summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/README.md2
-rw-r--r--src/bootstrap/CHANGELOG.md2
-rw-r--r--src/bootstrap/Cargo.lock8
-rw-r--r--src/bootstrap/README.md64
-rw-r--r--src/bootstrap/bin/rustc.rs2
-rw-r--r--src/bootstrap/bolt.rs71
-rw-r--r--src/bootstrap/bootstrap.py18
-rw-r--r--src/bootstrap/build.rs36
-rw-r--r--src/bootstrap/builder.rs24
-rw-r--r--src/bootstrap/builder/tests.rs4
-rw-r--r--src/bootstrap/channel.rs68
-rw-r--r--src/bootstrap/check.rs2
-rw-r--r--src/bootstrap/compile.rs67
-rw-r--r--src/bootstrap/config.rs153
-rw-r--r--src/bootstrap/dist.rs200
-rw-r--r--src/bootstrap/doc.rs285
-rw-r--r--src/bootstrap/download-ci-llvm-stamp2
-rw-r--r--src/bootstrap/flags.rs26
-rw-r--r--src/bootstrap/install.rs11
-rw-r--r--src/bootstrap/lib.rs66
-rw-r--r--src/bootstrap/native.rs116
-rw-r--r--src/bootstrap/sanity.rs2
-rw-r--r--src/bootstrap/tarball.rs6
-rw-r--r--src/bootstrap/test.rs237
-rw-r--r--src/bootstrap/tool.rs42
-rw-r--r--src/bootstrap/toolstate.rs1
-rw-r--r--src/ci/docker/README.md106
-rw-r--r--src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/Dockerfile2
-rw-r--r--src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/Dockerfile35
-rwxr-xr-xsrc/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/build-i586-gnu-toolchain.sh26
-rw-r--r--src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/i586-linux-gnu.config726
-rw-r--r--src/ci/docker/host-x86_64/dist-mips-linux/Dockerfile43
-rwxr-xr-xsrc/ci/docker/host-x86_64/dist-mips-linux/build-mips-toolchain.sh26
-rw-r--r--src/ci/docker/host-x86_64/dist-mips-linux/mips-linux-gnu.config740
-rw-r--r--src/ci/docker/host-x86_64/dist-mips-linux/patches/glibc/2.23/0001-MIPS-SPARC-fix-wrong-vfork-aliases-in-libpthread.so.patch44
-rw-r--r--src/ci/docker/host-x86_64/dist-mips-linux/patches/glibc/2.23/0002-MIPS-SPARC-more-fixes-to-the-vfork-aliases-in-libpth.patch63
-rw-r--r--src/ci/docker/host-x86_64/dist-mips64-linux/Dockerfile44
-rwxr-xr-xsrc/ci/docker/host-x86_64/dist-mips64-linux/build-mips64-toolchain.sh26
-rw-r--r--src/ci/docker/host-x86_64/dist-mips64-linux/mips64-linux-gnu.config741
-rw-r--r--src/ci/docker/host-x86_64/dist-mips64el-linux/Dockerfile43
-rwxr-xr-xsrc/ci/docker/host-x86_64/dist-mips64el-linux/build-mips64el-toolchain.sh26
-rw-r--r--src/ci/docker/host-x86_64/dist-mips64el-linux/mips64el-linux-gnu.config741
-rw-r--r--src/ci/docker/host-x86_64/dist-mipsel-linux/Dockerfile44
-rwxr-xr-xsrc/ci/docker/host-x86_64/dist-mipsel-linux/build-mipsel-toolchain.sh26
-rw-r--r--src/ci/docker/host-x86_64/dist-mipsel-linux/mipsel-linux-gnu.config740
-rw-r--r--src/ci/docker/host-x86_64/dist-various-2/Dockerfile2
-rw-r--r--src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile5
-rwxr-xr-xsrc/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh4
-rw-r--r--src/ci/docker/host-x86_64/x86_64-gnu-llvm-13-stage1/Dockerfile1
-rw-r--r--src/ci/docker/host-x86_64/x86_64-gnu-llvm-13/Dockerfile1
-rw-r--r--src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version2
-rwxr-xr-xsrc/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh11
-rw-r--r--src/ci/github-actions/ci.yml39
-rwxr-xr-xsrc/ci/pgo.sh39
-rwxr-xr-xsrc/ci/run.sh5
-rwxr-xr-xsrc/ci/scripts/select-xcode.sh13
-rwxr-xr-xsrc/ci/scripts/should-skip-this.sh8
-rw-r--r--src/doc/book/ADMIN_TASKS.md7
-rw-r--r--src/doc/book/TODO.md17
-rw-r--r--src/doc/book/ci/dictionary.txt1
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock40
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.lock16
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.lock16
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt2
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.lock16
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.lock16
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.lock16
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.lock16
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.lock16
-rw-r--r--src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/src/main.rs2
-rw-r--r--src/doc/book/listings/ch07-managing-growing-projects/listing-07-18/Cargo.lock16
-rw-r--r--src/doc/book/listings/ch07-managing-growing-projects/listing-07-18/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.lock16
-rw-r--r--src/doc/book/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch08-common-collections/listing-08-04/src/main.rs4
-rw-r--r--src/doc/book/listings/ch08-common-collections/listing-08-06/src/main.rs2
-rw-r--r--src/doc/book/listings/ch08-common-collections/listing-08-07/src/main.rs2
-rw-r--r--src/doc/book/listings/ch08-common-collections/listing-08-16/src/main.rs2
-rw-r--r--src/doc/book/listings/ch08-common-collections/no-listing-02-format/src/main.rs2
-rw-r--r--src/doc/book/listings/ch08-common-collections/no-listing-03-iterate-over-hashmap/src/main.rs2
-rw-r--r--src/doc/book/listings/ch09-error-handling/listing-09-07/src/main.rs3
-rw-r--r--src/doc/book/listings/ch09-error-handling/listing-09-08/src/main.rs3
-rw-r--r--src/doc/book/listings/ch09-error-handling/listing-09-13/Cargo.lock16
-rw-r--r--src/doc/book/listings/ch09-error-handling/listing-09-13/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.lock16
-rw-r--r--src/doc/book/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch11-writing-automated-tests/listing-11-01/Cargo.lock3
-rw-r--r--src/doc/book/listings/ch11-writing-automated-tests/listing-11-01/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.lock16
-rw-r--r--src/doc/book/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.lock16
-rw-r--r--src/doc/book/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/Cargo.toml2
-rw-r--r--src/doc/book/listings/ch18-patterns-and-matching/listing-18-14/src/main.rs8
-rw-r--r--src/doc/book/listings/ch18-patterns-and-matching/listing-18-15/src/main.rs12
-rw-r--r--src/doc/book/listings/ch18-patterns-and-matching/listing-18-16/src/main.rs10
-rw-r--r--src/doc/book/nostarch/acknowledgments.md2
-rw-r--r--src/doc/book/nostarch/appendix.md452
-rw-r--r--src/doc/book/nostarch/appendix_a.md142
-rw-r--r--src/doc/book/nostarch/appendix_b.md241
-rw-r--r--src/doc/book/nostarch/appendix_c.md184
-rw-r--r--src/doc/book/nostarch/appendix_d.md175
-rw-r--r--src/doc/book/nostarch/appendix_e.md66
-rw-r--r--src/doc/book/nostarch/bio.md7
-rw-r--r--src/doc/book/nostarch/chapter01.md161
-rw-r--r--src/doc/book/nostarch/chapter02.md509
-rw-r--r--src/doc/book/nostarch/chapter03.md528
-rw-r--r--src/doc/book/nostarch/chapter04.md520
-rw-r--r--src/doc/book/nostarch/chapter05.md486
-rw-r--r--src/doc/book/nostarch/chapter06.md362
-rw-r--r--src/doc/book/nostarch/chapter07.md595
-rw-r--r--src/doc/book/nostarch/chapter08.md497
-rw-r--r--src/doc/book/nostarch/chapter09.md646
-rw-r--r--src/doc/book/nostarch/chapter10.md577
-rw-r--r--src/doc/book/nostarch/chapter11.md476
-rw-r--r--src/doc/book/nostarch/chapter12.md454
-rw-r--r--src/doc/book/nostarch/chapter13.md404
-rw-r--r--src/doc/book/nostarch/chapter14.md343
-rw-r--r--src/doc/book/nostarch/chapter15.md675
-rw-r--r--src/doc/book/nostarch/chapter16.md436
-rw-r--r--src/doc/book/nostarch/chapter17.md407
-rw-r--r--src/doc/book/nostarch/chapter18.md366
-rw-r--r--src/doc/book/nostarch/chapter19.md684
-rw-r--r--src/doc/book/nostarch/chapter20.md731
-rw-r--r--src/doc/book/nostarch/frontmatter.md292
-rw-r--r--src/doc/book/nostarch/introduction.md13
-rw-r--r--src/doc/book/nostarch/preface.md24
-rw-r--r--src/doc/book/src/appendix-04-useful-development-tools.md15
-rw-r--r--src/doc/book/src/appendix-06-translation.md1
-rw-r--r--src/doc/book/src/ch00-00-introduction.md47
-rw-r--r--src/doc/book/src/ch01-01-installation.md58
-rw-r--r--src/doc/book/src/ch01-02-hello-world.md20
-rw-r--r--src/doc/book/src/ch01-03-hello-cargo.md24
-rw-r--r--src/doc/book/src/ch02-00-guessing-game-tutorial.md246
-rw-r--r--src/doc/book/src/ch03-00-common-programming-concepts.md6
-rw-r--r--src/doc/book/src/ch03-01-variables-and-mutability.md55
-rw-r--r--src/doc/book/src/ch03-02-data-types.md82
-rw-r--r--src/doc/book/src/ch03-03-how-functions-work.md22
-rw-r--r--src/doc/book/src/ch03-04-comments.md5
-rw-r--r--src/doc/book/src/ch03-05-control-flow.md84
-rw-r--r--src/doc/book/src/ch04-01-what-is-ownership.md88
-rw-r--r--src/doc/book/src/ch04-02-references-and-borrowing.md36
-rw-r--r--src/doc/book/src/ch04-03-slices.md50
-rw-r--r--src/doc/book/src/ch05-02-example-structs.md2
-rw-r--r--src/doc/book/src/ch08-02-strings.md4
-rw-r--r--src/doc/book/src/ch09-01-unrecoverable-errors-with-panic.md18
-rw-r--r--src/doc/book/src/ch09-02-recoverable-errors-with-result.md8
-rw-r--r--src/doc/book/src/ch13-02-iterators.md2
-rw-r--r--src/doc/book/src/ch14-02-publishing-to-crates-io.md9
-rw-r--r--src/doc/book/src/ch14-03-cargo-workspaces.md13
-rw-r--r--src/doc/book/src/ch14-04-installing-binaries.md8
-rw-r--r--src/doc/book/src/ch15-00-smart-pointers.md6
-rw-r--r--src/doc/book/src/ch15-01-box.md6
-rw-r--r--src/doc/book/src/ch15-02-deref.md11
-rw-r--r--src/doc/book/src/ch15-03-drop.md2
-rw-r--r--src/doc/book/src/ch15-05-interior-mutability.md8
-rw-r--r--src/doc/book/src/ch15-06-reference-cycles.md2
-rw-r--r--src/doc/book/src/ch16-01-threads.md4
-rw-r--r--src/doc/book/src/ch16-03-shared-state.md6
-rwxr-xr-xsrc/doc/book/tools/doc-to-md.sh13
-rw-r--r--src/doc/book/tools/docx-to-md.xsl262
-rw-r--r--src/doc/embedded-book/CITATION.bib7
-rw-r--r--src/doc/embedded-book/src/start/registers.md2
-rw-r--r--src/doc/index.md6
-rw-r--r--src/doc/nomicon/src/subtyping.md2
-rw-r--r--src/doc/nomicon/src/transmutes.md2
-rw-r--r--src/doc/reference/book.toml2
-rw-r--r--src/doc/reference/src/SUMMARY.md3
-rw-r--r--src/doc/reference/src/attributes.md3
-rw-r--r--src/doc/reference/src/attributes/codegen.md2
-rw-r--r--src/doc/reference/src/attributes/derive.md4
-rw-r--r--src/doc/reference/src/attributes/diagnostics.md2
-rw-r--r--src/doc/reference/src/conditional-compilation.md19
-rw-r--r--src/doc/reference/src/destructors.md2
-rw-r--r--src/doc/reference/src/expressions.md139
-rw-r--r--src/doc/reference/src/expressions/block-expr.md9
-rw-r--r--src/doc/reference/src/expressions/closure-expr.md2
-rw-r--r--src/doc/reference/src/expressions/grouped-expr.md4
-rw-r--r--src/doc/reference/src/expressions/loop-expr.md34
-rw-r--r--src/doc/reference/src/identifiers.md6
-rw-r--r--src/doc/reference/src/inline-assembly.md7
-rw-r--r--src/doc/reference/src/items/associated-items.md145
-rw-r--r--src/doc/reference/src/items/external-blocks.md58
-rw-r--r--src/doc/reference/src/items/functions.md4
-rw-r--r--src/doc/reference/src/items/traits.md1
-rw-r--r--src/doc/reference/src/items/type-aliases.md18
-rw-r--r--src/doc/reference/src/patterns.md324
-rw-r--r--src/doc/reference/src/statements-and-expressions.md12
-rw-r--r--src/doc/reference/src/statements.md86
-rw-r--r--src/doc/reference/src/tokens.md2
-rw-r--r--src/doc/reference/src/type-layout.md30
-rw-r--r--src/doc/reference/src/types/function-pointer.md2
-rw-r--r--src/doc/reference/src/types/pointer.md6
-rw-r--r--src/doc/reference/src/unsafe-blocks.md22
-rw-r--r--src/doc/reference/src/unsafe-functions.md5
-rw-r--r--src/doc/reference/src/unsafe-keyword.md58
-rw-r--r--src/doc/rust-by-example/src/cargo/conventions.md6
-rw-r--r--src/doc/rust-by-example/src/cargo/deps.md21
-rw-r--r--src/doc/rust-by-example/src/conversion/from_into.md2
-rw-r--r--src/doc/rust-by-example/src/error/iter_result.md2
-rw-r--r--src/doc/rust-by-example/src/error/option_unwrap/defaults.md6
-rw-r--r--src/doc/rust-by-example/src/flow_control/match/destructuring/destructure_slice.md2
-rw-r--r--src/doc/rust-by-example/src/flow_control/match/guard.md6
-rw-r--r--src/doc/rust-by-example/src/macros.md2
-rw-r--r--src/doc/rust-by-example/src/mod/struct_visibility.md3
-rw-r--r--src/doc/rust-by-example/src/primitives/array.md2
-rw-r--r--src/doc/rust-by-example/src/std/box.md6
-rw-r--r--src/doc/rust-by-example/src/std/str.md2
-rw-r--r--src/doc/rust-by-example/src/std_misc/path.md6
-rw-r--r--src/doc/rust-by-example/src/testing/doc_testing.md11
-rw-r--r--src/doc/rust-by-example/src/types/cast.md20
-rw-r--r--src/doc/rust-by-example/src/unsafe/asm.md4
-rw-r--r--src/doc/rustc-dev-guide/.github/workflows/ci.yml21
-rw-r--r--src/doc/rustc-dev-guide/.github/workflows/date-check.yml2
-rw-r--r--src/doc/rustc-dev-guide/book.toml1
-rw-r--r--src/doc/rustc-dev-guide/src/SUMMARY.md2
-rw-r--r--src/doc/rustc-dev-guide/src/about-this-guide.md4
-rw-r--r--src/doc/rustc-dev-guide/src/appendix/glossary.md3
-rw-r--r--src/doc/rustc-dev-guide/src/backend/codegen.md2
-rw-r--r--src/doc/rustc-dev-guide/src/backend/debugging.md2
-rw-r--r--src/doc/rustc-dev-guide/src/building/bootstrapping.md86
-rw-r--r--src/doc/rustc-dev-guide/src/building/how-to-build-and-run.md14
-rw-r--r--src/doc/rustc-dev-guide/src/building/new-target.md8
-rw-r--r--src/doc/rustc-dev-guide/src/building/prerequisites.md7
-rw-r--r--src/doc/rustc-dev-guide/src/building/suggested.md4
-rw-r--r--src/doc/rustc-dev-guide/src/closure.md16
-rw-r--r--src/doc/rustc-dev-guide/src/const-eval.md62
-rw-r--r--src/doc/rustc-dev-guide/src/const-eval/interpret.md (renamed from src/doc/rustc-dev-guide/src/miri.md)31
-rw-r--r--src/doc/rustc-dev-guide/src/contributing.md115
-rw-r--r--src/doc/rustc-dev-guide/src/diagnostics.md12
-rw-r--r--src/doc/rustc-dev-guide/src/diagnostics/diagnostic-structs.md147
-rw-r--r--src/doc/rustc-dev-guide/src/diagnostics/translation.md22
-rw-r--r--src/doc/rustc-dev-guide/src/feature-gates.md4
-rw-r--r--src/doc/rustc-dev-guide/src/generics.md4
-rw-r--r--src/doc/rustc-dev-guide/src/git.md29
-rw-r--r--src/doc/rustc-dev-guide/src/img/rustc_stages.svg3
-rw-r--r--src/doc/rustc-dev-guide/src/implementing_new_features.md12
-rw-r--r--src/doc/rustc-dev-guide/src/method-lookup.md4
-rw-r--r--src/doc/rustc-dev-guide/src/name-resolution.md2
-rw-r--r--src/doc/rustc-dev-guide/src/opaque-types-impl-trait-inference.md6
-rw-r--r--src/doc/rustc-dev-guide/src/overview.md4
-rw-r--r--src/doc/rustc-dev-guide/src/panic-implementation.md2
-rw-r--r--src/doc/rustc-dev-guide/src/rustc-driver.md2
-rw-r--r--src/doc/rustc-dev-guide/src/rustdoc.md2
-rw-r--r--src/doc/rustc-dev-guide/src/stability.md6
-rw-r--r--src/doc/rustc-dev-guide/src/tests/ci.md3
-rw-r--r--src/doc/rustc-dev-guide/src/tests/intro.md2
-rw-r--r--src/doc/rustc-dev-guide/src/tests/running.md12
-rw-r--r--src/doc/rustc-dev-guide/src/traits/resolution.md117
-rw-r--r--src/doc/rustc-dev-guide/src/ty.md2
-rw-r--r--src/doc/rustc/src/SUMMARY.md3
-rw-r--r--src/doc/rustc/src/command-line-arguments.md15
-rw-r--r--src/doc/rustc/src/platform-support.md18
-rw-r--r--src/doc/rustc/src/platform-support/android.md45
-rw-r--r--src/doc/rustc/src/platform-support/armeb-unknown-linux-gnueabi.md2
-rw-r--r--src/doc/rustc/src/platform-support/armv5te-none-eabi.md66
-rw-r--r--src/doc/rustc/src/platform-support/x86_64-fortanix-unknown-sgx.md72
-rw-r--r--src/doc/rustdoc/book.toml4
-rw-r--r--src/doc/rustdoc/src/unstable-features.md39
-rw-r--r--src/doc/style-guide/book.toml8
-rw-r--r--src/doc/style-guide/src/README.md190
-rw-r--r--src/doc/style-guide/src/SUMMARY.md11
-rw-r--r--src/doc/style-guide/src/advice.md34
-rw-r--r--src/doc/style-guide/src/cargo.md78
-rw-r--r--src/doc/style-guide/src/expressions.md850
-rw-r--r--src/doc/style-guide/src/items.md565
-rw-r--r--src/doc/style-guide/src/principles.md51
-rw-r--r--src/doc/style-guide/src/statements.md150
-rw-r--r--src/doc/style-guide/src/types.md58
-rw-r--r--src/doc/unstable-book/src/compiler-flags/dylib-lto.md4
-rw-r--r--src/doc/unstable-book/src/compiler-flags/self-profile-events.md2
-rw-r--r--src/doc/unstable-book/src/language-features/arbitrary-enum-discriminant.md37
-rw-r--r--src/doc/unstable-book/src/language-features/asm-sym.md13
-rw-r--r--src/doc/unstable-book/src/language-features/half-open-range-patterns-in-slices.md30
-rw-r--r--src/doc/unstable-book/src/language-features/half-open-range-patterns.md27
-rw-r--r--src/doc/unstable-book/src/language-features/unix-sigpipe.md10
-rwxr-xr-xsrc/etc/cat-and-grep.sh10
-rw-r--r--src/etc/natvis/libcore.natvis4
-rwxr-xr-xsrc/etc/rust-gdbgui3
-rw-r--r--src/librustdoc/clean/auto_trait.rs15
-rw-r--r--src/librustdoc/clean/blanket_impl.rs209
-rw-r--r--src/librustdoc/clean/inline.rs53
-rw-r--r--src/librustdoc/clean/mod.rs339
-rw-r--r--src/librustdoc/clean/simplify.rs60
-rw-r--r--src/librustdoc/clean/types.rs56
-rw-r--r--src/librustdoc/clean/utils.rs19
-rw-r--r--src/librustdoc/config.rs80
-rw-r--r--src/librustdoc/core.rs48
-rw-r--r--src/librustdoc/doctest.rs18
-rw-r--r--src/librustdoc/fold.rs2
-rw-r--r--src/librustdoc/formats/cache.rs29
-rw-r--r--src/librustdoc/formats/renderer.rs4
-rw-r--r--src/librustdoc/html/format.rs33
-rw-r--r--src/librustdoc/html/highlight.rs13
-rw-r--r--src/librustdoc/html/markdown.rs34
-rw-r--r--src/librustdoc/html/markdown/tests.rs48
-rw-r--r--src/librustdoc/html/render/context.rs65
-rw-r--r--src/librustdoc/html/render/mod.rs210
-rw-r--r--src/librustdoc/html/render/print_item.rs46
-rw-r--r--src/librustdoc/html/render/write_shared.rs6
-rw-r--r--src/librustdoc/html/sources.rs2
-rw-r--r--src/librustdoc/html/static/css/noscript.css6
-rw-r--r--src/librustdoc/html/static/css/rustdoc.css683
-rw-r--r--src/librustdoc/html/static/css/settings.css22
-rw-r--r--src/librustdoc/html/static/css/themes/ayu.css117
-rw-r--r--src/librustdoc/html/static/css/themes/dark.css116
-rw-r--r--src/librustdoc/html/static/css/themes/light.css109
-rw-r--r--src/librustdoc/html/static/js/main.js264
-rw-r--r--src/librustdoc/html/static/js/scrape-examples.js2
-rw-r--r--src/librustdoc/html/static/js/settings.js11
-rw-r--r--src/librustdoc/html/static/js/source-script.js37
-rw-r--r--src/librustdoc/html/static/js/storage.js4
-rw-r--r--src/librustdoc/html/templates/page.html54
-rw-r--r--src/librustdoc/html/templates/print_item.html24
-rw-r--r--src/librustdoc/json/conversions.rs12
-rw-r--r--src/librustdoc/json/mod.rs8
-rw-r--r--src/librustdoc/lib.rs87
-rw-r--r--src/librustdoc/lint.rs2
-rw-r--r--src/librustdoc/markdown.rs7
-rw-r--r--src/librustdoc/passes/bare_urls.rs6
-rw-r--r--src/librustdoc/passes/check_code_block_syntax.rs95
-rw-r--r--src/librustdoc/passes/check_doc_test_visibility.rs14
-rw-r--r--src/librustdoc/passes/collect_intra_doc_links.rs28
-rw-r--r--src/librustdoc/passes/collect_intra_doc_links/early.rs44
-rw-r--r--src/librustdoc/passes/html_tags.rs72
-rw-r--r--src/librustdoc/passes/propagate_doc_cfg.rs2
-rw-r--r--src/librustdoc/passes/strip_private.rs2
-rw-r--r--src/librustdoc/passes/stripper.rs44
-rw-r--r--src/librustdoc/scrape_examples.rs11
-rw-r--r--src/librustdoc/visit.rs2
-rw-r--r--src/librustdoc/visit_ast.rs20
-rw-r--r--src/librustdoc/visit_lib.rs32
-rw-r--r--src/rustdoc-json-types/lib.rs15
-rw-r--r--src/stage0.json568
-rw-r--r--src/test/assembly/asm/aarch64-types.rs2
-rw-r--r--src/test/assembly/asm/arm-types.rs2
-rw-r--r--src/test/assembly/asm/avr-types.rs2
-rw-r--r--src/test/assembly/asm/bpf-types.rs2
-rw-r--r--src/test/assembly/asm/global_asm.rs6
-rw-r--r--src/test/assembly/asm/hexagon-types.rs2
-rw-r--r--src/test/assembly/asm/mips-types.rs2
-rw-r--r--src/test/assembly/asm/msp430-types.rs2
-rw-r--r--src/test/assembly/asm/nvptx-types.rs2
-rw-r--r--src/test/assembly/asm/powerpc-types.rs2
-rw-r--r--src/test/assembly/asm/riscv-types.rs2
-rw-r--r--src/test/assembly/asm/s390x-types.rs2
-rw-r--r--src/test/assembly/asm/wasm-types.rs2
-rw-r--r--src/test/assembly/asm/x86-types.rs2
-rw-r--r--src/test/assembly/x86-stack-probes.rs42
-rw-r--r--src/test/codegen-units/item-collection/asm-sym.rs20
-rw-r--r--src/test/codegen-units/item-collection/generic-impl.rs6
-rw-r--r--src/test/codegen/abi-main-signature-32bit-c-int.rs2
-rw-r--r--src/test/codegen/binary-search-index-no-bound-check.rs20
-rw-r--r--src/test/codegen/deduced-param-attrs.rs60
-rw-r--r--src/test/codegen/function-arguments.rs2
-rw-r--r--src/test/codegen/mem-replace-direct-memcpy.rs1
-rw-r--r--src/test/codegen/sanitizer_scs_attr_check.rs6
-rw-r--r--src/test/codegen/slice-iter-len-eq-zero.rs14
-rw-r--r--src/test/codegen/slice_as_from_ptr_range.rs23
-rw-r--r--src/test/codegen/stack-probes-call.rs24
-rw-r--r--src/test/codegen/stack-probes-inline.rs32
-rw-r--r--src/test/codegen/stack-probes.rs22
-rw-r--r--src/test/codegen/vec-calloc.rs19
-rw-r--r--src/test/codegen/vec-in-place.rs2
-rw-r--r--src/test/incremental/hashes/function_interfaces.rs2
-rw-r--r--src/test/incremental/issue-61323.rs3
-rw-r--r--src/test/incremental/spans_significant_w_panic.rs1
-rw-r--r--src/test/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstCombine.diff6
-rw-r--r--src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff2
-rw-r--r--src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff2
-rw-r--r--src/test/mir-opt/const_prop/cast.main.ConstProp.diff4
-rw-r--r--src/test/mir-opt/const_prop/indirect.main.ConstProp.diff2
-rw-r--r--src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff2
-rw-r--r--src/test/mir-opt/derefer_complex_case.main.Derefer.diff12
-rw-r--r--src/test/mir-opt/dest-prop/simple.nrvo.DestinationPropagation.diff4
-rw-r--r--src/test/mir-opt/early_otherwise_branch_soundness.no_downcast.EarlyOtherwiseBranch.diff6
-rw-r--r--src/test/mir-opt/enum_cast.bar.mir_map.0.mir2
-rw-r--r--src/test/mir-opt/enum_cast.boo.mir_map.0.mir2
-rw-r--r--src/test/mir-opt/enum_cast.droppy.mir_map.0.mir2
-rw-r--r--src/test/mir-opt/enum_cast.foo.mir_map.0.mir2
-rw-r--r--src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff24
-rw-r--r--src/test/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff4
-rw-r--r--src/test/mir-opt/inline/asm-unwind.rs22
-rw-r--r--src/test/mir-opt/inline/asm_unwind.main.Inline.diff45
-rw-r--r--src/test/mir-opt/inline/cycle.f.Inline.diff2
-rw-r--r--src/test/mir-opt/inline/dyn_trait.get_query.Inline.diff6
-rw-r--r--src/test/mir-opt/inline/dyn_trait.mk_cycle.Inline.diff2
-rw-r--r--src/test/mir-opt/inline/dyn_trait.try_execute_query.Inline.diff4
-rw-r--r--src/test/mir-opt/inline/inline_diverging.g.Inline.diff2
-rw-r--r--src/test/mir-opt/inline/inline_generator.main.Inline.diff2
-rw-r--r--src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir6
-rw-r--r--src/test/mir-opt/inline/inline_shims.clone.Inline.diff2
-rw-r--r--src/test/mir-opt/inline/inline_trait_method.test.Inline.after.mir2
-rw-r--r--src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir2
-rw-r--r--src/test/mir-opt/inline/issue_78442.bar.Inline.diff2
-rw-r--r--src/test/mir-opt/inline/issue_78442.bar.RevealAll.diff4
-rw-r--r--src/test/mir-opt/issue-101867.rs2
-rw-r--r--src/test/mir-opt/issue_101867.main.mir_map.0.mir4
-rw-r--r--src/test/mir-opt/issue_101973.inner.ConstProp.diff4
-rw-r--r--src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.diff4
-rw-r--r--src/test/mir-opt/issue_91633.bar.mir_map.0.mir2
-rw-r--r--src/test/mir-opt/issue_91633.foo.mir_map.0.mir2
-rw-r--r--src/test/mir-opt/issue_91633.hey.mir_map.0.mir2
-rw-r--r--src/test/mir-opt/issue_99325.main.mir_map.0.mir18
-rw-r--r--src/test/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.diff8
-rw-r--r--src/test/mir-opt/lower_intrinsics.f_copy_nonoverlapping.LowerIntrinsics.diff4
-rw-r--r--src/test/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.diff2
-rw-r--r--src/test/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.mir2
-rw-r--r--src/test/mir-opt/nrvo_simple.nrvo.RenameReturnPlace.diff4
-rw-r--r--src/test/mir-opt/remove-never-const.rs1
-rw-r--r--src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff2
-rw-r--r--src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir4
-rw-r--r--src/test/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir2
-rw-r--r--src/test/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.mir10
-rw-r--r--src/test/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir2
-rw-r--r--src/test/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir2
-rw-r--r--src/test/pretty/issue-4264.pp8
-rw-r--r--src/test/pretty/issue-85089.pp20
-rw-r--r--src/test/pretty/issue-85089.rs16
-rw-r--r--src/test/pretty/raw-str-nonexpr.rs1
-rw-r--r--src/test/pretty/tests-are-sorted.pp69
-rw-r--r--src/test/pretty/tests-are-sorted.rs13
-rw-r--r--src/test/run-make-fulldeps/alloc-no-rc/Makefile4
-rw-r--r--src/test/run-make-fulldeps/alloc-no-sync/Makefile4
-rw-r--r--src/test/run-make-fulldeps/foreign-rust-exceptions/Makefile11
-rw-r--r--src/test/run-make-fulldeps/foreign-rust-exceptions/bar.rs7
-rw-r--r--src/test/run-make-fulldeps/foreign-rust-exceptions/foo.rs13
-rw-r--r--src/test/run-make-fulldeps/intrinsic-unreachable/Makefile1
-rw-r--r--src/test/run-make-fulldeps/issue-19371/foo.rs2
-rw-r--r--src/test/run-make-fulldeps/obtain-borrowck/driver.rs12
-rw-r--r--src/test/run-make-fulldeps/print-calling-conventions/Makefile4
-rw-r--r--src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/src/lib.rs8
-rw-r--r--src/test/run-make/coverage-reports/Makefile11
-rw-r--r--src/test/run-make/issue-36710/Makefile6
-rw-r--r--src/test/run-make/macos-fat-archive/Makefile10
-rw-r--r--src/test/run-make/macos-fat-archive/lib.rs3
-rw-r--r--src/test/run-make/macos-fat-archive/native-library.c1
-rw-r--r--src/test/run-make/native-link-modifier-verbatim-linker/Makefile15
-rw-r--r--src/test/run-make/native-link-modifier-verbatim-linker/local_native_dep.rs4
-rw-r--r--src/test/run-make/native-link-modifier-verbatim-linker/main.rs9
-rw-r--r--src/test/run-make/native-link-modifier-verbatim-rustc/Makefile12
-rw-r--r--src/test/run-make/native-link-modifier-verbatim-rustc/rust_dep.rs9
-rw-r--r--src/test/run-make/native-link-modifier-verbatim-rustc/upstream_native_dep.rs4
-rw-r--r--src/test/run-make/rlib-format-packed-bundled-libs-2/Makefile22
-rw-r--r--src/test/run-make/rlib-format-packed-bundled-libs-2/main.rs5
-rw-r--r--src/test/run-make/rlib-format-packed-bundled-libs-2/native_dep.rs4
-rw-r--r--src/test/run-make/rlib-format-packed-bundled-libs-2/rust_dep.rs11
-rw-r--r--src/test/run-make/rlib-format-packed-bundled-libs/Makefile34
-rw-r--r--src/test/run-make/rlib-format-packed-bundled-libs/main.rs4
-rw-r--r--src/test/run-make/rlib-format-packed-bundled-libs/native_dep_1.c1
-rw-r--r--src/test/run-make/rlib-format-packed-bundled-libs/native_dep_2.c1
-rw-r--r--src/test/run-make/rlib-format-packed-bundled-libs/native_dep_3.c1
-rw-r--r--src/test/run-make/rlib-format-packed-bundled-libs/rust_dep_local.rs13
-rw-r--r--src/test/run-make/rlib-format-packed-bundled-libs/rust_dep_up.rs13
-rw-r--r--src/test/rustdoc-gui/anchor-navigable.goml4
-rw-r--r--src/test/rustdoc-gui/anchors.goml247
-rw-r--r--src/test/rustdoc-gui/auto-hide-trait-implementations.goml2
-rw-r--r--src/test/rustdoc-gui/basic-code.goml4
-rw-r--r--src/test/rustdoc-gui/basic.goml4
-rw-r--r--src/test/rustdoc-gui/check-code-blocks-margin.goml6
-rw-r--r--src/test/rustdoc-gui/check-stab-in-docblock.goml27
-rw-r--r--src/test/rustdoc-gui/check_info_sign_position.goml4
-rw-r--r--src/test/rustdoc-gui/code-blocks-overflow.goml4
-rw-r--r--src/test/rustdoc-gui/code-color.goml38
-rw-r--r--src/test/rustdoc-gui/code-sidebar-toggle.goml2
-rw-r--r--src/test/rustdoc-gui/code-tags.goml10
-rw-r--r--src/test/rustdoc-gui/codeblock-tooltip.goml170
-rw-r--r--src/test/rustdoc-gui/default-settings.goml2
-rw-r--r--src/test/rustdoc-gui/docblock-big-code-mobile.goml2
-rw-r--r--src/test/rustdoc-gui/docblock-code-block-line-number.goml27
-rw-r--r--src/test/rustdoc-gui/docblock-details.goml15
-rw-r--r--src/test/rustdoc-gui/docblock-table-overflow.goml6
-rw-r--r--src/test/rustdoc-gui/docblock-table.goml2
-rw-r--r--src/test/rustdoc-gui/duplicate-macro-reexport.goml2
-rw-r--r--src/test/rustdoc-gui/escape-key.goml2
-rw-r--r--src/test/rustdoc-gui/font-weight.goml20
-rw-r--r--src/test/rustdoc-gui/hash-item-expansion.goml2
-rw-r--r--src/test/rustdoc-gui/headers-color.goml173
-rw-r--r--src/test/rustdoc-gui/headings.goml198
-rw-r--r--src/test/rustdoc-gui/help-page.goml24
-rw-r--r--src/test/rustdoc-gui/highlight-colors.goml94
-rw-r--r--src/test/rustdoc-gui/huge-collection-of-constants.goml2
-rw-r--r--src/test/rustdoc-gui/impl-default-expansion.goml2
-rw-r--r--src/test/rustdoc-gui/implementors.goml16
-rw-r--r--src/test/rustdoc-gui/item-decl-colors.goml74
-rw-r--r--src/test/rustdoc-gui/item-info-alignment.goml2
-rw-r--r--src/test/rustdoc-gui/item-info-overflow.goml10
-rw-r--r--src/test/rustdoc-gui/item-info.goml8
-rw-r--r--src/test/rustdoc-gui/item-summary-table.goml2
-rw-r--r--src/test/rustdoc-gui/javascript-disabled.goml2
-rw-r--r--src/test/rustdoc-gui/jump-to-def-background.goml57
-rw-r--r--src/test/rustdoc-gui/label-next-to-symbol.goml2
-rw-r--r--src/test/rustdoc-gui/links-color.goml2
-rw-r--r--src/test/rustdoc-gui/list_code_block.goml4
-rw-r--r--src/test/rustdoc-gui/mobile.goml6
-rw-r--r--src/test/rustdoc-gui/module-items-font.goml2
-rw-r--r--src/test/rustdoc-gui/no-docblock.goml8
-rw-r--r--src/test/rustdoc-gui/notable-trait.goml128
-rw-r--r--src/test/rustdoc-gui/overflow-tooltip-information.goml2
-rw-r--r--src/test/rustdoc-gui/pocket-menu.goml2
-rw-r--r--src/test/rustdoc-gui/run-on-hover.goml2
-rw-r--r--src/test/rustdoc-gui/rust-logo.goml100
-rw-r--r--src/test/rustdoc-gui/search-filter.goml4
-rw-r--r--src/test/rustdoc-gui/search-form-elements.goml44
-rw-r--r--src/test/rustdoc-gui/search-input-mobile.goml2
-rw-r--r--src/test/rustdoc-gui/search-reexport.goml2
-rw-r--r--src/test/rustdoc-gui/search-result-color.goml410
-rw-r--r--src/test/rustdoc-gui/search-result-description.goml2
-rw-r--r--src/test/rustdoc-gui/search-result-display.goml4
-rw-r--r--src/test/rustdoc-gui/search-result-go-to-first.goml12
-rw-r--r--src/test/rustdoc-gui/search-result-keyword.goml2
-rw-r--r--src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml10
-rw-r--r--src/test/rustdoc-gui/settings.goml15
-rw-r--r--src/test/rustdoc-gui/shortcuts.goml20
-rw-r--r--src/test/rustdoc-gui/sidebar-links-color.goml233
-rw-r--r--src/test/rustdoc-gui/sidebar-macro-reexport.goml4
-rw-r--r--src/test/rustdoc-gui/sidebar-mobile-scroll.goml10
-rw-r--r--src/test/rustdoc-gui/sidebar-mobile.goml18
-rw-r--r--src/test/rustdoc-gui/sidebar-source-code-display.goml25
-rw-r--r--src/test/rustdoc-gui/sidebar-source-code.goml6
-rw-r--r--src/test/rustdoc-gui/sidebar.goml73
-rw-r--r--src/test/rustdoc-gui/source-anchor-scroll.goml4
-rw-r--r--src/test/rustdoc-gui/source-code-page.goml90
-rw-r--r--src/test/rustdoc-gui/src-font-size.goml10
-rw-r--r--src/test/rustdoc-gui/src/test_docs/lib.rs91
-rw-r--r--src/test/rustdoc-gui/theme-change.goml4
-rw-r--r--src/test/rustdoc-gui/theme-in-history.goml4
-rw-r--r--src/test/rustdoc-gui/toggle-click-deadspace.goml4
-rw-r--r--src/test/rustdoc-gui/toggle-docs-mobile.goml2
-rw-r--r--src/test/rustdoc-gui/toggle-docs.goml4
-rw-r--r--src/test/rustdoc-gui/toggle-implementors.goml2
-rw-r--r--src/test/rustdoc-gui/toggled-open-implementations.goml2
-rw-r--r--src/test/rustdoc-gui/trait-sidebar-item-order.goml2
-rw-r--r--src/test/rustdoc-gui/type-declation-overflow.goml20
-rw-r--r--src/test/rustdoc-gui/unsafe-fn.goml28
-rw-r--r--src/test/rustdoc-gui/where-whitespace.goml4
-rw-r--r--src/test/rustdoc-js-std/asrawfd.js6
-rw-r--r--src/test/rustdoc-json/primitives/primitive_impls.rs34
-rw-r--r--src/test/rustdoc-json/primitives/primitive_overloading.rs (renamed from src/test/rustdoc-json/primitive_overloading.rs)0
-rw-r--r--src/test/rustdoc-json/primitives/primitive_type.rs (renamed from src/test/rustdoc-json/primitives.rs)0
-rw-r--r--src/test/rustdoc-json/primitives/use_primitive.rs (renamed from src/test/rustdoc-json/primitive.rs)2
-rw-r--r--src/test/rustdoc-json/reexport/reexport_method_from_private_module.rs28
-rw-r--r--src/test/rustdoc-ui/bare-urls.stderr2
-rw-r--r--src/test/rustdoc-ui/check-attr-test.stderr2
-rw-r--r--src/test/rustdoc-ui/check-attr.stderr2
-rw-r--r--src/test/rustdoc-ui/check-cfg-test.stderr2
-rw-r--r--src/test/rustdoc-ui/check-fail.stderr2
-rw-r--r--src/test/rustdoc-ui/check.stderr4
-rw-r--r--src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr2
-rw-r--r--src/test/rustdoc-ui/diagnostic-width.rs2
-rw-r--r--src/test/rustdoc-ui/diagnostic-width.stderr2
-rw-r--r--src/test/rustdoc-ui/doc-attr.stderr4
-rw-r--r--src/test/rustdoc-ui/doc-include-suggestion.stderr2
-rw-r--r--src/test/rustdoc-ui/doc-spotlight.stderr8
-rw-r--r--src/test/rustdoc-ui/doc-test-attr.stderr4
-rw-r--r--src/test/rustdoc-ui/doc_cfg_hide.rs11
-rw-r--r--src/test/rustdoc-ui/doc_cfg_hide.stderr40
-rw-r--r--src/test/rustdoc-ui/doctest-edition.stderr2
-rw-r--r--src/test/rustdoc-ui/feature-gate-rustdoc_missing_doc_code_examples.stderr6
-rw-r--r--src/test/rustdoc-ui/ignore-block-help.stderr2
-rw-r--r--src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.rs3
-rw-r--r--src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.stderr17
-rw-r--r--src/test/rustdoc-ui/infinite-recursive-type-impl-trait.rs4
-rw-r--r--src/test/rustdoc-ui/infinite-recursive-type-impl-trait.stderr17
-rw-r--r--src/test/rustdoc-ui/infinite-recursive-type.stderr4
-rw-r--r--src/test/rustdoc-ui/intra-doc/html-as-generics-intra-doc.stderr2
-rw-r--r--src/test/rustdoc-ui/intra-doc/macro-rules-error.stderr2
-rw-r--r--src/test/rustdoc-ui/intra-doc/malformed-generics.rs9
-rw-r--r--src/test/rustdoc-ui/intra-doc/malformed-generics.stderr82
-rw-r--r--src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr2
-rw-r--r--src/test/rustdoc-ui/intra-doc/private-from-crate-level.stderr2
-rw-r--r--src/test/rustdoc-ui/intra-doc/private.private.stderr2
-rw-r--r--src/test/rustdoc-ui/intra-doc/private.public.stderr2
-rw-r--r--src/test/rustdoc-ui/intra-doc/span-ice-55723.stderr2
-rw-r--r--src/test/rustdoc-ui/intra-doc/through-proc-macro.stderr2
-rw-r--r--src/test/rustdoc-ui/intra-doc/unknown-disambiguator.stderr12
-rw-r--r--src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr2
-rw-r--r--src/test/rustdoc-ui/intra-doc/warning-crlf.stderr2
-rw-r--r--src/test/rustdoc-ui/invalid-doc-attr.stderr6
-rw-r--r--src/test/rustdoc-ui/invalid-html-self-closing-tag.rs70
-rw-r--r--src/test/rustdoc-ui/invalid-html-self-closing-tag.stderr80
-rw-r--r--src/test/rustdoc-ui/invalid-syntax.rs6
-rw-r--r--src/test/rustdoc-ui/invalid-syntax.stderr19
-rw-r--r--src/test/rustdoc-ui/issue-102986.rs4
-rw-r--r--src/test/rustdoc-ui/issue-102986.stderr14
-rw-r--r--src/test/rustdoc-ui/issue-74134.private.stderr2
-rw-r--r--src/test/rustdoc-ui/issue-74134.public.stderr2
-rw-r--r--src/test/rustdoc-ui/lint-group.stderr2
-rw-r--r--src/test/rustdoc-ui/macro-docs.stderr2
-rw-r--r--src/test/rustdoc-ui/no-crate-level-doc-lint.stderr4
-rw-r--r--src/test/rustdoc-ui/normalize-cycle.rs1
-rw-r--r--src/test/rustdoc-ui/normalize-overflow.rs2
-rw-r--r--src/test/rustdoc-ui/pub-export-lint.stderr2
-rw-r--r--src/test/rustdoc-ui/reference-link-reports-error-once.stderr2
-rw-r--r--src/test/rustdoc-ui/renamed-lint-still-applies.stderr4
-rw-r--r--src/test/rustdoc-ui/suggestions/html-as-generics.fixed10
-rw-r--r--src/test/rustdoc-ui/suggestions/html-as-generics.rs10
-rw-r--r--src/test/rustdoc-ui/suggestions/html-as-generics.stderr24
-rw-r--r--src/test/rustdoc-ui/z-help.stdout47
-rw-r--r--src/test/rustdoc/anchors.no_const_anchor.html2
-rw-r--r--src/test/rustdoc/anchors.no_trait_method_anchor.html2
-rw-r--r--src/test/rustdoc/anchors.no_tymethod_anchor.html2
-rw-r--r--src/test/rustdoc/anchors.no_type_anchor.html2
-rw-r--r--src/test/rustdoc/anonymous-lifetime.rs2
-rw-r--r--src/test/rustdoc/array-links.link_box_generic.html1
-rw-r--r--src/test/rustdoc/array-links.link_box_u32.html1
-rw-r--r--src/test/rustdoc/array-links.link_slice_generic.html1
-rw-r--r--src/test/rustdoc/array-links.link_slice_u32.html1
-rw-r--r--src/test/rustdoc/array-links.rs28
-rw-r--r--src/test/rustdoc/assoc-consts.rs4
-rw-r--r--src/test/rustdoc/associated-consts.rs8
-rw-r--r--src/test/rustdoc/async-trait.rs16
-rw-r--r--src/test/rustdoc/attribute-rendering.rs2
-rw-r--r--src/test/rustdoc/attributes.rs2
-rw-r--r--src/test/rustdoc/auxiliary/async-trait-dep.rs9
-rw-r--r--src/test/rustdoc/auxiliary/reexport-doc-aux.rs5
-rw-r--r--src/test/rustdoc/blanket-reexport-item.rs2
-rw-r--r--src/test/rustdoc/const-generics/add-impl.rs2
-rw-r--r--src/test/rustdoc/const-generics/const-generics-docs.rs12
-rw-r--r--src/test/rustdoc/const-generics/const-impl.rs10
-rw-r--r--src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs2
-rw-r--r--src/test/rustdoc/const-value-display.rs4
-rw-r--r--src/test/rustdoc/decl-trailing-whitespace.rs2
-rw-r--r--src/test/rustdoc/deref-recursive-pathbuf.rs4
-rw-r--r--src/test/rustdoc/deref-recursive.rs4
-rw-r--r--src/test/rustdoc/deref-typedef.rs2
-rw-r--r--src/test/rustdoc/doc-notable_trait_box_is_not_an_iterator.rs38
-rw-r--r--src/test/rustdoc/duplicate_impls/issue-33054.rs6
-rw-r--r--src/test/rustdoc/empty-impl-block.rs2
-rw-r--r--src/test/rustdoc/escape-deref-methods.rs2
-rw-r--r--src/test/rustdoc/extern-impl.rs6
-rw-r--r--src/test/rustdoc/fn-bound.rs2
-rw-r--r--src/test/rustdoc/generic-impl.rs2
-rw-r--r--src/test/rustdoc/higher-ranked-trait-bounds.rs2
-rw-r--r--src/test/rustdoc/impl-disambiguation.rs10
-rw-r--r--src/test/rustdoc/impl-parts.rs4
-rw-r--r--src/test/rustdoc/index-page.rs6
-rw-r--r--src/test/rustdoc/inline_cross/assoc_item_trait_bounds.out0.html1
-rw-r--r--src/test/rustdoc/inline_cross/assoc_item_trait_bounds.out2.html1
-rw-r--r--src/test/rustdoc/inline_cross/assoc_item_trait_bounds.out9.html1
-rw-r--r--src/test/rustdoc/inline_cross/assoc_item_trait_bounds.rs40
-rw-r--r--src/test/rustdoc/inline_cross/auxiliary/assoc_item_trait_bounds.rs46
-rw-r--r--src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs13
-rw-r--r--src/test/rustdoc/inline_cross/auxiliary/issue-24183.rs14
-rw-r--r--src/test/rustdoc/inline_cross/impl_trait.rs7
-rw-r--r--src/test/rustdoc/inline_cross/issue-24183.method_no_where_self_sized.html1
-rw-r--r--src/test/rustdoc/inline_cross/issue-24183.rs18
-rw-r--r--src/test/rustdoc/inline_cross/issue-31948-1.rs20
-rw-r--r--src/test/rustdoc/inline_cross/issue-31948-2.rs12
-rw-r--r--src/test/rustdoc/inline_cross/issue-31948.rs20
-rw-r--r--src/test/rustdoc/inline_cross/issue-32881.rs4
-rw-r--r--src/test/rustdoc/inline_cross/issue-33113.rs4
-rw-r--r--src/test/rustdoc/inline_cross/trait-vis.rs2
-rw-r--r--src/test/rustdoc/inline_local/trait-vis.rs4
-rw-r--r--src/test/rustdoc/intra-doc/auxiliary/issue-103463-aux.rs4
-rw-r--r--src/test/rustdoc/intra-doc/extern-crate-only-used-in-link.rs2
-rw-r--r--src/test/rustdoc/intra-doc/issue-103463.rs8
-rw-r--r--src/test/rustdoc/intra-doc/issue-104145.rs14
-rw-r--r--src/test/rustdoc/intra-doc/no-doc-primitive.rs15
-rw-r--r--src/test/rustdoc/issue-100241.rs12
-rw-r--r--src/test/rustdoc/issue-29503.rs2
-rw-r--r--src/test/rustdoc/issue-33592.rs4
-rw-r--r--src/test/rustdoc/issue-46727.rs2
-rw-r--r--src/test/rustdoc/issue-50159.rs4
-rw-r--r--src/test/rustdoc/issue-51236.rs2
-rw-r--r--src/test/rustdoc/issue-54705.rs4
-rw-r--r--src/test/rustdoc/issue-55321.rs8
-rw-r--r--src/test/rustdoc/issue-56822.rs2
-rw-r--r--src/test/rustdoc/issue-60726.rs4
-rw-r--r--src/test/rustdoc/issue-75588.rs4
-rw-r--r--src/test/rustdoc/issue-80233-normalize-auto-trait.rs2
-rw-r--r--src/test/rustdoc/issue-82465-asref-for-and-of-local.rs4
-rw-r--r--src/test/rustdoc/issue-98697.rs4
-rw-r--r--src/test/rustdoc/keyword.rs2
-rw-r--r--src/test/rustdoc/logo-class-default.rs2
-rw-r--r--src/test/rustdoc/logo-class.rs4
-rw-r--r--src/test/rustdoc/macro-higher-kinded-function.rs4
-rw-r--r--src/test/rustdoc/negative-impl-sidebar.rs2
-rw-r--r--src/test/rustdoc/negative-impl.rs4
-rw-r--r--src/test/rustdoc/normalize-assoc-item.rs13
-rw-r--r--src/test/rustdoc/not-wf-ambiguous-normalization.rs24
-rw-r--r--src/test/rustdoc/primitive-reference.rs4
-rw-r--r--src/test/rustdoc/primitive-slice-auto-trait.rs2
-rw-r--r--src/test/rustdoc/primitive-tuple-auto-trait.rs2
-rw-r--r--src/test/rustdoc/primitive-unit-auto-trait.rs2
-rw-r--r--src/test/rustdoc/primitive.rs2
-rw-r--r--src/test/rustdoc/primitive/primitive-generic-impl.rs2
-rw-r--r--src/test/rustdoc/recursive-deref.rs18
-rw-r--r--src/test/rustdoc/reexport-dep-foreign-fn.rs2
-rw-r--r--src/test/rustdoc/reexport-doc.rs8
-rw-r--r--src/test/rustdoc/reexports-priv.rs32
-rw-r--r--src/test/rustdoc/reexports.rs16
-rw-r--r--src/test/rustdoc/rfc-2632-const-trait-impl.rs16
-rw-r--r--src/test/rustdoc/safe-intrinsic.rs2
-rw-r--r--src/test/rustdoc/sidebar-all-page.rs35
-rw-r--r--src/test/rustdoc/sidebar-items.rs18
-rw-r--r--src/test/rustdoc/sidebar-links-to-foreign-impl.rs6
-rw-r--r--src/test/rustdoc/sized_trait.rs2
-rw-r--r--src/test/rustdoc/src-links-auto-impls.rs6
-rw-r--r--src/test/rustdoc/strip-enum-variant.no-not-shown.html2
-rw-r--r--src/test/rustdoc/strip-enum-variant.rs2
-rw-r--r--src/test/rustdoc/synthetic_auto/basic.rs4
-rw-r--r--src/test/rustdoc/synthetic_auto/complex.rs2
-rw-r--r--src/test/rustdoc/synthetic_auto/crate-local.rs6
-rw-r--r--src/test/rustdoc/synthetic_auto/lifetimes.rs4
-rw-r--r--src/test/rustdoc/synthetic_auto/manual.rs4
-rw-r--r--src/test/rustdoc/synthetic_auto/negative.rs4
-rw-r--r--src/test/rustdoc/synthetic_auto/nested.rs4
-rw-r--r--src/test/rustdoc/synthetic_auto/no-redundancy.rs2
-rw-r--r--src/test/rustdoc/synthetic_auto/overflow.rs2
-rw-r--r--src/test/rustdoc/synthetic_auto/project.rs4
-rw-r--r--src/test/rustdoc/synthetic_auto/self-referential.rs2
-rw-r--r--src/test/rustdoc/synthetic_auto/static-region.rs2
-rw-r--r--src/test/rustdoc/toggle-item-contents.rs2
-rw-r--r--src/test/rustdoc/toggle-trait-fn.rs12
-rw-r--r--src/test/rustdoc/trait_alias.rs6
-rw-r--r--src/test/rustdoc/traits-in-bodies.rs6
-rw-r--r--src/test/rustdoc/tuple-struct-fields-doc.rs2
-rw-r--r--src/test/rustdoc/typedef.rs4
-rw-r--r--src/test/rustdoc/where.SWhere_Simd_item-decl.html2
-rw-r--r--src/test/rustdoc/where.SWhere_TraitWhere_item-decl.html2
-rw-r--r--src/test/rustdoc/where.rs14
-rw-r--r--src/test/rustdoc/whitespace-after-where-clause.enum.html4
-rw-r--r--src/test/rustdoc/whitespace-after-where-clause.enum2.html4
-rw-r--r--src/test/rustdoc/whitespace-after-where-clause.rs16
-rw-r--r--src/test/rustdoc/whitespace-after-where-clause.struct.html4
-rw-r--r--src/test/rustdoc/whitespace-after-where-clause.struct2.html4
-rw-r--r--src/test/rustdoc/whitespace-after-where-clause.trait.html4
-rw-r--r--src/test/rustdoc/whitespace-after-where-clause.trait2.html4
-rw-r--r--src/test/rustdoc/whitespace-after-where-clause.union.html4
-rw-r--r--src/test/rustdoc/whitespace-after-where-clause.union2.html4
-rw-r--r--src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs10
-rw-r--r--src/test/ui-fulldeps/auxiliary/lint-for-crate.rs8
-rw-r--r--src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs10
-rw-r--r--src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs4
-rw-r--r--src/test/ui-fulldeps/auxiliary/lint-tool-test.rs8
-rw-r--r--src/test/ui-fulldeps/fluent-messages/test.rs5
-rw-r--r--src/test/ui-fulldeps/fluent-messages/test.stderr29
-rw-r--r--src/test/ui-fulldeps/internal-lints/default_hash_types.stderr2
-rw-r--r--src/test/ui-fulldeps/internal-lints/diagnostics.rs52
-rw-r--r--src/test/ui-fulldeps/internal-lints/diagnostics.stderr14
-rw-r--r--src/test/ui-fulldeps/internal-lints/existing_doc_keyword.stderr2
-rw-r--r--src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr2
-rw-r--r--src/test/ui-fulldeps/internal-lints/query_stability.stderr2
-rw-r--r--src/test/ui-fulldeps/pprust-expr-roundtrip.rs4
-rw-r--r--src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs605
-rw-r--r--src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr552
-rw-r--r--src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs321
-rw-r--r--src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr256
-rw-r--r--src/test/ui/abi/abi-sysv64-register-usage.rs26
-rw-r--r--src/test/ui/abi/abi-typo-unstable.rs6
-rw-r--r--src/test/ui/abi/abi-typo-unstable.stderr11
-rw-r--r--src/test/ui/abi/segfault-no-out-of-stack.rs1
-rw-r--r--src/test/ui/abi/stack-probes-lto.rs3
-rw-r--r--src/test/ui/abi/stack-probes.rs30
-rw-r--r--src/test/ui/abi/unsupported.aarch64.stderr2
-rw-r--r--src/test/ui/abi/unsupported.arm.stderr2
-rw-r--r--src/test/ui/abi/unsupported.x64.stderr2
-rw-r--r--src/test/ui/abi/x86stdcall.rs26
-rw-r--r--src/test/ui/abi/x86stdcall2.rs12
-rw-r--r--src/test/ui/alloc-error/default-alloc-error-hook.rs11
-rw-r--r--src/test/ui/anon-params/anon-params-deprecated.stderr4
-rw-r--r--src/test/ui/anonymous-higher-ranked-lifetime.stderr20
-rw-r--r--src/test/ui/array-slice-vec/array_const_index-0.rs3
-rw-r--r--src/test/ui/array-slice-vec/array_const_index-0.stderr20
-rw-r--r--src/test/ui/array-slice-vec/array_const_index-1.rs3
-rw-r--r--src/test/ui/array-slice-vec/array_const_index-1.stderr20
-rw-r--r--src/test/ui/asm/aarch64/bad-reg.rs2
-rw-r--r--src/test/ui/asm/aarch64/may_unwind.rs2
-rw-r--r--src/test/ui/asm/aarch64/sym.rs2
-rw-r--r--src/test/ui/asm/aarch64/type-check-2-2.rs2
-rw-r--r--src/test/ui/asm/aarch64/type-check-2-2.stderr10
-rw-r--r--src/test/ui/asm/aarch64/type-check-2.rs2
-rw-r--r--src/test/ui/asm/aarch64/type-check-3.stderr2
-rw-r--r--src/test/ui/asm/bad-template.aarch64_mirunsafeck.stderr2
-rw-r--r--src/test/ui/asm/bad-template.aarch64_thirunsafeck.stderr2
-rw-r--r--src/test/ui/asm/bad-template.x86_64_mirunsafeck.stderr2
-rw-r--r--src/test/ui/asm/bad-template.x86_64_thirunsafeck.stderr2
-rw-r--r--src/test/ui/asm/generic-const.rs2
-rw-r--r--src/test/ui/asm/naked-functions-ffi.stderr2
-rw-r--r--src/test/ui/asm/naked-functions.rs2
-rw-r--r--src/test/ui/asm/named-asm-labels.stderr6
-rw-r--r--src/test/ui/asm/type-check-1.rs2
-rw-r--r--src/test/ui/asm/unpretty-expanded.rs1
-rw-r--r--src/test/ui/asm/unpretty-expanded.stdout1
-rw-r--r--src/test/ui/asm/x86_64/bad-reg.rs2
-rw-r--r--src/test/ui/asm/x86_64/issue-96797.rs2
-rw-r--r--src/test/ui/asm/x86_64/may_unwind.rs2
-rw-r--r--src/test/ui/asm/x86_64/multiple-clobber-abi.rs2
-rw-r--r--src/test/ui/asm/x86_64/sym.rs2
-rw-r--r--src/test/ui/asm/x86_64/type-check-2.rs2
-rw-r--r--src/test/ui/asm/x86_64/type-check-3.stderr2
-rw-r--r--src/test/ui/asm/x86_64/type-check-4.rs5
-rw-r--r--src/test/ui/asm/x86_64/type-check-4.stderr6
-rw-r--r--src/test/ui/asm/x86_64/type-check-5.rs2
-rw-r--r--src/test/ui/asm/x86_64/type-check-5.stderr10
-rw-r--r--src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr2
-rw-r--r--src/test/ui/associated-consts/defaults-not-assumed-fail.rs4
-rw-r--r--src/test/ui/associated-consts/defaults-not-assumed-fail.stderr39
-rw-r--r--src/test/ui/associated-consts/mismatched_impl_ty_1.rs18
-rw-r--r--src/test/ui/associated-consts/mismatched_impl_ty_2.rs11
-rw-r--r--src/test/ui/associated-consts/mismatched_impl_ty_3.rs11
-rw-r--r--src/test/ui/associated-item/associated-item-duplicate-names-2.stderr8
-rw-r--r--src/test/ui/associated-item/associated-item-duplicate-names-3.rs1
-rw-r--r--src/test/ui/associated-item/associated-item-duplicate-names-3.stderr18
-rw-r--r--src/test/ui/associated-item/associated-item-duplicate-names.stderr14
-rw-r--r--src/test/ui/associated-item/impl-duplicate-methods.rs (renamed from src/test/ui/impl-duplicate-methods.rs)2
-rw-r--r--src/test/ui/associated-item/impl-duplicate-methods.stderr11
-rw-r--r--src/test/ui/associated-type-bounds/inside-adt.rs4
-rw-r--r--src/test/ui/associated-type-bounds/inside-adt.stderr10
-rw-r--r--src/test/ui/associated-types/cache/project-fn-ret-invariant.oneuse.stderr10
-rw-r--r--src/test/ui/associated-types/cache/project-fn-ret-invariant.rs2
-rw-r--r--src/test/ui/associated-types/defaults-specialization.stderr2
-rw-r--r--src/test/ui/associated-types/issue-85103.rs2
-rw-r--r--src/test/ui/associated-types/issue-85103.stderr2
-rw-r--r--src/test/ui/associated-types/issue-87261.rs6
-rw-r--r--src/test/ui/associated-types/issue-87261.stderr18
-rw-r--r--src/test/ui/async-await/async-fn-nonsend.stderr2
-rw-r--r--src/test/ui/async-await/async-fn-size-moved-locals.rs2
-rw-r--r--src/test/ui/async-await/async-fn-size-uninit-locals.rs5
-rw-r--r--src/test/ui/async-await/async-trait-fn.rs3
-rw-r--r--src/test/ui/async-await/async-trait-fn.stderr62
-rw-r--r--src/test/ui/async-await/await-keyword/2015-edition-error-various-positions.stderr4
-rw-r--r--src/test/ui/async-await/await-keyword/2015-edition-warning.stderr4
-rw-r--r--src/test/ui/async-await/await-keyword/2018-edition-error-in-non-macro-position.stderr4
-rw-r--r--src/test/ui/async-await/edition-deny-async-fns-2015.rs1
-rw-r--r--src/test/ui/async-await/edition-deny-async-fns-2015.stderr28
-rw-r--r--src/test/ui/async-await/feature-gate-async_fn_in_trait.rs25
-rw-r--r--src/test/ui/async-await/feature-gate-async_fn_in_trait.stderr42
-rw-r--r--src/test/ui/async-await/in-trait/async-associated-types.rs24
-rw-r--r--src/test/ui/async-await/in-trait/async-associated-types.stderr57
-rw-r--r--src/test/ui/async-await/in-trait/async-associated-types2.rs30
-rw-r--r--src/test/ui/async-await/in-trait/async-example-desugared-boxed-in-trait.rs21
-rw-r--r--src/test/ui/async-await/in-trait/async-example-desugared-boxed-in-trait.stderr17
-rw-r--r--src/test/ui/async-await/in-trait/async-example-desugared-boxed.rs24
-rw-r--r--src/test/ui/async-await/in-trait/async-example-desugared-in-trait.rs21
-rw-r--r--src/test/ui/async-await/in-trait/async-example-desugared.rs23
-rw-r--r--src/test/ui/async-await/in-trait/async-example.rs32
-rw-r--r--src/test/ui/async-await/in-trait/async-generics-and-bounds.rs21
-rw-r--r--src/test/ui/async-await/in-trait/async-generics-and-bounds.stderr37
-rw-r--r--src/test/ui/async-await/in-trait/async-generics.rs18
-rw-r--r--src/test/ui/async-await/in-trait/async-generics.stderr37
-rw-r--r--src/test/ui/async-await/in-trait/async-lifetimes-and-bounds.rs20
-rw-r--r--src/test/ui/async-await/in-trait/async-lifetimes-and-bounds.stderr23
-rw-r--r--src/test/ui/async-await/in-trait/async-lifetimes.rs18
-rw-r--r--src/test/ui/async-await/in-trait/async-lifetimes.stderr23
-rw-r--r--src/test/ui/async-await/in-trait/async-recursive-generic.rs21
-rw-r--r--src/test/ui/async-await/in-trait/async-recursive-generic.stderr12
-rw-r--r--src/test/ui/async-await/in-trait/async-recursive.rs21
-rw-r--r--src/test/ui/async-await/in-trait/async-recursive.stderr12
-rw-r--r--src/test/ui/async-await/in-trait/fn-not-async-err.rs17
-rw-r--r--src/test/ui/async-await/in-trait/fn-not-async-err.stderr17
-rw-r--r--src/test/ui/async-await/in-trait/fn-not-async-err2.rs21
-rw-r--r--src/test/ui/async-await/in-trait/fn-not-async-err2.stderr12
-rw-r--r--src/test/ui/async-await/in-trait/issue-102138.rs46
-rw-r--r--src/test/ui/async-await/in-trait/issue-102219.rs10
-rw-r--r--src/test/ui/async-await/in-trait/issue-102310.rs15
-rw-r--r--src/test/ui/async-await/issue-64130-1-sync.rs2
-rw-r--r--src/test/ui/async-await/issue-64130-2-send.rs2
-rw-r--r--src/test/ui/async-await/issue-64130-3-other.rs2
-rw-r--r--src/test/ui/async-await/issue-66387-if-without-else.stderr2
-rw-r--r--src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr2
-rw-r--r--src/test/ui/async-await/issue-73541-3.rs (renamed from src/test/ui/issues/issue-73541-3.rs)0
-rw-r--r--src/test/ui/async-await/issue-73541-3.stderr (renamed from src/test/ui/issues/issue-73541-3.stderr)0
-rw-r--r--src/test/ui/async-await/issue-73541.rs (renamed from src/test/ui/issues/issue-73541.rs)0
-rw-r--r--src/test/ui/async-await/issue-73541.stderr (renamed from src/test/ui/issues/issue-73541.stderr)0
-rw-r--r--src/test/ui/async-await/issue-98634.rs50
-rw-r--r--src/test/ui/async-await/issue-98634.stderr60
-rw-r--r--src/test/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-panic.rs1
-rw-r--r--src/test/ui/async-await/issues/issue-95307.stderr2
-rw-r--r--src/test/ui/async-await/large_moves.attribute.stderr2
-rw-r--r--src/test/ui/async-await/large_moves.option.stderr2
-rw-r--r--src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr2
-rw-r--r--src/test/ui/async-await/no-const-async.stderr2
-rw-r--r--src/test/ui/attr-from-macro.rs20
-rw-r--r--src/test/ui/attributes/doc-attr.stderr4
-rw-r--r--src/test/ui/attributes/invalid-doc-attr.stderr6
-rw-r--r--src/test/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs6
-rw-r--r--src/test/ui/auto-traits/suspicious-impls-lint.stderr10
-rw-r--r--src/test/ui/auxiliary/attr-from-macro.rs15
-rw-r--r--src/test/ui/backtrace.rs1
-rw-r--r--src/test/ui/binding/fn-arg-incomplete-pattern-drop-order.rs1
-rw-r--r--src/test/ui/binding/issue-53114-safety-checks.stderr10
-rw-r--r--src/test/ui/binop/issue-77910-1.rs2
-rw-r--r--src/test/ui/binop/issue-77910-1.stderr12
-rw-r--r--src/test/ui/binop/issue-77910-2.stderr4
-rw-r--r--src/test/ui/block-result/consider-removing-last-semi.stderr6
-rw-r--r--src/test/ui/block-result/issue-11714.stderr2
-rw-r--r--src/test/ui/block-result/issue-13428.stderr2
-rw-r--r--src/test/ui/borrowck/anonymous-region-in-apit.rs12
-rw-r--r--src/test/ui/borrowck/anonymous-region-in-apit.stderr16
-rw-r--r--src/test/ui/borrowck/borrowck-block-unint.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-break-uninit-2.stderr4
-rw-r--r--src/test/ui/borrowck/borrowck-break-uninit.stderr4
-rw-r--r--src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-init-in-fru.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-init-op-equal.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-init-plus-equal.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-mut-borrow-linear-errors.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-return.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-storage-dead.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-uninit-after-item.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-uninit-field-access.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr50
-rw-r--r--src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr15
-rw-r--r--src/test/ui/borrowck/borrowck-uninit.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr10
-rw-r--r--src/test/ui/borrowck/borrowck-use-uninitialized-in-cast-trait.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr5
-rw-r--r--src/test/ui/borrowck/borrowck-while-cond.stderr5
-rw-r--r--src/test/ui/borrowck/issue-102209.rs28
-rw-r--r--src/test/ui/borrowck/issue-102209.stderr22
-rw-r--r--src/test/ui/borrowck/issue-103250.rs37
-rw-r--r--src/test/ui/borrowck/issue-103250.stderr17
-rw-r--r--src/test/ui/borrowck/issue-103624.rs31
-rw-r--r--src/test/ui/borrowck/issue-103624.stderr35
-rw-r--r--src/test/ui/borrowck/issue-17718-static-move.rs (renamed from src/test/ui/issues/issue-17718-static-move.rs)0
-rw-r--r--src/test/ui/borrowck/issue-17718-static-move.stderr (renamed from src/test/ui/issues/issue-17718-static-move.stderr)0
-rw-r--r--src/test/ui/borrowck/issue-23338-params-outlive-temps-of-body.rs (renamed from src/test/ui/issues/issue-23338-params-outlive-temps-of-body.rs)0
-rw-r--r--src/test/ui/borrowck/issue-24267-flow-exit.stderr8
-rw-r--r--src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr5
-rw-r--r--src/test/ui/borrowck/issue-81899.rs3
-rw-r--r--src/test/ui/borrowck/issue-81899.stderr23
-rw-r--r--src/test/ui/borrowck/issue-88434-minimal-example.rs3
-rw-r--r--src/test/ui/borrowck/issue-88434-minimal-example.stderr23
-rw-r--r--src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs3
-rw-r--r--src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr23
-rw-r--r--src/test/ui/borrowck/reborrow-sugg-move-then-borrow.rs26
-rw-r--r--src/test/ui/borrowck/reborrow-sugg-move-then-borrow.stderr24
-rw-r--r--src/test/ui/borrowck/suggest-assign-rvalue.rs57
-rw-r--r--src/test/ui/borrowck/suggest-assign-rvalue.stderr138
-rw-r--r--src/test/ui/borrowck/two-phase-across-loop.stderr5
-rw-r--r--src/test/ui/box/issue-95036.rs2
-rw-r--r--src/test/ui/builtin-clone-unwind.rs1
-rw-r--r--src/test/ui/cast/cast-rfc0401.rs6
-rw-r--r--src/test/ui/cast/issue-88621.rs2
-rw-r--r--src/test/ui/cast/issue-88621.stderr2
-rw-r--r--src/test/ui/catch-unwind-bang.rs1
-rw-r--r--src/test/ui/cenum_impl_drop_cast.stderr8
-rw-r--r--src/test/ui/cfg/cfg-method-receiver-ok.rs14
-rw-r--r--src/test/ui/cfg/cfg-method-receiver.rs11
-rw-r--r--src/test/ui/cfg/cfg-method-receiver.stderr24
-rw-r--r--src/test/ui/cfg/cfg-panic.rs3
-rw-r--r--src/test/ui/cfg/future-compat-crate-attributes-using-cfg_attr.stderr2
-rw-r--r--src/test/ui/check-cfg/compact-values.stderr2
-rw-r--r--src/test/ui/check-cfg/empty-values.stderr2
-rw-r--r--src/test/ui/check-cfg/invalid-cfg-value.stderr2
-rw-r--r--src/test/ui/check-cfg/no-values.stderr2
-rw-r--r--src/test/ui/check-cfg/well-known-values.stderr2
-rw-r--r--src/test/ui/check-static-values-constraints.rs2
-rw-r--r--src/test/ui/check-static-values-constraints.stderr4
-rw-r--r--src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr6
-rw-r--r--src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr4
-rw-r--r--src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr4
-rw-r--r--src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr4
-rw-r--r--src/test/ui/closures/2229_closure_analysis/issue-88118-2.stderr2
-rw-r--r--src/test/ui/closures/2229_closure_analysis/issue-90465.stderr2
-rw-r--r--src/test/ui/closures/2229_closure_analysis/match/issue-87097.stderr2
-rw-r--r--src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr5
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr2
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.stderr2
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.stderr2
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr2
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/macro.stderr2
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.stderr2
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.fixed1
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs1
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.stderr4
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr2
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/precise.stderr2
-rw-r--r--src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.stderr2
-rw-r--r--src/test/ui/closures/closure-bounds-subtype.stderr4
-rw-r--r--src/test/ui/closures/closure-reform-bad.stderr2
-rw-r--r--src/test/ui/closures/closure-return-type-must-be-sized.rs74
-rw-r--r--src/test/ui/closures/closure-return-type-must-be-sized.stderr99
-rw-r--r--src/test/ui/closures/closure_promotion.rs2
-rw-r--r--src/test/ui/closures/issue-101696.rs36
-rw-r--r--src/test/ui/closures/issue-102089-multiple-opaque-cast.rs17
-rw-r--r--src/test/ui/closures/issue-97607.rs12
-rw-r--r--src/test/ui/closures/multiple-fn-bounds.rs15
-rw-r--r--src/test/ui/closures/multiple-fn-bounds.stderr24
-rw-r--r--src/test/ui/closures/old-closure-expression-remove-semicolon.fixed2
-rw-r--r--src/test/ui/closures/old-closure-expression-remove-semicolon.rs2
-rw-r--r--src/test/ui/closures/old-closure-expression-remove-semicolon.stderr2
-rw-r--r--src/test/ui/codemap_tests/unicode.normal.stderr2
-rw-r--r--src/test/ui/coercion/coercion-missing-tail-expected-type.stderr4
-rw-r--r--src/test/ui/coercion/issue-36007.rs20
-rw-r--r--src/test/ui/coherence/coherence-default-trait-impl.stderr12
-rw-r--r--src/test/ui/coherence/coherence-fn-covariant-bound-vs-static.stderr4
-rw-r--r--src/test/ui/coherence/coherence-fn-implied-bounds.stderr6
-rw-r--r--src/test/ui/coherence/coherence-free-vs-bound-region.stderr6
-rw-r--r--src/test/ui/coherence/coherence-inherited-assoc-ty-cycle-err.stderr2
-rw-r--r--src/test/ui/coherence/coherence-negative-impls-copy-bad.rs11
-rw-r--r--src/test/ui/coherence/coherence-negative-impls-copy-bad.stderr36
-rw-r--r--src/test/ui/coherence/coherence-negative-impls-copy.rs29
-rw-r--r--src/test/ui/coherence/coherence-subtyping.stderr2
-rw-r--r--src/test/ui/coherence/coherence-wasm-bindgen.stderr8
-rw-r--r--src/test/ui/coherence/deep-bad-copy-reason.stderr4
-rw-r--r--src/test/ui/command/command-current-dir.rs1
-rw-r--r--src/test/ui/command/command-exec.rs1
-rw-r--r--src/test/ui/command/command-pre-exec.rs1
-rw-r--r--src/test/ui/command/command-uid-gid.rs1
-rw-r--r--src/test/ui/compare-method/issue-90444.stderr6
-rw-r--r--src/test/ui/conflicting-repr-hints.stderr2
-rw-r--r--src/test/ui/const-generics/const-generic-default-wont-borrowck.stderr5
-rw-r--r--src/test/ui/const-generics/const_trait_fn-issue-88433.rs1
-rw-r--r--src/test/ui/const-generics/generic_const_exprs/closures.stderr4
-rw-r--r--src/test/ui/const-generics/generic_const_exprs/dependence_lint.full.stderr10
-rw-r--r--src/test/ui/const-generics/generic_const_exprs/dependence_lint.gce.stderr8
-rw-r--r--src/test/ui/const-generics/generic_const_exprs/dependence_lint.rs1
-rw-r--r--src/test/ui/const-generics/generic_const_exprs/eval-try-unify.stderr2
-rw-r--r--src/test/ui/const-generics/generic_const_exprs/function-call.rs1
-rw-r--r--src/test/ui/const-generics/generic_const_exprs/function-call.stderr4
-rw-r--r--src/test/ui/const-generics/generic_const_exprs/issue-102074.rs23
-rw-r--r--src/test/ui/const-generics/generic_const_exprs/issue-102768.rs14
-rw-r--r--src/test/ui/const-generics/generic_const_exprs/issue-102768.stderr33
-rw-r--r--src/test/ui/const-generics/generic_const_exprs/issue-97047-ice-1.stderr2
-rw-r--r--src/test/ui/const-generics/generic_const_exprs/issue-97047-ice-2.stderr2
-rw-r--r--src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.stderr10
-rw-r--r--src/test/ui/const-generics/invariant.stderr2
-rw-r--r--src/test/ui/const-generics/issue-102124.rs20
-rw-r--r--src/test/ui/const-generics/issue-103243.rs37
-rw-r--r--src/test/ui/const-generics/issue-80471.stderr2
-rw-r--r--src/test/ui/const-generics/issue-93647.rs2
-rw-r--r--src/test/ui/const-generics/issues/issue-83466.stderr2
-rw-r--r--src/test/ui/const-generics/issues/issue-83765.stderr8
-rw-r--r--src/test/ui/const-generics/issues/issue-88119.rs1
-rw-r--r--src/test/ui/const-generics/issues/issue-98629.rs1
-rw-r--r--src/test/ui/const-generics/issues/issue-98629.stderr2
-rw-r--r--src/test/ui/const-generics/min_const_generics/complex-expression.rs1
-rw-r--r--src/test/ui/const-generics/min_const_generics/complex-expression.stderr18
-rw-r--r--src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.rs1
-rw-r--r--src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.stderr8
-rw-r--r--src/test/ui/const-generics/occurs-check/unify-fixpoint.stderr2
-rw-r--r--src/test/ui/const-generics/occurs-check/unused-substs-2.rs2
-rw-r--r--src/test/ui/const-generics/occurs-check/unused-substs-3.rs2
-rw-r--r--src/test/ui/const-ptr/forbidden_slices.32bit.stderr16
-rw-r--r--src/test/ui/const-ptr/forbidden_slices.64bit.stderr16
-rw-r--r--src/test/ui/const_prop/issue-102553.rs24
-rw-r--r--src/test/ui/consts/array-literal-index-oob.rs2
-rw-r--r--src/test/ui/consts/array-literal-index-oob.stderr6
-rw-r--r--src/test/ui/consts/assert-type-intrinsics.rs7
-rw-r--r--src/test/ui/consts/assert-type-intrinsics.stderr70
-rw-r--r--src/test/ui/consts/assoc_const_generic_impl.rs7
-rw-r--r--src/test/ui/consts/assoc_const_generic_impl.stderr40
-rw-r--r--src/test/ui/consts/cast-discriminant-zst-enum.rs1
-rw-r--r--src/test/ui/consts/const-err-early.rs17
-rw-r--r--src/test/ui/consts/const-err-early.stderr126
-rw-r--r--src/test/ui/consts/const-err-late.rs22
-rw-r--r--src/test/ui/consts/const-err-late.stderr27
-rw-r--r--src/test/ui/consts/const-err-multi.rs14
-rw-r--r--src/test/ui/consts/const-err-multi.stderr102
-rw-r--r--src/test/ui/consts/const-err-rpass.rs2
-rw-r--r--src/test/ui/consts/const-err.rs19
-rw-r--r--src/test/ui/consts/const-err.stderr44
-rw-r--r--src/test/ui/consts/const-eval/conditional_array_execution.rs10
-rw-r--r--src/test/ui/consts/const-eval/conditional_array_execution.stderr63
-rw-r--r--src/test/ui/consts/const-eval/const-eval-overflow-2.rs4
-rw-r--r--src/test/ui/consts/const-eval/const-eval-overflow-2.stderr24
-rw-r--r--src/test/ui/consts/const-eval/const-eval-overflow-3b.stderr4
-rw-r--r--src/test/ui/consts/const-eval/const-eval-overflow-4b.stderr4
-rw-r--r--src/test/ui/consts/const-eval/const-eval-overflow2.rs26
-rw-r--r--src/test/ui/consts/const-eval/const-eval-overflow2.stderr226
-rw-r--r--src/test/ui/consts/const-eval/const-eval-overflow2b.rs26
-rw-r--r--src/test/ui/consts/const-eval/const-eval-overflow2b.stderr226
-rw-r--r--src/test/ui/consts/const-eval/const-eval-overflow2c.rs26
-rw-r--r--src/test/ui/consts/const-eval/const-eval-overflow2c.stderr226
-rw-r--r--src/test/ui/consts/const-eval/const-eval-query-stack.rs10
-rw-r--r--src/test/ui/consts/const-eval/const-eval-query-stack.stderr64
-rw-r--r--src/test/ui/consts/const-eval/const-pointer-values-in-various-types.64bit.stderr570
-rw-r--r--src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs81
-rw-r--r--src/test/ui/consts/const-eval/const_fn_ptr_fail2.rs7
-rw-r--r--src/test/ui/consts/const-eval/const_fn_ptr_fail2.stderr92
-rw-r--r--src/test/ui/consts/const-eval/const_let.rs8
-rw-r--r--src/test/ui/consts/const-eval/const_let.stderr16
-rw-r--r--src/test/ui/consts/const-eval/const_panic_stability.e2018.stderr2
-rw-r--r--src/test/ui/consts/const-eval/const_raw_ptr_ops.stderr20
-rw-r--r--src/test/ui/consts/const-eval/erroneous-const.rs6
-rw-r--r--src/test/ui/consts/const-eval/erroneous-const.stderr45
-rw-r--r--src/test/ui/consts/const-eval/erroneous-const2.rs6
-rw-r--r--src/test/ui/consts/const-eval/erroneous-const2.stderr41
-rw-r--r--src/test/ui/consts/const-eval/format.rs4
-rw-r--r--src/test/ui/consts/const-eval/format.stderr78
-rw-r--r--src/test/ui/consts/const-eval/index-out-of-bounds-never-type.rs6
-rw-r--r--src/test/ui/consts/const-eval/index-out-of-bounds-never-type.stderr38
-rw-r--r--src/test/ui/consts/const-eval/infinite_loop.rs2
-rw-r--r--src/test/ui/consts/const-eval/infinite_loop.stderr6
-rw-r--r--src/test/ui/consts/const-eval/issue-100878.rs8
-rw-r--r--src/test/ui/consts/const-eval/issue-43197.rs16
-rw-r--r--src/test/ui/consts/const-eval/issue-43197.stderr119
-rw-r--r--src/test/ui/consts/const-eval/issue-44578.rs5
-rw-r--r--src/test/ui/consts/const-eval/issue-44578.stderr43
-rw-r--r--src/test/ui/consts/const-eval/issue-50814-2.rs3
-rw-r--r--src/test/ui/consts/const-eval/issue-50814-2.stderr23
-rw-r--r--src/test/ui/consts/const-eval/issue-50814.rs3
-rw-r--r--src/test/ui/consts/const-eval/issue-50814.stderr23
-rw-r--r--src/test/ui/consts/const-eval/issue-65394.rs2
-rw-r--r--src/test/ui/consts/const-eval/issue-65394.stderr4
-rw-r--r--src/test/ui/consts/const-eval/livedrop.rs2
-rw-r--r--src/test/ui/consts/const-eval/livedrop.stderr4
-rw-r--r--src/test/ui/consts/const-eval/panic-assoc-never-type.rs1
-rw-r--r--src/test/ui/consts/const-eval/panic-assoc-never-type.stderr6
-rw-r--r--src/test/ui/consts/const-eval/panic-never-type.rs1
-rw-r--r--src/test/ui/consts/const-eval/panic-never-type.stderr4
-rw-r--r--src/test/ui/consts/const-eval/partial_ptr_overwrite.rs3
-rw-r--r--src/test/ui/consts/const-eval/partial_ptr_overwrite.stderr25
-rw-r--r--src/test/ui/consts/const-eval/promoted_const_fn_fail.rs2
-rw-r--r--src/test/ui/consts/const-eval/promoted_const_fn_fail.stderr2
-rw-r--r--src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs2
-rw-r--r--src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr2
-rw-r--r--src/test/ui/consts/const-eval/promoted_errors.noopt.stderr93
-rw-r--r--src/test/ui/consts/const-eval/promoted_errors.opt.stderr95
-rw-r--r--src/test/ui/consts/const-eval/promoted_errors.opt_with_overflow_checks.stderr93
-rw-r--r--src/test/ui/consts/const-eval/promoted_errors.rs25
-rw-r--r--src/test/ui/consts/const-eval/pub_const_err.rs10
-rw-r--r--src/test/ui/consts/const-eval/pub_const_err.stderr31
-rw-r--r--src/test/ui/consts/const-eval/pub_const_err_bin.rs10
-rw-r--r--src/test/ui/consts/const-eval/pub_const_err_bin.stderr31
-rw-r--r--src/test/ui/consts/const-eval/ref_to_int_match.32bit.stderr21
-rw-r--r--src/test/ui/consts/const-eval/ref_to_int_match.64bit.stderr21
-rw-r--r--src/test/ui/consts/const-eval/ref_to_int_match.rs3
-rw-r--r--src/test/ui/consts/const-eval/ub-enum.32bit.stderr110
-rw-r--r--src/test/ui/consts/const-eval/ub-enum.64bit.stderr110
-rw-r--r--src/test/ui/consts/const-eval/ub-enum.rs16
-rw-r--r--src/test/ui/consts/const-eval/ub-int-array.32bit.stderr6
-rw-r--r--src/test/ui/consts/const-eval/ub-int-array.64bit.stderr6
-rw-r--r--src/test/ui/consts/const-eval/ub-int-array.rs1
-rw-r--r--src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr12
-rw-r--r--src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr12
-rw-r--r--src/test/ui/consts/const-eval/ub-nonnull.rs3
-rw-r--r--src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr114
-rw-r--r--src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr114
-rw-r--r--src/test/ui/consts/const-eval/ub-ref-ptr.rs15
-rw-r--r--src/test/ui/consts/const-eval/ub-uninhabit.32bit.stderr6
-rw-r--r--src/test/ui/consts/const-eval/ub-uninhabit.64bit.stderr6
-rw-r--r--src/test/ui/consts/const-eval/ub-uninhabit.rs1
-rw-r--r--src/test/ui/consts/const-eval/ub-upvars.rs2
-rw-r--r--src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr187
-rw-r--r--src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr187
-rw-r--r--src/test/ui/consts/const-eval/ub-wide-ptr.rs24
-rw-r--r--src/test/ui/consts/const-eval/union-ub.32bit.stderr4
-rw-r--r--src/test/ui/consts/const-eval/union-ub.64bit.stderr4
-rw-r--r--src/test/ui/consts/const-eval/union-ub.rs1
-rw-r--r--src/test/ui/consts/const-eval/union_promotion.rs2
-rw-r--r--src/test/ui/consts/const-eval/union_promotion.stderr2
-rw-r--r--src/test/ui/consts/const-eval/unused-broken-const.rs3
-rw-r--r--src/test/ui/consts/const-eval/unused-broken-const.stderr20
-rw-r--r--src/test/ui/consts/const-eval/valid-const.rs1
-rw-r--r--src/test/ui/consts/const-eval/validate_uninhabited_zsts.32bit.stderr16
-rw-r--r--src/test/ui/consts/const-eval/validate_uninhabited_zsts.64bit.stderr16
-rw-r--r--src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs2
-rw-r--r--src/test/ui/consts/const-external-macro-const-err.rs3
-rw-r--r--src/test/ui/consts/const-external-macro-const-err.stderr18
-rw-r--r--src/test/ui/consts/const-float-bits-reject-conv.rs24
-rw-r--r--src/test/ui/consts/const-float-bits-reject-conv.stderr199
-rw-r--r--src/test/ui/consts/const-fn-error.rs6
-rw-r--r--src/test/ui/consts/const-fn-error.stderr4
-rw-r--r--src/test/ui/consts/const-for.rs4
-rw-r--r--src/test/ui/consts/const-for.stderr4
-rw-r--r--src/test/ui/consts/const-int-arithmetic-overflow.rs1
-rw-r--r--src/test/ui/consts/const-len-underflow-separate-spans.rs3
-rw-r--r--src/test/ui/consts/const-len-underflow-separate-spans.stderr21
-rw-r--r--src/test/ui/consts/const-negation.rs2
-rw-r--r--src/test/ui/consts/const-prop-read-static-in-const.rs3
-rw-r--r--src/test/ui/consts/const-prop-read-static-in-const.stderr20
-rw-r--r--src/test/ui/consts/const-size_of_val-align_of_val-extern-type.rs6
-rw-r--r--src/test/ui/consts/const-size_of_val-align_of_val-extern-type.stderr40
-rw-r--r--src/test/ui/consts/const-slice-oob.rs5
-rw-r--r--src/test/ui/consts/const-slice-oob.stderr22
-rw-r--r--src/test/ui/consts/const_discriminant.rs1
-rw-r--r--src/test/ui/consts/const_in_pattern/custom-eq-branch-warn.stderr2
-rw-r--r--src/test/ui/consts/const_in_pattern/incomplete-slice.stderr2
-rw-r--r--src/test/ui/consts/const_in_pattern/issue-44333.stderr4
-rw-r--r--src/test/ui/consts/const_in_pattern/reject_non_structural.stderr4
-rw-r--r--src/test/ui/consts/const_in_pattern/warn_corner_cases.stderr2
-rw-r--r--src/test/ui/consts/const_limit/const_eval_limit_reached.rs3
-rw-r--r--src/test/ui/consts/const_limit/const_eval_limit_reached.stderr24
-rw-r--r--src/test/ui/consts/const_unsafe_unreachable_ub.stderr10
-rw-r--r--src/test/ui/consts/constifconst-call-in-const-position.rs22
-rw-r--r--src/test/ui/consts/constifconst-call-in-const-position.stderr18
-rw-r--r--src/test/ui/consts/control-flow/drop-fail.precise.stderr8
-rw-r--r--src/test/ui/consts/control-flow/drop-fail.rs8
-rw-r--r--src/test/ui/consts/control-flow/drop-fail.stock.stderr16
-rw-r--r--src/test/ui/consts/control-flow/issue-50577.stderr2
-rw-r--r--src/test/ui/consts/dangling-alloc-id-ice.rs1
-rw-r--r--src/test/ui/consts/dangling-alloc-id-ice.stderr2
-rw-r--r--src/test/ui/consts/drop_box.rs2
-rw-r--r--src/test/ui/consts/drop_box.stderr4
-rw-r--r--src/test/ui/consts/drop_zst.stderr4
-rw-r--r--src/test/ui/consts/extra-const-ub/detect-extra-ub.rs9
-rw-r--r--src/test/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr75
-rw-r--r--src/test/ui/consts/invalid-union.32bit.stderr17
-rw-r--r--src/test/ui/consts/invalid-union.64bit.stderr17
-rw-r--r--src/test/ui/consts/invalid-union.rs1
-rw-r--r--src/test/ui/consts/issue-102117.rs30
-rw-r--r--src/test/ui/consts/issue-102117.stderr37
-rw-r--r--src/test/ui/consts/issue-104155.rs5
-rw-r--r--src/test/ui/consts/issue-17718-constants-not-static.rs (renamed from src/test/ui/issues/issue-17718-constants-not-static.rs)0
-rw-r--r--src/test/ui/consts/issue-17718-constants-not-static.stderr (renamed from src/test/ui/issues/issue-17718-constants-not-static.stderr)0
-rw-r--r--src/test/ui/consts/issue-25826.stderr4
-rw-r--r--src/test/ui/consts/issue-46553.rs1
-rw-r--r--src/test/ui/consts/issue-56164.rs5
-rw-r--r--src/test/ui/consts/issue-56164.stderr22
-rw-r--r--src/test/ui/consts/issue-66693.rs3
-rw-r--r--src/test/ui/consts/issue-66693.stderr18
-rw-r--r--src/test/ui/consts/issue-78655.stderr5
-rw-r--r--src/test/ui/consts/issue-88071.rs2
-rw-r--r--src/test/ui/consts/issue-94675.rs5
-rw-r--r--src/test/ui/consts/issue-94675.stderr31
-rw-r--r--src/test/ui/consts/issue-miri-1910.stderr42
-rw-r--r--src/test/ui/consts/min_const_fn/min_const_fn.rs6
-rw-r--r--src/test/ui/consts/min_const_fn/min_const_fn.stderr20
-rw-r--r--src/test/ui/consts/miri_unleashed/abi-mismatch.rs1
-rw-r--r--src/test/ui/consts/miri_unleashed/abi-mismatch.stderr8
-rw-r--r--src/test/ui/consts/miri_unleashed/assoc_const.rs2
-rw-r--r--src/test/ui/consts/miri_unleashed/assoc_const.stderr46
-rw-r--r--src/test/ui/consts/miri_unleashed/assoc_const_2.rs4
-rw-r--r--src/test/ui/consts/miri_unleashed/assoc_const_2.stderr25
-rw-r--r--src/test/ui/consts/miri_unleashed/box.rs1
-rw-r--r--src/test/ui/consts/miri_unleashed/box.stderr10
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static.32bit.stderr81
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static.64bit.stderr81
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static.rs34
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr100
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static2.32bit.stderr38
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static2.64bit.stderr38
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static2.rs24
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr104
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr104
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs14
-rw-r--r--src/test/ui/consts/miri_unleashed/drop.rs1
-rw-r--r--src/test/ui/consts/miri_unleashed/drop.stderr6
-rw-r--r--src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs4
-rw-r--r--src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr6
-rw-r--r--src/test/ui/consts/miri_unleashed/inline_asm.rs1
-rw-r--r--src/test/ui/consts/miri_unleashed/inline_asm.stderr4
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_references.rs1
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_references.stderr12
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_references_err.32bit.stderr12
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_references_err.64bit.stderr12
-rw-r--r--src/test/ui/consts/miri_unleashed/mutable_references_err.rs2
-rw-r--r--src/test/ui/consts/miri_unleashed/mutating_global.rs1
-rw-r--r--src/test/ui/consts/miri_unleashed/mutating_global.stderr2
-rw-r--r--src/test/ui/consts/miri_unleashed/non_const_fn.rs2
-rw-r--r--src/test/ui/consts/miri_unleashed/non_const_fn.stderr4
-rw-r--r--src/test/ui/consts/miri_unleashed/ptr_arith.rs1
-rw-r--r--src/test/ui/consts/miri_unleashed/ptr_arith.stderr6
-rw-r--r--src/test/ui/consts/miri_unleashed/raw_mutable_const.rs2
-rw-r--r--src/test/ui/consts/miri_unleashed/raw_mutable_const.stderr4
-rw-r--r--src/test/ui/consts/miri_unleashed/tls.rs1
-rw-r--r--src/test/ui/consts/miri_unleashed/tls.stderr8
-rw-r--r--src/test/ui/consts/promote-not.rs2
-rw-r--r--src/test/ui/consts/ptr_comparisons.rs6
-rw-r--r--src/test/ui/consts/ptr_comparisons.stderr41
-rw-r--r--src/test/ui/consts/qualif-indirect-mutation-fail.rs18
-rw-r--r--src/test/ui/consts/qualif-indirect-mutation-fail.stderr36
-rw-r--r--src/test/ui/consts/raw-ptr-const.rs2
-rw-r--r--src/test/ui/consts/raw-ptr-const.stderr2
-rw-r--r--src/test/ui/consts/recursive.rs3
-rw-r--r--src/test/ui/consts/recursive.stderr31
-rw-r--r--src/test/ui/consts/refs_check_const_eq-issue-88384.stderr2
-rw-r--r--src/test/ui/consts/stable-precise-live-drops-in-libcore.rs2
-rw-r--r--src/test/ui/consts/stable-precise-live-drops-in-libcore.stderr4
-rw-r--r--src/test/ui/consts/trait_specialization.stderr2
-rw-r--r--src/test/ui/consts/uninhabited-const-issue-61744.rs3
-rw-r--r--src/test/ui/consts/uninhabited-const-issue-61744.stderr285
-rw-r--r--src/test/ui/consts/unstable-const-fn-in-libcore.rs10
-rw-r--r--src/test/ui/consts/unstable-const-fn-in-libcore.stderr33
-rw-r--r--src/test/ui/consts/write_to_static_via_mut_ref.rs1
-rw-r--r--src/test/ui/consts/write_to_static_via_mut_ref.stderr4
-rw-r--r--src/test/ui/deprecation/deprecation-lint.rs2
-rw-r--r--src/test/ui/derive-uninhabited-enum-38885.stderr2
-rw-r--r--src/test/ui/derives/clone-debug-dead-code-in-the-same-struct.stderr2
-rw-r--r--src/test/ui/derives/deriving-with-repr-packed.stderr20
-rw-r--r--src/test/ui/deriving/deriving-all-codegen.stdout72
-rw-r--r--src/test/ui/deriving/deriving-default-enum.rs10
-rw-r--r--src/test/ui/deriving/deriving-hash.rs20
-rw-r--r--src/test/ui/destructuring-assignment/warn-unused-duplication.stderr2
-rw-r--r--src/test/ui/did_you_mean/bad-assoc-ty.stderr2
-rw-r--r--src/test/ui/did_you_mean/issue-31424.stderr2
-rw-r--r--src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.fixed5
-rw-r--r--src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs5
-rw-r--r--src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr34
-rw-r--r--src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.stderr16
-rw-r--r--src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.stderr10
-rw-r--r--src/test/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.stderr4
-rw-r--r--src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr16
-rw-r--r--src/test/ui/did_you_mean/issue-54109-without-witness.stderr16
-rw-r--r--src/test/ui/drop/drop_order.rs64
-rw-r--r--src/test/ui/drop/dropck_legal_cycles.rs14
-rw-r--r--src/test/ui/drop/dynamic-drop-async.rs1
-rw-r--r--src/test/ui/drop/dynamic-drop.rs1
-rw-r--r--src/test/ui/drop/issue-100276.rs12
-rw-r--r--src/test/ui/drop/issue-17718-const-destructors.rs (renamed from src/test/ui/issues/issue-17718-const-destructors.rs)0
-rw-r--r--src/test/ui/drop/issue-23338-ensure-param-drop-order.rs (renamed from src/test/ui/issues/issue-23338-ensure-param-drop-order.rs)0
-rw-r--r--src/test/ui/drop/issue-48962.rs (renamed from src/test/ui/issues/issue-48962.rs)0
-rw-r--r--src/test/ui/drop/repeat-drop-2.rs2
-rw-r--r--src/test/ui/drop/repeat-drop-2.stderr9
-rw-r--r--src/test/ui/drop/repeat-drop.rs3
-rw-r--r--src/test/ui/dropck/dropck-eyepatch-implies-unsafe-impl.stderr12
-rw-r--r--src/test/ui/dropck/issue-24805-dropck-itemless.rs (renamed from src/test/ui/issues/issue-24805-dropck-itemless.rs)0
-rw-r--r--src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.stderr4
-rw-r--r--src/test/ui/dyn-keyword/dyn-2018-edition-lint.stderr4
-rw-r--r--src/test/ui/dyn-keyword/dyn-angle-brackets.stderr4
-rw-r--r--src/test/ui/dyn-star/auxiliary/dyn-star-foreign.rs10
-rw-r--r--src/test/ui/dyn-star/box.rs17
-rw-r--r--src/test/ui/dyn-star/const.rs2
-rw-r--r--src/test/ui/dyn-star/drop.rs2
-rw-r--r--src/test/ui/dyn-star/error.rs2
-rw-r--r--src/test/ui/dyn-star/error.stderr2
-rw-r--r--src/test/ui/dyn-star/make-dyn-star.rs5
-rw-r--r--src/test/ui/dyn-star/method.rs3
-rw-r--r--src/test/ui/dyn-star/no-explicit-dyn-star-cast.rs13
-rw-r--r--src/test/ui/dyn-star/no-explicit-dyn-star-cast.stderr28
-rw-r--r--src/test/ui/dyn-star/no-explicit-dyn-star.rs8
-rw-r--r--src/test/ui/dyn-star/no-explicit-dyn-star.stderr9
-rw-r--r--src/test/ui/dyn-star/no-implicit-dyn-star.rs8
-rw-r--r--src/test/ui/dyn-star/no-implicit-dyn-star.stderr19
-rw-r--r--src/test/ui/dyn-star/upcast.rs33
-rw-r--r--src/test/ui/editions/edition-raw-pointer-method-2015.stderr4
-rw-r--r--src/test/ui/empty/empty-attributes.stderr2
-rw-r--r--src/test/ui/empty/empty-struct-braces-expr.stderr46
-rw-r--r--src/test/ui/empty_global_asm.rs15
-rw-r--r--src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.rs1
-rw-r--r--src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr2
-rw-r--r--src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs2
-rw-r--r--src/test/ui/enum-discriminant/discriminant_size.stderr2
-rw-r--r--src/test/ui/enum-discriminant/discriminant_value.rs2
-rw-r--r--src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.rs10
-rw-r--r--src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.stderr36
-rw-r--r--src/test/ui/enum-discriminant/issue-43398.stderr2
-rw-r--r--src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs2
-rw-r--r--src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.rs2
-rw-r--r--src/test/ui/enum-discriminant/issue-70509-partial_eq.rs2
-rw-r--r--src/test/ui/enum-discriminant/issue-70509-partial_eq.stderr4
-rw-r--r--src/test/ui/enum-discriminant/repr128.stderr2
-rw-r--r--src/test/ui/enum/enum-discrim-too-small2.stderr4
-rw-r--r--src/test/ui/error-codes/E0017.stderr2
-rw-r--r--src/test/ui/error-codes/E0094.rs2
-rw-r--r--src/test/ui/error-codes/E0094.stderr2
-rw-r--r--src/test/ui/error-codes/E0199.stderr6
-rw-r--r--src/test/ui/error-codes/E0200.stderr6
-rw-r--r--src/test/ui/error-codes/E0201.rs2
-rw-r--r--src/test/ui/error-codes/E0201.stderr33
-rw-r--r--src/test/ui/error-codes/E0283.stderr4
-rw-r--r--src/test/ui/error-codes/E0308.rs2
-rw-r--r--src/test/ui/error-codes/E0308.stderr2
-rw-r--r--src/test/ui/error-codes/E0311.rs9
-rw-r--r--src/test/ui/error-codes/E0311.stderr24
-rw-r--r--src/test/ui/error-codes/E0388.stderr2
-rw-r--r--src/test/ui/error-codes/E0423.stderr22
-rw-r--r--src/test/ui/error-codes/E0520.stderr2
-rw-r--r--src/test/ui/error-codes/E0585.stderr2
-rw-r--r--src/test/ui/error-codes/E0771.stderr2
-rw-r--r--src/test/ui/error-codes/E0790.stderr20
-rw-r--r--src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.stderr2
-rw-r--r--src/test/ui/explain.stdout4
-rw-r--r--src/test/ui/expr/if/bad-if-let-suggestion.stderr5
-rw-r--r--src/test/ui/expr/if/if-let.stderr2
-rw-r--r--src/test/ui/expr/if/if-without-else-result.rs2
-rw-r--r--src/test/ui/expr/if/if-without-else-result.stderr2
-rw-r--r--src/test/ui/expr/if/issue-4201.rs2
-rw-r--r--src/test/ui/expr/if/issue-4201.stderr2
-rw-r--r--src/test/ui/expr/malformed_closure/ruby_style_closure.stderr2
-rw-r--r--src/test/ui/extenv/issue-55897.rs2
-rw-r--r--src/test/ui/extenv/issue-55897.stderr7
-rw-r--r--src/test/ui/extern-flag/empty-extern-arg.rs2
-rw-r--r--src/test/ui/extern/extern-no-mangle.stderr2
-rw-r--r--src/test/ui/extern/extern-with-type-bounds.rs2
-rw-r--r--src/test/ui/extern/extern-with-type-bounds.stderr2
-rw-r--r--src/test/ui/extern/issue-64655-allow-unwind-when-calling-panic-directly.rs1
-rw-r--r--src/test/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs1
-rw-r--r--src/test/ui/feature-gates/bench.stderr2
-rw-r--r--src/test/ui/feature-gates/feature-gate-asm_sym.rs19
-rw-r--r--src/test/ui/feature-gates/feature-gate-asm_sym.stderr21
-rw-r--r--src/test/ui/feature-gates/feature-gate-default_type_parameter_fallback.stderr2
-rw-r--r--src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr2
-rw-r--r--src/test/ui/feature-gates/feature-gate-repr-simd.stderr2
-rw-r--r--src/test/ui/feature-gates/feature-gate-return_position_impl_trait_in_trait.rs13
-rw-r--r--src/test/ui/feature-gates/feature-gate-return_position_impl_trait_in_trait.stderr22
-rw-r--r--src/test/ui/feature-gates/feature-gate-strict_provenance.stderr2
-rw-r--r--src/test/ui/feature-gates/feature-gate-test_unstable_lint.stderr2
-rw-r--r--src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr2
-rw-r--r--src/test/ui/fmt/auxiliary/format-string-proc-macro.rs28
-rw-r--r--src/test/ui/fmt/format-args-capture-issue-102057.rs19
-rw-r--r--src/test/ui/fmt/format-args-capture-issue-102057.stderr45
-rw-r--r--src/test/ui/fmt/format-args-capture-issue-93378.rs4
-rw-r--r--src/test/ui/fmt/format-args-capture-issue-93378.stderr17
-rw-r--r--src/test/ui/fmt/format-args-capture-macro-hygiene.rs18
-rw-r--r--src/test/ui/fmt/format-args-capture-macro-hygiene.stderr37
-rw-r--r--src/test/ui/fmt/format-concat-span.stderr11
-rw-r--r--src/test/ui/fmt/format-expanded-string.rs (renamed from src/test/ui/fmt/format-concat-span.rs)9
-rw-r--r--src/test/ui/fmt/format-expanded-string.stderr19
-rw-r--r--src/test/ui/fmt/ifmt-bad-arg.rs8
-rw-r--r--src/test/ui/fmt/ifmt-bad-arg.stderr98
-rw-r--r--src/test/ui/for-loop-while/while-let-2.stderr2
-rw-r--r--src/test/ui/fully-qualified-type/fully-qualified-type-name2.stderr12
-rw-r--r--src/test/ui/function-pointer/issue-102289.rs54
-rw-r--r--src/test/ui/function-pointer/sized-ret-with-binder.rs15
-rw-r--r--src/test/ui/function-pointer/unsized-ret.rs14
-rw-r--r--src/test/ui/function-pointer/unsized-ret.stderr35
-rw-r--r--src/test/ui/future-incompatible-lint-group.stderr8
-rw-r--r--src/test/ui/generator/issue-102645.rs23
-rw-r--r--src/test/ui/generator/issue-102645.stderr19
-rw-r--r--src/test/ui/generator/issue-52398.stderr2
-rw-r--r--src/test/ui/generator/issue-57084.stderr2
-rw-r--r--src/test/ui/generator/match-bindings.stderr2
-rw-r--r--src/test/ui/generator/panic-drops-resume.rs2
-rw-r--r--src/test/ui/generator/panic-drops.rs1
-rw-r--r--src/test/ui/generator/panic-safe.rs1
-rw-r--r--src/test/ui/generator/print/generator-print-verbose-1.stderr8
-rw-r--r--src/test/ui/generator/reborrow-mut-upvar.stderr2
-rw-r--r--src/test/ui/generator/resume-after-return.rs1
-rw-r--r--src/test/ui/generator/size-moved-locals.rs1
-rw-r--r--src/test/ui/generator/too-live-local-in-immovable-gen.stderr2
-rw-r--r--src/test/ui/generator/yield-in-args-rev.stderr2
-rw-r--r--src/test/ui/generator/yield-in-box.stderr2
-rw-r--r--src/test/ui/generator/yield-in-initializer.stderr2
-rw-r--r--src/test/ui/generator/yield-subtype.stderr2
-rw-r--r--src/test/ui/generic-associated-types/bugs/issue-86218.stderr23
-rw-r--r--src/test/ui/generic-associated-types/bugs/issue-88382.stderr4
-rw-r--r--src/test/ui/generic-associated-types/bugs/issue-89008.stderr19
-rw-r--r--src/test/ui/generic-associated-types/bugs/issue-91762.rs2
-rw-r--r--src/test/ui/generic-associated-types/issue-102114.rs16
-rw-r--r--src/test/ui/generic-associated-types/issue-102114.stderr12
-rw-r--r--src/test/ui/generic-associated-types/issue-86218-2.rs23
-rw-r--r--src/test/ui/generic-associated-types/issue-86218.rs (renamed from src/test/ui/generic-associated-types/bugs/issue-86218.rs)8
-rw-r--r--src/test/ui/generic-associated-types/issue-87258_a.stderr2
-rw-r--r--src/test/ui/generic-associated-types/issue-87429-specialization.stderr2
-rw-r--r--src/test/ui/generic-associated-types/issue-89008.rs (renamed from src/test/ui/generic-associated-types/bugs/issue-89008.rs)28
-rw-r--r--src/test/ui/generics/issue-94923.rs49
-rw-r--r--src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.rs2
-rw-r--r--src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.rs2
-rw-r--r--src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.rs1
-rw-r--r--src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.stderr6
-rw-r--r--src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns-in-slices.rs7
-rw-r--r--src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns-in-slices.stderr12
-rw-r--r--src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.rs18
-rw-r--r--src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.stderr53
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.rs1
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.stderr6
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.rs1
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.stderr136
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-pass.rs1
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs2
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr10
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.rs2
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr12
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.rs2
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.stderr16
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-semantics.rs1
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-syntactic-pass.rs1
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.rs1
-rw-r--r--src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.stderr52
-rw-r--r--src/test/ui/half-open-range-patterns/pat-tuple-4.rs1
-rw-r--r--src/test/ui/half-open-range-patterns/pat-tuple-5.rs1
-rw-r--r--src/test/ui/half-open-range-patterns/pat-tuple-5.stderr2
-rw-r--r--src/test/ui/half-open-range-patterns/range_pat_interactions0.rs1
-rw-r--r--src/test/ui/half-open-range-patterns/range_pat_interactions3.rs3
-rw-r--r--src/test/ui/half-open-range-patterns/range_pat_interactions3.stderr11
-rw-r--r--src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem0.rs2
-rw-r--r--src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem1.rs1
-rw-r--r--src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem1.stderr13
-rw-r--r--src/test/ui/higher-rank-trait-bounds/hrtb-perfect-forwarding.stderr2
-rw-r--r--src/test/ui/higher-rank-trait-bounds/issue-100689.rs29
-rw-r--r--src/test/ui/higher-rank-trait-bounds/issue-102899.rs32
-rw-r--r--src/test/ui/higher-rank-trait-bounds/issue-30786.stderr10
-rw-r--r--src/test/ui/higher-rank-trait-bounds/issue-46989.stderr2
-rw-r--r--src/test/ui/higher-rank-trait-bounds/issue-95034.rs20
-rw-r--r--src/test/ui/higher-rank-trait-bounds/issue-95034.stderr1
-rw-r--r--src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-71955.stderr16
-rw-r--r--src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.rs2
-rw-r--r--src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.stderr6
-rw-r--r--src/test/ui/hygiene/globs.stderr18
-rw-r--r--src/test/ui/hygiene/impl_items-2.rs26
-rw-r--r--src/test/ui/hygiene/impl_items-2.stderr15
-rw-r--r--src/test/ui/hygiene/impl_items.rs2
-rw-r--r--src/test/ui/hygiene/impl_items.stderr2
-rw-r--r--src/test/ui/hygiene/rustc-macro-transparency.stderr8
-rw-r--r--src/test/ui/impl-duplicate-methods.stderr11
-rw-r--r--src/test/ui/impl-trait/auto-trait-leak.stderr8
-rw-r--r--src/test/ui/impl-trait/equality-rpass.stderr2
-rw-r--r--src/test/ui/impl-trait/equality.stderr2
-rw-r--r--src/test/ui/impl-trait/equality2.stderr2
-rw-r--r--src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2015.stderr4
-rw-r--r--src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2021.stderr4
-rw-r--r--src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rs2
-rw-r--r--src/test/ui/impl-trait/hidden-lifetimes.stderr8
-rw-r--r--src/test/ui/impl-trait/in-trait/auxiliary/rpitit.rs11
-rw-r--r--src/test/ui/impl-trait/in-trait/default-body-type-err-2.rs13
-rw-r--r--src/test/ui/impl-trait/in-trait/default-body-type-err-2.stderr11
-rw-r--r--src/test/ui/impl-trait/in-trait/default-body-type-err.rs13
-rw-r--r--src/test/ui/impl-trait/in-trait/default-body-type-err.stderr12
-rw-r--r--src/test/ui/impl-trait/in-trait/default-body-with-rpit.rs21
-rw-r--r--src/test/ui/impl-trait/in-trait/default-body.rs21
-rw-r--r--src/test/ui/impl-trait/in-trait/early.rs23
-rw-r--r--src/test/ui/impl-trait/in-trait/foreign.rs9
-rw-r--r--src/test/ui/impl-trait/in-trait/issue-102140.rs30
-rw-r--r--src/test/ui/impl-trait/in-trait/issue-102140.stderr29
-rw-r--r--src/test/ui/impl-trait/in-trait/issue-102301.rs18
-rw-r--r--src/test/ui/impl-trait/in-trait/issue-102571.rs24
-rw-r--r--src/test/ui/impl-trait/in-trait/issue-102571.stderr14
-rw-r--r--src/test/ui/impl-trait/in-trait/signature-mismatch.rs21
-rw-r--r--src/test/ui/impl-trait/in-trait/signature-mismatch.stderr16
-rw-r--r--src/test/ui/impl-trait/issue-100075-2.stderr2
-rw-r--r--src/test/ui/impl-trait/issue-102605.rs15
-rw-r--r--src/test/ui/impl-trait/issue-102605.stderr41
-rw-r--r--src/test/ui/impl-trait/issue-103181-1.rs85
-rw-r--r--src/test/ui/impl-trait/issue-103181-1.stderr12
-rw-r--r--src/test/ui/impl-trait/issue-103181-2.rs29
-rw-r--r--src/test/ui/impl-trait/issue-103181-2.stderr9
-rw-r--r--src/test/ui/impl-trait/issue-103599.stderr2
-rw-r--r--src/test/ui/impl-trait/issue-86465.rs6
-rw-r--r--src/test/ui/impl-trait/issue-86465.stderr2
-rw-r--r--src/test/ui/impl-trait/issue-87450.stderr2
-rw-r--r--src/test/ui/impl-trait/issues/issue-78722.rs2
-rw-r--r--src/test/ui/impl-trait/issues/issue-78722.stderr4
-rw-r--r--src/test/ui/impl-trait/issues/issue-86800.stderr15
-rw-r--r--src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr2
-rw-r--r--src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr2
-rw-r--r--src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr14
-rw-r--r--src/test/ui/impl-trait/nested-return-type2-tait.rs1
-rw-r--r--src/test/ui/impl-trait/nested-return-type2-tait.stderr17
-rw-r--r--src/test/ui/impl-trait/nested-return-type2.rs1
-rw-r--r--src/test/ui/impl-trait/nested-return-type2.stderr17
-rw-r--r--src/test/ui/impl-trait/nested-return-type3-tait.rs1
-rw-r--r--src/test/ui/impl-trait/nested-return-type3-tait.stderr17
-rw-r--r--src/test/ui/impl-trait/nested-return-type3-tait2.rs1
-rw-r--r--src/test/ui/impl-trait/nested-return-type3-tait2.stderr17
-rw-r--r--src/test/ui/impl-trait/nested-return-type3-tait3.rs1
-rw-r--r--src/test/ui/impl-trait/nested-return-type3-tait3.stderr17
-rw-r--r--src/test/ui/impl-trait/nested-return-type3.rs1
-rw-r--r--src/test/ui/impl-trait/nested-return-type3.stderr17
-rw-r--r--src/test/ui/impl-trait/normalize-tait-in-const.rs39
-rw-r--r--src/test/ui/impl-trait/normalize-tait-in-const.stderr8
-rw-r--r--src/test/ui/impl-trait/region-escape-via-bound.stderr2
-rw-r--r--src/test/ui/impl-trait/static-return-lifetime-infered.stderr8
-rw-r--r--src/test/ui/impl-trait/unactionable_diagnostic.fixed25
-rw-r--r--src/test/ui/impl-trait/unactionable_diagnostic.rs25
-rw-r--r--src/test/ui/impl-trait/unactionable_diagnostic.stderr14
-rw-r--r--src/test/ui/impl-trait/where-allowed.stderr2
-rw-r--r--src/test/ui/imports/issue-56125.stderr12
-rw-r--r--src/test/ui/imports/issue-57015.stderr5
-rw-r--r--src/test/ui/imports/local-modularized-tricky-fail-2.stderr2
-rw-r--r--src/test/ui/inference/char-as-str-single.fixed1
-rw-r--r--src/test/ui/inference/char-as-str-single.rs1
-rw-r--r--src/test/ui/inference/char-as-str-single.stderr15
-rw-r--r--src/test/ui/inference/inference-variable-behind-raw-pointer.stderr2
-rw-r--r--src/test/ui/inference/inference_unstable.stderr2
-rw-r--r--src/test/ui/inference/issue-36053.rs (renamed from src/test/ui/issues/issue-36053.rs)0
-rw-r--r--src/test/ui/inference/need_type_info/concrete-impl.stderr9
-rw-r--r--src/test/ui/inference/need_type_info/do-not-suggest-generic-arguments-for-turbofish.rs11
-rw-r--r--src/test/ui/inference/need_type_info/do-not-suggest-generic-arguments-for-turbofish.stderr9
-rw-r--r--src/test/ui/inference/need_type_info/issue-103053.rs18
-rw-r--r--src/test/ui/inference/need_type_info/issue-103053.stderr14
-rw-r--r--src/test/ui/inference/str-as-char.fixed4
-rw-r--r--src/test/ui/inference/str-as-char.rs4
-rw-r--r--src/test/ui/inference/str-as-char.stderr24
-rw-r--r--src/test/ui/infinite/infinite-struct.rs7
-rw-r--r--src/test/ui/infinite/infinite-struct.stderr19
-rw-r--r--src/test/ui/infinite/infinite-tag-type-recursion.stderr4
-rw-r--r--src/test/ui/inline-const/const-match-pat-range.rs3
-rw-r--r--src/test/ui/intrinsics/const-eval-select-backtrace-std.rs1
-rw-r--r--src/test/ui/intrinsics/const-eval-select-backtrace-std.run.stderr2
-rw-r--r--src/test/ui/intrinsics/const-eval-select-backtrace.rs1
-rw-r--r--src/test/ui/intrinsics/const-eval-select-backtrace.run.stderr2
-rw-r--r--src/test/ui/intrinsics/intrinsic-alignment.rs1
-rw-r--r--src/test/ui/intrinsics/intrinsic-raw_eq-const-padding.rs1
-rw-r--r--src/test/ui/intrinsics/intrinsic-raw_eq-const-padding.stderr2
-rw-r--r--src/test/ui/intrinsics/intrinsic-raw_eq-const.rs1
-rw-r--r--src/test/ui/intrinsics/intrinsics-integer.rs6
-rw-r--r--src/test/ui/intrinsics/panic-uninitialized-zeroed.rs253
-rw-r--r--src/test/ui/intrinsics/safe-intrinsic-mismatch.rs11
-rw-r--r--src/test/ui/intrinsics/safe-intrinsic-mismatch.stderr14
-rw-r--r--src/test/ui/invalid/invalid-inline.rs9
-rw-r--r--src/test/ui/invalid/invalid-inline.stderr15
-rw-r--r--src/test/ui/invalid/invalid-llvm-passes.rs2
-rw-r--r--src/test/ui/issues/issue-102964.rs10
-rw-r--r--src/test/ui/issues/issue-102964.stderr19
-rw-r--r--src/test/ui/issues/issue-11958.stderr4
-rw-r--r--src/test/ui/issues/issue-1460.stderr2
-rw-r--r--src/test/ui/issues/issue-14875.rs1
-rw-r--r--src/test/ui/issues/issue-16250.stderr12
-rw-r--r--src/test/ui/issues/issue-16256.stderr2
-rw-r--r--src/test/ui/issues/issue-17431-1.stderr10
-rw-r--r--src/test/ui/issues/issue-17431-2.rs3
-rw-r--r--src/test/ui/issues/issue-17431-2.stderr31
-rw-r--r--src/test/ui/issues/issue-17431-3.stderr10
-rw-r--r--src/test/ui/issues/issue-17431-4.stderr10
-rw-r--r--src/test/ui/issues/issue-17431-5.stderr4
-rw-r--r--src/test/ui/issues/issue-17431-6.stderr10
-rw-r--r--src/test/ui/issues/issue-17431-7.stderr10
-rw-r--r--src/test/ui/issues/issue-18919.stderr4
-rw-r--r--src/test/ui/issues/issue-19991.rs2
-rw-r--r--src/test/ui/issues/issue-19991.stderr2
-rw-r--r--src/test/ui/issues/issue-21174.stderr4
-rw-r--r--src/test/ui/issues/issue-22644.rs2
-rw-r--r--src/test/ui/issues/issue-22644.stderr2
-rw-r--r--src/test/ui/issues/issue-23122-2.rs1
-rw-r--r--src/test/ui/issues/issue-23122-2.stderr9
-rw-r--r--src/test/ui/issues/issue-24013.stderr5
-rw-r--r--src/test/ui/issues/issue-24322.stderr4
-rw-r--r--src/test/ui/issues/issue-25901.rs2
-rw-r--r--src/test/ui/issues/issue-25901.stderr22
-rw-r--r--src/test/ui/issues/issue-28344.stderr2
-rw-r--r--src/test/ui/issues/issue-29746.rs2
-rw-r--r--src/test/ui/issues/issue-29948.rs1
-rw-r--r--src/test/ui/issues/issue-3008-1.stderr4
-rw-r--r--src/test/ui/issues/issue-3008-2.stderr4
-rw-r--r--src/test/ui/issues/issue-3008-3.stderr4
-rw-r--r--src/test/ui/issues/issue-30371.rs1
-rw-r--r--src/test/ui/issues/issue-30490.rs1
-rw-r--r--src/test/ui/issues/issue-32326.stderr12
-rw-r--r--src/test/ui/issues/issue-35241.stderr2
-rw-r--r--src/test/ui/issues/issue-3563-2.rs14
-rw-r--r--src/test/ui/issues/issue-3779.stderr6
-rw-r--r--src/test/ui/issues/issue-40000.stderr4
-rw-r--r--src/test/ui/issues/issue-4265.stderr8
-rw-r--r--src/test/ui/issues/issue-43853.rs1
-rw-r--r--src/test/ui/issues/issue-46519.rs1
-rw-r--r--src/test/ui/issues/issue-47094.stderr2
-rw-r--r--src/test/ui/issues/issue-47486.stderr5
-rw-r--r--src/test/ui/issues/issue-47725.stderr2
-rw-r--r--src/test/ui/issues/issue-50582.stderr4
-rw-r--r--src/test/ui/issues/issue-50781.stderr10
-rw-r--r--src/test/ui/issues/issue-54044.stderr2
-rw-r--r--src/test/ui/issues/issue-55380.stderr2
-rw-r--r--src/test/ui/issues/issue-57271.rs4
-rw-r--r--src/test/ui/issues/issue-57271.stderr28
-rw-r--r--src/test/ui/issues/issue-57362-2.stderr6
-rw-r--r--src/test/ui/issues/issue-58022.stderr12
-rw-r--r--src/test/ui/issues/issue-58734.stderr2
-rw-r--r--src/test/ui/issues/issue-59488.stderr4
-rw-r--r--src/test/ui/issues/issue-60622.stderr4
-rw-r--r--src/test/ui/issues/issue-6458-3.stderr6
-rw-r--r--src/test/ui/issues/issue-6458-4.stderr2
-rw-r--r--src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr2
-rw-r--r--src/test/ui/issues/issue-72278.stderr2
-rw-r--r--src/test/ui/issues/issue-72554.rs1
-rw-r--r--src/test/ui/issues/issue-72554.stderr24
-rw-r--r--src/test/ui/issues/issue-75307.rs2
-rw-r--r--src/test/ui/issues/issue-75307.stderr8
-rw-r--r--src/test/ui/issues/issue-75907.rs2
-rw-r--r--src/test/ui/issues/issue-75907_b.rs2
-rw-r--r--src/test/ui/issues/issue-77993-1.rs12
-rw-r--r--src/test/ui/issues/issue-77993-1.stderr16
-rw-r--r--src/test/ui/issues/issue-78957.stderr2
-rw-r--r--src/test/ui/issues/issue-86756.stderr2
-rw-r--r--src/test/ui/issues/issue-8727.stderr2
-rw-r--r--src/test/ui/issues/issue-87707.rs1
-rw-r--r--src/test/ui/issues/issue-87707.run.stderr4
-rw-r--r--src/test/ui/issues/issue-99838.rs2
-rw-r--r--src/test/ui/iterators/into-iter-on-arrays-2018.stderr2
-rw-r--r--src/test/ui/iterators/into-iter-on-arrays-lint.stderr2
-rw-r--r--src/test/ui/iterators/iter-count-overflow-debug.rs1
-rw-r--r--src/test/ui/iterators/iter-position-overflow-debug.rs1
-rw-r--r--src/test/ui/iterators/iter-step-overflow-debug.rs1
-rw-r--r--src/test/ui/iterators/iter-sum-overflow-debug.rs1
-rw-r--r--src/test/ui/iterators/iter-sum-overflow-overflow-checks.rs1
-rw-r--r--src/test/ui/keyword/keyword-self-as-type-param.stderr4
-rw-r--r--src/test/ui/lang-items/issue-83471.stderr14
-rw-r--r--src/test/ui/let-else/const-fn.rs1
-rw-r--r--src/test/ui/let-else/let-else-brace-before-else.stderr8
-rw-r--r--src/test/ui/let-else/let-else-irrefutable.stderr2
-rw-r--r--src/test/ui/let-else/let-else-non-diverging.rs11
-rw-r--r--src/test/ui/let-else/let-else-non-diverging.stderr13
-rw-r--r--src/test/ui/let-else/let-else-then-diverge.rs4
-rw-r--r--src/test/ui/let-else/let-else-then-diverge.stderr4
-rw-r--r--src/test/ui/lexer/lex-emoji-identifiers.rs17
-rw-r--r--src/test/ui/lexer/lex-emoji-identifiers.stderr52
-rw-r--r--src/test/ui/lexical-scopes.stderr2
-rw-r--r--src/test/ui/lifetimes/elided-lifetime-in-param-pat.rs11
-rw-r--r--src/test/ui/lifetimes/issue-79187-2.stderr2
-rw-r--r--src/test/ui/lifetimes/issue-79187.stderr2
-rw-r--r--src/test/ui/lifetimes/lifetime-errors/issue_74400.stderr2
-rw-r--r--src/test/ui/lifetimes/nested-binder-print.rs10
-rw-r--r--src/test/ui/lifetimes/nested-binder-print.stderr14
-rw-r--r--src/test/ui/lifetimes/re-empty-in-error.stderr2
-rw-r--r--src/test/ui/lifetimes/suggest-introducing-and-adding-missing-lifetime.stderr1
-rw-r--r--src/test/ui/lifetimes/unusual-rib-combinations.rs28
-rw-r--r--src/test/ui/lifetimes/unusual-rib-combinations.stderr61
-rw-r--r--src/test/ui/limits/issue-55878.stderr17
-rw-r--r--src/test/ui/linkage-attr/link-attr-validation-early.stderr2
-rw-r--r--src/test/ui/lint/auxiliary/trivial-cast-ice.rs7
-rw-r--r--src/test/ui/lint/bare-trait-objects-path.stderr2
-rw-r--r--src/test/ui/lint/clashing-extern-fn.stderr6
-rw-r--r--src/test/ui/lint/cli-lint-override.forbid_warn.stderr2
-rw-r--r--src/test/ui/lint/cli-lint-override.force_warn_deny.stderr2
-rw-r--r--src/test/ui/lint/cli-lint-override.warn_deny.stderr2
-rw-r--r--src/test/ui/lint/dead-code/issue-85071-2.stderr10
-rw-r--r--src/test/ui/lint/dead-code/issue-85071.stderr10
-rw-r--r--src/test/ui/lint/dead-code/unused-variant.stderr2
-rw-r--r--src/test/ui/lint/deny-overflowing-literals.stderr2
-rw-r--r--src/test/ui/lint/expansion-time.stderr8
-rw-r--r--src/test/ui/lint/fn_must_use.stderr2
-rw-r--r--src/test/ui/lint/for_loop_over_fallibles.rs43
-rw-r--r--src/test/ui/lint/for_loop_over_fallibles.stderr101
-rw-r--r--src/test/ui/lint/forbid-group-group-2.stderr4
-rw-r--r--src/test/ui/lint/forbid-group-member.stderr2
-rw-r--r--src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.rs12
-rw-r--r--src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.stderr23
-rw-r--r--src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs14
-rw-r--r--src/test/ui/lint/force-warn/allowed-deny-by-default-lint.stderr23
-rw-r--r--src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr2
-rw-r--r--src/test/ui/lint/force-warn/cap-lints-allow.stderr2
-rw-r--r--src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr2
-rw-r--r--src/test/ui/lint/force-warn/deny-by-default-lint.rs12
-rw-r--r--src/test/ui/lint/force-warn/deny-by-default-lint.stderr23
-rw-r--r--src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr2
-rw-r--r--src/test/ui/lint/force-warn/lint-group-allowed-lint-group.stderr2
-rw-r--r--src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr2
-rw-r--r--src/test/ui/lint/inclusive-range-pattern-syntax.stderr4
-rw-r--r--src/test/ui/lint/inert-attr-macro.stderr10
-rw-r--r--src/test/ui/lint/inline-trait-and-foreign-items.stderr6
-rw-r--r--src/test/ui/lint/invalid_value.rs (renamed from src/test/ui/lint/uninitialized-zeroed.rs)40
-rw-r--r--src/test/ui/lint/invalid_value.stderr (renamed from src/test/ui/lint/uninitialized-zeroed.stderr)242
-rw-r--r--src/test/ui/lint/issue-102705.rs22
-rw-r--r--src/test/ui/lint/issue-14309.stderr10
-rw-r--r--src/test/ui/lint/issue-1866.stderr4
-rw-r--r--src/test/ui/lint/issue-63364.stderr2
-rw-r--r--src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.stderr4
-rw-r--r--src/test/ui/lint/issue-79744.stderr2
-rw-r--r--src/test/ui/lint/issue-80988.stderr2
-rw-r--r--src/test/ui/lint/issue-83477.stderr2
-rw-r--r--src/test/ui/lint/issue-86600-lint-twice.stderr2
-rw-r--r--src/test/ui/lint/lint-attr-everywhere-early.stderr4
-rw-r--r--src/test/ui/lint/lint-attr-everywhere-late.stderr120
-rw-r--r--src/test/ui/lint/lint-const-item-mutation.stderr2
-rw-r--r--src/test/ui/lint/lint-ctypes-73249-2.stderr2
-rw-r--r--src/test/ui/lint/lint-ctypes-73249-3.stderr2
-rw-r--r--src/test/ui/lint/lint-ctypes-73249-5.stderr2
-rw-r--r--src/test/ui/lint/lint-ctypes-73251-1.stderr2
-rw-r--r--src/test/ui/lint/lint-ctypes-73251-2.stderr2
-rw-r--r--src/test/ui/lint/lint-ctypes-enum.stderr10
-rw-r--r--src/test/ui/lint/lint-ctypes-fn.stderr4
-rw-r--r--src/test/ui/lint/lint-ctypes.stderr10
-rw-r--r--src/test/ui/lint/lint-enum-intrinsics-non-enums.stderr2
-rw-r--r--src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr2
-rw-r--r--src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr2
-rw-r--r--src/test/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr2
-rw-r--r--src/test/ui/lint/lint-exceeding-bitshifts.rs2
-rw-r--r--src/test/ui/lint/lint-incoherent-auto-trait-objects.stderr44
-rw-r--r--src/test/ui/lint/lint-invalid-atomic-ordering-bool.stderr2
-rw-r--r--src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.stderr2
-rw-r--r--src/test/ui/lint/lint-invalid-atomic-ordering-exchange.stderr2
-rw-r--r--src/test/ui/lint/lint-invalid-atomic-ordering-fence.stderr2
-rw-r--r--src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.stderr2
-rw-r--r--src/test/ui/lint/lint-invalid-atomic-ordering-int.stderr2
-rw-r--r--src/test/ui/lint/lint-invalid-atomic-ordering-ptr.stderr2
-rw-r--r--src/test/ui/lint/lint-invalid-atomic-ordering-uint.stderr2
-rw-r--r--src/test/ui/lint/lint-non-snake-case-crate-2.stderr2
-rw-r--r--src/test/ui/lint/lint-output-format.rs1
-rw-r--r--src/test/ui/lint/lint-output-format.stderr12
-rw-r--r--src/test/ui/lint/lint-pre-expansion-extern-module.stderr2
-rw-r--r--src/test/ui/lint/lint-stability-deprecated.rs2
-rw-r--r--src/test/ui/lint/lint-strict-provenance-fuzzy-casts.stderr2
-rw-r--r--src/test/ui/lint/lint-strict-provenance-lossy-casts.stderr2
-rw-r--r--src/test/ui/lint/lint-temporary-cstring-as-param.stderr4
-rw-r--r--src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr4
-rw-r--r--src/test/ui/lint/lint-type-limits2.stderr4
-rw-r--r--src/test/ui/lint/lint-type-limits3.stderr4
-rw-r--r--src/test/ui/lint/lint-type-overflow.stderr2
-rw-r--r--src/test/ui/lint/lint-type-overflow2.rs1
-rw-r--r--src/test/ui/lint/lint-type-overflow2.stderr14
-rw-r--r--src/test/ui/lint/lint-unconditional-recursion.stderr2
-rw-r--r--src/test/ui/lint/lint-unsafe-code.stderr2
-rw-r--r--src/test/ui/lint/must_not_suspend/boxed.stderr10
-rw-r--r--src/test/ui/lint/must_not_suspend/dedup.stderr10
-rw-r--r--src/test/ui/lint/must_not_suspend/gated.stderr2
-rw-r--r--src/test/ui/lint/must_not_suspend/mutex.stderr10
-rw-r--r--src/test/ui/lint/must_not_suspend/ref-drop-tracking.stderr10
-rw-r--r--src/test/ui/lint/must_not_suspend/ref.drop_tracking.stderr10
-rw-r--r--src/test/ui/lint/must_not_suspend/ref.no_drop_tracking.stderr10
-rw-r--r--src/test/ui/lint/must_not_suspend/trait.stderr10
-rw-r--r--src/test/ui/lint/must_not_suspend/unit.stderr10
-rw-r--r--src/test/ui/lint/must_not_suspend/warn.stderr10
-rw-r--r--src/test/ui/lint/no-coverage.stderr2
-rw-r--r--src/test/ui/lint/noop-method-call.rs1
-rw-r--r--src/test/ui/lint/noop-method-call.stderr14
-rw-r--r--src/test/ui/lint/opaque-ty-ffi-unsafe.stderr2
-rw-r--r--src/test/ui/lint/outer-forbid.stderr4
-rw-r--r--src/test/ui/lint/redundant-semicolon/redundant-semi-proc-macro.stderr2
-rw-r--r--src/test/ui/lint/rfc-2383-lint-reason/expect_nested_lint_levels.stderr2
-rw-r--r--src/test/ui/lint/rfc-2383-lint-reason/expect_unfulfilled_expectation.stderr2
-rw-r--r--src/test/ui/lint/rfc-2383-lint-reason/expect_with_reason.stderr2
-rw-r--r--src/test/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr16
-rw-r--r--src/test/ui/lint/rfc-2383-lint-reason/lint-attribute-only-with-reason.stderr2
-rw-r--r--src/test/ui/lint/rfc-2457-non-ascii-idents/lint-mixed-script-confusables.stderr4
-rw-r--r--src/test/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.stderr8
-rw-r--r--src/test/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr2
-rw-r--r--src/test/ui/lint/trivial-cast-ice.rs12
-rw-r--r--src/test/ui/lint/trivial-casts-featuring-type-ascription.stderr4
-rw-r--r--src/test/ui/lint/trivial-casts.stderr4
-rw-r--r--src/test/ui/lint/trivial_casts.stderr4
-rw-r--r--src/test/ui/lint/type-overflow.stderr4
-rw-r--r--src/test/ui/lint/unaligned_references.stderr80
-rw-r--r--src/test/ui/lint/unaligned_references_external_macro.stderr16
-rw-r--r--src/test/ui/lint/unreachable_pub.stderr2
-rw-r--r--src/test/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.stderr2
-rw-r--r--src/test/ui/lint/unused/must-use-box-from-raw.stderr2
-rw-r--r--src/test/ui/lint/unused/must_use-in-stdlib-traits.stderr2
-rw-r--r--src/test/ui/lint/unused/must_use-tuple.stderr2
-rw-r--r--src/test/ui/lint/unused/unused-attr-duplicate.stderr10
-rw-r--r--src/test/ui/lint/unused/unused-closure.stderr2
-rw-r--r--src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr2
-rw-r--r--src/test/ui/lint/unused/unused-doc-comments-for-macros.stderr2
-rw-r--r--src/test/ui/lint/unused/unused-supertrait.rs11
-rw-r--r--src/test/ui/lint/unused/unused-supertrait.stderr15
-rw-r--r--src/test/ui/lint/unused/unused_attributes-must_use.stderr10
-rw-r--r--src/test/ui/lint/unused/useless-comment.stderr2
-rw-r--r--src/test/ui/liveness/liveness-asm.stderr2
-rw-r--r--src/test/ui/liveness/liveness-consts.stderr4
-rw-r--r--src/test/ui/liveness/liveness-dead.stderr2
-rw-r--r--src/test/ui/liveness/liveness-return-last-stmt-semi.rs1
-rw-r--r--src/test/ui/liveness/liveness-return-last-stmt-semi.stderr10
-rw-r--r--src/test/ui/liveness/liveness-unused.stderr2
-rw-r--r--src/test/ui/liveness/liveness-upvars.stderr4
-rw-r--r--src/test/ui/loops/loop-proper-liveness.stderr4
-rw-r--r--src/test/ui/macros/format-parse-errors.stderr2
-rw-r--r--src/test/ui/macros/issue-102878.rs10
-rw-r--r--src/test/ui/macros/issue-102878.stderr60
-rw-r--r--src/test/ui/macros/issue-39404.stderr2
-rw-r--r--src/test/ui/macros/issue-84195-lint-anon-const.stderr4
-rw-r--r--src/test/ui/macros/issue-99265.stderr278
-rw-r--r--src/test/ui/macros/issue-99907.stderr4
-rw-r--r--src/test/ui/macros/lint-trailing-macro-call.stderr2
-rw-r--r--src/test/ui/macros/macro-comma-behavior-rpass.rs1
-rw-r--r--src/test/ui/macros/macro-context.stderr4
-rw-r--r--src/test/ui/macros/macro-in-expression-context.stderr2
-rw-r--r--src/test/ui/macros/macro-match-nonterminal.stderr2
-rw-r--r--src/test/ui/macros/macro-missing-fragment-deduplication.stderr2
-rw-r--r--src/test/ui/macros/macro-missing-fragment.stderr4
-rw-r--r--src/test/ui/macros/macro-or-patterns-back-compat.stderr4
-rw-r--r--src/test/ui/macros/macro-use-all-and-none.stderr2
-rw-r--r--src/test/ui/macros/macro_rules-unmatchable-literals.rs14
-rw-r--r--src/test/ui/macros/macro_rules-unmatchable-literals.stderr14
-rw-r--r--src/test/ui/macros/macros-nonfatal-errors.rs23
-rw-r--r--src/test/ui/macros/macros-nonfatal-errors.stderr12
-rw-r--r--src/test/ui/macros/must-use-in-macro-55516.stderr2
-rw-r--r--src/test/ui/macros/rfc-2011-nicer-assert-messages/all-expr-kinds.rs1
-rw-r--r--src/test/ui/macros/rfc-2011-nicer-assert-messages/all-not-available-cases.rs1
-rw-r--r--src/test/ui/macros/rfc-2011-nicer-assert-messages/assert-without-captures-does-not-create-unnecessary-code.rs1
-rw-r--r--src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr44
-rw-r--r--src/test/ui/macros/stringify.rs1
-rw-r--r--src/test/ui/macros/syntax-error-recovery.rs18
-rw-r--r--src/test/ui/macros/syntax-error-recovery.stderr30
-rw-r--r--src/test/ui/malformed/malformed-regressions.stderr2
-rw-r--r--src/test/ui/marker_trait_attr/overlap-doesnt-conflict-with-specialization.stderr2
-rw-r--r--src/test/ui/marker_trait_attr/overlap-marker-trait-with-static-lifetime.rs10
-rw-r--r--src/test/ui/marker_trait_attr/overlap-marker-trait-with-underscore-lifetime.rs9
-rw-r--r--src/test/ui/marker_trait_attr/overlap-marker-trait-with-underscore-lifetime.stderr31
-rw-r--r--src/test/ui/marker_trait_attr/overlap-marker-trait.rs3
-rw-r--r--src/test/ui/marker_trait_attr/overlap-marker-trait.stderr4
-rw-r--r--src/test/ui/marker_trait_attr/overlap-permitted-for-annotated-marker-traits.rs3
-rw-r--r--src/test/ui/match/expr_before_ident_pat.rs2
-rw-r--r--src/test/ui/match/expr_before_ident_pat.stderr4
-rw-r--r--src/test/ui/match/issue-41255.rs1
-rw-r--r--src/test/ui/match/issue-41255.stderr30
-rw-r--r--src/test/ui/match/issue-92100.rs2
-rw-r--r--src/test/ui/methods/issues/issue-90315.rs79
-rw-r--r--src/test/ui/methods/issues/issue-90315.stderr198
-rw-r--r--src/test/ui/methods/method-call-lifetime-args-lint-fail.stderr4
-rw-r--r--src/test/ui/methods/method-call-lifetime-args-lint.stderr4
-rw-r--r--src/test/ui/methods/method-call-lifetime-args-unresolved.stderr2
-rw-r--r--src/test/ui/methods/method-deref-to-same-trait-object-with-separate-params.stderr2
-rw-r--r--src/test/ui/methods/method-macro-backtrace.stderr8
-rw-r--r--src/test/ui/mir/drop-elaboration-after-borrowck-error.rs8
-rw-r--r--src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr21
-rw-r--r--src/test/ui/mir/mir_calls_to_shims.rs1
-rw-r--r--src/test/ui/mir/mir_codegen_calls_diverging_drops.rs1
-rw-r--r--src/test/ui/mir/mir_drop_order.rs1
-rw-r--r--src/test/ui/mir/mir_drop_panics.rs1
-rw-r--r--src/test/ui/mir/mir_let_chains_drop_order.rs9
-rw-r--r--src/test/ui/mir/thir-constparam-temp.stderr2
-rw-r--r--src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr2
-rw-r--r--src/test/ui/mismatched_types/closure-mismatch.stderr2
-rw-r--r--src/test/ui/mismatched_types/fn-variance-1.stderr4
-rw-r--r--src/test/ui/mismatched_types/issue-36053-2.stderr4
-rw-r--r--src/test/ui/mismatched_types/show_module.rs18
-rw-r--r--src/test/ui/mismatched_types/show_module.stderr23
-rw-r--r--src/test/ui/mismatched_types/similar_paths.rs11
-rw-r--r--src/test/ui/mismatched_types/similar_paths.stderr23
-rw-r--r--src/test/ui/mismatched_types/similar_paths_primitive.rs10
-rw-r--r--src/test/ui/mismatched_types/similar_paths_primitive.stderr24
-rw-r--r--src/test/ui/modules/special_module_name.stderr2
-rw-r--r--src/test/ui/moves/issue-72649-uninit-in-loop.stderr10
-rw-r--r--src/test/ui/moves/move-into-dead-array-1.stderr5
-rw-r--r--src/test/ui/moves/move-of-addr-of-mut.stderr4
-rw-r--r--src/test/ui/moves/move-out-of-slice-2.stderr2
-rw-r--r--src/test/ui/namespace/namespaced-enum-glob-import-no-impls-xcrate.stderr24
-rw-r--r--src/test/ui/namespace/namespaced-enum-glob-import-no-impls.stderr24
-rw-r--r--src/test/ui/native-library-link-flags/suggest-libname-only-1.rs9
-rw-r--r--src/test/ui/native-library-link-flags/suggest-libname-only-1.stderr6
-rw-r--r--src/test/ui/native-library-link-flags/suggest-libname-only-2.rs9
-rw-r--r--src/test/ui/native-library-link-flags/suggest-libname-only-2.stderr6
-rw-r--r--src/test/ui/never_type/issue-52443.rs4
-rw-r--r--src/test/ui/never_type/issue-52443.stderr4
-rw-r--r--src/test/ui/never_type/issue-5500-1.rs (renamed from src/test/ui/issues/issue-5500-1.rs)0
-rw-r--r--src/test/ui/nll/closure-malformed-projection-input-issue-102800.rs31
-rw-r--r--src/test/ui/nll/closure-malformed-projection-input-issue-102800.stderr104
-rw-r--r--src/test/ui/nll/closure-requirements/escape-argument-callee.stderr2
-rw-r--r--src/test/ui/nll/closure-requirements/escape-argument.stderr2
-rw-r--r--src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr2
-rw-r--r--src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr2
-rw-r--r--src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr4
-rw-r--r--src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr2
-rw-r--r--src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr2
-rw-r--r--src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr2
-rw-r--r--src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr2
-rw-r--r--src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr2
-rw-r--r--src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr2
-rw-r--r--src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr2
-rw-r--r--src/test/ui/nll/closures-in-loops.stderr16
-rw-r--r--src/test/ui/nll/issue-48623-generator.stderr2
-rw-r--r--src/test/ui/nll/issue-51191.stderr2
-rw-r--r--src/test/ui/nll/issue-57642-higher-ranked-subtype.stderr10
-rw-r--r--src/test/ui/nll/issue-97997.stderr4
-rw-r--r--src/test/ui/nll/match-cfg-fake-edges.stderr5
-rw-r--r--src/test/ui/nll/match-on-borrowed.stderr5
-rw-r--r--src/test/ui/nll/relate_tys/impl-fn-ignore-binder-via-bottom.stderr6
-rw-r--r--src/test/ui/nll/relate_tys/universe-violation.stderr2
-rw-r--r--src/test/ui/nll/trait-associated-constant.stderr2
-rw-r--r--src/test/ui/nll/ty-outlives/impl-trait-captures.stderr8
-rw-r--r--src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr4
-rw-r--r--src/test/ui/no-patterns-in-args-2.stderr4
-rw-r--r--src/test/ui/non-fmt-panic.stderr2
-rw-r--r--src/test/ui/numbers-arithmetic/float-int-invalid-const-cast.rs2
-rw-r--r--src/test/ui/numbers-arithmetic/issue-8460-const.noopt.stderr48
-rw-r--r--src/test/ui/numbers-arithmetic/issue-8460-const.opt.stderr48
-rw-r--r--src/test/ui/numbers-arithmetic/issue-8460-const.opt_with_overflow_checks.stderr48
-rw-r--r--src/test/ui/numbers-arithmetic/issue-8460-const.rs2
-rw-r--r--src/test/ui/numbers-arithmetic/next-power-of-two-overflow-debug.rs1
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-lsh-1.rs2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-lsh-1.stderr2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-lsh-2.rs2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-lsh-2.stderr2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-lsh-3.rs2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-lsh-3.stderr2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-lsh-4.rs2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-lsh-4.stderr2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-rsh-1.rs2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-rsh-1.stderr2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-rsh-2.rs2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-rsh-2.stderr2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-rsh-3.rs2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-rsh-3.stderr2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-rsh-4.rs2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-rsh-4.stderr2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-rsh-5.rs2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-rsh-5.stderr2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-rsh-6.rs2
-rw-r--r--src/test/ui/numbers-arithmetic/overflowing-rsh-6.stderr2
-rw-r--r--src/test/ui/numbers-arithmetic/promoted_overflow_opt.rs1
-rw-r--r--src/test/ui/object-safety/issue-102762.rs26
-rw-r--r--src/test/ui/object-safety/issue-102762.stderr20
-rw-r--r--src/test/ui/object-safety/issue-102933.rs25
-rw-r--r--src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.rs15
-rw-r--r--src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.stderr43
-rw-r--r--src/test/ui/oom_unwind.rs2
-rw-r--r--src/test/ui/opt-in-copy.stderr8
-rw-r--r--src/test/ui/packed/issue-27060-rpass.stderr32
-rw-r--r--src/test/ui/packed/issue-27060.stderr10
-rw-r--r--src/test/ui/packed/packed-struct-borrow-element-64bit.stderr16
-rw-r--r--src/test/ui/packed/packed-struct-borrow-element.stderr24
-rw-r--r--src/test/ui/panic-handler/weak-lang-item.rs2
-rw-r--r--src/test/ui/panic-runtime/need-abort-got-unwind.rs1
-rw-r--r--src/test/ui/panic-runtime/transitive-link-a-bunch.rs1
-rw-r--r--src/test/ui/panic-runtime/want-unwind-got-abort.rs1
-rw-r--r--src/test/ui/panic-runtime/want-unwind-got-abort2.rs1
-rw-r--r--src/test/ui/panic-while-printing.rs1
-rw-r--r--src/test/ui/panics/issue-47429-short-backtraces.legacy.run.stderr2
-rw-r--r--src/test/ui/panics/issue-47429-short-backtraces.rs1
-rw-r--r--src/test/ui/panics/issue-47429-short-backtraces.v0.run.stderr2
-rw-r--r--src/test/ui/panics/runtime-switch.legacy.run.stderr2
-rw-r--r--src/test/ui/panics/runtime-switch.rs1
-rw-r--r--src/test/ui/panics/runtime-switch.v0.run.stderr2
-rw-r--r--src/test/ui/parser/assoc-static-semantic-fail.stderr2
-rw-r--r--src/test/ui/parser/attr-stmt-expr-attr-bad.rs2
-rw-r--r--src/test/ui/parser/attr-stmt-expr-attr-bad.stderr106
-rw-r--r--src/test/ui/parser/bad-let-as-field.rs6
-rw-r--r--src/test/ui/parser/bad-let-as-field.stderr15
-rw-r--r--src/test/ui/parser/bad-lit-suffixes.rs16
-rw-r--r--src/test/ui/parser/bad-lit-suffixes.stderr16
-rw-r--r--src/test/ui/parser/bad-pointer-type.rs2
-rw-r--r--src/test/ui/parser/bad-pointer-type.stderr11
-rw-r--r--src/test/ui/parser/default.stderr2
-rw-r--r--src/test/ui/parser/doc-after-struct-field.rs4
-rw-r--r--src/test/ui/parser/doc-after-struct-field.stderr4
-rw-r--r--src/test/ui/parser/doc-before-extern-rbrace.stderr2
-rw-r--r--src/test/ui/parser/doc-before-fn-rbrace.rs2
-rw-r--r--src/test/ui/parser/doc-before-fn-rbrace.stderr2
-rw-r--r--src/test/ui/parser/doc-before-rbrace.rs2
-rw-r--r--src/test/ui/parser/doc-before-rbrace.stderr2
-rw-r--r--src/test/ui/parser/doc-before-semi.rs2
-rw-r--r--src/test/ui/parser/doc-before-semi.stderr2
-rw-r--r--src/test/ui/parser/doc-before-struct-rbrace-1.rs2
-rw-r--r--src/test/ui/parser/doc-before-struct-rbrace-1.stderr5
-rw-r--r--src/test/ui/parser/doc-before-struct-rbrace-2.rs2
-rw-r--r--src/test/ui/parser/doc-before-struct-rbrace-2.stderr2
-rw-r--r--src/test/ui/parser/doc-inside-trait-item.stderr2
-rw-r--r--src/test/ui/parser/double-pointer.rs7
-rw-r--r--src/test/ui/parser/double-pointer.stderr15
-rw-r--r--src/test/ui/parser/emoji-identifiers.stderr18
-rw-r--r--src/test/ui/parser/empty-impl-semicolon.rs5
-rw-r--r--src/test/ui/parser/empty-impl-semicolon.stderr8
-rw-r--r--src/test/ui/parser/expr-as-stmt-2.stderr5
-rw-r--r--src/test/ui/parser/expr-as-stmt.stderr9
-rw-r--r--src/test/ui/parser/fn-field-parse-error-ice.rs2
-rw-r--r--src/test/ui/parser/fn-field-parse-error-ice.stderr12
-rw-r--r--src/test/ui/parser/fn-header-semantic-fail.stderr14
-rw-r--r--src/test/ui/parser/inner-attr-after-doc-comment.stderr2
-rw-r--r--src/test/ui/parser/issue-103143.rs5
-rw-r--r--src/test/ui/parser/issue-103143.stderr20
-rw-r--r--src/test/ui/parser/issue-103425.rs15
-rw-r--r--src/test/ui/parser/issue-103425.stderr29
-rw-r--r--src/test/ui/parser/issue-17718-parse-const.rs (renamed from src/test/ui/issues/issue-17718-parse-const.rs)0
-rw-r--r--src/test/ui/parser/issues/issue-101540.rs7
-rw-r--r--src/test/ui/parser/issues/issue-101540.stderr12
-rw-r--r--src/test/ui/parser/issues/issue-102182-impl-trait-recover.rs3
-rw-r--r--src/test/ui/parser/issues/issue-102182-impl-trait-recover.stderr14
-rw-r--r--src/test/ui/parser/issues/issue-17383.rs7
-rw-r--r--src/test/ui/parser/issues/issue-17383.stderr15
-rw-r--r--src/test/ui/parser/issues/issue-34222-1.stderr2
-rw-r--r--src/test/ui/parser/issues/issue-48636.stderr4
-rw-r--r--src/test/ui/parser/issues/issue-63115-range-pat-interpolated.rs1
-rw-r--r--src/test/ui/parser/issues/issue-68000-unicode-ident-after-missing-comma.stderr2
-rw-r--r--src/test/ui/parser/issues/issue-8537.stderr2
-rw-r--r--src/test/ui/parser/issues/issue-93282.rs1
-rw-r--r--src/test/ui/parser/issues/issue-93282.stderr27
-rw-r--r--src/test/ui/parser/item-needs-block.rs10
-rw-r--r--src/test/ui/parser/item-needs-block.stderr26
-rw-r--r--src/test/ui/parser/label-after-block-like.rs43
-rw-r--r--src/test/ui/parser/label-after-block-like.stderr176
-rw-r--r--src/test/ui/parser/label-is-actually-char.rs16
-rw-r--r--src/test/ui/parser/label-is-actually-char.stderr46
-rw-r--r--src/test/ui/parser/macro/issue-33569.stderr2
-rw-r--r--src/test/ui/parser/macro/issue-37113.stderr2
-rw-r--r--src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr3
-rw-r--r--src/test/ui/parser/missing-closing-angle-bracket-struct-field-ty.stderr3
-rw-r--r--src/test/ui/parser/numeric-lifetime.stderr16
-rw-r--r--src/test/ui/parser/parser-recovery-1.stderr12
-rw-r--r--src/test/ui/parser/parser-recovery-2.stderr12
-rw-r--r--src/test/ui/parser/recover-enum2.stderr2
-rw-r--r--src/test/ui/parser/recover-field-semi.stderr8
-rw-r--r--src/test/ui/parser/recover-range-pats.rs1
-rw-r--r--src/test/ui/parser/recover-range-pats.stderr126
-rw-r--r--src/test/ui/parser/recover-struct.stderr2
-rw-r--r--src/test/ui/parser/recovered-struct-variant.stderr4
-rw-r--r--src/test/ui/parser/removed-syntax-enum-newtype.stderr4
-rw-r--r--src/test/ui/parser/removed-syntax-field-let-2.rs12
-rw-r--r--src/test/ui/parser/removed-syntax-field-let-2.stderr33
-rw-r--r--src/test/ui/parser/removed-syntax-field-let.stderr8
-rw-r--r--src/test/ui/parser/removed-syntax-field-semicolon.stderr2
-rw-r--r--src/test/ui/parser/require-parens-for-chained-comparison.rs2
-rw-r--r--src/test/ui/parser/require-parens-for-chained-comparison.stderr16
-rw-r--r--src/test/ui/parser/semi-after-closure-in-macro.rs14
-rw-r--r--src/test/ui/parser/tag-variant-disr-non-nullary.rs12
-rw-r--r--src/test/ui/parser/tag-variant-disr-non-nullary.stderr25
-rw-r--r--src/test/ui/parser/trait-item-with-defaultness-fail-semantic.stderr2
-rw-r--r--src/test/ui/parser/trait-object-trait-parens.stderr2
-rw-r--r--src/test/ui/parser/type-alias-where-fixable.stderr2
-rw-r--r--src/test/ui/parser/unicode-control-codepoints.stderr4
-rw-r--r--src/test/ui/parser/unmatched-langle-1.stderr12
-rw-r--r--src/test/ui/pattern/issue-17718-patterns.rs (renamed from src/test/ui/issues/issue-17718-patterns.rs)0
-rw-r--r--src/test/ui/pattern/issue-17718-patterns.stderr (renamed from src/test/ui/issues/issue-17718-patterns.stderr)0
-rw-r--r--src/test/ui/pattern/issue-66270-pat-struct-parser-recovery.stderr2
-rw-r--r--src/test/ui/pattern/usefulness/consts-opaque.stderr2
-rw-r--r--src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.stderr4
-rw-r--r--src/test/ui/pattern/usefulness/integer-ranges/overlapping_range_endpoints.stderr2
-rw-r--r--src/test/ui/polymorphization/const_parameters/closures.stderr2
-rw-r--r--src/test/ui/polymorphization/const_parameters/functions.stderr2
-rw-r--r--src/test/ui/polymorphization/generators.stderr2
-rw-r--r--src/test/ui/polymorphization/predicates.stderr2
-rw-r--r--src/test/ui/polymorphization/promoted-function-2.stderr2
-rw-r--r--src/test/ui/privacy/access_levels.rs49
-rw-r--r--src/test/ui/privacy/access_levels.stderr125
-rw-r--r--src/test/ui/privacy/associated-item-privacy-inherent.rs6
-rw-r--r--src/test/ui/privacy/associated-item-privacy-inherent.stderr6
-rw-r--r--src/test/ui/privacy/associated-item-privacy-trait.rs6
-rw-r--r--src/test/ui/privacy/associated-item-privacy-trait.stderr6
-rw-r--r--src/test/ui/privacy/auxiliary/issue-17718-const-privacy.rs (renamed from src/test/ui/issues/auxiliary/issue-17718-const-privacy.rs)0
-rw-r--r--src/test/ui/privacy/effective_visibilities.rs75
-rw-r--r--src/test/ui/privacy/effective_visibilities.stderr134
-rw-r--r--src/test/ui/privacy/issue-17718-const-privacy.rs (renamed from src/test/ui/issues/issue-17718-const-privacy.rs)0
-rw-r--r--src/test/ui/privacy/issue-17718-const-privacy.stderr (renamed from src/test/ui/issues/issue-17718-const-privacy.stderr)0
-rw-r--r--src/test/ui/privacy/issue-30079.stderr2
-rw-r--r--src/test/ui/privacy/private-in-public-assoc-ty.stderr2
-rw-r--r--src/test/ui/privacy/private-in-public-non-principal.stderr2
-rw-r--r--src/test/ui/privacy/private-in-public-warn.stderr4
-rw-r--r--src/test/ui/privacy/private-inferred-type-3.rs2
-rw-r--r--src/test/ui/privacy/private-inferred-type-3.stderr2
-rw-r--r--src/test/ui/privacy/private-inferred-type.rs2
-rw-r--r--src/test/ui/privacy/private-inferred-type.stderr2
-rw-r--r--src/test/ui/privacy/reachable-unnameable-items.rs1
-rw-r--r--src/test/ui/privacy/where-priv-type.stderr2
-rw-r--r--src/test/ui/proc-macro/attr-complex-fn.stdout4
-rw-r--r--src/test/ui/proc-macro/call-deprecated.rs2
-rw-r--r--src/test/ui/proc-macro/capture-macro-rules-invoke.stdout12
-rw-r--r--src/test/ui/proc-macro/debug/dump-debug-span-debug.rs7
-rw-r--r--src/test/ui/proc-macro/debug/dump-debug-span-debug.stderr127
-rw-r--r--src/test/ui/proc-macro/debug/dump-debug.stderr6
-rw-r--r--src/test/ui/proc-macro/derive-bad.stderr5
-rw-r--r--src/test/ui/proc-macro/derive-helper-shadowing.stderr2
-rw-r--r--src/test/ui/proc-macro/dollar-crate-issue-57089.stdout8
-rw-r--r--src/test/ui/proc-macro/dollar-crate-issue-62325.stdout8
-rw-r--r--src/test/ui/proc-macro/dollar-crate.stdout24
-rw-r--r--src/test/ui/proc-macro/expand-with-a-macro.rs1
-rw-r--r--src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr4
-rw-r--r--src/test/ui/proc-macro/generate-mod.stderr18
-rw-r--r--src/test/ui/proc-macro/helper-attr-blocked-by-import-ambig.stderr2
-rw-r--r--src/test/ui/proc-macro/inner-attr-non-inline-mod.stderr2
-rw-r--r--src/test/ui/proc-macro/inner-attrs.stdout4
-rw-r--r--src/test/ui/proc-macro/issue-73933-procedural-masquerade.rs9
-rw-r--r--src/test/ui/proc-macro/issue-73933-procedural-masquerade.stderr91
-rw-r--r--src/test/ui/proc-macro/issue-73933-procedural-masquerade.stdout11
-rw-r--r--src/test/ui/proc-macro/issue-75930-derive-cfg.stderr2
-rw-r--r--src/test/ui/proc-macro/issue-75930-derive-cfg.stdout20
-rw-r--r--src/test/ui/proc-macro/issue-76182-leading-vert-pat.stdout4
-rw-r--r--src/test/ui/proc-macro/keep-expr-tokens.stderr12
-rw-r--r--src/test/ui/proc-macro/meta-macro-hygiene.rs4
-rw-r--r--src/test/ui/proc-macro/meta-macro-hygiene.stdout6
-rw-r--r--src/test/ui/proc-macro/mixed-site-span.stderr4
-rw-r--r--src/test/ui/proc-macro/pretty-print-hack-hide.rs12
-rw-r--r--src/test/ui/proc-macro/pretty-print-hack-hide.stdout21
-rw-r--r--src/test/ui/proc-macro/pretty-print-hack-show.rs17
-rw-r--r--src/test/ui/proc-macro/pretty-print-hack-show.stderr179
-rw-r--r--src/test/ui/proc-macro/pretty-print-hack-show.stdout44
-rw-r--r--src/test/ui/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs14
-rw-r--r--src/test/ui/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs14
-rw-r--r--src/test/ui/proc-macro/pretty-print-hack/rental-0.5.6/src/lib.rs14
-rw-r--r--src/test/ui/proc-macro/proc-macro-attributes.stderr2
-rw-r--r--src/test/ui/proc-macro/proc-macro-gates.stderr2
-rw-r--r--src/test/ui/proc-macro/three-equals.stderr6
-rw-r--r--src/test/ui/process/process-panic-after-fork.rs45
-rw-r--r--src/test/ui/process/process-spawn-nonexistent.rs1
-rw-r--r--src/test/ui/process/process-spawn-with-unicode-params.rs1
-rw-r--r--src/test/ui/process/signal-exit-status.rs1
-rw-r--r--src/test/ui/pub/pub-reexport-priv-extern-crate.stderr2
-rw-r--r--src/test/ui/pub/pub-restricted-error.stderr2
-rw-r--r--src/test/ui/query-system/query_depth.rs31
-rw-r--r--src/test/ui/query-system/query_depth.stderr11
-rw-r--r--src/test/ui/query-visibility.rs9
-rw-r--r--src/test/ui/range/range-inclusive-pattern-precedence.stderr4
-rw-r--r--src/test/ui/range/range-inclusive-pattern-precedence2.stderr4
-rw-r--r--src/test/ui/recursion/issue-83150.stderr6
-rw-r--r--src/test/ui/recursion/issue-95134.rs4
-rw-r--r--src/test/ui/recursion/issue-95134.stderr7
-rw-r--r--src/test/ui/recursion/recursive-enum.stderr4
-rw-r--r--src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr4
-rw-r--r--src/test/ui/regions/issue-101280.rs10
-rw-r--r--src/test/ui/regions/issue-101280.stderr14
-rw-r--r--src/test/ui/regions/issue-102374.rs20
-rw-r--r--src/test/ui/regions/issue-102374.stderr14
-rw-r--r--src/test/ui/regions/issue-102392.rs6
-rw-r--r--src/test/ui/regions/issue-102392.stderr14
-rw-r--r--src/test/ui/regions/region-bound-on-closure-outlives-call.stderr2
-rw-r--r--src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr4
-rw-r--r--src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr4
-rw-r--r--src/test/ui/regions/regions-fn-subtyping-return-static-fail.stderr2
-rw-r--r--src/test/ui/regions/regions-lifetime-bounds-on-fns.stderr4
-rw-r--r--src/test/ui/repr/repr-transparent-issue-87496.stderr2
-rw-r--r--src/test/ui/repr/repr-transparent-non-exhaustive.rs24
-rw-r--r--src/test/ui/repr/repr-transparent-non-exhaustive.stderr30
-rw-r--r--src/test/ui/resolve/bad-env-capture.stderr12
-rw-r--r--src/test/ui/resolve/bad-env-capture2.stderr12
-rw-r--r--src/test/ui/resolve/bad-env-capture3.stderr12
-rw-r--r--src/test/ui/resolve/bad-expr-path.stderr12
-rw-r--r--src/test/ui/resolve/bad-expr-path2.stderr12
-rw-r--r--src/test/ui/resolve/issue-102946.rs7
-rw-r--r--src/test/ui/resolve/issue-102946.stderr26
-rw-r--r--src/test/ui/resolve/issue-103202.rs7
-rw-r--r--src/test/ui/resolve/issue-103202.stderr9
-rw-r--r--src/test/ui/resolve/issue-14254.stderr127
-rw-r--r--src/test/ui/resolve/issue-23305.rs2
-rw-r--r--src/test/ui/resolve/issue-23305.stderr16
-rw-r--r--src/test/ui/resolve/issue-2356.stderr90
-rw-r--r--src/test/ui/resolve/issue-42944.stderr24
-rw-r--r--src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr4
-rw-r--r--src/test/ui/resolve/issue-73427.stderr40
-rw-r--r--src/test/ui/resolve/levenshtein.stderr18
-rw-r--r--src/test/ui/resolve/name-collision-in-trait-fn-sig.rs11
-rw-r--r--src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.stderr13
-rw-r--r--src/test/ui/resolve/privacy-enum-ctor.stderr6
-rw-r--r--src/test/ui/resolve/resolve-assoc-suggestions.stderr2
-rw-r--r--src/test/ui/resolve/resolve-hint-macro.stderr22
-rw-r--r--src/test/ui/resolve/resolve-self-in-impl.rs9
-rw-r--r--src/test/ui/resolve/resolve-self-in-impl.stderr74
-rw-r--r--src/test/ui/resolve/resolve-speculative-adjustment.stderr12
-rw-r--r--src/test/ui/resolve/tuple-struct-alias.stderr16
-rw-r--r--src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr38
-rw-r--r--src/test/ui/return/issue-64620.rs (renamed from src/test/ui/issues/issue-64620.rs)0
-rw-r--r--src/test/ui/return/issue-64620.stderr (renamed from src/test/ui/issues/issue-64620.stderr)0
-rw-r--r--src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-doubly-indirect-embedded.stderr4
-rw-r--r--src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-doubly-indirect-param.stderr4
-rw-r--r--src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-indirect-struct-embedded.stderr4
-rw-r--r--src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-indirect-struct-param.stderr4
-rw-r--r--src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-62307-match-ref-ref-forbidden-without-eq.stderr4
-rw-r--r--src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-63479-match-fnptr.stderr4
-rw-r--r--src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-6804.stderr4
-rw-r--r--src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.stderr2
-rw-r--r--src/test/ui/rfc-1937-termination-trait/issue-103052-1.rs11
-rw-r--r--src/test/ui/rfc-1937-termination-trait/issue-103052-1.stderr17
-rw-r--r--src/test/ui/rfc-1937-termination-trait/issue-103052-2.rs18
-rw-r--r--src/test/ui/rfc-1937-termination-trait/issue-103052-2.stderr15
-rw-r--r--src/test/ui/rfc-1937-termination-trait/termination-trait-in-test.rs1
-rw-r--r--src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr7
-rw-r--r--src/test/ui/rfc-2008-non-exhaustive/improper_ctypes/extern_crate_improper.stderr2
-rw-r--r--src/test/ui/rfc-2008-non-exhaustive/omitted-patterns.stderr48
-rw-r--r--src/test/ui/rfc-2008-non-exhaustive/stable-omitted-patterns.stderr8
-rw-r--r--src/test/ui/rfc-2008-non-exhaustive/struct.stderr12
-rw-r--r--src/test/ui/rfc-2091-track-caller/std-panic-locations.rs1
-rw-r--r--src/test/ui/rfc-2126-extern-absolute-paths/not-allowed.stderr7
-rw-r--r--src/test/ui/rfc-2294-if-let-guard/warns.stderr4
-rw-r--r--src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr4
-rw-r--r--src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.disallowed.stderr26
-rw-r--r--src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs15
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.rs14
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr10
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/auxiliary/staged-api.rs1
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr21
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs1
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs1
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.stderr1
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs9
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr21
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.rs1
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.stderr2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr4
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr77
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs15
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr77
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/const-drop.rs3
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.rs2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.stderr4
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.rs9
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.stderr14
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr4
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr4
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.rs1
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.stderr10
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr4
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/feature-gate.gated.stderr2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/feature-gate.rs1
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/feature-gate.stock.stderr13
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs1
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/inherent-impl-const-bounds.rs2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/issue-100222.rs10
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs15
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr19
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/issue-102985.rs12
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/issue-102985.stderr41
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/issue-103677.rs5
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/issue-90052.rs9
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/issue-90052.stderr14
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/issue-92230-wf-super-trait-env.rs2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/nested-closure.rs12
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/non-const-op-in-closure-in-const.rs1
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.rs31
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.stderr19
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/specializing-constness.rs26
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/specializing-constness.stderr8
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/static-const-trait-bound.rs18
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.nn.stderr8
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.ny.stderr8
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs9
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr24
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yn.stderr21
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yy.stderr21
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.nn.stderr14
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.ny.stderr8
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.rs20
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.yn.stderr8
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr10
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits.rs3
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs34
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.stderr14
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs7
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr36
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.rs17
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.rs31
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.stderr35
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs1
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs1
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs19
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr56
-rw-r--r--src/test/ui/rfc1623-2.stderr2
-rw-r--r--src/test/ui/rfcs/rfc1857-drop-order.rs1
-rw-r--r--src/test/ui/runtime/backtrace-debuginfo.rs1
-rw-r--r--src/test/ui/runtime/out-of-stack.rs1
-rw-r--r--src/test/ui/runtime/rt-explody-panic-payloads.rs14
-rw-r--r--src/test/ui/rust-2018/async-ident-allowed.stderr4
-rw-r--r--src/test/ui/rust-2018/async-ident.stderr4
-rw-r--r--src/test/ui/rust-2018/dyn-keyword.stderr4
-rw-r--r--src/test/ui/rust-2018/edition-lint-fully-qualified-paths.stderr4
-rw-r--r--src/test/ui/rust-2018/edition-lint-nested-empty-paths.stderr4
-rw-r--r--src/test/ui/rust-2018/edition-lint-nested-paths.stderr4
-rw-r--r--src/test/ui/rust-2018/edition-lint-paths.stderr4
-rw-r--r--src/test/ui/rust-2018/extern-crate-rename.stderr4
-rw-r--r--src/test/ui/rust-2018/extern-crate-submod.stderr4
-rw-r--r--src/test/ui/rust-2018/try-ident.stderr4
-rw-r--r--src/test/ui/rust-2018/try-macro.stderr4
-rw-r--r--src/test/ui/rust-2021/array-into-iter-ambiguous.stderr4
-rw-r--r--src/test/ui/rust-2021/future-prelude-collision-generic-trait.stderr4
-rw-r--r--src/test/ui/rust-2021/future-prelude-collision-generic.stderr4
-rw-r--r--src/test/ui/rust-2021/future-prelude-collision-imported.stderr4
-rw-r--r--src/test/ui/rust-2021/future-prelude-collision-macros.stderr4
-rw-r--r--src/test/ui/rust-2021/future-prelude-collision-turbofish.stderr4
-rw-r--r--src/test/ui/rust-2021/future-prelude-collision.stderr4
-rw-r--r--src/test/ui/rust-2021/generic-type-collision.stderr4
-rw-r--r--src/test/ui/rust-2021/inherent-dyn-collision.stderr4
-rw-r--r--src/test/ui/rust-2021/reserved-prefixes-migration.stderr4
-rw-r--r--src/test/ui/rustdoc/deny-invalid-doc-attrs.stderr4
-rw-r--r--src/test/ui/rustdoc/doc-test-attr.stderr4
-rw-r--r--src/test/ui/rustdoc/feature-gate-doc_primitive.stderr2
-rw-r--r--src/test/ui/sanitize/address.rs4
-rw-r--r--src/test/ui/sanitize/hwaddress.rs2
-rw-r--r--src/test/ui/sanitize/inline-always.stderr2
-rw-r--r--src/test/ui/sanitize/leak.rs2
-rw-r--r--src/test/ui/sanitize/memory-eager.rs1
-rw-r--r--src/test/ui/sanitize/memory.rs1
-rw-r--r--src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs2
-rw-r--r--src/test/ui/save-analysis/issue-68621.stderr2
-rw-r--r--src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr2
-rw-r--r--src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr2
-rw-r--r--src/test/ui/simd/portable-intrinsics-arent-exposed.stderr5
-rw-r--r--src/test/ui/simd/target-feature-mixup.rs1
-rw-r--r--src/test/ui/single-use-lifetime/derive-eq.rs11
-rw-r--r--src/test/ui/sized-cycle-note.rs11
-rw-r--r--src/test/ui/sized-cycle-note.stderr32
-rw-r--r--src/test/ui/span/E0072.stderr6
-rw-r--r--src/test/ui/span/E0204.stderr8
-rw-r--r--src/test/ui/span/E0493.rs2
-rw-r--r--src/test/ui/span/E0493.stderr4
-rw-r--r--src/test/ui/span/E0535.stderr2
-rw-r--r--src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs1
-rw-r--r--src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr38
-rw-r--r--src/test/ui/span/issue-7575.rs75
-rw-r--r--src/test/ui/span/issue-7575.stderr82
-rw-r--r--src/test/ui/span/multiline-span-E0072.stderr6
-rw-r--r--src/test/ui/span/recursive-type-field.rs4
-rw-r--r--src/test/ui/span/recursive-type-field.stderr38
-rw-r--r--src/test/ui/specialization/assoc-ty-graph-cycle.stderr2
-rw-r--r--src/test/ui/specialization/const_trait_impl.rs55
-rw-r--r--src/test/ui/specialization/cross-crate-defaults.stderr2
-rw-r--r--src/test/ui/specialization/default-associated-type-bound-1.stderr2
-rw-r--r--src/test/ui/specialization/default-associated-type-bound-2.stderr2
-rw-r--r--src/test/ui/specialization/default-generic-associated-type-bound.stderr2
-rw-r--r--src/test/ui/specialization/defaultimpl/allowed-cross-crate.stderr2
-rw-r--r--src/test/ui/specialization/defaultimpl/out-of-order.stderr2
-rw-r--r--src/test/ui/specialization/defaultimpl/overlap-projection.stderr2
-rw-r--r--src/test/ui/specialization/defaultimpl/projection.stderr2
-rw-r--r--src/test/ui/specialization/defaultimpl/specialization-no-default.stderr2
-rw-r--r--src/test/ui/specialization/defaultimpl/specialization-trait-item-not-implemented-rpass.stderr2
-rw-r--r--src/test/ui/specialization/defaultimpl/specialization-trait-item-not-implemented.stderr2
-rw-r--r--src/test/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr2
-rw-r--r--src/test/ui/specialization/defaultimpl/specialization-wfcheck.stderr2
-rw-r--r--src/test/ui/specialization/defaultimpl/validation.stderr2
-rw-r--r--src/test/ui/specialization/issue-35376.stderr2
-rw-r--r--src/test/ui/specialization/issue-36804.stderr2
-rw-r--r--src/test/ui/specialization/issue-38091-2.stderr4
-rw-r--r--src/test/ui/specialization/issue-38091.stderr2
-rw-r--r--src/test/ui/specialization/issue-39448.stderr2
-rw-r--r--src/test/ui/specialization/issue-39618.stderr2
-rw-r--r--src/test/ui/specialization/issue-50452-fail.stderr2
-rw-r--r--src/test/ui/specialization/issue-50452.stderr2
-rw-r--r--src/test/ui/specialization/issue-52050.stderr2
-rw-r--r--src/test/ui/specialization/issue-63716-parse-async.stderr2
-rw-r--r--src/test/ui/specialization/issue-70442.stderr2
-rw-r--r--src/test/ui/specialization/non-defaulted-item-fail.stderr2
-rw-r--r--src/test/ui/specialization/specialization-allowed-cross-crate.stderr2
-rw-r--r--src/test/ui/specialization/specialization-assoc-fns.stderr2
-rw-r--r--src/test/ui/specialization/specialization-basics.stderr2
-rw-r--r--src/test/ui/specialization/specialization-cross-crate.stderr2
-rw-r--r--src/test/ui/specialization/specialization-default-methods.stderr2
-rw-r--r--src/test/ui/specialization/specialization-default-projection.stderr2
-rw-r--r--src/test/ui/specialization/specialization-default-types.stderr2
-rw-r--r--src/test/ui/specialization/specialization-no-default.stderr2
-rw-r--r--src/test/ui/specialization/specialization-on-projection.stderr2
-rw-r--r--src/test/ui/specialization/specialization-out-of-order.stderr2
-rw-r--r--src/test/ui/specialization/specialization-overlap-negative.stderr2
-rw-r--r--src/test/ui/specialization/specialization-overlap-projection.stderr2
-rw-r--r--src/test/ui/specialization/specialization-overlap.stderr2
-rw-r--r--src/test/ui/specialization/specialization-polarity.stderr2
-rw-r--r--src/test/ui/specialization/specialization-projection-alias.stderr2
-rw-r--r--src/test/ui/specialization/specialization-projection.stderr2
-rw-r--r--src/test/ui/specialization/specialization-supertraits.stderr2
-rw-r--r--src/test/ui/specialization/specialization-translate-projections-with-lifetimes.stderr2
-rw-r--r--src/test/ui/specialization/specialization-translate-projections-with-params.stderr2
-rw-r--r--src/test/ui/specialization/specialization-translate-projections.stderr2
-rw-r--r--src/test/ui/specialization/transmute-specialization.stderr2
-rw-r--r--src/test/ui/stability-attribute/missing-const-stability.rs1
-rw-r--r--src/test/ui/stability-attribute/missing-const-stability.stderr2
-rw-r--r--src/test/ui/stability-attribute/stability-attribute-trait-impl.rs16
-rw-r--r--src/test/ui/stability-attribute/stability-attribute-trait-impl.stderr16
-rw-r--r--src/test/ui/stability-attribute/stable-in-unstable.rs8
-rw-r--r--src/test/ui/stability-attribute/stable-in-unstable.stderr20
-rw-r--r--src/test/ui/static/static-drop-scope.rs16
-rw-r--r--src/test/ui/static/static-drop-scope.stderr32
-rw-r--r--src/test/ui/statics/issue-17718-static-sync.rs (renamed from src/test/ui/issues/issue-17718-static-sync.rs)0
-rw-r--r--src/test/ui/statics/issue-17718-static-sync.stderr (renamed from src/test/ui/issues/issue-17718-static-sync.stderr)0
-rw-r--r--src/test/ui/statics/issue-17718-static-unsafe-interior.rs (renamed from src/test/ui/issues/issue-17718-static-unsafe-interior.rs)0
-rw-r--r--src/test/ui/statics/uninhabited-static.stderr18
-rw-r--r--src/test/ui/stats/hir-stats.rs1
-rw-r--r--src/test/ui/stats/hir-stats.stderr96
-rw-r--r--src/test/ui/std-backtrace.rs1
-rw-r--r--src/test/ui/structs-enums/issue-2718-a.rs (renamed from src/test/ui/issues/issue-2718-a.rs)0
-rw-r--r--src/test/ui/structs-enums/issue-2718-a.stderr (renamed from src/test/ui/issues/issue-2718-a.stderr)4
-rw-r--r--src/test/ui/structs-enums/rec-align-u32.rs1
-rw-r--r--src/test/ui/structs-enums/rec-align-u64.rs1
-rw-r--r--src/test/ui/structs-enums/struct-rec/issue-74224.stderr4
-rw-r--r--src/test/ui/structs-enums/struct-rec/issue-84611.stderr4
-rw-r--r--src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.rs6
-rw-r--r--src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr62
-rw-r--r--src/test/ui/structs/incomplete-fn-in-struct-definition.rs5
-rw-r--r--src/test/ui/structs/incomplete-fn-in-struct-definition.stderr15
-rw-r--r--src/test/ui/structs/struct-fn-in-definition.stderr9
-rw-r--r--src/test/ui/structs/struct-path-associated-type.rs4
-rw-r--r--src/test/ui/structs/struct-path-associated-type.stderr30
-rw-r--r--src/test/ui/suggestions/abi-typo.fixed6
-rw-r--r--src/test/ui/suggestions/abi-typo.rs6
-rw-r--r--src/test/ui/suggestions/abi-typo.stderr14
-rw-r--r--src/test/ui/suggestions/assoc_fn_without_self.stderr12
-rw-r--r--src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr9
-rw-r--r--src/test/ui/suggestions/boxed-variant-field.rs1
-rw-r--r--src/test/ui/suggestions/boxed-variant-field.stderr4
-rw-r--r--src/test/ui/suggestions/call-on-unimplemented-ctor.rs17
-rw-r--r--src/test/ui/suggestions/call-on-unimplemented-ctor.stderr21
-rw-r--r--src/test/ui/suggestions/call-on-unimplemented-fn-ptr.rs15
-rw-r--r--src/test/ui/suggestions/call-on-unimplemented-fn-ptr.stderr21
-rw-r--r--src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr9
-rw-r--r--src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr14
-rw-r--r--src/test/ui/suggestions/fn-to-method.rs19
-rw-r--r--src/test/ui/suggestions/fn-to-method.stderr38
-rw-r--r--src/test/ui/suggestions/format-borrow.stderr16
-rw-r--r--src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr12
-rw-r--r--src/test/ui/suggestions/inner_type.fixed40
-rw-r--r--src/test/ui/suggestions/inner_type.rs40
-rw-r--r--src/test/ui/suggestions/inner_type.stderr83
-rw-r--r--src/test/ui/suggestions/inner_type2.rs26
-rw-r--r--src/test/ui/suggestions/inner_type2.stderr29
-rw-r--r--src/test/ui/suggestions/into-convert.rs26
-rw-r--r--src/test/ui/suggestions/into-convert.stderr44
-rw-r--r--src/test/ui/suggestions/issue-101065.fixed14
-rw-r--r--src/test/ui/suggestions/issue-101065.rs14
-rw-r--r--src/test/ui/suggestions/issue-101065.stderr23
-rw-r--r--src/test/ui/suggestions/issue-101623.rs25
-rw-r--r--src/test/ui/suggestions/issue-101623.stderr14
-rw-r--r--src/test/ui/suggestions/issue-101984.stderr4
-rw-r--r--src/test/ui/suggestions/issue-102354.rs10
-rw-r--r--src/test/ui/suggestions/issue-102354.stderr24
-rw-r--r--src/test/ui/suggestions/issue-102892.rs25
-rw-r--r--src/test/ui/suggestions/issue-102892.stderr57
-rw-r--r--src/test/ui/suggestions/issue-103112.rs4
-rw-r--r--src/test/ui/suggestions/issue-103112.stderr15
-rw-r--r--src/test/ui/suggestions/issue-61963.stderr4
-rw-r--r--src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr1
-rw-r--r--src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr4
-rw-r--r--src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.stderr4
-rw-r--r--src/test/ui/suggestions/match-with-different-arm-types-as-stmt-instead-of-expr.stderr2
-rw-r--r--src/test/ui/suggestions/missing-bound-in-manual-copy-impl-2.stderr4
-rw-r--r--src/test/ui/suggestions/missing-bound-in-manual-copy-impl.stderr4
-rw-r--r--src/test/ui/suggestions/non-existent-field-present-in-subfield-recursion-limit.rs2
-rw-r--r--src/test/ui/suggestions/return-closures.stderr2
-rw-r--r--src/test/ui/suggestions/struct-field-type-including-single-colon.stderr4
-rw-r--r--src/test/ui/suggestions/sugg-else-for-closure.fixed8
-rw-r--r--src/test/ui/suggestions/sugg-else-for-closure.rs8
-rw-r--r--src/test/ui/suggestions/sugg-else-for-closure.stderr23
-rw-r--r--src/test/ui/suggestions/suggest-let-for-assignment.fixed17
-rw-r--r--src/test/ui/suggestions/suggest-let-for-assignment.rs17
-rw-r--r--src/test/ui/suggestions/suggest-let-for-assignment.stderr60
-rw-r--r--src/test/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr2
-rw-r--r--src/test/ui/symbol-names/impl1.legacy.stderr2
-rw-r--r--src/test/ui/symbol-names/impl1.rs4
-rw-r--r--src/test/ui/symbol-names/impl1.v0.stderr2
-rw-r--r--src/test/ui/test-attrs/inaccessible-test-modules.stderr14
-rw-r--r--src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs1
-rw-r--r--src/test/ui/test-attrs/test-on-not-fn.stderr24
-rw-r--r--src/test/ui/test-attrs/test-panic-while-printing.rs1
-rw-r--r--src/test/ui/test-attrs/test-should-fail-good-message.rs1
-rw-r--r--src/test/ui/test-attrs/test-thread-capture.rs1
-rw-r--r--src/test/ui/test-attrs/test-thread-capture.run.stdout2
-rw-r--r--src/test/ui/test-attrs/test-thread-nocapture.rs1
-rw-r--r--src/test/ui/test-attrs/test-thread-nocapture.run.stderr2
-rw-r--r--src/test/ui/thir-tree.stdout4
-rw-r--r--src/test/ui/threads-sendsync/issue-43733-2.rs2
-rw-r--r--src/test/ui/threads-sendsync/issue-43733.rs2
-rw-r--r--src/test/ui/threads-sendsync/sync-send-in-std.rs1
-rw-r--r--src/test/ui/traits/associated_type_bound/check-trait-object-bounds-2.stderr2
-rw-r--r--src/test/ui/traits/bound/not-on-bare-trait.stderr2
-rw-r--r--src/test/ui/traits/copy-impl-cannot-normalize.stderr4
-rw-r--r--src/test/ui/traits/issue-102989.rs16
-rw-r--r--src/test/ui/traits/issue-102989.stderr59
-rw-r--r--src/test/ui/traits/issue-33140-hack-boundaries.stderr17
-rw-r--r--src/test/ui/traits/issue-43784-supertrait.rs (renamed from src/test/ui/issues/issue-43784-supertrait.rs)0
-rw-r--r--src/test/ui/traits/issue-43784-supertrait.stderr (renamed from src/test/ui/issues/issue-43784-supertrait.stderr)0
-rw-r--r--src/test/ui/traits/issue-8153.stderr7
-rw-r--r--src/test/ui/traits/issue-91949-hangs-on-recursion.stderr2
-rw-r--r--src/test/ui/traits/negative-impls/negative-default-impls.stderr2
-rw-r--r--src/test/ui/traits/negative-impls/negative-specializes-negative.stderr2
-rw-r--r--src/test/ui/traits/negative-impls/negative-specializes-positive-item.stderr2
-rw-r--r--src/test/ui/traits/negative-impls/negative-specializes-positive.stderr2
-rw-r--r--src/test/ui/traits/negative-impls/positive-specializes-negative.stderr2
-rw-r--r--src/test/ui/traits/object/issue-33140-traitobject-crate.stderr57
-rw-r--r--src/test/ui/traits/safety-trait-impl-cc.stderr6
-rw-r--r--src/test/ui/traits/safety-trait-impl.stderr12
-rw-r--r--src/test/ui/traits/static-method-generic-inference.stderr4
-rw-r--r--src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr4
-rw-r--r--src/test/ui/traits/trait-upcasting/multiple-occurrence-ambiguousity.rs (renamed from src/test/ui/traits/trait-upcasting/multiple-occurence-ambiguousity.rs)0
-rw-r--r--src/test/ui/traits/trait-upcasting/multiple-occurrence-ambiguousity.stderr (renamed from src/test/ui/traits/trait-upcasting/multiple-occurence-ambiguousity.stderr)2
-rw-r--r--src/test/ui/traits/unspecified-self-in-trait-ref.stderr2
-rw-r--r--src/test/ui/transmutability/enums/should_order_correctly.rs1
-rw-r--r--src/test/ui/transmutability/enums/should_respect_endianness.rs1
-rw-r--r--src/test/ui/transmutability/enums/should_respect_endianness.stderr4
-rw-r--r--src/test/ui/transmutability/issue-101739-1.rs21
-rw-r--r--src/test/ui/transmutability/issue-101739-1.stderr16
-rw-r--r--src/test/ui/transmutability/issue-101739-2.rs37
-rw-r--r--src/test/ui/transmutability/issue-101739-2.stderr20
-rw-r--r--src/test/ui/transmutability/malformed-program-gracefulness/wrong-type-assume.rs4
-rw-r--r--src/test/ui/transmutability/malformed-program-gracefulness/wrong-type-assume.stderr37
-rw-r--r--src/test/ui/transmute-equal-assoc-types.rs4
-rw-r--r--src/test/ui/transmute-equal-assoc-types.stderr11
-rw-r--r--src/test/ui/transmute/lifetimes.rs23
-rw-r--r--src/test/ui/transmute/main.rs2
-rw-r--r--src/test/ui/transmute/main.stderr10
-rw-r--r--src/test/ui/treat-err-as-bug/delay_span_bug.rs2
-rw-r--r--src/test/ui/treat-err-as-bug/delay_span_bug.stderr2
-rw-r--r--src/test/ui/try-trait/bad-interconversion.stderr2
-rw-r--r--src/test/ui/type-alias-enum-variants/enum-variant-priority-lint-ambiguous_associated_items.stderr2
-rw-r--r--src/test/ui/type-alias-impl-trait/closure_parent_substs.rs65
-rw-r--r--src/test/ui/type-alias-impl-trait/closure_wf_outlives.rs65
-rw-r--r--src/test/ui/type-alias-impl-trait/closure_wf_outlives.stderr64
-rw-r--r--src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs3
-rw-r--r--src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.stderr10
-rw-r--r--src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug_no_type.rs6
-rw-r--r--src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug_no_type.stderr10
-rw-r--r--src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.rs4
-rw-r--r--src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.stderr14
-rw-r--r--src/test/ui/type-alias-impl-trait/different_defining_uses_never_type3.rs12
-rw-r--r--src/test/ui/type-alias-impl-trait/different_defining_uses_never_type3.stderr14
-rw-r--r--src/test/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs6
-rw-r--r--src/test/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr4
-rw-r--r--src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs5
-rw-r--r--src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr6
-rw-r--r--src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs7
-rw-r--r--src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr12
-rw-r--r--src/test/ui/type-alias-impl-trait/generic_lifetime_param.rs5
-rw-r--r--src/test/ui/type-alias-impl-trait/implied_bounds.rs51
-rw-r--r--src/test/ui/type-alias-impl-trait/implied_bounds.stderr16
-rw-r--r--src/test/ui/type-alias-impl-trait/implied_bounds2.rs10
-rw-r--r--src/test/ui/type-alias-impl-trait/implied_bounds3.rs18
-rw-r--r--src/test/ui/type-alias-impl-trait/implied_bounds_closure.rs31
-rw-r--r--src/test/ui/type-alias-impl-trait/implied_bounds_closure.stderr11
-rw-r--r--src/test/ui/type-alias-impl-trait/implied_bounds_from_types.rs51
-rw-r--r--src/test/ui/type-alias-impl-trait/implied_bounds_from_types.stderr16
-rw-r--r--src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check.rs27
-rw-r--r--src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs43
-rw-r--r--src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr58
-rw-r--r--src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs11
-rw-r--r--src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr14
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-101750.rs37
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr3
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr2
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-58662-generator-with-lifetime.rs2
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-58662-simplified.rs20
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-89686.rs2
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-89686.stderr2
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-96572-unconstrained-mismatch.rs10
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-96572-unconstrained-mismatch.stderr15
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-96572-unconstrained.rs92
-rw-r--r--src/test/ui/type-alias-impl-trait/missing_lifetime_bound.rs7
-rw-r--r--src/test/ui/type-alias-impl-trait/missing_lifetime_bound.stderr8
-rw-r--r--src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs6
-rw-r--r--src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr2
-rw-r--r--src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs6
-rw-r--r--src/test/ui/type-alias-impl-trait/unbounded_opaque_type.rs14
-rw-r--r--src/test/ui/type/issue-101866.rs15
-rw-r--r--src/test/ui/type/issue-101866.stderr18
-rw-r--r--src/test/ui/type/issue-94187-verbose-type-name.rs13
-rw-r--r--src/test/ui/type/type-check/assignment-expected-bool.stderr22
-rw-r--r--src/test/ui/type/type-check/assignment-in-if.rs19
-rw-r--r--src/test/ui/type/type-check/assignment-in-if.stderr71
-rw-r--r--src/test/ui/type/type-mismatch-same-crate-name.stderr11
-rw-r--r--src/test/ui/type/type-recursive-box-shadowed.stderr4
-rw-r--r--src/test/ui/type/type-recursive.stderr42
-rw-r--r--src/test/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.stderr4
-rw-r--r--src/test/ui/typeck/issue-87181/empty-tuple-method.stderr2
-rw-r--r--src/test/ui/typeck/issue-87181/enum-variant.stderr2
-rw-r--r--src/test/ui/typeck/issue-87181/tuple-field.stderr2
-rw-r--r--src/test/ui/typeck/slow-lhs-suggestion.rs26
-rw-r--r--src/test/ui/typeck/slow-lhs-suggestion.stderr187
-rw-r--r--src/test/ui/unboxed-closures/unboxed-closures-counter-not-moved.stderr2
-rw-r--r--src/test/ui/unboxed-closures/unboxed-closures-move-mutable.stderr2
-rw-r--r--src/test/ui/unboxed-closures/unboxed-closures-unsafe-extern-fn.stderr12
-rw-r--r--src/test/ui/unboxed-closures/unboxed-closures-wrong-abi.stderr18
-rw-r--r--src/test/ui/unboxed-closures/unboxed-closures-wrong-arg-type-extern-fn.stderr6
-rw-r--r--src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr5
-rw-r--r--src/test/ui/union/union-copy.stderr4
-rw-r--r--src/test/ui/union/union-nonrepresentable.stderr10
-rw-r--r--src/test/ui/union/union-repr-c.stderr10
-rw-r--r--src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.stderr2
-rw-r--r--src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.stderr4
-rw-r--r--src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.stderr2
-rw-r--r--src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.stderr4
-rw-r--r--src/test/ui/unresolved/unresolved-candidates.rs13
-rw-r--r--src/test/ui/unresolved/unresolved-candidates.stderr26
-rw-r--r--src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.mir.stderr4
-rw-r--r--src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.thir.stderr4
-rw-r--r--src/test/ui/unsized-locals/borrow-after-move.stderr2
-rw-r--r--src/test/ui/unsized-locals/by-value-trait-object-safety.stderr2
-rw-r--r--src/test/ui/unsized-locals/double-move.stderr2
-rw-r--r--src/test/ui/unsized-locals/issue-30276-feature-flagged.stderr2
-rw-r--r--src/test/ui/unsized-locals/issue-50940-with-feature.stderr2
-rw-r--r--src/test/ui/unwind-abis/feature-gate-c-unwind.stderr2
-rw-r--r--src/test/ui/unwind-abis/ffi-unwind-calls-lint.rs1
-rw-r--r--src/test/ui/unwind-abis/ffi-unwind-calls-lint.stderr6
-rw-r--r--src/test/ui/unwind-no-uwtable.rs1
-rw-r--r--src/test/ui/variance/variance-regions-unused-indirect.rs1
-rw-r--r--src/test/ui/variance/variance-regions-unused-indirect.stderr30
-rw-r--r--src/test/ui/wf/issue-103573.rs22
-rw-r--r--src/test/ui/wf/issue-103573.stderr14
-rw-r--r--src/test/ui/where-clauses/higher-ranked-fn-type.quiet.stderr18
-rw-r--r--src/test/ui/where-clauses/higher-ranked-fn-type.rs25
-rw-r--r--src/test/ui/where-clauses/higher-ranked-fn-type.verbose.stderr18
-rw-r--r--src/tools/build-manifest/src/main.rs55
-rw-r--r--src/tools/build-manifest/src/versions.rs19
-rw-r--r--src/tools/cargotest/main.rs6
-rw-r--r--src/tools/clippy/.github/workflows/clippy.yml1
-rw-r--r--src/tools/clippy/.github/workflows/clippy_bors.yml1
-rw-r--r--src/tools/clippy/.github/workflows/clippy_dev.yml2
-rw-r--r--src/tools/clippy/CHANGELOG.md166
-rw-r--r--src/tools/clippy/CONTRIBUTING.md27
-rw-r--r--src/tools/clippy/Cargo.toml8
-rw-r--r--src/tools/clippy/README.md46
-rw-r--r--src/tools/clippy/book/src/development/adding_lints.md24
-rw-r--r--src/tools/clippy/book/src/development/basics.md7
-rw-r--r--src/tools/clippy/book/src/development/common_tools_writing_lints.md15
-rw-r--r--src/tools/clippy/clippy_dev/src/fmt.rs6
-rw-r--r--src/tools/clippy/clippy_dev/src/lib.rs1
-rw-r--r--src/tools/clippy/clippy_dev/src/main.rs2
-rw-r--r--src/tools/clippy/clippy_dev/src/new_lint.rs166
-rw-r--r--src/tools/clippy/clippy_dev/src/serve.rs6
-rw-r--r--src/tools/clippy/clippy_dev/src/setup/git_hook.rs7
-rw-r--r--src/tools/clippy/clippy_dev/src/setup/intellij.rs42
-rw-r--r--src/tools/clippy/clippy_dev/src/setup/vscode.rs19
-rw-r--r--src/tools/clippy/clippy_dev/src/update_lints.rs111
-rw-r--r--src/tools/clippy/clippy_lints/Cargo.toml2
-rw-r--r--src/tools/clippy/clippy_lints/src/almost_complete_letter_range.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/approx_const.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/asm_syntax.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/assertions_on_constants.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/assertions_on_result_states.rs16
-rw-r--r--src/tools/clippy/clippy_lints/src/attrs.rs10
-rw-r--r--src/tools/clippy/clippy_lints/src/await_holding_invalid.rs42
-rw-r--r--src/tools/clippy/clippy_lints/src/blocks_in_if_conditions.rs68
-rw-r--r--src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/bool_to_int_with_if.rs54
-rw-r--r--src/tools/clippy/clippy_lints/src/booleans.rs13
-rw-r--r--src/tools/clippy/clippy_lints/src/box_default.rs129
-rw-r--r--src/tools/clippy/clippy_lints/src/cargo/common_metadata.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/cargo/feature_name.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/cargo/mod.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/cargo/multiple_crate_versions.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/as_ptr_cast_mut.rs38
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/borrow_as_ptr.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/cast_lossless.rs12
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/cast_nan_to_int.rs28
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs16
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/cast_possible_wrap.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/cast_slice_different_sizes.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/char_lit_as_u8.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast_any.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs7
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/mod.rs57
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/ptr_as_ptr.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs78
-rw-r--r--src/tools/clippy/clippy_lints/src/checked_conversions.rs16
-rw-r--r--src/tools/clippy/clippy_lints/src/cognitive_complexity.rs64
-rw-r--r--src/tools/clippy/clippy_lints/src/comparison_chain.rs8
-rw-r--r--src/tools/clippy/clippy_lints/src/copy_iterator.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/default.rs17
-rw-r--r--src/tools/clippy/clippy_lints/src/default_instead_of_iter_empty.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs69
-rw-r--r--src/tools/clippy/clippy_lints/src/default_union_representation.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/dereference.rs203
-rw-r--r--src/tools/clippy/clippy_lints/src/derivable_impls.rs28
-rw-r--r--src/tools/clippy/clippy_lints/src/derive.rs11
-rw-r--r--src/tools/clippy/clippy_lints/src/disallowed_macros.rs151
-rw-r--r--src/tools/clippy/clippy_lints/src/disallowed_methods.rs22
-rw-r--r--src/tools/clippy/clippy_lints/src/disallowed_script_idents.rs3
-rw-r--r--src/tools/clippy/clippy_lints/src/disallowed_types.rs24
-rw-r--r--src/tools/clippy/clippy_lints/src/doc.rs102
-rw-r--r--src/tools/clippy/clippy_lints/src/doc_link_with_quotes.rs60
-rw-r--r--src/tools/clippy/clippy_lints/src/double_parens.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/drop_forget_ref.rs30
-rw-r--r--src/tools/clippy/clippy_lints/src/empty_enum.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/entry.rs48
-rw-r--r--src/tools/clippy/clippy_lints/src/enum_variants.rs11
-rw-r--r--src/tools/clippy/clippy_lints/src/equatable_if_let.rs7
-rw-r--r--src/tools/clippy/clippy_lints/src/escape.rs19
-rw-r--r--src/tools/clippy/clippy_lints/src/eta_reduction.rs25
-rw-r--r--src/tools/clippy/clippy_lints/src/exhaustive_items.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/exit.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/explicit_write.rs8
-rw-r--r--src/tools/clippy/clippy_lints/src/fallible_impl_from.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/float_literal.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs55
-rw-r--r--src/tools/clippy/clippy_lints/src/format.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/format_args.rs302
-rw-r--r--src/tools/clippy/clippy_lints/src/format_impl.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/formatting.rs25
-rw-r--r--src/tools/clippy/clippy_lints/src/from_over_into.rs176
-rw-r--r--src/tools/clippy/clippy_lints/src/from_str_radix_10.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/functions/must_use.rs116
-rw-r--r--src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs95
-rw-r--r--src/tools/clippy/clippy_lints/src/functions/result.rs14
-rw-r--r--src/tools/clippy/clippy_lints/src/functions/too_many_arguments.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/functions/too_many_lines.rs10
-rw-r--r--src/tools/clippy/clippy_lints/src/future_not_send.rs32
-rw-r--r--src/tools/clippy/clippy_lints/src/if_then_some_else_none.rs19
-rw-r--r--src/tools/clippy/clippy_lints/src/implicit_hasher.rs11
-rw-r--r--src/tools/clippy/clippy_lints/src/implicit_return.rs16
-rw-r--r--src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs114
-rw-r--r--src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs22
-rw-r--r--src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/index_refutable_slice.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/indexing_slicing.rs1
-rw-r--r--src/tools/clippy/clippy_lints/src/infinite_iter.rs15
-rw-r--r--src/tools/clippy/clippy_lints/src/inherent_to_string.rs23
-rw-r--r--src/tools/clippy/clippy_lints/src/inline_fn_without_body.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/int_plus_one.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/invalid_upcast_comparisons.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/iter_not_returning_iterator.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/large_const_arrays.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/large_enum_variant.rs7
-rw-r--r--src/tools/clippy/clippy_lints/src/large_stack_arrays.rs50
-rw-r--r--src/tools/clippy/clippy_lints/src/len_zero.rs48
-rw-r--r--src/tools/clippy/clippy_lints/src/let_if_seq.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/let_underscore.rs23
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.register_all.rs13
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.register_complexity.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.register_correctness.rs1
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.register_internal.rs32
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.register_lints.rs48
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.register_nursery.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.register_pedantic.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.register_perf.rs1
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.register_restriction.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.register_style.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.register_suspicious.rs3
-rw-r--r--src/tools/clippy/clippy_lints/src/lib.rs98
-rw-r--r--src/tools/clippy/clippy_lints/src/lifetimes.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/literal_representation.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/explicit_counter_loop.rs14
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/for_kv_map.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/for_loops_over_fallibles.rs65
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/iter_next_loop.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/manual_find.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/manual_flatten.rs14
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs13
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/mod.rs59
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs29
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/needless_collect.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs45
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/never_loop.rs37
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/same_item_push.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/utils.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/loops/while_let_on_iterator.rs17
-rw-r--r--src/tools/clippy/clippy_lints/src/macro_use.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/manual_assert.rs31
-rw-r--r--src/tools/clippy/clippy_lints/src/manual_async_fn.rs24
-rw-r--r--src/tools/clippy/clippy_lints/src/manual_clamp.rs717
-rw-r--r--src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/manual_rem_euclid.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/manual_retain.rs18
-rw-r--r--src/tools/clippy/clippy_lints/src/manual_strip.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/map_unit_fn.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/match_result_ok.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/collapsible_match.rs29
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/manual_filter.rs153
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/manual_map.rs318
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/manual_unwrap_or.rs22
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/manual_utils.rs277
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs18
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs8
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/match_single_binding.rs51
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/match_str_case_mismatch.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/match_wild_err_arm.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/mod.rs40
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/needless_match.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs65
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/single_match.rs17
-rw-r--r--src/tools/clippy/clippy_lints/src/matches/try_err.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/mem_replace.rs72
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/bind_instead_of_map.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/bytes_nth.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/chars_cmp.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/chars_cmp_with_unwrap.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs13
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/clone_on_ref_ptr.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/err_expect.rs11
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs11
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/filetype_is_file.rs11
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/filter_map_next.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/filter_next.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/from_iter_instead_of_collect.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/get_first.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/get_last_with_len.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/get_unwrap.rs11
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/inefficient_to_string.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/into_iter_on_ref.rs8
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/is_digit_ascii_radix.rs7
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/iter_cloned_collect.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/iter_count.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/iter_kv_map.rs87
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/iter_next_slice.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/iter_nth.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs27
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/iter_with_drain.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/manual_ok_or.rs38
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs15
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs10
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/map_clone.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/map_flatten.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/map_identity.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/map_unwrap_or.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/mod.rs152
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/ok_expect.rs11
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs29
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/option_map_or_none.rs22
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/option_map_unwrap_or.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs33
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/or_then_unwrap.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/search_is_some.rs14
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/single_char_insert_string.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/single_char_push_string.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/stable_sort_primitive.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/str_splitn.rs24
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/string_extend_chars.rs3
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/suspicious_to_owned.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs73
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs7
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/unnecessary_iter_cloned.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/unnecessary_lazy_eval.rs10
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs38
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/useless_asref.rs7
-rw-r--r--src/tools/clippy/clippy_lints/src/methods/wrong_self_convention.rs15
-rw-r--r--src/tools/clippy/clippy_lints/src/minmax.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/misc.rs24
-rw-r--r--src/tools/clippy/clippy_lints/src/misc_early/literal_suffix.rs12
-rw-r--r--src/tools/clippy/clippy_lints/src/misc_early/mixed_case_hex_literals.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/misc_early/mod.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/misc_early/unneeded_field_pattern.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/misc_early/zero_prefixed_literal.rs18
-rw-r--r--src/tools/clippy/clippy_lints/src/mismatching_type_param_order.rs12
-rw-r--r--src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/missing_doc.rs12
-rw-r--r--src/tools/clippy/clippy_lints/src/missing_enforced_import_rename.rs7
-rw-r--r--src/tools/clippy/clippy_lints/src/missing_inline.rs14
-rw-r--r--src/tools/clippy/clippy_lints/src/missing_trait_methods.rs98
-rw-r--r--src/tools/clippy/clippy_lints/src/mixed_read_write_in_expression.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/module_style.rs21
-rw-r--r--src/tools/clippy/clippy_lints/src/mut_key.rs12
-rw-r--r--src/tools/clippy/clippy_lints/src/mut_reference.rs3
-rw-r--r--src/tools/clippy/clippy_lints/src/mutable_debug_assertion.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/mutex_atomic.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/needless_borrowed_ref.rs121
-rw-r--r--src/tools/clippy/clippy_lints/src/needless_continue.rs14
-rw-r--r--src/tools/clippy/clippy_lints/src/needless_for_each.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/needless_late_init.rs55
-rw-r--r--src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs21
-rw-r--r--src/tools/clippy/clippy_lints/src/needless_question_mark.rs16
-rw-r--r--src/tools/clippy/clippy_lints/src/neg_cmp_op_on_partial_ord.rs8
-rw-r--r--src/tools/clippy/clippy_lints/src/neg_multiply.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/new_without_default.rs11
-rw-r--r--src/tools/clippy/clippy_lints/src/non_copy_const.rs20
-rw-r--r--src/tools/clippy/clippy_lints/src/non_expressive_names.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/non_octal_unix_permissions.rs22
-rw-r--r--src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/nonstandard_macro_braces.rs83
-rw-r--r--src/tools/clippy/clippy_lints/src/octal_escapes.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs16
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs127
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs83
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/bit_mask.rs40
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/cmp_owned.rs28
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/duration_subsec.rs7
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/eq_op.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/misrefactored_assign_op.rs12
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/mod.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/needless_bitwise_bool.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/op_ref.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/ptr_eq.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/self_assignment.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/operators/verbose_bit_mask.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/option_env_unwrap.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/option_if_let_else.rs30
-rw-r--r--src/tools/clippy/clippy_lints/src/panic_in_result_fn.rs19
-rw-r--r--src/tools/clippy/clippy_lints/src/partial_pub_fields.rs81
-rw-r--r--src/tools/clippy/clippy_lints/src/partialeq_ne_impl.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/partialeq_to_none.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs8
-rw-r--r--src/tools/clippy/clippy_lints/src/precedence.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/ptr.rs66
-rw-r--r--src/tools/clippy/clippy_lints/src/ptr_offset_with_cast.rs14
-rw-r--r--src/tools/clippy/clippy_lints/src/question_mark.rs41
-rw-r--r--src/tools/clippy/clippy_lints/src/ranges.rs16
-rw-r--r--src/tools/clippy/clippy_lints/src/read_zero_byte_vec.rs45
-rw-r--r--src/tools/clippy/clippy_lints/src/redundant_clone.rs454
-rw-r--r--src/tools/clippy/clippy_lints/src/redundant_pub_crate.rs10
-rw-r--r--src/tools/clippy/clippy_lints/src/redundant_slicing.rs8
-rw-r--r--src/tools/clippy/clippy_lints/src/redundant_static_lifetimes.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/ref_option_ref.rs3
-rw-r--r--src/tools/clippy/clippy_lints/src/regex.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/renamed_lints.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/return_self_not_must_use.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/returns.rs212
-rw-r--r--src/tools/clippy/clippy_lints/src/same_name_method.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/self_named_constructors.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/semicolon_if_nothing_returned.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/shadow.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/slow_vector_initialization.rs16
-rw-r--r--src/tools/clippy/clippy_lints/src/std_instead_of_core.rs22
-rw-r--r--src/tools/clippy/clippy_lints/src/strings.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/strlen_on_c_strings.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs11
-rw-r--r--src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs37
-rw-r--r--src/tools/clippy/clippy_lints/src/swap.rs19
-rw-r--r--src/tools/clippy/clippy_lints/src/swap_ptr_to_ref.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/to_digit_is_some.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/trailing_empty_array.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/trait_bounds.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/crosspointer_transmute.rs10
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/transmute_float_to_int.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_bool.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_char.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_float.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/transmute_num_to_bytes.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/transmute_ptr_to_ref.rs18
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/transmute_ref_to_ref.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs178
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs41
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/unsound_collection_transmute.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/useless_transmute.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/utils.rs11
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute/wrong_transmute.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/types/borrowed_box.rs8
-rw-r--r--src/tools/clippy/clippy_lints/src/types/box_collection.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/types/mod.rs20
-rw-r--r--src/tools/clippy/clippy_lints/src/types/rc_buffer.rs27
-rw-r--r--src/tools/clippy/clippy_lints/src/types/redundant_allocation.rs55
-rw-r--r--src/tools/clippy/clippy_lints/src/types/vec_box.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/uninit_vec.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs23
-rw-r--r--src/tools/clippy/clippy_lints/src/unit_types/unit_arg.rs7
-rw-r--r--src/tools/clippy/clippy_lints/src/unit_types/unit_cmp.rs7
-rw-r--r--src/tools/clippy/clippy_lints/src/unnecessary_owned_empty_strings.rs4
-rw-r--r--src/tools/clippy/clippy_lints/src/unnecessary_self_imports.rs2
-rw-r--r--src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs15
-rw-r--r--src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/unsafe_removed_from_name.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/unused_io_amount.rs12
-rw-r--r--src/tools/clippy/clippy_lints/src/unused_peekable.rs36
-rw-r--r--src/tools/clippy/clippy_lints/src/unused_rounding.rs9
-rw-r--r--src/tools/clippy/clippy_lints/src/unused_self.rs6
-rw-r--r--src/tools/clippy/clippy_lints/src/unwrap.rs7
-rw-r--r--src/tools/clippy/clippy_lints/src/unwrap_in_result.rs72
-rw-r--r--src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs5
-rw-r--r--src/tools/clippy/clippy_lints/src/use_self.rs23
-rw-r--r--src/tools/clippy/clippy_lints/src/useless_conversion.rs19
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/author.rs121
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/conf.rs43
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints.rs1447
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/clippy_lints_internal.rs49
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/collapsible_calls.rs245
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/compiler_lint_functions.rs77
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/if_chain_style.rs164
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs239
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/invalid_paths.rs108
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs342
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs105
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs63
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/outer_expn_data_pass.rs62
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/produce_ice.rs37
-rw-r--r--src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs343
-rw-r--r--src/tools/clippy/clippy_lints/src/wildcard_imports.rs8
-rw-r--r--src/tools/clippy/clippy_lints/src/write.rs780
-rw-r--r--src/tools/clippy/clippy_lints/src/zero_div_zero.rs3
-rw-r--r--src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs7
-rw-r--r--src/tools/clippy/clippy_utils/Cargo.toml2
-rw-r--r--src/tools/clippy/clippy_utils/src/ast_utils.rs8
-rw-r--r--src/tools/clippy/clippy_utils/src/attrs.rs4
-rw-r--r--src/tools/clippy/clippy_utils/src/check_proc_macro.rs2
-rw-r--r--src/tools/clippy/clippy_utils/src/consts.rs56
-rw-r--r--src/tools/clippy/clippy_utils/src/diagnostics.rs51
-rw-r--r--src/tools/clippy/clippy_utils/src/eager_or_lazy.rs12
-rw-r--r--src/tools/clippy/clippy_utils/src/hir_utils.rs4
-rw-r--r--src/tools/clippy/clippy_utils/src/lib.rs297
-rw-r--r--src/tools/clippy/clippy_utils/src/macros.rs400
-rw-r--r--src/tools/clippy/clippy_utils/src/mir/maybe_storage_live.rs52
-rw-r--r--src/tools/clippy/clippy_utils/src/mir/mod.rs164
-rw-r--r--src/tools/clippy/clippy_utils/src/mir/possible_borrower.rs241
-rw-r--r--src/tools/clippy/clippy_utils/src/mir/possible_origin.rs59
-rw-r--r--src/tools/clippy/clippy_utils/src/mir/transitive_relation.rs29
-rw-r--r--src/tools/clippy/clippy_utils/src/msrvs.rs3
-rw-r--r--src/tools/clippy/clippy_utils/src/numeric_literal.rs7
-rw-r--r--src/tools/clippy/clippy_utils/src/paths.rs39
-rw-r--r--src/tools/clippy/clippy_utils/src/ptr.rs37
-rw-r--r--src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs36
-rw-r--r--src/tools/clippy/clippy_utils/src/source.rs18
-rw-r--r--src/tools/clippy/clippy_utils/src/sugg.rs120
-rw-r--r--src/tools/clippy/clippy_utils/src/ty.rs77
-rw-r--r--src/tools/clippy/clippy_utils/src/usage.rs77
-rw-r--r--src/tools/clippy/clippy_utils/src/visitors.rs164
-rw-r--r--src/tools/clippy/lintcheck/Cargo.toml2
-rw-r--r--src/tools/clippy/lintcheck/README.md20
-rw-r--r--src/tools/clippy/lintcheck/lintcheck_crates.toml8
-rw-r--r--src/tools/clippy/lintcheck/src/config.rs15
-rw-r--r--src/tools/clippy/lintcheck/src/driver.rs67
-rw-r--r--src/tools/clippy/lintcheck/src/main.rs320
-rw-r--r--src/tools/clippy/lintcheck/src/recursive.rs123
-rw-r--r--src/tools/clippy/rust-toolchain2
-rw-r--r--src/tools/clippy/rustc_tools_util/Cargo.toml2
-rw-r--r--src/tools/clippy/rustc_tools_util/README.md8
-rw-r--r--src/tools/clippy/rustc_tools_util/src/lib.rs12
-rw-r--r--src/tools/clippy/src/docs.rs14
-rw-r--r--src/tools/clippy/src/docs/arithmetic_side_effects.txt2
-rw-r--r--src/tools/clippy/src/docs/as_ptr_cast_mut.txt19
-rw-r--r--src/tools/clippy/src/docs/box_default.txt17
-rw-r--r--src/tools/clippy/src/docs/cast_nan_to_int.txt15
-rw-r--r--src/tools/clippy/src/docs/disallowed_macros.txt36
-rw-r--r--src/tools/clippy/src/docs/for_loops_over_fallibles.txt32
-rw-r--r--src/tools/clippy/src/docs/implicit_saturating_add.txt20
-rw-r--r--src/tools/clippy/src/docs/iter_kv_map.txt22
-rw-r--r--src/tools/clippy/src/docs/manual_clamp.txt46
-rw-r--r--src/tools/clippy/src/docs/manual_filter.txt21
-rw-r--r--src/tools/clippy/src/docs/missing_trait_methods.txt40
-rw-r--r--src/tools/clippy/src/docs/needless_borrowed_reference.txt18
-rw-r--r--src/tools/clippy/src/docs/partial_pub_fields.txt27
-rw-r--r--src/tools/clippy/src/docs/positional_named_format_parameters.txt15
-rw-r--r--src/tools/clippy/src/docs/print_literal.txt4
-rw-r--r--src/tools/clippy/src/docs/print_stderr.txt8
-rw-r--r--src/tools/clippy/src/docs/print_stdout.txt8
-rw-r--r--src/tools/clippy/src/docs/similar_names.txt4
-rw-r--r--src/tools/clippy/src/docs/uninlined_format_args.txt36
-rw-r--r--src/tools/clippy/src/docs/unused_format_specs.txt24
-rw-r--r--src/tools/clippy/src/docs/write_literal.txt4
-rw-r--r--src/tools/clippy/src/driver.rs6
-rw-r--r--src/tools/clippy/src/main.rs6
-rw-r--r--src/tools/clippy/tests/compile-test.rs25
-rw-r--r--src/tools/clippy/tests/dogfood.rs9
-rw-r--r--src/tools/clippy/tests/integration.rs23
-rw-r--r--src/tools/clippy/tests/lint_message_convention.rs2
-rw-r--r--src/tools/clippy/tests/missing-test-files.rs2
-rw-r--r--src/tools/clippy/tests/ui-cargo/duplicate_mod/fail/src/main.stderr2
-rw-r--r--src/tools/clippy/tests/ui-cargo/feature_name/fail/src/main.stderr4
-rw-r--r--src/tools/clippy/tests/ui-cargo/module_style/fail_mod/src/main.stderr2
-rw-r--r--src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/Cargo.toml9
-rw-r--r--src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/bad.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/bad/inner.rs1
-rw-r--r--src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.rs7
-rw-r--r--src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.stderr11
-rw-r--r--src/tools/clippy/tests/ui-cargo/module_style/fail_no_mod/src/main.stderr2
-rw-r--r--src/tools/clippy/tests/ui-internal/auxiliary/paths.rs2
-rw-r--r--src/tools/clippy/tests/ui-internal/check_clippy_version_attribute.stderr4
-rw-r--r--src/tools/clippy/tests/ui-internal/custom_ice_message.stderr2
-rw-r--r--src/tools/clippy/tests/ui-internal/if_chain_style.stderr2
-rw-r--r--src/tools/clippy/tests/ui-internal/invalid_paths.rs2
-rw-r--r--src/tools/clippy/tests/ui-internal/match_type_on_diag_item.rs39
-rw-r--r--src/tools/clippy/tests/ui-internal/match_type_on_diag_item.stderr27
-rw-r--r--src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed62
-rw-r--r--src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs62
-rw-r--r--src/tools/clippy/tests/ui-internal/unnecessary_def_path.stderr101
-rw-r--r--src/tools/clippy/tests/ui-internal/unnecessary_def_path_hardcoded_path.rs16
-rw-r--r--src/tools/clippy/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr27
-rw-r--r--src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr2
-rw-r--r--src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs2
-rw-r--r--src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr4
-rw-r--r--src/tools/clippy/tests/ui-toml/disallowed_macros/auxiliary/macros.rs32
-rw-r--r--src/tools/clippy/tests/ui-toml/disallowed_macros/clippy.toml11
-rw-r--r--src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.rs39
-rw-r--r--src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.stderr84
-rw-r--r--src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr2
-rw-r--r--src/tools/clippy/tests/ui-toml/fn_params_excessive_bools/test.stderr2
-rw-r--r--src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr2
-rw-r--r--src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed62
-rw-r--r--src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs2
-rw-r--r--src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr77
-rw-r--r--src/tools/clippy/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr2
-rw-r--r--src/tools/clippy/tests/ui-toml/struct_excessive_bools/test.stderr2
-rw-r--r--src/tools/clippy/tests/ui-toml/toml_disallowed_methods/clippy.toml1
-rw-r--r--src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs6
-rw-r--r--src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr24
-rw-r--r--src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr1
-rw-r--r--src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr2
-rw-r--r--src/tools/clippy/tests/ui/absurd-extreme-comparisons.stderr2
-rw-r--r--src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr2
-rw-r--r--src/tools/clippy/tests/ui/almost_complete_letter_range.fixed13
-rw-r--r--src/tools/clippy/tests/ui/almost_complete_letter_range.rs13
-rw-r--r--src/tools/clippy/tests/ui/almost_complete_letter_range.stderr39
-rw-r--r--src/tools/clippy/tests/ui/approx_const.stderr2
-rw-r--r--src/tools/clippy/tests/ui/arithmetic_side_effects.rs191
-rw-r--r--src/tools/clippy/tests/ui/arithmetic_side_effects.stderr356
-rw-r--r--src/tools/clippy/tests/ui/as_conversions.stderr2
-rw-r--r--src/tools/clippy/tests/ui/as_ptr_cast_mut.rs37
-rw-r--r--src/tools/clippy/tests/ui/as_ptr_cast_mut.stderr16
-rw-r--r--src/tools/clippy/tests/ui/asm_syntax.stderr4
-rw-r--r--src/tools/clippy/tests/ui/assertions_on_constants.stderr2
-rw-r--r--src/tools/clippy/tests/ui/assertions_on_result_states.fixed6
-rw-r--r--src/tools/clippy/tests/ui/assertions_on_result_states.rs6
-rw-r--r--src/tools/clippy/tests/ui/assertions_on_result_states.stderr8
-rw-r--r--src/tools/clippy/tests/ui/assign_ops2.rs2
-rw-r--r--src/tools/clippy/tests/ui/assign_ops2.stderr20
-rw-r--r--src/tools/clippy/tests/ui/author.stdout24
-rw-r--r--src/tools/clippy/tests/ui/author/blocks.stdout116
-rw-r--r--src/tools/clippy/tests/ui/author/call.stdout28
-rw-r--r--src/tools/clippy/tests/ui/author/if.stdout92
-rw-r--r--src/tools/clippy/tests/ui/author/issue_3849.stdout24
-rw-r--r--src/tools/clippy/tests/ui/author/loop.stdout202
-rw-r--r--src/tools/clippy/tests/ui/author/matches.stdout72
-rw-r--r--src/tools/clippy/tests/ui/author/repeat.stdout20
-rw-r--r--src/tools/clippy/tests/ui/author/struct.stdout112
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/macro_rules.rs7
-rw-r--r--src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs2
-rw-r--r--src/tools/clippy/tests/ui/await_holding_lock.stderr2
-rw-r--r--src/tools/clippy/tests/ui/await_holding_refcell_ref.stderr2
-rw-r--r--src/tools/clippy/tests/ui/bind_instead_of_map.fixed1
-rw-r--r--src/tools/clippy/tests/ui/bind_instead_of_map.rs1
-rw-r--r--src/tools/clippy/tests/ui/bind_instead_of_map.stderr6
-rw-r--r--src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr2
-rw-r--r--src/tools/clippy/tests/ui/bool_to_int_with_if.fixed8
-rw-r--r--src/tools/clippy/tests/ui/bool_to_int_with_if.rs14
-rw-r--r--src/tools/clippy/tests/ui/bool_to_int_with_if.stderr43
-rw-r--r--src/tools/clippy/tests/ui/borrow_box.rs5
-rw-r--r--src/tools/clippy/tests/ui/borrow_box.stderr20
-rw-r--r--src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.stderr2
-rw-r--r--src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.stderr2
-rw-r--r--src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.stderr2
-rw-r--r--src/tools/clippy/tests/ui/box_collection.rs4
-rw-r--r--src/tools/clippy/tests/ui/box_collection.stderr2
-rw-r--r--src/tools/clippy/tests/ui/box_default.fixed57
-rw-r--r--src/tools/clippy/tests/ui/box_default.rs57
-rw-r--r--src/tools/clippy/tests/ui/box_default.stderr88
-rw-r--r--src/tools/clippy/tests/ui/box_default_no_std.rs33
-rw-r--r--src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.rs3
-rw-r--r--src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.stderr22
-rw-r--r--src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.rs5
-rw-r--r--src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.stderr32
-rw-r--r--src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs3
-rw-r--r--src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr30
-rw-r--r--src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.rs5
-rw-r--r--src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.stderr30
-rw-r--r--src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr2
-rw-r--r--src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed17
-rw-r--r--src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs17
-rw-r--r--src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr42
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_bool.fixed13
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_bool.rs13
-rw-r--r--src/tools/clippy/tests/ui/cast_lossless_bool.stderr34
-rw-r--r--src/tools/clippy/tests/ui/cast_nan_to_int.rs18
-rw-r--r--src/tools/clippy/tests/ui/cast_nan_to_int.stderr51
-rw-r--r--src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed16
-rw-r--r--src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs16
-rw-r--r--src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr8
-rw-r--r--src/tools/clippy/tests/ui/char_lit_as_u8.stderr2
-rw-r--r--src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.stderr2
-rw-r--r--src/tools/clippy/tests/ui/checked_conversions.fixed16
-rw-r--r--src/tools/clippy/tests/ui/checked_conversions.rs16
-rw-r--r--src/tools/clippy/tests/ui/checked_conversions.stderr40
-rw-r--r--src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.stderr2
-rw-r--r--src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed24
-rw-r--r--src/tools/clippy/tests/ui/cloned_instead_of_copied.rs24
-rw-r--r--src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr30
-rw-r--r--src/tools/clippy/tests/ui/cognitive_complexity.stderr2
-rw-r--r--src/tools/clippy/tests/ui/cognitive_complexity_attr_used.stderr2
-rw-r--r--src/tools/clippy/tests/ui/collapsible_if.fixed3
-rw-r--r--src/tools/clippy/tests/ui/collapsible_if.rs5
-rw-r--r--src/tools/clippy/tests/ui/collapsible_if.stderr10
-rw-r--r--src/tools/clippy/tests/ui/collapsible_match.rs24
-rw-r--r--src/tools/clippy/tests/ui/collapsible_match.stderr76
-rw-r--r--src/tools/clippy/tests/ui/collapsible_match2.stderr2
-rw-r--r--src/tools/clippy/tests/ui/comparison_chain.stderr2
-rw-r--r--src/tools/clippy/tests/ui/copy_iterator.stderr2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-360.stderr2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-4775.rs2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-6254.stderr2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-7126.rs6
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-7868.stderr2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-7869.stderr2
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-9445.rs3
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-9459.rs5
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-9463.rs5
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-9463.stderr29
-rw-r--r--src/tools/clippy/tests/ui/crashes/ice-9625.rs4
-rw-r--r--src/tools/clippy/tests/ui/crashes/regressions.rs2
-rw-r--r--src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.stderr2
-rw-r--r--src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.stderr2
-rw-r--r--src/tools/clippy/tests/ui/crate_level_checks/std_main_recursion.stderr2
-rw-r--r--src/tools/clippy/tests/ui/def_id_nocore.stderr2
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed9
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs9
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_f64.stderr34
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed10
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs10
-rw-r--r--src/tools/clippy/tests/ui/default_numeric_fallback_i32.stderr34
-rw-r--r--src/tools/clippy/tests/ui/default_trait_access.fixed4
-rw-r--r--src/tools/clippy/tests/ui/default_trait_access.rs4
-rw-r--r--src/tools/clippy/tests/ui/default_trait_access.stderr2
-rw-r--r--src/tools/clippy/tests/ui/default_union_representation.stderr2
-rw-r--r--src/tools/clippy/tests/ui/derivable_impls.fixed213
-rw-r--r--src/tools/clippy/tests/ui/derivable_impls.rs4
-rw-r--r--src/tools/clippy/tests/ui/derivable_impls.stderr56
-rw-r--r--src/tools/clippy/tests/ui/derive.stderr2
-rw-r--r--src/tools/clippy/tests/ui/derive_hash_xor_eq.stderr2
-rw-r--r--src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr2
-rw-r--r--src/tools/clippy/tests/ui/doc/unbalanced_ticks.stderr2
-rw-r--r--src/tools/clippy/tests/ui/doc_link_with_quotes.rs7
-rw-r--r--src/tools/clippy/tests/ui/doc_link_with_quotes.stderr6
-rw-r--r--src/tools/clippy/tests/ui/double_must_use.stderr2
-rw-r--r--src/tools/clippy/tests/ui/drop_forget_copy.rs20
-rw-r--r--src/tools/clippy/tests/ui/drop_forget_copy.stderr42
-rw-r--r--src/tools/clippy/tests/ui/drop_non_drop.stderr2
-rw-r--r--src/tools/clippy/tests/ui/drop_ref.stderr2
-rw-r--r--src/tools/clippy/tests/ui/else_if_without_else.stderr2
-rw-r--r--src/tools/clippy/tests/ui/empty_enum.stderr2
-rw-r--r--src/tools/clippy/tests/ui/empty_loop.stderr2
-rw-r--r--src/tools/clippy/tests/ui/empty_loop_no_std.stderr2
-rw-r--r--src/tools/clippy/tests/ui/entry.fixed1
-rw-r--r--src/tools/clippy/tests/ui/entry.rs1
-rw-r--r--src/tools/clippy/tests/ui/entry.stderr20
-rw-r--r--src/tools/clippy/tests/ui/eprint_with_newline.rs10
-rw-r--r--src/tools/clippy/tests/ui/eprint_with_newline.stderr18
-rw-r--r--src/tools/clippy/tests/ui/err_expect.fixed17
-rw-r--r--src/tools/clippy/tests/ui/err_expect.rs17
-rw-r--r--src/tools/clippy/tests/ui/err_expect.stderr10
-rw-r--r--src/tools/clippy/tests/ui/eta.fixed25
-rw-r--r--src/tools/clippy/tests/ui/eta.rs25
-rw-r--r--src/tools/clippy/tests/ui/eta.stderr20
-rw-r--r--src/tools/clippy/tests/ui/expect.stderr2
-rw-r--r--src/tools/clippy/tests/ui/expect_fun_call.fixed9
-rw-r--r--src/tools/clippy/tests/ui/expect_fun_call.rs9
-rw-r--r--src/tools/clippy/tests/ui/expect_fun_call.stderr40
-rw-r--r--src/tools/clippy/tests/ui/explicit_counter_loop.rs1
-rw-r--r--src/tools/clippy/tests/ui/explicit_counter_loop.stderr18
-rw-r--r--src/tools/clippy/tests/ui/explicit_deref_methods.fixed10
-rw-r--r--src/tools/clippy/tests/ui/explicit_deref_methods.rs10
-rw-r--r--src/tools/clippy/tests/ui/explicit_write.fixed5
-rw-r--r--src/tools/clippy/tests/ui/explicit_write.rs5
-rw-r--r--src/tools/clippy/tests/ui/explicit_write.stderr32
-rw-r--r--src/tools/clippy/tests/ui/fallible_impl_from.rs1
-rw-r--r--src/tools/clippy/tests/ui/fallible_impl_from.stderr26
-rw-r--r--src/tools/clippy/tests/ui/field_reassign_with_default.stderr2
-rw-r--r--src/tools/clippy/tests/ui/filetype_is_file.stderr2
-rw-r--r--src/tools/clippy/tests/ui/filter_map_next_fixable.fixed16
-rw-r--r--src/tools/clippy/tests/ui/filter_map_next_fixable.rs16
-rw-r--r--src/tools/clippy/tests/ui/filter_map_next_fixable.stderr10
-rw-r--r--src/tools/clippy/tests/ui/float_cmp.stderr2
-rw-r--r--src/tools/clippy/tests/ui/float_cmp_const.stderr2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_exp.fixed1
-rw-r--r--src/tools/clippy/tests/ui/floating_point_exp.rs1
-rw-r--r--src/tools/clippy/tests/ui/floating_point_exp.stderr10
-rw-r--r--src/tools/clippy/tests/ui/floating_point_log.fixed2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_log.rs2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_logbase.fixed1
-rw-r--r--src/tools/clippy/tests/ui/floating_point_logbase.rs1
-rw-r--r--src/tools/clippy/tests/ui/floating_point_logbase.stderr10
-rw-r--r--src/tools/clippy/tests/ui/floating_point_mul_add.fixed2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_mul_add.rs2
-rw-r--r--src/tools/clippy/tests/ui/floating_point_mul_add.stderr30
-rw-r--r--src/tools/clippy/tests/ui/floating_point_powf.fixed1
-rw-r--r--src/tools/clippy/tests/ui/floating_point_powf.rs1
-rw-r--r--src/tools/clippy/tests/ui/floating_point_powf.stderr62
-rw-r--r--src/tools/clippy/tests/ui/floating_point_powi.fixed3
-rw-r--r--src/tools/clippy/tests/ui/floating_point_powi.rs3
-rw-r--r--src/tools/clippy/tests/ui/floating_point_powi.stderr24
-rw-r--r--src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr2
-rw-r--r--src/tools/clippy/tests/ui/for_loop_fixable.fixed2
-rw-r--r--src/tools/clippy/tests/ui/for_loop_fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/for_loop_unfixable.rs1
-rw-r--r--src/tools/clippy/tests/ui/for_loop_unfixable.stderr2
-rw-r--r--src/tools/clippy/tests/ui/for_loops_over_fallibles.rs72
-rw-r--r--src/tools/clippy/tests/ui/for_loops_over_fallibles.stderr95
-rw-r--r--src/tools/clippy/tests/ui/forget_non_drop.stderr2
-rw-r--r--src/tools/clippy/tests/ui/forget_ref.stderr2
-rw-r--r--src/tools/clippy/tests/ui/format.fixed10
-rw-r--r--src/tools/clippy/tests/ui/format.rs10
-rw-r--r--src/tools/clippy/tests/ui/format.stderr44
-rw-r--r--src/tools/clippy/tests/ui/format_args.fixed15
-rw-r--r--src/tools/clippy/tests/ui/format_args.rs15
-rw-r--r--src/tools/clippy/tests/ui/format_args.stderr60
-rw-r--r--src/tools/clippy/tests/ui/format_args_unfixable.rs6
-rw-r--r--src/tools/clippy/tests/ui/format_args_unfixable.stderr38
-rw-r--r--src/tools/clippy/tests/ui/format_push_string.stderr2
-rw-r--r--src/tools/clippy/tests/ui/formatting.stderr4
-rw-r--r--src/tools/clippy/tests/ui/from_over_into.fixed87
-rw-r--r--src/tools/clippy/tests/ui/from_over_into.rs66
-rw-r--r--src/tools/clippy/tests/ui/from_over_into.stderr70
-rw-r--r--src/tools/clippy/tests/ui/from_over_into_unfixable.rs35
-rw-r--r--src/tools/clippy/tests/ui/from_over_into_unfixable.stderr29
-rw-r--r--src/tools/clippy/tests/ui/functions.rs4
-rw-r--r--src/tools/clippy/tests/ui/future_not_send.stderr2
-rw-r--r--src/tools/clippy/tests/ui/get_unwrap.stderr2
-rw-r--r--src/tools/clippy/tests/ui/identity_op.fixed4
-rw-r--r--src/tools/clippy/tests/ui/identity_op.rs4
-rw-r--r--src/tools/clippy/tests/ui/if_let_mutex.stderr2
-rw-r--r--src/tools/clippy/tests/ui/if_not_else.stderr2
-rw-r--r--src/tools/clippy/tests/ui/if_same_then_else.stderr2
-rw-r--r--src/tools/clippy/tests/ui/if_same_then_else2.stderr2
-rw-r--r--src/tools/clippy/tests/ui/if_then_some_else_none.stderr2
-rw-r--r--src/tools/clippy/tests/ui/ifs_same_cond.stderr2
-rw-r--r--src/tools/clippy/tests/ui/impl.stderr2
-rw-r--r--src/tools/clippy/tests/ui/implicit_saturating_add.fixed106
-rw-r--r--src/tools/clippy/tests/ui/implicit_saturating_add.rs154
-rw-r--r--src/tools/clippy/tests/ui/implicit_saturating_add.stderr197
-rw-r--r--src/tools/clippy/tests/ui/implicit_saturating_sub.fixed50
-rw-r--r--src/tools/clippy/tests/ui/implicit_saturating_sub.rs50
-rw-r--r--src/tools/clippy/tests/ui/implicit_saturating_sub.stderr46
-rw-r--r--src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs1
-rw-r--r--src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.stderr20
-rw-r--r--src/tools/clippy/tests/ui/indexing_slicing_index.rs2
-rw-r--r--src/tools/clippy/tests/ui/indexing_slicing_index.stderr10
-rw-r--r--src/tools/clippy/tests/ui/indexing_slicing_slice.stderr2
-rw-r--r--src/tools/clippy/tests/ui/inefficient_to_string.stderr10
-rw-r--r--src/tools/clippy/tests/ui/infinite_iter.rs2
-rw-r--r--src/tools/clippy/tests/ui/infinite_iter.stderr32
-rw-r--r--src/tools/clippy/tests/ui/infinite_loop.stderr2
-rw-r--r--src/tools/clippy/tests/ui/inherent_to_string.stderr4
-rw-r--r--src/tools/clippy/tests/ui/inspect_for_each.stderr2
-rw-r--r--src/tools/clippy/tests/ui/integer_division.stderr2
-rw-r--r--src/tools/clippy/tests/ui/issue_2356.fixed1
-rw-r--r--src/tools/clippy/tests/ui/issue_2356.rs1
-rw-r--r--src/tools/clippy/tests/ui/issue_2356.stderr2
-rw-r--r--src/tools/clippy/tests/ui/issue_4266.rs1
-rw-r--r--src/tools/clippy/tests/ui/issue_4266.stderr8
-rw-r--r--src/tools/clippy/tests/ui/item_after_statement.rs1
-rw-r--r--src/tools/clippy/tests/ui/item_after_statement.stderr6
-rw-r--r--src/tools/clippy/tests/ui/iter_kv_map.fixed64
-rw-r--r--src/tools/clippy/tests/ui/iter_kv_map.rs64
-rw-r--r--src/tools/clippy/tests/ui/iter_kv_map.stderr136
-rw-r--r--src/tools/clippy/tests/ui/iter_nth.stderr2
-rw-r--r--src/tools/clippy/tests/ui/iter_skip_next_unfixable.stderr2
-rw-r--r--src/tools/clippy/tests/ui/large_enum_variant.rs4
-rw-r--r--src/tools/clippy/tests/ui/large_enum_variant.stderr16
-rw-r--r--src/tools/clippy/tests/ui/large_stack_arrays.rs6
-rw-r--r--src/tools/clippy/tests/ui/large_stack_arrays.stderr10
-rw-r--r--src/tools/clippy/tests/ui/len_without_is_empty.rs2
-rw-r--r--src/tools/clippy/tests/ui/len_without_is_empty.stderr2
-rw-r--r--src/tools/clippy/tests/ui/let_if_seq.stderr2
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_drop.stderr2
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_lock.stderr2
-rw-r--r--src/tools/clippy/tests/ui/let_underscore_must_use.stderr2
-rw-r--r--src/tools/clippy/tests/ui/linkedlist.stderr2
-rw-r--r--src/tools/clippy/tests/ui/literals.rs7
-rw-r--r--src/tools/clippy/tests/ui/literals.stderr35
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.edition2018.fixed43
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.edition2018.stderr58
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.edition2021.fixed18
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.edition2021.stderr51
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.fixed45
-rw-r--r--src/tools/clippy/tests/ui/manual_assert.rs19
-rw-r--r--src/tools/clippy/tests/ui/manual_bits.fixed3
-rw-r--r--src/tools/clippy/tests/ui/manual_bits.rs3
-rw-r--r--src/tools/clippy/tests/ui/manual_bits.stderr58
-rw-r--r--src/tools/clippy/tests/ui/manual_clamp.rs331
-rw-r--r--src/tools/clippy/tests/ui/manual_clamp.stderr390
-rw-r--r--src/tools/clippy/tests/ui/manual_filter.fixed119
-rw-r--r--src/tools/clippy/tests/ui/manual_filter.rs243
-rw-r--r--src/tools/clippy/tests/ui/manual_filter.stderr191
-rw-r--r--src/tools/clippy/tests/ui/manual_find.stderr2
-rw-r--r--src/tools/clippy/tests/ui/manual_find_fixable.fixed4
-rw-r--r--src/tools/clippy/tests/ui/manual_find_fixable.rs4
-rw-r--r--src/tools/clippy/tests/ui/manual_flatten.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_flatten.stderr2
-rw-r--r--src/tools/clippy/tests/ui/manual_map_option.fixed2
-rw-r--r--src/tools/clippy/tests/ui/manual_map_option.rs2
-rw-r--r--src/tools/clippy/tests/ui/manual_non_exhaustive_enum.stderr2
-rw-r--r--src/tools/clippy/tests/ui/manual_non_exhaustive_struct.stderr2
-rw-r--r--src/tools/clippy/tests/ui/manual_rem_euclid.fixed30
-rw-r--r--src/tools/clippy/tests/ui/manual_rem_euclid.rs30
-rw-r--r--src/tools/clippy/tests/ui/manual_rem_euclid.stderr30
-rw-r--r--src/tools/clippy/tests/ui/manual_strip.rs19
-rw-r--r--src/tools/clippy/tests/ui/manual_strip.stderr49
-rw-r--r--src/tools/clippy/tests/ui/map_err.stderr2
-rw-r--r--src/tools/clippy/tests/ui/map_unwrap_or.rs18
-rw-r--r--src/tools/clippy/tests/ui/map_unwrap_or.stderr30
-rw-r--r--src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed16
-rw-r--r--src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs19
-rw-r--r--src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr38
-rw-r--r--src/tools/clippy/tests/ui/match_overlapping_arm.rs1
-rw-r--r--src/tools/clippy/tests/ui/match_overlapping_arm.stderr34
-rw-r--r--src/tools/clippy/tests/ui/match_ref_pats.fixed3
-rw-r--r--src/tools/clippy/tests/ui/match_ref_pats.rs3
-rw-r--r--src/tools/clippy/tests/ui/match_ref_pats.stderr10
-rw-r--r--src/tools/clippy/tests/ui/match_result_ok.fixed3
-rw-r--r--src/tools/clippy/tests/ui/match_result_ok.rs3
-rw-r--r--src/tools/clippy/tests/ui/match_result_ok.stderr6
-rw-r--r--src/tools/clippy/tests/ui/match_same_arms.stderr2
-rw-r--r--src/tools/clippy/tests/ui/match_same_arms2.rs6
-rw-r--r--src/tools/clippy/tests/ui/match_same_arms2.stderr48
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding.fixed13
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding.rs12
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding.stderr19
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding2.fixed2
-rw-r--r--src/tools/clippy/tests/ui/match_single_binding2.rs2
-rw-r--r--src/tools/clippy/tests/ui/match_wild_err_arm.edition2018.stderr35
-rw-r--r--src/tools/clippy/tests/ui/match_wild_err_arm.rs3
-rw-r--r--src/tools/clippy/tests/ui/match_wild_err_arm.stderr (renamed from src/tools/clippy/tests/ui/match_wild_err_arm.edition2021.stderr)10
-rw-r--r--src/tools/clippy/tests/ui/mem_replace.fixed18
-rw-r--r--src/tools/clippy/tests/ui/mem_replace.rs18
-rw-r--r--src/tools/clippy/tests/ui/mem_replace.stderr46
-rw-r--r--src/tools/clippy/tests/ui/min_max.rs1
-rw-r--r--src/tools/clippy/tests/ui/min_max.stderr26
-rw-r--r--src/tools/clippy/tests/ui/min_rust_version_attr.rs227
-rw-r--r--src/tools/clippy/tests/ui/min_rust_version_attr.stderr46
-rw-r--r--src/tools/clippy/tests/ui/min_rust_version_invalid_attr.rs14
-rw-r--r--src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr44
-rw-r--r--src/tools/clippy/tests/ui/min_rust_version_multiple_inner_attr.rs11
-rw-r--r--src/tools/clippy/tests/ui/min_rust_version_multiple_inner_attr.stderr38
-rw-r--r--src/tools/clippy/tests/ui/min_rust_version_no_patch.rs14
-rw-r--r--src/tools/clippy/tests/ui/min_rust_version_outer_attr.rs4
-rw-r--r--src/tools/clippy/tests/ui/min_rust_version_outer_attr.stderr8
-rw-r--r--src/tools/clippy/tests/ui/mismatched_target_os_unix.stderr2
-rw-r--r--src/tools/clippy/tests/ui/mismatching_type_param_order.stderr2
-rw-r--r--src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs12
-rw-r--r--src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr12
-rw-r--r--src/tools/clippy/tests/ui/missing_doc.rs1
-rw-r--r--src/tools/clippy/tests/ui/missing_doc.stderr48
-rw-r--r--src/tools/clippy/tests/ui/missing_panics_doc.stderr2
-rw-r--r--src/tools/clippy/tests/ui/missing_trait_methods.rs50
-rw-r--r--src/tools/clippy/tests/ui/missing_trait_methods.stderr27
-rw-r--r--src/tools/clippy/tests/ui/mixed_read_write_in_expression.stderr2
-rw-r--r--src/tools/clippy/tests/ui/modulo_arithmetic_float.stderr2
-rw-r--r--src/tools/clippy/tests/ui/modulo_arithmetic_integral.stderr2
-rw-r--r--src/tools/clippy/tests/ui/modulo_arithmetic_integral_const.stderr2
-rw-r--r--src/tools/clippy/tests/ui/mut_from_ref.stderr2
-rw-r--r--src/tools/clippy/tests/ui/mut_mut.rs4
-rw-r--r--src/tools/clippy/tests/ui/mut_range_bound.stderr2
-rw-r--r--src/tools/clippy/tests/ui/needless_borrow.fixed93
-rw-r--r--src/tools/clippy/tests/ui/needless_borrow.rs91
-rw-r--r--src/tools/clippy/tests/ui/needless_borrow.stderr96
-rw-r--r--src/tools/clippy/tests/ui/needless_borrowed_ref.fixed41
-rw-r--r--src/tools/clippy/tests/ui/needless_borrowed_ref.rs41
-rw-r--r--src/tools/clippy/tests/ui/needless_borrowed_ref.stderr121
-rw-r--r--src/tools/clippy/tests/ui/needless_collect_indirect.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_collect_indirect.stderr32
-rw-r--r--src/tools/clippy/tests/ui/needless_continue.rs1
-rw-r--r--src/tools/clippy/tests/ui/needless_continue.stderr18
-rw-r--r--src/tools/clippy/tests/ui/needless_for_each_fixable.fixed7
-rw-r--r--src/tools/clippy/tests/ui/needless_for_each_fixable.rs7
-rw-r--r--src/tools/clippy/tests/ui/needless_for_each_fixable.stderr16
-rw-r--r--src/tools/clippy/tests/ui/needless_for_each_unfixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/needless_late_init.fixed5
-rw-r--r--src/tools/clippy/tests/ui/needless_late_init.rs5
-rw-r--r--src/tools/clippy/tests/ui/needless_late_init.stderr32
-rw-r--r--src/tools/clippy/tests/ui/needless_pass_by_value.rs9
-rw-r--r--src/tools/clippy/tests/ui/needless_pass_by_value.stderr52
-rw-r--r--src/tools/clippy/tests/ui/needless_range_loop.rs1
-rw-r--r--src/tools/clippy/tests/ui/needless_range_loop.stderr28
-rw-r--r--src/tools/clippy/tests/ui/needless_return.fixed37
-rw-r--r--src/tools/clippy/tests/ui/needless_return.rs37
-rw-r--r--src/tools/clippy/tests/ui/needless_return.stderr205
-rw-r--r--src/tools/clippy/tests/ui/never_loop.rs26
-rw-r--r--src/tools/clippy/tests/ui/never_loop.stderr15
-rw-r--r--src/tools/clippy/tests/ui/no_effect.rs6
-rw-r--r--src/tools/clippy/tests/ui/no_effect.stderr60
-rw-r--r--src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr2
-rw-r--r--src/tools/clippy/tests/ui/nonminimal_bool.rs6
-rw-r--r--src/tools/clippy/tests/ui/nonminimal_bool.stderr8
-rw-r--r--src/tools/clippy/tests/ui/octal_escapes.stderr2
-rw-r--r--src/tools/clippy/tests/ui/ok_expect.stderr2
-rw-r--r--src/tools/clippy/tests/ui/only_used_in_recursion.stderr2
-rw-r--r--src/tools/clippy/tests/ui/only_used_in_recursion2.stderr2
-rw-r--r--src/tools/clippy/tests/ui/option_as_ref_deref.fixed17
-rw-r--r--src/tools/clippy/tests/ui/option_as_ref_deref.rs17
-rw-r--r--src/tools/clippy/tests/ui/option_as_ref_deref.stderr42
-rw-r--r--src/tools/clippy/tests/ui/option_env_unwrap.stderr2
-rw-r--r--src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed3
-rw-r--r--src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs3
-rw-r--r--src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr38
-rw-r--r--src/tools/clippy/tests/ui/option_take_on_temporary.fixed15
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.fixed14
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.rs14
-rw-r--r--src/tools/clippy/tests/ui/or_fun_call.stderr52
-rw-r--r--src/tools/clippy/tests/ui/out_of_bounds_indexing/issue-3102.rs2
-rw-r--r--src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs2
-rw-r--r--src/tools/clippy/tests/ui/overly_complex_bool_expr.stderr2
-rw-r--r--src/tools/clippy/tests/ui/panic_in_result_fn.stderr2
-rw-r--r--src/tools/clippy/tests/ui/panic_in_result_fn_assertions.rs2
-rw-r--r--src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr2
-rw-r--r--src/tools/clippy/tests/ui/panic_in_result_fn_debug_assertions.rs2
-rw-r--r--src/tools/clippy/tests/ui/partial_pub_fields.rs40
-rw-r--r--src/tools/clippy/tests/ui/partial_pub_fields.stderr35
-rw-r--r--src/tools/clippy/tests/ui/pattern_type_mismatch/mutability.stderr2
-rw-r--r--src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr2
-rw-r--r--src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_structs.stderr2
-rw-r--r--src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_tuples.stderr2
-rw-r--r--src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.stderr2
-rw-r--r--src/tools/clippy/tests/ui/patterns.fixed3
-rw-r--r--src/tools/clippy/tests/ui/patterns.rs3
-rw-r--r--src/tools/clippy/tests/ui/patterns.stderr6
-rw-r--r--src/tools/clippy/tests/ui/positional_named_format_parameters.fixed56
-rw-r--r--src/tools/clippy/tests/ui/positional_named_format_parameters.rs56
-rw-r--r--src/tools/clippy/tests/ui/positional_named_format_parameters.stderr418
-rw-r--r--src/tools/clippy/tests/ui/print_literal.rs3
-rw-r--r--src/tools/clippy/tests/ui/print_literal.stderr56
-rw-r--r--src/tools/clippy/tests/ui/print_with_newline.rs10
-rw-r--r--src/tools/clippy/tests/ui/print_with_newline.stderr18
-rw-r--r--src/tools/clippy/tests/ui/println_empty_string.stderr24
-rw-r--r--src/tools/clippy/tests/ui/proc_macro.stderr2
-rw-r--r--src/tools/clippy/tests/ui/ptr_arg.rs30
-rw-r--r--src/tools/clippy/tests/ui/ptr_arg.stderr20
-rw-r--r--src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed1
-rw-r--r--src/tools/clippy/tests/ui/ptr_offset_with_cast.rs1
-rw-r--r--src/tools/clippy/tests/ui/ptr_offset_with_cast.stderr4
-rw-r--r--src/tools/clippy/tests/ui/pub_use.stderr2
-rw-r--r--src/tools/clippy/tests/ui/question_mark.fixed9
-rw-r--r--src/tools/clippy/tests/ui/question_mark.rs9
-rw-r--r--src/tools/clippy/tests/ui/range_contains.fixed26
-rw-r--r--src/tools/clippy/tests/ui/range_contains.rs26
-rw-r--r--src/tools/clippy/tests/ui/range_contains.stderr48
-rw-r--r--src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr2
-rw-r--r--src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr2
-rw-r--r--src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr2
-rw-r--r--src/tools/clippy/tests/ui/rc_mutex.stderr2
-rw-r--r--src/tools/clippy/tests/ui/recursive_format_impl.rs5
-rw-r--r--src/tools/clippy/tests/ui/recursive_format_impl.stderr20
-rw-r--r--src/tools/clippy/tests/ui/redundant_allocation.stderr2
-rw-r--r--src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr2
-rw-r--r--src/tools/clippy/tests/ui/redundant_clone.fixed4
-rw-r--r--src/tools/clippy/tests/ui/redundant_clone.rs4
-rw-r--r--src/tools/clippy/tests/ui/redundant_clone.stderr2
-rw-r--r--src/tools/clippy/tests/ui/redundant_else.stderr2
-rw-r--r--src/tools/clippy/tests/ui/redundant_field_names.fixed16
-rw-r--r--src/tools/clippy/tests/ui/redundant_field_names.rs16
-rw-r--r--src/tools/clippy/tests/ui/redundant_field_names.stderr22
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.stderr2
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed11
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs11
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr36
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed11
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs11
-rw-r--r--src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr44
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed13
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.rs13
-rw-r--r--src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr40
-rw-r--r--src/tools/clippy/tests/ui/ref_option_ref.rs5
-rw-r--r--src/tools/clippy/tests/ui/regex.stderr2
-rw-r--r--src/tools/clippy/tests/ui/rename.fixed9
-rw-r--r--src/tools/clippy/tests/ui/rename.rs5
-rw-r--r--src/tools/clippy/tests/ui/rename.stderr96
-rw-r--r--src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.stderr2
-rw-r--r--src/tools/clippy/tests/ui/result_large_err.stderr2
-rw-r--r--src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed2
-rw-r--r--src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs2
-rw-r--r--src/tools/clippy/tests/ui/result_unit_error.stderr2
-rw-r--r--src/tools/clippy/tests/ui/return_self_not_must_use.stderr2
-rw-r--r--src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed1
-rw-r--r--src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs1
-rw-r--r--src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.stderr8
-rw-r--r--src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed1
-rw-r--r--src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs1
-rw-r--r--src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.stderr12
-rw-r--r--src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.rs1
-rw-r--r--src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.stderr4
-rw-r--r--src/tools/clippy/tests/ui/same_functions_in_if_condition.rs12
-rw-r--r--src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr26
-rw-r--r--src/tools/clippy/tests/ui/same_item_push.stderr2
-rw-r--r--src/tools/clippy/tests/ui/same_name_method.stderr2
-rw-r--r--src/tools/clippy/tests/ui/search_is_some.stderr2
-rw-r--r--src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs2
-rw-r--r--src/tools/clippy/tests/ui/shadow.stderr6
-rw-r--r--src/tools/clippy/tests/ui/should_impl_trait/method_list_1.stderr14
-rw-r--r--src/tools/clippy/tests/ui/should_impl_trait/method_list_2.stderr2
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs7
-rw-r--r--src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr54
-rw-r--r--src/tools/clippy/tests/ui/similar_names.stderr2
-rw-r--r--src/tools/clippy/tests/ui/single_char_lifetime_names.stderr2
-rw-r--r--src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr2
-rw-r--r--src/tools/clippy/tests/ui/single_match.rs1
-rw-r--r--src/tools/clippy/tests/ui/single_match.stderr32
-rw-r--r--src/tools/clippy/tests/ui/single_match_else.rs4
-rw-r--r--src/tools/clippy/tests/ui/single_match_else.stderr10
-rw-r--r--src/tools/clippy/tests/ui/size_of_in_element_count/expressions.stderr2
-rw-r--r--src/tools/clippy/tests/ui/size_of_in_element_count/functions.stderr2
-rw-r--r--src/tools/clippy/tests/ui/skip_while_next.stderr2
-rw-r--r--src/tools/clippy/tests/ui/stable_sort_primitive.stderr2
-rw-r--r--src/tools/clippy/tests/ui/std_instead_of_core.rs6
-rw-r--r--src/tools/clippy/tests/ui/std_instead_of_core.stderr22
-rw-r--r--src/tools/clippy/tests/ui/str_to_string.stderr2
-rw-r--r--src/tools/clippy/tests/ui/string_to_string.stderr2
-rw-r--r--src/tools/clippy/tests/ui/struct_excessive_bools.stderr2
-rw-r--r--src/tools/clippy/tests/ui/suspicious_else_formatting.stderr2
-rw-r--r--src/tools/clippy/tests/ui/suspicious_map.stderr2
-rw-r--r--src/tools/clippy/tests/ui/suspicious_splitn.stderr2
-rw-r--r--src/tools/clippy/tests/ui/suspicious_to_owned.stderr8
-rw-r--r--src/tools/clippy/tests/ui/suspicious_unary_op_formatting.stderr2
-rw-r--r--src/tools/clippy/tests/ui/swap.stderr4
-rw-r--r--src/tools/clippy/tests/ui/toplevel_ref_arg.fixed2
-rw-r--r--src/tools/clippy/tests/ui/toplevel_ref_arg.rs2
-rw-r--r--src/tools/clippy/tests/ui/trailing_empty_array.stderr2
-rw-r--r--src/tools/clippy/tests/ui/trait_duplication_in_bounds_unfixable.stderr2
-rw-r--r--src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr4
-rw-r--r--src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed2
-rw-r--r--src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs2
-rw-r--r--src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs7
-rw-r--r--src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr38
-rw-r--r--src/tools/clippy/tests/ui/type_repetition_in_bounds.stderr2
-rw-r--r--src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr2
-rw-r--r--src/tools/clippy/tests/ui/undropped_manually_drops.stderr2
-rw-r--r--src/tools/clippy/tests/ui/uninit_vec.rs6
-rw-r--r--src/tools/clippy/tests/ui/uninit_vec.stderr2
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args.fixed182
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args.rs182
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args.stderr879
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed29
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.stderr15
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed29
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.stderr51
-rw-r--r--src/tools/clippy/tests/ui/uninlined_format_args_panic.rs29
-rw-r--r--src/tools/clippy/tests/ui/unit_arg.rs15
-rw-r--r--src/tools/clippy/tests/ui/unit_arg.stderr20
-rw-r--r--src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed3
-rw-r--r--src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs3
-rw-r--r--src/tools/clippy/tests/ui/unit_arg_empty_blocks.stderr8
-rw-r--r--src/tools/clippy/tests/ui/unit_hash.stderr2
-rw-r--r--src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.fixed18
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.rs18
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_cast.stderr20
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_clone.rs4
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_join.fixed2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_join.rs2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed21
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs21
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr68
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_self_imports.stderr2
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.fixed11
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.rs11
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.stderr2
-rw-r--r--src/tools/clippy/tests/ui/unneeded_field_pattern.stderr2
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns.fixed16
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns.rs16
-rw-r--r--src/tools/clippy/tests/ui/unnested_or_patterns.stderr13
-rw-r--r--src/tools/clippy/tests/ui/unsafe_derive_deserialize.stderr2
-rw-r--r--src/tools/clippy/tests/ui/unsafe_removed_from_name.rs3
-rw-r--r--src/tools/clippy/tests/ui/unused_async.stderr2
-rw-r--r--src/tools/clippy/tests/ui/unused_format_specs.fixed18
-rw-r--r--src/tools/clippy/tests/ui/unused_format_specs.rs18
-rw-r--r--src/tools/clippy/tests/ui/unused_format_specs.stderr54
-rw-r--r--src/tools/clippy/tests/ui/unused_format_specs_unfixable.rs30
-rw-r--r--src/tools/clippy/tests/ui/unused_format_specs_unfixable.stderr69
-rw-r--r--src/tools/clippy/tests/ui/unused_io_amount.stderr2
-rw-r--r--src/tools/clippy/tests/ui/unused_peekable.rs33
-rw-r--r--src/tools/clippy/tests/ui/unused_peekable.stderr2
-rw-r--r--src/tools/clippy/tests/ui/unused_self.stderr2
-rw-r--r--src/tools/clippy/tests/ui/unwrap.stderr2
-rw-r--r--src/tools/clippy/tests/ui/unwrap_expect_used.stderr4
-rw-r--r--src/tools/clippy/tests/ui/unwrap_in_result.stderr2
-rw-r--r--src/tools/clippy/tests/ui/upper_case_acronyms.rs9
-rw-r--r--src/tools/clippy/tests/ui/upper_case_acronyms.stderr14
-rw-r--r--src/tools/clippy/tests/ui/use_self.fixed42
-rw-r--r--src/tools/clippy/tests/ui/use_self.rs42
-rw-r--r--src/tools/clippy/tests/ui/use_self.stderr90
-rw-r--r--src/tools/clippy/tests/ui/used_underscore_binding.rs3
-rw-r--r--src/tools/clippy/tests/ui/used_underscore_binding.stderr12
-rw-r--r--src/tools/clippy/tests/ui/useless_asref.fixed3
-rw-r--r--src/tools/clippy/tests/ui/useless_asref.rs3
-rw-r--r--src/tools/clippy/tests/ui/useless_asref.stderr24
-rw-r--r--src/tools/clippy/tests/ui/useless_conversion.stderr2
-rw-r--r--src/tools/clippy/tests/ui/useless_conversion_try.stderr2
-rw-r--r--src/tools/clippy/tests/ui/vec.fixed2
-rw-r--r--src/tools/clippy/tests/ui/vec.rs2
-rw-r--r--src/tools/clippy/tests/ui/vec_resize_to_zero.stderr2
-rw-r--r--src/tools/clippy/tests/ui/verbose_file_reads.stderr2
-rw-r--r--src/tools/clippy/tests/ui/vtable_address_comparisons.stderr2
-rw-r--r--src/tools/clippy/tests/ui/while_let_loop.rs1
-rw-r--r--src/tools/clippy/tests/ui/while_let_loop.stderr10
-rw-r--r--src/tools/clippy/tests/ui/while_let_on_iterator.fixed10
-rw-r--r--src/tools/clippy/tests/ui/while_let_on_iterator.rs10
-rw-r--r--src/tools/clippy/tests/ui/while_let_on_iterator.stderr52
-rw-r--r--src/tools/clippy/tests/ui/wild_in_or_pats.stderr2
-rw-r--r--src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed10
-rw-r--r--src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs10
-rw-r--r--src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr14
-rw-r--r--src/tools/clippy/tests/ui/write_literal.rs4
-rw-r--r--src/tools/clippy/tests/ui/write_literal.stderr56
-rw-r--r--src/tools/clippy/tests/ui/write_literal_2.rs9
-rw-r--r--src/tools/clippy/tests/ui/write_literal_2.stderr80
-rw-r--r--src/tools/clippy/tests/ui/write_with_newline.rs8
-rw-r--r--src/tools/clippy/tests/ui/write_with_newline.stderr38
-rw-r--r--src/tools/clippy/tests/ui/writeln_empty_string.stderr12
-rw-r--r--src/tools/clippy/tests/ui/wrong_self_convention.stderr2
-rw-r--r--src/tools/clippy/tests/ui/wrong_self_convention2.stderr2
-rw-r--r--src/tools/clippy/tests/ui/wrong_self_conventions_mut.stderr2
-rw-r--r--src/tools/clippy/tests/ui/zero_div_zero.stderr2
-rw-r--r--src/tools/clippy/tests/ui/zero_sized_btreemap_values.stderr2
-rw-r--r--src/tools/clippy/tests/ui/zero_sized_hashmap_values.stderr2
-rw-r--r--src/tools/clippy/tests/versioncheck.rs8
-rw-r--r--src/tools/compiletest/src/common.rs28
-rw-r--r--src/tools/compiletest/src/header.rs20
-rw-r--r--src/tools/compiletest/src/main.rs29
-rw-r--r--src/tools/compiletest/src/runtest.rs35
-rw-r--r--src/tools/compiletest/src/util.rs6
-rw-r--r--src/tools/error_index_generator/error-index.css3
-rw-r--r--src/tools/jsondoclint/src/item_kind.rs3
-rw-r--r--src/tools/jsondoclint/src/validator.rs10
-rw-r--r--src/tools/linkchecker/main.rs1
-rwxr-xr-xsrc/tools/publish_toolstate.py17
-rw-r--r--src/tools/rust-analyzer/Cargo.lock205
-rw-r--r--src/tools/rust-analyzer/Cargo.toml1
-rw-r--r--src/tools/rust-analyzer/crates/base-db/src/fixture.rs8
-rw-r--r--src/tools/rust-analyzer/crates/base-db/src/input.rs22
-rw-r--r--src/tools/rust-analyzer/crates/cfg/Cargo.toml4
-rw-r--r--src/tools/rust-analyzer/crates/flycheck/Cargo.toml5
-rw-r--r--src/tools/rust-analyzer/crates/flycheck/src/lib.rs103
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/Cargo.toml8
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/adt.rs244
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/body.rs26
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs42
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs19
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/builtin_attr.rs2
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/child_by_source.rs4
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/data.rs8
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/db.rs15
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/expr.rs13
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/find_path.rs362
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs23
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs8
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs9
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/item_tree/pretty.rs6
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/lib.rs10
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs36
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs24
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs3
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/nameres/diagnostics.rs6
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/resolver.rs1
-rw-r--r--src/tools/rust-analyzer/crates/hir-expand/Cargo.toml4
-rw-r--r--src/tools/rust-analyzer/crates/hir-expand/src/ast_id_map.rs7
-rw-r--r--src/tools/rust-analyzer/crates/hir-expand/src/builtin_derive_macro.rs86
-rw-r--r--src/tools/rust-analyzer/crates/hir-expand/src/builtin_fn_macro.rs14
-rw-r--r--src/tools/rust-analyzer/crates/hir-expand/src/db.rs12
-rw-r--r--src/tools/rust-analyzer/crates/hir-expand/src/lib.rs25
-rw-r--r--src/tools/rust-analyzer/crates/hir-expand/src/name.rs1
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/Cargo.toml15
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs7
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/builder.rs217
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs75
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/chalk_ext.rs11
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs108
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests.rs43
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/db.rs27
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/unsafe_check.rs4
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/display.rs64
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/infer.rs44
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/infer/closure.rs6
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs2
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs114
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs24
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs78
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/lib.rs102
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/lower.rs235
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs12
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs110
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/tests.rs22
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/tests/coercion.rs18
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/tests/display_source_code.rs22
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs34
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/tests/patterns.rs10
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs54
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs159
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs12
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/traits.rs19
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/utils.rs101
-rw-r--r--src/tools/rust-analyzer/crates/hir/Cargo.toml6
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/diagnostics.rs2
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/display.rs3
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/from_id.rs10
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/lib.rs158
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/semantics.rs15
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs8
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs46
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/symbols.rs4
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/Cargo.toml2
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/assist_config.rs1
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs17
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/auto_import.rs23
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_into_to_from.rs2
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs822
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_function.rs1
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs35
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_constant.rs12
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs5
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_new.rs61
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_methods.rs8
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs18
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_documentation_template.rs52
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_is_method.rs18
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_projection_method.rs39
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs19
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs141
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_getter.rs325
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs15
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_new.rs23
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_setter.rs21
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_format_string_arg.rs296
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_method_call.rs7
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_path.rs3
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs2
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs1
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/handlers/unwrap_tuple.rs159
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/lib.rs6
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/tests.rs14
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/tests/generated.rs91
-rw-r--r--src/tools/rust-analyzer/crates/ide-assists/src/utils.rs88
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/Cargo.toml6
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/completions.rs7
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/completions/env_vars.rs150
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs12
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/completions/flyimport.rs14
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs51
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/completions/pattern.rs1
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix/format_like.rs247
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/config.rs1
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/context.rs45
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/context/analysis.rs1939
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/lib.rs8
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/snippet.rs8
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/tests.rs1
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/tests/pattern.rs27
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/Cargo.toml5
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs13
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/imports/merge_imports.rs2
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/lib.rs1
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs3
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/search.rs46
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string.rs6
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string_exprs.rs267
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs9
-rw-r--r--src/tools/rust-analyzer/crates/ide-diagnostics/Cargo.toml6
-rw-r--r--src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/inactive_code.rs31
-rw-r--r--src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs2
-rw-r--r--src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_fields.rs1
-rw-r--r--src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs33
-rw-r--r--src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs2
-rw-r--r--src/tools/rust-analyzer/crates/ide-ssr/Cargo.toml3
-rw-r--r--src/tools/rust-analyzer/crates/ide-ssr/src/matching.rs7
-rw-r--r--src/tools/rust-analyzer/crates/ide/Cargo.toml6
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/annotations.rs307
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/annotations/fn_references.rs (renamed from src/tools/rust-analyzer/crates/ide/src/fn_references.rs)37
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/doc_links.rs9
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/goto_definition.rs63
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/highlight_related.rs27
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/hover/render.rs11
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/hover/tests.rs136
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs83
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/lib.rs24
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/moniker.rs10
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/parent_module.rs18
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/references.rs20
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/static_index.rs4
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/status.rs2
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/highlight.rs11
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html6
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html2
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_general.html12
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html2
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_lifetimes.html4
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html8
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html8
-rw-r--r--src/tools/rust-analyzer/crates/mbe/Cargo.toml2
-rw-r--r--src/tools/rust-analyzer/crates/mbe/src/benchmark.rs30
-rw-r--r--src/tools/rust-analyzer/crates/mbe/src/expander.rs3
-rw-r--r--src/tools/rust-analyzer/crates/mbe/src/expander/matcher.rs91
-rw-r--r--src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs57
-rw-r--r--src/tools/rust-analyzer/crates/mbe/src/lib.rs6
-rw-r--r--src/tools/rust-analyzer/crates/mbe/src/parser.rs41
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml2
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_sysroot/mod.rs2
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/mod.rs11
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs9
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs11
-rw-r--r--src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs12
-rw-r--r--src/tools/rust-analyzer/crates/profile/Cargo.toml4
-rw-r--r--src/tools/rust-analyzer/crates/project-model/Cargo.toml10
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/build_scripts.rs374
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs184
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/lib.rs22
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/project_json.rs3
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/rustc_cfg.rs17
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/sysroot.rs74
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/tests.rs66
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/workspace.rs197
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml13
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/bin/logger.rs2
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs11
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/cargo_target_spec.rs84
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs10
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/cli/flags.rs31
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/cli/load_cargo.rs28
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/cli/lsif.rs3
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs110
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs211
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/dispatch.rs4
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/from_proto.rs10
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs53
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/handlers.rs33
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/integrated_benchmarks.rs2
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/lsp_utils.rs10
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs188
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs143
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/src/to_proto.rs19
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs12
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs2
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs1
-rw-r--r--src/tools/rust-analyzer/crates/sourcegen/Cargo.toml3
-rw-r--r--src/tools/rust-analyzer/crates/stdx/Cargo.toml2
-rw-r--r--src/tools/rust-analyzer/crates/syntax/Cargo.toml8
-rw-r--r--src/tools/rust-analyzer/crates/syntax/src/ast/edit_in_place.rs61
-rw-r--r--src/tools/rust-analyzer/crates/syntax/src/ast/make.rs23
-rw-r--r--src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs30
-rw-r--r--src/tools/rust-analyzer/crates/syntax/src/lib.rs2
-rw-r--r--src/tools/rust-analyzer/crates/test-utils/src/fixture.rs53
-rw-r--r--src/tools/rust-analyzer/crates/test-utils/src/minicore.rs94
-rw-r--r--src/tools/rust-analyzer/crates/text-edit/Cargo.toml2
-rw-r--r--src/tools/rust-analyzer/crates/toolchain/Cargo.toml2
-rw-r--r--src/tools/rust-analyzer/crates/vfs-notify/Cargo.toml2
-rw-r--r--src/tools/rust-analyzer/docs/dev/README.md2
-rw-r--r--src/tools/rust-analyzer/docs/dev/guide.md9
-rw-r--r--src/tools/rust-analyzer/docs/dev/syntax.md6
-rw-r--r--src/tools/rust-analyzer/docs/user/generated_config.adoc74
-rw-r--r--src/tools/rust-analyzer/docs/user/manual.adoc17
-rw-r--r--src/tools/rust-analyzer/lib/lsp-server/Cargo.toml10
-rw-r--r--src/tools/rust-analyzer/lib/lsp-server/src/msg.rs10
-rw-r--r--src/tools/rust-analyzer/lib/lsp-server/src/req_queue.rs7
-rw-r--r--src/tools/rust-analyzer/xtask/Cargo.toml4
-rw-r--r--src/tools/rust-analyzer/xtask/src/flags.rs19
-rw-r--r--src/tools/rust-analyzer/xtask/src/main.rs7
-rw-r--r--src/tools/rustdoc/main.rs3
-rw-r--r--src/tools/rustfmt/src/chains.rs10
-rw-r--r--src/tools/rustfmt/src/config/config_type.rs2
-rw-r--r--src/tools/rustfmt/src/items.rs12
-rw-r--r--src/tools/rustfmt/src/visitor.rs2
-rw-r--r--src/tools/tidy/src/alphabetical.rs111
-rw-r--r--src/tools/tidy/src/bins.rs5
-rw-r--r--src/tools/tidy/src/debug_artifacts.rs3
-rw-r--r--src/tools/tidy/src/deps.rs45
-rw-r--r--src/tools/tidy/src/edition.rs5
-rw-r--r--src/tools/tidy/src/error_codes_check.rs3
-rw-r--r--src/tools/tidy/src/errors.rs5
-rw-r--r--src/tools/tidy/src/features.rs276
-rw-r--r--src/tools/tidy/src/lib.rs3
-rw-r--r--src/tools/tidy/src/main.rs4
-rw-r--r--src/tools/tidy/src/pal.rs3
-rw-r--r--src/tools/tidy/src/style.rs5
-rw-r--r--src/tools/tidy/src/target_specific_tests.rs2
-rw-r--r--src/tools/tidy/src/ui_tests.rs6
-rw-r--r--src/tools/tidy/src/unit_tests.rs5
-rw-r--r--src/tools/tidy/src/walk.rs6
-rw-r--r--src/version2
3981 files changed, 67015 insertions, 36799 deletions
diff --git a/src/README.md b/src/README.md
index 3d2e6acd5..90ab80269 100644
--- a/src/README.md
+++ b/src/README.md
@@ -2,7 +2,7 @@ This directory contains the source code of the rust project, including:
- The test suite
- The bootstrapping build system
-- Various submodules for tools, like cargo, miri, etc.
+- Various submodules for tools, like cargo, etc.
For more information on how various parts of the compiler work, see the [rustc dev guide].
diff --git a/src/bootstrap/CHANGELOG.md b/src/bootstrap/CHANGELOG.md
index 85afc1f5f..64b74ecc9 100644
--- a/src/bootstrap/CHANGELOG.md
+++ b/src/bootstrap/CHANGELOG.md
@@ -13,6 +13,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Change the names for `dist` commands to match the component they generate. [#90684](https://github.com/rust-lang/rust/pull/90684)
- The `build.fast-submodules` option has been removed. Fast submodule checkouts are enabled unconditionally. Automatic submodule handling can still be disabled with `build.submodules = false`.
- Several unsupported `./configure` options have been removed: `optimize`, `parallel-compiler`. These can still be enabled with `--set`, although it isn't recommended.
+- `remote-test-server`'s `verbose` argument has been removed in favor of the `--verbose` flag
+- `remote-test-server`'s `remote` argument has been removed in favor of the `--bind` flag. Use `--bind 0.0.0.0:12345` to replicate the behavior of the `remote` argument.
### Non-breaking changes
diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock
index 84c06fdce..baecca44c 100644
--- a/src/bootstrap/Cargo.lock
+++ b/src/bootstrap/Cargo.lock
@@ -445,9 +445,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
-version = "1.0.39"
+version = "1.0.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
+checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b"
dependencies = [
"unicode-ident",
]
@@ -596,9 +596,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "1.0.95"
+version = "1.0.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942"
+checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1"
dependencies = [
"proc-macro2",
"quote",
diff --git a/src/bootstrap/README.md b/src/bootstrap/README.md
index a2e596bf4..985727bdd 100644
--- a/src/bootstrap/README.md
+++ b/src/bootstrap/README.md
@@ -1,7 +1,7 @@
# rustbuild - Bootstrapping Rust
This is an in-progress README which is targeted at helping to explain how Rust
-is bootstrapped and in general some of the technical details of the build
+is bootstrapped and in general, some of the technical details of the build
system.
## Using rustbuild
@@ -12,7 +12,7 @@ The rustbuild build system has a primary entry point, a top level `x.py` script:
$ python ./x.py build
```
-Note that if you're on Unix you should be able to execute the script directly:
+Note that if you're on Unix, you should be able to execute the script directly:
```sh
$ ./x.py build
@@ -20,8 +20,8 @@ $ ./x.py build
The script accepts commands, flags, and arguments to determine what to do:
-* `build` - a general purpose command for compiling code. Alone `build` will
- bootstrap the entire compiler, and otherwise arguments passed indicate what to
+* `build` - a general purpose command for compiling code. Alone, `build` will
+ bootstrap the entire compiler, and otherwise, arguments passed indicate what to
build. For example:
```
@@ -38,7 +38,7 @@ The script accepts commands, flags, and arguments to determine what to do:
./x.py build --stage 0 library/test
```
- If files are dirty that would normally be rebuilt from stage 0, that can be
+ If files that would normally be rebuilt from stage 0 are dirty, the rebuild can be
overridden using `--keep-stage 0`. Using `--keep-stage n` will skip all steps
that belong to stage n or earlier:
@@ -47,8 +47,8 @@ The script accepts commands, flags, and arguments to determine what to do:
./x.py build --keep-stage 0
```
-* `test` - a command for executing unit tests. Like the `build` command this
- will execute the entire test suite by default, and otherwise it can be used to
+* `test` - a command for executing unit tests. Like the `build` command, this
+ will execute the entire test suite by default, and otherwise, it can be used to
select which test suite is run:
```
@@ -75,7 +75,7 @@ The script accepts commands, flags, and arguments to determine what to do:
./x.py test src/doc
```
-* `doc` - a command for building documentation. Like above can take arguments
+* `doc` - a command for building documentation. Like above, can take arguments
for what to document.
## Configuring rustbuild
@@ -110,12 +110,12 @@ compiler. What actually happens when you invoke rustbuild is:
compiles the build system itself (this folder). Finally, it then invokes the
actual `bootstrap` binary build system.
2. In Rust, `bootstrap` will slurp up all configuration, perform a number of
- sanity checks (compilers exist for example), and then start building the
+ sanity checks (whether compilers exist, for example), and then start building the
stage0 artifacts.
-3. The stage0 `cargo` downloaded earlier is used to build the standard library
+3. The stage0 `cargo`, downloaded earlier, is used to build the standard library
and the compiler, and then these binaries are then copied to the `stage1`
directory. That compiler is then used to generate the stage1 artifacts which
- are then copied to the stage2 directory, and then finally the stage2
+ are then copied to the stage2 directory, and then finally, the stage2
artifacts are generated using that compiler.
The goal of each stage is to (a) leverage Cargo as much as possible and failing
@@ -149,7 +149,7 @@ like this:
build/
# Location where the stage0 compiler downloads are all cached. This directory
- # only contains the tarballs themselves as they're extracted elsewhere.
+ # only contains the tarballs themselves, as they're extracted elsewhere.
cache/
2015-12-19/
2016-01-15/
@@ -172,10 +172,10 @@ build/
# hand.
x86_64-unknown-linux-gnu/
- # The build artifacts for the `compiler-rt` library for the target this
- # folder is under. The exact layout here will likely depend on the platform,
- # and this is also built with CMake so the build system is also likely
- # different.
+ # The build artifacts for the `compiler-rt` library for the target that
+ # this folder is under. The exact layout here will likely depend on the
+ # platform, and this is also built with CMake, so the build system is
+ # also likely different.
compiler-rt/
build/
@@ -183,11 +183,11 @@ build/
llvm/
# build folder (e.g. the platform-specific build system). Like with
- # compiler-rt this is compiled with CMake
+ # compiler-rt, this is compiled with CMake
build/
# Installation of LLVM. Note that we run the equivalent of 'make install'
- # for LLVM to setup these folders.
+ # for LLVM, to setup these folders.
bin/
lib/
include/
@@ -206,18 +206,18 @@ build/
# Location where the stage0 Cargo and Rust compiler are unpacked. This
# directory is purely an extracted and overlaid tarball of these two (done
- # by the bootstrapy python script). In theory the build system does not
+ # by the bootstrap python script). In theory, the build system does not
# modify anything under this directory afterwards.
stage0/
- # These to build directories are the cargo output directories for builds of
- # the standard library and compiler, respectively. Internally these may also
+ # These to-build directories are the cargo output directories for builds of
+ # the standard library and compiler, respectively. Internally, these may also
# have other target directories, which represent artifacts being compiled
# from the host to the specified target.
#
# Essentially, each of these directories is filled in by one `cargo`
# invocation. The build system instruments calling Cargo in the right order
- # with the right variables to ensure these are filled in correctly.
+ # with the right variables to ensure that these are filled in correctly.
stageN-std/
stageN-test/
stageN-rustc/
@@ -232,8 +232,8 @@ build/
# being compiled (e.g. after libstd has been built), *this* is used as the
# sysroot for the stage0 compiler being run.
#
- # Basically this directory is just a temporary artifact use to configure the
- # stage0 compiler to ensure that the libstd we just built is used to
+ # Basically, this directory is just a temporary artifact used to configure the
+ # stage0 compiler to ensure that the libstd that we just built is used to
# compile the stage1 compiler.
stage0-sysroot/lib/
@@ -242,7 +242,7 @@ build/
# system will link (using hard links) output from stageN-{std,rustc} into
# each of these directories.
#
- # In theory there is no extra build output in these directories.
+ # In theory, there is no extra build output in these directories.
stage1/
stage2/
stage3/
@@ -265,14 +265,14 @@ structure here serves two goals:
depend on `std`, so libstd is a separate project compiled ahead of time
before the actual compiler builds.
2. Splitting "host artifacts" from "target artifacts". That is, when building
- code for an arbitrary target you don't need the entire compiler, but you'll
+ code for an arbitrary target, you don't need the entire compiler, but you'll
end up needing libraries like libtest that depend on std but also want to use
crates.io dependencies. Hence, libtest is split out as its own project that
is sequenced after `std` but before `rustc`. This project is built for all
targets.
There is some loss in build parallelism here because libtest can be compiled in
-parallel with a number of rustc artifacts, but in theory the loss isn't too bad!
+parallel with a number of rustc artifacts, but in theory, the loss isn't too bad!
## Build tools
@@ -285,13 +285,13 @@ appropriate libstd/libtest/librustc compile above.
## Extending rustbuild
-So you'd like to add a feature to the rustbuild build system or just fix a bug.
+So, you'd like to add a feature to the rustbuild build system or just fix a bug.
Great! One of the major motivational factors for moving away from `make` is that
Rust is in theory much easier to read, modify, and write. If you find anything
-excessively confusing, please open an issue on this and we'll try to get it
-documented or simplified pronto.
+excessively confusing, please open an issue on this, and we'll try to get it
+documented or simplified, pronto.
-First up, you'll probably want to read over the documentation above as that'll
+First up, you'll probably want to read over the documentation above, as that'll
give you a high level overview of what rustbuild is doing. You also probably
want to play around a bit yourself by just getting it up and running before you
dive too much into the actual build system itself.
@@ -326,7 +326,7 @@ A 'major change' includes
Changes that do not affect contributors to the compiler or users
building rustc from source don't need an update to `VERSION`.
-If you have any questions feel free to reach out on the `#t-infra` channel in
+If you have any questions, feel free to reach out on the `#t-infra` channel in
the [Rust Zulip server][rust-zulip] or ask on internals.rust-lang.org. When
you encounter bugs, please file issues on the rust-lang/rust issue tracker.
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
index e96f8b0d3..776d73b98 100644
--- a/src/bootstrap/bin/rustc.rs
+++ b/src/bootstrap/bin/rustc.rs
@@ -67,7 +67,7 @@ fn main() {
if target == "all"
|| target.into_string().unwrap().split(',').any(|c| c.trim() == crate_name)
{
- cmd.arg("-Ztime");
+ cmd.arg("-Ztime-passes");
}
}
}
diff --git a/src/bootstrap/bolt.rs b/src/bootstrap/bolt.rs
new file mode 100644
index 000000000..ea37cd470
--- /dev/null
+++ b/src/bootstrap/bolt.rs
@@ -0,0 +1,71 @@
+use std::path::Path;
+use std::process::Command;
+
+/// Uses the `llvm-bolt` binary to instrument the binary/library at the given `path` with BOLT.
+/// When the instrumented artifact is executed, it will generate BOLT profiles into
+/// `/tmp/prof.fdata.<pid>.fdata`.
+pub fn instrument_with_bolt_inplace(path: &Path) {
+ let dir = std::env::temp_dir();
+ let instrumented_path = dir.join("instrumented.so");
+
+ let status = Command::new("llvm-bolt")
+ .arg("-instrument")
+ .arg(&path)
+ // Make sure that each process will write its profiles into a separate file
+ .arg("--instrumentation-file-append-pid")
+ .arg("-o")
+ .arg(&instrumented_path)
+ .status()
+ .expect("Could not instrument artifact using BOLT");
+
+ if !status.success() {
+ panic!("Could not instrument {} with BOLT, exit code {:?}", path.display(), status.code());
+ }
+
+ std::fs::copy(&instrumented_path, path).expect("Cannot copy instrumented artifact");
+ std::fs::remove_file(instrumented_path).expect("Cannot delete instrumented artifact");
+}
+
+/// Uses the `llvm-bolt` binary to optimize the binary/library at the given `path` with BOLT,
+/// using merged profiles from `profile_path`.
+///
+/// The recorded profiles have to be merged using the `merge-fdata` tool from LLVM and the merged
+/// profile path should be then passed to this function.
+pub fn optimize_library_with_bolt_inplace(path: &Path, profile_path: &Path) {
+ let dir = std::env::temp_dir();
+ let optimized_path = dir.join("optimized.so");
+
+ let status = Command::new("llvm-bolt")
+ .arg(&path)
+ .arg("-data")
+ .arg(&profile_path)
+ .arg("-o")
+ .arg(&optimized_path)
+ // Reorder basic blocks within functions
+ .arg("-reorder-blocks=ext-tsp")
+ // Reorder functions within the binary
+ .arg("-reorder-functions=hfsort+")
+ // Split function code into hot and code regions
+ .arg("-split-functions=2")
+ // Split as many basic blocks as possible
+ .arg("-split-all-cold")
+ // Move jump tables to a separate section
+ .arg("-jump-tables=move")
+ // Use GNU_STACK program header for new segment (workaround for issues with strip/objcopy)
+ .arg("-use-gnu-stack")
+ // Fold functions with identical code
+ .arg("-icf=1")
+ // Update DWARF debug info in the final binary
+ .arg("-update-debug-sections")
+ // Print optimization statistics
+ .arg("-dyno-stats")
+ .status()
+ .expect("Could not optimize artifact using BOLT");
+
+ if !status.success() {
+ panic!("Could not optimize {} with BOLT, exit code {:?}", path.display(), status.code());
+ }
+
+ std::fs::copy(&optimized_path, path).expect("Cannot copy optimized artifact");
+ std::fs::remove_file(optimized_path).expect("Cannot delete optimized artifact");
+}
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index cc08ae5f9..57128685d 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -732,9 +732,19 @@ class RustBuild(object):
(os.pathsep + env["LIBRARY_PATH"]) \
if "LIBRARY_PATH" in env else ""
+ # Export Stage0 snapshot compiler related env variables
+ build_section = "target.{}".format(self.build)
+ host_triple_sanitized = self.build.replace("-", "_")
+ var_data = {
+ "CC": "cc", "CXX": "cxx", "LD": "linker", "AR": "ar", "RANLIB": "ranlib"
+ }
+ for var_name, toml_key in var_data.items():
+ toml_val = self.get_toml(toml_key, build_section)
+ if toml_val != None:
+ env["{}_{}".format(var_name, host_triple_sanitized)] = toml_val
+
# preserve existing RUSTFLAGS
env.setdefault("RUSTFLAGS", "")
- build_section = "target.{}".format(self.build)
target_features = []
if self.get_toml("crt-static", build_section) == "true":
target_features += ["+crt-static"]
@@ -742,9 +752,6 @@ class RustBuild(object):
target_features += ["-crt-static"]
if target_features:
env["RUSTFLAGS"] += " -C target-feature=" + (",".join(target_features))
- target_linker = self.get_toml("linker", build_section)
- if target_linker is not None:
- env["RUSTFLAGS"] += " -C linker=" + target_linker
env["RUSTFLAGS"] += " -Wrust_2018_idioms -Wunused_lifetimes"
env["RUSTFLAGS"] += " -Wsemicolon_in_expressions_from_macros"
if self.get_toml("deny-warnings", "rust") != "false":
@@ -771,7 +778,8 @@ class RustBuild(object):
elif color == "never":
args.append("--color=never")
- run(args, env=env, verbose=self.verbose)
+ # Run this from the source directory so cargo finds .cargo/config
+ run(args, env=env, verbose=self.verbose, cwd=self.rust_root)
def build_triple(self):
"""Build triple as in LLVM
diff --git a/src/bootstrap/build.rs b/src/bootstrap/build.rs
index ab34d5c1e..cd1f41802 100644
--- a/src/bootstrap/build.rs
+++ b/src/bootstrap/build.rs
@@ -1,43 +1,7 @@
-use env::consts::{EXE_EXTENSION, EXE_SUFFIX};
use std::env;
-use std::ffi::OsString;
-use std::path::PathBuf;
-
-/// Given an executable called `name`, return the filename for the
-/// executable for a particular target.
-pub fn exe(name: &PathBuf) -> PathBuf {
- if EXE_EXTENSION != "" && name.extension() != Some(EXE_EXTENSION.as_ref()) {
- let mut name: OsString = name.clone().into();
- name.push(EXE_SUFFIX);
- name.into()
- } else {
- name.clone()
- }
-}
fn main() {
let host = env::var("HOST").unwrap();
println!("cargo:rerun-if-changed=build.rs");
- println!("cargo:rerun-if-env-changed=RUSTC");
println!("cargo:rustc-env=BUILD_TRIPLE={}", host);
-
- // This may not be a canonicalized path.
- let mut rustc = PathBuf::from(env::var_os("RUSTC").unwrap());
-
- if rustc.is_relative() {
- println!("cargo:rerun-if-env-changed=PATH");
- for dir in env::split_paths(&env::var_os("PATH").unwrap_or_default()) {
- let absolute = dir.join(&exe(&rustc));
- if absolute.exists() {
- rustc = absolute;
- break;
- }
- }
- }
- assert!(rustc.is_absolute());
-
- // FIXME: if the path is not utf-8, this is going to break. Unfortunately
- // Cargo doesn't have a way for us to specify non-utf-8 paths easily, so
- // we'll need to invent some encoding scheme if this becomes a problem.
- println!("cargo:rustc-env=RUSTC={}", rustc.to_str().unwrap());
}
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 14e8ebd68..8b144f146 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -704,10 +704,12 @@ impl<'a> Builder<'a> {
doc::Miri,
doc::EmbeddedBook,
doc::EditionGuide,
+ doc::StyleGuide,
),
Kind::Dist => describe!(
dist::Docs,
dist::RustcDocs,
+ dist::JsonDocs,
dist::Mingw,
dist::Rustc,
dist::Std,
@@ -723,6 +725,7 @@ impl<'a> Builder<'a> {
dist::Miri,
dist::LlvmTools,
dist::RustDev,
+ dist::Bootstrap,
dist::Extended,
// It seems that PlainSourceTarball somehow changes how some of the tools
// perceive their dependencies (see #93033) which would invalidate fingerprints
@@ -1325,6 +1328,9 @@ impl<'a> Builder<'a> {
) -> Cargo {
let mut cargo = Command::new(&self.initial_cargo);
let out_dir = self.stage_out(compiler, mode);
+ // Run cargo from the source root so it can find .cargo/config.
+ // This matters when using vendoring and the working directory is outside the repository.
+ cargo.current_dir(&self.src);
// Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
// so we need to explicitly clear out if they've been updated.
@@ -1552,13 +1558,12 @@ impl<'a> Builder<'a> {
match mode {
Mode::ToolBootstrap => {
// Restrict the allowed features to those passed by rustbuild, so we don't depend on nightly accidentally.
- // HACK: because anyhow does feature detection in build.rs, we need to allow the backtrace feature too.
- rustflags.arg("-Zallow-features=binary-dep-depinfo,backtrace");
+ rustflags.arg("-Zallow-features=binary-dep-depinfo");
}
Mode::ToolStd => {
// Right now this is just compiletest and a few other tools that build on stable.
// Allow them to use `feature(test)`, but nothing else.
- rustflags.arg("-Zallow-features=binary-dep-depinfo,test,backtrace,proc_macro_internals,proc_macro_diagnostic,proc_macro_span");
+ rustflags.arg("-Zallow-features=binary-dep-depinfo,test,proc_macro_internals,proc_macro_diagnostic,proc_macro_span");
}
Mode::Std | Mode::Rustc | Mode::Codegen | Mode::ToolRustc => {}
}
@@ -1940,25 +1945,26 @@ impl<'a> Builder<'a> {
_ => s.display().to_string(),
}
};
+ let triple_underscored = target.triple.replace("-", "_");
let cc = ccacheify(&self.cc(target));
- cargo.env(format!("CC_{}", target.triple), &cc);
+ cargo.env(format!("CC_{}", triple_underscored), &cc);
let cflags = self.cflags(target, GitRepo::Rustc, CLang::C).join(" ");
- cargo.env(format!("CFLAGS_{}", target.triple), &cflags);
+ cargo.env(format!("CFLAGS_{}", triple_underscored), &cflags);
if let Some(ar) = self.ar(target) {
let ranlib = format!("{} s", ar.display());
cargo
- .env(format!("AR_{}", target.triple), ar)
- .env(format!("RANLIB_{}", target.triple), ranlib);
+ .env(format!("AR_{}", triple_underscored), ar)
+ .env(format!("RANLIB_{}", triple_underscored), ranlib);
}
if let Ok(cxx) = self.cxx(target) {
let cxx = ccacheify(&cxx);
let cxxflags = self.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" ");
cargo
- .env(format!("CXX_{}", target.triple), &cxx)
- .env(format!("CXXFLAGS_{}", target.triple), cxxflags);
+ .env(format!("CXX_{}", triple_underscored), &cxx)
+ .env(format!("CXXFLAGS_{}", triple_underscored), cxxflags);
}
}
diff --git a/src/bootstrap/builder/tests.rs b/src/bootstrap/builder/tests.rs
index 280eba75f..88bbcc93d 100644
--- a/src/bootstrap/builder/tests.rs
+++ b/src/bootstrap/builder/tests.rs
@@ -236,7 +236,7 @@ mod defaults {
fn doc_default() {
let mut config = configure("doc", &["A"], &["A"]);
config.compiler_docs = true;
- config.cmd = Subcommand::Doc { paths: Vec::new(), open: false };
+ config.cmd = Subcommand::Doc { paths: Vec::new(), open: false, json: false };
let mut cache = run_build(&[], config);
let a = TargetSelection::from_user("A");
@@ -587,7 +587,7 @@ mod dist {
fn doc_ci() {
let mut config = configure(&["A"], &["A"]);
config.compiler_docs = true;
- config.cmd = Subcommand::Doc { paths: Vec::new(), open: false };
+ config.cmd = Subcommand::Doc { paths: Vec::new(), open: false, json: false };
let build = Build::new(config);
let mut builder = Builder::new(&build);
builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), &[]);
diff --git a/src/bootstrap/channel.rs b/src/bootstrap/channel.rs
index 1932a0017..258352a21 100644
--- a/src/bootstrap/channel.rs
+++ b/src/bootstrap/channel.rs
@@ -5,10 +5,12 @@
//! `package_vers`, and otherwise indicating to the compiler what it should
//! print out as part of its version information.
+use std::fs;
use std::path::Path;
use std::process::Command;
use crate::util::output;
+use crate::util::t;
use crate::Build;
pub enum GitInfo {
@@ -18,19 +20,25 @@ pub enum GitInfo {
/// If the info should be used (`ignore_git` is false), this will be
/// `Some`, otherwise it will be `None`.
Present(Option<Info>),
+ /// This is not a git repostory, but the info can be fetched from the
+ /// `git-commit-info` file.
+ RecordedForTarball(Info),
}
pub struct Info {
- commit_date: String,
- sha: String,
- short_sha: String,
+ pub commit_date: String,
+ pub sha: String,
+ pub short_sha: String,
}
impl GitInfo {
pub fn new(ignore_git: bool, dir: &Path) -> GitInfo {
// See if this even begins to look like a git dir
if !dir.join(".git").exists() {
- return GitInfo::Absent;
+ match read_commit_info_file(dir) {
+ Some(info) => return GitInfo::RecordedForTarball(info),
+ None => return GitInfo::Absent,
+ }
}
// Make sure git commands work
@@ -65,10 +73,11 @@ impl GitInfo {
}))
}
- fn info(&self) -> Option<&Info> {
+ pub fn info(&self) -> Option<&Info> {
match self {
- GitInfo::Present(info) => info.as_ref(),
GitInfo::Absent => None,
+ GitInfo::Present(info) => info.as_ref(),
+ GitInfo::RecordedForTarball(info) => Some(info),
}
}
@@ -96,10 +105,53 @@ impl GitInfo {
version
}
- pub fn is_git(&self) -> bool {
+ /// Returns whether this directory has a `.git` directory which should be managed by bootstrap.
+ pub fn is_managed_git_subrepository(&self) -> bool {
match self {
- GitInfo::Absent => false,
+ GitInfo::Absent | GitInfo::RecordedForTarball(_) => false,
GitInfo::Present(_) => true,
}
}
+
+ /// Returns whether this is being built from a tarball.
+ pub fn is_from_tarball(&self) -> bool {
+ match self {
+ GitInfo::Absent | GitInfo::Present(_) => false,
+ GitInfo::RecordedForTarball(_) => true,
+ }
+ }
+}
+
+/// Read the commit information from the `git-commit-info` file given the
+/// project root.
+pub fn read_commit_info_file(root: &Path) -> Option<Info> {
+ if let Ok(contents) = fs::read_to_string(root.join("git-commit-info")) {
+ let mut lines = contents.lines();
+ let sha = lines.next();
+ let short_sha = lines.next();
+ let commit_date = lines.next();
+ let info = match (commit_date, sha, short_sha) {
+ (Some(commit_date), Some(sha), Some(short_sha)) => Info {
+ commit_date: commit_date.to_owned(),
+ sha: sha.to_owned(),
+ short_sha: short_sha.to_owned(),
+ },
+ _ => panic!("the `git-comit-info` file is malformed"),
+ };
+ Some(info)
+ } else {
+ None
+ }
+}
+
+/// Write the commit information to the `git-commit-info` file given the project
+/// root.
+pub fn write_commit_info_file(root: &Path, info: &Info) {
+ let commit_info = format!("{}\n{}\n{}\n", info.sha, info.short_sha, info.commit_date);
+ t!(fs::write(root.join("git-commit-info"), &commit_info));
+}
+
+/// Write the commit hash to the `git-commit-hash` file given the project root.
+pub fn write_commit_hash_file(root: &Path, sha: &str) {
+ t!(fs::write(root.join("git-commit-hash"), sha));
}
diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs
index 5c085bedf..229851238 100644
--- a/src/bootstrap/check.rs
+++ b/src/bootstrap/check.rs
@@ -456,6 +456,8 @@ tool_check_step!(Rustdoc, "src/tools/rustdoc", "src/librustdoc", SourceType::InT
// 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);
+// Miri on the other hand is treated as out of tree, since InTree also causes it to
+// be run as part of `check`, which can fail on platforms which libffi-sys has no support for.
tool_check_step!(Miri, "src/tools/miri", SourceType::Submodule);
tool_check_step!(Rls, "src/tools/rls", SourceType::InTree);
tool_check_step!(Rustfmt, "src/tools/rustfmt", SourceType::InTree);
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs
index c13e83f6c..e02a10b81 100644
--- a/src/bootstrap/compile.rs
+++ b/src/bootstrap/compile.rs
@@ -21,7 +21,7 @@ use serde::Deserialize;
use crate::builder::Cargo;
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
use crate::cache::{Interned, INTERNER};
-use crate::config::{LlvmLibunwind, TargetSelection};
+use crate::config::{LlvmLibunwind, RustcLto, TargetSelection};
use crate::dist;
use crate::native;
use crate::tool::SourceType;
@@ -299,9 +299,7 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
// Determine if we're going to compile in optimized C intrinsics to
// the `compiler-builtins` crate. These intrinsics live in LLVM's
- // `compiler-rt` repository, but our `src/llvm-project` submodule isn't
- // always checked out, so we need to conditionally look for this. (e.g. if
- // an external LLVM is used we skip the LLVM submodule checkout).
+ // `compiler-rt` repository.
//
// Note that this shouldn't affect the correctness of `compiler-builtins`,
// but only its speed. Some intrinsics in C haven't been translated to Rust
@@ -312,8 +310,15 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
// If `compiler-rt` is available ensure that the `c` feature of the
// `compiler-builtins` crate is enabled and it's configured to learn where
// `compiler-rt` is located.
- let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
- let compiler_builtins_c_feature = if compiler_builtins_root.exists() {
+ let compiler_builtins_c_feature = if builder.config.optimized_compiler_builtins {
+ if !builder.is_rust_llvm(target) {
+ panic!(
+ "need a managed LLVM submodule for optimized intrinsics support; unset `llvm-config` or `optimized-compiler-builtins`"
+ );
+ }
+
+ builder.update_submodule(&Path::new("src").join("llvm-project"));
+ let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
// Note that `libprofiler_builtins/build.rs` also computes this so if
// you're changing something here please also change that.
cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root);
@@ -459,7 +464,7 @@ fn copy_sanitizers(
builder.copy(&runtime.path, &dst);
if target == "x86_64-apple-darwin" || target == "aarch64-apple-darwin" {
- // Update the library’s install name to reflect that it has has been renamed.
+ // Update the library’s install name to reflect that it has been renamed.
apple_darwin_update_library_name(&dst, &format!("@rpath/{}", &runtime.name));
// Upon renaming the install name, the code signature of the file will invalidate,
// so we will sign it again.
@@ -696,6 +701,28 @@ impl Step for Rustc {
));
}
+ // cfg(bootstrap): remove if condition once the bootstrap compiler supports dylib LTO
+ if compiler.stage != 0 {
+ match builder.config.rust_lto {
+ RustcLto::Thin | RustcLto::Fat => {
+ // Since using LTO for optimizing dylibs is currently experimental,
+ // we need to pass -Zdylib-lto.
+ cargo.rustflag("-Zdylib-lto");
+ // Cargo by default passes `-Cembed-bitcode=no` and doesn't pass `-Clto` when
+ // compiling dylibs (and their dependencies), even when LTO is enabled for the
+ // crate. Therefore, we need to override `-Clto` and `-Cembed-bitcode` here.
+ let lto_type = match builder.config.rust_lto {
+ RustcLto::Thin => "thin",
+ RustcLto::Fat => "fat",
+ _ => unreachable!(),
+ };
+ cargo.rustflag(&format!("-Clto={}", lto_type));
+ cargo.rustflag("-Cembed-bitcode=yes");
+ }
+ RustcLto::ThinLocal => { /* Do nothing, this is the default */ }
+ }
+ }
+
builder.info(&format!(
"Building stage{} compiler artifacts ({} -> {})",
compiler.stage, &compiler.host, target
@@ -1099,10 +1126,13 @@ impl Step for Sysroot {
/// 1-3.
fn run(self, builder: &Builder<'_>) -> Interned<PathBuf> {
let compiler = self.compiler;
+ let host_dir = builder.out.join(&compiler.host.triple);
let sysroot = if compiler.stage == 0 {
- builder.out.join(&compiler.host.triple).join("stage0-sysroot")
+ host_dir.join("stage0-sysroot")
+ } else if builder.download_rustc() {
+ host_dir.join("ci-rustc-sysroot")
} else {
- builder.out.join(&compiler.host.triple).join(format!("stage{}", compiler.stage))
+ host_dir.join(format!("stage{}", compiler.stage))
};
let _ = fs::remove_dir_all(&sysroot);
t!(fs::create_dir_all(&sysroot));
@@ -1113,6 +1143,11 @@ impl Step for Sysroot {
builder.config.build, compiler.host,
"Cross-compiling is not yet supported with `download-rustc`",
);
+
+ // #102002, cleanup stage1 and stage0-sysroot folders when using download-rustc so people don't use old versions of the toolchain by accident.
+ let _ = fs::remove_dir_all(host_dir.join("stage1"));
+ let _ = fs::remove_dir_all(host_dir.join("stage0-sysroot"));
+
// Copy the compiler into the correct sysroot.
let ci_rustc_dir =
builder.config.out.join(&*builder.config.build.triple).join("ci-rustc");
@@ -1142,6 +1177,20 @@ impl Step for Sysroot {
);
}
}
+ // Same for the rustc-src component.
+ let sysroot_lib_rustlib_rustcsrc = sysroot.join("lib/rustlib/rustc-src");
+ t!(fs::create_dir_all(&sysroot_lib_rustlib_rustcsrc));
+ let sysroot_lib_rustlib_rustcsrc_rust = sysroot_lib_rustlib_rustcsrc.join("rust");
+ if let Err(e) =
+ symlink_dir(&builder.config, &builder.src, &sysroot_lib_rustlib_rustcsrc_rust)
+ {
+ eprintln!(
+ "warning: creating symbolic link `{}` to `{}` failed with {}",
+ sysroot_lib_rustlib_rustcsrc_rust.display(),
+ builder.src.display(),
+ e,
+ );
+ }
INTERNER.intern_path(sysroot)
}
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
index f1a150e0f..a8c403675 100644
--- a/src/bootstrap/config.rs
+++ b/src/bootstrap/config.rs
@@ -73,6 +73,8 @@ pub struct Config {
pub color: Color,
pub patch_binaries_for_nix: bool,
pub stage0_metadata: Stage0Metadata,
+ /// Whether to use the `c` feature of the `compiler_builtins` crate.
+ pub optimized_compiler_builtins: bool,
pub on_fail: Option<String>,
pub stage: u32,
@@ -156,9 +158,12 @@ pub struct Config {
pub rust_new_symbol_mangling: Option<bool>,
pub rust_profile_use: Option<String>,
pub rust_profile_generate: Option<String>,
+ pub rust_lto: RustcLto,
pub llvm_profile_use: Option<String>,
pub llvm_profile_generate: bool,
pub llvm_libunwind_default: Option<LlvmLibunwind>,
+ pub llvm_bolt_profile_generate: bool,
+ pub llvm_bolt_profile_use: Option<String>,
pub build: TargetSelection,
pub hosts: Vec<TargetSelection>,
@@ -315,6 +320,28 @@ impl SplitDebuginfo {
}
}
+/// LTO mode used for compiling rustc itself.
+#[derive(Default, Clone)]
+pub enum RustcLto {
+ #[default]
+ ThinLocal,
+ Thin,
+ Fat,
+}
+
+impl std::str::FromStr for RustcLto {
+ type Err = String;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ "thin-local" => Ok(RustcLto::ThinLocal),
+ "thin" => Ok(RustcLto::Thin),
+ "fat" => Ok(RustcLto::Fat),
+ _ => Err(format!("Invalid value for rustc LTO: {}", s)),
+ }
+ }
+}
+
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TargetSelection {
pub triple: Interned<String>,
@@ -597,6 +624,7 @@ define_config! {
bench_stage: Option<u32> = "bench-stage",
patch_binaries_for_nix: Option<bool> = "patch-binaries-for-nix",
metrics: Option<bool> = "metrics",
+ optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
}
}
@@ -721,6 +749,7 @@ define_config! {
profile_use: Option<String> = "profile-use",
// ignored; this is set from an env var set by bootstrap.py
download_rustc: Option<StringOrBool> = "download-rustc",
+ lto: Option<String> = "lto",
}
}
@@ -772,21 +801,20 @@ impl Config {
// set by build.rs
config.build = TargetSelection::from_user(&env!("BUILD_TRIPLE"));
+
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
// Undo `src/bootstrap`
config.src = manifest_dir.parent().unwrap().parent().unwrap().to_owned();
config.out = PathBuf::from("build");
- config.initial_cargo = PathBuf::from(env!("CARGO"));
- config.initial_rustc = PathBuf::from(env!("RUSTC"));
-
config
}
pub fn parse(args: &[String]) -> Config {
let flags = Flags::parse(&args);
-
let mut config = Config::default_opts();
+
+ // Set flags.
config.exclude = flags.exclude.into_iter().map(|path| TaskPath::parse(path)).collect();
config.include_default_paths = flags.include_default_paths;
config.rustc_error_format = flags.rustc_error_format;
@@ -804,8 +832,68 @@ impl Config {
}
config.llvm_profile_use = flags.llvm_profile_use;
config.llvm_profile_generate = flags.llvm_profile_generate;
+ config.llvm_bolt_profile_generate = flags.llvm_bolt_profile_generate;
+ config.llvm_bolt_profile_use = flags.llvm_bolt_profile_use;
+
+ if config.llvm_bolt_profile_generate && config.llvm_bolt_profile_use.is_some() {
+ eprintln!(
+ "Cannot use both `llvm_bolt_profile_generate` and `llvm_bolt_profile_use` at the same time"
+ );
+ crate::detail_exit(1);
+ }
+
+ // Infer the rest of the configuration.
+
+ // Infer the source directory. This is non-trivial because we want to support a downloaded bootstrap binary,
+ // running on a completely machine from where it was compiled.
+ let mut cmd = Command::new("git");
+ // NOTE: we cannot support running from outside the repository because the only path we have available
+ // is set at compile time, which can be wrong if bootstrap was downloaded from source.
+ // We still support running outside the repository if we find we aren't in a git directory.
+ cmd.arg("rev-parse").arg("--show-toplevel");
+ // Discard stderr because we expect this to fail when building from a tarball.
+ let output = cmd
+ .stderr(std::process::Stdio::null())
+ .output()
+ .ok()
+ .and_then(|output| if output.status.success() { Some(output) } else { None });
+ if let Some(output) = output {
+ let git_root = String::from_utf8(output.stdout).unwrap();
+ // We need to canonicalize this path to make sure it uses backslashes instead of forward slashes.
+ let git_root = PathBuf::from(git_root.trim()).canonicalize().unwrap();
+ let s = git_root.to_str().unwrap();
+
+ // Bootstrap is quite bad at handling /? in front of paths
+ let src = match s.strip_prefix("\\\\?\\") {
+ Some(p) => PathBuf::from(p),
+ None => PathBuf::from(git_root),
+ };
+ // If this doesn't have at least `stage0.json`, we guessed wrong. This can happen when,
+ // for example, the build directory is inside of another unrelated git directory.
+ // In that case keep the original `CARGO_MANIFEST_DIR` handling.
+ //
+ // NOTE: this implies that downloadable bootstrap isn't supported when the build directory is outside
+ // the source directory. We could fix that by setting a variable from all three of python, ./x, and x.ps1.
+ if src.join("src").join("stage0.json").exists() {
+ config.src = src;
+ }
+ } else {
+ // We're building from a tarball, not git sources.
+ // We don't support pre-downloaded bootstrap in this case.
+ }
+
+ if cfg!(test) {
+ // Use the build directory of the original x.py invocation, so that we can set `initial_rustc` properly.
+ config.out = Path::new(
+ &env::var_os("CARGO_TARGET_DIR").expect("cargo test directly is not supported"),
+ )
+ .parent()
+ .unwrap()
+ .to_path_buf();
+ }
let stage0_json = t!(std::fs::read(&config.src.join("src").join("stage0.json")));
+
config.stage0_metadata = t!(serde_json::from_slice::<Stage0Metadata>(&stage0_json));
#[cfg(test)]
@@ -861,7 +949,6 @@ impl Config {
let build = toml.build.unwrap_or_default();
- set(&mut config.initial_rustc, build.rustc.map(PathBuf::from));
set(&mut config.out, flags.build_dir.or_else(|| build.build_dir.map(PathBuf::from)));
// NOTE: Bootstrap spawns various commands with different working directories.
// To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
@@ -870,6 +957,16 @@ impl Config {
config.out = crate::util::absolute(&config.out);
}
+ config.initial_rustc = build
+ .rustc
+ .map(PathBuf::from)
+ .unwrap_or_else(|| config.out.join(config.build.triple).join("stage0/bin/rustc"));
+ config.initial_cargo = build
+ .cargo
+ .map(PathBuf::from)
+ .unwrap_or_else(|| config.out.join(config.build.triple).join("stage0/bin/cargo"));
+
+ // NOTE: it's important this comes *after* we set `initial_rustc` just above.
if config.dry_run {
let dir = config.out.join("tmp-dry-run");
t!(fs::create_dir_all(&dir));
@@ -916,6 +1013,7 @@ impl Config {
set(&mut config.print_step_timings, build.print_step_timings);
set(&mut config.print_step_rusage, build.print_step_rusage);
set(&mut config.patch_binaries_for_nix, build.patch_binaries_for_nix);
+ set(&mut config.optimized_compiler_builtins, build.optimized_compiler_builtins);
config.verbose = cmp::max(config.verbose, flags.verbose);
@@ -1099,6 +1197,12 @@ impl Config {
config.rust_profile_use = flags.rust_profile_use.or(rust.profile_use);
config.rust_profile_generate = flags.rust_profile_generate.or(rust.profile_generate);
config.download_rustc_commit = download_ci_rustc_commit(&config, rust.download_rustc);
+
+ config.rust_lto = rust
+ .lto
+ .as_deref()
+ .map(|value| RustcLto::from_str(value).unwrap())
+ .unwrap_or_default();
} else {
config.rust_profile_use = flags.rust_profile_use;
config.rust_profile_generate = flags.rust_profile_generate;
@@ -1280,20 +1384,21 @@ impl Config {
git
}
- pub(crate) fn artifact_version_part(&self, commit: &str) -> String {
- let mut channel = self.git();
- channel.arg("show").arg(format!("{}:src/ci/channel", commit));
- let channel = output(&mut channel);
-
- let mut version = self.git();
- version.arg("show").arg(format!("{}:src/version", commit));
- let version = output(&mut version);
-
- match channel.trim() {
- "stable" => version.trim().to_owned(),
- "beta" => channel.trim().to_owned(),
- "nightly" => channel.trim().to_owned(),
- other => unreachable!("{:?} is not recognized as a valid channel", other),
+ pub(crate) fn artifact_channel(&self, builder: &Builder<'_>, commit: &str) -> String {
+ if builder.rust_info.is_managed_git_subrepository() {
+ let mut channel = self.git();
+ channel.arg("show").arg(format!("{}:src/ci/channel", commit));
+ let channel = output(&mut channel);
+ channel.trim().to_owned()
+ } else if let Ok(channel) = fs::read_to_string(builder.src.join("src/ci/channel")) {
+ channel.trim().to_owned()
+ } else {
+ let src = builder.src.display();
+ eprintln!("error: failed to determine artifact channel");
+ eprintln!(
+ "help: either use git or ensure that {src}/src/ci/channel contains the name of the channel to use"
+ );
+ panic!();
}
}
@@ -1431,7 +1536,7 @@ impl Config {
}
pub fn submodules(&self, rust_info: &GitInfo) -> bool {
- self.submodules.unwrap_or(rust_info.is_git())
+ self.submodules.unwrap_or(rust_info.is_managed_git_subrepository())
}
}
@@ -1536,7 +1641,7 @@ fn maybe_download_rustfmt(builder: &Builder<'_>) -> Option<PathBuf> {
fn download_ci_rustc(builder: &Builder<'_>, commit: &str) {
builder.verbose(&format!("using downloaded stage2 artifacts from CI (commit {commit})"));
- let version = builder.config.artifact_version_part(commit);
+ let channel = builder.config.artifact_channel(builder, commit);
let host = builder.config.build.triple;
let bin_root = builder.out.join(host).join("ci-rustc");
let rustc_stamp = bin_root.join(".rustc-stamp");
@@ -1545,13 +1650,13 @@ fn download_ci_rustc(builder: &Builder<'_>, commit: &str) {
if bin_root.exists() {
t!(fs::remove_dir_all(&bin_root));
}
- let filename = format!("rust-std-{version}-{host}.tar.xz");
+ let filename = format!("rust-std-{channel}-{host}.tar.xz");
let pattern = format!("rust-std-{host}");
download_ci_component(builder, filename, &pattern, commit);
- let filename = format!("rustc-{version}-{host}.tar.xz");
+ let filename = format!("rustc-{channel}-{host}.tar.xz");
download_ci_component(builder, filename, "rustc", commit);
// download-rustc doesn't need its own cargo, it can just use beta's.
- let filename = format!("rustc-dev-{version}-{host}.tar.xz");
+ let filename = format!("rustc-dev-{channel}-{host}.tar.xz");
download_ci_component(builder, filename, "rustc-dev", commit);
builder.fix_bin_or_dylib(&bin_root.join("bin").join("rustc"));
diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs
index 1a59b3958..12585e80e 100644
--- a/src/bootstrap/dist.rs
+++ b/src/bootstrap/dist.rs
@@ -16,6 +16,7 @@ use std::process::Command;
use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
use crate::cache::{Interned, INTERNER};
+use crate::channel;
use crate::compile;
use crate::config::TargetSelection;
use crate::tarball::{GeneratedTarball, OverlayKind, Tarball};
@@ -35,18 +36,6 @@ pub fn tmpdir(builder: &Builder<'_>) -> PathBuf {
builder.out.join("tmp/dist")
}
-fn missing_tool(tool_name: &str, skip: bool) {
- if skip {
- println!("Unable to build {}, skipping dist", tool_name)
- } else {
- let help = "note: not all tools are available on all nightlies\nhelp: see https://forge.rust-lang.org/infra/toolstate.html for more information";
- panic!(
- "Unable to build submodule tool {} (use `missing-tools = true` to ignore this failure)\n{}",
- tool_name, help
- )
- }
-}
-
fn should_build_extended_tool(builder: &Builder<'_>, tool: &str) -> bool {
if !builder.config.extended {
return false;
@@ -87,6 +76,39 @@ impl Step for Docs {
}
}
+#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct JsonDocs {
+ pub host: TargetSelection,
+}
+
+impl Step for JsonDocs {
+ type Output = Option<GeneratedTarball>;
+ const DEFAULT: bool = true;
+
+ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
+ let default = run.builder.config.docs;
+ run.alias("rust-docs-json").default_condition(default)
+ }
+
+ fn make_run(run: RunConfig<'_>) {
+ run.builder.ensure(JsonDocs { host: run.target });
+ }
+
+ /// Builds the `rust-docs-json` installer component.
+ fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
+ let host = self.host;
+ builder.ensure(crate::doc::JsonStd { stage: builder.top_stage, target: host });
+
+ let dest = "share/doc/rust/json";
+
+ let mut tarball = Tarball::new(builder, "rust-docs-json", &host.triple);
+ tarball.set_product_name("Rust Documentation In JSON Format");
+ tarball.is_preview(true);
+ tarball.add_bulk_dir(&builder.json_doc_out(host), dest);
+ Some(tarball.generate())
+ }
+}
+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct RustcDocs {
pub host: TargetSelection,
@@ -897,12 +919,13 @@ impl Step for PlainSourceTarball {
// Create the version file
builder.create(&plain_dst_src.join("version"), &builder.rust_version());
- if let Some(sha) = builder.rust_sha() {
- builder.create(&plain_dst_src.join("git-commit-hash"), &sha);
+ if let Some(info) = builder.rust_info.info() {
+ channel::write_commit_hash_file(&plain_dst_src, &info.sha);
+ channel::write_commit_info_file(&plain_dst_src, info);
}
// If we're building from git sources, we need to vendor a complete distribution.
- if builder.rust_info.is_git() {
+ if builder.rust_info.is_managed_git_subrepository() {
// Ensure we have the submodules checked out.
builder.update_submodule(Path::new("src/tools/rust-analyzer"));
@@ -1170,18 +1193,9 @@ impl Step for Miri {
let compiler = self.compiler;
let target = self.target;
- let miri = builder
- .ensure(tool::Miri { compiler, target, extra_features: Vec::new() })
- .or_else(|| {
- missing_tool("miri", builder.build.config.missing_tools);
- None
- })?;
- let cargomiri = builder
- .ensure(tool::CargoMiri { compiler, target, extra_features: Vec::new() })
- .or_else(|| {
- missing_tool("cargo miri", builder.build.config.missing_tools);
- None
- })?;
+ let miri = builder.ensure(tool::Miri { compiler, target, extra_features: Vec::new() })?;
+ let cargomiri =
+ builder.ensure(tool::CargoMiri { compiler, target, extra_features: Vec::new() })?;
let mut tarball = Tarball::new(builder, "miri", &target.triple);
tarball.set_overlay(OverlayKind::Miri);
@@ -1353,6 +1367,7 @@ impl Step for Extended {
}
add_component!("rust-docs" => Docs { host: target });
+ add_component!("rust-json-docs" => JsonDocs { host: target });
add_component!("rust-demangler"=> RustDemangler { compiler, target });
add_component!("cargo" => Cargo { compiler, target });
add_component!("rustfmt" => Rustfmt { compiler, target });
@@ -1412,7 +1427,7 @@ impl Step for Extended {
let xform = |p: &Path| {
let mut contents = t!(fs::read_to_string(p));
- for tool in &["rust-demangler", "rust-analyzer", "miri", "rustfmt"] {
+ for tool in &["rust-demangler", "miri"] {
if !built_tools.contains(tool) {
contents = filter(&contents, tool);
}
@@ -1452,7 +1467,8 @@ impl Step for Extended {
prepare("rust-std");
prepare("rust-analysis");
prepare("clippy");
- for tool in &["rust-docs", "rust-demangler", "rust-analyzer", "miri"] {
+ prepare("rust-analyzer");
+ for tool in &["rust-docs", "rust-demangler", "miri"] {
if built_tools.contains(tool) {
prepare(tool);
}
@@ -1511,7 +1527,8 @@ impl Step for Extended {
prepare("rust-docs");
prepare("rust-std");
prepare("clippy");
- for tool in &["rust-demangler", "rust-analyzer", "miri"] {
+ prepare("rust-analyzer");
+ for tool in &["rust-demangler", "miri"] {
if built_tools.contains(tool) {
prepare(tool);
}
@@ -1595,25 +1612,23 @@ impl Step for Extended {
.arg("-out")
.arg(exe.join("StdGroup.wxs")),
);
- if built_tools.contains("rust-analyzer") {
- builder.run(
- Command::new(&heat)
- .current_dir(&exe)
- .arg("dir")
- .arg("rust-analyzer")
- .args(&heat_flags)
- .arg("-cg")
- .arg("RustAnalyzerGroup")
- .arg("-dr")
- .arg("RustAnalyzer")
- .arg("-var")
- .arg("var.RustAnalyzerDir")
- .arg("-out")
- .arg(exe.join("RustAnalyzerGroup.wxs"))
- .arg("-t")
- .arg(etc.join("msi/remove-duplicates.xsl")),
- );
- }
+ builder.run(
+ Command::new(&heat)
+ .current_dir(&exe)
+ .arg("dir")
+ .arg("rust-analyzer")
+ .args(&heat_flags)
+ .arg("-cg")
+ .arg("RustAnalyzerGroup")
+ .arg("-dr")
+ .arg("RustAnalyzer")
+ .arg("-var")
+ .arg("var.RustAnalyzerDir")
+ .arg("-out")
+ .arg(exe.join("RustAnalyzerGroup.wxs"))
+ .arg("-t")
+ .arg(etc.join("msi/remove-duplicates.xsl")),
+ );
builder.run(
Command::new(&heat)
.current_dir(&exe)
@@ -1745,15 +1760,15 @@ impl Step for Extended {
candle("CargoGroup.wxs".as_ref());
candle("StdGroup.wxs".as_ref());
candle("ClippyGroup.wxs".as_ref());
+ if built_tools.contains("miri") {
+ candle("MiriGroup.wxs".as_ref());
+ }
if built_tools.contains("rust-demangler") {
candle("RustDemanglerGroup.wxs".as_ref());
}
if built_tools.contains("rust-analyzer") {
candle("RustAnalyzerGroup.wxs".as_ref());
}
- if built_tools.contains("miri") {
- candle("MiriGroup.wxs".as_ref());
- }
candle("AnalysisGroup.wxs".as_ref());
if target.ends_with("windows-gnu") {
@@ -1785,15 +1800,15 @@ impl Step for Extended {
.arg("ClippyGroup.wixobj")
.current_dir(&exe);
+ if built_tools.contains("miri") {
+ cmd.arg("MiriGroup.wixobj");
+ }
if built_tools.contains("rust-analyzer") {
cmd.arg("RustAnalyzerGroup.wixobj");
}
if built_tools.contains("rust-demangler") {
cmd.arg("RustDemanglerGroup.wixobj");
}
- if built_tools.contains("miri") {
- cmd.arg("MiriGroup.wixobj");
- }
if target.ends_with("windows-gnu") {
cmd.arg("GccGroup.wixobj");
@@ -1838,23 +1853,21 @@ fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) {
///
/// Returns whether the files were actually copied.
fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) -> bool {
- if let Some(config) = builder.config.target_config.get(&target) {
- if config.llvm_config.is_some() && !builder.config.llvm_from_ci {
- // If the LLVM was externally provided, then we don't currently copy
- // artifacts into the sysroot. This is not necessarily the right
- // choice (in particular, it will require the LLVM dylib to be in
- // the linker's load path at runtime), but the common use case for
- // external LLVMs is distribution provided LLVMs, and in that case
- // they're usually in the standard search path (e.g., /usr/lib) and
- // copying them here is going to cause problems as we may end up
- // with the wrong files and isn't what distributions want.
- //
- // This behavior may be revisited in the future though.
- //
- // If the LLVM is coming from ourselves (just from CI) though, we
- // still want to install it, as it otherwise won't be available.
- return false;
- }
+ if !builder.is_rust_llvm(target) {
+ // If the LLVM was externally provided, then we don't currently copy
+ // artifacts into the sysroot. This is not necessarily the right
+ // choice (in particular, it will require the LLVM dylib to be in
+ // the linker's load path at runtime), but the common use case for
+ // external LLVMs is distribution provided LLVMs, and in that case
+ // they're usually in the standard search path (e.g., /usr/lib) and
+ // copying them here is going to cause problems as we may end up
+ // with the wrong files and isn't what distributions want.
+ //
+ // This behavior may be revisited in the future though.
+ //
+ // If the LLVM is coming from ourselves (just from CI) though, we
+ // still want to install it, as it otherwise won't be available.
+ return false;
}
// On macOS, rustc (and LLVM tools) link to an unversioned libLLVM.dylib
@@ -1873,7 +1886,7 @@ fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir
let mut cmd = Command::new(llvm_config);
cmd.arg("--libfiles");
builder.verbose(&format!("running {:?}", cmd));
- let files = output(&mut cmd);
+ let files = if builder.config.dry_run { "".into() } else { output(&mut cmd) };
let build_llvm_out = &builder.llvm_out(builder.config.build);
let target_llvm_out = &builder.llvm_out(target);
for file in files.trim_end().split(' ') {
@@ -2020,6 +2033,8 @@ impl Step for RustDev {
"llvm-dwp",
"llvm-nm",
"llvm-dwarfdump",
+ "llvm-dis",
+ "llvm-tblgen",
] {
tarball.add_file(src_bindir.join(exe(bin, target)), "bin", 0o755);
}
@@ -2050,6 +2065,41 @@ impl Step for RustDev {
}
}
+// Tarball intended for internal consumption to ease rustc/std development.
+//
+// Should not be considered stable by end users.
+#[derive(Clone, Debug, Eq, Hash, PartialEq)]
+pub struct Bootstrap {
+ pub target: TargetSelection,
+}
+
+impl Step for Bootstrap {
+ type Output = Option<GeneratedTarball>;
+ const DEFAULT: bool = false;
+ const ONLY_HOSTS: bool = true;
+
+ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
+ run.alias("bootstrap")
+ }
+
+ fn make_run(run: RunConfig<'_>) {
+ run.builder.ensure(Bootstrap { target: run.target });
+ }
+
+ fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
+ let target = self.target;
+
+ let tarball = Tarball::new(builder, "bootstrap", &target.triple);
+
+ let bootstrap_outdir = &builder.bootstrap_out;
+ for file in &["bootstrap", "llvm-config-wrapper", "rustc", "rustdoc", "sccache-plus-cl"] {
+ tarball.add_file(bootstrap_outdir.join(exe(file, target)), "bootstrap/bin", 0o755);
+ }
+
+ Some(tarball.generate())
+ }
+}
+
/// Tarball containing a prebuilt version of the build-manifest tool, intended to be used by the
/// release process to avoid cloning the monorepo and building stuff.
///
@@ -2115,6 +2165,10 @@ impl Step for ReproducibleArtifacts {
tarball.add_file(path, ".", 0o644);
added_anything = true;
}
+ if let Some(path) = builder.config.llvm_bolt_profile_use.as_ref() {
+ tarball.add_file(path, ".", 0o644);
+ added_anything = true;
+ }
if added_anything { Some(tarball.generate()) } else { None }
}
}
diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs
index f909ecc0a..ea06caf9c 100644
--- a/src/bootstrap/doc.rs
+++ b/src/bootstrap/doc.rs
@@ -7,6 +7,7 @@
//! Everything here is basically just a shim around calling either `rustbook` or
//! `rustdoc`.
+use std::ffi::OsStr;
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
@@ -81,6 +82,7 @@ book!(
Reference, "src/doc/reference", "reference", submodule;
RustByExample, "src/doc/rust-by-example", "rust-by-example", submodule;
RustdocBook, "src/doc/rustdoc", "rustdoc";
+ StyleGuide, "src/doc/style-guide", "style-guide";
);
fn open(builder: &Builder<'_>, path: impl AsRef<Path>) {
@@ -226,7 +228,7 @@ impl Step for TheBook {
}
// build the version info page and CSS
- builder.ensure(Standalone { compiler, target });
+ let shared_assets = builder.ensure(SharedAssets { target });
// build the redirect pages
builder.info(&format!("Documenting book redirect pages ({})", target));
@@ -235,7 +237,7 @@ impl Step for TheBook {
let path = file.path();
let path = path.to_str().unwrap();
- invoke_rustdoc(builder, compiler, target, path);
+ invoke_rustdoc(builder, compiler, &shared_assets, target, path);
}
if builder.was_invoked_explicitly::<Self>(Kind::Doc) {
@@ -249,6 +251,7 @@ impl Step for TheBook {
fn invoke_rustdoc(
builder: &Builder<'_>,
compiler: Compiler,
+ shared_assets: &SharedAssetsPaths,
target: TargetSelection,
markdown: &str,
) {
@@ -258,7 +261,6 @@ fn invoke_rustdoc(
let header = builder.src.join("src/doc/redirect.inc");
let footer = builder.src.join("src/doc/footer.inc");
- let version_info = out.join("version_info.html");
let mut cmd = builder.rustdoc_cmd(compiler);
@@ -267,7 +269,7 @@ fn invoke_rustdoc(
cmd.arg("--html-after-content")
.arg(&footer)
.arg("--html-before-content")
- .arg(&version_info)
+ .arg(&shared_assets.version_info)
.arg("--html-in-header")
.arg(&header)
.arg("--markdown-no-toc")
@@ -298,7 +300,7 @@ impl Step for Standalone {
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
let builder = run.builder;
- run.path("src/doc").default_condition(builder.config.docs)
+ run.path("src/doc").alias("standalone").default_condition(builder.config.docs)
}
fn make_run(run: RunConfig<'_>) {
@@ -323,21 +325,11 @@ impl Step for Standalone {
let out = builder.doc_out(target);
t!(fs::create_dir_all(&out));
+ let version_info = builder.ensure(SharedAssets { target: self.target }).version_info;
+
let favicon = builder.src.join("src/doc/favicon.inc");
let footer = builder.src.join("src/doc/footer.inc");
let full_toc = builder.src.join("src/doc/full-toc.inc");
- t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css")));
-
- let version_input = builder.src.join("src/doc/version_info.html.template");
- let version_info = out.join("version_info.html");
-
- if !builder.config.dry_run && !up_to_date(&version_input, &version_info) {
- let info = t!(fs::read_to_string(&version_input))
- .replace("VERSION", &builder.rust_release())
- .replace("SHORT_HASH", builder.rust_info.sha_short().unwrap_or(""))
- .replace("STAMP", builder.rust_info.sha().unwrap_or(""));
- t!(fs::write(&version_info, &info));
- }
for file in t!(fs::read_dir(builder.src.join("src/doc"))) {
let file = t!(file);
@@ -383,15 +375,9 @@ impl Step for Standalone {
}
if filename == "not_found.md" {
- cmd.arg("--markdown-css")
- .arg(format!("https://doc.rust-lang.org/rustdoc{}.css", &builder.version))
- .arg("--markdown-css")
- .arg("https://doc.rust-lang.org/rust.css");
+ cmd.arg("--markdown-css").arg("https://doc.rust-lang.org/rust.css");
} else {
- cmd.arg("--markdown-css")
- .arg(format!("rustdoc{}.css", &builder.version))
- .arg("--markdown-css")
- .arg("rust.css");
+ cmd.arg("--markdown-css").arg("rust.css");
}
builder.run(&mut cmd);
}
@@ -405,6 +391,45 @@ impl Step for Standalone {
}
}
+#[derive(Debug, Clone)]
+pub struct SharedAssetsPaths {
+ pub version_info: PathBuf,
+}
+
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct SharedAssets {
+ target: TargetSelection,
+}
+
+impl Step for SharedAssets {
+ type Output = SharedAssetsPaths;
+ const DEFAULT: bool = false;
+
+ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
+ // Other tasks depend on this, no need to execute it on its own
+ run.never()
+ }
+
+ // Generate shared resources used by other pieces of documentation.
+ fn run(self, builder: &Builder<'_>) -> Self::Output {
+ let out = builder.doc_out(self.target);
+
+ let version_input = builder.src.join("src").join("doc").join("version_info.html.template");
+ let version_info = out.join("version_info.html");
+ if !builder.config.dry_run && !up_to_date(&version_input, &version_info) {
+ let info = t!(fs::read_to_string(&version_input))
+ .replace("VERSION", &builder.rust_release())
+ .replace("SHORT_HASH", builder.rust_info.sha_short().unwrap_or(""))
+ .replace("STAMP", builder.rust_info.sha().unwrap_or(""));
+ t!(fs::write(&version_info, &info));
+ }
+
+ builder.copy(&builder.src.join("src").join("doc").join("rust.css"), &out.join("rust.css"));
+
+ SharedAssetsPaths { version_info }
+ }
+}
+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Std {
pub stage: u32,
@@ -431,49 +456,25 @@ impl Step for Std {
fn run(self, builder: &Builder<'_>) {
let stage = self.stage;
let target = self.target;
- builder.info(&format!("Documenting stage{} std ({})", stage, target));
- if builder.no_std(target) == Some(true) {
- panic!(
- "building std documentation for no_std target {target} is not supported\n\
- Set `docs = false` in the config to disable documentation."
- );
- }
let out = builder.doc_out(target);
t!(fs::create_dir_all(&out));
- let compiler = builder.compiler(stage, builder.config.build);
-
- let out_dir = builder.stage_out(compiler, Mode::Std).join(target.triple).join("doc");
-
- 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, SourceType::InTree, target, "rustdoc");
- compile::std_cargo(builder, target, compiler.stage, &mut cargo);
- cargo
- .arg("-p")
- .arg(package)
- .arg("-Zskip-rustdoc-fingerprint")
- .arg("--")
- .arg("--markdown-css")
- .arg("rust.css")
- .arg("--markdown-no-toc")
- .arg("-Z")
- .arg("unstable-options")
- .arg("--resource-suffix")
- .arg(&builder.version)
- .arg("--index-page")
- .arg(&builder.src.join("src/doc/index.md"));
+ builder.ensure(SharedAssets { target: self.target });
- if !builder.config.docs_minification {
- cargo.arg("--disable-minification");
- }
+ let index_page = builder.src.join("src/doc/index.md").into_os_string();
+ let mut extra_args = vec![
+ OsStr::new("--markdown-css"),
+ OsStr::new("rust.css"),
+ OsStr::new("--markdown-no-toc"),
+ OsStr::new("--index-page"),
+ &index_page,
+ ];
- builder.run(&mut cargo.into());
- };
+ if !builder.config.docs_minification {
+ extra_args.push(OsStr::new("--disable-minification"));
+ }
- let paths = builder
+ let requested_crates = builder
.paths
.iter()
.map(components_simplified)
@@ -491,30 +492,20 @@ impl Step for Std {
})
.collect::<Vec<_>>();
- // Only build the following crates. While we could just iterate over the
- // folder structure, that would also build internal crates that we do
- // not want to show in documentation. These crates will later be visited
- // by the rustc step, so internal documentation will show them.
- //
- // Note that the order here is important! The crates need to be
- // processed starting from the leaves, otherwise rustdoc will not
- // create correct links between crates because rustdoc depends on the
- // existence of the output directories to know if it should be a local
- // or remote link.
- let krates = ["core", "alloc", "std", "proc_macro", "test"];
- for krate in &krates {
- run_cargo_rustdoc_for(krate);
- if paths.iter().any(|p| p == krate) {
- // No need to document more of the libraries if we have the one we want.
- break;
- }
- }
- builder.cp_r(&out_dir, &out);
+ doc_std(
+ builder,
+ DocumentationFormat::HTML,
+ stage,
+ target,
+ &out,
+ &extra_args,
+ &requested_crates,
+ );
// Look for library/std, library/core etc in the `x.py doc` arguments and
// open the corresponding rendered docs.
- for requested_crate in paths {
- if krates.iter().any(|k| *k == requested_crate.as_str()) {
+ for requested_crate in requested_crates {
+ if STD_PUBLIC_CRATES.iter().any(|k| *k == requested_crate.as_str()) {
let index = out.join(requested_crate).join("index.html");
open(builder, &index);
}
@@ -523,6 +514,134 @@ impl Step for Std {
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct JsonStd {
+ pub stage: u32,
+ pub target: TargetSelection,
+}
+
+impl Step for JsonStd {
+ type Output = ();
+ const DEFAULT: bool = false;
+
+ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
+ let default = run.builder.config.docs && run.builder.config.cmd.json();
+ run.all_krates("test").path("library").default_condition(default)
+ }
+
+ fn make_run(run: RunConfig<'_>) {
+ run.builder.ensure(Std { stage: run.builder.top_stage, target: run.target });
+ }
+
+ /// Build JSON documentation for the standard library crates.
+ ///
+ /// This is largely just a wrapper around `cargo doc`.
+ fn run(self, builder: &Builder<'_>) {
+ let stage = self.stage;
+ let target = self.target;
+ let out = builder.json_doc_out(target);
+ t!(fs::create_dir_all(&out));
+ let extra_args = [OsStr::new("--output-format"), OsStr::new("json")];
+ doc_std(builder, DocumentationFormat::JSON, stage, target, &out, &extra_args, &[])
+ }
+}
+
+/// Name of the crates that are visible to consumers of the standard library.
+/// Documentation for internal crates is handled by the rustc step, so internal crates will show
+/// up there.
+///
+/// Order here is important!
+/// Crates need to be processed starting from the leaves, otherwise rustdoc will not
+/// create correct links between crates because rustdoc depends on the
+/// existence of the output directories to know if it should be a local
+/// or remote link.
+const STD_PUBLIC_CRATES: [&str; 5] = ["core", "alloc", "std", "proc_macro", "test"];
+
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+enum DocumentationFormat {
+ HTML,
+ JSON,
+}
+
+impl DocumentationFormat {
+ fn as_str(&self) -> &str {
+ match self {
+ DocumentationFormat::HTML => "HTML",
+ DocumentationFormat::JSON => "JSON",
+ }
+ }
+}
+
+/// Build the documentation for public standard library crates.
+///
+/// `requested_crates` can be used to build only a subset of the crates. If empty, all crates will
+/// be built.
+fn doc_std(
+ builder: &Builder<'_>,
+ format: DocumentationFormat,
+ stage: u32,
+ target: TargetSelection,
+ out: &Path,
+ extra_args: &[&OsStr],
+ requested_crates: &[String],
+) {
+ builder.info(&format!(
+ "Documenting stage{} std ({}) in {} format",
+ stage,
+ target,
+ format.as_str()
+ ));
+ if builder.no_std(target) == Some(true) {
+ panic!(
+ "building std documentation for no_std target {target} is not supported\n\
+ Set `docs = false` in the config to disable documentation."
+ );
+ }
+ let compiler = builder.compiler(stage, builder.config.build);
+ // This is directory where the compiler will place the output of the command.
+ // We will then copy the files from this directory into the final `out` directory, the specified
+ // as a function parameter.
+ let out_dir = builder.stage_out(compiler, Mode::Std).join(target.triple).join("doc");
+ // `cargo` uses the same directory for both JSON docs and HTML docs.
+ // This could lead to cross-contamination when copying files into the specified `out` directory.
+ // For example:
+ // ```bash
+ // x doc std
+ // x doc std --json
+ // ```
+ // could lead to HTML docs being copied into the JSON docs output directory.
+ // To avoid this issue, we clean the doc folder before invoking `cargo`.
+ if out_dir.exists() {
+ builder.remove_dir(&out_dir);
+ }
+
+ let run_cargo_rustdoc_for = |package: &str| {
+ let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "rustdoc");
+ compile::std_cargo(builder, target, compiler.stage, &mut cargo);
+ cargo
+ .arg("-p")
+ .arg(package)
+ .arg("-Zskip-rustdoc-fingerprint")
+ .arg("--")
+ .arg("-Z")
+ .arg("unstable-options")
+ .arg("--resource-suffix")
+ .arg(&builder.version)
+ .args(extra_args);
+ builder.run(&mut cargo.into());
+ };
+
+ for krate in STD_PUBLIC_CRATES {
+ run_cargo_rustdoc_for(krate);
+ if requested_crates.iter().any(|p| p == krate) {
+ // No need to document more of the libraries if we have the one we want.
+ break;
+ }
+ }
+
+ builder.cp_r(&out_dir, &out);
+}
+
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Rustc {
pub stage: u32,
pub target: TargetSelection,
diff --git a/src/bootstrap/download-ci-llvm-stamp b/src/bootstrap/download-ci-llvm-stamp
index 19504a51a..d19a1ae95 100644
--- a/src/bootstrap/download-ci-llvm-stamp
+++ b/src/bootstrap/download-ci-llvm-stamp
@@ -1,4 +1,4 @@
Change this file to make users of the `download-ci-llvm` configuration download
a new version of LLVM from CI, even if the LLVM submodule hasn’t changed.
-Last change is for: https://github.com/rust-lang/rust/pull/96867
+Last change is for: https://github.com/rust-lang/rust/pull/102790
diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs
index 789da7481..ee341a353 100644
--- a/src/bootstrap/flags.rs
+++ b/src/bootstrap/flags.rs
@@ -78,6 +78,8 @@ pub struct Flags {
//
// llvm_out/build/profiles/ is the location this writes to.
pub llvm_profile_generate: bool,
+ pub llvm_bolt_profile_generate: bool,
+ pub llvm_bolt_profile_use: Option<String>,
}
#[derive(Debug)]
@@ -107,6 +109,7 @@ pub enum Subcommand {
Doc {
paths: Vec<PathBuf>,
open: bool,
+ json: bool,
},
Test {
paths: Vec<PathBuf>,
@@ -254,6 +257,8 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
opts.optmulti("D", "", "deny certain clippy lints", "OPT");
opts.optmulti("W", "", "warn about certain clippy lints", "OPT");
opts.optmulti("F", "", "forbid certain clippy lints", "OPT");
+ opts.optflag("", "llvm-bolt-profile-generate", "generate BOLT profile for LLVM build");
+ opts.optopt("", "llvm-bolt-profile-use", "use BOLT profile for LLVM build", "PROFILE");
// We can't use getopt to parse the options until we have completed specifying which
// options are valid, but under the current implementation, some options are conditional on
@@ -325,6 +330,11 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
}
Kind::Doc => {
opts.optflag("", "open", "open the docs in a browser");
+ opts.optflag(
+ "",
+ "json",
+ "render the documentation in JSON format in addition to the usual HTML format",
+ );
}
Kind::Clean => {
opts.optflag("", "all", "clean all build artifacts");
@@ -493,6 +503,7 @@ Arguments:
./x.py doc src/doc/book
./x.py doc src/doc/nomicon
./x.py doc src/doc/book library/std
+ ./x.py doc library/std --json
./x.py doc library/std --open
If no arguments are passed then everything is documented:
@@ -581,7 +592,11 @@ Arguments:
},
},
Kind::Bench => Subcommand::Bench { paths, test_args: matches.opt_strs("test-args") },
- Kind::Doc => Subcommand::Doc { paths, open: matches.opt_present("open") },
+ Kind::Doc => Subcommand::Doc {
+ paths,
+ open: matches.opt_present("open"),
+ json: matches.opt_present("json"),
+ },
Kind::Clean => {
if !paths.is_empty() {
println!("\nclean does not take a path argument\n");
@@ -680,6 +695,8 @@ Arguments:
rust_profile_generate: matches.opt_str("rust-profile-generate"),
llvm_profile_use: matches.opt_str("llvm-profile-use"),
llvm_profile_generate: matches.opt_present("llvm-profile-generate"),
+ llvm_bolt_profile_generate: matches.opt_present("llvm-bolt-profile-generate"),
+ llvm_bolt_profile_use: matches.opt_str("llvm-bolt-profile-use"),
}
}
}
@@ -787,6 +804,13 @@ impl Subcommand {
_ => false,
}
}
+
+ pub fn json(&self) -> bool {
+ match *self {
+ Subcommand::Doc { json, .. } => json,
+ _ => false,
+ }
+ }
}
fn split(s: &[String]) -> Vec<String> {
diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs
index d34aa15c5..7672b7c91 100644
--- a/src/bootstrap/install.rs
+++ b/src/bootstrap/install.rs
@@ -200,13 +200,10 @@ install!((self, builder, _config),
install_sh(builder, "clippy", self.compiler.stage, Some(self.target), &tarball);
};
Miri, alias = "miri", Self::should_build(_config), only_hosts: true, {
- if let Some(tarball) = builder.ensure(dist::Miri { compiler: self.compiler, target: self.target }) {
- install_sh(builder, "miri", self.compiler.stage, Some(self.target), &tarball);
- } else {
- builder.info(
- &format!("skipping Install miri stage{} ({})", self.compiler.stage, self.target),
- );
- }
+ let tarball = builder
+ .ensure(dist::Miri { compiler: self.compiler, target: self.target })
+ .expect("missing miri");
+ install_sh(builder, "miri", self.compiler.stage, Some(self.target), &tarball);
};
Rustfmt, alias = "rustfmt", Self::should_build(_config), only_hosts: true, {
if let Some(tarball) = builder.ensure(dist::Rustfmt {
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index cc0cf12bd..7e70e99bb 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -122,6 +122,7 @@ use crate::util::{
check_run, exe, libdir, mtime, output, run, run_suppressed, try_run, try_run_suppressed, CiEnv,
};
+mod bolt;
mod builder;
mod cache;
mod cc_detect;
@@ -198,9 +199,12 @@ const EXTRA_CHECK_CFGS: &[(Option<Mode>, &'static str, Option<&[&'static str]>)]
(None, "bootstrap", None),
(Some(Mode::Rustc), "parallel_compiler", None),
(Some(Mode::ToolRustc), "parallel_compiler", None),
+ (Some(Mode::Codegen), "parallel_compiler", None),
(Some(Mode::Std), "stdarch_intel_sde", None),
(Some(Mode::Std), "no_fp_fmt_parse", None),
(Some(Mode::Std), "no_global_oom_handling", None),
+ (Some(Mode::Std), "no_rc", None),
+ (Some(Mode::Std), "no_sync", None),
(Some(Mode::Std), "freebsd12", None),
(Some(Mode::Std), "backtrace_in_libstd", None),
/* Extra values not defined in the built-in targets yet, but used in std */
@@ -226,6 +230,8 @@ const EXTRA_CHECK_CFGS: &[(Option<Mode>, &'static str, Option<&[&'static str]>)]
// FIXME: Used by proc-macro2, but we should not be triggering on external dependencies.
(Some(Mode::Rustc), "span_locations", None),
(Some(Mode::ToolRustc), "span_locations", None),
+ // Can be passed in RUSTFLAGS to prevent direct syscalls in rustix.
+ (None, "rustix_use_libc", None),
];
/// A structure representing a Rust compiler.
@@ -395,7 +401,7 @@ impl Build {
/// line and the filesystem `config`.
///
/// By default all build output will be placed in the current directory.
- pub fn new(config: Config) -> Build {
+ pub fn new(mut config: Config) -> Build {
let src = config.src.clone();
let out = config.out.clone();
@@ -456,19 +462,22 @@ impl Build {
.expect("failed to read src/version");
let version = version.trim();
- let bootstrap_out = if std::env::var("BOOTSTRAP_PYTHON").is_ok() {
- out.join("bootstrap").join("debug")
- } else {
- let workspace_target_dir = std::env::var("CARGO_TARGET_DIR")
- .map(PathBuf::from)
- .unwrap_or_else(|_| src.join("target"));
- let bootstrap_out = workspace_target_dir.join("debug");
- if !bootstrap_out.join("rustc").exists() && !cfg!(test) {
- // this restriction can be lifted whenever https://github.com/rust-lang/rfcs/pull/3028 is implemented
- panic!("run `cargo build --bins` before `cargo run`")
- }
- bootstrap_out
- };
+ let bootstrap_out = std::env::current_exe()
+ .expect("could not determine path to running process")
+ .parent()
+ .unwrap()
+ .to_path_buf();
+ if !bootstrap_out.join(exe("rustc", config.build)).exists() && !cfg!(test) {
+ // this restriction can be lifted whenever https://github.com/rust-lang/rfcs/pull/3028 is implemented
+ panic!(
+ "`rustc` not found in {}, run `cargo build --bins` before `cargo run`",
+ bootstrap_out.display()
+ )
+ }
+
+ if rust_info.is_from_tarball() && config.description.is_none() {
+ config.description = Some("built from a source tarball".to_owned());
+ }
let mut build = Build {
initial_rustc: config.initial_rustc.clone(),
@@ -540,13 +549,8 @@ impl Build {
// Make sure we update these before gathering metadata so we don't get an error about missing
// Cargo.toml files.
- let rust_submodules = [
- "src/tools/rust-installer",
- "src/tools/cargo",
- "src/tools/miri",
- "library/backtrace",
- "library/stdarch",
- ];
+ let rust_submodules =
+ ["src/tools/rust-installer", "src/tools/cargo", "library/backtrace", "library/stdarch"];
for s in rust_submodules {
build.update_submodule(Path::new(s));
}
@@ -574,7 +578,9 @@ impl Build {
// NOTE: The check for the empty directory is here because when running x.py the first time,
// the submodule won't be checked out. Check it out now so we can build it.
- if !channel::GitInfo::new(false, &absolute_path).is_git() && !dir_is_empty(&absolute_path) {
+ if !channel::GitInfo::new(false, &absolute_path).is_managed_git_subrepository()
+ && !dir_is_empty(&absolute_path)
+ {
return;
}
@@ -645,7 +651,7 @@ impl Build {
// Sample output: `submodule.src/rust-installer.path src/tools/rust-installer`
let submodule = Path::new(line.splitn(2, ' ').nth(1).unwrap());
// Don't update the submodule unless it's already been cloned.
- if channel::GitInfo::new(false, submodule).is_git() {
+ if channel::GitInfo::new(false, submodule).is_managed_git_subrepository() {
self.update_submodule(submodule);
}
}
@@ -671,6 +677,9 @@ impl Build {
return setup::setup(&self.config, *profile);
}
+ // Download rustfmt early so that it can be used in rust-analyzer configs.
+ let _ = &builder::Builder::new(&self).initial_rustfmt();
+
{
let builder = builder::Builder::new(&self);
if let Some(path) = builder.paths.get(0) {
@@ -825,6 +834,11 @@ impl Build {
self.out.join(&*target.triple).join("doc")
}
+ /// Output directory for all JSON-formatted documentation for a target
+ fn json_doc_out(&self, target: TargetSelection) -> PathBuf {
+ self.out.join(&*target.triple).join("json-doc")
+ }
+
fn test_out(&self, target: TargetSelection) -> PathBuf {
self.out.join(&*target.triple).join("test")
}
@@ -1253,7 +1267,7 @@ impl Build {
match &self.config.channel[..] {
"stable" => num.to_string(),
"beta" => {
- if self.rust_info.is_git() && !self.config.ignore_git {
+ if self.rust_info.is_managed_git_subrepository() && !self.config.ignore_git {
format!("{}-beta.{}", num, self.beta_prerelease_version())
} else {
format!("{}-beta", num)
@@ -1307,10 +1321,6 @@ impl Build {
self.package_vers(&self.version)
}
- fn llvm_link_tools_dynamically(&self, target: TargetSelection) -> bool {
- target.contains("linux-gnu") || target.contains("apple-darwin")
- }
-
/// Returns the `version` string associated with this compiler for Rust
/// itself.
///
diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
index fc3bfaf1b..2f856c276 100644
--- a/src/bootstrap/native.rs
+++ b/src/bootstrap/native.rs
@@ -16,7 +16,9 @@ use std::io;
use std::path::{Path, PathBuf};
use std::process::Command;
+use crate::bolt::{instrument_with_bolt_inplace, optimize_library_with_bolt_inplace};
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
+use crate::channel;
use crate::config::TargetSelection;
use crate::util::get_clang_cl_resource_dir;
use crate::util::{self, exe, output, program_out_of_date, t, up_to_date};
@@ -115,24 +117,29 @@ pub fn prebuilt_llvm_config(
}
/// This retrieves the LLVM sha we *want* to use, according to git history.
-pub(crate) fn detect_llvm_sha(config: &crate::config::Config) -> String {
- let mut rev_list = config.git();
- rev_list.args(&[
- PathBuf::from("rev-list"),
- format!("--author={}", config.stage0_metadata.config.git_merge_commit_email).into(),
- "-n1".into(),
- "--first-parent".into(),
- "HEAD".into(),
- "--".into(),
- config.src.join("src/llvm-project"),
- config.src.join("src/bootstrap/download-ci-llvm-stamp"),
- // the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
- config.src.join("src/version"),
- ]);
- let llvm_sha = output(&mut rev_list);
- let llvm_sha = llvm_sha.trim();
-
- if llvm_sha == "" {
+pub(crate) fn detect_llvm_sha(config: &crate::config::Config, is_git: bool) -> String {
+ let llvm_sha = if is_git {
+ let mut rev_list = config.git();
+ rev_list.args(&[
+ PathBuf::from("rev-list"),
+ format!("--author={}", config.stage0_metadata.config.git_merge_commit_email).into(),
+ "-n1".into(),
+ "--first-parent".into(),
+ "HEAD".into(),
+ "--".into(),
+ config.src.join("src/llvm-project"),
+ config.src.join("src/bootstrap/download-ci-llvm-stamp"),
+ // the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
+ config.src.join("src/version"),
+ ]);
+ output(&mut rev_list).trim().to_owned()
+ } else if let Some(info) = channel::read_commit_info_file(&config.src) {
+ info.sha.trim().to_owned()
+ } else {
+ "".to_owned()
+ };
+
+ if &llvm_sha == "" {
eprintln!("error: could not find commit hash for downloading LLVM");
eprintln!("help: maybe your repository history is too shallow?");
eprintln!("help: consider disabling `download-ci-llvm`");
@@ -140,7 +147,7 @@ pub(crate) fn detect_llvm_sha(config: &crate::config::Config) -> String {
panic!();
}
- llvm_sha.to_owned()
+ llvm_sha
}
/// Returns whether the CI-found LLVM is currently usable.
@@ -194,7 +201,9 @@ pub(crate) fn is_ci_llvm_available(config: &crate::config::Config, asserts: bool
}
if crate::util::CiEnv::is_ci() {
- let llvm_sha = detect_llvm_sha(config);
+ // We assume we have access to git, so it's okay to unconditionally pass
+ // `true` here.
+ let llvm_sha = detect_llvm_sha(config, true);
let head_sha = output(config.git().arg("rev-parse").arg("HEAD"));
let head_sha = head_sha.trim();
if llvm_sha == head_sha {
@@ -215,7 +224,7 @@ pub(crate) fn maybe_download_ci_llvm(builder: &Builder<'_>) {
}
let llvm_root = config.ci_llvm_root();
let llvm_stamp = llvm_root.join(".llvm-stamp");
- let llvm_sha = detect_llvm_sha(&config);
+ let llvm_sha = detect_llvm_sha(&config, builder.rust_info.is_managed_git_subrepository());
let key = format!("{}{}", llvm_sha, config.llvm_assertions);
if program_out_of_date(&llvm_stamp, &key) && !config.dry_run {
download_ci_llvm(builder, &llvm_sha);
@@ -260,8 +269,8 @@ fn download_ci_llvm(builder: &Builder<'_>, llvm_sha: &str) {
} else {
&builder.config.stage0_metadata.config.artifacts_server
};
- let version = builder.config.artifact_version_part(llvm_sha);
- let filename = format!("rust-dev-{}-{}.tar.xz", version, builder.build.build.triple);
+ let channel = builder.config.artifact_channel(builder, llvm_sha);
+ let filename = format!("rust-dev-{}-{}.tar.xz", channel, builder.build.build.triple);
let tarball = rustc_cache.join(&filename);
if !tarball.exists() {
let help_on_error = "error: failed to download llvm from ci
@@ -395,6 +404,12 @@ impl Step for Llvm {
if let Some(path) = builder.config.llvm_profile_use.as_ref() {
cfg.define("LLVM_PROFDATA_FILE", &path);
}
+ if builder.config.llvm_bolt_profile_generate
+ || builder.config.llvm_bolt_profile_use.is_some()
+ {
+ // Relocations are required for BOLT to work.
+ ldflags.push_all("-Wl,-q");
+ }
// Disable zstd to avoid a dependency on libzstd.so.
cfg.define("LLVM_ENABLE_ZSTD", "OFF");
@@ -423,12 +438,7 @@ impl Step for Llvm {
// which saves both memory during parallel links and overall disk space
// for the tools. We don't do this on every platform as it doesn't work
// equally well everywhere.
- //
- // If we're not linking rustc to a dynamic LLVM, though, then don't link
- // tools to it.
- let llvm_link_shared =
- builder.llvm_link_tools_dynamically(target) && builder.llvm_link_shared();
- if llvm_link_shared {
+ if builder.llvm_link_shared() {
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
}
@@ -494,18 +504,18 @@ impl Step for Llvm {
// https://llvm.org/docs/HowToCrossCompileLLVM.html
if target != builder.config.build {
- builder.ensure(Llvm { target: builder.config.build });
- // FIXME: if the llvm root for the build triple is overridden then we
- // should use llvm-tblgen from there, also should verify that it
- // actually exists most of the time in normal installs of LLVM.
- let host_bin = builder.llvm_out(builder.config.build).join("bin");
- cfg.define("LLVM_TABLEGEN", host_bin.join("llvm-tblgen").with_extension(EXE_EXTENSION));
- // LLVM_NM is required for cross compiling using MSVC
- cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION));
- cfg.define(
- "LLVM_CONFIG_PATH",
- host_bin.join("llvm-config").with_extension(EXE_EXTENSION),
- );
+ let llvm_config = builder.ensure(Llvm { target: builder.config.build });
+ if !builder.config.dry_run {
+ let llvm_bindir = output(Command::new(&llvm_config).arg("--bindir"));
+ let host_bin = Path::new(llvm_bindir.trim());
+ cfg.define(
+ "LLVM_TABLEGEN",
+ host_bin.join("llvm-tblgen").with_extension(EXE_EXTENSION),
+ );
+ // LLVM_NM is required for cross compiling using MSVC
+ cfg.define("LLVM_NM", host_bin.join("llvm-nm").with_extension(EXE_EXTENSION));
+ }
+ cfg.define("LLVM_CONFIG_PATH", llvm_config);
if builder.config.llvm_clang {
let build_bin = builder.llvm_out(builder.config.build).join("build").join("bin");
let clang_tblgen = build_bin.join("clang-tblgen").with_extension(EXE_EXTENSION);
@@ -553,7 +563,7 @@ impl Step for Llvm {
// libLLVM.dylib will be built. However, llvm-config will still look
// for a versioned path like libLLVM-14.dylib. Manually create a symbolic
// link to make llvm-config happy.
- if llvm_link_shared && target.contains("apple-darwin") {
+ if builder.llvm_link_shared() && target.contains("apple-darwin") {
let mut cmd = Command::new(&build_llvm_config);
let version = output(cmd.arg("--version"));
let major = version.split('.').next().unwrap();
@@ -568,12 +578,34 @@ impl Step for Llvm {
}
}
+ // After LLVM is built, we modify (instrument or optimize) the libLLVM.so library file
+ // in place. This is fine, because currently we do not support incrementally rebuilding
+ // LLVM after a configuration change, so to rebuild it the build files have to be removed,
+ // which will also remove these modified files.
+ if builder.config.llvm_bolt_profile_generate {
+ instrument_with_bolt_inplace(&get_built_llvm_lib_path(&build_llvm_config));
+ }
+ if let Some(path) = &builder.config.llvm_bolt_profile_use {
+ optimize_library_with_bolt_inplace(
+ &get_built_llvm_lib_path(&build_llvm_config),
+ &Path::new(path),
+ );
+ }
+
t!(stamp.write());
build_llvm_config
}
}
+/// Returns path to a built LLVM library (libLLVM.so).
+/// Assumes that we have built LLVM into a single library file.
+fn get_built_llvm_lib_path(llvm_config_path: &Path) -> PathBuf {
+ let mut cmd = Command::new(llvm_config_path);
+ cmd.arg("--libfiles");
+ PathBuf::from(output(&mut cmd).trim())
+}
+
fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) {
if !builder.config.llvm_version_check {
return;
diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs
index cae41286f..e90551725 100644
--- a/src/bootstrap/sanity.rs
+++ b/src/bootstrap/sanity.rs
@@ -74,7 +74,7 @@ pub fn check(build: &mut Build) {
let mut cmd_finder = Finder::new();
// If we've got a git directory we're gonna need git to update
// submodules and learn about various other aspects.
- if build.rust_info.is_git() {
+ if build.rust_info.is_managed_git_subrepository() {
cmd_finder.must_have("git");
}
diff --git a/src/bootstrap/tarball.rs b/src/bootstrap/tarball.rs
index e30067a5c..d999b6c15 100644
--- a/src/bootstrap/tarball.rs
+++ b/src/bootstrap/tarball.rs
@@ -4,6 +4,7 @@ use std::{
};
use crate::builder::Builder;
+use crate::channel;
use crate::util::t;
#[derive(Copy, Clone)]
@@ -297,8 +298,9 @@ impl<'a> Tarball<'a> {
fn run(self, build_cli: impl FnOnce(&Tarball<'a>, &mut Command)) -> GeneratedTarball {
t!(std::fs::create_dir_all(&self.overlay_dir));
self.builder.create(&self.overlay_dir.join("version"), &self.overlay.version(self.builder));
- if let Some(sha) = self.builder.rust_sha() {
- self.builder.create(&self.overlay_dir.join("git-commit-hash"), &sha);
+ if let Some(info) = self.builder.rust_info.info() {
+ channel::write_commit_hash_file(&self.overlay_dir, &info.sha);
+ channel::write_commit_info_file(&self.overlay_dir, info);
}
for file in self.overlay.legal_and_readme() {
self.builder.install(&self.builder.src.join(file), &self.overlay_dir, 0o644);
diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs
index dd41f8453..791c35c36 100644
--- a/src/bootstrap/test.rs
+++ b/src/bootstrap/test.rs
@@ -23,7 +23,7 @@ use crate::toolstate::ToolState;
use crate::util::{self, add_link_lib_path, dylib_path, dylib_path_var, output, t};
use crate::{envify, CLang, DocTests, GitRepo, Mode};
-const ADB_TEST_DIR: &str = "/data/tmp/work";
+const ADB_TEST_DIR: &str = "/data/local/tmp/work";
/// The two modes of the test runner; tests or benchmarks.
#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
@@ -461,139 +461,158 @@ impl Step for RustDemangler {
pub struct Miri {
stage: u32,
host: TargetSelection,
+ target: TargetSelection,
}
impl Step for Miri {
type Output = ();
- const ONLY_HOSTS: bool = true;
+ const ONLY_HOSTS: bool = false;
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/tools/miri")
}
fn make_run(run: RunConfig<'_>) {
- run.builder.ensure(Miri { stage: run.builder.top_stage, host: run.target });
+ run.builder.ensure(Miri {
+ stage: run.builder.top_stage,
+ host: run.build_triple(),
+ target: run.target,
+ });
}
/// Runs `cargo test` for miri.
fn run(self, builder: &Builder<'_>) {
let stage = self.stage;
let host = self.host;
+ let target = self.target;
let compiler = builder.compiler(stage, host);
// We need the stdlib for the *next* stage, as it was built with this compiler that also built Miri.
// Except if we are at stage 2, the bootstrap loop is complete and we can stick with our current stage.
let compiler_std = builder.compiler(if stage < 2 { stage + 1 } else { stage }, host);
- let miri =
- builder.ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() });
- let cargo_miri = builder.ensure(tool::CargoMiri {
- compiler,
- target: self.host,
- extra_features: Vec::new(),
- });
+ let miri = builder
+ .ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() })
+ .expect("in-tree tool");
+ let _cargo_miri = builder
+ .ensure(tool::CargoMiri { compiler, target: self.host, extra_features: Vec::new() })
+ .expect("in-tree tool");
// The stdlib we need might be at a different stage. And just asking for the
// sysroot does not seem to populate it, so we do that first.
builder.ensure(compile::Std::new(compiler_std, host));
let sysroot = builder.sysroot(compiler_std);
- if let (Some(miri), Some(_cargo_miri)) = (miri, cargo_miri) {
- 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);
-
- let mut cargo = Command::from(cargo);
- if !try_run(builder, &mut cargo) {
- return;
- }
- // # Run `cargo miri setup`.
- let mut cargo = tool::prepare_tool_cargo(
- builder,
- compiler,
- Mode::ToolRustc,
- host,
- "run",
- "src/tools/miri/cargo-miri",
- SourceType::Submodule,
- &[],
- );
- cargo.add_rustc_lib_path(builder, compiler);
- cargo.arg("--").arg("miri").arg("setup");
-
- // Tell `cargo miri setup` where to find the sources.
- cargo.env("XARGO_RUST_SRC", builder.src.join("library"));
- // Tell it where to find Miri.
- cargo.env("MIRI", &miri);
- // Debug things.
- cargo.env("RUST_BACKTRACE", "1");
- // Let cargo-miri know where xargo ended up.
- cargo.env("XARGO_CHECK", builder.out.join("bin").join("xargo-check"));
-
- let mut cargo = Command::from(cargo);
- if !try_run(builder, &mut cargo) {
- return;
- }
+ // # Run `cargo miri setup` for the given target.
+ let mut cargo = tool::prepare_tool_cargo(
+ builder,
+ compiler,
+ Mode::ToolRustc,
+ host,
+ "run",
+ "src/tools/miri/cargo-miri",
+ SourceType::Submodule,
+ &[],
+ );
+ cargo.add_rustc_lib_path(builder, compiler);
+ cargo.arg("--").arg("miri").arg("setup");
+ cargo.arg("--target").arg(target.rustc_target_arg());
+
+ // Tell `cargo miri setup` where to find the sources.
+ cargo.env("MIRI_LIB_SRC", builder.src.join("library"));
+ // Tell it where to find Miri.
+ cargo.env("MIRI", &miri);
+ // Debug things.
+ cargo.env("RUST_BACKTRACE", "1");
+
+ let mut cargo = Command::from(cargo);
+ builder.run(&mut cargo);
+
+ // # Determine where Miri put its sysroot.
+ // To this end, we run `cargo miri setup --print-sysroot` and capture the output.
+ // (We do this separately from the above so that when the setup actually
+ // happens we get some output.)
+ // We re-use the `cargo` from above.
+ cargo.arg("--print-sysroot");
+
+ // FIXME: Is there a way in which we can re-use the usual `run` helpers?
+ let miri_sysroot = if builder.config.dry_run {
+ String::new()
+ } else {
+ builder.verbose(&format!("running: {:?}", cargo));
+ let out =
+ cargo.output().expect("We already ran `cargo miri setup` before and that worked");
+ assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
+ // Output is "<sysroot>\n".
+ let stdout = String::from_utf8(out.stdout)
+ .expect("`cargo miri setup` stdout is not valid UTF-8");
+ let sysroot = stdout.trim_end();
+ builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
+ sysroot.to_owned()
+ };
- // # Determine where Miri put its sysroot.
- // To this end, we run `cargo miri setup --print-sysroot` and capture the output.
- // (We do this separately from the above so that when the setup actually
- // happens we get some output.)
- // We re-use the `cargo` from above.
- cargo.arg("--print-sysroot");
-
- // FIXME: Is there a way in which we can re-use the usual `run` helpers?
- let miri_sysroot = if builder.config.dry_run {
- String::new()
- } else {
- builder.verbose(&format!("running: {:?}", cargo));
- let out = cargo
- .output()
- .expect("We already ran `cargo miri setup` before and that worked");
- assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
- // Output is "<sysroot>\n".
- let stdout = String::from_utf8(out.stdout)
- .expect("`cargo miri setup` stdout is not valid UTF-8");
- let sysroot = stdout.trim_end();
- builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
- sysroot.to_owned()
- };
-
- // # Run `cargo test`.
- let mut cargo = tool::prepare_tool_cargo(
- builder,
- compiler,
- Mode::ToolRustc,
- host,
- "test",
- "src/tools/miri",
- SourceType::Submodule,
- &[],
- );
- cargo.add_rustc_lib_path(builder, compiler);
-
- // miri tests need to know about the stage sysroot
- cargo.env("MIRI_SYSROOT", miri_sysroot);
- cargo.env("MIRI_HOST_SYSROOT", sysroot);
- cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
- cargo.env("MIRI", miri);
- // propagate --bless
- if builder.config.cmd.bless() {
- cargo.env("MIRI_BLESS", "Gesundheit");
- }
+ // # Run `cargo test`.
+ let mut cargo = tool::prepare_tool_cargo(
+ builder,
+ compiler,
+ Mode::ToolRustc,
+ host,
+ "test",
+ "src/tools/miri",
+ SourceType::Submodule,
+ &[],
+ );
+ cargo.add_rustc_lib_path(builder, compiler);
- cargo.arg("--").args(builder.config.cmd.test_args());
+ // miri tests need to know about the stage sysroot
+ cargo.env("MIRI_SYSROOT", &miri_sysroot);
+ cargo.env("MIRI_HOST_SYSROOT", sysroot);
+ cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
+ cargo.env("MIRI", &miri);
+ // propagate --bless
+ if builder.config.cmd.bless() {
+ cargo.env("MIRI_BLESS", "Gesundheit");
+ }
- let mut cargo = Command::from(cargo);
- if !try_run(builder, &mut cargo) {
- return;
- }
+ // Set the target.
+ cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
+ // Forward test filters.
+ cargo.arg("--").args(builder.config.cmd.test_args());
- // # Done!
- builder.save_toolstate("miri", ToolState::TestPass);
- } else {
- eprintln!("failed to test miri: could not build");
- }
+ let mut cargo = Command::from(cargo);
+ builder.run(&mut cargo);
+
+ // # Run `cargo miri test`.
+ // This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
+ // that we get the desired output), but that is sufficient to make sure that the libtest harness
+ // itself executes properly under Miri.
+ let mut cargo = tool::prepare_tool_cargo(
+ builder,
+ compiler,
+ Mode::ToolRustc,
+ host,
+ "run",
+ "src/tools/miri/cargo-miri",
+ SourceType::Submodule,
+ &[],
+ );
+ cargo.add_rustc_lib_path(builder, compiler);
+ cargo.arg("--").arg("miri").arg("test");
+ cargo
+ .arg("--manifest-path")
+ .arg(builder.src.join("src/tools/miri/test-cargo-miri/Cargo.toml"));
+ cargo.arg("--target").arg(target.rustc_target_arg());
+ cargo.arg("--tests"); // don't run doctests, they are too confused by the staging
+ cargo.arg("--").args(builder.config.cmd.test_args());
+
+ // Tell `cargo miri` where to find things.
+ cargo.env("MIRI_SYSROOT", &miri_sysroot);
+ cargo.env("MIRI_HOST_SYSROOT", sysroot);
+ cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
+ cargo.env("MIRI", &miri);
+ // Debug things.
+ cargo.env("RUST_BACKTRACE", "1");
+
+ let mut cargo = Command::from(cargo);
+ builder.run(&mut cargo);
}
}
@@ -1400,7 +1419,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
}
let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
- flags.push(builder.config.cmd.rustc_args().join(" "));
+ flags.extend(builder.config.cmd.rustc_args().iter().map(|s| s.to_string()));
if let Some(linker) = builder.linker(target) {
cmd.arg("--linker").arg(linker);
@@ -1409,12 +1428,16 @@ note: if you're sure you want to do this, please open an issue as to why. In the
let mut hostflags = flags.clone();
hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
hostflags.extend(builder.lld_flags(compiler.host));
- cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
+ for flag in hostflags {
+ cmd.arg("--host-rustcflags").arg(flag);
+ }
let mut targetflags = flags;
targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
targetflags.extend(builder.lld_flags(target));
- cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
+ for flag in targetflags {
+ cmd.arg("--target-rustcflags").arg(flag);
+ }
cmd.arg("--python").arg(builder.python());
diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs
index 7d4ed24b6..eec74b267 100644
--- a/src/bootstrap/tool.rs
+++ b/src/bootstrap/tool.rs
@@ -698,7 +698,7 @@ pub struct RustAnalyzer {
impl Step for RustAnalyzer {
type Output = Option<PathBuf>;
const DEFAULT: bool = true;
- const ONLY_HOSTS: bool = false;
+ const ONLY_HOSTS: bool = true;
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
let builder = run.builder;
@@ -742,18 +742,22 @@ pub struct RustAnalyzerProcMacroSrv {
impl Step for RustAnalyzerProcMacroSrv {
type Output = Option<PathBuf>;
const DEFAULT: bool = true;
- const ONLY_HOSTS: bool = false;
+ const ONLY_HOSTS: bool = true;
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
let builder = run.builder;
- run.path("src/tools/rust-analyzer").default_condition(
- builder.config.extended
- && builder
- .config
- .tools
- .as_ref()
- .map_or(true, |tools| tools.iter().any(|tool| tool == "rust-analyzer")),
- )
+
+ // Allow building `rust-analyzer-proc-macro-srv` both as part of the `rust-analyzer` and as a stand-alone tool.
+ run.path("src/tools/rust-analyzer")
+ .path("src/tools/rust-analyzer/crates/proc-macro-srv-cli")
+ .default_condition(
+ builder.config.extended
+ && builder.config.tools.as_ref().map_or(true, |tools| {
+ tools.iter().any(|tool| {
+ tool == "rust-analyzer" || tool == "rust-analyzer-proc-macro-srv"
+ })
+ }),
+ )
}
fn make_run(run: RunConfig<'_>) {
@@ -764,7 +768,7 @@ impl Step for RustAnalyzerProcMacroSrv {
}
fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
- builder.ensure(ToolBuild {
+ let path = builder.ensure(ToolBuild {
compiler: self.compiler,
target: self.target,
tool: "rust-analyzer-proc-macro-srv",
@@ -773,7 +777,15 @@ impl Step for RustAnalyzerProcMacroSrv {
extra_features: vec!["proc-macro-srv/sysroot-abi".to_owned()],
is_optional_tool: false,
source_type: SourceType::InTree,
- })
+ })?;
+
+ // Copy `rust-analyzer-proc-macro-srv` to `<sysroot>/libexec/`
+ // so that r-a can use it.
+ let libexec_path = builder.sysroot(self.compiler).join("libexec");
+ t!(fs::create_dir_all(&libexec_path));
+ builder.copy(&path, &libexec_path.join("rust-analyzer-proc-macro-srv"));
+
+ Some(path)
}
}
@@ -856,12 +868,12 @@ tool_extended!((self, builder),
Cargofmt, "src/tools/rustfmt", "cargo-fmt", stable=true, in_tree=true, {};
CargoClippy, "src/tools/clippy", "cargo-clippy", stable=true, in_tree=true, {};
Clippy, "src/tools/clippy", "clippy-driver", stable=true, in_tree=true, {};
- Miri, "src/tools/miri", "miri", stable=false, {};
- CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", stable=false, {};
- Rls, "src/tools/rls", "rls", stable=true, {};
+ Miri, "src/tools/miri", "miri", stable=false, in_tree=true, {};
+ CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", stable=false, in_tree=true, {};
// FIXME: tool_std is not quite right, we shouldn't allow nightly features.
// But `builder.cargo` doesn't know how to handle ToolBootstrap in stages other than 0,
// and this is close enough for now.
+ Rls, "src/tools/rls", "rls", stable=true, in_tree=true, tool_std=true, {};
RustDemangler, "src/tools/rust-demangler", "rust-demangler", stable=false, in_tree=true, tool_std=true, {};
Rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, in_tree=true, {};
);
diff --git a/src/bootstrap/toolstate.rs b/src/bootstrap/toolstate.rs
index f3a6759ab..1a1774432 100644
--- a/src/bootstrap/toolstate.rs
+++ b/src/bootstrap/toolstate.rs
@@ -77,7 +77,6 @@ static STABLE_TOOLS: &[(&str, &str)] = &[
// though, as otherwise we will be unable to file an issue if they start
// failing.
static NIGHTLY_TOOLS: &[(&str, &str)] = &[
- ("miri", "src/tools/miri"),
("embedded-book", "src/doc/embedded-book"),
// ("rustc-dev-guide", "src/doc/rustc-dev-guide"),
];
diff --git a/src/ci/docker/README.md b/src/ci/docker/README.md
index b71a348ab..ea236bee5 100644
--- a/src/ci/docker/README.md
+++ b/src/ci/docker/README.md
@@ -230,6 +230,112 @@ For targets: `aarch64-unknown-linux-gnu`
- C compiler > gcc version = 8.3.0
- C compiler > C++ = ENABLE -- to cross compile LLVM
+### `i586-linux-gnu.config`
+
+For targets: `i586-unknown-linux-gnu`
+
+- Path and misc options > Prefix directory = /x-tools/${CT\_TARGET}
+- Path and misc options > Patches origin = Bundled only
+- Target options > Target Architecture = x86
+- Target options > Architecture level = i586
+- Target options > Target CFLAGS = -Wa,-mrelax-relocations=no
+- Operating System > Target OS = linux
+- Operating System > Linux kernel version = 3.2.101
+- Binary utilities > Version of binutils = 2.32
+- Binary utilities > binutils extra config = --enable-compressed-debug-sections=none -- (\*)
+- C-library > glibc version = 2.17.0
+- C compiler > gcc version = 8.3.0
+- C compiler > C++ = ENABLE
+
+(\*) Compressed debug is enabled by default for gas (assembly) on Linux/x86 targets,
+ but that makes our `compiler_builtins` incompatible with binutils < 2.32.
+
+### `mips-linux-gnu.config`
+
+For targets: `mips-unknown-linux-gnu`
+
+- Path and misc options > Prefix directory = /x-tools/${CT\_TARGET}
+- Path and misc options > Use a mirror = ENABLE
+- Path and misc options > Base URL = https://ci-mirrors.rust-lang.org/rustc
+- Path and misc options > Patches origin = Bundled, then local
+- Path and misc options > Local patch directory = /tmp/patches
+- Target options > Target Architecture = mips
+- Target options > ABI = o32
+- Target options > Endianness = Big endian
+- Target options > Bitness = 32-bit
+- Target options > Architecture level = mips32r2
+- Operating System > Target OS = linux
+- Operating System > Linux kernel version = 4.4.174
+- Binary utilities > Version of binutils = 2.32
+- C-library > glibc version = 2.23
+- C compiler > gcc version = 8.3.0
+- C compiler > gcc extra config = --with-fp-32=xx --with-odd-spreg-32=no
+- C compiler > C++ = ENABLE -- to cross compile LLVM
+
+### `mipsel-linux-gnu.config`
+
+For targets: `mipsel-unknown-linux-gnu`
+
+- Path and misc options > Prefix directory = /x-tools/${CT\_TARGET}
+- Path and misc options > Use a mirror = ENABLE
+- Path and misc options > Base URL = https://ci-mirrors.rust-lang.org/rustc
+- Path and misc options > Patches origin = Bundled, then local
+- Path and misc options > Local patch directory = /tmp/patches
+- Target options > Target Architecture = mips
+- Target options > ABI = o32
+- Target options > Endianness = Little endian
+- Target options > Bitness = 32-bit
+- Target options > Architecture level = mips32r2
+- Operating System > Target OS = linux
+- Operating System > Linux kernel version = 4.4.174
+- Binary utilities > Version of binutils = 2.32
+- C-library > glibc version = 2.23
+- C compiler > gcc version = 8.3.0
+- C compiler > gcc extra config = --with-fp-32=xx --with-odd-spreg-32=no
+- C compiler > C++ = ENABLE -- to cross compile LLVM
+
+### `mips64-linux-gnu.config`
+
+For targets: `mips64-unknown-linux-gnuabi64`
+
+- Path and misc options > Prefix directory = /x-tools/${CT\_TARGET}
+- Path and misc options > Use a mirror = ENABLE
+- Path and misc options > Base URL = https://ci-mirrors.rust-lang.org/rustc
+- Path and misc options > Patches origin = Bundled, then local
+- Path and misc options > Local patch directory = /tmp/patches
+- Target options > Target Architecture = mips
+- Target options > ABI = n64
+- Target options > Endianness = Big endian
+- Target options > Bitness = 64-bit
+- Target options > Architecture level = mips64r2
+- Operating System > Target OS = linux
+- Operating System > Linux kernel version = 4.4.174
+- Binary utilities > Version of binutils = 2.32
+- C-library > glibc version = 2.23
+- C compiler > gcc version = 8.3.0
+- C compiler > C++ = ENABLE -- to cross compile LLVM
+
+### `mips64el-linux-gnu.config`
+
+For targets: `mips64el-unknown-linux-gnuabi64`
+
+- Path and misc options > Prefix directory = /x-tools/${CT\_TARGET}
+- Path and misc options > Use a mirror = ENABLE
+- Path and misc options > Base URL = https://ci-mirrors.rust-lang.org/rustc
+- Path and misc options > Patches origin = Bundled, then local
+- Path and misc options > Local patch directory = /tmp/patches
+- Target options > Target Architecture = mips
+- Target options > ABI = n64
+- Target options > Endianness = Little endian
+- Target options > Bitness = 64-bit
+- Target options > Architecture level = mips64r2
+- Operating System > Target OS = linux
+- Operating System > Linux kernel version = 4.4.174
+- Binary utilities > Version of binutils = 2.32
+- C-library > glibc version = 2.23
+- C compiler > gcc version = 8.3.0
+- C compiler > C++ = ENABLE -- to cross compile LLVM
+
### `powerpc-linux-gnu.config`
For targets: `powerpc-unknown-linux-gnu`
diff --git a/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/Dockerfile b/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/Dockerfile
index 5ddd3f180..637b5fa22 100644
--- a/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/Dockerfile
+++ b/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/Dockerfile
@@ -47,4 +47,6 @@ ENV RUST_CONFIGURE_ARGS --disable-jemalloc \
--set=$TARGET.cc=x86_64-unknown-haiku-gcc \
--set=$TARGET.cxx=x86_64-unknown-haiku-g++ \
--set=$TARGET.llvm-config=/bin/llvm-config-haiku
+ENV EXTERNAL_LLVM 1
+
ENV SCRIPT python3 ../x.py dist --host=$HOST --target=$HOST
diff --git a/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/Dockerfile b/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/Dockerfile
index b0d65428e..26eb69f2e 100644
--- a/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/Dockerfile
+++ b/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/Dockerfile
@@ -1,5 +1,6 @@
-FROM ubuntu:16.04
+FROM ubuntu:22.04
+ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
g++-multilib \
make \
@@ -17,6 +18,25 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libssl-dev \
pkg-config
+COPY scripts/cross-apt-packages.sh /scripts/
+RUN sh /scripts/cross-apt-packages.sh
+
+COPY scripts/crosstool-ng-1.24.sh /scripts/
+RUN sh /scripts/crosstool-ng-1.24.sh
+
+COPY scripts/rustbuild-setup.sh /scripts/
+RUN sh /scripts/rustbuild-setup.sh
+WORKDIR /tmp
+
+COPY host-x86_64/dist-i586-gnu-i586-i686-musl/i586-linux-gnu.config \
+ host-x86_64/dist-i586-gnu-i586-i686-musl/build-i586-gnu-toolchain.sh \
+ /tmp/
+RUN su rustbuild -c ./build-i586-gnu-toolchain.sh
+ENV PATH=$PATH:/x-tools/i586-unknown-linux-gnu/bin
+ENV \
+ CC_i586_unknown_linux_gnu=i586-unknown-linux-gnu-gcc \
+ AR_i586_unknown_linux_gnu=i586-unknown-linux-gnu-ar
+
WORKDIR /build/
COPY scripts/musl.sh /build/
RUN CC=gcc CFLAGS="-m32 -Wa,-mrelax-relocations=no" \
@@ -27,17 +47,20 @@ RUN CC=gcc CFLAGS="-m32 -Wa,-mrelax-relocations=no" \
bash musl.sh i586 --target=i586 && \
rm -rf /build
+# FIXME: musl really shouldn't be linking libgcc_s.so, as it's linked to glibc,
+# but it's required by src/test/ui/proc-macro/crt-static.rs. Ubuntu:16.04 gcc-5
+# had libgcc_s.so as a symlink to the absolute libgcc_s.so.1, but now it's an
+# ld-script that expects to find libgcc_s.so.1 in the library search path.
+# See also https://github.com/rust-lang/rust/issues/82521
+RUN ln -s /usr/lib32/libgcc_s.so.1 /musl-i686/lib/
+
COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh
-COPY scripts/cmake.sh /scripts/
-RUN /scripts/cmake.sh
-
ENV RUST_CONFIGURE_ARGS \
--musl-root-i586=/musl-i586 \
--musl-root-i686=/musl-i686 \
- --disable-docs \
- --set llvm.allow-old-toolchain
+ --disable-docs
# Newer binutils broke things on some vms/distros (i.e., linking against
# unknown relocs disabled by the following flag), so we need to go out of our
diff --git a/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/build-i586-gnu-toolchain.sh b/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/build-i586-gnu-toolchain.sh
new file mode 100755
index 000000000..ceab60cfb
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/build-i586-gnu-toolchain.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+set -ex
+
+hide_output() {
+ set +x
+ on_err="
+echo ERROR: An error was encountered with the build.
+cat /tmp/build.log
+exit 1
+"
+ trap "$on_err" ERR
+ bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
+ PING_LOOP_PID=$!
+ "$@" &> /tmp/build.log
+ rm /tmp/build.log
+ trap - ERR
+ kill $PING_LOOP_PID
+ set -x
+}
+
+mkdir build
+cd build
+cp ../i586-linux-gnu.config .config
+hide_output ct-ng build
+cd ..
+rm -rf build
diff --git a/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/i586-linux-gnu.config b/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/i586-linux-gnu.config
new file mode 100644
index 000000000..cdbd52d23
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-i586-gnu-i586-i686-musl/i586-linux-gnu.config
@@ -0,0 +1,726 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# crosstool-NG Configuration
+#
+CT_CONFIGURE_has_static_link=y
+CT_CONFIGURE_has_cxx11=y
+CT_CONFIGURE_has_wget=y
+CT_CONFIGURE_has_curl=y
+CT_CONFIGURE_has_make_3_81_or_newer=y
+CT_CONFIGURE_has_make_4_0_or_newer=y
+CT_CONFIGURE_has_libtool_2_4_or_newer=y
+CT_CONFIGURE_has_libtoolize_2_4_or_newer=y
+CT_CONFIGURE_has_autoconf_2_65_or_newer=y
+CT_CONFIGURE_has_autoreconf_2_65_or_newer=y
+CT_CONFIGURE_has_automake_1_15_or_newer=y
+CT_CONFIGURE_has_gnu_m4_1_4_12_or_newer=y
+CT_CONFIGURE_has_python_3_4_or_newer=y
+CT_CONFIGURE_has_bison_2_7_or_newer=y
+CT_CONFIGURE_has_python=y
+CT_CONFIGURE_has_git=y
+CT_CONFIGURE_has_md5sum=y
+CT_CONFIGURE_has_sha1sum=y
+CT_CONFIGURE_has_sha256sum=y
+CT_CONFIGURE_has_sha512sum=y
+CT_CONFIGURE_has_install_with_strip_program=y
+CT_CONFIG_VERSION_CURRENT="3"
+CT_CONFIG_VERSION="3"
+CT_MODULES=y
+
+#
+# Paths and misc options
+#
+
+#
+# crosstool-NG behavior
+#
+# CT_OBSOLETE is not set
+# CT_EXPERIMENTAL is not set
+# CT_DEBUG_CT is not set
+
+#
+# Paths
+#
+CT_LOCAL_TARBALLS_DIR="${HOME}/src"
+CT_SAVE_TARBALLS=y
+# CT_TARBALLS_BUILDROOT_LAYOUT is not set
+CT_WORK_DIR="${CT_TOP_DIR}/.build"
+CT_BUILD_TOP_DIR="${CT_WORK_DIR:-${CT_TOP_DIR}/.build}/${CT_HOST:+HOST-${CT_HOST}/}${CT_TARGET}"
+CT_PREFIX_DIR="/x-tools/${CT_TARGET}"
+CT_RM_RF_PREFIX_DIR=y
+CT_REMOVE_DOCS=y
+CT_INSTALL_LICENSES=y
+CT_PREFIX_DIR_RO=y
+CT_STRIP_HOST_TOOLCHAIN_EXECUTABLES=y
+# CT_STRIP_TARGET_TOOLCHAIN_EXECUTABLES is not set
+
+#
+# Downloading
+#
+CT_DOWNLOAD_AGENT_WGET=y
+# CT_DOWNLOAD_AGENT_CURL is not set
+# CT_DOWNLOAD_AGENT_NONE is not set
+# CT_FORBID_DOWNLOAD is not set
+# CT_FORCE_DOWNLOAD is not set
+CT_CONNECT_TIMEOUT=10
+CT_DOWNLOAD_WGET_OPTIONS="--passive-ftp --tries=3 -nc --progress=dot:binary"
+# CT_ONLY_DOWNLOAD is not set
+CT_USE_MIRROR=y
+# CT_FORCE_MIRROR is not set
+CT_MIRROR_BASE_URL="https://ci-mirrors.rust-lang.org/rustc"
+CT_VERIFY_DOWNLOAD_DIGEST=y
+CT_VERIFY_DOWNLOAD_DIGEST_SHA512=y
+# CT_VERIFY_DOWNLOAD_DIGEST_SHA256 is not set
+# CT_VERIFY_DOWNLOAD_DIGEST_SHA1 is not set
+# CT_VERIFY_DOWNLOAD_DIGEST_MD5 is not set
+CT_VERIFY_DOWNLOAD_DIGEST_ALG="sha512"
+# CT_VERIFY_DOWNLOAD_SIGNATURE is not set
+
+#
+# Extracting
+#
+# CT_FORCE_EXTRACT is not set
+CT_OVERRIDE_CONFIG_GUESS_SUB=y
+# CT_ONLY_EXTRACT is not set
+CT_PATCH_BUNDLED=y
+# CT_PATCH_BUNDLED_LOCAL is not set
+CT_PATCH_ORDER="bundled"
+
+#
+# Build behavior
+#
+CT_PARALLEL_JOBS=0
+CT_LOAD=""
+CT_USE_PIPES=y
+CT_EXTRA_CFLAGS_FOR_BUILD=""
+CT_EXTRA_LDFLAGS_FOR_BUILD=""
+CT_EXTRA_CFLAGS_FOR_HOST=""
+CT_EXTRA_LDFLAGS_FOR_HOST=""
+# CT_CONFIG_SHELL_SH is not set
+# CT_CONFIG_SHELL_ASH is not set
+CT_CONFIG_SHELL_BASH=y
+# CT_CONFIG_SHELL_CUSTOM is not set
+CT_CONFIG_SHELL="${bash}"
+
+#
+# Logging
+#
+# CT_LOG_ERROR is not set
+# CT_LOG_WARN is not set
+# CT_LOG_INFO is not set
+CT_LOG_EXTRA=y
+# CT_LOG_ALL is not set
+# CT_LOG_DEBUG is not set
+CT_LOG_LEVEL_MAX="EXTRA"
+# CT_LOG_SEE_TOOLS_WARN is not set
+CT_LOG_PROGRESS_BAR=y
+CT_LOG_TO_FILE=y
+CT_LOG_FILE_COMPRESS=y
+
+#
+# Target options
+#
+# CT_ARCH_ALPHA is not set
+# CT_ARCH_ARC is not set
+# CT_ARCH_ARM is not set
+# CT_ARCH_AVR is not set
+# CT_ARCH_M68K is not set
+# CT_ARCH_MIPS is not set
+# CT_ARCH_NIOS2 is not set
+# CT_ARCH_POWERPC is not set
+# CT_ARCH_S390 is not set
+# CT_ARCH_SH is not set
+# CT_ARCH_SPARC is not set
+CT_ARCH_X86=y
+# CT_ARCH_XTENSA is not set
+CT_ARCH="x86"
+CT_ARCH_CHOICE_KSYM="X86"
+CT_ARCH_CPU=""
+CT_ARCH_TUNE=""
+CT_ARCH_X86_SHOW=y
+
+#
+# Options for x86
+#
+CT_ARCH_X86_PKG_KSYM=""
+CT_ALL_ARCH_CHOICES="ALPHA ARC ARM AVR M68K MICROBLAZE MIPS MOXIE MSP430 NIOS2 POWERPC RISCV S390 SH SPARC X86 XTENSA"
+CT_ARCH_SUFFIX=""
+# CT_OMIT_TARGET_VENDOR is not set
+
+#
+# Generic target options
+#
+# CT_MULTILIB is not set
+CT_DEMULTILIB=y
+CT_ARCH_USE_MMU=y
+CT_ARCH_SUPPORTS_32=y
+CT_ARCH_SUPPORTS_64=y
+CT_ARCH_DEFAULT_32=y
+CT_ARCH_BITNESS=32
+CT_ARCH_32=y
+# CT_ARCH_64 is not set
+
+#
+# Target optimisations
+#
+CT_ARCH_SUPPORTS_WITH_ARCH=y
+CT_ARCH_SUPPORTS_WITH_CPU=y
+CT_ARCH_SUPPORTS_WITH_TUNE=y
+CT_ARCH_ARCH="i586"
+CT_TARGET_CFLAGS="-Wa,-mrelax-relocations=no"
+CT_TARGET_LDFLAGS=""
+
+#
+# Toolchain options
+#
+
+#
+# General toolchain options
+#
+CT_FORCE_SYSROOT=y
+CT_USE_SYSROOT=y
+CT_SYSROOT_NAME="sysroot"
+CT_SYSROOT_DIR_PREFIX=""
+CT_WANTS_STATIC_LINK=y
+CT_WANTS_STATIC_LINK_CXX=y
+# CT_STATIC_TOOLCHAIN is not set
+CT_SHOW_CT_VERSION=y
+CT_TOOLCHAIN_PKGVERSION=""
+CT_TOOLCHAIN_BUGURL=""
+
+#
+# Tuple completion and aliasing
+#
+CT_TARGET_VENDOR="unknown"
+CT_TARGET_ALIAS_SED_EXPR=""
+CT_TARGET_ALIAS=""
+
+#
+# Toolchain type
+#
+CT_CROSS=y
+# CT_CANADIAN is not set
+CT_TOOLCHAIN_TYPE="cross"
+
+#
+# Build system
+#
+CT_BUILD=""
+CT_BUILD_PREFIX=""
+CT_BUILD_SUFFIX=""
+
+#
+# Misc options
+#
+# CT_TOOLCHAIN_ENABLE_NLS is not set
+
+#
+# Operating System
+#
+CT_KERNEL_SUPPORTS_SHARED_LIBS=y
+# CT_KERNEL_BARE_METAL is not set
+CT_KERNEL_LINUX=y
+CT_KERNEL="linux"
+CT_KERNEL_CHOICE_KSYM="LINUX"
+CT_KERNEL_LINUX_SHOW=y
+
+#
+# Options for linux
+#
+CT_KERNEL_LINUX_PKG_KSYM="LINUX"
+CT_LINUX_DIR_NAME="linux"
+CT_LINUX_PKG_NAME="linux"
+CT_LINUX_SRC_RELEASE=y
+CT_LINUX_PATCH_ORDER="global"
+# CT_LINUX_V_4_20 is not set
+# CT_LINUX_V_4_19 is not set
+# CT_LINUX_V_4_18 is not set
+# CT_LINUX_V_4_17 is not set
+# CT_LINUX_V_4_16 is not set
+# CT_LINUX_V_4_15 is not set
+# CT_LINUX_V_4_14 is not set
+# CT_LINUX_V_4_13 is not set
+# CT_LINUX_V_4_12 is not set
+# CT_LINUX_V_4_11 is not set
+# CT_LINUX_V_4_10 is not set
+# CT_LINUX_V_4_9 is not set
+# CT_LINUX_V_4_4 is not set
+# CT_LINUX_V_4_1 is not set
+# CT_LINUX_V_3_16 is not set
+# CT_LINUX_V_3_13 is not set
+# CT_LINUX_V_3_12 is not set
+# CT_LINUX_V_3_10 is not set
+# CT_LINUX_V_3_4 is not set
+CT_LINUX_V_3_2=y
+# CT_LINUX_V_2_6_32 is not set
+# CT_LINUX_NO_VERSIONS is not set
+CT_LINUX_VERSION="3.2.101"
+CT_LINUX_MIRRORS="$(CT_Mirrors kernel.org linux ${CT_LINUX_VERSION})"
+CT_LINUX_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_LINUX_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_LINUX_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_LINUX_SIGNATURE_FORMAT="unpacked/.sign"
+CT_LINUX_4_8_or_older=y
+CT_LINUX_older_than_4_8=y
+CT_LINUX_3_7_or_older=y
+CT_LINUX_older_than_3_7=y
+CT_LINUX_later_than_3_2=y
+CT_LINUX_3_2_or_later=y
+CT_KERNEL_LINUX_VERBOSITY_0=y
+# CT_KERNEL_LINUX_VERBOSITY_1 is not set
+# CT_KERNEL_LINUX_VERBOSITY_2 is not set
+CT_KERNEL_LINUX_VERBOSE_LEVEL=0
+CT_KERNEL_LINUX_INSTALL_CHECK=y
+CT_ALL_KERNEL_CHOICES="BARE_METAL LINUX WINDOWS"
+
+#
+# Common kernel options
+#
+CT_SHARED_LIBS=y
+
+#
+# Binary utilities
+#
+CT_ARCH_BINFMT_ELF=y
+CT_BINUTILS_BINUTILS=y
+CT_BINUTILS="binutils"
+CT_BINUTILS_CHOICE_KSYM="BINUTILS"
+CT_BINUTILS_BINUTILS_SHOW=y
+
+#
+# Options for binutils
+#
+CT_BINUTILS_BINUTILS_PKG_KSYM="BINUTILS"
+CT_BINUTILS_DIR_NAME="binutils"
+CT_BINUTILS_USE_GNU=y
+CT_BINUTILS_USE="BINUTILS"
+CT_BINUTILS_PKG_NAME="binutils"
+CT_BINUTILS_SRC_RELEASE=y
+CT_BINUTILS_PATCH_ORDER="global"
+CT_BINUTILS_V_2_32=y
+# CT_BINUTILS_V_2_31 is not set
+# CT_BINUTILS_V_2_30 is not set
+# CT_BINUTILS_V_2_29 is not set
+# CT_BINUTILS_V_2_28 is not set
+# CT_BINUTILS_V_2_27 is not set
+# CT_BINUTILS_V_2_26 is not set
+# CT_BINUTILS_NO_VERSIONS is not set
+CT_BINUTILS_VERSION="2.32"
+CT_BINUTILS_MIRRORS="$(CT_Mirrors GNU binutils) $(CT_Mirrors sourceware binutils/releases)"
+CT_BINUTILS_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_BINUTILS_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_BINUTILS_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_BINUTILS_SIGNATURE_FORMAT="packed/.sig"
+CT_BINUTILS_later_than_2_30=y
+CT_BINUTILS_2_30_or_later=y
+CT_BINUTILS_later_than_2_27=y
+CT_BINUTILS_2_27_or_later=y
+CT_BINUTILS_later_than_2_25=y
+CT_BINUTILS_2_25_or_later=y
+CT_BINUTILS_later_than_2_23=y
+CT_BINUTILS_2_23_or_later=y
+
+#
+# GNU binutils
+#
+CT_BINUTILS_HAS_HASH_STYLE=y
+CT_BINUTILS_HAS_GOLD=y
+CT_BINUTILS_HAS_PLUGINS=y
+CT_BINUTILS_HAS_PKGVERSION_BUGURL=y
+CT_BINUTILS_GOLD_SUPPORTS_ARCH=y
+CT_BINUTILS_GOLD_SUPPORT=y
+CT_BINUTILS_FORCE_LD_BFD_DEFAULT=y
+CT_BINUTILS_LINKER_LD=y
+# CT_BINUTILS_LINKER_LD_GOLD is not set
+CT_BINUTILS_LINKERS_LIST="ld"
+CT_BINUTILS_LINKER_DEFAULT="bfd"
+# CT_BINUTILS_PLUGINS is not set
+CT_BINUTILS_RELRO=m
+CT_BINUTILS_EXTRA_CONFIG_ARRAY="--enable-compressed-debug-sections=none"
+# CT_BINUTILS_FOR_TARGET is not set
+CT_ALL_BINUTILS_CHOICES="BINUTILS"
+
+#
+# C-library
+#
+CT_LIBC_GLIBC=y
+# CT_LIBC_UCLIBC is not set
+CT_LIBC="glibc"
+CT_LIBC_CHOICE_KSYM="GLIBC"
+CT_THREADS="nptl"
+CT_LIBC_GLIBC_SHOW=y
+
+#
+# Options for glibc
+#
+CT_LIBC_GLIBC_PKG_KSYM="GLIBC"
+CT_GLIBC_DIR_NAME="glibc"
+CT_GLIBC_USE_GNU=y
+CT_GLIBC_USE="GLIBC"
+CT_GLIBC_PKG_NAME="glibc"
+CT_GLIBC_SRC_RELEASE=y
+CT_GLIBC_PATCH_ORDER="global"
+# CT_GLIBC_V_2_29 is not set
+# CT_GLIBC_V_2_28 is not set
+# CT_GLIBC_V_2_27 is not set
+# CT_GLIBC_V_2_26 is not set
+# CT_GLIBC_V_2_25 is not set
+# CT_GLIBC_V_2_24 is not set
+# CT_GLIBC_V_2_23 is not set
+# CT_GLIBC_V_2_19 is not set
+CT_GLIBC_V_2_17=y
+# CT_GLIBC_V_2_12_1 is not set
+# CT_GLIBC_NO_VERSIONS is not set
+CT_GLIBC_VERSION="2.17"
+CT_GLIBC_MIRRORS="$(CT_Mirrors GNU glibc)"
+CT_GLIBC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GLIBC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GLIBC_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_GLIBC_SIGNATURE_FORMAT="packed/.sig"
+CT_GLIBC_2_29_or_older=y
+CT_GLIBC_older_than_2_29=y
+CT_GLIBC_2_27_or_older=y
+CT_GLIBC_older_than_2_27=y
+CT_GLIBC_2_26_or_older=y
+CT_GLIBC_older_than_2_26=y
+CT_GLIBC_2_25_or_older=y
+CT_GLIBC_older_than_2_25=y
+CT_GLIBC_2_24_or_older=y
+CT_GLIBC_older_than_2_24=y
+CT_GLIBC_2_23_or_older=y
+CT_GLIBC_older_than_2_23=y
+CT_GLIBC_2_20_or_older=y
+CT_GLIBC_older_than_2_20=y
+CT_GLIBC_2_17_or_later=y
+CT_GLIBC_2_17_or_older=y
+CT_GLIBC_later_than_2_14=y
+CT_GLIBC_2_14_or_later=y
+CT_GLIBC_DEP_KERNEL_HEADERS_VERSION=y
+CT_GLIBC_DEP_BINUTILS=y
+CT_GLIBC_DEP_GCC=y
+CT_GLIBC_DEP_PYTHON=y
+CT_GLIBC_HAS_NPTL_ADDON=y
+CT_GLIBC_HAS_PORTS_ADDON=y
+CT_GLIBC_HAS_LIBIDN_ADDON=y
+CT_GLIBC_USE_NPTL_ADDON=y
+# CT_GLIBC_USE_LIBIDN_ADDON is not set
+CT_GLIBC_HAS_OBSOLETE_RPC=y
+CT_GLIBC_EXTRA_CONFIG_ARRAY=""
+CT_GLIBC_CONFIGPARMS=""
+CT_GLIBC_EXTRA_CFLAGS=""
+CT_GLIBC_ENABLE_OBSOLETE_RPC=y
+# CT_GLIBC_DISABLE_VERSIONING is not set
+CT_GLIBC_OLDEST_ABI=""
+CT_GLIBC_FORCE_UNWIND=y
+# CT_GLIBC_LOCALES is not set
+# CT_GLIBC_KERNEL_VERSION_NONE is not set
+CT_GLIBC_KERNEL_VERSION_AS_HEADERS=y
+# CT_GLIBC_KERNEL_VERSION_CHOSEN is not set
+CT_GLIBC_MIN_KERNEL="3.2.101"
+CT_ALL_LIBC_CHOICES="AVR_LIBC BIONIC GLIBC MINGW_W64 MOXIEBOX MUSL NEWLIB NONE UCLIBC"
+CT_LIBC_SUPPORT_THREADS_ANY=y
+CT_LIBC_SUPPORT_THREADS_NATIVE=y
+
+#
+# Common C library options
+#
+CT_THREADS_NATIVE=y
+# CT_CREATE_LDSO_CONF is not set
+CT_LIBC_XLDD=y
+
+#
+# C compiler
+#
+CT_CC_CORE_PASSES_NEEDED=y
+CT_CC_CORE_PASS_1_NEEDED=y
+CT_CC_CORE_PASS_2_NEEDED=y
+CT_CC_SUPPORT_CXX=y
+CT_CC_SUPPORT_FORTRAN=y
+CT_CC_SUPPORT_ADA=y
+CT_CC_SUPPORT_OBJC=y
+CT_CC_SUPPORT_OBJCXX=y
+CT_CC_SUPPORT_GOLANG=y
+CT_CC_GCC=y
+CT_CC="gcc"
+CT_CC_CHOICE_KSYM="GCC"
+CT_CC_GCC_SHOW=y
+
+#
+# Options for gcc
+#
+CT_CC_GCC_PKG_KSYM="GCC"
+CT_GCC_DIR_NAME="gcc"
+CT_GCC_USE_GNU=y
+CT_GCC_USE="GCC"
+CT_GCC_PKG_NAME="gcc"
+CT_GCC_SRC_RELEASE=y
+CT_GCC_PATCH_ORDER="global"
+CT_GCC_V_8=y
+# CT_GCC_V_7 is not set
+# CT_GCC_V_6 is not set
+# CT_GCC_V_5 is not set
+# CT_GCC_V_4_9 is not set
+# CT_GCC_NO_VERSIONS is not set
+CT_GCC_VERSION="8.3.0"
+CT_GCC_MIRRORS="$(CT_Mirrors GNU gcc/gcc-${CT_GCC_VERSION}) $(CT_Mirrors sourceware gcc/releases/gcc-${CT_GCC_VERSION})"
+CT_GCC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GCC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GCC_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_GCC_SIGNATURE_FORMAT=""
+CT_GCC_later_than_7=y
+CT_GCC_7_or_later=y
+CT_GCC_later_than_6=y
+CT_GCC_6_or_later=y
+CT_GCC_later_than_5=y
+CT_GCC_5_or_later=y
+CT_GCC_later_than_4_9=y
+CT_GCC_4_9_or_later=y
+CT_GCC_later_than_4_8=y
+CT_GCC_4_8_or_later=y
+CT_CC_GCC_HAS_LIBMPX=y
+CT_CC_GCC_ENABLE_CXX_FLAGS=""
+CT_CC_GCC_CORE_EXTRA_CONFIG_ARRAY=""
+CT_CC_GCC_EXTRA_CONFIG_ARRAY=""
+CT_CC_GCC_STATIC_LIBSTDCXX=y
+# CT_CC_GCC_SYSTEM_ZLIB is not set
+CT_CC_GCC_CONFIG_TLS=m
+
+#
+# Optimisation features
+#
+CT_CC_GCC_USE_GRAPHITE=y
+CT_CC_GCC_USE_LTO=y
+
+#
+# Settings for libraries running on target
+#
+CT_CC_GCC_ENABLE_TARGET_OPTSPACE=y
+# CT_CC_GCC_LIBMUDFLAP is not set
+# CT_CC_GCC_LIBGOMP is not set
+# CT_CC_GCC_LIBSSP is not set
+# CT_CC_GCC_LIBQUADMATH is not set
+# CT_CC_GCC_LIBSANITIZER is not set
+CT_CC_GCC_LIBMPX=y
+
+#
+# Misc. obscure options.
+#
+CT_CC_CXA_ATEXIT=y
+# CT_CC_GCC_DISABLE_PCH is not set
+CT_CC_GCC_SJLJ_EXCEPTIONS=m
+CT_CC_GCC_LDBL_128=m
+# CT_CC_GCC_BUILD_ID is not set
+CT_CC_GCC_LNK_HASH_STYLE_DEFAULT=y
+# CT_CC_GCC_LNK_HASH_STYLE_SYSV is not set
+# CT_CC_GCC_LNK_HASH_STYLE_GNU is not set
+# CT_CC_GCC_LNK_HASH_STYLE_BOTH is not set
+CT_CC_GCC_LNK_HASH_STYLE=""
+CT_CC_GCC_DEC_FLOAT_AUTO=y
+# CT_CC_GCC_DEC_FLOAT_BID is not set
+# CT_CC_GCC_DEC_FLOAT_DPD is not set
+# CT_CC_GCC_DEC_FLOATS_NO is not set
+CT_ALL_CC_CHOICES="GCC"
+
+#
+# Additional supported languages:
+#
+CT_CC_LANG_CXX=y
+# CT_CC_LANG_FORTRAN is not set
+
+#
+# Debug facilities
+#
+# CT_DEBUG_DUMA is not set
+# CT_DEBUG_GDB is not set
+# CT_DEBUG_LTRACE is not set
+# CT_DEBUG_STRACE is not set
+CT_ALL_DEBUG_CHOICES="DUMA GDB LTRACE STRACE"
+
+#
+# Companion libraries
+#
+# CT_COMPLIBS_CHECK is not set
+# CT_COMP_LIBS_CLOOG is not set
+# CT_COMP_LIBS_EXPAT is not set
+CT_COMP_LIBS_GETTEXT=y
+CT_COMP_LIBS_GETTEXT_PKG_KSYM="GETTEXT"
+CT_GETTEXT_DIR_NAME="gettext"
+CT_GETTEXT_PKG_NAME="gettext"
+CT_GETTEXT_SRC_RELEASE=y
+CT_GETTEXT_PATCH_ORDER="global"
+CT_GETTEXT_V_0_19_8_1=y
+# CT_GETTEXT_NO_VERSIONS is not set
+CT_GETTEXT_VERSION="0.19.8.1"
+CT_GETTEXT_MIRRORS="$(CT_Mirrors GNU gettext)"
+CT_GETTEXT_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GETTEXT_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GETTEXT_ARCHIVE_FORMATS=".tar.xz .tar.lz .tar.gz"
+CT_GETTEXT_SIGNATURE_FORMAT="packed/.sig"
+CT_COMP_LIBS_GMP=y
+CT_COMP_LIBS_GMP_PKG_KSYM="GMP"
+CT_GMP_DIR_NAME="gmp"
+CT_GMP_PKG_NAME="gmp"
+CT_GMP_SRC_RELEASE=y
+CT_GMP_PATCH_ORDER="global"
+CT_GMP_V_6_1=y
+# CT_GMP_NO_VERSIONS is not set
+CT_GMP_VERSION="6.1.2"
+CT_GMP_MIRRORS="https://gmplib.org/download/gmp https://gmplib.org/download/gmp/archive $(CT_Mirrors GNU gmp)"
+CT_GMP_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GMP_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GMP_ARCHIVE_FORMATS=".tar.xz .tar.lz .tar.bz2"
+CT_GMP_SIGNATURE_FORMAT="packed/.sig"
+CT_GMP_later_than_5_1_0=y
+CT_GMP_5_1_0_or_later=y
+CT_GMP_later_than_5_0_0=y
+CT_GMP_5_0_0_or_later=y
+CT_GMP_REQUIRE_5_0_0_or_later=y
+CT_COMP_LIBS_ISL=y
+CT_COMP_LIBS_ISL_PKG_KSYM="ISL"
+CT_ISL_DIR_NAME="isl"
+CT_ISL_PKG_NAME="isl"
+CT_ISL_SRC_RELEASE=y
+CT_ISL_PATCH_ORDER="global"
+CT_ISL_V_0_20=y
+# CT_ISL_V_0_19 is not set
+# CT_ISL_V_0_18 is not set
+# CT_ISL_V_0_17 is not set
+# CT_ISL_V_0_16 is not set
+# CT_ISL_V_0_15 is not set
+# CT_ISL_NO_VERSIONS is not set
+CT_ISL_VERSION="0.20"
+CT_ISL_MIRRORS="https://ci-mirrors.rust-lang.org/rustc"
+CT_ISL_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_ISL_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_ISL_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_ISL_SIGNATURE_FORMAT=""
+CT_ISL_later_than_0_18=y
+CT_ISL_0_18_or_later=y
+CT_ISL_later_than_0_15=y
+CT_ISL_0_15_or_later=y
+CT_ISL_REQUIRE_0_15_or_later=y
+CT_ISL_later_than_0_14=y
+CT_ISL_0_14_or_later=y
+CT_ISL_REQUIRE_0_14_or_later=y
+CT_ISL_later_than_0_13=y
+CT_ISL_0_13_or_later=y
+CT_ISL_later_than_0_12=y
+CT_ISL_0_12_or_later=y
+CT_ISL_REQUIRE_0_12_or_later=y
+# CT_COMP_LIBS_LIBELF is not set
+CT_COMP_LIBS_LIBICONV=y
+CT_COMP_LIBS_LIBICONV_PKG_KSYM="LIBICONV"
+CT_LIBICONV_DIR_NAME="libiconv"
+CT_LIBICONV_PKG_NAME="libiconv"
+CT_LIBICONV_SRC_RELEASE=y
+CT_LIBICONV_PATCH_ORDER="global"
+CT_LIBICONV_V_1_15=y
+# CT_LIBICONV_NO_VERSIONS is not set
+CT_LIBICONV_VERSION="1.15"
+CT_LIBICONV_MIRRORS="$(CT_Mirrors GNU libiconv)"
+CT_LIBICONV_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_LIBICONV_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_LIBICONV_ARCHIVE_FORMATS=".tar.gz"
+CT_LIBICONV_SIGNATURE_FORMAT="packed/.sig"
+CT_COMP_LIBS_MPC=y
+CT_COMP_LIBS_MPC_PKG_KSYM="MPC"
+CT_MPC_DIR_NAME="mpc"
+CT_MPC_PKG_NAME="mpc"
+CT_MPC_SRC_RELEASE=y
+CT_MPC_PATCH_ORDER="global"
+CT_MPC_V_1_1=y
+# CT_MPC_V_1_0 is not set
+# CT_MPC_NO_VERSIONS is not set
+CT_MPC_VERSION="1.1.0"
+CT_MPC_MIRRORS="http://www.multiprecision.org/downloads $(CT_Mirrors GNU mpc)"
+CT_MPC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_MPC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_MPC_ARCHIVE_FORMATS=".tar.gz"
+CT_MPC_SIGNATURE_FORMAT="packed/.sig"
+CT_MPC_1_1_0_or_later=y
+CT_MPC_1_1_0_or_older=y
+CT_COMP_LIBS_MPFR=y
+CT_COMP_LIBS_MPFR_PKG_KSYM="MPFR"
+CT_MPFR_DIR_NAME="mpfr"
+CT_MPFR_PKG_NAME="mpfr"
+CT_MPFR_SRC_RELEASE=y
+CT_MPFR_PATCH_ORDER="global"
+CT_MPFR_V_4_0=y
+# CT_MPFR_V_3_1 is not set
+# CT_MPFR_NO_VERSIONS is not set
+CT_MPFR_VERSION="4.0.2"
+CT_MPFR_MIRRORS="http://www.mpfr.org/mpfr-${CT_MPFR_VERSION} $(CT_Mirrors GNU mpfr)"
+CT_MPFR_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_MPFR_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_MPFR_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz .zip"
+CT_MPFR_SIGNATURE_FORMAT="packed/.asc"
+CT_MPFR_later_than_4_0_0=y
+CT_MPFR_4_0_0_or_later=y
+CT_MPFR_later_than_3_0_0=y
+CT_MPFR_3_0_0_or_later=y
+CT_MPFR_REQUIRE_3_0_0_or_later=y
+CT_COMP_LIBS_NCURSES=y
+CT_COMP_LIBS_NCURSES_PKG_KSYM="NCURSES"
+CT_NCURSES_DIR_NAME="ncurses"
+CT_NCURSES_PKG_NAME="ncurses"
+CT_NCURSES_SRC_RELEASE=y
+CT_NCURSES_PATCH_ORDER="global"
+CT_NCURSES_V_6_1=y
+# CT_NCURSES_V_6_0 is not set
+# CT_NCURSES_NO_VERSIONS is not set
+CT_NCURSES_VERSION="6.1"
+CT_NCURSES_MIRRORS="ftp://invisible-island.net/ncurses $(CT_Mirrors GNU ncurses)"
+CT_NCURSES_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_NCURSES_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_NCURSES_ARCHIVE_FORMATS=".tar.gz"
+CT_NCURSES_SIGNATURE_FORMAT="packed/.sig"
+CT_NCURSES_HOST_CONFIG_ARGS=""
+CT_NCURSES_HOST_DISABLE_DB=y
+CT_NCURSES_HOST_FALLBACKS="linux,xterm,xterm-color,xterm-256color,vt100"
+CT_NCURSES_TARGET_CONFIG_ARGS=""
+# CT_NCURSES_TARGET_DISABLE_DB is not set
+CT_NCURSES_TARGET_FALLBACKS=""
+CT_COMP_LIBS_ZLIB=y
+CT_COMP_LIBS_ZLIB_PKG_KSYM="ZLIB"
+CT_ZLIB_DIR_NAME="zlib"
+CT_ZLIB_PKG_NAME="zlib"
+CT_ZLIB_SRC_RELEASE=y
+CT_ZLIB_PATCH_ORDER="global"
+CT_ZLIB_V_1_2_11=y
+# CT_ZLIB_NO_VERSIONS is not set
+CT_ZLIB_VERSION="1.2.11"
+CT_ZLIB_MIRRORS="http://downloads.sourceforge.net/project/libpng/zlib/${CT_ZLIB_VERSION}"
+CT_ZLIB_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_ZLIB_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_ZLIB_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_ZLIB_SIGNATURE_FORMAT="packed/.asc"
+CT_ALL_COMP_LIBS_CHOICES="CLOOG EXPAT GETTEXT GMP ISL LIBELF LIBICONV MPC MPFR NCURSES ZLIB"
+CT_LIBICONV_NEEDED=y
+CT_GETTEXT_NEEDED=y
+CT_GMP_NEEDED=y
+CT_MPFR_NEEDED=y
+CT_ISL_NEEDED=y
+CT_MPC_NEEDED=y
+CT_NCURSES_NEEDED=y
+CT_ZLIB_NEEDED=y
+CT_LIBICONV=y
+CT_GETTEXT=y
+CT_GMP=y
+CT_MPFR=y
+CT_ISL=y
+CT_MPC=y
+CT_NCURSES=y
+CT_ZLIB=y
+
+#
+# Companion tools
+#
+# CT_COMP_TOOLS_FOR_HOST is not set
+# CT_COMP_TOOLS_AUTOCONF is not set
+# CT_COMP_TOOLS_AUTOMAKE is not set
+# CT_COMP_TOOLS_BISON is not set
+# CT_COMP_TOOLS_DTC is not set
+# CT_COMP_TOOLS_LIBTOOL is not set
+# CT_COMP_TOOLS_M4 is not set
+# CT_COMP_TOOLS_MAKE is not set
+CT_ALL_COMP_TOOLS_CHOICES="AUTOCONF AUTOMAKE BISON DTC LIBTOOL M4 MAKE"
diff --git a/src/ci/docker/host-x86_64/dist-mips-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-mips-linux/Dockerfile
index 948fa40dd..eb511b321 100644
--- a/src/ci/docker/host-x86_64/dist-mips-linux/Dockerfile
+++ b/src/ci/docker/host-x86_64/dist-mips-linux/Dockerfile
@@ -1,31 +1,30 @@
-FROM ubuntu:16.04
-
-RUN apt-get update && apt-get install -y --no-install-recommends \
- g++ \
- make \
- ninja-build \
- file \
- curl \
- ca-certificates \
- python3 \
- git \
- cmake \
- sudo \
- gdb \
- xz-utils \
- g++-mips-linux-gnu \
- libssl-dev \
- pkg-config
+FROM ubuntu:22.04
+COPY scripts/cross-apt-packages.sh /scripts/
+RUN sh /scripts/cross-apt-packages.sh
+
+COPY scripts/crosstool-ng-1.24.sh /scripts/
+RUN sh /scripts/crosstool-ng-1.24.sh
+
+COPY scripts/rustbuild-setup.sh /scripts/
+RUN sh /scripts/rustbuild-setup.sh
+WORKDIR /tmp
+
+COPY host-x86_64/dist-mips-linux/patches/ /tmp/patches/
+COPY host-x86_64/dist-mips-linux/mips-linux-gnu.config host-x86_64/dist-mips-linux/build-mips-toolchain.sh /tmp/
+RUN su rustbuild -c ./build-mips-toolchain.sh
COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh
-COPY scripts/cmake.sh /scripts/
-RUN /scripts/cmake.sh
+ENV PATH=$PATH:/x-tools/mips-unknown-linux-gnu/bin
+
+ENV \
+ CC_mips_unknown_linux_gnu=mips-unknown-linux-gnu-gcc \
+ AR_mips_unknown_linux_gnu=mips-unknown-linux-gnu-ar \
+ CXX_mips_unknown_linux_gnu=mips-unknown-linux-gnu-g++
ENV HOSTS=mips-unknown-linux-gnu
-ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs \
- --set llvm.allow-old-toolchain
+ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs
ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS
diff --git a/src/ci/docker/host-x86_64/dist-mips-linux/build-mips-toolchain.sh b/src/ci/docker/host-x86_64/dist-mips-linux/build-mips-toolchain.sh
new file mode 100755
index 000000000..32612cf68
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-mips-linux/build-mips-toolchain.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+set -ex
+
+hide_output() {
+ set +x
+ on_err="
+echo ERROR: An error was encountered with the build.
+cat /tmp/build.log
+exit 1
+"
+ trap "$on_err" ERR
+ bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
+ PING_LOOP_PID=$!
+ "$@" &> /tmp/build.log
+ rm /tmp/build.log
+ trap - ERR
+ kill $PING_LOOP_PID
+ set -x
+}
+
+mkdir build
+cd build
+cp ../mips-linux-gnu.config .config
+hide_output ct-ng build
+cd ..
+rm -rf build
diff --git a/src/ci/docker/host-x86_64/dist-mips-linux/mips-linux-gnu.config b/src/ci/docker/host-x86_64/dist-mips-linux/mips-linux-gnu.config
new file mode 100644
index 000000000..575584ef0
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-mips-linux/mips-linux-gnu.config
@@ -0,0 +1,740 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# crosstool-NG Configuration
+#
+CT_CONFIGURE_has_static_link=y
+CT_CONFIGURE_has_cxx11=y
+CT_CONFIGURE_has_wget=y
+CT_CONFIGURE_has_curl=y
+CT_CONFIGURE_has_make_3_81_or_newer=y
+CT_CONFIGURE_has_make_4_0_or_newer=y
+CT_CONFIGURE_has_libtool_2_4_or_newer=y
+CT_CONFIGURE_has_libtoolize_2_4_or_newer=y
+CT_CONFIGURE_has_autoconf_2_65_or_newer=y
+CT_CONFIGURE_has_autoreconf_2_65_or_newer=y
+CT_CONFIGURE_has_automake_1_15_or_newer=y
+CT_CONFIGURE_has_gnu_m4_1_4_12_or_newer=y
+CT_CONFIGURE_has_python_3_4_or_newer=y
+CT_CONFIGURE_has_bison_2_7_or_newer=y
+CT_CONFIGURE_has_python=y
+CT_CONFIGURE_has_git=y
+CT_CONFIGURE_has_md5sum=y
+CT_CONFIGURE_has_sha1sum=y
+CT_CONFIGURE_has_sha256sum=y
+CT_CONFIGURE_has_sha512sum=y
+CT_CONFIGURE_has_install_with_strip_program=y
+CT_CONFIG_VERSION_CURRENT="3"
+CT_CONFIG_VERSION="3"
+CT_MODULES=y
+
+#
+# Paths and misc options
+#
+
+#
+# crosstool-NG behavior
+#
+# CT_OBSOLETE is not set
+# CT_EXPERIMENTAL is not set
+# CT_DEBUG_CT is not set
+
+#
+# Paths
+#
+CT_LOCAL_TARBALLS_DIR="${HOME}/src"
+CT_SAVE_TARBALLS=y
+# CT_TARBALLS_BUILDROOT_LAYOUT is not set
+CT_WORK_DIR="${CT_TOP_DIR}/.build"
+CT_BUILD_TOP_DIR="${CT_WORK_DIR:-${CT_TOP_DIR}/.build}/${CT_HOST:+HOST-${CT_HOST}/}${CT_TARGET}"
+CT_PREFIX_DIR="/x-tools/${CT_TARGET}"
+CT_RM_RF_PREFIX_DIR=y
+CT_REMOVE_DOCS=y
+CT_INSTALL_LICENSES=y
+CT_PREFIX_DIR_RO=y
+CT_STRIP_HOST_TOOLCHAIN_EXECUTABLES=y
+# CT_STRIP_TARGET_TOOLCHAIN_EXECUTABLES is not set
+
+#
+# Downloading
+#
+CT_DOWNLOAD_AGENT_WGET=y
+# CT_DOWNLOAD_AGENT_CURL is not set
+# CT_DOWNLOAD_AGENT_NONE is not set
+# CT_FORBID_DOWNLOAD is not set
+# CT_FORCE_DOWNLOAD is not set
+CT_CONNECT_TIMEOUT=10
+CT_DOWNLOAD_WGET_OPTIONS="--passive-ftp --tries=3 -nc --progress=dot:binary"
+# CT_ONLY_DOWNLOAD is not set
+CT_USE_MIRROR=y
+# CT_FORCE_MIRROR is not set
+CT_MIRROR_BASE_URL="https://ci-mirrors.rust-lang.org/rustc"
+CT_VERIFY_DOWNLOAD_DIGEST=y
+CT_VERIFY_DOWNLOAD_DIGEST_SHA512=y
+# CT_VERIFY_DOWNLOAD_DIGEST_SHA256 is not set
+# CT_VERIFY_DOWNLOAD_DIGEST_SHA1 is not set
+# CT_VERIFY_DOWNLOAD_DIGEST_MD5 is not set
+CT_VERIFY_DOWNLOAD_DIGEST_ALG="sha512"
+# CT_VERIFY_DOWNLOAD_SIGNATURE is not set
+
+#
+# Extracting
+#
+# CT_FORCE_EXTRACT is not set
+CT_OVERRIDE_CONFIG_GUESS_SUB=y
+# CT_ONLY_EXTRACT is not set
+# CT_PATCH_BUNDLED is not set
+CT_PATCH_BUNDLED_LOCAL=y
+CT_PATCH_ORDER="bundled,local"
+CT_PATCH_USE_LOCAL=y
+CT_LOCAL_PATCH_DIR="/tmp/patches"
+
+#
+# Build behavior
+#
+CT_PARALLEL_JOBS=0
+CT_LOAD=""
+CT_USE_PIPES=y
+CT_EXTRA_CFLAGS_FOR_BUILD=""
+CT_EXTRA_LDFLAGS_FOR_BUILD=""
+CT_EXTRA_CFLAGS_FOR_HOST=""
+CT_EXTRA_LDFLAGS_FOR_HOST=""
+# CT_CONFIG_SHELL_SH is not set
+# CT_CONFIG_SHELL_ASH is not set
+CT_CONFIG_SHELL_BASH=y
+# CT_CONFIG_SHELL_CUSTOM is not set
+CT_CONFIG_SHELL="${bash}"
+
+#
+# Logging
+#
+# CT_LOG_ERROR is not set
+# CT_LOG_WARN is not set
+# CT_LOG_INFO is not set
+CT_LOG_EXTRA=y
+# CT_LOG_ALL is not set
+# CT_LOG_DEBUG is not set
+CT_LOG_LEVEL_MAX="EXTRA"
+# CT_LOG_SEE_TOOLS_WARN is not set
+CT_LOG_PROGRESS_BAR=y
+CT_LOG_TO_FILE=y
+CT_LOG_FILE_COMPRESS=y
+
+#
+# Target options
+#
+# CT_ARCH_ALPHA is not set
+# CT_ARCH_ARC is not set
+# CT_ARCH_ARM is not set
+# CT_ARCH_AVR is not set
+# CT_ARCH_M68K is not set
+CT_ARCH_MIPS=y
+# CT_ARCH_NIOS2 is not set
+# CT_ARCH_POWERPC is not set
+# CT_ARCH_S390 is not set
+# CT_ARCH_SH is not set
+# CT_ARCH_SPARC is not set
+# CT_ARCH_X86 is not set
+# CT_ARCH_XTENSA is not set
+CT_ARCH="mips"
+CT_ARCH_CHOICE_KSYM="MIPS"
+CT_ARCH_TUNE=""
+CT_ARCH_MIPS_SHOW=y
+
+#
+# Options for mips
+#
+CT_ARCH_MIPS_PKG_KSYM=""
+CT_ARCH_mips_o32=y
+CT_ARCH_mips_ABI="32"
+CT_ALL_ARCH_CHOICES="ALPHA ARC ARM AVR M68K MICROBLAZE MIPS MOXIE MSP430 NIOS2 POWERPC RISCV S390 SH SPARC X86 XTENSA"
+CT_ARCH_SUFFIX=""
+# CT_OMIT_TARGET_VENDOR is not set
+
+#
+# Generic target options
+#
+# CT_MULTILIB is not set
+CT_DEMULTILIB=y
+CT_ARCH_USE_MMU=y
+CT_ARCH_SUPPORTS_EITHER_ENDIAN=y
+CT_ARCH_DEFAULT_BE=y
+CT_ARCH_BE=y
+# CT_ARCH_LE is not set
+CT_ARCH_ENDIAN="big"
+CT_ARCH_SUPPORTS_32=y
+CT_ARCH_SUPPORTS_64=y
+CT_ARCH_DEFAULT_32=y
+CT_ARCH_BITNESS=32
+CT_ARCH_32=y
+# CT_ARCH_64 is not set
+
+#
+# Target optimisations
+#
+CT_ARCH_SUPPORTS_WITH_ARCH=y
+CT_ARCH_SUPPORTS_WITH_TUNE=y
+CT_ARCH_SUPPORTS_WITH_FLOAT=y
+CT_ARCH_ARCH="mips32r2"
+CT_ARCH_FLOAT_AUTO=y
+# CT_ARCH_FLOAT_HW is not set
+# CT_ARCH_FLOAT_SW is not set
+CT_TARGET_CFLAGS=""
+CT_TARGET_LDFLAGS=""
+CT_ARCH_FLOAT="auto"
+
+#
+# Toolchain options
+#
+
+#
+# General toolchain options
+#
+CT_FORCE_SYSROOT=y
+CT_USE_SYSROOT=y
+CT_SYSROOT_NAME="sysroot"
+CT_SYSROOT_DIR_PREFIX=""
+CT_WANTS_STATIC_LINK=y
+CT_WANTS_STATIC_LINK_CXX=y
+# CT_STATIC_TOOLCHAIN is not set
+CT_SHOW_CT_VERSION=y
+CT_TOOLCHAIN_PKGVERSION=""
+CT_TOOLCHAIN_BUGURL=""
+
+#
+# Tuple completion and aliasing
+#
+CT_TARGET_VENDOR="unknown"
+CT_TARGET_ALIAS_SED_EXPR=""
+CT_TARGET_ALIAS=""
+
+#
+# Toolchain type
+#
+CT_CROSS=y
+# CT_CANADIAN is not set
+CT_TOOLCHAIN_TYPE="cross"
+
+#
+# Build system
+#
+CT_BUILD=""
+CT_BUILD_PREFIX=""
+CT_BUILD_SUFFIX=""
+
+#
+# Misc options
+#
+# CT_TOOLCHAIN_ENABLE_NLS is not set
+
+#
+# Operating System
+#
+CT_KERNEL_SUPPORTS_SHARED_LIBS=y
+# CT_KERNEL_BARE_METAL is not set
+CT_KERNEL_LINUX=y
+CT_KERNEL="linux"
+CT_KERNEL_CHOICE_KSYM="LINUX"
+CT_KERNEL_LINUX_SHOW=y
+
+#
+# Options for linux
+#
+CT_KERNEL_LINUX_PKG_KSYM="LINUX"
+CT_LINUX_DIR_NAME="linux"
+CT_LINUX_PKG_NAME="linux"
+CT_LINUX_SRC_RELEASE=y
+CT_LINUX_PATCH_ORDER="global"
+# CT_LINUX_V_4_20 is not set
+# CT_LINUX_V_4_19 is not set
+# CT_LINUX_V_4_18 is not set
+# CT_LINUX_V_4_17 is not set
+# CT_LINUX_V_4_16 is not set
+# CT_LINUX_V_4_15 is not set
+# CT_LINUX_V_4_14 is not set
+# CT_LINUX_V_4_13 is not set
+# CT_LINUX_V_4_12 is not set
+# CT_LINUX_V_4_11 is not set
+# CT_LINUX_V_4_10 is not set
+# CT_LINUX_V_4_9 is not set
+CT_LINUX_V_4_4=y
+# CT_LINUX_V_4_1 is not set
+# CT_LINUX_V_3_16 is not set
+# CT_LINUX_V_3_13 is not set
+# CT_LINUX_V_3_12 is not set
+# CT_LINUX_V_3_10 is not set
+# CT_LINUX_V_3_4 is not set
+# CT_LINUX_V_3_2 is not set
+# CT_LINUX_V_2_6_32 is not set
+# CT_LINUX_NO_VERSIONS is not set
+CT_LINUX_VERSION="4.4.174"
+CT_LINUX_MIRRORS="$(CT_Mirrors kernel.org linux ${CT_LINUX_VERSION})"
+CT_LINUX_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_LINUX_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_LINUX_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_LINUX_SIGNATURE_FORMAT="unpacked/.sign"
+CT_LINUX_4_8_or_older=y
+CT_LINUX_older_than_4_8=y
+CT_LINUX_later_than_3_7=y
+CT_LINUX_3_7_or_later=y
+CT_LINUX_later_than_3_2=y
+CT_LINUX_3_2_or_later=y
+CT_KERNEL_LINUX_VERBOSITY_0=y
+# CT_KERNEL_LINUX_VERBOSITY_1 is not set
+# CT_KERNEL_LINUX_VERBOSITY_2 is not set
+CT_KERNEL_LINUX_VERBOSE_LEVEL=0
+CT_KERNEL_LINUX_INSTALL_CHECK=y
+CT_ALL_KERNEL_CHOICES="BARE_METAL LINUX WINDOWS"
+
+#
+# Common kernel options
+#
+CT_SHARED_LIBS=y
+
+#
+# Binary utilities
+#
+CT_ARCH_BINFMT_ELF=y
+CT_BINUTILS_BINUTILS=y
+CT_BINUTILS="binutils"
+CT_BINUTILS_CHOICE_KSYM="BINUTILS"
+CT_BINUTILS_BINUTILS_SHOW=y
+
+#
+# Options for binutils
+#
+CT_BINUTILS_BINUTILS_PKG_KSYM="BINUTILS"
+CT_BINUTILS_DIR_NAME="binutils"
+CT_BINUTILS_USE_GNU=y
+CT_BINUTILS_USE="BINUTILS"
+CT_BINUTILS_PKG_NAME="binutils"
+CT_BINUTILS_SRC_RELEASE=y
+CT_BINUTILS_PATCH_ORDER="global"
+CT_BINUTILS_V_2_32=y
+# CT_BINUTILS_V_2_31 is not set
+# CT_BINUTILS_V_2_30 is not set
+# CT_BINUTILS_V_2_29 is not set
+# CT_BINUTILS_V_2_28 is not set
+# CT_BINUTILS_V_2_27 is not set
+# CT_BINUTILS_V_2_26 is not set
+# CT_BINUTILS_NO_VERSIONS is not set
+CT_BINUTILS_VERSION="2.32"
+CT_BINUTILS_MIRRORS="$(CT_Mirrors GNU binutils) $(CT_Mirrors sourceware binutils/releases)"
+CT_BINUTILS_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_BINUTILS_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_BINUTILS_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_BINUTILS_SIGNATURE_FORMAT="packed/.sig"
+CT_BINUTILS_later_than_2_30=y
+CT_BINUTILS_2_30_or_later=y
+CT_BINUTILS_later_than_2_27=y
+CT_BINUTILS_2_27_or_later=y
+CT_BINUTILS_later_than_2_25=y
+CT_BINUTILS_2_25_or_later=y
+CT_BINUTILS_later_than_2_23=y
+CT_BINUTILS_2_23_or_later=y
+
+#
+# GNU binutils
+#
+CT_BINUTILS_HAS_HASH_STYLE=y
+CT_BINUTILS_HAS_GOLD=y
+CT_BINUTILS_HAS_PLUGINS=y
+CT_BINUTILS_HAS_PKGVERSION_BUGURL=y
+CT_BINUTILS_FORCE_LD_BFD_DEFAULT=y
+CT_BINUTILS_LINKER_LD=y
+CT_BINUTILS_LINKERS_LIST="ld"
+CT_BINUTILS_LINKER_DEFAULT="bfd"
+# CT_BINUTILS_PLUGINS is not set
+CT_BINUTILS_RELRO=m
+CT_BINUTILS_EXTRA_CONFIG_ARRAY=""
+# CT_BINUTILS_FOR_TARGET is not set
+CT_ALL_BINUTILS_CHOICES="BINUTILS"
+
+#
+# C-library
+#
+CT_LIBC_GLIBC=y
+# CT_LIBC_UCLIBC is not set
+CT_LIBC="glibc"
+CT_LIBC_CHOICE_KSYM="GLIBC"
+CT_THREADS="nptl"
+CT_LIBC_GLIBC_SHOW=y
+
+#
+# Options for glibc
+#
+CT_LIBC_GLIBC_PKG_KSYM="GLIBC"
+CT_GLIBC_DIR_NAME="glibc"
+CT_GLIBC_USE_GNU=y
+CT_GLIBC_USE="GLIBC"
+CT_GLIBC_PKG_NAME="glibc"
+CT_GLIBC_SRC_RELEASE=y
+CT_GLIBC_PATCH_ORDER="global"
+# CT_GLIBC_V_2_29 is not set
+# CT_GLIBC_V_2_28 is not set
+# CT_GLIBC_V_2_27 is not set
+# CT_GLIBC_V_2_26 is not set
+# CT_GLIBC_V_2_25 is not set
+# CT_GLIBC_V_2_24 is not set
+CT_GLIBC_V_2_23=y
+# CT_GLIBC_V_2_19 is not set
+# CT_GLIBC_V_2_17 is not set
+# CT_GLIBC_V_2_12_1 is not set
+# CT_GLIBC_NO_VERSIONS is not set
+CT_GLIBC_VERSION="2.23"
+CT_GLIBC_MIRRORS="$(CT_Mirrors GNU glibc)"
+CT_GLIBC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GLIBC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GLIBC_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_GLIBC_SIGNATURE_FORMAT="packed/.sig"
+CT_GLIBC_2_29_or_older=y
+CT_GLIBC_older_than_2_29=y
+CT_GLIBC_2_27_or_older=y
+CT_GLIBC_older_than_2_27=y
+CT_GLIBC_2_26_or_older=y
+CT_GLIBC_older_than_2_26=y
+CT_GLIBC_2_25_or_older=y
+CT_GLIBC_older_than_2_25=y
+CT_GLIBC_2_24_or_older=y
+CT_GLIBC_older_than_2_24=y
+CT_GLIBC_2_23_or_later=y
+CT_GLIBC_2_23_or_older=y
+CT_GLIBC_later_than_2_20=y
+CT_GLIBC_2_20_or_later=y
+CT_GLIBC_later_than_2_17=y
+CT_GLIBC_2_17_or_later=y
+CT_GLIBC_later_than_2_14=y
+CT_GLIBC_2_14_or_later=y
+CT_GLIBC_DEP_KERNEL_HEADERS_VERSION=y
+CT_GLIBC_DEP_BINUTILS=y
+CT_GLIBC_DEP_GCC=y
+CT_GLIBC_DEP_PYTHON=y
+CT_GLIBC_HAS_LIBIDN_ADDON=y
+# CT_GLIBC_USE_LIBIDN_ADDON is not set
+CT_GLIBC_NO_SPARC_V8=y
+CT_GLIBC_HAS_OBSOLETE_RPC=y
+CT_GLIBC_EXTRA_CONFIG_ARRAY=""
+CT_GLIBC_CONFIGPARMS=""
+CT_GLIBC_EXTRA_CFLAGS=""
+CT_GLIBC_ENABLE_OBSOLETE_RPC=y
+# CT_GLIBC_DISABLE_VERSIONING is not set
+CT_GLIBC_OLDEST_ABI=""
+CT_GLIBC_FORCE_UNWIND=y
+# CT_GLIBC_LOCALES is not set
+# CT_GLIBC_KERNEL_VERSION_NONE is not set
+CT_GLIBC_KERNEL_VERSION_AS_HEADERS=y
+# CT_GLIBC_KERNEL_VERSION_CHOSEN is not set
+CT_GLIBC_MIN_KERNEL="4.4.174"
+CT_ALL_LIBC_CHOICES="AVR_LIBC BIONIC GLIBC MINGW_W64 MOXIEBOX MUSL NEWLIB NONE UCLIBC"
+CT_LIBC_SUPPORT_THREADS_ANY=y
+CT_LIBC_SUPPORT_THREADS_NATIVE=y
+
+#
+# Common C library options
+#
+CT_THREADS_NATIVE=y
+# CT_CREATE_LDSO_CONF is not set
+CT_LIBC_XLDD=y
+
+#
+# C compiler
+#
+CT_CC_CORE_PASSES_NEEDED=y
+CT_CC_CORE_PASS_1_NEEDED=y
+CT_CC_CORE_PASS_2_NEEDED=y
+CT_CC_SUPPORT_CXX=y
+CT_CC_SUPPORT_FORTRAN=y
+CT_CC_SUPPORT_ADA=y
+CT_CC_SUPPORT_OBJC=y
+CT_CC_SUPPORT_OBJCXX=y
+CT_CC_SUPPORT_GOLANG=y
+CT_CC_GCC=y
+CT_CC="gcc"
+CT_CC_CHOICE_KSYM="GCC"
+CT_CC_GCC_SHOW=y
+
+#
+# Options for gcc
+#
+CT_CC_GCC_PKG_KSYM="GCC"
+CT_GCC_DIR_NAME="gcc"
+CT_GCC_USE_GNU=y
+CT_GCC_USE="GCC"
+CT_GCC_PKG_NAME="gcc"
+CT_GCC_SRC_RELEASE=y
+CT_GCC_PATCH_ORDER="global"
+CT_GCC_V_8=y
+# CT_GCC_V_7 is not set
+# CT_GCC_V_6 is not set
+# CT_GCC_V_5 is not set
+# CT_GCC_V_4_9 is not set
+# CT_GCC_NO_VERSIONS is not set
+CT_GCC_VERSION="8.3.0"
+CT_GCC_MIRRORS="$(CT_Mirrors GNU gcc/gcc-${CT_GCC_VERSION}) $(CT_Mirrors sourceware gcc/releases/gcc-${CT_GCC_VERSION})"
+CT_GCC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GCC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GCC_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_GCC_SIGNATURE_FORMAT=""
+CT_GCC_later_than_7=y
+CT_GCC_7_or_later=y
+CT_GCC_later_than_6=y
+CT_GCC_6_or_later=y
+CT_GCC_later_than_5=y
+CT_GCC_5_or_later=y
+CT_GCC_later_than_4_9=y
+CT_GCC_4_9_or_later=y
+CT_GCC_later_than_4_8=y
+CT_GCC_4_8_or_later=y
+CT_CC_GCC_HAS_LIBMPX=y
+CT_CC_GCC_ENABLE_CXX_FLAGS=""
+CT_CC_GCC_CORE_EXTRA_CONFIG_ARRAY=""
+CT_CC_GCC_EXTRA_CONFIG_ARRAY="--with-fp-32=xx --with-odd-spreg-32=no"
+CT_CC_GCC_STATIC_LIBSTDCXX=y
+# CT_CC_GCC_SYSTEM_ZLIB is not set
+CT_CC_GCC_CONFIG_TLS=m
+
+#
+# Optimisation features
+#
+CT_CC_GCC_USE_GRAPHITE=y
+CT_CC_GCC_USE_LTO=y
+
+#
+# Settings for libraries running on target
+#
+CT_CC_GCC_ENABLE_TARGET_OPTSPACE=y
+# CT_CC_GCC_LIBMUDFLAP is not set
+# CT_CC_GCC_LIBGOMP is not set
+# CT_CC_GCC_LIBSSP is not set
+# CT_CC_GCC_LIBQUADMATH is not set
+# CT_CC_GCC_LIBSANITIZER is not set
+
+#
+# Misc. obscure options.
+#
+CT_CC_CXA_ATEXIT=y
+# CT_CC_GCC_DISABLE_PCH is not set
+CT_CC_GCC_SJLJ_EXCEPTIONS=m
+CT_CC_GCC_LDBL_128=m
+# CT_CC_GCC_BUILD_ID is not set
+CT_CC_GCC_LNK_HASH_STYLE_DEFAULT=y
+# CT_CC_GCC_LNK_HASH_STYLE_SYSV is not set
+# CT_CC_GCC_LNK_HASH_STYLE_GNU is not set
+# CT_CC_GCC_LNK_HASH_STYLE_BOTH is not set
+CT_CC_GCC_LNK_HASH_STYLE=""
+CT_CC_GCC_DEC_FLOAT_AUTO=y
+# CT_CC_GCC_DEC_FLOAT_BID is not set
+# CT_CC_GCC_DEC_FLOAT_DPD is not set
+# CT_CC_GCC_DEC_FLOATS_NO is not set
+CT_CC_GCC_HAS_ARCH_OPTIONS=y
+
+#
+# archictecture-specific options
+#
+CT_CC_GCC_mips_llsc=m
+CT_CC_GCC_mips_synci=m
+# CT_CC_GCC_mips_plt is not set
+CT_ALL_CC_CHOICES="GCC"
+
+#
+# Additional supported languages:
+#
+CT_CC_LANG_CXX=y
+# CT_CC_LANG_FORTRAN is not set
+
+#
+# Debug facilities
+#
+# CT_DEBUG_DUMA is not set
+# CT_DEBUG_GDB is not set
+# CT_DEBUG_LTRACE is not set
+# CT_DEBUG_STRACE is not set
+CT_ALL_DEBUG_CHOICES="DUMA GDB LTRACE STRACE"
+
+#
+# Companion libraries
+#
+# CT_COMPLIBS_CHECK is not set
+# CT_COMP_LIBS_CLOOG is not set
+# CT_COMP_LIBS_EXPAT is not set
+CT_COMP_LIBS_GETTEXT=y
+CT_COMP_LIBS_GETTEXT_PKG_KSYM="GETTEXT"
+CT_GETTEXT_DIR_NAME="gettext"
+CT_GETTEXT_PKG_NAME="gettext"
+CT_GETTEXT_SRC_RELEASE=y
+CT_GETTEXT_PATCH_ORDER="global"
+CT_GETTEXT_V_0_19_8_1=y
+# CT_GETTEXT_NO_VERSIONS is not set
+CT_GETTEXT_VERSION="0.19.8.1"
+CT_GETTEXT_MIRRORS="$(CT_Mirrors GNU gettext)"
+CT_GETTEXT_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GETTEXT_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GETTEXT_ARCHIVE_FORMATS=".tar.xz .tar.lz .tar.gz"
+CT_GETTEXT_SIGNATURE_FORMAT="packed/.sig"
+CT_COMP_LIBS_GMP=y
+CT_COMP_LIBS_GMP_PKG_KSYM="GMP"
+CT_GMP_DIR_NAME="gmp"
+CT_GMP_PKG_NAME="gmp"
+CT_GMP_SRC_RELEASE=y
+CT_GMP_PATCH_ORDER="global"
+CT_GMP_V_6_1=y
+# CT_GMP_NO_VERSIONS is not set
+CT_GMP_VERSION="6.1.2"
+CT_GMP_MIRRORS="https://gmplib.org/download/gmp https://gmplib.org/download/gmp/archive $(CT_Mirrors GNU gmp)"
+CT_GMP_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GMP_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GMP_ARCHIVE_FORMATS=".tar.xz .tar.lz .tar.bz2"
+CT_GMP_SIGNATURE_FORMAT="packed/.sig"
+CT_GMP_later_than_5_1_0=y
+CT_GMP_5_1_0_or_later=y
+CT_GMP_later_than_5_0_0=y
+CT_GMP_5_0_0_or_later=y
+CT_GMP_REQUIRE_5_0_0_or_later=y
+CT_COMP_LIBS_ISL=y
+CT_COMP_LIBS_ISL_PKG_KSYM="ISL"
+CT_ISL_DIR_NAME="isl"
+CT_ISL_PKG_NAME="isl"
+CT_ISL_SRC_RELEASE=y
+CT_ISL_PATCH_ORDER="global"
+CT_ISL_V_0_20=y
+# CT_ISL_V_0_19 is not set
+# CT_ISL_V_0_18 is not set
+# CT_ISL_V_0_17 is not set
+# CT_ISL_V_0_16 is not set
+# CT_ISL_V_0_15 is not set
+# CT_ISL_NO_VERSIONS is not set
+CT_ISL_VERSION="0.20"
+CT_ISL_MIRRORS="http://isl.gforge.inria.fr"
+CT_ISL_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_ISL_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_ISL_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_ISL_SIGNATURE_FORMAT=""
+CT_ISL_later_than_0_18=y
+CT_ISL_0_18_or_later=y
+CT_ISL_later_than_0_15=y
+CT_ISL_0_15_or_later=y
+CT_ISL_REQUIRE_0_15_or_later=y
+CT_ISL_later_than_0_14=y
+CT_ISL_0_14_or_later=y
+CT_ISL_REQUIRE_0_14_or_later=y
+CT_ISL_later_than_0_13=y
+CT_ISL_0_13_or_later=y
+CT_ISL_later_than_0_12=y
+CT_ISL_0_12_or_later=y
+CT_ISL_REQUIRE_0_12_or_later=y
+# CT_COMP_LIBS_LIBELF is not set
+CT_COMP_LIBS_LIBICONV=y
+CT_COMP_LIBS_LIBICONV_PKG_KSYM="LIBICONV"
+CT_LIBICONV_DIR_NAME="libiconv"
+CT_LIBICONV_PKG_NAME="libiconv"
+CT_LIBICONV_SRC_RELEASE=y
+CT_LIBICONV_PATCH_ORDER="global"
+CT_LIBICONV_V_1_15=y
+# CT_LIBICONV_NO_VERSIONS is not set
+CT_LIBICONV_VERSION="1.15"
+CT_LIBICONV_MIRRORS="$(CT_Mirrors GNU libiconv)"
+CT_LIBICONV_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_LIBICONV_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_LIBICONV_ARCHIVE_FORMATS=".tar.gz"
+CT_LIBICONV_SIGNATURE_FORMAT="packed/.sig"
+CT_COMP_LIBS_MPC=y
+CT_COMP_LIBS_MPC_PKG_KSYM="MPC"
+CT_MPC_DIR_NAME="mpc"
+CT_MPC_PKG_NAME="mpc"
+CT_MPC_SRC_RELEASE=y
+CT_MPC_PATCH_ORDER="global"
+CT_MPC_V_1_1=y
+# CT_MPC_V_1_0 is not set
+# CT_MPC_NO_VERSIONS is not set
+CT_MPC_VERSION="1.1.0"
+CT_MPC_MIRRORS="http://www.multiprecision.org/downloads $(CT_Mirrors GNU mpc)"
+CT_MPC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_MPC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_MPC_ARCHIVE_FORMATS=".tar.gz"
+CT_MPC_SIGNATURE_FORMAT="packed/.sig"
+CT_MPC_1_1_0_or_later=y
+CT_MPC_1_1_0_or_older=y
+CT_COMP_LIBS_MPFR=y
+CT_COMP_LIBS_MPFR_PKG_KSYM="MPFR"
+CT_MPFR_DIR_NAME="mpfr"
+CT_MPFR_PKG_NAME="mpfr"
+CT_MPFR_SRC_RELEASE=y
+CT_MPFR_PATCH_ORDER="global"
+CT_MPFR_V_4_0=y
+# CT_MPFR_V_3_1 is not set
+# CT_MPFR_NO_VERSIONS is not set
+CT_MPFR_VERSION="4.0.2"
+CT_MPFR_MIRRORS="http://www.mpfr.org/mpfr-${CT_MPFR_VERSION} $(CT_Mirrors GNU mpfr)"
+CT_MPFR_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_MPFR_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_MPFR_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz .zip"
+CT_MPFR_SIGNATURE_FORMAT="packed/.asc"
+CT_MPFR_later_than_4_0_0=y
+CT_MPFR_4_0_0_or_later=y
+CT_MPFR_later_than_3_0_0=y
+CT_MPFR_3_0_0_or_later=y
+CT_MPFR_REQUIRE_3_0_0_or_later=y
+CT_COMP_LIBS_NCURSES=y
+CT_COMP_LIBS_NCURSES_PKG_KSYM="NCURSES"
+CT_NCURSES_DIR_NAME="ncurses"
+CT_NCURSES_PKG_NAME="ncurses"
+CT_NCURSES_SRC_RELEASE=y
+CT_NCURSES_PATCH_ORDER="global"
+CT_NCURSES_V_6_1=y
+# CT_NCURSES_V_6_0 is not set
+# CT_NCURSES_NO_VERSIONS is not set
+CT_NCURSES_VERSION="6.1"
+CT_NCURSES_MIRRORS="ftp://invisible-island.net/ncurses $(CT_Mirrors GNU ncurses)"
+CT_NCURSES_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_NCURSES_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_NCURSES_ARCHIVE_FORMATS=".tar.gz"
+CT_NCURSES_SIGNATURE_FORMAT="packed/.sig"
+CT_NCURSES_HOST_CONFIG_ARGS=""
+CT_NCURSES_HOST_DISABLE_DB=y
+CT_NCURSES_HOST_FALLBACKS="linux,xterm,xterm-color,xterm-256color,vt100"
+CT_NCURSES_TARGET_CONFIG_ARGS=""
+# CT_NCURSES_TARGET_DISABLE_DB is not set
+CT_NCURSES_TARGET_FALLBACKS=""
+CT_COMP_LIBS_ZLIB=y
+CT_COMP_LIBS_ZLIB_PKG_KSYM="ZLIB"
+CT_ZLIB_DIR_NAME="zlib"
+CT_ZLIB_PKG_NAME="zlib"
+CT_ZLIB_SRC_RELEASE=y
+CT_ZLIB_PATCH_ORDER="global"
+CT_ZLIB_V_1_2_11=y
+# CT_ZLIB_NO_VERSIONS is not set
+CT_ZLIB_VERSION="1.2.11"
+CT_ZLIB_MIRRORS="http://downloads.sourceforge.net/project/libpng/zlib/${CT_ZLIB_VERSION}"
+CT_ZLIB_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_ZLIB_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_ZLIB_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_ZLIB_SIGNATURE_FORMAT="packed/.asc"
+CT_ALL_COMP_LIBS_CHOICES="CLOOG EXPAT GETTEXT GMP ISL LIBELF LIBICONV MPC MPFR NCURSES ZLIB"
+CT_LIBICONV_NEEDED=y
+CT_GETTEXT_NEEDED=y
+CT_GMP_NEEDED=y
+CT_MPFR_NEEDED=y
+CT_ISL_NEEDED=y
+CT_MPC_NEEDED=y
+CT_NCURSES_NEEDED=y
+CT_ZLIB_NEEDED=y
+CT_LIBICONV=y
+CT_GETTEXT=y
+CT_GMP=y
+CT_MPFR=y
+CT_ISL=y
+CT_MPC=y
+CT_NCURSES=y
+CT_ZLIB=y
+
+#
+# Companion tools
+#
+# CT_COMP_TOOLS_FOR_HOST is not set
+# CT_COMP_TOOLS_AUTOCONF is not set
+# CT_COMP_TOOLS_AUTOMAKE is not set
+# CT_COMP_TOOLS_BISON is not set
+# CT_COMP_TOOLS_DTC is not set
+# CT_COMP_TOOLS_LIBTOOL is not set
+# CT_COMP_TOOLS_M4 is not set
+# CT_COMP_TOOLS_MAKE is not set
+CT_ALL_COMP_TOOLS_CHOICES="AUTOCONF AUTOMAKE BISON DTC LIBTOOL M4 MAKE"
diff --git a/src/ci/docker/host-x86_64/dist-mips-linux/patches/glibc/2.23/0001-MIPS-SPARC-fix-wrong-vfork-aliases-in-libpthread.so.patch b/src/ci/docker/host-x86_64/dist-mips-linux/patches/glibc/2.23/0001-MIPS-SPARC-fix-wrong-vfork-aliases-in-libpthread.so.patch
new file mode 100644
index 000000000..393084df3
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-mips-linux/patches/glibc/2.23/0001-MIPS-SPARC-fix-wrong-vfork-aliases-in-libpthread.so.patch
@@ -0,0 +1,44 @@
+From 43c2948756bb6e144c7b871e827bba37d61ad3a3 Mon Sep 17 00:00:00 2001
+From: Aurelien Jarno <aurelien@aurel32.net>
+Date: Sat, 18 Jun 2016 19:11:23 +0200
+Subject: [PATCH 1/2] MIPS, SPARC: fix wrong vfork aliases in libpthread.so
+
+With recent binutils versions the GNU libc fails to build on at least
+MISP and SPARC, with this kind of error:
+
+ /home/aurel32/glibc/glibc-build/nptl/libpthread.so:(*IND*+0x0): multiple definition of `vfork@GLIBC_2.0'
+ /home/aurel32/glibc/glibc-build/nptl/libpthread.so::(.text+0xee50): first defined here
+
+It appears that on these architectures pt-vfork.S includes vfork.S
+(through the alpha version of pt-vfork.S) and that the __vfork aliases
+are not conditionalized on IS_IN (libc) like on other architectures.
+Therefore the aliases are also wrongly included in libpthread.so.
+
+Fix this by properly conditionalizing the aliases like on other
+architectures.
+
+Changelog:
+ * sysdeps/unix/sysv/linux/mips/vfork.S (__vfork): Conditionalize
+ hidden_def, weak_alias and strong_alias on [IS_IN (libc)].
+ * sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S: Likewise.
+---
+ sysdeps/unix/sysv/linux/mips/vfork.S | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/sysdeps/unix/sysv/linux/mips/vfork.S b/sysdeps/unix/sysv/linux/mips/vfork.S
+index 8c6615143708..c0c0ce699159 100644
+--- a/sysdeps/unix/sysv/linux/mips/vfork.S
++++ b/sysdeps/unix/sysv/linux/mips/vfork.S
+@@ -106,6 +106,8 @@ L(error):
+ #endif
+ END(__vfork)
+
++#if IS_IN (libc)
+ libc_hidden_def(__vfork)
+ weak_alias (__vfork, vfork)
+ strong_alias (__vfork, __libc_vfork)
++#endif
+--
+2.37.3
+
diff --git a/src/ci/docker/host-x86_64/dist-mips-linux/patches/glibc/2.23/0002-MIPS-SPARC-more-fixes-to-the-vfork-aliases-in-libpth.patch b/src/ci/docker/host-x86_64/dist-mips-linux/patches/glibc/2.23/0002-MIPS-SPARC-more-fixes-to-the-vfork-aliases-in-libpth.patch
new file mode 100644
index 000000000..e28c7ae99
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-mips-linux/patches/glibc/2.23/0002-MIPS-SPARC-more-fixes-to-the-vfork-aliases-in-libpth.patch
@@ -0,0 +1,63 @@
+From b87c1ec3fa398646f042a68f0ce0f7d09c1348c7 Mon Sep 17 00:00:00 2001
+From: Aurelien Jarno <aurelien@aurel32.net>
+Date: Tue, 21 Jun 2016 23:59:37 +0200
+Subject: [PATCH 2/2] MIPS, SPARC: more fixes to the vfork aliases in
+ libpthread.so
+
+Commit 43c29487 tried to fix the vfork aliases in libpthread.so on MIPS
+and SPARC, but failed to do it correctly, introducing an ABI change.
+
+This patch does the remaining changes needed to align the MIPS and SPARC
+vfork implementations with the other architectures. That way the the
+alpha version of pt-vfork.S works correctly for MIPS and SPARC. The
+changes for alpha were done in 82aab97c.
+
+Changelog:
+ * sysdeps/unix/sysv/linux/mips/vfork.S (__vfork): Rename into
+ __libc_vfork.
+ (__vfork) [IS_IN (libc)]: Remove alias.
+ (__libc_vfork) [IS_IN (libc)]: Define as an alias.
+ * sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S: Likewise.
+ * sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S: Likewise.
+---
+ sysdeps/unix/sysv/linux/mips/vfork.S | 12 ++++++------
+ 1 file changed, 6 insertions(+), 6 deletions(-)
+
+diff --git a/sysdeps/unix/sysv/linux/mips/vfork.S b/sysdeps/unix/sysv/linux/mips/vfork.S
+index c0c0ce699159..1867c8626ebe 100644
+--- a/sysdeps/unix/sysv/linux/mips/vfork.S
++++ b/sysdeps/unix/sysv/linux/mips/vfork.S
+@@ -31,13 +31,13 @@
+ LOCALSZ= 1
+ FRAMESZ= (((NARGSAVE+LOCALSZ)*SZREG)+ALSZ)&ALMASK
+ GPOFF= FRAMESZ-(1*SZREG)
+-NESTED(__vfork,FRAMESZ,sp)
++NESTED(__libc_vfork,FRAMESZ,sp)
+ #ifdef __PIC__
+ SETUP_GP
+ #endif
+ PTR_SUBU sp, FRAMESZ
+ cfi_adjust_cfa_offset (FRAMESZ)
+- SETUP_GP64_REG (a5, __vfork)
++ SETUP_GP64_REG (a5, __libc_vfork)
+ #ifdef __PIC__
+ SAVE_GP (GPOFF)
+ #endif
+@@ -104,10 +104,10 @@ L(error):
+ RESTORE_GP64_REG
+ j __syscall_error
+ #endif
+- END(__vfork)
++ END(__libc_vfork)
+
+ #if IS_IN (libc)
+-libc_hidden_def(__vfork)
+-weak_alias (__vfork, vfork)
+-strong_alias (__vfork, __libc_vfork)
++weak_alias (__libc_vfork, vfork)
++strong_alias (__libc_vfork, __vfork)
++libc_hidden_def (__vfork)
+ #endif
+--
+2.37.3
+
diff --git a/src/ci/docker/host-x86_64/dist-mips64-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-mips64-linux/Dockerfile
index fd15dbd22..de862e1df 100644
--- a/src/ci/docker/host-x86_64/dist-mips64-linux/Dockerfile
+++ b/src/ci/docker/host-x86_64/dist-mips64-linux/Dockerfile
@@ -1,30 +1,30 @@
-FROM ubuntu:16.04
-
-RUN apt-get update && apt-get install -y --no-install-recommends \
- g++ \
- make \
- ninja-build \
- file \
- curl \
- ca-certificates \
- python3 \
- git \
- cmake \
- sudo \
- gdb \
- xz-utils \
- g++-mips64-linux-gnuabi64 \
- libssl-dev \
- pkg-config
+FROM ubuntu:22.04
+
+COPY scripts/cross-apt-packages.sh /scripts/
+RUN sh /scripts/cross-apt-packages.sh
+
+COPY scripts/crosstool-ng-1.24.sh /scripts/
+RUN sh /scripts/crosstool-ng-1.24.sh
+
+COPY scripts/rustbuild-setup.sh /scripts/
+RUN sh /scripts/rustbuild-setup.sh
+WORKDIR /tmp
+
+COPY host-x86_64/dist-mips-linux/patches/ /tmp/patches/
+COPY host-x86_64/dist-mips64-linux/mips64-linux-gnu.config host-x86_64/dist-mips64-linux/build-mips64-toolchain.sh /tmp/
+RUN su rustbuild -c ./build-mips64-toolchain.sh
COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh
-COPY scripts/cmake.sh /scripts/
-RUN /scripts/cmake.sh
+ENV PATH=$PATH:/x-tools/mips64-unknown-linux-gnu/bin
+
+ENV \
+ CC_mips64_unknown_linux_gnuabi64=mips64-unknown-linux-gnu-gcc \
+ AR_mips64_unknown_linux_gnuabi64=mips64-unknown-linux-gnu-ar \
+ CXX_mips64_unknown_linux_gnuabi64=mips64-unknown-linux-gnu-g++
ENV HOSTS=mips64-unknown-linux-gnuabi64
-ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs \
- --set llvm.allow-old-toolchain
+ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs
ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS
diff --git a/src/ci/docker/host-x86_64/dist-mips64-linux/build-mips64-toolchain.sh b/src/ci/docker/host-x86_64/dist-mips64-linux/build-mips64-toolchain.sh
new file mode 100755
index 000000000..f554a5f47
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-mips64-linux/build-mips64-toolchain.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+set -ex
+
+hide_output() {
+ set +x
+ on_err="
+echo ERROR: An error was encountered with the build.
+cat /tmp/build.log
+exit 1
+"
+ trap "$on_err" ERR
+ bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
+ PING_LOOP_PID=$!
+ "$@" &> /tmp/build.log
+ rm /tmp/build.log
+ trap - ERR
+ kill $PING_LOOP_PID
+ set -x
+}
+
+mkdir build
+cd build
+cp ../mips64-linux-gnu.config .config
+hide_output ct-ng build
+cd ..
+rm -rf build
diff --git a/src/ci/docker/host-x86_64/dist-mips64-linux/mips64-linux-gnu.config b/src/ci/docker/host-x86_64/dist-mips64-linux/mips64-linux-gnu.config
new file mode 100644
index 000000000..4b1efe24a
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-mips64-linux/mips64-linux-gnu.config
@@ -0,0 +1,741 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# crosstool-NG Configuration
+#
+CT_CONFIGURE_has_static_link=y
+CT_CONFIGURE_has_cxx11=y
+CT_CONFIGURE_has_wget=y
+CT_CONFIGURE_has_curl=y
+CT_CONFIGURE_has_make_3_81_or_newer=y
+CT_CONFIGURE_has_make_4_0_or_newer=y
+CT_CONFIGURE_has_libtool_2_4_or_newer=y
+CT_CONFIGURE_has_libtoolize_2_4_or_newer=y
+CT_CONFIGURE_has_autoconf_2_65_or_newer=y
+CT_CONFIGURE_has_autoreconf_2_65_or_newer=y
+CT_CONFIGURE_has_automake_1_15_or_newer=y
+CT_CONFIGURE_has_gnu_m4_1_4_12_or_newer=y
+CT_CONFIGURE_has_python_3_4_or_newer=y
+CT_CONFIGURE_has_bison_2_7_or_newer=y
+CT_CONFIGURE_has_python=y
+CT_CONFIGURE_has_git=y
+CT_CONFIGURE_has_md5sum=y
+CT_CONFIGURE_has_sha1sum=y
+CT_CONFIGURE_has_sha256sum=y
+CT_CONFIGURE_has_sha512sum=y
+CT_CONFIGURE_has_install_with_strip_program=y
+CT_CONFIG_VERSION_CURRENT="3"
+CT_CONFIG_VERSION="3"
+CT_MODULES=y
+
+#
+# Paths and misc options
+#
+
+#
+# crosstool-NG behavior
+#
+# CT_OBSOLETE is not set
+# CT_EXPERIMENTAL is not set
+# CT_DEBUG_CT is not set
+
+#
+# Paths
+#
+CT_LOCAL_TARBALLS_DIR="${HOME}/src"
+CT_SAVE_TARBALLS=y
+# CT_TARBALLS_BUILDROOT_LAYOUT is not set
+CT_WORK_DIR="${CT_TOP_DIR}/.build"
+CT_BUILD_TOP_DIR="${CT_WORK_DIR:-${CT_TOP_DIR}/.build}/${CT_HOST:+HOST-${CT_HOST}/}${CT_TARGET}"
+CT_PREFIX_DIR="/x-tools/${CT_TARGET}"
+CT_RM_RF_PREFIX_DIR=y
+CT_REMOVE_DOCS=y
+CT_INSTALL_LICENSES=y
+CT_PREFIX_DIR_RO=y
+CT_STRIP_HOST_TOOLCHAIN_EXECUTABLES=y
+# CT_STRIP_TARGET_TOOLCHAIN_EXECUTABLES is not set
+
+#
+# Downloading
+#
+CT_DOWNLOAD_AGENT_WGET=y
+# CT_DOWNLOAD_AGENT_CURL is not set
+# CT_DOWNLOAD_AGENT_NONE is not set
+# CT_FORBID_DOWNLOAD is not set
+# CT_FORCE_DOWNLOAD is not set
+CT_CONNECT_TIMEOUT=10
+CT_DOWNLOAD_WGET_OPTIONS="--passive-ftp --tries=3 -nc --progress=dot:binary"
+# CT_ONLY_DOWNLOAD is not set
+CT_USE_MIRROR=y
+# CT_FORCE_MIRROR is not set
+CT_MIRROR_BASE_URL="https://ci-mirrors.rust-lang.org/rustc"
+CT_VERIFY_DOWNLOAD_DIGEST=y
+CT_VERIFY_DOWNLOAD_DIGEST_SHA512=y
+# CT_VERIFY_DOWNLOAD_DIGEST_SHA256 is not set
+# CT_VERIFY_DOWNLOAD_DIGEST_SHA1 is not set
+# CT_VERIFY_DOWNLOAD_DIGEST_MD5 is not set
+CT_VERIFY_DOWNLOAD_DIGEST_ALG="sha512"
+# CT_VERIFY_DOWNLOAD_SIGNATURE is not set
+
+#
+# Extracting
+#
+# CT_FORCE_EXTRACT is not set
+CT_OVERRIDE_CONFIG_GUESS_SUB=y
+# CT_ONLY_EXTRACT is not set
+# CT_PATCH_BUNDLED is not set
+CT_PATCH_BUNDLED_LOCAL=y
+CT_PATCH_ORDER="bundled,local"
+CT_PATCH_USE_LOCAL=y
+CT_LOCAL_PATCH_DIR="/tmp/patches"
+
+#
+# Build behavior
+#
+CT_PARALLEL_JOBS=0
+CT_LOAD=""
+CT_USE_PIPES=y
+CT_EXTRA_CFLAGS_FOR_BUILD=""
+CT_EXTRA_LDFLAGS_FOR_BUILD=""
+CT_EXTRA_CFLAGS_FOR_HOST=""
+CT_EXTRA_LDFLAGS_FOR_HOST=""
+# CT_CONFIG_SHELL_SH is not set
+# CT_CONFIG_SHELL_ASH is not set
+CT_CONFIG_SHELL_BASH=y
+# CT_CONFIG_SHELL_CUSTOM is not set
+CT_CONFIG_SHELL="${bash}"
+
+#
+# Logging
+#
+# CT_LOG_ERROR is not set
+# CT_LOG_WARN is not set
+# CT_LOG_INFO is not set
+CT_LOG_EXTRA=y
+# CT_LOG_ALL is not set
+# CT_LOG_DEBUG is not set
+CT_LOG_LEVEL_MAX="EXTRA"
+# CT_LOG_SEE_TOOLS_WARN is not set
+CT_LOG_PROGRESS_BAR=y
+CT_LOG_TO_FILE=y
+CT_LOG_FILE_COMPRESS=y
+
+#
+# Target options
+#
+# CT_ARCH_ALPHA is not set
+# CT_ARCH_ARC is not set
+# CT_ARCH_ARM is not set
+# CT_ARCH_AVR is not set
+# CT_ARCH_M68K is not set
+CT_ARCH_MIPS=y
+# CT_ARCH_NIOS2 is not set
+# CT_ARCH_POWERPC is not set
+# CT_ARCH_S390 is not set
+# CT_ARCH_SH is not set
+# CT_ARCH_SPARC is not set
+# CT_ARCH_X86 is not set
+# CT_ARCH_XTENSA is not set
+CT_ARCH="mips"
+CT_ARCH_CHOICE_KSYM="MIPS"
+CT_ARCH_TUNE=""
+CT_ARCH_MIPS_SHOW=y
+
+#
+# Options for mips
+#
+CT_ARCH_MIPS_PKG_KSYM=""
+# CT_ARCH_mips_n32 is not set
+CT_ARCH_mips_n64=y
+CT_ARCH_mips_ABI="64"
+CT_ALL_ARCH_CHOICES="ALPHA ARC ARM AVR M68K MICROBLAZE MIPS MOXIE MSP430 NIOS2 POWERPC RISCV S390 SH SPARC X86 XTENSA"
+CT_ARCH_SUFFIX=""
+# CT_OMIT_TARGET_VENDOR is not set
+
+#
+# Generic target options
+#
+# CT_MULTILIB is not set
+CT_DEMULTILIB=y
+CT_ARCH_USE_MMU=y
+CT_ARCH_SUPPORTS_EITHER_ENDIAN=y
+CT_ARCH_DEFAULT_BE=y
+CT_ARCH_BE=y
+# CT_ARCH_LE is not set
+CT_ARCH_ENDIAN="big"
+CT_ARCH_SUPPORTS_32=y
+CT_ARCH_SUPPORTS_64=y
+CT_ARCH_DEFAULT_32=y
+CT_ARCH_BITNESS=64
+# CT_ARCH_32 is not set
+CT_ARCH_64=y
+
+#
+# Target optimisations
+#
+CT_ARCH_SUPPORTS_WITH_ARCH=y
+CT_ARCH_SUPPORTS_WITH_TUNE=y
+CT_ARCH_SUPPORTS_WITH_FLOAT=y
+CT_ARCH_ARCH="mips64r2"
+CT_ARCH_FLOAT_AUTO=y
+# CT_ARCH_FLOAT_HW is not set
+# CT_ARCH_FLOAT_SW is not set
+CT_TARGET_CFLAGS=""
+CT_TARGET_LDFLAGS=""
+CT_ARCH_FLOAT="auto"
+
+#
+# Toolchain options
+#
+
+#
+# General toolchain options
+#
+CT_FORCE_SYSROOT=y
+CT_USE_SYSROOT=y
+CT_SYSROOT_NAME="sysroot"
+CT_SYSROOT_DIR_PREFIX=""
+CT_WANTS_STATIC_LINK=y
+CT_WANTS_STATIC_LINK_CXX=y
+# CT_STATIC_TOOLCHAIN is not set
+CT_SHOW_CT_VERSION=y
+CT_TOOLCHAIN_PKGVERSION=""
+CT_TOOLCHAIN_BUGURL=""
+
+#
+# Tuple completion and aliasing
+#
+CT_TARGET_VENDOR="unknown"
+CT_TARGET_ALIAS_SED_EXPR=""
+CT_TARGET_ALIAS=""
+
+#
+# Toolchain type
+#
+CT_CROSS=y
+# CT_CANADIAN is not set
+CT_TOOLCHAIN_TYPE="cross"
+
+#
+# Build system
+#
+CT_BUILD=""
+CT_BUILD_PREFIX=""
+CT_BUILD_SUFFIX=""
+
+#
+# Misc options
+#
+# CT_TOOLCHAIN_ENABLE_NLS is not set
+
+#
+# Operating System
+#
+CT_KERNEL_SUPPORTS_SHARED_LIBS=y
+# CT_KERNEL_BARE_METAL is not set
+CT_KERNEL_LINUX=y
+CT_KERNEL="linux"
+CT_KERNEL_CHOICE_KSYM="LINUX"
+CT_KERNEL_LINUX_SHOW=y
+
+#
+# Options for linux
+#
+CT_KERNEL_LINUX_PKG_KSYM="LINUX"
+CT_LINUX_DIR_NAME="linux"
+CT_LINUX_PKG_NAME="linux"
+CT_LINUX_SRC_RELEASE=y
+CT_LINUX_PATCH_ORDER="global"
+# CT_LINUX_V_4_20 is not set
+# CT_LINUX_V_4_19 is not set
+# CT_LINUX_V_4_18 is not set
+# CT_LINUX_V_4_17 is not set
+# CT_LINUX_V_4_16 is not set
+# CT_LINUX_V_4_15 is not set
+# CT_LINUX_V_4_14 is not set
+# CT_LINUX_V_4_13 is not set
+# CT_LINUX_V_4_12 is not set
+# CT_LINUX_V_4_11 is not set
+# CT_LINUX_V_4_10 is not set
+# CT_LINUX_V_4_9 is not set
+CT_LINUX_V_4_4=y
+# CT_LINUX_V_4_1 is not set
+# CT_LINUX_V_3_16 is not set
+# CT_LINUX_V_3_13 is not set
+# CT_LINUX_V_3_12 is not set
+# CT_LINUX_V_3_10 is not set
+# CT_LINUX_V_3_4 is not set
+# CT_LINUX_V_3_2 is not set
+# CT_LINUX_V_2_6_32 is not set
+# CT_LINUX_NO_VERSIONS is not set
+CT_LINUX_VERSION="4.4.174"
+CT_LINUX_MIRRORS="$(CT_Mirrors kernel.org linux ${CT_LINUX_VERSION})"
+CT_LINUX_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_LINUX_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_LINUX_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_LINUX_SIGNATURE_FORMAT="unpacked/.sign"
+CT_LINUX_4_8_or_older=y
+CT_LINUX_older_than_4_8=y
+CT_LINUX_later_than_3_7=y
+CT_LINUX_3_7_or_later=y
+CT_LINUX_later_than_3_2=y
+CT_LINUX_3_2_or_later=y
+CT_KERNEL_LINUX_VERBOSITY_0=y
+# CT_KERNEL_LINUX_VERBOSITY_1 is not set
+# CT_KERNEL_LINUX_VERBOSITY_2 is not set
+CT_KERNEL_LINUX_VERBOSE_LEVEL=0
+CT_KERNEL_LINUX_INSTALL_CHECK=y
+CT_ALL_KERNEL_CHOICES="BARE_METAL LINUX WINDOWS"
+
+#
+# Common kernel options
+#
+CT_SHARED_LIBS=y
+
+#
+# Binary utilities
+#
+CT_ARCH_BINFMT_ELF=y
+CT_BINUTILS_BINUTILS=y
+CT_BINUTILS="binutils"
+CT_BINUTILS_CHOICE_KSYM="BINUTILS"
+CT_BINUTILS_BINUTILS_SHOW=y
+
+#
+# Options for binutils
+#
+CT_BINUTILS_BINUTILS_PKG_KSYM="BINUTILS"
+CT_BINUTILS_DIR_NAME="binutils"
+CT_BINUTILS_USE_GNU=y
+CT_BINUTILS_USE="BINUTILS"
+CT_BINUTILS_PKG_NAME="binutils"
+CT_BINUTILS_SRC_RELEASE=y
+CT_BINUTILS_PATCH_ORDER="global"
+CT_BINUTILS_V_2_32=y
+# CT_BINUTILS_V_2_31 is not set
+# CT_BINUTILS_V_2_30 is not set
+# CT_BINUTILS_V_2_29 is not set
+# CT_BINUTILS_V_2_28 is not set
+# CT_BINUTILS_V_2_27 is not set
+# CT_BINUTILS_V_2_26 is not set
+# CT_BINUTILS_NO_VERSIONS is not set
+CT_BINUTILS_VERSION="2.32"
+CT_BINUTILS_MIRRORS="$(CT_Mirrors GNU binutils) $(CT_Mirrors sourceware binutils/releases)"
+CT_BINUTILS_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_BINUTILS_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_BINUTILS_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_BINUTILS_SIGNATURE_FORMAT="packed/.sig"
+CT_BINUTILS_later_than_2_30=y
+CT_BINUTILS_2_30_or_later=y
+CT_BINUTILS_later_than_2_27=y
+CT_BINUTILS_2_27_or_later=y
+CT_BINUTILS_later_than_2_25=y
+CT_BINUTILS_2_25_or_later=y
+CT_BINUTILS_later_than_2_23=y
+CT_BINUTILS_2_23_or_later=y
+
+#
+# GNU binutils
+#
+CT_BINUTILS_HAS_HASH_STYLE=y
+CT_BINUTILS_HAS_GOLD=y
+CT_BINUTILS_HAS_PLUGINS=y
+CT_BINUTILS_HAS_PKGVERSION_BUGURL=y
+CT_BINUTILS_FORCE_LD_BFD_DEFAULT=y
+CT_BINUTILS_LINKER_LD=y
+CT_BINUTILS_LINKERS_LIST="ld"
+CT_BINUTILS_LINKER_DEFAULT="bfd"
+# CT_BINUTILS_PLUGINS is not set
+CT_BINUTILS_RELRO=m
+CT_BINUTILS_EXTRA_CONFIG_ARRAY=""
+# CT_BINUTILS_FOR_TARGET is not set
+CT_ALL_BINUTILS_CHOICES="BINUTILS"
+
+#
+# C-library
+#
+CT_LIBC_GLIBC=y
+# CT_LIBC_UCLIBC is not set
+CT_LIBC="glibc"
+CT_LIBC_CHOICE_KSYM="GLIBC"
+CT_THREADS="nptl"
+CT_LIBC_GLIBC_SHOW=y
+
+#
+# Options for glibc
+#
+CT_LIBC_GLIBC_PKG_KSYM="GLIBC"
+CT_GLIBC_DIR_NAME="glibc"
+CT_GLIBC_USE_GNU=y
+CT_GLIBC_USE="GLIBC"
+CT_GLIBC_PKG_NAME="glibc"
+CT_GLIBC_SRC_RELEASE=y
+CT_GLIBC_PATCH_ORDER="global"
+# CT_GLIBC_V_2_29 is not set
+# CT_GLIBC_V_2_28 is not set
+# CT_GLIBC_V_2_27 is not set
+# CT_GLIBC_V_2_26 is not set
+# CT_GLIBC_V_2_25 is not set
+# CT_GLIBC_V_2_24 is not set
+CT_GLIBC_V_2_23=y
+# CT_GLIBC_V_2_19 is not set
+# CT_GLIBC_V_2_17 is not set
+# CT_GLIBC_V_2_12_1 is not set
+# CT_GLIBC_NO_VERSIONS is not set
+CT_GLIBC_VERSION="2.23"
+CT_GLIBC_MIRRORS="$(CT_Mirrors GNU glibc)"
+CT_GLIBC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GLIBC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GLIBC_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_GLIBC_SIGNATURE_FORMAT="packed/.sig"
+CT_GLIBC_2_29_or_older=y
+CT_GLIBC_older_than_2_29=y
+CT_GLIBC_2_27_or_older=y
+CT_GLIBC_older_than_2_27=y
+CT_GLIBC_2_26_or_older=y
+CT_GLIBC_older_than_2_26=y
+CT_GLIBC_2_25_or_older=y
+CT_GLIBC_older_than_2_25=y
+CT_GLIBC_2_24_or_older=y
+CT_GLIBC_older_than_2_24=y
+CT_GLIBC_2_23_or_later=y
+CT_GLIBC_2_23_or_older=y
+CT_GLIBC_later_than_2_20=y
+CT_GLIBC_2_20_or_later=y
+CT_GLIBC_later_than_2_17=y
+CT_GLIBC_2_17_or_later=y
+CT_GLIBC_later_than_2_14=y
+CT_GLIBC_2_14_or_later=y
+CT_GLIBC_DEP_KERNEL_HEADERS_VERSION=y
+CT_GLIBC_DEP_BINUTILS=y
+CT_GLIBC_DEP_GCC=y
+CT_GLIBC_DEP_PYTHON=y
+CT_GLIBC_HAS_LIBIDN_ADDON=y
+# CT_GLIBC_USE_LIBIDN_ADDON is not set
+CT_GLIBC_NO_SPARC_V8=y
+CT_GLIBC_HAS_OBSOLETE_RPC=y
+CT_GLIBC_EXTRA_CONFIG_ARRAY=""
+CT_GLIBC_CONFIGPARMS=""
+CT_GLIBC_EXTRA_CFLAGS=""
+CT_GLIBC_ENABLE_OBSOLETE_RPC=y
+# CT_GLIBC_DISABLE_VERSIONING is not set
+CT_GLIBC_OLDEST_ABI=""
+CT_GLIBC_FORCE_UNWIND=y
+# CT_GLIBC_LOCALES is not set
+# CT_GLIBC_KERNEL_VERSION_NONE is not set
+CT_GLIBC_KERNEL_VERSION_AS_HEADERS=y
+# CT_GLIBC_KERNEL_VERSION_CHOSEN is not set
+CT_GLIBC_MIN_KERNEL="4.4.174"
+CT_ALL_LIBC_CHOICES="AVR_LIBC BIONIC GLIBC MINGW_W64 MOXIEBOX MUSL NEWLIB NONE UCLIBC"
+CT_LIBC_SUPPORT_THREADS_ANY=y
+CT_LIBC_SUPPORT_THREADS_NATIVE=y
+
+#
+# Common C library options
+#
+CT_THREADS_NATIVE=y
+# CT_CREATE_LDSO_CONF is not set
+CT_LIBC_XLDD=y
+
+#
+# C compiler
+#
+CT_CC_CORE_PASSES_NEEDED=y
+CT_CC_CORE_PASS_1_NEEDED=y
+CT_CC_CORE_PASS_2_NEEDED=y
+CT_CC_SUPPORT_CXX=y
+CT_CC_SUPPORT_FORTRAN=y
+CT_CC_SUPPORT_ADA=y
+CT_CC_SUPPORT_OBJC=y
+CT_CC_SUPPORT_OBJCXX=y
+CT_CC_SUPPORT_GOLANG=y
+CT_CC_GCC=y
+CT_CC="gcc"
+CT_CC_CHOICE_KSYM="GCC"
+CT_CC_GCC_SHOW=y
+
+#
+# Options for gcc
+#
+CT_CC_GCC_PKG_KSYM="GCC"
+CT_GCC_DIR_NAME="gcc"
+CT_GCC_USE_GNU=y
+CT_GCC_USE="GCC"
+CT_GCC_PKG_NAME="gcc"
+CT_GCC_SRC_RELEASE=y
+CT_GCC_PATCH_ORDER="global"
+CT_GCC_V_8=y
+# CT_GCC_V_7 is not set
+# CT_GCC_V_6 is not set
+# CT_GCC_V_5 is not set
+# CT_GCC_V_4_9 is not set
+# CT_GCC_NO_VERSIONS is not set
+CT_GCC_VERSION="8.3.0"
+CT_GCC_MIRRORS="$(CT_Mirrors GNU gcc/gcc-${CT_GCC_VERSION}) $(CT_Mirrors sourceware gcc/releases/gcc-${CT_GCC_VERSION})"
+CT_GCC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GCC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GCC_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_GCC_SIGNATURE_FORMAT=""
+CT_GCC_later_than_7=y
+CT_GCC_7_or_later=y
+CT_GCC_later_than_6=y
+CT_GCC_6_or_later=y
+CT_GCC_later_than_5=y
+CT_GCC_5_or_later=y
+CT_GCC_later_than_4_9=y
+CT_GCC_4_9_or_later=y
+CT_GCC_later_than_4_8=y
+CT_GCC_4_8_or_later=y
+CT_CC_GCC_HAS_LIBMPX=y
+CT_CC_GCC_ENABLE_CXX_FLAGS=""
+CT_CC_GCC_CORE_EXTRA_CONFIG_ARRAY=""
+CT_CC_GCC_EXTRA_CONFIG_ARRAY=""
+CT_CC_GCC_STATIC_LIBSTDCXX=y
+# CT_CC_GCC_SYSTEM_ZLIB is not set
+CT_CC_GCC_CONFIG_TLS=m
+
+#
+# Optimisation features
+#
+CT_CC_GCC_USE_GRAPHITE=y
+CT_CC_GCC_USE_LTO=y
+
+#
+# Settings for libraries running on target
+#
+CT_CC_GCC_ENABLE_TARGET_OPTSPACE=y
+# CT_CC_GCC_LIBMUDFLAP is not set
+# CT_CC_GCC_LIBGOMP is not set
+# CT_CC_GCC_LIBSSP is not set
+# CT_CC_GCC_LIBQUADMATH is not set
+# CT_CC_GCC_LIBSANITIZER is not set
+
+#
+# Misc. obscure options.
+#
+CT_CC_CXA_ATEXIT=y
+# CT_CC_GCC_DISABLE_PCH is not set
+CT_CC_GCC_SJLJ_EXCEPTIONS=m
+CT_CC_GCC_LDBL_128=m
+# CT_CC_GCC_BUILD_ID is not set
+CT_CC_GCC_LNK_HASH_STYLE_DEFAULT=y
+# CT_CC_GCC_LNK_HASH_STYLE_SYSV is not set
+# CT_CC_GCC_LNK_HASH_STYLE_GNU is not set
+# CT_CC_GCC_LNK_HASH_STYLE_BOTH is not set
+CT_CC_GCC_LNK_HASH_STYLE=""
+CT_CC_GCC_DEC_FLOAT_AUTO=y
+# CT_CC_GCC_DEC_FLOAT_BID is not set
+# CT_CC_GCC_DEC_FLOAT_DPD is not set
+# CT_CC_GCC_DEC_FLOATS_NO is not set
+CT_CC_GCC_HAS_ARCH_OPTIONS=y
+
+#
+# archictecture-specific options
+#
+CT_CC_GCC_mips_llsc=m
+CT_CC_GCC_mips_synci=m
+# CT_CC_GCC_mips_plt is not set
+CT_ALL_CC_CHOICES="GCC"
+
+#
+# Additional supported languages:
+#
+CT_CC_LANG_CXX=y
+# CT_CC_LANG_FORTRAN is not set
+
+#
+# Debug facilities
+#
+# CT_DEBUG_DUMA is not set
+# CT_DEBUG_GDB is not set
+# CT_DEBUG_LTRACE is not set
+# CT_DEBUG_STRACE is not set
+CT_ALL_DEBUG_CHOICES="DUMA GDB LTRACE STRACE"
+
+#
+# Companion libraries
+#
+# CT_COMPLIBS_CHECK is not set
+# CT_COMP_LIBS_CLOOG is not set
+# CT_COMP_LIBS_EXPAT is not set
+CT_COMP_LIBS_GETTEXT=y
+CT_COMP_LIBS_GETTEXT_PKG_KSYM="GETTEXT"
+CT_GETTEXT_DIR_NAME="gettext"
+CT_GETTEXT_PKG_NAME="gettext"
+CT_GETTEXT_SRC_RELEASE=y
+CT_GETTEXT_PATCH_ORDER="global"
+CT_GETTEXT_V_0_19_8_1=y
+# CT_GETTEXT_NO_VERSIONS is not set
+CT_GETTEXT_VERSION="0.19.8.1"
+CT_GETTEXT_MIRRORS="$(CT_Mirrors GNU gettext)"
+CT_GETTEXT_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GETTEXT_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GETTEXT_ARCHIVE_FORMATS=".tar.xz .tar.lz .tar.gz"
+CT_GETTEXT_SIGNATURE_FORMAT="packed/.sig"
+CT_COMP_LIBS_GMP=y
+CT_COMP_LIBS_GMP_PKG_KSYM="GMP"
+CT_GMP_DIR_NAME="gmp"
+CT_GMP_PKG_NAME="gmp"
+CT_GMP_SRC_RELEASE=y
+CT_GMP_PATCH_ORDER="global"
+CT_GMP_V_6_1=y
+# CT_GMP_NO_VERSIONS is not set
+CT_GMP_VERSION="6.1.2"
+CT_GMP_MIRRORS="https://gmplib.org/download/gmp https://gmplib.org/download/gmp/archive $(CT_Mirrors GNU gmp)"
+CT_GMP_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GMP_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GMP_ARCHIVE_FORMATS=".tar.xz .tar.lz .tar.bz2"
+CT_GMP_SIGNATURE_FORMAT="packed/.sig"
+CT_GMP_later_than_5_1_0=y
+CT_GMP_5_1_0_or_later=y
+CT_GMP_later_than_5_0_0=y
+CT_GMP_5_0_0_or_later=y
+CT_GMP_REQUIRE_5_0_0_or_later=y
+CT_COMP_LIBS_ISL=y
+CT_COMP_LIBS_ISL_PKG_KSYM="ISL"
+CT_ISL_DIR_NAME="isl"
+CT_ISL_PKG_NAME="isl"
+CT_ISL_SRC_RELEASE=y
+CT_ISL_PATCH_ORDER="global"
+CT_ISL_V_0_20=y
+# CT_ISL_V_0_19 is not set
+# CT_ISL_V_0_18 is not set
+# CT_ISL_V_0_17 is not set
+# CT_ISL_V_0_16 is not set
+# CT_ISL_V_0_15 is not set
+# CT_ISL_NO_VERSIONS is not set
+CT_ISL_VERSION="0.20"
+CT_ISL_MIRRORS="http://isl.gforge.inria.fr"
+CT_ISL_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_ISL_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_ISL_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_ISL_SIGNATURE_FORMAT=""
+CT_ISL_later_than_0_18=y
+CT_ISL_0_18_or_later=y
+CT_ISL_later_than_0_15=y
+CT_ISL_0_15_or_later=y
+CT_ISL_REQUIRE_0_15_or_later=y
+CT_ISL_later_than_0_14=y
+CT_ISL_0_14_or_later=y
+CT_ISL_REQUIRE_0_14_or_later=y
+CT_ISL_later_than_0_13=y
+CT_ISL_0_13_or_later=y
+CT_ISL_later_than_0_12=y
+CT_ISL_0_12_or_later=y
+CT_ISL_REQUIRE_0_12_or_later=y
+# CT_COMP_LIBS_LIBELF is not set
+CT_COMP_LIBS_LIBICONV=y
+CT_COMP_LIBS_LIBICONV_PKG_KSYM="LIBICONV"
+CT_LIBICONV_DIR_NAME="libiconv"
+CT_LIBICONV_PKG_NAME="libiconv"
+CT_LIBICONV_SRC_RELEASE=y
+CT_LIBICONV_PATCH_ORDER="global"
+CT_LIBICONV_V_1_15=y
+# CT_LIBICONV_NO_VERSIONS is not set
+CT_LIBICONV_VERSION="1.15"
+CT_LIBICONV_MIRRORS="$(CT_Mirrors GNU libiconv)"
+CT_LIBICONV_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_LIBICONV_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_LIBICONV_ARCHIVE_FORMATS=".tar.gz"
+CT_LIBICONV_SIGNATURE_FORMAT="packed/.sig"
+CT_COMP_LIBS_MPC=y
+CT_COMP_LIBS_MPC_PKG_KSYM="MPC"
+CT_MPC_DIR_NAME="mpc"
+CT_MPC_PKG_NAME="mpc"
+CT_MPC_SRC_RELEASE=y
+CT_MPC_PATCH_ORDER="global"
+CT_MPC_V_1_1=y
+# CT_MPC_V_1_0 is not set
+# CT_MPC_NO_VERSIONS is not set
+CT_MPC_VERSION="1.1.0"
+CT_MPC_MIRRORS="http://www.multiprecision.org/downloads $(CT_Mirrors GNU mpc)"
+CT_MPC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_MPC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_MPC_ARCHIVE_FORMATS=".tar.gz"
+CT_MPC_SIGNATURE_FORMAT="packed/.sig"
+CT_MPC_1_1_0_or_later=y
+CT_MPC_1_1_0_or_older=y
+CT_COMP_LIBS_MPFR=y
+CT_COMP_LIBS_MPFR_PKG_KSYM="MPFR"
+CT_MPFR_DIR_NAME="mpfr"
+CT_MPFR_PKG_NAME="mpfr"
+CT_MPFR_SRC_RELEASE=y
+CT_MPFR_PATCH_ORDER="global"
+CT_MPFR_V_4_0=y
+# CT_MPFR_V_3_1 is not set
+# CT_MPFR_NO_VERSIONS is not set
+CT_MPFR_VERSION="4.0.2"
+CT_MPFR_MIRRORS="http://www.mpfr.org/mpfr-${CT_MPFR_VERSION} $(CT_Mirrors GNU mpfr)"
+CT_MPFR_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_MPFR_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_MPFR_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz .zip"
+CT_MPFR_SIGNATURE_FORMAT="packed/.asc"
+CT_MPFR_later_than_4_0_0=y
+CT_MPFR_4_0_0_or_later=y
+CT_MPFR_later_than_3_0_0=y
+CT_MPFR_3_0_0_or_later=y
+CT_MPFR_REQUIRE_3_0_0_or_later=y
+CT_COMP_LIBS_NCURSES=y
+CT_COMP_LIBS_NCURSES_PKG_KSYM="NCURSES"
+CT_NCURSES_DIR_NAME="ncurses"
+CT_NCURSES_PKG_NAME="ncurses"
+CT_NCURSES_SRC_RELEASE=y
+CT_NCURSES_PATCH_ORDER="global"
+CT_NCURSES_V_6_1=y
+# CT_NCURSES_V_6_0 is not set
+# CT_NCURSES_NO_VERSIONS is not set
+CT_NCURSES_VERSION="6.1"
+CT_NCURSES_MIRRORS="ftp://invisible-island.net/ncurses $(CT_Mirrors GNU ncurses)"
+CT_NCURSES_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_NCURSES_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_NCURSES_ARCHIVE_FORMATS=".tar.gz"
+CT_NCURSES_SIGNATURE_FORMAT="packed/.sig"
+CT_NCURSES_HOST_CONFIG_ARGS=""
+CT_NCURSES_HOST_DISABLE_DB=y
+CT_NCURSES_HOST_FALLBACKS="linux,xterm,xterm-color,xterm-256color,vt100"
+CT_NCURSES_TARGET_CONFIG_ARGS=""
+# CT_NCURSES_TARGET_DISABLE_DB is not set
+CT_NCURSES_TARGET_FALLBACKS=""
+CT_COMP_LIBS_ZLIB=y
+CT_COMP_LIBS_ZLIB_PKG_KSYM="ZLIB"
+CT_ZLIB_DIR_NAME="zlib"
+CT_ZLIB_PKG_NAME="zlib"
+CT_ZLIB_SRC_RELEASE=y
+CT_ZLIB_PATCH_ORDER="global"
+CT_ZLIB_V_1_2_11=y
+# CT_ZLIB_NO_VERSIONS is not set
+CT_ZLIB_VERSION="1.2.11"
+CT_ZLIB_MIRRORS="http://downloads.sourceforge.net/project/libpng/zlib/${CT_ZLIB_VERSION}"
+CT_ZLIB_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_ZLIB_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_ZLIB_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_ZLIB_SIGNATURE_FORMAT="packed/.asc"
+CT_ALL_COMP_LIBS_CHOICES="CLOOG EXPAT GETTEXT GMP ISL LIBELF LIBICONV MPC MPFR NCURSES ZLIB"
+CT_LIBICONV_NEEDED=y
+CT_GETTEXT_NEEDED=y
+CT_GMP_NEEDED=y
+CT_MPFR_NEEDED=y
+CT_ISL_NEEDED=y
+CT_MPC_NEEDED=y
+CT_NCURSES_NEEDED=y
+CT_ZLIB_NEEDED=y
+CT_LIBICONV=y
+CT_GETTEXT=y
+CT_GMP=y
+CT_MPFR=y
+CT_ISL=y
+CT_MPC=y
+CT_NCURSES=y
+CT_ZLIB=y
+
+#
+# Companion tools
+#
+# CT_COMP_TOOLS_FOR_HOST is not set
+# CT_COMP_TOOLS_AUTOCONF is not set
+# CT_COMP_TOOLS_AUTOMAKE is not set
+# CT_COMP_TOOLS_BISON is not set
+# CT_COMP_TOOLS_DTC is not set
+# CT_COMP_TOOLS_LIBTOOL is not set
+# CT_COMP_TOOLS_M4 is not set
+# CT_COMP_TOOLS_MAKE is not set
+CT_ALL_COMP_TOOLS_CHOICES="AUTOCONF AUTOMAKE BISON DTC LIBTOOL M4 MAKE"
diff --git a/src/ci/docker/host-x86_64/dist-mips64el-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-mips64el-linux/Dockerfile
index 376bdfb4a..b90950f73 100644
--- a/src/ci/docker/host-x86_64/dist-mips64el-linux/Dockerfile
+++ b/src/ci/docker/host-x86_64/dist-mips64el-linux/Dockerfile
@@ -1,31 +1,30 @@
-FROM ubuntu:16.04
-
-RUN apt-get update && apt-get install -y --no-install-recommends \
- g++ \
- make \
- ninja-build \
- file \
- curl \
- ca-certificates \
- python3 \
- git \
- cmake \
- sudo \
- gdb \
- xz-utils \
- g++-mips64el-linux-gnuabi64 \
- libssl-dev \
- pkg-config
+FROM ubuntu:22.04
+COPY scripts/cross-apt-packages.sh /scripts/
+RUN sh /scripts/cross-apt-packages.sh
+
+COPY scripts/crosstool-ng-1.24.sh /scripts/
+RUN sh /scripts/crosstool-ng-1.24.sh
+
+COPY scripts/rustbuild-setup.sh /scripts/
+RUN sh /scripts/rustbuild-setup.sh
+WORKDIR /tmp
+
+COPY host-x86_64/dist-mips-linux/patches/ /tmp/patches/
+COPY host-x86_64/dist-mips64el-linux/mips64el-linux-gnu.config host-x86_64/dist-mips64el-linux/build-mips64el-toolchain.sh /tmp/
+RUN su rustbuild -c ./build-mips64el-toolchain.sh
COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh
-COPY scripts/cmake.sh /scripts/
-RUN /scripts/cmake.sh
+ENV PATH=$PATH:/x-tools/mips64el-unknown-linux-gnu/bin
+
+ENV \
+ CC_mips64el_unknown_linux_gnuabi64=mips64el-unknown-linux-gnu-gcc \
+ AR_mips64el_unknown_linux_gnuabi64=mips64el-unknown-linux-gnu-ar \
+ CXX_mips64el_unknown_linux_gnuabi64=mips64el-unknown-linux-gnu-g++
ENV HOSTS=mips64el-unknown-linux-gnuabi64
-ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs \
- --set llvm.allow-old-toolchain
+ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs
ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS
diff --git a/src/ci/docker/host-x86_64/dist-mips64el-linux/build-mips64el-toolchain.sh b/src/ci/docker/host-x86_64/dist-mips64el-linux/build-mips64el-toolchain.sh
new file mode 100755
index 000000000..1ad406800
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-mips64el-linux/build-mips64el-toolchain.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+set -ex
+
+hide_output() {
+ set +x
+ on_err="
+echo ERROR: An error was encountered with the build.
+cat /tmp/build.log
+exit 1
+"
+ trap "$on_err" ERR
+ bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
+ PING_LOOP_PID=$!
+ "$@" &> /tmp/build.log
+ rm /tmp/build.log
+ trap - ERR
+ kill $PING_LOOP_PID
+ set -x
+}
+
+mkdir build
+cd build
+cp ../mips64el-linux-gnu.config .config
+hide_output ct-ng build
+cd ..
+rm -rf build
diff --git a/src/ci/docker/host-x86_64/dist-mips64el-linux/mips64el-linux-gnu.config b/src/ci/docker/host-x86_64/dist-mips64el-linux/mips64el-linux-gnu.config
new file mode 100644
index 000000000..baff944cf
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-mips64el-linux/mips64el-linux-gnu.config
@@ -0,0 +1,741 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# crosstool-NG Configuration
+#
+CT_CONFIGURE_has_static_link=y
+CT_CONFIGURE_has_cxx11=y
+CT_CONFIGURE_has_wget=y
+CT_CONFIGURE_has_curl=y
+CT_CONFIGURE_has_make_3_81_or_newer=y
+CT_CONFIGURE_has_make_4_0_or_newer=y
+CT_CONFIGURE_has_libtool_2_4_or_newer=y
+CT_CONFIGURE_has_libtoolize_2_4_or_newer=y
+CT_CONFIGURE_has_autoconf_2_65_or_newer=y
+CT_CONFIGURE_has_autoreconf_2_65_or_newer=y
+CT_CONFIGURE_has_automake_1_15_or_newer=y
+CT_CONFIGURE_has_gnu_m4_1_4_12_or_newer=y
+CT_CONFIGURE_has_python_3_4_or_newer=y
+CT_CONFIGURE_has_bison_2_7_or_newer=y
+CT_CONFIGURE_has_python=y
+CT_CONFIGURE_has_git=y
+CT_CONFIGURE_has_md5sum=y
+CT_CONFIGURE_has_sha1sum=y
+CT_CONFIGURE_has_sha256sum=y
+CT_CONFIGURE_has_sha512sum=y
+CT_CONFIGURE_has_install_with_strip_program=y
+CT_CONFIG_VERSION_CURRENT="3"
+CT_CONFIG_VERSION="3"
+CT_MODULES=y
+
+#
+# Paths and misc options
+#
+
+#
+# crosstool-NG behavior
+#
+# CT_OBSOLETE is not set
+# CT_EXPERIMENTAL is not set
+# CT_DEBUG_CT is not set
+
+#
+# Paths
+#
+CT_LOCAL_TARBALLS_DIR="${HOME}/src"
+CT_SAVE_TARBALLS=y
+# CT_TARBALLS_BUILDROOT_LAYOUT is not set
+CT_WORK_DIR="${CT_TOP_DIR}/.build"
+CT_BUILD_TOP_DIR="${CT_WORK_DIR:-${CT_TOP_DIR}/.build}/${CT_HOST:+HOST-${CT_HOST}/}${CT_TARGET}"
+CT_PREFIX_DIR="/x-tools/${CT_TARGET}"
+CT_RM_RF_PREFIX_DIR=y
+CT_REMOVE_DOCS=y
+CT_INSTALL_LICENSES=y
+CT_PREFIX_DIR_RO=y
+CT_STRIP_HOST_TOOLCHAIN_EXECUTABLES=y
+# CT_STRIP_TARGET_TOOLCHAIN_EXECUTABLES is not set
+
+#
+# Downloading
+#
+CT_DOWNLOAD_AGENT_WGET=y
+# CT_DOWNLOAD_AGENT_CURL is not set
+# CT_DOWNLOAD_AGENT_NONE is not set
+# CT_FORBID_DOWNLOAD is not set
+# CT_FORCE_DOWNLOAD is not set
+CT_CONNECT_TIMEOUT=10
+CT_DOWNLOAD_WGET_OPTIONS="--passive-ftp --tries=3 -nc --progress=dot:binary"
+# CT_ONLY_DOWNLOAD is not set
+CT_USE_MIRROR=y
+# CT_FORCE_MIRROR is not set
+CT_MIRROR_BASE_URL="https://ci-mirrors.rust-lang.org/rustc"
+CT_VERIFY_DOWNLOAD_DIGEST=y
+CT_VERIFY_DOWNLOAD_DIGEST_SHA512=y
+# CT_VERIFY_DOWNLOAD_DIGEST_SHA256 is not set
+# CT_VERIFY_DOWNLOAD_DIGEST_SHA1 is not set
+# CT_VERIFY_DOWNLOAD_DIGEST_MD5 is not set
+CT_VERIFY_DOWNLOAD_DIGEST_ALG="sha512"
+# CT_VERIFY_DOWNLOAD_SIGNATURE is not set
+
+#
+# Extracting
+#
+# CT_FORCE_EXTRACT is not set
+CT_OVERRIDE_CONFIG_GUESS_SUB=y
+# CT_ONLY_EXTRACT is not set
+# CT_PATCH_BUNDLED is not set
+CT_PATCH_BUNDLED_LOCAL=y
+CT_PATCH_ORDER="bundled,local"
+CT_PATCH_USE_LOCAL=y
+CT_LOCAL_PATCH_DIR="/tmp/patches"
+
+#
+# Build behavior
+#
+CT_PARALLEL_JOBS=0
+CT_LOAD=""
+CT_USE_PIPES=y
+CT_EXTRA_CFLAGS_FOR_BUILD=""
+CT_EXTRA_LDFLAGS_FOR_BUILD=""
+CT_EXTRA_CFLAGS_FOR_HOST=""
+CT_EXTRA_LDFLAGS_FOR_HOST=""
+# CT_CONFIG_SHELL_SH is not set
+# CT_CONFIG_SHELL_ASH is not set
+CT_CONFIG_SHELL_BASH=y
+# CT_CONFIG_SHELL_CUSTOM is not set
+CT_CONFIG_SHELL="${bash}"
+
+#
+# Logging
+#
+# CT_LOG_ERROR is not set
+# CT_LOG_WARN is not set
+# CT_LOG_INFO is not set
+CT_LOG_EXTRA=y
+# CT_LOG_ALL is not set
+# CT_LOG_DEBUG is not set
+CT_LOG_LEVEL_MAX="EXTRA"
+# CT_LOG_SEE_TOOLS_WARN is not set
+CT_LOG_PROGRESS_BAR=y
+CT_LOG_TO_FILE=y
+CT_LOG_FILE_COMPRESS=y
+
+#
+# Target options
+#
+# CT_ARCH_ALPHA is not set
+# CT_ARCH_ARC is not set
+# CT_ARCH_ARM is not set
+# CT_ARCH_AVR is not set
+# CT_ARCH_M68K is not set
+CT_ARCH_MIPS=y
+# CT_ARCH_NIOS2 is not set
+# CT_ARCH_POWERPC is not set
+# CT_ARCH_S390 is not set
+# CT_ARCH_SH is not set
+# CT_ARCH_SPARC is not set
+# CT_ARCH_X86 is not set
+# CT_ARCH_XTENSA is not set
+CT_ARCH="mips"
+CT_ARCH_CHOICE_KSYM="MIPS"
+CT_ARCH_TUNE=""
+CT_ARCH_MIPS_SHOW=y
+
+#
+# Options for mips
+#
+CT_ARCH_MIPS_PKG_KSYM=""
+# CT_ARCH_mips_n32 is not set
+CT_ARCH_mips_n64=y
+CT_ARCH_mips_ABI="64"
+CT_ALL_ARCH_CHOICES="ALPHA ARC ARM AVR M68K MICROBLAZE MIPS MOXIE MSP430 NIOS2 POWERPC RISCV S390 SH SPARC X86 XTENSA"
+CT_ARCH_SUFFIX=""
+# CT_OMIT_TARGET_VENDOR is not set
+
+#
+# Generic target options
+#
+# CT_MULTILIB is not set
+CT_DEMULTILIB=y
+CT_ARCH_USE_MMU=y
+CT_ARCH_SUPPORTS_EITHER_ENDIAN=y
+CT_ARCH_DEFAULT_BE=y
+# CT_ARCH_BE is not set
+CT_ARCH_LE=y
+CT_ARCH_ENDIAN="little"
+CT_ARCH_SUPPORTS_32=y
+CT_ARCH_SUPPORTS_64=y
+CT_ARCH_DEFAULT_32=y
+CT_ARCH_BITNESS=64
+# CT_ARCH_32 is not set
+CT_ARCH_64=y
+
+#
+# Target optimisations
+#
+CT_ARCH_SUPPORTS_WITH_ARCH=y
+CT_ARCH_SUPPORTS_WITH_TUNE=y
+CT_ARCH_SUPPORTS_WITH_FLOAT=y
+CT_ARCH_ARCH="mips64r2"
+CT_ARCH_FLOAT_AUTO=y
+# CT_ARCH_FLOAT_HW is not set
+# CT_ARCH_FLOAT_SW is not set
+CT_TARGET_CFLAGS=""
+CT_TARGET_LDFLAGS=""
+CT_ARCH_FLOAT="auto"
+
+#
+# Toolchain options
+#
+
+#
+# General toolchain options
+#
+CT_FORCE_SYSROOT=y
+CT_USE_SYSROOT=y
+CT_SYSROOT_NAME="sysroot"
+CT_SYSROOT_DIR_PREFIX=""
+CT_WANTS_STATIC_LINK=y
+CT_WANTS_STATIC_LINK_CXX=y
+# CT_STATIC_TOOLCHAIN is not set
+CT_SHOW_CT_VERSION=y
+CT_TOOLCHAIN_PKGVERSION=""
+CT_TOOLCHAIN_BUGURL=""
+
+#
+# Tuple completion and aliasing
+#
+CT_TARGET_VENDOR="unknown"
+CT_TARGET_ALIAS_SED_EXPR=""
+CT_TARGET_ALIAS=""
+
+#
+# Toolchain type
+#
+CT_CROSS=y
+# CT_CANADIAN is not set
+CT_TOOLCHAIN_TYPE="cross"
+
+#
+# Build system
+#
+CT_BUILD=""
+CT_BUILD_PREFIX=""
+CT_BUILD_SUFFIX=""
+
+#
+# Misc options
+#
+# CT_TOOLCHAIN_ENABLE_NLS is not set
+
+#
+# Operating System
+#
+CT_KERNEL_SUPPORTS_SHARED_LIBS=y
+# CT_KERNEL_BARE_METAL is not set
+CT_KERNEL_LINUX=y
+CT_KERNEL="linux"
+CT_KERNEL_CHOICE_KSYM="LINUX"
+CT_KERNEL_LINUX_SHOW=y
+
+#
+# Options for linux
+#
+CT_KERNEL_LINUX_PKG_KSYM="LINUX"
+CT_LINUX_DIR_NAME="linux"
+CT_LINUX_PKG_NAME="linux"
+CT_LINUX_SRC_RELEASE=y
+CT_LINUX_PATCH_ORDER="global"
+# CT_LINUX_V_4_20 is not set
+# CT_LINUX_V_4_19 is not set
+# CT_LINUX_V_4_18 is not set
+# CT_LINUX_V_4_17 is not set
+# CT_LINUX_V_4_16 is not set
+# CT_LINUX_V_4_15 is not set
+# CT_LINUX_V_4_14 is not set
+# CT_LINUX_V_4_13 is not set
+# CT_LINUX_V_4_12 is not set
+# CT_LINUX_V_4_11 is not set
+# CT_LINUX_V_4_10 is not set
+# CT_LINUX_V_4_9 is not set
+CT_LINUX_V_4_4=y
+# CT_LINUX_V_4_1 is not set
+# CT_LINUX_V_3_16 is not set
+# CT_LINUX_V_3_13 is not set
+# CT_LINUX_V_3_12 is not set
+# CT_LINUX_V_3_10 is not set
+# CT_LINUX_V_3_4 is not set
+# CT_LINUX_V_3_2 is not set
+# CT_LINUX_V_2_6_32 is not set
+# CT_LINUX_NO_VERSIONS is not set
+CT_LINUX_VERSION="4.4.174"
+CT_LINUX_MIRRORS="$(CT_Mirrors kernel.org linux ${CT_LINUX_VERSION})"
+CT_LINUX_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_LINUX_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_LINUX_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_LINUX_SIGNATURE_FORMAT="unpacked/.sign"
+CT_LINUX_4_8_or_older=y
+CT_LINUX_older_than_4_8=y
+CT_LINUX_later_than_3_7=y
+CT_LINUX_3_7_or_later=y
+CT_LINUX_later_than_3_2=y
+CT_LINUX_3_2_or_later=y
+CT_KERNEL_LINUX_VERBOSITY_0=y
+# CT_KERNEL_LINUX_VERBOSITY_1 is not set
+# CT_KERNEL_LINUX_VERBOSITY_2 is not set
+CT_KERNEL_LINUX_VERBOSE_LEVEL=0
+CT_KERNEL_LINUX_INSTALL_CHECK=y
+CT_ALL_KERNEL_CHOICES="BARE_METAL LINUX WINDOWS"
+
+#
+# Common kernel options
+#
+CT_SHARED_LIBS=y
+
+#
+# Binary utilities
+#
+CT_ARCH_BINFMT_ELF=y
+CT_BINUTILS_BINUTILS=y
+CT_BINUTILS="binutils"
+CT_BINUTILS_CHOICE_KSYM="BINUTILS"
+CT_BINUTILS_BINUTILS_SHOW=y
+
+#
+# Options for binutils
+#
+CT_BINUTILS_BINUTILS_PKG_KSYM="BINUTILS"
+CT_BINUTILS_DIR_NAME="binutils"
+CT_BINUTILS_USE_GNU=y
+CT_BINUTILS_USE="BINUTILS"
+CT_BINUTILS_PKG_NAME="binutils"
+CT_BINUTILS_SRC_RELEASE=y
+CT_BINUTILS_PATCH_ORDER="global"
+CT_BINUTILS_V_2_32=y
+# CT_BINUTILS_V_2_31 is not set
+# CT_BINUTILS_V_2_30 is not set
+# CT_BINUTILS_V_2_29 is not set
+# CT_BINUTILS_V_2_28 is not set
+# CT_BINUTILS_V_2_27 is not set
+# CT_BINUTILS_V_2_26 is not set
+# CT_BINUTILS_NO_VERSIONS is not set
+CT_BINUTILS_VERSION="2.32"
+CT_BINUTILS_MIRRORS="$(CT_Mirrors GNU binutils) $(CT_Mirrors sourceware binutils/releases)"
+CT_BINUTILS_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_BINUTILS_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_BINUTILS_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_BINUTILS_SIGNATURE_FORMAT="packed/.sig"
+CT_BINUTILS_later_than_2_30=y
+CT_BINUTILS_2_30_or_later=y
+CT_BINUTILS_later_than_2_27=y
+CT_BINUTILS_2_27_or_later=y
+CT_BINUTILS_later_than_2_25=y
+CT_BINUTILS_2_25_or_later=y
+CT_BINUTILS_later_than_2_23=y
+CT_BINUTILS_2_23_or_later=y
+
+#
+# GNU binutils
+#
+CT_BINUTILS_HAS_HASH_STYLE=y
+CT_BINUTILS_HAS_GOLD=y
+CT_BINUTILS_HAS_PLUGINS=y
+CT_BINUTILS_HAS_PKGVERSION_BUGURL=y
+CT_BINUTILS_FORCE_LD_BFD_DEFAULT=y
+CT_BINUTILS_LINKER_LD=y
+CT_BINUTILS_LINKERS_LIST="ld"
+CT_BINUTILS_LINKER_DEFAULT="bfd"
+# CT_BINUTILS_PLUGINS is not set
+CT_BINUTILS_RELRO=m
+CT_BINUTILS_EXTRA_CONFIG_ARRAY=""
+# CT_BINUTILS_FOR_TARGET is not set
+CT_ALL_BINUTILS_CHOICES="BINUTILS"
+
+#
+# C-library
+#
+CT_LIBC_GLIBC=y
+# CT_LIBC_UCLIBC is not set
+CT_LIBC="glibc"
+CT_LIBC_CHOICE_KSYM="GLIBC"
+CT_THREADS="nptl"
+CT_LIBC_GLIBC_SHOW=y
+
+#
+# Options for glibc
+#
+CT_LIBC_GLIBC_PKG_KSYM="GLIBC"
+CT_GLIBC_DIR_NAME="glibc"
+CT_GLIBC_USE_GNU=y
+CT_GLIBC_USE="GLIBC"
+CT_GLIBC_PKG_NAME="glibc"
+CT_GLIBC_SRC_RELEASE=y
+CT_GLIBC_PATCH_ORDER="global"
+# CT_GLIBC_V_2_29 is not set
+# CT_GLIBC_V_2_28 is not set
+# CT_GLIBC_V_2_27 is not set
+# CT_GLIBC_V_2_26 is not set
+# CT_GLIBC_V_2_25 is not set
+# CT_GLIBC_V_2_24 is not set
+CT_GLIBC_V_2_23=y
+# CT_GLIBC_V_2_19 is not set
+# CT_GLIBC_V_2_17 is not set
+# CT_GLIBC_V_2_12_1 is not set
+# CT_GLIBC_NO_VERSIONS is not set
+CT_GLIBC_VERSION="2.23"
+CT_GLIBC_MIRRORS="$(CT_Mirrors GNU glibc)"
+CT_GLIBC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GLIBC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GLIBC_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_GLIBC_SIGNATURE_FORMAT="packed/.sig"
+CT_GLIBC_2_29_or_older=y
+CT_GLIBC_older_than_2_29=y
+CT_GLIBC_2_27_or_older=y
+CT_GLIBC_older_than_2_27=y
+CT_GLIBC_2_26_or_older=y
+CT_GLIBC_older_than_2_26=y
+CT_GLIBC_2_25_or_older=y
+CT_GLIBC_older_than_2_25=y
+CT_GLIBC_2_24_or_older=y
+CT_GLIBC_older_than_2_24=y
+CT_GLIBC_2_23_or_later=y
+CT_GLIBC_2_23_or_older=y
+CT_GLIBC_later_than_2_20=y
+CT_GLIBC_2_20_or_later=y
+CT_GLIBC_later_than_2_17=y
+CT_GLIBC_2_17_or_later=y
+CT_GLIBC_later_than_2_14=y
+CT_GLIBC_2_14_or_later=y
+CT_GLIBC_DEP_KERNEL_HEADERS_VERSION=y
+CT_GLIBC_DEP_BINUTILS=y
+CT_GLIBC_DEP_GCC=y
+CT_GLIBC_DEP_PYTHON=y
+CT_GLIBC_HAS_LIBIDN_ADDON=y
+# CT_GLIBC_USE_LIBIDN_ADDON is not set
+CT_GLIBC_NO_SPARC_V8=y
+CT_GLIBC_HAS_OBSOLETE_RPC=y
+CT_GLIBC_EXTRA_CONFIG_ARRAY=""
+CT_GLIBC_CONFIGPARMS=""
+CT_GLIBC_EXTRA_CFLAGS=""
+CT_GLIBC_ENABLE_OBSOLETE_RPC=y
+# CT_GLIBC_DISABLE_VERSIONING is not set
+CT_GLIBC_OLDEST_ABI=""
+CT_GLIBC_FORCE_UNWIND=y
+# CT_GLIBC_LOCALES is not set
+# CT_GLIBC_KERNEL_VERSION_NONE is not set
+CT_GLIBC_KERNEL_VERSION_AS_HEADERS=y
+# CT_GLIBC_KERNEL_VERSION_CHOSEN is not set
+CT_GLIBC_MIN_KERNEL="4.4.174"
+CT_ALL_LIBC_CHOICES="AVR_LIBC BIONIC GLIBC MINGW_W64 MOXIEBOX MUSL NEWLIB NONE UCLIBC"
+CT_LIBC_SUPPORT_THREADS_ANY=y
+CT_LIBC_SUPPORT_THREADS_NATIVE=y
+
+#
+# Common C library options
+#
+CT_THREADS_NATIVE=y
+# CT_CREATE_LDSO_CONF is not set
+CT_LIBC_XLDD=y
+
+#
+# C compiler
+#
+CT_CC_CORE_PASSES_NEEDED=y
+CT_CC_CORE_PASS_1_NEEDED=y
+CT_CC_CORE_PASS_2_NEEDED=y
+CT_CC_SUPPORT_CXX=y
+CT_CC_SUPPORT_FORTRAN=y
+CT_CC_SUPPORT_ADA=y
+CT_CC_SUPPORT_OBJC=y
+CT_CC_SUPPORT_OBJCXX=y
+CT_CC_SUPPORT_GOLANG=y
+CT_CC_GCC=y
+CT_CC="gcc"
+CT_CC_CHOICE_KSYM="GCC"
+CT_CC_GCC_SHOW=y
+
+#
+# Options for gcc
+#
+CT_CC_GCC_PKG_KSYM="GCC"
+CT_GCC_DIR_NAME="gcc"
+CT_GCC_USE_GNU=y
+CT_GCC_USE="GCC"
+CT_GCC_PKG_NAME="gcc"
+CT_GCC_SRC_RELEASE=y
+CT_GCC_PATCH_ORDER="global"
+CT_GCC_V_8=y
+# CT_GCC_V_7 is not set
+# CT_GCC_V_6 is not set
+# CT_GCC_V_5 is not set
+# CT_GCC_V_4_9 is not set
+# CT_GCC_NO_VERSIONS is not set
+CT_GCC_VERSION="8.3.0"
+CT_GCC_MIRRORS="$(CT_Mirrors GNU gcc/gcc-${CT_GCC_VERSION}) $(CT_Mirrors sourceware gcc/releases/gcc-${CT_GCC_VERSION})"
+CT_GCC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GCC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GCC_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_GCC_SIGNATURE_FORMAT=""
+CT_GCC_later_than_7=y
+CT_GCC_7_or_later=y
+CT_GCC_later_than_6=y
+CT_GCC_6_or_later=y
+CT_GCC_later_than_5=y
+CT_GCC_5_or_later=y
+CT_GCC_later_than_4_9=y
+CT_GCC_4_9_or_later=y
+CT_GCC_later_than_4_8=y
+CT_GCC_4_8_or_later=y
+CT_CC_GCC_HAS_LIBMPX=y
+CT_CC_GCC_ENABLE_CXX_FLAGS=""
+CT_CC_GCC_CORE_EXTRA_CONFIG_ARRAY=""
+CT_CC_GCC_EXTRA_CONFIG_ARRAY=""
+CT_CC_GCC_STATIC_LIBSTDCXX=y
+# CT_CC_GCC_SYSTEM_ZLIB is not set
+CT_CC_GCC_CONFIG_TLS=m
+
+#
+# Optimisation features
+#
+CT_CC_GCC_USE_GRAPHITE=y
+CT_CC_GCC_USE_LTO=y
+
+#
+# Settings for libraries running on target
+#
+CT_CC_GCC_ENABLE_TARGET_OPTSPACE=y
+# CT_CC_GCC_LIBMUDFLAP is not set
+# CT_CC_GCC_LIBGOMP is not set
+# CT_CC_GCC_LIBSSP is not set
+# CT_CC_GCC_LIBQUADMATH is not set
+# CT_CC_GCC_LIBSANITIZER is not set
+
+#
+# Misc. obscure options.
+#
+CT_CC_CXA_ATEXIT=y
+# CT_CC_GCC_DISABLE_PCH is not set
+CT_CC_GCC_SJLJ_EXCEPTIONS=m
+CT_CC_GCC_LDBL_128=m
+# CT_CC_GCC_BUILD_ID is not set
+CT_CC_GCC_LNK_HASH_STYLE_DEFAULT=y
+# CT_CC_GCC_LNK_HASH_STYLE_SYSV is not set
+# CT_CC_GCC_LNK_HASH_STYLE_GNU is not set
+# CT_CC_GCC_LNK_HASH_STYLE_BOTH is not set
+CT_CC_GCC_LNK_HASH_STYLE=""
+CT_CC_GCC_DEC_FLOAT_AUTO=y
+# CT_CC_GCC_DEC_FLOAT_BID is not set
+# CT_CC_GCC_DEC_FLOAT_DPD is not set
+# CT_CC_GCC_DEC_FLOATS_NO is not set
+CT_CC_GCC_HAS_ARCH_OPTIONS=y
+
+#
+# archictecture-specific options
+#
+CT_CC_GCC_mips_llsc=m
+CT_CC_GCC_mips_synci=m
+# CT_CC_GCC_mips_plt is not set
+CT_ALL_CC_CHOICES="GCC"
+
+#
+# Additional supported languages:
+#
+CT_CC_LANG_CXX=y
+# CT_CC_LANG_FORTRAN is not set
+
+#
+# Debug facilities
+#
+# CT_DEBUG_DUMA is not set
+# CT_DEBUG_GDB is not set
+# CT_DEBUG_LTRACE is not set
+# CT_DEBUG_STRACE is not set
+CT_ALL_DEBUG_CHOICES="DUMA GDB LTRACE STRACE"
+
+#
+# Companion libraries
+#
+# CT_COMPLIBS_CHECK is not set
+# CT_COMP_LIBS_CLOOG is not set
+# CT_COMP_LIBS_EXPAT is not set
+CT_COMP_LIBS_GETTEXT=y
+CT_COMP_LIBS_GETTEXT_PKG_KSYM="GETTEXT"
+CT_GETTEXT_DIR_NAME="gettext"
+CT_GETTEXT_PKG_NAME="gettext"
+CT_GETTEXT_SRC_RELEASE=y
+CT_GETTEXT_PATCH_ORDER="global"
+CT_GETTEXT_V_0_19_8_1=y
+# CT_GETTEXT_NO_VERSIONS is not set
+CT_GETTEXT_VERSION="0.19.8.1"
+CT_GETTEXT_MIRRORS="$(CT_Mirrors GNU gettext)"
+CT_GETTEXT_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GETTEXT_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GETTEXT_ARCHIVE_FORMATS=".tar.xz .tar.lz .tar.gz"
+CT_GETTEXT_SIGNATURE_FORMAT="packed/.sig"
+CT_COMP_LIBS_GMP=y
+CT_COMP_LIBS_GMP_PKG_KSYM="GMP"
+CT_GMP_DIR_NAME="gmp"
+CT_GMP_PKG_NAME="gmp"
+CT_GMP_SRC_RELEASE=y
+CT_GMP_PATCH_ORDER="global"
+CT_GMP_V_6_1=y
+# CT_GMP_NO_VERSIONS is not set
+CT_GMP_VERSION="6.1.2"
+CT_GMP_MIRRORS="https://gmplib.org/download/gmp https://gmplib.org/download/gmp/archive $(CT_Mirrors GNU gmp)"
+CT_GMP_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GMP_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GMP_ARCHIVE_FORMATS=".tar.xz .tar.lz .tar.bz2"
+CT_GMP_SIGNATURE_FORMAT="packed/.sig"
+CT_GMP_later_than_5_1_0=y
+CT_GMP_5_1_0_or_later=y
+CT_GMP_later_than_5_0_0=y
+CT_GMP_5_0_0_or_later=y
+CT_GMP_REQUIRE_5_0_0_or_later=y
+CT_COMP_LIBS_ISL=y
+CT_COMP_LIBS_ISL_PKG_KSYM="ISL"
+CT_ISL_DIR_NAME="isl"
+CT_ISL_PKG_NAME="isl"
+CT_ISL_SRC_RELEASE=y
+CT_ISL_PATCH_ORDER="global"
+CT_ISL_V_0_20=y
+# CT_ISL_V_0_19 is not set
+# CT_ISL_V_0_18 is not set
+# CT_ISL_V_0_17 is not set
+# CT_ISL_V_0_16 is not set
+# CT_ISL_V_0_15 is not set
+# CT_ISL_NO_VERSIONS is not set
+CT_ISL_VERSION="0.20"
+CT_ISL_MIRRORS="http://isl.gforge.inria.fr"
+CT_ISL_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_ISL_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_ISL_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_ISL_SIGNATURE_FORMAT=""
+CT_ISL_later_than_0_18=y
+CT_ISL_0_18_or_later=y
+CT_ISL_later_than_0_15=y
+CT_ISL_0_15_or_later=y
+CT_ISL_REQUIRE_0_15_or_later=y
+CT_ISL_later_than_0_14=y
+CT_ISL_0_14_or_later=y
+CT_ISL_REQUIRE_0_14_or_later=y
+CT_ISL_later_than_0_13=y
+CT_ISL_0_13_or_later=y
+CT_ISL_later_than_0_12=y
+CT_ISL_0_12_or_later=y
+CT_ISL_REQUIRE_0_12_or_later=y
+# CT_COMP_LIBS_LIBELF is not set
+CT_COMP_LIBS_LIBICONV=y
+CT_COMP_LIBS_LIBICONV_PKG_KSYM="LIBICONV"
+CT_LIBICONV_DIR_NAME="libiconv"
+CT_LIBICONV_PKG_NAME="libiconv"
+CT_LIBICONV_SRC_RELEASE=y
+CT_LIBICONV_PATCH_ORDER="global"
+CT_LIBICONV_V_1_15=y
+# CT_LIBICONV_NO_VERSIONS is not set
+CT_LIBICONV_VERSION="1.15"
+CT_LIBICONV_MIRRORS="$(CT_Mirrors GNU libiconv)"
+CT_LIBICONV_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_LIBICONV_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_LIBICONV_ARCHIVE_FORMATS=".tar.gz"
+CT_LIBICONV_SIGNATURE_FORMAT="packed/.sig"
+CT_COMP_LIBS_MPC=y
+CT_COMP_LIBS_MPC_PKG_KSYM="MPC"
+CT_MPC_DIR_NAME="mpc"
+CT_MPC_PKG_NAME="mpc"
+CT_MPC_SRC_RELEASE=y
+CT_MPC_PATCH_ORDER="global"
+CT_MPC_V_1_1=y
+# CT_MPC_V_1_0 is not set
+# CT_MPC_NO_VERSIONS is not set
+CT_MPC_VERSION="1.1.0"
+CT_MPC_MIRRORS="http://www.multiprecision.org/downloads $(CT_Mirrors GNU mpc)"
+CT_MPC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_MPC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_MPC_ARCHIVE_FORMATS=".tar.gz"
+CT_MPC_SIGNATURE_FORMAT="packed/.sig"
+CT_MPC_1_1_0_or_later=y
+CT_MPC_1_1_0_or_older=y
+CT_COMP_LIBS_MPFR=y
+CT_COMP_LIBS_MPFR_PKG_KSYM="MPFR"
+CT_MPFR_DIR_NAME="mpfr"
+CT_MPFR_PKG_NAME="mpfr"
+CT_MPFR_SRC_RELEASE=y
+CT_MPFR_PATCH_ORDER="global"
+CT_MPFR_V_4_0=y
+# CT_MPFR_V_3_1 is not set
+# CT_MPFR_NO_VERSIONS is not set
+CT_MPFR_VERSION="4.0.2"
+CT_MPFR_MIRRORS="http://www.mpfr.org/mpfr-${CT_MPFR_VERSION} $(CT_Mirrors GNU mpfr)"
+CT_MPFR_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_MPFR_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_MPFR_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz .zip"
+CT_MPFR_SIGNATURE_FORMAT="packed/.asc"
+CT_MPFR_later_than_4_0_0=y
+CT_MPFR_4_0_0_or_later=y
+CT_MPFR_later_than_3_0_0=y
+CT_MPFR_3_0_0_or_later=y
+CT_MPFR_REQUIRE_3_0_0_or_later=y
+CT_COMP_LIBS_NCURSES=y
+CT_COMP_LIBS_NCURSES_PKG_KSYM="NCURSES"
+CT_NCURSES_DIR_NAME="ncurses"
+CT_NCURSES_PKG_NAME="ncurses"
+CT_NCURSES_SRC_RELEASE=y
+CT_NCURSES_PATCH_ORDER="global"
+CT_NCURSES_V_6_1=y
+# CT_NCURSES_V_6_0 is not set
+# CT_NCURSES_NO_VERSIONS is not set
+CT_NCURSES_VERSION="6.1"
+CT_NCURSES_MIRRORS="ftp://invisible-island.net/ncurses $(CT_Mirrors GNU ncurses)"
+CT_NCURSES_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_NCURSES_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_NCURSES_ARCHIVE_FORMATS=".tar.gz"
+CT_NCURSES_SIGNATURE_FORMAT="packed/.sig"
+CT_NCURSES_HOST_CONFIG_ARGS=""
+CT_NCURSES_HOST_DISABLE_DB=y
+CT_NCURSES_HOST_FALLBACKS="linux,xterm,xterm-color,xterm-256color,vt100"
+CT_NCURSES_TARGET_CONFIG_ARGS=""
+# CT_NCURSES_TARGET_DISABLE_DB is not set
+CT_NCURSES_TARGET_FALLBACKS=""
+CT_COMP_LIBS_ZLIB=y
+CT_COMP_LIBS_ZLIB_PKG_KSYM="ZLIB"
+CT_ZLIB_DIR_NAME="zlib"
+CT_ZLIB_PKG_NAME="zlib"
+CT_ZLIB_SRC_RELEASE=y
+CT_ZLIB_PATCH_ORDER="global"
+CT_ZLIB_V_1_2_11=y
+# CT_ZLIB_NO_VERSIONS is not set
+CT_ZLIB_VERSION="1.2.11"
+CT_ZLIB_MIRRORS="http://downloads.sourceforge.net/project/libpng/zlib/${CT_ZLIB_VERSION}"
+CT_ZLIB_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_ZLIB_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_ZLIB_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_ZLIB_SIGNATURE_FORMAT="packed/.asc"
+CT_ALL_COMP_LIBS_CHOICES="CLOOG EXPAT GETTEXT GMP ISL LIBELF LIBICONV MPC MPFR NCURSES ZLIB"
+CT_LIBICONV_NEEDED=y
+CT_GETTEXT_NEEDED=y
+CT_GMP_NEEDED=y
+CT_MPFR_NEEDED=y
+CT_ISL_NEEDED=y
+CT_MPC_NEEDED=y
+CT_NCURSES_NEEDED=y
+CT_ZLIB_NEEDED=y
+CT_LIBICONV=y
+CT_GETTEXT=y
+CT_GMP=y
+CT_MPFR=y
+CT_ISL=y
+CT_MPC=y
+CT_NCURSES=y
+CT_ZLIB=y
+
+#
+# Companion tools
+#
+# CT_COMP_TOOLS_FOR_HOST is not set
+# CT_COMP_TOOLS_AUTOCONF is not set
+# CT_COMP_TOOLS_AUTOMAKE is not set
+# CT_COMP_TOOLS_BISON is not set
+# CT_COMP_TOOLS_DTC is not set
+# CT_COMP_TOOLS_LIBTOOL is not set
+# CT_COMP_TOOLS_M4 is not set
+# CT_COMP_TOOLS_MAKE is not set
+CT_ALL_COMP_TOOLS_CHOICES="AUTOCONF AUTOMAKE BISON DTC LIBTOOL M4 MAKE"
diff --git a/src/ci/docker/host-x86_64/dist-mipsel-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-mipsel-linux/Dockerfile
index 70c8b2a96..6cc2de5e4 100644
--- a/src/ci/docker/host-x86_64/dist-mipsel-linux/Dockerfile
+++ b/src/ci/docker/host-x86_64/dist-mipsel-linux/Dockerfile
@@ -1,30 +1,30 @@
-FROM ubuntu:16.04
-
-RUN apt-get update && apt-get install -y --no-install-recommends \
- g++ \
- make \
- ninja-build \
- file \
- curl \
- ca-certificates \
- python3 \
- git \
- cmake \
- sudo \
- gdb \
- xz-utils \
- g++-mipsel-linux-gnu \
- libssl-dev \
- pkg-config
+FROM ubuntu:22.04
+
+COPY scripts/cross-apt-packages.sh /scripts/
+RUN sh /scripts/cross-apt-packages.sh
+
+COPY scripts/crosstool-ng-1.24.sh /scripts/
+RUN sh /scripts/crosstool-ng-1.24.sh
+
+COPY scripts/rustbuild-setup.sh /scripts/
+RUN sh /scripts/rustbuild-setup.sh
+WORKDIR /tmp
+
+COPY host-x86_64/dist-mips-linux/patches/ /tmp/patches/
+COPY host-x86_64/dist-mipsel-linux/mipsel-linux-gnu.config host-x86_64/dist-mipsel-linux/build-mipsel-toolchain.sh /tmp/
+RUN su rustbuild -c ./build-mipsel-toolchain.sh
COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh
-COPY scripts/cmake.sh /scripts/
-RUN /scripts/cmake.sh
+ENV PATH=$PATH:/x-tools/mipsel-unknown-linux-gnu/bin
+
+ENV \
+ CC_mipsel_unknown_linux_gnu=mipsel-unknown-linux-gnu-gcc \
+ AR_mipsel_unknown_linux_gnu=mipsel-unknown-linux-gnu-ar \
+ CXX_mipsel_unknown_linux_gnu=mipsel-unknown-linux-gnu-g++
ENV HOSTS=mipsel-unknown-linux-gnu
-ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs \
- --set llvm.allow-old-toolchain
+ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs
ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS
diff --git a/src/ci/docker/host-x86_64/dist-mipsel-linux/build-mipsel-toolchain.sh b/src/ci/docker/host-x86_64/dist-mipsel-linux/build-mipsel-toolchain.sh
new file mode 100755
index 000000000..598e48933
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-mipsel-linux/build-mipsel-toolchain.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+set -ex
+
+hide_output() {
+ set +x
+ on_err="
+echo ERROR: An error was encountered with the build.
+cat /tmp/build.log
+exit 1
+"
+ trap "$on_err" ERR
+ bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
+ PING_LOOP_PID=$!
+ "$@" &> /tmp/build.log
+ rm /tmp/build.log
+ trap - ERR
+ kill $PING_LOOP_PID
+ set -x
+}
+
+mkdir build
+cd build
+cp ../mipsel-linux-gnu.config .config
+hide_output ct-ng build
+cd ..
+rm -rf build
diff --git a/src/ci/docker/host-x86_64/dist-mipsel-linux/mipsel-linux-gnu.config b/src/ci/docker/host-x86_64/dist-mipsel-linux/mipsel-linux-gnu.config
new file mode 100644
index 000000000..adb2da7dd
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-mipsel-linux/mipsel-linux-gnu.config
@@ -0,0 +1,740 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# crosstool-NG Configuration
+#
+CT_CONFIGURE_has_static_link=y
+CT_CONFIGURE_has_cxx11=y
+CT_CONFIGURE_has_wget=y
+CT_CONFIGURE_has_curl=y
+CT_CONFIGURE_has_make_3_81_or_newer=y
+CT_CONFIGURE_has_make_4_0_or_newer=y
+CT_CONFIGURE_has_libtool_2_4_or_newer=y
+CT_CONFIGURE_has_libtoolize_2_4_or_newer=y
+CT_CONFIGURE_has_autoconf_2_65_or_newer=y
+CT_CONFIGURE_has_autoreconf_2_65_or_newer=y
+CT_CONFIGURE_has_automake_1_15_or_newer=y
+CT_CONFIGURE_has_gnu_m4_1_4_12_or_newer=y
+CT_CONFIGURE_has_python_3_4_or_newer=y
+CT_CONFIGURE_has_bison_2_7_or_newer=y
+CT_CONFIGURE_has_python=y
+CT_CONFIGURE_has_git=y
+CT_CONFIGURE_has_md5sum=y
+CT_CONFIGURE_has_sha1sum=y
+CT_CONFIGURE_has_sha256sum=y
+CT_CONFIGURE_has_sha512sum=y
+CT_CONFIGURE_has_install_with_strip_program=y
+CT_CONFIG_VERSION_CURRENT="3"
+CT_CONFIG_VERSION="3"
+CT_MODULES=y
+
+#
+# Paths and misc options
+#
+
+#
+# crosstool-NG behavior
+#
+# CT_OBSOLETE is not set
+# CT_EXPERIMENTAL is not set
+# CT_DEBUG_CT is not set
+
+#
+# Paths
+#
+CT_LOCAL_TARBALLS_DIR="${HOME}/src"
+CT_SAVE_TARBALLS=y
+# CT_TARBALLS_BUILDROOT_LAYOUT is not set
+CT_WORK_DIR="${CT_TOP_DIR}/.build"
+CT_BUILD_TOP_DIR="${CT_WORK_DIR:-${CT_TOP_DIR}/.build}/${CT_HOST:+HOST-${CT_HOST}/}${CT_TARGET}"
+CT_PREFIX_DIR="/x-tools/${CT_TARGET}"
+CT_RM_RF_PREFIX_DIR=y
+CT_REMOVE_DOCS=y
+CT_INSTALL_LICENSES=y
+CT_PREFIX_DIR_RO=y
+CT_STRIP_HOST_TOOLCHAIN_EXECUTABLES=y
+# CT_STRIP_TARGET_TOOLCHAIN_EXECUTABLES is not set
+
+#
+# Downloading
+#
+CT_DOWNLOAD_AGENT_WGET=y
+# CT_DOWNLOAD_AGENT_CURL is not set
+# CT_DOWNLOAD_AGENT_NONE is not set
+# CT_FORBID_DOWNLOAD is not set
+# CT_FORCE_DOWNLOAD is not set
+CT_CONNECT_TIMEOUT=10
+CT_DOWNLOAD_WGET_OPTIONS="--passive-ftp --tries=3 -nc --progress=dot:binary"
+# CT_ONLY_DOWNLOAD is not set
+CT_USE_MIRROR=y
+# CT_FORCE_MIRROR is not set
+CT_MIRROR_BASE_URL="https://ci-mirrors.rust-lang.org/rustc"
+CT_VERIFY_DOWNLOAD_DIGEST=y
+CT_VERIFY_DOWNLOAD_DIGEST_SHA512=y
+# CT_VERIFY_DOWNLOAD_DIGEST_SHA256 is not set
+# CT_VERIFY_DOWNLOAD_DIGEST_SHA1 is not set
+# CT_VERIFY_DOWNLOAD_DIGEST_MD5 is not set
+CT_VERIFY_DOWNLOAD_DIGEST_ALG="sha512"
+# CT_VERIFY_DOWNLOAD_SIGNATURE is not set
+
+#
+# Extracting
+#
+# CT_FORCE_EXTRACT is not set
+CT_OVERRIDE_CONFIG_GUESS_SUB=y
+# CT_ONLY_EXTRACT is not set
+# CT_PATCH_BUNDLED is not set
+CT_PATCH_BUNDLED_LOCAL=y
+CT_PATCH_ORDER="bundled,local"
+CT_PATCH_USE_LOCAL=y
+CT_LOCAL_PATCH_DIR="/tmp/patches"
+
+#
+# Build behavior
+#
+CT_PARALLEL_JOBS=0
+CT_LOAD=""
+CT_USE_PIPES=y
+CT_EXTRA_CFLAGS_FOR_BUILD=""
+CT_EXTRA_LDFLAGS_FOR_BUILD=""
+CT_EXTRA_CFLAGS_FOR_HOST=""
+CT_EXTRA_LDFLAGS_FOR_HOST=""
+# CT_CONFIG_SHELL_SH is not set
+# CT_CONFIG_SHELL_ASH is not set
+CT_CONFIG_SHELL_BASH=y
+# CT_CONFIG_SHELL_CUSTOM is not set
+CT_CONFIG_SHELL="${bash}"
+
+#
+# Logging
+#
+# CT_LOG_ERROR is not set
+# CT_LOG_WARN is not set
+# CT_LOG_INFO is not set
+CT_LOG_EXTRA=y
+# CT_LOG_ALL is not set
+# CT_LOG_DEBUG is not set
+CT_LOG_LEVEL_MAX="EXTRA"
+# CT_LOG_SEE_TOOLS_WARN is not set
+CT_LOG_PROGRESS_BAR=y
+CT_LOG_TO_FILE=y
+CT_LOG_FILE_COMPRESS=y
+
+#
+# Target options
+#
+# CT_ARCH_ALPHA is not set
+# CT_ARCH_ARC is not set
+# CT_ARCH_ARM is not set
+# CT_ARCH_AVR is not set
+# CT_ARCH_M68K is not set
+CT_ARCH_MIPS=y
+# CT_ARCH_NIOS2 is not set
+# CT_ARCH_POWERPC is not set
+# CT_ARCH_S390 is not set
+# CT_ARCH_SH is not set
+# CT_ARCH_SPARC is not set
+# CT_ARCH_X86 is not set
+# CT_ARCH_XTENSA is not set
+CT_ARCH="mips"
+CT_ARCH_CHOICE_KSYM="MIPS"
+CT_ARCH_TUNE=""
+CT_ARCH_MIPS_SHOW=y
+
+#
+# Options for mips
+#
+CT_ARCH_MIPS_PKG_KSYM=""
+CT_ARCH_mips_o32=y
+CT_ARCH_mips_ABI="32"
+CT_ALL_ARCH_CHOICES="ALPHA ARC ARM AVR M68K MICROBLAZE MIPS MOXIE MSP430 NIOS2 POWERPC RISCV S390 SH SPARC X86 XTENSA"
+CT_ARCH_SUFFIX=""
+# CT_OMIT_TARGET_VENDOR is not set
+
+#
+# Generic target options
+#
+# CT_MULTILIB is not set
+CT_DEMULTILIB=y
+CT_ARCH_USE_MMU=y
+CT_ARCH_SUPPORTS_EITHER_ENDIAN=y
+CT_ARCH_DEFAULT_BE=y
+# CT_ARCH_BE is not set
+CT_ARCH_LE=y
+CT_ARCH_ENDIAN="little"
+CT_ARCH_SUPPORTS_32=y
+CT_ARCH_SUPPORTS_64=y
+CT_ARCH_DEFAULT_32=y
+CT_ARCH_BITNESS=32
+CT_ARCH_32=y
+# CT_ARCH_64 is not set
+
+#
+# Target optimisations
+#
+CT_ARCH_SUPPORTS_WITH_ARCH=y
+CT_ARCH_SUPPORTS_WITH_TUNE=y
+CT_ARCH_SUPPORTS_WITH_FLOAT=y
+CT_ARCH_ARCH="mips32r2"
+CT_ARCH_FLOAT_AUTO=y
+# CT_ARCH_FLOAT_HW is not set
+# CT_ARCH_FLOAT_SW is not set
+CT_TARGET_CFLAGS=""
+CT_TARGET_LDFLAGS=""
+CT_ARCH_FLOAT="auto"
+
+#
+# Toolchain options
+#
+
+#
+# General toolchain options
+#
+CT_FORCE_SYSROOT=y
+CT_USE_SYSROOT=y
+CT_SYSROOT_NAME="sysroot"
+CT_SYSROOT_DIR_PREFIX=""
+CT_WANTS_STATIC_LINK=y
+CT_WANTS_STATIC_LINK_CXX=y
+# CT_STATIC_TOOLCHAIN is not set
+CT_SHOW_CT_VERSION=y
+CT_TOOLCHAIN_PKGVERSION=""
+CT_TOOLCHAIN_BUGURL=""
+
+#
+# Tuple completion and aliasing
+#
+CT_TARGET_VENDOR="unknown"
+CT_TARGET_ALIAS_SED_EXPR=""
+CT_TARGET_ALIAS=""
+
+#
+# Toolchain type
+#
+CT_CROSS=y
+# CT_CANADIAN is not set
+CT_TOOLCHAIN_TYPE="cross"
+
+#
+# Build system
+#
+CT_BUILD=""
+CT_BUILD_PREFIX=""
+CT_BUILD_SUFFIX=""
+
+#
+# Misc options
+#
+# CT_TOOLCHAIN_ENABLE_NLS is not set
+
+#
+# Operating System
+#
+CT_KERNEL_SUPPORTS_SHARED_LIBS=y
+# CT_KERNEL_BARE_METAL is not set
+CT_KERNEL_LINUX=y
+CT_KERNEL="linux"
+CT_KERNEL_CHOICE_KSYM="LINUX"
+CT_KERNEL_LINUX_SHOW=y
+
+#
+# Options for linux
+#
+CT_KERNEL_LINUX_PKG_KSYM="LINUX"
+CT_LINUX_DIR_NAME="linux"
+CT_LINUX_PKG_NAME="linux"
+CT_LINUX_SRC_RELEASE=y
+CT_LINUX_PATCH_ORDER="global"
+# CT_LINUX_V_4_20 is not set
+# CT_LINUX_V_4_19 is not set
+# CT_LINUX_V_4_18 is not set
+# CT_LINUX_V_4_17 is not set
+# CT_LINUX_V_4_16 is not set
+# CT_LINUX_V_4_15 is not set
+# CT_LINUX_V_4_14 is not set
+# CT_LINUX_V_4_13 is not set
+# CT_LINUX_V_4_12 is not set
+# CT_LINUX_V_4_11 is not set
+# CT_LINUX_V_4_10 is not set
+# CT_LINUX_V_4_9 is not set
+CT_LINUX_V_4_4=y
+# CT_LINUX_V_4_1 is not set
+# CT_LINUX_V_3_16 is not set
+# CT_LINUX_V_3_13 is not set
+# CT_LINUX_V_3_12 is not set
+# CT_LINUX_V_3_10 is not set
+# CT_LINUX_V_3_4 is not set
+# CT_LINUX_V_3_2 is not set
+# CT_LINUX_V_2_6_32 is not set
+# CT_LINUX_NO_VERSIONS is not set
+CT_LINUX_VERSION="4.4.174"
+CT_LINUX_MIRRORS="$(CT_Mirrors kernel.org linux ${CT_LINUX_VERSION})"
+CT_LINUX_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_LINUX_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_LINUX_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_LINUX_SIGNATURE_FORMAT="unpacked/.sign"
+CT_LINUX_4_8_or_older=y
+CT_LINUX_older_than_4_8=y
+CT_LINUX_later_than_3_7=y
+CT_LINUX_3_7_or_later=y
+CT_LINUX_later_than_3_2=y
+CT_LINUX_3_2_or_later=y
+CT_KERNEL_LINUX_VERBOSITY_0=y
+# CT_KERNEL_LINUX_VERBOSITY_1 is not set
+# CT_KERNEL_LINUX_VERBOSITY_2 is not set
+CT_KERNEL_LINUX_VERBOSE_LEVEL=0
+CT_KERNEL_LINUX_INSTALL_CHECK=y
+CT_ALL_KERNEL_CHOICES="BARE_METAL LINUX WINDOWS"
+
+#
+# Common kernel options
+#
+CT_SHARED_LIBS=y
+
+#
+# Binary utilities
+#
+CT_ARCH_BINFMT_ELF=y
+CT_BINUTILS_BINUTILS=y
+CT_BINUTILS="binutils"
+CT_BINUTILS_CHOICE_KSYM="BINUTILS"
+CT_BINUTILS_BINUTILS_SHOW=y
+
+#
+# Options for binutils
+#
+CT_BINUTILS_BINUTILS_PKG_KSYM="BINUTILS"
+CT_BINUTILS_DIR_NAME="binutils"
+CT_BINUTILS_USE_GNU=y
+CT_BINUTILS_USE="BINUTILS"
+CT_BINUTILS_PKG_NAME="binutils"
+CT_BINUTILS_SRC_RELEASE=y
+CT_BINUTILS_PATCH_ORDER="global"
+CT_BINUTILS_V_2_32=y
+# CT_BINUTILS_V_2_31 is not set
+# CT_BINUTILS_V_2_30 is not set
+# CT_BINUTILS_V_2_29 is not set
+# CT_BINUTILS_V_2_28 is not set
+# CT_BINUTILS_V_2_27 is not set
+# CT_BINUTILS_V_2_26 is not set
+# CT_BINUTILS_NO_VERSIONS is not set
+CT_BINUTILS_VERSION="2.32"
+CT_BINUTILS_MIRRORS="$(CT_Mirrors GNU binutils) $(CT_Mirrors sourceware binutils/releases)"
+CT_BINUTILS_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_BINUTILS_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_BINUTILS_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_BINUTILS_SIGNATURE_FORMAT="packed/.sig"
+CT_BINUTILS_later_than_2_30=y
+CT_BINUTILS_2_30_or_later=y
+CT_BINUTILS_later_than_2_27=y
+CT_BINUTILS_2_27_or_later=y
+CT_BINUTILS_later_than_2_25=y
+CT_BINUTILS_2_25_or_later=y
+CT_BINUTILS_later_than_2_23=y
+CT_BINUTILS_2_23_or_later=y
+
+#
+# GNU binutils
+#
+CT_BINUTILS_HAS_HASH_STYLE=y
+CT_BINUTILS_HAS_GOLD=y
+CT_BINUTILS_HAS_PLUGINS=y
+CT_BINUTILS_HAS_PKGVERSION_BUGURL=y
+CT_BINUTILS_FORCE_LD_BFD_DEFAULT=y
+CT_BINUTILS_LINKER_LD=y
+CT_BINUTILS_LINKERS_LIST="ld"
+CT_BINUTILS_LINKER_DEFAULT="bfd"
+# CT_BINUTILS_PLUGINS is not set
+CT_BINUTILS_RELRO=m
+CT_BINUTILS_EXTRA_CONFIG_ARRAY=""
+# CT_BINUTILS_FOR_TARGET is not set
+CT_ALL_BINUTILS_CHOICES="BINUTILS"
+
+#
+# C-library
+#
+CT_LIBC_GLIBC=y
+# CT_LIBC_UCLIBC is not set
+CT_LIBC="glibc"
+CT_LIBC_CHOICE_KSYM="GLIBC"
+CT_THREADS="nptl"
+CT_LIBC_GLIBC_SHOW=y
+
+#
+# Options for glibc
+#
+CT_LIBC_GLIBC_PKG_KSYM="GLIBC"
+CT_GLIBC_DIR_NAME="glibc"
+CT_GLIBC_USE_GNU=y
+CT_GLIBC_USE="GLIBC"
+CT_GLIBC_PKG_NAME="glibc"
+CT_GLIBC_SRC_RELEASE=y
+CT_GLIBC_PATCH_ORDER="global"
+# CT_GLIBC_V_2_29 is not set
+# CT_GLIBC_V_2_28 is not set
+# CT_GLIBC_V_2_27 is not set
+# CT_GLIBC_V_2_26 is not set
+# CT_GLIBC_V_2_25 is not set
+# CT_GLIBC_V_2_24 is not set
+CT_GLIBC_V_2_23=y
+# CT_GLIBC_V_2_19 is not set
+# CT_GLIBC_V_2_17 is not set
+# CT_GLIBC_V_2_12_1 is not set
+# CT_GLIBC_NO_VERSIONS is not set
+CT_GLIBC_VERSION="2.23"
+CT_GLIBC_MIRRORS="$(CT_Mirrors GNU glibc)"
+CT_GLIBC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GLIBC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GLIBC_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_GLIBC_SIGNATURE_FORMAT="packed/.sig"
+CT_GLIBC_2_29_or_older=y
+CT_GLIBC_older_than_2_29=y
+CT_GLIBC_2_27_or_older=y
+CT_GLIBC_older_than_2_27=y
+CT_GLIBC_2_26_or_older=y
+CT_GLIBC_older_than_2_26=y
+CT_GLIBC_2_25_or_older=y
+CT_GLIBC_older_than_2_25=y
+CT_GLIBC_2_24_or_older=y
+CT_GLIBC_older_than_2_24=y
+CT_GLIBC_2_23_or_later=y
+CT_GLIBC_2_23_or_older=y
+CT_GLIBC_later_than_2_20=y
+CT_GLIBC_2_20_or_later=y
+CT_GLIBC_later_than_2_17=y
+CT_GLIBC_2_17_or_later=y
+CT_GLIBC_later_than_2_14=y
+CT_GLIBC_2_14_or_later=y
+CT_GLIBC_DEP_KERNEL_HEADERS_VERSION=y
+CT_GLIBC_DEP_BINUTILS=y
+CT_GLIBC_DEP_GCC=y
+CT_GLIBC_DEP_PYTHON=y
+CT_GLIBC_HAS_LIBIDN_ADDON=y
+# CT_GLIBC_USE_LIBIDN_ADDON is not set
+CT_GLIBC_NO_SPARC_V8=y
+CT_GLIBC_HAS_OBSOLETE_RPC=y
+CT_GLIBC_EXTRA_CONFIG_ARRAY=""
+CT_GLIBC_CONFIGPARMS=""
+CT_GLIBC_EXTRA_CFLAGS=""
+CT_GLIBC_ENABLE_OBSOLETE_RPC=y
+# CT_GLIBC_DISABLE_VERSIONING is not set
+CT_GLIBC_OLDEST_ABI=""
+CT_GLIBC_FORCE_UNWIND=y
+# CT_GLIBC_LOCALES is not set
+# CT_GLIBC_KERNEL_VERSION_NONE is not set
+CT_GLIBC_KERNEL_VERSION_AS_HEADERS=y
+# CT_GLIBC_KERNEL_VERSION_CHOSEN is not set
+CT_GLIBC_MIN_KERNEL="4.4.174"
+CT_ALL_LIBC_CHOICES="AVR_LIBC BIONIC GLIBC MINGW_W64 MOXIEBOX MUSL NEWLIB NONE UCLIBC"
+CT_LIBC_SUPPORT_THREADS_ANY=y
+CT_LIBC_SUPPORT_THREADS_NATIVE=y
+
+#
+# Common C library options
+#
+CT_THREADS_NATIVE=y
+# CT_CREATE_LDSO_CONF is not set
+CT_LIBC_XLDD=y
+
+#
+# C compiler
+#
+CT_CC_CORE_PASSES_NEEDED=y
+CT_CC_CORE_PASS_1_NEEDED=y
+CT_CC_CORE_PASS_2_NEEDED=y
+CT_CC_SUPPORT_CXX=y
+CT_CC_SUPPORT_FORTRAN=y
+CT_CC_SUPPORT_ADA=y
+CT_CC_SUPPORT_OBJC=y
+CT_CC_SUPPORT_OBJCXX=y
+CT_CC_SUPPORT_GOLANG=y
+CT_CC_GCC=y
+CT_CC="gcc"
+CT_CC_CHOICE_KSYM="GCC"
+CT_CC_GCC_SHOW=y
+
+#
+# Options for gcc
+#
+CT_CC_GCC_PKG_KSYM="GCC"
+CT_GCC_DIR_NAME="gcc"
+CT_GCC_USE_GNU=y
+CT_GCC_USE="GCC"
+CT_GCC_PKG_NAME="gcc"
+CT_GCC_SRC_RELEASE=y
+CT_GCC_PATCH_ORDER="global"
+CT_GCC_V_8=y
+# CT_GCC_V_7 is not set
+# CT_GCC_V_6 is not set
+# CT_GCC_V_5 is not set
+# CT_GCC_V_4_9 is not set
+# CT_GCC_NO_VERSIONS is not set
+CT_GCC_VERSION="8.3.0"
+CT_GCC_MIRRORS="$(CT_Mirrors GNU gcc/gcc-${CT_GCC_VERSION}) $(CT_Mirrors sourceware gcc/releases/gcc-${CT_GCC_VERSION})"
+CT_GCC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GCC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GCC_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_GCC_SIGNATURE_FORMAT=""
+CT_GCC_later_than_7=y
+CT_GCC_7_or_later=y
+CT_GCC_later_than_6=y
+CT_GCC_6_or_later=y
+CT_GCC_later_than_5=y
+CT_GCC_5_or_later=y
+CT_GCC_later_than_4_9=y
+CT_GCC_4_9_or_later=y
+CT_GCC_later_than_4_8=y
+CT_GCC_4_8_or_later=y
+CT_CC_GCC_HAS_LIBMPX=y
+CT_CC_GCC_ENABLE_CXX_FLAGS=""
+CT_CC_GCC_CORE_EXTRA_CONFIG_ARRAY=""
+CT_CC_GCC_EXTRA_CONFIG_ARRAY="--with-fp-32=xx --with-odd-spreg-32=no"
+CT_CC_GCC_STATIC_LIBSTDCXX=y
+# CT_CC_GCC_SYSTEM_ZLIB is not set
+CT_CC_GCC_CONFIG_TLS=m
+
+#
+# Optimisation features
+#
+CT_CC_GCC_USE_GRAPHITE=y
+CT_CC_GCC_USE_LTO=y
+
+#
+# Settings for libraries running on target
+#
+CT_CC_GCC_ENABLE_TARGET_OPTSPACE=y
+# CT_CC_GCC_LIBMUDFLAP is not set
+# CT_CC_GCC_LIBGOMP is not set
+# CT_CC_GCC_LIBSSP is not set
+# CT_CC_GCC_LIBQUADMATH is not set
+# CT_CC_GCC_LIBSANITIZER is not set
+
+#
+# Misc. obscure options.
+#
+CT_CC_CXA_ATEXIT=y
+# CT_CC_GCC_DISABLE_PCH is not set
+CT_CC_GCC_SJLJ_EXCEPTIONS=m
+CT_CC_GCC_LDBL_128=m
+# CT_CC_GCC_BUILD_ID is not set
+CT_CC_GCC_LNK_HASH_STYLE_DEFAULT=y
+# CT_CC_GCC_LNK_HASH_STYLE_SYSV is not set
+# CT_CC_GCC_LNK_HASH_STYLE_GNU is not set
+# CT_CC_GCC_LNK_HASH_STYLE_BOTH is not set
+CT_CC_GCC_LNK_HASH_STYLE=""
+CT_CC_GCC_DEC_FLOAT_AUTO=y
+# CT_CC_GCC_DEC_FLOAT_BID is not set
+# CT_CC_GCC_DEC_FLOAT_DPD is not set
+# CT_CC_GCC_DEC_FLOATS_NO is not set
+CT_CC_GCC_HAS_ARCH_OPTIONS=y
+
+#
+# archictecture-specific options
+#
+CT_CC_GCC_mips_llsc=m
+CT_CC_GCC_mips_synci=m
+# CT_CC_GCC_mips_plt is not set
+CT_ALL_CC_CHOICES="GCC"
+
+#
+# Additional supported languages:
+#
+CT_CC_LANG_CXX=y
+# CT_CC_LANG_FORTRAN is not set
+
+#
+# Debug facilities
+#
+# CT_DEBUG_DUMA is not set
+# CT_DEBUG_GDB is not set
+# CT_DEBUG_LTRACE is not set
+# CT_DEBUG_STRACE is not set
+CT_ALL_DEBUG_CHOICES="DUMA GDB LTRACE STRACE"
+
+#
+# Companion libraries
+#
+# CT_COMPLIBS_CHECK is not set
+# CT_COMP_LIBS_CLOOG is not set
+# CT_COMP_LIBS_EXPAT is not set
+CT_COMP_LIBS_GETTEXT=y
+CT_COMP_LIBS_GETTEXT_PKG_KSYM="GETTEXT"
+CT_GETTEXT_DIR_NAME="gettext"
+CT_GETTEXT_PKG_NAME="gettext"
+CT_GETTEXT_SRC_RELEASE=y
+CT_GETTEXT_PATCH_ORDER="global"
+CT_GETTEXT_V_0_19_8_1=y
+# CT_GETTEXT_NO_VERSIONS is not set
+CT_GETTEXT_VERSION="0.19.8.1"
+CT_GETTEXT_MIRRORS="$(CT_Mirrors GNU gettext)"
+CT_GETTEXT_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GETTEXT_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GETTEXT_ARCHIVE_FORMATS=".tar.xz .tar.lz .tar.gz"
+CT_GETTEXT_SIGNATURE_FORMAT="packed/.sig"
+CT_COMP_LIBS_GMP=y
+CT_COMP_LIBS_GMP_PKG_KSYM="GMP"
+CT_GMP_DIR_NAME="gmp"
+CT_GMP_PKG_NAME="gmp"
+CT_GMP_SRC_RELEASE=y
+CT_GMP_PATCH_ORDER="global"
+CT_GMP_V_6_1=y
+# CT_GMP_NO_VERSIONS is not set
+CT_GMP_VERSION="6.1.2"
+CT_GMP_MIRRORS="https://gmplib.org/download/gmp https://gmplib.org/download/gmp/archive $(CT_Mirrors GNU gmp)"
+CT_GMP_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_GMP_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_GMP_ARCHIVE_FORMATS=".tar.xz .tar.lz .tar.bz2"
+CT_GMP_SIGNATURE_FORMAT="packed/.sig"
+CT_GMP_later_than_5_1_0=y
+CT_GMP_5_1_0_or_later=y
+CT_GMP_later_than_5_0_0=y
+CT_GMP_5_0_0_or_later=y
+CT_GMP_REQUIRE_5_0_0_or_later=y
+CT_COMP_LIBS_ISL=y
+CT_COMP_LIBS_ISL_PKG_KSYM="ISL"
+CT_ISL_DIR_NAME="isl"
+CT_ISL_PKG_NAME="isl"
+CT_ISL_SRC_RELEASE=y
+CT_ISL_PATCH_ORDER="global"
+CT_ISL_V_0_20=y
+# CT_ISL_V_0_19 is not set
+# CT_ISL_V_0_18 is not set
+# CT_ISL_V_0_17 is not set
+# CT_ISL_V_0_16 is not set
+# CT_ISL_V_0_15 is not set
+# CT_ISL_NO_VERSIONS is not set
+CT_ISL_VERSION="0.20"
+CT_ISL_MIRRORS="http://isl.gforge.inria.fr"
+CT_ISL_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_ISL_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_ISL_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz"
+CT_ISL_SIGNATURE_FORMAT=""
+CT_ISL_later_than_0_18=y
+CT_ISL_0_18_or_later=y
+CT_ISL_later_than_0_15=y
+CT_ISL_0_15_or_later=y
+CT_ISL_REQUIRE_0_15_or_later=y
+CT_ISL_later_than_0_14=y
+CT_ISL_0_14_or_later=y
+CT_ISL_REQUIRE_0_14_or_later=y
+CT_ISL_later_than_0_13=y
+CT_ISL_0_13_or_later=y
+CT_ISL_later_than_0_12=y
+CT_ISL_0_12_or_later=y
+CT_ISL_REQUIRE_0_12_or_later=y
+# CT_COMP_LIBS_LIBELF is not set
+CT_COMP_LIBS_LIBICONV=y
+CT_COMP_LIBS_LIBICONV_PKG_KSYM="LIBICONV"
+CT_LIBICONV_DIR_NAME="libiconv"
+CT_LIBICONV_PKG_NAME="libiconv"
+CT_LIBICONV_SRC_RELEASE=y
+CT_LIBICONV_PATCH_ORDER="global"
+CT_LIBICONV_V_1_15=y
+# CT_LIBICONV_NO_VERSIONS is not set
+CT_LIBICONV_VERSION="1.15"
+CT_LIBICONV_MIRRORS="$(CT_Mirrors GNU libiconv)"
+CT_LIBICONV_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_LIBICONV_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_LIBICONV_ARCHIVE_FORMATS=".tar.gz"
+CT_LIBICONV_SIGNATURE_FORMAT="packed/.sig"
+CT_COMP_LIBS_MPC=y
+CT_COMP_LIBS_MPC_PKG_KSYM="MPC"
+CT_MPC_DIR_NAME="mpc"
+CT_MPC_PKG_NAME="mpc"
+CT_MPC_SRC_RELEASE=y
+CT_MPC_PATCH_ORDER="global"
+CT_MPC_V_1_1=y
+# CT_MPC_V_1_0 is not set
+# CT_MPC_NO_VERSIONS is not set
+CT_MPC_VERSION="1.1.0"
+CT_MPC_MIRRORS="http://www.multiprecision.org/downloads $(CT_Mirrors GNU mpc)"
+CT_MPC_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_MPC_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_MPC_ARCHIVE_FORMATS=".tar.gz"
+CT_MPC_SIGNATURE_FORMAT="packed/.sig"
+CT_MPC_1_1_0_or_later=y
+CT_MPC_1_1_0_or_older=y
+CT_COMP_LIBS_MPFR=y
+CT_COMP_LIBS_MPFR_PKG_KSYM="MPFR"
+CT_MPFR_DIR_NAME="mpfr"
+CT_MPFR_PKG_NAME="mpfr"
+CT_MPFR_SRC_RELEASE=y
+CT_MPFR_PATCH_ORDER="global"
+CT_MPFR_V_4_0=y
+# CT_MPFR_V_3_1 is not set
+# CT_MPFR_NO_VERSIONS is not set
+CT_MPFR_VERSION="4.0.2"
+CT_MPFR_MIRRORS="http://www.mpfr.org/mpfr-${CT_MPFR_VERSION} $(CT_Mirrors GNU mpfr)"
+CT_MPFR_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_MPFR_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_MPFR_ARCHIVE_FORMATS=".tar.xz .tar.bz2 .tar.gz .zip"
+CT_MPFR_SIGNATURE_FORMAT="packed/.asc"
+CT_MPFR_later_than_4_0_0=y
+CT_MPFR_4_0_0_or_later=y
+CT_MPFR_later_than_3_0_0=y
+CT_MPFR_3_0_0_or_later=y
+CT_MPFR_REQUIRE_3_0_0_or_later=y
+CT_COMP_LIBS_NCURSES=y
+CT_COMP_LIBS_NCURSES_PKG_KSYM="NCURSES"
+CT_NCURSES_DIR_NAME="ncurses"
+CT_NCURSES_PKG_NAME="ncurses"
+CT_NCURSES_SRC_RELEASE=y
+CT_NCURSES_PATCH_ORDER="global"
+CT_NCURSES_V_6_1=y
+# CT_NCURSES_V_6_0 is not set
+# CT_NCURSES_NO_VERSIONS is not set
+CT_NCURSES_VERSION="6.1"
+CT_NCURSES_MIRRORS="ftp://invisible-island.net/ncurses $(CT_Mirrors GNU ncurses)"
+CT_NCURSES_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_NCURSES_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_NCURSES_ARCHIVE_FORMATS=".tar.gz"
+CT_NCURSES_SIGNATURE_FORMAT="packed/.sig"
+CT_NCURSES_HOST_CONFIG_ARGS=""
+CT_NCURSES_HOST_DISABLE_DB=y
+CT_NCURSES_HOST_FALLBACKS="linux,xterm,xterm-color,xterm-256color,vt100"
+CT_NCURSES_TARGET_CONFIG_ARGS=""
+# CT_NCURSES_TARGET_DISABLE_DB is not set
+CT_NCURSES_TARGET_FALLBACKS=""
+CT_COMP_LIBS_ZLIB=y
+CT_COMP_LIBS_ZLIB_PKG_KSYM="ZLIB"
+CT_ZLIB_DIR_NAME="zlib"
+CT_ZLIB_PKG_NAME="zlib"
+CT_ZLIB_SRC_RELEASE=y
+CT_ZLIB_PATCH_ORDER="global"
+CT_ZLIB_V_1_2_11=y
+# CT_ZLIB_NO_VERSIONS is not set
+CT_ZLIB_VERSION="1.2.11"
+CT_ZLIB_MIRRORS="http://downloads.sourceforge.net/project/libpng/zlib/${CT_ZLIB_VERSION}"
+CT_ZLIB_ARCHIVE_FILENAME="@{pkg_name}-@{version}"
+CT_ZLIB_ARCHIVE_DIRNAME="@{pkg_name}-@{version}"
+CT_ZLIB_ARCHIVE_FORMATS=".tar.xz .tar.gz"
+CT_ZLIB_SIGNATURE_FORMAT="packed/.asc"
+CT_ALL_COMP_LIBS_CHOICES="CLOOG EXPAT GETTEXT GMP ISL LIBELF LIBICONV MPC MPFR NCURSES ZLIB"
+CT_LIBICONV_NEEDED=y
+CT_GETTEXT_NEEDED=y
+CT_GMP_NEEDED=y
+CT_MPFR_NEEDED=y
+CT_ISL_NEEDED=y
+CT_MPC_NEEDED=y
+CT_NCURSES_NEEDED=y
+CT_ZLIB_NEEDED=y
+CT_LIBICONV=y
+CT_GETTEXT=y
+CT_GMP=y
+CT_MPFR=y
+CT_ISL=y
+CT_MPC=y
+CT_NCURSES=y
+CT_ZLIB=y
+
+#
+# Companion tools
+#
+# CT_COMP_TOOLS_FOR_HOST is not set
+# CT_COMP_TOOLS_AUTOCONF is not set
+# CT_COMP_TOOLS_AUTOMAKE is not set
+# CT_COMP_TOOLS_BISON is not set
+# CT_COMP_TOOLS_DTC is not set
+# CT_COMP_TOOLS_LIBTOOL is not set
+# CT_COMP_TOOLS_M4 is not set
+# CT_COMP_TOOLS_MAKE is not set
+CT_ALL_COMP_TOOLS_CHOICES="AUTOCONF AUTOMAKE BISON DTC LIBTOOL M4 MAKE"
diff --git a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile
index 126c292b3..8250ec0c3 100644
--- a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile
+++ b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile
@@ -129,4 +129,6 @@ ENV RUST_CONFIGURE_ARGS --enable-extended --enable-lld --disable-docs \
--set target.wasm32-wasi.wasi-root=/wasm32-wasi \
--musl-root-armv7=/musl-armv7
+ENV EXTERNAL_LLVM 1
+
ENV SCRIPT python3 ../x.py dist --host='' --target $TARGETS
diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
index 973c43072..423aba06c 100644
--- a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
+++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
@@ -78,11 +78,12 @@ ENV RUST_CONFIGURE_ARGS \
--set llvm.thin-lto=true \
--set llvm.ninja=false \
--set rust.jemalloc \
- --set rust.use-lld=true
+ --set rust.use-lld=true \
+ --set rust.lto=thin
ENV SCRIPT ../src/ci/pgo.sh python3 ../x.py dist \
--host $HOSTS --target $HOSTS \
--include-default-paths \
- build-manifest
+ build-manifest bootstrap
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=clang
# This is the only builder which will create source tarballs
diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh b/src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh
index fa780e1e4..9abfd4e97 100755
--- a/src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh
+++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh
@@ -22,7 +22,7 @@ INC="/rustroot/include:/usr/include"
# We need compiler-rt for the profile runtime (used later to PGO the LLVM build)
# but sanitizers aren't currently building. Since we don't need those, just
-# disable them.
+# disable them. BOLT is used for optimizing LLVM.
hide_output \
cmake ../llvm \
-DCMAKE_C_COMPILER=/rustroot/bin/gcc \
@@ -36,7 +36,7 @@ hide_output \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
- -DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt" \
+ -DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt;bolt" \
-DC_INCLUDE_DIRS="$INC"
hide_output make -j$(nproc)
diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13-stage1/Dockerfile b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13-stage1/Dockerfile
index 23f2215c2..1289f116f 100644
--- a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13-stage1/Dockerfile
+++ b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13-stage1/Dockerfile
@@ -29,6 +29,7 @@ RUN sh /scripts/sccache.sh
# We are disabling CI LLVM since this builder is intentionally using a host
# LLVM, rather than the typical src/llvm-project LLVM.
ENV NO_DOWNLOAD_CI_LLVM 1
+ENV EXTERNAL_LLVM 1
# Using llvm-link-shared due to libffi issues -- see #34486
ENV RUST_CONFIGURE_ARGS \
diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13/Dockerfile b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13/Dockerfile
index 8f6831bc5..4b89a72ba 100644
--- a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13/Dockerfile
+++ b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13/Dockerfile
@@ -40,6 +40,7 @@ RUN sh /scripts/sccache.sh
# We are disabling CI LLVM since this builder is intentionally using a host
# LLVM, rather than the typical src/llvm-project LLVM.
ENV NO_DOWNLOAD_CI_LLVM 1
+ENV EXTERNAL_LLVM 1
# Using llvm-link-shared due to libffi issues -- see #34486
ENV RUST_CONFIGURE_ARGS \
diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version
index 2774f8587..cc96715b2 100644
--- a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version
+++ b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version
@@ -1 +1 @@
-0.10.0 \ No newline at end of file
+0.12.7 \ No newline at end of file
diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh b/src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh
index 0fb8f41a7..80a066cac 100755
--- a/src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh
+++ b/src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh
@@ -4,7 +4,7 @@ set -eu
X_PY="$1"
-# Try to test all the tools and store the build/test success in the TOOLSTATE_FILE
+# Try to test the toolstate-tracked tools and store the build/test success in the TOOLSTATE_FILE.
set +e
python3 "$X_PY" test --stage 2 --no-fail-fast \
@@ -14,12 +14,19 @@ python3 "$X_PY" test --stage 2 --no-fail-fast \
src/doc/rust-by-example \
src/doc/embedded-book \
src/doc/edition-guide \
- src/tools/miri \
set -e
# debugging: print out the saved toolstates
cat /tmp/toolstate/toolstates.json
+
+# Test remaining tools that must pass.
python3 "$X_PY" test --stage 2 check-tools
python3 "$X_PY" test --stage 2 src/tools/clippy
python3 "$X_PY" test --stage 2 src/tools/rustfmt
+python3 "$X_PY" test --stage 2 src/tools/miri
+# We natively run this script on x86_64-unknown-linux-gnu and x86_64-pc-windows-msvc.
+# Also cover some other targets (on both of these hosts) via cross-testing.
+python3 "$X_PY" test --stage 2 src/tools/miri --target i686-pc-windows-msvc
+#FIXME(https://github.com/rust-lang/rust/issues/103519): macOS testing is currently disabled
+# python3 "$X_PY" test --stage 2 src/tools/miri --target aarch64-apple-darwin
diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml
index 6e4b0b0c2..10de2e8d5 100644
--- a/src/ci/github-actions/ci.yml
+++ b/src/ci/github-actions/ci.yml
@@ -153,6 +153,10 @@ x--expand-yaml-anchors--remove:
run: src/ci/scripts/install-sccache.sh
<<: *step
+ - name: select Xcode
+ run: src/ci/scripts/select-xcode.sh
+ <<: *step
+
- name: install clang
run: src/ci/scripts/install-clang.sh
<<: *step
@@ -264,6 +268,9 @@ on:
branches:
- "**"
+permissions:
+ contents: read
+
defaults:
run:
# On Linux, macOS, and Windows, use the system-provided bash as the default
@@ -273,6 +280,8 @@ defaults:
jobs:
pr:
+ permissions:
+ actions: write # for rust-lang/simpleinfra/github-actions/cancel-outdated-builds
<<: *base-ci-job
name: PR
env:
@@ -286,13 +295,15 @@ jobs:
- name: x86_64-gnu-llvm-13
<<: *job-linux-xl
-
+
- name: x86_64-gnu-tools
env:
CI_ONLY_WHEN_SUBMODULES_CHANGED: 1
<<: *job-linux-xl
auto:
+ permissions:
+ actions: write # for rust-lang/simpleinfra/github-actions/cancel-outdated-builds
<<: *base-ci-job
name: auto
env:
@@ -455,10 +466,11 @@ jobs:
- name: dist-x86_64-apple
env:
- SCRIPT: ./x.py dist --host=x86_64-apple-darwin --target=x86_64-apple-darwin
+ SCRIPT: ./x.py dist bootstrap --include-default-paths --host=x86_64-apple-darwin --target=x86_64-apple-darwin
RUST_CONFIGURE_ARGS: --enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
MACOSX_DEPLOYMENT_TARGET: 10.7
+ SELECT_XCODE: /Applications/Xcode_13.4.1.app
NO_LLVM_ASSERTIONS: 1
NO_DEBUG_ASSERTIONS: 1
NO_OVERFLOW_CHECKS: 1
@@ -467,10 +479,11 @@ jobs:
- name: dist-apple-various
env:
- SCRIPT: ./x.py dist --host='' --target=aarch64-apple-ios,x86_64-apple-ios,aarch64-apple-ios-sim
+ SCRIPT: ./x.py dist bootstrap --include-default-paths --host='' --target=aarch64-apple-ios,x86_64-apple-ios,aarch64-apple-ios-sim
RUST_CONFIGURE_ARGS: --enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
MACOSX_DEPLOYMENT_TARGET: 10.7
+ SELECT_XCODE: /Applications/Xcode_13.4.1.app
NO_LLVM_ASSERTIONS: 1
NO_DEBUG_ASSERTIONS: 1
NO_OVERFLOW_CHECKS: 1
@@ -478,10 +491,11 @@ jobs:
- name: dist-x86_64-apple-alt
env:
- SCRIPT: ./x.py dist
+ SCRIPT: ./x.py dist bootstrap --include-default-paths
RUST_CONFIGURE_ARGS: --enable-extended --enable-profiler --set rust.jemalloc --set llvm.ninja=false
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
MACOSX_DEPLOYMENT_TARGET: 10.7
+ SELECT_XCODE: /Applications/Xcode_13.4.1.app
NO_LLVM_ASSERTIONS: 1
NO_DEBUG_ASSERTIONS: 1
NO_OVERFLOW_CHECKS: 1
@@ -508,7 +522,7 @@ jobs:
# This target only needs to support 11.0 and up as nothing else supports the hardware
- name: dist-aarch64-apple
env:
- SCRIPT: ./x.py dist --stage 2
+ SCRIPT: ./x.py dist bootstrap --include-default-paths --stage 2
RUST_CONFIGURE_ARGS: >-
--build=x86_64-apple-darwin
--host=aarch64-apple-darwin
@@ -520,6 +534,7 @@ jobs:
--set rust.jemalloc
--set llvm.ninja=false
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
+ SELECT_XCODE: /Applications/Xcode_13.4.1.app
USE_XCODE_CLANG: 1
MACOSX_DEPLOYMENT_TARGET: 11.0
MACOSX_STD_DEPLOYMENT_TARGET: 11.0
@@ -652,7 +667,7 @@ jobs:
--target=x86_64-pc-windows-msvc
--enable-full-tools
--enable-profiler
- SCRIPT: PGO_HOST=x86_64-pc-windows-msvc src/ci/pgo.sh python x.py dist
+ SCRIPT: PGO_HOST=x86_64-pc-windows-msvc src/ci/pgo.sh python x.py dist bootstrap --include-default-paths
DIST_REQUIRE_ALL_TOOLS: 1
<<: *job-windows-xl
@@ -664,7 +679,7 @@ jobs:
--target=i686-pc-windows-msvc,i586-pc-windows-msvc
--enable-full-tools
--enable-profiler
- SCRIPT: python x.py dist
+ SCRIPT: python x.py dist bootstrap --include-default-paths
DIST_REQUIRE_ALL_TOOLS: 1
<<: *job-windows-xl
@@ -675,7 +690,7 @@ jobs:
--host=aarch64-pc-windows-msvc
--enable-full-tools
--enable-profiler
- SCRIPT: python x.py dist
+ SCRIPT: python x.py dist bootstrap --include-default-paths
DIST_REQUIRE_ALL_TOOLS: 1
# Hack around this SDK version, because it doesn't work with clang.
# See https://github.com/rust-lang/rust/issues/88796
@@ -692,14 +707,14 @@ jobs:
# We are intentionally allowing an old toolchain on this builder (and that's
# incompatible with LLVM downloads today).
NO_DOWNLOAD_CI_LLVM: 1
- SCRIPT: python x.py dist
+ SCRIPT: python x.py dist bootstrap --include-default-paths
CUSTOM_MINGW: 1
DIST_REQUIRE_ALL_TOOLS: 1
<<: *job-windows-xl
- name: dist-x86_64-mingw
env:
- SCRIPT: python x.py dist
+ SCRIPT: python x.py dist bootstrap --include-default-paths
RUST_CONFIGURE_ARGS: >-
--build=x86_64-pc-windows-gnu
--enable-full-tools
@@ -715,10 +730,12 @@ jobs:
- name: dist-x86_64-msvc-alt
env:
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-extended --enable-profiler
- SCRIPT: python x.py dist
+ SCRIPT: python x.py dist bootstrap --include-default-paths
<<: *job-windows-xl
try:
+ permissions:
+ actions: write # for rust-lang/simpleinfra/github-actions/cancel-outdated-builds
<<: *base-ci-job
name: try
env:
diff --git a/src/ci/pgo.sh b/src/ci/pgo.sh
index b60b7868d..cbe32920a 100755
--- a/src/ci/pgo.sh
+++ b/src/ci/pgo.sh
@@ -190,11 +190,40 @@ rm -r $RUSTC_PROFILE_DIRECTORY_ROOT
# directories ourselves.
rm -r $BUILD_ARTIFACTS/llvm $BUILD_ARTIFACTS/lld
-# This produces the actual final set of artifacts, using both the LLVM and rustc
-# collected profiling data.
-$@ \
- --rust-profile-use=${RUSTC_PROFILE_MERGED_FILE} \
- --llvm-profile-use=${LLVM_PROFILE_MERGED_FILE}
+if isLinux; then
+ # Gather BOLT profile (BOLT is currently only available on Linux)
+ python3 ../x.py build --target=$PGO_HOST --host=$PGO_HOST \
+ --stage 2 library/std \
+ --llvm-profile-use=${LLVM_PROFILE_MERGED_FILE} \
+ --llvm-bolt-profile-generate
+
+ BOLT_PROFILE_MERGED_FILE=/tmp/bolt.profdata
+
+ # Here we're profiling Bolt.
+ gather_profiles "Check,Debug,Opt" "Full" \
+ "syn-1.0.89,serde-1.0.136,ripgrep-13.0.0,regex-1.5.5,clap-3.1.6,hyper-0.14.18"
+
+ merge-fdata /tmp/prof.fdata* > ${BOLT_PROFILE_MERGED_FILE}
+
+ echo "BOLT statistics"
+ du -sh /tmp/prof.fdata*
+ du -sh ${BOLT_PROFILE_MERGED_FILE}
+ echo "Profile file count"
+ find /tmp/prof.fdata* -type f | wc -l
+
+ rm -r $BUILD_ARTIFACTS/llvm $BUILD_ARTIFACTS/lld
+
+ # This produces the actual final set of artifacts, using both the LLVM and rustc
+ # collected profiling data.
+ $@ \
+ --rust-profile-use=${RUSTC_PROFILE_MERGED_FILE} \
+ --llvm-profile-use=${LLVM_PROFILE_MERGED_FILE} \
+ --llvm-bolt-profile-use=${BOLT_PROFILE_MERGED_FILE}
+else
+ $@ \
+ --rust-profile-use=${RUSTC_PROFILE_MERGED_FILE} \
+ --llvm-profile-use=${LLVM_PROFILE_MERGED_FILE}
+fi
echo "Rustc binary size"
ls -la ./build/$PGO_HOST/stage2/bin
diff --git a/src/ci/run.sh b/src/ci/run.sh
index 9a247fb60..9d98ce224 100755
--- a/src/ci/run.sh
+++ b/src/ci/run.sh
@@ -69,6 +69,11 @@ RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-units-std=1"
# space required for CI artifacts.
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --dist-compression-formats=xz"
+# Enable the `c` feature for compiler_builtins, but only when the `compiler-rt` source is available.
+if [ "$EXTERNAL_LLVM" = "" ]; then
+ RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set build.optimized-compiler-builtins"
+fi
+
if [ "$DIST_SRC" = "" ]; then
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-dist-src"
fi
diff --git a/src/ci/scripts/select-xcode.sh b/src/ci/scripts/select-xcode.sh
new file mode 100755
index 000000000..3b9c77d42
--- /dev/null
+++ b/src/ci/scripts/select-xcode.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+# This script selects the Xcode instance to use.
+
+set -euo pipefail
+IFS=$'\n\t'
+
+source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
+
+if isMacOS; then
+ if [[ -s "${SELECT_XCODE-}" ]]; then
+ sudo xcode-select -s "${SELECT_XCODE}"
+ fi
+fi
diff --git a/src/ci/scripts/should-skip-this.sh b/src/ci/scripts/should-skip-this.sh
index c863f1b68..a8a189931 100755
--- a/src/ci/scripts/should-skip-this.sh
+++ b/src/ci/scripts/should-skip-this.sh
@@ -18,10 +18,14 @@ if [[ -n "${CI_ONLY_WHEN_SUBMODULES_CHANGED-}" ]]; then
# Submodules pseudo-files inside git have the 160000 permissions, so when
# those files are present in the diff a submodule was updated.
echo "Submodules were updated"
- elif ! git diff --quiet "$BASE_COMMIT" -- src/tools/clippy src/tools/rustfmt; then
+ elif ! (git diff --quiet "$BASE_COMMIT" -- \
+ src/tools/clippy src/tools/rustfmt src/tools/miri \
+ library/std/src/sys); then
# There is not an easy blanket search for subtrees. For now, manually list
# the subtrees.
- echo "Clippy or rustfmt subtrees were updated"
+ # Also run this when the platform-specific parts of std change, in case
+ # that breaks Miri.
+ echo "Tool subtrees were updated"
elif ! (git diff --quiet "$BASE_COMMIT" -- \
src/test/rustdoc-gui \
src/librustdoc \
diff --git a/src/doc/book/ADMIN_TASKS.md b/src/doc/book/ADMIN_TASKS.md
index 7c152577f..2a92eefd2 100644
--- a/src/doc/book/ADMIN_TASKS.md
+++ b/src/doc/book/ADMIN_TASKS.md
@@ -113,7 +113,12 @@ To check, say, updating `mdbook` or changing the way files get included:
## Produce markdown from docx for diffing
-- TODO Carol to document this next time she does it
+- Save the docx file to `tmp/chapterXX.docx`.
+- In Word, go to the review tab, choose "Accept all changes and stop tracking"
+- Save the docx again and close Word
+- Run `./tools/doc-to-md.sh`
+- This should write `nostarch/chapterXX.md`. Adjust the XSL in
+ `tools/doc-to-md.xsl` and run `./tools/doc-to-md.sh` again if needed.
## Generate Graphviz dot
diff --git a/src/doc/book/TODO.md b/src/doc/book/TODO.md
new file mode 100644
index 000000000..b61f85314
--- /dev/null
+++ b/src/doc/book/TODO.md
@@ -0,0 +1,17 @@
+# In each chapter
+
+- [ ] Manual regeneration
+- [ ] Check for upstream changes from last snapshot
+- [ ] Propagate updated output to docx
+- [ ] Extract docx and check diff
+- [ ] Answer all comments
+- [ ] Check cross references
+- [ ] Check indentation of --snip--
+- [ ] Numbered lines, Gray out unchanged lines
+- [ ] Check line wrapping
+- [ ] Check for unneeded command/compiling/running output
+- [ ] Check println style and error messages
+- [ ] Add alt text to images
+- [ ] Index tags
+ - [ ] search for "convention" conventions:naming:of blah
+ - [ ] check for double spaces, spaces at the end of paragraphs
diff --git a/src/doc/book/ci/dictionary.txt b/src/doc/book/ci/dictionary.txt
index 3fe25ff52..9eb695d5b 100644
--- a/src/doc/book/ci/dictionary.txt
+++ b/src/doc/book/ci/dictionary.txt
@@ -537,6 +537,7 @@ uncommenting
unevaluated
Uninstalling
uninstall
+unittests
unix
unpopulated
unoptimized
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock
index 0a2f222c2..edc20385b 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -8,9 +10,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "getrandom"
-version = "0.2.2"
+version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
+checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
dependencies = [
"cfg-if",
"libc",
@@ -26,33 +28,32 @@ dependencies = [
[[package]]
name = "libc"
-version = "0.2.86"
+version = "0.2.127"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
+checksum = "505e71a4706fa491e9b1b55f51b95d4037d0821ee40131190475f692b35b009b"
[[package]]
name = "ppv-lite86"
-version = "0.2.10"
+version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
+checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
name = "rand_chacha"
-version = "0.3.0"
+version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
+checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
@@ -60,24 +61,15 @@ dependencies = [
[[package]]
name = "rand_core"
-version = "0.6.2"
+version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
+checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
dependencies = [
"getrandom",
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
-version = "0.10.2+wasi-snapshot-preview1"
+version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
+checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml
index cc63f6f02..7eda67aea 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml
@@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.lock b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.lock
index 0a2f222c2..2ae9e459e 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.lock
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -38,14 +40,13 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
@@ -68,15 +69,6 @@ dependencies = [
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.toml b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.toml
index cc63f6f02..7eda67aea 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.toml
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.toml
@@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.lock b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.lock
index 0a2f222c2..2ae9e459e 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.lock
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -38,14 +40,13 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
@@ -68,15 +69,6 @@ dependencies = [
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.toml b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.toml
index cc63f6f02..7eda67aea 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.toml
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.toml
@@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt
index 62fe8327f..fbc0cec33 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt
@@ -5,7 +5,7 @@ $ cargo build
Compiling ppv-lite86 v0.2.10
Compiling rand_core v0.6.2
Compiling rand_chacha v0.3.0
- Compiling rand v0.8.3
+ Compiling rand v0.8.5
Compiling guessing_game v0.1.0 (file:///projects/guessing_game)
error[E0308]: mismatched types
--> src/main.rs:22:21
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.lock b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.lock
index 0a2f222c2..2ae9e459e 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.lock
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -38,14 +40,13 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
@@ -68,15 +69,6 @@ dependencies = [
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.toml b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.toml
index cc63f6f02..7eda67aea 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.toml
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.toml
@@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.lock b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.lock
index 0a2f222c2..2ae9e459e 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.lock
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -38,14 +40,13 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
@@ -68,15 +69,6 @@ dependencies = [
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.toml b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.toml
index cc63f6f02..7eda67aea 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.toml
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/listing-02-06/Cargo.toml
@@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.lock b/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.lock
index 0a2f222c2..2ae9e459e 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.lock
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -38,14 +40,13 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
@@ -68,15 +69,6 @@ dependencies = [
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.toml b/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.toml
index cc63f6f02..7eda67aea 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.toml
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/Cargo.toml
@@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.lock b/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.lock
index 0a2f222c2..2ae9e459e 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.lock
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -38,14 +40,13 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
@@ -68,15 +69,6 @@ dependencies = [
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.toml b/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.toml
index cc63f6f02..7eda67aea 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.toml
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-04-looping/Cargo.toml
@@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.lock b/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.lock
index 0a2f222c2..2ae9e459e 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.lock
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -38,14 +40,13 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
@@ -68,15 +69,6 @@ dependencies = [
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.toml b/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.toml
index cc63f6f02..7eda67aea 100644
--- a/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.toml
+++ b/src/doc/book/listings/ch02-guessing-game-tutorial/no-listing-05-quitting/Cargo.toml
@@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/src/main.rs b/src/doc/book/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/src/main.rs
index 9d3b4813b..77c716c14 100644
--- a/src/doc/book/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/src/main.rs
+++ b/src/doc/book/listings/ch03-common-programming-concepts/no-listing-07-numeric-operations/src/main.rs
@@ -10,7 +10,7 @@ fn main() {
// division
let quotient = 56.7 / 32.2;
- let floored = 2 / 3; // Results in 0
+ let truncated = -5 / 3; // Results in -1
// remainder
let remainder = 43 % 5;
diff --git a/src/doc/book/listings/ch07-managing-growing-projects/listing-07-18/Cargo.lock b/src/doc/book/listings/ch07-managing-growing-projects/listing-07-18/Cargo.lock
index 0a2f222c2..2ae9e459e 100644
--- a/src/doc/book/listings/ch07-managing-growing-projects/listing-07-18/Cargo.lock
+++ b/src/doc/book/listings/ch07-managing-growing-projects/listing-07-18/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -38,14 +40,13 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
@@ -68,15 +69,6 @@ dependencies = [
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/doc/book/listings/ch07-managing-growing-projects/listing-07-18/Cargo.toml b/src/doc/book/listings/ch07-managing-growing-projects/listing-07-18/Cargo.toml
index 15b3fffca..d508e9578 100644
--- a/src/doc/book/listings/ch07-managing-growing-projects/listing-07-18/Cargo.toml
+++ b/src/doc/book/listings/ch07-managing-growing-projects/listing-07-18/Cargo.toml
@@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.lock b/src/doc/book/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.lock
index 0a2f222c2..2ae9e459e 100644
--- a/src/doc/book/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.lock
+++ b/src/doc/book/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -38,14 +40,13 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
@@ -68,15 +69,6 @@ dependencies = [
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/doc/book/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.toml b/src/doc/book/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.toml
index cc63f6f02..7eda67aea 100644
--- a/src/doc/book/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.toml
+++ b/src/doc/book/listings/ch07-managing-growing-projects/no-listing-01-use-std-unnested/Cargo.toml
@@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch08-common-collections/listing-08-04/src/main.rs b/src/doc/book/listings/ch08-common-collections/listing-08-04/src/main.rs
index fa4e090d5..fca332de6 100644
--- a/src/doc/book/listings/ch08-common-collections/listing-08-04/src/main.rs
+++ b/src/doc/book/listings/ch08-common-collections/listing-08-04/src/main.rs
@@ -3,11 +3,11 @@ fn main() {
let v = vec![1, 2, 3, 4, 5];
let third: &i32 = &v[2];
- println!("The third element is {}", third);
+ println!("The third element is {third}");
let third: Option<&i32> = v.get(2);
match third {
- Some(third) => println!("The third element is {}", third),
+ Some(third) => println!("The third element is {third}"),
None => println!("There is no third element."),
}
// ANCHOR_END: here
diff --git a/src/doc/book/listings/ch08-common-collections/listing-08-06/src/main.rs b/src/doc/book/listings/ch08-common-collections/listing-08-06/src/main.rs
index 1b42274a6..653ac27b0 100644
--- a/src/doc/book/listings/ch08-common-collections/listing-08-06/src/main.rs
+++ b/src/doc/book/listings/ch08-common-collections/listing-08-06/src/main.rs
@@ -6,6 +6,6 @@ fn main() {
v.push(6);
- println!("The first element is: {}", first);
+ println!("The first element is: {first}");
// ANCHOR_END: here
}
diff --git a/src/doc/book/listings/ch08-common-collections/listing-08-07/src/main.rs b/src/doc/book/listings/ch08-common-collections/listing-08-07/src/main.rs
index 38b97784b..aebf855a9 100644
--- a/src/doc/book/listings/ch08-common-collections/listing-08-07/src/main.rs
+++ b/src/doc/book/listings/ch08-common-collections/listing-08-07/src/main.rs
@@ -2,7 +2,7 @@ fn main() {
// ANCHOR: here
let v = vec![100, 32, 57];
for i in &v {
- println!("{}", i);
+ println!("{i}");
}
// ANCHOR_END: here
}
diff --git a/src/doc/book/listings/ch08-common-collections/listing-08-16/src/main.rs b/src/doc/book/listings/ch08-common-collections/listing-08-16/src/main.rs
index 8938dc143..db57cddba 100644
--- a/src/doc/book/listings/ch08-common-collections/listing-08-16/src/main.rs
+++ b/src/doc/book/listings/ch08-common-collections/listing-08-16/src/main.rs
@@ -3,6 +3,6 @@ fn main() {
let mut s1 = String::from("foo");
let s2 = "bar";
s1.push_str(s2);
- println!("s2 is {}", s2);
+ println!("s2 is {s2}");
// ANCHOR_END: here
}
diff --git a/src/doc/book/listings/ch08-common-collections/no-listing-02-format/src/main.rs b/src/doc/book/listings/ch08-common-collections/no-listing-02-format/src/main.rs
index 4a38e63d2..db408e2b7 100644
--- a/src/doc/book/listings/ch08-common-collections/no-listing-02-format/src/main.rs
+++ b/src/doc/book/listings/ch08-common-collections/no-listing-02-format/src/main.rs
@@ -4,6 +4,6 @@ fn main() {
let s2 = String::from("tac");
let s3 = String::from("toe");
- let s = format!("{}-{}-{}", s1, s2, s3);
+ let s = format!("{s1}-{s2}-{s3}");
// ANCHOR_END: here
}
diff --git a/src/doc/book/listings/ch08-common-collections/no-listing-03-iterate-over-hashmap/src/main.rs b/src/doc/book/listings/ch08-common-collections/no-listing-03-iterate-over-hashmap/src/main.rs
index 2e7dc02e6..bb13c86f1 100644
--- a/src/doc/book/listings/ch08-common-collections/no-listing-03-iterate-over-hashmap/src/main.rs
+++ b/src/doc/book/listings/ch08-common-collections/no-listing-03-iterate-over-hashmap/src/main.rs
@@ -8,7 +8,7 @@ fn main() {
scores.insert(String::from("Yellow"), 50);
for (key, value) in &scores {
- println!("{}: {}", key, value);
+ println!("{key}: {value}");
}
// ANCHOR_END: here
}
diff --git a/src/doc/book/listings/ch09-error-handling/listing-09-07/src/main.rs b/src/doc/book/listings/ch09-error-handling/listing-09-07/src/main.rs
index f4564f670..0295949d2 100644
--- a/src/doc/book/listings/ch09-error-handling/listing-09-07/src/main.rs
+++ b/src/doc/book/listings/ch09-error-handling/listing-09-07/src/main.rs
@@ -1,7 +1,6 @@
// ANCHOR: here
use std::fs::File;
-use std::io;
-use std::io::Read;
+use std::io::{self, Read};
fn read_username_from_file() -> Result<String, io::Error> {
let mut username_file = File::open("hello.txt")?;
diff --git a/src/doc/book/listings/ch09-error-handling/listing-09-08/src/main.rs b/src/doc/book/listings/ch09-error-handling/listing-09-08/src/main.rs
index c3c6e23ef..ca672caad 100644
--- a/src/doc/book/listings/ch09-error-handling/listing-09-08/src/main.rs
+++ b/src/doc/book/listings/ch09-error-handling/listing-09-08/src/main.rs
@@ -1,7 +1,6 @@
// ANCHOR: here
use std::fs::File;
-use std::io;
-use std::io::Read;
+use std::io::{self, Read};
fn read_username_from_file() -> Result<String, io::Error> {
let mut username = String::new();
diff --git a/src/doc/book/listings/ch09-error-handling/listing-09-13/Cargo.lock b/src/doc/book/listings/ch09-error-handling/listing-09-13/Cargo.lock
index 0a2f222c2..2ae9e459e 100644
--- a/src/doc/book/listings/ch09-error-handling/listing-09-13/Cargo.lock
+++ b/src/doc/book/listings/ch09-error-handling/listing-09-13/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -38,14 +40,13 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
@@ -68,15 +69,6 @@ dependencies = [
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/doc/book/listings/ch09-error-handling/listing-09-13/Cargo.toml b/src/doc/book/listings/ch09-error-handling/listing-09-13/Cargo.toml
index 15b3fffca..d508e9578 100644
--- a/src/doc/book/listings/ch09-error-handling/listing-09-13/Cargo.toml
+++ b/src/doc/book/listings/ch09-error-handling/listing-09-13/Cargo.toml
@@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.lock b/src/doc/book/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.lock
index 0a2f222c2..2ae9e459e 100644
--- a/src/doc/book/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.lock
+++ b/src/doc/book/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -38,14 +40,13 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
@@ -68,15 +69,6 @@ dependencies = [
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/doc/book/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.toml b/src/doc/book/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.toml
index 15b3fffca..d508e9578 100644
--- a/src/doc/book/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.toml
+++ b/src/doc/book/listings/ch09-error-handling/no-listing-09-guess-out-of-range/Cargo.toml
@@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch11-writing-automated-tests/listing-11-01/Cargo.lock b/src/doc/book/listings/ch11-writing-automated-tests/listing-11-01/Cargo.lock
index d37189b33..8b8c69d33 100644
--- a/src/doc/book/listings/ch11-writing-automated-tests/listing-11-01/Cargo.lock
+++ b/src/doc/book/listings/ch11-writing-automated-tests/listing-11-01/Cargo.lock
@@ -1,6 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "adder"
version = "0.1.0"
-
diff --git a/src/doc/book/listings/ch11-writing-automated-tests/listing-11-01/Cargo.toml b/src/doc/book/listings/ch11-writing-automated-tests/listing-11-01/Cargo.toml
index e61cb12e3..b7d36d44c 100644
--- a/src/doc/book/listings/ch11-writing-automated-tests/listing-11-01/Cargo.toml
+++ b/src/doc/book/listings/ch11-writing-automated-tests/listing-11-01/Cargo.toml
@@ -3,4 +3,6 @@ name = "adder"
version = "0.1.0"
edition = "2021"
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
[dependencies]
diff --git a/src/doc/book/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.lock b/src/doc/book/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.lock
index eec3a9e4b..bf6974b58 100644
--- a/src/doc/book/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.lock
+++ b/src/doc/book/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "add_one"
version = "0.1.0"
@@ -45,14 +47,13 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
@@ -75,15 +76,6 @@ dependencies = [
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/doc/book/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/Cargo.toml b/src/doc/book/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/Cargo.toml
index fd4942ace..bc758bd88 100644
--- a/src/doc/book/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/Cargo.toml
+++ b/src/doc/book/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/add_one/Cargo.toml
@@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.lock b/src/doc/book/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.lock
index eec3a9e4b..bf6974b58 100644
--- a/src/doc/book/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.lock
+++ b/src/doc/book/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.lock
@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
+version = 3
+
[[package]]
name = "add_one"
version = "0.1.0"
@@ -45,14 +47,13 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "rand"
-version = "0.8.3"
+version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
- "rand_hc",
]
[[package]]
@@ -75,15 +76,6 @@ dependencies = [
]
[[package]]
-name = "rand_hc"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
-dependencies = [
- "rand_core",
-]
-
-[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src/doc/book/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/Cargo.toml b/src/doc/book/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/Cargo.toml
index fd4942ace..bc758bd88 100644
--- a/src/doc/book/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/Cargo.toml
+++ b/src/doc/book/listings/ch14-more-about-cargo/output-only-03-use-rand/add/add_one/Cargo.toml
@@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
diff --git a/src/doc/book/listings/ch18-patterns-and-matching/listing-18-14/src/main.rs b/src/doc/book/listings/ch18-patterns-and-matching/listing-18-14/src/main.rs
index 8d445d9b9..b71da9a37 100644
--- a/src/doc/book/listings/ch18-patterns-and-matching/listing-18-14/src/main.rs
+++ b/src/doc/book/listings/ch18-patterns-and-matching/listing-18-14/src/main.rs
@@ -8,9 +8,11 @@ fn main() {
let p = Point { x: 0, y: 7 };
match p {
- Point { x, y: 0 } => println!("On the x axis at {}", x),
- Point { x: 0, y } => println!("On the y axis at {}", y),
- Point { x, y } => println!("On neither axis: ({}, {})", x, y),
+ Point { x, y: 0 } => println!("On the x axis at {x}"),
+ Point { x: 0, y } => println!("On the y axis at {y}"),
+ Point { x, y } => {
+ println!("On neither axis: ({x}, {y})");
+ }
}
}
// ANCHOR_END: here
diff --git a/src/doc/book/listings/ch18-patterns-and-matching/listing-18-15/src/main.rs b/src/doc/book/listings/ch18-patterns-and-matching/listing-18-15/src/main.rs
index 9b8dac193..4ddef0aaf 100644
--- a/src/doc/book/listings/ch18-patterns-and-matching/listing-18-15/src/main.rs
+++ b/src/doc/book/listings/ch18-patterns-and-matching/listing-18-15/src/main.rs
@@ -10,18 +10,18 @@ fn main() {
match msg {
Message::Quit => {
- println!("The Quit variant has no data to destructure.")
+ println!("The Quit variant has no data to destructure.");
}
Message::Move { x, y } => {
println!(
- "Move in the x direction {} and in the y direction {}",
- x, y
+ "Move in the x direction {x} and in the y direction {y}"
);
}
- Message::Write(text) => println!("Text message: {}", text),
+ Message::Write(text) => {
+ println!("Text message: {text}");
+ }
Message::ChangeColor(r, g, b) => println!(
- "Change the color to red {}, green {}, and blue {}",
- r, g, b
+ "Change the color to red {r}, green {g}, and blue {b}",
),
}
}
diff --git a/src/doc/book/listings/ch18-patterns-and-matching/listing-18-16/src/main.rs b/src/doc/book/listings/ch18-patterns-and-matching/listing-18-16/src/main.rs
index ed6a20bf4..4c958601b 100644
--- a/src/doc/book/listings/ch18-patterns-and-matching/listing-18-16/src/main.rs
+++ b/src/doc/book/listings/ch18-patterns-and-matching/listing-18-16/src/main.rs
@@ -14,13 +14,11 @@ fn main() {
let msg = Message::ChangeColor(Color::Hsv(0, 160, 255));
match msg {
- Message::ChangeColor(Color::Rgb(r, g, b)) => println!(
- "Change the color to red {}, green {}, and blue {}",
- r, g, b
- ),
+ Message::ChangeColor(Color::Rgb(r, g, b)) => {
+ println!("Change color to red {r}, green {g}, and blue {b}");
+ }
Message::ChangeColor(Color::Hsv(h, s, v)) => println!(
- "Change the color to hue {}, saturation {}, and value {}",
- h, s, v
+ "Change color to hue {h}, saturation {s}, value {v}"
),
_ => (),
}
diff --git a/src/doc/book/nostarch/acknowledgments.md b/src/doc/book/nostarch/acknowledgments.md
index 89d4adffc..c29cb712a 100644
--- a/src/doc/book/nostarch/acknowledgments.md
+++ b/src/doc/book/nostarch/acknowledgments.md
@@ -12,8 +12,6 @@ Karen Rustad Tölva for the cover art. Thank you to our team at No Starch,
including Bill Pollock, Liz Chadwick, and Janelle Ludowise, for improving this
book and bringing it to print.
-<!--Insert Steve's acknowledgements here -->
-
Carol is grateful for the opportunity to work on this book. She thanks her
family for their constant love and support, especially her husband Jake
Goulding and her daughter Vivian.
diff --git a/src/doc/book/nostarch/appendix.md b/src/doc/book/nostarch/appendix.md
index 1722a9345..98432a1da 100644
--- a/src/doc/book/nostarch/appendix.md
+++ b/src/doc/book/nostarch/appendix.md
@@ -8,77 +8,67 @@ directory, so all fixes need to be made in `/src/`.
## Appendix A: Keywords
-The following list contains keywords that are reserved for current or future
+The following lists contain keywords that are reserved for current or future
use by the Rust language. As such, they cannot be used as identifiers (except
-as raw identifiers as we’ll discuss in the “Raw Identifiers†section).
-Identifiers are names of functions, variables, parameters, struct fields,
+as raw identifiers, as we’ll discuss in “Raw Identifiers†on page XX).
+*Identifiers* are names of functions, variables, parameters, struct fields,
modules, crates, constants, macros, static values, attributes, types, traits,
or lifetimes.
-### Keywords Currently in Use
+## Keywords Currently in Use
The following is a list of keywords currently in use, with their functionality
described.
-* `as` - perform primitive casting, disambiguate the specific trait containing
- an item, or rename items in `use` statements
-
-<!-- `extern crate` is a bit old. Not sure if it needs a mention
-/JT -->
-<!-- good call, took it out /Carol -->
-
-* `async` - return a `Future` instead of blocking the current thread
-* `await` - suspend execution until the result of a `Future` is ready
-* `break` - exit a loop immediately
-* `const` - define constant items or constant raw pointers
-* `continue` - continue to the next loop iteration
-* `crate` - in a module path, refers to the crate root
-<!-- these days `crate` is mostly just used as part of the module path
-/JT -->
-<!-- fixed! /Carol -->
-
-* `dyn` - dynamic dispatch to a trait object
-* `else` - fallback for `if` and `if let` control flow constructs
-* `enum` - define an enumeration
-* `extern` - link an external function or variable
-<!-- `extern crate` is a bit out of date
-/JT -->
-<!-- fixed! /Carol -->
-
-* `false` - Boolean false literal
-* `fn` - define a function or the function pointer type
-* `for` - loop over items from an iterator, implement a trait, or specify a
- higher-ranked lifetime
-* `if` - branch based on the result of a conditional expression
-* `impl` - implement inherent or trait functionality
-* `in` - part of `for` loop syntax
-* `let` - bind a variable
-* `loop` - loop unconditionally
-* `match` - match a value to patterns
-* `mod` - define a module
-* `move` - make a closure take ownership of all its captures
-* `mut` - denote mutability in references, raw pointers, or pattern bindings
-* `pub` - denote public visibility in struct fields, `impl` blocks, or modules
-* `ref` - bind by reference
-* `return` - return from function
-* `Self` - a type alias for the type we are defining or implementing
-* `self` - method subject or current module
-* `static` - global variable or lifetime lasting the entire program execution
-* `struct` - define a structure
-* `super` - parent module of the current module
-* `trait` - define a trait
-* `true` - Boolean true literal
-* `type` - define a type alias or associated type
-* `union` - define a union; is only a keyword when used in a union declaration
-* `unsafe` - denote unsafe code, functions, traits, or implementations
-* `use` - bring symbols into scope
-* `where` - denote clauses that constrain a type
-* `while` - loop conditionally based on the result of an expression
-
-### Keywords Reserved for Future Use
+* **`as` **: perform primitive casting, disambiguate the specific trait
+containing an item, or rename items in `use` statements
+* **`async` **: return a `Future` instead of blocking the current thread
+* **`await` **: suspend execution until the result of a `Future` is ready
+* **`break` **: exit a loop immediately
+* **`const` **: define constant items or constant raw pointers
+* **`continue` **: continue to the next loop iteration
+* **`crate` **: in a module path, refers to the crate root
+* **`dyn` **: dynamic dispatch to a trait object
+* **`else` **: fallback for `if` and `if let` control flow constructs
+* **`enum` **: define an enumeration
+* **`extern` **: link an external function or variable
+* **`false` **: Boolean false literal
+* **`fn` **: define a function or the function pointer type
+* **`for` **: loop over items from an iterator, implement a trait, or specify a
+higher-ranked lifetime
+* **`if` **: branch based on the result of a conditional expression
+* **`impl` **: implement inherent or trait functionality
+* **`in` **: part of `for` loop syntax
+* **`let` **: bind a variable
+* **`loop` **: loop unconditionally
+* **`match` **: match a value to patterns
+* **`mod` **: define a module
+* **`move` **: make a closure take ownership of all its captures
+* **`mut` **: denote mutability in references, raw pointers, or pattern bindings
+* **`pub` **: denote public visibility in struct fields, `impl` blocks, or
+modules
+* **`ref` **: bind by reference
+* **`return` **: return from function
+* **`Self` **: a type alias for the type we are defining or implementing
+* **`self` **: method subject or current module
+* **`static` **: global variable or lifetime lasting the entire program
+execution
+* **`struct` **: define a structure
+* **`super` **: parent module of the current module
+* **`trait` **: define a trait
+* **`true` **: Boolean true literal
+* **`type` **: define a type alias or associated type
+* **`union` **: define a union; is a keyword only when used in a union
+declaration
+* **`unsafe` **: denote unsafe code, functions, traits, or implementations
+* **`use` **: bring symbols into scope
+* **`where` **: denote clauses that constrain a type
+* **`while` **: loop conditionally based on the result of an expression
+
+## Keywords Reserved for Future Use
The following keywords do not yet have any functionality but are reserved by
-Rust for potential future use.
+Rust for potential future use:
* `abstract`
* `become`
@@ -94,7 +84,7 @@ Rust for potential future use.
* `virtual`
* `yield`
-### Raw Identifiers
+## Raw Identifiers
*Raw identifiers* are the syntax that lets you use keywords where they wouldn’t
normally be allowed. You use a raw identifier by prefixing a keyword with `r#`.
@@ -145,10 +135,10 @@ choose identifier names, as well as lets us integrate with programs written in
a language where these words aren’t keywords. In addition, raw identifiers
allow you to use libraries written in a different Rust edition than your crate
uses. For example, `try` isn’t a keyword in the 2015 edition but is in the 2018
-edition. If you depend on a library that’s written using the 2015 edition and
-has a `try` function, you’ll need to use the raw identifier syntax, `r#try` in
-this case, to call that function from your 2018 edition code. See Appendix E
-for more information on editions.
+and 2021 editions. If you depend on a library that is written using the 2015
+edition and has a `try` function, you’ll need to use the raw identifier syntax,
+`r#try` in this case, to call that function from your 2021 edition code. See
+Appendix E for more information on editions.
## Appendix B: Operators and Symbols
@@ -156,7 +146,7 @@ This appendix contains a glossary of Rust’s syntax, including operators and
other symbols that appear by themselves or in the context of paths, generics,
trait bounds, macros, attributes, comments, tuples, and brackets.
-### Operators
+## Operators
Table B-1 contains the operators in Rust, an example of how the operator would
appear in context, a short explanation, and whether that operator is
@@ -166,66 +156,72 @@ overload that operator is listed.
Table B-1: Operators
| Operator | Example | Explanation | Overloadable? |
-|----------|---------|-------------|---------------|
-| `!` | `ident!(...)`, `ident!{...}`, `ident![...]` | Macro expansion | |
+|---|---|---|---|
+| `!` | `ident!(...)`, `ident!{...}`, `ident![...]` | Macro expansion | |
| `!` | `!expr` | Bitwise or logical complement | `Not` |
| `!=` | `expr != expr` | Nonequality comparison | `PartialEq` |
-| `%` | `expr % expr` | Arithmetic remainder | `Rem` |
+| `% | `expr % expr` | Arithmetic remainder | `Rem` |
| `%=` | `var %= expr` | Arithmetic remainder and assignment | `RemAssign` |
-| `&` | `&expr`, `&mut expr` | Borrow | |
-| `&` | `&type`, `&mut type`, `&'a type`, `&'a mut type` | Borrowed pointer type | |
+| `& | `&expr`, `&mut expr` | Borrow | |
+| `&` | `&type`, `&mut type`, `&'a type`, `&'a mut type` | Borrowed pointer
+type | |
| `&` | `expr & expr` | Bitwise AND | `BitAnd` |
| `&=` | `var &= expr` | Bitwise AND and assignment | `BitAndAssign` |
-| `&&` | `expr && expr` | Short-circuiting logical AND | |
-| `*` | `expr * expr` | Arithmetic multiplication | `Mul` |
-| `*=` | `var *= expr` | Arithmetic multiplication and assignment | `MulAssign` |
+| `&&` | `expr && expr` | Short-circuiting logical AND | |
+| `* | `expr * expr` | Arithmetic multiplication | `Mul` |
+| `*=` | `var *= expr` | Arithmetic multiplication and assignment | `MulAssign`
+|
| `*` | `*expr` | Dereference | `Deref` |
-| `*` | `*const type`, `*mut type` | Raw pointer | |
-| `+` | `trait + trait`, `'a + trait` | Compound type constraint | |
-| `+` | `expr + expr` | Arithmetic addition | `Add` |
+| `*` | `*const type`, `*mut type | Raw pointer | |
+| `+ | `trait + trait`, `'a + trait` | Compound type constraint | |
+| `+ | `expr + expr` | Arithmetic addition | `Add` |
| `+=` | `var += expr` | Arithmetic addition and assignment | `AddAssign` |
-| `,` | `expr, expr` | Argument and element separator | |
-| `-` | `- expr` | Arithmetic negation | `Neg` |
-| `-` | `expr - expr` | Arithmetic subtraction | `Sub` |
+| `,` | `expr, expr` | Argument and element separator | |
+| `- | `- expr` | Arithmetic negation | `Neg` |
+| `- | `expr - expr` | Arithmetic subtraction | `Sub` |
| `-=` | `var -= expr` | Arithmetic subtraction and assignment | `SubAssign` |
-| `->` | `fn(...) -> type`, <code>&vert;...&vert; -> type</code> | Function and closure return type | |
-| `.` | `expr.ident` | Member access | |
-| `..` | `..`, `expr..`, `..expr`, `expr..expr` | Right-exclusive range literal | `PartialOrd` |
-| `..=` | `..=expr`, `expr..=expr` | Right-inclusive range literal | `PartialOrd` |
-| `..` | `..expr` | Struct literal update syntax | |
-| `..` | `variant(x, ..)`, `struct_type { x, .. }` | “And the rest†pattern binding | |
-| `...` | `expr...expr` | (Deprecated, use `..=` instead) In a pattern: inclusive range pattern | |
-| `/` | `expr / expr` | Arithmetic division | `Div` |
+| `-> | `fn(...) -> type`, `|…| -> type` | Function and closure return type | |
+| `. | `expr.ident` | Member access | |
+| `..` | `..`, `expr..`, `..expr`, `expr..expr` | Right-exclusive range literal
+| `PartialOrd` |
+| `..=` | `..=expr`, `expr..=expr` | Right-inclusive range literal |
+`PartialOrd` |
+| `..` | `..expr` | Struct literal update syntax | |
+| `..` | `variant(x, ..)`, `struct_type { x, .. }` | “And the rest†pattern
+binding | |
+| `...` | `expr...expr` | (Deprecated, use `..=` instead) In a pattern:
+inclusive range pattern | |
+| `/ | `expr / expr` | Arithmetic division | `Div` |
| `/=` | `var /= expr` | Arithmetic division and assignment | `DivAssign` |
-| `:` | `pat: type`, `ident: type` | Constraints | |
-| `:` | `ident: expr` | Struct field initializer | |
-| `:` | `'a: loop {...}` | Loop label | |
-| `;` | `expr;` | Statement and item terminator | |
-| `;` | `[...; len]` | Part of fixed-size array syntax | |
+| `: | `pat: type`, `ident: type` | Constraints | |
+| `:` | `ident: expr` | Struct field initializer | |
+| `:` | `'a: loop {...}` | Loop label | |
+| `; | `expr;` | Statement and item terminator | |
+| `;` | `[...; len]` | Part of fixed-size array syntax | |
| `<<` | `expr << expr` | Left-shift | `Shl` |
| `<<=` | `var <<= expr` | Left-shift and assignment | `ShlAssign` |
| `<` | `expr < expr` | Less than comparison | `PartialOrd` |
| `<=` | `expr <= expr` | Less than or equal to comparison | `PartialOrd` |
-| `=` | `var = expr`, `ident = type` | Assignment/equivalence | |
+| `=` | `var = expr`, `ident = type` | Assignment/equivalence | |
| `==` | `expr == expr` | Equality comparison | `PartialEq` |
-| `=>` | `pat => expr` | Part of match arm syntax | |
+| `=>` | `pat => expr` | Part of match arm syntax | |
| `>` | `expr > expr` | Greater than comparison | `PartialOrd` |
| `>=` | `expr >= expr` | Greater than or equal to comparison | `PartialOrd` |
| `>>` | `expr >> expr` | Right-shift | `Shr` |
| `>>=` | `var >>= expr` | Right-shift and assignment | `ShrAssign` |
-| `@` | `ident @ pat` | Pattern binding | |
+| `@ | `ident @ pat` | Pattern binding | |
| `^` | `expr ^ expr` | Bitwise exclusive OR | `BitXor` |
| `^=` | `var ^= expr` | Bitwise exclusive OR and assignment | `BitXorAssign` |
-| <code>&vert;</code> | <code>pat &vert; pat</code> | Pattern alternatives | |
-| <code>&vert;</code> | <code>expr &vert; expr</code> | Bitwise OR | `BitOr` |
-| <code>&vert;=</code> | <code>var &vert;= expr</code> | Bitwise OR and assignment | `BitOrAssign` |
-| <code>&vert;&vert;</code> | <code>expr &vert;&vert; expr</code> | Short-circuiting logical OR | |
-| `?` | `expr?` | Error propagation | |
+| `| | `pat | pat` | Pattern alternatives | |
+| `|` | `expr | expr` | Bitwise OR | `BitOr` |
+| `|=` | `var |= expr` | Bitwise OR and assignment | `BitOrAssign` |
+| `||` | `expr || expr` | Short-circuiting logical OR | |
+| `? | `expr?` | Error propagation | |
-### Non-operator Symbols
+## Non-operator Symbols
-The following list contains all symbols that don’t function as operators;
-that is, they don’t behave like a function or method call.
+The following tables contain all symbols that don’t function as operators; that
+is, they don’t behave like a function or method call.
Table B-2 shows symbols that appear on their own and are valid in a variety of
locations.
@@ -233,18 +229,22 @@ locations.
Table B-2: Stand-Alone Syntax
| Symbol | Explanation |
-|--------|-------------|
-| `'ident` | Named lifetime or loop label |
-| `...u8`, `...i32`, `...f64`, `...usize`, etc. | Numeric literal of specific type |
-| `"..."` | String literal |
-| `r"..."`, `r#"..."#`, `r##"..."##`, etc. | Raw string literal, escape characters not processed |
-| `b"..."` | Byte string literal; constructs an array of bytes instead of a string |
-| `br"..."`, `br#"..."#`, `br##"..."##`, etc. | Raw byte string literal, combination of raw and byte string literal |
-| `'...'` | Character literal |
-| `b'...'` | ASCII byte literal |
-| <code>&vert;...&vert; expr</code> | Closure |
-| `!` | Always empty bottom type for diverging functions |
-| `_` | “Ignored†pattern binding; also used to make integer literals readable |
+|---|---|
+| `'ident | Named lifetime or loop label |
+| `...u8`, `...i32`, `...f64`, `...usize`, and so on | Numeric literal of
+specific type |
+| `"..." | String literal |
+| `r"..."`, `r#"..."#`, `r##"..."##`, and so on | Raw string literal; escape
+characters not processed |
+| `b"..."` | Byte string literal; constructs an array of bytes instead of a
+string |
+| `br"..."`, `br#"..."#`, `br##"..."##`, and so on | Raw byte string literal;
+combination of raw and byte string literal |
+| `'...' | Character literal |
+| `b'...' | ASCII byte literal |
+| `|…| expr | Closure |
+| `! | Always-empty bottom type for diverging functions |
+| `_ | “Ignored†pattern binding; also used to make integer literals readable |
Table B-3 shows symbols that appear in the context of a path through the module
hierarchy to an item.
@@ -252,16 +252,23 @@ hierarchy to an item.
Table B-3: Path-Related Syntax
| Symbol | Explanation |
-|--------|-------------|
-| `ident::ident` | Namespace path |
-| `::path` | Path relative to the crate root (i.e., an explicitly absolute path) |
-| `self::path` | Path relative to the current module (i.e., an explicitly relative path).
+|---|---|
+| `ident::ident | Namespace path |
+| `::path` | Path relative to the crate root (that is, an explicitly absolute
+path) |
+| `self::path` | Path relative to the current module (that is, an explicitly
+relative path) |
| `super::path` | Path relative to the parent of the current module |
-| `type::ident`, `<type as trait>::ident` | Associated constants, functions, and types |
-| `<type>::...` | Associated item for a type that cannot be directly named (e.g., `<&T>::...`, `<[T]>::...`, etc.) |
-| `trait::method(...)` | Disambiguating a method call by naming the trait that defines it |
-| `type::method(...)` | Disambiguating a method call by naming the type for which it’s defined |
-| `<type as trait>::method(...)` | Disambiguating a method call by naming the trait and type |
+| `type::ident`, `<type as trait>::ident | Associated constants, functions, and
+types |
+| `<type>::...` | Associated item for a type that cannot be directly named (for
+example, `<&T>::...`, `<[T]>::...`, and so on) |
+| `trait::method(...)` | Disambiguating a method call by naming the trait that
+defines it |
+| `type::method(...)` | Disambiguating a method call by naming the type for
+which it’s defined |
+| `<type as trait>::method(...)` | Disambiguating a method call by naming the
+trait and type |
Table B-4 shows symbols that appear in the context of using generic type
parameters.
@@ -269,15 +276,19 @@ parameters.
Table B-4: Generics
| Symbol | Explanation |
-|--------|-------------|
-| `path<...>` | Specifies parameters to generic type in a type (e.g., `Vec<u8>`) |
-| `path::<...>`, `method::<...>` | Specifies parameters to generic type, function, or method in an expression; often referred to as turbofish (e.g., `"42".parse::<i32>()`) |
+|---|---|
+| `path<...>` | Specifies parameters to a generic type in a type (for example,
+`Vec<u8>`) |
+| `path::<...>, method::<...>` | Specifies parameters to a generic type,
+function, or method in an expression; often referred to as turbofish (for
+example, `"42".parse::<i32>()`) |
| `fn ident<...> ...` | Define generic function |
| `struct ident<...> ...` | Define generic structure |
| `enum ident<...> ...` | Define generic enumeration |
| `impl<...> ...` | Define generic implementation |
| `for<...> type` | Higher-ranked lifetime bounds |
-| `type<ident=type>` | A generic type where one or more associated types have specific assignments (e.g., `Iterator<Item=T>`) |
+| `type<ident=type>` | A generic type where one or more associated types have
+specific assignments (for example, `Iterator<Item=T>`) |
Table B-5 shows symbols that appear in the context of constraining generic type
parameters with trait bounds.
@@ -285,10 +296,12 @@ parameters with trait bounds.
Table B-5: Trait Bound Constraints
| Symbol | Explanation |
-|--------|-------------|
-| `T: U` | Generic parameter `T` constrained to types that implement `U` |
-| `T: 'a` | Generic type `T` must outlive lifetime `'a` (meaning the type cannot transitively contain any references with lifetimes shorter than `'a`) |
-| `T: 'static` | Generic type `T` contains no borrowed references other than `'static` ones |
+|---|---|
+| T: U` | Generic parameter `T` constrained to types that implement `U` |
+| `T: 'a` | Generic type `T` must outlive lifetime `'a` (meaning the type
+cannot transitively contain any references with lifetimes shorter than `'a`) |
+| `T: 'static` | Generic type `T` contains no borrowed references other than
+`'static` ones |
| `'b: 'a` | Generic lifetime `'b` must outlive lifetime `'a` |
| `T: ?Sized` | Allow generic type parameter to be a dynamically sized type |
| `'a + trait`, `trait + trait` | Compound type constraint |
@@ -299,7 +312,7 @@ macros and specifying attributes on an item.
Table B-6: Macros and Attributes
| Symbol | Explanation |
-|--------|-------------|
+|---|---|
| `#[meta]` | Outer attribute |
| `#![meta]` | Inner attribute |
| `$ident` | Macro substitution |
@@ -312,7 +325,7 @@ Table B-7 shows symbols that create comments.
Table B-7: Comments
| Symbol | Explanation |
-|--------|-------------|
+|---|---|
| `//` | Line comment |
| `//!` | Inner line doc comment |
| `///` | Outer line doc comment |
@@ -325,22 +338,23 @@ Table B-8 shows symbols that appear in the context of using tuples.
Table B-8: Tuples
| Symbol | Explanation |
-|--------|-------------|
-| `()` | Empty tuple (aka unit), both literal and type |
+|---|---|
+| `() | Empty tuple (aka unit), both literal and type |
| `(expr)` | Parenthesized expression |
| `(expr,)` | Single-element tuple expression |
| `(type,)` | Single-element tuple type |
| `(expr, ...)` | Tuple expression |
| `(type, ...)` | Tuple type |
-| `expr(expr, ...)` | Function call expression; also used to initialize tuple `struct`s and tuple `enum` variants |
-| `expr.0`, `expr.1`, etc. | Tuple indexing |
+| `expr(expr, ...)` | Function call expression; also used to initialize tuple
+`struct`s and tuple `enum` variants |
+| `expr.0`, `expr.1`, and so on | Tuple indexing |
-Table B-9 shows the contexts in which curly braces are used.
+Table B-9 shows the contexts in which curly brackets are used.
Table B-9: Curly Brackets
| Context | Explanation |
-|---------|-------------|
+|---|---|
| `{...}` | Block expression |
| `Type {...}` | `struct` literal |
@@ -349,12 +363,14 @@ Table B-10 shows the contexts in which square brackets are used.
Table B-10: Square Brackets
| Context | Explanation |
-|---------|-------------|
+|---|---|
| `[...]` | Array literal |
| `[expr; len]` | Array literal containing `len` copies of `expr` |
| `[type; len]` | Array type containing `len` instances of `type` |
-| `expr[expr]` | Collection indexing. Overloadable (`Index`, `IndexMut`) |
-| `expr[..]`, `expr[a..]`, `expr[..b]`, `expr[a..b]` | Collection indexing pretending to be collection slicing, using `Range`, `RangeFrom`, `RangeTo`, or `RangeFull` as the “index†|
+| `expr[expr]` | Collection indexing; overloadable (`Index`, `IndexMut`) |
+| `expr[..]`, `expr[a..]`, `expr[..b]`, `expr[a..b]` | Collection indexing
+pretending to be collection slicing, using `Range`, `RangeFrom`, `RangeTo`, or
+`RangeFull` as the “index†|
## Appendix C: Derivable Traits
@@ -373,14 +389,13 @@ library that you can use with `derive`. Each section covers:
* Examples of operations that require the trait
If you want different behavior from that provided by the `derive` attribute,
-consult the standard library documentation for each trait for details of how to
+consult the standard library documentation for each trait for details on how to
manually implement them.
-These traits listed here are the only ones defined by the standard library that
-can be implemented on your types using `derive`.
-Other traits defined in the standard library don’t have sensible default
-behavior, so it’s up to you to implement them in the way that makes sense for
-what you’re trying to accomplish.
+The traits listed here are the only ones defined by the standard library that
+can be implemented on your types using `derive`. Other traits defined in the
+standard library don’t have sensible default behavior, so it’s up to you to
+implement them in the way that makes sense for what you’re trying to accomplish.
An example of a trait that can’t be derived is `Display`, which handles
formatting for end users. You should always consider the appropriate way to
@@ -391,11 +406,10 @@ it can’t provide appropriate default behavior for you.
The list of derivable traits provided in this appendix is not comprehensive:
libraries can implement `derive` for their own traits, making the list of
-traits you can use `derive` with truly open-ended. Implementing `derive`
-involves using a procedural macro, which is covered in the
-“Macros†section of Chapter 19.
+traits you can use `derive` with truly open ended. Implementing `derive`
+involves using a procedural macro, which is covered in “Macros†on page XX.
-### `Debug` for Programmer Output
+## Debug for Programmer Output
The `Debug` trait enables debug formatting in format strings, which you
indicate by adding `:?` within `{}` placeholders.
@@ -404,11 +418,12 @@ The `Debug` trait allows you to print instances of a type for debugging
purposes, so you and other programmers using your type can inspect an instance
at a particular point in a program’s execution.
-The `Debug` trait is required, for example, in use of the `assert_eq!` macro.
-This macro prints the values of instances given as arguments if the equality
-assertion fails so programmers can see why the two instances weren’t equal.
+The `Debug` trait is required, for example, in the use of the `assert_eq!`
+macro. This macro prints the values of instances given as arguments if the
+equality assertion fails so programmers can see why the two instances weren’t
+equal.
-### `PartialEq` and `Eq` for Equality Comparisons
+## PartialEq and Eq for Equality Comparisons
The `PartialEq` trait allows you to compare instances of a type to check for
equality and enables use of the `==` and `!=` operators.
@@ -425,14 +440,14 @@ for equality.
The `Eq` trait has no methods. Its purpose is to signal that for every value of
the annotated type, the value is equal to itself. The `Eq` trait can only be
applied to types that also implement `PartialEq`, although not all types that
-implement `PartialEq` can implement `Eq`. One example of this is floating point
-number types: the implementation of floating point numbers states that two
+implement `PartialEq` can implement `Eq`. One example of this is floating-point
+number types: the implementation of floating-point numbers states that two
instances of the not-a-number (`NaN`) value are not equal to each other.
-An example of when `Eq` is required is for keys in a `HashMap<K, V>` so the
-`HashMap<K, V>` can tell whether two keys are the same.
+An example of when `Eq` is required is for keys in a `HashMap<K, V>` so that
+the `HashMap<K, V>` can tell whether two keys are the same.
-### `PartialOrd` and `Ord` for Ordering Comparisons
+## PartialOrd and Ord for Ordering Comparisons
The `PartialOrd` trait allows you to compare instances of a type for sorting
purposes. A type that implements `PartialOrd` can be used with the `<`, `>`,
@@ -443,8 +458,8 @@ Deriving `PartialOrd` implements the `partial_cmp` method, which returns an
`Option<Ordering>` that will be `None` when the values given don’t produce an
ordering. An example of a value that doesn’t produce an ordering, even though
most values of that type can be compared, is the not-a-number (`NaN`) floating
-point value. Calling `partial_cmp` with any floating point number and the `NaN`
-floating point value will return `None`.
+point value. Calling `partial_cmp` with any floating-point number and the `NaN`
+floating-point value will return `None`.
When derived on structs, `PartialOrd` compares two instances by comparing the
value in each field in the order in which the fields appear in the struct
@@ -466,12 +481,12 @@ implementation for `partial_cmp` does with `PartialOrd`.
An example of when `Ord` is required is when storing values in a `BTreeSet<T>`,
a data structure that stores data based on the sort order of the values.
-### `Clone` and `Copy` for Duplicating Values
+## Clone and Copy for Duplicating Values
The `Clone` trait allows you to explicitly create a deep copy of a value, and
the duplication process might involve running arbitrary code and copying heap
-data. See the “Ways Variables and Data Interact: Clone†section in Chapter 4
-for more information on `Clone`.
+data. See “Variables and Data Interacting with Clone†on page XX for more
+information on `Clone`.
Deriving `Clone` implements the `clone` method, which when implemented for the
whole type, calls `clone` on each of the parts of the type. This means all the
@@ -480,11 +495,11 @@ fields or values in the type must also implement `Clone` to derive `Clone`.
An example of when `Clone` is required is when calling the `to_vec` method on a
slice. The slice doesn’t own the type instances it contains, but the vector
returned from `to_vec` will need to own its instances, so `to_vec` calls
-`clone` on each item. Thus, the type stored in the slice must implement `Clone`.
+`clone` on each item. Thus the type stored in the slice must implement `Clone`.
The `Copy` trait allows you to duplicate a value by only copying bits stored on
-the stack; no arbitrary code is necessary. See the “Stack-Only Data: Copyâ€
-section in Chapter 4 for more information on `Copy`.
+the stack; no arbitrary code is necessary. See “Stack-Only Data: Copy†on page
+XX for more information on `Copy`.
The `Copy` trait doesn’t define any methods to prevent programmers from
overloading those methods and violating the assumption that no arbitrary code
@@ -492,7 +507,7 @@ is being run. That way, all programmers can assume that copying a value will be
very fast.
You can derive `Copy` on any type whose parts all implement `Copy`. A type that
-implements `Copy` must also implement `Clone`, because a type that implements
+implements `Copy` must also implement `Clone` because a type that implements
`Copy` has a trivial implementation of `Clone` that performs the same task as
`Copy`.
@@ -503,7 +518,7 @@ the code more concise.
Everything possible with `Copy` you can also accomplish with `Clone`, but the
code might be slower or have to use `clone` in places.
-### `Hash` for Mapping a Value to a Value of Fixed Size
+## Hash for Mapping a Value to a Value of Fixed Size
The `Hash` trait allows you to take an instance of a type of arbitrary size and
map that instance to a value of fixed size using a hash function. Deriving
@@ -514,7 +529,7 @@ meaning all fields or values must also implement `Hash` to derive `Hash`.
An example of when `Hash` is required is in storing keys in a `HashMap<K, V>`
to store data efficiently.
-### `Default` for Default Values
+## Default for Default Values
The `Default` trait allows you to create a default value for a type. Deriving
`Default` implements the `default` function. The derived implementation of the
@@ -523,9 +538,9 @@ meaning all fields or values in the type must also implement `Default` to
derive `Default`.
The `Default::default` function is commonly used in combination with the struct
-update syntax discussed in the “Creating Instances From Other Instances With
-Struct Update Syntax†section in Chapter 5. You can customize a few fields of a
-struct and then set and use a default value for the rest of the fields by using
+update syntax discussed in “Creating Instances from Other Instances with Struct
+Update Syntax†on page XX. You can customize a few fields of a struct and then
+set and use a default value for the rest of the fields by using
`..Default::default()`.
The `Default` trait is required when you use the method `unwrap_or_default` on
@@ -533,26 +548,23 @@ The `Default` trait is required when you use the method `unwrap_or_default` on
`unwrap_or_default` will return the result of `Default::default` for the type
`T` stored in the `Option<T>`.
-## Appendix D - Useful Development Tools
+## Appendix D: Useful Development Tools
In this appendix, we talk about some useful development tools that the Rust
project provides. We’ll look at automatic formatting, quick ways to apply
warning fixes, a linter, and integrating with IDEs.
-### Automatic Formatting with `rustfmt`
+## Automatic Formatting with rustfmt
The `rustfmt` tool reformats your code according to the community code style.
Many collaborative projects use `rustfmt` to prevent arguments about which
style to use when writing Rust: everyone formats their code using the tool.
-To install `rustfmt`, enter the following:
-
-```
-$ rustup component add rustfmt
-```
-
-This command gives you `rustfmt` and `cargo-fmt`, similar to how Rust gives you
-both `rustc` and `cargo`. To format any Cargo project, enter the following:
+Rust installations include `rustfmt` by default, so you should already have the
+programs `rustfmt` and `cargo-fmt` on your system. These two commands are
+analagous to `rustc` and `cargo` in that `rustfmt` allows finer-grained control
+and `cargo-fmt` understands conventions of a project that uses Cargo. To format
+any Cargo project, enter the following:
```
$ cargo fmt
@@ -562,13 +574,12 @@ Running this command reformats all the Rust code in the current crate. This
should only change the code style, not the code semantics. For more information
on `rustfmt`, see its documentation at *https://github.com/rust-lang/rustfmt*.
+## Fix Your Code with rustfix
-### Fix Your Code with `rustfix`
-
-The rustfix tool is included with Rust installations and can automatically fix
-compiler warnings that have a clear way to correct the problem that’s likely
-what you want. It’s likely you’ve seen compiler warnings before. For example,
-consider this code:
+The `rustfix` tool is included with Rust installations and can automatically
+fix compiler warnings that have a clear way to correct the problem that’s
+likely what you want. You’ve probably seen compiler warnings before. For
+example, consider this code:
Filename: src/main.rs
@@ -631,16 +642,11 @@ The `for` loop variable is now named `_i`, and the warning no longer appears.
You can also use the `cargo fix` command to transition your code between
different Rust editions. Editions are covered in Appendix E.
-### More Lints with Clippy
+## More Lints with Clippy
The Clippy tool is a collection of lints to analyze your code so you can catch
-common mistakes and improve your Rust code.
-
-To install Clippy, enter the following:
-
-```
-$ rustup component add clippy
-```
+common mistakes and improve your Rust code. Clippy is included with standard
+Rust installations.
To run Clippy’s lints on any Cargo project, enter the following:
@@ -664,14 +670,16 @@ fn main() {
Running `cargo clippy` on this project results in this error:
```
-error: approximate value of `f{32, 64}::consts::PI` found. Consider using it directly
+error: approximate value of `f{32, 64}::consts::PI` found
--> src/main.rs:2:13
|
2 | let x = 3.1415;
| ^^^^^^
|
- = note: #[deny(clippy::approx_constant)] on by default
- = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/master/index.html#approx_constant
+ = note: `#[deny(clippy::approx_constant)]` on by default
+ = help: consider using the constant directly
+ = help: for further information visit https://rust-lang.github.io/rust-
+clippy/master/index.html#approx_constant
```
This error lets you know that Rust already has a more precise `PI` constant
@@ -690,23 +698,24 @@ fn main() {
}
```
-For more information on Clippy, see its documentation at *https://github.com/rust-lang/rust-clippy*.
+For more information on Clippy, see its documentation at
+*https://github.com/rust-lang/rust-clippy**.*
-### IDE Integration Using `rust-analyzer`
+## IDE Integration Using rust-analyzer
-To help IDE integration, the Rust community recommends using `rust-analyzer`.
-This tool is a set of compiler-centric utilities that speaks the Language
-Server Protocol, which is a specification for IDEs and programming languages to
-communicate with each other. Different clients can use `rust-analyzer`, such as
-the Rust analyzer plug-in for Visual Studio Code at
+To help with IDE integration, the Rust community recommends using
+`rust-analyzer`. This tool is a set of compiler-centric utilities that speak
+Language Server Protocol, which is a specification for IDEs and programming
+languages to communicate with each other. Different clients can use
+`rust-analyzer`, such as the Rust analyzer plug-in for Visual Studio Code at
*https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer*.
Visit the `rust-analyzer` project’s home page at
*https://rust-analyzer.github.io* for installation instructions, then install
the language server support in your particular IDE. Your IDE will gain
-abilities such as autocompletion, jump to definition, and inline errors.
+capabilities such as autocompletion, jump to definition, and inline errors
-## Appendix E - Editions
+## Appendix E: Editions
In Chapter 1, you saw that `cargo new` adds a bit of metadata to your
*Cargo.toml* file about an edition. This appendix talks about what that means!
@@ -726,11 +735,11 @@ six-week release process.
Editions serve different purposes for different people:
* For active Rust users, a new edition brings together incremental changes into
- an easy-to-understand package.
+an easy-to-understand package.
* For non-users, a new edition signals that some major advancements have
- landed, which might make Rust worth another look.
+landed, which might make Rust worth another look.
* For those developing Rust, a new edition provides a rallying point for the
- project as a whole.
+project as a whole.
At the time of this writing, three Rust editions are available: Rust 2015, Rust
2018, and Rust 2021. This book is written using Rust 2021 edition idioms.
@@ -759,7 +768,8 @@ made. However, in some cases, mainly when new keywords are added, some new
features might only be available in later editions. You will need to switch
editions if you want to take advantage of such features.
-For more details, the *Edition
-Guide* at *https://doc.rust-lang.org/stable/edition-guide/* is a complete book
-about editions that enumerates the differences between editions and explains
-how to automatically upgrade your code to a new edition via `cargo fix`.
+For more details, *The* *Edition Guide* at
+*https://doc.rust-lang.org/stable/edition-guide* is a complete book about
+editions that enumerates the differences between editions and explains how to
+automatically upgrade your code to a new edition via `cargo fix`.
+
diff --git a/src/doc/book/nostarch/appendix_a.md b/src/doc/book/nostarch/appendix_a.md
new file mode 100644
index 000000000..ca3883be4
--- /dev/null
+++ b/src/doc/book/nostarch/appendix_a.md
@@ -0,0 +1,142 @@
+<!-- DO NOT EDIT THIS FILE.
+
+This file is periodically generated from the content in the `/src/`
+directory, so all fixes need to be made in `/src/`.
+-->
+
+[TOC]
+
+## Appendix A: Keywords
+
+The following lists contain keywords that are reserved for current or future
+use by the Rust language. As such, they cannot be used as identifiers (except
+as raw identifiers, as we’ll discuss in “Raw Identifiers†on page XX).
+*Identifiers* are names of functions, variables, parameters, struct fields,
+modules, crates, constants, macros, static values, attributes, types, traits,
+or lifetimes.
+
+## Keywords Currently in Use
+
+The following is a list of keywords currently in use, with their functionality
+described.
+
+* **`as` **: perform primitive casting, disambiguate the specific trait
+containing an item, or rename items in `use` statements
+* **`async` **: return a `Future` instead of blocking the current thread
+* **`await` **: suspend execution until the result of a `Future` is ready
+* **`break` **: exit a loop immediately
+* **`const` **: define constant items or constant raw pointers
+* **`continue` **: continue to the next loop iteration
+* **`crate` **: in a module path, refers to the crate root
+* **`dyn` **: dynamic dispatch to a trait object
+* **`else` **: fallback for `if` and `if let` control flow constructs
+* **`enum` **: define an enumeration
+* **`extern` **: link an external function or variable
+* **`false` **: Boolean false literal
+* **`fn` **: define a function or the function pointer type
+* **`for` **: loop over items from an iterator, implement a trait, or specify a
+higher-ranked lifetime
+* **`if` **: branch based on the result of a conditional expression
+* **`impl` **: implement inherent or trait functionality
+* **`in` **: part of `for` loop syntax
+* **`let` **: bind a variable
+* **`loop` **: loop unconditionally
+* **`match` **: match a value to patterns
+* **`mod` **: define a module
+* **`move` **: make a closure take ownership of all its captures
+* **`mut` **: denote mutability in references, raw pointers, or pattern bindings
+* **`pub` **: denote public visibility in struct fields, `impl` blocks, or
+modules
+* **`ref` **: bind by reference
+* **`return` **: return from function
+* **`Self` **: a type alias for the type we are defining or implementing
+* **`self` **: method subject or current module
+* **`static` **: global variable or lifetime lasting the entire program
+execution
+* **`struct` **: define a structure
+* **`super` **: parent module of the current module
+* **`trait` **: define a trait
+* **`true` **: Boolean true literal
+* **`type` **: define a type alias or associated type
+* **`union` **: define a union; is a keyword only when used in a union
+declaration
+* **`unsafe` **: denote unsafe code, functions, traits, or implementations
+* **`use` **: bring symbols into scope
+* **`where` **: denote clauses that constrain a type
+* **`while` **: loop conditionally based on the result of an expression
+
+## Keywords Reserved for Future Use
+
+The following keywords do not yet have any functionality but are reserved by
+Rust for potential future use:
+
+* `abstract`
+* `become`
+* `box`
+* `do`
+* `final`
+* `macro`
+* `override`
+* `priv`
+* `try`
+* `typeof`
+* `unsized`
+* `virtual`
+* `yield`
+
+## Raw Identifiers
+
+*Raw identifiers* are the syntax that lets you use keywords where they wouldn’t
+normally be allowed. You use a raw identifier by prefixing a keyword with `r#`.
+
+For example, `match` is a keyword. If you try to compile the following function
+that uses `match` as its name:
+
+Filename: src/main.rs
+
+```
+fn match(needle: &str, haystack: &str) -> bool {
+ haystack.contains(needle)
+}
+```
+
+you’ll get this error:
+
+```
+error: expected identifier, found keyword `match`
+ --> src/main.rs:4:4
+ |
+4 | fn match(needle: &str, haystack: &str) -> bool {
+ | ^^^^^ expected identifier, found keyword
+```
+
+The error shows that you can’t use the keyword `match` as the function
+identifier. To use `match` as a function name, you need to use the raw
+identifier syntax, like this:
+
+Filename: src/main.rs
+
+```
+fn r#match(needle: &str, haystack: &str) -> bool {
+ haystack.contains(needle)
+}
+
+fn main() {
+ assert!(r#match("foo", "foobar"));
+}
+```
+
+This code will compile without any errors. Note the `r#` prefix on the function
+name in its definition as well as where the function is called in `main`.
+
+Raw identifiers allow you to use any word you choose as an identifier, even if
+that word happens to be a reserved keyword. This gives us more freedom to
+choose identifier names, as well as lets us integrate with programs written in
+a language where these words aren’t keywords. In addition, raw identifiers
+allow you to use libraries written in a different Rust edition than your crate
+uses. For example, `try` isn’t a keyword in the 2015 edition but is in the 2018
+and 2021 editions. If you depend on a library that is written using the 2015
+edition and has a `try` function, you’ll need to use the raw identifier syntax,
+`r#try` in this case, to call that function from your 2021 edition code. See
+Appendix E for more information on editions.
+
diff --git a/src/doc/book/nostarch/appendix_b.md b/src/doc/book/nostarch/appendix_b.md
new file mode 100644
index 000000000..236608b6d
--- /dev/null
+++ b/src/doc/book/nostarch/appendix_b.md
@@ -0,0 +1,241 @@
+<!-- DO NOT EDIT THIS FILE.
+
+This file is periodically generated from the content in the `/src/`
+directory, so all fixes need to be made in `/src/`.
+-->
+
+[TOC]
+
+## Appendix B: Operators and Symbols
+
+This appendix contains a glossary of Rust’s syntax, including operators and
+other symbols that appear by themselves or in the context of paths, generics,
+trait bounds, macros, attributes, comments, tuples, and brackets.
+
+## Operators
+
+Table B-1 contains the operators in Rust, an example of how the operator would
+appear in context, a short explanation, and whether that operator is
+overloadable. If an operator is overloadable, the relevant trait to use to
+overload that operator is listed.
+
+Table B-1: Operators
+
+| Operator | Example | Explanation | Overloadable? |
+|---|---|---|---|
+| `!` | `ident!(...)`, `ident!{...}`, `ident![...]` | Macro expansion | |
+| `!` | `!expr` | Bitwise or logical complement | `Not` |
+| `!=` | `expr != expr` | Nonequality comparison | `PartialEq` |
+| `%` | `expr % expr` | Arithmetic remainder | `Rem` |
+| `%=` | `var %= expr` | Arithmetic remainder and assignment | `RemAssign` |
+| `&` | `&expr`, `&mut expr` | Borrow | |
+| `&` | `&type`, `&mut type`, `&'a type`, `&'a mut type` | Borrowed pointer
+type | |
+| `&` | `expr & expr` | Bitwise AND | `BitAnd` |
+| `&=` | `var &= expr` | Bitwise AND and assignment | `BitAndAssign` |
+| `&&` | `expr && expr` | Short-circuiting logical AND | |
+| `*` | `expr * expr` | Arithmetic multiplication | `Mul` |
+| `*=` | `var *= expr` | Arithmetic multiplication and assignment | `MulAssign`
+|
+| `*` | `*expr` | Dereference | `Deref` |
+| `*` | `*const type`, `*mut type` | Raw pointer | |
+| `+` | `trait + trait`, `'a + trait` | Compound type constraint | |
+| `+` | `expr + expr` | Arithmetic addition | `Add` |
+| `+=` | `var += expr` | Arithmetic addition and assignment | `AddAssign` |
+| `,` | `expr, expr` | Argument and element separator | |
+| `-` | `- expr` | Arithmetic negation | `Neg` |
+| `-` | `expr - expr` | Arithmetic subtraction | `Sub` |
+| `-=` | `var -= expr` | Arithmetic subtraction and assignment | `SubAssign` |
+| `->` | `fn(...) -> type`, `|…| -> type` | Function and closure return type |
+|
+| `. | `expr.ident` | Member access | |
+| `..` | `..`, `expr..`, `..expr`, `expr..expr` | Right-exclusive range literal
+| `PartialOrd` |
+| `..=` | `..=expr`, `expr..=expr` | Right-inclusive range literal |
+`PartialOrd` |
+| `..` | `..expr` | Struct literal update syntax | |
+| `..` | `variant(x, ..)`, `struct_type { x, .. }` | “And the rest†pattern
+binding | |
+| `...` | `expr...expr` | (Deprecated, use `..=` instead) In a pattern:
+inclusive range pattern | |
+| `/` | `expr / expr` | Arithmetic division | `Div` |
+| `/=` | `var /= expr` | Arithmetic division and assignment | `DivAssign` |
+| `: | `pat: type`, `ident: type` | Constraints | |
+| `:` | `ident: expr` | Struct field initializer | |
+| `:` | `'a: loop {...}` | Loop label | |
+| `;` | `expr;` | Statement and item terminator | |
+| `;` | `[...; len]` | Part of fixed-size array syntax | |
+| `<<` | `expr << expr` | Left-shift | `Shl` |
+| `<<=` | `var <<= expr` | Left-shift and assignment | `ShlAssign` |
+| `<` | `expr < expr` | Less than comparison | `PartialOrd` |
+| `<=` | `expr <= expr` | Less than or equal to comparison | `PartialOrd` |
+| `=` | `var = expr`, `ident = type` | Assignment/equivalence | |
+| `==` | `expr == expr` | Equality comparison | `PartialEq` |
+| `=>` | `pat => expr` | Part of match arm syntax | |
+| `>` | `expr > expr` | Greater than comparison | `PartialOrd` |
+| `>=` | `expr >= expr` | Greater than or equal to comparison | `PartialOrd` |
+| `>>` | `expr >> expr` | Right-shift | `Shr` |
+| `>>=` | `var >>= expr` | Right-shift and assignment | `ShrAssign` |
+| `@` | `ident @ pat` | Pattern binding | |
+| `^` | `expr ^ expr` | Bitwise exclusive OR | `BitXor` |
+| `^=` | `var ^= expr` | Bitwise exclusive OR and assignment | `BitXorAssign` |
+| `|` | `pat | pat` | Pattern alternatives | |
+| `|` | `expr | expr` | Bitwise OR | `BitOr` |
+| `|=` | `var |= expr` | Bitwise OR and assignment | `BitOrAssign` |
+| `||` | `expr || expr` | Short-circuiting logical OR | |
+| `?` | `expr?` | Error propagation | |
+
+## Non-operator Symbols
+
+The following tables contain all symbols that don’t function as operators; that
+is, they don’t behave like a function or method call.
+
+Table B-2 shows symbols that appear on their own and are valid in a variety of
+locations.
+
+Table B-2: Stand-Alone Syntax
+
+| Symbol | Explanation |
+|---|---|
+| `'ident` | Named lifetime or loop label |
+| `...u8`, `...i32`, `...f64`, `...usize`, and so on | Numeric literal of
+specific type |
+| `"..."` | String literal |
+| `r"..."`, `r#"..."#`, `r##"..."##`, and so on | Raw string literal; escape
+characters not processed |
+| `b"..."` | Byte string literal; constructs an array of bytes instead of a
+string |
+| `br"..."`, `br#"..."#`, `br##"..."##`, and so on | Raw byte string literal;
+combination of raw and byte string literal |
+| `'...'` | Character literal |
+| `b'...'` | ASCII byte literal |
+| `|…| expr` | Closure |
+| `!` | Always-empty bottom type for diverging functions |
+| `_` | “Ignored†pattern binding; also used to make integer literals readable |
+
+Table B-3 shows symbols that appear in the context of a path through the module
+hierarchy to an item.
+
+Table B-3: Path-Related Syntax
+
+| Symbol | Explanation |
+|---|---|
+| `ident::ident` | Namespace path |
+| `::path` | Path relative to the crate root (that is, an explicitly absolute
+path) |
+| `self::path` | Path relative to the current module (that is, an explicitly
+relative path) |
+| `super::path` | Path relative to the parent of the current module |
+| `type::ident`, `<type as trait>::ident` | Associated constants, functions,
+and types |
+| `<type>::...` | Associated item for a type that cannot be directly named (for
+example, `<&T>::...`, `<[T]>::...`, and so on) |
+| `trait::method(...)` | Disambiguating a method call by naming the trait that
+defines it |
+| `type::method(...)` | Disambiguating a method call by naming the type for
+which it’s defined |
+| `<type as trait>::method(...)` | Disambiguating a method call by naming the
+trait and type |
+
+Table B-4 shows symbols that appear in the context of using generic type
+parameters.
+
+Table B-4: Generics
+
+| Symbol | Explanation |
+|---|---|
+| `path<...>` | Specifies parameters to a generic type in a type (for example,
+`Vec<u8>`) |
+| `path::<...>, method::<...>` | Specifies parameters to a generic type,
+function, or method in an expression; often referred to as turbofish (for
+example, `"42".parse::<i32>()`) |
+| `fn ident<...> ...` | Define generic function |
+| `struct ident<...> ...` | Define generic structure |
+| `enum ident<...> ...` | Define generic enumeration |
+| `impl<...> ...` | Define generic implementation |
+| `for<...> type` | Higher-ranked lifetime bounds |
+| `type<ident=type>` | A generic type where one or more associated types have
+specific assignments (for example, `Iterator<Item=T>`) |
+
+Table B-5 shows symbols that appear in the context of constraining generic type
+parameters with trait bounds.
+
+Table B-5: Trait Bound Constraints
+
+| Symbol | Explanation |
+|---|---|
+| T: U` | Generic parameter `T` constrained to types that implement `U` |
+| `T: 'a` | Generic type `T` must outlive lifetime `'a` (meaning the type
+cannot transitively contain any references with lifetimes shorter than `'a`) |
+| `T: 'static` | Generic type `T` contains no borrowed references other than
+`'static` ones |
+| `'b: 'a` | Generic lifetime `'b` must outlive lifetime `'a` |
+| `T: ?Sized` | Allow generic type parameter to be a dynamically sized type |
+| `'a + trait`, `trait + trait` | Compound type constraint |
+
+Table B-6 shows symbols that appear in the context of calling or defining
+macros and specifying attributes on an item.
+
+Table B-6: Macros and Attributes
+
+| Symbol | Explanation |
+|---|---|
+| `#[meta]` | Outer attribute |
+| `#![meta]` | Inner attribute |
+| `$ident` | Macro substitution |
+| `$ident:kind` | Macro capture |
+| `$(…)…` | Macro repetition |
+| `ident!(...)`, `ident!{...}`, `ident![...]` | Macro invocation |
+
+Table B-7 shows symbols that create comments.
+
+Table B-7: Comments
+
+| Symbol | Explanation |
+|---|---|
+| `//` | Line comment |
+| `//!` | Inner line doc comment |
+| `///` | Outer line doc comment |
+| `/*...*/` | Block comment |
+| `/*!...*/` | Inner block doc comment |
+| `/**...*/` | Outer block doc comment |
+
+Table B-8 shows symbols that appear in the context of using tuples.
+
+Table B-8: Tuples
+
+| Symbol | Explanation |
+|---|---|
+| `()` | Empty tuple (aka unit), both literal and type |
+| `(expr)` | Parenthesized expression |
+| `(expr,)` | Single-element tuple expression |
+| `(type,)` | Single-element tuple type |
+| `(expr, ...)` | Tuple expression |
+| `(type, ...)` | Tuple type |
+| `expr(expr, ...)` | Function call expression; also used to initialize tuple
+`struct`s and tuple `enum` variants |
+| `expr.0`, `expr.1`, and so on | Tuple indexing |
+
+Table B-9 shows the contexts in which curly brackets are used.
+
+Table B-9: Curly Brackets
+
+| Context | Explanation |
+|---|---|
+| `{...}` | Block expression |
+| `Type {...}` | `struct` literal |
+
+Table B-10 shows the contexts in which square brackets are used.
+
+Table B-10: Square Brackets
+
+| Context | Explanation |
+|---|---|
+| `[...]` | Array literal |
+| `[expr; len]` | Array literal containing `len` copies of `expr` |
+| `[type; len]` | Array type containing `len` instances of `type` |
+| `expr[expr]` | Collection indexing; overloadable (`Index`, `IndexMut`) |
+| `expr[..]`, `expr[a..]`, `expr[..b]`, `expr[a..b]` | Collection indexing
+pretending to be collection slicing, using `Range`, `RangeFrom`, `RangeTo`, or
+`RangeFull` as the “index†|
+
diff --git a/src/doc/book/nostarch/appendix_c.md b/src/doc/book/nostarch/appendix_c.md
new file mode 100644
index 000000000..53131eb5f
--- /dev/null
+++ b/src/doc/book/nostarch/appendix_c.md
@@ -0,0 +1,184 @@
+<!-- DO NOT EDIT THIS FILE.
+
+This file is periodically generated from the content in the `/src/`
+directory, so all fixes need to be made in `/src/`.
+-->
+
+[TOC]
+
+## Appendix C: Derivable Traits
+
+In various places in the book, we’ve discussed the `derive` attribute, which
+you can apply to a struct or enum definition. The `derive` attribute generates
+code that will implement a trait with its own default implementation on the
+type you’ve annotated with the `derive` syntax.
+
+In this appendix, we provide a reference of all the traits in the standard
+library that you can use with `derive`. Each section covers:
+
+* What operators and methods deriving this trait will enable
+* What the implementation of the trait provided by `derive` does
+* What implementing the trait signifies about the type
+* The conditions in which you’re allowed or not allowed to implement the trait
+* Examples of operations that require the trait
+
+If you want different behavior from that provided by the `derive` attribute,
+consult the standard library documentation for each trait for details on how to
+manually implement them.
+
+The traits listed here are the only ones defined by the standard library that
+can be implemented on your types using `derive`. Other traits defined in the
+standard library don’t have sensible default behavior, so it’s up to you to
+implement them in the way that makes sense for what you’re trying to accomplish.
+
+An example of a trait that can’t be derived is `Display`, which handles
+formatting for end users. You should always consider the appropriate way to
+display a type to an end user. What parts of the type should an end user be
+allowed to see? What parts would they find relevant? What format of the data
+would be most relevant to them? The Rust compiler doesn’t have this insight, so
+it can’t provide appropriate default behavior for you.
+
+The list of derivable traits provided in this appendix is not comprehensive:
+libraries can implement `derive` for their own traits, making the list of
+traits you can use `derive` with truly open ended. Implementing `derive`
+involves using a procedural macro, which is covered in “Macros†on page XX.
+
+## Debug for Programmer Output
+
+The `Debug` trait enables debug formatting in format strings, which you
+indicate by adding `:?` within `{}` placeholders.
+
+The `Debug` trait allows you to print instances of a type for debugging
+purposes, so you and other programmers using your type can inspect an instance
+at a particular point in a program’s execution.
+
+The `Debug` trait is required, for example, in the use of the `assert_eq!`
+macro. This macro prints the values of instances given as arguments if the
+equality assertion fails so programmers can see why the two instances weren’t
+equal.
+
+## PartialEq and Eq for Equality Comparisons
+
+The `PartialEq` trait allows you to compare instances of a type to check for
+equality and enables use of the `==` and `!=` operators.
+
+Deriving `PartialEq` implements the `eq` method. When `PartialEq` is derived on
+structs, two instances are equal only if *all* fields are equal, and the
+instances are not equal if any fields are not equal. When derived on enums,
+each variant is equal to itself and not equal to the other variants.
+
+The `PartialEq` trait is required, for example, with the use of the
+`assert_eq!` macro, which needs to be able to compare two instances of a type
+for equality.
+
+The `Eq` trait has no methods. Its purpose is to signal that for every value of
+the annotated type, the value is equal to itself. The `Eq` trait can only be
+applied to types that also implement `PartialEq`, although not all types that
+implement `PartialEq` can implement `Eq`. One example of this is floating-point
+number types: the implementation of floating-point numbers states that two
+instances of the not-a-number (`NaN`) value are not equal to each other.
+
+An example of when `Eq` is required is for keys in a `HashMap<K, V>` so that
+the `HashMap<K, V>` can tell whether two keys are the same.
+
+## PartialOrd and Ord for Ordering Comparisons
+
+The `PartialOrd` trait allows you to compare instances of a type for sorting
+purposes. A type that implements `PartialOrd` can be used with the `<`, `>`,
+`<=`, and `>=` operators. You can only apply the `PartialOrd` trait to types
+that also implement `PartialEq`.
+
+Deriving `PartialOrd` implements the `partial_cmp` method, which returns an
+`Option<Ordering>` that will be `None` when the values given don’t produce an
+ordering. An example of a value that doesn’t produce an ordering, even though
+most values of that type can be compared, is the not-a-number (`NaN`) floating
+point value. Calling `partial_cmp` with any floating-point number and the `NaN`
+floating-point value will return `None`.
+
+When derived on structs, `PartialOrd` compares two instances by comparing the
+value in each field in the order in which the fields appear in the struct
+definition. When derived on enums, variants of the enum declared earlier in the
+enum definition are considered less than the variants listed later.
+
+The `PartialOrd` trait is required, for example, for the `gen_range` method
+from the `rand` crate that generates a random value in the range specified by a
+range expression.
+
+The `Ord` trait allows you to know that for any two values of the annotated
+type, a valid ordering will exist. The `Ord` trait implements the `cmp` method,
+which returns an `Ordering` rather than an `Option<Ordering>` because a valid
+ordering will always be possible. You can only apply the `Ord` trait to types
+that also implement `PartialOrd` and `Eq` (and `Eq` requires `PartialEq`). When
+derived on structs and enums, `cmp` behaves the same way as the derived
+implementation for `partial_cmp` does with `PartialOrd`.
+
+An example of when `Ord` is required is when storing values in a `BTreeSet<T>`,
+a data structure that stores data based on the sort order of the values.
+
+## Clone and Copy for Duplicating Values
+
+The `Clone` trait allows you to explicitly create a deep copy of a value, and
+the duplication process might involve running arbitrary code and copying heap
+data. See “Variables and Data Interacting with Clone†on page XX for more
+information on `Clone`.
+
+Deriving `Clone` implements the `clone` method, which when implemented for the
+whole type, calls `clone` on each of the parts of the type. This means all the
+fields or values in the type must also implement `Clone` to derive `Clone`.
+
+An example of when `Clone` is required is when calling the `to_vec` method on a
+slice. The slice doesn’t own the type instances it contains, but the vector
+returned from `to_vec` will need to own its instances, so `to_vec` calls
+`clone` on each item. Thus the type stored in the slice must implement `Clone`.
+
+The `Copy` trait allows you to duplicate a value by only copying bits stored on
+the stack; no arbitrary code is necessary. See “Stack-Only Data: Copy†on page
+XX for more information on `Copy`.
+
+The `Copy` trait doesn’t define any methods to prevent programmers from
+overloading those methods and violating the assumption that no arbitrary code
+is being run. That way, all programmers can assume that copying a value will be
+very fast.
+
+You can derive `Copy` on any type whose parts all implement `Copy`. A type that
+implements `Copy` must also implement `Clone` because a type that implements
+`Copy` has a trivial implementation of `Clone` that performs the same task as
+`Copy`.
+
+The `Copy` trait is rarely required; types that implement `Copy` have
+optimizations available, meaning you don’t have to call `clone`, which makes
+the code more concise.
+
+Everything possible with `Copy` you can also accomplish with `Clone`, but the
+code might be slower or have to use `clone` in places.
+
+## Hash for Mapping a Value to a Value of Fixed Size
+
+The `Hash` trait allows you to take an instance of a type of arbitrary size and
+map that instance to a value of fixed size using a hash function. Deriving
+`Hash` implements the `hash` method. The derived implementation of the `hash`
+method combines the result of calling `hash` on each of the parts of the type,
+meaning all fields or values must also implement `Hash` to derive `Hash`.
+
+An example of when `Hash` is required is in storing keys in a `HashMap<K, V>`
+to store data efficiently.
+
+## Default for Default Values
+
+The `Default` trait allows you to create a default value for a type. Deriving
+`Default` implements the `default` function. The derived implementation of the
+`default` function calls the `default` function on each part of the type,
+meaning all fields or values in the type must also implement `Default` to
+derive `Default`.
+
+The `Default::default` function is commonly used in combination with the struct
+update syntax discussed in “Creating Instances from Other Instances with Struct
+Update Syntax†on page XX. You can customize a few fields of a struct and then
+set and use a default value for the rest of the fields by using
+`..Default::default()`.
+
+The `Default` trait is required when you use the method `unwrap_or_default` on
+`Option<T>` instances, for example. If the `Option<T>` is `None`, the method
+`unwrap_or_default` will return the result of `Default::default` for the type
+`T` stored in the `Option<T>`.
+
diff --git a/src/doc/book/nostarch/appendix_d.md b/src/doc/book/nostarch/appendix_d.md
new file mode 100644
index 000000000..96b73e954
--- /dev/null
+++ b/src/doc/book/nostarch/appendix_d.md
@@ -0,0 +1,175 @@
+<!-- DO NOT EDIT THIS FILE.
+
+This file is periodically generated from the content in the `/src/`
+directory, so all fixes need to be made in `/src/`.
+-->
+
+[TOC]
+
+## Appendix D: Useful Development Tools
+
+In this appendix, we talk about some useful development tools that the Rust
+project provides. We’ll look at automatic formatting, quick ways to apply
+warning fixes, a linter, and integrating with IDEs.
+
+## Automatic Formatting with rustfmt
+
+The `rustfmt` tool reformats your code according to the community code style.
+Many collaborative projects use `rustfmt` to prevent arguments about which
+style to use when writing Rust: everyone formats their code using the tool.
+
+Rust installations include `rustfmt` by default, so you should already have the
+programs `rustfmt` and `cargo-fmt` on your system. These two commands are
+analagous to `rustc` and `cargo` in that `rustfmt` allows finer-grained control
+and `cargo-fmt` understands conventions of a project that uses Cargo. To format
+any Cargo project, enter the following:
+
+```
+$ cargo fmt
+```
+
+Running this command reformats all the Rust code in the current crate. This
+should only change the code style, not the code semantics. For more information
+on `rustfmt`, see its documentation at *https://github.com/rust-lang/rustfmt*.
+
+## Fix Your Code with rustfix
+
+The `rustfix` tool is included with Rust installations and can automatically
+fix compiler warnings that have a clear way to correct the problem that’s
+likely what you want. You’ve probably seen compiler warnings before. For
+example, consider this code:
+
+Filename: src/main.rs
+
+```
+fn do_something() {}
+
+fn main() {
+ for i in 0..100 {
+ do_something();
+ }
+}
+```
+
+Here, we’re calling the `do_something` function 100 times, but we never use the
+variable `i` in the body of the `for` loop. Rust warns us about that:
+
+```
+$ cargo build
+ Compiling myprogram v0.1.0 (file:///projects/myprogram)
+warning: unused variable: `i`
+ --> src/main.rs:4:9
+ |
+4 | for i in 0..100 {
+ | ^ help: consider using `_i` instead
+ |
+ = note: #[warn(unused_variables)] on by default
+
+ Finished dev [unoptimized + debuginfo] target(s) in 0.50s
+```
+
+The warning suggests that we use `_i` as a name instead: the underscore
+indicates that we intend for this variable to be unused. We can automatically
+apply that suggestion using the `rustfix` tool by running the command `cargo
+fix`:
+
+```
+$ cargo fix
+ Checking myprogram v0.1.0 (file:///projects/myprogram)
+ Fixing src/main.rs (1 fix)
+ Finished dev [unoptimized + debuginfo] target(s) in 0.59s
+```
+
+When we look at *src/main.rs* again, we’ll see that `cargo fix` has changed the
+code:
+
+Filename: src/main.rs
+
+```
+fn do_something() {}
+
+fn main() {
+ for _i in 0..100 {
+ do_something();
+ }
+}
+```
+
+The `for` loop variable is now named `_i`, and the warning no longer appears.
+
+You can also use the `cargo fix` command to transition your code between
+different Rust editions. Editions are covered in Appendix E.
+
+## More Lints with Clippy
+
+The Clippy tool is a collection of lints to analyze your code so you can catch
+common mistakes and improve your Rust code. Clippy is included with standard
+Rust installations.
+
+To run Clippy’s lints on any Cargo project, enter the following:
+
+```
+$ cargo clippy
+```
+
+For example, say you write a program that uses an approximation of a
+mathematical constant, such as pi, as this program does:
+
+Filename: src/main.rs
+
+```
+fn main() {
+ let x = 3.1415;
+ let r = 8.0;
+ println!("the area of the circle is {}", x * r * r);
+}
+```
+
+Running `cargo clippy` on this project results in this error:
+
+```
+error: approximate value of `f{32, 64}::consts::PI` found
+ --> src/main.rs:2:13
+ |
+2 | let x = 3.1415;
+ | ^^^^^^
+ |
+ = note: `#[deny(clippy::approx_constant)]` on by default
+ = help: consider using the constant directly
+ = help: for further information visit https://rust-lang.github.io/rust-
+clippy/master/index.html#approx_constant
+```
+
+This error lets you know that Rust already has a more precise `PI` constant
+defined, and that your program would be more correct if you used the constant
+instead. You would then change your code to use the `PI` constant.
+
+The following code doesn’t result in any errors or warnings from Clippy:
+
+Filename: src/main.rs
+
+```
+fn main() {
+ let x = std::f64::consts::PI;
+ let r = 8.0;
+ println!("the area of the circle is {}", x * r * r);
+}
+```
+
+For more information on Clippy, see its documentation at
+*https://github.com/rust-lang/rust-clippy**.*
+
+## IDE Integration Using rust-analyzer
+
+To help with IDE integration, the Rust community recommends using
+`rust-analyzer`. This tool is a set of compiler-centric utilities that speak
+Language Server Protocol, which is a specification for IDEs and programming
+languages to communicate with each other. Different clients can use
+`rust-analyzer`, such as the Rust analyzer plug-in for Visual Studio Code at
+*https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer*.
+
+Visit the `rust-analyzer` project’s home page at
+*https://rust-analyzer.github.io* for installation instructions, then install
+the language server support in your particular IDE. Your IDE will gain
+capabilities such as autocompletion, jump to definition, and inline errors
+
diff --git a/src/doc/book/nostarch/appendix_e.md b/src/doc/book/nostarch/appendix_e.md
new file mode 100644
index 000000000..ddb12b782
--- /dev/null
+++ b/src/doc/book/nostarch/appendix_e.md
@@ -0,0 +1,66 @@
+<!-- DO NOT EDIT THIS FILE.
+
+This file is periodically generated from the content in the `/src/`
+directory, so all fixes need to be made in `/src/`.
+-->
+
+[TOC]
+
+## Appendix E: Editions
+
+In Chapter 1, you saw that `cargo new` adds a bit of metadata to your
+*Cargo.toml* file about an edition. This appendix talks about what that means!
+
+The Rust language and compiler have a six-week release cycle, meaning users get
+a constant stream of new features. Other programming languages release larger
+changes less often; Rust releases smaller updates more frequently. After a
+while, all of these tiny changes add up. But from release to release, it can be
+difficult to look back and say, “Wow, between Rust 1.10 and Rust 1.31, Rust has
+changed a lot!â€
+
+Every two or three years, the Rust team produces a new Rust *edition*. Each
+edition brings together the features that have landed into a clear package with
+fully updated documentation and tooling. New editions ship as part of the usual
+six-week release process.
+
+Editions serve different purposes for different people:
+
+* For active Rust users, a new edition brings together incremental changes into
+an easy-to-understand package.
+* For non-users, a new edition signals that some major advancements have
+landed, which might make Rust worth another look.
+* For those developing Rust, a new edition provides a rallying point for the
+project as a whole.
+
+At the time of this writing, three Rust editions are available: Rust 2015, Rust
+2018, and Rust 2021. This book is written using Rust 2021 edition idioms.
+
+The `edition` key in *Cargo.toml* indicates which edition the compiler should
+use for your code. If the key doesn’t exist, Rust uses `2015` as the edition
+value for backward compatibility reasons.
+
+Each project can opt in to an edition other than the default 2015 edition.
+Editions can contain incompatible changes, such as including a new keyword that
+conflicts with identifiers in code. However, unless you opt in to those
+changes, your code will continue to compile even as you upgrade the Rust
+compiler version you use.
+
+All Rust compiler versions support any edition that existed prior to that
+compiler’s release, and they can link crates of any supported editions
+together. Edition changes only affect the way the compiler initially parses
+code. Therefore, if you’re using Rust 2015 and one of your dependencies uses
+Rust 2018, your project will compile and be able to use that dependency. The
+opposite situation, where your project uses Rust 2018 and a dependency uses
+Rust 2015, works as well.
+
+To be clear: most features will be available on all editions. Developers using
+any Rust edition will continue to see improvements as new stable releases are
+made. However, in some cases, mainly when new keywords are added, some new
+features might only be available in later editions. You will need to switch
+editions if you want to take advantage of such features.
+
+For more details, *The* *Edition Guide* at
+*https://doc.rust-lang.org/stable/edition-guide* is a complete book about
+editions that enumerates the differences between editions and explains how to
+automatically upgrade your code to a new edition via `cargo fix`.
+
diff --git a/src/doc/book/nostarch/bio.md b/src/doc/book/nostarch/bio.md
index cbb2bd4bb..38b0508bc 100644
--- a/src/doc/book/nostarch/bio.md
+++ b/src/doc/book/nostarch/bio.md
@@ -1,5 +1,6 @@
# About the Authors
-<!--Insert Steve's bio here -->
-
-Carol Nichols is a member of the Rust Crates.io Team and a former member of the Rust Core Team. She’s a co-founder of Integer 32, LLC, the world’s first Rust-focused software consultancy. Nichols has also organized the Rust Belt Rust Conference. \ No newline at end of file
+Carol Nichols is a member of the Rust Crates.io Team and a former member of the
+Rust Core Team. She’s a co-founder of Integer 32, LLC, the world’s first
+Rust-focused software consultancy. Nichols has also organized the Rust Belt
+Rust Conference.
diff --git a/src/doc/book/nostarch/chapter01.md b/src/doc/book/nostarch/chapter01.md
index 87848b66f..3379b14f2 100644
--- a/src/doc/book/nostarch/chapter01.md
+++ b/src/doc/book/nostarch/chapter01.md
@@ -21,28 +21,28 @@ The first step is to install Rust. We’ll download Rust through `rustup`, a
command line tool for managing Rust versions and associated tools. You’ll need
an internet connection for the download.
-> Note: If you prefer not to use `rustup` for some reason, please see the
-> Other Rust Installation Methods page at
-> *https://forge.rust-lang.org/infra/other-installation-methods.html* for more
-> options.
+> Note: If you prefer not to use `rustup` for some reason, please see the Other
+Rust Installation Methods page at
+*https://forge.rust-lang.org/infra/other-installation-methods.html* for more
+options.
The following steps install the latest stable version of the Rust compiler.
Rust’s stability guarantees ensure that all the examples in the book that
compile will continue to compile with newer Rust versions. The output might
-differ slightly between versions, because Rust often improves error messages
-and warnings. In other words, any newer, stable version of Rust you install
-using these steps should work as expected with the content of this book.
+differ slightly between versions because Rust often improves error messages and
+warnings. In other words, any newer, stable version of Rust you install using
+these steps should work as expected with the content of this book.
> ### Command Line Notation
>
> In this chapter and throughout the book, we’ll show some commands used in the
-> terminal. Lines that you should enter in a terminal all start with `$`. You
-> don’t need to type in the `$` character; it’s the command line prompt shown
-> to indicate the start of each command. Lines that don’t start with `$`
-> typically show the output of the previous command. Additionally,
-> PowerShell-specific examples will use `>` rather than `$`.
+terminal. Lines that you should enter in a terminal all start with `$`. You
+don’t need to type the `$` character; it’s the command line prompt shown to
+indicate the start of each command. Lines that don’t start with `$` typically
+show the output of the previous command. Additionally, PowerShell-specific
+examples will use `>` rather than `$`.
-### Installing `rustup` on Linux or macOS
+### Installing rustup on Linux or macOS
If you’re using Linux or macOS, open a terminal and enter the following command:
@@ -74,7 +74,7 @@ Linux users should generally install GCC or Clang, according to their
distribution’s documentation. For example, if you use Ubuntu, you can install
the `build-essential` package.
-### Installing `rustup` on Windows
+### Installing rustup on Windows
On Windows, go to *https://www.rust-lang.org/tools/install* and follow the
instructions for installing Rust. At some point in the installation, you’ll
@@ -82,18 +82,13 @@ receive a message explaining that you’ll also need the MSVC build tools for
Visual Studio 2013 or later.
To acquire the build tools, you’ll need to install Visual Studio 2022 from
-*https://visualstudio.microsoft.com/downloads/*. When asked which workloads to
+*https://visualstudio.microsoft.com/downloads*. When asked which workloads to
install, include:
-- “Desktop Development with C++â€
-- The Windows 10 or 11 SDK
-- The English language pack component, along with any other language pack of
- your choosing
-
-<!-- Liz: We do want to recommend the English language pack along with whatever
-other languages the reader speaks-- otherwise, sometimes error messages are
-printed strangely
-https://github.com/rust-lang/rust/issues/35785#issuecomment-735051657 /Carol -->
+* “Desktop Development with C++â€
+* The Windows 10 or 11 SDK
+* The English language pack component, along with any other language pack of
+your choosing
The rest of this book uses commands that work in both *cmd.exe* and PowerShell.
If there are specific differences, we’ll explain which to use.
@@ -108,7 +103,7 @@ $ rustc --version
```
You should see the version number, commit hash, and commit date for the latest
-stable version that has been released in the following format:
+stable version that has been released, in the following format:
```
rustc x.y.z (abcabcabc yyyy-mm-dd)
@@ -133,25 +128,18 @@ In PowerShell, use:
In Linux and macOS, use:
```
-echo $PATH
+$ echo $PATH
```
If that’s all correct and Rust still isn’t working, there are a number of
-places you can get help. The easiest is the #beginners channel on the official
-Rust Discord at *https://discord.gg/rust-lang*. There, you can chat with other
-Rustaceans (a silly nickname we call ourselves) who can help you out. Other
-great resources include the Users forum at *https://users.rust-lang.org/* and
-Stack Overflow at *https://stackoverflow.com/questions/tagged/rust*.
-
-<!-- `echo %PATH%` will work for cmd. PowerShell would use `echo $env:Path`.
-Bash would use `echo $PATH` /JT -->
-<!-- I've added these instructions above /Carol -->
+places you can get help. Find out how to get in touch with other Rustaceans (a
+silly nickname we call ourselves) on the community page at
+*https://www.rust-lang.org/community*.
### Updating and Uninstalling
-Once Rust is installed via `rustup`, when a new version of Rust is released,
-updating to the latest version is easy. From your shell, run the following
-update script:
+Once Rust is installed via `rustup`, updating to a newly released version is
+easy. From your shell, run the following update script:
```
$ rustup update
@@ -166,9 +154,9 @@ $ rustup self uninstall
### Local Documentation
-The installation of Rust also includes a local copy of the documentation, so
-you can read it offline. Run `rustup doc` to open the local documentation in
-your browser.
+The installation of Rust also includes a local copy of the documentation so
+that you can read it offline. Run `rustup doc` to open the local documentation
+in your browser.
Any time a type or function is provided by the standard library and you’re not
sure what it does or how to use it, use the application programming interface
@@ -176,17 +164,17 @@ sure what it does or how to use it, use the application programming interface
## Hello, World!
-Now that you’ve installed Rust, let’s write your first Rust program. It’s
-traditional when learning a new language to write a little program that prints
-the text `Hello, world!` to the screen, so we’ll do the same here!
+Now that you’ve installed Rust, it’s time to write your first Rust program.
+It’s traditional when learning a new language to write a little program that
+prints the text `Hello, world!` to the screen, so we’ll do the same here!
> Note: This book assumes basic familiarity with the command line. Rust makes
-> no specific demands about your editing or tooling or where your code lives, so
-> if you prefer to use an integrated development environment (IDE) instead of
-> the command line, feel free to use your favorite IDE. Many IDEs now have some
-> degree of Rust support; check the IDE’s documentation for details. The Rust
-> team has been focusing on enabling great IDE support via `rust-analyzer`. See
-> Appendix D for more details!
+no specific demands about your editing or tooling or where your code lives, so
+if you prefer to use an integrated development environment (IDE) instead of the
+command line, feel free to use your favorite IDE. Many IDEs now have some
+degree of Rust support; check the IDE’s documentation for details. The Rust
+team has been focusing on enabling great IDE support via `rust-analyzer`. See
+Appendix D for more details.
### Creating a Project Directory
@@ -254,8 +242,8 @@ Hello, world!
```
Regardless of your operating system, the string `Hello, world!` should print to
-the terminal. If you don’t see this output, refer back to the “Troubleshootingâ€
-part of the Installation section for ways to get help.
+the terminal. If you don’t see this output, refer back to “Troubleshooting†on
+page XX for ways to get help.
If `Hello, world!` did print, congratulations! You’ve officially written a Rust
program. That makes you a Rust programmer—welcome!
@@ -281,10 +269,10 @@ function bodies. It’s good style to place the opening curly bracket on the sam
line as the function declaration, adding one space in between.
> Note: If you want to stick to a standard style across Rust projects, you can
-> use an automatic formatter tool called `rustfmt` to format your code in a
-> particular style (more on `rustfmt` in Appendix D). The Rust team has
-> included this tool with the standard Rust distribution, like `rustc`, so it
-> should already be installed on your computer!
+use an automatic formatter tool called `rustfmt` to format your code in a
+particular style (more on `rustfmt` in Appendix D). The Rust team has included
+this tool with the standard Rust distribution, as `rustc` is, so it should
+already be installed on your computer!
The body of the `main` function holds the following code:
@@ -300,7 +288,7 @@ First, Rust style is to indent with four spaces, not a tab.
Second, `println!` calls a Rust macro. If it had called a function instead, it
would be entered as `println` (without the `!`). We’ll discuss Rust macros in
more detail in Chapter 19. For now, you just need to know that using a `!`
-means that you’re calling a macro instead of a normal function, and that macros
+means that you’re calling a macro instead of a normal function and that macros
don’t always follow the same rules as functions.
Third, you see the `"Hello, world!"` string. We pass this string as an argument
@@ -327,16 +315,16 @@ If you have a C or C++ background, you’ll notice that this is similar to `gcc`
or `clang`. After compiling successfully, Rust outputs a binary executable.
On Linux, macOS, and PowerShell on Windows, you can see the executable by
-entering the `ls` command in your shell. On Linux and macOS, you’ll see two
-files. With PowerShell on Windows, you’ll see the same three files that you
-would see using CMD.
+entering the `ls` command in your shell:
```
$ ls
main main.rs
```
-With CMD on Windows, you would enter the following:
+On Linux and macOS, you’ll see two files. With PowerShell on Windows, you’ll
+see the same three files that you would see using CMD. With CMD on Windows, you
+would enter the following:
```
> dir /B %= the /B option says to only show the file names =%
@@ -387,9 +375,9 @@ using Cargo, adding dependencies will be much easier to do.
Because the vast majority of Rust projects use Cargo, the rest of this book
assumes that you’re using Cargo too. Cargo comes installed with Rust if you
-used the official installers discussed in the “Installation†section. If you
+used the official installers discussed in “Installation†on page XX. If you
installed Rust through some other means, check whether Cargo is installed by
-entering the following into your terminal:
+entering the following in your terminal:
```
$ cargo --version
@@ -402,9 +390,9 @@ determine how to install Cargo separately.
### Creating a Project with Cargo
Let’s create a new project using Cargo and look at how it differs from our
-original “Hello, world!†project. Navigate back to your *projects* directory (or
-wherever you decided to store your code). Then, on any operating system, run
-the following:
+original “Hello, world!†project. Navigate back to your *projects* directory
+(or wherever you decided to store your code). Then, on any operating system,
+run the following:
```
$ cargo new hello_cargo
@@ -424,8 +412,8 @@ Git files won’t be generated if you run `cargo new` within an existing Git
repository; you can override this behavior by using `cargo new --vcs=git`.
> Note: Git is a common version control system. You can change `cargo new` to
-> use a different version control system or no version control system by using
-> the `--vcs` flag. Run `cargo new --help` to see the available options.
+use a different version control system or no version control system by using
+the `--vcs` flag. Run `cargo new --help` to see the available options.
Open *Cargo.toml* in your text editor of choice. It should look similar to the
code in Listing 1-2.
@@ -471,7 +459,7 @@ fn main() {
Cargo has generated a “Hello, world!†program for you, just like the one we
wrote in Listing 1-1! So far, the differences between our project and the
-project Cargo generated are that Cargo placed the code in the *src* directory,
+project Cargo generated are that Cargo placed the code in the *src* directory
and we have a *Cargo.toml* configuration file in the top directory.
Cargo expects your source files to live inside the *src* directory. The
@@ -499,21 +487,6 @@ $ cargo build
This command creates an executable file in *target/debug/hello_cargo* (or
*target\debug\hello_cargo.exe* on Windows) rather than in your current
-<!-- why does it put it in a debug folder? Interesting to know, because it seems
-laborious to have to enter the whole path to run the executable /LC -->
-<!-- Because `build` uses debug settings by default, and the compiler tries to
-make it clear that this isn't a release build by storing it in the `debug`
-path. Most people use `cargo run` instead, which is what we show in a few
-paragraphs. We talk about building for release mode in the next section; do you
-think it needs to be mentioned here too? I think it would be somewhat
-distracting and repetitive to get into that right here... /Carol -->
-<!-- JT, what do you think? I don't want to get into the weeds... but will the
-reader be wondering? /LC -->
-<!-- I think we could quickly mention that because the default build is a debug
-build, cargo will put the binary in the debug directory. If we created a release
-build, it would put it in the release directory. Looks like we do mention this
-later /JT -->
-<!-- I've added a sentence here along the lines of what JT suggested /Carol -->
directory. Because the default build is a debug build, Cargo puts the binary in
a directory named *debug*. You can run the executable with this command:
@@ -531,7 +504,7 @@ manages its contents for you.
We just built a project with `cargo build` and ran it with
`./target/debug/hello_cargo`, but we can also use `cargo run` to compile the
-code and then run the resulting executable all in one command:
+code and then run the resultant executable all in one command:
```
$ cargo run
@@ -568,7 +541,7 @@ $ cargo check
```
Why would you not want an executable? Often, `cargo check` is much faster than
-`cargo build`, because it skips the step of producing an executable. If you’re
+`cargo build` because it skips the step of producing an executable. If you’re
continually checking your work while writing the code, using `cargo check` will
speed up the process of letting you know if your project is still compiling! As
such, many Rustaceans run `cargo check` periodically as they write their
@@ -581,9 +554,9 @@ Let’s recap what we’ve learned so far about Cargo:
* We can build a project using `cargo build`.
* We can build and run a project in one step using `cargo run`.
* We can build a project without producing a binary to check for errors using
- `cargo check`.
+`cargo check`.
* Instead of saving the result of the build in the same directory as our code,
- Cargo stores it in the *target/debug* directory.
+Cargo stores it in the *target/debug* directory.
An additional advantage of using Cargo is that the commands are the same no
matter which operating system you’re working on. So, at this point, we’ll no
@@ -609,10 +582,6 @@ With simple projects, Cargo doesn’t provide a lot of value over just using
Once programs grow to multiple files or need a dependency, it’s much easier to
let Cargo coordinate the build.
-<!-- I think once you go add a second file or add a single dependency, you
-already want to move to cargo imho. /JT -->
-<!-- Updated above! /Carol -->
-
Even though the `hello_cargo` project is simple, it now uses much of the real
tooling you’ll use in the rest of your Rust career. In fact, to work on any
existing projects, you can use the following commands to check out the code
@@ -624,7 +593,8 @@ $ cd someproject
$ cargo build
```
-For more information about Cargo, check out its documentation at *https://doc.rust-lang.org/cargo/*.
+For more information about Cargo, check out its documentation at
+*https://doc.rust-lang.org/cargo*.
## Summary
@@ -642,8 +612,3 @@ and writing Rust code. So, in Chapter 2, we’ll build a guessing game program.
If you would rather start by learning how common programming concepts work in
Rust, see Chapter 3 and then return to Chapter 2.
-<!-- Question for Carol: Do we want to mention IDE support? Rust Analyzer is
-pretty good these days. /JT -->
-<!-- I don't want to make the reader feel like they *have* to stop at this
-point and set up their IDE (or use an unfamiliar IDE); I did add a sentence to
-the note about IDEs pointing to Appendix D for more info on Rust Analyzer. -->
diff --git a/src/doc/book/nostarch/chapter02.md b/src/doc/book/nostarch/chapter02.md
index b7986c0de..b01770dc5 100644
--- a/src/doc/book/nostarch/chapter02.md
+++ b/src/doc/book/nostarch/chapter02.md
@@ -11,8 +11,8 @@ directory, so all fixes need to be made in `/src/`.
Let’s jump into Rust by working through a hands-on project together! This
chapter introduces you to a few common Rust concepts by showing you how to use
them in a real program. You’ll learn about `let`, `match`, methods, associated
-functions, using external crates, and more! In the following chapters, we’ll
-explore these ideas in more detail. In this chapter, you’ll practice the
+functions, external crates, and more! In the following chapters, we’ll explore
+these ideas in more detail. In this chapter, you’ll just practice the
fundamentals.
We’ll implement a classic beginner programming problem: a guessing game. Here’s
@@ -45,14 +45,12 @@ name = "guessing_game"
version = "0.1.0"
edition = "2021"
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+# See more keys and their definitions at
+https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
```
-<!--- We should move to the 2021 edition. /JT --->
-<!-- Totally right, done! /Carol -->
-
As you saw in Chapter 1, `cargo new` generates a “Hello, world!†program for
you. Check out the *src/main.rs* file:
@@ -108,27 +106,21 @@ fn main() {
}
```
-<!--- Style question, should we switch to the more recent style of:
-```
- println!("You guessed: {guess}");
-```
-/JT --->
-<!-- Good call, I'll switch these throughout as I edit after TR. /Carol -->
-
Listing 2-1: Code that gets a guess from the user and prints it
This code contains a lot of information, so let’s go over it line by line. To
obtain user input and then print the result as output, we need to bring the
-`io` input/output library into scope. The `io` library comes from the
-standard library, known as `std`:
+`io` input/output library into scope. The `io` library comes from the standard
+library, known as `std`:
```
use std::io;
```
-By default, Rust has a set of items defined in the standard library that it brings
-into the scope of every program. This set is called the *prelude*, and you can
-see everything in it at *https://doc.rust-lang.org/std/prelude/index.html*.
+By default, Rust has a set of items defined in the standard library that it
+brings into the scope of every program. This set is called the *prelude*, and
+you can see everything in it at
+*https://doc.rust-lang.org/std/prelude/index.html*.
If a type you want to use isn’t in the prelude, you have to bring that type
into scope explicitly with a `use` statement. Using the `std::io` library
@@ -142,21 +134,16 @@ program:
fn main() {
```
-The `fn` syntax declares a new function, the parentheses, `()`, indicate there
-are no parameters, and the curly bracket, `{`, starts the body of the function.
+The `fn` syntax declares a new function; the parentheses, `()`, indicate there
+are no parameters; and the curly bracket, `{`, starts the body of the function.
As you also learned in Chapter 1, `println!` is a macro that prints a string to
the screen:
-<!--- Not sure if we want to go into it just yet, but `println!` formats a string
-and then prints the resulting string to stdout (which is often, but not always
-the screen). /JT --->
-<!-- Yeah, I want to gloss over that for now. Leaving this as-is. /Carol -->
-
```
- println!("Guess the number!");
+println!("Guess the number!");
- println!("Please input your guess.");
+println!("Please input your guess.");
```
This code is printing a prompt stating what the game is and requesting input
@@ -167,7 +154,7 @@ from the user.
Next, we’ll create a *variable* to store the user input, like this:
```
- let mut guess = String::new();
+let mut guess = String::new();
```
Now the program is getting interesting! There’s a lot going on in this little
@@ -179,15 +166,9 @@ let apples = 5;
This line creates a new variable named `apples` and binds it to the value 5. In
Rust, variables are immutable by default, meaning once we give the variable a
-value, the value won't change. We’ll be discussing this concept in detail in
-the “Variables and Mutability†section in Chapter 3. To make a variable
-mutable, we add `mut` before the variable name:
-
-<!--- Do we want to give a quick word about what "mutable" means? Folks who grab
-this book but aren't familiar with some of the technical programming language terms
-might need something like "variable are immutable by default, meaning once we give
-the variable its value, it won't change". /JT --->
-<!-- Sounds good, made that change /Carol -->
+value, the value won’t change. We’ll be discussing this concept in detail in
+“Variables and Mutability†on page XX. To make a variable mutable, we add `mut`
+before the variable name:
```
let apples = 5; // immutable
@@ -195,12 +176,12 @@ let mut bananas = 5; // mutable
```
> Note: The `//` syntax starts a comment that continues until the end of the
-> line. Rust ignores everything in comments. We’ll discuss comments in more
-> detail in Chapter 3.
+line. Rust ignores everything in comments. We’ll discuss comments in more
+detail in Chapter 3.
Returning to the guessing game program, you now know that `let mut guess` will
introduce a mutable variable named `guess`. The equal sign (`=`) tells Rust we
-want to bind something to the variable now. On the right of the equals sign is
+want to bind something to the variable now. On the right of the equal sign is
the value that `guess` is bound to, which is the result of calling
`String::new`, a function that returns a new instance of a `String`. `String`
is a string type provided by the standard library that is a growable, UTF-8
@@ -209,15 +190,9 @@ encoded bit of text.
The `::` syntax in the `::new` line indicates that `new` is an associated
function of the `String` type. An *associated function* is a function that’s
implemented on a type, in this case `String`. This `new` function creates a
-new, empty string. You’ll find a `new` function on many types, because it’s a
+new, empty string. You’ll find a `new` function on many types because it’s a
common name for a function that makes a new value of some kind.
-<!--- For some readers, we might want to say "If you've used languages with
-static methods, associated function work very similarly" or something along
-those lines. /JT --->
-<!-- I don't think that's helpful enough for all readers to include here, given
-that we're trying to make the book mostly background-agnostic. /Carol -->
-
In full, the `let mut guess = String::new();` line has created a mutable
variable that is currently bound to a new, empty instance of a `String`. Whew!
@@ -229,11 +204,11 @@ the `stdin` function from the `io` module, which will allow us to handle user
input:
```
- io::stdin()
- .read_line(&mut guess)
+io::stdin()
+ .read_line(&mut guess)
```
-If we hadn’t imported the `io` library with `use std::io` at the beginning of
+If we hadn’t imported the `io` library with `use std::io;` at the beginning of
the program, we could still use the function by writing this function call as
`std::io::stdin`. The `stdin` function returns an instance of `std::io::Stdin`,
which is a type that represents a handle to the standard input for your
@@ -252,27 +227,19 @@ let multiple parts of your code access one piece of data without needing to
copy that data into memory multiple times. References are a complex feature,
and one of Rust’s major advantages is how safe and easy it is to use
references. You don’t need to know a lot of those details to finish this
-program. For now, all you need to know is that like variables, references are
+program. For now, all you need to know is that, like variables, references are
immutable by default. Hence, you need to write `&mut guess` rather than
`&guess` to make it mutable. (Chapter 4 will explain references more
thoroughly.)
-### Handling Potential Failure with the `Result` Type
+### Handling Potential Failure with Result
We’re still working on this line of code. We’re now discussing a third line of
text, but note that it’s still part of a single logical line of code. The next
part is this method:
-<!--- in the program this is the second line of code -- do you mean the third
-section of this line? -->
-<!-- This is still discussing the code in Listing 2-1, and is going to talk
-about the third line, if you're counting the lines of the page, of this logical
-line of code, where logical lines of code are ended with semicolons. Do you
-have suggestions on how to make that clearer? /Carol -->
-<!--- Ashley, does this all track now? /LC --->
-
```
- .expect("Failed to read line");
+.expect("Failed to read line");
```
We could have written this code as:
@@ -291,17 +258,10 @@ we pass to it, but it also returns a `Result` value. `Result` is an
*enumeration*, often called an *enum*, which is a type that can be in one of
multiple possible states. We call each possible state a *variant*.
-<!--- Typo above: possibilities /JT --->
-<!--- Personally, I think the above paragraph might be introducing a little too
-much all at once. You might be able to shorten it to: "`Result` is an *enumeration*,
-often called an *enum*, which is a type that can be in one of multiple possible
-states. We call each possible state a *variant*. /JT --->
-<!-- I like it, made that change /Carol -->
-
Chapter 6 will cover enums in more detail. The purpose of these `Result` types
is to encode error-handling information.
-`Result`'s variants are `Ok` and `Err`. The `Ok` variant indicates the
+`Result`’s variants are `Ok` and `Err`. The `Ok` variant indicates the
operation was successful, and inside `Ok` is the successfully generated value.
The `Err` variant means the operation failed, and `Err` contains information
about how or why the operation failed.
@@ -337,38 +297,36 @@ warning: `guessing_game` (bin "guessing_game") generated 1 warning
Rust warns that you haven’t used the `Result` value returned from `read_line`,
indicating that the program hasn’t handled a possible error.
-The right way to suppress the warning is to actually write error handling, but
-in our case we just want to crash this program when a problem occurs, so we can
-use `expect`. You’ll learn about recovering from errors in Chapter 9.
+The right way to suppress the warning is to actually write error-handling code,
+but in our case we just want to crash this program when a problem occurs, so we
+can use `expect`. You’ll learn about recovering from errors in Chapter 9.
-### Printing Values with `println!` Placeholders
+### Printing Values with println! Placeholders
Aside from the closing curly bracket, there’s only one more line to discuss in
the code so far:
```
- println!("You guessed: {guess}");
+println!("You guessed: {guess}");
```
-<!--- Ditto with using the `{guess}` style in this line. /JT --->
-
This line prints the string that now contains the user’s input. The `{}` set of
curly brackets is a placeholder: think of `{}` as little crab pincers that hold
-a value in place. You can print more than one value using curly brackets: the
-first set of curly brackets holds the first value listed after the format
-string, the second set holds the second value, and so on. Printing multiple
-values in one call to `println!` would look like this:
+a value in place. When printing the value of a variable, the variable name can
+go inside the curly brackets. When printing the result of evaluating an
+expression, place empty curly brackets in the format string, then follow the
+format string with a comma-separated list of expressions to print in each empty
+curly bracket placeholder in the same order. Printing a variable and the result
+of an expression in one call to `println!` would look like this:
```
let x = 5;
let y = 10;
-println!("x = {x} and y = {y}");
+println!("x = {x} and y + 2 = {}", y + 2);
```
-<!--- And `println!("x = {x} and y = {y}");` in this example. /JT --->
-<!-- Done! /Carol -->
-This code would print `x = 5 and y = 10`.
+This code would print `x = 5 and y = 12`.
### Testing the First Part
@@ -401,43 +359,36 @@ library. However, the Rust team does provide a `rand` crate at
Remember that a crate is a collection of Rust source code files. The project
we’ve been building is a *binary crate*, which is an executable. The `rand`
-crate is a *library crate*, which contains code intended to be used in other
-programs and can't be executed on its own.
-
-<!--- Nit: ", and" followed by incomplete sentence. /JT --->
-<!-- Fixed /Carol -->
+crate is a *library crate*, which contains code that is intended to be used in
+other programs and can’t be executed on its own.
Cargo’s coordination of external crates is where Cargo really shines. Before we
can write code that uses `rand`, we need to modify the *Cargo.toml* file to
include the `rand` crate as a dependency. Open that file now and add the
-following line to the bottom beneath the `[dependencies]` section header that
+following line to the bottom, beneath the `[dependencies]` section header that
Cargo created for you. Be sure to specify `rand` exactly as we have here, with
-this version number, or the code examples in this tutorial may not work.
+this version number, or the code examples in this tutorial may not work:
Filename: Cargo.toml
```
-rand = "0.8.3"
+[dependencies]
+rand = "0.8.5"
```
-<!--- 0.8.5 is the current latest. /JT --->
-<!-- I will update this version to whatever is latest once we're in Word; there
-could be another version between now and then. If it's another 0.8.x version,
-it doesn't really matter in any case. /Carol -->
In the *Cargo.toml* file, everything that follows a header is part of that
section that continues until another section starts. In `[dependencies]` you
tell Cargo which external crates your project depends on and which versions of
those crates you require. In this case, we specify the `rand` crate with the
-semantic version specifier `0.8.3`. Cargo understands Semantic Versioning
+semantic version specifier `0.8.5`. Cargo understands Semantic Versioning
(sometimes called *SemVer*), which is a standard for writing version numbers.
-The number `0.8.3` is actually shorthand for `^0.8.3`, which means any version
-that is at least `0.8.3` but below `0.9.0`.
+The specifier `0.8.5` is actually shorthand for `^0.8.5`, which means any
+version that is at least 0.8.5 but below 0.9.0.
Cargo considers these versions to have public APIs compatible with version
-`0.8.3`, and this specification ensures you’ll get the latest patch release
-that will still compile with the code in this chapter. Any version `0.9.0` or
-greater is not guaranteed to have the same API as what the following examples
-use.
+0.8.5, and this specification ensures you’ll get the latest patch release that
+will still compile with the code in this chapter. Any version 0.9.0 or greater
+is not guaranteed to have the same API as what the following examples use.
Now, without changing any of the code, let’s build the project, as shown in
Listing 2-2.
@@ -445,48 +396,34 @@ Listing 2-2.
```
$ cargo build
Updating crates.io index
- Downloaded rand v0.8.3
- Downloaded libc v0.2.86
- Downloaded getrandom v0.2.2
+ Downloaded rand v0.8.5
+ Downloaded libc v0.2.127
+ Downloaded getrandom v0.2.7
Downloaded cfg-if v1.0.0
- Downloaded ppv-lite86 v0.2.10
- Downloaded rand_chacha v0.3.0
- Downloaded rand_core v0.6.2
- Compiling rand_core v0.6.2
- Compiling libc v0.2.86
- Compiling getrandom v0.2.2
- Compiling cfg-if v1.0.0
- Compiling ppv-lite86 v0.2.10
- Compiling rand_chacha v0.3.0
- Compiling rand v0.8.3
- Compiling guessing_game v0.1.0 (file:///projects/guessing_game)
- Finished dev [unoptimized + debuginfo] target(s) in 2.53s
-```
-<!--- If we feel like refreshing this, here's what I saw today:
-
+ Downloaded ppv-lite86 v0.2.16
+ Downloaded rand_chacha v0.3.1
+ Downloaded rand_core v0.6.3
+ Compiling rand_core v0.6.3
+ Compiling libc v0.2.127
+ Compiling getrandom v0.2.7
Compiling cfg-if v1.0.0
Compiling ppv-lite86 v0.2.16
- Compiling libc v0.2.120
- Compiling getrandom v0.2.5
- Compiling rand_core v0.6.3
Compiling rand_chacha v0.3.1
Compiling rand v0.8.5
- Compiling guessing_game v0.1.0 (/Users/jt/Source/book/guessing_game)
- Finished dev [unoptimized + debuginfo] target(s) in 1.50s
-
-/JT --->
-<!-- I will refresh this when we're in Word /Carol -->
+ Compiling guessing_game v0.1.0 (file:///projects/guessing_game)
+ Finished dev [unoptimized + debuginfo] target(s) in 2.53s
+```
-Listing 2-2: The output from running `cargo build` after adding the rand crate
-as a dependency
+Listing 2-2: The output from running `cargo build` after adding the `rand`
+crate as a dependency
You may see different version numbers (but they will all be compatible with the
-code, thanks to SemVer!), different lines (depending on the operating system),
-and the lines may be in a different order.
+code, thanks to SemVer!) and different lines (depending on the operating
+system), and the lines may be in a different order.
When we include an external dependency, Cargo fetches the latest versions of
everything that dependency needs from the *registry*, which is a copy of data
-from Crates.io at *https://crates.io/*. Crates.io is where people in the Rust
+from Crates.io at *https://crates.io*. Crates.io is where people in the Rust
ecosystem post their open source Rust projects for others to use.
After updating the registry, Cargo checks the `[dependencies]` section and
@@ -502,8 +439,8 @@ about them in your *Cargo.toml* file. Cargo also knows that you haven’t change
anything about your code, so it doesn’t recompile that either. With nothing to
do, it simply exits.
-If you open up the *src/main.rs* file, make a trivial change, and then save it
-and build again, you’ll only see two lines of output:
+If you open the *src/main.rs* file, make a trivial change, and then save it and
+build again, you’ll only see two lines of output:
```
$ cargo build
@@ -511,42 +448,30 @@ $ cargo build
Finished dev [unoptimized + debuginfo] target(s) in 2.53 secs
```
-These lines show Cargo only updates the build with your tiny change to the
+These lines show that Cargo only updates the build with your tiny change to the
*src/main.rs* file. Your dependencies haven’t changed, so Cargo knows it can
reuse what it has already downloaded and compiled for those.
-#### Ensuring Reproducible Builds with the *Cargo.lock* File
+#### Ensuring Reproducible Builds with the Cargo.lock File
Cargo has a mechanism that ensures you can rebuild the same artifact every time
you or anyone else builds your code: Cargo will use only the versions of the
dependencies you specified until you indicate otherwise. For example, say that
-next week version 0.8.4 of the `rand` crate comes out, and that version
+next week version 0.8.6 of the `rand` crate comes out, and that version
contains an important bug fix, but it also contains a regression that will
break your code. To handle this, Rust creates the *Cargo.lock* file the first
time you run `cargo build`, so we now have this in the *guessing_game*
directory.
-<!--- If we bump version numbers, we should bump above and below also. /JT --->
-<!-- Yup, will do in Word! /Carol -->
-
-When you build a project for the first time, Cargo figures out all the
-versions of the dependencies that fit the criteria and then writes them to
-the *Cargo.lock* file. When you build your project in the future, Cargo will
-see that the *Cargo.lock* file exists and use the versions specified there
+When you build a project for the first time, Cargo figures out all the versions
+of the dependencies that fit the criteria and then writes them to the
+*Cargo.lock* file. When you build your project in the future, Cargo will see
+that the *Cargo.lock* file exists and will use the versions specified there
rather than doing all the work of figuring out versions again. This lets you
have a reproducible build automatically. In other words, your project will
-remain at `0.8.3` until you explicitly upgrade, thanks to the *Cargo.lock*
-file. Because the *Cargo.lock* file is important for reproducible builds, it's
-often checked into source control with the rest of the code in your project.
-
-<!--- We could mention that because Cargo.lock is important for reproducible
-builds, they're often checked into source control alongside the Cargo.toml and
-the rest of the code of your project. /JT --->
-<!-- Liz, is this sentence ok even though we don't really talk about source
-control or what it is anywhere else in the book? I don't really want to get
-into it, but at this point I think it's a fair assumption that developers know
-what "source control" is. If you disagree, this sentence can come back out.
-/Carol -->
+remain at 0.8.5 until you explicitly upgrade, thanks to the *Cargo.lock* file.
+Because the *Cargo.lock* file is important for reproducible builds, it’s often
+checked into source control with the rest of the code in your project.
#### Updating a Crate to Get a New Version
@@ -554,24 +479,20 @@ When you *do* want to update a crate, Cargo provides the command `update`,
which will ignore the *Cargo.lock* file and figure out all the latest versions
that fit your specifications in *Cargo.toml*. Cargo will then write those
versions to the *Cargo.lock* file. Otherwise, by default, Cargo will only look
-for versions greater than `0.8.3` and less than `0.9.0`. If the `rand` crate
-has released the two new versions `0.8.4` and `0.9.0` you would see the
-following if you ran `cargo update`:
+for versions greater than 0.8.5 and less than 0.9.0. If the `rand` crate has
+released the two new versions 0.8.6 and 0.9.0, you would see the following if
+you ran `cargo update`:
```
$ cargo update
Updating crates.io index
- Updating rand v0.8.3 -> v0.8.4
+ Updating rand v0.8.5 -> v0.8.6
```
-Cargo ignores the `0.9.0` release. At this point, you would also notice a
-change in your *Cargo.lock* file noting that the version of the `rand` crate
-you are now using is `0.8.4`. To use `rand` version `0.9.0` or any version in
-the `0.9.x` series, you’d have to update the *Cargo.toml* file to look like
-this instead:
-
-<!--- Typo first line: release. /JT --->
-<!-- Fixed /Carol -->
+Cargo ignores the 0.9.0 release. At this point, you would also notice a change
+in your *Cargo.lock* file noting that the version of the `rand` crate you are
+now using is 0.8.6. To use `rand` version 0.9.0 or any version in the 0.9.*x*
+series, you’d have to update the *Cargo.toml* file to look like this instead:
```
[dependencies]
@@ -582,7 +503,7 @@ The next time you run `cargo build`, Cargo will update the registry of crates
available and reevaluate your `rand` requirements according to the new version
you have specified.
-There’s a lot more to say about Cargo and its ecosystem which we’ll discuss in
+There’s a lot more to say about Cargo and its ecosystem, which we’ll discuss in
Chapter 14, but for now, that’s all you need to know. Cargo makes it very easy
to reuse libraries, so Rustaceans are able to write smaller projects that are
assembled from a number of packages.
@@ -596,14 +517,14 @@ Filename: src/main.rs
```
use std::io;
-[1]use rand::Rng;
+1 use rand::Rng;
fn main() {
println!("Guess the number!");
- [2] let secret_number = rand::thread_rng().gen_range(1..=100);
+ 2 let secret_number = rand::thread_rng().gen_range(1..=100);
- [3] println!("The secret number is: {secret_number}");
+ 3 println!("The secret number is: {secret_number}");
println!("Please input your guess.");
@@ -617,50 +538,35 @@ fn main() {
}
```
-<!--- Same style suggestion re: `{secret_number}`. /JT --->
-<!--- Thought: for first-time readability, we could use `1..=100` in the above
-and let people know later this is equivalent to `1..101` later. We say a number
-between 1 and 100, so we could show the syntax equivalent of that description.
-/JT --->
-<!-- I'm into both these suggestions! /Carol -->
-
Listing 2-3: Adding code to generate a random number
-<!--- I can't remember how we handled wingdings in markdown before... I don't
-have those files on this machine. I've just used [x] for now, does that work?
-Then we'll replace them when we convert to Word /LC --->
-<!-- I don't think we added the wingdings at all until we moved to Word. For
-code listings that are the same as the last printing version, I'd definitely
-like to keep the wingdings the way they were. Using the brackets with numbers
-as you have here works fine! /Carol -->
-
-First, we add the line `use rand::Rng` [1]. The `Rng` trait defines methods
+First we add the line `use rand::Rng;` [1]. The `Rng` trait defines methods
that random number generators implement, and this trait must be in scope for us
to use those methods. Chapter 10 will cover traits in detail.
Next, we’re adding two lines in the middle. In the first line [2], we call the
`rand::thread_rng` function that gives us the particular random number
-generator that we’re going to use: one that is local to the current thread of
-execution and seeded by the operating system. Then we call the `gen_range`
+generator we’re going to use: one that is local to the current thread of
+execution and is seeded by the operating system. Then we call the `gen_range`
method on the random number generator. This method is defined by the `Rng`
-trait that we brought into scope with the `use rand::Rng` statement. The
+trait that we brought into scope with the `use rand::Rng;` statement. The
`gen_range` method takes a range expression as an argument and generates a
random number in the range. The kind of range expression we’re using here takes
the form `start..=end` and is inclusive on the lower and upper bounds, so we
need to specify `1..=100` to request a number between 1 and 100.
> Note: You won’t just know which traits to use and which methods and functions
-> to call from a crate, so each crate has documentation with instructions for
-> using it. Another neat feature of Cargo is that running the `cargo
-> doc --open` command will build documentation provided by all of your
-> dependencies locally and open it in your browser. If you’re interested in
-> other functionality in the `rand` crate, for example, run `cargo doc --open`
-> and click `rand` in the sidebar on the left.
-
-The second new line [3] prints the secret number. This is useful while
-we’re developing the program to be able to test it, but we’ll delete it from
-the final version. It’s not much of a game if the program prints the answer as
-soon as it starts!
+to call from a crate, so each crate has documentation with instructions for
+using it. Another neat feature of Cargo is that running the `cargo doc --open`
+command will build documentation provided by all your dependencies locally and
+open it in your browser. If you’re interested in other functionality in the
+`rand` crate, for example, run `cargo doc --open` and click `rand` in the
+sidebar on the left.
+
+The second new line [3] prints the secret number. This is useful while we’re
+developing the program to be able to test it, but we’ll delete it from the
+final version. It’s not much of a game if the program prints the answer as soon
+as it starts!
Try running the program a few times:
@@ -691,22 +597,22 @@ You should get different random numbers, and they should all be numbers between
## Comparing the Guess to the Secret Number
Now that we have user input and a random number, we can compare them. That step
-is shown in Listing 2-4. Note that this code won’t compile quite yet, as we
-will explain.
+is shown in Listing 2-4. Note that this code won’t compile just yet, as we will
+explain.
Filename: src/main.rs
```
use rand::Rng;
-[1]use std::cmp::Ordering;
+1 use std::cmp::Ordering;
use std::io;
fn main() {
- // --snip--
+ --snip--
println!("You guessed: {guess}");
- match[2] guess.cmp(&secret_number)[3] {
+ 2 match guess.3 cmp(&secret_number) {
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal => println!("You win!"),
@@ -724,7 +630,7 @@ the three outcomes that are possible when you compare two values.
Then we add five new lines at the bottom that use the `Ordering` type. The
`cmp` method [3] compares two values and can be called on anything that can be
compared. It takes a reference to whatever you want to compare with: here it’s
-comparing the `guess` to the `secret_number`. Then it returns a variant of the
+comparing `guess` to `secret_number`. Then it returns a variant of the
`Ordering` enum we brought into scope with the `use` statement. We use a
`match` expression [2] to decide what to do next based on which variant of
`Ordering` was returned from the call to `cmp` with the values in `guess` and
@@ -734,14 +640,16 @@ A `match` expression is made up of *arms*. An arm consists of a *pattern* to
match against, and the code that should be run if the value given to `match`
fits that arm’s pattern. Rust takes the value given to `match` and looks
through each arm’s pattern in turn. Patterns and the `match` construct are
-powerful Rust features that let you express a variety of situations your code
-might encounter and make sure that you handle them all. These features will be
+powerful Rust features: they let you express a variety of situations your code
+might encounter and they make sure you handle them all. These features will be
covered in detail in Chapter 6 and Chapter 18, respectively.
Let’s walk through an example with the `match` expression we use here. Say that
the user has guessed 50 and the randomly generated secret number this time is
-38. When the code compares 50 to 38, the `cmp` method will return
-`Ordering::Greater`, because 50 is greater than 38. The `match` expression gets
+38.
+
+When the code compares 50 to 38, the `cmp` method will return
+`Ordering::Greater` because 50 is greater than 38. The `match` expression gets
the `Ordering::Greater` value and starts checking each arm’s pattern. It looks
at the first arm’s pattern, `Ordering::Less`, and sees that the value
`Ordering::Greater` does not match `Ordering::Less`, so it ignores the code in
@@ -751,11 +659,6 @@ code in that arm will execute and print `Too big!` to the screen. The `match`
expression ends after the first successful match, so it won’t look at the last
arm in this scenario.
-<!--- Since `match` always ends after the first successful match, we might want
-to just say that directly: "The `match` expression ends after the first successful
-match, so it won't look at the last arm in this scenario". /JT --->
-<!-- Sounds good, done! /Carol -->
-
However, the code in Listing 2-4 won’t compile yet. Let’s try it:
```
@@ -782,85 +685,79 @@ an `i32`, which is the type of `secret_number` unless you add type information
elsewhere that would cause Rust to infer a different numerical type. The reason
for the error is that Rust cannot compare a string and a number type.
-<!--- Typo: Unless otherwise specified. /JT --->
-<!-- Fixed /Carol -->
-
Ultimately, we want to convert the `String` the program reads as input into a
-real number type so we can compare it numerically to the secret number. We do so
-by adding this line to the `main` function body:
+real number type so we can compare it numerically to the secret number. We do
+so by adding this line to the `main` function body:
Filename: src/main.rs
```
- // --snip--
+--snip--
- let mut guess = String::new();
+let mut guess = String::new();
- io::stdin()
- .read_line(&mut guess)
- .expect("Failed to read line");
+io::stdin()
+ .read_line(&mut guess)
+ .expect("Failed to read line");
- let guess: u32 = guess.trim().parse().expect("Please type a number!");
+let guess: u32 = guess
+ .trim()
+ .parse()
+ .expect("Please type a number!");
- println!("You guessed: {guess}");
+println!("You guessed: {guess}");
- match guess.cmp(&secret_number) {
- Ordering::Less => println!("Too small!"),
- Ordering::Greater => println!("Too big!"),
- Ordering::Equal => println!("You win!"),
- }
+match guess.cmp(&secret_number) {
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => println!("You win!"),
+}
```
We create a variable named `guess`. But wait, doesn’t the program already have
-a variable named `guess`? It does, but helpfully Rust allows us to *shadow* the
-previous value of `guess` with a new one. Shadowing lets us reuse the `guess`
+a variable named `guess`? It does, but helpfully Rust allows us to shadow the
+previous value of `guess` with a new one. *Shadowing* lets us reuse the `guess`
variable name rather than forcing us to create two unique variables, such as
-`guess_str` and `guess` for example. We’ll cover this in more detail in Chapter
-3, but for now know that this feature is often used when you want to convert a
-value from one type to another type.
+`guess_str` and `guess`, for example. We’ll cover this in more detail in
+Chapter 3, but for now, know that this feature is often used when you want to
+convert a value from one type to another type.
We bind this new variable to the expression `guess.trim().parse()`. The `guess`
in the expression refers to the original `guess` variable that contained the
input as a string. The `trim` method on a `String` instance will eliminate any
whitespace at the beginning and end, which we must do to be able to compare the
string to the `u32`, which can only contain numerical data. The user must press
-<span class="keystroke">enter</span> to satisfy `read_line` and input their
-guess, which adds a newline character to the string. For example, if the user
-types <span class="keystroke">5</span> and presses <span
-class="keystroke">enter</span>, `guess` looks like this: `5\n`. The `\n`
-represents “newlineâ€. (On Windows, pressing <span
-class="keystroke">enter</span> results in a carriage return and a newline,
-`\r\n`). The `trim` method eliminates `\n` or `\r\n`, resulting in just `5`.
+enter to satisfy `read_line` and input their guess, which adds a newline
+character to the string. For example, if the user types `5` and presses enter,
+`guess` looks like this: `5\n`. The `\n` represents “newline.†(On Windows,
+pressing enter results in a carriage return and a newline, `\r\n`.) The `trim`
+method eliminates `\n` or `\r\n`, resulting in just `5`.
The `parse` method on strings converts a string to another type. Here, we use
it to convert from a string to a number. We need to tell Rust the exact number
type we want by using `let guess: u32`. The colon (`:`) after `guess` tells
Rust we’ll annotate the variable’s type. Rust has a few built-in number types;
the `u32` seen here is an unsigned, 32-bit integer. It’s a good default choice
-for a small positive number. You’ll learn about other number types in Chapter
-3. Additionally, the `u32` annotation in this example program and the
-comparison with `secret_number` means that Rust will infer that `secret_number`
-should be a `u32` as well. So now the comparison will be between two values of
-the same type!
+for a small positive number. You’ll learn about other number types in Chapter 3.
-<!--- More correct to say "The `parse` method converts a string to another type.
-Here, we use it to convert from a string to a number." You can use `parse` to
-convert to non-numeric types also. /JT --->
-<!-- Great catch, fixed! /Carol -->
+Additionally, the `u32` annotation in this example program and the comparison
+with `secret_number` means Rust will infer that `secret_number` should be a
+`u32` as well. So now the comparison will be between two values of the same
+type!
The `parse` method will only work on characters that can logically be converted
into numbers and so can easily cause errors. If, for example, the string
-contained `AðŸ‘%`, there would be no way to convert that to a number. Because it
-might fail, the `parse` method returns a `Result` type, much as the `read_line`
-method does (discussed earlier in “Handling Potential Failure with the `Result`
-Typeâ€). We’ll treat this `Result` the same way by using the `expect` method
-again. If `parse` returns an `Err` `Result` variant because it couldn’t create
-a number from the string, the `expect` call will crash the game and print the
-message we give it. If `parse` can successfully convert the string to a number,
-it will return the `Ok` variant of `Result`, and `expect` will return the
-number that we want from the `Ok` value.
+contained `A`ðŸ‘`%`, there would be no way to convert that to a number. Because
+it might fail, the `parse` method returns a `Result` type, much as the
+`read_line` method does (discussed earlier in “Handling Potential Failure with
+Result†on page XX). We’ll treat this `Result` the same way by using the
+`expect` method again. If `parse` returns an `Err` `Result` variant because it
+couldn’t create a number from the string, the `expect` call will crash the game
+and print the message we give it. If `parse` can successfully convert the
+string to a number, it will return the `Ok` variant of `Result`, and `expect`
+will return the number that we want from the `Ok` value.
-Let’s run the program now!
+Let’s run the program now:
```
$ cargo run
@@ -891,20 +788,19 @@ more chances at guessing the number:
Filename: src/main.rs
```
- // --snip--
+--snip--
- println!("The secret number is: {secret_number}");
+println!("The secret number is: {secret_number}");
- loop {
- println!("Please input your guess.");
+loop {
+ println!("Please input your guess.");
- // --snip--
+ --snip--
- match guess.cmp(&secret_number) {
- Ordering::Less => println!("Too small!"),
- Ordering::Greater => println!("Too big!"),
- Ordering::Equal => println!("You win!"),
- }
+ match guess.cmp(&secret_number) {
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => println!("You win!"),
}
}
```
@@ -915,11 +811,10 @@ and run the program again. The program will now ask for another guess forever,
which actually introduces a new problem. It doesn’t seem like the user can quit!
The user could always interrupt the program by using the keyboard shortcut
-<span class="keystroke">ctrl-c</span>. But there’s another way to escape this
-insatiable monster, as mentioned in the `parse` discussion in “Comparing the
-Guess to the Secret Numberâ€: if the user enters a non-number answer, the
-program will crash. We can take advantage of that to allow the user to quit, as
-shown here:
+ctrl-C. But there’s another way to escape this insatiable monster, as mentioned
+in the `parse` discussion in “Comparing the Guess to the Secret Number†on page
+XX: if the user enters a non-number answer, the program will crash. We can take
+advantage of that to allow the user to quit, as shown here:
```
$ cargo run
@@ -942,12 +837,13 @@ You guessed: 59
You win!
Please input your guess.
quit
-thread 'main' panicked at 'Please type a number!: ParseIntError { kind: InvalidDigit }', src/main.rs:28:47
+thread 'main' panicked at 'Please type a number!: ParseIntError
+{ kind: InvalidDigit }', src/main.rs:28:47
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
-Typing `quit` will quit the game, but as you’ll notice so will entering any
-other non-number input. This is suboptimal to say the least; we want the game
+Typing `quit` will quit the game, but as you’ll notice, so will entering any
+other non-number input. This is suboptimal, to say the least; we want the game
to also stop when the correct number is guessed.
### Quitting After a Correct Guess
@@ -957,16 +853,14 @@ Let’s program the game to quit when the user wins by adding a `break` statemen
Filename: src/main.rs
```
- // --snip--
+--snip--
- match guess.cmp(&secret_number) {
- Ordering::Less => println!("Too small!"),
- Ordering::Greater => println!("Too big!"),
- Ordering::Equal => {
- println!("You win!");
- break;
- }
- }
+match guess.cmp(&secret_number) {
+ Ordering::Less => println!("Too small!"),
+ Ordering::Greater => println!("Too big!"),
+ Ordering::Equal => {
+ println!("You win!");
+ break;
}
}
```
@@ -985,20 +879,20 @@ is converted from a `String` to a `u32`, as shown in Listing 2-5.
Filename: src/main.rs
```
- // --snip--
+--snip--
- io::stdin()
- .read_line(&mut guess)
- .expect("Failed to read line");
+io::stdin()
+ .read_line(&mut guess)
+ .expect("Failed to read line");
- let guess: u32 = match guess.trim().parse() {
- Ok(num) => num,
- Err(_) => continue,
- };
+let guess: u32 = match guess.trim().parse() {
+ Ok(num) => num,
+ Err(_) => continue,
+};
- println!("You guessed: {guess}");
+println!("You guessed: {guess}");
- // --snip--
+--snip--
```
Listing 2-5: Ignoring a non-number guess and asking for another guess instead
@@ -1011,7 +905,7 @@ a `match` expression here, as we did with the `Ordering` result of the `cmp`
method.
If `parse` is able to successfully turn the string into a number, it will
-return an `Ok` value that contains the resulting number. That `Ok` value will
+return an `Ok` value that contains the resultant number. That `Ok` value will
match the first arm’s pattern, and the `match` expression will just return the
`num` value that `parse` produced and put inside the `Ok` value. That number
will end up right where we want it in the new `guess` variable we’re creating.
@@ -1098,10 +992,10 @@ fn main() {
Listing 2-6: Complete guessing game code
-## Summary
-
At this point, you’ve successfully built the guessing game. Congratulations!
+## Summary
+
This project was a hands-on way to introduce you to many new Rust concepts:
`let`, `match`, functions, the use of external crates, and more. In the next
few chapters, you’ll learn about these concepts in more detail. Chapter 3
@@ -1109,3 +1003,4 @@ covers concepts that most programming languages have, such as variables, data
types, and functions, and shows how to use them in Rust. Chapter 4 explores
ownership, a feature that makes Rust different from other languages. Chapter 5
discusses structs and method syntax, and Chapter 6 explains how enums work.
+
diff --git a/src/doc/book/nostarch/chapter03.md b/src/doc/book/nostarch/chapter03.md
index 281f31d33..249032fd7 100644
--- a/src/doc/book/nostarch/chapter03.md
+++ b/src/doc/book/nostarch/chapter03.md
@@ -18,19 +18,19 @@ Specifically, you’ll learn about variables, basic types, functions, comments,
and control flow. These foundations will be in every Rust program, and learning
them early will give you a strong core to start from.
-> #### Keywords
+> ### Keywords
>
-> The Rust language has a set of *keywords* that are reserved for use by
-> the language only, much as in other languages. Keep in mind that you cannot
-> use these words as names of variables or functions. Most of the keywords have
-> special meanings, and you’ll be using them to do various tasks in your Rust
-> programs; a few have no current functionality associated with them but have
-> been reserved for functionality that might be added to Rust in the future. You
-> can find a list of the keywords in Appendix A.
+> The Rust language has a set of *keywords* that are reserved for use by the
+language only, much as in other languages. Keep in mind that you cannot use
+these words as names of variables or functions. Most of the keywords have
+special meanings, and you’ll be using them to do various tasks in your Rust
+programs; a few have no current functionality associated with them but have
+been reserved for functionality that might be added to Rust in the future. You
+can find a list of the keywords in Appendix A.
## Variables and Mutability
-As mentioned in the “Storing Values with Variables†section, by default
+As mentioned in “Storing Values with Variables†on page XX, by default,
variables are immutable. This is one of many nudges Rust gives you to write
your code in a way that takes advantage of the safety and easy concurrency that
Rust offers. However, you still have the option to make your variables mutable.
@@ -38,12 +38,11 @@ Let’s explore how and why Rust encourages you to favor immutability and why
sometimes you might want to opt out.
When a variable is immutable, once a value is bound to a name, you can’t change
-that value. To illustrate this, let’s generate a new project called *variables*
-in your *projects* directory by using `cargo new variables`.
+that value. To illustrate this, generate a new project called *variables* in
+your *projects* directory by using `cargo new variables`.
Then, in your new *variables* directory, open *src/main.rs* and replace its
-code with the following code. This code won’t compile just yet, we’ll first
-examine the immutability error.
+code with the following code, which won’t compile just yet:
Filename: src/main.rs
@@ -56,8 +55,8 @@ fn main() {
}
```
-Save and run the program using `cargo run`. You should receive an error
-message, as shown in this output:
+Save and run the program using `cargo run`. You should receive an error message
+regarding an immutability error, as shown in this output:
```
$ cargo run
@@ -80,9 +79,8 @@ Compiler errors can be frustrating, but really they only mean your program
isn’t safely doing what you want it to do yet; they do *not* mean that you’re
not a good programmer! Experienced Rustaceans still get compiler errors.
-The error message indicates that the cause of the error is that you `` cannot
-assign twice to immutable variable `x` ``, because you tried to assign a second
-value to the immutable `x` variable.
+You received the error message `cannot assign twice to immutable variable `x``
+because you tried to assign a second value to the immutable `x` variable.
It’s important that we get compile-time errors when we attempt to change a
value that’s designated as immutable because this very situation can lead to
@@ -91,15 +89,15 @@ never change and another part of our code changes that value, it’s possible
that the first part of the code won’t do what it was designed to do. The cause
of this kind of bug can be difficult to track down after the fact, especially
when the second piece of code changes the value only *sometimes*. The Rust
-compiler guarantees that when you state a value won’t change, it really won’t
-change, so you don’t have to keep track of it yourself. Your code is thus
+compiler guarantees that when you state that a value won’t change, it really
+won’t change, so you don’t have to keep track of it yourself. Your code is thus
easier to reason through.
But mutability can be very useful, and can make code more convenient to write.
-Variables are immutable only by default; as you did in Chapter 2, you can make
-them mutable by adding `mut` in front of the variable name. Adding `mut` also
-conveys intent to future readers of the code by indicating that other parts of
-the code will be changing this variable’s value.
+Although variables are immutable by default, you can make them mutable by
+adding `mut` in front of the variable name as you did in Chapter 2. Adding
+`mut` also conveys intent to future readers of the code by indicating that
+other parts of the code will be changing this variable’s value.
For example, let’s change *src/main.rs* to the following:
@@ -125,18 +123,10 @@ The value of x is: 5
The value of x is: 6
```
-We’re allowed to change the value bound to `x` from `5` to `6` when `mut`
-is used. Ultimately, deciding whether to use mutability or not is up to you and
+We’re allowed to change the value bound to `x` from `5` to `6` when `mut` is
+used. Ultimately, deciding whether to use mutability or not is up to you and
depends on what you think is clearest in that particular situation.
-<!--- Just to voice some thoughts here: there's a kind of bad pattern I see sometimes
-with the Rust dev mindset around performance. In my experience it happens maybe less
-often than you'd think that cloning shows up in the profile as a performance hit. I
-wonder if we should maybe tone down or remove the discussion of performance above
-because it's far stronger for the developer to pick a clear representation for their
-program and then improve performance after they've found that model. /JT --->
-<!-- Ok, I've removed the discussion of performance here. Good call. /Carol -->
-
### Constants
Like immutable variables, *constants* are values that are bound to a name and
@@ -146,9 +136,9 @@ and variables.
First, you aren’t allowed to use `mut` with constants. Constants aren’t just
immutable by default—they’re always immutable. You declare constants using the
`const` keyword instead of the `let` keyword, and the type of the value *must*
-be annotated. We’re about to cover types and type annotations in the next
-section, “Data Types,†so don’t worry about the details right now. Just know
-that you must always annotate the type.
+be annotated. We’ll cover types and type annotations in “Data Types†on page
+XX, so don’t worry about the details right now. Just know that you must always
+annotate the type.
Constants can be declared in any scope, including the global scope, which makes
them useful for values that many parts of code need to know about.
@@ -169,15 +159,15 @@ program). Rust’s naming convention for constants is to use all uppercase with
underscores between words. The compiler is able to evaluate a limited set of
operations at compile time, which lets us choose to write out this value in a
way that’s easier to understand and verify, rather than setting this constant
-to the value 10,800. See the Rust Reference’s section on constant evaluation at
-*https://doc.rust-lang.org/reference/const_eval.html* for more information on
-what operations can be used when declaring constants.
+to the value `10,800`. See the Rust Reference’s section on constant evaluation
+at *https://doc.rust-lang.org/reference/const_eval.html* for more information
+on what operations can be used when declaring constants.
-Constants are valid for the entire time a program runs, within the scope they
-were declared in. This property makes constants useful for values in your
-application domain that multiple parts of the program might need to know about,
-such as the maximum number of points any player of a game is allowed to earn or
-the speed of light.
+Constants are valid for the entire time a program runs, within the scope in
+which they were declared. This property makes constants useful for values in
+your application domain that multiple parts of the program might need to know
+about, such as the maximum number of points any player of a game is allowed to
+earn, or the speed of light.
Naming hardcoded values used throughout your program as constants is useful in
conveying the meaning of that value to future maintainers of the code. It also
@@ -195,21 +185,6 @@ variable name to itself until either it itself is shadowed or the scope ends.
We can shadow a variable by using the same variable’s name and repeating the
use of the `let` keyword as follows:
-<!--- A potential reword of the above for clarity:
-
-As you saw in the guessing game tutorial in Chapter 2, you can declare a new
-variable with the same name as a previous variable. Rustaceans say that the
-first variable is *shadowed* by the second, which means that the second
-variable is what the compiler will see when you use the name of the variable.
-In effect, the second variable overshadows the first, taking any uses of the
-variable name to itself until either it itself is shadowed or the scope ends.
-We can shadow a variable by using the same variable’s name and repeating the
-use of the `let` keyword as follows:
-
-/JT --->
-<!-- Sounds good to me, I've made the change to JT's version. What do you
-think, Liz? /Carol -->
-
Filename: src/main.rs
```
@@ -226,17 +201,6 @@ fn main() {
println!("The value of x is: {x}");
}
```
-<!--- We haven't really introduced block scoping yet. I know we're starting
-with variables, but I wonder if we should introduce scopes before shadowing,
-or explain that each block has its own set of variables.
-/JT --->
-<!-- Chapter 4 goes into scopes in more detail. I feel like block scoping is a
-pretty common programming concept, and the behavior of scopes in Rust that
-we're demonstrating here is the same behavior as scopes have in most other
-common programming languages. I don't recall getting comments from readers
-being confused about scopes at this point. I added a small phrase in the next
-paragraph that the curly brackets are creating a new scope... do you think
-that's enough, Liz? /Carol -->
This program first binds `x` to a value of `5`. Then it creates a new variable
`x` by repeating `let x =`, taking the original value and adding `1` so the
@@ -246,10 +210,6 @@ variable, multiplying the previous value by `2` to give `x` a value of `12`.
When that scope is over, the inner shadowing ends and `x` returns to being `6`.
When we run this program, it will output the following:
-<!--- I lean towards reiterating that each `let x` is creating a new variable.
-/JT -->
-<!-- I've added a few mentions to that effect in the previous paragraph, what do you think, Liz? /Carol -->
-
```
$ cargo run
Compiling variables v0.1.0 (file:///projects/variables)
@@ -259,46 +219,21 @@ The value of x in the inner scope is: 12
The value of x is: 6
```
-Shadowing is different from marking a variable as `mut`, because we’ll get a
+Shadowing is different from marking a variable as `mut` because we’ll get a
compile-time error if we accidentally try to reassign to this variable without
using the `let` keyword. By using `let`, we can perform a few transformations
on a value but have the variable be immutable after those transformations have
been completed.
-<!--- so, to be clear, we're not overwriting the variable, so when the
-shadowing variable goes out of scope the earlier variables become visible to
-the compiler? --->
-<!-- Well, we *are* overwriting it *in the inner scope* -- there's no way to
-access the original value from the outer scope within the inner scope after
-the shadowing. But yes, shadowing only applies to the scope it happens in,
-which is what this example illustrates. Is there something that could be
-made clearer? /Carol -->
-<!-- JT, what do you think, is this clear enough as is or is there some way to clarify in the text? /LC -->
-<!--- I made a couple notes above trying to see if we could tease out a good
-explanation. Shadowing is effectively creating new variables and then these
-variables get a kind of "higher priority" when you look up the same variable
-name. Shadowing priority is kind of a "most recent wins", and it stays until
-that variable is shadowed by a following one or that variable goes out of scope.
-/JT -->
-
The other difference between `mut` and shadowing is that because we’re
effectively creating a new variable when we use the `let` keyword again, we can
change the type of the value but reuse the same name. For example, say our
program asks a user to show how many spaces they want between some text by
inputting space characters, and then we want to store that input as a number:
-<!--- Question: the further I read, the more I wonder if we should put the shadowing
-stuff later. Is it valuable here as a kind of "building the right mental model" or
-are we using up too much of our complexity budget for building that mental model
-relatively early in the journey? Once we're introducing shadowing into new types
-we're getting relatively deep into Rust-specific coding patterns /JT -->
-<!-- I think it's important to address this here because shadowing is extremely
-common in idiomatic Rust code, but can be unfamiliar. I'm not sure where it
-would be appropriate to address if not here. /Carol -->
-
```
- let spaces = " ";
- let spaces = spaces.len();
+let spaces = " ";
+let spaces = spaces.len();
```
The first `spaces` variable is a string type and the second `spaces` variable
@@ -308,8 +243,8 @@ the simpler `spaces` name. However, if we try to use `mut` for this, as shown
here, we’ll get a compile-time error:
```
- let mut spaces = " ";
- spaces = spaces.len();
+let mut spaces = " ";
+spaces = spaces.len();
```
The error says we’re not allowed to mutate a variable’s type:
@@ -339,20 +274,16 @@ Keep in mind that Rust is a *statically typed* language, which means that it
must know the types of all variables at compile time. The compiler can usually
infer what type we want to use based on the value and how we use it. In cases
when many types are possible, such as when we converted a `String` to a numeric
-type using `parse` in the “Comparing the Guess to the Secret Number†section in
-Chapter 2, we must add a type annotation, like this:
+type using `parse` in “Comparing the Guess to the Secret Number†on page XX, we
+must add a type annotation, like this:
```
let guess: u32 = "42".parse().expect("Not a number!");
```
-If we don’t add the `: u32` type annotation above, Rust will display the
-following error, which means the compiler needs more information from us to
-know which type we want to use:
-
-<!--- To help visual parsing, you might want to say "If we don't add the `: u32` type
-annotation above... /JT --->
-<!-- Done /Carol -->
+If we don’t add the `: u32` type annotation shown in the preceding code, Rust
+will display the following error, which means the compiler needs more
+information from us to know which type we want to use:
```
$ cargo build
@@ -377,20 +308,20 @@ these from other programming languages. Let’s jump into how they work in Rust.
An *integer* is a number without a fractional component. We used one integer
type in Chapter 2, the `u32` type. This type declaration indicates that the
value it’s associated with should be an unsigned integer (signed integer types
-start with `i`, instead of `u`) that takes up 32 bits of space. Table 3-1 shows
+start with `i` instead of `u`) that takes up 32 bits of space. Table 3-1 shows
the built-in integer types in Rust. We can use any of these variants to declare
the type of an integer value.
Table 3-1: Integer Types in Rust
-| Length | Signed | Unsigned |
-|---------|---------|----------|
-| 8-bit | `i8` | `u8` |
-| 16-bit | `i16` | `u16` |
-| 32-bit | `i32` | `u32` |
-| 64-bit | `i64` | `u64` |
-| 128-bit | `i128` | `u128` |
-| arch | `isize` | `usize` |
+| Length | Signed | Unsigned |
+|---|---|---|
+| 8-bit | `i8` | `u8` |
+| 16-bit | `i16` | `u16` |
+| 32-bit | `i32` | `u32` |
+| 64-bit | `i64` | `u64` |
+| 128-bit | `i128` | `u128` |
+| arch | `isize` | `usize` |
Each variant can be either signed or unsigned and has an explicit size.
*Signed* and *unsigned* refer to whether it’s possible for the number to be
@@ -420,55 +351,54 @@ have the same value as if you had specified `1000`.
Table 3-2: Integer Literals in Rust
-| Number literals | Example |
-|------------------|---------------|
-| Decimal | `98_222` |
-| Hex | `0xff` |
-| Octal | `0o77` |
-| Binary | `0b1111_0000` |
-| Byte (`u8` only) | `b'A'` |
+| Number literals | Example |
+|---|---|
+| Decimal | `98_222` |
+| Hex | `0xff` |
+| Octal | `0o77` |
+| Binary | `0b1111_0000` |
+| Byte (`u8` only) | `b'A'` |
So how do you know which type of integer to use? If you’re unsure, Rust’s
defaults are generally good places to start: integer types default to `i32`.
The primary situation in which you’d use `isize` or `usize` is when indexing
some sort of collection.
-> ##### Integer Overflow
+> ### Integer Overflow
>
> Let’s say you have a variable of type `u8` that can hold values between 0 and
-> 255. If you try to change the variable to a value outside of that range, such
-> as 256, *integer overflow* will occur, which can result in one of two
-> behaviors. When you’re compiling in debug mode, Rust includes checks for
-> integer overflow that cause your program to *panic* at runtime if this
-> behavior occurs. Rust uses the term panicking when a program exits with an
-> error; we’ll discuss panics in more depth in the “Unrecoverable Errors with
-> `panic!`†section in Chapter 9.
+255. If you try to change the variable to a value outside that range, such as
+256, *integer overflow* will occur, which can result in one of two behaviors.
+When you’re compiling in debug mode, Rust includes checks for integer overflow
+that cause your program to *panic* at runtime if this behavior occurs. Rust
+uses the term *panicking* when a program exits with an error; we’ll discuss
+panics in more depth in “Unrecoverable Errors with panic!†on page XX.
>
> When you’re compiling in release mode with the `--release` flag, Rust does
-> *not* include checks for integer overflow that cause panics. Instead, if
-> overflow occurs, Rust performs *two’s complement wrapping*. In short, values
-> greater than the maximum value the type can hold “wrap around†to the minimum
-> of the values the type can hold. In the case of a `u8`, the value 256 becomes
-> 0, the value 257 becomes 1, and so on. The program won’t panic, but the
-> variable will have a value that probably isn’t what you were expecting it to
-> have. Relying on integer overflow’s wrapping behavior is considered an error.
+*not* include checks for integer overflow that cause panics. Instead, if
+overflow occurs, Rust performs *two’s complement wrapping*. In short, values
+greater than the maximum value the type can hold “wrap around†to the minimum
+of the values the type can hold. In the case of a `u8`, the value 256 becomes
+0, the value 257 becomes 1, and so on. The program won’t panic, but the
+variable will have a value that probably isn’t what you were expecting it to
+have. Relying on integer overflow’s wrapping behavior is considered an error.
>
> To explicitly handle the possibility of overflow, you can use these families
-> of methods provided by the standard library for primitive numeric types:
+of methods provided by the standard library for primitive numeric types:
>
-> - Wrap in all modes with the `wrapping_*` methods, such as `wrapping_add`
-> - Return the `None` value if there is overflow with the `checked_*` methods
-> - Return the value and a boolean indicating whether there was overflow with
-> the `overflowing_*` methods
-> - Saturate at the value’s minimum or maximum values with `saturating_*`
-> methods
+> * Wrap in all modes with the `wrapping_*` methods, such as `wrapping_add`.
+> * Return the `None` value if there is overflow with the `checked_*` methods.
+> * Return the value and a boolean indicating whether there was overflow with
+the `overflowing_*` methods.
+> * Saturate at the value’s minimum or maximum values with the `saturating_*`
+methods.
#### Floating-Point Types
Rust also has two primitive types for *floating-point numbers*, which are
numbers with decimal points. Rust’s floating-point types are `f32` and `f64`,
which are 32 bits and 64 bits in size, respectively. The default type is `f64`
-because on modern CPUs it’s roughly the same speed as `f32` but is capable of
+because on modern CPUs, it’s roughly the same speed as `f32` but is capable of
more precision. All floating-point types are signed.
Here’s an example that shows floating-point numbers in action:
@@ -488,9 +418,9 @@ Floating-point numbers are represented according to the IEEE-754 standard. The
#### Numeric Operations
-Rust supports the basic mathematical operations you’d expect for all of the
-number types: addition, subtraction, multiplication, division, and remainder.
-Integer division rounds down to the nearest integer. The following code shows
+Rust supports the basic mathematical operations you’d expect for all the number
+types: addition, subtraction, multiplication, division, and remainder. Integer
+division truncates toward zero to the nearest integer. The following code shows
how you’d use each numeric operation in a `let` statement:
Filename: src/main.rs
@@ -508,7 +438,7 @@ fn main() {
// division
let quotient = 56.7 / 32.2;
- let floored = 2 / 3; // Results in 0
+ let truncated = -5 / 3; // Results in -1
// remainder
let remainder = 43 % 5;
@@ -536,12 +466,12 @@ fn main() {
```
The main way to use Boolean values is through conditionals, such as an `if`
-expression. We’ll cover how `if` expressions work in Rust in the “Control
-Flow†section.
+expression. We’ll cover how `if` expressions work in Rust in “Control Flow†on
+page XX.
#### The Character Type
-Rust’s `char` type is the language’s most primitive alphabetic type. Here’s
+Rust’s `char` type is the language’s most primitive alphabetic type. Here are
some examples of declaring `char` values:
Filename: src/main.rs
@@ -563,7 +493,7 @@ Values range from `U+0000` to `U+D7FF` and `U+E000` to `U+10FFFF` inclusive.
However, a “character†isn’t really a concept in Unicode, so your human
intuition for what a “character†is may not match up with what a `char` is in
Rust. We’ll discuss this topic in detail in “Storing UTF-8 Encoded Text with
-Strings†in Chapter 8.
+Strings†on page XX.
### Compound Types
@@ -572,9 +502,9 @@ primitive compound types: tuples and arrays.
#### The Tuple Type
-A tuple is a general way of grouping together a number of values with a variety
-of types into one compound type. Tuples have a fixed length: once declared,
-they cannot grow or shrink in size.
+A *tuple* is a general way of grouping together a number of values with a
+variety of types into one compound type. Tuples have a fixed length: once
+declared, they cannot grow or shrink in size.
We create a tuple by writing a comma-separated list of values inside
parentheses. Each position in the tuple has a type, and the types of the
@@ -589,7 +519,7 @@ fn main() {
}
```
-The variable `tup` binds to the entire tuple, because a tuple is considered a
+The variable `tup` binds to the entire tuple because a tuple is considered a
single compound element. To get the individual values out of a tuple, we can
use pattern matching to destructure a tuple value, like this:
@@ -607,7 +537,7 @@ fn main() {
This program first creates a tuple and binds it to the variable `tup`. It then
uses a pattern with `let` to take `tup` and turn it into three separate
-variables, `x`, `y`, and `z`. This is called *destructuring*, because it breaks
+variables, `x`, `y`, and `z`. This is called *destructuring* because it breaks
the single tuple into three parts. Finally, the program prints the value of
`y`, which is `6.4`.
@@ -632,28 +562,11 @@ This program creates the tuple `x` and then accesses each element of the tuple
using their respective indices. As with most programming languages, the first
index in a tuple is 0.
-<!--- Indexing into a tuple using a constant, just like accessing a field of a struct,
-I think is maybe a more natural way to think of this than thinking of `x.0`, `x.1`, etc
-as separate variables. In the struct case, we don't think of each field as a separate
-variable, but instead that there's a path to get to the contained values that can be
-used and checked at compile time. /JT --->
-<!-- I think JT was actually confused with what this paragraph was trying to
-say, it was explaining that this particular example created new variables and
-bound them to the values of the tuple elements, not that the tuple elements
-*were* separate variables, so I've reworded this paragraph. Please check that
-this makes sense, Liz! /Carol -->
-
The tuple without any values has a special name, *unit*. This value and its
corresponding type are both written `()` and represent an empty value or an
empty return type. Expressions implicitly return the unit value if they don’t
return any other value.
-<!--- It's trick to see the difference between `()` and `()`. Maybe we can say: "The
-tuple without any values has a special name, *unit*. This value, and its corresponding
-type -- also written `()` -- represent an empty value or an empty return type." /JT --->
-<!-- I've tried to clear this up, but didn't take JT's suggestion exactly,
-there were too many subphrases in my opinion /Carol -->
-
#### The Array Type
Another way to have a collection of multiple values is with an *array*. Unlike
@@ -674,7 +587,7 @@ fn main() {
Arrays are useful when you want your data allocated on the stack rather than
the heap (we will discuss the stack and the heap more in Chapter 4) or when you
want to ensure you always have a fixed number of elements. An array isn’t as
-flexible as the vector type, though. A vector is a similar collection type
+flexible as the vector type, though. A *vector* is a similar collection type
provided by the standard library that *is* allowed to grow or shrink in size.
If you’re unsure whether to use an array or a vector, chances are you should
use a vector. Chapter 8 discusses vectors in more detail.
@@ -711,7 +624,7 @@ The array named `a` will contain `5` elements that will all be set to the value
`3` initially. This is the same as writing `let a = [3, 3, 3, 3, 3];` but in a
more concise way.
-##### Accessing Array Elements
+#### Accessing Array Elements
An array is a single chunk of memory of a known, fixed size that can be
allocated on the stack. You can access elements of an array using indexing,
@@ -728,11 +641,11 @@ fn main() {
}
```
-In this example, the variable named `first` will get the value `1`, because
-that is the value at index `[0]` in the array. The variable named `second` will
-get the value `2` from index `[1]` in the array.
+In this example, the variable named `first` will get the value `1` because that
+is the value at index `[0]` in the array. The variable named `second` will get
+the value `2` from index `[1]` in the array.
-##### Invalid Array Element Access
+#### Invalid Array Element Access
Let’s see what happens if you try to access an element of an array that is past
the end of the array. Say you run this code, similar to the guessing game in
@@ -768,12 +681,13 @@ fn main() {
```
This code compiles successfully. If you run this code using `cargo run` and
-enter 0, 1, 2, 3, or 4, the program will print out the corresponding value at
-that index in the array. If you instead enter a number past the end of the
-array, such as 10, you’ll see output like this:
+enter `0`, `1`, `2`, `3`, or `4`, the program will print out the corresponding
+value at that index in the array. If you instead enter a number past the end of
+the array, such as `10`, you’ll see output like this:
```
-thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 10', src/main.rs:19:19
+thread 'main' panicked at 'index out of bounds: the len is 5 but the index is
+10', src/main.rs:19:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
@@ -793,13 +707,6 @@ kind of error by immediately exiting instead of allowing the memory access and
continuing. Chapter 9 discusses more of Rust’s error handling and how you can
write readable, safe code that neither panics nor allows invalid memory access.
-<!--- I get the idea, though I'm feeling a little uneasy with leaving the reader
-thinking "panic > invalid access" as the end of the story. Maybe we can tag something
-on to the end: "Chapter 9 discusses more of Rust's error handling, and how you can
-write readable, safe code that doesn't panic and doesn't allow invalid memory access.
-/JT --->
-<!-- I've incorporated JT's suggestion with a bit of rewording above /Carol -->
-
## Functions
Functions are prevalent in Rust code. You’ve already seen one of the most
@@ -836,14 +743,6 @@ called from inside the `main` function. Note that we defined `another_function`
as well. Rust doesn’t care where you define your functions, only that they’re
defined somewhere in a scope that can be seen by the caller.
-<!--- nit: Rust does want the functions in a place the caller can see. If they're
-not in scope, Rust won't let the program build. Maybe we can say:
-"only that they're defined somewhere the caller can see them".
-or alt: "only that they're defined somewhere in a scope that can be seen by the
-caller"
-/JT --->
-<!-- Done! /Carol -->
-
Let’s start a new binary project named *functions* to explore functions
further. Place the `another_function` example in *src/main.rs* and run it. You
should see the following output:
@@ -858,8 +757,8 @@ Another function.
```
The lines execute in the order in which they appear in the `main` function.
-First, the “Hello, world!†message prints, and then `another_function` is
-called and its message is printed.
+First the “Hello, world!†message prints, and then `another_function` is called
+and its message is printed.
### Parameters
@@ -885,9 +784,6 @@ fn another_function(x: i32) {
}
```
-<!--- nit: might want to use `{x}` /JT --->
-<!-- Done! /Carol -->
-
Try running this program; you should get the following output:
```
@@ -909,9 +805,6 @@ definitions means the compiler almost never needs you to use them elsewhere in
the code to figure out what type you mean. The compiler is also able to give
more helpful error messages if it knows what types the function expects.
-<!--- Also helps give much better error messages /JT --->
-<!-- Added a note! /Carol -->
-
When defining multiple parameters, separate the parameter declarations with
commas, like this:
@@ -957,19 +850,14 @@ understand. Other languages don’t have the same distinctions, so let’s look
what statements and expressions are and how their differences affect the bodies
of functions.
-*Statements* are instructions that perform some action and do not return a
-value. *Expressions* evaluate to a resulting value. Let’s look at some examples.
+* **Statements **: are instructions that perform some action and do not return
+a value.
+* **Expressions **: evaluate to a resultant value. Let’s look at some examples.
We’ve actually already used statements and expressions. Creating a variable and
assigning a value to it with the `let` keyword is a statement. In Listing 3-1,
`let y = 6;` is a statement.
-<!--- To help clarify how they're related, we could say that "`let y = 6;`" is a
-statement, and the `6` being assigned to `y` is an expression. edit: I see we
-say this later, just thought it might be a little nicer to give an examples of
-each just following their definition. /JT --->
-<!-- I think I'm going to leave this as-is /Carol -->
-
Filename: src/main.rs
```
@@ -1007,33 +895,16 @@ error: expected expression, found statement (`let`)
|
= note: variable declaration using `let` is a statement
-error[E0658]: `let` expressions in this position are experimental
+error[E0658]: `let` expressions in this position are unstable
--> src/main.rs:2:14
|
2 | let x = (let y = 6);
| ^^^^^^^^^
|
- = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
- = help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
-
-warning: unnecessary parentheses around assigned value
- --> src/main.rs:2:13
- |
-2 | let x = (let y = 6);
- | ^ ^
- |
- = note: `#[warn(unused_parens)]` on by default
-help: remove these parentheses
- |
-2 - let x = (let y = 6);
-2 + let x = let y = 6;
- |
+ = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for
+more information
```
-<!--- The errors in more recent Rust look slightly different here, if we want
-to update before publication. /JT --->
-<!-- Updated here and I will also check when we're in Word /Carol -->
-
The `let y = 6` statement does not return a value, so there isn’t anything for
`x` to bind to. This is different from what happens in other languages, such as
C and Ruby, where the assignment returns the value of the assignment. In those
@@ -1052,30 +923,22 @@ Filename: src/main.rs
```
fn main() {
- let y = {
+ 1 let y = {2
let x = 3;
- x + 1
+ 3 x + 1
};
println!("The value of y is: {y}");
}
```
-This expression:
-
-```
-{
- let x = 3;
- x + 1
-}
-```
-
-is a block that, in this case, evaluates to `4`. That value gets bound to `y`
-as part of the `let` statement. Note that the `x + 1` line doesn’t have a
-semicolon at the end, unlike most of the lines you’ve seen so far. Expressions
-do not include ending semicolons. If you add a semicolon to the end of an
-expression, you turn it into a statement, and it will then not return a value.
-Keep this in mind as you explore function return values and expressions next.
+The expression [2] is a block that, in this case, evaluates to `4`. That value
+gets bound to `y` as part of the `let` statement [1]. Note the line without a
+semicolon at the end [3], which is unlike most of the lines you’ve seen so far.
+Expressions do not include ending semicolons. If you add a semicolon to the end
+of an expression, you turn it into a statement, and it will then not return a
+value. Keep this in mind as you explore function return values and expressions
+next.
### Functions with Return Values
@@ -1128,10 +991,6 @@ Second, the `five` function has no parameters and defines the type of the
return value, but the body of the function is a lonely `5` with no semicolon
because it’s an expression whose value we want to return.
-<!--- If you want, you could point out that the `println!` line that main ends
-on is a statement, hence why main doesn't have a return value. /JT --->
-<!-- I don't think I want to :) /Carol -->
-
Let’s look at another example:
Filename: src/main.rs
@@ -1150,7 +1009,7 @@ fn plus_one(x: i32) -> i32 {
Running this code will print `The value of x is: 6`. But if we place a
semicolon at the end of the line containing `x + 1`, changing it from an
-expression to a statement, we’ll get an error.
+expression to a statement, we’ll get an error:
Filename: src/main.rs
@@ -1179,10 +1038,10 @@ error[E0308]: mismatched types
| |
| implicitly returns `()` as its body has no tail or `return` expression
8 | x + 1;
- | - help: consider removing this semicolon
+ | - help: remove this semicolon
```
-The main error message, “mismatched types,†reveals the core issue with this
+The main error message, `mismatched types`, reveals the core issue with this
code. The definition of the function `plus_one` says that it will return an
`i32`, but statements don’t evaluate to a value, which is expressed by `()`,
the unit type. Therefore, nothing is returned, which contradicts the function
@@ -1236,16 +1095,16 @@ fn main() {
```
Rust also has another kind of comment, documentation comments, which we’ll
-discuss in the “Publishing a Crate to Crates.io†section of Chapter 14.
+discuss in “Publishing a Crate to Crates.io†on page XX.
## Control Flow
-The ability to run some code depending on if a condition is true, or run some
-code repeatedly while a condition is true, are basic building blocks in most
-programming languages. The most common constructs that let you control the flow
-of execution of Rust code are `if` expressions and loops.
+The ability to run some code depending on whether a condition is `true` and to
+run some code repeatedly while a condition is `true` are basic building blocks
+in most programming languages. The most common constructs that let you control
+the flow of execution of Rust code are `if` expressions and loops.
-### `if` Expressions
+### if Expressions
An `if` expression allows you to branch your code depending on conditions. You
provide a condition and then state, “If this condition is met, run this block
@@ -1270,16 +1129,16 @@ fn main() {
All `if` expressions start with the keyword `if`, followed by a condition. In
this case, the condition checks whether or not the variable `number` has a
-value less than 5. We place the block of code to execute if the condition is true
-immediately after the condition inside curly brackets. Blocks of code
+value less than 5. We place the block of code to execute if the condition is
+`true` immediately after the condition inside curly brackets. Blocks of code
associated with the conditions in `if` expressions are sometimes called *arms*,
-just like the arms in `match` expressions that we discussed in the “Comparing
-the Guess to the Secret Number†section of Chapter 2.
+just like the arms in `match` expressions that we discussed in “Comparing the
+Guess to the Secret Number†on page XX.
-Optionally, we can also include an `else` expression, which we chose
-to do here, to give the program an alternative block of code to execute should
-the condition evaluate to false. If you don’t provide an `else` expression and
-the condition is false, the program will just skip the `if` block and move on
+Optionally, we can also include an `else` expression, which we chose to do
+here, to give the program an alternative block of code to execute should the
+condition evaluate to `false`. If you don’t provide an `else` expression and
+the condition is `false`, the program will just skip the `if` block and move on
to the next bit of code.
Try running this code; you should see the following output:
@@ -1359,7 +1218,7 @@ fn main() {
Running this code will print `number was something other than zero`.
-#### Handling Multiple Conditions with `else if`
+#### Handling Multiple Conditions with else if
You can use multiple conditions by combining `if` and `else` in an `else if`
expression. For example:
@@ -1394,17 +1253,17 @@ number is divisible by 3
```
When this program executes, it checks each `if` expression in turn and executes
-the first body for which the condition holds true. Note that even though 6 is
-divisible by 2, we don’t see the output `number is divisible by 2`, nor do we
-see the `number is not divisible by 4, 3, or 2` text from the `else` block.
-That’s because Rust only executes the block for the first true condition, and
-once it finds one, it doesn’t even check the rest.
+the first body for which the condition evaluates to `true`. Note that even
+though 6 is divisible by 2, we don’t see the output `number is divisible by 2`,
+nor do we see the `number is not divisible by 4, 3, or 2` text from the `else`
+block. That’s because Rust only executes the block for the first `true`
+condition, and once it finds one, it doesn’t even check the rest.
Using too many `else if` expressions can clutter your code, so if you have more
than one, you might want to refactor your code. Chapter 6 describes a powerful
Rust branching construct called `match` for these cases.
-#### Using `if` in a `let` Statement
+#### Using if in a let Statement
Because `if` is an expression, we can use it on the right side of a `let`
statement to assign the outcome to a variable, as in Listing 3-2.
@@ -1420,19 +1279,8 @@ fn main() {
}
```
-<!--- Style nit: `{number}`. /JT --->
-<!-- Fixed! /Carol -->
-
Listing 3-2: Assigning the result of an `if` expression to a variable
-<!--- I was wondering when listings got numbered and when they didn't. Many of
-the above don't get a number a title, though maybe it'd help readability? /JT --->
-<!-- Liz: Chapter 3 doesn't have many listing numbers because on the first
-round of printing, we hadn't really figured out what we were doing with listing
-numbers yet. I'm happy to add more listing numbers in Chapter 3, but it'll take
-me some time to go through and add appropriate captions, check cross
-references, etc. Let me know if you'd like me to spend that time. /Carol -->
-
The `number` variable will be bound to a value based on the outcome of the `if`
expression. Run this code to see what happens:
@@ -1475,7 +1323,8 @@ error[E0308]: `if` and `else` have incompatible types
--> src/main.rs:4:44
|
4 | let number = if condition { 5 } else { "six" };
- | - ^^^^^ expected integer, found `&str`
+ | - ^^^^^ expected integer, found
+`&str`
| |
| expected because of this
```
@@ -1493,12 +1342,12 @@ if it had to keep track of multiple hypothetical types for any variable.
It’s often useful to execute a block of code more than once. For this task,
Rust provides several *loops*, which will run through the code inside the loop
-body to the end and then start immediately back at the beginning. To
-experiment with loops, let’s make a new project called *loops*.
+body to the end and then start immediately back at the beginning. To experiment
+with loops, let’s make a new project called *loops*.
Rust has three kinds of loops: `loop`, `while`, and `for`. Let’s try each one.
-#### Repeating Code with `loop`
+#### Repeating Code with loop
The `loop` keyword tells Rust to execute a block of code over and over again
forever or until you explicitly tell it to stop.
@@ -1517,9 +1366,9 @@ fn main() {
```
When we run this program, we’ll see `again!` printed over and over continuously
-until we stop the program manually. Most terminals support the keyboard shortcut
-<span class="keystroke">ctrl-c</span> to interrupt a program that is stuck in
-a continual loop. Give it a try:
+until we stop the program manually. Most terminals support the keyboard
+shortcut ctrl-C to interrupt a program that is stuck in a continual loop. Give
+it a try:
```
$ cargo run
@@ -1533,25 +1382,20 @@ again!
^Cagain!
```
-The symbol `^C` represents where you pressed <span class="keystroke">ctrl-c
-</span>. You may or may not see the word `again!` printed after the `^C`,
-depending on where the code was in the loop when it received the interrupt
-signal.
+The symbol `^C` represents where you pressed ctrl-C. You may or may not see the
+word `again!` printed after the `^C`, depending on where the code was in the
+loop when it received the interrupt signal.
Fortunately, Rust also provides a way to break out of a loop using code. You
can place the `break` keyword within the loop to tell the program when to stop
-executing the loop. Recall that we did this in the guessing game in the
-“Quitting After a Correct Guess†section of Chapter 2 to exit the program when
-the user won the game by guessing the correct number.
+executing the loop. Recall that we did this in the guessing game in “Quitting
+After a Correct Guess†on page XX to exit the program when the user won the
+game by guessing the correct number.
We also used `continue` in the guessing game, which in a loop tells the program
to skip over any remaining code in this iteration of the loop and go to the
next iteration.
-<!--- Before you show loop labels below, you might want to give a code example
-of using `break` to break a loop. /JT --->
-<!-- I've rearranged the sections to take this suggestion here /Carol -->
-
#### Returning Values from Loops
One of the uses of a `loop` is to retry an operation you know might fail, such
@@ -1580,20 +1424,18 @@ fn main() {
Before the loop, we declare a variable named `counter` and initialize it to
`0`. Then we declare a variable named `result` to hold the value returned from
the loop. On every iteration of the loop, we add `1` to the `counter` variable,
-and then check whether the counter is equal to `10`. When it is, we use the
+and then check whether the `counter` is equal to `10`. When it is, we use the
`break` keyword with the value `counter * 2`. After the loop, we use a
semicolon to end the statement that assigns the value to `result`. Finally, we
-print the value in `result`, which in this case is 20.
+print the value in `result`, which in this case is `20`.
#### Loop Labels to Disambiguate Between Multiple Loops
-<!-- Liz: New heading for this section, what do you think? /Carol -->
-
If you have loops within loops, `break` and `continue` apply to the innermost
-loop at that point. You can optionally specify a *loop label* on a loop that we
-can then use with `break` or `continue` to specify that those keywords apply to
-the labeled loop instead of the innermost loop. Loop labels must begin with a
-single quote. Here’s an example with two nested loops:
+loop at that point. You can optionally specify a *loop label* on a loop that
+you can then use with `break` or `continue` to specify that those keywords
+apply to the labeled loop instead of the innermost loop. Loop labels must begin
+with a single quote. Here’s an example with two nested loops:
```
fn main() {
@@ -1639,10 +1481,10 @@ remaining = 10
End count = 2
```
-#### Conditional Loops with `while`
+#### Conditional Loops with while
A program will often need to evaluate a condition within a loop. While the
-condition is true, the loop runs. When the condition ceases to be true, the
+condition is `true`, the loop runs. When the condition ceases to be `true`, the
program calls `break`, stopping the loop. It’s possible to implement behavior
like this using a combination of `loop`, `if`, `else`, and `break`; you could
try that now in a program, if you’d like. However, this pattern is so common
@@ -1666,13 +1508,14 @@ fn main() {
}
```
-Listing 3-3: Using a `while` loop to run code while a condition holds true
+Listing 3-3: Using a `while` loop to run code while a condition evaluates to
+`true`
This construct eliminates a lot of nesting that would be necessary if you used
-`loop`, `if`, `else`, and `break`, and it’s clearer. While a condition holds
-true, the code runs; otherwise, it exits the loop.
+`loop`, `if`, `else`, and `break`, and it’s clearer. While a condition
+evaluates to `true`, the code runs; otherwise, it exits the loop.
-#### Looping Through a Collection with `for`
+#### Looping Through a Collection with for
You can choose to use the `while` construct to loop over the elements of a
collection, such as an array. For example, the loop in Listing 3-4 prints each
@@ -1697,8 +1540,8 @@ Listing 3-4: Looping through each element of a collection using a `while` loop
Here, the code counts up through the elements in the array. It starts at index
`0`, and then loops until it reaches the final index in the array (that is,
-when `index < 5` is no longer true). Running this code will print every element
-in the array:
+when `index < 5` is no longer `true`). Running this code will print every
+element in the array:
```
$ cargo run
@@ -1717,8 +1560,8 @@ will reach a value of `5` at some point, the loop stops executing before trying
to fetch a sixth value from the array.
However, this approach is error prone; we could cause the program to panic if
-the index value or test condition are incorrect. For example, if you changed
-the definition of the `a` array to have four elements but forgot to update the
+the index value or test condition is incorrect. For example, if you changed the
+definition of the `a` array to have four elements but forgot to update the
condition to `while index < 4`, the code would panic. It’s also slow, because
the compiler adds runtime code to perform the conditional check of whether the
index is within the bounds of the array on every iteration through the loop.
@@ -1775,15 +1618,16 @@ This code is a bit nicer, isn’t it?
## Summary
-You made it! That was a sizable chapter: you learned about variables, scalar
-and compound data types, functions, comments, `if` expressions, and loops!
-To practice with the concepts discussed in this chapter, try building
-programs to do the following:
+You made it! This was a sizable chapter: you learned about variables, scalar
+and compound data types, functions, comments, `if` expressions, and loops! To
+practice with the concepts discussed in this chapter, try building programs to
+do the following:
* Convert temperatures between Fahrenheit and Celsius.
-* Generate the nth Fibonacci number.
+* Generate the *n*th Fibonacci number.
* Print the lyrics to the Christmas carol “The Twelve Days of Christmas,â€
- taking advantage of the repetition in the song.
+taking advantage of the repetition in the song.
When you’re ready to move on, we’ll talk about a concept in Rust that *doesn’t*
commonly exist in other programming languages: ownership.
+
diff --git a/src/doc/book/nostarch/chapter04.md b/src/doc/book/nostarch/chapter04.md
index cbcad103e..11f7f4944 100644
--- a/src/doc/book/nostarch/chapter04.md
+++ b/src/doc/book/nostarch/chapter04.md
@@ -16,21 +16,15 @@ features: borrowing, slices, and how Rust lays data out in memory.
## What Is Ownership?
-*Ownership* is a set of rules that governs how a Rust program manages memory.
+*Ownership* is a set of rules that govern how a Rust program manages memory.
All programs have to manage the way they use a computer’s memory while running.
-Some languages have garbage collection that regularly looks for no-longer used
+Some languages have garbage collection that regularly looks for no-longer-used
memory as the program runs; in other languages, the programmer must explicitly
allocate and free the memory. Rust uses a third approach: memory is managed
through a system of ownership with a set of rules that the compiler checks. If
any of the rules are violated, the program won’t compile. None of the features
of ownership will slow down your program while it’s running.
-<!--- Minor nit: garbage collection isn't constant, it happens at times specified
-by the collection algorithm. Maybe "Some languages have garbage collection that
-regularly looks for no-longer used memory as the program runs."
-/JT --->
-<!-- Took this suggestion! /Carol -->
-
Because ownership is a new concept for many programmers, it does take some time
to get used to. The good news is that the more experienced you become with Rust
and the rules of the ownership system, the easier you’ll find it to naturally
@@ -44,92 +38,63 @@ strings.
> ### The Stack and the Heap
>
> Many programming languages don’t require you to think about the stack and the
-> heap very often. But in a systems programming language like Rust, whether a
-> value is on the stack or the heap affects how the language behaves and why
-> you have to make certain decisions. Parts of ownership will be described in
-> relation to the stack and the heap later in this chapter, so here is a brief
-> explanation in preparation.
+heap very often. But in a systems programming language like Rust, whether a
+value is on the stack or the heap affects how the language behaves and why you
+have to make certain decisions. Parts of ownership will be described in
+relation to the stack and the heap later in this chapter, so here is a brief
+explanation in preparation.
>
> Both the stack and the heap are parts of memory available to your code to use
-> at runtime, but they are structured in different ways. The stack stores
-> values in the order it gets them and removes the values in the opposite
-> order. This is referred to as *last in, first out*. Think of a stack of
-> plates: when you add more plates, you put them on top of the pile, and when
-> you need a plate, you take one off the top. Adding or removing plates from
-> the middle or bottom wouldn’t work as well! Adding data is called *pushing
-> onto the stack*, and removing data is called *popping off the stack*. All
-> data stored on the stack must have a known, fixed size. Data with an unknown
-> size at compile time or a size that might change must be stored on the heap
-> instead.
+at runtime, but they are structured in different ways. The stack stores values
+in the order it gets them and removes the values in the opposite order. This is
+referred to as *last in, first out*. Think of a stack of plates: when you add
+more plates, you put them on top of the pile, and when you need a plate, you
+take one off the top. Adding or removing plates from the middle or bottom
+wouldn’t work as well! Adding data is called *pushing onto the stack*, and
+removing data is called *popping off the stack*. All data stored on the stack
+must have a known, fixed size. Data with an unknown size at compile time or a
+size that might change must be stored on the heap instead.
>
> The heap is less organized: when you put data on the heap, you request a
-> certain amount of space. The memory allocator finds an empty spot in the heap
-> that is big enough, marks it as being in use, and returns a *pointer*, which
-> is the address of that location. This process is called *allocating on the
-> heap* and is sometimes abbreviated as just *allocating* (pushing values onto
-> the stack is not considered allocating). Because the pointer to the heap is a
-> known, fixed size, you can store the pointer on the stack, but when you want
-> the actual data, you must follow the pointer. Think of being seated at a
-> restaurant. When you enter, you state the number of people in your group, and
-> the staff finds an empty table that fits everyone and leads you there. If
-> someone in your group comes late, they can ask where you’ve been seated to
-> find you.
+certain amount of space. The memory allocator finds an empty spot in the heap
+that is big enough, marks it as being in use, and returns a *pointer*, which is
+the address of that location. This process is called *allocating on the heap*
+and is sometimes abbreviated as just *allocating* (pushing values onto the
+stack is not considered allocating). Because the pointer to the heap is a
+known, fixed size, you can store the pointer on the stack, but when you want
+the actual data, you must follow the pointer. Think of being seated at a
+restaurant. When you enter, you state the number of people in your group, and
+the host finds an empty table that fits everyone and leads you there. If
+someone in your group comes late, they can ask where you’ve been seated to find
+you.
>
> Pushing to the stack is faster than allocating on the heap because the
-> allocator never has to search for a place to store new data; that location is
-> always at the top of the stack. Comparatively, allocating space on the heap
-> requires more work, because the allocator must first find a big enough space
-> to hold the data and then perform bookkeeping to prepare for the next
-> allocation.
-
-<!--- Minor nit: not sure if worth clarifying but thought I'd mention - performance
-for heap allocation I think isn't as much the time spent in the allocator but that
-you have to spend time asking the system for memory. Custom allocators still have to
-do the allocation step but try to avoid the system step where possible.
-/JT --->
-<!-- I think this is a bit in the weeds, not making any change here /Carol -->
-
+allocator never has to search for a place to store new data; that location is
+always at the top of the stack. Comparatively, allocating space on the heap
+requires more work because the allocator must first find a big enough space to
+hold the data and then perform bookkeeping to prepare for the next allocation.
+>
> Accessing data in the heap is slower than accessing data on the stack because
-> you have to follow a pointer to get there. Contemporary processors are faster
-> if they jump around less in memory. Continuing the analogy, consider a server
-> at a restaurant taking orders from many tables. It’s most efficient to get
-> all the orders at one table before moving on to the next table. Taking an
-> order from table A, then an order from table B, then one from A again, and
-> then one from B again would be a much slower process. By the same token, a
-> processor can do its job better if it works on data that’s close to other
-> data (as it is on the stack) rather than farther away (as it can be on the
-> heap).
-
-<!--- I don't quite understand the last sentence. If you allocate enough to create
-virtual memory, sure. But modern systems you're probably safe for most things? Also,
-if we're contrasting against something like the heap, just having the ability to allocate
-large space is probably a big benefit of the heap rather than a drawback. IMHO I'd probably
-just drop the last sentence.
-/JT --->
-<!-- Done! /Carol -->
-
+you have to follow a pointer to get there. Contemporary processors are faster
+if they jump around less in memory. Continuing the analogy, consider a server
+at a restaurant taking orders from many tables. It’s most efficient to get all
+the orders at one table before moving on to the next table. Taking an order
+from table A, then an order from table B, then one from A again, and then one
+from B again would be a much slower process. By the same token, a processor can
+do its job better if it works on data that’s close to other data (as it is on
+the stack) rather than farther away (as it can be on the heap).
>
> When your code calls a function, the values passed into the function
-> (including, potentially, pointers to data on the heap) and the function’s
-> local variables get pushed onto the stack. When the function is over, those
-> values get popped off the stack.
-
-<!--- Some calling conventions don't always use the stack for parameters.
-For example, Windows x64 calling convention puts the first 4 arguments into
-registers, and only puts args 5 and later on the stack. Ditto for the return
-value. If it can fit in a register, x64 will use that instead of the stack:
-
-https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#parameter-passing
-/JT --->
-<!-- I think this is a bit in the weeds, not making any change here /Carol -->
-
+(including, potentially, pointers to data on the heap) and the function’s local
+variables get pushed onto the stack. When the function is over, those values
+get popped off the stack.
>
> Keeping track of what parts of code are using what data on the heap,
-> minimizing the amount of duplicate data on the heap, and cleaning up unused
-> data on the heap so you don’t run out of space are all problems that ownership
-> addresses. Once you understand ownership, you won’t need to think about the
-> stack and the heap very often, but knowing that the main purpose of ownership
-> is to manage heap data can help explain why it works the way it does.
+minimizing the amount of duplicate data on the heap, and cleaning up unused
+data on the heap so you don’t run out of space are all problems that ownership
+addresses. Once you understand ownership, you won’t need to think about the
+stack and the heap very often, but knowing that the main purpose of ownership
+is to manage heap data can help explain why it works the way it does.
### Ownership Rules
@@ -140,14 +105,6 @@ work through the examples that illustrate them:
* There can only be one owner at a time.
* When the owner goes out of scope, the value will be dropped.
-<!--- Maybe splitting hairs, but for the first bullet I'd say:
-"Each value in Rust has an *owner*".
-
-If we say variables here, and then find out later that, for example, structs can
-also be owners, this gets a bit mirky.
-/JT --->
-<!-- Took this suggestion! /Carol -->
-
### Variable Scope
Now that we’re past basic Rust syntax, we won’t include all the `fn main() {`
@@ -170,8 +127,8 @@ which it’s declared until the end of the current *scope*. Listing 4-1 shows a
program with comments annotating where the variable `s` would be valid.
```
-{ // s is not valid here, it’s not yet declared
- let s = "hello"; // s is valid from this point forward.
+{ // s is not valid here, since it's not yet declared
+ let s = "hello"; // s is valid from this point forward
// do stuff with s
} // this scope is now over, and s is no longer valid
@@ -181,23 +138,23 @@ Listing 4-1: A variable and the scope in which it is valid
In other words, there are two important points in time here:
-* When `s` comes *into scope*, it is valid.
-* It remains valid until it goes *out of scope*.
+* When `s` comes *into* scope, it is valid.
+* It remains valid until it goes *out of* scope.
At this point, the relationship between scopes and when variables are valid is
similar to that in other programming languages. Now we’ll build on top of this
understanding by introducing the `String` type.
-### The `String` Type
+### The String Type
To illustrate the rules of ownership, we need a data type that is more complex
-than those we covered in the “Data Types†section of Chapter 3. The types
-covered previously are all a known size, can be stored on the stack and popped
-off the stack when their scope is over, and can be quickly and trivially copied
-to make a new, independent instance if another part of code needs to use the
-same value in a different scope. But we want to look at data that is stored on
-the heap and explore how Rust knows when to clean up that data, and the
-`String` type is a great example.
+than those we covered in “Data Types†on page XX. The types covered previously
+are of a known size, can be stored on the stack and popped off the stack when
+their scope is over, and can be quickly and trivially copied to make a new,
+independent instance if another part of code needs to use the same value in a
+different scope. But we want to look at data that is stored on the heap and
+explore how Rust knows when to clean up that data, and the `String` type is a
+great example.
We’ll concentrate on the parts of `String` that relate to ownership. These
aspects also apply to other complex data types, whether they are provided by
@@ -220,9 +177,9 @@ let s = String::from("hello");
The double colon `::` operator allows us to namespace this particular `from`
function under the `String` type rather than using some sort of name like
-`string_from`. We’ll discuss this syntax more in the “Method Syntax†section of
-Chapter 5 and when we talk about namespacing with modules in “Paths for
-Referring to an Item in the Module Tree†in Chapter 7.
+`string_from`. We’ll discuss this syntax more in “Method Syntax†on page XX,
+and when we talk about namespacing with modules in “Paths for Referring to an
+Item in the Module Tree†on page XX.
This kind of string *can* be mutated:
@@ -231,11 +188,11 @@ let mut s = String::from("hello");
s.push_str(", world!"); // push_str() appends a literal to a String
-println!("{}", s); // This will print `hello, world!`
+println!("{s}"); // This will print `hello, world!`
```
So, what’s the difference here? Why can `String` be mutated but literals
-cannot? The difference is how these two types deal with memory.
+cannot? The difference is in how these two types deal with memory.
### Memory and Allocation
@@ -251,8 +208,8 @@ we need to allocate an amount of memory on the heap, unknown at compile time,
to hold the contents. This means:
* The memory must be requested from the memory allocator at runtime.
-* We need a way of returning this memory to the allocator when we’re
- done with our `String`.
+* We need a way of returning this memory to the allocator when we’re done with
+our `String`.
That first part is done by us: when we call `String::from`, its implementation
requests the memory it needs. This is pretty much universal in programming
@@ -261,19 +218,13 @@ languages.
However, the second part is different. In languages with a *garbage collector
(GC)*, the GC keeps track of and cleans up memory that isn’t being used
anymore, and we don’t need to think about it. In most languages without a GC,
-it’s our responsibility to identify when memory is no longer being used and
+it’s our responsibility to identify when memory is no longer being used and to
call code to explicitly free it, just as we did to request it. Doing this
correctly has historically been a difficult programming problem. If we forget,
we’ll waste memory. If we do it too early, we’ll have an invalid variable. If
we do it twice, that’s a bug too. We need to pair exactly one `allocate` with
exactly one `free`.
-<!--- The phrase "explicitly return it" gives a connotation in programming of
-returning a value to a caller rather than the more casual returning it to the OS.
-Maybe we can say "explicitly delete it" or "explicitly free it".
-/JT --->
-<!-- Changed "return" to "free" /Carol -->
-
Rust takes a different path: the memory is automatically returned once the
variable that owns it goes out of scope. Here’s a version of our scope example
from Listing 4-1 using a `String` instead of a string literal:
@@ -294,23 +245,23 @@ and it’s where the author of `String` can put the code to return the memory.
Rust calls `drop` automatically at the closing curly bracket.
> Note: In C++, this pattern of deallocating resources at the end of an item’s
-> lifetime is sometimes called *Resource Acquisition Is Initialization (RAII)*.
-> The `drop` function in Rust will be familiar to you if you’ve used RAII
-> patterns.
+lifetime is sometimes called *Resource Acquisition Is Initialization* *(RAII)*.
+The `drop` function in Rust will be familiar to you if you’ve used RAII
+patterns.
This pattern has a profound impact on the way Rust code is written. It may seem
simple right now, but the behavior of code can be unexpected in more
complicated situations when we want to have multiple variables use the data
we’ve allocated on the heap. Let’s explore some of those situations now.
-#### Ways Variables and Data Interact: Move
+#### Variables and Data Interacting with Move
Multiple variables can interact with the same data in different ways in Rust.
Let’s look at an example using an integer in Listing 4-2.
```
- let x = 5;
- let y = x;
+let x = 5;
+let y = x;
```
Listing 4-2: Assigning the integer value of variable `x` to `y`
@@ -324,8 +275,8 @@ onto the stack.
Now let’s look at the `String` version:
```
- let s1 = String::from("hello");
- let s2 = s1;
+let s1 = String::from("hello");
+let s2 = s1;
```
This looks very similar, so we might assume that the way it works would be the
@@ -338,38 +289,20 @@ the memory that holds the contents of the string, a length, and a capacity.
This group of data is stored on the stack. On the right is the memory on the
heap that holds the contents.
-<img alt="String in memory" src="img/trpl04-01.svg" class="center" style="width: 50%;" />
-
-<!--- This might be me being a bit nitpicky - when you show what the string looks like
-in memory, we're showing indices for data pointed to by ptr. I have a bit of a knee-jerk
-reaction here since we don't think of strings has having indices in Rust (because of UTF-8)
-Not sure if it's well enough alone, or if it might be better for the ptr to point at
-at cells of memory without giving them indices.
-
-Something like:
-
-[ptr | --] -> [h][e][l][l][o]
-[len | 5]
-[capacity | 5]
-/JT --->
-<!-- I think this is a bit in the weeds, not making any change here /Carol -->
-
-Figure 4-1: Representation in memory of a `String` holding the value `"hello"`
+Figure 4-1: Representation in memory of a `String` holding the value `"hello"`
bound to `s1`
-The length is how much memory, in bytes, the contents of the `String` is
+The length is how much memory, in bytes, the contents of the `String` are
currently using. The capacity is the total amount of memory, in bytes, that the
-`String` has received from the allocator. The difference between length
-and capacity matters, but not in this context, so for now, it’s fine to ignore
-the capacity.
+`String` has received from the allocator. The difference between length and
+capacity matters, but not in this context, so for now, it’s fine to ignore the
+capacity.
When we assign `s1` to `s2`, the `String` data is copied, meaning we copy the
pointer, the length, and the capacity that are on the stack. We do not copy the
data on the heap that the pointer refers to. In other words, the data
representation in memory looks like Figure 4-2.
-<img alt="s1 and s2 pointing to the same value" src="img/trpl04-02.svg" class="center" style="width: 50%;" />
-
Figure 4-2: Representation in memory of the variable `s2` that has a copy of
the pointer, length, and capacity of `s1`
@@ -378,8 +311,6 @@ look like if Rust instead copied the heap data as well. If Rust did this, the
operation `s2 = s1` could be very expensive in terms of runtime performance if
the data on the heap were large.
-<img alt="s1 and s2 to two places" src="img/trpl04-03.svg" class="center" style="width: 50%;" />
-
Figure 4-3: Another possibility for what `s2 = s1` might do if Rust copied the
heap data as well
@@ -391,7 +322,7 @@ same memory. This is known as a *double free* error and is one of the memory
safety bugs we mentioned previously. Freeing memory twice can lead to memory
corruption, which can potentially lead to security vulnerabilities.
-To ensure memory safety, after the line `let s2 = s1`, Rust considers `s1` as
+To ensure memory safety, after the line `let s2 = s1;`, Rust considers `s1` as
no longer valid. Therefore, Rust doesn’t need to free anything when `s1` goes
out of scope. Check out what happens when you try to use `s1` after `s2` is
created; it won’t work:
@@ -400,7 +331,7 @@ created; it won’t work:
let s1 = String::from("hello");
let s2 = s1;
-println!("{}, world!", s1);
+println!("{s1}, world!");
```
You’ll get an error like this because Rust prevents you from using the
@@ -411,33 +342,32 @@ error[E0382]: borrow of moved value: `s1`
--> src/main.rs:5:28
|
2 | let s1 = String::from("hello");
- | -- move occurs because `s1` has type `String`, which does not implement the `Copy` trait
+ | -- move occurs because `s1` has type `String`, which
+ does not implement the `Copy` trait
3 | let s2 = s1;
| -- value moved here
4 |
-5 | println!("{}, world!", s1);
- | ^^ value borrowed here after move
+5 | println!("{s1}, world!");
+ | ^^ value borrowed here after move
```
If you’ve heard the terms *shallow copy* and *deep copy* while working with
other languages, the concept of copying the pointer, length, and capacity
without copying the data probably sounds like making a shallow copy. But
-because Rust also invalidates the first variable, instead of calling it a
-shallow copy, it’s known as a *move*. In this example, we would say that
-`s1` was *moved* into `s2`. So what actually happens is shown in Figure 4-4.
-
-<img alt="s1 moved to s2" src="img/trpl04-04.svg" class="center" style="width: 50%;" />
+because Rust also invalidates the first variable, instead of being called a
+shallow copy, it’s known as a *move*. In this example, we would say that `s1`
+was *moved* into `s2`. So, what actually happens is shown in Figure 4-4.
Figure 4-4: Representation in memory after `s1` has been invalidated
-That solves our problem! With only `s2` valid, when it goes out of scope, it
+That solves our problem! With only `s2` valid, when it goes out of scope it
alone will free the memory, and we’re done.
In addition, there’s a design choice that’s implied by this: Rust will never
automatically create “deep†copies of your data. Therefore, any *automatic*
copying can be assumed to be inexpensive in terms of runtime performance.
-#### Ways Variables and Data Interact: Clone
+#### Variables and Data Interacting with Clone
If we *do* want to deeply copy the heap data of the `String`, not just the
stack data, we can use a common method called `clone`. We’ll discuss method
@@ -450,7 +380,7 @@ Here’s an example of the `clone` method in action:
let s1 = String::from("hello");
let s2 = s1.clone();
-println!("s1 = {}, s2 = {}", s1, s2);
+println!("s1 = {s1}, s2 = {s2}");
```
This works just fine and explicitly produces the behavior shown in Figure 4-3,
@@ -462,14 +392,14 @@ different is going on.
#### Stack-Only Data: Copy
-There’s another wrinkle we haven’t talked about yet. This code using integers –
-part of which was shown in Listing 4-2 – works and is valid:
+There’s another wrinkle we haven’t talked about yet. This code using
+integers—part of which was shown in Listing 4-2—works and is valid:
```
let x = 5;
let y = x;
-println!("x = {}, y = {}", x, y);
+println!("x = {x}, y = {y}");
```
But this code seems to contradict what we just learned: we don’t have a call to
@@ -480,7 +410,7 @@ time are stored entirely on the stack, so copies of the actual values are quick
to make. That means there’s no reason we would want to prevent `x` from being
valid after we create the variable `y`. In other words, there’s no difference
between deep and shallow copying here, so calling `clone` wouldn’t do anything
-different from the usual shallow copying and we can leave it out.
+different from the usual shallow copying, and we can leave it out.
Rust has a special annotation called the `Copy` trait that we can place on
types that are stored on the stack, as integers are (we’ll talk more about
@@ -488,29 +418,13 @@ traits in Chapter 10). If a type implements the `Copy` trait, variables that
use it do not move, but rather are trivially copied, making them still valid
after assignment to another variable.
-<!--- an older variable that uses that type, we mean? /LC --->
-<!-- I removed "older" here, I don't think that was quite right-- this sentence
-is trying to describe the line `let y = x` where the variable `x` is assigned
-to `y`. The variables must be the same type because they're getting the same
-value, so "that uses that type" isn't relevant. Let me know if there's any
-aspects that are still confusing here. /Carol -->
-<!-- JT, is this all clear in the text? /LC -->
-<!--- I think this is fine. When I teach it, I tend to stress *move* and *copy*
-so that they can build up that framework. So my slight tweak to the above might
-be:
-
-"If a type implements the `Copy` trait, variables that use it do not move but rather are
-trivially copied, making them still valid after assignment to another variable."
-/JT --->
-<!-- Took this suggestion! /Carol -->
-
Rust won’t let us annotate a type with `Copy` if the type, or any of its parts,
has implemented the `Drop` trait. If the type needs something special to happen
when the value goes out of scope and we add the `Copy` annotation to that type,
we’ll get a compile-time error. To learn about how to add the `Copy` annotation
-to your type to implement the trait, see “Derivable Traits†in Appendix C.
+to your type to implement the trait, see “Derivable Traits†on page XX.
-So what types implement the `Copy` trait? You can check the documentation for
+So, what types implement the `Copy` trait? You can check the documentation for
the given type to be sure, but as a general rule, any group of simple scalar
values can implement `Copy`, and nothing that requires allocation or is some
form of resource can implement `Copy`. Here are some of the types that
@@ -518,10 +432,10 @@ implement `Copy`:
* All the integer types, such as `u32`.
* The Boolean type, `bool`, with values `true` and `false`.
-* All the floating point types, such as `f64`.
+* All the floating-point types, such as `f64`.
* The character type, `char`.
* Tuples, if they only contain types that also implement `Copy`. For example,
- `(i32, i32)` implements `Copy`, but `(i32, String)` does not.
+`(i32, i32)` implements `Copy`, but `(i32, String)` does not.
### Ownership and Functions
@@ -530,9 +444,8 @@ assigning a value to a variable. Passing a variable to a function will move or
copy, just as assignment does. Listing 4-3 has an example with some annotations
showing where variables go into and out of scope.
-Filename: src/main.rs
-
```
+// src/main.rs
fn main() {
let s = String::from("hello"); // s comes into scope
@@ -545,17 +458,17 @@ fn main() {
// but i32 is Copy, so it's okay to still
// use x afterward
-} // Here, x goes out of scope, then s. But because s's value was moved, nothing
- // special happens.
+} // Here, x goes out of scope, then s. However, because s's value was moved,
+ // nothing special happens
fn takes_ownership(some_string: String) { // some_string comes into scope
- println!("{}", some_string);
+ println!("{some_string}");
} // Here, some_string goes out of scope and `drop` is called. The backing
- // memory is freed.
+ // memory is freed
fn makes_copy(some_integer: i32) { // some_integer comes into scope
- println!("{}", some_integer);
-} // Here, some_integer goes out of scope. Nothing special happens.
+ println!("{some_integer}");
+} // Here, some_integer goes out of scope. Nothing special happens
```
Listing 4-3: Functions with ownership and scope annotated
@@ -567,13 +480,12 @@ the ownership rules prevent you from doing so.
### Return Values and Scope
-Returning values can also transfer ownership. Listing 4-4 shows an example
-of a function that returns some value, with similar annotations as those in
-Listing 4-3.
-
-Filename: src/main.rs
+Returning values can also transfer ownership. Listing 4-4 shows an example of a
+function that returns some value, with similar annotations as those in Listing
+4-3.
```
+// src/main.rs
fn main() {
let s1 = gives_ownership(); // gives_ownership moves its return
// value into s1
@@ -584,7 +496,7 @@ fn main() {
// takes_and_gives_back, which also
// moves its return value into s3
} // Here, s3 goes out of scope and is dropped. s2 was moved, so nothing
- // happens. s1 goes out of scope and is dropped.
+ // happens. s1 goes out of scope and is dropped
fn gives_ownership() -> String { // gives_ownership will move its
// return value into the function
@@ -597,7 +509,7 @@ fn gives_ownership() -> String { // gives_ownership will move its
// function
}
-// This function takes a String and returns one
+// This function takes a String and returns a String
fn takes_and_gives_back(a_string: String) -> String { // a_string comes into
// scope
@@ -628,7 +540,7 @@ fn main() {
let (s2, len) = calculate_length(s1);
- println!("The length of '{}' is {}.", s2, len);
+ println!("The length of '{s2}' is {len}.");
}
fn calculate_length(s: String) -> (String, usize) {
@@ -655,12 +567,6 @@ the data stored at that address; that data is owned by some other variable.
Unlike a pointer, a reference is guaranteed to point to a valid value of a
particular type for the life of that reference.
-<!--- Possible wording tweak: "a reference is guaranteed to point to a valid value of a
-particular type for the life of that reference" or "a reference is always guaranteed
-to point to a valid value of a particular type"
-/JT --->
-<!-- Took this suggestion! /Carol -->
-
Here is how you would define and use a `calculate_length` function that has a
reference to an object as a parameter instead of taking ownership of the value:
@@ -672,7 +578,7 @@ fn main() {
let len = calculate_length(&s1);
- println!("The length of '{}' is {}.", s1, len);
+ println!("The length of '{s1}' is {len}.");
}
fn calculate_length(s: &String) -> usize {
@@ -686,14 +592,12 @@ function return value is gone. Second, note that we pass `&s1` into
`String`. These ampersands represent *references*, and they allow you to refer
to some value without taking ownership of it. Figure 4-5 depicts this concept.
-<img alt="&String s pointing at String s1" src="img/trpl04-05.svg" class="center" />
-
Figure 4-5: A diagram of `&String s` pointing at `String s1`
> Note: The opposite of referencing by using `&` is *dereferencing*, which is
-> accomplished with the dereference operator, `*`. We’ll see some uses of the
-> dereference operator in Chapter 8 and discuss details of dereferencing in
-> Chapter 15.
+accomplished with the dereference operator, `*`. We’ll see some uses of the
+dereference operator in Chapter 8 and discuss details of dereferencing in
+Chapter 15.
Let’s take a closer look at the function call here:
@@ -714,12 +618,12 @@ the parameter `s` is a reference. Let’s add some explanatory annotations:
fn calculate_length(s: &String) -> usize { // s is a reference to a String
s.len()
} // Here, s goes out of scope. But because it does not have ownership of what
- // it refers to, it is not dropped.
+ // it refers to, the String is not dropped
```
The scope in which the variable `s` is valid is the same as any function
parameter’s scope, but the value pointed to by the reference is not dropped
-when `s` stops being used because `s` doesn’t have ownership. When functions
+when `s` stops being used, because `s` doesn’t have ownership. When functions
have references as parameters instead of the actual values, we won’t need to
return the values in order to give back ownership, because we never had
ownership.
@@ -728,7 +632,7 @@ We call the action of creating a reference *borrowing*. As in real life, if a
person owns something, you can borrow it from them. When you’re done, you have
to give it back. You don’t own it.
-So what happens if we try to modify something we’re borrowing? Try the code in
+So, what happens if we try to modify something we’re borrowing? Try the code in
Listing 4-6. Spoiler alert: it doesn’t work!
Filename: src/main.rs
@@ -750,13 +654,16 @@ Listing 4-6: Attempting to modify a borrowed value
Here’s the error:
```
-error[E0596]: cannot borrow `*some_string` as mutable, as it is behind a `&` reference
+error[E0596]: cannot borrow `*some_string` as mutable, as it is behind a `&`
+reference
--> src/main.rs:8:5
|
7 | fn change(some_string: &String) {
- | ------- help: consider changing this to be a mutable reference: `&mut String`
+ | ------- help: consider changing this to be a mutable
+reference: `&mut String`
8 | some_string.push_str(", world");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `some_string` is a `&` reference, so the data it refers to cannot be borrowed as mutable
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `some_string` is a `&` reference, so
+the data it refers to cannot be borrowed as mutable
```
Just as variables are immutable by default, so are references. We’re not
@@ -781,7 +688,7 @@ fn change(some_string: &mut String) {
}
```
-First, we change `s` to be `mut`. Then we create a mutable reference with `&mut
+First we change `s` to be `mut`. Then we create a mutable reference with `&mut
s` where we call the `change` function, and update the function signature to
accept a mutable reference with `some_string: &mut String`. This makes it very
clear that the `change` function will mutate the value it borrows.
@@ -790,22 +697,15 @@ Mutable references have one big restriction: if you have a mutable reference to
a value, you can have no other references to that value. This code that
attempts to create two mutable references to `s` will fail:
-<!--- Clarification: "Mutable references have one big restriction: if you have a
-mutable reference to a value, you can have no other references to that value."
-This covers both not having two mutable references and having a mutable references
-and an immutable reference to the same value.
-/JT --->
-<!-- Took this suggestion! /Carol -->
-
Filename: src/main.rs
```
- let mut s = String::from("hello");
+let mut s = String::from("hello");
- let r1 = &mut s;
- let r2 = &mut s;
+let r1 = &mut s;
+let r2 = &mut s;
- println!("{}, {}", r1, r2);
+println!("{r1}, {r2}");
```
Here’s the error:
@@ -819,8 +719,8 @@ error[E0499]: cannot borrow `s` as mutable more than once at a time
5 | let r2 = &mut s;
| ^^^^^^ second mutable borrow occurs here
6 |
-7 | println!("{}, {}", r1, r2);
- | -- first borrow later used here
+7 | println!("{r1}, {r2}");
+ | -- first borrow later used here
```
This error says that this code is invalid because we cannot borrow `s` as
@@ -831,7 +731,7 @@ in `r2` that borrows the same data as `r1`.
The restriction preventing multiple mutable references to the same data at the
same time allows for mutation but in a very controlled fashion. It’s something
-that new Rustaceans struggle with, because most languages let you mutate
+that new Rustaceans struggle with because most languages let you mutate
whenever you’d like. The benefit of having this restriction is that Rust can
prevent data races at compile time. A *data race* is similar to a race
condition and happens when these three behaviors occur:
@@ -841,8 +741,8 @@ condition and happens when these three behaviors occur:
* There’s no mechanism being used to synchronize access to the data.
Data races cause undefined behavior and can be difficult to diagnose and fix
-when you’re trying to track them down at runtime; Rust prevents this problem
-by refusing to compile code with data races!
+when you’re trying to track them down at runtime; Rust prevents this problem by
+refusing to compile code with data races!
As always, we can use curly brackets to create a new scope, allowing for
multiple mutable references, just not *simultaneous* ones:
@@ -852,7 +752,7 @@ let mut s = String::from("hello");
{
let r1 = &mut s;
-} // r1 goes out of scope here, so we can make a new reference with no problems.
+} // r1 goes out of scope here, so we can make a new reference with no problems
let r2 = &mut s;
```
@@ -867,13 +767,14 @@ let r1 = &s; // no problem
let r2 = &s; // no problem
let r3 = &mut s; // BIG PROBLEM
-println!("{}, {}, and {}", r1, r2, r3);
+println!("{r1}, {r2}, and {r3}");
```
Here’s the error:
```
-error[E0502]: cannot borrow `s` as mutable because it is also borrowed as immutable
+error[E0502]: cannot borrow `s` as mutable because it is also borrowed as
+immutable
--> src/main.rs:6:14
|
4 | let r1 = &s; // no problem
@@ -882,8 +783,8 @@ error[E0502]: cannot borrow `s` as mutable because it is also borrowed as immuta
6 | let r3 = &mut s; // BIG PROBLEM
| ^^^^^^ mutable borrow occurs here
7 |
-8 | println!("{}, {}, and {}", r1, r2, r3);
- | -- immutable borrow later used here
+8 | println!("{r1}, {r2}, and {r3}");
+ | -- immutable borrow later used here
```
Whew! We *also* cannot have a mutable reference while we have an immutable one
@@ -904,20 +805,18 @@ let mut s = String::from("hello");
let r1 = &s; // no problem
let r2 = &s; // no problem
-println!("{} and {}", r1, r2);
+println!("{r1} and {r2}");
// variables r1 and r2 will not be used after this point
let r3 = &mut s; // no problem
-println!("{}", r3);
+println!("{r3}");
```
The scopes of the immutable references `r1` and `r2` end after the `println!`
where they are last used, which is before the mutable reference `r3` is
-created. These scopes don’t overlap, so this code is allowed. The ability of
-the compiler to tell that a reference is no longer being used at a point before
-the end of the scope is called *Non-Lexical Lifetimes* (NLL for short), and you
-can read more about it in The Edition Guide at
-*https://doc.rust-lang.org/edition-guide/rust-2018/ownership-and-lifetimes/non-lexical-lifetimes.html*.
+created. These scopes don’t overlap, so this code is allowed: the compiler can
+tell that the reference is no longer being used at a point before the end of
+the scope.
Even though borrowing errors may be frustrating at times, remember that it’s
the Rust compiler pointing out a potential bug early (at compile time rather
@@ -927,9 +826,9 @@ have to track down why your data isn’t what you thought it was.
### Dangling References
In languages with pointers, it’s easy to erroneously create a *dangling
-pointer*--a pointer that references a location in memory that may have been
-given to someone else--by freeing some memory while preserving a pointer to
-that memory. In Rust, by contrast, the compiler guarantees that references will
+pointer*—a pointer that references a location in memory that may have been
+given to someone else—by freeing some memory while preserving a pointer to that
+memory. In Rust, by contrast, the compiler guarantees that references will
never be dangling references: if you have a reference to some data, the
compiler will ensure that the data will not go out of scope before the
reference to the data does.
@@ -960,7 +859,8 @@ error[E0106]: missing lifetime specifier
5 | fn dangle() -> &String {
| ^ expected named lifetime parameter
|
- = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
+ = help: this function's return type contains a borrowed value,
+but there is no value for it to be borrowed from
help: consider using the `'static` lifetime
|
5 | fn dangle() -> &'static String {
@@ -972,22 +872,21 @@ discuss lifetimes in detail in Chapter 10. But, if you disregard the parts
about lifetimes, the message does contain the key to why this code is a problem:
```
-this function's return type contains a borrowed value, but there is no value
-for it to be borrowed from
+this function's return type contains a borrowed value, but there
+is no value for it to be borrowed from
```
Let’s take a closer look at exactly what’s happening at each stage of our
`dangle` code:
-Filename: src/main.rs
-
```
+// src/main.rs
fn dangle() -> &String { // dangle returns a reference to a String
let s = String::from("hello"); // s is a new String
&s // we return a reference to the String, s
-} // Here, s goes out of scope, and is dropped. Its memory goes away.
+} // Here, s goes out of scope and is dropped, so its memory goes away
// Danger!
```
@@ -1014,7 +913,7 @@ deallocated.
Let’s recap what we’ve discussed about references:
* At any given time, you can have *either* one mutable reference *or* any
- number of immutable references.
+number of immutable references.
* References must always be valid.
Next, we’ll look at a different kind of reference: slices.
@@ -1030,12 +929,6 @@ words separated by spaces and returns the first word it finds in that string.
If the function doesn’t find a space in the string, the whole string must be
one word, so the entire string should be returned.
-<!--- Do we want to clarify this is for words separated by spaces?
-Not all languages use spaces to separate words:
-https://www.w3.org/International/articles/typography/linebreak.en#whatisword
-/JT --->
-<!-- Took this suggestion! /Carol -->
-
Let’s work through how we’d write the signature of this function without using
slices, to understand the problem that slices will solve:
@@ -1052,15 +945,15 @@ Filename: src/main.rs
```
fn first_word(s: &String) -> usize {
- [1] let bytes = s.as_bytes();
+ 1 let bytes = s.as_bytes();
- for (i, &item)[2] in bytes.iter()[3].enumerate() {
- [4] if item == b' ' {
+ for (2 i, &item) in 3 bytes.iter().enumerate() {
+ 4 if item == b' ' {
return i;
}
}
- [5] s.len()
+ 5 s.len()
}
```
@@ -1071,13 +964,13 @@ Because we need to go through the `String` element by element and check whether
a value is a space, we’ll convert our `String` to an array of bytes using the
`as_bytes` method [1].
-Next, we create an iterator over the array of bytes using the `iter` method [3].
-We’ll discuss iterators in more detail in Chapter 13. For now, know that `iter`
-is a method that returns each element in a collection and that `enumerate`
-wraps the result of `iter` and returns each element as part of a tuple instead.
-The first element of the tuple returned from `enumerate` is the index, and the
-second element is a reference to the element. This is a bit more convenient
-than calculating the index ourselves.
+Next, we create an iterator over the array of bytes using the `iter` method
+[3]. We’ll discuss iterators in more detail in Chapter 13. For now, know that
+`iter` is a method that returns each element in a collection and that
+`enumerate` wraps the result of `iter` and returns each element as part of a
+tuple instead. The first element of the tuple returned from `enumerate` is the
+index, and the second element is a reference to the element. This is a bit more
+convenient than calculating the index ourselves.
Because the `enumerate` method returns a tuple, we can use patterns to
destructure that tuple. We’ll be discussing patterns more in Chapter 6. In the
@@ -1096,9 +989,8 @@ because it’s a separate value from the `String`, there’s no guarantee that i
will still be valid in the future. Consider the program in Listing 4-8 that
uses the `first_word` function from Listing 4-7.
-Filename: src/main.rs
-
```
+// src/main.rs
fn main() {
let mut s = String::from("hello world");
@@ -1130,8 +1022,8 @@ fn second_word(s: &String) -> (usize, usize) {
Now we’re tracking a starting *and* an ending index, and we have even more
values that were calculated from data in a particular state but aren’t tied to
-that state at all. We have three unrelated variables floating around that
-need to be kept in sync.
+that state at all. We have three unrelated variables floating around that need
+to be kept in sync.
Luckily, Rust has a solution to this problem: string slices.
@@ -1140,10 +1032,10 @@ Luckily, Rust has a solution to this problem: string slices.
A *string slice* is a reference to part of a `String`, and it looks like this:
```
- let s = String::from("hello world");
+let s = String::from("hello world");
- let hello = &s[0..5];
- let world = &s[6..11];
+let hello = &s[0..5];
+let world = &s[6..11];
```
Rather than a reference to the entire `String`, `hello` is a reference to a
@@ -1152,17 +1044,15 @@ using a range within brackets by specifying `[starting_index..ending_index]`,
where `starting_index` is the first position in the slice and `ending_index` is
one more than the last position in the slice. Internally, the slice data
structure stores the starting position and the length of the slice, which
-corresponds to `ending_index` minus `starting_index`. So in the case of `let
+corresponds to `ending_index` minus `starting_index`. So, in the case of `let
world = &s[6..11];`, `world` would be a slice that contains a pointer to the
-byte at index 6 of `s` with a length value of 5.
+byte at index 6 of `s` with a length value of `5`.
Figure 4-6 shows this in a diagram.
-<img alt="world containing a pointer to the byte at index 6 of String s and a length 5" src="img/trpl04-06.svg" class="center" style="width: 50%;" />
-
Figure 4-6: String slice referring to part of a `String`
-With Rust’s `..` range syntax, if you want to start at index zero, you can drop
+With Rust’s `..` range syntax, if you want to start at index 0, you can drop
the value before the two periods. In other words, these are equal:
```
@@ -1197,11 +1087,11 @@ let slice = &s[..];
```
> Note: String slice range indices must occur at valid UTF-8 character
-> boundaries. If you attempt to create a string slice in the middle of a
-> multibyte character, your program will exit with an error. For the purposes
-> of introducing string slices, we are assuming ASCII only in this section; a
-> more thorough discussion of UTF-8 handling is in the “Storing UTF-8 Encoded
-> Text with Strings†section of Chapter 8.
+boundaries. If you attempt to create a string slice in the middle of a
+multibyte character, your program will exit with an error. For the purposes of
+introducing string slices, we are assuming ASCII only in this section; a more
+thorough discussion of UTF-8 handling is in “Storing UTF-8 Encoded Text with
+Strings†on page XX.
With all this information in mind, let’s rewrite `first_word` to return a
slice. The type that signifies “string slice†is written as `&str`:
@@ -1222,10 +1112,10 @@ fn first_word(s: &String) -> &str {
}
```
-We get the index for the end of the word in the same way as we did in Listing
-4-7, by looking for the first occurrence of a space. When we find a space, we
-return a string slice using the start of the string and the index of the space
-as the starting and ending indices.
+We get the index for the end of the word the same way we did in Listing 4-7, by
+looking for the first occurrence of a space. When we find a space, we return a
+string slice using the start of the string and the index of the space as the
+starting and ending indices.
Now when we call `first_word`, we get back a single value that is tied to the
underlying data. The value is made up of a reference to the starting point of
@@ -1237,7 +1127,7 @@ Returning a slice would also work for a `second_word` function:
fn second_word(s: &String) -> &str {
```
-We now have a straightforward API that’s much harder to mess up, because the
+We now have a straightforward API that’s much harder to mess up because the
compiler will ensure the references into the `String` remain valid. Remember
the bug in the program in Listing 4-8, when we got the index to the end of the
first word but then cleared the string so our index was invalid? That code was
@@ -1257,7 +1147,7 @@ fn main() {
s.clear(); // error!
- println!("the first word is: {}", word);
+ println!("the first word is: {word}");
}
```
@@ -1274,8 +1164,8 @@ immutable
18 | s.clear(); // error!
| ^^^^^^^^^ mutable borrow occurs here
19 |
-20 | println!("the first word is: {}", word);
- | ---- immutable borrow later used here
+20 | println!("the first word is: {word}");
+ | ---- immutable borrow later used here
```
Recall from the borrowing rules that if we have an immutable reference to
@@ -1287,7 +1177,7 @@ reference in `clear` and the immutable reference in `word` from existing at the
same time, and compilation fails. Not only has Rust made our API easier to use,
but it has also eliminated an entire class of errors at compile time!
-#### String Literals Are Slices
+#### String Literals as Slices
Recall that we talked about string literals being stored inside the binary. Now
that we know about slices, we can properly understand string literals:
@@ -1323,9 +1213,10 @@ the type of the `s` parameter
If we have a string slice, we can pass that directly. If we have a `String`, we
can pass a slice of the `String` or a reference to the `String`. This
flexibility takes advantage of *deref coercions*, a feature we will cover in
-the “Implicit Deref Coercions with Functions and Methods†section of Chapter
-15. Defining a function to take a string slice instead of a reference to a
-`String` makes our API more general and useful without losing any functionality:
+“Implicit Deref Coercions with Functions and Methods†on page XX.
+
+Defining a function to take a string slice instead of a reference to a `String`
+makes our API more general and useful without losing any functionality:
Filename: src/main.rs
@@ -1333,16 +1224,18 @@ Filename: src/main.rs
fn main() {
let my_string = String::from("hello world");
- // `first_word` works on slices of `String`s, whether partial or whole
+ // `first_word` works on slices of `String`s, whether partial
+ // or whole
let word = first_word(&my_string[0..6]);
let word = first_word(&my_string[..]);
- // `first_word` also works on references to `String`s, which are equivalent
- // to whole slices of `String`s
+ // `first_word` also works on references to `String`s, which
+ // are equivalent to whole slices of `String`s
let word = first_word(&my_string);
let my_string_literal = "hello world";
- // `first_word` works on slices of string literals, whether partial or whole
+ // `first_word` works on slices of string literals,
+ // whether partial or whole
let word = first_word(&my_string_literal[0..6]);
let word = first_word(&my_string_literal[..]);
@@ -1355,14 +1248,14 @@ fn main() {
### Other Slices
String slices, as you might imagine, are specific to strings. But there’s a
-more general slice type, too. Consider this array:
+more general slice type too. Consider this array:
```
let a = [1, 2, 3, 4, 5];
```
-Just as we might want to refer to a part of a string, we might want to refer
-to part of an array. We’d do so like this:
+Just as we might want to refer to part of a string, we might want to refer to
+part of an array. We’d do so like this:
```
let a = [1, 2, 3, 4, 5];
@@ -1388,3 +1281,4 @@ means you don’t have to write and debug extra code to get this control.
Ownership affects how lots of other parts of Rust work, so we’ll talk about
these concepts further throughout the rest of the book. Let’s move on to
Chapter 5 and look at grouping pieces of data together in a `struct`.
+
diff --git a/src/doc/book/nostarch/chapter05.md b/src/doc/book/nostarch/chapter05.md
index 356ba82af..9881a3b74 100644
--- a/src/doc/book/nostarch/chapter05.md
+++ b/src/doc/book/nostarch/chapter05.md
@@ -19,16 +19,16 @@ We’ll demonstrate how to define and instantiate structs. We’ll discuss how t
define associated functions, especially the kind of associated functions called
*methods*, to specify behavior associated with a struct type. Structs and enums
(discussed in Chapter 6) are the building blocks for creating new types in your
-program’s domain to take full advantage of Rust’s compile time type checking.
+program’s domain to take full advantage of Rust’s compile-time type checking.
## Defining and Instantiating Structs
-Structs are similar to tuples, discussed in “The Tuple Type†section, in that
-both hold multiple related values. Like tuples, the pieces of a struct can be
-different types. Unlike with tuples, in a struct you’ll name each piece of data
-so it’s clear what the values mean. Adding these names means that structs are
-more flexible than tuples: you don’t have to rely on the order of the data to
-specify or access the values of an instance.
+Structs are similar to tuples, discussed in “The Tuple Type†on page XX, in
+that both hold multiple related values. Like tuples, the pieces of a struct can
+be different types. Unlike with tuples, in a struct you’ll name each piece of
+data so it’s clear what the values mean. Adding these names means that structs
+are more flexible than tuples: you don’t have to rely on the order of the data
+to specify or access the values of an instance.
To define a struct, we enter the keyword `struct` and name the entire struct. A
struct’s name should describe the significance of the pieces of data being
@@ -36,6 +36,8 @@ grouped together. Then, inside curly brackets, we define the names and types of
the pieces of data, which we call *fields*. For example, Listing 5-1 shows a
struct that stores information about a user account.
+Filename: src/main.rs
+
```
struct User {
active: bool,
@@ -49,20 +51,22 @@ Listing 5-1: A `User` struct definition
To use a struct after we’ve defined it, we create an *instance* of that struct
by specifying concrete values for each of the fields. We create an instance by
-stating the name of the struct and then add curly brackets containing `key:
-value` pairs, where the keys are the names of the fields and the values are the
+stating the name of the struct and then add curly brackets containing key:
+value pairs, where the keys are the names of the fields and the values are the
data we want to store in those fields. We don’t have to specify the fields in
the same order in which we declared them in the struct. In other words, the
struct definition is like a general template for the type, and instances fill
in that template with particular data to create values of the type. For
example, we can declare a particular user as shown in Listing 5-2.
+Filename: src/main.rs
+
```
fn main() {
let user1 = User {
- email: String::from("someone@example.com"),
- username: String::from("someusername123"),
active: true,
+ username: String::from("someusername123"),
+ email: String::from("someone@example.com"),
sign_in_count: 1,
};
}
@@ -76,19 +80,14 @@ mutable, we can change a value by using the dot notation and assigning into a
particular field. Listing 5-3 shows how to change the value in the `email`
field of a mutable `User` instance.
-<!--- Do we want to mention that `user1.email` will move the field? We can't
-just use `user1.email` multiple times re: "wherever we wanted
-to use this value"
-/JT --->
-<!-- I don't really want to mention that, but I did reword to avoid the
-implication that we can use the value wherever we wanted to. /Carol -->
+Filename: src/main.rs
```
fn main() {
let mut user1 = User {
- email: String::from("someone@example.com"),
- username: String::from("someusername123"),
active: true,
+ username: String::from("someusername123"),
+ email: String::from("someone@example.com"),
sign_in_count: 1,
};
@@ -110,9 +109,9 @@ the `sign_in_count` gets a value of `1`.
```
fn build_user(email: String, username: String) -> User {
User {
- email: email,
- username: username,
active: true,
+ username: username,
+ email: email,
sign_in_count: 1,
}
}
@@ -130,22 +129,22 @@ would get even more annoying. Luckily, there’s a convenient shorthand!
Because the parameter names and the struct field names are exactly the same in
Listing 5-4, we can use the *field init shorthand* syntax to rewrite
-`build_user` so that it behaves exactly the same but doesn’t have the
-repetition of `email` and `username`, as shown in Listing 5-5.
+`build_user` so it behaves exactly the same but doesn’t have the repetition of
+`username` and `email`, as shown in Listing 5-5.
```
fn build_user(email: String, username: String) -> User {
User {
- email,
- username,
active: true,
+ username,
+ email,
sign_in_count: 1,
}
}
```
Listing 5-5: A `build_user` function that uses field init shorthand because the
-`email` and `username` parameters have the same name as struct fields
+`username` and `email` parameters have the same name as struct fields
Here, we’re creating a new instance of the `User` struct, which has a field
named `email`. We want to set the `email` field’s value to the value in the
@@ -153,7 +152,7 @@ named `email`. We want to set the `email` field’s value to the value in the
the `email` parameter have the same name, we only need to write `email` rather
than `email: email`.
-### Creating Instances From Other Instances With Struct Update Syntax
+### Creating Instances from Other Instances with Struct Update Syntax
It’s often useful to create a new instance of a struct that includes most of
the values from another instance, but changes some. You can do this using
@@ -163,9 +162,11 @@ First, in Listing 5-6 we show how to create a new `User` instance in `user2`
regularly, without the update syntax. We set a new value for `email` but
otherwise use the same values from `user1` that we created in Listing 5-2.
+Filename: src/main.rs
+
```
fn main() {
- // --snip--
+ --snip--
let user2 = User {
active: user1.active,
@@ -182,9 +183,12 @@ Using struct update syntax, we can achieve the same effect with less code, as
shown in Listing 5-7. The syntax `..` specifies that the remaining fields not
explicitly set should have the same value as the fields in the given instance.
+Filename: src/main.rs
+
```
fn main() {
- // --snip--
+ --snip--
+
let user2 = User {
email: String::from("another@example.com"),
@@ -194,7 +198,7 @@ fn main() {
```
Listing 5-7: Using struct update syntax to set a new `email` value for a `User`
-instance but use the rest of the values from `user1`
+instance but to use the rest of the values from `user1`
The code in Listing 5-7 also creates an instance in `user2` that has a
different value for `email` but has the same values for the `username`,
@@ -204,33 +208,30 @@ corresponding fields in `user1`, but we can choose to specify values for as
many fields as we want in any order, regardless of the order of the fields in
the struct’s definition.
-Note that the struct update syntax uses `=` like an assignment; this is
-because it moves the data, just as we saw in the “Ways Variables and Data
-Interact: Move†section. In this example, we can no longer use `user1` after
-creating `user2` because the `String` in the `username` field of `user1` was
-moved into `user2`. If we had given `user2` new `String` values for both
-`email` and `username`, and thus only used the `active` and `sign_in_count`
-values from `user1`, then `user1` would still be valid after creating `user2`.
-The types of `active` and `sign_in_count` are types that implement the `Copy`
-trait, so the behavior we discussed in the “Stack-Only Data: Copy†section
-would apply.
-
-<!--- Misspelled "assignment" above.
-/JT --->
-<!-- Fixed! /Carol -->
-
-### Using Tuple Structs without Named Fields to Create Different Types
-
-Rust also supports structs that look similar to tuples, called *tuple
-structs*. Tuple structs have the added meaning the struct name provides but
-don’t have names associated with their fields; rather, they just have the types
-of the fields. Tuple structs are useful when you want to give the whole tuple a
-name and make the tuple a different type from other tuples, and when naming each
+Note that the struct update syntax uses `=` like an assignment; this is because
+it moves the data, just as we saw in “Variables and Data Interacting with Moveâ€
+on page XX. In this example, we can no longer use `user1` after creating
+`user2` because the `String` in the `username` field of `user1` was moved into
+`user2`. If we had given `user2` new `String` values for both `email` and
+`username`, and thus only used the `active` and `sign_in_count` values from
+`user1`, then `user1` would still be valid after creating `user2`. Both
+`active` and `sign_in_count` are types that implement the `Copy` trait, so the
+behavior we discussed in “Stack-Only Data: Copy†on page XX would apply.
+
+### Using Tuple Structs Without Named Fields to Create Different Types
+
+Rust also supports structs that look similar to tuples, called *tuple structs*.
+Tuple structs have the added meaning the struct name provides but don’t have
+names associated with their fields; rather, they just have the types of the
+fields. Tuple structs are useful when you want to give the whole tuple a name
+and make the tuple a different type from other tuples, and when naming each
field as in a regular struct would be verbose or redundant.
To define a tuple struct, start with the `struct` keyword and the struct name
-followed by the types in the tuple. For example, here we define and use
-two tuple structs named `Color` and `Point`:
+followed by the types in the tuple. For example, here we define and use two
+tuple structs named `Color` and `Point`:
+
+Filename: src/main.rs
```
struct Color(i32, i32, i32);
@@ -242,7 +243,7 @@ fn main() {
}
```
-Note that the `black` and `origin` values are different types, because they’re
+Note that the `black` and `origin` values are different types because they’re
instances of different tuple structs. Each struct you define is its own type,
even though the fields within the struct might have the same types. For
example, a function that takes a parameter of type `Color` cannot take a
@@ -251,30 +252,17 @@ values. Otherwise, tuple struct instances are similar to tuples in that you can
destructure them into their individual pieces, and you can use a `.` followed
by the index to access an individual value.
-<!--- The last line above feels a bit misleading. There are related
-restrictions on tuple structs that don't apply to tuples.
-
-One example is you can't create a tuple struct with a tuple.
-```
-struct Color(i32, i32, i32);
-
-fn main() {
- let x: Color = (1, 2, 3);
-}
-```
-
-You can't pass a tuple struct to something that expects a tuple, either.
-/JT --->
-<!-- I've reworded to avoid that implication /Carol -->
-
### Unit-Like Structs Without Any Fields
You can also define structs that don’t have any fields! These are called
*unit-like structs* because they behave similarly to `()`, the unit type that
-we mentioned in “The Tuple Type†section. Unit-like structs can be useful when
-you need to implement a trait on some type but don’t have any data that you
-want to store in the type itself. We’ll discuss traits in Chapter 10. Here’s an
-example of declaring and instantiating a unit struct named `AlwaysEqual`:
+we mentioned in “The Tuple Type†on page XX. Unit-like structs can be useful
+when you need to implement a trait on some type but don’t have any data that
+you want to store in the type itself. We’ll discuss traits in Chapter 10.
+Here’s an example of declaring and instantiating a unit struct named
+`AlwaysEqual`:
+
+Filename: src/main.rs
```
struct AlwaysEqual;
@@ -284,8 +272,8 @@ fn main() {
}
```
-To define `AlwaysEqual`, we use the `struct` keyword, the name we want, then a
-semicolon. No need for curly brackets or parentheses! Then we can get an
+To define `AlwaysEqual`, we use the `struct` keyword, the name we want, and
+then a semicolon. No need for curly brackets or parentheses! Then we can get an
instance of `AlwaysEqual` in the `subject` variable in a similar way: using the
name we defined, without any curly brackets or parentheses. Imagine that later
we’ll implement behavior for this type such that every instance of
@@ -297,31 +285,30 @@ implement them on any type, including unit-like structs.
> ### Ownership of Struct Data
>
> In the `User` struct definition in Listing 5-1, we used the owned `String`
-> type rather than the `&str` string slice type. This is a deliberate choice
-> because we want each instance of this struct to own all of its data and for
-> that data to be valid for as long as the entire struct is valid.
+type rather than the `&str` string slice type. This is a deliberate choice
+because we want each instance of this struct to own all of its data and for
+that data to be valid for as long as the entire struct is valid.
>
> It’s also possible for structs to store references to data owned by something
-> else, but to do so requires the use of *lifetimes*, a Rust feature that we’ll
-> discuss in Chapter 10. Lifetimes ensure that the data referenced by a struct
-> is valid for as long as the struct is. Let’s say you try to store a reference
-> in a struct without specifying lifetimes, like the following; this won’t work:
->
-> Filename: src/main.rs
+else, but to do so requires the use of *lifetimes*, a Rust feature that we’ll
+discuss in Chapter 10. Lifetimes ensure that the data referenced by a struct is
+valid for as long as the struct is. Let’s say you try to store a reference in a
+struct without specifying lifetimes, like the following in *src/main.rs*; this
+won’t work:
>
> ```
> struct User {
+> active: bool,
> username: &str,
> email: &str,
> sign_in_count: u64,
-> active: bool,
> }
>
> fn main() {
> let user1 = User {
-> email: "someone@example.com",
-> username: "someusername123",
> active: true,
+> username: "someusername123",
+> email: "someone@example.com",
> sign_in_count: 1,
> };
> }
@@ -330,7 +317,7 @@ implement them on any type, including unit-like structs.
> The compiler will complain that it needs lifetime specifiers:
>
> ```
-> $ cargo run
+> $ `cargo run`
> Compiling structs v0.1.0 (file:///projects/structs)
> error[E0106]: missing lifetime specifier
> --> src/main.rs:3:15
@@ -361,8 +348,8 @@ implement them on any type, including unit-like structs.
> ```
>
> In Chapter 10, we’ll discuss how to fix these errors so you can store
-> references in structs, but for now, we’ll fix errors like these using owned
-> types like `String` instead of references like `&str`.
+references in structs, but for now, we’ll fix errors like these using owned
+types like `String` instead of references like `&str`.
## An Example Program Using Structs
@@ -399,10 +386,6 @@ and height variables
Now, run this program using `cargo run`:
```
-$ cargo run
- Compiling rectangles v0.1.0 (file:///projects/rectangles)
- Finished dev [unoptimized + debuginfo] target(s) in 0.42s
- Running `target/debug/rectangles`
The area of the rectangle is 1500 square pixels.
```
@@ -417,10 +400,10 @@ fn area(width: u32, height: u32) -> u32 {
```
The `area` function is supposed to calculate the area of one rectangle, but the
-function we wrote has two parameters, and it's not clear anywhere in our
+function we wrote has two parameters, and it’s not clear anywhere in our
program that the parameters are related. It would be more readable and more
manageable to group width and height together. We’ve already discussed one way
-we might do that in “The Tuple Type†section of Chapter 3: by using tuples.
+we might do that in “The Tuple Type†on page XX: by using tuples.
### Refactoring with Tuples
@@ -434,21 +417,21 @@ fn main() {
println!(
"The area of the rectangle is {} square pixels.",
- area(rect1)
+ 1 area(rect1)
);
}
fn area(dimensions: (u32, u32)) -> u32 {
- dimensions.0 * dimensions.1
+ 2 dimensions.0 * dimensions.1
}
```
Listing 5-9: Specifying the width and height of the rectangle with a tuple
In one way, this program is better. Tuples let us add a bit of structure, and
-we’re now passing just one argument. But in another way, this version is less
-clear: tuples don’t name their elements, so we have to index into the parts of
-the tuple, making our calculation less obvious.
+we’re now passing just one argument [1]. But in another way, this version is
+less clear: tuples don’t name their elements, so we have to index into the
+parts of the tuple [2], making our calculation less obvious.
Mixing up the width and height wouldn’t matter for the area calculation, but if
we want to draw the rectangle on the screen, it would matter! We would have to
@@ -466,13 +449,13 @@ parts, as shown in Listing 5-10.
Filename: src/main.rs
```
-struct Rectangle {
- width: u32,
+1 struct Rectangle {
+ 2 width: u32,
height: u32,
}
fn main() {
- let rect1 = Rectangle {
+ 3 let rect1 = Rectangle {
width: 30,
height: 50,
};
@@ -483,27 +466,27 @@ fn main() {
);
}
-fn area(rectangle: &Rectangle) -> u32 {
- rectangle.width * rectangle.height
+4 fn area(rectangle: &Rectangle) -> u32 {
+ 5 rectangle.width * rectangle.height
}
```
Listing 5-10: Defining a `Rectangle` struct
-Here we’ve defined a struct and named it `Rectangle`. Inside the curly
+Here, we’ve defined a struct and named it `Rectangle` [1]. Inside the curly
brackets, we defined the fields as `width` and `height`, both of which have
-type `u32`. Then in `main`, we created a particular instance of `Rectangle`
-that has a width of 30 and a height of 50.
+type `u32` [2]. Then, in `main`, we created a particular instance of
+`Rectangle` that has a width of `30` and a height of `50` [3].
Our `area` function is now defined with one parameter, which we’ve named
-`rectangle`, whose type is an immutable borrow of a struct `Rectangle`
-instance. As mentioned in Chapter 4, we want to borrow the struct rather than
-take ownership of it. This way, `main` retains its ownership and can continue
-using `rect1`, which is the reason we use the `&` in the function signature and
-where we call the function.
+`rectangle`, whose type is an immutable borrow of a struct `Rectangle` instance
+[4]. As mentioned in Chapter 4, we want to borrow the struct rather than take
+ownership of it. This way, `main` retains its ownership and can continue using
+`rect1`, which is the reason we use the `&` in the function signature and where
+we call the function.
The `area` function accesses the `width` and `height` fields of the `Rectangle`
-instance (note that accessing fields of a borrowed struct instance does not
+instance [5] (note that accessing fields of a borrowed struct instance does not
move the field values, which is why you often see borrows of structs). Our
function signature for `area` now says exactly what we mean: calculate the area
of `Rectangle`, using its `width` and `height` fields. This conveys that the
@@ -511,14 +494,6 @@ width and height are related to each other, and it gives descriptive names to
the values rather than using the tuple index values of `0` and `1`. This is a
win for clarity.
-<!--- Tying to my comment above about `user1.email` moving that field: we should
-take a minute here and explain that accessing fields on a borrowed struct does
-not move them, and why you often see borrows of structs.
-/JT --->
-<!-- I've added a note in the paragraph above; I haven't really seen people
-struggle with that concept though so I don't want to spend too much time on it
-/Carol -->
-
### Adding Useful Functionality with Derived Traits
It’d be useful to be able to print an instance of `Rectangle` while we’re
@@ -555,7 +530,7 @@ error[E0277]: `Rectangle` doesn't implement `std::fmt::Display`
The `println!` macro can do many kinds of formatting, and by default, the curly
brackets tell `println!` to use formatting known as `Display`: output intended
for direct end user consumption. The primitive types we’ve seen so far
-implement `Display` by default, because there’s only one way you’d want to show
+implement `Display` by default because there’s only one way you’d want to show
a `1` or any other primitive type to a user. But with structs, the way
`println!` should format the output is less clear because there are more
display possibilities: Do you want commas or not? Do you want to print the
@@ -567,7 +542,8 @@ If we continue reading the errors, we’ll find this helpful note:
```
= help: the trait `std::fmt::Display` is not implemented for `Rectangle`
-= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
+= note: in format strings you may be able to use `{:?}` (or {:#?} for
+pretty-print) instead
```
Let’s try it! The `println!` macro call will now look like `println!("rect1 is
@@ -620,24 +596,16 @@ Now when we run the program, we won’t get any errors, and we’ll see the
following output:
```
-$ cargo run
- Compiling rectangles v0.1.0 (file:///projects/rectangles)
- Finished dev [unoptimized + debuginfo] target(s) in 0.48s
- Running `target/debug/rectangles`
rect1 is Rectangle { width: 30, height: 50 }
```
Nice! It’s not the prettiest output, but it shows the values of all the fields
for this instance, which would definitely help during debugging. When we have
larger structs, it’s useful to have output that’s a bit easier to read; in
-those cases, we can use `{:#?}` instead of `{:?}` in the `println!` string.
-In this example, using the `{:#?}` style will output:
+those cases, we can use `{:#?}` instead of `{:?}` in the `println!` string. In
+this example, using the `{:#?}` style will output the following:
```
-$ cargo run
- Compiling rectangles v0.1.0 (file:///projects/rectangles)
- Finished dev [unoptimized + debuginfo] target(s) in 0.48s
- Running `target/debug/rectangles`
rect1 is Rectangle {
width: 30,
height: 50,
@@ -645,20 +613,22 @@ rect1 is Rectangle {
```
Another way to print out a value using the `Debug` format is to use the `dbg!`
-macro, which takes ownership of an expression (as opposed to `println!` that
+macro, which takes ownership of an expression (as opposed to `println!`, which
takes a reference), prints the file and line number of where that `dbg!` macro
-call occurs in your code along with the resulting value of that expression, and
+call occurs in your code along with the resultant value of that expression, and
returns ownership of the value.
> Note: Calling the `dbg!` macro prints to the standard error console stream
-> (`stderr`), as opposed to `println!` which prints to the standard output
-> console stream (`stdout`). We’ll talk more about `stderr` and `stdout` in the
-> “Writing Error Messages to Standard Error Instead of Standard Output†section
-> in Chapter 12.
+(`stderr`), as opposed to `println!`, which prints to the standard output
+console stream (`stdout`). We’ll talk more about `stderr` and `stdout` in
+“Writing Error Messages to Standard Error Instead of Standard Output†on page
+XX.
Here’s an example where we’re interested in the value that gets assigned to the
`width` field, as well as the value of the whole struct in `rect1`:
+Filename: src/main.rs
+
```
#[derive(Debug)]
struct Rectangle {
@@ -669,31 +639,21 @@ struct Rectangle {
fn main() {
let scale = 2;
let rect1 = Rectangle {
- width: dbg!(30 * scale),
+ 1 width: dbg!(30 * scale),
height: 50,
};
- dbg!(&rect1);
+ 2 dbg!(&rect1);
}
```
-We can put `dbg!` around the expression `30 * scale` and, because `dbg!`
+We can put `dbg!` around the expression `30 * scale` [1] and, because `dbg!`
returns ownership of the expression’s value, the `width` field will get the
same value as if we didn’t have the `dbg!` call there. We don’t want `dbg!` to
-take ownership of `rect1`, so we use a reference to `rect1` in the next call.
-Here’s what the output of this example looks like:
-
-<!--- is it worth calling out that println! doesn't have the dbg! shortcoming
-of taking ownership?
-/JT --->
-<!-- I added a note in the paragraph above that starts with "Another way to
-print out a value" /Carol -->
+take ownership of `rect1`, so we use a reference to `rect1` in the next call
+[2]. Here’s what the output of this example looks like:
```
-$ cargo run
- Compiling rectangles v0.1.0 (file:///projects/rectangles)
- Finished dev [unoptimized + debuginfo] target(s) in 0.61s
- Running `target/debug/rectangles`
[src/main.rs:10] 30 * scale = 60
[src/main.rs:14] &rect1 = Rectangle {
width: 60,
@@ -701,13 +661,13 @@ $ cargo run
}
```
-We can see the first bit of output came from *src/main.rs* line 10, where we’re
-debugging the expression `30 * scale`, and its resulting value is 60 (the
-`Debug` formatting implemented for integers is to print only their value). The
-`dbg!` call on line 14 of *src/main.rs* outputs the value of `&rect1`, which is
-the `Rectangle` struct. This output uses the pretty `Debug` formatting of the
-`Rectangle` type. The `dbg!` macro can be really helpful when you’re trying to
-figure out what your code is doing!
+We can see the first bit of output came from [1] where we’re debugging the
+expression `30 * scale`, and its resultant value is `60` (the `Debug`
+formatting implemented for integers is to print only their value). The `dbg!`
+call at [2] outputs the value of `&rect1`, which is the `Rectangle` struct.
+This output uses the pretty `Debug` formatting of the `Rectangle` type. The
+`dbg!` macro can be really helpful when you’re trying to figure out what your
+code is doing!
In addition to the `Debug` trait, Rust has provided a number of traits for us
to use with the `derive` attribute that can add useful behavior to our custom
@@ -718,10 +678,10 @@ your own traits in Chapter 10. There are also many attributes other than
Reference at *https://doc.rust-lang.org/reference/attributes.html*.
Our `area` function is very specific: it only computes the area of rectangles.
-It would be helpful to tie this behavior more closely to our `Rectangle`
-struct, because it won’t work with any other type. Let’s look at how we can
-continue to refactor this code by turning the `area` function into an `area`
-*method* defined on our `Rectangle` type.
+It would be helpful to tie this behavior more closely to our `Rectangle` struct
+because it won’t work with any other type. Let’s look at how we can continue to
+refactor this code by turning the `area` function into an `area` *method*
+defined on our `Rectangle` type.
## Method Syntax
@@ -729,18 +689,9 @@ continue to refactor this code by turning the `area` function into an `area`
name, they can have parameters and a return value, and they contain some code
that’s run when the method is called from somewhere else. Unlike functions,
methods are defined within the context of a struct (or an enum or a trait
-object, which we cover in Chapters 6 and 17, respectively), and their first
-parameter is always `self`, which represents the instance of the struct the
-method is being called on.
-
-<!--- minor nit: some folks call the non-self functions in an `impl`
-"static methods" as a nod to OO languages that do the same. For folks
-from that background, we may want to call out that instance methods always
-have `self` and methods on the type do not.
-/JT --->
-<!-- This paragraph already says "their first parameter is always `self`", and
-we get into associated functions in just a bit. I don't want to distract with
-that info here; not changing anything at this spot. /Carol -->
+object, which we cover in Chapter 6 and Chapter 17, respectively), and their
+first parameter is always `self`, which represents the instance of the struct
+the method is being called on.
### Defining Methods
@@ -757,8 +708,8 @@ struct Rectangle {
height: u32,
}
-impl Rectangle {
- fn area(&self) -> u32 {
+1 impl Rectangle {
+ 2 fn area(&self) -> u32 {
self.width * self.height
}
}
@@ -771,7 +722,7 @@ fn main() {
println!(
"The area of the rectangle is {} square pixels.",
- rect1.area()
+ 3 rect1.area()
);
}
```
@@ -779,14 +730,14 @@ fn main() {
Listing 5-13: Defining an `area` method on the `Rectangle` struct
To define the function within the context of `Rectangle`, we start an `impl`
-(implementation) block for `Rectangle`. Everything within this `impl` block
+(implementation) block for `Rectangle` [1]. Everything within this `impl` block
will be associated with the `Rectangle` type. Then we move the `area` function
-within the `impl` curly brackets and change the first (and in this case, only)
-parameter to be `self` in the signature and everywhere within the body. In
-`main`, where we called the `area` function and passed `rect1` as an argument,
-we can instead use *method syntax* to call the `area` method on our `Rectangle`
-instance. The method syntax goes after an instance: we add a dot followed by
-the method name, parentheses, and any arguments.
+within the `impl` curly brackets [2] and change the first (and in this case,
+only) parameter to be `self` in the signature and everywhere within the body.
+In `main`, where we called the `area` function and passed `rect1` as an
+argument, we can instead use *method syntax* to call the `area` method on our
+`Rectangle` instance [3]. The method syntax goes after an instance: we add a
+dot followed by the method name, parentheses, and any arguments.
In the signature for `area`, we use `&self` instead of `rectangle: &Rectangle`.
The `&self` is actually short for `self: &Self`. Within an `impl` block, the
@@ -794,28 +745,30 @@ type `Self` is an alias for the type that the `impl` block is for. Methods must
have a parameter named `self` of type `Self` for their first parameter, so Rust
lets you abbreviate this with only the name `self` in the first parameter spot.
Note that we still need to use the `&` in front of the `self` shorthand to
-indicate this method borrows the `Self` instance, just as we did in `rectangle:
-&Rectangle`. Methods can take ownership of `self`, borrow `self` immutably as
-we’ve done here, or borrow `self` mutably, just as they can any other parameter.
-
-We’ve chosen `&self` here for the same reason we used `&Rectangle` in the
-function version: we don’t want to take ownership, and we just want to read the
-data in the struct, not write to it. If we wanted to change the instance that
-we’ve called the method on as part of what the method does, we’d use `&mut
-self` as the first parameter. Having a method that takes ownership of the
-instance by using just `self` as the first parameter is rare; this technique is
-usually used when the method transforms `self` into something else and you want
-to prevent the caller from using the original instance after the transformation.
-
-The main reason for using methods instead of functions, in addition to providing
-method syntax and not having to repeat the type of `self` in every method’s
-signature, is for organization. We’ve put all the things we can do with an
-instance of a type in one `impl` block rather than making future users of our
-code search for capabilities of `Rectangle` in various places in the library we
-provide.
+indicate that this method borrows the `Self` instance, just as we did in
+`rectangle: &Rectangle`. Methods can take ownership of `self`, borrow `self`
+immutably, as we’ve done here, or borrow `self` mutably, just as they can any
+other parameter.
+
+We chose `&self` here for the same reason we used `&Rectangle` in the function
+version: we don’t want to take ownership, and we just want to read the data in
+the struct, not write to it. If we wanted to change the instance that we’ve
+called the method on as part of what the method does, we’d use `&mut self` as
+the first parameter. Having a method that takes ownership of the instance by
+using just `self` as the first parameter is rare; this technique is usually
+used when the method transforms `self` into something else and you want to
+prevent the caller from using the original instance after the transformation.
+
+The main reason for using methods instead of functions, in addition to
+providing method syntax and not having to repeat the type of `self` in every
+method’s signature, is for organization. We’ve put all the things we can do
+with an instance of a type in one `impl` block rather than making future users
+of our code search for capabilities of `Rectangle` in various places in the
+library we provide.
Note that we can choose to give a method the same name as one of the struct’s
-fields. For example, we can define a method on `Rectangle` also named `width`:
+fields. For example, we can define a method on `Rectangle` that is also named
+`width`:
Filename: src/main.rs
@@ -833,42 +786,45 @@ fn main() {
};
if rect1.width() {
- println!("The rectangle has a nonzero width; it is {}", rect1.width);
+ println!(
+ "The rectangle has a nonzero width; it is {}",
+ rect1.width
+ );
}
}
```
Here, we’re choosing to make the `width` method return `true` if the value in
-the instance’s `width` field is greater than 0, and `false` if the value is 0:
-we can use a field within a method of the same name for any purpose. In `main`,
-when we follow `rect1.width` with parentheses, Rust knows we mean the method
-`width`. When we don’t use parentheses, Rust knows we mean the field `width`.
+the instance’s `width` field is greater than `0` and `false` if the value is
+`0`: we can use a field within a method of the same name for any purpose. In
+`main`, when we follow `rect1.width` with parentheses, Rust knows we mean the
+method `width`. When we don’t use parentheses, Rust knows we mean the field
+`width`.
Often, but not always, when we give methods with the same name as a field we
want it to only return the value in the field and do nothing else. Methods like
this are called *getters*, and Rust does not implement them automatically for
struct fields as some other languages do. Getters are useful because you can
-make the field private but the method public and thus enable read-only access
-to that field as part of the type’s public API. We will be discussing what
-public and private are and how to designate a field or method as public or
-private in Chapter 7.
+make the field private but the method public, and thus enable read-only access
+to that field as part of the type’s public API. We will discuss what public and
+private are and how to designate a field or method as public or private in
+Chapter 7.
-> ### Where’s the `->` Operator?
+> ### Where’s the -> Operator?
>
> In C and C++, two different operators are used for calling methods: you use
-> `.` if you’re calling a method on the object directly and `->` if you’re
-> calling the method on a pointer to the object and need to dereference the
-> pointer first. In other words, if `object` is a pointer,
-> `object->something()` is similar to `(*object).something()`.
+`.` if you’re calling a method on the object directly and `->` if you’re
+calling the method on a pointer to the object and need to dereference the
+pointer first. In other words, if `object` is a pointer,
+`object->`something`()` is similar to `(*object).`something`()`.
>
> Rust doesn’t have an equivalent to the `->` operator; instead, Rust has a
-> feature called *automatic referencing and dereferencing*. Calling methods is
-> one of the few places in Rust that has this behavior.
->
-> Here’s how it works: when you call a method with `object.something()`, Rust
-> automatically adds in `&`, `&mut`, or `*` so `object` matches the signature of
-> the method. In other words, the following are the same:
+feature called *automatic referencing and dereferencing*. Calling methods is
+one of the few places in Rust that has this behavior.
>
+> Here’s how it works: when you call a method with `object.`something`()`, Rust
+automatically adds in `&`, `&mut`, or `*` so `object` matches the signature of
+the method. In other words, the following are the same:
>
> ```
> p1.distance(&p2);
@@ -876,20 +832,20 @@ private in Chapter 7.
> ```
>
> The first one looks much cleaner. This automatic referencing behavior works
-> because methods have a clear receiver—the type of `self`. Given the receiver
-> and name of a method, Rust can figure out definitively whether the method is
-> reading (`&self`), mutating (`&mut self`), or consuming (`self`). The fact
-> that Rust makes borrowing implicit for method receivers is a big part of
-> making ownership ergonomic in practice.
+because methods have a clear receiver—the type of `self`. Given the receiver
+and name of a method, Rust can figure out definitively whether the method is
+reading (`&self`), mutating (`&mut self`), or consuming (`self`). The fact that
+Rust makes borrowing implicit for method receivers is a big part of making
+ownership ergonomic in practice.
### Methods with More Parameters
Let’s practice using methods by implementing a second method on the `Rectangle`
-struct. This time, we want an instance of `Rectangle` to take another instance
+struct. This time we want an instance of `Rectangle` to take another instance
of `Rectangle` and return `true` if the second `Rectangle` can fit completely
-within `self` (the first `Rectangle`); otherwise it should return `false`. That
-is, once we’ve defined the `can_hold` method, we want to be able to write the
-program shown in Listing 5-14.
+within `self` (the first `Rectangle`); otherwise, it should return `false`.
+That is, once we’ve defined the `can_hold` method, we want to be able to write
+the program shown in Listing 5-14.
Filename: src/main.rs
@@ -915,8 +871,8 @@ fn main() {
Listing 5-14: Using the as-yet-unwritten `can_hold` method
-And the expected output would look like the following, because both dimensions
-of `rect2` are smaller than the dimensions of `rect1` but `rect3` is wider than
+The expected output would look like the following because both dimensions of
+`rect2` are smaller than the dimensions of `rect1`, but `rect3` is wider than
`rect1`:
```
@@ -934,7 +890,7 @@ read `rect2` (rather than write, which would mean we’d need a mutable borrow),
and we want `main` to retain ownership of `rect2` so we can use it again after
calling the `can_hold` method. The return value of `can_hold` will be a
Boolean, and the implementation will check whether the width and height of
-`self` are both greater than the width and height of the other `Rectangle`,
+`self` are greater than the width and height of the other `Rectangle`,
respectively. Let’s add the new `can_hold` method to the `impl` block from
Listing 5-13, shown in Listing 5-15.
@@ -981,8 +937,8 @@ Filename: src/main.rs
```
impl Rectangle {
- fn square(size: u32) -> Self [1] {
- Self [2] {
+ fn square(size: u32) -> 1 Self {
+ 2 Self {
width: size,
height: size,
}
@@ -999,17 +955,11 @@ To call this associated function, we use the `::` syntax with the struct name;
the struct: the `::` syntax is used for both associated functions and
namespaces created by modules. We’ll discuss modules in Chapter 7.
-<!--- Should we mention the most common associated function is `new`? And that
-new isn't built into the language.
-/JT --->
-<!-- I've added a note as such above to the paragraph that starts with
-"Associated functions that aren’t methods" /Carol -->
-
-### Multiple `impl` Blocks
+### Multiple impl Blocks
Each struct is allowed to have multiple `impl` blocks. For example, Listing
-5-15 is equivalent to the code shown in Listing 5-16, which has each method
-in its own `impl` block.
+5-15 is equivalent to the code shown in Listing 5-16, which has each method in
+its own `impl` block.
```
impl Rectangle {
@@ -1043,31 +993,3 @@ structs have.
But structs aren’t the only way you can create custom types: let’s turn to
Rust’s enum feature to add another tool to your toolbox.
-<!--- We don't mention that you can only use `impl` in the same crate as the
-type it's created in, otherwise you could use `impl` and add methods on types
-that come from other people (which you can't do, unless you make a trait to
-attach them to)
-
-Another thing we may want to mention is that `Self` inside of an `impl` refers
-to the type being impl'd. So you might write the above:
-
-```
-impl Rectangle {
- fn square(size: u32) -> Self {
- Self {
- width: size,
- height: size,
- }
- }
-}
-```
-which is often a bit more ergonomic.
-
-/JT --->
-<!-- I've changed the `square` example to use `Self` and added some wingdings
-and notes explaining that. I don't really want to get into the restrictions on
-`impl` on types defined in another crate, because we haven't covered traits
-yet. Traits let you do `impl Trait for OtherCrateType` in some circumstances,
-so I don't want to say "you can't use an `impl` block on types from other
-crates" because I'd have to allude to traits or potentially give the reader the
-wrong impression. We get into these restrictions in chapter 10. -->
diff --git a/src/doc/book/nostarch/chapter06.md b/src/doc/book/nostarch/chapter06.md
index 47b51b5a1..ea4328bea 100644
--- a/src/doc/book/nostarch/chapter06.md
+++ b/src/doc/book/nostarch/chapter06.md
@@ -8,8 +8,8 @@ directory, so all fixes need to be made in `/src/`.
# Enums and Pattern Matching
-In this chapter we’ll look at *enumerations*, also referred to as *enums*.
-Enums allow you to define a type by enumerating its possible *variants*. First,
+In this chapter, we’ll look at *enumerations*, also referred to as *enums*.
+Enums allow you to define a type by enumerating its possible *variants*. First
we’ll define and use an enum to show how an enum can encode meaning along with
data. Next, we’ll explore a particularly useful enum, called `Option`, which
expresses that a value can be either something or nothing. Then we’ll look at
@@ -18,37 +18,8 @@ code for different values of an enum. Finally, we’ll cover how the `if let`
construct is another convenient and concise idiom available to handle enums in
your code.
-<!--- The above about algebraic data types feels pretty niche. Should it get
-the "expert aside" treatment that some of the early texts gets? /JT --->
-<!-- I decided to just remove the paragraph this comment was about. /Carol -->
-
## Defining an Enum
-<!--- I added this first line, it seems like this is what we're saying? Maybe
-summarize what enums are better suited for: when you know all possible outcomes
-and that the outcomes must be distinct from each other? I was hoping to
-generalize their usage early. Edit: reading on, I can see that might be tricky,
-so ignore this if so! /LC --->
-<!-- I made a slight edit to the first line here, what do you think? I don't
-think "enums are an alternative to structs" was quite right, because that
-sounded like in any situation, you could choose either enum or struct according
-to your preferences, but what I'd like the reader to come away with is that
-some situations are better expressed with enums; others with structs. /Carol -->
-<!-- I think this makes sense! I wonder if there's more we could add to give an
-idea of why we're contrasting them with structs, to give the reader a point of
-reference. What do you think JT? Would more explanation here be redundant? /LC
--->
-<!--- Here's my try for a framing, using our earlier Rectangle example:
-Where structs give you a way of grouping together related fields and data, like
-a `Rectangle` with its `width` and `height`, we don't yet have a way of saying
-a values is one of a possible set of values. For example, we may want to say
-that Rectangle is one of a set of possible shapes. To do this, Rust allows us
-to encode these possibilities as an enum. Let's look at...
-/JT --->
-<!-- I've generally taken JT's suggestion with a few edits. I'm a little
-concerned that we won't ever actually make a `Shape` enum with variants
-`Rectangle`, `Circle`, and `Triangle`? Is that a problem, Liz? /Carol -->
-
Where structs give you a way of grouping together related fields and data, like
a `Rectangle` with its `width` and `height`, enums give you a way of saying a
value is one of a possible set of values. For example, we may want to say that
@@ -64,7 +35,7 @@ variants, which is where enumeration gets its name.
Any IP address can be either a version four or a version six address, but not
both at the same time. That property of IP addresses makes the enum data
-structure appropriate, because an enum value can only be one of its variants.
+structure appropriate because an enum value can only be one of its variants.
Both version four and version six addresses are still fundamentally IP
addresses, so they should be treated as the same type when the code is handling
situations that apply to any kind of IP address.
@@ -114,22 +85,22 @@ Chapter 5, you might be tempted to tackle this problem with structs as shown in
Listing 6-1.
```
-enum IpAddrKind {
+1 enum IpAddrKind {
V4,
V6,
}
-struct IpAddr {
- kind: IpAddrKind,
- address: String,
+2 struct IpAddr {
+ 3 kind: IpAddrKind,
+ 4 address: String,
}
-let home = IpAddr {
+5 let home = IpAddr {
kind: IpAddrKind::V4,
address: String::from("127.0.0.1"),
};
-let loopback = IpAddr {
+6 let loopback = IpAddr {
kind: IpAddrKind::V6,
address: String::from("::1"),
};
@@ -138,14 +109,14 @@ let loopback = IpAddr {
Listing 6-1: Storing the data and `IpAddrKind` variant of an IP address using a
`struct`
-Here, we’ve defined a struct `IpAddr` that has two fields: a `kind` field that
-is of type `IpAddrKind` (the enum we defined previously) and an `address` field
-of type `String`. We have two instances of this struct. The first is `home`,
-and it has the value `IpAddrKind::V4` as its `kind` with associated address
-data of `127.0.0.1`. The second instance is `loopback`. It has the other
-variant of `IpAddrKind` as its `kind` value, `V6`, and has address `::1`
-associated with it. We’ve used a struct to bundle the `kind` and `address`
-values together, so now the variant is associated with the value.
+Here, we’ve defined a struct `IpAddr` [2] that has two fields: a `kind` field
+[3] that is of type `IpAddrKind` (the enum we defined previously [1]) and an
+`address` field [4] of type `String`. We have two instances of this struct. The
+first is `home` [5], and it has the value `IpAddrKind::V4` as its `kind` with
+associated address data of `127.0.0.1`. The second instance is `loopback` [6].
+It has the other variant of `IpAddrKind` as its `kind` value, `V6`, and has
+address `::1` associated with it. We’ve used a struct to bundle the `kind` and
+`address` values together, so now the variant is associated with the value.
However, representing the same concept using just an enum is more concise:
rather than an enum inside a struct, we can put data directly into each enum
@@ -164,7 +135,7 @@ let loopback = IpAddr::V6(String::from("::1"));
```
We attach data to each variant of the enum directly, so there is no need for an
-extra struct. Here it’s also easier to see another detail of how enums work:
+extra struct. Here, it’s also easier to see another detail of how enums work:
the name of each enum variant that we define also becomes a function that
constructs an instance of the enum. That is, `IpAddr::V4()` is a function call
that takes a `String` argument and returns an instance of the `IpAddr` type. We
@@ -172,7 +143,7 @@ automatically get this constructor function defined as a result of defining the
enum.
There’s another advantage to using an enum rather than a struct: each variant
-can have different types and amounts of associated data. Version four type IP
+can have different types and amounts of associated data. Version four IP
addresses will always have four numeric components that will have values
between 0 and 255. If we wanted to store `V4` addresses as four `u8` values but
still express `V6` addresses as one `String` value, we wouldn’t be able to with
@@ -199,11 +170,11 @@ different structs, which are defined differently for each variant:
```
struct Ipv4Addr {
- // --snip--
+ --snip--
}
struct Ipv6Addr {
- // --snip--
+ --snip--
}
enum IpAddr {
@@ -240,7 +211,7 @@ types of values
This enum has four variants with different types:
* `Quit` has no data associated with it at all.
-* `Move` has named fields like a struct does.
+* `Move` has named fields, like a struct does.
* `Write` includes a single `String`.
* `ChangeColor` includes three `i32` values.
@@ -260,16 +231,10 @@ struct WriteMessage(String); // tuple struct
struct ChangeColorMessage(i32, i32, i32); // tuple struct
```
-But if we used the different structs, which each have their own type, we
+But if we used the different structs, each of which has its own type, we
couldn’t as easily define a function to take any of these kinds of messages as
we could with the `Message` enum defined in Listing 6-2, which is a single type.
-<!--- We're also hinting at pattern matching complexity if we use the struct
-method. Should we call it out and mention the pattern matching chapter?
-/JT --->
-<!-- If readers don't have experience with pattern matching, I don't think this
-will resonate with them, so I'm not going to mention it here. /Carol -->
-
There is one more similarity between enums and structs: just as we’re able to
define methods on structs using `impl`, we’re also able to define methods on
enums. Here’s a method named `call` that we could define on our `Message` enum:
@@ -277,34 +242,34 @@ enums. Here’s a method named `call` that we could define on our `Message` enum
```
impl Message {
fn call(&self) {
- // method body would be defined here
+ 1 // method body would be defined here
}
}
-let m = Message::Write(String::from("hello"));
+2 let m = Message::Write(String::from("hello"));
m.call();
```
The body of the method would use `self` to get the value that we called the
-method on. In this example, we’ve created a variable `m` that has the value
+method on. In this example, we’ve created a variable `m` [2] that has the value
`Message::Write(String::from("hello"))`, and that is what `self` will be in the
-body of the `call` method when `m.call()` runs.
+body of the `call` method [1] when `m.call()` runs.
Let’s look at another enum in the standard library that is very common and
useful: `Option`.
-### The `Option` Enum and Its Advantages Over Null Values
+### The Option Enum and Its Advantages Over Null Values
This section explores a case study of `Option`, which is another enum defined
by the standard library. The `Option` type encodes the very common scenario in
which a value could be something or it could be nothing.
-For example, if you request the first of a list containing items, you would get
-a value. If you request the first item of an empty list, you would get nothing.
-Expressing this concept in terms of the type system means the compiler can
-check whether you’ve handled all the cases you should be handling; this
-functionality can prevent bugs that are extremely common in other programming
-languages.
+For example, if you request the first item in a list containing multiple items,
+you would get a value. If you request the first item in an empty list, you
+would get nothing. Expressing this concept in terms of the type system means
+the compiler can check whether you’ve handled all the cases you should be
+handling; this functionality can prevent bugs that are extremely common in
+other programming languages.
Programming language design is often thought of in terms of which features you
include, but the features you exclude are important too. Rust doesn’t have the
@@ -316,17 +281,16 @@ In his 2009 presentation “Null References: The Billion Dollar Mistake,†Tony
Hoare, the inventor of null, has this to say:
> I call it my billion-dollar mistake. At that time, I was designing the first
-> comprehensive type system for references in an object-oriented language. My
-> goal was to ensure that all use of references should be absolutely safe, with
-> checking performed automatically by the compiler. But I couldn’t resist the
-> temptation to put in a null reference, simply because it was so easy to
-> implement. This has led to innumerable errors, vulnerabilities, and system
-> crashes, which have probably caused a billion dollars of pain and damage in
-> the last forty years.
-
-The problem with null values is that if you try to use a null value as a
-not-null value, you’ll get an error of some kind. Because this null or not-null
-property is pervasive, it’s extremely easy to make this kind of error.
+comprehensive type system for references in an object-oriented language. My
+goal was to ensure that all use of references should be absolutely safe, with
+checking performed automatically by the compiler. But I couldn’t resist the
+temptation to put in a null reference, simply because it was so easy to
+implement. This has led to innumerable errors, vulnerabilities, and system
+crashes, which have probably caused a billion dollars of pain and damage in the
+last forty years.The problem with null values is that if you try to use a null
+value as a not-null value, you’ll get an error of some kind. Because this null
+or not-null property is pervasive, it’s extremely easy to make this kind of
+error.
However, the concept that null is trying to express is still a useful one: a
null is a value that is currently invalid or absent for some reason.
@@ -334,8 +298,7 @@ null is a value that is currently invalid or absent for some reason.
The problem isn’t really with the concept but with the particular
implementation. As such, Rust does not have nulls, but it does have an enum
that can encode the concept of a value being present or absent. This enum is
-`Option<T>`, and it is defined by the standard library
-as follows:
+`Option<T>`, and it is defined by the standard library as follows:
```
enum Option<T> {
@@ -352,11 +315,11 @@ prefix. The `Option<T>` enum is still just a regular enum, and `Some(T)` and
The `<T>` syntax is a feature of Rust we haven’t talked about yet. It’s a
generic type parameter, and we’ll cover generics in more detail in Chapter 10.
-For now, all you need to know is that `<T>` means the `Some` variant of the
-`Option` enum can hold one piece of data of any type, and that each concrete
-type that gets used in place of `T` makes the overall `Option<T>` type a
-different type. Here are some examples of using `Option` values to hold number
-types and string types:
+For now, all you need to know is that `<T>` means that the `Some` variant of
+the `Option` enum can hold one piece of data of any type, and that each
+concrete type that gets used in place of `T` makes the overall `Option<T>` type
+a different type. Here are some examples of using `Option` values to hold
+number types and string types:
```
let some_number = Some(5);
@@ -365,26 +328,6 @@ let some_char = Some('e');
let absent_number: Option<i32> = None;
```
-<!--- I would maybe do the above more explicitly as:
-
-"
-```
-let some_number = Some(5);
-
-let some_number2: Option<i32> = Some(5);
-```
-The types of `some_number` and `some_number2` in the above are identical.
-"
-
-Using `Some("a string")` we're going to open the door to references in
-generic positions (which we still need to build up to). We talk a little about
-Option<&str> below, but I don't think it helps explain the enum concept.
-
-/JT --->
-<!-- I changed the above to use `char` rather than string slice, but we're
-trying to show that options holding different types are themselves different
-types below, so I didn't want to make them both `i32`. /Carol -->
-
The type of `some_number` is `Option<i32>`. The type of `some_char` is
`Option<char>`, which is a different type. Rust can infer these types because
we’ve specified a value inside the `Some` variant. For `absent_number`, Rust
@@ -394,13 +337,13 @@ type that the corresponding `Some` variant will hold by looking only at a
`Option<i32>`.
When we have a `Some` value, we know that a value is present and the value is
-held within the `Some`. When we have a `None` value, in some sense, it means
-the same thing as null: we don’t have a valid value. So why is having
-`Option<T>` any better than having null?
+held within the `Some`. When we have a `None` value, in some sense it means the
+same thing as null: we don’t have a valid value. So why is having `Option<T>`
+any better than having null?
In short, because `Option<T>` and `T` (where `T` can be any type) are different
types, the compiler won’t let us use an `Option<T>` value as if it were
-definitely a valid value. For example, this code won’t compile because it’s
+definitely a valid value. For example, this code won’t compile, because it’s
trying to add an `i8` to an `Option<i8>`:
```
@@ -410,11 +353,9 @@ let y: Option<i8> = Some(5);
let sum = x + y;
```
-If we run this code, we get an error message like this:
+If we run this code, we get an error message like this one:
```
-$ cargo run
- Compiling enums v0.1.0 (file:///projects/enums)
error[E0277]: cannot add `Option<i8>` to `i8`
--> src/main.rs:5:17
|
@@ -435,8 +376,7 @@ using the value.
In other words, you have to convert an `Option<T>` to a `T` before you can
perform `T` operations with it. Generally, this helps catch one of the most
-common issues with null: assuming that something isn’t null when it actually
-is.
+common issues with null: assuming that something isn’t null when it actually is.
Eliminating the risk of incorrectly assuming a not-null value helps you to be
more confident in your code. In order to have a value that can possibly be
@@ -447,30 +387,30 @@ when the value is null. Everywhere that a value has a type that isn’t an
deliberate design decision for Rust to limit null’s pervasiveness and increase
the safety of Rust code.
-So, how do you get the `T` value out of a `Some` variant when you have a value
-of type `Option<T>` so you can use that value? The `Option<T>` enum has a large
-number of methods that are useful in a variety of situations; you can check
-them out in its documentation. Becoming familiar with the methods on
+So how do you get the `T` value out of a `Some` variant when you have a value
+of type `Option<T>` so that you can use that value? The `Option<T>` enum has a
+large number of methods that are useful in a variety of situations; you can
+check them out in its documentation. Becoming familiar with the methods on
`Option<T>` will be extremely useful in your journey with Rust.
In general, in order to use an `Option<T>` value, you want to have code that
will handle each variant. You want some code that will run only when you have a
`Some(T)` value, and this code is allowed to use the inner `T`. You want some
-other code to run if you have a `None` value, and that code doesn’t have a `T`
-value available. The `match` expression is a control flow construct that does
-just this when used with enums: it will run different code depending on which
-variant of the enum it has, and that code can use the data inside the matching
-value.
-
-## The `match` Control Flow Construct
-
-Rust has an extremely powerful control flow construct called `match` that allows
-you to compare a value against a series of patterns and then execute code based
-on which pattern matches. Patterns can be made up of literal values, variable
-names, wildcards, and many other things; Chapter 18 covers all the different
-kinds of patterns and what they do. The power of `match` comes from the
-expressiveness of the patterns and the fact that the compiler confirms that all
-possible cases are handled.
+other code to run only if you have a `None` value, and that code doesn’t have a
+`T` value available. The `match` expression is a control flow construct that
+does just this when used with enums: it will run different code depending on
+which variant of the enum it has, and that code can use the data inside the
+matching value.
+
+## The match Control Flow Construct
+
+Rust has an extremely powerful control flow construct called `match` that
+allows you to compare a value against a series of patterns and then execute
+code based on which pattern matches. Patterns can be made up of literal values,
+variable names, wildcards, and many other things; Chapter 18 covers all the
+different kinds of patterns and what they do. The power of `match` comes from
+the expressiveness of the patterns and the fact that the compiler confirms that
+all possible cases are handled.
Think of a `match` expression as being like a coin-sorting machine: coins slide
down a track with variously sized holes along it, and each coin falls through
@@ -479,12 +419,12 @@ through each pattern in a `match`, and at the first pattern the value “fits,â€
the value falls into the associated code block to be used during execution.
Speaking of coins, let’s use them as an example using `match`! We can write a
-function that takes an unknown United States coin and, in a similar way as the
-counting machine, determines which coin it is and return its value in cents, as
-shown here in Listing 6-3.
+function that takes an unknown US coin and, in a similar way as the counting
+machine, determines which coin it is and returns its value in cents, as shown
+in Listing 6-3.
```
-[1]enum Coin {
+1 enum Coin {
Penny,
Nickel,
Dime,
@@ -492,8 +432,8 @@ shown here in Listing 6-3.
}
fn value_in_cents(coin: Coin) -> u8 {
- match coin {
- Coin::Penny => 1,
+ 2 match coin {
+ 3 Coin::Penny => 1,
Coin::Nickel => 5,
Coin::Dime => 10,
Coin::Quarter => 25,
@@ -504,36 +444,29 @@ fn value_in_cents(coin: Coin) -> u8 {
Listing 6-3: An enum and a `match` expression that has the variants of the enum
as its patterns
-Let’s break down the `match` in the `value_in_cents` function. First, we list
+Let’s break down the `match` in the `value_in_cents` function. First we list
the `match` keyword followed by an expression, which in this case is the value
-`coin`. This seems very similar to an expression used with `if`, but there’s a
-big difference: with `if`, the expression needs to return a Boolean value, but
-here, it can return any type. The type of `coin` in this example is the `Coin`
-enum that we defined at [1].
+`coin` [2]. This seems very similar to an expression used with `if`, but
+there’s a big difference: with `if`, the expression needs to return a Boolean
+value, but here it can return any type. The type of `coin` in this example is
+the `Coin` enum that we defined at [1].
Next are the `match` arms. An arm has two parts: a pattern and some code. The
first arm here has a pattern that is the value `Coin::Penny` and then the `=>`
-operator that separates the pattern and the code to run. The code in this case
-is just the value `1`. Each arm is separated from the next with a comma.
+operator that separates the pattern and the code to run [3]. The code in this
+case is just the value `1`. Each arm is separated from the next with a comma.
-<!--- Tiny nit, though not sure how to phrase it. Arms are separated by commas
-in this example, though if you use blocks instead of simple values you won't use
-commas. We see this happen in the next example.
-/JT --->
-<!-- I clarified in the paragraph before the next example. You *can* use commas
-even if there's curly brackets, but people don't usually. /Carol -->
-
-When the `match` expression executes, it compares the resulting value against
+When the `match` expression executes, it compares the resultant value against
the pattern of each arm, in order. If a pattern matches the value, the code
associated with that pattern is executed. If that pattern doesn’t match the
value, execution continues to the next arm, much as in a coin-sorting machine.
We can have as many arms as we need: in Listing 6-3, our `match` has four arms.
-The code associated with each arm is an expression, and the resulting value of
+The code associated with each arm is an expression, and the resultant value of
the expression in the matching arm is the value that gets returned for the
entire `match` expression.
-We don't typically use curly brackets if the match arm code is short, as it is
+We don’t typically use curly brackets if the match arm code is short, as it is
in Listing 6-3 where each arm just returns a value. If you want to run multiple
lines of code in a match arm, you must use curly brackets, and the comma
following the arm is then optional. For example, the following code prints
@@ -554,7 +487,7 @@ fn value_in_cents(coin: Coin) -> u8 {
}
```
-### Patterns that Bind to Values
+### Patterns That Bind to Values
Another useful feature of match arms is that they can bind to the parts of the
values that match the pattern. This is how we can extract values out of enum
@@ -564,15 +497,15 @@ As an example, let’s change one of our enum variants to hold data inside it.
From 1999 through 2008, the United States minted quarters with different
designs for each of the 50 states on one side. No other coins got state
designs, so only quarters have this extra value. We can add this information to
-our `enum` by changing the `Quarter` variant to include a `UsState` value stored
-inside it, which we’ve done here in Listing 6-4.
+our `enum` by changing the `Quarter` variant to include a `UsState` value
+stored inside it, which we’ve done in Listing 6-4.
```
#[derive(Debug)] // so we can inspect the state in a minute
enum UsState {
Alabama,
Alaska,
- // --snip--
+ --snip--
}
enum Coin {
@@ -588,8 +521,8 @@ Listing 6-4: A `Coin` enum in which the `Quarter` variant also holds a
Let’s imagine that a friend is trying to collect all 50 state quarters. While
we sort our loose change by coin type, we’ll also call out the name of the
-state associated with each quarter so if it’s one our friend doesn’t have, they
-can add it to their collection.
+state associated with each quarter so that if it’s one our friend doesn’t have,
+they can add it to their collection.
In the match expression for this code, we add a variable called `state` to the
pattern that matches values of the variant `Coin::Quarter`. When a
@@ -617,13 +550,13 @@ that point, the binding for `state` will be the value `UsState::Alaska`. We can
then use that binding in the `println!` expression, thus getting the inner
state value out of the `Coin` enum variant for `Quarter`.
-### Matching with `Option<T>`
+### Matching with Option<T>
In the previous section, we wanted to get the inner `T` value out of the `Some`
-case when using `Option<T>`; we can also handle `Option<T>` using `match` as we
-did with the `Coin` enum! Instead of comparing coins, we’ll compare the
-variants of `Option<T>`, but the way that the `match` expression works remains
-the same.
+case when using `Option<T>`; we can also handle `Option<T>` using `match`, as
+we did with the `Coin` enum! Instead of comparing coins, we’ll compare the
+variants of `Option<T>`, but the way the `match` expression works remains the
+same.
Let’s say we want to write a function that takes an `Option<i32>` and, if
there’s a value inside, adds 1 to that value. If there isn’t a value inside,
@@ -636,44 +569,40 @@ Listing 6-5.
```
fn plus_one(x: Option<i32>) -> Option<i32> {
match x {
- None => None,
- Some(i) => Some(i + 1),
+ 1 None => None,
+ 2 Some(i) => Some(i + 1),
}
}
let five = Some(5);
-let six = plus_one(five);
-let none = plus_one(None);
+let six = plus_one(five); 3
+let none = plus_one(None); 4
```
Listing 6-5: A function that uses a `match` expression on an `Option<i32>`
Let’s examine the first execution of `plus_one` in more detail. When we call
-`plus_one(five)`, the variable `x` in the body of `plus_one` will have the
-value `Some(5)`. We then compare that against each match arm.
+`plus_one(five)` [3], the variable `x` in the body of `plus_one` will have the
+value `Some(5)`. We then compare that against each match arm:
```
None => None,
```
-The `Some(5)` value doesn’t match the pattern `None`, so we continue to the
-next arm.
+The `Some(5)` value doesn’t match the pattern `None` [1], so we continue to the
+next arm:
```
Some(i) => Some(i + 1),
```
-Does `Some(5)` match `Some(i)`? Why yes it does! We have the same variant. The
-`i` binds to the value contained in `Some`, so `i` takes the value `5`. The
+Does `Some(5)` match `Some(i)` [2]? Why yes, it does! We have the same variant.
+The `i` binds to the value contained in `Some`, so `i` takes the value `5`. The
code in the match arm is then executed, so we add 1 to the value of `i` and
create a new `Some` value with our total `6` inside.
Now let’s consider the second call of `plus_one` in Listing 6-5, where `x` is
-`None`. We enter the `match` and compare to the first arm.
-
-```
-None => None,
-```
+`None` [4]. We enter the `match` and compare to the first arm [1].
It matches! There’s no value to add to, so the program stops and returns the
`None` value on the right side of `=>`. Because the first arm matched, no other
@@ -704,26 +633,31 @@ a bug Rust knows how to catch. If we try to compile this code, we’ll get this
error:
```
-$ cargo run
- Compiling enums v0.1.0 (file:///projects/enums)
error[E0004]: non-exhaustive patterns: `None` not covered
- --> src/main.rs:3:15
+ --> src/main.rs:3:15
+ |
+3 | match x {
+ | ^ pattern `None` not covered
+ |
+ note: `Option<i32>` defined here
+ = note: the matched value is of type `Option<i32>`
+help: ensure that all possible cases are being handled by adding
+a match arm with a wildcard pattern or an explicit pattern as
+shown
|
-3 | match x {
- | ^ pattern `None` not covered
+4 ~ Some(i) => Some(i + 1),
+5 ~ None => todo!(),
|
- = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
- = note: the matched value is of type `Option<i32>`
```
-Rust knows that we didn’t cover every possible case and even knows which
+Rust knows that we didn’t cover every possible case, and even knows which
pattern we forgot! Matches in Rust are *exhaustive*: we must exhaust every last
possibility in order for the code to be valid. Especially in the case of
`Option<T>`, when Rust prevents us from forgetting to explicitly handle the
`None` case, it protects us from assuming that we have a value when we might
have null, thus making the billion-dollar mistake discussed earlier impossible.
-### Catch-all Patterns and the `_` Placeholder
+### Catch-all Patterns and the _ Placeholder
Using enums, we can also take special actions for a few particular values, but
for all other values take one default action. Imagine we’re implementing a game
@@ -740,7 +674,7 @@ let dice_roll = 9;
match dice_roll {
3 => add_fancy_hat(),
7 => remove_fancy_hat(),
- other => move_player(other),
+ 1 other => move_player(other),
}
fn add_fancy_hat() {}
@@ -748,10 +682,10 @@ fn remove_fancy_hat() {}
fn move_player(num_spaces: u8) {}
```
-For the first two arms, the patterns are the literal values 3 and 7. For the
-last arm that covers every other possible value, the pattern is the variable
-we’ve chosen to name `other`. The code that runs for the `other` arm uses the
-variable by passing it to the `move_player` function.
+For the first two arms, the patterns are the literal values `3` and `7`. For
+the last arm that covers every other possible value, the pattern is the
+variable we’ve chosen to name `other` [1]. The code that runs for the `other`
+arm uses the variable by passing it to the `move_player` function.
This code compiles, even though we haven’t listed all the possible values a
`u8` can have, because the last pattern will match all values not specifically
@@ -785,10 +719,10 @@ fn reroll() {}
This example also meets the exhaustiveness requirement because we’re explicitly
ignoring all other values in the last arm; we haven’t forgotten anything.
-Finally, we’ll change the rules of the game one more time, so that nothing else
+Finally, we’ll change the rules of the game one more time so that nothing else
happens on your turn if you roll anything other than a 3 or a 7. We can express
that by using the unit value (the empty tuple type we mentioned in “The Tuple
-Type†section) as the code that goes with the `_` arm:
+Type†on page XX) as the code that goes with the `_` arm:
```
let dice_roll = 9;
@@ -810,17 +744,18 @@ There’s more about patterns and matching that we’ll cover in Chapter 18. For
now, we’re going to move on to the `if let` syntax, which can be useful in
situations where the `match` expression is a bit wordy.
-## Concise Control Flow with `if let`
+## Concise Control Flow with if let
The `if let` syntax lets you combine `if` and `let` into a less verbose way to
handle values that match one pattern while ignoring the rest. Consider the
-program in Listing 6-6 that matches on an `Option<u8>` value in the `config_max`
-variable but only wants to execute code if the value is the `Some` variant.
+program in Listing 6-6 that matches on an `Option<u8>` value in the
+`config_max` variable but only wants to execute code if the value is the `Some`
+variant.
```
let config_max = Some(3u8);
match config_max {
- Some(max) => println!("The maximum is configured to be {}", max),
+ Some(max) => println!("The maximum is configured to be {max}"),
_ => (),
}
```
@@ -840,7 +775,7 @@ code behaves the same as the `match` in Listing 6-6:
```
let config_max = Some(3u8);
if let Some(max) = config_max {
- println!("The maximum is configured to be {}", max);
+ println!("The maximum is configured to be {max}");
}
```
@@ -848,7 +783,7 @@ The syntax `if let` takes a pattern and an expression separated by an equal
sign. It works the same way as a `match`, where the expression is given to the
`match` and the pattern is its first arm. In this case, the pattern is
`Some(max)`, and the `max` binds to the value inside the `Some`. We can then
-use `max` in the body of the `if let` block in the same way as we used `max` in
+use `max` in the body of the `if let` block in the same way we used `max` in
the corresponding `match` arm. The code in the `if let` block isn’t run if the
value doesn’t match the pattern.
@@ -867,7 +802,7 @@ We can include an `else` with an `if let`. The block of code that goes with the
`Coin` enum definition in Listing 6-4, where the `Quarter` variant also held a
`UsState` value. If we wanted to count all non-quarter coins we see while also
announcing the state of the quarters, we could do that with a `match`
-expression like this:
+expression, like this:
```
let mut count = 0;
@@ -877,7 +812,7 @@ match coin {
}
```
-Or we could use an `if let` and `else` expression like this:
+Or we could use an `if let` and `else` expression, like this:
```
let mut count = 0;
@@ -901,19 +836,10 @@ values, depending on how many cases you need to handle.
Your Rust programs can now express concepts in your domain using structs and
enums. Creating custom types to use in your API ensures type safety: the
-compiler will make certain your functions get only values of the type each
+compiler will make certain your functions only get values of the type each
function expects.
In order to provide a well-organized API to your users that is straightforward
to use and only exposes exactly what your users will need, let’s now turn to
Rust’s modules.
-<!--- I'm of two minds whether `?` should squeeze in here? We talk about `if
-let` but then switch topics next chapter and talk about modules. In the wild,
-I'd bet `?` would be as common, perhaps more common, than `if let`.
-
-But I'll defer to your pedagogy plan. Just wanted to share the thought.
-/JT --->
-<!-- Yeah introducing `?` here would be a big change; I don't want to talk
-about that until we've talked about `Result` even though you can use `?` on
-`Option` now, because `?` is still way more common with `Result`. /Carol -->
diff --git a/src/doc/book/nostarch/chapter07.md b/src/doc/book/nostarch/chapter07.md
index 32a9eb2fb..8b2dce777 100644
--- a/src/doc/book/nostarch/chapter07.md
+++ b/src/doc/book/nostarch/chapter07.md
@@ -20,7 +20,7 @@ optionally one library crate. As a package grows, you can extract parts into
separate crates that become external dependencies. This chapter covers all
these techniques. For very large projects comprising a set of interrelated
packages that evolve together, Cargo provides *workspaces*, which we’ll cover
-in the “Cargo Workspaces†section in Chapter 14.
+in “Cargo Workspaces†on page XX.
We’ll also discuss encapsulating implementation details, which lets you reuse
code at a higher level: once you’ve implemented an operation, other code can
@@ -43,11 +43,11 @@ organization, including which details are exposed, which details are private,
and what names are in each scope in your programs. These features, sometimes
collectively referred to as the *module system*, include:
-* **Packages:** A Cargo feature that lets you build, test, and share crates
-* **Crates:** A tree of modules that produces a library or executable
-* **Modules** and **use:** Let you control the organization, scope, and
- privacy of paths
-* **Paths:** A way of naming an item, such as a struct, function, or module
+* **Packages **: A Cargo feature that lets you build, test, and share crates
+* **Crates**: A tree of modules that produces a library or executable
+* **Modules and use**: Let you control the organization, scope, and privacy of
+paths
+* **Paths **: A way of naming an item, such as a struct, function, or module
In this chapter, we’ll cover all these features, discuss how they interact, and
explain how to use them to manage scope. By the end, you should have a solid
@@ -57,37 +57,16 @@ understanding of the module system and be able to work with scopes like a pro!
The first parts of the module system we’ll cover are packages and crates.
-<!-- Do you have a general definition of a crate we can add, or is it too
-dependent on whether it's a binary or library crate? /LC -->
-<!-- I've struggled to come up with something that isn't just "smaller than a
-package but bigger than a module"... "reusable" or "what you specify as a
-dependency" only applies to library crates... this definition I've added here
-gets a little bit into how the compiler sees crates, which might be too much
-detail? What do you think about this next paragraph? /Carol -->
-<!-- JT, what do you think? /LC -->
-<!-- I think this works.
-
-Carol - I'm wondering a bit if "packages" above helps the reader build the
-mental model or if it's kind of an implementation detail for cargo (we could
-say we "package crates"). You're definitely the expert here, but I wonder if we
-can simplify down to Crates/Modules/Paths and mention that we'll introduce some
-of the techniques the tooling uses to work with these later. /JT -->
-<!-- I feel like we need to explain the `[package]` section in *Cargo.toml*,
-and explain what the container is when you have a library and one or more
-binaries in one directory, and that's a package. It is a little weird because
-people hardly ever talk in terms of packages, only in terms of crates, but I
-think it's better to have the discussion of package here. /Carol -->
-
A *crate* is the smallest amount of code that the Rust compiler considers at a
time. Even if you run `rustc` rather than `cargo` and pass a single source code
-file (as we did all the way back in the “Writing and Running a Rust Programâ€
-section of Chapter 1), the compiler considers that file to be a crate. Crates
-can contain modules, and the modules may be defined in other files that get
-compiled with the crate, as we’ll see in the coming sections.
+file (as we did all the way back in “Writing and Running a Rust Program†on
+page XX), the compiler considers that file to be a crate. Crates can contain
+modules, and the modules may be defined in other files that get compiled with
+the crate, as we’ll see in the coming sections.
A crate can come in one of two forms: a binary crate or a library crate.
*Binary crates* are programs you can compile to an executable that you can run,
-such as a command-line program or a server. Each must have a function called
+such as a command line program or a server. Each must have a function called
`main` that defines what happens when the executable runs. All the crates we’ve
created so far have been binary crates.
@@ -95,27 +74,28 @@ created so far have been binary crates.
executable. Instead, they define functionality intended to be shared with
multiple projects. For example, the `rand` crate we used in Chapter 2 provides
functionality that generates random numbers. Most of the time when Rustaceans
-say “crateâ€, they mean library crate, and they use “crate†interchangeably with
-the general programming concept of a “library".
+say “crate,†they mean library crate, and they use “crate†interchangeably with
+the general programming concept of a “library.â€
The *crate root* is a source file that the Rust compiler starts from and makes
-up the root module of your crate (we’ll explain modules in depth in the
-“Defining Modules to Control Scope and Privacy†section).
+up the root module of your crate (we’ll explain modules in depth in “Defining
+Modules to Control Scope and Privacy†on page XX).
A *package* is a bundle of one or more crates that provides a set of
functionality. A package contains a *Cargo.toml* file that describes how to
build those crates. Cargo is actually a package that contains the binary crate
-for the command-line tool you’ve been using to build your code. The Cargo
+for the command line tool you’ve been using to build your code. The Cargo
package also contains a library crate that the binary crate depends on. Other
projects can depend on the Cargo library crate to use the same logic the Cargo
-command-line tool uses.
+command line tool uses.
-A package can contain as many binary crates as you like, but at most only one
+A crate can come in one of two forms: a binary crate or a library crate. A
+package can contain as many binary crates as you like, but at most only one
library crate. A package must contain at least one crate, whether that’s a
library or binary crate.
-Let’s walk through what happens when we create a package. First, we enter the
-command `cargo new`:
+Let’s walk through what happens when we create a package. First we enter the
+command `cargo new my-project`:
```
$ cargo new my-project
@@ -127,19 +107,15 @@ $ ls my-project/src
main.rs
```
-<!-- I can't remember if we warned folks we were going to use unix commands. May
-want to throw in the Windows command here too, so they feel welcome. /JT -->
-<!-- I don't think JT has seen chapter 1 yet, we address that there /Carol -->
-
-After we run `cargo new`, we use `ls` to see what Cargo creates. In the project
-directory, there’s a *Cargo.toml* file, giving us a package. There’s also a
-*src* directory that contains *main.rs*. Open *Cargo.toml* in your text editor,
-and note there’s no mention of *src/main.rs*. Cargo follows a convention that
-*src/main.rs* is the crate root of a binary crate with the same name as the
-package. Likewise, Cargo knows that if the package directory contains
-*src/lib.rs*, the package contains a library crate with the same name as the
-package, and *src/lib.rs* is its crate root. Cargo passes the crate root files
-to `rustc` to build the library or binary.
+After we run `cargo new my-project`, we use `ls` to see what Cargo creates. In
+the project directory, there’s a *Cargo.toml* file, giving us a package.
+There’s also a *src* directory that contains *main.rs*. Open *Cargo.toml* in
+your text editor, and note there’s no mention of *src/main.rs*. Cargo follows a
+convention that *src/main.rs* is the crate root of a binary crate with the same
+name as the package. Likewise, Cargo knows that if the package directory
+contains *src/lib.rs*, the package contains a library crate with the same name
+as the package, and *src/lib.rs* is its crate root. Cargo passes the crate root
+files to `rustc` to build the library or binary.
Here, we have a package that only contains *src/main.rs*, meaning it only
contains a binary crate named `my-project`. If a package contains *src/main.rs*
@@ -147,154 +123,103 @@ and *src/lib.rs*, it has two crates: a binary and a library, both with the same
name as the package. A package can have multiple binary crates by placing files
in the *src/bin* directory: each file will be a separate binary crate.
-## Defining Modules to Control Scope and Privacy
-
-In this section, we’ll talk about modules and other parts of the module system,
-namely *paths* that allow you to name items; the `use` keyword that brings a
-path into scope; and the `pub` keyword to make items public. We’ll also discuss
-the `as` keyword, external packages, and the glob operator.
-
-First, we’re going to start with a list of rules for easy reference when you’re
-organizing your code in the future. Then we’ll explain each of the rules in
-detail.
-
-### Modules Cheat Sheet
-
-<!--WHEN TRANSFERRED TO WORD, DECIDE ON BOX OR NOT -->
-
-Here we provide a quick reference on how modules, paths, the `use` keyword, and
-the `pub` keyword work in the compiler, and how most developers organize their
-code. We’ll be going through examples of each of these rules throughout this
-chapter, but this is a great place to refer to as a reminder of how modules
-work.
-
-- **Start from the crate root**: When compiling a crate, the compiler first
- looks in the crate root file (usually *src/lib.rs* for a library crate or
- *src/main.rs* for a binary crate) for code to compile.
- <!-- I may be asking a silly question here... but what is the compiler looking
- for in the crate root file? just things to start compiling? /LC -->
- <!-- That's exactly it-- it's the starting point of compilation, and the
- compiler will only find files if they're connected to the crate root somehow.
- Do you think that should be mentioned here? Is there something about this
- explanation that would make you feel more confident about the concept? /Carol
- -->
- <!-- I've added "for things to compile" -- I wanted to make sure the reader
- knew they weren't missing anything, that there wasn't a particular thing
- being looked for that the reader wasn't aware of /LC -->
- <!-- I changed "things" to "code" to be more precise /Carol -->
-- **Declaring modules**: In the crate root file, you can declare new modules;
-say, you declare a “garden†module with `mod garden;`. The compiler will look
+> ### Modules Cheat Sheet
+>
+> Before we get to the details of modules and paths, here we provide a quick
+reference on how modules, paths, the `use` keyword, and the `pub` keyword work
+in the compiler, and how most developers organize their code. We’ll be going
+through examples of each of these rules throughout this chapter, but this is a
+great place to refer to as a reminder of how modules work.
+>
+> * **Start from the crate root**: When compiling a crate, the compiler first
+looks in the crate root file (usually *src/lib.rs* for a library crate or
+*src/main.rs* for a binary crate) for code to compile.
+> * **Declaring modules**: In the crate root file, you can declare new modules;
+say you declare a “garden†module with `mod garden;`. The compiler will look
for the module’s code in these places:
-
- - Inline, within curly brackets that replace the semicolon following `mod
- garden`
- <!-- instead of or after the semicolon? Or is all of this instead of a
- semicolon? /LC -->
- <!-- Curly brackets and everything within them instead of the semicolon.
- I'm not sure a pithy way to make that distinction clearer? /Carol -->
- <!-- JT, would "Inline, within curly brackets that replace the semicolon
- following `mod garden` be clearer/accurate? /LC -->
- <!-- I wonder if we should order it where this cheatsheet happens after
- we show more examples. Most of the time, you'll use the `mod` keyword to
- pull files in as you refactor out into separate files. Sometimes you'll use
- it for those key cases, like grouping tests. Showing those examples and then
- going into the resolution may be a bit easier.
-
- To your question - I think of this as something that could be more of
- a warning. If you want to use `mod foo`, then be sure you haven't already
- declared a module called that in the current file. If you do, the compiler
- will see it first before it looks for a file with that name. /JT -->
- <!-- I feel pretty strongly that the cheat sheet needs to go first, so that
- after a reader's first time through the book, when they go back to the
- modules chapter to try and figure out why their modules aren't working,
- they get this first rather than having to read through or skip through the
- examples when they're already frustrated.
-
- I also don't feel like the "warning" way of talking about this belongs
- here. I almost added a section called "common mistakes" or "pitfalls" or
- "troubleshooting", and I think talking about what you *don't* want to do
- would belong there...
-
- Liz, I'm fine with your suggested wording and I've made that change. /Carol
- -->
-
- - In the file *src/garden.rs*
- - In the file *src/garden/mod.rs*
-- **Declaring submodules**: In any file other than the crate root, you can
- declare submodules. For example, you might declare `mod vegetables;` in
- *src/garden.rs*. The compiler will look for the submodule’s code within the
- directory named for the parent module in these places:
- - Inline, directly following `mod vegetables`, within curly brackets instead
- of the semicolon
- - In the file *src/garden/vegetables.rs*
- - In the file *src/garden/vegetables/mod.rs*
-- **Paths to code in modules**: Once a module is part of your crate, you can
- refer to code in that module from anywhere else in that same crate, as long
- as the privacy rules allow, using the path to the code. For example, an
- `Asparagus` type in the garden vegetables module would be found at
- `crate::garden::vegetables::Asparagus`.
-- **Private vs public**: Code within a module is private from its parent
- modules by default. To make a module public, declare it with `pub mod`
- instead of `mod`. To make items within a public module public as well, use
- `pub` before their declarations.
-- **The `use` keyword**: Within a scope, the `use` keyword creates shortcuts to
- items to reduce repetition of long paths. In any scope that can refer to
- `crate::garden::vegetables::Asparagus`, you can create a shortcut with `use
- crate::garden::vegetables::Asparagus;` and from then on you only need to
- write `Asparagus` to make use of that type in the scope.
-
-Here we create a binary crate named `backyard` that illustrates these rules. The
-crate’s directory, also named `backyard`, contains these files and directories:
-
-```
-backyard
-├── Cargo.lock
-├── Cargo.toml
-└── src
- ├── garden
- │   └── vegetables.rs
- ├── garden.rs
- └── main.rs
-```
-
-The crate root file in this case is *src/main.rs*, and it contains:
-
-Filename: src/main.rs
-
-```
-use crate::garden::vegetables::Asparagus;
-
-pub mod garden;
-
-fn main() {
- let plant = Asparagus {};
- println!("I'm growing {:?}!", plant);
-}
-```
-
-The `pub mod garden;` line tells the compiler to include the code it finds in
+>
+> * Inline, within curly brackets that replace the semicolon following `mod
+garden`
+> * In the file *src/garden.rs.*
+> * In the file *src/garden/mod.rs*
+> * **Declaring submodules**: In any file other than the crate root, you can
+declare submodules. For example, you might declare `mod vegetables;` in
+*src/garden.rs*. The compiler will look for the submodule’s code within the
+directory named for the parent module in these places:
+>
+> * Inline, directly following `mod vegetables`, within curly brackets instead
+of the semicolon
+> * In the file *src/garden/vegetables.rs*
+> * In the file *src/garden/vegetables/mod.rs*
+> * **Paths to code in modules**: Once a module is part of your crate, you can
+refer to code in that module from anywhere else in that same crate, as long as
+the privacy rules allow, using the path to the code. For example, an
+`Asparagus` type in the garden vegetables module would be found at
+`crate::garden::vegetables::Asparagus`.
+> * **Private vs. public**: Code within a module is private from its parent
+modules by default. To make a module public, declare it with `pub mod` instead
+of `mod`. To make items within a public module public as well, use `pub` before
+their declarations.
+> * **The use keyword**: Within a scope, the `use` keyword creates shortcuts to
+items to reduce repetition of long paths. In any scope that can refer to
+`crate::garden::vegetables::Asparagus`, you can create a shortcut with `use
+crate::garden::vegetables::Asparagus;` and from then on you only need to write
+`Asparagus` to make use of that type in the scope.
+>
+> Here, we create a binary crate named `backyard` that illustrates these rules.
+The crate’s directory, also named `backyard`, contains these files and
+directories:
+>
+> ```
+> backyard
+> ├── Cargo.lock
+> ├── Cargo.toml
+> └── src
+> ├── garden
+> │ └── vegetables.rs
+> ├── garden.rs
+> └── main.rs
+> ```
+>
+> The crate root file in this case is *src/main.rs*, and it contains:
+>
+> ```
+> use crate::garden::vegetables::Asparagus;
+>
+> pub mod garden;
+>
+> fn main() {
+> let plant = Asparagus {};
+> println!("I'm growing {:?}!", plant);
+> }
+> ```
+>
+> The `pub mod garden;` line tells the compiler to include the code it finds in
*src/garden.rs*, which is:
-
-Filename: src/garden.rs
-
-```
-pub mod vegetables;
-```
-
-Here, `pub mod vegetables;` means the code in *src/garden/vegetables.rs* is
+>
+> ```
+> pub mod vegetables;
+> ```
+>
+> Here, `pub mod vegetables;` means the code in *src/garden/vegetables.rs* is
included too. That code is:
+>
+> ```
+> #[derive(Debug)]
+> pub struct Asparagus {}
+> ```
+>
+> Now let’s get into the details of these rules and demonstrate them in action!
-```
-#[derive(Debug)]
-pub struct Asparagus {}
-```
-
-Now let’s get into the details of these rules and demonstrate them in action!
+## Defining Modules to Control Scope and Privacy
-### Grouping Related Code in Modules
+In this section, we’ll talk about modules and other parts of the module system,
+namely *paths*, which allow you to name items; the `use` keyword that brings a
+path into scope; and the `pub` keyword to make items public. We’ll also discuss
+the `as` keyword, external packages, and the glob operator.
*Modules* let us organize code within a crate for readability and easy reuse.
-Modules also allow us to control the *privacy* of items, because code within a
+Modules also allow us to control the *privacy* of items because code within a
module is private by default. Private items are internal implementation details
not available for outside use. We can choose to make modules and the items
within them public, which exposes them to allow external code to use and depend
@@ -302,7 +227,7 @@ on them.
As an example, let’s write a library crate that provides the functionality of a
restaurant. We’ll define the signatures of functions but leave their bodies
-empty to concentrate on the organization of the code, rather than the
+empty to concentrate on the organization of the code rather than the
implementation of a restaurant.
In the restaurant industry, some parts of a restaurant are referred to as
@@ -313,9 +238,10 @@ chefs and cooks work in the kitchen, dishwashers clean up, and managers do
administrative work.
To structure our crate in this way, we can organize its functions into nested
-modules. Create a new library named `restaurant` by running `cargo new --lib
-restaurant`; then enter the code in Listing 7-1 into *src/lib.rs* to define
-some modules and function signatures. Here’s the front of house section:
+modules. Create a new library named `restaurant` by running `cargo new
+restaurant --lib`. Then enter the code in Listing 7-1 into *src/lib.rs* to
+define some modules and function signatures; this code is the front of house
+section.
Filename: src/lib.rs
@@ -374,13 +300,13 @@ crate
Listing 7-2: The module tree for the code in Listing 7-1
-This tree shows how some of the modules nest inside one another; for example,
+This tree shows how some of the modules nest inside other modules; for example,
`hosting` nests inside `front_of_house`. The tree also shows that some modules
-are *siblings* to each other, meaning they’re defined in the same module;
-`hosting` and `serving` are siblings defined within `front_of_house`. If module
-A is contained inside module B, we say that module A is the *child* of module B
-and that module B is the *parent* of module A. Notice that the entire module
-tree is rooted under the implicit module named `crate`.
+are *siblings*, meaning they’re defined in the same module; `hosting` and
+`serving` are siblings defined within `front_of_house`. If module A is
+contained inside module B, we say that module A is the *child* of module B and
+that module B is the *parent* of module A. Notice that the entire module tree
+is rooted under the implicit module named `crate`.
The module tree might remind you of the filesystem’s directory tree on your
computer; this is a very apt comparison! Just like directories in a filesystem,
@@ -395,28 +321,27 @@ know its path.
A path can take two forms:
-* An *absolute path* is the full path starting from a crate root; for code
- from an external crate, the absolute path begins with the crate name, and for
- code from the current crate, it starts with the literal `crate`.
+* An *absolute path* is the full path starting from a crate root; for code from
+an external crate, the absolute path begins with the crate name, and for code
+from the current crate, it starts with the literal `crate`.
* A *relative path* starts from the current module and uses `self`, `super`, or
- an identifier in the current module.
+an identifier in the current module.
Both absolute and relative paths are followed by one or more identifiers
separated by double colons (`::`).
Returning to Listing 7-1, say we want to call the `add_to_waitlist` function.
This is the same as asking: what’s the path of the `add_to_waitlist` function?
-Listing 7-3 contains Listing 7-1 with some of the modules and functions
-removed.
+Listing 7-3 contains Listing 7-1 with some of the modules and functions removed.
-We’ll show two ways to call the `add_to_waitlist` function from a new function
-`eat_at_restaurant` defined in the crate root. These paths are correct, but
+We’ll show two ways to call the `add_to_waitlist` function from a new function,
+`eat_at_restaurant`, defined in the crate root. These paths are correct, but
there’s another problem remaining that will prevent this example from compiling
-as-is. We’ll explain why in a bit.
+as is. We’ll explain why in a bit.
The `eat_at_restaurant` function is part of our library crate’s public API, so
-we mark it with the `pub` keyword. In the “Exposing Paths with the `pub`
-Keyword†section, we’ll go into more detail about `pub`.
+we mark it with the `pub` keyword. In “Exposing Paths with the pub Keyword†on
+page XX, we’ll go into more detail about `pub`.
Filename: src/lib.rs
@@ -436,10 +361,6 @@ pub fn eat_at_restaurant() {
}
```
-<!-- We should probably let the reader know the above is expected to fail a
-little earlier. /JT -->
-<!-- I've rearranged a bit /Carol -->
-
Listing 7-3: Calling the `add_to_waitlist` function using absolute and relative
paths
@@ -460,20 +381,20 @@ filesystem equivalent would be using the path
that the path is relative.
Choosing whether to use a relative or absolute path is a decision you’ll make
-based on your project, and depends on whether you’re more likely to move item
-definition code separately from or together with the code that uses the item.
-For example, if we move the `front_of_house` module and the `eat_at_restaurant`
-function into a module named `customer_experience`, we’d need to update the
-absolute path to `add_to_waitlist`, but the relative path would still be valid.
-However, if we moved the `eat_at_restaurant` function separately into a module
-named `dining`, the absolute path to the `add_to_waitlist` call would stay the
-same, but the relative path would need to be updated.
-
-Our preference in general is to specify absolute paths because it’s more likely
-we’ll want to move code definitions and item calls independently of each other.
+based on your project, and it depends on whether you’re more likely to move
+item definition code separately from or together with the code that uses the
+item. For example, if we moved the `front_of_house` module and the
+`eat_at_restaurant` function into a module named `customer_experience`, we’d
+need to update the absolute path to `add_to_waitlist`, but the relative path
+would still be valid. However, if we moved the `eat_at_restaurant` function
+separately into a module named `dining`, the absolute path to the
+`add_to_waitlist` call would stay the same, but the relative path would need to
+be updated. Our preference in general is to specify absolute paths because it’s
+more likely we’ll want to move code definitions and item calls independently of
+each other.
Let’s try to compile Listing 7-3 and find out why it won’t compile yet! The
-error we get is shown in Listing 7-4.
+errors we get are shown in Listing 7-4.
```
$ cargo build
@@ -526,7 +447,7 @@ inner code you can change without breaking outer code. However, Rust does give
you the option to expose inner parts of child modules’ code to outer ancestor
modules by using the `pub` keyword to make an item public.
-### Exposing Paths with the `pub` Keyword
+### Exposing Paths with the pub Keyword
Let’s return to the error in Listing 7-4 that told us the `hosting` module is
private. We want the `eat_at_restaurant` function in the parent module to have
@@ -542,20 +463,14 @@ mod front_of_house {
}
}
-pub fn eat_at_restaurant() {
- // Absolute path
- crate::front_of_house::hosting::add_to_waitlist();
-
- // Relative path
- front_of_house::hosting::add_to_waitlist();
-}
+--snip--
```
Listing 7-5: Declaring the `hosting` module as `pub` to use it from
`eat_at_restaurant`
-Unfortunately, the code in Listing 7-5 still results in an error, as shown in
-Listing 7-6.
+Unfortunately, the code in Listing 7-5 still results in compiler errors, as
+shown in Listing 7-6.
```
$ cargo build
@@ -612,17 +527,11 @@ mod front_of_house {
}
}
-pub fn eat_at_restaurant() {
- // Absolute path
- crate::front_of_house::hosting::add_to_waitlist();
-
- // Relative path
- front_of_house::hosting::add_to_waitlist();
-}
+--snip--
```
Listing 7-7: Adding the `pub` keyword to `mod hosting` and `fn add_to_waitlist`
-lets us call the function from `eat_at_restaurant`
+lets us call the function from `eat_at_restaurant`.
Now the code will compile! To see why adding the `pub` keyword lets us use
these paths in `add_to_waitlist` with respect to the privacy rules, let’s look
@@ -650,48 +559,45 @@ If you plan on sharing your library crate so other projects can use your code,
your public API is your contract with users of your crate that determines how
they can interact with your code. There are many considerations around managing
changes to your public API to make it easier for people to depend on your
-crate. These considerations are out of the scope of this book; if you’re
-interested in this topic, see The Rust API Guidelines at
-*https://rust-lang.github.io/api-guidelines/*.
-
+crate. These considerations are beyond the scope of this book; if you’re
+interested in this topic, see the Rust API Guidelines at
+*https://rust-lang.github.io/api-guidelines*.
-> #### Best Practices for Packages with a Binary and a Library
+> ### Best Practices for Packages with a Binary and a Library
>
-> We mentioned a package can contain both a *src/main.rs* binary crate root as
-> well as a *src/lib.rs* library crate root, and both crates will have the
-> package name by default. Typically, packages with this pattern of containing
-> both a library and a binary crate will have just
-> enough code in the binary crate to start an executable that calls code with
-> the library crate. This lets other projects benefit from the most
-> functionality that the package provides, because the library crate’s code can
-> be shared.
+> We mentioned that a package can contain both a *src/main.rs* binary crate
+root as well as a *src/lib.rs* library crate root, and both crates will have
+the package name by default. Typically, packages with this pattern of
+containing both a library and a binary crate will have just enough code in the
+binary crate to start an executable that calls code with the library crate.
+This lets other projects benefit from the most functionality that the package
+provides because the library crate’s code can be shared.
>
> The module tree should be defined in *src/lib.rs*. Then, any public items can
-> be used in the binary crate by starting paths with the name of the package.
-> The binary crate becomes a user of the library crate just like a completely
-> external crate would use the library crate: it can only use the public API.
-> This helps you design a good API; not only are you the author, you’re also a
-> client!
+be used in the binary crate by starting paths with the name of the package. The
+binary crate becomes a user of the library crate just like a completely
+external crate would use the library crate: it can only use the public API.
+This helps you design a good API; not only are you the author, you’re also a
+client!
>
-> In Chapter 12, we’ll demonstrate this organizational practice with a
-> command-line program that will contain both a binary crate and a library
-> crate.
+> In Chapter 12, we’ll demonstrate this organizational practice with a command
+line program that will contain both a binary crate and a library crate.
-### Starting Relative Paths with `super`
+### Starting Relative Paths with super
We can construct relative paths that begin in the parent module, rather than
the current module or the crate root, by using `super` at the start of the
path. This is like starting a filesystem path with the `..` syntax. Using
`super` allows us to reference an item that we know is in the parent module,
which can make rearranging the module tree easier when the module is closely
-related to the parent, but the parent might be moved elsewhere in the module
+related to the parent but the parent might be moved elsewhere in the module
tree someday.
Consider the code in Listing 7-8 that models the situation in which a chef
fixes an incorrect order and personally brings it out to the customer. The
function `fix_incorrect_order` defined in the `back_of_house` module calls the
function `deliver_order` defined in the parent module by specifying the path to
-`deliver_order` starting with `super`:
+`deliver_order`, starting with `super`.
Filename: src/lib.rs
@@ -722,7 +628,7 @@ code gets moved to a different module.
### Making Structs and Enums Public
We can also use `pub` to designate structs and enums as public, but there are a
-few details extra to the usage of `pub` with structs and enums. If we use `pub`
+few extra details to the usage of `pub` with structs and enums. If we use `pub`
before a struct definition, we make the struct public, but the struct’s fields
will still be private. We can make each field public or not on a case-by-case
basis. In Listing 7-9, we’ve defined a public `back_of_house::Breakfast` struct
@@ -758,8 +664,9 @@ pub fn eat_at_restaurant() {
meal.toast = String::from("Wheat");
println!("I'd like {} toast please", meal.toast);
- // The next line won't compile if we uncomment it; we're not allowed
- // to see or modify the seasonal fruit that comes with the meal
+ // The next line won't compile if we uncomment it; we're not
+ // allowed to see or modify the seasonal fruit that comes
+ // with the meal
// meal.seasonal_fruit = String::from("blueberries");
}
```
@@ -769,7 +676,7 @@ Listing 7-9: A struct with some public fields and some private fields
Because the `toast` field in the `back_of_house::Breakfast` struct is public,
in `eat_at_restaurant` we can write and read to the `toast` field using dot
notation. Notice that we can’t use the `seasonal_fruit` field in
-`eat_at_restaurant` because `seasonal_fruit` is private. Try uncommenting the
+`eat_at_restaurant`, because `seasonal_fruit` is private. Try uncommenting the
line modifying the `seasonal_fruit` field value to see what error you get!
Also, note that because `back_of_house::Breakfast` has a private field, the
@@ -798,7 +705,7 @@ pub fn eat_at_restaurant() {
}
```
-Listing 7-10: Designating an enum as public makes all its variants public
+Listing 7-10: Designating an enum as public makes all its variants public.
Because we made the `Appetizer` enum public, we can use the `Soup` and `Salad`
variants in `eat_at_restaurant`.
@@ -813,7 +720,7 @@ There’s one more situation involving `pub` that we haven’t covered, and that
our last module system feature: the `use` keyword. We’ll cover `use` by itself
first, and then we’ll show how to combine `pub` and `use`.
-## Bringing Paths into Scope with the `use` Keyword
+## Bringing Paths into Scope with the use Keyword
Having to write out the paths to call functions can feel inconvenient and
repetitive. In Listing 7-7, whether we chose the absolute or relative path to
@@ -854,7 +761,7 @@ also check privacy, like any other paths.
Note that `use` only creates the shortcut for the particular scope in which the
`use` occurs. Listing 7-12 moves the `eat_at_restaurant` function into a new
child module named `customer`, which is then a different scope than the `use`
-statement, so the function body won’t compile:
+statement, so the function body won’t compile.
Filename: src/lib.rs
@@ -874,7 +781,7 @@ mod customer {
}
```
-Listing 7-12: A `use` statement only applies in the scope it’s in
+Listing 7-12: A `use` statement only applies in the scope it’s in.
The compiler error shows that the shortcut no longer applies within the
`customer` module:
@@ -900,11 +807,11 @@ fix this problem, move the `use` within the `customer` module too, or reference
the shortcut in the parent module with `super::hosting` within the child
`customer` module.
-### Creating Idiomatic `use` Paths
+### Creating Idiomatic use Paths
In Listing 7-11, you might have wondered why we specified `use
crate::front_of_house::hosting` and then called `hosting::add_to_waitlist` in
-`eat_at_restaurant` rather than specifying the `use` path all the way out to
+`eat_at_restaurant`, rather than specifying the `use` path all the way out to
the `add_to_waitlist` function to achieve the same result, as in Listing 7-13.
Filename: src/lib.rs
@@ -926,9 +833,9 @@ pub fn eat_at_restaurant() {
Listing 7-13: Bringing the `add_to_waitlist` function into scope with `use`,
which is unidiomatic
-Although both Listing 7-11 and 7-13 accomplish the same task, Listing 7-11 is
-the idiomatic way to bring a function into scope with `use`. Bringing the
-function’s parent module into scope with `use` means we have to specify the
+Although both Listing 7-11 and Listing 7-13 accomplish the same task, Listing
+7-11 is the idiomatic way to bring a function into scope with `use`. Bringing
+the function’s parent module into scope with `use` means we have to specify the
parent module when calling the function. Specifying the parent module when
calling the function makes it clear that the function isn’t locally defined
while still minimizing repetition of the full path. The code in Listing 7-13 is
@@ -958,7 +865,7 @@ emerged, and folks have gotten used to reading and writing Rust code this way.
The exception to this idiom is if we’re bringing two items with the same name
into scope with `use` statements, because Rust doesn’t allow that. Listing 7-15
shows how to bring two `Result` types into scope that have the same name but
-different parent modules and how to refer to them.
+different parent modules, and how to refer to them.
Filename: src/lib.rs
@@ -967,11 +874,11 @@ use std::fmt;
use std::io;
fn function1() -> fmt::Result {
- // --snip--
+ --snip--
}
fn function2() -> io::Result<()> {
- // --snip--
+ --snip--
}
```
@@ -980,10 +887,10 @@ requires using their parent modules.
As you can see, using the parent modules distinguishes the two `Result` types.
If instead we specified `use std::fmt::Result` and `use std::io::Result`, we’d
-have two `Result` types in the same scope and Rust wouldn’t know which one we
+have two `Result` types in the same scope, and Rust wouldn’t know which one we
meant when we used `Result`.
-### Providing New Names with the `as` Keyword
+### Providing New Names with the as Keyword
There’s another solution to the problem of bringing two types of the same name
into the same scope with `use`: after the path, we can specify `as` and a new
@@ -997,11 +904,11 @@ use std::fmt::Result;
use std::io::Result as IoResult;
fn function1() -> Result {
- // --snip--
+ --snip--
}
fn function2() -> IoResult<()> {
- // --snip--
+ --snip--
}
```
@@ -1012,13 +919,13 @@ In the second `use` statement, we chose the new name `IoResult` for the
that we’ve also brought into scope. Listing 7-15 and Listing 7-16 are
considered idiomatic, so the choice is up to you!
-### Re-exporting Names with `pub use`
+### Re-exporting Names with pub use
When we bring a name into scope with the `use` keyword, the name available in
the new scope is private. To enable the code that calls our code to refer to
that name as if it had been defined in that code’s scope, we can combine `pub`
-and `use`. This technique is called *re-exporting* because we’re bringing
-an item into scope but also making that item available for others to bring into
+and `use`. This technique is called *re-exporting* because we’re bringing an
+item into scope but also making that item available for others to bring into
their scope.
Listing 7-17 shows the code in Listing 7-11 with `use` in the root module
@@ -1047,7 +954,7 @@ Before this change, external code would have to call the `add_to_waitlist`
function by using the path
`restaurant::front_of_house::hosting::add_to_waitlist()`. Now that this `pub
use` has re-exported the `hosting` module from the root module, external code
-can now use the path `restaurant::hosting::add_to_waitlist()` instead.
+can use the path `restaurant::hosting::add_to_waitlist()` instead.
Re-exporting is useful when the internal structure of your code is different
from how programmers calling your code would think about the domain. For
@@ -1057,8 +964,8 @@ probably won’t think about the parts of the restaurant in those terms. With
`pub use`, we can write our code with one structure but expose a different
structure. Doing so makes our library well organized for programmers working on
the library and programmers calling the library. We’ll look at another example
-of `pub use` and how it affects your crate’s documentation in the “Exporting a
-Convenient Public API with `pub use`†section of Chapter 14.
+of `pub use` and how it affects your crate’s documentation in “Exporting a
+Convenient Public API with pub use†on page XX.
### Using External Packages
@@ -1069,29 +976,29 @@ added this line to *Cargo.toml*:
Filename: Cargo.toml
```
-rand = "0.8.3"
+rand = "0.8.5"
```
Adding `rand` as a dependency in *Cargo.toml* tells Cargo to download the
-`rand` package and any dependencies from *https://crates.io/* and make `rand`
+`rand` package and any dependencies from *https://crates.io*, and make `rand`
available to our project.
Then, to bring `rand` definitions into the scope of our package, we added a
`use` line starting with the name of the crate, `rand`, and listed the items we
-wanted to bring into scope. Recall that in the “Generating a Random Numberâ€
-section in Chapter 2, we brought the `Rng` trait into scope and called the
-`rand::thread_rng` function:
+wanted to bring into scope. Recall that in “Generating a Random Number†on page
+XX, we brought the `Rng` trait into scope and called the `rand::thread_rng`
+function:
```
use rand::Rng;
fn main() {
- let secret_number = rand::thread_rng().gen_range(1..101);
+ let secret_number = rand::thread_rng().gen_range(1..=100);
}
```
Members of the Rust community have made many packages available at
-*https://crates.io/*, and pulling any of them into your package involves these
+*https://crates.io*, and pulling any of them into your package involves these
same steps: listing them in your package’s *Cargo.toml* file and using `use` to
bring items from their crates into scope.
@@ -1108,20 +1015,20 @@ use std::collections::HashMap;
This is an absolute path starting with `std`, the name of the standard library
crate.
-### Using Nested Paths to Clean Up Large `use` Lists
+### Using Nested Paths to Clean Up Large use Lists
-If we’re using multiple items defined in the same crate or same module,
-listing each item on its own line can take up a lot of vertical space in our
-files. For example, these two `use` statements we had in the Guessing Game in
-Listing 2-4 bring items from `std` into scope:
+If we’re using multiple items defined in the same crate or same module, listing
+each item on its own line can take up a lot of vertical space in our files. For
+example, these two `use` statements we had in the guessing game in Listing 2-4
+bring items from `std` into scope:
Filename: src/main.rs
```
-// --snip--
+--snip--
use std::cmp::Ordering;
use std::io;
-// --snip--
+--snip--
```
Instead, we can use nested paths to bring the same items into scope in one
@@ -1132,9 +1039,9 @@ differ, as shown in Listing 7-18.
Filename: src/main.rs
```
-// --snip--
+--snip--
use std::{cmp::Ordering, io};
-// --snip--
+--snip--
```
Listing 7-18: Specifying a nested path to bring multiple items with the same
@@ -1187,10 +1094,9 @@ harder to tell what names are in scope and where a name used in your program
was defined.
The glob operator is often used when testing to bring everything under test
-into the `tests` module; we’ll talk about that in the “How to Write Testsâ€
-section in Chapter 11. The glob operator is also sometimes used as part of the
-prelude pattern: see the standard library documentation for more information on
-that pattern.
+into the `tests` module; we’ll talk about that in “How to Write Tests†on page
+XX. The glob operator is also sometimes used as part of the prelude pattern:
+see the standard library documentation for more information on that pattern.
## Separating Modules into Different Files
@@ -1204,7 +1110,7 @@ modules defined in the crate root file. In this case, the crate root file is
*src/lib.rs*, but this procedure also works with binary crates whose crate root
file is *src/main.rs*.
-First, we’ll extract the `front_of_house` module to its own file. Remove the
+First we’ll extract the `front_of_house` module to its own file. Remove the
code inside the curly brackets for the `front_of_house` module, leaving only
the `mod front_of_house;` declaration, so that *src/lib.rs* contains the code
shown in Listing 7-21. Note that this won’t compile until we create the
@@ -1245,18 +1151,17 @@ Note that you only need to load a file using a `mod` declaration *once* in your
module tree. Once the compiler knows the file is part of the project (and knows
where in the module tree the code resides because of where you’ve put the `mod`
statement), other files in your project should refer to the loaded file’s code
-using a path to where it was declared, as covered in the “Paths for Referring
-to an Item in the Module Tree†section. In other words, `mod` is *not* an
+using a path to where it was declared, as covered in “Paths for Referring to an
+Item in the Module Tree†on page XX. In other words, `mod` is *not* an
“include†operation that you may have seen in other programming languages.
-Next, we’ll extract the `hosting` module to its own file. The process
-is a bit different because `hosting` is a child module of `front_of_house`, not
-of the root module. We’ll place the file for `hosting` in a new directory that
-will be named for its ancestors in the module tree, in this case
-*src/front_of_house/*.
+Next, we’ll extract the `hosting` module to its own file. The process is a bit
+different because `hosting` is a child module of `front_of_house`, not of the
+root module. We’ll place the file for `hosting` in a new directory that will be
+named for its ancestors in the module tree, in this case *src/front_of_house*.
-To start moving `hosting`, we change *src/front_of_house.rs* to contain only the
-declaration of the `hosting` module:
+To start moving `hosting`, we change *src/front_of_house.rs* to contain only
+the declaration of the `hosting` module:
Filename: src/front_of_house.rs
@@ -1264,7 +1169,7 @@ Filename: src/front_of_house.rs
pub mod hosting;
```
-Then we create a *src/front_of_house* directory and a file *hosting.rs* to
+Then we create a *src/front_of_house* directory and a *hosting.rs* file to
contain the definitions made in the `hosting` module:
Filename: src/front_of_house/hosting.rs
@@ -1275,34 +1180,33 @@ pub fn add_to_waitlist() {}
If we instead put *hosting.rs* in the *src* directory, the compiler would
expect the *hosting.rs* code to be in a `hosting` module declared in the crate
-root, and not delcared as a child of the `front_of_house` module. The
-compiler’s rules for which files to check for which modules’ code means the
+root, and not declared as a child of the `front_of_house` module. The
+compiler’s rules for which files to check for which modules’ code mean the
directories and files more closely match the module tree.
-
> ### Alternate File Paths
>
> So far we’ve covered the most idiomatic file paths the Rust compiler uses,
-> but Rust also supports an older style of file path. For a module named
-> `front_of_house` declared in the crate root, the compiler will look for the
-> module’s code in:
+but Rust also supports an older style of file path. For a module named
+`front_of_house` declared in the crate root, the compiler will look for the
+module’s code in:
>
> * *src/front_of_house.rs* (what we covered)
> * *src/front_of_house/mod.rs* (older style, still supported path)
>
> For a module named `hosting` that is a submodule of `front_of_house`, the
-> compiler will look for the module’s code in:
+compiler will look for the module’s code in:
>
> * *src/front_of_house/hosting.rs* (what we covered)
> * *src/front_of_house/hosting/mod.rs* (older style, still supported path)
>
-> If you use both styles for the same module, you’ll get a compiler error. Using
-> a mix of both styles for different modules in the same project is allowed, but
-> might be confusing for people navigating your project.
+> If you use both styles for the same module, you’ll get a compiler error.
+Using a mix of both styles for different modules in the same project is
+allowed, but might be confusing for people navigating your project.
>
> The main downside to the style that uses files named *mod.rs* is that your
-> project can end up with many files named *mod.rs*, which can get confusing
-> when you have them open in your editor at the same time.
+project can end up with many files named *mod.rs*, which can get confusing when
+you have them open in your editor at the same time.
We’ve moved each module’s code to a separate file, and the module tree remains
the same. The function calls in `eat_at_restaurant` will work without any
@@ -1317,8 +1221,8 @@ that module.
## Summary
-Rust lets you split a package into multiple crates and a crate into modules
-so you can refer to items defined in one module from another module. You can do
+Rust lets you split a package into multiple crates and a crate into modules so
+you can refer to items defined in one module from another module. You can do
this by specifying absolute or relative paths. These paths can be brought into
scope with a `use` statement so you can use a shorter path for multiple uses of
the item in that scope. Module code is private by default, but you can make
@@ -1326,3 +1230,4 @@ definitions public by adding the `pub` keyword.
In the next chapter, we’ll look at some collection data structures in the
standard library that you can use in your neatly organized code.
+
diff --git a/src/doc/book/nostarch/chapter08.md b/src/doc/book/nostarch/chapter08.md
index 1c7968c99..c44ebd8f7 100644
--- a/src/doc/book/nostarch/chapter08.md
+++ b/src/doc/book/nostarch/chapter08.md
@@ -20,9 +20,9 @@ collections that are used very often in Rust programs:
* A *vector* allows you to store a variable number of values next to each other.
* A *string* is a collection of characters. We’ve mentioned the `String` type
- previously, but in this chapter we’ll talk about it in depth.
-* A *hash map* allows you to associate a value with a particular key. It’s a
- particular implementation of the more general data structure called a *map*.
+previously, but in this chapter we’ll talk about it in depth.
+* A *hash map* allows you to associate a value with a specific key. It’s a
+particular implementation of the more general data structure called a *map*.
To learn about the other kinds of collections provided by the standard library,
see the documentation at *https://doc.rust-lang.org/std/collections/index.html*.
@@ -63,8 +63,8 @@ the type of value you want to store, so you rarely need to do this type
annotation. Rust conveniently provides the `vec!` macro, which will create a
new vector that holds the values you give it. Listing 8-2 creates a new
`Vec<i32>` that holds the values `1`, `2`, and `3`. The integer type is `i32`
-because that’s the default integer type, as we discussed in the “Data Typesâ€
-section of Chapter 3.
+because that’s the default integer type, as we discussed in “Data Types†on
+page XX.
```
let v = vec![1, 2, 3];
@@ -97,26 +97,9 @@ make it mutable using the `mut` keyword, as discussed in Chapter 3. The numbers
we place inside are all of type `i32`, and Rust infers this from the data, so
we don’t need the `Vec<i32>` annotation.
-<!--
-I think people from other languages may get stuck a bit here because this is
-the first time (I think?) that we're showing a hindley-milner style type
-inference in action (rather than using the initializer to infer the type).
-
-Should we show the definition for `push`? That'd let us tie together the method
-call, mutable reference to self drawing on the `impl` we saw in earlier
-chapters and help to explain a little why the above works without having to
-annotate the type of the Vec.
-/JT --->
-<!-- I think readers would be more confused showing the definition of `push`
-here because we haven't covered generics yet. I haven't gotten comments about
-people being confused at this point (which doesn't mean they aren't), but
-personally when I learned this, it made sense to me that the type of the vector
-would be known from what I put in it. I'm leaning towards not elaborating here.
-/Carol -->
-
### Reading Elements of Vectors
-There are two ways to reference a value stored in a vector: via indexing or
+There are two ways to reference a value stored in a vector: via indexing or by
using the `get` method. In the following examples, we’ve annotated the types of
the values that are returned from these functions for extra clarity.
@@ -126,18 +109,18 @@ syntax and the `get` method.
```
let v = vec![1, 2, 3, 4, 5];
-[1] let third: &i32 = &v[2];
-println!("The third element is {}", third);
+1 let third: &i32 = &v[2];
+println!("The third element is {third}");
-[2] let third: Option<&i32> = v.get(2);
+2 let third: Option<&i32> = v.get(2);
match third {
- Some(third) => println!("The third element is {}", third),
+ Some(third) => println!("The third element is {third}"),
None => println!("There is no third element."),
}
```
-Listing 8-4: Using indexing syntax or the `get` method to access an item in a
-vector
+Listing 8-4: Using indexing syntax and using the `get` method to access an item
+in a vector
Note a few details here. We use the index value of `2` to get the third element
[1] because vectors are indexed by number, starting at zero. Using `&` and `[]`
@@ -145,18 +128,11 @@ gives us a reference to the element at the index value. When we use the `get`
method with the index passed as an argument [2], we get an `Option<&T>` that we
can use with `match`.
-<!---
-I think it should be "Second, we get the third element by using both `&` and
-`[]`"
-/JT --->
-<!-- No, it shouldn't, but I reworded this whole paragraph and added wingdings
-because it was unclear /Carol -->
-
-The reason Rust provides these two ways to reference an element is so you can
-choose how the program behaves when you try to use an index value outside the
-range of existing elements. As an example, let’s see what happens when we have
-a vector of five elements and then we try to access an element at index 100
-with each technique, as shown in Listing 8-5.
+Rust provides these two ways to reference an element so you can choose how the
+program behaves when you try to use an index value outside the range of
+existing elements. As an example, let’s see what happens when we have a vector
+of five elements and then we try to access an element at index 100 with each
+technique, as shown in Listing 8-5.
```
let v = vec![1, 2, 3, 4, 5];
@@ -191,7 +167,7 @@ rule that states you can’t have mutable and immutable references in the same
scope. That rule applies in Listing 8-6, where we hold an immutable reference
to the first element in a vector and try to add an element to the end. This
program won’t work if we also try to refer to that element later in the
-function:
+function.
```
let mut v = vec![1, 2, 3, 4, 5];
@@ -200,7 +176,7 @@ let first = &v[0];
v.push(6);
-println!("The first element is: {}", first);
+println!("The first element is: {first}");
```
Listing 8-6: Attempting to add an element to a vector while holding a reference
@@ -209,6 +185,8 @@ to an item
Compiling this code will result in this error:
```
+error[E0502]: cannot borrow `v` as mutable because it is also borrowed as
+immutable
--> src/main.rs:6:5
|
4 | let first = &v[0];
@@ -217,8 +195,8 @@ Compiling this code will result in this error:
6 | v.push(6);
| ^^^^^^^^^ mutable borrow occurs here
7 |
-8 | println!("The first element is: {}", first);
- | ----- immutable borrow later used here
+8 | println!("The first element is: {first}");
+ | ----- immutable borrow later used here
```
The code in Listing 8-6 might look like it should work: why should a reference
@@ -232,9 +210,9 @@ pointing to deallocated memory. The borrowing rules prevent programs from
ending up in that situation.
> Note: For more on the implementation details of the `Vec<T>` type, see “The
-> Rustonomicon†at *https://doc.rust-lang.org/nomicon/vec/vec.html*.
+Rustonomicon†at *https://doc.rust-lang.org/nomicon/vec/vec.html*.
-### Iterating over the Values in a Vector
+### Iterating Over the Values in a Vector
To access each element in a vector in turn, we would iterate through all of the
elements rather than use indices to access one at a time. Listing 8-7 shows how
@@ -244,7 +222,7 @@ to use a `for` loop to get immutable references to each element in a vector of
```
let v = vec![100, 32, 57];
for i in &v {
- println!("{}", i);
+ println!("{i}");
}
```
@@ -265,10 +243,9 @@ for i in &mut v {
Listing 8-8: Iterating over mutable references to elements in a vector
To change the value that the mutable reference refers to, we have to use the
-`*` dereference operator to get to the value in `i` before we can use the
-`+=` operator. We’ll talk more about the dereference operator in the
-“Following the Pointer to the Value with the Dereference Operatorâ€
-section of Chapter 15.
+`*` dereference operator to get to the value in `i` before we can use the `+=`
+operator. We’ll talk more about the dereference operator in “Following the
+Pointer to the Value†on page XX.
Iterating over a vector, whether immutably or mutably, is safe because of the
borrow checker’s rules. If we attempted to insert or remove items in the `for`
@@ -277,37 +254,13 @@ similar to the one we got with the code in Listing 8-6. The reference to the
vector that the `for` loop holds prevents simultaneous modification of the
whole vector.
-<!--
-Maybe worth a mention: the above use of the mutable reference while you iterate
-is perfectly safe because there's no changing that's happening to the vector
-that would invalidate the iterator. But, if you wanted to iterate the vector
-while also trying to remove or insert elements, you'd get an error. For example:
-
-```
-let mut v = vec![100, 32, 57];
-for i in &mut v {
- *i += 50;
- if *i > 100 {
- v.push(10); // <-- a second mutable reference is needed and will fail to compile
- }
-}
-```
-
-Things like this help Rust prevent some classic C++ issues where people didn't
-think about the implications of growing/shrinking a container while iterating
-over it.
-/JT --->
-<!-- I thought Listing 8-6 covered this, but I can see how driving home the
-connection with iteration as well is worthwhile so I added a paragraph just
-before this comment. Please check for clarity Liz! /Carol -->
-
### Using an Enum to Store Multiple Types
-Vectors can only store values that are the same type. This can be inconvenient;
-there are definitely use cases for needing to store a list of items of
-different types. Fortunately, the variants of an enum are defined under the
-same enum type, so when we need one type to represent elements of different
-types, we can define and use an enum!
+Vectors can only store values that are of the same type. This can be
+inconvenient; there are definitely use cases for needing to store a list of
+items of different types. Fortunately, the variants of an enum are defined
+under the same enum type, so when we need one type to represent elements of
+different types, we can define and use an enum!
For example, say we want to get values from a row in a spreadsheet in which
some of the columns in the row contain integers, some floating-point numbers,
@@ -330,8 +283,7 @@ let row = vec![
];
```
-Listing 8-9: Defining an `enum` to store values of different types in one
-vector
+Listing 8-9: Defining an `enum` to store values of different types in one vector
Rust needs to know what types will be in the vector at compile time so it knows
exactly how much memory on the heap will be needed to store each element. We
@@ -346,7 +298,7 @@ store in a vector, the enum technique won’t work. Instead, you can use a trait
object, which we’ll cover in Chapter 17.
Now that we’ve discussed some of the most common ways to use vectors, be sure
-to review the API documentation for all the many useful methods defined on
+to review the API documentation for all of the many useful methods defined on
`Vec<T>` by the standard library. For example, in addition to `push`, a `pop`
method removes and returns the last element.
@@ -372,19 +324,6 @@ valid.
Let’s move on to the next collection type: `String`!
-<!--
-nit: I think "meaning the integers it holds will be cleaned up" reads a little
-better
-
-nit #2: imho dropping isn't as imports when you start using vectors as reading
-elements from the vector. Is it better for training to mention it here, or
-would it be possible to move it later?
-/JT -->
-<!-- Took both nit suggestions-- reworded for nit #1 and moved this section to
-the end of the Vec section (and renumbered the listings) for nit #2. Liz,
-please check to make sure I didn't miss anything in the way the Vec section
-flows now! /Carol -->
-
## Storing UTF-8 Encoded Text with Strings
We talked about strings in Chapter 4, but we’ll look at them in more depth now.
@@ -420,22 +359,10 @@ of those types. Although this section is largely about `String`, both types are
used heavily in Rust’s standard library, and both `String` and string slices
are UTF-8 encoded.
-<!---
-I'm wondering if listing the above makes it a bit more cumbersome. In effect,
-out of gate we're saying there are a lot of different string types.
-
-But perhaps we could focus on String and &str here and let them learn about
-CString/CStr when doing FFI and OsString/OsStr when they work on paths?
-Basically, I'm wondering if we should cut down on the concept count and let
-them come across those alternate strings more naturally.
-/JT --->
-<!-- I'm ok with that! I removed the paragraph talking about the other, rarer
-string types. /Carol -->
-
### Creating a New String
Many of the same operations available with `Vec<T>` are available with `String`
-as well, because `String` is actually implemented as a wrapper around a vector
+as well because `String` is actually implemented as a wrapper around a vector
of bytes with some extra guarantees, restrictions, and capabilities. An example
of a function that works the same way with `Vec<T>` and `String` is the `new`
function to create an instance, shown in Listing 8-11.
@@ -446,9 +373,9 @@ let mut s = String::new();
Listing 8-11: Creating a new, empty `String`
-This line creates a new empty string called `s`, which we can then load data
-into. Often, we’ll have some initial data that we want to start the string
-with. For that, we use the `to_string` method, which is available on any type
+This line creates a new, empty string called `s`, into which we can then load
+data. Often, we’ll have some initial data with which we want to start the
+string. For that, we use the `to_string` method, which is available on any type
that implements the `Display` trait, as string literals do. Listing 8-12 shows
two examples.
@@ -467,7 +394,7 @@ literal
This code creates a string containing `initial contents`.
We can also use the function `String::from` to create a `String` from a string
-literal. The code in Listing 8-13 is equivalent to the code from Listing 8-12
+literal. The code in Listing 8-13 is equivalent to the code in Listing 8-12
that uses `to_string`.
```
@@ -480,7 +407,7 @@ string literal
Because strings are used for so many things, we can use many different generic
APIs for strings, providing us with a lot of options. Some of them can seem
redundant, but they all have their place! In this case, `String::from` and
-`to_string` do the same thing, so which you choose is a matter of style and
+`to_string` do the same thing, so which one you choose is a matter of style and
readability.
Remember that strings are UTF-8 encoded, so we can include any properly encoded
@@ -510,7 +437,7 @@ A `String` can grow in size and its contents can change, just like the contents
of a `Vec<T>`, if you push more data into it. In addition, you can conveniently
use the `+` operator or the `format!` macro to concatenate `String` values.
-#### Appending to a String with `push_str` and `push`
+#### Appending to a String with push_str and push
We can grow a `String` by using the `push_str` method to append a string slice,
as shown in Listing 8-15.
@@ -531,7 +458,7 @@ parameter. For example, in the code in Listing 8-16, we want to be able to use
let mut s1 = String::from("foo");
let s2 = "bar";
s1.push_str(s2);
-println!("s2 is {}", s2);
+println!("s2 is {s2}");
```
Listing 8-16: Using a string slice after appending its contents to a `String`
@@ -540,7 +467,7 @@ If the `push_str` method took ownership of `s2`, we wouldn’t be able to print
its value on the last line. However, this code works as we’d expect!
The `push` method takes a single character as a parameter and adds it to the
-`String`. Listing 8-17 adds the letter "l" to a `String` using the `push`
+`String`. Listing 8-17 adds the letter *l* to a `String` using the `push`
method.
```
@@ -552,7 +479,7 @@ Listing 8-17: Adding one character to a `String` value using `push`
As a result, `s` will contain `lol`.
-#### Concatenation with the `+` Operator or the `format!` Macro
+#### Concatenation with the + Operator or the format! Macro
Often, you’ll want to combine two existing strings. One way to do so is to use
the `+` operator, as shown in Listing 8-18.
@@ -579,8 +506,8 @@ fn add(self, s: &str) -> String {
In the standard library, you’ll see `add` defined using generics and associated
types. Here, we’ve substituted in concrete types, which is what happens when we
call this method with `String` values. We’ll discuss generics in Chapter 10.
-This signature gives us the clues we need to understand the tricky bits of the
-`+` operator.
+This signature gives us the clues we need in order to understand the tricky
+bits of the `+` operator.
First, `s2` has an `&`, meaning that we’re adding a *reference* of the second
string to the first string. This is because of the `s` parameter in the `add`
@@ -588,29 +515,6 @@ function: we can only add a `&str` to a `String`; we can’t add two `String`
values together. But wait—the type of `&s2` is `&String`, not `&str`, as
specified in the second parameter to `add`. So why does Listing 8-18 compile?
-<!--
-The above isn't quite right - the trait for ops::Add uses an Rhs associated type
-instead of using T for both lhs and rhs.
-
-```
-pub trait Add<Rhs = Self> {
- type Output;
- fn add(self, rhs: Rhs) -> Self::Output;
-}
-```
-
-The implementation of Add for String fills in Rhs with the slice:
-
-```
-impl<'_> Add<&'_ str> for String
-```
-
-Not sure if it's better to fix the description and not have deref coercion
-discussion following, or fix the example so you can have the coercion
-discussion.
-/JT --->
-<!-- I've made an edit above to address this /Carol -->
-
The reason we’re able to use `&s2` in the call to `add` is that the compiler
can *coerce* the `&String` argument into a `&str`. When we call the `add`
method, Rust uses a *deref coercion*, which here turns `&s2` into `&s2[..]`.
@@ -618,13 +522,13 @@ We’ll discuss deref coercion in more depth in Chapter 15. Because `add` does
not take ownership of the `s` parameter, `s2` will still be a valid `String`
after this operation.
-Second, we can see in the signature that `add` takes ownership of `self`,
+Second, we can see in the signature that `add` takes ownership of `self`
because `self` does *not* have an `&`. This means `s1` in Listing 8-18 will be
-moved into the `add` call and will no longer be valid after that. So although
+moved into the `add` call and will no longer be valid after that. So, although
`let s3 = s1 + &s2;` looks like it will copy both strings and create a new one,
this statement actually takes ownership of `s1`, appends a copy of the contents
of `s2`, and then returns ownership of the result. In other words, it looks
-like it’s making a lot of copies but isn’t; the implementation is more
+like it’s making a lot of copies, but it isn’t; the implementation is more
efficient than copying.
If we need to concatenate multiple strings, the behavior of the `+` operator
@@ -639,15 +543,15 @@ let s = s1 + "-" + &s2 + "-" + &s3;
```
At this point, `s` will be `tic-tac-toe`. With all of the `+` and `"`
-characters, it’s difficult to see what’s going on. For more complicated string
-combining, we can instead use the `format!` macro:
+characters, it’s difficult to see what’s going on. For combining strings in
+more complicated ways, we can instead use the `format!` macro:
```
let s1 = String::from("tic");
let s2 = String::from("tac");
let s3 = String::from("toe");
-let s = format!("{}-{}-{}", s1, s2, s3);
+let s = format!("{s1}-{s2}-{s3}");
```
This code also sets `s` to `tic-tac-toe`. The `format!` macro works like
@@ -668,7 +572,7 @@ let s1 = String::from("hello");
let h = s1[0];
```
-Listing 8-19: Attempting to use indexing syntax with a String
+Listing 8-19: Attempting to use indexing syntax with a `String`
This code will result in the following error:
@@ -679,7 +583,8 @@ error[E0277]: the type `String` cannot be indexed by `{integer}`
3 | let h = s1[0];
| ^^^^^ `String` cannot be indexed by `{integer}`
|
- = help: the trait `Index<{integer}>` is not implemented for `String`
+ = help: the trait `Index<{integer}>` is not implemented for
+`String`
```
The error and the note tell the story: Rust strings don’t support indexing. But
@@ -695,20 +600,21 @@ encoded UTF-8 example strings from Listing 8-14. First, this one:
let hello = String::from("Hola");
```
-In this case, `len` will be 4, which means the vector storing the string “Holaâ€
-is 4 bytes long. Each of these letters takes 1 byte when encoded in UTF-8. The
-following line, however, may surprise you. (Note that this string begins with
-the capital Cyrillic letter Ze, not the Arabic number 3.)
+In this case, `len` will be `4`, which means the vector storing the string
+`"Hola"` is 4 bytes long. Each of these letters takes one byte when encoded in
+UTF-8. The following line, however, may surprise you (note that this string
+begins with the capital Cyrillic letter *Ze*, not the Arabic number 3):
```
let hello = String::from("ЗдравÑтвуйте");
```
-Asked how long the string is, you might say 12. In fact, Rust’s answer is 24:
-that’s the number of bytes it takes to encode “ЗдравÑтвуйте†in UTF-8, because
-each Unicode scalar value in that string takes 2 bytes of storage. Therefore,
-an index into the string’s bytes will not always correlate to a valid Unicode
-scalar value. To demonstrate, consider this invalid Rust code:
+If you were asked how long the string is, you might say 12. In fact, Rust’s
+answer is 24: that’s the number of bytes it takes to encode “ЗдравÑтвуйте†in
+UTF-8, because each Unicode scalar value in that string takes 2 bytes of
+storage. Therefore, an index into the string’s bytes will not always correlate
+to a valid Unicode scalar value. To demonstrate, consider this invalid Rust
+code:
```
let hello = "ЗдравÑтвуйте";
@@ -738,8 +644,8 @@ If we look at the Hindi word “नमसà¥à¤¤à¥‡â€ written in the Devanagari
stored as a vector of `u8` values that looks like this:
```
-[224, 164, 168, 224, 164, 174, 224, 164, 184, 224, 165, 141, 224, 164, 164,
-224, 165, 135]
+[224, 164, 168, 224, 164, 174, 224, 164, 184, 224, 165, 141, 224,
+164, 164, 224, 165, 135]
```
That’s 18 bytes and is how computers ultimately store this data. If we look at
@@ -785,8 +691,8 @@ let hello = "ЗдравÑтвуйте";
let s = &hello[0..4];
```
-Here, `s` will be a `&str` that contains the first 4 bytes of the string.
-Earlier, we mentioned that each of these characters was 2 bytes, which means
+Here, `s` will be a `&str` that contains the first four bytes of the string.
+Earlier, we mentioned that each of these characters was two bytes, which means
`s` will be `Зд`.
If we were to try to slice only part of a character’s bytes with something like
@@ -794,55 +700,29 @@ If we were to try to slice only part of a character’s bytes with something lik
index were accessed in a vector:
```
-thread 'main' panicked at 'byte index 1 is not a char boundary; it is inside 'З' (bytes 0..2) of `ЗдравÑтвуйте`', src/main.rs:4:14
+thread 'main' panicked at 'byte index 1 is not a char boundary;
+it is inside 'З' (bytes 0..2) of `ЗдравÑтвуйте`', src/main.rs:4:14
```
-You should use ranges to create string slices with caution, because doing so
-can crash your program.
+You should use caution when creating string slices with ranges, because doing
+so can crash your program.
### Methods for Iterating Over Strings
-<!--- is there a reason this comes after how to slice, rather than after the
-discussion on why we can't directly index into a string? /LC --->
-<!-- I think the idea was that we show this progression of from worst technique
-to best:
-
-1. direct indexing, which doesn't compile
-2. slicing with a range, which looks similar to indexing, which does compile
-but might panic at runtime
-3. iterating over chars or bytes, which compiles and won't panic
-
-Do you have suggestions on making this clearer? I've tried to add a bit at the
-beginning of this section /Carol
--->
-<!-- JT, what do you think -- is this ordering clear to you? /LC -->
-<!---
-I'm okay with the current order - I think showing why it's bad, what's close to
-what you try first, and then finally the idiomatic Rust solution reads okay.
-
-One tiny nit, for flow, would be to use the Cyrillic example first here to show
-how `.chars()` works well for it and then mention that for more complex
-scripts, like Hindi, you'll need to use the more full-featured string handling
-you find on crates.io.
-/JT --->
-<!-- I've taken JT's suggestion here to use part of the Cyrillic string, then
-mention you'll need a crate to correctly get the grapheme clusters for Hindi
-/Carol -->
-
The best way to operate on pieces of strings is to be explicit about whether
you want characters or bytes. For individual Unicode scalar values, use the
-`chars` method. Calling `chars` on “Зд†separates out and returns two values
-of type `char`, and you can iterate over the result to access each element:
+`chars` method. Calling `chars` on “Зд†separates out and returns two values of
+type `char`, and you can iterate over the result to access each element:
-```rust
+```
for c in "Зд".chars() {
- println!("{}", c);
+ println!("{c}");
}
```
This code will print the following:
-```text
+```
З
д
```
@@ -850,15 +730,15 @@ This code will print the following:
Alternatively, the `bytes` method returns each raw byte, which might be
appropriate for your domain:
-```rust
+```
for b in "Зд".bytes() {
- println!("{}", b);
+ println!("{b}");
}
```
This code will print the four bytes that make up this string:
-```text
+```
208
151
208
@@ -866,41 +746,19 @@ This code will print the four bytes that make up this string:
```
But be sure to remember that valid Unicode scalar values may be made up of more
-than 1 byte.
+than one byte.
-Getting grapheme clusters from strings as with the Devanagari script is
+Getting grapheme clusters from strings, as with the Devanagari script, is
complex, so this functionality is not provided by the standard library. Crates
-are available on *https://crates.io/* if this is the functionality you need.
+are available at *https://crates.io* if this is the functionality you need.
### Strings Are Not So Simple
-<!---
-Because Strings are quite complicated, and have complications that are all
-their own and unlike any other containers, I wonder if maybe this chapter
-should be two different chapters with one specifically being about strings,
-string slices, chars, and related?
-/JT --->
-<!-- I don't think I want to make that big of a change at this point... the
-original idea was to compare and contrast the different containers, perhaps
-that's not serving its purpose as well as a chapter split could... I'll think
-about this for the next major revision. /Carol -->
-
-<!---
-We don't talk about searching in a string. Feels like it could use an example
-or two?
-/JT --->
-<!-- To address this suggestion and a bit of the previous suggestion as well, I
-changed the first paragraph in the "Creating a New String" section to mention
-that a `String` is implemented using a `Vec`. Then, to echo the last paragraph
-before the "Dropping a Vector Drops Its Elements" section, I've added some text
-here to again urge the reader to check out the standard library documentation
-for more functionality. /Carol -->
-
To summarize, strings are complicated. Different programming languages make
different choices about how to present this complexity to the programmer. Rust
has chosen to make the correct handling of `String` data the default behavior
for all Rust programs, which means programmers have to put more thought into
-handling UTF-8 data upfront. This trade-off exposes more of the complexity of
+handling UTF-8 data up front. This trade-off exposes more of the complexity of
strings than is apparent in other programming languages, but it prevents you
from having to handle errors involving non-ASCII characters later in your
development life cycle.
@@ -916,11 +774,11 @@ Let’s switch to something a bit less complex: hash maps!
## Storing Keys with Associated Values in Hash Maps
The last of our common collections is the *hash map*. The type `HashMap<K, V>`
-stores a mapping of keys of type `K` to values of type `V` using a
-*hashing function*, which determines how it places these keys and values into
-memory. Many programming languages support this kind of data structure, but
-they often use a different name, such as hash, map, object, hash table,
-dictionary, or associative array, just to name a few.
+stores a mapping of keys of type `K` to values of type `V` using a *hashing
+function*, which determines how it places these keys and values into memory.
+Many programming languages support this kind of data structure, but they often
+use a different name, such as *hash*, *map*, *object*, *hash table*,
+*dictionary*, or *associative array*, just to name a few.
Hash maps are useful when you want to look up data not by using an index, as
you can with vectors, but by using a key that can be of any type. For example,
@@ -934,7 +792,7 @@ As always, check the standard library documentation for more information.
### Creating a New Hash Map
-One way to create an empty hash map is using `new` and adding elements with
+One way to create an empty hash map is to use `new` and to add elements with
`insert`. In Listing 8-20, we’re keeping track of the scores of two teams whose
names are *Blue* and *Yellow*. The Blue team starts with 10 points, and the
Yellow team starts with 50.
@@ -958,25 +816,11 @@ standard library; there’s no built-in macro to construct them, for example.
Just like vectors, hash maps store their data on the heap. This `HashMap` has
keys of type `String` and values of type `i32`. Like vectors, hash maps are
-homogeneous: all of the keys must have the same type as each other, and all of
-the values must have the same type.
-
-<!---
-I'm not sure I've seen this in the wild? I'm tempted to say to skip the zip
-example for flow and go from creating the hash map to working with its
-contents.
-/JT --->
-<!-- Cut Listing 8-21 and renumbered! /Carol -->
+homogeneous: all of the keys must have the same type, and all of the values
+must have the same type.
### Accessing Values in a Hash Map
-<!---
-For flow, would it make sense for this section to follow creating the hash map?
-That way we introduce a useful concept and also continue the teams example.
-/JT --->
-<!-- Ok, I've switched the order of "Accessing Values in a Hash Map" and "Hash
-Maps and Ownership" and renumbered! Does this still make sense Liz? /Carol -->
-
We can get a value out of the hash map by providing its key to the `get`
method, as shown in Listing 8-21.
@@ -989,7 +833,7 @@ scores.insert(String::from("Blue"), 10);
scores.insert(String::from("Yellow"), 50);
let team_name = String::from("Blue");
-let score = scores.get(&team_name).unwrap_or(0);
+let score = scores.get(&team_name).copied().unwrap_or(0);
```
Listing 8-21: Accessing the score for the Blue team stored in the hash map
@@ -997,17 +841,11 @@ Listing 8-21: Accessing the score for the Blue team stored in the hash map
Here, `score` will have the value that’s associated with the Blue team, and the
result will be `10`. The `get` method returns an `Option<&V>`; if there’s no
value for that key in the hash map, `get` will return `None`. This program
-handles the `Option` by calling `unwrap_or` to set `score` to zero if `scores`
-doesn’t have an entry for the key.
-
-<!---
-Should there be a quick example here to show handling Some/None again before
-we move on to iteration?
-/JT --->
-<!-- I've changed the code in Listing 8-21 a bit to actually handle the
-`Option` instead of referencing chapter 6, what do you think Liz? /Carol -->
+handles the `Option` by calling `copied` to get an `Option<i32>` rather than an
+`Option<&i32>`, then `unwrap_or` to set `score` to zero if `scores` doesn’t
+have an entry for the key.
-We can iterate over each key/value pair in a hash map in a similar manner as we
+We can iterate over each key–value pair in a hash map in a similar manner as we
do with vectors, using a `for` loop:
```
@@ -1019,7 +857,7 @@ scores.insert(String::from("Blue"), 10);
scores.insert(String::from("Yellow"), 50);
for (key, value) in &scores {
- println!("{}: {}", key, value);
+ println!("{key}: {value}");
}
```
@@ -1044,8 +882,8 @@ let field_value = String::from("Blue");
let mut map = HashMap::new();
map.insert(field_name, field_value);
-// field_name and field_value are invalid at this point, try using them and
-// see what compiler error you get!
+// field_name and field_value are invalid at this point, try
+// using them and see what compiler error you get!
```
Listing 8-22: Showing that keys and values are owned by the hash map once
@@ -1057,40 +895,14 @@ they’ve been moved into the hash map with the call to `insert`.
If we insert references to values into the hash map, the values won’t be moved
into the hash map. The values that the references point to must be valid for at
least as long as the hash map is valid. We’ll talk more about these issues in
-the “Validating References with Lifetimes†section in Chapter 10.
+“Validating References with Lifetimes†on page XX.
### Updating a Hash Map
Although the number of key and value pairs is growable, each unique key can
only have one value associated with it at a time (but not vice versa: for
-example, both the Blue team and the Yellow team could have value 10 stored in
-the `scores` hash map).
-<!--- And vice versa? /LC --->
-<!-- No, you could have a hashmap that has ("Blue", 10) and ("Yellow", 10) for
-example. Stating this here feels a bit off topic for updating the value of an
-existing key, though, I'm not sure how to work it in. Do you think that's
-important enough to state here? If so, do you have suggestions on how to do it
-without distracting from the main point of this section? /Carol -->
-<!-- It may not be important enough, what do you think JT? /LC -->
-<!---
-I think it's maybe worth calling out. Something you could use to drive
-this home is the `.entry()` call. This makes it clear that for any key there's
-one cell (or entry) that you're updating in the hash map. I see we use it
-later, though worth a thought if bringing it earlier helps?
-/JT --->
-<!-- I've added a short sentence here, but every time I try to add something
-more, I end up getting tangled in saying things like "key value" as opposed to
-"value value", which is terrible... or I worry about misleading readers into
-thinking that you can't use a `Vec<T>` as a HashMap value type, which you
-totally can to store multiple "values" in one vector "value", which you totally
-can, it's just a little more complicated. Or I try to say "multiple keys can
-have the same value" which sounds like it could imply that there would be a
-*shared* value stored in the HashMap, which wouldn't be the case, there would
-be two separate allocations that would happen to have the same value... I just
-haven't heard a reader wondering if each value can only have one key with it
-before (which doesn't mean they haven't wondered it, I just haven't heard of
-it) so I don't want to lead readers astray if they weren't already going that
-direction? What do you think about what's here now, Liz? /Carol -->
+example, both the Blue team and the Yellow team could have the value `10`
+stored in the `scores` hash map).
When you want to change the data in a hash map, you have to decide how to
handle the case when a key already has a value assigned. You could replace the
@@ -1104,7 +916,7 @@ new value. Let’s look at how to do each of these!
If we insert a key and a value into a hash map and then insert that same key
with a different value, the value associated with that key will be replaced.
Even though the code in Listing 8-23 calls `insert` twice, the hash map will
-only contain one key/value pair because we’re inserting the value for the Blue
+only contain one key–value pair because we’re inserting the value for the Blue
team’s key both times.
```
@@ -1125,47 +937,16 @@ overwritten.
#### Adding a Key and Value Only If a Key Isn’t Present
-<!--- to be clear, are we talking about default values here, or just checking
-for an existing value before allowing insertion of a value? /LC--->
-<!-- I'm not sure what you mean exactly. Checking for an existing value before
-allowing insertion of a value can be used to insert whatever value would mean
-"default" in your program, or it can be used to insert some other value that
-you wouldn't call a default. That is, in Listing 8-25, would you call 50 a
-default value or no? (I don't think we've given enough information about what
-the program is ultimately trying to do to tell if 50 is a default or not, and I
-don't think it matters, but I am interested to know if there's something I'm
-missing that you're trying to get at). Can you elaborate on what was confusing
-and perhaps propose wording that would have cleared this up for you, and I can
-fix if needed? /Carol-->
-<!-- I suppose what I'm asking is whether a value is inserted from the started
-as a default value and then updated, meaning the key never has no value, or
-whether we're only allowing insertion of a value if there isn't already a
-value. I think it's the latter and maybe that's clear enough as is! JT, what do
-you think? /LC -->
-<!---
-I think the idea is generally right, we're going to insert the value if the
-key is not already in the hash map. Maybe the title could be:
-
-"Adding a key and value only if a key isn't present"
-
-Worth a note: I think "default" values are a bit of a loaded term in Rust. If
-we use it, we may confuse people later if we they come across `Default`, which
-is the default value of a type (like 0 is for i64, via `i64::default()`)
-/JT --->
-<!-- Ok, I've taken JT's suggestion for the section title and tried to reword
-the text here a bit; is this clearer, Liz? I share JT's concern about using the
-word "default"... /Carol -->
-
It’s common to check whether a particular key already exists in the hash map
-with a value then take the following actions: if the key does exist in the hash
-map, the existing value should remain the way it is. If the key doesn’t exist,
-insert it and a value for it.
+with a value and then to take the following actions: if the key does exist in
+the hash map, the existing value should remain the way it is; if the key
+doesn’t exist, insert it and a value for it.
Hash maps have a special API for this called `entry` that takes the key you
want to check as a parameter. The return value of the `entry` method is an enum
called `Entry` that represents a value that might or might not exist. Let’s say
we want to check whether the key for the Yellow team has a value associated
-with it. If it doesn’t, we want to insert the value 50, and the same for the
+with it. If it doesn’t, we want to insert the value `50`, and the same for the
Blue team. Using the `entry` API, the code looks like Listing 8-24.
```
@@ -1184,16 +965,16 @@ Listing 8-24: Using the `entry` method to only insert if the key does not
already have a value
The `or_insert` method on `Entry` is defined to return a mutable reference to
-the value for the corresponding `Entry` key if that key exists, and if not,
+the value for the corresponding `Entry` key if that key exists, and if not, it
inserts the parameter as the new value for this key and returns a mutable
reference to the new value. This technique is much cleaner than writing the
logic ourselves and, in addition, plays more nicely with the borrow checker.
Running the code in Listing 8-24 will print `{"Yellow": 50, "Blue": 10}`. The
first call to `entry` will insert the key for the Yellow team with the value
-50 because the Yellow team doesn’t have a value already. The second call to
+`50` because the Yellow team doesn’t have a value already. The second call to
`entry` will not change the hash map because the Blue team already has the
-value 10.
+value `10`.
#### Updating a Value Based on the Old Value
@@ -1202,7 +983,7 @@ update it based on the old value. For instance, Listing 8-25 shows code that
counts how many times each word appears in some text. We use a hash map with
the words as keys and increment the value to keep track of how many times we’ve
seen that word. If it’s the first time we’ve seen a word, we’ll first insert
-the value 0.
+the value `0`.
```
use std::collections::HashMap;
@@ -1223,37 +1004,29 @@ Listing 8-25: Counting occurrences of words using a hash map that stores words
and counts
This code will print `{"world": 2, "hello": 1, "wonderful": 1}`. You might see
-the same key/value pairs printed in a different order: recall from the
-“Accessing Values in a Hash Map†section that iterating over a hash map happens
-in an arbitrary order.
+the same key–value pairs printed in a different order: recall from “Accessing
+Values in a Hash Map†on page XX that iterating over a hash map happens in an
+arbitrary order.
-The `split_whitespace` method returns an iterator over sub-slices, separated by
+The `split_whitespace` method returns an iterator over subslices, separated by
whitespace, of the value in `text`. The `or_insert` method returns a mutable
-reference (`&mut V`) to the value for the specified key. Here we store that
+reference (`&mut V`) to the value for the specified key. Here, we store that
mutable reference in the `count` variable, so in order to assign to that value,
we must first dereference `count` using the asterisk (`*`). The mutable
reference goes out of scope at the end of the `for` loop, so all of these
changes are safe and allowed by the borrowing rules.
-<!---
-Running the above gave me `{"world": 2, "wonderful": 1, "hello": 1}` so the key
-order may not be deterministic or may change based on changes to the hashing
-function in the std lib.
-/JT --->
-<!-- I've added a note that getting a different order is perfectly normal
-/Carol -->
-
### Hashing Functions
By default, `HashMap` uses a hashing function called *SipHash* that can provide
-resistance to Denial of Service (DoS) attacks involving hash tables. This is
+resistance to denial-of-service (DoS) attacks involving hash tables. This is
not the fastest hashing algorithm available, but the trade-off for better
security that comes with the drop in performance is worth it. If you profile
your code and find that the default hash function is too slow for your
purposes, you can switch to another function by specifying a different hasher.
A *hasher* is a type that implements the `BuildHasher` trait. We’ll talk about
traits and how to implement them in Chapter 10. You don’t necessarily have to
-implement your own hasher from scratch; *https://crates.io/* has libraries
+implement your own hasher from scratch; *https://crates.io* has libraries
shared by other Rust users that provide hashers implementing many common
hashing algorithms.
@@ -1263,22 +1036,22 @@ Vectors, strings, and hash maps will provide a large amount of functionality
necessary in programs when you need to store, access, and modify data. Here are
some exercises you should now be equipped to solve:
-* Given a list of integers, use a vector and return the median (when sorted,
- the value in the middle position) and mode (the value that occurs most often;
- a hash map will be helpful here) of the list.
-* Convert strings to pig latin. The first consonant of each word is moved to
- the end of the word and “ay†is added, so “first†becomes “irst-fay.†Words
- that start with a vowel have “hay†added to the end instead (“apple†becomes
- “apple-hayâ€). Keep in mind the details about UTF-8 encoding!
-* Using a hash map and vectors, create a text interface to allow a user to add
- employee names to a department in a company. For example, “Add Sally to
- Engineering†or “Add Amir to Sales.†Then let the user retrieve a list of all
- people in a department or all people in the company by department, sorted
- alphabetically.
+1. Given a list of integers, use a vector and return the median (when sorted,
+the value in the middle position) and mode (the value that occurs most often; a
+hash map will be helpful here) of the list.
+1. Convert strings to pig latin. The first consonant of each word is moved to
+the end of the word and *ay* is added, so *first* becomes *irst-fay*. Words
+that start with a vowel have *hay* added to the end instead (*apple* becomes
+*apple-hay*). Keep in mind the details about UTF-8 encoding!
+1. Using a hash map and vectors, create a text interface to allow a user to add
+employee names to a department in a company; for example, “Add Sally to
+Engineering†or “Add Amir to Sales.†Then let the user retrieve a list of all
+people in a department or all people in the company by department, sorted
+alphabetically.
The standard library API documentation describes methods that vectors, strings,
and hash maps have that will be helpful for these exercises!
-We’re getting into more complex programs in which operations can fail, so, it’s
+We’re getting into more complex programs in which operations can fail, so it’s
a perfect time to discuss error handling. We’ll do that next!
diff --git a/src/doc/book/nostarch/chapter09.md b/src/doc/book/nostarch/chapter09.md
index 693dc1be0..4aa81123f 100644
--- a/src/doc/book/nostarch/chapter09.md
+++ b/src/doc/book/nostarch/chapter09.md
@@ -18,7 +18,7 @@ deployed your code to production!
Rust groups errors into two major categories: *recoverable* and *unrecoverable*
errors. For a recoverable error, such as a *file not found* error, we most
likely just want to report the problem to the user and retry the operation.
-Unrecoverable errors are always symptoms of bugs, like trying to access a
+Unrecoverable errors are always symptoms of bugs, such as trying to access a
location beyond the end of an array, and so we want to immediately stop the
program.
@@ -31,9 +31,9 @@ about returning `Result<T, E>` values. Additionally, we’ll explore
considerations when deciding whether to try to recover from an error or to stop
execution.
-## Unrecoverable Errors with `panic!`
+## Unrecoverable Errors with panic!
-Sometimes, bad things happen in your code, and there’s nothing you can do about
+Sometimes bad things happen in your code, and there’s nothing you can do about
it. In these cases, Rust has the `panic!` macro. There are two ways to cause a
panic in practice: by taking an action that causes our code to panic (such as
accessing an array past the end) or by explicitly calling the `panic!` macro.
@@ -42,39 +42,22 @@ print a failure message, unwind, clean up the stack, and quit. Via an
environment variable, you can also have Rust display the call stack when a
panic occurs to make it easier to track down the source of the panic.
-<!-- does Rust invoke the panic, or do we? Or sometimes it can be either? /LC --->
-<!-- We will have done *something* through a combination of the code we've
-written and the data the program gets at runtime. It *might* involve us
-literally typing `panic!` into our code, or it might be part of Rust that we're
-using that calls `panic!` for us because of something else we've done. Does
-that make sense? I've tried to clarify the last sentence a bit here /Carol -->
-<!---
-One way we could explain it is to say there are two ways to cause a panic in
-practice: by doing an action that causes our code to panic, like accessing an
-array past the end or dividing by zero, or by explicitly calling the `panic!`
-macro. In both cases, we cause a panic in our application. By default, these
-panics will unwind and clean up the stack. Via an environment setting, you can
-also have Rust display the call stack when a panic occurs to make it easier to
-track down the source of the panic.
-/JT --->
-<!-- I've taken JT's suggestion with some edits in the paragraph above /Carol
--->
> ### Unwinding the Stack or Aborting in Response to a Panic
>
-> By default, when a panic occurs, the program starts *unwinding*, which
-> means Rust walks back up the stack and cleans up the data from each function
-> it encounters. However, this walking back and cleanup is a lot of work. Rust,
-> therefore, allows you to choose the alternative of immediately *aborting*,
-> which ends the program without cleaning up.
+> By default, when a panic occurs the program starts *unwinding*, which means
+Rust walks back up the stack and cleans up the data from each function it
+encounters. However, walking back and cleaning up is a lot of work. Rust,
+therefore, allows you to choose the alternative of immediately *aborting*,
+which ends the program without cleaning up.
>
-> Memory that the program was using will then need to be cleaned
-> up by the operating system. If in your project you need to make the resulting
-> binary as small as possible, you can switch from unwinding to aborting upon a
-> panic by adding `panic = 'abort'` to the appropriate `[profile]` sections in
-> your *Cargo.toml* file. For example, if you want to abort on panic in release
-> mode, add this:
+> Memory that the program was using will then need to be cleaned up by the
+operating system. If in your project you need to make the resultant binary as
+small as possible, you can switch from unwinding to aborting upon a panic by
+adding `panic = 'abort'` to the appropriate `[profile]` sections in your
+*Cargo.toml* file. For example, if you want to abort on panic in release mode,
+add this:
>
-> ```toml
+> ```
> [profile.release]
> panic = 'abort'
> ```
@@ -93,7 +76,8 @@ When you run the program, you’ll see something like this:
```
thread 'main' panicked at 'crash and burn', src/main.rs:2:5
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+note: run with `RUST_BACKTRACE=1` environment variable to display
+a backtrace
```
The call to `panic!` causes the error message contained in the last two lines.
@@ -105,17 +89,14 @@ In this case, the line indicated is part of our code, and if we go to that
line, we see the `panic!` macro call. In other cases, the `panic!` call might
be in code that our code calls, and the filename and line number reported by
the error message will be someone else’s code where the `panic!` macro is
-called, not the line of our code that eventually led to the `panic!` call. We
-can use the backtrace of the functions the `panic!` call came from to figure
-out the part of our code that is causing the problem. We’ll discuss backtraces
-in more detail next.
-
-### Using a `panic!` Backtrace
+called, not the line of our code that eventually led to the `panic!` call.
-Let’s look at another example to see what it’s like when a `panic!` call comes
-from a library because of a bug in our code instead of from our code calling
-the macro directly. Listing 9-1 has some code that attempts to access an
-index in a vector beyond the range of valid indexes.
+We can use the backtrace of the functions the `panic!` call came from to figure
+out the part of our code that is causing the problem. To understand how to use
+a `panic!` backtrace, let’s look at another example and see what it’s like when
+a `panic!` call comes from a library because of a bug in our code instead of
+from our code calling the macro directly. Listing 9-1 has some code that
+attempts to access an index in a vector beyond the range of valid indexes.
Filename: src/main.rs
@@ -131,10 +112,10 @@ Listing 9-1: Attempting to access an element beyond the end of a vector, which
will cause a call to `panic!`
Here, we’re attempting to access the 100th element of our vector (which is at
-index 99 because indexing starts at zero), but the vector has only 3 elements.
-In this situation, Rust will panic. Using `[]` is supposed to return an
-element, but if you pass an invalid index, there’s no element that Rust could
-return here that would be correct.
+index 99 because indexing starts at zero), but the vector has only three
+elements. In this situation, Rust will panic. Using `[]` is supposed to return
+an element, but if you pass an invalid index, there’s no element that Rust
+could return here that would be correct.
In C, attempting to read beyond the end of a data structure is undefined
behavior. You might get whatever is at the location in memory that would
@@ -149,44 +130,55 @@ element at an index that doesn’t exist, Rust will stop execution and refuse to
continue. Let’s try it and see:
```
-thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 99', src/main.rs:4:5
+thread 'main' panicked at 'index out of bounds: the len is 3 but the index is
+99', src/main.rs:4:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
-This error points at line 4 of our `main.rs` where we attempt to access index
-99. The next note line tells us that we can set the `RUST_BACKTRACE`
-environment variable to get a backtrace of exactly what happened to cause the
-error. A *backtrace* is a list of all the functions that have been called to
-get to this point. Backtraces in Rust work as they do in other languages: the
-key to reading the backtrace is to start from the top and read until you see
-files you wrote. That’s the spot where the problem originated. The lines above
-that spot are code that your code has called; the lines below are code that
-called your code. These before-and-after lines might include core Rust code,
-standard library code, or crates that you’re using. Let’s try getting a
-backtrace by setting the `RUST_BACKTRACE` environment variable to any value
-except 0. Listing 9-2 shows output similar to what you’ll see.
+This error points at line 4 of our *main.rs* where we attempt to access `index`.
+
+The `note:` line tells us that we can set the `RUST_BACKTRACE` environment
+variable to get a backtrace of exactly what happened to cause the error. A
+*backtrace* is a list of all the functions that have been called to get to this
+point. Backtraces in Rust work as they do in other languages: the key to
+reading the backtrace is to start from the top and read until you see files you
+wrote. That’s the spot where the problem originated. The lines above that spot
+are code that your code has called; the lines below are code that called your
+code. These before-and-after lines might include core Rust code, standard
+library code, or crates that you’re using. Let’s try getting a backtrace by
+setting the `RUST_BACKTRACE` environment variable to any value except `0`.
+Listing 9-2 shows output similar to what you’ll see.
```
$ RUST_BACKTRACE=1 cargo run
-thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 99', src/main.rs:4:5
+thread 'main' panicked at 'index out of bounds: the len is 3 but the index is
+99', src/main.rs:4:5
stack backtrace:
0: rust_begin_unwind
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std
+/src/panicking.rs:584:5
1: core::panicking::panic_fmt
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:85
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core
+/src/panicking.rs:142:14
2: core::panicking::panic_bounds_check
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:62
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core
+/src/panicking.rs:84:5
3: <usize as core::slice::index::SliceIndex<[T]>>::index
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/slice/index.rs:255
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core
+/src/slice/index.rs:242:10
4: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/slice/index.rs:15
- 5: <alloc::vec::Vec<T> as core::ops::index::Index<I>>::index
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/alloc/src/vec.rs:1982
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core
+/src/slice/index.rs:18:9
+ 5: <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/alloc
+/src/vec/mod.rs:2591:9
6: panic::main
- at ./src/main.rs:4
+ at ./src/main.rs:4:5
7: core::ops::function::FnOnce::call_once
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/ops/function.rs:227
-note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core
+/src/ops/function.rs:248:5
+note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose
+backtrace.
```
Listing 9-2: The backtrace generated by a call to `panic!` displayed when the
@@ -208,21 +200,19 @@ panics in the future, you’ll need to figure out what action the code is taking
with what values to cause the panic and what the code should do instead.
We’ll come back to `panic!` and when we should and should not use `panic!` to
-handle error conditions in the “To `panic!` or Not to `panic!`†section later
-in this chapter. Next, we’ll look at how to recover from an error using
-`Result`.
+handle error conditions in “To panic! or Not to panic!†on page XX. Next, we’ll
+look at how to recover from an error using `Result`.
-## Recoverable Errors with `Result`
+## Recoverable Errors with Result
Most errors aren’t serious enough to require the program to stop entirely.
-Sometimes, when a function fails, it’s for a reason that you can easily
-interpret and respond to. For example, if you try to open a file and that
-operation fails because the file doesn’t exist, you might want to create the
-file instead of terminating the process.
+Sometimes when a function fails it’s for a reason that you can easily interpret
+and respond to. For example, if you try to open a file and that operation fails
+because the file doesn’t exist, you might want to create the file instead of
+terminating the process.
-Recall from “Handling Potential Failure with the `Result` Type†in Chapter 2
-that the `Result` enum is defined as having two variants, `Ok` and `Err`, as
-follows:
+Recall from “Handling Potential Failure with Result†on page XX that the
+`Result` enum is defined as having two variants, `Ok` and `Err`, as follows:
```
enum Result<T, E> {
@@ -237,7 +227,7 @@ the type of the value that will be returned in a success case within the `Ok`
variant, and `E` represents the type of the error that will be returned in a
failure case within the `Err` variant. Because `Result` has these generic type
parameters, we can use the `Result` type and the functions defined on it in
-many different situations where the successful value and error value we want to
+many different situations where the success value and error value we want to
return may differ.
Let’s call a function that returns a `Result` value because the function could
@@ -255,18 +245,6 @@ fn main() {
Listing 9-3: Opening a file
-<!---
-This brings up an interesting point - should we teach them to install
-rust-analyzer in the setup instructions? If so, then we can tell them to mouse
-over the name of what they want the typename of. The "assign something to i32 to
-have rustc tell you what it is" feels a bit like old style Rust.
-/JT --->
-<!-- I somewhat disagree here; not everyone uses IDE plugins. I'll see what JT
-says about mentioning rust-analyzer in chapter 1 rather than in the appendix...
-I am in favor of making the book shorter, though, so I've removed the parts
-about asking the compiler what the type of something is by deliberately
-annotating with the wrong type. /Carol -->
-
The return type of `File::open` is a `Result<T, E>`. The generic parameter `T`
has been filled in by the implementation of `File::open` with the type of the
success value, `std::fs::File`, which is a file handle. The type of `E` used in
@@ -282,7 +260,7 @@ In the case where `File::open` succeeds, the value in the variable
`greeting_file_result` will be an instance of `Ok` that contains a file handle.
In the case where it fails, the value in `greeting_file_result` will be an
instance of `Err` that contains more information about the kind of error that
-happened.
+occurred.
We need to add to the code in Listing 9-3 to take different actions depending
on the value `File::open` returns. Listing 9-4 shows one way to handle the
@@ -299,7 +277,9 @@ fn main() {
let greeting_file = match greeting_file_result {
Ok(file) => file,
- Err(error) => panic!("Problem opening the file: {:?}", error),
+ Err(error) => {
+ panic!("Problem opening the file: {:?}", error);
+ }
};
}
```
@@ -322,7 +302,9 @@ there’s no file named *hello.txt* in our current directory and we run this
code, we’ll see the following output from the `panic!` macro:
```
-thread 'main' panicked at 'Problem opening the file: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/main.rs:8:23
+thread 'main' panicked at 'Problem opening the file: Os { code:
+ 2, kind: NotFound, message: "No such file or directory" }',
+src/main.rs:8:23
```
As usual, this output tells us exactly what has gone wrong.
@@ -330,11 +312,11 @@ As usual, this output tells us exactly what has gone wrong.
### Matching on Different Errors
The code in Listing 9-4 will `panic!` no matter why `File::open` failed.
-However, we want to take different actions for different failure reasons: if
+However, we want to take different actions for different failure reasons. If
`File::open` failed because the file doesn’t exist, we want to create the file
and return the handle to the new file. If `File::open` failed for any other
reason—for example, because we didn’t have permission to open the file—we still
-want the code to `panic!` in the same way as it did in Listing 9-4. For this we
+want the code to `panic!` in the same way it did in Listing 9-4. For this, we
add an inner `match` expression, shown in Listing 9-5.
Filename: src/main.rs
@@ -349,14 +331,22 @@ fn main() {
let greeting_file = match greeting_file_result {
Ok(file) => file,
Err(error) => match error.kind() {
- ErrorKind::NotFound => match File::create("hello.txt") {
- Ok(fc) => fc,
- Err(e) => panic!("Problem creating the file: {:?}", e),
+ ErrorKind::NotFound => {
+ match File::create("hello.txt") {
+ Ok(fc) => fc,
+ Err(e) => panic!(
+ "Problem creating the file: {:?}",
+ e
+ ),
+ }
}
other_error => {
- panic!("Problem opening the file: {:?}", other_error);
+ panic!(
+ "Problem opening the file: {:?}",
+ other_error
+ );
}
- }
+ },
};
}
```
@@ -380,40 +370,41 @@ file can’t be created, a different error message is printed. The second arm of
the outer `match` stays the same, so the program panics on any error besides
the missing file error.
-> ### Alternatives to Using `match` with `Result<T, E>`
->
-> That’s a lot of `match`! The `match` expression is very useful but also very
-> much a primitive. In Chapter 13, you’ll learn about closures, which are used
-> with many of the methods defined on `Result<T, E>`. These methods can be more
-> concise than using `match` when handling `Result<T, E>` values in your code.
+#### Alternatives to Using match with Result<T, E>
-> For example, here’s another way to write the same logic as shown in Listing
-> 9-5, this time using closures and the `unwrap_or_else` method:
->
-> ```
-> use std::fs::File;
-> use std::io::ErrorKind;
->
-> fn main() {
-> let greeting_file = File::open("hello.txt").unwrap_or_else(|error| {
-> if error.kind() == ErrorKind::NotFound {
-> File::create("hello.txt").unwrap_or_else(|error| {
-> panic!("Problem creating the file: {:?}", error);
-> })
-> } else {
-> panic!("Problem opening the file: {:?}", error);
-> }
-> });
-> }
-> ```
->
-> Although this code has the same behavior as Listing 9-5, it doesn’t contain
-> any `match` expressions and is cleaner to read. Come back to this example
-> after you’ve read Chapter 13, and look up the `unwrap_or_else` method in the
-> standard library documentation. Many more of these methods can clean up huge
-> nested `match` expressions when you’re dealing with errors.
+That’s a lot of `match`! The `match` expression is very useful but also very
+much a primitive. In Chapter 13, you’ll learn about closures, which are used
+with many of the methods defined on `Result<T, E>`. These methods can be more
+concise than using `match` when handling `Result<T, E>` values in your code.
-### Shortcuts for Panic on Error: `unwrap` and `expect`
+For example, here’s another way to write the same logic as shown in Listing
+9-5, this time using closures and the `unwrap_or_else` method:
+
+```
+// src/main.rs
+use std::fs::File;
+use std::io::ErrorKind;
+
+fn main() {
+ let greeting_file = File::open("hello.txt").unwrap_or_else(|error| {
+ if error.kind() == ErrorKind::NotFound {
+ File::create("hello.txt").unwrap_or_else(|error| {
+ panic!("Problem creating the file: {:?}", error);
+ })
+ } else {
+ panic!("Problem opening the file: {:?}", error);
+ }
+ });
+}
+```
+
+Although this code has the same behavior as Listing 9-5, it doesn’t contain any
+`match` expressions and is cleaner to read. Come back to this example after
+you’ve read Chapter 13, and look up the `unwrap_or_else` method in the standard
+library documentation. Many more of these methods can clean up huge nested
+`match` expressions when you’re dealing with errors.
+
+#### Shortcuts for Panic on Error: unwrap and expect
Using `match` works well enough, but it can be a bit verbose and doesn’t always
communicate intent well. The `Result<T, E>` type has many helper methods
@@ -437,20 +428,11 @@ If we run this code without a *hello.txt* file, we’ll see an error message fro
the `panic!` call that the `unwrap` method makes:
```
-thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error {
-repr: Os { code: 2, message: "No such file or directory" } }',
-src/libcore/result.rs:906:4
+thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os {
+code: 2, kind: NotFound, message: "No such file or directory" }',
+src/main.rs:4:49
```
-<!---
-More recent rustc versions give a bit better error here (specifically the location):
-
-thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value:
-Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/main.rs:4:37
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
-/JT --->
-<!-- I'll update the error output when we're in Word /Carol -->
-
Similarly, the `expect` method lets us also choose the `panic!` error message.
Using `expect` instead of `unwrap` and providing good error messages can convey
your intent and make tracking down the source of a panic easier. The syntax of
@@ -473,36 +455,20 @@ will be the parameter that we pass to `expect`, rather than the default
`panic!` message that `unwrap` uses. Here’s what it looks like:
```
-thread 'main' panicked at 'hello.txt should be included in this project: Error { repr: Os { code:
-2, message: "No such file or directory" } }', src/libcore/result.rs:906:4
+thread 'main' panicked at 'hello.txt should be included in this project: Os {
+code: 2, kind: NotFound, message: "No such file or directory" }',
+src/main.rs:5:10
```
-<!---
-Ditto with the above:
-
-thread 'main' panicked at 'Failed to open hello.txt: Os { code: 2, kind: NotFound,
-message: "No such file or directory" }', src/main.rs:4:37
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
-/JT --->
-<!-- I'll update the error output when we're in Word /Carol -->
-
In production-quality code, most Rustaceans choose `expect` rather than
`unwrap` and give more context about why the operation is expected to always
succeed. That way, if your assumptions are ever proven wrong, you have more
information to use in debugging.
-<!---
-Now that `unwrap` and `expect` give an improved file location, we may not
-need the paragraph above.
-/JT --->
-<!-- I've changed the paragraph above, as well as the text in the examaple
-usage of `expect`, to better reflect current best practices and the reasons for
-them. /Carol -->
-
### Propagating Errors
When a function’s implementation calls something that might fail, instead of
-handling the error within the function itself, you can return the error to the
+handling the error within the function itself you can return the error to the
calling code so that it can decide what to do. This is known as *propagating*
the error and gives more control to the calling code, where there might be more
information or logic that dictates how the error should be handled than what
@@ -518,19 +484,19 @@ Filename: src/main.rs
use std::fs::File;
use std::io::{self, Read};
-fn read_username_from_file() -> Result<String, io::Error> [1] {
- let username_file_result = File::open("hello.txt"); [2]
+1 fn read_username_from_file() -> Result<String, io::Error> {
+ 2 let username_file_result = File::open("hello.txt");
- let mut username_file [3] = match username_file_result {
- Ok(file) => file, [4]
- Err(e) => return Err(e), [5]
+ 3 let mut username_file = match username_file_result {
+ 4 Ok(file) => file,
+ 5 Err(e) => return Err(e),
};
- let mut username = String::new(); [6]
+ 6 let mut username = String::new();
- match username_file.read_to_string(&mut username) [7] {
- Ok(_) => Ok(username), [8]
- Err(e) => Err(e), [9]
+ 7 match username_file.read_to_string(&mut username) {
+ 8 Ok(_) => Ok(username),
+ 9 Err(e) => Err(e),
}
}
```
@@ -541,12 +507,12 @@ This function can be written in a much shorter way, but we’re going to start b
doing a lot of it manually in order to explore error handling; at the end,
we’ll show the shorter way. Let’s look at the return type of the function
first: `Result<String, io::Error>` [1]. This means the function is returning a
-value of the type `Result<T, E>` where the generic parameter `T` has been
-filled in with the concrete type `String`, and the generic type `E` has been
+value of the type `Result<T, E>`, where the generic parameter `T` has been
+filled in with the concrete type `String` and the generic type `E` has been
filled in with the concrete type `io::Error`.
If this function succeeds without any problems, the code that calls this
-function will receive an `Ok` value that holds a `String`—the username that
+function will receive an `Ok` value that holds a `String`—the `username` that
this function read from the file [8]. If this function encounters any problems,
the calling code will receive an `Err` value that holds an instance of
`io::Error` that contains more information about what the problems were. We
@@ -564,9 +530,9 @@ function continues. In the `Err` case, instead of calling `panic!`, we use the
error value from `File::open`, now in the pattern variable `e`, back to the
calling code as this function’s error value [5].
-So if we have a file handle in `username_file`, the function then creates a new
-`String` in variable `username` [6] and calls the `read_to_string` method on
-the file handle in `username_file` to read the contents of the file into
+So, if we have a file handle in `username_file`, the function then creates a
+new `String` in variable `username` [6] and calls the `read_to_string` method
+on the file handle in `username_file` to read the contents of the file into
`username` [7]. The `read_to_string` method also returns a `Result` because it
might fail, even though `File::open` succeeded. So we need another `match` to
handle that `Result`: if `read_to_string` succeeds, then our function has
@@ -576,20 +542,6 @@ same way that we returned the error value in the `match` that handled the
return value of `File::open`. However, we don’t need to explicitly say
`return`, because this is the last expression in the function [9].
-<!---
-Style nit: I'm finding the above two paragraphs a bit difficult to read
-comfortably. I think one issue is that we're using a handful of single letter
-variable names while also trying to walk someone through an explanation of
-multiple concepts.
-
-Maybe just me? But feels like the above example might be explained a bit better
-if we used more complete variable names so the explanation could have a better
-flow (without trying to remember what each of the single-letter variables meant)
-/JT --->
-<!-- Totally valid! I've changed the variable names in this, previous, and
-following examples, broke up these paragraphs a bit, and added wingdings.
-/Carol -->
-
The code that calls this code will then handle getting either an `Ok` value
that contains a username or an `Err` value that contains an `io::Error`. It’s
up to the calling code to decide what to do with those values. If the calling
@@ -602,18 +554,17 @@ it to handle appropriately.
This pattern of propagating errors is so common in Rust that Rust provides the
question mark operator `?` to make this easier.
-#### A Shortcut for Propagating Errors: the `?` Operator
+#### A Shortcut for Propagating Errors: The ? Operator
Listing 9-7 shows an implementation of `read_username_from_file` that has the
-same functionality as in Listing 9-6, but this implementation uses the
-`?` operator.
+same functionality as in Listing 9-6, but this implementation uses the `?`
+operator.
Filename: src/main.rs
```
use std::fs::File;
-use std::io;
-use std::io::Read;
+use std::io::{self, Read};
fn read_username_from_file() -> Result<String, io::Error> {
let mut username_file = File::open("hello.txt")?;
@@ -651,13 +602,6 @@ define `impl From<io::Error> for OurError` to construct an instance of
`read_username_from_file` will call `from` and convert the error types without
needing to add any more code to the function.
-<!---
-It's a bit fuzzy what `impl From<OtherError> for ReturnedError` means. We may
-want to use a more concrete example, like: `impl From<OurError> for io::Error`.
-/JT --->
-<!-- I've added a more concrete example here, but converting the other way,
-which I think is more likely in production code /Carol -->
-
In the context of Listing 9-7, the `?` at the end of the `File::open` call will
return the value inside an `Ok` to the variable `username_file`. If an error
occurs, the `?` operator will return early out of the whole function and give
@@ -672,8 +616,7 @@ Filename: src/main.rs
```
use std::fs::File;
-use std::io;
-use std::io::Read;
+use std::io::{self, Read};
fn read_username_from_file() -> Result<String, io::Error> {
let mut username = String::new();
@@ -718,7 +661,7 @@ into that `String`, and returns it. Of course, using `fs::read_to_string`
doesn’t give us the opportunity to explain all the error handling, so we did it
the longer way first.
-#### Where The `?` Operator Can Be Used
+#### Where the ? Operator Can Be Used
The `?` operator can only be used in functions whose return type is compatible
with the value the `?` is used on. This is because the `?` operator is defined
@@ -729,8 +672,8 @@ as the `match` expression we defined in Listing 9-6. In Listing 9-6, the
it’s compatible with this `return`.
In Listing 9-10, let’s look at the error we’ll get if we use the `?` operator
-in a `main` function with a return type incompatible with the type of the value
-we use `?` on:
+in a `main` function with a return type that is incompatible with the type of
+the value we use `?` on.
Filename: src/main.rs
@@ -743,7 +686,7 @@ fn main() {
```
Listing 9-10: Attempting to use the `?` in the `main` function that returns
-`()` won’t compile
+`()` won’t compile.
This code opens a file, which might fail. The `?` operator follows the `Result`
value returned by `File::open`, but this `main` function has the return type of
@@ -751,15 +694,19 @@ value returned by `File::open`, but this `main` function has the return type of
message:
```
-error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
- --> src/main.rs:4:36
- |
-3 | / fn main() {
-4 | | let f = File::open("hello.txt")?;
- | | ^ cannot use the `?` operator in a function that returns `()`
-5 | | }
- | |_- this function should return `Result` or `Option` to accept `?`
- |
+error[E0277]: the `?` operator can only be used in a function that returns
+`Result` or `Option` (or another type that implements `FromResidual`)
+ --> src/main.rs:4:48
+ |
+3 | / fn main() {
+4 | | let greeting_file = File::open("hello.txt")?;
+ | | ^ cannot use the `?`
+operator in a function that returns `()`
+5 | | }
+ | |_- this function should return `Result` or `Option` to accept `?`
+ |
+ = help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not
+implemented for `()`
```
This error points out that we’re only allowed to use the `?` operator in a
@@ -768,9 +715,9 @@ function that returns `Result`, `Option`, or another type that implements
To fix the error, you have two choices. One choice is to change the return type
of your function to be compatible with the value you’re using the `?` operator
-on as long as you have no restrictions preventing that. The other technique is
-to use a `match` or one of the `Result<T, E>` methods to handle the `Result<T,
-E>` in whatever way is appropriate.
+on as long as you have no restrictions preventing that. The other choice is to
+use a `match` or one of the `Result<T, E>` methods to handle the `Result<T, E>`
+in whatever way is appropriate.
The error message also mentioned that `?` can be used with `Option<T>` values
as well. As with using `?` on `Result`, you can only use `?` on `Option` in a
@@ -778,9 +725,9 @@ function that returns an `Option`. The behavior of the `?` operator when called
on an `Option<T>` is similar to its behavior when called on a `Result<T, E>`:
if the value is `None`, the `None` will be returned early from the function at
that point. If the value is `Some`, the value inside the `Some` is the
-resulting value of the expression and the function continues. Listing 9-11 has
+resultant value of the expression, and the function continues. Listing 9-11 has
an example of a function that finds the last character of the first line in the
-given text:
+given text.
```
fn last_char_of_first_line(text: &str) -> Option<char> {
@@ -804,7 +751,7 @@ The `?` extracts the string slice, and we can call `chars` on that string slice
to get an iterator of its characters. We’re interested in the last character in
this first line, so we call `last` to return the last item in the iterator.
This is an `Option` because it’s possible that the first line is the empty
-string, for example if `text` starts with a blank line but has characters on
+string; for example, if `text` starts with a blank line but has characters on
other lines, as in `"\nhi"`. However, if there is a last character on the first
line, it will be returned in the `Some` variant. The `?` operator in the middle
gives us a concise way to express this logic, allowing us to implement the
@@ -819,14 +766,16 @@ you can use methods like the `ok` method on `Result` or the `ok_or` method on
`Option` to do the conversion explicitly.
So far, all the `main` functions we’ve used return `()`. The `main` function is
-special because it’s the entry and exit point of executable programs, and there
-are restrictions on what its return type can be for the programs to behave as
-expected.
+special because it’s the entry point and exit point of an executable program,
+and there are restrictions on what its return type can be for the program to
+behave as expected.
-Luckily, `main` can also return a `Result<(), E>`. Listing 9-12 has the
-code from Listing 9-10 but we’ve changed the return type of `main` to be
+Luckily, `main` can also return a `Result<(), E>`. Listing 9-12 has the code
+from Listing 9-10, but we’ve changed the return type of `main` to be
`Result<(), Box<dyn Error>>` and added a return value `Ok(())` to the end. This
-code will now compile:
+code will now compile.
+
+Filename: src/main.rs
```
use std::error::Error;
@@ -839,51 +788,36 @@ fn main() -> Result<(), Box<dyn Error>> {
}
```
-<!---
-The move to `Box<dyn Error>` isn't unexpected for an experienced Rust
-developer, but I wonder if we should keep `std::io::Error` here to keep with
-the flow of the previous examples?
-
-I think my instinct was to mention this since we don't use the flexibility
-the trait object gives us. Instead, we switch to explaining how exit codes
-work with Result values.
-/JT --->
-<!-- The idea here was to give the reader code that will work in the future no
-matter what errors they're trying to return from main. If we put in
-std::io::Error, it'll work for this example, but probably not in the reader's
-own projects. I've added a sentence to the end of the paragraph after Listing
-9-12's caption to explain this thinking. /Carol -->
-
Listing 9-12: Changing `main` to return `Result<(), E>` allows the use of the
-`?` operator on `Result` values
-
-The `Box<dyn Error>` type is a *trait object*, which we’ll talk about in the
-“Using Trait Objects that Allow for Values of Different Types†section in
-Chapter 17. For now, you can read `Box<dyn Error>` to mean “any kind of error.â€
-Using `?` on a `Result` value in a `main` function with the error type `Box<dyn
-Error>` is allowed, because it allows any `Err` value to be returned early.
-Even though the body of this `main` function will only ever return errors of
-type `std::io::Error`, by specifying `Box<dyn Error>`, this signature will
-continue to be correct even if more code that returns other errors is added to
-the body of `main`.
-
-When a `main` function returns a `Result<(), E>`, the executable will
-exit with a value of `0` if `main` returns `Ok(())` and will exit with a
-nonzero value if `main` returns an `Err` value. Executables written in C return
-integers when they exit: programs that exit successfully return the integer
-`0`, and programs that error return some integer other than `0`. Rust also
-returns integers from executables to be compatible with this convention.
+`?` operator on `Result` values.
+
+The `Box<dyn Error>` type is a *trait object*, which we’ll talk about in “Using
+Trait Objects That Allow for Values of Different Types†on page XX. For now,
+you can read `Box<dyn Error>` to mean “any kind of error.†Using `?` on a
+`Result` value in a `main` function with the error type `Box<dyn Error>` is
+allowed because it allows any `Err` value to be returned early. Even though the
+body of this `main` function will only ever return errors of type
+`std::io::Error`, by specifying `Box<dyn Error>`, this signature will continue
+to be correct even if more code that returns other errors is added to the body
+of `main`.
+
+When a `main` function returns a `Result<(), E>`, the executable will exit with
+a value of `0` if `main` returns `Ok(())` and will exit with a nonzero value if
+`main` returns an `Err` value. Executables written in C return integers when
+they exit: programs that exit successfully return the integer `0`, and programs
+that error return some integer other than `0`. Rust also returns integers from
+executables to be compatible with this convention.
The `main` function may return any types that implement the
`std::process::Termination` trait, which contains a function `report` that
-returns an `ExitCode` Consult the standard library documentation for more
+returns an `ExitCode`. Consult the standard library documentation for more
information on implementing the `Termination` trait for your own types.
Now that we’ve discussed the details of calling `panic!` or returning `Result`,
let’s return to the topic of how to decide which is appropriate to use in which
cases.
-## To `panic!` or Not to `panic!`
+## To panic! or Not to panic!
So how do you decide when you should call `panic!` and when you should return
`Result`? When code panics, there’s no way to recover. You could call `panic!`
@@ -904,11 +838,11 @@ some general guidelines on how to decide whether to panic in library code.
### Examples, Prototype Code, and Tests
-When you’re writing an example to illustrate some concept, also including robust
-error-handling code can make the example less clear. In
-examples, it’s understood that a call to a method like `unwrap` that could
-panic is meant as a placeholder for the way you’d want your application to
-handle errors, which can differ based on what the rest of your code is doing.
+When you’re writing an example to illustrate some concept, also including
+robust error-handling code can make the example less clear. In examples, it’s
+understood that a call to a method like `unwrap` that could panic is meant as a
+placeholder for the way you’d want your application to handle errors, which can
+differ based on what the rest of your code is doing.
Similarly, the `unwrap` and `expect` methods are very handy when prototyping,
before you’re ready to decide how to handle errors. They leave clear markers in
@@ -931,17 +865,6 @@ that you’ll never have an `Err` variant, it’s perfectly acceptable to call
`unwrap`, and even better to document the reason you think you’ll never have an
`Err` variant in the `expect` text. Here’s an example:
-<!---
-Some Rust devs may have a nuanced take on the above, myself included. I'd say
-you'd be safer to use `.expect(...)` and put as the argument the reason why it
-should never fail. If, in the future it ever *does* fail for some reason
-(probably as a result of many code fixes over time), then you've got a message
-to start with telling you what the original expectation was.
-/JT --->
-<!-- I agree with this and reinforcing this best practice; I've changed the
-`unwrap` to `expect` and demonstrated a good message. I still don't want to
-shame people too much for using `unwrap`, though. /Carol -->
-
```
use std::net::IpAddr;
@@ -960,25 +883,24 @@ valid IP address. If the IP address string came from a user rather than being
hardcoded into the program and therefore *did* have a possibility of failure,
we’d definitely want to handle the `Result` in a more robust way instead.
Mentioning the assumption that this IP address is hardcoded will prompt us to
-change `expect` to better error handling code if in the future, we need to get
+change `expect` to better error-handling code if, in the future, we need to get
the IP address from some other source instead.
### Guidelines for Error Handling
-It’s advisable to have your code panic when it’s possible that your code
-could end up in a bad state. In this context, a *bad state* is when some
-assumption, guarantee, contract, or invariant has been broken, such as when
-invalid values, contradictory values, or missing values are passed to your
-code—plus one or more of the following:
+It’s advisable to have your code panic when it’s possible that your code could
+end up in a bad state. In this context, a *bad state* is when some assumption,
+guarantee, contract, or invariant has been broken, such as when invalid values,
+contradictory values, or missing values are passed to your code—plus one or
+more of the following:
* The bad state is something that is unexpected, as opposed to something that
- will likely happen occasionally, like a user entering data in the wrong
- format.
+will likely happen occasionally, like a user entering data in the wrong format.
* Your code after this point needs to rely on not being in this bad state,
- rather than checking for the problem at every step.
+rather than checking for the problem at every step.
* There’s not a good way to encode this information in the types you use. We’ll
- work through an example of what we mean in the “Encoding States and Behavior
- as Types†section of Chapter 17.
+work through an example of what we mean in “Encoding States and Behavior as
+Types†on page XX.
If someone calls your code and passes in values that don’t make sense, it’s
best to return an error if you can so the user of the library can decide what
@@ -989,24 +911,6 @@ development. Similarly, `panic!` is often appropriate if you’re calling
external code that is out of your control and it returns an invalid state that
you have no way of fixing.
-<!---
-Disagree a bit with the above. I don't think libraries should ever panic. They
-should always be written defensively so they can be used in a broader range of
-applications, which include applications where crashing could result in data
-loss.
-
-Rather than crashing, libraries can encode the reasons they failed based on the
-user's input into an error that can be returned to the user.
-
-In practice, the only time the application should absolutely crash is if
-continuing could bring harm to the user's machine, their data, filesystem, and
-so on. Otherwise, the user should just be given a warning that the operation
-couldn't be completed successfully, so they can take their next action. If we
-crash, unfortunately the user never gets that choice.
-/JT --->
-<!-- I think we actually agree here but the original text wasn't clear enough;
-I've edited. /Carol -->
-
However, when failure is expected, it’s more appropriate to return a `Result`
than to make a `panic!` call. Examples include a parser being given malformed
data or an HTTP request returning a status that indicates you have hit a rate
@@ -1022,25 +926,12 @@ an out-of-bounds memory access: trying to access memory that doesn’t belong to
the current data structure is a common security problem. Functions often have
*contracts*: their behavior is only guaranteed if the inputs meet particular
requirements. Panicking when the contract is violated makes sense because a
-contract violation always indicates a caller-side bug and it’s not a kind of
+contract violation always indicates a caller-side bug, and it’s not a kind of
error you want the calling code to have to explicitly handle. In fact, there’s
no reasonable way for calling code to recover; the calling *programmers* need
to fix the code. Contracts for a function, especially when a violation will
cause a panic, should be explained in the API documentation for the function.
-<!---
-The wording of the first sentence in the above paragraph reads like we should
-panic on invalid data, but in the previous paragraph we say malformed data
-should be a `Result`. The rest makes sense, where the spirit of when the stdlib
-panics is less about invalid data and more about when the user will be put at
-risk.
-/JT --->
-<!-- I think we were trying to draw a distinction between "malformed" and
-"invalid" values that perhaps wasn't very clear. I've tried to clarify by
-adding "could put a user at risk", but I don't really want to get into the
-specifics of this because only a subset of readers will be writing code like
-this... /Carol -->
-
However, having lots of error checks in all of your functions would be verbose
and annoying. Fortunately, you can use Rust’s type system (and thus the type
checking done by the compiler) to do many of the checks for you. If your
@@ -1064,16 +955,18 @@ numbers before checking it against our secret number; we only validated that
the guess was positive. In this case, the consequences were not very dire: our
output of “Too high†or “Too low†would still be correct. But it would be a
useful enhancement to guide the user toward valid guesses and have different
-behavior when a user guesses a number that’s out of range versus when a user
-types, for example, letters instead.
+behavior when the user guesses a number that’s out of range versus when the
+user types, for example, letters instead.
One way to do this would be to parse the guess as an `i32` instead of only a
`u32` to allow potentially negative numbers, and then add a check for the
number being in range, like so:
+Filename: src/main.rs
+
```
loop {
- // --snip--
+ --snip--
let guess: i32 = match guess.trim().parse() {
Ok(num) => num,
@@ -1086,7 +979,7 @@ loop {
}
match guess.cmp(&secret_number) {
- // --snip--
+ --snip--
}
```
@@ -1096,7 +989,7 @@ and ask for another guess. After the `if` expression, we can proceed with the
comparisons between `guess` and the secret number knowing that `guess` is
between 1 and 100.
-However, this is not an ideal solution: if it was absolutely critical that the
+However, this is not an ideal solution: if it were absolutely critical that the
program only operated on values between 1 and 100, and it had many functions
with this requirement, having a check like this in every function would be
tedious (and might impact performance).
@@ -1108,71 +1001,60 @@ confidently use the values they receive. Listing 9-13 shows one way to define a
`Guess` type that will only create an instance of `Guess` if the `new` function
receives a value between 1 and 100.
+Filename: src/lib.rs
+
```
-pub struct Guess {
+1 pub struct Guess {
value: i32,
}
impl Guess {
- pub fn new(value: i32) -> Guess {
- if value < 1 || value > 100 {
- panic!("Guess value must be between 1 and 100, got {}.", value);
+ 2 pub fn new(value: i32) -> Guess {
+ 3 if value < 1 || value > 100 {
+ 4 panic!(
+ "Guess value must be between 1 and 100, got {}.",
+ value
+ );
}
- Guess { value }
+ 5 Guess { value }
}
- pub fn value(&self) -> i32 {
+ 6 pub fn value(&self) -> i32 {
self.value
}
}
```
-<!---
-The above example feels a bit off to me. We talk earlier about user input being
-a prime candidate for recoverable errors, and then we talk about encoding only
-proper states in the type system. But this examples seems to work with user
-input and panic if it's not correct, rather than using recoverable errors or
-encoding the state into the type.
-
-Maybe you could have them guess rock/paper/scissors and encode the
-rock/paper/scissor as three enum values, and if they type something outside of
-that, we don't allow it. Otherwise we create an enum of that value.
-/JT --->
-<!-- The point about this listing panicking is valid, but I disagree a little.
-I think this is encoding only valid states into the type system. Also, Chapter
-11 builds on this example to show how to use `should_panic`, so I'm going to
-leave this the way it is. /Carol -->
-
Listing 9-13: A `Guess` type that will only continue with values between 1 and
100
-First, we define a struct named `Guess` that has a field named `value` that
-holds an `i32`. This is where the number will be stored.
+First we define a struct named `Guess` that has a field named `value` that
+holds an `i32` [1]. This is where the number will be stored.
Then we implement an associated function named `new` on `Guess` that creates
-instances of `Guess` values. The `new` function is defined to have one
+instances of `Guess` values [2]. The `new` function is defined to have one
parameter named `value` of type `i32` and to return a `Guess`. The code in the
-body of the `new` function tests `value` to make sure it’s between 1 and 100.
-If `value` doesn’t pass this test, we make a `panic!` call, which will alert
-the programmer who is writing the calling code that they have a bug they need
-to fix, because creating a `Guess` with a `value` outside this range would
+body of the `new` function tests `value` to make sure it’s between 1 and 100
+[3]. If `value` doesn’t pass this test, we make a `panic!` call [4], which will
+alert the programmer who is writing the calling code that they have a bug they
+need to fix, because creating a `Guess` with a `value` outside this range would
violate the contract that `Guess::new` is relying on. The conditions in which
`Guess::new` might panic should be discussed in its public-facing API
documentation; we’ll cover documentation conventions indicating the possibility
of a `panic!` in the API documentation that you create in Chapter 14. If
`value` does pass the test, we create a new `Guess` with its `value` field set
-to the `value` parameter and return the `Guess`.
+to the `value` parameter and return the `Guess` [5].
Next, we implement a method named `value` that borrows `self`, doesn’t have any
-other parameters, and returns an `i32`. This kind of method is sometimes called
-a *getter*, because its purpose is to get some data from its fields and return
-it. This public method is necessary because the `value` field of the `Guess`
-struct is private. It’s important that the `value` field be private so code
-using the `Guess` struct is not allowed to set `value` directly: code outside
-the module *must* use the `Guess::new` function to create an instance of
-`Guess`, thereby ensuring there’s no way for a `Guess` to have a `value` that
-hasn’t been checked by the conditions in the `Guess::new` function.
+other parameters, and returns an `i32` [6]. This kind of method is sometimes
+called a *getter* because its purpose is to get some data from its fields and
+return it. This public method is necessary because the `value` field of the
+`Guess` struct is private. It’s important that the `value` field be private so
+code using the `Guess` struct is not allowed to set `value` directly: code
+outside the module *must* use the `Guess::new` function to create an instance
+of `Guess`, thereby ensuring there’s no way for a `Guess` to have a `value`
+that hasn’t been checked by the conditions in the `Guess::new` function.
A function that has a parameter or returns only numbers between 1 and 100 could
then declare in its signature that it takes or returns a `Guess` rather than an
@@ -1180,7 +1062,7 @@ then declare in its signature that it takes or returns a `Guess` rather than an
## Summary
-Rust’s error handling features are designed to help you write more robust code.
+Rust’s error-handling features are designed to help you write more robust code.
The `panic!` macro signals that your program is in a state it can’t handle and
lets you tell the process to stop instead of trying to proceed with invalid or
incorrect values. The `Result` enum uses Rust’s type system to indicate that
@@ -1193,17 +1075,3 @@ Now that you’ve seen useful ways that the standard library uses generics with
the `Option` and `Result` enums, we’ll talk about how generics work and how you
can use them in your code.
-<!---
-A meta comment: the coverage of `panic!` here feels helpful in terms of giving
-a more complete understanding of Rust, but in practice (and this may depend
-on domain), using `panic!` should be a fairly limited thing.
-
-Something I noticed we don't touch on but may want to is panic hooks, as
-unrecoverable errors isn't exactly true. You can recover from an unwinding
-panic if you need to code defensively against, say, a dependency panicking and
-you don't want your app to go down as a result.
-/JT --->
-<!-- Yeahhh I don't want to mention panic hooks, one because I don't think most
-people will need to think about them or implement one, and two because a subset
-of people will look at that and think "oh look, exception handling!" which...
-is not what it's for. /Carol -->
diff --git a/src/doc/book/nostarch/chapter10.md b/src/doc/book/nostarch/chapter10.md
index 2030c335e..bb8919d79 100644
--- a/src/doc/book/nostarch/chapter10.md
+++ b/src/doc/book/nostarch/chapter10.md
@@ -15,13 +15,13 @@ how they relate to other generics without knowing what will be in their place
when compiling and running the code.
Functions can take parameters of some generic type, instead of a concrete type
-like `i32` or `String`, in the same way a function takes parameters with
-unknown values to run the same code on multiple concrete values. In fact, we’ve
-already used generics in Chapter 6 with `Option<T>`, Chapter 8 with `Vec<T>`
-and `HashMap<K, V>`, and Chapter 9 with `Result<T, E>`. In this chapter, you’ll
+like `i32` or `String`, in the same way they take parameters with unknown
+values to run the same code on multiple concrete values. In fact, we’ve already
+used generics in Chapter 6 with `Option<T>`, in Chapter 8 with `Vec<T>` and
+`HashMap<K, V>`, and in Chapter 9 with `Result<T, E>`. In this chapter, you’ll
explore how to define your own types, functions, and methods with generics!
-First, we’ll review how to extract a function to reduce code duplication. We’ll
+First we’ll review how to extract a function to reduce code duplication. We’ll
then use the same technique to make a generic function from two functions that
differ only in the types of their parameters. We’ll also explain how to use
generic types in struct and enum definitions.
@@ -39,47 +39,47 @@ help.
## Removing Duplication by Extracting a Function
Generics allow us to replace specific types with a placeholder that represents
-multiple types to remove code duplication.
-Before diving into generics syntax, then, let’s first look at how to remove
-duplication in a way that doesn’t involve generic types by extracting a
-function that replaces specific values with a placeholder that represents
-multiple values. Then we’ll apply the same technique to extract a generic
-function! By looking at how to recognize duplicated code you can extract into a
-function, you’ll start to recognize duplicated code that can use generics.
+multiple types to remove code duplication. Before diving into generics syntax,
+let’s first look at how to remove duplication in a way that doesn’t involve
+generic types by extracting a function that replaces specific values with a
+placeholder that represents multiple values. Then we’ll apply the same
+technique to extract a generic function! By looking at how to recognize
+duplicated code you can extract into a function, you’ll start to recognize
+duplicated code that can use generics.
-We begin with the short program in Listing 10-1 that finds the largest number
-in a list.
+We’ll begin with the short program in Listing 10-1 that finds the largest
+number in a list.
Filename: src/main.rs
```
fn main() {
- let number_list = vec![34, 50, 25, 100, 65];
+ 1 let number_list = vec![34, 50, 25, 100, 65];
- let mut largest = &number_list[0];
+ 2 let mut largest = &number_list[0];
- for number in &number_list {
- if number > largest {
- largest = number;
+ 3 for number in &number_list {
+ 4 if number > largest {
+ 5 largest = number;
}
}
- println!("The largest number is {}", largest);
+ println!("The largest number is {largest}");
}
```
Listing 10-1: Finding the largest number in a list of numbers
-We store a list of integers in the variable `number_list` and place a reference
-to the first number in the list in a variable named `largest`. We then iterate
-through all the numbers in the list, and if the current number is greater than
-the number stored in `largest`, replace the reference in that variable.
-However, if the current number is less than or equal to the largest number seen
-so far, the variable doesn’t change, and the code moves on to the next number
-in the list. After considering all the numbers in the list, `largest` should
-refer to the largest number, which in this case is 100.
+We store a list of integers in the variable `number_list` [1] and place a
+reference to the first number in the list in a variable named `largest` [2]. We
+then iterate through all the numbers in the list [3], and if the current number
+is greater than the number stored in `largest` [4], we replace the reference in
+that variable [5]. However, if the current number is less than or equal to the
+largest number seen so far, the variable doesn’t change, and the code moves on
+to the next number in the list. After considering all the numbers in the list,
+`largest` should refer to the largest number, which in this case is 100.
-We've now been tasked with finding the largest number in two different lists of
+We’ve now been tasked with finding the largest number in two different lists of
numbers. To do so, we can choose to duplicate the code in Listing 10-1 and use
the same logic at two different places in the program, as shown in Listing 10-2.
@@ -97,7 +97,7 @@ fn main() {
}
}
- println!("The largest number is {}", largest);
+ println!("The largest number is {largest}");
let number_list = vec![102, 34, 6000, 89, 54, 2, 43, 8];
@@ -109,7 +109,7 @@ fn main() {
}
}
- println!("The largest number is {}", largest);
+ println!("The largest number is {largest}");
}
```
@@ -148,12 +148,12 @@ fn main() {
let number_list = vec![34, 50, 25, 100, 65];
let result = largest(&number_list);
- println!("The largest number is {}", result);
+ println!("The largest number is {result}");
let number_list = vec![102, 34, 6000, 89, 54, 2, 43, 8];
let result = largest(&number_list);
- println!("The largest number is {}", result);
+ println!("The largest number is {result}");
}
```
@@ -161,22 +161,15 @@ Listing 10-3: Abstracted code to find the largest number in two lists
The `largest` function has a parameter called `list`, which represents any
concrete slice of `i32` values we might pass into the function. As a result,
-when we call the function, the code runs on the specific values that we pass
-in.
+when we call the function, the code runs on the specific values that we pass in.
In summary, here are the steps we took to change the code from Listing 10-2 to
Listing 10-3:
-<!---
-"In summary"?
-/JT --->
-<!-- I believe "In sum" to be fine, but other people have been confused by it
-as well, so I'm ok changing it. /Carol -->
-
1. Identify duplicate code.
-2. Extract the duplicate code into the body of the function and specify the
- inputs and return values of that code in the function signature.
-3. Update the two instances of duplicated code to call the function instead.
+1. Extract the duplicate code into the body of the function, and specify the
+inputs and return values of that code in the function signature.
+1. Update the two instances of duplicated code to call the function instead.
Next, we’ll use these same steps with generics to reduce code duplication. In
the same way that the function body can operate on an abstract `list` instead
@@ -201,7 +194,7 @@ parameters and return value. Doing so makes our code more flexible and provides
more functionality to callers of our function while preventing code duplication.
Continuing with our `largest` function, Listing 10-4 shows two functions that
-both find the largest value in a slice. We'll then combine these into a single
+both find the largest value in a slice. We’ll then combine these into a single
function that uses generics.
Filename: src/main.rs
@@ -235,16 +228,16 @@ fn main() {
let number_list = vec![34, 50, 25, 100, 65];
let result = largest_i32(&number_list);
- println!("The largest number is {}", result);
+ println!("The largest number is {result}");
let char_list = vec!['y', 'm', 'a', 'q'];
let result = largest_char(&char_list);
- println!("The largest char is {}", result);
+ println!("The largest char is {result}");
}
```
-Listing 10-4: Two functions that differ only in their names and the types in
+Listing 10-4: Two functions that differ only in their names and in the types in
their signatures
The `largest_i32` function is the one we extracted in Listing 10-3 that finds
@@ -255,16 +248,16 @@ the duplication by introducing a generic type parameter in a single function.
To parameterize the types in a new single function, we need to name the type
parameter, just as we do for the value parameters to a function. You can use
any identifier as a type parameter name. But we’ll use `T` because, by
-convention, parameter names in Rust are short, often just a letter, and Rust’s
-type-naming convention is CamelCase. Short for “type,†`T` is the default
-choice of most Rust programmers.
+convention, type parameter names in Rust are short, often just one letter, and
+Rust’s type-naming convention is CamelCase. Short for *type*, `T` is the
+default choice of most Rust programmers.
When we use a parameter in the body of the function, we have to declare the
parameter name in the signature so the compiler knows what that name means.
Similarly, when we use a type parameter name in a function signature, we have
to declare the type parameter name before we use it. To define the generic
-`largest` function, place type name declarations inside angle brackets, `<>`,
-between the name of the function and the parameter list, like this:
+`largest` function, we place type name declarations inside angle brackets,
+`<>`, between the name of the function and the parameter list, like this:
```
fn largest<T>(list: &[T]) -> &T {
@@ -299,33 +292,33 @@ fn main() {
let number_list = vec![34, 50, 25, 100, 65];
let result = largest(&number_list);
- println!("The largest number is {}", result);
+ println!("The largest number is {result}");
let char_list = vec!['y', 'm', 'a', 'q'];
let result = largest(&char_list);
- println!("The largest char is {}", result);
+ println!("The largest char is {result}");
}
```
Listing 10-5: The `largest` function using generic type parameters; this
-doesn’t yet compile yet
+doesn’t compile yet
If we compile this code right now, we’ll get this error:
```
-error[E0369]: binary operation `>` cannot be applied to type `T`
+error[E0369]: binary operation `>` cannot be applied to type `&T`
--> src/main.rs:5:17
|
5 | if item > largest {
- | ---- ^ ------- T
+ | ---- ^ ------- &T
| |
- | T
+ | &T
|
help: consider restricting type parameter `T`
|
-1 | fn largest<T: std::cmp::PartialOrd>(list: &[T]) -> T {
- | ^^^^^^^^^^^^^^^^^^^^^^
+1 | fn largest<T: std::cmp::PartialOrd>(list: &[T]) -> &T {
+ | ++++++++++++++++++++++
```
The help text mentions `std::cmp::PartialOrd`, which is a *trait*, and we’re
@@ -334,31 +327,11 @@ states that the body of `largest` won’t work for all possible types that `T`
could be. Because we want to compare values of type `T` in the body, we can
only use types whose values can be ordered. To enable comparisons, the standard
library has the `std::cmp::PartialOrd` trait that you can implement on types
-(see Appendix C for more on this trait). By following the help text's
+(see Appendix C for more on this trait). By following the help text’s
suggestion, we restrict the types valid for `T` to only those that implement
`PartialOrd` and this example will compile, because the standard library
implements `PartialOrd` on both `i32` and `char`.
-<!---
-The wording at the end of the above paragraph feels a little odd. For the
-"You’ll learn how to specify that a generic type has a particular trait in the
-“Traits as Parameters†section." -- the error message above tells you how to
-maybe fix it.
-
-Well, it *could* fix it but the way the example is written adds multiple
-constraints.
-
-Do we want to leave this example unfinished and move onto other topics for a
-bit or revise the example so it's more self-contained, allowing the compiler to
-help us and later revisit after we've learned more?
-/JT --->
-<!-- I've modified the example and explanation just slightly so that only
-adding the `PartialOrd` trait as suggested here will fix it completely, perhaps
-leaving the reader hanging a little bit less. It's really hard to teach
-generics and trait bounds, though, because you can't do much with generics
-unless you have trait bounds too (and can't learn why you'd want trait bounds
-without knowing about generics). /Carol -->
-
### In Struct Definitions
We can also define structs to use a generic type parameter in one or more
@@ -368,9 +341,9 @@ fields using the `<>` syntax. Listing 10-6 defines a `Point<T>` struct to hold
Filename: src/main.rs
```
-struct Point<T> {
- x: T,
- y: T,
+1 struct Point<T> {
+ 2 x: T,
+ 3 y: T,
}
fn main() {
@@ -382,9 +355,10 @@ fn main() {
Listing 10-6: A `Point<T>` struct that holds `x` and `y` values of type `T`
The syntax for using generics in struct definitions is similar to that used in
-function definitions. First, we declare the name of the type parameter inside
-angle brackets just after the name of the struct. Then we use the generic type
-in the struct definition where we would otherwise specify concrete data types.
+function definitions. First we declare the name of the type parameter inside
+angle brackets just after the name of the struct [1]. Then we use the generic
+type in the struct definition where we would otherwise specify concrete data
+types [23].
Note that because we’ve used only one generic type to define `Point<T>`, this
definition says that the `Point<T>` struct is generic over some type `T`, and
@@ -408,42 +382,18 @@ fn main() {
Listing 10-7: The fields `x` and `y` must be the same type because both have
the same generic data type `T`.
-In this example, when we assign the integer value 5 to `x`, we let the compiler
-know that the generic type `T` will be an integer for this instance of
-`Point<T>`. Then when we specify 4.0 for `y`, which we’ve defined to have the
+In this example, when we assign the integer value `5` to `x`, we let the
+compiler know that the generic type `T` will be an integer for this instance of
+`Point<T>`. Then when we specify `4.0` for `y`, which we’ve defined to have the
same type as `x`, we’ll get a type mismatch error like this:
-<!---
-Not sure how or where we might want to call this out, but this is also how
-type inference in Rust works. If we don't know the type, we look for how it's
-used. That fresh type becomes a concrete type, and any use after that which
-is different than we expect becomes an error.
-
-fn main() {
- let mut x;
-
- x = 5;
- x = 4.0;
-}
-
-Also gives:
- |
-2 | let mut x;
- | ----- expected due to the type of this binding
-...
-5 | x = 4.0;
- | ^^^ expected integer, found floating-point number
-
-/JT --->
-<!-- Yeah, it's kind of neat trivia, but doesn't really fit here I don't think.
-/Carol -->
-
```
error[E0308]: mismatched types
--> src/main.rs:7:38
|
7 | let wont_work = Point { x: 5, y: 4.0 };
- | ^^^ expected integer, found floating-point number
+ | ^^^ expected integer, found floating-
+point number
```
To define a `Point` struct where `x` and `y` are both generics but could have
@@ -471,7 +421,7 @@ values of different types
Now all the instances of `Point` shown are allowed! You can use as many generic
type parameters in a definition as you want, but using more than a few makes
-your code hard to read. If you're finding you need lots of generic types in
+your code hard to read. If you’re finding you need lots of generic types in
your code, it could indicate that your code needs restructuring into smaller
pieces.
@@ -521,7 +471,7 @@ avoid duplication by using generic types instead.
### In Method Definitions
We can implement methods on structs and enums (as we did in Chapter 5) and use
-generic types in their definitions, too. Listing 10-9 shows the `Point<T>`
+generic types in their definitions too. Listing 10-9 shows the `Point<T>`
struct we defined in Listing 10-6 with a method named `x` implemented on it.
Filename: src/main.rs
@@ -545,16 +495,6 @@ fn main() {
}
```
-<!---
-
-The above code gives a warning for the unused `y`. Maybe we can print both
-`x` and `y`?
-
-/JT --->
-<!-- In general, I'm not worried about unused code warnings, there's a lot of
-examples that have unused code because they're small examples. I don't think
-there's much value in adding a method and printing `y` as well. /Carol -->
-
Listing 10-9: Implementing a method named `x` on the `Point<T>` struct that
will return a reference to the `x` field of type `T`
@@ -593,7 +533,7 @@ This code means the type `Point<f32>` will have a `distance_from_origin`
method; other instances of `Point<T>` where `T` is not of type `f32` will not
have this method defined. The method measures how far our point is from the
point at coordinates (0.0, 0.0) and uses mathematical operations that are
-available only for floating point types.
+available only for floating-point types.
Generic type parameters in a struct definition aren’t always the same as those
you use in that same struct’s method signatures. Listing 10-11 uses the generic
@@ -610,8 +550,11 @@ struct Point<X1, Y1> {
y: Y1,
}
-impl<X1, Y1> Point<X1, Y1> {
- fn mixup<X2, Y2>(self, other: Point<X2, Y2>) -> Point<X1, Y2> {
+1 impl<X1, Y1> Point<X1, Y1> {
+ 2 fn mixup<X2, Y2>(
+ self,
+ other: Point<X2, Y2>,
+ ) -> Point<X1, Y2> {
Point {
x: self.x,
y: other.y,
@@ -620,12 +563,12 @@ impl<X1, Y1> Point<X1, Y1> {
}
fn main() {
- let p1 = Point { x: 5, y: 10.4 };
- let p2 = Point { x: "Hello", y: 'c' };
+ 3 let p1 = Point { x: 5, y: 10.4 };
+ 4 let p2 = Point { x: "Hello", y: 'c' };
- let p3 = p1.mixup(p2);
+ 5 let p3 = p1.mixup(p2);
- println!("p3.x = {}, p3.y = {}", p3.x, p3.y);
+ 6 println!("p3.x = {}, p3.y = {}", p3.x, p3.y);
}
```
@@ -633,25 +576,25 @@ Listing 10-11: A method that uses generic types different from its struct’s
definition
In `main`, we’ve defined a `Point` that has an `i32` for `x` (with value `5`)
-and an `f64` for `y` (with value `10.4`). The `p2` variable is a `Point` struct
-that has a string slice for `x` (with value `"Hello"`) and a `char` for `y`
-(with value `c`). Calling `mixup` on `p1` with the argument `p2` gives us `p3`,
-which will have an `i32` for `x`, because `x` came from `p1`. The `p3` variable
-will have a `char` for `y`, because `y` came from `p2`. The `println!` macro
-call will print `p3.x = 5, p3.y = c`.
+and an `f64` for `y` (with value `10.4` [3]). The `p2` variable is a `Point`
+struct that has a string slice for `x` (with value `"Hello"`) and a `char` for
+`y` (with value `c` [4]). Calling `mixup` on `p1` with the argument `p2` gives
+us `p3` [5], which will have an `i32` for `x` because `x` came from `p1`. The
+`p3` variable will have a `char` for `y` because `y` came from `p2`. The
+`println!` macro call [6] will print `p3.x = 5, p3.y = c`.
The purpose of this example is to demonstrate a situation in which some generic
parameters are declared with `impl` and some are declared with the method
definition. Here, the generic parameters `X1` and `Y1` are declared after
-`impl` because they go with the struct definition. The generic parameters `X2`
-and `Y2` are declared after `fn mixup`, because they’re only relevant to the
-method.
+`impl` [1] because they go with the struct definition. The generic parameters
+`X2` and `Y2` are declared after `fn mixup` [2] because they’re only relevant
+to the method.
### Performance of Code Using Generics
You might be wondering whether there is a runtime cost when using generic type
-parameters. The good news is that using generic types won't make your run any
-slower than it would with concrete types.
+parameters. The good news is that using generic types won’t make your program
+run any slower than it would with concrete types.
Rust accomplishes this by performing monomorphization of the code using
generics at compile time. *Monomorphization* is the process of turning generic
@@ -676,15 +619,6 @@ is `f64`. As such, it expands the generic definition of `Option<T>` into two
definitions specialized to `i32` and `f64`, thereby replacing the generic
definition with the specific ones.
-<!---
-
-We may want to be clear in the above it doesn't actually do this, as you
-wouldn't be able to write `enum Option_i32` in your code as it would clash.
-
-/JT --->
-<!-- I've reworded the last sentence in the above paragraph and the next
-sentence to hopefully sidestep the issue JT pointed out. /Carol -->
-
The monomorphized version of the code looks similar to the following (the
compiler uses different names than what we’re using here for illustration):
@@ -716,13 +650,13 @@ at runtime.
## Traits: Defining Shared Behavior
-A *trait* defines functionality a particular type has and can share with other
-types. We can use traits to define shared behavior in an abstract way. We can
-use *trait bounds* to specify that a generic type can be any type that has
+A *trait* defines the functionality a particular type has and can share with
+other types. We can use traits to define shared behavior in an abstract way. We
+can use *trait bounds* to specify that a generic type can be any type that has
certain behavior.
> Note: Traits are similar to a feature often called *interfaces* in other
-> languages, although with some differences.
+languages, although with some differences.
### Defining a Trait
@@ -733,15 +667,15 @@ define a set of behaviors necessary to accomplish some purpose.
For example, let’s say we have multiple structs that hold various kinds and
amounts of text: a `NewsArticle` struct that holds a news story filed in a
-particular location and a `Tweet` that can have at most 280 characters along
+particular location and a `Tweet` that can have, at most, 280 characters along
with metadata that indicates whether it was a new tweet, a retweet, or a reply
to another tweet.
We want to make a media aggregator library crate named `aggregator` that can
display summaries of data that might be stored in a `NewsArticle` or `Tweet`
-instance. To do this, we need a summary from each type, and we’ll request
-that summary by calling a `summarize` method on an instance. Listing 10-12
-shows the definition of a public `Summary` trait that expresses this behavior.
+instance. To do this, we need a summary from each type, and we’ll request that
+summary by calling a `summarize` method on an instance. Listing 10-12 shows the
+definition of a public `Summary` trait that expresses this behavior.
Filename: src/lib.rs
@@ -755,7 +689,7 @@ Listing 10-12: A `Summary` trait that consists of the behavior provided by a
`summarize` method
Here, we declare a trait using the `trait` keyword and then the trait’s name,
-which is `Summary` in this case. We’ve also declared the trait as `pub` so that
+which is `Summary` in this case. We also declare the trait as `pub` so that
crates depending on this crate can make use of this trait too, as we’ll see in
a few examples. Inside the curly brackets, we declare the method signatures
that describe the behaviors of the types that implement this trait, which in
@@ -768,7 +702,7 @@ that any type that has the `Summary` trait will have the method `summarize`
defined with this signature exactly.
A trait can have multiple methods in its body: the method signatures are listed
-one per line and each line ends in a semicolon.
+one per line, and each line ends in a semicolon.
### Implementing a Trait on a Type
@@ -777,7 +711,7 @@ we can implement it on the types in our media aggregator. Listing 10-13 shows
an implementation of the `Summary` trait on the `NewsArticle` struct that uses
the headline, the author, and the location to create the return value of
`summarize`. For the `Tweet` struct, we define `summarize` as the username
-followed by the entire text of the tweet, assuming that tweet content is
+followed by the entire text of the tweet, assuming that the tweet content is
already limited to 280 characters.
Filename: src/lib.rs
@@ -792,7 +726,12 @@ pub struct NewsArticle {
impl Summary for NewsArticle {
fn summarize(&self) -> String {
- format!("{}, by {} ({})", self.headline, self.author, self.location)
+ format!(
+ "{}, by {} ({})",
+ self.headline,
+ self.author,
+ self.location
+ )
}
}
@@ -821,8 +760,6 @@ that the trait definition has defined. Instead of adding a semicolon after each
signature, we use curly brackets and fill in the method body with the specific
behavior that we want the methods of the trait to have for the particular type.
-<!-- NOTE TO ADD SOME NUMBER INDICATORS HERE IN THE WORD FILES -->
-
Now that the library has implemented the `Summary` trait on `NewsArticle` and
`Tweet`, users of the crate can call the trait methods on instances of
`NewsArticle` and `Tweet` in the same way we call regular methods. The only
@@ -852,23 +789,23 @@ know, people`.
Other crates that depend on the `aggregator` crate can also bring the `Summary`
trait into scope to implement `Summary` on their own types. One restriction to
-note is that we can implement a trait on a type only if at least one of the
-trait or the type is local to our crate. For example, we can implement standard
+note is that we can implement a trait on a type only if either the trait or the
+type, or both, are local to our crate. For example, we can implement standard
library traits like `Display` on a custom type like `Tweet` as part of our
-`aggregator` crate functionality, because the type `Tweet` is local to our
+`aggregator` crate functionality because the type `Tweet` is local to our
`aggregator` crate. We can also implement `Summary` on `Vec<T>` in our
-`aggregator` crate, because the trait `Summary` is local to our `aggregator`
+`aggregator` crate because the trait `Summary` is local to our `aggregator`
crate.
But we can’t implement external traits on external types. For example, we can’t
-implement the `Display` trait on `Vec<T>` within our `aggregator` crate,
-because `Display` and `Vec<T>` are both defined in the standard library and
-aren’t local to our `aggregator` crate. This restriction is part of a property
-called *coherence*, and more specifically the *orphan rule*, so named because
-the parent type is not present. This rule ensures that other people’s code
-can’t break your code and vice versa. Without the rule, two crates could
-implement the same trait for the same type, and Rust wouldn’t know which
-implementation to use.
+implement the `Display` trait on `Vec<T>` within our `aggregator` crate because
+`Display` and `Vec<T>` are both defined in the standard library and aren’t
+local to our `aggregator` crate. This restriction is part of a property called
+*coherence*, and more specifically the *orphan rule*, so named because the
+parent type is not present. This rule ensures that other people’s code can’t
+break your code and vice versa. Without the rule, two crates could implement
+the same trait for the same type, and Rust wouldn’t know which implementation
+to use.
### Default Implementations
@@ -877,7 +814,7 @@ in a trait instead of requiring implementations for all methods on every type.
Then, as we implement the trait on a particular type, we can keep or override
each method’s default behavior.
-In Listing 10-14 we specify a default string for the `summarize` method of the
+In Listing 10-14, we specify a default string for the `summarize` method of the
`Summary` trait instead of only defining the method signature, as we did in
Listing 10-12.
@@ -891,8 +828,8 @@ pub trait Summary {
}
```
-Listing 10-14: Defining a `Summary` trait with a default implementation of
-the `summarize` method
+Listing 10-14: Defining a `Summary` trait with a default implementation of the
+`summarize` method
To use a default implementation to summarize instances of `NewsArticle`, we
specify an empty `impl` block with `impl Summary for NewsArticle {}`.
@@ -904,7 +841,9 @@ the `summarize` method on an instance of `NewsArticle`, like this:
```
let article = NewsArticle {
- headline: String::from("Penguins win the Stanley Cup Championship!"),
+ headline: String::from(
+ "Penguins win the Stanley Cup Championship!"
+ ),
location: String::from("Pittsburgh, PA, USA"),
author: String::from("Iceburgh"),
content: String::from(
@@ -936,7 +875,10 @@ pub trait Summary {
fn summarize_author(&self) -> String;
fn summarize(&self) -> String {
- format!("(Read more from {}...)", self.summarize_author())
+ format!(
+ "(Read more from {}...)",
+ self.summarize_author()
+ )
}
}
```
@@ -956,7 +898,8 @@ After we define `summarize_author`, we can call `summarize` on instances of the
`Tweet` struct, and the default implementation of `summarize` will call the
definition of `summarize_author` that we’ve provided. Because we’ve implemented
`summarize_author`, the `Summary` trait has given us the behavior of the
-`summarize` method without requiring us to write any more code.
+`summarize` method without requiring us to write any more code. Here’s what
+that looks like:
```
let tweet = Tweet {
@@ -979,7 +922,7 @@ overriding implementation of that same method.
### Traits as Parameters
Now that you know how to define and implement traits, we can explore how to use
-traits to define functions that accept many different types. We'll use the
+traits to define functions that accept many different types. We’ll use the
`Summary` trait we implemented on the `NewsArticle` and `Tweet` types in
Listing 10-13 to define a `notify` function that calls the `summarize` method
on its `item` parameter, which is of some type that implements the `Summary`
@@ -1036,7 +979,7 @@ The generic type `T` specified as the type of the `item1` and `item2`
parameters constrains the function such that the concrete type of the value
passed as an argument for `item1` and `item2` must be the same.
-#### Specifying Multiple Trait Bounds with the `+` Syntax
+#### Specifying Multiple Trait Bounds with the + Syntax
We can also specify more than one trait bound. Say we wanted `notify` to use
display formatting as well as `summarize` on `item`: we specify in the `notify`
@@ -1056,14 +999,14 @@ pub fn notify<T: Summary + Display>(item: &T) {
With the two trait bounds specified, the body of `notify` can call `summarize`
and use `{}` to format `item`.
-#### Clearer Trait Bounds with `where` Clauses
+#### Clearer Trait Bounds with where Clauses
Using too many trait bounds has its downsides. Each generic has its own trait
bounds, so functions with multiple generic type parameters can contain lots of
trait bound information between the function’s name and its parameter list,
making the function signature hard to read. For this reason, Rust has alternate
syntax for specifying trait bounds inside a `where` clause after the function
-signature. So instead of writing this:
+signature. So, instead of writing this:
```
fn some_function<T: Display + Clone, U: Clone + Debug>(t: &T, u: &U) -> i32 {
@@ -1073,8 +1016,9 @@ we can use a `where` clause, like this:
```
fn some_function<T, U>(t: &T, u: &U) -> i32
- where T: Display + Clone,
- U: Clone + Debug
+where
+ T: Display + Clone,
+ U: Clone + Debug,
{
```
@@ -1082,7 +1026,7 @@ This function’s signature is less cluttered: the function name, parameter list
and return type are close together, similar to a function without lots of trait
bounds.
-### Returning Types that Implement Traits
+### Returning Types That Implement Traits
We can also use the `impl Trait` syntax in the return position to return a
value of some type that implements a trait, as shown here:
@@ -1145,22 +1089,17 @@ fn returns_summarizable(switch: bool) -> impl Summary {
Returning either a `NewsArticle` or a `Tweet` isn’t allowed due to restrictions
around how the `impl Trait` syntax is implemented in the compiler. We’ll cover
-how to write a function with this behavior in the “Using Trait Objects That
-Allow for Values of Different Types†section of Chapter 17.
-
-<!-- I've removed the whole "Fixing the `largest` Function with Trait Bounds"
-section now that the example is slightly different and adding the one trait
-bound as the compiler suggests fixed Listing 10-5 earlier. I've also renumbered
-the following listings. /Carol-->
+how to write a function with this behavior in “Using Trait Objects That Allow
+for Values of Different Types†on page XX.
### Using Trait Bounds to Conditionally Implement Methods
By using a trait bound with an `impl` block that uses generic type parameters,
we can implement methods conditionally for types that implement the specified
traits. For example, the type `Pair<T>` in Listing 10-15 always implements the
-`new` function to return a new instance of `Pair<T>` (recall from the “Defining
-Methods†section of Chapter 5 that `Self` is a type alias for the type of the
-`impl` block, which in this case is `Pair<T>`). But in the next `impl` block,
+`new` function to return a new instance of `Pair<T>` (recall from “Defining
+Methods†on page XX that `Self` is a type alias for the type of the `impl`
+block, which in this case is `Pair<T>`). But in the next `impl` block,
`Pair<T>` only implements the `cmp_display` method if its inner type `T`
implements the `PartialOrd` trait that enables comparison *and* the `Display`
trait that enables printing.
@@ -1197,14 +1136,14 @@ on trait bounds
We can also conditionally implement a trait for any type that implements
another trait. Implementations of a trait on any type that satisfies the trait
-bounds are called *blanket implementations* and are extensively used in the
+bounds are called *blanket implementations* and are used extensively in the
Rust standard library. For example, the standard library implements the
`ToString` trait on any type that implements the `Display` trait. The `impl`
block in the standard library looks similar to this code:
```
impl<T: Display> ToString for T {
- // --snip--
+ --snip--
}
```
@@ -1225,48 +1164,27 @@ reduce duplication but also specify to the compiler that we want the generic
type to have particular behavior. The compiler can then use the trait bound
information to check that all the concrete types used with our code provide the
correct behavior. In dynamically typed languages, we would get an error at
-runtime if we called a method on a type which didn’t define the method. But Rust
-moves these errors to compile time so we’re forced to fix the problems before
-our code is even able to run. Additionally, we don’t have to write code that
-checks for behavior at runtime because we’ve already checked at compile time.
-Doing so improves performance without having to give up the flexibility of
-generics.
+runtime if we called a method on a type which didn’t define the method. But
+Rust moves these errors to compile time so we’re forced to fix the problems
+before our code is even able to run. Additionally, we don’t have to write code
+that checks for behavior at runtime because we’ve already checked at compile
+time. Doing so improves performance without having to give up the flexibility
+of generics.
## Validating References with Lifetimes
-<!---
-
-meta comment: this chapter is already pretty hefty. We just went through both
-generics and a whirlwind tour of traits. Lifetimes, while related to generics,
-feel like you might want to give a five minute break between them, let those
-sink in, and then pick up this topic.
-
-I noticed a couple topics we may want to touch on above for a bit of
-completeness:
-
-* A closer look at how From/Into work and how they relate to each other.
-* Using traits to specialize what you do when returning values.
- i.e., Why does `let four: u32 = "4".parse().unwrap();` work?
-* Turbofish
-
-/JT --->
-<!-- These comments are totally valid, but seeing as this revision is already
-dragging on later than we were hoping, I don't really want to do large scale
-reorganization at this point. /Carol -->
-
Lifetimes are another kind of generic that we’ve already been using. Rather
than ensuring that a type has the behavior we want, lifetimes ensure that
references are valid as long as we need them to be.
-One detail we didn’t discuss in the “References and Borrowing†section in
-Chapter 4 is that every reference in Rust has a *lifetime*, which is the scope
-for which that reference is valid. Most of the time, lifetimes are implicit and
-inferred, just like most of the time, types are inferred. We only must annotate
-types when multiple types are possible. In a similar way, we must annotate
-lifetimes when the lifetimes of references could be related in a few different
-ways. Rust requires us to annotate the relationships using generic lifetime
-parameters to ensure the actual references used at runtime will definitely be
-valid.
+One detail we didn’t discuss in “References and Borrowing†on page XX is that
+every reference in Rust has a *lifetime*, which is the scope for which that
+reference is valid. Most of the time, lifetimes are implicit and inferred, just
+like most of the time, types are inferred. We must annotate types only when
+multiple types are possible. In a similar way, we must annotate lifetimes when
+the lifetimes of references could be related in a few different ways. Rust
+requires us to annotate the relationships using generic lifetime parameters to
+ensure the actual references used at runtime will definitely be valid.
Annotating lifetimes is not even a concept most other programming languages
have, so this is going to feel unfamiliar. Although we won’t cover lifetimes in
@@ -1282,32 +1200,32 @@ scope.
```
fn main() {
- let r;
+ 1 let r;
{
- let x = 5;
- r = &x;
- }
+ 2 let x = 5;
+ 3 r = &x;
+ 4 }
- println!("r: {}", r);
+ 5 println!("r: {r}");
}
```
Listing 10-16: An attempt to use a reference whose value has gone out of scope
-> Note: The examples in Listings 10-16, 10-17, and 10-23 declare variables
-> without giving them an initial value, so the variable name exists in the
-> outer scope. At first glance, this might appear to be in conflict with Rust’s
-> having no null values. However, if we try to use a variable before giving it
-> a value, we’ll get a compile-time error, which shows that Rust indeed does
-> not allow null values.
+> Note: The examples in Listing 10-16, 10-17, and 10-23 declare variables
+without giving them an initial value, so the variable name exists in the outer
+scope. At first glance, this might appear to be in conflict with Rust’s having
+no null values. However, if we try to use a variable before giving it a value,
+we’ll get a compile-time error, which shows that Rust indeed does not allow
+null values.
-The outer scope declares a variable named `r` with no initial value, and the
-inner scope declares a variable named `x` with the initial value of 5. Inside
-the inner scope, we attempt to set the value of `r` as a reference to `x`. Then
-the inner scope ends, and we attempt to print the value in `r`. This code won’t
-compile because the value `r` is referring to has gone out of scope before we
-try to use it. Here is the error message:
+The outer scope declares a variable named `r` with no initial value [1], and
+the inner scope declares a variable named `x` with the initial value of `5`
+[2]. Inside the inner scope, we attempt to set the value of `r` as a reference
+to `x` [3]. Then the inner scope ends [4], and we attempt to print the value in
+`r` [5]. This code won’t compile because the value that `r` is referring to has
+gone out of scope before we try to use it. Here is the error message:
```
error[E0597]: `x` does not live long enough
@@ -1318,17 +1236,17 @@ error[E0597]: `x` does not live long enough
7 | }
| - `x` dropped here while still borrowed
8 |
-9 | println!("r: {}", r);
- | - borrow later used here
+9 | println!("r: {r}");
+ | - borrow later used here
```
-The variable `x` doesn’t “live long enough.†The reason is that `x` will be out
-of scope when the inner scope ends on line 7. But `r` is still valid for the
-outer scope; because its scope is larger, we say that it “lives longer.†If
-Rust allowed this code to work, `r` would be referencing memory that was
-deallocated when `x` went out of scope, and anything we tried to do with `r`
-wouldn’t work correctly. So how does Rust determine that this code is invalid?
-It uses a borrow checker.
+The error message says that the variable `x` “does not live long enough.†The
+reason is that `x` will be out of scope when the inner scope ends on line 7.
+But `r` is still valid for the outer scope; because its scope is larger, we say
+that it “lives longer.†If Rust allowed this code to work, `r` would be
+referencing memory that was deallocated when `x` went out of scope, and
+anything we tried to do with `r` wouldn’t work correctly. So how does Rust
+determine that this code is invalid? It uses a borrow checker.
### The Borrow Checker
@@ -1345,7 +1263,7 @@ fn main() {
r = &x; // | |
} // -+ |
// |
- println!("r: {}", r); // |
+ println!("r: {r}"); // |
} // ---------+
```
@@ -1359,7 +1277,7 @@ lifetimes and sees that `r` has a lifetime of `'a` but that it refers to memory
with a lifetime of `'b`. The program is rejected because `'b` is shorter than
`'a`: the subject of the reference doesn’t live as long as the reference.
-Listing 10-18 fixes the code so it doesn’t have a dangling reference and
+Listing 10-18 fixes the code so it doesn’t have a dangling reference and it
compiles without any errors.
```
@@ -1368,7 +1286,7 @@ fn main() {
// |
let r = &x; // --+-- 'a |
// | |
- println!("r: {}", r); // | |
+ println!("r: {r}"); // | |
// --+ |
} // ----------+
```
@@ -1399,7 +1317,7 @@ fn main() {
let string2 = "xyz";
let result = longest(string1.as_str(), string2);
- println!("The longest string is {}", result);
+ println!("The longest string is {result}");
}
```
@@ -1408,9 +1326,9 @@ longer of two string slices
Note that we want the function to take string slices, which are references,
rather than strings, because we don’t want the `longest` function to take
-ownership of its parameters. Refer to the “String Slices as Parameters†section
-in Chapter 4 for more discussion about why the parameters we use in Listing
-10-19 are the ones we want.
+ownership of its parameters. Refer to “String Slices as Parameters†on page XX
+for more discussion about why the parameters we use in Listing 10-19 are the
+ones we want.
If we try to implement the `longest` function as shown in Listing 10-20, it
won’t compile.
@@ -1439,11 +1357,12 @@ error[E0106]: missing lifetime specifier
9 | fn longest(x: &str, y: &str) -> &str {
| ---- ---- ^ expected named lifetime parameter
|
- = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `x` or `y`
+ = help: this function's return type contains a borrowed value,
+but the signature does not say whether it is borrowed from `x` or `y`
help: consider introducing a named lifetime parameter
|
9 | fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
- | ^^^^ ^^^^^^^ ^^^^^^^ ^^^
+ | ++++ ++ ++ ++
```
The help text reveals that the return type needs a generic lifetime parameter
@@ -1487,25 +1406,16 @@ reference to an `i32` that also has the lifetime `'a`.
&'a mut i32 // a mutable reference with an explicit lifetime
```
-One lifetime annotation by itself doesn’t have much meaning, because the
+One lifetime annotation by itself doesn’t have much meaning because the
annotations are meant to tell Rust how generic lifetime parameters of multiple
references relate to each other. Let’s examine how the lifetime annotations
relate to each other in the context of the `longest` function.
-<!---
-
-The above description is a little hard to follow with a code example.
-
-/JT --->
-<!-- Rather than fleshing out the code that goes with this description, I've
-moved some of the description to the next section to go with the code example
-there. /Carol -->
-
### Lifetime Annotations in Function Signatures
To use lifetime annotations in function signatures, we need to declare the
generic *lifetime* parameters inside angle brackets between the function name
-and the parameter list, just as we did with generic *type* parameters
+and the parameter list, just as we did with generic *type* parameters.
We want the signature to express the following constraint: the returned
reference will be valid as long as both the parameters are valid. This is the
@@ -1579,7 +1489,7 @@ fn main() {
{
let string2 = String::from("xyz");
let result = longest(string1.as_str(), string2.as_str());
- println!("The longest string is {}", result);
+ println!("The longest string is {result}");
}
}
```
@@ -1589,7 +1499,7 @@ that have different concrete lifetimes
In this example, `string1` is valid until the end of the outer scope, `string2`
is valid until the end of the inner scope, and `result` references something
-that is valid until the end of the inner scope. Run this code, and you’ll see
+that is valid until the end of the inner scope. Run this code and you’ll see
that the borrow checker approves; it will compile and print `The longest string
is long string is long`.
@@ -1611,7 +1521,7 @@ fn main() {
let string2 = String::from("xyz");
result = longest(string1.as_str(), string2.as_str());
}
- println!("The longest string is {}", result);
+ println!("The longest string is {result}");
}
```
@@ -1624,11 +1534,12 @@ error[E0597]: `string2` does not live long enough
--> src/main.rs:6:44
|
6 | result = longest(string1.as_str(), string2.as_str());
- | ^^^^^^^ borrowed value does not live long enough
+ | ^^^^^^^^^^^^^^^^ borrowed value
+does not live long enough
7 | }
| - `string2` dropped here while still borrowed
-8 | println!("The longest string is {}", result);
- | ------ borrow later used here
+8 | println!("The longest string is {result}");
+ | ------ borrow later used here
```
The error shows that for `result` to be valid for the `println!` statement,
@@ -1637,7 +1548,7 @@ this because we annotated the lifetimes of the function parameters and return
values using the same lifetime parameter `'a`.
As humans, we can look at this code and see that `string1` is longer than
-`string2` and therefore `result` will contain a reference to `string1`.
+`string2`, and therefore, `result` will contain a reference to `string1`.
Because `string1` has not gone out of scope yet, a reference to `string1` will
still be valid for the `println!` statement. However, the compiler can’t see
that the reference is valid in this case. We’ve told Rust that the lifetime of
@@ -1693,14 +1604,12 @@ lifetime is not related to the lifetime of the parameters at all. Here is the
error message we get:
```
-error[E0515]: cannot return value referencing local variable `result`
+error[E0515]: cannot return reference to local variable `result`
--> src/main.rs:11:5
|
11 | result.as_str()
- | ------^^^^^^^^^
- | |
- | returns a value referencing data owned by the current function
- | `result` is borrowed here
+ | ^^^^^^^^^^^^^^^ returns a reference to data owned by the
+current function
```
The problem is that `result` goes out of scope and gets cleaned up at the end
@@ -1718,29 +1627,27 @@ would create dangling pointers or otherwise violate memory safety.
### Lifetime Annotations in Struct Definitions
-So far, the structs we’ve defined all hold owned types. We can define structs to
-hold references, but in that case we would need to add a lifetime annotation on
-every reference in the struct’s definition. Listing 10-24 has a struct named
+So far, the structs we’ve defined all hold owned types. We can define structs
+to hold references, but in that case we would need to add a lifetime annotation
+on every reference in the struct’s definition. Listing 10-24 has a struct named
`ImportantExcerpt` that holds a string slice.
-<!---
-
-nit: "So far, the structs we've *defined* all hold owned types"
-
-/JT --->
-<!-- Fixed! /Carol -->
-
Filename: src/main.rs
```
-struct ImportantExcerpt<'a> {
- part: &'a str,
+1 struct ImportantExcerpt<'a> {
+ 2 part: &'a str,
}
fn main() {
- let novel = String::from("Call me Ishmael. Some years ago...");
- let first_sentence = novel.split('.').next().expect("Could not find a '.'");
- let i = ImportantExcerpt {
+ 3 let novel = String::from(
+ "Call me Ishmael. Some years ago..."
+ );
+ 4 let first_sentence = novel
+ .split('.')
+ .next()
+ .expect("Could not find a '.'");
+ 5 let i = ImportantExcerpt {
part: first_sentence,
};
}
@@ -1749,25 +1656,25 @@ fn main() {
Listing 10-24: A struct that holds a reference, requiring a lifetime annotation
This struct has the single field `part` that holds a string slice, which is a
-reference. As with generic data types, we declare the name of the generic
+reference [2]. As with generic data types, we declare the name of the generic
lifetime parameter inside angle brackets after the name of the struct so we can
-use the lifetime parameter in the body of the struct definition. This
+use the lifetime parameter in the body of the struct definition [1]. This
annotation means an instance of `ImportantExcerpt` can’t outlive the reference
it holds in its `part` field.
The `main` function here creates an instance of the `ImportantExcerpt` struct
-that holds a reference to the first sentence of the `String` owned by the
-variable `novel`. The data in `novel` exists before the `ImportantExcerpt`
-instance is created. In addition, `novel` doesn’t go out of scope until after
-the `ImportantExcerpt` goes out of scope, so the reference in the
-`ImportantExcerpt` instance is valid.
+[5] that holds a reference to the first sentence of the `String` [4] owned by
+the variable `novel` [3]. The data in `novel` exists before the
+`ImportantExcerpt` instance is created. In addition, `novel` doesn’t go out of
+scope until after the `ImportantExcerpt` goes out of scope, so the reference in
+the `ImportantExcerpt` instance is valid.
### Lifetime Elision
You’ve learned that every reference has a lifetime and that you need to specify
-lifetime parameters for functions or structs that use references. However, in
-Chapter 4 we had a function in Listing 4-9, shown again in Listing 10-25, that
-compiled without lifetime annotations.
+lifetime parameters for functions or structs that use references. However, we
+had a function in Listing 4-9, shown again in Listing 10-25, that compiled
+without lifetime annotations.
Filename: src/lib.rs
@@ -1830,8 +1737,8 @@ which it can’t figure out lifetimes, the compiler will stop with an error.
These rules apply to `fn` definitions as well as `impl` blocks.
The first rule is that the compiler assigns a lifetime parameter to each
-parameter that’s a reference. In other words, a function with one parameter gets
-one lifetime parameter: `fn foo<'a>(x: &'a i32)`; a function with two
+parameter that’s a reference. In other words, a function with one parameter
+gets one lifetime parameter: `fn foo<'a>(x: &'a i32)`; a function with two
parameters gets two separate lifetime parameters: `fn foo<'a, 'b>(x: &'a i32,
y: &'b i32)`; and so on.
@@ -1907,7 +1814,7 @@ use the lifetime parameters depends on whether they’re related to the struct
fields or the method parameters and return values.
Lifetime names for struct fields always need to be declared after the `impl`
-keyword and then used after the struct’s name, because those lifetimes are part
+keyword and then used after the struct’s name because those lifetimes are part
of the struct’s type.
In method signatures inside the `impl` block, references might be tied to the
@@ -1916,7 +1823,7 @@ addition, the lifetime elision rules often make it so that lifetime annotations
aren’t necessary in method signatures. Let’s look at some examples using the
struct named `ImportantExcerpt` that we defined in Listing 10-24.
-First, we’ll use a method named `level` whose only parameter is a reference to
+First we’ll use a method named `level` whose only parameter is a reference to
`self` and whose return value is an `i32`, which is not a reference to anything:
```
@@ -1936,7 +1843,7 @@ Here is an example where the third lifetime elision rule applies:
```
impl<'a> ImportantExcerpt<'a> {
fn announce_and_return_part(&self, announcement: &str) -> &str {
- println!("Attention please: {}", announcement);
+ println!("Attention please: {announcement}");
self.part
}
}
@@ -1957,9 +1864,8 @@ string literals have the `'static` lifetime, which we can annotate as follows:
let s: &'static str = "I have a static lifetime.";
```
-The text of this string is stored directly in the program’s binary, which
-is always available. Therefore, the lifetime of all string literals is
-`'static`.
+The text of this string is stored directly in the program’s binary, which is
+always available. Therefore, the lifetime of all string literals is `'static`.
You might see suggestions to use the `'static` lifetime in error messages. But
before specifying `'static` as the lifetime for a reference, think about
@@ -1967,7 +1873,7 @@ whether the reference you have actually lives the entire lifetime of your
program or not, and whether you want it to. Most of the time, an error message
suggesting the `'static` lifetime results from attempting to create a dangling
reference or a mismatch of the available lifetimes. In such cases, the solution
-is fixing those problems, not specifying the `'static` lifetime.
+is to fix those problems, not to specify the `'static` lifetime.
## Generic Type Parameters, Trait Bounds, and Lifetimes Together
@@ -1985,7 +1891,7 @@ fn longest_with_an_announcement<'a, T>(
where
T: Display,
{
- println!("Announcement! {}", ann);
+ println!("Announcement! {ann}");
if x.len() > y.len() {
x
} else {
@@ -2021,3 +1927,4 @@ that you will only need in very advanced scenarios; for those, you should read
the Rust Reference at *https://doc.rust-lang.org/reference/trait-bounds.html*.
But next, you’ll learn how to write tests in Rust so you can make sure your
code is working the way it should.
+
diff --git a/src/doc/book/nostarch/chapter11.md b/src/doc/book/nostarch/chapter11.md
index ea4ffe5bf..cf909d70c 100644
--- a/src/doc/book/nostarch/chapter11.md
+++ b/src/doc/book/nostarch/chapter11.md
@@ -33,11 +33,12 @@ We can write tests that assert, for example, that when we pass `3` to the
we make changes to our code to make sure any existing correct behavior has not
changed.
-Testing is a complex skill: although we can’t cover every detail about how to
-write good tests in one chapter, we’ll discuss the mechanics of Rust’s testing
-facilities. We’ll talk about the annotations and macros available to you when
-writing your tests, the default behavior and options provided for running your
-tests, and how to organize tests into unit tests and integration tests.
+Testing is a complex skill: although we can’t cover in one chapter every detail
+about how to write good tests, in this chapter we will discuss the mechanics of
+Rust’s testing facilities. We’ll talk about the annotations and macros
+available to you when writing your tests, the default behavior and options
+provided for running your tests, and how to organize tests into unit tests and
+integration tests.
## How to Write Tests
@@ -45,9 +46,9 @@ Tests are Rust functions that verify that the non-test code is functioning in
the expected manner. The bodies of test functions typically perform these three
actions:
-1. Set up any needed data or state.
-2. Run the code you want to test.
-3. Assert the results are what you expect.
+* Set up any needed data or state.
+* Run the code you want to test.
+* Assert that the results are what you expect.
Let’s look at the features Rust provides specifically for writing tests that
take these actions, which include the `test` attribute, a few macros, and the
@@ -60,8 +61,8 @@ attribute. Attributes are metadata about pieces of Rust code; one example is
the `derive` attribute we used with structs in Chapter 5. To change a function
into a test function, add `#[test]` on the line before `fn`. When you run your
tests with the `cargo test` command, Rust builds a test runner binary that runs
-the annotated functions and reports on whether each
-test function passes or fails.
+the annotated functions and reports on whether each test function passes or
+fails.
Whenever we make a new library project with Cargo, a test module with a test
function in it is automatically generated for us. This module gives you a
@@ -89,10 +90,10 @@ Filename: src/lib.rs
```
#[cfg(test)]
mod tests {
-[1] #[test]
+ 1 #[test]
fn it_works() {
let result = 2 + 2;
- [2] assert_eq!(result, 4);
+ 2 assert_eq!(result, 4);
}
}
```
@@ -119,19 +120,21 @@ The `cargo test` command runs all tests in our project, as shown in Listing
$ cargo test
Compiling adder v0.1.0 (file:///projects/adder)
Finished test [unoptimized + debuginfo] target(s) in 0.57s
- Running unittests (target/debug/deps/adder-92948b65e88960b4)
+ Running unittests src/lib.rs (target/debug/deps/adder-
+92948b65e88960b4)
-[1] running 1 test
-[2] test tests::it_works ... ok
+1 running 1 test
+2 test tests::it_works ... ok
-[3] test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+3 test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
-[4] Doc-tests adder
+ 4 Doc-tests adder
running 0 tests
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
-
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
Listing 11-2: The output from running the automatically generated test
@@ -143,13 +146,12 @@ ok.` [3] means that all the tests passed, and the portion that reads `1 passed;
0 failed` totals the number of tests that passed or failed.
It’s possible to mark a test as ignored so it doesn’t run in a particular
-instance; we’ll cover that in the “Ignoring Some Tests Unless Specifically
-Requested†section later in this chapter. Because we haven’t done that here,
-the summary shows `0 ignored`. We can also pass an argument to the `cargo test`
-command to run only tests whose name matches a string; this is called *filtering*
-and we’ll cover that in the “Running a Subset of Tests by Name†section.
-Here we haven’t filtered the tests being run, so the end of the summary shows `0
-filtered out`.
+instance; we’ll cover that in “Ignoring Some Tests Unless Specifically
+Requested†on page XX. Because we haven’t done that here, the summary shows `0
+ignored`. We can also pass an argument to the `cargo test` command to run only
+tests whose name matches a string; this is called *filtering* and we’ll cover
+it in “Running a Subset of Tests by Name†on page XX. Here we haven’t filtered
+the tests being run, so the end of the summary shows `0 filtered out`.
The `0 measured` statistic is for benchmark tests that measure performance.
Benchmark tests are, as of this writing, only available in nightly Rust. See
@@ -161,10 +163,10 @@ The next part of the test output starting at `Doc-tests adder` [4] is for the
results of any documentation tests. We don’t have any documentation tests yet,
but Rust can compile any code examples that appear in our API documentation.
This feature helps keep your docs and your code in sync! We’ll discuss how to
-write documentation tests in the “Documentation Comments as Tests†section of
-Chapter 14. For now, we’ll ignore the `Doc-tests` output.
+write documentation tests in “Documentation Comments as Tests†on page XX. For
+now, we’ll ignore the `Doc-tests` output.
-Let’s start to customize the test to our own needs. First change the name of
+Let’s start to customize the test to our own needs. First, change the name of
the `it_works` function to a different name, such as `exploration`, like so:
Filename: src/lib.rs
@@ -174,7 +176,8 @@ Filename: src/lib.rs
mod tests {
#[test]
fn exploration() {
- assert_eq!(2 + 2, 4);
+ let result = 2 + 2;
+ assert_eq!(result, 4);
}
}
```
@@ -186,7 +189,8 @@ Then run `cargo test` again. The output now shows `exploration` instead of
running 1 test
test tests::exploration ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out;
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
Now we’ll add another test, but this time we’ll make a test that fails! Tests
@@ -222,18 +226,20 @@ Run the tests again using `cargo test`. The output should look like Listing
```
running 2 tests
test tests::exploration ... ok
-[1] test tests::another ... FAILED
+1 test tests::another ... FAILED
-[2] failures:
+2 failures:
---- tests::another stdout ----
thread 'main' panicked at 'Make this test fail', src/lib.rs:10:9
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+note: run with `RUST_BACKTRACE=1` environment variable to display
+a backtrace
-[3] failures:
+3 failures:
tests::another
-[4] test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+4 test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
error: test failed, to rerun pass '--lib'
```
@@ -248,7 +254,7 @@ line 10 in the *src/lib.rs* file. The next section [3] lists just the names of
all the failing tests, which is useful when there are lots of tests and lots of
detailed failing test output. We can use the name of a failing test to run just
that test to more easily debug it; we’ll talk more about ways to run tests in
-the “Controlling How Tests Are Run†section.
+“Controlling How Tests Are Run†on page XX.
The summary line displays at the end [4]: overall, our test result is `FAILED`.
We had one test pass and one test fail.
@@ -256,7 +262,7 @@ We had one test pass and one test fail.
Now that you’ve seen what the test results look like in different scenarios,
let’s look at some macros other than `panic!` that are useful in tests.
-### Checking Results with the `assert!` Macro
+### Checking Results with the assert! Macro
The `assert!` macro, provided by the standard library, is useful when you want
to ensure that some condition in a test evaluates to `true`. We give the
@@ -265,9 +271,9 @@ to ensure that some condition in a test evaluates to `true`. We give the
`assert!` macro calls `panic!` to cause the test to fail. Using the `assert!`
macro helps us check that our code is functioning in the way we intend.
-In Chapter 5, Listing 5-15, we used a `Rectangle` struct and a `can_hold`
-method, which are repeated here in Listing 11-5. Let’s put this code in the
-*src/lib.rs* file, then write some tests for it using the `assert!` macro.
+In Listing 5-15, we used a `Rectangle` struct and a `can_hold` method, which
+are repeated here in Listing 11-5. Let’s put this code in the *src/lib.rs*
+file, then write some tests for it using the `assert!` macro.
Filename: src/lib.rs
@@ -299,11 +305,11 @@ Filename: src/lib.rs
```
#[cfg(test)]
mod tests {
-[1] use super::*;
+ 1 use super::*;
#[test]
-[2] fn larger_can_hold_smaller() {
- [3] let larger = Rectangle {
+ 2 fn larger_can_hold_smaller() {
+ 3 let larger = Rectangle {
width: 8,
height: 7,
};
@@ -312,7 +318,7 @@ mod tests {
height: 1,
};
- [4] assert!(larger.can_hold(&smaller));
+ 4 assert!(larger.can_hold(&smaller));
}
}
```
@@ -322,11 +328,11 @@ indeed hold a smaller rectangle
Note that we’ve added a new line inside the `tests` module: `use super::*;`
[1]. The `tests` module is a regular module that follows the usual visibility
-rules we covered in Chapter 7 in the “Paths for Referring to an Item in the
-Module Tree†section. Because the `tests` module is an inner module, we need to
-bring the code under test in the outer module into the scope of the inner
-module. We use a glob here so anything we define in the outer module is
-available to this `tests` module.
+rules we covered in “Paths for Referring to an Item in the Module Tree†on page
+XX. Because the `tests` module is an inner module, we need to bring the code
+under test in the outer module into the scope of the inner module. We use a
+glob here, so anything we define in the outer module is available to this
+`tests` module.
We’ve named our test `larger_can_hold_smaller` [2], and we’ve created the two
`Rectangle` instances that we need [3]. Then we called the `assert!` macro and
@@ -338,7 +344,8 @@ out!
running 1 test
test tests::larger_can_hold_smaller ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
It does pass! Let’s add another test, this time asserting that a smaller
@@ -353,7 +360,7 @@ mod tests {
#[test]
fn larger_can_hold_smaller() {
- // --snip--
+ --snip--
}
#[test]
@@ -381,7 +388,8 @@ running 2 tests
test tests::larger_can_hold_smaller ... ok
test tests::smaller_cannot_hold_larger ... ok
-test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
Two tests that pass! Now let’s see what happens to our test results when we
@@ -390,7 +398,8 @@ method by replacing the greater-than sign with a less-than sign when it
compares the widths:
```
-// --snip--
+--snip--
+
impl Rectangle {
fn can_hold(&self, other: &Rectangle) -> bool {
self.width < other.width && self.height > other.height
@@ -408,26 +417,29 @@ test tests::larger_can_hold_smaller ... FAILED
failures:
---- tests::larger_can_hold_smaller stdout ----
-thread 'main' panicked at 'assertion failed: larger.can_hold(&smaller)', src/lib.rs:28:9
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+thread 'main' panicked at 'assertion failed:
+larger.can_hold(&smaller)', src/lib.rs:28:9
+note: run with `RUST_BACKTRACE=1` environment variable to display
+a backtrace
failures:
tests::larger_can_hold_smaller
-test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
-Our tests caught the bug! Because `larger.width` is 8 and `smaller.width` is
-5, the comparison of the widths in `can_hold` now returns `false`: 8 is not
+Our tests caught the bug! Because `larger.width` is `8` and `smaller.width` is
+`5`, the comparison of the widths in `can_hold` now returns `false`: 8 is not
less than 5.
-### Testing Equality with the `assert_eq!` and `assert_ne!` Macros
+### Testing Equality with the assert_eq! and assert_ne! Macros
A common way to verify functionality is to test for equality between the result
of the code under test and the value you expect the code to return. You could
-do this using the `assert!` macro and passing it an expression using the `==`
-operator. However, this is such a common test that the standard library
+do this by using the `assert!` macro and passing it an expression using the
+`==` operator. However, this is such a common test that the standard library
provides a pair of macros—`assert_eq!` and `assert_ne!`—to perform this test
more conveniently. These macros compare two arguments for equality or
inequality, respectively. They’ll also print the two values if the assertion
@@ -464,7 +476,8 @@ Let’s check that it passes!
running 1 test
test tests::it_adds_two ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
We pass `4` as the argument to `assert_eq!`, which is equal to the result of
@@ -489,23 +502,25 @@ test tests::it_adds_two ... FAILED
failures:
---- tests::it_adds_two stdout ----
-[1] thread 'main' panicked at 'assertion failed: `(left == right)`
-[2] left: `4`,
-[3] right: `5`', src/lib.rs:11:9
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+1 thread 'main' panicked at 'assertion failed: `(left == right)`
+2 left: `4`,
+3 right: `5`', src/lib.rs:11:9
+note: run with `RUST_BACKTRACE=1` environment variable to display
+a backtrace
failures:
tests::it_adds_two
-test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
Our test caught the bug! The `it_adds_two` test failed, and the message tells
-us that the assertion that fails was `` assertion failed: `(left == right)` ``
-[1] and what the `left` [2] and `right` [3] values are. This message helps us
-start debugging: the `left` argument was `4` but the `right` argument, where we
-had `add_two(2)`, was `5`. You can imagine that this would be especially
-helpful when we have a lot of tests going on.
+us that the assertion that failed was `assertion failed: `(left == right)`` [1]
+and what the `left` [2] and `right` [3] values are. This message helps us start
+debugging: the `left` argument was `4` but the `right` argument, where we had
+`add_two(2)`, was `5`. You can imagine that this would be especially helpful
+when we have a lot of tests going on.
Note that in some languages and test frameworks, the parameters to equality
assertion functions are called `expected` and `actual`, and the order in which
@@ -513,7 +528,7 @@ we specify the arguments matters. However, in Rust, they’re called `left` and
`right`, and the order in which we specify the value we expect and the value
the code produces doesn’t matter. We could write the assertion in this test as
`assert_eq!(add_two(2), 4)`, which would result in the same failure message
-that displays `` assertion failed: `(left == right)` ``.
+that displays `assertion failed: `(left == right)``.
The `assert_ne!` macro will pass if the two values we give it are not equal and
fail if they’re equal. This macro is most useful for cases when we’re not sure
@@ -531,21 +546,20 @@ the standard library types implement these traits. For structs and enums that
you define yourself, you’ll need to implement `PartialEq` to assert equality of
those types. You’ll also need to implement `Debug` to print the values when the
assertion fails. Because both traits are derivable traits, as mentioned in
-Listing 5-12 in Chapter 5, this is usually as straightforward as adding the
+Listing 5-12, this is usually as straightforward as adding the
`#[derive(PartialEq, Debug)]` annotation to your struct or enum definition. See
-Appendix C, “Derivable Traits,†for more details about these and other
-derivable traits.
+Appendix C for more details about these and other derivable traits.
### Adding Custom Failure Messages
You can also add a custom message to be printed with the failure message as
optional arguments to the `assert!`, `assert_eq!`, and `assert_ne!` macros. Any
arguments specified after the required arguments are passed along to the
-`format!` macro (discussed in Chapter 8 in the “Concatenation with the `+`
-Operator or the `format!` Macro†section), so you can pass a format string that
-contains `{}` placeholders and values to go in those placeholders. Custom
-messages are useful for documenting what an assertion means; when a test fails,
-you’ll have a better idea of what the problem is with the code.
+`format!` macro (discussed in “Concatenation with the + Operator or the format!
+Macro†on page XX), so you can pass a format string that contains `{}`
+placeholders and values to go in those placeholders. Custom messages are useful
+for documenting what an assertion means; when a test fails, you’ll have a
+better idea of what the problem is with the code.
For example, let’s say we have a function that greets people by name and we
want to test that the name we pass into the function appears in the output:
@@ -554,7 +568,7 @@ Filename: src/lib.rs
```
pub fn greeting(name: &str) -> String {
- format!("Hello {}!", name)
+ format!("Hello {name}!")
}
#[cfg(test)]
@@ -594,8 +608,10 @@ test tests::greeting_contains_name ... FAILED
failures:
---- tests::greeting_contains_name stdout ----
-thread 'main' panicked at 'assertion failed: result.contains(\"Carol\")', src/lib.rs:12:9
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+thread 'main' panicked at 'assertion failed:
+result.contains(\"Carol\")', src/lib.rs:12:9
+note: run with `RUST_BACKTRACE=1` environment variable to display
+a backtrace
failures:
@@ -614,8 +630,7 @@ fn greeting_contains_name() {
let result = greeting("Carol");
assert!(
result.contains("Carol"),
- "Greeting did not contain name, value was `{}`",
- result
+ "Greeting did not contain name, value was `{result}`"
);
}
```
@@ -624,21 +639,23 @@ Now when we run the test, we’ll get a more informative error message:
```
---- tests::greeting_contains_name stdout ----
-thread 'main' panicked at 'Greeting did not contain name, value was `Hello!`', src/lib.rs:12:9
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+thread 'main' panicked at 'Greeting did not contain name, value
+was `Hello!`', src/lib.rs:12:9
+note: run with `RUST_BACKTRACE=1` environment variable to display
+a backtrace
```
We can see the value we actually got in the test output, which would help us
debug what happened instead of what we were expecting to happen.
-### Checking for Panics with `should_panic`
+### Checking for Panics with should_panic
In addition to checking return values, it’s important to check that our code
handles error conditions as we expect. For example, consider the `Guess` type
-that we created in Chapter 9, Listing 9-13. Other code that uses `Guess`
-depends on the guarantee that `Guess` instances will contain only values
-between 1 and 100. We can write a test that ensures that attempting to create a
-`Guess` instance with a value outside that range panics.
+that we created in Listing 9-13. Other code that uses `Guess` depends on the
+guarantee that `Guess` instances will contain only values between 1 and 100. We
+can write a test that ensures that attempting to create a `Guess` instance with
+a value outside that range panics.
We do this by adding the attribute `should_panic` to our test function. The
test passes if the code inside the function panics; the test fails if the code
@@ -647,9 +664,8 @@ inside the function doesn’t panic.
Listing 11-8 shows a test that checks that the error conditions of `Guess::new`
happen when we expect them to.
-Filename: src/lib.rs
-
```
+// src/lib.rs
pub struct Guess {
value: i32,
}
@@ -657,7 +673,10 @@ pub struct Guess {
impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 || value > 100 {
- panic!("Guess value must be between 1 and 100, got {}.", value);
+ panic!(
+ "Guess value must be between 1 and 100, got {}.",
+ value
+ );
}
Guess { value }
@@ -676,7 +695,7 @@ mod tests {
}
```
-Listing 11-8: Testing that a condition will cause a `panic!`
+Listing 11-8: Testing that a condition will cause a panic!
We place the `#[should_panic]` attribute after the `#[test]` attribute and
before the test function it applies to. Let’s look at the result when this test
@@ -686,18 +705,24 @@ passes:
running 1 test
test tests::greater_than_100 - should panic ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
Looks good! Now let’s introduce a bug in our code by removing the condition
that the `new` function will panic if the value is greater than 100:
```
-// --snip--
+// src/lib.rs
+--snip--
+
impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 {
- panic!("Guess value must be between 1 and 100, got {}.", value);
+ panic!(
+ "Guess value must be between 1 and 100, got {}.",
+ value
+ );
}
Guess { value }
@@ -719,7 +744,8 @@ note: test did not panic as expected
failures:
tests::greater_than_100
-test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
We don’t get a very helpful message in this case, but when we look at the test
@@ -735,10 +761,9 @@ consider the modified code for `Guess` in Listing 11-9 where the `new` function
panics with different messages depending on whether the value is too small or
too large.
-Filename: src/lib.rs
-
```
-// --snip--
+// src/lib.rs
+--snip--
impl Guess {
pub fn new(value: i32) -> Guess {
@@ -777,32 +802,30 @@ This test will pass because the value we put in the `should_panic` attribute’s
`expected` parameter is a substring of the message that the `Guess::new`
function panics with. We could have specified the entire panic message that we
expect, which in this case would be `Guess value must be less than or equal to
-100, got 200.` What you choose to specify depends on how much of the panic
+100, got 200`. What you choose to specify depends on how much of the panic
message is unique or dynamic and how precise you want your test to be. In this
case, a substring of the panic message is enough to ensure that the code in the
test function executes the `else if value > 100` case.
-<!---
-We may want to make extra clear above that `expected` here means substring. I
-think many people would assume equality rather than substring like the
-expected/actual of unit tests.
-
-(let alone how .expect(..) works. It seems we use the word expect in different
-ways around the language/library )
-/JT --->
-<!-- I've changed the example to be more clearly a substring specified, and
-changed the caption as well. Hope that makes it extra clear! /Carol -->
-
To see what happens when a `should_panic` test with an `expected` message
fails, let’s again introduce a bug into our code by swapping the bodies of the
`if value < 1` and the `else if value > 100` blocks:
```
+// src/lib.rs
+--snip--
if value < 1 {
- panic!("Guess value must be less than or equal to 100, got {}.", value);
+ panic!(
+ "Guess value must be less than or equal to 100, got {}.",
+ value
+ );
} else if value > 100 {
- panic!("Guess value must be greater than or equal to 1, got {}.", value);
+ panic!(
+ "Guess value must be greater than or equal to 1, got {}.",
+ value
+ );
}
+--snip--
```
This time when we run the `should_panic` test, it will fail:
@@ -814,30 +837,35 @@ test tests::greater_than_100 - should panic ... FAILED
failures:
---- tests::greater_than_100 stdout ----
-thread 'main' panicked at 'Guess value must be greater than or equal to 1, got 200.', src/lib.rs:13:13
+thread 'main' panicked at 'Guess value must be greater than or equal to 1, got
+200.', src/lib.rs:13:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: panic did not contain expected string
- panic message: `"Guess value must be greater than or equal to 1, got 200."`,
+ panic message: `"Guess value must be greater than or equal to 1, got
+200."`,
expected substring: `"less than or equal to 100"`
failures:
tests::greater_than_100
-test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out;
+finished in 0.00s
```
The failure message indicates that this test did indeed panic as we expected,
but the panic message did not include the expected string `'Guess value must be
less than or equal to 100'`. The panic message that we did get in this case was
-`Guess value must be greater than or equal to 1, got 200.` Now we can start
+`Guess value must be greater than or equal to 1, got 200`. Now we can start
figuring out where our bug is!
-### Using `Result<T, E>` in Tests
+### Using Result<T, E> in Tests
Our tests so far all panic when they fail. We can also write tests that use
`Result<T, E>`! Here’s the test from Listing 11-1, rewritten to use `Result<T,
E>` and return an `Err` instead of panicking:
+Filename: src/lib.rs
+
```
#[cfg(test)]
mod tests {
@@ -872,15 +900,15 @@ test`.
## Controlling How Tests Are Run
-Just as `cargo run` compiles your code and then runs the resulting binary,
-`cargo test` compiles your code in test mode and runs the resulting test
+Just as `cargo run` compiles your code and then runs the resultant binary,
+`cargo test` compiles your code in test mode and runs the resultant test
binary. The default behavior of the binary produced by `cargo test` is to run
all the tests in parallel and capture output generated during test runs,
preventing the output from being displayed and making it easier to read the
output related to the test results. You can, however, specify command line
options to change this default behavior.
-Some command line options go to `cargo test`, and some go to the resulting test
+Some command line options go to `cargo test`, and some go to the resultant test
binary. To separate these two types of arguments, you list the arguments that
go to `cargo test` followed by the separator `--` and then the ones that go to
the test binary. Running `cargo test --help` displays the options you can use
@@ -934,7 +962,7 @@ Filename: src/lib.rs
```
fn prints_and_returns_10(a: i32) -> i32 {
- println!("I got the value {}", a);
+ println!("I got the value {a}");
10
}
@@ -968,16 +996,18 @@ test tests::this_test_will_fail ... FAILED
failures:
---- tests::this_test_will_fail stdout ----
-[1] I got the value 8
+1 I got the value 8
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `5`,
right: `10`', src/lib.rs:19:9
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+note: run with `RUST_BACKTRACE=1` environment variable to display
+a backtrace
failures:
tests::this_test_will_fail
-test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
Note that nowhere in this output do we see `I got the value 4`, which is
@@ -986,8 +1016,8 @@ output from the test that failed, `I got the value 8` [1], appears in the
section of the test summary output, which also shows the cause of the test
failure.
-If we want to see printed values for passing tests as well, we can tell Rust
-to also show the output of successful tests with `--show-output`.
+If we want to see printed values for passing tests as well, we can tell Rust to
+also show the output of successful tests with `--show-output`:
```
$ cargo test -- --show-output
@@ -1017,12 +1047,14 @@ I got the value 8
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `5`,
right: `10`', src/lib.rs:19:9
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+note: run with `RUST_BACKTRACE=1` environment variable to display
+a backtrace
failures:
tests::this_test_will_fail
-test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
### Running a Subset of Tests by Name
@@ -1074,7 +1106,8 @@ test tests::add_three_and_two ... ok
test tests::add_two_and_two ... ok
test tests::one_hundred ... ok
-test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
#### Running Single Tests
@@ -1085,12 +1118,14 @@ We can pass the name of any test function to `cargo test` to run only that test:
$ cargo test one_hundred
Compiling adder v0.1.0 (file:///projects/adder)
Finished test [unoptimized + debuginfo] target(s) in 0.69s
- Running unittests (target/debug/deps/adder-92948b65e88960b4)
+ Running unittests src/lib.rs (target/debug/deps/adder-
+92948b65e88960b4)
running 1 test
test tests::one_hundred ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out; finished in 0.00s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2
+filtered out; finished in 0.00s
```
Only the test with the name `one_hundred` ran; the other two tests didn’t match
@@ -1110,13 +1145,15 @@ run those two by running `cargo test add`:
$ cargo test add
Compiling adder v0.1.0 (file:///projects/adder)
Finished test [unoptimized + debuginfo] target(s) in 0.61s
- Running unittests (target/debug/deps/adder-92948b65e88960b4)
+ Running unittests src/lib.rs (target/debug/deps/adder-
+92948b65e88960b4)
running 2 tests
test tests::add_three_and_two ... ok
test tests::add_two_and_two ... ok
-test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s
+test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 1
+filtered out; finished in 0.00s
```
This command ran all tests with `add` in the name and filtered out the test
@@ -1137,7 +1174,8 @@ Filename: src/lib.rs
```
#[test]
fn it_works() {
- assert_eq!(2 + 2, 4);
+ let result = 2 + 2;
+ assert_eq!(result, 4);
}
#[test]
@@ -1147,20 +1185,22 @@ fn expensive_test() {
}
```
-After `#[test]` we add the `#[ignore]` line to the test we want to exclude. Now
-when we run our tests, `it_works` runs, but `expensive_test` doesn’t:
+After `#[test]`, we add the `#[ignore]` line to the test we want to exclude.
+Now when we run our tests, `it_works` runs, but `expensive_test` doesn’t:
```
$ cargo test
Compiling adder v0.1.0 (file:///projects/adder)
Finished test [unoptimized + debuginfo] target(s) in 0.60s
- Running unittests (target/debug/deps/adder-92948b65e88960b4)
+ Running unittests src/lib.rs (target/debug/deps/adder-
+92948b65e88960b4)
running 2 tests
test expensive_test ... ignored
test it_works ... ok
-test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
The `expensive_test` function is listed as `ignored`. If we want to run only
@@ -1169,19 +1209,21 @@ the ignored tests, we can use `cargo test -- --ignored`:
```
$ cargo test -- --ignored
Finished test [unoptimized + debuginfo] target(s) in 0.61s
- Running unittests (target/debug/deps/adder-92948b65e88960b4)
+ Running unittests src/lib.rs (target/debug/deps/adder-
+92948b65e88960b4)
running 1 test
test expensive_test ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1
+filtered out; finished in 0.00s
```
By controlling which tests run, you can make sure your `cargo test` results
-will be fast. When you’re at a point where it makes sense to check the results
-of the `ignored` tests and you have time to wait for the results, you can run
-`cargo test -- --ignored` instead. If you want to run all tests whether they’re
-ignored or not, you can run `cargo test -- --include-ignored`.
+will be returned quickly. When you’re at a point where it makes sense to check
+the results of the `ignored` tests and you have time to wait for the results,
+you can run `cargo test -- --ignored` instead. If you want to run all tests
+whether they’re ignored or not, you can run `cargo test -- --include-ignored`.
## Test Organization
@@ -1206,16 +1248,16 @@ code that they’re testing. The convention is to create a module named `tests`
in each file to contain the test functions and to annotate the module with
`cfg(test)`.
-#### The Tests Module and `#[cfg(test)]`
+#### The Tests Module and #[cfg(test)]
-The `#[cfg(test)]` annotation on the tests module tells Rust to compile and run
-the test code only when you run `cargo test`, not when you run `cargo build`.
-This saves compile time when you only want to build the library and saves space
-in the resulting compiled artifact because the tests are not included. You’ll
-see that because integration tests go in a different directory, they don’t need
-the `#[cfg(test)]` annotation. However, because unit tests go in the same files
-as the code, you’ll use `#[cfg(test)]` to specify that they shouldn’t be
-included in the compiled result.
+The `#[cfg(test)]` annotation on the `tests` module tells Rust to compile and
+run the test code only when you run `cargo test`, not when you run `cargo
+build`. This saves compile time when you only want to build the library and
+saves space in the resultant compiled artifact because the tests are not
+included. You’ll see that because integration tests go in a different
+directory, they don’t need the `#[cfg(test)]` annotation. However, because unit
+tests go in the same files as the code, you’ll use `#[cfg(test)]` to specify
+that they shouldn’t be included in the compiled result.
Recall that when we generated the new `adder` project in the first section of
this chapter, Cargo generated this code for us:
@@ -1227,12 +1269,13 @@ Filename: src/lib.rs
mod tests {
#[test]
fn it_works() {
- assert_eq!(2 + 2, 4);
+ let result = 2 + 2;
+ assert_eq!(result, 4);
}
}
```
-This code is the automatically generated test module. The attribute `cfg`
+This code is the automatically generated `tests` module. The attribute `cfg`
stands for *configuration* and tells Rust that the following item should only
be included given a certain configuration option. In this case, the
configuration option is `test`, which is provided by Rust for compiling and
@@ -1275,7 +1318,7 @@ Listing 11-12: Testing a private function
Note that the `internal_adder` function is not marked as `pub`. Tests are just
Rust code, and the `tests` module is just another module. As we discussed in
-the “Paths for Referring to an Item in the Module Tree†section, items in child
+“Paths for Referring to an Item in the Module Tree†on page XX, items in child
modules can use the items in their ancestor modules. In this test, we bring all
of the `test` module’s parent’s items into scope with `use super::*`, and then
the test can call `internal_adder`. If you don’t think private functions should
@@ -1291,7 +1334,7 @@ work correctly on their own could have problems when integrated, so test
coverage of the integrated code is important as well. To create integration
tests, you first need a *tests* directory.
-#### The *tests* Directory
+#### The tests Directory
We create a *tests* directory at the top level of our project directory, next
to *src*. Cargo knows to look for integration test files in this directory. We
@@ -1307,12 +1350,12 @@ adder
├── Cargo.lock
├── Cargo.toml
├── src
-│   └── lib.rs
+│ └── lib.rs
└── tests
└── integration_test.rs
```
-Enter the code in Listing 11-13 into the *tests/integration_test.rs* file:
+Enter the code in Listing 11-13 into the *tests/integration_test.rs* file.
Filename: tests/integration_test.rs
@@ -1327,37 +1370,42 @@ fn it_adds_two() {
Listing 11-13: An integration test of a function in the `adder` crate
-Each file in the `tests` directory is a separate crate, so we need to bring our
-library into each test crate’s scope. For that reason we add `use adder` at the
-top of the code, which we didn’t need in the unit tests.
+Each file in the *tests* directory is a separate crate, so we need to bring our
+library into each test crate’s scope. For that reason we add `use adder;` at
+the top of the code, which we didn’t need in the unit tests.
We don’t need to annotate any code in *tests/integration_test.rs* with
-`#[cfg(test)]`. Cargo treats the `tests` directory specially and compiles files
+`#[cfg(test)]`. Cargo treats the *tests* directory specially and compiles files
in this directory only when we run `cargo test`. Run `cargo test` now:
```
$ cargo test
Compiling adder v0.1.0 (file:///projects/adder)
Finished test [unoptimized + debuginfo] target(s) in 1.31s
- Running unittests (target/debug/deps/adder-1082c4b063a8fbe6)
+ Running unittests src/lib.rs (target/debug/deps/adder-
+1082c4b063a8fbe6)
-[1] running 1 test
+1 running 1 test
test tests::internal ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
- [2] Running tests/integration_test.rs (target/debug/deps/integration_test-1082c4b063a8fbe6)
+ 2 Running tests/integration_test.rs
+(target/debug/deps/integration_test-1082c4b063a8fbe6)
running 1 test
-[3] test it_adds_two ... ok
+3 test it_adds_two ... ok
-[4] test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+4 test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
Doc-tests adder
running 0 tests
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
The three sections of output include the unit tests, the integration test, and
@@ -1386,12 +1434,14 @@ followed by the name of the file:
```
$ cargo test --test integration_test
Finished test [unoptimized + debuginfo] target(s) in 0.64s
- Running tests/integration_test.rs (target/debug/deps/integration_test-82e7799c1bc62298)
+ Running tests/integration_test.rs
+(target/debug/deps/integration_test-82e7799c1bc62298)
running 1 test
test it_adds_two ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
This command runs only the tests in the *tests/integration_test.rs* file.
@@ -1409,11 +1459,11 @@ regarding how to separate code into modules and files.
The different behavior of *tests* directory files is most noticeable when you
have a set of helper functions to use in multiple integration test files and
-you try to follow the steps in the “Separating Modules into Different Filesâ€
-section of Chapter 7 to extract them into a common module. For example, if we
-create *tests/common.rs* and place a function named `setup` in it, we can add
-some code to `setup` that we want to call from multiple test functions in
-multiple test files:
+you try to follow the steps in “Separating Modules into Different Files†on
+page XX to extract them into a common module. For example, if we create
+*tests/common.rs* and place a function named `setup` in it, we can add some
+code to `setup` that we want to call from multiple test functions in multiple
+test files:
Filename: tests/common.rs
@@ -1431,53 +1481,58 @@ did we call the `setup` function from anywhere:
running 1 test
test tests::internal ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
- Running tests/common.rs (target/debug/deps/common-92948b65e88960b4)
+ Running tests/common.rs (target/debug/deps/common-
+92948b65e88960b4)
running 0 tests
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
- Running tests/integration_test.rs (target/debug/deps/integration_test-92948b65e88960b4)
+ Running tests/integration_test.rs
+(target/debug/deps/integration_test-92948b65e88960b4)
running 1 test
test it_adds_two ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
Doc-tests adder
running 0 tests
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
Having `common` appear in the test results with `running 0 tests` displayed for
it is not what we wanted. We just wanted to share some code with the other
-integration test files.
-To avoid having `common` appear in the test output, instead of creating
-*tests/common.rs*, we’ll create *tests/common/mod.rs*. The project directory
-now looks like this:
+integration test files. To avoid having `common` appear in the test output,
+instead of creating *tests/common.rs*, we’ll create *tests/common/mod.rs*. The
+project directory now looks like this:
```
├── Cargo.lock
├── Cargo.toml
├── src
-│   └── lib.rs
+│ └── lib.rs
└── tests
├── common
- │   └── mod.rs
+ │ └── mod.rs
└── integration_test.rs
```
This is the older naming convention that Rust also understands that we
-mentioned in the “Alternate File Paths†section of Chapter 7. Naming the file
-this way tells Rust not to treat the `common` module as an integration test
-file. When we move the `setup` function code into *tests/common/mod.rs* and
-delete the *tests/common.rs* file, the section in the test output will no
-longer appear. Files in subdirectories of the *tests* directory don’t get
-compiled as separate crates or have sections in the test output.
+mentioned in “Alternate File Paths†on page XX. Naming the file this way tells
+Rust not to treat the `common` module as an integration test file. When we move
+the `setup` function code into *tests/common/mod.rs* and delete the
+*tests/common.rs* file, the section in the test output will no longer appear.
+Files in subdirectories of the *tests* directory don’t get compiled as separate
+crates or have sections in the test output.
After we’ve created *tests/common/mod.rs*, we can use it from any of the
integration test files as a module. Here’s an example of calling the `setup`
@@ -1498,7 +1553,7 @@ fn it_adds_two() {
```
Note that the `mod common;` declaration is the same as the module declaration
-we demonstrated in Listing 7-21. Then in the test function, we can call the
+we demonstrated in Listing 7-21. Then, in the test function, we can call the
`common::setup()` function.
#### Integration Tests for Binary Crates
@@ -1512,10 +1567,9 @@ crates can use; binary crates are meant to be run on their own.
This is one of the reasons Rust projects that provide a binary have a
straightforward *src/main.rs* file that calls logic that lives in the
*src/lib.rs* file. Using that structure, integration tests *can* test the
-library crate with `use` to make the important functionality available.
-If the important functionality works, the small amount of code in the
-*src/main.rs* file will work as well, and that small amount of code doesn’t
-need to be tested.
+library crate with `use` to make the important functionality available. If the
+important functionality works, the small amount of code in the *src/main.rs*
+file will work as well, and that small amount of code doesn’t need to be tested.
## Summary
@@ -1531,11 +1585,3 @@ reduce logic bugs having to do with how your code is expected to behave.
Let’s combine the knowledge you learned in this chapter and in previous
chapters to work on a project!
-<!---
-We hint at doc tests but don't cover them. Should we have a section in this
-chapter about that? They're pretty handy.
-/JT --->
-<!-- We cover that in chapter 14, and there's a forward reference to that in
-"The Anatomy of a Test Function" section. I don't actually think most Rust
-developers will write doc tests; they're the most useful when writing open
-source libraries, which I think only a minority of developers do. /Carol -->
diff --git a/src/doc/book/nostarch/chapter12.md b/src/doc/book/nostarch/chapter12.md
index 950b2e999..86e986173 100644
--- a/src/doc/book/nostarch/chapter12.md
+++ b/src/doc/book/nostarch/chapter12.md
@@ -26,8 +26,8 @@ Along the way, we’ll show how to make our command line tool use the terminal
features that many other command line tools use. We’ll read the value of an
environment variable to allow the user to configure the behavior of our tool.
We’ll also print error messages to the standard error console stream (`stderr`)
-instead of standard output (`stdout`), so, for example, the user can redirect
-successful output to a file while still seeing error messages onscreen.
+instead of standard output (`stdout`) so that, for example, the user can
+redirect successful output to a file while still seeing error messages onscreen.
One Rust community member, Andrew Gallant, has already created a fully
featured, very fast version of `grep`, called `ripgrep`. By comparison, our
@@ -37,14 +37,14 @@ background knowledge you need to understand a real-world project such as
Our `grep` project will combine a number of concepts you’ve learned so far:
-* Organizing code (using what you learned about modules in Chapter 7)
-* Using vectors and strings (collections, Chapter 8)
+* Organizing code (Chapter 7)
+* Using vectors and strings (Chapter 8)
* Handling errors (Chapter 9)
* Using traits and lifetimes where appropriate (Chapter 10)
* Writing tests (Chapter 11)
We’ll also briefly introduce closures, iterators, and trait objects, which
-Chapters 13 and 17 will cover in detail.
+Chapter 13 and Chapter 17 will cover in detail.
## Accepting Command Line Arguments
@@ -69,8 +69,8 @@ $ cargo run -- searchstring example-filename.txt
```
Right now, the program generated by `cargo new` cannot process arguments we
-give it. Some existing libraries on *https://crates.io/* can help with writing
-a program that accepts command line arguments, but because you’re just learning
+give it. Some existing libraries on *https://crates.io* can help with writing a
+program that accepts command line arguments, but because you’re just learning
this concept, let’s implement this capability ourselves.
### Reading the Argument Values
@@ -85,7 +85,7 @@ collection, such as a vector, that contains all the elements the iterator
produces.
The code in Listing 12-1 allows your `minigrep` program to read any command
-line arguments passed to it and then collect the values into a vector.
+line arguments passed to it, and then collect the values into a vector.
Filename: src/main.rs
@@ -101,7 +101,7 @@ fn main() {
Listing 12-1: Collecting the command line arguments into a vector and printing
them
-First, we bring the `std::env` module into scope with a `use` statement so we
+First we bring the `std::env` module into scope with a `use` statement so we
can use its `args` function. Notice that the `std::env::args` function is
nested in two levels of modules. As we discussed in Chapter 7, in cases where
the desired function is nested in more than one module, we’ve chosen to bring
@@ -111,20 +111,20 @@ adding `use std::env::args` and then calling the function with just `args`,
because `args` might easily be mistaken for a function that’s defined in the
current module.
-> ### The `args` Function and Invalid Unicode
+> ### The args Function and Invalid Unicode
>
> Note that `std::env::args` will panic if any argument contains invalid
-> Unicode. If your program needs to accept arguments containing invalid
-> Unicode, use `std::env::args_os` instead. That function returns an iterator
-> that produces `OsString` values instead of `String` values. We’ve chosen to
-> use `std::env::args` here for simplicity, because `OsString` values differ
-> per platform and are more complex to work with than `String` values.
+Unicode. If your program needs to accept arguments containing invalid Unicode,
+use `std::env::args_os` instead. That function returns an iterator that
+produces `OsString` values instead of `String` values. We’ve chosen to use
+`std::env::args` here for simplicity because `OsString` values differ per
+platform and are more complex to work with than `String` values.
On the first line of `main`, we call `env::args`, and we immediately use
`collect` to turn the iterator into a vector containing all the values produced
by the iterator. We can use the `collect` function to create many kinds of
collections, so we explicitly annotate the type of `args` to specify that we
-want a vector of strings. Although we very rarely need to annotate types in
+want a vector of strings. Although you very rarely need to annotate types in
Rust, `collect` is one function you do often need to annotate because Rust
isn’t able to infer the kind of collection you want.
@@ -137,9 +137,6 @@ $ cargo run
[src/main.rs:5] args = [
"target/debug/minigrep",
]
-```
-
-```
$ cargo run -- needle haystack
--snip--
[src/main.rs:5] args = [
@@ -153,8 +150,8 @@ Notice that the first value in the vector is `"target/debug/minigrep"`, which
is the name of our binary. This matches the behavior of the arguments list in
C, letting programs use the name by which they were invoked in their execution.
It’s often convenient to have access to the program name in case you want to
-print it in messages or change behavior of the program based on what command
-line alias was used to invoke the program. But for the purposes of this
+print it in messages or change the behavior of the program based on what
+command line alias was used to invoke the program. But for the purposes of this
chapter, we’ll ignore it and save only the two arguments we need.
### Saving the Argument Values in Variables
@@ -184,7 +181,7 @@ Listing 12-2: Creating variables to hold the query argument and file path
argument
As we saw when we printed the vector, the program’s name takes up the first
-value in the vector at `args[0]`, so we’re starting arguments at index `1`. The
+value in the vector at `args[0]`, so we’re starting arguments at index 1. The
first argument `minigrep` takes is the string we’re searching for, so we put a
reference to the first argument in the variable `query`. The second argument
will be the file path, so we put a reference to the second argument in the
@@ -212,7 +209,7 @@ capabilities instead.
## Reading a File
Now we’ll add functionality to read the file specified in the `file_path`
-argument. First, we need a sample file to test it with: we’ll use a file with a
+argument. First we need a sample file to test it with: we’ll use a file with a
small amount of text over multiple lines with some repeated words. Listing 12-3
has an Emily Dickinson poem that will work well! Create a file called
*poem.txt* at the root level of your project, and enter the poem “I’m Nobody!
@@ -232,7 +229,7 @@ To tell your name the livelong day
To an admiring bog!
```
-Listing 12-3: A poem by Emily Dickinson makes a good test case
+Listing 12-3: A poem by Emily Dickinson makes a good test case.
With the text in place, edit *src/main.rs* and add code to read the file, as
shown in Listing 12-4.
@@ -241,26 +238,26 @@ Filename: src/main.rs
```
use std::env;
-[1] use std::fs;
+1 use std::fs;
fn main() {
- // --snip--
+ --snip--
println!("In file {}", file_path);
- [2] let contents = fs::read_to_string(file_path)
+ 2 let contents = fs::read_to_string(file_path)
.expect("Should have been able to read the file");
- [3] println!("With text:\n{contents}");
+ 3 println!("With text:\n{contents}");
}
```
Listing 12-4: Reading the contents of the file specified by the second argument
-First, we bring in a relevant part of the standard library with a `use`
+First we bring in a relevant part of the standard library with a `use`
statement: we need `std::fs` to handle files [1].
In `main`, the new statement `fs::read_to_string` takes the `file_path`, opens
-that file, and returns a `std::io::Result<String>` of the file’s contents [2].
+that file, and returns an `std::io::Result<String>` of the file’s contents [2].
After that, we again add a temporary `println!` statement that prints the value
of `contents` after the file is read, so we can check that the program is
@@ -295,9 +292,9 @@ responsibilities: generally, functions are clearer and easier to maintain if
each function is responsible for only one idea. The other problem is that we’re
not handling errors as well as we could. The program is still small, so these
flaws aren’t a big problem, but as the program grows, it will be harder to fix
-them cleanly. It’s good practice to begin refactoring early on when developing
-a program, because it’s much easier to refactor smaller amounts of code. We’ll
-do that next.
+them cleanly. It’s a good practice to begin refactoring early on when
+developing a program because it’s much easier to refactor smaller amounts of
+code. We’ll do that next.
## Refactoring to Improve Modularity and Error Handling
@@ -342,12 +339,12 @@ community has developed guidelines for splitting the separate concerns of a
binary program when `main` starts getting large. This process has the following
steps:
-* Split your program into a *main.rs* and a *lib.rs* and move your program’s
- logic to *lib.rs*.
+* Split your program into a *main.rs* file and a *lib.rs* file and move your
+program’s logic to *lib.rs*.
* As long as your command line parsing logic is small, it can remain in
- *main.rs*.
+*main.rs*.
* When the command line parsing logic starts getting complicated, extract it
- from *main.rs* and move it to *lib.rs*.
+from *main.rs* and move it to *lib.rs*.
The responsibilities that remain in the `main` function after this process
should be limited to the following:
@@ -358,7 +355,7 @@ should be limited to the following:
* Handling the error if `run` returns an error
This pattern is about separating concerns: *main.rs* handles running the
-program, and *lib.rs* handles all the logic of the task at hand. Because you
+program and *lib.rs* handles all the logic of the task at hand. Because you
can’t test the `main` function directly, this structure lets you test all of
your program’s logic by moving it into functions in *lib.rs*. The code that
remains in *main.rs* will be small enough to verify its correctness by reading
@@ -368,7 +365,7 @@ it. Let’s rework our program by following this process.
We’ll extract the functionality for parsing arguments into a function that
`main` will call to prepare for moving the command line parsing logic to
-*src/lib.rs*. Listing 12-5 shows the new start of `main` that calls a new
+src/lib.rs*. Listing 12-5 shows the new start of `main` that calls a new
function `parse_config`, which we’ll define in *src/main.rs* for the moment.
Filename: src/main.rs
@@ -379,7 +376,7 @@ fn main() {
let (query, file_path) = parse_config(&args);
- // --snip--
+ --snip--
}
fn parse_config(args: &[String]) -> (&str, &str) {
@@ -431,25 +428,25 @@ Filename: src/main.rs
fn main() {
let args: Vec<String> = env::args().collect();
- [1] let config = parse_config(&args);
+ 1 let config = parse_config(&args);
- println!("Searching for {}", config.query[2]);
- println!("In file {}", config.file_path[3]);
+ println!("Searching for {}", 2 config.query);
+ println!("In file {}", 3 config.file_path);
- let contents = fs::read_to_string(config.file_path[4])
+ let contents = fs::read_to_string(4 config.file_path)
.expect("Should have been able to read the file");
- // --snip--
+ --snip--
}
-[5] struct Config {
+5 struct Config {
query: String,
file_path: String,
}
-[6] fn parse_config(args: &[String]) -> Config {
- [7] let query = args[1].clone();
- [8] let file_path = args[2].clone();
+6 fn parse_config(args: &[String]) -> Config {
+ 7 let query = args[1].clone();
+ 8 let file_path = args[2].clone();
Config { query, file_path }
}
@@ -459,8 +456,8 @@ Listing 12-6: Refactoring `parse_config` to return an instance of a `Config`
struct
We’ve added a struct named `Config` defined to have fields named `query` and
-`file_path` [5]. The signature of `parse_config` now indicates that it returns a
-`Config` value [6]. In the body of `parse_config`, where we used to return
+`file_path` [5]. The signature of `parse_config` now indicates that it returns
+a `Config` value [6]. In the body of `parse_config`, where we used to return
string slices that reference `String` values in `args`, we now define `Config`
to contain owned `String` values. The `args` variable in `main` is the owner of
the argument values and is only letting the `parse_config` function borrow
@@ -469,44 +466,43 @@ ownership of the values in `args`.
There are a number of ways we could manage the `String` data; the easiest,
though somewhat inefficient, route is to call the `clone` method on the values
-[7][8]. This will make a full copy of the data for the `Config` instance to
+[7] [8]. This will make a full copy of the data for the `Config` instance to
own, which takes more time and memory than storing a reference to the string
data. However, cloning the data also makes our code very straightforward
because we don’t have to manage the lifetimes of the references; in this
circumstance, giving up a little performance to gain simplicity is a worthwhile
trade-off.
-> ### The Trade-Offs of Using `clone`
+> ### The Trade-Offs of Using clone
>
> There’s a tendency among many Rustaceans to avoid using `clone` to fix
-> ownership problems because of its runtime cost. In
-> Chapter 13, you’ll learn how to use more efficient
-> methods in this type of situation. But for now, it’s okay to copy a few
-> strings to continue making progress because you’ll make these copies only
-> once and your file path and query string are very small. It’s better to have
-> a working program that’s a bit inefficient than to try to hyperoptimize code
-> on your first pass. As you become more experienced with Rust, it’ll be
-> easier to start with the most efficient solution, but for now, it’s
-> perfectly acceptable to call `clone`.
+ownership problems because of its runtime cost. In Chapter 13, you’ll learn how
+to use more efficient methods in this type of situation. But for now, it’s okay
+to copy a few strings to continue making progress because you’ll make these
+copies only once and your file path and query string are very small. It’s
+better to have a working program that’s a bit inefficient than to try to
+hyperoptimize code on your first pass. As you become more experienced with
+Rust, it’ll be easier to start with the most efficient solution, but for now,
+it’s perfectly acceptable to call `clone`.
We’ve updated `main` so it places the instance of `Config` returned by
`parse_config` into a variable named `config` [1], and we updated the code that
previously used the separate `query` and `file_path` variables so it now uses
-the fields on the `Config` struct instead [2][3][4].
+the fields on the `Config` struct instead [2] [3] [4].
Now our code more clearly conveys that `query` and `file_path` are related and
that their purpose is to configure how the program will work. Any code that
uses these values knows to find them in the `config` instance in the fields
named for their purpose.
-#### Creating a Constructor for `Config`
+#### Creating a Constructor for Config
So far, we’ve extracted the logic responsible for parsing the command line
arguments from `main` and placed it in the `parse_config` function. Doing so
-helped us to see that the `query` and `file_path` values were related and that
+helped us see that the `query` and `file_path` values were related, and that
relationship should be conveyed in our code. We then added a `Config` struct to
-name the related purpose of `query` and `file_path` and to be able to return the
-values’ names as struct field names from the `parse_config` function.
+name the related purpose of `query` and `file_path` and to be able to return
+the values’ names as struct field names from the `parse_config` function.
So now that the purpose of the `parse_config` function is to create a `Config`
instance, we can change `parse_config` from a plain function to a function
@@ -523,15 +519,15 @@ Filename: src/main.rs
fn main() {
let args: Vec<String> = env::args().collect();
- [1] let config = Config::new(&args);
+ 1 let config = Config::new(&args);
- // --snip--
+ --snip--
}
-// --snip--
+--snip--
-[2] impl Config {
- [3] fn new(args: &[String]) -> Config {
+2 impl Config {
+ 3 fn new(args: &[String]) -> Config {
let query = args[1].clone();
let file_path = args[2].clone();
@@ -559,8 +555,10 @@ $ cargo run
Compiling minigrep v0.1.0 (file:///projects/minigrep)
Finished dev [unoptimized + debuginfo] target(s) in 0.0s
Running `target/debug/minigrep`
-thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', src/main.rs:27:21
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+thread 'main' panicked at 'index out of bounds: the len is 1 but
+the index is 1', src/main.rs:27:21
+note: run with `RUST_BACKTRACE=1` environment variable to display
+a backtrace
```
The line `index out of bounds: the len is 1 but the index is 1` is an error
@@ -570,18 +568,18 @@ they should do instead. Let’s fix that now.
#### Improving the Error Message
In Listing 12-8, we add a check in the `new` function that will verify that the
-slice is long enough before accessing index 1 and 2. If the slice isn’t long
-enough, the program panics and displays a better error message.
+slice is long enough before accessing index 1 and index 2. If the slice isn’t
+long enough, the program panics and displays a better error message.
Filename: src/main.rs
```
-// --snip--
+--snip--
fn new(args: &[String]) -> Config {
if args.len() < 3 {
panic!("not enough arguments");
}
- // --snip--
+ --snip--
```
Listing 12-8: Adding a check for the number of arguments
@@ -589,9 +587,9 @@ Listing 12-8: Adding a check for the number of arguments
This code is similar to the `Guess::new` function we wrote in Listing 9-13,
where we called `panic!` when the `value` argument was out of the range of
valid values. Instead of checking for a range of values here, we’re checking
-that the length of `args` is at least 3 and the rest of the function can
+that the length of `args` is at least `3` and the rest of the function can
operate under the assumption that this condition has been met. If `args` has
-fewer than three items, this condition will be true, and we call the `panic!`
+fewer than three items, this condition will be `true`, and we call the `panic!`
macro to end the program immediately.
With these extra few lines of code in `new`, let’s run the program without any
@@ -602,19 +600,21 @@ $ cargo run
Compiling minigrep v0.1.0 (file:///projects/minigrep)
Finished dev [unoptimized + debuginfo] target(s) in 0.0s
Running `target/debug/minigrep`
-thread 'main' panicked at 'not enough arguments', src/main.rs:26:13
-note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+thread 'main' panicked at 'not enough arguments',
+src/main.rs:26:13
+note: run with `RUST_BACKTRACE=1` environment variable to display
+a backtrace
```
This output is better: we now have a reasonable error message. However, we also
-have extraneous information we don’t want to give to our users. Perhaps using
-the technique we used in Listing 9-13 isn’t the best to use here: a call to
+have extraneous information we don’t want to give to our users. Perhaps the
+technique we used in Listing 9-13 isn’t the best one to use here: a call to
`panic!` is more appropriate for a programming problem than a usage problem, as
discussed in Chapter 9. Instead, we’ll use the other technique you learned
about in Chapter 9—returning a `Result` that indicates either success or an
error.
-#### Returning a `Result` Instead of Calling `panic!`
+#### Returning a Result Instead of Calling panic!
We can instead return a `Result` value that will contain a `Config` instance in
the successful case and will describe the problem in the error case. We’re also
@@ -650,7 +650,7 @@ impl Config {
Listing 12-9: Returning a `Result` from `Config::build`
Our `build` function returns a `Result` with a `Config` instance in the success
-case and a `&'static str` in the error case. Our error values will always be
+case and an `&'static str` in the error case. Our error values will always be
string literals that have the `'static` lifetime.
We’ve made two changes in the body of the function: instead of calling `panic!`
@@ -662,7 +662,7 @@ Returning an `Err` value from `Config::build` allows the `main` function to
handle the `Result` value returned from the `build` function and exit the
process more cleanly in the error case.
-#### Calling `Config::build` and Handling Errors
+#### Calling Config::build and Handling Errors
To handle the error case and print a user-friendly message, we need to update
`main` to handle the `Result` being returned by `Config::build`, as shown in
@@ -674,17 +674,17 @@ called our program that the program exited with an error state.
Filename: src/main.rs
```
-[1] use std::process;
+1 use std::process;
fn main() {
let args: Vec<String> = env::args().collect();
- [2] let config = Config::build(&args).unwrap_or_else([3]|err[4]| {
- [5] println!("Problem parsing arguments: {err}");
- [6] process::exit(1);
+ 2 let config = Config::build(&args).3 unwrap_or_else(|4 err| {
+ 5 println!("Problem parsing arguments: {err}");
+ 6 process::exit(1);
});
- // --snip--
+ --snip--
```
Listing 12-10: Exiting with an error code if building a `Config` fails
@@ -693,11 +693,11 @@ In this listing, we’ve used a method we haven’t covered in detail yet:
`unwrap_or_else`, which is defined on `Result<T, E>` by the standard library
[2]. Using `unwrap_or_else` allows us to define some custom, non-`panic!` error
handling. If the `Result` is an `Ok` value, this method’s behavior is similar
-to `unwrap`: it returns the inner value `Ok` is wrapping. However, if the value
-is an `Err` value, this method calls the code in the *closure*, which is an
-anonymous function we define and pass as an argument to `unwrap_or_else` [3].
-We’ll cover closures in more detail in Chapter 13. For now, you just need to
-know that `unwrap_or_else` will pass the inner value of the `Err`, which in
+to `unwrap`: it returns the inner value that `Ok` is wrapping. However, if the
+value is an `Err` value, this method calls the code in the *closure*, which is
+an anonymous function we define and pass as an argument to `unwrap_or_else`
+[3]. We’ll cover closures in more detail in Chapter 13. For now, you just need
+to know that `unwrap_or_else` will pass the inner value of the `Err`, which in
this case is the static string `"not enough arguments"` that we added in
Listing 12-9, to our closure in the argument `err` that appears between the
vertical pipes [4]. The code in the closure can then use the `err` value when
@@ -721,12 +721,12 @@ Problem parsing arguments: not enough arguments
Great! This output is much friendlier for our users.
-### Extracting Logic from `main`
+### Extracting Logic from main
Now that we’ve finished refactoring the configuration parsing, let’s turn to
the program’s logic. As we stated in “Separation of Concerns for Binary
-Projectsâ€, we’ll extract a function named `run` that will hold all the logic
-currently in the `main` function that isn’t involved with setting up
+Projects†on page XX, we’ll extract a function named `run` that will hold all
+the logic currently in the `main` function that isn’t involved with setting up
configuration or handling errors. When we’re done, `main` will be concise and
easy to verify by inspection, and we’ll be able to write tests for all the
other logic.
@@ -739,7 +739,7 @@ Filename: src/main.rs
```
fn main() {
- // --snip--
+ --snip--
println!("Searching for {}", config.query);
println!("In file {}", config.file_path);
@@ -754,7 +754,7 @@ fn run(config: Config) {
println!("With text:\n{contents}");
}
-// --snip--
+--snip--
```
Listing 12-11: Extracting a `run` function containing the rest of the program
@@ -764,7 +764,7 @@ The `run` function now contains all the remaining logic from `main`, starting
from reading the file. The `run` function takes the `Config` instance as an
argument.
-#### Returning Errors from the `run` Function
+#### Returning Errors from the run Function
With the remaining program logic separated into the `run` function, we can
improve the error handling, as we did with `Config::build` in Listing 12-9.
@@ -777,25 +777,25 @@ signature and body of `run`.
Filename: src/main.rs
```
-[1] use std::error::Error;
+1 use std::error::Error;
-// --snip--
+--snip--
-[2] fn run(config: Config) -> Result<(), Box<dyn Error>> {
- let contents = fs::read_to_string(config.file_path)?[3];
+2 fn run(config: Config) -> Result<(), Box<dyn Error>> {
+ let contents = fs::read_to_string(config.file_path)3 ?;
println!("With text:\n{contents}");
- [4] Ok(())
+ 4 Ok(())
}
```
Listing 12-12: Changing the `run` function to return `Result`
We’ve made three significant changes here. First, we changed the return type of
-the `run` function to `Result<(), Box<dyn Error>>` [2]. This function previously
-returned the unit type, `()`, and we keep that as the value returned in the
-`Ok` case.
+the `run` function to `Result<(), Box<dyn Error>>` [2]. This function
+previously returned the unit type, `()`, and we keep that as the value returned
+in the `Ok` case.
For the error type, we used the *trait object* `Box<dyn Error>` (and we’ve
brought `std::error::Error` into scope with a `use` statement at the top [1]).
@@ -803,7 +803,7 @@ We’ll cover trait objects in Chapter 17. For now, just know that `Box<dyn
Error>` means the function will return a type that implements the `Error`
trait, but we don’t have to specify what particular type the return value will
be. This gives us flexibility to return error values that may be of different
-types in different error cases. The `dyn` keyword is short for “dynamic.â€
+types in different error cases. The `dyn` keyword is short for *dynamic*.
Second, we’ve removed the call to `expect` in favor of the `?` operator [3], as
we talked about in Chapter 9. Rather than `panic!` on an error, `?` will return
@@ -826,7 +826,8 @@ warning: unused `Result` that must be used
| ^^^^^^^^^^^^
|
= note: `#[warn(unused_must_use)]` on by default
- = note: this `Result` may be an `Err` variant, which should be handled
+ = note: this `Result` may be an `Err` variant, which should be
+handled
```
Rust tells us that our code ignored the `Result` value and the `Result` value
@@ -834,7 +835,7 @@ might indicate that an error occurred. But we’re not checking to see whether o
not there was an error, and the compiler reminds us that we probably meant to
have some error-handling code here! Let’s rectify that problem now.
-#### Handling Errors Returned from `run` in `main`
+#### Handling Errors Returned from run in main
We’ll check for errors and handle them using a technique similar to one we used
with `Config::build` in Listing 12-10, but with a slight difference:
@@ -843,7 +844,7 @@ Filename: src/main.rs
```
fn main() {
- // --snip--
+ --snip--
println!("Searching for {}", config.query);
println!("In file {}", config.file_path);
@@ -856,11 +857,11 @@ fn main() {
```
We use `if let` rather than `unwrap_or_else` to check whether `run` returns an
-`Err` value and call `process::exit(1)` if it does. The `run` function doesn’t
-return a value that we want to `unwrap` in the same way that `Config::build`
-returns the `Config` instance. Because `run` returns `()` in the success case,
-we only care about detecting an error, so we don’t need `unwrap_or_else` to
-return the unwrapped value, which would only be `()`.
+`Err` value and to call `process::exit(1)` if it does. The `run` function
+doesn’t return a value that we want to `unwrap` in the same way that
+`Config::build` returns the `Config` instance. Because `run` returns `()` in
+the success case, we only care about detecting an error, so we don’t need
+`unwrap_or_else` to return the unwrapped value, which would only be `()`.
The bodies of the `if let` and the `unwrap_or_else` functions are the same in
both cases: we print the error and exit.
@@ -868,10 +869,10 @@ both cases: we print the error and exit.
### Splitting Code into a Library Crate
Our `minigrep` project is looking good so far! Now we’ll split the
-*src/main.rs* file and put some code into the *src/lib.rs* file. That way we
+*src/main.rs* file and put some code into the *src/lib.rs* file. That way, we
can test the code and have a *src/main.rs* file with fewer responsibilities.
-Let’s move all the code that isn’t the `main` function from *src/main.rs* to
+Let’s move all the code that isn’t in the `main` function from *src/main.rs* to
*src/lib.rs*:
* The `run` function definition
@@ -895,13 +896,15 @@ pub struct Config {
}
impl Config {
- pub fn build(args: &[String]) -> Result<Config, &'static str> {
- // --snip--
+ pub fn build(
+ args: &[String],
+ ) -> Result<Config, &'static str> {
+ --snip--
}
}
pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
- // --snip--
+ --snip--
}
```
@@ -923,9 +926,9 @@ use std::process;
use minigrep::Config;
fn main() {
- // --snip--
+ --snip--
if let Err(e) = minigrep::run(config) {
- // --snip--
+ --snip--
}
}
```
@@ -935,8 +938,7 @@ Listing 12-14: Using the `minigrep` library crate in *src/main.rs*
We add a `use minigrep::Config` line to bring the `Config` type from the
library crate into the binary crate’s scope, and we prefix the `run` function
with our crate name. Now all the functionality should be connected and should
-work. Run the program with `cargo run` and make sure everything works
-correctly.
+work. Run the program with `cargo run` and make sure everything works correctly.
Whew! That was a lot of work, but we’ve set ourselves up for success in the
future. Now it’s much easier to handle errors, and we’ve made the code more
@@ -954,21 +956,21 @@ for the core functionality of our code. We can call functions directly with
various arguments and check return values without having to call our binary
from the command line.
-In this section, we’ll add the searching logic to the `minigrep` program
-using the test-driven development (TDD) process with the following steps:
+In this section, we’ll add the searching logic to the `minigrep` program using
+the test-driven development (TDD) process with the following steps:
1. Write a test that fails and run it to make sure it fails for the reason you
- expect.
-2. Write or modify just enough code to make the new test pass.
-3. Refactor the code you just added or changed and make sure the tests
- continue to pass.
-4. Repeat from step 1!
+expect.
+1. Write or modify just enough code to make the new test pass.
+1. Refactor the code you just added or changed and make sure the tests continue
+to pass.
+1. Repeat from step 1!
Though it’s just one of many ways to write software, TDD can help drive code
design. Writing the test before you write the code that makes the test pass
helps to maintain high test coverage throughout the process.
-We’ll test drive the implementation of the functionality that will actually do
+We’ll test-drive the implementation of the functionality that will actually do
the searching for the query string in the file contents and produce a list of
lines that match the query. We’ll add this functionality in a function called
`search`.
@@ -977,11 +979,11 @@ lines that match the query. We’ll add this functionality in a function called
Because we don’t need them anymore, let’s remove the `println!` statements from
*src/lib.rs* and *src/main.rs* that we used to check the program’s behavior.
-Then, in *src/lib.rs*, add a `tests` module with a test function, as we did in
-Chapter 11. The test function specifies the behavior we want the `search`
-function to have: it will take a query and the text to search, and it will
-return only the lines from the text that contain the query. Listing 12-15 shows
-this test, which won’t compile yet.
+Then, in *src/lib.rs*, we’ll add a `tests` module with a test function, as we
+did in Chapter 11. The test function specifies the behavior we want the
+`search` function to have: it will take a query and the text to search, and it
+will return only the lines from the text that contain the query. Listing 12-15
+shows this test, which won’t compile yet.
Filename: src/lib.rs
@@ -998,7 +1000,10 @@ Rust:
safe, fast, productive.
Pick three.";
- assert_eq!(vec!["safe, fast, productive."], search(query, contents));
+ assert_eq!(
+ vec!["safe, fast, productive."],
+ search(query, contents)
+ );
}
}
```
@@ -1006,7 +1011,7 @@ Pick three.";
Listing 12-15: Creating a failing test for the `search` function we wish we had
This test searches for the string `"duct"`. The text we’re searching is three
-lines, only one of which contains `"duct"` (Note that the backslash after the
+lines, only one of which contains `"duct"` (note that the backslash after the
opening double quote tells Rust not to put a newline character at the beginning
of the contents of this string literal). We assert that the value returned from
the `search` function contains only the line we expect.
@@ -1017,12 +1022,15 @@ principles, we’ll add just enough code to get the test to compile and run by
adding a definition of the `search` function that always returns an empty
vector, as shown in Listing 12-16. Then the test should compile and fail
because an empty vector doesn’t match a vector containing the line `"safe,
-fast, productive."`
+fast, productive."`.
Filename: src/lib.rs
```
-pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
+pub fn search<'a>(
+ query: &str,
+ contents: &'a str,
+) -> Vec<&'a str> {
vec![]
}
```
@@ -1049,16 +1057,24 @@ get this error:
```
error[E0106]: missing lifetime specifier
- --> src/lib.rs:28:51
+ --> src/lib.rs:31:10
|
-28 | pub fn search(query: &str, contents: &str) -> Vec<&str> {
- | ---- ---- ^ expected named lifetime parameter
+29 | query: &str,
+ | ----
+30 | contents: &str,
+ | ----
+31 | ) -> Vec<&str> {
+ | ^ expected named lifetime parameter
|
- = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `query` or `contents`
+ = help: this function's return type contains a borrowed value, but the
+signature does not say whether it is borrowed from `query` or `contents`
help: consider introducing a named lifetime parameter
|
-28 | pub fn search<'a>(query: &'a str, contents: &'a str) -> Vec<&'a str> {
- | ++++ ++ ++ ++
+28 ~ pub fn search<'a>(
+29 ~ query: &'a str,
+30 ~ contents: &'a str,
+31 ~ ) -> Vec<&'a str> {
+ |
```
Rust can’t possibly know which of the two arguments we need, so we need to tell
@@ -1069,8 +1085,8 @@ syntax.
Other programming languages don’t require you to connect arguments to return
values in the signature, but this practice will get easier over time. You might
-want to compare this example with the “Validating References with Lifetimesâ€
-section in Chapter 10.
+want to compare this example with the examples in “Validating References with
+Lifetimes†on page XX.
Now let’s run the test:
@@ -1086,16 +1102,17 @@ test tests::one_result ... FAILED
failures:
---- tests::one_result stdout ----
-thread 'main' panicked at 'assertion failed: `(left == right)`
+thread 'tests::one_result' panicked at 'assertion failed: `(left == right)`
left: `["safe, fast, productive."]`,
- right: `[]`', src/lib.rs:44:9
+ right: `[]`', src/lib.rs:47:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
tests::one_result
-test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out;
+finished in 0.00s
error: test failed, to rerun pass '--lib'
```
@@ -1107,24 +1124,27 @@ Great, the test fails, exactly as we expected. Let’s get the test to pass!
Currently, our test is failing because we always return an empty vector. To fix
that and implement `search`, our program needs to follow these steps:
-* Iterate through each line of the contents.
-* Check whether the line contains our query string.
-* If it does, add it to the list of values we’re returning.
-* If it doesn’t, do nothing.
-* Return the list of results that match.
+1. Iterate through each line of the contents.
+1. Check whether the line contains our query string.
+1. If it does, add it to the list of values we’re returning.
+1. If it doesn’t, do nothing.
+1. Return the list of results that match.
Let’s work through each step, starting with iterating through lines.
-#### Iterating Through Lines with the `lines` Method
+#### Iterating Through Lines with the lines Method
Rust has a helpful method to handle line-by-line iteration of strings,
-conveniently named `lines`, that works as shown in Listing 12-17. Note this
-won’t compile yet.
+conveniently named `lines`, that works as shown in Listing 12-17. Note that
+this won’t compile yet.
Filename: src/lib.rs
```
-pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
+pub fn search<'a>(
+ query: &str,
+ contents: &'a str,
+) -> Vec<&'a str> {
for line in contents.lines() {
// do something with line
}
@@ -1143,12 +1163,15 @@ in a collection.
Next, we’ll check whether the current line contains our query string.
Fortunately, strings have a helpful method named `contains` that does this for
us! Add a call to the `contains` method in the `search` function, as shown in
-Listing 12-18. Note this still won’t compile yet.
+Listing 12-18. Note that this still won’t compile yet.
Filename: src/lib.rs
```
-pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
+pub fn search<'a>(
+ query: &str,
+ contents: &'a str,
+) -> Vec<&'a str> {
for line in contents.lines() {
if line.contains(query) {
// do something with line
@@ -1160,8 +1183,8 @@ pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
Listing 12-18: Adding functionality to see whether the line contains the string
in `query`
-At the moment, we’re building up functionality. To get it to compile, we need
-to return a value from the body as we indicated we would in the function
+At the moment, we’re building up functionality. To get the code to compile, we
+need to return a value from the body as we indicated we would in the function
signature.
#### Storing Matching Lines
@@ -1174,7 +1197,10 @@ we return the vector, as shown in Listing 12-19.
Filename: src/lib.rs
```
-pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
+pub fn search<'a>(
+ query: &str,
+ contents: &'a str,
+) -> Vec<&'a str> {
let mut results = Vec::new();
for line in contents.lines() {
@@ -1198,7 +1224,8 @@ $ cargo test
running 1 test
test tests::one_result ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
Our test passed, so we know it works!
@@ -1210,7 +1237,7 @@ but it doesn’t take advantage of some useful features of iterators. We’ll
return to this example in Chapter 13, where we’ll explore iterators in detail,
and look at how to improve it.
-#### Using the `search` Function in the `run` Function
+#### Using the search Function in the run Function
Now that the `search` function is working and tested, we need to call `search`
from our `run` function. We need to pass the `config.query` value and the
@@ -1234,7 +1261,7 @@ pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
We’re still using a `for` loop to return each line from `search` and print it.
Now the entire program should work! Let’s try it out, first with a word that
-should return exactly one line from the Emily Dickinson poem, “frogâ€:
+should return exactly one line from the Emily Dickinson poem: *frog*.
```
$ cargo run -- frog poem.txt
@@ -1244,7 +1271,7 @@ $ cargo run -- frog poem.txt
How public, like a frog
```
-Cool! Now let’s try a word that will match multiple lines, like “bodyâ€:
+Cool! Now let’s try a word that will match multiple lines, like *body*:
```
$ cargo run -- body poem.txt
@@ -1256,7 +1283,7 @@ How dreary to be somebody!
```
And finally, let’s make sure that we don’t get any lines when we search for a
-word that isn’t anywhere in the poem, such as “monomorphizationâ€:
+word that isn’t anywhere in the poem, such as *monomorphization*:
```
$ cargo run -- monomorphization poem.txt
@@ -1281,7 +1308,7 @@ users enter it each time they want it to apply, but by instead making it an
environment variable, we allow our users to set the environment variable once
and have all their searches be case insensitive in that terminal session.
-### Writing a Failing Test for the Case-Insensitive `search` Function
+### Writing a Failing Test for the Case-Insensitive search Function
We first add a new `search_case_insensitive` function that will be called when
the environment variable has a value. We’ll continue to follow the TDD process,
@@ -1306,7 +1333,10 @@ safe, fast, productive.
Pick three.
Duct tape.";
- assert_eq!(vec!["safe, fast, productive."], search(query, contents));
+ assert_eq!(
+ vec!["safe, fast, productive."],
+ search(query, contents)
+ );
}
#[test]
@@ -1330,7 +1360,7 @@ Listing 12-20: Adding a new failing test for the case-insensitive function
we’re about to add
Note that we’ve edited the old test’s `contents` too. We’ve added a new line
-with the text `"Duct tape."` using a capital D that shouldn’t match the query
+with the text `"Duct tape."` using a capital *D* that shouldn’t match the query
`"duct"` when we’re searching in a case-sensitive manner. Changing the old test
in this way helps ensure that we don’t accidentally break the case-sensitive
search functionality that we’ve already implemented. This test should pass now
@@ -1338,18 +1368,18 @@ and should continue to pass as we work on the case-insensitive search.
The new test for the case-*insensitive* search uses `"rUsT"` as its query. In
the `search_case_insensitive` function we’re about to add, the query `"rUsT"`
-should match the line containing `"Rust:"` with a capital R and match the line
-`"Trust me."` even though both have different casing from the query. This is
-our failing test, and it will fail to compile because we haven’t yet defined
+should match the line containing `"Rust:"` with a capital *R* and match the
+line `"Trust me."` even though both have different casing from the query. This
+is our failing test, and it will fail to compile because we haven’t yet defined
the `search_case_insensitive` function. Feel free to add a skeleton
implementation that always returns an empty vector, similar to the way we did
for the `search` function in Listing 12-16 to see the test compile and fail.
-### Implementing the `search_case_insensitive` Function
+### Implementing the search_case_insensitive Function
The `search_case_insensitive` function, shown in Listing 12-21, will be almost
the same as the `search` function. The only difference is that we’ll lowercase
-the `query` and each `line` so whatever the case of the input arguments,
+the `query` and each `line` so that whatever the case of the input arguments,
they’ll be the same case when we check whether the line contains the query.
Filename: src/lib.rs
@@ -1359,11 +1389,11 @@ pub fn search_case_insensitive<'a>(
query: &str,
contents: &'a str,
) -> Vec<&'a str> {
- [1] let query = query.to_lowercase();
+ 1 let query = query.to_lowercase();
let mut results = Vec::new();
for line in contents.lines() {
- if line.to_lowercase()[2].contains(&query[3]) {
+ if 2 line.to_lowercase().contains(3 &query) {
results.push(line);
}
}
@@ -1375,8 +1405,8 @@ pub fn search_case_insensitive<'a>(
Listing 12-21: Defining the `search_case_insensitive` function to lowercase the
query and the line before comparing them
-First, we lowercase the `query` string and store it in a shadowed variable with
-the same name [1]. Calling `to_lowercase` on the query is necessary so no
+First we lowercase the `query` string and store it in a shadowed variable with
+the same name [1]. Calling `to_lowercase` on the query is necessary so that no
matter whether the user’s query is `"rust"`, `"RUST"`, `"Rust"`, or `"rUsT"`,
we’ll treat the query as if it were `"rust"` and be insensitive to the case.
While `to_lowercase` will handle basic Unicode, it won’t be 100% accurate. If
@@ -1384,7 +1414,7 @@ we were writing a real application, we’d want to do a bit more work here, but
this section is about environment variables, not Unicode, so we’ll leave it at
that here.
-Note that `query` is now a `String` rather than a string slice, because calling
+Note that `query` is now a `String` rather than a string slice because calling
`to_lowercase` creates new data rather than referencing existing data. Say the
query is `"rUsT"`, as an example: that string slice doesn’t contain a lowercase
`u` or `t` for us to use, so we have to allocate a new `String` containing
@@ -1403,14 +1433,15 @@ running 2 tests
test tests::case_insensitive ... ok
test tests::case_sensitive ... ok
-test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.00s
```
Great! They passed. Now, let’s call the new `search_case_insensitive` function
-from the `run` function. First, we’ll add a configuration option to the
-`Config` struct to switch between case-sensitive and case-insensitive search.
-Adding this field will cause compiler errors because we aren’t initializing
-this field anywhere yet:
+from the `run` function. First we’ll add a configuration option to the `Config`
+struct to switch between case-sensitive and case-insensitive search. Adding
+this field will cause compiler errors because we aren’t initializing this field
+anywhere yet:
Filename: src/lib.rs
@@ -1461,10 +1492,12 @@ Filename: src/lib.rs
```
use std::env;
-// --snip--
+--snip--
impl Config {
- pub fn build(args: &[String]) -> Result<Config, &'static str> {
+ pub fn build(
+ args: &[String]
+ ) -> Result<Config, &'static str> {
if args.len() < 3 {
return Err("not enough arguments");
}
@@ -1486,7 +1519,7 @@ impl Config {
Listing 12-23: Checking for any value in an environment variable named
`IGNORE_CASE`
-Here, we create a new variable `ignore_case`. To set its value, we call the
+Here, we create a new variable, `ignore_case`. To set its value, we call the
`env::var` function and pass it the name of the `IGNORE_CASE` environment
variable. The `env::var` function returns a `Result` that will be the
successful `Ok` variant that contains the value of the environment variable if
@@ -1496,7 +1529,7 @@ if the environment variable is not set.
We’re using the `is_ok` method on the `Result` to check whether the environment
variable is set, which means the program should do a case-insensitive search.
If the `IGNORE_CASE` environment variable isn’t set to anything, `is_ok` will
-return false and the program will perform a case-sensitive search. We don’t
+return `false` and the program will perform a case-sensitive search. We don’t
care about the *value* of the environment variable, just whether it’s set or
unset, so we’re checking `is_ok` rather than using `unwrap`, `expect`, or any
of the other methods we’ve seen on `Result`.
@@ -1505,9 +1538,9 @@ We pass the value in the `ignore_case` variable to the `Config` instance so the
`run` function can read that value and decide whether to call
`search_case_insensitive` or `search`, as we implemented in Listing 12-22.
-Let’s give it a try! First, we’ll run our program without the environment
+Let’s give it a try! First we’ll run our program without the environment
variable set and with the query `to`, which should match any line that contains
-the word “to†in all lowercase:
+the word *to* in all lowercase:
```
$ cargo run -- to poem.txt
@@ -1518,8 +1551,8 @@ Are you nobody, too?
How dreary to be somebody!
```
-Looks like that still works! Now, let’s run the program with `IGNORE_CASE`
-set to `1` but with the same query `to`.
+Looks like that still works! Now let’s run the program with `IGNORE_CASE` set
+to `1` but with the same query `to`:
```
$ IGNORE_CASE=1 cargo run -- to poem.txt
@@ -1532,14 +1565,14 @@ run the program as separate commands:
PS> $Env:IGNORE_CASE=1; cargo run -- to poem.txt
```
-This will make `IGNORE_CASE` persist for the remainder of your shell
-session. It can be unset with the `Remove-Item` cmdlet:
+This will make `IGNORE_CASE` persist for the remainder of your shell session.
+It can be unset with the `Remove-Item` cmdlet:
```
PS> Remove-Item Env:IGNORE_CASE
```
-We should get lines that contain “to†that might have uppercase letters:
+We should get lines that contain *to* that might have uppercase letters:
```
Are you nobody, too?
@@ -1548,7 +1581,7 @@ To tell your name the livelong day
To an admiring bog!
```
-Excellent, we also got lines containing “Toâ€! Our `minigrep` program can now do
+Excellent, we also got lines containing *To*! Our `minigrep` program can now do
case-insensitive searching controlled by an environment variable. Now you know
how to manage options set using either command line arguments or environment
variables.
@@ -1573,12 +1606,12 @@ error messages. This distinction enables users to choose to direct the
successful output of a program to a file but still print error messages to the
screen.
-The `println!` macro is only capable of printing to standard output, so we
-have to use something else to print to standard error.
+The `println!` macro is only capable of printing to standard output, so we have
+to use something else to print to standard error.
### Checking Where Errors Are Written
-First, let’s observe how the content printed by `minigrep` is currently being
+First let’s observe how the content printed by `minigrep` is currently being
written to standard output, including any error messages we want to write to
standard error instead. We’ll do that by redirecting the standard output stream
to a file while intentionally causing an error. We won’t redirect the standard
@@ -1587,7 +1620,7 @@ the screen.
Command line programs are expected to send error messages to the standard error
stream so we can still see error messages on the screen even if we redirect the
-standard output stream to a file. Our program is not currently well-behaved:
+standard output stream to a file. Our program is not currently well behaved:
we’re about to see that it saves the error message output to a file instead!
To demonstrate this behavior, we’ll run the program with `>` and the file path,
@@ -1684,3 +1717,4 @@ well tested.
Next, we’ll explore some Rust features that were influenced by functional
languages: closures and iterators.
+
diff --git a/src/doc/book/nostarch/chapter13.md b/src/doc/book/nostarch/chapter13.md
index 8f7717ccb..52c1f5f97 100644
--- a/src/doc/book/nostarch/chapter13.md
+++ b/src/doc/book/nostarch/chapter13.md
@@ -23,15 +23,15 @@ More specifically, we’ll cover:
* *Closures*, a function-like construct you can store in a variable
* *Iterators*, a way of processing a series of elements
* How to use closures and iterators to improve the I/O project in Chapter 12
-* The performance of closures and iterators (Spoiler alert: they’re faster than
- you might think!)
+* The performance of closures and iterators (spoiler alert: they’re faster than
+you might think!)
We’ve already covered some other Rust features, such as pattern matching and
enums, that are also influenced by the functional style. Because mastering
closures and iterators is an important part of writing idiomatic, fast Rust
code, we’ll devote this entire chapter to them.
-## Closures: Anonymous Functions that Capture Their Environment
+## Closures: Anonymous Functions That Capture Their Environment
Rust’s closures are anonymous functions you can save in a variable or pass as
arguments to other functions. You can create the closure in one place and then
@@ -43,8 +43,8 @@ customization.
### Capturing the Environment with Closures
We’ll first examine how we can use closures to capture values from the
-environment they’re defined in for later use. Here’s the scenario: Every so
-often, our t-shirt company gives away an exclusive, limited-edition shirt to
+environment they’re defined in for later use. Here’s the scenario: every so
+often, our T-shirt company gives away an exclusive, limited-edition shirt to
someone on our mailing list as a promotion. People on the mailing list can
optionally add their favorite color to their profile. If the person chosen for
a free shirt has their favorite color set, they get that color shirt. If the
@@ -56,9 +56,9 @@ enum called `ShirtColor` that has the variants `Red` and `Blue` (limiting the
number of colors available for simplicity). We represent the company’s
inventory with an `Inventory` struct that has a field named `shirts` that
contains a `Vec<ShirtColor>` representing the shirt colors currently in stock.
-The method `giveaway` defined on `Inventory` gets the optional shirt
-color preference of the free shirt winner, and returns the shirt color the
-person will get. This setup is shown in Listing 13-1:
+The method `giveaway` defined on `Inventory` gets the optional shirt color
+preference of the free-shirt winner, and returns the shirt color the person
+will get. This setup is shown in Listing 13-1.
Filename: src/main.rs
@@ -74,8 +74,11 @@ struct Inventory {
}
impl Inventory {
- fn giveaway(&self, user_preference: Option<ShirtColor>) -> ShirtColor {
- user_preference.unwrap_or_else(|| self.most_stocked()) [1]
+ fn giveaway(
+ &self,
+ user_preference: Option<ShirtColor>,
+ ) -> ShirtColor {
+ 1 user_preference.unwrap_or_else(|| self.most_stocked())
}
fn most_stocked(&self) -> ShirtColor {
@@ -98,18 +101,22 @@ impl Inventory {
fn main() {
let store = Inventory {
- shirts: vec![ShirtColor::Blue, ShirtColor::Red, ShirtColor::Blue], [2]
+ 2 shirts: vec![
+ ShirtColor::Blue,
+ ShirtColor::Red,
+ ShirtColor::Blue,
+ ],
};
let user_pref1 = Some(ShirtColor::Red);
- let giveaway1 = store.giveaway(user_pref1); [3]
+ 3 let giveaway1 = store.giveaway(user_pref1);
println!(
"The user with preference {:?} gets {:?}",
user_pref1, giveaway1
);
let user_pref2 = None;
- let giveaway2 = store.giveaway(user_pref2); [4]
+ 4 let giveaway2 = store.giveaway(user_pref2);
println!(
"The user with preference {:?} gets {:?}",
user_pref2, giveaway2
@@ -125,11 +132,11 @@ method for a user with a preference for a red shirt [3] and a user without any
preference [4].
Again, this code could be implemented in many ways, and here, to focus on
-closures, we’ve stuck to concepts you’ve already learned except for the body of
-the `giveaway` method that uses a closure. In the `giveaway` method, we get the
-user preference as a parameter of type `Option<ShirtColor>` and call the
-`unwrap_or_else` method on `user_preference` [1]. The `unwrap_or_else` method on
-`Option<T>` is defined by the standard library. It takes one argument: a
+closures, we’ve stuck to concepts you’ve already learned, except for the body
+of the `giveaway` method that uses a closure. In the `giveaway` method, we get
+the user preference as a parameter of type `Option<ShirtColor>` and call the
+`unwrap_or_else` method on `user_preference` [1]. The `unwrap_or_else` method
+on `Option<T>` is defined by the standard library. It takes one argument: a
closure without any arguments that returns a value `T` (the same type stored in
the `Some` variant of the `Option<T>`, in this case `ShirtColor`). If the
`Option<T>` is the `Some` variant, `unwrap_or_else` returns the value from
@@ -138,18 +145,14 @@ calls the closure and returns the value returned by the closure.
We specify the closure expression `|| self.most_stocked()` as the argument to
`unwrap_or_else`. This is a closure that takes no parameters itself (if the
-closure had parameters, they would appear between the two vertical bars). The
+closure had parameters, they would appear between the two vertical pipes). The
body of the closure calls `self.most_stocked()`. We’re defining the closure
here, and the implementation of `unwrap_or_else` will evaluate the closure
later if the result is needed.
-Running this code prints:
+Running this code prints the following:
```
-$ cargo run
- Compiling shirt-company v0.1.0 (file:///projects/shirt-company)
- Finished dev [unoptimized + debuginfo] target(s) in 0.27s
- Running `target/debug/shirt-company`
The user with preference Some(Red) gets Red
The user with preference None gets Blue
```
@@ -184,7 +187,7 @@ explicitness and clarity at the cost of being more verbose than is strictly
necessary. Annotating the types for a closure would look like the definition
shown in Listing 13-2. In this example, we’re defining a closure and storing it
in a variable rather than defining the closure in the spot we pass it as an
-argument as we did in Listing 13-1.
+argument, as we did in Listing 13-1.
Filename: src/main.rs
@@ -200,11 +203,11 @@ Listing 13-2: Adding optional type annotations of the parameter and return
value types in the closure
With type annotations added, the syntax of closures looks more similar to the
-syntax of functions. Here we define a function that adds 1 to its parameter and
-a closure that has the same behavior, for comparison. We’ve added some spaces
-to line up the relevant parts. This illustrates how closure syntax is similar
-to function syntax except for the use of pipes and the amount of syntax that is
-optional:
+syntax of functions. Here, we define a function that adds 1 to its parameter
+and a closure that has the same behavior, for comparison. We’ve added some
+spaces to line up the relevant parts. This illustrates how closure syntax is
+similar to function syntax except for the use of pipes and the amount of syntax
+that is optional:
```
fn add_one_v1 (x: u32) -> u32 { x + 1 }
@@ -213,13 +216,13 @@ let add_one_v3 = |x| { x + 1 };
let add_one_v4 = |x| x + 1 ;
```
-The first line shows a function definition, and the second line shows a fully
+The first line shows a function definition and the second line shows a fully
annotated closure definition. In the third line, we remove the type annotations
-from the closure definition. In the fourth line, we remove the brackets, which
-are optional because the closure body has only one expression. These are all
-valid definitions that will produce the same behavior when they’re called. The
-`add_one_v3` and `add_one_v4` lines require the closures to be evaluated to be
-able to compile because the types will be inferred from their usage. This is
+from the closure definition. In the fourth line, we remove the curly brackets,
+which are optional because the closure body has only one expression. These are
+all valid definitions that will produce the same behavior when they’re called.
+The `add_one_v3` and `add_one_v4` lines require the closures to be evaluated to
+be able to compile because the types will be inferred from their usage. This is
similar to `let v = Vec::new();` needing either type annotations or values of
some type to be inserted into the `Vec` for Rust to be able to infer the type.
@@ -251,7 +254,8 @@ error[E0308]: mismatched types
--> src/main.rs:5:29
|
5 | let n = example_closure(5);
- | ^- help: try using a conversion method: `.to_string()`
+ | ^- help: try using a conversion method:
+`.to_string()`
| |
| expected struct `String`, found integer
```
@@ -271,7 +275,7 @@ captured values.
In Listing 13-4, we define a closure that captures an immutable reference to
the vector named `list` because it only needs an immutable reference to print
-the value:
+the value.
Filename: src/main.rs
@@ -280,10 +284,10 @@ fn main() {
let list = vec![1, 2, 3];
println!("Before defining closure: {:?}", list);
- [1] let only_borrows = || println!("From closure: {:?}", list);
+ 1 let only_borrows = || println!("From closure: {:?}", list);
println!("Before calling closure: {:?}", list);
- only_borrows(); [2]
+ 2 only_borrows();
println!("After calling closure: {:?}", list);
}
```
@@ -308,7 +312,7 @@ After calling closure: [1, 2, 3]
```
Next, in Listing 13-5, we change the closure body so that it adds an element to
-the `list` vector. The closure now captures a mutable reference:
+the `list` vector. The closure now captures a mutable reference.
Filename: src/main.rs
@@ -350,7 +354,7 @@ the data so that it’s owned by the new thread. We’ll discuss threads and why
you would want to use them in detail in Chapter 16 when we talk about
concurrency, but for now, let’s briefly explore spawning a new thread using a
closure that needs the `move` keyword. Listing 13-6 shows Listing 13-4 modified
-to print the vector in a new thread rather than in the main thread:
+to print the vector in a new thread rather than in the main thread.
Filename: src/main.rs
@@ -361,8 +365,8 @@ fn main() {
let list = vec![1, 2, 3];
println!("Before defining closure: {:?}", list);
- [1] thread::spawn(move || {
- [2] println!("From thread: {:?}", list)
+ 1 thread::spawn(move || {
+ 2 println!("From thread: {:?}", list)
}).join().unwrap();
}
```
@@ -372,29 +376,30 @@ ownership of `list`
We spawn a new thread, giving the thread a closure to run as an argument. The
closure body prints out the list. In Listing 13-4, the closure only captured
-`list` using an immutable reference because that's the least amount of access
+`list` using an immutable reference because that’s the least amount of access
to `list` needed to print it. In this example, even though the closure body
-still only needs an immutable reference, we need to specify that `list` should
-be moved into the closure by putting the `move` keyword at the beginning of the
-closure definition. The new thread might finish before the rest of the main
-thread finishes, or the main thread might finish first. If the main thread
-maintained ownership of `list` but ended before the new thread did and dropped
-`list`, the immutable reference in the thread would be invalid. Therefore, the
-compiler requires that `list` be moved into the closure given to the new thread
-so the reference will be valid. Try removing the `move` keyword or using `list`
-in the main thread after the closure is defined to see what compiler errors you
-get!
-
-### Moving Captured Values Out of Closures and the `Fn` Traits
+still only needs an immutable reference [2], we need to specify that `list`
+should be moved into the closure by putting the `move` keyword [1] at the
+beginning of the closure definition. The new thread might finish before the
+rest of the main thread finishes, or the main thread might finish first. If the
+main thread maintains ownership of `list` but ends before the new thread and
+drops `list`, the immutable reference in the thread would be invalid.
+Therefore, the compiler requires that `list` be moved into the closure given to
+the new thread so the reference will be valid. Try removing the `move` keyword
+or using `list` in the main thread after the closure is defined to see what
+compiler errors you get!
+
+### Moving Captured Values Out of Closures and the Fn Traits
Once a closure has captured a reference or captured ownership of a value from
the environment where the closure is defined (thus affecting what, if anything,
is moved *into* the closure), the code in the body of the closure defines what
happens to the references or values when the closure is evaluated later (thus
-affecting what, if anything, is moved *out of* the closure). A closure body can
-do any of the following: move a captured value out of the closure, mutate the
-captured value, neither move nor mutate the value, or capture nothing from the
-environment to begin with.
+affecting what, if anything, is moved *out of* the closure).
+
+A closure body can do any of the following: move a captured value out of the
+closure, mutate the captured value, neither move nor mutate the value, or
+capture nothing from the environment to begin with.
The way a closure captures and handles values from the environment affects
which traits the closure implements, and traits are how functions and structs
@@ -402,18 +407,18 @@ can specify what kinds of closures they can use. Closures will automatically
implement one, two, or all three of these `Fn` traits, in an additive fashion,
depending on how the closure’s body handles the values:
-1. `FnOnce` applies to closures that can be called once. All closures implement
- at least this trait, because all closures can be called. A closure that
- moves captured values out of its body will only implement `FnOnce` and none
- of the other `Fn` traits, because it can only be called once.
-2. `FnMut` applies to closures that don’t move captured values out of their
- body, but that might mutate the captured values. These closures can be
- called more than once.
-3. `Fn` applies to closures that don’t move captured values out of their body
- and that don’t mutate captured values, as well as closures that capture
- nothing from their environment. These closures can be called more than once
- without mutating their environment, which is important in cases such as
- calling a closure multiple times concurrently.
+* `FnOnce` applies to closures that can be called once. All closures implement
+at least this trait because all closures can be called. A closure that moves
+captured values out of its body will only implement `FnOnce` and none of the
+other `Fn` traits because it can only be called once.
+* `FnMut` applies to closures that don’t move captured values out of their
+body, but that might mutate the captured values. These closures can be called
+more than once.
+* `Fn` applies to closures that don’t move captured values out of their body
+and that don’t mutate captured values, as well as closures that capture nothing
+from their environment. These closures can be called more than once without
+mutating their environment, which is important in cases such as calling a
+closure multiple times concurrently.
Let’s look at the definition of the `unwrap_or_else` method on `Option<T>` that
we used in Listing 13-1:
@@ -444,27 +449,27 @@ the closure we provide when calling `unwrap_or_else`.
The trait bound specified on the generic type `F` is `FnOnce() -> T`, which
means `F` must be able to be called once, take no arguments, and return a `T`.
Using `FnOnce` in the trait bound expresses the constraint that
-`unwrap_or_else` is only going to call `f` at most one time. In the body of
+`unwrap_or_else` is only going to call `f` one time, at most. In the body of
`unwrap_or_else`, we can see that if the `Option` is `Some`, `f` won’t be
called. If the `Option` is `None`, `f` will be called once. Because all
-closures implement `FnOnce`, `unwrap_or_else` accepts the most different kinds
-of closures and is as flexible as it can be.
+closures implement `FnOnce`, `unwrap_or_else` accepts the largest variety of
+closures and is as flexible as it can be.
> Note: Functions can implement all three of the `Fn` traits too. If what we
-> want to do doesn’t require capturing a value from the environment, we can use
-> the name of a function rather than a closure where we need something that
-> implements one of the `Fn` traits. For example, on an `Option<Vec<T>>` value,
-> we could call `unwrap_or_else(Vec::new)` to get a new, empty vector if the
-> value is `None`.
+want to do doesn’t require capturing a value from the environment, we can use
+the name of a function rather than a closure where we need something that
+implements one of the `Fn` traits. For example, on an `Option<Vec<T>>` value,
+we could call `unwrap_or_else(Vec::new)` to get a new, empty vector if the
+value is `None`.
-Now let’s look at the standard library method `sort_by_key` defined on slices,
+Now let’s look at the standard library method `sort_by_key`, defined on slices,
to see how that differs from `unwrap_or_else` and why `sort_by_key` uses
`FnMut` instead of `FnOnce` for the trait bound. The closure gets one argument
in the form of a reference to the current item in the slice being considered,
and returns a value of type `K` that can be ordered. This function is useful
when you want to sort a slice by a particular attribute of each item. In
Listing 13-7, we have a list of `Rectangle` instances and we use `sort_by_key`
-to order them by their `width` attribute from low to high:
+to order them by their `width` attribute from low to high.
Filename: src/main.rs
@@ -510,21 +515,17 @@ This code prints:
The reason `sort_by_key` is defined to take an `FnMut` closure is that it calls
the closure multiple times: once for each item in the slice. The closure `|r|
-r.width` doesn’t capture, mutate, or move out anything from its environment, so
+r.width` doesn’t capture, mutate, or move anything out from its environment, so
it meets the trait bound requirements.
In contrast, Listing 13-8 shows an example of a closure that implements just
the `FnOnce` trait, because it moves a value out of the environment. The
-compiler won’t let us use this closure with `sort_by_key`:
+compiler won’t let us use this closure with `sort_by_key`.
Filename: src/main.rs
```
-#[derive(Debug)]
-struct Rectangle {
- width: u32,
- height: u32,
-}
+--snip--
fn main() {
let mut list = [
@@ -549,7 +550,7 @@ Listing 13-8: Attempting to use an `FnOnce` closure with `sort_by_key`
This is a contrived, convoluted way (that doesn’t work) to try and count the
number of times `sort_by_key` gets called when sorting `list`. This code
attempts to do this counting by pushing `value`—a `String` from the closure’s
-environment—into the `sort_operations` vector. The closure captures `value`
+environment—into the `sort_operations` vector. The closure captures `value` and
then moves `value` out of the closure by transferring ownership of `value` to
the `sort_operations` vector. This closure can be called once; trying to call
it a second time wouldn’t work because `value` would no longer be in the
@@ -559,7 +560,8 @@ that `value` can’t be moved out of the closure because the closure must
implement `FnMut`:
```
-error[E0507]: cannot move out of `value`, a captured variable in an `FnMut` closure
+error[E0507]: cannot move out of `value`, a captured variable in an `FnMut`
+closure
--> src/main.rs:18:30
|
15 | let value = String::from("by key called");
@@ -568,7 +570,8 @@ error[E0507]: cannot move out of `value`, a captured variable in an `FnMut` clos
17 | list.sort_by_key(|r| {
| ______________________-
18 | | sort_operations.push(value);
- | | ^^^^^ move occurs because `value` has type `String`, which does not implement the `Copy` trait
+ | | ^^^^^ move occurs because `value` has
+type `String`, which does not implement the `Copy` trait
19 | | r.width
20 | | });
| |_____- captured by this `FnMut` closure
@@ -576,39 +579,33 @@ error[E0507]: cannot move out of `value`, a captured variable in an `FnMut` clos
The error points to the line in the closure body that moves `value` out of the
environment. To fix this, we need to change the closure body so that it doesn’t
-move values out of the environment. To count the number of times `sort_by_key`
-is called, keeping a counter in the environment and incrementing its value in
-the closure body is a more straightforward way to calculate that. The closure
-in Listing 13-9 works with `sort_by_key` because it is only capturing a mutable
-reference to the `num_sort_operations` counter and can therefore be called more
-than once:
+move values out of the environment. Keeping a counter in the environment and
+incrementing its value in the closure body is a more straightforward way to
+count the number of times `sort_by_key` is called. The closure in Listing 13-9
+works with `sort_by_key` because it is only capturing a mutable reference to
+the `num_sort_operations` counter and can therefore be called more than once.
Filename: src/main.rs
```
-#[derive(Debug)]
-struct Rectangle {
- width: u32,
- height: u32,
-}
+--snip--
fn main() {
- let mut list = [
- Rectangle { width: 10, height: 1 },
- Rectangle { width: 3, height: 5 },
- Rectangle { width: 7, height: 12 },
- ];
+ --snip--
let mut num_sort_operations = 0;
list.sort_by_key(|r| {
num_sort_operations += 1;
r.width
});
- println!("{:#?}, sorted in {num_sort_operations} operations", list);
+ println!(
+ "{:#?}, sorted in {num_sort_operations} operations",
+ list
+ );
}
```
-Listing 13-9: Using an `FnMut` closure with `sort_by_key` is allowed
+Listing 13-9: Using an `FnMut` closure with `sort_by_key` is allowed.
The `Fn` traits are important when defining or using functions or types that
make use of closures. In the next section, we’ll discuss iterators. Many
@@ -637,10 +634,10 @@ let v1_iter = v1.iter();
Listing 13-10: Creating an iterator
The iterator is stored in the `v1_iter` variable. Once we’ve created an
-iterator, we can use it in a variety of ways. In Listing 3-5 in Chapter 3, we
-iterated over an array using a `for` loop to execute some code on each of its
-items. Under the hood this implicitly created and then consumed an iterator,
-but we glossed over how exactly that works until now.
+iterator, we can use it in a variety of ways. In Listing 3-5, we iterated over
+an array using a `for` loop to execute some code on each of its items. Under
+the hood, this implicitly created and then consumed an iterator, but we glossed
+over how exactly that works until now.
In the example in Listing 13-11, we separate the creation of the iterator from
the use of the iterator in the `for` loop. When the `for` loop is called using
@@ -653,7 +650,7 @@ let v1 = vec![1, 2, 3];
let v1_iter = v1.iter();
for val in v1_iter {
- println!("Got: {}", val);
+ println!("Got: {val}");
}
```
@@ -665,12 +662,12 @@ you would likely write this same functionality by starting a variable at index
incrementing the variable value in a loop until it reached the total number of
items in the vector.
-Iterators handle all that logic for you, cutting down on repetitive code you
+Iterators handle all of that logic for you, cutting down on repetitive code you
could potentially mess up. Iterators give you more flexibility to use the same
logic with many different kinds of sequences, not just data structures you can
index into, like vectors. Let’s examine how iterators do that.
-### The `Iterator` Trait and the `next` Method
+### The Iterator Trait and the next Method
All iterators implement a trait named `Iterator` that is defined in the
standard library. The definition of the trait looks like this:
@@ -685,7 +682,7 @@ pub trait Iterator {
}
```
-Notice this definition uses some new syntax: `type Item` and `Self::Item`,
+Notice that this definition uses some new syntax: `type Item` and `Self::Item`,
which are defining an *associated type* with this trait. We’ll talk about
associated types in depth in Chapter 19. For now, all you need to know is that
this code says implementing the `Iterator` trait requires that you also define
@@ -694,8 +691,8 @@ method. In other words, the `Item` type will be the type returned from the
iterator.
The `Iterator` trait only requires implementors to define one method: the
-`next` method, which returns one item of the iterator at a time wrapped in
-`Some` and, when iteration is over, returns `None`.
+`next` method, which returns one item of the iterator at a time, wrapped in
+`Some`, and, when iteration is over, returns `None`.
We can call the `next` method on iterators directly; Listing 13-12 demonstrates
what values are returned from repeated calls to `next` on the iterator created
@@ -733,7 +730,7 @@ ownership of `v1` and returns owned values, we can call `into_iter` instead of
`iter`. Similarly, if we want to iterate over mutable references, we can call
`iter_mut` instead of `iter`.
-### Methods that Consume the Iterator
+### Methods That Consume the Iterator
The `Iterator` trait has a number of different methods with default
implementations provided by the standard library; you can find out about these
@@ -742,12 +739,12 @@ trait. Some of these methods call the `next` method in their definition, which
is why you’re required to implement the `next` method when implementing the
`Iterator` trait.
-Methods that call `next` are called *consuming adaptors*, because calling them
+Methods that call `next` are called *consuming adapters* because calling them
uses up the iterator. One example is the `sum` method, which takes ownership of
the iterator and iterates through the items by repeatedly calling `next`, thus
consuming the iterator. As it iterates through, it adds each item to a running
total and returns the total when iteration is complete. Listing 13-13 has a
-test illustrating a use of the `sum` method:
+test illustrating a use of the `sum` method.
Filename: src/lib.rs
@@ -770,17 +767,17 @@ iterator
We aren’t allowed to use `v1_iter` after the call to `sum` because `sum` takes
ownership of the iterator we call it on.
-### Methods that Produce Other Iterators
+### Methods That Produce Other Iterators
-*Iterator adaptors* are methods defined on the `Iterator` trait that don’t
+*Iterator adapters* are methods defined on the `Iterator` trait that don’t
consume the iterator. Instead, they produce different iterators by changing
some aspect of the original iterator.
-Listing 13-17 shows an example of calling the iterator adaptor method `map`,
+Listing 13-14 shows an example of calling the iterator adapter method `map`,
which takes a closure to call on each item as the items are iterated through.
The `map` method returns a new iterator that produces the modified items. The
closure here creates a new iterator in which each item from the vector will be
-incremented by 1:
+incremented by 1.
Filename: src/main.rs
@@ -790,7 +787,7 @@ let v1: Vec<i32> = vec![1, 2, 3];
v1.iter().map(|x| x + 1);
```
-Listing 13-14: Calling the iterator adaptor `map` to create a new iterator
+Listing 13-14: Calling the iterator adapter `map` to create a new iterator
However, this code produces a warning:
@@ -806,17 +803,16 @@ warning: unused `Map` that must be used
```
The code in Listing 13-14 doesn’t do anything; the closure we’ve specified
-never gets called. The warning reminds us why: iterator adaptors are lazy, and
+never gets called. The warning reminds us why: iterator adapters are lazy, and
we need to consume the iterator here.
To fix this warning and consume the iterator, we’ll use the `collect` method,
-which we used in Chapter 12 with `env::args` in Listing 12-1. This method
-consumes the iterator and collects the resulting values into a collection data
-type.
+which we used with `env::args` in Listing 12-1. This method consumes the
+iterator and collects the resultant values into a collection data type.
-In Listing 13-15, we collect the results of iterating over the iterator that’s
-returned from the call to `map` into a vector. This vector will end up
-containing each item from the original vector incremented by 1.
+In Listing 13-15, we collect into a vector the results of iterating over the
+iterator that’s returned from the call to `map`. This vector will end up
+containing each item from the original vector, incremented by 1.
Filename: src/main.rs
@@ -828,7 +824,7 @@ let v2: Vec<_> = v1.iter().map(|x| x + 1).collect();
assert_eq!(v2, vec![2, 3, 4]);
```
-Listing 13-15: Calling the `map` method to create a new iterator and then
+Listing 13-15: Calling the `map` method to create a new iterator, and then
calling the `collect` method to consume the new iterator and create a vector
Because `map` takes a closure, we can specify any operation we want to perform
@@ -836,11 +832,11 @@ on each item. This is a great example of how closures let you customize some
behavior while reusing the iteration behavior that the `Iterator` trait
provides.
-You can chain multiple calls to iterator adaptors to perform complex actions in
+You can chain multiple calls to iterator adapters to perform complex actions in
a readable way. But because all iterators are lazy, you have to call one of the
-consuming adaptor methods to get results from calls to iterator adaptors.
+consuming adapter methods to get results from calls to iterator adapters.
-### Using Closures that Capture Their Environment
+### Using Closures That Capture Their Environment
Many iterator adapters take closures as arguments, and commonly the closures
we’ll specify as arguments to iterator adapters will be closures that capture
@@ -915,18 +911,18 @@ The `shoes_in_size` function takes ownership of a vector of shoes and a shoe
size as parameters. It returns a vector containing only shoes of the specified
size.
-In the body of `shoes_in_size`, we call `into_iter` to create an iterator
-that takes ownership of the vector. Then we call `filter` to adapt that
-iterator into a new iterator that only contains elements for which the closure
-returns `true`.
+In the body of `shoes_in_size`, we call `into_iter` to create an iterator that
+takes ownership of the vector. Then we call `filter` to adapt that iterator
+into a new iterator that only contains elements for which the closure returns
+`true`.
The closure captures the `shoe_size` parameter from the environment and
compares the value with each shoe’s size, keeping only shoes of the size
specified. Finally, calling `collect` gathers the values returned by the
adapted iterator into a vector that’s returned by the function.
-The test shows that when we call `shoes_in_size`, we get back only shoes
-that have the same size as the value we specified.
+The test shows that when we call `shoes_in_size`, we get back only shoes that
+have the same size as the value we specified.
## Improving Our I/O Project
@@ -935,19 +931,21 @@ Chapter 12 by using iterators to make places in the code clearer and more
concise. Let’s look at how iterators can improve our implementation of the
`Config::build` function and the `search` function.
-### Removing a `clone` Using an Iterator
+### Removing a clone Using an Iterator
In Listing 12-6, we added code that took a slice of `String` values and created
an instance of the `Config` struct by indexing into the slice and cloning the
values, allowing the `Config` struct to own those values. In Listing 13-17,
we’ve reproduced the implementation of the `Config::build` function as it was
-in Listing 12-23:
+in Listing 12-23.
Filename: src/lib.rs
```
impl Config {
- pub fn build(args: &[String]) -> Result<Config, &'static str> {
+ pub fn build(
+ args: &[String]
+ ) -> Result<Config, &'static str> {
if args.len() < 3 {
return Err("not enough arguments");
}
@@ -1001,7 +999,7 @@ fn main() {
process::exit(1);
});
- // --snip--
+ --snip--
}
```
@@ -1013,12 +1011,13 @@ Filename: src/main.rs
```
fn main() {
- let config = Config::build(env::args()).unwrap_or_else(|err| {
- eprintln!("Problem parsing arguments: {err}");
- process::exit(1);
- });
+ let config =
+ Config::build(env::args()).unwrap_or_else(|err| {
+ eprintln!("Problem parsing arguments: {err}");
+ process::exit(1);
+ });
- // --snip--
+ --snip--
}
```
@@ -1031,8 +1030,8 @@ we’re passing ownership of the iterator returned from `env::args` to
Next, we need to update the definition of `Config::build`. In your I/O
project’s *src/lib.rs* file, let’s change the signature of `Config::build` to
-look like Listing 13-19. This still won’t compile because we need to update the
-function body.
+look like Listing 13-19. This still won’t compile, because we need to update
+the function body.
Filename: src/lib.rs
@@ -1041,7 +1040,7 @@ impl Config {
pub fn build(
mut args: impl Iterator<Item = String>,
) -> Result<Config, &'static str> {
- // --snip--
+ --snip--
```
Listing 13-19: Updating the signature of `Config::build` to expect an iterator
@@ -1053,18 +1052,18 @@ the `Iterator` trait and returns `String` values.
We’ve updated the signature of the `Config::build` function so the parameter
`args` has a generic type with the trait bounds `impl Iterator<Item = String>`
instead of `&[String]`. This usage of the `impl Trait` syntax we discussed in
-the “Traits as Parameters†section of Chapter 10 means that `args` can be any
-type that implements the `Iterator` type and returns `String` items.
+“Traits as Parameters†on page XX means that `args` can be any type that
+implements the `Iterator` type and returns `String` items.
Because we’re taking ownership of `args` and we’ll be mutating `args` by
iterating over it, we can add the `mut` keyword into the specification of the
`args` parameter to make it mutable.
-#### Using `Iterator` Trait Methods Instead of Indexing
+#### Using Iterator Trait Methods Instead of Indexing
Next, we’ll fix the body of `Config::build`. Because `args` implements the
`Iterator` trait, we know we can call the `next` method on it! Listing 13-20
-updates the code from Listing 12-23 to use the `next` method:
+updates the code from Listing 12-23 to use the `next` method.
Filename: src/lib.rs
@@ -1100,21 +1099,24 @@ Listing 13-20: Changing the body of `Config::build` to use iterator methods
Remember that the first value in the return value of `env::args` is the name of
the program. We want to ignore that and get to the next value, so first we call
-`next` and do nothing with the return value. Second, we call `next` to get the
-value we want to put in the `query` field of `Config`. If `next` returns a
+`next` and do nothing with the return value. Then we call `next` to get the
+value we want to put in the `query` field of `Config`. If `next` returns
`Some`, we use a `match` to extract the value. If it returns `None`, it means
not enough arguments were given and we return early with an `Err` value. We do
the same thing for the `filename` value.
-### Making Code Clearer with Iterator Adaptors
+### Making Code Clearer with Iterator Adapters
We can also take advantage of iterators in the `search` function in our I/O
-project, which is reproduced here in Listing 13-21 as it was in Listing 12-19:
+project, which is reproduced here in Listing 13-21 as it was in Listing 12-19.
Filename: src/lib.rs
```
-pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
+pub fn search<'a>(
+ query: &str,
+ contents: &'a str,
+) -> Vec<&'a str> {
let mut results = Vec::new();
for line in contents.lines() {
@@ -1129,17 +1131,20 @@ pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
Listing 13-21: The implementation of the `search` function from Listing 12-19
-We can write this code in a more concise way using iterator adaptor methods.
+We can write this code in a more concise way using iterator adapter methods.
Doing so also lets us avoid having a mutable intermediate `results` vector. The
functional programming style prefers to minimize the amount of mutable state to
make code clearer. Removing the mutable state might enable a future enhancement
-to make searching happen in parallel, because we wouldn’t have to manage
-concurrent access to the `results` vector. Listing 13-22 shows this change:
+to make searching happen in parallel because we wouldn’t have to manage
+concurrent access to the `results` vector. Listing 13-22 shows this change.
Filename: src/lib.rs
```
-pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
+pub fn search<'a>(
+ query: &str,
+ contents: &'a str,
+) -> Vec<&'a str> {
contents
.lines()
.filter(|line| line.contains(query))
@@ -1147,24 +1152,23 @@ pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
}
```
-Listing 13-22: Using iterator adaptor methods in the implementation of the
+Listing 13-22: Using iterator adapter methods in the implementation of the
`search` function
Recall that the purpose of the `search` function is to return all lines in
`contents` that contain the `query`. Similar to the `filter` example in Listing
-13-16, this code uses the `filter` adaptor to keep only the lines that
-`line.contains(query)` returns `true` for. We then collect the matching lines
-into another vector with `collect`. Much simpler! Feel free to make the same
-change to use iterator methods in the `search_case_insensitive` function as
-well.
+13-16, this code uses the `filter` adapter to keep only the lines for which
+`line.contains(query)` returns `true`. We then collect the matching lines into
+another vector with `collect`. Much simpler! Feel free to make the same change
+to use iterator methods in the `search_case_insensitive` function as well.
-### Choosing Between Loops or Iterators
+### Choosing Between Loops and Iterators
The next logical question is which style you should choose in your own code and
why: the original implementation in Listing 13-21 or the version using
iterators in Listing 13-22. Most Rust programmers prefer to use the iterator
style. It’s a bit tougher to get the hang of at first, but once you get a feel
-for the various iterator adaptors and what they do, iterators can be easier to
+for the various iterator adapters and what they do, iterators can be easier to
understand. Instead of fiddling with the various bits of looping and building
new vectors, the code focuses on the high-level objective of the loop. This
abstracts away some of the commonplace code so it’s easier to see the concepts
@@ -1172,8 +1176,7 @@ that are unique to this code, such as the filtering condition each element in
the iterator must pass.
But are the two implementations truly equivalent? The intuitive assumption
-might be that the more low-level loop will be faster. Let’s talk about
-performance.
+might be that the lower-level loop will be faster. Let’s talk about performance.
## Comparing Performance: Loops vs. Iterators
@@ -1192,8 +1195,8 @@ test bench_search_iter ... bench: 19,234,900 ns/iter (+/- 657,200)
```
The iterator version was slightly faster! We won’t explain the benchmark code
-here, because the point is not to prove that the two versions are equivalent
-but to get a general sense of how these two implementations compare
+here because the point is not to prove that the two versions are equivalent but
+to get a general sense of how these two implementations compare
performance-wise.
For a more comprehensive benchmark, you should check using various texts of
@@ -1201,24 +1204,22 @@ various sizes as the `contents`, different words and words of different lengths
as the `query`, and all kinds of other variations. The point is this:
iterators, although a high-level abstraction, get compiled down to roughly the
same code as if you’d written the lower-level code yourself. Iterators are one
-of Rust’s *zero-cost abstractions*, by which we mean using the abstraction
+of Rust’s *zero-cost abstractions*, by which we mean that using the abstraction
imposes no additional runtime overhead. This is analogous to how Bjarne
Stroustrup, the original designer and implementor of C++, defines
*zero-overhead* in “Foundations of C++†(2012):
> In general, C++ implementations obey the zero-overhead principle: What you
-> don’t use, you don’t pay for. And further: What you do use, you couldn’t hand
-> code any better.
-
-As another example, the following code is taken from an audio decoder. The
-decoding algorithm uses the linear prediction mathematical operation to
-estimate future values based on a linear function of the previous samples. This
-code uses an iterator chain to do some math on three variables in scope: a
-`buffer` slice of data, an array of 12 `coefficients`, and an amount by which
-to shift data in `qlp_shift`. We’ve declared the variables within this example
-but not given them any values; although this code doesn’t have much meaning
-outside of its context, it’s still a concise, real-world example of how Rust
-translates high-level ideas to low-level code.
+don’t use, you don’t pay for. And further: What you do use, you couldn’t hand
+code any better.As another example, the following code is taken from an audio
+decoder. The decoding algorithm uses the linear prediction mathematical
+operation to estimate future values based on a linear function of the previous
+samples. This code uses an iterator chain to do some math on three variables in
+scope: a `buffer` slice of data, an array of 12 `coefficients`, and an amount
+by which to shift data in `qlp_shift`. We’ve declared the variables within this
+example but not given them any values; although this code doesn’t have much
+meaning outside of its context, it’s still a concise, real-world example of how
+Rust translates high-level ideas to low-level code.
```
let buffer: &mut [i32];
@@ -1237,12 +1238,12 @@ for i in 12..buffer.len() {
To calculate the value of `prediction`, this code iterates through each of the
12 values in `coefficients` and uses the `zip` method to pair the coefficient
-values with the previous 12 values in `buffer`. Then, for each pair, we
-multiply the values together, sum all the results, and shift the bits in the
-sum `qlp_shift` bits to the right.
+values with the previous 12 values in `buffer`. Then, for each pair, it
+multiplies the values together, sums all the results, and shifts the bits in
+the sum `qlp_shift` bits to the right.
Calculations in applications like audio decoders often prioritize performance
-most highly. Here, we’re creating an iterator, using two adaptors, and then
+most highly. Here, we’re creating an iterator, using two adapters, and then
consuming the value. What assembly code would this Rust code compile to? Well,
as of this writing, it compiles down to the same assembly you’d write by hand.
There’s no loop at all corresponding to the iteration over the values in
@@ -1253,7 +1254,7 @@ the loop.
All of the coefficients get stored in registers, which means accessing the
values is very fast. There are no bounds checks on the array access at runtime.
-All these optimizations that Rust is able to apply make the resulting code
+All of these optimizations that Rust is able to apply make the resultant code
extremely efficient. Now that you know this, you can use iterators and closures
without fear! They make code seem like it’s higher level but don’t impose a
runtime performance penalty for doing so.
@@ -1269,3 +1270,4 @@ Rust’s goal to strive to provide zero-cost abstractions.
Now that we’ve improved the expressiveness of our I/O project, let’s look at
some more features of `cargo` that will help us share the project with the
world.
+
diff --git a/src/doc/book/nostarch/chapter14.md b/src/doc/book/nostarch/chapter14.md
index 076410232..f5f2be719 100644
--- a/src/doc/book/nostarch/chapter14.md
+++ b/src/doc/book/nostarch/chapter14.md
@@ -8,19 +8,19 @@ directory, so all fixes need to be made in `/src/`.
# More About Cargo and Crates.io
-So far we’ve used only the most basic features of Cargo to build, run, and test
-our code, but it can do a lot more. In this chapter, we’ll discuss some of its
-other, more advanced features to show you how to do the following:
+So far, we’ve used only the most basic features of Cargo to build, run, and
+test our code, but it can do a lot more. In this chapter, we’ll discuss some of
+its other, more advanced features to show you how to do the following:
-* Customize your build through release profiles
-* Publish libraries on *https://crates.io/*
-* Organize large projects with workspaces
-* Install binaries from *https://crates.io/*
-* Extend Cargo using custom commands
+* Customize your build through release profiles.
+* Publish libraries on *https://crates.i**o*.
+* Organize large projects with workspaces.
+* Install binaries from *https://crates.io*.
+* Extend Cargo using custom commands.
Cargo can do even more than the functionality we cover in this chapter, so for
a full explanation of all its features, see its documentation at
-*https://doc.rust-lang.org/cargo/*.
+*https://doc.rust-lang.org/cargo*.
## Customizing Builds with Release Profiles
@@ -30,7 +30,7 @@ various options for compiling code. Each profile is configured independently of
the others.
Cargo has two main profiles: the `dev` profile Cargo uses when you run `cargo
-build` and the `release` profile Cargo uses when you run `cargo build
+build`, and the `release` profile Cargo uses when you run `cargo build
--release`. The `dev` profile is defined with good defaults for development,
and the `release` profile has good defaults for release builds.
@@ -45,7 +45,7 @@ $ cargo build --release
The `dev` and `release` are these different profiles used by the compiler.
-Cargo has default settings for each of the profiles that apply when you haven't
+Cargo has default settings for each of the profiles that apply when you haven’t
explicitly added any `[profile.*]` sections in the project’s *Cargo.toml* file.
By adding `[profile.*]` sections for any profile you want to customize, you
override any subset of the default settings. For example, here are the default
@@ -64,7 +64,7 @@ opt-level = 3
The `opt-level` setting controls the number of optimizations Rust will apply to
your code, with a range of 0 to 3. Applying more optimizations extends
compiling time, so if you’re in development and compiling your code often,
-you’ll want fewer optimizations to compile faster even if the resulting code
+you’ll want fewer optimizations to compile faster even if the resultant code
runs slower. The default `opt-level` for `dev` is therefore `0`. When you’re
ready to release your code, it’s best to spend more time compiling. You’ll only
compile in release mode once, but you’ll run the compiled program many times,
@@ -89,11 +89,12 @@ Cargo will use the defaults for the `dev` profile plus our customization to
optimizations than the default, but not as many as in a release build.
For the full list of configuration options and defaults for each profile, see
-Cargo’s documentation at *https://doc.rust-lang.org/cargo/reference/profiles.html*.
+Cargo’s documentation at
+*https://doc.rust-lang.org/cargo/reference/profiles.html*.
## Publishing a Crate to Crates.io
-We’ve used packages from *https://crates.io/* as dependencies of our project,
+We’ve used packages from *https://crates.io* as dependencies of our project,
but you can also share your code with other people by publishing your own
packages. The crate registry at *https://crates.io* distributes the source code
of your packages, so it primarily hosts code that is open source.
@@ -120,7 +121,7 @@ for an `add_one` function in a crate named `my_crate`.
Filename: src/lib.rs
-````
+```
/// Adds one to the number given.
///
/// # Examples
@@ -134,17 +135,10 @@ Filename: src/lib.rs
pub fn add_one(x: i32) -> i32 {
x + 1
}
-````
+```
Listing 14-1: A documentation comment for a function
-<!-- I removed two sets of ``` here because it was inverting the text and code
-formatting, but you may want to check that I have't changed meaning in the
-code! /LC -->
-<!-- Yeah, those need to be in there. It's definitely weird that it's a code
-block inside of a code block-- I think I've fixed it by adding more ` around
-the outer block, but I'll check it again when we're in Word. /Carol -->
-
Here, we give a description of what the `add_one` function does, start a
section with the heading `Examples`, and then provide code that demonstrates
how to use the `add_one` function. We can generate the HTML documentation from
@@ -156,9 +150,7 @@ For convenience, running `cargo doc --open` will build the HTML for your
current crate’s documentation (as well as the documentation for all of your
crate’s dependencies) and open the result in a web browser. Navigate to the
`add_one` function and you’ll see how the text in the documentation comments is
-rendered, as shown in Figure 14-1:
-
-<img alt="Rendered HTML documentation for the `add_one` function of `my_crate`" src="img/trpl14-01.png" class="center" />
+rendered, as shown in Figure 14-1.
Figure 14-1: HTML documentation for the `add_one` function
@@ -168,16 +160,16 @@ We used the `# Examples` Markdown heading in Listing 14-1 to create a section
in the HTML with the title “Examples.†Here are some other sections that crate
authors commonly use in their documentation:
-* **Panics**: The scenarios in which the function being documented could
- panic. Callers of the function who don’t want their programs to panic should
- make sure they don’t call the function in these situations.
+* **Panics**: The scenarios in which the function being documented could panic.
+Callers of the function who don’t want their programs to panic should make sure
+they don’t call the function in these situations.
* **Errors**: If the function returns a `Result`, describing the kinds of
- errors that might occur and what conditions might cause those errors to be
- returned can be helpful to callers so they can write code to handle the
- different kinds of errors in different ways.
+errors that might occur and what conditions might cause those errors to be
+returned can be helpful to callers so they can write code to handle the
+different kinds of errors in different ways.
* **Safety**: If the function is `unsafe` to call (we discuss unsafety in
- Chapter 19), there should be a section explaining why the function is unsafe
- and covering the invariants that the function expects callers to uphold.
+Chapter 19), there should be a section explaining why the function is unsafe
+and covering the invariants that the function expects callers to uphold.
Most documentation comments don’t need all of these sections, but this is a
good checklist to remind you of the aspects of your code users will be
@@ -191,7 +183,8 @@ test` will run the code examples in your documentation as tests! Nothing is
better than documentation with examples. But nothing is worse than examples
that don’t work because the code has changed since the documentation was
written. If we run `cargo test` with the documentation for the `add_one`
-function from Listing 14-1, we will see a section in the test results like this:
+function from Listing 14-1, we will see a section in the test results that
+looks like this:
```
Doc-tests my_crate
@@ -199,35 +192,36 @@ function from Listing 14-1, we will see a section in the test results like this:
running 1 test
test src/lib.rs - add_one (line 5) ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.27s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
+filtered out; finished in 0.27s
```
-Now if we change either the function or the example so the `assert_eq!` in the
+Now, if we change either the function or the example so the `assert_eq!` in the
example panics and run `cargo test` again, we’ll see that the doc tests catch
that the example and the code are out of sync with each other!
#### Commenting Contained Items
-The style of doc comment `//!` adds documentation to the item that contains the
-comments rather than to the items following the comments. We typically use
+The doc comment `//!` adds documentation to the item that *contains* the
+comments rather than to the items *following* the comments. We typically use
these doc comments inside the crate root file (*src/lib.rs* by convention) or
inside a module to document the crate or the module as a whole.
For example, to add documentation that describes the purpose of the `my_crate`
crate that contains the `add_one` function, we add documentation comments that
start with `//!` to the beginning of the *src/lib.rs* file, as shown in Listing
-14-2:
+14-2.
Filename: src/lib.rs
```
//! # My Crate
//!
-//! `my_crate` is a collection of utilities to make performing certain
-//! calculations more convenient.
+//! `my_crate` is a collection of utilities to make performing
+//! certain calculations more convenient.
/// Adds one to the number given.
-// --snip--
+--snip--
```
Listing 14-2: Documentation for the `my_crate` crate as a whole
@@ -238,11 +232,9 @@ that contains this comment rather than an item that follows this comment. In
this case, that item is the *src/lib.rs* file, which is the crate root. These
comments describe the entire crate.
-When we run `cargo doc --open`, these comments will display on the front
-page of the documentation for `my_crate` above the list of public items in the
-crate, as shown in Figure 14-2:
-
-<img alt="Rendered HTML documentation with a comment for the crate as a whole" src="img/trpl14-02.png" class="center" />
+When we run `cargo doc --open`, these comments will display on the front page
+of the documentation for `my_crate` above the list of public items in the
+crate, as shown in Figure 14-2.
Figure 14-2: Rendered documentation for `my_crate`, including the comment
describing the crate as a whole
@@ -251,7 +243,7 @@ Documentation comments within items are useful for describing crates and
modules especially. Use them to explain the overall purpose of the container to
help your users understand the crate’s organization.
-### Exporting a Convenient Public API with `pub use`
+### Exporting a Convenient Public API with pub use
The structure of your public API is a major consideration when publishing a
crate. People who use your crate are less familiar with the structure than you
@@ -259,26 +251,26 @@ are and might have difficulty finding the pieces they want to use if your crate
has a large module hierarchy.
In Chapter 7, we covered how to make items public using the `pub` keyword, and
-bring items into a scope with the `use` keyword. However, the structure that
-makes sense to you while you’re developing a crate might not be very convenient
-for your users. You might want to organize your structs in a hierarchy
-containing multiple levels, but then people who want to use a type you’ve
-defined deep in the hierarchy might have trouble finding out that type exists.
-They might also be annoyed at having to enter `use`
-`my_crate::some_module::another_module::UsefulType;` rather than `use`
-`my_crate::UsefulType;`.
+how to bring items into a scope with the `use` keyword. However, the structure
+that makes sense to you while you’re developing a crate might not be very
+convenient for your users. You might want to organize your structs in a
+hierarchy containing multiple levels, but then people who want to use a type
+you’ve defined deep in the hierarchy might have trouble finding out that type
+exists. They might also be annoyed at having to enter `use`
+`my_crate::`some_module`::`another_module`::`UsefulType`;` rather than `use`
+`my_crate::`UsefulType`;`.
The good news is that if the structure *isn’t* convenient for others to use
from another library, you don’t have to rearrange your internal organization:
instead, you can re-export items to make a public structure that’s different
-from your private structure by using `pub use`. Re-exporting takes a public
+from your private structure by using `pub use`. *Re-exporting* takes a public
item in one location and makes it public in another location, as if it were
defined in the other location instead.
For example, say we made a library named `art` for modeling artistic concepts.
Within this library are two modules: a `kinds` module containing two enums
named `PrimaryColor` and `SecondaryColor` and a `utils` module containing a
-function named `mix`, as shown in Listing 14-3:
+function named `mix`, as shown in Listing 14-3.
Filename: src/lib.rs
@@ -308,8 +300,11 @@ pub mod utils {
/// Combines two primary colors in equal amounts to create
/// a secondary color.
- pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
- // --snip--
+ pub fn mix(
+ c1: PrimaryColor,
+ c2: PrimaryColor,
+ ) -> SecondaryColor {
+ --snip--
}
}
```
@@ -318,9 +313,7 @@ Listing 14-3: An `art` library with items organized into `kinds` and `utils`
modules
Figure 14-3 shows what the front page of the documentation for this crate
-generated by `cargo doc` would look like:
-
-<img alt="Rendered documentation for the `art` crate that lists the `kinds` and `utils` modules" src="img/trpl14-03.png" class="center" />
+generated by `cargo doc` would look like.
Figure 14-3: Front page of the documentation for `art` that lists the `kinds`
and `utils` modules
@@ -332,7 +325,7 @@ see them.
Another crate that depends on this library would need `use` statements that
bring the items from `art` into scope, specifying the module structure that’s
currently defined. Listing 14-4 shows an example of a crate that uses the
-`PrimaryColor` and `mix` items from the `art` crate:
+`PrimaryColor` and `mix` items from the `art` crate.
Filename: src/main.rs
@@ -361,7 +354,7 @@ module names in the `use` statements.
To remove the internal organization from the public API, we can modify the
`art` crate code in Listing 14-3 to add `pub use` statements to re-export the
-items at the top level, as shown in Listing 14-5:
+items at the top level, as shown in Listing 14-5.
Filename: src/lib.rs
@@ -375,37 +368,26 @@ pub use self::kinds::SecondaryColor;
pub use self::utils::mix;
pub mod kinds {
- // --snip--
+ --snip--
}
pub mod utils {
- // --snip--
+ --snip--
}
```
-<!-- The example feels a tiny bit awkward. If you're
-going to use `pub use`, in my experience it's probably going
-to happen when you're pulling in definitions from sub-crates.
-In this one, we create modules that we export and also
-re-export symbols from those same modules. In practice,
-you'd probably use sub-crates or move the definitions around. /JT -->
-<!-- I don't want to get into sub-crates here, but I've added a sentence about
-this common usage in the second-to-last paragraph of this section. /Carol -->
-
Listing 14-5: Adding `pub use` statements to re-export items
The API documentation that `cargo doc` generates for this crate will now list
and link re-exports on the front page, as shown in Figure 14-4, making the
`PrimaryColor` and `SecondaryColor` types and the `mix` function easier to find.
-<img alt="Rendered documentation for the `art` crate with the re-exports on the front page" src="img/trpl14-04.png" class="center" />
-
-Figure 14-4: The front page of the documentation for `art`
-that lists the re-exports
+Figure 14-4: The front page of the documentation for `art` that lists the
+re-exports
The `art` crate users can still see and use the internal structure from Listing
14-3 as demonstrated in Listing 14-4, or they can use the more convenient
-structure in Listing 14-5, as shown in Listing 14-6:
+structure in Listing 14-5, as shown in Listing 14-6.
Filename: src/main.rs
@@ -414,7 +396,7 @@ use art::mix;
use art::PrimaryColor;
fn main() {
- // --snip--
+ --snip--
}
```
@@ -423,7 +405,7 @@ Listing 14-6: A program using the re-exported items from the `art` crate
In cases where there are many nested modules, re-exporting the types at the top
level with `pub use` can make a significant difference in the experience of
people who use the crate. Another common use of `pub use` is to re-export
-definitions of a dependency in the current crate to make that crate's
+definitions of a dependency in the current crate to make that crate’s
definitions part of your crate’s public API.
Creating a useful public API structure is more of an art than a science, and
@@ -436,11 +418,11 @@ differs from their public API.
### Setting Up a Crates.io Account
Before you can publish any crates, you need to create an account on
-*https://crates.io/* and get an API token. To do so, visit the home page at
-*https://crates.io/* and log in via a GitHub account. (The GitHub account is
+*https://crates.io* and get an API token. To do so, visit the home page at
+*https://crates.io* and log in via a GitHub account. (The GitHub account is
currently a requirement, but the site might support other ways of creating an
account in the future.) Once you’re logged in, visit your account settings at
-*https://crates.io/me/* and retrieve your API key. Then run the `cargo login`
+*https://crates.io/me* and retrieve your API key. Then run the `cargo login`
command with your API key, like this:
```
@@ -450,7 +432,7 @@ $ cargo login abcdefghijklmnopqrstuvwxyz012345
This command will inform Cargo of your API token and store it locally in
*~/.cargo/credentials*. Note that this token is a *secret*: do not share it
with anyone else. If you do share it with anyone for any reason, you should
-revoke it and generate a new token on *https://crates.io/*.
+revoke it and generate a new token on *https://crates.io*.
### Adding Metadata to a New Crate
@@ -460,7 +442,7 @@ file.
Your crate will need a unique name. While you’re working on a crate locally,
you can name a crate whatever you’d like. However, crate names on
-*https://crates.io/* are allocated on a first-come, first-served basis. Once a
+*https://crates.io* are allocated on a first-come, first-served basis. Once a
crate name is taken, no one else can publish a crate with that name. Before
attempting to publish a crate, search for the name you want to use. If the name
has been used, you will need to find another name and edit the `name` field in
@@ -480,22 +462,26 @@ the crate at this point, you’ll get a warning and then an error:
```
$ cargo publish
Updating crates.io index
-warning: manifest has no description, license, license-file, documentation, homepage or repository.
-See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
+warning: manifest has no description, license, license-file, documentation,
+homepage or repository.
+See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata
+for more info.
--snip--
error: failed to publish to registry at https://crates.io
Caused by:
- the remote server responded with an error: missing or empty metadata fields: description, license. Please see https://doc.rust-lang.org/cargo/reference/manifest.html for how to upload metadata
-```
-
-This errors because you’re missing some crucial information: a description and
-license are required so people will know what your crate does and under what
-terms they can use it. In *Cargo.toml*, add a description that's just a
-sentence or two, because it will appear with your crate in search results. For
-the `license` field, you need to give a *license identifier value*. The Linux
-Foundation’s Software Package Data Exchange (SPDX) at
-*http://spdx.org/licenses/* lists the identifiers you can use for this value.
+ the remote server responded with an error: missing or empty metadata fields:
+description, license. Please see https://doc.rust-
+lang.org/cargo/reference/manifest.html for how to upload metadata
+```
+
+This results in an error because you’re missing some crucial information: a
+description and license are required so people will know what your crate does
+and under what terms they can use it. In *Cargo.toml*, add a description that’s
+just a sentence or two, because it will appear with your crate in search
+results. For the `license` field, you need to give a *license identifier
+value*. The Linux Foundation’s Software Package Data Exchange (SPDX) at
+*http://spdx.org/licenses* lists the identifiers you can use for this value.
For example, to specify that you’ve licensed your crate using the MIT License,
add the `MIT` identifier:
@@ -528,27 +514,28 @@ Filename: Cargo.toml
name = "guessing_game"
version = "0.1.0"
edition = "2021"
-description = "A fun game where you guess what number the computer has chosen."
+description = "A fun game where you guess what number the
+computer has chosen."
license = "MIT OR Apache-2.0"
[dependencies]
```
-Cargo’s documentation at *https://doc.rust-lang.org/cargo/* describes other
-metadata you can specify to ensure others can discover and use your crate more
-easily.
+Cargo’s documentation at *https://doc.rust-lang.org/cargo* describes other
+metadata you can specify to ensure that others can discover and use your crate
+more easily.
### Publishing to Crates.io
Now that you’ve created an account, saved your API token, chosen a name for
your crate, and specified the required metadata, you’re ready to publish!
-Publishing a crate uploads a specific version to *https://crates.io/* for
-others to use.
+Publishing a crate uploads a specific version to *https://crates.io* for others
+to use.
Be careful, because a publish is *permanent*. The version can never be
-overwritten, and the code cannot be deleted. One major goal of crates.io is to
+overwritten, and the code cannot be deleted. One major goal of Crates.io is to
act as a permanent archive of code so that builds of all projects that depend
-on crates from *https://crates.io/* will continue to work. Allowing version
+on crates from *https://crates.io* will continue to work. Allowing version
deletions would make fulfilling that goal impossible. However, there is no
limit to the number of crate versions you can publish.
@@ -572,53 +559,33 @@ anyone can easily add your crate as a dependency of their project.
When you’ve made changes to your crate and are ready to release a new version,
you change the `version` value specified in your *Cargo.toml* file and
-republish. Use the Semantic Versioning rules at *http://semver.org/* to decide
-what an appropriate next version number is based on the kinds of changes you’ve
-made. Then run `cargo publish` to upload the new version.
+republish. Use the Semantic Versioning rules at *http://semver.org* to decide
+what an appropriate next version number is, based on the kinds of changes
+you’ve made. Then run `cargo publish` to upload the new version.
-### Deprecating Versions from Crates.io with `cargo yank`
+### Deprecating Versions from Crates.io with cargo yank
Although you can’t remove previous versions of a crate, you can prevent any
future projects from adding them as a new dependency. This is useful when a
crate version is broken for one reason or another. In such situations, Cargo
-supports *yanking* a crate version.
+supports yanking a crate version.
-Yanking a version prevents new projects from depending on that version while
+*Yanking* a version prevents new projects from depending on that version while
allowing all existing projects that depend on it to continue. Essentially, a
yank means that all projects with a *Cargo.lock* will not break, and any future
*Cargo.lock* files generated will not use the yanked version.
To yank a version of a crate, in the directory of the crate that you’ve
previously published, run `cargo yank` and specify which version you want to
-yank. For example, if we've published a crate named `guessing_game` version
-1.0.1 and we want to yank it, in the project directory for `guessing_game` we'd
+yank. For example, if we’ve published a crate named `guessing_game` version
+1.0.1 and we want to yank it, in the project directory for `guessing_game` we’d
run:
```
$ cargo yank --vers 1.0.1
Updating crates.io index
- Yank guessing_game:1.0.1
-```
-
-<!-- so we run this on a crate, then load that crate onto crates.io? Or does
-this go in a file that's part of the new crate version? /LC -->
-<!-- No, this is a command to run in the directory of a crate that has already
-been published to crates.io. Do you have suggestions on how to make this
-clearer? I've tried a bit above /Carol -->
-<!-- Ah, I see! I think this is clear. JT, does this read okay to you? /LC -->
-<!-- I think this makes sense. Maybe you could make it clear in the example
-that you're in the project directory?
-
-```
-my_project> cargo yank --vers 1.0.1
+ Yank guessing_game@1.0.1
```
-and then show the message that cargo returns when the version is yanked to
-help key them in.
-/JT -->
-<!-- We haven't used that notation anywhere else in the book, of showing the
-current directory in the prompt. I think showing the output is a good idea
-though, so I've added that above and made the introduction to the scenario more
-concrete. /Carol-->
By adding `--undo` to the command, you can also undo a yank and allow projects
to start depending on a version again:
@@ -626,7 +593,7 @@ to start depending on a version again:
```
$ cargo yank --vers 1.0.1 --undo
Updating crates.io index
- Unyank guessing_game_:1.0.1
+ Unyank guessing_game@1.0.1
```
A yank *does not* delete any code. It cannot, for example, delete accidentally
@@ -645,10 +612,10 @@ help manage multiple related packages that are developed in tandem.
A *workspace* is a set of packages that share the same *Cargo.lock* and output
directory. Let’s make a project using a workspace—we’ll use trivial code so we
can concentrate on the structure of the workspace. There are multiple ways to
-structure a workspace, so we'll just show one common way. We’ll have a
+structure a workspace, so we’ll just show one common way. We’ll have a
workspace containing a binary and two libraries. The binary, which will provide
the main functionality, will depend on the two libraries. One library will
-provide an `add_one` function, and a second library an `add_two` function.
+provide an `add_one` function and the other library an `add_two` function.
These three crates will be part of the same workspace. We’ll start by creating
a new directory for the workspace:
@@ -663,14 +630,6 @@ Instead, it will start with a `[workspace]` section that will allow us to add
members to the workspace by specifying the path to the package with our binary
crate; in this case, that path is *adder*:
-<!-- You can have metadata in the top-level Cargo.toml along with the
-`[workspace]` section. We use this in Nushell, for example:
-
-https://github.com/nushell/nushell/blob/main/Cargo.toml
-
- /JT -->
-<!-- Fixed! /Carol -->
-
Filename: Cargo.toml
```
@@ -764,8 +723,8 @@ pub fn add_one(x: i32) -> i32 {
```
Now we can have the `adder` package with our binary depend on the `add_one`
-package that has our library. First, we’ll need to add a path dependency on
-`add_one` to *adder/Cargo.toml*.
+package that has our library. First we’ll need to add a path dependency on
+`add_one` to *adder/Cargo.toml*:
Filename: adder/Cargo.toml
@@ -808,9 +767,9 @@ $ cargo build
Finished dev [unoptimized + debuginfo] target(s) in 0.68s
```
-To run the binary crate from the *add* directory, we can specify which
-package in the workspace we want to run by using the `-p` argument and the
-package name with `cargo run`:
+To run the binary crate from the *add* directory, we can specify which package
+in the workspace we want to run by using the `-p` argument and the package name
+with `cargo run`:
```
$ cargo run -p adder
@@ -837,7 +796,7 @@ Filename: add_one/Cargo.toml
```
[dependencies]
-rand = "0.8.3"
+rand = "0.8.5"
```
We can now add `use rand;` to the *add_one/src/lib.rs* file, and building the
@@ -848,20 +807,10 @@ referring to the `rand` we brought into scope:
```
$ cargo build
Updating crates.io index
- Downloaded rand v0.8.3
+ Downloaded rand v0.8.5
--snip--
- Compiling rand v0.8.3
+ Compiling rand v0.8.5
Compiling add_one v0.1.0 (file:///projects/add/add_one)
-warning: unused import: `rand`
- --> add_one/src/lib.rs:1:5
- |
-1 | use rand;
- | ^^^^
- |
- = note: `#[warn(unused_imports)]` on by default
-
-warning: 1 warning emitted
-
Compiling adder v0.1.0 (file:///projects/add/adder)
Finished dev [unoptimized + debuginfo] target(s) in 10.18s
```
@@ -874,7 +823,7 @@ to the *adder/src/main.rs* file for the `adder` package, we’ll get an error:
```
$ cargo build
- --snip--
+ --snip--
Compiling adder v0.1.0 (file:///projects/add/adder)
error[E0432]: unresolved import `rand`
--> adder/src/main.rs:2:5
@@ -923,24 +872,27 @@ $ cargo test
Compiling add_one v0.1.0 (file:///projects/add/add_one)
Compiling adder v0.1.0 (file:///projects/add/adder)
Finished test [unoptimized + debuginfo] target(s) in 0.27s
- Running target/debug/deps/add_one-f0253159197f7841
+ Running unittests src/lib.rs (target/debug/deps/add_one-f0253159197f7841)
running 1 test
test tests::it_works ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out;
+finished in 0.00s
- Running target/debug/deps/adder-49979ff40686fa8e
+ Running unittests src/main.rs (target/debug/deps/adder-49979ff40686fa8e)
running 0 tests
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out;
+finished in 0.00s
Doc-tests add_one
running 0 tests
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out;
+finished in 0.00s
```
The first section of the output shows that the `it_works` test in the `add_one`
@@ -955,24 +907,26 @@ we want to test:
```
$ cargo test -p add_one
Finished test [unoptimized + debuginfo] target(s) in 0.00s
- Running target/debug/deps/add_one-b3235fea9a156f74
+ Running unittests src/lib.rs (target/debug/deps/add_one-b3235fea9a156f74)
running 1 test
test tests::it_works ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out;
+finished in 0.00s
Doc-tests add_one
running 0 tests
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out;
+finished in 0.00s
```
This output shows `cargo test` only ran the tests for the `add_one` crate and
didn’t run the `adder` crate tests.
-If you publish the crates in the workspace to *https://crates.io/*, each crate
+If you publish the crates in the workspace to *https://crates.io*, each crate
in the workspace will need to be published separately. Like `cargo test`, we
can publish a particular crate in our workspace by using the `-p` flag and
specifying the name of the crate we want to publish.
@@ -980,17 +934,17 @@ specifying the name of the crate we want to publish.
For additional practice, add an `add_two` crate to this workspace in a similar
way as the `add_one` crate!
-As your project grows, consider using a workspace: it’s easier to understand
-smaller, individual components than one big blob of code. Furthermore, keeping
-the crates in a workspace can make coordination between crates easier if they
-are often changed at the same time.
+As your project grows, consider using a workspace: it provides
+easier-to-understand, smaller, individual components than one big blob of code.
+Furthermore, keeping the crates in a workspace can make coordination between
+crates easier if they are often changed at the same time.
-## Installing Binaries with `cargo install`
+## Installing Binaries with cargo install
The `cargo install` command allows you to install and use binary crates
locally. This isn’t intended to replace system packages; it’s meant to be a
convenient way for Rust developers to install tools that others have shared on
-*https://crates.io/*. Note that you can only install packages that have binary
+*https://crates.io*. Note that you can only install packages that have binary
targets. A *binary target* is the runnable program that is created if the crate
has a *src/main.rs* file or another file specified as a binary, as opposed to a
library target that isn’t runnable on its own but is suitable for including
@@ -1010,35 +964,36 @@ can run the following:
```
$ cargo install ripgrep
Updating crates.io index
- Downloaded ripgrep v11.0.2
+ Downloaded ripgrep v13.0.0
Downloaded 1 crate (243.3 KB) in 0.88s
- Installing ripgrep v11.0.2
---snip--
- Compiling ripgrep v11.0.2
+ Installing ripgrep v13.0.0
+ --snip--
+ Compiling ripgrep v13.0.0
Finished release [optimized + debuginfo] target(s) in 3m 10s
Installing ~/.cargo/bin/rg
- Installed package `ripgrep v11.0.2` (executable `rg`)
+ Installed package `ripgrep v13.0.0` (executable `rg`)
```
The second-to-last line of the output shows the location and the name of the
installed binary, which in the case of `ripgrep` is `rg`. As long as the
installation directory is in your `$PATH`, as mentioned previously, you can
-then run `rg --help` and start using a faster, rustier tool for searching files!
+then run `rg --help` and start using a faster, Rustier tool for searching files!
## Extending Cargo with Custom Commands
Cargo is designed so you can extend it with new subcommands without having to
-modify Cargo. If a binary in your `$PATH` is named `cargo-something`, you can
-run it as if it was a Cargo subcommand by running `cargo something`. Custom
+modify it. If a binary in your `$PATH` is named `cargo-something`, you can run
+it as if it were a Cargo subcommand by running `cargo something`. Custom
commands like this are also listed when you run `cargo --list`. Being able to
use `cargo install` to install extensions and then run them just like the
-built-in Cargo tools is a super convenient benefit of Cargo’s design!
+built-in Cargo tools is a super-convenient benefit of Cargo’s design!
## Summary
-Sharing code with Cargo and *https://crates.io/* is part of what makes the Rust
+Sharing code with Cargo and *https://crates.io* is part of what makes the Rust
ecosystem useful for many different tasks. Rust’s standard library is small and
stable, but crates are easy to share, use, and improve on a timeline different
from that of the language. Don’t be shy about sharing code that’s useful to you
-on *https://crates.io/*; it’s likely that it will be useful to someone else as
+on *https://crates.io*; it’s likely that it will be useful to someone else as
well!
+
diff --git a/src/doc/book/nostarch/chapter15.md b/src/doc/book/nostarch/chapter15.md
index 166277fab..c0e847da1 100644
--- a/src/doc/book/nostarch/chapter15.md
+++ b/src/doc/book/nostarch/chapter15.md
@@ -13,34 +13,34 @@ memory. This address refers to, or “points at,†some other data. The most
common kind of pointer in Rust is a reference, which you learned about in
Chapter 4. References are indicated by the `&` symbol and borrow the value they
point to. They don’t have any special capabilities other than referring to
-data, and have no overhead.
+data, and they have no overhead.
*Smart pointers*, on the other hand, are data structures that act like a
pointer but also have additional metadata and capabilities. The concept of
smart pointers isn’t unique to Rust: smart pointers originated in C++ and exist
in other languages as well. Rust has a variety of smart pointers defined in the
standard library that provide functionality beyond that provided by references.
-To explore the general concept, we'll look at a couple of different examples of
+To explore the general concept, we’ll look at a couple of different examples of
smart pointers, including a *reference counting* smart pointer type. This
pointer enables you to allow data to have multiple owners by keeping track of
the number of owners and, when no owners remain, cleaning up the data.
Rust, with its concept of ownership and borrowing, has an additional difference
between references and smart pointers: while references only borrow data, in
-many cases, smart pointers *own* the data they point to.
+many cases smart pointers *own* the data they point to.
-Though we didn't call them as such at the time, we’ve already encountered a few
+Though we didn’t call them as such at the time, we’ve already encountered a few
smart pointers in this book, including `String` and `Vec<T>` in Chapter 8. Both
-these types count as smart pointers because they own some memory and allow you
-to manipulate it. They also have metadata and extra capabilities or guarantees.
-`String`, for example, stores its capacity as metadata and has the extra
-ability to ensure its data will always be valid UTF-8.
+of these types count as smart pointers because they own some memory and allow
+you to manipulate it. They also have metadata and extra capabilities or
+guarantees. `String`, for example, stores its capacity as metadata and has the
+extra ability to ensure its data will always be valid UTF-8.
Smart pointers are usually implemented using structs. Unlike an ordinary
struct, smart pointers implement the `Deref` and `Drop` traits. The `Deref`
trait allows an instance of the smart pointer struct to behave like a reference
so you can write your code to work with either references or smart pointers.
-The `Drop` trait allows you to customize the code that's run when an instance
+The `Drop` trait allows you to customize the code that’s run when an instance
of the smart pointer goes out of scope. In this chapter, we’ll discuss both
traits and demonstrate why they’re important to smart pointers.
@@ -49,10 +49,10 @@ frequently in Rust, this chapter won’t cover every existing smart pointer. Man
libraries have their own smart pointers, and you can even write your own. We’ll
cover the most common smart pointers in the standard library:
-* `Box<T>` for allocating values on the heap
+* `Box<T>`, for allocating values on the heap
* `Rc<T>`, a reference counting type that enables multiple ownership
* `Ref<T>` and `RefMut<T>`, accessed through `RefCell<T>`, a type that enforces
- the borrowing rules at runtime instead of compile time
+the borrowing rules at runtime instead of compile time
In addition, we’ll cover the *interior mutability* pattern where an immutable
type exposes an API for mutating an interior value. We’ll also discuss
@@ -60,7 +60,7 @@ type exposes an API for mutating an interior value. We’ll also discuss
Let’s dive in!
-## Using `Box<T>` to Point to Data on the Heap
+## Using Box<T> to Point to Data on the Heap
The most straightforward smart pointer is a *box*, whose type is written
`Box<T>`. Boxes allow you to store data on the heap rather than the stack. What
@@ -72,35 +72,35 @@ heap instead of on the stack. But they don’t have many extra capabilities
either. You’ll use them most often in these situations:
* When you have a type whose size can’t be known at compile time and you want
- to use a value of that type in a context that requires an exact size
+to use a value of that type in a context that requires an exact size
* When you have a large amount of data and you want to transfer ownership but
- ensure the data won’t be copied when you do so
+ensure the data won’t be copied when you do so
* When you want to own a value and you care only that it’s a type that
- implements a particular trait rather than being of a specific type
+implements a particular trait rather than being of a specific type
-We’ll demonstrate the first situation in the “Enabling Recursive Types with
-Boxes†section. In the second case, transferring ownership of a large amount of
+We’ll demonstrate the first situation in “Enabling Recursive Types with Boxesâ€
+on page XX. In the second case, transferring ownership of a large amount of
data can take a long time because the data is copied around on the stack. To
improve performance in this situation, we can store the large amount of data on
the heap in a box. Then, only the small amount of pointer data is copied around
on the stack, while the data it references stays in one place on the heap. The
-third case is known as a *trait object*, and Chapter 17 devotes an entire
-section, “Using Trait Objects That Allow for Values of Different Types,†just
-to that topic. So what you learn here you’ll apply again in Chapter 17!
+third case is known as a *trait object*, and “Using Trait Objects That Allow
+for Values of Different Types†on page XX is devoted to that topic. So what you
+learn here you’ll apply again in that section!
-### Using a `Box<T>` to Store Data on the Heap
+### Using Box<T> to Store Data on the Heap
Before we discuss the heap storage use case for `Box<T>`, we’ll cover the
syntax and how to interact with values stored within a `Box<T>`.
-Listing 15-1 shows how to use a box to store an `i32` value on the heap:
+Listing 15-1 shows how to use a box to store an `i32` value on the heap.
Filename: src/main.rs
```
fn main() {
let b = Box::new(5);
- println!("b = {}", b);
+ println!("b = {b}");
}
```
@@ -118,34 +118,34 @@ Putting a single value on the heap isn’t very useful, so you won’t use boxes
themselves in this way very often. Having values like a single `i32` on the
stack, where they’re stored by default, is more appropriate in the majority of
situations. Let’s look at a case where boxes allow us to define types that we
-wouldn’t be allowed to if we didn’t have boxes.
+wouldn’t be allowed to define if we didn’t have boxes.
### Enabling Recursive Types with Boxes
-A value of *recursive type* can have another value of the same type as part of
-itself. Recursive types pose an issue because at compile time Rust needs to
+A value of a *recursive type* can have another value of the same type as part
+of itself. Recursive types pose an issue because at compile time Rust needs to
know how much space a type takes up. However, the nesting of values of
recursive types could theoretically continue infinitely, so Rust can’t know how
much space the value needs. Because boxes have a known size, we can enable
recursive types by inserting a box in the recursive type definition.
-As an example of a recursive type, let’s explore the *cons list*. This is a data
-type commonly found in functional programming languages. The cons list type
-we’ll define is straightforward except for the recursion; therefore, the
+As an example of a recursive type, let’s explore the *cons list*. This is a
+data type commonly found in functional programming languages. The cons list
+type we’ll define is straightforward except for the recursion; therefore, the
concepts in the example we’ll work with will be useful any time you get into
more complex situations involving recursive types.
#### More Information About the Cons List
A *cons list* is a data structure that comes from the Lisp programming language
-and its dialects and is made up of nested pairs, and is the Lisp version of a
-linked list. Its name comes from the `cons` function (short for “construct
-functionâ€) in Lisp that constructs a new pair from its two arguments. By
+and its dialects, is made up of nested pairs, and is the Lisp version of a
+linked list. Its name comes from the `cons` function (short for *construct
+function*) in Lisp that constructs a new pair from its two arguments. By
calling `cons` on a pair consisting of a value and another pair, we can
construct cons lists made up of recursive pairs.
-For example, here's a pseudocode representation of a cons list containing the
-list 1, 2, 3 with each pair in parentheses:
+For example, here’s a pseudocode representation of a cons list containing the
+list `1, 2, 3` with each pair in parentheses:
```
(1, (2, (3, Nil)))
@@ -181,16 +181,18 @@ Listing 15-2: The first attempt at defining an enum to represent a cons list
data structure of `i32` values
> Note: We’re implementing a cons list that holds only `i32` values for the
-> purposes of this example. We could have implemented it using generics, as we
-> discussed in Chapter 10, to define a cons list type that could store values of
-> any type.
+purposes of this example. We could have implemented it using generics, as we
+discussed in Chapter 10, to define a cons list type that could store values of
+any type.
Using the `List` type to store the list `1, 2, 3` would look like the code in
-Listing 15-3:
+Listing 15-3.
Filename: src/main.rs
```
+--snip--
+
use crate::List::{Cons, Nil};
fn main() {
@@ -206,7 +208,7 @@ is one more `Cons` value that holds `3` and a `List` value, which is finally
`Nil`, the non-recursive variant that signals the end of the list.
If we try to compile the code in Listing 15-3, we get the error shown in
-Listing 15-4:
+Listing 15-4.
```
error[E0072]: recursive type `List` has infinite size
@@ -217,7 +219,11 @@ error[E0072]: recursive type `List` has infinite size
2 | Cons(i32, List),
| ---- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `List` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `List`
+representable
+ |
+2 | Cons(i32, Box<List>),
+ | ++++ +
```
Listing 15-4: The error we get when attempting to define a recursive enum
@@ -225,7 +231,7 @@ Listing 15-4: The error we get when attempting to define a recursive enum
The error shows this type “has infinite size.†The reason is that we’ve defined
`List` with a variant that is recursive: it holds another value of itself
directly. As a result, Rust can’t figure out how much space it needs to store a
-`List` value. Let’s break down why we get this error. First, we'll look at how
+`List` value. Let’s break down why we get this error. First we’ll look at how
Rust decides how much space it needs to store a value of a non-recursive type.
#### Computing the Size of a Non-Recursive Type
@@ -258,23 +264,22 @@ type needs, the compiler looks at the variants, starting with the `Cons`
variant. The `Cons` variant holds a value of type `i32` and a value of type
`List`, and this process continues infinitely, as shown in Figure 15-1.
-<img alt="An infinite Cons list" src="img/trpl15-01.svg" class="center" style="width: 50%;" />
-
Figure 15-1: An infinite `List` consisting of infinite `Cons` variants
-#### Using `Box<T>` to Get a Recursive Type with a Known Size
+#### Using Box<T> to Get a Recursive Type with a Known Size
Because Rust can’t figure out how much space to allocate for recursively
defined types, the compiler gives an error with this helpful suggestion:
```
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `List` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `List`
+representable
|
2 | Cons(i32, Box<List>),
- | ^^^^ ^
+ | ++++ +
```
-In this suggestion, “indirection†means that instead of storing a value
+In this suggestion, *indirection* means that instead of storing a value
directly, we should change the data structure to store the value indirectly by
storing a pointer to the value instead.
@@ -288,7 +293,7 @@ this implementation is now more like placing the items next to one another
rather than inside one another.
We can change the definition of the `List` enum in Listing 15-2 and the usage
-of the `List` in Listing 15-3 to the code in Listing 15-5, which will compile:
+of the `List` in Listing 15-3 to the code in Listing 15-5, which will compile.
Filename: src/main.rs
@@ -301,31 +306,38 @@ enum List {
use crate::List::{Cons, Nil};
fn main() {
- let list = Cons(1, Box::new(Cons(2, Box::new(Cons(3, Box::new(Nil))))));
+ let list = Cons(
+ 1,
+ Box::new(Cons(
+ 2,
+ Box::new(Cons(
+ 3,
+ Box::new(Nil)
+ ))
+ ))
+ );
}
```
Listing 15-5: Definition of `List` that uses `Box<T>` in order to have a known
size
-The `Cons` variant needs the size of an `i32` plus the space to store the
-box’s pointer data. The `Nil` variant stores no values, so it needs less space
-than the `Cons` variant. We now know that any `List` value will take up the
-size of an `i32` plus the size of a box’s pointer data. By using a box, we’ve
-broken the infinite, recursive chain, so the compiler can figure out the size
-it needs to store a `List` value. Figure 15-2 shows what the `Cons` variant
-looks like now.
+The `Cons` variant needs the size of an `i32` plus the space to store the box’s
+pointer data. The `Nil` variant stores no values, so it needs less space than
+the `Cons` variant. We now know that any `List` value will take up the size of
+an `i32` plus the size of a box’s pointer data. By using a box, we’ve broken
+the infinite, recursive chain, so the compiler can figure out the size it needs
+to store a `List` value. Figure 15-2 shows what the `Cons` variant looks like
+now.
-<img alt="A finite Cons list" src="img/trpl15-02.svg" class="center" />
-
-Figure 15-2: A `List` that is not infinitely sized because `Cons` holds a `Box`
+Figure 15-2: A `List` that is not infinitely sized, because `Cons` holds a `Box`
Boxes provide only the indirection and heap allocation; they don’t have any
other special capabilities, like those we’ll see with the other smart pointer
types. They also don’t have the performance overhead that these special
capabilities incur, so they can be useful in cases like the cons list where the
indirection is the only feature we need. We’ll look at more use cases for boxes
-in Chapter 17, too.
+in Chapter 17.
The `Box<T>` type is a smart pointer because it implements the `Deref` trait,
which allows `Box<T>` values to be treated like references. When a `Box<T>`
@@ -335,7 +347,7 @@ even more important to the functionality provided by the other smart pointer
types we’ll discuss in the rest of this chapter. Let’s explore these two traits
in more detail.
-## Treating Smart Pointers Like Regular References with the `Deref` Trait
+## Treating Smart Pointers Like Regular References with Deref
Implementing the `Deref` trait allows you to customize the behavior of the
*dereference operator* `*` (not to be confused with the multiplication or glob
@@ -347,31 +359,31 @@ Let’s first look at how the dereference operator works with regular references
Then we’ll try to define a custom type that behaves like `Box<T>`, and see why
the dereference operator doesn’t work like a reference on our newly defined
type. We’ll explore how implementing the `Deref` trait makes it possible for
-smart pointers to work in ways similar to references. Then we’ll look at
-Rust’s *deref coercion* feature and how it lets us work with either references
-or smart pointers.
+smart pointers to work in ways similar to references. Then we’ll look at Rust’s
+*deref coercion* feature and how it lets us work with either references or
+smart pointers.
-> Note: there’s one big difference between the `MyBox<T>` type we’re about to
-> build and the real `Box<T>`: our version will not store its data on the heap.
-> We are focusing this example on `Deref`, so where the data is actually stored
-> is less important than the pointer-like behavior.
+> Note: There’s one big difference between the `MyBox<T>` type we’re about to
+build and the real `Box<T>`: our version will not store its data on the heap.
+We are focusing this example on `Deref`, so where the data is actually stored
+is less important than the pointer-like behavior.
### Following the Pointer to the Value
A regular reference is a type of pointer, and one way to think of a pointer is
as an arrow to a value stored somewhere else. In Listing 15-6, we create a
reference to an `i32` value and then use the dereference operator to follow the
-reference to the value:
+reference to the value.
Filename: src/main.rs
```
fn main() {
- [1] let x = 5;
- [2] let y = &x;
+ 1 let x = 5;
+ 2 let y = &x;
- [3] assert_eq!(5, x);
- [4] assert_eq!(5, *y);
+ 3 assert_eq!(5, x);
+ 4 assert_eq!(5, *y);
}
```
@@ -393,31 +405,33 @@ error[E0277]: can't compare `{integer}` with `&{integer}`
--> src/main.rs:6:5
|
6 | assert_eq!(5, y);
- | ^^^^^^^^^^^^^^^^ no implementation for `{integer} == &{integer}`
+ | ^^^^^^^^^^^^^^^^ no implementation for `{integer} ==
+&{integer}`
|
- = help: the trait `PartialEq<&{integer}>` is not implemented for `{integer}`
+ = help: the trait `PartialEq<&{integer}>` is not implemented
+for `{integer}`
```
Comparing a number and a reference to a number isn’t allowed because they’re
different types. We must use the dereference operator to follow the reference
to the value it’s pointing to.
-### Using `Box<T>` Like a Reference
+### Using Box<T> Like a Reference
We can rewrite the code in Listing 15-6 to use a `Box<T>` instead of a
reference; the dereference operator used on the `Box<T>` in Listing 15-7
functions in the same way as the dereference operator used on the reference in
-Listing 15-6:
+Listing 15-6.
Filename: src/main.rs
```
fn main() {
let x = 5;
- [1] let y = Box::new(x);
+ 1 let y = Box::new(x);
assert_eq!(5, x);
- [2] assert_eq!(5, *y);
+ 2 assert_eq!(5, *y);
}
```
@@ -445,18 +459,18 @@ Listing 15-8 defines a `MyBox<T>` type in the same way. We’ll also define a
Filename: src/main.rs
```
-[1] struct MyBox<T>(T);
+ 1 struct MyBox<T>(T);
impl<T> MyBox<T> {
- [2] fn new(x: T) -> MyBox<T> {
- [3] MyBox(x)
+ 2 fn new(x: T) -> MyBox<T> {
+ 3 MyBox(x)
}
}
```
Listing 15-8: Defining a `MyBox<T>` type
-We define a struct named `MyBox` and declare a generic parameter `T` [1],
+We define a struct named `MyBox` and declare a generic parameter `T` [1]
because we want our type to hold values of any type. The `MyBox` type is a
tuple struct with one element of type `T`. The `MyBox::new` function takes one
parameter of type `T` [2] and returns a `MyBox` instance that holds the value
@@ -482,7 +496,7 @@ fn main() {
Listing 15-9: Attempting to use `MyBox<T>` in the same way we used references
and `Box<T>`
-Here’s the resulting compilation error:
+Here’s the resultant compilation error:
```
error[E0614]: type `MyBox<{integer}>` cannot be dereferenced
@@ -496,14 +510,14 @@ Our `MyBox<T>` type can’t be dereferenced because we haven’t implemented tha
ability on our type. To enable dereferencing with the `*` operator, we
implement the `Deref` trait.
-### Treating a Type Like a Reference by Implementing the `Deref` Trait
+### Implementing the Deref Trait
-As discussed in the “Implementing a Trait on a Type†section of Chapter 10, to
-implement a trait, we need to provide implementations for the trait’s required
-methods. The `Deref` trait, provided by the standard library, requires us to
-implement one method named `deref` that borrows `self` and returns a reference
-to the inner data. Listing 15-10 contains an implementation of `Deref` to add
-to the definition of `MyBox`:
+As discussed in “Implementing a Trait on a Type†on page XX, to implement a
+trait we need to provide implementations for the trait’s required methods. The
+`Deref` trait, provided by the standard library, requires us to implement one
+method named `deref` that borrows `self` and returns a reference to the inner
+data. Listing 15-10 contains an implementation of `Deref` to add to the
+definition of `MyBox``<T>`.
Filename: src/main.rs
@@ -511,10 +525,10 @@ Filename: src/main.rs
use std::ops::Deref;
impl<T> Deref for MyBox<T> {
- [1] type Target = T;
+ 1 type Target = T;
fn deref(&self) -> &Self::Target {
- [2] &self.0
+ 2 &self.0
}
}
```
@@ -528,10 +542,10 @@ them in more detail in Chapter 19.
We fill in the body of the `deref` method with `&self.0` so `deref` returns a
reference to the value we want to access with the `*` operator [2]; recall from
-the “Using Tuple Structs without Named Fields to Create Different Typesâ€
-section of Chapter 5 that `.0` accesses the first value in a tuple struct. The
-`main` function in Listing 15-9 that calls `*` on the `MyBox<T>` value now
-compiles, and the assertions pass!
+“Using Tuple Structs Without Named Fields to Create Different Types†on page XX
+that `.0` accesses the first value in a tuple struct. The `main` function in
+Listing 15-9 that calls `*` on the `MyBox<T>` value now compiles, and the
+assertions pass!
Without the `Deref` trait, the compiler can only dereference `&` references.
The `deref` method gives the compiler the ability to take a value of any type
@@ -553,7 +567,7 @@ identically whether we have a regular reference or a type that implements
The reason the `deref` method returns a reference to a value, and that the
plain dereference outside the parentheses in `*(y.deref())` is still necessary,
-is to do with the ownership system. If the `deref` method returned the value
+has to do with the ownership system. If the `deref` method returned the value
directly instead of a reference to the value, the value would be moved out of
`self`. We don’t want to take ownership of the inner value inside `MyBox<T>` in
this case or in most cases where we use the dereference operator.
@@ -584,7 +598,7 @@ can work for either references or smart pointers.
To see deref coercion in action, let’s use the `MyBox<T>` type we defined in
Listing 15-8 as well as the implementation of `Deref` that we added in Listing
15-10. Listing 15-11 shows the definition of a function that has a string slice
-parameter:
+parameter.
Filename: src/main.rs
@@ -597,8 +611,8 @@ fn hello(name: &str) {
Listing 15-11: A `hello` function that has the parameter `name` of type `&str`
We can call the `hello` function with a string slice as an argument, such as
-`hello("Rust");` for example. Deref coercion makes it possible to call `hello`
-with a reference to a value of type `MyBox<String>`, as shown in Listing 15-12:
+`hello("Rust");`, for example. Deref coercion makes it possible to call `hello`
+with a reference to a value of type `MyBox<String>`, as shown in Listing 15-12.
Filename: src/main.rs
@@ -661,10 +675,10 @@ cases:
* From `&mut T` to `&mut U` when `T: DerefMut<Target=U>`
* From `&mut T` to `&U` when `T: Deref<Target=U>`
-The first two cases are the same as each other except that the second
-implements mutability. The first case states that if you have a `&T`, and `T`
-implements `Deref` to some type `U`, you can get a `&U` transparently. The
-second case states that the same deref coercion happens for mutable references.
+The first two cases are the same except that the second implements mutability.
+The first case states that if you have a `&T`, and `T` implements `Deref` to
+some type `U`, you can get a `&U` transparently. The second case states that
+the same deref coercion happens for mutable references.
The third case is trickier: Rust will also coerce a mutable reference to an
immutable one. But the reverse is *not* possible: immutable references will
@@ -678,12 +692,12 @@ the borrowing rules don’t guarantee that. Therefore, Rust can’t make the
assumption that converting an immutable reference to a mutable reference is
possible.
-## Running Code on Cleanup with the `Drop` Trait
+## Running Code on Cleanup with the Drop Trait
The second trait important to the smart pointer pattern is `Drop`, which lets
you customize what happens when a value is about to go out of scope. You can
-provide an implementation for the `Drop` trait on any type, and that code
-can be used to release resources like files or network connections.
+provide an implementation for the `Drop` trait on any type, and that code can
+be used to release resources like files or network connections.
We’re introducing `Drop` in the context of smart pointers because the
functionality of the `Drop` trait is almost always used when implementing a
@@ -692,7 +706,7 @@ space on the heap that the box points to.
In some languages, for some types, the programmer must call code to free memory
or resources every time they finish using an instance of those types. Examples
-include file handles, sockets, or locks. If they forget, the system might
+include file handles, sockets, and locks. If they forget, the system might
become overloaded and crash. In Rust, you can specify that a particular bit of
code be run whenever a value goes out of scope, and the compiler will insert
this code automatically. As a result, you don’t need to be careful about
@@ -706,7 +720,7 @@ let’s implement `drop` with `println!` statements for now.
Listing 15-14 shows a `CustomSmartPointer` struct whose only custom
functionality is that it will print `Dropping CustomSmartPointer!` when the
-instance goes out of scope, to show when Rust runs the `drop` function.
+instance goes out of scope, to show when Rust runs the `drop` method.
Filename: src/main.rs
@@ -715,21 +729,24 @@ struct CustomSmartPointer {
data: String,
}
-[1] impl Drop for CustomSmartPointer {
+1 impl Drop for CustomSmartPointer {
fn drop(&mut self) {
- [2] println!("Dropping CustomSmartPointer with data `{}`!", self.data);
+ 2 println!(
+ "Dropping CustomSmartPointer with data `{}`!",
+ self.data
+ );
}
}
fn main() {
- [3] let c = CustomSmartPointer {
+ 3 let c = CustomSmartPointer {
data: String::from("my stuff"),
};
- [4] let d = CustomSmartPointer {
+ 4 let d = CustomSmartPointer {
data: String::from("other stuff"),
};
- [5] println!("CustomSmartPointers created.");
-[6] }
+ 5 println!("CustomSmartPointers created.");
+6 }
```
Listing 15-14: A `CustomSmartPointer` struct that implements the `Drop` trait
@@ -738,12 +755,12 @@ where we would put our cleanup code
The `Drop` trait is included in the prelude, so we don’t need to bring it into
scope. We implement the `Drop` trait on `CustomSmartPointer` [1] and provide an
implementation for the `drop` method that calls `println!` [2]. The body of the
-`drop` function is where you would place any logic that you wanted to run when
-an instance of your type goes out of scope. We’re printing some text here to
+`drop` method is where you would place any logic that you wanted to run when an
+instance of your type goes out of scope. We’re printing some text here to
demonstrate visually when Rust will call `drop`.
-In `main`, we create two instances of `CustomSmartPointer` [3][4] and then
-print `CustomSmartPointers created` [5]. At the end of `main` [6], our
+In `main`, we create two instances of `CustomSmartPointer` at [3] and [4] and
+then print `CustomSmartPointers created` [5]. At the end of `main` [6], our
instances of `CustomSmartPointer` will go out of scope, and Rust will call the
code we put in the `drop` method [2], printing our final message. Note that we
didn’t need to call the `drop` method explicitly.
@@ -758,26 +775,24 @@ Dropping CustomSmartPointer with data `my stuff`!
Rust automatically called `drop` for us when our instances went out of scope,
calling the code we specified. Variables are dropped in the reverse order of
-their creation, so `d` was dropped before `c`. This example's purpose is to
+their creation, so `d` was dropped before `c`. This example’s purpose is to
give you a visual guide to how the `drop` method works; usually you would
specify the cleanup code that your type needs to run rather than a print
message.
-### Dropping a Value Early with `std::mem::drop`
-
Unfortunately, it’s not straightforward to disable the automatic `drop`
functionality. Disabling `drop` isn’t usually necessary; the whole point of the
`Drop` trait is that it’s taken care of automatically. Occasionally, however,
you might want to clean up a value early. One example is when using smart
pointers that manage locks: you might want to force the `drop` method that
releases the lock so that other code in the same scope can acquire the lock.
-Rust doesn’t let you call the `Drop` trait’s `drop` method manually; instead
+Rust doesn’t let you call the `Drop` trait’s `drop` method manually; instead,
you have to call the `std::mem::drop` function provided by the standard library
if you want to force a value to be dropped before the end of its scope.
If we try to call the `Drop` trait’s `drop` method manually by modifying the
`main` function from Listing 15-14, as shown in Listing 15-15, we’ll get a
-compiler error:
+compiler error.
Filename: src/main.rs
@@ -788,7 +803,9 @@ fn main() {
};
println!("CustomSmartPointer created.");
c.drop();
- println!("CustomSmartPointer dropped before the end of main.");
+ println!(
+ "CustomSmartPointer dropped before the end of main."
+ );
}
```
@@ -805,6 +822,7 @@ error[E0040]: explicit use of destructor method
| --^^^^--
| | |
| | explicit destructor calls not allowed
+ | help: consider using `drop` function: `drop(c)`
```
This error message states that we’re not allowed to explicitly call `drop`. The
@@ -823,9 +841,9 @@ scope, and we can’t call the `drop` method explicitly. So, if we need to force
a value to be cleaned up early, we use the `std::mem::drop` function.
The `std::mem::drop` function is different from the `drop` method in the `Drop`
-trait. We call it by passing as an argument the value we want to force drop.
+trait. We call it by passing as an argument the value we want to force-drop.
The function is in the prelude, so we can modify `main` in Listing 15-15 to
-call the `drop` function, as shown in Listing 15-16:
+call the `drop` function, as shown in Listing 15-16.
Filename: src/main.rs
@@ -836,7 +854,9 @@ fn main() {
};
println!("CustomSmartPointer created.");
drop(c);
- println!("CustomSmartPointer dropped before the end of main.");
+ println!(
+ "CustomSmartPointer dropped before the end of main."
+ );
}
```
@@ -851,7 +871,7 @@ Dropping CustomSmartPointer with data `some data`!
CustomSmartPointer dropped before the end of main.
```
-The text ```Dropping CustomSmartPointer with data `some data`!``` is printed
+The text `Dropping CustomSmartPointer with data `some data`!` is printed
between the `CustomSmartPointer created.` and `CustomSmartPointer dropped
before the end of main.` text, showing that the `drop` method code is called to
drop `c` at that point.
@@ -870,7 +890,7 @@ Now that we’ve examined `Box<T>` and some of the characteristics of smart
pointers, let’s look at a few other smart pointers defined in the standard
library.
-## `Rc<T>`, the Reference Counted Smart Pointer
+## Rc<T>, the Reference Counted Smart Pointer
In the majority of cases, ownership is clear: you know exactly which variable
owns a given value. However, there are cases when a single value might have
@@ -889,7 +909,7 @@ Imagine `Rc<T>` as a TV in a family room. When one person enters to watch TV,
they turn it on. Others can come into the room and watch the TV. When the last
person leaves the room, they turn off the TV because it’s no longer being used.
If someone turns off the TV while others are still watching it, there would be
-uproar from the remaining TV watchers!
+an uproar from the remaining TV watchers!
We use the `Rc<T>` type when we want to allocate some data on the heap for
multiple parts of our program to read and we can’t determine at compile time
@@ -901,23 +921,21 @@ Note that `Rc<T>` is only for use in single-threaded scenarios. When we discuss
concurrency in Chapter 16, we’ll cover how to do reference counting in
multithreaded programs.
-### Using `Rc<T>` to Share Data
+### Using Rc<T> to Share Data
Let’s return to our cons list example in Listing 15-5. Recall that we defined
it using `Box<T>`. This time, we’ll create two lists that both share ownership
-of a third list. Conceptually, this looks similar to Figure 15-3:
-
-<img alt="Two lists that share ownership of a third list" src="img/trpl15-03.svg" class="center" />
+of a third list. Conceptually, this looks similar to Figure 15-3.
Figure 15-3: Two lists, `b` and `c`, sharing ownership of a third list, `a`
-We’ll create list `a` that contains 5 and then 10. Then we’ll make two more
-lists: `b` that starts with 3 and `c` that starts with 4. Both `b` and `c`
-lists will then continue on to the first `a` list containing 5 and 10. In other
-words, both lists will share the first list containing 5 and 10.
+We’ll create list `a` that contains `5` and then `10`. Then we’ll make two more
+lists: `b` that starts with `3` and `c` that starts with `4`. Both `b` and `c`
+lists will then continue on to the first `a` list containing `5` and `10`. In
+other words, both lists will share the first list containing `5` and `10`.
Trying to implement this scenario using our definition of `List` with `Box<T>`
-won’t work, as shown in Listing 15-17:
+won’t work, as shown in Listing 15-17.
Filename: src/main.rs
@@ -931,13 +949,13 @@ use crate::List::{Cons, Nil};
fn main() {
let a = Cons(5, Box::new(Cons(10, Box::new(Nil))));
-[1] let b = Cons(3, Box::new(a));
-[2] let c = Cons(4, Box::new(a));
+ 1 let b = Cons(3, Box::new(a));
+ 2 let c = Cons(4, Box::new(a));
}
```
-Listing 15-17: Demonstrating we’re not allowed to have two lists using `Box<T>`
-that try to share ownership of a third list
+Listing 15-17: Demonstrating that we’re not allowed to have two lists using
+`Box<T>` that try to share ownership of a third list
When we compile this code, we get this error:
@@ -946,7 +964,8 @@ error[E0382]: use of moved value: `a`
--> src/main.rs:11:30
|
9 | let a = Cons(5, Box::new(Cons(10, Box::new(Nil))));
- | - move occurs because `a` has type `List`, which does not implement the `Copy` trait
+ | - move occurs because `a` has type `List`, which
+does not implement the `Copy` trait
10 | let b = Cons(3, Box::new(a));
| - value moved here
11 | let c = Cons(4, Box::new(a));
@@ -983,22 +1002,22 @@ enum List {
}
use crate::List::{Cons, Nil};
-[1] use std::rc::Rc;
+1 use std::rc::Rc;
fn main() {
-[2] let a = Rc::new(Cons(5, Rc::new(Cons(10, Rc::new(Nil)))));
-[3] let b = Cons(3, Rc::clone(&a));
-[4] let c = Cons(4, Rc::clone(&a));
+ 2 let a = Rc::new(Cons(5, Rc::new(Cons(10, Rc::new(Nil)))));
+ 3 let b = Cons(3, Rc::clone(&a));
+ 4 let c = Cons(4, Rc::clone(&a));
}
```
Listing 15-18: A definition of `List` that uses `Rc<T>`
We need to add a `use` statement to bring `Rc<T>` into scope [1] because it’s
-not in the prelude. In `main`, we create the list holding 5 and 10 and store it
-in a new `Rc<List>` in `a` [2]. Then when we create `b` [3] and `c` [4], we
-call the `Rc::clone` function and pass a reference to the `Rc<List>` in `a` as
-an argument.
+not in the prelude. In `main`, we create the list holding `5` and `10` and
+store it in a new `Rc<List>` in `a` [2]. Then, when we create `b` [3] and `c`
+[4], we call the `Rc::clone` function and pass a reference to the `Rc<List>` in
+`a` as an argument.
We could have called `a.clone()` rather than `Rc::clone(&a)`, but Rust’s
convention is to use `Rc::clone` in this case. The implementation of
@@ -1011,7 +1030,7 @@ increase the reference count. When looking for performance problems in the
code, we only need to consider the deep-copy clones and can disregard calls to
`Rc::clone`.
-### Cloning an `Rc<T>` Increases the Reference Count
+### Cloning an Rc<T> Increases the Reference Count
Let’s change our working example in Listing 15-18 so we can see the reference
counts changing as we create and drop references to the `Rc<List>` in `a`.
@@ -1022,16 +1041,30 @@ then we can see how the reference count changes when `c` goes out of scope.
Filename: src/main.rs
```
+--snip--
+
fn main() {
let a = Rc::new(Cons(5, Rc::new(Cons(10, Rc::new(Nil)))));
- println!("count after creating a = {}", Rc::strong_count(&a));
+ println!(
+ "count after creating a = {}",
+ Rc::strong_count(&a)
+ );
let b = Cons(3, Rc::clone(&a));
- println!("count after creating b = {}", Rc::strong_count(&a));
+ println!(
+ "count after creating b = {}",
+ Rc::strong_count(&a)
+ );
{
let c = Cons(4, Rc::clone(&a));
- println!("count after creating c = {}", Rc::strong_count(&a));
+ println!(
+ "count after creating c = {}",
+ Rc::strong_count(&a)
+ );
}
- println!("count after c goes out of scope = {}", Rc::strong_count(&a));
+ println!(
+ "count after c goes out of scope = {}",
+ Rc::strong_count(&a)
+ );
}
```
@@ -1040,8 +1073,8 @@ Listing 15-19: Printing the reference count
At each point in the program where the reference count changes, we print the
reference count, which we get by calling the `Rc::strong_count` function. This
function is named `strong_count` rather than `count` because the `Rc<T>` type
-also has a `weak_count`; we’ll see what `weak_count` is used for in the
-“Preventing Reference Cycles: Turning an `Rc<T>` into a `Weak<T>`†section.
+also has a `weak_count`; we’ll see what `weak_count` is used for in “Preventing
+Reference Cycles Using Weak<T>†on page XX.
This code prints the following:
@@ -1074,7 +1107,7 @@ section, we’ll discuss the interior mutability pattern and the `RefCell<T>`
type that you can use in conjunction with an `Rc<T>` to work with this
immutability restriction.
-## `RefCell<T>` and the Interior Mutability Pattern
+## RefCell<T> and the Interior Mutability Pattern
*Interior mutability* is a design pattern in Rust that allows you to mutate
data even when there are immutable references to that data; normally, this
@@ -1092,14 +1125,14 @@ safe API, and the outer type is still immutable.
Let’s explore this concept by looking at the `RefCell<T>` type that follows the
interior mutability pattern.
-### Enforcing Borrowing Rules at Runtime with `RefCell<T>`
+### Enforcing Borrowing Rules at Runtime with RefCell<T>
Unlike `Rc<T>`, the `RefCell<T>` type represents single ownership over the data
-it holds. So, what makes `RefCell<T>` different from a type like `Box<T>`?
+it holds. So what makes `RefCell<T>` different from a type like `Box<T>`?
Recall the borrowing rules you learned in Chapter 4:
-* At any given time, you can have *either* (but not both) one mutable reference
- or any number of immutable references.
+* At any given time, you can have *either* one mutable reference or any number
+of immutable references (but not both).
* References must always be valid.
With references and `Box<T>`, the borrowing rules’ invariants are enforced at
@@ -1137,13 +1170,13 @@ multithreaded program in Chapter 16.
Here is a recap of the reasons to choose `Box<T>`, `Rc<T>`, or `RefCell<T>`:
* `Rc<T>` enables multiple owners of the same data; `Box<T>` and `RefCell<T>`
- have single owners.
+have single owners.
* `Box<T>` allows immutable or mutable borrows checked at compile time; `Rc<T>`
- allows only immutable borrows checked at compile time; `RefCell<T>` allows
- immutable or mutable borrows checked at runtime.
+allows only immutable borrows checked at compile time; `RefCell<T>` allows
+immutable or mutable borrows checked at runtime.
* Because `RefCell<T>` allows mutable borrows checked at runtime, you can
- mutate the value inside the `RefCell<T>` even when the `RefCell<T>` is
- immutable.
+mutate the value inside the `RefCell<T>` even when the `RefCell<T>` is
+immutable.
Mutating the value inside an immutable value is the *interior mutability*
pattern. Let’s look at a situation in which interior mutability is useful and
@@ -1154,6 +1187,8 @@ examine how it’s possible.
A consequence of the borrowing rules is that when you have an immutable value,
you can’t borrow it mutably. For example, this code won’t compile:
+Filename: src/main.rs
+
```
fn main() {
let x = 5;
@@ -1164,7 +1199,8 @@ fn main() {
If you tried to compile this code, you’d get the following error:
```
-error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
+error[E0596]: cannot borrow `x` as mutable, as it is not declared
+as mutable
--> src/main.rs:3:13
|
2 | let x = 5;
@@ -1188,13 +1224,13 @@ an immutable value and see why that is useful.
#### A Use Case for Interior Mutability: Mock Objects
Sometimes during testing a programmer will use a type in place of another type,
-in order to observe particular behavior and assert it's implemented correctly.
-This placeholder type is called a *test double*. Think of it in the sense of a
-"stunt double" in filmmaking, where a person steps in and substitutes for an
-actor to do a particular tricky scene. Test doubles stand in for other types
-when we're running tests. *Mock objects* are specific types of test doubles
-that record what happens during a test so you can assert that the correct
-actions took place.
+in order to observe particular behavior and assert that it’s implemented
+correctly. This placeholder type is called a *test double*. Think of it in the
+sense of a stunt double in filmmaking, where a person steps in and substitutes
+for an actor to do a particularly tricky scene. Test doubles stand in for other
+types when we’re running tests. *Mock objects* are specific types of test
+doubles that record what happens during a test so you can assert that the
+correct actions took place.
Rust doesn’t have objects in the same sense as other languages have objects,
and Rust doesn’t have mock object functionality built into the standard library
@@ -1210,15 +1246,15 @@ Our library will only provide the functionality of tracking how close to the
maximum a value is and what the messages should be at what times. Applications
that use our library will be expected to provide the mechanism for sending the
messages: the application could put a message in the application, send an
-email, send a text message, or something else. The library doesn’t need to know
-that detail. All it needs is something that implements a trait we’ll provide
-called `Messenger`. Listing 15-20 shows the library code:
+email, send a text message, or do something else. The library doesn’t need to
+know that detail. All it needs is something that implements a trait we’ll
+provide called `Messenger`. Listing 15-20 shows the library code.
Filename: src/lib.rs
```
pub trait Messenger {
-[1] fn send(&self, msg: &str);
+ 1 fn send(&self, msg: &str);
}
pub struct LimitTracker<'a, T: Messenger> {
@@ -1231,7 +1267,10 @@ impl<'a, T> LimitTracker<'a, T>
where
T: Messenger,
{
- pub fn new(messenger: &'a T, max: usize) -> LimitTracker<'a, T> {
+ pub fn new(
+ messenger: &'a T,
+ max: usize
+ ) -> LimitTracker<'a, T> {
LimitTracker {
messenger,
value: 0,
@@ -1239,19 +1278,21 @@ where
}
}
-[2] pub fn set_value(&mut self, value: usize) {
+ 2 pub fn set_value(&mut self, value: usize) {
self.value = value;
- let percentage_of_max = self.value as f64 / self.max as f64;
+ let percentage_of_max =
+ self.value as f64 / self.max as f64;
if percentage_of_max >= 1.0 {
- self.messenger.send("Error: You are over your quota!");
+ self.messenger
+ .send("Error: You are over your quota!");
} else if percentage_of_max >= 0.9 {
self.messenger
- .send("Urgent warning: You've used up over 90% of your quota!");
+ .send("Urgent: You're at 90% of your quota!");
} else if percentage_of_max >= 0.75 {
self.messenger
- .send("Warning: You've used up over 75% of your quota!");
+ .send("Warning: You're at 75% of your quota!");
}
}
}
@@ -1269,7 +1310,7 @@ part is that we want to test the behavior of the `set_value` method on the
but `set_value` doesn’t return anything for us to make assertions on. We want
to be able to say that if we create a `LimitTracker` with something that
implements the `Messenger` trait and a particular value for `max`, when we pass
-different numbers for `value`, the messenger is told to send the appropriate
+different numbers for `value` the messenger is told to send the appropriate
messages.
We need a mock object that, instead of sending an email or text message when we
@@ -1277,7 +1318,7 @@ call `send`, will only keep track of the messages it’s told to send. We can
create a new instance of the mock object, create a `LimitTracker` that uses the
mock object, call the `set_value` method on `LimitTracker`, and then check that
the mock object has the messages we expect. Listing 15-21 shows an attempt to
-implement a mock object to do just that, but the borrow checker won’t allow it:
+implement a mock object to do just that, but the borrow checker won’t allow it.
Filename: src/lib.rs
@@ -1286,28 +1327,31 @@ Filename: src/lib.rs
mod tests {
use super::*;
- [1] struct MockMessenger {
- [2] sent_messages: Vec<String>,
+ 1 struct MockMessenger {
+ 2 sent_messages: Vec<String>,
}
impl MockMessenger {
- [3] fn new() -> MockMessenger {
+ 3 fn new() -> MockMessenger {
MockMessenger {
sent_messages: vec![],
}
}
}
- [4] impl Messenger for MockMessenger {
+ 4 impl Messenger for MockMessenger {
fn send(&self, message: &str) {
- [5] self.sent_messages.push(String::from(message));
+ 5 self.sent_messages.push(String::from(message));
}
}
#[test]
- [6] fn it_sends_an_over_75_percent_warning_message() {
+ 6 fn it_sends_an_over_75_percent_warning_message() {
let mock_messenger = MockMessenger::new();
- let mut limit_tracker = LimitTracker::new(&mock_messenger, 100);
+ let mut limit_tracker = LimitTracker::new(
+ &mock_messenger,
+ 100
+ );
limit_tracker.set_value(80);
@@ -1329,37 +1373,40 @@ we can give a `MockMessenger` to a `LimitTracker`. In the definition of the
the `MockMessenger` list of `sent_messages`.
In the test, we’re testing what happens when the `LimitTracker` is told to set
-`value` to something that is more than 75 percent of the `max` value [6].
-First, we create a new `MockMessenger`, which will start with an empty list of
+`value` to something that is more than 75 percent of the `max` value [6]. First
+we create a new `MockMessenger`, which will start with an empty list of
messages. Then we create a new `LimitTracker` and give it a reference to the
-new `MockMessenger` and a `max` value of 100. We call the `set_value` method on
-the `LimitTracker` with a value of 80, which is more than 75 percent of 100.
-Then we assert that the list of messages that the `MockMessenger` is keeping
-track of should now have one message in it.
+new `MockMessenger` and a `max` value of `100`. We call the `set_value` method
+on the `LimitTracker` with a value of `80`, which is more than 75 percent of
+100. Then we assert that the list of messages that the `MockMessenger` is
+keeping track of should now have one message in it.
However, there’s one problem with this test, as shown here:
```
-error[E0596]: cannot borrow `self.sent_messages` as mutable, as it is behind a `&` reference
+error[E0596]: cannot borrow `self.sent_messages` as mutable, as it is behind a
+`&` reference
--> src/lib.rs:58:13
|
2 | fn send(&self, msg: &str);
- | ----- help: consider changing that to be a mutable reference: `&mut self`
+ | ----- help: consider changing that to be a mutable reference:
+`&mut self`
...
58 | self.sent_messages.push(String::from(message));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` is a
+`&` reference, so the data it refers to cannot be borrowed as mutable
```
-We can’t modify the `MockMessenger` to keep track of the messages, because the
+We can’t modify the `MockMessenger` to keep track of the messages because the
`send` method takes an immutable reference to `self`. We also can’t take the
-suggestion from the error text to use `&mut self` instead, because then the
+suggestion from the error text to use `&mut self` instead because then the
signature of `send` wouldn’t match the signature in the `Messenger` trait
-definition (feel free to try and see what error message you get).
+definition (feel free to try it and see what error message you get).
This is a situation in which interior mutability can help! We’ll store the
-`sent_messages` within a `RefCell<T>`, and then the `send` method will be
-able to modify `sent_messages` to store the messages we’ve seen. Listing 15-22
-shows what that looks like:
+`sent_messages` within a `RefCell<T>`, and then the `send` method will be able
+to modify `sent_messages` to store the messages we’ve seen. Listing 15-22 shows
+what that looks like.
Filename: src/lib.rs
@@ -1370,28 +1417,33 @@ mod tests {
use std::cell::RefCell;
struct MockMessenger {
- [1] sent_messages: RefCell<Vec<String>>,
+ 1 sent_messages: RefCell<Vec<String>>,
}
impl MockMessenger {
fn new() -> MockMessenger {
MockMessenger {
- sent_messages: RefCell::new(vec![]) [2],
+ 2 sent_messages: RefCell::new(vec![]),
}
}
}
impl Messenger for MockMessenger {
fn send(&self, message: &str) {
- [3] self.sent_messages.borrow_mut().push(String::from(message));
+ self.sent_messages
+ 3 .borrow_mut()
+ .push(String::from(message));
}
}
#[test]
fn it_sends_an_over_75_percent_warning_message() {
- // --snip--
+ --snip--
- [4] assert_eq!(mock_messenger.sent_messages.borrow().len(), 1);
+ assert_eq!(
+ 4 mock_messenger.sent_messages.borrow().len(),
+ 1
+ );
}
}
```
@@ -1406,9 +1458,9 @@ instance around the empty vector [2].
For the implementation of the `send` method, the first parameter is still an
immutable borrow of `self`, which matches the trait definition. We call
`borrow_mut` on the `RefCell<Vec<String>>` in `self.sent_messages` [3] to get a
-mutable reference to the value inside the `RefCell<Vec<String>>`, which is
-the vector. Then we can call `push` on the mutable reference to the vector to
-keep track of the messages sent during the test.
+mutable reference to the value inside the `RefCell<Vec<String>>`, which is the
+vector. Then we can call `push` on the mutable reference to the vector to keep
+track of the messages sent during the test.
The last change we have to make is in the assertion: to see how many items are
in the inner vector, we call `borrow` on the `RefCell<Vec<String>>` to get an
@@ -1416,7 +1468,7 @@ immutable reference to the vector [4].
Now that you’ve seen how to use `RefCell<T>`, let’s dig into how it works!
-#### Keeping Track of Borrows at Runtime with `RefCell<T>`
+#### Keeping Track of Borrows at Runtime with RefCell<T>
When creating immutable and mutable references, we use the `&` and `&mut`
syntax, respectively. With `RefCell<T>`, we use the `borrow` and `borrow_mut`
@@ -1428,7 +1480,7 @@ can treat them like regular references.
The `RefCell<T>` keeps track of how many `Ref<T>` and `RefMut<T>` smart
pointers are currently active. Every time we call `borrow`, the `RefCell<T>`
increases its count of how many immutable borrows are active. When a `Ref<T>`
-value goes out of scope, the count of immutable borrows goes down by one. Just
+value goes out of scope, the count of immutable borrows goes down by 1. Just
like the compile-time borrowing rules, `RefCell<T>` lets us have many immutable
borrows or one mutable borrow at any point in time.
@@ -1442,15 +1494,15 @@ at runtime.
Filename: src/lib.rs
```
- impl Messenger for MockMessenger {
- fn send(&self, message: &str) {
- let mut one_borrow = self.sent_messages.borrow_mut();
- let mut two_borrow = self.sent_messages.borrow_mut();
+impl Messenger for MockMessenger {
+ fn send(&self, message: &str) {
+ let mut one_borrow = self.sent_messages.borrow_mut();
+ let mut two_borrow = self.sent_messages.borrow_mut();
- one_borrow.push(String::from(message));
- two_borrow.push(String::from(message));
- }
+ one_borrow.push(String::from(message));
+ two_borrow.push(String::from(message));
}
+}
```
Listing 15-23: Creating two mutable references in the same scope to see that
@@ -1473,7 +1525,7 @@ BorrowMutError`. This is how `RefCell<T>` handles violations of the borrowing
rules at runtime.
Choosing to catch borrowing errors at runtime rather than compile time, as
-we've done here, means you'd potentially be finding mistakes in your code later
+we’ve done here, means you’d potentially be finding mistakes in your code later
in the development process: possibly not until your code was deployed to
production. Also, your code would incur a small runtime performance penalty as
a result of keeping track of the borrows at runtime rather than compile time.
@@ -1483,7 +1535,7 @@ in a context where only immutable values are allowed. You can use `RefCell<T>`
despite its trade-offs to get more functionality than regular references
provide.
-### Having Multiple Owners of Mutable Data by Combining `Rc<T>` and `RefCell<T>`
+### Allowing Multiple Owners of Mutable Data with Rc<T> and RefCell<T>
A common way to use `RefCell<T>` is in combination with `Rc<T>`. Recall that
`Rc<T>` lets you have multiple owners of some data, but it only gives immutable
@@ -1493,10 +1545,10 @@ get a value that can have multiple owners *and* that you can mutate!
For example, recall the cons list example in Listing 15-18 where we used
`Rc<T>` to allow multiple lists to share ownership of another list. Because
`Rc<T>` holds only immutable values, we can’t change any of the values in the
-list once we’ve created them. Let’s add in `RefCell<T>` to gain the ability to
+list once we’ve created them. Let’s add in `RefCell<T>` for its ability to
change the values in the lists. Listing 15-24 shows that by using a
`RefCell<T>` in the `Cons` definition, we can modify the value stored in all
-the lists:
+the lists.
Filename: src/main.rs
@@ -1512,14 +1564,14 @@ use std::cell::RefCell;
use std::rc::Rc;
fn main() {
- [1] let value = Rc::new(RefCell::new(5));
+ 1 let value = Rc::new(RefCell::new(5));
- [2] let a = Rc::new(Cons(Rc::clone(&value), Rc::new(Nil)));
+ 2 let a = Rc::new(Cons(Rc::clone(&value), Rc::new(Nil)));
let b = Cons(Rc::new(RefCell::new(3)), Rc::clone(&a));
let c = Cons(Rc::new(RefCell::new(4)), Rc::clone(&a));
- [3] *value.borrow_mut() += 10;
+ 3 *value.borrow_mut() += 10;
println!("a after = {:?}", a);
println!("b after = {:?}", b);
@@ -1541,13 +1593,13 @@ can both refer to `a`, which is what we did in Listing 15-18.
After we’ve created the lists in `a`, `b`, and `c`, we want to add 10 to the
value in `value` [3]. We do this by calling `borrow_mut` on `value`, which uses
-the automatic dereferencing feature we discussed in Chapter 5 (see the section
-“Where’s the `->` Operator?â€) to dereference the `Rc<T>` to the inner
-`RefCell<T>` value. The `borrow_mut` method returns a `RefMut<T>` smart
-pointer, and we use the dereference operator on it and change the inner value.
+the automatic dereferencing feature we discussed in “Where’s the -> Operator?â€
+on page XX to dereference the `Rc<T>` to the inner `RefCell<T>` value. The
+`borrow_mut` method returns a `RefMut<T>` smart pointer, and we use the
+dereference operator on it and change the inner value.
When we print `a`, `b`, and `c`, we can see that they all have the modified
-value of 15 rather than 5:
+value of `15` rather than `5`:
```
a after = Cons(RefCell { value: 15 }, Nil)
@@ -1561,7 +1613,7 @@ access to its interior mutability so we can modify our data when we need to.
The runtime checks of the borrowing rules protect us from data races, and it’s
sometimes worth trading a bit of speed for this flexibility in our data
structures. Note that `RefCell<T>` does not work for multithreaded code!
-`Mutex<T>` is the thread-safe version of `RefCell<T>` and we’ll discuss
+`Mutex<T>` is the thread-safe version of `RefCell<T>`, and we’ll discuss
`Mutex<T>` in Chapter 16.
## Reference Cycles Can Leak Memory
@@ -1579,7 +1631,7 @@ will never be dropped.
Let’s look at how a reference cycle might happen and how to prevent it,
starting with the definition of the `List` enum and a `tail` method in Listing
-15-25:
+15-25.
Filename: src/main.rs
@@ -1590,12 +1642,12 @@ use std::rc::Rc;
#[derive(Debug)]
enum List {
- [1] Cons(i32, RefCell<Rc<List>>),
+ 1 Cons(i32, RefCell<Rc<List>>),
Nil,
}
impl List {
- [2] fn tail(&self) -> Option<&RefCell<Rc<List>>> {
+ 2 fn tail(&self) -> Option<&RefCell<Rc<List>>> {
match self {
Cons(_, item) => Some(item),
Nil => None,
@@ -1610,9 +1662,9 @@ modify what a `Cons` variant is referring to
We’re using another variation of the `List` definition from Listing 15-5. The
second element in the `Cons` variant is now `RefCell<Rc<List>>` [1], meaning
that instead of having the ability to modify the `i32` value as we did in
-Listing 15-24, we want to modify the `List` value a `Cons` variant is
-pointing to. We’re also adding a `tail` method [2] to make it convenient for us
-to access the second item if we have a `Cons` variant.
+Listing 15-24, we want to modify the `List` value a `Cons` variant is pointing
+to. We’re also adding a `tail` method [2] to make it convenient for us to
+access the second item if we have a `Cons` variant.
In Listing 15-26, we’re adding a `main` function that uses the definitions in
Listing 15-25. This code creates a list in `a` and a list in `b` that points to
@@ -1624,23 +1676,32 @@ Filename: src/main.rs
```
fn main() {
- [1] let a = Rc::new(Cons(5, RefCell::new(Rc::new(Nil))));
+ 1 let a = Rc::new(Cons(5, RefCell::new(Rc::new(Nil))));
println!("a initial rc count = {}", Rc::strong_count(&a));
println!("a next item = {:?}", a.tail());
- [2] let b = Rc::new(Cons(10, RefCell::new(Rc::clone(&a))));
+ 2 let b = Rc::new(Cons(10, RefCell::new(Rc::clone(&a))));
- println!("a rc count after b creation = {}", Rc::strong_count(&a));
+ println!(
+ "a rc count after b creation = {}",
+ Rc::strong_count(&a)
+ );
println!("b initial rc count = {}", Rc::strong_count(&b));
println!("b next item = {:?}", b.tail());
- [3] if let Some(link) = a.tail() {
- [4] *link.borrow_mut() = Rc::clone(&b);
+ 3 if let Some(link) = a.tail() {
+ 4 *link.borrow_mut() = Rc::clone(&b);
}
- println!("b rc count after changing a = {}", Rc::strong_count(&b));
- println!("a rc count after changing a = {}", Rc::strong_count(&a));
+ println!(
+ "b rc count after changing a = {}",
+ Rc::strong_count(&b)
+ );
+ println!(
+ "a rc count after changing a = {}",
+ Rc::strong_count(&a)
+ );
// Uncomment the next line to see that we have a cycle;
// it will overflow the stack
@@ -1653,8 +1714,8 @@ other
We create an `Rc<List>` instance holding a `List` value in the variable `a`
with an initial list of `5, Nil` [1]. We then create an `Rc<List>` instance
-holding another `List` value in the variable `b` that contains the value 10 and
-points to the list in `a` [2].
+holding another `List` value in the variable `b` that contains the value `10`
+and points to the list in `a` [2].
We modify `a` so it points to `b` instead of `Nil`, creating a cycle. We do
that by using the `tail` method to get a reference to the `RefCell<Rc<List>>`
@@ -1675,30 +1736,28 @@ b rc count after changing a = 2
a rc count after changing a = 2
```
-The reference count of the `Rc<List>` instances in both `a` and `b` are 2 after
+The reference count of the `Rc<List>` instances in both `a` and `b` is 2 after
we change the list in `a` to point to `b`. At the end of `main`, Rust drops the
-variable `b`, which decreases the reference count of the `b` `Rc<List>` instance
-from 2 to 1. The memory that `Rc<List>` has on the heap won’t be dropped at
-this point, because its reference count is 1, not 0. Then Rust drops `a`, which
-decreases the reference count of the `a` `Rc<List>` instance from 2 to 1 as
-well. This instance’s memory can’t be dropped either, because the other
+variable `b`, which decreases the reference count of the `b` `Rc<List>`
+instance from 2 to 1. The memory that `Rc<List>` has on the heap won’t be
+dropped at this point because its reference count is 1, not 0. Then Rust drops
+`a`, which decreases the reference count of the `a` `Rc<List>` instance from 2
+to 1 as well. This instance’s memory can’t be dropped either, because the other
`Rc<List>` instance still refers to it. The memory allocated to the list will
remain uncollected forever. To visualize this reference cycle, we’ve created a
diagram in Figure 15-4.
-<img alt="Reference cycle of lists" src="img/trpl15-04.svg" class="center" />
-
Figure 15-4: A reference cycle of lists `a` and `b` pointing to each other
If you uncomment the last `println!` and run the program, Rust will try to
print this cycle with `a` pointing to `b` pointing to `a` and so forth until it
overflows the stack.
-Compared to a real-world program, the consequences creating a reference cycle
-in this example aren’t very dire: right after we create the reference cycle,
-the program ends. However, if a more complex program allocated lots of memory
-in a cycle and held onto it for a long time, the program would use more memory
-than it needed and might overwhelm the system, causing it to run out of
+Compared to a real-world program, the consequences of creating a reference
+cycle in this example aren’t very dire: right after we create the reference
+cycle, the program ends. However, if a more complex program allocated lots of
+memory in a cycle and held onto it for a long time, the program would use more
+memory than it needed and might overwhelm the system, causing it to run out of
available memory.
Creating reference cycles is not easily done, but it’s not impossible either.
@@ -1719,7 +1778,7 @@ Let’s look at an example using graphs made up of parent nodes and child nodes
to see when non-ownership relationships are an appropriate way to prevent
reference cycles.
-### Preventing Reference Cycles: Turning an `Rc<T>` into a `Weak<T>`
+### Preventing Reference Cycles Using Weak<T>
So far, we’ve demonstrated that calling `Rc::clone` increases the
`strong_count` of an `Rc<T>` instance, and an `Rc<T>` instance is only cleaned
@@ -1727,7 +1786,7 @@ up if its `strong_count` is 0. You can also create a *weak reference* to the
value within an `Rc<T>` instance by calling `Rc::downgrade` and passing a
reference to the `Rc<T>`. Strong references are how you can share ownership of
an `Rc<T>` instance. Weak references don’t express an ownership relationship,
-and their count doesn't affect when an `Rc<T>` instance is cleaned up. They
+and their count doesn’t affect when an `Rc<T>` instance is cleaned up. They
won’t cause a reference cycle because any cycle involving some weak references
will be broken once the strong reference count of values involved is 0.
@@ -1739,7 +1798,7 @@ Instead of increasing the `strong_count` in the `Rc<T>` instance by 1, calling
`Rc<T>` instance to be cleaned up.
Because the value that `Weak<T>` references might have been dropped, to do
-anything with the value that a `Weak<T>` is pointing to, you must make sure the
+anything with the value that a `Weak<T>` is pointing to you must make sure the
value still exists. Do this by calling the `upgrade` method on a `Weak<T>`
instance, which will return an `Option<Rc<T>>`. You’ll get a result of `Some`
if the `Rc<T>` value has not been dropped yet and a result of `None` if the
@@ -1751,7 +1810,7 @@ As an example, rather than using a list whose items know only about the next
item, we’ll create a tree whose items know about their children items *and*
their parent items.
-#### Creating a Tree Data Structure: a `Node` with Child Nodes
+#### Creating a Tree Data Structure: A Node with Child Nodes
To start, we’ll build a tree with nodes that know about their child nodes.
We’ll create a struct named `Node` that holds its own `i32` value as well as
@@ -1777,8 +1836,8 @@ modify which nodes are children of another node, so we have a `RefCell<T>` in
`children` around the `Vec<Rc<Node>>`.
Next, we’ll use our struct definition and create one `Node` instance named
-`leaf` with the value 3 and no children, and another instance named `branch`
-with the value 5 and `leaf` as one of its children, as shown in Listing 15-27:
+`leaf` with the value `3` and no children, and another instance named `branch`
+with the value `5` and `leaf` as one of its children, as shown in Listing 15-27.
Filename: src/main.rs
@@ -1810,7 +1869,7 @@ parent. We’ll do that next.
To make the child node aware of its parent, we need to add a `parent` field to
our `Node` struct definition. The trouble is in deciding what the type of
-`parent` should be. We know it can’t contain an `Rc<T>`, because that would
+`parent` should be. We know it can’t contain an `Rc<T>` because that would
create a reference cycle with `leaf.parent` pointing to `branch` and
`branch.children` pointing to `leaf`, which would cause their `strong_count`
values to never be 0.
@@ -1820,7 +1879,7 @@ children: if a parent node is dropped, its child nodes should be dropped as
well. However, a child should not own its parent: if we drop a child node, the
parent should still exist. This is a case for weak references!
-So instead of `Rc<T>`, we’ll make the type of `parent` use `Weak<T>`,
+So, instead of `Rc<T>`, we’ll make the type of `parent` use `Weak<T>`,
specifically a `RefCell<Weak<Node>>`. Now our `Node` struct definition looks
like this:
@@ -1838,35 +1897,41 @@ struct Node {
}
```
-A node will be able to refer to its parent node but doesn’t own its parent.
-In Listing 15-28, we update `main` to use this new definition so the `leaf`
-node will have a way to refer to its parent, `branch`:
+A node will be able to refer to its parent node but doesn’t own its parent. In
+Listing 15-28, we update `main` to use this new definition so the `leaf` node
+will have a way to refer to its parent, `branch`.
-Filename: src/main.rs
+Filename: src/main.rs
```
fn main() {
let leaf = Rc::new(Node {
value: 3,
- [1] parent: RefCell::new(Weak::new()),
+ 1 parent: RefCell::new(Weak::new()),
children: RefCell::new(vec![]),
});
- [2] println!("leaf parent = {:?}", leaf.parent.borrow().upgrade());
+ 2 println!(
+ "leaf parent = {:?}",
+ leaf.parent.borrow().upgrade()
+ );
let branch = Rc::new(Node {
value: 5,
- [3] parent: RefCell::new(Weak::new()),
+ 3 parent: RefCell::new(Weak::new()),
children: RefCell::new(vec![Rc::clone(&leaf)]),
});
- [4] *leaf.parent.borrow_mut() = Rc::downgrade(&branch);
+ 4 *leaf.parent.borrow_mut() = Rc::downgrade(&branch);
- [5] println!("leaf parent = {:?}", leaf.parent.borrow().upgrade());
+ 5 println!(
+ "leaf parent = {:?}",
+ leaf.parent.borrow().upgrade()
+ );
}
```
-Listing 15-28: A `leaf` node with a weak reference to its parent node `branch`
+Listing 15-28: A `leaf` node with a weak reference to its parent node, `branch`
Creating the `leaf` node looks similar to Listing 15-27 with the exception of
the `parent` field: `leaf` starts out without a parent, so we create a new,
@@ -1881,13 +1946,13 @@ leaf parent = None
```
When we create the `branch` node, it will also have a new `Weak<Node>`
-reference in the `parent` field [3], because `branch` doesn’t have a parent
+reference in the `parent` field [3] because `branch` doesn’t have a parent
node. We still have `leaf` as one of the children of `branch`. Once we have the
`Node` instance in `branch`, we can modify `leaf` to give it a `Weak<Node>`
reference to its parent [4]. We use the `borrow_mut` method on the
`RefCell<Weak<Node>>` in the `parent` field of `leaf`, and then we use the
`Rc::downgrade` function to create a `Weak<Node>` reference to `branch` from
-the `Rc<Node>` in `branch.`
+the `Rc<Node>` in `branch`.
When we print the parent of `leaf` again [5], this time we’ll get a `Some`
variant holding `branch`: now `leaf` can access its parent! When we print
@@ -1904,13 +1969,13 @@ The lack of infinite output indicates that this code didn’t create a reference
cycle. We can also tell this by looking at the values we get from calling
`Rc::strong_count` and `Rc::weak_count`.
-#### Visualizing Changes to `strong_count` and `weak_count`
+#### Visualizing Changes to strong_count and weak_count
Let’s look at how the `strong_count` and `weak_count` values of the `Rc<Node>`
instances change by creating a new inner scope and moving the creation of
`branch` into that scope. By doing so, we can see what happens when `branch` is
created and then dropped when it goes out of scope. The modifications are shown
-in Listing 15-29:
+in Listing 15-29.
Filename: src/main.rs
@@ -1922,13 +1987,13 @@ fn main() {
children: RefCell::new(vec![]),
});
- [1] println!(
+ 1 println!(
"leaf strong = {}, weak = {}",
Rc::strong_count(&leaf),
Rc::weak_count(&leaf),
);
- [2] {
+ 2 {
let branch = Rc::new(Node {
value: 5,
parent: RefCell::new(Weak::new()),
@@ -1937,21 +2002,24 @@ fn main() {
*leaf.parent.borrow_mut() = Rc::downgrade(&branch);
- [3] println!(
+ 3 println!(
"branch strong = {}, weak = {}",
Rc::strong_count(&branch),
Rc::weak_count(&branch),
);
- [4] println!(
+ 4 println!(
"leaf strong = {}, weak = {}",
Rc::strong_count(&leaf),
Rc::weak_count(&leaf),
);
- [5] }
+ 5 }
- [6] println!("leaf parent = {:?}", leaf.parent.borrow().upgrade());
- [7] println!(
+ 6 println!(
+ "leaf parent = {:?}",
+ leaf.parent.borrow().upgrade()
+ );
+ 7 println!(
"leaf strong = {}, weak = {}",
Rc::strong_count(&leaf),
Rc::weak_count(&leaf),
@@ -1967,7 +2035,7 @@ count of 0 [1]. In the inner scope [2], we create `branch` and associate it
with `leaf`, at which point when we print the counts [3], the `Rc<Node>` in
`branch` will have a strong count of 1 and a weak count of 1 (for `leaf.parent`
pointing to `branch` with a `Weak<Node>`). When we print the counts in `leaf`
-[4], we’ll see it will have a strong count of 2, because `branch` now has a
+[4], we’ll see it will have a strong count of 2 because `branch` now has a
clone of the `Rc<Node>` of `leaf` stored in `branch.children`, but will still
have a weak count of 0.
@@ -1978,7 +2046,7 @@ don’t get any memory leaks!
If we try to access the parent of `leaf` after the end of the scope, we’ll get
`None` again [6]. At the end of the program [7], the `Rc<Node>` in `leaf` has a
-strong count of 1 and a weak count of 0, because the variable `leaf` is now the
+strong count of 1 and a weak count of 0 because the variable `leaf` is now the
only reference to the `Rc<Node>` again.
All of the logic that manages the counts and value dropping is built into
@@ -2005,7 +2073,8 @@ memory leaks and how to prevent them using `Weak<T>`.
If this chapter has piqued your interest and you want to implement your own
smart pointers, check out “The Rustonomicon†at
-*https://doc.rust-lang.org/stable/nomicon/* for more useful information.
+*https://doc.rust-lang.org/stable/nomicon* for more useful information.
Next, we’ll talk about concurrency in Rust. You’ll even learn about a few new
smart pointers.
+
diff --git a/src/doc/book/nostarch/chapter16.md b/src/doc/book/nostarch/chapter16.md
index 1f404f84d..7c5389e4f 100644
--- a/src/doc/book/nostarch/chapter16.md
+++ b/src/doc/book/nostarch/chapter16.md
@@ -16,30 +16,6 @@ computers take advantage of their multiple processors. Historically,
programming in these contexts has been difficult and error prone: Rust hopes to
change that.
-<!-- Concurrent programming isn't necessarily helped by having multiple
-processors. How I've been teaching it is to distinguish the two by their
-workload: concurrent programming serves the needs of I/O-bound workloads and
-parallel programming serves the needs of CPU-bound workloads. If you give
-CPU bound workloads more CPUs, you have the opportunity to possibly go faster
-(assuming sufficient parallelism in the code). For I/O-bound workloads,
-rather than the need to have multiple processors, you need to be able to
-get as many I/O requests in flight and being processed as you can. This
-allows more I/O requests, and as a result better throughput/response time
-on those I/O requests.
-
-We could introduce these concepts and then simplify like we do in a bit to
-say that the design considerations of Rust allow both concurrency and
-parallelism to be done safely (...and for the remainder of the chapter talk
-about those design considerations rather than the specifics for either
-concurrency or parallelism) /JT -->
-<!-- I really don't want to get in the weeds on this because there are many
-other books and resources about concurrency and parallelism because these
-concepts aren't Rust specific. I want this to feel accessible to programmers
-who have never even considered whether their programs are I/O or CPU bound,
-because those are the types of programmers we want to empower (and make them
-feel empowered to create concurrent and/or parallel code) through Rust. So I'm
-deliberately choosing not to change anything here. /Carol -->
-
Initially, the Rust team thought that ensuring memory safety and preventing
concurrency problems were two separate challenges to be solved with different
methods. Over time, the team discovered that the ownership and type systems are
@@ -55,16 +31,16 @@ shipped to production. We’ve nicknamed this aspect of Rust *fearless*
subtle bugs and is easy to refactor without introducing new bugs.
> Note: For simplicity’s sake, we’ll refer to many of the problems as
-> *concurrent* rather than being more precise by saying *concurrent and/or
-> parallel*. If this book were about concurrency and/or parallelism, we’d be
-> more specific. For this chapter, please mentally substitute *concurrent
-> and/or parallel* whenever we use *concurrent*.
+*concurrent* rather than being more precise by saying *concurrent and/or
+parallel*. If this book were about concurrency and/or parallelism, we’d be more
+specific. For this chapter, please mentally substitute *concurrent and/or
+parallel* whenever we use *concurrent*.
Many languages are dogmatic about the solutions they offer for handling
concurrent problems. For example, Erlang has elegant functionality for
message-passing concurrency but has only obscure ways to share state between
threads. Supporting only a subset of possible solutions is a reasonable
-strategy for higher-level languages, because a higher-level language promises
+strategy for higher-level languages because a higher-level language promises
benefits from giving up some control to gain abstractions. However, lower-level
languages are expected to provide the solution with the best performance in any
given situation and have fewer abstractions over the hardware. Therefore, Rust
@@ -76,9 +52,9 @@ Here are the topics we’ll cover in this chapter:
* How to create threads to run multiple pieces of code at the same time
* *Message-passing* concurrency, where channels send messages between threads
* *Shared-state* concurrency, where multiple threads have access to some piece
- of data
+of data
* The `Sync` and `Send` traits, which extend Rust’s concurrency guarantees to
- user-defined types as well as types provided by the standard library
+user-defined types as well as types provided by the standard library
## Using Threads to Run Code Simultaneously
@@ -96,11 +72,11 @@ order in which parts of your code on different threads will run. This can lead
to problems, such as:
* Race conditions, where threads are accessing data or resources in an
- inconsistent order
+inconsistent order
* Deadlocks, where two threads are waiting for each other, preventing both
- threads from continuing
+threads from continuing
* Bugs that happen only in certain situations and are hard to reproduce and fix
- reliably
+reliably
Rust attempts to mitigate the negative effects of using threads, but
programming in a multithreaded context still takes careful thought and requires
@@ -112,14 +88,14 @@ operating systems provide an API the language can call for creating new
threads. The Rust standard library uses a *1:1* model of thread implementation,
whereby a program uses one operating system thread per one language thread.
There are crates that implement other models of threading that make different
-tradeoffs to the 1:1 model.
+trade-offs to the 1:1 model.
-### Creating a New Thread with `spawn`
+### Creating a New Thread with spawn
To create a new thread, we call the `thread::spawn` function and pass it a
closure (we talked about closures in Chapter 13) containing the code we want to
run in the new thread. The example in Listing 16-1 prints some text from a main
-thread and other text from a new thread:
+thread and other text from a new thread.
Filename: src/main.rs
@@ -130,13 +106,13 @@ use std::time::Duration;
fn main() {
thread::spawn(|| {
for i in 1..10 {
- println!("hi number {} from the spawned thread!", i);
+ println!("hi number {i} from the spawned thread!");
thread::sleep(Duration::from_millis(1));
}
});
for i in 1..5 {
- println!("hi number {} from the main thread!", i);
+ println!("hi number {i} from the main thread!");
thread::sleep(Duration::from_millis(1));
}
}
@@ -174,19 +150,20 @@ If you run this code and only see output from the main thread, or don’t see an
overlap, try increasing the numbers in the ranges to create more opportunities
for the operating system to switch between the threads.
-### Waiting for All Threads to Finish Using `join` Handles
+### Waiting for All Threads to Finish Using join Handles
The code in Listing 16-1 not only stops the spawned thread prematurely most of
the time due to the main thread ending, but because there is no guarantee on
the order in which threads run, we also can’t guarantee that the spawned thread
will get to run at all!
-We can fix the problem of the spawned thread not running or ending prematurely
-by saving the return value of `thread::spawn` in a variable. The return type of
-`thread::spawn` is `JoinHandle`. A `JoinHandle` is an owned value that, when we
-call the `join` method on it, will wait for its thread to finish. Listing 16-2
-shows how to use the `JoinHandle` of the thread we created in Listing 16-1 and
-call `join` to make sure the spawned thread finishes before `main` exits:
+We can fix the problem of the spawned thread not running or of it ending
+prematurely by saving the return value of `thread::spawn` in a variable. The
+return type of `thread::spawn` is `JoinHandle<T>`. A `JoinHandle<T>` is an
+owned value that, when we call the `join` method on it, will wait for its
+thread to finish. Listing 16-2 shows how to use the `JoinHandle<T>` of the
+thread we created in Listing 16-1 and call `join` to make sure the spawned
+thread finishes before `main` exits.
Filename: src/main.rs
@@ -197,13 +174,13 @@ use std::time::Duration;
fn main() {
let handle = thread::spawn(|| {
for i in 1..10 {
- println!("hi number {} from the spawned thread!", i);
+ println!("hi number {i} from the spawned thread!");
thread::sleep(Duration::from_millis(1));
}
});
for i in 1..5 {
- println!("hi number {} from the main thread!", i);
+ println!("hi number {i} from the main thread!");
thread::sleep(Duration::from_millis(1));
}
@@ -211,7 +188,7 @@ fn main() {
}
```
-Listing 16-2: Saving a `JoinHandle` from `thread::spawn` to guarantee the
+Listing 16-2: Saving a `JoinHandle<T>` from `thread::spawn` to guarantee the
thread is run to completion
Calling `join` on the handle blocks the thread currently running until the
@@ -251,7 +228,7 @@ use std::time::Duration;
fn main() {
let handle = thread::spawn(|| {
for i in 1..10 {
- println!("hi number {} from the spawned thread!", i);
+ println!("hi number {i} from the spawned thread!");
thread::sleep(Duration::from_millis(1));
}
});
@@ -259,7 +236,7 @@ fn main() {
handle.join().unwrap();
for i in 1..5 {
- println!("hi number {} from the main thread!", i);
+ println!("hi number {i} from the main thread!");
thread::sleep(Duration::from_millis(1));
}
}
@@ -287,21 +264,21 @@ hi number 4 from the main thread!
Small details, such as where `join` is called, can affect whether or not your
threads run at the same time.
-### Using `move` Closures with Threads
+### Using move Closures with Threads
-We'll often use the `move` keyword with closures passed to `thread::spawn`
+We’ll often use the `move` keyword with closures passed to `thread::spawn`
because the closure will then take ownership of the values it uses from the
environment, thus transferring ownership of those values from one thread to
-another. In the “Capturing the Environment with Closures†section of Chapter
-13, we discussed `move` in the context of closures. Now, we’ll concentrate more
-on the interaction between `move` and `thread::spawn`.
+another. In “Capturing the Environment with Closures†on page XX, we discussed
+`move` in the context of closures. Now we’ll concentrate more on the
+interaction between `move` and `thread::spawn`.
Notice in Listing 16-1 that the closure we pass to `thread::spawn` takes no
arguments: we’re not using any data from the main thread in the spawned
thread’s code. To use data from the main thread in the spawned thread, the
spawned thread’s closure must capture the values it needs. Listing 16-3 shows
an attempt to create a vector in the main thread and use it in the spawned
-thread. However, this won’t yet work, as you’ll see in a moment.
+thread. However, this won’t work yet, as you’ll see in a moment.
Filename: src/main.rs
@@ -328,7 +305,8 @@ should be able to access `v` inside that new thread. But when we compile this
example, we get the following error:
```
-error[E0373]: closure may outlive the current function, but it borrows `v`, which is owned by the current function
+error[E0373]: closure may outlive the current function, but it borrows `v`,
+which is owned by the current function
--> src/main.rs:6:32
|
6 | let handle = thread::spawn(|| {
@@ -344,7 +322,8 @@ note: function requires argument type to outlive `'static`
7 | | println!("Here's a vector: {:?}", v);
8 | | });
| |______^
-help: to force the closure to take ownership of `v` (and any other referenced variables), use the `move` keyword
+help: to force the closure to take ownership of `v` (and any other referenced
+variables), use the `move` keyword
|
6 | let handle = thread::spawn(move || {
| ++++
@@ -352,11 +331,11 @@ help: to force the closure to take ownership of `v` (and any other referenced va
Rust *infers* how to capture `v`, and because `println!` only needs a reference
to `v`, the closure tries to borrow `v`. However, there’s a problem: Rust can’t
-tell how long the spawned thread will run, so it doesn’t know if the reference
-to `v` will always be valid.
+tell how long the spawned thread will run, so it doesn’t know whether the
+reference to `v` will always be valid.
Listing 16-4 provides a scenario that’s more likely to have a reference to `v`
-that won’t be valid:
+that won’t be valid.
Filename: src/main.rs
@@ -379,10 +358,10 @@ fn main() {
Listing 16-4: A thread with a closure that attempts to capture a reference to
`v` from a main thread that drops `v`
-If Rust allowed us to run this code, there’s a possibility the spawned thread
-would be immediately put in the background without running at all. The spawned
-thread has a reference to `v` inside, but the main thread immediately drops
-`v`, using the `drop` function we discussed in Chapter 15. Then, when the
+If Rust allowed us to run this code, there’s a possibility that the spawned
+thread would be immediately put in the background without running at all. The
+spawned thread has a reference to `v` inside, but the main thread immediately
+drops `v`, using the `drop` function we discussed in Chapter 15. Then, when the
spawned thread starts to execute, `v` is no longer valid, so a reference to it
is also invalid. Oh no!
@@ -390,7 +369,8 @@ To fix the compiler error in Listing 16-3, we can use the error message’s
advice:
```
-help: to force the closure to take ownership of `v` (and any other referenced variables), use the `move` keyword
+help: to force the closure to take ownership of `v` (and any other referenced
+variables), use the `move` keyword
|
6 | let handle = thread::spawn(move || {
| ++++
@@ -399,7 +379,7 @@ help: to force the closure to take ownership of `v` (and any other referenced va
By adding the `move` keyword before the closure, we force the closure to take
ownership of the values it’s using rather than allowing Rust to infer that it
should borrow the values. The modification to Listing 16-3 shown in Listing
-16-5 will compile and run as we intend:
+16-5 will compile and run as we intend.
Filename: src/main.rs
@@ -432,12 +412,14 @@ error[E0382]: use of moved value: `v`
--> src/main.rs:10:10
|
4 | let v = vec![1, 2, 3];
- | - move occurs because `v` has type `Vec<i32>`, which does not implement the `Copy` trait
+ | - move occurs because `v` has type `Vec<i32>`, which does not
+implement the `Copy` trait
5 |
6 | let handle = thread::spawn(move || {
| ------- value moved into closure here
7 | println!("Here's a vector: {:?}", v);
- | - variable moved due to use in closure
+ | - variable moved due to use in
+closure
...
10 | drop(v); // oh no!
| ^ value used here after move
@@ -453,38 +435,18 @@ rules when we try to use `v` in the main thread. The `move` keyword overrides
Rust’s conservative default of borrowing; it doesn’t let us violate the
ownership rules.
-With a basic understanding of threads and the thread API, let’s look at what we
-can *do* with threads.
+Now that we’ve covered what threads are and the methods supplied by the thread
+API, let’s look at some situations in which we can use threads.
## Using Message Passing to Transfer Data Between Threads
One increasingly popular approach to ensuring safe concurrency is *message
passing*, where threads or actors communicate by sending each other messages
-containing data. Here’s the idea in a slogan from the Go language
-documentation at *https://golang.org/doc/effective_go.html#concurrency*:
-“Do not communicate by sharing memory; instead, share memory by communicating.â€
-
-<!-- are they communicating to decide which thread should be running, or by
-"communicate" do we just mean sharing data? /LC -->
-<!-- Just sharing data. Is there something that should be clarified here? I'm
-not sure what to do because this paragraph doesn't mention deciding which
-thread should be running, it only mentions sharing data, so I'm not sure where
-the possible confusion is coming from. /Carol -->
-<!-- JT, if this will be already obvious to a reader, no changes needed. I just
-wanted to ensure there was no potential confusion around what is being
-communicated /LC -->
-<!-- I like that we want to give a shout-out to Go's thinking process when
-we align, though I made a bit of a face reading the quote. "Share memory" is a
-such a loaded concept that I think people might stumble a bit over the play on
-the technical words.
-
-Funnily the next line following that quote in the Go book is:
-
-"This approach can be taken too far." :D
-/JT -->
-<!-- I think this means JT is fine leaving this the way it is! /Carol -->
-
-To accomplish message-sending concurrency, Rust's standard library provides an
+containing data. Here’s the idea in a slogan from the Go language documentation
+at *https://golang.org/doc/effective_go.html#concurrency*: “Do not communicate
+by sharing memory; instead, share memory by communicating.â€
+
+To accomplish message-sending concurrency, Rust’s standard library provides an
implementation of *channels*. A channel is a general programming concept by
which data is sent from one thread to another.
@@ -493,7 +455,7 @@ water, such as a stream or a river. If you put something like a rubber duck
into a river, it will travel downstream to the end of the waterway.
A channel has two halves: a transmitter and a receiver. The transmitter half is
-the upstream location where you put rubber ducks into the river, and the
+the upstream location where you put the rubber duck into the river, and the
receiver half is where the rubber duck ends up downstream. One part of your
code calls methods on the transmitter with the data you want to send, and
another part checks the receiving end for arriving messages. A channel is said
@@ -503,9 +465,9 @@ Here, we’ll work up to a program that has one thread to generate values and
send them down a channel, and another thread that will receive the values and
print them out. We’ll be sending simple values between threads using a channel
to illustrate the feature. Once you’re familiar with the technique, you could
-use channels for any threads that needs to communicate between each other, such
-as a chat system or a system where many threads perform parts of a calculation
-and send the parts to one thread that aggregates the results.
+use channels for any threads that need to communicate with each other, such as
+a chat system or a system where many threads perform parts of a calculation and
+send the parts to one thread that aggregates the results.
First, in Listing 16-6, we’ll create a channel but not do anything with it.
Note that this won’t compile yet because Rust can’t tell what type of values we
@@ -533,14 +495,14 @@ producer for now, but we’ll add multiple producers when we get this example
working.
The `mpsc::channel` function returns a tuple, the first element of which is the
-sending end--the transmitter--and the second element is the receiving end--the
-receiver. The abbreviations `tx` and `rx` are traditionally used in many fields
-for *transmitter* and *receiver* respectively, so we name our variables as such
-to indicate each end. We’re using a `let` statement with a pattern that
-destructures the tuples; we’ll discuss the use of patterns in `let` statements
-and destructuring in Chapter 18. For now, know that using a `let` statement
-this way is a convenient approach to extract the pieces of the tuple returned
-by `mpsc::channel`.
+sending end—the transmitter—and the second element of which is the receiving
+end—the receiver. The abbreviations `tx` and `rx` are traditionally used in
+many fields for *transmitter* and *receiver*, respectively, so we name our
+variables as such to indicate each end. We’re using a `let` statement with a
+pattern that destructures the tuples; we’ll discuss the use of patterns in
+`let` statements and destructuring in Chapter 18. For now, know that using a
+`let` statement in this way is a convenient approach to extract the pieces of
+the tuple returned by `mpsc::channel`.
Let’s move the transmitting end into a spawned thread and have it send one
string so the spawned thread is communicating with the main thread, as shown in
@@ -563,18 +525,18 @@ fn main() {
}
```
-Listing 16-7: Moving `tx` to a spawned thread and sending “hiâ€
+Listing 16-7: Moving `tx` to a spawned thread and sending `"hi"`
Again, we’re using `thread::spawn` to create a new thread and then using `move`
to move `tx` into the closure so the spawned thread owns `tx`. The spawned
thread needs to own the transmitter to be able to send messages through the
channel.
-The transmitter has a `send` method that takes the value we want to send.
-The `send` method returns a `Result<T, E>` type, so if the receiver has
-already been dropped and there’s nowhere to send a value, the send operation
-will return an error. In this example, we’re calling `unwrap` to panic in case
-of an error. But in a real application, we would handle it properly: return to
+The transmitter has a `send` method that takes the value we want to send. The
+`send` method returns a `Result<T, E>` type, so if the receiver has already
+been dropped and there’s nowhere to send a value, the send operation will
+return an error. In this example, we’re calling `unwrap` to panic in case of an
+error. But in a real application, we would handle it properly: return to
Chapter 9 to review strategies for proper error handling.
In Listing 16-8, we’ll get the value from the receiver in the main thread. This
@@ -596,11 +558,11 @@ fn main() {
});
let received = rx.recv().unwrap();
- println!("Got: {}", received);
+ println!("Got: {received}");
}
```
-Listing 16-8: Receiving the value “hi†in the main thread and printing it
+Listing 16-8: Receiving the value `"hi"` in the main thread and printing it
The receiver has two useful methods: `recv` and `try_recv`. We’re using `recv`,
short for *receive*, which will block the main thread’s execution and wait
@@ -637,7 +599,7 @@ advantage of thinking about ownership throughout your Rust programs. Let’s do
an experiment to show how channels and ownership work together to prevent
problems: we’ll try to use a `val` value in the spawned thread *after* we’ve
sent it down the channel. Try compiling the code in Listing 16-9 to see why
-this code isn’t allowed:
+this code isn’t allowed.
Filename: src/main.rs
@@ -651,11 +613,11 @@ fn main() {
thread::spawn(move || {
let val = String::from("hi");
tx.send(val).unwrap();
- println!("val is {}", val);
+ println!("val is {val}");
});
let received = rx.recv().unwrap();
- println!("Got: {}", received);
+ println!("Got: {received}");
}
```
@@ -673,15 +635,16 @@ error[E0382]: borrow of moved value: `val`
--> src/main.rs:10:31
|
8 | let val = String::from("hi");
- | --- move occurs because `val` has type `String`, which does not implement the `Copy` trait
+ | --- move occurs because `val` has type `String`, which does
+not implement the `Copy` trait
9 | tx.send(val).unwrap();
| --- value moved here
-10 | println!("val is {}", val);
- | ^^^ value borrowed here after move
+10 | println!("val is {val}");
+ | ^^^ value borrowed here after move
```
-Our concurrency mistake has caused a compile time error. The `send` function
-takes ownership of its parameter, and when the value is moved, the receiver
+Our concurrency mistake has caused a compile-time error. The `send` function
+takes ownership of its parameter, and when the value is moved the receiver
takes ownership of it. This stops us from accidentally using the value again
after sending it; the ownership system checks that everything is okay.
@@ -718,24 +681,24 @@ fn main() {
});
for received in rx {
- println!("Got: {}", received);
+ println!("Got: {received}");
}
}
```
-Listing 16-10: Sending multiple messages and pausing between each
+Listing 16-10: Sending multiple messages and pausing between each one
This time, the spawned thread has a vector of strings that we want to send to
the main thread. We iterate over them, sending each individually, and pause
between each by calling the `thread::sleep` function with a `Duration` value of
-1 second.
+one second.
In the main thread, we’re not calling the `recv` function explicitly anymore:
instead, we’re treating `rx` as an iterator. For each value received, we’re
printing it. When the channel is closed, iteration will end.
When running the code in Listing 16-10, you should see the following output
-with a 1-second pause in between each line:
+with a one-second pause in between each line:
```
Got: hi
@@ -750,52 +713,52 @@ the spawned thread.
### Creating Multiple Producers by Cloning the Transmitter
-Earlier we mentioned that `mpsc` was an acronym for *multiple producer,
-single consumer*. Let’s put `mpsc` to use and expand the code in Listing 16-10
-to create multiple threads that all send values to the same receiver. We can do
-so by cloning the transmitter, as shown in Listing 16-11:
+Earlier we mentioned that `mpsc` was an acronym for *multiple producer, single
+consumer*. Let’s put `mpsc` to use and expand the code in Listing 16-10 to
+create multiple threads that all send values to the same receiver. We can do so
+by cloning the transmitter, as shown in Listing 16-11.
Filename: src/main.rs
```
- // --snip--
-
- let (tx, rx) = mpsc::channel();
-
- let tx1 = tx.clone();
- thread::spawn(move || {
- let vals = vec![
- String::from("hi"),
- String::from("from"),
- String::from("the"),
- String::from("thread"),
- ];
-
- for val in vals {
- tx1.send(val).unwrap();
- thread::sleep(Duration::from_secs(1));
- }
- });
+--snip--
+
+let (tx, rx) = mpsc::channel();
+
+let tx1 = tx.clone();
+thread::spawn(move || {
+ let vals = vec![
+ String::from("hi"),
+ String::from("from"),
+ String::from("the"),
+ String::from("thread"),
+ ];
+
+ for val in vals {
+ tx1.send(val).unwrap();
+ thread::sleep(Duration::from_secs(1));
+ }
+});
- thread::spawn(move || {
- let vals = vec![
- String::from("more"),
- String::from("messages"),
- String::from("for"),
- String::from("you"),
- ];
+thread::spawn(move || {
+ let vals = vec![
+ String::from("more"),
+ String::from("messages"),
+ String::from("for"),
+ String::from("you"),
+ ];
- for val in vals {
- tx.send(val).unwrap();
- thread::sleep(Duration::from_secs(1));
- }
- });
-
- for received in rx {
- println!("Got: {}", received);
+ for val in vals {
+ tx.send(val).unwrap();
+ thread::sleep(Duration::from_secs(1));
}
+});
+
+for received in rx {
+ println!("Got: {received}");
+}
- // --snip--
+--snip--
```
Listing 16-11: Sending multiple messages from multiple producers
@@ -828,22 +791,17 @@ concurrency.
## Shared-State Concurrency
-Message passing is a fine way of handling concurrency, but it’s not the only
-one. Another method would be for multiple threads to access the same shared
-data. Consider this part of the slogan from the Go language documentation
-again: “do not communicate by sharing memory.â€
-
-<!-- NB: if we decide to do anything with the Go quote above, we also
-reference it here.
-/JT -->
-<!-- Also not changing anything here. /Carol -->
+Message passing is a fine way to handle concurrency, but it’s not the only way.
+Another method would be for multiple threads to access the same shared data.
+Consider this part of the slogan from the Go language documentation again: “Do
+not communicate by sharing memory.â€
What would communicating by sharing memory look like? In addition, why would
message-passing enthusiasts caution not to use memory sharing?
-In a way, channels in any programming language are similar to single ownership,
+In a way, channels in any programming language are similar to single ownership
because once you transfer a value down a channel, you should no longer use that
-value. Shared memory concurrency is like multiple ownership: multiple threads
+value. Shared-memory concurrency is like multiple ownership: multiple threads
can access the same memory location at the same time. As you saw in Chapter 15,
where smart pointers made multiple ownership possible, multiple ownership can
add complexity because these different owners need managing. Rust’s type system
@@ -853,7 +811,7 @@ for shared memory.
### Using Mutexes to Allow Access to Data from One Thread at a Time
-*Mutex* is an abbreviation for *mutual exclusion*, as in, a mutex allows only
+*Mutex* is an abbreviation for *mutual exclusion*, as in a mutex allows only
one thread to access some data at any given time. To access the data in a
mutex, a thread must first signal that it wants access by asking to acquire the
mutex’s *lock*. The lock is a data structure that is part of the mutex that
@@ -863,9 +821,9 @@ mutex is described as *guarding* the data it holds via the locking system.
Mutexes have a reputation for being difficult to use because you have to
remember two rules:
-* You must attempt to acquire the lock before using the data.
-* When you’re done with the data that the mutex guards, you must unlock the
- data so other threads can acquire the lock.
+1. You must attempt to acquire the lock before using the data.
+1. When you’re done with the data that the mutex guards, you must unlock the
+data so other threads can acquire the lock.
For a real-world metaphor for a mutex, imagine a panel discussion at a
conference with only one microphone. Before a panelist can speak, they have to
@@ -880,10 +838,10 @@ Management of mutexes can be incredibly tricky to get right, which is why so
many people are enthusiastic about channels. However, thanks to Rust’s type
system and ownership rules, you can’t get locking and unlocking wrong.
-#### The API of `Mutex<T>`
+#### The API of Mutex<T>
As an example of how to use a mutex, let’s start by using a mutex in a
-single-threaded context, as shown in Listing 16-12:
+single-threaded context, as shown in Listing 16-12.
Filename: src/main.rs
@@ -891,14 +849,14 @@ Filename: src/main.rs
use std::sync::Mutex;
fn main() {
- [1] let m = Mutex::new(5);
+ 1 let m = Mutex::new(5);
{
- [2] let mut num = m.lock().unwrap();
- [3] *num = 6;
- [4] }
+ 2 let mut num = m.lock().unwrap();
+ 3 *num = 6;
+ 4 }
- [5] println!("m = {:?}", m);
+ 5 println!("m = {:?}", m);
}
```
@@ -928,19 +886,19 @@ pointer implements `Deref` to point at our inner data; the smart pointer also
has a `Drop` implementation that releases the lock automatically when a
`MutexGuard` goes out of scope, which happens at the end of the inner scope
[4]. As a result, we don’t risk forgetting to release the lock and blocking the
-mutex from being used by other threads, because the lock release happens
+mutex from being used by other threads because the lock release happens
automatically.
After dropping the lock, we can print the mutex value and see that we were able
-to change the inner `i32` to 6 [5].
+to change the inner `i32` to `6` [5].
-#### Sharing a `Mutex<T>` Between Multiple Threads
+#### Sharing a Mutex<T> Between Multiple Threads
-Now, let’s try to share a value between multiple threads using `Mutex<T>`.
-We’ll spin up 10 threads and have them each increment a counter value by 1, so
-the counter goes from 0 to 10. The next example in Listing 16-13 will have
-a compiler error, and we’ll use that error to learn more about using
-`Mutex<T>` and how Rust helps us use it correctly.
+Now let’s try to share a value between multiple threads using `Mutex<T>`. We’ll
+spin up 10 threads and have them each increment a counter value by 1, so the
+counter goes from 0 to 10. The example in Listing 16-13 will have a compiler
+error, and we’ll use that error to learn more about using `Mutex<T>` and how
+Rust helps us use it correctly.
Filename: src/main.rs
@@ -949,27 +907,27 @@ use std::sync::Mutex;
use std::thread;
fn main() {
- [1] let counter = Mutex::new(0);
+ 1 let counter = Mutex::new(0);
let mut handles = vec![];
- [2] for _ in 0..10 {
- [3] let handle = thread::spawn(move || {
- [4] let mut num = counter.lock().unwrap();
+ 2 for _ in 0..10 {
+ 3 let handle = thread::spawn(move || {
+ 4 let mut num = counter.lock().unwrap();
- [5] *num += 1;
+ 5 *num += 1;
});
- [6] handles.push(handle);
+ 6 handles.push(handle);
}
for handle in handles {
- [7] handle.join().unwrap();
+ 7 handle.join().unwrap();
}
- [8] println!("Result: {}", *counter.lock().unwrap());
+ 8 println!("Result: {}", *counter.lock().unwrap());
}
```
-Listing 16-13: Ten threads each increment a counter guarded by a `Mutex<T>`
+Listing 16-13: Ten threads, each incrementing a counter guarded by a `Mutex<T>`
We create a `counter` variable to hold an `i32` inside a `Mutex<T>` [1], as we
did in Listing 16-12. Next, we create 10 threads by iterating over a range of
@@ -991,22 +949,24 @@ error[E0382]: use of moved value: `counter`
--> src/main.rs:9:36
|
5 | let counter = Mutex::new(0);
- | ------- move occurs because `counter` has type `Mutex<i32>`, which does not implement the `Copy` trait
+ | ------- move occurs because `counter` has type `Mutex<i32>`, which
+does not implement the `Copy` trait
...
9 | let handle = thread::spawn(move || {
- | ^^^^^^^ value moved into closure here, in previous iteration of loop
+ | ^^^^^^^ value moved into closure here,
+in previous iteration of loop
10 | let mut num = counter.lock().unwrap();
| ------- use occurs due to use in closure
```
The error message states that the `counter` value was moved in the previous
-iteration of the loop. Rust is telling us that we can’t move the ownership
-of lock `counter` into multiple threads. Let’s fix the compiler error with a
+iteration of the loop. Rust is telling us that we can’t move the ownership of
+lock `counter` into multiple threads. Let’s fix the compiler error with the
multiple-ownership method we discussed in Chapter 15.
#### Multiple Ownership with Multiple Threads
-In Chapter 15, we gave a value multiple owners by using the smart pointer
+In Chapter 15, we gave a value to multiple owners by using the smart pointer
`Rc<T>` to create a reference counted value. Let’s do the same here and see
what happens. We’ll wrap the `Mutex<T>` in `Rc<T>` in Listing 16-14 and clone
the `Rc<T>` before moving ownership to the thread.
@@ -1043,33 +1003,36 @@ fn main() {
Listing 16-14: Attempting to use `Rc<T>` to allow multiple threads to own the
`Mutex<T>`
-Once again, we compile and get... different errors! The compiler is teaching us
-a lot.
+Once again, we compile and get… different errors! The compiler is teaching us a
+lot.
```
-[1] error[E0277]: `Rc<Mutex<i32>>` cannot be sent between threads safely
+error[E0277]: `Rc<Mutex<i32>>` cannot be sent between threads safely 1
--> src/main.rs:11:22
|
11 | let handle = thread::spawn(move || {
| ______________________^^^^^^^^^^^^^_-
| | |
- | | `Rc<Mutex<i32>>` cannot be sent between threads safely
+ | | `Rc<Mutex<i32>>` cannot be sent between threads
+safely
12 | | let mut num = counter.lock().unwrap();
13 | |
14 | | *num += 1;
15 | | });
| |_________- within this `[closure@src/main.rs:11:36: 15:10]`
|
-[2] = help: within `[closure@src/main.rs:11:36: 15:10]`, the trait `Send` is not implemented for `Rc<Mutex<i32>>`
- = note: required because it appears within the type `[closure@src/main.rs:11:36: 15:10]`
+= help: within `[closure@src/main.rs:11:36: 15:10]`, the trait `Send` is not
+implemented for `Rc<Mutex<i32>>` 2
+ = note: required because it appears within the type
+`[closure@src/main.rs:11:36: 15:10]`
note: required by a bound in `spawn`
```
Wow, that error message is very wordy! Here’s the important part to focus on:
-`` `Rc<Mutex<i32>>` cannot be sent between threads safely `` [1]. The compiler
-is also telling us the reason why: ``the trait `Send` is not implemented for
-`Rc<Mutex<i32>>` `` [2]. We’ll talk about `Send` in the next section: it’s one
-of the traits that ensures the types we use with threads are meant for use in
+``Rc<Mutex<i32>>` cannot be sent between threads safely` [1]. The compiler is
+also telling us the reason why: `the trait `Send` is not implemented for
+`Rc<Mutex<i32>>`` [2]. We’ll talk about `Send` in the next section: it’s one of
+the traits that ensures the types we use with threads are meant for use in
concurrent situations.
Unfortunately, `Rc<T>` is not safe to share across threads. When `Rc<T>`
@@ -1081,7 +1044,7 @@ could in turn lead to memory leaks or a value being dropped before we’re done
with it. What we need is a type exactly like `Rc<T>` but one that makes changes
to the reference count in a thread-safe way.
-#### Atomic Reference Counting with `Arc<T>`
+#### Atomic Reference Counting with Arc<T>
Fortunately, `Arc<T>` *is* a type like `Rc<T>` that is safe to use in
concurrent situations. The *a* stands for *atomic*, meaning it’s an *atomically
@@ -1100,7 +1063,7 @@ guarantees atomics provide.
Let’s return to our example: `Arc<T>` and `Rc<T>` have the same API, so we fix
our program by changing the `use` line, the call to `new`, and the call to
-`clone`. The code in Listing 16-15 will finally compile and run:
+`clone`. The code in Listing 16-15 will finally compile and run.
Filename: src/main.rs
@@ -1152,12 +1115,7 @@ standard library. These types provide safe, concurrent, atomic access to
primitive types. We chose to use `Mutex<T>` with a primitive type for this
example so we could concentrate on how `Mutex<T>` works.
-<!-- Do we want to mention that for simple counters we have simpler types in
-the standard library? (eg, AtomicI64 for the above)
-/JT -->
-<!-- Done! /Carol-->
-
-### Similarities Between `RefCell<T>`/`Rc<T>` and `Mutex<T>`/`Arc<T>`
+### Similarities Between RefCell<T>/Rc<T> and Mutex<T>/Arc<T>
You might have noticed that `counter` is immutable but we could get a mutable
reference to the value inside it; this means `Mutex<T>` provides interior
@@ -1180,7 +1138,7 @@ useful information.
We’ll round out this chapter by talking about the `Send` and `Sync` traits and
how we can use them with custom types.
-## Extensible Concurrency with the `Sync` and `Send` Traits
+## Extensible Concurrency with the Send and Sync Traits
Interestingly, the Rust language has *very* few concurrency features. Almost
every concurrency feature we’ve talked about so far in this chapter has been
@@ -1189,9 +1147,9 @@ concurrency are not limited to the language or the standard library; you can
write your own concurrency features or use those written by others.
However, two concurrency concepts are embedded in the language: the
-`std::marker` traits `Sync` and `Send`.
+`std::marker` traits `Send` and `Sync` .
-### Allowing Transference of Ownership Between Threads with `Send`
+### Allowing Transference of Ownership Between Threads with Send
The `Send` marker trait indicates that ownership of values of the type
implementing `Send` can be transferred between threads. Almost every Rust type
@@ -1204,15 +1162,15 @@ performance penalty.
Therefore, Rust’s type system and trait bounds ensure that you can never
accidentally send an `Rc<T>` value across threads unsafely. When we tried to do
-this in Listing 16-14, we got the error `the trait Send is not implemented for
-Rc<Mutex<i32>>`. When we switched to `Arc<T>`, which is `Send`, the code
+this in Listing 16-14, we got the error `the trait `Send` is not implemented
+for `Rc<Mutex<i32>>``. When we switched to `Arc<T>`, which is `Send`, the code
compiled.
Any type composed entirely of `Send` types is automatically marked as `Send` as
well. Almost all primitive types are `Send`, aside from raw pointers, which
we’ll discuss in Chapter 19.
-### Allowing Access from Multiple Threads with `Sync`
+### Allowing Access from Multiple Threads with Sync
The `Sync` marker trait indicates that it is safe for the type implementing
`Sync` to be referenced from multiple threads. In other words, any type `T` is
@@ -1225,10 +1183,9 @@ The smart pointer `Rc<T>` is also not `Sync` for the same reasons that it’s no
family of related `Cell<T>` types are not `Sync`. The implementation of borrow
checking that `RefCell<T>` does at runtime is not thread-safe. The smart
pointer `Mutex<T>` is `Sync` and can be used to share access with multiple
-threads as you saw in the “Sharing a `Mutex<T>` Between Multiple
-Threads†section.
+threads, as you saw in “Sharing a Mutex<T> Between Multiple Threads†on page XX.
-### Implementing `Send` and `Sync` Manually Is Unsafe
+### Implementing Send and Sync Manually Is Unsafe
Because types that are made up of `Send` and `Sync` traits are automatically
also `Send` and `Sync`, we don’t have to implement those traits manually. As
@@ -1239,7 +1196,7 @@ Manually implementing these traits involves implementing unsafe Rust code.
We’ll talk about using unsafe Rust code in Chapter 19; for now, the important
information is that building new concurrent types not made up of `Send` and
`Sync` parts requires careful thought to uphold the safety guarantees. “The
-Rustonomicon†at *https://doc.rust-lang.org/stable/nomicon/* has more
+Rustonomicon†at *https://doc.rust-lang.org/stable/nomicon* has more
information about these guarantees and how to uphold them.
## Summary
@@ -1266,3 +1223,4 @@ go forth and make your programs concurrent, fearlessly!
Next, we’ll talk about idiomatic ways to model problems and structure solutions
as your Rust programs get bigger. In addition, we’ll discuss how Rust’s idioms
relate to those you might be familiar with from object-oriented programming.
+
diff --git a/src/doc/book/nostarch/chapter17.md b/src/doc/book/nostarch/chapter17.md
index f13b1484a..946d20a11 100644
--- a/src/doc/book/nostarch/chapter17.md
+++ b/src/doc/book/nostarch/chapter17.md
@@ -6,29 +6,24 @@ directory, so all fixes need to be made in `/src/`.
[TOC]
-# Object-Oriented Programming Features of Rust
+# Object-Oriented Programming Features
Object-oriented programming (OOP) is a way of modeling programs. Objects as a
programmatic concept were introduced in the programming language Simula in the
1960s. Those objects influenced Alan Kay’s programming architecture in which
objects pass messages to each other. To describe this architecture, he coined
the term *object-oriented programming* in 1967. Many competing definitions
-describe what OOP is, and by some of these definitions Rust is object-oriented,
+describe what OOP is, and by some of these definitions Rust is object oriented
but by others it is not. In this chapter, we’ll explore certain characteristics
-that are commonly considered object-oriented and how those characteristics
+that are commonly considered object oriented and how those characteristics
translate to idiomatic Rust. We’ll then show you how to implement an
object-oriented design pattern in Rust and discuss the trade-offs of doing so
versus implementing a solution using some of Rust’s strengths instead.
-<!-- Nit: we should probably use "object-oriented" throughout, rather using both
-"object-oriented" and "object oriented"
-/JT -->
-<!-- Done! /Carol -->
-
## Characteristics of Object-Oriented Languages
There is no consensus in the programming community about what features a
-language must have to be considered object-oriented. Rust is influenced by many
+language must have to be considered object oriented. Rust is influenced by many
programming paradigms, including OOP; for example, we explored the features
that came from functional programming in Chapter 13. Arguably, OOP languages
share certain common characteristics, namely objects, encapsulation, and
@@ -38,20 +33,20 @@ Rust supports it.
### Objects Contain Data and Behavior
The book *Design Patterns: Elements of Reusable Object-Oriented Software* by
-Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (Addison-Wesley
-Professional, 1994), colloquially referred to as *The Gang of Four* book, is a
-catalog of object-oriented design patterns. It defines OOP this way:
+Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (Addison-Wesley,
+1994), colloquially referred to as *The Gang of Four* book, is a catalog of
+object-oriented design patterns. It defines OOP in this way:
-> Object-oriented programs are made up of objects. An *object* packages both
-> data and the procedures that operate on that data. The procedures are
-> typically called *methods* or *operations*.
+Object-oriented programs are made up of objects. An *object* packages both data
+and the procedures that operate on that data. The procedures are typically
+called *methods* or *operations*.
-Using this definition, Rust is object-oriented: structs and enums have data,
+Using this definition, Rust is object oriented: structs and enums have data,
and `impl` blocks provide methods on structs and enums. Even though structs and
enums with methods aren’t *called* objects, they provide the same
functionality, according to the Gang of Four’s definition of objects.
-### Encapsulation that Hides Implementation Details
+### Encapsulation That Hides Implementation Details
Another aspect commonly associated with OOP is the idea of *encapsulation*,
which means that the implementation details of an object aren’t accessible to
@@ -66,10 +61,10 @@ keyword to decide which modules, types, functions, and methods in our code
should be public, and by default everything else is private. For example, we
can define a struct `AveragedCollection` that has a field containing a vector
of `i32` values. The struct can also have a field that contains the average of
-the values in the vector, meaning the average doesn’t have to be computed
-on demand whenever anyone needs it. In other words, `AveragedCollection` will
+the values in the vector, meaning the average doesn’t have to be computed on
+demand whenever anyone needs it. In other words, `AveragedCollection` will
cache the calculated average for us. Listing 17-1 has the definition of the
-`AveragedCollection` struct:
+`AveragedCollection` struct.
Filename: src/lib.rs
@@ -87,7 +82,7 @@ The struct is marked `pub` so that other code can use it, but the fields within
the struct remain private. This is important in this case because we want to
ensure that whenever a value is added or removed from the list, the average is
also updated. We do this by implementing `add`, `remove`, and `average` methods
-on the struct, as shown in Listing 17-2:
+on the struct, as shown in Listing 17-2.
Filename: src/lib.rs
@@ -120,18 +115,12 @@ impl AveragedCollection {
}
```
-<!-- The above example will crash with a division by zero if you call it at
-any time when it's empty. Not sure if we want to fix, but thought I'd point
-it out.
-/JT -->
-<!-- It actually won't because f64 / 0 is NaN, not a panic /Carol -->
-
Listing 17-2: Implementations of the public methods `add`, `remove`, and
`average` on `AveragedCollection`
The public methods `add`, `remove`, and `average` are the only ways to access
-or modify data in an instance of `AveragedCollection`. When an item is added
-to `list` using the `add` method or removed using the `remove` method, the
+or modify data in an instance of `AveragedCollection`. When an item is added to
+`list` using the `add` method or removed using the `remove` method, the
implementations of each call the private `update_average` method that handles
updating the `average` field as well.
@@ -145,15 +134,15 @@ Because we’ve encapsulated the implementation details of the struct
`AveragedCollection`, we can easily change aspects, such as the data structure,
in the future. For instance, we could use a `HashSet<i32>` instead of a
`Vec<i32>` for the `list` field. As long as the signatures of the `add`,
-`remove`, and `average` public methods stay the same, code using
+`remove`, and `average` public methods stayed the same, code using
`AveragedCollection` wouldn’t need to change. If we made `list` public instead,
this wouldn’t necessarily be the case: `HashSet<i32>` and `Vec<i32>` have
different methods for adding and removing items, so the external code would
likely have to change if it were modifying `list` directly.
-If encapsulation is a required aspect for a language to be considered
-object-oriented, then Rust meets that requirement. The option to use `pub` or
-not for different parts of code enables encapsulation of implementation details.
+If encapsulation is a required aspect for a language to be considered object
+oriented, then Rust meets that requirement. The option to use `pub` or not for
+different parts of code enables encapsulation of implementation details.
### Inheritance as a Type System and as Code Sharing
@@ -161,8 +150,8 @@ not for different parts of code enables encapsulation of implementation details.
another object’s definition, thus gaining the parent object’s data and behavior
without you having to define them again.
-If a language must have inheritance to be an object-oriented language, then
-Rust is not one. There is no way to define a struct that inherits the parent
+If a language must have inheritance to be object oriented, then Rust is not
+such a language. There is no way to define a struct that inherits the parent
struct’s fields and method implementations without using a macro.
However, if you’re used to having inheritance in your programming toolbox, you
@@ -182,22 +171,6 @@ also override the default implementation of the `summarize` method when we
implement the `Summary` trait, which is similar to a child class overriding the
implementation of a method inherited from a parent class.
-<!-- I'm a bit uncomfortable with the above. I think it's more honest to say
-that Rust doesn't support inheritance unless you use a macro. Saying to use
-the trait system to an OO programmer is going to leave them pretty confused, as
-traits lack of the basics of inheritance: you can't use and modify state, you
-have to use a surrogate type to hold the trait implementation, you can't
-instantiate, and so on.
-
-The example that came to mind: trying to teach OO programmers who want to
-build a UI library with traditional OO techniques using the trait system.
-It's unfortunately not going to work very well, if at all.
-
-A trait's main focus is polymorphism and not inheritance. It's probably
-better for folks coming from OO backgrounds if we just come out and say it, tbh.
-/JT -->
-<!-- I agree, and I've made some edits to the paragraphs above /Carol -->
-
The other reason to use inheritance relates to the type system: to enable a
child type to be used in the same places as the parent type. This is also
called *polymorphism*, which means that you can substitute multiple objects for
@@ -206,12 +179,12 @@ each other at runtime if they share certain characteristics.
> ### Polymorphism
>
> To many people, polymorphism is synonymous with inheritance. But it’s
-> actually a more general concept that refers to code that can work with data
-> of multiple types. For inheritance, those types are generally subclasses.
+actually a more general concept that refers to code that can work with data of
+multiple types. For inheritance, those types are generally subclasses.
>
> Rust instead uses generics to abstract over different possible types and
-> trait bounds to impose constraints on what those types must provide. This is
-> sometimes called *bounded parametric polymorphism*.
+trait bounds to impose constraints on what those types must provide. This is
+sometimes called *bounded parametric polymorphism*.
Inheritance has recently fallen out of favor as a programming design solution
in many programming languages because it’s often at risk of sharing more code
@@ -223,15 +196,6 @@ apply to the subclass. In addition, some languages will only allow single
inheritance (meaning a subclass can only inherit from one class), further
restricting the flexibility of a program’s design.
-<!-- Nit - "inherit from one class" and "single-inheritance" read a bit
-differently to me. Saying you inherit from only one class almost makes it sound
-like that the class you inherit from can't have a parent. Probably minor, just
-made me read that sentence a couple times.
-/JT -->
-<!-- I've included the term "single inheritance" above (it appears that usually
-it's not hyphenated) but kept what was there as an explanation in case the
-reader isn't familiar. /Carol -->
-
For these reasons, Rust takes the different approach of using trait objects
instead of inheritance. Let’s look at how trait objects enable polymorphism in
Rust.
@@ -239,7 +203,7 @@ Rust.
## Using Trait Objects That Allow for Values of Different Types
In Chapter 8, we mentioned that one limitation of vectors is that they can
-store elements of only one type. We created a workaround in Listing 8-10 where
+store elements of only one type. We created a workaround in Listing 8-9 where
we defined a `SpreadsheetCell` enum that had variants to hold integers, floats,
and text. This meant we could store different types of data in each cell and
still have a vector that represented a row of cells. This is a perfectly good
@@ -257,7 +221,7 @@ some types for people to use, such as `Button` or `TextField`. In addition,
instance, one programmer might add an `Image` and another might add a
`SelectBox`.
-We won’t implement a fully fledged GUI library for this example but will show
+We won’t implement a full-fledged GUI library for this example but will show
how the pieces would fit together. At the time of writing the library, we can’t
know and define all the types other programmers might want to create. But we do
know that `gui` needs to keep track of many values of different types, and it
@@ -283,12 +247,12 @@ implementing our specified trait and a table used to look up trait methods on
that type at runtime. We create a trait object by specifying some sort of
pointer, such as a `&` reference or a `Box<T>` smart pointer, then the `dyn`
keyword, and then specifying the relevant trait. (We’ll talk about the reason
-trait objects must use a pointer in Chapter 19 in the section “Dynamically
-Sized Types and the `Sized` Trait.â€) We can use trait objects in place of a
-generic or concrete type. Wherever we use a trait object, Rust’s type system
-will ensure at compile time that any value used in that context will implement
-the trait object’s trait. Consequently, we don’t need to know all the possible
-types at compile time.
+trait objects must use a pointer in “Dynamically Sized Types and the Sized
+Trait†on page XX.) We can use trait objects in place of a generic or concrete
+type. Wherever we use a trait object, Rust’s type system will ensure at compile
+time that any value used in that context will implement the trait object’s
+trait. Consequently, we don’t need to know all the possible types at compile
+time.
We’ve mentioned that, in Rust, we refrain from calling structs and enums
“objects†to distinguish them from other languages’ objects. In a struct or
@@ -302,7 +266,7 @@ languages: their specific purpose is to allow abstraction across common
behavior.
Listing 17-3 shows how to define a trait named `Draw` with one method named
-`draw`:
+`draw`.
Filename: src/lib.rs
@@ -317,8 +281,8 @@ Listing 17-3: Definition of the `Draw` trait
This syntax should look familiar from our discussions on how to define traits
in Chapter 10. Next comes some new syntax: Listing 17-4 defines a struct named
`Screen` that holds a vector named `components`. This vector is of type
-`Box<dyn Draw>`, which is a trait object; it’s a stand-in for any type inside
-a `Box` that implements the `Draw` trait.
+`Box<dyn Draw>`, which is a trait object; it’s a stand-in for any type inside a
+`Box` that implements the `Draw` trait.
Filename: src/lib.rs
@@ -332,7 +296,7 @@ Listing 17-4: Definition of the `Screen` struct with a `components` field
holding a vector of trait objects that implement the `Draw` trait
On the `Screen` struct, we’ll define a method named `run` that will call the
-`draw` method on each of its `components`, as shown in Listing 17-5:
+`draw` method on each of its `components`, as shown in Listing 17-5.
Filename: src/lib.rs
@@ -353,8 +317,8 @@ This works differently from defining a struct that uses a generic type
parameter with trait bounds. A generic type parameter can only be substituted
with one concrete type at a time, whereas trait objects allow for multiple
concrete types to fill in for the trait object at runtime. For example, we
-could have defined the `Screen` struct using a generic type and a trait bound
-as in Listing 17-6:
+could have defined the `Screen` struct using a generic type and a trait bound,
+as in Listing 17-6.
Filename: src/lib.rs
@@ -394,7 +358,7 @@ Now we’ll add some types that implement the `Draw` trait. We’ll provide the
`Button` type. Again, actually implementing a GUI library is beyond the scope
of this book, so the `draw` method won’t have any useful implementation in its
body. To imagine what the implementation might look like, a `Button` struct
-might have fields for `width`, `height`, and `label`, as shown in Listing 17-7:
+might have fields for `width`, `height`, and `label`, as shown in Listing 17-7.
Filename: src/lib.rs
@@ -425,8 +389,8 @@ happens when a user clicks the button. These kinds of methods won’t apply to
types like `TextField`.
If someone using our library decides to implement a `SelectBox` struct that has
-`width`, `height`, and `options` fields, they implement the `Draw` trait on the
-`SelectBox` type as well, as shown in Listing 17-8:
+`width`, `height`, and `options` fields, they would implement the `Draw` trait
+on the `SelectBox` type as well, as shown in Listing 17-8.
Filename: src/main.rs
@@ -453,7 +417,7 @@ Our library’s user can now write their `main` function to create a `Screen`
instance. To the `Screen` instance, they can add a `SelectBox` and a `Button`
by putting each in a `Box<T>` to become a trait object. They can then call the
`run` method on the `Screen` instance, which will call `draw` on each of the
-components. Listing 17-9 shows this implementation:
+components. Listing 17-9 shows this implementation.
Filename: src/main.rs
@@ -484,12 +448,6 @@ fn main() {
}
```
-<!-- I'd forgotten the UI components were in this chapter. To close on the
-thought from earlier: we don't use any inheritance in our example, only
-polymorphism. This probably is a vote for my earlier suggestion.
-/JT -->
-<!-- I indeed took the earlier suggestion. /Carol -->
-
Listing 17-9: Using trait objects to store values of different types that
implement the same trait
@@ -500,9 +458,9 @@ means it implements the `draw` method.
This concept—of being concerned only with the messages a value responds to
rather than the value’s concrete type—is similar to the concept of *duck
-typing* in dynamically typed languages: if it walks like a duck and quacks
-like a duck, then it must be a duck! In the implementation of `run` on `Screen`
-in Listing 17-5, `run` doesn’t need to know what the concrete type of each
+typing* in dynamically typed languages: if it walks like a duck and quacks like
+a duck, then it must be a duck! In the implementation of `run` on `Screen` in
+Listing 17-5, `run` doesn’t need to know what the concrete type of each
component is. It doesn’t check whether a component is an instance of a `Button`
or a `SelectBox`, it just calls the `draw` method on the component. By
specifying `Box<dyn Draw>` as the type of the values in the `components`
@@ -516,7 +474,7 @@ if a value doesn’t implement a method but we call it anyway. Rust won’t comp
our code if the values don’t implement the traits that the trait objects need.
For example, Listing 17-10 shows what happens if we try to create a `Screen`
-with a `String` as a component:
+with a `String` as a component.
Filename: src/main.rs
@@ -532,8 +490,8 @@ fn main() {
}
```
-Listing 17-10: Attempting to use a type that doesn’t
-implement the trait object’s trait
+Listing 17-10: Attempting to use a type that doesn’t implement the trait
+object’s trait
We’ll get this error because `String` doesn’t implement the `Draw` trait:
@@ -542,27 +500,28 @@ error[E0277]: the trait bound `String: Draw` is not satisfied
--> src/main.rs:5:26
|
5 | components: vec![Box::new(String::from("Hi"))],
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Draw` is not implemented for `String`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Draw` is
+not implemented for `String`
|
= note: required for the cast to the object type `dyn Draw`
```
-This error lets us know that either we’re passing something to `Screen` we
-didn’t mean to pass and so should pass a different type or we should implement
+This error lets us know that either we’re passing something to `Screen` that we
+didn’t mean to pass and so should pass a different type, or we should implement
`Draw` on `String` so that `Screen` is able to call `draw` on it.
### Trait Objects Perform Dynamic Dispatch
-Recall in the “Performance of Code Using Generics†section in Chapter 10 our
-discussion on the monomorphization process performed by the compiler when we
-use trait bounds on generics: the compiler generates nongeneric implementations
-of functions and methods for each concrete type that we use in place of a
-generic type parameter. The code that results from monomorphization is doing
-*static dispatch*, which is when the compiler knows what method you’re calling
-at compile time. This is opposed to *dynamic dispatch*, which is when the
-compiler can’t tell at compile time which method you’re calling. In dynamic
-dispatch cases, the compiler emits code that at runtime will figure out which
-method to call.
+Recall in “Performance of Code Using Generics†on page XX our discussion on the
+monomorphization process performed by the compiler when we use trait bounds on
+generics: the compiler generates nongeneric implementations of functions and
+methods for each concrete type that we use in place of a generic type
+parameter. The code that results from monomorphization is doing *static
+dispatch*, which is when the compiler knows what method you’re calling at
+compile time. This is opposed to *dynamic dispatch*, which is when the compiler
+can’t tell at compile time which method you’re calling. In dynamic dispatch
+cases, the compiler emits code that at runtime will figure out which method to
+call.
When we use trait objects, Rust must use dynamic dispatch. The compiler doesn’t
know all the types that might be used with the code that’s using trait objects,
@@ -581,26 +540,13 @@ pattern is that we define a set of states a value can have internally. The
states are represented by a set of *state objects*, and the value’s behavior
changes based on its state. We’re going to work through an example of a blog
post struct that has a field to hold its state, which will be a state object
-from the set "draft", "review", or "published".
-<!-- can you give a quick example here, something we could visualize? are we
-saying "we define a set of states a value can have as state objects...."? /LC
--->
-<!-- What do you think about this, hinting at the coming example quickly? It
-felt weird to introduce something different only to switch gears in a few
-paragraphs, so is moving the example's introduction here ok? /Carol -->
-<!-- JT, what do you think? /LC -->
-<!-- Seems okay. My one thought coming to the end of the paragraph was "is
-this better than using an enum?" Not sure if we want to sidebar a bit on
-why we chose traits over enums, but some readers might be curious.
-/JT -->
-<!-- I've added a box later titled "Why Not An Enum?" to address this -- I
-think that makes a nice exercise for the reader :) /Carol -->
-
-The state objects share functionality: in Rust, of course, we use
-structs and traits rather than objects and inheritance. Each state object is
-responsible for its own behavior and for governing when it should change into
-another state. The value that holds a state object knows nothing about the
-different behavior of the states or when to transition between states.
+from the set “draft,†“review,†or “published.â€
+
+The state objects share functionality: in Rust, of course, we use structs and
+traits rather than objects and inheritance. Each state object is responsible
+for its own behavior and for governing when it should change into another
+state. The value that holds a state object knows nothing about the different
+behavior of the states or when to transition between states.
The advantage of using the state pattern is that, when the business
requirements of the program change, we won’t need to change the code of the
@@ -608,18 +554,18 @@ value holding the state or the code that uses the value. We’ll only need to
update the code inside one of the state objects to change its rules or perhaps
add more state objects.
-First, we’re going to implement the state pattern in a more traditional
+First we’re going to implement the state pattern in a more traditional
object-oriented way, then we’ll use an approach that’s a bit more natural in
-Rust. Let’s dig in to incrementally implementing a blog post workflow using the
+Rust. Let’s dig in to incrementally implement a blog post workflow using the
state pattern.
The final functionality will look like this:
1. A blog post starts as an empty draft.
-2. When the draft is done, a review of the post is requested.
-3. When the post is approved, it gets published.
-4. Only published blog posts return content to print, so unapproved posts can’t
- accidentally be published.
+1. When the draft is done, a review of the post is requested.
+1. When the post is approved, it gets published.
+1. Only published blog posts return content to print, so unapproved posts can’t
+accidentally be published.
Any other changes attempted on a post should have no effect. For example, if we
try to approve a draft blog post before we’ve requested a review, the post
@@ -635,16 +581,16 @@ Filename: src/main.rs
use blog::Post;
fn main() {
- [1] let mut post = Post::new();
+ 1 let mut post = Post::new();
- [2] post.add_text("I ate a salad for lunch today");
- [3] assert_eq!("", post.content());
+ 2 post.add_text("I ate a salad for lunch today");
+ 3 assert_eq!("", post.content());
- [4] post.request_review();
- [5] assert_eq!("", post.content());
+ 4 post.request_review();
+ 5 assert_eq!("", post.content());
- [6] post.approve();
- [7] assert_eq!("I ate a salad for lunch today", post.content());
+ 6 post.approve();
+ 7 assert_eq!("I ate a salad for lunch today", post.content());
}
```
@@ -667,13 +613,13 @@ post will be returned when `content` is called [7].
Notice that the only type we’re interacting with from the crate is the `Post`
type. This type will use the state pattern and will hold a value that will be
one of three state objects representing the various states a post can be
-in—draft, waiting for review, or published. Changing from one state to another
-will be managed internally within the `Post` type. The states change in
-response to the methods called by our library’s users on the `Post` instance,
-but they don’t have to manage the state changes directly. Also, users can’t
-make a mistake with the states, like publishing a post before it’s reviewed.
+in—draft, review, or published. Changing from one state to another will be
+managed internally within the `Post` type. The states change in response to the
+methods called by our library’s users on the `Post` instance, but they don’t
+have to manage the state changes directly. Also, users can’t make a mistake
+with the states, such as publishing a post before it’s reviewed.
-### Defining `Post` and Creating a New Instance in the Draft State
+### Defining Post and Creating a New Instance in the Draft State
Let’s get started on the implementation of the library! We know we need a
public `Post` struct that holds some content, so we’ll start with the
@@ -681,22 +627,6 @@ definition of the struct and an associated public `new` function to create an
instance of `Post`, as shown in Listing 17-12. We’ll also make a private
`State` trait that will define the behavior that all state objects for a `Post`
must have.
-<!-- JT, I had a few questions here about what the state objects and state
-traits are doing. I'd appreciate your view on whether this all reads well with
-nothing missing! /LC -->
-<!-- Seems okay. If you're going to try to use a traditional OO approach in
-Rust, it'll have a bit of this style. I'm glad we include something that's a
-bit more Rust-y at the end of the chapter.
-
-What I might suggest is that we give the reader a bit of a roadmap here to say
-that we're going to explore two solutions to this problem. The first, a more
-traditional approach encoded into Rust, and the second, an approach that's more
-natural to Rust.
-/JT -->
-<!-- Great idea! I've added a bit in the introduction of this section above --
-"First, we’re going to implement the state pattern in a more traditional
-object-oriented way, then we’ll use an approach that’s a bit more natural in
-Rust." /Carol -->
Then `Post` will hold a trait object of `Box<dyn State>` inside an `Option<T>`
in a private field named `state` to hold the state object. You’ll see why the
@@ -713,8 +643,8 @@ pub struct Post {
impl Post {
pub fn new() -> Post {
Post {
- [1] state: Some(Box::new(Draft {})),
- [2] content: String::new(),
+ 1 state: Some(Box::new(Draft {})),
+ 2 content: String::new(),
}
}
}
@@ -737,9 +667,9 @@ want a post to start in.
When we create a new `Post`, we set its `state` field to a `Some` value that
holds a `Box` [1]. This `Box` points to a new instance of the `Draft` struct.
-This ensures whenever we create a new instance of `Post`, it will start out as
-a draft. Because the `state` field of `Post` is private, there is no way to
-create a `Post` in any other state! In the `Post::new` function, we set the
+This ensures that whenever we create a new instance of `Post`, it will start
+out as a draft. Because the `state` field of `Post` is private, there is no way
+to create a `Post` in any other state! In the `Post::new` function, we set the
`content` field to a new, empty `String` [2].
### Storing the Text of the Post Content
@@ -750,13 +680,13 @@ blog post. We implement this as a method, rather than exposing the `content`
field as `pub`, so that later we can implement a method that will control how
the `content` field’s data is read. The `add_text` method is pretty
straightforward, so let’s add the implementation in Listing 17-13 to the `impl
-Post` block:
+Post` block.
Filename: src/lib.rs
```
impl Post {
- // --snip--
+ --snip--
pub fn add_text(&mut self, text: &str) {
self.content.push_str(text);
}
@@ -766,7 +696,7 @@ impl Post {
Listing 17-13: Implementing the `add_text` method to add text to a post’s
`content`
-The `add_text` method takes a mutable reference to `self`, because we’re
+The `add_text` method takes a mutable reference to `self` because we’re
changing the `Post` instance that we’re calling `add_text` on. We then call
`push_str` on the `String` in `content` and pass the `text` argument to add to
the saved `content`. This behavior doesn’t depend on the state the post is in,
@@ -783,13 +713,13 @@ implement the `content` method with the simplest thing that will fulfill this
requirement: always returning an empty string slice. We’ll change this later
once we implement the ability to change a post’s state so it can be published.
So far, posts can only be in the draft state, so the post content should always
-be empty. Listing 17-14 shows this placeholder implementation:
+be empty. Listing 17-14 shows this placeholder implementation.
Filename: src/lib.rs
```
impl Post {
- // --snip--
+ --snip--
pub fn content(&self) -> &str {
""
}
@@ -802,32 +732,32 @@ Listing 17-14: Adding a placeholder implementation for the `content` method on
With this added `content` method, everything in Listing 17-11 up to the line at
[3] works as intended.
-### Requesting a Review of the Post Changes Its State
+### Requesting a Review Changes the Post’s State
Next, we need to add functionality to request a review of a post, which should
-change its state from `Draft` to `PendingReview`. Listing 17-15 shows this code:
+change its state from `Draft` to `PendingReview`. Listing 17-15 shows this code.
Filename: src/lib.rs
```
impl Post {
- // --snip--
- [1] pub fn request_review(&mut self) {
- [2] if let Some(s) = self.state.take() {
- [3] self.state = Some(s.request_review())
+ --snip--
+ 1 pub fn request_review(&mut self) {
+ 2 if let Some(s) = self.state.take() {
+ 3 self.state = Some(s.request_review())
}
}
}
trait State {
- [4] fn request_review(self: Box<Self>) -> Box<dyn State>;
+ 4 fn request_review(self: Box<Self>) -> Box<dyn State>;
}
struct Draft {}
impl State for Draft {
fn request_review(self: Box<Self>) -> Box<dyn State> {
- [5] Box::new(PendingReview {})
+ 5 Box::new(PendingReview {})
}
}
@@ -835,7 +765,7 @@ struct PendingReview {}
impl State for PendingReview {
fn request_review(self: Box<Self>) -> Box<dyn State> {
- [6] self
+ 6 self
}
}
```
@@ -859,7 +789,7 @@ ownership of `Box<Self>`, invalidating the old state so the state value of the
To consume the old state, the `request_review` method needs to take ownership
of the state value. This is where the `Option` in the `state` field of `Post`
comes in: we call the `take` method to take the `Some` value out of the `state`
-field and leave a `None` in its place, because Rust doesn’t let us have
+field and leave a `None` in its place because Rust doesn’t let us have
unpopulated fields in structs [2]. This lets us move the `state` value out of
`Post` rather than borrowing it. Then we’ll set the post’s `state` value to the
result of this operation.
@@ -872,7 +802,7 @@ we’ve transformed it into a new state.
The `request_review` method on `Draft` returns a new, boxed instance of a new
`PendingReview` struct [5], which represents the state when a post is waiting
for a review. The `PendingReview` struct also implements the `request_review`
-method but doesn’t do any transformations. Rather, it returns itself [6],
+method but doesn’t do any transformations. Rather, it returns itself [6]
because when we request a review on a post already in the `PendingReview`
state, it should stay in the `PendingReview` state.
@@ -885,17 +815,17 @@ slice. We can now have a `Post` in the `PendingReview` state as well as in the
`Draft` state, but we want the same behavior in the `PendingReview` state.
Listing 17-11 now works up to the line at [5]!
-### Adding `approve` to Change the Behavior of `content`
+### Adding approve to Change the Behavior of content
The `approve` method will be similar to the `request_review` method: it will
set `state` to the value that the current state says it should have when that
-state is approved, as shown in Listing 17-16:
+state is approved, as shown in Listing 17-16.
Filename: src/lib.rs
```
impl Post {
- // --snip--
+ --snip--
pub fn approve(&mut self) {
if let Some(s) = self.state.take() {
self.state = Some(s.approve())
@@ -911,18 +841,18 @@ trait State {
struct Draft {}
impl State for Draft {
- // --snip--
+ --snip--
fn approve(self: Box<Self>) -> Box<dyn State> {
- [1] self
+ 1 self
}
}
struct PendingReview {}
impl State for PendingReview {
- // --snip--
+ --snip--
fn approve(self: Box<Self>) -> Box<dyn State> {
- [2] Box::new(Published {})
+ 2 Box::new(Published {})
}
}
@@ -949,33 +879,33 @@ Similar to the way `request_review` on `PendingReview` works, if we call the
return `self` [1]. When we call `approve` on `PendingReview`, it returns a new,
boxed instance of the `Published` struct [2]. The `Published` struct implements
the `State` trait, and for both the `request_review` method and the `approve`
-method, it returns itself, because the post should stay in the `Published`
-state in those cases.
+method, it returns itself because the post should stay in the `Published` state
+in those cases.
Now we need to update the `content` method on `Post`. We want the value
returned from `content` to depend on the current state of the `Post`, so we’re
going to have the `Post` delegate to a `content` method defined on its `state`,
-as shown in Listing 17-17:
+as shown in Listing 17-17.
Filename: src/lib.rs
```
impl Post {
- // --snip--
+ --snip--
pub fn content(&self) -> &str {
self.state.as_ref().unwrap().content(self)
}
- // --snip--
+ --snip--
}
```
Listing 17-17: Updating the `content` method on `Post` to delegate to a
`content` method on `State`
-Because the goal is to keep all these rules inside the structs that implement
-`State`, we call a `content` method on the value in `state` and pass the post
-instance (that is, `self`) as an argument. Then we return the value that’s
-returned from using the `content` method on the `state` value.
+Because the goal is to keep all of these rules inside the structs that
+implement `State`, we call a `content` method on the value in `state` and pass
+the post instance (that is, `self`) as an argument. Then we return the value
+that’s returned from using the `content` method on the `state` value.
We call the `as_ref` method on the `Option` because we want a reference to the
value inside the `Option` rather than ownership of the value. Because `state`
@@ -983,37 +913,37 @@ is an `Option<Box<dyn State>>`, when we call `as_ref`, an `Option<&Box<dyn
State>>` is returned. If we didn’t call `as_ref`, we would get an error because
we can’t move `state` out of the borrowed `&self` of the function parameter.
-We then call the `unwrap` method, which we know will never panic, because we
+We then call the `unwrap` method, which we know will never panic because we
know the methods on `Post` ensure that `state` will always contain a `Some`
value when those methods are done. This is one of the cases we talked about in
-the “Cases In Which You Have More Information Than the Compiler†section of
-Chapter 9 when we know that a `None` value is never possible, even though the
-compiler isn’t able to understand that.
+“Cases in Which You Have More Information Than the Compiler†on page XX when we
+know that a `None` value is never possible, even though the compiler isn’t able
+to understand that.
At this point, when we call `content` on the `&Box<dyn State>`, deref coercion
will take effect on the `&` and the `Box` so the `content` method will
ultimately be called on the type that implements the `State` trait. That means
we need to add `content` to the `State` trait definition, and that is where
we’ll put the logic for what content to return depending on which state we
-have, as shown in Listing 17-18:
+have, as shown in Listing 17-18.
Filename: src/lib.rs
```
trait State {
- // --snip--
+ --snip--
fn content<'a>(&self, post: &'a Post) -> &'a str {
- [1] ""
+ 1 ""
}
}
-// --snip--
+--snip--
struct Published {}
impl State for Published {
- // --snip--
+ --snip--
fn content<'a>(&self, post: &'a Post) -> &'a str {
- [2] &post.content
+ 2 &post.content
}
}
```
@@ -1021,9 +951,9 @@ impl State for Published {
Listing 17-18: Adding the `content` method to the `State` trait
We add a default implementation for the `content` method that returns an empty
-string slice [1]. That means we don’t need to implement `content` on the `Draft`
-and `PendingReview` structs. The `Published` struct will override the `content`
-method and return the value in `post.content` [2].
+string slice [1]. That means we don’t need to implement `content` on the
+`Draft` and `PendingReview` structs. The `Published` struct will override the
+`content` method and return the value in `post.content` [2].
Note that we need lifetime annotations on this method, as we discussed in
Chapter 10. We’re taking a reference to a `post` as an argument and returning a
@@ -1034,14 +964,14 @@ And we’re done—all of Listing 17-11 now works! We’ve implemented the state
pattern with the rules of the blog post workflow. The logic related to the
rules lives in the state objects rather than being scattered throughout `Post`.
-> #### Why Not An Enum?
+> ### Why Not An Enum?
>
> You may have been wondering why we didn’t use an `enum` with the different
-> possible post states as variants. That’s certainly a possible solution, try
-> it and compare the end results to see which you prefer! One disadvantage of
-> using an enum is every place that checks the value of the enum will need a
-> `match` expression or similar to handle every possible variant. This could
-> get more repetitive than this trait object solution.
+possible post states as variants. That’s certainly a possible solution; try it
+and compare the end results to see which you prefer! One disadvantage of using
+an enum is that every place that checks the value of the enum will need a
+`match` expression or similar to handle every possible variant. This could get
+more repetitive than this trait object solution.
### Trade-offs of the State Pattern
@@ -1069,11 +999,11 @@ functionality. To see the simplicity of maintaining code that uses the state
pattern, try a few of these suggestions:
* Add a `reject` method that changes the post’s state from `PendingReview` back
- to `Draft`.
+to `Draft`.
* Require two calls to `approve` before the state can be changed to `Published`.
* Allow users to add text content only when a post is in the `Draft` state.
- Hint: have the state object responsible for what might change about the
- content but not responsible for modifying the `Post`.
+Hint: have the state object responsible for what might change about the content
+but not responsible for modifying the `Post`.
One downside of the state pattern is that, because the states implement the
transitions between states, some of the states are coupled to each other. If we
@@ -1085,22 +1015,22 @@ another design pattern.
Another downside is that we’ve duplicated some logic. To eliminate some of the
duplication, we might try to make default implementations for the
-`request_review` and `approve` methods on the `State` trait that return `self`;
-however, this would violate object safety, because the trait doesn’t know what
-the concrete `self` will be exactly. We want to be able to use `State` as a
-trait object, so we need its methods to be object safe.
+`request_review` and `approve` methods on the `State` trait that return `self`.
+However, this wouldn’t work: when using `State` as a trait object, the trait
+doesn’t know what the concrete `self` will be exactly, so the return type isn’t
+known at compile time.
Other duplication includes the similar implementations of the `request_review`
and `approve` methods on `Post`. Both methods delegate to the implementation of
the same method on the value in the `state` field of `Option` and set the new
value of the `state` field to the result. If we had a lot of methods on `Post`
that followed this pattern, we might consider defining a macro to eliminate the
-repetition (see the “Macros†section in Chapter 19).
+repetition (see “Macros†on page XX).
By implementing the state pattern exactly as it’s defined for object-oriented
languages, we’re not taking as full advantage of Rust’s strengths as we could.
Let’s look at some changes we can make to the `blog` crate that can make
-invalid states and transitions into compile time errors.
+invalid states and transitions into compile-time errors.
#### Encoding States and Behavior as Types
@@ -1129,9 +1059,9 @@ and the ability to add text to the post’s content. But instead of having a
draft posts don’t have the `content` method at all. That way, if we try to get
a draft post’s content, we’ll get a compiler error telling us the method
doesn’t exist. As a result, it will be impossible for us to accidentally
-display draft post content in production, because that code won’t even compile.
+display draft post content in production because that code won’t even compile.
Listing 17-19 shows the definition of a `Post` struct and a `DraftPost` struct,
-as well as methods on each:
+as well as methods on each.
Filename: src/lib.rs
@@ -1145,19 +1075,19 @@ pub struct DraftPost {
}
impl Post {
- [1] pub fn new() -> DraftPost {
+ 1 pub fn new() -> DraftPost {
DraftPost {
content: String::new(),
}
}
- [2] pub fn content(&self) -> &str {
+ 2 pub fn content(&self) -> &str {
&self.content
}
}
impl DraftPost {
- [3] pub fn add_text(&mut self, text: &str) {
+ 3 pub fn add_text(&mut self, text: &str) {
self.content.push_str(text);
}
}
@@ -1189,15 +1119,15 @@ So how do we get a published post? We want to enforce the rule that a draft
post has to be reviewed and approved before it can be published. A post in the
pending review state should still not display any content. Let’s implement
these constraints by adding another struct, `PendingReviewPost`, defining the
-`request_review` method on `DraftPost` to return a `PendingReviewPost`, and
+`request_review` method on `DraftPost` to return a `PendingReviewPost` and
defining an `approve` method on `PendingReviewPost` to return a `Post`, as
-shown in Listing 17-20:
+shown in Listing 17-20.
Filename: src/lib.rs
```
impl DraftPost {
- // --snip--
+ --snip--
pub fn request_review(self) -> PendingReviewPost {
PendingReviewPost {
content: self.content,
@@ -1240,7 +1170,7 @@ called on, so we need to add more `let post =` shadowing assignments to save
the returned instances. We also can’t have the assertions about the draft and
pending review posts’ contents be empty strings, nor do we need them: we can’t
compile code that tries to use the content of posts in those states any longer.
-The updated code in `main` is shown in Listing 17-21:
+The updated code in `main` is shown in Listing 17-21.
Filename: src/main.rs
@@ -1287,16 +1217,17 @@ object-oriented languages don’t have.
## Summary
-No matter whether or not you think Rust is an object-oriented language after
+Regardless of whether you think Rust is an object-oriented language after
reading this chapter, you now know that you can use trait objects to get some
object-oriented features in Rust. Dynamic dispatch can give your code some
flexibility in exchange for a bit of runtime performance. You can use this
flexibility to implement object-oriented patterns that can help your code’s
maintainability. Rust also has other features, like ownership, that
object-oriented languages don’t have. An object-oriented pattern won’t always
-be the best way to take advantage of Rust’s strengths, but is an available
+be the best way to take advantage of Rust’s strengths, but it is an available
option.
Next, we’ll look at patterns, which are another of Rust’s features that enable
lots of flexibility. We’ve looked at them briefly throughout the book but
haven’t seen their full capability yet. Let’s go!
+
diff --git a/src/doc/book/nostarch/chapter18.md b/src/doc/book/nostarch/chapter18.md
index 0b104dcf6..40c7f10a1 100644
--- a/src/doc/book/nostarch/chapter18.md
+++ b/src/doc/book/nostarch/chapter18.md
@@ -23,20 +23,6 @@ Some example patterns include `x`, `(a, 3)`, and `Some(Color::Red)`. In the
contexts in which patterns are valid, these components describe the shape of
data. Our program then matches values against the patterns to determine whether
it has the correct shape of data to continue running a particular piece of code.
-<!-- is there some generic pattern we can show as an example, early on, or
-is it too dependent on where the pattern is used? /LC -->
-<!-- Yeah, if a pattern is out of context, it doesn't look special. Like `3`
-can be a pattern. /Carol -->
-<!-- We could mention something like, "If you've written a little Rust, you've
-already used patterns without knowing it. For example `let x = 3`, the `x` is
-a pattern." Though looks like we use this later.
-
-Or, we could say, "Some example patterns include: `x`, `(a, b)`, and `Color::Red`
-/JT -->
-<!-- Ok, I've tried rewording this paragraph to include some examples, I do
-think it's important to emphasize that these are only patterns in the contexts
-patterns may exist, because without the context, there's no way to distinguish
-patterns from regular values /Carol -->
To use a pattern, we compare it to some value. If the pattern matches the
value, we use the value parts in our code. Recall the `match` expressions in
@@ -56,7 +42,7 @@ Patterns pop up in a number of places in Rust, and you’ve been using them a lo
without realizing it! This section discusses all the places where patterns are
valid.
-### `match` Arms
+### match Arms
As discussed in Chapter 6, we use patterns in the arms of `match` expressions.
Formally, `match` expressions are defined as the keyword `match`, a value to
@@ -71,7 +57,7 @@ match VALUE {
}
```
-For example, here's the `match` expression from Listing 6-5 that matches on an
+For example, here’s the `match` expression from Listing 6-5 that matches on an
`Option<i32>` value in the variable `x`:
```
@@ -81,7 +67,7 @@ match x {
}
```
-The patterns in this `match` expression are the `None` and `Some(i)` on the
+The patterns in this `match` expression are the `None` and `Some(i)` to the
left of each arrow.
One requirement for `match` expressions is that they need to be *exhaustive* in
@@ -93,12 +79,12 @@ value can never fail and thus covers every remaining case.
The particular pattern `_` will match anything, but it never binds to a
variable, so it’s often used in the last match arm. The `_` pattern can be
useful when you want to ignore any value not specified, for example. We’ll
-cover the `_` pattern in more detail in the “Ignoring Values in a Patternâ€
-section later in this chapter.
+cover the `_` pattern in more detail in “Ignoring Values in a Pattern†on page
+XX.
-### Conditional `if let` Expressions
+### Conditional if let Expressions
-In Chapter 6 we discussed how to use `if let` expressions mainly as a shorter
+In Chapter 6, we discussed how to use `if let` expressions mainly as a shorter
way to write the equivalent of a `match` that only matches one case.
Optionally, `if let` can have a corresponding `else` containing code to run if
the pattern in the `if let` doesn’t match.
@@ -106,8 +92,8 @@ the pattern in the `if let` doesn’t match.
Listing 18-1 shows that it’s also possible to mix and match `if let`, `else
if`, and `else if let` expressions. Doing so gives us more flexibility than a
`match` expression in which we can express only one value to compare with the
-patterns. Also, Rust doesn't require that the conditions in a series of `if
-let`, `else if`, `else if let` arms relate to each other.
+patterns. Also, Rust doesn’t require that the conditions in a series of `if
+let`, `else if`, and `else if let` arms relate to each other.
The code in Listing 18-1 determines what color to make your background based on
a series of checks for several conditions. For this example, we’ve created
@@ -122,18 +108,20 @@ fn main() {
let is_tuesday = false;
let age: Result<u8, _> = "34".parse();
- [1] if let Some(color) = favorite_color {
- [2] println!("Using your favorite color, {color}, as the background");
- [3] } else if is_tuesday {
- [4] println!("Tuesday is green day!");
- [5]} else if let Ok(age) = age {
- [6] if age > 30 {
- [7] println!("Using purple as the background color");
+ 1 if let Some(color) = favorite_color {
+ 2 println!(
+ "Using your favorite, {color}, as the background"
+ );
+ 3 } else if is_tuesday {
+ 4 println!("Tuesday is green day!");
+ 5 } else if let Ok(age) = age {
+ 6 if age > 30 {
+ 7 println!("Using purple as the background color");
} else {
- [8] println!("Using orange as the background color");
+ 8 println!("Using orange as the background color");
}
- [9] } else {
- [10] println!("Using blue as the background color");
+ 9 } else {
+ 10 println!("Using blue as the background color");
}
}
```
@@ -145,7 +133,7 @@ background [2]. If no favorite color is specified and today is Tuesday [3], the
background color is green [4]. Otherwise, if the user specifies their age as a
string and we can parse it as a number successfully [5], the color is either
purple [7] or orange [8] depending on the value of the number [6]. If none of
-these conditions apply [9], the background color is blue.
+these conditions apply [9], the background color is blue [10].
This conditional structure lets us support complex requirements. With the
hardcoded values we have here, this example will print `Using purple as the
@@ -159,29 +147,20 @@ can’t combine these two conditions into `if let Ok(age) = age && age > 30`. Th
shadowed `age` we want to compare to 30 isn’t valid until the new scope starts
with the curly bracket.
-<!-- Have we given them an intuition yet for why this is? I may be forgetting
-something from the earlier chapters, but I wonder if we should reiterate that
-when a pattern matches, the variable that gets bound is only valid for the
-expression or block that follows the match. /JT -->
-<!-- I don't really see a difference between saying "The shadowed `age` we want
-to compare to 30 isn't valid until the new scope starts with the curly bracket"
-and "when a pattern matches, the variable that gets bound is only valid for the
-expression or block that follows the match"? To me, it sounds like this would
-be saying the same thing twice, so I'm not going to change anything here.
-/Carol -->
-
The downside of using `if let` expressions is that the compiler doesn’t check
for exhaustiveness, whereas with `match` expressions it does. If we omitted the
last `else` block [9] and therefore missed handling some cases, the compiler
would not alert us to the possible logic bug.
-### `while let` Conditional Loops
+### while let Conditional Loops
Similar in construction to `if let`, the `while let` conditional loop allows a
`while` loop to run for as long as a pattern continues to match. In Listing
-18-2 we code a `while let` loop that uses a vector as a stack and prints the
+18-2, we code a `while let` loop that uses a vector as a stack and prints the
values in the vector in the opposite order in which they were pushed.
+Filename: src/main.rs
+
```
let mut stack = Vec::new();
@@ -190,31 +169,33 @@ stack.push(2);
stack.push(3);
while let Some(top) = stack.pop() {
- println!("{}", top);
+ println!("{top}");
}
```
Listing 18-2: Using a `while let` loop to print values for as long as
`stack.pop()` returns `Some`
-This example prints 3, 2, and then 1. The `pop` method takes the last element
-out of the vector and returns `Some(value)`. If the vector is empty, `pop`
-returns `None`. The `while` loop continues running the code in its block as
-long as `pop` returns `Some`. When `pop` returns `None`, the loop stops. We can
-use `while let` to pop every element off our stack.
+This example prints `3`, `2`, and then `1`. The `pop` method takes the last
+element out of the vector and returns `Some(value)`. If the vector is empty,
+`pop` returns `None`. The `while` loop continues running the code in its block
+as long as `pop` returns `Some`. When `pop` returns `None`, the loop stops. We
+can use `while let` to pop every element off our stack.
-### `for` Loops
+### for Loops
In a `for` loop, the value that directly follows the keyword `for` is a
-pattern. For example, in `for x in y` the `x` is the pattern. Listing 18-3
-demonstrates how to use a pattern in a `for` loop to destructure, or break
+pattern. For example, in `for x in y`, the `x` is the pattern. Listing 18-3
+demonstrates how to use a pattern in a `for` loop to *destructure*, or break
apart, a tuple as part of the `for` loop.
+Filename: src/main.rs
+
```
let v = vec!['a', 'b', 'c'];
for (index, value) in v.iter().enumerate() {
- println!("{} is at index {}", value, index);
+ println!("{value} is at index {index}");
}
```
@@ -234,7 +215,7 @@ tuple `(0, 'a')`. When this value is matched to the pattern `(index, value)`,
`index` will be `0` and `value` will be `'a'`, printing the first line of the
output.
-### `let` Statements
+### let Statements
Prior to this chapter, we had only explicitly discussed using patterns with
`match` and `if let`, but in fact, we’ve used patterns in other places as well,
@@ -245,7 +226,7 @@ variable assignment with `let`:
let x = 5;
```
-Every time you've used a `let` statement like this you've been using patterns,
+Every time you’ve used a `let` statement like this you’ve been using patterns,
although you might not have realized it! More formally, a `let` statement looks
like this:
@@ -253,14 +234,14 @@ like this:
let PATTERN = EXPRESSION;
```
-In statements like `let x = 5;` with a variable name in the `PATTERN` slot, the
+In statements like `let x = 5;` with a variable name in the PATTERN slot, the
variable name is just a particularly simple form of a pattern. Rust compares
-the expression against the pattern and assigns any names it finds. So in the
+the expression against the pattern and assigns any names it finds. So, in the
`let x = 5;` example, `x` is a pattern that means “bind what matches here to
the variable `x`.†Because the name `x` is the whole pattern, this pattern
effectively means “bind everything to the variable `x`, whatever the value is.â€
-To see the pattern matching aspect of `let` more clearly, consider Listing
+To see the pattern-matching aspect of `let` more clearly, consider Listing
18-4, which uses a pattern with `let` to destructure a tuple.
```
@@ -272,9 +253,9 @@ at once
Here, we match a tuple against a pattern. Rust compares the value `(1, 2, 3)`
to the pattern `(x, y, z)` and sees that the value matches the pattern, in that
-it sees that the number of elements is the same in both, so Rust
-binds `1` to `x`, `2` to `y`, and `3` to `z`. You can think of this tuple
-pattern as nesting three individual variable patterns inside it.
+it sees that the number of elements is the same in both, so Rust binds `1` to
+`x`, `2` to `y`, and `3` to `z`. You can think of this tuple pattern as nesting
+three individual variable patterns inside it.
If the number of elements in the pattern doesn’t match the number of elements
in the tuple, the overall type won’t match and we’ll get a compiler error. For
@@ -295,7 +276,8 @@ error[E0308]: mismatched types
--> src/main.rs:2:9
|
2 | let (x, y) = (1, 2, 3);
- | ^^^^^^ --------- this expression has type `({integer}, {integer}, {integer})`
+ | ^^^^^^ --------- this expression has type `({integer}, {integer},
+{integer})`
| |
| expected a tuple with 3 elements, found one with 2 elements
|
@@ -304,9 +286,9 @@ error[E0308]: mismatched types
```
To fix the error, we could ignore one or more of the values in the tuple using
-`_` or `..`, as you’ll see in the “Ignoring Values in a Pattern†section. If
-the problem is that we have too many variables in the pattern, the solution is
-to make the types match by removing variables so the number of variables equals
+`_` or `..`, as you’ll see in “Ignoring Values in a Pattern†on page XX. If the
+problem is that we have too many variables in the pattern, the solution is to
+make the types match by removing variables so the number of variables equals
the number of elements in the tuple.
### Function Parameters
@@ -321,7 +303,7 @@ fn foo(x: i32) {
}
```
-Listing 18-6: A function signature uses patterns in the parameters
+Listing 18-6: A function signature using patterns in the parameters
The `x` part is a pattern! As we did with `let`, we could match a tuple in a
function’s arguments to the pattern. Listing 18-7 splits the values in a tuple
@@ -331,7 +313,7 @@ Filename: src/main.rs
```
fn print_coordinates(&(x, y): &(i32, i32)) {
- println!("Current location: ({}, {})", x, y);
+ println!("Current location: ({x}, {y})");
}
fn main() {
@@ -346,10 +328,10 @@ This code prints `Current location: (3, 5)`. The values `&(3, 5)` match the
pattern `&(x, y)`, so `x` is the value `3` and `y` is the value `5`.
We can also use patterns in closure parameter lists in the same way as in
-function parameter lists, because closures are similar to functions, as
+function parameter lists because closures are similar to functions, as
discussed in Chapter 13.
-At this point, you’ve seen several ways of using patterns, but patterns don’t
+At this point, you’ve seen several ways to use patterns, but patterns don’t
work the same in every place we can use them. In some places, the patterns must
be irrefutable; in other circumstances, they can be refutable. We’ll discuss
these two concepts next.
@@ -365,12 +347,12 @@ a_value` because if the value in the `a_value` variable is `None` rather than
`Some`, the `Some(x)` pattern will not match.
Function parameters, `let` statements, and `for` loops can only accept
-irrefutable patterns, because the program cannot do anything meaningful when
-values don’t match. The `if let` and `while let` expressions accept
-refutable and irrefutable patterns, but the compiler warns against
-irrefutable patterns because by definition they’re intended to handle possible
-failure: the functionality of a conditional is in its ability to perform
-differently depending on success or failure.
+irrefutable patterns because the program cannot do anything meaningful when
+values don’t match. The `if let` and `while let` expressions accept refutable
+and irrefutable patterns, but the compiler warns against irrefutable patterns
+because, by definition, they’re intended to handle possible failure: the
+functionality of a conditional is in its ability to perform differently
+depending on success or failure.
In general, you shouldn’t have to worry about the distinction between refutable
and irrefutable patterns; however, you do need to be familiar with the concept
@@ -380,7 +362,7 @@ using the pattern with, depending on the intended behavior of the code.
Let’s look at an example of what happens when we try to use a refutable pattern
where Rust requires an irrefutable pattern and vice versa. Listing 18-8 shows a
-`let` statement, but for the pattern we’ve specified `Some(x)`, a refutable
+`let` statement, but for the pattern, we’ve specified `Some(x)`, a refutable
pattern. As you might expect, this code will not compile.
```
@@ -389,7 +371,7 @@ let Some(x) = some_option_value;
Listing 18-8: Attempting to use a refutable pattern with `let`
-If `some_option_value` was a `None` value, it would fail to match the pattern
+If `some_option_value` were a `None` value, it would fail to match the pattern
`Some(x)`, meaning the pattern is refutable. However, the `let` statement can
only accept an irrefutable pattern because there is nothing valid the code can
do with a `None` value. At compile time, Rust will complain that we’ve tried to
@@ -402,13 +384,15 @@ error[E0005]: refutable pattern in local binding: `None` not covered
3 | let Some(x) = some_option_value;
| ^^^^^^^ pattern `None` 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
+ = 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
= note: the matched value is of type `Option<i32>`
help: you might want to use `if let` to ignore the variant that isn't matched
|
-3 | if let Some(x) = some_option_value { /* */ }
- |
+3 | let x = if let Some(x) = some_option_value { x } else { todo!() };
+ | ++++++++++ ++++++++++++++++++++++
```
Because we didn’t cover (and couldn’t cover!) every valid value with the
@@ -416,13 +400,13 @@ pattern `Some(x)`, Rust rightfully produces a compiler error.
If we have a refutable pattern where an irrefutable pattern is needed, we can
fix it by changing the code that uses the pattern: instead of using `let`, we
-can use `if let`. Then if the pattern doesn’t match, the code will just skip
+can use `if let`. Then, if the pattern doesn’t match, the code will just skip
the code in the curly brackets, giving it a way to continue validly. Listing
18-9 shows how to fix the code in Listing 18-8.
```
if let Some(x) = some_option_value {
- println!("{}", x);
+ println!("{x}");
}
```
@@ -436,7 +420,7 @@ the compiler will give a warning.
```
if let x = 5 {
- println!("{}", x);
+ println!("{x}");
};
```
@@ -453,7 +437,8 @@ warning: irrefutable `if let` pattern
| ^^^^^^^^^
|
= note: `#[warn(irrefutable_let_patterns)]` on by default
- = note: this pattern will always match, so the `if let` is useless
+ = note: this pattern will always match, so the `if let` is
+useless
= help: consider replacing the `if let` with a `let`
```
@@ -469,14 +454,16 @@ patterns.
## Pattern Syntax
-In this section, we gather all the syntax valid in patterns and discuss why and
-when you might want to use each one.
+In this section, we gather all the syntax that is valid in patterns and discuss
+why and when you might want to use each one.
### Matching Literals
As you saw in Chapter 6, you can match patterns against literals directly. The
following code gives some examples:
+Filename: src/main.rs
+
```
let x = 1;
@@ -488,14 +475,14 @@ match x {
}
```
-This code prints `one` because the value in `x` is 1. This syntax is useful
+This code prints `one` because the value in `x` is `1`. This syntax is useful
when you want your code to take an action if it gets a particular concrete
value.
### Matching Named Variables
Named variables are irrefutable patterns that match any value, and we’ve used
-them many times in the book. However, there is a complication when you use
+them many times in this book. However, there is a complication when you use
named variables in `match` expressions. Because `match` starts a new scope,
variables declared as part of a pattern inside the `match` expression will
shadow those with the same name outside the `match` construct, as is the case
@@ -509,16 +496,16 @@ Filename: src/main.rs
```
fn main() {
- [1] let x = Some(5);
- [2] let y = 10;
+ 1 let x = Some(5);
+ 2 let y = 10;
match x {
- [3] Some(50) => println!("Got 50"),
- [4] Some(y) => println!("Matched, y = {y}"),
- [5] _ => println!("Default case, x = {:?}", x),
+ 3 Some(50) => println!("Got 50"),
+ 4 Some(y) => println!("Matched, y = {y}"),
+ 5 _ => println!("Default case, x = {:?}", x),
}
- [6] println!("at the end: x = {:?}, y = {y}", x);
+ 6 println!("at the end: x = {:?}, y = {y}", x);
}
```
@@ -532,7 +519,7 @@ code continues.
The pattern in the second match arm [4] introduces a new variable named `y`
that will match any value inside a `Some` value. Because we’re in a new scope
inside the `match` expression, this is a new `y` variable, not the `y` we
-declared at the beginning with the value 10 [2]. This new `y` binding will
+declared at the beginning with the value `10` [2]. This new `y` binding will
match any value inside a `Some`, which is what we have in `x`. Therefore, this
new `y` binds to the inner value of the `Some` in `x`. That value is `5`, so
the expression for that arm executes and prints `Matched, y = 5`.
@@ -550,8 +537,8 @@ the inner `y`. The last `println!` [6] produces `at the end: x = Some(5), y =
To create a `match` expression that compares the values of the outer `x` and
`y`, rather than introducing a shadowed variable, we would need to use a match
-guard conditional instead. We’ll talk about match guards later in the “Extra
-Conditionals with Match Guards†section.
+guard conditional instead. We’ll talk about match guards in “Extra Conditionals
+with Match Guards†on page XX.
### Multiple Patterns
@@ -561,6 +548,8 @@ the value of `x` against the match arms, the first of which has an *or* option,
meaning if the value of `x` matches either of the values in that arm, that
arm’s code will run:
+Filename: src/main.rs
+
```
let x = 1;
@@ -573,12 +562,14 @@ match x {
This code prints `one or two`.
-### Matching Ranges of Values with `..=`
+### Matching Ranges of Values with ..=
The `..=` syntax allows us to match to an inclusive range of values. In the
following code, when a pattern matches any of the values within the given
range, that arm will execute:
+Filename: src/main.rs
+
```
let x = 5;
@@ -588,11 +579,11 @@ match x {
}
```
-If `x` is 1, 2, 3, 4, or 5, the first arm will match. This syntax is more
-convenient for multiple match values than using the `|` operator to express the
-same idea; if we were to use `|` we would have to specify `1 | 2 | 3 | 4 | 5`.
-Specifying a range is much shorter, especially if we want to match, say, any
-number between 1 and 1,000!
+If `x` is `1`, `2`, `3`, `4`, or `5`, the first arm will match. This syntax is
+more convenient for multiple match values than using the `|` operator to
+express the same idea; if we were to use `|`, we would have to specify `1 | 2 |
+3 | 4 | 5`. Specifying a range is much shorter, especially if we want to match,
+say, any number between 1 and 1,000!
The compiler checks that the range isn’t empty at compile time, and because the
only types for which Rust can tell if a range is empty or not are `char` and
@@ -600,6 +591,8 @@ numeric values, ranges are only allowed with numeric or `char` values.
Here is an example using ranges of `char` values:
+Filename: src/main.rs
+
```
let x = 'c';
@@ -684,7 +677,7 @@ destructure the other fields.
In Listing 18-14, we have a `match` expression that separates `Point` values
into three cases: points that lie directly on the `x` axis (which is true when
-`y = 0`), on the `y` axis (`x = 0`), or neither.
+`y = 0`), on the `y` axis (`x = 0`), or on neither axis.
Filename: src/main.rs
@@ -693,9 +686,11 @@ fn main() {
let p = Point { x: 0, y: 7 };
match p {
- Point { x, y: 0 } => println!("On the x axis at {}", x),
- Point { x: 0, y } => println!("On the y axis at {}", y),
- Point { x, y } => println!("On neither axis: ({}, {})", x, y),
+ Point { x, y: 0 } => println!("On the x axis at {x}"),
+ Point { x: 0, y } => println!("On the y axis at {y}"),
+ Point { x, y } => {
+ println!("On neither axis: ({x}, {y})");
+ }
}
}
```
@@ -712,21 +707,16 @@ value of the `y` field. The third arm doesn’t specify any literals, so it
matches any other `Point` and creates variables for both the `x` and `y` fields.
In this example, the value `p` matches the second arm by virtue of `x`
-containing a 0, so this code will print `On the y axis at 7`.
+containing a `0`, so this code will print `On the y axis at 7`.
Remember that a `match` expression stops checking arms once it has found the
first matching pattern, so even though `Point { x: 0, y: 0}` is on the `x` axis
and the `y` axis, this code would only print `On the x axis at 0`.
-<!-- We should remind them that we stop at the first pattern, so even though
-0,0 is on both x- and y-axis in a sense, you'll only ever see the "on x-axis
-message" /JT -->
-<!-- Done! /Carol -->
-
#### Destructuring Enums
-We've destructured enums in this book (for example, Listing 6-5 in Chapter 6),
-but haven’t yet explicitly discussed that the pattern to destructure an enum
+We’ve destructured enums in this book (for example, Listing 6-5), but we
+haven’t yet explicitly discussed that the pattern to destructure an enum
corresponds to the way the data stored within the enum is defined. As an
example, in Listing 18-15 we use the `Message` enum from Listing 6-2 and write
a `match` with patterns that will destructure each inner value.
@@ -742,22 +732,24 @@ enum Message {
}
fn main() {
- [1] let msg = Message::ChangeColor(0, 160, 255);
+ 1 let msg = Message::ChangeColor(0, 160, 255);
match msg {
- [2] Message::Quit => {
- println!("The Quit variant has no data to destructure.")
+ 2 Message::Quit => {
+ println!(
+ "The Quit variant has no data to destructure."
+ );
}
- [3] Message::Move { x, y } => {
+ 3 Message::Move { x, y } => {
println!(
- "Move in the x direction {} and in the y direction {}",
- x, y
+ "Move in the x dir {x}, in the y dir {y}"
);
}
- [4] Message::Write(text) => println!("Text message: {}", text),
- [5] Message::ChangeColor(r, g, b) => println!(
- "Change the color to red {}, green {}, and blue {}",
- r, g, b
+ 4 Message::Write(text) => {
+ println!("Text message: {text}");
+ }
+ 5 Message::ChangeColor(r, g, b) => println!(
+ "Change color to red {r}, green {g}, and blue {b}"
),
}
}
@@ -765,7 +757,7 @@ fn main() {
Listing 18-15: Destructuring enum variants that hold different kinds of values
-This code will print `Change the color to red 0, green 160, and blue 255`. Try
+This code will print `Change color to red 0, green 160, and blue 255`. Try
changing the value of `msg` [1] to see the code from the other arms run.
For enum variants without any data, like `Message::Quit` [2], we can’t
@@ -791,6 +783,8 @@ but matching can work on nested items too! For example, we can refactor the
code in Listing 18-15 to support RGB and HSV colors in the `ChangeColor`
message, as shown in Listing 18-16.
+Filename: src/main.rs
+
```
enum Color {
Rgb(i32, i32, i32),
@@ -809,12 +803,10 @@ fn main() {
match msg {
Message::ChangeColor(Color::Rgb(r, g, b)) => println!(
- "Change the color to red {}, green {}, and blue {}",
- r, g, b
+ "Change color to red {r}, green {g}, and blue {b}"
),
Message::ChangeColor(Color::Hsv(h, s, v)) => println!(
- "Change the color to hue {}, saturation {}, and value {}",
- h, s, v
+ "Change color to hue {h}, saturation {s}, value {v}"
),
_ => (),
}
@@ -837,7 +829,8 @@ The following example shows a complicated destructure where we nest structs and
tuples inside a tuple and destructure all the primitive values out:
```
-let ((feet, inches), Point { x, y }) = ((3, 10), Point { x: 3, y: -10 });
+let ((feet, inches), Point { x, y }) =
+ ((3, 10), Point { x: 3, y: -10 });
```
This code lets us break complex types into their component parts so we can use
@@ -856,7 +849,7 @@ pattern (which you’ve seen), using the `_` pattern within another pattern,
using a name that starts with an underscore, or using `..` to ignore remaining
parts of a value. Let’s explore how and why to use each of these patterns.
-#### Ignoring an Entire Value with `_`
+#### An Entire Value with _
We’ve used the underscore as a wildcard pattern that will match any value but
not bind to the value. This is especially useful as the last arm in a `match`
@@ -867,7 +860,7 @@ Filename: src/main.rs
```
fn foo(_: i32, y: i32) {
- println!("This code only uses the y parameter: {}", y);
+ println!("This code only uses the y parameter: {y}");
}
fn main() {
@@ -883,12 +876,12 @@ and will print `This code only uses the y parameter: 4`.
In most cases when you no longer need a particular function parameter, you
would change the signature so it doesn’t include the unused parameter. Ignoring
a function parameter can be especially useful in cases when, for example,
-you're implementing a trait when you need a certain type signature but the
+you’re implementing a trait when you need a certain type signature but the
function body in your implementation doesn’t need one of the parameters. You
then avoid getting a compiler warning about unused function parameters, as you
would if you used a name instead.
-#### Ignoring Parts of a Value with a Nested `_`
+#### Parts of a Value with a Nested _
We can also use `_` inside another pattern to ignore just part of a value, for
example, when we want to test for only part of a value but have no use for the
@@ -897,6 +890,8 @@ responsible for managing a setting’s value. The business requirements are that
the user should not be allowed to overwrite an existing customization of a
setting but can unset the setting and give it a value if it is currently unset.
+Filename: src/main.rs
+
```
let mut setting_value = Some(5);
let new_setting_value = Some(10);
@@ -923,30 +918,32 @@ when `setting_value` and `new_setting_value` are the `Some` variant. In that
case, we print the reason for not changing `setting_value`, and it doesn’t get
changed.
-In all other cases (if either `setting_value` or `new_setting_value` are
-`None`) expressed by the `_` pattern in the second arm, we want to allow
+In all other cases (if either `setting_value` or `new_setting_value` is `None`)
+expressed by the `_` pattern in the second arm, we want to allow
`new_setting_value` to become `setting_value`.
We can also use underscores in multiple places within one pattern to ignore
particular values. Listing 18-19 shows an example of ignoring the second and
fourth values in a tuple of five items.
+Filename: src/main.rs
+
```
let numbers = (2, 4, 8, 16, 32);
match numbers {
(first, _, third, _, fifth) => {
- println!("Some numbers: {first}, {third}, {fifth}")
+ println!("Some numbers: {first}, {third}, {fifth}");
}
}
```
Listing 18-19: Ignoring multiple parts of a tuple
-This code will print `Some numbers: 2, 8, 32`, and the values 4 and 16 will be
-ignored.
+This code will print `Some numbers: 2, 8, 32`, and the values `4` and `16` will
+be ignored.
-#### Ignoring an Unused Variable by Starting Its Name with `_`
+#### An Unused Variable by Starting Its Name with _
If you create a variable but don’t use it anywhere, Rust will usually issue a
warning because an unused variable could be a bug. However, sometimes it’s
@@ -965,10 +962,10 @@ fn main() {
}
```
-Listing 18-20: Starting a variable name with an
-underscore to avoid getting unused variable warnings
+Listing 18-20: Starting a variable name with an underscore to avoid getting
+unused variable warnings
-Here we get a warning about not using the variable `y`, but we don’t get a
+Here, we get a warning about not using the variable `y`, but we don’t get a
warning about not using `_x`.
Note that there is a subtle difference between using only `_` and using a name
@@ -976,6 +973,8 @@ that starts with an underscore. The syntax `_x` still binds the value to the
variable, whereas `_` doesn’t bind at all. To show a case where this
distinction matters, Listing 18-21 will provide us with an error.
+Filename: src/main.rs
+
```
let s = Some(String::from("Hello!"));
@@ -987,13 +986,15 @@ println!("{:?}", s);
```
Listing 18-21: An unused variable starting with an underscore still binds the
-value, which might take ownership of the value
+value, which might take ownership of the value.
We’ll receive an error because the `s` value will still be moved into `_s`,
which prevents us from using `s` again. However, using the underscore by itself
doesn’t ever bind to the value. Listing 18-22 will compile without any errors
because `s` doesn’t get moved into `_`.
+Filename: src/main.rs
+
```
let s = Some(String::from("Hello!"));
@@ -1004,11 +1005,11 @@ if let Some(_) = s {
println!("{:?}", s);
```
-Listing 18-22: Using an underscore does not bind the value
+Listing 18-22: Using an underscore does not bind the value.
This code works just fine because we never bind `s` to anything; it isn’t moved.
-#### Ignoring Remaining Parts of a Value with `..`
+#### Remaining Parts of a Value with ..
With values that have many parts, we can use the `..` syntax to use specific
parts and ignore the rest, avoiding the need to list underscores for each
@@ -1018,6 +1019,8 @@ explicitly matched in the rest of the pattern. In Listing 18-23, we have a
`match` expression, we want to operate only on the `x` coordinate and ignore
the values in the `y` and `z` fields.
+Filename: src/main.rs
+
```
struct Point {
x: i32,
@@ -1028,7 +1031,7 @@ struct Point {
let origin = Point { x: 0, y: 0, z: 0 };
match origin {
- Point { x, .. } => println!("x is {}", x),
+ Point { x, .. } => println!("x is {x}"),
}
```
@@ -1059,8 +1062,8 @@ fn main() {
Listing 18-24: Matching only the first and last values in a tuple and ignoring
all other values
-In this code, the first and last value are matched with `first` and `last`. The
-`..` will match and ignore everything in the middle.
+In this code, the first and last values are matched with `first` and `last`.
+The `..` will match and ignore everything in the middle.
However, using `..` must be unambiguous. If it is unclear which values are
intended for matching and which should be ignored, Rust will give us an error.
@@ -1075,7 +1078,7 @@ fn main() {
match numbers {
(.., second, ..) => {
- println!("Some numbers: {}", second)
+ println!("Some numbers: {second}");
},
}
}
@@ -1111,14 +1114,16 @@ useful for expressing more complex ideas than a pattern alone allows.
The condition can use variables created in the pattern. Listing 18-26 shows a
`match` where the first arm has the pattern `Some(x)` and also has a match
-guard of `if x % 2 == 0` (which will be true if the number is even).
+guard of `if x % 2 == 0` (which will be `true` if the number is even).
+
+Filename: src/main.rs
```
let num = Some(4);
match num {
- Some(x) if x % 2 == 0 => println!("The number {} is even", x),
- Some(x) => println!("The number {} is odd", x),
+ Some(x) if x % 2 == 0 => println!("The number {x} is even"),
+ Some(x) => println!("The number {x} is odd"),
None => (),
}
```
@@ -1126,18 +1131,18 @@ match num {
Listing 18-26: Adding a match guard to a pattern
This example will print `The number 4 is even`. When `num` is compared to the
-pattern in the first arm, it matches, because `Some(4)` matches `Some(x)`. Then
+pattern in the first arm, it matches because `Some(4)` matches `Some(x)`. Then
the match guard checks whether the remainder of dividing `x` by 2 is equal to
0, and because it is, the first arm is selected.
If `num` had been `Some(5)` instead, the match guard in the first arm would
-have been false because the remainder of 5 divided by 2 is 1, which is not
+have been `false` because the remainder of 5 divided by 2 is 1, which is not
equal to 0. Rust would then go to the second arm, which would match because the
second arm doesn’t have a match guard and therefore matches any `Some` variant.
There is no way to express the `if x % 2 == 0` condition within a pattern, so
the match guard gives us the ability to express this logic. The downside of
-this additional expressiveness is that the compiler doesn't try to check for
+this additional expressiveness is that the compiler doesn’t try to check for
exhaustiveness when match guard expressions are involved.
In Listing 18-11, we mentioned that we could use match guards to solve our
@@ -1185,6 +1190,8 @@ guard. The important part of this example is that the `if y` match guard
applies to `4`, `5`, *and* `6`, even though it might look like `if y` only
applies to `6`.
+Filename: src/main.rs
+
```
let x = 4;
let y = false;
@@ -1200,11 +1207,11 @@ Listing 18-28: Combining multiple patterns with a match guard
The match condition states that the arm only matches if the value of `x` is
equal to `4`, `5`, or `6` *and* if `y` is `true`. When this code runs, the
pattern of the first arm matches because `x` is `4`, but the match guard `if y`
-is false, so the first arm is not chosen. The code moves on to the second arm,
-which does match, and this program prints `no`. The reason is that the `if`
-condition applies to the whole pattern `4 | 5 | 6`, not only to the last value
-`6`. In other words, the precedence of a match guard in relation to a pattern
-behaves like this:
+is `false`, so the first arm is not chosen. The code moves on to the second
+arm, which does match, and this program prints `no`. The reason is that the
+`if` condition applies to the whole pattern `4 | 5 | 6`, not just to the last
+value `6`. In other words, the precedence of a match guard in relation to a
+pattern behaves like this:
```
(4 | 5 | 6) if y => ...
@@ -1221,15 +1228,17 @@ were applied only to the final value in the list of values specified using the
`|` operator, the arm would have matched and the program would have printed
`yes`.
-### `@` Bindings
+### @ Bindings
The *at* operator `@` lets us create a variable that holds a value at the same
-time as we’re testing that value for a pattern match. In Listing 18-29, we want
-to test that a `Message::Hello` `id` field is within the range `3..=7`. We also
+time we’re testing that value for a pattern match. In Listing 18-29, we want to
+test that a `Message::Hello` `id` field is within the range `3..=7`. We also
want to bind the value to the variable `id_variable` so we can use it in the
code associated with the arm. We could name this variable `id`, the same as the
field, but for this example we’ll use a different name.
+Filename: src/main.rs
+
```
enum Message {
Hello { id: i32 },
@@ -1240,11 +1249,11 @@ let msg = Message::Hello { id: 5 };
match msg {
Message::Hello {
id: id_variable @ 3..=7,
- } => println!("Found an id in range: {}", id_variable),
+ } => println!("Found an id in range: {id_variable}"),
Message::Hello { id: 10..=12 } => {
println!("Found an id in another range")
}
- Message::Hello { id } => println!("Found some other id: {}", id),
+ Message::Hello { id } => println!("Some other id: {id}"),
}
```
@@ -1254,12 +1263,12 @@ This example will print `Found an id in range: 5`. By specifying `id_variable
@` before the range `3..=7`, we’re capturing whatever value matched the range
while also testing that the value matched the range pattern.
-In the second arm, where we only have a range specified in the pattern, the code
-associated with the arm doesn’t have a variable that contains the actual value
-of the `id` field. The `id` field’s value could have been 10, 11, or 12, but
-the code that goes with that pattern doesn’t know which it is. The pattern code
-isn’t able to use the value from the `id` field, because we haven’t saved the
-`id` value in a variable.
+In the second arm, where we only have a range specified in the pattern, the
+code associated with the arm doesn’t have a variable that contains the actual
+value of the `id` field. The `id` field’s value could have been 10, 11, or 12,
+but the code that goes with that pattern doesn’t know which it is. The pattern
+code isn’t able to use the value from the `id` field because we haven’t saved
+the `id` value in a variable.
In the last arm, where we’ve specified a variable without a range, we do have
the value available to use in the arm’s code in a variable named `id`. The
@@ -1280,3 +1289,4 @@ variables. We can create simple or complex patterns to suit our needs.
Next, for the penultimate chapter of the book, we’ll look at some advanced
aspects of a variety of Rust’s features.
+
diff --git a/src/doc/book/nostarch/chapter19.md b/src/doc/book/nostarch/chapter19.md
index 5ef3fd7a2..410e7eb62 100644
--- a/src/doc/book/nostarch/chapter19.md
+++ b/src/doc/book/nostarch/chapter19.md
@@ -9,7 +9,7 @@ directory, so all fixes need to be made in `/src/`.
# Advanced Features
By now, you’ve learned the most commonly used parts of the Rust programming
-language. Before we do one more project in Chapter 20, we’ll look at a few
+language. Before we do one more project, in Chapter 20, we’ll look at a few
aspects of the language you might run into every once in a while, but may not
use every day. You can use this chapter as a reference for when you encounter
any unknowns. The features covered here are useful in very specific situations.
@@ -19,11 +19,11 @@ grasp of all the features Rust has to offer.
In this chapter, we’ll cover:
* Unsafe Rust: how to opt out of some of Rust’s guarantees and take
- responsibility for manually upholding those guarantees
+responsibility for manually upholding those guarantees
* Advanced traits: associated types, default type parameters, fully qualified
- syntax, supertraits, and the newtype pattern in relation to traits
+syntax, supertraits, and the newtype pattern in relation to traits
* Advanced types: more about the newtype pattern, type aliases, the never type,
- and dynamically sized types
+and dynamically sized types
* Advanced functions and closures: function pointers and returning closures
* Macros: ways to define code that defines more code at compile time
@@ -61,30 +61,30 @@ that holds the unsafe code. You can take five actions in unsafe Rust that you
can’t in safe Rust, which we call *unsafe superpowers*. Those superpowers
include the ability to:
-* Dereference a raw pointer
-* Call an unsafe function or method
-* Access or modify a mutable static variable
-* Implement an unsafe trait
-* Access fields of `union`s
+1. Dereference a raw pointer
+1. Call an unsafe function or method
+1. Access or modify a mutable static variable
+1. Implement an unsafe trait
+1. Access fields of `union`s
It’s important to understand that `unsafe` doesn’t turn off the borrow checker
-or disable any other of Rust’s safety checks: if you use a reference in unsafe
+or disable any of Rust’s other safety checks: if you use a reference in unsafe
code, it will still be checked. The `unsafe` keyword only gives you access to
these five features that are then not checked by the compiler for memory
-safety. You’ll still get some degree of safety inside of an unsafe block.
+safety. You’ll still get some degree of safety inside an unsafe block.
In addition, `unsafe` does not mean the code inside the block is necessarily
dangerous or that it will definitely have memory safety problems: the intent is
that as the programmer, you’ll ensure the code inside an `unsafe` block will
access memory in a valid way.
-People are fallible, and mistakes will happen, but by requiring these five
-unsafe operations to be inside blocks annotated with `unsafe` you’ll know that
+People are fallible and mistakes will happen, but by requiring these five
+unsafe operations to be inside blocks annotated with `unsafe`, you’ll know that
any errors related to memory safety must be within an `unsafe` block. Keep
`unsafe` blocks small; you’ll be thankful later when you investigate memory
bugs.
-To isolate unsafe code as much as possible, it’s best to enclose unsafe code
+To isolate unsafe code as much as possible, it’s best to enclose such code
within a safe abstraction and provide a safe API, which we’ll discuss later in
the chapter when we examine unsafe functions and methods. Parts of the standard
library are implemented as safe abstractions over unsafe code that has been
@@ -98,18 +98,18 @@ some abstractions that provide a safe interface to unsafe code.
### Dereferencing a Raw Pointer
-In Chapter 4, in the “Dangling References†section, we mentioned that the
-compiler ensures references are always valid. Unsafe Rust has two new types
-called *raw pointers* that are similar to references. As with references, raw
-pointers can be immutable or mutable and are written as `*const T` and `*mut
-T`, respectively. The asterisk isn’t the dereference operator; it’s part of the
+In “Dangling References†on page XX, we mentioned that the compiler ensures
+references are always valid. Unsafe Rust has two new types called *raw
+pointers* that are similar to references. As with references, raw pointers can
+be immutable or mutable and are written as `*const T` and `*mut T`,
+respectively. The asterisk isn’t the dereference operator; it’s part of the
type name. In the context of raw pointers, *immutable* means that the pointer
can’t be directly assigned to after being dereferenced.
Different from references and smart pointers, raw pointers:
* Are allowed to ignore the borrowing rules by having both immutable and
- mutable pointers or multiple mutable pointers to the same location
+mutable pointers or multiple mutable pointers to the same location
* Aren’t guaranteed to point to valid memory
* Are allowed to be null
* Don’t implement any automatic cleanup
@@ -144,9 +144,9 @@ To demonstrate this, next we’ll create a raw pointer whose validity we can’t
so certain of. Listing 19-2 shows how to create a raw pointer to an arbitrary
location in memory. Trying to use arbitrary memory is undefined: there might be
data at that address or there might not, the compiler might optimize the code
-so there is no memory access, or the program might error with a segmentation
-fault. Usually, there is no good reason to write code like this, but it is
-possible.
+so there is no memory access, or the program might terminate with a
+segmentation fault. Usually, there is no good reason to write code like this,
+but it is possible.
```
let address = 0x012345usize;
@@ -176,8 +176,8 @@ Listing 19-3: Dereferencing raw pointers within an `unsafe` block
Creating a pointer does no harm; it’s only when we try to access the value that
it points at that we might end up dealing with an invalid value.
-Note also that in Listing 19-1 and 19-3, we created `*const i32` and `*mut i32`
-raw pointers that both pointed to the same memory location, where `num` is
+Note also that in Listings 19-1 and 19-3, we created `*const i32` and `*mut
+i32` raw pointers that both pointed to the same memory location, where `num` is
stored. If we instead tried to create an immutable and a mutable reference to
`num`, the code would not have compiled because Rust’s ownership rules don’t
allow a mutable reference at the same time as any immutable references. With
@@ -186,8 +186,8 @@ same location and change data through the mutable pointer, potentially creating
a data race. Be careful!
With all of these dangers, why would you ever use raw pointers? One major use
-case is when interfacing with C code, as you’ll see in the next section,
-“Calling an Unsafe Function or Method.†Another case is when building up safe
+case is when interfacing with C code, as you’ll see in “Calling an Unsafe
+Function or Method†on page XX. Another case is when building up safe
abstractions that the borrow checker doesn’t understand. We’ll introduce unsafe
functions and then look at an example of a safe abstraction that uses unsafe
code.
@@ -201,7 +201,7 @@ definition. The `unsafe` keyword in this context indicates the function has
requirements we need to uphold when we call this function, because Rust can’t
guarantee we’ve met these requirements. By calling an unsafe function within an
`unsafe` block, we’re saying that we’ve read this function’s documentation and
-take responsibility for upholding the function’s contracts.
+we take responsibility for upholding the function’s contracts.
Here is an unsafe function named `dangerous` that doesn’t do anything in its
body:
@@ -218,13 +218,15 @@ We must call the `dangerous` function within a separate `unsafe` block. If we
try to call `dangerous` without the `unsafe` block, we’ll get an error:
```
-error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
+error[E0133]: call to unsafe function is unsafe and requires
+unsafe function or block
--> src/main.rs:4:5
|
4 | dangerous();
| ^^^^^^^^^^^ call to unsafe function
|
- = note: consult the function's documentation for information on how to avoid undefined behavior
+ = note: consult the function's documentation for information on
+how to avoid undefined behavior
```
With the `unsafe` block, we’re asserting to Rust that we’ve read the function’s
@@ -264,7 +266,10 @@ implement `split_at_mut` as a function rather than a method and only for slices
of `i32` values rather than for a generic type `T`.
```
-fn split_at_mut(values: &mut [i32], mid: usize) -> (&mut [i32], &mut [i32]) {
+fn split_at_mut(
+ values: &mut [i32],
+ mid: usize,
+) -> (&mut [i32], &mut [i32]) {
let len = values.len();
assert!(mid <= len);
@@ -289,12 +294,12 @@ When we try to compile the code in Listing 19-5, we’ll get an error:
```
error[E0499]: cannot borrow `*values` as mutable more than once at a time
- --> src/main.rs:6:31
+ --> src/main.rs:9:31
|
-1 | fn split_at_mut(values: &mut [i32], mid: usize) -> (&mut [i32], &mut [i32]) {
- | - let's call the lifetime of this reference `'1`
+2 | values: &mut [i32],
+ | - let's call the lifetime of this reference `'1`
...
-6 | (&mut values[..mid], &mut values[mid..])
+9 | (&mut values[..mid], &mut values[mid..])
| --------------------------^^^^^^--------
| | | |
| | | second mutable borrow occurs here
@@ -314,16 +319,19 @@ to unsafe functions to make the implementation of `split_at_mut` work.
```
use std::slice;
-fn split_at_mut(values: &mut [i32], mid: usize) -> (&mut [i32], &mut [i32]) {
- [1] let len = values.len();
- [2] let ptr = values.as_mut_ptr();
+fn split_at_mut(
+ values: &mut [i32],
+ mid: usize,
+) -> (&mut [i32], &mut [i32]) {
+ 1 let len = values.len();
+ 2 let ptr = values.as_mut_ptr();
- [3] assert!(mid <= len);
+ 3 assert!(mid <= len);
- [4] unsafe {
+ 4 unsafe {
(
- [5] slice::from_raw_parts_mut(ptr, mid),
- [6] slice::from_raw_parts_mut(ptr.add(mid), len - mid),
+ 5 slice::from_raw_parts_mut(ptr, mid),
+ 6 slice::from_raw_parts_mut(ptr.add(mid), len - mid),
)
}
}
@@ -332,13 +340,12 @@ fn split_at_mut(values: &mut [i32], mid: usize) -> (&mut [i32], &mut [i32]) {
Listing 19-6: Using unsafe code in the implementation of the `split_at_mut`
function
-
-Recall from “The Slice Type†section in Chapter 4 that a slice is a pointer to
-some data and the length of the slice. We use the `len` method to get the
-length of a slice [1] and the `as_mut_ptr` method to access the raw pointer of
-a slice [2]. In this case, because we have a mutable slice to `i32` values,
-`as_mut_ptr` returns a raw pointer with the type `*mut i32`, which we’ve stored
-in the variable `ptr`.
+Recall from “The Slice Type†on page XX that a slice is a pointer to some data
+and the length of the slice. We use the `len` method to get the length of a
+slice [1] and the `as_mut_ptr` method to access the raw pointer of a slice [2].
+In this case, because we have a mutable slice to `i32` values, `as_mut_ptr`
+returns a raw pointer with the type `*mut i32`, which we’ve stored in the
+variable `ptr`.
We keep the assertion that the `mid` index is within the slice [3]. Then we get
to the unsafe code [4]: the `slice::from_raw_parts_mut` function takes a raw
@@ -350,15 +357,15 @@ we create a slice using that pointer and the remaining number of items after
The function `slice::from_raw_parts_mut` is unsafe because it takes a raw
pointer and must trust that this pointer is valid. The `add` method on raw
-pointers is also unsafe, because it must trust that the offset location is also
+pointers is also unsafe because it must trust that the offset location is also
a valid pointer. Therefore, we had to put an `unsafe` block around our calls to
-`slice::from_raw_parts_mut` and `add` so we could call them. By looking at
-the code and by adding the assertion that `mid` must be less than or equal to
+`slice::from_raw_parts_mut` and `add` so we could call them. By looking at the
+code and by adding the assertion that `mid` must be less than or equal to
`len`, we can tell that all the raw pointers used within the `unsafe` block
will be valid pointers to data within the slice. This is an acceptable and
appropriate use of `unsafe`.
-Note that we don’t need to mark the resulting `split_at_mut` function as
+Note that we don’t need to mark the resultant `split_at_mut` function as
`unsafe`, and we can call this function from safe Rust. We’ve created a safe
abstraction to the unsafe code with an implementation of the function that uses
`unsafe` code in a safe way, because it creates only valid pointers from the
@@ -374,7 +381,9 @@ use std::slice;
let address = 0x01234usize;
let r = address as *mut i32;
-let values: &[i32] = unsafe { slice::from_raw_parts_mut(r, 10000) };
+let values: &[i32] = unsafe {
+ slice::from_raw_parts_mut(r, 10000)
+};
```
Listing 19-7: Creating a slice from an arbitrary memory location
@@ -383,11 +392,11 @@ We don’t own the memory at this arbitrary location, and there is no guarantee
that the slice this code creates contains valid `i32` values. Attempting to use
`values` as though it’s a valid slice results in undefined behavior.
-#### Using `extern` Functions to Call External Code
+#### Using extern Functions to Call External Code
-Sometimes, your Rust code might need to interact with code written in another
+Sometimes your Rust code might need to interact with code written in another
language. For this, Rust has the keyword `extern` that facilitates the creation
-and use of a *Foreign Function Interface (FFI)*. An FFI is a way for a
+and use of a *Foreign Function Interface* *(FFI)*, which is a way for a
programming language to define functions and enable a different (foreign)
programming language to call those functions.
@@ -406,7 +415,10 @@ extern "C" {
fn main() {
unsafe {
- println!("Absolute value of -3 according to C: {}", abs(-3));
+ println!(
+ "Absolute value of -3 according to C: {}",
+ abs(-3)
+ );
}
}
```
@@ -416,33 +428,25 @@ language
Within the `extern "C"` block, we list the names and signatures of external
functions from another language we want to call. The `"C"` part defines which
-*application binary interface (ABI)* the external function uses: the ABI
+*application binary interface* *(ABI)* the external function uses: the ABI
defines how to call the function at the assembly level. The `"C"` ABI is the
most common and follows the C programming language’s ABI.
-<!-- Totally optional - but do we want to mention the other external types
-that Rust supports here? Also, do we want to mention there are helper
-crates for connecting to other languages, include C++?
-/JT -->
-<!-- I don't really want to get into the other external types or other
-languages; there are other resources that cover these topics better than I
-could here. /Carol -->
-
-> #### Calling Rust Functions from Other Languages
+> ### Calling Rust Functions from Other Languages
>
> We can also use `extern` to create an interface that allows other languages
-> to call Rust functions. Instead of an creating a whole `extern` block, we add
-> the `extern` keyword and specify the ABI to use just before the `fn` keyword
-> for the relevant function. We also need to add a `#[no_mangle]` annotation to
-> tell the Rust compiler not to mangle the name of this function. *Mangling* is
-> when a compiler changes the name we’ve given a function to a different name
-> that contains more information for other parts of the compilation process to
-> consume but is less human readable. Every programming language compiler
-> mangles names slightly differently, so for a Rust function to be nameable by
-> other languages, we must disable the Rust compiler’s name mangling.
+to call Rust functions. Instead of creating a whole `extern` block, we add the
+`extern` keyword and specify the ABI to use just before the `fn` keyword for
+the relevant function. We also need to add a `#[no_mangle]` annotation to tell
+the Rust compiler not to mangle the name of this function. *Mangling* is when a
+compiler changes the name we’ve given a function to a different name that
+contains more information for other parts of the compilation process to consume
+but is less human readable. Every programming language compiler mangles names
+slightly differently, so for a Rust function to be nameable by other languages,
+we must disable the Rust compiler’s name mangling.
>
> In the following example, we make the `call_from_c` function accessible from
-> C code, after it’s compiled to a shared library and linked from C:
+C code, after it’s compiled to a shared library and linked from C:
>
> ```
> #[no_mangle]
@@ -455,13 +459,12 @@ could here. /Carol -->
### Accessing or Modifying a Mutable Static Variable
-In this book, we’ve not yet talked about *global variables*, which Rust does
+In this book, we’ve not yet talked about global variables, which Rust does
support but can be problematic with Rust’s ownership rules. If two threads are
accessing the same mutable global variable, it can cause a data race.
In Rust, global variables are called *static* variables. Listing 19-9 shows an
-example declaration and use of a static variable with a string slice as a
-value.
+example declaration and use of a static variable with a string slice as a value.
Filename: src/main.rs
@@ -469,18 +472,18 @@ Filename: src/main.rs
static HELLO_WORLD: &str = "Hello, world!";
fn main() {
- println!("name is: {}", HELLO_WORLD);
+ println!("value is: {HELLO_WORLD}");
}
```
Listing 19-9: Defining and using an immutable static variable
-Static variables are similar to constants, which we discussed in the
-“Differences Between Variables and Constants†section in Chapter 3. The names
-of static variables are in `SCREAMING_SNAKE_CASE` by convention. Static
-variables can only store references with the `'static` lifetime, which means
-the Rust compiler can figure out the lifetime and we aren’t required to
-annotate it explicitly. Accessing an immutable static variable is safe.
+Static variables are similar to constants, which we discussed in “Constants†on
+page XX. The names of static variables are in `SCREAMING_SNAKE_CASE` by
+convention. Static variables can only store references with the `'static`
+lifetime, which means the Rust compiler can figure out the lifetime and we
+aren’t required to annotate it explicitly. Accessing an immutable static
+variable is safe.
A subtle difference between constants and immutable static variables is that
values in a static variable have a fixed address in memory. Using the value
@@ -505,12 +508,12 @@ fn main() {
add_to_count(3);
unsafe {
- println!("COUNTER: {}", COUNTER);
+ println!("COUNTER: {COUNTER}");
}
}
```
-Listing 19-10: Reading from or writing to a mutable static variable is unsafe
+Listing 19-10: Reading from or writing to a mutable static variable is unsafe.
As with regular variables, we specify mutability using the `mut` keyword. Any
code that reads or writes from `COUNTER` must be within an `unsafe` block. This
@@ -522,7 +525,7 @@ With mutable data that is globally accessible, it’s difficult to ensure there
are no data races, which is why Rust considers mutable static variables to be
unsafe. Where possible, it’s preferable to use the concurrency techniques and
thread-safe smart pointers we discussed in Chapter 16 so the compiler checks
-that data accessed from different threads is done safely.
+that data access from different threads is done safely.
### Implementing an Unsafe Trait
@@ -540,8 +543,6 @@ unsafe trait Foo {
unsafe impl Foo for i32 {
// method implementations go here
}
-
-fn main() {}
```
Listing 19-11: Defining and implementing an unsafe trait
@@ -549,25 +550,25 @@ Listing 19-11: Defining and implementing an unsafe trait
By using `unsafe impl`, we’re promising that we’ll uphold the invariants that
the compiler can’t verify.
-As an example, recall the `Sync` and `Send` marker traits we discussed in the
-“Extensible Concurrency with the `Sync` and `Send` Traits†section in Chapter
-16: the compiler implements these traits automatically if our types are
-composed entirely of `Send` and `Sync` types. If we implement a type that
-contains a type that is not `Send` or `Sync`, such as raw pointers, and we want
-to mark that type as `Send` or `Sync`, we must use `unsafe`. Rust can’t verify
-that our type upholds the guarantees that it can be safely sent across threads
-or accessed from multiple threads; therefore, we need to do those checks
-manually and indicate as such with `unsafe`.
+As an example, recall the `Send` and `Sync` marker traits we discussed in
+“Extensible Concurrency with the Send and Sync Traits†on page XX: the compiler
+implements these traits automatically if our types are composed entirely of
+`Send` and `Sync` types. If we implement a type that contains a type that is
+not `Send` or `Sync`, such as raw pointers, and we want to mark that type as
+`Send` or `Sync`, we must use `unsafe`. Rust can’t verify that our type upholds
+the guarantees that it can be safely sent across threads or accessed from
+multiple threads; therefore, we need to do those checks manually and indicate
+as such with `unsafe`.
### Accessing Fields of a Union
-The final action that works only with `unsafe` is accessing fields of a
-*union*. A `union` is similar to a `struct`, but only one declared field is
-used in a particular instance at one time. Unions are primarily used to
-interface with unions in C code. Accessing union fields is unsafe because Rust
-can’t guarantee the type of the data currently being stored in the union
-instance. You can learn more about unions in the Rust Reference at
-*https://doc.rust-lang.org/reference/items/unions.html*.
+The final action that works only with `unsafe` is accessing fields of a union.
+A `union` is similar to a `struct`, but only one declared field is used in a
+particular instance at one time. Unions are primarily used to interface with
+unions in C code. Accessing union fields is unsafe because Rust can’t guarantee
+the type of the data currently being stored in the union instance. You can
+learn more about unions in the Rust Reference at
+*https://doc.rust-lang.org/reference/items/unions.html**.*
### When to Use Unsafe Code
@@ -579,11 +580,11 @@ it easier to track down the source of problems when they occur.
## Advanced Traits
-We first covered traits in the “Traits: Defining Shared Behavior†section of
-Chapter 10, but we didn’t discuss the more advanced details. Now that you know
-more about Rust, we can get into the nitty-gritty.
+We first covered traits in “Traits: Defining Shared Behavior†on page XX, but
+we didn’t discuss the more advanced details. Now that you know more about Rust,
+we can get into the nitty-gritty.
-### Specifying Placeholder Types in Trait Definitions with Associated Types
+### Associated Types
*Associated types* connect a type placeholder with a trait such that the trait
method definitions can use these placeholder types in their signatures. The
@@ -632,7 +633,7 @@ impl Iterator for Counter {
type Item = u32;
fn next(&mut self) -> Option<Self::Item> {
- // --snip--
+ --snip--
```
This syntax seems comparable to that of generics. So why not just define the
@@ -648,7 +649,7 @@ Listing 19-13: A hypothetical definition of the `Iterator` trait using generics
The difference is that when using generics, as in Listing 19-13, we must
annotate the types in each implementation; because we can also implement
-`Iterator<String> for Counter` or any other type, we could have multiple
+`Iterator<``String``> for Counter` or any other type, we could have multiple
implementations of `Iterator` for `Counter`. In other words, when a trait has a
generic parameter, it can be implemented for a type multiple times, changing
the concrete types of the generic type parameters each time. When we use the
@@ -657,29 +658,23 @@ indicate which implementation of `Iterator` we want to use.
With associated types, we don’t need to annotate types because we can’t
implement a trait on a type multiple times. In Listing 19-12 with the
-definition that uses associated types, we can only choose what the type of
-`Item` will be once, because there can only be one `impl Iterator for Counter`.
-We don’t have to specify that we want an iterator of `u32` values everywhere
-that we call `next` on `Counter`.
+definition that uses associated types, we can choose what the type of `Item`
+will be only once because there can be only one `impl Iterator for Counter`. We
+don’t have to specify that we want an iterator of `u32` values everywhere we
+call `next` on `Counter`.
Associated types also become part of the trait’s contract: implementors of the
trait must provide a type to stand in for the associated type placeholder.
Associated types often have a name that describes how the type will be used,
-and documenting the associated type in the API documentation is good practice.
-
-<!-- It also makes the type a part of the trait's contract. Not sure if
-too subtle of a point, but the associated type of a trait is part of the
-require things that the implementor must provide. They often also have a name
-that may clue you in as to how that required type will be used.
-/JT -->
-<!-- Great points, I've added a small paragraph here! /Carol -->
+and documenting the associated type in the API documentation is a good practice.
### Default Generic Type Parameters and Operator Overloading
When we use generic type parameters, we can specify a default concrete type for
the generic type. This eliminates the need for implementors of the trait to
specify a concrete type if the default type works. You specify a default type
-when declaring a generic type with the `<PlaceholderType=ConcreteType>` syntax.
+when declaring a generic type with the `<`PlaceholderType`=`ConcreteType`>`
+syntax.
A great example of a situation where this technique is useful is with *operator
overloading*, in which you customize the behavior of an operator (such as `+`)
@@ -690,7 +685,7 @@ operators. But you can overload the operations and corresponding traits listed
in `std::ops` by implementing the traits associated with the operator. For
example, in Listing 19-14 we overload the `+` operator to add two `Point`
instances together. We do this by implementing the `Add` trait on a `Point`
-struct:
+struct.
Filename: src/main.rs
@@ -743,7 +738,7 @@ trait Add<Rhs=Self> {
This code should look generally familiar: a trait with one method and an
associated type. The new part is `Rhs=Self`: this syntax is called *default
-type parameters*. The `Rhs` generic type parameter (short for “right hand
+type parameters*. The `Rhs` generic type parameter (short for “right-hand
sideâ€) defines the type of the `rhs` parameter in the `add` method. If we don’t
specify a concrete type for `Rhs` when we implement the `Add` trait, the type
of `Rhs` will default to `Self`, which will be the type we’re implementing
@@ -756,11 +751,11 @@ default.
We have two structs, `Millimeters` and `Meters`, holding values in different
units. This thin wrapping of an existing type in another struct is known as the
-*newtype pattern*, which we describe in more detail in the “Using the Newtype
-Pattern to Implement External Traits on External Types†section. We want to add
-values in millimeters to values in meters and have the implementation of `Add`
-do the conversion correctly. We can implement `Add` for `Millimeters` with
-`Meters` as the `Rhs`, as shown in Listing 19-15.
+*newtype pattern*, which we describe in more detail in “Using the Newtype
+Pattern to Implement External Traits on External Types†on page XX. We want to
+add values in millimeters to values in meters and have the implementation of
+`Add` do the conversion correctly. We can implement `Add` for `Millimeters`
+with `Meters` as the `Rhs`, as shown in Listing 19-15.
Filename: src/lib.rs
@@ -780,15 +775,15 @@ impl Add<Meters> for Millimeters {
```
Listing 19-15: Implementing the `Add` trait on `Millimeters` to add
-`Millimeters` to `Meters`
+`Millimeters` and `Meters`
To add `Millimeters` and `Meters`, we specify `impl Add<Meters>` to set the
value of the `Rhs` type parameter instead of using the default of `Self`.
You’ll use default type parameters in two main ways:
-* To extend a type without breaking existing code
-* To allow customization in specific cases most users won’t need
+1. To extend a type without breaking existing code
+1. To allow customization in specific cases most users won’t need
The standard library’s `Add` trait is an example of the second purpose:
usually, you’ll add two like types, but the `Add` trait provides the ability to
@@ -802,7 +797,7 @@ type parameter to an existing trait, you can give it a default to allow
extension of the functionality of the trait without breaking the existing
implementation code.
-### Fully Qualified Syntax for Disambiguation: Calling Methods with the Same Name
+### Disambiguating Between Methods with the Same Name
Nothing in Rust prevents a trait from having a method with the same name as
another trait’s method, nor does Rust prevent you from implementing both traits
@@ -849,7 +844,7 @@ impl Human {
Listing 19-16: Two traits are defined to have a `fly` method and are
implemented on the `Human` type, and a `fly` method is implemented on `Human`
-directly
+directly.
When we call `fly` on an instance of `Human`, the compiler defaults to calling
the method that is directly implemented on the type, as shown in Listing 19-17.
@@ -894,10 +889,6 @@ disambiguate.
Running this code prints the following:
```
-$ cargo run
- Compiling traits-example v0.1.0 (file:///projects/traits-example)
- Finished dev [unoptimized + debuginfo] target(s) in 0.46s
- Running `target/debug/traits-example`
This is your captain speaking.
Up!
*waving arms furiously*
@@ -909,12 +900,12 @@ trait to use based on the type of `self`.
However, associated functions that are not methods don’t have a `self`
parameter. When there are multiple types or traits that define non-method
-functions with the same function name, Rust doesn't always know which type you
-mean unless you use *fully qualified syntax*. For example, in Listing 19-19 we
-create a trait for an animal shelter that wants to name all baby dogs *Spot*.
-We make an `Animal` trait with an associated non-method function `baby_name`.
-The `Animal` trait is implemented for the struct `Dog`, on which we also
-provide an associated non-method function `baby_name` directly.
+functions with the same function name, Rust doesn’t always know which type you
+mean unless you use fully qualified syntax. For example, in Listing 19-19 we
+create a trait for an animal shelter that wants to name all baby dogs Spot. We
+make an `Animal` trait with an associated non-method function `baby_name`. The
+`Animal` trait is implemented for the struct `Dog`, on which we also provide an
+associated non-method function `baby_name` directly.
Filename: src/main.rs
@@ -984,7 +975,8 @@ error[E0283]: type annotations needed
--> src/main.rs:20:43
|
20 | println!("A baby dog is called a {}", Animal::baby_name());
- | ^^^^^^^^^^^^^^^^^ cannot infer type
+ | ^^^^^^^^^^^^^^^^^ cannot infer
+type
|
= note: cannot satisfy `_: Animal`
```
@@ -998,7 +990,10 @@ Filename: src/main.rs
```
fn main() {
- println!("A baby dog is called a {}", <Dog as Animal>::baby_name());
+ println!(
+ "A baby dog is called a {}",
+ <Dog as Animal>::baby_name()
+ );
}
```
@@ -1028,20 +1023,20 @@ in the program. You only need to use this more verbose syntax in cases where
there are multiple implementations that use the same name and Rust needs help
to identify which implementation you want to call.
-### Using Supertraits to Require One Trait’s Functionality Within Another Trait
+### Using Supertraits
-Sometimes, you might write a trait definition that depends on another trait:
-for a type to implement the first trait, you want to require that type to also
+Sometimes you might write a trait definition that depends on another trait: for
+a type to implement the first trait, you want to require that type to also
implement the second trait. You would do this so that your trait definition can
make use of the associated items of the second trait. The trait your trait
definition is relying on is called a *supertrait* of your trait.
For example, let’s say we want to make an `OutlinePrint` trait with an
-`outline_print` method that will print a given value formatted so that it's
+`outline_print` method that will print a given value formatted so that it’s
framed in asterisks. That is, given a `Point` struct that implements the
-standard library trait `Display` to result in `(x, y)`, when we
-call `outline_print` on a `Point` instance that has `1` for `x` and `3` for
-`y`, it should print the following:
+standard library trait `Display` to result in `(x, y)`, when we call
+`outline_print` on a `Point` instance that has `1` for `x` and `3` for `y`, it
+should print the following:
```
**********
@@ -1111,7 +1106,8 @@ error[E0277]: `Point` doesn't implement `std::fmt::Display`
| ^^^^^^^^^^^^ `Point` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `Point`
- = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
+ = note: in format strings you may be able to use `{:?}` (or {:#?} for
+pretty-print) instead
note: required by a bound in `OutlinePrint`
--> src/main.rs:3:21
|
@@ -1134,24 +1130,23 @@ impl fmt::Display for Point {
}
```
-Then implementing the `OutlinePrint` trait on `Point` will compile
+Then, implementing the `OutlinePrint` trait on `Point` will compile
successfully, and we can call `outline_print` on a `Point` instance to display
it within an outline of asterisks.
-### Using the Newtype Pattern to Implement External Traits on External Types
-
-In Chapter 10 in the “Implementing a Trait on a Type†section, we mentioned the
-orphan rule that states we’re only allowed to implement a trait on a type if
-either the trait or the type are local to our crate.
-It’s possible to get
-around this restriction using the *newtype pattern*, which involves creating a
-new type in a tuple struct. (We covered tuple structs in the “Using Tuple
-Structs without Named Fields to Create Different Types†section of Chapter 5.)
-The tuple struct will have one field and be a thin wrapper around the type we
-want to implement a trait for. Then the wrapper type is local to our crate, and
-we can implement the trait on the wrapper. *Newtype* is a term that originates
-from the Haskell programming language. There is no runtime performance penalty
-for using this pattern, and the wrapper type is elided at compile time.
+### Using the Newtype Pattern to Implement External Traits
+
+In “Implementing a Trait on a Type†on page XX, we mentioned the orphan rule
+that states we’re only allowed to implement a trait on a type if either the
+trait or the type, or both, are local to our crate. It’s possible to get around
+this restriction using the *newtype pattern*, which involves creating a new
+type in a tuple struct. (We covered tuple structs in “Using Tuple Structs
+Without Named Fields to Create Different Types†on page XX.) The tuple struct
+will have one field and be a thin wrapper around the type for which we want to
+implement a trait. Then the wrapper type is local to our crate, and we can
+implement the trait on the wrapper. *Newtype* is a term that originates from
+the Haskell programming language. There is no runtime performance penalty for
+using this pattern, and the wrapper type is elided at compile time.
As an example, let’s say we want to implement `Display` on `Vec<T>`, which the
orphan rule prevents us from doing directly because the `Display` trait and the
@@ -1173,15 +1168,18 @@ impl fmt::Display for Wrapper {
}
fn main() {
- let w = Wrapper(vec![String::from("hello"), String::from("world")]);
- println!("w = {}", w);
+ let w = Wrapper(vec![
+ String::from("hello"),
+ String::from("world"),
+ ]);
+ println!("w = {w}");
}
```
Listing 19-23: Creating a `Wrapper` type around `Vec<String>` to implement
`Display`
-The implementation of `Display` uses `self.0` to access the inner `Vec<T>`,
+The implementation of `Display` uses `self.0` to access the inner `Vec<T>`
because `Wrapper` is a tuple struct and `Vec<T>` is the item at index 0 in the
tuple. Then we can use the functionality of the `Display` type on `Wrapper`.
@@ -1190,9 +1188,9 @@ doesn’t have the methods of the value it’s holding. We would have to impleme
all the methods of `Vec<T>` directly on `Wrapper` such that the methods
delegate to `self.0`, which would allow us to treat `Wrapper` exactly like a
`Vec<T>`. If we wanted the new type to have every method the inner type has,
-implementing the `Deref` trait (discussed in Chapter 15 in the “Treating Smart
-Pointers Like Regular References with the `Deref` Trait†section) on the
-`Wrapper` to return the inner type would be a solution. If we don’t want the
+implementing the `Deref` trait on the `Wrapper` to return the inner type would
+be a solution (we discussed implementing the `Deref` trait in “Treating Smart
+Pointers Like Regular References with Deref†on page XX). If we didn’t want the
`Wrapper` type to have all the methods of the inner type—for example, to
restrict the `Wrapper` type’s behavior—we would have to implement just the
methods we do want manually.
@@ -1210,16 +1208,15 @@ the `!` type and dynamically sized types.
### Using the Newtype Pattern for Type Safety and Abstraction
-> Note: This section assumes you’ve read the earlier section “Using the
-> Newtype Pattern to Implement External Traits on External
-> Types.â€
+> Note: This section assumes you’ve read the earlier section “Using the Newtype
+Pattern to Implement External Traits†on page XX.
The newtype pattern is also useful for tasks beyond those we’ve discussed so
far, including statically enforcing that values are never confused and
indicating the units of a value. You saw an example of using newtypes to
indicate units in Listing 19-15: recall that the `Millimeters` and `Meters`
structs wrapped `u32` values in a newtype. If we wrote a function with a
-parameter of type `Millimeters`, we couldn’t compile a program that
+parameter of type `Millimeters`, we wouldn’t be able to compile a program that
accidentally tried to call that function with a value of type `Meters` or a
plain `u32`.
@@ -1233,8 +1230,8 @@ associated with their name. Code using `People` would only interact with the
public API we provide, such as a method to add a name string to the `People`
collection; that code wouldn’t need to know that we assign an `i32` ID to names
internally. The newtype pattern is a lightweight way to achieve encapsulation
-to hide implementation details, which we discussed in the “Encapsulation that
-Hides Implementation Details†section of Chapter 17.
+to hide implementation details, which we discussed in “Encapsulation That Hides
+Implementation Details†on page XX.
### Creating Type Synonyms with Type Aliases
@@ -1246,7 +1243,7 @@ the alias `Kilometers` to `i32` like so:
type Kilometers = i32;
```
-Now, the alias `Kilometers` is a *synonym* for `i32`; unlike the `Millimeters`
+Now the alias `Kilometers` is a *synonym* for `i32`; unlike the `Millimeters`
and `Meters` types we created in Listing 19-15, `Kilometers` is not a separate,
new type. Values that have the type `Kilometers` will be treated the same as
values of type `i32`:
@@ -1262,20 +1259,11 @@ println!("x + y = {}", x + y);
Because `Kilometers` and `i32` are the same type, we can add values of both
types and we can pass `Kilometers` values to functions that take `i32`
-parameters. However, using this method, we don’t get the type checking benefits
+parameters. However, using this method, we don’t get the type-checking benefits
that we get from the newtype pattern discussed earlier. In other words, if we
mix up `Kilometers` and `i32` values somewhere, the compiler will not give us
an error.
-<!-- Having a few battle wounds trying to debug using this pattern, it's
-definitely good to warn people that if they use type aliases to the same base
-type in their program (like multiple aliases to `usize`), they're asking for
-trouble as the typechecker will not help them if they mix up their types.
-/JT -->
-<!-- I'm not sure if JT was saying this paragraph was good or it could use more
-emphasis? I've added a sentence to the end of the paragraph above in case it
-was the latter /Carol -->
-
The main use case for type synonyms is to reduce repetition. For example, we
might have a lengthy type like this:
@@ -1288,14 +1276,16 @@ over the code can be tiresome and error prone. Imagine having a project full of
code like that in Listing 19-24.
```
-let f: Box<dyn Fn() + Send + 'static> = Box::new(|| println!("hi"));
+let f: Box<dyn Fn() + Send + 'static> = Box::new(|| {
+ println!("hi");
+});
fn takes_long_type(f: Box<dyn Fn() + Send + 'static>) {
- // --snip--
+ --snip--
}
fn returns_long_type() -> Box<dyn Fn() + Send + 'static> {
- // --snip--
+ --snip--
}
```
@@ -1311,11 +1301,11 @@ type Thunk = Box<dyn Fn() + Send + 'static>;
let f: Thunk = Box::new(|| println!("hi"));
fn takes_long_type(f: Thunk) {
- // --snip--
+ --snip--
}
fn returns_long_type() -> Thunk {
- // --snip--
+ --snip--
}
```
@@ -1343,7 +1333,10 @@ pub trait Write {
fn flush(&mut self) -> Result<(), Error>;
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>;
- fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<(), Error>;
+ fn write_fmt(
+ &mut self,
+ fmt: fmt::Arguments,
+ ) -> Result<(), Error>;
}
```
@@ -1374,7 +1367,7 @@ us a consistent interface across all of `std::io`. Because it’s an alias, itâ€
just another `Result<T, E>`, which means we can use any methods that work on
`Result<T, E>` with it, as well as special syntax like the `?` operator.
-### The Never Type that Never Returns
+### The Never Type That Never Returns
Rust has a special type named `!` that’s known in type theory lingo as the
*empty type* because it has no values. We prefer to call it the *never type*
@@ -1383,16 +1376,16 @@ return. Here is an example:
```
fn bar() -> ! {
- // --snip--
+ --snip--
}
```
This code is read as “the function `bar` returns never.†Functions that return
-never are called *diverging functions*. We can’t create values of the type `!`
+never are called *diverging functions*. We can’t create values of the type `!`,
so `bar` can never possibly return.
But what use is a type you can never create values for? Recall the code from
-Listing 2-5, part of the number guessing game; we’ve reproduced a bit of it
+Listing 2-5, part of the number-guessing game; we’ve reproduced a bit of it
here in Listing 19-26.
```
@@ -1404,9 +1397,9 @@ let guess: u32 = match guess.trim().parse() {
Listing 19-26: A `match` with an arm that ends in `continue`
-At the time, we skipped over some details in this code. In Chapter 6 in “The
-`match` Control Flow Operator†section, we discussed that `match` arms must all
-return the same type. So, for example, the following code doesn’t work:
+At the time, we skipped over some details in this code. In “The match Control
+Flow Construct†on page XX, we discussed that `match` arms must all return the
+same type. So, for example, the following code doesn’t work:
```
let guess = match guess.trim().parse() {
@@ -1440,7 +1433,9 @@ impl<T> Option<T> {
pub fn unwrap(self) -> T {
match self {
Some(val) => val,
- None => panic!("called `Option::unwrap()` on a `None` value"),
+ None => panic!(
+ "called `Option::unwrap()` on a `None` value"
+ ),
}
}
}
@@ -1466,7 +1461,7 @@ Here, the loop never ends, so `!` is the value of the expression. However, this
wouldn’t be true if we included a `break`, because the loop would terminate
when it got to the `break`.
-### Dynamically Sized Types and the `Sized` Trait
+### Dynamically Sized Types and the Sized Trait
Rust needs to know certain details about its types, such as how much space to
allocate for a value of a particular type. This leaves one corner of its type
@@ -1493,25 +1488,25 @@ storage and `s2` needs 15. This is why it’s not possible to create a variable
holding a dynamically sized type.
So what do we do? In this case, you already know the answer: we make the types
-of `s1` and `s2` a `&str` rather than a `str`. Recall from the “String Slicesâ€
-section of Chapter 4 that the slice data structure just stores the starting
-position and the length of the slice. So although a `&T` is a single value that
-stores the memory address of where the `T` is located, a `&str` is *two*
-values: the address of the `str` and its length. As such, we can know the size
-of a `&str` value at compile time: it’s twice the length of a `usize`. That is,
-we always know the size of a `&str`, no matter how long the string it refers to
-is. In general, this is the way in which dynamically sized types are used in
-Rust: they have an extra bit of metadata that stores the size of the dynamic
+of `s1` and `s2` a `&str` rather than a `str`. Recall from “String Slices†on
+page XX that the slice data structure just stores the starting position and the
+length of the slice. So, although a `&T` is a single value that stores the
+memory address of where the `T` is located, a `&str` is *two* values: the
+address of the `str` and its length. As such, we can know the size of a `&str`
+value at compile time: it’s twice the length of a `usize`. That is, we always
+know the size of a `&str`, no matter how long the string it refers to is. In
+general, this is the way in which dynamically sized types are used in Rust:
+they have an extra bit of metadata that stores the size of the dynamic
information. The golden rule of dynamically sized types is that we must always
put values of dynamically sized types behind a pointer of some kind.
We can combine `str` with all kinds of pointers: for example, `Box<str>` or
`Rc<str>`. In fact, you’ve seen this before but with a different dynamically
sized type: traits. Every trait is a dynamically sized type we can refer to by
-using the name of the trait. In Chapter 17 in the “Using Trait Objects That
-Allow for Values of Different Types†section, we mentioned that to use traits
-as trait objects, we must put them behind a pointer, such as `&dyn Trait` or
-`Box<dyn Trait>` (`Rc<dyn Trait>` would work too).
+using the name of the trait. In “Using Trait Objects That Allow for Values of
+Different Types†on page XX, we mentioned that to use traits as trait objects,
+we must put them behind a pointer, such as `&dyn Trait` or `Box<dyn Trait>`
+(`Rc<dyn Trait>` would work too).
To work with DSTs, Rust provides the `Sized` trait to determine whether or not
a type’s size is known at compile time. This trait is automatically implemented
@@ -1521,7 +1516,7 @@ generic function definition like this:
```
fn generic<T>(t: T) {
- // --snip--
+ --snip--
}
```
@@ -1529,7 +1524,7 @@ is actually treated as though we had written this:
```
fn generic<T: Sized>(t: T) {
- // --snip--
+ --snip--
}
```
@@ -1539,7 +1534,7 @@ restriction:
```
fn generic<T: ?Sized>(t: &T) {
- // --snip--
+ --snip--
}
```
@@ -1564,14 +1559,14 @@ including function pointers and returning closures.
We’ve talked about how to pass closures to functions; you can also pass regular
functions to functions! This technique is useful when you want to pass a
function you’ve already defined rather than defining a new closure. Functions
-coerce to the type `fn` (with a lowercase f), not to be confused with the `Fn`
-closure trait. The `fn` type is called a *function pointer*. Passing functions
-with function pointers will allow you to use functions as arguments to other
-functions.
+coerce to the type `fn` (with a lowercase *f*), not to be confused with the
+`Fn` closure trait. The `fn` type is called a *function pointer*. Passing
+functions with function pointers will allow you to use functions as arguments
+to other functions.
The syntax for specifying that a parameter is a function pointer is similar to
that of closures, as shown in Listing 19-27, where we’ve defined a function
-`add_one` that adds one to its parameter. The function `do_twice` takes two
+`add_one` that adds 1 to its parameter. The function `do_twice` takes two
parameters: a function pointer to any function that takes an `i32` parameter
and returns an `i32`, and one `i32 value`. The `do_twice` function calls the
function `f` twice, passing it the `arg` value, then adds the two function call
@@ -1592,7 +1587,7 @@ fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
fn main() {
let answer = do_twice(add_one, 5);
- println!("The answer is: {}", answer);
+ println!("The answer is: {answer}");
}
```
@@ -1619,13 +1614,15 @@ functions can accept functions as arguments, but C doesn’t have closures.
As an example of where you could use either a closure defined inline or a named
function, let’s look at a use of the `map` method provided by the `Iterator`
-trait in the standard library. To use the `map` function to turn a
-vector of numbers into a vector of strings, we could use a closure, like this:
+trait in the standard library. To use the `map` function to turn a vector of
+numbers into a vector of strings, we could use a closure, like this:
```
let list_of_numbers = vec![1, 2, 3];
-let list_of_strings: Vec<String> =
- list_of_numbers.iter().map(|i| i.to_string()).collect();
+let list_of_strings: Vec<String> = list_of_numbers
+ .iter()
+ .map(|i| i.to_string())
+ .collect();
```
Or we could name a function as the argument to `map` instead of the closure,
@@ -1633,23 +1630,25 @@ like this:
```
let list_of_numbers = vec![1, 2, 3];
-let list_of_strings: Vec<String> =
- list_of_numbers.iter().map(ToString::to_string).collect();
+let list_of_strings: Vec<String> = list_of_numbers
+ .iter()
+ .map(ToString::to_string)
+ .collect();
```
-Note that we must use the fully qualified syntax that we talked about earlier
-in the “Advanced Traits†section because there are multiple functions available
+Note that we must use the fully qualified syntax that we talked about in
+“Advanced Traits†on page XX because there are multiple functions available
named `to_string`.
-Here, we’re using the `to_string` function defined in the
-`ToString` trait, which the standard library has implemented for any type that
-implements `Display`.
+Here, we’re using the `to_string` function defined in the `ToString` trait,
+which the standard library has implemented for any type that implements
+`Display`.
-Recall from the “Enum values†section of Chapter 6 that the name of each enum
-variant that we define also becomes an initializer function. We can use these
-initializer functions as function pointers that implement the closure traits,
-which means we can specify the initializer functions as arguments for methods
-that take closures, like so:
+Recall from “Enum Values†on page XX that the name of each enum variant that we
+define also becomes an initializer function. We can use these initializer
+functions as function pointers that implement the closure traits, which means
+we can specify the initializer functions as arguments for methods that take
+closures, like so:
```
enum Status {
@@ -1657,12 +1656,14 @@ enum Status {
Stop,
}
-let list_of_statuses: Vec<Status> = (0u32..20).map(Status::Value).collect();
+let list_of_statuses: Vec<Status> = (0u32..20)
+ .map(Status::Value)
+ .collect();
```
-Here we create `Status::Value` instances using each `u32` value in the range
+Here, we create `Status::Value` instances using each `u32` value in the range
that `map` is called on by using the initializer function of `Status::Value`.
-Some people prefer this style, and some people prefer to use closures. They
+Some people prefer this style and some people prefer to use closures. They
compile to the same code, so use whichever style is clearer to you.
### Returning Closures
@@ -1689,10 +1690,14 @@ error[E0746]: return type cannot have an unboxed trait object
--> src/lib.rs:1:25
|
1 | fn returns_closure() -> dyn Fn(i32) -> i32 {
- | ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ | ^^^^^^^^^^^^^^^^^^ doesn't have a size known at
+compile-time
|
- = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
-help: use `impl Fn(i32) -> i32` as the return type, as all return paths are of type `[closure@src/lib.rs:2:5: 2:14]`, which implements `Fn(i32) -> i32`
+ = note: for information on `impl Trait`, see
+<https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-
+implement-traits>
+help: use `impl Fn(i32) -> i32` as the return type, as all return paths are of
+type `[closure@src/lib.rs:2:5: 2:14]`, which implements `Fn(i32) -> i32`
|
1 | fn returns_closure() -> impl Fn(i32) -> i32 {
| ~~~~~~~~~~~~~~~~~~~
@@ -1708,9 +1713,8 @@ fn returns_closure() -> Box<dyn Fn(i32) -> i32> {
}
```
-This code will compile just fine. For more about trait objects, refer to the
-section “Using Trait Objects That Allow for Values of Different Types†in
-Chapter 17.
+This code will compile just fine. For more about trait objects, refer to “Using
+Trait Objects That Allow for Values of Different Types†on page XX.
Next, let’s look at macros!
@@ -1722,10 +1726,10 @@ of features in Rust: *declarative* macros with `macro_rules!` and three kinds
of *procedural* macros:
* Custom `#[derive]` macros that specify code added with the `derive` attribute
- used on structs and enums
+used on structs and enums
* Attribute-like macros that define custom attributes usable on any item
* Function-like macros that look like function calls but operate on the tokens
- specified as their argument
+specified as their argument
We’ll talk about each of these in turn, but first, let’s look at why we even
need macros when we already have functions.
@@ -1740,7 +1744,7 @@ macros *expand* to produce more code than the code you’ve written manually.
Metaprogramming is useful for reducing the amount of code you have to write and
maintain, which is also one of the roles of functions. However, macros have
-some additional powers that functions don’t.
+some additional powers that functions don’t have.
A function signature must declare the number and type of parameters the
function has. Macros, on the other hand, can take a variable number of
@@ -1760,14 +1764,14 @@ Another important difference between macros and functions is that you must
define macros or bring them into scope *before* you call them in a file, as
opposed to functions you can define anywhere and call anywhere.
-### Declarative Macros with `macro_rules!` for General Metaprogramming
+### Declarative Macros with macro_rules! for General Metaprogramming
The most widely used form of macros in Rust is the *declarative macro*. These
are also sometimes referred to as “macros by example,†“`macro_rules!` macros,â€
or just plain “macros.†At their core, declarative macros allow you to write
something similar to a Rust `match` expression. As discussed in Chapter 6,
`match` expressions are control structures that take an expression, compare the
-resulting value of the expression to patterns, and then run the code associated
+resultant value of the expression to patterns, and then run the code associated
with the matching pattern. Macros also compare a value to patterns that are
associated with particular code: in this situation, the value is the literal
Rust source code passed to the macro; the patterns are compared with the
@@ -1794,15 +1798,15 @@ Listing 19-28 shows a slightly simplified definition of the `vec!` macro.
Filename: src/lib.rs
```
-[1] #[macro_export]
-[2] macro_rules! vec {
- [3] ( $( $x:expr ),* ) => {
+1 #[macro_export]
+2 macro_rules! vec {
+ 3 ( $( $x:expr ),* ) => {
{
let mut temp_vec = Vec::new();
- [4] $(
- [5] temp_vec.push($x [6]);
+ 4 $(
+ 5 temp_vec.push(6 $x);
)*
- [7] temp_vec
+ 7 temp_vec
}
};
}
@@ -1811,8 +1815,8 @@ Filename: src/lib.rs
Listing 19-28: A simplified version of the `vec!` macro definition
> Note: The actual definition of the `vec!` macro in the standard library
-> includes code to preallocate the correct amount of memory up front. That code
-> is an optimization that we don’t include here to make the example simpler.
+includes code to pre-allocate the correct amount of memory up front. That code
+is an optimization that we don’t include here, to make the example simpler.
The `#[macro_export]` annotation [1] indicates that this macro should be made
available whenever the crate in which the macro is defined is brought into
@@ -1830,20 +1834,19 @@ is the only pattern in this macro, there is only one valid way to match; any
other pattern will result in an error. More complex macros will have more than
one arm.
-Valid pattern syntax in macro definitions is different than the pattern syntax
+Valid pattern syntax in macro definitions is different from the pattern syntax
covered in Chapter 18 because macro patterns are matched against Rust code
structure rather than values. Let’s walk through what the pattern pieces in
Listing 19-28 mean; for the full macro pattern syntax, see the Rust Reference
at *https://doc.rust-lang.org/reference/macros-by-example.html*.
-First, we use a set of parentheses to encompass the whole pattern. We use a
+First we use a set of parentheses to encompass the whole pattern. We use a
dollar sign (`$`) to declare a variable in the macro system that will contain
the Rust code matching the pattern. The dollar sign makes it clear this is a
-macro variable as opposed to a regular Rust variable.
-Next comes a set of parentheses that captures values that match the
-pattern within the parentheses for use in the replacement code. Within `$()` is
-`$x:expr`, which matches any Rust expression and gives the expression the name
-`$x`.
+macro variable as opposed to a regular Rust variable. Next comes a set of
+parentheses that captures values that match the pattern within the parentheses
+for use in the replacement code. Within `$()` is `$x:expr`, which matches any
+Rust expression and gives the expression the name `$x`.
The comma following `$()` indicates that a literal comma separator character
could optionally appear after the code that matches the code in `$()`. The `*`
@@ -1853,11 +1856,11 @@ When we call this macro with `vec![1, 2, 3];`, the `$x` pattern matches three
times with the three expressions `1`, `2`, and `3`.
Now let’s look at the pattern in the body of the code associated with this arm:
-`temp_vec.push()` [5] within `$()*` [4][7] is generated for each part that
-matches `$()` in the pattern zero or more times depending on how many times the
-pattern matches. The `$x` [6] is replaced with each expression matched. When we
-call this macro with `vec![1, 2, 3];`, the code generated that replaces this
-macro call will be the following:
+`temp_vec.push()` [5] within `$()* at [4] and [7] is generated for each part
+that matches `$()` in the pattern zero or more times depending on how many
+times the pattern matches. The `$x` [6] is replaced with each expression
+matched. When we call this macro with `vec![1, 2, 3];`, the code generated that
+replaces this macro call will be the following:
```
{
@@ -1874,24 +1877,16 @@ generate code to create a vector containing the specified elements.
To learn more about how to write macros, consult the online documentation or
other resources, such as “The Little Book of Rust Macros†at
-*https://veykril.github.io/tlborm/* started by Daniel Keep and continued by
+*https://veykril.github.io/tlborm* started by Daniel Keep and continued by
Lukas Wirth.
-<!-- Not sure what "In the future, Rust will have a second kind of declarative
-macro" means here. I suspect we're "stuck" with the two kinds of macros we
-already have today, at least I don't see much energy in pushing to add a third
-just yet.
-/JT -->
-<!-- Yeah, great catch, I think that part was back when we had more dreams that
-have now been postponed/abandoned. I've removed. /Carol -->
-
### Procedural Macros for Generating Code from Attributes
-The second form of macros is the *procedural macro*, which acts more like a
-function (and is a type of procedure). Procedural macros accept some code as an
-input, operate on that code, and produce some code as an output rather than
+The second form of macros is the procedural macro, which acts more like a
+function (and is a type of procedure). *Procedural macros* accept some code as
+an input, operate on that code, and produce some code as an output rather than
matching against patterns and replacing the code with other code as declarative
-macros do. The three kinds of procedural macros are custom derive,
+macros do. The three kinds of procedural macros are custom `derive`,
attribute-like, and function-like, and all work in a similar fashion.
When creating procedural macros, the definitions must reside in their own crate
@@ -1903,7 +1898,7 @@ macro variety.
Filename: src/lib.rs
```
-use proc_macro;
+use proc_macro::TokenStream;
#[some_attribute]
pub fn some_name(input: TokenStream) -> TokenStream {
@@ -1922,20 +1917,20 @@ that specifies which kind of procedural macro we’re creating. We can have
multiple kinds of procedural macros in the same crate.
Let’s look at the different kinds of procedural macros. We’ll start with a
-custom derive macro and then explain the small dissimilarities that make the
+custom `derive` macro and then explain the small dissimilarities that make the
other forms different.
-### How to Write a Custom `derive` Macro
+### How to Write a Custom derive Macro
Let’s create a crate named `hello_macro` that defines a trait named
`HelloMacro` with one associated function named `hello_macro`. Rather than
making our users implement the `HelloMacro` trait for each of their types,
we’ll provide a procedural macro so users can annotate their type with
`#[derive(HelloMacro)]` to get a default implementation of the `hello_macro`
-function. The default implementation will print `Hello, Macro! My name is
-TypeName!` where `TypeName` is the name of the type on which this trait has
-been defined. In other words, we’ll write a crate that enables another
-programmer to write code like Listing 19-30 using our crate.
+function. The default implementation will print `Hello, Macro! My name is`
+TypeName`!` where TypeName is the name of the type on which this trait has been
+defined. In other words, we’ll write a crate that enables another programmer to
+write code like Listing 19-30 using our crate.
Filename: src/main.rs
@@ -2002,8 +1997,8 @@ name at runtime. We need a macro to generate code at compile time.
The next step is to define the procedural macro. At the time of this writing,
procedural macros need to be in their own crate. Eventually, this restriction
might be lifted. The convention for structuring crates and macro crates is as
-follows: for a crate named `foo`, a custom derive procedural macro crate is
-called `foo_derive`. Let’s start a new crate called `hello_macro_derive` inside
+follows: for a crate named foo, a custom `derive` procedural macro crate is
+called foo`_derive`. Let’s start a new crate called `hello_macro_derive` inside
our `hello_macro` project:
```
@@ -2095,11 +2090,11 @@ The `hello_macro_derive` function first converts the `input` from a
operations on. This is where `syn` comes into play. The `parse` function in
`syn` takes a `TokenStream` and returns a `DeriveInput` struct representing the
parsed Rust code. Listing 19-32 shows the relevant parts of the `DeriveInput`
-struct we get from parsing the `struct Pancakes;` string:
+struct we get from parsing the `struct Pancakes;` string.
```
DeriveInput {
- // --snip--
+ --snip--
ident: Ident {
ident: "Pancakes",
@@ -2121,14 +2116,14 @@ Listing 19-32: The `DeriveInput` instance we get when parsing the code that has
the macro’s attribute in Listing 19-30
The fields of this struct show that the Rust code we’ve parsed is a unit struct
-with the `ident` (identifier, meaning the name) of `Pancakes`. There are more
+with the `ident` (*identifier*, meaning the name) of `Pancakes`. There are more
fields on this struct for describing all sorts of Rust code; check the `syn`
documentation for `DeriveInput` at
*https://docs.rs/syn/1.0/syn/struct.DeriveInput.html* for more information.
Soon we’ll define the `impl_hello_macro` function, which is where we’ll build
the new Rust code we want to include. But before we do, note that the output
-for our derive macro is also a `TokenStream`. The returned `TokenStream` is
+for our `derive` macro is also a `TokenStream`. The returned `TokenStream` is
added to the code that our crate users write, so when they compile their crate,
they’ll get the extra functionality that we provide in the modified
`TokenStream`.
@@ -2153,7 +2148,10 @@ fn impl_hello_macro(ast: &syn::DeriveInput) -> TokenStream {
let gen = quote! {
impl HelloMacro for #name {
fn hello_macro() {
- println!("Hello, Macro! My name is {}!", stringify!(#name));
+ println!(
+ "Hello, Macro! My name is {}!",
+ stringify!(#name)
+ );
}
}
};
@@ -2166,7 +2164,7 @@ Listing 19-33: Implementing the `HelloMacro` trait using the parsed Rust code
We get an `Ident` struct instance containing the name (identifier) of the
annotated type using `ast.ident`. The struct in Listing 19-32 shows that when
we run the `impl_hello_macro` function on the code in Listing 19-30, the
-`ident` we get will have the `ident` field with a value of `"Pancakes"`. Thus,
+`ident` we get will have the `ident` field with a value of `"Pancakes"`. Thus
the `name` variable in Listing 19-33 will contain an `Ident` struct instance
that, when printed, will be the string `"Pancakes"`, the name of the struct in
Listing 19-30.
@@ -2185,13 +2183,13 @@ introduction.
We want our procedural macro to generate an implementation of our `HelloMacro`
trait for the type the user annotated, which we can get by using `#name`. The
-trait implementation has the one function `hello_macro`, whose body contains the
-functionality we want to provide: printing `Hello, Macro! My name is` and then
-the name of the annotated type.
+trait implementation has the one function `hello_macro`, whose body contains
+the functionality we want to provide: printing `Hello, Macro! My name is` and
+then the name of the annotated type.
The `stringify!` macro used here is built into Rust. It takes a Rust
expression, such as `1 + 2`, and at compile time turns the expression into a
-string literal, such as `"1 + 2"`. This is different than `format!` or
+string literal, such as `"1 + 2"`. This is different from `format!` or
`println!`, macros which evaluate the expression and then turn the result into
a `String`. There is a possibility that the `#name` input might be an
expression to print literally, so we use `stringify!`. Using `stringify!` also
@@ -2203,7 +2201,7 @@ and `hello_macro_derive`. Let’s hook up these crates to the code in Listing
your *projects* directory using `cargo new pancakes`. We need to add
`hello_macro` and `hello_macro_derive` as dependencies in the `pancakes`
crate’s *Cargo.toml*. If you’re publishing your versions of `hello_macro` and
-`hello_macro_derive` to *https://crates.io/*, they would be regular
+`hello_macro_derive` to *https://crates.io*, they would be regular
dependencies; if not, you can specify them as `path` dependencies as follows:
```
@@ -2219,15 +2217,15 @@ should print `Hello, Macro! My name is Pancakes!` The implementation of the
trait implementation.
Next, let’s explore how the other kinds of procedural macros differ from custom
-derive macros.
+`derive` macros.
-### Attribute-like macros
+### Attribute-like Macros
-Attribute-like macros are similar to custom derive macros, but instead of
+Attribute-like macros are similar to custom `derive` macros, but instead of
generating code for the `derive` attribute, they allow you to create new
attributes. They’re also more flexible: `derive` only works for structs and
enums; attributes can be applied to other items as well, such as functions.
-Here’s an example of using an attribute-like macro: say you have an attribute
+Here’s an example of using an attribute-like macro. Say you have an attribute
named `route` that annotates functions when using a web application framework:
```
@@ -2240,7 +2238,10 @@ macro. The signature of the macro definition function would look like this:
```
#[proc_macro_attribute]
-pub fn route(attr: TokenStream, item: TokenStream) -> TokenStream {
+pub fn route(
+ attr: TokenStream,
+ item: TokenStream
+) -> TokenStream {
```
Here, we have two parameters of type `TokenStream`. The first is for the
@@ -2248,21 +2249,21 @@ contents of the attribute: the `GET, "/"` part. The second is the body of the
item the attribute is attached to: in this case, `fn index() {}` and the rest
of the function’s body.
-Other than that, attribute-like macros work the same way as custom derive
+Other than that, attribute-like macros work the same way as custom `derive`
macros: you create a crate with the `proc-macro` crate type and implement a
function that generates the code you want!
-### Function-like macros
+### Function-like Macros
Function-like macros define macros that look like function calls. Similarly to
`macro_rules!` macros, they’re more flexible than functions; for example, they
-can take an unknown number of arguments. However, `macro_rules!` macros can be
-defined only using the match-like syntax we discussed in the section
-“Declarative Macros with `macro_rules!` for General Metaprogramming†earlier.
-Function-like macros take a `TokenStream` parameter and their definition
-manipulates that `TokenStream` using Rust code as the other two types of
-procedural macros do. An example of a function-like macro is an `sql!` macro
-that might be called like so:
+can take an unknown number of arguments. However, `macro_rules!` macros can
+only be defined using the match-like syntax we discussed in “Declarative Macros
+with macro_rules! for General Metaprogramming†on page XX. Function-like macros
+take a `TokenStream` parameter, and their definition manipulates that
+`TokenStream` using Rust code as the other two types of procedural macros do.
+An example of a function-like macro is an `sql!` macro that might be called
+like so:
```
let sql = sql!(SELECT * FROM posts WHERE id=1);
@@ -2277,32 +2278,19 @@ syntactically correct, which is much more complex processing than a
pub fn sql(input: TokenStream) -> TokenStream {
```
-This definition is similar to the custom derive macro’s signature: we receive
+This definition is similar to the custom `derive` macro’s signature: we receive
the tokens that are inside the parentheses and return the code we wanted to
generate.
-<!-- I may get a few looks for this, but I wonder if we should trim the
-procedural macros section above a bit. There's a lot of information in there,
-but it feels like something we could intro and then point people off to other
-materials for. Reason being (and I know I may be in the minority here),
-procedural macros are something we should use only rarely in our Rust projects.
-They are a burden on the compiler, have the potential to hurt readability and
-maintainability, and... you know the saying with great power comes great
-responsibilty and all that. /JT -->
-<!-- I think we felt obligated to have this section when procedural macros were
-introduced because there wasn't any documentation for them. I feel like the
-custom derive is the most common kind people want to make... While I'd love to
-not have to maintain this section, I asked around and people seemed generally
-in favor of keeping it, so I think I will, for now. /Carol -->
-
## Summary
Whew! Now you have some Rust features in your toolbox that you likely won’t use
often, but you’ll know they’re available in very particular circumstances.
We’ve introduced several complex topics so that when you encounter them in
-error message suggestions or in other peoples’ code, you’ll be able to
+error message suggestions or in other people’s code, you’ll be able to
recognize these concepts and syntax. Use this chapter as a reference to guide
you to solutions.
Next, we’ll put everything we’ve discussed throughout the book into practice
and do one more project!
+
diff --git a/src/doc/book/nostarch/chapter20.md b/src/doc/book/nostarch/chapter20.md
index e692e2f1d..9d4e22cd7 100644
--- a/src/doc/book/nostarch/chapter20.md
+++ b/src/doc/book/nostarch/chapter20.md
@@ -16,21 +16,19 @@ lessons.
For our final project, we’ll make a web server that says “hello†and looks like
Figure 20-1 in a web browser.
-!hello from rust at *img/trpl20-01.png*
-
Figure 20-1: Our final shared project
Here is our plan for building the web server:
1. Learn a bit about TCP and HTTP.
-2. Listen for TCP connections on a socket.
-3. Parse a small number of HTTP requests.
-4. Create a proper HTTP response.
-5. Improve the throughput of our server with a thread pool.
+1. Listen for TCP connections on a socket.
+1. Parse a small number of HTTP requests.
+1. Create a proper HTTP response.
+1. Improve the throughput of our server with a thread pool.
Before we get started, we should mention one detail: the method we’ll use won’t
be the best way to build a web server with Rust. Community members have
-published a number of production-ready crates available at *https://crates.io/*
+published a number of production-ready crates available at *https://crates.io*
that provide more complete web server and thread pool implementations than
we’ll build. However, our intention in this chapter is to help you learn, not
to take the easy route. Because Rust is a systems programming language, we can
@@ -81,12 +79,12 @@ Filename: src/main.rs
use std::net::TcpListener;
fn main() {
- [1] let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
+ 1 let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
- [2] for stream in listener.incoming() {
- [3] let stream = stream.unwrap();
+ 2 for stream in listener.incoming() {
+ 3 let stream = stream.unwrap();
- [4] println!("Connection established!");
+ 4 println!("Connection established!");
}
}
```
@@ -99,7 +97,7 @@ Using `TcpListener`, we can listen for TCP connections at the address
address representing your computer (this is the same on every computer and
doesn’t represent the authors’ computer specifically), and `7878` is the port.
We’ve chosen this port for two reasons: HTTP isn’t normally accepted on this
-port so our server is unlikely to conflict with any other web server you might
+port, so our server is unlikely to conflict with any other web server you might
have running on your machine, and 7878 is *rust* typed on a telephone.
The `bind` function in this scenario works like the `new` function in that it
@@ -109,7 +107,7 @@ to a port.â€
The `bind` function returns a `Result<T, E>`, which indicates that it’s
possible for binding to fail. For example, connecting to port 80 requires
-administrator privileges (nonadministrators can listen only on ports higher
+administrator privileges (non-administrators can listen only on ports higher
than 1023), so if we tried to connect to port 80 without being an
administrator, binding wouldn’t work. Binding also wouldn’t work, for example,
if we ran two instances of our program and so had two programs listening to the
@@ -141,7 +139,7 @@ open connections are closed.
Let’s try running this code! Invoke `cargo run` in the terminal and then load
*127.0.0.1:7878* in a web browser. The browser should show an error message
-like “Connection reset,†because the server isn’t currently sending back any
+like “Connection reset†because the server isn’t currently sending back any
data. But when you look at your terminal, you should see several messages that
were printed when the browser connected to the server!
@@ -152,7 +150,7 @@ Connection established!
Connection established!
```
-Sometimes, you’ll see multiple messages printed for one browser request; the
+Sometimes you’ll see multiple messages printed for one browser request; the
reason might be that the browser is making a request for the page as well as a
request for other resources, like the *favicon.ico* icon that appears in the
browser tab.
@@ -164,10 +162,10 @@ part of the `drop` implementation. Browsers sometimes deal with closed
connections by retrying, because the problem might be temporary. The important
factor is that we’ve successfully gotten a handle to a TCP connection!
-Remember to stop the program by pressing <span class="keystroke">ctrl-c
-when you’re done running a particular version of the code. Then restart the
-program by invoking the `cargo run` command after you’ve made each set of code
-changes to make sure you’re running the newest code.
+Remember to stop the program by pressing ctrl-C when you’re done running a
+particular version of the code. Then restart the program by invoking the `cargo
+run` command after you’ve made each set of code changes to make sure you’re
+running the newest code.
### Reading the Request
@@ -181,7 +179,7 @@ look like Listing 20-2.
Filename: src/main.rs
```
-[1] use std::{
+1 use std::{
io::{prelude::*, BufReader},
net::{TcpListener, TcpStream},
};
@@ -192,19 +190,19 @@ fn main() {
for stream in listener.incoming() {
let stream = stream.unwrap();
- [2] handle_connection(stream);
+ 2 handle_connection(stream);
}
}
fn handle_connection(mut stream: TcpStream) {
- [3] let buf_reader = BufReader::new(&mut stream);
- [4] let http_request: Vec<_> = buf_reader
- [5] .lines()
- [6] .map(|result| result.unwrap())
- [7] .take_while(|line| !line.is_empty())
+ 3 let buf_reader = BufReader::new(&mut stream);
+ 4 let http_request: Vec<_> = buf_reader
+ 5 .lines()
+ 6 .map(|result| result.unwrap())
+ 7 .take_while(|line| !line.is_empty())
.collect();
- [8] println!("Request: {:#?}", http_request);
+ 8 println!("Request: {:#?}", http_request);
}
```
@@ -251,8 +249,11 @@ $ cargo run
Request: [
"GET / HTTP/1.1",
"Host: 127.0.0.1:7878",
- "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:99.0) Gecko/20100101 Firefox/99.0",
- "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
+ "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:99.0)
+Gecko/20100101 Firefox/99.0",
+ "Accept:
+text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*
+;q=0.8",
"Accept-Language: en-US,en;q=0.5",
"Accept-Encoding: gzip, deflate, br",
"DNT: 1",
@@ -292,17 +293,17 @@ being used, such as `GET` or `POST`, which describes how the client is making
this request. Our client used a `GET` request, which means it is asking for
information.
-The next part of the request line is */*, which indicates the *Uniform Resource
-Identifier* *(URI)* the client is requesting: a URI is almost, but not quite,
-the same as a *Uniform Resource Locator* *(URL)*. The difference between URIs
+The next part of the request line is */*, which indicates the *uniform resource
+identifier* *(URI)* the client is requesting: a URI is almost, but not quite,
+the same as a *uniform resource locator* *(URL)*. The difference between URIs
and URLs isn’t important for our purposes in this chapter, but the HTTP spec
-uses the term URI, so we can just mentally substitute URL for URI here.
+uses the term *URI*, so we can just mentally substitute *URL* for *URI* here.
The last part is the HTTP version the client uses, and then the request line
-ends in a *CRLF sequence*. (CRLF stands for *carriage return* and *line feed*,
+ends in a CRLF sequence. (CRLF stands for *carriage return* and *line feed*,
which are terms from the typewriter days!) The CRLF sequence can also be
written as `\r\n`, where `\r` is a carriage return and `\n` is a line feed. The
-CRLF sequence separates the request line from the rest of the request data.
+*CRLF sequence* separates the request line from the rest of the request data.
Note that when the CRLF is printed, we see a new line start rather than `\r\n`.
Looking at the request line data we received from running our program so far,
@@ -334,8 +335,8 @@ a reason phrase that provides a text description of the status code. After the
CRLF sequence are any headers, another CRLF sequence, and the body of the
response.
-Here is an example response that uses HTTP version 1.1, has a status code of
-200, an OK reason phrase, no headers, and no body:
+Here is an example response that uses HTTP version 1.1, and has a status code
+of 200, an OK reason phrase, no headers, and no body:
```
HTTP/1.1 200 OK\r\n\r\n
@@ -358,9 +359,9 @@ fn handle_connection(mut stream: TcpStream) {
.take_while(|line| !line.is_empty())
.collect();
- [1] let response = "HTTP/1.1 200 OK\r\n\r\n";
+ 1 let response = "HTTP/1.1 200 OK\r\n\r\n";
- [2] stream.write_all(response.as_bytes()[3]).unwrap();
+ 2 stream.write_all(response.3 as_bytes()).unwrap();
}
```
@@ -376,7 +377,7 @@ a real application you would add error handling here.
With these changes, let’s run our code and make a request. We’re no longer
printing any data to the terminal, so we won’t see any output other than the
output from Cargo. When you load *127.0.0.1:7878* in a web browser, you should
-get a blank page instead of an error. You’ve just hand-coded receiving an HTTP
+get a blank page instead of an error. You’ve just handcoded receiving an HTTP
request and sending a response!
### Returning Real HTML
@@ -413,11 +414,11 @@ Filename: src/main.rs
```
use std::{
- [1] fs,
+ 1 fs,
io::{prelude::*, BufReader},
net::{TcpListener, TcpStream},
};
-// --snip--
+--snip--
fn handle_connection(mut stream: TcpStream) {
let buf_reader = BufReader::new(&mut stream);
@@ -431,8 +432,11 @@ fn handle_connection(mut stream: TcpStream) {
let contents = fs::read_to_string("hello.html").unwrap();
let length = contents.len();
- [2] let response =
- format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}");
+ 2 let response = format!(
+ "{status_line}\r\n\
+ Content-Length: {length}\r\n\r\n\
+ {contents}"
+ );
stream.write_all(response.as_bytes()).unwrap();
}
@@ -442,8 +446,8 @@ Listing 20-5: Sending the contents of *hello.html* as the body of the response
We’ve added `fs` to the `use` statement to bring the standard library’s
filesystem module into scope [1]. The code for reading the contents of a file
-to a string should look familiar; we used it in Chapter 12 when we read the
-contents of a file for our I/O project in Listing 12-4.
+to a string should look familiar; we used it when we read the contents of a
+file for our I/O project in Listing 12-4.
Next, we use `format!` to add the file’s contents as the body of the success
response [2]. To ensure a valid HTTP response, we add the `Content-Length`
@@ -465,7 +469,7 @@ request to */*.
Right now, our web server will return the HTML in the file no matter what the
client requested. Let’s add functionality to check that the browser is
-requesting */* before returning the HTML file and return an error if the
+requesting */* before returning the HTML file, and return an error if the
browser requests anything else. For this we need to modify `handle_connection`,
as shown in Listing 20-6. This new code checks the content of the request
received against what we know a request for */* looks like and adds `if` and
@@ -474,23 +478,29 @@ received against what we know a request for */* looks like and adds `if` and
Filename: src/main.rs
```
-// --snip--
+--snip--
fn handle_connection(mut stream: TcpStream) {
let buf_reader = BufReader::new(&mut stream);
- [1] let request_line = buf_reader.lines().next().unwrap().unwrap();
+ 1 let request_line = buf_reader
+ .lines()
+ .next()
+ .unwrap()
+ .unwrap();
- [2] if request_line == "GET / HTTP/1.1" {
+ 2 if request_line == "GET / HTTP/1.1" {
let status_line = "HTTP/1.1 200 OK";
let contents = fs::read_to_string("hello.html").unwrap();
let length = contents.len();
let response = format!(
- "{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}"
+ "{status_line}\r\n\
+ Content-Length: {length}\r\n\r\n\
+ {contents}"
);
stream.write_all(response.as_bytes()).unwrap();
- [3] } else {
+ 3 } else {
// some other request
}
}
@@ -526,18 +536,20 @@ indicating the response to the end user.
Filename: src/main.rs
```
- // --snip--
- } else {
- [1] let status_line = "HTTP/1.1 404 NOT FOUND";
- [2] let contents = fs::read_to_string("404.html").unwrap();
- let length = contents.len();
+--snip--
+} else {
+ 1 let status_line = "HTTP/1.1 404 NOT FOUND";
+ 2 let contents = fs::read_to_string("404.html").unwrap();
+ let length = contents.len();
- let response = format!(
- "{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}"
- );
+ let response = format!(
+ "{status_line}\r\n\
+ Content-Length: {length}\r\n\r\n
+ {contents}"
+ );
- stream.write_all(response.as_bytes()).unwrap();
- }
+ stream.write_all(response.as_bytes()).unwrap();
+}
```
Listing 20-7: Responding with status code 404 and an error page if anything
@@ -546,8 +558,8 @@ other than */* was requested
Here, our response has a status line with status code 404 and the reason phrase
`NOT FOUND` [1]. The body of the response will be the HTML in the file
*404.html* [1]. You’ll need to create a *404.html* file next to *hello.html*
-for the error page; again feel free to use any HTML you want or use the example
-HTML in Listing 20-8.
+for the error page; again feel free to use any HTML you want, or use the
+example HTML in Listing 20-8.
Filename: 404.html
@@ -573,34 +585,38 @@ return the contents of *hello.html*, and any other request, like
### A Touch of Refactoring
-At the moment the `if` and `else` blocks have a lot of repetition: they’re both
-reading files and writing the contents of the files to the stream. The only
-differences are the status line and the filename. Let’s make the code more
+At the moment, the `if` and `else` blocks have a lot of repetition: they’re
+both reading files and writing the contents of the files to the stream. The
+only differences are the status line and the filename. Let’s make the code more
concise by pulling out those differences into separate `if` and `else` lines
that will assign the values of the status line and the filename to variables;
we can then use those variables unconditionally in the code to read the file
-and write the response. Listing 20-9 shows the resulting code after replacing
+and write the response. Listing 20-9 shows the resultant code after replacing
the large `if` and `else` blocks.
Filename: src/main.rs
```
-// --snip--
+--snip--
fn handle_connection(mut stream: TcpStream) {
- // --snip--
+ --snip--
- let (status_line, filename) = if request_line == "GET / HTTP/1.1" {
- ("HTTP/1.1 200 OK", "hello.html")
- } else {
- ("HTTP/1.1 404 NOT FOUND", "404.html")
- };
+ let (status_line, filename) =
+ if request_line == "GET / HTTP/1.1" {
+ ("HTTP/1.1 200 OK", "hello.html")
+ } else {
+ ("HTTP/1.1 404 NOT FOUND", "404.html")
+ };
let contents = fs::read_to_string(filename).unwrap();
let length = contents.len();
- let response =
- format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}");
+ let response = format!(
+ "{status_line}\r\n\
+ Content-Length: {length}\r\n\r\n\
+ {contents}"
+ );
stream.write_all(response.as_bytes()).unwrap();
}
@@ -638,14 +654,14 @@ server received more and more requests, this serial execution would be less and
less optimal. If the server receives a request that takes a long time to
process, subsequent requests will have to wait until the long request is
finished, even if the new requests can be processed quickly. We’ll need to fix
-this, but first, we’ll look at the problem in action.
+this, but first we’ll look at the problem in action.
-### Simulating a Slow Request in the Current Server Implementation
+### Simulating a Slow Request
We’ll look at how a slow-processing request can affect other requests made to
our current server implementation. Listing 20-10 implements handling a request
to */sleep* with a simulated slow response that will cause the server to sleep
-for 5 seconds before responding.
+for five seconds before responding.
Filename: src/main.rs
@@ -657,44 +673,44 @@ use std::{
thread,
time::Duration,
};
-// --snip--
+--snip--
fn handle_connection(mut stream: TcpStream) {
- // --snip--
+ --snip--
- let (status_line, filename) = [1] match &request_line[..] {
- [2] "GET / HTTP/1.1" => ("HTTP/1.1 200 OK", "hello.html"),
- [3] "GET /sleep HTTP/1.1" => {
+ let (status_line, filename) = 1 match &request_line[..] {
+ 2 "GET / HTTP/1.1" => ("HTTP/1.1 200 OK", "hello.html"),
+ 3 "GET /sleep HTTP/1.1" => {
thread::sleep(Duration::from_secs(5));
("HTTP/1.1 200 OK", "hello.html")
}
- [4] _ => ("HTTP/1.1 404 NOT FOUND", "404.html"),
+ 4 _ => ("HTTP/1.1 404 NOT FOUND", "404.html"),
};
- // --snip--
+ --snip--
}
```
-Listing 20-10: Simulating a slow request by sleeping for 5 seconds
+Listing 20-10: Simulating a slow request by sleeping for five seconds
We switched from `if` to `match` now that we have three cases [1]. We need to
-explicitly match on a slice of `request_line` to pattern match against the
+explicitly match on a slice of `request_line` to pattern-match against the
string literal values; `match` doesn’t do automatic referencing and
-dereferencing like the equality method does.
+dereferencing, like the equality method does.
The first arm [2] is the same as the `if` block from Listing 20-9. The second
arm [3] matches a request to */sleep*. When that request is received, the
-server will sleep for 5 seconds before rendering the successful HTML page. The
-third arm [4] is the same as the `else` block from Listing 20-9.
+server will sleep for five seconds before rendering the successful HTML page.
+The third arm [4] is the same as the `else` block from Listing 20-9.
You can see how primitive our server is: real libraries would handle the
recognition of multiple requests in a much less verbose way!
Start the server using `cargo run`. Then open two browser windows: one for
-*http://127.0.0.1:7878/* and the other for *http://127.0.0.1:7878/sleep*. If
-you enter the */* URI a few times, as before, you’ll see it respond quickly.
-But if you enter */sleep* and then load */*, you’ll see that */* waits until
-`sleep` has slept for its full 5 seconds before loading.
+*http://127.0.0.1:7878* and the other for *http://127.0.0.1:7878/sleep*. If you
+enter the */* URI a few times, as before, you’ll see it respond quickly. But if
+you enter */sleep* and then load */*, you’ll see that */* waits until `sleep`
+has slept for its full five seconds before loading.
There are multiple techniques we could use to avoid requests backing up behind
a slow request; the one we’ll implement is a thread pool.
@@ -711,33 +727,28 @@ a new task. A thread pool allows you to process connections concurrently,
increasing the throughput of your server.
We’ll limit the number of threads in the pool to a small number to protect us
-from Denial of Service (DoS) attacks; if we had our program create a new thread
-for each request as it came in, someone making 10 million requests to our
-server could create havoc by using up all our server’s resources and grinding
-the processing of requests to a halt.
+from DoS attacks; if we had our program create a new thread for each request as
+it came in, someone making 10 million requests to our server could create havoc
+by using up all our server’s resources and grinding the processing of requests
+to a halt.
Rather than spawning unlimited threads, then, we’ll have a fixed number of
threads waiting in the pool. Requests that come in are sent to the pool for
processing. The pool will maintain a queue of incoming requests. Each of the
threads in the pool will pop off a request from this queue, handle the request,
and then ask the queue for another request. With this design, we can process up
-to `N` requests concurrently, where `N` is the number of threads. If each
-thread is responding to a long-running request, subsequent requests can still
-back up in the queue, but we’ve increased the number of long-running requests
-we can handle before reaching that point.
+to N requests concurrently, where N is the number of threads. If each thread is
+responding to a long-running request, subsequent requests can still back up in
+the queue, but we’ve increased the number of long-running requests we can
+handle before reaching that point.
This technique is just one of many ways to improve the throughput of a web
-server. Other options you might explore are the *fork/join model*, the
-*single-threaded async I/O model*, or the *multi-threaded async I/O model*. If
+server. Other options you might explore are the fork/join model, the
+single-threaded async I/O model, and the multithreaded async I/O model. If
you’re interested in this topic, you can read more about other solutions and
try to implement them; with a low-level language like Rust, all of these
options are possible.
-<!-- A more modern approach would probably use tokio, which could be a
-multi-threaded async I/O model. /JT -->
-<!-- I've added "multi-theraded async I/O model", I don't want to get into
-particular async crates though /Carol -->
-
Before we begin implementing a thread pool, let’s talk about what using the
pool should look like. When you’re trying to design code, writing the client
interface first can help guide your design. Write the API of the code so it’s
@@ -757,8 +768,7 @@ First, let’s explore how our code might look if it did create a new thread for
every connection. As mentioned earlier, this isn’t our final plan due to the
problems with potentially spawning an unlimited number of threads, but it is a
starting point to get a working multithreaded server first. Then we’ll add the
-thread pool as an improvement, and contrasting the two solutions will be
-easier.
+thread pool as an improvement, and contrasting the two solutions will be easier.
Listing 20-11 shows the changes to make to `main` to spawn a new thread to
handle each stream within the `for` loop.
@@ -790,9 +800,9 @@ new threads without any limit.
#### Creating a Finite Number of Threads
-We want our thread pool to work in a similar, familiar way so switching from
-threads to a thread pool doesn’t require large changes to the code that uses
-our API. Listing 20-12 shows the hypothetical interface for a `ThreadPool`
+We want our thread pool to work in a similar, familiar way so that switching
+from threads to a thread pool doesn’t require large changes to the code that
+uses our API. Listing 20-12 shows the hypothetical interface for a `ThreadPool`
struct we want to use instead of `thread::spawn`.
Filename: src/main.rs
@@ -800,12 +810,12 @@ Filename: src/main.rs
```
fn main() {
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
- [1] let pool = ThreadPool::new(4);
+ 1 let pool = ThreadPool::new(4);
for stream in listener.incoming() {
let stream = stream.unwrap();
- [2] pool.execute(|| {
+ 2 pool.execute(|| {
handle_connection(stream);
});
}
@@ -819,9 +829,9 @@ of threads, in this case four [1]. Then, in the `for` loop, `pool.execute` has
a similar interface as `thread::spawn` in that it takes a closure the pool
should run for each stream [2]. We need to implement `pool.execute` so it takes
the closure and gives it to a thread in the pool to run. This code won’t yet
-compile, but we’ll try so the compiler can guide us in how to fix it.
+compile, but we’ll try so that the compiler can guide us in how to fix it.
-#### Building `ThreadPool` Using Compiler Driven Development
+#### Building ThreadPool Using Compiler-Driven Development
Make the changes in Listing 20-12 to *src/main.rs*, and then let’s use the
compiler errors from `cargo check` to drive our development. Here is the first
@@ -831,21 +841,21 @@ error we get:
$ cargo check
Checking hello v0.1.0 (file:///projects/hello)
error[E0433]: failed to resolve: use of undeclared type `ThreadPool`
- --> src/main.rs:10:16
+ --> src/main.rs:11:16
|
-10 | let pool = ThreadPool::new(4);
+11 | let pool = ThreadPool::new(4);
| ^^^^^^^^^^ use of undeclared type `ThreadPool`
```
Great! This error tells us we need a `ThreadPool` type or module, so we’ll
build one now. Our `ThreadPool` implementation will be independent of the kind
-of work our web server is doing. So, let’s switch the `hello` crate from a
+of work our web server is doing. So let’s switch the `hello` crate from a
binary crate to a library crate to hold our `ThreadPool` implementation. After
we change to a library crate, we could also use the separate thread pool
library for any work we want to do using a thread pool, not just for serving
web requests.
-Create a *src/lib.rs* that contains the following, which is the simplest
+Create a *src/lib.rs* file that contains the following, which is the simplest
definition of a `ThreadPool` struct that we can have for now:
Filename: src/lib.rs
@@ -854,7 +864,7 @@ Filename: src/lib.rs
pub struct ThreadPool;
```
-Then edit *main.rs* file to bring `ThreadPool` into scope from the library
+Then edit the *main.rs* file to bring `ThreadPool` into scope from the library
crate by adding the following code to the top of *src/main.rs*:
Filename: src/main.rs
@@ -869,11 +879,13 @@ we need to address:
```
$ cargo check
Checking hello v0.1.0 (file:///projects/hello)
-error[E0599]: no function or associated item named `new` found for struct `ThreadPool` in the current scope
- --> src/bin/main.rs:11:28
+error[E0599]: no function or associated item named `new` found for struct
+`ThreadPool` in the current scope
+ --> src/main.rs:12:28
|
-11 | let pool = ThreadPool::new(4);
- | ^^^ function or associated item not found in `ThreadPool`
+12 | let pool = ThreadPool::new(4);
+ | ^^^ function or associated item not found in
+`ThreadPool`
```
This error indicates that next we need to create an associated function named
@@ -894,37 +906,37 @@ impl ThreadPool {
}
```
-We chose `usize` as the type of the `size` parameter, because we know that a
+We chose `usize` as the type of the `size` parameter because we know that a
negative number of threads doesn’t make any sense. We also know we’ll use this
-4 as the number of elements in a collection of threads, which is what the
-`usize` type is for, as discussed in the “Integer Types†section of Chapter 3.
+`4` as the number of elements in a collection of threads, which is what the
+`usize` type is for, as discussed in “Integer Types†on page XX.
Let’s check the code again:
```
$ cargo check
Checking hello v0.1.0 (file:///projects/hello)
-error[E0599]: no method named `execute` found for struct `ThreadPool` in the current scope
- --> src/bin/main.rs:16:14
+error[E0599]: no method named `execute` found for struct `ThreadPool` in the
+current scope
+ --> src/main.rs:17:14
|
-16 | pool.execute(|| {
+17 | pool.execute(|| {
| ^^^^^^^ method not found in `ThreadPool`
```
Now the error occurs because we don’t have an `execute` method on `ThreadPool`.
-Recall from the “Creating a Finite Number of Threads†section that we decided
+Recall from “Creating a Finite Number of Threads†on page XX that we decided
our thread pool should have an interface similar to `thread::spawn`. In
addition, we’ll implement the `execute` function so it takes the closure it’s
given and gives it to an idle thread in the pool to run.
We’ll define the `execute` method on `ThreadPool` to take a closure as a
-parameter. Recall from the “Moving Captured Values Out of the Closure and the
-`Fn` Traits†section in Chapter 13 that we can take closures as parameters with
-three different traits: `Fn`, `FnMut`, and `FnOnce`. We need to decide which
-kind of closure to use here. We know we’ll end up doing something similar to
-the standard library `thread::spawn` implementation, so we can look at what
-bounds the signature of `thread::spawn` has on its parameter. The documentation
-shows us the following:
+parameter. Recall from “Moving Captured Values Out of Closures and the Fn
+Traits†on page XX that we can take closures as parameters with three different
+traits: `Fn`, `FnMut`, and `FnOnce`. We need to decide which kind of closure to
+use here. We know we’ll end up doing something similar to the standard library
+`thread::spawn` implementation, so we can look at what bounds the signature of
+`thread::spawn` has on its parameter. The documentation shows us the following:
```
pub fn spawn<F, T>(f: F) -> JoinHandle<T>
@@ -952,10 +964,10 @@ Filename: src/lib.rs
```
impl ThreadPool {
- // --snip--
+ --snip--
pub fn execute<F>(&self, f: F)
where
- F: FnOnce() [1] + Send + 'static,
+ F: FnOnce() 1 + Send + 'static,
{
}
}
@@ -967,7 +979,7 @@ function definitions, the return type can be omitted from the signature, but
even if we have no parameters, we still need the parentheses.
Again, this is the simplest implementation of the `execute` method: it does
-nothing, but we’re trying only to make our code compile. Let’s check it again:
+nothing, but we’re only trying to make our code compile. Let’s check it again:
```
$ cargo check
@@ -981,18 +993,18 @@ the chapter. Our library isn’t actually calling the closure passed to `execute
yet!
> Note: A saying you might hear about languages with strict compilers, such as
-> Haskell and Rust, is “if the code compiles, it works.†But this saying is not
-> universally true. Our project compiles, but it does absolutely nothing! If we
-> were building a real, complete project, this would be a good time to start
-> writing unit tests to check that the code compiles *and* has the behavior we
-> want.
+Haskell and Rust, is “if the code compiles, it works.†But this saying is not
+universally true. Our project compiles, but it does absolutely nothing! If we
+were building a real, complete project, this would be a good time to start
+writing unit tests to check that the code compiles *and* has the behavior we
+want.
-#### Validating the Number of Threads in `new`
+#### Validating the Number of Threads in new
We aren’t doing anything with the parameters to `new` and `execute`. Let’s
implement the bodies of these functions with the behavior we want. To start,
let’s think about `new`. Earlier we chose an unsigned type for the `size`
-parameter, because a pool with a negative number of threads makes no sense.
+parameter because a pool with a negative number of threads makes no sense.
However, a pool with zero threads also makes no sense, yet zero is a perfectly
valid `usize`. We’ll add code to check that `size` is greater than zero before
we return a `ThreadPool` instance and have the program panic if it receives a
@@ -1006,16 +1018,16 @@ impl ThreadPool {
///
/// The size is the number of threads in the pool.
///
- [1] /// # Panics
+ 1 /// # Panics
///
/// The `new` function will panic if the size is zero.
pub fn new(size: usize) -> ThreadPool {
- [2] assert!(size > 0);
+ 2 assert!(size > 0);
ThreadPool
}
- // --snip--
+ --snip--
}
```
@@ -1035,14 +1047,10 @@ you’re feeling ambitious, try to write a function named `build` with the
following signature to compare with the `new` function:
```
-pub fn build(size: usize) -> Result<ThreadPool, PoolCreationError> {
+pub fn build(
+ size: usize
+) -> Result<ThreadPool, PoolCreationError> {
```
-<!-- Similar nit here to a comment I made a few chapters ago: fallible
-constructors are awkward to use. We may want to discourage their use. A modern
-approach might use a builder pattern to set the number of threads, and use a
-default number of threads that's non-zero. /JT -->
-<!-- I've changed the function name to be `build` which nicely matches the
-changes JT suggested for chapter 12. /Carol -->
#### Creating Space to Store the Threads
@@ -1073,18 +1081,18 @@ returned a `ThreadPool` instance containing them.
Filename: src/lib.rs
```
-[1] use std::thread;
+1 use std::thread;
pub struct ThreadPool {
- [2] threads: Vec<thread::JoinHandle<()>>,
+ 2 threads: Vec<thread::JoinHandle<()>>,
}
impl ThreadPool {
- // --snip--
+ --snip--
pub fn new(size: usize) -> ThreadPool {
assert!(size > 0);
- [3] let mut threads = Vec::with_capacity(size);
+ 3 let mut threads = Vec::with_capacity(size);
for _ in 0..size {
// create some threads and store them in the vector
@@ -1092,26 +1100,26 @@ impl ThreadPool {
ThreadPool { threads }
}
- // --snip--
+ --snip--
}
```
Listing 20-14: Creating a vector for `ThreadPool` to hold the threads
-We’ve brought `std::thread` into scope in the library crate [1], because we’re
+We’ve brought `std::thread` into scope in the library crate [1] because we’re
using `thread::JoinHandle` as the type of the items in the vector in
`ThreadPool` [2].
Once a valid size is received, our `ThreadPool` creates a new vector that can
hold `size` items [3]. The `with_capacity` function performs the same task as
-`Vec::new` but with an important difference: it preallocates space in the
+`Vec::new` but with an important difference: it pre-allocates space in the
vector. Because we know we need to store `size` elements in the vector, doing
this allocation up front is slightly more efficient than using `Vec::new`,
which resizes itself as elements are inserted.
When you run `cargo check` again, it should succeed.
-#### A `Worker` Struct Responsible for Sending Code from the `ThreadPool` to a Thread
+#### Sending Code from the ThreadPool to a Thread
We left a comment in the `for` loop in Listing 20-14 regarding the creation of
threads. Here, we’ll look at how we actually create threads. The standard
@@ -1125,31 +1133,31 @@ implement it manually.
We’ll implement this behavior by introducing a new data structure between the
`ThreadPool` and the threads that will manage this new behavior. We’ll call
this data structure *Worker*, which is a common term in pooling
-implementations. The Worker picks up code that needs to be run and runs the
-code in the Worker’s thread.
+implementations. The `Worker` picks up code that needs to be run and runs the
+code in its thread.
-Think of people working in the kitchen at a restaurant: the
-workers wait until orders come in from customers, and then they’re responsible
-for taking those orders and filling them.
+Think of people working in the kitchen at a restaurant: the workers wait until
+orders come in from customers, and then they’re responsible for taking those
+orders and filling them.
Instead of storing a vector of `JoinHandle<()>` instances in the thread pool,
we’ll store instances of the `Worker` struct. Each `Worker` will store a single
`JoinHandle<()>` instance. Then we’ll implement a method on `Worker` that will
take a closure of code to run and send it to the already running thread for
-execution. We’ll also give each worker an `id` so we can distinguish between
-the different workers in the pool when logging or debugging.
+execution. We’ll also give each `Worker` an `id` so we can distinguish between
+the different instances of `Worker` in the pool when logging or debugging.
Here is the new process that will happen when we create a `ThreadPool`. We’ll
implement the code that sends the closure to the thread after we have `Worker`
set up in this way:
1. Define a `Worker` struct that holds an `id` and a `JoinHandle<()>`.
-2. Change `ThreadPool` to hold a vector of `Worker` instances.
-3. Define a `Worker::new` function that takes an `id` number and returns a
- `Worker` instance that holds the `id` and a thread spawned with an empty
- closure.
-4. In `ThreadPool::new`, use the `for` loop counter to generate an `id`, create
- a new `Worker` with that `id`, and store the worker in the vector.
+1. Change `ThreadPool` to hold a vector of `Worker` instances.
+1. Define a `Worker::new` function that takes an `id` number and returns a
+`Worker` instance that holds the `id` and a thread spawned with an empty
+closure.
+1. In `ThreadPool::new`, use the `for` loop counter to generate an `id`, create
+a new `Worker` with that `id`, and store the `Worker` in the vector.
If you’re up for a challenge, try implementing these changes on your own before
looking at the code in Listing 20-15.
@@ -1162,49 +1170,39 @@ Filename: src/lib.rs
use std::thread;
pub struct ThreadPool {
- [1] workers: Vec<Worker>,
+ 1 workers: Vec<Worker>,
}
impl ThreadPool {
- // --snip--
+ --snip--
pub fn new(size: usize) -> ThreadPool {
assert!(size > 0);
let mut workers = Vec::with_capacity(size);
- [2] for id in 0..size {
- [3] workers.push(Worker::new(id));
+ 2 for id in 0..size {
+ 3 workers.push(Worker::new(id));
}
ThreadPool { workers }
}
- // --snip--
+ --snip--
}
-[4] struct Worker {
+4 struct Worker {
id: usize,
thread: thread::JoinHandle<()>,
}
impl Worker {
- [5] fn new(id: usize) -> Worker {
- [6] let thread = thread::spawn(|| {});
+ 5 fn new(id: usize) -> Worker {
+ 6 let thread = thread::spawn(|| {});
- Worker { [7] id, [8] thread }
+ Worker { 7 id, 8 thread }
}
}
```
-<!-- Spawning a thread in the constructor isn't safe to do as the spawn
-of the thread may fail. You can use
-https://doc.rust-lang.org/std/thread/struct.Builder.html#method.spawn
-to be better protected against running out of resources. This should
-probably not live in the constructor, but instead in some helper function
-that can return a Result. /JT -->
-<!-- I've added a note in a few paragraphs. I think this behavior is perfectly
-fine for this example so I'm not going to change the code, but it is something
-readers should know. /Carol -->
-
Listing 20-15: Modifying `ThreadPool` to hold `Worker` instances instead of
holding threads directly
@@ -1221,11 +1219,11 @@ so we make the `Worker` struct [4] and its `new` function [5] private. The
empty closure [6].
> Note: If the operating system can’t create a thread because there aren’t
-> enough system resources, `thread::spawn` will panic. That will cause our
-> whole server to panic, even though the creation of some threads might
-> succeed. For simplicity’s sake, this behavior is fine, but in a production
-> thread pool implementation, you’d likely want to use `std::thread::Builder`
-> and its `spawn` method that returns `Result` instead.
+enough system resources, `thread::spawn` will panic. That will cause our whole
+server to panic, even though the creation of some threads might succeed. For
+simplicity’s sake, this behavior is fine, but in a production thread pool
+implementation, you’d likely want to use `std::thread::Builder` and its `spawn`
+method that returns `Result` instead.
This code will compile and will store the number of `Worker` instances we
specified as an argument to `ThreadPool::new`. But we’re *still* not processing
@@ -1247,13 +1245,13 @@ as the queue of jobs, and `execute` will send a job from the `ThreadPool` to
the `Worker` instances, which will send the job to its thread. Here is the plan:
1. The `ThreadPool` will create a channel and hold on to the sender.
-2. Each `Worker` will hold on to the receiver.
-3. We’ll create a new `Job` struct that will hold the closures we want to send
- down the channel.
-4. The `execute` method will send the job it wants to execute through the
- sender.
-5. In its thread, the `Worker` will loop over its receiver and execute the
- closures of any jobs it receives.
+1. Each `Worker` will hold on to the receiver.
+1. We’ll create a new `Job` struct that will hold the closures we want to send
+down the channel.
+1. The `execute` method will send the job it wants to execute through the
+sender.
+1. In its thread, the `Worker` will loop over its receiver and execute the
+closures of any jobs it receives.
Let’s start by creating a channel in `ThreadPool::new` and holding the sender
in the `ThreadPool` instance, as shown in Listing 20-16. The `Job` struct
@@ -1273,11 +1271,11 @@ pub struct ThreadPool {
struct Job;
impl ThreadPool {
- // --snip--
+ --snip--
pub fn new(size: usize) -> ThreadPool {
assert!(size > 0);
- [1] let (sender, receiver) = mpsc::channel();
+ 1 let (sender, receiver) = mpsc::channel();
let mut workers = Vec::with_capacity(size);
@@ -1285,9 +1283,9 @@ impl ThreadPool {
workers.push(Worker::new(id));
}
- ThreadPool { workers, [2] sender }
+ ThreadPool { workers, 2 sender }
}
- // --snip--
+ --snip--
}
```
@@ -1297,16 +1295,16 @@ transmits `Job` instances
In `ThreadPool::new`, we create our new channel [1] and have the pool hold the
sender [2]. This will successfully compile.
-Let’s try passing a receiver of the channel into each worker as the thread pool
-creates the channel. We know we want to use the receiver in the thread that the
-workers spawn, so we’ll reference the `receiver` parameter in the closure. The
-code in Listing 20-17 won’t quite compile yet.
+Let’s try passing a receiver of the channel into each `Worker` as the thread
+pool creates the channel. We know we want to use the receiver in the thread
+that the `Worker` instances spawn, so we’ll reference the `receiver` parameter
+in the closure. The code in Listing 20-17 won’t quite compile yet.
Filename: src/lib.rs
```
impl ThreadPool {
- // --snip--
+ --snip--
pub fn new(size: usize) -> ThreadPool {
assert!(size > 0);
@@ -1315,20 +1313,20 @@ impl ThreadPool {
let mut workers = Vec::with_capacity(size);
for id in 0..size {
- [1] workers.push(Worker::new(id, receiver));
+ 1 workers.push(Worker::new(id, receiver));
}
ThreadPool { workers, sender }
}
- // --snip--
+ --snip--
}
-// --snip--
+--snip--
impl Worker {
fn new(id: usize, receiver: mpsc::Receiver<Job>) -> Worker {
let thread = thread::spawn(|| {
- [2] receiver;
+ 2 receiver;
});
Worker { id, thread }
@@ -1336,7 +1334,7 @@ impl Worker {
}
```
-Listing 20-17: Passing the receiver to the workers
+Listing 20-17: Passing the receiver to each `Worker`
We’ve made some small and straightforward changes: we pass the receiver into
`Worker::new` [1], and then we use it inside the closure [2].
@@ -1347,13 +1345,15 @@ When we try to check this code, we get this error:
$ cargo check
Checking hello v0.1.0 (file:///projects/hello)
error[E0382]: use of moved value: `receiver`
- --> src/lib.rs:27:42
+ --> src/lib.rs:26:42
|
-22 | let (sender, receiver) = mpsc::channel();
- | -------- move occurs because `receiver` has type `std::sync::mpsc::Receiver<Job>`, which does not implement the `Copy` trait
+21 | let (sender, receiver) = mpsc::channel();
+ | -------- move occurs because `receiver` has type
+`std::sync::mpsc::Receiver<Job>`, which does not implement the `Copy` trait
...
-27 | workers.push(Worker::new(id, receiver));
- | ^^^^^^^^ value moved here, in previous iteration of loop
+26 | workers.push(Worker::new(id, receiver));
+ | ^^^^^^^^ value moved here, in
+previous iteration of loop
```
The code is trying to pass `receiver` to multiple `Worker` instances. This
@@ -1361,7 +1361,8 @@ won’t work, as you’ll recall from Chapter 16: the channel implementation tha
Rust provides is multiple *producer*, single *consumer*. This means we can’t
just clone the consuming end of the channel to fix this code. We also don’t
want to send a message multiple times to multiple consumers; we want one list
-of messages with multiple workers such that each message gets processed once.
+of messages with multiple `Worker` instances such that each message gets
+processed once.
Additionally, taking a job off the channel queue involves mutating the
`receiver`, so the threads need a safe way to share and modify `receiver`;
@@ -1369,9 +1370,10 @@ otherwise, we might get race conditions (as covered in Chapter 16).
Recall the thread-safe smart pointers discussed in Chapter 16: to share
ownership across multiple threads and allow the threads to mutate the value, we
-need to use `Arc<Mutex<T>>`. The `Arc` type will let multiple workers own the
-receiver, and `Mutex` will ensure that only one worker gets a job from the
-receiver at a time. Listing 20-18 shows the changes we need to make.
+need to use `Arc<Mutex<T>>`. The `Arc` type will let multiple `Worker`
+instances own the receiver, and `Mutex` will ensure that only one `Worker` gets
+a job from the receiver at a time. Listing 20-18 shows the changes we need to
+make.
Filename: src/lib.rs
@@ -1380,75 +1382,81 @@ use std::{
sync::{mpsc, Arc, Mutex},
thread,
};
-// --snip--
+--snip--
impl ThreadPool {
- // --snip--
+ --snip--
pub fn new(size: usize) -> ThreadPool {
assert!(size > 0);
let (sender, receiver) = mpsc::channel();
- [1] let receiver = Arc::new(Mutex::new(receiver));
+ 1 let receiver = Arc::new(Mutex::new(receiver));
let mut workers = Vec::with_capacity(size);
for id in 0..size {
- workers.push(Worker::new(id, Arc::clone(&receiver)[2]));
+ workers.push(
+ Worker::new(id, Arc::clone(& 2 receiver))
+ );
}
ThreadPool { workers, sender }
}
- // --snip--
+ --snip--
}
-// --snip--
+--snip--
impl Worker {
- fn new(id: usize, receiver: Arc<Mutex<mpsc::Receiver<Job>>>) -> Worker {
- // --snip--
+ fn new(
+ id: usize,
+ receiver: Arc<Mutex<mpsc::Receiver<Job>>>,
+ ) -> Worker {
+ --snip--
}
}
```
-Listing 20-18: Sharing the receiver among the workers using `Arc` and `Mutex`
+Listing 20-18: Sharing the receiver among the `Worker` instances using `Arc`
+and `Mutex`
In `ThreadPool::new`, we put the receiver in an `Arc` and a `Mutex` [1]. For
-each new worker, we clone the `Arc` to bump the reference count so the workers
-can share ownership of the receiver [2].
+each new `Worker`, we clone the `Arc` to bump the reference count so the
+`Worker` instances can share ownership of the receiver [2].
With these changes, the code compiles! We’re getting there!
-#### Implementing the `execute` Method
+#### Implementing the execute Method
Let’s finally implement the `execute` method on `ThreadPool`. We’ll also change
`Job` from a struct to a type alias for a trait object that holds the type of
-closure that `execute` receives. As discussed in the “Creating Type Synonyms
-with Type Aliases†section of Chapter 19, type aliases allow us to make long
-types shorter for ease of use. Look at Listing 20-19.
+closure that `execute` receives. As discussed in “Creating Type Synonyms with
+Type Aliases†on page XX, type aliases allow us to make long types shorter for
+ease of use. Look at Listing 20-19.
Filename: src/lib.rs
```
-// --snip--
+--snip--
type Job = Box<dyn FnOnce() + Send + 'static>;
impl ThreadPool {
- // --snip--
+ --snip--
pub fn execute<F>(&self, f: F)
where
F: FnOnce() + Send + 'static,
{
- [1] let job = Box::new(f);
+ 1 let job = Box::new(f);
- [2] self.sender.send(job).unwrap();
+ 2 self.sender.send(job).unwrap();
}
}
-// --snip--
+--snip--
```
Listing 20-19: Creating a `Job` type alias for a `Box` that holds each closure
@@ -1463,7 +1471,7 @@ executing: our threads continue executing as long as the pool exists. The
reason we use `unwrap` is that we know the failure case won’t happen, but the
compiler doesn’t know that.
-But we’re not quite done yet! In the worker, our closure being passed to
+But we’re not quite done yet! In the `Worker`, our closure being passed to
`thread::spawn` still only *references* the receiving end of the channel.
Instead, we need the closure to loop forever, asking the receiving end of the
channel for a job and running the job when it gets one. Let’s make the change
@@ -1472,12 +1480,19 @@ shown in Listing 20-20 to `Worker::new`.
Filename: src/lib.rs
```
-// --snip--
+--snip--
impl Worker {
- fn new(id: usize, receiver: Arc<Mutex<mpsc::Receiver<Job>>>) -> Worker {
+ fn new(
+ id: usize,
+ receiver: Arc<Mutex<mpsc::Receiver<Job>>>,
+ ) -> Worker {
let thread = thread::spawn(move || loop {
- let job = receiver.lock()[1].unwrap()[2].recv()[3].unwrap()[4];
+ let job = receiver
+ 1 .lock()
+ 2 .unwrap()
+ 3 .recv()
+ 4 .unwrap();
println!("Worker {id} got a job; executing.");
@@ -1489,7 +1504,8 @@ impl Worker {
}
```
-Listing 20-20: Receiving and executing the jobs in the worker’s thread
+Listing 20-20: Receiving and executing the jobs in the `Worker` instance’s
+thread
Here, we first call `lock` on the `receiver` to acquire the mutex [1], and then
we call `unwrap` to panic on any errors [2]. Acquiring a lock might fail if the
@@ -1555,21 +1571,24 @@ overloaded if the server receives a lot of requests. If we make a request to
*/sleep*, the server will be able to serve other requests by having another
thread run them.
-> Note: if you open */sleep* in multiple browser windows simultaneously, they
-> might load one at a time in 5 second intervals. Some web browsers execute
-> multiple instances of the same request sequentially for caching reasons. This
-> limitation is not caused by our web server.
+> Note: If you open */sleep* in multiple browser windows simultaneously, they
+might load one at a time in five-second intervals. Some web browsers execute
+multiple instances of the same request sequentially for caching reasons. This
+limitation is not caused by our web server.
After learning about the `while let` loop in Chapter 18, you might be wondering
-why we didn’t write the worker thread code as shown in Listing 20-21.
+why we didn’t write the `Worker` thread code as shown in Listing 20-21.
Filename: src/lib.rs
```
-// --snip--
+--snip--
impl Worker {
- fn new(id: usize, receiver: Arc<Mutex<mpsc::Receiver<Job>>>) -> Worker {
+ fn new(
+ id: usize,
+ receiver: Arc<Mutex<mpsc::Receiver<Job>>>,
+ ) -> Worker {
let thread = thread::spawn(move || {
while let Ok(job) = receiver.lock().unwrap().recv() {
println!("Worker {id} got a job; executing.");
@@ -1598,21 +1617,20 @@ longer than intended if we aren’t mindful of the lifetime of the
The code in Listing 20-20 that uses `let job =
receiver.lock().unwrap().recv().unwrap();` works because with `let`, any
-temporary values used in the expression on the right hand side of the equals
+temporary values used in the expression on the right-hand side of the equal
sign are immediately dropped when the `let` statement ends. However, `while
let` (and `if let` and `match`) does not drop temporary values until the end of
the associated block. In Listing 20-21, the lock remains held for the duration
-of the call to `job()`, meaning other workers cannot receive jobs.
+of the call to `job()`, meaning other `Worker` instances cannot receive jobs.
## Graceful Shutdown and Cleanup
The code in Listing 20-20 is responding to requests asynchronously through the
use of a thread pool, as we intended. We get some warnings about the `workers`,
`id`, and `thread` fields that we’re not using in a direct way that reminds us
-we’re not cleaning up anything. When we use the less elegant <span
-class="keystroke">ctrl-c</span> method to halt the main thread, all other
-threads are stopped immediately as well, even if they’re in the middle of
-serving a request.
+we’re not cleaning up anything. When we use the less elegant ctrl-C method to
+halt the main thread, all other threads are stopped immediately as well, even
+if they’re in the middle of serving a request.
Next, then, we’ll implement the `Drop` trait to call `join` on each of the
threads in the pool so they can finish the requests they’re working on before
@@ -1621,7 +1639,7 @@ accepting new requests and shut down. To see this code in action, we’ll modify
our server to accept only two requests before gracefully shutting down its
thread pool.
-### Implementing the `Drop` Trait on `ThreadPool`
+### Implementing the Drop Trait on ThreadPool
Let’s start with implementing `Drop` on our thread pool. When the pool is
dropped, our threads should all join to make sure they finish their work.
@@ -1633,10 +1651,10 @@ Filename: src/lib.rs
```
impl Drop for ThreadPool {
fn drop(&mut self) {
- [1] for worker in &mut self.workers {
- [2] println!("Shutting down worker {}", worker.id);
+ 1 for worker in &mut self.workers {
+ 2 println!("Shutting down worker {}", worker.id);
- [3] worker.thread.join().unwrap();
+ 3 worker.thread.join().unwrap();
}
}
}
@@ -1644,21 +1662,29 @@ impl Drop for ThreadPool {
Listing 20-22: Joining each thread when the thread pool goes out of scope
-First, we loop through each of the thread pool `workers` [1]. We use `&mut` for
+First we loop through each of the thread pool `workers` [1]. We use `&mut` for
this because `self` is a mutable reference, and we also need to be able to
-mutate `worker`. For each worker, we print a message saying that this
-particular worker is shutting down [2], and then we call `join` on that
-worker’s thread [3]. If the call to `join` fails, we use `unwrap` to make Rust
-panic and go into an ungraceful shutdown.
+mutate `worker`. For each `worker`, we print a message saying that this
+particular `Worker` instance is shutting down [2], and then we call `join` on
+that `Worker` instance’s thread [3]. If the call to `join` fails, we use
+`unwrap` to make Rust panic and go into an ungraceful shutdown.
Here is the error we get when we compile this code:
```
-error[E0507]: cannot move out of `worker.thread` which is behind a mutable reference
- --> src/lib.rs:52:13
- |
-52 | worker.thread.join().unwrap();
- | ^^^^^^^^^^^^^ move occurs because `worker.thread` has type `JoinHandle<()>`, which does not implement the `Copy` trait
+error[E0507]: cannot move out of `worker.thread` which is behind a mutable
+reference
+ --> src/lib.rs:52:13
+ |
+52 | worker.thread.join().unwrap();
+ | ^^^^^^^^^^^^^ ------ `worker.thread` moved due to this
+method call
+ | |
+ | move occurs because `worker.thread` has type
+`JoinHandle<()>`, which does not implement the `Copy` trait
+ |
+note: this function takes ownership of the receiver `self`, which moves
+`worker.thread`
```
The error tells us we can’t call `join` because we only have a mutable borrow
@@ -1687,24 +1713,27 @@ Now let’s lean on the compiler to find the other places that need to change.
Checking this code, we get two errors:
```
-error[E0599]: no method named `join` found for enum `Option` in the current scope
+error[E0599]: no method named `join` found for enum `Option` in the current
+scope
--> src/lib.rs:52:27
|
52 | worker.thread.join().unwrap();
- | ^^^^ method not found in `Option<JoinHandle<()>>`
+ | ^^^^ method not found in
+`Option<JoinHandle<()>>`
error[E0308]: mismatched types
--> src/lib.rs:72:22
|
72 | Worker { id, thread }
- | ^^^^^^ expected enum `Option`, found struct `JoinHandle`
+ | ^^^^^^ expected enum `Option`, found struct
+`JoinHandle`
|
= note: expected enum `Option<JoinHandle<()>>`
found struct `JoinHandle<_>`
help: try wrapping the expression in `Some`
|
-72 | Worker { id, Some(thread) }
- | +++++ +
+72 | Worker { id, thread: Some(thread) }
+ | +++++++++++++ +
```
Let’s address the second error, which points to the code at the end of
@@ -1715,8 +1744,11 @@ Filename: src/lib.rs
```
impl Worker {
- fn new(id: usize, receiver: Arc<Mutex<mpsc::Receiver<Job>>>) -> Worker {
- // --snip--
+ fn new(
+ id: usize,
+ receiver: Arc<Mutex<mpsc::Receiver<Job>>>,
+ ) -> Worker {
+ --snip--
Worker {
id,
@@ -1738,8 +1770,8 @@ impl Drop for ThreadPool {
for worker in &mut self.workers {
println!("Shutting down worker {}", worker.id);
- [1] if let Some(thread) = worker.thread.take() {
- [2] thread.join().unwrap();
+ 1 if let Some(thread) = worker.thread.take() {
+ 2 thread.join().unwrap();
}
}
}
@@ -1749,27 +1781,27 @@ impl Drop for ThreadPool {
As discussed in Chapter 17, the `take` method on `Option` takes the `Some`
variant out and leaves `None` in its place. We’re using `if let` to destructure
the `Some` and get the thread [1]; then we call `join` on the thread [2]. If a
-worker’s thread is already `None`, we know that worker has already had its
-thread cleaned up, so nothing happens in that case.
+`Worker` instance’s thread is already `None`, we know that `Worker` has already
+had its thread cleaned up, so nothing happens in that case.
### Signaling to the Threads to Stop Listening for Jobs
With all the changes we’ve made, our code compiles without any warnings.
-However, the bad news is this code doesn’t function the way we want it to yet.
-The key is the logic in the closures run by the threads of the `Worker`
-instances: at the moment, we call `join`, but that won’t shut down the threads
+However, the bad news is that this code doesn’t function the way we want it to
+yet. The key is the logic in the closures run by the threads of the `Worker`
+instances: at the moment, we call `join`, but that won’t shut down the threads,
because they `loop` forever looking for jobs. If we try to drop our
`ThreadPool` with our current implementation of `drop`, the main thread will
-block forever waiting for the first thread to finish.
+block forever, waiting for the first thread to finish.
-To fix this problem, we’ll need a change in the the `ThreadPool` `drop`
+To fix this problem, we’ll need a change in the `ThreadPool` `drop`
implementation and then a change in the `Worker` loop.
-First, we’ll change the `ThreadPool` `drop` implementation to explicitly drop
+First we’ll change the `ThreadPool` `drop` implementation to explicitly drop
the `sender` before waiting for the threads to finish. Listing 20-23 shows the
changes to `ThreadPool` to explicitly drop `sender`. We use the same `Option`
and `take` technique as we did with the thread to be able to move `sender` out
-of `ThreadPool`:
+of `ThreadPool`.
Filename: src/lib.rs
@@ -1778,10 +1810,10 @@ pub struct ThreadPool {
workers: Vec<Worker>,
sender: Option<mpsc::Sender<Job>>,
}
-// --snip--
+--snip--
impl ThreadPool {
pub fn new(size: usize) -> ThreadPool {
- // --snip--
+ --snip--
ThreadPool {
workers,
@@ -1795,13 +1827,17 @@ impl ThreadPool {
{
let job = Box::new(f);
- self.sender.as_ref().unwrap().send(job).unwrap();
+ self.sender
+ .as_ref()
+ .unwrap()
+ .send(job)
+ .unwrap();
}
}
impl Drop for ThreadPool {
fn drop(&mut self) {
- [1] drop(self.sender.take());
+ 1 drop(self.sender.take());
for worker in &mut self.workers {
println!("Shutting down worker {}", worker.id);
@@ -1814,28 +1850,37 @@ impl Drop for ThreadPool {
}
```
-Listing 20-23: Explicitly drop `sender` before joining the worker threads
+Listing 20-23: Explicitly dropping `sender` before joining the `Worker` threads
Dropping `sender` [1] closes the channel, which indicates no more messages will
-be sent. When that happens, all the calls to `recv` that the workers do in the
-infinite loop will return an error. In Listing 20-24, we change the `Worker`
-loop to gracefully exit the loop in that case, which means the threads will
-finish when the `ThreadPool` `drop` implementation calls `join` on them.
+be sent. When that happens, all the calls to `recv` that the `Worker` instances
+do in the infinite loop will return an error. In Listing 20-24, we change the
+`Worker` loop to gracefully exit the loop in that case, which means the threads
+will finish when the `ThreadPool` `drop` implementation calls `join` on them.
Filename: src/lib.rs
```
impl Worker {
- fn new(id: usize, receiver: Arc<Mutex<mpsc::Receiver<Job>>>) -> Worker {
+ fn new(
+ id: usize,
+ receiver: Arc<Mutex<mpsc::Receiver<Job>>>,
+ ) -> Worker {
let thread = thread::spawn(move || loop {
- match receiver.lock().unwrap().recv() {
+ let message = receiver.lock().unwrap().recv();
+
+ match message {
Ok(job) => {
- println!("Worker {id} got a job; executing.");
+ println!(
+ "Worker {id} got a job; executing."
+ );
job();
}
Err(_) => {
- println!("Worker {id} disconnected; shutting down.");
+ println!(
+ "Worker {id} shutting down."
+ );
break;
}
}
@@ -1849,7 +1894,7 @@ impl Worker {
}
```
-Listing 20-24: Explicitly break out of the loop when `recv` returns an error
+Listing 20-24: Explicitly breaking out of the loop when `recv` returns an error
To see this code in action, let’s modify `main` to accept only two requests
before gracefully shutting down the server, as shown in Listing 20-25.
@@ -1873,8 +1918,8 @@ fn main() {
}
```
-Listing 20-25: Shut down the server after serving two requests by exiting the
-loop
+Listing 20-25: Shutting down the server after serving two requests by exiting
+the loop
You wouldn’t want a real-world web server to shut down after serving only two
requests. This code just demonstrates that the graceful shutdown and cleanup is
@@ -1905,26 +1950,27 @@ Shutting down worker 2
Shutting down worker 3
```
-You might see a different ordering of workers and messages printed. We can see
-how this code works from the messages: workers 0 and 3 got the first two
-requests. The server stopped accepting connections after the second connection,
-and the `Drop` implementation on `ThreadPool` starts executing before worker 3
-even starts its job. Dropping the `sender` disconnects all the workers and
-tells them to shut down. The workers each print a message when they disconnect,
-and then the thread pool calls `join` to wait for each worker thread to finish.
+You might see a different ordering of `Worker` IDs and messages printed. We can
+see how this code works from the messages: `Worker` instances 0 and 3 got the
+first two requests. The server stopped accepting connections after the second
+connection, and the `Drop` implementation on `ThreadPool` starts executing
+before `Worker` 3 even starts its job. Dropping the `sender` disconnects all
+the `Worker` instances and tells them to shut down. The `Worker` instances each
+print a message when they disconnect, and then the thread pool calls `join` to
+wait for each `Worker` thread to finish.
Notice one interesting aspect of this particular execution: the `ThreadPool`
-dropped the `sender`, and before any worker received an error, we tried to join
-worker 0. Worker 0 had not yet gotten an error from `recv`, so the main thread
-blocked waiting for worker 0 to finish. In the meantime, worker 3 received a
-job and then all threads received an error. When worker 0 finished, the main
-thread waited for the rest of the workers to finish. At that point, they had
-all exited their loops and stopped.
+dropped the `sender`, and before any `Worker` received an error, we tried to
+join `Worker` 0. `Worker` 0 had not yet gotten an error from `recv`, so the
+main thread blocked, waiting for `Worker` 0 to finish. In the meantime,
+`Worker` 3 received a job and then all threads received an error. When `Worker`
+0 finished, the main thread waited for the rest of the `Worker` instances to
+finish. At that point, they had all exited their loops and stopped.
Congrats! We’ve now completed our project; we have a basic web server that uses
a thread pool to respond asynchronously. We’re able to perform a graceful
shutdown of the server, which cleans up all the threads in the pool. See
-*https://www.nostarch.com/Rust2021/* to download the full code for this chapter
+*https://www.nostarch.com/Rust2021* to download the full code for this chapter
for reference.
We could do more here! If you want to continue enhancing this project, here are
@@ -1934,14 +1980,15 @@ some ideas:
* Add tests of the library’s functionality.
* Change calls to `unwrap` to more robust error handling.
* Use `ThreadPool` to perform some task other than serving web requests.
-* Find a thread pool crate on *https://crates.io/* and implement a similar web
- server using the crate instead. Then compare its API and robustness to the
- thread pool we implemented.
+* Find a thread pool crate on *https://crates.io* and implement a similar web
+server using the crate instead. Then compare its API and robustness to the
+thread pool we implemented.
## Summary
Well done! You’ve made it to the end of the book! We want to thank you for
joining us on this tour of Rust. You’re now ready to implement your own Rust
-projects and help with other peoples’ projects. Keep in mind that there is a
+projects and help with other people’s projects. Keep in mind that there is a
welcoming community of other Rustaceans who would love to help you with any
challenges you encounter on your Rust journey.
+
diff --git a/src/doc/book/nostarch/frontmatter.md b/src/doc/book/nostarch/frontmatter.md
new file mode 100644
index 000000000..001f96483
--- /dev/null
+++ b/src/doc/book/nostarch/frontmatter.md
@@ -0,0 +1,292 @@
+<!-- DO NOT EDIT THIS FILE.
+
+This file is periodically generated from the content in the `/src/`
+directory, so all fixes need to be made in `/src/`.
+-->
+## About the Authors
+
+Carol Nichols is a member of the Rust Crates.io Team and a former member of the
+Rust Core Team. She’s a co-founder of Integer 32, LLC, the world’s first
+Rust-focused software consultancy. Nichols has also organized the Rust Belt
+Rust Conference.
+
+Steve Klabnik was the lead for the Rust documentation team and was one of
+Rust’s core developers. A frequent speaker and a prolific open source
+contributor, he previously worked on projects such as Ruby and Ruby on Rails.
+
+## About the Technical Reviewer
+
+JT is a Rust core team member and the co-creator of the Rust error message
+format, Rust Language Server (RLS), and Nushell. They first started using Rust
+in 2011, and in 2016 joined Mozilla to work on Rust full time, helping to shape
+its direction for widespread use. These days, they are a freelance Rust trainer
+and advocate for safe systems programming.
+
+## Brief Contents
+
+## Contents in Detail
+
+## Foreword
+
+It wasn’t always so clear, but the Rust programming language is fundamentally
+about *empowerment*: no matter what kind of code you are writing now, Rust
+empowers you to reach further, to program with confidence in a wider variety of
+domains than you did before.
+
+Take, for example, “systems-level†work that deals with low-level details of
+memory management, data representation, and concurrency. Traditionally, this
+realm of programming is seen as arcane, accessible to only a select few who
+have devoted the necessary years learning it to avoid its infamous pitfalls.
+And even those who practice it do so with caution, lest their code be open to
+exploits, crashes, or corruption.
+
+Rust breaks down these barriers by eliminating the old pitfalls and providing a
+friendly, polished set of tools to help you along the way. Programmers who need
+to “dip down†into lower-level control can do so with Rust, without taking on
+the customary risk of crashes or security holes and without having to learn the
+fine points of a fickle toolchain. Better yet, the language is designed to
+guide you naturally toward reliable code that is efficient in terms of speed
+and memory usage.
+
+Programmers who are already working with low-level code can use Rust to raise
+their ambitions. For example, introducing parallelism in Rust is a relatively
+low-risk operation: the compiler will catch the classical mistakes for you. And
+you can tackle more aggressive optimizations in your code with the confidence
+that you won’t accidentally introduce crashes or vulnerabilities.
+
+But Rust isn’t limited to low-level systems programming. It’s expressive and
+ergonomic enough to make CLI apps, web servers, and many other kinds of code
+quite pleasant to write—you’ll find simple examples later in the book. Working
+with Rust allows you to build skills that transfer from one domain to another;
+you can learn Rust by writing a web app, then apply those same skills to target
+your Raspberry Pi.
+
+This book fully embraces the potential of Rust to empower its users. It’s a
+friendly and approachable text intended to help you level up not just your
+knowledge of Rust, but also your reach and confidence as a programmer in
+general. So dive in, get ready to learn—and welcome to the Rust community!
+
+Nicholas Matsakis and Aaron Turon
+
+## ACKNOWLEDGMENTS
+
+We would like to thank everyone who has worked on the Rust language for
+creating an amazing language worth writing a book about. We’re grateful to
+everyone in the Rust community for being welcoming and creating an environment
+worth welcoming more folks into.
+
+We’re especially thankful for everyone who read early versions of this book
+online and provided feedback, bug reports, and pull requests. Special thanks to
+Eduard-Mihai Burtescu, Alex Crichton, and JT for providing technical review,
+and to Karen Rustad Tölva for the cover art. Thank you to our team at No
+Starch, including Bill Pollock, Liz Chadwick, and Janelle Ludowise, for
+improving this book and bringing it to print.
+
+Carol is grateful for the opportunity to work on this book. She thanks her
+family for their constant love and support, especially her husband, Jake
+Goulding, and her daughter, Vivian.
+
+## Preface
+
+This version of the text assumes you’re using Rust 1.62.0 (released 2022-06-30)
+or later with `edition="2021"` in the *Cargo.toml* file of all projects to
+configure them to use Rust 2021 edition idioms. See “Installation†on page XX
+for instructions on installing or updating Rust, and see Appendix E for
+information on editions.
+
+The 2021 edition of the Rust language includes a number of improvements that
+make Rust more ergonomic and that correct some inconsistencies. On top of a
+general update to reflect these improvements, this rendition of the book has a
+number of improvements to address specific feedback:
+
+* Chapter 7 contains a new quick reference section on organizing your code into
+multiple files with modules.
+* Chapter 13 has new and improved closure examples that more clearly illustrate
+captures, the `move` keyword, and the `Fn` traits.
+* We fixed a number of small errors and imprecise wording throughout the book.
+Thank you to the readers who reported them!
+
+Note that any code from earlier renditions of this book that compiled will
+continue to compile with the relevant edition in the project’s *Cargo.toml*,
+even as you update the Rust compiler version you’re using. That’s Rust’s
+backward-compatibility guarantees at work!
+
+## Introduction
+
+Welcome to *The Rust Programming Language*, an introductory book about Rust.
+The Rust programming language helps you write faster, more reliable software.
+High-level ergonomics and low-level control are often at odds in programming
+language design; Rust challenges that conflict. Through balancing powerful
+technical capacity and a great developer experience, Rust gives you the option
+to control low-level details (such as memory usage) without all the hassle
+traditionally associated with such control.
+
+## Who Rust Is For
+
+Rust is ideal for many people for a variety of reasons. Let’s look at a few of
+the most important groups.
+
+### Teams of Developers
+
+Rust is proving to be a productive tool for collaborating among large teams of
+developers with varying levels of systems programming knowledge. Low-level code
+is prone to various subtle bugs, which in most other languages can only be
+caught through extensive testing and careful code review by experienced
+developers. In Rust, the compiler plays a gatekeeper role by refusing to
+compile code with these elusive bugs, including concurrency bugs. By working
+alongside the compiler, the team can spend their time focusing on the program’s
+logic rather than chasing down bugs.
+
+Rust also brings contemporary developer tools to the systems programming world:
+
+* Cargo, the included dependency manager and build tool, makes adding,
+compiling, and managing dependencies painless and consistent across the Rust
+ecosystem.
+* The `rustfmt` formatting tool ensures a consistent coding style across
+developers.
+* The Rust Language Server powers integrated development environment (IDE)
+integration for code completion and inline error messages.
+
+By using these and other tools in the Rust ecosystem, developers can be
+productive while writing systems-level code.
+
+### Students
+
+Rust is for students and those who are interested in learning about systems
+concepts. Using Rust, many people have learned about topics like operating
+systems development. The community is very welcoming and happy to answer
+students’ questions. Through efforts such as this book, the Rust teams want to
+make systems concepts more accessible to more people, especially those new to
+programming.
+
+### Companies
+
+Hundreds of companies, large and small, use Rust in production for a variety of
+tasks, including command line tools, web services, DevOps tooling, embedded
+devices, audio and video analysis and transcoding, cryptocurrencies,
+bioinformatics, search engines, Internet of Things applications, machine
+learning, and even major parts of the Firefox web browser.
+
+### Open Source Developers
+
+Rust is for people who want to build the Rust programming language, community,
+developer tools, and libraries. We’d love to have you contribute to the Rust
+language.
+
+### People Who Value Speed and Stability
+
+Rust is for people who crave speed and stability in a language. By speed, we
+mean both how quickly Rust code can run and the speed at which Rust lets you
+write programs. The Rust compiler’s checks ensure stability through feature
+additions and refactoring. This is in contrast to the brittle legacy code in
+languages without these checks, which developers are often afraid to modify. By
+striving for zero-cost abstractions, higher-level features that compile to
+lower-level code as fast as code written manually, Rust endeavors to make safe
+code be fast code as well.
+
+The Rust language hopes to support many other users as well; those mentioned
+here are merely some of the biggest stakeholders. Overall, Rust’s greatest
+ambition is to eliminate the trade-offs that programmers have accepted for
+decades by providing safety *and* productivity, speed *and* ergonomics. Give
+Rust a try and see if its choices work for you.
+
+## Who This Book Is For
+
+This book assumes that you’ve written code in another programming language, but
+doesn’t make any assumptions about which one. We’ve tried to make the material
+broadly accessible to those from a wide variety of programming backgrounds. We
+don’t spend a lot of time talking about what programming *is* or how to think
+about it. If you’re entirely new to programming, you would be better served by
+reading a book that specifically provides an introduction to programming.
+
+## How to Use This Book
+
+In general, this book assumes that you’re reading it in sequence from front to
+back. Later chapters build on concepts in earlier chapters, and earlier
+chapters might not delve into details on a particular topic but will revisit
+the topic in a later chapter.
+
+You’ll find two kinds of chapters in this book: concept chapters and project
+chapters. In concept chapters, you’ll learn about an aspect of Rust. In project
+chapters, we’ll build small programs together, applying what you’ve learned so
+far. Chapter 2, Chapter 12, and Chapter 20 are project chapters; the rest are
+concept chapters.
+
+**Chapter 1** explains how to install Rust, how to write a “Hello, world!â€
+program, and how to use Cargo, Rust’s package manager and build tool. **Chapter
+2** is a hands-on introduction to writing a program in Rust, having you build
+up a number-guessing game. Here, we cover concepts at a high level, and later
+chapters will provide additional detail. If you want to get your hands dirty
+right away, Chapter 2 is the place for that. **Chapter 3** covers Rust features
+that are similar to those of other programming languages, and in **Chapter 4**
+you’ll learn about Rust’s ownership system. If you’re a particularly meticulous
+learner who prefers to learn every detail before moving on to the next, you
+might want to skip Chapter 2 and go straight to Chapter 3, returning to Chapter
+2 when you’d like to work on a project applying the details you’ve learned.
+
+**Chapter 5** discusses structs and methods, and **Chapter 6** covers enums,
+`match` expressions, and the `if let` control flow construct. You’ll use
+structs and enums to make custom types in Rust.
+
+In **Chapter 7**, you’ll learn about Rust’s module system and about privacy
+rules for organizing your code and its public application programming interface
+(API). **Chapter 8** discusses some common collection data structures that the
+standard library provides, such as vectors, strings, and hash maps. **Chapter
+9** explores Rust’s error-handling philosophy and techniques.
+
+**Chapter 10** digs into generics, traits, and lifetimes, which give you the
+power to define code that applies to multiple types. **Chapter 11** is all
+about testing, which even with Rust’s safety guarantees is necessary to ensure
+your program’s logic is correct. In **Chapter 12**, we’ll build our own
+implementation of a subset of functionality from the `grep` command line tool
+that searches for text within files. For this, we’ll use many of the concepts
+we discussed in the previous chapters.
+
+**Chapter 13** explores closures and iterators: features of Rust that come from
+functional programming languages. In **Chapter 14**, we’ll examine Cargo in
+more depth and talk about best practices for sharing your libraries with
+others. **Chapter 15** discusses smart pointers that the standard library
+provides and the traits that enable their functionality.
+
+In **Chapter 16**, we’ll walk through different models of concurrent
+programming and talk about how Rust helps you program in multiple threads
+fearlessly. **Chapter 17** looks at how Rust idioms compare to object-oriented
+programming principles you might be familiar with.
+
+**Chapter 18** is a reference on patterns and pattern matching, which are
+powerful ways of expressing ideas throughout Rust programs. **Chapter 19**
+contains a smorgasbord of advanced topics of interest, including unsafe Rust,
+macros, and more about lifetimes, traits, types, functions, and closures.
+
+In **Chapter 20**, we’ll complete a project in which we’ll implement a
+low-level multithreaded web server!
+
+Finally, some appendices contain useful information about the language in a
+more reference-like format**. Appendix A** covers Rust’s keywords, **Appendix
+B** covers Rust’s operators and symbols, **Appendix C** covers derivable traits
+provided by the standard library, **Appendix D** covers some useful development
+tools, and **Appendix E** explains Rust editions.
+
+There is no wrong way to read this book: if you want to skip ahead, go for it!
+You might have to jump back to earlier chapters if you experience any
+confusion. But do whatever works for you.
+
+An important part of the process of learning Rust is learning how to read the
+error messages the compiler displays: these will guide you toward working code.
+As such, we’ll provide many examples that don’t compile along with the error
+message the compiler will show you in each situation. Know that if you enter
+and run a random example, it may not compile! Make sure you read the
+surrounding text to see whether the example you’re trying to run is meant to
+error. In most situations, we’ll lead you to the correct version of any code
+that doesn’t compile.
+
+## Resources and How to Contribute to This Book
+
+This book is open source. If you find an error, please don’t hesitate to file
+an issue or send a pull request on GitHub at
+*https://github.com/rust-lang/book*. Please see *CONTRIBUTING.md* at
+*https://github.com/rust-lang/book/blob/main/CONTRIBUTING.md* for more details.
+
+The source code for the examples in this book, errata, and other information
+are available at *https://www.nostarch.com/Rust2021*.
+
diff --git a/src/doc/book/nostarch/introduction.md b/src/doc/book/nostarch/introduction.md
index b3ff9b111..bcaed24c5 100644
--- a/src/doc/book/nostarch/introduction.md
+++ b/src/doc/book/nostarch/introduction.md
@@ -8,7 +8,7 @@ directory, so all fixes need to be made in `/src/`.
# Introduction
-Welcome to *The Rust Programming Language*, an introductory book about Rust.
+Welcome to *The Rust Programming Language,* an introductory book about Rust.
The Rust programming language helps you write faster, more reliable software.
High-level ergonomics and low-level control are often at odds in programming
language design; Rust challenges that conflict. Through balancing powerful
@@ -62,12 +62,6 @@ devices, audio and video analysis and transcoding, cryptocurrencies,
bioinformatics, search engines, Internet of Things applications, machine
learning, and even major parts of the Firefox web browser.
-<!-- with Rust adopted in a lot of really recognizable names, is it worth
-namedropping some companies that use Rust significantly? /LC -->
-<!-- No, I don't want to show favoritism, and there are lots of politics around
-the big companies using Rust that I don't want to get into. I would also worry
-about the list getting dated. /Carol -->
-
### Open Source Developers
Rust is for people who want to build the Rust programming language, community,
@@ -119,7 +113,7 @@ number guessing game. Here we cover concepts at a high level, and later
chapters will provide additional detail. If you want to get your hands dirty
right away, Chapter 2 is the place for that. Chapter 3 covers Rust features
that are similar to those of other programming languages, and in Chapter 4
-you'll learn about Rust’s ownership system. If you’re a particularly meticulous
+you’ll learn about Rust’s ownership system. If you’re a particularly meticulous
learner who prefers to learn every detail before moving on to the next, you
might want to skip Chapter 2 and go straight to Chapter 3, returning to Chapter
2 when you’d like to work on a project applying the details you’ve learned.
@@ -182,10 +176,11 @@ that doesn’t compile.
## Resources and How to Contribute to This Book
-This book is open source. If you find an error, please don't hesitate to file
+This book is open source. If you find an error, please don’t hesitate to file
an issue or send a pull request on GitHub at
*https://github.com/rust-lang/book/*. Please see *CONTRIBUTING.md* at
*https://github.com/rust-lang/book/blob/main/CONTRIBUTING.md* for more details.
The source code for the examples in this book, errata, and other information
are available at *https://www.nostarch.com/Rust2021/*.
+
diff --git a/src/doc/book/nostarch/preface.md b/src/doc/book/nostarch/preface.md
index 5ec239151..33b1a0fd8 100644
--- a/src/doc/book/nostarch/preface.md
+++ b/src/doc/book/nostarch/preface.md
@@ -1,22 +1,22 @@
-# Preface
+## Preface
This version of the text assumes you’re using Rust 1.62.0 (released 2022-06-30)
-or later with edition="2021" in *Cargo.toml* of all projects to use Rust 2021
-Edition idioms. See “Installation†on page 1 to install or update Rust, and see
-Appendix E for information on editions.
+or later with `edition="2021"` in *Cargo.toml* of all projects to use Rust 2021
+Edition idioms. See “Installation†on page 1 for instructions on installing or
+updating Rust, and see Appendix E for information on editions.
-The 2021 Edition of the Rust language includes a small number of improvements
-that make Rust more ergonomic and correct some inconsistencies. This rendition
-of the book has a number of improvements to address feedback:
+The 2021 Edition of the Rust language includes a number of improvements that
+make Rust more ergonomic and correct some inconsistencies. On top of a general
+update to reflect these improvements, this rendition of the book has a number
+of improvements to address specific feedback:
-• Chapter 7 contains a new quick reference section on organizing your code into
+* Chapter 7 contains a new quick reference section on organizing your code into
multiple files with modules.
-• Chapter 13 has new and improved closure examples that more clearly illustrate
+* Chapter 13 has new and improved closure examples that more clearly illustrate
captures, the `move` keyword, and the `Fn` traits.
-• We fixed a number of small errors and imprecise wording throughout the book.
+* We fixed a number of small errors and imprecise wording throughout the book.
Thank you to the readers who reported them!
-
-Note that any code in earlier renditions of this book that compiled will
+Note that any code from earlier renditions of this book that compiled will
continue to compile with the relevant edition in the project’s *Cargo.toml*,
even as you update the Rust compiler version you’re using. That’s Rust’s
backward compatibility guarantees at work!
diff --git a/src/doc/book/src/appendix-04-useful-development-tools.md b/src/doc/book/src/appendix-04-useful-development-tools.md
index b357f64e2..40b076153 100644
--- a/src/doc/book/src/appendix-04-useful-development-tools.md
+++ b/src/doc/book/src/appendix-04-useful-development-tools.md
@@ -130,14 +130,15 @@ fn main() {
Running `cargo clippy` on this project results in this error:
```text
-error: approximate value of `f{32, 64}::consts::PI` found. Consider using it directly
+error: approximate value of `f{32, 64}::consts::PI` found
--> src/main.rs:2:13
|
2 | let x = 3.1415;
| ^^^^^^
|
- = note: #[deny(clippy::approx_constant)] on by default
- = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/master/index.html#approx_constant
+ = note: `#[deny(clippy::approx_constant)]` on by default
+ = help: consider using the constant directly
+ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant
```
This error lets you know that Rust already has a more precise `PI` constant
@@ -171,9 +172,9 @@ communicate with each other. Different clients can use `rust-analyzer`, such as
[lsp]: http://langserver.org/
[vscode]: https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer
-Visit the `rust-analyzer` project’s [home page][rust-analyzer] for installation
-instructions, then install the language server support in your particular IDE.
-Your IDE will gain abilities such as autocompletion, jump to definition, and
-inline errors.
+Visit the `rust-analyzer` project’s [home page][rust-analyzer]<!-- ignore -->
+for installation instructions, then install the language server support in your
+particular IDE. Your IDE will gain abilities such as autocompletion, jump to
+definition, and inline errors.
[rust-analyzer]: https://rust-analyzer.github.io
diff --git a/src/doc/book/src/appendix-06-translation.md b/src/doc/book/src/appendix-06-translation.md
index 0bc6aabd9..2c5734354 100644
--- a/src/doc/book/src/appendix-06-translation.md
+++ b/src/doc/book/src/appendix-06-translation.md
@@ -24,7 +24,6 @@ For resources in languages other than English. Most are still in progress; see
- [Svenska](https://github.com/sebras/book)
- [Farsi](https://github.com/pomokhtari/rust-book-fa)
- [Deutsch](https://github.com/rust-lang-de/rustbook-de)
-- [Turkish](https://github.com/RustDili/dokuman/tree/master/ceviriler), [online](https://rustdili.github.io/)
- [हिंदी](https://github.com/venkatarun95/rust-book-hindi)
- [ไทย](https://github.com/rust-lang-th/book-th)
- [Danske](https://github.com/DanKHansen/book-dk)
diff --git a/src/doc/book/src/ch00-00-introduction.md b/src/doc/book/src/ch00-00-introduction.md
index ba7b9ea0e..9df8e6c88 100644
--- a/src/doc/book/src/ch00-00-introduction.md
+++ b/src/doc/book/src/ch00-00-introduction.md
@@ -24,8 +24,8 @@ the most important groups.
Rust is proving to be a productive tool for collaborating among large teams of
developers with varying levels of systems programming knowledge. Low-level code
-is prone to a variety of subtle bugs, which in most other languages can be
-caught only through extensive testing and careful code review by experienced
+is prone to various subtle bugs, which in most other languages can be caught
+only through extensive testing and careful code review by experienced
developers. In Rust, the compiler plays a gatekeeper role by refusing to
compile code with these elusive bugs, including concurrency bugs. By working
alongside the compiler, the team can spend their time focusing on the program’s
@@ -36,7 +36,8 @@ Rust also brings contemporary developer tools to the systems programming world:
* Cargo, the included dependency manager and build tool, makes adding,
compiling, and managing dependencies painless and consistent across the Rust
ecosystem.
-* Rustfmt ensures a consistent coding style across developers.
+* The Rustfmt formatting tool ensures a consistent coding style across
+ developers.
* The Rust Language Server powers Integrated Development Environment (IDE)
integration for code completion and inline error messages.
@@ -55,8 +56,8 @@ programming.
### Companies
Hundreds of companies, large and small, use Rust in production for a variety of
-tasks. Those tasks include command line tools, web services, DevOps tooling,
-embedded devices, audio and video analysis and transcoding, cryptocurrencies,
+tasks, including command line tools, web services, DevOps tooling, embedded
+devices, audio and video analysis and transcoding, cryptocurrencies,
bioinformatics, search engines, Internet of Things applications, machine
learning, and even major parts of the Firefox web browser.
@@ -69,13 +70,13 @@ language.
### People Who Value Speed and Stability
Rust is for people who crave speed and stability in a language. By speed, we
-mean the speed of the programs that you can create with Rust and the speed at
-which Rust lets you write them. The Rust compiler’s checks ensure stability
-through feature additions and refactoring. This is in contrast to the brittle
-legacy code in languages without these checks, which developers are often
-afraid to modify. By striving for zero-cost abstractions, higher-level features
-that compile to lower-level code as fast as code written manually, Rust
-endeavors to make safe code be fast code as well.
+mean both how quickly Rust code can run and the speed at which Rust lets you
+write programs. The Rust compiler’s checks ensure stability through feature
+additions and refactoring. This is in contrast to the brittle legacy code in
+languages without these checks, which developers are often afraid to modify. By
+striving for zero-cost abstractions, higher-level features that compile to
+lower-level code as fast as code written manually, Rust endeavors to make safe
+code be fast code as well.
The Rust language hopes to support many other users as well; those mentioned
here are merely some of the biggest stakeholders. Overall, Rust’s greatest
@@ -96,8 +97,8 @@ reading a book that specifically provides an introduction to programming.
In general, this book assumes that you’re reading it in sequence from front to
back. Later chapters build on concepts in earlier chapters, and earlier
-chapters might not delve into details on a topic; we typically revisit the
-topic in a later chapter.
+chapters might not delve into details on a particular topic but will revisit
+the topic in a later chapter.
You’ll find two kinds of chapters in this book: concept chapters and project
chapters. In concept chapters, you’ll learn about an aspect of Rust. In project
@@ -106,15 +107,15 @@ far. Chapters 2, 12, and 20 are project chapters; the rest are concept chapters.
Chapter 1 explains how to install Rust, how to write a “Hello, world!†program,
and how to use Cargo, Rust’s package manager and build tool. Chapter 2 is a
-hands-on introduction to the Rust language. Here we cover concepts at a high
-level, and later chapters will provide additional detail. If you want to get
-your hands dirty right away, Chapter 2 is the place for that. At first, you
-might even want to skip Chapter 3, which covers Rust features similar to those
-of other programming languages, and head straight to Chapter 4 to learn about
-Rust’s ownership system. However, if you’re a particularly meticulous learner
-who prefers to learn every detail before moving on to the next, you might want
-to skip Chapter 2 and go straight to Chapter 3, returning to Chapter 2 when
-you’d like to work on a project applying the details you’ve learned.
+hands-on introduction to writing a program in Rust, having you build up a
+number guessing game. Here we cover concepts at a high level, and later
+chapters will provide additional detail. If you want to get your hands dirty
+right away, Chapter 2 is the place for that. Chapter 3 covers Rust features
+that are similar to those of other programming languages, and in Chapter 4
+you’ll learn about Rust’s ownership system. If you’re a particularly meticulous
+learner who prefers to learn every detail before moving on to the next, you
+might want to skip Chapter 2 and go straight to Chapter 3, returning to Chapter
+2 when you’d like to work on a project applying the details you’ve learned.
Chapter 5 discusses structs and methods, and Chapter 6 covers enums, `match`
expressions, and the `if let` control flow construct. You’ll use structs and
diff --git a/src/doc/book/src/ch01-01-installation.md b/src/doc/book/src/ch01-01-installation.md
index 47664eb4f..fa9617ad9 100644
--- a/src/doc/book/src/ch01-01-installation.md
+++ b/src/doc/book/src/ch01-01-installation.md
@@ -10,18 +10,18 @@ an internet connection for the download.
The following steps install the latest stable version of the Rust compiler.
Rust’s stability guarantees ensure that all the examples in the book that
compile will continue to compile with newer Rust versions. The output might
-differ slightly between versions, because Rust often improves error messages
-and warnings. In other words, any newer, stable version of Rust you install
-using these steps should work as expected with the content of this book.
+differ slightly between versions because Rust often improves error messages and
+warnings. In other words, any newer, stable version of Rust you install using
+these steps should work as expected with the content of this book.
> ### Command Line Notation
>
> In this chapter and throughout the book, we’ll show some commands used in the
> terminal. Lines that you should enter in a terminal all start with `$`. You
-> don’t need to type in the `$` character; it’s the command line prompt shown
-> to indicate the start of each command. Lines that don’t start with `$`
-> typically show the output of the previous command. Additionally,
-> PowerShell-specific examples will use `>` rather than `$`.
+> don’t need to type the `$` character; it’s the command line prompt shown to
+> indicate the start of each command. Lines that don’t start with `$` typically
+> show the output of the previous command. Additionally, PowerShell-specific
+> examples will use `>` rather than `$`.
### Installing `rustup` on Linux or macOS
@@ -60,13 +60,14 @@ the `build-essential` package.
On Windows, go to [https://www.rust-lang.org/tools/install][install] and follow
the instructions for installing Rust. At some point in the installation, you’ll
receive a message explaining that you’ll also need the MSVC build tools for
-Visual Studio 2013 or later. To acquire the build tools, you’ll need to install
-[Visual Studio 2022][visualstudio]. When asked which workloads to install,
-include:
+Visual Studio 2013 or later.
-- “Desktop Development with C++â€
-- The Windows 10 or 11 SDK
-- The English language pack component, along with any other language pack of
+To acquire the build tools, you’ll need to install [Visual Studio
+2022][visualstudio]. When asked which workloads to install, include:
+
+* “Desktop Development with C++â€
+* The Windows 10 or 11 SDK
+* The English language pack component, along with any other language pack of
your choosing
The rest of this book uses commands that work in both *cmd.exe* and PowerShell.
@@ -82,15 +83,15 @@ $ rustc --version
```
You should see the version number, commit hash, and commit date for the latest
-stable version that has been released in the following format:
+stable version that has been released, in the following format:
```text
rustc x.y.z (abcabcabc yyyy-mm-dd)
```
If you see this information, you have installed Rust successfully! If you don’t
-see this information, check that Rust is in your `%PATH%`
-system variable as follows.
+see this information, check that Rust is in your `%PATH%` system variable as
+follows.
In Windows CMD, use:
@@ -100,27 +101,24 @@ In Windows CMD, use:
In PowerShell, use:
-```console
+```powershell
> echo $env:Path
```
In Linux and macOS, use:
```console
-echo $PATH
+$ echo $PATH
```
If that’s all correct and Rust still isn’t working, there are a number of
-places you can get help. The easiest is the #beginners channel on [the official
-Rust Discord][discord]. There, you can chat with other Rustaceans (a silly
-nickname we call ourselves) who can help you out. Other great resources include
-[the Users forum][users] and [Stack Overflow][stackoverflow].
+places you can get help. Find out how to get in touch with other Rustaceans (a
+silly nickname we call ourselves) on [the community page][community].
### Updating and Uninstalling
-Once Rust is installed via `rustup`, when a new version of Rust is released,
-updating to the latest version is easy. From your shell, run the following
-update script:
+Once Rust is installed via `rustup`, updating to a newly released version is
+easy. From your shell, run the following update script:
```console
$ rustup update
@@ -135,9 +133,9 @@ $ rustup self uninstall
### Local Documentation
-The installation of Rust also includes a local copy of the documentation, so
-you can read it offline. Run `rustup doc` to open the local documentation in
-your browser.
+The installation of Rust also includes a local copy of the documentation so
+that you can read it offline. Run `rustup doc` to open the local documentation
+in your browser.
Any time a type or function is provided by the standard library and you’re not
sure what it does or how to use it, use the application programming interface
@@ -146,6 +144,4 @@ sure what it does or how to use it, use the application programming interface
[otherinstall]: https://forge.rust-lang.org/infra/other-installation-methods.html
[install]: https://www.rust-lang.org/tools/install
[visualstudio]: https://visualstudio.microsoft.com/downloads/
-[discord]: https://discord.gg/rust-lang
-[users]: https://users.rust-lang.org/
-[stackoverflow]: https://stackoverflow.com/questions/tagged/rust
+[community]: https://www.rust-lang.org/community
diff --git a/src/doc/book/src/ch01-02-hello-world.md b/src/doc/book/src/ch01-02-hello-world.md
index ce9b8f55b..8d8d754d7 100644
--- a/src/doc/book/src/ch01-02-hello-world.md
+++ b/src/doc/book/src/ch01-02-hello-world.md
@@ -1,8 +1,8 @@
## Hello, World!
-Now that you’ve installed Rust, let’s write your first Rust program. It’s
-traditional when learning a new language to write a little program that prints
-the text `Hello, world!` to the screen, so we’ll do the same here!
+Now that you’ve installed Rust, it’s time to write your first Rust program.
+It’s traditional when learning a new language to write a little program that
+prints the text `Hello, world!` to the screen, so we’ll do the same here!
> Note: This book assumes basic familiarity with the command line. Rust makes
> no specific demands about your editing or tooling or where your code lives, so
@@ -10,7 +10,7 @@ the text `Hello, world!` to the screen, so we’ll do the same here!
> the command line, feel free to use your favorite IDE. Many IDEs now have some
> degree of Rust support; check the IDE’s documentation for details. The Rust
> team has been focusing on enabling great IDE support via `rust-analyzer`. See
-> [Appendix D][devtools]<!-- ignore --> for more details!
+> [Appendix D][devtools]<!-- ignore --> for more details.
### Creating a Project Directory
@@ -109,7 +109,7 @@ line as the function declaration, adding one space in between.
> use an automatic formatter tool called `rustfmt` to format your code in a
> particular style (more on `rustfmt` in
> [Appendix D][devtools]<!-- ignore -->). The Rust team has included this tool
-> with the standard Rust distribution, like `rustc`, so it should already be
+> with the standard Rust distribution, as `rustc` is, so it should already be
> installed on your computer!
The body of the `main` function holds the following code:
@@ -126,7 +126,7 @@ First, Rust style is to indent with four spaces, not a tab.
Second, `println!` calls a Rust macro. If it had called a function instead, it
would be entered as `println` (without the `!`). We’ll discuss Rust macros in
more detail in Chapter 19. For now, you just need to know that using a `!`
-means that you’re calling a macro instead of a normal function, and that macros
+means that you’re calling a macro instead of a normal function and that macros
don’t always follow the same rules as functions.
Third, you see the `"Hello, world!"` string. We pass this string as an argument
@@ -153,16 +153,16 @@ If you have a C or C++ background, you’ll notice that this is similar to `gcc`
or `clang`. After compiling successfully, Rust outputs a binary executable.
On Linux, macOS, and PowerShell on Windows, you can see the executable by
-entering the `ls` command in your shell. On Linux and macOS, you’ll see two
-files. With PowerShell on Windows, you’ll see the same three files that you
-would see using CMD.
+entering the `ls` command in your shell:
```console
$ ls
main main.rs
```
-With CMD on Windows, you would enter the following:
+On Linux and macOS, you’ll see two files. With PowerShell on Windows, you’ll
+see the same three files that you would see using CMD. With CMD on Windows, you
+would enter the following:
```cmd
> dir /B %= the /B option says to only show the file names =%
diff --git a/src/doc/book/src/ch01-03-hello-cargo.md b/src/doc/book/src/ch01-03-hello-cargo.md
index 9979e76dd..42cd0889c 100644
--- a/src/doc/book/src/ch01-03-hello-cargo.md
+++ b/src/doc/book/src/ch01-03-hello-cargo.md
@@ -17,7 +17,7 @@ assumes that you’re using Cargo too. Cargo comes installed with Rust if you
used the official installers discussed in the
[“Installationâ€][installation]<!-- ignore --> section. If you installed Rust
through some other means, check whether Cargo is installed by entering the
-following into your terminal:
+following in your terminal:
```console
$ cargo --version
@@ -30,9 +30,9 @@ determine how to install Cargo separately.
### Creating a Project with Cargo
Let’s create a new project using Cargo and look at how it differs from our
-original “Hello, world!†project. Navigate back to your *projects* directory (or
-wherever you decided to store your code). Then, on any operating system, run
-the following:
+original “Hello, world!†project. Navigate back to your *projects* directory
+(or wherever you decided to store your code). Then, on any operating system,
+run the following:
```console
$ cargo new hello_cargo
@@ -74,8 +74,8 @@ edition = "2021"
<span class="caption">Listing 1-2: Contents of *Cargo.toml* generated by `cargo
new`</span>
-This file is in the [*TOML*](https://toml.io)<!-- ignore --> (*Tom’s Obvious,
-Minimal Language*) format, which is Cargo’s configuration format.
+This file is in the [*TOML*][toml]<!-- ignore --> (*Tom’s Obvious, Minimal
+Language*) format, which is Cargo’s configuration format.
The first line, `[package]`, is a section heading that indicates that the
following statements are configuring a package. As we add more information to
@@ -102,7 +102,7 @@ fn main() {
Cargo has generated a “Hello, world!†program for you, just like the one we
wrote in Listing 1-1! So far, the differences between our project and the
-project Cargo generated are that Cargo placed the code in the *src* directory,
+project Cargo generated are that Cargo placed the code in the *src* directory
and we have a *Cargo.toml* configuration file in the top directory.
Cargo expects your source files to live inside the *src* directory. The
@@ -147,7 +147,7 @@ manages its contents for you.
We just built a project with `cargo build` and ran it with
`./target/debug/hello_cargo`, but we can also use `cargo run` to compile the
-code and then run the resulting executable all in one command:
+code and then run the resultant executable all in one command:
```console
$ cargo run
@@ -184,7 +184,7 @@ $ cargo check
```
Why would you not want an executable? Often, `cargo check` is much faster than
-`cargo build`, because it skips the step of producing an executable. If you’re
+`cargo build` because it skips the step of producing an executable. If you’re
continually checking your work while writing the code, using `cargo check` will
speed up the process of letting you know if your project is still compiling! As
such, many Rustaceans run `cargo check` periodically as they write their
@@ -236,9 +236,7 @@ $ cd someproject
$ cargo build
```
-For more information about Cargo, check out [its documentation].
-
-[its documentation]: https://doc.rust-lang.org/cargo/
+For more information about Cargo, check out [its documentation][cargo].
## Summary
@@ -257,4 +255,6 @@ If you would rather start by learning how common programming concepts work in
Rust, see Chapter 3 and then return to Chapter 2.
[installation]: ch01-01-installation.html#installation
+[toml]: https://toml.io
[appendix-e]: appendix-05-editions.html
+[cargo]: https://doc.rust-lang.org/cargo/
diff --git a/src/doc/book/src/ch02-00-guessing-game-tutorial.md b/src/doc/book/src/ch02-00-guessing-game-tutorial.md
index bffbc0501..4dac23764 100644
--- a/src/doc/book/src/ch02-00-guessing-game-tutorial.md
+++ b/src/doc/book/src/ch02-00-guessing-game-tutorial.md
@@ -3,8 +3,8 @@
Let’s jump into Rust by working through a hands-on project together! This
chapter introduces you to a few common Rust concepts by showing you how to use
them in a real program. You’ll learn about `let`, `match`, methods, associated
-functions, using external crates, and more! In the following chapters, we’ll
-explore these ideas in more detail. In this chapter, you’ll practice the
+functions, external crates, and more! In the following chapters, we’ll explore
+these ideas in more detail. In this chapter, you’ll just practice the
fundamentals.
We’ll implement a classic beginner programming problem: a guessing game. Here’s
@@ -34,7 +34,8 @@ cd listings/ch02-guessing-game-tutorial
rm -rf no-listing-01-cargo-new
cargo new no-listing-01-cargo-new --name guessing_game
cd no-listing-01-cargo-new
-cargo run
+cargo run > output.txt 2>&1
+cd ../../..
-->
<span class="filename">Filename: Cargo.toml</span>
@@ -83,16 +84,16 @@ prints it</span>
This code contains a lot of information, so let’s go over it line by line. To
obtain user input and then print the result as output, we need to bring the
-`io` input/output library into scope. The `io` library comes from the
-standard library, known as `std`:
+`io` input/output library into scope. The `io` library comes from the standard
+library, known as `std`:
```rust,ignore
{{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs:io}}
```
-By default, Rust has a set of items defined in the standard library that it brings
-into the scope of every program. This set is called the *prelude*, and you can
-see everything in it [in the standard library documentation][prelude].
+By default, Rust has a set of items defined in the standard library that it
+brings into the scope of every program. This set is called the *prelude*, and
+you can see everything in it [in the standard library documentation][prelude].
If a type you want to use isn’t in the prelude, you have to bring that type
into scope explicitly with a `use` statement. Using the `std::io` library
@@ -106,8 +107,8 @@ program:
{{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs:main}}
```
-The `fn` syntax declares a new function, the parentheses, `()`, indicate there
-are no parameters, and the curly bracket, `{`, starts the body of the function.
+The `fn` syntax declares a new function; the parentheses, `()`, indicate there
+are no parameters; and the curly bracket, `{`, starts the body of the function.
As you also learned in Chapter 1, `println!` is a macro that prints a string to
the screen:
@@ -136,7 +137,7 @@ let apples = 5;
This line creates a new variable named `apples` and binds it to the value 5. In
Rust, variables are immutable by default, meaning once we give the variable a
-value, the value won't change. We’ll be discussing this concept in detail in
+value, the value won’t change. We’ll be discussing this concept in detail in
the [“Variables and Mutabilityâ€][variables-and-mutability]<!-- ignore -->
section in Chapter 3. To make a variable mutable, we add `mut` before the
variable name:
@@ -152,7 +153,7 @@ let mut bananas = 5; // mutable
Returning to the guessing game program, you now know that `let mut guess` will
introduce a mutable variable named `guess`. The equal sign (`=`) tells Rust we
-want to bind something to the variable now. On the right of the equals sign is
+want to bind something to the variable now. On the right of the equal sign is
the value that `guess` is bound to, which is the result of calling
`String::new`, a function that returns a new instance of a `String`.
[`String`][string]<!-- ignore --> is a string type provided by the standard
@@ -161,7 +162,7 @@ library that is a growable, UTF-8 encoded bit of text.
The `::` syntax in the `::new` line indicates that `new` is an associated
function of the `String` type. An *associated function* is a function that’s
implemented on a type, in this case `String`. This `new` function creates a
-new, empty string. You’ll find a `new` function on many types, because it’s a
+new, empty string. You’ll find a `new` function on many types because it’s a
common name for a function that makes a new value of some kind.
In full, the `let mut guess = String::new();` line has created a mutable
@@ -178,7 +179,7 @@ input:
{{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs:read}}
```
-If we hadn’t imported the `io` library with `use std::io` at the beginning of
+If we hadn’t imported the `io` library with `use std::io;` at the beginning of
the program, we could still use the function by writing this function call as
`std::io::stdin`. The `stdin` function returns an instance of
[`std::io::Stdin`][iostdin]<!-- ignore -->, which is a type that represents a
@@ -198,12 +199,15 @@ let multiple parts of your code access one piece of data without needing to
copy that data into memory multiple times. References are a complex feature,
and one of Rust’s major advantages is how safe and easy it is to use
references. You don’t need to know a lot of those details to finish this
-program. For now, all you need to know is that like variables, references are
+program. For now, all you need to know is that, like variables, references are
immutable by default. Hence, you need to write `&mut guess` rather than
`&guess` to make it mutable. (Chapter 4 will explain references more
thoroughly.)
-### Handling Potential Failure with the `Result` Type
+<!-- Old heading. Do not remove or links may break. -->
+<a id="handling-potential-failure-with-the-result-type"></a>
+
+### Handling Potential Failure with `Result`
We’re still working on this line of code. We’re now discussing a third line of
text, but note that it’s still part of a single logical line of code. The next
@@ -230,10 +234,10 @@ ignore --> is an [*enumeration*][enums]<!-- ignore -->, often called an *enum*,
which is a type that can be in one of multiple possible states. We call each
possible state a *variant*.
-Chapter 6 will cover enums in more detail. The purpose of these `Result` types
-is to encode error-handling information.
+[Chapter 6][enums]<!-- ignore --> will cover enums in more detail. The purpose
+of these `Result` types is to encode error-handling information.
-`Result`'s variants are `Ok` and `Err`. The `Ok` variant indicates the
+`Result`’s variants are `Ok` and `Err`. The `Ok` variant indicates the
operation was successful, and inside `Ok` is the successfully generated value.
The `Err` variant means the operation failed, and `Err` contains information
about how or why the operation failed.
@@ -257,9 +261,9 @@ If you don’t call `expect`, the program will compile, but you’ll get a warni
Rust warns that you haven’t used the `Result` value returned from `read_line`,
indicating that the program hasn’t handled a possible error.
-The right way to suppress the warning is to actually write error handling, but
-in our case we just want to crash this program when a problem occurs, so we can
-use `expect`. You’ll learn about recovering from errors in [Chapter
+The right way to suppress the warning is to actually write error-handling code,
+but in our case we just want to crash this program when a problem occurs, so we
+can use `expect`. You’ll learn about recovering from errors in [Chapter
9][recover]<!-- ignore -->.
### Printing Values with `println!` Placeholders
@@ -273,19 +277,21 @@ the code so far:
This line prints the string that now contains the user’s input. The `{}` set of
curly brackets is a placeholder: think of `{}` as little crab pincers that hold
-a value in place. You can print more than one value using curly brackets: the
-first set of curly brackets holds the first value listed after the format
-string, the second set holds the second value, and so on. Printing multiple
-values in one call to `println!` would look like this:
+a value in place. When printing the value of a variable, the variable name can
+go inside the curly brackets. When printing the result of evaluating an
+expression, place empty curly brackets in the format string, then follow the
+format string with a comma-separated list of expressions to print in each empty
+curly bracket placeholder in the same order. Printing a variable and the result
+of an expression in one call to `println!` would look like this:
```rust
let x = 5;
let y = 10;
-println!("x = {} and y = {}", x, y);
+println!("x = {x} and y + 2 = {}", y + 2);
```
-This code would print `x = 5 and y = 10`.
+This code would print `x = 5 and y = 12`.
### Testing the First Part
@@ -324,15 +330,15 @@ said functionality.
Remember that a crate is a collection of Rust source code files. The project
we’ve been building is a *binary crate*, which is an executable. The `rand`
-crate is a *library crate*, which contains code intended to be used in other
-programs and can't be executed on its own.
+crate is a *library crate*, which contains code that is intended to be used in
+other programs and can’t be executed on its own.
Cargo’s coordination of external crates is where Cargo really shines. Before we
can write code that uses `rand`, we need to modify the *Cargo.toml* file to
include the `rand` crate as a dependency. Open that file now and add the
-following line to the bottom beneath the `[dependencies]` section header that
+following line to the bottom, beneath the `[dependencies]` section header that
Cargo created for you. Be sure to specify `rand` exactly as we have here, with
-this version number, or the code examples in this tutorial may not work.
+this version number, or the code examples in this tutorial may not work:
<!-- When updating the version of `rand` used, also update the version of
`rand` used in these files so they all match:
@@ -343,50 +349,50 @@ this version number, or the code examples in this tutorial may not work.
<span class="filename">Filename: Cargo.toml</span>
```toml
-{{#include ../listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml:9:}}
+{{#include ../listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml:8:}}
```
In the *Cargo.toml* file, everything that follows a header is part of that
section that continues until another section starts. In `[dependencies]` you
tell Cargo which external crates your project depends on and which versions of
those crates you require. In this case, we specify the `rand` crate with the
-semantic version specifier `0.8.3`. Cargo understands [Semantic
+semantic version specifier `0.8.5`. Cargo understands [Semantic
Versioning][semver]<!-- ignore --> (sometimes called *SemVer*), which is a
-standard for writing version numbers. The number `0.8.3` is actually shorthand
-for `^0.8.3`, which means any version that is at least `0.8.3` but below
-`0.9.0`.
+standard for writing version numbers. The specifier `0.8.5` is actually
+shorthand for `^0.8.5`, which means any version that is at least 0.8.5 but
+below 0.9.0.
Cargo considers these versions to have public APIs compatible with version
-`0.8.3`, and this specification ensures you’ll get the latest patch release
-that will still compile with the code in this chapter. Any version `0.9.0` or
-greater is not guaranteed to have the same API as what the following examples
-use.
+0.8.5, and this specification ensures you’ll get the latest patch release that
+will still compile with the code in this chapter. Any version 0.9.0 or greater
+is not guaranteed to have the same API as what the following examples use.
Now, without changing any of the code, let’s build the project, as shown in
Listing 2-2.
<!-- manual-regeneration
cd listings/ch02-guessing-game-tutorial/listing-02-02/
+rm Cargo.lock
cargo clean
cargo build -->
```console
$ cargo build
Updating crates.io index
- Downloaded rand v0.8.3
- Downloaded libc v0.2.86
- Downloaded getrandom v0.2.2
+ Downloaded rand v0.8.5
+ Downloaded libc v0.2.127
+ Downloaded getrandom v0.2.7
Downloaded cfg-if v1.0.0
- Downloaded ppv-lite86 v0.2.10
- Downloaded rand_chacha v0.3.0
- Downloaded rand_core v0.6.2
- Compiling rand_core v0.6.2
- Compiling libc v0.2.86
- Compiling getrandom v0.2.2
+ Downloaded ppv-lite86 v0.2.16
+ Downloaded rand_chacha v0.3.1
+ Downloaded rand_core v0.6.3
+ Compiling libc v0.2.127
+ Compiling getrandom v0.2.7
Compiling cfg-if v1.0.0
- Compiling ppv-lite86 v0.2.10
- Compiling rand_chacha v0.3.0
- Compiling rand v0.8.3
+ Compiling ppv-lite86 v0.2.16
+ Compiling rand_core v0.6.3
+ Compiling rand_chacha v0.3.1
+ Compiling rand v0.8.5
Compiling guessing_game v0.1.0 (file:///projects/guessing_game)
Finished dev [unoptimized + debuginfo] target(s) in 2.53s
```
@@ -395,8 +401,8 @@ $ cargo build
adding the rand crate as a dependency</span>
You may see different version numbers (but they will all be compatible with the
-code, thanks to SemVer!), different lines (depending on the operating system),
-and the lines may be in a different order.
+code, thanks to SemVer!) and different lines (depending on the operating
+system), and the lines may be in a different order.
When we include an external dependency, Cargo fetches the latest versions of
everything that dependency needs from the *registry*, which is a copy of data
@@ -416,8 +422,8 @@ about them in your *Cargo.toml* file. Cargo also knows that you haven’t change
anything about your code, so it doesn’t recompile that either. With nothing to
do, it simply exits.
-If you open up the *src/main.rs* file, make a trivial change, and then save it
-and build again, you’ll only see two lines of output:
+If you open the *src/main.rs* file, make a trivial change, and then save it and
+build again, you’ll only see two lines of output:
<!-- manual-regeneration
cd listings/ch02-guessing-game-tutorial/listing-02-02/
@@ -430,7 +436,7 @@ $ cargo build
Finished dev [unoptimized + debuginfo] target(s) in 2.53 secs
```
-These lines show Cargo only updates the build with your tiny change to the
+These lines show that Cargo only updates the build with your tiny change to the
*src/main.rs* file. Your dependencies haven’t changed, so Cargo knows it can
reuse what it has already downloaded and compiled for those.
@@ -439,21 +445,21 @@ reuse what it has already downloaded and compiled for those.
Cargo has a mechanism that ensures you can rebuild the same artifact every time
you or anyone else builds your code: Cargo will use only the versions of the
dependencies you specified until you indicate otherwise. For example, say that
-next week version 0.8.4 of the `rand` crate comes out, and that version
+next week version 0.8.6 of the `rand` crate comes out, and that version
contains an important bug fix, but it also contains a regression that will
break your code. To handle this, Rust creates the *Cargo.lock* file the first
time you run `cargo build`, so we now have this in the *guessing_game*
directory.
-When you build a project for the first time, Cargo figures out all the
-versions of the dependencies that fit the criteria and then writes them to
-the *Cargo.lock* file. When you build your project in the future, Cargo will
-see that the *Cargo.lock* file exists and use the versions specified there
+When you build a project for the first time, Cargo figures out all the versions
+of the dependencies that fit the criteria and then writes them to the
+*Cargo.lock* file. When you build your project in the future, Cargo will see
+that the *Cargo.lock* file exists and will use the versions specified there
rather than doing all the work of figuring out versions again. This lets you
have a reproducible build automatically. In other words, your project will
-remain at `0.8.3` until you explicitly upgrade, thanks to the *Cargo.lock*
-file. Because the *Cargo.lock* file is important for reproducible builds, it's
-often checked into source control with the rest of the code in your project.
+remain at 0.8.5 until you explicitly upgrade, thanks to the *Cargo.lock* file.
+Because the *Cargo.lock* file is important for reproducible builds, it’s often
+checked into source control with the rest of the code in your project.
#### Updating a Crate to Get a New Version
@@ -461,9 +467,9 @@ When you *do* want to update a crate, Cargo provides the command `update`,
which will ignore the *Cargo.lock* file and figure out all the latest versions
that fit your specifications in *Cargo.toml*. Cargo will then write those
versions to the *Cargo.lock* file. Otherwise, by default, Cargo will only look
-for versions greater than `0.8.3` and less than `0.9.0`. If the `rand` crate
-has released the two new versions `0.8.4` and `0.9.0` you would see the
-following if you ran `cargo update`:
+for versions greater than 0.8.5 and less than 0.9.0. If the `rand` crate has
+released the two new versions 0.8.6 and 0.9.0, you would see the following if
+you ran `cargo update`:
<!-- manual-regeneration
cd listings/ch02-guessing-game-tutorial/listing-02-02/
@@ -474,14 +480,13 @@ as a guide to creating the hypothetical output shown here -->
```console
$ cargo update
Updating crates.io index
- Updating rand v0.8.3 -> v0.8.4
+ Updating rand v0.8.5 -> v0.8.6
```
-Cargo ignores the `0.9.0` release. At this point, you would also notice a
-change in your *Cargo.lock* file noting that the version of the `rand` crate
-you are now using is `0.8.4`. To use `rand` version `0.9.0` or any version in
-the `0.9.x` series, you’d have to update the *Cargo.toml* file to look like
-this instead:
+Cargo ignores the 0.9.0 release. At this point, you would also notice a change
+in your *Cargo.lock* file noting that the version of the `rand` crate you are
+now using is 0.8.6. To use `rand` version 0.9.0 or any version in the 0.9.*x*
+series, you’d have to update the *Cargo.toml* file to look like this instead:
```toml
[dependencies]
@@ -493,7 +498,7 @@ available and reevaluate your `rand` requirements according to the new version
you have specified.
There’s a lot more to say about [Cargo][doccargo]<!-- ignore --> and [its
-ecosystem][doccratesio]<!-- ignore --> which we’ll discuss in Chapter 14, but
+ecosystem][doccratesio]<!-- ignore -->, which we’ll discuss in Chapter 14, but
for now, that’s all you need to know. Cargo makes it very easy to reuse
libraries, so Rustaceans are able to write smaller projects that are assembled
from a number of packages.
@@ -512,16 +517,16 @@ update *src/main.rs*, as shown in Listing 2-3.
<span class="caption">Listing 2-3: Adding code to generate a random
number</span>
-First, we add the line `use rand::Rng`. The `Rng` trait defines methods that
+First we add the line `use rand::Rng;`. The `Rng` trait defines methods that
random number generators implement, and this trait must be in scope for us to
use those methods. Chapter 10 will cover traits in detail.
Next, we’re adding two lines in the middle. In the first line, we call the
`rand::thread_rng` function that gives us the particular random number
-generator that we’re going to use: one that is local to the current thread of
-execution and seeded by the operating system. Then we call the `gen_range`
+generator we’re going to use: one that is local to the current thread of
+execution and is seeded by the operating system. Then we call the `gen_range`
method on the random number generator. This method is defined by the `Rng`
-trait that we brought into scope with the `use rand::Rng` statement. The
+trait that we brought into scope with the `use rand::Rng;` statement. The
`gen_range` method takes a range expression as an argument and generates a
random number in the range. The kind of range expression we’re using here takes
the form `start..=end` and is inclusive on the lower and upper bounds, so we
@@ -530,7 +535,7 @@ need to specify `1..=100` to request a number between 1 and 100.
> Note: You won’t just know which traits to use and which methods and functions
> to call from a crate, so each crate has documentation with instructions for
> using it. Another neat feature of Cargo is that running the `cargo doc
-> --open` command will build documentation provided by all of your dependencies
+> --open` command will build documentation provided by all your dependencies
> locally and open it in your browser. If you’re interested in other
> functionality in the `rand` crate, for example, run `cargo doc --open` and
> click `rand` in the sidebar on the left.
@@ -577,8 +582,8 @@ You should get different random numbers, and they should all be numbers between
## Comparing the Guess to the Secret Number
Now that we have user input and a random number, we can compare them. That step
-is shown in Listing 2-4. Note that this code won’t compile quite yet, as we
-will explain.
+is shown in Listing 2-4. Note that this code won’t compile just yet, as we will
+explain.
<span class="filename">Filename: src/main.rs</span>
@@ -597,7 +602,7 @@ the three outcomes that are possible when you compare two values.
Then we add five new lines at the bottom that use the `Ordering` type. The
`cmp` method compares two values and can be called on anything that can be
compared. It takes a reference to whatever you want to compare with: here it’s
-comparing the `guess` to the `secret_number`. Then it returns a variant of the
+comparing `guess` to `secret_number`. Then it returns a variant of the
`Ordering` enum we brought into scope with the `use` statement. We use a
[`match`][match]<!-- ignore --> expression to decide what to do next based on
which variant of `Ordering` was returned from the call to `cmp` with the values
@@ -607,14 +612,16 @@ A `match` expression is made up of *arms*. An arm consists of a *pattern* to
match against, and the code that should be run if the value given to `match`
fits that arm’s pattern. Rust takes the value given to `match` and looks
through each arm’s pattern in turn. Patterns and the `match` construct are
-powerful Rust features that let you express a variety of situations your code
-might encounter and make sure that you handle them all. These features will be
+powerful Rust features: they let you express a variety of situations your code
+might encounter and they make sure you handle them all. These features will be
covered in detail in Chapter 6 and Chapter 18, respectively.
Let’s walk through an example with the `match` expression we use here. Say that
the user has guessed 50 and the randomly generated secret number this time is
-38. When the code compares 50 to 38, the `cmp` method will return
-`Ordering::Greater`, because 50 is greater than 38. The `match` expression gets
+38.
+
+When the code compares 50 to 38, the `cmp` method will return
+`Ordering::Greater` because 50 is greater than 38. The `match` expression gets
the `Ordering::Greater` value and starts checking each arm’s pattern. It looks
at the first arm’s pattern, `Ordering::Less`, and sees that the value
`Ordering::Greater` does not match `Ordering::Less`, so it ignores the code in
@@ -626,6 +633,11 @@ arm in this scenario.
However, the code in Listing 2-4 won’t compile yet. Let’s try it:
+<!--
+The error numbers in this output should be that of the code **WITHOUT** the
+anchor or snip comments
+-->
+
```console
{{#include ../listings/ch02-guessing-game-tutorial/listing-02-04/output.txt}}
```
@@ -642,8 +654,8 @@ elsewhere that would cause Rust to infer a different numerical type. The reason
for the error is that Rust cannot compare a string and a number type.
Ultimately, we want to convert the `String` the program reads as input into a
-real number type so we can compare it numerically to the secret number. We do so
-by adding this line to the `main` function body:
+real number type so we can compare it numerically to the secret number. We do
+so by adding this line to the `main` function body:
<span class="filename">Filename: src/main.rs</span>
@@ -658,12 +670,12 @@ let guess: u32 = guess.trim().parse().expect("Please type a number!");
```
We create a variable named `guess`. But wait, doesn’t the program already have
-a variable named `guess`? It does, but helpfully Rust allows us to *shadow* the
-previous value of `guess` with a new one. Shadowing lets us reuse the `guess`
+a variable named `guess`? It does, but helpfully Rust allows us to shadow the
+previous value of `guess` with a new one. *Shadowing* lets us reuse the `guess`
variable name rather than forcing us to create two unique variables, such as
-`guess_str` and `guess` for example. We’ll cover this in more detail in Chapter
-3, but for now know that this feature is often used when you want to convert a
-value from one type to another type.
+`guess_str` and `guess`, for example. We’ll cover this in more detail in
+[Chapter 3][shadowing]<!-- ignore -->, but for now, know that this feature is
+often used when you want to convert a value from one type to another type.
We bind this new variable to the expression `guess.trim().parse()`. The `guess`
in the expression refers to the original `guess` variable that contained the
@@ -674,9 +686,9 @@ string to the `u32`, which can only contain numerical data. The user must press
guess, which adds a newline character to the string. For example, if the user
types <span class="keystroke">5</span> and presses <span
class="keystroke">enter</span>, `guess` looks like this: `5\n`. The `\n`
-represents “newlineâ€. (On Windows, pressing <span
+represents “newline.†(On Windows, pressing <span
class="keystroke">enter</span> results in a carriage return and a newline,
-`\r\n`). The `trim` method eliminates `\n` or `\r\n`, resulting in just `5`.
+`\r\n`.) The `trim` method eliminates `\n` or `\r\n`, resulting in just `5`.
The [`parse` method on strings][parse]<!-- ignore --> converts a string to
another type. Here, we use it to convert from a string to a number. We need to
@@ -684,25 +696,27 @@ tell Rust the exact number type we want by using `let guess: u32`. The colon
(`:`) after `guess` tells Rust we’ll annotate the variable’s type. Rust has a
few built-in number types; the `u32` seen here is an unsigned, 32-bit integer.
It’s a good default choice for a small positive number. You’ll learn about
-other number types in Chapter 3. Additionally, the `u32` annotation in this
-example program and the comparison with `secret_number` means that Rust will
-infer that `secret_number` should be a `u32` as well. So now the comparison
-will be between two values of the same type!
+other number types in [Chapter 3][integers]<!-- ignore -->.
+
+Additionally, the `u32` annotation in this example program and the comparison
+with `secret_number` means Rust will infer that `secret_number` should be a
+`u32` as well. So now the comparison will be between two values of the same
+type!
The `parse` method will only work on characters that can logically be converted
into numbers and so can easily cause errors. If, for example, the string
contained `AðŸ‘%`, there would be no way to convert that to a number. Because it
might fail, the `parse` method returns a `Result` type, much as the `read_line`
-method does (discussed earlier in [“Handling Potential Failure with the
-`Result` Typeâ€](#handling-potential-failure-with-the-result-type)<!-- ignore
--->). We’ll treat this `Result` the same way by using the `expect` method
-again. If `parse` returns an `Err` `Result` variant because it couldn’t create
-a number from the string, the `expect` call will crash the game and print the
-message we give it. If `parse` can successfully convert the string to a number,
-it will return the `Ok` variant of `Result`, and `expect` will return the
-number that we want from the `Ok` value.
+method does (discussed earlier in [“Handling Potential Failure with
+`Result`â€](#handling-potential-failure-with-result)<!-- ignore-->). We’ll treat
+this `Result` the same way by using the `expect` method again. If `parse`
+returns an `Err` `Result` variant because it couldn’t create a number from the
+string, the `expect` call will crash the game and print the message we give it.
+If `parse` can successfully convert the string to a number, it will return the
+`Ok` variant of `Result`, and `expect` will return the number that we want from
+the `Ok` value.
-Let’s run the program now!
+Let’s run the program now:
<!-- manual-regeneration
cd listings/ch02-guessing-game-tutorial/no-listing-03-convert-string-to-number/
@@ -788,8 +802,8 @@ thread 'main' panicked at 'Please type a number!: ParseIntError { kind: InvalidD
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
-Typing `quit` will quit the game, but as you’ll notice so will entering any
-other non-number input. This is suboptimal to say the least; we want the game
+Typing `quit` will quit the game, but as you’ll notice, so will entering any
+other non-number input. This is suboptimal, to say the least; we want the game
to also stop when the correct number is guessed.
### Quitting After a Correct Guess
@@ -829,7 +843,7 @@ a `match` expression here, as we did with the `Ordering` result of the `cmp`
method.
If `parse` is able to successfully turn the string into a number, it will
-return an `Ok` value that contains the resulting number. That `Ok` value will
+return an `Ok` value that contains the resultant number. That `Ok` value will
match the first arm’s pattern, and the `match` expression will just return the
`num` value that `parse` produced and put inside the `Ok` value. That number
will end up right where we want it in the new `guess` variable we’re creating.
@@ -891,10 +905,10 @@ secret number. Listing 2-6 shows the final code.
<span class="caption">Listing 2-6: Complete guessing game code</span>
-## Summary
-
At this point, you’ve successfully built the guessing game. Congratulations!
+## Summary
+
This project was a hands-on way to introduce you to many new Rust concepts:
`let`, `match`, functions, the use of external crates, and more. In the next
few chapters, you’ll learn about these concepts in more detail. Chapter 3
@@ -919,4 +933,6 @@ discusses structs and method syntax, and Chapter 6 explains how enums work.
[doccargo]: http://doc.crates.io
[doccratesio]: http://doc.crates.io/crates-io.html
[match]: ch06-02-match.html
+[shadowing]: ch03-01-variables-and-mutability.html#shadowing
[parse]: ../std/primitive.str.html#method.parse
+[integers]: ch03-02-data-types.html#integer-types
diff --git a/src/doc/book/src/ch03-00-common-programming-concepts.md b/src/doc/book/src/ch03-00-common-programming-concepts.md
index 8495543f3..2e37fad02 100644
--- a/src/doc/book/src/ch03-00-common-programming-concepts.md
+++ b/src/doc/book/src/ch03-00-common-programming-concepts.md
@@ -12,9 +12,9 @@ them early will give you a strong core to start from.
> #### Keywords
>
-> The Rust language has a set of *keywords* that are reserved for use by
-> the language only, much as in other languages. Keep in mind that you cannot
-> use these words as names of variables or functions. Most of the keywords have
+> The Rust language has a set of *keywords* that are reserved for use by the
+> language only, much as in other languages. Keep in mind that you cannot use
+> these words as names of variables or functions. Most of the keywords have
> special meanings, and you’ll be using them to do various tasks in your Rust
> programs; a few have no current functionality associated with them but have
> been reserved for functionality that might be added to Rust in the future. You
diff --git a/src/doc/book/src/ch03-01-variables-and-mutability.md b/src/doc/book/src/ch03-01-variables-and-mutability.md
index ac583f1b2..883a53050 100644
--- a/src/doc/book/src/ch03-01-variables-and-mutability.md
+++ b/src/doc/book/src/ch03-01-variables-and-mutability.md
@@ -1,7 +1,7 @@
## Variables and Mutability
As mentioned in the [“Storing Values with
-Variablesâ€][storing-values-with-variables]<!-- ignore --> section, by default
+Variablesâ€][storing-values-with-variables]<!-- ignore --> section, by default,
variables are immutable. This is one of many nudges Rust gives you to write
your code in a way that takes advantage of the safety and easy concurrency that
Rust offers. However, you still have the option to make your variables mutable.
@@ -9,12 +9,11 @@ Let’s explore how and why Rust encourages you to favor immutability and why
sometimes you might want to opt out.
When a variable is immutable, once a value is bound to a name, you can’t change
-that value. To illustrate this, let’s generate a new project called *variables*
-in your *projects* directory by using `cargo new variables`.
+that value. To illustrate this, generate a new project called *variables* in
+your *projects* directory by using `cargo new variables`.
Then, in your new *variables* directory, open *src/main.rs* and replace its
-code with the following code. This code won’t compile just yet, we’ll first
-examine the immutability error.
+code with the following code, which won’t compile just yet:
<span class="filename">Filename: src/main.rs</span>
@@ -22,8 +21,8 @@ examine the immutability error.
{{#rustdoc_include ../listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/src/main.rs}}
```
-Save and run the program using `cargo run`. You should receive an error
-message, as shown in this output:
+Save and run the program using `cargo run`. You should receive an error message
+regarding an immutability error, as shown in this output:
```console
{{#include ../listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt}}
@@ -34,9 +33,8 @@ Compiler errors can be frustrating, but really they only mean your program
isn’t safely doing what you want it to do yet; they do *not* mean that you’re
not a good programmer! Experienced Rustaceans still get compiler errors.
-The error message indicates that the cause of the error is that you `` cannot
-assign twice to immutable variable `x` ``, because you tried to assign a second
-value to the immutable `x` variable.
+You received the error message `` cannot assign twice to immutable variable `x`
+`` because you tried to assign a second value to the immutable `x` variable.
It’s important that we get compile-time errors when we attempt to change a
value that’s designated as immutable because this very situation can lead to
@@ -45,15 +43,16 @@ never change and another part of our code changes that value, it’s possible
that the first part of the code won’t do what it was designed to do. The cause
of this kind of bug can be difficult to track down after the fact, especially
when the second piece of code changes the value only *sometimes*. The Rust
-compiler guarantees that when you state a value won’t change, it really won’t
-change, so you don’t have to keep track of it yourself. Your code is thus
+compiler guarantees that when you state that a value won’t change, it really
+won’t change, so you don’t have to keep track of it yourself. Your code is thus
easier to reason through.
-But mutability can be very useful, and can make code more convenient to write.
-Although variables are immutable by default, you can make them mutable by adding
-`mut` in front of the variable name as you did in Chapter 2. Adding `mut` also
-conveys intent to future readers of the code by indicating that other parts of
-the code will be changing this variable’s value.
+But mutability can be very useful, and can make code more convenient to write.
+Although variables are immutable by default, you can make them mutable by
+adding `mut` in front of the variable name as you did in [Chapter
+2][storing-values-with-variables]<!-- ignore -->. Adding `mut` also conveys
+intent to future readers of the code by indicating that other parts of the code
+will be changing this variable’s value.
For example, let’s change *src/main.rs* to the following:
@@ -69,8 +68,8 @@ When we run the program now, we get this:
{{#include ../listings/ch03-common-programming-concepts/no-listing-02-adding-mut/output.txt}}
```
-We’re allowed to change the value bound to `x` from `5` to `6` when `mut`
-is used. Ultimately, deciding whether to use mutability or not is up to you and
+We’re allowed to change the value bound to `x` from `5` to `6` when `mut` is
+used. Ultimately, deciding whether to use mutability or not is up to you and
depends on what you think is clearest in that particular situation.
### Constants
@@ -82,9 +81,9 @@ and variables.
First, you aren’t allowed to use `mut` with constants. Constants aren’t just
immutable by default—they’re always immutable. You declare constants using the
`const` keyword instead of the `let` keyword, and the type of the value *must*
-be annotated. We’re about to cover types and type annotations in the next
-section, [“Data Types,â€][data-types]<!-- ignore --> so don’t worry about the
-details right now. Just know that you must always annotate the type.
+be annotated. We’ll cover types and type annotations in the next section,
+[“Data Types,â€][data-types]<!-- ignore -->, so don’t worry about the details
+right now. Just know that you must always annotate the type.
Constants can be declared in any scope, including the global scope, which makes
them useful for values that many parts of code need to know about.
@@ -109,11 +108,11 @@ to the value 10,800. See the [Rust Reference’s section on constant
evaluation][const-eval] for more information on what operations can be used
when declaring constants.
-Constants are valid for the entire time a program runs, within the scope they
-were declared in. This property makes constants useful for values in your
-application domain that multiple parts of the program might need to know about,
-such as the maximum number of points any player of a game is allowed to earn or
-the speed of light.
+Constants are valid for the entire time a program runs, within the scope in
+which they were declared. This property makes constants useful for values in
+your application domain that multiple parts of the program might need to know
+about, such as the maximum number of points any player of a game is allowed to
+earn, or the speed of light.
Naming hardcoded values used throughout your program as constants is useful in
conveying the meaning of that value to future maintainers of the code. It also
@@ -150,7 +149,7 @@ When we run this program, it will output the following:
{{#include ../listings/ch03-common-programming-concepts/no-listing-03-shadowing/output.txt}}
```
-Shadowing is different from marking a variable as `mut`, because we’ll get a
+Shadowing is different from marking a variable as `mut` because we’ll get a
compile-time error if we accidentally try to reassign to this variable without
using the `let` keyword. By using `let`, we can perform a few transformations
on a value but have the variable be immutable after those transformations have
diff --git a/src/doc/book/src/ch03-02-data-types.md b/src/doc/book/src/ch03-02-data-types.md
index 47c00adc8..bedf1450c 100644
--- a/src/doc/book/src/ch03-02-data-types.md
+++ b/src/doc/book/src/ch03-02-data-types.md
@@ -16,9 +16,9 @@ Chapter 2, we must add a type annotation, like this:
let guess: u32 = "42".parse().expect("Not a number!");
```
-If we don’t add the `: u32` type annotation above, Rust will display the
-following error, which means the compiler needs more information from us to
-know which type we want to use:
+If we don’t add the `: u32` type annotation shown in the preceding code, Rust
+will display the following error, which means the compiler needs more
+information from us to know which type we want to use:
```console
{{#include ../listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt}}
@@ -37,7 +37,7 @@ these from other programming languages. Let’s jump into how they work in Rust.
An *integer* is a number without a fractional component. We used one integer
type in Chapter 2, the `u32` type. This type declaration indicates that the
value it’s associated with should be an unsigned integer (signed integer types
-start with `i`, instead of `u`) that takes up 32 bits of space. Table 3-1 shows
+start with `i` instead of `u`) that takes up 32 bits of space. Table 3-1 shows
the built-in integer types in Rust. We can use any of these variants to declare
the type of an integer value.
@@ -59,9 +59,8 @@ negative—in other words, whether the number needs to have a sign with it
represented without a sign (unsigned). It’s like writing numbers on paper: when
the sign matters, a number is shown with a plus sign or a minus sign; however,
when it’s safe to assume the number is positive, it’s shown with no sign.
-Signed numbers are stored using [two’s
-complement](https://en.wikipedia.org/wiki/Two%27s_complement)<!-- ignore -->
-representation.
+Signed numbers are stored using [two’s complement][twos-complement]<!-- ignore
+--> representation.
Each signed variant can store numbers from -(2<sup>n - 1</sup>) to 2<sup>n -
1</sup> - 1 inclusive, where *n* is the number of bits that variant uses. So an
@@ -98,12 +97,12 @@ some sort of collection.
> ##### Integer Overflow
>
> Let’s say you have a variable of type `u8` that can hold values between 0 and
-> 255. If you try to change the variable to a value outside of that range, such
-> as 256, *integer overflow* will occur, which can result in one of two
-> behaviors. When you’re compiling in debug mode, Rust includes checks for
-> integer overflow that cause your program to *panic* at runtime if this
-> behavior occurs. Rust uses the term panicking when a program exits with an
-> error; we’ll discuss panics in more depth in the [“Unrecoverable Errors with
+> 255. If you try to change the variable to a value outside that range, such as
+> 256, *integer overflow* will occur, which can result in one of two behaviors.
+> When you’re compiling in debug mode, Rust includes checks for integer overflow
+> that cause your program to *panic* at runtime if this behavior occurs. Rust
+> uses the term *panicking* when a program exits with an error; we’ll discuss
+> panics in more depth in the [“Unrecoverable Errors with
> `panic!`â€][unrecoverable-errors-with-panic]<!-- ignore --> section in Chapter
> 9.
>
@@ -119,19 +118,19 @@ some sort of collection.
> To explicitly handle the possibility of overflow, you can use these families
> of methods provided by the standard library for primitive numeric types:
>
-> - Wrap in all modes with the `wrapping_*` methods, such as `wrapping_add`
-> - Return the `None` value if there is overflow with the `checked_*` methods
-> - Return the value and a boolean indicating whether there was overflow with
-> the `overflowing_*` methods
-> - Saturate at the value’s minimum or maximum values with `saturating_*`
-> methods
+> * Wrap in all modes with the `wrapping_*` methods, such as `wrapping_add`.
+> * Return the `None` value if there is overflow with the `checked_*` methods.
+> * Return the value and a boolean indicating whether there was overflow with
+> the `overflowing_*` methods.
+> * Saturate at the value’s minimum or maximum values with the `saturating_*`
+> methods.
#### Floating-Point Types
Rust also has two primitive types for *floating-point numbers*, which are
numbers with decimal points. Rust’s floating-point types are `f32` and `f64`,
which are 32 bits and 64 bits in size, respectively. The default type is `f64`
-because on modern CPUs it’s roughly the same speed as `f32` but is capable of
+because on modern CPUs, it’s roughly the same speed as `f32` but is capable of
more precision. All floating-point types are signed.
Here’s an example that shows floating-point numbers in action:
@@ -147,9 +146,9 @@ Floating-point numbers are represented according to the IEEE-754 standard. The
#### Numeric Operations
-Rust supports the basic mathematical operations you’d expect for all of the
-number types: addition, subtraction, multiplication, division, and remainder.
-Integer division rounds down to the nearest integer. The following code shows
+Rust supports the basic mathematical operations you’d expect for all the number
+types: addition, subtraction, multiplication, division, and remainder. Integer
+division truncates toward zero to the nearest integer. The following code shows
how you’d use each numeric operation in a `let` statement:
<span class="filename">Filename: src/main.rs</span>
@@ -159,8 +158,9 @@ how you’d use each numeric operation in a `let` statement:
```
Each expression in these statements uses a mathematical operator and evaluates
-to a single value, which is then bound to a variable. [Appendix B][appendix_b]<!-- ignore --> contains a
-list of all operators that Rust provides.
+to a single value, which is then bound to a variable. [Appendix
+B][appendix_b]<!-- ignore --> contains a list of all operators that Rust
+provides.
#### The Boolean Type
@@ -180,7 +180,7 @@ Flowâ€][control-flow]<!-- ignore --> section.
#### The Character Type
-Rust’s `char` type is the language’s most primitive alphabetic type. Here’s
+Rust’s `char` type is the language’s most primitive alphabetic type. Here are
some examples of declaring `char` values:
<span class="filename">Filename: src/main.rs</span>
@@ -207,9 +207,9 @@ primitive compound types: tuples and arrays.
#### The Tuple Type
-A tuple is a general way of grouping together a number of values with a variety
-of types into one compound type. Tuples have a fixed length: once declared,
-they cannot grow or shrink in size.
+A *tuple* is a general way of grouping together a number of values with a
+variety of types into one compound type. Tuples have a fixed length: once
+declared, they cannot grow or shrink in size.
We create a tuple by writing a comma-separated list of values inside
parentheses. Each position in the tuple has a type, and the types of the
@@ -222,7 +222,7 @@ type annotations in this example:
{{#rustdoc_include ../listings/ch03-common-programming-concepts/no-listing-10-tuples/src/main.rs}}
```
-The variable `tup` binds to the entire tuple, because a tuple is considered a
+The variable `tup` binds to the entire tuple because a tuple is considered a
single compound element. To get the individual values out of a tuple, we can
use pattern matching to destructure a tuple value, like this:
@@ -234,7 +234,7 @@ use pattern matching to destructure a tuple value, like this:
This program first creates a tuple and binds it to the variable `tup`. It then
uses a pattern with `let` to take `tup` and turn it into three separate
-variables, `x`, `y`, and `z`. This is called *destructuring*, because it breaks
+variables, `x`, `y`, and `z`. This is called *destructuring* because it breaks
the single tuple into three parts. Finally, the program prints the value of
`y`, which is `6.4`.
@@ -275,9 +275,9 @@ Arrays are useful when you want your data allocated on the stack rather than
the heap (we will discuss the stack and the heap more in [Chapter
4][stack-and-heap]<!-- ignore -->) or when you want to ensure you always have a
fixed number of elements. An array isn’t as flexible as the vector type,
-though. A vector is a similar collection type provided by the standard library
-that *is* allowed to grow or shrink in size. If you’re unsure whether to use an
-array or a vector, chances are you should use a vector. [Chapter
+though. A *vector* is a similar collection type provided by the standard
+library that *is* allowed to grow or shrink in size. If you’re unsure whether
+to use an array or a vector, chances are you should use a vector. [Chapter
8][vectors]<!-- ignore --> discusses vectors in more detail.
However, arrays are more useful when you know the number of elements will not
@@ -324,9 +324,9 @@ like this:
{{#rustdoc_include ../listings/ch03-common-programming-concepts/no-listing-14-array-indexing/src/main.rs}}
```
-In this example, the variable named `first` will get the value `1`, because
-that is the value at index `[0]` in the array. The variable named `second` will
-get the value `2` from index `[1]` in the array.
+In this example, the variable named `first` will get the value `1` because that
+is the value at index `[0]` in the array. The variable named `second` will get
+the value `2` from index `[1]` in the array.
##### Invalid Array Element Access
@@ -341,9 +341,9 @@ Chapter 2, to get an array index from the user:
```
This code compiles successfully. If you run this code using `cargo run` and
-enter 0, 1, 2, 3, or 4, the program will print out the corresponding value at
-that index in the array. If you instead enter a number past the end of the
-array, such as 10, you’ll see output like this:
+enter `0`, `1`, `2`, `3`, or `4`, the program will print out the corresponding
+value at that index in the array. If you instead enter a number past the end of
+the array, such as `10`, you’ll see output like this:
<!-- manual-regeneration
cd listings/ch03-common-programming-concepts/no-listing-15-invalid-array-access
@@ -374,10 +374,10 @@ write readable, safe code that neither panics nor allows invalid memory access.
[comparing-the-guess-to-the-secret-number]:
ch02-00-guessing-game-tutorial.html#comparing-the-guess-to-the-secret-number
+[twos-complement]: https://en.wikipedia.org/wiki/Two%27s_complement
[control-flow]: ch03-05-control-flow.html#control-flow
[strings]: ch08-02-strings.html#storing-utf-8-encoded-text-with-strings
[stack-and-heap]: ch04-01-what-is-ownership.html#the-stack-and-the-heap
[vectors]: ch08-01-vectors.html
[unrecoverable-errors-with-panic]: ch09-01-unrecoverable-errors-with-panic.html
-[wrapping]: ../std/num/struct.Wrapping.html
[appendix_b]: appendix-02-operators.md
diff --git a/src/doc/book/src/ch03-03-how-functions-work.md b/src/doc/book/src/ch03-03-how-functions-work.md
index c698853ce..2b59f0cd4 100644
--- a/src/doc/book/src/ch03-03-how-functions-work.md
+++ b/src/doc/book/src/ch03-03-how-functions-work.md
@@ -35,8 +35,8 @@ should see the following output:
```
The lines execute in the order in which they appear in the `main` function.
-First, the “Hello, world!†message prints, and then `another_function` is
-called and its message is printed.
+First the “Hello, world!†message prints, and then `another_function` is called
+and its message is printed.
### Parameters
@@ -108,8 +108,9 @@ understand. Other languages don’t have the same distinctions, so let’s look
what statements and expressions are and how their differences affect the bodies
of functions.
-*Statements* are instructions that perform some action and do not return a
-value. *Expressions* evaluate to a resulting value. Let’s look at some examples.
+* **Statements** are instructions that perform some action and do not return
+ a value.
+* **Expressions** evaluate to a resultant value. Let’s look at some examples.
We’ve actually already used statements and expressions. Creating a variable and
assigning a value to it with the `let` keyword is a statement. In Listing 3-1,
@@ -172,10 +173,11 @@ This expression:
is a block that, in this case, evaluates to `4`. That value gets bound to `y`
as part of the `let` statement. Note that the `x + 1` line doesn’t have a
-semicolon at the end, unlike most of the lines you’ve seen so far. Expressions
-do not include ending semicolons. If you add a semicolon to the end of an
-expression, you turn it into a statement, and it will then not return a value.
-Keep this in mind as you explore function return values and expressions next.
+semicolon at the end, which is unlike most of the lines you’ve seen so far.
+Expressions do not include ending semicolons. If you add a semicolon to the end
+of an expression, you turn it into a statement, and it will then not return a
+value. Keep this in mind as you explore function return values and expressions
+next.
### Functions with Return Values
@@ -226,7 +228,7 @@ Let’s look at another example:
Running this code will print `The value of x is: 6`. But if we place a
semicolon at the end of the line containing `x + 1`, changing it from an
-expression to a statement, we’ll get an error.
+expression to a statement, we’ll get an error:
<span class="filename">Filename: src/main.rs</span>
@@ -240,7 +242,7 @@ Compiling this code produces an error, as follows:
{{#include ../listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt}}
```
-The main error message, “mismatched types,†reveals the core issue with this
+The main error message, `mismatched types`, reveals the core issue with this
code. The definition of the function `plus_one` says that it will return an
`i32`, but statements don’t evaluate to a value, which is expressed by `()`,
the unit type. Therefore, nothing is returned, which contradicts the function
diff --git a/src/doc/book/src/ch03-04-comments.md b/src/doc/book/src/ch03-04-comments.md
index 6af0ce175..bfb0cfe17 100644
--- a/src/doc/book/src/ch03-04-comments.md
+++ b/src/doc/book/src/ch03-04-comments.md
@@ -39,4 +39,7 @@ separate line above the code it’s annotating:
```
Rust also has another kind of comment, documentation comments, which we’ll
-discuss in the “Publishing a Crate to Crates.io†section of Chapter 14.
+discuss in the [“Publishing a Crate to Crates.ioâ€][publishing]<!-- ignore -->
+section of Chapter 14.
+
+[publishing]: ch14-02-publishing-to-crates-io.html
diff --git a/src/doc/book/src/ch03-05-control-flow.md b/src/doc/book/src/ch03-05-control-flow.md
index 100bfb3e3..60d6b95a9 100644
--- a/src/doc/book/src/ch03-05-control-flow.md
+++ b/src/doc/book/src/ch03-05-control-flow.md
@@ -1,9 +1,9 @@
## Control Flow
-The ability to run some code depending on if a condition is true, or run some
-code repeatedly while a condition is true, are basic building blocks in most
-programming languages. The most common constructs that let you control the flow
-of execution of Rust code are `if` expressions and loops.
+The ability to run some code depending on whether a condition is `true` and to
+run some code repeatedly while a condition is `true` are basic building blocks
+in most programming languages. The most common constructs that let you control
+the flow of execution of Rust code are `if` expressions and loops.
### `if` Expressions
@@ -22,17 +22,17 @@ the `if` expression. In the *src/main.rs* file, input the following:
All `if` expressions start with the keyword `if`, followed by a condition. In
this case, the condition checks whether or not the variable `number` has a
-value less than 5. We place the block of code to execute if the condition is true
-immediately after the condition inside curly brackets. Blocks of code
+value less than 5. We place the block of code to execute if the condition is
+`true` immediately after the condition inside curly brackets. Blocks of code
associated with the conditions in `if` expressions are sometimes called *arms*,
just like the arms in `match` expressions that we discussed in the [“Comparing
the Guess to the Secret Numberâ€][comparing-the-guess-to-the-secret-number]<!--
ignore --> section of Chapter 2.
-Optionally, we can also include an `else` expression, which we chose
-to do here, to give the program an alternative block of code to execute should
-the condition evaluate to false. If you don’t provide an `else` expression and
-the condition is false, the program will just skip the `if` block and move on
+Optionally, we can also include an `else` expression, which we chose to do
+here, to give the program an alternative block of code to execute should the
+condition evaluate to `false`. If you don’t provide an `else` expression and
+the condition is `false`, the program will just skip the `if` block and move on
to the next bit of code.
Try running this code; you should see the following output:
@@ -105,11 +105,11 @@ see the following output:
```
When this program executes, it checks each `if` expression in turn and executes
-the first body for which the condition holds true. Note that even though 6 is
-divisible by 2, we don’t see the output `number is divisible by 2`, nor do we
-see the `number is not divisible by 4, 3, or 2` text from the `else` block.
-That’s because Rust only executes the block for the first true condition, and
-once it finds one, it doesn’t even check the rest.
+the first body for which the condition evaluates to `true`. Note that even
+though 6 is divisible by 2, we don’t see the output `number is divisible by 2`,
+nor do we see the `number is not divisible by 4, 3, or 2` text from the `else`
+block. That’s because Rust only executes the block for the first `true`
+condition, and once it finds one, it doesn’t even check the rest.
Using too many `else if` expressions can clutter your code, so if you have more
than one, you might want to refactor your code. Chapter 6 describes a powerful
@@ -171,8 +171,8 @@ if it had to keep track of multiple hypothetical types for any variable.
It’s often useful to execute a block of code more than once. For this task,
Rust provides several *loops*, which will run through the code inside the loop
-body to the end and then start immediately back at the beginning. To
-experiment with loops, let’s make a new project called *loops*.
+body to the end and then start immediately back at the beginning. To experiment
+with loops, let’s make a new project called *loops*.
Rust has three kinds of loops: `loop`, `while`, and `for`. Let’s try each one.
@@ -191,9 +191,9 @@ like this:
```
When we run this program, we’ll see `again!` printed over and over continuously
-until we stop the program manually. Most terminals support the keyboard shortcut
-<span class="keystroke">ctrl-c</span> to interrupt a program that is stuck in
-a continual loop. Give it a try:
+until we stop the program manually. Most terminals support the keyboard
+shortcut <span class="keystroke">ctrl-c</span> to interrupt a program that is
+stuck in a continual loop. Give it a try:
<!-- manual-regeneration
cd listings/ch03-common-programming-concepts/no-listing-32-loop
@@ -213,10 +213,10 @@ again!
^Cagain!
```
-The symbol `^C` represents where you pressed <span class="keystroke">ctrl-c
-</span>. You may or may not see the word `again!` printed after the `^C`,
-depending on where the code was in the loop when it received the interrupt
-signal.
+The symbol `^C` represents where you pressed <span
+class="keystroke">ctrl-c</span>. You may or may not see the word `again!`
+printed after the `^C`, depending on where the code was in the loop when it
+received the interrupt signal.
Fortunately, Rust also provides a way to break out of a loop using code. You
can place the `break` keyword within the loop to tell the program when to stop
@@ -245,18 +245,18 @@ use it, as shown here:
Before the loop, we declare a variable named `counter` and initialize it to
`0`. Then we declare a variable named `result` to hold the value returned from
the loop. On every iteration of the loop, we add `1` to the `counter` variable,
-and then check whether the counter is equal to `10`. When it is, we use the
+and then check whether the `counter` is equal to `10`. When it is, we use the
`break` keyword with the value `counter * 2`. After the loop, we use a
semicolon to end the statement that assigns the value to `result`. Finally, we
-print the value in `result`, which in this case is 20.
+print the value in `result`, which in this case is `20`.
#### Loop Labels to Disambiguate Between Multiple Loops
If you have loops within loops, `break` and `continue` apply to the innermost
-loop at that point. You can optionally specify a *loop label* on a loop that we
-can then use with `break` or `continue` to specify that those keywords apply to
-the labeled loop instead of the innermost loop. Loop labels must begin with a
-single quote. Here’s an example with two nested loops:
+loop at that point. You can optionally specify a *loop label* on a loop that
+you can then use with `break` or `continue` to specify that those keywords
+apply to the labeled loop instead of the innermost loop. Loop labels must begin
+with a single quote. Here’s an example with two nested loops:
```rust
{{#rustdoc_include ../listings/ch03-common-programming-concepts/no-listing-32-5-loop-labels/src/main.rs}}
@@ -274,7 +274,7 @@ doesn’t specify a label will exit the inner loop only. The `break
#### Conditional Loops with `while`
A program will often need to evaluate a condition within a loop. While the
-condition is true, the loop runs. When the condition ceases to be true, the
+condition is `true`, the loop runs. When the condition ceases to be `true`, the
program calls `break`, stopping the loop. It’s possible to implement behavior
like this using a combination of `loop`, `if`, `else`, and `break`; you could
try that now in a program, if you’d like. However, this pattern is so common
@@ -292,8 +292,8 @@ time, and then, after the loop, print a message and exit.
condition holds true</span>
This construct eliminates a lot of nesting that would be necessary if you used
-`loop`, `if`, `else`, and `break`, and it’s clearer. While a condition holds
-true, the code runs; otherwise, it exits the loop.
+`loop`, `if`, `else`, and `break`, and it’s clearer. While a condition
+evaluates to `true`, the code runs; otherwise, it exits the loop.
#### Looping Through a Collection with `for`
@@ -312,8 +312,8 @@ using a `while` loop</span>
Here, the code counts up through the elements in the array. It starts at index
`0`, and then loops until it reaches the final index in the array (that is,
-when `index < 5` is no longer true). Running this code will print every element
-in the array:
+when `index < 5` is no longer `true`). Running this code will print every
+element in the array:
```console
{{#include ../listings/ch03-common-programming-concepts/listing-03-04/output.txt}}
@@ -324,8 +324,8 @@ will reach a value of `5` at some point, the loop stops executing before trying
to fetch a sixth value from the array.
However, this approach is error prone; we could cause the program to panic if
-the index value or test condition are incorrect. For example, if you changed
-the definition of the `a` array to have four elements but forgot to update the
+the index value or test condition is incorrect. For example, if you changed the
+definition of the `a` array to have four elements but forgot to update the
condition to `while index < 4`, the code would panic. It’s also slow, because
the compiler adds runtime code to perform the conditional check of whether the
index is within the bounds of the array on every iteration through the loop.
@@ -372,13 +372,13 @@ This code is a bit nicer, isn’t it?
## Summary
-You made it! That was a sizable chapter: you learned about variables, scalar
-and compound data types, functions, comments, `if` expressions, and loops!
-To practice with the concepts discussed in this chapter, try building
-programs to do the following:
+You made it! This was a sizable chapter: you learned about variables, scalar
+and compound data types, functions, comments, `if` expressions, and loops! To
+practice with the concepts discussed in this chapter, try building programs to
+do the following:
* Convert temperatures between Fahrenheit and Celsius.
-* Generate the nth Fibonacci number.
+* Generate the *n*th Fibonacci number.
* Print the lyrics to the Christmas carol “The Twelve Days of Christmas,â€
taking advantage of the repetition in the song.
diff --git a/src/doc/book/src/ch04-01-what-is-ownership.md b/src/doc/book/src/ch04-01-what-is-ownership.md
index 94842e1b0..5249c2dd7 100644
--- a/src/doc/book/src/ch04-01-what-is-ownership.md
+++ b/src/doc/book/src/ch04-01-what-is-ownership.md
@@ -1,8 +1,8 @@
## What Is Ownership?
-*Ownership* is a set of rules that governs how a Rust program manages memory.
+*Ownership* is a set of rules that govern how a Rust program manages memory.
All programs have to manage the way they use a computer’s memory while running.
-Some languages have garbage collection that regularly looks for no-longer used
+Some languages have garbage collection that regularly looks for no-longer-used
memory as the program runs; in other languages, the programmer must explicitly
allocate and free the memory. Rust uses a third approach: memory is managed
through a system of ownership with a set of rules that the compiler checks. If
@@ -49,14 +49,14 @@ strings.
> known, fixed size, you can store the pointer on the stack, but when you want
> the actual data, you must follow the pointer. Think of being seated at a
> restaurant. When you enter, you state the number of people in your group, and
-> the staff finds an empty table that fits everyone and leads you there. If
+> the host finds an empty table that fits everyone and leads you there. If
> someone in your group comes late, they can ask where you’ve been seated to
> find you.
>
> Pushing to the stack is faster than allocating on the heap because the
> allocator never has to search for a place to store new data; that location is
> always at the top of the stack. Comparatively, allocating space on the heap
-> requires more work, because the allocator must first find a big enough space
+> requires more work because the allocator must first find a big enough space
> to hold the data and then perform bookkeeping to prepare for the next
> allocation.
>
@@ -122,8 +122,8 @@ valid</span>
In other words, there are two important points in time here:
-* When `s` comes *into scope*, it is valid.
-* It remains valid until it goes *out of scope*.
+* When `s` comes *into* scope, it is valid.
+* It remains valid until it goes *out of* scope.
At this point, the relationship between scopes and when variables are valid is
similar to that in other programming languages. Now we’ll build on top of this
@@ -133,7 +133,7 @@ understanding by introducing the `String` type.
To illustrate the rules of ownership, we need a data type that is more complex
than those we covered in the [“Data Typesâ€][data-types]<!-- ignore --> section
-of Chapter 3. The types covered previously are all a known size, can be stored
+of Chapter 3. The types covered previously are of a known size, can be stored
on the stack and popped off the stack when their scope is over, and can be
quickly and trivially copied to make a new, independent instance if another
part of code needs to use the same value in a different scope. But we want to
@@ -162,7 +162,7 @@ let s = String::from("hello");
The double colon `::` operator allows us to namespace this particular `from`
function under the `String` type rather than using some sort of name like
`string_from`. We’ll discuss this syntax more in the [“Method
-Syntaxâ€][method-syntax]<!-- ignore --> section of Chapter 5 and when we talk
+Syntaxâ€][method-syntax]<!-- ignore --> section of Chapter 5, and when we talk
about namespacing with modules in [“Paths for Referring to an Item in the
Module Treeâ€][paths-module-tree]<!-- ignore --> in Chapter 7.
@@ -173,7 +173,7 @@ This kind of string *can* be mutated:
```
So, what’s the difference here? Why can `String` be mutated but literals
-cannot? The difference is how these two types deal with memory.
+cannot? The difference is in how these two types deal with memory.
### Memory and Allocation
@@ -189,8 +189,8 @@ we need to allocate an amount of memory on the heap, unknown at compile time,
to hold the contents. This means:
* The memory must be requested from the memory allocator at runtime.
-* We need a way of returning this memory to the allocator when we’re
- done with our `String`.
+* We need a way of returning this memory to the allocator when we’re done with
+ our `String`.
That first part is done by us: when we call `String::from`, its implementation
requests the memory it needs. This is pretty much universal in programming
@@ -199,7 +199,7 @@ languages.
However, the second part is different. In languages with a *garbage collector
(GC)*, the GC keeps track of and cleans up memory that isn’t being used
anymore, and we don’t need to think about it. In most languages without a GC,
-it’s our responsibility to identify when memory is no longer being used and
+it’s our responsibility to identify when memory is no longer being used and to
call code to explicitly free it, just as we did to request it. Doing this
correctly has historically been a difficult programming problem. If we forget,
we’ll waste memory. If we do it too early, we’ll have an invalid variable. If
@@ -231,7 +231,10 @@ simple right now, but the behavior of code can be unexpected in more
complicated situations when we want to have multiple variables use the data
we’ve allocated on the heap. Let’s explore some of those situations now.
-#### Ways Variables and Data Interact: Move
+<!-- Old heading. Do not remove or links may break. -->
+<a id="ways-variables-and-data-interact-move"></a>
+
+#### Variables and Data Interacting with Move
Multiple variables can interact with the same data in different ways in Rust.
Let’s look at an example using an integer in Listing 4-2.
@@ -265,23 +268,29 @@ the memory that holds the contents of the string, a length, and a capacity.
This group of data is stored on the stack. On the right is the memory on the
heap that holds the contents.
-<img alt="String in memory" src="img/trpl04-01.svg" class="center" style="width: 50%;" />
+<img alt="Two tables: the first table contains the representation of s1 on the
+stack, consisting of its length (5), capacity (5), and a pointer to the first
+value in the second table. The second table contains the representation of the
+string data on the heap, byte by byte." src="img/trpl04-01.svg" class="center"
+style="width: 50%;" />
<span class="caption">Figure 4-1: Representation in memory of a `String`
holding the value `"hello"` bound to `s1`</span>
-The length is how much memory, in bytes, the contents of the `String` is
+The length is how much memory, in bytes, the contents of the `String` are
currently using. The capacity is the total amount of memory, in bytes, that the
-`String` has received from the allocator. The difference between length
-and capacity matters, but not in this context, so for now, it’s fine to ignore
-the capacity.
+`String` has received from the allocator. The difference between length and
+capacity matters, but not in this context, so for now, it’s fine to ignore the
+capacity.
When we assign `s1` to `s2`, the `String` data is copied, meaning we copy the
pointer, the length, and the capacity that are on the stack. We do not copy the
data on the heap that the pointer refers to. In other words, the data
representation in memory looks like Figure 4-2.
-<img alt="s1 and s2 pointing to the same value" src="img/trpl04-02.svg" class="center" style="width: 50%;" />
+<img alt="Three tables: tables s1 and s2 representing those strings on the
+stack, respectively, and both pointing to the same string data on the heap."
+src="img/trpl04-02.svg" class="center" style="width: 50%;" />
<span class="caption">Figure 4-2: Representation in memory of the variable `s2`
that has a copy of the pointer, length, and capacity of `s1`</span>
@@ -291,7 +300,9 @@ look like if Rust instead copied the heap data as well. If Rust did this, the
operation `s2 = s1` could be very expensive in terms of runtime performance if
the data on the heap were large.
-<img alt="s1 and s2 to two places" src="img/trpl04-03.svg" class="center" style="width: 50%;" />
+<img alt="Four tables: two tables representing the stack data for s1 and s2,
+and each points to its own copy of string data on the heap."
+src="img/trpl04-03.svg" class="center" style="width: 50%;" />
<span class="caption">Figure 4-3: Another possibility for what `s2 = s1` might
do if Rust copied the heap data as well</span>
@@ -304,7 +315,7 @@ same memory. This is known as a *double free* error and is one of the memory
safety bugs we mentioned previously. Freeing memory twice can lead to memory
corruption, which can potentially lead to security vulnerabilities.
-To ensure memory safety, after the line `let s2 = s1`, Rust considers `s1` as
+To ensure memory safety, after the line `let s2 = s1;`, Rust considers `s1` as
no longer valid. Therefore, Rust doesn’t need to free anything when `s1` goes
out of scope. Check out what happens when you try to use `s1` after `s2` is
created; it won’t work:
@@ -323,23 +334,30 @@ invalidated reference:
If you’ve heard the terms *shallow copy* and *deep copy* while working with
other languages, the concept of copying the pointer, length, and capacity
without copying the data probably sounds like making a shallow copy. But
-because Rust also invalidates the first variable, instead of calling it a
-shallow copy, it’s known as a *move*. In this example, we would say that
-`s1` was *moved* into `s2`. So what actually happens is shown in Figure 4-4.
+because Rust also invalidates the first variable, instead of being called a
+shallow copy, it’s known as a *move*. In this example, we would say that `s1`
+was *moved* into `s2`. So, what actually happens is shown in Figure 4-4.
-<img alt="s1 moved to s2" src="img/trpl04-04.svg" class="center" style="width: 50%;" />
+<img alt="Three tables: tables s1 and s2 representing those strings on the
+stack, respectively, and both pointing to the same string data on the heap.
+Table s1 is grayed out be-cause s1 is no longer valid; only s2 can be used to
+access the heap data." src="img/trpl04-04.svg" class="center" style="width:
+50%;" />
<span class="caption">Figure 4-4: Representation in memory after `s1` has been
invalidated</span>
-That solves our problem! With only `s2` valid, when it goes out of scope, it
+That solves our problem! With only `s2` valid, when it goes out of scope it
alone will free the memory, and we’re done.
In addition, there’s a design choice that’s implied by this: Rust will never
automatically create “deep†copies of your data. Therefore, any *automatic*
copying can be assumed to be inexpensive in terms of runtime performance.
-#### Ways Variables and Data Interact: Clone
+<!-- Old heading. Do not remove or links may break. -->
+<a id="ways-variables-and-data-interact-clone"></a>
+
+#### Variables and Data Interacting with Clone
If we *do* want to deeply copy the heap data of the `String`, not just the
stack data, we can use a common method called `clone`. We’ll discuss method
@@ -361,8 +379,8 @@ different is going on.
#### Stack-Only Data: Copy
-There’s another wrinkle we haven’t talked about yet. This code using integers –
-part of which was shown in Listing 4-2 – works and is valid:
+There’s another wrinkle we haven’t talked about yet. This code using
+integers—part of which was shown in Listing 4-2—works and is valid:
```rust
{{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-06-copy/src/main.rs:here}}
@@ -376,7 +394,7 @@ time are stored entirely on the stack, so copies of the actual values are quick
to make. That means there’s no reason we would want to prevent `x` from being
valid after we create the variable `y`. In other words, there’s no difference
between deep and shallow copying here, so calling `clone` wouldn’t do anything
-different from the usual shallow copying and we can leave it out.
+different from the usual shallow copying, and we can leave it out.
Rust has a special annotation called the `Copy` trait that we can place on
types that are stored on the stack, as integers are (we’ll talk more about
@@ -391,7 +409,7 @@ we’ll get a compile-time error. To learn about how to add the `Copy` annotatio
to your type to implement the trait, see [“Derivable
Traitsâ€][derivable-traits]<!-- ignore --> in Appendix C.
-So what types implement the `Copy` trait? You can check the documentation for
+So, what types implement the `Copy` trait? You can check the documentation for
the given type to be sure, but as a general rule, any group of simple scalar
values can implement `Copy`, and nothing that requires allocation or is some
form of resource can implement `Copy`. Here are some of the types that
@@ -399,7 +417,7 @@ implement `Copy`:
* All the integer types, such as `u32`.
* The Boolean type, `bool`, with values `true` and `false`.
-* All the floating point types, such as `f64`.
+* All the floating-point types, such as `f64`.
* The character type, `char`.
* Tuples, if they only contain types that also implement `Copy`. For example,
`(i32, i32)` implements `Copy`, but `(i32, String)` does not.
@@ -427,9 +445,9 @@ the ownership rules prevent you from doing so.
### Return Values and Scope
-Returning values can also transfer ownership. Listing 4-4 shows an example
-of a function that returns some value, with similar annotations as those in
-Listing 4-3.
+Returning values can also transfer ownership. Listing 4-4 shows an example of a
+function that returns some value, with similar annotations as those in Listing
+4-3.
<span class="filename">Filename: src/main.rs</span>
diff --git a/src/doc/book/src/ch04-02-references-and-borrowing.md b/src/doc/book/src/ch04-02-references-and-borrowing.md
index 060c344bb..ea2d8d202 100644
--- a/src/doc/book/src/ch04-02-references-and-borrowing.md
+++ b/src/doc/book/src/ch04-02-references-and-borrowing.md
@@ -9,9 +9,8 @@ the data stored at that address; that data is owned by some other variable.
Unlike a pointer, a reference is guaranteed to point to a valid value of a
particular type for the life of that reference.
-Here is how you would define and use a `calculate_length` function that
-has a reference to an object as a parameter instead of taking ownership of the
-value:
+Here is how you would define and use a `calculate_length` function that has a
+reference to an object as a parameter instead of taking ownership of the value:
<span class="filename">Filename: src/main.rs</span>
@@ -25,7 +24,9 @@ function return value is gone. Second, note that we pass `&s1` into
`String`. These ampersands represent *references*, and they allow you to refer
to some value without taking ownership of it. Figure 4-5 depicts this concept.
-<img alt="&amp;String s pointing at String s1" src="img/trpl04-05.svg" class="center" />
+<img alt="Three tables: the table for s contains only a pointer to the table
+for s1. The table for s1 contains the stack data for s1 and points to the
+string data on the heap." src="img/trpl04-05.svg" class="center" />
<span class="caption">Figure 4-5: A diagram of `&String s` pointing at `String
s1`</span>
@@ -54,7 +55,7 @@ the parameter `s` is a reference. Let’s add some explanatory annotations:
The scope in which the variable `s` is valid is the same as any function
parameter’s scope, but the value pointed to by the reference is not dropped
-when `s` stops being used because `s` doesn’t have ownership. When functions
+when `s` stops being used, because `s` doesn’t have ownership. When functions
have references as parameters instead of the actual values, we won’t need to
return the values in order to give back ownership, because we never had
ownership.
@@ -63,7 +64,7 @@ We call the action of creating a reference *borrowing*. As in real life, if a
person owns something, you can borrow it from them. When you’re done, you have
to give it back. You don’t own it.
-So what happens if we try to modify something we’re borrowing? Try the code in
+So, what happens if we try to modify something we’re borrowing? Try the code in
Listing 4-6. Spoiler alert: it doesn’t work!
<span class="filename">Filename: src/main.rs</span>
@@ -94,7 +95,7 @@ with just a few small tweaks that use, instead, a *mutable reference*:
{{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-09-fixes-listing-04-06/src/main.rs}}
```
-First, we change `s` to be `mut`. Then we create a mutable reference with `&mut
+First we change `s` to be `mut`. Then we create a mutable reference with `&mut
s` where we call the `change` function, and update the function signature to
accept a mutable reference with `some_string: &mut String`. This makes it very
clear that the `change` function will mutate the value it borrows.
@@ -123,7 +124,7 @@ in `r2` that borrows the same data as `r1`.
The restriction preventing multiple mutable references to the same data at the
same time allows for mutation but in a very controlled fashion. It’s something
-that new Rustaceans struggle with, because most languages let you mutate
+that new Rustaceans struggle with because most languages let you mutate
whenever you’d like. The benefit of having this restriction is that Rust can
prevent data races at compile time. A *data race* is similar to a race
condition and happens when these three behaviors occur:
@@ -133,8 +134,8 @@ condition and happens when these three behaviors occur:
* There’s no mechanism being used to synchronize access to the data.
Data races cause undefined behavior and can be difficult to diagnose and fix
-when you’re trying to track them down at runtime; Rust prevents this problem
-by refusing to compile code with data races!
+when you’re trying to track them down at runtime; Rust prevents this problem by
+refusing to compile code with data races!
As always, we can use curly brackets to create a new scope, allowing for
multiple mutable references, just not *simultaneous* ones:
@@ -175,10 +176,9 @@ occurs before the mutable reference is introduced:
The scopes of the immutable references `r1` and `r2` end after the `println!`
where they are last used, which is before the mutable reference `r3` is
-created. These scopes don’t overlap, so this code is allowed. The ability of
-the compiler to tell that a reference is no longer being used at a point before
-the end of the scope is called *Non-Lexical Lifetimes* (NLL for short), and you
-can read more about it in [The Edition Guide][nll].
+created. These scopes don’t overlap, so this code is allowed: the compiler can
+tell that the reference is no longer being used at a point before the end of
+the scope.
Even though borrowing errors may be frustrating at times, remember that it’s
the Rust compiler pointing out a potential bug early (at compile time rather
@@ -188,9 +188,9 @@ have to track down why your data isn’t what you thought it was.
### Dangling References
In languages with pointers, it’s easy to erroneously create a *dangling
-pointer*--a pointer that references a location in memory that may have been
-given to someone else--by freeing some memory while preserving a pointer to
-that memory. In Rust, by contrast, the compiler guarantees that references will
+pointer*—a pointer that references a location in memory that may have been
+given to someone else—by freeing some memory while preserving a pointer to that
+memory. In Rust, by contrast, the compiler guarantees that references will
never be dangling references: if you have a reference to some data, the
compiler will ensure that the data will not go out of scope before the
reference to the data does.
@@ -251,5 +251,3 @@ Let’s recap what we’ve discussed about references:
* References must always be valid.
Next, we’ll look at a different kind of reference: slices.
-
-[nll]: https://doc.rust-lang.org/edition-guide/rust-2018/ownership-and-lifetimes/non-lexical-lifetimes.html
diff --git a/src/doc/book/src/ch04-03-slices.md b/src/doc/book/src/ch04-03-slices.md
index afb6f76b1..6ffb1dc11 100644
--- a/src/doc/book/src/ch04-03-slices.md
+++ b/src/doc/book/src/ch04-03-slices.md
@@ -32,7 +32,7 @@ byte index value into the `String` parameter</span>
Because we need to go through the `String` element by element and check whether
a value is a space, we’ll convert our `String` to an array of bytes using the
-`as_bytes` method:
+`as_bytes` method.
```rust,ignore
{{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-07/src/main.rs:as_bytes}}
@@ -60,7 +60,7 @@ Because we get a reference to the element from `.iter().enumerate()`, we use
Inside the `for` loop, we search for the byte that represents the space by
using the byte literal syntax. If we find a space, we return the position.
-Otherwise, we return the length of the string by using `s.len()`:
+Otherwise, we return the length of the string by using `s.len()`.
```rust,ignore
{{#rustdoc_include ../listings/ch04-understanding-ownership/listing-04-07/src/main.rs:inside_for}}
@@ -98,8 +98,8 @@ fn second_word(s: &String) -> (usize, usize) {
Now we’re tracking a starting *and* an ending index, and we have even more
values that were calculated from data in a particular state but aren’t tied to
-that state at all. We have three unrelated variables floating around that
-need to be kept in sync.
+that state at all. We have three unrelated variables floating around that need
+to be kept in sync.
Luckily, Rust has a solution to this problem: string slices.
@@ -117,18 +117,22 @@ using a range within brackets by specifying `[starting_index..ending_index]`,
where `starting_index` is the first position in the slice and `ending_index` is
one more than the last position in the slice. Internally, the slice data
structure stores the starting position and the length of the slice, which
-corresponds to `ending_index` minus `starting_index`. So in the case of `let
+corresponds to `ending_index` minus `starting_index`. So, in the case of `let
world = &s[6..11];`, `world` would be a slice that contains a pointer to the
-byte at index 6 of `s` with a length value of 5.
+byte at index 6 of `s` with a length value of `5`.
Figure 4-6 shows this in a diagram.
-<img alt="world containing a pointer to the byte at index 6 of String s and a length 5" src="img/trpl04-06.svg" class="center" style="width: 50%;" />
+<img alt="Three tables: a table representing the stack data of s, which points
+to the byte at index 0 in a table of the string data &quot;hello world&quot; on
+the heap. The third table rep-resents the stack data of the slice world, which
+has a length value of 5 and points to byte 6 of the heap data table."
+src="img/trpl04-06.svg" class="center" style="width: 50%;" />
<span class="caption">Figure 4-6: String slice referring to part of a
`String`</span>
-With Rust’s `..` range syntax, if you want to start at index zero, you can drop
+With Rust’s `..` range syntax, if you want to start at index 0, you can drop
the value before the two periods. In other words, these are equal:
```rust
@@ -178,10 +182,10 @@ slice. The type that signifies “string slice†is written as `&str`:
{{#rustdoc_include ../listings/ch04-understanding-ownership/no-listing-18-first-word-slice/src/main.rs:here}}
```
-We get the index for the end of the word in the same way as we did in Listing
-4-7, by looking for the first occurrence of a space. When we find a space, we
-return a string slice using the start of the string and the index of the space
-as the starting and ending indices.
+We get the index for the end of the word the same way we did in Listing 4-7, by
+looking for the first occurrence of a space. When we find a space, we return a
+string slice using the start of the string and the index of the space as the
+starting and ending indices.
Now when we call `first_word`, we get back a single value that is tied to the
underlying data. The value is made up of a reference to the starting point of
@@ -193,7 +197,7 @@ Returning a slice would also work for a `second_word` function:
fn second_word(s: &String) -> &str {
```
-We now have a straightforward API that’s much harder to mess up, because the
+We now have a straightforward API that’s much harder to mess up because the
compiler will ensure the references into the `String` remain valid. Remember
the bug in the program in Listing 4-8, when we got the index to the end of the
first word but then cleared the string so our index was invalid? That code was
@@ -224,7 +228,10 @@ reference in `clear` and the immutable reference in `word` from existing at the
same time, and compilation fails. Not only has Rust made our API easier to use,
but it has also eliminated an entire class of errors at compile time!
-#### String Literals Are Slices
+<!-- Old heading. Do not remove or links may break. -->
+<a id="string-literals-are-slices"></a>
+
+#### String Literals as Slices
Recall that we talked about string literals being stored inside the binary. Now
that we know about slices, we can properly understand string literals:
@@ -260,10 +267,11 @@ a string slice for the type of the `s` parameter</span>
If we have a string slice, we can pass that directly. If we have a `String`, we
can pass a slice of the `String` or a reference to the `String`. This
flexibility takes advantage of *deref coercions*, a feature we will cover in
-the [“Implicit Deref Coercions with Functions and
-Methodsâ€][deref-coercions]<!--ignore--> section of Chapter 15. Defining a
-function to take a string slice instead of a reference to a `String` makes our
-API more general and useful without losing any functionality:
+[“Implicit Deref Coercions with Functions and
+Methodsâ€][deref-coercions]<!--ignore--> section of Chapter 15.
+
+Defining a function to take a string slice instead of a reference to a `String`
+makes our API more general and useful without losing any functionality:
<span class="filename">Filename: src/main.rs</span>
@@ -274,14 +282,14 @@ API more general and useful without losing any functionality:
### Other Slices
String slices, as you might imagine, are specific to strings. But there’s a
-more general slice type, too. Consider this array:
+more general slice type too. Consider this array:
```rust
let a = [1, 2, 3, 4, 5];
```
-Just as we might want to refer to a part of a string, we might want to refer
-to part of an array. We’d do so like this:
+Just as we might want to refer to part of a string, we might want to refer to
+part of an array. We’d do so like this:
```rust
let a = [1, 2, 3, 4, 5];
diff --git a/src/doc/book/src/ch05-02-example-structs.md b/src/doc/book/src/ch05-02-example-structs.md
index a83fa0564..5d33d9cb1 100644
--- a/src/doc/book/src/ch05-02-example-structs.md
+++ b/src/doc/book/src/ch05-02-example-structs.md
@@ -198,7 +198,7 @@ that expression, and returns ownership of the value.
> Note: Calling the `dbg!` macro prints to the standard error console stream
> (`stderr`), as opposed to `println!` which prints to the standard output
> console stream (`stdout`). We’ll talk more about `stderr` and `stdout` in the
-> “[“Writing Error Messages to Standard Error Instead of Standard
+> [“Writing Error Messages to Standard Error Instead of Standard
> Output†section in Chapter 12][err]<!-- ignore -->.
Here’s an example where we’re interested in the value that gets assigned to the
diff --git a/src/doc/book/src/ch08-02-strings.md b/src/doc/book/src/ch08-02-strings.md
index bf79c3925..9663d36ab 100644
--- a/src/doc/book/src/ch08-02-strings.md
+++ b/src/doc/book/src/ch08-02-strings.md
@@ -355,7 +355,7 @@ of type `char`, and you can iterate over the result to access each element:
```rust
for c in "Зд".chars() {
- println!("{}", c);
+ println!("{c}");
}
```
@@ -371,7 +371,7 @@ appropriate for your domain:
```rust
for b in "Зд".bytes() {
- println!("{}", b);
+ println!("{b}");
}
```
diff --git a/src/doc/book/src/ch09-01-unrecoverable-errors-with-panic.md b/src/doc/book/src/ch09-01-unrecoverable-errors-with-panic.md
index f5b9fefb8..5675fe3e7 100644
--- a/src/doc/book/src/ch09-01-unrecoverable-errors-with-panic.md
+++ b/src/doc/book/src/ch09-01-unrecoverable-errors-with-panic.md
@@ -120,21 +120,21 @@ $ RUST_BACKTRACE=1 cargo run
thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 99', src/main.rs:4:5
stack backtrace:
0: rust_begin_unwind
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:85
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/panicking.rs:142:14
2: core::panicking::panic_bounds_check
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:62
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/panicking.rs:84:5
3: <usize as core::slice::index::SliceIndex<[T]>>::index
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/slice/index.rs:255
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/slice/index.rs:242:10
4: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/slice/index.rs:15
- 5: <alloc::vec::Vec<T> as core::ops::index::Index<I>>::index
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/alloc/src/vec.rs:1982
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/slice/index.rs:18:9
+ 5: <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/alloc/src/vec/mod.rs:2591:9
6: panic::main
- at ./src/main.rs:4
+ at ./src/main.rs:4:5
7: core::ops::function::FnOnce::call_once
- at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/ops/function.rs:227
+ at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```
diff --git a/src/doc/book/src/ch09-02-recoverable-errors-with-result.md b/src/doc/book/src/ch09-02-recoverable-errors-with-result.md
index 347ef9aa7..2ee006f09 100644
--- a/src/doc/book/src/ch09-02-recoverable-errors-with-result.md
+++ b/src/doc/book/src/ch09-02-recoverable-errors-with-result.md
@@ -6,9 +6,9 @@ interpret and respond to. For example, if you try to open a file and that
operation fails because the file doesn’t exist, you might want to create the
file instead of terminating the process.
-Recall from [“Handling Potential Failure with the `Result`
-Typeâ€][handle_failure]<!-- ignore --> in Chapter 2 that the `Result` enum is
-defined as having two variants, `Ok` and `Err`, as follows:
+Recall from [“Handling Potential Failure with `Result`â€][handle_failure]<!--
+ignore --> in Chapter 2 that the `Result` enum is defined as having two
+variants, `Ok` and `Err`, as follows:
```rust
enum Result<T, E> {
@@ -532,6 +532,6 @@ Now that we’ve discussed the details of calling `panic!` or returning `Result`
let’s return to the topic of how to decide which is appropriate to use in which
cases.
-[handle_failure]: ch02-00-guessing-game-tutorial.html#handling-potential-failure-with-the-result-type
+[handle_failure]: ch02-00-guessing-game-tutorial.html#handling-potential-failure-with-result
[trait-objects]: ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types
[termination]: ../std/process/trait.Termination.html
diff --git a/src/doc/book/src/ch13-02-iterators.md b/src/doc/book/src/ch13-02-iterators.md
index 2efa552a8..030ebf48e 100644
--- a/src/doc/book/src/ch13-02-iterators.md
+++ b/src/doc/book/src/ch13-02-iterators.md
@@ -133,7 +133,7 @@ ownership of the iterator we call it on.
consume the iterator. Instead, they produce different iterators by changing
some aspect of the original iterator.
-Listing 13-17 shows an example of calling the iterator adaptor method `map`,
+Listing 13-14 shows an example of calling the iterator adaptor method `map`,
which takes a closure to call on each item as the items are iterated through.
The `map` method returns a new iterator that produces the modified items. The
closure here creates a new iterator in which each item from the vector will be
diff --git a/src/doc/book/src/ch14-02-publishing-to-crates-io.md b/src/doc/book/src/ch14-02-publishing-to-crates-io.md
index 64885d052..c5b1ac7fc 100644
--- a/src/doc/book/src/ch14-02-publishing-to-crates-io.md
+++ b/src/doc/book/src/ch14-02-publishing-to-crates-io.md
@@ -442,10 +442,15 @@ yank. For example, if we've published a crate named `guessing_game` version
1.0.1 and we want to yank it, in the project directory for `guessing_game` we'd
run:
+<!-- manual-regeneration:
+cargo yank carol-test --version 2.1.0
+cargo yank carol-test --version 2.1.0 --undo
+-->
+
```console
$ cargo yank --vers 1.0.1
Updating crates.io index
- Yank guessing_game:1.0.1
+ Yank guessing_game@1.0.1
```
By adding `--undo` to the command, you can also undo a yank and allow projects
@@ -454,7 +459,7 @@ to start depending on a version again:
```console
$ cargo yank --vers 1.0.1 --undo
Updating crates.io index
- Unyank guessing_game_:1.0.1
+ Unyank guessing_game@1.0.1
```
A yank *does not* delete any code. It cannot, for example, delete accidentally
diff --git a/src/doc/book/src/ch14-03-cargo-workspaces.md b/src/doc/book/src/ch14-03-cargo-workspaces.md
index 942d61b46..7c67331b7 100644
--- a/src/doc/book/src/ch14-03-cargo-workspaces.md
+++ b/src/doc/book/src/ch14-03-cargo-workspaces.md
@@ -224,9 +224,9 @@ copy output below; the output updating script doesn't handle subdirectories in p
```console
$ cargo build
Updating crates.io index
- Downloaded rand v0.8.3
+ Downloaded rand v0.8.5
--snip--
- Compiling rand v0.8.3
+ Compiling rand v0.8.5
Compiling add_one v0.1.0 (file:///projects/add/add_one)
warning: unused import: `rand`
--> add_one/src/lib.rs:1:5
@@ -236,8 +236,7 @@ warning: unused import: `rand`
|
= note: `#[warn(unused_imports)]` on by default
-warning: 1 warning emitted
-
+warning: `add_one` (lib) generated 1 warning
Compiling adder v0.1.0 (file:///projects/add/adder)
Finished dev [unoptimized + debuginfo] target(s) in 10.18s
```
@@ -300,14 +299,14 @@ $ cargo test
Compiling add_one v0.1.0 (file:///projects/add/add_one)
Compiling adder v0.1.0 (file:///projects/add/adder)
Finished test [unoptimized + debuginfo] target(s) in 0.27s
- Running target/debug/deps/add_one-f0253159197f7841
+ Running unittests src/lib.rs (target/debug/deps/add_one-f0253159197f7841)
running 1 test
test tests::it_works ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
- Running target/debug/deps/adder-49979ff40686fa8e
+ Running unittests src/main.rs (target/debug/deps/adder-49979ff40686fa8e)
running 0 tests
@@ -338,7 +337,7 @@ copy output below; the output updating script doesn't handle subdirectories in p
```console
$ cargo test -p add_one
Finished test [unoptimized + debuginfo] target(s) in 0.00s
- Running target/debug/deps/add_one-b3235fea9a156f74
+ Running unittests src/lib.rs (target/debug/deps/add_one-b3235fea9a156f74)
running 1 test
test tests::it_works ... ok
diff --git a/src/doc/book/src/ch14-04-installing-binaries.md b/src/doc/book/src/ch14-04-installing-binaries.md
index 425cf9c37..fd821f3a0 100644
--- a/src/doc/book/src/ch14-04-installing-binaries.md
+++ b/src/doc/book/src/ch14-04-installing-binaries.md
@@ -31,14 +31,14 @@ cargo install something you don't have, copy relevant output below
```console
$ cargo install ripgrep
Updating crates.io index
- Downloaded ripgrep v11.0.2
+ Downloaded ripgrep v13.0.0
Downloaded 1 crate (243.3 KB) in 0.88s
- Installing ripgrep v11.0.2
+ Installing ripgrep v13.0.0
--snip--
- Compiling ripgrep v11.0.2
+ Compiling ripgrep v13.0.0
Finished release [optimized + debuginfo] target(s) in 3m 10s
Installing ~/.cargo/bin/rg
- Installed package `ripgrep v11.0.2` (executable `rg`)
+ Installed package `ripgrep v13.0.0` (executable `rg`)
```
The second-to-last line of the output shows the location and the name of the
diff --git a/src/doc/book/src/ch15-00-smart-pointers.md b/src/doc/book/src/ch15-00-smart-pointers.md
index 7552dd5d1..9ecdcc835 100644
--- a/src/doc/book/src/ch15-00-smart-pointers.md
+++ b/src/doc/book/src/ch15-00-smart-pointers.md
@@ -12,7 +12,7 @@ pointer but also have additional metadata and capabilities. The concept of
smart pointers isn’t unique to Rust: smart pointers originated in C++ and exist
in other languages as well. Rust has a variety of smart pointers defined in the
standard library that provide functionality beyond that provided by references.
-To explore the general concept, we'll look at a couple of different examples of
+To explore the general concept, we’ll look at a couple of different examples of
smart pointers, including a *reference counting* smart pointer type. This
pointer enables you to allow data to have multiple owners by keeping track of
the number of owners and, when no owners remain, cleaning up the data.
@@ -21,7 +21,7 @@ Rust, with its concept of ownership and borrowing, has an additional difference
between references and smart pointers: while references only borrow data, in
many cases, smart pointers *own* the data they point to.
-Though we didn't call them as such at the time, we’ve already encountered a few
+Though we didn’t call them as such at the time, we’ve already encountered a few
smart pointers in this book, including `String` and `Vec<T>` in Chapter 8. Both
these types count as smart pointers because they own some memory and allow you
to manipulate it. They also have metadata and extra capabilities or guarantees.
@@ -32,7 +32,7 @@ Smart pointers are usually implemented using structs. Unlike an ordinary
struct, smart pointers implement the `Deref` and `Drop` traits. The `Deref`
trait allows an instance of the smart pointer struct to behave like a reference
so you can write your code to work with either references or smart pointers.
-The `Drop` trait allows you to customize the code that's run when an instance
+The `Drop` trait allows you to customize the code that’s run when an instance
of the smart pointer goes out of scope. In this chapter, we’ll discuss both
traits and demonstrate why they’re important to smart pointers.
diff --git a/src/doc/book/src/ch15-01-box.md b/src/doc/book/src/ch15-01-box.md
index 030a7842d..838062552 100644
--- a/src/doc/book/src/ch15-01-box.md
+++ b/src/doc/book/src/ch15-01-box.md
@@ -82,7 +82,7 @@ functionâ€) in Lisp that constructs a new pair from its two arguments. By
calling `cons` on a pair consisting of a value and another pair, we can
construct cons lists made up of recursive pairs.
-For example, here's a pseudocode representation of a cons list containing the
+For example, here’s a pseudocode representation of a cons list containing the
list 1, 2, 3 with each pair in parentheses:
```text
@@ -150,7 +150,7 @@ a recursive enum</span>
The error shows this type “has infinite size.†The reason is that we’ve defined
`List` with a variant that is recursive: it holds another value of itself
directly. As a result, Rust can’t figure out how much space it needs to store a
-`List` value. Let’s break down why we get this error. First, we'll look at how
+`List` value. Let’s break down why we get this error. First, we’ll look at how
Rust decides how much space it needs to store a value of a non-recursive type.
#### Computing the Size of a Non-Recursive Type
@@ -196,7 +196,7 @@ after doing automatic regeneration, look at listings/ch15-smart-pointers/listing
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `List` representable
|
2 | Cons(i32, Box<List>),
- | ^^^^ ^
+ | ++++ +
```
In this suggestion, “indirection†means that instead of storing a value
diff --git a/src/doc/book/src/ch15-02-deref.md b/src/doc/book/src/ch15-02-deref.md
index ba0b8990f..23c9fe8bf 100644
--- a/src/doc/book/src/ch15-02-deref.md
+++ b/src/doc/book/src/ch15-02-deref.md
@@ -73,11 +73,12 @@ Listing 15-6:
`Box<i32>`</span>
The main difference between Listing 15-7 and Listing 15-6 is that here we set
-`y` to be an instance of a box pointing to a copied value of `x` rather than a
-reference pointing to the value of `x`. In the last assertion, we can use the
-dereference operator to follow the box’s pointer in the same way that we did
-when `y` was a reference. Next, we’ll explore what is special about `Box<T>`
-that enables us to use the dereference operator by defining our own box type.
+`y` to be an instance of a `Box<T>` pointing to a copied value of `x` rather
+than a reference pointing to the value of `x`. In the last assertion, we can
+use the dereference operator to follow the pointer of the `Box<T>` in the same
+way that we did when `y` was a reference. Next, we’ll explore what is special
+about `Box<T>` that enables us to use the dereference operator by defining our
+own type.
### Defining Our Own Smart Pointer
diff --git a/src/doc/book/src/ch15-03-drop.md b/src/doc/book/src/ch15-03-drop.md
index 1ab2b86f0..05ab86873 100644
--- a/src/doc/book/src/ch15-03-drop.md
+++ b/src/doc/book/src/ch15-03-drop.md
@@ -58,7 +58,7 @@ When we run this program, we’ll see the following output:
Rust automatically called `drop` for us when our instances went out of scope,
calling the code we specified. Variables are dropped in the reverse order of
-their creation, so `d` was dropped before `c`. This example's purpose is to
+their creation, so `d` was dropped before `c`. This example’s purpose is to
give you a visual guide to how the `drop` method works; usually you would
specify the cleanup code that your type needs to run rather than a print
message.
diff --git a/src/doc/book/src/ch15-05-interior-mutability.md b/src/doc/book/src/ch15-05-interior-mutability.md
index 74bb02f05..7b5e825d7 100644
--- a/src/doc/book/src/ch15-05-interior-mutability.md
+++ b/src/doc/book/src/ch15-05-interior-mutability.md
@@ -103,11 +103,11 @@ an immutable value and see why that is useful.
#### A Use Case for Interior Mutability: Mock Objects
Sometimes during testing a programmer will use a type in place of another type,
-in order to observe particular behavior and assert it's implemented correctly.
+in order to observe particular behavior and assert it’s implemented correctly.
This placeholder type is called a *test double*. Think of it in the sense of a
-"stunt double" in filmmaking, where a person steps in and substitutes for an
+“stunt double†in filmmaking, where a person steps in and substitutes for an
actor to do a particular tricky scene. Test doubles stand in for other types
-when we're running tests. *Mock objects* are specific types of test doubles
+when we’re running tests. *Mock objects* are specific types of test doubles
that record what happens during a test so you can assert that the correct
actions took place.
@@ -273,7 +273,7 @@ BorrowMutError`. This is how `RefCell<T>` handles violations of the borrowing
rules at runtime.
Choosing to catch borrowing errors at runtime rather than compile time, as
-we've done here, means you'd potentially be finding mistakes in your code later
+we’ve done here, means you’d potentially be finding mistakes in your code later
in the development process: possibly not until your code was deployed to
production. Also, your code would incur a small runtime performance penalty as
a result of keeping track of the borrows at runtime rather than compile time.
diff --git a/src/doc/book/src/ch15-06-reference-cycles.md b/src/doc/book/src/ch15-06-reference-cycles.md
index 4b55d88a6..bef289202 100644
--- a/src/doc/book/src/ch15-06-reference-cycles.md
+++ b/src/doc/book/src/ch15-06-reference-cycles.md
@@ -117,7 +117,7 @@ up if its `strong_count` is 0. You can also create a *weak reference* to the
value within an `Rc<T>` instance by calling `Rc::downgrade` and passing a
reference to the `Rc<T>`. Strong references are how you can share ownership of
an `Rc<T>` instance. Weak references don’t express an ownership relationship,
-and their count doesn't affect when an `Rc<T>` instance is cleaned up. They
+and their count doesn’t affect when an `Rc<T>` instance is cleaned up. They
won’t cause a reference cycle because any cycle involving some weak references
will be broken once the strong reference count of values involved is 0.
diff --git a/src/doc/book/src/ch16-01-threads.md b/src/doc/book/src/ch16-01-threads.md
index 52947a99b..cfdd0c706 100644
--- a/src/doc/book/src/ch16-01-threads.md
+++ b/src/doc/book/src/ch16-01-threads.md
@@ -173,7 +173,7 @@ threads run at the same time.
We'll often use the `move` keyword with closures passed to `thread::spawn`
because the closure will then take ownership of the values it uses from the
environment, thus transferring ownership of those values from one thread to
-another. In the [“Capturing the Environment with Closuresâ€][capture]<!-- ignore
+another. In the [“Capturing References or Moving Ownershipâ€][capture]<!-- ignore
--> section of Chapter 13, we discussed `move` in the context of closures. Now,
we’ll concentrate more on the interaction between `move` and `thread::spawn`.
@@ -278,4 +278,4 @@ ownership rules.
With a basic understanding of threads and the thread API, let’s look at what we
can *do* with threads.
-[capture]: ch13-01-closures.html#capturing-the-environment-with-closures
+[capture]: ch13-01-closures.html#capturing-references-or-moving-ownership
diff --git a/src/doc/book/src/ch16-03-shared-state.md b/src/doc/book/src/ch16-03-shared-state.md
index 41dccfa13..918d162cf 100644
--- a/src/doc/book/src/ch16-03-shared-state.md
+++ b/src/doc/book/src/ch16-03-shared-state.md
@@ -219,9 +219,9 @@ thread update the final result with its part.
Note that if you are doing simple numerical operations, there are types simpler
than `Mutex<T>` types provided by the [`std::sync::atomic` module of the
-standard library][atomic]. These types provide safe, concurrent, atomic access
-to primitive types. We chose to use `Mutex<T>` with a primitive type for this
-example so we could concentrate on how `Mutex<T>` works.
+standard library][atomic]<!-- ignore -->. These types provide safe, concurrent,
+atomic access to primitive types. We chose to use `Mutex<T>` with a primitive
+type for this example so we could concentrate on how `Mutex<T>` works.
### Similarities Between `RefCell<T>`/`Rc<T>` and `Mutex<T>`/`Arc<T>`
diff --git a/src/doc/book/tools/doc-to-md.sh b/src/doc/book/tools/doc-to-md.sh
index cffe4c04b..8c802a71f 100755
--- a/src/doc/book/tools/doc-to-md.sh
+++ b/src/doc/book/tools/doc-to-md.sh
@@ -7,6 +7,15 @@ find tmp -name '*.docx' -print0 | \
# Extract just the filename so we can reuse it easily.
xargs -0 basename -s .docx | \
while IFS= read -r filename; do
+ # Truncate the `nostarch` dir file and put the "no editing" warning back.
+ # Tell shellcheck to ignore this because I want the `/src/` printed
+ # literally, not expanded.
+ # shellcheck disable=SC2016
+ echo '<!-- DO NOT EDIT THIS FILE.
+
+This file is periodically generated from the content in the `/src/`
+directory, so all fixes need to be made in `/src/`.
+-->' > "nostarch/$filename.md"
# Make a directory to put the XML in.
mkdir -p "tmp/$filename"
# Unzip the docx to get at the XML.
@@ -15,6 +24,6 @@ while IFS= read -r filename; do
xsltproc tools/docx-to-md.xsl "tmp/$filename/word/document.xml" | \
# Hard wrap at 80 chars at word bourdaries.
fold -w 80 -s | \
- # Remove trailing whitespace and save in the `nostarch` dir for comparison.
- sed -e "s/ *$//" > "nostarch/$filename.md"
+ # Remove trailing whitespace and append to the file in the `nostarch` dir for comparison.
+ sed -e "s/ *$//" >> "nostarch/$filename.md"
done
diff --git a/src/doc/book/tools/docx-to-md.xsl b/src/doc/book/tools/docx-to-md.xsl
index 637c7a59c..8deec85c9 100644
--- a/src/doc/book/tools/docx-to-md.xsl
+++ b/src/doc/book/tools/docx-to-md.xsl
@@ -12,14 +12,41 @@
<xsl:template match="w:p[starts-with(w:pPr/w:pStyle/@w:val, 'Contents3')]" />
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'ChapterStart']" />
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'ChapterNumber']" />
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'Normal']" />
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'Standard']" />
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'AuthorQuery']" />
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'BookHalfTitle']" />
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'BookTitle0']" />
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'BookEdition']" />
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'BookAuthor']" />
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'Copyright']" />
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'CopyrightHead']" />
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'CopyrightLOC']" />
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'ProductionDirective0']" />
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'ProductionDirective']" />
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'BoxType']" />
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'GraphicSlug']" />
<xsl:template match="w:p[w:pPr[not(w:pStyle)]]" />
+ <xsl:variable name="chapternumber" select="//w:p[w:pPr/w:pStyle/@w:val = 'ChapterNumber']/w:r/w:t" />
+ <xsl:variable name="appendixnumber" select="//w:p[w:pPr/w:pStyle/@w:val = 'AppendixNumber']/w:r/w:t" />
+
<!-- Paragraph styles -->
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'AppendixNumber']" >
+ <xsl:text>&#10;[TOC]&#10;&#10;</xsl:text>
+ <xsl:text>## Appendix </xsl:text>
+ <xsl:apply-templates select="*" />
+ <xsl:text>: </xsl:text>
+ </xsl:template>
+
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'AppendixTitle']">
+ <xsl:apply-templates select="*" />
+ <xsl:text>&#10;&#10;</xsl:text>
+ </xsl:template>
+
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'ChapterTitle']">
<xsl:text>&#10;[TOC]&#10;&#10;</xsl:text>
<xsl:text># </xsl:text>
@@ -27,11 +54,13 @@
<xsl:text>&#10;&#10;</xsl:text>
</xsl:template>
- <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'HeadA']">
+
+ <xsl:template match="w:p[(w:pPr/w:pStyle/@w:val = 'HeadA' or w:pPr/w:pStyle/@w:val = 'FrontmatterTitle') and w:r/w:t]">
<xsl:text>## </xsl:text>
<xsl:apply-templates select="*" />
<xsl:text>&#10;&#10;</xsl:text>
</xsl:template>
+ <xsl:template match="w:p[(w:pPr/w:pStyle/@w:val = 'HeadA' or w:pPr/w:pStyle/@w:val = 'FrontmatterTitle') and not(w:r/w:t)]" />
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'HeadB']">
<xsl:text>### </xsl:text>
@@ -51,10 +80,13 @@
<xsl:text>&#10;&#10;</xsl:text>
</xsl:template>
- <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'NumListA' or @w:val = 'NumListB']]">
+ <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'NumListA' or @w:val = 'NumListB' or @w:val = 'ListNumber' or @w:val = 'ListNumber0']]">
<xsl:text>1. </xsl:text>
<xsl:apply-templates select="*" />
<xsl:text>&#10;</xsl:text>
+ <xsl:if test="not(following-sibling::*[1][self::w:p]) or following-sibling::w:p[1][w:pPr/w:pStyle[@w:val != 'NumListA' and @w:val != 'NumListB' and @w:val != 'ListNumber' and @w:val != 'ListNumber0']]">
+ <xsl:text>&#10;</xsl:text>
+ </xsl:if>
</xsl:template>
<xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'NumListC']]">
@@ -63,10 +95,27 @@
<xsl:text>&#10;&#10;</xsl:text>
</xsl:template>
- <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'BulletA' or @w:val = 'BulletB' or @w:val = 'ListPlainA' or @w:val = 'ListPlainB']]">
+ <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'BulletA' or @w:val = 'BulletB' or @w:val = 'ListPlainA' or @w:val = 'ListPlainB' or @w:val = 'ListBullet' or @w:val = 'ListPlain' or @w:val = 'ListBullet0']]">
<xsl:text>* </xsl:text>
<xsl:apply-templates select="*" />
<xsl:text>&#10;</xsl:text>
+ <xsl:if test="not(following-sibling::*[1][self::w:p]) or following-sibling::w:p[1][w:pPr/w:pStyle[@w:val != 'BulletA' and @w:val != 'BulletB' and @w:val != 'ListPlainA' and @w:val != 'ListPlainB' and @w:val != 'ListBullet' and @w:val != 'ListPlain' and @w:val != 'ListBullet0']]">
+ <xsl:text>&#10;</xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'BoxListBullet']]">
+ <xsl:text>> * </xsl:text>
+ <xsl:apply-templates select="*" />
+ <xsl:text>&#10;</xsl:text>
+ <xsl:choose>
+ <xsl:when test="following-sibling::w:p[1][w:pPr/w:pStyle[@w:val = 'BoxBody']]">
+ <xsl:text>>&#10;</xsl:text>
+ </xsl:when>
+ <xsl:when test="not(following-sibling::*[1][self::w:p])">
+ <xsl:text>&#10;</xsl:text>
+ </xsl:when>
+ </xsl:choose>
</xsl:template>
<xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'BulletC' or @w:val = 'ListPlainC']]">
@@ -81,7 +130,13 @@
<xsl:text>&#10;</xsl:text>
</xsl:template>
- <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'BodyFirst' or @w:val = 'Body' or @w:val = 'BodyFirstBox' or @w:val = 'BodyBox' or @w:val = '1stPara']]">
+ <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'CodeLabel']]">
+ <xsl:text>Filename: </xsl:text>
+ <xsl:apply-templates select="*" />
+ <xsl:text>&#10;&#10;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'BodyFirst' or @w:val = 'Body' or @w:val = 'BodyFirstBox' or @w:val = 'BodyBox' or @w:val = '1stPara' or @w:val = 'ChapterIntro' or @w:val = 'BodyContinued' or @w:val = 'SourceForeword']]">
<xsl:if test=".//w:t">
<xsl:apply-templates select="*" />
<xsl:text>&#10;&#10;</xsl:text>
@@ -113,39 +168,172 @@
<xsl:text>&#10;```&#10;&#10;</xsl:text>
</xsl:template>
+ <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'Code' or @w:val = 'CodeWide' or @w:val = 'CodeAnnotated']]">
+ <xsl:if test="not(preceding-sibling::*[1][self::w:p]) or preceding-sibling::w:p[1][w:pPr[not(w:pStyle) or (w:pStyle/@w:val != 'Code' and w:pStyle/@w:val != 'CodeWide' and w:pStyle/@w:val != 'CodeAnnotated')]]">
+ <xsl:text>```&#10;</xsl:text>
+ </xsl:if>
+
+ <!-- Don't apply Emphasis/etc templates in code blocks -->
+ <xsl:for-each select="w:r">
+ <xsl:value-of select="w:t" />
+ </xsl:for-each>
+
+ <xsl:text>&#10;</xsl:text>
+
+ <xsl:if test="not(following-sibling::*[1][self::w:p]) or following-sibling::w:p[1][w:pPr[not(w:pStyle) or (w:pStyle/@w:val != 'Code' and w:pStyle/@w:val != 'CodeWide' and w:pStyle/@w:val != 'CodeAnnotated')]]">
+ <xsl:text>```&#10;&#10;</xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'BoxCode']]">
+ <xsl:choose>
+ <xsl:when test="not(preceding-sibling::*[1][self::w:p]) or preceding-sibling::w:p[1][w:pPr[not(w:pStyle) or w:pStyle/@w:val != 'BoxCode']]">
+ <xsl:text>> ```&#10;> </xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>> </xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ <xsl:apply-templates select="*" />
+
+ <xsl:choose>
+ <xsl:when test="following-sibling::w:p[1][w:pPr/w:pStyle/@w:val = 'BoxCode']">
+ <xsl:text>&#10;</xsl:text>
+ </xsl:when>
+ <xsl:when test="following-sibling::w:p[1][w:pPr/w:pStyle/@w:val = 'BoxBody']">
+ <xsl:text>&#10;> ```&#10;>&#10;</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>&#10;> ```&#10;&#10;</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'CodeSingle']">
<xsl:text>```&#10;</xsl:text>
<xsl:apply-templates select="*" />
<xsl:text>&#10;```&#10;&#10;</xsl:text>
</xsl:template>
- <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'ProductionDirective']">
+ <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'TableTitle']]">
+ <xsl:text>Table </xsl:text>
+ <xsl:value-of select="$chapternumber" />
+ <xsl:value-of select="$appendixnumber" />
+ <xsl:text>-</xsl:text>
+ <xsl:number level="any" count="w:p[w:pPr/w:pStyle[@w:val = 'TableTitle']]" />
+ <xsl:text>: </xsl:text>
<xsl:apply-templates select="*" />
<xsl:text>&#10;&#10;</xsl:text>
</xsl:template>
- <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'Caption' or @w:val = 'TableTitle' or @w:val = 'Caption1' or @w:val = 'Listing']]">
+ <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'Caption' or @w:val = 'Caption1' or @w:val = 'Listing' or @w:val = 'CodeListingCaption']]">
+ <xsl:text>Listing </xsl:text>
+ <xsl:value-of select="$chapternumber" />
+ <xsl:value-of select="$appendixnumber" />
+ <xsl:text>-</xsl:text>
+ <xsl:number level="any" count="w:p[w:pPr/w:pStyle[@w:val = 'Caption' or @w:val = 'Caption1' or @w:val = 'Listing' or @w:val = 'CodeListingCaption']]" />
+ <xsl:text>: </xsl:text>
<xsl:apply-templates select="*" />
<xsl:text>&#10;&#10;</xsl:text>
</xsl:template>
- <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'BlockQuote']]">
+ <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'BlockQuote' or @w:val = 'QuotePara']]">
<xsl:text>> </xsl:text>
<xsl:apply-templates select="*" />
</xsl:template>
- <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'BlockText']]">
- <xsl:text>&#10;</xsl:text>
+ <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'BoxTitle']]">
+ <xsl:text>> ### </xsl:text>
+ <xsl:apply-templates select="*" />
+ <xsl:text>&#10;>&#10;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="w:p[w:pPr/w:pStyle[@w:val = 'BlockText' or @w:val = 'BoxBody']]">
<xsl:text>> </xsl:text>
<xsl:apply-templates select="*" />
- <xsl:text>&#10;&#10;</xsl:text>
+ <xsl:choose>
+ <xsl:when test="following-sibling::w:p[1][w:pPr/w:pStyle/@w:val = 'BlockText' or w:pPr/w:pStyle/@w:val = 'BoxBody' or w:pPr/w:pStyle/@w:val = 'BoxListBullet' or w:pPr/w:pStyle/@w:val = 'BoxCode' or w:pPr/w:pStyle/@w:val = 'BoxRunInHead']">
+ <xsl:text>&#10;>&#10;</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>&#10;&#10;</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
<xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'Note']">
- <xsl:text>> </xsl:text>
+ <xsl:text>> Note: </xsl:text>
<xsl:apply-templates select="*" />
<xsl:text>&#10;&#10;</xsl:text>
</xsl:template>
+ <xsl:template match="w:r[w:rPr/w:rStyle/@w:val = 'NoteHead']" />
+
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'RunInHead']">
+ <xsl:text>* **</xsl:text>
+ <xsl:apply-templates select="*" />
+ <xsl:text>**: </xsl:text>
+ </xsl:template>
+
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'RunInPara']">
+ <xsl:apply-templates select="*" />
+ <xsl:text>&#10;</xsl:text>
+ <xsl:if test="following-sibling::w:p[1][w:pPr/w:pStyle/@w:val != 'RunInHead']">
+ <xsl:text>&#10;</xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'BoxRunInHead']">
+ <xsl:text>> * **</xsl:text>
+ <xsl:apply-templates select="*" />
+ <xsl:text>**: </xsl:text>
+ </xsl:template>
+
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'BoxRunInPara']">
+ <xsl:apply-templates select="*" />
+ <xsl:text>&#10;</xsl:text>
+ <xsl:if test="following-sibling::w:p[1][w:pPr/w:pStyle/@w:val != 'BoxRunInHead']">
+ <xsl:text>>&#10;</xsl:text>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="w:p[w:pPr/w:pStyle/@w:val = 'CaptionLine']">
+ <xsl:text>Figure </xsl:text>
+ <xsl:value-of select="$chapternumber" />
+ <xsl:value-of select="$appendixnumber" />
+ <xsl:text>-</xsl:text>
+ <xsl:number level="any" count="w:p[w:pPr/w:pStyle/@w:val = 'CaptionLine']" />
+ <xsl:text>: </xsl:text>
+ <xsl:apply-templates select="*" />
+ <xsl:text>&#10;&#10;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="w:tbl">
+ <xsl:apply-templates select="*" />
+ <xsl:text>&#10;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="w:tr[.//w:pStyle/@w:val = 'TableHeader']">
+ <xsl:apply-templates select="*" />
+ <xsl:text>|&#10;</xsl:text>
+ <xsl:for-each select="w:tc">
+ <xsl:text>|---</xsl:text>
+ </xsl:for-each>
+ <xsl:text>|&#10;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="w:tr">
+ <xsl:apply-templates select="*" />
+ <xsl:text>|&#10;</xsl:text>
+ </xsl:template>
+
+ <xsl:template match="w:tc">
+ <xsl:text>| </xsl:text>
+ <xsl:apply-templates select=".//w:r" />
+ <xsl:text> </xsl:text>
+ </xsl:template>
+
+ <xsl:template match="w:p[not(w:pPr)]" />
<xsl:template match="w:p">
Unmatched: <xsl:value-of select="w:pPr/w:pStyle/@w:val" />
@@ -163,9 +351,13 @@ Unmatched: <xsl:value-of select="w:pPr/w:pStyle/@w:val" />
<xsl:if test="starts-with(w:t, ' ')">
<xsl:text> </xsl:text>
</xsl:if>
- <xsl:text>`</xsl:text>
+ <xsl:if test="not(preceding-sibling::*[1][self::w:r]) or preceding-sibling::w:r[1][not(w:rPr/w:rStyle/@w:val = 'Literal') and not(w:rPr/w:rStyle/@w:val = 'LiteralBold') and not(w:rPr/w:rStyle/@w:val = 'LiteralCaption') and not(w:rPr/w:rStyle/@w:val = 'LiteralBox')]">
+ <xsl:text>`</xsl:text>
+ </xsl:if>
<xsl:value-of select="normalize-space(w:t)" />
- <xsl:text>`</xsl:text>
+ <xsl:if test="not(following-sibling::*[1][self::w:r]) or following-sibling::w:r[1][not(w:rPr/w:rStyle/@w:val = 'Literal') and not(w:rPr/w:rStyle/@w:val = 'LiteralBold') and not(w:rPr/w:rStyle/@w:val = 'LiteralCaption') and not(w:rPr/w:rStyle/@w:val = 'LiteralBox')] or following-sibling::w:r[1][w:rPr/w:rStyle/@w:val = 'Literal' and not(w:t)]">
+ <xsl:text>`</xsl:text>
+ </xsl:if>
<xsl:if test="substring(w:t, string-length(w:t)) = ' '">
<xsl:text> </xsl:text>
</xsl:if>
@@ -176,7 +368,7 @@ Unmatched: <xsl:value-of select="w:pPr/w:pStyle/@w:val" />
</xsl:choose>
</xsl:template>
- <xsl:template match="w:r[w:rPr/w:rStyle[@w:val = 'EmphasisBold']]">
+ <xsl:template match="w:r[w:rPr/w:rStyle[@w:val = 'EmphasisBold' or @w:val = 'Bold']]">
<xsl:choose>
<xsl:when test="normalize-space(w:t) != ''">
<xsl:if test="starts-with(w:t, ' ')">
@@ -195,15 +387,41 @@ Unmatched: <xsl:value-of select="w:pPr/w:pStyle/@w:val" />
</xsl:choose>
</xsl:template>
- <xsl:template match="w:r[w:rPr/w:rStyle[@w:val = 'EmphasisItalic' or @w:val = 'EmphasisItalicBox' or @w:val = 'EmphasisNote' or @w:val = 'EmphasisRevCaption' or @w:val = 'EmphasisRevItal']]">
+ <xsl:template match="w:r[w:rPr/w:rStyle[@w:val = 'EmphasisItalic' or @w:val = 'EmphasisItalicBox' or @w:val = 'EmphasisNote' or @w:val = 'EmphasisRevCaption' or @w:val = 'EmphasisRevItal' or @w:val = 'Italic' or @w:val = 'LinkURL']]">
+ <xsl:choose>
+ <xsl:when test="w:t and normalize-space(w:t) != ''">
+ <xsl:if test="starts-with(w:t, ' ')">
+ <xsl:text> </xsl:text>
+ </xsl:if>
+ <xsl:if test="not(preceding-sibling::*[1][self::w:r]) or preceding-sibling::w:r[1][not(w:t) or not(w:rPr/w:rStyle/@w:val = 'EmphasisItalic') and not(w:rPr/w:rStyle/@w:val = 'EmphasisItalicBox') and not(w:rPr/w:rStyle/@w:val = 'EmphasisNote') and not(w:rPr/w:rStyle/@w:val = 'EmphasisRevCaption') and not(w:rPr/w:rStyle/@w:val = 'EmphasisRevItal') and not(w:rPr/w:rStyle/@w:val = 'Italic') and not(w:rPr/w:rStyle/@w:val = 'LinkURL')]">
+ <xsl:text>*</xsl:text>
+ </xsl:if>
+
+ <xsl:value-of select="normalize-space(w:t)" />
+
+ <xsl:if test="not(following-sibling::*[1][self::w:r]) or following-sibling::w:r[1][not(w:t) or not(w:rPr/w:rStyle/@w:val = 'EmphasisItalic') and not(w:rPr/w:rStyle/@w:val = 'EmphasisItalicBox') and not(w:rPr/w:rStyle/@w:val = 'EmphasisNote') and not(w:rPr/w:rStyle/@w:val = 'EmphasisRevCaption') and not(w:rPr/w:rStyle/@w:val = 'EmphasisRevItal') and not(w:rPr/w:rStyle/@w:val = 'Italic') and not(w:rPr/w:rStyle/@w:val = 'LinkURL')]">
+ <xsl:text>*</xsl:text>
+ </xsl:if>
+
+ <xsl:if test="substring(w:t, string-length(w:t)) = ' '">
+ <xsl:text> </xsl:text>
+ </xsl:if>
+ </xsl:when>
+ <xsl:when test="w:t">
+ <xsl:text> </xsl:text>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match="w:r[w:rPr/w:rStyle[@w:val = 'CodeAnnotation']]">
<xsl:choose>
<xsl:when test="normalize-space(w:t) != ''">
<xsl:if test="starts-with(w:t, ' ')">
<xsl:text> </xsl:text>
</xsl:if>
- <xsl:text>*</xsl:text>
+ <xsl:text>[</xsl:text>
<xsl:value-of select="normalize-space(w:t)" />
- <xsl:text>*</xsl:text>
+ <xsl:text>]</xsl:text>
<xsl:if test="substring(w:t, string-length(w:t)) = ' '">
<xsl:text> </xsl:text>
</xsl:if>
@@ -214,6 +432,16 @@ Unmatched: <xsl:value-of select="w:pPr/w:pStyle/@w:val" />
</xsl:choose>
</xsl:template>
+ <xsl:template match="w:r[w:rPr/w:rStyle[@w:val = 'Superscript']]">
+ <xsl:if test="not(preceding-sibling::*[1][self::w:r]) or preceding-sibling::w:r[1][not(w:t) or not(w:rPr/w:rStyle/@w:val = 'Superscript')]">
+ <xsl:text>&lt;sup></xsl:text>
+ </xsl:if>
+ <xsl:value-of select="w:t" />
+ <xsl:if test="not(following-sibling::*[1][self::w:r]) or following-sibling::w:r[1][not(w:t) or not(w:rPr/w:rStyle/@w:val = 'Superscript')]">
+ <xsl:text>&lt;/sup></xsl:text>
+ </xsl:if>
+ </xsl:template>
+
<xsl:template match="w:r">
<xsl:value-of select="w:t" />
</xsl:template>
diff --git a/src/doc/embedded-book/CITATION.bib b/src/doc/embedded-book/CITATION.bib
new file mode 100644
index 000000000..5bcade5af
--- /dev/null
+++ b/src/doc/embedded-book/CITATION.bib
@@ -0,0 +1,7 @@
+@booklet{embedded-rust-book,
+ title = {The Embedded Rust Book},
+ author = {{Rust on Embedded Devices Working Group} and others},
+ date = {}, % intentionally left empty because the book has no 'publication date'
+ url = {https://docs.rust-embedded.org/book/},
+ urldate = {}, % fill this in manually
+}
diff --git a/src/doc/embedded-book/src/start/registers.md b/src/doc/embedded-book/src/start/registers.md
index 09f695a0a..d5bb3e0cc 100644
--- a/src/doc/embedded-book/src/start/registers.md
+++ b/src/doc/embedded-book/src/start/registers.md
@@ -22,7 +22,7 @@ You may well find that the code you need to access the peripherals in your micro
## Board Crate
-A board crate is the perfect starting point, if you're new to embedded Rust. They nicely abstract the HW details that might be overwelming when starting studying this subject, and makes standard tasks easy, like turning a LED on or off. The functionality it exposes varies a lot between boards. Since this book aims at staying hardware agnostic, the board crates won't be covered by this book.
+A board crate is the perfect starting point, if you're new to embedded Rust. They nicely abstract the HW details that might be overwhelming when starting studying this subject, and makes standard tasks easy, like turning a LED on or off. The functionality it exposes varies a lot between boards. Since this book aims at staying hardware agnostic, the board crates won't be covered by this book.
If you want to experiment with the STM32F3DISCOVERY board, it is highly recommmand to take a look at the [stm32f3-discovery] board crate, which provides functionality to blink the board LEDs, access its compass, bluetooth and more. The [Discovery] book offers a great introduction to the use of a board crate.
diff --git a/src/doc/index.md b/src/doc/index.md
index 744c7f709..bf08960f3 100644
--- a/src/doc/index.md
+++ b/src/doc/index.md
@@ -113,6 +113,12 @@ resources useful.
[The Reference](reference/index.html) is not a formal spec, but is more detailed and
comprehensive than the book.
+## The Style Guide
+
+[The Rust Style Guide](style-guide/index.html) describes the standard formatting of Rust
+code. Most developers use rustfmt to format their code, and rustfmt's default
+formatting matches this style guide.
+
## The Rustonomicon
[The Rustonomicon](nomicon/index.html) is your guidebook to the dark arts of unsafe
diff --git a/src/doc/nomicon/src/subtyping.md b/src/doc/nomicon/src/subtyping.md
index 91e870e5e..6f0c12db4 100644
--- a/src/doc/nomicon/src/subtyping.md
+++ b/src/doc/nomicon/src/subtyping.md
@@ -252,7 +252,7 @@ type of the referent is shared knowledge, which is why adjusting that type in on
one place (the reference) can lead to issues. But if you shrink down a reference's
lifetime when you hand it to someone, that lifetime information isn't shared in
any way. There are now two independent references with independent lifetimes.
-There's no way to mess with original reference's lifetime using the other one.
+There's no way to mess with the original reference's lifetime using the other one.
Or rather, the only way to mess with someone's lifetime is to build a meowing dog.
But as soon as you try to build a meowing dog, the lifetime should be wrapped up
diff --git a/src/doc/nomicon/src/transmutes.md b/src/doc/nomicon/src/transmutes.md
index 1f6d7d568..eea866859 100644
--- a/src/doc/nomicon/src/transmutes.md
+++ b/src/doc/nomicon/src/transmutes.md
@@ -2,7 +2,7 @@
Get out of our way type system! We're going to reinterpret these bits or die
trying! Even though this book is all about doing things that are unsafe, I
-really can't emphasize that you should deeply think about finding Another Way
+really can't emphasize enough that you should deeply think about finding Another Way
than the operations covered in this section. This is really, truly, the most
horribly unsafe thing you can do in Rust. The guardrails here are dental floss.
diff --git a/src/doc/reference/book.toml b/src/doc/reference/book.toml
index 19b9afc79..9fb3730c8 100644
--- a/src/doc/reference/book.toml
+++ b/src/doc/reference/book.toml
@@ -10,6 +10,8 @@ edit-url-template = "https://github.com/rust-lang/reference/edit/master/{path}"
[output.html.redirect]
"/expressions/enum-variant-expr.html" = "struct-expr.html"
+"/unsafe-blocks.html" = "unsafe-keyword.html"
+"/unsafe-functions.html" = "unsafe-keyword.html"
[rust]
edition = "2021"
diff --git a/src/doc/reference/src/SUMMARY.md b/src/doc/reference/src/SUMMARY.md
index 82d70d043..4d9cc1d76 100644
--- a/src/doc/reference/src/SUMMARY.md
+++ b/src/doc/reference/src/SUMMARY.md
@@ -118,8 +118,7 @@
- [Inline assembly](inline-assembly.md)
- [Unsafety](unsafety.md)
- - [Unsafe functions](unsafe-functions.md)
- - [Unsafe blocks](unsafe-blocks.md)
+ - [The `unsafe` keyword](unsafe-keyword.md)
- [Behavior considered undefined](behavior-considered-undefined.md)
- [Behavior not considered unsafe](behavior-not-considered-unsafe.md)
diff --git a/src/doc/reference/src/attributes.md b/src/doc/reference/src/attributes.md
index 857cd7d72..b7c1ef609 100644
--- a/src/doc/reference/src/attributes.md
+++ b/src/doc/reference/src/attributes.md
@@ -228,6 +228,8 @@ The following is an index of all built-in attributes.
- [`link`] — Specifies a native library to link with an `extern` block.
- [`link_name`] — Specifies the name of the symbol for functions or statics
in an `extern` block.
+ - [`link_ordinal`] — Specifies the ordinal of the symbol for functions or
+ statics in an `extern` block.
- [`no_link`] — Prevents linking an extern crate.
- [`repr`] — Controls type layout.
- [`crate_type`] — Specifies the type of crate (library, executable, etc.).
@@ -297,6 +299,7 @@ The following is an index of all built-in attributes.
[`ignore`]: attributes/testing.md#the-ignore-attribute
[`inline`]: attributes/codegen.md#the-inline-attribute
[`link_name`]: items/external-blocks.md#the-link_name-attribute
+[`link_ordinal`]: items/external-blocks.md#the-link_ordinal-attribute
[`link_section`]: abi.md#the-link_section-attribute
[`link`]: items/external-blocks.md#the-link-attribute
[`macro_export`]: macros-by-example.md#path-based-scope
diff --git a/src/doc/reference/src/attributes/codegen.md b/src/doc/reference/src/attributes/codegen.md
index 4ebabaccf..3a36a10ca 100644
--- a/src/doc/reference/src/attributes/codegen.md
+++ b/src/doc/reference/src/attributes/codegen.md
@@ -347,7 +347,7 @@ trait object whose methods are attributed.
[target architecture]: ../conditional-compilation.md#target_arch
[trait]: ../items/traits.md
[undefined behavior]: ../behavior-considered-undefined.md
-[unsafe function]: ../unsafe-functions.md
+[unsafe function]: ../unsafe-keyword.md
[rust-abi]: ../items/external-blocks.md#abi
[`core::intrinsics::caller_location`]: ../../core/intrinsics/fn.caller_location.html
[`core::panic::Location::caller`]: ../../core/panic/struct.Location.html#method.caller
diff --git a/src/doc/reference/src/attributes/derive.md b/src/doc/reference/src/attributes/derive.md
index b8909ac71..bb5631f7a 100644
--- a/src/doc/reference/src/attributes/derive.md
+++ b/src/doc/reference/src/attributes/derive.md
@@ -24,10 +24,6 @@ impl<T: PartialEq> PartialEq for Foo<T> {
fn eq(&self, other: &Foo<T>) -> bool {
self.a == other.a && self.b == other.b
}
-
- fn ne(&self, other: &Foo<T>) -> bool {
- self.a != other.a || self.b != other.b
- }
}
```
diff --git a/src/doc/reference/src/attributes/diagnostics.md b/src/doc/reference/src/attributes/diagnostics.md
index 1dd9363d8..45f9cc440 100644
--- a/src/doc/reference/src/attributes/diagnostics.md
+++ b/src/doc/reference/src/attributes/diagnostics.md
@@ -184,7 +184,7 @@ Tuple struct fields are ignored.
Here is an example:
```rust
-#[deprecated(since = "5.2", note = "foo was rarely used. Users should instead use bar")]
+#[deprecated(since = "5.2.0", note = "foo was rarely used. Users should instead use bar")]
pub fn foo() {}
pub fn bar() {}
diff --git a/src/doc/reference/src/conditional-compilation.md b/src/doc/reference/src/conditional-compilation.md
index 6966cec4f..97840e4f6 100644
--- a/src/doc/reference/src/conditional-compilation.md
+++ b/src/doc/reference/src/conditional-compilation.md
@@ -191,6 +191,25 @@ Example values:
* `"pc"`
* `"unknown"`
+### `target_has_atomic`
+
+Key-value option set for each bit width that the target supports
+atomic loads, stores, and compare-and-swap operations.
+
+When this cfg is present, all of the stable [`core::sync::atomic`] APIs are available for
+the relevant atomic width.
+
+[`core::sync::atomic`]: ../core/sync/atomic/index.html
+
+Possible values:
+
+* `"8"`
+* `"16"`
+* `"32"`
+* `"64"`
+* `"128"`
+* `"ptr"`
+
### `test`
Enabled when compiling the test harness. Done with `rustc` by using the
diff --git a/src/doc/reference/src/destructors.md b/src/doc/reference/src/destructors.md
index 6d616b3e7..242d9b2db 100644
--- a/src/doc/reference/src/destructors.md
+++ b/src/doc/reference/src/destructors.md
@@ -158,7 +158,7 @@ smallest scope that contains the expression and is one of the following:
* The entire function body.
* A statement.
-* The body of a [`if`], [`while`] or [`loop`] expression.
+* The body of an [`if`], [`while`] or [`loop`] expression.
* The `else` block of an `if` expression.
* The condition expression of an `if` or `while` expression, or a `match`
guard.
diff --git a/src/doc/reference/src/expressions.md b/src/doc/reference/src/expressions.md
index 32ee658ff..b2411cd8e 100644
--- a/src/doc/reference/src/expressions.md
+++ b/src/doc/reference/src/expressions.md
@@ -22,6 +22,7 @@
> &nbsp;&nbsp; &nbsp;&nbsp; | [_MethodCallExpression_]\
> &nbsp;&nbsp; &nbsp;&nbsp; | [_FieldExpression_]\
> &nbsp;&nbsp; &nbsp;&nbsp; | [_ClosureExpression_]\
+> &nbsp;&nbsp; &nbsp;&nbsp; | [_AsyncBlockExpression_]\
> &nbsp;&nbsp; &nbsp;&nbsp; | [_ContinueExpression_]\
> &nbsp;&nbsp; &nbsp;&nbsp; | [_BreakExpression_]\
> &nbsp;&nbsp; &nbsp;&nbsp; | [_RangeExpression_]\
@@ -34,7 +35,6 @@
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup>[†](#expression-attributes)\
> &nbsp;&nbsp; (\
> &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; [_BlockExpression_]\
-> &nbsp;&nbsp; &nbsp;&nbsp; | [_AsyncBlockExpression_]\
> &nbsp;&nbsp; &nbsp;&nbsp; | [_UnsafeBlockExpression_]\
> &nbsp;&nbsp; &nbsp;&nbsp; | [_LoopExpression_]\
> &nbsp;&nbsp; &nbsp;&nbsp; | [_IfExpression_]\
@@ -42,28 +42,24 @@
> &nbsp;&nbsp; &nbsp;&nbsp; | [_MatchExpression_]\
> &nbsp;&nbsp; )
-An expression may have two roles: it always produces a *value*, and it may have
-*effects* (otherwise known as "side effects"). An expression *evaluates to* a
-value, and has effects during *evaluation*. Many expressions contain
-sub-expressions, called the *operands* of the expression. The meaning of each
-kind of expression dictates several things:
+An expression may have two roles: it always produces a *value*, and it may have *effects* (otherwise known as "side effects").
+An expression *evaluates to* a value, and has effects during *evaluation*.
+Many expressions contain sub-expressions, called the *operands* of the expression.
+The meaning of each kind of expression dictates several things:
* Whether or not to evaluate the operands when evaluating the expression
* The order in which to evaluate the operands
* How to combine the operands' values to obtain the value of the expression
In this way, the structure of expressions dictates the structure of execution.
-Blocks are just another kind of expression, so blocks, statements, expressions,
-and blocks again can recursively nest inside each other to an arbitrary depth.
+Blocks are just another kind of expression, so blocks, statements, expressions, and blocks again can recursively nest inside each other to an arbitrary depth.
-> **Note**: We give names to the operands of expressions so that we may discuss
-> them, but these names are not stable and may be changed.
+> **Note**: We give names to the operands of expressions so that we may discuss them, but these names are not stable and may be changed.
## Expression precedence
-The precedence of Rust operators and expressions is ordered as follows, going
-from strong to weak. Binary Operators at the same precedence level are grouped
-in the order given by their associativity.
+The precedence of Rust operators and expressions is ordered as follows, going from strong to weak.
+Binary Operators at the same precedence level are grouped in the order given by their associativity.
| Operator/Expression | Associativity |
|-----------------------------|---------------------|
@@ -89,9 +85,8 @@ in the order given by their associativity.
## Evaluation order of operands
-The following list of expressions all evaluate their operands the same way, as
-described after the list. Other expressions either don't take operands or
-evaluate them conditionally as described on their respective pages.
+The following list of expressions all evaluate their operands the same way, as described after the list.
+Other expressions either don't take operands or evaluate them conditionally as described on their respective pages.
* Dereference expression
* Error propagation expression
@@ -113,15 +108,13 @@ evaluate them conditionally as described on their respective pages.
* Range expression
* Return expression
-The operands of these expressions are evaluated prior to applying the effects of
-the expression. Expressions taking multiple operands are evaluated left to right
-as written in the source code.
+The operands of these expressions are evaluated prior to applying the effects of the expression.
+Expressions taking multiple operands are evaluated left to right as written in the source code.
> **Note**: Which subexpressions are the operands of an expression is
> determined by expression precedence as per the previous section.
-For example, the two `next` method calls will always be called in the same
-order:
+For example, the two `next` method calls will always be called in the same order:
```rust
# // Using vec instead of array to avoid references
@@ -134,23 +127,18 @@ assert_eq!(
);
```
-> **Note**: Since this is applied recursively, these expressions are also
-> evaluated from innermost to outermost, ignoring siblings until there are no
-> inner subexpressions.
+> **Note**: Since this is applied recursively, these expressions are also evaluated from innermost to outermost, ignoring siblings until there are no inner subexpressions.
## Place Expressions and Value Expressions
-Expressions are divided into two main categories: place expressions and value
-expressions; there is also a third, minor category of expressions called
-assignee expressions. Within each expression, operands may likewise occur in
-either place context or value context. The evaluation of an expression depends
-both on its own category and the context it occurs within.
+Expressions are divided into two main categories: place expressions and value expressions;
+there is also a third, minor category of expressions called assignee expressions.
+Within each expression, operands may likewise occur in either place context or value context.
+The evaluation of an expression depends both on its own category and the context it occurs within.
-A *place expression* is an expression that represents a memory location. These
-expressions are [paths] which refer to local variables, [static variables],
-[dereferences][deref] (`*expr`), [array indexing] expressions (`expr[expr]`),
-[field] references (`expr.f`) and parenthesized place expressions. All other
-expressions are value expressions.
+A *place expression* is an expression that represents a memory location.
+These expressions are [paths] which refer to local variables, [static variables], [dereferences][deref] (`*expr`), [array indexing] expressions (`expr[expr]`), [field] references (`expr.f`) and parenthesized place expressions.
+All other expressions are value expressions.
A *value expression* is an expression that represents an actual value.
@@ -166,11 +154,10 @@ The following contexts are *place expression* contexts:
expression.
* The base of a [functional update] struct expression.
-> Note: Historically, place expressions were called *lvalues* and value
-> expressions were called *rvalues*.
+> Note: Historically, place expressions were called *lvalues* and value expressions were called *rvalues*.
-An *assignee expression* is an expression that appears in the left operand of an
-[assignment][assign] expression. Explicitly, the assignee expressions are:
+An *assignee expression* is an expression that appears in the left operand of an [assignment][assign] expression.
+Explicitly, the assignee expressions are:
- Place expressions.
- [Underscores][_UnderscoreExpression_].
@@ -185,59 +172,49 @@ Arbitrary parenthesisation is permitted inside assignee expressions.
### Moved and copied types
-When a place expression is evaluated in a value expression context, or is bound
-by value in a pattern, it denotes the value held _in_ that memory location. If
-the type of that value implements [`Copy`], then the value will be copied. In
-the remaining situations, if that type is [`Sized`], then it may be possible to
-move the value. Only the following place expressions may be moved out of:
+When a place expression is evaluated in a value expression context, or is bound by value in a pattern, it denotes the value held _in_ that memory location.
+If the type of that value implements [`Copy`], then the value will be copied.
+In the remaining situations, if that type is [`Sized`], then it may be possible to move the value.
+Only the following place expressions may be moved out of:
* [Variables] which are not currently borrowed.
* [Temporary values](#temporaries).
-* [Fields][field] of a place expression which can be moved out of and
- don't implement [`Drop`].
-* The result of [dereferencing][deref] an expression with type [`Box<T>`] and
- that can also be moved out of.
+* [Fields][field] of a place expression which can be moved out of and don't implement [`Drop`].
+* The result of [dereferencing][deref] an expression with type [`Box<T>`] and that can also be moved out of.
-After moving out of a place expression that evaluates to a local variable, the
-location is deinitialized and cannot be read from again until it is
-reinitialized. In all other cases, trying to use a place expression in a value
-expression context is an error.
+After moving out of a place expression that evaluates to a local variable, the location is deinitialized and cannot be read from again until it is reinitialized.
+In all other cases, trying to use a place expression in a value expression context is an error.
### Mutability
-For a place expression to be [assigned][assign] to, mutably [borrowed][borrow],
-[implicitly mutably borrowed], or bound to a pattern containing `ref mut`, it
-must be _mutable_. We call these *mutable place expressions*. In contrast,
-other place expressions are called *immutable place expressions*.
+For a place expression to be [assigned][assign] to, mutably [borrowed][borrow], [implicitly mutably borrowed], or bound to a pattern containing `ref mut`, it must be _mutable_.
+We call these *mutable place expressions*.
+In contrast, other place expressions are called *immutable place expressions*.
The following expressions can be mutable place expression contexts:
* Mutable [variables] which are not currently borrowed.
* [Mutable `static` items].
* [Temporary values].
-* [Fields][field]: this evaluates the subexpression in a mutable place
- expression context.
+* [Fields][field]: this evaluates the subexpression in a mutable place expression context.
* [Dereferences][deref] of a `*mut T` pointer.
-* Dereference of a variable, or field of a variable, with type `&mut T`. Note:
- This is an exception to the requirement of the next rule.
-* Dereferences of a type that implements `DerefMut`: this then requires that
- the value being dereferenced is evaluated in a mutable place expression context.
-* [Array indexing] of a type that implements `IndexMut`: this
- then evaluates the value being indexed, but not the index, in mutable place
- expression context.
+* Dereference of a variable, or field of a variable, with type `&mut T`.
+ Note: This is an exception to the requirement of the next rule.
+* Dereferences of a type that implements `DerefMut`:
+ this then requires that the value being dereferenced is evaluated in a mutable place expression context.
+* [Array indexing] of a type that implements `IndexMut`:
+ this then evaluates the value being indexed, but not the index, in mutable place expression context.
### Temporaries
-When using a value expression in most place expression contexts, a temporary
-unnamed memory location is created and initialized to that value. The expression
-evaluates to that location instead, except if [promoted] to a `static`. The
-[drop scope] of the temporary is usually the end of the enclosing statement.
+When using a value expression in most place expression contexts, a temporary unnamed memory location is created and initialized to that value.
+The expression evaluates to that location instead, except if [promoted] to a `static`.
+The [drop scope] of the temporary is usually the end of the enclosing statement.
### Implicit Borrows
-Certain expressions will treat an expression as a place expression by implicitly
-borrowing it. For example, it is possible to compare two unsized [slices][slice] for
-equality directly, because the `==` operator implicitly borrows its operands:
+Certain expressions will treat an expression as a place expression by implicitly borrowing it.
+For example, it is possible to compare two unsized [slices][slice] for equality directly, because the `==` operator implicitly borrows its operands:
```rust
# let c = [1, 2, 3];
@@ -264,31 +241,21 @@ Implicit borrows may be taken in the following expressions:
## Overloading Traits
-Many of the following operators and expressions can also be overloaded for
-other types using traits in `std::ops` or `std::cmp`. These traits also
-exist in `core::ops` and `core::cmp` with the same names.
+Many of the following operators and expressions can also be overloaded for other types using traits in `std::ops` or `std::cmp`.
+These traits also exist in `core::ops` and `core::cmp` with the same names.
## Expression Attributes
-[Outer attributes][_OuterAttribute_] before an expression are allowed only in
-a few specific cases:
+[Outer attributes][_OuterAttribute_] before an expression are allowed only in a few specific cases:
* Before an expression used as a [statement].
-* Elements of [array expressions], [tuple expressions], [call expressions],
- and tuple-style [struct] expressions.
- <!--
- These were likely stabilized inadvertently.
- See https://github.com/rust-lang/rust/issues/32796 and
- https://github.com/rust-lang/rust/issues/15701
- -->
+* Elements of [array expressions], [tuple expressions], [call expressions], and tuple-style [struct] expressions.
* The tail expression of [block expressions].
<!-- Keep list in sync with block-expr.md -->
They are never allowed before:
* [Range][_RangeExpression_] expressions.
-* Binary operator expressions ([_ArithmeticOrLogicalExpression_],
- [_ComparisonExpression_], [_LazyBooleanExpression_], [_TypeCastExpression_],
- [_AssignmentExpression_], [_CompoundAssignmentExpression_]).
+* Binary operator expressions ([_ArithmeticOrLogicalExpression_], [_ComparisonExpression_], [_LazyBooleanExpression_], [_TypeCastExpression_], [_AssignmentExpression_], [_CompoundAssignmentExpression_]).
[block expressions]: expressions/block-expr.md
diff --git a/src/doc/reference/src/expressions/block-expr.md b/src/doc/reference/src/expressions/block-expr.md
index a68b27e56..bd9c0a623 100644
--- a/src/doc/reference/src/expressions/block-expr.md
+++ b/src/doc/reference/src/expressions/block-expr.md
@@ -103,7 +103,7 @@ Async contexts are established by async blocks as well as the bodies of async fu
Async blocks act like a function boundary, much like closures.
Therefore, the `?` operator and `return` expressions both affect the output of the future, not the enclosing function or other context.
-That is, `return <expr>` from within a closure will return the result of `<expr>` as the output of the future.
+That is, `return <expr>` from within an async block will return the result of `<expr>` as the output of the future.
Similarly, if `<expr>?` propagates an error, that error is propagated as the result of the future.
Finally, the `break` and `continue` keywords cannot be used to branch out from an async block.
@@ -112,7 +112,7 @@ Therefore the following is illegal:
```rust,compile_fail
loop {
async move {
- break; // This would break out of the loop.
+ break; // error[E0267]: `break` inside of an `async` block
}
}
```
@@ -140,6 +140,10 @@ unsafe {
let a = unsafe { an_unsafe_fn() };
```
+## Labelled block expressions
+
+Labelled block expressions are documented in the [Loops and other breakable expressions] section.
+
## Attributes on block expressions
[Inner attributes] are allowed directly after the opening brace of a block expression in the following situations:
@@ -189,3 +193,4 @@ fn is_unix_platform() -> bool {
[tuple expressions]: tuple-expr.md
[unsafe operations]: ../unsafety.md
[value expressions]: ../expressions.md#place-expressions-and-value-expressions
+[Loops and other breakable expressions]: loop-expr.md#labelled-block-expressions
diff --git a/src/doc/reference/src/expressions/closure-expr.md b/src/doc/reference/src/expressions/closure-expr.md
index bdc177bb5..103f74795 100644
--- a/src/doc/reference/src/expressions/closure-expr.md
+++ b/src/doc/reference/src/expressions/closure-expr.md
@@ -12,7 +12,7 @@
> _ClosureParam_ :\
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup> [_PatternNoTopAlt_]&nbsp;( `:` [_Type_] )<sup>?</sup>
-A *closure expression*, also know as a lambda expression or a lambda, defines a [closure type] and evaluates to a value of that type.
+A *closure expression*, also known as a lambda expression or a lambda, defines a [closure type] and evaluates to a value of that type.
The syntax for a closure expression is an optional `move` keyword, then a pipe-symbol-delimited (`|`) comma-separated list of [patterns], called the *closure parameters* each optionally followed by a `:` and a type, then an optional `->` and type, called the *return type*, and then an expression, called the *closure body operand*.
The optional type after each pattern is a type annotation for the pattern.
If there is a return type, the closure body must be a [block].
diff --git a/src/doc/reference/src/expressions/grouped-expr.md b/src/doc/reference/src/expressions/grouped-expr.md
index 0ff7e2c90..1ae2209c5 100644
--- a/src/doc/reference/src/expressions/grouped-expr.md
+++ b/src/doc/reference/src/expressions/grouped-expr.md
@@ -16,8 +16,8 @@ Parentheses can be used to explicitly modify the precedence order of subexpressi
An example of a parenthesized expression:
```rust
-let x: i32 = 2 + 3 * 4;
-let y: i32 = (2 + 3) * 4;
+let x: i32 = 2 + 3 * 4; // not parenthesized
+let y: i32 = (2 + 3) * 4; // parenthesized
assert_eq!(x, 14);
assert_eq!(y, 20);
```
diff --git a/src/doc/reference/src/expressions/loop-expr.md b/src/doc/reference/src/expressions/loop-expr.md
index 308f3e346..204207ee0 100644
--- a/src/doc/reference/src/expressions/loop-expr.md
+++ b/src/doc/reference/src/expressions/loop-expr.md
@@ -1,4 +1,4 @@
-# Loops
+# Loops and other breakable expressions
> **<sup>Syntax</sup>**\
> _LoopExpression_ :\
@@ -7,6 +7,7 @@
> &nbsp;&nbsp; &nbsp;&nbsp; | [_PredicateLoopExpression_]\
> &nbsp;&nbsp; &nbsp;&nbsp; | [_PredicatePatternLoopExpression_]\
> &nbsp;&nbsp; &nbsp;&nbsp; | [_IteratorLoopExpression_]\
+> &nbsp;&nbsp; &nbsp;&nbsp; | [_LabelBlockExpression_]\
> &nbsp;&nbsp; )
[_LoopLabel_]: #loop-labels
@@ -14,16 +15,19 @@
[_PredicateLoopExpression_]: #predicate-loops
[_PredicatePatternLoopExpression_]: #predicate-pattern-loops
[_IteratorLoopExpression_]: #iterator-loops
+[_LabelBlockExpression_]: #labelled-block-expressions
-Rust supports four loop expressions:
+Rust supports five loop expressions:
* A [`loop` expression](#infinite-loops) denotes an infinite loop.
* A [`while` expression](#predicate-loops) loops until a predicate is false.
* A [`while let` expression](#predicate-pattern-loops) tests a pattern.
* A [`for` expression](#iterator-loops) extracts values from an iterator, looping until the iterator is empty.
+* A [labelled block expression](#labelled-block-expressions) runs a loop exactly once, but allows exiting the loop early with `break`.
-All four types of loop support [`break` expressions](#break-expressions), [`continue` expressions](#continue-expressions), and [labels](#loop-labels).
-Only `loop` supports [evaluation to non-trivial values](#break-and-loop-values).
+All five types of loop support [`break` expressions](#break-expressions), and [labels](#loop-labels).
+All except labelled block expressions support [`continue` expressions](#continue-expressions).
+Only `loop` and labelled block expressions support [evaluation to non-trivial values](#break-and-loop-values).
## Infinite loops
@@ -193,6 +197,18 @@ A loop expression may optionally have a _label_. The label is written as a lifet
If a label is present, then labeled `break` and `continue` expressions nested within this loop may exit out of this loop or return control to its head.
See [break expressions](#break-expressions) and [continue expressions](#continue-expressions).
+Labels follow the hygiene and shadowing rules of local variables. For example, this code will print "outer loop":
+
+```rust
+'a: loop {
+ 'a: loop {
+ break 'a;
+ }
+ print!("outer loop");
+ break 'a;
+}
+```
+
## `break` expressions
> **<sup>Syntax</sup>**\
@@ -226,6 +242,16 @@ Example:
A `break` expression is only permitted in the body of a loop, and has one of the forms `break`, `break 'label` or ([see below](#break-and-loop-values)) `break EXPR` or `break 'label EXPR`.
+## Labelled block expressions
+
+> **<sup>Syntax</sup>**\
+> _LabelBlockExpression_ :\
+> &nbsp;&nbsp; [_BlockExpression_]
+
+Labelled block expressions are exactly like block expressions, except that they allow using `break` expressions within the block.
+Unlike other loops, `break` expressions within a label expression *must* have a label (i.e. the label is not optional).
+Unlike other loops, labelled block expressions *must* begin with a label.
+
## `continue` expressions
> **<sup>Syntax</sup>**\
diff --git a/src/doc/reference/src/identifiers.md b/src/doc/reference/src/identifiers.md
index a4e972cd3..c760f6826 100644
--- a/src/doc/reference/src/identifiers.md
+++ b/src/doc/reference/src/identifiers.md
@@ -13,7 +13,7 @@
> NON_KEYWORD_IDENTIFIER | RAW_IDENTIFIER
<!-- When updating the version, update the UAX links, too. -->
-Identifiers follow the specification in [Unicode Standard Annex #31][UAX31] for Unicode version 13.0, with the additions described below. Some examples of identifiers:
+Identifiers follow the specification in [Unicode Standard Annex #31][UAX31] for Unicode version 15.0, with the additions described below. Some examples of identifiers:
* `foo`
* `_identifier`
@@ -68,5 +68,5 @@ keyword except the ones listed above for `RAW_IDENTIFIER`.
[proc-macro]: procedural-macros.md
[reserved]: keywords.md#reserved-keywords
[strict]: keywords.md#strict-keywords
-[UAX15]: https://www.unicode.org/reports/tr15/tr15-50.html
-[UAX31]: https://www.unicode.org/reports/tr31/tr31-33.html
+[UAX15]: https://www.unicode.org/reports/tr15/tr15-53.html
+[UAX31]: https://www.unicode.org/reports/tr31/tr31-37.html
diff --git a/src/doc/reference/src/inline-assembly.md b/src/doc/reference/src/inline-assembly.md
index 6233475a3..996b157da 100644
--- a/src/doc/reference/src/inline-assembly.md
+++ b/src/doc/reference/src/inline-assembly.md
@@ -123,12 +123,17 @@ Several types of operands are supported:
* `inlateout(<reg>) <expr>` / `inlateout(<reg>) <in expr> => <out expr>`
- Identical to `inout` except that the register allocator can reuse a register allocated to an `in` (this can happen if the compiler knows the `in` has the same initial value as the `inlateout`).
- You should only write to the register after all inputs are read, otherwise you may clobber an input.
+* `sym <path>`
+ - `<path>` must refer to a `fn` or `static`.
+ - A mangled symbol name referring to the item is substituted into the asm template string.
+ - The substituted string does not include any modifiers (e.g. GOT, PLT, relocations, etc).
+ - `<path>` is allowed to point to a `#[thread_local]` static, in which case the asm code can combine the symbol with relocations (e.g. `@plt`, `@TPOFF`) to read from thread-local data.
Operand expressions are evaluated from left to right, just like function call arguments.
After the `asm!` has executed, outputs are written to in left to right order.
This is significant if two outputs point to the same place: that place will contain the value of the rightmost output.
-Since `global_asm!` exists outside a function, it cannot use input/output operands.
+Since `global_asm!` exists outside a function, it can only use `sym` operands.
## Register operands
diff --git a/src/doc/reference/src/items/associated-items.md b/src/doc/reference/src/items/associated-items.md
index f5dc31aae..2401127b5 100644
--- a/src/doc/reference/src/items/associated-items.md
+++ b/src/doc/reference/src/items/associated-items.md
@@ -205,22 +205,49 @@ types cannot be defined in [inherent implementations] nor can they be given a
default implementation in traits.
An *associated type declaration* declares a signature for associated type
-definitions. It is written as `type`, then an [identifier], and
-finally an optional list of trait bounds.
+definitions. It is written in one of the following forms, where `Assoc` is the
+name of the associated type, `Params` is a comma-separated list of type,
+lifetime or const parameters, `Bounds` is a plus-separated list of trait bounds
+that the associated type must meet, and `WhereBounds` is a comma-separated list
+of bounds that the parameters must meet:
+
+<!-- ignore: illustrative example forms -->
+```rust,ignore
+type Assoc;
+type Assoc: Bounds;
+type Assoc<Params>;
+type Assoc<Params>: Bounds;
+type Assoc<Params> where WhereBounds;
+type Assoc<Params>: Bounds where WhereBounds;
+```
The identifier is the name of the declared type alias. The optional trait bounds
must be fulfilled by the implementations of the type alias.
There is an implicit [`Sized`] bound on associated types that can be relaxed using the special `?Sized` bound.
-An *associated type definition* defines a type alias on another type. It is
-written as `type`, then an [identifier], then an `=`, and finally a [type].
+An *associated type definition* defines a type alias for the implementation
+of a trait on a type. They are written similarly to an *associated type declaration*,
+but cannot contain `Bounds`, but instead must contain a `Type`:
+
+<!-- ignore: illustrative example forms -->
+```rust,ignore
+type Assoc = Type;
+type Assoc<Params> = Type; // the type `Type` here may reference `Params`
+type Assoc<Params> = Type where WhereBounds;
+type Assoc<Params> where WhereBounds = Type; // deprecated, prefer the form above
+```
If a type `Item` has an associated type `Assoc` from a trait `Trait`, then
`<Item as Trait>::Assoc` is a type that is an alias of the type specified in the
associated type definition. Furthermore, if `Item` is a type parameter, then
`Item::Assoc` can be used in type parameters.
-Associated types must not include [generic parameters] or [where clauses].
+Associated types may include [generic parameters] and [where clauses]; these are
+often referred to as *generic associated types*, or *GATs*. If the type `Thing`
+has an associated type `Item` from a trait `Trait` with the generics `<'a>` , the
+type can be named like `<Thing as Trait>::Item<'x>`, where `'x` is some lifetime
+in scope. In this case, `'x` will be used wherever `'a` appears in the associated
+type definitions on impls.
```rust
trait AssociatedType {
@@ -249,6 +276,37 @@ fn main() {
}
```
+An example of associated types with generics and where clauses:
+
+```rust
+struct ArrayLender<'a, T>(&'a mut [T; 16]);
+
+trait Lend {
+ // Generic associated type declaration
+ type Lender<'a> where Self: 'a;
+ fn lend<'a>(&'a mut self) -> Self::Lender<'a>;
+}
+
+impl<T> Lend for [T; 16] {
+ // Generic associated type definition
+ type Lender<'a> = ArrayLender<'a, T> where Self: 'a;
+
+ fn lend<'a>(&'a mut self) -> Self::Lender<'a> {
+ ArrayLender(self)
+ }
+}
+
+fn borrow<'a, T: Lend>(array: &'a mut T) -> <T as Lend>::Lender<'a> {
+ array.lend()
+}
+
+
+fn main() {
+ let mut array = [0usize; 16];
+ let lender = borrow(&mut array);
+}
+```
+
### Associated Types Container Example
Consider the following example of a `Container` trait. Notice that the type is
@@ -279,6 +337,83 @@ impl<T> Container for Vec<T> {
}
```
+### Relationship between `Bounds` and `WhereBounds`
+
+In this example:
+
+```rust
+# use std::fmt::Debug;
+trait Example {
+ type Output<T>: Ord where T: Debug;
+}
+```
+
+Given a reference to the associated type like `<X as Example>::Output<Y>`, the associated type itself must be `Ord`, and the type `Y` must be `Debug`.
+
+### Required where clauses on generic associated types
+
+Generic associated type declarations on traits currently may require a list of
+where clauses, dependent on functions in the trait and how the GAT is used. These
+rules may be loosened in the future; updates can be found [on the generic
+associated types initiative repository](https://rust-lang.github.io/generic-associated-types-initiative/explainer/required_bounds.html).
+
+In a few words, these where clauses are required in order to maximize the allowed
+definitions of the associated type in impls. To do this, any clauses that *can be
+proven to hold* on functions (using the parameters of the function or trait)
+where a GAT appears as an input or output must also be written on the GAT itself.
+
+```rust
+trait LendingIterator {
+ type Item<'x> where Self: 'x;
+ fn next<'a>(&'a mut self) -> Self::Item<'a>;
+}
+```
+
+In the above, on the `next` function, we can prove that `Self: 'a`, because of
+the implied bounds from `&'a mut self`; therefore, we must write the equivalent
+bound on the GAT itself: `where Self: 'x`.
+
+When there are multiple functions in a trait that use the GAT, then the
+*intersection* of the bounds from the different functions are used, rather than
+the union.
+
+```rust
+trait Check<T> {
+ type Checker<'x>;
+ fn create_checker<'a>(item: &'a T) -> Self::Checker<'a>;
+ fn do_check(checker: Self::Checker<'_>);
+}
+```
+
+In this example, no bounds are required on the `type Checker<'a>;`. While we
+know that `T: 'a` on `create_checker`, we do not know that on `do_check`. However,
+if `do_check` was commented out, then the `where T: 'x` bound would be required
+on `Checker`.
+
+The bounds on associated types also propagate required where clauses.
+
+```rust
+trait Iterable {
+ type Item<'a> where Self: 'a;
+ type Iterator<'a>: Iterator<Item = Self::Item<'a>> where Self: 'a;
+ fn iter<'a>(&'a self) -> Self::Iterator<'a>;
+}
+```
+
+Here, `where Self: 'a` is required on `Item` because of `iter`. However, `Item`
+is used in the bounds of `Iterator`, the `where Self: 'a` clause is also required
+there.
+
+Finally, any explicit uses of `'static` on GATs in the trait do not count towards
+the required bounds.
+
+```rust
+trait StaticReturn {
+ type Y<'a>;
+ fn foo(&self) -> Self::Y<'static>;
+}
+```
+
## Associated Constants
*Associated constants* are [constants] associated with a type.
diff --git a/src/doc/reference/src/items/external-blocks.md b/src/doc/reference/src/items/external-blocks.md
index e768a1502..c91e1d10c 100644
--- a/src/doc/reference/src/items/external-blocks.md
+++ b/src/doc/reference/src/items/external-blocks.md
@@ -122,6 +122,9 @@ specifies the kind of library with the following possible values:
- `static` — Indicates a static library.
- `framework` — Indicates a macOS framework. This is only valid for macOS
targets.
+- `raw-dylib` — Indicates a dynamic library where the compiler will generate
+ an import library to link against (see [`dylib` versus `raw-dylib`] below
+ for details). This is only valid for Windows targets.
The `name` key must be included if `kind` is specified.
@@ -198,9 +201,26 @@ The default for this modifier is `-whole-archive`.
More implementation details about this modifier can be found in
[`whole-archive` documentation for rustc].
+#### `dylib` versus `raw-dylib`
+
+On Windows, linking against a dynamic library requires that an import library
+is provided to the linker: this is a special static library that declares all
+of the symbols exported by the dynamic library in such a way that the linker
+knows that they have to be dynamically loaded at runtime.
+
+Specifying `kind = "dylib"` instructs the Rust compiler to link an import
+library based on the `name` key. The linker will then use its normal library
+resolution logic to find that import library. Alternatively, specifying
+`kind = "raw-dylib"` instructs the compiler to generate an import library
+during compilation and provide that to the linker instead.
+
+`raw-dylib` is only supported on Windows and not supported on 32-bit x86
+(`target_arch="x86"`). Using it when targeting other platforms or
+x86 on Windows will result in a compiler error.
+
### The `link_name` attribute
-The `link_name` attribute may be specified on declarations inside an `extern`
+The *`link_name` attribute* may be specified on declarations inside an `extern`
block to indicate the symbol to import for the given function or static. It
uses the [_MetaNameValueStr_] syntax to specify the name of the symbol.
@@ -211,6 +231,41 @@ extern {
}
```
+Using this attribute with the `link_ordinal` attribute will result in a
+compiler error.
+
+### The `link_ordinal` attribute
+
+The *`link_ordinal` attribute* can be applied on declarations inside an `extern`
+block to indicate the numeric ordinal to use when generating the import library
+to link against. An ordinal is a unique number per symbol exported by a dynamic
+library on Windows and can be used when the library is being loaded to find
+that symbol rather than having to look it up by name.
+
+<div class="warning">
+
+Warning: `link_ordinal` should only be used in cases where the ordinal of the
+symbol is known to be stable: if the ordinal of a symbol is not explicitly set
+when its containing binary is built then one will be automatically assigned to
+it, and that assigned ordinal may change between builds of the binary.
+
+</div>
+
+<!-- ignore: Only works on x86 Windows -->
+```rust,ignore
+#[link(name = "exporter", kind = "raw-dylib")]
+extern "stdcall" {
+ #[link_ordinal(15)]
+ fn imported_function_stdcall(i: i32);
+}
+```
+
+This attribute is only used with the `raw-dylib` linking kind.
+Using any other kind will result in a compiler error.
+
+Using this attribute with the `link_name` attribute will result in a
+compiler error.
+
### Attributes on function parameters
Attributes on extern function parameters follow the same rules and
@@ -233,3 +288,4 @@ restrictions as [regular function parameters].
[regular function parameters]: functions.md#attributes-on-function-parameters
[`bundle` documentation for rustc]: ../../rustc/command-line-arguments.html#linking-modifiers-bundle
[`whole-archive` documentation for rustc]: ../../rustc/command-line-arguments.html#linking-modifiers-whole-archive
+[`dylib` versus `raw-dylib`]: #dylib-versus-raw-dylib
diff --git a/src/doc/reference/src/items/functions.md b/src/doc/reference/src/items/functions.md
index 325588a53..5b4ac7af6 100644
--- a/src/doc/reference/src/items/functions.md
+++ b/src/doc/reference/src/items/functions.md
@@ -59,8 +59,8 @@ fn answer_to_life_the_universe_and_everything() -> i32 {
## Function parameters
-As with `let` bindings, function parameters are irrefutable [patterns], so any
-pattern that is valid in a let binding is also valid as a parameter:
+Function parameters are irrefutable [patterns], so any pattern that is valid in
+an else-less `let` binding is also valid as a parameter:
```rust
fn first((value, _): (i32, i32)) -> i32 { value }
diff --git a/src/doc/reference/src/items/traits.md b/src/doc/reference/src/items/traits.md
index 26870a0fc..3c5d31d5c 100644
--- a/src/doc/reference/src/items/traits.md
+++ b/src/doc/reference/src/items/traits.md
@@ -70,6 +70,7 @@ Object safe traits can be the base trait of a [trait object]. A trait is
* All [supertraits] must also be object safe.
* `Sized` must not be a [supertrait][supertraits]. In other words, it must not require `Self: Sized`.
* It must not have any associated constants.
+* It must not have any associated types with generics.
* All associated functions must either be dispatchable from a trait object or be explicitly non-dispatchable:
* Dispatchable functions require:
* Not have any type parameters (although lifetime parameters are allowed),
diff --git a/src/doc/reference/src/items/type-aliases.md b/src/doc/reference/src/items/type-aliases.md
index ff0cc75f7..d2e14b903 100644
--- a/src/doc/reference/src/items/type-aliases.md
+++ b/src/doc/reference/src/items/type-aliases.md
@@ -4,7 +4,7 @@
> _TypeAlias_ :\
> &nbsp;&nbsp; `type` [IDENTIFIER]&nbsp;[_GenericParams_]<sup>?</sup>
> ( `:` [_TypeParamBounds_] )<sup>?</sup>
-> [_WhereClause_]<sup>?</sup> ( `=` [_Type_] )<sup>?</sup> `;`
+> [_WhereClause_]<sup>?</sup> ( `=` [_Type_] [_WhereClause_]<sup>?</sup>)<sup>?</sup> `;`
A _type alias_ defines a new name for an existing [type]. Type aliases are
declared with the keyword `type`. Every value has a single, specific type, but
@@ -31,11 +31,18 @@ let _ = UseAlias(5); // OK
let _ = TypeAlias(5); // Doesn't work
```
-A type alias without the [_Type_] specification may only appear as an
-[associated type] in a [trait].
+A type alias, when not used as an associated type, must include a [_Type_] and
+may not include [_TypeParamBounds_].
-A type alias with [_TypeParamBounds_] may only specified when used as
-an [associated type] in a [trait].
+A type alias, when used as an [associated type] in a [trait], must not include a
+[_Type_] specification but may include [_TypeParamBounds_].
+
+A type alias, when used as an [associated type] in a [trait impl], must include
+a [_Type_] specification and may not include [_TypeParamBounds_].
+
+Where clauses before the equals sign on a type alias in a [trait impl] (like
+`type TypeAlias<T> where T: Foo = Bar<T>`) are deprecated. Where clauses after
+the equals sign (like `type TypeAlias<T> = Bar<T> where T: Foo`) are preferred.
[IDENTIFIER]: ../identifiers.md
[_GenericParams_]: generics.md
@@ -45,3 +52,4 @@ an [associated type] in a [trait].
[associated type]: associated-items.md#associated-types
[trait]: traits.md
[type]: ../types.md
+[trait impl]: implementations.md#trait-implementations
diff --git a/src/doc/reference/src/patterns.md b/src/doc/reference/src/patterns.md
index 5c81ecd87..14bbac155 100644
--- a/src/doc/reference/src/patterns.md
+++ b/src/doc/reference/src/patterns.md
@@ -22,18 +22,16 @@
> &nbsp;&nbsp; | [_PathPattern_]\
> &nbsp;&nbsp; | [_MacroInvocation_]
-Patterns are used to match values against structures and to,
-optionally, bind variables to values inside these structures. They are also
-used in variable declarations and parameters for functions and closures.
+Patterns are used to match values against structures and to, optionally, bind variables to values inside these structures.
+They are also used in variable declarations and parameters for functions and closures.
The pattern in the following example does four things:
* Tests if `person` has the `car` field filled with something.
-* Tests if the person's `age` field is between 13 and 19, and binds its value to
- the `person_age` variable.
+* Tests if the person's `age` field is between 13 and 19, and binds its value to the `person_age` variable.
* Binds a reference to the `name` field to the variable `person_name`.
-* Ignores the rest of the fields of `person`. The remaining fields can have any value and
- are not bound to any variables.
+* Ignores the rest of the fields of `person`.
+ The remaining fields can have any value and are not bound to any variables.
```rust
# struct Car;
@@ -65,8 +63,7 @@ if let
Patterns are used in:
* [`let` declarations](statements.md#let-statements)
-* [Function](items/functions.md) and [closure](expressions/closure-expr.md)
- parameters
+* [Function](items/functions.md) and [closure](expressions/closure-expr.md) parameters
* [`match` expressions](expressions/match-expr.md)
* [`if let` expressions](expressions/if-expr.md)
* [`while let` expressions](expressions/loop-expr.md#predicate-pattern-loops)
@@ -75,13 +72,10 @@ Patterns are used in:
## Destructuring
Patterns can be used to *destructure* [structs], [enums], and [tuples].
-Destructuring breaks up a value into its component pieces. The syntax used is
-almost the same as when creating such values. In a pattern whose [scrutinee]
-expression has a `struct`, `enum` or `tuple` type, a placeholder (`_`) stands
-in for a *single* data field, whereas a wildcard `..` stands in for *all* the
-remaining fields of a particular variant. When destructuring a data structure
-with named (but not numbered) fields, it is allowed to write `fieldname` as a
-shorthand for `fieldname: fieldname`.
+Destructuring breaks up a value into its component pieces.
+The syntax used is almost the same as when creating such values.
+In a pattern whose [scrutinee] expression has a `struct`, `enum` or `tuple` type, a placeholder (`_`) stands in for a *single* data field, whereas a wildcard `..` stands in for *all* the remaining fields of a particular variant.
+When destructuring a data structure with named (but not numbered) fields, it is allowed to write `fieldname` as a shorthand for `fieldname: fieldname`.
```rust
# enum Message {
@@ -104,9 +98,9 @@ match message {
## Refutability
-A pattern is said to be *refutable* when it has the possibility of not being matched
-by the value it is being matched against. *Irrefutable* patterns, on the other hand,
-always match the value they are being matched against. Examples:
+A pattern is said to be *refutable* when it has the possibility of not being matched by the value it is being matched against.
+*Irrefutable* patterns, on the other hand, always match the value they are being matched against.
+Examples:
```rust
let (x, y) = (1, 2); // "(x, y)" is an irrefutable pattern
@@ -141,16 +135,12 @@ if let (a, 3) = (1, 2) { // "(a, 3)" is refutable, and will not match
[INTEGER_LITERAL]: tokens.md#integer-literals
[FLOAT_LITERAL]: tokens.md#floating-point-literals
-_Literal patterns_ match exactly the same value as what is created by the
-literal. Since negative numbers are not [literals], literal patterns also
-accept an optional minus sign before the literal, which acts like the negation
-operator.
+_Literal patterns_ match exactly the same value as what is created by the literal.
+Since negative numbers are not [literals], literal patterns also accept an optional minus sign before the literal, which acts like the negation operator.
<div class="warning">
-Floating-point literals are currently accepted, but due to the complexity of comparing
-them, they are going to be forbidden on literal patterns in a future version of Rust (see
-[issue #41620](https://github.com/rust-lang/rust/issues/41620)).
+Floating-point literals are currently accepted, but due to the complexity of comparing them, they are going to be forbidden on literal patterns in a future version of Rust (see [issue #41620](https://github.com/rust-lang/rust/issues/41620)).
</div>
@@ -175,14 +165,13 @@ for i in -2..5 {
> _IdentifierPattern_ :\
> &nbsp;&nbsp; &nbsp;&nbsp; `ref`<sup>?</sup> `mut`<sup>?</sup> [IDENTIFIER] (`@` [_PatternNoTopAlt_] ) <sup>?</sup>
-Identifier patterns bind the value they match to a variable. The identifier
-must be unique within the pattern. The variable will shadow any variables of
-the same name in scope. The scope of the new binding depends on the context of
-where the pattern is used (such as a `let` binding or a `match` arm).
+Identifier patterns bind the value they match to a variable.
+The identifier must be unique within the pattern.
+The variable will shadow any variables of the same name in scope.
+The scope of the new binding depends on the context of where the pattern is used (such as a `let` binding or a `match` arm).
-Patterns that consist of only an identifier, possibly with a `mut`, match any value and
-bind it to that identifier. This is the most commonly used pattern in variable
-declarations and parameters for functions and closures.
+Patterns that consist of only an identifier, possibly with a `mut`, match any value and bind it to that identifier.
+This is the most commonly used pattern in variable declarations and parameters for functions and closures.
```rust
let mut variable = 10;
@@ -191,9 +180,8 @@ fn sum(x: i32, y: i32) -> i32 {
# }
```
-To bind the matched value of a pattern to a variable, use the syntax `variable @
-subpattern`. For example, the following binds the value 2 to `e` (not the
-entire range: the range here is a range subpattern).
+To bind the matched value of a pattern to a variable, use the syntax `variable @ subpattern`.
+For example, the following binds the value 2 to `e` (not the entire range: the range here is a range subpattern).
```rust
let x = 2;
@@ -204,10 +192,8 @@ match x {
}
```
-By default, identifier patterns bind a variable to a copy of or move from the
-matched value depending on whether the matched value implements [`Copy`].
-This can be changed to bind to a reference by using the `ref` keyword,
-or to a mutable reference using `ref mut`. For example:
+By default, identifier patterns bind a variable to a copy of or move from the matched value depending on whether the matched value implements [`Copy`].
+This can be changed to bind to a reference by using the `ref` keyword, or to a mutable reference using `ref mut`. For example:
```rust
# let a = Some(10);
@@ -222,10 +208,10 @@ match a {
}
```
-In the first match expression, the value is copied (or moved). In the second match,
-a reference to the same memory location is bound to the variable value. This syntax is
-needed because in destructuring subpatterns the `&` operator can't be applied to
-the value's fields. For example, the following is not valid:
+In the first match expression, the value is copied (or moved).
+In the second match, a reference to the same memory location is bound to the variable value.
+This syntax is needed because in destructuring subpatterns the `&` operator can't be applied to the value's fields.
+For example, the following is not valid:
```rust,compile_fail
# struct Person {
@@ -247,21 +233,18 @@ To make it valid, write the following:
if let Person {name: ref person_name, age: 18..=150 } = value { }
```
-Thus, `ref` is not something that is being matched against. Its objective is
-exclusively to make the matched binding a reference, instead of potentially
-copying or moving what was matched.
+Thus, `ref` is not something that is being matched against.
+Its objective is exclusively to make the matched binding a reference, instead of potentially copying or moving what was matched.
-[Path patterns](#path-patterns) take precedence over identifier patterns. It is an error
-if `ref` or `ref mut` is specified and the identifier shadows a constant.
+[Path patterns](#path-patterns) take precedence over identifier patterns.
+It is an error if `ref` or `ref mut` is specified and the identifier shadows a constant.
-Identifier patterns are irrefutable if the `@` subpattern is irrefutable or
-the subpattern is not specified.
+Identifier patterns are irrefutable if the `@` subpattern is irrefutable or the subpattern is not specified.
### Binding modes
-To service better ergonomics, patterns operate in different *binding modes* in
-order to make it easier to bind references to values. When a reference value is matched by
-a non-reference pattern, it will be automatically treated as a `ref` or `ref mut` binding.
+To service better ergonomics, patterns operate in different *binding modes* in order to make it easier to bind references to values.
+When a reference value is matched by a non-reference pattern, it will be automatically treated as a `ref` or `ref mut` binding.
Example:
```rust
@@ -271,26 +254,22 @@ if let Some(y) = x {
}
```
-*Non-reference patterns* include all patterns except bindings, [wildcard
-patterns](#wildcard-pattern) (`_`), [`const` patterns](#path-patterns) of reference types,
-and [reference patterns](#reference-patterns).
-
-If a binding pattern does not explicitly have `ref`, `ref mut`, or `mut`, then it uses the
-*default binding mode* to determine how the variable is bound. The default binding
-mode starts in "move" mode which uses move semantics. When matching a pattern, the
-compiler starts from the outside of the pattern and works inwards. Each time a reference
-is matched using a non-reference pattern, it will automatically dereference the value and
-update the default binding mode. References will set the default binding mode to `ref`.
-Mutable references will set the mode to `ref mut` unless the mode is already `ref` in
-which case it remains `ref`. If the automatically dereferenced value is still a reference,
-it is dereferenced and this process repeats.
-
-Move bindings and reference bindings can be mixed together in the same pattern, doing so will
-result in partial move of the object bound to and the object cannot be used afterwards.
+*Non-reference patterns* include all patterns except bindings, [wildcard patterns](#wildcard-pattern) (`_`), [`const` patterns](#path-patterns) of reference types, and [reference patterns](#reference-patterns).
+
+If a binding pattern does not explicitly have `ref`, `ref mut`, or `mut`, then it uses the *default binding mode* to determine how the variable is bound.
+The default binding mode starts in "move" mode which uses move semantics.
+When matching a pattern, the compiler starts from the outside of the pattern and works inwards.
+Each time a reference is matched using a non-reference pattern, it will automatically dereference the value and update the default binding mode.
+References will set the default binding mode to `ref`.
+Mutable references will set the mode to `ref mut` unless the mode is already `ref` in which case it remains `ref`.
+If the automatically dereferenced value is still a reference, it is dereferenced and this process repeats.
+
+Move bindings and reference bindings can be mixed together in the same pattern.
+Doing so will result in partial move of the object bound to and the object cannot be used afterwards.
This applies only if the type cannot be copied.
-In the example below, `name` is moved out of `person`, trying to use `person` as a whole or
-`person.name` would result in an error because of *partial move*.
+In the example below, `name` is moved out of `person`.
+Trying to use `person` as a whole or `person.name` would result in an error because of *partial move*.
Example:
@@ -310,10 +289,10 @@ let Person { name, ref age } = person;
> _WildcardPattern_ :\
> &nbsp;&nbsp; `_`
-The _wildcard pattern_ (an underscore symbol) matches any value. It is used to ignore values when they don't
-matter. Inside other patterns it matches a single data field (as opposed to the `..`
-which matches the remaining fields). Unlike identifier patterns, it does not copy, move
-or borrow the value it matches.
+The _wildcard pattern_ (an underscore symbol) matches any value.
+It is used to ignore values when they don't matter.
+Inside other patterns it matches a single data field (as opposed to the `..` which matches the remaining fields).
+Unlike identifier patterns, it does not copy, move or borrow the value it matches.
Examples:
@@ -351,13 +330,9 @@ The wildcard pattern is always irrefutable.
> _RestPattern_ :\
> &nbsp;&nbsp; `..`
-The _rest pattern_ (the `..` token) acts as a variable-length pattern which
-matches zero or more elements that haven't been matched already before and
-after. It may only be used in [tuple](#tuple-patterns), [tuple
-struct](#tuple-struct-patterns), and [slice](#slice-patterns) patterns, and
-may only appear once as one of the elements in those patterns. It is also
-allowed in an [identifier pattern](#identifier-patterns) for [slice
-patterns](#slice-patterns) only.
+The _rest pattern_ (the `..` token) acts as a variable-length pattern which matches zero or more elements that haven't been matched already before and after.
+It may only be used in [tuple](#tuple-patterns), [tuple struct](#tuple-struct-patterns), and [slice](#slice-patterns) patterns, and may only appear once as one of the elements in those patterns.
+It is also allowed in an [identifier pattern](#identifier-patterns) for [slice patterns](#slice-patterns) only.
The rest pattern is always irrefutable.
@@ -413,7 +388,8 @@ match tuple {
> &nbsp;&nbsp; &nbsp;&nbsp; _RangePatternBound_ `..=` _RangePatternBound_
>
> _HalfOpenRangePattern_ :\
-> &nbsp;&nbsp; | _RangePatternBound_ `..`
+> &nbsp;&nbsp; &nbsp;&nbsp; _RangePatternBound_ `..`
+> &nbsp;&nbsp; | `..=` _RangePatternBound_
>
> _ObsoleteRangePattern_ :\
> &nbsp;&nbsp; _RangePatternBound_ `...` _RangePatternBound_
@@ -425,29 +401,50 @@ match tuple {
> &nbsp;&nbsp; | `-`<sup>?</sup> [FLOAT_LITERAL]\
> &nbsp;&nbsp; | [_PathExpression_]
-Range patterns match values within the range defined by their bounds. A range pattern may be
-closed or half-open. A range pattern is closed if it has both a lower and an upper bound, and
-it matches all the values between and including both of its bounds. A range pattern that is
-half-open is written with a lower bound but not an upper bound, and matches any value equal to
-or greater than the specified lower bound.
+*Range patterns* match scalar values within the range defined by their bounds.
+A bound on the left of its sigils is a *lower bound*.
+A bound on the right is an *upper bound*.
+A range pattern may be closed or half-open.
+
+A range pattern is *closed* if it has both a lower and an upper bound.
+The only closed ranged pattern is the inclusive range pattern.
+
+*Inclusive range patterns* match all the values between and including both of its bounds.
+It is written as its lower bounds, followed by `..=`, followed by its upper bounds.
+The type of it is the type unification of its upper and lower bounds.
+
+For example, a pattern `'m'..='p'` will match only the values `'m'`, `'n'`, `'o'`, and `'p'`.
+
+The lower bound cannot be greater than the upper bound.
+That is, in `a..=b`, a &le; b must be the case.
+For example, it is an error to have a range pattern `10..=0`.
-For example, a pattern `'m'..='p'` will match only the values `'m'`, `'n'`, `'o'`, and `'p'`. For an integer the
-pattern `1..` will match 9, or 9001, or 9007199254740991 (if it is of an appropriate size), but
-not 0, and not negative numbers for signed integers. The bounds can be literals or paths that point
-to constant values.
+Range patterns are *half-open* if they have only an upper or lower bound.
+They have the same type as their upper or lower bound.
-A half-open range pattern in the style `a..` cannot be used to match within the context of a slice.
+A half open range with only a lower bound is written as its lower bound followed by `..`.
+These range patterns will match on any value greater than or equal to the lower bound.
+For example, `1..` will match 1, 9, or 9001, or 9007199254740991 (if it is of an appropriate size), but not 0, and not negative numbers for signed integers.
+The bounds can be literals or paths that point to constant values.
-A pattern `a..=b` must always have a &le; b. It is an error to have a range pattern
-`10..=0`, for example.
+A half open range with only an upper bound is written as `..=` followed by its upper bound.
+These range patterns will match on any value less than or equal to the upper bound.
+For example, `..=10` will match 10, 1, 0, and for signed interger types, all negative values.
-Range patterns only work on scalar types. The accepted types are:
+Half-open range patterns cannot be used as the top-level pattern for subpatterns in [slice patterns](#slice-patterns).
-* Integer types (u8, i8, u16, i16, usize, isize, etc.).
-* Character types (char).
-* Floating point types (f32 and f64). This is being deprecated and will not be available
- in a future version of Rust (see
- [issue #41620](https://github.com/rust-lang/rust/issues/41620)).
+The bounds is written as one of:
+
+* A character, byte, integer, or float literal.
+* A `-` followed by an integer or float literal.
+* A [path]
+
+If the bounds is written as a path, after macro resolution, the path must resolve to a constant item of the type `char`, an integer type, or a float type.
+
+The type and value of the bounds is dependent upon how it is written out.
+If the bounds is a [path], the pattern has the type and value of the [constant] the path resolves to.
+If it is a literal, it has the type and value of the corresponding [literal expression].
+If is a literal preceded by a `-`, it has the same type as the corresponding [literal expression] and the value of [negating] the value of the corresponding literal expression.
Examples:
@@ -524,23 +521,26 @@ println!("{}", match 0xfacade {
});
```
-Range patterns for (non-`usize` and -`isize`) integer and `char` types are irrefutable
-when they span the entire set of possible values of a type. For example, `0u8..=255u8`
-is irrefutable. The range of values for an integer type is the closed range from its
-minimum to maximum value. The range of values for a `char` type are precisely those
-ranges containing all Unicode Scalar Values: `'\u{0000}'..='\u{D7FF}'` and
-`'\u{E000}'..='\u{10FFFF}'`.
+Range patterns for fix-width integer and `char` types are irrefutable when they span the entire set of possible values of a type.
+For example, `0u8..=255u8` is irrefutable.
+The range of values for an integer type is the closed range from its minimum to maximum value.
+The range of values for a `char` type are precisely those ranges containing all Unicode Scalar Values: `'\u{0000}'..='\u{D7FF}'` and `'\u{E000}'..='\u{10FFFF}'`.
+
+Floating point range patterns are deprecated and may be removed in a future Rust release.
+See [issue #41620](https://github.com/rust-lang/rust/issues/41620) for more information.
> **Edition Differences**: Before the 2021 edition, closed range patterns may also be written using `...` as an alternative to `..=`, with the same meaning.
+> **Note**: Although range patterns use the same syntax as [range expressions], there are no exclusive range patterns.
+> That is, neither `x .. y` nor `.. x` are valid range patterns.
+
## Reference patterns
> **<sup>Syntax</sup>**\
> _ReferencePattern_ :\
> &nbsp;&nbsp; (`&`|`&&`) `mut`<sup>?</sup> [_PatternWithoutRange_]
-Reference patterns dereference the pointers that are being matched
-and, thus, borrow them.
+Reference patterns dereference the pointers that are being matched and, thus, borrow them.
For example, these two matches on `x: &i32` are equivalent:
@@ -553,11 +553,9 @@ let b = match int_reference { &0 => "zero", _ => "some" };
assert_eq!(a, b);
```
-The grammar production for reference patterns has to match the token `&&` to match a
-reference to a reference because it is a token by itself, not two `&` tokens.
+The grammar production for reference patterns has to match the token `&&` to match a reference to a reference because it is a token by itself, not two `&` tokens.
-Adding the `mut` keyword dereferences a mutable reference. The mutability must match the
-mutability of the reference.
+Adding the `mut` keyword dereferences a mutable reference. The mutability must match the mutability of the reference.
Reference patterns are always irrefutable.
@@ -594,8 +592,7 @@ Reference patterns are always irrefutable.
Struct patterns match struct values that match all criteria defined by its subpatterns.
They are also used to [destructure](#destructuring) a struct.
-On a struct pattern, the fields are referenced by name, index (in the case of tuple
-structs) or ignored by use of `..`:
+On a struct pattern, the fields are referenced by name, index (in the case of tuple structs) or ignored by use of `..`:
```rust
# struct Point {
@@ -644,8 +641,7 @@ match struct_value {
}
```
-The `ref` and/or `mut` _IDENTIFIER_ syntax matches any value and binds it to
-a variable with the same name as the given field.
+The `ref` and/or `mut` _IDENTIFIER_ syntax matches any value and binds it to a variable with the same name as the given field.
```rust
# struct Struct {
@@ -669,9 +665,8 @@ A struct pattern is refutable when one of its subpatterns is refutable.
> _TupleStructItems_ :\
> &nbsp;&nbsp; [_Pattern_]&nbsp;( `,` [_Pattern_] )<sup>\*</sup> `,`<sup>?</sup>
-Tuple struct patterns match tuple struct and enum values that match all criteria defined
-by its subpatterns. They are also used to [destructure](#destructuring) a tuple struct or
-enum value.
+Tuple struct patterns match tuple struct and enum values that match all criteria defined by its subpatterns.
+They are also used to [destructure](#destructuring) a tuple struct or enum value.
A tuple struct pattern is refutable when one of its subpatterns is refutable.
@@ -689,8 +684,7 @@ A tuple struct pattern is refutable when one of its subpatterns is refutable.
Tuple patterns match tuple values that match all criteria defined by its subpatterns.
They are also used to [destructure](#destructuring) a tuple.
-The form `(..)` with a single [_RestPattern_] is a special form that does not
-require a comma, and matches a tuple of any size.
+The form `(..)` with a single [_RestPattern_] is a special form that does not require a comma, and matches a tuple of any size.
The tuple pattern is refutable when one of its subpatterns is refutable.
@@ -710,10 +704,8 @@ assert_eq!(b, "ten");
> _GroupedPattern_ :\
> &nbsp;&nbsp; `(` [_Pattern_] `)`
-Enclosing a pattern in parentheses can be used to explicitly control the
-precedence of compound patterns. For example, a reference pattern next to a
-range pattern such as `&0..=5` is ambiguous and is not allowed, but can be
-expressed with parentheses.
+Enclosing a pattern in parentheses can be used to explicitly control the precedence of compound patterns.
+For example, a reference pattern next to a range pattern such as `&0..=5` is ambiguous and is not allowed, but can be expressed with parentheses.
```rust
let int_reference = &3;
@@ -733,6 +725,7 @@ match int_reference {
> &nbsp;&nbsp; [_Pattern_] \(`,` [_Pattern_])<sup>\*</sup> `,`<sup>?</sup>
Slice patterns can match both arrays of fixed size and slices of dynamic size.
+
```rust
// Fixed size
let arr = [1, 2, 3];
@@ -751,14 +744,10 @@ match v[..] {
};
```
-Slice patterns are irrefutable when matching an array as long as each element
-is irrefutable. When matching a slice, it is irrefutable only in the form with
-a single `..` [rest pattern](#rest-patterns) or [identifier
-pattern](#identifier-patterns) with the `..` rest pattern as a subpattern.
+Slice patterns are irrefutable when matching an array as long as each element is irrefutable.
+When matching a slice, it is irrefutable only in the form with a single `..` [rest pattern](#rest-patterns) or [identifier pattern](#identifier-patterns) with the `..` rest pattern as a subpattern.
-Within a slice, a half-open range pattern like `a..` must be enclosed in parentheses,
-as in `(a..)`, to clarify it is intended to match a single value.
-A future version of Rust may give the non-parenthesized version an alternate meaning.
+Within a slice, a half-open range pattern like `a..` must be enclosed in parentheses, as in `(a..)`, to clarify it is intended to match a single value.
## Path patterns
@@ -778,33 +767,27 @@ Unqualified path patterns can refer to:
Qualified path patterns can only refer to associated constants.
-Constants cannot be a union type. Struct and enum constants must have
-`#[derive(PartialEq, Eq)]` (not merely implemented).
+Constants cannot be a union type.
+Struct and enum constants must have `#[derive(PartialEq, Eq)]` (not merely implemented).
-Path patterns are irrefutable when they refer to structs or an enum variant when the enum
-has only one variant or a constant whose type is irrefutable. They are refutable when they
-refer to refutable constants or enum variants for enums with multiple variants.
+Path patterns are irrefutable when they refer to structs or an enum variant when the enum has only one variant or a constant whose type is irrefutable.
+They are refutable when they refer to refutable constants or enum variants for enums with multiple variants.
## Or-patterns
-_Or-patterns_ are patterns that match on one of two or more sub-patterns (e.g.
-`A | B | C`). They can nest arbitrarily. Syntactically, or-patterns are allowed
-in any of the places where other patterns are allowed (represented by the
-_Pattern_ production), with the exceptions of `let`-bindings and function and
-closure arguments (represented by the _PatternNoTopAlt_ production).
+_Or-patterns_ are patterns that match on one of two or more sub-patterns (for example `A | B | C`).
+They can nest arbitrarily.
+Syntactically, or-patterns are allowed in any of the places where other patterns are allowed (represented by the _Pattern_ production), with the exceptions of `let`-bindings and function and closure arguments (represented by the _PatternNoTopAlt_ production).
### Static semantics
-1. Given a pattern `p | q` at some depth for some arbitrary patterns `p` and `q`,
- the pattern is considered ill-formed if:
+1. Given a pattern `p | q` at some depth for some arbitrary patterns `p` and `q`, the pattern is considered ill-formed if:
+ the type inferred for `p` does not unify with the type inferred for `q`, or
+ the same set of bindings are not introduced in `p` and `q`, or
- + the type of any two bindings with the same name in `p` and `q` do not unify
- with respect to types or binding modes.
+ + the type of any two bindings with the same name in `p` and `q` do not unify with respect to types or binding modes.
- Unification of types is in all instances aforementioned exact and
- implicit [type coercions] do not apply.
+ Unification of types is in all instances aforementioned exact and implicit [type coercions] do not apply.
2. When type checking an expression `match e_s { a_1 => e_1, ... a_n => e_n }`,
for each match arm `a_i` which contains a pattern of form `p_i | q_i`,
@@ -812,35 +795,27 @@ closure arguments (represented by the _PatternNoTopAlt_ production).
at the depth `d` where it exists the fragment of `e_s` at depth `d`,
the type of the expression fragment does not unify with `p_i | q_i`.
-3. With respect to exhaustiveness checking, a pattern `p | q` is
- considered to cover `p` as well as `q`. For some constructor `c(x, ..)`
- the distributive law applies such that `c(p | q, ..rest)` covers the same
- set of value as `c(p, ..rest) | c(q, ..rest)` does. This can be applied
- recursively until there are no more nested patterns of form `p | q` other
- than those that exist at the top level.
+3. With respect to exhaustiveness checking, a pattern `p | q` is considered to cover `p` as well as `q`.
+ For some constructor `c(x, ..)` the distributive law applies such that `c(p | q, ..rest)` covers the same set of value as `c(p, ..rest) | c(q, ..rest)` does.
+ This can be applied recursively until there are no more nested patterns of form `p | q` other than those that exist at the top level.
- Note that by *"constructor"* we do not refer to tuple struct patterns,
- but rather we refer to a pattern for any product type.
- This includes enum variants, tuple structs, structs with named fields,
- arrays, tuples, and slices.
+ Note that by *"constructor"* we do not refer to tuple struct patterns, but rather we refer to a pattern for any product type.
+ This includes enum variants, tuple structs, structs with named fields, arrays, tuples, and slices.
### Dynamic semantics
-1. The dynamic semantics of pattern matching a scrutinee expression `e_s`
- against a pattern `c(p | q, ..rest)` at depth `d` where `c` is some constructor,
- `p` and `q` are arbitrary patterns, and `rest` is optionally any remaining
- potential factors in `c`, is defined as being the same as that of
- `c(p, ..rest) | c(q, ..rest)`.
+1. The dynamic semantics of pattern matching a scrutinee expression `e_s` against a pattern `c(p | q, ..rest)` at depth `d` where `c` is some constructor,
+ `p` and `q` are arbitrary patterns,
+ and `rest` is optionally any remaining potential factors in `c`,
+ is defined as being the same as that of `c(p, ..rest) | c(q, ..rest)`.
### Precedence with other undelimited patterns
-As shown elsewhere in this chapter, there are several types of patterns that
-are syntactically undelimited, including identifier patterns, reference
-patterns, and or-patterns. Or-patterns always have the lowest-precedence. This
-allows us to reserve syntactic space for a possible future type ascription
-feature and also to reduce ambiguity. For example, `x @ A(..) | B(..)` will
-result in an error that `x` is not bound in all patterns, `&A(x) | B(x)` will
-result in a type mismatch between `x` in the different subpatterns.
+As shown elsewhere in this chapter, there are several types of patterns that are syntactically undelimited, including identifier patterns, reference patterns, and or-patterns.
+Or-patterns always have the lowest-precedence.
+This allows us to reserve syntactic space for a possible future type ascription feature and also to reduce ambiguity.
+For example, `x @ A(..) | B(..)` will result in an error that `x` is not bound in all patterns.
+`&A(x) | B(x)` will result in a type mismatch between `x` in the different subpatterns.
[_GroupedPattern_]: #grouped-patterns
[_IdentifierPattern_]: #identifier-patterns
@@ -865,8 +840,13 @@ result in a type mismatch between `x` in the different subpatterns.
[`Copy`]: special-types-and-traits.md#copy
[IDENTIFIER]: identifiers.md
+[constant]: items/constant-items.md
[enums]: items/enumerations.md
[literals]: expressions/literal-expr.md
+[literal expression]: expressions/literal-expr.md
+[negating]: expressions/operator-expr.md#negation-operators
+[path]: expressions/path-expr.md
+[range expressions]: expressions/range-expr.md
[structs]: items/structs.md
[tuples]: types/tuple.md
[scrutinee]: glossary.md#scrutinee
diff --git a/src/doc/reference/src/statements-and-expressions.md b/src/doc/reference/src/statements-and-expressions.md
index b093972a9..fede41196 100644
--- a/src/doc/reference/src/statements-and-expressions.md
+++ b/src/doc/reference/src/statements-and-expressions.md
@@ -1,11 +1,7 @@
# Statements and expressions
-Rust is _primarily_ an expression language. This means that most forms of
-value-producing or effect-causing evaluation are directed by the uniform syntax
-category of _expressions_. Each kind of expression can typically _nest_ within
-each other kind of expression, and rules for evaluation of expressions involve
-specifying both the value produced by the expression and the order in which its
-sub-expressions are themselves evaluated.
+Rust is _primarily_ an expression language.
+This means that most forms of value-producing or effect-causing evaluation are directed by the uniform syntax category of _expressions_.
+Each kind of expression can typically _nest_ within each other kind of expression, and rules for evaluation of expressions involve specifying both the value produced by the expression and the order in which its sub-expressions are themselves evaluated.
-In contrast, statements serve _mostly_ to contain and explicitly
-sequence expression evaluation.
+In contrast, statements serve _mostly_ to contain and explicitly sequence expression evaluation.
diff --git a/src/doc/reference/src/statements.md b/src/doc/reference/src/statements.md
index 8d9c21d7d..c2ae585a0 100644
--- a/src/doc/reference/src/statements.md
+++ b/src/doc/reference/src/statements.md
@@ -9,35 +9,27 @@
> &nbsp;&nbsp; | [_MacroInvocationSemi_]
-A *statement* is a component of a [block], which is in turn a component of an
-outer [expression] or [function].
+A *statement* is a component of a [block], which is in turn a component of an outer [expression] or [function].
-Rust has two kinds of statement: [declaration
-statements](#declaration-statements) and [expression
-statements](#expression-statements).
+Rust has two kinds of statement: [declaration statements](#declaration-statements) and [expression statements](#expression-statements).
## Declaration statements
-A *declaration statement* is one that introduces one or more *names* into the
-enclosing statement block. The declared names may denote new variables or new
-[items][item].
+A *declaration statement* is one that introduces one or more *names* into the enclosing statement block.
+The declared names may denote new variables or new [items][item].
-The two kinds of declaration statements are item declarations and `let`
-statements.
+The two kinds of declaration statements are item declarations and `let` statements.
### Item declarations
-An *item declaration statement* has a syntactic form identical to an
-[item declaration][item] within a [module]. Declaring an item within a statement
-block restricts its scope to the block containing the statement. The item is not
-given a [canonical path] nor are any sub-items it may declare. The exception to
-this is that associated items defined by [implementations] are still accessible
-in outer scopes as long as the item and, if applicable, trait are accessible.
+An *item declaration statement* has a syntactic form identical to an [item declaration][item] within a [module].
+Declaring an item within a statement block restricts its scope to the block containing the statement.
+The item is not given a [canonical path] nor are any sub-items it may declare.
+The exception to this is that associated items defined by [implementations] are still accessible in outer scopes as long as the item and, if applicable, trait are accessible.
It is otherwise identical in meaning to declaring the item inside a module.
-There is no implicit capture of the containing function's generic parameters,
-parameters, and local variables. For example, `inner` may not access
-`outer_var`.
+There is no implicit capture of the containing function's generic parameters, parameters, and local variables.
+For example, `inner` may not access `outer_var`.
```rust
fn outer() {
@@ -54,16 +46,32 @@ fn outer() {
> **<sup>Syntax</sup>**\
> _LetStatement_ :\
> &nbsp;&nbsp; [_OuterAttribute_]<sup>\*</sup> `let` [_PatternNoTopAlt_]
-> ( `:` [_Type_] )<sup>?</sup> (`=` [_Expression_] )<sup>?</sup> `;`
+> ( `:` [_Type_] )<sup>?</sup> (`=` [_Expression_] [†](#let-else-restriction)
+> ( `else` [_BlockExpression_]) <sup>?</sup> ) <sup>?</sup> `;`
+>
+> <span id="let-else-restriction">† When an `else` block is specified, the
+> _Expression_ must not be a [_LazyBooleanExpression_], or end with a `}`.</span>
+
+A *`let` statement* introduces a new set of [variables], given by a [pattern].
+The pattern is followed optionally by a type annotation and then either ends, or is followed by an initializer expression plus an optional `else` block.
+When no type annotation is given, the compiler will infer the type, or signal an error if insufficient type information is available for definite inference.
+Any variables introduced by a variable declaration are visible from the point of declaration until the end of the enclosing block scope, except when they are shadowed by another variable declaration.
+
+If an `else` block is not present, the pattern must be irrefutable.
+If an `else` block is present, the pattern may be refutable.
+If the pattern does not match (this requires it to be refutable), the `else` block is executed.
+The `else` block must always diverge (evaluate to the [never type]).
-A *`let` statement* introduces a new set of [variables], given by an
-irrefutable [pattern]. The pattern is followed optionally by a type
-annotation and then optionally by an initializer expression. When no
-type annotation is given, the compiler will infer the type, or signal
-an error if insufficient type information is available for definite
-inference. Any variables introduced by a variable declaration are visible
-from the point of declaration until the end of the enclosing block scope,
-except when they are shadowed by another variable declaration.
+```rust
+let (mut v, w) = (vec![1, 2, 3], 42); // The bindings may be mut or const
+let Some(t) = v.pop() else { // Refutable patterns require an else block
+ panic!(); // The else block must diverge
+};
+let [u, v] = [v[0], v[1]] else { // This pattern is irrefutable, so the compiler
+ // will lint as the else block is redundant.
+ panic!();
+};
+```
## Expression statements
@@ -72,16 +80,13 @@ except when they are shadowed by another variable declaration.
> &nbsp;&nbsp; &nbsp;&nbsp; [_ExpressionWithoutBlock_][expression] `;`\
> &nbsp;&nbsp; | [_ExpressionWithBlock_][expression] `;`<sup>?</sup>
-An *expression statement* is one that evaluates an [expression] and ignores its
-result. As a rule, an expression statement's purpose is to trigger the effects
-of evaluating its expression.
+An *expression statement* is one that evaluates an [expression] and ignores its result.
+As a rule, an expression statement's purpose is to trigger the effects of evaluating its expression.
-An expression that consists of only a [block expression][block] or control flow
-expression, if used in a context where a statement is permitted, can omit the
-trailing semicolon. This can cause an ambiguity between it being parsed as a
-standalone statement and as a part of another expression; in this case, it is
-parsed as a statement. The type of [_ExpressionWithBlock_][expression]
-expressions when used as statements must be the unit type.
+An expression that consists of only a [block expression][block] or control flow expression, if used in a context where a statement is permitted, can omit the trailing semicolon.
+This can cause an ambiguity between it being parsed as a standalone statement and as a part of another expression;
+in this case, it is parsed as a statement.
+The type of [_ExpressionWithBlock_][expression] expressions when used as statements must be the unit type.
```rust
# let mut v = vec![1, 2, 3];
@@ -113,14 +118,15 @@ if true {
## Attributes on Statements
-Statements accept [outer attributes]. The attributes that have meaning on a
-statement are [`cfg`], and [the lint check attributes].
+Statements accept [outer attributes].
+The attributes that have meaning on a statement are [`cfg`], and [the lint check attributes].
[block]: expressions/block-expr.md
[expression]: expressions.md
[function]: items/functions.md
[item]: items.md
[module]: items/modules.md
+[never type]: types/never.md
[canonical path]: paths.md#canonical-paths
[implementations]: items/implementations.md
[variables]: variables.md
@@ -128,9 +134,11 @@ statement are [`cfg`], and [the lint check attributes].
[`cfg`]: conditional-compilation.md
[the lint check attributes]: attributes/diagnostics.md#lint-check-attributes
[pattern]: patterns.md
+[_BlockExpression_]: expressions/block-expr.md
[_ExpressionStatement_]: #expression-statements
[_Expression_]: expressions.md
[_Item_]: items.md
+[_LazyBooleanExpression_]: expressions/operator-expr.md#lazy-boolean-operators
[_LetStatement_]: #let-statements
[_MacroInvocationSemi_]: macros.md#macro-invocation
[_OuterAttribute_]: attributes.md
diff --git a/src/doc/reference/src/tokens.md b/src/doc/reference/src/tokens.md
index 197c20147..8f9bcb1f7 100644
--- a/src/doc/reference/src/tokens.md
+++ b/src/doc/reference/src/tokens.md
@@ -667,7 +667,7 @@ Similarly the `r`, `b`, and `br` prefixes used in raw string literals, byte lite
> **Edition Differences**: Starting with the 2021 edition, reserved prefixes are reported as an error by the lexer (in particular, they cannot be passed to macros).
>
-> Before the 2021 edition, a reserved prefixes are accepted by the lexer and interpreted as multiple tokens (for example, one token for the identifier or keyword, followed by a `#` token).
+> Before the 2021 edition, reserved prefixes are accepted by the lexer and interpreted as multiple tokens (for example, one token for the identifier or keyword, followed by a `#` token).
>
> Examples accepted in all editions:
> ```rust
diff --git a/src/doc/reference/src/type-layout.md b/src/doc/reference/src/type-layout.md
index ce9296662..80a36abb8 100644
--- a/src/doc/reference/src/type-layout.md
+++ b/src/doc/reference/src/type-layout.md
@@ -20,8 +20,10 @@ The alignment of a value can be checked with the [`align_of_val`] function.
The *size* of a value is the offset in bytes between successive elements in an
array with that item type including alignment padding. The size of a value is
-always a multiple of its alignment. The size of a value can be checked with the
-[`size_of_val`] function.
+always a multiple of its alignment. Note that some types are zero-sized; 0 is
+considered a multiple of any alignment (for example, on some platforms, the type
+`[u16; 0]` has size 0 and alignment 2). The size of a value can be checked with
+the [`size_of_val`] function.
Types where all values have the same size and alignment, and both are known at
compile time, implement the [`Sized`] trait and can be checked with the
@@ -86,9 +88,9 @@ String slices are a UTF-8 representation of characters that have the same layout
## Tuple Layout
-Tuples do not have any guarantees about their layout.
+Tuples are laid out according to the [default representation][Default].
-The exception to this is the unit tuple (`()`) which is guaranteed as a
+The exception to this is the unit tuple (`()`), which is guaranteed as a
zero-sized type to have a size of 0 and an alignment of 1.
## Trait Object Layout
@@ -162,7 +164,25 @@ representation will not change the layout of `Inner`.
Nominal types without a `repr` attribute have the default representation.
Informally, this representation is also called the `rust` representation.
-There are no guarantees of data layout made by this representation.
+The only data layout guarantees made by this representation are those required
+for soundness. They are:
+
+ 1. The fields are properly aligned.
+ 2. The fields do not overlap.
+ 3. The alignment of the type is at least the maximum alignment of its fields.
+
+Formally, the first guarantee means that the offset of any field is divisible by
+that field's alignment. The second guarantee means that the fields can be
+ordered such that the offset plus the size of any field is less than or equal to
+the offset of the next field in the ordering. The ordering does not have to be
+the same as the order in which the fields are specified in the declaration of
+the type.
+
+Be aware that the second guarantee does not imply that the fields have distinct
+addresses: zero-sized types may have the same address as other fields in the
+same struct.
+
+There are no other guarantees of data layout made by this representation.
### The `C` Representation
diff --git a/src/doc/reference/src/types/function-pointer.md b/src/doc/reference/src/types/function-pointer.md
index a51f76135..82103beaa 100644
--- a/src/doc/reference/src/types/function-pointer.md
+++ b/src/doc/reference/src/types/function-pointer.md
@@ -62,5 +62,5 @@ restrictions as [regular function parameters].
[closures]: closure.md
[extern function]: ../items/functions.md#extern-function-qualifier
[function items]: function-item.md
-[unsafe function]: ../unsafe-functions.md
+[unsafe function]: ../unsafe-keyword.md
[regular function parameters]: ../items/functions.md#attributes-on-function-parameters
diff --git a/src/doc/reference/src/types/pointer.md b/src/doc/reference/src/types/pointer.md
index 9c8d80f39..4a74370a5 100644
--- a/src/doc/reference/src/types/pointer.md
+++ b/src/doc/reference/src/types/pointer.md
@@ -11,8 +11,8 @@ They can be moved or copied, stored into data structs, and returned from functio
### Shared references (`&`)
-These point to memory _owned by some other value_.
-When a shared reference to a value is created it prevents direct mutation of the value.
+Shared references point to memory which is owned by some other value.
+When a shared reference to a value is created, it prevents direct mutation of the value.
[Interior mutability] provides an exception for this in certain circumstances.
As the name suggests, any number of shared references to a value may exist.
A shared reference type is written `&type`, or `&'a type` when you need to specify an explicit lifetime.
@@ -22,7 +22,7 @@ Releasing a reference has no effect on the value it points to, but referencing o
### Mutable references (`&mut`)
-These also point to memory owned by some other value.
+Mutable references point to memory which is owned by some other value.
A mutable reference type is written `&mut type` or `&'a mut type`.
A mutable reference (that hasn't been borrowed) is the only way to access the value it points to, so is not `Copy`.
diff --git a/src/doc/reference/src/unsafe-blocks.md b/src/doc/reference/src/unsafe-blocks.md
deleted file mode 100644
index 754278445..000000000
--- a/src/doc/reference/src/unsafe-blocks.md
+++ /dev/null
@@ -1,22 +0,0 @@
-# Unsafe blocks
-
-A block of code can be prefixed with the `unsafe` keyword, to permit calling
-`unsafe` functions or dereferencing raw pointers within a safe function.
-
-When a programmer has sufficient conviction that a sequence of potentially
-unsafe operations is actually safe, they can encapsulate that sequence (taken
-as a whole) within an `unsafe` block. The compiler will consider uses of such
-code safe, in the surrounding context.
-
-Unsafe blocks are used to wrap foreign libraries, make direct use of hardware
-or implement features not directly present in the language. For example, Rust
-provides the language features necessary to implement memory-safe concurrency
-in the language but the implementation of threads and message passing is in the
-standard library.
-
-Rust's type system is a conservative approximation of the dynamic safety
-requirements, so in some cases there is a performance cost to using safe code.
-For example, a doubly-linked list is not a tree structure and can only be
-represented with reference-counted pointers in safe code. By using `unsafe`
-blocks to represent the reverse links as raw pointers, it can be implemented
-with only boxes.
diff --git a/src/doc/reference/src/unsafe-functions.md b/src/doc/reference/src/unsafe-functions.md
deleted file mode 100644
index 7a5064c08..000000000
--- a/src/doc/reference/src/unsafe-functions.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# Unsafe functions
-
-Unsafe functions are functions that are not safe in all contexts and/or for all
-possible inputs. Such a function must be prefixed with the keyword `unsafe` and
-can only be called from an `unsafe` block or another `unsafe` function.
diff --git a/src/doc/reference/src/unsafe-keyword.md b/src/doc/reference/src/unsafe-keyword.md
new file mode 100644
index 000000000..5fa5deea6
--- /dev/null
+++ b/src/doc/reference/src/unsafe-keyword.md
@@ -0,0 +1,58 @@
+# The `unsafe` keyword
+
+The `unsafe` keyword can occur in several different contexts:
+unsafe functions (`unsafe fn`), unsafe blocks (`unsafe {}`), unsafe traits (`unsafe trait`), and unsafe trait implementations (`unsafe impl`).
+It plays several different roles, depending on where it is used and whether the `unsafe_op_in_unsafe_fn` lint is enabled:
+- it is used to mark code that *defines* extra safety conditions (`unsafe fn`, `unsafe trait`)
+- it is used to mark code that needs to *satisfy* extra safety conditions (`unsafe {}`, `unsafe impl`, `unsafe fn` without [`unsafe_op_in_unsafe_fn`])
+
+The following discusses each of these cases.
+See the [keyword documentation][keyword] for some illustrative examples.
+
+## Unsafe functions (`unsafe fn`)
+
+Unsafe functions are functions that are not safe in all contexts and/or for all possible inputs.
+We say they have *extra safety conditions*, which are requirements that must be upheld by all callers and that the compiler does not check.
+For example, [`get_unchecked`] has the extra safety condition that the index must be in-bounds.
+The unsafe function should come with documentation explaining what those extra safety conditions are.
+
+Such a function must be prefixed with the keyword `unsafe` and can only be called from inside an `unsafe` block, or inside `unsafe fn` without the [`unsafe_op_in_unsafe_fn`] lint.
+
+## Unsafe blocks (`unsafe {}`)
+
+A block of code can be prefixed with the `unsafe` keyword, to permit calling `unsafe` functions or dereferencing raw pointers.
+By default, the body of an unsafe function is also considered to be an unsafe block;
+this can be changed by enabling the [`unsafe_op_in_unsafe_fn`] lint.
+
+By putting operations into an unsafe block, the programmer states that they have taken care of satisfying the extra safety conditions of all operations inside that block.
+
+Unsafe blocks are the logical dual to unsafe functions:
+where unsafe functions define a proof obligation that callers must uphold, unsafe blocks state that all relevant proof obligations have been discharged.
+There are many ways to discharge proof obligations;
+for example, there could be run-time checks or data structure invariants that guarantee that certain properties are definitely true, or the unsafe block could be inside an `unsafe fn` and use its own proof obligations to discharge the proof obligations of its callees.
+
+Unsafe blocks are used to wrap foreign libraries, make direct use of hardware or implement features not directly present in the language.
+For example, Rust provides the language features necessary to implement memory-safe concurrency in the language but the implementation of threads and message passing in the standard library uses unsafe blocks.
+
+Rust's type system is a conservative approximation of the dynamic safety requirements, so in some cases there is a performance cost to using safe code.
+For example, a doubly-linked list is not a tree structure and can only be represented with reference-counted pointers in safe code.
+By using `unsafe` blocks to represent the reverse links as raw pointers, it can be implemented without reference counting.
+(See ["Learn Rust With Entirely Too Many Linked Lists"](https://rust-unofficial.github.io/too-many-lists/) for a more in-depth exploration of this particular example.)
+
+## Unsafe traits (`unsafe trait`)
+
+An unsafe trait is a trait that comes with extra safety conditions that must be upheld by *implementations* of the trait.
+The unsafe trait should come with documentation explaining what those extra safety conditions are.
+
+Such a trait must be prefixed with the keyword `unsafe` and can only be implemented by `unsafe impl` blocks.
+
+## Unsafe trait implementations (`unsafe impl`)
+
+When implementing an unsafe trait, the implementation needs to be prefixed with the `unsafe` keyword.
+By writing `unsafe impl`, the programmer states that they have taken care of satisfying the extra safety conditions required by the trait.
+
+Unsafe trait implementations are the logical dual to unsafe traits: where unsafe traits define a proof obligation that implementations must uphold, unsafe implementations state that all relevant proof obligations have been discharged.
+
+[keyword]: ../std/keyword.unsafe.html
+[`get_unchecked`]: ../std/primitive.slice.html#method.get_unchecked
+[`unsafe_op_in_unsafe_fn`]: ../rustc/lints/listing/allowed-by-default.html#unsafe-op-in-unsafe-fn
diff --git a/src/doc/rust-by-example/src/cargo/conventions.md b/src/doc/rust-by-example/src/cargo/conventions.md
index 6e8196608..2335104f5 100644
--- a/src/doc/rust-by-example/src/cargo/conventions.md
+++ b/src/doc/rust-by-example/src/cargo/conventions.md
@@ -25,9 +25,9 @@ foo
└── my_other_bin.rs
```
-To tell `cargo` to compile or run this binary as opposed to the default or other
-binaries, we just pass `cargo` the `--bin my_other_bin` flag, where `my_other_bin`
-is the name of the binary we want to work with.
+To tell `cargo` to only compile or run this binary, we just pass `cargo` the
+`--bin my_other_bin` flag, where `my_other_bin` is the name of the binary we
+want to work with.
In addition to extra binaries, `cargo` supports [more features] such as
benchmarks, tests, and examples.
diff --git a/src/doc/rust-by-example/src/cargo/deps.md b/src/doc/rust-by-example/src/cargo/deps.md
index 8913e9e38..85f223f98 100644
--- a/src/doc/rust-by-example/src/cargo/deps.md
+++ b/src/doc/rust-by-example/src/cargo/deps.md
@@ -11,8 +11,8 @@ To create a new Rust project,
# A binary
cargo new foo
-# OR A library
-cargo new --lib foo
+# A library
+cargo new --lib bar
```
For the rest of this chapter, let's assume we are making a binary, rather than
@@ -21,14 +21,19 @@ a library, but all of the concepts are the same.
After the above commands, you should see a file hierarchy like this:
```txt
-foo
-├── Cargo.toml
-└── src
- └── main.rs
+.
+├── bar
+│ ├── Cargo.toml
+│ └── src
+│ └── lib.rs
+└── foo
+ ├── Cargo.toml
+ └── src
+ └── main.rs
```
-The `main.rs` is the root source file for your new project -- nothing new there.
-The `Cargo.toml` is the config file for `cargo` for this project (`foo`). If you
+The `main.rs` is the root source file for your new `foo` project -- nothing new there.
+The `Cargo.toml` is the config file for `cargo` for this project. If you
look inside it, you should see something like this:
```toml
diff --git a/src/doc/rust-by-example/src/conversion/from_into.md b/src/doc/rust-by-example/src/conversion/from_into.md
index 266d10f28..47b327142 100644
--- a/src/doc/rust-by-example/src/conversion/from_into.md
+++ b/src/doc/rust-by-example/src/conversion/from_into.md
@@ -66,7 +66,7 @@ impl From<i32> for Number {
fn main() {
let int = 5;
- // Try removing the type declaration
+ // Try removing the type annotation
let num: Number = int.into();
println!("My number is {:?}", num);
}
diff --git a/src/doc/rust-by-example/src/error/iter_result.md b/src/doc/rust-by-example/src/error/iter_result.md
index e77e21ff6..288f4fc02 100644
--- a/src/doc/rust-by-example/src/error/iter_result.md
+++ b/src/doc/rust-by-example/src/error/iter_result.md
@@ -51,7 +51,7 @@ fn main() {
## Fail the entire operation with `collect()`
-`Result` implements `FromIter` so that a vector of results (`Vec<Result<T, E>>`)
+`Result` implements `FromIterator` so that a vector of results (`Vec<Result<T, E>>`)
can be turned into a result with a vector (`Result<Vec<T>, E>`). Once an
`Result::Err` is found, the iteration will terminate.
diff --git a/src/doc/rust-by-example/src/error/option_unwrap/defaults.md b/src/doc/rust-by-example/src/error/option_unwrap/defaults.md
index eb515aee6..117333f12 100644
--- a/src/doc/rust-by-example/src/error/option_unwrap/defaults.md
+++ b/src/doc/rust-by-example/src/error/option_unwrap/defaults.md
@@ -1,6 +1,6 @@
# Unpacking options and defaults
-The is more than one way to unpack an `Option` and fall back on a default if it is `None`. To choose the one that meets our needs, we need to consider the following:
+There is more than one way to unpack an `Option` and fall back on a default if it is `None`. To choose the one that meets our needs, we need to consider the following:
* do we need eager or lazy evaluation?
* do we need to keep the original empty value intact, or modify it in place?
@@ -60,7 +60,7 @@ fn main() {
## `get_or_insert()` evaluates eagerly, modifies empty value in place
-To make sure that an `Option` contains a value, we can use `get_or_insert` to modify it in place with a fallback value, as is shown in the following example. Note that `get_or_insert` eagerly evaluaes its parameter, so variable `apple` is moved:
+To make sure that an `Option` contains a value, we can use `get_or_insert` to modify it in place with a fallback value, as is shown in the following example. Note that `get_or_insert` eagerly evaluates its parameter, so variable `apple` is moved:
```rust,editable
#[derive(Debug)]
@@ -75,7 +75,7 @@ fn main() {
// my_fruit is: Apple
// first_available_fruit is: Apple
//println!("Variable named `apple` is moved: {:?}", apple);
- // TODO: uncomment the line above to see the compliler error
+ // TODO: uncomment the line above to see the compiler error
}
```
diff --git a/src/doc/rust-by-example/src/flow_control/match/destructuring/destructure_slice.md b/src/doc/rust-by-example/src/flow_control/match/destructuring/destructure_slice.md
index 54552972a..93b7e4205 100644
--- a/src/doc/rust-by-example/src/flow_control/match/destructuring/destructure_slice.md
+++ b/src/doc/rust-by-example/src/flow_control/match/destructuring/destructure_slice.md
@@ -45,4 +45,4 @@ fn main() {
### See also:
-[Arrays and Slices](../../../primitives/array.md)
+[Arrays and Slices](../../../primitives/array.md) and [Binding](../binding.md) for `@` sigil
diff --git a/src/doc/rust-by-example/src/flow_control/match/guard.md b/src/doc/rust-by-example/src/flow_control/match/guard.md
index 6dba58f13..63008a743 100644
--- a/src/doc/rust-by-example/src/flow_control/match/guard.md
+++ b/src/doc/rust-by-example/src/flow_control/match/guard.md
@@ -5,7 +5,7 @@ A `match` *guard* can be added to filter the arm.
```rust,editable
enum Temperature {
Celsius(i32),
- Farenheit(i32),
+ Fahrenheit(i32),
}
fn main() {
@@ -17,8 +17,8 @@ fn main() {
// The `if condition` part ^ is a guard
Temperature::Celsius(t) => println!("{}C is below 30 Celsius", t),
- Temperature::Farenheit(t) if t > 86 => println!("{}F is above 86 Farenheit", t),
- Temperature::Farenheit(t) => println!("{}F is below 86 Farenheit", t),
+ Temperature::Fahrenheit(t) if t > 86 => println!("{}F is above 86 Fahrenheit", t),
+ Temperature::Fahrenheit(t) => println!("{}F is below 86 Fahrenheit", t),
}
}
```
diff --git a/src/doc/rust-by-example/src/macros.md b/src/doc/rust-by-example/src/macros.md
index ffeb923e5..3f12fcc41 100644
--- a/src/doc/rust-by-example/src/macros.md
+++ b/src/doc/rust-by-example/src/macros.md
@@ -37,4 +37,4 @@ So why are macros useful?
3. Variadic interfaces. Sometimes you want to define an interface that takes a
variable number of arguments. An example is `println!` which could take any
- number of arguments, depending on the format string!. (More on this later)
+ number of arguments, depending on the format string. (More on this later)
diff --git a/src/doc/rust-by-example/src/mod/struct_visibility.md b/src/doc/rust-by-example/src/mod/struct_visibility.md
index e7359413c..8641a7264 100644
--- a/src/doc/rust-by-example/src/mod/struct_visibility.md
+++ b/src/doc/rust-by-example/src/mod/struct_visibility.md
@@ -13,7 +13,6 @@ mod my {
}
// A public struct with a private field of generic type `T`
- #[allow(dead_code)]
pub struct ClosedBox<T> {
contents: T,
}
@@ -56,4 +55,4 @@ fn main() {
[generics][generics] and [methods][methods]
[generics]: ../generics.md
-[methods]: ../fn/methods.md \ No newline at end of file
+[methods]: ../fn/methods.md
diff --git a/src/doc/rust-by-example/src/primitives/array.md b/src/doc/rust-by-example/src/primitives/array.md
index 841c71c14..0f56182cd 100644
--- a/src/doc/rust-by-example/src/primitives/array.md
+++ b/src/doc/rust-by-example/src/primitives/array.md
@@ -64,7 +64,7 @@ fn main() {
}
}
- // Out of bound indexing causes compile error
+ // Out of bound indexing causes runtime error
//println!("{}", xs[5]);
}
```
diff --git a/src/doc/rust-by-example/src/std/box.md b/src/doc/rust-by-example/src/std/box.md
index 0740c07d6..ebc8ff430 100644
--- a/src/doc/rust-by-example/src/std/box.md
+++ b/src/doc/rust-by-example/src/std/box.md
@@ -62,11 +62,11 @@ fn main() {
mem::size_of_val(&rectangle));
// box size == pointer size
- println!("Boxed point occupies {} bytes on the heap",
+ println!("Boxed point occupies {} bytes on the stack",
mem::size_of_val(&boxed_point));
- println!("Boxed rectangle occupies {} bytes on the heap",
+ println!("Boxed rectangle occupies {} bytes on the stack",
mem::size_of_val(&boxed_rectangle));
- println!("Boxed box occupies {} bytes on the heap",
+ println!("Boxed box occupies {} bytes on the stack",
mem::size_of_val(&box_in_a_box));
// Copy the data contained in `boxed_point` into `unboxed_point`
diff --git a/src/doc/rust-by-example/src/std/str.md b/src/doc/rust-by-example/src/std/str.md
index 26d8fd109..a15038b90 100644
--- a/src/doc/rust-by-example/src/std/str.md
+++ b/src/doc/rust-by-example/src/std/str.md
@@ -69,7 +69,7 @@ This way you can add any character to your string, even unprintable ones
and ones that you don't know how to type. If you want a literal backslash,
escape it with another one: `\\`
-String or character literal delimiters occuring within a literal must be escaped: `"\""`, `'\''`.
+String or character literal delimiters occurring within a literal must be escaped: `"\""`, `'\''`.
```rust,editable
fn main() {
diff --git a/src/doc/rust-by-example/src/std_misc/path.md b/src/doc/rust-by-example/src/std_misc/path.md
index 48d85c144..af0f3d388 100644
--- a/src/doc/rust-by-example/src/std_misc/path.md
+++ b/src/doc/rust-by-example/src/std_misc/path.md
@@ -13,8 +13,10 @@ between `Path` and `PathBuf` is similar to that of `str` and `String`:
a `PathBuf` can be mutated in-place, and can be dereferenced to a `Path`.
Note that a `Path` is *not* internally represented as an UTF-8 string, but
-instead is stored as a vector of bytes (`Vec<u8>`). Therefore, converting a
-`Path` to a `&str` is *not* free and may fail (an `Option` is returned).
+instead is stored as an `OsString`. Therefore, converting a `Path` to a `&str`
+is *not* free and may fail (an `Option` is returned). However, a `Path` can be
+freely converted to an `OsString` or `&OsStr` using `into_os_string` and
+`as_os_str`, respectively.
```rust,editable
use std::path::Path;
diff --git a/src/doc/rust-by-example/src/testing/doc_testing.md b/src/doc/rust-by-example/src/testing/doc_testing.md
index 2fac440f9..1d6cd46ad 100644
--- a/src/doc/rust-by-example/src/testing/doc_testing.md
+++ b/src/doc/rust-by-example/src/testing/doc_testing.md
@@ -1,9 +1,10 @@
# Documentation testing
The primary way of documenting a Rust project is through annotating the source
-code. Documentation comments are written in [markdown] and support code
-blocks in them. Rust takes care about correctness, so these code blocks are
-compiled and used as documentation tests.
+code. Documentation comments are written in
+[CommonMark Markdown specification][commonmark] and support code blocks in them.
+Rust takes care about correctness, so these code blocks are compiled and used
+as documentation tests.
```rust,ignore
/// First line is a short summary describing function.
@@ -83,7 +84,7 @@ and `unwrap` it in hidden `main`. Sounds complicated? Here's an example:
/// ```
/// # // hidden lines start with `#` symbol, but they're still compilable!
/// # fn try_main() -> Result<(), String> { // line that wraps the body shown in doc
-/// let res = try::try_div(10, 2)?;
+/// let res = doccomments::try_div(10, 2)?;
/// # Ok(()) // returning from try_main
/// # }
/// # fn main() { // starting main that'll unwrap()
@@ -106,6 +107,6 @@ pub fn try_div(a: i32, b: i32) -> Result<i32, String> {
* [API Guidelines][doc-nursery] on documentation guidelines
[doc-nursery]: https://rust-lang-nursery.github.io/api-guidelines/documentation.html
-[markdown]: https://daringfireball.net/projects/markdown/
+[commonmark]: https://commonmark.org/
[RFC505]: https://github.com/rust-lang/rfcs/blob/master/text/0505-api-comment-conventions.md
[question-instead-of-unwrap]: https://rust-lang-nursery.github.io/api-guidelines/documentation.html#examples-use--not-try-not-unwrap-c-question-mark
diff --git a/src/doc/rust-by-example/src/types/cast.md b/src/doc/rust-by-example/src/types/cast.md
index 6182874cd..deed34cf7 100644
--- a/src/doc/rust-by-example/src/types/cast.md
+++ b/src/doc/rust-by-example/src/types/cast.md
@@ -53,13 +53,13 @@ fn main() {
// Unless it already fits, of course.
println!(" 128 as a i16 is: {}", 128 as i16);
- // 128 as i8 -> -128, whose two's complement in eight bits is:
+ // 128 as u8 -> 128, whose value in 8-bit two's complement representation is:
println!(" 128 as a i8 is : {}", 128 as i8);
// repeating the example above
// 1000 as u8 -> 232
println!("1000 as a u8 is : {}", 1000 as u8);
- // and the two's complement of 232 is -24
+ // and the value of 232 in 8-bit two's complement representation is -24
println!(" 232 as a i8 is : {}", 232 as i8);
// Since Rust 1.45, the `as` keyword performs a *saturating cast*
@@ -67,23 +67,23 @@ fn main() {
// the upper bound or is less than the lower bound, the returned value
// will be equal to the bound crossed.
- // 300.0 is 255
- println!("300.0 is {}", 300.0_f32 as u8);
+ // 300.0 as u8 is 255
+ println!(" 300.0 as u8 is : {}", 300.0_f32 as u8);
// -100.0 as u8 is 0
- println!("-100.0 as u8 is {}", -100.0_f32 as u8);
+ println!("-100.0 as u8 is : {}", -100.0_f32 as u8);
// nan as u8 is 0
- println!("nan as u8 is {}", f32::NAN as u8);
+ println!(" nan as u8 is : {}", f32::NAN as u8);
// This behavior incurs a small runtime cost and can be avoided
// with unsafe methods, however the results might overflow and
// return **unsound values**. Use these methods wisely:
unsafe {
- // 300.0 is 44
- println!("300.0 is {}", 300.0_f32.to_int_unchecked::<u8>());
+ // 300.0 as u8 is 44
+ println!(" 300.0 as u8 is : {}", 300.0_f32.to_int_unchecked::<u8>());
// -100.0 as u8 is 156
- println!("-100.0 as u8 is {}", (-100.0_f32).to_int_unchecked::<u8>());
+ println!("-100.0 as u8 is : {}", (-100.0_f32).to_int_unchecked::<u8>());
// nan as u8 is 0
- println!("nan as u8 is {}", f32::NAN.to_int_unchecked::<u8>());
+ println!(" nan as u8 is : {}", f32::NAN.to_int_unchecked::<u8>());
}
}
```
diff --git a/src/doc/rust-by-example/src/unsafe/asm.md b/src/doc/rust-by-example/src/unsafe/asm.md
index ee6b8088a..7ad6e0c5e 100644
--- a/src/doc/rust-by-example/src/unsafe/asm.md
+++ b/src/doc/rust-by-example/src/unsafe/asm.md
@@ -227,7 +227,7 @@ This state is generally referred to as being "clobbered".
We need to tell the compiler about this since it may need to save and restore this state around the inline assembly block.
```rust
-use core::arch::asm;
+use std::arch::asm;
fn main() {
// three entries of four bytes each
@@ -333,7 +333,7 @@ In some cases, fine control is needed over the way a register name is formatted
By default the compiler will always choose the name that refers to the full register size (e.g. `rax` on x86-64, `eax` on x86, etc).
-This default can be overriden by using modifiers on the template string operands, just like you would with format strings:
+This default can be overridden by using modifiers on the template string operands, just like you would with format strings:
```rust
use std::arch::asm;
diff --git a/src/doc/rustc-dev-guide/.github/workflows/ci.yml b/src/doc/rustc-dev-guide/.github/workflows/ci.yml
index c571d408d..a21e342cb 100644
--- a/src/doc/rustc-dev-guide/.github/workflows/ci.yml
+++ b/src/doc/rustc-dev-guide/.github/workflows/ci.yml
@@ -14,28 +14,28 @@ jobs:
if: github.repository == 'rust-lang/rustc-dev-guide'
runs-on: ubuntu-latest
env:
- MDBOOK_VERSION: 0.4.12
- MDBOOK_LINKCHECK_VERSION: 0.7.2
- MDBOOK_MERMAID_VERSION: 0.10.0
- MDBOOK_TOC_VERSION: 0.6.1
+ MDBOOK_VERSION: 0.4.21
+ MDBOOK_LINKCHECK_VERSION: 0.7.6
+ MDBOOK_MERMAID_VERSION: 0.11.2
+ MDBOOK_TOC_VERSION: 0.9.0
DEPLOY_DIR: book/html
BASE_SHA: ${{ github.event.pull_request.base.sha }}
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
with:
# linkcheck needs the base commit.
fetch-depth: 0
- name: Cache binaries
id: mdbook-cache
- uses: actions/cache@v2
+ uses: actions/cache@v3
with:
path: |
~/.cargo/bin
key: ${{ runner.os }}-${{ env.MDBOOK_VERSION }}--${{ env.MDBOOK_LINKCHECK_VERSION }}--${{ env.MDBOOK_TOC_VERSION }}--${{ env.MDBOOK_MERMAID_VERSION }}
- name: Cache linkcheck
- uses: actions/cache@v2
+ uses: actions/cache@v3
with:
path: |
~/book/linkcheck
@@ -49,10 +49,9 @@ jobs:
- name: Install latest nightly Rust toolchain
if: steps.mdbook-cache.outputs.cache-hit != 'true'
- uses: actions-rs/toolchain@v1
- with:
- toolchain: nightly
- override: true
+ run: |
+ rustup update nightly
+ rustup override set nightly
- name: Install Dependencies
if: steps.mdbook-cache.outputs.cache-hit != 'true'
diff --git a/src/doc/rustc-dev-guide/.github/workflows/date-check.yml b/src/doc/rustc-dev-guide/.github/workflows/date-check.yml
index b808876a4..c34c11c1e 100644
--- a/src/doc/rustc-dev-guide/.github/workflows/date-check.yml
+++ b/src/doc/rustc-dev-guide/.github/workflows/date-check.yml
@@ -15,7 +15,7 @@ jobs:
steps:
- name: Checkout repo
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: Ensure Rust is up-to-date
run: |
diff --git a/src/doc/rustc-dev-guide/book.toml b/src/doc/rustc-dev-guide/book.toml
index c86ec5638..dc216760e 100644
--- a/src/doc/rustc-dev-guide/book.toml
+++ b/src/doc/rustc-dev-guide/book.toml
@@ -43,3 +43,4 @@ warning-policy = "error"
[output.html.redirect]
"/compiletest.html" = "tests/compiletest.html"
"/diagnostics/sessiondiagnostic.html" = "diagnostics/diagnostic-structs.html"
+"/miri.html" = "const-eval/interpret.html"
diff --git a/src/doc/rustc-dev-guide/src/SUMMARY.md b/src/doc/rustc-dev-guide/src/SUMMARY.md
index 99b24fe59..360265c0e 100644
--- a/src/doc/rustc-dev-guide/src/SUMMARY.md
+++ b/src/doc/rustc-dev-guide/src/SUMMARY.md
@@ -152,7 +152,7 @@
- [MIR optimizations](./mir/optimizations.md)
- [Debugging](./mir/debugging.md)
- [Constant evaluation](./const-eval.md)
- - [miri const evaluator](./miri.md)
+ - [Interpreter](./const-eval/interpret.md)
- [Monomorphization](./backend/monomorph.md)
- [Lowering MIR](./backend/lowering-mir.md)
- [Code Generation](./backend/codegen.md)
diff --git a/src/doc/rustc-dev-guide/src/about-this-guide.md b/src/doc/rustc-dev-guide/src/about-this-guide.md
index b2c71866c..71407854e 100644
--- a/src/doc/rustc-dev-guide/src/about-this-guide.md
+++ b/src/doc/rustc-dev-guide/src/about-this-guide.md
@@ -5,7 +5,7 @@ as well as to help new contributors get involved in rustc development.
There are seven parts to this guide:
-1. [Building and debugging `rustc`][p1]:
+1. [Building `rustc`][p1]:
Contains information that should be useful no matter how you are contributing,
about building, debugging, profiling, etc.
2. [Contributing to `rustc`][p2]:
@@ -23,7 +23,7 @@ There are seven parts to this guide:
7. [Appendices][p7] at the end with useful reference information.
There are a few of these with different information, including a glossary.
-[p1]: ./getting-started.md
+[p1]: ./building/how-to-build-and-run.html
[p2]: ./contributing.md
[p3]: ./part-2-intro.md
[p4]: ./part-3-intro.md
diff --git a/src/doc/rustc-dev-guide/src/appendix/glossary.md b/src/doc/rustc-dev-guide/src/appendix/glossary.md
index 375db493c..42306dc1c 100644
--- a/src/doc/rustc-dev-guide/src/appendix/glossary.md
+++ b/src/doc/rustc-dev-guide/src/appendix/glossary.md
@@ -36,6 +36,7 @@ Term | Meaning
<span id="infcx">infcx</span> &nbsp; | The type inference context (`InferCtxt`). (see `rustc_middle::infer`)
<span id="inf-var">inference variable</span> &nbsp; | When doing type or region inference, an "inference variable" is a kind of special type/region that represents what you are trying to infer. Think of X in algebra. For example, if we are trying to infer the type of a variable in a program, we create an inference variable to represent that unknown type.
<span id="intern">intern</span> &nbsp; | Interning refers to storing certain frequently-used constant data, such as strings, and then referring to the data by an identifier (e.g. a `Symbol`) rather than the data itself, to reduce memory usage and number of allocations. See [this chapter](../memory.md) for more info.
+<span id="interpreter">interpreter</span> &nbsp; | The heart of const evaluation, running MIR code at compile time. ([see more](../const-eval/interpret.md))
<span id="intrinsic">intrinsic</span> &nbsp; | Intrinsics are special functions that are implemented in the compiler itself but exposed (often unstably) to users. They do magical and dangerous things. (See [`std::intrinsics`](https://doc.rust-lang.org/std/intrinsics/index.html))
<span id="ir">IR</span> &nbsp; | Short for Intermediate Representation, a general term in compilers. During compilation, the code is transformed from raw source (ASCII text) to various IRs. In Rust, these are primarily HIR, MIR, and LLVM IR. Each IR is well-suited for some set of computations. For example, MIR is well-suited for the borrow checker, and LLVM IR is well-suited for codegen because LLVM accepts it.
<span id="irlo">IRLO</span> &nbsp; | `IRLO` or `irlo` is sometimes used as an abbreviation for [internals.rust-lang.org](https://internals.rust-lang.org).
@@ -47,7 +48,7 @@ Term | Meaning
<span id="llvm">[LLVM]</span> &nbsp; | (actually not an acronym :P) an open-source compiler backend. It accepts LLVM IR and outputs native binaries. Various languages (e.g. Rust) can then implement a compiler front-end that outputs LLVM IR and use LLVM to compile to all the platforms LLVM supports.
<span id="memoization">memoization</span> &nbsp; | The process of storing the results of (pure) computations (such as pure function calls) to avoid having to repeat them in the future. This is typically a trade-off between execution speed and memory usage.
<span id="mir">MIR</span> &nbsp; | The Mid-level IR that is created after type-checking for use by borrowck and codegen. ([see more](../mir/index.md))
-<span id="miri">miri</span> &nbsp; | An interpreter for MIR used for constant evaluation. ([see more](../miri.md))
+<span id="miri">Miri</span> &nbsp; | A tool to detect Undefined Behavior in (unsafe) Rust code. ([see more](https://github.com/rust-lang/miri))
<span id="mono">monomorphization</span> &nbsp; | The process of taking generic implementations of types and functions and instantiating them with concrete types. For example, in the code we might have `Vec<T>`, but in the final executable, we will have a copy of the `Vec` code for every concrete type used in the program (e.g. a copy for `Vec<usize>`, a copy for `Vec<MyStruct>`, etc).
<span id="normalize">normalize</span> &nbsp; | A general term for converting to a more canonical form, but in the case of rustc typically refers to [associated type normalization](../traits/goals-and-clauses.md#normalizeprojection---type).
<span id="newtype">newtype</span> &nbsp; | A wrapper around some other type (e.g., `struct Foo(T)` is a "newtype" for `T`). This is commonly used in Rust to give a stronger type for indices.
diff --git a/src/doc/rustc-dev-guide/src/backend/codegen.md b/src/doc/rustc-dev-guide/src/backend/codegen.md
index 5feea5202..e2c92430e 100644
--- a/src/doc/rustc-dev-guide/src/backend/codegen.md
+++ b/src/doc/rustc-dev-guide/src/backend/codegen.md
@@ -3,7 +3,7 @@
Code generation (or "codegen") is the part of the compiler
that actually generates an executable binary.
Usually, rustc uses LLVM for code generation,
-bu there is also support for [Cranelift] and [GCC].
+but there is also support for [Cranelift] and [GCC].
The key is that rustc doesn't implement codegen itself.
It's worth noting, though, that in the Rust source code,
many parts of the backend have `codegen` in their names
diff --git a/src/doc/rustc-dev-guide/src/backend/debugging.md b/src/doc/rustc-dev-guide/src/backend/debugging.md
index 791a61fbe..26375204e 100644
--- a/src/doc/rustc-dev-guide/src/backend/debugging.md
+++ b/src/doc/rustc-dev-guide/src/backend/debugging.md
@@ -222,7 +222,7 @@ really helpful for this.
1. Once you have some LLVM IR for the problematic code (see above), you can
create a minimal working example with Godbolt. Go to
-[gcc.godbolt.org](https://gcc.godbolt.org).
+[llvm.godbolt.org](https://llvm.godbolt.org).
2. Choose `LLVM-IR` as programming language.
diff --git a/src/doc/rustc-dev-guide/src/building/bootstrapping.md b/src/doc/rustc-dev-guide/src/building/bootstrapping.md
index 939c47f1b..3bacc21d3 100644
--- a/src/doc/rustc-dev-guide/src/building/bootstrapping.md
+++ b/src/doc/rustc-dev-guide/src/building/bootstrapping.md
@@ -54,7 +54,7 @@ and its associated dynamic libraries,
which `x.py` will download for you.
(You can also configure `x.py` to use something else.)
-The stage0 compiler is then used only to compile `rustbuild`, `std`, and `rustc`.
+The stage0 compiler is then used only to compile `src/bootstrap`, `std`, and `rustc`.
When compiling `rustc`, the stage0 compiler uses the freshly compiled `std`.
There are two concepts at play here:
a compiler (with its set of dependencies)
@@ -73,9 +73,12 @@ In theory, the stage1 compiler is functionally identical to the stage2 compiler,
but in practice there are subtle differences.
In particular, the stage1 compiler itself was built by stage0
and hence not by the source in your working directory.
-This means that the symbol names used in the compiler source
-may not match the symbol names that would have been made by the stage1 compiler,
-which can cause problems for dynamic libraries and tests.
+This means that the ABI generated by the stage0 compiler may not match the ABI that would have been
+made by the stage1 compiler, which can cause problems for dynamic libraries, tests, and tools using
+`rustc_private`.
+
+Note that the `proc_macro` crate avoids this issue with a C FFI layer called `proc_macro::bridge`,
+allowing it to be used with stage 1.
The `stage2` compiler is the one distributed with `rustup` and all other install methods.
However, it takes a very long time to build
@@ -226,14 +229,6 @@ another program we are building with the stage N compiler:
`build --stage N compiler/rustc` is linking the stage N artifacts to the `std`
built by the stage N compiler.
-Here is a chart of a full build using `x.py`:
-
-<img alt="A diagram of the rustc compilation phases" src="../img/rustc_stages.svg" class="center" />
-
-Keep in mind this diagram is a simplification, i.e. `rustdoc` can be built at
-different stages, the process is a bit different when passing flags such as
-`--keep-stage`, or if there are non-host targets.
-
### Stages and `std`
Note that there are two `std` libraries in play here:
@@ -365,7 +360,7 @@ This flag has the following effects:
Code which does not use `-Z force-unstable-if-unmarked` should include the
`#![feature(rustc_private)]` crate attribute to access these force-unstable
-crates. This is needed for things that link `rustc`, such as `miri`, `rls`, or
+crates. This is needed for things that link `rustc`, such as `miri` or
`clippy`.
You can find more discussion about sysroots in:
@@ -375,9 +370,46 @@ You can find more discussion about sysroots in:
[rustdoc PR]: https://github.com/rust-lang/rust/pull/76728
-### Directories and artifacts generated by `x.py`
+## Passing flags to commands invoked by `bootstrap`
+
+`x.py` allows you to pass stage-specific flags to `rustc` and `cargo` when bootstrapping.
+The `RUSTFLAGS_BOOTSTRAP` environment variable is passed as `RUSTFLAGS` to the bootstrap stage
+(stage0), and `RUSTFLAGS_NOT_BOOTSTRAP` is passed when building artifacts for later stages.
+`RUSTFLAGS` will work, but also affects the build of `bootstrap` itself, so it will be rare to want
+to use it.
+Finally, `MAGIC_EXTRA_RUSTFLAGS` bypasses the `cargo` cache to pass flags to rustc without
+recompiling all dependencies.
+
+`RUSTDOCFLAGS`, `RUSTDOCFLAGS_BOOTSTRAP`, and `RUSTDOCFLAGS_NOT_BOOTSTRAP` are anologous to
+`RUSTFLAGS`, but for rustdoc.
+
+`CARGOFLAGS` will pass arguments to cargo itself (e.g. `--timings`). `CARGOFLAGS_BOOTSTRAP` and
+`CARGOFLAGS_NOT_BOOTSTRAP` work analogously to `RUSTFLAGS_BOOTSTRAP`.
+
+`--test-args` will pass arguments through to the test runner. For `src/test/ui`, this is
+compiletest; for unit tests and doctests this is the `libtest` runner. Most test runner accept
+`--help`, which you can use to find out the options accepted by the runner.
-The following tables indicate the outputs of various stage actions:
+## Environment Variables
+
+During bootstrapping, there are a bunch of compiler-internal environment
+variables that are used. If you are trying to run an intermediate version of
+`rustc`, sometimes you may need to set some of these environment variables
+manually. Otherwise, you get an error like the following:
+
+```text
+thread 'main' panicked at 'RUSTC_STAGE was not set: NotPresent', library/core/src/result.rs:1165:5
+```
+
+If `./stageN/bin/rustc` gives an error about environment variables, that
+usually means something is quite wrong -- or you're trying to compile e.g.
+`rustc` or `std` or something that depends on environment variables. In
+the unlikely case that you actually need to invoke rustc in such a situation,
+you can tell the bootstrap shim to print all env variables by adding `-vvv` to your `x.py` command.
+
+### Directories and artifacts generated by `bootstrap`
+
+This is an incomplete reference for the outputs generated by bootstrap:
| Stage 0 Action | Output |
|-----------------------------------------------------------|----------------------------------------------|
@@ -416,27 +448,3 @@ The following tables indicate the outputs of various stage actions:
| copy `rustdoc` | `build/HOST/stage2/bin` |
`--stage=2` stops here.
-
-## Passing stage-specific flags to `rustc`
-
-`x.py` allows you to pass stage-specific flags to `rustc` when bootstrapping.
-The `RUSTFLAGS_BOOTSTRAP` environment variable is passed as RUSTFLAGS to the bootstrap stage
-(stage0), and `RUSTFLAGS_NOT_BOOTSTRAP` is passed when building artifacts for later stages.
-
-## Environment Variables
-
-During bootstrapping, there are a bunch of compiler-internal environment
-variables that are used. If you are trying to run an intermediate version of
-`rustc`, sometimes you may need to set some of these environment variables
-manually. Otherwise, you get an error like the following:
-
-```text
-thread 'main' panicked at 'RUSTC_STAGE was not set: NotPresent', library/core/src/result.rs:1165:5
-```
-
-If `./stageN/bin/rustc` gives an error about environment variables, that
-usually means something is quite wrong -- or you're trying to compile e.g.
-`rustc` or `std` or something that depends on environment variables. In
-the unlikely case that you actually need to invoke rustc in such a situation,
-you can find the environment variable values by adding the following flag to
-your `x.py` command: `--on-fail=print-env`.
diff --git a/src/doc/rustc-dev-guide/src/building/how-to-build-and-run.md b/src/doc/rustc-dev-guide/src/building/how-to-build-and-run.md
index cce9d766a..c5cf3166d 100644
--- a/src/doc/rustc-dev-guide/src/building/how-to-build-and-run.md
+++ b/src/doc/rustc-dev-guide/src/building/how-to-build-and-run.md
@@ -150,8 +150,9 @@ This final product (stage1 compiler + libs built using that compiler)
is what you need to build other Rust programs (unless you use `#![no_std]` or
`#![no_core]`).
-You will probably find that building the stage1 `std` is a bottleneck for you** -- but fear not,
-there is a (hacky) workaround. See [the section on "recommended workflows"](./suggested.md) below.
+You will probably find that building the stage1 `std` is a bottleneck for you,
+but fear not, there is a (hacky) workaround...
+see [the section on "recommended workflows"](./suggested.md) below.
Note that this whole command just gives you a subset of the full `rustc`
build. The **full** `rustc` build (what you get with `./x.py build
@@ -220,6 +221,15 @@ fall back to using `cargo` from the installed `nightly`, `beta`, or `stable` too
`rustup install nightly` if you haven't already. See the
[rustup documentation on custom toolchains](https://rust-lang.github.io/rustup/concepts/toolchains.html#custom-toolchains).
+**Note:** rust-analyzer and IntelliJ Rust plugin use a component called
+`rust-analyzer-proc-macro-srv` to work with proc macros. If you intend to use a
+custom toolchain for a project (e.g. via `rustup override set stage1`) you may
+want to build this component:
+
+```bash
+./x.py build proc-macro-srv-cli
+```
+
## Building targets for cross-compilation
To produce a compiler that can cross-compile for other targets,
diff --git a/src/doc/rustc-dev-guide/src/building/new-target.md b/src/doc/rustc-dev-guide/src/building/new-target.md
index 77833fad1..f999a9472 100644
--- a/src/doc/rustc-dev-guide/src/building/new-target.md
+++ b/src/doc/rustc-dev-guide/src/building/new-target.md
@@ -102,15 +102,11 @@ unreleased version of `libc`, you can add it to the top-level
```diff
diff --git a/Cargo.toml b/Cargo.toml
-index be15e50e2bc..4fb1248ba99 100644
+index 1e83f05e0ca..4d0172071c1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
-@@ -66,10 +66,11 @@ cargo = { path = "src/tools/cargo" }
+@@ -113,6 +113,8 @@ cargo-util = { path = "src/tools/cargo/crates/cargo-util" }
[patch.crates-io]
- # Similar to Cargo above we want the RLS to use a vendored version of `rustfmt`
- # that we're shipping as well (to ensure that the rustfmt in RLS and the
- # `rustfmt` executable are the same exact version).
- rustfmt-nightly = { path = "src/tools/rustfmt" }
+libc = { git = "https://github.com/rust-lang/libc", rev = "0bf7ce340699dcbacabdf5f16a242d2219a49ee0" }
# See comments in `src/tools/rustc-workspace-hack/README.md` for what's going on
diff --git a/src/doc/rustc-dev-guide/src/building/prerequisites.md b/src/doc/rustc-dev-guide/src/building/prerequisites.md
index 0783e82ee..100b14aca 100644
--- a/src/doc/rustc-dev-guide/src/building/prerequisites.md
+++ b/src/doc/rustc-dev-guide/src/building/prerequisites.md
@@ -9,6 +9,7 @@ Before building the compiler, you need the following things installed:
* `git`
* `ssl` which comes in `libssl-dev` or `openssl-devel`
* `pkg-config` if you are compiling on Linux and targeting Linux
+* `libstdc++-static` may be required on some Linux distributions such as Fedora and Ubuntu
If building LLVM from source (the default), you'll need additional tools:
@@ -36,8 +37,10 @@ winget install -e Python.Python.3
winget install -e Kitware.CMake
```
-If any of those is installed already, winget will detect it.
-Then edit your systems `PATH` variable and add: `C:\Program Files\CMake\bin`.
+If any of those is installed already, winget will detect it. Then edit your system's `PATH` variable
+and add: `C:\Program Files\CMake\bin`. See
+[this guide on editing the system `PATH`](https://www.java.com/en/download/help/path.html) from the
+Java documentation.
For more information about building on Windows,
see [the `rust-lang/rust` README](https://github.com/rust-lang/rust#building-on-windows).
diff --git a/src/doc/rustc-dev-guide/src/building/suggested.md b/src/doc/rustc-dev-guide/src/building/suggested.md
index 3e077977d..5c5e571e4 100644
--- a/src/doc/rustc-dev-guide/src/building/suggested.md
+++ b/src/doc/rustc-dev-guide/src/building/suggested.md
@@ -36,14 +36,18 @@ you can write: <!-- date-check: apr 2022 --><!-- the date comment is for the edi
"./build/$TARGET_TRIPLE/stage0/bin/rustfmt",
"--edition=2021"
],
+ "rust-analyzer.procMacro.server": "./build/$TARGET_TRIPLE/stage0/libexec/rust-analyzer-proc-macro-srv",
"rust-analyzer.procMacro.enable": true,
"rust-analyzer.cargo.buildScripts.enable": true,
+ "rust-analyzer.cargo.buildScripts.invocationLocation": "root",
+ "rust-analyzer.cargo.buildScripts.invocationStrategy": "once",
"rust-analyzer.cargo.buildScripts.overrideCommand": [
"python3",
"x.py",
"check",
"--json-output"
],
+ "rust-analyzer.cargo.sysroot": "./build/$TARGET_TRIPLE/stage0-sysroot",
"rust-analyzer.rustc.source": "./Cargo.toml",
}
```
diff --git a/src/doc/rustc-dev-guide/src/closure.md b/src/doc/rustc-dev-guide/src/closure.md
index b43be3213..c3906a80b 100644
--- a/src/doc/rustc-dev-guide/src/closure.md
+++ b/src/doc/rustc-dev-guide/src/closure.md
@@ -135,10 +135,10 @@ appropriate trait: `Fn` trait for immutable borrow, `FnMut` for mutable borrow,
and `FnOnce` for move semantics.
Most of the code related to the closure is in the
-[`compiler/rustc_typeck/src/check/upvar.rs`][upvar] file and the data structures are
+[`compiler/rustc_hir_typeck/src/upvar.rs`][upvar] file and the data structures are
declared in the file [`compiler/rustc_middle/src/ty/mod.rs`][ty].
-[upvar]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/check/upvar/index.html
+[upvar]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/upvar/index.html
[ty]:https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/index.html
Before we go any further, let's discuss how we can examine the flow of control through the rustc
@@ -146,12 +146,12 @@ codebase. For closures specifically, set the `RUST_LOG` env variable as below an
output in a file:
```console
-> RUST_LOG=rustc_typeck::check::upvar rustc +stage1 -Z dump-mir=all \
+> RUST_LOG=rustc_hir_typeck::upvar rustc +stage1 -Z dump-mir=all \
<.rs file to compile> 2> <file where the output will be dumped>
```
This uses the stage1 compiler and enables `debug!` logging for the
-`rustc_typeck::check::upvar` module.
+`rustc_hir_typeck::upvar` module.
The other option is to step through the code using lldb or gdb.
@@ -164,7 +164,7 @@ Let's start with [`upvar.rs`][upvar]. This file has something called
the [`euv::ExprUseVisitor`] which walks the source of the closure and
invokes a callback for each upvar that is borrowed, mutated, or moved.
-[`euv::ExprUseVisitor`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/expr_use_visitor/struct.ExprUseVisitor.html
+[`euv::ExprUseVisitor`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/expr_use_visitor/struct.ExprUseVisitor.html
```rust
fn main() {
@@ -210,6 +210,6 @@ self.tables
.extend(delegate.adjust_upvar_captures);
```
-[`Delegate`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/expr_use_visitor/trait.Delegate.html
-[ibk]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/check/upvar/struct.InferBorrowKind.html
-[cmt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/mem_categorization/index.html
+[`Delegate`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/expr_use_visitor/trait.Delegate.html
+[ibk]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/upvar/struct.InferBorrowKind.html
+[cmt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/mem_categorization/index.html
diff --git a/src/doc/rustc-dev-guide/src/const-eval.md b/src/doc/rustc-dev-guide/src/const-eval.md
index 5a11f8cdd..a7b1c8963 100644
--- a/src/doc/rustc-dev-guide/src/const-eval.md
+++ b/src/doc/rustc-dev-guide/src/const-eval.md
@@ -20,26 +20,72 @@ Additionally constant evaluation can be used to reduce the workload or binary
size at runtime by precomputing complex operations at compiletime and only
storing the result.
+All uses of constant evaluation can either be categorized as "influencing the type system"
+(array lengths, enum variant discriminants, const generic parameters), or as solely being
+done to precompute expressions to be used at runtime.
+
Constant evaluation can be done by calling the `const_eval_*` functions of `TyCtxt`.
They're the wrappers of the `const_eval` query.
+* `const_eval_global_id_for_typeck` evaluates a constant to a valtree,
+ so the result value can be further inspected by the compiler.
+* `const_eval_global_id` evaluate a constant to an "opaque blob" containing its final value;
+ this is only useful for codegen backends and the CTFE evaluator engine itself.
+* `eval_static_initializer` specifically computes the initial values of a static.
+ Statics are special; all other functions do not represent statics correctly
+ and have thus assertions preventing their use on statics.
+
The `const_eval_*` functions use a [`ParamEnv`](./param_env.html) of environment
in which the constant is evaluated (e.g. the function within which the constant is used)
and a [`GlobalId`]. The `GlobalId` is made up of an `Instance` referring to a constant
or static or of an `Instance` of a function and an index into the function's `Promoted` table.
-Constant evaluation returns a [`EvalToConstValueResult`] with either the error, or a
-representation of the constant. `static` initializers are always represented as
-[`miri`](./miri.html) virtual memory allocations (via [`ConstValue::ByRef`]).
-Other constants get represented as [`ConstValue::Scalar`]
-or [`ConstValue::Slice`] if possible. This means that the `const_eval_*`
-functions cannot be used to create miri-pointers to the evaluated constant.
-If you need the value of a constant inside Miri, you need to directly work with
-[`const_to_op`].
+Constant evaluation returns an [`EvalToValTreeResult`] for type system constants or
+[`EvalToConstValueResult`] with either the error, or a representation of the constant.
+
+Constants for the type system are encoded in "valtree representation". The `ValTree` datastructure
+allows us to represent
+
+* arrays,
+* many structs,
+* tuples,
+* enums and,
+* most primitives.
+
+The basic rule for
+being permitted in the type system is that every value must be uniquely represented. In other
+words: a specific value must only be representable in one specific way. For example: there is only
+one way to represent an array of two integers as a `ValTree`:
+`ValTree::Branch(&[ValTree::Leaf(first_int), ValTree;:Leaf(second_int)])`.
+Even though theoretically a `[u32; 2]` could be encoded in a `u64` and thus just be a
+`ValTree::Leaf(bits_of_two_u32)`, that is not a legal construction of `ValTree`
+(and is very complex to do, so it is unlikely anyone is tempted to do so).
+
+These rules also mean that some values are not representable. There can be no `union`s in type
+level constants, as it is not clear how they should be represented, because their active variant
+is unknown. Similarly there is no way to represent raw pointers, as addresses are unknown at
+compile-time and thus we cannot make any assumptions about them. References on the other hand
+*can* be represented, as equality for references is defined as equality on their value, so we
+ignore their address and just look at the backing value. We must make sure that the pointer values
+of the references are not observable at compile time. We thus encode `&42` exactly like `42`.
+Any conversion from
+valtree back to codegen constants must reintroduce an actual indirection. At codegen time the
+addresses may be deduplicated between multiple uses or not, entirely depending on arbitrary
+optimization choices.
+
+As a consequence, all decoding of `ValTree` must happen by matching on the type first and making
+decisions depending on that. The value itself gives no useful information without the type that
+belongs to it.
+
+Other constants get represented as [`ConstValue::Scalar`] or
+[`ConstValue::Slice`] if possible. These values are only useful outside the
+compile-time interpreter. If you need the value of a constant during
+interpretation, you need to directly work with [`const_to_op`].
[`GlobalId`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/struct.GlobalId.html
[`ConstValue::Scalar`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/value/enum.ConstValue.html#variant.Scalar
[`ConstValue::Slice`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/value/enum.ConstValue.html#variant.Slice
[`ConstValue::ByRef`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/value/enum.ConstValue.html#variant.ByRef
[`EvalToConstValueResult`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/error/type.EvalToConstValueResult.html
+[`EvalToValTreeResult`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/error/type.EvalToValTreeResult.html
[`const_to_op`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_const_eval/interpret/struct.InterpCx.html#method.const_to_op
diff --git a/src/doc/rustc-dev-guide/src/miri.md b/src/doc/rustc-dev-guide/src/const-eval/interpret.md
index c5de358d2..ee044505e 100644
--- a/src/doc/rustc-dev-guide/src/miri.md
+++ b/src/doc/rustc-dev-guide/src/const-eval/interpret.md
@@ -1,14 +1,13 @@
-# Miri
+# Interpreter
<!-- toc -->
-The Miri (**MIR** **I**nterpreter) engine is a virtual machine for executing MIR without
-compiling to machine code. It is usually invoked via `tcx.const_eval_*` functions.
-In the following, we will refer to the Miri engine as just "Miri", but note that
-there also is a stand-alone
-[tool called "Miri"](https://github.com/rust-lang/miri/) that is based on the
-engine (sometimes referred to as Miri-the-tool to disambiguate it from the
-engine).
+The interpreter is a virtual machine for executing MIR without compiling to
+machine code. It is usually invoked via `tcx.const_eval_*` functions. The
+interpreter is shared between the compiler (for compile-time function
+evaluation, CTFE) and the tool [Miri](https://github.com/rust-lang/miri/), which
+uses the same virtual machine to detect Undefined Behavior in (unsafe) Rust
+code.
If you start out with a constant:
@@ -98,7 +97,7 @@ further queries need to be executed in order to get at something as simple as a
`usize`.
Future evaluations of the same constants will not actually invoke
-Miri, but just use the cached result.
+the interpreter, but just use the cached result.
[`Operand`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_const_eval/interpret/enum.Operand.html
[`Immediate`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_const_eval/interpret/enum.Immediate.html
@@ -108,7 +107,7 @@ Miri, but just use the cached result.
## Datastructures
-Miri's outside-facing datastructures can be found in
+The interpreter's outside-facing datastructures can be found in
[rustc_middle/src/mir/interpret](https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/mir/interpret).
This is mainly the error enum and the [`ConstValue`] and [`Scalar`] types. A
`ConstValue` can be either `Scalar` (a single `Scalar`, i.e., integer or thin
@@ -124,7 +123,7 @@ in an `Option<u64>` yielding the `Scalar` if possible.
## Memory
-To support any kind of pointers, Miri needs to have a "virtual memory" that the
+To support any kind of pointers, the interpreter needs to have a "virtual memory" that the
pointers can point to. This is implemented in the [`Memory`] type. In the
simplest model, every global variable, stack variable and every dynamic
allocation corresponds to an [`Allocation`] in that memory. (Actually using an
@@ -164,7 +163,7 @@ track of which of its bytes are initialized.
### Global memory and exotic allocations
-`Memory` exists only during the Miri evaluation; it gets destroyed when the
+`Memory` exists only during evaluation; it gets destroyed when the
final value of the constant is computed. In case that constant contains any
pointers, those get "interned" and moved to a global "const eval memory" that is
part of `TyCtxt`. These allocations stay around for the remaining computation
@@ -190,10 +189,10 @@ bytes of its value.
### Pointer values vs Pointer types
-One common cause of confusion in Miri is that being a pointer *value* and having
+One common cause of confusion in the interpreter is that being a pointer *value* and having
a pointer *type* are entirely independent properties. By "pointer value", we
refer to a `Scalar::Ptr` containing a `Pointer` and thus pointing somewhere into
-Miri's virtual memory. This is in contrast to `Scalar::Raw`, which is just some
+the interpreter's virtual memory. This is in contrast to `Scalar::Raw`, which is just some
concrete integer.
However, a variable of pointer or reference *type*, such as `*const T` or `&T`,
@@ -214,7 +213,7 @@ that allow accessing the fields of a `ConstValue` (`ByRef` or otherwise). You sh
never have to access an `Allocation` directly except for translating it to the
compilation target (at the moment just LLVM).
-Miri starts by creating a virtual stack frame for the current constant that is
+The interpreter starts by creating a virtual stack frame for the current constant that is
being evaluated. There's essentially no difference between a constant and a
function with no arguments, except that constants do not allow local (named)
variables at the time of writing this guide.
@@ -231,7 +230,7 @@ The frames are just a `Vec<Frame>`, there's no way to actually refer to a
`Frame`'s memory even if horrible shenanigans are done via unsafe code. The only
memory that can be referred to are `Allocation`s.
-Miri now calls the `step` method (in
+The interpreter now calls the `step` method (in
[rustc_const_eval/src/interpret/step.rs](https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/step.rs)
) until it either returns an error or has no further statements to execute. Each
statement will now initialize or modify the locals or the virtual memory
diff --git a/src/doc/rustc-dev-guide/src/contributing.md b/src/doc/rustc-dev-guide/src/contributing.md
index e59bb0a77..279bc2f28 100644
--- a/src/doc/rustc-dev-guide/src/contributing.md
+++ b/src/doc/rustc-dev-guide/src/contributing.md
@@ -183,6 +183,7 @@ As a developer to this repository, you don't have to treat the following externa
differently from other crates that are directly in this repo:
* [Clippy](https://github.com/rust-lang/rust-clippy)
+* [Miri](https://github.com/rust-lang/miri)
* [rustfmt](https://github.com/rust-lang/rustfmt)
* [rust-analyzer](https://github.com/rust-lang/rust-analyzer)
@@ -249,37 +250,36 @@ subtrees) actually needs to use `git subtree`.
### External Dependencies (submodules)
-Currently building Rust will also build the following external projects:
+Building Rust will also use external git repositories tracked using [git
+submodules]. The complete list may be found in the [`.gitmodules`] file. Some
+of these projects are required (like `stdarch` for the standard library) and
+some of them are optional (like [Miri]).
-* [miri](https://github.com/rust-lang/miri)
-* [rls](https://github.com/rust-lang/rls/)
+Usage of submodules is discussed more in the [Using Git
+chapter](git.md#git-submodules).
-We allow breakage of these tools in the nightly channel. Maintainers of these
-projects will be notified of the breakages and should fix them as soon as
-possible.
-
-After the external is fixed, one could add the changes with
-
-```sh
-git add path/to/submodule
-```
-
-outside the submodule.
-
-In order to prepare your tool-fixing PR, you can run the build locally by doing
-`./x.py build src/tools/TOOL`. If you will be editing the sources
-there, you may wish to set `submodules = false` in the `config.toml`
-to prevent `x.py` from resetting to the original branch.
+Some of the submodules are allowed to be in a "broken" state where they
+either don't build or their tests don't pass, e.g. the documentation books
+like [The Rust Reference]. Maintainers of these projects will be notified
+when the project is in a broken state, and they should fix them as soon
+as possible. The current status is tracked on the [toolstate website].
+More information may be found on the Forge [Toolstate chapter].
Breakage is not allowed in the beta and stable channels, and must be addressed
-before the PR is merged.
+before the PR is merged. They are also not allowed to be broken on master in
+the week leading up to the beta cut.
+
+[git submodules]: https://git-scm.com/book/en/v2/Git-Tools-Submodules
+[`.gitmodules`]: https://github.com/rust-lang/rust/blob/master/.gitmodules
+[The Rust Reference]: https://github.com/rust-lang/reference/
+[toolstate website]: https://rust-lang-nursery.github.io/rust-toolstate/
+[Toolstate chapter]: https://forge.rust-lang.org/infra/toolstate.html
#### Breaking Tools Built With The Compiler
Rust's build system builds a number of tools that make use of the internals of
the compiler and that are hosted in a separate repository, and included in Rust
-via git submodules. This includes [RLS](https://github.com/rust-lang/rls) and
-[Miri](https://github.com/rust-lang/Miri). If these tools break because of your
+via git submodules (such as [Miri]). If these tools break because of your
changes, you may run into a sort of "chicken and egg" problem. These tools rely
on the latest compiler to be built so you can't update them (in their own
repositories) to reflect your changes to the compiler until those changes are
@@ -299,7 +299,7 @@ done and the tools are working again, you go back in the compiler and update the
tools so they can be distributed again.
This should avoid a bunch of synchronization dances and is also much easier on contributors as
-there's no need to block on rls/miri/other tools changes going upstream.
+there's no need to block on tools changes going upstream.
Here are those same steps in detail:
@@ -309,8 +309,8 @@ Here are those same steps in detail:
from resetting to the original branch after you make your changes. If you
need to [update any submodules to their latest versions](#updating-submodules),
see the section of this file about that for more information.
-2. (optional) Run `./x.py test src/tools/rls` (substituting the submodule
- that broke for `rls`). Fix any errors in the submodule (and possibly others).
+2. (optional) Run `./x.py test src/tools/cargo` (substituting the submodule
+ that broke for `cargo`). Fix any errors in the submodule (and possibly others).
3. (optional) Make commits for your changes and send them to upstream repositories as a PR.
4. (optional) Maintainers of these submodules will **not** merge the PR. The PR can't be
merged because CI will be broken. You'll want to write a message on the PR referencing
@@ -320,71 +320,6 @@ Here are those same steps in detail:
7. (optional) Help land your PR on the upstream repository now that your changes are in nightly.
8. (optional) Send a PR to rust-lang/rust updating the submodule.
-#### Updating submodules
-
-These instructions are specific to updating `rls`, however they may apply
-to the other submodules as well. Please help by improving these instructions
-if you find any discrepancies or special cases that need to be addressed.
-
-To update the `rls` submodule, start by running the appropriate
-[`git submodule` command](https://git-scm.com/book/en/v2/Git-Tools-Submodules).
-For example, to update to the latest commit on the remote master branch,
-you may want to run:
-```
-git submodule update --remote src/tools/rls
-```
-If you run `./x.py build` now, and you are lucky, it may just work. If you see
-an error message about patches that did not resolve to any crates, you will need
-to complete a few more steps which are outlined with their rationale below.
-
-*(This error may change in the future to include more information.)*
-```
-error: failed to resolve patches for `https://github.com/rust-lang/rls`
-
-Caused by:
- patch for `rls` in `https://github.com/rust-lang/rls` did not resolve to any crates
-failed to run: ~/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path ~/rust/src/bootstrap/Cargo.toml
-```
-
-The [`[patch]`][patchsec] section of `Cargo.toml` can be very useful for
-testing. In addition to that, you should read the [Overriding
-dependencies][overriding] section of the documentation.
-
-[patchsec]: http://doc.crates.io/manifest.html#the-patch-section
-[overriding]: http://doc.crates.io/specifying-dependencies.html#overriding-dependencies
-
-Specifically, the following [section in Overriding dependencies][testingbugfix]
-reveals what the problem is:
-
-[testingbugfix]: http://doc.crates.io/specifying-dependencies.html#testing-a-bugfix
-
-> Next up we need to ensure that our lock file is updated to use this new
-> version of uuid so our project uses the locally checked out copy instead of
-> one from crates.io. The way `[patch]` works is that it'll load the dependency
-> at ../path/to/uuid and then whenever crates.io is queried for versions of
-> uuid it'll also return the local version.
->
-> This means that the version number of the local checkout is significant and
-> will affect whether the patch is used. Our manifest declared uuid = "1.0"
-> which means we'll only resolve to >= 1.0.0, < 2.0.0, and Cargo's greedy
-> resolution algorithm also means that we'll resolve to the maximum version
-> within that range. Typically this doesn't matter as the version of the git
-> repository will already be greater or match the maximum version published on
-> crates.io, but it's important to keep this in mind!
-
-This says that when we updated the submodule, the version number in our
-`src/tools/rls/Cargo.toml` changed. The new version is different from
-the version in `Cargo.lock`, so the build can no longer continue.
-
-To resolve this, we need to update `Cargo.lock`. Luckily, cargo provides a
-command to do this easily.
-
-```
-$ cargo update -p rls
-```
-
-This should change the version listed in `Cargo.lock` to the new version you updated
-the submodule to. Running `./x.py build` should work now.
## Writing Documentation
diff --git a/src/doc/rustc-dev-guide/src/diagnostics.md b/src/doc/rustc-dev-guide/src/diagnostics.md
index 0f0bfd895..e1d5fbe1a 100644
--- a/src/doc/rustc-dev-guide/src/diagnostics.md
+++ b/src/doc/rustc-dev-guide/src/diagnostics.md
@@ -314,10 +314,10 @@ reporting errors.
[errors]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/index.html
-Diagnostics can be implemented as types which implement the `SessionDiagnostic`
+Diagnostics can be implemented as types which implement the `IntoDiagnostic`
trait. This is preferred for new diagnostics as it enforces a separation
between diagnostic emitting logic and the main code paths. For less-complex
-diagnostics, the `SessionDiagnostic` trait can be derived -- see [Diagnostic
+diagnostics, the `IntoDiagnostic` trait can be derived -- see [Diagnostic
structs][diagnostic-structs]. Within the trait implementation, the APIs
described below can be used as normal.
@@ -388,10 +388,8 @@ In addition to telling the user exactly _why_ their code is wrong, it's
oftentimes furthermore possible to tell them how to fix it. To this end,
`DiagnosticBuilder` offers a structured suggestions API, which formats code
suggestions pleasingly in the terminal, or (when the `--error-format json` flag
-is passed) as JSON for consumption by tools, most notably the [Rust Language
-Server][rls] and [`rustfix`][rustfix].
+is passed) as JSON for consumption by tools like [`rustfix`][rustfix].
-[rls]: https://github.com/rust-lang/rls
[rustfix]: https://github.com/rust-lang/rustfix
Not all suggestions should be applied mechanically, they have a degree of
@@ -757,7 +755,7 @@ then dumped into the `Session::buffered_lints` used by the rest of the compiler.
The compiler accepts an `--error-format json` flag to output
diagnostics as JSON objects (for the benefit of tools such as `cargo
-fix` or the RLS). It looks like this:
+fix`). It looks like this:
```console
$ rustc json_error_demo.rs --error-format json
@@ -771,7 +769,7 @@ object, but the series of lines taken together is, unfortunately, not
valid JSON, thwarting tools and tricks (such as [piping to `python3 -m
json.tool`](https://docs.python.org/3/library/json.html#module-json.tool))
that require such. (One speculates that this was intentional for LSP
-performance purposes, so that each line/object can be sent to RLS as
+performance purposes, so that each line/object can be sent as
it is flushed?)
Also note the "rendered" field, which contains the "human" output as a
diff --git a/src/doc/rustc-dev-guide/src/diagnostics/diagnostic-structs.md b/src/doc/rustc-dev-guide/src/diagnostics/diagnostic-structs.md
index f456474c7..d51e79348 100644
--- a/src/doc/rustc-dev-guide/src/diagnostics/diagnostic-structs.md
+++ b/src/doc/rustc-dev-guide/src/diagnostics/diagnostic-structs.md
@@ -1,14 +1,14 @@
# Diagnostic and subdiagnostic structs
rustc has two diagnostic derives that can be used to create simple diagnostics,
which are recommended to be used when they are applicable:
-`#[derive(SessionDiagnostic)]` and `#[derive(SessionSubdiagnostic)]`.
+`#[derive(Diagnostic)]` and `#[derive(Subdiagnostic)]`.
Diagnostics created with the derive macros can be translated into different
languages and each has a slug that uniquely identifies the diagnostic.
-## `#[derive(SessionDiagnostic)]`
+## `#[derive(Diagnostic)]`
Instead of using the `DiagnosticBuilder` API to create and emit diagnostics,
-the `SessionDiagnostic` derive can be used. `#[derive(SessionDiagnostic)]` is
+the `Diagnostic` derive can be used. `#[derive(Diagnostic)]` is
only applicable for simple diagnostics that don't require much logic in
deciding whether or not to add additional subdiagnostics.
@@ -16,24 +16,24 @@ Consider the [definition][defn] of the "field already declared" diagnostic
shown below:
```rust,ignore
-#[derive(SessionDiagnostic)]
-#[diag(typeck::field_already_declared, code = "E0124")]
+#[derive(Diagnostic)]
+#[diag(hir_analysis_field_already_declared, code = "E0124")]
pub struct FieldAlreadyDeclared {
pub field_name: Ident,
#[primary_span]
#[label]
pub span: Span,
- #[label(typeck::previous_decl_label)]
+ #[label(hir_analysis_previous_decl_label)]
pub prev_span: Span,
}
```
-`SessionDiagnostic` can only be applied to structs. Every `SessionDiagnostic`
+`Diagnostic` can only be applied to structs. Every `Diagnostic`
has to have one attribute, `#[diag(...)]`, applied to the struct itself.
If an error has an error code (e.g. "E0624"), then that can be specified using
the `code` sub-attribute. Specifying a `code` isn't mandatory, but if you are
-porting a diagnostic that uses `DiagnosticBuilder` to use `SessionDiagnostic`
+porting a diagnostic that uses `DiagnosticBuilder` to use `Diagnostic`
then you should keep the code if there was one.
`#[diag(..)]` must provide a slug as the first positional argument (a path to an
@@ -47,16 +47,16 @@ In our example, the Fluent message for the "field already declared" diagnostic
looks like this:
```fluent
-typeck_field_already_declared =
+hir_analysis_field_already_declared =
field `{$field_name}` is already declared
.label = field already declared
.previous_decl_label = `{$field_name}` first declared here
```
-`typeck_field_already_declared` is the slug from our example and is followed
+`hir_analysis_field_already_declared` is the slug from our example and is followed
by the diagnostic message.
-Every field of the `SessionDiagnostic` which does not have an annotation is
+Every field of the `Diagnostic` which does not have an annotation is
available in Fluent messages as a variable, like `field_name` in the example
above. Fields can be annotated `#[skip_arg]` if this is undesired.
@@ -66,19 +66,19 @@ of the diagnostic.
Diagnostics are more than just their primary message, they often include
labels, notes, help messages and suggestions, all of which can also be
-specified on a `SessionDiagnostic`.
+specified on a `Diagnostic`.
`#[label]`, `#[help]` and `#[note]` can all be applied to fields which have the
type `Span`. Applying any of these attributes will create the corresponding
subdiagnostic with that `Span`. These attributes will look for their
diagnostic message in a Fluent attribute attached to the primary Fluent
message. In our example, `#[label]` will look for
-`typeck_field_already_declared.label` (which has the message "field already
+`hir_analysis_field_already_declared.label` (which has the message "field already
declared"). If there is more than one subdiagnostic of the same type, then
these attributes can also take a value that is the attribute name to look for
(e.g. `previous_decl_label` in our example).
-Other types have special behavior when used in a `SessionDiagnostic` derive:
+Other types have special behavior when used in a `Diagnostic` derive:
- Any attribute applied to an `Option<T>` and will only emit a
subdiagnostic if the option is `Some(..)`.
@@ -107,21 +107,21 @@ the value of the `field_name` field of the struct), not a Fluent identifier.
`applicability` can be used to specify the applicability in the attribute, it
cannot be used when the field's type contains an `Applicability`.
-In the end, the `SessionDiagnostic` derive will generate an implementation of
-`SessionDiagnostic` that looks like the following:
+In the end, the `Diagnostic` derive will generate an implementation of
+`IntoDiagnostic` that looks like the following:
```rust,ignore
-impl SessionDiagnostic<'_> for FieldAlreadyDeclared {
- fn into_diagnostic(self, sess: &'_ rustc_session::Session) -> DiagnosticBuilder<'_> {
- let mut diag = sess.struct_err(rustc_errors::fluent::typeck::field_already_declared);
+impl IntoDiagnostic<'_> for FieldAlreadyDeclared {
+ fn into_diagnostic(self, handler: &'_ rustc_errors::Handler) -> DiagnosticBuilder<'_> {
+ let mut diag = handler.struct_err(rustc_errors::fluent::hir_analysis_field_already_declared);
diag.set_span(self.span);
diag.span_label(
self.span,
- rustc_errors::fluent::typeck::label
+ rustc_errors::fluent::hir_analysis_label
);
diag.span_label(
self.prev_span,
- rustc_errors::fluent::typeck::previous_decl_label
+ rustc_errors::fluent::hir_analysis_previous_decl_label
);
diag
}
@@ -141,22 +141,20 @@ tcx.sess.emit_err(FieldAlreadyDeclared {
```
### Reference
-`#[derive(SessionDiagnostic)]` and `#[derive(LintDiagnostic)]` support the
+`#[derive(Diagnostic)]` and `#[derive(LintDiagnostic)]` support the
following attributes:
- `#[diag(slug, code = "...")]`
- - _Applied to struct._
+ - _Applied to struct or enum variant._
- _Mandatory_
- Defines the text and error code to be associated with the diagnostic.
- Slug (_Mandatory_)
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
mandatory.
- - A path to an item in `rustc_errors::fluent`. Always in a module starting
- with a Fluent resource name (which is typically the name of the crate
- that the diagnostic is from), e.g.
- `rustc_errors::fluent::typeck::field_already_declared`
+ - A path to an item in `rustc_errors::fluent`, e.g.
+ `rustc_errors::fluent::hir_analysis_field_already_declared`
(`rustc_errors::fluent` is implicit in the attribute, so just
- `typeck::field_already_declared`).
+ `hir_analysis_field_already_declared`).
- See [translation documentation](./translation.md).
- `code = "..."` (_Optional_)
- Specifies the error code.
@@ -191,14 +189,12 @@ following attributes:
- _Applied to `(Span, MachineApplicability)` or `Span` fields._
- Adds a suggestion subdiagnostic.
- Slug (_Mandatory_)
- - A path to an item in `rustc_errors::fluent`. Always in a module starting
- with a Fluent resource name (which is typically the name of the crate
- that the diagnostic is from), e.g.
- `rustc_errors::fluent::typeck::field_already_declared`
+ - A path to an item in `rustc_errors::fluent`, e.g.
+ `rustc_errors::fluent::hir_analysis_field_already_declared`
(`rustc_errors::fluent` is implicit in the attribute, so just
- `typeck::field_already_declared`). Fluent attributes for all messages
- exist as top-level items in that module (so `typeck_message.attr` is just
- `typeck::attr`).
+ `hir_analysis_field_already_declared`). Fluent attributes for all messages
+ exist as top-level items in that module (so `hir_analysis_message.attr` is just
+ `attr`).
- See [translation documentation](./translation.md).
- Defaults to `rustc_errors::fluent::_subdiag::suggestion` (or
- `.suggestion` in Fluent).
@@ -210,20 +206,20 @@ following attributes:
`has-placeholders` or `unspecified`.
- `#[subdiagnostic]`
- _Applied to a type that implements `AddToDiagnostic` (from
- `#[derive(SessionSubdiagnostic)]`)._
+ `#[derive(Subdiagnostic)]`)._
- Adds the subdiagnostic represented by the subdiagnostic struct.
- `#[primary_span]` (_Optional_)
- - _Applied to `Span` fields on `SessionSubdiagnostic`s. Not used for `LintDiagnostic`s._
+ - _Applied to `Span` fields on `Subdiagnostic`s. Not used for `LintDiagnostic`s._
- Indicates the primary span of the diagnostic.
- `#[skip_arg]` (_Optional_)
- _Applied to any field._
- Prevents the field from being provided as a diagnostic argument.
-## `#[derive(SessionSubdiagnostic)]`
+## `#[derive(Subdiagnostic)]`
It is common in the compiler to write a function that conditionally adds a
specific subdiagnostic to an error if it is applicable. Oftentimes these
subdiagnostics could be represented using a diagnostic struct even if the
-overall diagnostic could not. In this circumstance, the `SessionSubdiagnostic`
+overall diagnostic could not. In this circumstance, the `Subdiagnostic`
derive can be used to represent a partial diagnostic (e.g a note, label, help or
suggestion) as a struct.
@@ -231,14 +227,14 @@ Consider the [definition][subdiag_defn] of the "expected return type" label
shown below:
```rust
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
pub enum ExpectedReturnTypeLabel<'tcx> {
- #[label(typeck::expected_default_return_type)]
+ #[label(hir_analysis_expected_default_return_type)]
Unit {
#[primary_span]
span: Span,
},
- #[label(typeck::expected_return_type)]
+ #[label(hir_analysis_expected_return_type)]
Other {
#[primary_span]
span: Span,
@@ -247,9 +243,9 @@ pub enum ExpectedReturnTypeLabel<'tcx> {
}
```
-Unlike `SessionDiagnostic`, `SessionSubdiagnostic` can be applied to structs or
+Unlike `Diagnostic`, `Subdiagnostic` can be applied to structs or
enums. Attributes that are placed on the type for structs are placed on each
-variants for enums (or vice versa). Each `SessionSubdiagnostic` should have one
+variants for enums (or vice versa). Each `Subdiagnostic` should have one
attribute applied to the struct or each variant, one of:
- `#[label(..)]` for defining a label
@@ -268,9 +264,9 @@ In our example, the Fluent message for the "expected return type" label
looks like this:
```fluent
-typeck_expected_default_return_type = expected `()` because of default return type
+hir_analysis_expected_default_return_type = expected `()` because of default return type
-typeck_expected_return_type = expected `{$expected}` because of return type
+hir_analysis_expected_return_type = expected `{$expected}` because of return type
```
Using the `#[primary_span]` attribute on a field (with type `Span`) will denote
@@ -281,7 +277,7 @@ Every field of the type/variant which does not have an annotation is available
in Fluent messages as a variable. Fields can be annotated `#[skip_arg]` if this
is undesired.
-Like `SessionDiagnostic`, `SessionSubdiagnostic` supports `Option<T>` and
+Like `Diagnostic`, `Subdiagnostic` supports `Option<T>` and
`Vec<T>` fields.
Suggestions can be emitted using one of four attributes on the type/variant:
@@ -306,8 +302,8 @@ following sub-attributes:
Applicabilities can also be specified as a field (of type `Applicability`)
using the `#[applicability]` attribute.
-In the end, the `SessionSubdiagnostic` derive will generate an implementation
-of `SessionSubdiagnostic` that looks like the following:
+In the end, the `Subdiagnostic` derive will generate an implementation
+of `AddToDiagnostic` that looks like the following:
```rust
impl<'tcx> AddToDiagnostic for ExpectedReturnTypeLabel<'tcx> {
@@ -315,11 +311,11 @@ impl<'tcx> AddToDiagnostic for ExpectedReturnTypeLabel<'tcx> {
use rustc_errors::{Applicability, IntoDiagnosticArg};
match self {
ExpectedReturnTypeLabel::Unit { span } => {
- diag.span_label(span, rustc_errors::fluent::typeck::expected_default_return_type)
+ diag.span_label(span, rustc_errors::fluent::hir_analysis_expected_default_return_type)
}
ExpectedReturnTypeLabel::Other { span, expected } => {
diag.set_arg("expected", expected);
- diag.span_label(span, rustc_errors::fluent::typeck::expected_return_type)
+ diag.span_label(span, rustc_errors::fluent::hir_analysis_expected_return_type)
}
}
@@ -333,7 +329,7 @@ diagnostic or by assigning it to a `#[subdiagnostic]`-annotated field of a
diagnostic struct.
### Reference
-`#[derive(SessionSubdiagnostic)]` supports the following attributes:
+`#[derive(Subdiagnostic)]` supports the following attributes:
- `#[label(slug)]`, `#[help(slug)]` or `#[note(slug)]`
- _Applied to struct or enum variant. Mutually exclusive with struct/enum variant attributes._
@@ -342,26 +338,22 @@ diagnostic struct.
- Slug (_Mandatory_)
- Uniquely identifies the diagnostic and corresponds to its Fluent message,
mandatory.
- - A path to an item in `rustc_errors::fluent`. Always in a module starting
- with a Fluent resource name (which is typically the name of the crate
- that the diagnostic is from), e.g.
- `rustc_errors::fluent::typeck::field_already_declared`
+ - A path to an item in `rustc_errors::fluent`, e.g.
+ `rustc_errors::fluent::hir_analysis_field_already_declared`
(`rustc_errors::fluent` is implicit in the attribute, so just
- `typeck::field_already_declared`).
+ `hir_analysis_field_already_declared`).
- See [translation documentation](./translation.md).
- `#[suggestion{,_hidden,_short,_verbose}(slug, code = "...", applicability = "...")]`
- _Applied to struct or enum variant. Mutually exclusive with struct/enum variant attributes._
- _Mandatory_
- Defines the type to be representing a suggestion.
- Slug (_Mandatory_)
- - A path to an item in `rustc_errors::fluent`. Always in a module starting
- with a Fluent resource name (which is typically the name of the crate
- that the diagnostic is from), e.g.
- `rustc_errors::fluent::typeck::field_already_declared`
+ - A path to an item in `rustc_errors::fluent`, e.g.
+ `rustc_errors::fluent::hir_analysis_field_already_declared`
(`rustc_errors::fluent` is implicit in the attribute, so just
- `typeck::field_already_declared`). Fluent attributes for all messages
- exist as top-level items in that module (so `typeck_message.attr` is just
- `typeck::attr`).
+ `hir_analysis::field_already_declared`). Fluent attributes for all messages
+ exist as top-level items in that module (so `hir_analysis_message.attr` is just
+ `hir_analysis::attr`).
- See [translation documentation](./translation.md).
- Defaults to `rustc_errors::fluent::_subdiag::suggestion` (or
- `.suggestion` in Fluent).
@@ -376,19 +368,32 @@ diagnostic struct.
- `maybe-incorrect`
- `has-placeholders`
- `unspecified`
-- `#[primary_span]` (_Mandatory_ for labels and suggestions; _optional_ otherwise)
+- `#[multipart_suggestion{,_hidden,_short,_verbose}(slug, applicability = "...")]`
+ - _Applied to struct or enum variant. Mutually exclusive with struct/enum variant attributes._
+ - _Mandatory_
+ - Defines the type to be representing a multipart suggestion.
+ - Slug (_Mandatory_): see `#[suggestion]`
+ - `applicability = "..."` (_Optional_): see `#[suggestion]`
+- `#[primary_span]` (_Mandatory_ for labels and suggestions; _optional_ otherwise; not applicable
+to multipart suggestions)
- _Applied to `Span` fields._
- Indicates the primary span of the subdiagnostic.
-- `#[applicability]` (_Optional_; only applicable to suggestions)
+- `#[suggestion_part(code = "...")]` (_Mandatory_; only applicable to multipart suggestions)
+ - _Applied to `Span` fields._
+ - Indicates the span to be one part of the multipart suggestion.
+ - `code = "..."` (_Mandatory_)
+ - Value is a format string indicating the code to be suggested as a
+ replacement.
+- `#[applicability]` (_Optional_; only applicable to (simple and multipart) suggestions)
- _Applied to `Applicability` fields._
- Indicates the applicability of the suggestion.
- `#[skip_arg]` (_Optional_)
- _Applied to any field._
- Prevents the field from being provided as a diagnostic argument.
-[defn]: https://github.com/rust-lang/rust/blob/bbe9d27b8ff36da56638aa43d6d0cdfdf89a4e57/compiler/rustc_typeck/src/errors.rs#L65-L74
-[use]: https://github.com/rust-lang/rust/blob/eb82facb1626166188d49599a3313fc95201f556/compiler/rustc_typeck/src/collect.rs#L981-L985
+[defn]: https://github.com/rust-lang/rust/blob/6201eabde85db854c1ebb57624be5ec699246b50/compiler/rustc_hir_analysis/src/errors.rs#L68-L77
+[use]: https://github.com/rust-lang/rust/blob/f1112099eba41abadb6f921df7edba70affe92c5/compiler/rustc_hir_analysis/src/collect.rs#L823-L827
-[subdiag_defn]: https://github.com/rust-lang/rust/blob/e70c60d34b9783a2fd3171d88d248c2e0ec8ecdd/compiler/rustc_typeck/src/errors.rs#L220-L233
-[subdiag_use_1]: https://github.com/rust-lang/rust/blob/e70c60d34b9783a2fd3171d88d248c2e0ec8ecdd/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs#L556-L560
-[subdiag_use_2]: https://github.com/rust-lang/rust/blob/e70c60d34b9783a2fd3171d88d248c2e0ec8ecdd/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs#L575-L579
+[subdiag_defn]: https://github.com/rust-lang/rust/blob/f1112099eba41abadb6f921df7edba70affe92c5/compiler/rustc_hir_analysis/src/errors.rs#L221-L234
+[subdiag_use_1]: https://github.com/rust-lang/rust/blob/f1112099eba41abadb6f921df7edba70affe92c5/compiler/rustc_hir_analysis/src/check/fn_ctxt/suggestions.rs#L670-L674
+[subdiag_use_2]: https://github.com/rust-lang/rust/blob/f1112099eba41abadb6f921df7edba70affe92c5/compiler/rustc_hir_analysis/src/check/fn_ctxt/suggestions.rs#L704-L707
diff --git a/src/doc/rustc-dev-guide/src/diagnostics/translation.md b/src/doc/rustc-dev-guide/src/diagnostics/translation.md
index 5bb37fbc2..e36333039 100644
--- a/src/doc/rustc-dev-guide/src/diagnostics/translation.md
+++ b/src/doc/rustc-dev-guide/src/diagnostics/translation.md
@@ -11,7 +11,7 @@ There are two ways of writing translatable diagnostics:
diagnostic structs). See [the diagnostic and subdiagnostic structs
documentation](./diagnostic-structs.md).
2. Using typed identifiers with `DiagnosticBuilder` APIs (in
- `SessionDiagnostic` implementations).
+ `Diagnostic` implementations).
When adding or changing a translatable diagnostic, you don't need to worry
about the translations, only updating the original English message. Currently,
@@ -127,14 +127,12 @@ pub static DEFAULT_LOCALE_RESOURCES: &'static [&'static str] = &[
];
mod fluent_generated {
- mod typeck {
- pub const field_multiply_specified_in_initializer: DiagnosticMessage =
- DiagnosticMessage::new("typeck_field_multiply_specified_in_initializer");
- pub const label: SubdiagnosticMessage =
- SubdiagnosticMessage::attr("label");
- pub const label_previous_use: SubdiagnosticMessage =
- SubdiagnosticMessage::attr("previous_use_label");
- }
+ pub const typeck_field_multiply_specified_in_initializer: DiagnosticMessage =
+ DiagnosticMessage::new("typeck_field_multiply_specified_in_initializer");
+ pub const label: SubdiagnosticMessage =
+ SubdiagnosticMessage::attr("label");
+ pub const label_previous_use: SubdiagnosticMessage =
+ SubdiagnosticMessage::attr("previous_use_label");
}
```
@@ -143,9 +141,9 @@ mod fluent_generated {
```rust
use rustc_errors::fluent;
-let mut err = sess.struct_span_err(span, fluent::typeck::field_multiply_specified_in_initializer);
-err.span_label(span, fluent::typeck::label);
-err.span_label(previous_use_span, fluent::typeck::previous_use_label);
+let mut err = sess.struct_span_err(span, fluent::typeck_field_multiply_specified_in_initializer);
+err.span_label(span, fluent::label);
+err.span_label(previous_use_span, fluent::previous_use_label);
err.emit();
```
diff --git a/src/doc/rustc-dev-guide/src/feature-gates.md b/src/doc/rustc-dev-guide/src/feature-gates.md
index 229281f2f..9e9a83ea6 100644
--- a/src/doc/rustc-dev-guide/src/feature-gates.md
+++ b/src/doc/rustc-dev-guide/src/feature-gates.md
@@ -9,7 +9,9 @@ modifying feature gates.
See ["Stability in code"] for help with adding a new feature; this section just
covers how to add the feature gate *declaration*.
-Add a feature gate declaration to `rustc_feature/src/active.rs` in the active
+First, add the feature name to `rustc_span/src/symbol.rs` in the `Symbols {...}` block.
+
+Then, add a feature gate declaration to `rustc_feature/src/active.rs` in the active
`declare_features` block:
```rust,ignore
diff --git a/src/doc/rustc-dev-guide/src/generics.md b/src/doc/rustc-dev-guide/src/generics.md
index 13549b2fb..0173bee8f 100644
--- a/src/doc/rustc-dev-guide/src/generics.md
+++ b/src/doc/rustc-dev-guide/src/generics.md
@@ -125,7 +125,7 @@ You may have a couple of followup questions…
`MyStruct`: `Adt(Foo, &[Param(0), Param(1)])`.
**`subst`** How do we actually do the substitutions? There is a function for that too! You use
-[`subst`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/subst/trait.Subst.html) to
+[`subst`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/subst/struct.EarlyBinder.html#method.subst) to
replace a `SubstRef` with another list of types.
[Here is an example of actually using `subst` in the compiler][substex]. The exact details are not
@@ -134,7 +134,7 @@ a real `ty::Ty`. You can see that we first get some substitutions (`substs`). T
`type_of` to get a type and call `ty.subst(substs)` to get a new version of `ty` with
the substitutions made.
-[substex]: https://github.com/rust-lang/rust/blob/597f432489f12a3f33419daa039ccef11a12c4fd/src/librustc_typeck/astconv.rs#L942-L953
+[substex]: https://github.com/rust-lang/rust/blob/0940040c0486a536be4f8685c7dd9a078f9e87c2/compiler/rustc_hir_analysis/src/astconv/mod.rs#L1231-L1242
**Note on indices:** It is possible for the indices in `Param` to not match with what we expect. For
example, the index could be out of bounds or it could be the index of a lifetime when we were
diff --git a/src/doc/rustc-dev-guide/src/git.md b/src/doc/rustc-dev-guide/src/git.md
index 5899753ba..65397e349 100644
--- a/src/doc/rustc-dev-guide/src/git.md
+++ b/src/doc/rustc-dev-guide/src/git.md
@@ -148,8 +148,8 @@ Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
+ modified: src/llvm-project (new commits)
modified: src/tools/cargo (new commits)
- modified: src/tools/rls (new commits)
no changes added to commit (use "git add" and/or "git commit -a")
```
@@ -176,6 +176,8 @@ There is a workaround in [the issue][#77620-workaround].
[#77620]: https://github.com/rust-lang/rust/issues/77620
[#77620-workaround]: https://github.com/rust-lang/rust/issues/77620#issuecomment-705228229
+(Note that as of Sept 2022 `miri` is a subtree and not a submodule.)
+
## Rebasing and Conflicts
When you edit your code locally, you are making changes to the version of
@@ -391,41 +393,41 @@ you might want to get used to the main concepts of Git before reading this secti
The `rust-lang/rust` repository uses [Git submodules] as a way to use other
Rust projects from within the `rust` repo. Examples include Rust's fork of
-`llvm-project` and many devtools such as `cargo` and `rls`.
+`llvm-project`, `cargo` and libraries like `stdarch` and `backtrace`.
Those projects are developed and maintained in an separate Git (and GitHub)
repository, and they have their own Git history/commits, issue tracker and PRs.
Submodules allow us to create some sort of embedded sub-repository inside the
`rust` repository and use them like they were directories in the `rust` repository.
-Take `miri` for example. `miri` is maintained in the [`rust-lang/miri`] repository,
-but it is used in `rust-lang/rust` by the compiler for const evaluation. We bring it
-in `rust` as a submodule, in the `src/tools/miri` folder.
+Take `llvm-project` for example. `llvm-project` is maintained in the [`rust-lang/llvm-project`]
+repository, but it is used in `rust-lang/rust` by the compiler for code generation and
+optimization. We bring it in `rust` as a submodule, in the `src/llvm-project` folder.
The contents of submodules are ignored by Git: submodules are in some sense isolated
-from the rest of the repository. However, if you try to `cd src/tools/miri` and then
+from the rest of the repository. However, if you try to `cd src/llvm-project` and then
run `git status`:
```
-HEAD detached at 3fafb835
+HEAD detached at 9567f08afc943
nothing to commit, working tree clean
```
-As far as git is concerned, you are no longer in the `rust` repo, but in the `miri` repo.
+As far as git is concerned, you are no longer in the `rust` repo, but in the `llvm-project` repo.
You will notice that we are in "detached HEAD" state, i.e. not on a branch but on a
particular commit.
This is because, like any dependency, we want to be able to control which version to use.
Submodules allow us to do just that: every submodule is "pinned" to a certain
commit, which doesn't change unless modified manually. If you use `git checkout <commit>`
-in the `miri` directory and go back to the `rust` directory, you can stage this
-change like any other, e.g. by running `git add src/tools/miri`. (Note that if
+in the `llvm-project` directory and go back to the `rust` directory, you can stage this
+change like any other, e.g. by running `git add src/llvm-project`. (Note that if
you *don't* stage the change to commit, then you run the risk that running
`x.py` will just undo your change by switching back to the previous commit when
it automatically "updates" the submodules.)
This version selection is usually done by the maintainers of the project, and
-looks like [this][miri-update].
+looks like [this][llvm-update].
Git submodules take some time to get used to, so don't worry if it isn't perfectly
clear yet. You will rarely have to use them directly and, again, you don't need
@@ -434,6 +436,5 @@ exist and that they correspond to some sort of embedded subrepository dependency
that Git can nicely and fairly conveniently handle for us.
[Git submodules]: https://git-scm.com/book/en/v2/Git-Tools-Submodules
-[`rust-toolstate`]: https://rust-lang-nursery.github.io/rust-toolstate/
-[`rust-lang/miri`]: https://github.com/rust-lang/miri
-[miri-update]: https://github.com/rust-lang/rust/pull/77500/files
+[`rust-lang/llvm-project`]: https://github.com/rust-lang/llvm-project
+[llvm-update]: https://github.com/rust-lang/rust/pull/99464/files
diff --git a/src/doc/rustc-dev-guide/src/img/rustc_stages.svg b/src/doc/rustc-dev-guide/src/img/rustc_stages.svg
deleted file mode 100644
index 25f7ab11b..000000000
--- a/src/doc/rustc-dev-guide/src/img/rustc_stages.svg
+++ /dev/null
@@ -1,3 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" style="background-color: rgb(255, 255, 255);" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="581px" height="816px" viewBox="-0.5 -0.5 581 816"><defs/><g><rect x="0" y="0" width="580" height="315" fill="#ffffff" stroke="#000000" pointer-events="all"/><rect x="0" y="665" width="580" height="150" fill="#ffffff" stroke="#000000" pointer-events="all"/><rect x="0" y="345" width="580" height="287.5" fill="#ffffff" stroke="#000000" pointer-events="all"/><path d="M 120 25 L 193.63 25" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 198.88 25 L 191.88 28.5 L 193.63 25 L 191.88 21.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 25px; margin-left: 160px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Download</div></div></div></foreignObject><text x="160" y="28" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Download</text></switch></g><rect x="40" y="10" width="80" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 25px; margin-left: 41px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">beta</div></div></div></foreignObject><text x="80" y="29" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">beta</text></switch></g><rect x="200" y="10" width="80" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 25px; margin-left: 201px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage0</div></div></div></foreignObject><text x="240" y="29" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage0</text></switch></g><path d="M 120 120 L 173.63 120" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 178.88 120 L 171.88 123.5 L 173.63 120 L 171.88 116.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 120px; margin-left: 144px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Builds</div></div></div></foreignObject><text x="144" y="123" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Builds</text></switch></g><rect x="40" y="105" width="80" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 120px; margin-left: 41px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage0</div></div></div></foreignObject><text x="80" y="124" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage0</text></switch></g><path d="M 260 120 L 313.63 120" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 318.88 120 L 311.88 123.5 L 313.63 120 L 311.88 116.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 120px; margin-left: 290px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Outputs</div></div></div></foreignObject><text x="290" y="123" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Outputs</text></switch></g><rect x="180" y="105" width="80" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 120px; margin-left: 181px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">libtest/libstd</div></div></div></foreignObject><text x="220" y="124" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">libtest/libstd</text></switch></g><path d="M 400 120 L 453.63 120" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 458.88 120 L 451.88 123.5 L 453.63 120 L 451.88 116.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 120px; margin-left: 430px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Copy</div></div></div></foreignObject><text x="430" y="123" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Copy</text></switch></g><rect x="320" y="105" width="80" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 120px; margin-left: 321px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage0-std</div></div></div></foreignObject><text x="360" y="124" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage0-std</text></switch></g><path d="M 515 135 L 515 145 Q 515 155 505 155 L 230 155 Q 220 155 220 161.82 L 220 168.63" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 220 173.88 L 216.5 166.88 L 220 168.63 L 223.5 166.88 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><rect x="460" y="105" width="110" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 108px; height: 1px; padding-top: 120px; margin-left: 461px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage0-sysroot</div></div></div></foreignObject><text x="515" y="124" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage0-sysroot</text></switch></g><path d="M 120 190 L 173.63 190" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 178.88 190 L 171.88 193.5 L 173.63 190 L 171.88 186.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 190px; margin-left: 144px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Builds</div></div></div></foreignObject><text x="144" y="193" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Builds</text></switch></g><rect x="40" y="175" width="80" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 190px; margin-left: 41px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage0</div></div></div></foreignObject><text x="80" y="194" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage0</text></switch></g><path d="M 260 190 L 313.63 190" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 318.88 190 L 311.88 193.5 L 313.63 190 L 311.88 186.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 190px; margin-left: 290px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Outputs</div></div></div></foreignObject><text x="290" y="193" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Outputs</text></switch></g><rect x="180" y="175" width="80" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 190px; margin-left: 181px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">rustc</div></div></div></foreignObject><text x="220" y="194" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">rustc</text></switch></g><path d="M 400 190 L 453.63 190" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 458.88 190 L 451.88 193.5 L 453.63 190 L 451.88 186.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 190px; margin-left: 430px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Copy</div></div></div></foreignObject><text x="430" y="193" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Copy</text></switch></g><rect x="320" y="175" width="80" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 190px; margin-left: 321px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage0-rustc</div></div></div></foreignObject><text x="360" y="194" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage0-rustc</text></switch></g><path d="M 515 205 L 515 227.5 Q 515 237.5 505 237.5 L 230 237.5 Q 220 237.5 220 247.5 L 220 263.63" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 220 268.88 L 216.5 261.88 L 220 263.63 L 223.5 261.88 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><rect x="460" y="175" width="110" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 108px; height: 1px; padding-top: 190px; margin-left: 461px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage0-sysroot</div></div></div></foreignObject><text x="515" y="194" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage0-sysroot</text></switch></g><path d="M 120 237.5 L 210 237.5 Q 220 237.5 220 247.5 L 220 263.63" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 220 268.88 L 216.5 261.88 L 220 263.63 L 223.5 261.88 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><rect x="40" y="222.5" width="80" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 238px; margin-left: 41px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">llvm</div></div></div></foreignObject><text x="80" y="241" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">llvm</text></switch></g><path d="M 120 285 L 173.63 285" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 178.88 285 L 171.88 288.5 L 173.63 285 L 171.88 281.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 285px; margin-left: 144px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Builds</div></div></div></foreignObject><text x="144" y="288" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Builds</text></switch></g><rect x="40" y="270" width="80" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 285px; margin-left: 41px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage0</div></div></div></foreignObject><text x="80" y="289" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage0</text></switch></g><path d="M 260 285 L 313.63 285" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 318.88 285 L 311.88 288.5 L 313.63 285 L 311.88 281.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 285px; margin-left: 290px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Outputs</div></div></div></foreignObject><text x="290" y="288" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Outputs</text></switch></g><rect x="180" y="270" width="80" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 285px; margin-left: 181px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">codegen</div></div></div></foreignObject><text x="220" y="289" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">codegen</text></switch></g><rect x="320" y="270" width="100" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 98px; height: 1px; padding-top: 285px; margin-left: 321px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage0-codegen</div></div></div></foreignObject><text x="370" y="289" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage0-codegen</text></switch></g><rect x="-30" y="145" width="90" height="20" fill="none" stroke="none" transform="rotate(-90,15,155)" pointer-events="all"/><g transform="translate(-0.5 -0.5)rotate(-90 15 155)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 88px; height: 1px; padding-top: 155px; margin-left: -29px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 24px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">Stage 0</div></div></div></foreignObject><text x="15" y="162" fill="#000000" font-family="Helvetica" font-size="24px" text-anchor="middle">Stage 0</text></switch></g><path d="M 150 380 L 203.63 380" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 208.88 380 L 201.88 383.5 L 203.63 380 L 201.88 376.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 380px; margin-left: 174px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Copy</div></div></div></foreignObject><text x="174" y="383" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Copy</text></switch></g><rect x="40" y="355" width="110" height="50" rx="7.5" ry="7.5" fill="#fff2cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 108px; height: 1px; padding-top: 380px; margin-left: 41px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage0-rustc<br />stage0-codegen<br />stage0-sysroot</div></div></div></foreignObject><text x="95" y="384" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage0-rustc...</text></switch></g><path d="M 250 395 L 250 405 Q 250 415 240 415 L 90 415 Q 80 415 80 421.82 L 80 428.63" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 80 433.88 L 76.5 426.88 L 80 428.63 L 83.5 426.88 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><rect x="210" y="365" width="80" height="30" rx="4.5" ry="4.5" fill="#fff2cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 380px; margin-left: 211px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage1</div></div></div></foreignObject><text x="250" y="384" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage1</text></switch></g><path d="M 120 450 L 173.63 450" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 178.88 450 L 171.88 453.5 L 173.63 450 L 171.88 446.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 450px; margin-left: 144px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Builds</div></div></div></foreignObject><text x="144" y="453" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Builds</text></switch></g><rect x="40" y="435" width="80" height="30" rx="4.5" ry="4.5" fill="#fff2cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 450px; margin-left: 41px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage1</div></div></div></foreignObject><text x="80" y="454" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage1</text></switch></g><path d="M 260 450 L 313.63 450" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 318.88 450 L 311.88 453.5 L 313.63 450 L 311.88 446.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 450px; margin-left: 290px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Outputs</div></div></div></foreignObject><text x="290" y="453" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Outputs</text></switch></g><rect x="180" y="435" width="80" height="30" rx="4.5" ry="4.5" fill="#fff2cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 450px; margin-left: 181px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">libtest/libstd</div></div></div></foreignObject><text x="220" y="454" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">libtest/libstd</text></switch></g><path d="M 400 450 L 453.63 450" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 458.88 450 L 451.88 453.5 L 453.63 450 L 451.88 446.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 450px; margin-left: 430px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Copy</div></div></div></foreignObject><text x="430" y="453" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Copy</text></switch></g><rect x="320" y="435" width="80" height="30" rx="4.5" ry="4.5" fill="#fff2cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 450px; margin-left: 321px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage1-std</div></div></div></foreignObject><text x="360" y="454" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage1-std</text></switch></g><path d="M 515 465 L 515 477.5 Q 515 487.5 505 487.5 L 230 487.5 Q 220 487.5 220 495.57 L 220 503.63" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 220 508.88 L 216.5 501.88 L 220 503.63 L 223.5 501.88 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><rect x="460" y="435" width="110" height="30" rx="4.5" ry="4.5" fill="#fff2cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 108px; height: 1px; padding-top: 450px; margin-left: 461px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage1/lib/rustlib</div></div></div></foreignObject><text x="515" y="454" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage1/lib/rustlib</text></switch></g><path d="M 120 525 L 173.63 525" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 178.88 525 L 171.88 528.5 L 173.63 525 L 171.88 521.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 525px; margin-left: 144px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Builds</div></div></div></foreignObject><text x="144" y="528" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Builds</text></switch></g><rect x="40" y="510" width="80" height="30" rx="4.5" ry="4.5" fill="#fff2cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 525px; margin-left: 41px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage1</div></div></div></foreignObject><text x="80" y="529" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage1</text></switch></g><path d="M 260 525 L 313.63 525" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 318.88 525 L 311.88 528.5 L 313.63 525 L 311.88 521.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 525px; margin-left: 290px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Outputs</div></div></div></foreignObject><text x="290" y="528" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Outputs</text></switch></g><rect x="180" y="510" width="80" height="30" rx="4.5" ry="4.5" fill="#fff2cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 525px; margin-left: 181px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">rustc</div></div></div></foreignObject><text x="220" y="529" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">rustc</text></switch></g><path d="M 400 525 L 453.63 525" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 458.88 525 L 451.88 528.5 L 453.63 525 L 451.88 521.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 525px; margin-left: 430px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Copy</div></div></div></foreignObject><text x="430" y="528" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Copy</text></switch></g><rect x="320" y="510" width="80" height="30" rx="4.5" ry="4.5" fill="#fff2cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 525px; margin-left: 321px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage1-rustc</div></div></div></foreignObject><text x="360" y="529" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage1-rustc</text></switch></g><path d="M 515 540 L 515 550 Q 515 560 505 560 L 230 560 Q 220 560 220 566.82 L 220 573.63" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 220 578.88 L 216.5 571.88 L 220 573.63 L 223.5 571.88 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><rect x="460" y="510" width="110" height="30" rx="4.5" ry="4.5" fill="#fff2cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 108px; height: 1px; padding-top: 525px; margin-left: 461px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage1/lib/rustlib</div></div></div></foreignObject><text x="515" y="529" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage1/lib/rustlib</text></switch></g><path d="M 120 595 L 173.63 595" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 178.88 595 L 171.88 598.5 L 173.63 595 L 171.88 591.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 595px; margin-left: 144px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Builds</div></div></div></foreignObject><text x="144" y="598" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Builds</text></switch></g><rect x="40" y="580" width="80" height="30" rx="4.5" ry="4.5" fill="#fff2cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 595px; margin-left: 41px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage1</div></div></div></foreignObject><text x="80" y="599" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage1</text></switch></g><path d="M 260 595 L 313.63 595" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 318.88 595 L 311.88 598.5 L 313.63 595 L 311.88 591.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 595px; margin-left: 290px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Outputs</div></div></div></foreignObject><text x="290" y="598" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Outputs</text></switch></g><rect x="180" y="580" width="80" height="30" rx="4.5" ry="4.5" fill="#fff2cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 595px; margin-left: 181px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">codegen</div></div></div></foreignObject><text x="220" y="599" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">codegen</text></switch></g><rect x="320" y="580" width="100" height="30" rx="4.5" ry="4.5" fill="#fff2cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 98px; height: 1px; padding-top: 595px; margin-left: 321px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage1-codegen</div></div></div></foreignObject><text x="370" y="599" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage1-codegen</text></switch></g><rect x="-30" y="510" width="90" height="20" fill="none" stroke="none" transform="rotate(-90,15,520)" pointer-events="all"/><g transform="translate(-0.5 -0.5)rotate(-90 15 520)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 88px; height: 1px; padding-top: 520px; margin-left: -29px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 24px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; "><div>Stage 1</div></div></div></div></foreignObject><text x="15" y="527" fill="#000000" font-family="Helvetica" font-size="24px" text-anchor="middle">Stage 1</text></switch></g><path d="M 150 702.5 L 203.63 702.5" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 208.88 702.5 L 201.88 706 L 203.63 702.5 L 201.88 699 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 703px; margin-left: 174px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Copy</div></div></div></foreignObject><text x="174" y="706" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Copy</text></switch></g><rect x="40" y="677.5" width="110" height="50" rx="7.5" ry="7.5" fill="#ccff99" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 108px; height: 1px; padding-top: 703px; margin-left: 41px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage1-rustc<br />stage1-codegen<br />stage1/lib/rustlib</div></div></div></foreignObject><text x="95" y="706" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage1-rustc...</text></switch></g><path d="M 250 717.5 L 250 730 Q 250 740 240 740 L 90 740 Q 80 740 80 748.07 L 80 756.13" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 80 761.38 L 76.5 754.38 L 80 756.13 L 83.5 754.38 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><rect x="210" y="687.5" width="80" height="30" rx="4.5" ry="4.5" fill="#ccff99" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 703px; margin-left: 211px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage2</div></div></div></foreignObject><text x="250" y="706" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage2</text></switch></g><path d="M 120 777.5 L 173.63 777.5" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 178.88 777.5 L 171.88 781 L 173.63 777.5 L 171.88 774 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 778px; margin-left: 144px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Builds</div></div></div></foreignObject><text x="144" y="781" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Builds</text></switch></g><rect x="40" y="762.5" width="80" height="30" rx="4.5" ry="4.5" fill="#ccff99" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 778px; margin-left: 41px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage2</div></div></div></foreignObject><text x="80" y="781" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage2</text></switch></g><path d="M 260 777.5 L 313.63 777.5" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 318.88 777.5 L 311.88 781 L 313.63 777.5 L 311.88 774 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 778px; margin-left: 290px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Outputs</div></div></div></foreignObject><text x="290" y="781" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Outputs</text></switch></g><rect x="180" y="762.5" width="80" height="30" rx="4.5" ry="4.5" fill="#ccff99" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 778px; margin-left: 181px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">rustdoc</div></div></div></foreignObject><text x="220" y="781" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">rustdoc</text></switch></g><path d="M 400 777.5 L 443.63 777.5" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 448.88 777.5 L 441.88 781 L 443.63 777.5 L 441.88 774 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 778px; margin-left: 425px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; "><div style="font-size: 11px">Copy</div></div></div></div></foreignObject><text x="425" y="781" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Copy</text></switch></g><rect x="320" y="762.5" width="80" height="30" rx="4.5" ry="4.5" fill="#ccff99" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 778px; margin-left: 321px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage2-tools</div></div></div></foreignObject><text x="360" y="781" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage2-tools</text></switch></g><path d="M 120 70 L 173.63 70" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 178.88 70 L 171.88 73.5 L 173.63 70 L 171.88 66.5 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 70px; margin-left: 144px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 11px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; background-color: #ffffff; white-space: nowrap; ">Builds</div></div></div></foreignObject><text x="144" y="73" fill="#000000" font-family="Helvetica" font-size="11px" text-anchor="middle">Builds</text></switch></g><rect x="40" y="55" width="80" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 70px; margin-left: 41px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage0</div></div></div></foreignObject><text x="80" y="74" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage0</text></switch></g><rect x="180" y="55" width="80" height="30" rx="4.5" ry="4.5" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 70px; margin-left: 181px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">bootstrap</div></div></div></foreignObject><text x="220" y="74" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">bootstrap</text></switch></g><path d="M 190 560 L 130 560 Q 120 560 120 558.75 L 120 558.13 Q 120 557.5 130 557.5 L 210 557.5 Q 220 557.5 220 564.32 L 220 571.13" fill="none" stroke="#000000" stroke-miterlimit="10" pointer-events="stroke"/><path d="M 220 576.38 L 216.5 569.38 L 220 571.13 L 223.5 569.38 Z" fill="#000000" stroke="#000000" stroke-miterlimit="10" pointer-events="all"/><rect x="110" y="551" width="80" height="18" rx="2.7" ry="2.7" fill="#ffe6cc" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 560px; margin-left: 111px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">llvm</div></div></div></foreignObject><text x="150" y="564" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">llvm</text></switch></g><rect x="450" y="762.5" width="80" height="30" rx="4.5" ry="4.5" fill="#ccff99" stroke="#000000" pointer-events="all"/><g transform="translate(-0.5 -0.5)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 78px; height: 1px; padding-top: 778px; margin-left: 451px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 12px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; ">stage2</div></div></div></foreignObject><text x="490" y="781" fill="#000000" font-family="Helvetica" font-size="12px" text-anchor="middle">stage2</text></switch></g><rect x="-30" y="735" width="90" height="20" fill="none" stroke="none" transform="rotate(-90,15,745)" pointer-events="all"/><g transform="translate(-0.5 -0.5)rotate(-90 15 745)"><switch><foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 88px; height: 1px; padding-top: 745px; margin-left: -29px;"><div style="box-sizing: border-box; font-size: 0; text-align: center; "><div style="display: inline-block; font-size: 24px; font-family: Helvetica; color: #000000; line-height: 1.2; pointer-events: all; white-space: normal; word-wrap: normal; "><div>Stage 2</div></div></div></div></foreignObject><text x="15" y="752" fill="#000000" font-family="Helvetica" font-size="24px" text-anchor="middle">Stage 2</text></switch></g></g><switch><g requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"/><a transform="translate(0,-5)" xlink:href="https://desk.draw.io/support/solutions/articles/16000042487" target="_blank"><text text-anchor="middle" font-size="10px" x="50%" y="100%">Viewer does not support full SVG 1.1</text></a></switch></svg> \ No newline at end of file
diff --git a/src/doc/rustc-dev-guide/src/implementing_new_features.md b/src/doc/rustc-dev-guide/src/implementing_new_features.md
index ef6ae6179..9147c1b41 100644
--- a/src/doc/rustc-dev-guide/src/implementing_new_features.md
+++ b/src/doc/rustc-dev-guide/src/implementing_new_features.md
@@ -28,6 +28,12 @@ get by with only an r+. For example, it is OK to add or modify
unstable command-line flags or attributes without an FCP for
compiler development or standard library use, as long as you don't
expect them to be in wide use in the nightly ecosystem.
+Some teams have lighter weight processes that they use in scenarios
+like this; for example, the compiler team recommends
+filing a Major Change Proposal ([MCP][mcp]) as a lightweight way to
+garner support and feedback without requiring full consensus.
+
+[mcp]: compiler/mcp.md#public-facing-changes-require-rfcbot-fcp
You don't need to have the implementation fully ready for r+ to propose an FCP,
but it is generally a good idea to have at least a proof
@@ -123,9 +129,9 @@ a new unstable feature:
2. Pick a name for the feature gate (for RFCs, use the name
in the RFC).
-3. Add a feature gate declaration to `rustc_feature/src/active.rs`
- in the active `declare_features` block. See [here][add-feature-gate] for
- detailed instructions.
+3. Add a feature gate declaration to `rustc_feature/src/active.rs` in the active
+ `declare_features` block, and add the feature gate keyword to
+ `rustc_span/src/symbol.rs`. See [here][add-feature-gate] for detailed instructions.
4. Prevent usage of the new feature unless the feature gate is set.
You can check it in most places in the compiler using the
diff --git a/src/doc/rustc-dev-guide/src/method-lookup.md b/src/doc/rustc-dev-guide/src/method-lookup.md
index 8eb8ec5ce..8b49e8d00 100644
--- a/src/doc/rustc-dev-guide/src/method-lookup.md
+++ b/src/doc/rustc-dev-guide/src/method-lookup.md
@@ -32,8 +32,8 @@ inference variables or other information.
[fully-qualified syntax]: https://doc.rust-lang.org/nightly/book/ch19-03-advanced-traits.html#fully-qualified-syntax-for-disambiguation-calling-methods-with-the-same-name
[UFCS]: https://github.com/rust-lang/rfcs/blob/master/text/0132-ufcs.md
-[probe]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/check/method/probe/
-[confirm]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/check/method/confirm/
+[probe]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/method/probe/
+[confirm]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/method/confirm/
## The Probe phase
diff --git a/src/doc/rustc-dev-guide/src/name-resolution.md b/src/doc/rustc-dev-guide/src/name-resolution.md
index c4f44909b..1dbc95ead 100644
--- a/src/doc/rustc-dev-guide/src/name-resolution.md
+++ b/src/doc/rustc-dev-guide/src/name-resolution.md
@@ -174,7 +174,7 @@ Still, it probably provides useful first guidepost to what happens in there.
following stages of compilation?
* Who calls it and how it is actually used.
* Is it a pass and then the result is only used, or can it be computed
- incrementally (e.g. for RLS)?
+ incrementally?
* The overall strategy description is a bit vague.
* Where does the name `Rib` come from?
* Does this thing have its own tests, or is it tested only as part of some e2e
diff --git a/src/doc/rustc-dev-guide/src/opaque-types-impl-trait-inference.md b/src/doc/rustc-dev-guide/src/opaque-types-impl-trait-inference.md
index 52d2127bf..f9c2ea74d 100644
--- a/src/doc/rustc-dev-guide/src/opaque-types-impl-trait-inference.md
+++ b/src/doc/rustc-dev-guide/src/opaque-types-impl-trait-inference.md
@@ -147,7 +147,7 @@ flowchart TD
### Relating an opaque type to another type
-There is one central place where an opaqe type gets its hidden type constrained,
+There is one central place where an opaque type gets its hidden type constrained,
and that is the `handle_opaque_type` function.
Amusingly it takes two types, so you can pass any two types,
but one of them should be an opaque type.
@@ -216,7 +216,7 @@ and then handle it correctly.
The MIR borrow checker relates things via `nll_relate` and only cares about regions.
Any type relation will trigger the binding of hidden types,
so the borrow checker is doing the same thing as the type checker,
-but ignores obivously dead code (e.g. after a panic).
+but ignores obviously dead code (e.g. after a panic).
The borrow checker is also the source of truth when it comes to hidden types,
as it is the only one who can properly figure out what lifetimes on the hidden type correspond
to which lifetimes on the opaque type declaration.
@@ -224,7 +224,7 @@ to which lifetimes on the opaque type declaration.
## Backwards compatibility hacks
`impl Trait` in return position has various quirks that were not part
-of any RFCs and are likely accidental stabilizations.
+of any RFCs and are likely accidental stabilization.
To support these,
the `replace_opaque_types_with_inference_vars` is being used to reintroduce the previous behaviour.
diff --git a/src/doc/rustc-dev-guide/src/overview.md b/src/doc/rustc-dev-guide/src/overview.md
index c7da92542..7fbdfd359 100644
--- a/src/doc/rustc-dev-guide/src/overview.md
+++ b/src/doc/rustc-dev-guide/src/overview.md
@@ -177,7 +177,7 @@ satisfy/optimize for. For example,
of space on the user's system...
- Compiler memory usage: while compiling a program, we don't want to use more
memory than we need.
-- Program speed: how fast is your compiled program. More/better compile-time
+- Program speed: how fast is your compiled program? More/better compile-time
analyses often means the compiler can do better optimizations.
- Program size: how large is the compiled binary? Similar to the previous
point.
@@ -190,7 +190,7 @@ satisfy/optimize for. For example,
the input programs says they do, and should continue to do so despite the
tremendous amount of change constantly going on.
- Integration: a number of other tools need to use the compiler in
- various ways (e.g. cargo, clippy, miri, RLS) that must be supported.
+ various ways (e.g. cargo, clippy, miri) that must be supported.
- Compiler stability: the compiler should not crash or fail ungracefully on the
stable channel.
- Rust stability: the compiler must respect Rust's stability guarantees by not
diff --git a/src/doc/rustc-dev-guide/src/panic-implementation.md b/src/doc/rustc-dev-guide/src/panic-implementation.md
index 66e61548e..d1ca202dc 100644
--- a/src/doc/rustc-dev-guide/src/panic-implementation.md
+++ b/src/doc/rustc-dev-guide/src/panic-implementation.md
@@ -28,7 +28,7 @@ Actually resolving this goes through several layers of indirection:
1. In `compiler/rustc_middle/src/middle/weak_lang_items.rs`, `panic_impl` is
declared as 'weak lang item', with the symbol `rust_begin_unwind`. This is
- used in `rustc_typeck/src/collect.rs` to set the actual symbol name to
+ used in `rustc_hir_analysis/src/collect.rs` to set the actual symbol name to
`rust_begin_unwind`.
Note that `panic_impl` is declared in an `extern "Rust"` block,
diff --git a/src/doc/rustc-dev-guide/src/rustc-driver.md b/src/doc/rustc-dev-guide/src/rustc-driver.md
index 7250c852c..cef50111d 100644
--- a/src/doc/rustc-dev-guide/src/rustc-driver.md
+++ b/src/doc/rustc-dev-guide/src/rustc-driver.md
@@ -7,7 +7,7 @@ using the interface defined in the [`rustc_interface`] crate.
The `rustc_interface` crate provides external users with an (unstable) API
for running code at particular times during the compilation process, allowing
third parties to effectively use `rustc`'s internals as a library for
-analyzing a crate or emulating the compiler in-process (e.g. the RLS or rustdoc).
+analyzing a crate or emulating the compiler in-process (e.g. rustdoc).
For those using `rustc` as a library, the [`rustc_interface::run_compiler()`][i_rc]
function is the main entrypoint to the compiler. It takes a configuration for the compiler
diff --git a/src/doc/rustc-dev-guide/src/rustdoc.md b/src/doc/rustc-dev-guide/src/rustdoc.md
index 4cdda5a3e..23428efd6 100644
--- a/src/doc/rustc-dev-guide/src/rustdoc.md
+++ b/src/doc/rustc-dev-guide/src/rustdoc.md
@@ -148,7 +148,7 @@ authors can request rebuilds, which will be run with the latest rustdoc.
Docs.rs performs some transformations on rustdoc's output in order to save
storage and display a navigation bar at the top. In particular, certain static
-files (like main.js and rustdoc.css may be shared across multiple invocations
+files, like main.js and rustdoc.css, may be shared across multiple invocations
of the same version of rustdoc. Others, like crates.js and sidebar-items.js, are
different for different invocations. Still others, like fonts, will never
change. These categories are distinguished using the `SharedResource` enum in
diff --git a/src/doc/rustc-dev-guide/src/stability.md b/src/doc/rustc-dev-guide/src/stability.md
index 3469ce2ba..b7308ee73 100644
--- a/src/doc/rustc-dev-guide/src/stability.md
+++ b/src/doc/rustc-dev-guide/src/stability.md
@@ -74,13 +74,11 @@ To stabilize a feature, follow these steps:
0. Ask a **@T-libs-api** member to start an FCP on the tracking issue and wait for
the FCP to complete (with `disposition-merge`).
-1. Change `#[unstable(...)]` to `#[stable(since = "version")]`.
- `version` should be the *current nightly*, i.e. stable+2. You can see which version is
- the current nightly [on Forge](https://forge.rust-lang.org/#current-release-versions).
+1. Change `#[unstable(...)]` to `#[stable(since = "CURRENT_RUSTC_VERSION")]`.
2. Remove `#![feature(...)]` from any test or doc-test for this API. If the feature is used in the
compiler or tools, remove it from there as well.
3. If applicable, change `#[rustc_const_unstable(...)]` to
- `#[rustc_const_stable(since = "version")]`.
+ `#[rustc_const_stable(since = "CURRENT_RUSTC_VERSION")]`.
4. Open a PR against `rust-lang/rust`.
- Add the appropriate labels: `@rustbot modify labels: +T-libs-api`.
- Link to the tracking issue and say "Closes #XXXXX".
diff --git a/src/doc/rustc-dev-guide/src/tests/ci.md b/src/doc/rustc-dev-guide/src/tests/ci.md
index 21f834130..cca4973cb 100644
--- a/src/doc/rustc-dev-guide/src/tests/ci.md
+++ b/src/doc/rustc-dev-guide/src/tests/ci.md
@@ -2,9 +2,10 @@
## Testing infrastructure
+<!-- date-check: oct 2022 -->
When a Pull Request is opened on GitHub, [GitHub Actions] will automatically
launch a build that will run all tests on some configurations
-(x86_64-gnu-llvm-12 linux. x86_64-gnu-tools linux, mingw-check linux).
+(x86_64-gnu-llvm-13 linux, x86_64-gnu-tools linux, and mingw-check linux).
In essence, each runs `./x.py test` with various different options.
The integration bot [bors] is used for coordinating merges to the master branch.
diff --git a/src/doc/rustc-dev-guide/src/tests/intro.md b/src/doc/rustc-dev-guide/src/tests/intro.md
index 8b65e4df5..66e0a9eef 100644
--- a/src/doc/rustc-dev-guide/src/tests/intro.md
+++ b/src/doc/rustc-dev-guide/src/tests/intro.md
@@ -115,7 +115,7 @@ will unpack, build, and run all tests.
### Tool tests
Packages that are included with Rust have all of their tests run as well.
-This includes things such as cargo, clippy, rustfmt, rls, miri, bootstrap
+This includes things such as cargo, clippy, rustfmt, miri, bootstrap
(testing the Rust build system itself), etc.
Most of the tools are located in the [`src/tools`] directory.
diff --git a/src/doc/rustc-dev-guide/src/tests/running.md b/src/doc/rustc-dev-guide/src/tests/running.md
index be9d965e4..5d1441936 100644
--- a/src/doc/rustc-dev-guide/src/tests/running.md
+++ b/src/doc/rustc-dev-guide/src/tests/running.md
@@ -245,14 +245,20 @@ The binary will be created at
`./build/$HOST_ARCH/stage2-tools/$TARGET_ARCH/release/remote-test-server`. Copy
this over to the remote machine.
-On the remote machine, run the `remote-test-server` with the `remote` argument
-(and optionally `-v` for verbose output). Output should look like this:
+On the remote machine, run the `remote-test-server` with the `--bind
+0.0.0.0:12345` flag (and optionally `-v` for verbose output). Output should
+look like this:
```sh
-$ ./remote-test-server -v remote
+$ ./remote-test-server -v --bind 0.0.0.0:12345
starting test server
listening on 0.0.0.0:12345!
```
+Note that binding the server to 0.0.0.0 will allow all hosts able to reach your
+machine to execute arbitrary code on your machine. We strongly recommend either
+setting up a firewall to block external access to port 12345, or to use a more
+restrictive IP address when binding.
+
You can test if the `remote-test-server` is working by connecting to it and
sending `ping\n`. It should reply `pong`:
```sh
diff --git a/src/doc/rustc-dev-guide/src/traits/resolution.md b/src/doc/rustc-dev-guide/src/traits/resolution.md
index 195fe6050..88767ad94 100644
--- a/src/doc/rustc-dev-guide/src/traits/resolution.md
+++ b/src/doc/rustc-dev-guide/src/traits/resolution.md
@@ -72,10 +72,10 @@ Trait resolution consists of three major parts:
are completely fulfilled. Basically it is a worklist of obligations
to be selected: once selection is successful, the obligation is
removed from the worklist and any nested obligations are enqueued.
+ Fulfillment constrains inference variables.
-- **Coherence**: The coherence checks are intended to ensure that there
- are never overlapping impls, where two impls could be used with
- equal precedence.
+- **Evaluation**: Checks whether obligations holds without constraining
+ any inference variables. Used by selection.
## Selection
@@ -111,6 +111,8 @@ may lead to other errors downstream).
### Candidate assembly
+**TODO**: Talk about _why_ we have different candidates, and why it needs to happen in a probe.
+
Searches for impls/where-clauses/etc that might
possibly be used to satisfy the obligation. Each of those is called
a candidate. To avoid ambiguity, we want to find exactly one
@@ -120,68 +122,23 @@ the obligation contains unbound inference variables.
The subroutines that decide whether a particular impl/where-clause/etc applies
to a particular obligation are collectively referred to as the process of
-_matching_. As of <!-- date-check --> May 2022, this amounts to unifying
-the `Self` types, but in the future we may also recursively consider some of the
-nested obligations, in the case of an impl.
-
-**TODO**: what does "unifying the `Self` types" mean? The `Self` of the
-obligation with that of an impl?
-
-The basic idea for candidate assembly is to do a first pass in which
-we identify all possible candidates. During this pass, all that we do
-is try and unify the type parameters. (In particular, we ignore any
-nested where clauses.) Presuming that this unification succeeds, the
-impl is added as a candidate.
+_matching_. For `impl` candidates <!-- date-check: Oct 2022 -->,
+this amounts to unifying the impl header (the `Self` type and the trait arguments)
+while ignoring nested obligations. If matching succeeds then we add it
+to a set of candidates. There are other rules when assembling candidates for
+built-in traits such as `Copy`, `Sized`, and `CoerceUnsized`.
Once this first pass is done, we can examine the set of candidates. If
it is a singleton set, then we are done: this is the only impl in
-scope that could possibly apply. Otherwise, we can winnow down the set
-of candidates by using where clauses and other conditions. If this
-reduced set yields a single, unambiguous entry, we're good to go,
-otherwise the result is considered ambiguous.
-
-#### The basic process: Inferring based on the impls we see
-
-This process is easier if we work through some examples. Consider
-the following trait:
-
-```rust,ignore
-trait Convert<Target> {
- fn convert(&self) -> Target;
-}
-```
+scope that could possibly apply. Otherwise, we can **winnow** down the set
+of candidates by using where clauses and other conditions. Winnowing uses
+`evaluate_candidate` to check whether the nested obligations may apply.
+If this still leaves more than 1 candidate, we use ` fn candidate_should_be_dropped_in_favor_of`
+to prefer some candidates over others.
-This trait just has one method. It's about as simple as it gets. It
-converts from the (implicit) `Self` type to the `Target` type. If we
-wanted to permit conversion between `isize` and `usize`, we might
-implement `Convert` like so:
-```rust,ignore
-impl Convert<usize> for isize { ... } // isize -> usize
-impl Convert<isize> for usize { ... } // usize -> isize
-```
-
-Now imagine there is some code like the following:
-
-```rust,ignore
-let x: isize = ...;
-let y = x.convert();
-```
-
-The call to convert will generate a trait reference `Convert<$Y> for
-isize`, where `$Y` is the type variable representing the type of
-`y`. Of the two impls we can see, the only one that matches is
-`Convert<usize> for isize`. Therefore, we can
-select this impl, which will cause the type of `$Y` to be unified to
-`usize`. (Note that while assembling candidates, we do the initial
-unifications in a transaction, so that they don't affect one another.)
-
-**TODO**: The example says we can "select" the impl, but this section is
-talking specifically about candidate assembly. Does this mean we can sometimes
-skip confirmation? Or is this poor wording?
-**TODO**: Is the unification of `$Y` part of trait resolution or type
-inference? Or is this not the same type of "inference variable" as in type
-inference?
+If this reduced set yields a single, unambiguous entry, we're good to go,
+otherwise the result is considered ambiguous.
#### Winnowing: Resolving ambiguities
@@ -281,38 +238,18 @@ result of selection would be an error.
Note that the candidate impl is chosen based on the `Self` type, but
confirmation is done based on (in this case) the `Target` type parameter.
-### Selection during translation
+### Selection during codegen
As mentioned above, during type checking, we do not store the results of trait
-selection. At trans time, we repeat the trait selection to choose a particular
-impl for each method call. In this second selection, we do not consider any
-where-clauses to be in scope because we know that each resolution will resolve
-to a particular impl.
-
-One interesting twist has to do with nested obligations. In general, in trans,
-we only need to do a "shallow" selection for an obligation. That is, we wish to
-identify which impl applies, but we do not (yet) need to decide how to select
-any nested obligations. Nonetheless, we *do* currently do a complete resolution,
-and that is because it can sometimes inform the results of type inference.
+selection. At codegen time, we repeat the trait selection to choose a particular
+impl for each method call. This is done using `fn codegen_select_candidate`.
+In this second selection, we do not consider any where-clauses to be in scope
+because we know that each resolution will resolve to a particular impl.
+
+One interesting twist has to do with nested obligations. In general, in codegen,
+we only to figure out which candidate applies, we do not care about nested obligations,
+as these are already assumed to be true. Nonetheless, we *do* currently do fulfill all of them.
+That is because it can sometimes inform the results of type inference.
That is, we do not have the full substitutions in terms of the type variables
of the impl available to us, so we must run trait selection to figure
everything out.
-
-**TODO**: is this still talking about trans?
-
-Here is an example:
-
-```rust,ignore
-trait Foo { ... }
-impl<U, T:Bar<U>> Foo for Vec<T> { ... }
-
-impl Bar<usize> for isize { ... }
-```
-
-After one shallow round of selection for an obligation like `Vec<isize>
-: Foo`, we would know which impl we want, and we would know that
-`T=isize`, but we do not know the type of `U`. We must select the
-nested obligation `isize : Bar<U>` to find out that `U=usize`.
-
-It would be good to only do *just as much* nested resolution as
-necessary. Currently, though, we just do a full resolution.
diff --git a/src/doc/rustc-dev-guide/src/ty.md b/src/doc/rustc-dev-guide/src/ty.md
index 1cc03fce0..9b35f0d4c 100644
--- a/src/doc/rustc-dev-guide/src/ty.md
+++ b/src/doc/rustc-dev-guide/src/ty.md
@@ -78,7 +78,7 @@ expected type. The [`astconv` module][astconv] is where the code responsible for
but also in other parts of the compiler that want to ask questions like "what argument types does
this function expect?"
-[astconv]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/astconv/index.html
+[astconv]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/astconv/index.html
**How semantics drive the two instances of `Ty`**
diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md
index d9d430c20..06883ddd5 100644
--- a/src/doc/rustc/src/SUMMARY.md
+++ b/src/doc/rustc/src/SUMMARY.md
@@ -20,9 +20,11 @@
- [aarch64-nintendo-switch-freestanding](platform-support/aarch64-nintendo-switch-freestanding.md)
- [armeb-unknown-linux-gnueabi](platform-support/armeb-unknown-linux-gnueabi.md)
- [armv4t-none-eabi](platform-support/armv4t-none-eabi.md)
+ - [armv5te-none-eabi](platform-support/armv5te-none-eabi.md)
- [armv6k-nintendo-3ds](platform-support/armv6k-nintendo-3ds.md)
- [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md)
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)
+ - [\*-android and \*-androideabi](platform-support/android.md)
- [\*-fuchsia](platform-support/fuchsia.md)
- [\*-kmc-solid_\*](platform-support/kmc-solid.md)
- [m68k-unknown-linux-gnu](platform-support/m68k-unknown-linux-gnu.md)
@@ -33,6 +35,7 @@
- [*-unknown-openbsd](platform-support/openbsd.md)
- [\*-unknown-uefi](platform-support/unknown-uefi.md)
- [wasm64-unknown-unknown](platform-support/wasm64-unknown-unknown.md)
+ - [x86_64-fortanix-unknown-sgx](platform-support/x86_64-fortanix-unknown-sgx.md)
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
- [Targets](targets/index.md)
- [Built-in Targets](targets/built-in.md)
diff --git a/src/doc/rustc/src/command-line-arguments.md b/src/doc/rustc/src/command-line-arguments.md
index f05ff3f1b..2dc182b3d 100644
--- a/src/doc/rustc/src/command-line-arguments.md
+++ b/src/doc/rustc/src/command-line-arguments.md
@@ -270,6 +270,11 @@ This flag will set which lints should be set to the [warn level](lints/levels.md
_Note:_ The order of these lint level arguments is taken into account, see [lint level via compiler flag](lints/levels.md#via-compiler-flag) for more information.
+<a id="option-force-warn"></a>
+## `--force-warn`: force a lint to warn
+
+This flag sets the given lint to the [forced warn level](lints/levels.md#force-warn) and the level cannot be overridden, even ignoring the [lint caps](lints/levels.md#capping-lints).
+
<a id="option-a-allow"></a>
## `-A`: set lint allowed
@@ -295,9 +300,9 @@ _Note:_ The order of these lint level arguments is taken into account, see [lint
## `-Z`: set unstable options
This flag will allow you to set unstable options of rustc. In order to set multiple options,
-the -Z flag can be used multiple times. For example: `rustc -Z verbose -Z time`.
+the -Z flag can be used multiple times. For example: `rustc -Z verbose -Z time-passes`.
Specifying options with -Z is only available on nightly. To view all available options
-run: `rustc -Z help`.
+run: `rustc -Z help`, or see [The Unstable Book](../unstable-book/index.html).
<a id="option-cap-lints"></a>
## `--cap-lints`: set the most restrictive lint level
@@ -381,6 +386,12 @@ are:
- `always` — Always use colors.
- `never` — Never colorize output.
+<a id="option-diagnostic-width"></a>
+## `--diagnostic-width`: specify the terminal width for diagnostics
+
+This flag takes a number that specifies the width of the terminal in characters.
+Formatting of diagnostics will take the width into consideration to make them better fit on the screen.
+
<a id="option-remap-path-prefix"></a>
## `--remap-path-prefix`: remap source names in output
diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md
index 3a6963ebc..a36518cc8 100644
--- a/src/doc/rustc/src/platform-support.md
+++ b/src/doc/rustc/src/platform-support.md
@@ -125,17 +125,17 @@ target | std | notes
`aarch64-apple-ios` | ✓ | ARM64 iOS
[`aarch64-apple-ios-sim`](platform-support/aarch64-apple-ios-sim.md) | ✓ | Apple iOS Simulator on ARM64
`aarch64-fuchsia` | ✓ | ARM64 Fuchsia
-`aarch64-linux-android` | ✓ | ARM64 Android
+[`aarch64-linux-android`](platform-support/android.md) | ✓ | ARM64 Android
`aarch64-unknown-none-softfloat` | * | Bare ARM64, softfloat
`aarch64-unknown-none` | * | Bare ARM64, hardfloat
-`arm-linux-androideabi` | ✓ | ARMv7 Android
+[`arm-linux-androideabi`](platform-support/android.md) | ✓ | ARMv7 Android
`arm-unknown-linux-musleabi` | ✓ | ARMv6 Linux with MUSL
`arm-unknown-linux-musleabihf` | ✓ | ARMv6 Linux with MUSL, hardfloat
`armebv7r-none-eabi` | * | Bare ARMv7-R, Big Endian
`armebv7r-none-eabihf` | * | Bare ARMv7-R, Big Endian, hardfloat
`armv5te-unknown-linux-gnueabi` | ✓ | ARMv5TE Linux (kernel 4.4, glibc 2.23)
`armv5te-unknown-linux-musleabi` | ✓ | ARMv5TE Linux with MUSL
-`armv7-linux-androideabi` | ✓ | ARMv7a Android
+[`armv7-linux-androideabi`](platform-support/android.md) | ✓ | ARMv7a Android
`armv7-unknown-linux-gnueabi` | ✓ |ARMv7 Linux (kernel 4.15, glibc 2.27)
`armv7-unknown-linux-musleabi` | ✓ |ARMv7 Linux with MUSL
`armv7-unknown-linux-musleabihf` | ✓ | ARMv7 Linux with MUSL, hardfloat
@@ -144,9 +144,9 @@ target | std | notes
`armv7r-none-eabihf` | * | Bare ARMv7-R, hardfloat
`asmjs-unknown-emscripten` | ✓ | asm.js via Emscripten
`i586-pc-windows-msvc` | * | 32-bit Windows w/o SSE
-`i586-unknown-linux-gnu` | ✓ | 32-bit Linux w/o SSE (kernel 4.4, glibc 2.23)
+`i586-unknown-linux-gnu` | ✓ | 32-bit Linux w/o SSE (kernel 3.2, glibc 2.17)
`i586-unknown-linux-musl` | ✓ | 32-bit Linux w/o SSE, MUSL
-`i686-linux-android` | ✓ | 32-bit x86 Android
+[`i686-linux-android`](platform-support/android.md) | ✓ | 32-bit x86 Android
`i686-unknown-freebsd` | ✓ | 32-bit FreeBSD
`i686-unknown-linux-musl` | ✓ | 32-bit Linux with MUSL
`mips-unknown-linux-musl` | ✓ | MIPS Linux with MUSL
@@ -165,7 +165,7 @@ target | std | notes
`thumbv7em-none-eabi` | * | Bare Cortex-M4, M7
`thumbv7em-none-eabihf` | * | Bare Cortex-M4F, M7F, FPU, hardfloat
`thumbv7m-none-eabi` | * | Bare Cortex-M3
-`thumbv7neon-linux-androideabi` | ✓ | Thumb2-mode ARMv7a Android with NEON
+[`thumbv7neon-linux-androideabi`](platform-support/android.md) | ✓ | Thumb2-mode ARMv7a Android with NEON
`thumbv7neon-unknown-linux-gnueabihf` | ✓ | Thumb2-mode ARMv7a Linux with NEON (kernel 4.4, glibc 2.23)
`thumbv8m.base-none-eabi` | * | ARMv8-M Baseline
`thumbv8m.main-none-eabi` | * | ARMv8-M Mainline
@@ -174,9 +174,9 @@ target | std | notes
`wasm32-unknown-unknown` | ✓ | WebAssembly
`wasm32-wasi` | ✓ | WebAssembly with WASI
`x86_64-apple-ios` | ✓ | 64-bit x86 iOS
-`x86_64-fortanix-unknown-sgx` | ✓ | [Fortanix ABI] for 64-bit Intel SGX
+[`x86_64-fortanix-unknown-sgx`](platform-support/x86_64-fortanix-unknown-sgx.md) | ✓ | [Fortanix ABI] for 64-bit Intel SGX
`x86_64-fuchsia` | ✓ | 64-bit Fuchsia
-`x86_64-linux-android` | ✓ | 64-bit x86 Android
+[`x86_64-linux-android`](platform-support/android.md) | ✓ | 64-bit x86 Android
`x86_64-pc-solaris` | ✓ | 64-bit Solaris 10/11, illumos
`x86_64-unknown-linux-gnux32` | ✓ | 64-bit Linux (x32 ABI) (kernel 4.15, glibc 2.27)
[`x86_64-unknown-none`](platform-support/x86_64-unknown-none.md) | * | Freestanding/bare-metal x86_64, softfloat
@@ -226,6 +226,7 @@ target | std | host | notes
[`armeb-unknown-linux-gnueabi`](platform-support/armeb-unknown-linux-gnueabi.md) | ✓ | ? | ARM BE8 the default ARM big-endian architecture since [ARMv6](https://developer.arm.com/documentation/101754/0616/armlink-Reference/armlink-Command-line-Options/--be8?lang=en).
`armv4t-none-eabi` | * | | ARMv4T A32
`armv4t-unknown-linux-gnueabi` | ? | |
+[`armv5te-none-eabi`](platform-support/armv5te-none-eabi.md) | * | | ARMv5TE A32
`armv5te-unknown-linux-uclibceabi` | ? | | ARMv5TE Linux with uClibc
`armv6-unknown-freebsd` | ✓ | ✓ | ARMv6 FreeBSD
`armv6-unknown-netbsd-eabihf` | ? | |
@@ -292,6 +293,7 @@ target | std | host | notes
`sparc64-unknown-netbsd` | ✓ | ✓ | NetBSD/sparc64
[`sparc64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | OpenBSD/sparc64
`thumbv4t-none-eabi` | * | | ARMv4T T32
+[`thumbv5te-none-eabi`](platform-support/armv5te-none-eabi.md) | * | | ARMv5TE T32
`thumbv7a-pc-windows-msvc` | ? | |
`thumbv7a-uwp-windows-msvc` | ✓ | |
`thumbv7neon-unknown-linux-musleabihf` | ? | | Thumb2-mode ARMv7a Linux with NEON, MUSL
diff --git a/src/doc/rustc/src/platform-support/android.md b/src/doc/rustc/src/platform-support/android.md
new file mode 100644
index 000000000..b2c8e5d4d
--- /dev/null
+++ b/src/doc/rustc/src/platform-support/android.md
@@ -0,0 +1,45 @@
+# *-linux-android and *-linux-androideabi
+
+**Tier: 2**
+
+[Android] is a mobile operating system built on top of the Linux kernel.
+
+[Android]: https://source.android.com/
+
+## Target maintainers
+
+- Chris Wailes ([@chriswailes](https://github.com/chriswailes))
+- Matthew Maurer ([@maurer](https://github.com/maurer))
+- Martin Geisler ([@mgeisler](https://github.com/mgeisler))
+
+## Requirements
+
+This target is cross-compiled from a host environment. Development may be done
+from the [source tree] or using the Android NDK.
+
+[source tree]: https://source.android.com/docs/setup/build/downloading
+
+Android targets support std. Generated binaries use the ELF file format.
+
+## NDK/API Update Policy
+
+Rust will support the most recent Long Term Support (LTS) Android Native
+Development Kit (NDK). By default Rust will support all API levels supported
+by the NDK, but a higher minimum API level may be required if deemed necessary.
+
+## Building the target
+
+To build Rust binaries for Android you'll need a copy of the most recent LTS
+edition of the [Android NDK]. Supported Android targets are:
+
+* aarch64-linux-android
+* arm-linux-androideabi
+* armv7-linux-androideabi
+* i686-linux-android
+* thumbv7neon-linux-androideabi
+* x86_64-linux-android
+
+[Android NDK]: https://developer.android.com/ndk/downloads
+
+A list of all supported targets can be found
+[here](https://doc.rust-lang.org/rustc/platform-support.html)
diff --git a/src/doc/rustc/src/platform-support/armeb-unknown-linux-gnueabi.md b/src/doc/rustc/src/platform-support/armeb-unknown-linux-gnueabi.md
index 507631cdc..432e0cfc9 100644
--- a/src/doc/rustc/src/platform-support/armeb-unknown-linux-gnueabi.md
+++ b/src/doc/rustc/src/platform-support/armeb-unknown-linux-gnueabi.md
@@ -1,7 +1,7 @@
# armeb-unknown-linux-gnueabi
**Tier: 3**
-Target for cross-compiling Linux user-mode applications targetting the ARM BE8 architecture.
+Target for cross-compiling Linux user-mode applications targeting the ARM BE8 architecture.
## Overview
BE8 architecture retains the same little-endian ordered code-stream used by conventional little endian ARM systems, however the data accesses are in big-endian. BE8 is used primarily in high-performance networking applications where the ability to read packets in their native "Network Byte Order" is important (many network protocols transmit data in big-endian byte order for their wire formats).
diff --git a/src/doc/rustc/src/platform-support/armv5te-none-eabi.md b/src/doc/rustc/src/platform-support/armv5te-none-eabi.md
new file mode 100644
index 000000000..f469dab1c
--- /dev/null
+++ b/src/doc/rustc/src/platform-support/armv5te-none-eabi.md
@@ -0,0 +1,66 @@
+# `armv5te-none-eabi`
+
+**Tier: 3**
+
+Bare-metal target for any cpu in the ARMv5TE architecture family, supporting
+ARM/Thumb code interworking (aka `a32`/`t32`), with `a32` code as the default code
+generation.
+
+The `thumbv5te-none-eabi` target is the same as this one, but the instruction set defaults to `t32`.
+
+## Target Maintainers
+
+* [@QuinnPainter](https://github.com/QuinnPainter)
+
+## Requirements
+
+The target is cross-compiled, and uses static linking.
+
+By default, the `lld` linker included with Rust will be used.
+
+However, you may want to use the `arm-none-eabi-ld` linker instead. This can be obtained for Windows/Mac/Linux from the [ARM
+Developer Website][arm-dev], or possibly from your OS's package manager. To use it, add the following to your `.cargo/config.toml`:
+
+```toml
+[target.armv5te-none-eabi]
+linker = "arm-none-eabi-ld"
+```
+
+[arm-dev]: https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain
+
+This target doesn't provide a linker script, you'll need to bring your own
+according to the specific device you want to target. Pass
+`-Clink-arg=-Tyour_script.ld` as a rustc argument to make the linker use
+`your_script.ld` during linking.
+
+## Building Rust Programs
+
+Because it is Tier 3, rust does not yet ship pre-compiled artifacts for this target.
+
+Just use the `build-std` nightly cargo feature to build the `core` library. You
+can pass this as a command line argument to cargo, or your `.cargo/config.toml`
+file might include the following lines:
+
+```toml
+[unstable]
+build-std = ["core"]
+```
+
+Most of `core` should work as expected, with the following notes:
+* the target is "soft float", so `f32` and `f64` operations are emulated in
+ software.
+* integer division is also emulated in software.
+* the target is old enough that it doesn't have atomic instructions.
+
+`alloc` is also supported, as long as you provide your own global allocator.
+
+Rust programs are output as ELF files.
+
+## Testing
+
+This is a cross-compiled target that you will need to emulate during testing.
+
+Because this is a device-agnostic target, and the exact emulator that you'll
+need depends on the specific device you want to run your code on.
+
+For example, when programming for the DS, you can use one of the several available DS emulators, such as [melonDS](https://melonds.kuribo64.net/).
diff --git a/src/doc/rustc/src/platform-support/x86_64-fortanix-unknown-sgx.md b/src/doc/rustc/src/platform-support/x86_64-fortanix-unknown-sgx.md
new file mode 100644
index 000000000..97b5827c1
--- /dev/null
+++ b/src/doc/rustc/src/platform-support/x86_64-fortanix-unknown-sgx.md
@@ -0,0 +1,72 @@
+# `x86_64-fortanix-unknown-sgx`
+
+**Tier: 2**
+
+Secure enclaves using [Intel Software Guard Extensions
+(SGX)](https://www.intel.com/content/www/us/en/developer/tools/software-guard-extensions/overview.html)
+based on the ABI defined by Fortanix for the [Enclave Development Platform
+(EDP)](https://edp.fortanix.com/).
+
+## Target maintainers
+
+The [EDP team](mailto:edp.maintainers@fortanix.com) at Fortanix.
+
+- Jethro Beekman [@jethrogb](https://github.com/jethrogb)
+- Raoul Strackx [@raoulstrackx](https://github.com/raoulstrackx)
+- Mohsen Zohrevandi [@mzohreva](https://github.com/mzohreva)
+
+## Requirements
+
+The target supports `std` with a default allocator. Only cross compilation is
+supported.
+
+Binaries support all CPUs that include Intel SGX. Only 64-bit mode is supported.
+
+Not all `std` features are supported, see [Using Rust's
+std](https://edp.fortanix.com/docs/concepts/rust-std/) for details.
+
+The `extern "C"` calling convention is the System V AMD64 ABI.
+
+The supported ABI is the
+[fortanix-sgx-abi](https://edp.fortanix.com/docs/api/fortanix_sgx_abi/index.html).
+
+The compiler output is ELF, but the native format for the platform is the SGX
+stream (SGXS) format. A converter like
+[ftxsgx-elf2sgxs](https://crates.io/crates/fortanix-sgx-tools) is needed.
+
+Programs in SGXS format adhering to the Fortanix SGX ABI can be run with any
+compatible runner, such as
+[ftxsgx-runner](https://crates.io/crates/fortanix-sgx-tools).
+
+See the [EDP installation
+guide](https://edp.fortanix.com/docs/installation/guide/) for recommendations
+on how to setup a development and runtime environment.
+
+## Building the target
+
+As a tier 2 target, the target is built by the Rust project.
+
+You can configure rustbuild like so:
+
+```toml
+[build]
+build-stage = 1
+target = ["x86_64-fortanix-unknown-sgx"]
+```
+
+## Building Rust programs
+
+Standard build flows using `cargo` or `rustc` should work.
+
+## Testing
+
+The Rust test suite as well as custom unit and integration tests will run on
+hardware that has Intel SGX enabled if a cargo runner is configured correctly,
+see the requirements section.
+
+## Cross-compilation toolchains and C code
+
+C code is not generally supported, as there is no libc. C code compiled for
+x86-64 in freestanding mode using the System V AMD64 ABI may work. The
+[rs-libc](https://crates.io/crates/rs-libc) crate contains a subset of libc
+that's known to work with this target.
diff --git a/src/doc/rustdoc/book.toml b/src/doc/rustdoc/book.toml
index dfa685785..45405a117 100644
--- a/src/doc/rustdoc/book.toml
+++ b/src/doc/rustdoc/book.toml
@@ -6,9 +6,5 @@ title = "The rustdoc book"
git-repository-url = "https://github.com/rust-lang/rust/tree/master/src/doc/rustdoc"
[output.html.redirect]
-"/what-to-include.html" = "write-documentation/what-to-include.html"
"/the-doc-attribute.html" = "write-documentation/the-doc-attribute.html"
-"/linking-to-items-by-name.html" = "write-documentation/linking-to-items-by-name.html"
"/documentation-tests.html" = "write-documentation/documentation-tests.html"
-"/website-features.html" = "advanced-features.html#custom-search-engines"
-"/passes.html" = "deprecated-features.html#passes"
diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md
index 32b350074..b8b5014ab 100644
--- a/src/doc/rustdoc/src/unstable-features.md
+++ b/src/doc/rustdoc/src/unstable-features.md
@@ -197,6 +197,35 @@ To do so, the `#[doc(keyword = "...")]` attribute is used. Example:
mod empty_mod {}
```
+## Effects of other nightly features
+
+These nightly-only features are not primarily related to Rustdoc,
+but have convenient effects on the documentation produced.
+
+### `fundamental` types
+
+Annotating a type with `#[fundamental]` primarily influences coherence rules about generic types,
+i.e., they alter whether other crates can provide implementations for that type.
+The unstable book [links to further information][unstable-fundamental].
+
+[unstable-fundamental]: https://doc.rust-lang.org/unstable-book/language-features/fundamental.html
+
+For documentation, this has an additional side effect:
+If a method is implemented on `F<T>` (or `F<&T>`),
+where `F` is a fundamental type,
+then the method is not only documented at the page about `F`,
+but also on the page about `T`.
+In a sense, it makes the type transparent to Rustdoc.
+This is especially convenient for types that work as annotated pointers,
+such as `Pin<&mut T>`,
+as it ensures that methods only implemented through those annotated pointers
+can still be found with the type they act on.
+
+If the `fundamental` feature's effect on coherence is not intended,
+such a type can be marked as fundamental only for purposes of documentation
+by introducing a custom feature and
+limiting the use of `fundamental` to when documentation is built.
+
## Unstable command-line arguments
These features are enabled by passing a command-line flag to Rustdoc, but the flags in question are
@@ -465,6 +494,16 @@ Note that the third item is the crate root, which in this case is undocumented.
[JSON format](https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc_json_types/). `--output-format html` has no effect,
and is also accepted on stable toolchains.
+JSON Output for toolchain crates (`std`, `alloc`, `core`, `test`, and `proc_macro`)
+is available via the `rust-docs-json` rustup component.
+
+```shell
+rustup component add --toolchain nightly rust-docs-json
+```
+
+Then the json files will be present in the `share/doc/rust/json/` directory
+of the rustup toolchain directory.
+
It can also be used with `--show-coverage`. Take a look at its
[documentation](#--show-coverage-calculate-the-percentage-of-items-with-documentation) for more
information.
diff --git a/src/doc/style-guide/book.toml b/src/doc/style-guide/book.toml
new file mode 100644
index 000000000..056aec8cd
--- /dev/null
+++ b/src/doc/style-guide/book.toml
@@ -0,0 +1,8 @@
+[book]
+title = "The Rust Style Guide"
+author = "The Rust Style Team"
+multilingual = false
+src = "src"
+
+[output.html]
+git-repository-url = "https://github.com/rust-lang/rust/tree/HEAD/src/doc/style-guide/"
diff --git a/src/doc/style-guide/src/README.md b/src/doc/style-guide/src/README.md
new file mode 100644
index 000000000..adb73a7ee
--- /dev/null
+++ b/src/doc/style-guide/src/README.md
@@ -0,0 +1,190 @@
+# Rust Style Guide
+
+## Motivation - why use a formatting tool?
+
+Formatting code is a mostly mechanical task which takes both time and mental
+effort. By using an automatic formatting tool, a programmer is relieved of
+this task and can concentrate on more important things.
+
+Furthermore, by sticking to an established style guide (such as this one),
+programmers don't need to formulate ad hoc style rules, nor do they need to
+debate with other programmers what style rules should be used, saving time,
+communication overhead, and mental energy.
+
+Humans comprehend information through pattern matching. By ensuring that all
+Rust code has similar formatting, less mental effort is required to comprehend a
+new project, lowering the barrier to entry for new developers.
+
+Thus, there are productivity benefits to using a formatting tool (such as
+rustfmt), and even larger benefits by using a community-consistent formatting,
+typically by using a formatting tool's default settings.
+
+
+## Formatting conventions
+
+### Indentation and line width
+
+* Use spaces, not tabs.
+* Each level of indentation must be four spaces (that is, all indentation
+ outside of string literals and comments must be a multiple of four).
+* The maximum width for a line is 100 characters.
+* A tool should be configurable for all three of these variables.
+
+
+### Blank lines
+
+Separate items and statements by either zero or one blank lines (i.e., one or
+two newlines). E.g,
+
+```rust
+fn foo() {
+ let x = ...;
+
+ let y = ...;
+ let z = ...;
+}
+
+fn bar() {}
+fn baz() {}
+```
+
+Formatting tools should make the bounds on blank lines configurable: there
+should be separate minimum and maximum numbers of newlines between both
+statements and (top-level) items (i.e., four options). As described above, the
+defaults for both statements and items should be minimum: 1, maximum: 2.
+
+
+### [Module-level items](items.md)
+### [Statements](statements.md)
+### [Expressions](expressions.md)
+### [Types](types.md)
+
+
+### Comments
+
+The following guidelines for comments are recommendations only, a mechanical
+formatter might skip formatting of comments.
+
+Prefer line comments (`//`) to block comments (`/* ... */`).
+
+When using line comments there should be a single space after the opening sigil.
+
+When using single-line block comments there should be a single space after the
+opening sigil and before the closing sigil. Multi-line block comments should
+have a newline after the opening sigil and before the closing sigil.
+
+Prefer to put a comment on its own line. Where a comment follows code, there
+should be a single space before it. Where a block comment is inline, there
+should be surrounding whitespace as if it were an identifier or keyword. There
+should be no trailing whitespace after a comment or at the end of any line in a
+multi-line comment. Examples:
+
+```rust
+// A comment on an item.
+struct Foo { ... }
+
+fn foo() {} // A comment after an item.
+
+pub fn foo(/* a comment before an argument */ x: T) {...}
+```
+
+Comments should usually be complete sentences. Start with a capital letter, end
+with a period (`.`). An inline block comment may be treated as a note without
+punctuation.
+
+Source lines which are entirely a comment should be limited to 80 characters
+in length (including comment sigils, but excluding indentation) or the maximum
+width of the line (including comment sigils and indentation), whichever is
+smaller:
+
+```rust
+// This comment goes up to the ................................. 80 char margin.
+
+{
+ // This comment is .............................................. 80 chars wide.
+}
+
+{
+ {
+ {
+ {
+ {
+ {
+ // This comment is limited by the ......................... 100 char margin.
+ }
+ }
+ }
+ }
+ }
+}
+```
+
+#### Doc comments
+
+Prefer line comments (`///`) to block comments (`/** ... */`).
+
+Prefer outer doc comments (`///` or `/** ... */`), only use inner doc comments
+(`//!` and `/*! ... */`) to write module-level or crate-level documentation.
+
+Doc comments should come before attributes.
+
+### Attributes
+
+Put each attribute on its own line, indented to the level of the item.
+In the case of inner attributes (`#!`), indent it to the level of the inside of
+the item. Prefer outer attributes, where possible.
+
+For attributes with argument lists, format like functions.
+
+```rust
+#[repr(C)]
+#[foo(foo, bar)]
+struct CRepr {
+ #![repr(C)]
+ x: f32,
+ y: f32,
+}
+```
+
+For attributes with an equal sign, there should be a single space before and
+after the `=`, e.g., `#[foo = 42]`.
+
+There must only be a single `derive` attribute. Note for tool authors: if
+combining multiple `derive` attributes into a single attribute, the ordering of
+the derived names should be preserved. E.g., `#[derive(bar)] #[derive(foo)]
+struct Baz;` should be formatted to `#[derive(bar, foo)] struct Baz;`.
+
+### *small* items
+
+In many places in this guide we specify that a formatter may format an item
+differently if it is *small*, for example struct literals:
+
+```rust
+// Normal formatting
+Foo {
+ f1: an_expression,
+ f2: another_expression(),
+}
+
+// *small* formatting
+Foo { f1, f2 }
+```
+
+We leave it to individual tools to decide on exactly what *small* means. In
+particular, tools are free to use different definitions in different
+circumstances.
+
+Some suitable heuristics are the size of the item (in characters) or the
+complexity of an item (for example, that all components must be simple names,
+not more complex sub-expressions). For more discussion on suitable heuristics,
+see [this issue](https://github.com/rust-lang-nursery/fmt-rfcs/issues/47).
+
+Tools should give the user an option to ignore such heuristics and always use
+the normal formatting.
+
+
+## [Non-formatting conventions](advice.md)
+
+## [Cargo.toml conventions](cargo.md)
+
+## [Principles used for deciding these guidelines](principles.md)
diff --git a/src/doc/style-guide/src/SUMMARY.md b/src/doc/style-guide/src/SUMMARY.md
new file mode 100644
index 000000000..004692fa6
--- /dev/null
+++ b/src/doc/style-guide/src/SUMMARY.md
@@ -0,0 +1,11 @@
+# Summary
+
+[Introduction](README.md)
+
+- [Module-level items](items.md)
+- [Statements](statements.md)
+- [Expressions](expressions.md)
+- [Types](types.md)
+- [Non-formatting conventions](advice.md)
+- [`Cargo.toml` conventions](cargo.md)
+- [Principles used for deciding these guidelines](principles.md)
diff --git a/src/doc/style-guide/src/advice.md b/src/doc/style-guide/src/advice.md
new file mode 100644
index 000000000..ab4b92b0a
--- /dev/null
+++ b/src/doc/style-guide/src/advice.md
@@ -0,0 +1,34 @@
+# Other style advice
+
+## Expressions
+
+Prefer to use Rust's expression oriented nature where possible;
+
+```rust
+// use
+let x = if y { 1 } else { 0 };
+// not
+let x;
+if y {
+ x = 1;
+} else {
+ x = 0;
+}
+```
+
+## Names
+
+ * Types shall be `UpperCamelCase`,
+ * Enum variants shall be `UpperCamelCase`,
+ * Struct fields shall be `snake_case`,
+ * Function and method names shall be `snake_case`,
+ * Local variables shall be `snake_case`,
+ * Macro names shall be `snake_case`,
+ * Constants (`const`s and immutable `static`s) shall be `SCREAMING_SNAKE_CASE`.
+ * When a name is forbidden because it is a reserved word (e.g., `crate`), use a
+ trailing underscore to make the name legal (e.g., `crate_`), or use raw
+ identifiers if possible.
+
+### Modules
+
+Avoid `#[path]` annotations where possible.
diff --git a/src/doc/style-guide/src/cargo.md b/src/doc/style-guide/src/cargo.md
new file mode 100644
index 000000000..f4993ba06
--- /dev/null
+++ b/src/doc/style-guide/src/cargo.md
@@ -0,0 +1,78 @@
+# Cargo.toml conventions
+
+## Formatting conventions
+
+Use the same line width and indentation as Rust code.
+
+Put a blank line between the last key-value pair in a section and the header of
+the next section. Do not place a blank line between section headers and the
+key-value pairs in that section, or between key-value pairs in a section.
+
+Sort key names alphabetically within each section, with the exception of the
+`[package]` section. Put the `[package]` section at the top of the file; put
+the `name` and `version` keys in that order at the top of that section,
+followed by the remaining keys other than `description` in alphabetical order,
+followed by the `description` at the end of that section.
+
+Don't use quotes around any standard key names; use bare keys. Only use quoted
+keys for non-standard keys whose names require them, and avoid introducing such
+key names when possible. See the [TOML
+specification](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md#table)
+for details.
+
+Put a single space both before and after the `=` between a key and value. Do
+not indent any key names; start all key names at the start of a line.
+
+Use multi-line strings (rather than newline escape sequences) for any string
+values that include multiple lines, such as the crate description.
+
+For array values, such as a list of authors, put the entire list on the same
+line as the key, if it fits. Otherwise, use block indentation: put a newline
+after the opening square bracket, indent each item by one indentation level,
+put a comma after each item (including the last), and put the closing square
+bracket at the start of a line by itself after the last item.
+
+```rust
+authors = [
+ "A Uthor <a.uthor@example.org>",
+ "Another Author <author@example.net>",
+]
+```
+
+For table values, such as a crate dependency with a path, write the entire
+table using curly braces and commas on the same line as the key if it fits. If
+the entire table does not fit on the same line as the key, separate it out into
+a separate section with key-value pairs:
+
+```toml
+[dependencies]
+crate1 = { path = "crate1", version = "1.2.3" }
+
+[dependencies.extremely_long_crate_name_goes_here]
+path = "extremely_long_path_name_goes_right_here"
+version = "4.5.6"
+```
+
+## Metadata conventions
+
+The authors list should consist of strings that each contain an author name
+followed by an email address in angle brackets: `Full Name <email@address>`.
+It should not contain bare email addresses, or names without email addresses.
+(The authors list may also include a mailing list address without an associated
+name.)
+
+The license field must contain a valid [SPDX
+expression](https://spdx.org/spdx-specification-21-web-version#h.jxpfx0ykyb60),
+using valid [SPDX license names](https://spdx.org/licenses/). (As an exception,
+by widespread convention, the license field may use `/` in place of ` OR `; for
+example, `MIT/Apache-2.0`.)
+
+The homepage field, if present, must consist of a single URL, including the
+scheme (e.g. `https://example.org/`, not just `example.org`.)
+
+Within the description field, wrap text at 80 columns. Don't start the
+description field with the name of the crate (e.g. "cratename is a ..."); just
+describe the crate itself. If providing a multi-sentence description, the first
+sentence should go on a line by itself and summarize the crate, like the
+subject of an email or commit message; subsequent sentences can then describe
+the crate in more detail.
diff --git a/src/doc/style-guide/src/expressions.md b/src/doc/style-guide/src/expressions.md
new file mode 100644
index 000000000..c7d0446dd
--- /dev/null
+++ b/src/doc/style-guide/src/expressions.md
@@ -0,0 +1,850 @@
+## Expressions
+
+### Blocks
+
+A block expression should have a newline after the initial `{` and before the
+terminal `}`. Any qualifier before the block (e.g., `unsafe`) should always be
+on the same line as the opening brace, and separated with a single space. The
+contents of the block should be block indented:
+
+```rust
+fn block_as_stmt() {
+ a_call();
+
+ {
+ a_call_inside_a_block();
+
+ // a comment in a block
+ the_value
+ }
+}
+
+fn block_as_expr() {
+ let foo = {
+ a_call_inside_a_block();
+
+ // a comment in a block
+ the_value
+ };
+}
+
+fn unsafe_block_as_stmt() {
+ a_call();
+
+ unsafe {
+ a_call_inside_a_block();
+
+ // a comment in a block
+ the_value
+ }
+}
+```
+
+If a block has an attribute, it should be on its own line:
+
+```rust
+fn block_as_stmt() {
+ #[an_attribute]
+ {
+ #![an_inner_attribute]
+
+ // a comment in a block
+ the_value
+ }
+}
+```
+
+Avoid writing comments on the same line as the braces.
+
+An empty block should be written as `{}`.
+
+A block may be written on a single line if:
+
+* it is either used in expression position (not statement position) or is an
+ unsafe block in statement position
+* contains a single-line expression and no statements
+* contains no comments
+
+A single line block should have spaces after the opening brace and before the
+closing brace.
+
+Examples:
+
+```rust
+fn main() {
+ // Single line
+ let _ = { a_call() };
+ let _ = unsafe { a_call() };
+
+ // Not allowed on one line
+ // Statement position.
+ {
+ a_call()
+ }
+
+ // Contains a statement
+ let _ = {
+ a_call();
+ };
+ unsafe {
+ a_call();
+ }
+
+ // Contains a comment
+ let _ = {
+ // A comment
+ };
+ let _ = {
+ // A comment
+ a_call()
+ };
+
+ // Multiple lines
+ let _ = {
+ a_call();
+ another_call()
+ };
+ let _ = {
+ a_call(
+ an_argument,
+ another_arg,
+ )
+ };
+}
+```
+
+
+### Closures
+
+Don't put any extra spaces before the first `|` (unless the closure is prefixed
+by `move`); put a space between the second `|` and the expression of the
+closure. Between the `|`s, you should use function definition syntax, however,
+elide types where possible.
+
+Use closures without the enclosing `{}`, if possible. Add the `{}` when you have
+a return type, when there are statements, there are comments in the body, or the
+body expression spans multiple lines and is a control-flow expression. If using
+braces, follow the rules above for blocks. Examples:
+
+```rust
+|arg1, arg2| expr
+
+move |arg1: i32, arg2: i32| -> i32 {
+ expr1;
+ expr2
+}
+
+|| Foo {
+ field1,
+ field2: 0,
+}
+
+|| {
+ if true {
+ blah
+ } else {
+ boo
+ }
+}
+
+|x| unsafe {
+ expr
+}
+```
+
+
+### Struct literals
+
+If a struct literal is *small* it may be formatted on a single line. If not,
+each field should be on it's own, block-indented line. There should be a
+trailing comma in the multi-line form only. There should be a space after the
+colon only.
+
+There should be a space before the opening brace. In the single-line form there
+should be spaces after the opening brace and before the closing brace.
+
+```rust
+Foo { field1, field2: 0 }
+let f = Foo {
+ field1,
+ field2: an_expr,
+};
+```
+
+Functional record update syntax is treated like a field, but it must never have
+a trailing comma. There should be no space after `..`.
+
+let f = Foo {
+ field1,
+ ..an_expr
+};
+
+
+### Tuple literals
+
+Use a single-line form where possible. There should not be spaces around the
+parentheses. Where a single-line form is not possible, each element of the tuple
+should be on its own block-indented line and there should be a trailing comma.
+
+```rust
+(a, b, c)
+
+let x = (
+ a_long_expr,
+ another_very_long_expr,
+);
+```
+
+
+### Tuple struct literals
+
+There should be no space between the identifier and the opening parenthesis.
+Otherwise, follow the rules for tuple literals, e.g., `Foo(a, b)`.
+
+
+### Enum literals
+
+Follow the formatting rules for the various struct literals. Prefer using the
+name of the enum as a qualifying name, unless the enum is in the prelude. E.g.,
+
+```rust
+Foo::Bar(a, b)
+Foo::Baz {
+ field1,
+ field2: 1001,
+}
+Ok(an_expr)
+```
+
+
+### Array literals
+
+For simple array literals, avoid line breaking, no spaces around square
+brackets, contents of the array should be separated by commas and spaces. If
+using the repeating initialiser, there should be a space after the semicolon
+only. Apply the same rules if using the `vec!` or similar macros (always use
+square brackets here). Examples:
+
+```rust
+fn main() {
+ [1, 2, 3];
+ vec![a, b, c, d];
+ let a = [42; 10];
+}
+```
+
+If a line must be broken, prefer breaking only after the `;`, if possible.
+Otherwise, follow the rules below for function calls. In any case, the contents
+of the initialiser should be block indented and there should be line breaks
+after the opening bracket and before the closing bracket:
+
+```rust
+fn main() {
+ [
+ a_long_expression();
+ 1234567890
+ ]
+ let x = [
+ an_expression,
+ another_expression,
+ a_third_expression,
+ ];
+}
+```
+
+
+### Array accesses, indexing, and slicing.
+
+No spaces around the square brackets, avoid breaking lines if possible, never
+break a line between the target expression and the opening bracket. If the
+indexing expression covers multiple lines, then it should be block indented and
+there should be newlines after the opening brackets and before the closing
+bracket. However, this should be avoided where possible.
+
+Examples:
+
+```rust
+fn main() {
+ foo[42];
+ &foo[..10];
+ bar[0..100];
+ foo[4 + 5 / bar];
+ a_long_target[
+ a_long_indexing_expression
+ ];
+}
+```
+
+### Unary operations
+
+Do not include a space between a unary op and its operand (i.e., `!x`, not
+`! x`). However, there must be a space after `&mut`. Avoid line-breaking
+between a unary operator and its operand.
+
+### Binary operations
+
+Do include spaces around binary ops (i.e., `x + 1`, not `x+1`) (including `=`
+and other assignment operators such as `+=` or `*=`).
+
+For comparison operators, because for `T op U`, `&T op &U` is also implemented:
+if you have `t: &T`, and `u: U`, prefer `*t op u` to `t op &u`. In general,
+within expressions, prefer dereferencing to taking references.
+
+Use parentheses liberally, do not necessarily elide them due to precedence.
+Tools should not automatically insert or remove parentheses. Do not use spaces
+to indicate precedence.
+
+If line-breaking, put the operator on a new line and block indent. Put each
+sub-expression on its own line. E.g.,
+
+```rust
+foo_bar
+ + bar
+ + baz
+ + qux
+ + whatever
+```
+
+Prefer line-breaking at an assignment operator (either `=` or `+=`, etc.) rather
+than at other binary operators.
+
+### Control flow
+
+Do not include extraneous parentheses for `if` and `while` expressions.
+
+```rust
+if true {
+}
+```
+
+is better than
+
+```rust
+if (true) {
+}
+```
+
+Do include extraneous parentheses if it makes an arithmetic or logic expression
+easier to understand (`(x * 15) + (y * 20)` is fine)
+
+### Function calls
+
+Do not put a space between the function name, and the opening parenthesis.
+
+Do not put a space between an argument, and the comma which follows.
+
+Do put a space between an argument, and the comma which precedes it.
+
+Prefer not to break a line in the callee expression.
+
+#### Single-line calls
+
+Do not put a space between the function name and open paren, between the open
+paren and the first argument, or between the last argument and the close paren.
+
+Do not put a comma after the last argument.
+
+```rust
+foo(x, y, z)
+```
+
+#### Multi-line calls
+
+If the function call is not *small*, it would otherwise over-run the max width,
+or any argument or the callee is multi-line, then the call should be formatted
+across multiple lines. In this case, each argument should be on it's own block-
+indented line, there should be a newline after the opening parenthesis and
+before the closing parenthesis, and there should be a trailing comma. E.g.,
+
+```rust
+a_function_call(
+ arg1,
+ a_nested_call(a, b),
+)
+```
+
+
+### Method calls
+
+Follow the function rules for calling.
+
+Do not put any spaces around the `.`.
+
+```rust
+x.foo().bar().baz(x, y, z);
+```
+
+
+### Macro uses
+
+Macros which can be parsed like other constructs should be formatted like those
+constructs. For example, a macro use `foo!(a, b, c)` can be parsed like a
+function call (ignoring the `!`), therefore it should be formatted following the
+rules for function calls.
+
+#### Special case macros
+
+Macros which take a format string and where all other arguments are *small* may
+be formatted with arguments before and after the format string on a single line
+and the format string on its own line, rather than putting each argument on its
+own line. For example,
+
+```rust
+println!(
+ "Hello {} and {}",
+ name1, name2,
+);
+
+assert_eq!(
+ x, y,
+ "x and y were not equal, see {}",
+ reason,
+);
+```
+
+
+### Casts (`as`)
+
+Put spaces before and after `as`:
+
+```rust
+let cstr = "Hi\0" as *const str as *const [u8] as *const std::os::raw::c_char;
+```
+
+
+### Chains of fields and method calls
+
+A chain is a sequence of field accesses and/or method calls. A chain may also
+include the try operator ('?'). E.g., `a.b.c().d` or `foo?.bar().baz?`.
+
+Prefer formatting on one line if possible, and the chain is *small*. If
+formatting on multiple lines, each field access or method call in the chain
+should be on its own line with the line-break before the `.` and after any `?`.
+Each line should be block-indented. E.g.,
+
+```rust
+let foo = bar
+ .baz?
+ .qux();
+```
+
+If the length of the last line of the first element plus its indentation is
+less than or equal to the indentation of the second line (and there is space),
+then combine the first and second lines, e.g.,
+
+```rust
+x.baz?
+ .qux()
+
+let foo = x
+ .baz?
+ .qux();
+
+foo(
+ expr1,
+ expr2,
+).baz?
+ .qux();
+```
+
+#### Multi-line elements
+
+If any element in a chain is formatted across multiple lines, then that element
+and any later elements must be on their own line. Earlier elements may be kept
+on a single line. E.g.,
+
+```rust
+a.b.c()?.d
+ .foo(
+ an_expr,
+ another_expr,
+ )
+ .bar
+ .baz
+```
+
+Note there is block indent due to the chain and the function call in the above
+example.
+
+Prefer formatting the whole chain in multi-line style and each element on one
+line, rather than putting some elements on multiple lines and some on a single
+line, e.g.,
+
+```rust
+// Better
+self.pre_comment
+ .as_ref()
+ .map_or(false, |comment| comment.starts_with("//"))
+
+// Worse
+self.pre_comment.as_ref().map_or(
+ false,
+ |comment| comment.starts_with("//"),
+)
+```
+
+### Control flow expressions
+
+This section covers `if`, `if let`, `loop`, `while`, `while let`, and `for`
+expressions.
+
+The keyword, any initial clauses, and the opening brace of the block should be
+on a single line. The usual rules for [block formatting](#blocks) should be
+applied to the block.
+
+If there is an `else` component, then the closing brace, `else`, any following
+clause, and the opening brace should all be on the same line. There should be a
+single space before and after the `else` keyword. For example:
+
+```rust
+if ... {
+ ...
+} else {
+ ...
+}
+
+if let ... {
+ ...
+} else if ... {
+ ...
+} else {
+ ...
+}
+```
+
+If the control line needs to be broken, then prefer to break before the `=` in
+`* let` expressions and before `in` in a `for` expression; the following line
+should be block indented. If the control line is broken for any reason, then the
+opening brace should be on its own line and not indented. Examples:
+
+```rust
+while let Some(foo)
+ = a_long_expression
+{
+ ...
+}
+
+for foo
+ in a_long_expression
+{
+ ...
+}
+
+if a_long_expression
+ && another_long_expression
+ || a_third_long_expression
+{
+ ...
+}
+```
+
+Where the initial clause is multi-lined and ends with one or more closing
+parentheses, square brackets, or braces, and there is nothing else on that line,
+and that line is not indented beyond the indent on the first line of the control
+flow expression, then the opening brace of the block should be put on the same
+line with a preceding space. For example:
+
+```rust
+if !self.config.file_lines().intersects(
+ &self.codemap.lookup_line_range(
+ stmt.span,
+ ),
+) { // Opening brace on same line as initial clause.
+ ...
+}
+```
+
+
+#### Single line `if else`
+
+Formatters may place an `if else` or `if let else` on a single line if it occurs
+in expression context (i.e., is not a standalone statement), it contains a
+single `else` clause, and is *small*. For example:
+
+```rust
+let y = if x { 0 } else { 1 };
+
+// Examples that must be multi-line.
+let y = if something_very_long {
+ not_small
+} else {
+ also_not_small
+};
+
+if x {
+ 0
+} else {
+ 1
+}
+```
+
+
+### Match
+
+Prefer not to line-break inside the discriminant expression. There must always
+be a line break after the opening brace and before the closing brace. The match
+arms must be block indented once:
+
+```rust
+match foo {
+ // arms
+}
+
+let x = match foo.bar.baz() {
+ // arms
+};
+```
+
+Use a trailing comma for a match arm if and only if not using a block.
+
+Never start a match arm pattern with `|`, e.g.,
+
+```rust
+match foo {
+ // Don't do this.
+ | foo => bar,
+ // Or this.
+ | a_very_long_pattern
+ | another_pattern
+ | yet_another_pattern
+ | a_forth_pattern => {
+ ...
+ }
+}
+```
+
+Prefer
+
+
+```rust
+match foo {
+ foo => bar,
+ a_very_long_pattern
+ | another_pattern
+ | yet_another_pattern
+ | a_forth_pattern => {
+ ...
+ }
+}
+```
+
+Avoid splitting the left-hand side (before the `=>`) of a match arm where
+possible. If the right-hand side of the match arm is kept on the same line,
+never use a block (unless the block is empty).
+
+If the right-hand side consists of multiple statements or has line comments or
+the start of the line cannot be fit on the same line as the left-hand side, use
+a block.
+
+The body of a block arm should be block indented once.
+
+Examples:
+
+```rust
+match foo {
+ foo => bar,
+ a_very_long_patten | another_pattern if an_expression() => {
+ no_room_for_this_expression()
+ }
+ foo => {
+ // A comment.
+ an_expression()
+ }
+ foo => {
+ let a = statement();
+ an_expression()
+ }
+ bar => {}
+ // Trailing comma on last item.
+ foo => bar,
+}
+```
+
+If the body is a single expression with no line comments and not a control flow
+expression, then it may be started on the same line as the right-hand side. If
+not, then it must be in a block. Example,
+
+```rust
+match foo {
+ // A combinable expression.
+ foo => a_function_call(another_call(
+ argument1,
+ argument2,
+ )),
+ // A non-combinable expression
+ bar => {
+ a_function_call(
+ another_call(
+ argument1,
+ argument2,
+ ),
+ another_argument,
+ )
+ }
+}
+```
+
+#### Line-breaking
+
+Where it is possible to use a block form on the right-hand side and avoid
+breaking the left-hand side, do that. E.g.
+
+```rust
+ // Assuming the following line does done fit in the max width
+ a_very_long_pattern | another_pattern => ALongStructName {
+ ...
+ },
+ // Prefer this
+ a_very_long_pattern | another_pattern => {
+ ALongStructName {
+ ...
+ }
+ }
+ // To splitting the pattern.
+```
+
+Never break after `=>` without using the block form of the body.
+
+If the left-hand side must be split and there is an `if` clause, break before
+the `if` and block indent. In this case, always use a block body and start the
+body on a new line:
+
+```rust
+ a_very_long_pattern | another_pattern
+ if expr =>
+ {
+ ...
+ }
+```
+
+If required to break the pattern, put each clause of the pattern on its own
+line with no additional indent, breaking before the `|`. If there is an `if`
+clause, then you must use the above form:
+
+```rust
+ a_very_long_pattern
+ | another_pattern
+ | yet_another_pattern
+ | a_forth_pattern => {
+ ...
+ }
+ a_very_long_pattern
+ | another_pattern
+ | yet_another_pattern
+ | a_forth_pattern
+ if expr =>
+ {
+ ...
+ }
+```
+
+If the pattern is multi-line, and the last line is less wide than the indent, do
+not put the `if` clause on a newline. E.g.,
+
+```rust
+ Token::Dimension {
+ value,
+ ref unit,
+ ..
+ } if num_context.is_ok(context.parsing_mode, value) => {
+ ...
+ }
+```
+
+If every clause in a pattern is *small*, but does not fit on one line, then the
+pattern may be formatted across multiple lines with as many clauses per line as
+possible. Again break before a `|`:
+
+```rust
+ foo | bar | baz
+ | qux => {
+ ...
+ }
+```
+
+We define a pattern clause to be *small* if it matches the following grammar:
+
+```
+[small, ntp]:
+ - single token
+ - `&[single-line, ntp]`
+
+[small]:
+ - `[small, ntp]`
+ - unary tuple constructor `([small, ntp])`
+ - `&[small]`
+```
+
+E.g., `&&Some(foo)` matches, `Foo(4, Bar)` does not.
+
+
+### Combinable expressions
+
+Where a function call has a single argument, and that argument is formatted
+across multiple-lines, the outer call may be formatted as if it were a single-
+line call. The same combining behaviour may be applied to any similar
+expressions which have multi-line, block-indented lists of sub-expressions
+delimited by parentheses (e.g., macros or tuple struct literals). E.g.,
+
+```rust
+foo(bar(
+ an_expr,
+ another_expr,
+))
+
+let x = foo(Bar {
+ field: whatever,
+});
+
+foo(|param| {
+ action();
+ foo(param)
+})
+```
+
+Such behaviour should extend recursively, however, tools may choose to limit the
+depth of nesting.
+
+Only where the multi-line sub-expression is a closure with an explicit block,
+this combining behaviour may be used where there are other arguments, as long as
+all the arguments and the first line of the closure fit on the first line, the
+closure is the last argument, and there is only one closure argument:
+
+```rust
+foo(first_arg, x, |param| {
+ action();
+ foo(param)
+})
+```
+
+
+### Ranges
+
+Do not put spaces in ranges, e.g., `0..10`, `x..=y`, `..x.len()`, `foo..`.
+
+When writing a range with both upper and lower bounds, if the line must be
+broken, break before the range operator and block indent the second line:
+
+```rust
+a_long_expression
+ ..another_long_expression
+```
+
+For the sake of indicating precedence, we recommend that if either bound is a
+compound expression, then use parentheses around it, e.g., `..(x + 1)`,
+`(x.f)..(x.f.len())`, or `0..(x - 10)`.
+
+
+### Hexadecimal literals
+
+Hexadecimal literals may use upper- or lower-case letters, but they must not be
+mixed within the same literal. Projects should use the same case for all
+literals, but we do not make a recommendation for either lower- or upper-case.
+Tools should have an option to convert mixed case literals to upper-case, and
+may have an option to convert all literals to either lower- or upper-case.
+
+
+## Patterns
+
+Patterns should be formatted like their corresponding expressions. See the
+section on `match` for additional formatting for patterns in match arms.
diff --git a/src/doc/style-guide/src/items.md b/src/doc/style-guide/src/items.md
new file mode 100644
index 000000000..283597535
--- /dev/null
+++ b/src/doc/style-guide/src/items.md
@@ -0,0 +1,565 @@
+## Items
+
+`extern crate` statements must be first in a file. They must be ordered
+alphabetically.
+
+`use` statements, and module *declarations* (`mod foo;`, not `mod { ... }`)
+must come before other items. We recommend that imports come before module
+declarations; if imports and modules are separated, then they should be ordered
+alphabetically. When sorting, `self` and `super` must come before any other
+names. Module declarations should not be moved if they are annotated with
+`#[macro_use]`, since that may be semantics changing.
+
+Tools should make the above ordering optional.
+
+
+### Function definitions
+
+In Rust, one finds functions by searching for `fn [function-name]`; It's
+important that you style your code so that it's very searchable in this way.
+
+The proper ordering and spacing is:
+
+```rust
+[pub] [unsafe] [extern ["ABI"]] fn foo(arg1: i32, arg2: i32) -> i32 {
+ ...
+}
+```
+
+Avoid comments within the signature itself.
+
+If the function signature does not fit on one line, then break after the opening
+parenthesis and before the closing parenthesis and put each argument on its own
+block-indented line. For example,
+
+```rust
+fn foo(
+ arg1: i32,
+ arg2: i32,
+) -> i32 {
+ ...
+}
+```
+
+Note the trailing comma on the last argument.
+
+
+### Tuples and tuple structs
+
+Write the type list as you would a parameter list to a function.
+
+Build a tuple or tuple struct as you would call a function.
+
+#### Single-line
+
+```rust
+struct Bar(Type1, Type2);
+
+let x = Bar(11, 22);
+let y = (11, 22, 33);
+```
+
+### Enums
+
+In the declaration, put each variant on its own line, block indented.
+
+Format each variant accordingly as either a struct, tuple struct, or identifier,
+which doesn't require special formatting (but without the `struct` keyword.
+
+```rust
+enum FooBar {
+ First(u32),
+ Second,
+ Error {
+ err: Box<Error>,
+ line: u32,
+ },
+}
+```
+
+If a struct variant is [*small*](index.html#small-items), it may be formatted on
+one line. In this case, do not use a trailing comma for the field list, but do
+put spaces around each brace:
+
+```rust
+enum FooBar {
+ Error { err: Box<Error>, line: u32 },
+}
+```
+
+In an enum with multiple struct variants, if any struct variant is written on
+multiple lines, then the multi-line formatting should be used for all struct
+variants. However, such a situation might be an indication that you should
+factor out the fields of the variant into their own struct.
+
+
+### Structs and Unions
+
+Struct names follow on the same line as the `struct` keyword, with the opening
+brace on the same line when it fits within the right margin. All struct fields
+are indented once and end with a trailing comma. The closing brace is not
+indented and appears on its own line.
+
+```rust
+struct Foo {
+ a: A,
+ b: B,
+}
+```
+
+If and only if the type of a field does not fit within the right margin, it is
+pulled down to its own line and indented again.
+
+```rust
+struct Foo {
+ a: A,
+ long_name:
+ LongType,
+}
+```
+
+Prefer using a unit struct (e.g., `struct Foo;`) to an empty struct (e.g.,
+`struct Foo();` or `struct Foo {}`, these only exist to simplify code
+generation), but if you must use an empty struct, keep it on one line with no
+space between the braces: `struct Foo;` or `struct Foo {}`.
+
+The same guidelines are used for untagged union declarations.
+
+```rust
+union Foo {
+ a: A,
+ b: B,
+ long_name:
+ LongType,
+}
+```
+
+
+### Tuple structs
+
+Put the whole struct on one line if possible. Types in the parentheses should be
+separated by a comma and space with no trailing comma. No spaces around the
+parentheses or semi-colon:
+
+```rust
+pub struct Foo(String, u8);
+```
+
+Prefer unit structs to empty tuple structs (these only exist to simplify code
+generation), e.g., `struct Foo;` rather than `struct Foo();`.
+
+For more than a few fields, prefer a proper struct with named fields. Given
+this, a tuple struct should always fit on one line. If it does not, block format
+the fields with a field on each line and a trailing comma:
+
+```rust
+pub struct Foo(
+ String,
+ u8,
+);
+```
+
+
+### Traits
+
+Trait items should be block-indented. If there are no items, the trait may be
+formatted on a single line. Otherwise there should be line-breaks after the
+opening brace and before the closing brace:
+
+```rust
+trait Foo {}
+
+pub trait Bar {
+ ...
+}
+```
+
+If the trait has bounds, there should be a space after the colon but not before
+and before and after each `+`, e.g.,
+
+```rust
+trait Foo: Debug + Bar {}
+```
+
+Prefer not to line-break in the bounds if possible (consider using a `where`
+clause). Prefer to break between bounds than to break any individual bound. If
+you must break the bounds, put each bound (including the first) on its own
+block-indented line, break before the `+` and put the opening brace on its own
+line:
+
+```rust
+pub trait IndexRanges:
+ Index<Range<usize>, Output=Self>
+ + Index<RangeTo<usize>, Output=Self>
+ + Index<RangeFrom<usize>, Output=Self>
+ + Index<RangeFull, Output=Self>
+{
+ ...
+}
+```
+
+
+### Impls
+
+Impl items should be block indented. If there are no items, the impl may be
+formatted on a single line. Otherwise there should be line-breaks after the
+opening brace and before the closing brace:
+
+```rust
+impl Foo {}
+
+impl Bar for Foo {
+ ...
+}
+```
+
+Avoid line-breaking in the signature if possible. If a line break is required in
+a non-inherent impl, break immediately before `for`, block indent the concrete type
+and put the opening brace on its own line:
+
+```rust
+impl Bar
+ for Foo
+{
+ ...
+}
+```
+
+
+### Extern crate
+
+`extern crate foo;`
+
+Use spaces around keywords, no spaces around the semi-colon.
+
+
+### Modules
+
+```rust
+mod foo {
+}
+```
+
+```rust
+mod foo;
+```
+
+Use spaces around keywords and before the opening brace, no spaces around the
+semi-colon.
+
+### macro\_rules!
+
+Use `{}` for the full definition of the macro.
+
+```rust
+macro_rules! foo {
+}
+```
+
+
+### Generics
+
+Prefer to put a generics clause on one line. Break other parts of an item
+declaration rather than line-breaking a generics clause. If a generics clause is
+large enough to require line-breaking, you should prefer to use a `where` clause
+instead.
+
+Do not put spaces before or after `<` nor before `>`. Only put a space after `>`
+if it is followed by a word or opening brace, not an opening parenthesis. There
+should be a space after each comma and no trailing comma.
+
+```rust
+fn foo<T: Display, U: Debug>(x: Vec<T>, y: Vec<U>) ...
+
+impl<T: Display, U: Debug> SomeType<T, U> { ...
+```
+
+If the generics clause must be formatted across multiple lines, each parameter
+should have its own block-indented line, there should be newlines after the
+opening bracket and before the closing bracket, and the should be a trailing
+comma.
+
+```rust
+fn foo<
+ T: Display,
+ U: Debug,
+>(x: Vec<T>, y: Vec<U>) ...
+```
+
+If an associated type is bound in a generic type, then there should be spaces on
+either side of the `=`:
+
+```rust
+<T: Example<Item = u32>>
+```
+
+Prefer to use single-letter names for generic parameters.
+
+
+### `where` clauses
+
+These rules apply for `where` clauses on any item.
+
+A `where` clause may immediately follow a closing bracket of any kind.
+Otherwise, it must start a new line, with no indent. Each component of a `where`
+clause must be on its own line and be block indented. There should be a trailing
+comma, unless the clause is terminated with a semicolon. If the `where` clause
+is followed by a block (or assignment), the block should be started on a new
+line. Examples:
+
+```rust
+fn function<T, U>(args)
+where
+ T: Bound,
+ U: AnotherBound,
+{
+ body
+}
+
+fn foo<T>(
+ args
+) -> ReturnType
+where
+ T: Bound,
+{
+ body
+}
+
+fn foo<T, U>(
+ args,
+) where
+ T: Bound,
+ U: AnotherBound,
+{
+ body
+}
+
+fn foo<T, U>(
+ args
+) -> ReturnType
+where
+ T: Bound,
+ U: AnotherBound; // Note, no trailing comma.
+
+// Note that where clauses on `type` aliases are not enforced and should not
+// be used.
+type Foo<T>
+where
+ T: Bound
+= Bar<T>;
+```
+
+If a `where` clause is very short, we recommend using an inline bound on the
+type parameter.
+
+
+If a component of a `where` clause is long, it may be broken before `+` and
+further block indented. Each bound should go on its own line. E.g.,
+
+```rust
+impl<T: ?Sized, Idx> IndexRanges<Idx> for T
+where
+ T: Index<Range<Idx>, Output = Self::Output>
+ + Index<RangeTo<Idx>, Output = Self::Output>
+ + Index<RangeFrom<Idx>, Output = Self::Output>
+ + Index<RangeInclusive<Idx>, Output = Self::Output>
+ + Index<RangeToInclusive<Idx>, Output = Self::Output> + Index<RangeFull>
+```
+
+#### Option - `where_single_line`
+
+`where_single_line` is `false` by default. If `true`, then a where clause with
+exactly one component may be formatted on a single line if the rest of the
+item's signature is also kept on one line. In this case, there is no need for a
+trailing comma and if followed by a block, no need for a newline before the
+block. E.g.,
+
+```rust
+// May be single-lined.
+fn foo<T>(args) -> ReturnType
+where T: Bound {
+ body
+}
+
+// Must be multi-lined.
+fn foo<T>(
+ args
+) -> ReturnType
+where
+ T: Bound,
+{
+ body
+}
+```
+
+
+### Type aliases
+
+Type aliases should generally be kept on one line. If necessary to break the
+line, do so after the `=`; the right-hand-side should be block indented:
+
+```rust
+pub type Foo = Bar<T>;
+
+// If multi-line is required
+type VeryLongType<T, U: SomeBound> =
+ AnEvenLongerType<T, U, Foo<T>>;
+```
+
+Where possible avoid `where` clauses and keep type constraints inline. Where
+that is not possible split the line before and after the `where` clause (and
+split the `where` clause as normal), e.g.,
+
+```rust
+type VeryLongType<T, U>
+where
+ T: U::AnAssociatedType,
+ U: SomeBound,
+= AnEvenLongerType<T, U, Foo<T>>;
+```
+
+
+### Associated types
+
+Associated types should follow the guidelines above for type aliases. Where an
+associated type has a bound, there should be a space after the colon but not
+before:
+
+```rust
+pub type Foo: Bar;
+```
+
+
+### extern items
+
+When writing extern items (such as `extern "C" fn`), always be explicit about
+the ABI. For example, write `extern "C" fn foo ...`, not `extern fn foo ...`, or
+`extern "C" { ... }`.
+
+
+### Imports (`use` statements)
+
+If an import can be formatted on one line, do so. There should be no spaces
+around braces.
+
+```rust
+use a::b::c;
+use a::b::d::*;
+use a::b::{foo, bar, baz};
+```
+
+
+#### Large list imports
+
+Prefer to use multiple imports rather than a multi-line import. However, tools
+should not split imports by default (they may offer this as an option).
+
+If an import does require multiple lines (either because a list of single names
+does not fit within the max width, or because of the rules for nested imports
+below), then break after the opening brace and before the closing brace, use a
+trailing comma, and block indent the names.
+
+
+```rust
+// Prefer
+foo::{long, list, of, imports};
+foo::{more, imports};
+
+// If necessary
+foo::{
+ long, list, of, imports, more,
+ imports, // Note trailing comma
+};
+```
+
+
+#### Ordering of imports
+
+A *group* of imports is a set of imports on the same or sequential lines. One or
+more blank lines or other items (e.g., a function) separate groups of imports.
+
+Within a group of imports, imports must be sorted ascii-betically. Groups of
+imports must not be merged or re-ordered.
+
+
+E.g., input:
+
+```rust
+use d;
+use c;
+
+use b;
+use a;
+```
+
+output:
+
+```rust
+use c;
+use d;
+
+use a;
+use b;
+```
+
+Because of `macro_use`, attributes must also start a new group and prevent
+re-ordering.
+
+Note that tools which only have access to syntax (such as Rustfmt) cannot tell
+which imports are from an external crate or the std lib, etc.
+
+
+#### Ordering list import
+
+Names in a list import must be sorted ascii-betically, but with `self` and
+`super` first, and groups and glob imports last. This applies recursively. For
+example, `a::*` comes before `b::a` but `a::b` comes before `a::*`. E.g.,
+`use foo::bar::{a, b::c, b::d, b::d::{x, y, z}, b::{self, r, s}};`.
+
+
+#### Normalisation
+
+Tools must make the following normalisations:
+
+* `use a::self;` -> `use a;`
+* `use a::{};` -> (nothing)
+* `use a::{b};` -> `use a::b;`
+
+And must apply these recursively.
+
+Tools must not otherwise merge or un-merge import lists or adjust glob imports
+(without an explicit option).
+
+
+#### Nested imports
+
+If there are any nested imports in a list import, then use the multi-line form,
+even if the import fits on one line. Each nested import must be on its own line,
+but non-nested imports must be grouped on as few lines as possible.
+
+For example,
+
+```rust
+use a::b::{
+ x, y, z,
+ u::{...},
+ w::{...},
+};
+```
+
+
+#### Merging/un-merging imports
+
+An example:
+
+```rust
+// Un-merged
+use a::b;
+use a::c::d;
+
+// Merged
+use a::{b, c::d};
+```
+
+Tools must not merge or un-merge imports by default. They may offer merging or
+un-merging as an option.
diff --git a/src/doc/style-guide/src/principles.md b/src/doc/style-guide/src/principles.md
new file mode 100644
index 000000000..b02b3c047
--- /dev/null
+++ b/src/doc/style-guide/src/principles.md
@@ -0,0 +1,51 @@
+# Guiding principles and rationale
+
+When deciding on style guidelines, the style team tried to be guided by the
+following principles (in rough priority order):
+
+* readability
+ - scan-ability
+ - avoiding misleading formatting
+ - accessibility - readable and editable by users using the the widest
+ variety of hardware, including non-visual accessibility interfaces
+ - readability of code when quoted in rustc error messages
+
+* aesthetics
+ - sense of 'beauty'
+ - consistent with other languages/tools
+
+* specifics
+ - compatibility with version control practices - preserving diffs,
+ merge-friendliness, etc.
+ - preventing right-ward drift
+ - minimising vertical space
+
+* application
+ - ease of manual application
+ - ease of implementation (in Rustfmt, and in other tools/editors/code generators)
+ - internal consistency
+ - simplicity of formatting rules
+
+
+## Overarching guidelines
+
+Prefer block indent over visual indent. E.g.,
+
+```rust
+// Block indent
+a_function_call(
+ foo,
+ bar,
+);
+
+// Visual indent
+a_function_call(foo,
+ bar);
+```
+
+This makes for smaller diffs (e.g., if `a_function_call` is renamed in the above
+example) and less rightward drift.
+
+Lists should have a trailing comma when followed by a newline, see the block
+indent example above. This choice makes moving code (e.g., by copy and paste)
+easier and makes smaller diffs.
diff --git a/src/doc/style-guide/src/statements.md b/src/doc/style-guide/src/statements.md
new file mode 100644
index 000000000..29b48bb1e
--- /dev/null
+++ b/src/doc/style-guide/src/statements.md
@@ -0,0 +1,150 @@
+### Let statements
+
+There should be spaces after the `:` and on both sides of the `=` (if they are
+present). No space before the semi-colon.
+
+```rust
+// A comment.
+let pattern: Type = expr;
+
+let pattern;
+let pattern: Type;
+let pattern = expr;
+```
+
+If possible the declaration should be formatted on a single line. If this is not
+possible, then try splitting after the `=`, if the declaration can fit on two
+lines. The expression should be block indented.
+
+```rust
+let pattern: Type =
+ expr;
+```
+
+If the first line does not fit on a single line, then split after the colon,
+using block indentation. If the type covers multiple lines, even after line-
+breaking after the `:`, then the first line may be placed on the same line as
+the `:`, subject to the [combining rules](https://github.com/rust-lang-nursery/fmt-rfcs/issues/61) (WIP).
+
+
+```rust
+let pattern:
+ Type =
+ expr;
+```
+
+e.g,
+
+```rust
+let Foo {
+ f: abcd,
+ g: qwer,
+}: Foo<Bar> =
+ Foo { f, g };
+
+let (abcd,
+ defg):
+ Baz =
+{ ... }
+```
+
+If the expression covers multiple lines, if the first line of the expression
+fits in the remaining space, it stays on the same line as the `=`, the rest of the
+expression is not indented. If the first line does not fit, then it should start
+on the next lines, and should be block indented. If the expression is a block
+and the type or pattern cover multiple lines, then the opening brace should be
+on a new line and not indented (this provides separation for the interior of the
+block from the type), otherwise the opening brace follows the `=`.
+
+Examples:
+
+```rust
+let foo = Foo {
+ f: abcd,
+ g: qwer,
+};
+
+let foo =
+ ALongName {
+ f: abcd,
+ g: qwer,
+ };
+
+let foo: Type = {
+ an_expression();
+ ...
+};
+
+let foo:
+ ALongType =
+{
+ an_expression();
+ ...
+};
+
+let Foo {
+ f: abcd,
+ g: qwer,
+}: Foo<Bar> = Foo {
+ f: blimblimblim,
+ g: blamblamblam,
+};
+
+let Foo {
+ f: abcd,
+ g: qwer,
+}: Foo<Bar> = foo(
+ blimblimblim,
+ blamblamblam,
+);
+```
+
+
+### Macros in statement position
+
+A macro use in statement position should use parentheses or square brackets as
+delimiters and should be terminated with a semi-colon. There should be no spaces
+between the name, `!`, the delimiters, or the `;`.
+
+```rust
+// A comment.
+a_macro!(...);
+```
+
+
+### Expressions in statement position
+
+There should be no space between the expression and the semi-colon.
+
+```
+<expr>;
+```
+
+All expressions in statement position should be terminated with a semi-colon,
+unless they end with a block or are used as the value for a block.
+
+E.g.,
+
+```rust
+{
+ an_expression();
+ expr_as_value()
+}
+
+return foo();
+
+loop {
+ break;
+}
+```
+
+Use a semi-colon where an expression has void type, even if it could be
+propagated. E.g.,
+
+```rust
+fn foo() { ... }
+
+fn bar() {
+ foo();
+}
+```
diff --git a/src/doc/style-guide/src/types.md b/src/doc/style-guide/src/types.md
new file mode 100644
index 000000000..25861ddab
--- /dev/null
+++ b/src/doc/style-guide/src/types.md
@@ -0,0 +1,58 @@
+## Types and Bounds
+
+### Single line formatting
+
+* `[T]` no spaces
+* `[T; expr]`, e.g., `[u32; 42]`, `[Vec<Foo>; 10 * 2 + foo()]` (space after colon, no spaces around square brackets)
+* `*const T`, `*mut T` (no space after `*`, space before type)
+* `&'a T`, `&T`, `&'a mut T`, `&mut T` (no space after `&`, single spaces separating other words)
+* `unsafe extern "C" fn<'a, 'b, 'c>(T, U, V) -> W` or `fn()` (single spaces around keyowrds and sigils, and after commas, no trailing commas, no spaces around brackets)
+* `!` should be treated like any other type name, `Name`
+* `(A, B, C, D)` (spaces after commas, no spaces around parens, no trailing comma unless it is a one-tuple)
+* `<Baz<T> as SomeTrait>::Foo::Bar` or `Foo::Bar` or `::Foo::Bar` (no spaces around `::` or angle brackets, single spaces around `as`)
+* `Foo::Bar<T, U, V>` (spaces after commas, no trailing comma, no spaces around angle brackets)
+* `T + T + T` (single spaces between types, and `+`).
+* `impl T + T + T` (single spaces between keyword, types, and `+`).
+
+Parentheses used in types should not be surrounded by whitespace, e.g., `(Foo)`
+
+
+### Line breaks
+
+Avoid breaking lines in types where possible. Prefer breaking at outermost scope, e.g., prefer
+
+```rust
+Foo<
+ Bar,
+ Baz<Type1, Type2>,
+>
+```
+
+to
+
+```rust
+Foo<Bar, Baz<
+ Type1,
+ Type2,
+>>
+```
+
+`[T; expr]` may be broken after the `;` if necessary.
+
+Function types may be broken following the rules for function declarations.
+
+Generic types may be broken following the rules for generics.
+
+Types with `+` may be broken after any `+` using block indent and breaking before the `+`. When breaking such a type, all `+`s should be line broken, e.g.,
+
+```rust
+impl Clone
+ + Copy
+ + Debug
+
+Box<
+ Clone
+ + Copy
+ + Debug
+>
+```
diff --git a/src/doc/unstable-book/src/compiler-flags/dylib-lto.md b/src/doc/unstable-book/src/compiler-flags/dylib-lto.md
new file mode 100644
index 000000000..f69ea334f
--- /dev/null
+++ b/src/doc/unstable-book/src/compiler-flags/dylib-lto.md
@@ -0,0 +1,4 @@
+## `dylib-lto`
+
+This option enables using LTO for the `dylib` crate type. This is currently only used for compiling
+`rustc` itself (more specifically, the `librustc_driver` dylib).
diff --git a/src/doc/unstable-book/src/compiler-flags/self-profile-events.md b/src/doc/unstable-book/src/compiler-flags/self-profile-events.md
index 3ce18743b..3e644f786 100644
--- a/src/doc/unstable-book/src/compiler-flags/self-profile-events.md
+++ b/src/doc/unstable-book/src/compiler-flags/self-profile-events.md
@@ -41,7 +41,7 @@ $ rustc -Zself-profile -Zself-profile-events=default,args
- `llvm`
- Adds tracing information about LLVM passes and codegeneration.
- - Disabled by default because this only works when `-Znew-llvm-pass-manager` is enabled.
+ - Disabled by default because this significantly increases the trace file size.
## Event synonyms
diff --git a/src/doc/unstable-book/src/language-features/arbitrary-enum-discriminant.md b/src/doc/unstable-book/src/language-features/arbitrary-enum-discriminant.md
deleted file mode 100644
index e0bb78227..000000000
--- a/src/doc/unstable-book/src/language-features/arbitrary-enum-discriminant.md
+++ /dev/null
@@ -1,37 +0,0 @@
-# `arbitrary_enum_discriminant`
-
-The tracking issue for this feature is: [#60553]
-
-[#60553]: https://github.com/rust-lang/rust/issues/60553
-
-------------------------
-
-The `arbitrary_enum_discriminant` feature permits tuple-like and
-struct-like enum variants with `#[repr(<int-type>)]` to have explicit discriminants.
-
-## Examples
-
-```rust
-#![feature(arbitrary_enum_discriminant)]
-
-#[allow(dead_code)]
-#[repr(u8)]
-enum Enum {
- Unit = 3,
- Tuple(u16) = 2,
- Struct {
- a: u8,
- b: u16,
- } = 1,
-}
-
-impl Enum {
- fn tag(&self) -> u8 {
- unsafe { *(self as *const Self as *const u8) }
- }
-}
-
-assert_eq!(3, Enum::Unit.tag());
-assert_eq!(2, Enum::Tuple(5).tag());
-assert_eq!(1, Enum::Struct{a: 7, b: 11}.tag());
-```
diff --git a/src/doc/unstable-book/src/language-features/asm-sym.md b/src/doc/unstable-book/src/language-features/asm-sym.md
deleted file mode 100644
index 103d91caf..000000000
--- a/src/doc/unstable-book/src/language-features/asm-sym.md
+++ /dev/null
@@ -1,13 +0,0 @@
-# `asm_sym`
-
-The tracking issue for this feature is: [#93333]
-
-[#93333]: https://github.com/rust-lang/rust/issues/93333
-
-------------------------
-
-This feature adds a `sym <path>` operand type to `asm!` and `global_asm!`.
-- `<path>` must refer to a `fn` or `static`.
-- A mangled symbol name referring to the item is substituted into the asm template string.
-- The substituted string does not include any modifiers (e.g. GOT, PLT, relocations, etc).
-- `<path>` is allowed to point to a `#[thread_local]` static, in which case the asm code can combine the symbol with relocations (e.g. `@plt`, `@TPOFF`) to read from thread-local data.
diff --git a/src/doc/unstable-book/src/language-features/half-open-range-patterns-in-slices.md b/src/doc/unstable-book/src/language-features/half-open-range-patterns-in-slices.md
new file mode 100644
index 000000000..56a1a97df
--- /dev/null
+++ b/src/doc/unstable-book/src/language-features/half-open-range-patterns-in-slices.md
@@ -0,0 +1,30 @@
+# `half_open_range_patterns_in_slices`
+
+The tracking issue for this feature is: [#67264]
+It is part of the `exclusive_range_pattern` feature,
+tracked at [#37854].
+
+[#67264]: https://github.com/rust-lang/rust/issues/67264
+[#37854]: https://github.com/rust-lang/rust/issues/37854
+-----
+
+This feature allow using top-level half-open range patterns in slices.
+
+```rust
+#![feature(half_open_range_patterns_in_slices)]
+#![feature(exclusive_range_pattern)]
+
+fn main() {
+ let xs = [13, 1, 5, 2, 3, 1, 21, 8];
+ let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs else { return; };
+}
+```
+
+Note that this feature is not required if the patterns are wrapped between parenthesis.
+
+```rust
+fn main() {
+ let xs = [13, 1];
+ let [(a @ 3..), c] = xs else { return; };
+}
+```
diff --git a/src/doc/unstable-book/src/language-features/half-open-range-patterns.md b/src/doc/unstable-book/src/language-features/half-open-range-patterns.md
deleted file mode 100644
index 3b16dd049..000000000
--- a/src/doc/unstable-book/src/language-features/half-open-range-patterns.md
+++ /dev/null
@@ -1,27 +0,0 @@
-# `half_open_range_patterns`
-
-The tracking issue for this feature is: [#67264]
-It is part of the `#![exclusive_range_pattern]` feature,
-tracked at [#37854].
-
-[#67264]: https://github.com/rust-lang/rust/issues/67264
-[#37854]: https://github.com/rust-lang/rust/issues/37854
------
-
-The `half_open_range_patterns` feature allows RangeTo patterns
-(`..10`) to be used in appropriate pattern matching contexts.
-This requires also enabling the `exclusive_range_pattern` feature.
-
-It also enabled RangeFrom patterns but that has since been
-stabilized.
-
-```rust
-#![feature(half_open_range_patterns)]
-#![feature(exclusive_range_pattern)]
- let x = 5;
- match x {
- ..0 => println!("negative!"), // "RangeTo" pattern. Unstable.
- 0 => println!("zero!"),
- 1.. => println!("positive!"), // "RangeFrom" pattern. Stable.
- }
-```
diff --git a/src/doc/unstable-book/src/language-features/unix-sigpipe.md b/src/doc/unstable-book/src/language-features/unix-sigpipe.md
index aa39b6eb2..7ed6a7de8 100644
--- a/src/doc/unstable-book/src/language-features/unix-sigpipe.md
+++ b/src/doc/unstable-book/src/language-features/unix-sigpipe.md
@@ -36,7 +36,7 @@ hello world
Set the `SIGPIPE` handler to `SIG_IGN` before invoking `fn main()`. This will result in `ErrorKind::BrokenPipe` errors if you program tries to write to a closed pipe. This is normally what you want if you for example write socket servers, socket clients, or pipe peers.
-This is what libstd has done by default since 2014. Omitting `#[unix_sigpipe = "..."]` is the same as having `#[unix_sigpipe = "sig_ign"]`.
+This is what libstd has done by default since 2014. (However, see the note on child processes below.)
### Example
@@ -52,3 +52,11 @@ hello world
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', library/std/src/io/stdio.rs:1016:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
+
+### Note on child processes
+
+When spawning child processes, the legacy Rust behavior if `#[unix_sigpipe]` is not specified is to
+reset `SIGPIPE` to `SIG_DFL`.
+
+If `#[unix_sigpipe = "..."]` is specified, no matter what its value is, the signal disposition of
+`SIGPIPE` is no longer reset. This means that the child inherits the parent's `SIGPIPE` behavior.
diff --git a/src/etc/cat-and-grep.sh b/src/etc/cat-and-grep.sh
index 77dc52a93..238f7f5b6 100755
--- a/src/etc/cat-and-grep.sh
+++ b/src/etc/cat-and-grep.sh
@@ -26,7 +26,7 @@ Options:
-i Case insensitive search.
'
-GREPPER=fgrep
+GREPPER=grep
INVERT=0
GREPFLAGS='q'
while getopts ':vieh' OPTION; do
@@ -39,7 +39,7 @@ while getopts ':vieh' OPTION; do
GREPFLAGS="i$GREPFLAGS"
;;
e)
- GREPPER=egrep
+ GREPFLAGS="E$GREPFLAGS"
;;
h)
echo "$USAGE"
@@ -51,6 +51,12 @@ while getopts ':vieh' OPTION; do
esac
done
+if ! echo "$GREPFLAGS" | grep -q E
+then
+ # use F flag if there is not an E flag
+ GREPFLAGS="F$GREPFLAGS"
+fi
+
shift $((OPTIND - 1))
# use gnu version of tool if available (for bsd)
diff --git a/src/etc/natvis/libcore.natvis b/src/etc/natvis/libcore.natvis
index a4e8a57e4..624d8cc5c 100644
--- a/src/etc/natvis/libcore.natvis
+++ b/src/etc/natvis/libcore.natvis
@@ -154,10 +154,10 @@
</Type>
<Type Name="core::time::Duration">
- <DisplayString>{secs,d}s {nanos,d}ns</DisplayString>
+ <DisplayString>{secs,d}s {nanos.__0,d}ns</DisplayString>
<Expand>
<Item Name="seconds">secs,d</Item>
- <Item Name="nanoseconds">nanos,d</Item>
+ <Item Name="nanoseconds">nanos.__0,d</Item>
</Expand>
</Type>
</AutoVisualizer>
diff --git a/src/etc/rust-gdbgui b/src/etc/rust-gdbgui
index 9744913b6..590e488e6 100755
--- a/src/etc/rust-gdbgui
+++ b/src/etc/rust-gdbgui
@@ -58,7 +58,6 @@ GDB_ARGS="--directory=\"$GDB_PYTHON_MODULE_DIRECTORY\" -iex \"add-auto-load-safe
# Finally we execute gdbgui.
PYTHONPATH="$PYTHONPATH:$GDB_PYTHON_MODULE_DIRECTORY" \
exec ${RUST_GDBGUI} \
- --gdb ${RUST_GDB} \
- --gdb-args "${GDB_ARGS}" \
+ --gdb-cmd "${RUST_GDB} ${GDB_ARGS}" \
"${@}"
diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs
index 175472797..764a6d3aa 100644
--- a/src/librustdoc/clean/auto_trait.rs
+++ b/src/librustdoc/clean/auto_trait.rs
@@ -148,7 +148,7 @@ where
})
.collect();
// We are only interested in case the type *doesn't* implement the Sized trait.
- if !ty.is_sized(tcx.at(rustc_span::DUMMY_SP), param_env) {
+ if !ty.is_sized(tcx, param_env) {
// In case `#![no_core]` is used, `sized_trait` returns nothing.
if let Some(item) = tcx.lang_items().sized_trait().and_then(|sized_trait_did| {
self.generate_for_trait(ty, sized_trait_did, param_env, item_def_id, &f, true)
@@ -475,6 +475,12 @@ where
let mut ty_to_fn: FxHashMap<Type, (PolyTrait, Option<Type>)> = Default::default();
+ // FIXME: This code shares much of the logic found in `clean_ty_generics` and
+ // `simplify::where_clause`. Consider deduplicating it to avoid diverging
+ // implementations.
+ // Further, the code below does not merge (partially re-sugared) bounds like
+ // `Tr<A = T>` & `Tr<B = U>` and it does not render higher-ranked parameters
+ // originating from equality predicates.
for p in clean_where_predicates {
let (orig_p, p) = (p, clean_predicate(p, self.cx));
if p.is_none() {
@@ -549,8 +555,8 @@ where
WherePredicate::RegionPredicate { lifetime, bounds } => {
lifetime_to_bounds.entry(lifetime).or_default().extend(bounds);
}
- WherePredicate::EqPredicate { lhs, rhs } => {
- match lhs {
+ WherePredicate::EqPredicate { lhs, rhs, bound_params } => {
+ match *lhs {
Type::QPath(box QPathData {
ref assoc, ref self_type, ref trait_, ..
}) => {
@@ -585,13 +591,14 @@ where
GenericArgs::AngleBracketed { ref mut bindings, .. } => {
bindings.push(TypeBinding {
assoc: assoc.clone(),
- kind: TypeBindingKind::Equality { term: rhs },
+ kind: TypeBindingKind::Equality { term: *rhs },
});
}
GenericArgs::Parenthesized { .. } => {
existing_predicates.push(WherePredicate::EqPredicate {
lhs: lhs.clone(),
rhs,
+ bound_params,
});
continue; // If something other than a Fn ends up
// with parentheses, leave it alone
diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs
index cc734389e..8b63c3db3 100644
--- a/src/librustdoc/clean/blanket_impl.rs
+++ b/src/librustdoc/clean/blanket_impl.rs
@@ -2,7 +2,6 @@ use crate::rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtE
use rustc_hir as hir;
use rustc_infer::infer::{InferOk, TyCtxtInferExt};
use rustc_infer::traits;
-use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::ToPredicate;
use rustc_span::DUMMY_SP;
@@ -14,122 +13,124 @@ pub(crate) struct BlanketImplFinder<'a, 'tcx> {
impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
pub(crate) fn get_blanket_impls(&mut self, item_def_id: DefId) -> Vec<Item> {
- let param_env = self.cx.tcx.param_env(item_def_id);
- let ty = self.cx.tcx.bound_type_of(item_def_id);
+ let cx = &mut self.cx;
+ let param_env = cx.tcx.param_env(item_def_id);
+ let ty = cx.tcx.bound_type_of(item_def_id);
trace!("get_blanket_impls({:?})", ty);
let mut impls = Vec::new();
- self.cx.with_all_traits(|cx, all_traits| {
- for &trait_def_id in all_traits {
- if !cx.cache.access_levels.is_public(trait_def_id)
- || cx.generated_synthetics.get(&(ty.0, trait_def_id)).is_some()
- {
+ for trait_def_id in cx.tcx.all_traits() {
+ if !cx.cache.effective_visibilities.is_directly_public(trait_def_id)
+ || cx.generated_synthetics.get(&(ty.0, trait_def_id)).is_some()
+ {
+ continue;
+ }
+ // NOTE: doesn't use `for_each_relevant_impl` to avoid looking at anything besides blanket impls
+ let trait_impls = cx.tcx.trait_impls_of(trait_def_id);
+ 'blanket_impls: for &impl_def_id in trait_impls.blanket_impls() {
+ trace!(
+ "get_blanket_impls: Considering impl for trait '{:?}' {:?}",
+ trait_def_id,
+ impl_def_id
+ );
+ let trait_ref = cx.tcx.bound_impl_trait_ref(impl_def_id).unwrap();
+ if !matches!(trait_ref.0.self_ty().kind(), ty::Param(_)) {
continue;
}
- // NOTE: doesn't use `for_each_relevant_impl` to avoid looking at anything besides blanket impls
- let trait_impls = cx.tcx.trait_impls_of(trait_def_id);
- for &impl_def_id in trait_impls.blanket_impls() {
- trace!(
- "get_blanket_impls: Considering impl for trait '{:?}' {:?}",
- trait_def_id,
- impl_def_id
- );
- let trait_ref = cx.tcx.bound_impl_trait_ref(impl_def_id).unwrap();
- let is_param = matches!(trait_ref.0.self_ty().kind(), ty::Param(_));
- let may_apply = is_param && cx.tcx.infer_ctxt().enter(|infcx| {
- let substs = infcx.fresh_substs_for_item(DUMMY_SP, item_def_id);
- let ty = ty.subst(infcx.tcx, substs);
- let param_env = EarlyBinder(param_env).subst(infcx.tcx, substs);
+ let infcx = cx.tcx.infer_ctxt().build();
+ let substs = infcx.fresh_substs_for_item(DUMMY_SP, item_def_id);
+ let impl_ty = ty.subst(infcx.tcx, substs);
+ let param_env = EarlyBinder(param_env).subst(infcx.tcx, substs);
- let impl_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id);
- let trait_ref = trait_ref.subst(infcx.tcx, impl_substs);
+ let impl_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id);
+ let impl_trait_ref = trait_ref.subst(infcx.tcx, impl_substs);
- // Require the type the impl is implemented on to match
- // our type, and ignore the impl if there was a mismatch.
- let cause = traits::ObligationCause::dummy();
- let eq_result = infcx.at(&cause, param_env).eq(trait_ref.self_ty(), ty);
- if let Ok(InferOk { value: (), obligations }) = eq_result {
- // FIXME(eddyb) ignoring `obligations` might cause false positives.
- drop(obligations);
+ // Require the type the impl is implemented on to match
+ // our type, and ignore the impl if there was a mismatch.
+ let cause = traits::ObligationCause::dummy();
+ let Ok(eq_result) = infcx.at(&cause, param_env).eq(impl_trait_ref.self_ty(), impl_ty) else {
+ continue
+ };
+ let InferOk { value: (), obligations } = eq_result;
+ // FIXME(eddyb) ignoring `obligations` might cause false positives.
+ drop(obligations);
- trace!(
- "invoking predicate_may_hold: param_env={:?}, trait_ref={:?}, ty={:?}",
- param_env,
- trait_ref,
- ty
- );
- let predicates = cx
- .tcx
- .predicates_of(impl_def_id)
- .instantiate(cx.tcx, impl_substs)
- .predicates
- .into_iter()
- .chain(Some(
- ty::Binder::dummy(trait_ref)
- .to_poly_trait_predicate()
- .map_bound(ty::PredicateKind::Trait)
- .to_predicate(infcx.tcx),
- ));
- for predicate in predicates {
- debug!("testing predicate {:?}", predicate);
- let obligation = traits::Obligation::new(
- traits::ObligationCause::dummy(),
- param_env,
- predicate,
- );
- match infcx.evaluate_obligation(&obligation) {
- Ok(eval_result) if eval_result.may_apply() => {}
- Err(traits::OverflowError::Canonical) => {}
- Err(traits::OverflowError::ErrorReporting) => {}
- _ => {
- return false;
- }
- }
- }
- true
- } else {
- false
- }
- });
- debug!(
- "get_blanket_impls: found applicable impl: {} for trait_ref={:?}, ty={:?}",
- may_apply, trait_ref, ty
+ trace!(
+ "invoking predicate_may_hold: param_env={:?}, impl_trait_ref={:?}, impl_ty={:?}",
+ param_env,
+ impl_trait_ref,
+ impl_ty
+ );
+ let predicates = cx
+ .tcx
+ .predicates_of(impl_def_id)
+ .instantiate(cx.tcx, impl_substs)
+ .predicates
+ .into_iter()
+ .chain(Some(
+ ty::Binder::dummy(impl_trait_ref)
+ .to_poly_trait_predicate()
+ .map_bound(ty::PredicateKind::Trait)
+ .to_predicate(infcx.tcx),
+ ));
+ for predicate in predicates {
+ debug!("testing predicate {:?}", predicate);
+ let obligation = traits::Obligation::new(
+ traits::ObligationCause::dummy(),
+ param_env,
+ predicate,
);
- if !may_apply {
- continue;
+ match infcx.evaluate_obligation(&obligation) {
+ Ok(eval_result) if eval_result.may_apply() => {}
+ Err(traits::OverflowError::Canonical) => {}
+ Err(traits::OverflowError::ErrorReporting) => {}
+ _ => continue 'blanket_impls,
}
+ }
+ debug!(
+ "get_blanket_impls: found applicable impl for trait_ref={:?}, ty={:?}",
+ trait_ref, ty
+ );
- cx.generated_synthetics.insert((ty.0, trait_def_id));
+ cx.generated_synthetics.insert((ty.0, trait_def_id));
- impls.push(Item {
- name: None,
- attrs: Default::default(),
- visibility: Inherited,
- item_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
- kind: Box::new(ImplItem(Box::new(Impl {
- unsafety: hir::Unsafety::Normal,
- generics: clean_ty_generics(
- cx,
- cx.tcx.generics_of(impl_def_id),
- cx.tcx.explicit_predicates_of(impl_def_id),
- ),
- // FIXME(eddyb) compute both `trait_` and `for_` from
- // the post-inference `trait_ref`, as it's more accurate.
- trait_: Some(clean_trait_ref_with_bindings(cx, trait_ref.0, ThinVec::new())),
- for_: clean_middle_ty(ty.0, cx, None),
- items: cx.tcx
- .associated_items(impl_def_id)
- .in_definition_order()
- .map(|x| clean_middle_assoc_item(x, cx))
- .collect::<Vec<_>>(),
- polarity: ty::ImplPolarity::Positive,
- kind: ImplKind::Blanket(Box::new(clean_middle_ty(trait_ref.0.self_ty(), cx, None))),
- }))),
- cfg: None,
- });
- }
+ impls.push(Item {
+ name: None,
+ attrs: Default::default(),
+ visibility: Inherited,
+ item_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
+ kind: Box::new(ImplItem(Box::new(Impl {
+ unsafety: hir::Unsafety::Normal,
+ generics: clean_ty_generics(
+ cx,
+ cx.tcx.generics_of(impl_def_id),
+ cx.tcx.explicit_predicates_of(impl_def_id),
+ ),
+ // FIXME(eddyb) compute both `trait_` and `for_` from
+ // the post-inference `trait_ref`, as it's more accurate.
+ trait_: Some(clean_trait_ref_with_bindings(
+ cx,
+ trait_ref.0,
+ ThinVec::new(),
+ )),
+ for_: clean_middle_ty(ty.0, cx, None),
+ items: cx
+ .tcx
+ .associated_items(impl_def_id)
+ .in_definition_order()
+ .map(|x| clean_middle_assoc_item(x, cx))
+ .collect::<Vec<_>>(),
+ polarity: ty::ImplPolarity::Positive,
+ kind: ImplKind::Blanket(Box::new(clean_middle_ty(
+ trait_ref.0.self_ty(),
+ cx,
+ None,
+ ))),
+ }))),
+ cfg: None,
+ });
}
- });
+ }
impls
}
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs
index df0e9f7cc..4e2031a91 100644
--- a/src/librustdoc/clean/inline.rs
+++ b/src/librustdoc/clean/inline.rs
@@ -55,12 +55,39 @@ pub(crate) fn try_inline(
let mut ret = Vec::new();
debug!("attrs={:?}", attrs);
- let attrs_clone = attrs;
+
+ let attrs_without_docs = attrs.map(|attrs| {
+ attrs.into_iter().filter(|a| a.doc_str().is_none()).cloned().collect::<Vec<_>>()
+ });
+ // We need this ugly code because:
+ //
+ // ```
+ // attrs_without_docs.map(|a| a.as_slice())
+ // ```
+ //
+ // will fail because it returns a temporary slice and:
+ //
+ // ```
+ // attrs_without_docs.map(|s| {
+ // vec = s.as_slice();
+ // vec
+ // })
+ // ```
+ //
+ // will fail because we're moving an uninitialized variable into a closure.
+ let vec;
+ let attrs_without_docs = match attrs_without_docs {
+ Some(s) => {
+ vec = s;
+ Some(vec.as_slice())
+ }
+ None => None,
+ };
let kind = match res {
Res::Def(DefKind::Trait, did) => {
record_extern_fqn(cx, did, ItemType::Trait);
- build_impls(cx, Some(parent_module), did, attrs, &mut ret);
+ build_impls(cx, Some(parent_module), did, attrs_without_docs, &mut ret);
clean::TraitItem(Box::new(build_external_trait(cx, did)))
}
Res::Def(DefKind::Fn, did) => {
@@ -69,27 +96,27 @@ pub(crate) fn try_inline(
}
Res::Def(DefKind::Struct, did) => {
record_extern_fqn(cx, did, ItemType::Struct);
- build_impls(cx, Some(parent_module), did, attrs, &mut ret);
+ build_impls(cx, Some(parent_module), did, attrs_without_docs, &mut ret);
clean::StructItem(build_struct(cx, did))
}
Res::Def(DefKind::Union, did) => {
record_extern_fqn(cx, did, ItemType::Union);
- build_impls(cx, Some(parent_module), did, attrs, &mut ret);
+ build_impls(cx, Some(parent_module), did, attrs_without_docs, &mut ret);
clean::UnionItem(build_union(cx, did))
}
Res::Def(DefKind::TyAlias, did) => {
record_extern_fqn(cx, did, ItemType::Typedef);
- build_impls(cx, Some(parent_module), did, attrs, &mut ret);
+ build_impls(cx, Some(parent_module), did, attrs_without_docs, &mut ret);
clean::TypedefItem(build_type_alias(cx, did))
}
Res::Def(DefKind::Enum, did) => {
record_extern_fqn(cx, did, ItemType::Enum);
- build_impls(cx, Some(parent_module), did, attrs, &mut ret);
+ build_impls(cx, Some(parent_module), did, attrs_without_docs, &mut ret);
clean::EnumItem(build_enum(cx, did))
}
Res::Def(DefKind::ForeignTy, did) => {
record_extern_fqn(cx, did, ItemType::ForeignType);
- build_impls(cx, Some(parent_module), did, attrs, &mut ret);
+ build_impls(cx, Some(parent_module), did, attrs_without_docs, &mut ret);
clean::ForeignTypeItem
}
// Never inline enum variants but leave them shown as re-exports.
@@ -123,7 +150,7 @@ pub(crate) fn try_inline(
_ => return None,
};
- let (attrs, cfg) = merge_attrs(cx, Some(parent_module), load_attrs(cx, did), attrs_clone);
+ let (attrs, cfg) = merge_attrs(cx, Some(parent_module), load_attrs(cx, did), attrs);
cx.inlined.insert(did.into());
let mut item = clean::Item::from_def_id_and_attrs_and_parts(
did,
@@ -362,7 +389,7 @@ pub(crate) fn build_impl(
if !did.is_local() {
if let Some(traitref) = associated_trait {
let did = traitref.def_id;
- if !cx.cache.access_levels.is_public(did) {
+ if !cx.cache.effective_visibilities.is_directly_public(did) {
return;
}
@@ -391,7 +418,7 @@ pub(crate) fn build_impl(
// reachable in rustdoc generated documentation
if !did.is_local() {
if let Some(did) = for_.def_id(&cx.cache) {
- if !cx.cache.access_levels.is_public(did) {
+ if !cx.cache.effective_visibilities.is_directly_public(did) {
return;
}
@@ -425,7 +452,7 @@ pub(crate) fn build_impl(
let assoc_kind = match item.kind {
hir::ImplItemKind::Const(..) => ty::AssocKind::Const,
hir::ImplItemKind::Fn(..) => ty::AssocKind::Fn,
- hir::ImplItemKind::TyAlias(..) => ty::AssocKind::Type,
+ hir::ImplItemKind::Type(..) => ty::AssocKind::Type,
};
let trait_item = tcx
.associated_items(associated_trait.def_id)
@@ -733,10 +760,6 @@ pub(crate) fn record_extern_trait(cx: &mut DocContext<'_>, did: DefId) {
debug!("record_extern_trait: {:?}", did);
let trait_ = build_external_trait(cx, did);
- let trait_ = clean::TraitWithExtraInfo {
- trait_,
- is_notable: clean::utils::has_doc_flag(cx.tcx, did, sym::notable_trait),
- };
cx.external_traits.borrow_mut().insert(did, trait_);
cx.active_extern_traits.remove(&did);
}
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index c8875c272..64a18757b 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -17,16 +17,16 @@ use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::PredicateOrigin;
+use rustc_hir_analysis::hir_ty_to_ty;
use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
use rustc_middle::middle::resolve_lifetime as rl;
use rustc_middle::ty::fold::TypeFolder;
-use rustc_middle::ty::subst::{InternalSubsts, Subst};
-use rustc_middle::ty::{self, AdtKind, DefIdTree, EarlyBinder, Lift, Ty, TyCtxt};
+use rustc_middle::ty::InternalSubsts;
+use rustc_middle::ty::{self, AdtKind, DefIdTree, EarlyBinder, Ty, TyCtxt};
use rustc_middle::{bug, span_bug};
use rustc_span::hygiene::{AstPass, MacroKind};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{self, ExpnKind};
-use rustc_typeck::hir_ty_to_ty;
use std::assert_matches::assert_matches;
use std::collections::hash_map::Entry;
@@ -176,8 +176,6 @@ fn clean_poly_trait_ref_with_bindings<'tcx>(
poly_trait_ref: ty::PolyTraitRef<'tcx>,
bindings: ThinVec<TypeBinding>,
) -> GenericBound {
- let poly_trait_ref = poly_trait_ref.lift_to_tcx(cx.tcx).unwrap();
-
// collect any late bound regions
let late_bound_regions: Vec<_> = cx
.tcx
@@ -292,8 +290,9 @@ fn clean_where_predicate<'tcx>(
},
hir::WherePredicate::EqPredicate(ref wrp) => WherePredicate::EqPredicate {
- lhs: clean_ty(wrp.lhs_ty, cx),
- rhs: clean_ty(wrp.rhs_ty, cx).into(),
+ lhs: Box::new(clean_ty(wrp.lhs_ty, cx)),
+ rhs: Box::new(clean_ty(wrp.rhs_ty, cx).into()),
+ bound_params: Vec::new(),
},
})
}
@@ -309,7 +308,9 @@ pub(crate) fn clean_predicate<'tcx>(
}
ty::PredicateKind::RegionOutlives(pred) => clean_region_outlives_predicate(pred),
ty::PredicateKind::TypeOutlives(pred) => clean_type_outlives_predicate(pred, cx),
- ty::PredicateKind::Projection(pred) => Some(clean_projection_predicate(pred, cx)),
+ ty::PredicateKind::Projection(pred) => {
+ Some(clean_projection_predicate(bound_predicate.rebind(pred), cx))
+ }
ty::PredicateKind::ConstEvaluatable(..) => None,
ty::PredicateKind::WellFormed(..) => None,
@@ -387,13 +388,25 @@ fn clean_hir_term<'tcx>(term: &hir::Term<'tcx>, cx: &mut DocContext<'tcx>) -> Te
}
fn clean_projection_predicate<'tcx>(
- pred: ty::ProjectionPredicate<'tcx>,
+ pred: ty::Binder<'tcx, ty::ProjectionPredicate<'tcx>>,
cx: &mut DocContext<'tcx>,
) -> WherePredicate {
- let ty::ProjectionPredicate { projection_ty, term } = pred;
+ let late_bound_regions = cx
+ .tcx
+ .collect_referenced_late_bound_regions(&pred)
+ .into_iter()
+ .filter_map(|br| match br {
+ ty::BrNamed(_, name) if name != kw::UnderscoreLifetime => Some(Lifetime(name)),
+ _ => None,
+ })
+ .collect();
+
+ let ty::ProjectionPredicate { projection_ty, term } = pred.skip_binder();
+
WherePredicate::EqPredicate {
- lhs: clean_projection(projection_ty, cx, None),
- rhs: clean_middle_term(term, cx),
+ lhs: Box::new(clean_projection(projection_ty, cx, None)),
+ rhs: Box::new(clean_middle_term(term, cx)),
+ bound_params: late_bound_regions,
}
}
@@ -402,8 +415,17 @@ fn clean_projection<'tcx>(
cx: &mut DocContext<'tcx>,
def_id: Option<DefId>,
) -> Type {
- let lifted = ty.lift_to_tcx(cx.tcx).unwrap();
- let trait_ = clean_trait_ref_with_bindings(cx, lifted.trait_ref(cx.tcx), ThinVec::new());
+ if cx.tcx.def_kind(ty.item_def_id) == DefKind::ImplTraitPlaceholder {
+ let bounds = cx
+ .tcx
+ .explicit_item_bounds(ty.item_def_id)
+ .iter()
+ .map(|(bound, _)| EarlyBinder(*bound).subst(cx.tcx, ty.substs))
+ .collect::<Vec<_>>();
+ return clean_middle_opaque_bounds(cx, bounds);
+ }
+
+ let trait_ = clean_trait_ref_with_bindings(cx, ty.trait_ref(cx.tcx), ThinVec::new());
let self_type = clean_middle_ty(ty.self_ty(), cx, None);
let self_def_id = if let Some(def_id) = def_id {
cx.tcx.opt_parent(def_id).or(Some(def_id))
@@ -632,7 +654,7 @@ fn clean_ty_generics<'tcx>(
let mut impl_trait = BTreeMap::<ImplTraitParam, Vec<GenericBound>>::default();
// Bounds in the type_params and lifetimes fields are repeated in the
- // predicates field (see rustc_typeck::collect::ty_generics), so remove
+ // predicates field (see rustc_hir_analysis::collect::ty_generics), so remove
// them.
let stripped_params = gens
.params
@@ -655,8 +677,9 @@ fn clean_ty_generics<'tcx>(
})
.collect::<Vec<GenericParamDef>>();
- // param index -> [(DefId of trait, associated type name and generics, type)]
- let mut impl_trait_proj = FxHashMap::<u32, Vec<(DefId, PathSegment, Ty<'_>)>>::default();
+ // param index -> [(trait DefId, associated type name & generics, type, higher-ranked params)]
+ let mut impl_trait_proj =
+ FxHashMap::<u32, Vec<(DefId, PathSegment, Ty<'_>, Vec<GenericParamDef>)>>::default();
let where_predicates = preds
.predicates
@@ -715,6 +738,14 @@ fn clean_ty_generics<'tcx>(
trait_did,
name,
rhs.ty().unwrap(),
+ p.get_bound_params()
+ .into_iter()
+ .flatten()
+ .map(|param| GenericParamDef {
+ name: param.0,
+ kind: GenericParamDefKind::Lifetime { outlives: Vec::new() },
+ })
+ .collect(),
));
}
@@ -730,15 +761,19 @@ fn clean_ty_generics<'tcx>(
// Move trait bounds to the front.
bounds.sort_by_key(|b| !matches!(b, GenericBound::TraitBound(..)));
- if let crate::core::ImplTraitParam::ParamIndex(idx) = param {
- if let Some(proj) = impl_trait_proj.remove(&idx) {
- for (trait_did, name, rhs) in proj {
- let rhs = clean_middle_ty(rhs, cx, None);
- simplify::merge_bounds(cx, &mut bounds, trait_did, name, &Term::Type(rhs));
- }
+ let crate::core::ImplTraitParam::ParamIndex(idx) = param else { unreachable!() };
+ if let Some(proj) = impl_trait_proj.remove(&idx) {
+ for (trait_did, name, rhs, bound_params) in proj {
+ let rhs = clean_middle_ty(rhs, cx, None);
+ simplify::merge_bounds(
+ cx,
+ &mut bounds,
+ bound_params,
+ trait_did,
+ name,
+ &Term::Type(rhs),
+ );
}
- } else {
- unreachable!();
}
cx.impl_trait_bounds.insert(param, bounds);
@@ -749,31 +784,36 @@ fn clean_ty_generics<'tcx>(
let mut where_predicates =
where_predicates.into_iter().flat_map(|p| clean_predicate(*p, cx)).collect::<Vec<_>>();
- // Type parameters have a Sized bound by default unless removed with
- // ?Sized. Scan through the predicates and mark any type parameter with
- // a Sized bound, removing the bounds as we find them.
+ // In the surface language, all type parameters except `Self` have an
+ // implicit `Sized` bound unless removed with `?Sized`.
+ // However, in the list of where-predicates below, `Sized` appears like a
+ // normal bound: It's either present (the type is sized) or
+ // absent (the type is unsized) but never *maybe* (i.e. `?Sized`).
+ //
+ // This is unsuitable for rendering.
+ // Thus, as a first step remove all `Sized` bounds that should be implicit.
//
- // Note that associated types also have a sized bound by default, but we
+ // Note that associated types also have an implicit `Sized` bound but we
// don't actually know the set of associated types right here so that's
- // handled in cleaning associated types
+ // handled when cleaning associated types.
let mut sized_params = FxHashSet::default();
- where_predicates.retain(|pred| match *pred {
- WherePredicate::BoundPredicate { ty: Generic(ref g), ref bounds, .. } => {
- if bounds.iter().any(|b| b.is_sized_bound(cx)) {
- sized_params.insert(*g);
- false
- } else {
- true
- }
+ where_predicates.retain(|pred| {
+ if let WherePredicate::BoundPredicate { ty: Generic(g), bounds, .. } = pred
+ && *g != kw::SelfUpper
+ && bounds.iter().any(|b| b.is_sized_bound(cx))
+ {
+ sized_params.insert(*g);
+ false
+ } else {
+ true
}
- _ => true,
});
- // Run through the type parameters again and insert a ?Sized
- // unbound for any we didn't find to be Sized.
+ // As a final step, go through the type parameters again and insert a
+ // `?Sized` bound for each one we didn't find to be `Sized`.
for tp in &stripped_params {
- if matches!(tp.kind, types::GenericParamDefKind::Type { .. })
- && !sized_params.contains(&tp.name)
+ if let types::GenericParamDefKind::Type { .. } = tp.kind
+ && !sized_params.contains(&tp.name)
{
where_predicates.push(WherePredicate::BoundPredicate {
ty: Type::Generic(tp.name),
@@ -1002,7 +1042,7 @@ fn clean_poly_trait_ref<'tcx>(
}
fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext<'tcx>) -> Item {
- let local_did = trait_item.def_id.to_def_id();
+ let local_did = trait_item.owner_id.to_def_id();
cx.with_param_env(local_did, |cx| {
let inner = match trait_item.kind {
hir::TraitItemKind::Const(ty, Some(default)) => AssocConstItem(
@@ -1054,7 +1094,7 @@ pub(crate) fn clean_impl_item<'tcx>(
impl_: &hir::ImplItem<'tcx>,
cx: &mut DocContext<'tcx>,
) -> Item {
- let local_did = impl_.def_id.to_def_id();
+ let local_did = impl_.owner_id.to_def_id();
cx.with_param_env(local_did, |cx| {
let inner = match impl_.kind {
hir::ImplItemKind::Const(ty, expr) => {
@@ -1063,10 +1103,10 @@ pub(crate) fn clean_impl_item<'tcx>(
}
hir::ImplItemKind::Fn(ref sig, body) => {
let m = clean_function(cx, sig, impl_.generics, body);
- let defaultness = cx.tcx.impl_defaultness(impl_.def_id);
+ let defaultness = cx.tcx.impl_defaultness(impl_.owner_id);
MethodItem(m, Some(defaultness))
}
- hir::ImplItemKind::TyAlias(hir_ty) => {
+ hir::ImplItemKind::Type(hir_ty) => {
let type_ = clean_ty(hir_ty, cx);
let generics = clean_generics(impl_.generics, cx);
let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, hir_ty), cx, None);
@@ -1080,7 +1120,7 @@ pub(crate) fn clean_impl_item<'tcx>(
let mut what_rustc_thinks =
Item::from_def_id_and_parts(local_did, Some(impl_.ident.name), inner, cx);
- let impl_ref = cx.tcx.impl_trait_ref(cx.tcx.local_parent(impl_.def_id));
+ let impl_ref = cx.tcx.impl_trait_ref(cx.tcx.local_parent(impl_.owner_id.def_id));
// Trait impl items always inherit the impl's visibility --
// we don't want to show `pub`.
@@ -1177,11 +1217,18 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
if let ty::TraitContainer = assoc_item.container {
let bounds = tcx.explicit_item_bounds(assoc_item.def_id);
- let predicates = ty::GenericPredicates { parent: None, predicates: bounds };
- let mut generics =
- clean_ty_generics(cx, tcx.generics_of(assoc_item.def_id), predicates);
- // Filter out the bounds that are (likely?) directly attached to the associated type,
- // as opposed to being located in the where clause.
+ let predicates = tcx.explicit_predicates_of(assoc_item.def_id).predicates;
+ let predicates =
+ tcx.arena.alloc_from_iter(bounds.into_iter().chain(predicates).copied());
+ let mut generics = clean_ty_generics(
+ cx,
+ tcx.generics_of(assoc_item.def_id),
+ ty::GenericPredicates { parent: None, predicates },
+ );
+ // Move bounds that are (likely) directly attached to the associated type
+ // from the where clause to the associated type.
+ // There is no guarantee that this is what the user actually wrote but we have
+ // no way of knowing.
let mut bounds = generics
.where_predicates
.drain_filter(|pred| match *pred {
@@ -1239,6 +1286,24 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
}
None => bounds.push(GenericBound::maybe_sized(cx)),
}
+ // Move bounds that are (likely) directly attached to the parameters of the
+ // (generic) associated type from the where clause to the respective parameter.
+ // There is no guarantee that this is what the user actually wrote but we have
+ // no way of knowing.
+ let mut where_predicates = Vec::new();
+ for mut pred in generics.where_predicates {
+ if let WherePredicate::BoundPredicate { ty: Generic(arg), bounds, .. } = &mut pred
+ && let Some(GenericParamDef {
+ kind: GenericParamDefKind::Type { bounds: param_bounds, .. },
+ ..
+ }) = generics.params.iter_mut().find(|param| &param.name == arg)
+ {
+ param_bounds.extend(mem::take(bounds));
+ } else {
+ where_predicates.push(pred);
+ }
+ }
+ generics.where_predicates = where_predicates;
if tcx.impl_defaultness(assoc_item.def_id).has_value() {
AssocTypeItem(
@@ -1325,7 +1390,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
segments: trait_segments.iter().map(|x| clean_path_segment(x, cx)).collect(),
};
register_res(cx, trait_.res);
- let self_def_id = DefId::local(qself.hir_id.owner.local_def_index);
+ let self_def_id = DefId::local(qself.hir_id.owner.def_id.local_def_index);
let self_type = clean_ty(qself, cx);
let should_show_cast = compute_should_show_cast(Some(self_def_id), &trait_, &self_type);
Type::QPath(Box::new(QPathData {
@@ -1366,7 +1431,7 @@ fn maybe_expand_private_type_alias<'tcx>(
let Res::Def(DefKind::TyAlias, def_id) = path.res else { return None };
// Substitute private type aliases
let def_id = def_id.as_local()?;
- let alias = if !cx.cache.access_levels.is_exported(def_id.to_def_id()) {
+ let alias = if !cx.cache.effective_visibilities.is_exported(def_id.to_def_id()) {
&cx.tcx.hir().expect_item(def_id).kind
} else {
return None;
@@ -1480,7 +1545,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
// as we currently do not supply the parent generics to anonymous constants
// but do allow `ConstKind::Param`.
//
- // `const_eval_poly` tries to to first substitute generic parameters which
+ // `const_eval_poly` tries to first substitute generic parameters which
// results in an ICE while manually constructing the constant and using `eval`
// does nothing for `ConstKind::Param`.
let ct = ty::Const::from_anon_const(cx.tcx, def_id);
@@ -1509,13 +1574,12 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
}
TyKind::BareFn(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))),
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
- TyKind::Infer | TyKind::Err => Infer,
- TyKind::Typeof(..) => panic!("unimplemented type {:?}", ty.kind),
+ TyKind::Infer | TyKind::Err | TyKind::Typeof(..) => Infer,
}
}
/// Returns `None` if the type could not be normalized
-fn normalize<'tcx>(cx: &mut DocContext<'tcx>, ty: Ty<'_>) -> Option<Ty<'tcx>> {
+fn normalize<'tcx>(cx: &mut DocContext<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
// HACK: low-churn fix for #79459 while we wait for a trait normalization fix
if !cx.tcx.sess.opts.unstable_opts.normalize_docs {
return None;
@@ -1526,13 +1590,11 @@ fn normalize<'tcx>(cx: &mut DocContext<'tcx>, ty: Ty<'_>) -> Option<Ty<'tcx>> {
use rustc_middle::traits::ObligationCause;
// Try to normalize `<X as Y>::T` to a type
- let lifted = ty.lift_to_tcx(cx.tcx).unwrap();
- let normalized = cx.tcx.infer_ctxt().enter(|infcx| {
- infcx
- .at(&ObligationCause::dummy(), cx.param_env)
- .normalize(lifted)
- .map(|resolved| infcx.resolve_vars_if_possible(resolved.value))
- });
+ let infcx = cx.tcx.infer_ctxt().build();
+ let normalized = infcx
+ .at(&ObligationCause::dummy(), cx.param_env)
+ .normalize(ty)
+ .map(|resolved| infcx.resolve_vars_if_possible(resolved.value));
match normalized {
Ok(normalized_value) => {
debug!("normalized {:?} to {:?}", ty, normalized_value);
@@ -1546,12 +1608,12 @@ fn normalize<'tcx>(cx: &mut DocContext<'tcx>, ty: Ty<'_>) -> Option<Ty<'tcx>> {
}
pub(crate) fn clean_middle_ty<'tcx>(
- this: Ty<'tcx>,
+ ty: Ty<'tcx>,
cx: &mut DocContext<'tcx>,
def_id: Option<DefId>,
) -> Type {
- trace!("cleaning type: {:?}", this);
- let ty = normalize(cx, this).unwrap_or(this);
+ trace!("cleaning type: {:?}", ty);
+ let ty = normalize(cx, ty).unwrap_or(ty);
match *ty.kind() {
ty::Never => Primitive(PrimitiveType::Never),
ty::Bool => Primitive(PrimitiveType::Bool),
@@ -1561,8 +1623,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
ty::Float(float_ty) => Primitive(float_ty.into()),
ty::Str => Primitive(PrimitiveType::Str),
ty::Slice(ty) => Slice(Box::new(clean_middle_ty(ty, cx, None))),
- ty::Array(ty, n) => {
- let mut n = cx.tcx.lift(n).expect("array lift failed");
+ ty::Array(ty, mut n) => {
n = n.eval(cx.tcx, ty::ParamEnv::reveal_all());
let n = print_const(cx, n);
Array(Box::new(clean_middle_ty(ty, cx, None)), n)
@@ -1574,7 +1635,6 @@ pub(crate) fn clean_middle_ty<'tcx>(
type_: Box::new(clean_middle_ty(ty, cx, None)),
},
ty::FnDef(..) | ty::FnPtr(_) => {
- let ty = cx.tcx.lift(this).expect("FnPtr lift failed");
let sig = ty.fn_sig(cx.tcx);
let decl = clean_fn_decl_from_did_and_sig(cx, None, sig);
BareFunction(Box::new(BareFunctionDecl {
@@ -1608,7 +1668,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
let did = obj
.principal_def_id()
.or_else(|| dids.next())
- .unwrap_or_else(|| panic!("found trait object `{:?}` with no traits?", this));
+ .unwrap_or_else(|| panic!("found trait object `{:?}` with no traits?", ty));
let substs = match obj.principal() {
Some(principal) => principal.skip_binder().substs,
// marker traits have no substs.
@@ -1632,8 +1692,6 @@ pub(crate) fn clean_middle_ty<'tcx>(
.map(|pb| TypeBinding {
assoc: projection_to_path_segment(
pb.skip_binder()
- .lift_to_tcx(cx.tcx)
- .unwrap()
// HACK(compiler-errors): Doesn't actually matter what self
// type we put here, because we're only using the GAT's substs.
.with_self_ty(cx.tcx, cx.tcx.types.self_param)
@@ -1666,66 +1724,13 @@ pub(crate) fn clean_middle_ty<'tcx>(
ty::Opaque(def_id, substs) => {
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
// by looking up the bounds associated with the def_id.
- let substs = cx.tcx.lift(substs).expect("Opaque lift failed");
let bounds = cx
.tcx
.explicit_item_bounds(def_id)
.iter()
.map(|(bound, _)| EarlyBinder(*bound).subst(cx.tcx, substs))
.collect::<Vec<_>>();
- let mut regions = vec![];
- let mut has_sized = false;
- let mut bounds = bounds
- .iter()
- .filter_map(|bound| {
- let bound_predicate = bound.kind();
- let trait_ref = match bound_predicate.skip_binder() {
- ty::PredicateKind::Trait(tr) => bound_predicate.rebind(tr.trait_ref),
- ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_ty, reg)) => {
- if let Some(r) = clean_middle_region(reg) {
- regions.push(GenericBound::Outlives(r));
- }
- return None;
- }
- _ => return None,
- };
-
- if let Some(sized) = cx.tcx.lang_items().sized_trait() {
- if trait_ref.def_id() == sized {
- has_sized = true;
- return None;
- }
- }
-
- let bindings: ThinVec<_> = bounds
- .iter()
- .filter_map(|bound| {
- if let ty::PredicateKind::Projection(proj) = bound.kind().skip_binder()
- {
- if proj.projection_ty.trait_ref(cx.tcx) == trait_ref.skip_binder() {
- Some(TypeBinding {
- assoc: projection_to_path_segment(proj.projection_ty, cx),
- kind: TypeBindingKind::Equality {
- term: clean_middle_term(proj.term, cx),
- },
- })
- } else {
- None
- }
- } else {
- None
- }
- })
- .collect();
-
- Some(clean_poly_trait_ref_with_bindings(cx, trait_ref, bindings))
- })
- .collect::<Vec<_>>();
- bounds.extend(regions);
- if !has_sized && !bounds.is_empty() {
- bounds.insert(0, GenericBound::maybe_sized(cx));
- }
- ImplTrait(bounds)
+ clean_middle_opaque_bounds(cx, bounds)
}
ty::Closure(..) => panic!("Closure"),
@@ -1738,6 +1743,64 @@ pub(crate) fn clean_middle_ty<'tcx>(
}
}
+fn clean_middle_opaque_bounds<'tcx>(
+ cx: &mut DocContext<'tcx>,
+ bounds: Vec<ty::Predicate<'tcx>>,
+) -> Type {
+ let mut regions = vec![];
+ let mut has_sized = false;
+ let mut bounds = bounds
+ .iter()
+ .filter_map(|bound| {
+ let bound_predicate = bound.kind();
+ let trait_ref = match bound_predicate.skip_binder() {
+ ty::PredicateKind::Trait(tr) => bound_predicate.rebind(tr.trait_ref),
+ ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(_ty, reg)) => {
+ if let Some(r) = clean_middle_region(reg) {
+ regions.push(GenericBound::Outlives(r));
+ }
+ return None;
+ }
+ _ => return None,
+ };
+
+ if let Some(sized) = cx.tcx.lang_items().sized_trait() {
+ if trait_ref.def_id() == sized {
+ has_sized = true;
+ return None;
+ }
+ }
+
+ let bindings: ThinVec<_> = bounds
+ .iter()
+ .filter_map(|bound| {
+ if let ty::PredicateKind::Projection(proj) = bound.kind().skip_binder() {
+ if proj.projection_ty.trait_ref(cx.tcx) == trait_ref.skip_binder() {
+ Some(TypeBinding {
+ assoc: projection_to_path_segment(proj.projection_ty, cx),
+ kind: TypeBindingKind::Equality {
+ term: clean_middle_term(proj.term, cx),
+ },
+ })
+ } else {
+ None
+ }
+ } else {
+ None
+ }
+ })
+ .collect();
+
+ Some(clean_poly_trait_ref_with_bindings(cx, trait_ref, bindings))
+ })
+ .collect::<Vec<_>>();
+ bounds.extend(regions);
+ if !has_sized && !bounds.is_empty() {
+ bounds.insert(0, GenericBound::maybe_sized(cx));
+ }
+ ImplTrait(bounds)
+}
+
pub(crate) fn clean_field<'tcx>(field: &hir::FieldDef<'tcx>, cx: &mut DocContext<'tcx>) -> Item {
let def_id = cx.tcx.hir().local_def_id(field.hir_id).to_def_id();
clean_field_with_def_id(def_id, field.ident.name, clean_ty(field.ty, cx), cx)
@@ -1895,7 +1958,7 @@ fn clean_maybe_renamed_item<'tcx>(
) -> Vec<Item> {
use hir::ItemKind;
- let def_id = item.def_id.to_def_id();
+ let def_id = item.owner_id.to_def_id();
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id()));
cx.with_param_env(def_id, |cx| {
let kind = match item.kind {
@@ -2037,11 +2100,11 @@ fn clean_extern_crate<'tcx>(
cx: &mut DocContext<'tcx>,
) -> Vec<Item> {
// this is the ID of the `extern crate` statement
- let cnum = cx.tcx.extern_mod_stmt_cnum(krate.def_id).unwrap_or(LOCAL_CRATE);
+ let cnum = cx.tcx.extern_mod_stmt_cnum(krate.owner_id.def_id).unwrap_or(LOCAL_CRATE);
// this is the ID of the crate itself
let crate_def_id = cnum.as_def_id();
let attrs = cx.tcx.hir().attrs(krate.hir_id());
- let ty_vis = cx.tcx.visibility(krate.def_id);
+ let ty_vis = cx.tcx.visibility(krate.owner_id);
let please_inline = ty_vis.is_public()
&& attrs.iter().any(|a| {
a.has_name(sym::doc)
@@ -2059,7 +2122,7 @@ fn clean_extern_crate<'tcx>(
if let Some(items) = inline::try_inline(
cx,
cx.tcx.parent_module(krate.hir_id()).to_def_id(),
- Some(krate.def_id.to_def_id()),
+ Some(krate.owner_id.to_def_id()),
res,
name,
Some(attrs),
@@ -2095,11 +2158,11 @@ fn clean_use_statement<'tcx>(
return Vec::new();
}
- let visibility = cx.tcx.visibility(import.def_id);
+ let visibility = cx.tcx.visibility(import.owner_id);
let attrs = cx.tcx.hir().attrs(import.hir_id());
let inline_attr = attrs.lists(sym::doc).get_word_attr(sym::inline);
let pub_underscore = visibility.is_public() && name == kw::Underscore;
- let current_mod = cx.tcx.parent_module_from_def_id(import.def_id);
+ let current_mod = cx.tcx.parent_module_from_def_id(import.owner_id.def_id);
// The parent of the module in which this import resides. This
// is the same as `current_mod` if that's already the top
@@ -2170,7 +2233,7 @@ fn clean_use_statement<'tcx>(
}
if !denied {
let mut visited = FxHashSet::default();
- let import_def_id = import.def_id.to_def_id();
+ let import_def_id = import.owner_id.to_def_id();
if let Some(mut items) = inline::try_inline(
cx,
@@ -2193,7 +2256,7 @@ fn clean_use_statement<'tcx>(
Import::new_simple(name, resolve_use_source(cx, path), true)
};
- vec![Item::from_def_id_and_parts(import.def_id.to_def_id(), None, ImportItem(inner), cx)]
+ vec![Item::from_def_id_and_parts(import.owner_id.to_def_id(), None, ImportItem(inner), cx)]
}
fn clean_maybe_renamed_foreign_item<'tcx>(
@@ -2201,7 +2264,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
item: &hir::ForeignItem<'tcx>,
renamed: Option<Symbol>,
) -> Item {
- let def_id = item.def_id.to_def_id();
+ let def_id = item.owner_id.to_def_id();
cx.with_param_env(def_id, |cx| {
let kind = match item.kind {
hir::ForeignItemKind::Fn(decl, names, generics) => {
diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs
index af7813a77..1bcb9fcd5 100644
--- a/src/librustdoc/clean/simplify.rs
+++ b/src/librustdoc/clean/simplify.rs
@@ -14,7 +14,6 @@
use rustc_data_structures::fx::FxIndexMap;
use rustc_hir::def_id::DefId;
use rustc_middle::ty;
-use rustc_span::Symbol;
use crate::clean;
use crate::clean::GenericArgs as PP;
@@ -26,38 +25,37 @@ pub(crate) fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> {
//
// We use `FxIndexMap` so that the insertion order is preserved to prevent messing up to
// the order of the generated bounds.
- let mut params: FxIndexMap<Symbol, (Vec<_>, Vec<_>)> = FxIndexMap::default();
+ let mut tybounds = FxIndexMap::default();
let mut lifetimes = Vec::new();
let mut equalities = Vec::new();
- let mut tybounds = Vec::new();
for clause in clauses {
match clause {
- WP::BoundPredicate { ty, bounds, bound_params } => match ty {
- clean::Generic(s) => {
- let (b, p) = params.entry(s).or_default();
- b.extend(bounds);
- p.extend(bound_params);
- }
- t => tybounds.push((t, (bounds, bound_params))),
- },
+ WP::BoundPredicate { ty, bounds, bound_params } => {
+ let (b, p): &mut (Vec<_>, Vec<_>) = tybounds.entry(ty).or_default();
+ b.extend(bounds);
+ p.extend(bound_params);
+ }
WP::RegionPredicate { lifetime, bounds } => {
lifetimes.push((lifetime, bounds));
}
- WP::EqPredicate { lhs, rhs } => equalities.push((lhs, rhs)),
+ WP::EqPredicate { lhs, rhs, bound_params } => equalities.push((lhs, rhs, bound_params)),
}
}
// Look for equality predicates on associated types that can be merged into
- // general bound predicates
- equalities.retain(|&(ref lhs, ref rhs)| {
- let Some((self_, trait_did, name)) = lhs.projection() else {
- return true;
- };
- let clean::Generic(generic) = self_ else { return true };
- let Some((bounds, _)) = params.get_mut(generic) else { return true };
-
- merge_bounds(cx, bounds, trait_did, name, rhs)
+ // general bound predicates.
+ equalities.retain(|&(ref lhs, ref rhs, ref bound_params)| {
+ let Some((ty, trait_did, name)) = lhs.projection() else { return true; };
+ let Some((bounds, _)) = tybounds.get_mut(ty) else { return true };
+ let bound_params = bound_params
+ .into_iter()
+ .map(|param| clean::GenericParamDef {
+ name: param.0,
+ kind: clean::GenericParamDefKind::Lifetime { outlives: Vec::new() },
+ })
+ .collect();
+ merge_bounds(cx, bounds, bound_params, trait_did, name, rhs)
});
// And finally, let's reassemble everything
@@ -65,23 +63,23 @@ pub(crate) fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> {
clauses.extend(
lifetimes.into_iter().map(|(lt, bounds)| WP::RegionPredicate { lifetime: lt, bounds }),
);
- clauses.extend(params.into_iter().map(|(k, (bounds, params))| WP::BoundPredicate {
- ty: clean::Generic(k),
- bounds,
- bound_params: params,
- }));
clauses.extend(tybounds.into_iter().map(|(ty, (bounds, bound_params))| WP::BoundPredicate {
ty,
bounds,
bound_params,
}));
- clauses.extend(equalities.into_iter().map(|(lhs, rhs)| WP::EqPredicate { lhs, rhs }));
+ clauses.extend(equalities.into_iter().map(|(lhs, rhs, bound_params)| WP::EqPredicate {
+ lhs,
+ rhs,
+ bound_params,
+ }));
clauses
}
pub(crate) fn merge_bounds(
cx: &clean::DocContext<'_>,
bounds: &mut Vec<clean::GenericBound>,
+ mut bound_params: Vec<clean::GenericParamDef>,
trait_did: DefId,
assoc: clean::PathSegment,
rhs: &clean::Term,
@@ -98,6 +96,14 @@ pub(crate) fn merge_bounds(
return false;
}
let last = trait_ref.trait_.segments.last_mut().expect("segments were empty");
+
+ trait_ref.generic_params.append(&mut bound_params);
+ // Since the parameters (probably) originate from `tcx.collect_*_late_bound_regions` which
+ // returns a hash set, sort them alphabetically to guarantee a stable and deterministic
+ // output (and to fully deduplicate them).
+ trait_ref.generic_params.sort_unstable_by(|p, q| p.name.as_str().cmp(q.name.as_str()));
+ trait_ref.generic_params.dedup_by_key(|p| p.name);
+
match last.args {
PP::AngleBracketed { ref mut bindings, .. } => {
bindings.push(clean::TypeBinding {
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index f973fd088..cd1f972dc 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -21,6 +21,7 @@ use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_hir::lang_items::LangItem;
use rustc_hir::{BodyId, Mutability};
+use rustc_hir_analysis::check::intrinsic::intrinsic_operation_unsafety;
use rustc_index::vec::IndexVec;
use rustc_middle::ty::fast_reject::SimplifiedType;
use rustc_middle::ty::{self, TyCtxt};
@@ -31,7 +32,6 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{self, FileName, Loc};
use rustc_target::abi::VariantIdx;
use rustc_target::spec::abi::Abi;
-use rustc_typeck::check::intrinsic::intrinsic_operation_unsafety;
use crate::clean::cfg::Cfg;
use crate::clean::clean_visibility;
@@ -119,7 +119,7 @@ pub(crate) struct Crate {
pub(crate) module: Item,
pub(crate) primitives: ThinVec<(DefId, PrimitiveType)>,
/// Only here so that they can be filtered through the rustdoc passes.
- pub(crate) external_traits: Rc<RefCell<FxHashMap<DefId, TraitWithExtraInfo>>>,
+ pub(crate) external_traits: Rc<RefCell<FxHashMap<DefId, Trait>>>,
}
impl Crate {
@@ -132,13 +132,6 @@ impl Crate {
}
}
-/// This struct is used to wrap additional information added by rustdoc on a `trait` item.
-#[derive(Clone, Debug)]
-pub(crate) struct TraitWithExtraInfo {
- pub(crate) trait_: Trait,
- pub(crate) is_notable: bool,
-}
-
#[derive(Copy, Clone, Debug)]
pub(crate) struct ExternalCrate {
pub(crate) crate_num: CrateNum,
@@ -247,13 +240,13 @@ impl ExternalCrate {
let item = tcx.hir().item(id);
match item.kind {
hir::ItemKind::Mod(_) => {
- as_keyword(Res::Def(DefKind::Mod, id.def_id.to_def_id()))
+ as_keyword(Res::Def(DefKind::Mod, id.owner_id.to_def_id()))
}
hir::ItemKind::Use(path, hir::UseKind::Single)
- if tcx.visibility(id.def_id).is_public() =>
+ if tcx.visibility(id.owner_id).is_public() =>
{
as_keyword(path.res.expect_non_local())
- .map(|(_, prim)| (id.def_id.to_def_id(), prim))
+ .map(|(_, prim)| (id.owner_id.to_def_id(), prim))
}
_ => None,
}
@@ -315,14 +308,14 @@ impl ExternalCrate {
let item = tcx.hir().item(id);
match item.kind {
hir::ItemKind::Mod(_) => {
- as_primitive(Res::Def(DefKind::Mod, id.def_id.to_def_id()))
+ as_primitive(Res::Def(DefKind::Mod, id.owner_id.to_def_id()))
}
hir::ItemKind::Use(path, hir::UseKind::Single)
- if tcx.visibility(id.def_id).is_public() =>
+ if tcx.visibility(id.owner_id).is_public() =>
{
as_primitive(path.res.expect_non_local()).map(|(_, prim)| {
// Pretend the primitive is local.
- (id.def_id.to_def_id(), prim)
+ (id.owner_id.to_def_id(), prim)
})
}
_ => None,
@@ -689,7 +682,7 @@ impl Item {
let abi = tcx.fn_sig(self.item_id.as_def_id().unwrap()).abi();
hir::FnHeader {
unsafety: if abi == Abi::RustIntrinsic {
- intrinsic_operation_unsafety(self.name.unwrap())
+ intrinsic_operation_unsafety(tcx, self.item_id.as_def_id().unwrap())
} else {
hir::Unsafety::Unsafe
},
@@ -1357,7 +1350,7 @@ impl Lifetime {
pub(crate) enum WherePredicate {
BoundPredicate { ty: Type, bounds: Vec<GenericBound>, bound_params: Vec<Lifetime> },
RegionPredicate { lifetime: Lifetime, bounds: Vec<GenericBound> },
- EqPredicate { lhs: Type, rhs: Term },
+ EqPredicate { lhs: Box<Type>, rhs: Box<Term>, bound_params: Vec<Lifetime> },
}
impl WherePredicate {
@@ -1368,6 +1361,15 @@ impl WherePredicate {
_ => None,
}
}
+
+ pub(crate) fn get_bound_params(&self) -> Option<&[Lifetime]> {
+ match self {
+ Self::BoundPredicate { bound_params, .. } | Self::EqPredicate { bound_params, .. } => {
+ Some(bound_params)
+ }
+ _ => None,
+ }
+ }
}
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
@@ -1530,6 +1532,9 @@ impl Trait {
pub(crate) fn is_auto(&self, tcx: TyCtxt<'_>) -> bool {
tcx.trait_is_auto(self.def_id)
}
+ pub(crate) fn is_notable_trait(&self, tcx: TyCtxt<'_>) -> bool {
+ tcx.is_doc_notable_trait(self.def_id)
+ }
pub(crate) fn unsafety(&self, tcx: TyCtxt<'_>) -> hir::Unsafety {
tcx.trait_def(self.def_id).unsafety
}
@@ -2201,8 +2206,11 @@ impl Path {
/// Checks if this is a `T::Name` path for an associated type.
pub(crate) fn is_assoc_ty(&self) -> bool {
match self.res {
- Res::SelfTy { .. } if self.segments.len() != 1 => true,
- Res::Def(DefKind::TyParam, _) if self.segments.len() != 1 => true,
+ Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } | Res::Def(DefKind::TyParam, _)
+ if self.segments.len() != 1 =>
+ {
+ true
+ }
Res::Def(DefKind::AssocTy, _) => true,
_ => false,
}
@@ -2532,15 +2540,15 @@ impl SubstParam {
mod size_asserts {
use super::*;
use rustc_data_structures::static_assert_size;
- // These are in alphabetical order, which is easy to maintain.
+ // tidy-alphabetical-start
static_assert_size!(Crate, 72); // frequently moved by-value
static_assert_size!(DocFragment, 32);
- #[cfg(not(bootstrap))]
- static_assert_size!(GenericArg, 56);
+ static_assert_size!(GenericArg, 48);
static_assert_size!(GenericArgs, 32);
static_assert_size!(GenericParamDef, 56);
static_assert_size!(Item, 56);
- static_assert_size!(ItemKind, 96);
+ static_assert_size!(ItemKind, 88);
static_assert_size!(PathSegment, 40);
- static_assert_size!(Type, 56);
+ static_assert_size!(Type, 48);
+ // tidy-alphabetical-end
}
diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs
index 3eaedaf10..58767d3a4 100644
--- a/src/librustdoc/clean/utils.rs
+++ b/src/librustdoc/clean/utils.rs
@@ -7,7 +7,6 @@ use crate::clean::{
PathSegment, Primitive, PrimitiveType, Type, TypeBinding, Visibility,
};
use crate::core::DocContext;
-use crate::formats::item_type::ItemType;
use crate::visit_lib::LibEmbargoVisitor;
use rustc_ast as ast;
@@ -234,8 +233,7 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
match n.kind() {
- ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted }) => {
- assert_eq!(promoted, ());
+ ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs: _ }) => {
let s = if let Some(def) = def.as_local() {
print_const_expr(cx.tcx, cx.tcx.hir().body_owned_by(def.did))
} else {
@@ -305,9 +303,9 @@ fn format_integer_with_underscore_sep(num: &str) -> String {
.collect()
}
-fn print_const_with_custom_print_scalar(
- tcx: TyCtxt<'_>,
- ct: mir::ConstantKind<'_>,
+fn print_const_with_custom_print_scalar<'tcx>(
+ tcx: TyCtxt<'tcx>,
+ ct: mir::ConstantKind<'tcx>,
underscores_and_type: bool,
) -> String {
// Use a slightly different format for integer types which always shows the actual value.
@@ -321,7 +319,7 @@ fn print_const_with_custom_print_scalar(
}
}
(mir::ConstantKind::Val(ConstValue::Scalar(int), _), ty::Int(i)) => {
- let ty = tcx.lift(ct.ty()).unwrap();
+ let ty = ct.ty();
let size = tcx.layout_of(ty::ParamEnv::empty().and(ty)).unwrap().size;
let data = int.assert_bits(size);
let sign_extended_data = size.sign_extend(data) as i128;
@@ -455,7 +453,9 @@ pub(crate) fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type {
match path.res {
Res::PrimTy(p) => Primitive(PrimitiveType::from(p)),
- Res::SelfTy { .. } if path.segments.len() == 1 => Generic(kw::SelfUpper),
+ Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } if path.segments.len() == 1 => {
+ Generic(kw::SelfUpper)
+ }
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => Generic(path.segments[0].name),
_ => {
let _ = register_res(cx, path.res);
@@ -503,9 +503,6 @@ pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId {
return did;
}
inline::record_extern_fqn(cx, did, kind);
- if let ItemType::Trait = kind {
- inline::record_extern_trait(cx, did);
- }
did
}
diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs
index 932533db0..67ea39fb9 100644
--- a/src/librustdoc/config.rs
+++ b/src/librustdoc/config.rs
@@ -142,8 +142,6 @@ pub(crate) struct Options {
// Options that alter generated documentation pages
/// Crate version to note on the sidebar of generated docs.
pub(crate) crate_version: Option<String>,
- /// Collected options specific to outputting final pages.
- pub(crate) render_options: RenderOptions,
/// The format that we output when rendering.
///
/// Currently used only for the `--show-coverage` option.
@@ -159,6 +157,10 @@ pub(crate) struct Options {
/// Configuration for scraping examples from the current crate. If this option is Some(..) then
/// the compiler will scrape examples and not generate documentation.
pub(crate) scrape_examples_options: Option<ScrapeExamplesOptions>,
+
+ /// Note: this field is duplicated in `RenderOptions` because it's useful
+ /// to have it in both places.
+ pub(crate) unstable_features: rustc_feature::UnstableFeatures,
}
impl fmt::Debug for Options {
@@ -194,7 +196,6 @@ impl fmt::Debug for Options {
.field("persist_doctests", &self.persist_doctests)
.field("show_coverage", &self.show_coverage)
.field("crate_version", &self.crate_version)
- .field("render_options", &self.render_options)
.field("runtool", &self.runtool)
.field("runtool_args", &self.runtool_args)
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
@@ -202,6 +203,7 @@ impl fmt::Debug for Options {
.field("no_run", &self.no_run)
.field("nocapture", &self.nocapture)
.field("scrape_examples_options", &self.scrape_examples_options)
+ .field("unstable_features", &self.unstable_features)
.finish()
}
}
@@ -267,6 +269,8 @@ pub(crate) struct RenderOptions {
pub(crate) generate_redirect_map: bool,
/// Show the memory layout of types in the docs.
pub(crate) show_type_layout: bool,
+ /// Note: this field is duplicated in `Options` because it's useful to have
+ /// it in both places.
pub(crate) unstable_features: rustc_feature::UnstableFeatures,
pub(crate) emit: Vec<EmitType>,
/// If `true`, HTML source pages will generate links for items to their definition.
@@ -316,7 +320,7 @@ impl Options {
pub(crate) fn from_matches(
matches: &getopts::Matches,
args: Vec<String>,
- ) -> Result<Options, i32> {
+ ) -> Result<(Options, RenderOptions), i32> {
let args = &args[1..];
// Check for unstable options.
nightly_options::check_nightly_options(matches, &opts());
@@ -710,7 +714,9 @@ impl Options {
let with_examples = matches.opt_strs("with-examples");
let call_locations = crate::scrape_examples::load_call_locations(with_examples, &diag)?;
- Ok(Options {
+ let unstable_features =
+ rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
+ let options = Options {
input,
proc_macro_crate,
error_format,
@@ -744,42 +750,42 @@ impl Options {
run_check,
no_run,
nocapture,
- render_options: RenderOptions {
- output,
- external_html,
- id_map,
- playground_url,
- module_sorting,
- themes,
- extension_css,
- extern_html_root_urls,
- extern_html_root_takes_precedence,
- default_settings,
- resource_suffix,
- enable_minification,
- enable_index_page,
- index_page,
- static_root_path,
- markdown_no_toc,
- markdown_css,
- markdown_playground_url,
- document_private,
- document_hidden,
- generate_redirect_map,
- show_type_layout,
- unstable_features: rustc_feature::UnstableFeatures::from_environment(
- crate_name.as_deref(),
- ),
- emit,
- generate_link_to_definition,
- call_locations,
- no_emit_shared: false,
- },
crate_name,
output_format,
json_unused_externs,
scrape_examples_options,
- })
+ unstable_features,
+ };
+ let render_options = RenderOptions {
+ output,
+ external_html,
+ id_map,
+ playground_url,
+ module_sorting,
+ themes,
+ extension_css,
+ extern_html_root_urls,
+ extern_html_root_takes_precedence,
+ default_settings,
+ resource_suffix,
+ enable_minification,
+ enable_index_page,
+ index_page,
+ static_root_path,
+ markdown_no_toc,
+ markdown_css,
+ markdown_playground_url,
+ document_private,
+ document_hidden,
+ generate_redirect_map,
+ show_type_layout,
+ unstable_features,
+ emit,
+ generate_link_to_definition,
+ call_locations,
+ no_emit_shared: false,
+ };
+ Ok((options, render_options))
}
/// Returns `true` if the file given as `self.input` is a Markdown file.
diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs
index c48b25aea..3e5f42b7a 100644
--- a/src/librustdoc/core.rs
+++ b/src/librustdoc/core.rs
@@ -1,6 +1,7 @@
use rustc_ast::NodeId;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::{self, Lrc};
+use rustc_data_structures::unord::UnordSet;
use rustc_errors::emitter::{Emitter, EmitterWriter};
use rustc_errors::json::JsonEmitter;
use rustc_feature::UnstableFeatures;
@@ -10,12 +11,10 @@ use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{HirId, Path, TraitCandidate};
use rustc_interface::interface;
use rustc_middle::hir::nested_filter;
-use rustc_middle::middle::privacy::AccessLevels;
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt};
use rustc_resolve as resolve;
use rustc_session::config::{self, CrateType, ErrorOutputType};
use rustc_session::lint;
-use rustc_session::DiagnosticOutput;
use rustc_session::Session;
use rustc_span::symbol::sym;
use rustc_span::{source_map, Span, Symbol};
@@ -26,7 +25,7 @@ use std::rc::Rc;
use std::sync::LazyLock;
use crate::clean::inline::build_external_trait;
-use crate::clean::{self, ItemId, TraitWithExtraInfo};
+use crate::clean::{self, ItemId};
use crate::config::{Options as RustdocOptions, OutputFormat, RenderOptions};
use crate::formats::cache::Cache;
use crate::passes::collect_intra_doc_links::PreprocessedMarkdownLink;
@@ -40,7 +39,6 @@ pub(crate) struct ResolverCaches {
/// Traits in scope for a given module.
/// See `collect_intra_doc_links::traits_implemented_by` for more details.
pub(crate) traits_in_scope: DefIdMap<Vec<TraitCandidate>>,
- pub(crate) all_traits: Option<Vec<DefId>>,
pub(crate) all_trait_impls: Option<Vec<DefId>>,
pub(crate) all_macro_rules: FxHashMap<Symbol, Res<NodeId>>,
}
@@ -59,7 +57,7 @@ pub(crate) struct DocContext<'tcx> {
/// Most of this logic is copied from rustc_lint::late.
pub(crate) param_env: ParamEnv<'tcx>,
/// Later on moved through `clean::Crate` into `cache`
- pub(crate) external_traits: Rc<RefCell<FxHashMap<DefId, clean::TraitWithExtraInfo>>>,
+ pub(crate) external_traits: Rc<RefCell<FxHashMap<DefId, clean::Trait>>>,
/// Used while populating `external_traits` to ensure we don't process the same trait twice at
/// the same time.
pub(crate) active_extern_traits: FxHashSet<DefId>,
@@ -136,12 +134,6 @@ impl<'tcx> DocContext<'tcx> {
}
}
- pub(crate) fn with_all_traits(&mut self, f: impl FnOnce(&mut Self, &[DefId])) {
- let all_traits = self.resolver_caches.all_traits.take();
- f(self, all_traits.as_ref().expect("`all_traits` are already borrowed"));
- self.resolver_caches.all_traits = all_traits;
- }
-
pub(crate) fn with_all_trait_impls(&mut self, f: impl FnOnce(&mut Self, &[DefId])) {
let all_trait_impls = self.resolver_caches.all_trait_impls.take();
f(self, all_trait_impls.as_ref().expect("`all_trait_impls` are already borrowed"));
@@ -287,19 +279,17 @@ pub(crate) fn create_config(
output_file: None,
output_dir: None,
file_loader: None,
- diagnostic_output: DiagnosticOutput::Default,
lint_caps,
parse_sess_created: None,
register_lints: Some(Box::new(crate::lint::register_lints)),
override_queries: Some(|_sess, providers, _external_providers| {
// Most lints will require typechecking, so just don't run them.
providers.lint_mod = |_, _| {};
- // Prevent `rustc_typeck::check_crate` from calling `typeck` on all bodies.
+ // Prevent `rustc_hir_analysis::check_crate` from calling `typeck` on all bodies.
providers.typeck_item_bodies = |_, _| {};
// hack so that `used_trait_imports` won't try to call typeck
providers.used_trait_imports = |_, _| {
- static EMPTY_SET: LazyLock<FxHashSet<LocalDefId>> =
- LazyLock::new(FxHashSet::default);
+ static EMPTY_SET: LazyLock<UnordSet<LocalDefId>> = LazyLock::new(UnordSet::default);
&EMPTY_SET
};
// In case typeck does end up being called, don't ICE in case there were name resolution errors
@@ -356,17 +346,9 @@ pub(crate) fn run_global_ctxt(
});
rustc_passes::stability::check_unused_or_stable_features(tcx);
- let auto_traits = resolver_caches
- .all_traits
- .as_ref()
- .expect("`all_traits` are already borrowed")
- .iter()
- .copied()
- .filter(|&trait_def_id| tcx.trait_is_auto(trait_def_id))
- .collect();
- let access_levels = AccessLevels {
- map: tcx.privacy_access_levels(()).map.iter().map(|(k, v)| (k.to_def_id(), *v)).collect(),
- };
+ let auto_traits =
+ tcx.all_traits().filter(|&trait_def_id| tcx.trait_is_auto(trait_def_id)).collect();
+ let effective_visibilities = tcx.effective_visibilities(()).map_id(Into::into);
let mut ctxt = DocContext {
tcx,
@@ -379,7 +361,7 @@ pub(crate) fn run_global_ctxt(
impl_trait_bounds: Default::default(),
generated_synthetics: Default::default(),
auto_traits,
- cache: Cache::new(access_levels, render_options.document_private),
+ cache: Cache::new(effective_visibilities, render_options.document_private),
inlined: FxHashSet::default(),
output_format,
render_options,
@@ -391,9 +373,7 @@ pub(crate) fn run_global_ctxt(
// Note that in case of `#![no_core]`, the trait is not available.
if let Some(sized_trait_did) = ctxt.tcx.lang_items().sized_trait() {
let sized_trait = build_external_trait(&mut ctxt, sized_trait_did);
- ctxt.external_traits
- .borrow_mut()
- .insert(sized_trait_did, TraitWithExtraInfo { trait_: sized_trait, is_notable: false });
+ ctxt.external_traits.borrow_mut().insert(sized_trait_did, sized_trait);
}
debug!("crate: {:?}", tcx.hir().krate());
@@ -409,12 +389,8 @@ pub(crate) fn run_global_ctxt(
tcx.struct_lint_node(
crate::lint::MISSING_CRATE_LEVEL_DOCS,
DocContext::as_local_hir_id(tcx, krate.module.item_id).unwrap(),
- |lint| {
- let mut diag =
- lint.build("no documentation found for this crate's top-level module");
- diag.help(&help);
- diag.emit();
- },
+ "no documentation found for this crate's top-level module",
+ |lint| lint.help(help),
);
}
diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs
index 20ae102bc..db70029f6 100644
--- a/src/librustdoc/doctest.rs
+++ b/src/librustdoc/doctest.rs
@@ -14,11 +14,10 @@ use rustc_parse::maybe_new_parser_from_source_str;
use rustc_parse::parser::attr::InnerAttrPolicy;
use rustc_session::config::{self, CrateType, ErrorOutputType};
use rustc_session::parse::ParseSess;
-use rustc_session::{lint, DiagnosticOutput, Session};
+use rustc_session::{lint, Session};
use rustc_span::edition::Edition;
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::sym;
-use rustc_span::Symbol;
use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP};
use rustc_target::spec::TargetTriple;
use tempfile::Builder as TempFileBuilder;
@@ -80,7 +79,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
lint_cap: Some(options.lint_cap.unwrap_or(lint::Forbid)),
cg: options.codegen_options.clone(),
externs: options.externs.clone(),
- unstable_features: options.render_options.unstable_features,
+ unstable_features: options.unstable_features,
actually_rustdoc: true,
edition: options.edition,
target_triple: options.target.clone(),
@@ -100,7 +99,6 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
output_file: None,
output_dir: None,
file_loader: None,
- diagnostic_output: DiagnosticOutput::Default,
lint_caps,
parse_sess_created: None,
register_lints: Some(Box::new(crate::lint::register_lints)),
@@ -125,7 +123,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
let opts = scrape_test_config(crate_attrs);
let enable_per_target_ignores = options.enable_per_target_ignores;
let mut collector = Collector::new(
- tcx.crate_name(LOCAL_CRATE),
+ tcx.crate_name(LOCAL_CRATE).to_string(),
options,
false,
opts,
@@ -210,12 +208,13 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
pub(crate) fn run_tests(
mut test_args: Vec<String>,
nocapture: bool,
- tests: Vec<test::TestDescAndFn>,
+ mut tests: Vec<test::TestDescAndFn>,
) {
test_args.insert(0, "rustdoctest".to_string());
if nocapture {
test_args.push("--nocapture".to_string());
}
+ tests.sort_by(|a, b| a.desc.name.as_slice().cmp(&b.desc.name.as_slice()));
test::test_main(&test_args, tests, None);
}
@@ -909,7 +908,7 @@ pub(crate) struct Collector {
rustdoc_options: RustdocOptions,
use_headers: bool,
enable_per_target_ignores: bool,
- crate_name: Symbol,
+ crate_name: String,
opts: GlobalTestOptions,
position: Span,
source_map: Option<Lrc<SourceMap>>,
@@ -921,7 +920,7 @@ pub(crate) struct Collector {
impl Collector {
pub(crate) fn new(
- crate_name: Symbol,
+ crate_name: String,
rustdoc_options: RustdocOptions,
use_headers: bool,
opts: GlobalTestOptions,
@@ -984,7 +983,7 @@ impl Tester for Collector {
fn add_test(&mut self, test: String, config: LangString, line: usize) {
let filename = self.get_filename();
let name = self.generate_name(line, &filename);
- let crate_name = self.crate_name.to_string();
+ let crate_name = self.crate_name.clone();
let opts = self.opts.clone();
let edition = config.edition.unwrap_or(self.rustdoc_options.edition);
let rustdoc_options = self.rustdoc_options.clone();
@@ -1134,6 +1133,7 @@ impl Tester for Collector {
panic::resume_unwind(Box::new(()));
}
+ Ok(())
})),
});
}
diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs
index ed702f5c4..c6f1f9de5 100644
--- a/src/librustdoc/fold.rs
+++ b/src/librustdoc/fold.rs
@@ -94,7 +94,7 @@ pub(crate) trait DocFolder: Sized {
let external_traits = { std::mem::take(&mut *c.external_traits.borrow_mut()) };
for (k, mut v) in external_traits {
- v.trait_.items = v.trait_.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
+ v.items = v.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
c.external_traits.borrow_mut().insert(k, v);
}
diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs
index 86392610d..afe2264e8 100644
--- a/src/librustdoc/formats/cache.rs
+++ b/src/librustdoc/formats/cache.rs
@@ -2,9 +2,9 @@ use std::mem;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::{CrateNum, DefId};
-use rustc_middle::middle::privacy::AccessLevels;
+use rustc_middle::middle::privacy::EffectiveVisibilities;
use rustc_middle::ty::{self, TyCtxt};
-use rustc_span::{sym, Symbol};
+use rustc_span::Symbol;
use crate::clean::{self, types::ExternalLocation, ExternalCrate, ItemId, PrimitiveType};
use crate::core::DocContext;
@@ -62,7 +62,7 @@ pub(crate) struct Cache {
/// Implementations of a crate should inherit the documentation of the
/// parent trait if no extra documentation is specified, and default methods
/// should show up in documentation about trait implementations.
- pub(crate) traits: FxHashMap<DefId, clean::TraitWithExtraInfo>,
+ pub(crate) traits: FxHashMap<DefId, clean::Trait>,
/// When rendering traits, it's often useful to be able to list all
/// implementors of the trait, and this mapping is exactly, that: a mapping
@@ -77,8 +77,8 @@ pub(crate) struct Cache {
// Note that external items for which `doc(hidden)` applies to are shown as
// non-reachable while local items aren't. This is because we're reusing
- // the access levels from the privacy check pass.
- pub(crate) access_levels: AccessLevels<DefId>,
+ // the effective visibilities from the privacy check pass.
+ pub(crate) effective_visibilities: EffectiveVisibilities<DefId>,
/// The version of the crate being documented, if given from the `--crate-version` flag.
pub(crate) crate_version: Option<String>,
@@ -132,8 +132,11 @@ struct CacheBuilder<'a, 'tcx> {
}
impl Cache {
- pub(crate) fn new(access_levels: AccessLevels<DefId>, document_private: bool) -> Self {
- Cache { access_levels, document_private, ..Cache::default() }
+ pub(crate) fn new(
+ effective_visibilities: EffectiveVisibilities<DefId>,
+ document_private: bool,
+ ) -> Self {
+ Cache { effective_visibilities, document_private, ..Cache::default() }
}
/// Populates the `Cache` with more data. The returned `Crate` will be missing some data that was
@@ -225,12 +228,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// Propagate a trait method's documentation to all implementors of the
// trait.
if let clean::TraitItem(ref t) = *item.kind {
- self.cache.traits.entry(item.item_id.expect_def_id()).or_insert_with(|| {
- clean::TraitWithExtraInfo {
- trait_: *t.clone(),
- is_notable: item.attrs.has_doc_flag(sym::notable_trait),
- }
- });
+ self.cache.traits.entry(item.item_id.expect_def_id()).or_insert_with(|| (**t).clone());
}
// Collect all the implementors of traits.
@@ -386,7 +384,10 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// paths map if there was already an entry present and we're
// not a public item.
if !self.cache.paths.contains_key(&item.item_id.expect_def_id())
- || self.cache.access_levels.is_public(item.item_id.expect_def_id())
+ || self
+ .cache
+ .effective_visibilities
+ .is_directly_public(item.item_id.expect_def_id())
{
self.cache.paths.insert(
item.item_id.expect_def_id(),
diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs
index 62ba984ac..6f9cc0266 100644
--- a/src/librustdoc/formats/renderer.rs
+++ b/src/librustdoc/formats/renderer.rs
@@ -58,7 +58,7 @@ pub(crate) fn run_format<'tcx, T: FormatRenderer<'tcx>>(
let emit_crate = options.should_emit_crate();
let (mut format_renderer, krate) = prof
- .extra_verbose_generic_activity("create_renderer", T::descr())
+ .verbose_generic_activity_with_arg("create_renderer", T::descr())
.run(|| T::init(krate, options, cache, tcx))?;
if !emit_crate {
@@ -92,6 +92,6 @@ pub(crate) fn run_format<'tcx, T: FormatRenderer<'tcx>>(
.run(|| cx.item(item))?;
}
}
- prof.extra_verbose_generic_activity("renderer_after_krate", T::descr())
+ prof.verbose_generic_activity_with_arg("renderer_after_krate", T::descr())
.run(|| format_renderer.after_krate())
}
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index b499e186c..92e7f2739 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -331,7 +331,8 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
bounds_display.truncate(bounds_display.len() - " + ".len());
write!(f, "{}: {bounds_display}", lifetime.print())
}
- clean::WherePredicate::EqPredicate { lhs, rhs } => {
+ // FIXME(fmease): Render bound params.
+ clean::WherePredicate::EqPredicate { lhs, rhs, bound_params: _ } => {
if f.alternate() {
write!(f, "{:#} == {:#}", lhs.print(cx), rhs.print(cx))
} else {
@@ -611,7 +612,7 @@ fn generate_macro_def_id_path(
};
if path.len() < 2 {
// The minimum we can have is the crate name followed by the macro name. If shorter, then
- // it means that that `relative` was empty, which is an error.
+ // it means that `relative` was empty, which is an error.
debug!("macro path cannot be empty!");
return Err(HrefError::NotInExternalCache);
}
@@ -658,7 +659,7 @@ pub(crate) fn href_with_root_path(
}
if !did.is_local()
- && !cache.access_levels.is_public(did)
+ && !cache.effective_visibilities.is_directly_public(did)
&& !cache.document_private
&& !cache.primitive_locations.values().any(|&id| id == did)
{
@@ -1010,15 +1011,25 @@ fn fmt_type<'cx>(
write!(f, "]")
}
},
- clean::Array(ref t, ref n) => {
- primitive_link(f, PrimitiveType::Array, "[", cx)?;
- fmt::Display::fmt(&t.print(cx), f)?;
- if f.alternate() {
- primitive_link(f, PrimitiveType::Array, &format!("; {}]", n), cx)
- } else {
- primitive_link(f, PrimitiveType::Array, &format!("; {}]", Escape(n)), cx)
+ clean::Array(ref t, ref n) => match **t {
+ clean::Generic(name) if !f.alternate() => primitive_link(
+ f,
+ PrimitiveType::Array,
+ &format!("[{name}; {n}]", n = Escape(n)),
+ cx,
+ ),
+ _ => {
+ write!(f, "[")?;
+ fmt::Display::fmt(&t.print(cx), f)?;
+ if f.alternate() {
+ write!(f, "; {n}")?;
+ } else {
+ write!(f, "; ")?;
+ primitive_link(f, PrimitiveType::Array, &format!("{n}", n = Escape(n)), cx)?;
+ }
+ write!(f, "]")
}
- }
+ },
clean::RawPointer(m, ref t) => {
let m = match m {
hir::Mutability::Mut => "mut",
diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs
index 8922bf377..5e28204b2 100644
--- a/src/librustdoc/html/highlight.rs
+++ b/src/librustdoc/html/highlight.rs
@@ -7,19 +7,18 @@
use crate::clean::PrimitiveType;
use crate::html::escape::Escape;
-use crate::html::render::Context;
+use crate::html::render::{Context, LinkFromSrc};
use std::collections::VecDeque;
use std::fmt::{Display, Write};
use rustc_data_structures::fx::FxHashMap;
-use rustc_lexer::{LiteralKind, TokenKind};
+use rustc_lexer::{Cursor, LiteralKind, TokenKind};
use rustc_span::edition::Edition;
use rustc_span::symbol::Symbol;
use rustc_span::{BytePos, Span, DUMMY_SP};
use super::format::{self, Buffer};
-use super::render::LinkFromSrc;
/// This type is needed in case we want to render links on items to allow to go to their definition.
pub(crate) struct HrefContext<'a, 'b, 'c> {
@@ -408,15 +407,16 @@ enum Highlight<'a> {
struct TokenIter<'a> {
src: &'a str,
+ cursor: Cursor<'a>,
}
impl<'a> Iterator for TokenIter<'a> {
type Item = (TokenKind, &'a str);
fn next(&mut self) -> Option<(TokenKind, &'a str)> {
- if self.src.is_empty() {
+ let token = self.cursor.advance_token();
+ if token.kind == TokenKind::Eof {
return None;
}
- let token = rustc_lexer::first_token(self.src);
let (text, rest) = self.src.split_at(token.len as usize);
self.src = rest;
Some((token.kind, text))
@@ -525,7 +525,7 @@ impl<'a> Classifier<'a> {
/// Takes as argument the source code to HTML-ify, the rust edition to use and the source code
/// file span which will be used later on by the `span_correspondance_map`.
fn new(src: &str, file_span: Span, decoration_info: Option<DecorationInfo>) -> Classifier<'_> {
- let tokens = PeekIter::new(TokenIter { src });
+ let tokens = PeekIter::new(TokenIter { src, cursor: Cursor::new(src) });
let decorations = decoration_info.map(Decorations::new);
Classifier {
tokens,
@@ -850,6 +850,7 @@ impl<'a> Classifier<'a> {
Class::Ident(self.new_span(before, text))
}
TokenKind::Lifetime { .. } => Class::Lifetime,
+ TokenKind::Eof => panic!("Eof in advance"),
};
// Anything that didn't return above is the simple case where we the
// class just spans a single token, so we can use the `string` method.
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index 43d07d4a5..1e1c657b0 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -111,14 +111,9 @@ pub(crate) struct MarkdownWithToc<'a>(
pub(crate) Edition,
pub(crate) &'a Option<Playground>,
);
-/// A tuple struct like `Markdown` that renders the markdown escaping HTML tags.
-pub(crate) struct MarkdownHtml<'a>(
- pub(crate) &'a str,
- pub(crate) &'a mut IdMap,
- pub(crate) ErrorCodes,
- pub(crate) Edition,
- pub(crate) &'a Option<Playground>,
-);
+/// A tuple struct like `Markdown` that renders the markdown escaping HTML tags
+/// and includes no paragraph tags.
+pub(crate) struct MarkdownItemInfo<'a>(pub(crate) &'a str, pub(crate) &'a mut IdMap);
/// A tuple struct like `Markdown` that renders only the first paragraph.
pub(crate) struct MarkdownSummaryLine<'a>(pub &'a str, pub &'a [RenderedLink]);
@@ -251,8 +246,6 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
_ => {}
}
}
- let lines = origtext.lines().filter_map(|l| map_line(l).for_html());
- let text = lines.intersperse("\n".into()).collect::<String>();
let parse_result = match kind {
CodeBlockKind::Fenced(ref lang) => {
@@ -265,7 +258,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
<pre class=\"language-{}\"><code>{}</code></pre>\
</div>",
lang,
- Escape(&text),
+ Escape(&origtext),
)
.into(),
));
@@ -275,6 +268,9 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
CodeBlockKind::Indented => Default::default(),
};
+ let lines = origtext.lines().filter_map(|l| map_line(l).for_html());
+ let text = lines.intersperse("\n".into()).collect::<String>();
+
compile_fail = parse_result.compile_fail;
should_panic = parse_result.should_panic;
ignore = parse_result.ignore;
@@ -818,11 +814,8 @@ impl<'tcx> ExtraInfo<'tcx> {
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
hir_id,
self.sp,
- |lint| {
- let mut diag = lint.build(msg);
- diag.help(help);
- diag.emit();
- },
+ msg,
+ |lint| lint.help(help),
);
}
}
@@ -1072,9 +1065,9 @@ impl MarkdownWithToc<'_> {
}
}
-impl MarkdownHtml<'_> {
+impl MarkdownItemInfo<'_> {
pub(crate) fn into_string(self) -> String {
- let MarkdownHtml(md, ids, codes, edition, playground) = self;
+ let MarkdownItemInfo(md, ids) = self;
// This is actually common enough to special-case
if md.is_empty() {
@@ -1093,7 +1086,9 @@ impl MarkdownHtml<'_> {
let p = HeadingLinks::new(p, None, ids, HeadingOffset::H1);
let p = Footnotes::new(p);
let p = TableWrapper::new(p.map(|(ev, _)| ev));
- let p = CodeBlocks::new(p, codes, edition, playground);
+ let p = p.filter(|event| {
+ !matches!(event, Event::Start(Tag::Paragraph) | Event::End(Tag::Paragraph))
+ });
html::push_html(&mut s, p);
s
@@ -1439,6 +1434,7 @@ static DEFAULT_ID_MAP: Lazy<FxHashMap<Cow<'static, str>, usize>> = Lazy::new(||
fn init_id_map() -> FxHashMap<Cow<'static, str>, usize> {
let mut map = FxHashMap::default();
// This is the list of IDs used in Javascript.
+ map.insert("help".into(), 1);
map.insert("settings".into(), 1);
map.insert("not-displayed".into(), 1);
map.insert("alternative-display".into(), 1);
diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs
index 5c0bf0ed9..68b31a6ee 100644
--- a/src/librustdoc/html/markdown/tests.rs
+++ b/src/librustdoc/html/markdown/tests.rs
@@ -1,5 +1,5 @@
use super::{find_testable_code, plain_text_summary, short_markdown_summary};
-use super::{ErrorCodes, HeadingOffset, IdMap, Ignore, LangString, Markdown, MarkdownHtml};
+use super::{ErrorCodes, HeadingOffset, IdMap, Ignore, LangString, Markdown, MarkdownItemInfo};
use rustc_span::edition::{Edition, DEFAULT_EDITION};
#[test]
@@ -279,14 +279,13 @@ fn test_plain_text_summary() {
fn test_markdown_html_escape() {
fn t(input: &str, expect: &str) {
let mut idmap = IdMap::new();
- let output =
- MarkdownHtml(input, &mut idmap, ErrorCodes::Yes, DEFAULT_EDITION, &None).into_string();
+ let output = MarkdownItemInfo(input, &mut idmap).into_string();
assert_eq!(output, expect, "original: {}", input);
}
- t("`Struct<'a, T>`", "<p><code>Struct&lt;'a, T&gt;</code></p>\n");
- t("Struct<'a, T>", "<p>Struct&lt;’a, T&gt;</p>\n");
- t("Struct<br>", "<p>Struct&lt;br&gt;</p>\n");
+ t("`Struct<'a, T>`", "<code>Struct&lt;'a, T&gt;</code>");
+ t("Struct<'a, T>", "Struct&lt;’a, T&gt;");
+ t("Struct<br>", "Struct&lt;br&gt;");
}
#[test]
@@ -310,3 +309,40 @@ fn test_find_testable_code_line() {
t("```rust\n```\n```rust\n```", &[1, 3]);
t("```rust\n```\n ```rust\n```", &[1, 3]);
}
+
+#[test]
+fn test_ascii_with_prepending_hashtag() {
+ fn t(input: &str, expect: &str) {
+ let mut map = IdMap::new();
+ let output = Markdown {
+ content: input,
+ links: &[],
+ ids: &mut map,
+ error_codes: ErrorCodes::Yes,
+ edition: DEFAULT_EDITION,
+ playground: &None,
+ heading_offset: HeadingOffset::H2,
+ }
+ .into_string();
+ assert_eq!(output, expect, "original: {}", input);
+ }
+
+ t(
+ r#"```ascii
+#..#.####.#....#.....##..
+#..#.#....#....#....#..#.
+####.###..#....#....#..#.
+#..#.#....#....#....#..#.
+#..#.#....#....#....#..#.
+#..#.####.####.####..##..
+```"#,
+ "<div class=\"example-wrap\"><pre class=\"language-ascii\"><code>\
+#..#.####.#....#.....##..
+#..#.#....#....#....#..#.
+####.###..#....#....#..#.
+#..#.#....#....#....#..#.
+#..#.#....#....#....#..#.
+#..#.####.####.####..##..
+</code></pre></div>",
+ );
+}
diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs
index 62def4a94..5733d1f9c 100644
--- a/src/librustdoc/html/render/context.rs
+++ b/src/librustdoc/html/render/context.rs
@@ -17,8 +17,8 @@ use super::print_item::{full_path, item_path, print_item};
use super::search_index::build_index;
use super::write_shared::write_shared;
use super::{
- collect_spans_and_sources, print_sidebar, scrape_examples_help, AllTypes, LinkFromSrc, NameDoc,
- StylePath, BASIC_KEYWORDS,
+ collect_spans_and_sources, print_sidebar, scrape_examples_help, sidebar_module_like, AllTypes,
+ LinkFromSrc, NameDoc, StylePath, BASIC_KEYWORDS,
};
use crate::clean::{self, types::ExternalLocation, ExternalCrate};
@@ -430,7 +430,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
extension_css,
resource_suffix,
static_root_path,
- unstable_features,
generate_redirect_map,
show_type_layout,
generate_link_to_definition,
@@ -511,7 +510,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
resource_suffix,
static_root_path,
fs: DocFS::new(sender),
- codes: ErrorCodes::from(unstable_features.is_nightly_build()),
+ codes: ErrorCodes::from(options.unstable_features.is_nightly_build()),
playground,
all: RefCell::new(AllTypes::new()),
errors: receiver,
@@ -581,6 +580,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
let crate_name = self.tcx().crate_name(LOCAL_CRATE);
let final_file = self.dst.join(crate_name.as_str()).join("all.html");
let settings_file = self.dst.join("settings.html");
+ let help_file = self.dst.join("help.html");
let scrape_examples_help_file = self.dst.join("scrape-examples-help.html");
let mut root_path = self.dst.to_str().expect("invalid path").to_owned();
@@ -597,16 +597,24 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
keywords: BASIC_KEYWORDS,
resource_suffix: &shared.resource_suffix,
};
- let sidebar = if shared.cache.crate_version.is_some() {
- format!("<h2 class=\"location\">Crate {}</h2>", crate_name)
- } else {
- String::new()
- };
let all = shared.all.replace(AllTypes::new());
+ let mut sidebar = Buffer::html();
+ if shared.cache.crate_version.is_some() {
+ write!(sidebar, "<h2 class=\"location\">Crate {}</h2>", crate_name)
+ };
+
+ let mut items = Buffer::html();
+ sidebar_module_like(&mut items, all.item_sections());
+ if !items.is_empty() {
+ sidebar.push_str("<div class=\"sidebar-elems\">");
+ sidebar.push_buffer(items);
+ sidebar.push_str("</div>");
+ }
+
let v = layout::render(
&shared.layout,
&page,
- sidebar,
+ sidebar.into_inner(),
|buf: &mut Buffer| all.print(buf),
&shared.style_files,
);
@@ -626,9 +634,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
write!(
buf,
"<div class=\"main-heading\">\
- <h1 class=\"fqn\">\
- <span class=\"in-band\">Rustdoc settings</span>\
- </h1>\
+ <h1 class=\"fqn\">Rustdoc settings</h1>\
<span class=\"out-of-band\">\
<a id=\"back\" href=\"javascript:void(0)\" onclick=\"history.back();\">\
Back\
@@ -651,6 +657,39 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
);
shared.fs.write(settings_file, v)?;
+ // Generating help page.
+ page.title = "Rustdoc help";
+ page.description = "Documentation for Rustdoc";
+ page.root_path = "./";
+
+ let sidebar = "<h2 class=\"location\">Help</h2><div class=\"sidebar-elems\"></div>";
+ let v = layout::render(
+ &shared.layout,
+ &page,
+ sidebar,
+ |buf: &mut Buffer| {
+ write!(
+ buf,
+ "<div class=\"main-heading\">\
+ <h1 class=\"fqn\">Rustdoc help</h1>\
+ <span class=\"out-of-band\">\
+ <a id=\"back\" href=\"javascript:void(0)\" onclick=\"history.back();\">\
+ Back\
+ </a>\
+ </span>\
+ </div>\
+ <noscript>\
+ <section>\
+ <p>You need to enable Javascript to use keyboard commands or search.</p>\
+ <p>For more information, browse the <a href=\"https://doc.rust-lang.org/rustdoc/\">rustdoc handbook</a>.</p>\
+ </section>\
+ </noscript>",
+ )
+ },
+ &shared.style_files,
+ );
+ shared.fs.write(help_file, v)?;
+
if shared.layout.scrape_examples_extension {
page.title = "About scraped examples";
page.description = "How the scraped examples feature works in Rustdoc";
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 1e6f20d2b..96c57c8c8 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -74,7 +74,9 @@ use crate::html::format::{
PrintWithSpace,
};
use crate::html::highlight;
-use crate::html::markdown::{HeadingOffset, IdMap, Markdown, MarkdownHtml, MarkdownSummaryLine};
+use crate::html::markdown::{
+ HeadingOffset, IdMap, Markdown, MarkdownItemInfo, MarkdownSummaryLine,
+};
use crate::html::sources;
use crate::html::static_files::SCRAPE_EXAMPLES_HELP_MD;
use crate::scrape_examples::{CallData, CallLocation};
@@ -239,8 +241,8 @@ struct AllTypes {
opaque_tys: FxHashSet<ItemEntry>,
statics: FxHashSet<ItemEntry>,
constants: FxHashSet<ItemEntry>,
- attributes: FxHashSet<ItemEntry>,
- derives: FxHashSet<ItemEntry>,
+ attribute_macros: FxHashSet<ItemEntry>,
+ derive_macros: FxHashSet<ItemEntry>,
trait_aliases: FxHashSet<ItemEntry>,
}
@@ -259,8 +261,8 @@ impl AllTypes {
opaque_tys: new_set(100),
statics: new_set(100),
constants: new_set(100),
- attributes: new_set(100),
- derives: new_set(100),
+ attribute_macros: new_set(100),
+ derive_macros: new_set(100),
trait_aliases: new_set(100),
}
}
@@ -283,27 +285,75 @@ impl AllTypes {
ItemType::OpaqueTy => self.opaque_tys.insert(ItemEntry::new(new_url, name)),
ItemType::Static => self.statics.insert(ItemEntry::new(new_url, name)),
ItemType::Constant => self.constants.insert(ItemEntry::new(new_url, name)),
- ItemType::ProcAttribute => self.attributes.insert(ItemEntry::new(new_url, name)),
- ItemType::ProcDerive => self.derives.insert(ItemEntry::new(new_url, name)),
+ ItemType::ProcAttribute => {
+ self.attribute_macros.insert(ItemEntry::new(new_url, name))
+ }
+ ItemType::ProcDerive => self.derive_macros.insert(ItemEntry::new(new_url, name)),
ItemType::TraitAlias => self.trait_aliases.insert(ItemEntry::new(new_url, name)),
_ => true,
};
}
}
-}
-impl AllTypes {
+ fn item_sections(&self) -> FxHashSet<ItemSection> {
+ let mut sections = FxHashSet::default();
+
+ if !self.structs.is_empty() {
+ sections.insert(ItemSection::Structs);
+ }
+ if !self.enums.is_empty() {
+ sections.insert(ItemSection::Enums);
+ }
+ if !self.unions.is_empty() {
+ sections.insert(ItemSection::Unions);
+ }
+ if !self.primitives.is_empty() {
+ sections.insert(ItemSection::PrimitiveTypes);
+ }
+ if !self.traits.is_empty() {
+ sections.insert(ItemSection::Traits);
+ }
+ if !self.macros.is_empty() {
+ sections.insert(ItemSection::Macros);
+ }
+ if !self.functions.is_empty() {
+ sections.insert(ItemSection::Functions);
+ }
+ if !self.typedefs.is_empty() {
+ sections.insert(ItemSection::TypeDefinitions);
+ }
+ if !self.opaque_tys.is_empty() {
+ sections.insert(ItemSection::OpaqueTypes);
+ }
+ if !self.statics.is_empty() {
+ sections.insert(ItemSection::Statics);
+ }
+ if !self.constants.is_empty() {
+ sections.insert(ItemSection::Constants);
+ }
+ if !self.attribute_macros.is_empty() {
+ sections.insert(ItemSection::AttributeMacros);
+ }
+ if !self.derive_macros.is_empty() {
+ sections.insert(ItemSection::DeriveMacros);
+ }
+ if !self.trait_aliases.is_empty() {
+ sections.insert(ItemSection::TraitAliases);
+ }
+
+ sections
+ }
+
fn print(self, f: &mut Buffer) {
- fn print_entries(f: &mut Buffer, e: &FxHashSet<ItemEntry>, title: &str, class: &str) {
+ fn print_entries(f: &mut Buffer, e: &FxHashSet<ItemEntry>, kind: ItemSection) {
if !e.is_empty() {
let mut e: Vec<&ItemEntry> = e.iter().collect();
e.sort();
write!(
f,
- "<h3 id=\"{}\">{}</h3><ul class=\"{} docblock\">",
- title.replace(' ', "-"), // IDs cannot contain whitespaces.
- title,
- class
+ "<h3 id=\"{id}\">{title}</h3><ul class=\"all-items\">",
+ id = kind.id(),
+ title = kind.name(),
);
for s in e.iter() {
@@ -314,27 +364,23 @@ impl AllTypes {
}
}
- f.write_str(
- "<h1 class=\"fqn\">\
- <span class=\"in-band\">List of all items</span>\
- </h1>",
- );
+ f.write_str("<h1 class=\"fqn\">List of all items</h1>");
// Note: print_entries does not escape the title, because we know the current set of titles
// doesn't require escaping.
- print_entries(f, &self.structs, "Structs", "structs");
- print_entries(f, &self.enums, "Enums", "enums");
- print_entries(f, &self.unions, "Unions", "unions");
- print_entries(f, &self.primitives, "Primitives", "primitives");
- print_entries(f, &self.traits, "Traits", "traits");
- print_entries(f, &self.macros, "Macros", "macros");
- print_entries(f, &self.attributes, "Attribute Macros", "attributes");
- print_entries(f, &self.derives, "Derive Macros", "derives");
- print_entries(f, &self.functions, "Functions", "functions");
- print_entries(f, &self.typedefs, "Typedefs", "typedefs");
- print_entries(f, &self.trait_aliases, "Trait Aliases", "trait-aliases");
- print_entries(f, &self.opaque_tys, "Opaque Types", "opaque-types");
- print_entries(f, &self.statics, "Statics", "statics");
- print_entries(f, &self.constants, "Constants", "constants")
+ print_entries(f, &self.structs, ItemSection::Structs);
+ print_entries(f, &self.enums, ItemSection::Enums);
+ print_entries(f, &self.unions, ItemSection::Unions);
+ print_entries(f, &self.primitives, ItemSection::PrimitiveTypes);
+ print_entries(f, &self.traits, ItemSection::Traits);
+ print_entries(f, &self.macros, ItemSection::Macros);
+ print_entries(f, &self.attribute_macros, ItemSection::AttributeMacros);
+ print_entries(f, &self.derive_macros, ItemSection::DeriveMacros);
+ print_entries(f, &self.functions, ItemSection::Functions);
+ print_entries(f, &self.typedefs, ItemSection::TypeDefinitions);
+ print_entries(f, &self.trait_aliases, ItemSection::TraitAliases);
+ print_entries(f, &self.opaque_tys, ItemSection::OpaqueTypes);
+ print_entries(f, &self.statics, ItemSection::Statics);
+ print_entries(f, &self.constants, ItemSection::Constants);
}
}
@@ -348,9 +394,7 @@ fn scrape_examples_help(shared: &SharedContext<'_>) -> String {
let mut ids = IdMap::default();
format!(
"<div class=\"main-heading\">\
- <h1 class=\"fqn\">\
- <span class=\"in-band\">About scraped examples</span>\
- </h1>\
+ <h1 class=\"fqn\">About scraped examples</h1>\
</div>\
<div>{}</div>",
Markdown {
@@ -536,7 +580,6 @@ fn short_item_info(
parent: Option<&clean::Item>,
) -> Vec<String> {
let mut extra_info = vec![];
- let error_codes = cx.shared.codes;
if let Some(depr @ Deprecation { note, since, is_since_rustc_version: _, suggestion: _ }) =
item.deprecation(cx.tcx())
@@ -560,13 +603,7 @@ fn short_item_info(
if let Some(note) = note {
let note = note.as_str();
- let html = MarkdownHtml(
- note,
- &mut cx.id_map,
- error_codes,
- cx.shared.edition(),
- &cx.shared.playground,
- );
+ let html = MarkdownItemInfo(note, &mut cx.id_map);
message.push_str(&format!(": {}", html.into_string()));
}
extra_info.push(format!(
@@ -1239,6 +1276,15 @@ fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String {
if let Some((did, ty)) = decl.output.as_return().and_then(|t| Some((t.def_id(cx.cache())?, t)))
{
+ // Box has pass-through impls for Read, Write, Iterator, and Future when the
+ // boxed type implements one of those. We don't want to treat every Box return
+ // as being notably an Iterator (etc), though, so we exempt it. Pin has the same
+ // issue, with a pass-through impl for Future.
+ if Some(did) == cx.tcx().lang_items().owned_box()
+ || Some(did) == cx.tcx().lang_items().pin_type()
+ {
+ return "".to_string();
+ }
if let Some(impls) = cx.cache().impls.get(&did) {
for i in impls {
let impl_ = i.inner_impl();
@@ -1251,7 +1297,12 @@ fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String {
if let Some(trait_) = &impl_.trait_ {
let trait_did = trait_.def_id();
- if cx.cache().traits.get(&trait_did).map_or(false, |t| t.is_notable) {
+ if cx
+ .cache()
+ .traits
+ .get(&trait_did)
+ .map_or(false, |t| t.is_notable_trait(cx.tcx()))
+ {
if out.is_empty() {
write!(
&mut out,
@@ -1555,7 +1606,7 @@ fn render_impl(
link,
render_mode,
false,
- trait_.map(|t| &t.trait_),
+ trait_,
rendering_params,
);
}
@@ -1615,7 +1666,7 @@ fn render_impl(
&mut default_impl_items,
&mut impl_items,
cx,
- &t.trait_,
+ t,
i.inner_impl(),
&i.impl_item,
parent,
@@ -1747,7 +1798,7 @@ pub(crate) fn render_impl_summary(
write!(w, "<section id=\"{}\" class=\"impl has-srclink\"{}>", id, aliases);
render_rightside(w, cx, &i.impl_item, containing_item, RenderMode::Normal);
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
- write!(w, "<h3 class=\"code-header in-band\">");
+ write!(w, "<h3 class=\"code-header\">");
if let Some(use_absolute) = use_absolute {
write!(w, "{}", inner_impl.print(use_absolute, cx));
@@ -1811,12 +1862,12 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
buffer.write_str("<div class=\"sidebar-elems\">");
if it.is_crate() {
- write!(buffer, "<div class=\"block\"><ul>");
+ write!(buffer, "<ul class=\"block\">");
if let Some(ref version) = cx.cache().crate_version {
write!(buffer, "<li class=\"version\">Version {}</li>", Escape(version));
}
write!(buffer, "<li><a id=\"all-types\" href=\"all.html\">All Items</a></li>");
- buffer.write_str("</ul></div>");
+ buffer.write_str("</ul>");
}
match *it.kind {
@@ -1842,7 +1893,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
if !it.is_mod() {
let path: String = cx.current.iter().map(|s| s.as_str()).intersperse("::").collect();
- write!(buffer, "<h2 class=\"location\"><a href=\"index.html\">In {}</a></h2>", path);
+ write!(buffer, "<h2><a href=\"index.html\">In {}</a></h2>", path);
}
// Closes sidebar-elems div.
@@ -2216,21 +2267,8 @@ fn extract_for_impl_name(item: &clean::Item, cx: &Context<'_>) -> Option<(String
}
}
-/// Don't call this function directly!!! Use `print_sidebar_title` or `print_sidebar_block` instead!
-fn print_sidebar_title_inner(buf: &mut Buffer, id: &str, title: &str) {
- write!(
- buf,
- "<h3 class=\"sidebar-title\">\
- <a href=\"#{}\">{}</a>\
- </h3>",
- id, title
- );
-}
-
fn print_sidebar_title(buf: &mut Buffer, id: &str, title: &str) {
- buf.push_str("<div class=\"block\">");
- print_sidebar_title_inner(buf, id, title);
- buf.push_str("</div>");
+ write!(buf, "<h3><a href=\"#{}\">{}</a></h3>", id, title);
}
fn print_sidebar_block(
@@ -2239,13 +2277,12 @@ fn print_sidebar_block(
title: &str,
items: impl Iterator<Item = impl fmt::Display>,
) {
- buf.push_str("<div class=\"block\">");
- print_sidebar_title_inner(buf, id, title);
- buf.push_str("<ul>");
+ print_sidebar_title(buf, id, title);
+ buf.push_str("<ul class=\"block\">");
for item in items {
write!(buf, "<li>{}</li>", item);
}
- buf.push_str("</ul></div>");
+ buf.push_str("</ul>");
}
fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) {
@@ -2469,7 +2506,7 @@ fn sidebar_enum(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, e: &clean:
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-enum ItemSection {
+pub(crate) enum ItemSection {
Reexports,
PrimitiveTypes,
Modules,
@@ -2621,11 +2658,27 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection {
}
}
-fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
+pub(crate) fn sidebar_module_like(buf: &mut Buffer, item_sections_in_use: FxHashSet<ItemSection>) {
use std::fmt::Write as _;
let mut sidebar = String::new();
+ for &sec in ItemSection::ALL.iter().filter(|sec| item_sections_in_use.contains(sec)) {
+ let _ = write!(sidebar, "<li><a href=\"#{}\">{}</a></li>", sec.id(), sec.name());
+ }
+
+ if !sidebar.is_empty() {
+ write!(
+ buf,
+ "<section>\
+ <ul class=\"block\">{}</ul>\
+ </section>",
+ sidebar
+ );
+ }
+}
+
+fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
let item_sections_in_use: FxHashSet<_> = items
.iter()
.filter(|it| {
@@ -2640,21 +2693,8 @@ fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
})
.map(|it| item_ty_to_section(it.type_()))
.collect();
- for &sec in ItemSection::ALL.iter().filter(|sec| item_sections_in_use.contains(sec)) {
- let _ = write!(sidebar, "<li><a href=\"#{}\">{}</a></li>", sec.id(), sec.name());
- }
- if !sidebar.is_empty() {
- write!(
- buf,
- "<section>\
- <div class=\"block\">\
- <ul>{}</ul>\
- </div>\
- </section>",
- sidebar
- );
- }
+ sidebar_module_like(buf, item_sections_in_use);
}
fn sidebar_foreign_type(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item) {
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index cfa450942..632781736 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -400,7 +400,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
if myitem.fn_header(cx.tcx()).unwrap().unsafety
== hir::Unsafety::Unsafe =>
{
- "<a title=\"unsafe function\" href=\"#\"><sup>âš </sup></a>"
+ "<sup title=\"unsafe function\">âš </sup>"
}
_ => "",
};
@@ -514,7 +514,7 @@ fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &cle
+ name.as_str().len()
+ generics_len;
- wrap_into_docblock(w, |w| {
+ wrap_into_item_decl(w, |w| {
wrap_item(w, "fn", |w| {
render_attributes_in_pre(w, it, "");
w.reserve(header_len);
@@ -553,7 +553,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
cx.tcx().trait_def(t.def_id).must_implement_one_of.clone();
// Output the trait definition
- wrap_into_docblock(w, |w| {
+ wrap_into_item_decl(w, |w| {
wrap_item(w, "trait", |w| {
render_attributes_in_pre(w, it, "");
write!(
@@ -716,9 +716,9 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
document(&mut content, cx, m, Some(t), HeadingOffset::H5);
let toggled = !content.is_empty();
if toggled {
- write!(w, "<details class=\"rustdoc-toggle\" open><summary>");
+ write!(w, "<details class=\"rustdoc-toggle method-toggle\" open><summary>");
}
- write!(w, "<div id=\"{}\" class=\"method has-srclink\">", id);
+ write!(w, "<section id=\"{}\" class=\"method has-srclink\">", id);
render_rightside(w, cx, m, t, RenderMode::Normal);
write!(w, "<h4 class=\"code-header\">");
render_assoc_item(
@@ -730,7 +730,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
RenderMode::Normal,
);
w.write_str("</h4>");
- w.write_str("</div>");
+ w.write_str("</section>");
if toggled {
write!(w, "</summary>");
w.push_buffer(content);
@@ -890,7 +890,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
w,
"implementors",
"Implementors",
- "<div class=\"item-list\" id=\"implementors-list\">",
+ "<div id=\"implementors-list\">",
);
for implementor in concrete {
render_implementor(cx, implementor, it, w, &implementor_dups, &[]);
@@ -902,7 +902,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
w,
"synthetic-implementors",
"Auto implementors",
- "<div class=\"item-list\" id=\"synthetic-implementors-list\">",
+ "<div id=\"synthetic-implementors-list\">",
);
for implementor in synthetic {
render_implementor(
@@ -923,7 +923,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
w,
"implementors",
"Implementors",
- "<div class=\"item-list\" id=\"implementors-list\"></div>",
+ "<div id=\"implementors-list\"></div>",
);
if t.is_auto(cx.tcx()) {
@@ -931,7 +931,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
w,
"synthetic-implementors",
"Auto implementors",
- "<div class=\"item-list\" id=\"synthetic-implementors-list\"></div>",
+ "<div id=\"synthetic-implementors-list\"></div>",
);
}
}
@@ -1033,7 +1033,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
}
fn item_trait_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::TraitAlias) {
- wrap_into_docblock(w, |w| {
+ wrap_into_item_decl(w, |w| {
wrap_item(w, "trait-alias", |w| {
render_attributes_in_pre(w, it, "");
write!(
@@ -1057,7 +1057,7 @@ fn item_trait_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &
}
fn item_opaque_ty(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::OpaqueTy) {
- wrap_into_docblock(w, |w| {
+ wrap_into_item_decl(w, |w| {
wrap_item(w, "opaque", |w| {
render_attributes_in_pre(w, it, "");
write!(
@@ -1096,7 +1096,7 @@ fn item_typedef(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clea
});
}
- wrap_into_docblock(w, |w| write_content(w, cx, it, t));
+ wrap_into_item_decl(w, |w| write_content(w, cx, it, t));
document(w, cx, it, None, HeadingOffset::H2);
@@ -1110,7 +1110,7 @@ fn item_typedef(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clea
}
fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean::Union) {
- wrap_into_docblock(w, |w| {
+ wrap_into_item_decl(w, |w| {
wrap_item(w, "union", |w| {
render_attributes_in_pre(w, it, "");
render_union(w, it, Some(&s.generics), &s.fields, "", cx);
@@ -1174,7 +1174,7 @@ fn print_tuple_struct_fields(w: &mut Buffer, cx: &Context<'_>, s: &[clean::Item]
fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::Enum) {
let count_variants = e.variants().count();
- wrap_into_docblock(w, |w| {
+ wrap_into_item_decl(w, |w| {
wrap_item(w, "enum", |w| {
render_attributes_in_pre(w, it, "");
write!(
@@ -1333,14 +1333,14 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
}
fn item_macro(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::Macro) {
- wrap_into_docblock(w, |w| {
+ wrap_into_item_decl(w, |w| {
highlight::render_macro_with_highlighting(&t.source, w);
});
document(w, cx, it, None, HeadingOffset::H2)
}
fn item_proc_macro(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, m: &clean::ProcMacro) {
- wrap_into_docblock(w, |w| {
+ wrap_into_item_decl(w, |w| {
let name = it.name.expect("proc-macros always have names");
match m.kind {
MacroKind::Bang => {
@@ -1387,7 +1387,7 @@ fn item_primitive(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item) {
}
fn item_constant(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, c: &clean::Constant) {
- wrap_into_docblock(w, |w| {
+ wrap_into_item_decl(w, |w| {
wrap_item(w, "const", |w| {
render_attributes_in_code(w, it);
@@ -1436,7 +1436,7 @@ fn item_constant(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, c: &cle
}
fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean::Struct) {
- wrap_into_docblock(w, |w| {
+ wrap_into_item_decl(w, |w| {
wrap_item(w, "struct", |w| {
render_attributes_in_code(w, it);
render_struct(w, it, Some(&s.generics), s.struct_type, &s.fields, "", true, cx);
@@ -1489,7 +1489,7 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
}
fn item_static(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean::Static) {
- wrap_into_docblock(w, |w| {
+ wrap_into_item_decl(w, |w| {
wrap_item(w, "static", |w| {
render_attributes_in_code(w, it);
write!(
@@ -1506,7 +1506,7 @@ fn item_static(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
}
fn item_foreign_type(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item) {
- wrap_into_docblock(w, |w| {
+ wrap_into_item_decl(w, |w| {
wrap_item(w, "foreigntype", |w| {
w.write_str("extern {\n");
render_attributes_in_code(w, it);
@@ -1595,11 +1595,11 @@ fn bounds(t_bounds: &[clean::GenericBound], trait_alias: bool, cx: &Context<'_>)
bounds
}
-fn wrap_into_docblock<F>(w: &mut Buffer, f: F)
+fn wrap_into_item_decl<F>(w: &mut Buffer, f: F)
where
F: FnOnce(&mut Buffer),
{
- w.write_str("<div class=\"docblock item-decl\">");
+ w.write_str("<div class=\"item-decl\">");
f(w);
w.write_str("</div>")
}
diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs
index fc4d46fe6..85f63c985 100644
--- a/src/librustdoc/html/render/write_shared.rs
+++ b/src/librustdoc/html/render/write_shared.rs
@@ -517,14 +517,12 @@ if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};
};
let content = format!(
- "<h1 class=\"fqn\">\
- <span class=\"in-band\">List of all crates</span>\
- </h1><ul class=\"crate mod\">{}</ul>",
+ "<h1 class=\"fqn\">List of all crates</h1><ul class=\"all-items\">{}</ul>",
krates
.iter()
.map(|s| {
format!(
- "<li><a class=\"crate mod\" href=\"{}index.html\">{}</a></li>",
+ "<li><a href=\"{}index.html\">{}</a></li>",
ensure_trailing_slash(s),
s
)
diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs
index 2e2bee78b..7ab65bff3 100644
--- a/src/librustdoc/html/sources.rs
+++ b/src/librustdoc/html/sources.rs
@@ -274,7 +274,7 @@ pub(crate) fn print_src(
) {
let lines = s.lines().count();
let mut line_numbers = Buffer::empty_from(buf);
- line_numbers.write_str("<pre class=\"line-numbers\">");
+ line_numbers.write_str("<pre class=\"src-line-numbers\">");
match source_context {
SourceContext::Standalone => {
for line in 1..=lines {
diff --git a/src/librustdoc/html/static/css/noscript.css b/src/librustdoc/html/static/css/noscript.css
index 0a19a99ab..301f03a16 100644
--- a/src/librustdoc/html/static/css/noscript.css
+++ b/src/librustdoc/html/static/css/noscript.css
@@ -14,7 +14,11 @@ rules.
display: none;
}
-.sub {
+nav.sub {
/* The search bar and related controls don't work without JS */
display: none;
}
+
+.source .sidebar {
+ display: none;
+}
diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index bb35970eb..1cc954a98 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -132,19 +132,29 @@ h1, h2, h3, h4, h5, h6 {
font-weight: 500;
}
h1, h2, h3, h4 {
- margin: 20px 0 15px 0;
+ margin: 25px 0 15px 0;
padding-bottom: 6px;
}
.docblock h3, .docblock h4, h5, h6 {
margin: 15px 0 5px 0;
}
+.docblock > h2:first-child,
+.docblock > h3:first-child,
+.docblock > h4:first-child,
+.docblock > h5:first-child,
+.docblock > h6:first-child {
+ margin-top: 0;
+}
h1.fqn {
margin: 0;
padding: 0;
- border-bottom-color: var(--headings-border-bottom-color);
-}
-h2, h3, h4 {
- border-bottom-color: var(--headings-border-bottom-color);
+ flex-grow: 1;
+ /* We use overflow-wrap: break-word for Safari, which doesn't recognize
+ `anywhere`: https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap */
+ overflow-wrap: break-word;
+ /* Then override it with `anywhere`, which is required to make non-Safari browsers break
+ more aggressively when we want them to. */
+ overflow-wrap: anywhere;
}
.main-heading {
display: flex;
@@ -153,9 +163,6 @@ h2, h3, h4 {
padding-bottom: 6px;
margin-bottom: 15px;
}
-.main-heading a:hover {
- text-decoration: underline;
-}
#toggle-all-docs {
text-decoration: none;
}
@@ -164,7 +171,7 @@ h2, h3, h4 {
Rustdoc-generated h2 section headings (e.g. "Implementations", "Required Methods", etc)
Underlines elsewhere in the documentation break up visual flow and tend to invert
section hierarchies. */
-h2,
+.content h2,
.top-doc .docblock > h3,
.top-doc .docblock > h4 {
border-bottom: 1px solid var(--headings-border-bottom-color);
@@ -177,48 +184,28 @@ h4.code-header {
}
.code-header {
font-weight: 600;
- border-bottom-style: none;
margin: 0;
padding: 0;
- margin-top: 0.6em;
- margin-bottom: 0.4em;
-}
-.impl,
-.impl-items .method,
-.methods .method,
-.impl-items .type,
-.methods .type,
-.impl-items .associatedconstant,
-.methods .associatedconstant,
-.impl-items .associatedtype,
-.methods .associatedtype {
- flex-basis: 100%;
- font-weight: 600;
- position: relative;
}
+#crate-search,
h1, h2, h3, h4, h5, h6,
.sidebar,
.mobile-topbar,
-a.source,
.search-input,
.search-results .result-name,
.item-left > a,
.out-of-band,
span.since,
-details.rustdoc-toggle > summary::before,
-.content ul.crate a.crate,
a.srclink,
-#help-button > button,
+#help-button > a,
details.rustdoc-toggle.top-doc > summary,
-details.rustdoc-toggle.top-doc > summary::before,
details.rustdoc-toggle.non-exhaustive > summary,
-details.rustdoc-toggle.non-exhaustive > summary::before,
.scraped-example-title,
.more-examples-toggle summary, .more-examples-toggle .hide-more,
.example-links a,
/* This selector is for the items listed in the "all items" page. */
-#main-content > ul.docblock > li > a {
+ul.all-items {
font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif;
}
@@ -230,14 +217,14 @@ pre.rust a,
.sidebar h2 a,
.sidebar h3 a,
.mobile-topbar h2 a,
-.in-band a,
+h1 a,
.search-results a,
.module-item .stab,
.import-item .stab,
.result-name .primitive > i, .result-name .keyword > i,
-.content .method .where,
-.content .fn .where,
-.content .where.fmt-newline {
+.method .where,
+.fn .where,
+.where.fmt-newline {
color: var(--main-color);
}
@@ -274,7 +261,7 @@ pre.rust a,
color: var(--macro-link-color);
}
-.content span.mod, .content a.mod, .block a.current.mod {
+.content span.mod, .content a.mod {
color: var(--mod-link-color);
}
@@ -299,32 +286,14 @@ p {
https://www.w3.org/WAI/WCAG21/Understanding/visual-presentation.html */
margin: 0 0 .75em 0;
}
-
-summary {
- outline: none;
+/* For the last child of a div, the margin will be taken care of
+ by the margin-top of the next item. */
+p:last-child {
+ margin: 0;
}
/* Fix some style changes due to normalize.css 8 */
-td,
-th {
- padding: 0;
-}
-
-table {
- border-collapse: collapse;
-}
-
-button,
-input,
-optgroup,
-select,
-textarea {
- color: inherit;
- font: inherit;
- margin: 0;
-}
-
button {
/* Buttons on Safari have different default padding than other platforms. Make them the same. */
padding: 1px 6px;
@@ -375,9 +344,6 @@ code, pre, a.test-arrow, .code-header {
pre {
padding: 14px;
}
-.docblock.item-decl {
- margin-left: 0;
-}
.item-decl pre {
overflow-x: auto;
}
@@ -394,22 +360,11 @@ img {
overflow: visible;
}
-.sub-container {
- display: flex;
- flex-direction: row;
- flex-wrap: nowrap;
-}
-
.sub-logo-container {
- display: none;
- margin-right: 20px;
+ line-height: 0;
}
-.source .sub-logo-container {
- display: block;
-}
-
-.source .sub-logo-container > img {
+.sub-logo-container > img {
height: 60px;
width: 60px;
object-fit: contain;
@@ -421,7 +376,7 @@ img {
.sidebar {
font-size: 0.875rem;
- width: 250px;
+ width: 200px;
min-width: 200px;
overflow-y: scroll;
position: sticky;
@@ -430,15 +385,6 @@ img {
left: 0;
}
-.sidebar-elems,
-.sidebar > .location {
- padding-left: 24px;
-}
-
-.sidebar .location {
- overflow-wrap: anywhere;
-}
-
.rustdoc.source .sidebar {
width: 50px;
min-width: 0px;
@@ -452,10 +398,6 @@ img {
overflow-y: hidden;
}
-.rustdoc.source .sidebar .sidebar-logo {
- display: none;
-}
-
.source .sidebar, #sidebar-toggle, #source-sidebar {
background-color: var(--sidebar-background-color);
}
@@ -465,16 +407,15 @@ img {
}
.source .sidebar > *:not(#sidebar-toggle) {
- opacity: 0;
visibility: hidden;
}
.source-sidebar-expanded .source .sidebar {
overflow-y: auto;
+ width: 300px;
}
.source-sidebar-expanded .source .sidebar > *:not(#sidebar-toggle) {
- opacity: 1;
visibility: visible;
}
@@ -532,22 +473,15 @@ img {
width: 100px;
}
-.location:empty {
- border: none;
-}
-
-.location a:first-of-type {
- font-weight: 500;
-}
-
-.block ul, .block li {
+ul.block, .block li {
padding: 0;
margin: 0;
list-style: none;
}
.block a,
-h2.location a {
+.sidebar h2 a,
+.sidebar h3 a {
display: block;
padding: 0.25rem;
margin-left: -0.25rem;
@@ -557,8 +491,7 @@ h2.location a {
}
.sidebar h2 {
- border-bottom: none;
- font-weight: 500;
+ overflow-wrap: anywhere;
padding: 0;
margin: 0;
margin-top: 0.7rem;
@@ -567,11 +500,23 @@ h2.location a {
.sidebar h3 {
font-size: 1.125rem; /* 18px */
- font-weight: 500;
padding: 0;
margin: 0;
}
+.sidebar-elems,
+.sidebar > h2 {
+ padding-left: 24px;
+}
+
+.sidebar a, .sidebar .current {
+ color: var(--sidebar-link-color);
+}
+.sidebar .current,
+.sidebar a:hover {
+ background-color: var(--sidebar-current-link-background-color);
+}
+
.sidebar-elems .block {
margin-bottom: 2em;
}
@@ -585,66 +530,61 @@ h2.location a {
}
.source .content pre.rust {
- white-space: pre;
overflow: auto;
padding-left: 0;
}
.rustdoc .example-wrap {
- display: inline-flex;
+ display: flex;
+ position: relative;
margin-bottom: 10px;
}
+/* For the last child of a div, the margin will be taken care of
+ by the margin-top of the next item. */
+.rustdoc .example-wrap:last-child {
+ margin-bottom: 0px;
+}
-.example-wrap {
- position: relative;
- width: 100%;
+.rustdoc .example-wrap > pre {
+ margin: 0;
+ flex-grow: 1;
+ overflow-x: auto;
}
-.example-wrap > pre.line-number {
+.rustdoc .example-wrap > pre.example-line-numbers,
+.rustdoc .example-wrap > pre.src-line-numbers {
+ flex-grow: 0;
overflow: initial;
+ text-align: right;
+ -webkit-user-select: none;
+ -moz-user-select: none;
+ -ms-user-select: none;
+ user-select: none;
+}
+
+.example-line-numbers {
border: 1px solid;
padding: 13px 8px;
- text-align: right;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
+ border-color: var(--example-line-numbers-border-color);
}
-.example-wrap > pre.rust a:hover {
- text-decoration: underline;
-}
-
-.line-numbers {
- text-align: right;
-}
-.rustdoc:not(.source) .example-wrap > pre:not(.line-number) {
- width: 100%;
- overflow-x: auto;
+.src-line-numbers span {
+ cursor: pointer;
+ color: var(--src-line-numbers-span-color);
}
-
-.rustdoc:not(.source) .example-wrap > pre.line-numbers {
- width: auto;
- overflow-x: visible;
+.src-line-numbers .line-highlighted {
+ background-color: var(--src-line-number-highlighted-background-color);
}
-
-.rustdoc .example-wrap > pre {
- margin: 0;
+.src-line-numbers :target {
+ background-color: transparent;
}
.search-loading {
text-align: center;
}
-.content > .example-wrap pre.line-numbers {
- position: relative;
- -webkit-user-select: none;
- -moz-user-select: none;
- -ms-user-select: none;
- user-select: none;
-}
-.line-numbers span {
- cursor: pointer;
-}
-
.docblock-short {
overflow-wrap: break-word;
overflow-wrap: anywhere;
@@ -669,9 +609,6 @@ h2.location a {
.docblock h5 { font-size: 1rem; }
.docblock h6 { font-size: 0.875rem; }
-.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 {
- border-bottom-color: var(--headings-border-bottom-color);
-}
.docblock {
margin-left: 24px;
@@ -683,33 +620,9 @@ h2.location a {
overflow-x: auto;
}
-.content .out-of-band {
+.out-of-band {
flex-grow: 0;
font-size: 1.125rem;
- font-weight: normal;
- float: right;
-}
-
-.method > .code-header, .trait-impl > .code-header {
- max-width: calc(100% - 41px);
- display: block;
-}
-
-.content .in-band {
- flex-grow: 1;
- margin: 0px;
- padding: 0px;
- /* We use overflow-wrap: break-word for Safari, which doesn't recognize
- `anywhere`: https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap */
- overflow-wrap: break-word;
- /* Then override it with `anywhere`, which is required to make non-Safari browsers break
- more aggressively when we want them to. */
- overflow-wrap: anywhere;
- background-color: var(--main-background-color);
-}
-
-.in-band > code, .in-band > .code-header {
- display: inline-block;
}
.docblock code, .docblock-short code,
@@ -726,6 +639,7 @@ pre, .rustdoc.source .example-wrap {
width: calc(100% - 2px);
overflow-x: auto;
display: block;
+ border-collapse: collapse;
}
.docblock table td {
@@ -740,38 +654,21 @@ pre, .rustdoc.source .example-wrap {
border: 1px solid var(--border-color);
}
-.content .item-list {
- list-style-type: none;
- padding: 0;
-}
-
-.content > .methods > .method {
- font-size: 1rem;
- position: relative;
-}
/* Shift "where ..." part of method or fn definition down a line */
-.content .method .where,
-.content .fn .where,
-.content .where.fmt-newline {
+.method .where,
+.fn .where,
+.where.fmt-newline {
display: block;
font-size: 0.875rem;
}
.item-info {
display: block;
-}
-
-.content .item-info code {
- font-size: 0.875rem;
-}
-
-.content .item-info {
- position: relative;
margin-left: 24px;
}
-.content .impl-items .docblock, .content .impl-items .item-info {
- margin-bottom: .6em;
+.item-info code {
+ font-size: 0.875rem;
}
#main-content > .item-info {
@@ -780,16 +677,24 @@ pre, .rustdoc.source .example-wrap {
}
nav.sub {
+ flex-grow: 1;
+ flex-flow: row nowrap;
+ margin: 4px 0 25px 0;
+ display: flex;
+ align-items: center;
+}
+.search-form {
position: relative;
- font-size: 1rem;
+ display: flex;
+ height: 34px;
flex-grow: 1;
- margin-bottom: 25px;
}
.source nav.sub {
+ margin: 0 0 15px 0;
+}
+.source .search-form {
margin-left: 32px;
}
-nav.sum { text-align: right; }
-nav.sub form { display: inline; }
a {
text-decoration: none;
@@ -805,9 +710,7 @@ a {
display: initial;
}
-.in-band:hover > .anchor, .impl:hover > .anchor, .method.trait-impl:hover > .anchor,
-.type.trait-impl:hover > .anchor, .associatedconstant.trait-impl:hover > .anchor,
-.associatedtype.trait-impl:hover > .anchor {
+.impl:hover > .anchor, .trait-impl:hover > .anchor {
display: inline-block;
position: absolute;
}
@@ -831,12 +734,16 @@ h2.small-section-header > .anchor {
content: '§';
}
-.docblock a:not(.srclink):not(.test-arrow):not(.scrape-help):hover,
-.docblock-short a:not(.srclink):not(.test-arrow):not(.scrape-help):hover, .item-info a {
+.main-heading a:hover,
+.example-wrap > pre.rust a:hover,
+.all-items a:hover,
+.docblock a:not(.test-arrow):not(.scrape-help):hover,
+.docblock-short a:not(.test-arrow):not(.scrape-help):hover,
+.item-info a {
text-decoration: underline;
}
-.block a.current.crate { font-weight: 500; }
+.crate.block a.current { font-weight: 500; }
/* In most contexts we use `overflow-wrap: anywhere` to ensure that we can wrap
as much as needed on mobile (see
@@ -876,15 +783,6 @@ table,
padding-right: 1.25rem;
}
-.search-container {
- position: relative;
- display: flex;
- height: 34px;
- margin-top: 4px;
-}
-.search-container > * {
- height: 100%;
-}
.search-results-title {
margin-top: 0;
white-space: nowrap;
@@ -922,6 +820,9 @@ table,
/* Removes default arrow from firefox */
text-indent: 0.01px;
background-color: var(--main-background-color);
+ color: inherit;
+ line-height: 1.5;
+ font-weight: 500;
}
/* cancel stylistic differences in padding in firefox
for "appearance: none"-style (or equivalent) <select>s */
@@ -957,18 +858,14 @@ so that we can apply CSS-filters to change the arrow color in themes */
-webkit-appearance: textfield for search inputs. That
causes rounded corners and no border on iOS Safari. */
-webkit-appearance: none;
- /* Override Normalize.css: we have margins and do
- not want to overflow - the `moz` attribute is necessary
- until Firefox 29, too early to drop at this point */
- -moz-box-sizing: border-box !important;
- box-sizing: border-box !important;
outline: none;
border: 1px solid var(--border-color);
border-radius: 2px;
padding: 8px;
font-size: 1rem;
- width: 100%;
+ flex-grow: 1;
background-color: var(--button-background-color);
+ color: var(--search-color);
}
.search-input:focus {
border-color: var(--search-input-focused-border-color);
@@ -1005,13 +902,18 @@ so that we can apply CSS-filters to change the arrow color in themes */
flex-flow: row wrap;
}
-.search-results .result-name, .search-results div.desc, .search-results .result-description {
+.search-results .result-name, .search-results div.desc {
width: 50%;
}
.search-results .result-name {
padding-right: 1em;
}
+.search-results a:hover,
+.search-results a:focus {
+ background-color: var(--search-result-link-focus-background-color);
+}
+
.popover {
font-size: 1rem;
position: absolute;
@@ -1042,40 +944,36 @@ so that we can apply CSS-filters to change the arrow color in themes */
color: var(--main-color);
}
-#help-button .popover {
+/* use larger max-width for help popover, but not for help.html */
+#help.popover {
max-width: 600px;
}
-#help-button .popover::before {
+#help.popover::before {
right: 48px;
}
-#help-button dt {
+#help dt {
float: left;
clear: left;
display: block;
margin-right: 0.5rem;
}
-#help-button span.top, #help-button span.bottom {
+#help span.top, #help span.bottom {
text-align: center;
display: block;
font-size: 1.125rem;
}
-#help-button span.top {
- text-align: center;
- display: block;
+#help span.top {
margin: 10px 0;
border-bottom: 1px solid var(--border-color);
padding-bottom: 4px;
margin-bottom: 6px;
}
-#help-button span.bottom {
+#help span.bottom {
clear: both;
border-top: 1px solid var(--border-color);
}
-.side-by-side {
- text-align: initial;
-}
.side-by-side > div {
width: 50%;
float: left;
@@ -1097,10 +995,13 @@ so that we can apply CSS-filters to change the arrow color in themes */
margin-bottom: 5px;
font-size: 0.875rem;
font-weight: normal;
+ color: var(--main-color);
+ background-color: var(--stab-background-color);
}
-.stab p {
- display: inline;
- margin: 0;
+
+.stab.portability > code {
+ background: none;
+ color: var(--stab-code-color);
}
.stab .emoji {
@@ -1108,6 +1009,12 @@ so that we can apply CSS-filters to change the arrow color in themes */
margin-right: 0.3rem;
}
+/* This is to prevent the `.stab` elements to overflow the .docblock elements. */
+.docblock .stab {
+ padding: 0 0.125em;
+ margin-bottom: 0;
+}
+
/* Black one-pixel outline around emoji shapes */
.emoji {
text-shadow:
@@ -1142,7 +1049,6 @@ so that we can apply CSS-filters to change the arrow color in themes */
.rightside {
padding-left: 12px;
padding-right: 2px;
- position: initial;
float: right;
}
@@ -1151,23 +1057,55 @@ so that we can apply CSS-filters to change the arrow color in themes */
color: var(--right-side-color);
}
-
-.impl-items .srclink, .impl .srclink, .methods .srclink {
- /* Override header settings otherwise it's too bold */
- font-weight: normal;
- font-size: 1rem;
+pre.rust {
+ tab-size: 4;
+ -moz-tab-size: 4;
}
-td.summary-column {
- width: 100%;
+/* Code highlighting */
+pre.rust .kw {
+ color: var(--code-highlight-kw-color);
}
-
-.summary {
- padding-right: 0px;
+pre.rust .kw-2 {
+ color: var(--code-highlight-kw-2-color);
+}
+pre.rust .lifetime {
+ color: var(--code-highlight-lifetime-color);
+}
+pre.rust .prelude-ty {
+ color: var(--code-highlight-prelude-color);
+}
+pre.rust .prelude-val {
+ color: var(--code-highlight-prelude-val-color);
+}
+pre.rust .string {
+ color: var(--code-highlight-string-color);
+}
+pre.rust .number {
+ color: var(--code-highlight-number-color);
+}
+pre.rust .bool-val {
+ color: var(--code-highlight-literal-color);
+}
+pre.rust .self {
+ color: var(--code-highlight-self-color);
+}
+pre.rust .attribute {
+ color: var(--code-highlight-attribute-color);
+}
+pre.rust .macro,
+pre.rust .macro-nonterminal {
+ color: var(--code-highlight-macro-color);
}
-
pre.rust .question-mark {
font-weight: bold;
+ color: var(--code-highlight-question-mark-color);
+}
+pre.rust .comment {
+ color: var(--code-highlight-comment-color);
+}
+pre.rust .doccomment {
+ color: var(--code-highlight-doc-comment-color);
}
.example-wrap.compile_fail,
@@ -1278,9 +1216,6 @@ a.test-arrow {
.example-wrap:hover .test-arrow {
visibility: visible;
}
-a.test-arrow:hover {
- text-decoration: none;
-}
.code-attribute {
font-weight: 300;
@@ -1300,13 +1235,11 @@ h3.variant {
font-weight: 600;
font-size: 1.125rem;
margin-bottom: 10px;
- border-bottom: none;
}
.sub-variant h4 {
font-size: 1rem;
font-weight: 400;
- border-bottom: none;
margin-top: 0;
margin-bottom: 0;
}
@@ -1357,7 +1290,7 @@ h3.variant {
content: "\00a0\00a0\00a0";
}
-.notable-traits .notable, .notable-traits .docblock {
+.notable-traits .docblock {
margin: 0;
}
@@ -1375,16 +1308,6 @@ h3.variant {
font-size: 1.25rem;
}
-/* Example code has the "Run" button that needs to be positioned relative to the pre */
-pre.rust.rust-example-rendered {
- position: relative;
-}
-
-pre.rust {
- tab-size: 4;
- -moz-tab-size: 4;
-}
-
.search-failed {
text-align: center;
margin-top: 20px;
@@ -1416,6 +1339,8 @@ pre.rust {
border: 0;
border-top: 2px solid;
flex: 1;
+ line-height: 1.5;
+ color: inherit;
}
#titles > button > div.count {
@@ -1433,7 +1358,6 @@ pre.rust {
position: sticky;
top: 0;
left: 0;
- font-weight: bold;
font-size: 1.25rem;
border-bottom: 1px solid;
display: flex;
@@ -1444,7 +1368,6 @@ pre.rust {
}
#source-sidebar {
width: 100%;
- z-index: 1;
overflow: auto;
}
#source-sidebar > .title {
@@ -1454,6 +1377,8 @@ pre.rust {
margin-bottom: 6px;
}
#sidebar-toggle > button {
+ font-size: inherit;
+ font-weight: bold;
background: none;
color: inherit;
cursor: pointer;
@@ -1476,23 +1401,29 @@ pre.rust {
outline: none;
}
-#settings-menu > a, #help-button > button, #copy-path {
- padding: 5px;
+#settings-menu > a, #help-button > a, #copy-path {
width: 33px;
- border: 1px solid var(--border-color);
- border-radius: 2px;
cursor: pointer;
+ line-height: 1.5;
}
-#settings-menu > a, #help-button > button {
+#settings-menu > a, #help-button > a {
padding: 5px;
height: 100%;
display: block;
background-color: var(--button-background-color);
+ border: 1px solid var(--border-color);
+ border-radius: 2px;
}
#copy-path {
color: var(--copy-path-button-color);
+ background: var(--main-background-color);
+ height: 34px;
+ margin-left: 10px;
+ padding: 0;
+ padding-left: 2px;
+ border: 0;
}
#copy-path > img {
filter: var(--copy-path-img-filter);
@@ -1513,26 +1444,7 @@ pre.rust {
animation: rotating 2s linear infinite;
}
-.setting-line .radio-line input:checked {
- box-shadow: inset 0 0 0 3px var(--main-background-color);
- background-color: var(--settings-input-color);
-}
-.setting-line .radio-line input:focus {
- box-shadow: 0 0 1px 1px var(--settings-input-color);
-}
-/* In here we combine both `:focus` and `:checked` properties. */
-.setting-line .radio-line input:checked:focus {
- box-shadow: inset 0 0 0 3px var(--main-background-color),
- 0 0 2px 2px var(--settings-input-color);
-}
-.setting-line .radio-line input:hover {
- border-color: var(--settings-input-color) !important;
-}
-input:checked + .slider {
- background-color: var(--settings-input-color);
-}
-
-#help-button > button {
+#help-button > a {
text-align: center;
/* Rare exception to specifying font sizes in rem. Since this is acting
as an icon, it's okay to specify their sizes in pixels. */
@@ -1540,15 +1452,6 @@ input:checked + .slider {
padding-top: 2px;
}
-#copy-path {
- height: 34px;
- background-color: var(--main-background-color);
- margin-left: 10px;
- padding: 0;
- padding-left: 2px;
- border: 0;
-}
-
kbd {
display: inline-block;
padding: 3px 5px;
@@ -1560,25 +1463,39 @@ kbd {
cursor: default;
}
-#main-content > ul {
- padding-left: 10px;
-}
-#main-content > ul > li {
+ul.all-items > li {
list-style: none;
}
-.non-exhaustive {
- margin-bottom: 1em;
-}
-
details.dir-entry {
padding-left: 4px;
}
+details.dir-entry > summary::after {
+ content: " â–º";
+ position: absolute;
+ left: -15px;
+ top: 0px;
+ font-size: 80%;
+ padding: 2px 0px;
+ /* set width to cover gap between arrow and text */
+ width: 25px;
+}
+
+details[open].dir-entry > summary::after {
+ content: " â–¼";
+}
+
+details.dir-entry > summary::-webkit-details-marker,
+details.dir-entry > summary::marker {
+ display: none;
+}
+
details.dir-entry > summary {
margin: 0 0 0 13px;
- list-style-position: outside;
+ list-style: none;
cursor: pointer;
+ position: relative;
}
details.dir-entry div.folders, details.dir-entry div.files {
@@ -1589,6 +1506,17 @@ details.dir-entry a {
display: block;
}
+/* We use CSS containment on the details elements because most sizeable elements
+ of the page are contained in one of these. This also makes re-rendering
+ faster on document changes (like closing and opening toggles).
+ Unfortunately we can't yet specify contain: content or contain: strict
+ because the [-]/[+] toggles extend past the boundaries of the <details>
+ https://developer.mozilla.org/en-US/docs/Web/CSS/contain */
+details.rustdoc-toggle {
+ contain: layout;
+ position: relative;
+}
+
/* The hideme class is used on summary tags that contain a span with
placeholder text shown only when the toggle is closed. For instance,
"Expand description" or "Show methods". */
@@ -1598,6 +1526,8 @@ details.rustdoc-toggle > summary.hideme {
details.rustdoc-toggle > summary {
list-style: none;
+ /* focus outline is shown on `::before` instead of this */
+ outline: none;
}
details.rustdoc-toggle > summary::-webkit-details-marker,
details.rustdoc-toggle > summary::marker {
@@ -1621,7 +1551,6 @@ details.rustdoc-toggle > summary::before {
}
details.rustdoc-toggle > summary.hideme > span,
-details.rustdoc-toggle > summary::before,
.more-examples-toggle summary, .more-examples-toggle .hide-more {
color: var(--toggles-color);
}
@@ -1646,6 +1575,15 @@ details.rustdoc-toggle > summary:hover::before {
opacity: 1;
}
+details.rustdoc-toggle > summary:focus-visible::before {
+ /* The SVG is black, and gets turned white using a filter in the dark themes.
+ Do the same with the outline.
+ The dotted 1px style is copied from Firefox's focus ring style.
+ */
+ outline: 1px dotted #000;
+ outline-offset: 1px;
+}
+
details.rustdoc-toggle.top-doc > summary,
details.rustdoc-toggle.top-doc > summary::before,
details.rustdoc-toggle.non-exhaustive > summary,
@@ -1681,10 +1619,6 @@ details.rustdoc-toggle[open] > summary.hideme {
position: absolute;
}
-details.rustdoc-toggle {
- position: relative;
-}
-
details.rustdoc-toggle[open] > summary.hideme > span {
display: none;
}
@@ -1718,37 +1652,20 @@ details.rustdoc-toggle[open] > summary.hideme::after {
display: inline-block;
}
-/* Media Queries */
-
-/*
-WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY;
-If you update this line, then you also need to update the line with the same warning
-in storage.js plus the media query with (max-width: 700px)
-*/
-@media (min-width: 701px) {
- /* In case there is no documentation before a code block, we need to add some margin at the top
- to prevent an overlay between the "collapse toggle" and the information tooltip.
- However, it's not needed with smaller screen width because the doc/code block is always put
- "one line" below. */
- .docblock > .example-wrap:first-child .tooltip {
- margin-top: 16px;
- }
-
- /* When we expand the sidebar on the source code page, we hide the logo on the left of the
- search bar to have more space. */
- .source-sidebar-expanded .source .sidebar + main .width-limiter .sub-logo-container.rust-logo {
- display: none;
- }
-
- .source-sidebar-expanded .source .sidebar {
- width: 300px;
- }
+/* In case there is no documentation before a code block, we need to add some margin at the top
+to prevent an overlay between the "collapse toggle" and the information tooltip.
+However, it's not needed with smaller screen width because the doc/code block is always put
+"one line" below. */
+.docblock > .example-wrap:first-child .tooltip {
+ margin-top: 16px;
}
+/* Media Queries */
+
/*
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
If you update this line, then you also need to update the line with the same warning
-in storage.js plus the media query with (min-width: 701px)
+in storage.js
*/
@media (max-width: 700px) {
/* When linking to an item with an `id` (for instance, by clicking a link in the sidebar,
@@ -1775,13 +1692,13 @@ in storage.js plus the media query with (min-width: 701px)
flex-direction: column;
}
- .content .out-of-band {
+ .out-of-band {
text-align: left;
margin-left: initial;
padding: initial;
}
- .content .out-of-band .since::before {
+ .out-of-band .since::before {
content: "Since ";
}
@@ -1827,24 +1744,13 @@ in storage.js plus the media query with (min-width: 701px)
}
.rustdoc.source > .sidebar {
- position: fixed;
- margin: 0;
- z-index: 11;
width: 0;
}
- .mobile-topbar .location a {
- padding: 0;
- margin: 0;
- }
-
- .mobile-topbar .location {
- border: none;
- padding: 0;
+ .mobile-topbar h2 {
+ padding-bottom: 0;
margin: auto 0.5em auto auto;
- text-overflow: ellipsis;
overflow: hidden;
- white-space: nowrap;
/* Rare exception to specifying font sizes in rem. Since the topbar
height is specified in pixels, this also has to be specified in
pixels to avoid overflowing the topbar when the user sets a bigger
@@ -1852,6 +1758,13 @@ in storage.js plus the media query with (min-width: 701px)
font-size: 24px;
}
+ .mobile-topbar h2 a {
+ display: block;
+ text-overflow: ellipsis;
+ overflow: hidden;
+ white-space: nowrap;
+ }
+
.mobile-topbar .logo-container {
max-height: 45px;
}
@@ -1876,16 +1789,13 @@ in storage.js plus the media query with (min-width: 701px)
top: 0;
}
- .source .mobile-topbar {
- display: none;
- }
-
.sidebar-menu-toggle {
width: 45px;
/* Rare exception to specifying font sizes in rem. Since this is acting
as an icon, it's okay to specify its sizes in pixels. */
font-size: 32px;
border: none;
+ color: var(--main-color);
}
.sidebar-elems {
@@ -1897,10 +1807,6 @@ in storage.js plus the media query with (min-width: 701px)
margin-left: 0px;
}
- .source .content {
- margin-top: 10px;
- }
-
.anchor {
display: none !important;
}
@@ -1941,7 +1847,6 @@ in storage.js plus the media query with (min-width: 701px)
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
cursor: pointer;
- font-weight: bold;
border: 1px solid;
border-left: 0;
}
@@ -1957,14 +1862,6 @@ in storage.js plus the media query with (min-width: 701px)
border-bottom: 1px solid;
}
- #source-sidebar {
- z-index: 11;
- }
-
- #main-content > .line-numbers {
- margin-top: 0;
- }
-
.notable-traits .notable-traits-tooltiptext {
left: 0;
top: 100%;
@@ -1992,10 +1889,10 @@ in storage.js plus the media query with (min-width: 701px)
border-bottom: 1px solid #aaa9;
padding: 5px 0px;
}
- .search-results .result-name, .search-results div.desc, .search-results .result-description {
+ .search-results .result-name, .search-results div.desc {
width: 100%;
}
- .search-results div.desc, .search-results .result-description, .item-right {
+ .search-results div.desc, .item-right {
padding-left: 2em;
}
@@ -2015,13 +1912,18 @@ in storage.js plus the media query with (min-width: 701px)
}
/* Align summary-nested and unnested item-info gizmos. */
- .content .impl-items > .item-info {
+ .impl-items > .item-info {
margin-left: 34px;
}
+
+ .source nav.sub {
+ margin: 0;
+ padding: 8px;
+ }
}
@media print {
- nav.sidebar, nav.sub, .content .out-of-band, a.srclink, #copy-path,
+ nav.sidebar, nav.sub, .out-of-band, a.srclink, #copy-path,
details.rustdoc-toggle[open] > summary::before, details.rustdoc-toggle > summary::before,
details.rustdoc-toggle.top-doc > summary {
display: none;
@@ -2037,10 +1939,6 @@ in storage.js plus the media query with (min-width: 701px)
}
@media (max-width: 464px) {
- #crate-search {
- border-radius: 4px;
- }
-
.docblock {
margin-left: 12px;
}
@@ -2050,15 +1948,15 @@ in storage.js plus the media query with (min-width: 701px)
overflow-wrap: anywhere;
}
- .sub-container {
+ nav.sub {
flex-direction: column;
}
- .sub-logo-container {
- align-self: center;
+ .search-form {
+ align-self: stretch;
}
- .source .sub-logo-container > img {
+ .sub-logo-container > img {
height: 35px;
width: 35px;
}
@@ -2071,23 +1969,24 @@ in storage.js plus the media query with (min-width: 701px)
}
}
-.method-toggle summary,
-.implementors-toggle summary,
-.impl {
+.method-toggle > summary,
+.implementors-toggle > summary,
+.impl,
+#implementors-list > .docblock,
+.impl-items > section,
+.methods > section
+{
margin-bottom: 0.75em;
}
-.method-toggle[open] {
+.method-toggle[open]:not(:last-child),
+.implementors-toggle[open]:not(:last-child) {
margin-bottom: 2em;
}
-.implementors-toggle[open] {
- margin-bottom: 2em;
-}
-
-#trait-implementations-list .method-toggle,
-#synthetic-implementations-list .method-toggle,
-#blanket-implementations-list .method-toggle {
+#trait-implementations-list .method-toggle:not(:last-child),
+#synthetic-implementations-list .method-toggle:not(:last-child),
+#blanket-implementations-list .method-toggle:not(:last-child) {
margin-bottom: 1em;
}
@@ -2124,10 +2023,6 @@ in storage.js plus the media query with (min-width: 701px)
padding-bottom: 0;
}
-.scraped-example:not(.expanded) .code-wrapper pre.line-numbers {
- overflow-x: hidden;
-}
-
.scraped-example .code-wrapper .prev {
position: absolute;
top: 0.25em;
@@ -2170,12 +2065,12 @@ in storage.js plus the media query with (min-width: 701px)
bottom: 0;
}
-.scraped-example .code-wrapper .line-numbers {
+.scraped-example .code-wrapper .src-line-numbers {
margin: 0;
padding: 14px 0;
}
-.scraped-example .code-wrapper .line-numbers span {
+.scraped-example .code-wrapper .src-line-numbers span {
padding: 0 14px;
}
diff --git a/src/librustdoc/html/static/css/settings.css b/src/librustdoc/html/static/css/settings.css
index e82ec0426..83939f63b 100644
--- a/src/librustdoc/html/static/css/settings.css
+++ b/src/librustdoc/html/static/css/settings.css
@@ -12,7 +12,8 @@
margin-right: 0.3em;
height: 1.2rem;
width: 1.2rem;
- border: 1px solid;
+ color: inherit;
+ border: 1px solid currentColor;
outline: none;
-webkit-appearance: none;
cursor: pointer;
@@ -88,3 +89,22 @@ input:checked + .slider:before {
#settings .setting-line {
margin: 1.2em 0.6em;
}
+
+.setting-line .radio-line input:checked {
+ box-shadow: inset 0 0 0 3px var(--main-background-color);
+ background-color: var(--settings-input-color);
+}
+.setting-line .radio-line input:focus {
+ box-shadow: 0 0 1px 1px var(--settings-input-color);
+}
+/* In here we combine both `:focus` and `:checked` properties. */
+.setting-line .radio-line input:checked:focus {
+ box-shadow: inset 0 0 0 3px var(--main-background-color),
+ 0 0 2px 2px var(--settings-input-color);
+}
+.setting-line .radio-line input:hover {
+ border-color: var(--settings-input-color) !important;
+}
+input:checked + .slider {
+ background-color: var(--settings-input-color);
+}
diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css
index e7a898e9f..fdfdb3e19 100644
--- a/src/librustdoc/html/static/css/themes/ayu.css
+++ b/src/librustdoc/html/static/css/themes/ayu.css
@@ -35,6 +35,29 @@ Original by Dempfi (https://github.com/dempfi/ayu)
--keyword-link-color: #39afd7;
--mod-link-color: #39afd7;
--link-color: #39afd7;
+ --sidebar-link-color: #53b1db;
+ --sidebar-current-link-background-color: transparent;
+ --search-result-link-focus-background-color: #3c3c3c;
+ --stab-background-color: #314559;
+ --stab-code-color: #e6e1cf;
+ --search-color: #fff;
+ --code-highlight-kw-color: #ff7733;
+ --code-highlight-kw-2-color: #ff7733;
+ --code-highlight-lifetime-color: #ff7733;
+ --code-highlight-prelude-color: #69f2df;
+ --code-highlight-prelude-val-color: #ff7733;
+ --code-highlight-number-color: #b8cc52;
+ --code-highlight-string-color: #b8cc52;
+ --code-highlight-literal-color: #ff7733;
+ --code-highlight-attribute-color: #e6e1cf;
+ --code-highlight-self-color: #36a3d9;
+ --code-highlight-macro-color: #a37acc;
+ --code-highlight-question-mark-color: #ff9011;
+ --code-highlight-comment-color: #788797;
+ --code-highlight-doc-comment-color: #a1ac88;
+ --example-line-numbers-border-color: none;
+ --src-line-numbers-span-color: #5c6773;
+ --src-line-number-highlighted-background-color: rgba(255, 236, 164, 0.06);
}
.slider {
@@ -50,7 +73,7 @@ input:focus + .slider {
h1, h2, h3, h4 {
color: white;
}
-h1.fqn a {
+h1 a {
color: #fff;
}
h4 {
@@ -85,7 +108,6 @@ pre, .rustdoc.source .example-wrap {
.sidebar .current,
.sidebar a:hover {
- background-color: transparent;
color: #ffb44c;
}
@@ -93,10 +115,8 @@ pre, .rustdoc.source .example-wrap {
color: #ff7733;
}
-.line-numbers span { color: #5c6773; }
-.line-numbers .line-highlighted {
+.src-line-numbers .line-highlighted {
color: #708090;
- background-color: rgba(255, 236, 164, 0.06);
padding-right: 4px;
border-right: 1px solid #ffb44c;
}
@@ -119,12 +139,6 @@ pre, .rustdoc.source .example-wrap {
.content .item-info::before { color: #ccc; }
-.sidebar a { color: #53b1db; }
-.sidebar a.current.type { color: #53b1db; }
-
-pre.rust .comment { color: #788797; }
-pre.rust .doccomment { color: #a1ac88; }
-
.sidebar h2 a,
.sidebar h3 a {
color: white;
@@ -148,53 +162,15 @@ details.rustdoc-toggle > summary::before {
filter: invert(98%) sepia(12%) saturate(81%) hue-rotate(343deg) brightness(113%) contrast(76%);
}
-.search-input {
- color: #fff;
-}
-
.module-item .stab,
.import-item .stab {
color: #000;
}
-.stab {
- color: #c5c5c5;
- background: #314559 !important;
-}
-
-.stab.portability > code {
- color: #e6e1cf;
- background: none;
-}
-
.result-name .primitive > i, .result-name .keyword > i {
color: #788797;
}
-.line-numbers :target { background-color: transparent; }
-
-/* Code highlighting */
-pre.rust .number, pre.rust .string { color: #b8cc52; }
-pre.rust .kw, pre.rust .kw-2, pre.rust .prelude-ty,
-pre.rust .bool-val, pre.rust .prelude-val,
-pre.rust .lifetime { color: #ff7733; }
-pre.rust .macro, pre.rust .macro-nonterminal { color: #a37acc; }
-pre.rust .question-mark {
- color: #ff9011;
-}
-pre.rust .self {
- color: #36a3d9;
- font-style: italic;
-}
-pre.rust .attribute {
- color: #e6e1cf;
-}
-
-.example-wrap > pre.line-number {
- color: #5c67736e;
- border: none;
-}
-
a.test-arrow {
font-size: 100%;
color: #788797;
@@ -260,52 +236,13 @@ pre.rust .kw {}
pre.rust .self, pre.rust .bool-val, pre.rust .prelude-val, pre.rust .attribute {}
pre.rust .kw-2, pre.rust .prelude-ty {}
-.search-results a:focus span {}
-a.result-trait:focus {}
-a.result-traitalias:focus {}
-a.result-mod:focus,
-a.result-externcrate:focus {}
-a.result-mod:focus {}
-a.result-externcrate:focus {}
-a.result-enum:focus {}
-a.result-struct:focus {}
-a.result-union:focus {}
-a.result-fn:focus,
-a.result-method:focus,
-a.result-tymethod:focus {}
-a.result-type:focus {}
-a.result-associatedtype:focus {}
-a.result-foreigntype:focus {}
-a.result-attr:focus,
-a.result-derive:focus,
-a.result-macro:focus {}
-a.result-constant:focus,
-a.result-static:focus {}
-a.result-primitive:focus {}
-a.result-keyword:focus {}
-
-.sidebar a.current.enum {}
-.sidebar a.current.struct {}
-.sidebar a.current.foreigntype {}
-.sidebar a.current.attr,
-.sidebar a.current.derive,
-.sidebar a.current.macro {}
-.sidebar a.current.union {}
-.sidebar a.current.constant
-.sidebar a.current.static {}
-.sidebar a.current.primitive {}
-.sidebar a.current.trait {}
-.sidebar a.current.traitalias {}
-.sidebar a.current.fn {}
-.sidebar a.current.keyword {}
-
kbd {
color: #c5c5c5;
background-color: #314559;
box-shadow: inset 0 -1px 0 #5c6773;
}
-#settings-menu > a, #help-button > button {
+#settings-menu > a, #help-button > a {
color: #fff;
}
@@ -314,7 +251,7 @@ kbd {
}
#settings-menu > a:hover, #settings-menu > a:focus,
-#help-button > button:hover, #help-button > button:focus {
+#help-button > a:hover, #help-button > a:focus {
border-color: #e0e0e0;
}
diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css
index 07a1ed8b7..361d3d4a2 100644
--- a/src/librustdoc/html/static/css/themes/dark.css
+++ b/src/librustdoc/html/static/css/themes/dark.css
@@ -30,6 +30,29 @@
--keyword-link-color: #d2991d;
--mod-link-color: #d2991d;
--link-color: #d2991d;
+ --sidebar-link-color: #fdbf35;
+ --sidebar-current-link-background-color: #444;
+ --search-result-link-focus-background-color: #616161;
+ --stab-background-color: #314559;
+ --stab-code-color: #e6e1cf;
+ --search-color: #111;
+ --code-highlight-kw-color: #ab8ac1;
+ --code-highlight-kw-2-color: #769acb;
+ --code-highlight-lifetime-color: #d97f26;
+ --code-highlight-prelude-color: #769acb;
+ --code-highlight-prelude-val-color: #ee6868;
+ --code-highlight-number-color: #83a300;
+ --code-highlight-string-color: #83a300;
+ --code-highlight-literal-color: #ee6868;
+ --code-highlight-attribute-color: #ee6868;
+ --code-highlight-self-color: #ee6868;
+ --code-highlight-macro-color: #3e999f;
+ --code-highlight-question-mark-color: #ff9011;
+ --code-highlight-comment-color: #8d8d8b;
+ --code-highlight-doc-comment-color: #8ca375;
+ --example-line-numbers-border-color: #4a4949;
+ --src-line-numbers-span-color: #3b91e2;
+ --src-line-number-highlighted-background-color: #0a042f;
}
.slider {
@@ -49,68 +72,8 @@ input:focus + .slider {
drop-shadow(0 -1px 0 #fff)
}
-.sidebar .current,
-.sidebar a:hover {
- background: #444;
-}
-
-.line-numbers span { color: #3B91E2; }
-.line-numbers .line-highlighted {
- background-color: #0a042f !important;
-}
-
-.search-results a:hover {
- background-color: #777;
-}
-
-.search-results a:focus {
- color: #eee !important;
- background-color: #616161;
-}
-.search-results a:focus span { color: #eee !important; }
-a.result-trait:focus { background-color: #013191; }
-a.result-traitalias:focus { background-color: #013191; }
-a.result-mod:focus,
-a.result-externcrate:focus { background-color: #884719; }
-a.result-enum:focus { background-color: #194e9f; }
-a.result-struct:focus { background-color: #194e9f; }
-a.result-union:focus { background-color: #194e9f; }
-a.result-fn:focus,
-a.result-method:focus,
-a.result-tymethod:focus { background-color: #4950ed; }
-a.result-type:focus { background-color: #194e9f; }
-a.result-associatedtype:focus { background-color: #884719; }
-a.result-foreigntype:focus { background-color: #194e9f; }
-a.result-attr:focus,
-a.result-derive:focus,
-a.result-macro:focus { background-color: #217d1c; }
-a.result-constant:focus,
-a.result-static:focus { background-color: #884719; }
-a.result-primitive:focus { background-color: #194e9f; }
-a.result-keyword:focus { background-color: #884719; }
-
.content .item-info::before { color: #ccc; }
-.sidebar a { color: #fdbf35; }
-.sidebar a.current.enum { color: #12ece2; }
-.sidebar a.current.struct { color: #12ece2; }
-.sidebar a.current.type { color: #12ece2; }
-.sidebar a.current.foreigntype { color: #12ece2; }
-.sidebar a.current.attr,
-.sidebar a.current.derive,
-.sidebar a.current.macro { color: #0be900; }
-.sidebar a.current.union { color: #12ece2; }
-.sidebar a.current.constant
-.sidebar a.current.static { color: #fdbf35; }
-.sidebar a.current.primitive { color: #12ece2; }
-.sidebar a.current.trait { color: #cca7ff; }
-.sidebar a.current.traitalias { color: #cca7ff; }
-.sidebar a.current.fn { color: #32d479; }
-.sidebar a.current.keyword { color: #fdbf35; }
-
-pre.rust .comment { color: #8d8d8b; }
-pre.rust .doccomment { color: #8ca375; }
-
body.source .example-wrap pre.rust a {
background: #333;
}
@@ -119,10 +82,6 @@ details.rustdoc-toggle > summary::before {
filter: invert(100%);
}
-.search-input {
- color: #111;
-}
-
#crate-search-div::after {
/* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */
filter: invert(94%) sepia(0%) saturate(721%) hue-rotate(255deg) brightness(90%) contrast(90%);
@@ -134,31 +93,6 @@ details.rustdoc-toggle > summary::before {
filter: invert(69%) sepia(60%) saturate(6613%) hue-rotate(184deg) brightness(100%) contrast(91%);
}
-.stab { background: #314559; }
-
-.stab.portability > code {
- color: #e6e1cf;
- background: none;
-}
-
-.line-numbers :target { background-color: transparent; }
-
-/* Code highlighting */
-pre.rust .kw { color: #ab8ac1; }
-pre.rust .kw-2, pre.rust .prelude-ty { color: #769acb; }
-pre.rust .number, pre.rust .string { color: #83a300; }
-pre.rust .self, pre.rust .bool-val, pre.rust .prelude-val,
-pre.rust .attribute { color: #ee6868; }
-pre.rust .macro, pre.rust .macro-nonterminal { color: #3E999F; }
-pre.rust .lifetime { color: #d97f26; }
-pre.rust .question-mark {
- color: #ff9011;
-}
-
-.example-wrap > pre.line-number {
- border-color: #4a4949;
-}
-
a.test-arrow {
color: #dedede;
background-color: rgba(78, 139, 202, 0.2);
@@ -211,12 +145,12 @@ kbd {
box-shadow: inset 0 -1px 0 #c6cbd1;
}
-#settings-menu > a, #help-button > button {
+#settings-menu > a, #help-button > a {
color: #000;
}
#settings-menu > a:hover, #settings-menu > a:focus,
-#help-button > button:hover, #help-button > button:focus {
+#help-button > a:hover, #help-button > a:focus {
border-color: #ffb900;
}
diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css
index 64335f629..5eb4bbcf8 100644
--- a/src/librustdoc/html/static/css/themes/light.css
+++ b/src/librustdoc/html/static/css/themes/light.css
@@ -30,6 +30,29 @@
--keyword-link-color: #3873ad;
--mod-link-color: #3873ad;
--link-color: #3873ad;
+ --sidebar-link-color: #356da4;
+ --sidebar-current-link-background-color: #fff;
+ --search-result-link-focus-background-color: #ccc;
+ --stab-background-color: #fff5d6;
+ --stab-code-color: #000;
+ --search-color: #000;
+ --code-highlight-kw-color: #8959a8;
+ --code-highlight-kw-2-color: #4271ae;
+ --code-highlight-lifetime-color: #b76514;
+ --code-highlight-prelude-color: #4271ae;
+ --code-highlight-prelude-val-color: #c82829;
+ --code-highlight-number-color: #718c00;
+ --code-highlight-string-color: #718c00;
+ --code-highlight-literal-color: #c82829;
+ --code-highlight-attribute-color: #c82829;
+ --code-highlight-self-color: #c82829;
+ --code-highlight-macro-color: #3e999f;
+ --code-highlight-question-mark-color: #ff9011;
+ --code-highlight-comment-color: #8e908c;
+ --code-highlight-doc-comment-color: #4d4d4c;
+ --example-line-numbers-border-color: #c7c7c7;
+ --src-line-numbers-span-color: #c67e2d;
+ --src-line-number-highlighted-background-color: #fdffd3;
}
.slider {
@@ -48,65 +71,8 @@ input:focus + .slider {
*/
}
-.sidebar .current,
-.sidebar a:hover {
- background-color: #fff;
-}
-
-.line-numbers span { color: #c67e2d; }
-.line-numbers .line-highlighted {
- background-color: #FDFFD3 !important;
-}
-
-.search-results a:hover {
- background-color: #ddd;
-}
-
-.search-results a:focus {
- color: #000 !important;
- background-color: #ccc;
-}
-.search-results a:focus span { color: #000 !important; }
-a.result-trait:focus { background-color: #c7b6ff; }
-a.result-traitalias:focus { background-color: #c7b6ff; }
-a.result-mod:focus,
-a.result-externcrate:focus { background-color: #afc6e4; }
-a.result-enum:focus { background-color: #e7b1a0; }
-a.result-struct:focus { background-color: #e7b1a0; }
-a.result-union:focus { background-color: #e7b1a0; }
-a.result-fn:focus,
-a.result-method:focus,
-a.result-tymethod:focus { background-color: #c6afb3; }
-a.result-type:focus { background-color: #e7b1a0; }
-a.result-associatedtype:focus { background-color: #afc6e4; }
-a.result-foreigntype:focus { background-color: #e7b1a0; }
-a.result-attr:focus,
-a.result-derive:focus,
-a.result-macro:focus { background-color: #8ce488; }
-a.result-constant:focus,
-a.result-static:focus { background-color: #afc6e4; }
-a.result-primitive:focus { background-color: #e7b1a0; }
-a.result-keyword:focus { background-color: #afc6e4; }
-
.content .item-info::before { color: #ccc; }
-.sidebar a { color: #356da4; }
-.sidebar a.current.enum { color: #a63283; }
-.sidebar a.current.struct { color: #a63283; }
-.sidebar a.current.type { color: #a63283; }
-.sidebar a.current.foreigntype { color: #356da4; }
-.sidebar a.current.attr,
-.sidebar a.current.derive,
-.sidebar a.current.macro { color: #067901; }
-.sidebar a.current.union { color: #a63283; }
-.sidebar a.current.constant
-.sidebar a.current.static { color: #356da4; }
-.sidebar a.current.primitive { color: #a63283; }
-.sidebar a.current.trait { color: #6849c3; }
-.sidebar a.current.traitalias { color: #4b349e; }
-.sidebar a.current.fn { color: #a67736; }
-.sidebar a.current.keyword { color: #356da4; }
-
body.source .example-wrap pre.rust a {
background: #eee;
}
@@ -122,29 +88,6 @@ body.source .example-wrap pre.rust a {
filter: invert(44%) sepia(18%) saturate(23%) hue-rotate(317deg) brightness(96%) contrast(93%);
}
-.stab { background: #FFF5D6; border-color: #FFC600; }
-.stab.portability > code { background: none; }
-
-.line-numbers :target { background-color: transparent; }
-
-/* Code highlighting */
-pre.rust .kw { color: #8959A8; }
-pre.rust .kw-2, pre.rust .prelude-ty { color: #4271AE; }
-pre.rust .number, pre.rust .string { color: #718C00; }
-pre.rust .self, pre.rust .bool-val, pre.rust .prelude-val,
-pre.rust .attribute { color: #C82829; }
-pre.rust .comment { color: #8E908C; }
-pre.rust .doccomment { color: #4D4D4C; }
-pre.rust .macro, pre.rust .macro-nonterminal { color: #3E999F; }
-pre.rust .lifetime { color: #B76514; }
-pre.rust .question-mark {
- color: #ff9011;
-}
-
-.example-wrap > pre.line-number {
- border-color: #c7c7c7;
-}
-
a.test-arrow {
color: #f5f5f5;
background-color: rgba(78, 139, 202, 0.2);
@@ -196,8 +139,12 @@ kbd {
box-shadow: inset 0 -1px 0 #c6cbd1;
}
+#settings-menu > a, #help-button > a {
+ color: #000;
+}
+
#settings-menu > a:hover, #settings-menu > a:focus,
-#help-button > button:hover, #help-button > button:focus {
+#help-button > a:hover, #help-button > a:focus {
border-color: #717171;
}
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js
index 6e9660ddc..33480fa41 100644
--- a/src/librustdoc/html/static/js/main.js
+++ b/src/librustdoc/html/static/js/main.js
@@ -55,7 +55,7 @@ function blurHandler(event, parentElem, hideCallback) {
function setMobileTopbar() {
// FIXME: It would be nicer to generate this text content directly in HTML,
// but with the current code it's hard to get the right information in the right place.
- const mobileLocationTitle = document.querySelector(".mobile-topbar h2.location");
+ const mobileLocationTitle = document.querySelector(".mobile-topbar h2");
const locationTitle = document.querySelector(".sidebar h2.location");
if (mobileLocationTitle && locationTitle) {
mobileLocationTitle.innerHTML = locationTitle.innerHTML;
@@ -192,6 +192,8 @@ function loadCss(cssFileName) {
}
(function() {
+ const isHelpPage = window.location.pathname.endsWith("/help.html");
+
function loadScript(url) {
const script = document.createElement("script");
script.src = url;
@@ -199,6 +201,9 @@ function loadCss(cssFileName) {
}
getSettingsButton().onclick = event => {
+ if (event.ctrlKey || event.altKey || event.metaKey) {
+ return;
+ }
addClass(getSettingsButton(), "rotate");
event.preventDefault();
// Sending request for the CSS and the JS files at the same time so it will
@@ -404,9 +409,12 @@ function loadCss(cssFileName) {
break;
case "+":
+ ev.preventDefault();
+ expandAllDocs();
+ break;
case "-":
ev.preventDefault();
- toggleAllDocs();
+ collapseAllDocs();
break;
case "?":
@@ -442,18 +450,15 @@ function loadCss(cssFileName) {
return;
}
- const div = document.createElement("div");
- div.className = "block " + shortty;
const h3 = document.createElement("h3");
h3.innerHTML = `<a href="index.html#${id}">${longty}</a>`;
- div.appendChild(h3);
const ul = document.createElement("ul");
+ ul.className = "block " + shortty;
for (const item of filtered) {
const name = item[0];
const desc = item[1]; // can be null
- let klass = shortty;
let path;
if (shortty === "mod") {
path = name + "/index.html";
@@ -461,20 +466,19 @@ function loadCss(cssFileName) {
path = shortty + "." + name + ".html";
}
const current_page = document.location.href.split("/").pop();
- if (path === current_page) {
- klass += " current";
- }
const link = document.createElement("a");
link.href = path;
link.title = desc;
- link.className = klass;
+ if (path === current_page) {
+ link.className = "current";
+ }
link.textContent = name;
const li = document.createElement("li");
li.appendChild(link);
ul.appendChild(li);
}
- div.appendChild(ul);
- sidebar.appendChild(div);
+ sidebar.appendChild(h3);
+ sidebar.appendChild(ul);
}
if (sidebar) {
@@ -522,7 +526,7 @@ function loadCss(cssFileName) {
}
let currentNbImpls = implementors.getElementsByClassName("impl").length;
- const traitName = document.querySelector("h1.fqn > .in-band > .trait").textContent;
+ const traitName = document.querySelector("h1.fqn > .trait").textContent;
const baseIdName = "impl-" + traitName + "-";
const libs = Object.getOwnPropertyNames(imp);
// We don't want to include impls from this JS file, when the HTML already has them.
@@ -555,7 +559,6 @@ function loadCss(cssFileName) {
const code = document.createElement("h3");
code.innerHTML = struct[TEXT_IDX];
addClass(code, "code-header");
- addClass(code, "in-band");
onEachLazy(code.getElementsByTagName("a"), elem => {
const href = elem.getAttribute("href");
@@ -593,38 +596,52 @@ function loadCss(cssFileName) {
return;
}
// Draw a convenient sidebar of known crates if we have a listing
- const div = document.createElement("div");
- div.className = "block crate";
- div.innerHTML = "<h3>Crates</h3>";
+ const h3 = document.createElement("h3");
+ h3.innerHTML = "Crates";
const ul = document.createElement("ul");
- div.appendChild(ul);
+ ul.className = "block crate";
for (const crate of window.ALL_CRATES) {
- let klass = "crate";
- if (window.rootPath !== "./" && crate === window.currentCrate) {
- klass += " current";
- }
const link = document.createElement("a");
link.href = window.rootPath + crate + "/index.html";
- link.className = klass;
+ if (window.rootPath !== "./" && crate === window.currentCrate) {
+ link.className = "current";
+ }
link.textContent = crate;
const li = document.createElement("li");
li.appendChild(link);
ul.appendChild(li);
}
- sidebarElems.appendChild(div);
+ sidebarElems.appendChild(h3);
+ sidebarElems.appendChild(ul);
}
+ function expandAllDocs() {
+ const innerToggle = document.getElementById(toggleAllDocsId);
+ removeClass(innerToggle, "will-expand");
+ onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
+ if (!hasClass(e, "type-contents-toggle")) {
+ e.open = true;
+ }
+ });
+ innerToggle.title = "collapse all docs";
+ innerToggle.children[0].innerText = "\u2212"; // "\u2212" is "−" minus sign
+ }
- function labelForToggleButton(sectionIsCollapsed) {
- if (sectionIsCollapsed) {
- // button will expand the section
- return "+";
- }
- // button will collapse the section
- // note that this text is also set in the HTML template in ../render/mod.rs
- return "\u2212"; // "\u2212" is "−" minus sign
+ function collapseAllDocs() {
+ const innerToggle = document.getElementById(toggleAllDocsId);
+ addClass(innerToggle, "will-expand");
+ onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
+ if (e.parentNode.id !== "implementations-list" ||
+ (!hasClass(e, "implementors-toggle") &&
+ !hasClass(e, "type-contents-toggle"))
+ ) {
+ e.open = false;
+ }
+ });
+ innerToggle.title = "expand all docs";
+ innerToggle.children[0].innerText = "+";
}
function toggleAllDocs() {
@@ -632,29 +649,11 @@ function loadCss(cssFileName) {
if (!innerToggle) {
return;
}
- let sectionIsCollapsed = false;
if (hasClass(innerToggle, "will-expand")) {
- removeClass(innerToggle, "will-expand");
- onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
- if (!hasClass(e, "type-contents-toggle")) {
- e.open = true;
- }
- });
- innerToggle.title = "collapse all docs";
+ expandAllDocs();
} else {
- addClass(innerToggle, "will-expand");
- onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
- if (e.parentNode.id !== "implementations-list" ||
- (!hasClass(e, "implementors-toggle") &&
- !hasClass(e, "type-contents-toggle"))
- ) {
- e.open = false;
- }
- });
- sectionIsCollapsed = true;
- innerToggle.title = "expand all docs";
+ collapseAllDocs();
}
- innerToggle.children[0].innerText = labelForToggleButton(sectionIsCollapsed);
}
(function() {
@@ -697,60 +696,95 @@ function loadCss(cssFileName) {
}
}());
+ window.rustdoc_add_line_numbers_to_examples = () => {
+ onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
+ const parent = x.parentNode;
+ const line_numbers = parent.querySelectorAll(".example-line-numbers");
+ if (line_numbers.length > 0) {
+ return;
+ }
+ const count = x.textContent.split("\n").length;
+ const elems = [];
+ for (let i = 0; i < count; ++i) {
+ elems.push(i + 1);
+ }
+ const node = document.createElement("pre");
+ addClass(node, "example-line-numbers");
+ node.innerHTML = elems.join("\n");
+ parent.insertBefore(node, x);
+ });
+ };
+
+ window.rustdoc_remove_line_numbers_from_examples = () => {
+ onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
+ const parent = x.parentNode;
+ const line_numbers = parent.querySelectorAll(".example-line-numbers");
+ for (const node of line_numbers) {
+ parent.removeChild(node);
+ }
+ });
+ };
+
(function() {
// To avoid checking on "rustdoc-line-numbers" value on every loop...
if (getSettingValue("line-numbers") === "true") {
- onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
- const count = x.textContent.split("\n").length;
- const elems = [];
- for (let i = 0; i < count; ++i) {
- elems.push(i + 1);
- }
- const node = document.createElement("pre");
- addClass(node, "line-number");
- node.innerHTML = elems.join("\n");
- x.parentNode.insertBefore(node, x);
- });
+ window.rustdoc_add_line_numbers_to_examples();
}
}());
let oldSidebarScrollPosition = null;
- function showSidebar() {
- if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT) {
+ // Scroll locking used both here and in source-script.js
+
+ window.rustdocMobileScrollLock = function() {
+ const mobile_topbar = document.querySelector(".mobile-topbar");
+ if (window.innerWidth <= window.RUSTDOC_MOBILE_BREAKPOINT) {
// This is to keep the scroll position on mobile.
oldSidebarScrollPosition = window.scrollY;
document.body.style.width = `${document.body.offsetWidth}px`;
document.body.style.position = "fixed";
document.body.style.top = `-${oldSidebarScrollPosition}px`;
- document.querySelector(".mobile-topbar").style.top = `${oldSidebarScrollPosition}px`;
- document.querySelector(".mobile-topbar").style.position = "relative";
+ if (mobile_topbar) {
+ mobile_topbar.style.top = `${oldSidebarScrollPosition}px`;
+ mobile_topbar.style.position = "relative";
+ }
} else {
oldSidebarScrollPosition = null;
}
- const sidebar = document.getElementsByClassName("sidebar")[0];
- addClass(sidebar, "shown");
- }
+ };
- function hideSidebar() {
+ window.rustdocMobileScrollUnlock = function() {
+ const mobile_topbar = document.querySelector(".mobile-topbar");
if (oldSidebarScrollPosition !== null) {
// This is to keep the scroll position on mobile.
document.body.style.width = "";
document.body.style.position = "";
document.body.style.top = "";
- document.querySelector(".mobile-topbar").style.top = "";
- document.querySelector(".mobile-topbar").style.position = "";
+ if (mobile_topbar) {
+ mobile_topbar.style.top = "";
+ mobile_topbar.style.position = "";
+ }
// The scroll position is lost when resetting the style, hence why we store it in
// `oldSidebarScrollPosition`.
window.scrollTo(0, oldSidebarScrollPosition);
oldSidebarScrollPosition = null;
}
+ };
+
+ function showSidebar() {
+ window.rustdocMobileScrollLock();
+ const sidebar = document.getElementsByClassName("sidebar")[0];
+ addClass(sidebar, "shown");
+ }
+
+ function hideSidebar() {
+ window.rustdocMobileScrollUnlock();
const sidebar = document.getElementsByClassName("sidebar")[0];
removeClass(sidebar, "shown");
}
window.addEventListener("resize", () => {
- if (window.innerWidth >= window.RUSTDOC_MOBILE_BREAKPOINT &&
+ if (window.innerWidth > window.RUSTDOC_MOBILE_BREAKPOINT &&
oldSidebarScrollPosition !== null) {
// If the user opens the sidebar in "mobile" mode, and then grows the browser window,
// we need to switch away from mobile mode and make the main content area scrollable.
@@ -859,7 +893,10 @@ function loadCss(cssFileName) {
rustdoc_version.appendChild(rustdoc_version_code);
const container = document.createElement("div");
- container.className = "popover";
+ if (!isHelpPage) {
+ container.className = "popover";
+ }
+ container.id = "help";
container.style.display = "none";
const side_by_side = document.createElement("div");
@@ -871,15 +908,22 @@ function loadCss(cssFileName) {
container.appendChild(side_by_side);
container.appendChild(rustdoc_version);
- const help_button = getHelpButton();
- help_button.appendChild(container);
-
- container.onblur = helpBlurHandler;
- container.onclick = event => {
- event.preventDefault();
- };
- help_button.onblur = helpBlurHandler;
- help_button.children[0].onblur = helpBlurHandler;
+ if (isHelpPage) {
+ const help_section = document.createElement("section");
+ help_section.appendChild(container);
+ document.getElementById("main-content").appendChild(help_section);
+ container.style.display = "block";
+ } else {
+ const help_button = getHelpButton();
+ help_button.appendChild(container);
+
+ container.onblur = helpBlurHandler;
+ container.onclick = event => {
+ event.preventDefault();
+ };
+ help_button.onblur = helpBlurHandler;
+ help_button.children[0].onblur = helpBlurHandler;
+ }
return container;
}
@@ -888,7 +932,7 @@ function loadCss(cssFileName) {
* Hide all the popover menus.
*/
window.hidePopoverMenus = function() {
- onEachLazy(document.querySelectorAll(".search-container .popover"), elem => {
+ onEachLazy(document.querySelectorAll(".search-form .popover"), elem => {
elem.style.display = "none";
});
};
@@ -920,19 +964,43 @@ function loadCss(cssFileName) {
}
}
- document.querySelector(`#${HELP_BUTTON_ID} > button`).addEventListener("click", event => {
- const target = event.target;
- if (target.tagName !== "BUTTON" || target.parentElement.id !== HELP_BUTTON_ID) {
- return;
- }
- const menu = getHelpMenu(true);
- const shouldShowHelp = menu.style.display === "none";
- if (shouldShowHelp) {
- showHelp();
- } else {
- window.hidePopoverMenus();
- }
- });
+ if (isHelpPage) {
+ showHelp();
+ document.querySelector(`#${HELP_BUTTON_ID} > a`).addEventListener("click", event => {
+ // Already on the help page, make help button a no-op.
+ const target = event.target;
+ if (target.tagName !== "A" ||
+ target.parentElement.id !== HELP_BUTTON_ID ||
+ event.ctrlKey ||
+ event.altKey ||
+ event.metaKey) {
+ return;
+ }
+ event.preventDefault();
+ });
+ } else {
+ document.querySelector(`#${HELP_BUTTON_ID} > a`).addEventListener("click", event => {
+ // By default, have help button open docs in a popover.
+ // If user clicks with a moderator, though, use default browser behavior,
+ // probably opening in a new window or tab.
+ const target = event.target;
+ if (target.tagName !== "A" ||
+ target.parentElement.id !== HELP_BUTTON_ID ||
+ event.ctrlKey ||
+ event.altKey ||
+ event.metaKey) {
+ return;
+ }
+ event.preventDefault();
+ const menu = getHelpMenu(true);
+ const shouldShowHelp = menu.style.display === "none";
+ if (shouldShowHelp) {
+ showHelp();
+ } else {
+ window.hidePopoverMenus();
+ }
+ });
+ }
setMobileTopbar();
addSidebarItems();
diff --git a/src/librustdoc/html/static/js/scrape-examples.js b/src/librustdoc/html/static/js/scrape-examples.js
index fd7a14497..d0fd115fd 100644
--- a/src/librustdoc/html/static/js/scrape-examples.js
+++ b/src/librustdoc/html/static/js/scrape-examples.js
@@ -8,7 +8,7 @@
// Scroll code block to the given code location
function scrollToLoc(elt, loc) {
- const lines = elt.querySelector(".line-numbers");
+ const lines = elt.querySelector(".src-line-numbers");
let scrollOffset;
// If the block is greater than the size of the viewer,
diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js
index 797b931af..5e1c7e6f0 100644
--- a/src/librustdoc/html/static/js/settings.js
+++ b/src/librustdoc/html/static/js/settings.js
@@ -19,6 +19,13 @@
updateSystemTheme();
updateLightAndDark();
break;
+ case "line-numbers":
+ if (value === true) {
+ window.rustdoc_add_line_numbers_to_examples();
+ } else {
+ window.rustdoc_remove_line_numbers_from_examples();
+ }
+ break;
}
}
@@ -209,7 +216,9 @@
const innerHTML = `<div class="settings">${buildSettingsPageSections(settings)}</div>`;
const el = document.createElement(elementKind);
el.id = "settings";
- el.className = "popover";
+ if (!isSettingsPage) {
+ el.className = "popover";
+ }
el.innerHTML = innerHTML;
if (isSettingsPage) {
diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js
index 06d15d9e5..0b9368dd8 100644
--- a/src/librustdoc/html/static/js/source-script.js
+++ b/src/librustdoc/html/static/js/source-script.js
@@ -10,7 +10,6 @@
(function() {
const rootPath = document.getElementById("rustdoc-vars").attributes["data-root-path"].value;
-let oldScrollPosition = null;
const NAME_OFFSET = 0;
const DIRS_OFFSET = 1;
@@ -70,44 +69,18 @@ function createDirEntry(elem, parent, fullPath, hasFoundFile) {
function toggleSidebar() {
const child = this.parentNode.children[0];
if (child.innerText === ">") {
- if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT) {
- // This is to keep the scroll position on mobile.
- oldScrollPosition = window.scrollY;
- document.body.style.position = "fixed";
- document.body.style.top = `-${oldScrollPosition}px`;
- } else {
- oldScrollPosition = null;
- }
+ window.rustdocMobileScrollLock();
addClass(document.documentElement, "source-sidebar-expanded");
child.innerText = "<";
updateLocalStorage("source-sidebar-show", "true");
} else {
- if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT && oldScrollPosition !== null) {
- // This is to keep the scroll position on mobile.
- document.body.style.position = "";
- document.body.style.top = "";
- // The scroll position is lost when resetting the style, hence why we store it in
- // `oldScrollPosition`.
- window.scrollTo(0, oldScrollPosition);
- oldScrollPosition = null;
- }
+ window.rustdocMobileScrollUnlock();
removeClass(document.documentElement, "source-sidebar-expanded");
child.innerText = ">";
updateLocalStorage("source-sidebar-show", "false");
}
}
-window.addEventListener("resize", () => {
- if (window.innerWidth >= window.RUSTDOC_MOBILE_BREAKPOINT && oldScrollPosition !== null) {
- // If the user opens the sidebar in "mobile" mode, and then grows the browser window,
- // we need to switch away from mobile mode and make the main content area scrollable.
- document.body.style.position = "";
- document.body.style.top = "";
- window.scrollTo(0, oldScrollPosition);
- oldScrollPosition = null;
- }
-});
-
function createSidebarToggle() {
const sidebarToggle = document.createElement("div");
sidebarToggle.id = "sidebar-toggle";
@@ -125,7 +98,7 @@ function createSidebarToggle() {
return sidebarToggle;
}
-// This function is called from "source-files.js", generated in `html/render/mod.rs`.
+// This function is called from "source-files.js", generated in `html/render/write_shared.rs`.
// eslint-disable-next-line no-unused-vars
function createSourceSidebar() {
const container = document.querySelector("nav.sidebar");
@@ -183,7 +156,7 @@ function highlightSourceLines(match) {
if (x) {
x.scrollIntoView();
}
- onEachLazy(document.getElementsByClassName("line-numbers"), e => {
+ onEachLazy(document.getElementsByClassName("src-line-numbers"), e => {
onEachLazy(e.getElementsByTagName("span"), i_e => {
removeClass(i_e, "line-highlighted");
});
@@ -245,7 +218,7 @@ window.addEventListener("hashchange", () => {
}
});
-onEachLazy(document.getElementsByClassName("line-numbers"), el => {
+onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
el.addEventListener("click", handleSourceHighlight);
});
diff --git a/src/librustdoc/html/static/js/storage.js b/src/librustdoc/html/static/js/storage.js
index 0c5389d45..b462a2c50 100644
--- a/src/librustdoc/html/static/js/storage.js
+++ b/src/librustdoc/html/static/js/storage.js
@@ -10,9 +10,9 @@ window.currentTheme = document.getElementById("themeStyle");
window.mainTheme = document.getElementById("mainThemeStyle");
// WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
-// If you update this line, then you also need to update the two media queries with the same
+// If you update this line, then you also need to update the media query with the same
// warning in rustdoc.css
-window.RUSTDOC_MOBILE_BREAKPOINT = 701;
+window.RUSTDOC_MOBILE_BREAKPOINT = 700;
const settingsDataset = (function() {
const settingsElement = document.getElementById("default-settings");
diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html
index 7caffeae3..c32386916 100644
--- a/src/librustdoc/html/templates/page.html
+++ b/src/librustdoc/html/templates/page.html
@@ -73,6 +73,7 @@
</div> {#- -#}
<![endif]--> {#- -#}
{{- layout.external_html.before_content|safe -}}
+ {%- if page.css_class != "source" -%}
<nav class="mobile-topbar"> {#- -#}
<button class="sidebar-menu-toggle">&#9776;</button> {#- -#}
<a class="sidebar-logo" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {#- -#}
@@ -84,9 +85,11 @@
{%- endif -%}
</div> {#- -#}
</a> {#- -#}
- <h2 class="location"></h2> {#- -#}
+ <h2></h2> {#- -#}
</nav> {#- -#}
+ {%- endif -%}
<nav class="sidebar"> {#- -#}
+ {%- if page.css_class != "source" -%}
<a class="sidebar-logo" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {#- -#}
<div class="logo-container"> {#- -#}
{%- if !layout.logo.is_empty() %}
@@ -96,11 +99,13 @@
{%- endif -%}
</div> {#- -#}
</a> {#- -#}
+ {%- endif -%}
{{- sidebar|safe -}}
</nav> {#- -#}
<main> {#- -#}
<div class="width-limiter"> {#- -#}
- <div class="sub-container"> {#- -#}
+ <nav class="sub"> {#- -#}
+ {%- if page.css_class == "source" -%}
<a class="sub-logo-container" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {#- -#}
{%- if !layout.logo.is_empty() %}
<img src="{{layout.logo}}" alt="logo"> {#- -#}
@@ -108,30 +113,27 @@
<img class="rust-logo" src="{{static_root_path|safe}}rust-logo{{page.resource_suffix}}.svg" alt="logo"> {#- -#}
{%- endif -%}
</a> {#- -#}
- <nav class="sub"> {#- -#}
- <form class="search-form"> {#- -#}
- <div class="search-container"> {#- -#}
- <span></span> {#- This empty span is a hacky fix for Safari - See #93184 -#}
- <input {# -#}
- class="search-input" {# -#}
- name="search" {# -#}
- autocomplete="off" {# -#}
- spellcheck="false" {# -#}
- placeholder="Click or press ‘S’ to search, ‘?’ for more options…" {# -#}
- type="search"> {#- -#}
- <div id="help-button" title="help" tabindex="-1"> {#- -#}
- <button type="button">?</button> {#- -#}
- </div> {#- -#}
- <div id="settings-menu" tabindex="-1"> {#- -#}
- <a href="{{page.root_path|safe}}settings.html" title="settings"> {#- -#}
- <img width="22" height="22" alt="Change settings" {# -#}
- src="{{static_root_path|safe}}wheel{{page.resource_suffix}}.svg"> {#- -#}
- </a> {#- -#}
- </div> {#- -#}
- </div> {#- -#}
- </form> {#- -#}
- </nav> {#- -#}
- </div> {#- -#}
+ {%- endif -%}
+ <form class="search-form"> {#- -#}
+ <span></span> {#- This empty span is a hacky fix for Safari - See #93184 -#}
+ <input {# -#}
+ class="search-input" {# -#}
+ name="search" {# -#}
+ autocomplete="off" {# -#}
+ spellcheck="false" {# -#}
+ placeholder="Click or press ‘S’ to search, ‘?’ for more options…" {# -#}
+ type="search"> {#- -#}
+ <div id="help-button" title="help" tabindex="-1"> {#- -#}
+ <a href="{{page.root_path|safe}}help.html">?</a> {#- -#}
+ </div> {#- -#}
+ <div id="settings-menu" tabindex="-1"> {#- -#}
+ <a href="{{page.root_path|safe}}settings.html" title="settings"> {#- -#}
+ <img width="22" height="22" alt="Change settings" {# -#}
+ src="{{static_root_path|safe}}wheel{{page.resource_suffix}}.svg"> {#- -#}
+ </a> {#- -#}
+ </div> {#- -#}
+ </form> {#- -#}
+ </nav> {#- -#}
<section id="main-content" class="content">{{- content|safe -}}</section> {#- -#}
</div> {#- -#}
</main> {#- -#}
diff --git a/src/librustdoc/html/templates/print_item.html b/src/librustdoc/html/templates/print_item.html
index c755157d2..b6ce3ea3d 100644
--- a/src/librustdoc/html/templates/print_item.html
+++ b/src/librustdoc/html/templates/print_item.html
@@ -1,18 +1,16 @@
<div class="main-heading"> {#- -#}
<h1 class="fqn"> {#- -#}
- <span class="in-band"> {#- -#}
- {{-typ-}}
- {#- The breadcrumbs of the item path, like std::string -#}
- {%- for component in path_components -%}
- <a href="{{component.path|safe}}index.html">{{component.name}}</a>::<wbr>
- {%- endfor -%}
- <a class="{{item_type}}" href="#">{{name}}</a> {#- -#}
- <button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"> {#- -#}
- <img src="{{static_root_path|safe}}clipboard{{page.resource_suffix}}.svg" {# -#}
- width="19" height="18" {# -#}
- alt="Copy item path"> {#- -#}
- </button> {#- -#}
- </span> {#- -#}
+ {{-typ-}}
+ {#- The breadcrumbs of the item path, like std::string -#}
+ {%- for component in path_components -%}
+ <a href="{{component.path|safe}}index.html">{{component.name}}</a>::<wbr>
+ {%- endfor -%}
+ <a class="{{item_type}}" href="#">{{name}}</a> {#- -#}
+ <button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"> {#- -#}
+ <img src="{{static_root_path|safe}}clipboard{{page.resource_suffix}}.svg" {# -#}
+ width="19" height="18" {# -#}
+ alt="Copy item path"> {#- -#}
+ </button> {#- -#}
</h1> {#- -#}
<span class="out-of-band"> {#- -#}
{% if !stability_since_raw.is_empty() %}
diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs
index 49a31f5f1..cdf59cdd3 100644
--- a/src/librustdoc/json/conversions.rs
+++ b/src/librustdoc/json/conversions.rs
@@ -272,7 +272,12 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
ConstantItem(c) => ItemEnum::Constant(c.into_tcx(tcx)),
MacroItem(m) => ItemEnum::Macro(m.source),
ProcMacroItem(m) => ItemEnum::ProcMacro(m.into_tcx(tcx)),
- PrimitiveItem(p) => ItemEnum::PrimitiveType(p.as_sym().to_string()),
+ PrimitiveItem(p) => {
+ ItemEnum::Primitive(Primitive {
+ name: p.as_sym().to_string(),
+ impls: Vec::new(), // Added in JsonRenderer::item
+ })
+ }
TyAssocConstItem(ty) => ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: None },
AssocConstItem(ty, default) => {
ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: Some(default.expr(tcx)) }
@@ -427,8 +432,9 @@ impl FromWithTcx<clean::WherePredicate> for WherePredicate {
lifetime: convert_lifetime(lifetime),
bounds: bounds.into_tcx(tcx),
},
- EqPredicate { lhs, rhs } => {
- WherePredicate::EqPredicate { lhs: lhs.into_tcx(tcx), rhs: rhs.into_tcx(tcx) }
+ // FIXME(fmease): Convert bound parameters as well.
+ EqPredicate { lhs, rhs, bound_params: _ } => {
+ WherePredicate::EqPredicate { lhs: (*lhs).into_tcx(tcx), rhs: (*rhs).into_tcx(tcx) }
}
}
}
diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs
index 5e8f5f6fe..d13efe6c1 100644
--- a/src/librustdoc/json/mod.rs
+++ b/src/librustdoc/json/mod.rs
@@ -108,7 +108,6 @@ impl<'tcx> JsonRenderer<'tcx> {
.filter_map(|(&id, trait_item)| {
// only need to synthesize items for external traits
if !id.is_local() {
- let trait_item = &trait_item.trait_;
for item in &trait_item.items {
trace!("Adding subitem to {id:?}: {:?}", item.item_id);
self.item(item.clone()).unwrap();
@@ -219,12 +218,15 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
u.impls = self.get_impls(item_id.expect_def_id());
false
}
+ types::ItemEnum::Primitive(ref mut p) => {
+ p.impls = self.get_impls(item_id.expect_def_id());
+ false
+ }
types::ItemEnum::Method(_)
| types::ItemEnum::Module(_)
| types::ItemEnum::AssocConst { .. }
- | types::ItemEnum::AssocType { .. }
- | types::ItemEnum::PrimitiveType(_) => true,
+ | types::ItemEnum::AssocType { .. } => true,
types::ItemEnum::ExternCrate { .. }
| types::ItemEnum::Import(_)
| types::ItemEnum::StructField(_)
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index 14d695582..4cf9435d9 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -9,14 +9,12 @@
#![feature(control_flow_enum)]
#![feature(drain_filter)]
#![feature(let_chains)]
-#![cfg_attr(bootstrap, feature(let_else))]
#![feature(test)]
#![feature(never_type)]
#![feature(once_cell)]
#![feature(type_ascription)]
#![feature(iter_intersperse)]
#![feature(type_alias_impl_trait)]
-#![cfg_attr(bootstrap, feature(generic_associated_types))]
#![recursion_limit = "256"]
#![warn(rustc::internal)]
#![allow(clippy::collapsible_if, clippy::collapsible_else_if)]
@@ -43,6 +41,7 @@ extern crate rustc_errors;
extern crate rustc_expand;
extern crate rustc_feature;
extern crate rustc_hir;
+extern crate rustc_hir_analysis;
extern crate rustc_hir_pretty;
extern crate rustc_index;
extern crate rustc_infer;
@@ -61,7 +60,6 @@ extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_target;
extern crate rustc_trait_selection;
-extern crate rustc_typeck;
extern crate test;
// See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
@@ -156,7 +154,6 @@ pub fn main() {
}
}
- rustc_driver::set_sigpipe_handler();
rustc_driver::install_ice_hook();
// When using CI artifacts (with `download_stage1 = true`), tracing is unconditionally built
@@ -461,7 +458,7 @@ fn opts() -> Vec<RustcOptGroup> {
"human|json|short",
)
}),
- unstable("diagnostic-width", |o| {
+ stable("diagnostic-width", |o| {
o.optopt(
"",
"diagnostic-width",
@@ -676,39 +673,6 @@ fn usage(argv0: &str) {
/// A result type used by several functions under `main()`.
type MainResult = Result<(), ErrorGuaranteed>;
-fn main_args(at_args: &[String]) -> MainResult {
- let args = rustc_driver::args::arg_expand_all(at_args);
-
- let mut options = getopts::Options::new();
- for option in opts() {
- (option.apply)(&mut options);
- }
- let matches = match options.parse(&args[1..]) {
- Ok(m) => m,
- Err(err) => {
- early_error(ErrorOutputType::default(), &err.to_string());
- }
- };
-
- // Note that we discard any distinction between different non-zero exit
- // codes from `from_matches` here.
- let options = match config::Options::from_matches(&matches, args) {
- Ok(opts) => opts,
- Err(code) => {
- return if code == 0 {
- Ok(())
- } else {
- Err(ErrorGuaranteed::unchecked_claim_error_was_emitted())
- };
- }
- };
- rustc_interface::util::run_in_thread_pool_with_globals(
- options.edition,
- 1, // this runs single-threaded, even in a parallel compiler
- move || main_options(options),
- )
-}
-
fn wrap_return(diag: &rustc_errors::Handler, res: Result<(), String>) -> MainResult {
match res {
Ok(()) => Ok(()),
@@ -739,7 +703,33 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
}
}
-fn main_options(options: config::Options) -> MainResult {
+fn main_args(at_args: &[String]) -> MainResult {
+ let args = rustc_driver::args::arg_expand_all(at_args);
+
+ let mut options = getopts::Options::new();
+ for option in opts() {
+ (option.apply)(&mut options);
+ }
+ let matches = match options.parse(&args[1..]) {
+ Ok(m) => m,
+ Err(err) => {
+ early_error(ErrorOutputType::default(), &err.to_string());
+ }
+ };
+
+ // Note that we discard any distinction between different non-zero exit
+ // codes from `from_matches` here.
+ let (options, render_options) = match config::Options::from_matches(&matches, args) {
+ Ok(opts) => opts,
+ Err(code) => {
+ return if code == 0 {
+ Ok(())
+ } else {
+ Err(ErrorGuaranteed::unchecked_claim_error_was_emitted())
+ };
+ }
+ };
+
let diag = core::new_handler(
options.error_format,
None,
@@ -751,9 +741,18 @@ fn main_options(options: config::Options) -> MainResult {
(true, true) => return wrap_return(&diag, markdown::test(options)),
(true, false) => return doctest::run(options),
(false, true) => {
+ let input = options.input.clone();
+ let edition = options.edition;
+ let config = core::create_config(options);
+
+ // `markdown::render` can invoke `doctest::make_test`, which
+ // requires session globals and a thread pool, so we use
+ // `run_compiler`.
return wrap_return(
&diag,
- markdown::render(&options.input, options.render_options, options.edition),
+ interface::run_compiler(config, |_compiler| {
+ markdown::render(&input, render_options, edition)
+ }),
);
}
(false, false) => {}
@@ -774,14 +773,12 @@ fn main_options(options: config::Options) -> MainResult {
let crate_version = options.crate_version.clone();
let output_format = options.output_format;
- // FIXME: fix this clone (especially render_options)
let externs = options.externs.clone();
- let render_options = options.render_options.clone();
let scrape_examples_options = options.scrape_examples_options.clone();
- let document_private = options.render_options.document_private;
+
let config = core::create_config(options);
- interface::create_compiler_and_run(config, |compiler| {
+ interface::run_compiler(config, |compiler| {
let sess = compiler.session();
if sess.opts.describe_lints {
@@ -813,7 +810,7 @@ fn main_options(options: config::Options) -> MainResult {
sess,
krate,
externs,
- document_private,
+ render_options.document_private,
)
});
(resolver.clone(), resolver_caches)
diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs
index e76c19a61..3aad97bc2 100644
--- a/src/librustdoc/lint.rs
+++ b/src/librustdoc/lint.rs
@@ -148,7 +148,7 @@ declare_rustdoc_lint! {
///
/// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags
INVALID_HTML_TAGS,
- Allow,
+ Warn,
"detects invalid HTML tags in doc comments"
}
diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs
index 0b557ef24..044e05144 100644
--- a/src/librustdoc/markdown.rs
+++ b/src/librustdoc/markdown.rs
@@ -5,7 +5,6 @@ use std::path::Path;
use rustc_span::edition::Edition;
use rustc_span::source_map::DUMMY_SP;
-use rustc_span::Symbol;
use crate::config::{Options, RenderOptions};
use crate::doctest::{Collector, GlobalTestOptions};
@@ -36,6 +35,8 @@ fn extract_leading_metadata(s: &str) -> (Vec<&str>, &str) {
/// Render `input` (e.g., "foo.md") into an HTML file in `output`
/// (e.g., output = "bar" => "bar/foo.html").
+///
+/// Requires session globals to be available, for symbol interning.
pub(crate) fn render<P: AsRef<Path>>(
input: P,
options: RenderOptions,
@@ -133,7 +134,7 @@ pub(crate) fn test(options: Options) -> Result<(), String> {
let mut opts = GlobalTestOptions::default();
opts.no_crate_inject = true;
let mut collector = Collector::new(
- Symbol::intern(&options.input.display().to_string()),
+ options.input.display().to_string(),
options.clone(),
true,
opts,
@@ -142,7 +143,7 @@ pub(crate) fn test(options: Options) -> Result<(), String> {
options.enable_per_target_ignores,
);
collector.set_position(DUMMY_SP);
- let codes = ErrorCodes::from(options.render_options.unstable_features.is_nightly_build());
+ let codes = ErrorCodes::from(options.unstable_features.is_nightly_build());
find_testable_code(&input_str, &mut collector, codes, options.enable_per_target_ignores, None);
diff --git a/src/librustdoc/passes/bare_urls.rs b/src/librustdoc/passes/bare_urls.rs
index 392e26ea6..7ff3ccef9 100644
--- a/src/librustdoc/passes/bare_urls.rs
+++ b/src/librustdoc/passes/bare_urls.rs
@@ -71,16 +71,14 @@ impl<'a, 'tcx> DocVisitor for BareUrlsLinter<'a, 'tcx> {
let report_diag = |cx: &DocContext<'_>, msg: &str, url: &str, range: Range<usize>| {
let sp = super::source_span_for_markdown_range(cx.tcx, &dox, &range, &item.attrs)
.unwrap_or_else(|| item.attr_span(cx.tcx));
- cx.tcx.struct_span_lint_hir(crate::lint::BARE_URLS, hir_id, sp, |lint| {
- lint.build(msg)
- .note("bare URLs are not automatically turned into clickable links")
+ cx.tcx.struct_span_lint_hir(crate::lint::BARE_URLS, hir_id, sp, msg, |lint| {
+ lint.note("bare URLs are not automatically turned into clickable links")
.span_suggestion(
sp,
"use an automatic link instead",
format!("<{}>", url),
Applicability::MachineApplicable,
)
- .emit();
});
};
diff --git a/src/librustdoc/passes/check_code_block_syntax.rs b/src/librustdoc/passes/check_code_block_syntax.rs
index 381ac7a5d..2e651b538 100644
--- a/src/librustdoc/passes/check_code_block_syntax.rs
+++ b/src/librustdoc/passes/check_code_block_syntax.rs
@@ -1,8 +1,9 @@
//! Validates syntax inside Rust code blocks (\`\`\`rust).
use rustc_data_structures::sync::{Lock, Lrc};
use rustc_errors::{
- emitter::Emitter, translation::Translate, Applicability, Diagnostic, Handler,
- LazyFallbackBundle, LintDiagnosticBuilder,
+ emitter::Emitter,
+ translation::{to_fluent_args, Translate},
+ Applicability, Diagnostic, Handler, LazyFallbackBundle,
};
use rustc_parse::parse_stream_from_source_str;
use rustc_session::parse::ParseSess;
@@ -97,48 +98,10 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
None => (item.attr_span(self.cx.tcx), false),
};
- // lambda that will use the lint to start a new diagnostic and add
- // a suggestion to it when needed.
- let diag_builder = |lint: LintDiagnosticBuilder<'_, ()>| {
- let explanation = if is_ignore {
- "`ignore` code blocks require valid Rust code for syntax highlighting; \
- mark blocks that do not contain Rust code as text"
- } else {
- "mark blocks that do not contain Rust code as text"
- };
- let msg = if buffer.has_errors {
- "could not parse code block as Rust code"
- } else {
- "Rust code block is empty"
- };
- let mut diag = lint.build(msg);
-
- if precise_span {
- if is_ignore {
- // giving an accurate suggestion is hard because `ignore` might not have come first in the list.
- // just give a `help` instead.
- diag.span_help(
- sp.from_inner(InnerSpan::new(0, 3)),
- &format!("{}: ```text", explanation),
- );
- } else if empty_block {
- diag.span_suggestion(
- sp.from_inner(InnerSpan::new(0, 3)).shrink_to_hi(),
- explanation,
- "text",
- Applicability::MachineApplicable,
- );
- }
- } else if empty_block || is_ignore {
- diag.help(&format!("{}: ```text", explanation));
- }
-
- // FIXME(#67563): Provide more context for these errors by displaying the spans inline.
- for message in buffer.messages.iter() {
- diag.note(message);
- }
-
- diag.emit();
+ let msg = if buffer.has_errors {
+ "could not parse code block as Rust code"
+ } else {
+ "Rust code block is empty"
};
// Finally build and emit the completed diagnostic.
@@ -148,7 +111,42 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
crate::lint::INVALID_RUST_CODEBLOCKS,
hir_id,
sp,
- diag_builder,
+ msg,
+ |lint| {
+ let explanation = if is_ignore {
+ "`ignore` code blocks require valid Rust code for syntax highlighting; \
+ mark blocks that do not contain Rust code as text"
+ } else {
+ "mark blocks that do not contain Rust code as text"
+ };
+
+ if precise_span {
+ if is_ignore {
+ // giving an accurate suggestion is hard because `ignore` might not have come first in the list.
+ // just give a `help` instead.
+ lint.span_help(
+ sp.from_inner(InnerSpan::new(0, 3)),
+ &format!("{}: ```text", explanation),
+ );
+ } else if empty_block {
+ lint.span_suggestion(
+ sp.from_inner(InnerSpan::new(0, 3)).shrink_to_hi(),
+ explanation,
+ "text",
+ Applicability::MachineApplicable,
+ );
+ }
+ } else if empty_block || is_ignore {
+ lint.help(&format!("{}: ```text", explanation));
+ }
+
+ // FIXME(#67563): Provide more context for these errors by displaying the spans inline.
+ for message in buffer.messages.iter() {
+ lint.note(message);
+ }
+
+ lint
+ },
);
}
}
@@ -195,8 +193,11 @@ impl Translate for BufferEmitter {
impl Emitter for BufferEmitter {
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
let mut buffer = self.buffer.borrow_mut();
- // FIXME(davidtwco): need to support translation here eventually
- buffer.messages.push(format!("error from rustc: {}", diag.message[0].0.expect_str()));
+
+ let fluent_args = to_fluent_args(diag.args());
+ let translated_main_message = self.translate_message(&diag.message[0].0, &fluent_args);
+
+ buffer.messages.push(format!("error from rustc: {}", translated_main_message));
if diag.is_error() {
buffer.has_errors = true;
}
diff --git a/src/librustdoc/passes/check_doc_test_visibility.rs b/src/librustdoc/passes/check_doc_test_visibility.rs
index 55d5f303d..7740c6d5b 100644
--- a/src/librustdoc/passes/check_doc_test_visibility.rs
+++ b/src/librustdoc/passes/check_doc_test_visibility.rs
@@ -56,7 +56,7 @@ impl crate::doctest::Tester for Tests {
}
pub(crate) fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> bool {
- if !cx.cache.access_levels.is_public(item.item_id.expect_def_id())
+ if !cx.cache.effective_visibilities.is_directly_public(item.item_id.expect_def_id())
|| matches!(
*item.kind,
clean::StructFieldItem(_)
@@ -125,21 +125,19 @@ pub(crate) fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item
crate::lint::MISSING_DOC_CODE_EXAMPLES,
hir_id,
sp,
- |lint| {
- lint.build("missing code example in this documentation").emit();
- },
+ "missing code example in this documentation",
+ |lint| lint,
);
}
} else if tests.found_tests > 0
- && !cx.cache.access_levels.is_exported(item.item_id.expect_def_id())
+ && !cx.cache.effective_visibilities.is_exported(item.item_id.expect_def_id())
{
cx.tcx.struct_span_lint_hir(
crate::lint::PRIVATE_DOC_TESTS,
hir_id,
item.attr_span(cx.tcx),
- |lint| {
- lint.build("documentation test in private item").emit();
- },
+ "documentation test in private item",
+ |lint| lint,
);
}
}
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs
index b2a41bfa4..8aa0abd36 100644
--- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
@@ -80,10 +80,10 @@ impl Res {
}
}
- fn def_id(self, tcx: TyCtxt<'_>) -> DefId {
+ fn def_id(self, tcx: TyCtxt<'_>) -> Option<DefId> {
match self {
- Res::Def(_, id) => id,
- Res::Primitive(prim) => *PrimitiveType::primitive_locations(tcx).get(&prim).unwrap(),
+ Res::Def(_, id) => Some(id),
+ Res::Primitive(prim) => PrimitiveType::primitive_locations(tcx).get(&prim).copied(),
}
}
@@ -1127,10 +1127,10 @@ impl LinkCollector<'_, '_> {
}
}
- Some(ItemLink {
+ res.def_id(self.cx.tcx).map(|page_id| ItemLink {
link: ori_link.link.clone(),
link_text: link_text.clone(),
- page_id: res.def_id(self.cx.tcx),
+ page_id,
fragment,
})
}
@@ -1202,8 +1202,8 @@ impl LinkCollector<'_, '_> {
item.item_id.expect_def_id().as_local().map(|src_id| (src_id, dst_id))
})
{
- if self.cx.tcx.privacy_access_levels(()).is_exported(src_id)
- && !self.cx.tcx.privacy_access_levels(()).is_exported(dst_id)
+ if self.cx.tcx.effective_visibilities(()).is_exported(src_id)
+ && !self.cx.tcx.effective_visibilities(()).is_exported(dst_id)
{
privacy_error(self.cx, diag_info, path_str);
}
@@ -1609,9 +1609,7 @@ fn report_diagnostic(
let sp = item.attr_span(tcx);
- tcx.struct_span_lint_hir(lint, hir_id, sp, |lint| {
- let mut diag = lint.build(msg);
-
+ tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |lint| {
let span =
super::source_span_for_markdown_range(tcx, dox, link_range, &item.attrs).map(|sp| {
if dox.as_bytes().get(link_range.start) == Some(&b'`')
@@ -1624,7 +1622,7 @@ fn report_diagnostic(
});
if let Some(sp) = span {
- diag.set_span(sp);
+ lint.set_span(sp);
} else {
// blah blah blah\nblah\nblah [blah] blah blah\nblah blah
// ^ ~~~~
@@ -1634,7 +1632,7 @@ fn report_diagnostic(
let line = dox[last_new_line_offset..].lines().next().unwrap_or("");
// Print the line containing the `link_range` and manually mark it with '^'s.
- diag.note(&format!(
+ lint.note(&format!(
"the link appears in this line:\n\n{line}\n\
{indicator: <before$}{indicator:^<found$}",
line = line,
@@ -1644,9 +1642,9 @@ fn report_diagnostic(
));
}
- decorate(&mut diag, span);
+ decorate(lint, span);
- diag.emit();
+ lint
});
}
@@ -1895,7 +1893,7 @@ fn disambiguator_error(
diag_info.link_range = disambiguator_range;
report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, msg, &diag_info, |diag, _sp| {
let msg = format!(
- "see {}/rustdoc/write-documentation/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators",
+ "see {}/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators",
crate::DOC_RUST_LANG_ORG_CHANNEL
);
diag.note(&msg);
diff --git a/src/librustdoc/passes/collect_intra_doc_links/early.rs b/src/librustdoc/passes/collect_intra_doc_links/early.rs
index 38cfd7a27..1b373cfe5 100644
--- a/src/librustdoc/passes/collect_intra_doc_links/early.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links/early.rs
@@ -37,7 +37,6 @@ pub(crate) fn early_resolve_intra_doc_links(
markdown_links: Default::default(),
doc_link_resolutions: Default::default(),
traits_in_scope: Default::default(),
- all_traits: Default::default(),
all_trait_impls: Default::default(),
all_macro_rules: Default::default(),
document_private_items,
@@ -48,7 +47,6 @@ pub(crate) fn early_resolve_intra_doc_links(
link_resolver.resolve_doc_links_local(&krate.attrs);
link_resolver.process_module_children_or_reexports(CRATE_DEF_ID.to_def_id());
visit::walk_crate(&mut link_resolver, krate);
- link_resolver.process_extern_impls();
// FIXME: somehow rustdoc is still missing crates even though we loaded all
// the known necessary crates. Load them all unconditionally until we find a way to fix this.
@@ -58,11 +56,12 @@ pub(crate) fn early_resolve_intra_doc_links(
link_resolver.resolver.resolve_rustdoc_path(extern_name, TypeNS, parent_scope);
}
+ link_resolver.process_extern_impls();
+
ResolverCaches {
markdown_links: Some(link_resolver.markdown_links),
doc_link_resolutions: link_resolver.doc_link_resolutions,
traits_in_scope: link_resolver.traits_in_scope,
- all_traits: Some(link_resolver.all_traits),
all_trait_impls: Some(link_resolver.all_trait_impls),
all_macro_rules: link_resolver.all_macro_rules,
}
@@ -80,7 +79,6 @@ struct EarlyDocLinkResolver<'r, 'ra> {
markdown_links: FxHashMap<String, Vec<PreprocessedMarkdownLink>>,
doc_link_resolutions: FxHashMap<(Symbol, Namespace, DefId), Option<Res<ast::NodeId>>>,
traits_in_scope: DefIdMap<Vec<TraitCandidate>>,
- all_traits: Vec<DefId>,
all_trait_impls: Vec<DefId>,
all_macro_rules: FxHashMap<Symbol, Res<ast::NodeId>>,
document_private_items: bool,
@@ -121,8 +119,6 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
loop {
let crates = Vec::from_iter(self.resolver.cstore().crates_untracked());
for &cnum in &crates[start_cnum..] {
- let all_traits =
- Vec::from_iter(self.resolver.cstore().traits_in_crate_untracked(cnum));
let all_trait_impls =
Vec::from_iter(self.resolver.cstore().trait_impls_in_crate_untracked(cnum));
let all_inherent_impls =
@@ -131,20 +127,18 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
self.resolver.cstore().incoherent_impls_in_crate_untracked(cnum),
);
- // Querying traits in scope is expensive so we try to prune the impl and traits lists
- // using privacy, private traits and impls from other crates are never documented in
+ // Querying traits in scope is expensive so we try to prune the impl lists using
+ // privacy, private traits and impls from other crates are never documented in
// the current crate, and links in their doc comments are not resolved.
- for &def_id in &all_traits {
- if self.resolver.cstore().visibility_untracked(def_id).is_public() {
- self.resolve_doc_links_extern_impl(def_id, false);
- }
- }
for &(trait_def_id, impl_def_id, simplified_self_ty) in &all_trait_impls {
if self.resolver.cstore().visibility_untracked(trait_def_id).is_public()
&& simplified_self_ty.and_then(|ty| ty.def()).map_or(true, |ty_def_id| {
self.resolver.cstore().visibility_untracked(ty_def_id).is_public()
})
{
+ if self.visited_mods.insert(trait_def_id) {
+ self.resolve_doc_links_extern_impl(trait_def_id, false);
+ }
self.resolve_doc_links_extern_impl(impl_def_id, false);
}
}
@@ -157,7 +151,6 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
self.resolve_doc_links_extern_impl(impl_def_id, true);
}
- self.all_traits.extend(all_traits);
self.all_trait_impls
.extend(all_trait_impls.into_iter().map(|(_, def_id, _)| def_id));
}
@@ -306,15 +299,20 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
{
if let Some(def_id) = child.res.opt_def_id() && !def_id.is_local() {
let scope_id = match child.res {
- Res::Def(DefKind::Variant, ..) => self.resolver.parent(def_id),
+ Res::Def(
+ DefKind::Variant
+ | DefKind::AssocTy
+ | DefKind::AssocFn
+ | DefKind::AssocConst,
+ ..,
+ ) => self.resolver.parent(def_id),
_ => def_id,
};
self.resolve_doc_links_extern_outer(def_id, scope_id); // Outer attribute scope
if let Res::Def(DefKind::Mod, ..) = child.res {
self.resolve_doc_links_extern_inner(def_id); // Inner attribute scope
}
- // `DefKind::Trait`s are processed in `process_extern_impls`.
- if let Res::Def(DefKind::Mod | DefKind::Enum, ..) = child.res {
+ if let Res::Def(DefKind::Mod | DefKind::Enum | DefKind::Trait, ..) = child.res {
self.process_module_children_or_reexports(def_id);
}
if let Res::Def(DefKind::Struct | DefKind::Union | DefKind::Variant, _) =
@@ -356,10 +354,14 @@ impl Visitor<'_> for EarlyDocLinkResolver<'_, '_> {
self.parent_scope.module = old_module;
} else {
match &item.kind {
- ItemKind::Trait(..) => {
- self.all_traits.push(self.resolver.local_def_id(item.id).to_def_id());
- }
- ItemKind::Impl(box ast::Impl { of_trait: Some(..), .. }) => {
+ ItemKind::Impl(box ast::Impl { of_trait: Some(trait_ref), .. }) => {
+ if let Some(partial_res) = self.resolver.get_partial_res(trait_ref.ref_id)
+ && let Some(res) = partial_res.full_res()
+ && let Some(trait_def_id) = res.opt_def_id()
+ && !trait_def_id.is_local()
+ && self.visited_mods.insert(trait_def_id) {
+ self.resolve_doc_links_extern_impl(trait_def_id, false);
+ }
self.all_trait_impls.push(self.resolver.local_def_id(item.id).to_def_id());
}
ItemKind::MacroDef(macro_def) if macro_def.macro_rules => {
diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs
index 885dadb32..a89ed7c7e 100644
--- a/src/librustdoc/passes/html_tags.rs
+++ b/src/librustdoc/passes/html_tags.rs
@@ -22,10 +22,8 @@ struct InvalidHtmlTagsLinter<'a, 'tcx> {
}
pub(crate) fn check_invalid_html_tags(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
- if cx.tcx.sess.is_nightly_build() {
- let mut coll = InvalidHtmlTagsLinter { cx };
- coll.visit_crate(&krate);
- }
+ let mut coll = InvalidHtmlTagsLinter { cx };
+ coll.visit_crate(&krate);
krate
}
@@ -186,7 +184,60 @@ fn extract_html_tag(
}
drop_tag(tags, tag_name, r, f);
} else {
- tags.push((tag_name, r));
+ let mut is_self_closing = false;
+ let mut quote_pos = None;
+ if c != '>' {
+ let mut quote = None;
+ let mut after_eq = false;
+ for (i, c) in text[pos..].char_indices() {
+ if !c.is_whitespace() {
+ if let Some(q) = quote {
+ if c == q {
+ quote = None;
+ quote_pos = None;
+ after_eq = false;
+ }
+ } else if c == '>' {
+ break;
+ } else if c == '/' && !after_eq {
+ is_self_closing = true;
+ } else {
+ if is_self_closing {
+ is_self_closing = false;
+ }
+ if (c == '"' || c == '\'') && after_eq {
+ quote = Some(c);
+ quote_pos = Some(pos + i);
+ } else if c == '=' {
+ after_eq = true;
+ }
+ }
+ } else if quote.is_none() {
+ after_eq = false;
+ }
+ }
+ }
+ if let Some(quote_pos) = quote_pos {
+ let qr = Range { start: quote_pos, end: quote_pos };
+ f(
+ &format!("unclosed quoted HTML attribute on tag `{}`", tag_name),
+ &qr,
+ false,
+ );
+ }
+ if is_self_closing {
+ // https://html.spec.whatwg.org/#parse-error-non-void-html-element-start-tag-with-trailing-solidus
+ let valid = ALLOWED_UNCLOSED.contains(&&tag_name[..])
+ || tags.iter().take(pos + 1).any(|(at, _)| {
+ let at = at.to_lowercase();
+ at == "svg" || at == "math"
+ });
+ if !valid {
+ f(&format!("invalid self-closing HTML tag `{}`", tag_name), &r, false);
+ }
+ } else {
+ tags.push((tag_name, r));
+ }
}
}
break;
@@ -240,9 +291,8 @@ impl<'a, 'tcx> DocVisitor for InvalidHtmlTagsLinter<'a, 'tcx> {
Some(sp) => sp,
None => item.attr_span(tcx),
};
- tcx.struct_span_lint_hir(crate::lint::INVALID_HTML_TAGS, hir_id, sp, |lint| {
+ tcx.struct_span_lint_hir(crate::lint::INVALID_HTML_TAGS, hir_id, sp, msg, |lint| {
use rustc_lint_defs::Applicability;
- let mut diag = lint.build(msg);
// If a tag looks like `<this>`, it might actually be a generic.
// We don't try to detect stuff `<like, this>` because that's not valid HTML,
// and we don't try to detect stuff `<like this>` because that's not valid Rust.
@@ -305,11 +355,10 @@ impl<'a, 'tcx> DocVisitor for InvalidHtmlTagsLinter<'a, 'tcx> {
if (generics_start > 0 && dox.as_bytes()[generics_start - 1] == b'<')
|| (generics_end < dox.len() && dox.as_bytes()[generics_end] == b'>')
{
- diag.emit();
- return;
+ return lint;
}
// multipart form is chosen here because ``Vec<i32>`` would be confusing.
- diag.multipart_suggestion(
+ lint.multipart_suggestion(
"try marking as source code",
vec![
(generics_sp.shrink_to_lo(), String::from("`")),
@@ -318,7 +367,8 @@ impl<'a, 'tcx> DocVisitor for InvalidHtmlTagsLinter<'a, 'tcx> {
Applicability::MaybeIncorrect,
);
}
- diag.emit()
+
+ lint
});
};
diff --git a/src/librustdoc/passes/propagate_doc_cfg.rs b/src/librustdoc/passes/propagate_doc_cfg.rs
index 765f7c61b..de3a4b339 100644
--- a/src/librustdoc/passes/propagate_doc_cfg.rs
+++ b/src/librustdoc/passes/propagate_doc_cfg.rs
@@ -48,7 +48,7 @@ impl<'a, 'tcx> CfgPropagator<'a, 'tcx> {
let expected_parent = hir.get_parent_item(hir_id);
// If parents are different, it means that `item` is a reexport and we need
// to compute the actual `cfg` by iterating through its "real" parents.
- if self.parent == Some(expected_parent) {
+ if self.parent == Some(expected_parent.def_id) {
return;
}
}
diff --git a/src/librustdoc/passes/strip_private.rs b/src/librustdoc/passes/strip_private.rs
index f3aa3c7ce..450f69e15 100644
--- a/src/librustdoc/passes/strip_private.rs
+++ b/src/librustdoc/passes/strip_private.rs
@@ -23,7 +23,7 @@ pub(crate) fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) ->
{
let mut stripper = Stripper {
retained: &mut retained,
- access_levels: &cx.cache.access_levels,
+ effective_visibilities: &cx.cache.effective_visibilities,
update_retained: true,
is_json_output,
};
diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs
index a9d768f01..0089ce63d 100644
--- a/src/librustdoc/passes/stripper.rs
+++ b/src/librustdoc/passes/stripper.rs
@@ -1,15 +1,17 @@
//! A collection of utility functions for the `strip_*` passes.
use rustc_hir::def_id::DefId;
-use rustc_middle::middle::privacy::AccessLevels;
+use rustc_middle::middle::privacy::EffectiveVisibilities;
+use rustc_span::symbol::sym;
+
use std::mem;
-use crate::clean::{self, Item, ItemId, ItemIdSet};
+use crate::clean::{self, Item, ItemId, ItemIdSet, NestedAttributesExt};
use crate::fold::{strip_item, DocFolder};
use crate::formats::cache::Cache;
pub(crate) struct Stripper<'a> {
pub(crate) retained: &'a mut ItemIdSet,
- pub(crate) access_levels: &'a AccessLevels<DefId>,
+ pub(crate) effective_visibilities: &'a EffectiveVisibilities<DefId>,
pub(crate) update_retained: bool,
pub(crate) is_json_output: bool,
}
@@ -20,13 +22,13 @@ pub(crate) struct Stripper<'a> {
#[inline]
fn is_item_reachable(
is_json_output: bool,
- access_levels: &AccessLevels<DefId>,
+ effective_visibilities: &EffectiveVisibilities<DefId>,
item_id: ItemId,
) -> bool {
if is_json_output {
- access_levels.is_reachable(item_id.expect_def_id())
+ effective_visibilities.is_reachable(item_id.expect_def_id())
} else {
- access_levels.is_exported(item_id.expect_def_id())
+ effective_visibilities.is_exported(item_id.expect_def_id())
}
}
@@ -64,7 +66,7 @@ impl<'a> DocFolder for Stripper<'a> {
| clean::ForeignTypeItem => {
let item_id = i.item_id;
if item_id.is_local()
- && !is_item_reachable(self.is_json_output, self.access_levels, item_id)
+ && !is_item_reachable(self.is_json_output, self.effective_visibilities, item_id)
{
debug!("Stripper: stripping {:?} {:?}", i.type_(), i.name);
return None;
@@ -151,6 +153,22 @@ pub(crate) struct ImplStripper<'a> {
pub(crate) document_private: bool,
}
+impl<'a> ImplStripper<'a> {
+ #[inline]
+ fn should_keep_impl(&self, item: &Item, for_def_id: DefId) -> bool {
+ if !for_def_id.is_local() || self.retained.contains(&for_def_id.into()) {
+ true
+ } else if self.is_json_output {
+ // If the "for" item is exported and the impl block isn't `#[doc(hidden)]`, then we
+ // need to keep it.
+ self.cache.effective_visibilities.is_exported(for_def_id)
+ && !item.attrs.lists(sym::doc).has_word(sym::hidden)
+ } else {
+ false
+ }
+ }
+}
+
impl<'a> DocFolder for ImplStripper<'a> {
fn fold_item(&mut self, i: Item) -> Option<Item> {
if let clean::ImplItem(ref imp) = *i.kind {
@@ -168,7 +186,7 @@ impl<'a> DocFolder for ImplStripper<'a> {
item_id.is_local()
&& !is_item_reachable(
self.is_json_output,
- &self.cache.access_levels,
+ &self.cache.effective_visibilities,
item_id,
)
})
@@ -178,15 +196,17 @@ impl<'a> DocFolder for ImplStripper<'a> {
return None;
}
}
+ // Because we don't inline in `maybe_inline_local` if the output format is JSON,
+ // we need to make a special check for JSON output: we want to keep it unless it has
+ // a `#[doc(hidden)]` attribute if the `for_` type is exported.
if let Some(did) = imp.for_.def_id(self.cache) {
- if did.is_local() && !imp.for_.is_assoc_ty() && !self.retained.contains(&did.into())
- {
+ if !imp.for_.is_assoc_ty() && !self.should_keep_impl(&i, did) {
debug!("ImplStripper: impl item for stripped type; removing");
return None;
}
}
if let Some(did) = imp.trait_.as_ref().map(|t| t.def_id()) {
- if did.is_local() && !self.retained.contains(&did.into()) {
+ if !self.should_keep_impl(&i, did) {
debug!("ImplStripper: impl item for stripped trait; removing");
return None;
}
@@ -194,7 +214,7 @@ impl<'a> DocFolder for ImplStripper<'a> {
if let Some(generics) = imp.trait_.as_ref().and_then(|t| t.generics()) {
for typaram in generics {
if let Some(did) = typaram.def_id(self.cache) {
- if did.is_local() && !self.retained.contains(&did.into()) {
+ if !self.should_keep_impl(&i, did) {
debug!(
"ImplStripper: stripped item in trait's generics; removing impl"
);
diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs
index ca86ac89e..dfa6ba38b 100644
--- a/src/librustdoc/scrape_examples.rs
+++ b/src/librustdoc/scrape_examples.rs
@@ -143,14 +143,14 @@ where
// then we need to exit before calling typeck (which will panic). See
// test/run-make/rustdoc-scrape-examples-invalid-expr for an example.
let hir = tcx.hir();
- if hir.maybe_body_owned_by(ex.hir_id.owner).is_none() {
+ if hir.maybe_body_owned_by(ex.hir_id.owner.def_id).is_none() {
return;
}
// Get type of function if expression is a function call
let (ty, call_span, ident_span) = match ex.kind {
hir::ExprKind::Call(f, _) => {
- let types = tcx.typeck(ex.hir_id.owner);
+ let types = tcx.typeck(ex.hir_id.owner.def_id);
if let Some(ty) = types.node_type_opt(f.hir_id) {
(ty, ex.span, f.span)
@@ -160,7 +160,7 @@ where
}
}
hir::ExprKind::MethodCall(path, _, _, call_span) => {
- let types = tcx.typeck(ex.hir_id.owner);
+ let types = tcx.typeck(ex.hir_id.owner.def_id);
let Some(def_id) = types.type_dependent_def_id(ex.hir_id) else {
trace!("type_dependent_def_id({}) = None", ex.hir_id);
return;
@@ -183,9 +183,8 @@ where
// If the enclosing item has a span coming from a proc macro, then we also don't want to include
// the example.
- let enclosing_item_span = tcx
- .hir()
- .span_with_body(tcx.hir().local_def_id_to_hir_id(tcx.hir().get_parent_item(ex.hir_id)));
+ let enclosing_item_span =
+ tcx.hir().span_with_body(tcx.hir().get_parent_item(ex.hir_id).into());
if enclosing_item_span.from_expansion() {
trace!("Rejecting expr ({call_span:?}) from macro item: {enclosing_item_span:?}");
return;
diff --git a/src/librustdoc/visit.rs b/src/librustdoc/visit.rs
index c40274394..d29ceead4 100644
--- a/src/librustdoc/visit.rs
+++ b/src/librustdoc/visit.rs
@@ -65,7 +65,7 @@ pub(crate) trait DocVisitor: Sized {
// FIXME: make this a simple by-ref for loop once external_traits is cleaned up
let external_traits = { std::mem::take(&mut *c.external_traits.borrow_mut()) };
for (k, v) in external_traits {
- v.trait_.items.iter().for_each(|i| self.visit_item(i));
+ v.items.iter().for_each(|i| self.visit_item(i));
c.external_traits.borrow_mut().insert(k, v);
}
}
diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs
index c27ac0ac4..06dffce55 100644
--- a/src/librustdoc/visit_ast.rs
+++ b/src/librustdoc/visit_ast.rs
@@ -7,8 +7,8 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::Node;
use rustc_hir::CRATE_HIR_ID;
-use rustc_middle::middle::privacy::AccessLevel;
-use rustc_middle::ty::TyCtxt;
+use rustc_middle::middle::privacy::Level;
+use rustc_middle::ty::{TyCtxt, Visibility};
use rustc_span::def_id::{CRATE_DEF_ID, LOCAL_CRATE};
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::Span;
@@ -230,7 +230,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
} else {
// All items need to be handled here in case someone wishes to link
// to them with intra-doc links
- self.cx.cache.access_levels.map.insert(did, AccessLevel::Public);
+ self.cx.cache.effective_visibilities.set_public_at_level(
+ did,
+ || Visibility::Restricted(CRATE_DEF_ID),
+ Level::Direct,
+ );
}
}
}
@@ -242,7 +246,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
None => return false,
};
- let is_private = !self.cx.cache.access_levels.is_public(res_did);
+ let is_private = !self.cx.cache.effective_visibilities.is_directly_public(res_did);
let is_hidden = inherits_doc_hidden(self.cx.tcx, res_hir_id);
// Only inline if requested or if the item would otherwise be stripped.
@@ -291,11 +295,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
debug!("visiting item {:?}", item);
let name = renamed.unwrap_or(item.ident.name);
- let def_id = item.def_id.to_def_id();
+ let def_id = item.owner_id.to_def_id();
let is_pub = self.cx.tcx.visibility(def_id).is_public();
if is_pub {
- self.store_path(item.def_id.to_def_id());
+ self.store_path(item.owner_id.to_def_id());
}
match item.kind {
@@ -356,7 +360,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// 3. We're inlining, since a reexport where inlining has been requested
// should be inlined even if it is also documented at the top level.
- let def_id = item.def_id.to_def_id();
+ let def_id = item.owner_id.to_def_id();
let is_macro_2_0 = !macro_def.macro_rules;
let nonexported = !self.cx.tcx.has_attr(def_id, sym::macro_export);
@@ -401,7 +405,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
om: &mut Module<'tcx>,
) {
// If inlining we only want to include public functions.
- if !self.inlining || self.cx.tcx.visibility(item.def_id).is_public() {
+ if !self.inlining || self.cx.tcx.visibility(item.owner_id).is_public() {
om.foreigns.push((item, renamed));
}
}
diff --git a/src/librustdoc/visit_lib.rs b/src/librustdoc/visit_lib.rs
index f01ec3866..70214e2ad 100644
--- a/src/librustdoc/visit_lib.rs
+++ b/src/librustdoc/visit_lib.rs
@@ -1,8 +1,8 @@
use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def::{DefKind, Res};
-use rustc_hir::def_id::{CrateNum, DefId};
-use rustc_middle::middle::privacy::{AccessLevel, AccessLevels};
-use rustc_middle::ty::TyCtxt;
+use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_ID};
+use rustc_middle::middle::privacy::{EffectiveVisibilities, Level};
+use rustc_middle::ty::{TyCtxt, Visibility};
// FIXME: this may not be exhaustive, but is sufficient for rustdocs current uses
@@ -10,10 +10,10 @@ use rustc_middle::ty::TyCtxt;
/// specific rustdoc annotations into account (i.e., `doc(hidden)`)
pub(crate) struct LibEmbargoVisitor<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
- // Accessibility levels for reachable nodes
- access_levels: &'a mut AccessLevels<DefId>,
- // Previous accessibility level, None means unreachable
- prev_level: Option<AccessLevel>,
+ // Effective visibilities for reachable nodes
+ effective_visibilities: &'a mut EffectiveVisibilities<DefId>,
+ // Previous level, None means unreachable
+ prev_level: Option<Level>,
// Keeps track of already visited modules, in case a module re-exports its parent
visited_mods: FxHashSet<DefId>,
}
@@ -22,26 +22,30 @@ impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> {
pub(crate) fn new(cx: &'a mut crate::core::DocContext<'tcx>) -> LibEmbargoVisitor<'a, 'tcx> {
LibEmbargoVisitor {
tcx: cx.tcx,
- access_levels: &mut cx.cache.access_levels,
- prev_level: Some(AccessLevel::Public),
+ effective_visibilities: &mut cx.cache.effective_visibilities,
+ prev_level: Some(Level::Direct),
visited_mods: FxHashSet::default(),
}
}
pub(crate) fn visit_lib(&mut self, cnum: CrateNum) {
let did = cnum.as_def_id();
- self.update(did, Some(AccessLevel::Public));
+ self.update(did, Some(Level::Direct));
self.visit_mod(did);
}
// Updates node level and returns the updated level
- fn update(&mut self, did: DefId, level: Option<AccessLevel>) -> Option<AccessLevel> {
+ fn update(&mut self, did: DefId, level: Option<Level>) -> Option<Level> {
let is_hidden = self.tcx.is_doc_hidden(did);
- let old_level = self.access_levels.map.get(&did).cloned();
- // Accessibility levels can only grow
+ let old_level = self.effective_visibilities.public_at_level(did);
+ // Visibility levels can only grow
if level > old_level && !is_hidden {
- self.access_levels.map.insert(did, level.unwrap());
+ self.effective_visibilities.set_public_at_level(
+ did,
+ || Visibility::Restricted(CRATE_DEF_ID),
+ level.unwrap(),
+ );
level
} else {
old_level
diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs
index fb1830426..4bc91fc40 100644
--- a/src/rustdoc-json-types/lib.rs
+++ b/src/rustdoc-json-types/lib.rs
@@ -9,7 +9,7 @@ use std::path::PathBuf;
use serde::{Deserialize, Serialize};
/// rustdoc format-version.
-pub const FORMAT_VERSION: u32 = 21;
+pub const FORMAT_VERSION: u32 = 22;
/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
/// about the language items in the local crate, as well as info about external items to allow
@@ -51,6 +51,11 @@ pub struct ItemSummary {
pub crate_id: u32,
/// The list of path components for the fully qualified path of this item (e.g.
/// `["std", "io", "lazy", "Lazy"]` for `std::io::lazy::Lazy`).
+ ///
+ /// Note that items can appear in multiple paths, and the one chosen is implementation
+ /// defined. Currenty, this is the full path to where the item was defined. Eg
+ /// [`String`] is currently `["alloc", "string", "String"]` and [`HashMap`] is
+ /// `["std", "collections", "hash", "map", "HashMap"]`, but this is subject to change.
pub path: Vec<String>,
/// Whether this item is a struct, trait, macro, etc.
pub kind: ItemKind,
@@ -254,7 +259,7 @@ pub enum ItemEnum {
Macro(String),
ProcMacro(ProcMacro),
- PrimitiveType(String),
+ Primitive(Primitive),
AssocConst {
#[serde(rename = "type")]
@@ -709,5 +714,11 @@ pub struct Static {
pub expr: String,
}
+#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
+pub struct Primitive {
+ pub name: String,
+ pub impls: Vec<Id>,
+}
+
#[cfg(test)]
mod tests;
diff --git a/src/stage0.json b/src/stage0.json
index a54fd5496..db7444839 100644
--- a/src/stage0.json
+++ b/src/stage0.json
@@ -17,292 +17,292 @@
"tool is executed."
],
"compiler": {
- "date": "2022-09-22",
- "version": "1.64.0"
+ "date": "2022-11-03",
+ "version": "1.65.0"
},
"rustfmt": null,
"checksums_sha256": {
- "dist/2022-09-22/cargo-1.64.0-aarch64-apple-darwin.tar.gz": "dbb26b73baefc8351a7024f307445758fe1e9c18d83000358c02b80a5b1003b3",
- "dist/2022-09-22/cargo-1.64.0-aarch64-apple-darwin.tar.xz": "8d987d76039b730086ee303710d93f3ff2abcfe3cb74505d8e68c9f72edaa812",
- "dist/2022-09-22/cargo-1.64.0-aarch64-pc-windows-msvc.tar.gz": "6b86e2b51fa4471358e128369baff21a216815e90eb3ff70af7271e64438da0a",
- "dist/2022-09-22/cargo-1.64.0-aarch64-pc-windows-msvc.tar.xz": "dc174319e5750d6489fd45d982a5dd9d7305845e9aaaa809bef9f445f1c2c219",
- "dist/2022-09-22/cargo-1.64.0-aarch64-unknown-linux-gnu.tar.gz": "a2079bad79c054facecd149bafb645c321047fd9e4d2aa500607b2450654b209",
- "dist/2022-09-22/cargo-1.64.0-aarch64-unknown-linux-gnu.tar.xz": "103d69e4f2f49f5a6309d7d195747b31f94cf707f90fb49cf76039a5ce6295c7",
- "dist/2022-09-22/cargo-1.64.0-aarch64-unknown-linux-musl.tar.gz": "f589c0e8c0472128e88f751429b5e697b5605e2105e3571016400f98f47c1b54",
- "dist/2022-09-22/cargo-1.64.0-aarch64-unknown-linux-musl.tar.xz": "aff8dedcaa02b5059dd59f8c5644ed87b8c9c72be90c578044fe5755ca841418",
- "dist/2022-09-22/cargo-1.64.0-arm-unknown-linux-gnueabi.tar.gz": "f497f70e3154d78399487c75934734a13efdb64d5ba8fe7fcd4d28740cece688",
- "dist/2022-09-22/cargo-1.64.0-arm-unknown-linux-gnueabi.tar.xz": "79e703e1e0355ef3d268d13f778b2c85ada0dee9d5067fb94f5fca20c6d09c53",
- "dist/2022-09-22/cargo-1.64.0-arm-unknown-linux-gnueabihf.tar.gz": "40e6d068d84a110c74c63dbd9bc457c8e9d8c520bb75c64b2b4f1a269378a003",
- "dist/2022-09-22/cargo-1.64.0-arm-unknown-linux-gnueabihf.tar.xz": "d73428a73d9234c9f4f6412025ca827a667b2d6e8dc61e1852725784d8d3136d",
- "dist/2022-09-22/cargo-1.64.0-armv7-unknown-linux-gnueabihf.tar.gz": "a12455495aa39006f2cf83c9f86b7ecc4b188f98e683a99134c97eeb217b66bf",
- "dist/2022-09-22/cargo-1.64.0-armv7-unknown-linux-gnueabihf.tar.xz": "ecd2e5f4c08bbda72ad2936bfdd521d9a641d311e71e8ace44b00570f068b819",
- "dist/2022-09-22/cargo-1.64.0-i686-pc-windows-gnu.tar.gz": "2e73350bbe2e8c5fa27893e57704e37d6c6d8ef5d548a7bbe0d24615468f5158",
- "dist/2022-09-22/cargo-1.64.0-i686-pc-windows-gnu.tar.xz": "3596f78c51024eda28adc8be508ad084e1e6dfb71d8a0bce00a67cfc592ec5ad",
- "dist/2022-09-22/cargo-1.64.0-i686-pc-windows-msvc.tar.gz": "55b9d1a121410a5f3c755012ec4a55ee6f7c270a958c7a506c14542095a793bf",
- "dist/2022-09-22/cargo-1.64.0-i686-pc-windows-msvc.tar.xz": "64711cbcc71906184427f501399ebe304e95a42f2f773d251cdd6bb1a148dc94",
- "dist/2022-09-22/cargo-1.64.0-i686-unknown-linux-gnu.tar.gz": "da713a9521c857d87bfebc1e2b1da01e9882d11fa6cb1c2ebbf38b1b0a15bbcc",
- "dist/2022-09-22/cargo-1.64.0-i686-unknown-linux-gnu.tar.xz": "e2e20a16f5db52cd6b773c94225b03880743544ff2f317dd857cf0dceac6ab57",
- "dist/2022-09-22/cargo-1.64.0-mips-unknown-linux-gnu.tar.gz": "a935deca822265d1b341682324743c95213346a650eecdf7c8493eecd233ba72",
- "dist/2022-09-22/cargo-1.64.0-mips-unknown-linux-gnu.tar.xz": "3227f9957542bc2b8ef6605e24cd27a16ab76ae318d86d18f4e99ffcf17aaae4",
- "dist/2022-09-22/cargo-1.64.0-mips64-unknown-linux-gnuabi64.tar.gz": "4bdf7a09474588dd647e9007ca0fcce13bf8784f20e940442c0649c40b5402d0",
- "dist/2022-09-22/cargo-1.64.0-mips64-unknown-linux-gnuabi64.tar.xz": "4b4c950e95755b39ef64b720913482f3a61daceb4e8a57fe8812f92b4c2bc76f",
- "dist/2022-09-22/cargo-1.64.0-mips64el-unknown-linux-gnuabi64.tar.gz": "e49b9e758768533b47470765eb2b4cc3cdc378460677daeaff62638e711b957b",
- "dist/2022-09-22/cargo-1.64.0-mips64el-unknown-linux-gnuabi64.tar.xz": "252d0edd035601ed2fb633093780a9bbd957ed7abf276cc48e805e6cdedc76cd",
- "dist/2022-09-22/cargo-1.64.0-mipsel-unknown-linux-gnu.tar.gz": "26c870ab447656d4c5610c73af7bbd400dc06dad0fd90c7558206c4ab4783928",
- "dist/2022-09-22/cargo-1.64.0-mipsel-unknown-linux-gnu.tar.xz": "42ffc698db364e1d8a1b1c20e87ba0aadf2a0103f411a76fa277de84fe8139a5",
- "dist/2022-09-22/cargo-1.64.0-powerpc-unknown-linux-gnu.tar.gz": "112820998ab4b1a20a2bac39963ee50e49adf4d3eac22b0f8af4d7b55044ae9a",
- "dist/2022-09-22/cargo-1.64.0-powerpc-unknown-linux-gnu.tar.xz": "d2e075eba43c29fe493d7b9d5b951ead3f0a61fd8c7d7fa795547fd02827cb5b",
- "dist/2022-09-22/cargo-1.64.0-powerpc64-unknown-linux-gnu.tar.gz": "8a5f37a0a50cc516772af9c1b56a4f159c1b90b4ec64470313afa9ad7ffb1552",
- "dist/2022-09-22/cargo-1.64.0-powerpc64-unknown-linux-gnu.tar.xz": "82787ee0f4951227eff08ea0127d4454ea2a56fe1f06ecca6de7823bcb3be647",
- "dist/2022-09-22/cargo-1.64.0-powerpc64le-unknown-linux-gnu.tar.gz": "19df9e098ba8a2a6d6120a1340b40dfcaf4cbb5b0c1294d76665e75555bffdd4",
- "dist/2022-09-22/cargo-1.64.0-powerpc64le-unknown-linux-gnu.tar.xz": "ba7188b2c7890e61bf58d3aa9e94c323fec375f67cf03841bbcc0f6c800fe6ad",
- "dist/2022-09-22/cargo-1.64.0-riscv64gc-unknown-linux-gnu.tar.gz": "f5ebe9cf9237845051bfcb173101eb15c45b651d79b0d7982b11b3c7cd08832d",
- "dist/2022-09-22/cargo-1.64.0-riscv64gc-unknown-linux-gnu.tar.xz": "b94e262dec82b7cacf3baa77f35601c82d389ad338d118b42da4d23e26240760",
- "dist/2022-09-22/cargo-1.64.0-s390x-unknown-linux-gnu.tar.gz": "a5f14599f7ca4c641c27b9fa5bbdfbeb5f92eb8f66101b7474f04ff78df4950d",
- "dist/2022-09-22/cargo-1.64.0-s390x-unknown-linux-gnu.tar.xz": "7c01b6af89c18437778ef410cb98c948493bd6070c4b81e7f38f3c25ae1c6a52",
- "dist/2022-09-22/cargo-1.64.0-x86_64-apple-darwin.tar.gz": "e032116e22f6d3a4cb078f21031794e88f2a87f066625b8eb7623777e42d6eca",
- "dist/2022-09-22/cargo-1.64.0-x86_64-apple-darwin.tar.xz": "9dd507854410d20cd8b75b296e319bb5a62f9b1c2cb6c2b043c32de96eb5cc35",
- "dist/2022-09-22/cargo-1.64.0-x86_64-pc-windows-gnu.tar.gz": "dc029ae8045adc561ccab8a981be89c5eda83162ffcc0c43a1dd7d9c903b2e09",
- "dist/2022-09-22/cargo-1.64.0-x86_64-pc-windows-gnu.tar.xz": "287c49c9a9cfb51f9bb758ee3586cb3542aa1c0651f088cba4e6eb4ba8e87741",
- "dist/2022-09-22/cargo-1.64.0-x86_64-pc-windows-msvc.tar.gz": "b197c91ef9ddd98f1ae129e4f108d9d2b48350dc377300047cbb19c63a6fc641",
- "dist/2022-09-22/cargo-1.64.0-x86_64-pc-windows-msvc.tar.xz": "38d75dbba91dc1dbf35898c5845ee29d6f6ec69b44516220930b4c7e8719bd0a",
- "dist/2022-09-22/cargo-1.64.0-x86_64-unknown-freebsd.tar.gz": "36e86a67fa943d324ce7b977d967ae16ad012ac0aa0b7625db61a16c8f25c2d1",
- "dist/2022-09-22/cargo-1.64.0-x86_64-unknown-freebsd.tar.xz": "6a78d94aed814a9ff3bc650d0ff0ac7ee1eb1595819e672bc7e66d658149d808",
- "dist/2022-09-22/cargo-1.64.0-x86_64-unknown-illumos.tar.gz": "360ebcca8247099bffae548a1c09449c8dc4516918d4f18f7ba09ef650b7775c",
- "dist/2022-09-22/cargo-1.64.0-x86_64-unknown-illumos.tar.xz": "f7ac58bbf283c8c6fcb3648bb18601e0c7c30f6613177b400485f39dc4552044",
- "dist/2022-09-22/cargo-1.64.0-x86_64-unknown-linux-gnu.tar.gz": "12c2e61bf7de8b37c16d0323972a6085f9e01ee6d716549dd1ef4a92481b0610",
- "dist/2022-09-22/cargo-1.64.0-x86_64-unknown-linux-gnu.tar.xz": "21434d83a30ad3fa4e4831487c5574a20b07dd57d213b26e1246290c57d4ec41",
- "dist/2022-09-22/cargo-1.64.0-x86_64-unknown-linux-musl.tar.gz": "fffd3e692f39c28a0392d17ee2f5695f53141e34c0bf8bbb7cdc0ef9fd3ad791",
- "dist/2022-09-22/cargo-1.64.0-x86_64-unknown-linux-musl.tar.xz": "01d06176fd894b9299ed4f5b78e87d78a9a25b9ba803d3f8c50b7a4ea21d8807",
- "dist/2022-09-22/cargo-1.64.0-x86_64-unknown-netbsd.tar.gz": "cb2b26b0081cefdf87e977d7ba3b82687b15f79d875188c6028a3f25f5601a4f",
- "dist/2022-09-22/cargo-1.64.0-x86_64-unknown-netbsd.tar.xz": "302402ff74a8cf51d22808723d3ed3fee2b6cd765677023d2f380c34f2c6f719",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-apple-darwin.tar.gz": "808d3b83211e45cabdf59a19a72565e13d45bba79053ae8210d51eb05500e5fb",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-apple-darwin.tar.xz": "ed79f61b3d8b4ea3ffcb78fb9952cc3b199d646d057827bb3bfa5247489f21cd",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-apple-ios-sim.tar.gz": "24f8b2121f4d342eb9d21b926a34bd7960c34275ce9bee4e77c67969a2780ca9",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-apple-ios-sim.tar.xz": "2e1193d20d85265def6e4e525b32f197b7bec6047f22c43f0df15d8e4aae1ff0",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-apple-ios.tar.gz": "aa6513954fe168aa158fb5f6074037d252e4c8fd9bec5c4894dd68c8be4c8fdd",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-apple-ios.tar.xz": "6c1b63340ba2aa051eea47d09b1c79c817538144140672f6f11be8cefa241501",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-fuchsia.tar.gz": "5ffb190975f5936800e128d1a41ca8a9974acad2ce80d1b45620a259860e6ffe",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-fuchsia.tar.xz": "d69cb543c339c5830b3e65a4bf754b8540a5e57044be44fd34580b1dbe9da0ec",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-linux-android.tar.gz": "b56deb8930974159f1027f884b8a4756e392765189a27f6d80e95519d206b9d1",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-linux-android.tar.xz": "b6395b3bd2be7787672366482e134dbf64a9418aa5011b2090ed906cd3c0a060",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-pc-windows-msvc.tar.gz": "708e7a144c3f7895a80e87cd3f59083ba72d2f5670da550f5dfb843385214c95",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-pc-windows-msvc.tar.xz": "9fd1b3bad839f01c7b8c5075c34dfe8d0c1a9fd7139cd7aedf7144cabfc610e7",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-unknown-linux-gnu.tar.gz": "2b425658f84793d5bbf00ce545f410ec6454add202cce27a718d81e0233e7007",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-unknown-linux-gnu.tar.xz": "40abc9ec4f86ff0e37ba176e4c68dfa708e9857bb0372169c865367593127566",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-unknown-linux-musl.tar.gz": "fc74d1ddc8a12d7a58a40534b10297e249c972e39943a7cb514ac72032c5fcd8",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-unknown-linux-musl.tar.xz": "2438f7116711b2c65b60d59662ad333cc5f66868ec34498777ed764103f4d4a3",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-unknown-none-softfloat.tar.gz": "6697319c1011268dd73c9140655a04321d52b257dc381da374db68fb990cfc42",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-unknown-none-softfloat.tar.xz": "ea09ce9479411883444011727cdc9655748f4fe199d16a547a6464a68c45beb9",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-unknown-none.tar.gz": "a32b5b222fc43fd791d62c4c1bebb9a41d2783934e3f27f7bdb692342cca2502",
- "dist/2022-09-22/rust-std-1.64.0-aarch64-unknown-none.tar.xz": "241a7335982e67b510fe48d33acce068c2dda88c20b321d3fe87cb3625239f5f",
- "dist/2022-09-22/rust-std-1.64.0-arm-linux-androideabi.tar.gz": "4fa112179b4df1bbf5922c4e68e7c8fa87770ee1bec951e39761cc5f0e504e29",
- "dist/2022-09-22/rust-std-1.64.0-arm-linux-androideabi.tar.xz": "da0d33bee214073dff52914e2f9cfa4a6ecea6a1035ffae71c4338f5bcaa02e8",
- "dist/2022-09-22/rust-std-1.64.0-arm-unknown-linux-gnueabi.tar.gz": "f7ca0fc92aab9f1a8c44ec180c7e10018138ca7e9b507bec085d03d9fd3a73e9",
- "dist/2022-09-22/rust-std-1.64.0-arm-unknown-linux-gnueabi.tar.xz": "9e7dc879ce647d0b5c7423dcfea1438d64ea2e0764895b5cb9b3258ab0ecf8dd",
- "dist/2022-09-22/rust-std-1.64.0-arm-unknown-linux-gnueabihf.tar.gz": "30ea300372033c2886d61ac59a7532f8d0e4665f548c6e90d8fd25a57f89ee9f",
- "dist/2022-09-22/rust-std-1.64.0-arm-unknown-linux-gnueabihf.tar.xz": "07fbe4ef51f33e7954e25c433522da224b10c6f7353f612713669a4fc58704e8",
- "dist/2022-09-22/rust-std-1.64.0-arm-unknown-linux-musleabi.tar.gz": "0f6e4f77289cfa8eb415c037449f59ce359dbef9a161c78ba8474c8405fbd50b",
- "dist/2022-09-22/rust-std-1.64.0-arm-unknown-linux-musleabi.tar.xz": "f0d24e63e2687af229ea1472650bf5dd5a50d7706062b47a73413e28101fccf1",
- "dist/2022-09-22/rust-std-1.64.0-arm-unknown-linux-musleabihf.tar.gz": "21990412baeade16a29a7b82e2734460e3fae144abd4eee1bb31848ac94ad30b",
- "dist/2022-09-22/rust-std-1.64.0-arm-unknown-linux-musleabihf.tar.xz": "9955ac8be9828e0400c16a1c0388a769401dc8e732d099ffada156867cab08fb",
- "dist/2022-09-22/rust-std-1.64.0-armebv7r-none-eabi.tar.gz": "a6c849f95edf97d2fceabee5cf21963062ce2d840794acf28a427128430ca01f",
- "dist/2022-09-22/rust-std-1.64.0-armebv7r-none-eabi.tar.xz": "d8bee2d8337bb67ab604961a61e117d09d93b500dc8bea17c85f2f349bf18ad2",
- "dist/2022-09-22/rust-std-1.64.0-armebv7r-none-eabihf.tar.gz": "74296a66735011527c129e5885105398479b2dbdc98b2ff516c655681354ca86",
- "dist/2022-09-22/rust-std-1.64.0-armebv7r-none-eabihf.tar.xz": "39ef3482b47b6218cf811ef53662385b8c52ef91930acc60685a3e334126d02c",
- "dist/2022-09-22/rust-std-1.64.0-armv5te-unknown-linux-gnueabi.tar.gz": "7bcea2b201ebc61748760e5004d4451944191391129d3cd47cdbc909aeb0c3be",
- "dist/2022-09-22/rust-std-1.64.0-armv5te-unknown-linux-gnueabi.tar.xz": "af9b36ce5ad613112f83f085840e1f2c5f58ec7b72d8dbf9e833883105699a37",
- "dist/2022-09-22/rust-std-1.64.0-armv5te-unknown-linux-musleabi.tar.gz": "d38f38f2f31fb099c1360e5ef81fd3159b09ddf0bfd8b555cfb07acc08be5547",
- "dist/2022-09-22/rust-std-1.64.0-armv5te-unknown-linux-musleabi.tar.xz": "5246edd6be26f10d11a3100d3e74f460c2cfbdabb417e4cc8225ce2b82c485ce",
- "dist/2022-09-22/rust-std-1.64.0-armv7-linux-androideabi.tar.gz": "997cb016441d53f45e8bb9c7c7aca1926275c384505f33c1b713e695e3532ae4",
- "dist/2022-09-22/rust-std-1.64.0-armv7-linux-androideabi.tar.xz": "8bcb6ad1ef04154191be993135b604ce344bcc0645f235d87027c05abe9de8fb",
- "dist/2022-09-22/rust-std-1.64.0-armv7-unknown-linux-gnueabi.tar.gz": "89ef5effad1ed58610582b35db06670b01a7a491ac43856c8d6d179b37814e7e",
- "dist/2022-09-22/rust-std-1.64.0-armv7-unknown-linux-gnueabi.tar.xz": "eca7608caa6b8fb31467b4524292e86f854ebd06fcff29f58f5fc860b664c711",
- "dist/2022-09-22/rust-std-1.64.0-armv7-unknown-linux-gnueabihf.tar.gz": "9cda1ef1d14372d7c5288cc69c9b5e9f211f5bebf7da22fae6d6ca8fc06ed687",
- "dist/2022-09-22/rust-std-1.64.0-armv7-unknown-linux-gnueabihf.tar.xz": "ef1820f55b341ed1a78cadbd3564f9f8800f99bbfb7533821ef5f90ba2c21e87",
- "dist/2022-09-22/rust-std-1.64.0-armv7-unknown-linux-musleabi.tar.gz": "bbff558e98be89b530dc5f6aca35e5b9661fb221bd2a199b7de6cf971dc60ab4",
- "dist/2022-09-22/rust-std-1.64.0-armv7-unknown-linux-musleabi.tar.xz": "742fac589f1bc1a0ddd857e32b317e2b673c40adb8ef6dfc3516563ba9bc839f",
- "dist/2022-09-22/rust-std-1.64.0-armv7-unknown-linux-musleabihf.tar.gz": "bb233eb7c5dd2f8ae50c4874aea1a8b2e9965f92d184c4e6574f6db45f3c0562",
- "dist/2022-09-22/rust-std-1.64.0-armv7-unknown-linux-musleabihf.tar.xz": "a31b9284ca3e864343fdad900fc877cc14e00de32dcde7326023372720cd4b09",
- "dist/2022-09-22/rust-std-1.64.0-armv7a-none-eabi.tar.gz": "1074c419524eab1e6b73c54e62a30b50f0557025e30372316965218cba515858",
- "dist/2022-09-22/rust-std-1.64.0-armv7a-none-eabi.tar.xz": "3cc35863989cb5b1e236ae79600649ef5bc460233afb11d806dfb2c028c14e09",
- "dist/2022-09-22/rust-std-1.64.0-armv7r-none-eabi.tar.gz": "df7efe69bfdc3e284550ef75f4617a9d0b5f02157fe19ec3306e81d719959970",
- "dist/2022-09-22/rust-std-1.64.0-armv7r-none-eabi.tar.xz": "c8091d6ad014fc9608a51f942ebd0d67c2fbfa186133e4054cb162c6a03ab3f0",
- "dist/2022-09-22/rust-std-1.64.0-armv7r-none-eabihf.tar.gz": "258d0df03c1ad69a194510c3bfc22dbdeeedbfc881d16e83dd86cbee60d4c952",
- "dist/2022-09-22/rust-std-1.64.0-armv7r-none-eabihf.tar.xz": "52ddc8560c87303b887eb852a7b742c59cee240500bbdbf3069eb7258f9a9e35",
- "dist/2022-09-22/rust-std-1.64.0-asmjs-unknown-emscripten.tar.gz": "71c28ab0421fcc9d045a19eb67778c9c4b9d64a37e076fe94621c1d84bbdb97b",
- "dist/2022-09-22/rust-std-1.64.0-asmjs-unknown-emscripten.tar.xz": "6443813cc696cba8155c1cbfe8eb46ef1846c4609f6887e8d883b0a3a045167d",
- "dist/2022-09-22/rust-std-1.64.0-i586-pc-windows-msvc.tar.gz": "c5ae8faf7a3c8f94a962f460c44b7fb155f0ccc9b98447c21ed63798276cb25c",
- "dist/2022-09-22/rust-std-1.64.0-i586-pc-windows-msvc.tar.xz": "ce02bcf63aad651ddaa05a5034704d2e8c8cf064bca94acff5ce96c0fcda07b9",
- "dist/2022-09-22/rust-std-1.64.0-i586-unknown-linux-gnu.tar.gz": "82779e550c600d664063c935a5fb52fa1c5e3ba840fe1bf01a48ee9757f6b640",
- "dist/2022-09-22/rust-std-1.64.0-i586-unknown-linux-gnu.tar.xz": "791aafcfb41c342783bc3c8cdb57ac61453fc02eee185f15c275716f419556f3",
- "dist/2022-09-22/rust-std-1.64.0-i586-unknown-linux-musl.tar.gz": "a649905b57cff932ae3d8955c410398c225ff2cd9d80da8076eb19d5338cb1e7",
- "dist/2022-09-22/rust-std-1.64.0-i586-unknown-linux-musl.tar.xz": "0cb3b0848cd31bd68ac82cd138c6345e5348f5af3dcc1f13275ee019a0895c59",
- "dist/2022-09-22/rust-std-1.64.0-i686-linux-android.tar.gz": "445755849a1469147316bc496a02ae198f293d537b3a95040d9c3892cf41d37b",
- "dist/2022-09-22/rust-std-1.64.0-i686-linux-android.tar.xz": "b7185e6b963235734acb092d0cef6cc77d5799e659fcd1e1543fea62351ef51e",
- "dist/2022-09-22/rust-std-1.64.0-i686-pc-windows-gnu.tar.gz": "08648a4175ed8f211f9ac7beedb171b9074d041e10b89db45cd45d42af88d854",
- "dist/2022-09-22/rust-std-1.64.0-i686-pc-windows-gnu.tar.xz": "a05610fccaacbcbdc7c872280f73ae0999666058cfba409dffcab3f2cc64d6f6",
- "dist/2022-09-22/rust-std-1.64.0-i686-pc-windows-msvc.tar.gz": "e0871d7e01d404498bb457c2f96143b844f2cf886a546c505a8bff640940e785",
- "dist/2022-09-22/rust-std-1.64.0-i686-pc-windows-msvc.tar.xz": "a18e2b009dac092f6410a4e66d5c22e81e525c7f9cb91296553ed8832fe35d33",
- "dist/2022-09-22/rust-std-1.64.0-i686-unknown-freebsd.tar.gz": "575ce3a32df08254e0c2ada462c950647a85861c0e1ec18d1b83b17c82d9717b",
- "dist/2022-09-22/rust-std-1.64.0-i686-unknown-freebsd.tar.xz": "d0ae58443104554e4636ffccde22a09d7ec360749f6638cc06d1cd22eaaa2f4d",
- "dist/2022-09-22/rust-std-1.64.0-i686-unknown-linux-gnu.tar.gz": "50b32b772e2eb993dea89011fd800c291889c05ce615e45d9a260ee568661069",
- "dist/2022-09-22/rust-std-1.64.0-i686-unknown-linux-gnu.tar.xz": "c80c57df63517d6171c061e6c095b794593172a3abefa9b4202992706bda12e5",
- "dist/2022-09-22/rust-std-1.64.0-i686-unknown-linux-musl.tar.gz": "2898a1b2a3c28201d2da4e470bc64c261e6eb61531fbdeeb963b3dbef4d958ec",
- "dist/2022-09-22/rust-std-1.64.0-i686-unknown-linux-musl.tar.xz": "b193faf2e37951bf1ac6c3f2d4bd4fe84971a2f56f22e66323cccd142df54156",
- "dist/2022-09-22/rust-std-1.64.0-mips-unknown-linux-gnu.tar.gz": "1649e72798f14336c25019cf0d5e800016f9087e9e703749c456e1293178f01d",
- "dist/2022-09-22/rust-std-1.64.0-mips-unknown-linux-gnu.tar.xz": "45baef38fbfadf21d4e603554c49d62525d1dff887e4ea7045b1fc88feb81663",
- "dist/2022-09-22/rust-std-1.64.0-mips-unknown-linux-musl.tar.gz": "bc18714aa6ab30d3b53cb166a3126fd3a1876b4c53aeba1741b9227400e49968",
- "dist/2022-09-22/rust-std-1.64.0-mips-unknown-linux-musl.tar.xz": "993b3e003feaa966466509ea9161106978ef7c874877461b4ca1a9936032b25b",
- "dist/2022-09-22/rust-std-1.64.0-mips64-unknown-linux-gnuabi64.tar.gz": "8d876d6b783697d306240414cfea4c1ebca8f97b77a70f32aba5cea41f205756",
- "dist/2022-09-22/rust-std-1.64.0-mips64-unknown-linux-gnuabi64.tar.xz": "a2d2e2d274105054303adfd9ecb75ea2fba36a228ab23a669c609062f4db0035",
- "dist/2022-09-22/rust-std-1.64.0-mips64-unknown-linux-muslabi64.tar.gz": "a51ecd555b7374eba850b47ddc83c0a6a288a547ce14c90629c0077c0297c023",
- "dist/2022-09-22/rust-std-1.64.0-mips64-unknown-linux-muslabi64.tar.xz": "83981de8b57719d714d59b55f3749d8c6ff10588d8d6c7d7ae371bfb668a7b5b",
- "dist/2022-09-22/rust-std-1.64.0-mips64el-unknown-linux-gnuabi64.tar.gz": "2f7632305068706e09c02421856bc8bba5bf28c197dea418a7d076d1d6f35cb9",
- "dist/2022-09-22/rust-std-1.64.0-mips64el-unknown-linux-gnuabi64.tar.xz": "8ec026244400bac48d918230a0c99aa2c31ff33d6cc4d18552228509ca58c074",
- "dist/2022-09-22/rust-std-1.64.0-mips64el-unknown-linux-muslabi64.tar.gz": "d707d6e9e58921ea6c2a57882fc32dc5e2a74003ca0a30c9460e5d88c8b07e5f",
- "dist/2022-09-22/rust-std-1.64.0-mips64el-unknown-linux-muslabi64.tar.xz": "97f40ad383014955448f7917abba7a547d1ddd205746641d3e9c3f730cbd129e",
- "dist/2022-09-22/rust-std-1.64.0-mipsel-unknown-linux-gnu.tar.gz": "6f0e5498ab6505e3f4312249fc369eded48b9d4f33f910eee438936ad5d25758",
- "dist/2022-09-22/rust-std-1.64.0-mipsel-unknown-linux-gnu.tar.xz": "7dbcf969fc6717215796079437cf073a8ef7df95b77ded4654009c8379c91e0a",
- "dist/2022-09-22/rust-std-1.64.0-mipsel-unknown-linux-musl.tar.gz": "eabb79f49167d03e1c5ee4f047316d84db5d50e3224aa6168765a5f5db0afe93",
- "dist/2022-09-22/rust-std-1.64.0-mipsel-unknown-linux-musl.tar.xz": "288dd07746b0ece185753e784c7e97f2f01984e9302ef46a4ff71db665002637",
- "dist/2022-09-22/rust-std-1.64.0-nvptx64-nvidia-cuda.tar.gz": "32d865ba8c5b3a61ae0393fa021ebd15d14a515723879a3c494b7b7320f325ff",
- "dist/2022-09-22/rust-std-1.64.0-nvptx64-nvidia-cuda.tar.xz": "fbf12642d1df994db8e2e25d50f3c1a567b6b9379c53c1151afe2e3c6871022c",
- "dist/2022-09-22/rust-std-1.64.0-powerpc-unknown-linux-gnu.tar.gz": "61d228cb732ddb85802465781b69ed20719314adde5863805cdcac9c3cc1336f",
- "dist/2022-09-22/rust-std-1.64.0-powerpc-unknown-linux-gnu.tar.xz": "6b29ebec4cd705760db634717cf6df68a9a377d52c25def30f5a2e2641a83279",
- "dist/2022-09-22/rust-std-1.64.0-powerpc64-unknown-linux-gnu.tar.gz": "4a96801730f61b8b116553ec7c3572b56b03836b59220b3f2b2736e8428a92e3",
- "dist/2022-09-22/rust-std-1.64.0-powerpc64-unknown-linux-gnu.tar.xz": "dc0352fdcf7f8b4fcb551d63001738ee120ea2a0fcc7d55db11f1f87eba90b3e",
- "dist/2022-09-22/rust-std-1.64.0-powerpc64le-unknown-linux-gnu.tar.gz": "362dc9a7bc63d222598878d8d36dbd9008a1bb05cf389a90eeac28a76f55cdae",
- "dist/2022-09-22/rust-std-1.64.0-powerpc64le-unknown-linux-gnu.tar.xz": "ef697469b2a3ea8897f49b70e3be0c7aaca3f26fd3234812113e2e85cafac738",
- "dist/2022-09-22/rust-std-1.64.0-riscv32i-unknown-none-elf.tar.gz": "a6e4f4e61a84a7dce3554f6daea4854e9897f6affd7d0a4de279912a06f30a99",
- "dist/2022-09-22/rust-std-1.64.0-riscv32i-unknown-none-elf.tar.xz": "6966de249e5b0ac3bf10489baad41a55f29f777dd6d44f76e2ae950ba40cbb41",
- "dist/2022-09-22/rust-std-1.64.0-riscv32imac-unknown-none-elf.tar.gz": "111900d8e3325bb770b18a43cefb101c47ca9c4aece41c494ead994cfc14c007",
- "dist/2022-09-22/rust-std-1.64.0-riscv32imac-unknown-none-elf.tar.xz": "5ba51e00b3352b9e207e0f66c890962b7c2111bda9b9f2d786c3e3f10a9c3011",
- "dist/2022-09-22/rust-std-1.64.0-riscv32imc-unknown-none-elf.tar.gz": "164efc3ec05976883ffba2d52a62243a1c67582d359e301e4a1f6bd83141a747",
- "dist/2022-09-22/rust-std-1.64.0-riscv32imc-unknown-none-elf.tar.xz": "527bd3c4ec7f68c246046463f56c7071862079c5857e465d2b365de92d4bd81b",
- "dist/2022-09-22/rust-std-1.64.0-riscv64gc-unknown-linux-gnu.tar.gz": "5b8e8e67ae67ac74699b976043615f029f487c4148fdca4cb33fe7fe90192860",
- "dist/2022-09-22/rust-std-1.64.0-riscv64gc-unknown-linux-gnu.tar.xz": "284b09a96d4cdbb96827914a318f9c41e2b207c0afeae76b9f0e3830d2ef2d4d",
- "dist/2022-09-22/rust-std-1.64.0-riscv64gc-unknown-none-elf.tar.gz": "bd04973eb7e8061a55fe27c3fd14a29e1cac143714d323ef4c4c480c4df1df76",
- "dist/2022-09-22/rust-std-1.64.0-riscv64gc-unknown-none-elf.tar.xz": "eac6ca401809e0b94ace04ae255525bf972ad5cdc1f8775d401e166c4b688a0d",
- "dist/2022-09-22/rust-std-1.64.0-riscv64imac-unknown-none-elf.tar.gz": "55bfb141b8ae992e3ac1066b264f7a8609d10e2223079ecf503928fd1d138272",
- "dist/2022-09-22/rust-std-1.64.0-riscv64imac-unknown-none-elf.tar.xz": "74af2d8a944a1d57f27c002710ef9ba8e6f434d524ae27ba482f8ce7b5474f0c",
- "dist/2022-09-22/rust-std-1.64.0-s390x-unknown-linux-gnu.tar.gz": "b8c75287bd02dab135199fb760ed8adefa0bea44fd678421dd383582d3af8c28",
- "dist/2022-09-22/rust-std-1.64.0-s390x-unknown-linux-gnu.tar.xz": "939db2384f543325cc8a2423ab53e28623b9e9762dacea1e2010cf894d3e6ab1",
- "dist/2022-09-22/rust-std-1.64.0-sparc64-unknown-linux-gnu.tar.gz": "49d65f9a5bb57325fc3075ed37687e89ace44e2d2d5f1eed97ec3a4a4de1aae5",
- "dist/2022-09-22/rust-std-1.64.0-sparc64-unknown-linux-gnu.tar.xz": "3551f014fe1839e68e7b06eeb1b3f67869bef9c4849da9c9c01a7b8c3e32ebf2",
- "dist/2022-09-22/rust-std-1.64.0-sparcv9-sun-solaris.tar.gz": "4fe9b47445348a7251d0b09708f3c29fd424714e9d50a1a3f6ace492e2149b49",
- "dist/2022-09-22/rust-std-1.64.0-sparcv9-sun-solaris.tar.xz": "d5782d4352ed363011ff896fe89a6ef576e9206e0abb30255fb84cd1707b40aa",
- "dist/2022-09-22/rust-std-1.64.0-thumbv6m-none-eabi.tar.gz": "d73733335ae6554f42471bfc86c27c1e461401f0c3604514bbaa50f59b3e071f",
- "dist/2022-09-22/rust-std-1.64.0-thumbv6m-none-eabi.tar.xz": "419dc37e5fad24e5ff41e21b207bda1ef0c5aa94291fea4620c27f8be6d5f3bc",
- "dist/2022-09-22/rust-std-1.64.0-thumbv7em-none-eabi.tar.gz": "90657346d888b1be2f3d7a6491603daaff804016cd45391945456dc0e3c39448",
- "dist/2022-09-22/rust-std-1.64.0-thumbv7em-none-eabi.tar.xz": "b9e77f24e5f37a0789a1e9d84813cee643f4677ff1272e4c01699d74cd42c8dd",
- "dist/2022-09-22/rust-std-1.64.0-thumbv7em-none-eabihf.tar.gz": "53a0dbe3446ec6d5fd20f595c96519c068939e0acea209f958b457c4c0ce7dbf",
- "dist/2022-09-22/rust-std-1.64.0-thumbv7em-none-eabihf.tar.xz": "e5b653284e38c75b1799a9dc21a174e313d65bd19b88f6022f2009be6e404cc7",
- "dist/2022-09-22/rust-std-1.64.0-thumbv7m-none-eabi.tar.gz": "3e27b5f8cfc2be73edc963529a92a077bc47d6a08518ab279a5de1cd02e6ccb5",
- "dist/2022-09-22/rust-std-1.64.0-thumbv7m-none-eabi.tar.xz": "078100e6d739a786be141f387780f42d0d7a248803c66e51341d3ec8cf8ef269",
- "dist/2022-09-22/rust-std-1.64.0-thumbv7neon-linux-androideabi.tar.gz": "8c677b7e69a9e0c2c67c8fb9d12075c573ef9a7f1f4c00d6f326f4ca9bc33b17",
- "dist/2022-09-22/rust-std-1.64.0-thumbv7neon-linux-androideabi.tar.xz": "49ad860fd9dd866f3b1a698c5b05a1b7a61bc6fcd75cbba1d61aec13c797d0c4",
- "dist/2022-09-22/rust-std-1.64.0-thumbv7neon-unknown-linux-gnueabihf.tar.gz": "320efa58b6066e0b640b9b93330f89f27a14cce490d8a5eafe33f1d3949de5f1",
- "dist/2022-09-22/rust-std-1.64.0-thumbv7neon-unknown-linux-gnueabihf.tar.xz": "31397ee504b3d30854d70915d445d8d04361480b3297ce19069056d6009055b8",
- "dist/2022-09-22/rust-std-1.64.0-thumbv8m.base-none-eabi.tar.gz": "d22c9248d92c1b09f7069ee02e85a6441a3751943d928b791e812890fbf9b2f2",
- "dist/2022-09-22/rust-std-1.64.0-thumbv8m.base-none-eabi.tar.xz": "6a9b3358c082cb2a4fbbe7e784a3e49e80fdd126fd773aa95d510c444bd5cf7f",
- "dist/2022-09-22/rust-std-1.64.0-thumbv8m.main-none-eabi.tar.gz": "3e94e4e529d5e1df27c23273fda38c6ad8e3d14e67278ece262cb7b74eeeab7d",
- "dist/2022-09-22/rust-std-1.64.0-thumbv8m.main-none-eabi.tar.xz": "c57e0033ed685123d1a751f6b22569ad004ff2cb4c67c90c87aad7ba4b236851",
- "dist/2022-09-22/rust-std-1.64.0-thumbv8m.main-none-eabihf.tar.gz": "09330542b62b03c82e56d5404bb79e9e88af9a693faeeb5bcdad1735df6c8ddf",
- "dist/2022-09-22/rust-std-1.64.0-thumbv8m.main-none-eabihf.tar.xz": "3834fc11d573847a74558124768c22e9c3d879be04f196d273bdf678513926b4",
- "dist/2022-09-22/rust-std-1.64.0-wasm32-unknown-emscripten.tar.gz": "547457d0adef92008116afd1635b8abfd10fa7fd8d969223443dc905086a9e4b",
- "dist/2022-09-22/rust-std-1.64.0-wasm32-unknown-emscripten.tar.xz": "d46d12e7b145c292f36eb1cbe87fdcdad03785431d1b1775b804efba6c0dfd2e",
- "dist/2022-09-22/rust-std-1.64.0-wasm32-unknown-unknown.tar.gz": "1ecd99d7c8d568156957fcccb2d064eb8e1be3c309e216ce74c65ea549994d73",
- "dist/2022-09-22/rust-std-1.64.0-wasm32-unknown-unknown.tar.xz": "0be660957c1367d554f9d3649538a26ebffdf2d24d5dc48630c4e4372df6809e",
- "dist/2022-09-22/rust-std-1.64.0-wasm32-wasi.tar.gz": "d9bd33196e84f70dd67f60181aeee94a081406cac401c4ee613c16f82b99d963",
- "dist/2022-09-22/rust-std-1.64.0-wasm32-wasi.tar.xz": "388219deb87b5f6f673cc29fbadac4679c3c8d368147abba3c91e5491b09ca86",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-apple-darwin.tar.gz": "eb2f7c51f63973765f01efe509ccd2f26345d4bf0d77695adb4198a0899ae648",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-apple-darwin.tar.xz": "db5909b4b7544b2e1a5651c2d33be8a378e89ffee6b00d247c7cd2c5d115d83b",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-apple-ios.tar.gz": "7091a4133c652cc118e0b46116cbaf649777e79d1c91ae99151b6d390cfee45b",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-apple-ios.tar.xz": "1093cec3252ce6a9b742b961bf4490b2474dbf1d9614834381631c6bd016ba28",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-fortanix-unknown-sgx.tar.gz": "ae65fbd896e8d6ede58d72c86c6070570a63f6505fa1c6a5aed803419a53d1b0",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-fortanix-unknown-sgx.tar.xz": "ad10d74a47ec79b3300be10da2bb5bd3ba4b83f24be7c52e15f8d914578a1515",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-fuchsia.tar.gz": "4666bcd6009b9f1575ae9fed9bc7b0d9f00822fcd5c2dd9e55b6eed4222481c1",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-fuchsia.tar.xz": "c174539e3fee336168d88349d5fd0b77225bbc00f795a34de83cff7cbfcf40b8",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-linux-android.tar.gz": "9ea4213afa6c9b850116c18f2c461e105a5f907a96a057d3646040bfd22df180",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-linux-android.tar.xz": "80560adee5b2fefcde2a4179764d4e01972c2469da0f8b899bede69dfe649bf6",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-pc-solaris.tar.gz": "711364829736f94401b05f5e2bd85ff48234c01fa17fa92fc593e937436c7934",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-pc-solaris.tar.xz": "a4f68e996b83fb29fea28fcd4b0480c6df482408439f6b134dd87f47f2c03412",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-pc-windows-gnu.tar.gz": "dcf87f97432adf7228e907b551d9b73f1ab16f79dc5da0724a227b7ffdaf57b4",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-pc-windows-gnu.tar.xz": "af605be7aca0d4425863776331b0cf428c2f7fdbce899faea4cf2f09c12750ad",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-pc-windows-msvc.tar.gz": "a374306ef4ac906a777e0631a5749d44360ff7cbe91a0df45c67a74ab2c0b7ba",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-pc-windows-msvc.tar.xz": "a075b165891b8f707da80f7ca316bd328abcba95727ca91ee504e9131a335224",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-sun-solaris.tar.gz": "904860bea5b3d578bbecf71000f7ae8c6034a959a0e6aba92aa29b4555741e6b",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-sun-solaris.tar.xz": "8004c8b1cf3aa1874ff6a163f15a4cdae3dd3eea35ef0182468285af342248d2",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-freebsd.tar.gz": "c91edba781ba56f35f2dba56a268d41866ea9bb5f6ffb9d342635f66b836898b",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-freebsd.tar.xz": "70878bf98440f616b14b325235c8e4434b65524532da335dc44474b19b6ebf80",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-illumos.tar.gz": "7dafef8daa72c7ed37208fa017d6b574e5c453cf6a291184ca94806a71705523",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-illumos.tar.xz": "3e7103ff4ab8263f6890b6726f33f08898541fa4ef7fa9c69d8afa39bde53181",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-linux-gnu.tar.gz": "4d4c2715f816bc8ae82c2a5904106fd4dfd668dbd9a98492c8cd388bff9b0b5c",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-linux-gnu.tar.xz": "6ace34bcbba9557aa2fc3a0515c3da4a83ca24d7d45506c5e1b32f589fa38a8b",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-linux-gnux32.tar.gz": "99a0f82b626aee1ff0c2d0425a78398e2fe1ee448a63e45437bd0d0b6c5f21d8",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-linux-gnux32.tar.xz": "14155beea7c65833fa4bc2a6baac52ae8f83c51dce7edf4797658c617d4865cc",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-linux-musl.tar.gz": "243770414216f5c1891778a7bf0b865d28da1d49bfafdbfb45091aa1dfead9bc",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-linux-musl.tar.xz": "29af13a882abbe797fadd43afcb75bce2e2304438db9e21a3e64a2e9100501fb",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-netbsd.tar.gz": "e5b69cbdf7137e53d332ddbd0f6b6d22dc52163d4f50e81318ea01f82c67e5d8",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-netbsd.tar.xz": "bd4fdf598005d11f20db8fbd773f1c7124ba51ab373b35903e4a6750661dbd0c",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-none.tar.gz": "86e479e7ce264f3099dbf89eaabfef85ea7152f492cf14c23b90c05559014de3",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-none.tar.xz": "f48ab8a410a9142cdb9929c80475df6fde5d0c11b976785307e9a1e8b2044e56",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-redox.tar.gz": "65c5abdcad56554294ad7a4bec4124fc65e633ab76e50323c1079aaf33c62a56",
- "dist/2022-09-22/rust-std-1.64.0-x86_64-unknown-redox.tar.xz": "d8ae246352669df7aec4b43d2bb11fe095da4596533425424827c98a7d93fd4e",
- "dist/2022-09-22/rustc-1.64.0-aarch64-apple-darwin.tar.gz": "cc68733a81b1bac45bfcccb38412bcfb5c8d0abc3aa246fa9bebff7cf2be4826",
- "dist/2022-09-22/rustc-1.64.0-aarch64-apple-darwin.tar.xz": "6a040850c3c11d6a9aa3bf3544929009c9d1cfc3c7bf82799bed58c481b7745b",
- "dist/2022-09-22/rustc-1.64.0-aarch64-pc-windows-msvc.tar.gz": "152871f56d2c3dba43b069bbd0ddc9b1817965375144fea1d16242553f83cc1b",
- "dist/2022-09-22/rustc-1.64.0-aarch64-pc-windows-msvc.tar.xz": "121074f8bc41a58b0ec7e9e25dc8445f8c10f035cc320da9e97b2a521368cb7e",
- "dist/2022-09-22/rustc-1.64.0-aarch64-unknown-linux-gnu.tar.gz": "2347730846c1608619c100d41b8d292da002c050575eb8ab7885d478531baeaa",
- "dist/2022-09-22/rustc-1.64.0-aarch64-unknown-linux-gnu.tar.xz": "8f10b379bcc8caaab983b7d04a3f105dae42f95718f231b46d7e68685d239191",
- "dist/2022-09-22/rustc-1.64.0-aarch64-unknown-linux-musl.tar.gz": "af05a237f766d8d6828533ee169e19ed9886afa966c1a83546be6fa7e820310e",
- "dist/2022-09-22/rustc-1.64.0-aarch64-unknown-linux-musl.tar.xz": "880784ec231629e5244f3a9b80e49c60fdef9e360f519bcb9e2b1bf0ccfd24b5",
- "dist/2022-09-22/rustc-1.64.0-arm-unknown-linux-gnueabi.tar.gz": "9674c7794817e764e1bf55cfcfd5991f0c285a609137b960a24b75cce3fd7a9b",
- "dist/2022-09-22/rustc-1.64.0-arm-unknown-linux-gnueabi.tar.xz": "cf060d16c7aeb4e1c9515488f3a3514821439c044176c2c38987540351ceea36",
- "dist/2022-09-22/rustc-1.64.0-arm-unknown-linux-gnueabihf.tar.gz": "c0184fd0c9657b091809fa9de0ce6eaa923891f9cb7f39af7cb3606d0eb1fb90",
- "dist/2022-09-22/rustc-1.64.0-arm-unknown-linux-gnueabihf.tar.xz": "03475c9ee448e3e14bd3e7e75bcc61d2fed4c4a21f02d80c5574b9c2a859cc0f",
- "dist/2022-09-22/rustc-1.64.0-armv7-unknown-linux-gnueabihf.tar.gz": "81fdf1207dc5abb420d1e6c0f95f68ec717b183ee5c8dc25860f8e4432be7723",
- "dist/2022-09-22/rustc-1.64.0-armv7-unknown-linux-gnueabihf.tar.xz": "455ce33dd2894c451d921b5a1ca259732ab0b2e03a3bbc88a25b4d8d0f0833b0",
- "dist/2022-09-22/rustc-1.64.0-i686-pc-windows-gnu.tar.gz": "c5333399aeb53dfcfd57ec79c245c2f0d4bd1ba3813fcdcfb9d4eb97857927d9",
- "dist/2022-09-22/rustc-1.64.0-i686-pc-windows-gnu.tar.xz": "8c27aca6ebd973e41e0c402ed040be9e1bcd24c2127f6b1968fa6c40796b3ca3",
- "dist/2022-09-22/rustc-1.64.0-i686-pc-windows-msvc.tar.gz": "2b02f2e6bf7650890ddcd88e7cd15a6cc0a494b8653fcd788cda2127139e1224",
- "dist/2022-09-22/rustc-1.64.0-i686-pc-windows-msvc.tar.xz": "9a6257350a25c3d5d18d9f9ae937cb5ed7f46f070e698546ab11f5d9e8d85d96",
- "dist/2022-09-22/rustc-1.64.0-i686-unknown-linux-gnu.tar.gz": "bd805a90ec93aa1fd3f7b1d1f9339ac336c1350a31cb39f0506ba4da793bd3ef",
- "dist/2022-09-22/rustc-1.64.0-i686-unknown-linux-gnu.tar.xz": "3d604e150c469461a64c17b6d26f96a5a3d6975246c92cd13ee9bc6e4df0aaeb",
- "dist/2022-09-22/rustc-1.64.0-mips-unknown-linux-gnu.tar.gz": "ae5608caed9915aaa693b541106eb5e7f730deaad82694f7b699b41cee52f0f1",
- "dist/2022-09-22/rustc-1.64.0-mips-unknown-linux-gnu.tar.xz": "cb857587dfbbee9d2605093835a9dd261e021b37a87c42a6382224175c0493d1",
- "dist/2022-09-22/rustc-1.64.0-mips64-unknown-linux-gnuabi64.tar.gz": "8210e115343aac16e73cb938e8b2b0ed5131937db966b6fb600c0674a9c648f9",
- "dist/2022-09-22/rustc-1.64.0-mips64-unknown-linux-gnuabi64.tar.xz": "6d489dedcc82f201b356ed2ae8db91614eca8344791efe38b5d07b434a32bfc1",
- "dist/2022-09-22/rustc-1.64.0-mips64el-unknown-linux-gnuabi64.tar.gz": "5c108a9bfd8ac42d7cc7eadc76dc0a3c2b07c625c0603a0eb8d82b55d6957915",
- "dist/2022-09-22/rustc-1.64.0-mips64el-unknown-linux-gnuabi64.tar.xz": "9a2249057665460324a8c0dd9c269d783ecee69e2f513412be6cf9fad5d8f14a",
- "dist/2022-09-22/rustc-1.64.0-mipsel-unknown-linux-gnu.tar.gz": "6c338844bbda27edee4284fb7acf4b48b7d5ada3f2f5b0236af8a90a704bf17e",
- "dist/2022-09-22/rustc-1.64.0-mipsel-unknown-linux-gnu.tar.xz": "aeb1e24596ac507f1facf2d91cf8abdbd8a9e27da79820e5258be1024c5d8514",
- "dist/2022-09-22/rustc-1.64.0-powerpc-unknown-linux-gnu.tar.gz": "8c43c6868fe824b35d01357da91c111545f5143810d3ef5cd1e7e9d20ba2214f",
- "dist/2022-09-22/rustc-1.64.0-powerpc-unknown-linux-gnu.tar.xz": "5f4de96bff2937fc0a64a216604c7af765af94460a1f283330eddc610d91271b",
- "dist/2022-09-22/rustc-1.64.0-powerpc64-unknown-linux-gnu.tar.gz": "cb494af7e7cbbd8032f4f59cc0dbba1bb355adb3e5280a45a3b03e72451ed11e",
- "dist/2022-09-22/rustc-1.64.0-powerpc64-unknown-linux-gnu.tar.xz": "f58b7797371087800e4cb89807e7f346cc6eea9ab82a85e6f1088ad8369b01f2",
- "dist/2022-09-22/rustc-1.64.0-powerpc64le-unknown-linux-gnu.tar.gz": "f22636dcac8b16ad357da3a3f36382b277cb3fafbee9b34d7aecd9db3db40d9c",
- "dist/2022-09-22/rustc-1.64.0-powerpc64le-unknown-linux-gnu.tar.xz": "11630fc51fffe722e52f649357b5948c24b5305cfb61a8114527234e054451c4",
- "dist/2022-09-22/rustc-1.64.0-riscv64gc-unknown-linux-gnu.tar.gz": "3a59336edcb5e33a3532168cc672f140ea43277229c84955dd5ba7a856006c3f",
- "dist/2022-09-22/rustc-1.64.0-riscv64gc-unknown-linux-gnu.tar.xz": "5f3e69a185c7246773948ac97c053cf135d81ffdbf926d10a3339de93424f26b",
- "dist/2022-09-22/rustc-1.64.0-s390x-unknown-linux-gnu.tar.gz": "0555443cc4b7a69896171f2d886a8a2ab1ce91cff0763f7aafbc9567b0929815",
- "dist/2022-09-22/rustc-1.64.0-s390x-unknown-linux-gnu.tar.xz": "ac3facab7a17d7e7105178275b3186276e58a5202d91f451aa06cca2d0322bca",
- "dist/2022-09-22/rustc-1.64.0-x86_64-apple-darwin.tar.gz": "1201a655352c1a3ec6cd754e458d12eb0d69afdd1608b2813998d7bda1bb9dff",
- "dist/2022-09-22/rustc-1.64.0-x86_64-apple-darwin.tar.xz": "ea2e44d239492c1426b93c6b071d309a11f100bd0c76f92169883c8f27a567ca",
- "dist/2022-09-22/rustc-1.64.0-x86_64-pc-windows-gnu.tar.gz": "7dd40101913c9fdd707d92dae6ad709d90367aa4bc5e43bfc593fd5447666c01",
- "dist/2022-09-22/rustc-1.64.0-x86_64-pc-windows-gnu.tar.xz": "d38c3404648c1840861da51eb915d42c4c6ab7d12b456e9990dc7dec6521810f",
- "dist/2022-09-22/rustc-1.64.0-x86_64-pc-windows-msvc.tar.gz": "eb69517a2e0e5d93bdd27e24a8cf9a5fd0af8ed7bce0409bb19df8a007509a7d",
- "dist/2022-09-22/rustc-1.64.0-x86_64-pc-windows-msvc.tar.xz": "6a86e668a6111dfa72bff4e06d51b1264b92c9ac20ce7d64dc878f7e03a3fa5b",
- "dist/2022-09-22/rustc-1.64.0-x86_64-unknown-freebsd.tar.gz": "a6293ae73f2cf18f07c550a972135cef89979b9f6972e322596898058df6828a",
- "dist/2022-09-22/rustc-1.64.0-x86_64-unknown-freebsd.tar.xz": "2bfff1f69355252de14f6288bd78922f6d3bf93c4540708d22b6aeb9d7262fe4",
- "dist/2022-09-22/rustc-1.64.0-x86_64-unknown-illumos.tar.gz": "4b714e075756d29f6d1c57ce55a13d2d2788709fb4c55efa66f1a168ca94a1e1",
- "dist/2022-09-22/rustc-1.64.0-x86_64-unknown-illumos.tar.xz": "57f1be16d52a1843aceb8df7a882bdaae96606dc06c3af5e463b5c5c9ea11f84",
- "dist/2022-09-22/rustc-1.64.0-x86_64-unknown-linux-gnu.tar.gz": "5923a063408f2db09a0035da4ec699ee1ee35eb62c09c473c882ad77c42da0d0",
- "dist/2022-09-22/rustc-1.64.0-x86_64-unknown-linux-gnu.tar.xz": "1f5756a03119853b53358018c5b1592940a2354c3c9f84ee7faf684e3478f8f0",
- "dist/2022-09-22/rustc-1.64.0-x86_64-unknown-linux-musl.tar.gz": "e7570860b932a6950631ca5a0c4658787a3c56bbab701ba5a4162a7a23a37fff",
- "dist/2022-09-22/rustc-1.64.0-x86_64-unknown-linux-musl.tar.xz": "5177d749b5dcc74596e314b73c5f3f3eabed8b3e207f812f229fbf0682c162ae",
- "dist/2022-09-22/rustc-1.64.0-x86_64-unknown-netbsd.tar.gz": "29689b4eff49d494ef56850cd22130dbd098928829c72a0b5423a02aada846a4",
- "dist/2022-09-22/rustc-1.64.0-x86_64-unknown-netbsd.tar.xz": "0b6b9e0580078b30a9795b9b116197e7cd2e873c20107dffdb4f775cd4155264"
+ "dist/2022-11-03/cargo-1.65.0-aarch64-apple-darwin.tar.gz": "40858f3078b277165c191b6478c2aba7bf0010162273e28e9964404993eba188",
+ "dist/2022-11-03/cargo-1.65.0-aarch64-apple-darwin.tar.xz": "71013b8d491a355d0b88a97c9c47e50817cf1b506fc8507cd644d2225ec76356",
+ "dist/2022-11-03/cargo-1.65.0-aarch64-pc-windows-msvc.tar.gz": "5b5b684e028b9a024c137974a4121b355f016d644c635a6d0f4d29814cd1c9d9",
+ "dist/2022-11-03/cargo-1.65.0-aarch64-pc-windows-msvc.tar.xz": "b32487855fb9bafc58c423d62b52d283af100ab8e8519ce8a0d406adbfe7ceaf",
+ "dist/2022-11-03/cargo-1.65.0-aarch64-unknown-linux-gnu.tar.gz": "406d244def7ea78ed75ca4852498a1b632360626fb5fec69a8442b14ef04aee8",
+ "dist/2022-11-03/cargo-1.65.0-aarch64-unknown-linux-gnu.tar.xz": "3fd483c0d58673ab69862824408c8a48612827ddcdeaaca0f8fbe5ca02214a4c",
+ "dist/2022-11-03/cargo-1.65.0-aarch64-unknown-linux-musl.tar.gz": "43cb587b766a892d9c474f0a04417533d6c12e085ba07af8e27853d41afb4f91",
+ "dist/2022-11-03/cargo-1.65.0-aarch64-unknown-linux-musl.tar.xz": "5e9880995c5a8f247a2d8ee143183f45feee1ec09bad5e147c837518f01591e4",
+ "dist/2022-11-03/cargo-1.65.0-arm-unknown-linux-gnueabi.tar.gz": "25c783ec2a61c127215609ae5e45ca11de938cf8e1e163ccdd422be2b245414a",
+ "dist/2022-11-03/cargo-1.65.0-arm-unknown-linux-gnueabi.tar.xz": "88b14f59d8dbc64c093100a2748f5392510b480ac4b05a816a85b50030b90db1",
+ "dist/2022-11-03/cargo-1.65.0-arm-unknown-linux-gnueabihf.tar.gz": "1793a5773d24d6e4685870a6e47de3f764e74d35f85bdc0d3e888be0efce6a54",
+ "dist/2022-11-03/cargo-1.65.0-arm-unknown-linux-gnueabihf.tar.xz": "e3b82e61a5bbf6338555716d8e925cd0a96e4fc0ae262dd04bec009a46aa6051",
+ "dist/2022-11-03/cargo-1.65.0-armv7-unknown-linux-gnueabihf.tar.gz": "fcd2a151adebc87fddebb710d7c7606f0aa77245bb45ec05f8b600cd30008687",
+ "dist/2022-11-03/cargo-1.65.0-armv7-unknown-linux-gnueabihf.tar.xz": "a27a726733230bff2807109fdd619ccd04d3e96e22ea53d3e24552524619ec2f",
+ "dist/2022-11-03/cargo-1.65.0-i686-pc-windows-gnu.tar.gz": "894dc627e3d5a597ca8c6aa5d0ef55f2d9130b14dde19df193b41242e605a31f",
+ "dist/2022-11-03/cargo-1.65.0-i686-pc-windows-gnu.tar.xz": "e462df98c630ab06196d27a2a631bbf12da40f8cb0d40028368205e1dcdbe978",
+ "dist/2022-11-03/cargo-1.65.0-i686-pc-windows-msvc.tar.gz": "d8d9ec39ba20f8d0ad37a2c0791008631e6ac6efc419bc9543a65785db097c5a",
+ "dist/2022-11-03/cargo-1.65.0-i686-pc-windows-msvc.tar.xz": "2994d66f1644a7a0d814cec9d619cca204adeb2af81cb03759f168044d9bf4ee",
+ "dist/2022-11-03/cargo-1.65.0-i686-unknown-linux-gnu.tar.gz": "b58b88e7dbfc7b570df1ec0f7be75c318ad8e99ff1e66f4154827b2c81eee3d2",
+ "dist/2022-11-03/cargo-1.65.0-i686-unknown-linux-gnu.tar.xz": "64d456a303d6f1edf0bd9807089aa71ef065705b9dd7d115faff5c2d431e78cd",
+ "dist/2022-11-03/cargo-1.65.0-mips-unknown-linux-gnu.tar.gz": "602458e1f1669d0a0daf5edd0fb0f9aff24891357e2eda12fcef1b2bb56d95c9",
+ "dist/2022-11-03/cargo-1.65.0-mips-unknown-linux-gnu.tar.xz": "f32903493610bb5b2302139bf37120159b848223cdc23da546e6fae7e8e6cbfc",
+ "dist/2022-11-03/cargo-1.65.0-mips64-unknown-linux-gnuabi64.tar.gz": "b9a484868b89cc435dc65bc545ec89126d12a9a76a477a13263bcda2f1572f57",
+ "dist/2022-11-03/cargo-1.65.0-mips64-unknown-linux-gnuabi64.tar.xz": "453e95cc057583057c2239539425a4e57d80e38ba00288f09d04fddcde2548af",
+ "dist/2022-11-03/cargo-1.65.0-mips64el-unknown-linux-gnuabi64.tar.gz": "ca75879b45e7768b6be0d5809e41cc82783f9db4ce7f670966e665ed843a65e2",
+ "dist/2022-11-03/cargo-1.65.0-mips64el-unknown-linux-gnuabi64.tar.xz": "594c03b8e6e6a7f3d38cf655591d63c24ed2ab5ce14ace41f1f2c1181c9c09ca",
+ "dist/2022-11-03/cargo-1.65.0-mipsel-unknown-linux-gnu.tar.gz": "01ffeeaf5cd1837810580ba2fe7c74354cc25cb7a0a6858e815dfad6aa5e3fd8",
+ "dist/2022-11-03/cargo-1.65.0-mipsel-unknown-linux-gnu.tar.xz": "a80ca689ce20508fddb6274e2e5f69a59a5b8e1a1272f840d6b1ca60f83dcccb",
+ "dist/2022-11-03/cargo-1.65.0-powerpc-unknown-linux-gnu.tar.gz": "ac9c7bf7e7c38ef6a14e72ddad5abe9592ebbdd9d80c4c5ce59046fd790260a6",
+ "dist/2022-11-03/cargo-1.65.0-powerpc-unknown-linux-gnu.tar.xz": "cc309119f4157f3cbdafe065d07bee7de5f262da998854e02b2d8f9f425dce73",
+ "dist/2022-11-03/cargo-1.65.0-powerpc64-unknown-linux-gnu.tar.gz": "3aab12cb517b9d27feb0d43fd24834af627a4556bf8760937a77429fe9087592",
+ "dist/2022-11-03/cargo-1.65.0-powerpc64-unknown-linux-gnu.tar.xz": "32fac316c0676e395fa3c87ad4222d3c70489278da4c6986ee30406df6e6eb4f",
+ "dist/2022-11-03/cargo-1.65.0-powerpc64le-unknown-linux-gnu.tar.gz": "aad8a7e6df87d81e2e0c2913670547dc65672434c23d32811da307ec4b767f59",
+ "dist/2022-11-03/cargo-1.65.0-powerpc64le-unknown-linux-gnu.tar.xz": "9393de910df7cd6947e380460a1144ac2373a36c776c7367a81212a51a92d9a7",
+ "dist/2022-11-03/cargo-1.65.0-riscv64gc-unknown-linux-gnu.tar.gz": "913289a36696a53e642bd247d7d78920809c5db6300a3181064b62c82a0444b3",
+ "dist/2022-11-03/cargo-1.65.0-riscv64gc-unknown-linux-gnu.tar.xz": "fdc9be1d0552179318c588e8eebebfa42fcf5eb65d58b93ba2949d9b5718b429",
+ "dist/2022-11-03/cargo-1.65.0-s390x-unknown-linux-gnu.tar.gz": "ca3f9db0bf5bc244bdc225eccb54f9a0b2663ac92e374e33c7c8d6d9339f6b78",
+ "dist/2022-11-03/cargo-1.65.0-s390x-unknown-linux-gnu.tar.xz": "bcddebbf39443e62d67e35b3c669677442a551dbfa1f172e2405368cc571e555",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-apple-darwin.tar.gz": "40cbbd62013130d5208435dc45d6c91703eb6a469b6d8eacf746eedc6974ccc0",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-apple-darwin.tar.xz": "906a656ea12808065da0702082fb08d010f0d51f61148887068ac44613c07ebc",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-pc-windows-gnu.tar.gz": "79819a7e5ade380a36cb7bebf8922034802891333bf85c1d0e194b9b70c7ff4a",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-pc-windows-gnu.tar.xz": "06f51741e03f9ba458fa774c705f078a5bba36f2f5a990e555c710a4b39a9eae",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-pc-windows-msvc.tar.gz": "2932be27a0ebea2d36a30c18b758a7f90582fcb8bc675a225d661e611e57afb9",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-pc-windows-msvc.tar.xz": "a0ef427322ac3f41d64f935655942a7dcf7e40bbc7d4f82600087f96d02de4c0",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-unknown-freebsd.tar.gz": "a896973695382f4c622b98544f6126c088b21d6a625c129131b113ac36d777a8",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-unknown-freebsd.tar.xz": "b12447bec51998ca618710de0f72fdf728c881de76dd28133ead22758be70de1",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-unknown-illumos.tar.gz": "a1f391d8d3a819e4c217ab6a12c864cd0af69255ca653566320dbef5eefe0769",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-unknown-illumos.tar.xz": "e357c8cc226a1985649c1bec88c1fe9bb0a860d01c530e5692726739fab3dfad",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-unknown-linux-gnu.tar.gz": "f7d67cf3b34a7d82fa2b22d42ad2aed20ee8f4be95ab97f88b8bf03a397217c2",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-unknown-linux-gnu.tar.xz": "82547aacaf42fc3c2970ec31b96751dfbeba3dffe1a042a3780bd670c29a89bf",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-unknown-linux-musl.tar.gz": "43a7154520914663c0d291284621e40cf116ad3b5fea6274ea7cfdd4b9e7368f",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-unknown-linux-musl.tar.xz": "7b2b3632205310b867d8d70403aa7ea3a879972033442628fa59483e4ecf0d8b",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-unknown-netbsd.tar.gz": "fc41c57eabf4a601bdfd78b8586f0e639404305ca0b61ad62284be4623394de3",
+ "dist/2022-11-03/cargo-1.65.0-x86_64-unknown-netbsd.tar.xz": "1567ef1c6ca630fc03125cf4560dcb4d4d2cf1cdcd23ef8b1ad7ec7fa4881693",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-apple-darwin.tar.gz": "68316299635d2577af3b64a2de4839a107f6c33f92e9427d6127526d12ecf07f",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-apple-darwin.tar.xz": "c467c69df0821daebc02be91ac012e4e930ac8e9ef8bdeebf3f04cb5517cc7b0",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-apple-ios-sim.tar.gz": "34061a4772a1054803ea26ccddef78f8d4f654b6c00b328232df7fb4f68c0b20",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-apple-ios-sim.tar.xz": "28c94371a7e0f842bd75af8107e3e6c1e057a2500f1fb81fcc2436700559542f",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-apple-ios.tar.gz": "7707c1fd458a72cedbb62cd0060043eabe6d0f6b66f9d73f2453f502231df85e",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-apple-ios.tar.xz": "d47d58f2ab066002fea4f75184ae9ec1eede3a3636e4948d564c6511d2e85fb2",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-fuchsia.tar.gz": "b4798d4b55b8b8423a1cc870118d2972d057439bbfa2b80f28a83fb2ca242f74",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-fuchsia.tar.xz": "12f2213e0451336a6e9f35b13bf51bdbad445c53cad52cb86577b831d6fa5feb",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-linux-android.tar.gz": "a948302c50dc0960a1eeaf564cead55bb9d1228847e4c396a244e1f9cdc9a14d",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-linux-android.tar.xz": "aa7a9537f10b7551711c0a70d8f632ed6416f442749e508a1fc698a47eb34308",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-pc-windows-msvc.tar.gz": "c14710a87c532cd606955a7c3021a75d4f7a3be2cc05211452df6ae00b9205f5",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-pc-windows-msvc.tar.xz": "1aaa57c35d2a3b52123a02daf85e741b525721bbb2eaa5722388a1ddb9f6fe68",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-unknown-linux-gnu.tar.gz": "86eea00f31fc4cfe320624b38547d1850efb3c890ed00e73b39f725803c4c755",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-unknown-linux-gnu.tar.xz": "735b681c8a6e60925c76d6cc899e78b4cb4562ada24a1f265b2021c1faad78ad",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-unknown-linux-musl.tar.gz": "5136887db2170733bb40b18be597e0ac9474fac030d7344c4517b38b0c98c70a",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-unknown-linux-musl.tar.xz": "9ea488da40c347826cce7e238847c745ee566254bb1d077412673f8243fb1cd2",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-unknown-none-softfloat.tar.gz": "f9c09c55883181e09f5d169e210e8bc15d55c459b4c187e4987969429e076980",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-unknown-none-softfloat.tar.xz": "b52417af1f9ea204cc20c66f486c7233a1e1571243dd38630149b79b7ce2c825",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-unknown-none.tar.gz": "3be333d58f33e5790586b20b369bb1110e3241d14c42282720f80107d6e0df6b",
+ "dist/2022-11-03/rust-std-1.65.0-aarch64-unknown-none.tar.xz": "8258b2773dc1688826c126e01b138be10c22a43137ebf091f0a1938fee8272f5",
+ "dist/2022-11-03/rust-std-1.65.0-arm-linux-androideabi.tar.gz": "beffe3e8ce63cd9a2f8cf26cdd9dda2c1178d50c8612009e36ef3d40e845ea9c",
+ "dist/2022-11-03/rust-std-1.65.0-arm-linux-androideabi.tar.xz": "5379cc9c176bc708bf3d8d01f101514267cd09cc055e9b68d741b40a0302c396",
+ "dist/2022-11-03/rust-std-1.65.0-arm-unknown-linux-gnueabi.tar.gz": "0802275835c36a936031a1da78e11c8070e3fa7f699951977bc0463748805d07",
+ "dist/2022-11-03/rust-std-1.65.0-arm-unknown-linux-gnueabi.tar.xz": "c8793e77ef43336bc372a7a5b4720d5449e92577c7875471c2bc40ddbfde4811",
+ "dist/2022-11-03/rust-std-1.65.0-arm-unknown-linux-gnueabihf.tar.gz": "cbbd549a619cf13c413e1954ed8dca72939e583a34b59076e1fb034e4e04dc24",
+ "dist/2022-11-03/rust-std-1.65.0-arm-unknown-linux-gnueabihf.tar.xz": "f7d5eb17dbe46ee9d3c4f9fcffc07b8e3311c747545402c8d3b5c43043f27288",
+ "dist/2022-11-03/rust-std-1.65.0-arm-unknown-linux-musleabi.tar.gz": "90ee725d476587abfea627f3e6ebda3073f44fdc1af53d2fc2e71a27f7ad38d1",
+ "dist/2022-11-03/rust-std-1.65.0-arm-unknown-linux-musleabi.tar.xz": "453a1443e4753611dc4e6969e50ad8d7984a31d1a457729a860599ed19b1de7a",
+ "dist/2022-11-03/rust-std-1.65.0-arm-unknown-linux-musleabihf.tar.gz": "1b170a4206d7de4fdfae965c5d41b29f6d44f117c5ed8c691270d54ad82e98a4",
+ "dist/2022-11-03/rust-std-1.65.0-arm-unknown-linux-musleabihf.tar.xz": "32d7f301196d73027fb9a5ae595dbadacdc234307c36b4a175a132e75318e38c",
+ "dist/2022-11-03/rust-std-1.65.0-armebv7r-none-eabi.tar.gz": "e7411233c42774111cbecd5e7f833cc552e4e10047ef368835fc6bb6779bd62a",
+ "dist/2022-11-03/rust-std-1.65.0-armebv7r-none-eabi.tar.xz": "aa0052fc3904d93ba4f107f49e16849118108390cb1152f17323cdc2bd559b1e",
+ "dist/2022-11-03/rust-std-1.65.0-armebv7r-none-eabihf.tar.gz": "c85f7d61c3a9d4930005e5f054b71145aa6da207ad6b3cb10b7f65514adf0f54",
+ "dist/2022-11-03/rust-std-1.65.0-armebv7r-none-eabihf.tar.xz": "2d43f8c1a80a9713955915388cf00756388ca0423930839b22bb0687efa173ed",
+ "dist/2022-11-03/rust-std-1.65.0-armv5te-unknown-linux-gnueabi.tar.gz": "e4410b54c63eab57e234a5c230744b3bb63704e012d503bb27ea27e47b85afb1",
+ "dist/2022-11-03/rust-std-1.65.0-armv5te-unknown-linux-gnueabi.tar.xz": "d079e841be640b4ce26aa821f29bc813243a7c0af7b8aca8ca4acf5c2e5b722f",
+ "dist/2022-11-03/rust-std-1.65.0-armv5te-unknown-linux-musleabi.tar.gz": "8897a7c3df9cad8d5686c7c0aa5475f82aa3e94de2f8ff7184fa017e94da96dd",
+ "dist/2022-11-03/rust-std-1.65.0-armv5te-unknown-linux-musleabi.tar.xz": "1d11ab1d60070ae30ff87b55dca077f4d532d814a9ab7bc77055b5b429a78c6e",
+ "dist/2022-11-03/rust-std-1.65.0-armv7-linux-androideabi.tar.gz": "c7b9649ff1ca1accf8a0f109eccafdb8c5746596b77253bd65c856b616ab02fc",
+ "dist/2022-11-03/rust-std-1.65.0-armv7-linux-androideabi.tar.xz": "da55725498ac8af64359e7c2a46f225dbaf647e1254f648b1f150a3a10a0de94",
+ "dist/2022-11-03/rust-std-1.65.0-armv7-unknown-linux-gnueabi.tar.gz": "2b2962822322e6c361bb1213f95fb17ac87aefc0e369ac7de67d7d31035092ef",
+ "dist/2022-11-03/rust-std-1.65.0-armv7-unknown-linux-gnueabi.tar.xz": "c14268337c69650a2618909d8e691489385d748374d73ab8d6a2f9d6b030d70d",
+ "dist/2022-11-03/rust-std-1.65.0-armv7-unknown-linux-gnueabihf.tar.gz": "616714d28c5c4c0273a22cbc18179ba5354d2e3f4dfc300024266c46b4f68127",
+ "dist/2022-11-03/rust-std-1.65.0-armv7-unknown-linux-gnueabihf.tar.xz": "fec73401941bffce3b6913d31955f1291119dea119c0051d94f271ae7c959d4c",
+ "dist/2022-11-03/rust-std-1.65.0-armv7-unknown-linux-musleabi.tar.gz": "c920e0c288d08be499efeafeb1d52f6c30c6abeca57f09d57190292af21b9645",
+ "dist/2022-11-03/rust-std-1.65.0-armv7-unknown-linux-musleabi.tar.xz": "0b5bc219333e3e983fb1e7e86a0c268c4a52ccbd6326a16785be9d9017d97e9f",
+ "dist/2022-11-03/rust-std-1.65.0-armv7-unknown-linux-musleabihf.tar.gz": "da790276100bf066127987bb7964325379ef249f887d17fd3e26bc1628700a8f",
+ "dist/2022-11-03/rust-std-1.65.0-armv7-unknown-linux-musleabihf.tar.xz": "9368527053c4bab0fd320209b45f0278d0a1e54a37006a56a6e565404ab73fef",
+ "dist/2022-11-03/rust-std-1.65.0-armv7a-none-eabi.tar.gz": "f687d4efa0e494feb97ee2103dd2d3149af54d4751c3327d26fea71711ecc464",
+ "dist/2022-11-03/rust-std-1.65.0-armv7a-none-eabi.tar.xz": "4a157c9d23367be9a16cb0ea667f80ee85f2aa4ca549fb0a893f40a846927db7",
+ "dist/2022-11-03/rust-std-1.65.0-armv7r-none-eabi.tar.gz": "cfa95c5ebe1183f5d2fc1d05676915a35fb0234085c7a7ff20da822d8fb3b03c",
+ "dist/2022-11-03/rust-std-1.65.0-armv7r-none-eabi.tar.xz": "b5e9a895d2f59da805453435ed827a957ef131ef465c139456360c5c9ebf86f8",
+ "dist/2022-11-03/rust-std-1.65.0-armv7r-none-eabihf.tar.gz": "e18afa534abd57c7cc8827cabd60e87710299817f4bfdd75699e2f200952d6f3",
+ "dist/2022-11-03/rust-std-1.65.0-armv7r-none-eabihf.tar.xz": "25ced4ebecd8da057b74c14bfd810d645454959f58677c32d5d0b3942303f13b",
+ "dist/2022-11-03/rust-std-1.65.0-asmjs-unknown-emscripten.tar.gz": "10387374e52db6232723a7f71327a130f88980f063b26ffc0a9b450b2fb7d67b",
+ "dist/2022-11-03/rust-std-1.65.0-asmjs-unknown-emscripten.tar.xz": "0b28c4673f2e4006732dfdc1085c754e9c94c82a8c3b2afda17981e87c5cfaf9",
+ "dist/2022-11-03/rust-std-1.65.0-i586-pc-windows-msvc.tar.gz": "3e5c4634045d67fbe710ba77c78b257b58bc74d51d2fde9c25e018676d190da9",
+ "dist/2022-11-03/rust-std-1.65.0-i586-pc-windows-msvc.tar.xz": "d81357c4b1b814f8bde8e3d5fc039fa7e9072c9f15aa75e129e98d37eb9f4675",
+ "dist/2022-11-03/rust-std-1.65.0-i586-unknown-linux-gnu.tar.gz": "2813d22ea020ff3ba737762b19d03e4ede5713d4ffd5222c70f798016019963a",
+ "dist/2022-11-03/rust-std-1.65.0-i586-unknown-linux-gnu.tar.xz": "533eda439eb5ffec258b8219445742d6d60570040b3ff167291e3d0d985b9d70",
+ "dist/2022-11-03/rust-std-1.65.0-i586-unknown-linux-musl.tar.gz": "415c09908b8a38841221e4021d428262e6c394cebc82af32f091bcfbf849e1e2",
+ "dist/2022-11-03/rust-std-1.65.0-i586-unknown-linux-musl.tar.xz": "7f5d9ae65827aef1a51676927a4c9533f942021d2fd45fd93b23dfaa738ee205",
+ "dist/2022-11-03/rust-std-1.65.0-i686-linux-android.tar.gz": "c6cea8b87db4c2b56e02a0a50e5906f4cf73cffe78cb282cc6f5aaa2e5daa78f",
+ "dist/2022-11-03/rust-std-1.65.0-i686-linux-android.tar.xz": "85c9f5f8b165e76876f95f3423adb8260f8c7fe4fc8ca15660ae870cc2d53916",
+ "dist/2022-11-03/rust-std-1.65.0-i686-pc-windows-gnu.tar.gz": "9ea4072ebf97349fc0b34e27cb9c2e03d2b508b07d21edaf74a25e60f7d7853d",
+ "dist/2022-11-03/rust-std-1.65.0-i686-pc-windows-gnu.tar.xz": "c0f6c117faec7b4d8c4cbe0a252604ff45dcadacb3b75fc6b9e67671d0b878fa",
+ "dist/2022-11-03/rust-std-1.65.0-i686-pc-windows-msvc.tar.gz": "139f947a0d85702c61efb294aa0353768dc7b96c014dc5a092979170507f37d9",
+ "dist/2022-11-03/rust-std-1.65.0-i686-pc-windows-msvc.tar.xz": "33f36a6b82ed2dd9a120d503d3701807db12d482144813fb6eaa4f5ca03f425e",
+ "dist/2022-11-03/rust-std-1.65.0-i686-unknown-freebsd.tar.gz": "e0ae8dad99b48ba9525e07351bdc53ea6ef3a88b268b68be5092df9a84b89cbc",
+ "dist/2022-11-03/rust-std-1.65.0-i686-unknown-freebsd.tar.xz": "016666bdc2cb3b3d994385ec7f73e8bf59491d226818757cc8dafc07705ba45a",
+ "dist/2022-11-03/rust-std-1.65.0-i686-unknown-linux-gnu.tar.gz": "8f3c90a21494b90e7f7bb16ee8f0b170b4d63389b05ce6c158eeedf5904d51fb",
+ "dist/2022-11-03/rust-std-1.65.0-i686-unknown-linux-gnu.tar.xz": "99bd62d593a6ab3205cab7f06b5793a075b9d05d868e927a6948e46269d61e82",
+ "dist/2022-11-03/rust-std-1.65.0-i686-unknown-linux-musl.tar.gz": "f29068870b8ce028a13b4593add734c120ca9bd08dfb6826701a9e7fccd5e1ae",
+ "dist/2022-11-03/rust-std-1.65.0-i686-unknown-linux-musl.tar.xz": "644a4c57c1392f776c5ebb13f9832778b69464391b3766e6bbd18c3aa11787a6",
+ "dist/2022-11-03/rust-std-1.65.0-mips-unknown-linux-gnu.tar.gz": "83cd534c97c44b3cda6eb2b5bc1259906cd7b7c4711950d62816736eca82eff3",
+ "dist/2022-11-03/rust-std-1.65.0-mips-unknown-linux-gnu.tar.xz": "50c65a8effc85aa89242ba0a2a2c89bfcc4d0a39dcb42396d10b0036b9a4e90c",
+ "dist/2022-11-03/rust-std-1.65.0-mips-unknown-linux-musl.tar.gz": "ea6c59b68367159e64af476035ef8b94b322f2246a453ac1ed475a990dcead55",
+ "dist/2022-11-03/rust-std-1.65.0-mips-unknown-linux-musl.tar.xz": "3bc5043f4eb7bb6418708792ee8e777197e562d03843a9adf62ce245ba07289a",
+ "dist/2022-11-03/rust-std-1.65.0-mips64-unknown-linux-gnuabi64.tar.gz": "5b163bc93b6fb649668b7dfda6afed48e35d29cb67e05baba59e109b96e77404",
+ "dist/2022-11-03/rust-std-1.65.0-mips64-unknown-linux-gnuabi64.tar.xz": "338c702b79dac33e32dde097084dd38852487d2976c5eb66b44ba8fc8319342b",
+ "dist/2022-11-03/rust-std-1.65.0-mips64-unknown-linux-muslabi64.tar.gz": "7a6ab5c7cd4c6c5c63a118750867f0c4410c862689cdcc7440937d00639aa9d5",
+ "dist/2022-11-03/rust-std-1.65.0-mips64-unknown-linux-muslabi64.tar.xz": "9450745a5e678c9b7e65ecc7d6a016f92d8d22d8091c4a77431b1e58b99a435f",
+ "dist/2022-11-03/rust-std-1.65.0-mips64el-unknown-linux-gnuabi64.tar.gz": "1efc00ec863d21be4b1f097dfbc206fceee31a9b2ffcaff5230ba42e29ffdb04",
+ "dist/2022-11-03/rust-std-1.65.0-mips64el-unknown-linux-gnuabi64.tar.xz": "a0a0e60a0e850140194250fbbfb962c322d4f474f4ec22d03b7f537034257c09",
+ "dist/2022-11-03/rust-std-1.65.0-mips64el-unknown-linux-muslabi64.tar.gz": "91270833ad6cdadf7bb406e175906e8e5c8431caa5fc3cfc10cc40163cb14578",
+ "dist/2022-11-03/rust-std-1.65.0-mips64el-unknown-linux-muslabi64.tar.xz": "0862706d22dcfee39b0d2df874dd6065d8c3020c0b8974f6e7b694edd42413ae",
+ "dist/2022-11-03/rust-std-1.65.0-mipsel-unknown-linux-gnu.tar.gz": "646398fdd4ee9f5b9a96aee16c615a4f32f77f2bcdc7ee2a4f5f2274cf1d6b92",
+ "dist/2022-11-03/rust-std-1.65.0-mipsel-unknown-linux-gnu.tar.xz": "79e078420f7c45fd1cf38b70620ced50d35ddb1621736b65be987c20481fe5bc",
+ "dist/2022-11-03/rust-std-1.65.0-mipsel-unknown-linux-musl.tar.gz": "9db41968e4f025fb9c049a6db88fc1b785503ce161e77f2879f795f422d83f7b",
+ "dist/2022-11-03/rust-std-1.65.0-mipsel-unknown-linux-musl.tar.xz": "482e9245873338a08f47ea2c29683134b8813deb3e3eafb78b786d34bbecce51",
+ "dist/2022-11-03/rust-std-1.65.0-nvptx64-nvidia-cuda.tar.gz": "28e3eecde27c015f854a93f44a4af86efb59f7a0c9800a77b91edeb50d08f571",
+ "dist/2022-11-03/rust-std-1.65.0-nvptx64-nvidia-cuda.tar.xz": "1aeb2f90c2b15d835fadf0c3874bea8a1af740b8ba4b802eb6cbee4496f5357e",
+ "dist/2022-11-03/rust-std-1.65.0-powerpc-unknown-linux-gnu.tar.gz": "7c1f66581e7024e6e3ecd69db878defd5ea4a88b8b049ffaf62965ce9d652b15",
+ "dist/2022-11-03/rust-std-1.65.0-powerpc-unknown-linux-gnu.tar.xz": "672b9ea8018dcdf7d5f79f5298bacc34e7600a082727b4f1a20c14251752aaa2",
+ "dist/2022-11-03/rust-std-1.65.0-powerpc64-unknown-linux-gnu.tar.gz": "f3a25b84be74da0455f6e85c9c1d189ce1cd660e965c6bc7d1018c8fdd31e597",
+ "dist/2022-11-03/rust-std-1.65.0-powerpc64-unknown-linux-gnu.tar.xz": "8a26e08908156ae5a05c64c2732435ef4efb994a2ac6d0b2e9c93c0dae19d089",
+ "dist/2022-11-03/rust-std-1.65.0-powerpc64le-unknown-linux-gnu.tar.gz": "b66b5d04ad9627003b6658399e22ebf758cf6c6ce4b38ae0829cc3817402d776",
+ "dist/2022-11-03/rust-std-1.65.0-powerpc64le-unknown-linux-gnu.tar.xz": "ce18b44300f7d5d94856cef5b270ba010061fafa411beb9782207e26cbab88a6",
+ "dist/2022-11-03/rust-std-1.65.0-riscv32i-unknown-none-elf.tar.gz": "cd0eeecc284385a66f6c217467cde74ce450b02b6ac3418989ed452e1d9fa56e",
+ "dist/2022-11-03/rust-std-1.65.0-riscv32i-unknown-none-elf.tar.xz": "19cdc94ab99fd668cfd0697ddaf38989ab6aa8b6a317291fee87911c4879c09b",
+ "dist/2022-11-03/rust-std-1.65.0-riscv32imac-unknown-none-elf.tar.gz": "a7dd667b06ad75fd6027b2cf34921c57d3419b1e63ee687085af6955a0d79d9a",
+ "dist/2022-11-03/rust-std-1.65.0-riscv32imac-unknown-none-elf.tar.xz": "5d61b0ab7bc4f065279e131aac33d64d2c2f5c5f6ad356f45278340bdb3ad223",
+ "dist/2022-11-03/rust-std-1.65.0-riscv32imc-unknown-none-elf.tar.gz": "9ee81f4c10602eab12d4ab0048e2a3aea8a557bf0cd4e5274a344c2f9ba2ec27",
+ "dist/2022-11-03/rust-std-1.65.0-riscv32imc-unknown-none-elf.tar.xz": "b73be7b808403390cd81c53e46d117be3202c4e97c69dfc7a7e4e34fbe3c0b47",
+ "dist/2022-11-03/rust-std-1.65.0-riscv64gc-unknown-linux-gnu.tar.gz": "ee47cf94cd4fd130a233518236f49b742f7f29bb66e2256be23ba71a292430e2",
+ "dist/2022-11-03/rust-std-1.65.0-riscv64gc-unknown-linux-gnu.tar.xz": "fa99f123ce14f1cda245857b50fd4709adee960e7d36ce663b87c13aee18b64b",
+ "dist/2022-11-03/rust-std-1.65.0-riscv64gc-unknown-none-elf.tar.gz": "55459a12f4f2a3cdc7c050febd26365fb5326db62243b406349eb87783d177b3",
+ "dist/2022-11-03/rust-std-1.65.0-riscv64gc-unknown-none-elf.tar.xz": "8f1bfe6264930035324d4c497bcd1af70bf6c302e470cc96b9103c6c57930264",
+ "dist/2022-11-03/rust-std-1.65.0-riscv64imac-unknown-none-elf.tar.gz": "fdd2b1bbee188a1fd74f700096b486fc659c9d29c5f7f906aa2958d4dc95ec91",
+ "dist/2022-11-03/rust-std-1.65.0-riscv64imac-unknown-none-elf.tar.xz": "04f970b1b643049dba001459075609368203add0b00de797fbca53384c8895d9",
+ "dist/2022-11-03/rust-std-1.65.0-s390x-unknown-linux-gnu.tar.gz": "f3ea601929249df63d207883a3777f0def4e84f4e7c1cfe12e3f7872e3f20996",
+ "dist/2022-11-03/rust-std-1.65.0-s390x-unknown-linux-gnu.tar.xz": "a3f6740be345364f4599ae837d2401e0f31e5d33a4f958852d12a384ee581a83",
+ "dist/2022-11-03/rust-std-1.65.0-sparc64-unknown-linux-gnu.tar.gz": "f58ed6eba451802d5ba37ce1455266317863fdfa04096e0ca8f2cb25488083bd",
+ "dist/2022-11-03/rust-std-1.65.0-sparc64-unknown-linux-gnu.tar.xz": "fc2a8816665f464d3085dcd379c44b9de0ee1f1084fae0a4c32c57754b27992b",
+ "dist/2022-11-03/rust-std-1.65.0-sparcv9-sun-solaris.tar.gz": "021fb2b640e88717b32356d738a1385cf41c860fdec5830045d026cdf11261de",
+ "dist/2022-11-03/rust-std-1.65.0-sparcv9-sun-solaris.tar.xz": "7941668a20b44d293485a0c8369f46a1cb6f29fa976fb1644097897723447960",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv6m-none-eabi.tar.gz": "f8de6b8de74bfdb20921be1f61df7b018e29b4f94829d951004ddb82b9062086",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv6m-none-eabi.tar.xz": "f9b28bdb16e33343e4dbc66921a295f42371273f147c30d76552cf7c97fc15a0",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv7em-none-eabi.tar.gz": "b1e9b2f38f8197236efa70ec75de87dd5503c466c8a9bdd14cd54144ab26ec74",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv7em-none-eabi.tar.xz": "862f08bbfc281b6f8417630f59670dadd22d49e4fb98f0dd153d2b81e2e39c5c",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv7em-none-eabihf.tar.gz": "4afecbf8043a574388c82a28522317dcbc332f585364572fae0dc41bf19f2aee",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv7em-none-eabihf.tar.xz": "609f8625e4397903173cd330774c2116d096a1d7a1539afa479a15b9e7961406",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv7m-none-eabi.tar.gz": "543a6365bff2f8038c41b144f02cf353c0421241235a9a431b379f53a758c95f",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv7m-none-eabi.tar.xz": "878de0ce07f95c8e2837350af17b0d75a1e759d150917a95aa966284f36d104b",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv7neon-linux-androideabi.tar.gz": "c1b5a05d36bdbbe3bbbfb1de2566969e3a82c61182fd74691362f8187e3d5622",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv7neon-linux-androideabi.tar.xz": "20b23a5b2ec299506b402921841afa5a948a67769749a59646d100f43ca4c206",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv7neon-unknown-linux-gnueabihf.tar.gz": "1102d8d4f3cea919ffa97655120f312dc4ec52c86918966f87c0145a055b4a5a",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv7neon-unknown-linux-gnueabihf.tar.xz": "0996cdb1f05ae6df6b26f3c2798bd72727952a73a5fa2a8e988ac992e71fa584",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv8m.base-none-eabi.tar.gz": "266ce748b7d7bd241547ce1a9b9c27971580e0706dbee58550d2207fb3d97f91",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv8m.base-none-eabi.tar.xz": "d1fb5e2a653d6d98d6608ceb2ecb16f4379b791c2c81c03f4bcf4c23d70cab3c",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv8m.main-none-eabi.tar.gz": "7222393cc74402a855ba16496620d1ec92a4c3154a44660f3ad0333a4e40b872",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv8m.main-none-eabi.tar.xz": "f6b16ca290d003fd45d2bbea740a5b9803aafc8baa76dedc29074e6eebd07289",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv8m.main-none-eabihf.tar.gz": "17f534931cbc4298a4c2df6677d220989e3dcd3a50edd40f8d1e9113118f198a",
+ "dist/2022-11-03/rust-std-1.65.0-thumbv8m.main-none-eabihf.tar.xz": "1b22f23d4ee80a8c586a84acd988a550dc2b137ce8c624d48c2b44cfd93f1675",
+ "dist/2022-11-03/rust-std-1.65.0-wasm32-unknown-emscripten.tar.gz": "d776bc36af79f99582fdd7b559e6f692b7f617b7f83a47f369fa433f0f2b49fa",
+ "dist/2022-11-03/rust-std-1.65.0-wasm32-unknown-emscripten.tar.xz": "f9aa938f2c664f885d3eafad45519ba759ebe3631d62d953a2670174bb90517c",
+ "dist/2022-11-03/rust-std-1.65.0-wasm32-unknown-unknown.tar.gz": "177a35ce65f969127bbd58ef08e24471afb2c638a811104c493699a23f5e0006",
+ "dist/2022-11-03/rust-std-1.65.0-wasm32-unknown-unknown.tar.xz": "e5190436f2a0c7fa6f2b03bfbfd9c2b44a0de499533b6491f0ec05f08e9cbb6b",
+ "dist/2022-11-03/rust-std-1.65.0-wasm32-wasi.tar.gz": "5972f8bacfda0ed5e02b0b9a76ca3f6ed8f5f3d4c11d9ff42bafc8833c744b5d",
+ "dist/2022-11-03/rust-std-1.65.0-wasm32-wasi.tar.xz": "cfb55d6d29200a14cd2764a83d513cc85e45a79ed82f2916a7c6f06d10fc1d31",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-apple-darwin.tar.gz": "6b832ef5e94dc9d21c00b5c3cdbf5e4f4223a6215d6fa025ba064b7a24a4963a",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-apple-darwin.tar.xz": "8afef6fee075b7994b5f9b14b13738db27d9841af65f19fb9edccf299b013102",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-apple-ios.tar.gz": "9e5d88ea498ebdf50e1bbded7c3a107a820e668fb6c693c8d0d99244dba125b6",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-apple-ios.tar.xz": "2ba1cb490b834877a6caf77e5db19058492d7e943403b09a4efb1b89a0930cf3",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-fortanix-unknown-sgx.tar.gz": "cdef3244fbbbb2f291c462f53cd4ef6aeeda3d1b7ccb8d77b1d4040947855026",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-fortanix-unknown-sgx.tar.xz": "abdfbe1d32f3935cd5cf5235e88ca0275638977c0586aee2fd5a3a694ca9c0a9",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-fuchsia.tar.gz": "08faecdacef02a81b63d7d2a40fd18a10e7d6954f6461f95c95296936447fc26",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-fuchsia.tar.xz": "4ec2e0c20daf9f474f4cb660dee4707d892f1053c9099cb823b02bb9930d61e1",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-linux-android.tar.gz": "a093924e7fff13cde2c3a46903dc52f4e69e2ad1f79f477dc8e51ff053e87828",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-linux-android.tar.xz": "bd72b31cdab3c65434af6aed84a080cffc388acd4afc0e87d1223e358eff7acf",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-pc-solaris.tar.gz": "611f718e776fc021dcf1c6d7b66de15cb717049dc05d5f040717b4eec54eaa1b",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-pc-solaris.tar.xz": "e89de2a096a90308b78e4e8ee8d51f0b17db0319191bbae8823ee2c805b75ef1",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-pc-windows-gnu.tar.gz": "5ab4b95694511e4cd9af7c5ee3698f0d7c8a2be55e3fc8a7d866bcca1d560625",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-pc-windows-gnu.tar.xz": "05d44a506ec32cfda19a6959f1ad89d994f2705eea3b86f0c00cb9d2ec4423b3",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-pc-windows-msvc.tar.gz": "e07c5bd1b18068bf8e739a7b59875a2911d45315ad8b5e9e6348101f97fdb269",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-pc-windows-msvc.tar.xz": "8b2398872f69d15fcc57777472c31b58f7dc4b55c33f382870fc221995351a0c",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-sun-solaris.tar.gz": "5d7ec4e6f07d78bffad42289b4e8798f48b276c6c436159c4d4117c34c4d4cf0",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-sun-solaris.tar.xz": "4eacb700c3791a8f5d1424a4cdc8e3b35c4fcdee57b97c855cadca6821a7afbd",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-freebsd.tar.gz": "eab943166d86021dad01e65a2f304fcc2914d48e34bcba9f710f362401770e0a",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-freebsd.tar.xz": "bd2242d140bb99bf03d480c56ad85c5ab034d41e29599bee0609191e1181c96f",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-illumos.tar.gz": "153f7d78721ba0e273f9d556ebe4d35ec44522dce0f136e9fa269408345b9e06",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-illumos.tar.xz": "ef652ce8b7183068be581ebb8c91dcefac8ec0f84edbf86f7998261e503edafb",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-linux-gnu.tar.gz": "8c194b0e3814efecb87fc4779767ef17d25399fbd476dbfc92f9a7f88b98f784",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-linux-gnu.tar.xz": "2b588cd2d49688c0c33b7466614123e8fe4c910f4d802fc0ff0662b1772816a9",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-linux-gnux32.tar.gz": "e077e02a56c379950df3c3dda1b18b4fa78d33eb25667f206540dcca3eff0d55",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-linux-gnux32.tar.xz": "7c630f206556916021a7e43dfcfd8392fe1b1e3c7ec94ffc8ef1be87b0ce0631",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-linux-musl.tar.gz": "fbf8b5a2c388710cc7f4cc045d93cf05ebdd2d497936f54f995ccb44d346d85b",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-linux-musl.tar.xz": "55abeb1b55aeebc46a4af2f304271361397df58d12f7eb23fb262bc3132c6056",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-netbsd.tar.gz": "d0405e239dff6b7d840a5a6e45f60c7f661fd428d5a310b25e44de4e7fcb8eec",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-netbsd.tar.xz": "f173d07ccbbe65fc0878c16a7435f17a9db04476f0949e4625a79fa37911e436",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-none.tar.gz": "0942c94117d599cb85e028fc6f9aba057c1d1e8456a6d71c47f64c6d991e6ccd",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-none.tar.xz": "1d3ebe239659688ec787cc87819f8c4a6b77e0361f086111a5c36eb0ad730ca8",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-redox.tar.gz": "b8cc647867823ea52e4f6e647cf5fa7c6370447a324be8a70b56004f179301aa",
+ "dist/2022-11-03/rust-std-1.65.0-x86_64-unknown-redox.tar.xz": "23fd34f7ec55ba1e581e692764314c7c342eb87da00562dcba51808a89cb8a92",
+ "dist/2022-11-03/rustc-1.65.0-aarch64-apple-darwin.tar.gz": "bbcf34977e41b9f966746a559aa2af6fa7efd7f695338851b37f722f7a1104fb",
+ "dist/2022-11-03/rustc-1.65.0-aarch64-apple-darwin.tar.xz": "3368c57e5d2b396486eee5c38d184ddf13f248fbd0291c20764cd26a4e6fb5f1",
+ "dist/2022-11-03/rustc-1.65.0-aarch64-pc-windows-msvc.tar.gz": "1c0be4fe80c052e0df315ca97006d5c9c4fdc4c172f3c3c9e6bad3747731578e",
+ "dist/2022-11-03/rustc-1.65.0-aarch64-pc-windows-msvc.tar.xz": "d5008e3675ba9b57d05e4b9785b64b88d4166dc45b3fada6744e236024bfc18a",
+ "dist/2022-11-03/rustc-1.65.0-aarch64-unknown-linux-gnu.tar.gz": "5ada1a7c9496017e3eed5d8ada62699c8d513f7664d8e02d5d9f02d26974cedc",
+ "dist/2022-11-03/rustc-1.65.0-aarch64-unknown-linux-gnu.tar.xz": "67c3d3545fd898c1383071c0f6296453565e0da10903c50652d7bf679b53e8a2",
+ "dist/2022-11-03/rustc-1.65.0-aarch64-unknown-linux-musl.tar.gz": "f3e2d2890291fedfea3829c7ffe937603cc43464463fde25187a054ab46755df",
+ "dist/2022-11-03/rustc-1.65.0-aarch64-unknown-linux-musl.tar.xz": "51676b3c7023bf57084497b02c6fbfa1604309f52b207d1afe59cf7d20c5fa54",
+ "dist/2022-11-03/rustc-1.65.0-arm-unknown-linux-gnueabi.tar.gz": "05a72c333b1ef236fbbb1dc7245b38af1818f0de4e7148f4f7d03b4019cc9c5e",
+ "dist/2022-11-03/rustc-1.65.0-arm-unknown-linux-gnueabi.tar.xz": "d6157c4f1b33ca22035c4a796449a187cf8ea54ce50baafc0b035cc0728e8d16",
+ "dist/2022-11-03/rustc-1.65.0-arm-unknown-linux-gnueabihf.tar.gz": "2fa0fc7b34eaede3a9a9b85386fc217dc5f455e0a5252bcad10bbc2027b14ef9",
+ "dist/2022-11-03/rustc-1.65.0-arm-unknown-linux-gnueabihf.tar.xz": "a217abf1b6db15feb869702b9e3a6462640ba9e87fef9f3bd7c551d237fa2956",
+ "dist/2022-11-03/rustc-1.65.0-armv7-unknown-linux-gnueabihf.tar.gz": "34698308b23db42d36e2a651d1d122d0078eb0b1b6ad8d0fdf7dde8358f1486c",
+ "dist/2022-11-03/rustc-1.65.0-armv7-unknown-linux-gnueabihf.tar.xz": "883a82b25c5929ba1dbc532394b213a29a914d6dc6bfcf4f28da955c722a760c",
+ "dist/2022-11-03/rustc-1.65.0-i686-pc-windows-gnu.tar.gz": "2c6655ed0b87b123a632c861c7b0748d593f82c886013346884d5372d3c504e7",
+ "dist/2022-11-03/rustc-1.65.0-i686-pc-windows-gnu.tar.xz": "2ee9b0e2880b5e6817816ba891aa481c0e0c6625683126cc296b2b8dc73177cf",
+ "dist/2022-11-03/rustc-1.65.0-i686-pc-windows-msvc.tar.gz": "8ee53ccb1e99945be3c04e36154f467493170c663c47b1c5c8e68e9283875826",
+ "dist/2022-11-03/rustc-1.65.0-i686-pc-windows-msvc.tar.xz": "11c01faea62d1077b6e059958991c6496e27a6db1a0b8fd48fb0d2168981d8a5",
+ "dist/2022-11-03/rustc-1.65.0-i686-unknown-linux-gnu.tar.gz": "88b9ac8670c55077be42cb9168e0f17d922c0b0eba3044ffa3e63729f02b363a",
+ "dist/2022-11-03/rustc-1.65.0-i686-unknown-linux-gnu.tar.xz": "5345c5ffa8aa334419f3c4ca8669c9ea7545abd81097856bbf599271d48b24a8",
+ "dist/2022-11-03/rustc-1.65.0-mips-unknown-linux-gnu.tar.gz": "8f63f3cf93718ea10b7f462f5b31cf16b56178c1a120ea17d8bcf7485a1b2e74",
+ "dist/2022-11-03/rustc-1.65.0-mips-unknown-linux-gnu.tar.xz": "6ac4ffc60c6942be108e881717fe1288cad15db8a735966899ad8155fb39e17e",
+ "dist/2022-11-03/rustc-1.65.0-mips64-unknown-linux-gnuabi64.tar.gz": "8318f09fbe8e07ba5e01b19522fce3c2dea319e4edaeb7616004533510bbc930",
+ "dist/2022-11-03/rustc-1.65.0-mips64-unknown-linux-gnuabi64.tar.xz": "414a54a5dabd280c1d59925b3c2781d7850eb0e958701c7e51765478e69e9f06",
+ "dist/2022-11-03/rustc-1.65.0-mips64el-unknown-linux-gnuabi64.tar.gz": "dbabfcec57e0d8e1699111914affd0ae9618eb069c1c278c65dcc8febfdd6ef4",
+ "dist/2022-11-03/rustc-1.65.0-mips64el-unknown-linux-gnuabi64.tar.xz": "550ca4d5aaeeedcf9e9242060c4ce11eff88fe57860ef11921c7d034fd07a203",
+ "dist/2022-11-03/rustc-1.65.0-mipsel-unknown-linux-gnu.tar.gz": "ef52a7a666f0e76afe8ff61dba430bf64fed424e4b3e32cea11676a0889bad10",
+ "dist/2022-11-03/rustc-1.65.0-mipsel-unknown-linux-gnu.tar.xz": "77ffd6f14aaa13c54a5f470116e3a4866d44ed0fac2546c325bc4e4bfe66083a",
+ "dist/2022-11-03/rustc-1.65.0-powerpc-unknown-linux-gnu.tar.gz": "224e34c6add5e19bd7eb522048c0bedf259612328b21a2c6f01fe8a3fb7a68a5",
+ "dist/2022-11-03/rustc-1.65.0-powerpc-unknown-linux-gnu.tar.xz": "78c5334e77ef84be2ebce14c5adc4d4e20410d975f6349020cdcffd01ff2a590",
+ "dist/2022-11-03/rustc-1.65.0-powerpc64-unknown-linux-gnu.tar.gz": "aaca27aabaeded4e3e4243d372c3bbb213f5781185e8bb2416a5090d434c6ce7",
+ "dist/2022-11-03/rustc-1.65.0-powerpc64-unknown-linux-gnu.tar.xz": "e890651263099a66d85a021d455f1851507b58c5282680d1b1bb2f778d6cad1d",
+ "dist/2022-11-03/rustc-1.65.0-powerpc64le-unknown-linux-gnu.tar.gz": "17222364ca34b31bf2a596b1117114ddd08cd1f0d16309c21c1d712dadd63141",
+ "dist/2022-11-03/rustc-1.65.0-powerpc64le-unknown-linux-gnu.tar.xz": "a6ce7aadd10a3fd84fe4717a59378421a65b101b61f27eed8b09336b8daf62cf",
+ "dist/2022-11-03/rustc-1.65.0-riscv64gc-unknown-linux-gnu.tar.gz": "06f7b5761a290424f08bc66e258b9b4e47e45346873ed0ec0688fb223e232155",
+ "dist/2022-11-03/rustc-1.65.0-riscv64gc-unknown-linux-gnu.tar.xz": "60102ba6b659a1e070626d3f1098fd16427464631923c64a458f4e281901679d",
+ "dist/2022-11-03/rustc-1.65.0-s390x-unknown-linux-gnu.tar.gz": "1a9c7f8e18f3c5136c83d4b941cc567ac7d576b52a82e42c1bafbbf47d493b61",
+ "dist/2022-11-03/rustc-1.65.0-s390x-unknown-linux-gnu.tar.xz": "dc3666eeba9754f67876df7249961c79b21fc576f6e49185ca23d01d82d1356d",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-apple-darwin.tar.gz": "be525d2eb2a55f7f5a9f5b3cffe5c1d7b511b4adf9cf5d5855b861138152f1fa",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-apple-darwin.tar.xz": "4ee585ecd3f195eb2ee380a9a8550d24852a578c38f07138aef354b0a6b10b77",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-pc-windows-gnu.tar.gz": "3abfe8be05104781fb71b6d9f81afd46998733d1f672dd901b27263325f03e5c",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-pc-windows-gnu.tar.xz": "197bb667b78f5bcee3713a28b94f3beed30d8fc8b9ab00d5e70b1a75944a2c70",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-pc-windows-msvc.tar.gz": "894fe660f3508e9dfac49ed27880aff0dc07196bda1bf15c7c7cc530dbe5599b",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-pc-windows-msvc.tar.xz": "0eae7a12177781bedfeb042a21a971e57c1542e5a5a4da751edaf69f95ae7fbf",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-unknown-freebsd.tar.gz": "e6104c86d66a19527c48e4e533c28e1b7b74cd2c4e3dfc3eba139c4b152ea121",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-unknown-freebsd.tar.xz": "9dcde013879317c17a2e1e0e584f3ac1b6edda2419a51d32fac22201354a25e7",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-unknown-illumos.tar.gz": "25154fb657c111809698912f437fe94fabfcf3c367bd10d227755c9a9f6f9109",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-unknown-illumos.tar.xz": "922ecf55b2848099369d8b2f6bcfd2979cee307aabd5eab392955b813f7a53ad",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-unknown-linux-gnu.tar.gz": "6a30ffca17a244ad6bfb1d257572155f4e2b08d3ca2d852c2fc7420e264c6baa",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-unknown-linux-gnu.tar.xz": "62b89786e195fc5a8a262f83118d6689832b24228c9d303cba8ac14dc1e9adc8",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-unknown-linux-musl.tar.gz": "afcb7bcec9b128d641224ca476dc5f9e5ab74b6ff82235b95dd305e882e46def",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-unknown-linux-musl.tar.xz": "06960685fcf39f24993525cb804649343b8f3c953ad740163edee16d9c9645bd",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-unknown-netbsd.tar.gz": "5af04405b78b7a4062e163b7926014fda0a7ef851d75ed50bcaf3f472c277028",
+ "dist/2022-11-03/rustc-1.65.0-x86_64-unknown-netbsd.tar.xz": "d6b913b77954146a2aca87ea15758df6bc9481512692423f0b1c0c39c14d5095"
}
}
diff --git a/src/test/assembly/asm/aarch64-types.rs b/src/test/assembly/asm/aarch64-types.rs
index 04b5f4aed..66c39a48c 100644
--- a/src/test/assembly/asm/aarch64-types.rs
+++ b/src/test/assembly/asm/aarch64-types.rs
@@ -2,7 +2,7 @@
// compile-flags: --target aarch64-unknown-linux-gnu
// needs-llvm-components: aarch64
-#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)]
+#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
diff --git a/src/test/assembly/asm/arm-types.rs b/src/test/assembly/asm/arm-types.rs
index 5ac1af6af..b22a26ce3 100644
--- a/src/test/assembly/asm/arm-types.rs
+++ b/src/test/assembly/asm/arm-types.rs
@@ -3,7 +3,7 @@
// compile-flags: -C target-feature=+neon
// needs-llvm-components: arm
-#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)]
+#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
diff --git a/src/test/assembly/asm/avr-types.rs b/src/test/assembly/asm/avr-types.rs
index 58bf1ad9e..b2d11a882 100644
--- a/src/test/assembly/asm/avr-types.rs
+++ b/src/test/assembly/asm/avr-types.rs
@@ -2,7 +2,7 @@
// compile-flags: --target avr-unknown-gnu-atmega328
// needs-llvm-components: avr
-#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch)]
+#![feature(no_core, lang_items, rustc_attrs, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(non_camel_case_types)]
diff --git a/src/test/assembly/asm/bpf-types.rs b/src/test/assembly/asm/bpf-types.rs
index f894644cc..e177b8d0d 100644
--- a/src/test/assembly/asm/bpf-types.rs
+++ b/src/test/assembly/asm/bpf-types.rs
@@ -2,7 +2,7 @@
// compile-flags: --target bpfel-unknown-none -C target_feature=+alu32
// needs-llvm-components: bpf
-#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
+#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
diff --git a/src/test/assembly/asm/global_asm.rs b/src/test/assembly/asm/global_asm.rs
index 4cf73b40f..0b361a7ed 100644
--- a/src/test/assembly/asm/global_asm.rs
+++ b/src/test/assembly/asm/global_asm.rs
@@ -4,7 +4,7 @@
// compile-flags: -C llvm-args=--x86-asm-syntax=intel
// compile-flags: -C symbol-mangling-version=v0
-#![feature(asm_const, asm_sym)]
+#![feature(asm_const)]
#![crate_type = "rlib"]
use std::arch::global_asm;
@@ -28,4 +28,6 @@ global_asm!("lea rax, [rip + {}]", sym MY_STATIC);
// CHECK: call _RNvCsiubXh4Yz005_10global_asm6foobar
global_asm!("call {}", sym foobar);
// CHECK: _RNvCsiubXh4Yz005_10global_asm6foobar:
-fn foobar() { loop {} }
+fn foobar() {
+ loop {}
+}
diff --git a/src/test/assembly/asm/hexagon-types.rs b/src/test/assembly/asm/hexagon-types.rs
index eff9a0bb4..af16faedb 100644
--- a/src/test/assembly/asm/hexagon-types.rs
+++ b/src/test/assembly/asm/hexagon-types.rs
@@ -2,7 +2,7 @@
// compile-flags: --target hexagon-unknown-linux-musl
// needs-llvm-components: hexagon
-#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
+#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
diff --git a/src/test/assembly/asm/mips-types.rs b/src/test/assembly/asm/mips-types.rs
index 04bf49a40..6aa28b062 100644
--- a/src/test/assembly/asm/mips-types.rs
+++ b/src/test/assembly/asm/mips-types.rs
@@ -5,7 +5,7 @@
//[mips64] compile-flags: --target mips64-unknown-linux-gnuabi64
//[mips64] needs-llvm-components: mips
-#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
+#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
diff --git a/src/test/assembly/asm/msp430-types.rs b/src/test/assembly/asm/msp430-types.rs
index 4fa2e8081..2c73b3b09 100644
--- a/src/test/assembly/asm/msp430-types.rs
+++ b/src/test/assembly/asm/msp430-types.rs
@@ -2,7 +2,7 @@
// compile-flags: --target msp430-none-elf
// needs-llvm-components: msp430
-#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch, asm_const)]
+#![feature(no_core, lang_items, rustc_attrs, asm_experimental_arch, asm_const)]
#![crate_type = "rlib"]
#![no_core]
#![allow(non_camel_case_types)]
diff --git a/src/test/assembly/asm/nvptx-types.rs b/src/test/assembly/asm/nvptx-types.rs
index 3ebd5b4b8..c319946b5 100644
--- a/src/test/assembly/asm/nvptx-types.rs
+++ b/src/test/assembly/asm/nvptx-types.rs
@@ -3,7 +3,7 @@
// compile-flags: --crate-type cdylib
// needs-llvm-components: nvptx
-#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch)]
+#![feature(no_core, lang_items, rustc_attrs, asm_experimental_arch)]
#![no_core]
#[rustc_builtin_macro]
diff --git a/src/test/assembly/asm/powerpc-types.rs b/src/test/assembly/asm/powerpc-types.rs
index 0ca890849..e27b00520 100644
--- a/src/test/assembly/asm/powerpc-types.rs
+++ b/src/test/assembly/asm/powerpc-types.rs
@@ -5,7 +5,7 @@
//[powerpc64] compile-flags: --target powerpc64-unknown-linux-gnu
//[powerpc64] needs-llvm-components: powerpc
-#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
+#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
diff --git a/src/test/assembly/asm/riscv-types.rs b/src/test/assembly/asm/riscv-types.rs
index 68dc186ea..f18ba294d 100644
--- a/src/test/assembly/asm/riscv-types.rs
+++ b/src/test/assembly/asm/riscv-types.rs
@@ -6,7 +6,7 @@
//[riscv32] needs-llvm-components: riscv
// compile-flags: -C target-feature=+d
-#![feature(no_core, lang_items, rustc_attrs, asm_sym)]
+#![feature(no_core, lang_items, rustc_attrs)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register)]
diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs
index 6a12902a0..2fb404dd9 100644
--- a/src/test/assembly/asm/s390x-types.rs
+++ b/src/test/assembly/asm/s390x-types.rs
@@ -3,7 +3,7 @@
//[s390x] compile-flags: --target s390x-unknown-linux-gnu
//[s390x] needs-llvm-components: systemz
-#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
+#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
diff --git a/src/test/assembly/asm/wasm-types.rs b/src/test/assembly/asm/wasm-types.rs
index 3aa128c46..3b1ac1b45 100644
--- a/src/test/assembly/asm/wasm-types.rs
+++ b/src/test/assembly/asm/wasm-types.rs
@@ -3,7 +3,7 @@
// compile-flags: --crate-type cdylib
// needs-llvm-components: webassembly
-#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch)]
+#![feature(no_core, lang_items, rustc_attrs, asm_experimental_arch)]
#![no_core]
#[rustc_builtin_macro]
diff --git a/src/test/assembly/asm/x86-types.rs b/src/test/assembly/asm/x86-types.rs
index e871535cf..81be79cba 100644
--- a/src/test/assembly/asm/x86-types.rs
+++ b/src/test/assembly/asm/x86-types.rs
@@ -7,7 +7,7 @@
// compile-flags: -C llvm-args=--x86-asm-syntax=intel
// compile-flags: -C target-feature=+avx512bw
-#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)]
+#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]
diff --git a/src/test/assembly/x86-stack-probes.rs b/src/test/assembly/x86-stack-probes.rs
new file mode 100644
index 000000000..c7141fb20
--- /dev/null
+++ b/src/test/assembly/x86-stack-probes.rs
@@ -0,0 +1,42 @@
+// min-llvm-version: 16
+// revisions: x86_64 i686
+// assembly-output: emit-asm
+//[x86_64] compile-flags: --target x86_64-unknown-linux-gnu
+//[x86_64] needs-llvm-components: x86
+//[i686] compile-flags: --target i686-unknown-linux-gnu
+//[i686] needs-llvm-components: x86
+// compile-flags: -C llvm-args=-x86-asm-syntax=intel
+
+#![feature(no_core, lang_items)]
+#![crate_type = "lib"]
+#![no_core]
+
+#[lang = "sized"]
+trait Sized {}
+#[lang = "copy"]
+trait Copy {}
+
+impl Copy for u8 {}
+
+// Check that inline-asm stack probes are generated correctly.
+// To avoid making this test fragile to slight asm changes,
+// we only check that the stack pointer is decremented by a page at a time,
+// instead of matching the whole probe sequence.
+
+// CHECK-LABEL: small_stack_probe:
+#[no_mangle]
+pub fn small_stack_probe(x: u8, f: fn(&mut [u8; 8192])) {
+ // CHECK-NOT: __rust_probestack
+ // x86_64: sub rsp, 4096
+ // i686: sub esp, 4096
+ f(&mut [x; 8192]);
+}
+
+// CHECK-LABEL: big_stack_probe:
+#[no_mangle]
+pub fn big_stack_probe(x: u8, f: fn(&[u8; 65536])) {
+ // CHECK-NOT: __rust_probestack
+ // x86_64: sub rsp, 4096
+ // i686: sub esp, 4096
+ f(&mut [x; 65536]);
+}
diff --git a/src/test/codegen-units/item-collection/asm-sym.rs b/src/test/codegen-units/item-collection/asm-sym.rs
new file mode 100644
index 000000000..8bafb95bc
--- /dev/null
+++ b/src/test/codegen-units/item-collection/asm-sym.rs
@@ -0,0 +1,20 @@
+// needs-asm-support
+// compile-flags: -Ccodegen-units=1 -Zprint-mono-items=lazy --crate-type=lib
+
+#[inline(always)]
+pub unsafe fn f() {
+ //~ MONO_ITEM static f::S @@ asm_sym-cgu.0[External]
+ static S: usize = 1;
+ //~ MONO_ITEM fn f::fun @@ asm_sym-cgu.0[External]
+ fn fun() {}
+ core::arch::asm!("/* {0} {1} */", sym S, sym fun);
+}
+
+//~ MONO_ITEM fn g @@ asm_sym-cgu.0[External]
+pub unsafe fn g() {
+ //~ MONO_ITEM static g::S @@ asm_sym-cgu.0[Internal]
+ static S: usize = 2;
+ //~ MONO_ITEM fn g::fun @@ asm_sym-cgu.0[Internal]
+ fn fun() {}
+ core::arch::asm!("/* {0} {1} */", sym S, sym fun);
+}
diff --git a/src/test/codegen-units/item-collection/generic-impl.rs b/src/test/codegen-units/item-collection/generic-impl.rs
index dd5367ef0..4260230c2 100644
--- a/src/test/codegen-units/item-collection/generic-impl.rs
+++ b/src/test/codegen-units/item-collection/generic-impl.rs
@@ -30,11 +30,11 @@ pub struct LifeTimeOnly<'a> {
impl<'a> LifeTimeOnly<'a> {
- //~ MONO_ITEM fn LifeTimeOnly::foo
+ //~ MONO_ITEM fn LifeTimeOnly::<'_>::foo
pub fn foo(&self) {}
- //~ MONO_ITEM fn LifeTimeOnly::bar
+ //~ MONO_ITEM fn LifeTimeOnly::<'_>::bar
pub fn bar(&'a self) {}
- //~ MONO_ITEM fn LifeTimeOnly::baz
+ //~ MONO_ITEM fn LifeTimeOnly::<'_>::baz
pub fn baz<'b>(&'b self) {}
pub fn non_instantiated<T>(&self) {}
diff --git a/src/test/codegen/abi-main-signature-32bit-c-int.rs b/src/test/codegen/abi-main-signature-32bit-c-int.rs
index 31b19a542..7f22ddcfc 100644
--- a/src/test/codegen/abi-main-signature-32bit-c-int.rs
+++ b/src/test/codegen/abi-main-signature-32bit-c-int.rs
@@ -7,4 +7,4 @@
fn main() {
}
-// CHECK: define i32 @main(i32{{( %0)?}}, {{i8\*\*|ptr}}{{( %1)?}})
+// CHECK: define{{( hidden)?}} i32 @main(i32{{( %0)?}}, {{i8\*\*|ptr}}{{( %1)?}})
diff --git a/src/test/codegen/binary-search-index-no-bound-check.rs b/src/test/codegen/binary-search-index-no-bound-check.rs
index 2deabcaa6..c1766a4a4 100644
--- a/src/test/codegen/binary-search-index-no-bound-check.rs
+++ b/src/test/codegen/binary-search-index-no-bound-check.rs
@@ -16,3 +16,23 @@ pub fn binary_search_index_no_bounds_check(s: &[u8]) -> u8 {
42
}
}
+
+// Similarly, check that `partition_point` is known to return a valid fencepost.
+
+// CHECK-LABEL: @unknown_split
+#[no_mangle]
+pub fn unknown_split(x: &[i32], i: usize) -> (&[i32], &[i32]) {
+ // This just makes sure that the subsequent function is looking for the
+ // absence of something that might actually be there.
+
+ // CHECK: call core::panicking::panic
+ x.split_at(i)
+}
+
+// CHECK-LABEL: @partition_point_split_no_bounds_check
+#[no_mangle]
+pub fn partition_point_split_no_bounds_check(x: &[i32], needle: i32) -> (&[i32], &[i32]) {
+ // CHECK-NOT: call core::panicking::panic
+ let i = x.partition_point(|p| p < &needle);
+ x.split_at(i)
+}
diff --git a/src/test/codegen/deduced-param-attrs.rs b/src/test/codegen/deduced-param-attrs.rs
new file mode 100644
index 000000000..153046eef
--- /dev/null
+++ b/src/test/codegen/deduced-param-attrs.rs
@@ -0,0 +1,60 @@
+// compile-flags: -O
+
+#![crate_type = "lib"]
+#![allow(incomplete_features)]
+#![feature(unsized_locals, unsized_fn_params)]
+
+use std::cell::Cell;
+use std::hint;
+
+// Check to make sure that we can deduce the `readonly` attribute from function bodies for
+// parameters passed indirectly.
+
+pub struct BigStruct {
+ blah: [i32; 1024],
+}
+
+pub struct BigCellContainer {
+ blah: [Cell<i32>; 1024],
+}
+
+// The by-value parameter for this big struct can be marked readonly.
+//
+// CHECK: @use_big_struct_immutably({{.*}} readonly {{.*}} %big_struct)
+#[no_mangle]
+pub fn use_big_struct_immutably(big_struct: BigStruct) {
+ hint::black_box(&big_struct);
+}
+
+// The by-value parameter for this big struct can't be marked readonly, because we mutate it.
+//
+// CHECK-NOT: @use_big_struct_mutably({{.*}} readonly {{.*}} %big_struct)
+#[no_mangle]
+pub fn use_big_struct_mutably(mut big_struct: BigStruct) {
+ big_struct.blah[987] = 654;
+ hint::black_box(&big_struct);
+}
+
+// The by-value parameter for this big struct can't be marked readonly, because it contains
+// UnsafeCell.
+//
+// CHECK-NOT: @use_big_cell_container({{.*}} readonly {{.*}} %big_cell_container)
+#[no_mangle]
+pub fn use_big_cell_container(big_cell_container: BigCellContainer) {
+ hint::black_box(&big_cell_container);
+}
+
+// Make sure that we don't mistakenly mark a big struct as `readonly` when passed through a generic
+// type parameter if it contains UnsafeCell.
+//
+// CHECK-NOT: @use_something({{.*}} readonly {{.*}} %something)
+#[no_mangle]
+#[inline(never)]
+pub fn use_something<T>(something: T) {
+ hint::black_box(&something);
+}
+
+#[no_mangle]
+pub fn forward_big_cell_container(big_cell_container: BigCellContainer) {
+ use_something(big_cell_container)
+}
diff --git a/src/test/codegen/function-arguments.rs b/src/test/codegen/function-arguments.rs
index bc650ebf5..44fee9523 100644
--- a/src/test/codegen/function-arguments.rs
+++ b/src/test/codegen/function-arguments.rs
@@ -127,7 +127,7 @@ pub fn mutable_notunpin_borrow(_: &mut NotUnpin) {
pub fn notunpin_borrow(_: &NotUnpin) {
}
-// CHECK: @indirect_struct({{%S\*|ptr}} noalias nocapture noundef dereferenceable(32) %_1)
+// CHECK: @indirect_struct({{%S\*|ptr}} noalias nocapture noundef readonly dereferenceable(32) %_1)
#[no_mangle]
pub fn indirect_struct(_: S) {
}
diff --git a/src/test/codegen/mem-replace-direct-memcpy.rs b/src/test/codegen/mem-replace-direct-memcpy.rs
index b41ef538d..4318e926e 100644
--- a/src/test/codegen/mem-replace-direct-memcpy.rs
+++ b/src/test/codegen/mem-replace-direct-memcpy.rs
@@ -4,6 +4,7 @@
// known to be `1` after inlining).
// compile-flags: -C no-prepopulate-passes -Zinline-mir=no
+// ignore-debug: the debug assertions get in the way
#![crate_type = "lib"]
diff --git a/src/test/codegen/sanitizer_scs_attr_check.rs b/src/test/codegen/sanitizer_scs_attr_check.rs
index 0b53db3b7..a885d9117 100644
--- a/src/test/codegen/sanitizer_scs_attr_check.rs
+++ b/src/test/codegen/sanitizer_scs_attr_check.rs
@@ -7,11 +7,11 @@
#![crate_type = "lib"]
#![feature(no_sanitize)]
-// CHECK: ; Function Attrs:{{.*}}shadowcallstack
-// CHECK-NEXT: scs
+// CHECK: ; sanitizer_scs_attr_check::scs
+// CHECK-NEXT: ; Function Attrs:{{.*}}shadowcallstack
pub fn scs() {}
+// CHECK: ; sanitizer_scs_attr_check::no_scs
// CHECK-NOT: ; Function Attrs:{{.*}}shadowcallstack
-// CHECK-NEXT: no_scs
#[no_sanitize(shadow_call_stack)]
pub fn no_scs() {}
diff --git a/src/test/codegen/slice-iter-len-eq-zero.rs b/src/test/codegen/slice-iter-len-eq-zero.rs
index fd19e624c..112402825 100644
--- a/src/test/codegen/slice-iter-len-eq-zero.rs
+++ b/src/test/codegen/slice-iter-len-eq-zero.rs
@@ -1,5 +1,6 @@
// no-system-llvm
// compile-flags: -O
+// ignore-debug: the debug assertions add extra comparisons
#![crate_type = "lib"]
type Demo = [u8; 3];
@@ -12,3 +13,16 @@ pub fn slice_iter_len_eq_zero(y: std::slice::Iter<'_, Demo>) -> bool {
// CHECK: ret i1 %2
y.len() == 0
}
+
+// CHECK-LABEL: @array_into_iter_len_eq_zero
+#[no_mangle]
+pub fn array_into_iter_len_eq_zero(y: std::array::IntoIter<Demo, 123>) -> bool {
+ // This should be able to just check that the indexes are equal, and not
+ // need any subtractions or comparisons to handle `start > end`.
+
+ // CHECK-NOT: icmp
+ // CHECK-NOT: sub
+ // CHECK: %1 = icmp eq {{i16|i32|i64}}
+ // CHECK: ret i1 %1
+ y.len() == 0
+}
diff --git a/src/test/codegen/slice_as_from_ptr_range.rs b/src/test/codegen/slice_as_from_ptr_range.rs
new file mode 100644
index 000000000..0e3fefd97
--- /dev/null
+++ b/src/test/codegen/slice_as_from_ptr_range.rs
@@ -0,0 +1,23 @@
+// compile-flags: -O
+// only-64bit (because we're using [ui]size)
+// ignore-debug (because the assertions get in the way)
+// min-llvm-version: 15.0 (because this is a relatively new instcombine)
+
+#![crate_type = "lib"]
+#![feature(slice_from_ptr_range)]
+
+// This is intentionally using a non-power-of-two array length,
+// as that's where the optimization differences show up
+
+// CHECK-LABEL: @flatten_via_ptr_range
+#[no_mangle]
+pub fn flatten_via_ptr_range(slice_of_arrays: &[[i32; 13]]) -> &[i32] {
+ // CHECK-NOT: lshr
+ // CHECK-NOT: udiv
+ // CHECK: mul nuw nsw i64 %{{.+}}, 13
+ // CHECK-NOT: lshr
+ // CHECK-NOT: udiv
+ let r = slice_of_arrays.as_ptr_range();
+ let r = r.start.cast()..r.end.cast();
+ unsafe { core::slice::from_ptr_range(r) }
+}
diff --git a/src/test/codegen/stack-probes-call.rs b/src/test/codegen/stack-probes-call.rs
new file mode 100644
index 000000000..a18fd41c2
--- /dev/null
+++ b/src/test/codegen/stack-probes-call.rs
@@ -0,0 +1,24 @@
+// Check the "probe-stack" attribute for targets with `StackProbeType::Call`,
+// or `StackProbeType::InlineOrCall` when running on older LLVM.
+
+// compile-flags: -C no-prepopulate-passes
+// revisions: i686 x86_64
+//[i686] compile-flags: --target i686-unknown-linux-gnu
+//[i686] needs-llvm-components: x86
+//[i686] ignore-llvm-version: 16 - 99
+//[x86_64] compile-flags: --target x86_64-unknown-linux-gnu
+//[x86_64] needs-llvm-components: x86
+//[x86_64] ignore-llvm-version: 16 - 99
+
+#![crate_type = "rlib"]
+#![feature(no_core, lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+trait Sized {}
+
+#[no_mangle]
+pub fn foo() {
+// CHECK: @foo() unnamed_addr #0
+// CHECK: attributes #0 = { {{.*}}"probe-stack"="__rust_probestack"{{.*}} }
+}
diff --git a/src/test/codegen/stack-probes-inline.rs b/src/test/codegen/stack-probes-inline.rs
new file mode 100644
index 000000000..a6b781de5
--- /dev/null
+++ b/src/test/codegen/stack-probes-inline.rs
@@ -0,0 +1,32 @@
+// Check the "probe-stack" attribute for targets with `StackProbeType::Inline`,
+// or `StackProbeType::InlineOrCall` when running on newer LLVM.
+
+// compile-flags: -C no-prepopulate-passes
+// revisions: powerpc powerpc64 powerpc64le s390x i686 x86_64
+//[powerpc] compile-flags: --target powerpc-unknown-linux-gnu
+//[powerpc] needs-llvm-components: powerpc
+//[powerpc64] compile-flags: --target powerpc64-unknown-linux-gnu
+//[powerpc64] needs-llvm-components: powerpc
+//[powerpc64le] compile-flags: --target powerpc64le-unknown-linux-gnu
+//[powerpc64le] needs-llvm-components: powerpc
+//[s390x] compile-flags: --target s390x-unknown-linux-gnu
+//[s390x] needs-llvm-components: systemz
+//[i686] compile-flags: --target i686-unknown-linux-gnu
+//[i686] needs-llvm-components: x86
+//[i686] min-llvm-version: 16
+//[x86_64] compile-flags: --target x86_64-unknown-linux-gnu
+//[x86_64] needs-llvm-components: x86
+//[x86_64] min-llvm-version: 16
+
+#![crate_type = "rlib"]
+#![feature(no_core, lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+trait Sized {}
+
+#[no_mangle]
+pub fn foo() {
+// CHECK: @foo() unnamed_addr #0
+// CHECK: attributes #0 = { {{.*}}"probe-stack"="inline-asm"{{.*}} }
+}
diff --git a/src/test/codegen/stack-probes.rs b/src/test/codegen/stack-probes.rs
deleted file mode 100644
index 9bd351df3..000000000
--- a/src/test/codegen/stack-probes.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-// ignore-arm
-// ignore-aarch64
-// ignore-mips
-// ignore-mips64
-// ignore-powerpc
-// ignore-powerpc64
-// ignore-powerpc64le
-// ignore-riscv64
-// ignore-s390x
-// ignore-sparc
-// ignore-sparc64
-// ignore-wasm
-// ignore-emscripten
-// ignore-windows
-// compile-flags: -C no-prepopulate-passes
-
-#![crate_type = "lib"]
-
-#[no_mangle]
-pub fn foo() {
-// CHECK: @foo() unnamed_addr #0
-}
diff --git a/src/test/codegen/vec-calloc.rs b/src/test/codegen/vec-calloc.rs
index 435a4ab51..ae6e448f1 100644
--- a/src/test/codegen/vec-calloc.rs
+++ b/src/test/codegen/vec-calloc.rs
@@ -1,4 +1,4 @@
-// compile-flags: -O
+// compile-flags: -O -Z merge-functions=disabled
// only-x86_64
// ignore-debug
// min-llvm-version: 15.0
@@ -144,6 +144,23 @@ pub fn vec_non_zero_tuple(n: usize) -> Vec<(i16, u8, char)> {
vec![(0, 0, 'A'); n]
}
+// CHECK-LABEL: @vec_option_bool
+#[no_mangle]
+pub fn vec_option_bool(n: usize) -> Vec<Option<bool>> {
+ // CHECK-NOT: call {{.*}}alloc::vec::from_elem
+ // CHECK-NOT: call {{.*}}reserve
+ // CHECK-NOT: call {{.*}}__rust_alloc(
+
+ // CHECK: call {{.*}}__rust_alloc_zeroed(
+
+ // CHECK-NOT: call {{.*}}alloc::vec::from_elem
+ // CHECK-NOT: call {{.*}}reserve
+ // CHECK-NOT: call {{.*}}__rust_alloc(
+
+ // CHECK: ret void
+ vec![Some(false); n]
+}
+
// Ensure that __rust_alloc_zeroed gets the right attributes for LLVM to optimize it away.
// CHECK: declare noalias ptr @__rust_alloc_zeroed(i64, i64 allocalign) unnamed_addr [[RUST_ALLOC_ZEROED_ATTRS:#[0-9]+]]
diff --git a/src/test/codegen/vec-in-place.rs b/src/test/codegen/vec-in-place.rs
index 62139aa9b..5df366905 100644
--- a/src/test/codegen/vec-in-place.rs
+++ b/src/test/codegen/vec-in-place.rs
@@ -17,7 +17,7 @@ pub struct Foo {
// Going from an aggregate struct to another type currently requires Copy to
// enable the TrustedRandomAccess specialization. Without it optimizations do not yet
-// reliably recognize the loops as noop for for repr(C) or non-Copy structs.
+// reliably recognize the loops as noop for repr(C) or non-Copy structs.
#[derive(Copy, Clone)]
pub struct Bar {
a: u64,
diff --git a/src/test/incremental/hashes/function_interfaces.rs b/src/test/incremental/hashes/function_interfaces.rs
index 076eddaab..3ff949fbb 100644
--- a/src/test/incremental/hashes/function_interfaces.rs
+++ b/src/test/incremental/hashes/function_interfaces.rs
@@ -323,7 +323,7 @@ pub fn change_return_impl_trait() -> impl Clone {
#[cfg(not(any(cfail1,cfail4)))]
#[rustc_clean(cfg = "cfail2")]
#[rustc_clean(cfg = "cfail3")]
-#[rustc_clean(cfg = "cfail5")]
+#[rustc_clean(cfg = "cfail5", except = "typeck")]
#[rustc_clean(cfg = "cfail6")]
pub fn change_return_impl_trait() -> impl Copy {
0u32
diff --git a/src/test/incremental/issue-61323.rs b/src/test/incremental/issue-61323.rs
index 97cbfe408..7ce47947c 100644
--- a/src/test/incremental/issue-61323.rs
+++ b/src/test/incremental/issue-61323.rs
@@ -1,7 +1,7 @@
// revisions: rpass cfail
enum A {
- //[cfail]~^ ERROR 3:1: 3:7: recursive type `A` has infinite size [E0072]
+ //[cfail]~^ ERROR 3:1: 3:7: recursive types `A` and `C` have infinite size [E0072]
B(C),
}
@@ -10,6 +10,5 @@ struct C(Box<A>);
#[cfg(cfail)]
struct C(A);
-//[cfail]~^ ERROR 12:1: 12:9: recursive type `C` has infinite size [E0072]
fn main() {}
diff --git a/src/test/incremental/spans_significant_w_panic.rs b/src/test/incremental/spans_significant_w_panic.rs
index e9e35791a..6f51c9729 100644
--- a/src/test/incremental/spans_significant_w_panic.rs
+++ b/src/test/incremental/spans_significant_w_panic.rs
@@ -8,7 +8,6 @@
// compile-flags: -C overflow-checks=on -Z query-dep-graph
#![feature(rustc_attrs)]
-#![feature(bench_black_box)]
#![rustc_partition_codegened(module = "spans_significant_w_panic", cfg = "rpass2")]
#![rustc_partition_codegened(module = "spans_significant_w_panic", cfg = "rpass4")]
diff --git a/src/test/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstCombine.diff b/src/test/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstCombine.diff
index bde2f04fa..6f01553ee 100644
--- a/src/test/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstCombine.diff
+++ b/src/test/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstCombine.diff
@@ -24,7 +24,7 @@
_2 = <T as Clone>::clone(move _3) -> bb1; // scope 0 at $DIR/combine_clone_of_primitives.rs:8:5: 8:9
// mir::Constant
// + span: $DIR/combine_clone_of_primitives.rs:8:5: 8:9
- // + literal: Const { ty: for<'r> fn(&'r T) -> T {<T as Clone>::clone}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a T) -> T {<T as Clone>::clone}, val: Value(<ZST>) }
}
bb1: {
@@ -37,7 +37,7 @@
- _5 = <u64 as Clone>::clone(move _6) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
- // mir::Constant
- // + span: $DIR/combine_clone_of_primitives.rs:9:5: 9:11
-- // + literal: Const { ty: for<'r> fn(&'r u64) -> u64 {<u64 as Clone>::clone}, val: Value(<ZST>) }
+- // + literal: Const { ty: for<'a> fn(&'a u64) -> u64 {<u64 as Clone>::clone}, val: Value(<ZST>) }
+ _6 = _7; // scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
+ _5 = (*_6); // scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
+ goto -> bb2; // scope 0 at $DIR/combine_clone_of_primitives.rs:9:5: 9:11
@@ -53,7 +53,7 @@
- _8 = <[f32; 3] as Clone>::clone(move _9) -> [return: bb3, unwind: bb4]; // scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
- // mir::Constant
- // + span: $DIR/combine_clone_of_primitives.rs:10:5: 10:16
-- // + literal: Const { ty: for<'r> fn(&'r [f32; 3]) -> [f32; 3] {<[f32; 3] as Clone>::clone}, val: Value(<ZST>) }
+- // + literal: Const { ty: for<'a> fn(&'a [f32; 3]) -> [f32; 3] {<[f32; 3] as Clone>::clone}, val: Value(<ZST>) }
+ _9 = _10; // scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
+ _8 = (*_9); // scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
+ goto -> bb3; // scope 0 at $DIR/combine_clone_of_primitives.rs:10:5: 10:16
diff --git a/src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff b/src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff
index 248abb8fd..f8a7c687e 100644
--- a/src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff
+++ b/src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff
@@ -33,7 +33,7 @@
_0 = core::slice::<impl [&i32]>::as_ptr(move _1) -> [return: bb1, unwind: bb2]; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:31: +0:44
// mir::Constant
// + span: $DIR/const-promotion-extern-static.rs:9:36: 9:42
- // + literal: Const { ty: for<'r> fn(&'r [&i32]) -> *const &i32 {core::slice::<impl [&i32]>::as_ptr}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a [&i32]) -> *const &i32 {core::slice::<impl [&i32]>::as_ptr}, val: Value(<ZST>) }
}
bb1: {
diff --git a/src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff b/src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff
index 8ce895fe7..e938ca28a 100644
--- a/src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff
+++ b/src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff
@@ -35,7 +35,7 @@
_0 = core::slice::<impl [&i32]>::as_ptr(move _1) -> [return: bb1, unwind: bb2]; // scope 0 at $DIR/const-promotion-extern-static.rs:+0:31: +0:55
// mir::Constant
// + span: $DIR/const-promotion-extern-static.rs:13:47: 13:53
- // + literal: Const { ty: for<'r> fn(&'r [&i32]) -> *const &i32 {core::slice::<impl [&i32]>::as_ptr}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a [&i32]) -> *const &i32 {core::slice::<impl [&i32]>::as_ptr}, val: Value(<ZST>) }
}
bb1: {
diff --git a/src/test/mir-opt/const_prop/cast.main.ConstProp.diff b/src/test/mir-opt/const_prop/cast.main.ConstProp.diff
index e040a4b3a..1d4dfc29f 100644
--- a/src/test/mir-opt/const_prop/cast.main.ConstProp.diff
+++ b/src/test/mir-opt/const_prop/cast.main.ConstProp.diff
@@ -14,10 +14,10 @@
bb0: {
StorageLive(_1); // scope 0 at $DIR/cast.rs:+1:9: +1:10
-- _1 = const 42_u8 as u32 (Misc); // scope 0 at $DIR/cast.rs:+1:13: +1:24
+- _1 = const 42_u8 as u32 (IntToInt); // scope 0 at $DIR/cast.rs:+1:13: +1:24
+ _1 = const 42_u32; // scope 0 at $DIR/cast.rs:+1:13: +1:24
StorageLive(_2); // scope 1 at $DIR/cast.rs:+3:9: +3:10
-- _2 = const 42_u32 as u8 (Misc); // scope 1 at $DIR/cast.rs:+3:13: +3:24
+- _2 = const 42_u32 as u8 (IntToInt); // scope 1 at $DIR/cast.rs:+3:13: +3:24
+ _2 = const 42_u8; // scope 1 at $DIR/cast.rs:+3:13: +3:24
_0 = const (); // scope 0 at $DIR/cast.rs:+0:11: +4:2
StorageDead(_2); // scope 1 at $DIR/cast.rs:+4:1: +4:2
diff --git a/src/test/mir-opt/const_prop/indirect.main.ConstProp.diff b/src/test/mir-opt/const_prop/indirect.main.ConstProp.diff
index 948bb7f56..f4c0c5c5e 100644
--- a/src/test/mir-opt/const_prop/indirect.main.ConstProp.diff
+++ b/src/test/mir-opt/const_prop/indirect.main.ConstProp.diff
@@ -13,7 +13,7 @@
bb0: {
StorageLive(_1); // scope 0 at $DIR/indirect.rs:+1:9: +1:10
StorageLive(_2); // scope 0 at $DIR/indirect.rs:+1:13: +1:25
-- _2 = const 2_u32 as u8 (Misc); // scope 0 at $DIR/indirect.rs:+1:13: +1:25
+- _2 = const 2_u32 as u8 (IntToInt); // scope 0 at $DIR/indirect.rs:+1:13: +1:25
- _3 = CheckedAdd(_2, const 1_u8); // scope 0 at $DIR/indirect.rs:+1:13: +1:29
- assert(!move (_3.1: bool), "attempt to compute `{} + {}`, which would overflow", move _2, const 1_u8) -> bb1; // scope 0 at $DIR/indirect.rs:+1:13: +1:29
+ _2 = const 2_u8; // scope 0 at $DIR/indirect.rs:+1:13: +1:25
diff --git a/src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff b/src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff
index 53f977de5..995611f0e 100644
--- a/src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff
+++ b/src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff
@@ -20,7 +20,7 @@
_2 = core::str::<impl str>::as_bytes(move _3) -> bb1; // scope 0 at $DIR/deduplicate_blocks.rs:+1:11: +1:23
// mir::Constant
// + span: $DIR/deduplicate_blocks.rs:5:13: 5:21
- // + literal: Const { ty: for<'r> fn(&'r str) -> &'r [u8] {core::str::<impl str>::as_bytes}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a str) -> &'a [u8] {core::str::<impl str>::as_bytes}, val: Value(<ZST>) }
}
bb1: {
diff --git a/src/test/mir-opt/derefer_complex_case.main.Derefer.diff b/src/test/mir-opt/derefer_complex_case.main.Derefer.diff
index c353c375a..713d56c38 100644
--- a/src/test/mir-opt/derefer_complex_case.main.Derefer.diff
+++ b/src/test/mir-opt/derefer_complex_case.main.Derefer.diff
@@ -3,15 +3,15 @@
fn main() -> () {
let mut _0: (); // return place in scope 0 at $DIR/derefer_complex_case.rs:+0:11: +0:11
- let mut _1: std::slice::Iter<i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
+ let mut _1: std::slice::Iter<'_, i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
let mut _2: &[i32; 2]; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
let _3: [i32; 2]; // in scope 0 at $DIR/derefer_complex_case.rs:+1:18: +1:26
- let mut _4: std::slice::Iter<i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
+ let mut _4: std::slice::Iter<'_, i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
let mut _5: (); // in scope 0 at $DIR/derefer_complex_case.rs:+0:1: +2:2
let _6: (); // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
let mut _7: std::option::Option<&i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
- let mut _8: &mut std::slice::Iter<i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
- let mut _9: &mut std::slice::Iter<i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
+ let mut _8: &mut std::slice::Iter<'_, i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
+ let mut _9: &mut std::slice::Iter<'_, i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
let mut _10: isize; // in scope 0 at $DIR/derefer_complex_case.rs:+1:5: +1:40
let mut _11: !; // in scope 0 at $DIR/derefer_complex_case.rs:+1:5: +1:40
let mut _13: i32; // in scope 0 at $DIR/derefer_complex_case.rs:+1:34: +1:37
@@ -53,10 +53,10 @@
StorageLive(_9); // scope 1 at $DIR/derefer_complex_case.rs:+1:17: +1:26
_9 = &mut _4; // scope 1 at $DIR/derefer_complex_case.rs:+1:17: +1:26
_8 = &mut (*_9); // scope 1 at $DIR/derefer_complex_case.rs:+1:17: +1:26
- _7 = <std::slice::Iter<i32> as Iterator>::next(move _8) -> bb3; // scope 1 at $DIR/derefer_complex_case.rs:+1:17: +1:26
+ _7 = <std::slice::Iter<'_, i32> as Iterator>::next(move _8) -> bb3; // scope 1 at $DIR/derefer_complex_case.rs:+1:17: +1:26
// mir::Constant
// + span: $DIR/derefer_complex_case.rs:6:17: 6:26
- // + literal: Const { ty: for<'r> fn(&'r mut std::slice::Iter<i32>) -> Option<<std::slice::Iter<i32> as Iterator>::Item> {<std::slice::Iter<i32> as Iterator>::next}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a mut std::slice::Iter<'_, i32>) -> Option<<std::slice::Iter<'_, i32> as Iterator>::Item> {<std::slice::Iter<'_, i32> as Iterator>::next}, val: Value(<ZST>) }
}
bb3: {
diff --git a/src/test/mir-opt/dest-prop/simple.nrvo.DestinationPropagation.diff b/src/test/mir-opt/dest-prop/simple.nrvo.DestinationPropagation.diff
index a20a172af..80b09ed5f 100644
--- a/src/test/mir-opt/dest-prop/simple.nrvo.DestinationPropagation.diff
+++ b/src/test/mir-opt/dest-prop/simple.nrvo.DestinationPropagation.diff
@@ -1,12 +1,12 @@
- // MIR for `nrvo` before DestinationPropagation
+ // MIR for `nrvo` after DestinationPropagation
- fn nrvo(_1: for<'r> fn(&'r mut [u8; 1024])) -> [u8; 1024] {
+ fn nrvo(_1: for<'a> fn(&'a mut [u8; 1024])) -> [u8; 1024] {
debug init => _1; // in scope 0 at $DIR/simple.rs:+0:9: +0:13
let mut _0: [u8; 1024]; // return place in scope 0 at $DIR/simple.rs:+0:39: +0:49
let mut _2: [u8; 1024]; // in scope 0 at $DIR/simple.rs:+1:9: +1:16
let _3: (); // in scope 0 at $DIR/simple.rs:+2:5: +2:19
- let mut _4: for<'r> fn(&'r mut [u8; 1024]); // in scope 0 at $DIR/simple.rs:+2:5: +2:9
+ let mut _4: for<'a> fn(&'a mut [u8; 1024]); // in scope 0 at $DIR/simple.rs:+2:5: +2:9
let mut _5: &mut [u8; 1024]; // in scope 0 at $DIR/simple.rs:+2:10: +2:18
let mut _6: &mut [u8; 1024]; // in scope 0 at $DIR/simple.rs:+2:10: +2:18
scope 1 {
diff --git a/src/test/mir-opt/early_otherwise_branch_soundness.no_downcast.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_soundness.no_downcast.EarlyOtherwiseBranch.diff
index 9e089b01b..659aed18f 100644
--- a/src/test/mir-opt/early_otherwise_branch_soundness.no_downcast.EarlyOtherwiseBranch.diff
+++ b/src/test/mir-opt/early_otherwise_branch_soundness.no_downcast.EarlyOtherwiseBranch.diff
@@ -1,12 +1,12 @@
- // MIR for `no_downcast` before EarlyOtherwiseBranch
+ // MIR for `no_downcast` after EarlyOtherwiseBranch
- fn no_downcast(_1: &E) -> u32 {
+ fn no_downcast(_1: &E<'_>) -> u32 {
debug e => _1; // in scope 0 at $DIR/early_otherwise_branch_soundness.rs:+0:16: +0:17
let mut _0: u32; // return place in scope 0 at $DIR/early_otherwise_branch_soundness.rs:+0:26: +0:29
let mut _2: isize; // in scope 0 at $DIR/early_otherwise_branch_soundness.rs:+1:20: +1:30
let mut _3: isize; // in scope 0 at $DIR/early_otherwise_branch_soundness.rs:+1:12: +1:31
- let mut _4: &E; // in scope 0 at $DIR/early_otherwise_branch_soundness.rs:+0:16: +0:17
+ let mut _4: &E<'_>; // in scope 0 at $DIR/early_otherwise_branch_soundness.rs:+0:16: +0:17
scope 1 {
}
@@ -16,7 +16,7 @@
}
bb1: {
- _4 = deref_copy (((*_1) as Some).0: &E); // scope 1 at $DIR/early_otherwise_branch_soundness.rs:+1:12: +1:31
+ _4 = deref_copy (((*_1) as Some).0: &E<'_>); // scope 1 at $DIR/early_otherwise_branch_soundness.rs:+1:12: +1:31
_2 = discriminant((*_4)); // scope 1 at $DIR/early_otherwise_branch_soundness.rs:+1:12: +1:31
switchInt(move _2) -> [1_isize: bb2, otherwise: bb3]; // scope 1 at $DIR/early_otherwise_branch_soundness.rs:+1:12: +1:31
}
diff --git a/src/test/mir-opt/enum_cast.bar.mir_map.0.mir b/src/test/mir-opt/enum_cast.bar.mir_map.0.mir
index 59ec80915..e58085f70 100644
--- a/src/test/mir-opt/enum_cast.bar.mir_map.0.mir
+++ b/src/test/mir-opt/enum_cast.bar.mir_map.0.mir
@@ -10,7 +10,7 @@ fn bar(_1: Bar) -> usize {
StorageLive(_2); // scope 0 at $DIR/enum_cast.rs:+1:5: +1:8
_2 = move _1; // scope 0 at $DIR/enum_cast.rs:+1:5: +1:8
_3 = discriminant(_2); // scope 0 at $DIR/enum_cast.rs:+1:5: +1:17
- _0 = move _3 as usize (Misc); // scope 0 at $DIR/enum_cast.rs:+1:5: +1:17
+ _0 = move _3 as usize (IntToInt); // scope 0 at $DIR/enum_cast.rs:+1:5: +1:17
StorageDead(_2); // scope 0 at $DIR/enum_cast.rs:+1:16: +1:17
return; // scope 0 at $DIR/enum_cast.rs:+2:2: +2:2
}
diff --git a/src/test/mir-opt/enum_cast.boo.mir_map.0.mir b/src/test/mir-opt/enum_cast.boo.mir_map.0.mir
index f6903c1ec..525c6234e 100644
--- a/src/test/mir-opt/enum_cast.boo.mir_map.0.mir
+++ b/src/test/mir-opt/enum_cast.boo.mir_map.0.mir
@@ -10,7 +10,7 @@ fn boo(_1: Boo) -> usize {
StorageLive(_2); // scope 0 at $DIR/enum_cast.rs:+1:5: +1:8
_2 = move _1; // scope 0 at $DIR/enum_cast.rs:+1:5: +1:8
_3 = discriminant(_2); // scope 0 at $DIR/enum_cast.rs:+1:5: +1:17
- _0 = move _3 as usize (Misc); // scope 0 at $DIR/enum_cast.rs:+1:5: +1:17
+ _0 = move _3 as usize (IntToInt); // scope 0 at $DIR/enum_cast.rs:+1:5: +1:17
StorageDead(_2); // scope 0 at $DIR/enum_cast.rs:+1:16: +1:17
return; // scope 0 at $DIR/enum_cast.rs:+2:2: +2:2
}
diff --git a/src/test/mir-opt/enum_cast.droppy.mir_map.0.mir b/src/test/mir-opt/enum_cast.droppy.mir_map.0.mir
index 98e1f8e11..bb5faa480 100644
--- a/src/test/mir-opt/enum_cast.droppy.mir_map.0.mir
+++ b/src/test/mir-opt/enum_cast.droppy.mir_map.0.mir
@@ -29,7 +29,7 @@ fn droppy() -> () {
StorageLive(_4); // scope 3 at $DIR/enum_cast.rs:+5:17: +5:18
_4 = move _2; // scope 3 at $DIR/enum_cast.rs:+5:17: +5:18
_5 = discriminant(_4); // scope 3 at $DIR/enum_cast.rs:+5:17: +5:27
- _3 = move _5 as usize (Misc); // scope 3 at $DIR/enum_cast.rs:+5:17: +5:27
+ _3 = move _5 as usize (IntToInt); // scope 3 at $DIR/enum_cast.rs:+5:17: +5:27
drop(_4) -> [return: bb1, unwind: bb4]; // scope 3 at $DIR/enum_cast.rs:+5:26: +5:27
}
diff --git a/src/test/mir-opt/enum_cast.foo.mir_map.0.mir b/src/test/mir-opt/enum_cast.foo.mir_map.0.mir
index aaa2d2646..a1d29a0b9 100644
--- a/src/test/mir-opt/enum_cast.foo.mir_map.0.mir
+++ b/src/test/mir-opt/enum_cast.foo.mir_map.0.mir
@@ -10,7 +10,7 @@ fn foo(_1: Foo) -> usize {
StorageLive(_2); // scope 0 at $DIR/enum_cast.rs:+1:5: +1:8
_2 = move _1; // scope 0 at $DIR/enum_cast.rs:+1:5: +1:8
_3 = discriminant(_2); // scope 0 at $DIR/enum_cast.rs:+1:5: +1:17
- _0 = move _3 as usize (Misc); // scope 0 at $DIR/enum_cast.rs:+1:5: +1:17
+ _0 = move _3 as usize (IntToInt); // scope 0 at $DIR/enum_cast.rs:+1:5: +1:17
StorageDead(_2); // scope 0 at $DIR/enum_cast.rs:+1:16: +1:17
return; // scope 0 at $DIR/enum_cast.rs:+2:2: +2:2
}
diff --git a/src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff b/src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff
index dca36b1a7..6ab63e82e 100644
--- a/src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff
+++ b/src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff
@@ -1,24 +1,24 @@
- // MIR for `float_to_exponential_common` before ConstProp
+ // MIR for `float_to_exponential_common` after ConstProp
- fn float_to_exponential_common(_1: &mut Formatter, _2: &T, _3: bool) -> Result<(), std::fmt::Error> {
+ fn float_to_exponential_common(_1: &mut Formatter<'_>, _2: &T, _3: bool) -> Result<(), std::fmt::Error> {
debug fmt => _1; // in scope 0 at $DIR/funky_arms.rs:+0:35: +0:38
debug num => _2; // in scope 0 at $DIR/funky_arms.rs:+0:60: +0:63
debug upper => _3; // in scope 0 at $DIR/funky_arms.rs:+0:69: +0:74
let mut _0: std::result::Result<(), std::fmt::Error>; // return place in scope 0 at $DIR/funky_arms.rs:+0:85: +0:91
let _4: bool; // in scope 0 at $DIR/funky_arms.rs:+4:9: +4:19
- let mut _5: &std::fmt::Formatter; // in scope 0 at $DIR/funky_arms.rs:+4:22: +4:37
+ let mut _5: &std::fmt::Formatter<'_>; // in scope 0 at $DIR/funky_arms.rs:+4:22: +4:37
let mut _7: std::option::Option<usize>; // in scope 0 at $DIR/funky_arms.rs:+13:30: +13:45
- let mut _8: &std::fmt::Formatter; // in scope 0 at $DIR/funky_arms.rs:+13:30: +13:45
+ let mut _8: &std::fmt::Formatter<'_>; // in scope 0 at $DIR/funky_arms.rs:+13:30: +13:45
let mut _9: isize; // in scope 0 at $DIR/funky_arms.rs:+13:12: +13:27
- let mut _11: &mut std::fmt::Formatter; // in scope 0 at $DIR/funky_arms.rs:+15:43: +15:46
+ let mut _11: &mut std::fmt::Formatter<'_>; // in scope 0 at $DIR/funky_arms.rs:+15:43: +15:46
let mut _12: &T; // in scope 0 at $DIR/funky_arms.rs:+15:48: +15:51
let mut _13: core::num::flt2dec::Sign; // in scope 0 at $DIR/funky_arms.rs:+15:53: +15:57
let mut _14: u32; // in scope 0 at $DIR/funky_arms.rs:+15:59: +15:79
let mut _15: u32; // in scope 0 at $DIR/funky_arms.rs:+15:59: +15:75
let mut _16: usize; // in scope 0 at $DIR/funky_arms.rs:+15:59: +15:68
let mut _17: bool; // in scope 0 at $DIR/funky_arms.rs:+15:81: +15:86
- let mut _18: &mut std::fmt::Formatter; // in scope 0 at $DIR/funky_arms.rs:+17:46: +17:49
+ let mut _18: &mut std::fmt::Formatter<'_>; // in scope 0 at $DIR/funky_arms.rs:+17:46: +17:49
let mut _19: &T; // in scope 0 at $DIR/funky_arms.rs:+17:51: +17:54
let mut _20: core::num::flt2dec::Sign; // in scope 0 at $DIR/funky_arms.rs:+17:56: +17:60
let mut _21: bool; // in scope 0 at $DIR/funky_arms.rs:+17:62: +17:67
@@ -38,10 +38,10 @@
StorageLive(_4); // scope 0 at $DIR/funky_arms.rs:+4:9: +4:19
StorageLive(_5); // scope 0 at $DIR/funky_arms.rs:+4:22: +4:37
_5 = &(*_1); // scope 0 at $DIR/funky_arms.rs:+4:22: +4:37
- _4 = Formatter::sign_plus(move _5) -> bb1; // scope 0 at $DIR/funky_arms.rs:+4:22: +4:37
+ _4 = Formatter::<'_>::sign_plus(move _5) -> bb1; // scope 0 at $DIR/funky_arms.rs:+4:22: +4:37
// mir::Constant
// + span: $DIR/funky_arms.rs:15:26: 15:35
- // + literal: Const { ty: for<'r> fn(&'r Formatter) -> bool {Formatter::sign_plus}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a Formatter<'_>) -> bool {Formatter::<'_>::sign_plus}, val: Value(<ZST>) }
}
bb1: {
@@ -66,10 +66,10 @@
StorageLive(_7); // scope 3 at $DIR/funky_arms.rs:+13:30: +13:45
StorageLive(_8); // scope 3 at $DIR/funky_arms.rs:+13:30: +13:45
_8 = &(*_1); // scope 3 at $DIR/funky_arms.rs:+13:30: +13:45
- _7 = Formatter::precision(move _8) -> bb5; // scope 3 at $DIR/funky_arms.rs:+13:30: +13:45
+ _7 = Formatter::<'_>::precision(move _8) -> bb5; // scope 3 at $DIR/funky_arms.rs:+13:30: +13:45
// mir::Constant
// + span: $DIR/funky_arms.rs:24:34: 24:43
- // + literal: Const { ty: for<'r> fn(&'r Formatter) -> Option<usize> {Formatter::precision}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a Formatter<'_>) -> Option<usize> {Formatter::<'_>::precision}, val: Value(<ZST>) }
}
bb5: {
@@ -91,7 +91,7 @@
StorageLive(_15); // scope 3 at $DIR/funky_arms.rs:+15:59: +15:75
StorageLive(_16); // scope 3 at $DIR/funky_arms.rs:+15:59: +15:68
_16 = _10; // scope 3 at $DIR/funky_arms.rs:+15:59: +15:68
- _15 = move _16 as u32 (Misc); // scope 3 at $DIR/funky_arms.rs:+15:59: +15:75
+ _15 = move _16 as u32 (IntToInt); // scope 3 at $DIR/funky_arms.rs:+15:59: +15:75
StorageDead(_16); // scope 3 at $DIR/funky_arms.rs:+15:74: +15:75
_14 = Add(move _15, const 1_u32); // scope 3 at $DIR/funky_arms.rs:+15:59: +15:79
StorageDead(_15); // scope 3 at $DIR/funky_arms.rs:+15:78: +15:79
@@ -100,7 +100,7 @@
_0 = float_to_exponential_common_exact::<T>(move _11, move _12, move _13, move _14, move _17) -> bb7; // scope 3 at $DIR/funky_arms.rs:+15:9: +15:87
// mir::Constant
// + span: $DIR/funky_arms.rs:26:9: 26:42
- // + literal: Const { ty: for<'r, 's, 't0> fn(&'r mut Formatter<'s>, &'t0 T, Sign, u32, bool) -> Result<(), std::fmt::Error> {float_to_exponential_common_exact::<T>}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a, 'b, 'c> fn(&'a mut Formatter<'b>, &'c T, Sign, u32, bool) -> Result<(), std::fmt::Error> {float_to_exponential_common_exact::<T>}, val: Value(<ZST>) }
}
bb7: {
@@ -125,7 +125,7 @@
_0 = float_to_exponential_common_shortest::<T>(move _18, move _19, move _20, move _21) -> bb9; // scope 2 at $DIR/funky_arms.rs:+17:9: +17:68
// mir::Constant
// + span: $DIR/funky_arms.rs:28:9: 28:45
- // + literal: Const { ty: for<'r, 's, 't0> fn(&'r mut Formatter<'s>, &'t0 T, Sign, bool) -> Result<(), std::fmt::Error> {float_to_exponential_common_shortest::<T>}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a, 'b, 'c> fn(&'a mut Formatter<'b>, &'c T, Sign, bool) -> Result<(), std::fmt::Error> {float_to_exponential_common_shortest::<T>}, val: Value(<ZST>) }
}
bb9: {
diff --git a/src/test/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff b/src/test/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff
index 3f612e03f..ed53c9a95 100644
--- a/src/test/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff
+++ b/src/test/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff
@@ -31,7 +31,7 @@
StorageLive(_6); // scope 1 at $DIR/if-condition-int.rs:+4:23: +4:31
StorageLive(_7); // scope 1 at $DIR/if-condition-int.rs:+4:23: +4:24
_7 = _2; // scope 1 at $DIR/if-condition-int.rs:+4:23: +4:24
- _6 = move _7 as i32 (Misc); // scope 1 at $DIR/if-condition-int.rs:+4:23: +4:31
+ _6 = move _7 as i32 (IntToInt); // scope 1 at $DIR/if-condition-int.rs:+4:23: +4:31
StorageDead(_7); // scope 1 at $DIR/if-condition-int.rs:+4:30: +4:31
_0 = Add(const 100_i32, move _6); // scope 1 at $DIR/if-condition-int.rs:+4:17: +4:31
StorageDead(_6); // scope 1 at $DIR/if-condition-int.rs:+4:30: +4:31
@@ -43,7 +43,7 @@
StorageLive(_4); // scope 1 at $DIR/if-condition-int.rs:+3:23: +3:31
StorageLive(_5); // scope 1 at $DIR/if-condition-int.rs:+3:23: +3:24
_5 = _2; // scope 1 at $DIR/if-condition-int.rs:+3:23: +3:24
- _4 = move _5 as i32 (Misc); // scope 1 at $DIR/if-condition-int.rs:+3:23: +3:31
+ _4 = move _5 as i32 (IntToInt); // scope 1 at $DIR/if-condition-int.rs:+3:23: +3:31
StorageDead(_5); // scope 1 at $DIR/if-condition-int.rs:+3:30: +3:31
_0 = Add(const 10_i32, move _4); // scope 1 at $DIR/if-condition-int.rs:+3:18: +3:31
StorageDead(_4); // scope 1 at $DIR/if-condition-int.rs:+3:30: +3:31
diff --git a/src/test/mir-opt/inline/asm-unwind.rs b/src/test/mir-opt/inline/asm-unwind.rs
new file mode 100644
index 000000000..c03feb433
--- /dev/null
+++ b/src/test/mir-opt/inline/asm-unwind.rs
@@ -0,0 +1,22 @@
+// Tests inlining of `may_unwind` inline assembly.
+//
+// ignore-wasm32-bare compiled with panic=abort by default
+// needs-asm-support
+#![feature(asm_unwind)]
+
+struct D;
+
+impl Drop for D {
+ fn drop(&mut self) {}
+}
+
+#[inline(always)]
+fn foo() {
+ let _d = D;
+ unsafe { std::arch::asm!("", options(may_unwind)) };
+}
+
+// EMIT_MIR asm_unwind.main.Inline.diff
+pub fn main() {
+ foo();
+}
diff --git a/src/test/mir-opt/inline/asm_unwind.main.Inline.diff b/src/test/mir-opt/inline/asm_unwind.main.Inline.diff
new file mode 100644
index 000000000..57072fc0a
--- /dev/null
+++ b/src/test/mir-opt/inline/asm_unwind.main.Inline.diff
@@ -0,0 +1,45 @@
+- // MIR for `main` before Inline
++ // MIR for `main` after Inline
+
+ fn main() -> () {
+ let mut _0: (); // return place in scope 0 at $DIR/asm-unwind.rs:+0:15: +0:15
+ let _1: (); // in scope 0 at $DIR/asm-unwind.rs:+1:5: +1:10
++ scope 1 (inlined foo) { // at $DIR/asm-unwind.rs:21:5: 21:10
++ let _2: D; // in scope 1 at $DIR/asm-unwind.rs:15:9: 15:11
++ scope 2 {
++ debug _d => _2; // in scope 2 at $DIR/asm-unwind.rs:15:9: 15:11
++ scope 3 {
++ }
++ }
++ }
+
+ bb0: {
+ StorageLive(_1); // scope 0 at $DIR/asm-unwind.rs:+1:5: +1:10
+- _1 = foo() -> bb1; // scope 0 at $DIR/asm-unwind.rs:+1:5: +1:10
+- // mir::Constant
+- // + span: $DIR/asm-unwind.rs:21:5: 21:8
+- // + literal: Const { ty: fn() {foo}, val: Value(<ZST>) }
++ StorageLive(_2); // scope 1 at $DIR/asm-unwind.rs:15:9: 15:11
++ asm!("", options(MAY_UNWIND)) -> [return: bb1, unwind: bb3]; // scope 3 at $DIR/asm-unwind.rs:16:14: 16:54
+ }
+
+ bb1: {
++ drop(_2) -> bb2; // scope 1 at $DIR/asm-unwind.rs:17:1: 17:2
++ }
++
++ bb2: {
++ StorageDead(_2); // scope 1 at $DIR/asm-unwind.rs:17:1: 17:2
+ StorageDead(_1); // scope 0 at $DIR/asm-unwind.rs:+1:10: +1:11
+ _0 = const (); // scope 0 at $DIR/asm-unwind.rs:+0:15: +2:2
+ return; // scope 0 at $DIR/asm-unwind.rs:+2:2: +2:2
++ }
++
++ bb3 (cleanup): {
++ drop(_2) -> bb4; // scope 1 at $DIR/asm-unwind.rs:17:1: 17:2
++ }
++
++ bb4 (cleanup): {
++ resume; // scope 1 at $DIR/asm-unwind.rs:14:1: 17:2
+ }
+ }
+
diff --git a/src/test/mir-opt/inline/cycle.f.Inline.diff b/src/test/mir-opt/inline/cycle.f.Inline.diff
index 40fdd1cdb..75ea69a42 100644
--- a/src/test/mir-opt/inline/cycle.f.Inline.diff
+++ b/src/test/mir-opt/inline/cycle.f.Inline.diff
@@ -17,7 +17,7 @@
_2 = <impl Fn() as Fn<()>>::call(move _3, move _4) -> [return: bb1, unwind: bb3]; // scope 0 at $DIR/cycle.rs:+1:5: +1:8
// mir::Constant
// + span: $DIR/cycle.rs:6:5: 6:6
- // + literal: Const { ty: for<'r> extern "rust-call" fn(&'r impl Fn(), ()) -> <impl Fn() as FnOnce<()>>::Output {<impl Fn() as Fn<()>>::call}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> extern "rust-call" fn(&'a impl Fn(), ()) -> <impl Fn() as FnOnce<()>>::Output {<impl Fn() as Fn<()>>::call}, val: Value(<ZST>) }
}
bb1: {
diff --git a/src/test/mir-opt/inline/dyn_trait.get_query.Inline.diff b/src/test/mir-opt/inline/dyn_trait.get_query.Inline.diff
index 4b50ba950..1e95b5b29 100644
--- a/src/test/mir-opt/inline/dyn_trait.get_query.Inline.diff
+++ b/src/test/mir-opt/inline/dyn_trait.get_query.Inline.diff
@@ -28,7 +28,7 @@
// mir::Constant
// + span: $DIR/dyn-trait.rs:33:13: 33:21
// + user_ty: UserType(0)
- // + literal: Const { ty: for<'r> fn(&'r T) -> &'r <Q as Query>::C {<Q as Query>::cache::<T>}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a T) -> &'a <Q as Query>::C {<Q as Query>::cache::<T>}, val: Value(<ZST>) }
}
bb1: {
@@ -46,9 +46,9 @@
+ _0 = <dyn Cache<V = <Q as Query>::V> as Cache>::store_nocache(move _7) -> bb2; // scope 3 at $DIR/dyn-trait.rs:21:5: 21:22
// mir::Constant
- // + span: $DIR/dyn-trait.rs:34:5: 34:22
-- // + literal: Const { ty: for<'r> fn(&'r <Q as Query>::C) {try_execute_query::<<Q as Query>::C>}, val: Value(<ZST>) }
+- // + literal: Const { ty: for<'a> fn(&'a <Q as Query>::C) {try_execute_query::<<Q as Query>::C>}, val: Value(<ZST>) }
+ // + span: $DIR/dyn-trait.rs:21:7: 21:20
-+ // + literal: Const { ty: for<'r> fn(&'r dyn Cache<V = <Q as Query>::V>) {<dyn Cache<V = <Q as Query>::V> as Cache>::store_nocache}, val: Value(<ZST>) }
++ // + literal: Const { ty: for<'a> fn(&'a dyn Cache<V = <Q as Query>::V>) {<dyn Cache<V = <Q as Query>::V> as Cache>::store_nocache}, val: Value(<ZST>) }
}
bb2: {
diff --git a/src/test/mir-opt/inline/dyn_trait.mk_cycle.Inline.diff b/src/test/mir-opt/inline/dyn_trait.mk_cycle.Inline.diff
index 994930ef4..7421db4d0 100644
--- a/src/test/mir-opt/inline/dyn_trait.mk_cycle.Inline.diff
+++ b/src/test/mir-opt/inline/dyn_trait.mk_cycle.Inline.diff
@@ -12,7 +12,7 @@
_0 = <dyn Cache<V = V> as Cache>::store_nocache(move _2) -> bb1; // scope 0 at $DIR/dyn-trait.rs:+1:5: +1:22
// mir::Constant
// + span: $DIR/dyn-trait.rs:21:7: 21:20
- // + literal: Const { ty: for<'r> fn(&'r dyn Cache<V = V>) {<dyn Cache<V = V> as Cache>::store_nocache}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a dyn Cache<V = V>) {<dyn Cache<V = V> as Cache>::store_nocache}, val: Value(<ZST>) }
}
bb1: {
diff --git a/src/test/mir-opt/inline/dyn_trait.try_execute_query.Inline.diff b/src/test/mir-opt/inline/dyn_trait.try_execute_query.Inline.diff
index 58c05b9f5..e6e783744 100644
--- a/src/test/mir-opt/inline/dyn_trait.try_execute_query.Inline.diff
+++ b/src/test/mir-opt/inline/dyn_trait.try_execute_query.Inline.diff
@@ -23,9 +23,9 @@
+ _0 = <dyn Cache<V = <C as Cache>::V> as Cache>::store_nocache(move _4) -> bb1; // scope 1 at $DIR/dyn-trait.rs:21:5: 21:22
// mir::Constant
- // + span: $DIR/dyn-trait.rs:27:5: 27:13
-- // + literal: Const { ty: for<'r> fn(&'r (dyn Cache<V = <C as Cache>::V> + 'r)) {mk_cycle::<<C as Cache>::V>}, val: Value(<ZST>) }
+- // + literal: Const { ty: for<'a> fn(&'a (dyn Cache<V = <C as Cache>::V> + 'a)) {mk_cycle::<<C as Cache>::V>}, val: Value(<ZST>) }
+ // + span: $DIR/dyn-trait.rs:21:7: 21:20
-+ // + literal: Const { ty: for<'r> fn(&'r dyn Cache<V = <C as Cache>::V>) {<dyn Cache<V = <C as Cache>::V> as Cache>::store_nocache}, val: Value(<ZST>) }
++ // + literal: Const { ty: for<'a> fn(&'a dyn Cache<V = <C as Cache>::V>) {<dyn Cache<V = <C as Cache>::V> as Cache>::store_nocache}, val: Value(<ZST>) }
}
bb1: {
diff --git a/src/test/mir-opt/inline/inline_diverging.g.Inline.diff b/src/test/mir-opt/inline/inline_diverging.g.Inline.diff
index a25f1454f..a71baad3e 100644
--- a/src/test/mir-opt/inline/inline_diverging.g.Inline.diff
+++ b/src/test/mir-opt/inline/inline_diverging.g.Inline.diff
@@ -25,7 +25,7 @@
bb1: {
StorageLive(_4); // scope 0 at $DIR/inline-diverging.rs:+2:9: +2:10
_4 = _1; // scope 0 at $DIR/inline-diverging.rs:+2:9: +2:10
- _0 = move _4 as u32 (Misc); // scope 0 at $DIR/inline-diverging.rs:+2:9: +2:17
+ _0 = move _4 as u32 (IntToInt); // scope 0 at $DIR/inline-diverging.rs:+2:9: +2:17
StorageDead(_4); // scope 0 at $DIR/inline-diverging.rs:+2:16: +2:17
StorageDead(_2); // scope 0 at $DIR/inline-diverging.rs:+5:5: +5:6
return; // scope 0 at $DIR/inline-diverging.rs:+6:2: +6:2
diff --git a/src/test/mir-opt/inline/inline_generator.main.Inline.diff b/src/test/mir-opt/inline/inline_generator.main.Inline.diff
index 0b992e3c3..3fd8aad72 100644
--- a/src/test/mir-opt/inline/inline_generator.main.Inline.diff
+++ b/src/test/mir-opt/inline/inline_generator.main.Inline.diff
@@ -70,7 +70,7 @@
- _1 = <[generator@$DIR/inline-generator.rs:15:5: 15:8] as Generator<bool>>::resume(move _2, const false) -> [return: bb3, unwind: bb4]; // scope 0 at $DIR/inline-generator.rs:+1:14: +1:46
- // mir::Constant
- // + span: $DIR/inline-generator.rs:9:33: 9:39
-- // + literal: Const { ty: for<'r> fn(Pin<&'r mut [generator@$DIR/inline-generator.rs:15:5: 15:8]>, bool) -> GeneratorState<<[generator@$DIR/inline-generator.rs:15:5: 15:8] as Generator<bool>>::Yield, <[generator@$DIR/inline-generator.rs:15:5: 15:8] as Generator<bool>>::Return> {<[generator@$DIR/inline-generator.rs:15:5: 15:8] as Generator<bool>>::resume}, val: Value(<ZST>) }
+- // + literal: Const { ty: for<'a> fn(Pin<&'a mut [generator@$DIR/inline-generator.rs:15:5: 15:8]>, bool) -> GeneratorState<<[generator@$DIR/inline-generator.rs:15:5: 15:8] as Generator<bool>>::Yield, <[generator@$DIR/inline-generator.rs:15:5: 15:8] as Generator<bool>>::Return> {<[generator@$DIR/inline-generator.rs:15:5: 15:8] as Generator<bool>>::resume}, val: Value(<ZST>) }
+ StorageLive(_7); // scope 0 at $DIR/inline-generator.rs:+1:14: +1:46
+ _7 = const false; // scope 0 at $DIR/inline-generator.rs:+1:14: +1:46
+ StorageLive(_10); // scope 0 at $DIR/inline-generator.rs:+1:14: +1:46
diff --git a/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir b/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir
index cabc1a920..169e7f5c5 100644
--- a/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir
+++ b/src/test/mir-opt/inline/inline_retag.bar.Inline.after.mir
@@ -2,8 +2,8 @@
fn bar() -> bool {
let mut _0: bool; // return place in scope 0 at $DIR/inline-retag.rs:+0:13: +0:17
- let _1: for<'r, 's> fn(&'r i32, &'s i32) -> bool {foo}; // in scope 0 at $DIR/inline-retag.rs:+1:9: +1:10
- let mut _2: for<'r, 's> fn(&'r i32, &'s i32) -> bool {foo}; // in scope 0 at $DIR/inline-retag.rs:+2:5: +2:6
+ let _1: for<'a, 'b> fn(&'a i32, &'b i32) -> bool {foo}; // in scope 0 at $DIR/inline-retag.rs:+1:9: +1:10
+ let mut _2: for<'a, 'b> fn(&'a i32, &'b i32) -> bool {foo}; // in scope 0 at $DIR/inline-retag.rs:+2:5: +2:6
let mut _3: &i32; // in scope 0 at $DIR/inline-retag.rs:+2:7: +2:9
let _4: &i32; // in scope 0 at $DIR/inline-retag.rs:+2:7: +2:9
let _5: i32; // in scope 0 at $DIR/inline-retag.rs:+2:8: +2:9
@@ -27,7 +27,7 @@ fn bar() -> bool {
_1 = foo; // scope 0 at $DIR/inline-retag.rs:+1:13: +1:16
// mir::Constant
// + span: $DIR/inline-retag.rs:11:13: 11:16
- // + literal: Const { ty: for<'r, 's> fn(&'r i32, &'s i32) -> bool {foo}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a, 'b> fn(&'a i32, &'b i32) -> bool {foo}, val: Value(<ZST>) }
StorageLive(_2); // scope 1 at $DIR/inline-retag.rs:+2:5: +2:6
_2 = _1; // scope 1 at $DIR/inline-retag.rs:+2:5: +2:6
StorageLive(_3); // scope 1 at $DIR/inline-retag.rs:+2:7: +2:9
diff --git a/src/test/mir-opt/inline/inline_shims.clone.Inline.diff b/src/test/mir-opt/inline/inline_shims.clone.Inline.diff
index 25ca05893..d691e90b7 100644
--- a/src/test/mir-opt/inline/inline_shims.clone.Inline.diff
+++ b/src/test/mir-opt/inline/inline_shims.clone.Inline.diff
@@ -14,7 +14,7 @@
- _0 = <fn(A, B) as Clone>::clone(move _2) -> bb1; // scope 0 at $DIR/inline-shims.rs:+1:5: +1:14
- // mir::Constant
- // + span: $DIR/inline-shims.rs:6:7: 6:12
-- // + literal: Const { ty: for<'r> fn(&'r fn(A, B)) -> fn(A, B) {<fn(A, B) as Clone>::clone}, val: Value(<ZST>) }
+- // + literal: Const { ty: for<'a> fn(&'a fn(A, B)) -> fn(A, B) {<fn(A, B) as Clone>::clone}, val: Value(<ZST>) }
- }
-
- bb1: {
diff --git a/src/test/mir-opt/inline/inline_trait_method.test.Inline.after.mir b/src/test/mir-opt/inline/inline_trait_method.test.Inline.after.mir
index ed95edd16..89eefc292 100644
--- a/src/test/mir-opt/inline/inline_trait_method.test.Inline.after.mir
+++ b/src/test/mir-opt/inline/inline_trait_method.test.Inline.after.mir
@@ -11,7 +11,7 @@ fn test(_1: &dyn X) -> u32 {
_0 = <dyn X as X>::y(move _2) -> bb1; // scope 0 at $DIR/inline-trait-method.rs:+1:5: +1:10
// mir::Constant
// + span: $DIR/inline-trait-method.rs:9:7: 9:8
- // + literal: Const { ty: for<'r> fn(&'r dyn X) -> u32 {<dyn X as X>::y}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a dyn X) -> u32 {<dyn X as X>::y}, val: Value(<ZST>) }
}
bb1: {
diff --git a/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir b/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir
index b8896430d..3d05869fa 100644
--- a/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir
+++ b/src/test/mir-opt/inline/inline_trait_method_2.test2.Inline.after.mir
@@ -21,7 +21,7 @@ fn test2(_1: &dyn X) -> bool {
_0 = <dyn X as X>::y(move _4) -> bb1; // scope 1 at $DIR/inline-trait-method_2.rs:10:5: 10:10
// mir::Constant
// + span: $DIR/inline-trait-method_2.rs:10:7: 10:8
- // + literal: Const { ty: for<'r> fn(&'r dyn X) -> bool {<dyn X as X>::y}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a dyn X) -> bool {<dyn X as X>::y}, val: Value(<ZST>) }
}
bb1: {
diff --git a/src/test/mir-opt/inline/issue_78442.bar.Inline.diff b/src/test/mir-opt/inline/issue_78442.bar.Inline.diff
index c16dfdf39..4186650df 100644
--- a/src/test/mir-opt/inline/issue_78442.bar.Inline.diff
+++ b/src/test/mir-opt/inline/issue_78442.bar.Inline.diff
@@ -29,7 +29,7 @@
- _2 = <fn() {foo} as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
- // mir::Constant
- // + span: $DIR/issue-78442.rs:11:5: 11:15
-- // + literal: Const { ty: for<'r> extern "rust-call" fn(&'r fn() {foo}, ()) -> <fn() {foo} as FnOnce<()>>::Output {<fn() {foo} as Fn<()>>::call}, val: Value(<ZST>) }
+- // + literal: Const { ty: for<'a> extern "rust-call" fn(&'a fn() {foo}, ()) -> <fn() {foo} as FnOnce<()>>::Output {<fn() {foo} as Fn<()>>::call}, val: Value(<ZST>) }
+ _2 = move (*_3)() -> [return: bb5, unwind: bb3]; // scope 1 at $SRC_DIR/core/src/ops/function.rs:LL:COL
}
diff --git a/src/test/mir-opt/inline/issue_78442.bar.RevealAll.diff b/src/test/mir-opt/inline/issue_78442.bar.RevealAll.diff
index 0faa522cb..24e9a3df1 100644
--- a/src/test/mir-opt/inline/issue_78442.bar.RevealAll.diff
+++ b/src/test/mir-opt/inline/issue_78442.bar.RevealAll.diff
@@ -29,8 +29,8 @@
+ _2 = <fn() {foo} as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/issue-78442.rs:+4:5: +4:17
// mir::Constant
// + span: $DIR/issue-78442.rs:11:5: 11:15
-- // + literal: Const { ty: for<'r> extern "rust-call" fn(&'r impl Fn(), ()) -> <impl Fn() as FnOnce<()>>::Output {<impl Fn() as Fn<()>>::call}, val: Value(<ZST>) }
-+ // + literal: Const { ty: for<'r> extern "rust-call" fn(&'r fn() {foo}, ()) -> <fn() {foo} as FnOnce<()>>::Output {<fn() {foo} as Fn<()>>::call}, val: Value(<ZST>) }
+- // + literal: Const { ty: for<'a> extern "rust-call" fn(&'a impl Fn(), ()) -> <impl Fn() as FnOnce<()>>::Output {<impl Fn() as Fn<()>>::call}, val: Value(<ZST>) }
++ // + literal: Const { ty: for<'a> extern "rust-call" fn(&'a fn() {foo}, ()) -> <fn() {foo} as FnOnce<()>>::Output {<fn() {foo} as Fn<()>>::call}, val: Value(<ZST>) }
}
bb2: {
diff --git a/src/test/mir-opt/issue-101867.rs b/src/test/mir-opt/issue-101867.rs
index 931396e21..8a357eb79 100644
--- a/src/test/mir-opt/issue-101867.rs
+++ b/src/test/mir-opt/issue-101867.rs
@@ -1,5 +1,3 @@
-#![cfg_attr(bootstrap, feature(let_else))]
-
// EMIT_MIR issue_101867.main.mir_map.0.mir
fn main() {
let x: Option<u8> = Some(1);
diff --git a/src/test/mir-opt/issue_101867.main.mir_map.0.mir b/src/test/mir-opt/issue_101867.main.mir_map.0.mir
index 98501ac8c..42a9e5587 100644
--- a/src/test/mir-opt/issue_101867.main.mir_map.0.mir
+++ b/src/test/mir-opt/issue_101867.main.mir_map.0.mir
@@ -1,8 +1,8 @@
// MIR for `main` 0 mir_map
| User Type Annotations
-| 0: user_ty: Canonical { max_universe: U0, variables: [], value: Ty(std::option::Option<u8>) }, span: $DIR/issue-101867.rs:5:12: 5:22, inferred_ty: std::option::Option<u8>
-| 1: user_ty: Canonical { max_universe: U0, variables: [], value: Ty(std::option::Option<u8>) }, span: $DIR/issue-101867.rs:5:12: 5:22, inferred_ty: std::option::Option<u8>
+| 0: user_ty: Canonical { max_universe: U0, variables: [], value: Ty(std::option::Option<u8>) }, span: $DIR/issue-101867.rs:3:12: 3:22, inferred_ty: std::option::Option<u8>
+| 1: user_ty: Canonical { max_universe: U0, variables: [], value: Ty(std::option::Option<u8>) }, span: $DIR/issue-101867.rs:3:12: 3:22, inferred_ty: std::option::Option<u8>
|
fn main() -> () {
let mut _0: (); // return place in scope 0 at $DIR/issue-101867.rs:+0:11: +0:11
diff --git a/src/test/mir-opt/issue_101973.inner.ConstProp.diff b/src/test/mir-opt/issue_101973.inner.ConstProp.diff
index 89733a9a2..281afe4be 100644
--- a/src/test/mir-opt/issue_101973.inner.ConstProp.diff
+++ b/src/test/mir-opt/issue_101973.inner.ConstProp.diff
@@ -90,9 +90,9 @@
StorageDead(_16); // scope 3 at $SRC_DIR/core/src/num/uint_macros.rs:LL:COL
StorageDead(_6); // scope 0 at $DIR/issue-101973.rs:+1:57: +1:58
StorageDead(_4); // scope 0 at $DIR/issue-101973.rs:+1:57: +1:58
- _2 = move _3 as i32 (Misc); // scope 0 at $DIR/issue-101973.rs:+1:5: +1:65
+ _2 = move _3 as i32 (IntToInt); // scope 0 at $DIR/issue-101973.rs:+1:5: +1:65
StorageDead(_3); // scope 0 at $DIR/issue-101973.rs:+1:64: +1:65
- _0 = move _2 as i64 (Misc); // scope 0 at $DIR/issue-101973.rs:+1:5: +1:72
+ _0 = move _2 as i64 (IntToInt); // scope 0 at $DIR/issue-101973.rs:+1:5: +1:72
StorageDead(_2); // scope 0 at $DIR/issue-101973.rs:+1:71: +1:72
return; // scope 0 at $DIR/issue-101973.rs:+2:2: +2:2
}
diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.diff
index 76d8d9396..269e4e326 100644
--- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.diff
+++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.diff
@@ -25,7 +25,7 @@
let _24: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let mut _25: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let _26: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
- let mut _27: std::option::Option<std::fmt::Arguments>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+ let mut _27: std::option::Option<std::fmt::Arguments<'_>>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
scope 1 {
debug split => _1; // in scope 1 at $DIR/issue-73223.rs:+1:9: +1:14
let _6: std::option::Option<i32>; // in scope 1 at $DIR/issue-73223.rs:+6:9: +6:14
@@ -139,7 +139,7 @@
_21 = core::panicking::assert_failed::<i32, i32>(const core::panicking::AssertKind::Eq, move _23, move _25, move _27); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
// mir::Constant
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
- // + literal: Const { ty: for<'r, 's, 't0> fn(core::panicking::AssertKind, &'r i32, &'s i32, Option<Arguments<'t0>>) -> ! {core::panicking::assert_failed::<i32, i32>}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a, 'b, 'c> fn(core::panicking::AssertKind, &'a i32, &'b i32, Option<Arguments<'c>>) -> ! {core::panicking::assert_failed::<i32, i32>}, val: Value(<ZST>) }
// mir::Constant
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
// + literal: Const { ty: core::panicking::AssertKind, val: Value(Scalar(0x00)) }
diff --git a/src/test/mir-opt/issue_91633.bar.mir_map.0.mir b/src/test/mir-opt/issue_91633.bar.mir_map.0.mir
index f5092d2ac..625f6c736 100644
--- a/src/test/mir-opt/issue_91633.bar.mir_map.0.mir
+++ b/src/test/mir-opt/issue_91633.bar.mir_map.0.mir
@@ -15,7 +15,7 @@ fn bar(_1: Box<[T]>) -> () {
_2 = <[T] as Index<usize>>::index(move _3, const 0_usize) -> [return: bb1, unwind: bb3]; // scope 0 at $DIR/issue-91633.rs:+4:14: +4:19
// mir::Constant
// + span: $DIR/issue-91633.rs:15:14: 15:19
- // + literal: Const { ty: for<'r> fn(&'r [T], usize) -> &'r <[T] as Index<usize>>::Output {<[T] as Index<usize>>::index}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a [T], usize) -> &'a <[T] as Index<usize>>::Output {<[T] as Index<usize>>::index}, val: Value(<ZST>) }
}
bb1: {
diff --git a/src/test/mir-opt/issue_91633.foo.mir_map.0.mir b/src/test/mir-opt/issue_91633.foo.mir_map.0.mir
index 2e8b0feed..9903e203a 100644
--- a/src/test/mir-opt/issue_91633.foo.mir_map.0.mir
+++ b/src/test/mir-opt/issue_91633.foo.mir_map.0.mir
@@ -27,7 +27,7 @@ fn foo(_1: Box<[T]>) -> T {
_2 = <T as Clone>::clone(move _3) -> [return: bb2, unwind: bb5]; // scope 0 at $DIR/issue-91633.rs:+2:14: +2:27
// mir::Constant
// + span: $DIR/issue-91633.rs:28:20: 28:25
- // + literal: Const { ty: for<'r> fn(&'r T) -> T {<T as Clone>::clone}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a T) -> T {<T as Clone>::clone}, val: Value(<ZST>) }
}
bb2: {
diff --git a/src/test/mir-opt/issue_91633.hey.mir_map.0.mir b/src/test/mir-opt/issue_91633.hey.mir_map.0.mir
index 74f4a5a97..37c3b3fca 100644
--- a/src/test/mir-opt/issue_91633.hey.mir_map.0.mir
+++ b/src/test/mir-opt/issue_91633.hey.mir_map.0.mir
@@ -17,7 +17,7 @@ fn hey(_1: &[T]) -> () {
_3 = <[T] as Index<usize>>::index(move _4, const 0_usize) -> [return: bb1, unwind: bb2]; // scope 0 at $DIR/issue-91633.rs:+4:15: +4:20
// mir::Constant
// + span: $DIR/issue-91633.rs:7:15: 7:20
- // + literal: Const { ty: for<'r> fn(&'r [T], usize) -> &'r <[T] as Index<usize>>::Output {<[T] as Index<usize>>::index}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a [T], usize) -> &'a <[T] as Index<usize>>::Output {<[T] as Index<usize>>::index}, val: Value(<ZST>) }
}
bb1: {
diff --git a/src/test/mir-opt/issue_99325.main.mir_map.0.mir b/src/test/mir-opt/issue_99325.main.mir_map.0.mir
index 8659ddfdb..165efa9df 100644
--- a/src/test/mir-opt/issue_99325.main.mir_map.0.mir
+++ b/src/test/mir-opt/issue_99325.main.mir_map.0.mir
@@ -2,7 +2,7 @@
| User Type Annotations
| 0: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Value(Branch([Leaf(0x41), Leaf(0x41), Leaf(0x41), Leaf(0x41)])) }], user_self_ty: None }) }, span: $DIR/issue-99325.rs:10:16: 10:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
-| 1: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:8 ~ issue_99325[8f58]::main::{constant#1}), const_param_did: Some(DefId(0:4 ~ issue_99325[8f58]::function_with_bytes::BYTES)) }, substs: [], promoted: () }) }], user_self_ty: None }) }, span: $DIR/issue-99325.rs:11:16: 11:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
+| 1: user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:3 ~ issue_99325[8f58]::function_with_bytes), UserSubsts { substs: [Const { ty: &'static [u8; 4], kind: Unevaluated(UnevaluatedConst { def: WithOptConstParam { did: DefId(0:8 ~ issue_99325[8f58]::main::{constant#1}), const_param_did: Some(DefId(0:4 ~ issue_99325[8f58]::function_with_bytes::BYTES)) }, substs: [] }) }], user_self_ty: None }) }, span: $DIR/issue-99325.rs:11:16: 11:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">}
|
fn main() -> () {
let mut _0: (); // return place in scope 0 at $DIR/issue-99325.rs:+0:15: +0:15
@@ -26,7 +26,7 @@ fn main() -> () {
let _19: &&[u8]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let mut _20: &&[u8; 4]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let _21: &&[u8; 4]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
- let mut _22: std::option::Option<std::fmt::Arguments>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+ let mut _22: std::option::Option<std::fmt::Arguments<'_>>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let _23: (); // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let mut _24: (&&[u8], &&[u8; 4]); // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let mut _25: &&[u8]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
@@ -46,7 +46,7 @@ fn main() -> () {
let _40: &&[u8]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let mut _41: &&[u8; 4]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let _42: &&[u8; 4]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
- let mut _43: std::option::Option<std::fmt::Arguments>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+ let mut _43: std::option::Option<std::fmt::Arguments<'_>>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
scope 1 {
debug left_val => _8; // in scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
debug right_val => _9; // in scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
@@ -101,7 +101,7 @@ fn main() -> () {
_11 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _12, move _13) -> [return: bb2, unwind: bb19]; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
// mir::Constant
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
- // + literal: Const { ty: for<'r, 's> fn(&'r &[u8], &'s &[u8; 4]) -> bool {<&[u8] as PartialEq<&[u8; 4]>>::eq}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a, 'b> fn(&'a &[u8], &'b &[u8; 4]) -> bool {<&[u8] as PartialEq<&[u8; 4]>>::eq}, val: Value(<ZST>) }
}
bb2: {
@@ -128,11 +128,11 @@ fn main() -> () {
_21 = &(*_9); // scope 2 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
_20 = &(*_21); // scope 2 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
StorageLive(_22); // scope 2 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
- _22 = Option::<Arguments>::None; // scope 2 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+ _22 = Option::<Arguments<'_>>::None; // scope 2 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
_16 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _17, move _18, move _20, move _22) -> bb19; // scope 2 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
// mir::Constant
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
- // + literal: Const { ty: for<'r, 's, 't0> fn(core::panicking::AssertKind, &'r &[u8], &'s &[u8; 4], Option<Arguments<'t0>>) -> ! {core::panicking::assert_failed::<&[u8], &[u8; 4]>}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a, 'b, 'c> fn(core::panicking::AssertKind, &'a &[u8], &'b &[u8; 4], Option<Arguments<'c>>) -> ! {core::panicking::assert_failed::<&[u8], &[u8; 4]>}, val: Value(<ZST>) }
}
bb4: {
@@ -210,7 +210,7 @@ fn main() -> () {
_32 = <&[u8] as PartialEq<&[u8; 4]>>::eq(move _33, move _34) -> [return: bb11, unwind: bb19]; // scope 3 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
// mir::Constant
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
- // + literal: Const { ty: for<'r, 's> fn(&'r &[u8], &'s &[u8; 4]) -> bool {<&[u8] as PartialEq<&[u8; 4]>>::eq}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a, 'b> fn(&'a &[u8], &'b &[u8; 4]) -> bool {<&[u8] as PartialEq<&[u8; 4]>>::eq}, val: Value(<ZST>) }
}
bb11: {
@@ -237,11 +237,11 @@ fn main() -> () {
_42 = &(*_30); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
_41 = &(*_42); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
StorageLive(_43); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
- _43 = Option::<Arguments>::None; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+ _43 = Option::<Arguments<'_>>::None; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
_37 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _38, move _39, move _41, move _43) -> bb19; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
// mir::Constant
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
- // + literal: Const { ty: for<'r, 's, 't0> fn(core::panicking::AssertKind, &'r &[u8], &'s &[u8; 4], Option<Arguments<'t0>>) -> ! {core::panicking::assert_failed::<&[u8], &[u8; 4]>}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a, 'b, 'c> fn(core::panicking::AssertKind, &'a &[u8], &'b &[u8; 4], Option<Arguments<'c>>) -> ! {core::panicking::assert_failed::<&[u8], &[u8; 4]>}, val: Value(<ZST>) }
}
bb13: {
diff --git a/src/test/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.diff b/src/test/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.diff
index a648e5d67..d962ef8cb 100644
--- a/src/test/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.diff
+++ b/src/test/mir-opt/lower_intrinsics.discriminant.LowerIntrinsics.diff
@@ -32,7 +32,7 @@
- _2 = discriminant_value::<T>(move _3) -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:45
- // mir::Constant
- // + span: $DIR/lower_intrinsics.rs:49:5: 49:41
-- // + literal: Const { ty: for<'r> extern "rust-intrinsic" fn(&'r T) -> <T as DiscriminantKind>::Discriminant {discriminant_value::<T>}, val: Value(<ZST>) }
+- // + literal: Const { ty: for<'a> extern "rust-intrinsic" fn(&'a T) -> <T as DiscriminantKind>::Discriminant {discriminant_value::<T>}, val: Value(<ZST>) }
+ _2 = discriminant((*_3)); // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:45
+ goto -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:+1:5: +1:45
}
@@ -53,7 +53,7 @@
- _5 = discriminant_value::<i32>(move _6) -> bb2; // scope 0 at $DIR/lower_intrinsics.rs:+2:5: +2:45
- // mir::Constant
- // + span: $DIR/lower_intrinsics.rs:50:5: 50:41
-- // + literal: Const { ty: for<'r> extern "rust-intrinsic" fn(&'r i32) -> <i32 as DiscriminantKind>::Discriminant {discriminant_value::<i32>}, val: Value(<ZST>) }
+- // + literal: Const { ty: for<'a> extern "rust-intrinsic" fn(&'a i32) -> <i32 as DiscriminantKind>::Discriminant {discriminant_value::<i32>}, val: Value(<ZST>) }
+ _5 = discriminant((*_6)); // scope 0 at $DIR/lower_intrinsics.rs:+2:5: +2:45
+ goto -> bb2; // scope 0 at $DIR/lower_intrinsics.rs:+2:5: +2:45
}
@@ -74,7 +74,7 @@
- _9 = discriminant_value::<()>(move _10) -> bb3; // scope 0 at $DIR/lower_intrinsics.rs:+3:5: +3:46
- // mir::Constant
- // + span: $DIR/lower_intrinsics.rs:51:5: 51:41
-- // + literal: Const { ty: for<'r> extern "rust-intrinsic" fn(&'r ()) -> <() as DiscriminantKind>::Discriminant {discriminant_value::<()>}, val: Value(<ZST>) }
+- // + literal: Const { ty: for<'a> extern "rust-intrinsic" fn(&'a ()) -> <() as DiscriminantKind>::Discriminant {discriminant_value::<()>}, val: Value(<ZST>) }
+ _9 = discriminant((*_10)); // scope 0 at $DIR/lower_intrinsics.rs:+3:5: +3:46
+ goto -> bb3; // scope 0 at $DIR/lower_intrinsics.rs:+3:5: +3:46
}
@@ -95,7 +95,7 @@
- _13 = discriminant_value::<E>(move _14) -> bb4; // scope 0 at $DIR/lower_intrinsics.rs:+4:5: +4:48
- // mir::Constant
- // + span: $DIR/lower_intrinsics.rs:52:5: 52:41
-- // + literal: Const { ty: for<'r> extern "rust-intrinsic" fn(&'r E) -> <E as DiscriminantKind>::Discriminant {discriminant_value::<E>}, val: Value(<ZST>) }
+- // + literal: Const { ty: for<'a> extern "rust-intrinsic" fn(&'a E) -> <E as DiscriminantKind>::Discriminant {discriminant_value::<E>}, val: Value(<ZST>) }
+ _13 = discriminant((*_14)); // scope 0 at $DIR/lower_intrinsics.rs:+4:5: +4:48
+ goto -> bb4; // scope 0 at $DIR/lower_intrinsics.rs:+4:5: +4:48
}
diff --git a/src/test/mir-opt/lower_intrinsics.f_copy_nonoverlapping.LowerIntrinsics.diff b/src/test/mir-opt/lower_intrinsics.f_copy_nonoverlapping.LowerIntrinsics.diff
index 4fb6752b6..ec15fd1ef 100644
--- a/src/test/mir-opt/lower_intrinsics.f_copy_nonoverlapping.LowerIntrinsics.diff
+++ b/src/test/mir-opt/lower_intrinsics.f_copy_nonoverlapping.LowerIntrinsics.diff
@@ -36,7 +36,7 @@
_7 = &_1; // scope 3 at $DIR/lower_intrinsics.rs:+4:29: +4:33
_6 = &raw const (*_7); // scope 3 at $DIR/lower_intrinsics.rs:+4:29: +4:33
_5 = _6; // scope 3 at $DIR/lower_intrinsics.rs:+4:29: +4:45
- _4 = move _5 as *const i32 (Misc); // scope 3 at $DIR/lower_intrinsics.rs:+4:29: +4:59
+ _4 = move _5 as *const i32 (PtrToPtr); // scope 3 at $DIR/lower_intrinsics.rs:+4:29: +4:59
StorageDead(_5); // scope 3 at $DIR/lower_intrinsics.rs:+4:58: +4:59
StorageLive(_8); // scope 3 at $DIR/lower_intrinsics.rs:+4:61: +4:91
StorageLive(_9); // scope 3 at $DIR/lower_intrinsics.rs:+4:61: +4:79
@@ -45,7 +45,7 @@
_11 = &mut _2; // scope 3 at $DIR/lower_intrinsics.rs:+4:61: +4:69
_10 = &raw mut (*_11); // scope 3 at $DIR/lower_intrinsics.rs:+4:61: +4:69
_9 = _10; // scope 3 at $DIR/lower_intrinsics.rs:+4:61: +4:79
- _8 = move _9 as *mut i32 (Misc); // scope 3 at $DIR/lower_intrinsics.rs:+4:61: +4:91
+ _8 = move _9 as *mut i32 (PtrToPtr); // scope 3 at $DIR/lower_intrinsics.rs:+4:61: +4:91
StorageDead(_9); // scope 3 at $DIR/lower_intrinsics.rs:+4:90: +4:91
- _3 = copy_nonoverlapping::<i32>(move _4, move _8, const 0_usize) -> bb1; // scope 3 at $DIR/lower_intrinsics.rs:+4:9: +4:95
- // mir::Constant
diff --git a/src/test/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.diff b/src/test/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.diff
index 46fccba56..5f5d6e68f 100644
--- a/src/test/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.diff
+++ b/src/test/mir-opt/lower_slice_len.bound.LowerSliceLenCalls.diff
@@ -23,7 +23,7 @@
- _5 = core::slice::<impl [u8]>::len(move _6) -> bb1; // scope 0 at $DIR/lower_slice_len.rs:+1:16: +1:27
- // mir::Constant
- // + span: $DIR/lower_slice_len.rs:5:22: 5:25
-- // + literal: Const { ty: for<'r> fn(&'r [u8]) -> usize {core::slice::<impl [u8]>::len}, val: Value(<ZST>) }
+- // + literal: Const { ty: for<'a> fn(&'a [u8]) -> usize {core::slice::<impl [u8]>::len}, val: Value(<ZST>) }
+ _5 = Len((*_6)); // scope 0 at $DIR/lower_slice_len.rs:+1:16: +1:27
+ goto -> bb1; // scope 0 at $DIR/lower_slice_len.rs:+1:16: +1:27
}
diff --git a/src/test/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.mir b/src/test/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.mir
index 25c6e3060..963e7cde6 100644
--- a/src/test/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.mir
+++ b/src/test/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.mir
@@ -20,7 +20,7 @@ fn main() -> () {
_2 = <str as ToString>::to_string(move _3) -> bb1; // scope 0 at $DIR/no-spurious-drop-after-call.rs:+1:20: +1:34
// mir::Constant
// + span: $DIR/no-spurious-drop-after-call.rs:9:23: 9:32
- // + literal: Const { ty: for<'r> fn(&'r str) -> String {<str as ToString>::to_string}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a str) -> String {<str as ToString>::to_string}, val: Value(<ZST>) }
}
bb1: {
diff --git a/src/test/mir-opt/nrvo_simple.nrvo.RenameReturnPlace.diff b/src/test/mir-opt/nrvo_simple.nrvo.RenameReturnPlace.diff
index 9e89bd9fb..ce35f920b 100644
--- a/src/test/mir-opt/nrvo_simple.nrvo.RenameReturnPlace.diff
+++ b/src/test/mir-opt/nrvo_simple.nrvo.RenameReturnPlace.diff
@@ -1,13 +1,13 @@
- // MIR for `nrvo` before RenameReturnPlace
+ // MIR for `nrvo` after RenameReturnPlace
- fn nrvo(_1: for<'r> fn(&'r mut [u8; 1024])) -> [u8; 1024] {
+ fn nrvo(_1: for<'a> fn(&'a mut [u8; 1024])) -> [u8; 1024] {
debug init => _1; // in scope 0 at $DIR/nrvo-simple.rs:+0:9: +0:13
- let mut _0: [u8; 1024]; // return place in scope 0 at $DIR/nrvo-simple.rs:+0:39: +0:49
+ let mut _0: [u8; 1024]; // return place in scope 0 at $DIR/nrvo-simple.rs:+1:9: +1:16
let mut _2: [u8; 1024]; // in scope 0 at $DIR/nrvo-simple.rs:+1:9: +1:16
let _3: (); // in scope 0 at $DIR/nrvo-simple.rs:+2:5: +2:19
- let mut _4: for<'r> fn(&'r mut [u8; 1024]); // in scope 0 at $DIR/nrvo-simple.rs:+2:5: +2:9
+ let mut _4: for<'a> fn(&'a mut [u8; 1024]); // in scope 0 at $DIR/nrvo-simple.rs:+2:5: +2:9
let mut _5: &mut [u8; 1024]; // in scope 0 at $DIR/nrvo-simple.rs:+2:10: +2:18
let mut _6: &mut [u8; 1024]; // in scope 0 at $DIR/nrvo-simple.rs:+2:10: +2:18
scope 1 {
diff --git a/src/test/mir-opt/remove-never-const.rs b/src/test/mir-opt/remove-never-const.rs
index 017746647..16095cfdd 100644
--- a/src/test/mir-opt/remove-never-const.rs
+++ b/src/test/mir-opt/remove-never-const.rs
@@ -6,7 +6,6 @@
// compile-flags: --emit mir,link
#![feature(never_type)]
-#![warn(const_err)]
struct PrintName<T>(T);
diff --git a/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff b/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff
index 99667aabd..188aa5564 100644
--- a/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff
+++ b/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff
@@ -57,7 +57,7 @@
_7 = <std::ops::Range<i32> as Iterator>::next(move _8) -> bb3; // scope 2 at $DIR/remove_storage_markers.rs:+2:14: +2:19
// mir::Constant
// + span: $DIR/remove_storage_markers.rs:10:14: 10:19
- // + literal: Const { ty: for<'r> fn(&'r mut std::ops::Range<i32>) -> Option<<std::ops::Range<i32> as Iterator>::Item> {<std::ops::Range<i32> as Iterator>::next}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a mut std::ops::Range<i32>) -> Option<<std::ops::Range<i32> as Iterator>::Item> {<std::ops::Range<i32> as Iterator>::next}, val: Value(<ZST>) }
}
bb3: {
diff --git a/src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir
index 899bb67fb..fe57e32a7 100644
--- a/src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir
+++ b/src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir
@@ -29,7 +29,7 @@ fn array_casts() -> () {
let _31: &usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let mut _32: &usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
let _33: &usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
- let mut _34: std::option::Option<std::fmt::Arguments>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
+ let mut _34: std::option::Option<std::fmt::Arguments<'_>>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
scope 1 {
debug x => _1; // in scope 1 at $DIR/retag.rs:+1:9: +1:14
let _2: *mut usize; // in scope 1 at $DIR/retag.rs:+2:9: +2:10
@@ -180,7 +180,7 @@ fn array_casts() -> () {
_28 = core::panicking::assert_failed::<usize, usize>(move _29, move _30, move _32, move _34); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
// mir::Constant
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
- // + literal: Const { ty: for<'r, 's, 't0> fn(core::panicking::AssertKind, &'r usize, &'s usize, Option<Arguments<'t0>>) -> ! {core::panicking::assert_failed::<usize, usize>}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a, 'b, 'c> fn(core::panicking::AssertKind, &'a usize, &'b usize, Option<Arguments<'c>>) -> ! {core::panicking::assert_failed::<usize, usize>}, val: Value(<ZST>) }
}
bb4: {
diff --git a/src/test/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir b/src/test/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir
index 84f674db2..cdc413c56 100644
--- a/src/test/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir
+++ b/src/test/mir-opt/retag.core.ptr-drop_in_place.Test.SimplifyCfg-make_shim.after.mir
@@ -11,7 +11,7 @@ fn std::ptr::drop_in_place(_1: *mut Test) -> () {
_3 = <Test as Drop>::drop(move _2) -> bb1; // scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56
// mir::Constant
// + span: $SRC_DIR/core/src/ptr/mod.rs:LL:COL
- // + literal: Const { ty: for<'r> fn(&'r mut Test) {<Test as Drop>::drop}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a mut Test) {<Test as Drop>::drop}, val: Value(<ZST>) }
}
bb1: {
diff --git a/src/test/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.mir
index 7212de52f..81225b44e 100644
--- a/src/test/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.mir
+++ b/src/test/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.mir
@@ -11,7 +11,7 @@ fn main() -> () {
let mut _9: &mut i32; // in scope 0 at $DIR/retag.rs:+4:19: +4:20
let mut _12: *mut i32; // in scope 0 at $DIR/retag.rs:+7:18: +7:29
let mut _14: [closure@main::{closure#0}]; // in scope 0 at $DIR/retag.rs:+11:31: +14:6
- let mut _16: for<'r> fn(&'r i32) -> &'r i32; // in scope 0 at $DIR/retag.rs:+15:14: +15:15
+ let mut _16: for<'a> fn(&'a i32) -> &'a i32; // in scope 0 at $DIR/retag.rs:+15:14: +15:15
let mut _17: &i32; // in scope 0 at $DIR/retag.rs:+15:16: +15:18
let _18: &i32; // in scope 0 at $DIR/retag.rs:+15:16: +15:18
let _19: &i32; // in scope 0 at $DIR/retag.rs:+18:5: +18:24
@@ -25,7 +25,7 @@ fn main() -> () {
scope 1 {
debug x => _1; // in scope 1 at $DIR/retag.rs:+1:9: +1:14
let _3: &mut i32; // in scope 1 at $DIR/retag.rs:+3:13: +3:14
- let _13: for<'r> fn(&'r i32) -> &'r i32; // in scope 1 at $DIR/retag.rs:+11:9: +11:10
+ let _13: for<'a> fn(&'a i32) -> &'a i32; // in scope 1 at $DIR/retag.rs:+11:9: +11:10
scope 2 {
debug v => _3; // in scope 2 at $DIR/retag.rs:+3:13: +3:14
let _8: &mut i32; // in scope 2 at $DIR/retag.rs:+4:13: +4:14
@@ -75,7 +75,7 @@ fn main() -> () {
_3 = Test::foo(move _4, move _6) -> [return: bb1, unwind: bb8]; // scope 1 at $DIR/retag.rs:+3:17: +3:36
// mir::Constant
// + span: $DIR/retag.rs:33:25: 33:28
- // + literal: Const { ty: for<'r, 'x> fn(&'r Test, &'x mut i32) -> &'x mut i32 {Test::foo}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a, 'x> fn(&'a Test, &'x mut i32) -> &'x mut i32 {Test::foo}, val: Value(<ZST>) }
}
bb1: {
@@ -114,7 +114,7 @@ fn main() -> () {
StorageLive(_14); // scope 1 at $DIR/retag.rs:+11:31: +14:6
Deinit(_14); // scope 1 at $DIR/retag.rs:+11:31: +14:6
Retag(_14); // scope 1 at $DIR/retag.rs:+11:31: +14:6
- _13 = move _14 as for<'r> fn(&'r i32) -> &'r i32 (Pointer(ClosureFnPointer(Normal))); // scope 1 at $DIR/retag.rs:+11:31: +14:6
+ _13 = move _14 as for<'a> fn(&'a i32) -> &'a i32 (Pointer(ClosureFnPointer(Normal))); // scope 1 at $DIR/retag.rs:+11:31: +14:6
StorageDead(_14); // scope 1 at $DIR/retag.rs:+11:47: +11:48
StorageLive(_15); // scope 6 at $DIR/retag.rs:+15:9: +15:11
StorageLive(_16); // scope 6 at $DIR/retag.rs:+15:14: +15:15
@@ -154,7 +154,7 @@ fn main() -> () {
_19 = Test::foo_shr(move _20, move _22) -> [return: bb4, unwind: bb7]; // scope 7 at $DIR/retag.rs:+18:5: +18:24
// mir::Constant
// + span: $DIR/retag.rs:48:13: 48:20
- // + literal: Const { ty: for<'r, 'x> fn(&'r Test, &'x i32) -> &'x i32 {Test::foo_shr}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a, 'x> fn(&'a Test, &'x i32) -> &'x i32 {Test::foo_shr}, val: Value(<ZST>) }
}
bb4: {
diff --git a/src/test/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir b/src/test/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir
index b4b317e84..31ccf1454 100644
--- a/src/test/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir
+++ b/src/test/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir
@@ -84,7 +84,7 @@ fn std::ptr::drop_in_place(_1: *mut [String]) -> () {
bb13: {
_15 = &raw mut (*_1); // scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56
- _9 = move _15 as *mut std::string::String (Misc); // scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56
+ _9 = move _15 as *mut std::string::String (PtrToPtr); // scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56
_10 = Offset(_9, move _3); // scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56
goto -> bb12; // scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56
}
diff --git a/src/test/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir b/src/test/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir
index 7ffd242e0..ed9f3bdbd 100644
--- a/src/test/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir
+++ b/src/test/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir
@@ -34,6 +34,6 @@ fn std::ptr::drop_in_place(_1: *mut Vec<i32>) -> () {
_3 = <Vec<i32> as Drop>::drop(move _2) -> [return: bb5, unwind: bb4]; // scope 0 at $SRC_DIR/core/src/ptr/mod.rs:+0:1: +0:56
// mir::Constant
// + span: $SRC_DIR/core/src/ptr/mod.rs:LL:COL
- // + literal: Const { ty: for<'r> fn(&'r mut Vec<i32>) {<Vec<i32> as Drop>::drop}, val: Value(<ZST>) }
+ // + literal: Const { ty: for<'a> fn(&'a mut Vec<i32>) {<Vec<i32> as Drop>::drop}, val: Value(<ZST>) }
}
}
diff --git a/src/test/pretty/issue-4264.pp b/src/test/pretty/issue-4264.pp
index 752c36a0f..18e6d75b1 100644
--- a/src/test/pretty/issue-4264.pp
+++ b/src/test/pretty/issue-4264.pp
@@ -32,12 +32,12 @@ fn bar() ({
({
let res =
((::alloc::fmt::format as
- for<'r> fn(Arguments<'r>) -> String {format})(((::core::fmt::Arguments::new_v1
+ for<'a> fn(Arguments<'a>) -> String {format})(((::core::fmt::Arguments::new_v1
as
- fn(&[&'static str], &[ArgumentV1]) -> Arguments {Arguments::new_v1})((&([("test"
+ fn(&[&'static str], &[ArgumentV1<'_>]) -> Arguments<'_> {Arguments::<'_>::new_v1})((&([("test"
as &str)] as [&str; 1]) as &[&str; 1]),
- (&([] as [ArgumentV1; 0]) as &[ArgumentV1; 0])) as
- Arguments)) as String);
+ (&([] as [ArgumentV1<'_>; 0]) as &[ArgumentV1<'_>; 0])) as
+ Arguments<'_>)) as String);
(res as String)
} as String);
} as ())
diff --git a/src/test/pretty/issue-85089.pp b/src/test/pretty/issue-85089.pp
new file mode 100644
index 000000000..f84e9df04
--- /dev/null
+++ b/src/test/pretty/issue-85089.pp
@@ -0,0 +1,20 @@
+#[prelude_import]
+use ::std::prelude::rust_2015::*;
+#[macro_use]
+extern crate std;
+// Test to print lifetimes on HIR pretty-printing.
+
+// pretty-compare-only
+// pretty-mode:hir
+// pp-exact:issue-85089.pp
+
+trait A<'x> { }
+trait B<'x> { }
+
+struct Foo<'b> {
+ bar: &'b dyn for<'a> A<'a>,
+}
+
+impl <'a> B<'a> for dyn for<'b> A<'b> { }
+
+impl <'a> A<'a> for Foo<'a> { }
diff --git a/src/test/pretty/issue-85089.rs b/src/test/pretty/issue-85089.rs
new file mode 100644
index 000000000..eb45d4731
--- /dev/null
+++ b/src/test/pretty/issue-85089.rs
@@ -0,0 +1,16 @@
+// Test to print lifetimes on HIR pretty-printing.
+
+// pretty-compare-only
+// pretty-mode:hir
+// pp-exact:issue-85089.pp
+
+trait A<'x> {}
+trait B<'x> {}
+
+struct Foo<'b> {
+ pub bar: &'b dyn for<'a> A<'a>,
+}
+
+impl<'a> B<'a> for dyn for<'b> A<'b> {}
+
+impl<'a> A<'a> for Foo<'a> {}
diff --git a/src/test/pretty/raw-str-nonexpr.rs b/src/test/pretty/raw-str-nonexpr.rs
index 7af80979b..12440b5ae 100644
--- a/src/test/pretty/raw-str-nonexpr.rs
+++ b/src/test/pretty/raw-str-nonexpr.rs
@@ -1,3 +1,4 @@
+// needs-asm-support
// pp-exact
#[cfg(foo = r#"just parse this"#)]
diff --git a/src/test/pretty/tests-are-sorted.pp b/src/test/pretty/tests-are-sorted.pp
new file mode 100644
index 000000000..15dcd4ed9
--- /dev/null
+++ b/src/test/pretty/tests-are-sorted.pp
@@ -0,0 +1,69 @@
+#![feature(prelude_import)]
+#![no_std]
+#[prelude_import]
+use ::std::prelude::rust_2015::*;
+#[macro_use]
+extern crate std;
+// compile-flags: --crate-type=lib --test
+// pretty-compare-only
+// pretty-mode:expanded
+// pp-exact:tests-are-sorted.pp
+
+extern crate test;
+#[cfg(test)]
+#[rustc_test_marker = "m_test"]
+pub const m_test: test::TestDescAndFn =
+ test::TestDescAndFn {
+ desc: test::TestDesc {
+ name: test::StaticTestName("m_test"),
+ ignore: false,
+ ignore_message: ::core::option::Option::None,
+ compile_fail: false,
+ no_run: false,
+ should_panic: test::ShouldPanic::No,
+ test_type: test::TestType::Unknown,
+ },
+ testfn: test::StaticTestFn(|| test::assert_test_result(m_test())),
+ };
+fn m_test() {}
+
+extern crate test;
+#[cfg(test)]
+#[rustc_test_marker = "z_test"]
+pub const z_test: test::TestDescAndFn =
+ test::TestDescAndFn {
+ desc: test::TestDesc {
+ name: test::StaticTestName("z_test"),
+ ignore: false,
+ ignore_message: ::core::option::Option::None,
+ compile_fail: false,
+ no_run: false,
+ should_panic: test::ShouldPanic::No,
+ test_type: test::TestType::Unknown,
+ },
+ testfn: test::StaticTestFn(|| test::assert_test_result(z_test())),
+ };
+fn z_test() {}
+
+extern crate test;
+#[cfg(test)]
+#[rustc_test_marker = "a_test"]
+pub const a_test: test::TestDescAndFn =
+ test::TestDescAndFn {
+ desc: test::TestDesc {
+ name: test::StaticTestName("a_test"),
+ ignore: false,
+ ignore_message: ::core::option::Option::None,
+ compile_fail: false,
+ no_run: false,
+ should_panic: test::ShouldPanic::No,
+ test_type: test::TestType::Unknown,
+ },
+ testfn: test::StaticTestFn(|| test::assert_test_result(a_test())),
+ };
+fn a_test() {}
+#[rustc_main]
+pub fn main() -> () {
+ extern crate test;
+ test::test_main_static(&[&a_test, &m_test, &z_test])
+}
diff --git a/src/test/pretty/tests-are-sorted.rs b/src/test/pretty/tests-are-sorted.rs
new file mode 100644
index 000000000..1f737d547
--- /dev/null
+++ b/src/test/pretty/tests-are-sorted.rs
@@ -0,0 +1,13 @@
+// compile-flags: --crate-type=lib --test
+// pretty-compare-only
+// pretty-mode:expanded
+// pp-exact:tests-are-sorted.pp
+
+#[test]
+fn m_test() {}
+
+#[test]
+fn z_test() {}
+
+#[test]
+fn a_test() {}
diff --git a/src/test/run-make-fulldeps/alloc-no-rc/Makefile b/src/test/run-make-fulldeps/alloc-no-rc/Makefile
new file mode 100644
index 000000000..5f7ae70fa
--- /dev/null
+++ b/src/test/run-make-fulldeps/alloc-no-rc/Makefile
@@ -0,0 +1,4 @@
+include ../tools.mk
+
+all:
+ $(RUSTC) --edition=2021 -Dwarnings --crate-type=rlib ../../../../library/alloc/src/lib.rs --cfg no_rc
diff --git a/src/test/run-make-fulldeps/alloc-no-sync/Makefile b/src/test/run-make-fulldeps/alloc-no-sync/Makefile
new file mode 100644
index 000000000..6a258a2dd
--- /dev/null
+++ b/src/test/run-make-fulldeps/alloc-no-sync/Makefile
@@ -0,0 +1,4 @@
+include ../tools.mk
+
+all:
+ $(RUSTC) --edition=2021 -Dwarnings --crate-type=rlib ../../../../library/alloc/src/lib.rs --cfg no_sync
diff --git a/src/test/run-make-fulldeps/foreign-rust-exceptions/Makefile b/src/test/run-make-fulldeps/foreign-rust-exceptions/Makefile
new file mode 100644
index 000000000..50fca7f24
--- /dev/null
+++ b/src/test/run-make-fulldeps/foreign-rust-exceptions/Makefile
@@ -0,0 +1,11 @@
+# ignore-i686-pc-windows-gnu
+
+# This test doesn't work on 32-bit MinGW as cdylib has its own copy of unwinder
+# so cross-DLL unwinding does not work.
+
+include ../tools.mk
+
+all:
+ $(RUSTC) bar.rs --crate-type=cdylib
+ $(RUSTC) foo.rs
+ $(call RUN,foo) 2>&1 | $(CGREP) "Rust cannot catch foreign exceptions"
diff --git a/src/test/run-make-fulldeps/foreign-rust-exceptions/bar.rs b/src/test/run-make-fulldeps/foreign-rust-exceptions/bar.rs
new file mode 100644
index 000000000..5f9efe323
--- /dev/null
+++ b/src/test/run-make-fulldeps/foreign-rust-exceptions/bar.rs
@@ -0,0 +1,7 @@
+#![crate_type = "cdylib"]
+#![feature(c_unwind)]
+
+#[no_mangle]
+extern "C-unwind" fn panic() {
+ panic!();
+}
diff --git a/src/test/run-make-fulldeps/foreign-rust-exceptions/foo.rs b/src/test/run-make-fulldeps/foreign-rust-exceptions/foo.rs
new file mode 100644
index 000000000..266987c5b
--- /dev/null
+++ b/src/test/run-make-fulldeps/foreign-rust-exceptions/foo.rs
@@ -0,0 +1,13 @@
+#![feature(c_unwind)]
+
+#[cfg_attr(not(windows), link(name = "bar"))]
+#[cfg_attr(windows, link(name = "bar.dll"))]
+extern "C-unwind" {
+ fn panic();
+}
+
+fn main() {
+ let _ = std::panic::catch_unwind(|| {
+ unsafe { panic() };
+ });
+}
diff --git a/src/test/run-make-fulldeps/intrinsic-unreachable/Makefile b/src/test/run-make-fulldeps/intrinsic-unreachable/Makefile
index 3c4dade0f..ff9cc5709 100644
--- a/src/test/run-make-fulldeps/intrinsic-unreachable/Makefile
+++ b/src/test/run-make-fulldeps/intrinsic-unreachable/Makefile
@@ -1,5 +1,6 @@
include ../tools.mk
+# needs-asm-support
# ignore-windows-msvc
#
# Because of Windows exception handling, the code is not necessarily any shorter.
diff --git a/src/test/run-make-fulldeps/issue-19371/foo.rs b/src/test/run-make-fulldeps/issue-19371/foo.rs
index fd294b018..7e1b6aeb3 100644
--- a/src/test/run-make-fulldeps/issue-19371/foo.rs
+++ b/src/test/run-make-fulldeps/issue-19371/foo.rs
@@ -5,7 +5,6 @@ extern crate rustc_driver;
extern crate rustc_session;
extern crate rustc_span;
-use rustc_session::DiagnosticOutput;
use rustc_session::config::{Input, Options, OutputType, OutputTypes};
use rustc_interface::interface;
use rustc_span::source_map::FileName;
@@ -55,7 +54,6 @@ fn compile(code: String, output: PathBuf, sysroot: PathBuf) {
output_file: Some(output),
output_dir: None,
file_loader: None,
- diagnostic_output: DiagnosticOutput::Default,
lint_caps: Default::default(),
parse_sess_created: None,
register_lints: None,
diff --git a/src/test/run-make-fulldeps/obtain-borrowck/driver.rs b/src/test/run-make-fulldeps/obtain-borrowck/driver.rs
index 8f78bda03..a6c60df83 100644
--- a/src/test/run-make-fulldeps/obtain-borrowck/driver.rs
+++ b/src/test/run-make-fulldeps/obtain-borrowck/driver.rs
@@ -69,25 +69,25 @@ impl rustc_driver::Callbacks for CompilerCalls {
let crate_items = tcx.hir_crate_items(());
for id in crate_items.items() {
- if matches!(tcx.def_kind(id.def_id), DefKind::Fn) {
- bodies.push(id.def_id);
+ if matches!(tcx.def_kind(id.owner_id), DefKind::Fn) {
+ bodies.push(id.owner_id);
}
}
for id in crate_items.trait_items() {
- if matches!(tcx.def_kind(id.def_id), DefKind::AssocFn) {
+ if matches!(tcx.def_kind(id.owner_id), DefKind::AssocFn) {
let trait_item = hir.trait_item(id);
if let rustc_hir::TraitItemKind::Fn(_, trait_fn) = &trait_item.kind {
if let rustc_hir::TraitFn::Provided(_) = trait_fn {
- bodies.push(trait_item.def_id);
+ bodies.push(trait_item.owner_id);
}
}
}
}
for id in crate_items.impl_items() {
- if matches!(tcx.def_kind(id.def_id), DefKind::AssocFn) {
- bodies.push(id.def_id);
+ if matches!(tcx.def_kind(id.owner_id), DefKind::AssocFn) {
+ bodies.push(id.owner_id);
}
}
diff --git a/src/test/run-make-fulldeps/print-calling-conventions/Makefile b/src/test/run-make-fulldeps/print-calling-conventions/Makefile
new file mode 100644
index 000000000..d3fd06392
--- /dev/null
+++ b/src/test/run-make-fulldeps/print-calling-conventions/Makefile
@@ -0,0 +1,4 @@
+-include ../tools.mk
+
+all:
+ $(RUSTC) --print calling-conventions
diff --git a/src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/src/lib.rs b/src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/src/lib.rs
index bac3970a4..d8658a0f2 100644
--- a/src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/src/lib.rs
+++ b/src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/src/lib.rs
@@ -1,8 +1,8 @@
// Scraped example should only include line numbers for items b and c in ex.rs
-// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '14'
-// @has foobar/fn.f.html '//*[@class="line-numbers"]' '15'
-// @has foobar/fn.f.html '//*[@class="line-numbers"]' '21'
-// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '22'
+// @!has foobar/fn.f.html '//*[@class="src-line-numbers"]' '14'
+// @has foobar/fn.f.html '//*[@class="src-line-numbers"]' '15'
+// @has foobar/fn.f.html '//*[@class="src-line-numbers"]' '21'
+// @!has foobar/fn.f.html '//*[@class="src-line-numbers"]' '22'
pub fn f() {}
diff --git a/src/test/run-make/coverage-reports/Makefile b/src/test/run-make/coverage-reports/Makefile
index 6fc2a6bad..64b2f75ef 100644
--- a/src/test/run-make/coverage-reports/Makefile
+++ b/src/test/run-make/coverage-reports/Makefile
@@ -1,6 +1,11 @@
# needs-profiler-support
# ignore-windows-gnu
+# FIXME(pietroalbini): this test currently does not work on cross-compiled
+# targets because remote-test is not capable of sending back the *.profraw
+# files generated by the LLVM instrumentation.
+# ignore-cross-compile
+
# Rust coverage maps support LLVM Coverage Mapping Format versions 5 and 6,
# corresponding with LLVM versions 12 and 13, respectively.
# When upgrading LLVM versions, consider whether to enforce a minimum LLVM
@@ -75,19 +80,19 @@ ifdef RUSTC_BLESS_TEST
rm -f expected_*
endif
-include clear_expected_if_blessed
+-include clear_expected_if_blessed
%: $(SOURCEDIR)/lib/%.rs
# Compile the test library with coverage instrumentation
$(RUSTC) $(SOURCEDIR)/lib/$@.rs \
$$( sed -n 's/^\/\/ compile-flags: \([^#]*\).*/\1/p' $(SOURCEDIR)/lib/$@.rs ) \
- --crate-type rlib -Cinstrument-coverage
+ --crate-type rlib -Cinstrument-coverage --target $(TARGET)
%: $(SOURCEDIR)/%.rs
# Compile the test program with coverage instrumentation
$(RUSTC) $(SOURCEDIR)/$@.rs \
$$( sed -n 's/^\/\/ compile-flags: \([^#]*\).*/\1/p' $(SOURCEDIR)/$@.rs ) \
- -L "$(TMPDIR)" -Cinstrument-coverage
+ -L "$(TMPDIR)" -Cinstrument-coverage --target $(TARGET)
# Run it in order to generate some profiling data,
# with `LLVM_PROFILE_FILE=<profdata_file>` environment variable set to
diff --git a/src/test/run-make/issue-36710/Makefile b/src/test/run-make/issue-36710/Makefile
index b5270ad2b..986a3f4e6 100644
--- a/src/test/run-make/issue-36710/Makefile
+++ b/src/test/run-make/issue-36710/Makefile
@@ -1,10 +1,6 @@
-# ignore-riscv64 $(call RUN,foo) expects to run the target executable natively
+# ignore-cross-compile $(call RUN,foo) expects to run the target executable natively
# so it won't work with remote-test-server
-# ignore-arm Another build using remote-test-server
# ignore-none no-std is not supported
-# ignore-wasm32 FIXME: don't attempt to compile C++ to WASM
-# ignore-wasm64 FIXME: don't attempt to compile C++ to WASM
-# ignore-nvptx64-nvidia-cuda FIXME: can't find crate for `std`
# ignore-musl FIXME: this makefile needs teaching how to use a musl toolchain
# (see dist-i586-gnu-i586-i686-musl Dockerfile)
diff --git a/src/test/run-make/macos-fat-archive/Makefile b/src/test/run-make/macos-fat-archive/Makefile
new file mode 100644
index 000000000..cc99375db
--- /dev/null
+++ b/src/test/run-make/macos-fat-archive/Makefile
@@ -0,0 +1,10 @@
+# only-macos
+
+-include ../../run-make-fulldeps/tools.mk
+
+"$(TMPDIR)"/libnative-library.a: native-library.c
+ $(CC) -arch arm64 -arch x86_64 native-library.c -c -o "$(TMPDIR)"/native-library.o
+ $(AR) crs "$(TMPDIR)"/libnative-library.a "$(TMPDIR)"/native-library.o
+
+all: "$(TMPDIR)"/libnative-library.a
+ $(RUSTC) lib.rs --crate-type=lib -L "native=$(TMPDIR)" -l static=native-library
diff --git a/src/test/run-make/macos-fat-archive/lib.rs b/src/test/run-make/macos-fat-archive/lib.rs
new file mode 100644
index 000000000..9943a266c
--- /dev/null
+++ b/src/test/run-make/macos-fat-archive/lib.rs
@@ -0,0 +1,3 @@
+extern "C" {
+ pub fn native_func();
+}
diff --git a/src/test/run-make/macos-fat-archive/native-library.c b/src/test/run-make/macos-fat-archive/native-library.c
new file mode 100644
index 000000000..d300fdf1c
--- /dev/null
+++ b/src/test/run-make/macos-fat-archive/native-library.c
@@ -0,0 +1 @@
+void native_func() {}
diff --git a/src/test/run-make/native-link-modifier-verbatim-linker/Makefile b/src/test/run-make/native-link-modifier-verbatim-linker/Makefile
new file mode 100644
index 000000000..e56e1e94e
--- /dev/null
+++ b/src/test/run-make/native-link-modifier-verbatim-linker/Makefile
@@ -0,0 +1,15 @@
+# ignore-cross-compile
+# ignore-macos
+
+include ../../run-make-fulldeps/tools.mk
+
+all:
+ # Verbatim allows specify precise name.
+ $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_some_strange_name.ext
+ $(RUSTC) main.rs -Zunstable-options -l static:+verbatim=local_some_strange_name.ext
+
+ # With verbatim any other name cannot be used (local).
+ $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/liblocal_native_dep.a
+ $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep.a
+ $(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep.lib
+ $(RUSTC) main.rs -Zunstable-options -l static:+verbatim=local_native_dep 2>&1 | $(CGREP) "local_native_dep"
diff --git a/src/test/run-make/native-link-modifier-verbatim-linker/local_native_dep.rs b/src/test/run-make/native-link-modifier-verbatim-linker/local_native_dep.rs
new file mode 100644
index 000000000..59b6c92d2
--- /dev/null
+++ b/src/test/run-make/native-link-modifier-verbatim-linker/local_native_dep.rs
@@ -0,0 +1,4 @@
+#[no_mangle]
+pub fn local_native_f() -> i32 {
+ return 0;
+}
diff --git a/src/test/run-make/native-link-modifier-verbatim-linker/main.rs b/src/test/run-make/native-link-modifier-verbatim-linker/main.rs
new file mode 100644
index 000000000..71b73a489
--- /dev/null
+++ b/src/test/run-make/native-link-modifier-verbatim-linker/main.rs
@@ -0,0 +1,9 @@
+extern "C" {
+ fn local_native_f() -> i32;
+}
+
+pub fn main() {
+ unsafe {
+ assert!(local_native_f() == 0);
+ };
+}
diff --git a/src/test/run-make/native-link-modifier-verbatim-rustc/Makefile b/src/test/run-make/native-link-modifier-verbatim-rustc/Makefile
new file mode 100644
index 000000000..1093b1cd3
--- /dev/null
+++ b/src/test/run-make/native-link-modifier-verbatim-rustc/Makefile
@@ -0,0 +1,12 @@
+include ../../run-make-fulldeps/tools.mk
+
+all:
+ # Verbatim allows specify precise name.
+ $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_some_strange_name.ext
+ $(RUSTC) rust_dep.rs -Zunstable-options -l static:+verbatim=upstream_some_strange_name.ext --crate-type rlib
+
+ # With verbatim any other name cannot be used (upstream).
+ $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/libupstream_native_dep.a
+ $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep.a
+ $(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep.lib
+ $(RUSTC) rust_dep.rs -Zunstable-options -l static:+verbatim=upstream_native_dep --crate-type rlib 2>&1 | $(CGREP) "upstream_native_dep"
diff --git a/src/test/run-make/native-link-modifier-verbatim-rustc/rust_dep.rs b/src/test/run-make/native-link-modifier-verbatim-rustc/rust_dep.rs
new file mode 100644
index 000000000..e9517218e
--- /dev/null
+++ b/src/test/run-make/native-link-modifier-verbatim-rustc/rust_dep.rs
@@ -0,0 +1,9 @@
+extern "C" {
+ fn upstream_native_f() -> i32;
+}
+
+pub fn rust_dep() {
+ unsafe {
+ assert!(upstream_native_f() == 0);
+ }
+}
diff --git a/src/test/run-make/native-link-modifier-verbatim-rustc/upstream_native_dep.rs b/src/test/run-make/native-link-modifier-verbatim-rustc/upstream_native_dep.rs
new file mode 100644
index 000000000..839686233
--- /dev/null
+++ b/src/test/run-make/native-link-modifier-verbatim-rustc/upstream_native_dep.rs
@@ -0,0 +1,4 @@
+#[no_mangle]
+pub fn upstream_native_f() -> i32 {
+ return 0;
+}
diff --git a/src/test/run-make/rlib-format-packed-bundled-libs-2/Makefile b/src/test/run-make/rlib-format-packed-bundled-libs-2/Makefile
deleted file mode 100644
index 4574cf17f..000000000
--- a/src/test/run-make/rlib-format-packed-bundled-libs-2/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
--include ../../run-make-fulldeps/tools.mk
-
-# ignore-cross-compile
-
-# Make sure -Zpacked_bundled_libs is compatible with verbatim.
-
-# We're using the llvm-nm instead of the system nm to ensure it is compatible
-# with the LLVM bitcode generated by rustc.
-NM = "$(LLVM_BIN_DIR)"/llvm-nm
-
-all:
- # Build strange-named dep.
- $(RUSTC) native_dep.rs --crate-type=staticlib -o $(TMPDIR)/native_dep.ext
-
- $(RUSTC) rust_dep.rs --crate-type=rlib -Zpacked_bundled_libs
- $(NM) $(TMPDIR)/librust_dep.rlib | $(CGREP) -e "U.*native_f1"
- $(AR) t $(TMPDIR)/librust_dep.rlib | $(CGREP) "native_dep.ext"
-
- # Make sure compiler doesn't use files, that it shouldn't know about.
- rm $(TMPDIR)/native_dep.ext
-
- $(RUSTC) main.rs --extern rust_dep=$(TMPDIR)/librust_dep.rlib -Zpacked_bundled_libs
diff --git a/src/test/run-make/rlib-format-packed-bundled-libs-2/main.rs b/src/test/run-make/rlib-format-packed-bundled-libs-2/main.rs
deleted file mode 100644
index 8d2b8a285..000000000
--- a/src/test/run-make/rlib-format-packed-bundled-libs-2/main.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-extern crate rust_dep;
-
-pub fn main() {
- rust_dep::rust_dep();
-}
diff --git a/src/test/run-make/rlib-format-packed-bundled-libs-2/native_dep.rs b/src/test/run-make/rlib-format-packed-bundled-libs-2/native_dep.rs
deleted file mode 100644
index 321a8237e..000000000
--- a/src/test/run-make/rlib-format-packed-bundled-libs-2/native_dep.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-#[no_mangle]
-pub fn native_f1() -> i32 {
- return 1;
-}
diff --git a/src/test/run-make/rlib-format-packed-bundled-libs-2/rust_dep.rs b/src/test/run-make/rlib-format-packed-bundled-libs-2/rust_dep.rs
deleted file mode 100644
index d99dda05c..000000000
--- a/src/test/run-make/rlib-format-packed-bundled-libs-2/rust_dep.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-#![feature(native_link_modifiers_verbatim)]
-#[link(name = "native_dep.ext", kind = "static", modifiers = "+verbatim")]
-extern "C" {
- fn native_f1() -> i32;
-}
-
-pub fn rust_dep() {
- unsafe {
- assert!(native_f1() == 1);
- }
-}
diff --git a/src/test/run-make/rlib-format-packed-bundled-libs/Makefile b/src/test/run-make/rlib-format-packed-bundled-libs/Makefile
deleted file mode 100644
index 0b991ac42..000000000
--- a/src/test/run-make/rlib-format-packed-bundled-libs/Makefile
+++ /dev/null
@@ -1,34 +0,0 @@
--include ../../run-make-fulldeps/tools.mk
-
-# ignore-cross-compile
-
-# Make sure rlib format with -Zpacked_bundled_libs is correct.
-
-# We're using the llvm-nm instead of the system nm to ensure it is compatible
-# with the LLVM bitcode generated by rustc.
-NM = "$(LLVM_BIN_DIR)"/llvm-nm
-
-all: $(call NATIVE_STATICLIB,native_dep_1) $(call NATIVE_STATICLIB,native_dep_2) $(call NATIVE_STATICLIB,native_dep_3)
- $(RUSTC) rust_dep_up.rs --crate-type=rlib -Zpacked_bundled_libs
- $(NM) $(TMPDIR)/librust_dep_up.rlib | $(CGREP) -e "U.*native_f2"
- $(NM) $(TMPDIR)/librust_dep_up.rlib | $(CGREP) -e "U.*native_f3"
- $(NM) $(TMPDIR)/librust_dep_up.rlib | $(CGREP) -e "T.*rust_dep_up"
- $(AR) t $(TMPDIR)/librust_dep_up.rlib | $(CGREP) "native_dep_2"
- $(AR) t $(TMPDIR)/librust_dep_up.rlib | $(CGREP) "native_dep_3"
- $(RUSTC) rust_dep_local.rs --extern rlib=$(TMPDIR)/librust_dep_up.rlib -Zpacked_bundled_libs --crate-type=rlib
- $(NM) $(TMPDIR)/librust_dep_local.rlib | $(CGREP) -e "U.*native_f1"
- $(NM) $(TMPDIR)/librust_dep_local.rlib | $(CGREP) -e "T.*rust_dep_local"
- $(AR) t $(TMPDIR)/librust_dep_local.rlib | $(CGREP) "native_dep_1"
-
- # Make sure compiler doesn't use files, that it shouldn't know about.
- rm $(TMPDIR)/*native_dep_*
-
- $(RUSTC) main.rs --extern lib=$(TMPDIR)/librust_dep_local.rlib -o $(TMPDIR)/main.exe -Zpacked_bundled_libs --print link-args | $(CGREP) -e "native_dep_1.*native_dep_2.*native_dep_3"
-
-ifndef IS_MSVC
- $(NM) $(TMPDIR)/main.exe | $(CGREP) -e "T.*native_f1"
- $(NM) $(TMPDIR)/main.exe | $(CGREP) -e "T.*native_f2"
- $(NM) $(TMPDIR)/main.exe | $(CGREP) -e "T.*native_f3"
- $(NM) $(TMPDIR)/main.exe | $(CGREP) -e "T.*rust_dep_local"
- $(NM) $(TMPDIR)/main.exe | $(CGREP) -e "T.*rust_dep_up"
-endif
diff --git a/src/test/run-make/rlib-format-packed-bundled-libs/main.rs b/src/test/run-make/rlib-format-packed-bundled-libs/main.rs
deleted file mode 100644
index 042a4879f..000000000
--- a/src/test/run-make/rlib-format-packed-bundled-libs/main.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-extern crate rust_dep_local;
-pub fn main() {
- rust_dep_local::rust_dep_local();
-}
diff --git a/src/test/run-make/rlib-format-packed-bundled-libs/native_dep_1.c b/src/test/run-make/rlib-format-packed-bundled-libs/native_dep_1.c
deleted file mode 100644
index 07be8562c..000000000
--- a/src/test/run-make/rlib-format-packed-bundled-libs/native_dep_1.c
+++ /dev/null
@@ -1 +0,0 @@
-int native_f1() { return 1; }
diff --git a/src/test/run-make/rlib-format-packed-bundled-libs/native_dep_2.c b/src/test/run-make/rlib-format-packed-bundled-libs/native_dep_2.c
deleted file mode 100644
index a1b94e40d..000000000
--- a/src/test/run-make/rlib-format-packed-bundled-libs/native_dep_2.c
+++ /dev/null
@@ -1 +0,0 @@
-int native_f2() { return 2; }
diff --git a/src/test/run-make/rlib-format-packed-bundled-libs/native_dep_3.c b/src/test/run-make/rlib-format-packed-bundled-libs/native_dep_3.c
deleted file mode 100644
index f81f397a4..000000000
--- a/src/test/run-make/rlib-format-packed-bundled-libs/native_dep_3.c
+++ /dev/null
@@ -1 +0,0 @@
-int native_f3() { return 3; }
diff --git a/src/test/run-make/rlib-format-packed-bundled-libs/rust_dep_local.rs b/src/test/run-make/rlib-format-packed-bundled-libs/rust_dep_local.rs
deleted file mode 100644
index 8280c7d6c..000000000
--- a/src/test/run-make/rlib-format-packed-bundled-libs/rust_dep_local.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-#[link(name = "native_dep_1", kind = "static")]
-extern "C" {
- fn native_f1() -> i32;
-}
-
-extern crate rust_dep_up;
-
-pub fn rust_dep_local() {
- unsafe {
- assert!(native_f1() == 1);
- }
- rust_dep_up::rust_dep_up();
-}
diff --git a/src/test/run-make/rlib-format-packed-bundled-libs/rust_dep_up.rs b/src/test/run-make/rlib-format-packed-bundled-libs/rust_dep_up.rs
deleted file mode 100644
index edcd7c521..000000000
--- a/src/test/run-make/rlib-format-packed-bundled-libs/rust_dep_up.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-#[link(name = "native_dep_2", kind = "static")]
-#[link(name = "native_dep_3", kind = "static")]
-extern "C" {
- fn native_f2() -> i32;
- fn native_f3() -> i32;
-}
-
-pub fn rust_dep_up() {
- unsafe {
- assert!(native_f2() == 2);
- assert!(native_f3() == 3);
- }
-}
diff --git a/src/test/rustdoc-gui/anchor-navigable.goml b/src/test/rustdoc-gui/anchor-navigable.goml
index 424c31223..9d5c55a1e 100644
--- a/src/test/rustdoc-gui/anchor-navigable.goml
+++ b/src/test/rustdoc-gui/anchor-navigable.goml
@@ -4,8 +4,8 @@
// anchor and the `impl Foo`. If there were a gap, this would cause an annoying
// problem: you hover `impl Foo` to see the anchor, then when you move your
// mouse to the left, the anchor disappears before you reach it.
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
// We check that ".item-info" is bigger than its content.
move-cursor-to: ".impl"
-assert-property: (".impl > a.anchor", {"offsetWidth": "9"})
+assert-property: (".impl > a.anchor", {"offsetWidth": "8"})
assert-css: (".impl > a.anchor", {"left": "-8px"})
diff --git a/src/test/rustdoc-gui/anchors.goml b/src/test/rustdoc-gui/anchors.goml
index 3ad62c721..fb8e288fa 100644
--- a/src/test/rustdoc-gui/anchors.goml
+++ b/src/test/rustdoc-gui/anchors.goml
@@ -1,154 +1,107 @@
// This test is to ensure that the anchors (`§`) have the expected color and position.
-goto: file://|DOC_PATH|/staged_api/struct.Foo.html
-// This is needed to ensure that the text color is computed.
-show-text: true
-
-// Set the theme to light.
-local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
-// We reload the page so the local storage settings are being used.
-reload:
-
-assert-css: ("#toggle-all-docs", {"color": "rgb(0, 0, 0)"})
-assert-css: (".fqn .in-band a:nth-of-type(1)", {"color": "rgb(0, 0, 0)"})
-assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(173, 55, 138)"})
-assert-css: (
- ".rightside .srclink",
- {"color": "rgb(56, 115, 173)", "text-decoration": "none solid rgb(56, 115, 173)"},
- ALL,
-)
-compare-elements-css: (".rightside .srclink", ".rightside.srclink", ["color", "text-decoration"])
-compare-elements-css: (".main-heading .srclink", ".rightside.srclink", ["color", "text-decoration"])
-
-move-cursor-to: ".main-heading .srclink"
-assert-css: (
- ".main-heading .srclink",
- {"color": "rgb(56, 115, 173)", "text-decoration": "underline solid rgb(56, 115, 173)"},
-)
-move-cursor-to: ".impl-items .rightside .srclink"
-assert-css: (
- ".impl-items .rightside .srclink",
- {"color": "rgb(56, 115, 173)", "text-decoration": "none solid rgb(56, 115, 173)"},
-)
-move-cursor-to: ".impl-items .rightside.srclink"
-assert-css: (
- ".impl-items .rightside.srclink",
- {"color": "rgb(56, 115, 173)", "text-decoration": "none solid rgb(56, 115, 173)"},
-)
-
-goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
-
-assert-css: ("#top-doc-prose-title", {"color": "rgb(0, 0, 0)"})
-
-assert-css: (".sidebar a", {"color": "rgb(53, 109, 164)"})
-assert-css: (".in-band a", {"color": "rgb(0, 0, 0)"})
-
-// We move the cursor over the "Implementations" title so the anchor is displayed.
-move-cursor-to: "h2#implementations"
-assert-css: ("h2#implementations a.anchor", {"color": "rgb(0, 0, 0)"})
-
-// Same thing with the impl block title.
-move-cursor-to: "#impl-HeavilyDocumentedStruct"
-assert-css: ("#impl-HeavilyDocumentedStruct a.anchor", {"color": "rgb(0, 0, 0)"})
-
-assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"})
-
-//
-// We do the same checks with the dark theme now.
-//
-local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"}
-goto: file://|DOC_PATH|/staged_api/struct.Foo.html
-
-assert-css: ("#toggle-all-docs", {"color": "rgb(221, 221, 221)"})
-assert-css: (".fqn .in-band a:nth-of-type(1)", {"color": "rgb(221, 221, 221)"})
-assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(45, 191, 184)"})
-assert-css: (
- ".rightside .srclink",
- {"color": "rgb(210, 153, 29)", "text-decoration": "none solid rgb(210, 153, 29)"},
- ALL,
-)
-compare-elements-css: (".rightside .srclink", ".rightside.srclink", ["color", "text-decoration"])
-compare-elements-css: (".main-heading .srclink", ".rightside.srclink", ["color", "text-decoration"])
-
-move-cursor-to: ".main-heading .srclink"
-assert-css: (
- ".main-heading .srclink",
- {"color": "rgb(210, 153, 29)", "text-decoration": "underline solid rgb(210, 153, 29)"},
+define-function: (
+ "check-colors",
+ (theme, main_color, title_color, fqn_color, fqn_type_color, src_link_color, sidebar_link_color),
+ [
+ ("goto", "file://" + |DOC_PATH| + "/staged_api/struct.Foo.html"),
+ // This is needed to ensure that the text color is computed.
+ ("show-text", true),
+
+ // Setting the theme.
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ // We reload the page so the local storage settings are being used.
+ ("reload"),
+
+ ("assert-css", ("#toggle-all-docs", {"color": |main_color|})),
+ ("assert-css", (".fqn a:nth-of-type(1)", {"color": |fqn_color|})),
+ ("assert-css", (".fqn a:nth-of-type(2)", {"color": |fqn_type_color|})),
+ ("assert-css", (
+ ".rightside .srclink",
+ {"color": |src_link_color|, "text-decoration": "none solid " + |src_link_color|},
+ ALL,
+ )),
+ (
+ "compare-elements-css",
+ (".rightside .srclink", ".rightside.srclink", ["color", "text-decoration"]),
+ ),
+ (
+ "compare-elements-css",
+ (".main-heading .srclink", ".rightside.srclink", ["color", "text-decoration"]),
+ ),
+
+ ("move-cursor-to", ".main-heading .srclink"),
+ ("assert-css", (
+ ".main-heading .srclink",
+ {"color": |src_link_color|, "text-decoration": "underline solid " + |src_link_color|},
+ )),
+ ("move-cursor-to", ".impl-items .rightside .srclink"),
+ ("assert-css", (
+ ".impl-items .rightside .srclink",
+ {"color": |src_link_color|, "text-decoration": "none solid " + |src_link_color|},
+ )),
+ ("move-cursor-to", ".impl-items .rightside.srclink"),
+ ("assert-css", (
+ ".impl-items .rightside.srclink",
+ {"color": |src_link_color|, "text-decoration": "none solid " + |src_link_color|},
+ )),
+
+ ("goto", "file://" + |DOC_PATH| + "/test_docs/struct.HeavilyDocumentedStruct.html"),
+ // Since we changed page, we need to set the theme again.
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ // We reload the page so the local storage settings are being used.
+ ("reload"),
+
+ ("assert-css", ("#top-doc-prose-title", {"color": |title_color|})),
+
+ ("assert-css", (".sidebar a", {"color": |sidebar_link_color|})),
+ ("assert-css", ("h1.fqn a", {"color": |title_color|})),
+
+ // We move the cursor over the "Implementations" title so the anchor is displayed.
+ ("move-cursor-to", "h2#implementations"),
+ ("assert-css", ("h2#implementations a.anchor", {"color": |main_color|})),
+
+ // Same thing with the impl block title.
+ ("move-cursor-to", "#impl-HeavilyDocumentedStruct"),
+ ("assert-css", ("#impl-HeavilyDocumentedStruct a.anchor", {"color": |main_color|})),
+
+ ("assert-css", ("#title-for-struct-impl-item-doc", {"margin-left": "0px"})),
+ ],
)
-move-cursor-to: ".impl-items .rightside .srclink"
-assert-css: (
- ".impl-items .rightside .srclink",
- {"color": "rgb(210, 153, 29)", "text-decoration": "none solid rgb(210, 153, 29)"},
-)
-move-cursor-to: ".impl-items .rightside.srclink"
-assert-css: (
- ".impl-items .rightside.srclink",
- {"color": "rgb(210, 153, 29)", "text-decoration": "none solid rgb(210, 153, 29)"},
-)
-
-goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
-
-assert-css: ("#top-doc-prose-title", {"color": "rgb(221, 221, 221)"})
-
-assert-css: (".sidebar a", {"color": "rgb(253, 191, 53)"})
-assert-css: (".in-band a", {"color": "rgb(221, 221, 221)"})
-
-// We move the cursor over the "Implementations" title so the anchor is displayed.
-move-cursor-to: "h2#implementations"
-assert-css: ("h2#implementations a.anchor", {"color": "rgb(221, 221, 221)"})
-
-// Same thing with the impl block title.
-move-cursor-to: "#impl-HeavilyDocumentedStruct"
-assert-css: ("#impl-HeavilyDocumentedStruct a.anchor", {"color": "rgb(221, 221, 221)"})
-
-assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"})
-
-//
-// We do the same checks with the ayu theme now.
-//
-local-storage: {"rustdoc-theme": "ayu", "rustdoc-use-system-theme": "false"}
-goto: file://|DOC_PATH|/staged_api/struct.Foo.html
-assert-css: ("#toggle-all-docs", {"color": "rgb(197, 197, 197)"})
-assert-css: (".fqn .in-band a:nth-of-type(1)", {"color": "rgb(255, 255, 255)"})
-assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(255, 160, 165)"})
-assert-css: (
- ".rightside .srclink",
- {"color": "rgb(57, 175, 215)", "text-decoration": "none solid rgb(57, 175, 215)"},
- ALL,
+call-function: (
+ "check-colors",
+ {
+ "theme": "ayu",
+ "main_color": "rgb(197, 197, 197)",
+ "title_color": "rgb(255, 255, 255)",
+ "fqn_color": "rgb(255, 255, 255)",
+ "fqn_type_color": "rgb(255, 160, 165)",
+ "src_link_color": "rgb(57, 175, 215)",
+ "sidebar_link_color": "rgb(83, 177, 219)",
+ },
)
-compare-elements-css: (".rightside .srclink", ".rightside.srclink", ["color", "text-decoration"])
-compare-elements-css: (".main-heading .srclink", ".rightside.srclink", ["color", "text-decoration"])
-
-move-cursor-to: ".main-heading .srclink"
-assert-css: (
- ".main-heading .srclink",
- {"color": "rgb(57, 175, 215)", "text-decoration": "underline solid rgb(57, 175, 215)"},
-)
-move-cursor-to: ".impl-items .rightside .srclink"
-assert-css: (
- ".impl-items .rightside .srclink",
- {"color": "rgb(57, 175, 215)", "text-decoration": "none solid rgb(57, 175, 215)"},
+call-function: (
+ "check-colors",
+ {
+ "theme": "dark",
+ "main_color": "rgb(221, 221, 221)",
+ "title_color": "rgb(221, 221, 221)",
+ "fqn_color": "rgb(221, 221, 221)",
+ "fqn_type_color": "rgb(45, 191, 184)",
+ "src_link_color": "rgb(210, 153, 29)",
+ "sidebar_link_color": "rgb(253, 191, 53)",
+ },
)
-move-cursor-to: ".impl-items .rightside.srclink"
-assert-css: (
- ".impl-items .rightside.srclink",
- {"color": "rgb(57, 175, 215)", "text-decoration": "none solid rgb(57, 175, 215)"},
+call-function: (
+ "check-colors",
+ {
+ "theme": "light",
+ "main_color": "rgb(0, 0, 0)",
+ "title_color": "rgb(0, 0, 0)",
+ "fqn_color": "rgb(0, 0, 0)",
+ "fqn_type_color": "rgb(173, 55, 138)",
+ "src_link_color": "rgb(56, 115, 173)",
+ "sidebar_link_color": "rgb(53, 109, 164)",
+ },
)
-
-goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
-
-assert-css: ("#top-doc-prose-title", {"color": "rgb(255, 255, 255)"})
-
-assert-css: (".sidebar a", {"color": "rgb(83, 177, 219)"})
-assert-css: (".in-band a", {"color": "rgb(255, 255, 255)"})
-
-// We move the cursor over the "Implementations" title so the anchor is displayed.
-move-cursor-to: "h2#implementations"
-assert-css: ("h2#implementations a.anchor", {"color": "rgb(197, 197, 197)"})
-
-// Same thing with the impl block title.
-move-cursor-to: "#impl-HeavilyDocumentedStruct"
-assert-css: ("#impl-HeavilyDocumentedStruct a.anchor", {"color": "rgb(197, 197, 197)"})
-
-assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"})
diff --git a/src/test/rustdoc-gui/auto-hide-trait-implementations.goml b/src/test/rustdoc-gui/auto-hide-trait-implementations.goml
index 7b1358fed..0a619c352 100644
--- a/src/test/rustdoc-gui/auto-hide-trait-implementations.goml
+++ b/src/test/rustdoc-gui/auto-hide-trait-implementations.goml
@@ -1,5 +1,5 @@
// Checks that the setting "auto hide trait implementations" is working as expected.
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
// By default, the trait implementations are not collapsed.
assert-attribute: ("#trait-implementations-list > details", {"open": ""}, ALL)
diff --git a/src/test/rustdoc-gui/basic-code.goml b/src/test/rustdoc-gui/basic-code.goml
index 27deb2c98..f4ba5a128 100644
--- a/src/test/rustdoc-gui/basic-code.goml
+++ b/src/test/rustdoc-gui/basic-code.goml
@@ -1,3 +1,3 @@
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
click: ".srclink"
-assert-count: (".line-numbers", 1)
+assert-count: (".src-line-numbers", 1)
diff --git a/src/test/rustdoc-gui/basic.goml b/src/test/rustdoc-gui/basic.goml
index 239e51a91..60292835b 100644
--- a/src/test/rustdoc-gui/basic.goml
+++ b/src/test/rustdoc-gui/basic.goml
@@ -1,4 +1,4 @@
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
assert: ("#functions")
-goto: ./struct.Foo.html
+goto: "./struct.Foo.html"
assert: ("div.item-decl")
diff --git a/src/test/rustdoc-gui/check-code-blocks-margin.goml b/src/test/rustdoc-gui/check-code-blocks-margin.goml
index f6266eba7..c2cec0020 100644
--- a/src/test/rustdoc-gui/check-code-blocks-margin.goml
+++ b/src/test/rustdoc-gui/check-code-blocks-margin.goml
@@ -1,6 +1,6 @@
// This test ensures that the docblock elements have the appropriate left margin.
-goto: file://|DOC_PATH|/test_docs/fn.foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
// The top docblock elements shouldn't have left margin...
-assert-css: ("#main-content .docblock.item-decl", {"margin-left": "0px"})
+assert-css: ("#main-content .item-decl", {"margin-left": "0px"})
// ... but all the others should!
-assert-css: ("#main-content .docblock:not(.item-decl)", {"margin-left": "24px"})
+assert-css: ("#main-content .docblock", {"margin-left": "24px"})
diff --git a/src/test/rustdoc-gui/check-stab-in-docblock.goml b/src/test/rustdoc-gui/check-stab-in-docblock.goml
new file mode 100644
index 000000000..266fa9997
--- /dev/null
+++ b/src/test/rustdoc-gui/check-stab-in-docblock.goml
@@ -0,0 +1,27 @@
+// This test checks that using `.stab` attributes in `.docblock` elements doesn't
+// create scrollable paragraphs.
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
+// Needs the text to be display to check for scrollable content.
+show-text: true
+size: (786, 600)
+// Confirms that there 3 paragraphs.
+assert-count: (".top-doc .docblock p", 3)
+// Checking that there is no scrollable content.
+store-property: (clientHeight, ".top-doc .docblock p:nth-of-type(1)", "clientHeight")
+store-property: (clientWidth, ".top-doc .docblock p:nth-of-type(1)", "clientWidth")
+assert-property: (
+ ".top-doc .docblock p:nth-of-type(1)",
+ {"scrollHeight": |clientHeight|, "scrollWidth": |clientWidth|},
+)
+store-property: (clientHeight, ".top-doc .docblock p:nth-of-type(2)", "clientHeight")
+store-property: (clientWidth, ".top-doc .docblock p:nth-of-type(2)", "clientWidth")
+assert-property: (
+ ".top-doc .docblock p:nth-of-type(2)",
+ {"scrollHeight": |clientHeight|, "scrollWidth": |clientWidth|},
+)
+store-property: (clientHeight, ".top-doc .docblock p:nth-of-type(3)", "clientHeight")
+store-property: (clientWidth, ".top-doc .docblock p:nth-of-type(3)", "clientWidth")
+assert-property: (
+ ".top-doc .docblock p:nth-of-type(3)",
+ {"scrollHeight": |clientHeight|, "scrollWidth": |clientWidth|},
+)
diff --git a/src/test/rustdoc-gui/check_info_sign_position.goml b/src/test/rustdoc-gui/check_info_sign_position.goml
index 47a78f02f..f36e73fc5 100644
--- a/src/test/rustdoc-gui/check_info_sign_position.goml
+++ b/src/test/rustdoc-gui/check_info_sign_position.goml
@@ -1,7 +1,7 @@
// This test checks the position of the information on the code blocks (like
// `compile_fail` or `ignore`).
-goto: file://|DOC_PATH|/test_docs/index.html
-goto: ./fn.check_list_code_block.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
+goto: "./fn.check_list_code_block.html"
// If the codeblock is the first element of the docblock, the information tooltip must have
// have some top margin to avoid going over the toggle (the "[+]").
assert-css: (".docblock > .example-wrap.compile_fail .tooltip", { "margin-top": "16px" })
diff --git a/src/test/rustdoc-gui/code-blocks-overflow.goml b/src/test/rustdoc-gui/code-blocks-overflow.goml
index f93f3f0ae..fbf0e890b 100644
--- a/src/test/rustdoc-gui/code-blocks-overflow.goml
+++ b/src/test/rustdoc-gui/code-blocks-overflow.goml
@@ -1,8 +1,8 @@
// This test ensures that codeblocks content don't overflow.
-goto: file://|DOC_PATH|/lib2/sub_mod/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/lib2/sub_mod/struct.Foo.html"
size: (1080, 600)
// There should be two codeblocks: a rust one and a non-rust one.
assert-count: (".docblock > .example-wrap", 2)
assert: ".docblock > .example-wrap > .language-txt"
assert: ".docblock > .example-wrap > .rust-example-rendered"
-assert-css: (".docblock > .example-wrap > pre", {"width": "785.25px", "overflow-x": "auto"}, ALL)
+assert-css: (".docblock > .example-wrap > pre", {"width": "796px", "overflow-x": "auto"}, ALL)
diff --git a/src/test/rustdoc-gui/code-color.goml b/src/test/rustdoc-gui/code-color.goml
index 2f95bfb6b..118f04ad6 100644
--- a/src/test/rustdoc-gui/code-color.goml
+++ b/src/test/rustdoc-gui/code-color.goml
@@ -2,29 +2,23 @@
// check that the rule isn't applied on other "<code>" elements.
//
// While we're at it, we also check it for the other themes.
-goto: file://|DOC_PATH|/test_docs/fn.foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
// If the text isn't displayed, the browser doesn't compute color style correctly...
show-text: true
-// Set the theme to dark.
-local-storage: {"rustdoc-theme": "dark", "rustdoc-preferred-dark-theme": "dark", "rustdoc-use-system-theme": "false"}
-// We reload the page so the local storage settings are being used.
-reload:
-assert-css: (".docblock pre > code", {"color": "rgb(221, 221, 221)"}, ALL)
-assert-css: (".docblock > p > code", {"color": "rgb(221, 221, 221)"}, ALL)
+define-function: (
+ "check-colors",
+ (theme, doc_code_color, doc_inline_code_color),
+ [
+ // Set the theme.
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ // We reload the page so the local storage settings are being used.
+ ("reload"),
+ ("assert-css", (".docblock pre > code", {"color": |doc_code_color|}, ALL)),
+ ("assert-css", (".docblock > p > code", {"color": |doc_inline_code_color|}, ALL)),
+ ],
+)
-// Set the theme to ayu.
-local-storage: {"rustdoc-theme": "ayu", "rustdoc-preferred-dark-theme": "ayu", "rustdoc-use-system-theme": "false"}
-// We reload the page so the local storage settings are being used.
-reload:
-
-assert-css: (".docblock pre > code", {"color": "rgb(230, 225, 207)"}, ALL)
-assert-css: (".docblock > p > code", {"color": "rgb(255, 180, 84)"}, ALL)
-
-// Set the theme to light.
-local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
-// We reload the page so the local storage settings are being used.
-reload:
-
-assert-css: (".docblock pre > code", {"color": "rgb(0, 0, 0)"}, ALL)
-assert-css: (".docblock > p > code", {"color": "rgb(0, 0, 0)"}, ALL)
+call-function: ("check-colors", ("ayu", "rgb(230, 225, 207)", "rgb(255, 180, 84)"))
+call-function: ("check-colors", ("dark", "rgb(221, 221, 221)", "rgb(221, 221, 221)"))
+call-function: ("check-colors", ("light", "rgb(0, 0, 0)", "rgb(0, 0, 0)"))
diff --git a/src/test/rustdoc-gui/code-sidebar-toggle.goml b/src/test/rustdoc-gui/code-sidebar-toggle.goml
index 867db0569..00a0ea1e1 100644
--- a/src/test/rustdoc-gui/code-sidebar-toggle.goml
+++ b/src/test/rustdoc-gui/code-sidebar-toggle.goml
@@ -1,5 +1,5 @@
// This test checks that the source code pages sidebar toggle is working as expected.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
click: ".srclink"
wait-for: "#sidebar-toggle"
click: "#sidebar-toggle"
diff --git a/src/test/rustdoc-gui/code-tags.goml b/src/test/rustdoc-gui/code-tags.goml
index 8d399a9a5..837a2c1d5 100644
--- a/src/test/rustdoc-gui/code-tags.goml
+++ b/src/test/rustdoc-gui/code-tags.goml
@@ -1,5 +1,5 @@
// This test ensures that items and documentation code blocks are wrapped in <pre><code>
-goto: file://|DOC_PATH|/test_docs/fn.foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
size: (1080, 600)
// There should be four doc codeblocks.
// Check that their content is inside <pre><code>
@@ -7,14 +7,14 @@ assert-count: (".example-wrap pre > code", 4)
// Check that function signature is inside <pre><code>
assert: "pre.rust.fn > code"
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
assert: "pre.rust.struct > code"
-goto: file://|DOC_PATH|/test_docs/enum.AnEnum.html
+goto: "file://" + |DOC_PATH| + "/test_docs/enum.AnEnum.html"
assert: "pre.rust.enum > code"
-goto: file://|DOC_PATH|/test_docs/trait.AnotherOne.html
+goto: "file://" + |DOC_PATH| + "/test_docs/trait.AnotherOne.html"
assert: "pre.rust.trait > code"
-goto: file://|DOC_PATH|/test_docs/type.SomeType.html
+goto: "file://" + |DOC_PATH| + "/test_docs/type.SomeType.html"
assert: "pre.rust.typedef > code"
diff --git a/src/test/rustdoc-gui/codeblock-tooltip.goml b/src/test/rustdoc-gui/codeblock-tooltip.goml
index 21a9e120c..8e681a2a0 100644
--- a/src/test/rustdoc-gui/codeblock-tooltip.goml
+++ b/src/test/rustdoc-gui/codeblock-tooltip.goml
@@ -1,96 +1,80 @@
// Checking the colors of the codeblocks tooltips.
-goto: file://|DOC_PATH|/test_docs/fn.foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
show-text: true
-// Dark theme.
-local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"}
-reload:
-
-// compile_fail block
-assert-css: (".docblock .example-wrap.compile_fail .tooltip", {"color": "rgba(255, 0, 0, 0.5)"})
-assert-css: (".docblock .example-wrap.compile_fail", {"border-left": "2px solid rgba(255, 0, 0, 0.5)"})
-
-move-cursor-to: ".docblock .example-wrap.compile_fail"
-
-assert-css: (".docblock .example-wrap.compile_fail .tooltip", {"color": "rgb(255, 0, 0)"})
-assert-css: (".docblock .example-wrap.compile_fail", {"border-left": "2px solid rgb(255, 0, 0)"})
-
-// should_panic block
-assert-css: (".docblock .example-wrap.should_panic .tooltip", {"color": "rgba(255, 0, 0, 0.5)"})
-assert-css: (".docblock .example-wrap.should_panic", {"border-left": "2px solid rgba(255, 0, 0, 0.5)"})
-
-move-cursor-to: ".docblock .example-wrap.should_panic"
-
-assert-css: (".docblock .example-wrap.should_panic .tooltip", {"color": "rgb(255, 0, 0)"})
-assert-css: (".docblock .example-wrap.should_panic", {"border-left": "2px solid rgb(255, 0, 0)"})
-
-// ignore block
-assert-css: (".docblock .example-wrap.ignore .tooltip", {"color": "rgba(255, 142, 0, 0.6)"})
-assert-css: (".docblock .example-wrap.ignore", {"border-left": "2px solid rgba(255, 142, 0, 0.6)"})
-
-move-cursor-to: ".docblock .example-wrap.ignore"
-
-assert-css: (".docblock .example-wrap.ignore .tooltip", {"color": "rgb(255, 142, 0)"})
-assert-css: (".docblock .example-wrap.ignore", {"border-left": "2px solid rgb(255, 142, 0)"})
-
-
-// Light theme.
-local-storage: {"rustdoc-theme": "light"}
-reload:
-
-assert-css: (".docblock .example-wrap.compile_fail .tooltip", {"color": "rgba(255, 0, 0, 0.5)"})
-assert-css: (".docblock .example-wrap.compile_fail", {"border-left": "2px solid rgba(255, 0, 0, 0.5)"})
-
-move-cursor-to: ".docblock .example-wrap.compile_fail"
-
-assert-css: (".docblock .example-wrap.compile_fail .tooltip", {"color": "rgb(255, 0, 0)"})
-assert-css: (".docblock .example-wrap.compile_fail", {"border-left": "2px solid rgb(255, 0, 0)"})
-
-// should_panic block
-assert-css: (".docblock .example-wrap.should_panic .tooltip", {"color": "rgba(255, 0, 0, 0.5)"})
-assert-css: (".docblock .example-wrap.should_panic", {"border-left": "2px solid rgba(255, 0, 0, 0.5)"})
-
-move-cursor-to: ".docblock .example-wrap.should_panic"
-
-assert-css: (".docblock .example-wrap.should_panic .tooltip", {"color": "rgb(255, 0, 0)"})
-assert-css: (".docblock .example-wrap.should_panic", {"border-left": "2px solid rgb(255, 0, 0)"})
-
-// ignore block
-assert-css: (".docblock .example-wrap.ignore .tooltip", {"color": "rgba(255, 142, 0, 0.6)"})
-assert-css: (".docblock .example-wrap.ignore", {"border-left": "2px solid rgba(255, 142, 0, 0.6)"})
-
-move-cursor-to: ".docblock .example-wrap.ignore"
-
-assert-css: (".docblock .example-wrap.ignore .tooltip", {"color": "rgb(255, 142, 0)"})
-assert-css: (".docblock .example-wrap.ignore", {"border-left": "2px solid rgb(255, 142, 0)"})
-
-
-// Ayu theme.
-local-storage: {"rustdoc-theme": "ayu"}
-reload:
-
-assert-css: (".docblock .example-wrap.compile_fail .tooltip", {"color": "rgba(255, 0, 0, 0.5)"})
-assert-css: (".docblock .example-wrap.compile_fail", {"border-left": "2px solid rgba(255, 0, 0, 0.5)"})
-
-move-cursor-to: ".docblock .example-wrap.compile_fail"
-
-assert-css: (".docblock .example-wrap.compile_fail .tooltip", {"color": "rgb(255, 0, 0)"})
-assert-css: (".docblock .example-wrap.compile_fail", {"border-left": "2px solid rgb(255, 0, 0)"})
-
-// should_panic block
-assert-css: (".docblock .example-wrap.should_panic .tooltip", {"color": "rgba(255, 0, 0, 0.5)"})
-assert-css: (".docblock .example-wrap.should_panic", {"border-left": "2px solid rgba(255, 0, 0, 0.5)"})
-
-move-cursor-to: ".docblock .example-wrap.should_panic"
-
-assert-css: (".docblock .example-wrap.should_panic .tooltip", {"color": "rgb(255, 0, 0)"})
-assert-css: (".docblock .example-wrap.should_panic", {"border-left": "2px solid rgb(255, 0, 0)"})
-
-// ignore block
-assert-css: (".docblock .example-wrap.ignore .tooltip", {"color": "rgba(255, 142, 0, 0.6)"})
-assert-css: (".docblock .example-wrap.ignore", {"border-left": "2px solid rgba(255, 142, 0, 0.6)"})
-
-move-cursor-to: ".docblock .example-wrap.ignore"
-
-assert-css: (".docblock .example-wrap.ignore .tooltip", {"color": "rgb(255, 142, 0)"})
-assert-css: (".docblock .example-wrap.ignore", {"border-left": "2px solid rgb(255, 142, 0)"})
+define-function: (
+ "check-colors",
+ (theme),
+ [
+ // Setting the theme.
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ ("reload"),
+
+ // compile_fail block
+ ("assert-css", (
+ ".docblock .example-wrap.compile_fail .tooltip",
+ {"color": "rgba(255, 0, 0, 0.5)"},
+ )),
+ ("assert-css", (
+ ".docblock .example-wrap.compile_fail",
+ {"border-left": "2px solid rgba(255, 0, 0, 0.5)"},
+ )),
+
+ ("move-cursor-to", ".docblock .example-wrap.compile_fail"),
+
+ ("assert-css", (
+ ".docblock .example-wrap.compile_fail .tooltip",
+ {"color": "rgb(255, 0, 0)"},
+ )),
+ ("assert-css", (
+ ".docblock .example-wrap.compile_fail",
+ {"border-left": "2px solid rgb(255, 0, 0)"},
+ )),
+
+ // should_panic block
+ ("assert-css", (
+ ".docblock .example-wrap.should_panic .tooltip",
+ {"color": "rgba(255, 0, 0, 0.5)"},
+ )),
+ ("assert-css", (
+ ".docblock .example-wrap.should_panic",
+ {"border-left": "2px solid rgba(255, 0, 0, 0.5)"},
+ )),
+
+ ("move-cursor-to", ".docblock .example-wrap.should_panic"),
+
+ ("assert-css", (
+ ".docblock .example-wrap.should_panic .tooltip",
+ {"color": "rgb(255, 0, 0)"},
+ )),
+ ("assert-css", (
+ ".docblock .example-wrap.should_panic",
+ {"border-left": "2px solid rgb(255, 0, 0)"},
+ )),
+
+ // ignore block
+ ("assert-css", (
+ ".docblock .example-wrap.ignore .tooltip",
+ {"color": "rgba(255, 142, 0, 0.6)"},
+ )),
+ ("assert-css", (
+ ".docblock .example-wrap.ignore",
+ {"border-left": "2px solid rgba(255, 142, 0, 0.6)"},
+ )),
+
+ ("move-cursor-to", ".docblock .example-wrap.ignore"),
+
+ ("assert-css", (
+ ".docblock .example-wrap.ignore .tooltip",
+ {"color": "rgb(255, 142, 0)"},
+ )),
+ ("assert-css", (
+ ".docblock .example-wrap.ignore",
+ {"border-left": "2px solid rgb(255, 142, 0)"},
+ )),
+ ],
+)
+
+call-function: ("check-colors", ("ayu"))
+call-function: ("check-colors", ("dark"))
+call-function: ("check-colors", ("light"))
diff --git a/src/test/rustdoc-gui/default-settings.goml b/src/test/rustdoc-gui/default-settings.goml
index 90f0b087a..ab27b001e 100644
--- a/src/test/rustdoc-gui/default-settings.goml
+++ b/src/test/rustdoc-gui/default-settings.goml
@@ -2,7 +2,7 @@
//
// The "settings" crate uses "ayu" as default setting, which is what we will
// check.
-goto: file://|DOC_PATH|/settings/index.html
+goto: "file://" + |DOC_PATH| + "/settings/index.html"
// Wait a bit to be sure the default theme is applied.
// If the theme isn't applied, the command will time out.
wait-for-css: ("body", {"background-color": "rgb(15, 20, 25)"})
diff --git a/src/test/rustdoc-gui/docblock-big-code-mobile.goml b/src/test/rustdoc-gui/docblock-big-code-mobile.goml
index 02f79f1fc..9f8df44d7 100644
--- a/src/test/rustdoc-gui/docblock-big-code-mobile.goml
+++ b/src/test/rustdoc-gui/docblock-big-code-mobile.goml
@@ -1,7 +1,7 @@
// If we have a long `<code>`, we need to ensure that it'll be fully displayed on mobile, meaning
// that it'll be on two lines.
emulate: "iPhone 8" // it has the following size: (375, 667)
-goto: file://|DOC_PATH|/test_docs/long_code_block/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/long_code_block/index.html"
// We now check that the block is on two lines:
show-text: true // We need to enable text draw to be able to have the "real" size
// Little explanations for this test: if the text wasn't displayed on two lines, it would take
diff --git a/src/test/rustdoc-gui/docblock-code-block-line-number.goml b/src/test/rustdoc-gui/docblock-code-block-line-number.goml
index baf9651c4..911ee34be 100644
--- a/src/test/rustdoc-gui/docblock-code-block-line-number.goml
+++ b/src/test/rustdoc-gui/docblock-code-block-line-number.goml
@@ -1,8 +1,8 @@
// Checks that the setting "line numbers" is working as expected.
-goto: file://|DOC_PATH|/test_docs/fn.foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
// We check that without this setting, there is no line number displayed.
-assert-false: "pre.line-number"
+assert-false: "pre.example-line-numbers"
// We now set the setting to show the line numbers on code examples.
local-storage: {"rustdoc-line-numbers": "true" }
@@ -10,13 +10,30 @@ local-storage: {"rustdoc-line-numbers": "true" }
reload:
// We wait for them to be added into the DOM by the JS...
-wait-for: "pre.line-number"
+wait-for: "pre.example-line-numbers"
// If the test didn't fail, it means that it was found!
// Let's now check some CSS properties...
-assert-css: ("pre.line-number", {
+assert-css: ("pre.example-line-numbers", {
"margin": "0px",
"padding": "13px 8px",
"text-align": "right",
})
// The first code block has two lines so let's check its `<pre>` elements lists both of them.
-assert-text: ("pre.line-number", "1\n2")
+assert-text: ("pre.example-line-numbers", "1\n2")
+
+// Now, try changing the setting dynamically. We'll turn it off, using the settings menu,
+// and make sure it goes away.
+
+// First, open the settings menu.
+click: "#settings-menu"
+wait-for: "#settings"
+assert-css: ("#settings", {"display": "block"})
+
+// Then, click the toggle button.
+click: "input#line-numbers + .slider"
+wait-for: 100 // wait-for-false does not exist
+assert-false: "pre.example-line-numbers"
+
+// Finally, turn it on again.
+click: "input#line-numbers + .slider"
+wait-for: "pre.example-line-numbers"
diff --git a/src/test/rustdoc-gui/docblock-details.goml b/src/test/rustdoc-gui/docblock-details.goml
index f6287ade2..9ae571efb 100644
--- a/src/test/rustdoc-gui/docblock-details.goml
+++ b/src/test/rustdoc-gui/docblock-details.goml
@@ -1,5 +1,5 @@
// This ensures that the `<details>`/`<summary>` elements are displayed as expected.
-goto: file://|DOC_PATH|/test_docs/details/struct.Details.html
+goto: "file://" + |DOC_PATH| + "/test_docs/details/struct.Details.html"
show-text: true
local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"}
reload:
@@ -14,10 +14,21 @@ assert-css: (
// We now check that the `<summary>` doesn't have a bottom border and has the correct display.
assert-css: (
".top-doc .docblock summary h4",
- {"border-bottom": "0px none rgb(210, 210, 210)"},
+ {"border-bottom-width": "0px"},
)
// This allows to ensure that summary is on one line only!
assert-property: (".top-doc .docblock summary h4", {"offsetHeight": "33"})
assert-css: (".top-doc .docblock summary h4", {"margin-top": "15px", "margin-bottom": "5px"})
// So `33 + 15 + 5` == `53`
assert-property: (".top-doc .docblock summary", {"offsetHeight": "53"})
+
+// We now check the `<summary>` on a method.
+assert-css: (
+ ".method-toggle .docblock summary h4",
+ {"border-bottom-width": "0px"},
+)
+// This allows to ensure that summary is on one line only!
+assert-property: (".method-toggle .docblock summary h4", {"offsetHeight": "30"})
+assert-css: (".method-toggle .docblock summary h4", {"margin-top": "15px", "margin-bottom": "5px"})
+// So `30 + 15 + 5` == `50`
+assert-property: (".method-toggle .docblock summary", {"offsetHeight": "50"})
diff --git a/src/test/rustdoc-gui/docblock-table-overflow.goml b/src/test/rustdoc-gui/docblock-table-overflow.goml
index 7f97cf220..d8670089a 100644
--- a/src/test/rustdoc-gui/docblock-table-overflow.goml
+++ b/src/test/rustdoc-gui/docblock-table-overflow.goml
@@ -1,10 +1,10 @@
// This test ensures that the type declaration content overflow is handled inside the <pre> directly.
-goto: file://|DOC_PATH|/lib2/long_table/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/lib2/long_table/struct.Foo.html"
// We set a fixed size so there is no chance of "random" resize.
size: (1100, 800)
// Logically, the ".docblock" and the "<p>" should have the same scroll width.
compare-elements-property: (".top-doc .docblock", ".top-doc .docblock > p", ["scrollWidth"])
-assert-property: (".top-doc .docblock", {"scrollWidth": "801"})
+assert-property: (".top-doc .docblock", {"scrollWidth": "816"})
// However, since there is overflow in the <table>, its scroll width is bigger.
assert-property: (".top-doc .docblock table", {"scrollWidth": "1572"})
@@ -16,6 +16,6 @@ compare-elements-property: (
"#implementations-list > details .docblock > p",
["scrollWidth"],
)
-assert-property: ("#implementations-list > details .docblock", {"scrollWidth": "801"})
+assert-property: ("#implementations-list > details .docblock", {"scrollWidth": "816"})
// However, since there is overflow in the <table>, its scroll width is bigger.
assert-property: ("#implementations-list > details .docblock table", {"scrollWidth": "1572"})
diff --git a/src/test/rustdoc-gui/docblock-table.goml b/src/test/rustdoc-gui/docblock-table.goml
index 7263156ab..4e316ce0b 100644
--- a/src/test/rustdoc-gui/docblock-table.goml
+++ b/src/test/rustdoc-gui/docblock-table.goml
@@ -1,4 +1,4 @@
-goto: file://|DOC_PATH|/test_docs/doc_block_table/struct.DocBlockTable.html#method.func
+goto: "file://" + |DOC_PATH| + "/test_docs/doc_block_table/struct.DocBlockTable.html#method.func"
compare-elements-css: (".impl-items .docblock table th", ".top-doc .docblock table th", ["border"])
compare-elements-css: (".impl-items .docblock table td", ".top-doc .docblock table td", ["border"])
diff --git a/src/test/rustdoc-gui/duplicate-macro-reexport.goml b/src/test/rustdoc-gui/duplicate-macro-reexport.goml
index 9ea599062..496203c12 100644
--- a/src/test/rustdoc-gui/duplicate-macro-reexport.goml
+++ b/src/test/rustdoc-gui/duplicate-macro-reexport.goml
@@ -1,5 +1,5 @@
// This test ensures that there is no macro duplicates in the sidebar.
-goto: file://|DOC_PATH|/test_docs/macro.a.html
+goto: "file://" + |DOC_PATH| + "/test_docs/macro.a.html"
// Waiting for the elements in the sidebar to be rendered.
wait-for: ".sidebar-elems .macro"
// Check there is only one macro named "a" listed in the sidebar.
diff --git a/src/test/rustdoc-gui/escape-key.goml b/src/test/rustdoc-gui/escape-key.goml
index a5afb037d..78e9f2309 100644
--- a/src/test/rustdoc-gui/escape-key.goml
+++ b/src/test/rustdoc-gui/escape-key.goml
@@ -1,6 +1,6 @@
// This test ensures that the "Escape" shortcut is handled correctly based on the
// current content displayed.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
// First, we check that the search results are hidden when the Escape key is pressed.
write: (".search-input", "test")
// To be SURE that the search will be run.
diff --git a/src/test/rustdoc-gui/font-weight.goml b/src/test/rustdoc-gui/font-weight.goml
index 5f29fde66..8ba005b0c 100644
--- a/src/test/rustdoc-gui/font-weight.goml
+++ b/src/test/rustdoc-gui/font-weight.goml
@@ -1,6 +1,6 @@
// This test checks that the font weight is correctly applied.
-goto: file://|DOC_PATH|/lib2/struct.Foo.html
-assert-css: ("//*[@class='docblock item-decl']//a[text()='Alias']", {"font-weight": "400"})
+goto: "file://" + |DOC_PATH| + "/lib2/struct.Foo.html"
+assert-css: ("//*[@class='item-decl']//a[text()='Alias']", {"font-weight": "400"})
assert-css: (
"//*[@class='structfield small-section-header']//a[text()='Alias']",
{"font-weight": "400"},
@@ -9,17 +9,17 @@ assert-css: ("#method\.a_method > .code-header", {"font-weight": "600"})
assert-css: ("#associatedtype\.X > .code-header", {"font-weight": "600"})
assert-css: ("#associatedconstant\.Y > .code-header", {"font-weight": "600"})
-goto: file://|DOC_PATH|/test_docs/type.SomeType.html
+goto: "file://" + |DOC_PATH| + "/test_docs/type.SomeType.html"
assert-css: (".top-doc .docblock p", {"font-weight": "400"}, ALL)
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
-assert-css: (".impl-items .method", {"font-weight": "600"}, ALL)
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
+assert-css: (".impl-items .method > .code-header", {"font-weight": "600"}, ALL)
-goto: file://|DOC_PATH|/lib2/trait.Trait.html
+goto: "file://" + |DOC_PATH| + "/lib2/trait.Trait.html"
// This is a complex selector, so here's how it works:
//
-// * //*[@class='docblock item-decl'] — selects element of any tag with classes docblock and item-decl
+// * //*[@class='item-decl'] — selects element of any tag with classes docblock and item-decl
// * /pre[@class='rust trait'] — selects immediate child with tag pre and classes rust and trait
// * /code — selects immediate child with tag code
// * /a[@class='constant'] — selects immediate child with tag a and class constant
@@ -29,11 +29,11 @@ goto: file://|DOC_PATH|/lib2/trait.Trait.html
// This uses '/parent::*' as a proxy for the style of the text node.
// We can't just select the '<a>' because intermediate tags could be added.
assert-count: (
- "//*[@class='docblock item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*",
+ "//*[@class='item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*",
1,
)
assert-css: (
- "//*[@class='docblock item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*",
+ "//*[@class='item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*",
{"font-weight": "400"},
)
@@ -41,4 +41,4 @@ assert-count: (".methods .associatedtype", 1)
assert-css: (".methods .associatedtype", {"font-weight": "600"})
assert-count: (".methods .constant", 1)
assert-css: (".methods .constant", {"font-weight": "600"})
-assert-css: (".methods .method", {"font-weight": "600"})
+assert-css: (".methods .method > .code-header", {"font-weight": "600"})
diff --git a/src/test/rustdoc-gui/hash-item-expansion.goml b/src/test/rustdoc-gui/hash-item-expansion.goml
index 861f69283..3cf94f624 100644
--- a/src/test/rustdoc-gui/hash-item-expansion.goml
+++ b/src/test/rustdoc-gui/hash-item-expansion.goml
@@ -1,5 +1,5 @@
// This test ensures that the element corresponding to the hash is displayed.
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.borrow
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html#method.borrow"
// In the blanket implementations list, "Borrow" is the second one, hence the ":nth(2)".
assert-attribute: ("#blanket-implementations-list > details:nth-child(2)", {"open": ""})
// We first check that the impl block is open by default.
diff --git a/src/test/rustdoc-gui/headers-color.goml b/src/test/rustdoc-gui/headers-color.goml
index a47a9c8a1..c80a49c52 100644
--- a/src/test/rustdoc-gui/headers-color.goml
+++ b/src/test/rustdoc-gui/headers-color.goml
@@ -1,117 +1,70 @@
// This test check for headers text and background colors for the different themes.
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
-// This is needed so that the text color is computed.
-show-text: true
-
-// Ayu theme
-local-storage: {
- "rustdoc-theme": "ayu",
- "rustdoc-preferred-dark-theme": "ayu",
- "rustdoc-use-system-theme": "false",
-}
-reload:
-
-assert-css: (
- ".impl",
- {"color": "rgb(197, 197, 197)", "background-color": "rgba(0, 0, 0, 0)"},
- ALL,
-)
-assert-css: (
- ".impl .code-header",
- {"color": "rgb(230, 225, 207)", "background-color": "rgb(15, 20, 25)"},
- ALL,
+define-function: (
+ "check-colors",
+ (theme, color, code_header_color, focus_background_color, headings_color),
+ [
+ ("goto", "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"),
+ // This is needed so that the text color is computed.
+ ("show-text", true),
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ ("reload"),
+ ("assert-css", (
+ ".impl",
+ {"color": |color|, "background-color": "rgba(0, 0, 0, 0)"},
+ ALL,
+ )),
+ ("assert-css", (
+ ".impl .code-header",
+ {"color": |code_header_color|, "background-color": "rgba(0, 0, 0, 0)"},
+ ALL,
+ )),
+ ("goto", "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html#impl-Foo"),
+ ("assert-css", (
+ "#impl-Foo",
+ {"color": |color|, "background-color": |focus_background_color|},
+ )),
+ ("goto", "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html#method.must_use"),
+ ("assert-css", (
+ "#method\.must_use",
+ {"color": |color|, "background-color": |focus_background_color|},
+ ALL,
+ )),
+ ("goto", "file://" + |DOC_PATH| + "/test_docs/index.html"),
+ ("assert-css", (".small-section-header a", {"color": |color|}, ALL)),
+ ("goto", "file://" + |DOC_PATH| + "/test_docs/struct.HeavilyDocumentedStruct.html"),
+ // We select headings (h2, h3, h...).
+ ("assert-css", (".docblock > :not(p) > a", {"color": |headings_color|}, ALL)),
+ ],
)
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html#impl-Foo
-assert-css: (
- "#impl-Foo",
- {"color": "rgb(197, 197, 197)", "background-color": "rgba(255, 236, 164, 0.06)"},
+call-function: (
+ "check-colors",
+ {
+ "theme": "ayu",
+ "color": "rgb(197, 197, 197)",
+ "code_header_color": "rgb(230, 225, 207)",
+ "focus_background_color": "rgba(255, 236, 164, 0.06)",
+ "headings_color": "rgb(57, 175, 215)",
+ },
)
-
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.must_use
-assert-css: (
- "#method\.must_use",
- {"color": "rgb(197, 197, 197)", "background-color": "rgba(255, 236, 164, 0.06)"},
- ALL,
+call-function: (
+ "check-colors",
+ {
+ "theme": "dark",
+ "color": "rgb(221, 221, 221)",
+ "code_header_color": "rgb(221, 221, 221)",
+ "focus_background_color": "rgb(73, 74, 61)",
+ "headings_color": "rgb(210, 153, 29)",
+ },
)
-
-goto: file://|DOC_PATH|/test_docs/index.html
-assert-css: (".small-section-header a", {"color": "rgb(197, 197, 197)"}, ALL)
-
-goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
-// We select headings (h2, h3, h...).
-assert-css: (".docblock > :not(p) > a", {"color": "rgb(57, 175, 215)"}, ALL)
-
-// Dark theme
-local-storage: {
- "rustdoc-theme": "dark",
- "rustdoc-preferred-dark-theme": "dark",
- "rustdoc-use-system-theme": "false",
-}
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
-
-assert-css: (
- ".impl",
- {"color": "rgb(221, 221, 221)", "background-color": "rgba(0, 0, 0, 0)"},
- ALL,
-)
-assert-css: (
- ".impl .code-header",
- {"color": "rgb(221, 221, 221)", "background-color": "rgb(53, 53, 53)"},
- ALL,
-)
-
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html#impl-Foo
-assert-css: (
- "#impl-Foo",
- {"color": "rgb(221, 221, 221)", "background-color": "rgb(73, 74, 61)"},
-)
-
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.must_use
-assert-css: (
- "#method\.must_use",
- {"color": "rgb(221, 221, 221)", "background-color": "rgb(73, 74, 61)"},
- ALL,
+call-function: (
+ "check-colors",
+ {
+ "theme": "light",
+ "color": "rgb(0, 0, 0)",
+ "code_header_color": "rgb(0, 0, 0)",
+ "focus_background_color": "rgb(253, 255, 211)",
+ "headings_color": "rgb(56, 115, 173)",
+ },
)
-
-goto: file://|DOC_PATH|/test_docs/index.html
-assert-css: (".small-section-header a", {"color": "rgb(221, 221, 221)"}, ALL)
-
-goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
-// We select headings (h2, h3, h...).
-assert-css: (".docblock > :not(p) > a", {"color": "rgb(210, 153, 29)"}, ALL)
-
-// Light theme
-local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
-reload:
-
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
-
-assert-css: (
- ".impl",
- {"color": "rgb(0, 0, 0)", "background-color": "rgba(0, 0, 0, 0)"},
- ALL,
-)
-assert-css: (
- ".impl .code-header",
- {"color": "rgb(0, 0, 0)", "background-color": "rgb(255, 255, 255)"},
- ALL,
-)
-
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html#impl-Foo
-assert-css: ("#impl-Foo", {"color": "rgb(0, 0, 0)", "background-color": "rgb(253, 255, 211)"})
-
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html#method.must_use
-assert-css: (
- "#method\.must_use",
- {"color": "rgb(0, 0, 0)", "background-color": "rgb(253, 255, 211)"},
- ALL,
-)
-
-goto: file://|DOC_PATH|/test_docs/index.html
-assert-css: (".small-section-header a", {"color": "rgb(0, 0, 0)"}, ALL)
-
-goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
-// We select headings (h2, h3, h...).
-assert-css: (".docblock > :not(p) > a", {"color": "rgb(56, 115, 173)"}, ALL)
diff --git a/src/test/rustdoc-gui/headings.goml b/src/test/rustdoc-gui/headings.goml
index ed07e777b..85e17ca95 100644
--- a/src/test/rustdoc-gui/headings.goml
+++ b/src/test/rustdoc-gui/headings.goml
@@ -11,7 +11,7 @@
// 18px 1.125em
// 16px 1rem
// 14px 0.875rem
-goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.HeavilyDocumentedStruct.html"
assert-css: ("h1.fqn", {"font-size": "24px"})
@@ -50,7 +50,7 @@ assert-css: ("h6#sub-heading-for-struct-impl-item-doc", {"font-size": "14px"})
assert-css: ("h6#sub-heading-for-struct-impl-item-doc", {"border-bottom-width": "0px"})
assert-css: ("h6#sub-sub-heading-for-struct-impl-item-doc", {"font-size": "14px"})
-goto: file://|DOC_PATH|/test_docs/enum.HeavilyDocumentedEnum.html
+goto: "file://" + |DOC_PATH| + "/test_docs/enum.HeavilyDocumentedEnum.html"
assert-css: ("h1.fqn", {"font-size": "24px"})
@@ -106,10 +106,10 @@ assert-css: ("h6#sub-heading-for-enum-impl-item-doc", {"border-bottom-width": "0
assert-css: ("h6#sub-sub-heading-for-enum-impl-item-doc", {"font-size": "14px"})
assert-css: ("h6#sub-sub-heading-for-enum-impl-item-doc", {"border-bottom-width": "0px"})
-assert-text: (".sidebar .mod h3", "Modules")
-assert-css: (".sidebar .mod h3", {"border-bottom-width": "0px"}, ALL)
+assert-text: ("//ul[@class='block mod']/preceding-sibling::h3", "Modules")
+assert-css: ("//ul[@class='block mod']/preceding-sibling::h3", {"border-bottom-width": "0px"}, ALL)
-goto: file://|DOC_PATH|/test_docs/union.HeavilyDocumentedUnion.html
+goto: "file://" + |DOC_PATH| + "/test_docs/union.HeavilyDocumentedUnion.html"
assert-css: ("h1.fqn", {"font-size": "24px"})
@@ -141,7 +141,7 @@ assert-css: ("h5#title-for-union-impl-item-doc", {"border-bottom-width": "0px"})
assert-css: ("h6#sub-heading-for-union-impl-item-doc", {"font-size": "14px"})
assert-css: ("h6#sub-heading-for-union-impl-item-doc", {"border-bottom-width": "0px"})
-goto: file://|DOC_PATH|/test_docs/macro.heavily_documented_macro.html
+goto: "file://" + |DOC_PATH| + "/test_docs/macro.heavily_documented_macro.html"
assert-css: ("h1.fqn", {"font-size": "24px"})
@@ -150,109 +150,85 @@ assert-css: ("h2#top-doc-prose-title", {"border-bottom-width": "1px"})
assert-css: ("h3#top-doc-prose-sub-heading", {"font-size": "20px"})
assert-css: ("h3#top-doc-prose-sub-heading", {"border-bottom-width": "1px"})
-// Checking colors now.
+// Needed to check colors
show-text: true
-local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
-goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
-assert-css: (
- ".top-doc .docblock h2",
- {"color": "rgb(0, 0, 0)", "border-bottom": "1px solid rgb(221, 221, 221)"},
-)
-assert-css: (
- ".top-doc .docblock h3",
- {"color": "rgb(0, 0, 0)", "border-bottom": "1px solid rgb(221, 221, 221)"},
-)
-assert-css: (
- ".top-doc .docblock h4",
- {"color": "rgb(0, 0, 0)", "border-bottom": "1px solid rgb(221, 221, 221)"},
-)
-assert-css: (
- ".top-doc .docblock h5",
- {"color": "rgb(0, 0, 0)", "border-bottom": "0px none rgb(221, 221, 221)"},
-)
-assert-css: (
- "#implementations-list .docblock h4",
- {"color": "rgb(0, 0, 0)", "border-bottom": "0px none rgb(221, 221, 221)"},
-)
-assert-css: (
- "#implementations-list .docblock h5",
- {"color": "rgb(0, 0, 0)", "border-bottom": "0px none rgb(221, 221, 221)"},
-)
-assert-css: (
- "#implementations-list .docblock h6",
- {"color": "rgb(0, 0, 0)", "border-bottom": "0px none rgb(221, 221, 221)"},
-)
-
-local-storage: {"rustdoc-theme": "dark"}
-reload:
-assert-css: (
- ".top-doc .docblock h2",
- {"color": "rgb(221, 221, 221)", "border-bottom": "1px solid rgb(210, 210, 210)"},
-)
-assert-css: (
- ".top-doc .docblock h3",
- {"color": "rgb(221, 221, 221)", "border-bottom": "1px solid rgb(210, 210, 210)"},
-)
-assert-css: (
- ".top-doc .docblock h4",
- {"color": "rgb(221, 221, 221)", "border-bottom": "1px solid rgb(210, 210, 210)"},
-)
-assert-css: (
- ".top-doc .docblock h5",
- {"color": "rgb(221, 221, 221)", "border-bottom": "0px none rgb(210, 210, 210)"},
-)
-assert-css: (
- "#implementations-list .docblock h4",
- {"color": "rgb(221, 221, 221)", "border-bottom": "0px none rgb(210, 210, 210)"},
-)
-assert-css: (
- "#implementations-list .docblock h5",
- {"color": "rgb(221, 221, 221)", "border-bottom": "0px none rgb(210, 210, 210)"},
-)
-assert-css: (
- "#implementations-list .docblock h6",
- {"color": "rgb(221, 221, 221)", "border-bottom": "0px none rgb(210, 210, 210)"},
-)
-
-local-storage: {"rustdoc-theme": "ayu"}
-reload:
-assert-css: (
- ".top-doc .docblock h2",
- {"color": "rgb(255, 255, 255)", "border-bottom": "1px solid rgb(92, 103, 115)"},
-)
-assert-css: (
- ".top-doc .docblock h2",
- {"color": "rgb(255, 255, 255)", "border-bottom": "1px solid rgb(92, 103, 115)"},
-)
-assert-css: (
- ".top-doc .docblock h4",
- {"color": "rgb(255, 255, 255)", "border-bottom": "1px solid rgb(92, 103, 115)"},
-)
-assert-css: (
- ".top-doc .docblock h5",
- {"color": "rgb(197, 197, 197)", "border-bottom": "0px none rgb(92, 103, 115)"},
-)
-assert-css: (
- "#implementations-list .docblock h4",
- {"color": "rgb(255, 255, 255)", "border-bottom": "0px none rgb(92, 103, 115)"},
-)
-assert-css: (
- "#implementations-list .docblock h5",
- {"color": "rgb(197, 197, 197)", "border-bottom": "0px none rgb(92, 103, 115)"},
-)
-assert-css: (
- "#implementations-list .docblock h6",
- {"color": "rgb(197, 197, 197)", "border-bottom": "0px none rgb(92, 103, 115)"},
-)
-
-local-storage: {"rustdoc-theme": "light"}
-goto: file://|DOC_PATH|/staged_api/struct.Foo.html
-assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL)
-
-local-storage: {"rustdoc-theme": "dark"}
-reload:
-assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL)
-
-local-storage: {"rustdoc-theme": "ayu"}
-reload:
-assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL)
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.HeavilyDocumentedStruct.html"
+
+define-function: (
+ "check-colors",
+ (theme, heading_color, small_heading_color, heading_border_color),
+ [
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ ("reload"),
+ ("assert-css", (
+ ".top-doc .docblock h2",
+ {"color": |heading_color|, "border-bottom": "1px solid " + |heading_border_color|},
+ )),
+ ("assert-css", (
+ ".top-doc .docblock h3",
+ {"color": |heading_color|, "border-bottom": "1px solid " + |heading_border_color|},
+ )),
+ ("assert-css", (
+ ".top-doc .docblock h4",
+ {"color": |heading_color|, "border-bottom": "1px solid " + |heading_border_color|},
+ )),
+ ("assert-css", (
+ ".top-doc .docblock h5",
+ {"color": |small_heading_color|, "border-bottom-width": "0px"},
+ )),
+ ("assert-css", (
+ "#implementations-list .docblock h4",
+ {"color": |heading_color|, "border-bottom-width": "0px"},
+ )),
+ ("assert-css", (
+ "#implementations-list .docblock h5",
+ {"color": |small_heading_color|, "border-bottom-width": "0px"},
+ )),
+ ("assert-css", (
+ "#implementations-list .docblock h6",
+ {"color": |small_heading_color|, "border-bottom-width": "0px"},
+ )),
+ ],
+)
+call-function: (
+ "check-colors",
+ {
+ "theme": "ayu",
+ "heading_color": "rgb(255, 255, 255)",
+ "small_heading_color": "rgb(197, 197, 197)",
+ "heading_border_color": "rgb(92, 103, 115)",
+ },
+)
+call-function: (
+ "check-colors",
+ {
+ "theme": "dark",
+ "heading_color": "rgb(221, 221, 221)",
+ "small_heading_color": "rgb(221, 221, 221)",
+ "heading_border_color": "rgb(210, 210, 210)",
+ },
+)
+call-function: (
+ "check-colors",
+ {
+ "theme": "light",
+ "heading_color": "rgb(0, 0, 0)",
+ "small_heading_color": "rgb(0, 0, 0)",
+ "heading_border_color": "rgb(221, 221, 221)",
+ },
+)
+
+define-function: (
+ "check-since-color",
+ (theme),
+ [
+ ("local-storage", {"rustdoc-theme": |theme|}),
+ ("reload"),
+ ("assert-css", (".since", {"color": "rgb(128, 128, 128)"}, ALL)),
+ ],
+)
+
+goto: "file://" + |DOC_PATH| + "/staged_api/struct.Foo.html"
+call-function: ("check-since-color", ("ayu"))
+call-function: ("check-since-color", ("dark"))
+call-function: ("check-since-color", ("light"))
diff --git a/src/test/rustdoc-gui/help-page.goml b/src/test/rustdoc-gui/help-page.goml
new file mode 100644
index 000000000..521e14748
--- /dev/null
+++ b/src/test/rustdoc-gui/help-page.goml
@@ -0,0 +1,24 @@
+// This test ensures that opening the help page in its own tab works.
+goto: "file://" + |DOC_PATH| + "/help.html"
+size: (1000, 1000) // Try desktop size first.
+wait-for: "#help"
+assert-css: ("#help", {"display": "block"})
+click: "#help-button > a"
+assert-css: ("#help", {"display": "block"})
+compare-elements-property: (".sub", "#help", ["offsetWidth"])
+compare-elements-position: (".sub", "#help", ("x"))
+size: (500, 1000) // Try mobile next.
+assert-css: ("#help", {"display": "block"})
+compare-elements-property: (".sub", "#help", ["offsetWidth"])
+compare-elements-position: (".sub", "#help", ("x"))
+
+// This test ensures that opening the help popover without switching pages works.
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
+size: (1000, 1000) // Only supported on desktop.
+assert-false: "#help"
+click: "#help-button > a"
+assert-css: ("#help", {"display": "block"})
+click: "#help-button > a"
+assert-css: ("#help", {"display": "none"})
+compare-elements-property-false: (".sub", "#help", ["offsetWidth"])
+compare-elements-position-false: (".sub", "#help", ("x"))
diff --git a/src/test/rustdoc-gui/highlight-colors.goml b/src/test/rustdoc-gui/highlight-colors.goml
new file mode 100644
index 000000000..51693314e
--- /dev/null
+++ b/src/test/rustdoc-gui/highlight-colors.goml
@@ -0,0 +1,94 @@
+// This test checks the highlight colors in the source code pages.
+goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
+show-text: true
+
+define-function: (
+ "check-colors",
+ (
+ theme,
+ kw,
+ kw2,
+ prelude_ty,
+ prelude_val,
+ lifetime,
+ number,
+ string,
+ bool_val,
+ self,
+ attribute,
+ macro,
+ question_mark,
+ comment,
+ doc_comment,
+ ),
+ [
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ ("reload"),
+ ("assert-css", ("pre.rust .kw", {"color": |kw|}, ALL)),
+ ("assert-css", ("pre.rust .kw-2", {"color": |kw2|}, ALL)),
+ ("assert-css", ("pre.rust .prelude-ty", {"color": |prelude_ty|}, ALL)),
+ ("assert-css", ("pre.rust .prelude-val", {"color": |prelude_val|}, ALL)),
+ ("assert-css", ("pre.rust .lifetime", {"color": |lifetime|}, ALL)),
+ ("assert-css", ("pre.rust .number", {"color": |number|}, ALL)),
+ ("assert-css", ("pre.rust .string", {"color": |string|}, ALL)),
+ ("assert-css", ("pre.rust .bool-val", {"color": |bool_val|}, ALL)),
+ ("assert-css", ("pre.rust .self", {"color": |self|}, ALL)),
+ ("assert-css", ("pre.rust .attribute", {"color": |attribute|}, ALL)),
+ ("assert-css", ("pre.rust .macro", {"color": |macro|}, ALL)),
+ ("assert-css", ("pre.rust .question-mark", {"color": |question_mark|}, ALL)),
+ ("assert-css", ("pre.rust .comment", {"color": |comment|}, ALL)),
+ ("assert-css", ("pre.rust .doccomment", {"color": |doc_comment|}, ALL)),
+ ],
+)
+
+call-function: ("check-colors", {
+ "theme": "ayu",
+ "kw": "rgb(255, 119, 51)",
+ "kw2": "rgb(255, 119, 51)",
+ "prelude_ty": "rgb(105, 242, 223)",
+ "prelude_val": "rgb(255, 119, 51)",
+ "lifetime": "rgb(255, 119, 51)",
+ "number": "rgb(184, 204, 82)",
+ "string": "rgb(184, 204, 82)",
+ "bool_val": "rgb(255, 119, 51)",
+ "self": "rgb(54, 163, 217)",
+ "attribute": "rgb(230, 225, 207)",
+ "macro": "rgb(163, 122, 204)",
+ "question_mark": "rgb(255, 144, 17)",
+ "comment": "rgb(120, 135, 151)",
+ "doc_comment": "rgb(161, 172, 136)",
+})
+call-function: ("check-colors", {
+ "theme": "dark",
+ "kw": "rgb(171, 138, 193)",
+ "kw2": "rgb(118, 154, 203)",
+ "prelude_ty": "rgb(118, 154, 203)",
+ "prelude_val": "rgb(238, 104, 104)",
+ "lifetime": "rgb(217, 127, 38)",
+ "number": "rgb(131, 163, 0)",
+ "string": "rgb(131, 163, 0)",
+ "bool_val": "rgb(238, 104, 104)",
+ "self": "rgb(238, 104, 104)",
+ "attribute": "rgb(238, 104, 104)",
+ "macro": "rgb(62, 153, 159)",
+ "question_mark": "rgb(255, 144, 17)",
+ "comment": "rgb(141, 141, 139)",
+ "doc_comment": "rgb(140, 163, 117)",
+})
+call-function: ("check-colors", {
+ "theme": "light",
+ "kw": "rgb(137, 89, 168)",
+ "kw2": "rgb(66, 113, 174)",
+ "prelude_ty": "rgb(66, 113, 174)",
+ "prelude_val": "rgb(200, 40, 41)",
+ "lifetime": "rgb(183, 101, 20)",
+ "number": "rgb(113, 140, 0)",
+ "string": "rgb(113, 140, 0)",
+ "bool_val": "rgb(200, 40, 41)",
+ "self": "rgb(200, 40, 41)",
+ "attribute": "rgb(200, 40, 41)",
+ "macro": "rgb(62, 153, 159)",
+ "question_mark": "rgb(255, 144, 17)",
+ "comment": "rgb(142, 144, 140)",
+ "doc_comment": "rgb(77, 77, 76)",
+})
diff --git a/src/test/rustdoc-gui/huge-collection-of-constants.goml b/src/test/rustdoc-gui/huge-collection-of-constants.goml
index 4f75b5841..3ccd33f1c 100644
--- a/src/test/rustdoc-gui/huge-collection-of-constants.goml
+++ b/src/test/rustdoc-gui/huge-collection-of-constants.goml
@@ -1,6 +1,6 @@
// Make sure that the last two entries are more than 12 pixels apart and not stacked on each other.
-goto: file://|DOC_PATH|/test_docs/huge_amount_of_consts/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/huge_amount_of_consts/index.html"
compare-elements-position-near-false: (
"//*[@class='item-table']//div[last()-1]",
diff --git a/src/test/rustdoc-gui/impl-default-expansion.goml b/src/test/rustdoc-gui/impl-default-expansion.goml
index 6df2661e6..c3f9240cc 100644
--- a/src/test/rustdoc-gui/impl-default-expansion.goml
+++ b/src/test/rustdoc-gui/impl-default-expansion.goml
@@ -1,3 +1,3 @@
// This test ensures that the impl blocks are open by default.
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
assert-attribute: ("#implementations-list details.implementors-toggle", {"open": ""})
diff --git a/src/test/rustdoc-gui/implementors.goml b/src/test/rustdoc-gui/implementors.goml
index 666a6e125..4999283dc 100644
--- a/src/test/rustdoc-gui/implementors.goml
+++ b/src/test/rustdoc-gui/implementors.goml
@@ -1,6 +1,6 @@
// The goal of this test is to check that the external trait implementors, generated with JS,
// have the same display than the "local" ones.
-goto: file://|DOC_PATH|/implementors/trait.Whatever.html
+goto: "file://" + |DOC_PATH| + "/implementors/trait.Whatever.html"
assert: "#implementors-list"
// There are supposed to be two implementors listed.
assert-count: ("#implementors-list .impl", 2)
@@ -8,28 +8,28 @@ assert-count: ("#implementors-list .impl", 2)
assert: ("#implementors-list .impl:nth-child(1) > a.anchor")
assert-attribute: ("#implementors-list .impl:nth-child(1)", {"id": "impl-Whatever-for-Struct"})
assert-attribute: ("#implementors-list .impl:nth-child(1) > a.anchor", {"href": "#impl-Whatever-for-Struct"})
-assert: "#implementors-list .impl:nth-child(1) > .code-header.in-band"
+assert: "#implementors-list .impl:nth-child(1) > .code-header"
assert: ("#implementors-list .impl:nth-child(2) > a.anchor")
assert-attribute: ("#implementors-list .impl:nth-child(2)", {"id": "impl-Whatever-1"})
assert-attribute: ("#implementors-list .impl:nth-child(2) > a.anchor", {"href": "#impl-Whatever-1"})
-assert: "#implementors-list .impl:nth-child(2) > .code-header.in-band"
+assert: "#implementors-list .impl:nth-child(2) > .code-header"
-goto: file://|DOC_PATH|/test_docs/struct.HasEmptyTraits.html
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.HasEmptyTraits.html"
compare-elements-position-near-false: (
"#impl-EmptyTrait1-for-HasEmptyTraits",
"#impl-EmptyTrait2-for-HasEmptyTraits",
- {"y": 30},
+ {"y": 34},
)
compare-elements-position-near: (
"#impl-EmptyTrait3-for-HasEmptyTraits h3",
"#impl-EmptyTrait3-for-HasEmptyTraits .item-info",
- {"y": 30},
+ {"y": 34},
)
// Now check that re-exports work correctly.
// There should be exactly one impl shown on both of these pages.
-goto: file://|DOC_PATH|/lib2/trait.TraitToReexport.html
+goto: "file://" + |DOC_PATH| + "/lib2/trait.TraitToReexport.html"
assert-count: ("#implementors-list .impl", 1)
-goto: file://|DOC_PATH|/implementors/trait.TraitToReexport.html
+goto: "file://" + |DOC_PATH| + "/implementors/trait.TraitToReexport.html"
assert-count: ("#implementors-list .impl", 1)
diff --git a/src/test/rustdoc-gui/item-decl-colors.goml b/src/test/rustdoc-gui/item-decl-colors.goml
new file mode 100644
index 000000000..ce688287a
--- /dev/null
+++ b/src/test/rustdoc-gui/item-decl-colors.goml
@@ -0,0 +1,74 @@
+// This test ensures that the color of the items in the type decl are working as expected.
+define-function: (
+ "check-colors",
+ (
+ theme,
+ attr_color,
+ trait_color,
+ struct_color,
+ enum_color,
+ primitive_color,
+ constant_color,
+ fn_color,
+ assoc_type_color,
+ ),
+ [
+ ("goto", "file://" + |DOC_PATH| + "/test_docs/struct.WithGenerics.html"),
+ ("show-text", true),
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ ("reload"),
+ ("assert-css", (".item-decl .code-attribute", {"color": |attr_color|}, ALL)),
+ ("assert-css", (".item-decl .trait", {"color": |trait_color|}, ALL)),
+ // We need to add `code` here because otherwise it would select the parent too.
+ ("assert-css", (".item-decl code .struct", {"color": |struct_color|}, ALL)),
+ ("assert-css", (".item-decl .enum", {"color": |enum_color|}, ALL)),
+ ("assert-css", (".item-decl .primitive", {"color": |primitive_color|}, ALL)),
+ ("goto", "file://" + |DOC_PATH| + "/test_docs/trait.TraitWithoutGenerics.html"),
+ ("assert-css", (".item-decl .constant", {"color": |constant_color|}, ALL)),
+ ("assert-css", (".item-decl .fnname", {"color": |fn_color|}, ALL)),
+ ("assert-css", (".item-decl .associatedtype", {"color": |assoc_type_color|}, ALL)),
+ ],
+)
+
+call-function: (
+ "check-colors",
+ {
+ "theme": "ayu",
+ "attr_color": "rgb(153, 153, 153)",
+ "trait_color": "rgb(57, 175, 215)",
+ "struct_color": "rgb(255, 160, 165)",
+ "enum_color": "rgb(255, 160, 165)",
+ "primitive_color": "rgb(255, 160, 165)",
+ "constant_color": "rgb(57, 175, 215)",
+ "fn_color": "rgb(253, 214, 135)",
+ "assoc_type_color": "rgb(57, 175, 215)",
+ },
+)
+call-function: (
+ "check-colors",
+ {
+ "theme": "dark",
+ "attr_color": "rgb(153, 153, 153)",
+ "trait_color": "rgb(183, 140, 242)",
+ "struct_color": "rgb(45, 191, 184)",
+ "enum_color": "rgb(45, 191, 184)",
+ "primitive_color": "rgb(45, 191, 184)",
+ "constant_color": "rgb(210, 153, 29)",
+ "fn_color": "rgb(43, 171, 99)",
+ "assoc_type_color": "rgb(210, 153, 29)",
+ },
+)
+call-function: (
+ "check-colors",
+ {
+ "theme": "light",
+ "attr_color": "rgb(153, 153, 153)",
+ "trait_color": "rgb(110, 79, 201)",
+ "struct_color": "rgb(173, 55, 138)",
+ "enum_color": "rgb(173, 55, 138)",
+ "primitive_color": "rgb(173, 55, 138)",
+ "constant_color": "rgb(56, 115, 173)",
+ "fn_color": "rgb(173, 124, 55)",
+ "assoc_type_color": "rgb(56, 115, 173)",
+ },
+)
diff --git a/src/test/rustdoc-gui/item-info-alignment.goml b/src/test/rustdoc-gui/item-info-alignment.goml
index 4d7b5045f..94b52f005 100644
--- a/src/test/rustdoc-gui/item-info-alignment.goml
+++ b/src/test/rustdoc-gui/item-info-alignment.goml
@@ -1,6 +1,6 @@
// This test ensures that the "item-info" looks about the same
// whether or not it's inside a toggle.
-goto: file://|DOC_PATH|/lib2/struct.ItemInfoAlignmentTest.html
+goto: "file://" + |DOC_PATH| + "/lib2/struct.ItemInfoAlignmentTest.html"
// First, we try it in "desktop" mode.
size: (1200, 870)
diff --git a/src/test/rustdoc-gui/item-info-overflow.goml b/src/test/rustdoc-gui/item-info-overflow.goml
index b7095a3c5..8ea14621c 100644
--- a/src/test/rustdoc-gui/item-info-overflow.goml
+++ b/src/test/rustdoc-gui/item-info-overflow.goml
@@ -1,10 +1,10 @@
// This test ensures that the "item-info" elements don't overflow.
-goto: file://|DOC_PATH|/lib2/struct.LongItemInfo.html
+goto: "file://" + |DOC_PATH| + "/lib2/struct.LongItemInfo.html"
// We set a fixed size so there is no chance of "random" resize.
size: (1200, 870)
// Logically, the "item-decl" and the "item-info" should have the same scroll width.
-compare-elements-property: (".docblock.item-decl", ".item-info", ["scrollWidth"])
-assert-property: (".item-info", {"scrollWidth": "890"})
+compare-elements-property: (".item-decl", ".item-info", ["scrollWidth"])
+assert-property: (".item-info", {"scrollWidth": "940"})
// Just to be sure we're comparing the correct "item-info":
assert-text: (
".item-info",
@@ -13,7 +13,7 @@ assert-text: (
)
// Checking the "item-info" on an impl block as well:
-goto: file://|DOC_PATH|/lib2/struct.LongItemInfo2.html
+goto: "file://" + |DOC_PATH| + "/lib2/struct.LongItemInfo2.html"
compare-elements-property: (
"#impl-SimpleTrait-for-LongItemInfo2 .item-info",
"#impl-SimpleTrait-for-LongItemInfo2 + .docblock",
@@ -21,7 +21,7 @@ compare-elements-property: (
)
assert-property: (
"#impl-SimpleTrait-for-LongItemInfo2 .item-info",
- {"scrollWidth": "866"},
+ {"scrollWidth": "916"},
)
// Just to be sure we're comparing the correct "item-info":
assert-text: (
diff --git a/src/test/rustdoc-gui/item-info.goml b/src/test/rustdoc-gui/item-info.goml
index 50c45b76b..6780dfca6 100644
--- a/src/test/rustdoc-gui/item-info.goml
+++ b/src/test/rustdoc-gui/item-info.goml
@@ -1,15 +1,15 @@
// This test ensures a few things for item info elements.
-goto: file://|DOC_PATH|/lib2/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/lib2/struct.Foo.html"
// Ensuring that the item information don't take 100% of the width if unnecessary.
// We set a fixed size so there is no chance of "random" resize.
size: (1100, 800)
// We check that ".item-info" is bigger than its content.
-assert-css: (".item-info", {"width": "790px"})
+assert-css: (".item-info", {"width": "840px"})
assert-css: (".item-info .stab", {"width": "289px"})
-assert-position: (".item-info .stab", {"x": 295})
+assert-position: (".item-info .stab", {"x": 245})
// Now we ensure that they're not rendered on the same line.
-goto: file://|DOC_PATH|/lib2/trait.Trait.html
+goto: "file://" + |DOC_PATH| + "/lib2/trait.Trait.html"
// We first ensure that there are two item info on the trait.
assert-count: ("#main-content > .item-info .stab", 2)
// They should not have the same `y` position!
diff --git a/src/test/rustdoc-gui/item-summary-table.goml b/src/test/rustdoc-gui/item-summary-table.goml
index 4bff32b3d..2a92e9da5 100644
--- a/src/test/rustdoc-gui/item-summary-table.goml
+++ b/src/test/rustdoc-gui/item-summary-table.goml
@@ -1,5 +1,5 @@
// This test ensures that <table> elements aren't display in items summary.
-goto: file://|DOC_PATH|/lib2/summary_table/index.html
+goto: "file://" + |DOC_PATH| + "/lib2/summary_table/index.html"
// We check that we picked the right item first.
assert-text: (".item-table .item-left", "Foo")
// Then we check that its summary is empty.
diff --git a/src/test/rustdoc-gui/javascript-disabled.goml b/src/test/rustdoc-gui/javascript-disabled.goml
index 1693f7b64..edf179d0d 100644
--- a/src/test/rustdoc-gui/javascript-disabled.goml
+++ b/src/test/rustdoc-gui/javascript-disabled.goml
@@ -2,5 +2,5 @@
// can't be used without JS.
javascript: false
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
assert-css: (".sub", {"display": "none"})
diff --git a/src/test/rustdoc-gui/jump-to-def-background.goml b/src/test/rustdoc-gui/jump-to-def-background.goml
index d17400f5b..b65faf13d 100644
--- a/src/test/rustdoc-gui/jump-to-def-background.goml
+++ b/src/test/rustdoc-gui/jump-to-def-background.goml
@@ -1,43 +1,22 @@
// We check the background color on the jump to definition links in the source code page.
-goto: file://|DOC_PATH|/src/link_to_definition/lib.rs.html
+goto: "file://" + |DOC_PATH| + "/src/link_to_definition/lib.rs.html"
-// Set the theme to dark.
-local-storage: {
- "rustdoc-theme": "dark",
- "rustdoc-preferred-dark-theme": "dark",
- "rustdoc-use-system-theme": "false",
-}
-// We reload the page so the local storage settings are being used.
-reload:
-
-assert-css: (
- "body.source .example-wrap pre.rust a",
- {"background-color": "rgb(51, 51, 51)"},
- ALL,
-)
-
-// Set the theme to ayu.
-local-storage: {
- "rustdoc-theme": "ayu",
- "rustdoc-preferred-dark-theme": "ayu",
- "rustdoc-use-system-theme": "false",
-}
-// We reload the page so the local storage settings are being used.
-reload:
-
-assert-css: (
- "body.source .example-wrap pre.rust a",
- {"background-color": "rgb(51, 51, 51)"},
- ALL,
+define-function: (
+ "check-background-color",
+ (theme, background_color),
+ [
+ // Set the theme.
+ ("local-storage", { "rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false" }),
+ // We reload the page so the local storage settings are being used.
+ ("reload"),
+ ("assert-css", (
+ "body.source .example-wrap pre.rust a",
+ {"background-color": |background_color|},
+ ALL,
+ )),
+ ],
)
-// Set the theme to light.
-local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
-// We reload the page so the local storage settings are being used.
-reload:
-
-assert-css: (
- "body.source .example-wrap pre.rust a",
- {"background-color": "rgb(238, 238, 238)"},
- ALL,
-)
+call-function: ("check-background-color", ("ayu", "rgb(51, 51, 51)"))
+call-function: ("check-background-color", ("dark", "rgb(51, 51, 51)"))
+call-function: ("check-background-color", ("light", "rgb(238, 238, 238)"))
diff --git a/src/test/rustdoc-gui/label-next-to-symbol.goml b/src/test/rustdoc-gui/label-next-to-symbol.goml
index 4b4cea262..05f8ddc71 100644
--- a/src/test/rustdoc-gui/label-next-to-symbol.goml
+++ b/src/test/rustdoc-gui/label-next-to-symbol.goml
@@ -1,6 +1,6 @@
// These tests verify that labels like "UNIX" and "Deprecated" stay on the same line as their symbol.
// It also verifies the staggered layout on mobile.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
// Desktop view
size: (1080, 600)
diff --git a/src/test/rustdoc-gui/links-color.goml b/src/test/rustdoc-gui/links-color.goml
index 69c5b4a67..839629ad9 100644
--- a/src/test/rustdoc-gui/links-color.goml
+++ b/src/test/rustdoc-gui/links-color.goml
@@ -1,5 +1,5 @@
// This test checks links colors.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
// This is needed so that the text color is computed.
show-text: true
diff --git a/src/test/rustdoc-gui/list_code_block.goml b/src/test/rustdoc-gui/list_code_block.goml
index eba1a662b..3423a449d 100644
--- a/src/test/rustdoc-gui/list_code_block.goml
+++ b/src/test/rustdoc-gui/list_code_block.goml
@@ -1,4 +1,4 @@
// This test checks that code blocks in list are supported.
-goto: file://|DOC_PATH|/test_docs/index.html
-goto: ./fn.check_list_code_block.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
+goto: "./fn.check_list_code_block.html"
assert: ("pre.rust.fn")
diff --git a/src/test/rustdoc-gui/mobile.goml b/src/test/rustdoc-gui/mobile.goml
index 13b9b563d..704542a39 100644
--- a/src/test/rustdoc-gui/mobile.goml
+++ b/src/test/rustdoc-gui/mobile.goml
@@ -1,5 +1,5 @@
// Test various properties of the mobile UI
-goto: file://|DOC_PATH|/staged_api/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/staged_api/struct.Foo.html"
size: (400, 600)
font-size: 18
@@ -12,7 +12,7 @@ assert-css: (".main-heading", {
"flex-direction": "column"
})
-assert-property: (".mobile-topbar h2.location", {"offsetHeight": 36})
+assert-property: (".mobile-topbar h2", {"offsetHeight": 36})
// Note: We can't use assert-text here because the 'Since' is set by CSS and
// is therefore not part of the DOM.
@@ -24,7 +24,7 @@ assert-css-false: (".content .out-of-band .since::before", { "content": "\"Since
// On the settings page, the theme buttons should not line-wrap. Instead, they should
// all be placed as a group on a line below the setting name "Theme."
-goto: file://|DOC_PATH|/settings.html
+goto: "file://" + |DOC_PATH| + "/settings.html"
size: (400, 600)
// Ignored for now https://github.com/rust-lang/rust/issues/93784.
// compare-elements-position-near-false: ("#preferred-light-theme .setting-name", "#preferred-light-theme .choice", {"y": 16})
diff --git a/src/test/rustdoc-gui/module-items-font.goml b/src/test/rustdoc-gui/module-items-font.goml
index 758ee391a..cd3676a98 100644
--- a/src/test/rustdoc-gui/module-items-font.goml
+++ b/src/test/rustdoc-gui/module-items-font.goml
@@ -1,5 +1,5 @@
// This test checks that the correct font is used on module items (in index.html pages).
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
assert-css: (
".item-table .module-item a",
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
diff --git a/src/test/rustdoc-gui/no-docblock.goml b/src/test/rustdoc-gui/no-docblock.goml
new file mode 100644
index 000000000..2366a60f5
--- /dev/null
+++ b/src/test/rustdoc-gui/no-docblock.goml
@@ -0,0 +1,8 @@
+// This test checks that there are margins applied to methods with no docblocks.
+goto: "file://" + |DOC_PATH| + "/test_docs/trait.TraitWithNoDocblocks.html"
+// Check that the two methods are more than 24px apart.
+compare-elements-position-near-false: ("//*[@id='tymethod.first_fn']", "//*[@id='tymethod.second_fn']", {"y": 24})
+
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.TypeWithNoDocblocks.html"
+// Check that the two methods are more than 24px apart.
+compare-elements-position-near-false: ("//*[@id='method.first_fn']", "//*[@id='method.second_fn']", {"y": 24})
diff --git a/src/test/rustdoc-gui/notable-trait.goml b/src/test/rustdoc-gui/notable-trait.goml
new file mode 100644
index 000000000..efe0cb15f
--- /dev/null
+++ b/src/test/rustdoc-gui/notable-trait.goml
@@ -0,0 +1,128 @@
+// This test checks the position of the `i` for the notable traits.
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.NotableStructWithLongName.html"
+show-text: true
+// We start with a wide screen.
+size: (1100, 600)
+// Checking they have the same y position.
+compare-elements-position: (
+ "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ ("y"),
+)
+// Checking they don't have the same x position.
+compare-elements-position-false: (
+ "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ ("x"),
+)
+// The `i` should be *after* the type.
+assert-position: (
+ "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
+ {"x": 677},
+)
+assert-position: (
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ {"x": 951},
+)
+// The tooltip should be beside the `i`
+click: "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']"
+compare-elements-position-near: (
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits-tooltiptext force-tooltip']",
+ {"y": 2}
+)
+compare-elements-position-false: (
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits-tooltiptext force-tooltip']",
+ ("x")
+)
+// The docblock should be flush with the border.
+assert-css: (
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits-tooltiptext force-tooltip']/*[@class='docblock']",
+ {"margin-left": "0px"}
+)
+
+// Now only the `i` should be on the next line.
+size: (1055, 600)
+compare-elements-position-false: (
+ "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ ("y", "x"),
+)
+
+// Now both the `i` and the struct name should be on the next line.
+size: (980, 600)
+// Checking they have the same y position.
+compare-elements-position: (
+ "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ ("y"),
+)
+// Checking they don't have the same x position.
+compare-elements-position-false: (
+ "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ ("x"),
+)
+// The `i` should be *after* the type.
+assert-position: (
+ "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
+ {"x": 245},
+)
+assert-position: (
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ {"x": 519},
+)
+
+// Checking on mobile now.
+size: (650, 600)
+// Checking they have the same y position.
+compare-elements-position: (
+ "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ ("y"),
+)
+// Checking they don't have the same x position.
+compare-elements-position-false: (
+ "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ ("x"),
+)
+// The `i` should be *after* the type.
+assert-position: (
+ "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
+ {"x": 15},
+)
+assert-position: (
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ {"x": 289},
+)
+// The tooltip should be below `i`
+compare-elements-position-near-false: (
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits-tooltiptext force-tooltip']",
+ {"y": 2}
+)
+compare-elements-position-false: (
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits-tooltiptext force-tooltip']",
+ ("x")
+)
+compare-elements-position-near: (
+ "//*[@id='method.create_an_iterator_from_read']/parent::*",
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits-tooltiptext force-tooltip']",
+ {"x": 5}
+)
+// The docblock should be flush with the border.
+assert-css: (
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits-tooltiptext force-tooltip']/*[@class='docblock']",
+ {"margin-left": "0px"}
+)
+
+// Checking on very small mobile. The `i` should be on its own line.
+size: (365, 600)
+compare-elements-position-false: (
+ "//*[@id='method.create_an_iterator_from_read']//a[text()='NotableStructWithLongName']",
+ "//*[@id='method.create_an_iterator_from_read']//*[@class='notable-traits']",
+ ("y", "x"),
+)
diff --git a/src/test/rustdoc-gui/overflow-tooltip-information.goml b/src/test/rustdoc-gui/overflow-tooltip-information.goml
index f481f82c2..09ad6cdd7 100644
--- a/src/test/rustdoc-gui/overflow-tooltip-information.goml
+++ b/src/test/rustdoc-gui/overflow-tooltip-information.goml
@@ -1,7 +1,7 @@
// The goal of this test is to ensure that the tooltip `.information` class doesn't
// have overflow and max-width CSS rules set because they create a bug in firefox on
// mac. For more information: https://github.com/rust-lang/rust/issues/89185
-goto: file://|DOC_PATH|/test_docs/fn.foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
assert-css: (".docblock > .example-wrap .tooltip", {
"overflow-x": "visible",
"max-width": "none"
diff --git a/src/test/rustdoc-gui/pocket-menu.goml b/src/test/rustdoc-gui/pocket-menu.goml
index 71d514648..fb63ea62a 100644
--- a/src/test/rustdoc-gui/pocket-menu.goml
+++ b/src/test/rustdoc-gui/pocket-menu.goml
@@ -1,5 +1,5 @@
// This test ensures that the "pocket menus" are working as expected.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
// First we check that the help menu doesn't exist yet.
assert-false: "#help-button .popover"
// Then we display the help menu.
diff --git a/src/test/rustdoc-gui/run-on-hover.goml b/src/test/rustdoc-gui/run-on-hover.goml
index b8efa8e30..6c785e1c4 100644
--- a/src/test/rustdoc-gui/run-on-hover.goml
+++ b/src/test/rustdoc-gui/run-on-hover.goml
@@ -1,7 +1,7 @@
// Example code blocks sometimes have a "Run" button to run them on the
// Playground. That button is hidden until the user hovers over the code block.
// This test checks that it is hidden, and that it shows on hover.
-goto: file://|DOC_PATH|/test_docs/fn.foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
assert-css: (".test-arrow", {"visibility": "hidden"})
move-cursor-to: ".example-wrap"
assert-css: (".test-arrow", {"visibility": "visible"})
diff --git a/src/test/rustdoc-gui/rust-logo.goml b/src/test/rustdoc-gui/rust-logo.goml
index 4a9dcf735..6c8dc8594 100644
--- a/src/test/rustdoc-gui/rust-logo.goml
+++ b/src/test/rustdoc-gui/rust-logo.goml
@@ -1,78 +1,34 @@
// This test ensures that the correct style is applied to the rust logo in the sidebar.
-goto: file://|DOC_PATH|/test_docs/index.html
-
-// First we start with the dark theme.
-local-storage: {
- "rustdoc-theme": "dark",
- "rustdoc-preferred-dark-theme": "dark",
- "rustdoc-use-system-theme": "false",
-}
-reload:
-
-assert-css: (
- ".rust-logo",
- {"filter": "drop-shadow(rgb(255, 255, 255) 1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px 1px 0px) drop-shadow(rgb(255, 255, 255) -1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px -1px 0px)"},
-)
-
-// In the source view page now.
-goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
-
-local-storage: {
- "rustdoc-theme": "dark",
- "rustdoc-preferred-dark-theme": "dark",
- "rustdoc-use-system-theme": "false",
-}
-reload:
-
-assert-css: (
- ".rust-logo",
- {"filter": "drop-shadow(rgb(255, 255, 255) 1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px 1px 0px) drop-shadow(rgb(255, 255, 255) -1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px -1px 0px)"},
-)
-
-// Then with the ayu theme.
-local-storage: {
- "rustdoc-theme": "ayu",
- "rustdoc-preferred-dark-theme": "ayu",
- "rustdoc-use-system-theme": "false",
-}
-reload:
-
-assert-css: (
- ".rust-logo",
- {"filter": "drop-shadow(rgb(255, 255, 255) 1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px 1px 0px) drop-shadow(rgb(255, 255, 255) -1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px -1px 0px)"},
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
+
+define-function: (
+ "check-logo",
+ (theme, filter),
+ [
+ // Going to the doc page.
+ ("goto", "file://" + |DOC_PATH| + "/test_docs/index.html"),
+ // Changing theme.
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ ("reload"),
+ ("assert-css", (".rust-logo", {"filter": |filter|})),
+ // Going to the source code page.
+ ("goto", "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"),
+ // Changing theme (since it's local files, the local storage works by folder).
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ ("reload"),
+ ("assert-css", (".rust-logo", {"filter": |filter|})),
+ ],
)
-// In the source view page now.
-goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
-
-local-storage: {
- "rustdoc-theme": "ayu",
- "rustdoc-preferred-dark-theme": "ayu",
- "rustdoc-use-system-theme": "false",
-}
-reload:
-
-assert-css: (
- ".rust-logo",
- {"filter": "drop-shadow(rgb(255, 255, 255) 1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px 1px 0px) drop-shadow(rgb(255, 255, 255) -1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px -1px 0px)"},
+call-function: (
+ "check-logo",
+ ("ayu", "drop-shadow(rgb(255, 255, 255) 1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px 1px 0px) drop-shadow(rgb(255, 255, 255) -1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px -1px 0px)"),
)
-
-// And finally with the light theme.
-local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
-reload:
-
-assert-css: (
- ".rust-logo",
- {"filter": "none"},
+call-function: (
+ "check-logo",
+ ("dark", "drop-shadow(rgb(255, 255, 255) 1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px 1px 0px) drop-shadow(rgb(255, 255, 255) -1px 0px 0px) drop-shadow(rgb(255, 255, 255) 0px -1px 0px)"),
)
-
-// In the source view page now.
-goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
-
-local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
-reload:
-
-assert-css: (
- ".rust-logo",
- {"filter": "none"},
+call-function: (
+ "check-logo",
+ ("light", "none"),
)
diff --git a/src/test/rustdoc-gui/search-filter.goml b/src/test/rustdoc-gui/search-filter.goml
index 35d7ca480..27db816e6 100644
--- a/src/test/rustdoc-gui/search-filter.goml
+++ b/src/test/rustdoc-gui/search-filter.goml
@@ -1,5 +1,5 @@
// Checks that the crate search filtering is handled correctly and changes the results.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
show-text: true
write: (".search-input", "test")
// To be SURE that the search will be run.
@@ -43,7 +43,7 @@ wait-for: "#titles"
assert-property: ("#crate-search", {"value": "all crates"})
// Checking that the URL parameter is taken into account for crate filtering.
-goto: file://|DOC_PATH|/test_docs/index.html?search=test&filter-crate=lib2
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html?search=test&filter-crate=lib2"
wait-for: "#crate-search"
assert-property: ("#crate-search", {"value": "lib2"})
assert-false: "#results .externcrate"
diff --git a/src/test/rustdoc-gui/search-form-elements.goml b/src/test/rustdoc-gui/search-form-elements.goml
index 1c64974e9..542db348c 100644
--- a/src/test/rustdoc-gui/search-form-elements.goml
+++ b/src/test/rustdoc-gui/search-form-elements.goml
@@ -1,5 +1,5 @@
// This test ensures that the elements in ".search-form" have the expected display.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
show-text: true
// Ayu theme
@@ -33,7 +33,7 @@ assert-css: (
{"border-color": "rgb(197, 197, 197)"},
)
assert-css: (
- "#help-button > button",
+ "#help-button > a",
{
"color": "rgb(255, 255, 255)",
"border-color": "rgb(92, 103, 115)",
@@ -47,13 +47,21 @@ assert-css: (
)
// Only "border-color" should change.
assert-css: (
- "#help-button:hover > button",
+ "#help-button:hover > a",
{
"color": "rgb(255, 255, 255)",
"border-color": "rgb(224, 224, 224)",
"background-color": "rgb(20, 25, 32)",
},
)
+// Link color inside
+click: "#help-button"
+assert-css: (
+ "#help a",
+ {
+ "color": "rgb(57, 175, 215)",
+ },
+)
assert-css: (
"#settings-menu",
@@ -62,7 +70,6 @@ assert-css: (
assert-css: (
"#settings-menu > a",
{
- "color": "rgb(255, 255, 255)",
"border-color": "rgb(92, 103, 115)",
"background-color": "rgb(20, 25, 32)",
},
@@ -76,7 +83,6 @@ assert-css: (
assert-css: (
"#settings-menu:hover > a",
{
- "color": "rgb(255, 255, 255)",
"border-color": "rgb(224, 224, 224)",
"background-color": "rgb(20, 25, 32)",
},
@@ -113,7 +119,7 @@ assert-css: (
{"border-color": "rgb(221, 221, 221)"},
)
assert-css: (
- "#help-button > button",
+ "#help-button > a",
{
"color": "rgb(0, 0, 0)",
"border-color": "rgb(224, 224, 224)",
@@ -127,13 +133,21 @@ assert-css: (
)
// Only "border-color" should change.
assert-css: (
- "#help-button:hover > button",
+ "#help-button:hover > a",
{
"color": "rgb(0, 0, 0)",
"border-color": "rgb(255, 185, 0)",
"background-color": "rgb(240, 240, 240)",
},
)
+// Link color inside
+click: "#help-button"
+assert-css: (
+ "#help a",
+ {
+ "color": "rgb(210, 153, 29)",
+ },
+)
assert-css: (
"#settings-menu",
@@ -142,7 +156,6 @@ assert-css: (
assert-css: (
"#settings-menu > a",
{
- "color": "rgb(0, 0, 0)",
"border-color": "rgb(224, 224, 224)",
"background-color": "rgb(240, 240, 240)",
},
@@ -193,7 +206,7 @@ assert-css: (
{"border-color": "rgb(0, 0, 0)"},
)
assert-css: (
- "#help-button > button",
+ "#help-button > a",
{
"color": "rgb(0, 0, 0)",
"border-color": "rgb(224, 224, 224)",
@@ -207,13 +220,21 @@ assert-css: (
)
// Only "border-color" should change.
assert-css: (
- "#help-button:hover > button",
+ "#help-button:hover > a",
{
"color": "rgb(0, 0, 0)",
"border-color": "rgb(113, 113, 113)",
"background-color": "rgb(255, 255, 255)",
},
)
+// Link color inside
+click: "#help-button"
+assert-css: (
+ "#help a",
+ {
+ "color": "rgb(56, 115, 173)",
+ },
+)
assert-css: (
"#settings-menu",
@@ -222,7 +243,6 @@ assert-css: (
assert-css: (
"#settings-menu > a",
{
- "color": "rgb(56, 115, 173)",
"border-color": "rgb(224, 224, 224)",
"background-color": "rgb(255, 255, 255)",
},
@@ -236,7 +256,7 @@ assert-css: (
assert-css: (
"#settings-menu:hover > a",
{
- "color": "rgb(56, 115, 173)",
+ "color": "rgb(0, 0, 0)",
"border-color": "rgb(113, 113, 113)",
"background-color": "rgb(255, 255, 255)",
},
diff --git a/src/test/rustdoc-gui/search-input-mobile.goml b/src/test/rustdoc-gui/search-input-mobile.goml
index 5c95db70a..ce0cef77c 100644
--- a/src/test/rustdoc-gui/search-input-mobile.goml
+++ b/src/test/rustdoc-gui/search-input-mobile.goml
@@ -1,6 +1,6 @@
// Test to ensure that you can click on the search input, whatever the width.
// The PR which fixed it is: https://github.com/rust-lang/rust/pull/81592
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
size: (463, 700)
// We first check that the search input isn't already focused.
assert-false: ("input.search-input:focus")
diff --git a/src/test/rustdoc-gui/search-reexport.goml b/src/test/rustdoc-gui/search-reexport.goml
index 5ef890d47..dd19f03bd 100644
--- a/src/test/rustdoc-gui/search-reexport.goml
+++ b/src/test/rustdoc-gui/search-reexport.goml
@@ -1,6 +1,6 @@
// Checks that the reexports are present in the search index, can have
// doc aliases and are highligted when their ID is the hash of the page.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"}
reload:
// First we check that the reexport has the correct ID and no background color.
diff --git a/src/test/rustdoc-gui/search-result-color.goml b/src/test/rustdoc-gui/search-result-color.goml
index c4b5fdf53..69bb30df9 100644
--- a/src/test/rustdoc-gui/search-result-color.goml
+++ b/src/test/rustdoc-gui/search-result-color.goml
@@ -1,5 +1,58 @@
// The goal of this test is to ensure the color of the text is the one expected.
-goto: file://|DOC_PATH|/test_docs/index.html?search=coo
+
+define-function: (
+ "check-result-color",
+ (result_kind, color, hover_color),
+ [
+ (
+ "assert-css",
+ (".result-" + |result_kind| + " ." + |result_kind|, {"color": |color|}, ALL),
+ ),
+ (
+ "assert-css",
+ (
+ ".result-" + |result_kind|,
+ {"color": |entry_color|, "background-color": |background_color|},
+ ),
+ ),
+ (
+ "move-cursor-to",
+ ".result-" + |result_kind|,
+ ),
+ (
+ "assert-css",
+ (
+ ".result-" + |result_kind| + ":hover",
+ {"color": |hover_entry_color|, "background-color": |hover_background_color|},
+ ),
+ ),
+ (
+ "assert-css",
+ (".result-" + |result_kind| + ":hover ." + |result_kind|, {"color": |hover_color|}),
+ ),
+ (
+ "move-cursor-to",
+ ".search-input",
+ ),
+ (
+ "focus",
+ ".result-" + |result_kind|,
+ ),
+ (
+ "assert-css",
+ (
+ ".result-" + |result_kind| + ":focus",
+ {"color": |hover_entry_color|, "background-color": |hover_background_color|},
+ ),
+ ),
+ (
+ "assert-css",
+ (".result-" + |result_kind| + ":focus ." + |result_kind|, {"color": |hover_color|}),
+ ),
+ ],
+)
+
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html?search=coo"
// This is needed so that the text color is computed.
show-text: true
@@ -28,56 +81,71 @@ assert-css: (
{"color": "rgb(120, 135, 151)"},
)
-// Checking the color of "keyword".
-assert-css: (
- ".result-name .keyword",
- {"color": "rgb(57, 175, 215)"},
- ALL,
-)
-// Check the color of "struct".
-assert-css: (
- ".result-name .struct",
- {"color": "rgb(255, 160, 165)"},
- ALL,
-)
-// Check the color of "associated type".
-assert-css: (
- ".result-name .associatedtype",
- {"color": "rgb(57, 175, 215)"},
- ALL,
-)
-// Check the color of "type method".
-assert-css: (
- ".result-name .tymethod",
- {"color": "rgb(253, 214, 135)"},
- ALL,
-)
-// Check the color of "method".
-assert-css: (
- ".result-name .method",
- {"color": "rgb(253, 214, 135)"},
- ALL,
-)
-// Check the color of "struct field".
-assert-css: (
- ".result-name .structfield",
- {"color": "rgb(0, 150, 207)"},
- ALL,
-)
-// Check the color of "macro".
-assert-css: (
- ".result-name .macro",
- {"color": "rgb(163, 122, 204)"},
- ALL,
-)
-// Check the color of "fn".
-assert-css: (
- ".result-name .fn",
- {"color": "rgb(253, 214, 135)"},
- ALL,
+store-value: (entry_color, "rgb(0, 150, 207)") // color of the search entry
+store-value: (hover_entry_color, "rgb(255, 255, 255)") // color of the hovered/focused search entry
+store-value: (background_color, "rgba(0, 0, 0, 0)") // background color
+store-value: (hover_background_color, "rgb(60, 60, 60)") // hover background color
+
+call-function: (
+ "check-result-color", (
+ "keyword", // item kind
+ "rgb(57, 175, 215)", // color of item kind
+ "rgb(57, 175, 215)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "struct", // item kind
+ "rgb(255, 160, 165)", // color of item kind
+ "rgb(255, 160, 165)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "associatedtype", // item kind
+ "rgb(57, 175, 215)", // color of item kind
+ "rgb(57, 175, 215)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "tymethod", // item kind
+ "rgb(253, 214, 135)", // color of item kind
+ "rgb(253, 214, 135)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "method", // item kind
+ "rgb(253, 214, 135)", // color of item kind
+ "rgb(253, 214, 135)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "structfield", // item kind
+ "rgb(0, 150, 207)", // color of item kind
+ "rgb(255, 255, 255)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "macro", // item kind
+ "rgb(163, 122, 204)", // color of item kind
+ "rgb(163, 122, 204)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "fn", // item kind
+ "rgb(253, 214, 135)", // color of item kind
+ "rgb(253, 214, 135)", // color of hovered/focused item kind
+ ),
)
// Checking the `<a>` container.
+move-cursor-to: ".search-input"
+focus: ".search-input" // To ensure the `<a>` container isnt focus or hover.
assert-css: (
"//*[@class='result-name']/*[text()='test_docs::']/ancestor::a",
{"color": "rgb(0, 150, 207)", "background-color": "rgba(0, 0, 0, 0)"},
@@ -113,78 +181,82 @@ assert-css: (
{"color": "rgb(221, 221, 221)"},
)
-// Checking the color for "keyword".
+// Checking the color for "keyword" text.
assert-css: (
"//*[@class='result-name']//*[text()='(keyword)']",
{"color": "rgb(221, 221, 221)"},
)
-// Checking the color of "keyword".
-assert-css: (
- ".result-name .keyword",
- {"color": "rgb(210, 153, 29)"},
- ALL,
-)
-// Check the color of "struct".
-assert-css: (
- ".result-name .struct",
- {"color": "rgb(45, 191, 184)"},
- ALL,
-)
-// Check the color of "associated type".
-assert-css: (
- ".result-name .associatedtype",
- {"color": "rgb(210, 153, 29)"},
- ALL,
-)
-// Check the color of "type method".
-assert-css: (
- ".result-name .tymethod",
- {"color": "rgb(43, 171, 99)"},
- ALL,
-)
-// Check the color of "method".
-assert-css: (
- ".result-name .method",
- {"color": "rgb(43, 171, 99)"},
- ALL,
-)
-// Check the color of "struct field".
-assert-css: (
- ".result-name .structfield",
- {"color": "rgb(221, 221, 221)"},
- ALL,
-)
-// Check the color of "macro".
-assert-css: (
- ".result-name .macro",
- {"color": "rgb(9, 189, 0)"},
- ALL,
-)
-// Check the color of "fn".
-assert-css: (
- ".result-name .fn",
- {"color": "rgb(43, 171, 99)"},
- ALL,
+store-value: (entry_color, "rgb(221, 221, 221)") // color of the search entry
+store-value: (hover_entry_color, "rgb(221, 221, 221)") // color of the hovered/focused search entry
+store-value: (background_color, "rgba(0, 0, 0, 0)") // background color
+store-value: (hover_background_color, "rgb(97, 97, 97)") // hover background color
+
+call-function: (
+ "check-result-color", (
+ "keyword", // item kind
+ "rgb(210, 153, 29)", // color of item kind
+ "rgb(210, 153, 29)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "struct", // item kind
+ "rgb(45, 191, 184)", // color of item kind
+ "rgb(45, 191, 184)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "associatedtype", // item kind
+ "rgb(210, 153, 29)", // color of item kind
+ "rgb(210, 153, 29)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "tymethod", // item kind
+ "rgb(43, 171, 99)", // color of item kind
+ "rgb(43, 171, 99)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "method", // item kind
+ "rgb(43, 171, 99)", // color of item kind
+ "rgb(43, 171, 99)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "structfield", // item kind
+ "rgb(221, 221, 221)", // color of item kind
+ "rgb(221, 221, 221)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "macro", // item kind
+ "rgb(9, 189, 0)", // color of item kind
+ "rgb(9, 189, 0)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "fn", // item kind
+ "rgb(43, 171, 99)", // color of item kind
+ "rgb(43, 171, 99)", // color of hovered/focused item kind
+ ),
)
// Checking the `<a>` container.
+move-cursor-to: ".search-input"
+focus: ".search-input" // To ensure the `<a>` container isnt focus or hover.
assert-css: (
"//*[@class='result-name']/*[text()='test_docs::']/ancestor::a",
{"color": "rgb(221, 221, 221)", "background-color": "rgba(0, 0, 0, 0)"},
)
-// Checking color and background on hover.
-move-cursor-to: "//*[@class='desc']//*[text()='Just a normal struct.']"
-assert-css: (
- "//*[@class='result-name']/*[text()='test_docs::']",
- {"color": "rgb(221, 221, 221)"},
-)
-assert-css: (
- "//*[@class='result-name']/*[text()='test_docs::']/ancestor::a",
- {"color": "rgb(221, 221, 221)", "background-color": "rgb(119, 119, 119)"},
-)
-
// Light theme
local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
reload:
@@ -200,80 +272,84 @@ assert-css: (
{"color": "rgb(0, 0, 0)"},
)
-// Checking the color for "keyword".
+// Checking the color for "keyword" text.
assert-css: (
"//*[@class='result-name']//*[text()='(keyword)']",
{"color": "rgb(0, 0, 0)"},
)
-// Checking the color of "keyword".
-assert-css: (
- ".result-name .keyword",
- {"color": "rgb(56, 115, 173)"},
- ALL,
-)
-// Check the color of "struct".
-assert-css: (
- ".result-name .struct",
- {"color": "rgb(173, 55, 138)"},
- ALL,
-)
-// Check the color of "associated type".
-assert-css: (
- ".result-name .associatedtype",
- {"color": "rgb(56, 115, 173)"},
- ALL,
-)
-// Check the color of "type method".
-assert-css: (
- ".result-name .tymethod",
- {"color": "rgb(173, 124, 55)"},
- ALL,
-)
-// Check the color of "method".
-assert-css: (
- ".result-name .method",
- {"color": "rgb(173, 124, 55)"},
- ALL,
-)
-// Check the color of "struct field".
-assert-css: (
- ".result-name .structfield",
- {"color": "rgb(0, 0, 0)"},
- ALL,
-)
-// Check the color of "macro".
-assert-css: (
- ".result-name .macro",
- {"color": "rgb(6, 128, 0)"},
- ALL,
-)
-// Check the color of "fn".
-assert-css: (
- ".result-name .fn",
- {"color": "rgb(173, 124, 55)"},
- ALL,
+store-value: (entry_color, "rgb(0, 0, 0)") // color of the search entry
+store-value: (hover_entry_color, "rgb(0, 0, 0)") // color of the hovered/focused search entry
+store-value: (background_color, "rgba(0, 0, 0, 0)") // background color
+store-value: (hover_background_color, "rgb(204, 204, 204)") // hover background color
+
+call-function: (
+ "check-result-color", (
+ "keyword", // item kind
+ "rgb(56, 115, 173)", // color of item kind
+ "rgb(56, 115, 173)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "struct", // item kind
+ "rgb(173, 55, 138)", // color of item kind
+ "rgb(173, 55, 138)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "associatedtype", // item kind
+ "rgb(56, 115, 173)", // color of item kind
+ "rgb(56, 115, 173)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "tymethod", // item kind
+ "rgb(173, 124, 55)", // color of item kind
+ "rgb(173, 124, 55)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "method", // item kind
+ "rgb(173, 124, 55)", // color of item kind
+ "rgb(173, 124, 55)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "structfield", // item kind
+ "rgb(0, 0, 0)", // color of item kind
+ "rgb(0, 0, 0)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "macro", // item kind
+ "rgb(6, 128, 0)", // color of item kind
+ "rgb(6, 128, 0)", // color of hovered/focused item kind
+ ),
+)
+call-function: (
+ "check-result-color", (
+ "fn", // item kind
+ "rgb(173, 124, 55)", // color of item kind
+ "rgb(173, 124, 55)", // color of hovered/focused item kind
+ ),
)
// Checking the `<a>` container.
+move-cursor-to: ".search-input"
+focus: ".search-input" // To ensure the `<a>` container isnt focus or hover.
assert-css: (
"//*[@class='result-name']/*[text()='test_docs::']/ancestor::a",
{"color": "rgb(0, 0, 0)", "background-color": "rgba(0, 0, 0, 0)"},
)
-// Checking color and background on hover.
-move-cursor-to: "//*[@class='desc']//*[text()='Just a normal struct.']"
-assert-css: (
- "//*[@class='result-name']/*[text()='test_docs::']",
- {"color": "rgb(0, 0, 0)"},
-)
-assert-css: (
- "//*[@class='result-name']/*[text()='test_docs::']/ancestor::a",
- {"color": "rgb(0, 0, 0)", "background-color": "rgb(221, 221, 221)"},
-)
-
// Check the alias more specifically in the dark theme.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
// We set the theme so we're sure that the correct values will be used, whatever the computer
// this test is running on.
local-storage: {
diff --git a/src/test/rustdoc-gui/search-result-description.goml b/src/test/rustdoc-gui/search-result-description.goml
index d8cb6ee57..53a335b63 100644
--- a/src/test/rustdoc-gui/search-result-description.goml
+++ b/src/test/rustdoc-gui/search-result-description.goml
@@ -1,5 +1,5 @@
// This test is to ensure that the codeblocks are correctly rendered in the search results.
-goto: file://|DOC_PATH|/test_docs/index.html?search=some_more_function
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html?search=some_more_function"
// Waiting for the search results to appear...
wait-for: "#titles"
assert-text: (".search-results .desc code", "format!")
diff --git a/src/test/rustdoc-gui/search-result-display.goml b/src/test/rustdoc-gui/search-result-display.goml
index efbbfb925..053bfd8c9 100644
--- a/src/test/rustdoc-gui/search-result-display.goml
+++ b/src/test/rustdoc-gui/search-result-display.goml
@@ -1,5 +1,5 @@
// Checks that the search results have the expected width.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
size: (900, 1000)
write: (".search-input", "test")
// To be SURE that the search will be run.
@@ -7,7 +7,7 @@ press-key: 'Enter'
wait-for: "#crate-search"
// The width is returned by "getComputedStyle" which returns the exact number instead of the
// CSS rule which is "50%"...
-assert-css: (".search-results div.desc", {"width": "293px"})
+assert-css: (".search-results div.desc", {"width": "318px"})
size: (600, 100)
// As counter-intuitive as it may seem, in this width, the width is "100%", which is why
// when computed it's larger.
diff --git a/src/test/rustdoc-gui/search-result-go-to-first.goml b/src/test/rustdoc-gui/search-result-go-to-first.goml
index 255470a3e..eeddf5ef6 100644
--- a/src/test/rustdoc-gui/search-result-go-to-first.goml
+++ b/src/test/rustdoc-gui/search-result-go-to-first.goml
@@ -2,18 +2,18 @@
// First, we check that the first page doesn't have the string we're looking for to ensure
// that the feature is changing page as expected.
-goto: file://|DOC_PATH|/test_docs/index.html
-assert-text-false: (".fqn .in-band", "Struct test_docs::Foo")
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
+assert-text-false: (".fqn", "Struct test_docs::Foo")
// We now check that we land on the search result page if "go_to_first" isn't set.
-goto: file://|DOC_PATH|/test_docs/index.html?search=struct%3AFoo
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html?search=struct%3AFoo"
// Waiting for the search results to appear...
wait-for: "#titles"
-assert-text-false: (".fqn .in-band", "Struct test_docs::Foo")
+assert-text-false: (".fqn", "Struct test_docs::Foo")
// Ensure that the search results are displayed, not the "normal" content.
assert-css: ("#main-content", {"display": "none"})
// Now we can check that the feature is working as expected!
-goto: file://|DOC_PATH|/test_docs/index.html?search=struct%3AFoo&go_to_first=true
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html?search=struct%3AFoo&go_to_first=true"
// Waiting for the page to load...
-wait-for-text: (".fqn .in-band", "Struct test_docs::Foo")
+wait-for-text: (".fqn", "Struct test_docs::Foo")
diff --git a/src/test/rustdoc-gui/search-result-keyword.goml b/src/test/rustdoc-gui/search-result-keyword.goml
index 16ae10431..66e63155a 100644
--- a/src/test/rustdoc-gui/search-result-keyword.goml
+++ b/src/test/rustdoc-gui/search-result-keyword.goml
@@ -1,5 +1,5 @@
// Checks that the "keyword" results have the expected text alongside them.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
write: (".search-input", "CookieMonster")
// To be SURE that the search will be run.
press-key: 'Enter'
diff --git a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml
index 9d506c151..a19dc6a8b 100644
--- a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml
+++ b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml
@@ -1,6 +1,6 @@
// Checks that the search tab results work correctly with function signature syntax
// First, try a search-by-name
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
write: (".search-input", "Foo")
// To be SURE that the search will be run.
press-key: 'Enter'
@@ -22,7 +22,7 @@ press-key: "ArrowLeft"
wait-for-attribute: ("#titles > button:nth-of-type(3)", {"class": "selected"})
// Now try search-by-return
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
write: (".search-input", "-> String")
// To be SURE that the search will be run.
press-key: 'Enter'
@@ -44,7 +44,7 @@ press-key: "ArrowLeft"
wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
// Try with a search-by-return with no results
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
write: (".search-input", "-> Something")
// To be SURE that the search will be run.
press-key: 'Enter'
@@ -54,7 +54,7 @@ assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
assert-text: ("#titles > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH)
// Try with a search-by-parameter
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
write: (".search-input", "usize pattern")
// To be SURE that the search will be run.
press-key: 'Enter'
@@ -64,7 +64,7 @@ assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"})
assert-text: ("#titles > button:nth-of-type(1)", "In Function Parameters", STARTS_WITH)
// Try with a search-by-parameter-and-return
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
write: (".search-input", "pattern -> str")
// To be SURE that the search will be run.
press-key: 'Enter'
diff --git a/src/test/rustdoc-gui/settings.goml b/src/test/rustdoc-gui/settings.goml
index d9cf5ee66..f258f4d2a 100644
--- a/src/test/rustdoc-gui/settings.goml
+++ b/src/test/rustdoc-gui/settings.goml
@@ -1,5 +1,6 @@
-// This test ensures that the settings menu display is working as expected.
-goto: file://|DOC_PATH|/test_docs/index.html
+// This test ensures that the settings menu display is working as expected and that
+// the settings page is also rendered as expected.
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
show-text: true // needed when we check for colors below.
// First, we check that the settings page doesn't exist.
assert-false: "#settings"
@@ -138,9 +139,15 @@ wait-for-css: ("#help-button .popover", {"display": "block"})
assert-css: ("#settings-menu .popover", {"display": "none"})
// Now we go to the settings page to check that the CSS is loaded as expected.
-goto: file://|DOC_PATH|/settings.html
+goto: "file://" + |DOC_PATH| + "/settings.html"
wait-for: "#settings"
-assert-css: (".setting-line .toggle .slider", {"width": "45px", "margin-right": "20px"})
+assert-css: (
+ ".setting-line .toggle .slider",
+ {"width": "45px", "margin-right": "20px", "border": "0px none rgb(0, 0, 0)"},
+)
+
+assert-attribute-false: ("#settings", {"class": "popover"}, CONTAINS)
+compare-elements-position: (".sub form", "#settings", ("x"))
// We now check the display with JS disabled.
assert-false: "noscript section"
diff --git a/src/test/rustdoc-gui/shortcuts.goml b/src/test/rustdoc-gui/shortcuts.goml
index 1f20a0eaa..9068680d6 100644
--- a/src/test/rustdoc-gui/shortcuts.goml
+++ b/src/test/rustdoc-gui/shortcuts.goml
@@ -1,5 +1,5 @@
// Check that the various shortcuts are working.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
// We first check that the search input isn't already focused.
assert-false: "input.search-input:focus"
press-key: "s"
@@ -11,3 +11,21 @@ press-key: "?"
assert-css: ("#help-button .popover", {"display": "block"})
press-key: "Escape"
assert-css: ("#help-button .popover", {"display": "none"})
+// Checking doc collapse and expand.
+// It should be displaying a "-":
+assert-text: ("#toggle-all-docs", "[\u2212]")
+press-key: "-"
+wait-for-text: ("#toggle-all-docs", "[+]")
+assert-attribute: ("#toggle-all-docs", {"class": "will-expand"})
+// Pressing it again shouldn't do anything.
+press-key: "-"
+assert-text: ("#toggle-all-docs", "[+]")
+assert-attribute: ("#toggle-all-docs", {"class": "will-expand"})
+// Expanding now.
+press-key: "+"
+wait-for-text: ("#toggle-all-docs", "[\u2212]")
+assert-attribute: ("#toggle-all-docs", {"class": ""})
+// Pressing it again shouldn't do anything.
+press-key: "+"
+assert-text: ("#toggle-all-docs", "[\u2212]")
+assert-attribute: ("#toggle-all-docs", {"class": ""})
diff --git a/src/test/rustdoc-gui/sidebar-links-color.goml b/src/test/rustdoc-gui/sidebar-links-color.goml
new file mode 100644
index 000000000..18a1a3fad
--- /dev/null
+++ b/src/test/rustdoc-gui/sidebar-links-color.goml
@@ -0,0 +1,233 @@
+// This test checks links colors in sidebar before and after hover.
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
+
+// This is needed so that the text color is computed.
+show-text: true
+
+// Ayu theme
+local-storage: {
+ "rustdoc-theme": "ayu",
+ "rustdoc-use-system-theme": "false",
+}
+reload:
+
+// Struct
+assert-css: (
+ ".sidebar .block.struct a:not(.current)",
+ {"color": "rgb(83, 177, 219)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.struct a:not(.current)"
+assert-css: (
+ ".sidebar .block.struct a:hover",
+ {"color": "rgb(255, 180, 76)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+// Enum
+assert-css: (
+ ".sidebar .block.enum a",
+ {"color": "rgb(83, 177, 219)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.enum a"
+assert-css: (
+ ".sidebar .block.enum a:hover",
+ {"color": "rgb(255, 180, 76)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+// Union
+assert-css: (
+ ".sidebar .block.union a",
+ {"color": "rgb(83, 177, 219)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.union a"
+assert-css: (
+ ".sidebar .block.union a:hover",
+ {"color": "rgb(255, 180, 76)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+// Trait
+assert-css: (
+ ".sidebar .block.trait a",
+ {"color": "rgb(83, 177, 219)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.trait a"
+assert-css: (
+ ".sidebar .block.trait a:hover",
+ {"color": "rgb(255, 180, 76)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+// Function
+assert-css: (
+ ".sidebar .block.fn a",
+ {"color": "rgb(83, 177, 219)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.fn a"
+assert-css: (
+ ".sidebar .block.fn a:hover",
+ {"color": "rgb(255, 180, 76)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+// Type definition
+assert-css: (
+ ".sidebar .block.type a",
+ {"color": "rgb(83, 177, 219)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.type a"
+assert-css: (
+ ".sidebar .block.type a:hover",
+ {"color": "rgb(255, 180, 76)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+// Keyword
+assert-css: (
+ ".sidebar .block.keyword a",
+ {"color": "rgb(83, 177, 219)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.keyword a"
+assert-css: (
+ ".sidebar .block.keyword a:hover",
+ {"color": "rgb(255, 180, 76)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+
+// Dark theme
+local-storage: {"rustdoc-theme": "dark"}
+reload:
+
+// Struct
+assert-css: (
+ ".sidebar .block.struct a:not(.current)",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.struct a:not(.current)"
+assert-css: (
+ ".sidebar .block.struct a:hover",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgb(68, 68, 68)"},
+)
+// Enum
+assert-css: (
+ ".sidebar .block.enum a",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.enum a"
+assert-css: (
+ ".sidebar .block.enum a:hover",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgb(68, 68, 68)"},
+)
+// Union
+assert-css: (
+ ".sidebar .block.union a",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.union a"
+assert-css: (
+ ".sidebar .block.union a:hover",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgb(68, 68, 68)"},
+)
+// Trait
+assert-css: (
+ ".sidebar .block.trait a",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.trait a"
+assert-css: (
+ ".sidebar .block.trait a:hover",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgb(68, 68, 68)"},
+)
+// Function
+assert-css: (
+ ".sidebar .block.fn a",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.fn a"
+assert-css: (
+ ".sidebar .block.fn a:hover",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgb(68, 68, 68)"},
+)
+// Type definition
+assert-css: (
+ ".sidebar .block.type a",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.type a"
+assert-css: (
+ ".sidebar .block.type a:hover",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgb(68, 68, 68)"},
+)
+// Keyword
+assert-css: (
+ ".sidebar .block.keyword a",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.keyword a"
+assert-css: (
+ ".sidebar .block.keyword a:hover",
+ {"color": "rgb(253, 191, 53)", "background-color": "rgb(68, 68, 68)"},
+)
+
+// Light theme
+local-storage: {"rustdoc-theme": "light"}
+reload:
+
+// Struct
+assert-css: (
+ ".sidebar .block.struct a:not(.current)",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.struct a:not(.current)"
+assert-css: (
+ ".sidebar .block.struct a:hover",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgb(255, 255, 255)"},
+)
+// Enum
+assert-css: (
+ ".sidebar .block.enum a",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.enum a"
+assert-css: (
+ ".sidebar .block.enum a:hover",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgb(255, 255, 255)"},
+)
+// Union
+assert-css: (
+ ".sidebar .block.union a",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.union a"
+assert-css: (
+ ".sidebar .block.union a:hover",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgb(255, 255, 255)"},
+)
+// Trait
+assert-css: (
+ ".sidebar .block.trait a",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.trait a"
+assert-css: (
+ ".sidebar .block.trait a:hover",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgb(255, 255, 255)"},
+)
+// Function
+assert-css: (
+ ".sidebar .block.fn a",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.fn a"
+assert-css: (
+ ".sidebar .block.fn a:hover",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgb(255, 255, 255)"},
+)
+// Type definition
+assert-css: (
+ ".sidebar .block.type a",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.type a"
+assert-css: (
+ ".sidebar .block.type a:hover",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgb(255, 255, 255)"},
+)
+// Keyword
+assert-css: (
+ ".sidebar .block.keyword a",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgba(0, 0, 0, 0)"},
+)
+move-cursor-to: ".sidebar .block.keyword a"
+assert-css: (
+ ".sidebar .block.keyword a:hover",
+ {"color": "rgb(53, 109, 164)", "background-color": "rgb(255, 255, 255)"},
+)
diff --git a/src/test/rustdoc-gui/sidebar-macro-reexport.goml b/src/test/rustdoc-gui/sidebar-macro-reexport.goml
index a3a62fe54..b5c1b6a43 100644
--- a/src/test/rustdoc-gui/sidebar-macro-reexport.goml
+++ b/src/test/rustdoc-gui/sidebar-macro-reexport.goml
@@ -1,5 +1,5 @@
// This test ensures that the reexport of a macro doesn't make the original macro
// displayed twice in the sidebar.
-goto: file://|DOC_PATH|/test_docs/macro.repro.html
-wait-for: ".sidebar-elems .macro .macro"
+goto: "file://" + |DOC_PATH| + "/test_docs/macro.repro.html"
+wait-for: ".sidebar-elems .block.macro a"
assert-count: ("//*[@class='sidebar-elems']//*[@class='block macro']//a[text()='repro']", 1)
diff --git a/src/test/rustdoc-gui/sidebar-mobile-scroll.goml b/src/test/rustdoc-gui/sidebar-mobile-scroll.goml
index dc50185f0..2449269b1 100644
--- a/src/test/rustdoc-gui/sidebar-mobile-scroll.goml
+++ b/src/test/rustdoc-gui/sidebar-mobile-scroll.goml
@@ -1,12 +1,12 @@
// This test ensures that the mobile sidebar preserves scroll position.
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
// Switching to "mobile view" by reducing the width to 600px.
-size: (600, 600)
+size: (700, 600)
assert-css: (".sidebar", {"display": "block", "left": "-1000px"})
// Scroll down.
scroll-to: "//h2[@id='blanket-implementations']"
-assert-window-property: {"pageYOffset": "643"}
+assert-window-property: {"pageYOffset": "627"}
// Open the sidebar menu.
click: ".sidebar-menu-toggle"
@@ -21,11 +21,11 @@ assert-window-property: {"pageYOffset": "0"}
// Close the sidebar menu. Make sure the scroll position gets restored.
click: ".sidebar-menu-toggle"
wait-for-css: (".sidebar", {"left": "-1000px"})
-assert-window-property: {"pageYOffset": "643"}
+assert-window-property: {"pageYOffset": "627"}
// Now test that scrollability returns when the browser window is just resized.
click: ".sidebar-menu-toggle"
wait-for-css: (".sidebar", {"left": "0px"})
assert-window-property: {"pageYOffset": "0"}
size: (900, 600)
-assert-window-property: {"pageYOffset": "643"}
+assert-window-property: {"pageYOffset": "627"}
diff --git a/src/test/rustdoc-gui/sidebar-mobile.goml b/src/test/rustdoc-gui/sidebar-mobile.goml
index 033c65783..453873f1b 100644
--- a/src/test/rustdoc-gui/sidebar-mobile.goml
+++ b/src/test/rustdoc-gui/sidebar-mobile.goml
@@ -1,7 +1,7 @@
// This test ensure that the sidebar isn't "hidden" on mobile but instead moved out of the viewport.
// This is especially important for devices for "text-first" content (like for users with
// sight issues).
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
// Switching to "mobile view" by reducing the width to 600px.
size: (600, 600)
assert-css: (".sidebar", {"display": "block", "left": "-1000px"})
@@ -13,7 +13,7 @@ click: ".sidebar-menu-toggle"
assert-css: (".sidebar", {"display": "block", "left": "-1000px"})
// Force the sidebar open by focusing a link inside it.
// This makes it easier for keyboard users to get to it.
-focus: ".sidebar-title a"
+focus: ".sidebar-elems h3 a"
assert-css: (".sidebar", {"display": "block", "left": "0px"})
// When we tab out of the sidebar, close it.
focus: ".search-input"
@@ -23,6 +23,11 @@ assert-css: (".sidebar", {"display": "block", "left": "-1000px"})
click: ".sidebar-menu-toggle"
assert-css: (".sidebar", {"left": "0px"})
+// Make sure the "struct Foo" header is hidden, since the mobile topbar already does it.
+assert-css: ("//nav[contains(@class, 'sidebar')]//h2/a[text()='Foo']/parent::h2", {"display": "none"})
+// Make sure the global navigation is still here.
+assert-css: ("//nav[contains(@class, 'sidebar')]//h2/a[text()='In test_docs']/parent::h2", {"display": "block"})
+
// Click elsewhere.
click: "body"
assert-css: (".sidebar", {"display": "block", "left": "-1000px"})
@@ -39,26 +44,27 @@ assert-position: ("#method\.must_use", {"y": 45})
// Check that the bottom-most item on the sidebar menu can be scrolled fully into view.
click: ".sidebar-menu-toggle"
scroll-to: ".block.keyword li:nth-child(1)"
-compare-elements-position-near: (".block.keyword li:nth-child(1)", ".mobile-topbar", {"y": 543})
+compare-elements-position-near: (".block.keyword li:nth-child(1)", ".mobile-topbar", {"y": 543.19})
// Now checking the background color of the sidebar.
+show-text: true
local-storage: {"rustdoc-use-system-theme": "false", "rustdoc-theme": "dark"}
reload:
// Open the sidebar menu.
click: ".sidebar-menu-toggle"
-assert-css: (".sidebar", {"background-color": "rgb(80, 80, 80)"})
+assert-css: (".sidebar", {"background-color": "rgb(80, 80, 80)", "color": "rgb(221, 221, 221)"})
local-storage: {"rustdoc-use-system-theme": "false", "rustdoc-theme": "ayu"}
reload:
// Open the sidebar menu.
click: ".sidebar-menu-toggle"
-assert-css: (".sidebar", {"background-color": "rgb(20, 25, 31)"})
+assert-css: (".sidebar", {"background-color": "rgb(20, 25, 31)", "color": "rgb(197, 197, 197)"})
local-storage: {"rustdoc-use-system-theme": "false", "rustdoc-theme": "light"}
reload:
// Open the sidebar menu.
click: ".sidebar-menu-toggle"
-assert-css: (".sidebar", {"background-color": "rgb(245, 245, 245)"})
+assert-css: (".sidebar", {"background-color": "rgb(245, 245, 245)", "color": "rgb(0, 0, 0)"})
diff --git a/src/test/rustdoc-gui/sidebar-source-code-display.goml b/src/test/rustdoc-gui/sidebar-source-code-display.goml
index 4321efcdb..4155dab64 100644
--- a/src/test/rustdoc-gui/sidebar-source-code-display.goml
+++ b/src/test/rustdoc-gui/sidebar-source-code-display.goml
@@ -1,22 +1,19 @@
// This test ensures that the elements in the sidebar are displayed correctly.
javascript: false
-goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
+goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
// Since the javascript is disabled, there shouldn't be a toggle.
assert-false: "#sidebar-toggle"
-// For some reason, we need to wait a bit here because it seems like the transition on opacity
-// is being applied whereas it can't be reproduced in a browser...
-wait-for-css: (".sidebar > *", {"visibility": "hidden", "opacity": 0})
+wait-for-css: (".sidebar", {"display": "none"})
// Let's retry with javascript enabled.
javascript: true
reload:
wait-for: "#sidebar-toggle"
-assert-css: ("#sidebar-toggle", {"visibility": "visible", "opacity": 1})
-assert-css: (".sidebar > *:not(#sidebar-toggle)", {"visibility": "hidden", "opacity": 0})
+assert-css: ("#sidebar-toggle", {"visibility": "visible"})
+assert-css: (".sidebar > *:not(#sidebar-toggle)", {"visibility": "hidden"})
// Let's expand the sidebar now.
click: "#sidebar-toggle"
-// Because of the transition CSS, we check by using `wait-for-css` instead of `assert-css`.
-wait-for-css: ("#sidebar-toggle", {"visibility": "visible", "opacity": 1})
+wait-for-css: ("#sidebar-toggle", {"visibility": "visible"})
// We now check that opening the sidebar and clicking a link will leave it open.
// The behavior here on desktop is different than the behavior on mobile,
@@ -25,7 +22,7 @@ wait-for-css: ("#sidebar-toggle", {"visibility": "visible", "opacity": 1})
wait-for-css: (".sidebar", {"width": "300px"})
assert-local-storage: {"rustdoc-source-sidebar-show": "true"}
click: ".sidebar a.selected"
-goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
+goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
wait-for-css: (".sidebar", {"width": "300px"})
assert-local-storage: {"rustdoc-source-sidebar-show": "true"}
@@ -36,7 +33,7 @@ show-text: true
local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
reload:
// Waiting for the sidebar to be displayed...
-wait-for-css: ("#sidebar-toggle", {"visibility": "visible", "opacity": 1})
+wait-for-css: ("#sidebar-toggle", {"visibility": "visible"})
assert-css: (
"#source-sidebar details[open] > .files a.selected",
{"color": "rgb(0, 0, 0)", "background-color": "rgb(255, 255, 255)"},
@@ -91,7 +88,7 @@ assert-css: (
local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"}
reload:
// Waiting for the sidebar to be displayed...
-wait-for-css: ("#sidebar-toggle", {"visibility": "visible", "opacity": 1})
+wait-for-css: ("#sidebar-toggle", {"visibility": "visible"})
assert-css: (
"#source-sidebar details[open] > .files > a.selected",
{"color": "rgb(221, 221, 221)", "background-color": "rgb(51, 51, 51)"},
@@ -146,7 +143,7 @@ assert-css: (
local-storage: {"rustdoc-theme": "ayu", "rustdoc-use-system-theme": "false"}
reload:
// Waiting for the sidebar to be displayed...
-wait-for-css: ("#sidebar-toggle", {"visibility": "visible", "opacity": 1})
+wait-for-css: ("#sidebar-toggle", {"visibility": "visible"})
assert-css: (
"#source-sidebar details[open] > .files a.selected",
{"color": "rgb(255, 180, 76)", "background-color": "rgb(20, 25, 31)"},
@@ -201,7 +198,7 @@ assert-css: (
size: (500, 700)
reload:
// Waiting for the sidebar to be displayed...
-wait-for-css: ("#sidebar-toggle", {"visibility": "visible", "opacity": 1})
+wait-for-css: ("#sidebar-toggle", {"visibility": "visible"})
// We now check it takes the full size of the display.
assert-property: ("body", {"clientWidth": "500", "clientHeight": "700"})
@@ -253,7 +250,7 @@ click: "#sidebar-toggle"
wait-for-css: ("#source-sidebar", {"visibility": "visible"})
assert-local-storage: {"rustdoc-source-sidebar-show": "true"}
click: ".sidebar a.selected"
-goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
+goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
wait-for-css: ("#source-sidebar", {"visibility": "hidden"})
assert-local-storage: {"rustdoc-source-sidebar-show": "false"}
// Resize back to desktop size, to check that the sidebar doesn't spontaneously open.
diff --git a/src/test/rustdoc-gui/sidebar-source-code.goml b/src/test/rustdoc-gui/sidebar-source-code.goml
index e882080c7..9ba663687 100644
--- a/src/test/rustdoc-gui/sidebar-source-code.goml
+++ b/src/test/rustdoc-gui/sidebar-source-code.goml
@@ -1,6 +1,6 @@
// The goal of this test is to ensure that the sidebar is working as expected in the source
// code pages.
-goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
+goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
// First: desktop mode.
size: (1100, 800)
// We check that the sidebar isn't expanded and has the expected width.
@@ -17,7 +17,7 @@ wait-for: "html:not(.expanded)"
assert: "nav.sidebar"
// Checking that only the path to the current file is "open".
-goto: file://|DOC_PATH|/src/lib2/another_folder/sub_mod/mod.rs.html
+goto: "file://" + |DOC_PATH| + "/src/lib2/another_folder/sub_mod/mod.rs.html"
// First we expand the sidebar again.
click: (10, 10)
// We wait for the sidebar to be expanded.
@@ -42,4 +42,4 @@ assert-false: ".source-sidebar-expanded"
assert: "nav.sidebar"
// Check that the topbar is not visible
-assert-property: (".mobile-topbar", {"offsetParent": "null"})
+assert-false: ".mobile-topbar"
diff --git a/src/test/rustdoc-gui/sidebar.goml b/src/test/rustdoc-gui/sidebar.goml
index 32fe3334f..5058630f4 100644
--- a/src/test/rustdoc-gui/sidebar.goml
+++ b/src/test/rustdoc-gui/sidebar.goml
@@ -1,5 +1,6 @@
// Checks multiple things on the sidebar display (width of its elements, colors, etc).
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
+assert-property: (".sidebar", {"clientWidth": "200"})
show-text: true
local-storage: {"rustdoc-theme": "light"}
// We reload the page so the local storage settings are being used.
@@ -8,26 +9,29 @@ reload:
assert-text: (".sidebar > .location", "Crate test_docs")
// In modules, we only have one "location" element.
assert-count: (".sidebar .location", 1)
+assert-count: (".sidebar h2", 1)
assert-text: ("#all-types", "All Items")
assert-css: ("#all-types", {"color": "rgb(53, 109, 164)"})
// We check that we have the crates list and that the "current" on is "test_docs".
-assert-text: (".sidebar-elems .crate > ul > li > a.current", "test_docs")
+assert-text: (".sidebar-elems ul.crate > li > a.current", "test_docs")
// And we're also supposed to have the list of items in the current module.
assert-text: (".sidebar-elems section ul > li:nth-child(1)", "Re-exports")
assert-text: (".sidebar-elems section ul > li:nth-child(2)", "Modules")
assert-text: (".sidebar-elems section ul > li:nth-child(3)", "Macros")
assert-text: (".sidebar-elems section ul > li:nth-child(4)", "Structs")
assert-text: (".sidebar-elems section ul > li:nth-child(5)", "Enums")
-assert-text: (".sidebar-elems section ul > li:nth-child(6)", "Traits")
-assert-text: (".sidebar-elems section ul > li:nth-child(7)", "Functions")
-assert-text: (".sidebar-elems section ul > li:nth-child(8)", "Type Definitions")
-assert-text: (".sidebar-elems section ul > li:nth-child(9)", "Unions")
-assert-text: (".sidebar-elems section ul > li:nth-child(10)", "Keywords")
+assert-text: (".sidebar-elems section ul > li:nth-child(6)", "Constants")
+assert-text: (".sidebar-elems section ul > li:nth-child(7)", "Traits")
+assert-text: (".sidebar-elems section ul > li:nth-child(8)", "Functions")
+assert-text: (".sidebar-elems section ul > li:nth-child(9)", "Type Definitions")
+assert-text: (".sidebar-elems section ul > li:nth-child(10)", "Unions")
+assert-text: (".sidebar-elems section ul > li:nth-child(11)", "Keywords")
assert-text: ("#structs + .item-table .item-left > a", "Foo")
click: "#structs + .item-table .item-left > a"
// PAGE: struct.Foo.html
-assert-count: (".sidebar .location", 2)
+assert-count: (".sidebar .location", 1)
+assert-count: (".sidebar h2", 2)
// We check that there is no crate listed outside of the top level.
assert-false: ".sidebar-elems > .crate"
@@ -38,38 +42,43 @@ click: ".sidebar h2.location a"
assert-property: ("html", {"scrollTop": "0"})
// We now go back to the crate page to click on the "lib2" crate link.
-goto: file://|DOC_PATH|/test_docs/index.html
-assert-css: (".sidebar-elems .crate > ul > li:first-child > a", {"color": "rgb(53, 109, 164)"})
-click: ".sidebar-elems .crate > ul > li:first-child > a"
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
+assert-property: (".sidebar", {"clientWidth": "200"})
+assert-css: (".sidebar-elems ul.crate > li:first-child > a", {"color": "rgb(53, 109, 164)"})
+click: ".sidebar-elems ul.crate > li:first-child > a"
// PAGE: lib2/index.html
-goto: file://|DOC_PATH|/lib2/index.html
+goto: "file://" + |DOC_PATH| + "/lib2/index.html"
+assert-property: (".sidebar", {"clientWidth": "200"})
assert-text: (".sidebar > .location", "Crate lib2")
// We check that we have the crates list and that the "current" on is now "lib2".
-assert-text: (".sidebar-elems .crate > ul > li > a.current", "lib2")
+assert-text: (".sidebar-elems ul.crate > li > a.current", "lib2")
// We now go to the "foobar" function page.
-assert-text: (".sidebar-elems > section .block ul > li:nth-child(1)", "Modules")
-assert-text: (".sidebar-elems > section .block ul > li:nth-child(2)", "Structs")
-assert-text: (".sidebar-elems > section .block ul > li:nth-child(3)", "Traits")
-assert-text: (".sidebar-elems > section .block ul > li:nth-child(4)", "Functions")
-assert-text: (".sidebar-elems > section .block ul > li:nth-child(5)", "Type Definitions")
+assert-text: (".sidebar-elems > section ul.block > li:nth-child(1)", "Modules")
+assert-text: (".sidebar-elems > section ul.block > li:nth-child(2)", "Structs")
+assert-text: (".sidebar-elems > section ul.block > li:nth-child(3)", "Traits")
+assert-text: (".sidebar-elems > section ul.block > li:nth-child(4)", "Functions")
+assert-text: (".sidebar-elems > section ul.block > li:nth-child(5)", "Type Definitions")
assert-text: ("#functions + .item-table .item-left > a", "foobar")
click: "#functions + .item-table .item-left > a"
// PAGE: fn.foobar.html
-// In items containing no items (like functions or constants) and in modules, we have one
-// "location" elements.
-assert-count: (".sidebar .location", 1)
-assert-text: (".sidebar .sidebar-elems .location", "In lib2")
+// In items containing no items (like functions or constants) and in modules, we have no
+// "location" elements. Only the parent module h2.
+assert-count: (".sidebar .location", 0)
+assert-count: (".sidebar h2", 1)
+assert-text: (".sidebar .sidebar-elems h2", "In lib2")
// We check that we don't have the crate list.
assert-false: ".sidebar-elems > .crate"
-goto: ./module/index.html
+goto: "./module/index.html"
+assert-property: (".sidebar", {"clientWidth": "200"})
assert-text: (".sidebar > .location", "Module module")
// We check that we don't have the crate list.
assert-false: ".sidebar-elems > .crate"
-goto: ./sub_module/sub_sub_module/index.html
+goto: "./sub_module/sub_sub_module/index.html"
+assert-property: (".sidebar", {"clientWidth": "200"})
assert-text: (".sidebar > .location", "Module sub_sub_module")
// We check that we don't have the crate list.
assert-false: ".sidebar-elems .crate"
@@ -77,12 +86,22 @@ assert-text: (".sidebar-elems > section ul > li:nth-child(1)", "Functions")
assert-text: ("#functions + .item-table .item-left > a", "foo")
// Links to trait implementations in the sidebar should not wrap even if they are long.
-goto: file://|DOC_PATH|/lib2/struct.HasALongTraitWithParams.html
+goto: "file://" + |DOC_PATH| + "/lib2/struct.HasALongTraitWithParams.html"
+assert-property: (".sidebar", {"clientWidth": "200"})
assert-property: (".sidebar-elems section .block li > a", {"offsetHeight": 29})
// Test that clicking on of the "In <module>" headings in the sidebar links to the
// appropriate anchor in index.html.
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
-click: ".block.mod h3 a"
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
+assert-property: (".sidebar", {"clientWidth": "200"})
+click: "//ul[@class='block mod']/preceding-sibling::h3/a"
// PAGE: index.html
assert-css: ("#modules", {"background-color": "rgb(253, 255, 211)"})
+
+// Finally, assert that the `[+]/[−]` toggle doesn't affect sidebar width.
+click: "#toggle-all-docs"
+assert-text: ("#toggle-all-docs", "[+]")
+assert-property: (".sidebar", {"clientWidth": "200"})
+click: "#toggle-all-docs"
+assert-text: ("#toggle-all-docs", "[−]")
+assert-property: (".sidebar", {"clientWidth": "200"}) \ No newline at end of file
diff --git a/src/test/rustdoc-gui/source-anchor-scroll.goml b/src/test/rustdoc-gui/source-anchor-scroll.goml
index 4e51c8dca..ddfe0c3d1 100644
--- a/src/test/rustdoc-gui/source-anchor-scroll.goml
+++ b/src/test/rustdoc-gui/source-anchor-scroll.goml
@@ -1,6 +1,6 @@
// We check that when the anchor changes and is output of the displayed content,
// the page is scrolled to it.
-goto: file://|DOC_PATH|/src/link_to_definition/lib.rs.html
+goto: "file://" + |DOC_PATH| + "/src/link_to_definition/lib.rs.html"
// We reduce the window size to make it easier to make an element "out of the page".
size: (600, 800)
@@ -10,7 +10,7 @@ assert-property: ("html", {"scrollTop": "0"})
click: '//a[text() = "barbar"]'
assert-property: ("html", {"scrollTop": "125"})
click: '//a[text() = "bar"]'
-assert-property: ("html", {"scrollTop": "166"})
+assert-property: ("html", {"scrollTop": "156"})
click: '//a[text() = "sub_fn"]'
assert-property: ("html", {"scrollTop": "53"})
diff --git a/src/test/rustdoc-gui/source-code-page.goml b/src/test/rustdoc-gui/source-code-page.goml
index 581f826a3..a2dac2aa6 100644
--- a/src/test/rustdoc-gui/source-code-page.goml
+++ b/src/test/rustdoc-gui/source-code-page.goml
@@ -1,30 +1,72 @@
// Checks that the interactions with the source code pages are working as expected.
-goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
+goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
+show-text: true
// Check that we can click on the line number.
-click: ".line-numbers > span:nth-child(4)" // This is the span for line 4.
+click: ".src-line-numbers > span:nth-child(4)" // This is the span for line 4.
// Ensure that the page URL was updated.
assert-document-property: ({"URL": "lib.rs.html#4"}, ENDS_WITH)
assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
// We now check that the good spans are highlighted
-goto: file://|DOC_PATH|/src/test_docs/lib.rs.html#4-6
-assert-attribute-false: (".line-numbers > span:nth-child(3)", {"class": "line-highlighted"})
-assert-attribute: (".line-numbers > span:nth-child(4)", {"class": "line-highlighted"})
-assert-attribute: (".line-numbers > span:nth-child(5)", {"class": "line-highlighted"})
-assert-attribute: (".line-numbers > span:nth-child(6)", {"class": "line-highlighted"})
-assert-attribute-false: (".line-numbers > span:nth-child(7)", {"class": "line-highlighted"})
+goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#4-6"
+assert-attribute-false: (".src-line-numbers > span:nth-child(3)", {"class": "line-highlighted"})
+assert-attribute: (".src-line-numbers > span:nth-child(4)", {"class": "line-highlighted"})
+assert-attribute: (".src-line-numbers > span:nth-child(5)", {"class": "line-highlighted"})
+assert-attribute: (".src-line-numbers > span:nth-child(6)", {"class": "line-highlighted"})
+assert-attribute-false: (".src-line-numbers > span:nth-child(7)", {"class": "line-highlighted"})
+
+define-function: (
+ "check-colors",
+ (theme, color, background_color, highlight_color, highlight_background_color),
+ [
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ ("reload"),
+ ("assert-css", (
+ ".src-line-numbers > span:not(.line-highlighted)",
+ {"color": |color|, "background-color": |background_color|},
+ ALL,
+ )),
+ ("assert-css", (
+ ".src-line-numbers > span.line-highlighted",
+ {"color": |highlight_color|, "background-color": |highlight_background_color|},
+ ALL,
+ )),
+ ],
+)
+
+call-function: ("check-colors", {
+ "theme": "ayu",
+ "color": "rgb(92, 103, 115)",
+ "background_color": "rgba(0, 0, 0, 0)",
+ "highlight_color": "rgb(112, 128, 144)",
+ "highlight_background_color": "rgba(255, 236, 164, 0.06)",
+})
+call-function: ("check-colors", {
+ "theme": "dark",
+ "color": "rgb(59, 145, 226)",
+ "background_color": "rgba(0, 0, 0, 0)",
+ "highlight_color": "rgb(59, 145, 226)",
+ "highlight_background_color": "rgb(10, 4, 47)",
+})
+call-function: ("check-colors", {
+ "theme": "light",
+ "color": "rgb(198, 126, 45)",
+ "background_color": "rgba(0, 0, 0, 0)",
+ "highlight_color": "rgb(198, 126, 45)",
+ "highlight_background_color": "rgb(253, 255, 211)",
+})
+
// This is to ensure that the content is correctly align with the line numbers.
compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y"))
// Assert that the line numbers text is aligned to the right.
-assert-css: (".line-numbers", {"text-align": "right"})
+assert-css: (".src-line-numbers", {"text-align": "right"})
// Now let's check that clicking on something else than the line number doesn't
// do anything (and certainly not add a `#NaN` to the URL!).
-show-text: true
-goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
+goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
// We use this assert-position to know where we will click.
-assert-position: ("//*[@id='1']", {"x": 104, "y": 103})
-// We click on the left of the "1" span but still in the "line-number" `<pre>`.
+assert-position: ("//*[@id='1']", {"x": 104, "y": 112})
+// We click on the left of the "1" span but still in the "src-line-number" `<pre>`.
click: (103, 103)
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
@@ -47,3 +89,25 @@ assert-property: ("#source-sidebar details:first-of-type", {"open": "false"})
// Check the spacing.
assert-css: ("#source-sidebar > details.dir-entry", {"padding-left": "4px"})
+
+// Check the search form
+assert-css: ("nav.sub", {"flex-direction": "row"})
+// The goal of this test is to ensure the search input is perfectly centered
+// between the top of the page and the top of the gray code block.
+// To check this, we maintain the invariant:
+//
+// offsetTop[nav.sub form] = offsetTop[#main-content] - offsetHeight[nav.sub form] - offsetTop[nav.sub form]
+assert-property: ("nav.sub form", {"offsetTop": 28, "offsetHeight": 34})
+assert-property: ("#main-content", {"offsetTop": 90})
+// 28 = 90 - 34 - 28
+
+// Now do the same check on moderately-sized mobile.
+size: (700, 700)
+assert-css: ("nav.sub", {"flex-direction": "row"})
+assert-property: ("nav.sub form", {"offsetTop": 21, "offsetHeight": 34})
+assert-property: ("#main-content", {"offsetTop": 76})
+// 21 = 76 - 34 - 21
+
+// Tiny mobile gets a different display where the logo is stacked on top.
+size: (450, 700)
+assert-css: ("nav.sub", {"flex-direction": "column"})
diff --git a/src/test/rustdoc-gui/src-font-size.goml b/src/test/rustdoc-gui/src-font-size.goml
index 0c01e2545..b17dfd94c 100644
--- a/src/test/rustdoc-gui/src-font-size.goml
+++ b/src/test/rustdoc-gui/src-font-size.goml
@@ -1,11 +1,11 @@
// This test ensures that the "[src]" have the same font size as their headers
// to avoid having some weird height difference in the background when the element
// is selected.
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
show-text: true
// Check the impl headers.
-assert-css: (".impl.has-srclink .srclink", {"font-size": "16px"}, ALL)
-assert-css: (".impl.has-srclink .code-header.in-band", {"font-size": "18px"}, ALL)
+assert-css: (".impl.has-srclink .srclink", {"font-size": "16px", "font-weight": 400}, ALL)
+assert-css: (".impl.has-srclink .code-header", {"font-size": "18px", "font-weight": 600}, ALL)
// Check the impl items.
-assert-css: (".impl-items .has-srclink .srclink", {"font-size": "16px"}, ALL)
-assert-css: (".impl-items .has-srclink .code-header", {"font-size": "16px"}, ALL)
+assert-css: (".impl-items .has-srclink .srclink", {"font-size": "16px", "font-weight": 400}, ALL)
+assert-css: (".impl-items .has-srclink .code-header", {"font-size": "16px", "font-weight": 600}, ALL)
diff --git a/src/test/rustdoc-gui/src/test_docs/lib.rs b/src/test/rustdoc-gui/src/test_docs/lib.rs
index 4eedf7f15..fdf97e492 100644
--- a/src/test/rustdoc-gui/src/test_docs/lib.rs
+++ b/src/test/rustdoc-gui/src/test_docs/lib.rs
@@ -5,6 +5,25 @@
#![crate_name = "test_docs"]
#![feature(rustdoc_internals)]
#![feature(doc_cfg)]
+#![feature(associated_type_defaults)]
+
+/*!
+Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy
+this crate even more!
+Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy
+this crate even more!
+Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy
+this crate even more!
+
+Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated</span>.
+Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated</span>.
+Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated</span>.
+
+Finally, you can use `quz` only on <span class="stab portability"><code>Unix or x86-64</code>
+</span>.
+Finally, you can use `quz` only on <span class="stab portability"><code>Unix or x86-64</code>
+</span>.
+*/
use std::convert::AsRef;
use std::fmt;
@@ -298,6 +317,18 @@ pub mod details {
/// <div>I'm the content of the details!</div>
/// </details>
pub struct Details;
+
+ impl Details {
+ /// We check the appearance of the `<details>`/`<summary>` in here.
+ ///
+ /// ## Hello
+ ///
+ /// <details>
+ /// <summary><h4>I'm a summary</h4></summary>
+ /// <div>I'm the content of the details!</div>
+ /// </details>
+ pub fn method() {}
+ }
}
pub mod doc_block_table {
@@ -325,3 +356,63 @@ pub mod doc_block_table {
}
}
+
+pub struct NotableStructWithLongName<R>(R);
+
+impl<R: std::io::Read> NotableStructWithLongName<R> {
+ pub fn create_an_iterator_from_read(r: R) -> NotableStructWithLongName<R> { Self(r) }
+}
+
+impl<R: std::io::Read> std::iter::Iterator for NotableStructWithLongName<R> {
+ type Item = ();
+
+ fn next(&mut self) -> Option<Self::Item> { () }
+}
+
+pub trait TraitWithNoDocblocks {
+ fn first_fn(&self);
+ fn second_fn(&self);
+}
+
+pub struct TypeWithNoDocblocks;
+
+impl TypeWithNoDocblocks {
+ fn x() -> Option<Self> {
+ Some(Self)
+ }
+ fn y() -> Option<u32> {
+ // code comment
+ let t = Self::x()?;
+ Some(0)
+ }
+}
+
+impl TypeWithNoDocblocks {
+ pub fn first_fn(&self) {}
+ pub fn second_fn<'a>(&'a self) {
+ let x = 12;
+ let y = "a";
+ let z = false;
+ }
+}
+
+pub unsafe fn unsafe_fn() {}
+
+pub fn safe_fn() {}
+
+#[repr(C)]
+pub struct WithGenerics<T: TraitWithNoDocblocks, S = String, E = WhoLetTheDogOut, P = i8> {
+ s: S,
+ t: T,
+ e: E,
+ p: P,
+}
+
+pub const CONST: u8 = 0;
+
+pub trait TraitWithoutGenerics {
+ const C: u8 = CONST;
+ type T = SomeType;
+
+ fn foo();
+}
diff --git a/src/test/rustdoc-gui/theme-change.goml b/src/test/rustdoc-gui/theme-change.goml
index fb1c37ae6..b1de3c366 100644
--- a/src/test/rustdoc-gui/theme-change.goml
+++ b/src/test/rustdoc-gui/theme-change.goml
@@ -1,5 +1,5 @@
// Ensures that the theme change is working as expected.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
local-storage: {"rustdoc-use-system-theme": "false", "rustdoc-theme": "dark"}
reload:
click: "#settings-menu"
@@ -17,7 +17,7 @@ click: "#theme-dark"
wait-for-css: ("body", { "background-color": "rgb(53, 53, 53)" })
assert-local-storage: { "rustdoc-theme": "dark" }
-goto: file://|DOC_PATH|/settings.html
+goto: "file://" + |DOC_PATH| + "/settings.html"
wait-for: "#settings"
click: "#theme-light"
wait-for-css: ("body", { "background-color": "rgb(255, 255, 255)" })
diff --git a/src/test/rustdoc-gui/theme-in-history.goml b/src/test/rustdoc-gui/theme-in-history.goml
index f576ced1c..c29571728 100644
--- a/src/test/rustdoc-gui/theme-in-history.goml
+++ b/src/test/rustdoc-gui/theme-in-history.goml
@@ -1,5 +1,5 @@
// Ensures that the theme is working when going back in history.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
// Set the theme to dark.
local-storage: {
"rustdoc-theme": "dark",
@@ -12,7 +12,7 @@ assert-css: ("body", { "background-color": "rgb(53, 53, 53)" })
assert-local-storage: { "rustdoc-theme": "dark" }
// Now we go to the settings page.
-goto: file://|DOC_PATH|/settings.html
+goto: "file://" + |DOC_PATH| + "/settings.html"
wait-for: "#settings"
// We change the theme to "light".
click: "#theme-light"
diff --git a/src/test/rustdoc-gui/toggle-click-deadspace.goml b/src/test/rustdoc-gui/toggle-click-deadspace.goml
index 8c3a0bf5b..029403ee1 100644
--- a/src/test/rustdoc-gui/toggle-click-deadspace.goml
+++ b/src/test/rustdoc-gui/toggle-click-deadspace.goml
@@ -1,6 +1,6 @@
// This test ensures that clicking on a method summary, but not on the "[-]",
// doesn't toggle the <details>.
-goto: file://|DOC_PATH|/lib2/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/lib2/struct.Foo.html"
assert-attribute: (".impl-items .rustdoc-toggle", {"open": ""})
click: "h4.code-header" // This is the position of "pub" in "pub fn a_method"
assert-attribute: (".impl-items .rustdoc-toggle", {"open": ""})
@@ -12,4 +12,4 @@ assert-attribute-false: (".impl-items .rustdoc-toggle", {"open": ""})
// Click the "Trait" part of "impl Trait" and verify it navigates.
click: "#impl-Trait-for-Foo h3 a:first-of-type"
-assert-text: (".fqn .in-band", "Trait lib2::Trait")
+assert-text: (".fqn", "Trait lib2::Trait")
diff --git a/src/test/rustdoc-gui/toggle-docs-mobile.goml b/src/test/rustdoc-gui/toggle-docs-mobile.goml
index ee6bc3cf7..6ce24a81b 100644
--- a/src/test/rustdoc-gui/toggle-docs-mobile.goml
+++ b/src/test/rustdoc-gui/toggle-docs-mobile.goml
@@ -1,6 +1,6 @@
// Checks that the documentation toggles on mobile have the correct position, style and work
// as expected.
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
size: (433, 600)
assert-attribute: (".top-doc", {"open": ""})
click: (4, 270) // This is the position of the top doc comment toggle
diff --git a/src/test/rustdoc-gui/toggle-docs.goml b/src/test/rustdoc-gui/toggle-docs.goml
index 63962b576..8c9fd0a88 100644
--- a/src/test/rustdoc-gui/toggle-docs.goml
+++ b/src/test/rustdoc-gui/toggle-docs.goml
@@ -1,5 +1,5 @@
// Checks that the documentation toggles have the correct position, style and work as expected.
-goto: file://|DOC_PATH|/test_docs/index.html
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
assert-attribute: ("#main-content > details.top-doc", {"open": ""})
assert-text: ("#toggle-all-docs", "[−]")
click: "#toggle-all-docs"
@@ -13,7 +13,7 @@ wait-for-attribute: ("#main-content > details.top-doc", {"open": ""})
assert-text: ("#toggle-all-docs", "[−]")
// Check that it works on non-module pages as well.
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
// We first check that everything is visible.
assert-text: ("#toggle-all-docs", "[−]")
assert-attribute: ("#implementations-list details.rustdoc-toggle", {"open": ""}, ALL)
diff --git a/src/test/rustdoc-gui/toggle-implementors.goml b/src/test/rustdoc-gui/toggle-implementors.goml
index 15521ff0f..8ff5b91af 100644
--- a/src/test/rustdoc-gui/toggle-implementors.goml
+++ b/src/test/rustdoc-gui/toggle-implementors.goml
@@ -1,4 +1,4 @@
// This test ensures that the implementors toggle are not open by default.
-goto: file://|DOC_PATH|/implementors/trait.Whatever.html
+goto: "file://" + |DOC_PATH| + "/implementors/trait.Whatever.html"
assert-attribute-false: ("#implementors-list > details", {"open": ""}, ALL)
diff --git a/src/test/rustdoc-gui/toggled-open-implementations.goml b/src/test/rustdoc-gui/toggled-open-implementations.goml
index bc97b38c8..e4d59b5d7 100644
--- a/src/test/rustdoc-gui/toggled-open-implementations.goml
+++ b/src/test/rustdoc-gui/toggled-open-implementations.goml
@@ -1,5 +1,5 @@
// This tests that the "implementations" section on struct/enum pages
// has all the implementations toggled open by default, so users can
// find method names in those implementations with Ctrl-F.
-goto: file://|DOC_PATH|/test_docs/struct.Foo.html
+goto: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
assert-attribute: (".rustdoc-toggle.implementors-toggle", {"open": ""})
diff --git a/src/test/rustdoc-gui/trait-sidebar-item-order.goml b/src/test/rustdoc-gui/trait-sidebar-item-order.goml
index d77d1dca4..a799444a1 100644
--- a/src/test/rustdoc-gui/trait-sidebar-item-order.goml
+++ b/src/test/rustdoc-gui/trait-sidebar-item-order.goml
@@ -1,5 +1,5 @@
// Checks that the elements in the sidebar are alphabetically sorted.
-goto: file://|DOC_PATH|/test_docs/trait.AnotherOne.html
+goto: "file://" + |DOC_PATH| + "/test_docs/trait.AnotherOne.html"
assert-text: (".sidebar-elems section .block li:nth-of-type(1) > a", "another")
assert-text: (".sidebar-elems section .block li:nth-of-type(2) > a", "func1")
assert-text: (".sidebar-elems section .block li:nth-of-type(3) > a", "func2")
diff --git a/src/test/rustdoc-gui/type-declation-overflow.goml b/src/test/rustdoc-gui/type-declation-overflow.goml
index 9a46908f9..fce3002e7 100644
--- a/src/test/rustdoc-gui/type-declation-overflow.goml
+++ b/src/test/rustdoc-gui/type-declation-overflow.goml
@@ -1,5 +1,5 @@
// This test ensures that the items declaration content overflow is handled inside the <pre> directly.
-goto: file://|DOC_PATH|/lib2/long_trait/trait.ALongNameBecauseItHelpsTestingTheCurrentProblem.html
+goto: "file://" + |DOC_PATH| + "/lib2/long_trait/trait.ALongNameBecauseItHelpsTestingTheCurrentProblem.html"
// We set a fixed size so there is no chance of "random" resize.
size: (1100, 800)
// Logically, the <body> scroll width should be the width of the window.
@@ -8,30 +8,30 @@ assert-property: ("body", {"scrollWidth": "1100"})
assert-property: (".item-decl pre", {"scrollWidth": "1324"})
// In the table-ish view on the module index, the name should not be wrapped more than necessary.
-goto: file://|DOC_PATH|/lib2/too_long/index.html
+goto: "file://" + |DOC_PATH| + "/lib2/too_long/index.html"
assert-property: (".item-table .struct", {"offsetWidth": "684"})
// We now make the same check on type declaration...
-goto: file://|DOC_PATH|/lib2/too_long/type.ReallyLongTypeNameLongLongLong.html
+goto: "file://" + |DOC_PATH| + "/lib2/too_long/type.ReallyLongTypeNameLongLongLong.html"
assert-property: ("body", {"scrollWidth": "1100"})
// We now check that the section width hasn't grown because of it.
-assert-property: ("#main-content", {"scrollWidth": "825"})
+assert-property: ("#main-content", {"scrollWidth": "840"})
// And now checking that it has scrollable content.
assert-property: (".item-decl pre", {"scrollWidth": "1103"})
// ... and constant.
// On a sidenote, it also checks that the (very) long title isn't changing the docblock width.
-goto: file://|DOC_PATH|/lib2/too_long/constant.ReallyLongTypeNameLongLongLongConstBecauseWhyNotAConstRightGigaGigaSupraLong.html
+goto: "file://" + |DOC_PATH| + "/lib2/too_long/constant.ReallyLongTypeNameLongLongLongConstBecauseWhyNotAConstRightGigaGigaSupraLong.html"
assert-property: ("body", {"scrollWidth": "1100"})
// We now check that the section width hasn't grown because of it.
-assert-property: ("#main-content", {"scrollWidth": "825"})
+assert-property: ("#main-content", {"scrollWidth": "840"})
// And now checking that it has scrollable content.
assert-property: (".item-decl pre", {"scrollWidth": "950"})
// On mobile:
size: (600, 600)
-goto: file://|DOC_PATH|/lib2/too_long/struct.SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName.html
+goto: "file://" + |DOC_PATH| + "/lib2/too_long/struct.SuperIncrediblyLongLongLongLongLongLongLongGigaGigaGigaMegaLongLongLongStructName.html"
// It shouldn't have an overflow in the topbar either.
-assert-property: (".mobile-topbar .location", {"scrollWidth": "500"})
-assert-property: (".mobile-topbar .location", {"clientWidth": "500"})
-assert-css: (".mobile-topbar .location", {"overflow-x": "hidden"})
+store-property: (scrollWidth, ".mobile-topbar h2", "scrollWidth")
+assert-property: (".mobile-topbar h2", {"clientWidth": |scrollWidth|})
+assert-css: (".mobile-topbar h2", {"overflow-x": "hidden"})
diff --git a/src/test/rustdoc-gui/unsafe-fn.goml b/src/test/rustdoc-gui/unsafe-fn.goml
new file mode 100644
index 000000000..5e43b85fc
--- /dev/null
+++ b/src/test/rustdoc-gui/unsafe-fn.goml
@@ -0,0 +1,28 @@
+// Check position and color of the `<sup>` for unsafe elements.
+goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
+// If the text isn't displayed, the browser doesn't compute color style correctly...
+show-text: true
+
+compare-elements-property: (
+ "//a[@title='test_docs::safe_fn fn']/..",
+ "//a[@title='test_docs::unsafe_fn fn']/..",
+ ["clientHeight"]
+)
+
+define-function: (
+ "sup-check",
+ // `theme` is the theme being tested.
+ // `color` is the expected color of the `<sup>` element.
+ (theme, color),
+ [
+ // Set the theme.
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ // We reload the page so the local storage settings are being used.
+ ("reload"),
+ ("assert-css", (".item-left sup", {"color": |color|})),
+ ],
+)
+
+call-function: ("sup-check", ("dark", "rgb(221, 221, 221)"))
+call-function: ("sup-check", ("ayu", "rgb(197, 197, 197)"))
+call-function: ("sup-check", ("light", "rgb(0, 0, 0)"))
diff --git a/src/test/rustdoc-gui/where-whitespace.goml b/src/test/rustdoc-gui/where-whitespace.goml
index 1a3ff1f49..776c8ec72 100644
--- a/src/test/rustdoc-gui/where-whitespace.goml
+++ b/src/test/rustdoc-gui/where-whitespace.goml
@@ -1,5 +1,5 @@
// This test ensures that the where conditions are correctly displayed.
-goto: file://|DOC_PATH|/lib2/trait.Whitespace.html
+goto: "file://" + |DOC_PATH| + "/lib2/trait.Whitespace.html"
show-text: true
// First, we check in the trait definition if the where clause is "on its own" (not on the same
// line than "pub trait Whitespace<Idx>").
@@ -7,7 +7,7 @@ compare-elements-position-false: (".item-decl code", ".where.fmt-newline", ("y")
// And that the code following it isn't on the same line either.
compare-elements-position-false: (".item-decl .fnname", ".where.fmt-newline", ("y"))
-goto: file://|DOC_PATH|/lib2/struct.WhereWhitespace.html
+goto: "file://" + |DOC_PATH| + "/lib2/struct.WhereWhitespace.html"
// We make the screen a bit wider to ensure that the trait impl is on one line.
size: (915, 915)
diff --git a/src/test/rustdoc-js-std/asrawfd.js b/src/test/rustdoc-js-std/asrawfd.js
index fd228a590..369a34f9c 100644
--- a/src/test/rustdoc-js-std/asrawfd.js
+++ b/src/test/rustdoc-js-std/asrawfd.js
@@ -6,9 +6,9 @@ const EXPECTED = {
'others': [
// Reproduction test for https://github.com/rust-lang/rust/issues/78724
// Validate that type alias methods get the correct path.
- { 'path': 'std::os::unix::io::AsRawFd', 'name': 'as_raw_fd' },
- { 'path': 'std::os::wasi::io::AsRawFd', 'name': 'as_raw_fd' },
+ { 'path': 'std::os::fd::AsRawFd', 'name': 'as_raw_fd' },
+ { 'path': 'std::os::fd::AsRawFd', 'name': 'as_raw_fd' },
{ 'path': 'std::os::linux::process::PidFd', 'name': 'as_raw_fd' },
- { 'path': 'std::os::unix::io::RawFd', 'name': 'as_raw_fd' },
+ { 'path': 'std::os::fd::RawFd', 'name': 'as_raw_fd' },
],
};
diff --git a/src/test/rustdoc-json/primitives/primitive_impls.rs b/src/test/rustdoc-json/primitives/primitive_impls.rs
new file mode 100644
index 000000000..1fc937406
--- /dev/null
+++ b/src/test/rustdoc-json/primitives/primitive_impls.rs
@@ -0,0 +1,34 @@
+#![feature(no_core)]
+#![feature(rustc_attrs)]
+#![feature(rustdoc_internals)]
+#![no_core]
+#![rustc_coherence_is_core]
+
+// @set impl_i32 = "$.index[*][?(@.docs=='Only core can do this')].id"
+
+/// Only core can do this
+impl i32 {
+ // @set identity = "$.index[*][?(@.docs=='Do Nothing')].id"
+
+ /// Do Nothing
+ pub fn identity(self) -> Self {
+ self
+ }
+
+ // @is "$.index[*][?(@.docs=='Only core can do this')].inner.items[*]" $identity
+}
+
+// @set Trait = "$.index[*][?(@.name=='Trait')].id"
+pub trait Trait {}
+// @set impl_trait_for_i32 = "$.index[*][?(@.docs=='impl Trait for i32')].id"
+/// impl Trait for i32
+impl Trait for i32 {}
+
+/// i32
+#[doc(primitive = "i32")]
+mod prim_i32 {}
+
+// @set i32 = "$.index[*][?(@.docs=='i32')].id"
+// @is "$.index[*][?(@.docs=='i32')].name" '"i32"'
+// @is "$.index[*][?(@.docs=='i32')].inner.name" '"i32"'
+// @ismany "$.index[*][?(@.docs=='i32')].inner.impls[*]" $impl_i32 $impl_trait_for_i32
diff --git a/src/test/rustdoc-json/primitive_overloading.rs b/src/test/rustdoc-json/primitives/primitive_overloading.rs
index 56b35cd14..56b35cd14 100644
--- a/src/test/rustdoc-json/primitive_overloading.rs
+++ b/src/test/rustdoc-json/primitives/primitive_overloading.rs
diff --git a/src/test/rustdoc-json/primitives.rs b/src/test/rustdoc-json/primitives/primitive_type.rs
index 8024044bc..8024044bc 100644
--- a/src/test/rustdoc-json/primitives.rs
+++ b/src/test/rustdoc-json/primitives/primitive_type.rs
diff --git a/src/test/rustdoc-json/primitive.rs b/src/test/rustdoc-json/primitives/use_primitive.rs
index 6454dd7f5..e22927374 100644
--- a/src/test/rustdoc-json/primitive.rs
+++ b/src/test/rustdoc-json/primitives/use_primitive.rs
@@ -5,7 +5,7 @@
#[doc(primitive = "usize")]
mod usize {}
-// @set local_crate_id = "$.index[*][?(@.name=='primitive')].crate_id"
+// @set local_crate_id = "$.index[*][?(@.name=='use_primitive')].crate_id"
// @has "$.index[*][?(@.name=='ilog10')]"
// @!is "$.index[*][?(@.name=='ilog10')].crate_id" $local_crate_id
diff --git a/src/test/rustdoc-json/reexport/reexport_method_from_private_module.rs b/src/test/rustdoc-json/reexport/reexport_method_from_private_module.rs
new file mode 100644
index 000000000..239b1a23b
--- /dev/null
+++ b/src/test/rustdoc-json/reexport/reexport_method_from_private_module.rs
@@ -0,0 +1,28 @@
+// Regression test for <https://github.com/rust-lang/rust/issues/102583>.
+
+// @set impl_S = "$.index[*][?(@.docs=='impl S')].id"
+// @has "$.index[*][?(@.name=='S')].inner.impls[*]" $impl_S
+// @set is_present = "$.index[*][?(@.name=='is_present')].id"
+// @is "$.index[*][?(@.docs=='impl S')].inner.items[*]" $is_present
+// @!has "$.index[*][?(@.name=='hidden_impl')]"
+// @!has "$.index[*][?(@.name=='hidden_fn')]"
+
+#![no_std]
+
+mod private_mod {
+ pub struct S;
+
+ /// impl S
+ impl S {
+ pub fn is_present() {}
+ #[doc(hidden)]
+ pub fn hidden_fn() {}
+ }
+
+ #[doc(hidden)]
+ impl S {
+ pub fn hidden_impl() {}
+ }
+}
+
+pub use private_mod::*;
diff --git a/src/test/rustdoc-ui/bare-urls.stderr b/src/test/rustdoc-ui/bare-urls.stderr
index 7097a8ddf..ccf52cd0b 100644
--- a/src/test/rustdoc-ui/bare-urls.stderr
+++ b/src/test/rustdoc-ui/bare-urls.stderr
@@ -4,12 +4,12 @@ error: this URL is not a hyperlink
LL | /// https://somewhere.com
| ^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://somewhere.com>`
|
+ = note: bare URLs are not automatically turned into clickable links
note: the lint level is defined here
--> $DIR/bare-urls.rs:3:9
|
LL | #![deny(rustdoc::bare_urls)]
| ^^^^^^^^^^^^^^^^^^
- = note: bare URLs are not automatically turned into clickable links
error: this URL is not a hyperlink
--> $DIR/bare-urls.rs:7:5
diff --git a/src/test/rustdoc-ui/check-attr-test.stderr b/src/test/rustdoc-ui/check-attr-test.stderr
index b1fa9edf0..01beba1ff 100644
--- a/src/test/rustdoc-ui/check-attr-test.stderr
+++ b/src/test/rustdoc-ui/check-attr-test.stderr
@@ -8,12 +8,12 @@ error: unknown attribute `compile-fail`. Did you mean `compile_fail`?
9 | | /// ```
| |_______^
|
+ = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully
note: the lint level is defined here
--> $DIR/check-attr-test.rs:3:9
|
3 | #![deny(rustdoc::invalid_codeblock_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully
error: unknown attribute `compilefail`. Did you mean `compile_fail`?
--> $DIR/check-attr-test.rs:5:1
diff --git a/src/test/rustdoc-ui/check-attr.stderr b/src/test/rustdoc-ui/check-attr.stderr
index 370b804c5..f66e63ab7 100644
--- a/src/test/rustdoc-ui/check-attr.stderr
+++ b/src/test/rustdoc-ui/check-attr.stderr
@@ -10,12 +10,12 @@ LL | | /// boo
LL | | /// ```
| |_______^
|
+ = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully
note: the lint level is defined here
--> $DIR/check-attr.rs:1:9
|
LL | #![deny(rustdoc::invalid_codeblock_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully
error: unknown attribute `compilefail`. Did you mean `compile_fail`?
--> $DIR/check-attr.rs:3:1
diff --git a/src/test/rustdoc-ui/check-cfg-test.stderr b/src/test/rustdoc-ui/check-cfg-test.stderr
index dc25205da..9770be2f1 100644
--- a/src/test/rustdoc-ui/check-cfg-test.stderr
+++ b/src/test/rustdoc-ui/check-cfg-test.stderr
@@ -4,8 +4,8 @@ warning: unexpected `cfg` condition value
LL | #[cfg(feature = "invalid")]
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unexpected_cfgs)]` on by default
= note: expected values for `feature` are: test
+ = note: `#[warn(unexpected_cfgs)]` on by default
warning: 1 warning emitted
diff --git a/src/test/rustdoc-ui/check-fail.stderr b/src/test/rustdoc-ui/check-fail.stderr
index 217b89d93..d8aeccbfc 100644
--- a/src/test/rustdoc-ui/check-fail.stderr
+++ b/src/test/rustdoc-ui/check-fail.stderr
@@ -32,8 +32,8 @@ LL | | //! let x = 12;
LL | | //! ```
| |_______^
|
- = note: `#[deny(rustdoc::invalid_codeblock_attributes)]` implied by `#[deny(rustdoc::all)]`
= help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function
+ = note: `#[deny(rustdoc::invalid_codeblock_attributes)]` implied by `#[deny(rustdoc::all)]`
error: unknown attribute `testharness`. Did you mean `test_harness`?
--> $DIR/check-fail.rs:16:1
diff --git a/src/test/rustdoc-ui/check.stderr b/src/test/rustdoc-ui/check.stderr
index 78ae65d31..d379f33f2 100644
--- a/src/test/rustdoc-ui/check.stderr
+++ b/src/test/rustdoc-ui/check.stderr
@@ -24,14 +24,14 @@ LL | pub fn foo() {}
warning: no documentation found for this crate's top-level module
|
+ = help: The following guide may be of use:
+ https://doc.rust-lang.org/$CHANNEL/rustdoc/how-to-write-documentation.html
note: the lint level is defined here
--> $DIR/check.rs:10:9
|
LL | #![warn(rustdoc::all)]
| ^^^^^^^^^^^^
= note: `#[warn(rustdoc::missing_crate_level_docs)]` implied by `#[warn(rustdoc::all)]`
- = help: The following guide may be of use:
- https://doc.rust-lang.org/$CHANNEL/rustdoc/how-to-write-documentation.html
warning: missing code example in this documentation
--> $DIR/check.rs:5:1
diff --git a/src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr b/src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr
index 67d9c3989..3e08354a6 100644
--- a/src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr
+++ b/src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr
@@ -4,12 +4,12 @@ error: unresolved link to `v2`
LL | /// [v2]
| ^^ no item named `v2` in scope
|
+ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
note: the lint level is defined here
--> $DIR/deny-intra-link-resolution-failure.rs:1:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: aborting due to previous error
diff --git a/src/test/rustdoc-ui/diagnostic-width.rs b/src/test/rustdoc-ui/diagnostic-width.rs
index 61961d5ec..290d9db77 100644
--- a/src/test/rustdoc-ui/diagnostic-width.rs
+++ b/src/test/rustdoc-ui/diagnostic-width.rs
@@ -1,4 +1,4 @@
-// compile-flags: -Zunstable-options --diagnostic-width=10
+// compile-flags: --diagnostic-width=10
#![deny(rustdoc::bare_urls)]
/// This is a long line that contains a http://link.com
diff --git a/src/test/rustdoc-ui/diagnostic-width.stderr b/src/test/rustdoc-ui/diagnostic-width.stderr
index fed049d2b..1a00d10d3 100644
--- a/src/test/rustdoc-ui/diagnostic-width.stderr
+++ b/src/test/rustdoc-ui/diagnostic-width.stderr
@@ -4,12 +4,12 @@ error: this URL is not a hyperlink
LL | ... a http://link.com
| ^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://link.com>`
|
+ = note: bare URLs are not automatically turned into clickable links
note: the lint level is defined here
--> $DIR/diagnostic-width.rs:2:9
|
LL | ...ny(rustdoc::bare_url...
| ^^^^^^^^^^^^^^^^^^
- = note: bare URLs are not automatically turned into clickable links
error: aborting due to previous error
diff --git a/src/test/rustdoc-ui/doc-attr.stderr b/src/test/rustdoc-ui/doc-attr.stderr
index cc2494c92..68df2771f 100644
--- a/src/test/rustdoc-ui/doc-attr.stderr
+++ b/src/test/rustdoc-ui/doc-attr.stderr
@@ -4,14 +4,14 @@ error: unknown `doc` attribute `as_ptr`
LL | #[doc(as_ptr)]
| ^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
note: the lint level is defined here
--> $DIR/doc-attr.rs:2:9
|
LL | #![deny(warnings)]
| ^^^^^^^^
= note: `#[deny(invalid_doc_attributes)]` implied by `#[deny(warnings)]`
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: invalid `doc` attribute
--> $DIR/doc-attr.rs:12:7
diff --git a/src/test/rustdoc-ui/doc-include-suggestion.stderr b/src/test/rustdoc-ui/doc-include-suggestion.stderr
index 870b7efa2..fcc93d053 100644
--- a/src/test/rustdoc-ui/doc-include-suggestion.stderr
+++ b/src/test/rustdoc-ui/doc-include-suggestion.stderr
@@ -4,9 +4,9 @@ warning: unknown `doc` attribute `include`
LL | #[doc(include = "external-cross-doc.md")]
| ------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-- help: use `doc = include_str!` instead: `#[doc = include_str!("external-cross-doc.md")]`
|
- = note: `#[warn(invalid_doc_attributes)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
+ = note: `#[warn(invalid_doc_attributes)]` on by default
warning: 1 warning emitted
diff --git a/src/test/rustdoc-ui/doc-spotlight.stderr b/src/test/rustdoc-ui/doc-spotlight.stderr
index 8e7831139..58612327f 100644
--- a/src/test/rustdoc-ui/doc-spotlight.stderr
+++ b/src/test/rustdoc-ui/doc-spotlight.stderr
@@ -4,16 +4,16 @@ error: unknown `doc` attribute `spotlight`
LL | #[doc(spotlight)]
| ^^^^^^^^^ help: use `notable_trait` instead
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
+ = note: `doc(spotlight)` was renamed to `doc(notable_trait)`
+ = note: `doc(spotlight)` is now a no-op
note: the lint level is defined here
--> $DIR/doc-spotlight.rs:2:9
|
LL | #![deny(warnings)]
| ^^^^^^^^
= note: `#[deny(invalid_doc_attributes)]` implied by `#[deny(warnings)]`
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
- = note: `doc(spotlight)` was renamed to `doc(notable_trait)`
- = note: `doc(spotlight)` is now a no-op
error: aborting due to previous error
diff --git a/src/test/rustdoc-ui/doc-test-attr.stderr b/src/test/rustdoc-ui/doc-test-attr.stderr
index 7f5e2d6bc..5e6014954 100644
--- a/src/test/rustdoc-ui/doc-test-attr.stderr
+++ b/src/test/rustdoc-ui/doc-test-attr.stderr
@@ -4,13 +4,13 @@ error: `#[doc(test(...)]` takes a list of attributes
LL | #![doc(test)]
| ^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
note: the lint level is defined here
--> $DIR/doc-test-attr.rs:2:9
|
LL | #![deny(invalid_doc_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: `#[doc(test(...)]` takes a list of attributes
--> $DIR/doc-test-attr.rs:7:8
diff --git a/src/test/rustdoc-ui/doc_cfg_hide.rs b/src/test/rustdoc-ui/doc_cfg_hide.rs
new file mode 100644
index 000000000..5d8791748
--- /dev/null
+++ b/src/test/rustdoc-ui/doc_cfg_hide.rs
@@ -0,0 +1,11 @@
+#![feature(doc_cfg_hide)]
+#![deny(warnings)]
+
+#![doc(cfg_hide = "test")] //~ ERROR
+//~^ WARN
+#![doc(cfg_hide)] //~ ERROR
+//~^ WARN
+
+#[doc(cfg_hide(doc))] //~ ERROR
+//~^ WARN
+pub fn foo() {}
diff --git a/src/test/rustdoc-ui/doc_cfg_hide.stderr b/src/test/rustdoc-ui/doc_cfg_hide.stderr
new file mode 100644
index 000000000..03623368c
--- /dev/null
+++ b/src/test/rustdoc-ui/doc_cfg_hide.stderr
@@ -0,0 +1,40 @@
+error: this attribute can only be applied at the crate level
+ --> $DIR/doc_cfg_hide.rs:9:7
+ |
+LL | #[doc(cfg_hide(doc))]
+ | ^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
+ = note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
+note: the lint level is defined here
+ --> $DIR/doc_cfg_hide.rs:2:9
+ |
+LL | #![deny(warnings)]
+ | ^^^^^^^^
+ = note: `#[deny(invalid_doc_attributes)]` implied by `#[deny(warnings)]`
+help: to apply to the crate, use an inner attribute
+ |
+LL | #![doc(cfg_hide(doc))]
+ | ~~~~~~~~~~~~~~~~~~~~~~
+
+error: `#[doc(cfg_hide(...)]` takes a list of attributes
+ --> $DIR/doc_cfg_hide.rs:4:8
+ |
+LL | #![doc(cfg_hide = "test")]
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
+
+error: `#[doc(cfg_hide(...)]` takes a list of attributes
+ --> $DIR/doc_cfg_hide.rs:6:8
+ |
+LL | #![doc(cfg_hide)]
+ | ^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
+
+error: aborting due to 3 previous errors
+
diff --git a/src/test/rustdoc-ui/doctest-edition.stderr b/src/test/rustdoc-ui/doctest-edition.stderr
index 1643d6053..8a3329aa3 100644
--- a/src/test/rustdoc-ui/doctest-edition.stderr
+++ b/src/test/rustdoc-ui/doctest-edition.stderr
@@ -7,12 +7,12 @@ LL | | //! foo'b'
LL | | //! ```
| |_______^
|
+ = note: error from rustc: prefix `foo` is unknown
note: the lint level is defined here
--> $DIR/doctest-edition.rs:3:9
|
LL | #![deny(rustdoc::invalid_rust_codeblocks)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: error from rustc: prefix `foo` is unknown
help: mark blocks that do not contain Rust code as text
|
LL | //! ```text
diff --git a/src/test/rustdoc-ui/feature-gate-rustdoc_missing_doc_code_examples.stderr b/src/test/rustdoc-ui/feature-gate-rustdoc_missing_doc_code_examples.stderr
index 517e08aa7..cbe9a3d14 100644
--- a/src/test/rustdoc-ui/feature-gate-rustdoc_missing_doc_code_examples.stderr
+++ b/src/test/rustdoc-ui/feature-gate-rustdoc_missing_doc_code_examples.stderr
@@ -4,14 +4,14 @@ error: unknown lint: `rustdoc::missing_doc_code_examples`
LL | #![allow(rustdoc::missing_doc_code_examples)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
+ = note: the `rustdoc::missing_doc_code_examples` lint is unstable
+ = note: see issue #101730 <https://github.com/rust-lang/rust/issues/101730> for more information
+ = help: add `#![feature(rustdoc_missing_doc_code_examples)]` to the crate attributes to enable
note: the lint level is defined here
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:1:9
|
LL | #![deny(unknown_lints)]
| ^^^^^^^^^^^^^
- = note: the `rustdoc::missing_doc_code_examples` lint is unstable
- = note: see issue #101730 <https://github.com/rust-lang/rust/issues/101730> for more information
- = help: add `#![feature(rustdoc_missing_doc_code_examples)]` to the crate attributes to enable
error: unknown lint: `rustdoc::missing_doc_code_examples`
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:4:1
diff --git a/src/test/rustdoc-ui/ignore-block-help.stderr b/src/test/rustdoc-ui/ignore-block-help.stderr
index 9c02ff11d..a30ea51dd 100644
--- a/src/test/rustdoc-ui/ignore-block-help.stderr
+++ b/src/test/rustdoc-ui/ignore-block-help.stderr
@@ -7,13 +7,13 @@ LL | | /// let heart = 'â¤ï¸';
LL | | /// ```
| |_______^
|
- = note: `#[warn(rustdoc::invalid_rust_codeblocks)]` on by default
help: `ignore` code blocks require valid Rust code for syntax highlighting; mark blocks that do not contain Rust code as text: ```text
--> $DIR/ignore-block-help.rs:3:5
|
LL | /// ```ignore (to-prevent-tidy-error)
| ^^^
= note: error from rustc: character literal may only contain one codepoint
+ = note: `#[warn(rustdoc::invalid_rust_codeblocks)]` on by default
warning: 1 warning emitted
diff --git a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.rs b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.rs
index 2319de556..4b1e04234 100644
--- a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.rs
+++ b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.rs
@@ -1,11 +1,12 @@
+// check-pass
// normalize-stderr-test: "`.*`" -> "`DEF_ID`"
// normalize-stdout-test: "`.*`" -> "`DEF_ID`"
// edition:2018
pub async fn f() -> impl std::fmt::Debug {
+ // rustdoc doesn't care that this is infinitely sized
#[derive(Debug)]
enum E {
- //~^ ERROR recursive type `f::{closure#0}::E` has infinite size
This(E),
Unit,
}
diff --git a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.stderr b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.stderr
deleted file mode 100644
index aa39d26fe..000000000
--- a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait-return.stderr
+++ /dev/null
@@ -1,17 +0,0 @@
-error[E0072]: recursive type `DEF_ID` has infinite size
- --> $DIR/infinite-recursive-type-impl-trait-return.rs:7:5
- |
-LL | enum E {
- | ^^^^^^ recursive type has infinite size
-LL |
-LL | This(E),
- | - recursive without indirection
- |
-help: insert some indirection (e.g., a `DEF_ID` representable
- |
-LL | This(Box<E>),
- | ++++ +
-
-error: aborting due to previous error
-
-For more information about this error, try `DEF_ID`.
diff --git a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.rs b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.rs
index b3a7ee563..ac79582fb 100644
--- a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.rs
+++ b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.rs
@@ -1,6 +1,8 @@
+// check-pass
+
fn f() -> impl Sized {
+ // rustdoc doesn't care that this is infinitely sized
enum E {
- //~^ ERROR recursive type `f::E` has infinite size
V(E),
}
unimplemented!()
diff --git a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.stderr b/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.stderr
deleted file mode 100644
index 009bedec5..000000000
--- a/src/test/rustdoc-ui/infinite-recursive-type-impl-trait.stderr
+++ /dev/null
@@ -1,17 +0,0 @@
-error[E0072]: recursive type `f::E` has infinite size
- --> $DIR/infinite-recursive-type-impl-trait.rs:2:5
- |
-LL | enum E {
- | ^^^^^^ recursive type has infinite size
-LL |
-LL | V(E),
- | - recursive without indirection
- |
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `f::E` representable
- |
-LL | V(Box<E>),
- | ++++ +
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0072`.
diff --git a/src/test/rustdoc-ui/infinite-recursive-type.stderr b/src/test/rustdoc-ui/infinite-recursive-type.stderr
index b33aba446..9e2c3ff16 100644
--- a/src/test/rustdoc-ui/infinite-recursive-type.stderr
+++ b/src/test/rustdoc-ui/infinite-recursive-type.stderr
@@ -2,12 +2,12 @@ error[E0072]: recursive type `E` has infinite size
--> $DIR/infinite-recursive-type.rs:1:1
|
LL | enum E {
- | ^^^^^^ recursive type has infinite size
+ | ^^^^^^
LL |
LL | V(E),
| - recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `E` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | V(Box<E>),
| ++++ +
diff --git a/src/test/rustdoc-ui/intra-doc/html-as-generics-intra-doc.stderr b/src/test/rustdoc-ui/intra-doc/html-as-generics-intra-doc.stderr
index 00fe229da..7c81044db 100644
--- a/src/test/rustdoc-ui/intra-doc/html-as-generics-intra-doc.stderr
+++ b/src/test/rustdoc-ui/intra-doc/html-as-generics-intra-doc.stderr
@@ -4,12 +4,12 @@ error: unresolved link to `NonExistentStruct`
LL | /// This [test][NonExistentStruct<i32>] thing!
| ^^^^^^^^^^^^^^^^^^^^^^ no item named `NonExistentStruct` in scope
|
+ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
note: the lint level is defined here
--> $DIR/html-as-generics-intra-doc.rs:2:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: unresolved link to `NonExistentStruct2`
--> $DIR/html-as-generics-intra-doc.rs:17:11
diff --git a/src/test/rustdoc-ui/intra-doc/macro-rules-error.stderr b/src/test/rustdoc-ui/intra-doc/macro-rules-error.stderr
index 8e17323fd..6ad8084b0 100644
--- a/src/test/rustdoc-ui/intra-doc/macro-rules-error.stderr
+++ b/src/test/rustdoc-ui/intra-doc/macro-rules-error.stderr
@@ -4,12 +4,12 @@ error: unresolved link to `before_but_limited_to_module`
LL | /// [before_but_limited_to_module]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `before_but_limited_to_module` in scope
|
+ = note: `macro_rules` named `before_but_limited_to_module` exists in this crate, but it is not in scope at this link's location
note: the lint level is defined here
--> $DIR/macro-rules-error.rs:5:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: `macro_rules` named `before_but_limited_to_module` exists in this crate, but it is not in scope at this link's location
error: unresolved link to `after`
--> $DIR/macro-rules-error.rs:15:6
diff --git a/src/test/rustdoc-ui/intra-doc/malformed-generics.rs b/src/test/rustdoc-ui/intra-doc/malformed-generics.rs
index 15e02925e..161625ed2 100644
--- a/src/test/rustdoc-ui/intra-doc/malformed-generics.rs
+++ b/src/test/rustdoc-ui/intra-doc/malformed-generics.rs
@@ -3,17 +3,26 @@
//! [Vec<] //~ ERROR
//! [Vec<Box<T] //~ ERROR
//! [Vec<Box<T>] //~ ERROR
+//~^ WARN
//! [Vec<Box<T>>>] //~ ERROR
+//~^ WARN
//! [Vec<T>>>] //~ ERROR
+//~^ WARN
//! [<Vec] //~ ERROR
//! [Vec::<] //~ ERROR
//! [<T>] //~ ERROR
+//~^ WARN
//! [<invalid syntax>] //~ ERROR
+//~^ WARN
//! [Vec:<T>:new()] //~ ERROR
+//~^ WARN
//! [Vec<<T>>] //~ ERROR
+//~^ WARN
//! [Vec<>] //~ ERROR
//! [Vec<<>>] //~ ERROR
// FIXME(#74563) support UFCS
//! [<Vec as IntoIterator>::into_iter] //~ ERROR
+//~^ WARN
//! [<Vec<T> as IntoIterator>::iter] //~ ERROR
+//~^ WARN
diff --git a/src/test/rustdoc-ui/intra-doc/malformed-generics.stderr b/src/test/rustdoc-ui/intra-doc/malformed-generics.stderr
index 5bc0f84e2..08349fef8 100644
--- a/src/test/rustdoc-ui/intra-doc/malformed-generics.stderr
+++ b/src/test/rustdoc-ui/intra-doc/malformed-generics.stderr
@@ -23,67 +23,67 @@ LL | //! [Vec<Box<T>]
| ^^^^^^^^^^ unbalanced angle brackets
error: unresolved link to `Vec<Box<T>>>`
- --> $DIR/malformed-generics.rs:6:6
+ --> $DIR/malformed-generics.rs:7:6
|
LL | //! [Vec<Box<T>>>]
| ^^^^^^^^^^^^ unbalanced angle brackets
error: unresolved link to `Vec<T>>>`
- --> $DIR/malformed-generics.rs:7:6
+ --> $DIR/malformed-generics.rs:9:6
|
LL | //! [Vec<T>>>]
| ^^^^^^^^ unbalanced angle brackets
error: unresolved link to `<Vec`
- --> $DIR/malformed-generics.rs:8:6
+ --> $DIR/malformed-generics.rs:11:6
|
LL | //! [<Vec]
| ^^^^ unbalanced angle brackets
error: unresolved link to `Vec::<`
- --> $DIR/malformed-generics.rs:9:6
+ --> $DIR/malformed-generics.rs:12:6
|
LL | //! [Vec::<]
| ^^^^^^ unbalanced angle brackets
error: unresolved link to `<T>`
- --> $DIR/malformed-generics.rs:10:6
+ --> $DIR/malformed-generics.rs:13:6
|
LL | //! [<T>]
| ^^^ missing type for generic parameters
error: unresolved link to `<invalid syntax>`
- --> $DIR/malformed-generics.rs:11:6
+ --> $DIR/malformed-generics.rs:15:6
|
LL | //! [<invalid syntax>]
| ^^^^^^^^^^^^^^^^ missing type for generic parameters
error: unresolved link to `Vec:<T>:new`
- --> $DIR/malformed-generics.rs:12:6
+ --> $DIR/malformed-generics.rs:17:6
|
LL | //! [Vec:<T>:new()]
| ^^^^^^^^^^^^^ has invalid path separator
error: unresolved link to `Vec<<T>>`
- --> $DIR/malformed-generics.rs:13:6
+ --> $DIR/malformed-generics.rs:19:6
|
LL | //! [Vec<<T>>]
| ^^^^^^^^ too many angle brackets
error: unresolved link to `Vec<>`
- --> $DIR/malformed-generics.rs:14:6
+ --> $DIR/malformed-generics.rs:21:6
|
LL | //! [Vec<>]
| ^^^^^ empty angle brackets
error: unresolved link to `Vec<<>>`
- --> $DIR/malformed-generics.rs:15:6
+ --> $DIR/malformed-generics.rs:22:6
|
LL | //! [Vec<<>>]
| ^^^^^^^ too many angle brackets
error: unresolved link to `<Vec as IntoIterator>::into_iter`
- --> $DIR/malformed-generics.rs:18:6
+ --> $DIR/malformed-generics.rs:25:6
|
LL | //! [<Vec as IntoIterator>::into_iter]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ fully-qualified syntax is unsupported
@@ -91,12 +91,68 @@ LL | //! [<Vec as IntoIterator>::into_iter]
= note: see https://github.com/rust-lang/rust/issues/74563 for more information
error: unresolved link to `<Vec<T> as IntoIterator>::iter`
- --> $DIR/malformed-generics.rs:19:6
+ --> $DIR/malformed-generics.rs:27:6
|
LL | //! [<Vec<T> as IntoIterator>::iter]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ fully-qualified syntax is unsupported
|
= note: see https://github.com/rust-lang/rust/issues/74563 for more information
-error: aborting due to 15 previous errors
+warning: unclosed HTML tag `T`
+ --> $DIR/malformed-generics.rs:5:13
+ |
+LL | //! [Vec<Box<T>]
+ | ^^^
+ |
+ = note: `#[warn(rustdoc::invalid_html_tags)]` on by default
+
+warning: unclosed HTML tag `T`
+ --> $DIR/malformed-generics.rs:7:13
+ |
+LL | //! [Vec<Box<T>>>]
+ | ^^^
+
+warning: unclosed HTML tag `T`
+ --> $DIR/malformed-generics.rs:9:9
+ |
+LL | //! [Vec<T>>>]
+ | ^^^
+
+warning: unclosed HTML tag `T`
+ --> $DIR/malformed-generics.rs:13:6
+ |
+LL | //! [<T>]
+ | ^^^
+
+warning: unclosed HTML tag `invalid`
+ --> $DIR/malformed-generics.rs:15:6
+ |
+LL | //! [<invalid syntax>]
+ | ^^^^^^^^
+
+warning: unclosed HTML tag `T`
+ --> $DIR/malformed-generics.rs:17:10
+ |
+LL | //! [Vec:<T>:new()]
+ | ^^^
+
+warning: unclosed HTML tag `T`
+ --> $DIR/malformed-generics.rs:19:10
+ |
+LL | //! [Vec<<T>>]
+ | ^^^
+
+warning: unclosed HTML tag `Vec`
+ --> $DIR/malformed-generics.rs:25:6
+ |
+LL | //! [<Vec as IntoIterator>::into_iter]
+ | ^^^^
+
+warning: unclosed HTML tag `T`
+ --> $DIR/malformed-generics.rs:27:10
+ |
+LL | //! [<Vec<T> as IntoIterator>::iter]
+ | ^^^
+
+error: aborting due to 15 previous errors; 9 warnings emitted
diff --git a/src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr b/src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr
index 4828a3044..8ec894d10 100644
--- a/src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr
+++ b/src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr
@@ -4,12 +4,12 @@ error: unresolved link to `T`
LL | //! [[T]::rotate_left]
| ^ no item named `T` in scope
|
+ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
note: the lint level is defined here
--> $DIR/non-path-primitives.rs:1:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: unresolved link to `Z`
--> $DIR/non-path-primitives.rs:14:5
diff --git a/src/test/rustdoc-ui/intra-doc/private-from-crate-level.stderr b/src/test/rustdoc-ui/intra-doc/private-from-crate-level.stderr
index 6172cd2e3..4d5bd70bf 100644
--- a/src/test/rustdoc-ui/intra-doc/private-from-crate-level.stderr
+++ b/src/test/rustdoc-ui/intra-doc/private-from-crate-level.stderr
@@ -4,8 +4,8 @@ warning: public documentation for `private_from_crate_level` links to private it
LL | //! [my_module]
| ^^^^^^^^^ this item is private
|
- = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
= note: this link will resolve properly if you pass `--document-private-items`
+ = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
warning: 1 warning emitted
diff --git a/src/test/rustdoc-ui/intra-doc/private.private.stderr b/src/test/rustdoc-ui/intra-doc/private.private.stderr
index 392321f9c..6661e9021 100644
--- a/src/test/rustdoc-ui/intra-doc/private.private.stderr
+++ b/src/test/rustdoc-ui/intra-doc/private.private.stderr
@@ -4,8 +4,8 @@ warning: public documentation for `DocMe` links to private item `DontDocMe`
LL | /// docs [DontDocMe] [DontDocMe::f] [DontDocMe::x]
| ^^^^^^^^^ this item is private
|
- = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
= note: this link resolves only because you passed `--document-private-items`, but will break without
+ = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
warning: public documentation for `DocMe` links to private item `DontDocMe::f`
--> $DIR/private.rs:7:23
diff --git a/src/test/rustdoc-ui/intra-doc/private.public.stderr b/src/test/rustdoc-ui/intra-doc/private.public.stderr
index 5d1c34b91..45b51e12e 100644
--- a/src/test/rustdoc-ui/intra-doc/private.public.stderr
+++ b/src/test/rustdoc-ui/intra-doc/private.public.stderr
@@ -4,8 +4,8 @@ warning: public documentation for `DocMe` links to private item `DontDocMe`
LL | /// docs [DontDocMe] [DontDocMe::f] [DontDocMe::x]
| ^^^^^^^^^ this item is private
|
- = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
= note: this link will resolve properly if you pass `--document-private-items`
+ = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
warning: public documentation for `DocMe` links to private item `DontDocMe::f`
--> $DIR/private.rs:7:23
diff --git a/src/test/rustdoc-ui/intra-doc/span-ice-55723.stderr b/src/test/rustdoc-ui/intra-doc/span-ice-55723.stderr
index bf4ab9fdd..e8ee40ad4 100644
--- a/src/test/rustdoc-ui/intra-doc/span-ice-55723.stderr
+++ b/src/test/rustdoc-ui/intra-doc/span-ice-55723.stderr
@@ -4,12 +4,12 @@ error: unresolved link to `i`
LL | /// (arr[i])
| ^ no item named `i` in scope
|
+ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
note: the lint level is defined here
--> $DIR/span-ice-55723.rs:1:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: aborting due to previous error
diff --git a/src/test/rustdoc-ui/intra-doc/through-proc-macro.stderr b/src/test/rustdoc-ui/intra-doc/through-proc-macro.stderr
index f0a7ed178..508d0683d 100644
--- a/src/test/rustdoc-ui/intra-doc/through-proc-macro.stderr
+++ b/src/test/rustdoc-ui/intra-doc/through-proc-macro.stderr
@@ -4,12 +4,12 @@ warning: unresolved link to `Oooops`
LL | /// [Oooops]
| ^^^^^^ no item named `Oooops` in scope
|
+ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
note: the lint level is defined here
--> $DIR/through-proc-macro.rs:7:9
|
LL | #![warn(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: 1 warning emitted
diff --git a/src/test/rustdoc-ui/intra-doc/unknown-disambiguator.stderr b/src/test/rustdoc-ui/intra-doc/unknown-disambiguator.stderr
index bb8572eae..e7b4c43e7 100644
--- a/src/test/rustdoc-ui/intra-doc/unknown-disambiguator.stderr
+++ b/src/test/rustdoc-ui/intra-doc/unknown-disambiguator.stderr
@@ -4,13 +4,13 @@ error: unknown disambiguator `foo`
LL | //! Linking to [foo@banana] and [`bar@banana!()`].
| ^^^
|
+ = note: see https://doc.rust-lang.org/$CHANNEL/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
note: the lint level is defined here
--> $DIR/unknown-disambiguator.rs:2:9
|
LL | #![deny(warnings)]
| ^^^^^^^^
= note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(warnings)]`
- = note: see https://doc.rust-lang.org/$CHANNEL/rustdoc/write-documentation/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
error: unknown disambiguator `bar`
--> $DIR/unknown-disambiguator.rs:4:35
@@ -18,7 +18,7 @@ error: unknown disambiguator `bar`
LL | //! Linking to [foo@banana] and [`bar@banana!()`].
| ^^^
|
- = note: see https://doc.rust-lang.org/$CHANNEL/rustdoc/write-documentation/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
+ = note: see https://doc.rust-lang.org/$CHANNEL/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
error: unknown disambiguator `foo`
--> $DIR/unknown-disambiguator.rs:10:34
@@ -26,7 +26,7 @@ error: unknown disambiguator `foo`
LL | //! And with weird backticks: [``foo@hello``] [foo`@`hello].
| ^^^
|
- = note: see https://doc.rust-lang.org/$CHANNEL/rustdoc/write-documentation/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
+ = note: see https://doc.rust-lang.org/$CHANNEL/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
error: unknown disambiguator `foo`
--> $DIR/unknown-disambiguator.rs:10:48
@@ -34,7 +34,7 @@ error: unknown disambiguator `foo`
LL | //! And with weird backticks: [``foo@hello``] [foo`@`hello].
| ^^^
|
- = note: see https://doc.rust-lang.org/$CHANNEL/rustdoc/write-documentation/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
+ = note: see https://doc.rust-lang.org/$CHANNEL/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
error: unknown disambiguator ``
--> $DIR/unknown-disambiguator.rs:7:31
@@ -42,7 +42,7 @@ error: unknown disambiguator ``
LL | //! And to [no disambiguator](@nectarine) and [another](@apricot!()).
| ^
|
- = note: see https://doc.rust-lang.org/$CHANNEL/rustdoc/write-documentation/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
+ = note: see https://doc.rust-lang.org/$CHANNEL/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
error: unknown disambiguator ``
--> $DIR/unknown-disambiguator.rs:7:57
@@ -50,7 +50,7 @@ error: unknown disambiguator ``
LL | //! And to [no disambiguator](@nectarine) and [another](@apricot!()).
| ^
|
- = note: see https://doc.rust-lang.org/$CHANNEL/rustdoc/write-documentation/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
+ = note: see https://doc.rust-lang.org/$CHANNEL/rustdoc/linking-to-items-by-name.html#namespaces-and-disambiguators for more info about disambiguators
error: aborting due to 6 previous errors
diff --git a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr
index 5c0df1d1b..815324563 100644
--- a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr
+++ b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr
@@ -4,12 +4,12 @@ error: unresolved link to `zip`
LL | /// See [zip] crate.
| ^^^ no item named `zip` in scope
|
+ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
note: the lint level is defined here
--> $DIR/unused-extern-crate.rs:2:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: aborting due to previous error
diff --git a/src/test/rustdoc-ui/intra-doc/warning-crlf.stderr b/src/test/rustdoc-ui/intra-doc/warning-crlf.stderr
index d46df9264..c309a55f4 100644
--- a/src/test/rustdoc-ui/intra-doc/warning-crlf.stderr
+++ b/src/test/rustdoc-ui/intra-doc/warning-crlf.stderr
@@ -4,8 +4,8 @@ warning: unresolved link to `error`
LL | /// [error]
| ^^^^^ no item named `error` in scope
|
- = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
+ = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
warning: unresolved link to `error1`
--> $DIR/warning-crlf.rs:12:11
diff --git a/src/test/rustdoc-ui/invalid-doc-attr.stderr b/src/test/rustdoc-ui/invalid-doc-attr.stderr
index a4fa38179..3c66e587b 100644
--- a/src/test/rustdoc-ui/invalid-doc-attr.stderr
+++ b/src/test/rustdoc-ui/invalid-doc-attr.stderr
@@ -4,15 +4,15 @@ error: this attribute can only be applied at the crate level
LL | #[doc(test(no_crate_inject))]
| ^^^^^^^^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
+ = note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
note: the lint level is defined here
--> $DIR/invalid-doc-attr.rs:2:9
|
LL | #![deny(warnings)]
| ^^^^^^^^
= note: `#[deny(invalid_doc_attributes)]` implied by `#[deny(warnings)]`
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
- = note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
help: to apply to the crate, use an inner attribute
|
LL | #![doc(test(no_crate_inject))]
diff --git a/src/test/rustdoc-ui/invalid-html-self-closing-tag.rs b/src/test/rustdoc-ui/invalid-html-self-closing-tag.rs
new file mode 100644
index 000000000..d973a53cb
--- /dev/null
+++ b/src/test/rustdoc-ui/invalid-html-self-closing-tag.rs
@@ -0,0 +1,70 @@
+#![deny(rustdoc::invalid_html_tags)]
+
+/// <p/>
+//~^ ERROR invalid self-closing HTML tag `p`
+pub struct A;
+
+/// <p style/>
+//~^ ERROR invalid self-closing HTML tag `p`
+pub struct B;
+
+/// <p style=""/>
+//~^ ERROR invalid self-closing HTML tag `p`
+pub struct C;
+
+/// <p style="x"/>
+//~^ ERROR invalid self-closing HTML tag `p`
+pub struct D;
+
+/// <p style="x/></p>
+//~^ ERROR unclosed quoted HTML attribute
+pub struct E;
+
+/// <p style='x/></p>
+//~^ ERROR unclosed quoted HTML attribute
+pub struct F;
+
+/// <p style="x/"></p>
+pub struct G;
+
+/// <p style="x/"/>
+//~^ ERROR invalid self-closing HTML tag `p`
+pub struct H;
+
+/// <p / >
+//~^ ERROR invalid self-closing HTML tag `p`
+pub struct I;
+
+/// <br/>
+pub struct J;
+
+/// <a href=/></a>
+pub struct K;
+
+/// <a href=//></a>
+pub struct L;
+
+/// <a href="/"/>
+//~^ ERROR invalid self-closing HTML tag `a`
+pub struct M;
+
+/// <a href=x />
+//~^ ERROR invalid self-closing HTML tag `a`
+pub struct N;
+
+/// <a href= />
+//~^ ERROR invalid self-closing HTML tag `a`
+pub struct O;
+
+/// <a href=x/></a>
+pub struct P;
+
+/// <svg><rect width=1 height=1 /></svg>
+pub struct Q;
+
+/// <svg><rect width=1 height=/></svg>
+//~^ ERROR unclosed HTML tag `rect`
+pub struct R;
+
+/// <svg / q>
+pub struct S;
diff --git a/src/test/rustdoc-ui/invalid-html-self-closing-tag.stderr b/src/test/rustdoc-ui/invalid-html-self-closing-tag.stderr
new file mode 100644
index 000000000..e45edfb43
--- /dev/null
+++ b/src/test/rustdoc-ui/invalid-html-self-closing-tag.stderr
@@ -0,0 +1,80 @@
+error: invalid self-closing HTML tag `p`
+ --> $DIR/invalid-html-self-closing-tag.rs:3:5
+ |
+LL | /// <p/>
+ | ^^
+ |
+note: the lint level is defined here
+ --> $DIR/invalid-html-self-closing-tag.rs:1:9
+ |
+LL | #![deny(rustdoc::invalid_html_tags)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: invalid self-closing HTML tag `p`
+ --> $DIR/invalid-html-self-closing-tag.rs:7:5
+ |
+LL | /// <p style/>
+ | ^^
+
+error: invalid self-closing HTML tag `p`
+ --> $DIR/invalid-html-self-closing-tag.rs:11:5
+ |
+LL | /// <p style=""/>
+ | ^^
+
+error: invalid self-closing HTML tag `p`
+ --> $DIR/invalid-html-self-closing-tag.rs:15:5
+ |
+LL | /// <p style="x"/>
+ | ^^
+
+error: unclosed quoted HTML attribute on tag `p`
+ --> $DIR/invalid-html-self-closing-tag.rs:19:14
+ |
+LL | /// <p style="x/></p>
+ | ^
+
+error: unclosed quoted HTML attribute on tag `p`
+ --> $DIR/invalid-html-self-closing-tag.rs:23:14
+ |
+LL | /// <p style='x/></p>
+ | ^
+
+error: invalid self-closing HTML tag `p`
+ --> $DIR/invalid-html-self-closing-tag.rs:30:5
+ |
+LL | /// <p style="x/"/>
+ | ^^
+
+error: invalid self-closing HTML tag `p`
+ --> $DIR/invalid-html-self-closing-tag.rs:34:5
+ |
+LL | /// <p / >
+ | ^^
+
+error: invalid self-closing HTML tag `a`
+ --> $DIR/invalid-html-self-closing-tag.rs:47:5
+ |
+LL | /// <a href="/"/>
+ | ^^
+
+error: invalid self-closing HTML tag `a`
+ --> $DIR/invalid-html-self-closing-tag.rs:51:5
+ |
+LL | /// <a href=x />
+ | ^^
+
+error: invalid self-closing HTML tag `a`
+ --> $DIR/invalid-html-self-closing-tag.rs:55:5
+ |
+LL | /// <a href= />
+ | ^^
+
+error: unclosed HTML tag `rect`
+ --> $DIR/invalid-html-self-closing-tag.rs:65:10
+ |
+LL | /// <svg><rect width=1 height=/></svg>
+ | ^^^^^
+
+error: aborting due to 12 previous errors
+
diff --git a/src/test/rustdoc-ui/invalid-syntax.rs b/src/test/rustdoc-ui/invalid-syntax.rs
index b503d1093..acb2a6f08 100644
--- a/src/test/rustdoc-ui/invalid-syntax.rs
+++ b/src/test/rustdoc-ui/invalid-syntax.rs
@@ -99,3 +99,9 @@ pub fn indent_after_fenced() {}
/// ```
pub fn invalid() {}
//~^^^^ WARNING could not parse code block as Rust code
+
+/// ```
+/// fn wook_at_my_beautifuw_bwaces_plz() {);
+/// ```
+pub fn uwu() {}
+//~^^^^ WARNING could not parse code block as Rust code
diff --git a/src/test/rustdoc-ui/invalid-syntax.stderr b/src/test/rustdoc-ui/invalid-syntax.stderr
index 4c6249cc6..597d19e74 100644
--- a/src/test/rustdoc-ui/invalid-syntax.stderr
+++ b/src/test/rustdoc-ui/invalid-syntax.stderr
@@ -7,10 +7,10 @@ LL | | /// \__________pkt->size___________/ \_result->size_/ \__pkt->si
LL | | /// ```
| |_______^
|
- = note: `#[warn(rustdoc::invalid_rust_codeblocks)]` on by default
= note: error from rustc: unknown start of token: \
= note: error from rustc: unknown start of token: \
= note: error from rustc: unknown start of token: \
+ = note: `#[warn(rustdoc::invalid_rust_codeblocks)]` on by default
help: mark blocks that do not contain Rust code as text
|
LL | /// ```text
@@ -150,5 +150,20 @@ help: mark blocks that do not contain Rust code as text
LL | /// ```text
| ++++
-warning: 12 warnings emitted
+warning: could not parse code block as Rust code
+ --> $DIR/invalid-syntax.rs:103:5
+ |
+LL | /// ```
+ | _____^
+LL | | /// fn wook_at_my_beautifuw_bwaces_plz() {);
+LL | | /// ```
+ | |_______^
+ |
+ = note: error from rustc: mismatched closing delimiter: `)`
+help: mark blocks that do not contain Rust code as text
+ |
+LL | /// ```text
+ | ++++
+
+warning: 13 warnings emitted
diff --git a/src/test/rustdoc-ui/issue-102986.rs b/src/test/rustdoc-ui/issue-102986.rs
new file mode 100644
index 000000000..001784ac2
--- /dev/null
+++ b/src/test/rustdoc-ui/issue-102986.rs
@@ -0,0 +1,4 @@
+struct Struct {
+ y: (typeof("hey"),),
+ //~^ `typeof` is a reserved keyword but unimplemented
+}
diff --git a/src/test/rustdoc-ui/issue-102986.stderr b/src/test/rustdoc-ui/issue-102986.stderr
new file mode 100644
index 000000000..3a573726c
--- /dev/null
+++ b/src/test/rustdoc-ui/issue-102986.stderr
@@ -0,0 +1,14 @@
+error[E0516]: `typeof` is a reserved keyword but unimplemented
+ --> $DIR/issue-102986.rs:2:9
+ |
+LL | y: (typeof("hey"),),
+ | ^^^^^^^^^^^^^ reserved keyword
+ |
+help: consider replacing `typeof(...)` with an actual type
+ |
+LL | y: (&'static str,),
+ | ~~~~~~~~~~~~
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0516`.
diff --git a/src/test/rustdoc-ui/issue-74134.private.stderr b/src/test/rustdoc-ui/issue-74134.private.stderr
index 31d2dbe96..44c88b618 100644
--- a/src/test/rustdoc-ui/issue-74134.private.stderr
+++ b/src/test/rustdoc-ui/issue-74134.private.stderr
@@ -4,8 +4,8 @@ warning: public documentation for `public_item` links to private item `PrivateTy
LL | /// [`PrivateType`]
| ^^^^^^^^^^^ this item is private
|
- = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
= note: this link resolves only because you passed `--document-private-items`, but will break without
+ = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
warning: 1 warning emitted
diff --git a/src/test/rustdoc-ui/issue-74134.public.stderr b/src/test/rustdoc-ui/issue-74134.public.stderr
index 6a3173e3e..5b1887b83 100644
--- a/src/test/rustdoc-ui/issue-74134.public.stderr
+++ b/src/test/rustdoc-ui/issue-74134.public.stderr
@@ -4,8 +4,8 @@ warning: public documentation for `public_item` links to private item `PrivateTy
LL | /// [`PrivateType`]
| ^^^^^^^^^^^ this item is private
|
- = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
= note: this link will resolve properly if you pass `--document-private-items`
+ = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
warning: 1 warning emitted
diff --git a/src/test/rustdoc-ui/lint-group.stderr b/src/test/rustdoc-ui/lint-group.stderr
index 5336c0445..4f2c96588 100644
--- a/src/test/rustdoc-ui/lint-group.stderr
+++ b/src/test/rustdoc-ui/lint-group.stderr
@@ -35,8 +35,8 @@ error: unresolved link to `error`
LL | /// what up, let's make an [error]
| ^^^^^ no item named `error` in scope
|
- = note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(rustdoc::all)]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
+ = note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(rustdoc::all)]`
error: unclosed HTML tag `unknown`
--> $DIR/lint-group.rs:28:5
diff --git a/src/test/rustdoc-ui/macro-docs.stderr b/src/test/rustdoc-ui/macro-docs.stderr
index e3cc17311..2b136f5be 100644
--- a/src/test/rustdoc-ui/macro-docs.stderr
+++ b/src/test/rustdoc-ui/macro-docs.stderr
@@ -7,13 +7,13 @@ LL | /// A
LL | m!();
| ---- in this macro invocation
|
- = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
= note: the link appears in this line:
[`long_cat`] is really long
^^^^^^^^^^
= note: no item named `long_cat` in scope
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
+ = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
= note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: 1 warning emitted
diff --git a/src/test/rustdoc-ui/no-crate-level-doc-lint.stderr b/src/test/rustdoc-ui/no-crate-level-doc-lint.stderr
index 1a1f8085a..fb3a5e415 100644
--- a/src/test/rustdoc-ui/no-crate-level-doc-lint.stderr
+++ b/src/test/rustdoc-ui/no-crate-level-doc-lint.stderr
@@ -1,12 +1,12 @@
error: no documentation found for this crate's top-level module
|
+ = help: The following guide may be of use:
+ https://doc.rust-lang.org/$CHANNEL/rustdoc/how-to-write-documentation.html
note: the lint level is defined here
--> $DIR/no-crate-level-doc-lint.rs:3:9
|
LL | #![deny(rustdoc::missing_crate_level_docs)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: The following guide may be of use:
- https://doc.rust-lang.org/$CHANNEL/rustdoc/how-to-write-documentation.html
error: aborting due to previous error
diff --git a/src/test/rustdoc-ui/normalize-cycle.rs b/src/test/rustdoc-ui/normalize-cycle.rs
index 14ffac1e1..1ed9ac6bc 100644
--- a/src/test/rustdoc-ui/normalize-cycle.rs
+++ b/src/test/rustdoc-ui/normalize-cycle.rs
@@ -1,4 +1,5 @@
// check-pass
+// compile-flags: -Znormalize-docs
// Regression test for <https://github.com/rust-lang/rust/issues/79459>.
pub trait Query {}
diff --git a/src/test/rustdoc-ui/normalize-overflow.rs b/src/test/rustdoc-ui/normalize-overflow.rs
index 0cdcc88e3..3698fe70e 100644
--- a/src/test/rustdoc-ui/normalize-overflow.rs
+++ b/src/test/rustdoc-ui/normalize-overflow.rs
@@ -1,3 +1,5 @@
// aux-crate:overflow=overflow.rs
// check-pass
// Regression test for <https://github.com/rust-lang/rust/issues/79506>.
+
+extern crate overflow;
diff --git a/src/test/rustdoc-ui/pub-export-lint.stderr b/src/test/rustdoc-ui/pub-export-lint.stderr
index c6be9c6a9..81ef79961 100644
--- a/src/test/rustdoc-ui/pub-export-lint.stderr
+++ b/src/test/rustdoc-ui/pub-export-lint.stderr
@@ -4,12 +4,12 @@ error: unresolved link to `aloha`
LL | /// [aloha]
| ^^^^^ no item named `aloha` in scope
|
+ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
note: the lint level is defined here
--> $DIR/pub-export-lint.rs:1:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: aborting due to previous error
diff --git a/src/test/rustdoc-ui/reference-link-reports-error-once.stderr b/src/test/rustdoc-ui/reference-link-reports-error-once.stderr
index b46a51e93..2ab67090f 100644
--- a/src/test/rustdoc-ui/reference-link-reports-error-once.stderr
+++ b/src/test/rustdoc-ui/reference-link-reports-error-once.stderr
@@ -4,12 +4,12 @@ error: unresolved link to `ref`
LL | /// [a]: ref
| ^^^ no item named `ref` in scope
|
+ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
note: the lint level is defined here
--> $DIR/reference-link-reports-error-once.rs:1:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: unresolved link to `ref2`
--> $DIR/reference-link-reports-error-once.rs:15:10
diff --git a/src/test/rustdoc-ui/renamed-lint-still-applies.stderr b/src/test/rustdoc-ui/renamed-lint-still-applies.stderr
index 8e2a2cdd7..ee9b67cb9 100644
--- a/src/test/rustdoc-ui/renamed-lint-still-applies.stderr
+++ b/src/test/rustdoc-ui/renamed-lint-still-applies.stderr
@@ -18,12 +18,12 @@ error: unresolved link to `x`
LL | //! [x]
| ^ no item named `x` in scope
|
+ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
note: the lint level is defined here
--> $DIR/renamed-lint-still-applies.rs:2:9
|
LL | #![deny(broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^
- = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
error: this URL is not a hyperlink
--> $DIR/renamed-lint-still-applies.rs:9:5
@@ -31,12 +31,12 @@ error: this URL is not a hyperlink
LL | //! http://example.com
| ^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://example.com>`
|
+ = note: bare URLs are not automatically turned into clickable links
note: the lint level is defined here
--> $DIR/renamed-lint-still-applies.rs:7:9
|
LL | #![deny(rustdoc::non_autolinks)]
| ^^^^^^^^^^^^^^^^^^^^^^
- = note: bare URLs are not automatically turned into clickable links
error: aborting due to 2 previous errors; 2 warnings emitted
diff --git a/src/test/rustdoc-ui/suggestions/html-as-generics.fixed b/src/test/rustdoc-ui/suggestions/html-as-generics.fixed
index 07c8c9ff2..003542d38 100644
--- a/src/test/rustdoc-ui/suggestions/html-as-generics.fixed
+++ b/src/test/rustdoc-ui/suggestions/html-as-generics.fixed
@@ -70,3 +70,13 @@ pub struct NestedGenericsWithPunct;
//~^ ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
pub struct NestedGenericsWithPunct2;
+
+/// This [`Vec<i32>`] thing!
+//~^ERROR unclosed HTML tag `i32`
+//~|HELP try marking as source
+pub struct IntraDocLink;
+
+/// This [`Vec::<i32>`] thing!
+//~^ERROR unclosed HTML tag `i32`
+//~|HELP try marking as source
+pub struct IntraDocLinkTurbofish;
diff --git a/src/test/rustdoc-ui/suggestions/html-as-generics.rs b/src/test/rustdoc-ui/suggestions/html-as-generics.rs
index cdd652f39..4254a660b 100644
--- a/src/test/rustdoc-ui/suggestions/html-as-generics.rs
+++ b/src/test/rustdoc-ui/suggestions/html-as-generics.rs
@@ -70,3 +70,13 @@ pub struct NestedGenericsWithPunct;
//~^ ERROR unclosed HTML tag `i32`
//~|HELP try marking as source
pub struct NestedGenericsWithPunct2;
+
+/// This [Vec<i32>] thing!
+//~^ERROR unclosed HTML tag `i32`
+//~|HELP try marking as source
+pub struct IntraDocLink;
+
+/// This [Vec::<i32>] thing!
+//~^ERROR unclosed HTML tag `i32`
+//~|HELP try marking as source
+pub struct IntraDocLinkTurbofish;
diff --git a/src/test/rustdoc-ui/suggestions/html-as-generics.stderr b/src/test/rustdoc-ui/suggestions/html-as-generics.stderr
index 211dd4210..481278bda 100644
--- a/src/test/rustdoc-ui/suggestions/html-as-generics.stderr
+++ b/src/test/rustdoc-ui/suggestions/html-as-generics.stderr
@@ -157,5 +157,27 @@ help: try marking as source code
LL | /// Generics with punct `Vec<Vec<i32>>`!
| + +
-error: aborting due to 14 previous errors
+error: unclosed HTML tag `i32`
+ --> $DIR/html-as-generics.rs:74:14
+ |
+LL | /// This [Vec<i32>] thing!
+ | ^^^^^
+ |
+help: try marking as source code
+ |
+LL | /// This [`Vec<i32>`] thing!
+ | + +
+
+error: unclosed HTML tag `i32`
+ --> $DIR/html-as-generics.rs:79:16
+ |
+LL | /// This [Vec::<i32>] thing!
+ | ^^^^^
+ |
+help: try marking as source code
+ |
+LL | /// This [`Vec::<i32>`] thing!
+ | + +
+
+error: aborting due to 16 previous errors
diff --git a/src/test/rustdoc-ui/z-help.stdout b/src/test/rustdoc-ui/z-help.stdout
index 749abe364..46f11d2e5 100644
--- a/src/test/rustdoc-ui/z-help.stdout
+++ b/src/test/rustdoc-ui/z-help.stdout
@@ -1,8 +1,8 @@
-Z allow-features=val -- only allow the listed language features to be enabled in code (space separated)
-Z always-encode-mir=val -- encode MIR of all functions into the crate metadata (default: no)
- -Z assume-incomplete-release=val -- make cfg(version) treat the current version as incomplete (default: no)
-Z asm-comments=val -- generate comments into the assembly (may change behavior) (default: no)
-Z assert-incr-state=val -- assert that the incremental cache is in given state: either `loaded` or `not-loaded`.
+ -Z assume-incomplete-release=val -- make cfg(version) treat the current version as incomplete (default: no)
-Z binary-dep-depinfo=val -- include artifacts (sysroot, crate dependencies) used during compilation in dep-info (default: no)
-Z box-noalias=val -- emit noalias metadata for box (default: yes)
-Z branch-protection=val -- set options for branch target identification and pointer authentication on AArch64
@@ -17,6 +17,7 @@
-Z deduplicate-diagnostics=val -- deduplicate identical diagnostics (default: yes)
-Z dep-info-omit-d-target=val -- in dep-info output, omit targets for tracking dependencies of the dep-info files themselves (default: no)
-Z dep-tasks=val -- print tasks that execute and the color their dep node gets (requires debug build) (default: no)
+ -Z diagnostic-width=val -- set the current output width for diagnostic truncation
-Z dlltool=val -- import library generation tool (windows-gnu only)
-Z dont-buffer-diagnostics=val -- emit diagnostics rather than buffering (breaks NLL error downgrading, sorting) (default: no)
-Z drop-tracking=val -- enables drop tracking in generators (default: no)
@@ -35,6 +36,7 @@
-Z dump-mir-graphviz=val -- in addition to `.mir` files, create graphviz `.dot` files (and with `-Z instrument-coverage`, also create a `.dot` file for the MIR-derived coverage graph) (default: no)
-Z dump-mir-spanview=val -- in addition to `.mir` files, create `.html` files to view spans for all `statement`s (including terminators), only `terminator` spans, or computed `block` spans (one span encompassing a block's terminator and all statements). If `-Z instrument-coverage` is also enabled, create an additional `.html` file showing the computed coverage spans.
-Z dwarf-version=val -- version of DWARF debug information to emit (default: 2 or 4, depending on platform)
+ -Z dylib-lto=val -- enables LTO for dylib crate type
-Z emit-stack-sizes=val -- emit a section containing stack size metadata (default: no)
-Z emit-thin-lto=val -- emit the bc module with thin LTO info (default: yes)
-Z export-executable-symbols=val -- export symbols from executables, as if they were dynamic libraries
@@ -54,11 +56,11 @@
-Z incremental-info=val -- print high-level information about incremental reuse (or the lack thereof) (default: no)
-Z incremental-relative-spans=val -- hash spans relative to their parent item for incr. comp. (default: no)
-Z incremental-verify-ich=val -- verify incr. comp. hashes of green query instances (default: no)
+ -Z inline-in-all-cgus=val -- control whether `#[inline]` functions are in all CGUs
-Z inline-llvm=val -- enable LLVM inlining (default: yes)
-Z inline-mir=val -- enable MIR inlining (default: no)
- -Z inline-mir-threshold=val -- a default MIR inlining threshold (default: 50)
-Z inline-mir-hint-threshold=val -- inlining threshold for functions with inline hint (default: 100)
- -Z inline-in-all-cgus=val -- control whether `#[inline]` functions are in all CGUs
+ -Z inline-mir-threshold=val -- a default MIR inlining threshold (default: 50)
-Z input-stats=val -- gather statistics about the input (default: no)
-Z instrument-coverage=val -- instrument the generated code to support LLVM source-based code coverage reports (note, the compiler build config must include `profiler = true`); implies `-C symbol-mangling-version=v0`. Optional values are:
`=all` (implicit value)
@@ -67,6 +69,7 @@
`=off` (default)
-Z instrument-mcount=val -- insert function instrument code for mcount-based tracing (default: no)
-Z keep-hygiene-data=val -- keep hygiene data after analysis (default: no)
+ -Z layout-seed=val -- seed layout randomization
-Z link-native-libraries=val -- link native libraries in the linker invocation (default: yes)
-Z link-only=val -- link the `.rlink` file generated by `-Z no-link` (default: no)
-Z llvm-plugins=val -- a list LLVM plugins to enable (space separated)
@@ -78,11 +81,10 @@
-Z meta-stats=val -- gather metadata statistics (default: no)
-Z mir-emit-retag=val -- emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 (default: no)
-Z mir-enable-passes=val -- use like `-Zmir-enable-passes=+DestProp,-InstCombine`. Forces the specified passes to be enabled, overriding all other checks. Passes that are not specified are enabled or disabled by other flags as usual.
- -Z mir-pretty-relative-line-numbers=val -- use line numbers relative to the function in mir pretty printing
-Z mir-opt-level=val -- MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)
+ -Z mir-pretty-relative-line-numbers=val -- use line numbers relative to the function in mir pretty printing
-Z move-size-limit=val -- the size at which the `large_assignments` lint starts to be emitted
-Z mutable-noalias=val -- emit noalias metadata for mutable references (default: yes)
- -Z new-llvm-pass-manager=val -- use new LLVM pass manager (default: no)
-Z nll-facts=val -- dump facts from NLL analysis into side files (default: no)
-Z nll-facts-dir=val -- the directory the NLL facts are dumped into (default: `nll-facts`)
-Z no-analysis=val -- parse and expand the source, but run no analysis
@@ -92,12 +94,11 @@
-Z no-leak-check=val -- disable the 'leak check' for subtyping; unsound, but useful for tests
-Z no-link=val -- compile without linking
-Z no-parallel-llvm=val -- run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)
- -Z no-unique-section-names=val -- do not use unique names for text and data sections when -Z function-sections is used
-Z no-profiler-runtime=val -- prevent automatic injection of the profiler_builtins crate
+ -Z no-unique-section-names=val -- do not use unique names for text and data sections when -Z function-sections is used
-Z normalize-docs=val -- normalize associated items in rustdoc when generating documentation
-Z oom=val -- panic strategy for out-of-memory handling
-Z osx-rpath-install-name=val -- pass `-install_name @rpath/...` to the macOS linker (default: no)
- -Z diagnostic-width=val -- set the current output width for diagnostic truncation
-Z packed-bundled-libs=val -- change rlib format to store native libraries as archives
-Z panic-abort-tests=val -- support compiling tests with panic=abort (default: no)
-Z panic-in-drop=val -- panic strategy for panics in drops
@@ -121,15 +122,13 @@
-Z profile=val -- insert profiling code (default: no)
-Z profile-closures=val -- profile size of closures
-Z profile-emit=val -- file path to emit profiling data at runtime when using 'profile' (default based on relative source path)
- -Z profiler-runtime=val -- name of the profiler runtime crate to automatically inject (default: `profiler_builtins`)
-Z profile-sample-use=val -- use the given `.prof` file for sampled profile-guided optimization (also known as AutoFDO)
+ -Z profiler-runtime=val -- name of the profiler runtime crate to automatically inject (default: `profiler_builtins`)
-Z query-dep-graph=val -- enable queries of the dependency graph for regression testing (default: no)
-Z randomize-layout=val -- randomize the layout of types (default: no)
- -Z layout-seed=val -- seed layout randomization
-Z relax-elf-relocations=val -- whether ELF relocations can be relaxed
-Z relro-level=val -- choose which RELRO level to use
-Z remap-cwd-prefix=val -- remap paths under the current working directory to this path prefix
- -Z simulate-remapped-rust-src-base=val -- simulate the effect of remap-debuginfo = true at bootstrapping by remapping path to rust's source base directory. only meant for testing purposes
-Z report-delayed-bugs=val -- immediately print bugs registered with `delay_span_bug` (default: no)
-Z sanitizer=val -- use a sanitizer
-Z sanitizer-memory-track-origins=val -- enable origins tracking in MemorySanitizer
@@ -137,22 +136,20 @@
-Z saturating-float-casts=val -- make float->int casts UB-free: numbers outside the integer type's range are clipped to the max/min integer respectively, and NaN is mapped to 0 (default: yes)
-Z save-analysis=val -- write syntax and type analysis (in JSON format) information, in addition to normal output (default: no)
-Z self-profile=val -- run the self profiler and output the raw event data
- -Z self-profile-events=val -- specify the events recorded by the self profiler;
- for example: `-Z self-profile-events=default,query-keys`
- all options: none, all, default, generic-activity, query-provider, query-cache-hit
- query-blocked, incr-cache-load, incr-result-hashing, query-keys, function-args, args, llvm, artifact-sizes
-Z self-profile-counter=val -- counter used by the self profiler (default: `wall-time`), one of:
`wall-time` (monotonic clock, i.e. `std::time::Instant`)
`instructions:u` (retired instructions, userspace-only)
`instructions-minus-irqs:u` (subtracting hardware interrupt counts for extra accuracy)
+ -Z self-profile-events=val -- specify the events recorded by the self profiler;
+ for example: `-Z self-profile-events=default,query-keys`
+ all options: none, all, default, generic-activity, query-provider, query-cache-hit
+ query-blocked, incr-cache-load, incr-result-hashing, query-keys, function-args, args, llvm, artifact-sizes
-Z share-generics=val -- make the current crate share its generic instantiations
-Z show-span=val -- show spans for compiler debugging (expr|pat|ty)
+ -Z simulate-remapped-rust-src-base=val -- simulate the effect of remap-debuginfo = true at bootstrapping by remapping path to rust's source base directory. only meant for testing purposes
-Z span-debug=val -- forward proc_macro::Span's `Debug` impl to `Span`
-Z span-free-formats=val -- exclude spans when debug-printing compiler state (default: no)
- -Z src-hash-algorithm=val -- hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)
- -Z stack-protector=val -- control stack smash protection strategy (`rustc --print stack-protector-strategies` for details)
- -Z strict-init-checks=val -- control if mem::uninitialized and mem::zeroed panic on more UB
- -Z strip=val -- tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)
+ -Z split-dwarf-inlining=val -- provide minimal debug info in the object/executable to facilitate online symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF
-Z split-dwarf-kind=val -- split dwarf variant (only if -Csplit-debuginfo is enabled and on relevant platform)
(default: `split`)
@@ -160,26 +157,28 @@
file which is ignored by the linker
`single`: sections which do not require relocation are written into object file but ignored
by the linker
- -Z split-dwarf-inlining=val -- provide minimal debug info in the object/executable to facilitate online symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF
+ -Z src-hash-algorithm=val -- hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)
+ -Z stack-protector=val -- control stack smash protection strategy (`rustc --print stack-protector-strategies` for details)
+ -Z strict-init-checks=val -- control if mem::uninitialized and mem::zeroed panic on more UB
+ -Z strip=val -- tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)
-Z symbol-mangling-version=val -- which mangling version to use for symbol names ('legacy' (default) or 'v0')
-Z teach=val -- show extended diagnostic help (default: no)
-Z temps-dir=val -- the directory the intermediate files are written to
- -Z translate-lang=val -- language identifier for diagnostic output
- -Z translate-additional-ftl=val -- additional fluent translation to preferentially use (for testing translation)
- -Z translate-directionality-markers=val -- emit directionality isolation markers in translated diagnostics
- -Z tune-cpu=val -- select processor to schedule for (`rustc --print target-cpus` for details)
-Z thinlto=val -- enable ThinLTO when possible
-Z thir-unsafeck=val -- use the THIR unsafety checker (default: no)
-Z threads=val -- use a thread pool with N threads
- -Z time=val -- measure time of rustc processes (default: no)
-Z time-llvm-passes=val -- measure time of each LLVM pass (default: no)
-Z time-passes=val -- measure time of each rustc pass (default: no)
-Z tls-model=val -- choose the TLS model to use (`rustc --print tls-models` for details)
-Z trace-macros=val -- for every macro invocation, print its name and arguments (default: no)
+ -Z translate-additional-ftl=val -- additional fluent translation to preferentially use (for testing translation)
+ -Z translate-directionality-markers=val -- emit directionality isolation markers in translated diagnostics
+ -Z translate-lang=val -- language identifier for diagnostic output
-Z translate-remapped-path-to-local-path=val -- translate remapped paths into local paths when possible (default: yes)
-Z trap-unreachable=val -- generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)
-Z treat-err-as-bug=val -- treat error number `val` that occurs as bug
-Z trim-diagnostic-paths=val -- in diagnostics, use heuristics to shorten paths referring to items
+ -Z tune-cpu=val -- select processor to schedule for (`rustc --print target-cpus` for details)
-Z ui-testing=val -- emit compiler diagnostics in a form suitable for UI testing (default: no)
-Z uninit-const-chunk-threshold=val -- allow generating const initializers with mixed init/uninit chunks, and set the maximum number of chunks for which this is allowed (default: 16)
-Z unleash-the-miri-inside-of-you=val -- take the brakes off const evaluation. NOTE: this is unsound (default: no)
diff --git a/src/test/rustdoc/anchors.no_const_anchor.html b/src/test/rustdoc/anchors.no_const_anchor.html
index 4da1ffead..75e67330a 100644
--- a/src/test/rustdoc/anchors.no_const_anchor.html
+++ b/src/test/rustdoc/anchors.no_const_anchor.html
@@ -1 +1 @@
-<div id="associatedconstant.YOLO" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#16">source</a><h4 class="code-header">const <a href="#associatedconstant.YOLO" class="constant">YOLO</a>: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></div> \ No newline at end of file
+<section id="associatedconstant.YOLO" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#16">source</a><h4 class="code-header">const <a href="#associatedconstant.YOLO" class="constant">YOLO</a>: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section> \ No newline at end of file
diff --git a/src/test/rustdoc/anchors.no_trait_method_anchor.html b/src/test/rustdoc/anchors.no_trait_method_anchor.html
index 6b78c7c81..d7bd525ff 100644
--- a/src/test/rustdoc/anchors.no_trait_method_anchor.html
+++ b/src/test/rustdoc/anchors.no_trait_method_anchor.html
@@ -1 +1 @@
-<div id="method.bar" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#23">source</a><h4 class="code-header">fn <a href="#method.bar" class="fnname">bar</a>()</h4></div> \ No newline at end of file
+<section id="method.bar" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#23">source</a><h4 class="code-header">fn <a href="#method.bar" class="fnname">bar</a>()</h4></section> \ No newline at end of file
diff --git a/src/test/rustdoc/anchors.no_tymethod_anchor.html b/src/test/rustdoc/anchors.no_tymethod_anchor.html
index c08f4427c..e668e5e4d 100644
--- a/src/test/rustdoc/anchors.no_tymethod_anchor.html
+++ b/src/test/rustdoc/anchors.no_tymethod_anchor.html
@@ -1 +1 @@
-<div id="tymethod.foo" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#20">source</a><h4 class="code-header">fn <a href="#tymethod.foo" class="fnname">foo</a>()</h4></div> \ No newline at end of file
+<section id="tymethod.foo" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#20">source</a><h4 class="code-header">fn <a href="#tymethod.foo" class="fnname">foo</a>()</h4></section> \ No newline at end of file
diff --git a/src/test/rustdoc/anchors.no_type_anchor.html b/src/test/rustdoc/anchors.no_type_anchor.html
index ba8e65443..2c66d5aa3 100644
--- a/src/test/rustdoc/anchors.no_type_anchor.html
+++ b/src/test/rustdoc/anchors.no_type_anchor.html
@@ -1 +1 @@
-<div id="associatedtype.T" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#13">source</a><h4 class="code-header">type <a href="#associatedtype.T" class="associatedtype">T</a></h4></div> \ No newline at end of file
+<section id="associatedtype.T" class="method has-srclink"><a class="srclink rightside" href="../src/foo/anchors.rs.html#13">source</a><h4 class="code-header">type <a href="#associatedtype.T" class="associatedtype">T</a></h4></section> \ No newline at end of file
diff --git a/src/test/rustdoc/anonymous-lifetime.rs b/src/test/rustdoc/anonymous-lifetime.rs
index f5a7d2258..390ed5a1f 100644
--- a/src/test/rustdoc/anonymous-lifetime.rs
+++ b/src/test/rustdoc/anonymous-lifetime.rs
@@ -12,7 +12,7 @@ pub trait Stream {
}
// @has 'foo/trait.Stream.html'
-// @has - '//*[@class="code-header in-band"]' 'impl<S: ?Sized + Stream + Unpin> Stream for &mut S'
+// @has - '//*[@class="code-header"]' 'impl<S: ?Sized + Stream + Unpin> Stream for &mut S'
impl<S: ?Sized + Stream + Unpin> Stream for &mut S {
type Item = S::Item;
diff --git a/src/test/rustdoc/array-links.link_box_generic.html b/src/test/rustdoc/array-links.link_box_generic.html
new file mode 100644
index 000000000..3481bb6a0
--- /dev/null
+++ b/src/test/rustdoc/array-links.link_box_generic.html
@@ -0,0 +1 @@
+<code>pub fn delta&lt;T&gt;() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;<a class="primitive" href="{{channel}}/core/primitive.array.html">[T; 1]</a>&gt;</code> \ No newline at end of file
diff --git a/src/test/rustdoc/array-links.link_box_u32.html b/src/test/rustdoc/array-links.link_box_u32.html
new file mode 100644
index 000000000..e864ae55c
--- /dev/null
+++ b/src/test/rustdoc/array-links.link_box_u32.html
@@ -0,0 +1 @@
+<code>pub fn gamma() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;[<a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a>; <a class="primitive" href="{{channel}}/core/primitive.array.html">1</a>]&gt;</code> \ No newline at end of file
diff --git a/src/test/rustdoc/array-links.link_slice_generic.html b/src/test/rustdoc/array-links.link_slice_generic.html
new file mode 100644
index 000000000..f1ca2f59b
--- /dev/null
+++ b/src/test/rustdoc/array-links.link_slice_generic.html
@@ -0,0 +1 @@
+<code>pub fn beta&lt;T&gt;() -&gt; &amp;'static <a class="primitive" href="{{channel}}/core/primitive.array.html">[T; 1]</a></code> \ No newline at end of file
diff --git a/src/test/rustdoc/array-links.link_slice_u32.html b/src/test/rustdoc/array-links.link_slice_u32.html
new file mode 100644
index 000000000..c3943e8d3
--- /dev/null
+++ b/src/test/rustdoc/array-links.link_slice_u32.html
@@ -0,0 +1 @@
+<code>pub fn alpha() -&gt; &amp;'static [<a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a>; <a class="primitive" href="{{channel}}/core/primitive.array.html">1</a>]</code> \ No newline at end of file
diff --git a/src/test/rustdoc/array-links.rs b/src/test/rustdoc/array-links.rs
new file mode 100644
index 000000000..07f92ac51
--- /dev/null
+++ b/src/test/rustdoc/array-links.rs
@@ -0,0 +1,28 @@
+#![crate_name = "foo"]
+#![no_std]
+
+pub struct MyBox<T: ?Sized>(*const T);
+
+// @has 'foo/fn.alpha.html'
+// @snapshot link_slice_u32 - '//pre[@class="rust fn"]/code'
+pub fn alpha() -> &'static [u32; 1] {
+ loop {}
+}
+
+// @has 'foo/fn.beta.html'
+// @snapshot link_slice_generic - '//pre[@class="rust fn"]/code'
+pub fn beta<T>() -> &'static [T; 1] {
+ loop {}
+}
+
+// @has 'foo/fn.gamma.html'
+// @snapshot link_box_u32 - '//pre[@class="rust fn"]/code'
+pub fn gamma() -> MyBox<[u32; 1]> {
+ loop {}
+}
+
+// @has 'foo/fn.delta.html'
+// @snapshot link_box_generic - '//pre[@class="rust fn"]/code'
+pub fn delta<T>() -> MyBox<[T; 1]> {
+ loop {}
+}
diff --git a/src/test/rustdoc/assoc-consts.rs b/src/test/rustdoc/assoc-consts.rs
index 97b7739b4..a3e10ee55 100644
--- a/src/test/rustdoc/assoc-consts.rs
+++ b/src/test/rustdoc/assoc-consts.rs
@@ -13,7 +13,7 @@ pub trait Foo {
pub struct Bar;
impl Foo for Bar {
- // @has assoc_consts/struct.Bar.html '//h3[@class="code-header in-band"]' 'impl Foo for Bar'
+ // @has assoc_consts/struct.Bar.html '//h3[@class="code-header"]' 'impl Foo for Bar'
// @has - '//*[@id="associatedconstant.FOO"]' 'const FOO: usize'
const FOO: usize = 12;
// @has - '//*[@id="associatedconstant.FOO_NO_DEFAULT"]' 'const FOO_NO_DEFAULT: bool'
@@ -81,7 +81,7 @@ pub trait Qux {
const QUX_DEFAULT2: u32 = 3;
}
-// @has assoc_consts/struct.Bar.html '//h3[@class="code-header in-band"]' 'impl Qux for Bar'
+// @has assoc_consts/struct.Bar.html '//h3[@class="code-header"]' 'impl Qux for Bar'
impl Qux for Bar {
// @has - '//*[@id="associatedconstant.QUX0"]' 'const QUX0: u8'
// @has - '//*[@class="docblock"]' "Docs for QUX0 in trait."
diff --git a/src/test/rustdoc/associated-consts.rs b/src/test/rustdoc/associated-consts.rs
index 9319a073b..adb155bb5 100644
--- a/src/test/rustdoc/associated-consts.rs
+++ b/src/test/rustdoc/associated-consts.rs
@@ -9,7 +9,7 @@ pub trait Trait {
pub struct Bar;
// @has 'foo/struct.Bar.html'
-// @!has - '//h3[@class="sidebar-title"]' 'Associated Constants'
+// @!has - '//div[@class="sidebar-elems"]//h3' 'Associated Constants'
// @!has - '//div[@class="sidebar-elems"]//a' 'FOO'
impl Trait for Bar {
const FOO: u32 = 1;
@@ -22,7 +22,7 @@ pub enum Foo {
}
// @has 'foo/enum.Foo.html'
-// @!has - '//h3[@class="sidebar-title"]' 'Associated Constants'
+// @!has - '//div[@class="sidebar-elems"]//h3' 'Associated Constants'
// @!has - '//div[@class="sidebar-elems"]//a' 'FOO'
impl Trait for Foo {
const FOO: u32 = 1;
@@ -33,7 +33,7 @@ impl Trait for Foo {
pub struct Baz;
// @has 'foo/struct.Baz.html'
-// @has - '//h3[@class="sidebar-title"]' 'Associated Constants'
+// @has - '//div[@class="sidebar-elems"]//h3' 'Associated Constants'
// @has - '//div[@class="sidebar-elems"]//a' 'FOO'
impl Baz {
pub const FOO: u32 = 42;
@@ -44,7 +44,7 @@ pub enum Quux {
}
// @has 'foo/enum.Quux.html'
-// @has - '//h3[@class="sidebar-title"]' 'Associated Constants'
+// @has - '//div[@class="sidebar-elems"]//h3' 'Associated Constants'
// @has - '//div[@class="sidebar-elems"]//a' 'FOO'
impl Quux {
pub const FOO: u32 = 42;
diff --git a/src/test/rustdoc/async-trait.rs b/src/test/rustdoc/async-trait.rs
new file mode 100644
index 000000000..a473e4674
--- /dev/null
+++ b/src/test/rustdoc/async-trait.rs
@@ -0,0 +1,16 @@
+// aux-build:async-trait-dep.rs
+// edition:2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+extern crate async_trait_dep;
+
+pub struct Oink {}
+
+// @has 'async_trait/struct.Oink.html' '//h4[@class="code-header"]' "async fn woof()"
+impl async_trait_dep::Meow for Oink {
+ async fn woof() {
+ todo!()
+ }
+}
diff --git a/src/test/rustdoc/attribute-rendering.rs b/src/test/rustdoc/attribute-rendering.rs
index 677787184..36e10923c 100644
--- a/src/test/rustdoc/attribute-rendering.rs
+++ b/src/test/rustdoc/attribute-rendering.rs
@@ -1,7 +1,7 @@
#![crate_name = "foo"]
// @has 'foo/fn.f.html'
-// @has - //*[@'class="docblock item-decl"]' '#[export_name = "f"] pub fn f()'
+// @has - //*[@'class="item-decl"]' '#[export_name = "f"] pub fn f()'
#[export_name = "\
f"]
pub fn f() {}
diff --git a/src/test/rustdoc/attributes.rs b/src/test/rustdoc/attributes.rs
index 1c7f4b724..a36dadced 100644
--- a/src/test/rustdoc/attributes.rs
+++ b/src/test/rustdoc/attributes.rs
@@ -8,6 +8,6 @@ pub extern "C" fn f() {}
#[export_name = "bar"]
pub extern "C" fn g() {}
-// @has foo/struct.Repr.html '//*[@class="docblock item-decl"]' '#[repr(C, align(8))]'
+// @has foo/struct.Repr.html '//*[@class="item-decl"]' '#[repr(C, align(8))]'
#[repr(C, align(8))]
pub struct Repr;
diff --git a/src/test/rustdoc/auxiliary/async-trait-dep.rs b/src/test/rustdoc/auxiliary/async-trait-dep.rs
new file mode 100644
index 000000000..10a55dd02
--- /dev/null
+++ b/src/test/rustdoc/auxiliary/async-trait-dep.rs
@@ -0,0 +1,9 @@
+// edition:2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+pub trait Meow {
+ /// Who's a good dog?
+ async fn woof();
+}
diff --git a/src/test/rustdoc/auxiliary/reexport-doc-aux.rs b/src/test/rustdoc/auxiliary/reexport-doc-aux.rs
new file mode 100644
index 000000000..3400717eb
--- /dev/null
+++ b/src/test/rustdoc/auxiliary/reexport-doc-aux.rs
@@ -0,0 +1,5 @@
+pub struct Foo;
+
+impl Foo {
+ pub fn foo() {}
+}
diff --git a/src/test/rustdoc/blanket-reexport-item.rs b/src/test/rustdoc/blanket-reexport-item.rs
index 676d656da..437f0001f 100644
--- a/src/test/rustdoc/blanket-reexport-item.rs
+++ b/src/test/rustdoc/blanket-reexport-item.rs
@@ -1,6 +1,6 @@
#![crate_name = "foo"]
-// @has foo/struct.S.html '//*[@id="impl-Into%3CU%3E-for-S"]//h3[@class="code-header in-band"]' 'impl<T, U> Into<U> for T'
+// @has foo/struct.S.html '//*[@id="impl-Into%3CU%3E-for-S"]//h3[@class="code-header"]' 'impl<T, U> Into<U> for T'
pub struct S2 {}
mod m {
pub struct S {}
diff --git a/src/test/rustdoc/const-generics/add-impl.rs b/src/test/rustdoc/const-generics/add-impl.rs
index 591139523..6cbae9abe 100644
--- a/src/test/rustdoc/const-generics/add-impl.rs
+++ b/src/test/rustdoc/const-generics/add-impl.rs
@@ -7,7 +7,7 @@ pub struct Simd<T, const WIDTH: usize> {
inner: T,
}
-// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//h3[@class="code-header in-band"]' 'impl Add<Simd<u8, 16>> for Simd<u8, 16>'
+// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//h3[@class="code-header"]' 'impl Add<Simd<u8, 16>> for Simd<u8, 16>'
impl Add for Simd<u8, 16> {
type Output = Self;
diff --git a/src/test/rustdoc/const-generics/const-generics-docs.rs b/src/test/rustdoc/const-generics/const-generics-docs.rs
index 87d2f29e2..5bf76e3c4 100644
--- a/src/test/rustdoc/const-generics/const-generics-docs.rs
+++ b/src/test/rustdoc/const-generics/const-generics-docs.rs
@@ -19,10 +19,10 @@ pub use extern_crate::WTrait;
// @has foo/trait.Trait.html '//pre[@class="rust trait"]' \
// 'pub trait Trait<const N: usize>'
-// @has - '//*[@id="impl-Trait%3C1%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<1> for u8'
-// @has - '//*[@id="impl-Trait%3C2%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<2> for u8'
-// @has - '//*[@id="impl-Trait%3C{1%20+%202}%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<{1 + 2}> for u8'
-// @has - '//*[@id="impl-Trait%3CN%3E-for-%5Bu8%3B%20N%5D"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="impl-Trait%3C1%3E-for-u8"]//h3[@class="code-header"]' 'impl Trait<1> for u8'
+// @has - '//*[@id="impl-Trait%3C2%3E-for-u8"]//h3[@class="code-header"]' 'impl Trait<2> for u8'
+// @has - '//*[@id="impl-Trait%3C{1%20+%202}%3E-for-u8"]//h3[@class="code-header"]' 'impl Trait<{1 + 2}> for u8'
+// @has - '//*[@id="impl-Trait%3CN%3E-for-%5Bu8%3B%20N%5D"]//h3[@class="code-header"]' \
// 'impl<const N: usize> Trait<N> for [u8; N]'
pub trait Trait<const N: usize> {}
impl Trait<1> for u8 {}
@@ -36,7 +36,7 @@ pub struct Foo<const N: usize> where u8: Trait<N>;
// @has foo/struct.Bar.html '//pre[@class="rust struct"]' 'pub struct Bar<T, const N: usize>(_)'
pub struct Bar<T, const N: usize>([T; N]);
-// @has foo/struct.Foo.html '//*[@id="impl-Foo%3CM%3E"]/h3[@class="code-header in-band"]' 'impl<const M: usize> Foo<M>where u8: Trait<M>'
+// @has foo/struct.Foo.html '//*[@id="impl-Foo%3CM%3E"]/h3[@class="code-header"]' 'impl<const M: usize> Foo<M>where u8: Trait<M>'
impl<const M: usize> Foo<M> where u8: Trait<M> {
// @has - '//*[@id="associatedconstant.FOO_ASSOC"]' 'pub const FOO_ASSOC: usize'
pub const FOO_ASSOC: usize = M + 13;
@@ -47,7 +47,7 @@ impl<const M: usize> Foo<M> where u8: Trait<M> {
}
}
-// @has foo/struct.Bar.html '//*[@id="impl-Bar%3Cu8%2C%20M%3E"]/h3[@class="code-header in-band"]' 'impl<const M: usize> Bar<u8, M>'
+// @has foo/struct.Bar.html '//*[@id="impl-Bar%3Cu8%2C%20M%3E"]/h3[@class="code-header"]' 'impl<const M: usize> Bar<u8, M>'
impl<const M: usize> Bar<u8, M> {
// @has - '//*[@id="method.hey"]' \
// 'pub fn hey<const N: usize>(&self) -> Foo<N>where u8: Trait<N>'
diff --git a/src/test/rustdoc/const-generics/const-impl.rs b/src/test/rustdoc/const-generics/const-impl.rs
index f1181d54a..75ee84279 100644
--- a/src/test/rustdoc/const-generics/const-impl.rs
+++ b/src/test/rustdoc/const-generics/const-impl.rs
@@ -9,20 +9,20 @@ pub enum Order {
}
// @has foo/struct.VSet.html '//pre[@class="rust struct"]' 'pub struct VSet<T, const ORDER: Order>'
-// @has foo/struct.VSet.html '//*[@id="impl-Send-for-VSet%3CT%2C%20ORDER%3E"]/h3[@class="code-header in-band"]' 'impl<T, const ORDER: Order> Send for VSet<T, ORDER>'
-// @has foo/struct.VSet.html '//*[@id="impl-Sync-for-VSet%3CT%2C%20ORDER%3E"]/h3[@class="code-header in-band"]' 'impl<T, const ORDER: Order> Sync for VSet<T, ORDER>'
+// @has foo/struct.VSet.html '//*[@id="impl-Send-for-VSet%3CT%2C%20ORDER%3E"]/h3[@class="code-header"]' 'impl<T, const ORDER: Order> Send for VSet<T, ORDER>'
+// @has foo/struct.VSet.html '//*[@id="impl-Sync-for-VSet%3CT%2C%20ORDER%3E"]/h3[@class="code-header"]' 'impl<T, const ORDER: Order> Sync for VSet<T, ORDER>'
pub struct VSet<T, const ORDER: Order> {
inner: Vec<T>,
}
-// @has foo/struct.VSet.html '//*[@id="impl-VSet%3CT%2C%20{%20Order%3A%3ASorted%20}%3E"]/h3[@class="code-header in-band"]' 'impl<T> VSet<T, { Order::Sorted }>'
+// @has foo/struct.VSet.html '//*[@id="impl-VSet%3CT%2C%20{%20Order%3A%3ASorted%20}%3E"]/h3[@class="code-header"]' 'impl<T> VSet<T, { Order::Sorted }>'
impl<T> VSet<T, { Order::Sorted }> {
pub fn new() -> Self {
Self { inner: Vec::new() }
}
}
-// @has foo/struct.VSet.html '//*[@id="impl-VSet%3CT%2C%20{%20Order%3A%3AUnsorted%20}%3E"]/h3[@class="code-header in-band"]' 'impl<T> VSet<T, { Order::Unsorted }>'
+// @has foo/struct.VSet.html '//*[@id="impl-VSet%3CT%2C%20{%20Order%3A%3AUnsorted%20}%3E"]/h3[@class="code-header"]' 'impl<T> VSet<T, { Order::Unsorted }>'
impl<T> VSet<T, { Order::Unsorted }> {
pub fn new() -> Self {
Self { inner: Vec::new() }
@@ -31,7 +31,7 @@ impl<T> VSet<T, { Order::Unsorted }> {
pub struct Escape<const S: &'static str>;
-// @has foo/struct.Escape.html '//*[@id="impl-Escape%3Cr#%22%3Cscript%3Ealert(%22Escape%22)%3B%3C/script%3E%22#%3E"]/h3[@class="code-header in-band"]' 'impl Escape<r#"<script>alert("Escape");</script>"#>'
+// @has foo/struct.Escape.html '//*[@id="impl-Escape%3Cr#%22%3Cscript%3Ealert(%22Escape%22)%3B%3C/script%3E%22#%3E"]/h3[@class="code-header"]' 'impl Escape<r#"<script>alert("Escape");</script>"#>'
impl Escape<r#"<script>alert("Escape");</script>"#> {
pub fn f() {}
}
diff --git a/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs b/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs
index 4eac8e31e..310e89a35 100644
--- a/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs
+++ b/src/test/rustdoc/const-generics/lazy_normalization_consts/const-equate-pred.rs
@@ -12,7 +12,7 @@ pub struct Hasher<T> {
unsafe impl<T: Default> Send for Hasher<T> {}
// @has foo/struct.Foo.html
-// @has - '//h3[@class="code-header in-band"]' 'impl Send for Foo'
+// @has - '//h3[@class="code-header"]' 'impl Send for Foo'
pub struct Foo {
hasher: Hasher<[u8; 3]>,
}
diff --git a/src/test/rustdoc/const-value-display.rs b/src/test/rustdoc/const-value-display.rs
index 5b2f3c48d..8d95f0de9 100644
--- a/src/test/rustdoc/const-value-display.rs
+++ b/src/test/rustdoc/const-value-display.rs
@@ -1,9 +1,9 @@
#![crate_name = "foo"]
// @has 'foo/constant.HOUR_IN_SECONDS.html'
-// @has - '//*[@class="docblock item-decl"]//code' 'pub const HOUR_IN_SECONDS: u64 = _; // 3_600u64'
+// @has - '//*[@class="item-decl"]//code' 'pub const HOUR_IN_SECONDS: u64 = _; // 3_600u64'
pub const HOUR_IN_SECONDS: u64 = 60 * 60;
// @has 'foo/constant.NEGATIVE.html'
-// @has - '//*[@class="docblock item-decl"]//code' 'pub const NEGATIVE: i64 = _; // -3_600i64'
+// @has - '//*[@class="item-decl"]//code' 'pub const NEGATIVE: i64 = _; // -3_600i64'
pub const NEGATIVE: i64 = -60 * 60;
diff --git a/src/test/rustdoc/decl-trailing-whitespace.rs b/src/test/rustdoc/decl-trailing-whitespace.rs
index 46a2307ab..e47edc132 100644
--- a/src/test/rustdoc/decl-trailing-whitespace.rs
+++ b/src/test/rustdoc/decl-trailing-whitespace.rs
@@ -7,7 +7,7 @@ pub struct Error;
// @has 'foo/trait.Write.html'
pub trait Write {
- // @snapshot 'declaration' - '//*[@class="docblock item-decl"]//code'
+ // @snapshot 'declaration' - '//*[@class="item-decl"]//code'
fn poll_write(
self: Option<String>,
cx: &mut Option<String>,
diff --git a/src/test/rustdoc/deref-recursive-pathbuf.rs b/src/test/rustdoc/deref-recursive-pathbuf.rs
index 746df9c80..be2b42b5a 100644
--- a/src/test/rustdoc/deref-recursive-pathbuf.rs
+++ b/src/test/rustdoc/deref-recursive-pathbuf.rs
@@ -7,9 +7,9 @@
// @has '-' '//*[@class="impl-items"]//*[@id="method.as_path"]' 'pub fn as_path(&self)'
// @has '-' '//*[@id="deref-methods-Path"]' 'Methods from Deref<Target = Path>'
// @has '-' '//*[@class="impl-items"]//*[@id="method.exists"]' 'pub fn exists(&self)'
-// @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods-PathBuf"]' 'Methods from Deref<Target=PathBuf>'
+// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-PathBuf"]' 'Methods from Deref<Target=PathBuf>'
// @has '-' '//*[@class="sidebar-elems"]//*[@class="block"]//a[@href="#method.as_path"]' 'as_path'
-// @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods-Path"]' 'Methods from Deref<Target=Path>'
+// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-Path"]' 'Methods from Deref<Target=Path>'
// @has '-' '//*[@class="sidebar-elems"]//*[@class="block"]//a[@href="#method.exists"]' 'exists'
#![crate_name = "foo"]
diff --git a/src/test/rustdoc/deref-recursive.rs b/src/test/rustdoc/deref-recursive.rs
index d5f8473f2..0436f2f86 100644
--- a/src/test/rustdoc/deref-recursive.rs
+++ b/src/test/rustdoc/deref-recursive.rs
@@ -7,9 +7,9 @@
// @has '-' '//*[@class="impl-items"]//*[@id="method.bar"]' 'pub fn bar(&self)'
// @has '-' '//*[@id="deref-methods-Baz"]' 'Methods from Deref<Target = Baz>'
// @has '-' '//*[@class="impl-items"]//*[@id="method.baz"]' 'pub fn baz(&self)'
-// @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods-Bar"]' 'Methods from Deref<Target=Bar>'
+// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-Bar"]' 'Methods from Deref<Target=Bar>'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.bar"]' 'bar'
-// @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods-Baz"]' 'Methods from Deref<Target=Baz>'
+// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-Baz"]' 'Methods from Deref<Target=Baz>'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.baz"]' 'baz'
#![crate_name = "foo"]
diff --git a/src/test/rustdoc/deref-typedef.rs b/src/test/rustdoc/deref-typedef.rs
index 28f977e31..32424d13e 100644
--- a/src/test/rustdoc/deref-typedef.rs
+++ b/src/test/rustdoc/deref-typedef.rs
@@ -6,7 +6,7 @@
// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_b"]' 'pub fn foo_b(&self)'
// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_c"]' 'pub fn foo_c(&self)'
// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_j"]' 'pub fn foo_j(&self)'
-// @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods-FooJ"]' 'Methods from Deref<Target=FooJ>'
+// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-FooJ"]' 'Methods from Deref<Target=FooJ>'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_a"]' 'foo_a'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_b"]' 'foo_b'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_c"]' 'foo_c'
diff --git a/src/test/rustdoc/doc-notable_trait_box_is_not_an_iterator.rs b/src/test/rustdoc/doc-notable_trait_box_is_not_an_iterator.rs
new file mode 100644
index 000000000..3fb00c7db
--- /dev/null
+++ b/src/test/rustdoc/doc-notable_trait_box_is_not_an_iterator.rs
@@ -0,0 +1,38 @@
+#![feature(doc_notable_trait)]
+#![feature(lang_items)]
+#![feature(no_core)]
+#![no_core]
+#[lang = "owned_box"]
+pub struct Box<T>;
+
+impl<T> Box<T> {
+ pub fn new(x: T) -> Box<T> {
+ Box
+ }
+}
+
+#[doc(notable_trait)]
+pub trait FakeIterator {}
+
+impl<I: FakeIterator> FakeIterator for Box<I> {}
+
+#[lang = "pin"]
+pub struct Pin<T>;
+
+impl<T> Pin<T> {
+ pub fn new(x: T) -> Pin<T> {
+ Pin
+ }
+}
+
+impl<I: FakeIterator> FakeIterator for Pin<I> {}
+
+// @!has doc_notable_trait_box_is_not_an_iterator/fn.foo.html '//*' 'Notable'
+pub fn foo<T>(x: T) -> Box<T> {
+ Box::new(x)
+}
+
+// @!has doc_notable_trait_box_is_not_an_iterator/fn.bar.html '//*' 'Notable'
+pub fn bar<T>(x: T) -> Pin<T> {
+ Pin::new(x)
+}
diff --git a/src/test/rustdoc/duplicate_impls/issue-33054.rs b/src/test/rustdoc/duplicate_impls/issue-33054.rs
index 84c9e4ac0..c1f95ac91 100644
--- a/src/test/rustdoc/duplicate_impls/issue-33054.rs
+++ b/src/test/rustdoc/duplicate_impls/issue-33054.rs
@@ -1,12 +1,12 @@
// ignore-tidy-linelength
// @has issue_33054/impls/struct.Foo.html
-// @has - '//h3[@class="code-header in-band"]' 'impl Foo'
-// @has - '//h3[@class="code-header in-band"]' 'impl Bar for Foo'
+// @has - '//h3[@class="code-header"]' 'impl Foo'
+// @has - '//h3[@class="code-header"]' 'impl Bar for Foo'
// @count - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]' 1
// @count - '//*[@id="main-content"]/div[@id="implementations-list"]/details/summary/*[@class="impl has-srclink"]' 1
// @has issue_33054/impls/bar/trait.Bar.html
-// @has - '//h3[@class="code-header in-band"]' 'impl Bar for Foo'
+// @has - '//h3[@class="code-header"]' 'impl Bar for Foo'
// @count - '//*[@class="struct"]' 1
pub mod impls;
diff --git a/src/test/rustdoc/empty-impl-block.rs b/src/test/rustdoc/empty-impl-block.rs
index 6a2a254f6..95d4db06b 100644
--- a/src/test/rustdoc/empty-impl-block.rs
+++ b/src/test/rustdoc/empty-impl-block.rs
@@ -16,5 +16,5 @@ pub struct Another;
pub trait Bar {}
// @has 'foo/struct.Another.html'
-// @has - '//h3[@class="code-header in-band"]' 'impl Bar for Another'
+// @has - '//h3[@class="code-header"]' 'impl Bar for Another'
impl Bar for Another {}
diff --git a/src/test/rustdoc/escape-deref-methods.rs b/src/test/rustdoc/escape-deref-methods.rs
index a62ad2c40..66919d73e 100644
--- a/src/test/rustdoc/escape-deref-methods.rs
+++ b/src/test/rustdoc/escape-deref-methods.rs
@@ -27,7 +27,7 @@ impl Deref for TitleList {
}
// @has foo/struct.TitleList.html
-// @has - '//*[@class="sidebar-title"]' 'Methods from Deref<Target=Vec<Title>>'
+// @has - '//div[@class="sidebar-elems"]//h3' 'Methods from Deref<Target=Vec<Title>>'
impl DerefMut for TitleList {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.members
diff --git a/src/test/rustdoc/extern-impl.rs b/src/test/rustdoc/extern-impl.rs
index f357d65df..fd1bc2140 100644
--- a/src/test/rustdoc/extern-impl.rs
+++ b/src/test/rustdoc/extern-impl.rs
@@ -19,9 +19,9 @@ impl Foo {
// @has foo/trait.Bar.html
pub trait Bar {}
-// @has - '//h3[@class="code-header in-band"]' 'impl Bar for fn()'
+// @has - '//h3[@class="code-header"]' 'impl Bar for fn()'
impl Bar for fn() {}
-// @has - '//h3[@class="code-header in-band"]' 'impl Bar for extern "C" fn()'
+// @has - '//h3[@class="code-header"]' 'impl Bar for extern "C" fn()'
impl Bar for extern fn() {}
-// @has - '//h3[@class="code-header in-band"]' 'impl Bar for extern "system" fn()'
+// @has - '//h3[@class="code-header"]' 'impl Bar for extern "system" fn()'
impl Bar for extern "system" fn() {}
diff --git a/src/test/rustdoc/fn-bound.rs b/src/test/rustdoc/fn-bound.rs
index 4c4ffddc8..9e060ff20 100644
--- a/src/test/rustdoc/fn-bound.rs
+++ b/src/test/rustdoc/fn-bound.rs
@@ -11,7 +11,7 @@ pub struct ConditionalIterator<F> {
}
-// @has 'fn_bound/struct.ConditionalIterator.html' '//h3[@class="code-header in-band"]' 'impl<F: Fn(&i32)> Iterator for ConditionalIterator<F>'
+// @has 'fn_bound/struct.ConditionalIterator.html' '//h3[@class="code-header"]' 'impl<F: Fn(&i32)> Iterator for ConditionalIterator<F>'
impl<F: Fn(&i32)> Iterator for ConditionalIterator<F> {
type Item = ();
diff --git a/src/test/rustdoc/generic-impl.rs b/src/test/rustdoc/generic-impl.rs
index c6beed70a..6f68b1574 100644
--- a/src/test/rustdoc/generic-impl.rs
+++ b/src/test/rustdoc/generic-impl.rs
@@ -5,7 +5,7 @@ use std::fmt;
// @!has foo/struct.Bar.html '//*[@id="impl-ToString-for-Bar"]' ''
pub struct Bar;
-// @has foo/struct.Foo.html '//*[@id="impl-ToString-for-Foo"]//h3[@class="code-header in-band"]' 'impl<T> ToString for T'
+// @has foo/struct.Foo.html '//*[@id="impl-ToString-for-Foo"]//h3[@class="code-header"]' 'impl<T> ToString for T'
pub struct Foo;
// @has foo/struct.Foo.html '//*[@class="sidebar-elems"]//section//a[@href="#impl-ToString-for-Foo"]' 'ToString'
diff --git a/src/test/rustdoc/higher-ranked-trait-bounds.rs b/src/test/rustdoc/higher-ranked-trait-bounds.rs
index 59b5b6e57..3493ae6d2 100644
--- a/src/test/rustdoc/higher-ranked-trait-bounds.rs
+++ b/src/test/rustdoc/higher-ranked-trait-bounds.rs
@@ -49,7 +49,7 @@ impl<'a> Foo<'a> {
// @has foo/trait.B.html
pub trait B<'x> {}
-// @has - '//h3[@class="code-header in-band"]' "impl<'a> B<'a> for dyn for<'b> Trait<'b>"
+// @has - '//h3[@class="code-header"]' "impl<'a> B<'a> for dyn for<'b> Trait<'b>"
impl<'a> B<'a> for dyn for<'b> Trait<'b> {}
// @has foo/struct.Bar.html
diff --git a/src/test/rustdoc/impl-disambiguation.rs b/src/test/rustdoc/impl-disambiguation.rs
index d1d39ccff..9e74ede8f 100644
--- a/src/test/rustdoc/impl-disambiguation.rs
+++ b/src/test/rustdoc/impl-disambiguation.rs
@@ -4,13 +4,13 @@ pub trait Foo {}
pub struct Bar<T> { field: T }
-// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header in-band"]' \
+// @has foo/trait.Foo.html '//*[@id="implementors-list"]//h3[@class="code-header"]' \
// "impl Foo for Bar<u8>"
impl Foo for Bar<u8> {}
-// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header in-band"]' \
+// @has foo/trait.Foo.html '//*[@id="implementors-list"]//h3[@class="code-header"]' \
// "impl Foo for Bar<u16>"
impl Foo for Bar<u16> {}
-// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header in-band"]' \
+// @has foo/trait.Foo.html '//*[@id="implementors-list"]//h3[@class="code-header"]' \
// "impl<'a> Foo for &'a Bar<u8>"
impl<'a> Foo for &'a Bar<u8> {}
@@ -22,9 +22,9 @@ pub mod mod2 {
pub enum Baz {}
}
-// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header in-band"]' \
+// @has foo/trait.Foo.html '//*[@id="implementors-list"]//h3[@class="code-header"]' \
// "impl Foo for foo::mod1::Baz"
impl Foo for mod1::Baz {}
-// @has foo/trait.Foo.html '//*[@class="item-list"]//h3[@class="code-header in-band"]' \
+// @has foo/trait.Foo.html '//*[@id="implementors-list"]//h3[@class="code-header"]' \
// "impl<'a> Foo for &'a foo::mod2::Baz"
impl<'a> Foo for &'a mod2::Baz {}
diff --git a/src/test/rustdoc/impl-parts.rs b/src/test/rustdoc/impl-parts.rs
index b1481e1f2..7b931727e 100644
--- a/src/test/rustdoc/impl-parts.rs
+++ b/src/test/rustdoc/impl-parts.rs
@@ -5,8 +5,8 @@ pub auto trait AnAutoTrait {}
pub struct Foo<T> { field: T }
-// @has impl_parts/struct.Foo.html '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has impl_parts/struct.Foo.html '//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<T: Clone> !AnAutoTrait for Foo<T>where T: Sync,"
-// @has impl_parts/trait.AnAutoTrait.html '//*[@class="item-list"]//h3[@class="code-header in-band"]' \
+// @has impl_parts/trait.AnAutoTrait.html '//*[@id="implementors-list"]//h3[@class="code-header"]' \
// "impl<T: Clone> !AnAutoTrait for Foo<T>where T: Sync,"
impl<T: Clone> !AnAutoTrait for Foo<T> where T: Sync {}
diff --git a/src/test/rustdoc/index-page.rs b/src/test/rustdoc/index-page.rs
index be668a127..0c947ea2e 100644
--- a/src/test/rustdoc/index-page.rs
+++ b/src/test/rustdoc/index-page.rs
@@ -5,7 +5,7 @@
#![crate_name = "foo"]
// @has foo/../index.html
-// @has - '//span[@class="in-band"]' 'List of all crates'
-// @has - '//ul[@class="crate mod"]//a[@href="foo/index.html"]' 'foo'
-// @has - '//ul[@class="crate mod"]//a[@href="all_item_types/index.html"]' 'all_item_types'
+// @has - '//h1[@class="fqn"]' 'List of all crates'
+// @has - '//ul[@class="all-items"]//a[@href="foo/index.html"]' 'foo'
+// @has - '//ul[@class="all-items"]//a[@href="all_item_types/index.html"]' 'all_item_types'
pub struct Foo;
diff --git a/src/test/rustdoc/inline_cross/assoc_item_trait_bounds.out0.html b/src/test/rustdoc/inline_cross/assoc_item_trait_bounds.out0.html
new file mode 100644
index 000000000..8934bc1ee
--- /dev/null
+++ b/src/test/rustdoc/inline_cross/assoc_item_trait_bounds.out0.html
@@ -0,0 +1 @@
+<h4 class="code-header">type <a href="#associatedtype.Out0" class="associatedtype">Out0</a>: <a class="trait" href="../assoc_item_trait_bounds/trait.Support.html" title="trait assoc_item_trait_bounds::Support">Support</a>&lt;Item = <a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>&gt;</h4> \ No newline at end of file
diff --git a/src/test/rustdoc/inline_cross/assoc_item_trait_bounds.out2.html b/src/test/rustdoc/inline_cross/assoc_item_trait_bounds.out2.html
new file mode 100644
index 000000000..bf330670e
--- /dev/null
+++ b/src/test/rustdoc/inline_cross/assoc_item_trait_bounds.out2.html
@@ -0,0 +1 @@
+<h4 class="code-header">type <a href="#associatedtype.Out2" class="associatedtype">Out2</a>&lt;T&gt;: <a class="trait" href="../assoc_item_trait_bounds/trait.Support.html" title="trait assoc_item_trait_bounds::Support">Support</a>&lt;Item = T&gt;</h4> \ No newline at end of file
diff --git a/src/test/rustdoc/inline_cross/assoc_item_trait_bounds.out9.html b/src/test/rustdoc/inline_cross/assoc_item_trait_bounds.out9.html
new file mode 100644
index 000000000..69d84e1b2
--- /dev/null
+++ b/src/test/rustdoc/inline_cross/assoc_item_trait_bounds.out9.html
@@ -0,0 +1 @@
+<h4 class="code-header">type <a href="#associatedtype.Out9" class="associatedtype">Out9</a>: <a class="trait" href="{{channel}}/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="{{channel}}/std/primitive.i32.html">i32</a>) -&gt; <a class="primitive" href="{{channel}}/std/primitive.bool.html">bool</a> + <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a></h4> \ No newline at end of file
diff --git a/src/test/rustdoc/inline_cross/assoc_item_trait_bounds.rs b/src/test/rustdoc/inline_cross/assoc_item_trait_bounds.rs
new file mode 100644
index 000000000..5f4712aab
--- /dev/null
+++ b/src/test/rustdoc/inline_cross/assoc_item_trait_bounds.rs
@@ -0,0 +1,40 @@
+// Regression test for issues #77763, #84579 and #102142.
+#![crate_name = "main"]
+
+// aux-build:assoc_item_trait_bounds.rs
+// build-aux-docs
+// ignore-cross-compile
+extern crate assoc_item_trait_bounds as aux;
+
+// @has main/trait.Main.html
+// @has - '//*[@id="associatedtype.Out0"]' 'type Out0: Support<Item = ()>'
+// @has - '//*[@id="associatedtype.Out1"]' 'type Out1: Support<Item = Self::Item>'
+// @has - '//*[@id="associatedtype.Out2"]' 'type Out2<T>: Support<Item = T>'
+// @has - '//*[@id="associatedtype.Out3"]' 'type Out3: Support<Produce<()> = bool>'
+// @has - '//*[@id="associatedtype.Out4"]' 'type Out4<T>: Support<Produce<T> = T>'
+// @has - '//*[@id="associatedtype.Out5"]' "type Out5: Support<Output<'static> = &'static ()>"
+// @has - '//*[@id="associatedtype.Out6"]' "type Out6: for<'a> Support<Output<'a> = &'a ()>"
+// @has - '//*[@id="associatedtype.Out7"]' "type Out7: Support<Item = String, Produce<i32> = u32> + Unrelated"
+// @has - '//*[@id="associatedtype.Out8"]' "type Out8: Unrelated + Protocol<i16, Q1 = u128, Q0 = ()>"
+// @has - '//*[@id="associatedtype.Out9"]' "type Out9: FnMut(i32) -> bool + Clone"
+// @has - '//*[@id="associatedtype.Out10"]' "type Out10<'q>: Support<Output<'q> = ()>"
+// @has - '//*[@id="associatedtype.Out11"]' "type Out11: for<'r, 's> Helper<A<'s> = &'s (), B<'r> = ()>"
+// @has - '//*[@id="associatedtype.Out12"]' "type Out12: for<'w> Helper<B<'w> = Cow<'w, str>, A<'w> = bool>"
+// @has - '//*[@id="associatedtype.Out13"]' "type Out13: for<'fst, 'snd> Aid<'snd, Result<'fst> = &'fst mut str>"
+// @has - '//*[@id="associatedtype.Out14"]' "type Out14<P: Copy + Eq, Q: ?Sized>"
+//
+// Snapshots:
+// Check that we don't render any where-clauses for the following associated types since
+// all corresponding projection equality predicates should have already been re-sugared
+// to associated type bindings:
+//
+// @snapshot out0 - '//*[@id="associatedtype.Out0"]/*[@class="code-header"]'
+// @snapshot out2 - '//*[@id="associatedtype.Out2"]/*[@class="code-header"]'
+// @snapshot out9 - '//*[@id="associatedtype.Out9"]/*[@class="code-header"]'
+//
+// @has - '//*[@id="tymethod.make"]' \
+// "fn make<F>(F, impl FnMut(&str) -> bool)\
+// where \
+// F: FnOnce(u32) -> String, \
+// Self::Out2<()>: Protocol<u8, Q0 = Self::Item, Q1 = ()>"
+pub use aux::Main;
diff --git a/src/test/rustdoc/inline_cross/auxiliary/assoc_item_trait_bounds.rs b/src/test/rustdoc/inline_cross/auxiliary/assoc_item_trait_bounds.rs
new file mode 100644
index 000000000..d326e61da
--- /dev/null
+++ b/src/test/rustdoc/inline_cross/auxiliary/assoc_item_trait_bounds.rs
@@ -0,0 +1,46 @@
+pub trait Main {
+ type Item;
+
+ type Out0: Support<Item = ()>;
+ type Out1: Support<Item = Self::Item>;
+ type Out2<T>: Support<Item = T>;
+ type Out3: Support<Produce<()> = bool>;
+ type Out4<T>: Support<Produce<T> = T>;
+ type Out5: Support<Output<'static> = &'static ()>;
+ type Out6: for<'a> Support<Output<'a> = &'a ()>;
+ type Out7: Support<Item = String, Produce<i32> = u32> + Unrelated;
+ type Out8: Unrelated + Protocol<i16, Q1 = u128, Q0 = ()>;
+ type Out9: FnMut(i32) -> bool + Clone;
+ type Out10<'q>: Support<Output<'q> = ()>;
+ type Out11: for<'r, 's> Helper<A<'s> = &'s (), B<'r> = ()>;
+ type Out12: for<'w> Helper<B<'w> = std::borrow::Cow<'w, str>, A<'w> = bool>;
+ type Out13: for<'fst, 'snd> Aid<'snd, Result<'fst> = &'fst mut str>;
+ type Out14<P: Copy + Eq, Q: ?Sized>;
+
+ fn make<F>(_: F, _: impl FnMut(&str) -> bool)
+ where
+ F: FnOnce(u32) -> String,
+ Self::Out2<()>: Protocol<u8, Q0 = Self::Item, Q1 = ()>;
+}
+
+pub trait Support {
+ type Item;
+ type Output<'a>;
+ type Produce<T>;
+}
+
+pub trait Protocol<K> {
+ type Q0;
+ type Q1;
+}
+
+pub trait Unrelated {}
+
+pub trait Helper {
+ type A<'q>;
+ type B<'q>;
+}
+
+pub trait Aid<'src> {
+ type Result<'inter>;
+}
diff --git a/src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs b/src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs
index 913ba8f2a..19433c968 100644
--- a/src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs
+++ b/src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs
@@ -13,6 +13,19 @@ pub fn func3(_x: impl Iterator<Item = impl Iterator<Item = u8>> + Clone) {}
pub fn func4<T: Iterator<Item = impl Clone>>(_x: T) {}
+pub fn func5(
+ _f: impl for<'any> Fn(&'any str, &'any str) -> bool + for<'r> Other<T<'r> = ()>,
+ _a: impl for<'alpha, 'beta> Auxiliary<'alpha, Item<'beta> = fn(&'beta ())>,
+) {}
+
+pub trait Other {
+ type T<'dependency>;
+}
+
+pub trait Auxiliary<'arena> {
+ type Item<'input>;
+}
+
pub async fn async_fn() {}
pub struct Foo;
diff --git a/src/test/rustdoc/inline_cross/auxiliary/issue-24183.rs b/src/test/rustdoc/inline_cross/auxiliary/issue-24183.rs
new file mode 100644
index 000000000..e7a13acc6
--- /dev/null
+++ b/src/test/rustdoc/inline_cross/auxiliary/issue-24183.rs
@@ -0,0 +1,14 @@
+#![crate_type = "lib"]
+
+pub trait U/*: ?Sized */ {
+ fn modified(self) -> Self
+ where
+ Self: Sized
+ {
+ self
+ }
+
+ fn touch(&self)/* where Self: ?Sized */{}
+}
+
+pub trait S: Sized {}
diff --git a/src/test/rustdoc/inline_cross/impl_trait.rs b/src/test/rustdoc/inline_cross/impl_trait.rs
index ef615472b..6c1cf8252 100644
--- a/src/test/rustdoc/inline_cross/impl_trait.rs
+++ b/src/test/rustdoc/inline_cross/impl_trait.rs
@@ -26,6 +26,13 @@ pub use impl_trait_aux::func3;
// @has - '//pre[@class="rust fn"]' "T: Iterator<Item = impl Clone>,"
pub use impl_trait_aux::func4;
+// @has impl_trait/fn.func5.html
+// @has - '//pre[@class="rust fn"]' "func5("
+// @has - '//pre[@class="rust fn"]' "_f: impl for<'any> Fn(&'any str, &'any str) -> bool + for<'r> Other<T<'r> = ()>,"
+// @has - '//pre[@class="rust fn"]' "_a: impl for<'alpha, 'beta> Auxiliary<'alpha, Item<'beta> = fn(&'beta ())>"
+// @!has - '//pre[@class="rust fn"]' 'where'
+pub use impl_trait_aux::func5;
+
// @has impl_trait/fn.async_fn.html
// @has - '//pre[@class="rust fn"]' "pub async fn async_fn()"
pub use impl_trait_aux::async_fn;
diff --git a/src/test/rustdoc/inline_cross/issue-24183.method_no_where_self_sized.html b/src/test/rustdoc/inline_cross/issue-24183.method_no_where_self_sized.html
new file mode 100644
index 000000000..6955a9614
--- /dev/null
+++ b/src/test/rustdoc/inline_cross/issue-24183.method_no_where_self_sized.html
@@ -0,0 +1 @@
+<h4 class="code-header">fn <a href="#method.touch" class="fnname">touch</a>(&amp;self)</h4> \ No newline at end of file
diff --git a/src/test/rustdoc/inline_cross/issue-24183.rs b/src/test/rustdoc/inline_cross/issue-24183.rs
new file mode 100644
index 000000000..d11b6955f
--- /dev/null
+++ b/src/test/rustdoc/inline_cross/issue-24183.rs
@@ -0,0 +1,18 @@
+#![crate_type = "lib"]
+#![crate_name = "usr"]
+
+// aux-crate:issue_24183=issue-24183.rs
+// edition: 2021
+
+// @has usr/trait.U.html
+// @has - '//*[@class="item-decl"]' "pub trait U {"
+// @has - '//*[@id="method.modified"]' \
+// "fn modified(self) -> Self\
+// where \
+// Self: Sized"
+// @snapshot method_no_where_self_sized - '//*[@id="method.touch"]/*[@class="code-header"]'
+pub use issue_24183::U;
+
+// @has usr/trait.S.html
+// @has - '//*[@class="item-decl"]' 'pub trait S: Sized {'
+pub use issue_24183::S;
diff --git a/src/test/rustdoc/inline_cross/issue-31948-1.rs b/src/test/rustdoc/inline_cross/issue-31948-1.rs
index be8585dd1..6e89167b3 100644
--- a/src/test/rustdoc/inline_cross/issue-31948-1.rs
+++ b/src/test/rustdoc/inline_cross/issue-31948-1.rs
@@ -5,22 +5,22 @@
extern crate rustdoc_nonreachable_impls;
// @has issue_31948_1/struct.Wobble.html
-// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Bark for'
-// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Woof for'
-// @!has - '//*[@class="impl"]//h3[@class="code-header in-band"]' 'Bar for'
-// @!has - '//*[@class="impl"]//h3[@class="code-header in-band"]' 'Qux for'
+// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Bark for'
+// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Woof for'
+// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'Bar for'
+// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'Qux for'
pub use rustdoc_nonreachable_impls::hidden::Wobble;
// @has issue_31948_1/trait.Bark.html
-// @has - '//h3[@class="code-header in-band"]' 'for Foo'
-// @has - '//h3[@class="code-header in-band"]' 'for Wobble'
-// @!has - '//h3[@class="code-header in-band"]' 'for Wibble'
+// @has - '//h3[@class="code-header"]' 'for Foo'
+// @has - '//h3[@class="code-header"]' 'for Wobble'
+// @!has - '//h3[@class="code-header"]' 'for Wibble'
pub use rustdoc_nonreachable_impls::Bark;
// @has issue_31948_1/trait.Woof.html
-// @has - '//h3[@class="code-header in-band"]' 'for Foo'
-// @has - '//h3[@class="code-header in-band"]' 'for Wobble'
-// @!has - '//h3[@class="code-header in-band"]' 'for Wibble'
+// @has - '//h3[@class="code-header"]' 'for Foo'
+// @has - '//h3[@class="code-header"]' 'for Wobble'
+// @!has - '//h3[@class="code-header"]' 'for Wibble'
pub use rustdoc_nonreachable_impls::Woof;
// @!has issue_31948_1/trait.Bar.html
diff --git a/src/test/rustdoc/inline_cross/issue-31948-2.rs b/src/test/rustdoc/inline_cross/issue-31948-2.rs
index 7aa994f19..141e07656 100644
--- a/src/test/rustdoc/inline_cross/issue-31948-2.rs
+++ b/src/test/rustdoc/inline_cross/issue-31948-2.rs
@@ -5,15 +5,15 @@
extern crate rustdoc_nonreachable_impls;
// @has issue_31948_2/struct.Wobble.html
-// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Qux for'
-// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Bark for'
-// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Woof for'
-// @!has - '//*[@class="impl"]//h3[@class="code-header in-band"]' 'Bar for'
+// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Qux for'
+// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Bark for'
+// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Woof for'
+// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'Bar for'
pub use rustdoc_nonreachable_impls::hidden::Wobble;
// @has issue_31948_2/trait.Qux.html
-// @has - '//h3[@class="code-header in-band"]' 'for Foo'
-// @has - '//h3[@class="code-header in-band"]' 'for Wobble'
+// @has - '//h3[@class="code-header"]' 'for Foo'
+// @has - '//h3[@class="code-header"]' 'for Wobble'
pub use rustdoc_nonreachable_impls::hidden::Qux;
// @!has issue_31948_2/trait.Bar.html
diff --git a/src/test/rustdoc/inline_cross/issue-31948.rs b/src/test/rustdoc/inline_cross/issue-31948.rs
index 7bf4110d3..96fc6ca47 100644
--- a/src/test/rustdoc/inline_cross/issue-31948.rs
+++ b/src/test/rustdoc/inline_cross/issue-31948.rs
@@ -5,22 +5,22 @@
extern crate rustdoc_nonreachable_impls;
// @has issue_31948/struct.Foo.html
-// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Bark for'
-// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Woof for'
-// @!has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'Bar for'
-// @!has - '//*[@class="impl"]//h3[@class="code-header in-band"]' 'Qux for'
+// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Bark for'
+// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Woof for'
+// @!has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'Bar for'
+// @!has - '//*[@class="impl"]//h3[@class="code-header"]' 'Qux for'
pub use rustdoc_nonreachable_impls::Foo;
// @has issue_31948/trait.Bark.html
-// @has - '//h3[@class="code-header in-band"]' 'for Foo'
-// @!has - '//h3[@class="code-header in-band"]' 'for Wibble'
-// @!has - '//h3[@class="code-header in-band"]' 'for Wobble'
+// @has - '//h3[@class="code-header"]' 'for Foo'
+// @!has - '//h3[@class="code-header"]' 'for Wibble'
+// @!has - '//h3[@class="code-header"]' 'for Wobble'
pub use rustdoc_nonreachable_impls::Bark;
// @has issue_31948/trait.Woof.html
-// @has - '//h3[@class="code-header in-band"]' 'for Foo'
-// @!has - '//h3[@class="code-header in-band"]' 'for Wibble'
-// @!has - '//h3[@class="code-header in-band"]' 'for Wobble'
+// @has - '//h3[@class="code-header"]' 'for Foo'
+// @!has - '//h3[@class="code-header"]' 'for Wibble'
+// @!has - '//h3[@class="code-header"]' 'for Wobble'
pub use rustdoc_nonreachable_impls::Woof;
// @!has issue_31948/trait.Bar.html
diff --git a/src/test/rustdoc/inline_cross/issue-32881.rs b/src/test/rustdoc/inline_cross/issue-32881.rs
index 8052339a8..183fd15ab 100644
--- a/src/test/rustdoc/inline_cross/issue-32881.rs
+++ b/src/test/rustdoc/inline_cross/issue-32881.rs
@@ -5,7 +5,7 @@
extern crate rustdoc_trait_object_impl;
// @has issue_32881/trait.Bar.html
-// @has - '//h3[@class="code-header in-band"]' "impl<'a> dyn Bar"
-// @has - '//h3[@class="code-header in-band"]' "impl<'a> Debug for dyn Bar"
+// @has - '//h3[@class="code-header"]' "impl<'a> dyn Bar"
+// @has - '//h3[@class="code-header"]' "impl<'a> Debug for dyn Bar"
pub use rustdoc_trait_object_impl::Bar;
diff --git a/src/test/rustdoc/inline_cross/issue-33113.rs b/src/test/rustdoc/inline_cross/issue-33113.rs
index c60859bbc..d954707fa 100644
--- a/src/test/rustdoc/inline_cross/issue-33113.rs
+++ b/src/test/rustdoc/inline_cross/issue-33113.rs
@@ -5,6 +5,6 @@
extern crate bar;
// @has issue_33113/trait.Bar.html
-// @has - '//h3[@class="code-header in-band"]' "for &'a char"
-// @has - '//h3[@class="code-header in-band"]' "for Foo"
+// @has - '//h3[@class="code-header"]' "for &'a char"
+// @has - '//h3[@class="code-header"]' "for Foo"
pub use bar::Bar;
diff --git a/src/test/rustdoc/inline_cross/trait-vis.rs b/src/test/rustdoc/inline_cross/trait-vis.rs
index 363c52a33..b646babac 100644
--- a/src/test/rustdoc/inline_cross/trait-vis.rs
+++ b/src/test/rustdoc/inline_cross/trait-vis.rs
@@ -3,5 +3,5 @@
extern crate inner;
// @has trait_vis/struct.SomeStruct.html
-// @has - '//h3[@class="code-header in-band"]' 'impl Clone for SomeStruct'
+// @has - '//h3[@class="code-header"]' 'impl Clone for SomeStruct'
pub use inner::SomeStruct;
diff --git a/src/test/rustdoc/inline_local/trait-vis.rs b/src/test/rustdoc/inline_local/trait-vis.rs
index e7b08088f..19b69da15 100644
--- a/src/test/rustdoc/inline_local/trait-vis.rs
+++ b/src/test/rustdoc/inline_local/trait-vis.rs
@@ -13,6 +13,6 @@ mod asdf {
}
// @has trait_vis/struct.SomeStruct.html
-// @has - '//h3[@class="code-header in-band"]' 'impl ThisTrait for SomeStruct'
-// @!has - '//h3[@class="code-header in-band"]' 'impl PrivateTrait for SomeStruct'
+// @has - '//h3[@class="code-header"]' 'impl ThisTrait for SomeStruct'
+// @!has - '//h3[@class="code-header"]' 'impl PrivateTrait for SomeStruct'
pub use asdf::SomeStruct;
diff --git a/src/test/rustdoc/intra-doc/auxiliary/issue-103463-aux.rs b/src/test/rustdoc/intra-doc/auxiliary/issue-103463-aux.rs
new file mode 100644
index 000000000..2b8fdec1f
--- /dev/null
+++ b/src/test/rustdoc/intra-doc/auxiliary/issue-103463-aux.rs
@@ -0,0 +1,4 @@
+pub trait Trait {
+ /// [`u8::clone`]
+ fn method();
+}
diff --git a/src/test/rustdoc/intra-doc/extern-crate-only-used-in-link.rs b/src/test/rustdoc/intra-doc/extern-crate-only-used-in-link.rs
index 5d8dcf8bc..ad50887e9 100644
--- a/src/test/rustdoc/intra-doc/extern-crate-only-used-in-link.rs
+++ b/src/test/rustdoc/intra-doc/extern-crate-only-used-in-link.rs
@@ -16,4 +16,4 @@
//! [`empty`]
// @has - '//a[@href="../empty2/index.html"]' 'empty2'
-//! [empty2<x>]
+//! [`empty2<x>`]
diff --git a/src/test/rustdoc/intra-doc/issue-103463.rs b/src/test/rustdoc/intra-doc/issue-103463.rs
new file mode 100644
index 000000000..4adf8a9a8
--- /dev/null
+++ b/src/test/rustdoc/intra-doc/issue-103463.rs
@@ -0,0 +1,8 @@
+// The `Trait` is not pulled into the crate resulting in doc links in its methods being resolved.
+
+// aux-build:issue-103463-aux.rs
+
+extern crate issue_103463_aux;
+use issue_103463_aux::Trait;
+
+fn main() {}
diff --git a/src/test/rustdoc/intra-doc/issue-104145.rs b/src/test/rustdoc/intra-doc/issue-104145.rs
new file mode 100644
index 000000000..9ce36740d
--- /dev/null
+++ b/src/test/rustdoc/intra-doc/issue-104145.rs
@@ -0,0 +1,14 @@
+// Doc links in `Trait`'s methods are resolved because it has a local impl.
+
+// aux-build:issue-103463-aux.rs
+
+extern crate issue_103463_aux;
+use issue_103463_aux::Trait;
+
+pub struct LocalType;
+
+impl Trait for LocalType {
+ fn method() {}
+}
+
+fn main() {}
diff --git a/src/test/rustdoc/intra-doc/no-doc-primitive.rs b/src/test/rustdoc/intra-doc/no-doc-primitive.rs
new file mode 100644
index 000000000..e5eba1d8d
--- /dev/null
+++ b/src/test/rustdoc/intra-doc/no-doc-primitive.rs
@@ -0,0 +1,15 @@
+// Crate tree without a `doc(primitive)` module for primitive type linked to by a doc link.
+
+#![deny(rustdoc::broken_intra_doc_links)]
+#![feature(no_core, lang_items, rustc_attrs)]
+#![no_core]
+#![rustc_coherence_is_core]
+#![crate_type = "rlib"]
+
+// @has no_doc_primitive/index.html
+//! A [`char`] and its [`char::len_utf8`].
+impl char {
+ pub fn len_utf8(self) -> usize {
+ 42
+ }
+}
diff --git a/src/test/rustdoc/issue-100241.rs b/src/test/rustdoc/issue-100241.rs
new file mode 100644
index 000000000..9e9cba13a
--- /dev/null
+++ b/src/test/rustdoc/issue-100241.rs
@@ -0,0 +1,12 @@
+//! See [`S`].
+
+// Check that this isn't an ICE
+// should-fail
+
+mod foo {
+ pub use inner::S;
+ //~^ ERROR unresolved imports `inner`, `foo::S`
+}
+
+use foo::*;
+use foo::S;
diff --git a/src/test/rustdoc/issue-29503.rs b/src/test/rustdoc/issue-29503.rs
index 134821e1e..01ae44385 100644
--- a/src/test/rustdoc/issue-29503.rs
+++ b/src/test/rustdoc/issue-29503.rs
@@ -5,7 +5,7 @@ pub trait MyTrait {
fn my_string(&self) -> String;
}
-// @has - "//div[@id='implementors-list']//*[@id='impl-MyTrait-for-T']//h3[@class='code-header in-band']" "impl<T> MyTrait for Twhere T: Debug"
+// @has - "//div[@id='implementors-list']//*[@id='impl-MyTrait-for-T']//h3[@class='code-header']" "impl<T> MyTrait for Twhere T: Debug"
impl<T> MyTrait for T
where
T: fmt::Debug,
diff --git a/src/test/rustdoc/issue-33592.rs b/src/test/rustdoc/issue-33592.rs
index 815439db9..7a128f0b8 100644
--- a/src/test/rustdoc/issue-33592.rs
+++ b/src/test/rustdoc/issue-33592.rs
@@ -6,8 +6,8 @@ pub struct Bar;
pub struct Baz;
-// @has foo/trait.Foo.html '//h3[@class="code-header in-band"]' 'impl Foo<i32> for Bar'
+// @has foo/trait.Foo.html '//h3[@class="code-header"]' 'impl Foo<i32> for Bar'
impl Foo<i32> for Bar {}
-// @has foo/trait.Foo.html '//h3[@class="code-header in-band"]' 'impl<T> Foo<T> for Baz'
+// @has foo/trait.Foo.html '//h3[@class="code-header"]' 'impl<T> Foo<T> for Baz'
impl<T> Foo<T> for Baz {}
diff --git a/src/test/rustdoc/issue-46727.rs b/src/test/rustdoc/issue-46727.rs
index 00e9127a3..8cfc4827a 100644
--- a/src/test/rustdoc/issue-46727.rs
+++ b/src/test/rustdoc/issue-46727.rs
@@ -3,5 +3,5 @@
extern crate issue_46727;
// @has issue_46727/trait.Foo.html
-// @has - '//h3[@class="code-header in-band"]' 'impl<T> Foo for Bar<[T; 3]>'
+// @has - '//h3[@class="code-header"]' 'impl<T> Foo for Bar<[T; 3]>'
pub use issue_46727::{Foo, Bar};
diff --git a/src/test/rustdoc/issue-50159.rs b/src/test/rustdoc/issue-50159.rs
index 43fb705f5..04bc4f304 100644
--- a/src/test/rustdoc/issue-50159.rs
+++ b/src/test/rustdoc/issue-50159.rs
@@ -11,8 +11,8 @@ impl<B, C> Signal2 for B where B: Signal<Item = C> {
}
// @has issue_50159/struct.Switch.html
-// @has - '//h3[@class="code-header in-band"]' 'impl<B> Send for Switch<B>where <B as Signal>::Item: Send'
-// @has - '//h3[@class="code-header in-band"]' 'impl<B> Sync for Switch<B>where <B as Signal>::Item: Sync'
+// @has - '//h3[@class="code-header"]' 'impl<B> Send for Switch<B>where <B as Signal>::Item: Send'
+// @has - '//h3[@class="code-header"]' 'impl<B> Sync for Switch<B>where <B as Signal>::Item: Sync'
// @count - '//*[@id="implementations-list"]//*[@class="impl"]' 0
// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]' 5
pub struct Switch<B: Signal> {
diff --git a/src/test/rustdoc/issue-51236.rs b/src/test/rustdoc/issue-51236.rs
index aa5890a84..1c7aa9c7e 100644
--- a/src/test/rustdoc/issue-51236.rs
+++ b/src/test/rustdoc/issue-51236.rs
@@ -7,7 +7,7 @@ pub mod traits {
}
// @has issue_51236/struct.Owned.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<T> Send for Owned<T>where <T as Owned<'static>>::Reader: Send"
pub struct Owned<T> where T: for<'a> ::traits::Owned<'a> {
marker: PhantomData<<T as ::traits::Owned<'static>>::Reader>,
diff --git a/src/test/rustdoc/issue-54705.rs b/src/test/rustdoc/issue-54705.rs
index ce0f85d25..7b7290ab4 100644
--- a/src/test/rustdoc/issue-54705.rs
+++ b/src/test/rustdoc/issue-54705.rs
@@ -1,10 +1,10 @@
pub trait ScopeHandle<'scope> {}
// @has issue_54705/struct.ScopeFutureContents.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<'scope, S> Send for ScopeFutureContents<'scope, S>where S: Sync"
//
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<'scope, S> Sync for ScopeFutureContents<'scope, S>where S: Sync"
pub struct ScopeFutureContents<'scope, S>
where S: ScopeHandle<'scope>,
diff --git a/src/test/rustdoc/issue-55321.rs b/src/test/rustdoc/issue-55321.rs
index ee2420d86..22a18ef90 100644
--- a/src/test/rustdoc/issue-55321.rs
+++ b/src/test/rustdoc/issue-55321.rs
@@ -1,9 +1,9 @@
#![feature(negative_impls)]
// @has issue_55321/struct.A.html
-// @has - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl !Send for A"
-// @has - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl !Sync for A"
pub struct A();
@@ -11,8 +11,8 @@ impl !Send for A {}
impl !Sync for A {}
// @has issue_55321/struct.B.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<T> !Send for B<T>"
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<T> !Sync for B<T>"
pub struct B<T: ?Sized>(A, Box<T>);
diff --git a/src/test/rustdoc/issue-56822.rs b/src/test/rustdoc/issue-56822.rs
index aef6ddd8d..b4eef344b 100644
--- a/src/test/rustdoc/issue-56822.rs
+++ b/src/test/rustdoc/issue-56822.rs
@@ -17,7 +17,7 @@ impl<'a, T> MyTrait for Inner<'a, T> {
}
// @has issue_56822/struct.Parser.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<'a> Send for Parser<'a>"
pub struct Parser<'a> {
field: <Wrapper<Inner<'a, u8>> as MyTrait>::Output
diff --git a/src/test/rustdoc/issue-60726.rs b/src/test/rustdoc/issue-60726.rs
index 167f0f039..fbb0f82ae 100644
--- a/src/test/rustdoc/issue-60726.rs
+++ b/src/test/rustdoc/issue-60726.rs
@@ -26,9 +26,9 @@ where
{}
// @has issue_60726/struct.IntoIter.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<T> !Send for IntoIter<T>"
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<T> !Sync for IntoIter<T>"
pub struct IntoIter<T>{
hello:DynTrait<FooInterface<T>>,
diff --git a/src/test/rustdoc/issue-75588.rs b/src/test/rustdoc/issue-75588.rs
index ac97b94fb..3b11059a7 100644
--- a/src/test/rustdoc/issue-75588.rs
+++ b/src/test/rustdoc/issue-75588.rs
@@ -10,8 +10,8 @@ extern crate realcore;
extern crate real_gimli;
// issue #74672
-// @!has foo/trait.Deref.html '//*[@id="impl-Deref-for-EndianSlice"]//h3[@class="code-header in-band"]' 'impl Deref for EndianSlice'
+// @!has foo/trait.Deref.html '//*[@id="impl-Deref-for-EndianSlice"]//h3[@class="code-header"]' 'impl Deref for EndianSlice'
pub use realcore::Deref;
-// @has foo/trait.Join.html '//*[@id="impl-Join-for-Foo"]//h3[@class="code-header in-band"]' 'impl Join for Foo'
+// @has foo/trait.Join.html '//*[@id="impl-Join-for-Foo"]//h3[@class="code-header"]' 'impl Join for Foo'
pub use realcore::Join;
diff --git a/src/test/rustdoc/issue-80233-normalize-auto-trait.rs b/src/test/rustdoc/issue-80233-normalize-auto-trait.rs
index 515e617b4..62fbc2444 100644
--- a/src/test/rustdoc/issue-80233-normalize-auto-trait.rs
+++ b/src/test/rustdoc/issue-80233-normalize-auto-trait.rs
@@ -31,7 +31,7 @@ impl<T: Trait3> Trait3 for Vec<T> {
pub struct Struct1 {}
// @has issue_80233_normalize_auto_trait/struct.Question.html
-// @has - '//h3[@class="code-header in-band"]' 'impl<T> Send for Question<T>'
+// @has - '//h3[@class="code-header"]' 'impl<T> Send for Question<T>'
pub struct Question<T: Trait1> {
pub ins: <<Vec<T> as Trait3>::Type3 as Trait2>::Type2,
}
diff --git a/src/test/rustdoc/issue-82465-asref-for-and-of-local.rs b/src/test/rustdoc/issue-82465-asref-for-and-of-local.rs
index 8999e6a88..adf4d111a 100644
--- a/src/test/rustdoc/issue-82465-asref-for-and-of-local.rs
+++ b/src/test/rustdoc/issue-82465-asref-for-and-of-local.rs
@@ -1,14 +1,14 @@
use std::convert::AsRef;
pub struct Local;
-// @has issue_82465_asref_for_and_of_local/struct.Local.html '//h3[@class="code-header in-band"]' 'impl AsRef<str> for Local'
+// @has issue_82465_asref_for_and_of_local/struct.Local.html '//h3[@class="code-header"]' 'impl AsRef<str> for Local'
impl AsRef<str> for Local {
fn as_ref(&self) -> &str {
todo!()
}
}
-// @has - '//h3[@class="code-header in-band"]' 'impl AsRef<Local> for str'
+// @has - '//h3[@class="code-header"]' 'impl AsRef<Local> for str'
impl AsRef<Local> for str {
fn as_ref(&self) -> &Local {
todo!()
diff --git a/src/test/rustdoc/issue-98697.rs b/src/test/rustdoc/issue-98697.rs
index a8841f137..d50268509 100644
--- a/src/test/rustdoc/issue-98697.rs
+++ b/src/test/rustdoc/issue-98697.rs
@@ -12,6 +12,6 @@ extern crate issue_98697_reexport_with_anonymous_lifetime;
// @!has issue_98697/fn.repro.html '//pre[@class="rust fn"]/code' 'for<'
pub use issue_98697_reexport_with_anonymous_lifetime::repro;
-// @has issue_98697/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header in-band"]' 'impl MyTrait<&Extra> for Extra'
-// @!has issue_98697/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header in-band"]' 'impl<'
+// @has issue_98697/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header"]' 'impl MyTrait<&Extra> for Extra'
+// @!has issue_98697/struct.Extra.html '//div[@id="trait-implementations-list"]//h3[@class="code-header"]' 'impl<'
pub use issue_98697_reexport_with_anonymous_lifetime::Extra;
diff --git a/src/test/rustdoc/keyword.rs b/src/test/rustdoc/keyword.rs
index 1cebe4c67..ea1273850 100644
--- a/src/test/rustdoc/keyword.rs
+++ b/src/test/rustdoc/keyword.rs
@@ -7,7 +7,7 @@
// @has foo/index.html '//div[@class="sidebar-elems"]//li/a' 'Keywords'
// @has foo/index.html '//div[@class="sidebar-elems"]//li/a/@href' '#keywords'
// @has foo/keyword.match.html '//a[@class="keyword"]' 'match'
-// @has foo/keyword.match.html '//span[@class="in-band"]' 'Keyword match'
+// @has foo/keyword.match.html '//h1[@class="fqn"]' 'Keyword match'
// @has foo/keyword.match.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'this is a test!'
// @has foo/index.html '//a/@href' '../foo/index.html'
// @!has foo/foo/index.html
diff --git a/src/test/rustdoc/logo-class-default.rs b/src/test/rustdoc/logo-class-default.rs
index a7016d227..d2d439199 100644
--- a/src/test/rustdoc/logo-class-default.rs
+++ b/src/test/rustdoc/logo-class-default.rs
@@ -1,4 +1,4 @@
// Note: this test is paired with logo-class.rs.
// @has logo_class_default/struct.SomeStruct.html '//*[@class="logo-container"]/img[@class="rust-logo"]' ''
-// @has logo_class_default/struct.SomeStruct.html '//*[@class="sub-logo-container"]/img[@class="rust-logo"]' ''
+// @has src/logo_class_default/logo-class-default.rs.html '//*[@class="sub-logo-container"]/img[@class="rust-logo"]' ''
pub struct SomeStruct;
diff --git a/src/test/rustdoc/logo-class.rs b/src/test/rustdoc/logo-class.rs
index f071f356a..d3aa446da 100644
--- a/src/test/rustdoc/logo-class.rs
+++ b/src/test/rustdoc/logo-class.rs
@@ -5,6 +5,6 @@
// @has logo_class/struct.SomeStruct.html '//*[@class="logo-container"]/img[@src="https://raw.githubusercontent.com/sagebind/isahc/master/media/isahc.svg.png"]' ''
// @!has logo_class/struct.SomeStruct.html '//*[@class="logo-container"]/img[@class="rust-logo"]' ''
//
-// @has logo_class/struct.SomeStruct.html '//*[@class="sub-logo-container"]/img[@src="https://raw.githubusercontent.com/sagebind/isahc/master/media/isahc.svg.png"]' ''
-// @!has logo_class/struct.SomeStruct.html '//*[@class="sub-logo-container"]/img[@class="rust-logo"]' ''
+// @has src/logo_class/logo-class.rs.html '//*[@class="sub-logo-container"]/img[@src="https://raw.githubusercontent.com/sagebind/isahc/master/media/isahc.svg.png"]' ''
+// @!has src/logo_class/logo-class.rs.html '//*[@class="sub-logo-container"]/img[@class="rust-logo"]' ''
pub struct SomeStruct;
diff --git a/src/test/rustdoc/macro-higher-kinded-function.rs b/src/test/rustdoc/macro-higher-kinded-function.rs
index 02a430564..b8c52b7b7 100644
--- a/src/test/rustdoc/macro-higher-kinded-function.rs
+++ b/src/test/rustdoc/macro-higher-kinded-function.rs
@@ -11,8 +11,8 @@ macro_rules! gen {
}
// @has 'foo/struct.Providers.html'
-// @has - '//*[@class="docblock item-decl"]//code' "pub a: for<'tcx> fn(_: TyCtxt<'tcx>, _: u8) -> i8,"
-// @has - '//*[@class="docblock item-decl"]//code' "pub b: for<'tcx> fn(_: TyCtxt<'tcx>, _: u16) -> i16,"
+// @has - '//*[@class="item-decl"]//code' "pub a: for<'tcx> fn(_: TyCtxt<'tcx>, _: u8) -> i8,"
+// @has - '//*[@class="item-decl"]//code' "pub b: for<'tcx> fn(_: TyCtxt<'tcx>, _: u16) -> i16,"
// @has - '//*[@id="structfield.a"]/code' "a: for<'tcx> fn(_: TyCtxt<'tcx>, _: u8) -> i8"
// @has - '//*[@id="structfield.b"]/code' "b: for<'tcx> fn(_: TyCtxt<'tcx>, _: u16) -> i16"
gen! {
diff --git a/src/test/rustdoc/negative-impl-sidebar.rs b/src/test/rustdoc/negative-impl-sidebar.rs
index b995fff1f..4af6d0084 100644
--- a/src/test/rustdoc/negative-impl-sidebar.rs
+++ b/src/test/rustdoc/negative-impl-sidebar.rs
@@ -4,6 +4,6 @@
pub struct Foo;
// @has foo/struct.Foo.html
-// @has - '//*[@class="sidebar-title"]/a[@href="#trait-implementations"]' 'Trait Implementations'
+// @has - '//div[@class="sidebar-elems"]//h3/a[@href="#trait-implementations"]' 'Trait Implementations'
// @has - '//*[@class="sidebar-elems"]//section//a' '!Sync'
impl !Sync for Foo {}
diff --git a/src/test/rustdoc/negative-impl.rs b/src/test/rustdoc/negative-impl.rs
index 61a239868..af19c784d 100644
--- a/src/test/rustdoc/negative-impl.rs
+++ b/src/test/rustdoc/negative-impl.rs
@@ -5,10 +5,10 @@ pub struct Alpha;
// @matches negative_impl/struct.Bravo.html '//pre' "pub struct Bravo<B>"
pub struct Bravo<B>(B);
-// @matches negative_impl/struct.Alpha.html '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @matches negative_impl/struct.Alpha.html '//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl !Send for Alpha"
impl !Send for Alpha {}
-// @matches negative_impl/struct.Bravo.html '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' "\
+// @matches negative_impl/struct.Bravo.html '//*[@class="impl has-srclink"]//h3[@class="code-header"]' "\
// impl<B> !Send for Bravo<B>"
impl<B> !Send for Bravo<B> {}
diff --git a/src/test/rustdoc/normalize-assoc-item.rs b/src/test/rustdoc/normalize-assoc-item.rs
index ad1a868ee..db56f6852 100644
--- a/src/test/rustdoc/normalize-assoc-item.rs
+++ b/src/test/rustdoc/normalize-assoc-item.rs
@@ -11,11 +11,24 @@ impl Trait for usize {
type X = isize;
}
+impl Trait for () {
+ type X = fn() -> i32;
+}
+
+impl Trait for isize {
+ type X = <() as Trait>::X;
+}
+
// @has 'normalize_assoc_item/fn.f.html' '//pre[@class="rust fn"]' 'pub fn f() -> isize'
pub fn f() -> <usize as Trait>::X {
0
}
+// @has 'normalize_assoc_item/fn.f2.html' '//pre[@class="rust fn"]' 'pub fn f2() -> fn() -> i32'
+pub fn f2() -> <isize as Trait>::X {
+ todo!()
+}
+
pub struct S {
// @has 'normalize_assoc_item/struct.S.html' '//span[@id="structfield.box_me_up"]' 'box_me_up: Box<S, Global>'
pub box_me_up: <S as Trait>::X,
diff --git a/src/test/rustdoc/not-wf-ambiguous-normalization.rs b/src/test/rustdoc/not-wf-ambiguous-normalization.rs
new file mode 100644
index 000000000..1e9f925f8
--- /dev/null
+++ b/src/test/rustdoc/not-wf-ambiguous-normalization.rs
@@ -0,0 +1,24 @@
+// compile-flags: -Znormalize-docs
+
+#![feature(type_alias_impl_trait)]
+
+trait Allocator {
+ type Buffer;
+}
+
+struct DefaultAllocator;
+
+// This unconstrained impl parameter causes the normalization of
+// `<DefaultAllocator as Allocator>::Buffer` to be ambiguous,
+// which caused an ICE with `-Znormalize-docs`.
+impl<T> Allocator for DefaultAllocator {
+ type Buffer = ();
+}
+
+type A = impl Fn(<DefaultAllocator as Allocator>::Buffer);
+
+fn foo() -> A {
+ |_| ()
+}
+
+fn main() {}
diff --git a/src/test/rustdoc/primitive-reference.rs b/src/test/rustdoc/primitive-reference.rs
index 5c1193406..ea8d2d166 100644
--- a/src/test/rustdoc/primitive-reference.rs
+++ b/src/test/rustdoc/primitive-reference.rs
@@ -9,12 +9,12 @@
// @has - '//div[@class="sidebar-elems"]//li/a/@href' '#primitives'
// @has foo/primitive.reference.html
// @has - '//a[@class="primitive"]' 'reference'
-// @has - '//span[@class="in-band"]' 'Primitive Type reference'
+// @has - '//h1[@class="fqn"]' 'Primitive Type reference'
// @has - '//section[@id="main-content"]//div[@class="docblock"]//p' 'this is a test!'
// There should be only one implementation listed.
// @count - '//*[@class="impl has-srclink"]' 1
-// @has - '//*[@id="impl-Foo%3C%26A%3E-for-%26B"]/*[@class="code-header in-band"]' \
+// @has - '//*[@id="impl-Foo%3C%26A%3E-for-%26B"]/*[@class="code-header"]' \
// 'impl<A, B> Foo<&A> for &B'
#[doc(primitive = "reference")]
/// this is a test!
diff --git a/src/test/rustdoc/primitive-slice-auto-trait.rs b/src/test/rustdoc/primitive-slice-auto-trait.rs
index 7f8f74ff4..cdddd6b65 100644
--- a/src/test/rustdoc/primitive-slice-auto-trait.rs
+++ b/src/test/rustdoc/primitive-slice-auto-trait.rs
@@ -4,7 +4,7 @@
#![feature(rustdoc_internals)]
// @has foo/primitive.slice.html '//a[@class="primitive"]' 'slice'
-// @has - '//span[@class="in-band"]' 'Primitive Type slice'
+// @has - '//h1[@class="fqn"]' 'Primitive Type slice'
// @has - '//section[@id="main-content"]//div[@class="docblock"]//p' 'this is a test!'
// @has - '//h2[@id="synthetic-implementations"]' 'Auto Trait Implementations'
// @has - '//div[@id="synthetic-implementations-list"]//h3' 'impl<T> Send for [T]where T: Send'
diff --git a/src/test/rustdoc/primitive-tuple-auto-trait.rs b/src/test/rustdoc/primitive-tuple-auto-trait.rs
index a2fbbf078..df681457f 100644
--- a/src/test/rustdoc/primitive-tuple-auto-trait.rs
+++ b/src/test/rustdoc/primitive-tuple-auto-trait.rs
@@ -4,7 +4,7 @@
#![feature(rustdoc_internals)]
// @has foo/primitive.tuple.html '//a[@class="primitive"]' 'tuple'
-// @has - '//span[@class="in-band"]' 'Primitive Type tuple'
+// @has - '//h1[@class="fqn"]' 'Primitive Type tuple'
// @has - '//section[@id="main-content"]//div[@class="docblock"]//p' 'this is a test!'
// @has - '//h2[@id="synthetic-implementations"]' 'Auto Trait Implementations'
// @has - '//div[@id="synthetic-implementations-list"]//h3' 'Send'
diff --git a/src/test/rustdoc/primitive-unit-auto-trait.rs b/src/test/rustdoc/primitive-unit-auto-trait.rs
index 76182622e..391e33bea 100644
--- a/src/test/rustdoc/primitive-unit-auto-trait.rs
+++ b/src/test/rustdoc/primitive-unit-auto-trait.rs
@@ -4,7 +4,7 @@
#![feature(rustdoc_internals)]
// @has foo/primitive.unit.html '//a[@class="primitive"]' 'unit'
-// @has - '//span[@class="in-band"]' 'Primitive Type unit'
+// @has - '//h1[@class="fqn"]' 'Primitive Type unit'
// @has - '//section[@id="main-content"]//div[@class="docblock"]//p' 'this is a test!'
// @has - '//h2[@id="synthetic-implementations"]' 'Auto Trait Implementations'
// @has - '//div[@id="synthetic-implementations-list"]//h3' 'impl Send for ()'
diff --git a/src/test/rustdoc/primitive.rs b/src/test/rustdoc/primitive.rs
index 605ca4d17..6347fdac3 100644
--- a/src/test/rustdoc/primitive.rs
+++ b/src/test/rustdoc/primitive.rs
@@ -7,7 +7,7 @@
// @has foo/index.html '//div[@class="sidebar-elems"]//li/a' 'Primitive Types'
// @has foo/index.html '//div[@class="sidebar-elems"]//li/a/@href' '#primitives'
// @has foo/primitive.i32.html '//a[@class="primitive"]' 'i32'
-// @has foo/primitive.i32.html '//span[@class="in-band"]' 'Primitive Type i32'
+// @has foo/primitive.i32.html '//h1[@class="fqn"]' 'Primitive Type i32'
// @has foo/primitive.i32.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'this is a test!'
// @has foo/index.html '//a/@href' '../foo/index.html'
// @!has foo/index.html '//span' '🔒'
diff --git a/src/test/rustdoc/primitive/primitive-generic-impl.rs b/src/test/rustdoc/primitive/primitive-generic-impl.rs
index eebb2cf5a..7b336b398 100644
--- a/src/test/rustdoc/primitive/primitive-generic-impl.rs
+++ b/src/test/rustdoc/primitive/primitive-generic-impl.rs
@@ -1,7 +1,7 @@
#![feature(rustdoc_internals)]
#![crate_name = "foo"]
-// @has foo/primitive.i32.html '//*[@id="impl-ToString-for-i32"]//h3[@class="code-header in-band"]' 'impl<T> ToString for T'
+// @has foo/primitive.i32.html '//*[@id="impl-ToString-for-i32"]//h3[@class="code-header"]' 'impl<T> ToString for T'
#[doc(primitive = "i32")]
/// Some useless docs, wouhou!
diff --git a/src/test/rustdoc/recursive-deref.rs b/src/test/rustdoc/recursive-deref.rs
index 2ab9d44be..aa38485c4 100644
--- a/src/test/rustdoc/recursive-deref.rs
+++ b/src/test/rustdoc/recursive-deref.rs
@@ -9,7 +9,7 @@ impl C {
pub fn c(&self) {}
}
-// @has recursive_deref/struct.A.html '//h3[@class="code-header in-band"]' 'impl Deref for A'
+// @has recursive_deref/struct.A.html '//h3[@class="code-header"]' 'impl Deref for A'
// @has '-' '//*[@class="impl-items"]//*[@id="method.c"]' 'pub fn c(&self)'
impl Deref for A {
type Target = B;
@@ -19,7 +19,7 @@ impl Deref for A {
}
}
-// @has recursive_deref/struct.B.html '//h3[@class="code-header in-band"]' 'impl Deref for B'
+// @has recursive_deref/struct.B.html '//h3[@class="code-header"]' 'impl Deref for B'
// @has '-' '//*[@class="impl-items"]//*[@id="method.c"]' 'pub fn c(&self)'
impl Deref for B {
type Target = C;
@@ -29,7 +29,7 @@ impl Deref for B {
}
}
-// @has recursive_deref/struct.C.html '//h3[@class="code-header in-band"]' 'impl Deref for C'
+// @has recursive_deref/struct.C.html '//h3[@class="code-header"]' 'impl Deref for C'
impl Deref for C {
type Target = B;
@@ -49,7 +49,7 @@ impl G {
pub fn g() {}
}
-// @has recursive_deref/struct.D.html '//h3[@class="code-header in-band"]' 'impl Deref for D'
+// @has recursive_deref/struct.D.html '//h3[@class="code-header"]' 'impl Deref for D'
// We also check that `G::g` method isn't rendered because there is no `self` argument.
// @!has '-' '//*[@id="deref-methods-G"]' ''
impl Deref for D {
@@ -60,7 +60,7 @@ impl Deref for D {
}
}
-// @has recursive_deref/struct.E.html '//h3[@class="code-header in-band"]' 'impl Deref for E'
+// @has recursive_deref/struct.E.html '//h3[@class="code-header"]' 'impl Deref for E'
// We also check that `G::g` method isn't rendered because there is no `self` argument.
// @!has '-' '//*[@id="deref-methods-G"]' ''
impl Deref for E {
@@ -71,7 +71,7 @@ impl Deref for E {
}
}
-// @has recursive_deref/struct.F.html '//h3[@class="code-header in-band"]' 'impl Deref for F'
+// @has recursive_deref/struct.F.html '//h3[@class="code-header"]' 'impl Deref for F'
// We also check that `G::g` method isn't rendered because there is no `self` argument.
// @!has '-' '//*[@id="deref-methods-G"]' ''
impl Deref for F {
@@ -82,7 +82,7 @@ impl Deref for F {
}
}
-// @has recursive_deref/struct.G.html '//h3[@class="code-header in-band"]' 'impl Deref for G'
+// @has recursive_deref/struct.G.html '//h3[@class="code-header"]' 'impl Deref for G'
impl Deref for G {
type Target = E;
@@ -100,7 +100,7 @@ impl I {
pub fn i() {}
}
-// @has recursive_deref/struct.H.html '//h3[@class="code-header in-band"]' 'impl Deref for H'
+// @has recursive_deref/struct.H.html '//h3[@class="code-header"]' 'impl Deref for H'
// @!has '-' '//*[@id="deref-methods-I"]' ''
impl Deref for H {
type Target = I;
@@ -110,7 +110,7 @@ impl Deref for H {
}
}
-// @has recursive_deref/struct.I.html '//h3[@class="code-header in-band"]' 'impl Deref for I'
+// @has recursive_deref/struct.I.html '//h3[@class="code-header"]' 'impl Deref for I'
impl Deref for I {
type Target = H;
diff --git a/src/test/rustdoc/reexport-dep-foreign-fn.rs b/src/test/rustdoc/reexport-dep-foreign-fn.rs
index 6e1dc4539..6694c91d1 100644
--- a/src/test/rustdoc/reexport-dep-foreign-fn.rs
+++ b/src/test/rustdoc/reexport-dep-foreign-fn.rs
@@ -8,5 +8,5 @@
extern crate all_item_types;
// @has 'foo/fn.foo_ffn.html'
-// @has - '//*[@class="docblock item-decl"]//code' 'pub unsafe extern "C" fn foo_ffn()'
+// @has - '//*[@class="item-decl"]//code' 'pub unsafe extern "C" fn foo_ffn()'
pub use all_item_types::foo_ffn;
diff --git a/src/test/rustdoc/reexport-doc.rs b/src/test/rustdoc/reexport-doc.rs
new file mode 100644
index 000000000..df2c889b4
--- /dev/null
+++ b/src/test/rustdoc/reexport-doc.rs
@@ -0,0 +1,8 @@
+// aux-build:reexport-doc-aux.rs
+
+extern crate reexport_doc_aux as dep;
+
+// @has 'reexport_doc/struct.Foo.html'
+// @count - '//p' 'These are the docs for Foo.' 1
+/// These are the docs for Foo.
+pub use dep::Foo;
diff --git a/src/test/rustdoc/reexports-priv.rs b/src/test/rustdoc/reexports-priv.rs
index aea9b9f2b..11364e7f7 100644
--- a/src/test/rustdoc/reexports-priv.rs
+++ b/src/test/rustdoc/reexports-priv.rs
@@ -5,7 +5,7 @@
extern crate reexports;
-// @has 'foo/macro.addr_of.html' '//*[@class="docblock item-decl"]' 'pub macro addr_of($place:expr) {'
+// @has 'foo/macro.addr_of.html' '//*[@class="item-decl"]' 'pub macro addr_of($place:expr) {'
pub use reexports::addr_of;
// @!has 'foo/macro.addr_of_crate.html'
pub(crate) use reexports::addr_of_crate;
@@ -14,7 +14,7 @@ pub(self) use reexports::addr_of_self;
// @!has 'foo/macro.addr_of_local.html'
use reexports::addr_of_local;
-// @has 'foo/struct.Foo.html' '//*[@class="docblock item-decl"]' 'pub struct Foo;'
+// @has 'foo/struct.Foo.html' '//*[@class="item-decl"]' 'pub struct Foo;'
pub use reexports::Foo;
// @!has 'foo/struct.FooCrate.html'
pub(crate) use reexports::FooCrate;
@@ -23,7 +23,7 @@ pub(self) use reexports::FooSelf;
// @!has 'foo/struct.FooLocal.html'
use reexports::FooLocal;
-// @has 'foo/enum.Bar.html' '//*[@class="docblock item-decl"]' 'pub enum Bar {'
+// @has 'foo/enum.Bar.html' '//*[@class="item-decl"]' 'pub enum Bar {'
pub use reexports::Bar;
// @!has 'foo/enum.BarCrate.html'
pub(crate) use reexports::BarCrate;
@@ -50,7 +50,7 @@ pub(self) use reexports::TypeSelf;
// @!has 'foo/type.TypeLocal.html'
use reexports::TypeLocal;
-// @has 'foo/union.Union.html' '//*[@class="docblock item-decl"]' 'pub union Union {'
+// @has 'foo/union.Union.html' '//*[@class="item-decl"]' 'pub union Union {'
pub use reexports::Union;
// @!has 'foo/union.UnionCrate.html'
pub(crate) use reexports::UnionCrate;
@@ -61,33 +61,33 @@ use reexports::UnionLocal;
pub mod outer {
pub mod inner {
- // @has 'foo/outer/inner/macro.addr_of.html' '//*[@class="docblock item-decl"]' 'pub macro addr_of($place:expr) {'
+ // @has 'foo/outer/inner/macro.addr_of.html' '//*[@class="item-decl"]' 'pub macro addr_of($place:expr) {'
pub use reexports::addr_of;
- // @has 'foo/outer/inner/macro.addr_of_crate.html' '//*[@class="docblock item-decl"]' 'pub(crate) macro addr_of_crate($place:expr) {'
+ // @has 'foo/outer/inner/macro.addr_of_crate.html' '//*[@class="item-decl"]' 'pub(crate) macro addr_of_crate($place:expr) {'
pub(crate) use reexports::addr_of_crate;
- // @has 'foo/outer/inner/macro.addr_of_super.html' '//*[@class="docblock item-decl"]' 'pub(in outer) macro addr_of_super($place:expr) {'
+ // @has 'foo/outer/inner/macro.addr_of_super.html' '//*[@class="item-decl"]' 'pub(in outer) macro addr_of_super($place:expr) {'
pub(super) use reexports::addr_of_super;
// @!has 'foo/outer/inner/macro.addr_of_self.html'
pub(self) use reexports::addr_of_self;
// @!has 'foo/outer/inner/macro.addr_of_local.html'
use reexports::addr_of_local;
- // @has 'foo/outer/inner/struct.Foo.html' '//*[@class="docblock item-decl"]' 'pub struct Foo;'
+ // @has 'foo/outer/inner/struct.Foo.html' '//*[@class="item-decl"]' 'pub struct Foo;'
pub use reexports::Foo;
- // @has 'foo/outer/inner/struct.FooCrate.html' '//*[@class="docblock item-decl"]' 'pub(crate) struct FooCrate;'
+ // @has 'foo/outer/inner/struct.FooCrate.html' '//*[@class="item-decl"]' 'pub(crate) struct FooCrate;'
pub(crate) use reexports::FooCrate;
- // @has 'foo/outer/inner/struct.FooSuper.html' '//*[@class="docblock item-decl"]' 'pub(in outer) struct FooSuper;'
+ // @has 'foo/outer/inner/struct.FooSuper.html' '//*[@class="item-decl"]' 'pub(in outer) struct FooSuper;'
pub(super) use reexports::FooSuper;
// @!has 'foo/outer/inner/struct.FooSelf.html'
pub(self) use reexports::FooSelf;
// @!has 'foo/outer/inner/struct.FooLocal.html'
use reexports::FooLocal;
- // @has 'foo/outer/inner/enum.Bar.html' '//*[@class="docblock item-decl"]' 'pub enum Bar {'
+ // @has 'foo/outer/inner/enum.Bar.html' '//*[@class="item-decl"]' 'pub enum Bar {'
pub use reexports::Bar;
- // @has 'foo/outer/inner/enum.BarCrate.html' '//*[@class="docblock item-decl"]' 'pub(crate) enum BarCrate {'
+ // @has 'foo/outer/inner/enum.BarCrate.html' '//*[@class="item-decl"]' 'pub(crate) enum BarCrate {'
pub(crate) use reexports::BarCrate;
- // @has 'foo/outer/inner/enum.BarSuper.html' '//*[@class="docblock item-decl"]' 'pub(in outer) enum BarSuper {'
+ // @has 'foo/outer/inner/enum.BarSuper.html' '//*[@class="item-decl"]' 'pub(in outer) enum BarSuper {'
pub(super) use reexports::BarSuper;
// @!has 'foo/outer/inner/enum.BarSelf.html'
pub(self) use reexports::BarSelf;
@@ -116,11 +116,11 @@ pub mod outer {
// @!has 'foo/outer/inner/type.TypeLocal.html'
use reexports::TypeLocal;
- // @has 'foo/outer/inner/union.Union.html' '//*[@class="docblock item-decl"]' 'pub union Union {'
+ // @has 'foo/outer/inner/union.Union.html' '//*[@class="item-decl"]' 'pub union Union {'
pub use reexports::Union;
- // @has 'foo/outer/inner/union.UnionCrate.html' '//*[@class="docblock item-decl"]' 'pub(crate) union UnionCrate {'
+ // @has 'foo/outer/inner/union.UnionCrate.html' '//*[@class="item-decl"]' 'pub(crate) union UnionCrate {'
pub(crate) use reexports::UnionCrate;
- // @has 'foo/outer/inner/union.UnionSuper.html' '//*[@class="docblock item-decl"]' 'pub(in outer) union UnionSuper {'
+ // @has 'foo/outer/inner/union.UnionSuper.html' '//*[@class="item-decl"]' 'pub(in outer) union UnionSuper {'
pub(super) use reexports::UnionSuper;
// @!has 'foo/outer/inner/union.UnionSelf.html'
pub(self) use reexports::UnionSelf;
diff --git a/src/test/rustdoc/reexports.rs b/src/test/rustdoc/reexports.rs
index 7abcbfb61..9aa6d7224 100644
--- a/src/test/rustdoc/reexports.rs
+++ b/src/test/rustdoc/reexports.rs
@@ -4,7 +4,7 @@
extern crate reexports;
-// @has 'foo/macro.addr_of.html' '//*[@class="docblock item-decl"]' 'pub macro addr_of($place:expr) {'
+// @has 'foo/macro.addr_of.html' '//*[@class="item-decl"]' 'pub macro addr_of($place:expr) {'
pub use reexports::addr_of;
// @!has 'foo/macro.addr_of_crate.html'
pub(crate) use reexports::addr_of_crate;
@@ -13,7 +13,7 @@ pub(self) use reexports::addr_of_self;
// @!has 'foo/macro.addr_of_local.html'
use reexports::addr_of_local;
-// @has 'foo/struct.Foo.html' '//*[@class="docblock item-decl"]' 'pub struct Foo;'
+// @has 'foo/struct.Foo.html' '//*[@class="item-decl"]' 'pub struct Foo;'
pub use reexports::Foo;
// @!has 'foo/struct.FooCrate.html'
pub(crate) use reexports::FooCrate;
@@ -22,7 +22,7 @@ pub(self) use reexports::FooSelf;
// @!has 'foo/struct.FooLocal.html'
use reexports::FooLocal;
-// @has 'foo/enum.Bar.html' '//*[@class="docblock item-decl"]' 'pub enum Bar {'
+// @has 'foo/enum.Bar.html' '//*[@class="item-decl"]' 'pub enum Bar {'
pub use reexports::Bar;
// @!has 'foo/enum.BarCrate.html'
pub(crate) use reexports::BarCrate;
@@ -49,7 +49,7 @@ pub(self) use reexports::TypeSelf;
// @!has 'foo/type.TypeLocal.html'
use reexports::TypeLocal;
-// @has 'foo/union.Union.html' '//*[@class="docblock item-decl"]' 'pub union Union {'
+// @has 'foo/union.Union.html' '//*[@class="item-decl"]' 'pub union Union {'
pub use reexports::Union;
// @!has 'foo/union.UnionCrate.html'
pub(crate) use reexports::UnionCrate;
@@ -60,7 +60,7 @@ use reexports::UnionLocal;
pub mod outer {
pub mod inner {
- // @has 'foo/outer/inner/macro.addr_of.html' '//*[@class="docblock item-decl"]' 'pub macro addr_of($place:expr) {'
+ // @has 'foo/outer/inner/macro.addr_of.html' '//*[@class="item-decl"]' 'pub macro addr_of($place:expr) {'
pub use reexports::addr_of;
// @!has 'foo/outer/inner/macro.addr_of_crate.html'
pub(crate) use reexports::addr_of_crate;
@@ -71,7 +71,7 @@ pub mod outer {
// @!has 'foo/outer/inner/macro.addr_of_local.html'
use reexports::addr_of_local;
- // @has 'foo/outer/inner/struct.Foo.html' '//*[@class="docblock item-decl"]' 'pub struct Foo;'
+ // @has 'foo/outer/inner/struct.Foo.html' '//*[@class="item-decl"]' 'pub struct Foo;'
pub use reexports::Foo;
// @!has 'foo/outer/inner/struct.FooCrate.html'
pub(crate) use reexports::FooCrate;
@@ -82,7 +82,7 @@ pub mod outer {
// @!has 'foo/outer/inner/struct.FooLocal.html'
use reexports::FooLocal;
- // @has 'foo/outer/inner/enum.Bar.html' '//*[@class="docblock item-decl"]' 'pub enum Bar {'
+ // @has 'foo/outer/inner/enum.Bar.html' '//*[@class="item-decl"]' 'pub enum Bar {'
pub use reexports::Bar;
// @!has 'foo/outer/inner/enum.BarCrate.html'
pub(crate) use reexports::BarCrate;
@@ -115,7 +115,7 @@ pub mod outer {
// @!has 'foo/outer/inner/type.TypeLocal.html'
use reexports::TypeLocal;
- // @has 'foo/outer/inner/union.Union.html' '//*[@class="docblock item-decl"]' 'pub union Union {'
+ // @has 'foo/outer/inner/union.Union.html' '//*[@class="item-decl"]' 'pub union Union {'
pub use reexports::Union;
// @!has 'foo/outer/inner/union.UnionCrate.html'
pub(crate) use reexports::UnionCrate;
diff --git a/src/test/rustdoc/rfc-2632-const-trait-impl.rs b/src/test/rustdoc/rfc-2632-const-trait-impl.rs
index f3e211e30..602ee1b1b 100644
--- a/src/test/rustdoc/rfc-2632-const-trait-impl.rs
+++ b/src/test/rustdoc/rfc-2632-const-trait-impl.rs
@@ -18,10 +18,10 @@ pub struct S<T>(T);
// @has - '//pre[@class="rust trait"]/code/span[@class="where"]' ': Clone'
#[const_trait]
pub trait Tr<T> {
- // @!has - '//div[@id="method.a"]/h4[@class="code-header"]' '~const'
- // @has - '//div[@id="method.a"]/h4[@class="code-header"]/a[@class="trait"]' 'Clone'
- // @!has - '//div[@id="method.a"]/h4[@class="code-header"]/span[@class="where"]' '~const'
- // @has - '//div[@id="method.a"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone'
+ // @!has - '//section[@id="method.a"]/h4[@class="code-header"]' '~const'
+ // @has - '//section[@id="method.a"]/h4[@class="code-header"]/a[@class="trait"]' 'Clone'
+ // @!has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where"]' '~const'
+ // @has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone'
fn a<A: ~const Clone + ~const Destruct>()
where
Option<A>: ~const Clone + ~const Destruct,
@@ -30,10 +30,10 @@ pub trait Tr<T> {
}
// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]' ''
-// @!has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header in-band"]' '~const'
-// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header in-band"]/a[@class="trait"]' 'Clone'
-// @!has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header in-band"]/span[@class="where"]' '~const'
-// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header in-band"]/span[@class="where fmt-newline"]' ': Clone'
+// @!has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]' '~const'
+// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/a[@class="trait"]' 'Clone'
+// @!has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/span[@class="where"]' '~const'
+// @has - '//section[@id="impl-Tr%3CT%3E-for-T"]/h3[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone'
impl<T: ~const Clone + ~const Destruct> const Tr<T> for T
where
Option<T>: ~const Clone + ~const Destruct,
diff --git a/src/test/rustdoc/safe-intrinsic.rs b/src/test/rustdoc/safe-intrinsic.rs
index d3bb8514b..d08abdaeb 100644
--- a/src/test/rustdoc/safe-intrinsic.rs
+++ b/src/test/rustdoc/safe-intrinsic.rs
@@ -1,5 +1,6 @@
#![feature(intrinsics)]
#![feature(no_core)]
+#![feature(rustc_attrs)]
#![no_core]
#![crate_name = "foo"]
@@ -7,6 +8,7 @@
extern "rust-intrinsic" {
// @has 'foo/fn.abort.html'
// @has - '//pre[@class="rust fn"]' 'pub extern "rust-intrinsic" fn abort() -> !'
+ #[rustc_safe_intrinsic]
pub fn abort() -> !;
// @has 'foo/fn.unreachable.html'
// @has - '//pre[@class="rust fn"]' 'pub unsafe extern "rust-intrinsic" fn unreachable() -> !'
diff --git a/src/test/rustdoc/sidebar-all-page.rs b/src/test/rustdoc/sidebar-all-page.rs
new file mode 100644
index 000000000..e74b981de
--- /dev/null
+++ b/src/test/rustdoc/sidebar-all-page.rs
@@ -0,0 +1,35 @@
+#![crate_name = "foo"]
+
+#![feature(rustdoc_internals)]
+
+// @has 'foo/all.html'
+// @has - '//*[@class="sidebar-elems"]//li' 'Structs'
+// @has - '//*[@class="sidebar-elems"]//li' 'Enums'
+// @has - '//*[@class="sidebar-elems"]//li' 'Unions'
+// @has - '//*[@class="sidebar-elems"]//li' 'Functions'
+// @has - '//*[@class="sidebar-elems"]//li' 'Traits'
+// @has - '//*[@class="sidebar-elems"]//li' 'Macros'
+// @has - '//*[@class="sidebar-elems"]//li' 'Type Definitions'
+// @has - '//*[@class="sidebar-elems"]//li' 'Constants'
+// @has - '//*[@class="sidebar-elems"]//li' 'Statics'
+// @has - '//*[@class="sidebar-elems"]//li' 'Primitive Types'
+
+pub struct Foo;
+pub enum Enum {
+ A,
+}
+pub union Bar {
+ a: u8,
+ b: u16,
+}
+pub fn foo() {}
+pub trait Trait {}
+#[macro_export]
+macro_rules! foo {
+ () => {}
+}
+pub type Type = u8;
+pub const FOO: u8 = 0;
+pub static BAR: u8 = 0;
+#[doc(primitive = "u8")]
+mod u8 {}
diff --git a/src/test/rustdoc/sidebar-items.rs b/src/test/rustdoc/sidebar-items.rs
index b5b681ab0..6f7afa59b 100644
--- a/src/test/rustdoc/sidebar-items.rs
+++ b/src/test/rustdoc/sidebar-items.rs
@@ -2,17 +2,17 @@
#![crate_name = "foo"]
// @has foo/trait.Foo.html
-// @has - '//*[@class="sidebar-title"]/a[@href="#required-methods"]' 'Required Methods'
+// @has - '//div[@class="sidebar-elems"]//h3/a[@href="#required-methods"]' 'Required Methods'
// @has - '//*[@class="sidebar-elems"]//section//a' 'bar'
-// @has - '//*[@class="sidebar-title"]/a[@href="#provided-methods"]' 'Provided Methods'
+// @has - '//div[@class="sidebar-elems"]//h3/a[@href="#provided-methods"]' 'Provided Methods'
// @has - '//*[@class="sidebar-elems"]//section//a' 'foo'
-// @has - '//*[@class="sidebar-title"]/a[@href="#required-associated-consts"]' 'Required Associated Constants'
+// @has - '//div[@class="sidebar-elems"]//h3/a[@href="#required-associated-consts"]' 'Required Associated Constants'
// @has - '//*[@class="sidebar-elems"]//section//a' 'FOO'
-// @has - '//*[@class="sidebar-title"]/a[@href="#provided-associated-consts"]' 'Provided Associated Constants'
+// @has - '//div[@class="sidebar-elems"]//h3/a[@href="#provided-associated-consts"]' 'Provided Associated Constants'
// @has - '//*[@class="sidebar-elems"]//section//a' 'BAR'
-// @has - '//*[@class="sidebar-title"]/a[@href="#required-associated-types"]' 'Required Associated Types'
+// @has - '//div[@class="sidebar-elems"]//h3/a[@href="#required-associated-types"]' 'Required Associated Types'
// @has - '//*[@class="sidebar-elems"]//section//a' 'Output'
-// @has - '//*[@class="sidebar-title"]/a[@href="#provided-associated-types"]' 'Provided Associated Types'
+// @has - '//div[@class="sidebar-elems"]//h3/a[@href="#provided-associated-types"]' 'Provided Associated Types'
// @has - '//*[@class="sidebar-elems"]//section//a' 'Extra'
pub trait Foo {
const FOO: usize;
@@ -25,7 +25,7 @@ pub trait Foo {
}
// @has foo/struct.Bar.html
-// @has - '//*[@class="sidebar-title"]/a[@href="#fields"]' 'Fields'
+// @has - '//div[@class="sidebar-elems"]//h3/a[@href="#fields"]' 'Fields'
// @has - '//*[@class="sidebar-elems"]//section//a[@href="#structfield.f"]' 'f'
// @has - '//*[@class="sidebar-elems"]//section//a[@href="#structfield.u"]' 'u'
// @!has - '//*[@class="sidebar-elems"]//section//a' 'waza'
@@ -36,7 +36,7 @@ pub struct Bar {
}
// @has foo/enum.En.html
-// @has - '//*[@class="sidebar-title"]/a[@href="#variants"]' 'Variants'
+// @has - '//div[@class="sidebar-elems"]//h3/a[@href="#variants"]' 'Variants'
// @has - '//*[@class="sidebar-elems"]//section//a' 'Foo'
// @has - '//*[@class="sidebar-elems"]//section//a' 'Bar'
pub enum En {
@@ -45,7 +45,7 @@ pub enum En {
}
// @has foo/union.MyUnion.html
-// @has - '//*[@class="sidebar-title"]/a[@href="#fields"]' 'Fields'
+// @has - '//div[@class="sidebar-elems"]//h3/a[@href="#fields"]' 'Fields'
// @has - '//*[@class="sidebar-elems"]//section//a[@href="#structfield.f1"]' 'f1'
// @has - '//*[@class="sidebar-elems"]//section//a[@href="#structfield.f2"]' 'f2'
// @!has - '//*[@class="sidebar-elems"]//section//a' 'waza'
diff --git a/src/test/rustdoc/sidebar-links-to-foreign-impl.rs b/src/test/rustdoc/sidebar-links-to-foreign-impl.rs
index 155150396..11e946948 100644
--- a/src/test/rustdoc/sidebar-links-to-foreign-impl.rs
+++ b/src/test/rustdoc/sidebar-links-to-foreign-impl.rs
@@ -3,12 +3,12 @@
#![crate_name = "foo"]
// @has foo/trait.Foo.html
-// @has - '//*[@class="sidebar-title"]/a[@href="#foreign-impls"]' 'Implementations on Foreign Types'
+// @has - '//div[@class="sidebar-elems"]//h3/a[@href="#foreign-impls"]' 'Implementations on Foreign Types'
// @has - '//h2[@id="foreign-impls"]' 'Implementations on Foreign Types'
// @has - '//*[@class="sidebar-elems"]//section//a[@href="#impl-Foo-for-u32"]' 'u32'
-// @has - '//*[@id="impl-Foo-for-u32"]//h3[@class="code-header in-band"]' 'impl Foo for u32'
+// @has - '//*[@id="impl-Foo-for-u32"]//h3[@class="code-header"]' 'impl Foo for u32'
// @has - '//*[@class="sidebar-elems"]//section//a[@href="#impl-Foo-for-%26%27a%20str"]' "&'a str"
-// @has - '//*[@id="impl-Foo-for-%26%27a%20str"]//h3[@class="code-header in-band"]' "impl<'a> Foo for &'a str"
+// @has - '//*[@id="impl-Foo-for-%26%27a%20str"]//h3[@class="code-header"]' "impl<'a> Foo for &'a str"
pub trait Foo {}
impl Foo for u32 {}
diff --git a/src/test/rustdoc/sized_trait.rs b/src/test/rustdoc/sized_trait.rs
index 36718ebe1..feef4de8d 100644
--- a/src/test/rustdoc/sized_trait.rs
+++ b/src/test/rustdoc/sized_trait.rs
@@ -11,7 +11,7 @@ pub struct Bar {
pub struct Foo<T: ?Sized>(T);
// @has foo/struct.Unsized.html
-// @has - '//*[@id="impl-Sized-for-Unsized"]//h3[@class="code-header in-band"]' 'impl !Sized for Unsized'
+// @has - '//*[@id="impl-Sized-for-Unsized"]//h3[@class="code-header"]' 'impl !Sized for Unsized'
pub struct Unsized {
data: [u8],
}
diff --git a/src/test/rustdoc/src-links-auto-impls.rs b/src/test/rustdoc/src-links-auto-impls.rs
index 313a4b118..953563833 100644
--- a/src/test/rustdoc/src-links-auto-impls.rs
+++ b/src/test/rustdoc/src-links-auto-impls.rs
@@ -1,11 +1,11 @@
#![crate_name = "foo"]
// @has foo/struct.Unsized.html
-// @has - '//*[@id="impl-Sized-for-Unsized"]/h3[@class="code-header in-band"]' 'impl !Sized for Unsized'
+// @has - '//*[@id="impl-Sized-for-Unsized"]/h3[@class="code-header"]' 'impl !Sized for Unsized'
// @!has - '//*[@id="impl-Sized-for-Unsized"]//a[@class="srclink"]' 'source'
-// @has - '//*[@id="impl-Sync-for-Unsized"]/h3[@class="code-header in-band"]' 'impl Sync for Unsized'
+// @has - '//*[@id="impl-Sync-for-Unsized"]/h3[@class="code-header"]' 'impl Sync for Unsized'
// @!has - '//*[@id="impl-Sync-for-Unsized"]//a[@class="srclink"]' 'source'
-// @has - '//*[@id="impl-Any-for-Unsized"]/h3[@class="code-header in-band"]' 'impl<T> Any for T'
+// @has - '//*[@id="impl-Any-for-Unsized"]/h3[@class="code-header"]' 'impl<T> Any for T'
// @has - '//*[@id="impl-Any-for-Unsized"]//a[@class="srclink rightside"]' 'source'
pub struct Unsized {
data: [u8],
diff --git a/src/test/rustdoc/strip-enum-variant.no-not-shown.html b/src/test/rustdoc/strip-enum-variant.no-not-shown.html
index c4ee1a991..782198956 100644
--- a/src/test/rustdoc/strip-enum-variant.no-not-shown.html
+++ b/src/test/rustdoc/strip-enum-variant.no-not-shown.html
@@ -1 +1 @@
-<ul><li><a href="#variant.Shown">Shown</a></li></ul> \ No newline at end of file
+<ul class="block"><li><a href="#variant.Shown">Shown</a></li></ul> \ No newline at end of file
diff --git a/src/test/rustdoc/strip-enum-variant.rs b/src/test/rustdoc/strip-enum-variant.rs
index f82ffdfed..8753a7dc6 100644
--- a/src/test/rustdoc/strip-enum-variant.rs
+++ b/src/test/rustdoc/strip-enum-variant.rs
@@ -3,7 +3,7 @@
// @!has - '//code' 'NotShown'
// @has - '//code' '// some variants omitted'
// Also check that `NotShown` isn't displayed in the sidebar.
-// @snapshot no-not-shown - '//*[@class="sidebar-elems"]/section/*[@class="block"][1]/ul'
+// @snapshot no-not-shown - '//*[@class="sidebar-elems"]/section/*[@class="block"][1]'
pub enum MyThing {
Shown,
#[doc(hidden)]
diff --git a/src/test/rustdoc/synthetic_auto/basic.rs b/src/test/rustdoc/synthetic_auto/basic.rs
index 19138fd1a..7c6a38865 100644
--- a/src/test/rustdoc/synthetic_auto/basic.rs
+++ b/src/test/rustdoc/synthetic_auto/basic.rs
@@ -1,6 +1,6 @@
// @has basic/struct.Foo.html
-// @has - '//h3[@class="code-header in-band"]' 'impl<T> Send for Foo<T>where T: Send'
-// @has - '//h3[@class="code-header in-band"]' 'impl<T> Sync for Foo<T>where T: Sync'
+// @has - '//h3[@class="code-header"]' 'impl<T> Send for Foo<T>where T: Send'
+// @has - '//h3[@class="code-header"]' 'impl<T> Sync for Foo<T>where T: Sync'
// @count - '//*[@id="implementations-list"]//*[@class="impl has-srclink"]' 0
// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]' 5
pub struct Foo<T> {
diff --git a/src/test/rustdoc/synthetic_auto/complex.rs b/src/test/rustdoc/synthetic_auto/complex.rs
index 39f78983d..43393c21f 100644
--- a/src/test/rustdoc/synthetic_auto/complex.rs
+++ b/src/test/rustdoc/synthetic_auto/complex.rs
@@ -20,7 +20,7 @@ mod foo {
}
// @has complex/struct.NotOuter.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<'a, T, K: ?Sized> Send for Outer<'a, T, K>where K: for<'b> Fn((&'b bool, &'a u8)) \
// -> &'b i8, T: MyTrait<'a>, <T as MyTrait<'a>>::MyItem: Copy, 'a: 'static"
diff --git a/src/test/rustdoc/synthetic_auto/crate-local.rs b/src/test/rustdoc/synthetic_auto/crate-local.rs
index 58b787dfa..ed01f63f9 100644
--- a/src/test/rustdoc/synthetic_auto/crate-local.rs
+++ b/src/test/rustdoc/synthetic_auto/crate-local.rs
@@ -3,7 +3,7 @@
pub auto trait Banana {}
// @has crate_local/struct.Peach.html
-// @has - '//h3[@class="code-header in-band"]' 'impl Banana for Peach'
-// @has - '//h3[@class="code-header in-band"]' 'impl Send for Peach'
-// @has - '//h3[@class="code-header in-band"]' 'impl Sync for Peach'
+// @has - '//h3[@class="code-header"]' 'impl Banana for Peach'
+// @has - '//h3[@class="code-header"]' 'impl Send for Peach'
+// @has - '//h3[@class="code-header"]' 'impl Sync for Peach'
pub struct Peach;
diff --git a/src/test/rustdoc/synthetic_auto/lifetimes.rs b/src/test/rustdoc/synthetic_auto/lifetimes.rs
index 0c94850e7..33170a844 100644
--- a/src/test/rustdoc/synthetic_auto/lifetimes.rs
+++ b/src/test/rustdoc/synthetic_auto/lifetimes.rs
@@ -9,10 +9,10 @@ where
{}
// @has lifetimes/struct.Foo.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<'c, K> Send for Foo<'c, K>where K: for<'b> Fn(&'b bool) -> &'c u8, 'c: 'static"
//
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<'c, K> Sync for Foo<'c, K>where K: Sync"
pub struct Foo<'c, K: 'c> {
inner_field: Inner<'c, K>,
diff --git a/src/test/rustdoc/synthetic_auto/manual.rs b/src/test/rustdoc/synthetic_auto/manual.rs
index 35047e3e8..77c04ad2a 100644
--- a/src/test/rustdoc/synthetic_auto/manual.rs
+++ b/src/test/rustdoc/synthetic_auto/manual.rs
@@ -1,8 +1,8 @@
// @has manual/struct.Foo.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// 'impl<T> Sync for Foo<T>where T: Sync'
//
-// @has - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// 'impl<T> Send for Foo<T>'
//
// @count - '//*[@id="trait-implementations-list"]//*[@class="impl has-srclink"]' 1
diff --git a/src/test/rustdoc/synthetic_auto/negative.rs b/src/test/rustdoc/synthetic_auto/negative.rs
index 66e749ac3..2c2c848a5 100644
--- a/src/test/rustdoc/synthetic_auto/negative.rs
+++ b/src/test/rustdoc/synthetic_auto/negative.rs
@@ -3,10 +3,10 @@ pub struct Inner<T: Copy> {
}
// @has negative/struct.Outer.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<T> !Send for Outer<T>"
//
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<T> !Sync for Outer<T>"
pub struct Outer<T: Copy> {
inner_field: Inner<T>,
diff --git a/src/test/rustdoc/synthetic_auto/nested.rs b/src/test/rustdoc/synthetic_auto/nested.rs
index 09587bcc3..423bf115a 100644
--- a/src/test/rustdoc/synthetic_auto/nested.rs
+++ b/src/test/rustdoc/synthetic_auto/nested.rs
@@ -9,10 +9,10 @@ where
}
// @has nested/struct.Foo.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// 'impl<T> Send for Foo<T>where T: Copy'
//
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// 'impl<T> Sync for Foo<T>where T: Sync'
pub struct Foo<T> {
inner_field: Inner<T>,
diff --git a/src/test/rustdoc/synthetic_auto/no-redundancy.rs b/src/test/rustdoc/synthetic_auto/no-redundancy.rs
index 41375decc..59f336233 100644
--- a/src/test/rustdoc/synthetic_auto/no-redundancy.rs
+++ b/src/test/rustdoc/synthetic_auto/no-redundancy.rs
@@ -9,7 +9,7 @@ where
}
// @has no_redundancy/struct.Outer.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<T> Send for Outer<T>where T: Send + Copy"
pub struct Outer<T> {
inner_field: Inner<T>,
diff --git a/src/test/rustdoc/synthetic_auto/overflow.rs b/src/test/rustdoc/synthetic_auto/overflow.rs
index c132ab6fb..35a487c76 100644
--- a/src/test/rustdoc/synthetic_auto/overflow.rs
+++ b/src/test/rustdoc/synthetic_auto/overflow.rs
@@ -21,7 +21,7 @@ enum TyData<I: Interner> {
struct VariableKind<I: Interner>(I::InternedType);
// @has overflow/struct.BoundVarsCollector.html
-// @has - '//h3[@class="code-header in-band"]' "impl<'tcx> Send for BoundVarsCollector<'tcx>"
+// @has - '//h3[@class="code-header"]' "impl<'tcx> Send for BoundVarsCollector<'tcx>"
pub struct BoundVarsCollector<'tcx> {
val: VariableKind<RustInterner<'tcx>>
}
diff --git a/src/test/rustdoc/synthetic_auto/project.rs b/src/test/rustdoc/synthetic_auto/project.rs
index e80b1b1dc..558ff2add 100644
--- a/src/test/rustdoc/synthetic_auto/project.rs
+++ b/src/test/rustdoc/synthetic_auto/project.rs
@@ -23,10 +23,10 @@ where
}
// @has project/struct.Foo.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<'c, K> Send for Foo<'c, K>where K: MyTrait<MyItem = bool>, 'c: 'static"
//
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<'c, K> Sync for Foo<'c, K>where K: MyTrait, <K as MyTrait>::MyItem: OtherTrait, \
// 'c: 'static,"
pub struct Foo<'c, K: 'c> {
diff --git a/src/test/rustdoc/synthetic_auto/self-referential.rs b/src/test/rustdoc/synthetic_auto/self-referential.rs
index d15a8de7d..c6ae96de7 100644
--- a/src/test/rustdoc/synthetic_auto/self-referential.rs
+++ b/src/test/rustdoc/synthetic_auto/self-referential.rs
@@ -23,7 +23,7 @@ impl<T> Pattern for Wrapper<T> {
// @has self_referential/struct.WriteAndThen.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<P1> Send for WriteAndThen<P1>where <P1 as Pattern>::Value: Send"
pub struct WriteAndThen<P1>(pub P1::Value,pub <Constrain<P1, Wrapper<P1::Value>> as Pattern>::Value)
where P1: Pattern;
diff --git a/src/test/rustdoc/synthetic_auto/static-region.rs b/src/test/rustdoc/synthetic_auto/static-region.rs
index 08e956731..1a76cb919 100644
--- a/src/test/rustdoc/synthetic_auto/static-region.rs
+++ b/src/test/rustdoc/synthetic_auto/static-region.rs
@@ -3,7 +3,7 @@ pub trait OwnedTrait<'a> {
}
// @has static_region/struct.Owned.html
-// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<T> Send for Owned<T>where <T as OwnedTrait<'static>>::Reader: Send"
pub struct Owned<T> where T: OwnedTrait<'static> {
marker: <T as OwnedTrait<'static>>::Reader,
diff --git a/src/test/rustdoc/toggle-item-contents.rs b/src/test/rustdoc/toggle-item-contents.rs
index dbaf195e1..47a1d62f5 100644
--- a/src/test/rustdoc/toggle-item-contents.rs
+++ b/src/test/rustdoc/toggle-item-contents.rs
@@ -55,7 +55,7 @@ pub union Union {
// @has 'toggle_item_contents/struct.PrivStruct.html'
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 0
-// @has - '//div[@class="docblock item-decl"]' '/* private fields */'
+// @has - '//div[@class="item-decl"]' '/* private fields */'
pub struct PrivStruct {
a: usize,
b: usize,
diff --git a/src/test/rustdoc/toggle-trait-fn.rs b/src/test/rustdoc/toggle-trait-fn.rs
index 65e8daeb0..e41422ce7 100644
--- a/src/test/rustdoc/toggle-trait-fn.rs
+++ b/src/test/rustdoc/toggle-trait-fn.rs
@@ -4,12 +4,12 @@
// summary. Trait methods with no documentation should not be wrapped.
//
// @has foo/trait.Foo.html
-// @has - '//details[@class="rustdoc-toggle"]//summary//h4[@class="code-header"]' 'is_documented()'
-// @!has - '//details[@class="rustdoc-toggle"]//summary//h4[@class="code-header"]' 'not_documented()'
-// @has - '//details[@class="rustdoc-toggle"]//*[@class="docblock"]' 'is_documented is documented'
-// @has - '//details[@class="rustdoc-toggle"]//summary//h4[@class="code-header"]' 'is_documented_optional()'
-// @!has - '//details[@class="rustdoc-toggle"]//summary//h4[@class="code-header"]' 'not_documented_optional()'
-// @has - '//details[@class="rustdoc-toggle"]//*[@class="docblock"]' 'is_documented_optional is documented'
+// @has - '//details[@class="rustdoc-toggle method-toggle"]//summary//h4[@class="code-header"]' 'is_documented()'
+// @!has - '//details[@class="rustdoc-toggle method-toggle"]//summary//h4[@class="code-header"]' 'not_documented()'
+// @has - '//details[@class="rustdoc-toggle method-toggle"]//*[@class="docblock"]' 'is_documented is documented'
+// @has - '//details[@class="rustdoc-toggle method-toggle"]//summary//h4[@class="code-header"]' 'is_documented_optional()'
+// @!has - '//details[@class="rustdoc-toggle method-toggle"]//summary//h4[@class="code-header"]' 'not_documented_optional()'
+// @has - '//details[@class="rustdoc-toggle method-toggle"]//*[@class="docblock"]' 'is_documented_optional is documented'
pub trait Foo {
fn not_documented();
diff --git a/src/test/rustdoc/trait_alias.rs b/src/test/rustdoc/trait_alias.rs
index a0c657d9a..791c099cc 100644
--- a/src/test/rustdoc/trait_alias.rs
+++ b/src/test/rustdoc/trait_alias.rs
@@ -14,13 +14,13 @@ use std::fmt::Debug;
// @has foo/index.html '//a[@class="traitalias"]' 'Foo'
// @has foo/traitalias.CopyAlias.html
-// @has - '//section[@id="main-content"]/div[@class="docblock item-decl"]/pre' 'trait CopyAlias = Copy;'
+// @has - '//section[@id="main-content"]/div[@class="item-decl"]/pre' 'trait CopyAlias = Copy;'
pub trait CopyAlias = Copy;
// @has foo/traitalias.Alias2.html
-// @has - '//section[@id="main-content"]/div[@class="docblock item-decl"]/pre' 'trait Alias2 = Copy + Debug;'
+// @has - '//section[@id="main-content"]/div[@class="item-decl"]/pre' 'trait Alias2 = Copy + Debug;'
pub trait Alias2 = Copy + Debug;
// @has foo/traitalias.Foo.html
-// @has - '//section[@id="main-content"]/div[@class="docblock item-decl"]/pre' 'trait Foo<T> = Into<T> + Debug;'
+// @has - '//section[@id="main-content"]/div[@class="item-decl"]/pre' 'trait Foo<T> = Into<T> + Debug;'
pub trait Foo<T> = Into<T> + Debug;
// @has foo/fn.bar.html '//a[@href="traitalias.Alias2.html"]' 'Alias2'
pub fn bar<T>() where T: Alias2 {}
diff --git a/src/test/rustdoc/traits-in-bodies.rs b/src/test/rustdoc/traits-in-bodies.rs
index 6d450a625..a65dd7a54 100644
--- a/src/test/rustdoc/traits-in-bodies.rs
+++ b/src/test/rustdoc/traits-in-bodies.rs
@@ -4,7 +4,7 @@
pub struct Bounded<T: Clone>(T);
// @has traits_in_bodies/struct.SomeStruct.html
-// @has - '//h3[@class="code-header in-band"]' 'impl Clone for SomeStruct'
+// @has - '//h3[@class="code-header"]' 'impl Clone for SomeStruct'
pub struct SomeStruct;
fn asdf() -> Bounded<SomeStruct> {
@@ -18,7 +18,7 @@ fn asdf() -> Bounded<SomeStruct> {
}
// @has traits_in_bodies/struct.Point.html
-// @has - '//h3[@class="code-header in-band"]' 'impl Copy for Point'
+// @has - '//h3[@class="code-header"]' 'impl Copy for Point'
#[derive(Clone)]
pub struct Point {
x: i32,
@@ -31,7 +31,7 @@ const _FOO: () = {
};
// @has traits_in_bodies/struct.Inception.html
-// @has - '//h3[@class="code-header in-band"]' 'impl Clone for Inception'
+// @has - '//h3[@class="code-header"]' 'impl Clone for Inception'
pub struct Inception;
static _BAR: usize = {
diff --git a/src/test/rustdoc/tuple-struct-fields-doc.rs b/src/test/rustdoc/tuple-struct-fields-doc.rs
index 66bb40932..8ab1143d1 100644
--- a/src/test/rustdoc/tuple-struct-fields-doc.rs
+++ b/src/test/rustdoc/tuple-struct-fields-doc.rs
@@ -2,7 +2,7 @@
// @has foo/struct.Foo.html
// @has - '//h2[@id="fields"]' 'Tuple Fields'
-// @has - '//h3[@class="sidebar-title"]/a[@href="#fields"]' 'Tuple Fields'
+// @has - '//div[@class="sidebar-elems"]//h3/a[@href="#fields"]' 'Tuple Fields'
// @has - '//*[@id="structfield.0"]' '0: u32'
// @has - '//*[@id="main-content"]/div[@class="docblock"]' 'hello'
// @!has - '//*[@id="structfield.1"]' ''
diff --git a/src/test/rustdoc/typedef.rs b/src/test/rustdoc/typedef.rs
index b68ec4557..d5dfa9484 100644
--- a/src/test/rustdoc/typedef.rs
+++ b/src/test/rustdoc/typedef.rs
@@ -9,8 +9,8 @@ impl MyStruct {
}
// @has typedef/type.MyAlias.html
-// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'impl MyAlias'
-// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' 'impl MyTrait for MyAlias'
+// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'impl MyAlias'
+// @has - '//*[@class="impl has-srclink"]//h3[@class="code-header"]' 'impl MyTrait for MyAlias'
// @hasraw - 'Alias docstring'
// @has - '//*[@class="sidebar"]//*[@class="location"]' 'MyAlias'
// @has - '//*[@class="sidebar"]//a[@href="#implementations"]' 'Methods'
diff --git a/src/test/rustdoc/where.SWhere_Simd_item-decl.html b/src/test/rustdoc/where.SWhere_Simd_item-decl.html
index 0133bcaeb..6c1b5d315 100644
--- a/src/test/rustdoc/where.SWhere_Simd_item-decl.html
+++ b/src/test/rustdoc/where.SWhere_Simd_item-decl.html
@@ -1 +1 @@
-<div class="docblock item-decl"><pre class="rust struct"><code>pub struct Simd&lt;T&gt;(_) <br /><span class="where">where<br />&#160;&#160;&#160;&#160;T: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code></pre></div> \ No newline at end of file
+<div class="item-decl"><pre class="rust struct"><code>pub struct Simd&lt;T&gt;(_)<br /><span class="where">where<br />&#160;&#160;&#160;&#160;T: <a class="trait" href="trait.MyTrait.html" title="trait foo::MyTrait">MyTrait</a></span>;</code></pre></div> \ No newline at end of file
diff --git a/src/test/rustdoc/where.SWhere_TraitWhere_item-decl.html b/src/test/rustdoc/where.SWhere_TraitWhere_item-decl.html
index 542a3337b..24ab77703 100644
--- a/src/test/rustdoc/where.SWhere_TraitWhere_item-decl.html
+++ b/src/test/rustdoc/where.SWhere_TraitWhere_item-decl.html
@@ -1,4 +1,4 @@
-<div class="docblock item-decl"><pre class="rust trait"><code>pub trait TraitWhere {
+<div class="item-decl"><pre class="rust trait"><code>pub trait TraitWhere {
type <a href="#associatedtype.Item" class="associatedtype">Item</a>&lt;'a&gt;<br />&#160;&#160;&#160;&#160;<span class="where">where<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Self: 'a</span>;
fn <a href="#method.func" class="fnname">func</a>(self)<br />&#160;&#160;&#160;&#160;<span class="where">where<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Self: <a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
diff --git a/src/test/rustdoc/where.rs b/src/test/rustdoc/where.rs
index 7a6c0db23..8b5bce28f 100644
--- a/src/test/rustdoc/where.rs
+++ b/src/test/rustdoc/where.rs
@@ -13,7 +13,7 @@ pub fn charlie<C>() where C: MyTrait {}
pub struct Delta<D>(D);
-// @has foo/struct.Delta.html '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has foo/struct.Delta.html '//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<D> Delta<D>where D: MyTrait"
impl<D> Delta<D> where D: MyTrait {
pub fn delta() {}
@@ -22,13 +22,13 @@ impl<D> Delta<D> where D: MyTrait {
pub struct Echo<E>(E);
// @has 'foo/struct.Simd.html'
-// @snapshot SWhere_Simd_item-decl - '//div[@class="docblock item-decl"]'
+// @snapshot SWhere_Simd_item-decl - '//div[@class="item-decl"]'
pub struct Simd<T>([T; 1])
where
T: MyTrait;
// @has 'foo/trait.TraitWhere.html'
-// @snapshot SWhere_TraitWhere_item-decl - '//div[@class="docblock item-decl"]'
+// @snapshot SWhere_TraitWhere_item-decl - '//div[@class="item-decl"]'
pub trait TraitWhere {
type Item<'a> where Self: 'a;
@@ -43,17 +43,17 @@ pub trait TraitWhere {
{ todo!() }
}
-// @has foo/struct.Echo.html '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has foo/struct.Echo.html '//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<E> MyTrait for Echo<E>where E: MyTrait"
-// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//h3[@class="code-header in-band"]' \
+// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//h3[@class="code-header"]' \
// "impl<E> MyTrait for Echo<E>where E: MyTrait"
impl<E> MyTrait for Echo<E>where E: MyTrait {}
pub enum Foxtrot<F> { Foxtrot1(F) }
-// @has foo/enum.Foxtrot.html '//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
+// @has foo/enum.Foxtrot.html '//*[@class="impl has-srclink"]//h3[@class="code-header"]' \
// "impl<F> MyTrait for Foxtrot<F>where F: MyTrait"
-// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//h3[@class="code-header in-band"]' \
+// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//h3[@class="code-header"]' \
// "impl<F> MyTrait for Foxtrot<F>where F: MyTrait"
impl<F> MyTrait for Foxtrot<F>where F: MyTrait {}
diff --git a/src/test/rustdoc/whitespace-after-where-clause.enum.html b/src/test/rustdoc/whitespace-after-where-clause.enum.html
index 9e5bf45ae..c74866f4a 100644
--- a/src/test/rustdoc/whitespace-after-where-clause.enum.html
+++ b/src/test/rustdoc/whitespace-after-where-clause.enum.html
@@ -1,4 +1,4 @@
-<div class="docblock item-decl"><pre class="rust enum"><code>pub enum Cow&lt;'a, B:&#160;?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a&gt; <span class="where fmt-newline">where<br />&#160;&#160;&#160;&#160;B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt;,&#160;</span>{
+<div class="item-decl"><pre class="rust enum"><code>pub enum Cow&lt;'a, B:&#160;?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a&gt;<span class="where fmt-newline">where<br />&#160;&#160;&#160;&#160;B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt;,</span>{
Borrowed(<a class="primitive" href="{{channel}}/std/primitive.reference.html">&amp;'a </a>B),
Whatever(<a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>),
-}</code></pre></div>
+}</code></pre></div> \ No newline at end of file
diff --git a/src/test/rustdoc/whitespace-after-where-clause.enum2.html b/src/test/rustdoc/whitespace-after-where-clause.enum2.html
index 6bc47beae..ac7d77598 100644
--- a/src/test/rustdoc/whitespace-after-where-clause.enum2.html
+++ b/src/test/rustdoc/whitespace-after-where-clause.enum2.html
@@ -1,4 +1,4 @@
-<div class="docblock item-decl"><pre class="rust enum"><code>pub enum Cow2&lt;'a, B:&#160;?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt; + 'a&gt; {
+<div class="item-decl"><pre class="rust enum"><code>pub enum Cow2&lt;'a, B:&#160;?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt; + 'a&gt; {
Borrowed(<a class="primitive" href="{{channel}}/std/primitive.reference.html">&amp;'a </a>B),
Whatever(<a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>),
-}</code></pre></div>
+}</code></pre></div> \ No newline at end of file
diff --git a/src/test/rustdoc/whitespace-after-where-clause.rs b/src/test/rustdoc/whitespace-after-where-clause.rs
index c36386a2a..4b740b970 100644
--- a/src/test/rustdoc/whitespace-after-where-clause.rs
+++ b/src/test/rustdoc/whitespace-after-where-clause.rs
@@ -4,7 +4,7 @@
#![crate_name = "foo"]
// @has 'foo/trait.ToOwned.html'
-// @snapshot trait - '//*[@class="docblock item-decl"]'
+// @snapshot trait - '//*[@class="item-decl"]'
pub trait ToOwned<T>
where T: Clone
{
@@ -14,7 +14,7 @@ where T: Clone
}
// @has 'foo/trait.ToOwned2.html'
-// @snapshot trait2 - '//*[@class="docblock item-decl"]'
+// @snapshot trait2 - '//*[@class="item-decl"]'
// There should be a whitespace before `{` in this case!
pub trait ToOwned2<T: Clone> {
type Owned;
@@ -23,7 +23,7 @@ pub trait ToOwned2<T: Clone> {
}
// @has 'foo/enum.Cow.html'
-// @snapshot enum - '//*[@class="docblock item-decl"]'
+// @snapshot enum - '//*[@class="item-decl"]'
pub enum Cow<'a, B: ?Sized + 'a>
where
B: ToOwned<Clone>,
@@ -33,7 +33,7 @@ where
}
// @has 'foo/enum.Cow2.html'
-// @snapshot enum2 - '//*[@class="docblock item-decl"]'
+// @snapshot enum2 - '//*[@class="item-decl"]'
// There should be a whitespace before `{` in this case!
pub enum Cow2<'a, B: ?Sized + ToOwned<Clone> + 'a> {
Borrowed(&'a B),
@@ -41,7 +41,7 @@ pub enum Cow2<'a, B: ?Sized + ToOwned<Clone> + 'a> {
}
// @has 'foo/struct.Struct.html'
-// @snapshot struct - '//*[@class="docblock item-decl"]'
+// @snapshot struct - '//*[@class="item-decl"]'
pub struct Struct<'a, B: ?Sized + 'a>
where
B: ToOwned<Clone>,
@@ -51,7 +51,7 @@ where
}
// @has 'foo/struct.Struct2.html'
-// @snapshot struct2 - '//*[@class="docblock item-decl"]'
+// @snapshot struct2 - '//*[@class="item-decl"]'
// There should be a whitespace before `{` in this case!
pub struct Struct2<'a, B: ?Sized + ToOwned<Clone> + 'a> {
pub a: &'a B,
@@ -59,7 +59,7 @@ pub struct Struct2<'a, B: ?Sized + ToOwned<Clone> + 'a> {
}
// @has 'foo/union.Union.html'
-// @snapshot union - '//*[@class="docblock item-decl"]'
+// @snapshot union - '//*[@class="item-decl"]'
pub union Union<'a, B: ?Sized + 'a>
where
B: ToOwned<Clone>,
@@ -69,7 +69,7 @@ where
}
// @has 'foo/union.Union2.html'
-// @snapshot union2 - '//*[@class="docblock item-decl"]'
+// @snapshot union2 - '//*[@class="item-decl"]'
// There should be a whitespace before `{` in this case!
pub union Union2<'a, B: ?Sized + ToOwned<Clone> + 'a> {
a: &'a B,
diff --git a/src/test/rustdoc/whitespace-after-where-clause.struct.html b/src/test/rustdoc/whitespace-after-where-clause.struct.html
index 236cc3b30..1ba1367d2 100644
--- a/src/test/rustdoc/whitespace-after-where-clause.struct.html
+++ b/src/test/rustdoc/whitespace-after-where-clause.struct.html
@@ -1,4 +1,4 @@
-<div class="docblock item-decl"><pre class="rust struct"><code>pub struct Struct&lt;'a, B:&#160;?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a&gt; <span class="where fmt-newline">where<br />&#160;&#160;&#160;&#160;B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt;,&#160;</span>{
+<div class="item-decl"><pre class="rust struct"><code>pub struct Struct&lt;'a, B:&#160;?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a&gt;<span class="where fmt-newline">where<br />&#160;&#160;&#160;&#160;B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt;,</span>{
pub a: <a class="primitive" href="{{channel}}/std/primitive.reference.html">&amp;'a </a>B,
pub b: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>,
-}</code></pre></div>
+}</code></pre></div> \ No newline at end of file
diff --git a/src/test/rustdoc/whitespace-after-where-clause.struct2.html b/src/test/rustdoc/whitespace-after-where-clause.struct2.html
index 47f5c6ba9..fb06b0f77 100644
--- a/src/test/rustdoc/whitespace-after-where-clause.struct2.html
+++ b/src/test/rustdoc/whitespace-after-where-clause.struct2.html
@@ -1,4 +1,4 @@
-<div class="docblock item-decl"><pre class="rust struct"><code>pub struct Struct2&lt;'a, B:&#160;?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt; + 'a&gt; {
+<div class="item-decl"><pre class="rust struct"><code>pub struct Struct2&lt;'a, B:&#160;?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt; + 'a&gt; {
pub a: <a class="primitive" href="{{channel}}/std/primitive.reference.html">&amp;'a </a>B,
pub b: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>,
-}</code></pre></div>
+}</code></pre></div> \ No newline at end of file
diff --git a/src/test/rustdoc/whitespace-after-where-clause.trait.html b/src/test/rustdoc/whitespace-after-where-clause.trait.html
index 98f03b837..16b558237 100644
--- a/src/test/rustdoc/whitespace-after-where-clause.trait.html
+++ b/src/test/rustdoc/whitespace-after-where-clause.trait.html
@@ -1,6 +1,6 @@
-<div class="docblock item-decl"><pre class="rust trait"><code>pub trait ToOwned&lt;T&gt; <span class="where fmt-newline">where<br />&#160;&#160;&#160;&#160;T: <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,&#160;</span>{
+<div class="item-decl"><pre class="rust trait"><code>pub trait ToOwned&lt;T&gt;<span class="where fmt-newline">where<br />&#160;&#160;&#160;&#160;T: <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</span>{
type <a href="#associatedtype.Owned" class="associatedtype">Owned</a>;
fn <a href="#tymethod.to_owned" class="fnname">to_owned</a>(&amp;self) -&gt; Self::<a class="associatedtype" href="trait.ToOwned.html#associatedtype.Owned" title="type foo::ToOwned::Owned">Owned</a>;
<span class="item-spacer" /> fn <a href="#tymethod.whatever" class="fnname">whatever</a>(&amp;self) -&gt; T;
-}</code></pre></div>
+}</code></pre></div> \ No newline at end of file
diff --git a/src/test/rustdoc/whitespace-after-where-clause.trait2.html b/src/test/rustdoc/whitespace-after-where-clause.trait2.html
index 35052869e..eeca6e1f5 100644
--- a/src/test/rustdoc/whitespace-after-where-clause.trait2.html
+++ b/src/test/rustdoc/whitespace-after-where-clause.trait2.html
@@ -1,6 +1,6 @@
-<div class="docblock item-decl"><pre class="rust trait"><code>pub trait ToOwned2&lt;T:&#160;<a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt; {
+<div class="item-decl"><pre class="rust trait"><code>pub trait ToOwned2&lt;T:&#160;<a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt; {
type <a href="#associatedtype.Owned" class="associatedtype">Owned</a>;
fn <a href="#tymethod.to_owned" class="fnname">to_owned</a>(&amp;self) -&gt; Self::<a class="associatedtype" href="trait.ToOwned2.html#associatedtype.Owned" title="type foo::ToOwned2::Owned">Owned</a>;
<span class="item-spacer" /> fn <a href="#tymethod.whatever" class="fnname">whatever</a>(&amp;self) -&gt; T;
-}</code></pre></div>
+}</code></pre></div> \ No newline at end of file
diff --git a/src/test/rustdoc/whitespace-after-where-clause.union.html b/src/test/rustdoc/whitespace-after-where-clause.union.html
index 97e1bbcf3..0dfb6407d 100644
--- a/src/test/rustdoc/whitespace-after-where-clause.union.html
+++ b/src/test/rustdoc/whitespace-after-where-clause.union.html
@@ -1,3 +1,3 @@
-<div class="docblock item-decl"><pre class="rust union"><code>pub union Union&lt;'a, B:&#160;?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a&gt; <span class="where fmt-newline">where<br />&#160;&#160;&#160;&#160;B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt;,&#160;</span>{
+<div class="item-decl"><pre class="rust union"><code>pub union Union&lt;'a, B:&#160;?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a&gt;<span class="where fmt-newline">where<br />&#160;&#160;&#160;&#160;B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt;,</span>{
/* private fields */
-}</code></pre></div>
+}</code></pre></div> \ No newline at end of file
diff --git a/src/test/rustdoc/whitespace-after-where-clause.union2.html b/src/test/rustdoc/whitespace-after-where-clause.union2.html
index 6c752a8b4..0d237df53 100644
--- a/src/test/rustdoc/whitespace-after-where-clause.union2.html
+++ b/src/test/rustdoc/whitespace-after-where-clause.union2.html
@@ -1,3 +1,3 @@
-<div class="docblock item-decl"><pre class="rust union"><code>pub union Union2&lt;'a, B:&#160;?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt; + 'a&gt; {
+<div class="item-decl"><pre class="rust union"><code>pub union Union2&lt;'a, B:&#160;?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>&gt; + 'a&gt; {
/* private fields */
-}</code></pre></div>
+}</code></pre></div> \ No newline at end of file
diff --git a/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs b/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs
index 03ad3ca82..c05443488 100644
--- a/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs
+++ b/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs
@@ -44,14 +44,16 @@ impl<'tcx> LateLintPass<'tcx> for MissingAllowedAttrPass {
) {
let item = match cx.tcx.hir().get(id) {
Node::Item(item) => item,
- _ => cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(id)),
+ _ => cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(id).def_id),
};
let allowed = |attr| pprust::attribute_to_string(attr).contains("allowed_attr");
if !cx.tcx.hir().attrs(item.hir_id()).iter().any(allowed) {
- cx.lint(MISSING_ALLOWED_ATTR, |lint| {
- lint.build("Missing 'allowed_attr' attribute").set_span(span).emit();
- });
+ cx.lint(
+ MISSING_ALLOWED_ATTR,
+ "Missing 'allowed_attr' attribute",
+ |lint| lint.set_span(span)
+ );
}
}
}
diff --git a/src/test/ui-fulldeps/auxiliary/lint-for-crate.rs b/src/test/ui-fulldeps/auxiliary/lint-for-crate.rs
index 0b1534939..073da688c 100644
--- a/src/test/ui-fulldeps/auxiliary/lint-for-crate.rs
+++ b/src/test/ui-fulldeps/auxiliary/lint-for-crate.rs
@@ -29,9 +29,11 @@ impl<'tcx> LateLintPass<'tcx> for Pass {
let attrs = cx.tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
let span = cx.tcx.def_span(CRATE_DEF_ID);
if !cx.sess().contains_name(attrs, Symbol::intern("crate_okay")) {
- cx.lint(CRATE_NOT_OKAY, |lint| {
- lint.build("crate is not marked with #![crate_okay]").set_span(span).emit();
- });
+ cx.lint(
+ CRATE_NOT_OKAY,
+ "crate is not marked with #![crate_okay]",
+ |lint| lint.set_span(span)
+ );
}
}
}
diff --git a/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs b/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs
index 2d41b5f30..4a41e7fbb 100644
--- a/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs
+++ b/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs
@@ -22,12 +22,10 @@ declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]);
impl<'tcx> LateLintPass<'tcx> for Pass {
fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) {
match it.ident.as_str() {
- "lintme" => cx.lint(TEST_LINT, |lint| {
- lint.build("item is named 'lintme'").set_span(it.span).emit();
- }),
- "pleaselintme" => cx.lint(PLEASE_LINT, |lint| {
- lint.build("item is named 'pleaselintme'").set_span(it.span).emit();
- }),
+ "lintme" => cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span)),
+ "pleaselintme" => {
+ cx.lint(PLEASE_LINT, "item is named 'pleaselintme'", |lint| lint.set_span(it.span))
+ }
_ => {}
}
}
diff --git a/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs b/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs
index 285754928..30956deb7 100644
--- a/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs
+++ b/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs
@@ -21,9 +21,7 @@ declare_lint_pass!(Pass => [TEST_LINT]);
impl EarlyLintPass for Pass {
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
if it.ident.name.as_str() == "lintme" {
- cx.lint(TEST_LINT, |lint| {
- lint.build("item is named 'lintme'").set_span(it.span).emit();
- });
+ cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span));
}
}
}
diff --git a/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs b/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs
index 3d5dba42b..c2c024865 100644
--- a/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs
+++ b/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs
@@ -31,14 +31,10 @@ declare_lint_pass!(Pass => [TEST_LINT, TEST_GROUP, TEST_RUSTC_TOOL_LINT]);
impl EarlyLintPass for Pass {
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
if it.ident.name.as_str() == "lintme" {
- cx.lint(TEST_LINT, |lint| {
- lint.build("item is named 'lintme'").set_span(it.span).emit();
- });
+ cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span));
}
if it.ident.name.as_str() == "lintmetoo" {
- cx.lint(TEST_GROUP, |lint| {
- lint.build("item is named 'lintmetoo'").set_span(it.span).emit();
- });
+ cx.lint(TEST_GROUP, "item is named 'lintmetoo'", |lint| lint.set_span(it.span));
}
}
}
diff --git a/src/test/ui-fulldeps/fluent-messages/test.rs b/src/test/ui-fulldeps/fluent-messages/test.rs
index 256857e52..4e8147e2b 100644
--- a/src/test/ui-fulldeps/fluent-messages/test.rs
+++ b/src/test/ui-fulldeps/fluent-messages/test.rs
@@ -49,6 +49,7 @@ mod duplicate {
use super::fluent_messages;
fluent_messages! {
+//~^ ERROR the name `a_b_key` is defined multiple times
a => "./duplicate-a.ftl",
a_b => "./duplicate-a-b.ftl",
//~^ ERROR overrides existing message: `a_b_key`
@@ -80,7 +81,7 @@ mod valid {
valid => "./valid.ftl",
}
- use self::fluent_generated::{DEFAULT_LOCALE_RESOURCES, valid::key};
+ use self::fluent_generated::{DEFAULT_LOCALE_RESOURCES, valid_key};
}
mod missing_crate_name {
@@ -93,5 +94,5 @@ mod missing_crate_name {
//~| ERROR name `with-hyphens` does not start with the crate name
}
- use self::fluent_generated::{DEFAULT_LOCALE_RESOURCES, test_crate::{foo, with_hyphens}};
+ use self::fluent_generated::{DEFAULT_LOCALE_RESOURCES, test_crate_foo, with_hyphens};
}
diff --git a/src/test/ui-fulldeps/fluent-messages/test.stderr b/src/test/ui-fulldeps/fluent-messages/test.stderr
index 26d87430a..d1cd4fe26 100644
--- a/src/test/ui-fulldeps/fluent-messages/test.stderr
+++ b/src/test/ui-fulldeps/fluent-messages/test.stderr
@@ -30,19 +30,31 @@ error: expected a message field for "missing_message"
|
error: overrides existing message: `a_b_key`
- --> $DIR/test.rs:53:16
+ --> $DIR/test.rs:54:16
|
LL | a_b => "./duplicate-a-b.ftl",
| ^^^^^^^^^^^^^^^^^^^^^
|
help: previously defined in this resource
- --> $DIR/test.rs:52:14
+ --> $DIR/test.rs:53:14
|
LL | a => "./duplicate-a.ftl",
| ^^^^^^^^^^^^^^^^^^^
+error[E0428]: the name `a_b_key` is defined multiple times
+ --> $DIR/test.rs:51:5
+ |
+LL | fluent_messages! {
+ | ^^^^^^^^^^^^^^^^
+ | |
+ | `a_b_key` redefined here
+ | previous definition of the value `a_b_key` here
+ |
+ = note: os-specific message
+ = note: os-specific message
+
error: name `slug_with_hyphens_this-slug-has-hyphens` contains a '-' character
- --> $DIR/test.rs:62:30
+ --> $DIR/test.rs:63:30
|
LL | slug_with_hyphens => "./slug-with-hyphens.ftl",
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -50,7 +62,7 @@ LL | slug_with_hyphens => "./slug-with-hyphens.ftl",
= help: replace any '-'s with '_'s
error: attribute `label-has-hyphens` contains a '-' character
- --> $DIR/test.rs:71:31
+ --> $DIR/test.rs:72:31
|
LL | label_with_hyphens => "./label-with-hyphens.ftl",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -58,7 +70,7 @@ LL | label_with_hyphens => "./label-with-hyphens.ftl",
= help: replace any '-'s with '_'s
error: name `with-hyphens` contains a '-' character
- --> $DIR/test.rs:90:23
+ --> $DIR/test.rs:91:23
|
LL | test_crate => "./missing-crate-name.ftl",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -66,7 +78,7 @@ LL | test_crate => "./missing-crate-name.ftl",
= help: replace any '-'s with '_'s
error: name `with-hyphens` does not start with the crate name
- --> $DIR/test.rs:90:23
+ --> $DIR/test.rs:91:23
|
LL | test_crate => "./missing-crate-name.ftl",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -74,12 +86,13 @@ LL | test_crate => "./missing-crate-name.ftl",
= help: prepend `test_crate_` to the slug name: `test_crate_with_hyphens`
error: name `test-crate_foo` contains a '-' character
- --> $DIR/test.rs:90:23
+ --> $DIR/test.rs:91:23
|
LL | test_crate => "./missing-crate-name.ftl",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: replace any '-'s with '_'s
-error: aborting due to 9 previous errors
+error: aborting due to 10 previous errors
+For more information about this error, try `rustc --explain E0428`.
diff --git a/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr b/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr
index 9d13ee89b..3cb13082f 100644
--- a/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr
+++ b/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr
@@ -4,12 +4,12 @@ error: prefer `FxHashMap` over `HashMap`, it has better performance
LL | let _map: HashMap<String, String> = HashMap::default();
| ^^^^^^^
|
+ = note: a `use rustc_data_structures::fx::FxHashMap` may be necessary
note: the lint level is defined here
--> $DIR/default_hash_types.rs:4:9
|
LL | #![deny(rustc::default_hash_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: a `use rustc_data_structures::fx::FxHashMap` may be necessary
error: prefer `FxHashMap` over `HashMap`, it has better performance
--> $DIR/default_hash_types.rs:16:15
diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.rs b/src/test/ui-fulldeps/internal-lints/diagnostics.rs
index e9e809fa4..643e81d99 100644
--- a/src/test/ui-fulldeps/internal-lints/diagnostics.rs
+++ b/src/test/ui-fulldeps/internal-lints/diagnostics.rs
@@ -12,66 +12,72 @@ extern crate rustc_session;
extern crate rustc_span;
use rustc_errors::{
- AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent
+ AddToDiagnostic, IntoDiagnostic, Diagnostic, DiagnosticBuilder,
+ ErrorGuaranteed, Handler, fluent, SubdiagnosticMessage,
};
-use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
-use rustc_session::SessionDiagnostic;
+use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::Span;
-#[derive(SessionDiagnostic)]
-#[diag(parser::expect_path)]
-struct DeriveSessionDiagnostic {
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
+struct DeriveDiagnostic {
#[primary_span]
span: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[note(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[note(compiletest_example)]
struct Note {
#[primary_span]
span: Span,
}
-pub struct UntranslatableInSessionDiagnostic;
+pub struct UntranslatableInIntoDiagnostic;
-impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic {
+impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for UntranslatableInIntoDiagnostic {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
handler.struct_err("untranslatable diagnostic")
//~^ ERROR diagnostics should be created using translatable messages
}
}
-pub struct TranslatableInSessionDiagnostic;
+pub struct TranslatableInIntoDiagnostic;
-impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic {
+impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInIntoDiagnostic {
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
- handler.struct_err(fluent::parser::expect_path)
+ handler.struct_err(fluent::compiletest_example)
}
}
-pub struct UntranslatableInAddSubdiagnostic;
+pub struct UntranslatableInAddToDiagnostic;
-impl AddSubdiagnostic for UntranslatableInAddSubdiagnostic {
- fn add_to_diagnostic(self, diag: &mut Diagnostic) {
+impl AddToDiagnostic for UntranslatableInAddToDiagnostic {
+ fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
+ where
+ F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
+ {
diag.note("untranslatable diagnostic");
//~^ ERROR diagnostics should be created using translatable messages
}
}
-pub struct TranslatableInAddSubdiagnostic;
+pub struct TranslatableInAddToDiagnostic;
-impl AddSubdiagnostic for TranslatableInAddSubdiagnostic {
- fn add_to_diagnostic(self, diag: &mut Diagnostic) {
- diag.note(fluent::typeck::note);
+impl AddToDiagnostic for TranslatableInAddToDiagnostic {
+ fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
+ where
+ F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
+ {
+ diag.note(fluent::note);
}
}
pub fn make_diagnostics<'a>(handler: &'a Handler) {
- let _diag = handler.struct_err(fluent::parser::expect_path);
- //~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
+ let _diag = handler.struct_err(fluent::compiletest_example);
+ //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
let _diag = handler.struct_err("untranslatable diagnostic");
- //~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
+ //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
//~^^ ERROR diagnostics should be created using translatable messages
}
diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.stderr b/src/test/ui-fulldeps/internal-lints/diagnostics.stderr
index e5c5bc2e9..510d6a171 100644
--- a/src/test/ui-fulldeps/internal-lints/diagnostics.stderr
+++ b/src/test/ui-fulldeps/internal-lints/diagnostics.stderr
@@ -11,15 +11,15 @@ LL | #![deny(rustc::untranslatable_diagnostic)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: diagnostics should be created using translatable messages
- --> $DIR/diagnostics.rs:56:14
+ --> $DIR/diagnostics.rs:59:14
|
LL | diag.note("untranslatable diagnostic");
| ^^^^
-error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
- --> $DIR/diagnostics.rs:70:25
+error: diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
+ --> $DIR/diagnostics.rs:76:25
|
-LL | let _diag = handler.struct_err(fluent::parser::expect_path);
+LL | let _diag = handler.struct_err(fluent::compiletest_example);
| ^^^^^^^^^^
|
note: the lint level is defined here
@@ -28,14 +28,14 @@ note: the lint level is defined here
LL | #![deny(rustc::diagnostic_outside_of_impl)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
- --> $DIR/diagnostics.rs:73:25
+error: diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls
+ --> $DIR/diagnostics.rs:79:25
|
LL | let _diag = handler.struct_err("untranslatable diagnostic");
| ^^^^^^^^^^
error: diagnostics should be created using translatable messages
- --> $DIR/diagnostics.rs:73:25
+ --> $DIR/diagnostics.rs:79:25
|
LL | let _diag = handler.struct_err("untranslatable diagnostic");
| ^^^^^^^^^^
diff --git a/src/test/ui-fulldeps/internal-lints/existing_doc_keyword.stderr b/src/test/ui-fulldeps/internal-lints/existing_doc_keyword.stderr
index bc9fcdd7b..4e296fff6 100644
--- a/src/test/ui-fulldeps/internal-lints/existing_doc_keyword.stderr
+++ b/src/test/ui-fulldeps/internal-lints/existing_doc_keyword.stderr
@@ -4,12 +4,12 @@ error: found non-existing keyword `tadam` used in `#[doc(keyword = \"...\")]`
LL | #[doc(keyword = "tadam")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
+ = help: only existing keywords are allowed in core/std
note: the lint level is defined here
--> $DIR/existing_doc_keyword.rs:8:9
|
LL | #![deny(rustc::existing_doc_keyword)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: only existing keywords are allowed in core/std
error: aborting due to previous error
diff --git a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr
index 9df6be65e..ad6e93334 100644
--- a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr
+++ b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr
@@ -4,12 +4,12 @@ error: implementing `LintPass` by hand
LL | impl LintPass for Foo {
| ^^^^^^^^
|
+ = help: try using `declare_lint_pass!` or `impl_lint_pass!` instead
note: the lint level is defined here
--> $DIR/lint_pass_impl_without_macro.rs:4:9
|
LL | #![deny(rustc::lint_pass_impl_without_macro)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: try using `declare_lint_pass!` or `impl_lint_pass!` instead
error: implementing `LintPass` by hand
--> $DIR/lint_pass_impl_without_macro.rs:30:14
diff --git a/src/test/ui-fulldeps/internal-lints/query_stability.stderr b/src/test/ui-fulldeps/internal-lints/query_stability.stderr
index 7e8b448f4..ee4ef9982 100644
--- a/src/test/ui-fulldeps/internal-lints/query_stability.stderr
+++ b/src/test/ui-fulldeps/internal-lints/query_stability.stderr
@@ -4,12 +4,12 @@ error: using `drain` can result in unstable query results
LL | for _ in x.drain() {}
| ^^^^^
|
+ = note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale
note: the lint level is defined here
--> $DIR/query_stability.rs:4:9
|
LL | #![deny(rustc::potential_query_instability)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale
error: using `iter` can result in unstable query results
--> $DIR/query_stability.rs:16:16
diff --git a/src/test/ui-fulldeps/pprust-expr-roundtrip.rs b/src/test/ui-fulldeps/pprust-expr-roundtrip.rs
index da6a84bf3..117b79871 100644
--- a/src/test/ui-fulldeps/pprust-expr-roundtrip.rs
+++ b/src/test/ui-fulldeps/pprust-expr-roundtrip.rs
@@ -73,10 +73,10 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
2 => {
let seg = PathSegment::from_ident(Ident::from_str("x"));
iter_exprs(depth - 1, &mut |e| {
- g(ExprKind::MethodCall(seg.clone(), vec![e, make_x()], DUMMY_SP))
+ g(ExprKind::MethodCall(seg.clone(), e, vec![make_x()], DUMMY_SP))
});
iter_exprs(depth - 1, &mut |e| {
- g(ExprKind::MethodCall(seg.clone(), vec![make_x(), e], DUMMY_SP))
+ g(ExprKind::MethodCall(seg.clone(), make_x(), vec![e], DUMMY_SP))
});
}
3..=8 => {
diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs
index c1c109ac1..ca77e483d 100644
--- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs
+++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs
@@ -1,10 +1,10 @@
// check-fail
-// Tests error conditions for specifying diagnostics using #[derive(SessionDiagnostic)]
+// Tests error conditions for specifying diagnostics using #[derive(Diagnostic)]
// normalize-stderr-test "the following other types implement trait `IntoDiagnosticArg`:(?:.*\n){0,9}\s+and \d+ others" -> "normalized in stderr"
// normalize-stderr-test "diagnostic_builder\.rs:[0-9]+:[0-9]+" -> "diagnostic_builder.rs:LL:CC"
// The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly,
-// changing the output of this test. Since SessionDiagnostic is strictly internal to the compiler
+// changing the output of this test. Since Diagnostic is strictly internal to the compiler
// the test is just ignored on stable and beta:
// ignore-beta
// ignore-stable
@@ -17,7 +17,7 @@ use rustc_span::symbol::Ident;
use rustc_span::Span;
extern crate rustc_macros;
-use rustc_macros::{SessionDiagnostic, LintDiagnostic, SessionSubdiagnostic};
+use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
extern crate rustc_middle;
use rustc_middle::ty::Ty;
@@ -27,116 +27,120 @@ use rustc_errors::{Applicability, MultiSpan};
extern crate rustc_session;
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct Hello {}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct HelloWarn {}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
-//~^ ERROR `#[derive(SessionDiagnostic)]` can only be used on structs
-enum SessionDiagnosticOnEnum {
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
+//~^ ERROR unsupported type attribute for diagnostic derive enum
+enum DiagnosticOnEnum {
Foo,
+//~^ ERROR diagnostic slug not specified
Bar,
+//~^ ERROR diagnostic slug not specified
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
#[diag = "E0123"]
//~^ ERROR `#[diag = ...]` is not a valid attribute
struct WrongStructAttrStyle {}
-#[derive(SessionDiagnostic)]
-#[nonsense(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[nonsense(compiletest_example, code = "E0123")]
//~^ ERROR `#[nonsense(...)]` is not a valid attribute
//~^^ ERROR diagnostic slug not specified
//~^^^ ERROR cannot find attribute `nonsense` in this scope
struct InvalidStructAttr {}
-#[derive(SessionDiagnostic)]
+#[derive(Diagnostic)]
#[diag("E0123")]
//~^ ERROR `#[diag("...")]` is not a valid attribute
//~^^ ERROR diagnostic slug not specified
struct InvalidLitNestedAttr {}
-#[derive(SessionDiagnostic)]
+#[derive(Diagnostic)]
#[diag(nonsense, code = "E0123")]
//~^ ERROR cannot find value `nonsense` in module `rustc_errors::fluent`
struct InvalidNestedStructAttr {}
-#[derive(SessionDiagnostic)]
+#[derive(Diagnostic)]
#[diag(nonsense("foo"), code = "E0123", slug = "foo")]
//~^ ERROR `#[diag(nonsense(...))]` is not a valid attribute
//~^^ ERROR diagnostic slug not specified
struct InvalidNestedStructAttr1 {}
-#[derive(SessionDiagnostic)]
+#[derive(Diagnostic)]
#[diag(nonsense = "...", code = "E0123", slug = "foo")]
//~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute
-//~^^ ERROR diagnostic slug not specified
+//~| ERROR `#[diag(slug = ...)]` is not a valid attribute
+//~| ERROR diagnostic slug not specified
struct InvalidNestedStructAttr2 {}
-#[derive(SessionDiagnostic)]
+#[derive(Diagnostic)]
#[diag(nonsense = 4, code = "E0123", slug = "foo")]
//~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute
-//~^^ ERROR diagnostic slug not specified
+//~| ERROR `#[diag(slug = ...)]` is not a valid attribute
+//~| ERROR diagnostic slug not specified
struct InvalidNestedStructAttr3 {}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123", slug = "foo")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123", slug = "foo")]
//~^ ERROR `#[diag(slug = ...)]` is not a valid attribute
struct InvalidNestedStructAttr4 {}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct WrongPlaceField {
#[suggestion = "bar"]
//~^ ERROR `#[suggestion = ...]` is not a valid attribute
sp: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0456")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
+#[diag(compiletest_example, code = "E0456")]
//~^ ERROR specified multiple times
//~^^ ERROR specified multiple times
struct DiagSpecifiedTwice {}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0456", code = "E0457")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0456", code = "E0457")]
//~^ ERROR specified multiple times
struct CodeSpecifiedTwice {}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, typeck::ambiguous_lifetime_bound, code = "E0456")]
-//~^ ERROR `#[diag(typeck::ambiguous_lifetime_bound)]` is not a valid attribute
+#[derive(Diagnostic)]
+#[diag(compiletest_example, compiletest_example, code = "E0456")]
+//~^ ERROR `#[diag(compiletest_example)]` is not a valid attribute
struct SlugSpecifiedTwice {}
-#[derive(SessionDiagnostic)]
+#[derive(Diagnostic)]
struct KindNotProvided {} //~ ERROR diagnostic slug not specified
-#[derive(SessionDiagnostic)]
+#[derive(Diagnostic)]
#[diag(code = "E0456")]
//~^ ERROR diagnostic slug not specified
struct SlugNotProvided {}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound)]
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
struct CodeNotProvided {}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct MessageWrongType {
#[primary_span]
//~^ ERROR `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan`
foo: String,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct InvalidPathFieldAttr {
#[nonsense]
//~^ ERROR `#[nonsense]` is not a valid attribute
@@ -144,201 +148,204 @@ struct InvalidPathFieldAttr {
foo: String,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithField {
name: String,
- #[label(typeck::label)]
+ #[label(label)]
span: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithMessageAppliedToField {
- #[label(typeck::label)]
+ #[label(label)]
//~^ ERROR the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
name: String,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithNonexistentField {
- #[suggestion(typeck::suggestion, code = "{name}")]
+ #[suggestion(suggestion, code = "{name}")]
//~^ ERROR `name` doesn't refer to a field on this type
suggestion: (Span, Applicability),
}
-#[derive(SessionDiagnostic)]
+#[derive(Diagnostic)]
//~^ ERROR invalid format string: expected `'}'`
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorMissingClosingBrace {
- #[suggestion(typeck::suggestion, code = "{name")]
+ #[suggestion(suggestion, code = "{name")]
suggestion: (Span, Applicability),
name: String,
val: usize,
}
-#[derive(SessionDiagnostic)]
+#[derive(Diagnostic)]
//~^ ERROR invalid format string: unmatched `}`
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorMissingOpeningBrace {
- #[suggestion(typeck::suggestion, code = "name}")]
+ #[suggestion(suggestion, code = "name}")]
suggestion: (Span, Applicability),
name: String,
val: usize,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct LabelOnSpan {
- #[label(typeck::label)]
+ #[label(label)]
sp: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct LabelOnNonSpan {
- #[label(typeck::label)]
+ #[label(label)]
//~^ ERROR the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
id: u32,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct Suggest {
- #[suggestion(typeck::suggestion, code = "This is the suggested code")]
- #[suggestion_short(typeck::suggestion, code = "This is the suggested code")]
- #[suggestion_hidden(typeck::suggestion, code = "This is the suggested code")]
- #[suggestion_verbose(typeck::suggestion, code = "This is the suggested code")]
+ #[suggestion(suggestion, code = "This is the suggested code")]
+ #[suggestion_short(suggestion, code = "This is the suggested code")]
+ #[suggestion_hidden(suggestion, code = "This is the suggested code")]
+ #[suggestion_verbose(suggestion, code = "This is the suggested code")]
suggestion: (Span, Applicability),
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct SuggestWithoutCode {
- #[suggestion(typeck::suggestion)]
+ #[suggestion(suggestion)]
+ //~^ ERROR suggestion without `code = "..."`
suggestion: (Span, Applicability),
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct SuggestWithBadKey {
#[suggestion(nonsense = "bar")]
//~^ ERROR `#[suggestion(nonsense = ...)]` is not a valid attribute
+ //~| ERROR suggestion without `code = "..."`
suggestion: (Span, Applicability),
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct SuggestWithShorthandMsg {
#[suggestion(msg = "bar")]
//~^ ERROR `#[suggestion(msg = ...)]` is not a valid attribute
+ //~| ERROR suggestion without `code = "..."`
suggestion: (Span, Applicability),
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct SuggestWithoutMsg {
#[suggestion(code = "bar")]
suggestion: (Span, Applicability),
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct SuggestWithTypesSwapped {
- #[suggestion(typeck::suggestion, code = "This is suggested code")]
+ #[suggestion(suggestion, code = "This is suggested code")]
suggestion: (Applicability, Span),
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct SuggestWithWrongTypeApplicabilityOnly {
- #[suggestion(typeck::suggestion, code = "This is suggested code")]
+ #[suggestion(suggestion, code = "This is suggested code")]
//~^ ERROR wrong field type for suggestion
suggestion: Applicability,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct SuggestWithSpanOnly {
- #[suggestion(typeck::suggestion, code = "This is suggested code")]
+ #[suggestion(suggestion, code = "This is suggested code")]
suggestion: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct SuggestWithDuplicateSpanAndApplicability {
- #[suggestion(typeck::suggestion, code = "This is suggested code")]
- //~^ ERROR type of field annotated with `#[suggestion(...)]` contains more than one `Span`
+ #[suggestion(suggestion, code = "This is suggested code")]
suggestion: (Span, Span, Applicability),
+ //~^ ERROR specified multiple times
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct SuggestWithDuplicateApplicabilityAndSpan {
- #[suggestion(typeck::suggestion, code = "This is suggested code")]
- //~^ ERROR type of field annotated with `#[suggestion(...)]` contains more than one
+ #[suggestion(suggestion, code = "This is suggested code")]
suggestion: (Applicability, Applicability, Span),
+ //~^ ERROR specified multiple times
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct WrongKindOfAnnotation {
#[label = "bar"]
//~^ ERROR `#[label = ...]` is not a valid attribute
z: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct OptionsInErrors {
- #[label(typeck::label)]
+ #[label(label)]
label: Option<Span>,
- #[suggestion(typeck::suggestion)]
+ #[suggestion(suggestion, code = "...")]
opt_sugg: Option<(Span, Applicability)>,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0456")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0456")]
struct MoveOutOfBorrowError<'tcx> {
name: Ident,
ty: Ty<'tcx>,
#[primary_span]
- #[label(typeck::label)]
+ #[label(label)]
span: Span,
- #[label(typeck::label)]
+ #[label(label)]
other_span: Span,
- #[suggestion(typeck::suggestion, code = "{name}.clone()")]
+ #[suggestion(suggestion, code = "{name}.clone()")]
opt_sugg: Option<(Span, Applicability)>,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithLifetime<'a> {
- #[label(typeck::label)]
+ #[label(label)]
span: Span,
name: &'a str,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithDefaultLabelAttr<'a> {
#[label]
span: Span,
name: &'a str,
}
-#[derive(SessionDiagnostic)]
+#[derive(Diagnostic)]
//~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[diag(compiletest_example, code = "E0123")]
struct ArgFieldWithoutSkip {
#[primary_span]
span: Span,
other: Hello,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct ArgFieldWithSkip {
#[primary_span]
span: Span,
@@ -348,236 +355,444 @@ struct ArgFieldWithSkip {
other: Hello,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithSpannedNote {
#[note]
span: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithSpannedNoteCustom {
- #[note(typeck::note)]
+ #[note(note)]
span: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
#[note]
struct ErrorWithNote {
val: String,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
-#[note(typeck::note)]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
+#[note(note)]
struct ErrorWithNoteCustom {
val: String,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithSpannedHelp {
#[help]
span: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithSpannedHelpCustom {
- #[help(typeck::help)]
+ #[help(help)]
span: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
#[help]
struct ErrorWithHelp {
val: String,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
-#[help(typeck::help)]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
+#[help(help)]
struct ErrorWithHelpCustom {
val: String,
}
-#[derive(SessionDiagnostic)]
+#[derive(Diagnostic)]
#[help]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithHelpWrongOrder {
val: String,
}
-#[derive(SessionDiagnostic)]
-#[help(typeck::help)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[help(help)]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithHelpCustomWrongOrder {
val: String,
}
-#[derive(SessionDiagnostic)]
+#[derive(Diagnostic)]
#[note]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithNoteWrongOrder {
val: String,
}
-#[derive(SessionDiagnostic)]
-#[note(typeck::note)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[note(note)]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithNoteCustomWrongOrder {
val: String,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct ApplicabilityInBoth {
- #[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")]
- //~^ ERROR applicability cannot be set in both the field and attribute
+ #[suggestion(suggestion, code = "...", applicability = "maybe-incorrect")]
+ //~^ ERROR specified multiple times
suggestion: (Span, Applicability),
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct InvalidApplicability {
- #[suggestion(typeck::suggestion, code = "...", applicability = "batman")]
+ #[suggestion(suggestion, code = "...", applicability = "batman")]
//~^ ERROR invalid applicability
suggestion: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct ValidApplicability {
- #[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")]
+ #[suggestion(suggestion, code = "...", applicability = "maybe-incorrect")]
suggestion: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct NoApplicability {
- #[suggestion(typeck::suggestion, code = "...")]
+ #[suggestion(suggestion, code = "...")]
suggestion: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[note(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[note(parser_add_paren)]
struct Note;
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound)]
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
struct Subdiagnostic {
#[subdiagnostic]
note: Note,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct VecField {
#[primary_span]
#[label]
spans: Vec<Span>,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct UnitField {
#[primary_span]
spans: Span,
#[help]
foo: (),
- #[help(typeck::help)]
+ #[help(help)]
bar: (),
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct OptUnitField {
#[primary_span]
spans: Span,
#[help]
foo: Option<()>,
- #[help(typeck::help)]
+ #[help(help)]
bar: Option<()>,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct LabelWithTrailingPath {
- #[label(typeck::label, foo)]
- //~^ ERROR `#[label(...)]` is not a valid attribute
+ #[label(label, foo)]
+ //~^ ERROR `#[label(foo)]` is not a valid attribute
span: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct LabelWithTrailingNameValue {
- #[label(typeck::label, foo = "...")]
- //~^ ERROR `#[label(...)]` is not a valid attribute
+ #[label(label, foo = "...")]
+ //~^ ERROR `#[label(foo = ...)]` is not a valid attribute
span: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct LabelWithTrailingList {
- #[label(typeck::label, foo("..."))]
- //~^ ERROR `#[label(...)]` is not a valid attribute
+ #[label(label, foo("..."))]
+ //~^ ERROR `#[label(foo(...))]` is not a valid attribute
span: Span,
}
#[derive(LintDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound)]
+#[diag(compiletest_example)]
struct LintsGood {
}
#[derive(LintDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound)]
+#[diag(compiletest_example)]
struct PrimarySpanOnLint {
#[primary_span]
//~^ ERROR `#[primary_span]` is not a valid attribute
span: Span,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
struct ErrorWithMultiSpan {
#[primary_span]
span: MultiSpan,
}
-#[derive(SessionDiagnostic)]
-#[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
#[warning]
struct ErrorWithWarn {
val: String,
}
-#[derive(SessionDiagnostic)]
-#[error(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[error(compiletest_example, code = "E0123")]
//~^ ERROR `#[error(...)]` is not a valid attribute
//~| ERROR diagnostic slug not specified
//~| ERROR cannot find attribute `error` in this scope
struct ErrorAttribute {}
-#[derive(SessionDiagnostic)]
-#[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[warn_(compiletest_example, code = "E0123")]
//~^ ERROR `#[warn_(...)]` is not a valid attribute
//~| ERROR diagnostic slug not specified
//~| ERROR cannot find attribute `warn_` in this scope
struct WarnAttribute {}
-#[derive(SessionDiagnostic)]
-#[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[derive(Diagnostic)]
+#[lint(compiletest_example, code = "E0123")]
//~^ ERROR `#[lint(...)]` is not a valid attribute
//~| ERROR diagnostic slug not specified
//~| ERROR cannot find attribute `lint` in this scope
struct LintAttributeOnSessionDiag {}
#[derive(LintDiagnostic)]
-#[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]
+#[lint(compiletest_example, code = "E0123")]
//~^ ERROR `#[lint(...)]` is not a valid attribute
+//~| ERROR `#[lint(...)]` is not a valid attribute
//~| ERROR diagnostic slug not specified
//~| ERROR cannot find attribute `lint` in this scope
struct LintAttributeOnLintDiag {}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
+struct DuplicatedSuggestionCode {
+ #[suggestion(suggestion, code = "...", code = ",,,")]
+ //~^ ERROR specified multiple times
+ suggestion: Span,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
+struct InvalidTypeInSuggestionTuple {
+ #[suggestion(suggestion, code = "...")]
+ suggestion: (Span, usize),
+ //~^ ERROR wrong types for suggestion
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
+struct MissingApplicabilityInSuggestionTuple {
+ #[suggestion(suggestion, code = "...")]
+ suggestion: (Span,),
+ //~^ ERROR wrong types for suggestion
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
+struct MissingCodeInSuggestion {
+ #[suggestion(suggestion)]
+ //~^ ERROR suggestion without `code = "..."`
+ suggestion: Span,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
+#[multipart_suggestion(suggestion)]
+//~^ ERROR `#[multipart_suggestion(...)]` is not a valid attribute
+//~| ERROR cannot find attribute `multipart_suggestion` in this scope
+#[multipart_suggestion()]
+//~^ ERROR `#[multipart_suggestion(...)]` is not a valid attribute
+//~| ERROR cannot find attribute `multipart_suggestion` in this scope
+struct MultipartSuggestion {
+ #[multipart_suggestion(suggestion)]
+ //~^ ERROR `#[multipart_suggestion(...)]` is not a valid attribute
+ //~| ERROR cannot find attribute `multipart_suggestion` in this scope
+ suggestion: Span,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
+#[suggestion(suggestion, code = "...")]
+//~^ ERROR `#[suggestion(...)]` is not a valid attribute
+struct SuggestionOnStruct {
+ #[primary_span]
+ suggestion: Span,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
+#[label]
+//~^ ERROR `#[label]` is not a valid attribute
+struct LabelOnStruct {
+ #[primary_span]
+ suggestion: Span,
+}
+
+#[derive(Diagnostic)]
+enum ExampleEnum {
+ #[diag(compiletest_example)]
+ Foo {
+ #[primary_span]
+ sp: Span,
+ #[note]
+ note_sp: Span,
+ },
+ #[diag(compiletest_example)]
+ Bar {
+ #[primary_span]
+ sp: Span,
+ },
+ #[diag(compiletest_example)]
+ Baz,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
+struct RawIdentDiagnosticArg {
+ pub r#type: String,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
+struct SubdiagnosticBad {
+ #[subdiagnostic(bad)]
+//~^ ERROR `#[subdiagnostic(bad)]` is not a valid attribute
+ note: Note,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
+struct SubdiagnosticBadStr {
+ #[subdiagnostic = "bad"]
+//~^ ERROR `#[subdiagnostic = ...]` is not a valid attribute
+ note: Note,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
+struct SubdiagnosticBadTwice {
+ #[subdiagnostic(bad, bad)]
+//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
+ note: Note,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
+struct SubdiagnosticBadLitStr {
+ #[subdiagnostic("bad")]
+//~^ ERROR `#[subdiagnostic("...")]` is not a valid attribute
+ note: Note,
+}
+
+#[derive(LintDiagnostic)]
+#[diag(compiletest_example)]
+struct SubdiagnosticEagerLint {
+ #[subdiagnostic(eager)]
+//~^ ERROR `#[subdiagnostic(...)]` is not a valid attribute
+ note: Note,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
+struct SubdiagnosticEagerCorrect {
+ #[subdiagnostic(eager)]
+ note: Note,
+}
+
+// Check that formatting of `correct` in suggestion doesn't move the binding for that field, making
+// the `set_arg` call a compile error; and that isn't worked around by moving the `set_arg` call
+// after the `span_suggestion` call - which breaks eager translation.
+
+#[derive(Subdiagnostic)]
+#[suggestion_short(
+ use_instead,
+ applicability = "machine-applicable",
+ code = "{correct}"
+)]
+pub(crate) struct SubdiagnosticWithSuggestion {
+ #[primary_span]
+ span: Span,
+ invalid: String,
+ correct: String,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
+struct SubdiagnosticEagerSuggestion {
+ #[subdiagnostic(eager)]
+ sub: SubdiagnosticWithSuggestion,
+}
+
+/// with a doc comment on the type..
+#[derive(Diagnostic)]
+#[diag(compiletest_example, code = "E0123")]
+struct WithDocComment {
+ /// ..and the field
+ #[primary_span]
+ span: Span,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
+struct SuggestionsGood {
+ #[suggestion(code("foo", "bar"))]
+ sub: Span,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
+struct SuggestionsSingleItem {
+ #[suggestion(code("foo"))]
+ sub: Span,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
+struct SuggestionsNoItem {
+ #[suggestion(code())]
+ //~^ ERROR expected at least one string literal for `code(...)`
+ sub: Span,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
+struct SuggestionsInvalidItem {
+ #[suggestion(code(foo))]
+ //~^ ERROR `code(...)` must contain only string literals
+ sub: Span,
+}
+
+#[derive(Diagnostic)]
+#[diag(compiletest_example)]
+struct SuggestionsInvalidLiteral {
+ #[suggestion(code = 3)]
+ //~^ ERROR `code = "..."`/`code(...)` must contain only string literals
+ sub: Span,
+}
diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr
index ab5c28fe4..859c272b6 100644
--- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr
+++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr
@@ -1,50 +1,59 @@
-error: `#[derive(SessionDiagnostic)]` can only be used on structs
+error: unsupported type attribute for diagnostic derive enum
--> $DIR/diagnostic-derive.rs:39:1
|
-LL | / #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
-LL | |
-LL | | enum SessionDiagnosticOnEnum {
-LL | | Foo,
-LL | | Bar,
-LL | | }
- | |_^
+LL | #[diag(compiletest_example, code = "E0123")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: diagnostic slug not specified
+ --> $DIR/diagnostic-derive.rs:42:5
+ |
+LL | Foo,
+ | ^^^
+ |
+ = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
+
+error: diagnostic slug not specified
+ --> $DIR/diagnostic-derive.rs:44:5
+ |
+LL | Bar,
+ | ^^^
+ |
+ = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
error: `#[diag = ...]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:48:1
+ --> $DIR/diagnostic-derive.rs:50:1
|
LL | #[diag = "E0123"]
| ^^^^^^^^^^^^^^^^^
error: `#[nonsense(...)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:53:1
+ --> $DIR/diagnostic-derive.rs:55:1
|
-LL | #[nonsense(typeck::ambiguous_lifetime_bound, code = "E0123")]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: only `diag`, `help`, `note` and `warning` are valid attributes
+LL | #[nonsense(compiletest_example, code = "E0123")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: diagnostic slug not specified
- --> $DIR/diagnostic-derive.rs:53:1
+ --> $DIR/diagnostic-derive.rs:55:1
|
-LL | / #[nonsense(typeck::ambiguous_lifetime_bound, code = "E0123")]
+LL | / #[nonsense(compiletest_example, code = "E0123")]
LL | |
LL | |
LL | |
LL | | struct InvalidStructAttr {}
| |___________________________^
|
- = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]`
+ = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
error: `#[diag("...")]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:60:8
+ --> $DIR/diagnostic-derive.rs:62:8
|
LL | #[diag("E0123")]
| ^^^^^^^
|
- = help: first argument of the attribute should be the diagnostic slug
+ = help: a diagnostic slug is required as the first argument
error: diagnostic slug not specified
- --> $DIR/diagnostic-derive.rs:60:1
+ --> $DIR/diagnostic-derive.rs:62:1
|
LL | / #[diag("E0123")]
LL | |
@@ -52,18 +61,18 @@ LL | |
LL | | struct InvalidLitNestedAttr {}
| |______________________________^
|
- = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]`
+ = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
error: `#[diag(nonsense(...))]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:71:8
+ --> $DIR/diagnostic-derive.rs:73:8
|
LL | #[diag(nonsense("foo"), code = "E0123", slug = "foo")]
| ^^^^^^^^^^^^^^^
|
- = help: first argument of the attribute should be the diagnostic slug
+ = help: a diagnostic slug is required as the first argument
error: diagnostic slug not specified
- --> $DIR/diagnostic-derive.rs:71:1
+ --> $DIR/diagnostic-derive.rs:73:1
|
LL | / #[diag(nonsense("foo"), code = "E0123", slug = "foo")]
LL | |
@@ -71,252 +80,300 @@ LL | |
LL | | struct InvalidNestedStructAttr1 {}
| |__________________________________^
|
- = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]`
+ = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
error: `#[diag(nonsense = ...)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:77:8
+ --> $DIR/diagnostic-derive.rs:79:8
|
LL | #[diag(nonsense = "...", code = "E0123", slug = "foo")]
| ^^^^^^^^^^^^^^^^
|
- = help: first argument of the attribute should be the diagnostic slug
+ = help: only `code` is a valid nested attributes following the slug
+
+error: `#[diag(slug = ...)]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:79:42
+ |
+LL | #[diag(nonsense = "...", code = "E0123", slug = "foo")]
+ | ^^^^^^^^^^^^
+ |
+ = help: only `code` is a valid nested attributes following the slug
error: diagnostic slug not specified
- --> $DIR/diagnostic-derive.rs:77:1
+ --> $DIR/diagnostic-derive.rs:79:1
|
LL | / #[diag(nonsense = "...", code = "E0123", slug = "foo")]
LL | |
LL | |
+LL | |
LL | | struct InvalidNestedStructAttr2 {}
| |__________________________________^
|
- = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]`
+ = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
error: `#[diag(nonsense = ...)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:83:8
+ --> $DIR/diagnostic-derive.rs:86:8
|
LL | #[diag(nonsense = 4, code = "E0123", slug = "foo")]
| ^^^^^^^^^^^^
+
+error: `#[diag(slug = ...)]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:86:38
|
- = help: first argument of the attribute should be the diagnostic slug
+LL | #[diag(nonsense = 4, code = "E0123", slug = "foo")]
+ | ^^^^^^^^^^^^
+ |
+ = help: only `code` is a valid nested attributes following the slug
error: diagnostic slug not specified
- --> $DIR/diagnostic-derive.rs:83:1
+ --> $DIR/diagnostic-derive.rs:86:1
|
LL | / #[diag(nonsense = 4, code = "E0123", slug = "foo")]
LL | |
LL | |
+LL | |
LL | | struct InvalidNestedStructAttr3 {}
| |__________________________________^
|
- = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]`
+ = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
error: `#[diag(slug = ...)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:89:58
+ --> $DIR/diagnostic-derive.rs:93:45
|
-LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0123", slug = "foo")]
- | ^^^^^^^^^^^^
+LL | #[diag(compiletest_example, code = "E0123", slug = "foo")]
+ | ^^^^^^^^^^^^
|
= help: only `code` is a valid nested attributes following the slug
error: `#[suggestion = ...]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:96:5
+ --> $DIR/diagnostic-derive.rs:100:5
|
LL | #[suggestion = "bar"]
| ^^^^^^^^^^^^^^^^^^^^^
error: specified multiple times
- --> $DIR/diagnostic-derive.rs:103:1
+ --> $DIR/diagnostic-derive.rs:107:8
|
-LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0456")]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[diag(compiletest_example, code = "E0456")]
+ | ^^^^^^^^^^^^^^^^^^^
|
note: previously specified here
- --> $DIR/diagnostic-derive.rs:102:1
+ --> $DIR/diagnostic-derive.rs:106:8
|
-LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[diag(compiletest_example, code = "E0123")]
+ | ^^^^^^^^^^^^^^^^^^^
error: specified multiple times
- --> $DIR/diagnostic-derive.rs:103:49
+ --> $DIR/diagnostic-derive.rs:107:36
|
-LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0456")]
- | ^^^^^^^
+LL | #[diag(compiletest_example, code = "E0456")]
+ | ^^^^^^^
|
note: previously specified here
- --> $DIR/diagnostic-derive.rs:102:49
+ --> $DIR/diagnostic-derive.rs:106:36
|
-LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")]
- | ^^^^^^^
+LL | #[diag(compiletest_example, code = "E0123")]
+ | ^^^^^^^
error: specified multiple times
- --> $DIR/diagnostic-derive.rs:109:65
+ --> $DIR/diagnostic-derive.rs:113:52
|
-LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0456", code = "E0457")]
- | ^^^^^^^
+LL | #[diag(compiletest_example, code = "E0456", code = "E0457")]
+ | ^^^^^^^
|
note: previously specified here
- --> $DIR/diagnostic-derive.rs:109:49
+ --> $DIR/diagnostic-derive.rs:113:36
|
-LL | #[diag(typeck::ambiguous_lifetime_bound, code = "E0456", code = "E0457")]
- | ^^^^^^^
+LL | #[diag(compiletest_example, code = "E0456", code = "E0457")]
+ | ^^^^^^^
-error: `#[diag(typeck::ambiguous_lifetime_bound)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:114:42
+error: `#[diag(compiletest_example)]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:118:29
+ |
+LL | #[diag(compiletest_example, compiletest_example, code = "E0456")]
+ | ^^^^^^^^^^^^^^^^^^^
|
-LL | #[diag(typeck::ambiguous_lifetime_bound, typeck::ambiguous_lifetime_bound, code = "E0456")]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = help: diagnostic slug must be the first argument
error: diagnostic slug not specified
- --> $DIR/diagnostic-derive.rs:119:1
+ --> $DIR/diagnostic-derive.rs:123:1
|
LL | struct KindNotProvided {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]`
+ = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
error: diagnostic slug not specified
- --> $DIR/diagnostic-derive.rs:122:1
+ --> $DIR/diagnostic-derive.rs:126:1
|
LL | / #[diag(code = "E0456")]
LL | |
LL | | struct SlugNotProvided {}
| |_________________________^
|
- = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]`
+ = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
error: the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan`
- --> $DIR/diagnostic-derive.rs:133:5
+ --> $DIR/diagnostic-derive.rs:137:5
|
LL | #[primary_span]
| ^^^^^^^^^^^^^^^
error: `#[nonsense]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:141:5
+ --> $DIR/diagnostic-derive.rs:145:5
|
LL | #[nonsense]
| ^^^^^^^^^^^
- |
- = help: only `skip_arg`, `primary_span`, `label`, `note`, `help` and `subdiagnostic` are valid field attributes
error: the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
- --> $DIR/diagnostic-derive.rs:158:5
+ --> $DIR/diagnostic-derive.rs:162:5
|
-LL | #[label(typeck::label)]
- | ^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[label(label)]
+ | ^^^^^^^^^^^^^^^
error: `name` doesn't refer to a field on this type
- --> $DIR/diagnostic-derive.rs:166:45
+ --> $DIR/diagnostic-derive.rs:170:37
|
-LL | #[suggestion(typeck::suggestion, code = "{name}")]
- | ^^^^^^^^
+LL | #[suggestion(suggestion, code = "{name}")]
+ | ^^^^^^^^
error: invalid format string: expected `'}'` but string was terminated
- --> $DIR/diagnostic-derive.rs:171:16
+ --> $DIR/diagnostic-derive.rs:175:10
|
-LL | #[derive(SessionDiagnostic)]
- | - ^ expected `'}'` in format string
- | |
- | because of this opening brace
+LL | #[derive(Diagnostic)]
+ | ^^^^^^^^^^ expected `'}'` in format string
|
= note: if you intended to print `{`, you can escape it using `{{`
- = note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
+ = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
error: invalid format string: unmatched `}` found
- --> $DIR/diagnostic-derive.rs:181:15
+ --> $DIR/diagnostic-derive.rs:185:10
|
-LL | #[derive(SessionDiagnostic)]
- | ^ unmatched `}` in format string
+LL | #[derive(Diagnostic)]
+ | ^^^^^^^^^^ unmatched `}` in format string
|
= note: if you intended to print `}`, you can escape it using `}}`
- = note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
+ = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
error: the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
- --> $DIR/diagnostic-derive.rs:201:5
+ --> $DIR/diagnostic-derive.rs:205:5
|
-LL | #[label(typeck::label)]
- | ^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[label(label)]
+ | ^^^^^^^^^^^^^^^
+
+error: suggestion without `code = "..."`
+ --> $DIR/diagnostic-derive.rs:223:5
+ |
+LL | #[suggestion(suggestion)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: `#[suggestion(nonsense = ...)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:226:18
+ --> $DIR/diagnostic-derive.rs:231:18
|
LL | #[suggestion(nonsense = "bar")]
| ^^^^^^^^^^^^^^^^
|
- = help: only `message`, `code` and `applicability` are valid field attributes
+ = help: only `code` and `applicability` are valid nested attributes
+
+error: suggestion without `code = "..."`
+ --> $DIR/diagnostic-derive.rs:231:5
+ |
+LL | #[suggestion(nonsense = "bar")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `#[suggestion(msg = ...)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:234:18
+ --> $DIR/diagnostic-derive.rs:240:18
|
LL | #[suggestion(msg = "bar")]
| ^^^^^^^^^^^
|
- = help: only `message`, `code` and `applicability` are valid field attributes
+ = help: only `code` and `applicability` are valid nested attributes
+
+error: suggestion without `code = "..."`
+ --> $DIR/diagnostic-derive.rs:240:5
+ |
+LL | #[suggestion(msg = "bar")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: wrong field type for suggestion
- --> $DIR/diagnostic-derive.rs:256:5
+ --> $DIR/diagnostic-derive.rs:263:5
|
-LL | / #[suggestion(typeck::suggestion, code = "This is suggested code")]
+LL | / #[suggestion(suggestion, code = "This is suggested code")]
LL | |
LL | | suggestion: Applicability,
| |_____________________________^
|
= help: `#[suggestion(...)]` should be applied to fields of type `Span` or `(Span, Applicability)`
-error: type of field annotated with `#[suggestion(...)]` contains more than one `Span`
- --> $DIR/diagnostic-derive.rs:271:5
+error: specified multiple times
+ --> $DIR/diagnostic-derive.rs:279:24
|
-LL | / #[suggestion(typeck::suggestion, code = "This is suggested code")]
-LL | |
-LL | | suggestion: (Span, Span, Applicability),
- | |___________________________________________^
+LL | suggestion: (Span, Span, Applicability),
+ | ^^^^
+ |
+note: previously specified here
+ --> $DIR/diagnostic-derive.rs:279:18
+ |
+LL | suggestion: (Span, Span, Applicability),
+ | ^^^^
-error: type of field annotated with `#[suggestion(...)]` contains more than one Applicability
- --> $DIR/diagnostic-derive.rs:279:5
+error: specified multiple times
+ --> $DIR/diagnostic-derive.rs:287:33
|
-LL | / #[suggestion(typeck::suggestion, code = "This is suggested code")]
-LL | |
-LL | | suggestion: (Applicability, Applicability, Span),
- | |____________________________________________________^
+LL | suggestion: (Applicability, Applicability, Span),
+ | ^^^^^^^^^^^^^
+ |
+note: previously specified here
+ --> $DIR/diagnostic-derive.rs:287:18
+ |
+LL | suggestion: (Applicability, Applicability, Span),
+ | ^^^^^^^^^^^^^
error: `#[label = ...]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:287:5
+ --> $DIR/diagnostic-derive.rs:294:5
|
LL | #[label = "bar"]
| ^^^^^^^^^^^^^^^^
-error: applicability cannot be set in both the field and attribute
- --> $DIR/diagnostic-derive.rs:438:52
+error: specified multiple times
+ --> $DIR/diagnostic-derive.rs:445:44
+ |
+LL | #[suggestion(suggestion, code = "...", applicability = "maybe-incorrect")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: previously specified here
+ --> $DIR/diagnostic-derive.rs:447:24
|
-LL | #[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | suggestion: (Span, Applicability),
+ | ^^^^^^^^^^^^^
error: invalid applicability
- --> $DIR/diagnostic-derive.rs:446:52
+ --> $DIR/diagnostic-derive.rs:453:44
|
-LL | #[suggestion(typeck::suggestion, code = "...", applicability = "batman")]
- | ^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[suggestion(suggestion, code = "...", applicability = "batman")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
-error: `#[label(...)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:509:5
+error: `#[label(foo)]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:516:20
|
-LL | #[label(typeck::label, foo)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[label(label, foo)]
+ | ^^^
+ |
+ = help: a diagnostic slug must be the first argument to the attribute
-error: `#[label(...)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:517:5
+error: `#[label(foo = ...)]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:524:20
|
-LL | #[label(typeck::label, foo = "...")]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[label(label, foo = "...")]
+ | ^^^^^^^^^^^
-error: `#[label(...)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:525:5
+error: `#[label(foo(...))]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:532:20
|
-LL | #[label(typeck::label, foo("..."))]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[label(label, foo("..."))]
+ | ^^^^^^^^^^
error: `#[primary_span]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:538:5
+ --> $DIR/diagnostic-derive.rs:545:5
|
LL | #[primary_span]
| ^^^^^^^^^^^^^^^
@@ -324,132 +381,281 @@ LL | #[primary_span]
= help: the `primary_span` field attribute is not valid for lint diagnostics
error: `#[error(...)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:558:1
- |
-LL | #[error(typeck::ambiguous_lifetime_bound, code = "E0123")]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ --> $DIR/diagnostic-derive.rs:565:1
|
- = help: `error` and `lint` have been replaced by `diag`
+LL | #[error(compiletest_example, code = "E0123")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: diagnostic slug not specified
- --> $DIR/diagnostic-derive.rs:558:1
+ --> $DIR/diagnostic-derive.rs:565:1
|
-LL | / #[error(typeck::ambiguous_lifetime_bound, code = "E0123")]
+LL | / #[error(compiletest_example, code = "E0123")]
LL | |
LL | |
LL | |
LL | | struct ErrorAttribute {}
| |________________________^
|
- = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]`
+ = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
error: `#[warn_(...)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:565:1
- |
-LL | #[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ --> $DIR/diagnostic-derive.rs:572:1
|
- = help: `warn_` have been replaced by `warning`
+LL | #[warn_(compiletest_example, code = "E0123")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: diagnostic slug not specified
- --> $DIR/diagnostic-derive.rs:565:1
+ --> $DIR/diagnostic-derive.rs:572:1
|
-LL | / #[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")]
+LL | / #[warn_(compiletest_example, code = "E0123")]
LL | |
LL | |
LL | |
LL | | struct WarnAttribute {}
| |_______________________^
|
- = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]`
+ = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
error: `#[lint(...)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:572:1
- |
-LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ --> $DIR/diagnostic-derive.rs:579:1
|
- = help: `error` and `lint` have been replaced by `diag`
+LL | #[lint(compiletest_example, code = "E0123")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: diagnostic slug not specified
- --> $DIR/diagnostic-derive.rs:572:1
+ --> $DIR/diagnostic-derive.rs:579:1
|
-LL | / #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]
+LL | / #[lint(compiletest_example, code = "E0123")]
LL | |
LL | |
LL | |
LL | | struct LintAttributeOnSessionDiag {}
| |____________________________________^
|
- = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(typeck::example_error)]`
+ = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]`
error: `#[lint(...)]` is not a valid attribute
- --> $DIR/diagnostic-derive.rs:579:1
+ --> $DIR/diagnostic-derive.rs:586:1
|
-LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[lint(compiletest_example, code = "E0123")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: `#[lint(...)]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:586:1
|
- = help: `error` and `lint` have been replaced by `diag`
+LL | #[lint(compiletest_example, code = "E0123")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: diagnostic slug not specified
- --> $DIR/diagnostic-derive.rs:579:1
+ --> $DIR/diagnostic-derive.rs:586:1
|
-LL | / #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]
+LL | / #[lint(compiletest_example, code = "E0123")]
+LL | |
LL | |
LL | |
LL | |
LL | | struct LintAttributeOnLintDiag {}
| |_________________________________^
|
- = help: specify the slug as the first argument to the attribute, such as `#[diag(typeck::example_error)]`
+ = help: specify the slug as the first argument to the attribute, such as `#[diag(compiletest_example)]`
+
+error: specified multiple times
+ --> $DIR/diagnostic-derive.rs:596:44
+ |
+LL | #[suggestion(suggestion, code = "...", code = ",,,")]
+ | ^^^^^^^^^^^^
+ |
+note: previously specified here
+ --> $DIR/diagnostic-derive.rs:596:30
+ |
+LL | #[suggestion(suggestion, code = "...", code = ",,,")]
+ | ^^^^^^^^^^^^
+
+error: wrong types for suggestion
+ --> $DIR/diagnostic-derive.rs:605:24
+ |
+LL | suggestion: (Span, usize),
+ | ^^^^^
+ |
+ = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)`
+
+error: wrong types for suggestion
+ --> $DIR/diagnostic-derive.rs:613:17
+ |
+LL | suggestion: (Span,),
+ | ^^^^^^^
+ |
+ = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)`
+
+error: suggestion without `code = "..."`
+ --> $DIR/diagnostic-derive.rs:620:5
+ |
+LL | #[suggestion(suggestion)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: `#[multipart_suggestion(...)]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:627:1
+ |
+LL | #[multipart_suggestion(suggestion)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: consider creating a `Subdiagnostic` instead
+
+error: `#[multipart_suggestion(...)]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:630:1
+ |
+LL | #[multipart_suggestion()]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: consider creating a `Subdiagnostic` instead
+
+error: `#[multipart_suggestion(...)]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:634:5
+ |
+LL | #[multipart_suggestion(suggestion)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: consider creating a `Subdiagnostic` instead
+
+error: `#[suggestion(...)]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:642:1
+ |
+LL | #[suggestion(suggestion, code = "...")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: `#[label]` and `#[suggestion]` can only be applied to fields
+
+error: `#[label]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:651:1
+ |
+LL | #[label]
+ | ^^^^^^^^
+ |
+ = help: `#[label]` and `#[suggestion]` can only be applied to fields
+
+error: `#[subdiagnostic(bad)]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:685:21
+ |
+LL | #[subdiagnostic(bad)]
+ | ^^^
+ |
+ = help: `eager` is the only supported nested attribute for `subdiagnostic`
+
+error: `#[subdiagnostic = ...]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:693:5
+ |
+LL | #[subdiagnostic = "bad"]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: `eager` is the only supported nested attribute for `subdiagnostic`
+
+error: `#[subdiagnostic(...)]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:701:5
+ |
+LL | #[subdiagnostic(bad, bad)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: `eager` is the only supported nested attribute for `subdiagnostic`
+
+error: `#[subdiagnostic("...")]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:709:21
+ |
+LL | #[subdiagnostic("bad")]
+ | ^^^^^
+ |
+ = help: `eager` is the only supported nested attribute for `subdiagnostic`
+
+error: `#[subdiagnostic(...)]` is not a valid attribute
+ --> $DIR/diagnostic-derive.rs:717:5
+ |
+LL | #[subdiagnostic(eager)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: eager subdiagnostics are not supported on lints
+
+error: expected at least one string literal for `code(...)`
+ --> $DIR/diagnostic-derive.rs:779:18
+ |
+LL | #[suggestion(code())]
+ | ^^^^^^
+
+error: `code(...)` must contain only string literals
+ --> $DIR/diagnostic-derive.rs:787:23
+ |
+LL | #[suggestion(code(foo))]
+ | ^^^
+
+error: `code = "..."`/`code(...)` must contain only string literals
+ --> $DIR/diagnostic-derive.rs:795:18
+ |
+LL | #[suggestion(code = 3)]
+ | ^^^^^^^^
error: cannot find attribute `nonsense` in this scope
- --> $DIR/diagnostic-derive.rs:53:3
+ --> $DIR/diagnostic-derive.rs:55:3
|
-LL | #[nonsense(typeck::ambiguous_lifetime_bound, code = "E0123")]
+LL | #[nonsense(compiletest_example, code = "E0123")]
| ^^^^^^^^
error: cannot find attribute `nonsense` in this scope
- --> $DIR/diagnostic-derive.rs:141:7
+ --> $DIR/diagnostic-derive.rs:145:7
|
LL | #[nonsense]
| ^^^^^^^^
error: cannot find attribute `error` in this scope
- --> $DIR/diagnostic-derive.rs:558:3
+ --> $DIR/diagnostic-derive.rs:565:3
|
-LL | #[error(typeck::ambiguous_lifetime_bound, code = "E0123")]
+LL | #[error(compiletest_example, code = "E0123")]
| ^^^^^
error: cannot find attribute `warn_` in this scope
- --> $DIR/diagnostic-derive.rs:565:3
+ --> $DIR/diagnostic-derive.rs:572:3
|
-LL | #[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")]
+LL | #[warn_(compiletest_example, code = "E0123")]
| ^^^^^ help: a built-in attribute with a similar name exists: `warn`
error: cannot find attribute `lint` in this scope
- --> $DIR/diagnostic-derive.rs:572:3
+ --> $DIR/diagnostic-derive.rs:579:3
|
-LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]
+LL | #[lint(compiletest_example, code = "E0123")]
| ^^^^ help: a built-in attribute with a similar name exists: `link`
error: cannot find attribute `lint` in this scope
- --> $DIR/diagnostic-derive.rs:579:3
+ --> $DIR/diagnostic-derive.rs:586:3
|
-LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]
+LL | #[lint(compiletest_example, code = "E0123")]
| ^^^^ help: a built-in attribute with a similar name exists: `link`
+error: cannot find attribute `multipart_suggestion` in this scope
+ --> $DIR/diagnostic-derive.rs:627:3
+ |
+LL | #[multipart_suggestion(suggestion)]
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: cannot find attribute `multipart_suggestion` in this scope
+ --> $DIR/diagnostic-derive.rs:630:3
+ |
+LL | #[multipart_suggestion()]
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: cannot find attribute `multipart_suggestion` in this scope
+ --> $DIR/diagnostic-derive.rs:634:7
+ |
+LL | #[multipart_suggestion(suggestion)]
+ | ^^^^^^^^^^^^^^^^^^^^
+
error[E0425]: cannot find value `nonsense` in module `rustc_errors::fluent`
- --> $DIR/diagnostic-derive.rs:66:8
+ --> $DIR/diagnostic-derive.rs:68:8
|
LL | #[diag(nonsense, code = "E0123")]
| ^^^^^^^^ not found in `rustc_errors::fluent`
error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied
- --> $DIR/diagnostic-derive.rs:331:10
+ --> $DIR/diagnostic-derive.rs:338:10
|
-LL | #[derive(SessionDiagnostic)]
- | ^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello`
+LL | #[derive(Diagnostic)]
+ | ^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello`
|
= help: normalized in stderr
note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`
@@ -457,9 +663,9 @@ note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`
|
LL | arg: impl IntoDiagnosticArg,
| ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg`
- = note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
+ = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: aborting due to 55 previous errors
+error: aborting due to 83 previous errors
Some errors have detailed explanations: E0277, E0425.
For more information about an error, try `rustc --explain E0277`.
diff --git a/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs
index 812ca0c72..efec85eb5 100644
--- a/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs
+++ b/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs
@@ -1,8 +1,8 @@
// check-fail
-// Tests error conditions for specifying subdiagnostics using #[derive(SessionSubdiagnostic)]
+// Tests error conditions for specifying subdiagnostics using #[derive(Subdiagnostic)]
// The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly,
-// changing the output of this test. Since SessionSubdiagnostic is strictly internal to the compiler
+// changing the output of this test. Since Subdiagnostic is strictly internal to the compiler
// the test is just ignored on stable and beta:
// ignore-beta
// ignore-stable
@@ -17,25 +17,25 @@ extern crate rustc_macros;
use rustc_errors::Applicability;
use rustc_span::Span;
-use rustc_macros::SessionSubdiagnostic;
+use rustc_macros::Subdiagnostic;
-#[derive(SessionSubdiagnostic)]
-#[label(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren)]
struct A {
#[primary_span]
span: Span,
var: String,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
enum B {
- #[label(parser::add_paren)]
+ #[label(parser_add_paren)]
A {
#[primary_span]
span: Span,
var: String,
},
- #[label(parser::add_paren)]
+ #[label(parser_add_paren)]
B {
#[primary_span]
span: Span,
@@ -43,23 +43,23 @@ enum B {
}
}
-#[derive(SessionSubdiagnostic)]
-#[label(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren)]
//~^ ERROR label without `#[primary_span]` field
struct C {
var: String,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
#[label]
-//~^ ERROR `#[label]` is not a valid attribute
+//~^ ERROR diagnostic slug must be first argument
struct D {
#[primary_span]
span: Span,
var: String,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
#[foo]
//~^ ERROR `#[foo]` is not a valid attribute
//~^^ ERROR cannot find attribute `foo` in this scope
@@ -69,7 +69,7 @@ struct E {
var: String,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
#[label = "..."]
//~^ ERROR `#[label = ...]` is not a valid attribute
struct F {
@@ -78,43 +78,47 @@ struct F {
var: String,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
#[label(bug = "...")]
//~^ ERROR `#[label(bug = ...)]` is not a valid attribute
+//~| ERROR diagnostic slug must be first argument
struct G {
#[primary_span]
span: Span,
var: String,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
#[label("...")]
//~^ ERROR `#[label("...")]` is not a valid attribute
+//~| ERROR diagnostic slug must be first argument
struct H {
#[primary_span]
span: Span,
var: String,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
#[label(slug = 4)]
//~^ ERROR `#[label(slug = ...)]` is not a valid attribute
+//~| ERROR diagnostic slug must be first argument
struct J {
#[primary_span]
span: Span,
var: String,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
#[label(slug("..."))]
//~^ ERROR `#[label(slug(...))]` is not a valid attribute
+//~| ERROR diagnostic slug must be first argument
struct K {
#[primary_span]
span: Span,
var: String,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
#[label(slug)]
//~^ ERROR cannot find value `slug` in module `rustc_errors::fluent`
//~^^ NOTE not found in `rustc_errors::fluent`
@@ -124,7 +128,7 @@ struct L {
var: String,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
#[label()]
//~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
struct M {
@@ -133,30 +137,30 @@ struct M {
var: String,
}
-#[derive(SessionSubdiagnostic)]
-#[label(parser::add_paren, code = "...")]
-//~^ ERROR `code` is not a valid nested attribute of a `label` attribute
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren, code = "...")]
+//~^ ERROR `#[label(code = ...)]` is not a valid attribute
struct N {
#[primary_span]
span: Span,
var: String,
}
-#[derive(SessionSubdiagnostic)]
-#[label(parser::add_paren, applicability = "machine-applicable")]
-//~^ ERROR `applicability` is not a valid nested attribute of a `label` attribute
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren, applicability = "machine-applicable")]
+//~^ ERROR `#[label(applicability = ...)]` is not a valid attribute
struct O {
#[primary_span]
span: Span,
var: String,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
#[foo]
//~^ ERROR cannot find attribute `foo` in this scope
//~^^ ERROR unsupported type attribute for subdiagnostic enum
enum P {
- #[label(parser::add_paren)]
+ #[label(parser_add_paren)]
A {
#[primary_span]
span: Span,
@@ -164,7 +168,7 @@ enum P {
}
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
enum Q {
#[bar]
//~^ ERROR `#[bar]` is not a valid attribute
@@ -176,7 +180,7 @@ enum Q {
}
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
enum R {
#[bar = "..."]
//~^ ERROR `#[bar = ...]` is not a valid attribute
@@ -188,7 +192,7 @@ enum R {
}
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
enum S {
#[bar = 4]
//~^ ERROR `#[bar = ...]` is not a valid attribute
@@ -200,7 +204,7 @@ enum S {
}
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
enum T {
#[bar("...")]
//~^ ERROR `#[bar(...)]` is not a valid attribute
@@ -212,10 +216,11 @@ enum T {
}
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
enum U {
#[label(code = "...")]
//~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute
+ //~| ERROR `#[label(code = ...)]` is not a valid attribute
A {
#[primary_span]
span: Span,
@@ -223,24 +228,23 @@ enum U {
}
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
enum V {
- #[label(parser::add_paren)]
+ #[label(parser_add_paren)]
A {
#[primary_span]
span: Span,
var: String,
},
B {
- //~^ ERROR subdiagnostic kind not specified
#[primary_span]
span: Span,
var: String,
}
}
-#[derive(SessionSubdiagnostic)]
-#[label(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren)]
//~^ ERROR label without `#[primary_span]` field
struct W {
#[primary_span]
@@ -248,8 +252,8 @@ struct W {
span: String,
}
-#[derive(SessionSubdiagnostic)]
-#[label(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren)]
struct X {
#[primary_span]
span: Span,
@@ -258,8 +262,8 @@ struct X {
applicability: Applicability,
}
-#[derive(SessionSubdiagnostic)]
-#[label(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren)]
struct Y {
#[primary_span]
span: Span,
@@ -269,8 +273,8 @@ struct Y {
bar: String,
}
-#[derive(SessionSubdiagnostic)]
-#[label(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren)]
struct Z {
#[primary_span]
span: Span,
@@ -280,8 +284,8 @@ struct Z {
bar: String,
}
-#[derive(SessionSubdiagnostic)]
-#[label(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren)]
struct AA {
#[primary_span]
span: Span,
@@ -291,8 +295,8 @@ struct AA {
bar: String,
}
-#[derive(SessionSubdiagnostic)]
-#[label(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren)]
struct AB {
#[primary_span]
span: Span,
@@ -300,31 +304,31 @@ struct AB {
z: Z
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
union AC {
//~^ ERROR unexpected unsupported untagged union
span: u32,
b: u64
}
-#[derive(SessionSubdiagnostic)]
-#[label(parser::add_paren)]
-#[label(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren)]
+#[label(parser_add_paren)]
struct AD {
#[primary_span]
span: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[label(parser::add_paren, parser::add_paren)]
-//~^ ERROR `#[label(parser::add_paren)]` is not a valid attribute
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren, parser_add_paren)]
+//~^ ERROR `#[label(parser_add_paren)]` is not a valid attribute
struct AE {
#[primary_span]
span: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[label(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren)]
struct AF {
#[primary_span]
//~^ NOTE previously specified here
@@ -334,15 +338,15 @@ struct AF {
span_b: Span,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
struct AG {
//~^ ERROR subdiagnostic kind not specified
#[primary_span]
span: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[suggestion(parser::add_paren, code = "...")]
+#[derive(Subdiagnostic)]
+#[suggestion(parser_add_paren, code = "...")]
struct AH {
#[primary_span]
span: Span,
@@ -351,9 +355,9 @@ struct AH {
var: String,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
enum AI {
- #[suggestion(parser::add_paren, code = "...")]
+ #[suggestion(parser_add_paren, code = "...")]
A {
#[primary_span]
span: Span,
@@ -361,7 +365,7 @@ enum AI {
applicability: Applicability,
var: String,
},
- #[suggestion(parser::add_paren, code = "...")]
+ #[suggestion(parser_add_paren, code = "...")]
B {
#[primary_span]
span: Span,
@@ -371,8 +375,8 @@ enum AI {
}
}
-#[derive(SessionSubdiagnostic)]
-#[suggestion(parser::add_paren, code = "...", code = "...")]
+#[derive(Subdiagnostic)]
+#[suggestion(parser_add_paren, code = "...", code = "...")]
//~^ ERROR specified multiple times
//~^^ NOTE previously specified here
struct AJ {
@@ -382,8 +386,8 @@ struct AJ {
applicability: Applicability,
}
-#[derive(SessionSubdiagnostic)]
-#[suggestion(parser::add_paren, code = "...")]
+#[derive(Subdiagnostic)]
+#[suggestion(parser_add_paren, code = "...")]
struct AK {
#[primary_span]
span: Span,
@@ -395,8 +399,8 @@ struct AK {
applicability_b: Applicability,
}
-#[derive(SessionSubdiagnostic)]
-#[suggestion(parser::add_paren, code = "...")]
+#[derive(Subdiagnostic)]
+#[suggestion(parser_add_paren, code = "...")]
struct AL {
#[primary_span]
span: Span,
@@ -405,15 +409,15 @@ struct AL {
applicability: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[suggestion(parser::add_paren, code = "...")]
+#[derive(Subdiagnostic)]
+#[suggestion(parser_add_paren, code = "...")]
struct AM {
#[primary_span]
span: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[suggestion(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[suggestion(parser_add_paren)]
//~^ ERROR suggestion without `code = "..."`
struct AN {
#[primary_span]
@@ -422,43 +426,43 @@ struct AN {
applicability: Applicability,
}
-#[derive(SessionSubdiagnostic)]
-#[suggestion(parser::add_paren, code ="...", applicability = "foo")]
+#[derive(Subdiagnostic)]
+#[suggestion(parser_add_paren, code ="...", applicability = "foo")]
//~^ ERROR invalid applicability
struct AO {
#[primary_span]
span: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[help(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[help(parser_add_paren)]
struct AP {
var: String
}
-#[derive(SessionSubdiagnostic)]
-#[note(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[note(parser_add_paren)]
struct AQ;
-#[derive(SessionSubdiagnostic)]
-#[suggestion(parser::add_paren, code = "...")]
+#[derive(Subdiagnostic)]
+#[suggestion(parser_add_paren, code = "...")]
//~^ ERROR suggestion without `#[primary_span]` field
struct AR {
var: String,
}
-#[derive(SessionSubdiagnostic)]
-#[suggestion(parser::add_paren, code ="...", applicability = "machine-applicable")]
+#[derive(Subdiagnostic)]
+#[suggestion(parser_add_paren, code ="...", applicability = "machine-applicable")]
struct AS {
#[primary_span]
span: Span,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
#[label]
//~^ ERROR unsupported type attribute for subdiagnostic enum
enum AT {
- #[label(parser::add_paren)]
+ #[label(parser_add_paren)]
A {
#[primary_span]
span: Span,
@@ -466,25 +470,25 @@ enum AT {
}
}
-#[derive(SessionSubdiagnostic)]
-#[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
+#[derive(Subdiagnostic)]
+#[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")]
struct AU {
#[primary_span]
span: Span,
var: String,
}
-#[derive(SessionSubdiagnostic)]
-#[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
+#[derive(Subdiagnostic)]
+#[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")]
//~^ ERROR `var` doesn't refer to a field on this type
struct AV {
#[primary_span]
span: Span,
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
enum AW {
- #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
+ #[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")]
A {
#[primary_span]
span: Span,
@@ -492,9 +496,9 @@ enum AW {
}
}
-#[derive(SessionSubdiagnostic)]
+#[derive(Subdiagnostic)]
enum AX {
- #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
+ #[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")]
//~^ ERROR `var` doesn't refer to a field on this type
A {
#[primary_span]
@@ -502,19 +506,19 @@ enum AX {
}
}
-#[derive(SessionSubdiagnostic)]
-#[warning(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[warning(parser_add_paren)]
struct AY {}
-#[derive(SessionSubdiagnostic)]
-#[warning(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[warning(parser_add_paren)]
struct AZ {
#[primary_span]
span: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[suggestion(parser::add_paren, code = "...")]
+#[derive(Subdiagnostic)]
+#[suggestion(parser_add_paren, code = "...")]
//~^ ERROR suggestion without `#[primary_span]` field
struct BA {
#[suggestion_part]
@@ -528,32 +532,32 @@ struct BA {
var: String,
}
-#[derive(SessionSubdiagnostic)]
-#[multipart_suggestion(parser::add_paren, code = "...", applicability = "machine-applicable")]
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren, code = "...", applicability = "machine-applicable")]
//~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields
-//~| ERROR `code` is not a valid nested attribute of a `multipart_suggestion` attribute
+//~| ERROR `#[multipart_suggestion(code = ...)]` is not a valid attribute
struct BBa {
var: String,
}
-#[derive(SessionSubdiagnostic)]
-#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren, applicability = "machine-applicable")]
struct BBb {
#[suggestion_part]
//~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
span1: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren, applicability = "machine-applicable")]
struct BBc {
#[suggestion_part()]
//~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
span1: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[multipart_suggestion(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren)]
//~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields
struct BC {
#[primary_span]
@@ -561,8 +565,8 @@ struct BC {
span: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[multipart_suggestion(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren)]
struct BD {
#[suggestion_part]
//~^ ERROR `#[suggestion_part(...)]` attribute without `code = "..."`
@@ -581,8 +585,8 @@ struct BD {
s2: String,
}
-#[derive(SessionSubdiagnostic)]
-#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren, applicability = "machine-applicable")]
struct BE {
#[suggestion_part(code = "...", code = ",,,")]
//~^ ERROR specified multiple times
@@ -590,8 +594,8 @@ struct BE {
span: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren, applicability = "machine-applicable")]
struct BF {
#[suggestion_part(code = "(")]
first: Span,
@@ -599,8 +603,8 @@ struct BF {
second: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[multipart_suggestion(parser::add_paren)]
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren)]
struct BG {
#[applicability]
appl: Applicability,
@@ -610,12 +614,11 @@ struct BG {
second: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
-//~^ NOTE previously specified here
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren, applicability = "machine-applicable")]
struct BH {
#[applicability]
- //~^ ERROR specified multiple times
+ //~^ ERROR `#[applicability]` has no effect
appl: Applicability,
#[suggestion_part(code = "(")]
first: Span,
@@ -623,9 +626,83 @@ struct BH {
second: Span,
}
-#[derive(SessionSubdiagnostic)]
-#[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren, applicability = "machine-applicable")]
struct BI {
#[suggestion_part(code = "")]
spans: Vec<Span>,
}
+
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren)]
+struct BJ {
+ #[primary_span]
+ span: Span,
+ r#type: String,
+}
+
+/// with a doc comment on the type..
+#[derive(Subdiagnostic)]
+#[label(parser_add_paren)]
+struct BK {
+ /// ..and the field
+ #[primary_span]
+ span: Span,
+}
+
+/// with a doc comment on the type..
+#[derive(Subdiagnostic)]
+enum BL {
+ /// ..and the variant..
+ #[label(parser_add_paren)]
+ Foo {
+ /// ..and the field
+ #[primary_span]
+ span: Span,
+ }
+}
+
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren)]
+struct BM {
+ #[suggestion_part(code("foo"))]
+ //~^ ERROR expected exactly one string literal for `code = ...`
+ span: Span,
+ r#type: String,
+}
+
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren)]
+struct BN {
+ #[suggestion_part(code("foo", "bar"))]
+ //~^ ERROR expected exactly one string literal for `code = ...`
+ span: Span,
+ r#type: String,
+}
+
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren)]
+struct BO {
+ #[suggestion_part(code(3))]
+ //~^ ERROR expected exactly one string literal for `code = ...`
+ span: Span,
+ r#type: String,
+}
+
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren)]
+struct BP {
+ #[suggestion_part(code())]
+ //~^ ERROR expected exactly one string literal for `code = ...`
+ span: Span,
+ r#type: String,
+}
+
+#[derive(Subdiagnostic)]
+#[multipart_suggestion(parser_add_paren)]
+struct BQ {
+ #[suggestion_part(code = 3)]
+ //~^ ERROR `code = "..."`/`code(...)` must contain only string literals
+ span: Span,
+ r#type: String,
+}
diff --git a/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr
index 0a0247e89..a85a8711e 100644
--- a/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr
+++ b/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr
@@ -1,14 +1,14 @@
error: label without `#[primary_span]` field
--> $DIR/subdiagnostic-derive.rs:47:1
|
-LL | / #[label(parser::add_paren)]
+LL | / #[label(parser_add_paren)]
LL | |
LL | | struct C {
LL | | var: String,
LL | | }
| |_^
-error: `#[label]` is not a valid attribute
+error: diagnostic slug must be first argument of a `#[label(...)]` attribute
--> $DIR/subdiagnostic-derive.rs:54:1
|
LL | #[label]
@@ -31,103 +31,119 @@ error: `#[label(bug = ...)]` is not a valid attribute
|
LL | #[label(bug = "...")]
| ^^^^^^^^^^^
+
+error: diagnostic slug must be first argument of a `#[label(...)]` attribute
+ --> $DIR/subdiagnostic-derive.rs:82:1
|
- = help: first argument of the attribute should be the diagnostic slug
+LL | #[label(bug = "...")]
+ | ^^^^^^^^^^^^^^^^^^^^^
error: `#[label("...")]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:91:9
+ --> $DIR/subdiagnostic-derive.rs:92:9
|
LL | #[label("...")]
| ^^^^^
+
+error: diagnostic slug must be first argument of a `#[label(...)]` attribute
+ --> $DIR/subdiagnostic-derive.rs:92:1
|
- = help: first argument of the attribute should be the diagnostic slug
+LL | #[label("...")]
+ | ^^^^^^^^^^^^^^^
error: `#[label(slug = ...)]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:100:9
+ --> $DIR/subdiagnostic-derive.rs:102:9
|
LL | #[label(slug = 4)]
| ^^^^^^^^
+
+error: diagnostic slug must be first argument of a `#[label(...)]` attribute
+ --> $DIR/subdiagnostic-derive.rs:102:1
|
- = help: first argument of the attribute should be the diagnostic slug
+LL | #[label(slug = 4)]
+ | ^^^^^^^^^^^^^^^^^^
error: `#[label(slug(...))]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:109:9
+ --> $DIR/subdiagnostic-derive.rs:112:9
|
LL | #[label(slug("..."))]
| ^^^^^^^^^^^
+
+error: diagnostic slug must be first argument of a `#[label(...)]` attribute
+ --> $DIR/subdiagnostic-derive.rs:112:1
|
- = help: first argument of the attribute should be the diagnostic slug
+LL | #[label(slug("..."))]
+ | ^^^^^^^^^^^^^^^^^^^^^
error: diagnostic slug must be first argument of a `#[label(...)]` attribute
- --> $DIR/subdiagnostic-derive.rs:128:1
+ --> $DIR/subdiagnostic-derive.rs:132:1
|
LL | #[label()]
| ^^^^^^^^^^
-error: `code` is not a valid nested attribute of a `label` attribute
- --> $DIR/subdiagnostic-derive.rs:137:28
+error: `#[label(code = ...)]` is not a valid attribute
+ --> $DIR/subdiagnostic-derive.rs:141:27
|
-LL | #[label(parser::add_paren, code = "...")]
- | ^^^^^^^^^^^^
+LL | #[label(parser_add_paren, code = "...")]
+ | ^^^^^^^^^^^^
-error: `applicability` is not a valid nested attribute of a `label` attribute
- --> $DIR/subdiagnostic-derive.rs:146:28
+error: `#[label(applicability = ...)]` is not a valid attribute
+ --> $DIR/subdiagnostic-derive.rs:150:27
|
-LL | #[label(parser::add_paren, applicability = "machine-applicable")]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[label(parser_add_paren, applicability = "machine-applicable")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: unsupported type attribute for subdiagnostic enum
- --> $DIR/subdiagnostic-derive.rs:155:1
+ --> $DIR/subdiagnostic-derive.rs:159:1
|
LL | #[foo]
| ^^^^^^
error: `#[bar]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:169:5
+ --> $DIR/subdiagnostic-derive.rs:173:5
|
LL | #[bar]
| ^^^^^^
error: `#[bar = ...]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:181:5
+ --> $DIR/subdiagnostic-derive.rs:185:5
|
LL | #[bar = "..."]
| ^^^^^^^^^^^^^^
error: `#[bar = ...]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:193:5
+ --> $DIR/subdiagnostic-derive.rs:197:5
|
LL | #[bar = 4]
| ^^^^^^^^^^
error: `#[bar(...)]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:205:5
+ --> $DIR/subdiagnostic-derive.rs:209:5
|
LL | #[bar("...")]
| ^^^^^^^^^^^^^
-error: diagnostic slug must be first argument of a `#[label(...)]` attribute
- --> $DIR/subdiagnostic-derive.rs:217:5
+error: `#[label(code = ...)]` is not a valid attribute
+ --> $DIR/subdiagnostic-derive.rs:221:13
|
LL | #[label(code = "...")]
- | ^^^^^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^
-error: subdiagnostic kind not specified
- --> $DIR/subdiagnostic-derive.rs:234:5
+error: diagnostic slug must be first argument of a `#[label(...)]` attribute
+ --> $DIR/subdiagnostic-derive.rs:221:5
|
-LL | B {
- | ^
+LL | #[label(code = "...")]
+ | ^^^^^^^^^^^^^^^^^^^^^^
error: the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan`
- --> $DIR/subdiagnostic-derive.rs:246:5
+ --> $DIR/subdiagnostic-derive.rs:250:5
|
LL | #[primary_span]
| ^^^^^^^^^^^^^^^
error: label without `#[primary_span]` field
- --> $DIR/subdiagnostic-derive.rs:243:1
+ --> $DIR/subdiagnostic-derive.rs:247:1
|
-LL | / #[label(parser::add_paren)]
+LL | / #[label(parser_add_paren)]
LL | |
LL | | struct W {
LL | | #[primary_span]
@@ -137,13 +153,13 @@ LL | | }
| |_^
error: `#[applicability]` is only valid on suggestions
- --> $DIR/subdiagnostic-derive.rs:256:5
+ --> $DIR/subdiagnostic-derive.rs:260:5
|
LL | #[applicability]
| ^^^^^^^^^^^^^^^^
error: `#[bar]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:266:5
+ --> $DIR/subdiagnostic-derive.rs:270:5
|
LL | #[bar]
| ^^^^^^
@@ -151,13 +167,13 @@ LL | #[bar]
= help: only `primary_span`, `applicability` and `skip_arg` are valid field attributes
error: `#[bar = ...]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:277:5
+ --> $DIR/subdiagnostic-derive.rs:281:5
|
LL | #[bar = "..."]
| ^^^^^^^^^^^^^^
error: `#[bar(...)]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:288:5
+ --> $DIR/subdiagnostic-derive.rs:292:5
|
LL | #[bar("...")]
| ^^^^^^^^^^^^^
@@ -165,7 +181,7 @@ LL | #[bar("...")]
= help: only `primary_span`, `applicability` and `skip_arg` are valid field attributes
error: unexpected unsupported untagged union
- --> $DIR/subdiagnostic-derive.rs:304:1
+ --> $DIR/subdiagnostic-derive.rs:308:1
|
LL | / union AC {
LL | |
@@ -174,78 +190,78 @@ LL | | b: u64
LL | | }
| |_^
-error: `#[label(parser::add_paren)]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:319:28
+error: `#[label(parser_add_paren)]` is not a valid attribute
+ --> $DIR/subdiagnostic-derive.rs:323:27
|
-LL | #[label(parser::add_paren, parser::add_paren)]
- | ^^^^^^^^^^^^^^^^^
+LL | #[label(parser_add_paren, parser_add_paren)]
+ | ^^^^^^^^^^^^^^^^
|
= help: a diagnostic slug must be the first argument to the attribute
error: specified multiple times
- --> $DIR/subdiagnostic-derive.rs:332:5
+ --> $DIR/subdiagnostic-derive.rs:336:5
|
LL | #[primary_span]
| ^^^^^^^^^^^^^^^
|
note: previously specified here
- --> $DIR/subdiagnostic-derive.rs:329:5
+ --> $DIR/subdiagnostic-derive.rs:333:5
|
LL | #[primary_span]
| ^^^^^^^^^^^^^^^
error: subdiagnostic kind not specified
- --> $DIR/subdiagnostic-derive.rs:338:8
+ --> $DIR/subdiagnostic-derive.rs:342:8
|
LL | struct AG {
| ^^
error: specified multiple times
- --> $DIR/subdiagnostic-derive.rs:375:47
+ --> $DIR/subdiagnostic-derive.rs:379:46
|
-LL | #[suggestion(parser::add_paren, code = "...", code = "...")]
- | ^^^^^^^^^^^^
+LL | #[suggestion(parser_add_paren, code = "...", code = "...")]
+ | ^^^^^^^^^^^^
|
note: previously specified here
- --> $DIR/subdiagnostic-derive.rs:375:33
+ --> $DIR/subdiagnostic-derive.rs:379:32
|
-LL | #[suggestion(parser::add_paren, code = "...", code = "...")]
- | ^^^^^^^^^^^^
+LL | #[suggestion(parser_add_paren, code = "...", code = "...")]
+ | ^^^^^^^^^^^^
error: specified multiple times
- --> $DIR/subdiagnostic-derive.rs:393:5
+ --> $DIR/subdiagnostic-derive.rs:397:5
|
LL | #[applicability]
| ^^^^^^^^^^^^^^^^
|
note: previously specified here
- --> $DIR/subdiagnostic-derive.rs:390:5
+ --> $DIR/subdiagnostic-derive.rs:394:5
|
LL | #[applicability]
| ^^^^^^^^^^^^^^^^
error: the `#[applicability]` attribute can only be applied to fields of type `Applicability`
- --> $DIR/subdiagnostic-derive.rs:403:5
+ --> $DIR/subdiagnostic-derive.rs:407:5
|
LL | #[applicability]
| ^^^^^^^^^^^^^^^^
error: suggestion without `code = "..."`
- --> $DIR/subdiagnostic-derive.rs:416:1
+ --> $DIR/subdiagnostic-derive.rs:420:1
|
-LL | #[suggestion(parser::add_paren)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[suggestion(parser_add_paren)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: invalid applicability
- --> $DIR/subdiagnostic-derive.rs:426:46
+ --> $DIR/subdiagnostic-derive.rs:430:45
|
-LL | #[suggestion(parser::add_paren, code ="...", applicability = "foo")]
- | ^^^^^^^^^^^^^^^^^^^^^
+LL | #[suggestion(parser_add_paren, code ="...", applicability = "foo")]
+ | ^^^^^^^^^^^^^^^^^^^^^
error: suggestion without `#[primary_span]` field
- --> $DIR/subdiagnostic-derive.rs:444:1
+ --> $DIR/subdiagnostic-derive.rs:448:1
|
-LL | / #[suggestion(parser::add_paren, code = "...")]
+LL | / #[suggestion(parser_add_paren, code = "...")]
LL | |
LL | | struct AR {
LL | | var: String,
@@ -253,25 +269,25 @@ LL | | }
| |_^
error: unsupported type attribute for subdiagnostic enum
- --> $DIR/subdiagnostic-derive.rs:458:1
+ --> $DIR/subdiagnostic-derive.rs:462:1
|
LL | #[label]
| ^^^^^^^^
error: `var` doesn't refer to a field on this type
- --> $DIR/subdiagnostic-derive.rs:478:39
+ --> $DIR/subdiagnostic-derive.rs:482:38
|
-LL | #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
- | ^^^^^^^
+LL | #[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")]
+ | ^^^^^^^
error: `var` doesn't refer to a field on this type
- --> $DIR/subdiagnostic-derive.rs:497:43
+ --> $DIR/subdiagnostic-derive.rs:501:42
|
-LL | #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")]
- | ^^^^^^^
+LL | #[suggestion(parser_add_paren, code ="{var}", applicability = "machine-applicable")]
+ | ^^^^^^^
error: `#[suggestion_part]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:520:5
+ --> $DIR/subdiagnostic-derive.rs:524:5
|
LL | #[suggestion_part]
| ^^^^^^^^^^^^^^^^^^
@@ -279,7 +295,7 @@ LL | #[suggestion_part]
= help: `#[suggestion_part(...)]` is only valid in multipart suggestions, use `#[primary_span]` instead
error: `#[suggestion_part(...)]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:523:5
+ --> $DIR/subdiagnostic-derive.rs:527:5
|
LL | #[suggestion_part(code = "...")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -287,9 +303,9 @@ LL | #[suggestion_part(code = "...")]
= help: `#[suggestion_part(...)]` is only valid in multipart suggestions
error: suggestion without `#[primary_span]` field
- --> $DIR/subdiagnostic-derive.rs:517:1
+ --> $DIR/subdiagnostic-derive.rs:521:1
|
-LL | / #[suggestion(parser::add_paren, code = "...")]
+LL | / #[suggestion(parser_add_paren, code = "...")]
LL | |
LL | | struct BA {
LL | | #[suggestion_part]
@@ -298,16 +314,18 @@ LL | | var: String,
LL | | }
| |_^
-error: `code` is not a valid nested attribute of a `multipart_suggestion` attribute
- --> $DIR/subdiagnostic-derive.rs:532:43
+error: `#[multipart_suggestion(code = ...)]` is not a valid attribute
+ --> $DIR/subdiagnostic-derive.rs:536:42
+ |
+LL | #[multipart_suggestion(parser_add_paren, code = "...", applicability = "machine-applicable")]
+ | ^^^^^^^^^^^^
|
-LL | #[multipart_suggestion(parser::add_paren, code = "...", applicability = "machine-applicable")]
- | ^^^^^^^^^^^^
+ = help: only `applicability` is a valid nested attributes
error: multipart suggestion without any `#[suggestion_part(...)]` fields
- --> $DIR/subdiagnostic-derive.rs:532:1
+ --> $DIR/subdiagnostic-derive.rs:536:1
|
-LL | / #[multipart_suggestion(parser::add_paren, code = "...", applicability = "machine-applicable")]
+LL | / #[multipart_suggestion(parser_add_paren, code = "...", applicability = "machine-applicable")]
LL | |
LL | |
LL | | struct BBa {
@@ -316,19 +334,19 @@ LL | | }
| |_^
error: `#[suggestion_part(...)]` attribute without `code = "..."`
- --> $DIR/subdiagnostic-derive.rs:542:5
+ --> $DIR/subdiagnostic-derive.rs:546:5
|
LL | #[suggestion_part]
| ^^^^^^^^^^^^^^^^^^
error: `#[suggestion_part(...)]` attribute without `code = "..."`
- --> $DIR/subdiagnostic-derive.rs:550:5
+ --> $DIR/subdiagnostic-derive.rs:554:5
|
LL | #[suggestion_part()]
| ^^^^^^^^^^^^^^^^^^^^
error: `#[primary_span]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:559:5
+ --> $DIR/subdiagnostic-derive.rs:563:5
|
LL | #[primary_span]
| ^^^^^^^^^^^^^^^
@@ -336,9 +354,9 @@ LL | #[primary_span]
= help: multipart suggestions use one or more `#[suggestion_part]`s rather than one `#[primary_span]`
error: multipart suggestion without any `#[suggestion_part(...)]` fields
- --> $DIR/subdiagnostic-derive.rs:556:1
+ --> $DIR/subdiagnostic-derive.rs:560:1
|
-LL | / #[multipart_suggestion(parser::add_paren)]
+LL | / #[multipart_suggestion(parser_add_paren)]
LL | |
LL | | struct BC {
LL | | #[primary_span]
@@ -348,19 +366,19 @@ LL | | }
| |_^
error: `#[suggestion_part(...)]` attribute without `code = "..."`
- --> $DIR/subdiagnostic-derive.rs:567:5
+ --> $DIR/subdiagnostic-derive.rs:571:5
|
LL | #[suggestion_part]
| ^^^^^^^^^^^^^^^^^^
error: `#[suggestion_part(...)]` attribute without `code = "..."`
- --> $DIR/subdiagnostic-derive.rs:570:5
+ --> $DIR/subdiagnostic-derive.rs:574:5
|
LL | #[suggestion_part()]
| ^^^^^^^^^^^^^^^^^^^^
error: `#[suggestion_part(foo = ...)]` is not a valid attribute
- --> $DIR/subdiagnostic-derive.rs:573:23
+ --> $DIR/subdiagnostic-derive.rs:577:23
|
LL | #[suggestion_part(foo = "bar")]
| ^^^^^^^^^^^
@@ -368,40 +386,64 @@ LL | #[suggestion_part(foo = "bar")]
= help: `code` is the only valid nested attribute
error: the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
- --> $DIR/subdiagnostic-derive.rs:576:5
+ --> $DIR/subdiagnostic-derive.rs:580:5
|
LL | #[suggestion_part(code = "...")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan`
- --> $DIR/subdiagnostic-derive.rs:579:5
+ --> $DIR/subdiagnostic-derive.rs:583:5
|
LL | #[suggestion_part()]
| ^^^^^^^^^^^^^^^^^^^^
error: specified multiple times
- --> $DIR/subdiagnostic-derive.rs:587:37
+ --> $DIR/subdiagnostic-derive.rs:591:37
|
LL | #[suggestion_part(code = "...", code = ",,,")]
| ^^^^^^^^^^^^
|
note: previously specified here
- --> $DIR/subdiagnostic-derive.rs:587:23
+ --> $DIR/subdiagnostic-derive.rs:591:23
|
LL | #[suggestion_part(code = "...", code = ",,,")]
| ^^^^^^^^^^^^
-error: specified multiple times
- --> $DIR/subdiagnostic-derive.rs:617:5
+error: `#[applicability]` has no effect if all `#[suggestion]`/`#[multipart_suggestion]` attributes have a static `applicability = "..."`
+ --> $DIR/subdiagnostic-derive.rs:620:5
|
LL | #[applicability]
| ^^^^^^^^^^^^^^^^
+
+error: expected exactly one string literal for `code = ...`
+ --> $DIR/subdiagnostic-derive.rs:668:23
|
-note: previously specified here
- --> $DIR/subdiagnostic-derive.rs:614:43
+LL | #[suggestion_part(code("foo"))]
+ | ^^^^^^^^^^^
+
+error: expected exactly one string literal for `code = ...`
+ --> $DIR/subdiagnostic-derive.rs:677:23
+ |
+LL | #[suggestion_part(code("foo", "bar"))]
+ | ^^^^^^^^^^^^^^^^^^
+
+error: expected exactly one string literal for `code = ...`
+ --> $DIR/subdiagnostic-derive.rs:686:23
+ |
+LL | #[suggestion_part(code(3))]
+ | ^^^^^^^
+
+error: expected exactly one string literal for `code = ...`
+ --> $DIR/subdiagnostic-derive.rs:695:23
+ |
+LL | #[suggestion_part(code())]
+ | ^^^^^^
+
+error: `code = "..."`/`code(...)` must contain only string literals
+ --> $DIR/subdiagnostic-derive.rs:704:23
|
-LL | #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #[suggestion_part(code = 3)]
+ | ^^^^^^^^
error: cannot find attribute `foo` in this scope
--> $DIR/subdiagnostic-derive.rs:63:3
@@ -410,59 +452,59 @@ LL | #[foo]
| ^^^
error: cannot find attribute `foo` in this scope
- --> $DIR/subdiagnostic-derive.rs:155:3
+ --> $DIR/subdiagnostic-derive.rs:159:3
|
LL | #[foo]
| ^^^
error: cannot find attribute `bar` in this scope
- --> $DIR/subdiagnostic-derive.rs:169:7
+ --> $DIR/subdiagnostic-derive.rs:173:7
|
LL | #[bar]
| ^^^
error: cannot find attribute `bar` in this scope
- --> $DIR/subdiagnostic-derive.rs:181:7
+ --> $DIR/subdiagnostic-derive.rs:185:7
|
LL | #[bar = "..."]
| ^^^
error: cannot find attribute `bar` in this scope
- --> $DIR/subdiagnostic-derive.rs:193:7
+ --> $DIR/subdiagnostic-derive.rs:197:7
|
LL | #[bar = 4]
| ^^^
error: cannot find attribute `bar` in this scope
- --> $DIR/subdiagnostic-derive.rs:205:7
+ --> $DIR/subdiagnostic-derive.rs:209:7
|
LL | #[bar("...")]
| ^^^
error: cannot find attribute `bar` in this scope
- --> $DIR/subdiagnostic-derive.rs:266:7
+ --> $DIR/subdiagnostic-derive.rs:270:7
|
LL | #[bar]
| ^^^
error: cannot find attribute `bar` in this scope
- --> $DIR/subdiagnostic-derive.rs:277:7
+ --> $DIR/subdiagnostic-derive.rs:281:7
|
LL | #[bar = "..."]
| ^^^
error: cannot find attribute `bar` in this scope
- --> $DIR/subdiagnostic-derive.rs:288:7
+ --> $DIR/subdiagnostic-derive.rs:292:7
|
LL | #[bar("...")]
| ^^^
error[E0425]: cannot find value `slug` in module `rustc_errors::fluent`
- --> $DIR/subdiagnostic-derive.rs:118:9
+ --> $DIR/subdiagnostic-derive.rs:122:9
|
LL | #[label(slug)]
| ^^^^ not found in `rustc_errors::fluent`
-error: aborting due to 63 previous errors
+error: aborting due to 72 previous errors
For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/abi/abi-sysv64-register-usage.rs b/src/test/ui/abi/abi-sysv64-register-usage.rs
index 9404e71d0..393306936 100644
--- a/src/test/ui/abi/abi-sysv64-register-usage.rs
+++ b/src/test/ui/abi/abi-sysv64-register-usage.rs
@@ -6,20 +6,30 @@
// ignore-arm
// ignore-aarch64
// needs-asm-support
-#![feature(asm_sym)]
#[cfg(target_arch = "x86_64")]
-pub extern "sysv64" fn all_the_registers(rdi: i64, rsi: i64, rdx: i64,
- rcx: i64, r8 : i64, r9 : i64,
- xmm0: f32, xmm1: f32, xmm2: f32,
- xmm3: f32, xmm4: f32, xmm5: f32,
- xmm6: f32, xmm7: f32) -> i64 {
+pub extern "sysv64" fn all_the_registers(
+ rdi: i64,
+ rsi: i64,
+ rdx: i64,
+ rcx: i64,
+ r8: i64,
+ r9: i64,
+ xmm0: f32,
+ xmm1: f32,
+ xmm2: f32,
+ xmm3: f32,
+ xmm4: f32,
+ xmm5: f32,
+ xmm6: f32,
+ xmm7: f32,
+) -> i64 {
assert_eq!(rdi, 1);
assert_eq!(rsi, 2);
assert_eq!(rdx, 3);
assert_eq!(rcx, 4);
- assert_eq!(r8, 5);
- assert_eq!(r9, 6);
+ assert_eq!(r8, 5);
+ assert_eq!(r9, 6);
assert_eq!(xmm0, 1.0f32);
assert_eq!(xmm1, 2.0f32);
assert_eq!(xmm2, 4.0f32);
diff --git a/src/test/ui/abi/abi-typo-unstable.rs b/src/test/ui/abi/abi-typo-unstable.rs
new file mode 100644
index 000000000..94991a5eb
--- /dev/null
+++ b/src/test/ui/abi/abi-typo-unstable.rs
@@ -0,0 +1,6 @@
+// rust-intrinsic is unstable and not enabled, so it should not be suggested as a fix
+extern "rust-intrinsec" fn rust_intrinsic() {} //~ ERROR invalid ABI
+
+fn main() {
+ rust_intrinsic();
+}
diff --git a/src/test/ui/abi/abi-typo-unstable.stderr b/src/test/ui/abi/abi-typo-unstable.stderr
new file mode 100644
index 000000000..3b346e002
--- /dev/null
+++ b/src/test/ui/abi/abi-typo-unstable.stderr
@@ -0,0 +1,11 @@
+error[E0703]: invalid ABI: found `rust-intrinsec`
+ --> $DIR/abi-typo-unstable.rs:2:8
+ |
+LL | extern "rust-intrinsec" fn rust_intrinsic() {}
+ | ^^^^^^^^^^^^^^^^ invalid ABI
+ |
+ = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions.
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0703`.
diff --git a/src/test/ui/abi/segfault-no-out-of-stack.rs b/src/test/ui/abi/segfault-no-out-of-stack.rs
index ad4faf95a..ab2b30894 100644
--- a/src/test/ui/abi/segfault-no-out-of-stack.rs
+++ b/src/test/ui/abi/segfault-no-out-of-stack.rs
@@ -3,6 +3,7 @@
#![allow(unused_imports)]
// ignore-emscripten can't run commands
// ignore-sgx no processes
+// ignore-fuchsia must translate zircon signal to SIGSEGV/SIGBUS, FIXME (#58590)
#![feature(rustc_private)]
extern crate libc;
diff --git a/src/test/ui/abi/stack-probes-lto.rs b/src/test/ui/abi/stack-probes-lto.rs
index 90df1f3f5..6d934538f 100644
--- a/src/test/ui/abi/stack-probes-lto.rs
+++ b/src/test/ui/abi/stack-probes-lto.rs
@@ -3,8 +3,6 @@
// ignore-aarch64
// ignore-mips
// ignore-mips64
-// ignore-powerpc
-// ignore-s390x
// ignore-sparc
// ignore-sparc64
// ignore-wasm
@@ -12,6 +10,7 @@
// ignore-sgx no processes
// ignore-musl FIXME #31506
// ignore-pretty
+// ignore-fuchsia no exception handler registered for segfault
// compile-flags: -C lto
// no-prefer-dynamic
diff --git a/src/test/ui/abi/stack-probes.rs b/src/test/ui/abi/stack-probes.rs
index e998dd0f8..e7b91644b 100644
--- a/src/test/ui/abi/stack-probes.rs
+++ b/src/test/ui/abi/stack-probes.rs
@@ -3,13 +3,12 @@
// ignore-aarch64
// ignore-mips
// ignore-mips64
-// ignore-powerpc
-// ignore-s390x
// ignore-sparc
// ignore-sparc64
// ignore-wasm
// ignore-emscripten no processes
// ignore-sgx no processes
+// ignore-fuchsia no exception handler registered for segfault
use std::env;
use std::mem::MaybeUninit;
@@ -26,8 +25,9 @@ fn main() {
let args = env::args().skip(1).collect::<Vec<_>>();
if args.len() > 0 {
match &args[0][..] {
- "main-thread" => recurse(&MaybeUninit::uninit()),
- "child-thread" => thread::spawn(|| recurse(&MaybeUninit::uninit())).join().unwrap(),
+ "main-recurse" => overflow_recurse(),
+ "child-recurse" => thread::spawn(overflow_recurse).join().unwrap(),
+ "child-frame" => overflow_frame(),
_ => panic!(),
}
return;
@@ -40,9 +40,10 @@ fn main() {
// that we report stack overflow on the main thread, see #43052 for some
// details
if cfg!(not(target_os = "linux")) {
- assert_overflow(Command::new(&me).arg("main-thread"));
+ assert_overflow(Command::new(&me).arg("main-recurse"));
}
- assert_overflow(Command::new(&me).arg("child-thread"));
+ assert_overflow(Command::new(&me).arg("child-recurse"));
+ assert_overflow(Command::new(&me).arg("child-frame"));
}
#[allow(unconditional_recursion)]
@@ -54,6 +55,23 @@ fn recurse(array: &MaybeUninit<[u64; 1024]>) {
recurse(&local);
}
+#[inline(never)]
+fn overflow_recurse() {
+ recurse(&MaybeUninit::uninit());
+}
+
+fn overflow_frame() {
+ // By using a 1MiB stack frame with only 512KiB stack, we'll jump over any
+ // guard page, even with 64K pages -- but stack probes should catch it.
+ const STACK_SIZE: usize = 512 * 1024;
+ thread::Builder::new().stack_size(STACK_SIZE).spawn(|| {
+ let local: MaybeUninit<[u8; 2 * STACK_SIZE]> = MaybeUninit::uninit();
+ unsafe {
+ black_box(local.as_ptr() as u64);
+ }
+ }).unwrap().join().unwrap();
+}
+
fn assert_overflow(cmd: &mut Command) {
let output = cmd.output().unwrap();
assert!(!output.status.success());
diff --git a/src/test/ui/abi/unsupported.aarch64.stderr b/src/test/ui/abi/unsupported.aarch64.stderr
index a948947db..e86a73ea6 100644
--- a/src/test/ui/abi/unsupported.aarch64.stderr
+++ b/src/test/ui/abi/unsupported.aarch64.stderr
@@ -52,9 +52,9 @@ warning: use of calling convention not supported on this target
LL | extern "stdcall" fn stdcall() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unsupported_calling_conventions)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
+ = note: `#[warn(unsupported_calling_conventions)]` on by default
error: aborting due to 8 previous errors; 1 warning emitted
diff --git a/src/test/ui/abi/unsupported.arm.stderr b/src/test/ui/abi/unsupported.arm.stderr
index 297354c28..f7569c8cd 100644
--- a/src/test/ui/abi/unsupported.arm.stderr
+++ b/src/test/ui/abi/unsupported.arm.stderr
@@ -46,9 +46,9 @@ warning: use of calling convention not supported on this target
LL | extern "stdcall" fn stdcall() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unsupported_calling_conventions)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
+ = note: `#[warn(unsupported_calling_conventions)]` on by default
error: aborting due to 7 previous errors; 1 warning emitted
diff --git a/src/test/ui/abi/unsupported.x64.stderr b/src/test/ui/abi/unsupported.x64.stderr
index 49b88cd3f..26023a458 100644
--- a/src/test/ui/abi/unsupported.x64.stderr
+++ b/src/test/ui/abi/unsupported.x64.stderr
@@ -46,9 +46,9 @@ warning: use of calling convention not supported on this target
LL | extern "stdcall" fn stdcall() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unsupported_calling_conventions)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
+ = note: `#[warn(unsupported_calling_conventions)]` on by default
error: aborting due to 7 previous errors; 1 warning emitted
diff --git a/src/test/ui/abi/x86stdcall.rs b/src/test/ui/abi/x86stdcall.rs
index 868923e59..d1cf1319f 100644
--- a/src/test/ui/abi/x86stdcall.rs
+++ b/src/test/ui/abi/x86stdcall.rs
@@ -1,17 +1,15 @@
// run-pass
-// ignore-wasm32-bare no libc to test ffi with
-// ignore-sgx no libc
+// only-windows
// GetLastError doesn't seem to work with stack switching
#[cfg(windows)]
mod kernel32 {
- extern "system" {
- pub fn SetLastError(err: usize);
- pub fn GetLastError() -> usize;
- }
+ extern "system" {
+ pub fn SetLastError(err: usize);
+ pub fn GetLastError() -> usize;
+ }
}
-
#[cfg(windows)]
pub fn main() {
unsafe {
@@ -22,17 +20,3 @@ pub fn main() {
assert_eq!(expected, actual);
}
}
-
-#[cfg(any(target_os = "android",
- target_os = "dragonfly",
- target_os = "emscripten",
- target_os = "freebsd",
- target_os = "fuchsia",
- target_os = "illumos",
- target_os = "linux",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd",
- target_os = "solaris",
- target_os = "vxworks"))]
-pub fn main() { }
diff --git a/src/test/ui/abi/x86stdcall2.rs b/src/test/ui/abi/x86stdcall2.rs
index 563e3aba6..4d508ecb2 100644
--- a/src/test/ui/abi/x86stdcall2.rs
+++ b/src/test/ui/abi/x86stdcall2.rs
@@ -1,4 +1,5 @@
// run-pass
+// only-windows
#![allow(non_camel_case_types)]
pub type HANDLE = usize;
@@ -7,20 +8,16 @@ pub type SIZE_T = u32;
pub type LPVOID = usize;
pub type BOOL = u8;
-#[cfg(windows)]
mod kernel32 {
- use super::{HANDLE, DWORD, SIZE_T, LPVOID, BOOL};
+ use super::{BOOL, DWORD, HANDLE, LPVOID, SIZE_T};
extern "system" {
pub fn GetProcessHeap() -> HANDLE;
- pub fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T)
- -> LPVOID;
+ pub fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID;
pub fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL;
}
}
-
-#[cfg(windows)]
pub fn main() {
let heap = unsafe { kernel32::GetProcessHeap() };
let mem = unsafe { kernel32::HeapAlloc(heap, 0, 100) };
@@ -28,6 +25,3 @@ pub fn main() {
let res = unsafe { kernel32::HeapFree(heap, 0, mem) };
assert!(res != 0);
}
-
-#[cfg(not(windows))]
-pub fn main() { }
diff --git a/src/test/ui/alloc-error/default-alloc-error-hook.rs b/src/test/ui/alloc-error/default-alloc-error-hook.rs
index 100e97497..8be09500f 100644
--- a/src/test/ui/alloc-error/default-alloc-error-hook.rs
+++ b/src/test/ui/alloc-error/default-alloc-error-hook.rs
@@ -15,5 +15,14 @@ fn main() {
let me = env::current_exe().unwrap();
let output = Command::new(&me).arg("next").output().unwrap();
assert!(!output.status.success(), "{:?} is a success", output.status);
- assert_eq!(str::from_utf8(&output.stderr).unwrap(), "memory allocation of 42 bytes failed\n");
+
+ let mut stderr = str::from_utf8(&output.stderr).unwrap();
+
+ // When running inside QEMU user-mode emulation, there will be an extra message printed by QEMU
+ // in the stderr whenever a core dump happens. Remove it before the check.
+ stderr = stderr
+ .strip_suffix("qemu: uncaught target signal 6 (Aborted) - core dumped\n")
+ .unwrap_or(stderr);
+
+ assert_eq!(stderr, "memory allocation of 42 bytes failed\n");
}
diff --git a/src/test/ui/anon-params/anon-params-deprecated.stderr b/src/test/ui/anon-params/anon-params-deprecated.stderr
index 474b14f59..691e2c795 100644
--- a/src/test/ui/anon-params/anon-params-deprecated.stderr
+++ b/src/test/ui/anon-params/anon-params-deprecated.stderr
@@ -4,13 +4,13 @@ warning: anonymous parameters are deprecated and will be removed in the next edi
LL | fn foo(i32);
| ^^^ help: try naming the parameter or explicitly ignoring it: `_: i32`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
note: the lint level is defined here
--> $DIR/anon-params-deprecated.rs:1:9
|
LL | #![warn(anonymous_parameters)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
warning: anonymous parameters are deprecated and will be removed in the next edition
--> $DIR/anon-params-deprecated.rs:12:30
diff --git a/src/test/ui/anonymous-higher-ranked-lifetime.stderr b/src/test/ui/anonymous-higher-ranked-lifetime.stderr
index 1a0a5fdf4..bf5f642ca 100644
--- a/src/test/ui/anonymous-higher-ranked-lifetime.stderr
+++ b/src/test/ui/anonymous-higher-ranked-lifetime.stderr
@@ -6,7 +6,7 @@ LL | f1(|_: (), _: ()| {});
| |
| expected due to this
|
- = note: expected closure signature `for<'r, 's> fn(&'r (), &'s ()) -> _`
+ = note: expected closure signature `for<'a, 'b> fn(&'a (), &'b ()) -> _`
found closure signature `fn((), ()) -> _`
note: required by a bound in `f1`
--> $DIR/anonymous-higher-ranked-lifetime.rs:16:25
@@ -22,7 +22,7 @@ LL | f2(|_: (), _: ()| {});
| |
| expected due to this
|
- = note: expected closure signature `for<'a, 'r> fn(&'a (), &'r ()) -> _`
+ = note: expected closure signature `for<'a, 'b> fn(&'a (), &'b ()) -> _`
found closure signature `fn((), ()) -> _`
note: required by a bound in `f2`
--> $DIR/anonymous-higher-ranked-lifetime.rs:17:25
@@ -38,7 +38,7 @@ LL | f3(|_: (), _: ()| {});
| |
| expected due to this
|
- = note: expected closure signature `for<'r> fn(&(), &'r ()) -> _`
+ = note: expected closure signature `for<'a> fn(&(), &'a ()) -> _`
found closure signature `fn((), ()) -> _`
note: required by a bound in `f3`
--> $DIR/anonymous-higher-ranked-lifetime.rs:18:29
@@ -54,7 +54,7 @@ LL | f4(|_: (), _: ()| {});
| |
| expected due to this
|
- = note: expected closure signature `for<'r, 's> fn(&'s (), &'r ()) -> _`
+ = note: expected closure signature `for<'r, 'a> fn(&'a (), &'r ()) -> _`
found closure signature `fn((), ()) -> _`
note: required by a bound in `f4`
--> $DIR/anonymous-higher-ranked-lifetime.rs:19:25
@@ -86,7 +86,7 @@ LL | g1(|_: (), _: ()| {});
| |
| expected due to this
|
- = note: expected closure signature `for<'r> fn(&'r (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>) -> _`
+ = note: expected closure signature `for<'a> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>) -> _`
found closure signature `fn((), ()) -> _`
note: required by a bound in `g1`
--> $DIR/anonymous-higher-ranked-lifetime.rs:23:25
@@ -102,7 +102,7 @@ LL | g2(|_: (), _: ()| {});
| |
| expected due to this
|
- = note: expected closure signature `for<'r> fn(&'r (), for<'r> fn(&'r ())) -> _`
+ = note: expected closure signature `for<'a> fn(&'a (), for<'a> fn(&'a ())) -> _`
found closure signature `fn((), ()) -> _`
note: required by a bound in `g2`
--> $DIR/anonymous-higher-ranked-lifetime.rs:24:25
@@ -118,7 +118,7 @@ LL | g3(|_: (), _: ()| {});
| |
| expected due to this
|
- = note: expected closure signature `for<'s> fn(&'s (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>) -> _`
+ = note: expected closure signature `for<'s> fn(&'s (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>) -> _`
found closure signature `fn((), ()) -> _`
note: required by a bound in `g3`
--> $DIR/anonymous-higher-ranked-lifetime.rs:25:25
@@ -134,7 +134,7 @@ LL | g4(|_: (), _: ()| {});
| |
| expected due to this
|
- = note: expected closure signature `for<'s> fn(&'s (), for<'r> fn(&'r ())) -> _`
+ = note: expected closure signature `for<'a> fn(&'a (), for<'r> fn(&'r ())) -> _`
found closure signature `fn((), ()) -> _`
note: required by a bound in `g4`
--> $DIR/anonymous-higher-ranked-lifetime.rs:26:25
@@ -150,7 +150,7 @@ LL | h1(|_: (), _: (), _: (), _: ()| {});
| |
| expected due to this
|
- = note: expected closure signature `for<'r, 's> fn(&'r (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>, &'s (), for<'r, 's> fn(&'r (), &'s ())) -> _`
+ = note: expected closure signature `for<'a, 'b> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>, &'b (), for<'a, 'b> fn(&'a (), &'b ())) -> _`
found closure signature `fn((), (), (), ()) -> _`
note: required by a bound in `h1`
--> $DIR/anonymous-higher-ranked-lifetime.rs:29:25
@@ -166,7 +166,7 @@ LL | h2(|_: (), _: (), _: (), _: ()| {});
| |
| expected due to this
|
- = note: expected closure signature `for<'t0, 'r> fn(&'r (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>, &'t0 (), for<'r, 's> fn(&'r (), &'s ())) -> _`
+ = note: expected closure signature `for<'t0, 'a> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>, &'t0 (), for<'a, 'b> fn(&'a (), &'b ())) -> _`
found closure signature `fn((), (), (), ()) -> _`
note: required by a bound in `h2`
--> $DIR/anonymous-higher-ranked-lifetime.rs:30:25
diff --git a/src/test/ui/array-slice-vec/array_const_index-0.rs b/src/test/ui/array-slice-vec/array_const_index-0.rs
index 9ff7e2c56..96755802e 100644
--- a/src/test/ui/array-slice-vec/array_const_index-0.rs
+++ b/src/test/ui/array-slice-vec/array_const_index-0.rs
@@ -1,8 +1,7 @@
const A: &'static [i32] = &[];
const B: i32 = (&A)[1];
//~^ index out of bounds: the length is 0 but the index is 1
-//~| ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~| ERROR evaluation of constant value failed
fn main() {
let _ = B;
diff --git a/src/test/ui/array-slice-vec/array_const_index-0.stderr b/src/test/ui/array-slice-vec/array_const_index-0.stderr
index 483239871..3b92cc766 100644
--- a/src/test/ui/array-slice-vec/array_const_index-0.stderr
+++ b/src/test/ui/array-slice-vec/array_const_index-0.stderr
@@ -1,23 +1,9 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/array_const_index-0.rs:2:16
|
LL | const B: i32 = (&A)[1];
- | ------------ ^^^^^^^ index out of bounds: the length is 0 but the index is 1
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^ index out of bounds: the length is 0 but the index is 1
error: aborting due to previous error
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/array_const_index-0.rs:2:16
- |
-LL | const B: i32 = (&A)[1];
- | ------------ ^^^^^^^ index out of bounds: the length is 0 but the index is 1
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/array-slice-vec/array_const_index-1.rs b/src/test/ui/array-slice-vec/array_const_index-1.rs
index f4326189c..625bf06a7 100644
--- a/src/test/ui/array-slice-vec/array_const_index-1.rs
+++ b/src/test/ui/array-slice-vec/array_const_index-1.rs
@@ -1,8 +1,7 @@
const A: [i32; 0] = [];
const B: i32 = A[1];
//~^ index out of bounds: the length is 0 but the index is 1
-//~| ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~| ERROR evaluation of constant value failed
fn main() {
let _ = B;
diff --git a/src/test/ui/array-slice-vec/array_const_index-1.stderr b/src/test/ui/array-slice-vec/array_const_index-1.stderr
index 361f518c0..591db268a 100644
--- a/src/test/ui/array-slice-vec/array_const_index-1.stderr
+++ b/src/test/ui/array-slice-vec/array_const_index-1.stderr
@@ -1,23 +1,9 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/array_const_index-1.rs:2:16
|
LL | const B: i32 = A[1];
- | ------------ ^^^^ index out of bounds: the length is 0 but the index is 1
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^ index out of bounds: the length is 0 but the index is 1
error: aborting due to previous error
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/array_const_index-1.rs:2:16
- |
-LL | const B: i32 = A[1];
- | ------------ ^^^^ index out of bounds: the length is 0 but the index is 1
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/asm/aarch64/bad-reg.rs b/src/test/ui/asm/aarch64/bad-reg.rs
index 2b6a9b71c..9ccb8ed67 100644
--- a/src/test/ui/asm/aarch64/bad-reg.rs
+++ b/src/test/ui/asm/aarch64/bad-reg.rs
@@ -1,7 +1,7 @@
// only-aarch64
// compile-flags: -C target-feature=+neon
-#![feature(asm_const, asm_sym)]
+#![feature(asm_const)]
use std::arch::asm;
diff --git a/src/test/ui/asm/aarch64/may_unwind.rs b/src/test/ui/asm/aarch64/may_unwind.rs
index dfd891b42..6af8728bb 100644
--- a/src/test/ui/asm/aarch64/may_unwind.rs
+++ b/src/test/ui/asm/aarch64/may_unwind.rs
@@ -2,7 +2,7 @@
// run-pass
// needs-asm-support
-#![feature(asm_sym, asm_unwind)]
+#![feature(asm_unwind)]
use std::arch::asm;
use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
diff --git a/src/test/ui/asm/aarch64/sym.rs b/src/test/ui/asm/aarch64/sym.rs
index 3f659363c..6a6cdb00d 100644
--- a/src/test/ui/asm/aarch64/sym.rs
+++ b/src/test/ui/asm/aarch64/sym.rs
@@ -3,7 +3,7 @@
// needs-asm-support
// run-pass
-#![feature(thread_local, asm_sym)]
+#![feature(thread_local)]
use std::arch::asm;
diff --git a/src/test/ui/asm/aarch64/type-check-2-2.rs b/src/test/ui/asm/aarch64/type-check-2-2.rs
index aa12d4aa4..0ce1f1d8f 100644
--- a/src/test/ui/asm/aarch64/type-check-2-2.rs
+++ b/src/test/ui/asm/aarch64/type-check-2-2.rs
@@ -1,6 +1,6 @@
// only-aarch64
-#![feature(repr_simd, never_type, asm_sym)]
+#![feature(repr_simd, never_type)]
use std::arch::{asm, global_asm};
diff --git a/src/test/ui/asm/aarch64/type-check-2-2.stderr b/src/test/ui/asm/aarch64/type-check-2-2.stderr
index b2a695529..eef16a165 100644
--- a/src/test/ui/asm/aarch64/type-check-2-2.stderr
+++ b/src/test/ui/asm/aarch64/type-check-2-2.stderr
@@ -5,6 +5,11 @@ LL | let x: u64;
| - binding declared here but left uninitialized
LL | asm!("{}", in(reg) x);
| ^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: u64 = 0;
+ | +++
error[E0381]: used binding `y` isn't initialized
--> $DIR/type-check-2-2.rs:22:9
@@ -13,6 +18,11 @@ LL | let mut y: u64;
| ----- binding declared here but left uninitialized
LL | asm!("{}", inout(reg) y);
| ^^^^^^^^^^^^^^^^^^^^^^^^ `y` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let mut y: u64 = 0;
+ | +++
error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
--> $DIR/type-check-2-2.rs:30:29
diff --git a/src/test/ui/asm/aarch64/type-check-2.rs b/src/test/ui/asm/aarch64/type-check-2.rs
index fdafe63c7..1c71c1185 100644
--- a/src/test/ui/asm/aarch64/type-check-2.rs
+++ b/src/test/ui/asm/aarch64/type-check-2.rs
@@ -1,6 +1,6 @@
// only-aarch64
-#![feature(repr_simd, never_type, asm_sym)]
+#![feature(repr_simd, never_type)]
use std::arch::{asm, global_asm};
diff --git a/src/test/ui/asm/aarch64/type-check-3.stderr b/src/test/ui/asm/aarch64/type-check-3.stderr
index 49292982e..f710df2dc 100644
--- a/src/test/ui/asm/aarch64/type-check-3.stderr
+++ b/src/test/ui/asm/aarch64/type-check-3.stderr
@@ -4,9 +4,9 @@ warning: formatting may not be suitable for sub-register argument
LL | asm!("{}", in(reg) 0u8);
| ^^ --- for this argument
|
- = note: `#[warn(asm_sub_register)]` on by default
= help: use `{0:w}` to have the register formatted as `w0`
= help: or use `{0:x}` to keep the default formatting of `x0`
+ = note: `#[warn(asm_sub_register)]` on by default
warning: formatting may not be suitable for sub-register argument
--> $DIR/type-check-3.rs:50:15
diff --git a/src/test/ui/asm/bad-template.aarch64_mirunsafeck.stderr b/src/test/ui/asm/bad-template.aarch64_mirunsafeck.stderr
index 5dac693cc..bb6a222b2 100644
--- a/src/test/ui/asm/bad-template.aarch64_mirunsafeck.stderr
+++ b/src/test/ui/asm/bad-template.aarch64_mirunsafeck.stderr
@@ -189,9 +189,9 @@ warning: formatting may not be suitable for sub-register argument
LL | asm!("{:foo}", in(reg) foo);
| ^^^^^^ --- for this argument
|
- = note: `#[warn(asm_sub_register)]` on by default
= help: use `{0:w}` to have the register formatted as `w0`
= help: or use `{0:x}` to keep the default formatting of `x0`
+ = note: `#[warn(asm_sub_register)]` on by default
error: aborting due to 21 previous errors; 1 warning emitted
diff --git a/src/test/ui/asm/bad-template.aarch64_thirunsafeck.stderr b/src/test/ui/asm/bad-template.aarch64_thirunsafeck.stderr
index 5dac693cc..bb6a222b2 100644
--- a/src/test/ui/asm/bad-template.aarch64_thirunsafeck.stderr
+++ b/src/test/ui/asm/bad-template.aarch64_thirunsafeck.stderr
@@ -189,9 +189,9 @@ warning: formatting may not be suitable for sub-register argument
LL | asm!("{:foo}", in(reg) foo);
| ^^^^^^ --- for this argument
|
- = note: `#[warn(asm_sub_register)]` on by default
= help: use `{0:w}` to have the register formatted as `w0`
= help: or use `{0:x}` to keep the default formatting of `x0`
+ = note: `#[warn(asm_sub_register)]` on by default
error: aborting due to 21 previous errors; 1 warning emitted
diff --git a/src/test/ui/asm/bad-template.x86_64_mirunsafeck.stderr b/src/test/ui/asm/bad-template.x86_64_mirunsafeck.stderr
index b29b74bac..903b5e959 100644
--- a/src/test/ui/asm/bad-template.x86_64_mirunsafeck.stderr
+++ b/src/test/ui/asm/bad-template.x86_64_mirunsafeck.stderr
@@ -189,9 +189,9 @@ warning: formatting may not be suitable for sub-register argument
LL | asm!("{:foo}", in(reg) foo);
| ^^^^^^ --- for this argument
|
- = note: `#[warn(asm_sub_register)]` on by default
= help: use `{0:e}` to have the register formatted as `eax`
= help: or use `{0:r}` to keep the default formatting of `rax`
+ = note: `#[warn(asm_sub_register)]` on by default
error: aborting due to 21 previous errors; 1 warning emitted
diff --git a/src/test/ui/asm/bad-template.x86_64_thirunsafeck.stderr b/src/test/ui/asm/bad-template.x86_64_thirunsafeck.stderr
index b29b74bac..903b5e959 100644
--- a/src/test/ui/asm/bad-template.x86_64_thirunsafeck.stderr
+++ b/src/test/ui/asm/bad-template.x86_64_thirunsafeck.stderr
@@ -189,9 +189,9 @@ warning: formatting may not be suitable for sub-register argument
LL | asm!("{:foo}", in(reg) foo);
| ^^^^^^ --- for this argument
|
- = note: `#[warn(asm_sub_register)]` on by default
= help: use `{0:e}` to have the register formatted as `eax`
= help: or use `{0:r}` to keep the default formatting of `rax`
+ = note: `#[warn(asm_sub_register)]` on by default
error: aborting due to 21 previous errors; 1 warning emitted
diff --git a/src/test/ui/asm/generic-const.rs b/src/test/ui/asm/generic-const.rs
index 55c558780..caa9b7dbc 100644
--- a/src/test/ui/asm/generic-const.rs
+++ b/src/test/ui/asm/generic-const.rs
@@ -1,7 +1,7 @@
// needs-asm-support
// build-pass
-#![feature(asm_const, asm_sym)]
+#![feature(asm_const)]
use std::arch::asm;
diff --git a/src/test/ui/asm/naked-functions-ffi.stderr b/src/test/ui/asm/naked-functions-ffi.stderr
index ac7435513..908881b19 100644
--- a/src/test/ui/asm/naked-functions-ffi.stderr
+++ b/src/test/ui/asm/naked-functions-ffi.stderr
@@ -4,9 +4,9 @@ warning: `extern` fn uses type `char`, which is not FFI-safe
LL | pub extern "C" fn naked(p: char) -> u128 {
| ^^^^ not FFI-safe
|
- = note: `#[warn(improper_ctypes_definitions)]` on by default
= help: consider using `u32` or `libc::wchar_t` instead
= note: the `char` type has no C equivalent
+ = note: `#[warn(improper_ctypes_definitions)]` on by default
warning: `extern` fn uses type `u128`, which is not FFI-safe
--> $DIR/naked-functions-ffi.rs:9:37
diff --git a/src/test/ui/asm/naked-functions.rs b/src/test/ui/asm/naked-functions.rs
index 9e626f571..2f3716ca7 100644
--- a/src/test/ui/asm/naked-functions.rs
+++ b/src/test/ui/asm/naked-functions.rs
@@ -4,7 +4,7 @@
// ignore-wasm32
#![feature(naked_functions)]
-#![feature(asm_const, asm_sym, asm_unwind)]
+#![feature(asm_const, asm_unwind)]
#![crate_type = "lib"]
use std::arch::asm;
diff --git a/src/test/ui/asm/named-asm-labels.stderr b/src/test/ui/asm/named-asm-labels.stderr
index 001601497..c8380629e 100644
--- a/src/test/ui/asm/named-asm-labels.stderr
+++ b/src/test/ui/asm/named-asm-labels.stderr
@@ -4,9 +4,9 @@ error: avoid using named labels in inline assembly
LL | asm!("bar: nop");
| ^^^
|
- = note: `#[deny(named_asm_labels)]` on by default
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
+ = note: `#[deny(named_asm_labels)]` on by default
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:27:15
@@ -259,13 +259,13 @@ warning: avoid using named labels in inline assembly
LL | asm!("warned: nop");
| ^^^^^^
|
+ = help: only local labels of the form `<number>:` should be used in inline asm
+ = note: see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
note: the lint level is defined here
--> $DIR/named-asm-labels.rs:132:16
|
LL | #[warn(named_asm_labels)]
| ^^^^^^^^^^^^^^^^
- = help: only local labels of the form `<number>:` should be used in inline asm
- = note: see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
error: avoid using named labels in inline assembly
--> $DIR/named-asm-labels.rs:143:20
diff --git a/src/test/ui/asm/type-check-1.rs b/src/test/ui/asm/type-check-1.rs
index 50b369ae0..59f7b36af 100644
--- a/src/test/ui/asm/type-check-1.rs
+++ b/src/test/ui/asm/type-check-1.rs
@@ -3,7 +3,7 @@
// ignore-spirv
// ignore-wasm32
-#![feature(asm_const, asm_sym)]
+#![feature(asm_const)]
use std::arch::{asm, global_asm};
diff --git a/src/test/ui/asm/unpretty-expanded.rs b/src/test/ui/asm/unpretty-expanded.rs
index 6128f49b8..25cf1c3d7 100644
--- a/src/test/ui/asm/unpretty-expanded.rs
+++ b/src/test/ui/asm/unpretty-expanded.rs
@@ -1,3 +1,4 @@
+// needs-asm-support
// check-pass
// compile-flags: -Zunpretty=expanded
core::arch::global_asm!("x: .byte 42");
diff --git a/src/test/ui/asm/unpretty-expanded.stdout b/src/test/ui/asm/unpretty-expanded.stdout
index 15b60d155..ab1b5f45e 100644
--- a/src/test/ui/asm/unpretty-expanded.stdout
+++ b/src/test/ui/asm/unpretty-expanded.stdout
@@ -4,6 +4,7 @@
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
+// needs-asm-support
// check-pass
// compile-flags: -Zunpretty=expanded
global_asm! ("x: .byte 42");
diff --git a/src/test/ui/asm/x86_64/bad-reg.rs b/src/test/ui/asm/x86_64/bad-reg.rs
index a4f50a534..f5728079a 100644
--- a/src/test/ui/asm/x86_64/bad-reg.rs
+++ b/src/test/ui/asm/x86_64/bad-reg.rs
@@ -1,7 +1,7 @@
// only-x86_64
// compile-flags: -C target-feature=+avx2
-#![feature(asm_const, asm_sym)]
+#![feature(asm_const)]
use std::arch::asm;
diff --git a/src/test/ui/asm/x86_64/issue-96797.rs b/src/test/ui/asm/x86_64/issue-96797.rs
index d3e0906f3..954f8c5cc 100644
--- a/src/test/ui/asm/x86_64/issue-96797.rs
+++ b/src/test/ui/asm/x86_64/issue-96797.rs
@@ -7,8 +7,6 @@
// regression test for #96797
-#![feature(asm_sym)]
-
use std::arch::global_asm;
#[no_mangle]
diff --git a/src/test/ui/asm/x86_64/may_unwind.rs b/src/test/ui/asm/x86_64/may_unwind.rs
index 2f5d1a360..c11f0938d 100644
--- a/src/test/ui/asm/x86_64/may_unwind.rs
+++ b/src/test/ui/asm/x86_64/may_unwind.rs
@@ -3,7 +3,7 @@
// needs-asm-support
// needs-unwind
-#![feature(asm_sym, asm_unwind)]
+#![feature(asm_unwind)]
use std::arch::asm;
use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};
diff --git a/src/test/ui/asm/x86_64/multiple-clobber-abi.rs b/src/test/ui/asm/x86_64/multiple-clobber-abi.rs
index 513eb270e..06589431a 100644
--- a/src/test/ui/asm/x86_64/multiple-clobber-abi.rs
+++ b/src/test/ui/asm/x86_64/multiple-clobber-abi.rs
@@ -4,8 +4,6 @@
// Checks that multiple clobber_abi options can be used
-#![feature(asm_sym)]
-
use std::arch::asm;
extern "sysv64" fn foo(x: i32) -> i32 {
diff --git a/src/test/ui/asm/x86_64/sym.rs b/src/test/ui/asm/x86_64/sym.rs
index 447e11e6e..93ef4f090 100644
--- a/src/test/ui/asm/x86_64/sym.rs
+++ b/src/test/ui/asm/x86_64/sym.rs
@@ -3,7 +3,7 @@
// needs-asm-support
// run-pass
-#![feature(thread_local, asm_sym)]
+#![feature(thread_local)]
use std::arch::asm;
diff --git a/src/test/ui/asm/x86_64/type-check-2.rs b/src/test/ui/asm/x86_64/type-check-2.rs
index 59d8cde3f..80b29ec87 100644
--- a/src/test/ui/asm/x86_64/type-check-2.rs
+++ b/src/test/ui/asm/x86_64/type-check-2.rs
@@ -1,6 +1,6 @@
// only-x86_64
-#![feature(repr_simd, never_type, asm_sym)]
+#![feature(repr_simd, never_type)]
use std::arch::{asm, global_asm};
diff --git a/src/test/ui/asm/x86_64/type-check-3.stderr b/src/test/ui/asm/x86_64/type-check-3.stderr
index 366038fea..1baf50ff6 100644
--- a/src/test/ui/asm/x86_64/type-check-3.stderr
+++ b/src/test/ui/asm/x86_64/type-check-3.stderr
@@ -44,9 +44,9 @@ warning: formatting may not be suitable for sub-register argument
LL | asm!("{0} {0}", in(reg) 0i16);
| ^^^ ^^^ ---- for this argument
|
- = note: `#[warn(asm_sub_register)]` on by default
= help: use `{0:x}` to have the register formatted as `ax`
= help: or use `{0:r}` to keep the default formatting of `rax`
+ = note: `#[warn(asm_sub_register)]` on by default
warning: formatting may not be suitable for sub-register argument
--> $DIR/type-check-3.rs:36:15
diff --git a/src/test/ui/asm/x86_64/type-check-4.rs b/src/test/ui/asm/x86_64/type-check-4.rs
index da3b76c3d..3d5d3807c 100644
--- a/src/test/ui/asm/x86_64/type-check-4.rs
+++ b/src/test/ui/asm/x86_64/type-check-4.rs
@@ -1,14 +1,13 @@
// only-x86_64
// compile-flags: -C target-feature=+avx512f
-#![feature(asm_const, asm_sym)]
+#![feature(asm_const)]
use std::arch::{asm, global_asm};
use std::arch::x86_64::{_mm256_setzero_ps, _mm_setzero_ps};
-fn main() {
-}
+fn main() {}
// Constants must be... constant
diff --git a/src/test/ui/asm/x86_64/type-check-4.stderr b/src/test/ui/asm/x86_64/type-check-4.stderr
index 33f4638fb..3875bcc21 100644
--- a/src/test/ui/asm/x86_64/type-check-4.stderr
+++ b/src/test/ui/asm/x86_64/type-check-4.stderr
@@ -1,5 +1,5 @@
error[E0013]: constants cannot refer to statics
- --> $DIR/type-check-4.rs:22:25
+ --> $DIR/type-check-4.rs:21:25
|
LL | global_asm!("{}", const S);
| ^
@@ -7,7 +7,7 @@ LL | global_asm!("{}", const S);
= help: consider extracting the value of the `static` to a `const`, and referring to that
error[E0013]: constants cannot refer to statics
- --> $DIR/type-check-4.rs:25:35
+ --> $DIR/type-check-4.rs:24:35
|
LL | global_asm!("{}", const const_foo(S));
| ^
@@ -15,7 +15,7 @@ LL | global_asm!("{}", const const_foo(S));
= help: consider extracting the value of the `static` to a `const`, and referring to that
error[E0013]: constants cannot refer to statics
- --> $DIR/type-check-4.rs:28:35
+ --> $DIR/type-check-4.rs:27:35
|
LL | global_asm!("{}", const const_bar(S));
| ^
diff --git a/src/test/ui/asm/x86_64/type-check-5.rs b/src/test/ui/asm/x86_64/type-check-5.rs
index 6190e0b52..8198df910 100644
--- a/src/test/ui/asm/x86_64/type-check-5.rs
+++ b/src/test/ui/asm/x86_64/type-check-5.rs
@@ -1,6 +1,6 @@
// only-x86_64
-#![feature(repr_simd, never_type, asm_sym)]
+#![feature(repr_simd, never_type)]
use std::arch::asm;
diff --git a/src/test/ui/asm/x86_64/type-check-5.stderr b/src/test/ui/asm/x86_64/type-check-5.stderr
index e9c93fea5..bd90461e5 100644
--- a/src/test/ui/asm/x86_64/type-check-5.stderr
+++ b/src/test/ui/asm/x86_64/type-check-5.stderr
@@ -5,6 +5,11 @@ LL | let x: u64;
| - binding declared here but left uninitialized
LL | asm!("{}", in(reg) x);
| ^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: u64 = 0;
+ | +++
error[E0381]: used binding `y` isn't initialized
--> $DIR/type-check-5.rs:18:9
@@ -13,6 +18,11 @@ LL | let mut y: u64;
| ----- binding declared here but left uninitialized
LL | asm!("{}", inout(reg) y);
| ^^^^^^^^^^^^^^^^^^^^^^^^ `y` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let mut y: u64 = 0;
+ | +++
error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
--> $DIR/type-check-5.rs:26:29
diff --git a/src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr b/src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr
index de1d9589e..742b81535 100644
--- a/src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr
+++ b/src/test/ui/associated-consts/associated-const-impl-wrong-lifetime.stderr
@@ -2,7 +2,7 @@ error[E0308]: const not compatible with trait
--> $DIR/associated-const-impl-wrong-lifetime.rs:7:5
|
LL | const NAME: &'a str = "unit";
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
+ | ^^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected reference `&'static str`
found reference `&'a str`
diff --git a/src/test/ui/associated-consts/defaults-not-assumed-fail.rs b/src/test/ui/associated-consts/defaults-not-assumed-fail.rs
index 3936e6a3b..6762d7583 100644
--- a/src/test/ui/associated-consts/defaults-not-assumed-fail.rs
+++ b/src/test/ui/associated-consts/defaults-not-assumed-fail.rs
@@ -6,8 +6,7 @@ trait Tr {
// This should not be a constant evaluation error (overflow). The value of
// `Self::A` must not be assumed to hold inside the trait.
const B: u8 = Self::A + 1;
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of `<() as Tr>::B` failed
}
// An impl that doesn't override any constant will NOT cause a const eval error
@@ -34,7 +33,6 @@ fn main() {
assert_eq!(<() as Tr>::B, 0); // causes the error above
//~^ ERROR evaluation of constant value failed
//~| ERROR erroneous constant used
- //~| WARN this was previously accepted by the compiler but is being phased out
assert_eq!(<u8 as Tr>::A, 254);
assert_eq!(<u8 as Tr>::B, 255);
diff --git a/src/test/ui/associated-consts/defaults-not-assumed-fail.stderr b/src/test/ui/associated-consts/defaults-not-assumed-fail.stderr
index 66ee6031c..aa130f438 100644
--- a/src/test/ui/associated-consts/defaults-not-assumed-fail.stderr
+++ b/src/test/ui/associated-consts/defaults-not-assumed-fail.stderr
@@ -1,52 +1,23 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of `<() as Tr>::B` failed
--> $DIR/defaults-not-assumed-fail.rs:8:19
|
LL | const B: u8 = Self::A + 1;
- | ----------- ^^^^^^^^^^^ attempt to compute `u8::MAX + 1_u8`, which would overflow
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^ attempt to compute `u8::MAX + 1_u8`, which would overflow
error[E0080]: evaluation of constant value failed
- --> $DIR/defaults-not-assumed-fail.rs:34:16
+ --> $DIR/defaults-not-assumed-fail.rs:33:16
|
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
| ^^^^^^^^^^^^^ referenced constant has errors
-error: erroneous constant used
- --> $DIR/defaults-not-assumed-fail.rs:34:5
+error[E0080]: erroneous constant used
+ --> $DIR/defaults-not-assumed-fail.rs:33:5
|
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/defaults-not-assumed-fail.rs:8:19
- |
-LL | const B: u8 = Self::A + 1;
- | ----------- ^^^^^^^^^^^ attempt to compute `u8::MAX + 1_u8`, which would overflow
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: erroneous constant used
- --> $DIR/defaults-not-assumed-fail.rs:34:5
- |
-LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
-
diff --git a/src/test/ui/associated-consts/mismatched_impl_ty_1.rs b/src/test/ui/associated-consts/mismatched_impl_ty_1.rs
new file mode 100644
index 000000000..4dc6c2e47
--- /dev/null
+++ b/src/test/ui/associated-consts/mismatched_impl_ty_1.rs
@@ -0,0 +1,18 @@
+// run-pass
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+trait MyTrait {
+ type ArrayType;
+ const SIZE: usize;
+ const ARRAY: Self::ArrayType;
+}
+impl MyTrait for () {
+ type ArrayType = [u8; Self::SIZE];
+ const SIZE: usize = 4;
+ const ARRAY: [u8; Self::SIZE] = [1, 2, 3, 4];
+}
+
+fn main() {
+ let _ = <() as MyTrait>::ARRAY;
+}
diff --git a/src/test/ui/associated-consts/mismatched_impl_ty_2.rs b/src/test/ui/associated-consts/mismatched_impl_ty_2.rs
new file mode 100644
index 000000000..539becfdc
--- /dev/null
+++ b/src/test/ui/associated-consts/mismatched_impl_ty_2.rs
@@ -0,0 +1,11 @@
+// run-pass
+trait Trait {
+ const ASSOC: fn(&'static u32);
+}
+impl Trait for () {
+ const ASSOC: for<'a> fn(&'a u32) = |_| ();
+}
+
+fn main() {
+ let _ = <() as Trait>::ASSOC;
+}
diff --git a/src/test/ui/associated-consts/mismatched_impl_ty_3.rs b/src/test/ui/associated-consts/mismatched_impl_ty_3.rs
new file mode 100644
index 000000000..17bcc8fe5
--- /dev/null
+++ b/src/test/ui/associated-consts/mismatched_impl_ty_3.rs
@@ -0,0 +1,11 @@
+// run-pass
+trait Trait {
+ const ASSOC: for<'a, 'b> fn(&'a u32, &'b u32);
+}
+impl Trait for () {
+ const ASSOC: for<'a> fn(&'a u32, &'a u32) = |_, _| ();
+}
+
+fn main() {
+ let _ = <() as Trait>::ASSOC;
+}
diff --git a/src/test/ui/associated-item/associated-item-duplicate-names-2.stderr b/src/test/ui/associated-item/associated-item-duplicate-names-2.stderr
index f4efd1312..0b96a6bd7 100644
--- a/src/test/ui/associated-item/associated-item-duplicate-names-2.stderr
+++ b/src/test/ui/associated-item/associated-item-duplicate-names-2.stderr
@@ -1,11 +1,11 @@
-error[E0201]: duplicate definitions with name `bar`:
+error[E0592]: duplicate definitions with name `bar`
--> $DIR/associated-item-duplicate-names-2.rs:5:5
|
LL | const bar: bool = true;
- | --------------- previous definition of `bar` here
+ | --------------- other definition for `bar`
LL | fn bar() {}
- | ^^^^^^^^ duplicate definition
+ | ^^^^^^^^ duplicate definitions for `bar`
error: aborting due to previous error
-For more information about this error, try `rustc --explain E0201`.
+For more information about this error, try `rustc --explain E0592`.
diff --git a/src/test/ui/associated-item/associated-item-duplicate-names-3.rs b/src/test/ui/associated-item/associated-item-duplicate-names-3.rs
index 6aa1b483e..3a70a2f94 100644
--- a/src/test/ui/associated-item/associated-item-duplicate-names-3.rs
+++ b/src/test/ui/associated-item/associated-item-duplicate-names-3.rs
@@ -16,4 +16,5 @@ impl Foo for Baz {
fn main() {
let x: Baz::Bar = 5;
+ //~^ ERROR ambiguous associated type
}
diff --git a/src/test/ui/associated-item/associated-item-duplicate-names-3.stderr b/src/test/ui/associated-item/associated-item-duplicate-names-3.stderr
index 03782f663..bf4bd634c 100644
--- a/src/test/ui/associated-item/associated-item-duplicate-names-3.stderr
+++ b/src/test/ui/associated-item/associated-item-duplicate-names-3.stderr
@@ -1,11 +1,21 @@
error[E0201]: duplicate definitions with name `Bar`:
--> $DIR/associated-item-duplicate-names-3.rs:14:5
|
+LL | type Bar;
+ | --------- item in trait
+...
LL | type Bar = i16;
- | -------- previous definition of `Bar` here
+ | --------------- previous definition here
LL | type Bar = u16;
- | ^^^^^^^^ duplicate definition
+ | ^^^^^^^^^^^^^^^ duplicate definition
-error: aborting due to previous error
+error[E0223]: ambiguous associated type
+ --> $DIR/associated-item-duplicate-names-3.rs:18:12
+ |
+LL | let x: Baz::Bar = 5;
+ | ^^^^^^^^ help: use fully-qualified syntax: `<Baz as Trait>::Bar`
+
+error: aborting due to 2 previous errors
-For more information about this error, try `rustc --explain E0201`.
+Some errors have detailed explanations: E0201, E0223.
+For more information about an error, try `rustc --explain E0201`.
diff --git a/src/test/ui/associated-item/associated-item-duplicate-names.stderr b/src/test/ui/associated-item/associated-item-duplicate-names.stderr
index c9119c102..f89ea6e57 100644
--- a/src/test/ui/associated-item/associated-item-duplicate-names.stderr
+++ b/src/test/ui/associated-item/associated-item-duplicate-names.stderr
@@ -1,18 +1,24 @@
error[E0201]: duplicate definitions with name `Ty`:
--> $DIR/associated-item-duplicate-names.rs:11:5
|
+LL | type Ty;
+ | -------- item in trait
+...
LL | type Ty = ();
- | ------- previous definition of `Ty` here
+ | ------------- previous definition here
LL | type Ty = usize;
- | ^^^^^^^ duplicate definition
+ | ^^^^^^^^^^^^^^^^ duplicate definition
error[E0201]: duplicate definitions with name `BAR`:
--> $DIR/associated-item-duplicate-names.rs:13:5
|
+LL | const BAR: u32;
+ | --------------- item in trait
+...
LL | const BAR: u32 = 7;
- | -------------- previous definition of `BAR` here
+ | ------------------- previous definition here
LL | const BAR: u32 = 8;
- | ^^^^^^^^^^^^^^ duplicate definition
+ | ^^^^^^^^^^^^^^^^^^^ duplicate definition
error: aborting due to 2 previous errors
diff --git a/src/test/ui/impl-duplicate-methods.rs b/src/test/ui/associated-item/impl-duplicate-methods.rs
index adb09d7f5..328d54d5a 100644
--- a/src/test/ui/impl-duplicate-methods.rs
+++ b/src/test/ui/associated-item/impl-duplicate-methods.rs
@@ -3,7 +3,7 @@ struct Foo;
impl Foo {
fn orange(&self) {}
fn orange(&self) {}
- //~^ ERROR duplicate definition
+ //~^ ERROR duplicate definitions with name `orange` [E0592]
}
fn main() {}
diff --git a/src/test/ui/associated-item/impl-duplicate-methods.stderr b/src/test/ui/associated-item/impl-duplicate-methods.stderr
new file mode 100644
index 000000000..6f753845a
--- /dev/null
+++ b/src/test/ui/associated-item/impl-duplicate-methods.stderr
@@ -0,0 +1,11 @@
+error[E0592]: duplicate definitions with name `orange`
+ --> $DIR/impl-duplicate-methods.rs:5:5
+ |
+LL | fn orange(&self) {}
+ | ---------------- other definition for `orange`
+LL | fn orange(&self) {}
+ | ^^^^^^^^^^^^^^^^ duplicate definitions for `orange`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0592`.
diff --git a/src/test/ui/associated-type-bounds/inside-adt.rs b/src/test/ui/associated-type-bounds/inside-adt.rs
index f26037f07..8eb8c44bb 100644
--- a/src/test/ui/associated-type-bounds/inside-adt.rs
+++ b/src/test/ui/associated-type-bounds/inside-adt.rs
@@ -16,7 +16,7 @@ enum E2 { V(Box<dyn Iterator<Item: Copy>>) }
//~^ ERROR associated type bounds are not allowed within structs, enums, or unions
enum E3 { V(dyn Iterator<Item: 'static>) }
//~^ ERROR associated type bounds are not allowed within structs, enums, or unions
-//~| ERROR the size for values of type `(dyn Iterator<Item = impl Sized> + 'static)`
+//~| ERROR the size for values of type `(dyn Iterator<Item = impl Sized + 'static> + 'static)`
union U1 { f: ManuallyDrop<dyn Iterator<Item: Copy>> }
//~^ ERROR associated type bounds are not allowed within structs, enums, or unions
@@ -25,6 +25,6 @@ union U2 { f: ManuallyDrop<Box<dyn Iterator<Item: Copy>>> }
//~^ ERROR associated type bounds are not allowed within structs, enums, or unions
union U3 { f: ManuallyDrop<dyn Iterator<Item: 'static>> }
//~^ ERROR associated type bounds are not allowed within structs, enums, or unions
-//~| ERROR the size for values of type `(dyn Iterator<Item = impl Sized> + 'static)`
+//~| ERROR the size for values of type `(dyn Iterator<Item = impl Sized + 'static> + 'static)`
fn main() {}
diff --git a/src/test/ui/associated-type-bounds/inside-adt.stderr b/src/test/ui/associated-type-bounds/inside-adt.stderr
index 978390fa7..dbfcfa580 100644
--- a/src/test/ui/associated-type-bounds/inside-adt.stderr
+++ b/src/test/ui/associated-type-bounds/inside-adt.stderr
@@ -70,13 +70,13 @@ help: the `Box` type always has a statically known size and allocates its conten
LL | enum E1 { V(Box<dyn Iterator<Item: Copy>>) }
| ++++ +
-error[E0277]: the size for values of type `(dyn Iterator<Item = impl Sized> + 'static)` cannot be known at compilation time
+error[E0277]: the size for values of type `(dyn Iterator<Item = impl Sized + 'static> + 'static)` cannot be known at compilation time
--> $DIR/inside-adt.rs:17:13
|
LL | enum E3 { V(dyn Iterator<Item: 'static>) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
- = help: the trait `Sized` is not implemented for `(dyn Iterator<Item = impl Sized> + 'static)`
+ = help: the trait `Sized` is not implemented for `(dyn Iterator<Item = impl Sized + 'static> + 'static)`
= note: no field of an enum variant may have a dynamically sized type
= help: change the field's type to have a statically known size
help: borrowed types always have a statically known size
@@ -107,14 +107,14 @@ help: the `Box` type always has a statically known size and allocates its conten
LL | union U1 { f: Box<ManuallyDrop<dyn Iterator<Item: Copy>>> }
| ++++ +
-error[E0277]: the size for values of type `(dyn Iterator<Item = impl Sized> + 'static)` cannot be known at compilation time
+error[E0277]: the size for values of type `(dyn Iterator<Item = impl Sized + 'static> + 'static)` cannot be known at compilation time
--> $DIR/inside-adt.rs:26:15
|
LL | union U3 { f: ManuallyDrop<dyn Iterator<Item: 'static>> }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
- = help: within `ManuallyDrop<(dyn Iterator<Item = impl Sized> + 'static)>`, the trait `Sized` is not implemented for `(dyn Iterator<Item = impl Sized> + 'static)`
- = note: required because it appears within the type `ManuallyDrop<(dyn Iterator<Item = impl Sized> + 'static)>`
+ = help: within `ManuallyDrop<(dyn Iterator<Item = impl Sized + 'static> + 'static)>`, the trait `Sized` is not implemented for `(dyn Iterator<Item = impl Sized + 'static> + 'static)`
+ = note: required because it appears within the type `ManuallyDrop<(dyn Iterator<Item = impl Sized + 'static> + 'static)>`
= note: no field of a union may have a dynamically sized type
= help: change the field's type to have a statically known size
help: borrowed types always have a statically known size
diff --git a/src/test/ui/associated-types/cache/project-fn-ret-invariant.oneuse.stderr b/src/test/ui/associated-types/cache/project-fn-ret-invariant.oneuse.stderr
index cc1560162..77841780f 100644
--- a/src/test/ui/associated-types/cache/project-fn-ret-invariant.oneuse.stderr
+++ b/src/test/ui/associated-types/cache/project-fn-ret-invariant.oneuse.stderr
@@ -15,19 +15,19 @@ LL | let a = bar(f, x);
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
- --> $DIR/project-fn-ret-invariant.rs:40:13
+ --> $DIR/project-fn-ret-invariant.rs:42:13
|
LL | fn baz<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
-LL | let f = foo; // <-- No consistent type can be inferred for `f` here.
-LL | let a = bar(f, x);
+...
+LL | let b = bar(f, y);
| ^^^^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
- = note: requirement occurs because of a function pointer to `foo`
- = note: the function `foo` is invariant over the parameter `'a`
+ = note: requirement occurs because of the type `Type<'_>`, which makes the generic argument `'_` invariant
+ = note: the struct `Type<'a>` is invariant over the parameter `'a`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: `'a` and `'b` must be the same: replace one with the other
diff --git a/src/test/ui/associated-types/cache/project-fn-ret-invariant.rs b/src/test/ui/associated-types/cache/project-fn-ret-invariant.rs
index 1075fd6e0..e04337913 100644
--- a/src/test/ui/associated-types/cache/project-fn-ret-invariant.rs
+++ b/src/test/ui/associated-types/cache/project-fn-ret-invariant.rs
@@ -39,8 +39,8 @@ fn baz<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
let f = foo; // <-- No consistent type can be inferred for `f` here.
let a = bar(f, x);
//[oneuse]~^ ERROR lifetime may not live long enough
- //[oneuse]~| ERROR lifetime may not live long enough
let b = bar(f, y);
+ //[oneuse]~^ ERROR lifetime may not live long enough
(a, b)
}
diff --git a/src/test/ui/associated-types/defaults-specialization.stderr b/src/test/ui/associated-types/defaults-specialization.stderr
index 2d61b2a64..8df326351 100644
--- a/src/test/ui/associated-types/defaults-specialization.stderr
+++ b/src/test/ui/associated-types/defaults-specialization.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(associated_type_defaults, specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0053]: method `make` has an incompatible type for trait
--> $DIR/defaults-specialization.rs:19:18
diff --git a/src/test/ui/associated-types/issue-85103.rs b/src/test/ui/associated-types/issue-85103.rs
index c5e138561..9c6a419e9 100644
--- a/src/test/ui/associated-types/issue-85103.rs
+++ b/src/test/ui/associated-types/issue-85103.rs
@@ -4,6 +4,6 @@ use std::borrow::Cow;
#[rustc_layout(debug)]
type Edges<'a, E> = Cow<'a, [E]>;
-//~^ ERROR layout error: NormalizationFailure
+//~^ 6:1: 6:18: unable to determine layout for `<[E] as ToOwned>::Owned` because `<[E] as ToOwned>::Owned` cannot be normalized
fn main() {}
diff --git a/src/test/ui/associated-types/issue-85103.stderr b/src/test/ui/associated-types/issue-85103.stderr
index bddd1dce8..17f714807 100644
--- a/src/test/ui/associated-types/issue-85103.stderr
+++ b/src/test/ui/associated-types/issue-85103.stderr
@@ -1,4 +1,4 @@
-error: layout error: NormalizationFailure(<[E] as std::borrow::ToOwned>::Owned, Type(<[E] as std::borrow::ToOwned>::Owned))
+error: unable to determine layout for `<[E] as ToOwned>::Owned` because `<[E] as ToOwned>::Owned` cannot be normalized
--> $DIR/issue-85103.rs:6:1
|
LL | type Edges<'a, E> = Cow<'a, [E]>;
diff --git a/src/test/ui/associated-types/issue-87261.rs b/src/test/ui/associated-types/issue-87261.rs
index 384561f8c..e8548d402 100644
--- a/src/test/ui/associated-types/issue-87261.rs
+++ b/src/test/ui/associated-types/issue-87261.rs
@@ -77,10 +77,10 @@ where
fn main() {
accepts_trait(returns_opaque());
- //~^ ERROR type mismatch resolving `<impl Trait as Trait>::Associated == ()`
+ //~^ ERROR type mismatch resolving `<impl Trait + 'static as Trait>::Associated == ()`
accepts_trait(returns_opaque_derived());
- //~^ ERROR type mismatch resolving `<impl DerivedTrait as Trait>::Associated == ()`
+ //~^ ERROR type mismatch resolving `<impl DerivedTrait + 'static as Trait>::Associated == ()`
accepts_trait(returns_opaque_foo());
//~^ ERROR type mismatch resolving `<impl Trait + Foo as Trait>::Associated == ()`
@@ -89,7 +89,7 @@ fn main() {
//~^ ERROR type mismatch resolving `<impl DerivedTrait + Foo as Trait>::Associated == ()`
accepts_generic_trait(returns_opaque_generic());
- //~^ ERROR type mismatch resolving `<impl GenericTrait<()> as GenericTrait<()>>::Associated == ()`
+ //~^ ERROR type mismatch resolving `<impl GenericTrait<()> + 'static as GenericTrait<()>>::Associated == ()`
accepts_generic_trait(returns_opaque_generic_foo());
//~^ ERROR type mismatch resolving `<impl GenericTrait<()> + Foo as GenericTrait<()>>::Associated == ()`
diff --git a/src/test/ui/associated-types/issue-87261.stderr b/src/test/ui/associated-types/issue-87261.stderr
index f24423dd1..2cce6b947 100644
--- a/src/test/ui/associated-types/issue-87261.stderr
+++ b/src/test/ui/associated-types/issue-87261.stderr
@@ -132,7 +132,7 @@ note: required by a bound in `accepts_generic_trait`
LL | fn accepts_generic_trait<T: GenericTrait<(), Associated = ()>>(_: T) {}
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_generic_trait`
-error[E0271]: type mismatch resolving `<impl Trait as Trait>::Associated == ()`
+error[E0271]: type mismatch resolving `<impl Trait + 'static as Trait>::Associated == ()`
--> $DIR/issue-87261.rs:79:19
|
LL | fn returns_opaque() -> impl Trait + 'static {
@@ -144,18 +144,18 @@ LL | accepts_trait(returns_opaque());
| required by a bound introduced by this call
|
= note: expected unit type `()`
- found associated type `<impl Trait as Trait>::Associated`
+ found associated type `<impl Trait + 'static as Trait>::Associated`
note: required by a bound in `accepts_trait`
--> $DIR/issue-87261.rs:43:27
|
LL | fn accepts_trait<T: Trait<Associated = ()>>(_: T) {}
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait`
-help: consider constraining the associated type `<impl Trait as Trait>::Associated` to `()`
+help: consider constraining the associated type `<impl Trait + 'static as Trait>::Associated` to `()`
|
LL | fn returns_opaque() -> impl Trait<Associated = ()> + 'static {
| +++++++++++++++++
-error[E0271]: type mismatch resolving `<impl DerivedTrait as Trait>::Associated == ()`
+error[E0271]: type mismatch resolving `<impl DerivedTrait + 'static as Trait>::Associated == ()`
--> $DIR/issue-87261.rs:82:19
|
LL | fn returns_opaque_derived() -> impl DerivedTrait + 'static {
@@ -167,13 +167,13 @@ LL | accepts_trait(returns_opaque_derived());
| required by a bound introduced by this call
|
= note: expected unit type `()`
- found associated type `<impl DerivedTrait as Trait>::Associated`
+ found associated type `<impl DerivedTrait + 'static as Trait>::Associated`
note: required by a bound in `accepts_trait`
--> $DIR/issue-87261.rs:43:27
|
LL | fn accepts_trait<T: Trait<Associated = ()>>(_: T) {}
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait`
-help: consider constraining the associated type `<impl DerivedTrait as Trait>::Associated` to `()`
+help: consider constraining the associated type `<impl DerivedTrait + 'static as Trait>::Associated` to `()`
|
LL | fn returns_opaque_derived() -> impl DerivedTrait<Associated = ()> + 'static {
| +++++++++++++++++
@@ -222,7 +222,7 @@ note: required by a bound in `accepts_trait`
LL | fn accepts_trait<T: Trait<Associated = ()>>(_: T) {}
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_trait`
-error[E0271]: type mismatch resolving `<impl GenericTrait<()> as GenericTrait<()>>::Associated == ()`
+error[E0271]: type mismatch resolving `<impl GenericTrait<()> + 'static as GenericTrait<()>>::Associated == ()`
--> $DIR/issue-87261.rs:91:27
|
LL | fn returns_opaque_generic() -> impl GenericTrait<()> + 'static {
@@ -234,13 +234,13 @@ LL | accepts_generic_trait(returns_opaque_generic());
| required by a bound introduced by this call
|
= note: expected unit type `()`
- found associated type `<impl GenericTrait<()> as GenericTrait<()>>::Associated`
+ found associated type `<impl GenericTrait<()> + 'static as GenericTrait<()>>::Associated`
note: required by a bound in `accepts_generic_trait`
--> $DIR/issue-87261.rs:44:46
|
LL | fn accepts_generic_trait<T: GenericTrait<(), Associated = ()>>(_: T) {}
| ^^^^^^^^^^^^^^^ required by this bound in `accepts_generic_trait`
-help: consider constraining the associated type `<impl GenericTrait<()> as GenericTrait<()>>::Associated` to `()`
+help: consider constraining the associated type `<impl GenericTrait<()> + 'static as GenericTrait<()>>::Associated` to `()`
|
LL | fn returns_opaque_generic() -> impl GenericTrait<(), Associated = ()> + 'static {
| +++++++++++++++++
diff --git a/src/test/ui/async-await/async-fn-nonsend.stderr b/src/test/ui/async-await/async-fn-nonsend.stderr
index 40ad46b48..a7b872fe4 100644
--- a/src/test/ui/async-await/async-fn-nonsend.stderr
+++ b/src/test/ui/async-await/async-fn-nonsend.stderr
@@ -27,7 +27,7 @@ error: future cannot be sent between threads safely
LL | assert_send(non_sync_with_method_call());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ future returned by `non_sync_with_method_call` is not `Send`
|
- = help: the trait `Send` is not implemented for `dyn std::fmt::Write`
+ = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `dyn std::fmt::Write`
note: future is not `Send` as this value is used across an await
--> $DIR/async-fn-nonsend.rs:46:14
|
diff --git a/src/test/ui/async-await/async-fn-size-moved-locals.rs b/src/test/ui/async-await/async-fn-size-moved-locals.rs
index 155662566..79b7239f3 100644
--- a/src/test/ui/async-await/async-fn-size-moved-locals.rs
+++ b/src/test/ui/async-await/async-fn-size-moved-locals.rs
@@ -7,7 +7,7 @@
//
// See issue #59123 for a full explanation.
-// ignore-emscripten (sizes don't match)
+// needs-unwind Size of Futures change on panic=abort
// run-pass
// edition:2018
diff --git a/src/test/ui/async-await/async-fn-size-uninit-locals.rs b/src/test/ui/async-await/async-fn-size-uninit-locals.rs
index 31a086ba9..546172693 100644
--- a/src/test/ui/async-await/async-fn-size-uninit-locals.rs
+++ b/src/test/ui/async-await/async-fn-size-uninit-locals.rs
@@ -5,6 +5,7 @@
// being reflected in the size.
// ignore-emscripten (sizes don't match)
+// needs-unwind Size of Futures change on panic=abort
// run-pass
// edition:2018
@@ -67,9 +68,7 @@ async fn joined() {
let c = Big::new();
fut().await;
- noop();
joiner = Joiner { a: Some(a), b: Some(b), c: Some(c) };
- noop();
}
async fn joined_with_noop() {
@@ -97,7 +96,7 @@ async fn join_retval() -> Joiner {
fn main() {
assert_eq!(2, std::mem::size_of_val(&single()));
assert_eq!(3, std::mem::size_of_val(&single_with_noop()));
- assert_eq!(3078, std::mem::size_of_val(&joined()));
+ assert_eq!(3074, std::mem::size_of_val(&joined()));
assert_eq!(3078, std::mem::size_of_val(&joined_with_noop()));
assert_eq!(3074, std::mem::size_of_val(&join_retval()));
}
diff --git a/src/test/ui/async-await/async-trait-fn.rs b/src/test/ui/async-await/async-trait-fn.rs
index 0ea685986..e2062e827 100644
--- a/src/test/ui/async-await/async-trait-fn.rs
+++ b/src/test/ui/async-await/async-trait-fn.rs
@@ -1,11 +1,8 @@
// edition:2018
trait T {
async fn foo() {} //~ ERROR functions in traits cannot be declared `async`
- //~^ ERROR mismatched types
async fn bar(&self) {} //~ ERROR functions in traits cannot be declared `async`
- //~^ ERROR mismatched types
async fn baz() { //~ ERROR functions in traits cannot be declared `async`
- //~^ ERROR mismatched types
// Nested item must not ICE.
fn a() {}
}
diff --git a/src/test/ui/async-await/async-trait-fn.stderr b/src/test/ui/async-await/async-trait-fn.stderr
index e5c584e31..afbe25cf7 100644
--- a/src/test/ui/async-await/async-trait-fn.stderr
+++ b/src/test/ui/async-await/async-trait-fn.stderr
@@ -9,10 +9,10 @@ LL | async fn foo() {}
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
error[E0706]: functions in traits cannot be declared `async`
- --> $DIR/async-trait-fn.rs:5:5
+ --> $DIR/async-trait-fn.rs:4:5
|
LL | async fn bar(&self) {}
| -----^^^^^^^^^^^^^^
@@ -22,10 +22,10 @@ LL | async fn bar(&self) {}
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
error[E0706]: functions in traits cannot be declared `async`
- --> $DIR/async-trait-fn.rs:7:5
+ --> $DIR/async-trait-fn.rs:5:5
|
LL | async fn baz() {
| -----^^^^^^^^^
@@ -35,56 +35,8 @@ LL | async fn baz() {
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
-
-error[E0308]: mismatched types
- --> $DIR/async-trait-fn.rs:3:20
- |
-LL | async fn foo() {}
- | ^^ expected associated type, found opaque type
- |
- ::: $SRC_DIR/core/src/future/mod.rs:LL:COL
- |
-LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
- | ------------------------------- the found opaque type
- |
- = note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/async-trait-fn.rs:3:20>)
- found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
-
-error[E0308]: mismatched types
- --> $DIR/async-trait-fn.rs:5:25
- |
-LL | async fn bar(&self) {}
- | ^^ expected associated type, found opaque type
- |
- ::: $SRC_DIR/core/src/future/mod.rs:LL:COL
- |
-LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
- | ------------------------------- the found opaque type
- |
- = note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/async-trait-fn.rs:5:25>)
- found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
-
-error[E0308]: mismatched types
- --> $DIR/async-trait-fn.rs:7:20
- |
-LL | async fn baz() {
- | ____________________^
-LL | |
-LL | | // Nested item must not ICE.
-LL | | fn a() {}
-LL | | }
- | |_____^ expected associated type, found opaque type
- |
- ::: $SRC_DIR/core/src/future/mod.rs:LL:COL
- |
-LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
- | ------------------------------- the found opaque type
- |
- = note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/async-trait-fn.rs:7:20>)
- found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
-error: aborting due to 6 previous errors
+error: aborting due to 3 previous errors
-Some errors have detailed explanations: E0308, E0706.
-For more information about an error, try `rustc --explain E0308`.
+For more information about this error, try `rustc --explain E0706`.
diff --git a/src/test/ui/async-await/await-keyword/2015-edition-error-various-positions.stderr b/src/test/ui/async-await/await-keyword/2015-edition-error-various-positions.stderr
index 50a82c08c..d99967eb2 100644
--- a/src/test/ui/async-await/await-keyword/2015-edition-error-various-positions.stderr
+++ b/src/test/ui/async-await/await-keyword/2015-edition-error-various-positions.stderr
@@ -4,13 +4,13 @@ error: `await` is a keyword in the 2018 edition
LL | pub mod await {
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#await`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
note: the lint level is defined here
--> $DIR/2015-edition-error-various-positions.rs:2:9
|
LL | #![deny(keyword_idents)]
| ^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `await` is a keyword in the 2018 edition
--> $DIR/2015-edition-error-various-positions.rs:7:20
diff --git a/src/test/ui/async-await/await-keyword/2015-edition-warning.stderr b/src/test/ui/async-await/await-keyword/2015-edition-warning.stderr
index 1c4c19ea4..bf5c4d8d6 100644
--- a/src/test/ui/async-await/await-keyword/2015-edition-warning.stderr
+++ b/src/test/ui/async-await/await-keyword/2015-edition-warning.stderr
@@ -4,13 +4,13 @@ error: `await` is a keyword in the 2018 edition
LL | pub mod await {
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#await`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
note: the lint level is defined here
--> $DIR/2015-edition-warning.rs:4:9
|
LL | #![deny(keyword_idents)]
| ^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `await` is a keyword in the 2018 edition
--> $DIR/2015-edition-warning.rs:10:20
diff --git a/src/test/ui/async-await/await-keyword/2018-edition-error-in-non-macro-position.stderr b/src/test/ui/async-await/await-keyword/2018-edition-error-in-non-macro-position.stderr
index ccbaa1f2a..6bd8f671d 100644
--- a/src/test/ui/async-await/await-keyword/2018-edition-error-in-non-macro-position.stderr
+++ b/src/test/ui/async-await/await-keyword/2018-edition-error-in-non-macro-position.stderr
@@ -46,7 +46,9 @@ error: expected identifier, found keyword `await`
--> $DIR/2018-edition-error-in-non-macro-position.rs:13:14
|
LL | struct Foo { await: () }
- | ^^^^^ expected identifier, found keyword
+ | --- ^^^^^ expected identifier, found keyword
+ | |
+ | while parsing this struct
|
help: escape `await` to use it as an identifier
|
diff --git a/src/test/ui/async-await/edition-deny-async-fns-2015.rs b/src/test/ui/async-await/edition-deny-async-fns-2015.rs
index 22a61dcd2..6bd6d879a 100644
--- a/src/test/ui/async-await/edition-deny-async-fns-2015.rs
+++ b/src/test/ui/async-await/edition-deny-async-fns-2015.rs
@@ -17,7 +17,6 @@ impl Foo {
trait Bar {
async fn foo() {} //~ ERROR `async fn` is not permitted in Rust 2015
//~^ ERROR functions in traits cannot be declared `async`
- //~| ERROR mismatched types
}
fn main() {
diff --git a/src/test/ui/async-await/edition-deny-async-fns-2015.stderr b/src/test/ui/async-await/edition-deny-async-fns-2015.stderr
index 8c2902d9b..ba918eb28 100644
--- a/src/test/ui/async-await/edition-deny-async-fns-2015.stderr
+++ b/src/test/ui/async-await/edition-deny-async-fns-2015.stderr
@@ -53,7 +53,7 @@ LL | async fn foo() {}
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
error[E0670]: `async fn` is not permitted in Rust 2015
- --> $DIR/edition-deny-async-fns-2015.rs:37:9
+ --> $DIR/edition-deny-async-fns-2015.rs:36:9
|
LL | async fn bar() {}
| ^^^^^ to use `async fn`, switch to Rust 2018 or later
@@ -62,7 +62,7 @@ LL | async fn bar() {}
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
error[E0670]: `async fn` is not permitted in Rust 2015
- --> $DIR/edition-deny-async-fns-2015.rs:27:9
+ --> $DIR/edition-deny-async-fns-2015.rs:26:9
|
LL | async fn foo() {}
| ^^^^^ to use `async fn`, switch to Rust 2018 or later
@@ -71,7 +71,7 @@ LL | async fn foo() {}
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
error[E0670]: `async fn` is not permitted in Rust 2015
- --> $DIR/edition-deny-async-fns-2015.rs:32:13
+ --> $DIR/edition-deny-async-fns-2015.rs:31:13
|
LL | async fn bar() {}
| ^^^^^ to use `async fn`, switch to Rust 2018 or later
@@ -90,23 +90,9 @@ LL | async fn foo() {}
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
-error[E0308]: mismatched types
- --> $DIR/edition-deny-async-fns-2015.rs:18:20
- |
-LL | async fn foo() {}
- | ^^ expected associated type, found opaque type
- |
- ::: $SRC_DIR/core/src/future/mod.rs:LL:COL
- |
-LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
- | ------------------------------- the found opaque type
- |
- = note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/edition-deny-async-fns-2015.rs:18:20>)
- found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
-
-error: aborting due to 11 previous errors
+error: aborting due to 10 previous errors
-Some errors have detailed explanations: E0308, E0670, E0706.
-For more information about an error, try `rustc --explain E0308`.
+Some errors have detailed explanations: E0670, E0706.
+For more information about an error, try `rustc --explain E0670`.
diff --git a/src/test/ui/async-await/feature-gate-async_fn_in_trait.rs b/src/test/ui/async-await/feature-gate-async_fn_in_trait.rs
new file mode 100644
index 000000000..792f378cb
--- /dev/null
+++ b/src/test/ui/async-await/feature-gate-async_fn_in_trait.rs
@@ -0,0 +1,25 @@
+// edition:2021
+
+// RPITIT is not enough to allow use of async functions
+#![allow(incomplete_features)]
+#![feature(return_position_impl_trait_in_trait)]
+
+trait T {
+ async fn foo(); //~ ERROR functions in traits cannot be declared `async`
+}
+
+// Both return_position_impl_trait_in_trait and async_fn_in_trait are required for this (see also
+// feature-gate-return_position_impl_trait_in_trait.rs)
+trait T2 {
+ async fn foo() -> impl Sized; //~ ERROR functions in traits cannot be declared `async`
+}
+
+trait T3 {
+ fn foo() -> impl std::future::Future<Output = ()>;
+}
+
+impl T3 for () {
+ async fn foo() {} //~ ERROR functions in traits cannot be declared `async`
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/feature-gate-async_fn_in_trait.stderr b/src/test/ui/async-await/feature-gate-async_fn_in_trait.stderr
new file mode 100644
index 000000000..2a5fbd1ec
--- /dev/null
+++ b/src/test/ui/async-await/feature-gate-async_fn_in_trait.stderr
@@ -0,0 +1,42 @@
+error[E0706]: functions in traits cannot be declared `async`
+ --> $DIR/feature-gate-async_fn_in_trait.rs:8:5
+ |
+LL | async fn foo();
+ | -----^^^^^^^^^^
+ | |
+ | `async` because of this
+ |
+ = note: `async` trait functions are not currently supported
+ = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
+
+error[E0706]: functions in traits cannot be declared `async`
+ --> $DIR/feature-gate-async_fn_in_trait.rs:14:5
+ |
+LL | async fn foo() -> impl Sized;
+ | -----^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | `async` because of this
+ |
+ = note: `async` trait functions are not currently supported
+ = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
+
+error[E0706]: functions in traits cannot be declared `async`
+ --> $DIR/feature-gate-async_fn_in_trait.rs:22:5
+ |
+LL | async fn foo() {}
+ | -----^^^^^^^^^
+ | |
+ | `async` because of this
+ |
+ = note: `async` trait functions are not currently supported
+ = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0706`.
diff --git a/src/test/ui/async-await/in-trait/async-associated-types.rs b/src/test/ui/async-await/in-trait/async-associated-types.rs
new file mode 100644
index 000000000..a6f928f3b
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-associated-types.rs
@@ -0,0 +1,24 @@
+// check-fail
+// known-bug: #102682
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+use std::fmt::Debug;
+
+trait MyTrait<'a, 'b, T> where Self: 'a, T: Debug + Sized + 'b {
+ type MyAssoc;
+
+ async fn foo(&'a self, key: &'b T) -> Self::MyAssoc;
+}
+
+impl<'a, 'b, T: Debug + Sized + 'b, U: 'a> MyTrait<'a, 'b, T> for U {
+ type MyAssoc = (&'a U, &'b T);
+
+ async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
+ (self, key)
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/async-associated-types.stderr b/src/test/ui/async-await/in-trait/async-associated-types.stderr
new file mode 100644
index 000000000..0985150ee
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-associated-types.stderr
@@ -0,0 +1,57 @@
+error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
+ --> $DIR/async-associated-types.rs:19:43
+ |
+LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
+ | ^^^^^^^^^^^^^^
+ |
+note: first, the lifetime cannot outlive the lifetime `'a` as defined here...
+ --> $DIR/async-associated-types.rs:16:6
+ |
+LL | impl<'a, 'b, T: Debug + Sized + 'b, U: 'a> MyTrait<'a, 'b, T> for U {
+ | ^^
+note: ...so that the types are compatible
+ --> $DIR/async-associated-types.rs:19:43
+ |
+LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
+ | ^^^^^^^^^^^^^^
+ = note: expected `(&'a U, &'b T)`
+ found `(&U, &T)`
+ = note: but, the lifetime must be valid for the static lifetime...
+note: ...so that the types are compatible
+ --> $DIR/async-associated-types.rs:19:43
+ |
+LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
+ | ^^^^^^^^^^^^^^
+ = note: expected `MyTrait<'static, 'static, T>`
+ found `MyTrait<'_, '_, T>`
+
+error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements
+ --> $DIR/async-associated-types.rs:19:43
+ |
+LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
+ | ^^^^^^^^^^^^^^
+ |
+note: first, the lifetime cannot outlive the lifetime `'b` as defined here...
+ --> $DIR/async-associated-types.rs:16:10
+ |
+LL | impl<'a, 'b, T: Debug + Sized + 'b, U: 'a> MyTrait<'a, 'b, T> for U {
+ | ^^
+note: ...so that the types are compatible
+ --> $DIR/async-associated-types.rs:19:43
+ |
+LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
+ | ^^^^^^^^^^^^^^
+ = note: expected `(&'a U, &'b T)`
+ found `(&U, &T)`
+ = note: but, the lifetime must be valid for the static lifetime...
+note: ...so that the types are compatible
+ --> $DIR/async-associated-types.rs:19:43
+ |
+LL | async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
+ | ^^^^^^^^^^^^^^
+ = note: expected `MyTrait<'static, 'static, T>`
+ found `MyTrait<'_, '_, T>`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0495`.
diff --git a/src/test/ui/async-await/in-trait/async-associated-types2.rs b/src/test/ui/async-await/in-trait/async-associated-types2.rs
new file mode 100644
index 000000000..e546a0579
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-associated-types2.rs
@@ -0,0 +1,30 @@
+// check-pass
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![feature(type_alias_impl_trait)]
+#![allow(incomplete_features)]
+
+use std::future::Future;
+
+trait MyTrait {
+ type Fut<'a>: Future<Output = i32>
+ where
+ Self: 'a;
+
+ fn foo<'a>(&'a self) -> Self::Fut<'a>;
+}
+
+impl MyTrait for i32 {
+ type Fut<'a> = impl Future<Output = i32> + 'a
+ where
+ Self: 'a;
+
+ fn foo<'a>(&'a self) -> Self::Fut<'a> {
+ async {
+ *self
+ }
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/async-example-desugared-boxed-in-trait.rs b/src/test/ui/async-await/in-trait/async-example-desugared-boxed-in-trait.rs
new file mode 100644
index 000000000..38ba29718
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-example-desugared-boxed-in-trait.rs
@@ -0,0 +1,21 @@
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![feature(return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+use std::future::Future;
+use std::pin::Pin;
+
+trait MyTrait {
+ fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>>;
+}
+
+impl MyTrait for i32 {
+ async fn foo(&self) -> i32 {
+ //~^ ERROR method `foo` has an incompatible type for trait
+ *self
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/async-example-desugared-boxed-in-trait.stderr b/src/test/ui/async-await/in-trait/async-example-desugared-boxed-in-trait.stderr
new file mode 100644
index 000000000..22d2928f2
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-example-desugared-boxed-in-trait.stderr
@@ -0,0 +1,17 @@
+error[E0053]: method `foo` has an incompatible type for trait
+ --> $DIR/async-example-desugared-boxed-in-trait.rs:15:28
+ |
+LL | async fn foo(&self) -> i32 {
+ | ^^^ expected struct `Pin`, found opaque type
+ |
+note: type in trait
+ --> $DIR/async-example-desugared-boxed-in-trait.rs:11:22
+ |
+LL | fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>>;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: expected fn pointer `fn(&i32) -> Pin<Box<dyn Future<Output = i32>>>`
+ found fn pointer `fn(&i32) -> impl Future<Output = i32>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0053`.
diff --git a/src/test/ui/async-await/in-trait/async-example-desugared-boxed.rs b/src/test/ui/async-await/in-trait/async-example-desugared-boxed.rs
new file mode 100644
index 000000000..61d7e2520
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-example-desugared-boxed.rs
@@ -0,0 +1,24 @@
+// check-pass
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![feature(return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+use std::future::Future;
+use std::pin::Pin;
+
+trait MyTrait {
+ async fn foo(&self) -> i32;
+}
+
+impl MyTrait for i32 {
+ // This will break once a PR that implements #102745 is merged
+ fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>> {
+ Box::pin(async {
+ *self
+ })
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/async-example-desugared-in-trait.rs b/src/test/ui/async-await/in-trait/async-example-desugared-in-trait.rs
new file mode 100644
index 000000000..feeda719e
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-example-desugared-in-trait.rs
@@ -0,0 +1,21 @@
+// check-pass
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![feature(return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+use std::future::Future;
+
+trait MyTrait {
+ fn foo(&self) -> impl Future<Output = i32> + '_;
+}
+
+impl MyTrait for i32 {
+ // This will break once a PR that implements #102745 is merged
+ async fn foo(&self) -> i32 {
+ *self
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/async-example-desugared.rs b/src/test/ui/async-await/in-trait/async-example-desugared.rs
new file mode 100644
index 000000000..1313c9edd
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-example-desugared.rs
@@ -0,0 +1,23 @@
+// check-pass
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![feature(return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+use std::future::Future;
+
+trait MyTrait {
+ async fn foo(&self) -> i32;
+}
+
+impl MyTrait for i32 {
+ // This will break once a PR that implements #102745 is merged
+ fn foo(&self) -> impl Future<Output = i32> + '_ {
+ async {
+ *self
+ }
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/async-example.rs b/src/test/ui/async-await/in-trait/async-example.rs
new file mode 100644
index 000000000..abf94ef74
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-example.rs
@@ -0,0 +1,32 @@
+// check-pass
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+trait MyTrait {
+ async fn foo(&self) -> i32;
+ async fn bar(&self) -> i32;
+}
+
+impl MyTrait for i32 {
+ async fn foo(&self) -> i32 {
+ *self
+ }
+
+ async fn bar(&self) -> i32 {
+ self.foo().await
+ }
+}
+
+fn main() {
+ let x = 5;
+ // Calling from non-async context
+ let _ = x.foo();
+ let _ = x.bar();
+ // Calling from async block in non-async context
+ async {
+ let _: i32 = x.foo().await;
+ let _: i32 = x.bar().await;
+ };
+}
diff --git a/src/test/ui/async-await/in-trait/async-generics-and-bounds.rs b/src/test/ui/async-await/in-trait/async-generics-and-bounds.rs
new file mode 100644
index 000000000..a73d55adf
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-generics-and-bounds.rs
@@ -0,0 +1,21 @@
+// check-fail
+// known-bug: #102682
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+use std::fmt::Debug;
+use std::hash::Hash;
+
+trait MyTrait<T, U> {
+ async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
+}
+
+impl<T, U> MyTrait<T, U> for (T, U) {
+ async fn foo(&self) -> &(T, U) {
+ self
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/async-generics-and-bounds.stderr b/src/test/ui/async-await/in-trait/async-generics-and-bounds.stderr
new file mode 100644
index 000000000..5c8d64fc6
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-generics-and-bounds.stderr
@@ -0,0 +1,37 @@
+error[E0311]: the parameter type `U` may not live long enough
+ --> $DIR/async-generics-and-bounds.rs:12:28
+ |
+LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
+ | ^^^^^^^
+ |
+note: the parameter type `U` must be valid for the anonymous lifetime as defined here...
+ --> $DIR/async-generics-and-bounds.rs:12:18
+ |
+LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
+ | ^
+note: ...so that the reference type `&(T, U)` does not outlive the data it points at
+ --> $DIR/async-generics-and-bounds.rs:12:28
+ |
+LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
+ | ^^^^^^^
+
+error[E0311]: the parameter type `T` may not live long enough
+ --> $DIR/async-generics-and-bounds.rs:12:28
+ |
+LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
+ | ^^^^^^^
+ |
+note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
+ --> $DIR/async-generics-and-bounds.rs:12:18
+ |
+LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
+ | ^
+note: ...so that the reference type `&(T, U)` does not outlive the data it points at
+ --> $DIR/async-generics-and-bounds.rs:12:28
+ |
+LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
+ | ^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0311`.
diff --git a/src/test/ui/async-await/in-trait/async-generics.rs b/src/test/ui/async-await/in-trait/async-generics.rs
new file mode 100644
index 000000000..67000e577
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-generics.rs
@@ -0,0 +1,18 @@
+// check-fail
+// known-bug: #102682
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+trait MyTrait<T, U> {
+ async fn foo(&self) -> &(T, U);
+}
+
+impl<T, U> MyTrait<T, U> for (T, U) {
+ async fn foo(&self) -> &(T, U) {
+ self
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/async-generics.stderr b/src/test/ui/async-await/in-trait/async-generics.stderr
new file mode 100644
index 000000000..6ae73d9e3
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-generics.stderr
@@ -0,0 +1,37 @@
+error[E0311]: the parameter type `U` may not live long enough
+ --> $DIR/async-generics.rs:9:28
+ |
+LL | async fn foo(&self) -> &(T, U);
+ | ^^^^^^^
+ |
+note: the parameter type `U` must be valid for the anonymous lifetime as defined here...
+ --> $DIR/async-generics.rs:9:18
+ |
+LL | async fn foo(&self) -> &(T, U);
+ | ^
+note: ...so that the reference type `&(T, U)` does not outlive the data it points at
+ --> $DIR/async-generics.rs:9:28
+ |
+LL | async fn foo(&self) -> &(T, U);
+ | ^^^^^^^
+
+error[E0311]: the parameter type `T` may not live long enough
+ --> $DIR/async-generics.rs:9:28
+ |
+LL | async fn foo(&self) -> &(T, U);
+ | ^^^^^^^
+ |
+note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
+ --> $DIR/async-generics.rs:9:18
+ |
+LL | async fn foo(&self) -> &(T, U);
+ | ^
+note: ...so that the reference type `&(T, U)` does not outlive the data it points at
+ --> $DIR/async-generics.rs:9:28
+ |
+LL | async fn foo(&self) -> &(T, U);
+ | ^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0311`.
diff --git a/src/test/ui/async-await/in-trait/async-lifetimes-and-bounds.rs b/src/test/ui/async-await/in-trait/async-lifetimes-and-bounds.rs
new file mode 100644
index 000000000..3f7448cec
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-lifetimes-and-bounds.rs
@@ -0,0 +1,20 @@
+// check-fail
+// known-bug: #102682
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+use std::fmt::Debug;
+
+trait MyTrait<'a, 'b, T> {
+ async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T) where T: Debug + Sized;
+}
+
+impl<'a, 'b, T, U> MyTrait<'a, 'b, T> for U {
+ async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
+ (self, key)
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/async-lifetimes-and-bounds.stderr b/src/test/ui/async-await/in-trait/async-lifetimes-and-bounds.stderr
new file mode 100644
index 000000000..0f0242027
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-lifetimes-and-bounds.stderr
@@ -0,0 +1,23 @@
+error[E0309]: the parameter type `Self` may not live long enough
+ --> $DIR/async-lifetimes-and-bounds.rs:11:43
+ |
+LL | async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T) where T: Debug + Sized;
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = help: consider adding an explicit lifetime bound `Self: 'a`...
+ = note: ...so that the reference type `&'a Self` does not outlive the data it points at
+
+error[E0309]: the parameter type `T` may not live long enough
+ --> $DIR/async-lifetimes-and-bounds.rs:11:43
+ |
+LL | async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T) where T: Debug + Sized;
+ | ^^^^^^^^^^^^^^^^^ ...so that the reference type `&'b T` does not outlive the data it points at
+ |
+help: consider adding an explicit lifetime bound...
+ |
+LL | trait MyTrait<'a, 'b, T: 'b> {
+ | ++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0309`.
diff --git a/src/test/ui/async-await/in-trait/async-lifetimes.rs b/src/test/ui/async-await/in-trait/async-lifetimes.rs
new file mode 100644
index 000000000..acbac471c
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-lifetimes.rs
@@ -0,0 +1,18 @@
+// check-fail
+// known-bug: #102682
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+trait MyTrait<'a, 'b, T> {
+ async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T);
+}
+
+impl<'a, 'b, T, U> MyTrait<'a, 'b, T> for U {
+ async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
+ (self, key)
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/async-lifetimes.stderr b/src/test/ui/async-await/in-trait/async-lifetimes.stderr
new file mode 100644
index 000000000..9a7d294bb
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-lifetimes.stderr
@@ -0,0 +1,23 @@
+error[E0309]: the parameter type `Self` may not live long enough
+ --> $DIR/async-lifetimes.rs:9:43
+ |
+LL | async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T);
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = help: consider adding an explicit lifetime bound `Self: 'a`...
+ = note: ...so that the reference type `&'a Self` does not outlive the data it points at
+
+error[E0309]: the parameter type `T` may not live long enough
+ --> $DIR/async-lifetimes.rs:9:43
+ |
+LL | async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T);
+ | ^^^^^^^^^^^^^^^^^ ...so that the reference type `&'b T` does not outlive the data it points at
+ |
+help: consider adding an explicit lifetime bound...
+ |
+LL | trait MyTrait<'a, 'b, T: 'b> {
+ | ++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0309`.
diff --git a/src/test/ui/async-await/in-trait/async-recursive-generic.rs b/src/test/ui/async-await/in-trait/async-recursive-generic.rs
new file mode 100644
index 000000000..6839abd38
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-recursive-generic.rs
@@ -0,0 +1,21 @@
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+trait MyTrait<T> {
+ async fn foo_recursive(&self, n: usize) -> T;
+}
+
+impl<T> MyTrait<T> for T where T: Copy {
+ async fn foo_recursive(&self, n: usize) -> T {
+ //~^ ERROR recursion in an `async fn` requires boxing
+ if n > 0 {
+ self.foo_recursive(n - 1).await
+ } else {
+ *self
+ }
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/async-recursive-generic.stderr b/src/test/ui/async-await/in-trait/async-recursive-generic.stderr
new file mode 100644
index 000000000..cab173bdd
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-recursive-generic.stderr
@@ -0,0 +1,12 @@
+error[E0733]: recursion in an `async fn` requires boxing
+ --> $DIR/async-recursive-generic.rs:11:48
+ |
+LL | async fn foo_recursive(&self, n: usize) -> T {
+ | ^ recursive `async fn`
+ |
+ = note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
+ = note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0733`.
diff --git a/src/test/ui/async-await/in-trait/async-recursive.rs b/src/test/ui/async-await/in-trait/async-recursive.rs
new file mode 100644
index 000000000..61119f809
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-recursive.rs
@@ -0,0 +1,21 @@
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+trait MyTrait {
+ async fn foo_recursive(&self, n: usize) -> i32;
+}
+
+impl MyTrait for i32 {
+ async fn foo_recursive(&self, n: usize) -> i32 {
+ //~^ ERROR recursion in an `async fn` requires boxing
+ if n > 0 {
+ self.foo_recursive(n - 1).await
+ } else {
+ *self
+ }
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/async-recursive.stderr b/src/test/ui/async-await/in-trait/async-recursive.stderr
new file mode 100644
index 000000000..9feff37b3
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/async-recursive.stderr
@@ -0,0 +1,12 @@
+error[E0733]: recursion in an `async fn` requires boxing
+ --> $DIR/async-recursive.rs:11:48
+ |
+LL | async fn foo_recursive(&self, n: usize) -> i32 {
+ | ^^^ recursive `async fn`
+ |
+ = note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
+ = note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0733`.
diff --git a/src/test/ui/async-await/in-trait/fn-not-async-err.rs b/src/test/ui/async-await/in-trait/fn-not-async-err.rs
new file mode 100644
index 000000000..f94d32145
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/fn-not-async-err.rs
@@ -0,0 +1,17 @@
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+trait MyTrait {
+ async fn foo(&self) -> i32;
+}
+
+impl MyTrait for i32 {
+ fn foo(&self) -> i32 {
+ //~^ ERROR: `i32` is not a future [E0277]
+ *self
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/fn-not-async-err.stderr b/src/test/ui/async-await/in-trait/fn-not-async-err.stderr
new file mode 100644
index 000000000..03321dc5b
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/fn-not-async-err.stderr
@@ -0,0 +1,17 @@
+error[E0277]: `i32` is not a future
+ --> $DIR/fn-not-async-err.rs:11:22
+ |
+LL | fn foo(&self) -> i32 {
+ | ^^^ `i32` is not a future
+ |
+ = help: the trait `Future` is not implemented for `i32`
+ = note: i32 must be a future or must implement `IntoFuture` to be awaited
+note: required by a bound in `MyTrait::foo::{opaque#0}`
+ --> $DIR/fn-not-async-err.rs:7:28
+ |
+LL | async fn foo(&self) -> i32;
+ | ^^^ required by this bound in `MyTrait::foo::{opaque#0}`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/async-await/in-trait/fn-not-async-err2.rs b/src/test/ui/async-await/in-trait/fn-not-async-err2.rs
new file mode 100644
index 000000000..594baa91a
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/fn-not-async-err2.rs
@@ -0,0 +1,21 @@
+// edition: 2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+use std::future::Future;
+
+trait MyTrait {
+ async fn foo(&self) -> i32;
+}
+
+impl MyTrait for i32 {
+ fn foo(&self) -> impl Future<Output = i32> {
+ //~^ ERROR `impl Trait` only allowed in function and inherent method return types, not in `impl` method return [E0562]
+ async {
+ *self
+ }
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/in-trait/fn-not-async-err2.stderr b/src/test/ui/async-await/in-trait/fn-not-async-err2.stderr
new file mode 100644
index 000000000..f591f1847
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/fn-not-async-err2.stderr
@@ -0,0 +1,12 @@
+error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `impl` method return
+ --> $DIR/fn-not-async-err2.rs:13:22
+ |
+LL | fn foo(&self) -> impl Future<Output = i32> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0562`.
diff --git a/src/test/ui/async-await/in-trait/issue-102138.rs b/src/test/ui/async-await/in-trait/issue-102138.rs
new file mode 100644
index 000000000..f61b34ed9
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/issue-102138.rs
@@ -0,0 +1,46 @@
+// check-pass
+// edition:2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+use std::future::Future;
+
+async fn yield_now() {}
+
+trait AsyncIterator {
+ type Item;
+ async fn next(&mut self) -> Option<Self::Item>;
+}
+
+struct YieldingRange {
+ counter: u32,
+ stop: u32,
+}
+
+impl AsyncIterator for YieldingRange {
+ type Item = u32;
+
+ async fn next(&mut self) -> Option<Self::Item> {
+ if self.counter == self.stop {
+ None
+ } else {
+ let c = self.counter;
+ self.counter += 1;
+ yield_now().await;
+ Some(c)
+ }
+ }
+}
+
+async fn async_main() {
+ let mut x = YieldingRange { counter: 0, stop: 10 };
+
+ while let Some(v) = x.next().await {
+ println!("Hi: {v}");
+ }
+}
+
+fn main() {
+ let _ = async_main();
+}
diff --git a/src/test/ui/async-await/in-trait/issue-102219.rs b/src/test/ui/async-await/in-trait/issue-102219.rs
new file mode 100644
index 000000000..9a35f6515
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/issue-102219.rs
@@ -0,0 +1,10 @@
+// compile-flags:--crate-type=lib
+// edition:2021
+// check-pass
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+trait T {
+ async fn foo();
+}
diff --git a/src/test/ui/async-await/in-trait/issue-102310.rs b/src/test/ui/async-await/in-trait/issue-102310.rs
new file mode 100644
index 000000000..49c3e9fee
--- /dev/null
+++ b/src/test/ui/async-await/in-trait/issue-102310.rs
@@ -0,0 +1,15 @@
+// check-pass
+// edition:2021
+
+#![feature(async_fn_in_trait)]
+#![allow(incomplete_features)]
+
+pub trait SpiDevice {
+ async fn transaction<F, R>(&mut self);
+}
+
+impl SpiDevice for () {
+ async fn transaction<F, R>(&mut self) {}
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/issue-64130-1-sync.rs b/src/test/ui/async-await/issue-64130-1-sync.rs
index af83f14bb..1714cec52 100644
--- a/src/test/ui/async-await/issue-64130-1-sync.rs
+++ b/src/test/ui/async-await/issue-64130-1-sync.rs
@@ -1,7 +1,7 @@
#![feature(negative_impls)]
// edition:2018
-// This tests the the specialized async-await-specific error when futures don't implement an
+// This tests the specialized async-await-specific error when futures don't implement an
// auto trait (which is specifically Sync) due to some type that was captured.
struct Foo;
diff --git a/src/test/ui/async-await/issue-64130-2-send.rs b/src/test/ui/async-await/issue-64130-2-send.rs
index 2362831d8..7a6e5952c 100644
--- a/src/test/ui/async-await/issue-64130-2-send.rs
+++ b/src/test/ui/async-await/issue-64130-2-send.rs
@@ -1,7 +1,7 @@
#![feature(negative_impls)]
// edition:2018
-// This tests the the specialized async-await-specific error when futures don't implement an
+// This tests the specialized async-await-specific error when futures don't implement an
// auto trait (which is specifically Send) due to some type that was captured.
struct Foo;
diff --git a/src/test/ui/async-await/issue-64130-3-other.rs b/src/test/ui/async-await/issue-64130-3-other.rs
index 52801c35b..630fb2c41 100644
--- a/src/test/ui/async-await/issue-64130-3-other.rs
+++ b/src/test/ui/async-await/issue-64130-3-other.rs
@@ -2,7 +2,7 @@
#![feature(negative_impls)]
// edition:2018
-// This tests the the unspecialized async-await-specific error when futures don't implement an
+// This tests the unspecialized async-await-specific error when futures don't implement an
// auto trait (which is not Send or Sync) due to some type that was captured.
auto trait Qux {}
diff --git a/src/test/ui/async-await/issue-66387-if-without-else.stderr b/src/test/ui/async-await/issue-66387-if-without-else.stderr
index e8e2a4898..8155fcb56 100644
--- a/src/test/ui/async-await/issue-66387-if-without-else.stderr
+++ b/src/test/ui/async-await/issue-66387-if-without-else.stderr
@@ -4,7 +4,7 @@ error[E0317]: `if` may be missing an `else` clause
LL | / if true {
LL | | return 0;
LL | | }
- | |_____^ expected `()`, found `i32`
+ | |_____^ expected `i32`, found `()`
|
= note: `if` expressions without `else` evaluate to `()`
= help: consider adding an `else` block that evaluates to the expected type
diff --git a/src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr b/src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr
index 198de7bf7..7fb881166 100644
--- a/src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr
+++ b/src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr
@@ -18,7 +18,7 @@ LL | async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> {
| ___________________________________________________________________^
LL | | }
| |_^
- = note: required because it captures the following types: `ResumeTy`, `impl for<'r, 's, 't0> Future<Output = ()>`, `()`
+ = note: required because it captures the following types: `ResumeTy`, `impl Future<Output = ()>`, `()`
note: required because it's used within this `async` block
--> $DIR/issue-70935-complex-spans.rs:16:16
|
diff --git a/src/test/ui/issues/issue-73541-3.rs b/src/test/ui/async-await/issue-73541-3.rs
index 02ca02da8..02ca02da8 100644
--- a/src/test/ui/issues/issue-73541-3.rs
+++ b/src/test/ui/async-await/issue-73541-3.rs
diff --git a/src/test/ui/issues/issue-73541-3.stderr b/src/test/ui/async-await/issue-73541-3.stderr
index 53487aaca..53487aaca 100644
--- a/src/test/ui/issues/issue-73541-3.stderr
+++ b/src/test/ui/async-await/issue-73541-3.stderr
diff --git a/src/test/ui/issues/issue-73541.rs b/src/test/ui/async-await/issue-73541.rs
index 399a07cd3..399a07cd3 100644
--- a/src/test/ui/issues/issue-73541.rs
+++ b/src/test/ui/async-await/issue-73541.rs
diff --git a/src/test/ui/issues/issue-73541.stderr b/src/test/ui/async-await/issue-73541.stderr
index 4bb466ff1..4bb466ff1 100644
--- a/src/test/ui/issues/issue-73541.stderr
+++ b/src/test/ui/async-await/issue-73541.stderr
diff --git a/src/test/ui/async-await/issue-98634.rs b/src/test/ui/async-await/issue-98634.rs
new file mode 100644
index 000000000..b0d38687f
--- /dev/null
+++ b/src/test/ui/async-await/issue-98634.rs
@@ -0,0 +1,50 @@
+// edition: 2021
+
+use std::{
+ future::Future,
+ pin::Pin,
+ task::{Context, Poll, Waker},
+};
+
+pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
+ pub callback: F,
+}
+
+impl<F> Future for StructAsync<F>
+where
+ F: Fn() -> Pin<Box<dyn Future<Output = ()>>>,
+{
+ type Output = ();
+
+ fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
+ Poll::Pending
+ }
+}
+
+async fn callback() {}
+
+struct Runtime;
+
+fn waker() -> &'static Waker {
+ todo!()
+}
+
+impl Runtime {
+ #[track_caller]
+ pub fn block_on<F: Future>(&self, mut future: F) -> F::Output {
+ loop {
+ unsafe {
+ Pin::new_unchecked(&mut future).poll(&mut Context::from_waker(waker()));
+ }
+ }
+ }
+}
+
+fn main() {
+ Runtime.block_on(async {
+ StructAsync { callback }.await;
+ //~^ ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
+ //~| ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
+ //~| ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
+ });
+}
diff --git a/src/test/ui/async-await/issue-98634.stderr b/src/test/ui/async-await/issue-98634.stderr
new file mode 100644
index 000000000..5160e48d8
--- /dev/null
+++ b/src/test/ui/async-await/issue-98634.stderr
@@ -0,0 +1,60 @@
+error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
+ --> $DIR/issue-98634.rs:45:23
+ |
+LL | StructAsync { callback }.await;
+ | ^^^^^^^^ expected struct `Pin`, found opaque type
+ |
+note: while checking the return type of the `async fn`
+ --> $DIR/issue-98634.rs:24:21
+ |
+LL | async fn callback() {}
+ | ^ checked the `Output` of this `async fn`, found opaque type
+ = note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
+ found opaque type `impl Future<Output = ()>`
+note: required by a bound in `StructAsync`
+ --> $DIR/issue-98634.rs:9:35
+ |
+LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync`
+
+error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
+ --> $DIR/issue-98634.rs:45:9
+ |
+LL | StructAsync { callback }.await;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Pin`, found opaque type
+ |
+note: while checking the return type of the `async fn`
+ --> $DIR/issue-98634.rs:24:21
+ |
+LL | async fn callback() {}
+ | ^ checked the `Output` of this `async fn`, found opaque type
+ = note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
+ found opaque type `impl Future<Output = ()>`
+note: required by a bound in `StructAsync`
+ --> $DIR/issue-98634.rs:9:35
+ |
+LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync`
+
+error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
+ --> $DIR/issue-98634.rs:45:33
+ |
+LL | StructAsync { callback }.await;
+ | ^^^^^^ expected struct `Pin`, found opaque type
+ |
+note: while checking the return type of the `async fn`
+ --> $DIR/issue-98634.rs:24:21
+ |
+LL | async fn callback() {}
+ | ^ checked the `Output` of this `async fn`, found opaque type
+ = note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
+ found opaque type `impl Future<Output = ()>`
+note: required by a bound in `StructAsync`
+ --> $DIR/issue-98634.rs:9:35
+ |
+LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0271`.
diff --git a/src/test/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-panic.rs b/src/test/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-panic.rs
index 5e71229be..b4ea4c9f6 100644
--- a/src/test/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-panic.rs
+++ b/src/test/ui/async-await/issues/issue-65419/issue-65419-async-fn-resume-after-panic.rs
@@ -6,7 +6,6 @@
// error-pattern: thread 'main' panicked at '`async fn` resumed after panicking'
// edition:2018
// ignore-wasm no panic or subprocess support
-// ignore-emscripten no panic or subprocess support
#![feature(generators, generator_trait)]
diff --git a/src/test/ui/async-await/issues/issue-95307.stderr b/src/test/ui/async-await/issues/issue-95307.stderr
index 1c12f1e48..a497cebe3 100644
--- a/src/test/ui/async-await/issues/issue-95307.stderr
+++ b/src/test/ui/async-await/issues/issue-95307.stderr
@@ -9,7 +9,7 @@ LL | async fn new() -> [u8; _];
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
error: in expressions, `_` can only be used on the left-hand side of an assignment
--> $DIR/issue-95307.rs:7:28
diff --git a/src/test/ui/async-await/large_moves.attribute.stderr b/src/test/ui/async-await/large_moves.attribute.stderr
index 8d3f0b77f..da34f44b2 100644
--- a/src/test/ui/async-await/large_moves.attribute.stderr
+++ b/src/test/ui/async-await/large_moves.attribute.stderr
@@ -10,12 +10,12 @@ LL | | dbg!(y);
LL | | };
| |_____^ value moved from here
|
+ = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
note: the lint level is defined here
--> $DIR/large_moves.rs:1:9
|
LL | #![deny(large_assignments)]
| ^^^^^^^^^^^^^^^^^
- = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
error: moving 10024 bytes
--> $DIR/large_moves.rs:18:14
diff --git a/src/test/ui/async-await/large_moves.option.stderr b/src/test/ui/async-await/large_moves.option.stderr
index 8d3f0b77f..da34f44b2 100644
--- a/src/test/ui/async-await/large_moves.option.stderr
+++ b/src/test/ui/async-await/large_moves.option.stderr
@@ -10,12 +10,12 @@ LL | | dbg!(y);
LL | | };
| |_____^ value moved from here
|
+ = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
note: the lint level is defined here
--> $DIR/large_moves.rs:1:9
|
LL | #![deny(large_assignments)]
| ^^^^^^^^^^^^^^^^^
- = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
error: moving 10024 bytes
--> $DIR/large_moves.rs:18:14
diff --git a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr
index 3128b4df4..ae4d0d585 100644
--- a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr
+++ b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr
@@ -25,7 +25,7 @@ LL | | (a, b)
LL | | }
| |_^
|
-help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
+help: to declare that `impl Trait<'a>` captures `'b`, you can add an explicit `'b` lifetime bound
|
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b {
| ++++
diff --git a/src/test/ui/async-await/no-const-async.stderr b/src/test/ui/async-await/no-const-async.stderr
index e6f6e9e9f..c5bd520aa 100644
--- a/src/test/ui/async-await/no-const-async.stderr
+++ b/src/test/ui/async-await/no-const-async.stderr
@@ -18,7 +18,7 @@ note: ...which requires borrow-checking `x`...
|
LL | pub const async fn x() {}
| ^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires processing `x`...
+note: ...which requires processing MIR for `x`...
--> $DIR/no-const-async.rs:4:1
|
LL | pub const async fn x() {}
diff --git a/src/test/ui/attr-from-macro.rs b/src/test/ui/attr-from-macro.rs
new file mode 100644
index 000000000..bb3a5c94d
--- /dev/null
+++ b/src/test/ui/attr-from-macro.rs
@@ -0,0 +1,20 @@
+// aux-build:attr-from-macro.rs
+// run-pass
+
+extern crate attr_from_macro;
+
+attr_from_macro::creator! {
+ struct Foo;
+ enum Bar;
+ enum FooBar;
+}
+
+fn main() {
+ // Checking the `repr(u32)` on the enum.
+ assert_eq!(4, std::mem::size_of::<Bar>());
+ // Checking the `repr(u16)` on the enum.
+ assert_eq!(2, std::mem::size_of::<FooBar>());
+
+ // Checking the Debug impl on the types.
+ eprintln!("{:?} {:?} {:?}", Foo, Bar::A, FooBar::A);
+}
diff --git a/src/test/ui/attributes/doc-attr.stderr b/src/test/ui/attributes/doc-attr.stderr
index cc2494c92..68df2771f 100644
--- a/src/test/ui/attributes/doc-attr.stderr
+++ b/src/test/ui/attributes/doc-attr.stderr
@@ -4,14 +4,14 @@ error: unknown `doc` attribute `as_ptr`
LL | #[doc(as_ptr)]
| ^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
note: the lint level is defined here
--> $DIR/doc-attr.rs:2:9
|
LL | #![deny(warnings)]
| ^^^^^^^^
= note: `#[deny(invalid_doc_attributes)]` implied by `#[deny(warnings)]`
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: invalid `doc` attribute
--> $DIR/doc-attr.rs:12:7
diff --git a/src/test/ui/attributes/invalid-doc-attr.stderr b/src/test/ui/attributes/invalid-doc-attr.stderr
index a4fa38179..3c66e587b 100644
--- a/src/test/ui/attributes/invalid-doc-attr.stderr
+++ b/src/test/ui/attributes/invalid-doc-attr.stderr
@@ -4,15 +4,15 @@ error: this attribute can only be applied at the crate level
LL | #[doc(test(no_crate_inject))]
| ^^^^^^^^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
+ = note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
note: the lint level is defined here
--> $DIR/invalid-doc-attr.rs:2:9
|
LL | #![deny(warnings)]
| ^^^^^^^^
= note: `#[deny(invalid_doc_attributes)]` implied by `#[deny(warnings)]`
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
- = note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
help: to apply to the crate, use an inner attribute
|
LL | #![doc(test(no_crate_inject))]
diff --git a/src/test/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs b/src/test/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs
index e8b4fe7ae..74fbae035 100644
--- a/src/test/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs
+++ b/src/test/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs
@@ -23,9 +23,11 @@ pub fn assert_sigpipe_handler(expected_handler: SignalHandler) {
SignalHandler::Ignore => libc::SIG_IGN,
SignalHandler::Default => libc::SIG_DFL,
};
- assert_eq!(prev, expected);
+ assert_eq!(prev, expected, "expected sigpipe value matches actual value");
// Unlikely to matter, but restore the old value anyway
- unsafe { libc::signal(libc::SIGPIPE, prev); };
+ unsafe {
+ libc::signal(libc::SIGPIPE, prev);
+ };
}
}
diff --git a/src/test/ui/auto-traits/suspicious-impls-lint.stderr b/src/test/ui/auto-traits/suspicious-impls-lint.stderr
index 97b2d7221..9cd4e79f8 100644
--- a/src/test/ui/auto-traits/suspicious-impls-lint.stderr
+++ b/src/test/ui/auto-traits/suspicious-impls-lint.stderr
@@ -4,11 +4,6 @@ error: cross-crate traits with a default impl, like `Send`, should not be specia
LL | unsafe impl<T: Send> Send for MayImplementSendErr<&T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the lint level is defined here
- --> $DIR/suspicious-impls-lint.rs:1:9
- |
-LL | #![deny(suspicious_auto_trait_impls)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= warning: this will change its meaning in a future release!
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
= note: `&T` is not a generic parameter
@@ -17,6 +12,11 @@ note: try using the same sequence of generic parameters as the struct definition
|
LL | struct MayImplementSendErr<T>(T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+note: the lint level is defined here
+ --> $DIR/suspicious-impls-lint.rs:1:9
+ |
+LL | #![deny(suspicious_auto_trait_impls)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: cross-crate traits with a default impl, like `Send`, should not be specialized
--> $DIR/suspicious-impls-lint.rs:21:1
diff --git a/src/test/ui/auxiliary/attr-from-macro.rs b/src/test/ui/auxiliary/attr-from-macro.rs
new file mode 100644
index 000000000..9b388675c
--- /dev/null
+++ b/src/test/ui/auxiliary/attr-from-macro.rs
@@ -0,0 +1,15 @@
+#[macro_export]
+macro_rules! creator {
+ (struct $name1:ident; enum $name2:ident; enum $name3:ident;) => {
+ #[derive(Debug)]
+ pub struct $name1;
+
+ #[derive(Debug)]
+ #[repr(u32)]
+ pub enum $name2 { A }
+
+ #[derive(Debug)]
+ #[repr(u16)]
+ pub enum $name3 { A }
+ }
+}
diff --git a/src/test/ui/backtrace.rs b/src/test/ui/backtrace.rs
index e2ac43fff..dd73dd988 100644
--- a/src/test/ui/backtrace.rs
+++ b/src/test/ui/backtrace.rs
@@ -4,6 +4,7 @@
// ignore-openbsd no support for libbacktrace without filename
// ignore-sgx no processes
// ignore-msvc see #62897 and `backtrace-debuginfo.rs` test
+// ignore-fuchsia Backtraces not symbolized
// compile-flags:-g
// compile-flags:-Cstrip=none
diff --git a/src/test/ui/binding/fn-arg-incomplete-pattern-drop-order.rs b/src/test/ui/binding/fn-arg-incomplete-pattern-drop-order.rs
index 684172ca6..0450fe8ab 100644
--- a/src/test/ui/binding/fn-arg-incomplete-pattern-drop-order.rs
+++ b/src/test/ui/binding/fn-arg-incomplete-pattern-drop-order.rs
@@ -3,7 +3,6 @@
// Check that partially moved from function parameters are dropped after the
// named bindings that move from them.
-// ignore-wasm32-bare compiled with panic=abort by default
use std::{panic, cell::RefCell};
diff --git a/src/test/ui/binding/issue-53114-safety-checks.stderr b/src/test/ui/binding/issue-53114-safety-checks.stderr
index f3840273c..57a065d6d 100644
--- a/src/test/ui/binding/issue-53114-safety-checks.stderr
+++ b/src/test/ui/binding/issue-53114-safety-checks.stderr
@@ -4,11 +4,11 @@ error: reference to packed field is unaligned
LL | let _ = &p.b;
| ^^^^
|
- = note: `#[deny(unaligned_references)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
+ = note: `#[deny(unaligned_references)]` on by default
error: reference to packed field is unaligned
--> $DIR/issue-53114-safety-checks.rs:29:17
@@ -109,11 +109,11 @@ error: reference to packed field is unaligned
LL | let _ = &p.b;
| ^^^^
|
- = note: `#[deny(unaligned_references)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
+ = note: `#[deny(unaligned_references)]` on by default
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -122,11 +122,11 @@ error: reference to packed field is unaligned
LL | let (_,) = (&p.b,);
| ^^^^
|
- = note: `#[deny(unaligned_references)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
+ = note: `#[deny(unaligned_references)]` on by default
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -135,11 +135,11 @@ error: reference to packed field is unaligned
LL | match &p.b { _ => { } }
| ^^^^
|
- = note: `#[deny(unaligned_references)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
+ = note: `#[deny(unaligned_references)]` on by default
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -148,9 +148,9 @@ error: reference to packed field is unaligned
LL | match (&p.b,) { (_,) => { } }
| ^^^^
|
- = note: `#[deny(unaligned_references)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
+ = note: `#[deny(unaligned_references)]` on by default
diff --git a/src/test/ui/binop/issue-77910-1.rs b/src/test/ui/binop/issue-77910-1.rs
index d786e3358..95bbd6a60 100644
--- a/src/test/ui/binop/issue-77910-1.rs
+++ b/src/test/ui/binop/issue-77910-1.rs
@@ -7,5 +7,5 @@ fn main() {
// we shouldn't ice with the bound var here.
assert_eq!(foo, y);
//~^ ERROR binary operation `==` cannot be applied to type
- //~| ERROR `for<'r> fn(&'r i32) -> &'r i32 {foo}` doesn't implement `Debug`
+ //~| ERROR `for<'a> fn(&'a i32) -> &'a i32 {foo}` doesn't implement `Debug`
}
diff --git a/src/test/ui/binop/issue-77910-1.stderr b/src/test/ui/binop/issue-77910-1.stderr
index 097a14f26..263a35d98 100644
--- a/src/test/ui/binop/issue-77910-1.stderr
+++ b/src/test/ui/binop/issue-77910-1.stderr
@@ -1,25 +1,25 @@
-error[E0369]: binary operation `==` cannot be applied to type `for<'r> fn(&'r i32) -> &'r i32 {foo}`
+error[E0369]: binary operation `==` cannot be applied to type `for<'a> fn(&'a i32) -> &'a i32 {foo}`
--> $DIR/issue-77910-1.rs:8:5
|
LL | assert_eq!(foo, y);
| ^^^^^^^^^^^^^^^^^^
| |
- | for<'r> fn(&'r i32) -> &'r i32 {foo}
+ | for<'a> fn(&'a i32) -> &'a i32 {foo}
| _
|
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
-error[E0277]: `for<'r> fn(&'r i32) -> &'r i32 {foo}` doesn't implement `Debug`
+error[E0277]: `for<'a> fn(&'a i32) -> &'a i32 {foo}` doesn't implement `Debug`
--> $DIR/issue-77910-1.rs:8:5
|
LL | fn foo(s: &i32) -> &i32 {
| --- consider calling this function
...
LL | assert_eq!(foo, y);
- | ^^^^^^^^^^^^^^^^^^ `for<'r> fn(&'r i32) -> &'r i32 {foo}` cannot be formatted using `{:?}` because it doesn't implement `Debug`
+ | ^^^^^^^^^^^^^^^^^^ `for<'a> fn(&'a i32) -> &'a i32 {foo}` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
- = help: the trait `Debug` is not implemented for fn item `for<'r> fn(&'r i32) -> &'r i32 {foo}`
- = help: use parentheses to call the function: `foo(s)`
+ = help: the trait `Debug` is not implemented for fn item `for<'a> fn(&'a i32) -> &'a i32 {foo}`
+ = help: use parentheses to call this function: `foo(/* &i32 */)`
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors
diff --git a/src/test/ui/binop/issue-77910-2.stderr b/src/test/ui/binop/issue-77910-2.stderr
index a334bd856..b3856b6ae 100644
--- a/src/test/ui/binop/issue-77910-2.stderr
+++ b/src/test/ui/binop/issue-77910-2.stderr
@@ -1,10 +1,10 @@
-error[E0369]: binary operation `==` cannot be applied to type `for<'r> fn(&'r i32) -> &'r i32 {foo}`
+error[E0369]: binary operation `==` cannot be applied to type `for<'a> fn(&'a i32) -> &'a i32 {foo}`
--> $DIR/issue-77910-2.rs:7:12
|
LL | if foo == y {}
| --- ^^ - _
| |
- | for<'r> fn(&'r i32) -> &'r i32 {foo}
+ | for<'a> fn(&'a i32) -> &'a i32 {foo}
|
help: use parentheses to call this function
|
diff --git a/src/test/ui/block-result/consider-removing-last-semi.stderr b/src/test/ui/block-result/consider-removing-last-semi.stderr
index 2412dcd32..9be0367ae 100644
--- a/src/test/ui/block-result/consider-removing-last-semi.stderr
+++ b/src/test/ui/block-result/consider-removing-last-semi.stderr
@@ -7,7 +7,7 @@ LL | pub fn f() -> String {
| implicitly returns `()` as its body has no tail or `return` expression
LL | 0u8;
LL | "bla".to_string();
- | - help: remove this semicolon
+ | - help: remove this semicolon to return this value
error[E0308]: mismatched types
--> $DIR/consider-removing-last-semi.rs:8:15
@@ -18,7 +18,7 @@ LL | pub fn g() -> String {
| implicitly returns `()` as its body has no tail or `return` expression
LL | "this won't work".to_string();
LL | "removeme".to_string();
- | - help: remove this semicolon
+ | - help: remove this semicolon to return this value
error[E0308]: mismatched types
--> $DIR/consider-removing-last-semi.rs:13:25
@@ -29,7 +29,7 @@ LL | pub fn macro_tests() -> u32 {
| implicitly returns `()` as its body has no tail or `return` expression
...
LL | mac!();
- | - help: remove this semicolon
+ | - help: remove this semicolon to return this value
error: aborting due to 3 previous errors
diff --git a/src/test/ui/block-result/issue-11714.stderr b/src/test/ui/block-result/issue-11714.stderr
index 5b8d96fd4..42fb3d3d4 100644
--- a/src/test/ui/block-result/issue-11714.stderr
+++ b/src/test/ui/block-result/issue-11714.stderr
@@ -7,7 +7,7 @@ LL | fn blah() -> i32 {
| implicitly returns `()` as its body has no tail or `return` expression
...
LL | ;
- | - help: remove this semicolon
+ | - help: remove this semicolon to return this value
error: aborting due to previous error
diff --git a/src/test/ui/block-result/issue-13428.stderr b/src/test/ui/block-result/issue-13428.stderr
index a33448edf..2b386d10c 100644
--- a/src/test/ui/block-result/issue-13428.stderr
+++ b/src/test/ui/block-result/issue-13428.stderr
@@ -15,7 +15,7 @@ LL | fn bar() -> String {
| implicitly returns `()` as its body has no tail or `return` expression
LL | "foobar".to_string()
LL | ;
- | - help: remove this semicolon
+ | - help: remove this semicolon to return this value
error: aborting due to 2 previous errors
diff --git a/src/test/ui/borrowck/anonymous-region-in-apit.rs b/src/test/ui/borrowck/anonymous-region-in-apit.rs
new file mode 100644
index 000000000..7799a7cb1
--- /dev/null
+++ b/src/test/ui/borrowck/anonymous-region-in-apit.rs
@@ -0,0 +1,12 @@
+#![feature(anonymous_lifetime_in_impl_trait)]
+
+trait Foo<T> {
+ fn bar(self, baz: T);
+}
+
+fn qux(foo: impl Foo<&str>) {
+ |baz: &str| foo.bar(baz);
+ //~^ ERROR borrowed data escapes outside of closure
+}
+
+fn main() {}
diff --git a/src/test/ui/borrowck/anonymous-region-in-apit.stderr b/src/test/ui/borrowck/anonymous-region-in-apit.stderr
new file mode 100644
index 000000000..9e100f8ac
--- /dev/null
+++ b/src/test/ui/borrowck/anonymous-region-in-apit.stderr
@@ -0,0 +1,16 @@
+error[E0521]: borrowed data escapes outside of closure
+ --> $DIR/anonymous-region-in-apit.rs:8:17
+ |
+LL | fn qux(foo: impl Foo<&str>) {
+ | --- lifetime `'2` appears in the type of `foo`
+LL | |baz: &str| foo.bar(baz);
+ | --- - ^^^^^^^^^^^^
+ | | | |
+ | | | `baz` escapes the closure body here
+ | | | argument requires that `'1` must outlive `'2`
+ | | let's call the lifetime of this reference `'1`
+ | `baz` is a reference that is only valid in the closure body
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0521`.
diff --git a/src/test/ui/borrowck/borrowck-block-unint.stderr b/src/test/ui/borrowck/borrowck-block-unint.stderr
index e720db1c6..f47921a97 100644
--- a/src/test/ui/borrowck/borrowck-block-unint.stderr
+++ b/src/test/ui/borrowck/borrowck-block-unint.stderr
@@ -7,6 +7,11 @@ LL | force(|| {
| ^^ `x` used here but it isn't initialized
LL | println!("{}", x);
| - borrow occurs due to use in closure
+ |
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-break-uninit-2.stderr b/src/test/ui/borrowck/borrowck-break-uninit-2.stderr
index 91038b3ad..ea93a8f40 100644
--- a/src/test/ui/borrowck/borrowck-break-uninit-2.stderr
+++ b/src/test/ui/borrowck/borrowck-break-uninit-2.stderr
@@ -8,6 +8,10 @@ LL | println!("{}", x);
| ^ `x` used here but it isn't initialized
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-break-uninit.stderr b/src/test/ui/borrowck/borrowck-break-uninit.stderr
index 8d0c9582f..a7a8fc2ff 100644
--- a/src/test/ui/borrowck/borrowck-break-uninit.stderr
+++ b/src/test/ui/borrowck/borrowck-break-uninit.stderr
@@ -8,6 +8,10 @@ LL | println!("{}", x);
| ^ `x` used here but it isn't initialized
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr b/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr
index e8a2fbc91..1a22b5f09 100644
--- a/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr
+++ b/src/test/ui/borrowck/borrowck-init-in-called-fn-expr.stderr
@@ -5,6 +5,11 @@ LL | let i: isize;
| - binding declared here but left uninitialized
LL | i
| ^ `i` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let i: isize = 0;
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr b/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr
index 1e950d6a2..f1b9b9aa7 100644
--- a/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr
+++ b/src/test/ui/borrowck/borrowck-init-in-fn-expr.stderr
@@ -5,6 +5,11 @@ LL | let i: isize;
| - binding declared here but left uninitialized
LL | i
| ^ `i` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let i: isize = 0;
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-init-in-fru.stderr b/src/test/ui/borrowck/borrowck-init-in-fru.stderr
index 83a3e3e0e..39b28811a 100644
--- a/src/test/ui/borrowck/borrowck-init-in-fru.stderr
+++ b/src/test/ui/borrowck/borrowck-init-in-fru.stderr
@@ -5,6 +5,11 @@ LL | let mut origin: Point;
| ---------- binding declared here but left uninitialized
LL | origin = Point { x: 10, ..origin };
| ^^^^^^^^^^^^^^^^^^^^^^^^^ `origin.y` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let mut origin: Point = todo!();
+ | +++++++++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-init-op-equal.stderr b/src/test/ui/borrowck/borrowck-init-op-equal.stderr
index 74704b2ab..ef0fa6df4 100644
--- a/src/test/ui/borrowck/borrowck-init-op-equal.stderr
+++ b/src/test/ui/borrowck/borrowck-init-op-equal.stderr
@@ -5,6 +5,11 @@ LL | let v: isize;
| - binding declared here but left uninitialized
LL | v += 1;
| ^^^^^^ `v` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let v: isize = 0;
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-init-plus-equal.stderr b/src/test/ui/borrowck/borrowck-init-plus-equal.stderr
index 7542576d6..cec053318 100644
--- a/src/test/ui/borrowck/borrowck-init-plus-equal.stderr
+++ b/src/test/ui/borrowck/borrowck-init-plus-equal.stderr
@@ -5,6 +5,11 @@ LL | let mut v: isize;
| ----- binding declared here but left uninitialized
LL | v = v + 1;
| ^ `v` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let mut v: isize = 0;
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-mut-borrow-linear-errors.stderr b/src/test/ui/borrowck/borrowck-mut-borrow-linear-errors.stderr
index 15ac73760..d2b845619 100644
--- a/src/test/ui/borrowck/borrowck-mut-borrow-linear-errors.stderr
+++ b/src/test/ui/borrowck/borrowck-mut-borrow-linear-errors.stderr
@@ -25,7 +25,10 @@ error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-mut-borrow-linear-errors.rs:12:30
|
LL | _ => { addr.push(&mut x); }
- | ^^^^^^ `x` was mutably borrowed here in the previous iteration of the loop
+ | ----------^^^^^^-
+ | | |
+ | | `x` was mutably borrowed here in the previous iteration of the loop
+ | first borrow used here, in later iteration of loop
error: aborting due to 3 previous errors
diff --git a/src/test/ui/borrowck/borrowck-return.stderr b/src/test/ui/borrowck/borrowck-return.stderr
index 1c916e223..9799357c9 100644
--- a/src/test/ui/borrowck/borrowck-return.stderr
+++ b/src/test/ui/borrowck/borrowck-return.stderr
@@ -5,6 +5,11 @@ LL | let x: isize;
| - binding declared here but left uninitialized
LL | return x;
| ^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-storage-dead.stderr b/src/test/ui/borrowck/borrowck-storage-dead.stderr
index 2cea4392d..3a413153a 100644
--- a/src/test/ui/borrowck/borrowck-storage-dead.stderr
+++ b/src/test/ui/borrowck/borrowck-storage-dead.stderr
@@ -5,6 +5,11 @@ LL | let x: i32;
| - binding declared here but left uninitialized
LL | let _ = x + 1;
| ^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: i32 = 0;
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-uninit-after-item.stderr b/src/test/ui/borrowck/borrowck-uninit-after-item.stderr
index 588b1b0c9..071598b42 100644
--- a/src/test/ui/borrowck/borrowck-uninit-after-item.stderr
+++ b/src/test/ui/borrowck/borrowck-uninit-after-item.stderr
@@ -6,6 +6,11 @@ LL | let bar;
LL | fn baz(_x: isize) { }
LL | baz(bar);
| ^^^ `bar` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let bar = 0;
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-uninit-field-access.stderr b/src/test/ui/borrowck/borrowck-uninit-field-access.stderr
index 6a38a7989..f0f4ad704 100644
--- a/src/test/ui/borrowck/borrowck-uninit-field-access.stderr
+++ b/src/test/ui/borrowck/borrowck-uninit-field-access.stderr
@@ -5,6 +5,11 @@ LL | let mut a: Point;
| ----- binding declared here but left uninitialized
LL | let _ = a.x + 1;
| ^^^ `a.x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let mut a: Point = Default::default();
+ | ++++++++++++++++++++
error[E0382]: use of moved value: `line1.origin`
--> $DIR/borrowck-uninit-field-access.rs:25:13
diff --git a/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr b/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr
index 744cb14e6..fdbb451bd 100644
--- a/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr
+++ b/src/test/ui/borrowck/borrowck-uninit-in-assignop.stderr
@@ -5,6 +5,11 @@ LL | let x: isize;
| - binding declared here but left uninitialized
LL | x += 1;
| ^^^^^^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:9:5
@@ -13,6 +18,11 @@ LL | let x: isize;
| - binding declared here but left uninitialized
LL | x -= 1;
| ^^^^^^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:12:5
@@ -21,6 +31,11 @@ LL | let x: isize;
| - binding declared here but left uninitialized
LL | x *= 1;
| ^^^^^^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:15:5
@@ -29,6 +44,11 @@ LL | let x: isize;
| - binding declared here but left uninitialized
LL | x /= 1;
| ^^^^^^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:18:5
@@ -37,6 +57,11 @@ LL | let x: isize;
| - binding declared here but left uninitialized
LL | x %= 1;
| ^^^^^^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:21:5
@@ -45,6 +70,11 @@ LL | let x: isize;
| - binding declared here but left uninitialized
LL | x ^= 1;
| ^^^^^^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:24:5
@@ -53,6 +83,11 @@ LL | let x: isize;
| - binding declared here but left uninitialized
LL | x &= 1;
| ^^^^^^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:27:5
@@ -61,6 +96,11 @@ LL | let x: isize;
| - binding declared here but left uninitialized
LL | x |= 1;
| ^^^^^^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:30:5
@@ -69,6 +109,11 @@ LL | let x: isize;
| - binding declared here but left uninitialized
LL | x <<= 1;
| ^^^^^^^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-in-assignop.rs:33:5
@@ -77,6 +122,11 @@ LL | let x: isize;
| - binding declared here but left uninitialized
LL | x >>= 1;
| ^^^^^^^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error: aborting due to 10 previous errors
diff --git a/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr b/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr
index c486cb6dd..73fded754 100644
--- a/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr
+++ b/src/test/ui/borrowck/borrowck-uninit-ref-chain.stderr
@@ -5,6 +5,11 @@ LL | let x: &&Box<i32>;
| - binding declared here but left uninitialized
LL | let _y = &**x;
| ^^^^ `**x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: &&Box<i32> = todo!();
+ | +++++++++
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-ref-chain.rs:11:14
@@ -13,6 +18,11 @@ LL | let x: &&S<i32, i32>;
| - binding declared here but left uninitialized
LL | let _y = &**x;
| ^^^^ `**x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: &&S<i32, i32> = todo!();
+ | +++++++++
error[E0381]: used binding `x` isn't initialized
--> $DIR/borrowck-uninit-ref-chain.rs:14:14
@@ -21,6 +31,11 @@ LL | let x: &&i32;
| - binding declared here but left uninitialized
LL | let _y = &**x;
| ^^^^ `**x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: &&i32 = todo!();
+ | +++++++++
error[E0381]: partially assigned binding `a` isn't fully initialized
--> $DIR/borrowck-uninit-ref-chain.rs:18:5
diff --git a/src/test/ui/borrowck/borrowck-uninit.stderr b/src/test/ui/borrowck/borrowck-uninit.stderr
index d5566691a..eeafc4ce1 100644
--- a/src/test/ui/borrowck/borrowck-uninit.stderr
+++ b/src/test/ui/borrowck/borrowck-uninit.stderr
@@ -5,6 +5,11 @@ LL | let x: isize;
| - binding declared here but left uninitialized
LL | foo(x);
| ^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: isize = 0;
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr b/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr
index 459cf1398..18e808f10 100644
--- a/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr
+++ b/src/test/ui/borrowck/borrowck-use-in-index-lvalue.stderr
@@ -5,6 +5,11 @@ LL | let w: &mut [isize];
| - binding declared here but left uninitialized
LL | w[5] = 0;
| ^^^^ `*w` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let w: &mut [isize] = todo!();
+ | +++++++++
error[E0381]: used binding `w` isn't initialized
--> $DIR/borrowck-use-in-index-lvalue.rs:6:5
@@ -13,6 +18,11 @@ LL | let mut w: &mut [isize];
| ----- binding declared here but left uninitialized
LL | w[5] = 0;
| ^^^^ `*w` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let mut w: &mut [isize] = todo!();
+ | +++++++++
error: aborting due to 2 previous errors
diff --git a/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast-trait.stderr b/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast-trait.stderr
index 942ed4fc6..55f3ff553 100644
--- a/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast-trait.stderr
+++ b/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast-trait.stderr
@@ -5,6 +5,11 @@ LL | let x: &i32;
| - binding declared here but left uninitialized
LL | let y = x as *const dyn Foo;
| ^ `*x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: &i32 = todo!();
+ | +++++++++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr b/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr
index f3289e239..ea3d0d3ef 100644
--- a/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr
+++ b/src/test/ui/borrowck/borrowck-use-uninitialized-in-cast.stderr
@@ -5,6 +5,11 @@ LL | let x: &i32;
| - binding declared here but left uninitialized
LL | let y = x as *const i32;
| ^ `*x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: &i32 = todo!();
+ | +++++++++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/borrowck-while-cond.stderr b/src/test/ui/borrowck/borrowck-while-cond.stderr
index e41c1c55e..5d0194989 100644
--- a/src/test/ui/borrowck/borrowck-while-cond.stderr
+++ b/src/test/ui/borrowck/borrowck-while-cond.stderr
@@ -5,6 +5,11 @@ LL | let x: bool;
| - binding declared here but left uninitialized
LL | while x { }
| ^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: bool = false;
+ | +++++++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/issue-102209.rs b/src/test/ui/borrowck/issue-102209.rs
new file mode 100644
index 000000000..37628bff7
--- /dev/null
+++ b/src/test/ui/borrowck/issue-102209.rs
@@ -0,0 +1,28 @@
+use std::marker::PhantomData;
+
+pub struct NfaBuilder<'brand> {
+ brand: PhantomData<&'brand mut &'brand mut ()>,
+}
+
+impl NfaBuilder<'_> {
+ pub fn with<R, F: FnOnce(NfaBuilder<'_>) -> R>(f: F) -> R {
+ Brand::with(|brand| {
+ f(Self { brand: brand.lt })
+ //~^ ERROR lifetime may not live long enough
+ //~| ERROR lifetime may not live long enough
+ })
+ }
+}
+
+#[derive(Clone, Copy)]
+pub struct Brand<'brand> {
+ lt: PhantomData<&'brand mut &'brand mut ()>,
+}
+
+impl Brand<'_> {
+ pub fn with<R, F: FnOnce(Brand<'_>) -> R>(f: F) -> R {
+ f(Self { lt: PhantomData })
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/borrowck/issue-102209.stderr b/src/test/ui/borrowck/issue-102209.stderr
new file mode 100644
index 000000000..351de8217
--- /dev/null
+++ b/src/test/ui/borrowck/issue-102209.stderr
@@ -0,0 +1,22 @@
+error: lifetime may not live long enough
+ --> $DIR/issue-102209.rs:10:29
+ |
+LL | impl NfaBuilder<'_> {
+ | -- lifetime `'2` appears in the `impl`'s self type
+LL | pub fn with<R, F: FnOnce(NfaBuilder<'_>) -> R>(f: F) -> R {
+LL | Brand::with(|brand| {
+ | ----- has type `Brand<'1>`
+LL | f(Self { brand: brand.lt })
+ | ^^^^^^^^ this usage requires that `'1` must outlive `'2`
+
+error: lifetime may not live long enough
+ --> $DIR/issue-102209.rs:10:29
+ |
+LL | impl NfaBuilder<'_> {
+ | -- lifetime `'1` appears in the `impl`'s self type
+...
+LL | f(Self { brand: brand.lt })
+ | ^^^^^^^^ this usage requires that `'1` must outlive `'static`
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/borrowck/issue-103250.rs b/src/test/ui/borrowck/issue-103250.rs
new file mode 100644
index 000000000..46565f61c
--- /dev/null
+++ b/src/test/ui/borrowck/issue-103250.rs
@@ -0,0 +1,37 @@
+// edition:2021
+
+type TranslateFn = Box<dyn Fn(String, String) -> String>;
+
+pub struct DeviceCluster {
+ devices: Vec<Device>,
+}
+
+impl DeviceCluster {
+ pub async fn do_something(&mut self) -> Result<String, Box<dyn std::error::Error>> {
+ let mut last_error: Box<dyn std::error::Error>;
+
+ for device in &mut self.devices {
+ match device.do_something().await {
+ Ok(info) => {
+ return Ok(info);
+ }
+ Err(e) => {}
+ }
+ }
+
+ Err(last_error)
+ //~^ ERROR used binding `last_error` isn't initialized
+ }
+}
+
+pub struct Device {
+ translate_fn: Option<TranslateFn>,
+}
+
+impl Device {
+ pub async fn do_something(&mut self) -> Result<String, Box<dyn std::error::Error>> {
+ Ok(String::from(""))
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/borrowck/issue-103250.stderr b/src/test/ui/borrowck/issue-103250.stderr
new file mode 100644
index 000000000..4a2378352
--- /dev/null
+++ b/src/test/ui/borrowck/issue-103250.stderr
@@ -0,0 +1,17 @@
+error[E0381]: used binding `last_error` isn't initialized
+ --> $DIR/issue-103250.rs:22:13
+ |
+LL | let mut last_error: Box<dyn std::error::Error>;
+ | -------------- binding declared here but left uninitialized
+...
+LL | Err(last_error)
+ | ^^^^^^^^^^ `last_error` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let mut last_error: Box<dyn std::error::Error> = todo!();
+ | +++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0381`.
diff --git a/src/test/ui/borrowck/issue-103624.rs b/src/test/ui/borrowck/issue-103624.rs
new file mode 100644
index 000000000..f1fa95f92
--- /dev/null
+++ b/src/test/ui/borrowck/issue-103624.rs
@@ -0,0 +1,31 @@
+// edition:2021
+
+struct StructA {
+ b: StructB,
+}
+
+async fn spawn_blocking<T>(f: impl (Fn() -> T) + Send + Sync + 'static) -> T {
+ todo!()
+}
+
+impl StructA {
+ async fn foo(&self) {
+ let bar = self.b.bar().await;
+ spawn_blocking(move || {
+ //~^ ERROR borrowed data escapes outside of associated function
+ self.b;
+ //~^ ERROR cannot move out of `self.b`, as `self` is a captured variable in an `Fn` closure
+ })
+ .await;
+ }
+}
+
+struct StructB {}
+
+impl StructB {
+ async fn bar(&self) -> Option<u8> {
+ None
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/borrowck/issue-103624.stderr b/src/test/ui/borrowck/issue-103624.stderr
new file mode 100644
index 000000000..e6a35dd88
--- /dev/null
+++ b/src/test/ui/borrowck/issue-103624.stderr
@@ -0,0 +1,35 @@
+error[E0507]: cannot move out of `self.b`, as `self` is a captured variable in an `Fn` closure
+ --> $DIR/issue-103624.rs:16:13
+ |
+LL | async fn foo(&self) {
+ | ----- captured outer variable
+LL | let bar = self.b.bar().await;
+LL | spawn_blocking(move || {
+ | ------- captured by this `Fn` closure
+LL |
+LL | self.b;
+ | ^^^^^^ move occurs because `self.b` has type `StructB`, which does not implement the `Copy` trait
+
+error[E0521]: borrowed data escapes outside of associated function
+ --> $DIR/issue-103624.rs:14:9
+ |
+LL | async fn foo(&self) {
+ | -----
+ | |
+ | `self` is a reference that is only valid in the associated function body
+ | let's call the lifetime of this reference `'1`
+LL | let bar = self.b.bar().await;
+LL | / spawn_blocking(move || {
+LL | |
+LL | | self.b;
+LL | |
+LL | | })
+ | | ^
+ | | |
+ | |__________`self` escapes the associated function body here
+ | argument requires that `'1` must outlive `'static`
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0507, E0521.
+For more information about an error, try `rustc --explain E0507`.
diff --git a/src/test/ui/issues/issue-17718-static-move.rs b/src/test/ui/borrowck/issue-17718-static-move.rs
index 015487a06..015487a06 100644
--- a/src/test/ui/issues/issue-17718-static-move.rs
+++ b/src/test/ui/borrowck/issue-17718-static-move.rs
diff --git a/src/test/ui/issues/issue-17718-static-move.stderr b/src/test/ui/borrowck/issue-17718-static-move.stderr
index 984534bfb..984534bfb 100644
--- a/src/test/ui/issues/issue-17718-static-move.stderr
+++ b/src/test/ui/borrowck/issue-17718-static-move.stderr
diff --git a/src/test/ui/issues/issue-23338-params-outlive-temps-of-body.rs b/src/test/ui/borrowck/issue-23338-params-outlive-temps-of-body.rs
index d45aaa843..d45aaa843 100644
--- a/src/test/ui/issues/issue-23338-params-outlive-temps-of-body.rs
+++ b/src/test/ui/borrowck/issue-23338-params-outlive-temps-of-body.rs
diff --git a/src/test/ui/borrowck/issue-24267-flow-exit.stderr b/src/test/ui/borrowck/issue-24267-flow-exit.stderr
index b85e8f216..58d1c8c0f 100644
--- a/src/test/ui/borrowck/issue-24267-flow-exit.stderr
+++ b/src/test/ui/borrowck/issue-24267-flow-exit.stderr
@@ -8,6 +8,10 @@ LL | println!("{}", x);
| ^ `x` used here but it isn't initialized
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let x: i32 = 0;
+ | +++
error[E0381]: used binding `x` isn't initialized
--> $DIR/issue-24267-flow-exit.rs:18:20
@@ -19,6 +23,10 @@ LL | println!("{}", x);
| ^ `x` used here but it isn't initialized
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let x: i32 = 0;
+ | +++
error: aborting due to 2 previous errors
diff --git a/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr b/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr
index f5d2eecfa..9683da919 100644
--- a/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr
+++ b/src/test/ui/borrowck/issue-62107-match-arm-scopes.stderr
@@ -5,6 +5,11 @@ LL | let e: i32;
| - binding declared here but left uninitialized
LL | match e {
| ^ `e` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let e: i32 = 0;
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/borrowck/issue-81899.rs b/src/test/ui/borrowck/issue-81899.rs
index 9b6061203..24b20b650 100644
--- a/src/test/ui/borrowck/issue-81899.rs
+++ b/src/test/ui/borrowck/issue-81899.rs
@@ -2,8 +2,7 @@
// The `panic!()` below is important to trigger the fixed ICE.
const _CONST: &[u8] = &f(&[], |_| {});
-//~^ ERROR any use of this value
-//~| WARNING this was previously
+//~^ ERROR constant
const fn f<F>(_: &[u8], _: F) -> &[u8]
where
diff --git a/src/test/ui/borrowck/issue-81899.stderr b/src/test/ui/borrowck/issue-81899.stderr
index fd591c7b5..12e80b9df 100644
--- a/src/test/ui/borrowck/issue-81899.stderr
+++ b/src/test/ui/borrowck/issue-81899.stderr
@@ -1,5 +1,5 @@
error[E0080]: evaluation of constant value failed
- --> $DIR/issue-81899.rs:12:5
+ --> $DIR/issue-81899.rs:11:5
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
| -------------- inside `_CONST` at $DIR/issue-81899.rs:4:24
@@ -7,32 +7,17 @@ LL | const _CONST: &[u8] = &f(&[], |_| {});
LL | panic!()
| ^^^^^^^^
| |
- | the evaluated program panicked at 'explicit panic', $DIR/issue-81899.rs:12:5
+ | the evaluated program panicked at 'explicit panic', $DIR/issue-81899.rs:11:5
| inside `f::<[closure@$DIR/issue-81899.rs:4:31: 4:34]>` at $SRC_DIR/std/src/panic.rs:LL:COL
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/issue-81899.rs:4:23
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
- | ------------------- ^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^ referenced constant has errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/issue-81899.rs:4:23
- |
-LL | const _CONST: &[u8] = &f(&[], |_| {});
- | ------------------- ^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/borrowck/issue-88434-minimal-example.rs b/src/test/ui/borrowck/issue-88434-minimal-example.rs
index 7618d001e..983a02310 100644
--- a/src/test/ui/borrowck/issue-88434-minimal-example.rs
+++ b/src/test/ui/borrowck/issue-88434-minimal-example.rs
@@ -1,8 +1,7 @@
// Regression test related to issue 88434
const _CONST: &() = &f(&|_| {});
-//~^ ERROR any use of this value
-//~| WARNING this was previously
+//~^ ERROR constant
const fn f<F>(_: &F)
where
diff --git a/src/test/ui/borrowck/issue-88434-minimal-example.stderr b/src/test/ui/borrowck/issue-88434-minimal-example.stderr
index a3582e780..dc87c4c2b 100644
--- a/src/test/ui/borrowck/issue-88434-minimal-example.stderr
+++ b/src/test/ui/borrowck/issue-88434-minimal-example.stderr
@@ -1,5 +1,5 @@
error[E0080]: evaluation of constant value failed
- --> $DIR/issue-88434-minimal-example.rs:11:5
+ --> $DIR/issue-88434-minimal-example.rs:10:5
|
LL | const _CONST: &() = &f(&|_| {});
| ---------- inside `_CONST` at $DIR/issue-88434-minimal-example.rs:3:22
@@ -7,32 +7,17 @@ LL | const _CONST: &() = &f(&|_| {});
LL | panic!()
| ^^^^^^^^
| |
- | the evaluated program panicked at 'explicit panic', $DIR/issue-88434-minimal-example.rs:11:5
+ | the evaluated program panicked at 'explicit panic', $DIR/issue-88434-minimal-example.rs:10:5
| inside `f::<[closure@$DIR/issue-88434-minimal-example.rs:3:25: 3:28]>` at $SRC_DIR/std/src/panic.rs:LL:COL
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/issue-88434-minimal-example.rs:3:21
|
LL | const _CONST: &() = &f(&|_| {});
- | ----------------- ^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^ referenced constant has errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/issue-88434-minimal-example.rs:3:21
- |
-LL | const _CONST: &() = &f(&|_| {});
- | ----------------- ^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs b/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs
index b1fc1615e..a99c5b76a 100644
--- a/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs
+++ b/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.rs
@@ -1,8 +1,7 @@
// Regression test for issue 88434
const _CONST: &[u8] = &f(&[], |_| {});
-//~^ ERROR any use of this value will cause an error
-//~| WARNING this was previously
+//~^ ERROR constant
const fn f<F>(_: &[u8], _: F) -> &[u8]
where
diff --git a/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr b/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr
index a6c65b302..4b4a25d7b 100644
--- a/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr
+++ b/src/test/ui/borrowck/issue-88434-removal-index-should-be-less.stderr
@@ -1,5 +1,5 @@
error[E0080]: evaluation of constant value failed
- --> $DIR/issue-88434-removal-index-should-be-less.rs:11:5
+ --> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
| -------------- inside `_CONST` at $DIR/issue-88434-removal-index-should-be-less.rs:3:24
@@ -7,32 +7,17 @@ LL | const _CONST: &[u8] = &f(&[], |_| {});
LL | panic!()
| ^^^^^^^^
| |
- | the evaluated program panicked at 'explicit panic', $DIR/issue-88434-removal-index-should-be-less.rs:11:5
+ | the evaluated program panicked at 'explicit panic', $DIR/issue-88434-removal-index-should-be-less.rs:10:5
| inside `f::<[closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34]>` at $SRC_DIR/std/src/panic.rs:LL:COL
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:23
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
- | ------------------- ^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^ referenced constant has errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/issue-88434-removal-index-should-be-less.rs:3:23
- |
-LL | const _CONST: &[u8] = &f(&[], |_| {});
- | ------------------- ^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/borrowck/reborrow-sugg-move-then-borrow.rs b/src/test/ui/borrowck/reborrow-sugg-move-then-borrow.rs
new file mode 100644
index 000000000..31eba0740
--- /dev/null
+++ b/src/test/ui/borrowck/reborrow-sugg-move-then-borrow.rs
@@ -0,0 +1,26 @@
+// Tests the suggestion to reborrow the first move site
+// when we move then borrow a `&mut` ref.
+
+struct State;
+
+impl IntoIterator for &mut State {
+ type IntoIter = std::vec::IntoIter<()>;
+ type Item = ();
+
+ fn into_iter(self) -> Self::IntoIter {
+ vec![].into_iter()
+ }
+}
+
+fn once(f: impl FnOnce()) {}
+
+fn fill_memory_blocks_mt(state: &mut State) {
+ for _ in state {}
+ //~^ HELP consider creating a fresh reborrow of `state` here
+ fill_segment(state);
+ //~^ ERROR borrow of moved value: `state`
+}
+
+fn fill_segment(state: &mut State) {}
+
+fn main() {}
diff --git a/src/test/ui/borrowck/reborrow-sugg-move-then-borrow.stderr b/src/test/ui/borrowck/reborrow-sugg-move-then-borrow.stderr
new file mode 100644
index 000000000..13a2005e2
--- /dev/null
+++ b/src/test/ui/borrowck/reborrow-sugg-move-then-borrow.stderr
@@ -0,0 +1,24 @@
+error[E0382]: borrow of moved value: `state`
+ --> $DIR/reborrow-sugg-move-then-borrow.rs:20:18
+ |
+LL | fn fill_memory_blocks_mt(state: &mut State) {
+ | ----- move occurs because `state` has type `&mut State`, which does not implement the `Copy` trait
+LL | for _ in state {}
+ | ----- `state` moved due to this implicit call to `.into_iter()`
+LL |
+LL | fill_segment(state);
+ | ^^^^^ value borrowed here after move
+ |
+note: this function takes ownership of the receiver `self`, which moves `state`
+ --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
+ |
+LL | fn into_iter(self) -> Self::IntoIter;
+ | ^^^^
+help: consider creating a fresh reborrow of `state` here
+ |
+LL | for _ in &mut *state {}
+ | ++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0382`.
diff --git a/src/test/ui/borrowck/suggest-assign-rvalue.rs b/src/test/ui/borrowck/suggest-assign-rvalue.rs
new file mode 100644
index 000000000..aaca9d47f
--- /dev/null
+++ b/src/test/ui/borrowck/suggest-assign-rvalue.rs
@@ -0,0 +1,57 @@
+#![allow(dead_code)]
+#![feature(never_type)]
+
+#[derive(Debug, Default)]
+struct Demo {}
+
+#[derive(Debug)]
+struct DemoNoDef {}
+
+fn apple(_: u32) {}
+
+fn banana() {
+ let chaenomeles;
+ apple(chaenomeles);
+ //~^ ERROR used binding `chaenomeles` isn't initialized [E0381]
+}
+
+fn main() {
+ let my_bool: bool = bool::default();
+ println!("my_bool: {}", my_bool);
+
+ let my_float: f32;
+ println!("my_float: {}", my_float);
+ //~^ ERROR used binding `my_float` isn't initialized
+ let demo: Demo;
+ println!("demo: {:?}", demo);
+ //~^ ERROR used binding `demo` isn't initialized
+
+ let demo_no: DemoNoDef;
+ println!("demo_no: {:?}", demo_no);
+ //~^ ERROR used binding `demo_no` isn't initialized
+
+ let arr: [i32; 5];
+ println!("arr: {:?}", arr);
+ //~^ ERROR used binding `arr` isn't initialized
+ let foo: Vec<&str>;
+ println!("foo: {:?}", foo);
+ //~^ ERROR used binding `foo` isn't initialized
+
+ let my_string: String;
+ println!("my_string: {}", my_string);
+ //~^ ERROR used binding `my_string` isn't initialized
+
+ let my_int: &i32;
+ println!("my_int: {}", *my_int);
+ //~^ ERROR used binding `my_int` isn't initialized
+
+ let hello: &str;
+ println!("hello: {}", hello);
+ //~^ ERROR used binding `hello` isn't initialized
+
+ let never: !;
+ println!("never: {}", never);
+ //~^ ERROR used binding `never` isn't initialized [E0381]
+
+ banana();
+}
diff --git a/src/test/ui/borrowck/suggest-assign-rvalue.stderr b/src/test/ui/borrowck/suggest-assign-rvalue.stderr
new file mode 100644
index 000000000..92acba640
--- /dev/null
+++ b/src/test/ui/borrowck/suggest-assign-rvalue.stderr
@@ -0,0 +1,138 @@
+error[E0381]: used binding `chaenomeles` isn't initialized
+ --> $DIR/suggest-assign-rvalue.rs:14:11
+ |
+LL | let chaenomeles;
+ | ----------- binding declared here but left uninitialized
+LL | apple(chaenomeles);
+ | ^^^^^^^^^^^ `chaenomeles` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let chaenomeles = 0;
+ | +++
+
+error[E0381]: used binding `my_float` isn't initialized
+ --> $DIR/suggest-assign-rvalue.rs:23:30
+ |
+LL | let my_float: f32;
+ | -------- binding declared here but left uninitialized
+LL | println!("my_float: {}", my_float);
+ | ^^^^^^^^ `my_float` used here but it isn't initialized
+ |
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let my_float: f32 = 0.0;
+ | +++++
+
+error[E0381]: used binding `demo` isn't initialized
+ --> $DIR/suggest-assign-rvalue.rs:26:28
+ |
+LL | let demo: Demo;
+ | ---- binding declared here but left uninitialized
+LL | println!("demo: {:?}", demo);
+ | ^^^^ `demo` used here but it isn't initialized
+ |
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let demo: Demo = Default::default();
+ | ++++++++++++++++++++
+
+error[E0381]: used binding `demo_no` isn't initialized
+ --> $DIR/suggest-assign-rvalue.rs:30:31
+ |
+LL | let demo_no: DemoNoDef;
+ | ------- binding declared here but left uninitialized
+LL | println!("demo_no: {:?}", demo_no);
+ | ^^^^^^^ `demo_no` used here but it isn't initialized
+ |
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let demo_no: DemoNoDef = todo!();
+ | +++++++++
+
+error[E0381]: used binding `arr` isn't initialized
+ --> $DIR/suggest-assign-rvalue.rs:34:27
+ |
+LL | let arr: [i32; 5];
+ | --- binding declared here but left uninitialized
+LL | println!("arr: {:?}", arr);
+ | ^^^ `arr` used here but it isn't initialized
+ |
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let arr: [i32; 5] = todo!();
+ | +++++++++
+
+error[E0381]: used binding `foo` isn't initialized
+ --> $DIR/suggest-assign-rvalue.rs:37:27
+ |
+LL | let foo: Vec<&str>;
+ | --- binding declared here but left uninitialized
+LL | println!("foo: {:?}", foo);
+ | ^^^ `foo` used here but it isn't initialized
+ |
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let foo: Vec<&str> = vec![];
+ | ++++++++
+
+error[E0381]: used binding `my_string` isn't initialized
+ --> $DIR/suggest-assign-rvalue.rs:41:31
+ |
+LL | let my_string: String;
+ | --------- binding declared here but left uninitialized
+LL | println!("my_string: {}", my_string);
+ | ^^^^^^^^^ `my_string` used here but it isn't initialized
+ |
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let my_string: String = Default::default();
+ | ++++++++++++++++++++
+
+error[E0381]: used binding `my_int` isn't initialized
+ --> $DIR/suggest-assign-rvalue.rs:45:28
+ |
+LL | let my_int: &i32;
+ | ------ binding declared here but left uninitialized
+LL | println!("my_int: {}", *my_int);
+ | ^^^^^^^ `*my_int` used here but it isn't initialized
+ |
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let my_int: &i32 = todo!();
+ | +++++++++
+
+error[E0381]: used binding `hello` isn't initialized
+ --> $DIR/suggest-assign-rvalue.rs:49:27
+ |
+LL | let hello: &str;
+ | ----- binding declared here but left uninitialized
+LL | println!("hello: {}", hello);
+ | ^^^^^ `hello` used here but it isn't initialized
+ |
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let hello: &str = todo!();
+ | +++++++++
+
+error[E0381]: used binding `never` isn't initialized
+ --> $DIR/suggest-assign-rvalue.rs:53:27
+ |
+LL | let never: !;
+ | ----- binding declared here but left uninitialized
+LL | println!("never: {}", never);
+ | ^^^^^ `never` used here but it isn't initialized
+ |
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 10 previous errors
+
+For more information about this error, try `rustc --explain E0381`.
diff --git a/src/test/ui/borrowck/two-phase-across-loop.stderr b/src/test/ui/borrowck/two-phase-across-loop.stderr
index 95896c6bb..22f9b39df 100644
--- a/src/test/ui/borrowck/two-phase-across-loop.stderr
+++ b/src/test/ui/borrowck/two-phase-across-loop.stderr
@@ -2,7 +2,10 @@ error[E0499]: cannot borrow `foo` as mutable more than once at a time
--> $DIR/two-phase-across-loop.rs:17:22
|
LL | strings.push(foo.get_string());
- | ^^^^^^^^^^^^^^^^ `foo` was mutably borrowed here in the previous iteration of the loop
+ | -------------^^^^^^^^^^^^^^^^-
+ | | |
+ | | `foo` was mutably borrowed here in the previous iteration of the loop
+ | first borrow used here, in later iteration of loop
error: aborting due to previous error
diff --git a/src/test/ui/box/issue-95036.rs b/src/test/ui/box/issue-95036.rs
index c2d4275aa..0611fabc1 100644
--- a/src/test/ui/box/issue-95036.rs
+++ b/src/test/ui/box/issue-95036.rs
@@ -1,7 +1,7 @@
// compile-flags: -O
// build-pass
-#![feature(allocator_api, bench_black_box)]
+#![feature(allocator_api)]
#[inline(never)]
pub fn by_ref(node: &mut Box<[u8; 1], &std::alloc::Global>) {
diff --git a/src/test/ui/builtin-clone-unwind.rs b/src/test/ui/builtin-clone-unwind.rs
index 3623c4a4d..16add6ff2 100644
--- a/src/test/ui/builtin-clone-unwind.rs
+++ b/src/test/ui/builtin-clone-unwind.rs
@@ -3,7 +3,6 @@
#![allow(unused_variables)]
#![allow(unused_imports)]
-// ignore-wasm32-bare compiled with panic=abort by default
// Test that builtin implementations of `Clone` cleanup everything
// in case of unwinding.
diff --git a/src/test/ui/cast/cast-rfc0401.rs b/src/test/ui/cast/cast-rfc0401.rs
index 996fa013f..9a9875416 100644
--- a/src/test/ui/cast/cast-rfc0401.rs
+++ b/src/test/ui/cast/cast-rfc0401.rs
@@ -159,11 +159,7 @@ fn main()
assert!(foo as usize != bar as usize);
// Taking a few bits of a function's address is totally pointless and we detect that
- // Disabling the lint to ensure that the assertion can still be run
- #[allow(const_err)]
- {
- assert_eq!(foo as i16, foo as usize as i16);
- }
+ assert_eq!(foo as i16, foo as usize as i16);
// fptr-ptr-cast
diff --git a/src/test/ui/cast/issue-88621.rs b/src/test/ui/cast/issue-88621.rs
index 9242b80e2..1679793ee 100644
--- a/src/test/ui/cast/issue-88621.rs
+++ b/src/test/ui/cast/issue-88621.rs
@@ -1,5 +1,3 @@
-#![feature(arbitrary_enum_discriminant)]
-
#[repr(u8)]
enum Kind2 {
Foo() = 1,
diff --git a/src/test/ui/cast/issue-88621.stderr b/src/test/ui/cast/issue-88621.stderr
index e96d86651..886145c1b 100644
--- a/src/test/ui/cast/issue-88621.stderr
+++ b/src/test/ui/cast/issue-88621.stderr
@@ -1,5 +1,5 @@
error[E0605]: non-primitive cast: `Kind2` as `u8`
- --> $DIR/issue-88621.rs:11:13
+ --> $DIR/issue-88621.rs:9:13
|
LL | let _ = Kind2::Foo() as u8;
| ^^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
diff --git a/src/test/ui/catch-unwind-bang.rs b/src/test/ui/catch-unwind-bang.rs
index b31b5cab5..fb3503937 100644
--- a/src/test/ui/catch-unwind-bang.rs
+++ b/src/test/ui/catch-unwind-bang.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
fn worker() -> ! {
panic!()
diff --git a/src/test/ui/cenum_impl_drop_cast.stderr b/src/test/ui/cenum_impl_drop_cast.stderr
index 98c331057..b3f921c14 100644
--- a/src/test/ui/cenum_impl_drop_cast.stderr
+++ b/src/test/ui/cenum_impl_drop_cast.stderr
@@ -4,13 +4,13 @@ error: cannot cast enum `E` into integer `u32` because it implements `Drop`
LL | let i = e as u32;
| ^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #73333 <https://github.com/rust-lang/rust/issues/73333>
note: the lint level is defined here
--> $DIR/cenum_impl_drop_cast.rs:1:9
|
LL | #![deny(cenum_impl_drop_cast)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #73333 <https://github.com/rust-lang/rust/issues/73333>
error: aborting due to previous error
@@ -21,11 +21,11 @@ error: cannot cast enum `E` into integer `u32` because it implements `Drop`
LL | let i = e as u32;
| ^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #73333 <https://github.com/rust-lang/rust/issues/73333>
note: the lint level is defined here
--> $DIR/cenum_impl_drop_cast.rs:1:9
|
LL | #![deny(cenum_impl_drop_cast)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #73333 <https://github.com/rust-lang/rust/issues/73333>
diff --git a/src/test/ui/cfg/cfg-method-receiver-ok.rs b/src/test/ui/cfg/cfg-method-receiver-ok.rs
new file mode 100644
index 000000000..61ad3b8c1
--- /dev/null
+++ b/src/test/ui/cfg/cfg-method-receiver-ok.rs
@@ -0,0 +1,14 @@
+// check-pass
+
+macro_rules! foo {
+ () => {
+ #[allow(unreachable_patterns)]
+ {
+ 123i32
+ }
+ };
+}
+
+fn main() {
+ let _ = foo!().abs();
+}
diff --git a/src/test/ui/cfg/cfg-method-receiver.rs b/src/test/ui/cfg/cfg-method-receiver.rs
new file mode 100644
index 000000000..71134ff17
--- /dev/null
+++ b/src/test/ui/cfg/cfg-method-receiver.rs
@@ -0,0 +1,11 @@
+macro_rules! cbor_map {
+ ($key:expr) => {
+ $key.signum();
+ //~^ ERROR can't call method `signum` on ambiguous numeric type `{integer}` [E0689]
+ };
+}
+
+fn main() {
+ cbor_map! { #[cfg(test)] 4};
+ //~^ ERROR removing an expression is not supported in this position
+}
diff --git a/src/test/ui/cfg/cfg-method-receiver.stderr b/src/test/ui/cfg/cfg-method-receiver.stderr
new file mode 100644
index 000000000..5767a7c1b
--- /dev/null
+++ b/src/test/ui/cfg/cfg-method-receiver.stderr
@@ -0,0 +1,24 @@
+error: removing an expression is not supported in this position
+ --> $DIR/cfg-method-receiver.rs:9:17
+ |
+LL | cbor_map! { #[cfg(test)] 4};
+ | ^^^^^^^^^^^^
+
+error[E0689]: can't call method `signum` on ambiguous numeric type `{integer}`
+ --> $DIR/cfg-method-receiver.rs:3:14
+ |
+LL | $key.signum();
+ | ^^^^^^
+...
+LL | cbor_map! { #[cfg(test)] 4};
+ | --------------------------- in this macro invocation
+ |
+ = note: this error originates in the macro `cbor_map` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: you must specify a concrete type for this numeric value, like `i32`
+ |
+LL | cbor_map! { #[cfg(test)] 4_i32};
+ | ~~~~~
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0689`.
diff --git a/src/test/ui/cfg/cfg-panic.rs b/src/test/ui/cfg/cfg-panic.rs
index fb3e5059c..2de72d54a 100644
--- a/src/test/ui/cfg/cfg-panic.rs
+++ b/src/test/ui/cfg/cfg-panic.rs
@@ -1,9 +1,6 @@
// build-pass
// compile-flags: -C panic=unwind
// needs-unwind
-// ignore-emscripten no panic_unwind implementation
-// ignore-wasm32 no panic_unwind implementation
-// ignore-wasm64 no panic_unwind implementation
#[cfg(panic = "abort")]
diff --git a/src/test/ui/cfg/future-compat-crate-attributes-using-cfg_attr.stderr b/src/test/ui/cfg/future-compat-crate-attributes-using-cfg_attr.stderr
index b52535ffd..9ce4710d6 100644
--- a/src/test/ui/cfg/future-compat-crate-attributes-using-cfg_attr.stderr
+++ b/src/test/ui/cfg/future-compat-crate-attributes-using-cfg_attr.stderr
@@ -4,9 +4,9 @@ error: `crate_type` within an `#![cfg_attr] attribute is deprecated`
LL | #![cfg_attr(foo, crate_type="bin")]
| ^^^^^^^^^^^^^^^^
|
- = note: `#[deny(deprecated_cfg_attr_crate_type_name)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #91632 <https://github.com/rust-lang/rust/issues/91632>
+ = note: `#[deny(deprecated_cfg_attr_crate_type_name)]` on by default
error: `crate_name` within an `#![cfg_attr] attribute is deprecated`
--> $DIR/future-compat-crate-attributes-using-cfg_attr.rs:9:18
diff --git a/src/test/ui/check-cfg/compact-values.stderr b/src/test/ui/check-cfg/compact-values.stderr
index a196e1537..9864aa385 100644
--- a/src/test/ui/check-cfg/compact-values.stderr
+++ b/src/test/ui/check-cfg/compact-values.stderr
@@ -4,8 +4,8 @@ warning: unexpected `cfg` condition value
LL | #[cfg(target(os = "linux", arch = "X"))]
| ^^^^^^^^^^
|
- = note: `#[warn(unexpected_cfgs)]` on by default
= note: expected values for `target_arch` are: aarch64, arm, avr, bpf, hexagon, m68k, mips, mips64, msp430, nvptx64, powerpc, powerpc64, riscv32, riscv64, s390x, sparc, sparc64, wasm32, wasm64, x86, x86_64
+ = note: `#[warn(unexpected_cfgs)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/check-cfg/empty-values.stderr b/src/test/ui/check-cfg/empty-values.stderr
index 10dab5034..a0168b2ca 100644
--- a/src/test/ui/check-cfg/empty-values.stderr
+++ b/src/test/ui/check-cfg/empty-values.stderr
@@ -6,8 +6,8 @@ LL | #[cfg(test = "value")]
| |
| help: remove the value
|
- = note: `#[warn(unexpected_cfgs)]` on by default
= note: no expected value for `test`
+ = note: `#[warn(unexpected_cfgs)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/check-cfg/invalid-cfg-value.stderr b/src/test/ui/check-cfg/invalid-cfg-value.stderr
index 7db2aadec..60abcb188 100644
--- a/src/test/ui/check-cfg/invalid-cfg-value.stderr
+++ b/src/test/ui/check-cfg/invalid-cfg-value.stderr
@@ -4,8 +4,8 @@ warning: unexpected `cfg` condition value
LL | #[cfg(feature = "sedre")]
| ^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unexpected_cfgs)]` on by default
= note: expected values for `feature` are: full, serde
+ = note: `#[warn(unexpected_cfgs)]` on by default
warning: unexpected `cfg` condition value
--> $DIR/invalid-cfg-value.rs:14:7
diff --git a/src/test/ui/check-cfg/no-values.stderr b/src/test/ui/check-cfg/no-values.stderr
index 7025b4cd7..8c926d187 100644
--- a/src/test/ui/check-cfg/no-values.stderr
+++ b/src/test/ui/check-cfg/no-values.stderr
@@ -4,8 +4,8 @@ warning: unexpected `cfg` condition value
LL | #[cfg(feature = "foo")]
| ^^^^^^^^^^^^^^^
|
- = note: `#[warn(unexpected_cfgs)]` on by default
= note: no expected value for `feature`
+ = note: `#[warn(unexpected_cfgs)]` on by default
warning: unexpected `cfg` condition value
--> $DIR/no-values.rs:10:7
diff --git a/src/test/ui/check-cfg/well-known-values.stderr b/src/test/ui/check-cfg/well-known-values.stderr
index 24ce2280c..4ec74494f 100644
--- a/src/test/ui/check-cfg/well-known-values.stderr
+++ b/src/test/ui/check-cfg/well-known-values.stderr
@@ -6,8 +6,8 @@ LL | #[cfg(target_os = "linuz")]
| |
| help: did you mean: `"linux"`
|
- = note: `#[warn(unexpected_cfgs)]` on by default
= note: expected values for `target_os` are: android, cuda, dragonfly, emscripten, espidf, freebsd, fuchsia, haiku, hermit, horizon, illumos, ios, l4re, linux, macos, netbsd, none, openbsd, psp, redox, solaris, solid_asp3, tvos, uefi, unknown, vxworks, wasi, watchos, windows, xous
+ = note: `#[warn(unexpected_cfgs)]` on by default
warning: unexpected `cfg` condition value
--> $DIR/well-known-values.rs:14:7
diff --git a/src/test/ui/check-static-values-constraints.rs b/src/test/ui/check-static-values-constraints.rs
index eb4ecd8ba..f6a577d0d 100644
--- a/src/test/ui/check-static-values-constraints.rs
+++ b/src/test/ui/check-static-values-constraints.rs
@@ -63,7 +63,7 @@ static STATIC8: SafeStruct = SafeStruct{field1: SafeEnum::Variant1,
// This example should fail because field1 in the base struct is not safe
static STATIC9: SafeStruct = SafeStruct{field1: SafeEnum::Variant1,
..SafeStruct{field1: SafeEnum::Variant3(WithDtor),
-//~^ ERROR destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
field2: SafeEnum::Variant1}};
struct UnsafeStruct;
diff --git a/src/test/ui/check-static-values-constraints.stderr b/src/test/ui/check-static-values-constraints.stderr
index 3c193ca34..31939f7f6 100644
--- a/src/test/ui/check-static-values-constraints.stderr
+++ b/src/test/ui/check-static-values-constraints.stderr
@@ -1,4 +1,4 @@
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `SafeStruct` cannot be evaluated at compile-time
--> $DIR/check-static-values-constraints.rs:65:43
|
LL | ..SafeStruct{field1: SafeEnum::Variant3(WithDtor),
@@ -7,7 +7,7 @@ LL | |
LL | | field2: SafeEnum::Variant1}};
| | ^- value is dropped here
| |________________________________________________________________________________|
- | statics cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in statics
error[E0010]: allocations are not allowed in statics
--> $DIR/check-static-values-constraints.rs:79:33
diff --git a/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr b/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr
index 284fc1c21..e6ddc6068 100644
--- a/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr
+++ b/src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr
@@ -26,7 +26,7 @@ LL | with_closure_expecting_fn_with_free_region(|x: fn(&u32), y| {});
| ^ one type is more general than the other
|
= note: expected fn pointer `fn(&u32)`
- found fn pointer `for<'r> fn(&'r u32)`
+ found fn pointer `for<'a> fn(&'a u32)`
error[E0308]: mismatched types
--> $DIR/expect-fn-supply-fn.rs:39:50
@@ -34,7 +34,7 @@ error[E0308]: mismatched types
LL | with_closure_expecting_fn_with_bound_region(|x: fn(&'x u32), y| {});
| ^ one type is more general than the other
|
- = note: expected fn pointer `for<'r> fn(&'r u32)`
+ = note: expected fn pointer `for<'a> fn(&'a u32)`
found fn pointer `fn(&u32)`
error[E0308]: mismatched types
@@ -43,7 +43,7 @@ error[E0308]: mismatched types
LL | with_closure_expecting_fn_with_bound_region(|x: Foo<'_>, y| {
| ^ one type is more general than the other
|
- = note: expected fn pointer `for<'r> fn(&'r u32)`
+ = note: expected fn pointer `for<'a> fn(&'a u32)`
found fn pointer `fn(&u32)`
error: aborting due to 5 previous errors
diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr
index 7e767cba3..cf414adc0 100644
--- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness.stderr
@@ -4,13 +4,13 @@ warning: value captured by `a` is never read
LL | a = 1;
| ^
|
+ = help: did you mean to capture by reference instead?
note: the lint level is defined here
--> $DIR/liveness.rs:5:9
|
LL | #![warn(unused)]
| ^^^^^^
= note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]`
- = help: did you mean to capture by reference instead?
warning: unused variable: `a`
--> $DIR/liveness.rs:33:9
@@ -18,8 +18,8 @@ warning: unused variable: `a`
LL | a += 1;
| ^
|
- = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
= help: did you mean to capture by reference instead?
+ = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
warning: value assigned to `a` is never read
--> $DIR/liveness.rs:53:9
diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr
index 2ac801b49..0410de4c7 100644
--- a/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/liveness_unintentional_copy.stderr
@@ -4,13 +4,13 @@ warning: value assigned to `a` is never read
LL | a = s;
| ^
|
+ = help: maybe it is overwritten before being read?
note: the lint level is defined here
--> $DIR/liveness_unintentional_copy.rs:4:9
|
LL | #![warn(unused)]
| ^^^^^^
= note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]`
- = help: maybe it is overwritten before being read?
warning: unused variable: `a`
--> $DIR/liveness_unintentional_copy.rs:20:9
@@ -18,8 +18,8 @@ warning: unused variable: `a`
LL | a = s;
| ^
|
- = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
= help: did you mean to capture by reference instead?
+ = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
warning: unused variable: `a`
--> $DIR/liveness_unintentional_copy.rs:36:9
diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr
index 93abbecf4..508c4b911 100644
--- a/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr
@@ -4,11 +4,11 @@ error: reference to packed field is unaligned
LL | println!("{}", foo.x);
| ^^^^^
|
- = note: `#[deny(unaligned_references)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
+ = note: `#[deny(unaligned_references)]` on by default
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
@@ -20,10 +20,10 @@ error: reference to packed field is unaligned
LL | println!("{}", foo.x);
| ^^^^^
|
- = note: `#[deny(unaligned_references)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
+ = note: `#[deny(unaligned_references)]` on by default
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/src/test/ui/closures/2229_closure_analysis/issue-88118-2.stderr b/src/test/ui/closures/2229_closure_analysis/issue-88118-2.stderr
index 15689023d..b3cb558f9 100644
--- a/src/test/ui/closures/2229_closure_analysis/issue-88118-2.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/issue-88118-2.stderr
@@ -4,9 +4,9 @@ warning: irrefutable `if let` guard pattern
LL | Registry if let _ = registry.try_find_description() => { }
| ^
|
- = note: `#[warn(irrefutable_let_patterns)]` on by default
= note: this pattern will always match, so the guard is useless
= help: consider removing the guard and adding a `let` inside the match arm
+ = note: `#[warn(irrefutable_let_patterns)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/closures/2229_closure_analysis/issue-90465.stderr b/src/test/ui/closures/2229_closure_analysis/issue-90465.stderr
index 3e921dc0f..c1679c6b6 100644
--- a/src/test/ui/closures/2229_closure_analysis/issue-90465.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/issue-90465.stderr
@@ -10,12 +10,12 @@ LL | let _ = f0;
LL | }
| - in Rust 2018, `f0` is dropped here along with the closure, but in Rust 2021 `f0` is not part of the closure
|
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
note: the lint level is defined here
--> $DIR/issue-90465.rs:3:9
|
LL | #![deny(rust_2021_incompatible_closure_captures)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `f0` to be fully captured
|
LL ~ let c0 = move || {
diff --git a/src/test/ui/closures/2229_closure_analysis/match/issue-87097.stderr b/src/test/ui/closures/2229_closure_analysis/match/issue-87097.stderr
index 2a49ed4b5..384010859 100644
--- a/src/test/ui/closures/2229_closure_analysis/match/issue-87097.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/match/issue-87097.stderr
@@ -18,8 +18,8 @@ LL | | Variant::B => (),
LL | | };
| |______^
|
- = note: `#[warn(unused_must_use)]` on by default
= note: closures are lazy and do nothing unless called
+ = note: `#[warn(unused_must_use)]` on by default
warning: unused closure that must be used
--> $DIR/issue-87097.rs:26:5
diff --git a/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr b/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr
index fea5441ec..ad061d93c 100644
--- a/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr
@@ -76,6 +76,11 @@ LL | let x: u8;
| - binding declared here but left uninitialized
LL | let c1 = || match x { };
| ^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: u8 = 0;
+ | +++
error: aborting due to 8 previous errors
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr
index d7104bafe..3a42cc8b8 100644
--- a/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr
@@ -7,12 +7,12 @@ LL | thread::spawn(move || unsafe {
LL | *fptr.0 = 20;
| ------- in Rust 2018, this closure captures all of `fptr`, but in Rust 2021, it will only capture `fptr.0`
|
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
note: the lint level is defined here
--> $DIR/auto_traits.rs:2:9
|
LL | #![deny(rust_2021_incompatible_closure_captures)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `fptr` to be fully captured
|
LL ~ thread::spawn(move || { let _ = &fptr; unsafe {
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.stderr
index c611daf13..bb17e3a34 100644
--- a/src/test/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.stderr
@@ -15,13 +15,13 @@ LL | | println!("{:?}", x);
LL | | });
| |______- in this macro invocation
|
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
note: the lint level is defined here
--> $DIR/closure-body-macro-fragment.rs:4:9
|
LL | #![warn(rust_2021_compatibility)]
| ^^^^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(rust_2021_incompatible_closure_captures)]` implied by `#[warn(rust_2021_compatibility)]`
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
= note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
help: add a dummy let to cause `a` to be fully captured
|
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.stderr
index 832a81711..a0795c129 100644
--- a/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/insignificant_drop_attr_migrations.stderr
@@ -10,12 +10,12 @@ LL | let _t = t.0;
LL | }
| - in Rust 2018, `t` is dropped here, but in Rust 2021, only `t.0` will be dropped here as part of the closure
|
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
note: the lint level is defined here
--> $DIR/insignificant_drop_attr_migrations.rs:3:9
|
LL | #![deny(rust_2021_incompatible_closure_captures)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `t` to be fully captured
|
LL ~ let c = || {
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr
index 41b675f79..36a80e694 100644
--- a/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr
@@ -4,9 +4,9 @@ warning: irrefutable `if let` pattern
LL | if let a = "" {
| ^^^^^^^^^^
|
- = note: `#[warn(irrefutable_let_patterns)]` on by default
= note: this pattern will always match, so the `if let` is useless
= help: consider replacing the `if let` with a `let`
+ = note: `#[warn(irrefutable_let_patterns)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/macro.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/macro.stderr
index 2d0c56aad..c17edce72 100644
--- a/src/test/ui/closures/2229_closure_analysis/migrations/macro.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/macro.stderr
@@ -7,12 +7,12 @@ LL | let _ = || dbg!(a.0);
LL | }
| - in Rust 2018, `a` is dropped here, but in Rust 2021, only `a.0` will be dropped here as part of the closure
|
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
note: the lint level is defined here
--> $DIR/macro.rs:5:9
|
LL | #![deny(rust_2021_incompatible_closure_captures)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `a` to be fully captured
|
LL | let _ = || { let _ = &a; dbg!(a.0) };
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.stderr
index 12760cc72..94526487e 100644
--- a/src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/migrations_rustfix.stderr
@@ -10,12 +10,12 @@ LL | let _t = t.0;
LL | }
| - in Rust 2018, `t` is dropped here, but in Rust 2021, only `t.0` will be dropped here as part of the closure
|
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
note: the lint level is defined here
--> $DIR/migrations_rustfix.rs:2:9
|
LL | #![deny(rust_2021_incompatible_closure_captures)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `t` to be fully captured
|
LL ~ let c = || {
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.fixed b/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.fixed
index 89f393141..ff2244a8e 100644
--- a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.fixed
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.fixed
@@ -3,7 +3,6 @@
#![deny(rust_2021_incompatible_closure_captures)]
//~^ NOTE: the lint level is defined here
-// ignore-wasm32-bare compiled with panic=abort by default
#![feature(fn_traits)]
#![feature(never_type)]
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs b/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs
index 6b0b10521..52e96d013 100644
--- a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.rs
@@ -3,7 +3,6 @@
#![deny(rust_2021_incompatible_closure_captures)]
//~^ NOTE: the lint level is defined here
-// ignore-wasm32-bare compiled with panic=abort by default
#![feature(fn_traits)]
#![feature(never_type)]
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.stderr
index 2648b0043..e10898f98 100644
--- a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.stderr
@@ -1,5 +1,5 @@
error: changes to closure capture in Rust 2021 will affect which traits the closure implements
- --> $DIR/mir_calls_to_shims.rs:21:38
+ --> $DIR/mir_calls_to_shims.rs:20:38
|
LL | let result = panic::catch_unwind(move || {
| ^^^^^^^
@@ -10,12 +10,12 @@ LL | let result = panic::catch_unwind(move || {
LL | f.0()
| --- in Rust 2018, this closure captures all of `f`, but in Rust 2021, it will only capture `f.0`
|
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
note: the lint level is defined here
--> $DIR/mir_calls_to_shims.rs:4:9
|
LL | #![deny(rust_2021_incompatible_closure_captures)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `f` to be fully captured
|
LL ~ let result = panic::catch_unwind(move || {
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr
index 96d5c936f..efb264447 100644
--- a/src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr
@@ -13,12 +13,12 @@ LL | let _f_2 = f2.1;
LL | }
| - in Rust 2018, `f2` is dropped here, but in Rust 2021, only `f2.1` will be dropped here as part of the closure
|
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
note: the lint level is defined here
--> $DIR/multi_diagnostics.rs:2:9
|
LL | #![deny(rust_2021_incompatible_closure_captures)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `f1`, `f2` to be fully captured
|
LL ~ let c = || {
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/precise.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/precise.stderr
index aa9b8672a..eff26a4d6 100644
--- a/src/test/ui/closures/2229_closure_analysis/migrations/precise.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/precise.stderr
@@ -10,12 +10,12 @@ LL | let _t = t.0;
LL | }
| - in Rust 2018, `t` is dropped here, but in Rust 2021, only `t.0` will be dropped here as part of the closure
|
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
note: the lint level is defined here
--> $DIR/precise.rs:3:9
|
LL | #![deny(rust_2021_incompatible_closure_captures)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `t` to be fully captured
|
LL ~ let c = || {
diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.stderr
index 0d9f09ee3..54ad20f89 100644
--- a/src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/migrations/significant_drop.stderr
@@ -20,12 +20,12 @@ LL | }
| in Rust 2018, `t1` is dropped here, but in Rust 2021, only `t1.0` will be dropped here as part of the closure
| in Rust 2018, `t2` is dropped here, but in Rust 2021, only `t2.0` will be dropped here as part of the closure
|
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
note: the lint level is defined here
--> $DIR/significant_drop.rs:2:9
|
LL | #![deny(rust_2021_incompatible_closure_captures)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
help: add a dummy let to cause `t`, `t1`, `t2` to be fully captured
|
LL ~ let c = || {
diff --git a/src/test/ui/closures/closure-bounds-subtype.stderr b/src/test/ui/closures/closure-bounds-subtype.stderr
index 1a40326d9..8ad8273fc 100644
--- a/src/test/ui/closures/closure-bounds-subtype.stderr
+++ b/src/test/ui/closures/closure-bounds-subtype.stderr
@@ -11,6 +11,10 @@ note: required by a bound in `take_const_owned`
|
LL | fn take_const_owned<F>(_: F) where F: FnOnce() + Sync + Send {
| ^^^^ required by this bound in `take_const_owned`
+help: use parentheses to call this type parameter
+ |
+LL | take_const_owned(f());
+ | ++
help: consider further restricting this bound
|
LL | fn give_owned<F>(f: F) where F: FnOnce() + Send + std::marker::Sync {
diff --git a/src/test/ui/closures/closure-reform-bad.stderr b/src/test/ui/closures/closure-reform-bad.stderr
index 9dfff8499..4c40f70b9 100644
--- a/src/test/ui/closures/closure-reform-bad.stderr
+++ b/src/test/ui/closures/closure-reform-bad.stderr
@@ -8,7 +8,7 @@ LL | call_bare(f)
| |
| arguments to this function are incorrect
|
- = note: expected fn pointer `for<'r> fn(&'r str)`
+ = note: expected fn pointer `for<'a> fn(&'a str)`
found closure `[closure@$DIR/closure-reform-bad.rs:10:13: 10:22]`
note: closures can only be coerced to `fn` types if they do not capture any variables
--> $DIR/closure-reform-bad.rs:10:43
diff --git a/src/test/ui/closures/closure-return-type-must-be-sized.rs b/src/test/ui/closures/closure-return-type-must-be-sized.rs
new file mode 100644
index 000000000..8cfa02912
--- /dev/null
+++ b/src/test/ui/closures/closure-return-type-must-be-sized.rs
@@ -0,0 +1,74 @@
+#![feature(unboxed_closures)]
+
+trait A {
+ fn a() where Self: Sized;
+}
+
+mod a {
+ use crate::A;
+
+ pub fn foo<F: FnOnce<()>>() where F::Output: A {
+ F::Output::a()
+ }
+
+ pub fn bar<F: FnOnce() -> R, R: ?Sized>() {}
+
+ pub fn baz<F: FnOnce<()>>() where F::Output: A, F::Output: Sized {
+ F::Output::a()
+ }
+}
+
+mod b {
+ use crate::A;
+
+ pub fn foo<F: Fn<()>>() where F::Output: A {
+ F::Output::a()
+ }
+
+ pub fn bar<F: Fn() -> R, R: ?Sized>() {}
+
+ pub fn baz<F: Fn<()>>() where F::Output: A, F::Output: Sized {
+ F::Output::a()
+ }
+}
+
+mod c {
+ use crate::A;
+
+ pub fn foo<F: FnMut<()>>() where F::Output: A {
+ F::Output::a()
+ }
+
+ pub fn bar<F: FnMut() -> R, R: ?Sized>() {}
+
+ pub fn baz<F: FnMut<()>>() where F::Output: A, F::Output: Sized {
+ F::Output::a()
+ }
+}
+
+impl A for Box<dyn A> {
+ fn a() {}
+}
+
+fn main() {
+ a::foo::<fn() -> dyn A>(); //~ ERROR E0277
+ a::bar::<fn() -> dyn A, _>(); //~ ERROR E0277
+ a::baz::<fn() -> dyn A>(); //~ ERROR E0277
+ a::foo::<fn() -> Box<dyn A>>(); // ok
+ a::bar::<fn() -> Box<dyn A>, _>(); // ok
+ a::baz::<fn() -> Box<dyn A>>(); // ok
+
+ b::foo::<fn() -> dyn A>(); //~ ERROR E0277
+ b::bar::<fn() -> dyn A, _>(); //~ ERROR E0277
+ b::baz::<fn() -> dyn A>(); //~ ERROR E0277
+ b::foo::<fn() -> Box<dyn A>>(); // ok
+ b::bar::<fn() -> Box<dyn A>, _>(); // ok
+ b::baz::<fn() -> Box<dyn A>>(); // ok
+
+ c::foo::<fn() -> dyn A>(); //~ ERROR E0277
+ c::bar::<fn() -> dyn A, _>(); //~ ERROR E0277
+ c::baz::<fn() -> dyn A>(); //~ ERROR E0277
+ c::foo::<fn() -> Box<dyn A>>(); // ok
+ c::bar::<fn() -> Box<dyn A>, _>(); // ok
+ c::baz::<fn() -> Box<dyn A>>(); // ok
+}
diff --git a/src/test/ui/closures/closure-return-type-must-be-sized.stderr b/src/test/ui/closures/closure-return-type-must-be-sized.stderr
new file mode 100644
index 000000000..b07425bd8
--- /dev/null
+++ b/src/test/ui/closures/closure-return-type-must-be-sized.stderr
@@ -0,0 +1,99 @@
+error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
+ --> $DIR/closure-return-type-must-be-sized.rs:54:5
+ |
+LL | a::foo::<fn() -> dyn A>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
+ = note: required because it appears within the type `fn() -> dyn A`
+
+error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
+ --> $DIR/closure-return-type-must-be-sized.rs:55:14
+ |
+LL | a::bar::<fn() -> dyn A, _>();
+ | ^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
+ = note: required because it appears within the type `fn() -> dyn A`
+note: required by a bound in `a::bar`
+ --> $DIR/closure-return-type-must-be-sized.rs:14:19
+ |
+LL | pub fn bar<F: FnOnce() -> R, R: ?Sized>() {}
+ | ^^^^^^^^^^^^^ required by this bound in `a::bar`
+
+error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
+ --> $DIR/closure-return-type-must-be-sized.rs:56:5
+ |
+LL | a::baz::<fn() -> dyn A>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
+ = note: required because it appears within the type `fn() -> dyn A`
+
+error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
+ --> $DIR/closure-return-type-must-be-sized.rs:61:5
+ |
+LL | b::foo::<fn() -> dyn A>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
+ = note: required because it appears within the type `fn() -> dyn A`
+
+error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
+ --> $DIR/closure-return-type-must-be-sized.rs:62:14
+ |
+LL | b::bar::<fn() -> dyn A, _>();
+ | ^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
+ = note: required because it appears within the type `fn() -> dyn A`
+note: required by a bound in `b::bar`
+ --> $DIR/closure-return-type-must-be-sized.rs:28:19
+ |
+LL | pub fn bar<F: Fn() -> R, R: ?Sized>() {}
+ | ^^^^^^^^^ required by this bound in `b::bar`
+
+error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
+ --> $DIR/closure-return-type-must-be-sized.rs:63:5
+ |
+LL | b::baz::<fn() -> dyn A>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
+ = note: required because it appears within the type `fn() -> dyn A`
+
+error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
+ --> $DIR/closure-return-type-must-be-sized.rs:68:5
+ |
+LL | c::foo::<fn() -> dyn A>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
+ = note: required because it appears within the type `fn() -> dyn A`
+
+error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
+ --> $DIR/closure-return-type-must-be-sized.rs:69:14
+ |
+LL | c::bar::<fn() -> dyn A, _>();
+ | ^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
+ = note: required because it appears within the type `fn() -> dyn A`
+note: required by a bound in `c::bar`
+ --> $DIR/closure-return-type-must-be-sized.rs:42:19
+ |
+LL | pub fn bar<F: FnMut() -> R, R: ?Sized>() {}
+ | ^^^^^^^^^^^^ required by this bound in `c::bar`
+
+error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
+ --> $DIR/closure-return-type-must-be-sized.rs:70:5
+ |
+LL | c::baz::<fn() -> dyn A>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ = help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
+ = note: required because it appears within the type `fn() -> dyn A`
+
+error: aborting due to 9 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/closures/closure_promotion.rs b/src/test/ui/closures/closure_promotion.rs
index db36985af..47a8fc090 100644
--- a/src/test/ui/closures/closure_promotion.rs
+++ b/src/test/ui/closures/closure_promotion.rs
@@ -1,7 +1,5 @@
// build-pass (FIXME(62277): could be check-pass?)
-#![allow(const_err)]
-
fn main() {
let x: &'static _ = &|| { let z = 3; z };
}
diff --git a/src/test/ui/closures/issue-101696.rs b/src/test/ui/closures/issue-101696.rs
new file mode 100644
index 000000000..0a358bd16
--- /dev/null
+++ b/src/test/ui/closures/issue-101696.rs
@@ -0,0 +1,36 @@
+// check-pass
+
+use std::marker::PhantomData;
+
+#[derive(Default)]
+struct MyType<'a> {
+ field: usize,
+ _phantom: PhantomData<&'a ()>,
+}
+
+#[derive(Default)]
+struct MyTypeVariant<'a> {
+ field: usize,
+ _phantom: PhantomData<&'a ()>,
+}
+
+trait AsVariantTrait {
+ type Type;
+}
+
+impl<'a> AsVariantTrait for MyType<'a> {
+ type Type = MyTypeVariant<'a>;
+}
+
+type Variant<G> = <G as AsVariantTrait>::Type;
+
+fn foo<T: Default, F: FnOnce(T)>(f: F) {
+ let input = T::default();
+ f(input);
+}
+
+fn main() {
+ foo(|a: <MyType as AsVariantTrait>::Type| {
+ a.field;
+ });
+}
diff --git a/src/test/ui/closures/issue-102089-multiple-opaque-cast.rs b/src/test/ui/closures/issue-102089-multiple-opaque-cast.rs
new file mode 100644
index 000000000..043bf06a1
--- /dev/null
+++ b/src/test/ui/closures/issue-102089-multiple-opaque-cast.rs
@@ -0,0 +1,17 @@
+// edition:2021
+// check-pass
+
+pub struct Example<'a, T> {
+ a: T,
+ b: &'a T,
+}
+
+impl<'a, T> Example<'a, T> {
+ pub fn error_trying_to_destructure_self_in_closure(self) {
+ let closure = || {
+ let Self { a, b } = self;
+ };
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/closures/issue-97607.rs b/src/test/ui/closures/issue-97607.rs
new file mode 100644
index 000000000..74c910ad0
--- /dev/null
+++ b/src/test/ui/closures/issue-97607.rs
@@ -0,0 +1,12 @@
+// check-pass
+#[allow(unused)]
+
+fn test<T, F, U>(f: F) -> Box<dyn Fn(T) -> U + 'static>
+where
+ F: 'static + Fn(T) -> U,
+ for<'a> U: 'a, // < This is the problematic line, see #97607
+{
+ Box::new(move |t| f(t))
+}
+
+fn main() {}
diff --git a/src/test/ui/closures/multiple-fn-bounds.rs b/src/test/ui/closures/multiple-fn-bounds.rs
new file mode 100644
index 000000000..6bb4098e2
--- /dev/null
+++ b/src/test/ui/closures/multiple-fn-bounds.rs
@@ -0,0 +1,15 @@
+fn foo<F: Fn(&char) -> bool + Fn(char) -> bool>(f: F) {
+ //~^ NOTE required by a bound in `foo`
+ //~| NOTE required by this bound in `foo`
+ //~| NOTE closure inferred to have a different signature due to this bound
+ todo!();
+}
+
+fn main() {
+ let v = true;
+ foo(move |x| v);
+ //~^ ERROR type mismatch in closure arguments
+ //~| NOTE expected closure signature
+ //~| NOTE expected due to this
+ //~| NOTE found signature defined here
+}
diff --git a/src/test/ui/closures/multiple-fn-bounds.stderr b/src/test/ui/closures/multiple-fn-bounds.stderr
new file mode 100644
index 000000000..eefc123fe
--- /dev/null
+++ b/src/test/ui/closures/multiple-fn-bounds.stderr
@@ -0,0 +1,24 @@
+error[E0631]: type mismatch in closure arguments
+ --> $DIR/multiple-fn-bounds.rs:10:5
+ |
+LL | foo(move |x| v);
+ | ^^^ -------- found signature defined here
+ | |
+ | expected due to this
+ |
+ = note: expected closure signature `fn(char) -> _`
+ found closure signature `for<'a> fn(&'a char) -> _`
+note: closure inferred to have a different signature due to this bound
+ --> $DIR/multiple-fn-bounds.rs:1:11
+ |
+LL | fn foo<F: Fn(&char) -> bool + Fn(char) -> bool>(f: F) {
+ | ^^^^^^^^^^^^^^^^^
+note: required by a bound in `foo`
+ --> $DIR/multiple-fn-bounds.rs:1:31
+ |
+LL | fn foo<F: Fn(&char) -> bool + Fn(char) -> bool>(f: F) {
+ | ^^^^^^^^^^^^^^^^ required by this bound in `foo`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0631`.
diff --git a/src/test/ui/closures/old-closure-expression-remove-semicolon.fixed b/src/test/ui/closures/old-closure-expression-remove-semicolon.fixed
index 623e917da..8aa9e952b 100644
--- a/src/test/ui/closures/old-closure-expression-remove-semicolon.fixed
+++ b/src/test/ui/closures/old-closure-expression-remove-semicolon.fixed
@@ -7,6 +7,6 @@ fn foo() -> i32 {
fn main() {
let _x: i32 = {
//~^ ERROR mismatched types
- foo() //~ HELP remove this semicolon
+ foo() //~ HELP remove this semicolon to return this value
};
}
diff --git a/src/test/ui/closures/old-closure-expression-remove-semicolon.rs b/src/test/ui/closures/old-closure-expression-remove-semicolon.rs
index 4974b0866..912c7a331 100644
--- a/src/test/ui/closures/old-closure-expression-remove-semicolon.rs
+++ b/src/test/ui/closures/old-closure-expression-remove-semicolon.rs
@@ -7,6 +7,6 @@ fn foo() -> i32 {
fn main() {
let _x: i32 = {
//~^ ERROR mismatched types
- foo(); //~ HELP remove this semicolon
+ foo(); //~ HELP remove this semicolon to return this value
};
}
diff --git a/src/test/ui/closures/old-closure-expression-remove-semicolon.stderr b/src/test/ui/closures/old-closure-expression-remove-semicolon.stderr
index 9b73ce4fe..bc54ab4d5 100644
--- a/src/test/ui/closures/old-closure-expression-remove-semicolon.stderr
+++ b/src/test/ui/closures/old-closure-expression-remove-semicolon.stderr
@@ -5,7 +5,7 @@ LL | let _x: i32 = {
| ___________________^
LL | |
LL | | foo();
- | | - help: remove this semicolon
+ | | - help: remove this semicolon to return this value
LL | | };
| |_____^ expected `i32`, found `()`
diff --git a/src/test/ui/codemap_tests/unicode.normal.stderr b/src/test/ui/codemap_tests/unicode.normal.stderr
index 60f8cff84..05ceb6910 100644
--- a/src/test/ui/codemap_tests/unicode.normal.stderr
+++ b/src/test/ui/codemap_tests/unicode.normal.stderr
@@ -4,7 +4,7 @@ error[E0703]: invalid ABI: found `路濫狼áÌÌ`
LL | extern "路濫狼áÌÌ" fn foo() {}
| ^^^^^^^^^ invalid ABI
|
- = help: valid ABIs: Rust, C, C-unwind, cdecl, cdecl-unwind, stdcall, stdcall-unwind, fastcall, fastcall-unwind, vectorcall, vectorcall-unwind, thiscall, thiscall-unwind, aapcs, aapcs-unwind, win64, win64-unwind, sysv64, sysv64-unwind, ptx-kernel, msp430-interrupt, x86-interrupt, amdgpu-kernel, efiapi, avr-interrupt, avr-non-blocking-interrupt, C-cmse-nonsecure-call, wasm, system, system-unwind, rust-intrinsic, rust-call, platform-intrinsic, unadjusted, rust-cold
+ = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions.
error: aborting due to previous error
diff --git a/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr b/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr
index a4843bca5..4c04bb113 100644
--- a/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr
+++ b/src/test/ui/coercion/coercion-missing-tail-expected-type.stderr
@@ -6,7 +6,7 @@ LL | fn plus_one(x: i32) -> i32 {
| |
| implicitly returns `()` as its body has no tail or `return` expression
LL | x + 1;
- | - help: remove this semicolon
+ | - help: remove this semicolon to return this value
error[E0308]: mismatched types
--> $DIR/coercion-missing-tail-expected-type.rs:8:13
@@ -16,7 +16,7 @@ LL | fn foo() -> Result<u8, u64> {
| |
| implicitly returns `()` as its body has no tail or `return` expression
LL | Ok(1);
- | - help: remove this semicolon
+ | - help: remove this semicolon to return this value
|
= note: expected enum `Result<u8, u64>`
found unit type `()`
diff --git a/src/test/ui/coercion/issue-36007.rs b/src/test/ui/coercion/issue-36007.rs
new file mode 100644
index 000000000..78812df87
--- /dev/null
+++ b/src/test/ui/coercion/issue-36007.rs
@@ -0,0 +1,20 @@
+// check-pass
+#![feature(coerce_unsized, unsize)]
+
+use std::marker::Unsize;
+use std::ops::CoerceUnsized;
+
+struct Foo<T: ?Sized>(Box<T>);
+
+impl<T> CoerceUnsized<Foo<dyn Baz>> for Foo<T> where T: Unsize<dyn Baz> {}
+
+struct Bar;
+
+trait Baz {}
+
+impl Baz for Bar {}
+
+fn main() {
+ let foo = Foo(Box::new(Bar));
+ let foobar: Foo<Bar> = foo;
+}
diff --git a/src/test/ui/coherence/coherence-default-trait-impl.stderr b/src/test/ui/coherence/coherence-default-trait-impl.stderr
index b08ccb087..632018782 100644
--- a/src/test/ui/coherence/coherence-default-trait-impl.stderr
+++ b/src/test/ui/coherence/coherence-default-trait-impl.stderr
@@ -3,12 +3,24 @@ error[E0199]: implementing the trait `MySafeTrait` is not unsafe
|
LL | unsafe impl MySafeTrait for Foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove `unsafe` from this trait implementation
+ |
+LL - unsafe impl MySafeTrait for Foo {}
+LL + impl MySafeTrait for Foo {}
+ |
error[E0200]: the trait `MyUnsafeTrait` requires an `unsafe impl` declaration
--> $DIR/coherence-default-trait-impl.rs:13:1
|
LL | impl MyUnsafeTrait for Foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the trait `MyUnsafeTrait` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
+help: add `unsafe` to this trait implementation
+ |
+LL | unsafe impl MyUnsafeTrait for Foo {}
+ | ++++++
error: aborting due to 2 previous errors
diff --git a/src/test/ui/coherence/coherence-fn-covariant-bound-vs-static.stderr b/src/test/ui/coherence/coherence-fn-covariant-bound-vs-static.stderr
index cfcef9699..7dabd97b9 100644
--- a/src/test/ui/coherence/coherence-fn-covariant-bound-vs-static.stderr
+++ b/src/test/ui/coherence/coherence-fn-covariant-bound-vs-static.stderr
@@ -1,10 +1,10 @@
-error[E0119]: conflicting implementations of trait `Trait` for type `for<'r> fn(for<'r> fn(&'r ()))`
+error[E0119]: conflicting implementations of trait `Trait` for type `for<'r> fn(fn(&'r ()))`
--> $DIR/coherence-fn-covariant-bound-vs-static.rs:17:1
|
LL | impl Trait for for<'r> fn(fn(&'r ())) {}
| ------------------------------------- first implementation here
LL | impl<'a> Trait for fn(fn(&'a ())) {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'r> fn(for<'r> fn(&'r ()))`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'r> fn(fn(&'r ()))`
|
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
diff --git a/src/test/ui/coherence/coherence-fn-implied-bounds.stderr b/src/test/ui/coherence/coherence-fn-implied-bounds.stderr
index 8612ce60d..201871204 100644
--- a/src/test/ui/coherence/coherence-fn-implied-bounds.stderr
+++ b/src/test/ui/coherence/coherence-fn-implied-bounds.stderr
@@ -7,14 +7,14 @@ LL |
LL | impl Trait for for<'c> fn(&'c &'c u32, &'c &'c u32) -> &'c u32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a &'b u32, &'b &'a u32) -> &'b u32`
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
+ = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
note: the lint level is defined here
--> $DIR/coherence-fn-implied-bounds.rs:15:9
|
LL | #![deny(coherence_leak_check)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
- = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
error: aborting due to previous error
diff --git a/src/test/ui/coherence/coherence-free-vs-bound-region.stderr b/src/test/ui/coherence/coherence-free-vs-bound-region.stderr
index af18655b0..e2d84b833 100644
--- a/src/test/ui/coherence/coherence-free-vs-bound-region.stderr
+++ b/src/test/ui/coherence/coherence-free-vs-bound-region.stderr
@@ -7,14 +7,14 @@ LL |
LL | impl TheTrait for fn(&u8) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `fn(&u8)`
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
+ = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
note: the lint level is defined here
--> $DIR/coherence-free-vs-bound-region.rs:10:9
|
LL | #![deny(coherence_leak_check)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
- = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
error: aborting due to previous error
diff --git a/src/test/ui/coherence/coherence-inherited-assoc-ty-cycle-err.stderr b/src/test/ui/coherence/coherence-inherited-assoc-ty-cycle-err.stderr
index 97f3c7593..7bd50649d 100644
--- a/src/test/ui/coherence/coherence-inherited-assoc-ty-cycle-err.stderr
+++ b/src/test/ui/coherence/coherence-inherited-assoc-ty-cycle-err.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0391]: cycle detected when building specialization graph of trait `Trait`
--> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:9:1
diff --git a/src/test/ui/coherence/coherence-negative-impls-copy-bad.rs b/src/test/ui/coherence/coherence-negative-impls-copy-bad.rs
new file mode 100644
index 000000000..563f28e22
--- /dev/null
+++ b/src/test/ui/coherence/coherence-negative-impls-copy-bad.rs
@@ -0,0 +1,11 @@
+#![feature(negative_impls)]
+#![crate_type = "lib"]
+
+impl !Copy for str {}
+//~^ ERROR only traits defined in the current crate can be implemented
+
+impl !Copy for fn() {}
+//~^ ERROR only traits defined in the current crate can be implemented
+
+impl !Copy for () {}
+//~^ ERROR only traits defined in the current crate can be implemented
diff --git a/src/test/ui/coherence/coherence-negative-impls-copy-bad.stderr b/src/test/ui/coherence/coherence-negative-impls-copy-bad.stderr
new file mode 100644
index 000000000..2295d6315
--- /dev/null
+++ b/src/test/ui/coherence/coherence-negative-impls-copy-bad.stderr
@@ -0,0 +1,36 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+ --> $DIR/coherence-negative-impls-copy-bad.rs:4:1
+ |
+LL | impl !Copy for str {}
+ | ^^^^^^^^^^^^^^^---
+ | | |
+ | | `str` is not defined in the current crate
+ | impl doesn't use only types from inside the current crate
+ |
+ = note: define and implement a trait or new type instead
+
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+ --> $DIR/coherence-negative-impls-copy-bad.rs:7:1
+ |
+LL | impl !Copy for fn() {}
+ | ^^^^^^^^^^^^^^^----
+ | | |
+ | | `fn()` is not defined in the current crate
+ | impl doesn't use only types from inside the current crate
+ |
+ = note: define and implement a trait or new type instead
+
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+ --> $DIR/coherence-negative-impls-copy-bad.rs:10:1
+ |
+LL | impl !Copy for () {}
+ | ^^^^^^^^^^^^^^^--
+ | | |
+ | | this is not defined in the current crate because tuples are always foreign
+ | impl doesn't use only types from inside the current crate
+ |
+ = note: define and implement a trait or new type instead
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0117`.
diff --git a/src/test/ui/coherence/coherence-negative-impls-copy.rs b/src/test/ui/coherence/coherence-negative-impls-copy.rs
new file mode 100644
index 000000000..7b29aade4
--- /dev/null
+++ b/src/test/ui/coherence/coherence-negative-impls-copy.rs
@@ -0,0 +1,29 @@
+// check-pass
+// regression test for issue #101836
+
+#![feature(negative_impls, extern_types)]
+#![crate_type = "lib"]
+
+struct NonCopy;
+struct NeverCopy(NonCopy);
+
+impl !Copy for NeverCopy {}
+
+
+struct WithDrop;
+impl Drop for WithDrop { fn drop(&mut self) {} }
+
+impl !Copy for WithDrop {}
+
+
+struct Type;
+trait Trait {}
+extern {
+ type ExternType;
+}
+
+impl !Copy for &mut Type {}
+
+impl !Copy for dyn Trait {}
+
+impl !Copy for ExternType {}
diff --git a/src/test/ui/coherence/coherence-subtyping.stderr b/src/test/ui/coherence/coherence-subtyping.stderr
index 25d8c8756..9d90019a5 100644
--- a/src/test/ui/coherence/coherence-subtyping.stderr
+++ b/src/test/ui/coherence/coherence-subtyping.stderr
@@ -7,10 +7,10 @@ LL |
LL | impl TheTrait for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`
|
- = note: `#[warn(coherence_leak_check)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
+ = note: `#[warn(coherence_leak_check)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/coherence/coherence-wasm-bindgen.stderr b/src/test/ui/coherence/coherence-wasm-bindgen.stderr
index aa74e2315..cfcc21240 100644
--- a/src/test/ui/coherence/coherence-wasm-bindgen.stderr
+++ b/src/test/ui/coherence/coherence-wasm-bindgen.stderr
@@ -7,15 +7,15 @@ LL | impl<'a, 'b, A, R> IntoWasmAbi for &'a (dyn Fn(A) -> R + 'b)
LL | impl<'a, 'b, A, R> IntoWasmAbi for &'a (dyn for<'x> Fn(&'x A) -> R + 'b)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&dyn std::ops::Fn(&_) -> _`
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
+ = note: downstream crates may implement trait `FromWasmAbi` for type `&_`
+ = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
note: the lint level is defined here
--> $DIR/coherence-wasm-bindgen.rs:10:9
|
LL | #![deny(coherence_leak_check)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
- = note: downstream crates may implement trait `FromWasmAbi` for type `&_`
- = note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
error: aborting due to previous error
diff --git a/src/test/ui/coherence/deep-bad-copy-reason.stderr b/src/test/ui/coherence/deep-bad-copy-reason.stderr
index 295538cee..168ee5726 100644
--- a/src/test/ui/coherence/deep-bad-copy-reason.stderr
+++ b/src/test/ui/coherence/deep-bad-copy-reason.stderr
@@ -1,11 +1,11 @@
error[E0204]: the trait `Copy` may not be implemented for this type
- --> $DIR/deep-bad-copy-reason.rs:33:15
+ --> $DIR/deep-bad-copy-reason.rs:33:24
|
LL | pub struct List<'tcx, T>(Interned<'tcx, ListS<T>>);
| ------------------------ this field does not implement `Copy`
...
LL | impl<'tcx, T> Copy for List<'tcx, T> {}
- | ^^^^
+ | ^^^^^^^^^^^^^
|
note: the `Copy` impl for `Interned<'tcx, ListS<T>>` requires that `OpaqueListContents: Sized`
--> $DIR/deep-bad-copy-reason.rs:23:26
diff --git a/src/test/ui/command/command-current-dir.rs b/src/test/ui/command/command-current-dir.rs
index 69a0b486d..5d06fcdeb 100644
--- a/src/test/ui/command/command-current-dir.rs
+++ b/src/test/ui/command/command-current-dir.rs
@@ -1,6 +1,7 @@
// run-pass
// ignore-emscripten no processes
// ignore-sgx no processes
+// ignore-fuchsia Needs directory creation privilege
use std::env;
use std::fs;
diff --git a/src/test/ui/command/command-exec.rs b/src/test/ui/command/command-exec.rs
index 0af87214f..032dad184 100644
--- a/src/test/ui/command/command-exec.rs
+++ b/src/test/ui/command/command-exec.rs
@@ -5,6 +5,7 @@
// ignore-pretty issue #37199
// ignore-emscripten no processes
// ignore-sgx no processes
+// ignore-fuchsia no execvp syscall provided
#![feature(process_exec)]
diff --git a/src/test/ui/command/command-pre-exec.rs b/src/test/ui/command/command-pre-exec.rs
index 61914e229..d366c5ffb 100644
--- a/src/test/ui/command/command-pre-exec.rs
+++ b/src/test/ui/command/command-pre-exec.rs
@@ -6,6 +6,7 @@
// ignore-windows - this is a unix-specific test
// ignore-emscripten no processes
// ignore-sgx no processes
+// ignore-fuchsia no execvp syscall
#![feature(process_exec, rustc_private)]
extern crate libc;
diff --git a/src/test/ui/command/command-uid-gid.rs b/src/test/ui/command/command-uid-gid.rs
index e1eb4b140..aa4e2f5b8 100644
--- a/src/test/ui/command/command-uid-gid.rs
+++ b/src/test/ui/command/command-uid-gid.rs
@@ -2,6 +2,7 @@
// ignore-android
// ignore-emscripten
// ignore-sgx
+// ignore-fuchsia no '/bin/sh', '/bin/ls'
#![feature(rustc_private)]
diff --git a/src/test/ui/compare-method/issue-90444.stderr b/src/test/ui/compare-method/issue-90444.stderr
index 84bbec062..ee63f34b7 100644
--- a/src/test/ui/compare-method/issue-90444.stderr
+++ b/src/test/ui/compare-method/issue-90444.stderr
@@ -5,10 +5,10 @@ LL | fn from(_: fn((), (), &mut ())) -> Self {
| ^^^^^^^^^^^^^^^^^^^
| |
| types differ in mutability
- | help: change the parameter type to match the trait: `for<'r> fn((), (), &'r ())`
+ | help: change the parameter type to match the trait: `for<'a> fn((), (), &'a ())`
|
- = note: expected fn pointer `fn(for<'r> fn((), (), &'r ())) -> A`
- found fn pointer `fn(for<'r> fn((), (), &'r mut ())) -> A`
+ = note: expected fn pointer `fn(for<'a> fn((), (), &'a ())) -> A`
+ found fn pointer `fn(for<'a> fn((), (), &'a mut ())) -> A`
error[E0053]: method `from` has an incompatible type for trait
--> $DIR/issue-90444.rs:11:16
diff --git a/src/test/ui/conflicting-repr-hints.stderr b/src/test/ui/conflicting-repr-hints.stderr
index 0c7c50d67..4dcd8f4fc 100644
--- a/src/test/ui/conflicting-repr-hints.stderr
+++ b/src/test/ui/conflicting-repr-hints.stderr
@@ -4,9 +4,9 @@ error[E0566]: conflicting representation hints
LL | #[repr(C, u64)]
| ^ ^^^
|
- = note: `#[deny(conflicting_repr_hints)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
+ = note: `#[deny(conflicting_repr_hints)]` on by default
error[E0566]: conflicting representation hints
--> $DIR/conflicting-repr-hints.rs:19:8
diff --git a/src/test/ui/const-generics/const-generic-default-wont-borrowck.stderr b/src/test/ui/const-generics/const-generic-default-wont-borrowck.stderr
index c62f1d1d2..0ed370b83 100644
--- a/src/test/ui/const-generics/const-generic-default-wont-borrowck.stderr
+++ b/src/test/ui/const-generics/const-generic-default-wont-borrowck.stderr
@@ -5,6 +5,11 @@ LL | let s: &'static str; s.len()
| - ^^^^^^^ `*s` used here but it isn't initialized
| |
| binding declared here but left uninitialized
+ |
+help: consider assigning a value
+ |
+LL | let s: &'static str = todo!(); s.len()
+ | +++++++++
error: aborting due to previous error
diff --git a/src/test/ui/const-generics/const_trait_fn-issue-88433.rs b/src/test/ui/const-generics/const_trait_fn-issue-88433.rs
index 8724fa698..6e04cfaec 100644
--- a/src/test/ui/const-generics/const_trait_fn-issue-88433.rs
+++ b/src/test/ui/const-generics/const_trait_fn-issue-88433.rs
@@ -2,6 +2,7 @@
#![feature(const_trait_impl)]
+#[const_trait]
trait Func<T> {
type Output;
diff --git a/src/test/ui/const-generics/generic_const_exprs/closures.stderr b/src/test/ui/const-generics/generic_const_exprs/closures.stderr
index a15dd2016..a7d891d77 100644
--- a/src/test/ui/const-generics/generic_const_exprs/closures.stderr
+++ b/src/test/ui/const-generics/generic_const_exprs/closures.stderr
@@ -1,4 +1,4 @@
-error[E0391]: cycle detected when building an abstract representation for test::{constant#0}
+error[E0391]: cycle detected when building an abstract representation for `test::{constant#0}`
--> $DIR/closures.rs:3:35
|
LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
@@ -14,7 +14,7 @@ note: ...which requires type-checking `test::{constant#0}`...
|
LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
| ^^^^^^^^^^^^^
- = note: ...which again requires building an abstract representation for test::{constant#0}, completing the cycle
+ = note: ...which again requires building an abstract representation for `test::{constant#0}`, completing the cycle
note: cycle used when checking that `test` is well-formed
--> $DIR/closures.rs:3:1
|
diff --git a/src/test/ui/const-generics/generic_const_exprs/dependence_lint.full.stderr b/src/test/ui/const-generics/generic_const_exprs/dependence_lint.full.stderr
index 4cd86fecd..d674e3acd 100644
--- a/src/test/ui/const-generics/generic_const_exprs/dependence_lint.full.stderr
+++ b/src/test/ui/const-generics/generic_const_exprs/dependence_lint.full.stderr
@@ -1,5 +1,5 @@
error: generic parameters may not be used in const operations
- --> $DIR/dependence_lint.rs:13:32
+ --> $DIR/dependence_lint.rs:14:32
|
LL | let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce
| ^ cannot perform const operation using `T`
@@ -8,7 +8,7 @@ LL | let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
error: generic parameters may not be used in const operations
- --> $DIR/dependence_lint.rs:20:37
+ --> $DIR/dependence_lint.rs:21:37
|
LL | let _: [u8; if true { size_of::<T>() } else { 3 }]; // error on stable, error with gce
| ^ cannot perform const operation using `T`
@@ -17,17 +17,17 @@ LL | let _: [u8; if true { size_of::<T>() } else { 3 }]; // error on stable,
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
warning: cannot use constants which depend on generic parameters in types
- --> $DIR/dependence_lint.rs:9:9
+ --> $DIR/dependence_lint.rs:10:9
|
LL | [0; size_of::<*mut T>()]; // lint on stable, error with `generic_const_exprs`
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(const_evaluatable_unchecked)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
+ = note: `#[warn(const_evaluatable_unchecked)]` on by default
warning: cannot use constants which depend on generic parameters in types
- --> $DIR/dependence_lint.rs:16:9
+ --> $DIR/dependence_lint.rs:17:9
|
LL | [0; if false { size_of::<T>() } else { 3 }]; // lint on stable, error with gce
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/test/ui/const-generics/generic_const_exprs/dependence_lint.gce.stderr b/src/test/ui/const-generics/generic_const_exprs/dependence_lint.gce.stderr
index b13bcdb2c..74111ef1d 100644
--- a/src/test/ui/const-generics/generic_const_exprs/dependence_lint.gce.stderr
+++ b/src/test/ui/const-generics/generic_const_exprs/dependence_lint.gce.stderr
@@ -1,5 +1,5 @@
error: overly complex generic constant
- --> $DIR/dependence_lint.rs:16:9
+ --> $DIR/dependence_lint.rs:17:9
|
LL | [0; if false { size_of::<T>() } else { 3 }]; // lint on stable, error with gce
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ control flow is not supported in generic constants
@@ -7,7 +7,7 @@ LL | [0; if false { size_of::<T>() } else { 3 }]; // lint on stable, error w
= help: consider moving this anonymous constant into a `const` function
error: overly complex generic constant
- --> $DIR/dependence_lint.rs:20:17
+ --> $DIR/dependence_lint.rs:21:17
|
LL | let _: [u8; if true { size_of::<T>() } else { 3 }]; // error on stable, error with gce
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ control flow is not supported in generic constants
@@ -15,7 +15,7 @@ LL | let _: [u8; if true { size_of::<T>() } else { 3 }]; // error on stable,
= help: consider moving this anonymous constant into a `const` function
error: unconstrained generic constant
- --> $DIR/dependence_lint.rs:13:12
+ --> $DIR/dependence_lint.rs:14:12
|
LL | let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -23,7 +23,7 @@ LL | let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce
= help: try adding a `where` bound using this expression: `where [(); size_of::<*mut T>()]:`
error: unconstrained generic constant
- --> $DIR/dependence_lint.rs:9:9
+ --> $DIR/dependence_lint.rs:10:9
|
LL | [0; size_of::<*mut T>()]; // lint on stable, error with `generic_const_exprs`
| ^^^^^^^^^^^^^^^^^^^
diff --git a/src/test/ui/const-generics/generic_const_exprs/dependence_lint.rs b/src/test/ui/const-generics/generic_const_exprs/dependence_lint.rs
index dcdfd75de..b715e07f8 100644
--- a/src/test/ui/const-generics/generic_const_exprs/dependence_lint.rs
+++ b/src/test/ui/const-generics/generic_const_exprs/dependence_lint.rs
@@ -1,4 +1,5 @@
// revisions: full gce
+// compile-flags: -Zdeduplicate-diagnostics=yes
#![cfg_attr(gce, feature(generic_const_exprs))]
#![allow(incomplete_features)]
diff --git a/src/test/ui/const-generics/generic_const_exprs/eval-try-unify.stderr b/src/test/ui/const-generics/generic_const_exprs/eval-try-unify.stderr
index b5719b3fe..8eb1fccc5 100644
--- a/src/test/ui/const-generics/generic_const_exprs/eval-try-unify.stderr
+++ b/src/test/ui/const-generics/generic_const_exprs/eval-try-unify.stderr
@@ -4,8 +4,8 @@ warning: the feature `generic_const_exprs` is incomplete and may not be safe to
LL | #![feature(generic_const_exprs)]
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/const-generics/generic_const_exprs/function-call.rs b/src/test/ui/const-generics/generic_const_exprs/function-call.rs
index b5de66621..3c866333d 100644
--- a/src/test/ui/const-generics/generic_const_exprs/function-call.rs
+++ b/src/test/ui/const-generics/generic_const_exprs/function-call.rs
@@ -1,4 +1,5 @@
// check-pass
+// compile-flags: -Zdeduplicate-diagnostics=yes
const fn foo<T>() -> usize {
// We might instead branch on `std::mem::size_of::<*mut T>() < 8` here,
diff --git a/src/test/ui/const-generics/generic_const_exprs/function-call.stderr b/src/test/ui/const-generics/generic_const_exprs/function-call.stderr
index 0d8463714..84abfe578 100644
--- a/src/test/ui/const-generics/generic_const_exprs/function-call.stderr
+++ b/src/test/ui/const-generics/generic_const_exprs/function-call.stderr
@@ -1,12 +1,12 @@
warning: cannot use constants which depend on generic parameters in types
- --> $DIR/function-call.rs:14:17
+ --> $DIR/function-call.rs:15:17
|
LL | let _ = [0; foo::<T>()];
| ^^^^^^^^^^
|
- = note: `#[warn(const_evaluatable_unchecked)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
+ = note: `#[warn(const_evaluatable_unchecked)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-102074.rs b/src/test/ui/const-generics/generic_const_exprs/issue-102074.rs
new file mode 100644
index 000000000..66d15cf12
--- /dev/null
+++ b/src/test/ui/const-generics/generic_const_exprs/issue-102074.rs
@@ -0,0 +1,23 @@
+// check-pass
+// Checks that the NoopMethodCall lint doesn't call Instance::resolve on unresolved consts
+
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+#[derive(Debug, Clone)]
+pub struct Aes128CipherKey([u8; Aes128Cipher::KEY_LEN]);
+
+impl Aes128CipherKey {
+ pub fn new(key: &[u8; Aes128Cipher::KEY_LEN]) -> Self {
+ Self(key.clone())
+ }
+}
+
+#[derive(Debug, Clone)]
+pub struct Aes128Cipher;
+
+impl Aes128Cipher {
+ const KEY_LEN: usize = 16;
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-102768.rs b/src/test/ui/const-generics/generic_const_exprs/issue-102768.rs
new file mode 100644
index 000000000..7aea0d30d
--- /dev/null
+++ b/src/test/ui/const-generics/generic_const_exprs/issue-102768.rs
@@ -0,0 +1,14 @@
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+trait X {
+ type Y<'a>;
+}
+
+const _: () = {
+ fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
+ //~^ ERROR this associated type takes 1 lifetime argument but 0 lifetime arguments
+ //~| ERROR this associated type takes 0 generic arguments but 1 generic argument
+};
+
+fn main() {}
diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-102768.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-102768.stderr
new file mode 100644
index 000000000..9deb9b265
--- /dev/null
+++ b/src/test/ui/const-generics/generic_const_exprs/issue-102768.stderr
@@ -0,0 +1,33 @@
+error[E0107]: this associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
+ --> $DIR/issue-102768.rs:9:30
+ |
+LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
+ | ^ expected 1 lifetime argument
+ |
+note: associated type defined here, with 1 lifetime parameter: `'a`
+ --> $DIR/issue-102768.rs:5:10
+ |
+LL | type Y<'a>;
+ | ^ --
+help: add missing lifetime argument
+ |
+LL | fn f2<'a>(arg: Box<dyn X<Y<'a, 1> = &'a ()>>) {}
+ | +++
+
+error[E0107]: this associated type takes 0 generic arguments but 1 generic argument was supplied
+ --> $DIR/issue-102768.rs:9:30
+ |
+LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
+ | ^--- help: remove these generics
+ | |
+ | expected 0 generic arguments
+ |
+note: associated type defined here, with 0 generic parameters
+ --> $DIR/issue-102768.rs:5:10
+ |
+LL | type Y<'a>;
+ | ^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0107`.
diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-97047-ice-1.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-97047-ice-1.stderr
index b5b2b0e40..1cceaece7 100644
--- a/src/test/ui/const-generics/generic_const_exprs/issue-97047-ice-1.stderr
+++ b/src/test/ui/const-generics/generic_const_exprs/issue-97047-ice-1.stderr
@@ -4,8 +4,8 @@ warning: the feature `adt_const_params` is incomplete and may not be safe to use
LL | #![feature(adt_const_params, generic_const_exprs)]
| ^^^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
+ = note: `#[warn(incomplete_features)]` on by default
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/issue-97047-ice-1.rs:3:30
diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-97047-ice-2.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-97047-ice-2.stderr
index 5dfbd87cc..774e842bc 100644
--- a/src/test/ui/const-generics/generic_const_exprs/issue-97047-ice-2.stderr
+++ b/src/test/ui/const-generics/generic_const_exprs/issue-97047-ice-2.stderr
@@ -4,8 +4,8 @@ warning: the feature `adt_const_params` is incomplete and may not be safe to use
LL | #![feature(adt_const_params, generic_const_exprs)]
| ^^^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
+ = note: `#[warn(incomplete_features)]` on by default
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/issue-97047-ice-2.rs:3:30
diff --git a/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.stderr b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.stderr
index 45c7d835f..440cf457e 100644
--- a/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.stderr
+++ b/src/test/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.stderr
@@ -4,11 +4,6 @@ error: the trait `Foo` cannot be made into an object
LL | fn test(&self) where [u8; bar::<Self>()]: Sized;
| ^^^^
|
-note: the lint level is defined here
- --> $DIR/object-safety-err-where-bounds.rs:3:9
- |
-LL | #![deny(where_clauses_object_safety)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443>
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
@@ -19,6 +14,11 @@ LL | trait Foo {
LL | fn test(&self) where [u8; bar::<Self>()]: Sized;
| ^^^^ ...because method `test` references the `Self` type in its `where` clause
= help: consider moving `test` to another trait
+note: the lint level is defined here
+ --> $DIR/object-safety-err-where-bounds.rs:3:9
+ |
+LL | #![deny(where_clauses_object_safety)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/const-generics/invariant.stderr b/src/test/ui/const-generics/invariant.stderr
index ce0fad104..aabe4c93b 100644
--- a/src/test/ui/const-generics/invariant.stderr
+++ b/src/test/ui/const-generics/invariant.stderr
@@ -7,10 +7,10 @@ LL | impl SadBee for for<'a> fn(&'a ()) {
LL | impl SadBee for fn(&'static ()) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a> fn(&'a ())`
|
- = note: `#[warn(coherence_leak_check)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
+ = note: `#[warn(coherence_leak_check)]` on by default
error[E0308]: mismatched types
--> $DIR/invariant.rs:27:5
diff --git a/src/test/ui/const-generics/issue-102124.rs b/src/test/ui/const-generics/issue-102124.rs
new file mode 100644
index 000000000..a28f198e9
--- /dev/null
+++ b/src/test/ui/const-generics/issue-102124.rs
@@ -0,0 +1,20 @@
+// run-pass
+// compile-flags: -Zmir-opt-level=3
+
+// regression test for #102124
+
+const L: usize = 4;
+
+pub trait Print<const N: usize> {
+ fn print(&self) -> usize {
+ N
+ }
+}
+
+pub struct Printer;
+impl Print<L> for Printer {}
+
+fn main() {
+ let p = Printer;
+ assert_eq!(p.print(), 4);
+}
diff --git a/src/test/ui/const-generics/issue-103243.rs b/src/test/ui/const-generics/issue-103243.rs
deleted file mode 100644
index 78c73522b..000000000
--- a/src/test/ui/const-generics/issue-103243.rs
+++ /dev/null
@@ -1,37 +0,0 @@
-// build-pass
-
-pub trait CSpace<const N: usize>: Sized {
- type Traj;
-}
-
-pub trait FullTrajectory<T, S1, const N: usize> {}
-
-pub struct Const<const R: usize>;
-
-pub trait Obstacle<CS, const N: usize>
-where
- CS: CSpace<N>,
-{
- fn trajectory_free<FT, S1>(&self, t: &FT)
- where
- FT: FullTrajectory<CS::Traj, S1, N>;
-}
-
-// -----
-
-const N: usize = 4;
-
-struct ObstacleSpace2df32;
-
-impl<CS> Obstacle<CS, N> for ObstacleSpace2df32
-where
- CS: CSpace<N>,
-{
- fn trajectory_free<TF, S1>(&self, t: &TF)
- where
- TF: FullTrajectory<CS::Traj, S1, N>,
- {
- }
-}
-
-fn main() {}
diff --git a/src/test/ui/const-generics/issue-80471.stderr b/src/test/ui/const-generics/issue-80471.stderr
index dbcc0b7b6..b89706710 100644
--- a/src/test/ui/const-generics/issue-80471.stderr
+++ b/src/test/ui/const-generics/issue-80471.stderr
@@ -4,8 +4,8 @@ warning: the feature `adt_const_params` is incomplete and may not be safe to use
LL | #![feature(adt_const_params)]
| ^^^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error[E0741]: `Box<Nat>` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter
--> $DIR/issue-80471.rs:10:17
diff --git a/src/test/ui/const-generics/issue-93647.rs b/src/test/ui/const-generics/issue-93647.rs
index c1a6bf6e3..806540e17 100644
--- a/src/test/ui/const-generics/issue-93647.rs
+++ b/src/test/ui/const-generics/issue-93647.rs
@@ -1,6 +1,6 @@
struct X<const N: usize = {
(||1usize)()
- //~^ ERROR cannot call
+ //~^ ERROR cannot call non-const closure
}>;
fn main() {}
diff --git a/src/test/ui/const-generics/issues/issue-83466.stderr b/src/test/ui/const-generics/issues/issue-83466.stderr
index a60f71ea6..bcfd70639 100644
--- a/src/test/ui/const-generics/issues/issue-83466.stderr
+++ b/src/test/ui/const-generics/issues/issue-83466.stderr
@@ -7,9 +7,9 @@ LL | fn func<'a, U>(self) -> U {
LL | S.func::<'a, 10_u32>()
| ^^
|
- = note: `#[warn(late_bound_lifetime_arguments)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
+ = note: `#[warn(late_bound_lifetime_arguments)]` on by default
error[E0747]: constant provided when a type was expected
--> $DIR/issue-83466.rs:11:18
diff --git a/src/test/ui/const-generics/issues/issue-83765.stderr b/src/test/ui/const-generics/issues/issue-83765.stderr
index d5f914f46..4becf3a36 100644
--- a/src/test/ui/const-generics/issues/issue-83765.stderr
+++ b/src/test/ui/const-generics/issues/issue-83765.stderr
@@ -1,16 +1,16 @@
-error[E0391]: cycle detected when resolving instance `<LazyUpdim<T, { T::DIM }, DIM> as TensorDimension>::DIM`
+error[E0391]: cycle detected when resolving instance `<LazyUpdim<'_, T, { T::DIM }, DIM> as TensorDimension>::DIM`
--> $DIR/issue-83765.rs:5:5
|
LL | const DIM: usize;
| ^^^^^^^^^^^^^^^^
|
-note: ...which requires computing candidate for `<LazyUpdim<T, { T::DIM }, DIM> as TensorDimension>`...
+note: ...which requires computing candidate for `<LazyUpdim<'_, T, { T::DIM }, DIM> as TensorDimension>`...
--> $DIR/issue-83765.rs:4:1
|
LL | trait TensorDimension {
| ^^^^^^^^^^^^^^^^^^^^^
- = note: ...which again requires resolving instance `<LazyUpdim<T, { T::DIM }, DIM> as TensorDimension>::DIM`, completing the cycle
-note: cycle used when computing candidate for `<LazyUpdim<T, { T::DIM }, DIM> as TensorDimension>`
+ = note: ...which again requires resolving instance `<LazyUpdim<'_, T, { T::DIM }, DIM> as TensorDimension>::DIM`, completing the cycle
+note: cycle used when computing candidate for `<LazyUpdim<'_, T, { T::DIM }, DIM> as TensorDimension>`
--> $DIR/issue-83765.rs:4:1
|
LL | trait TensorDimension {
diff --git a/src/test/ui/const-generics/issues/issue-88119.rs b/src/test/ui/const-generics/issues/issue-88119.rs
index 70dfa7f70..647b0eea8 100644
--- a/src/test/ui/const-generics/issues/issue-88119.rs
+++ b/src/test/ui/const-generics/issues/issue-88119.rs
@@ -3,6 +3,7 @@
#![allow(incomplete_features)]
#![feature(const_trait_impl, generic_const_exprs)]
+#[const_trait]
trait ConstName {
const NAME_BYTES: &'static [u8];
}
diff --git a/src/test/ui/const-generics/issues/issue-98629.rs b/src/test/ui/const-generics/issues/issue-98629.rs
index fc8666bbc..1d2d3012a 100644
--- a/src/test/ui/const-generics/issues/issue-98629.rs
+++ b/src/test/ui/const-generics/issues/issue-98629.rs
@@ -1,5 +1,6 @@
#![feature(const_trait_impl)]
+#[const_trait]
trait Trait {
const N: usize;
}
diff --git a/src/test/ui/const-generics/issues/issue-98629.stderr b/src/test/ui/const-generics/issues/issue-98629.stderr
index 535702208..4a248be76 100644
--- a/src/test/ui/const-generics/issues/issue-98629.stderr
+++ b/src/test/ui/const-generics/issues/issue-98629.stderr
@@ -1,5 +1,5 @@
error[E0046]: not all trait items implemented, missing: `N`
- --> $DIR/issue-98629.rs:7:1
+ --> $DIR/issue-98629.rs:8:1
|
LL | const N: usize;
| -------------- `N` from trait
diff --git a/src/test/ui/const-generics/min_const_generics/complex-expression.rs b/src/test/ui/const-generics/min_const_generics/complex-expression.rs
index 7840989cb..8e667aeba 100644
--- a/src/test/ui/const-generics/min_const_generics/complex-expression.rs
+++ b/src/test/ui/const-generics/min_const_generics/complex-expression.rs
@@ -1,3 +1,4 @@
+// compile-flags: -Zdeduplicate-diagnostics=yes
use std::mem::size_of;
fn test<const N: usize>() {}
diff --git a/src/test/ui/const-generics/min_const_generics/complex-expression.stderr b/src/test/ui/const-generics/min_const_generics/complex-expression.stderr
index bf0d0f352..deabd05a6 100644
--- a/src/test/ui/const-generics/min_const_generics/complex-expression.stderr
+++ b/src/test/ui/const-generics/min_const_generics/complex-expression.stderr
@@ -1,5 +1,5 @@
error: generic parameters may not be used in const operations
- --> $DIR/complex-expression.rs:9:38
+ --> $DIR/complex-expression.rs:10:38
|
LL | struct Break0<const N: usize>([u8; { N + 1 }]);
| ^ cannot perform const operation using `N`
@@ -8,7 +8,7 @@ LL | struct Break0<const N: usize>([u8; { N + 1 }]);
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
error: generic parameters may not be used in const operations
- --> $DIR/complex-expression.rs:12:40
+ --> $DIR/complex-expression.rs:13:40
|
LL | struct Break1<const N: usize>([u8; { { N } }]);
| ^ cannot perform const operation using `N`
@@ -17,7 +17,7 @@ LL | struct Break1<const N: usize>([u8; { { N } }]);
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
error: generic parameters may not be used in const operations
- --> $DIR/complex-expression.rs:16:17
+ --> $DIR/complex-expression.rs:17:17
|
LL | let _: [u8; N + 1];
| ^ cannot perform const operation using `N`
@@ -26,7 +26,7 @@ LL | let _: [u8; N + 1];
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
error: generic parameters may not be used in const operations
- --> $DIR/complex-expression.rs:21:17
+ --> $DIR/complex-expression.rs:22:17
|
LL | let _ = [0; N + 1];
| ^ cannot perform const operation using `N`
@@ -35,7 +35,7 @@ LL | let _ = [0; N + 1];
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
error: generic parameters may not be used in const operations
- --> $DIR/complex-expression.rs:25:45
+ --> $DIR/complex-expression.rs:26:45
|
LL | struct BreakTy0<T>(T, [u8; { size_of::<*mut T>() }]);
| ^ cannot perform const operation using `T`
@@ -44,7 +44,7 @@ LL | struct BreakTy0<T>(T, [u8; { size_of::<*mut T>() }]);
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
error: generic parameters may not be used in const operations
- --> $DIR/complex-expression.rs:28:47
+ --> $DIR/complex-expression.rs:29:47
|
LL | struct BreakTy1<T>(T, [u8; { { size_of::<*mut T>() } }]);
| ^ cannot perform const operation using `T`
@@ -53,7 +53,7 @@ LL | struct BreakTy1<T>(T, [u8; { { size_of::<*mut T>() } }]);
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
error: generic parameters may not be used in const operations
- --> $DIR/complex-expression.rs:32:32
+ --> $DIR/complex-expression.rs:33:32
|
LL | let _: [u8; size_of::<*mut T>() + 1];
| ^ cannot perform const operation using `T`
@@ -62,14 +62,14 @@ LL | let _: [u8; size_of::<*mut T>() + 1];
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
warning: cannot use constants which depend on generic parameters in types
- --> $DIR/complex-expression.rs:37:17
+ --> $DIR/complex-expression.rs:38:17
|
LL | let _ = [0; size_of::<*mut T>() + 1];
| ^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(const_evaluatable_unchecked)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
+ = note: `#[warn(const_evaluatable_unchecked)]` on by default
error: aborting due to 7 previous errors; 1 warning emitted
diff --git a/src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.rs b/src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.rs
index 71d13ca61..e9d868093 100644
--- a/src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.rs
+++ b/src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.rs
@@ -1,4 +1,5 @@
// check-pass
+// compile-flags: -Zdeduplicate-diagnostics=yes
#![allow(dead_code)]
fn foo<T>() {
diff --git a/src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.stderr b/src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.stderr
index f9f6660f6..8003dfa40 100644
--- a/src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.stderr
+++ b/src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.stderr
@@ -1,15 +1,15 @@
warning: cannot use constants which depend on generic parameters in types
- --> $DIR/const-evaluatable-unchecked.rs:5:9
+ --> $DIR/const-evaluatable-unchecked.rs:6:9
|
LL | [0; std::mem::size_of::<*mut T>()];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(const_evaluatable_unchecked)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
+ = note: `#[warn(const_evaluatable_unchecked)]` on by default
warning: cannot use constants which depend on generic parameters in types
- --> $DIR/const-evaluatable-unchecked.rs:16:21
+ --> $DIR/const-evaluatable-unchecked.rs:17:21
|
LL | let _ = [0; Self::ASSOC];
| ^^^^^^^^^^^
@@ -18,7 +18,7 @@ LL | let _ = [0; Self::ASSOC];
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
warning: cannot use constants which depend on generic parameters in types
- --> $DIR/const-evaluatable-unchecked.rs:28:21
+ --> $DIR/const-evaluatable-unchecked.rs:29:21
|
LL | let _ = [0; Self::ASSOC];
| ^^^^^^^^^^^
diff --git a/src/test/ui/const-generics/occurs-check/unify-fixpoint.stderr b/src/test/ui/const-generics/occurs-check/unify-fixpoint.stderr
index f9b56bd38..fe3f24a67 100644
--- a/src/test/ui/const-generics/occurs-check/unify-fixpoint.stderr
+++ b/src/test/ui/const-generics/occurs-check/unify-fixpoint.stderr
@@ -4,8 +4,8 @@ warning: the feature `generic_const_exprs` is incomplete and may not be safe to
LL | #![feature(generic_const_exprs)]
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-2.rs b/src/test/ui/const-generics/occurs-check/unused-substs-2.rs
index 9a73f1a53..9b1212694 100644
--- a/src/test/ui/const-generics/occurs-check/unused-substs-2.rs
+++ b/src/test/ui/const-generics/occurs-check/unused-substs-2.rs
@@ -1,7 +1,7 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
-// The goal is is to get an unevaluated const `ct` with a `Ty::Infer(TyVar(_#1t)` subst.
+// The goal is to get an unevaluated const `ct` with a `Ty::Infer(TyVar(_#1t)` subst.
//
// If we are then able to infer `ty::Infer(TyVar(_#1t) := Ty<ct>` we introduced an
// artificial inference cycle.
diff --git a/src/test/ui/const-generics/occurs-check/unused-substs-3.rs b/src/test/ui/const-generics/occurs-check/unused-substs-3.rs
index 0d38bd393..d5aeab47e 100644
--- a/src/test/ui/const-generics/occurs-check/unused-substs-3.rs
+++ b/src/test/ui/const-generics/occurs-check/unused-substs-3.rs
@@ -1,7 +1,7 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]
-// The goal is is to get an unevaluated const `ct` with a `Ty::Infer(TyVar(_#1t)` subst.
+// The goal is to get an unevaluated const `ct` with a `Ty::Infer(TyVar(_#1t)` subst.
//
// If we are then able to infer `ty::Infer(TyVar(_#1t) := Ty<ct>` we introduced an
// artificial inference cycle.
diff --git a/src/test/ui/const-ptr/forbidden_slices.32bit.stderr b/src/test/ui/const-ptr/forbidden_slices.32bit.stderr
index 82a3c92e6..8978ab436 100644
--- a/src/test/ui/const-ptr/forbidden_slices.32bit.stderr
+++ b/src/test/ui/const-ptr/forbidden_slices.32bit.stderr
@@ -5,7 +5,7 @@ LL | &*ptr::slice_from_raw_parts(data, len)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| dereferencing pointer failed: null pointer is a dangling pointer (it has no provenance)
- | inside `std::slice::from_raw_parts::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | inside `std::slice::from_raw_parts::<'_, u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:18:34
|
@@ -19,7 +19,7 @@ LL | &*ptr::slice_from_raw_parts(data, len)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| dereferencing pointer failed: null pointer is a dangling pointer (it has no provenance)
- | inside `std::slice::from_raw_parts::<()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | inside `std::slice::from_raw_parts::<'_, ()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:19:33
|
@@ -33,7 +33,7 @@ LL | &*ptr::slice_from_raw_parts(data, len)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| dereferencing pointer failed: ALLOC_ID has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds
- | inside `std::slice::from_raw_parts::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | inside `std::slice::from_raw_parts::<'_, u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:22:34
|
@@ -92,7 +92,7 @@ LL | &*ptr::slice_from_raw_parts(data, len)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| dereferencing pointer failed: ALLOC_ID has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds
- | inside `std::slice::from_raw_parts::<u64>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | inside `std::slice::from_raw_parts::<'_, u64>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:43:5
|
@@ -111,7 +111,7 @@ LL | unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
LL | unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
- | ------------------------------ inside `from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | ------------------------------ inside `from_ptr_range::<'_, u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:46:34
|
@@ -130,7 +130,7 @@ LL | assert!(0 < pointee_size && pointee_size <= isize::MAX as usize);
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
LL | unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
- | ------------------------------ inside `from_ptr_range::<()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | ------------------------------ inside `from_ptr_range::<'_, ()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:47:33
|
@@ -230,7 +230,7 @@ LL | unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
LL | unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
- | ------------------------------ inside `from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | ------------------------------ inside `from_ptr_range::<'_, u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:79:34
|
@@ -249,7 +249,7 @@ LL | unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
LL | unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
- | ------------------------------ inside `from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | ------------------------------ inside `from_ptr_range::<'_, u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:80:35
|
diff --git a/src/test/ui/const-ptr/forbidden_slices.64bit.stderr b/src/test/ui/const-ptr/forbidden_slices.64bit.stderr
index f88746af9..db42b7c98 100644
--- a/src/test/ui/const-ptr/forbidden_slices.64bit.stderr
+++ b/src/test/ui/const-ptr/forbidden_slices.64bit.stderr
@@ -5,7 +5,7 @@ LL | &*ptr::slice_from_raw_parts(data, len)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| dereferencing pointer failed: null pointer is a dangling pointer (it has no provenance)
- | inside `std::slice::from_raw_parts::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | inside `std::slice::from_raw_parts::<'_, u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:18:34
|
@@ -19,7 +19,7 @@ LL | &*ptr::slice_from_raw_parts(data, len)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| dereferencing pointer failed: null pointer is a dangling pointer (it has no provenance)
- | inside `std::slice::from_raw_parts::<()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | inside `std::slice::from_raw_parts::<'_, ()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:19:33
|
@@ -33,7 +33,7 @@ LL | &*ptr::slice_from_raw_parts(data, len)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| dereferencing pointer failed: ALLOC_ID has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds
- | inside `std::slice::from_raw_parts::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | inside `std::slice::from_raw_parts::<'_, u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:22:34
|
@@ -92,7 +92,7 @@ LL | &*ptr::slice_from_raw_parts(data, len)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| dereferencing pointer failed: ALLOC_ID has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds
- | inside `std::slice::from_raw_parts::<u64>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | inside `std::slice::from_raw_parts::<'_, u64>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:43:5
|
@@ -111,7 +111,7 @@ LL | unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
LL | unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
- | ------------------------------ inside `from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | ------------------------------ inside `from_ptr_range::<'_, u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:46:34
|
@@ -130,7 +130,7 @@ LL | assert!(0 < pointee_size && pointee_size <= isize::MAX as usize);
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
LL | unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
- | ------------------------------ inside `from_ptr_range::<()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | ------------------------------ inside `from_ptr_range::<'_, ()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:47:33
|
@@ -230,7 +230,7 @@ LL | unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
LL | unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
- | ------------------------------ inside `from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | ------------------------------ inside `from_ptr_range::<'_, u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:79:34
|
@@ -249,7 +249,7 @@ LL | unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
LL | unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
- | ------------------------------ inside `from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+ | ------------------------------ inside `from_ptr_range::<'_, u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
|
::: $DIR/forbidden_slices.rs:80:35
|
diff --git a/src/test/ui/const_prop/issue-102553.rs b/src/test/ui/const_prop/issue-102553.rs
new file mode 100644
index 000000000..523a9d7ac
--- /dev/null
+++ b/src/test/ui/const_prop/issue-102553.rs
@@ -0,0 +1,24 @@
+// compile-flags: --crate-type=lib
+// check-pass
+
+pub trait Widget<E> {
+ fn boxed<'w>(self) -> Box<dyn WidgetDyn<E> + 'w>
+ where
+ Self: Sized + 'w;
+}
+
+pub trait WidgetDyn<E> {}
+
+impl<T, E> WidgetDyn<E> for T where T: Widget<E> {}
+
+impl<E> Widget<E> for dyn WidgetDyn<E> + '_ {
+ fn boxed<'w>(self) -> Box<dyn WidgetDyn<E> + 'w>
+ where
+ Self: Sized + 'w,
+ {
+ // Even though this is illegal to const evaluate, this should never
+ // trigger an ICE because it can never be called from actual code
+ // (due to the trivially false where-clause predicate).
+ Box::new(self)
+ }
+}
diff --git a/src/test/ui/consts/array-literal-index-oob.rs b/src/test/ui/consts/array-literal-index-oob.rs
index 9b3f735b1..67b49b1ba 100644
--- a/src/test/ui/consts/array-literal-index-oob.rs
+++ b/src/test/ui/consts/array-literal-index-oob.rs
@@ -1,7 +1,7 @@
// build-pass
// ignore-pass (test emits codegen-time warnings and verifies that they are not errors)
-#![warn(const_err, unconditional_panic)]
+#![warn(unconditional_panic)]
fn main() {
&{ [1, 2, 3][4] };
diff --git a/src/test/ui/consts/array-literal-index-oob.stderr b/src/test/ui/consts/array-literal-index-oob.stderr
index f96b8d48b..54bf3af81 100644
--- a/src/test/ui/consts/array-literal-index-oob.stderr
+++ b/src/test/ui/consts/array-literal-index-oob.stderr
@@ -5,10 +5,10 @@ LL | &{ [1, 2, 3][4] };
| ^^^^^^^^^^^^ index out of bounds: the length is 3 but the index is 4
|
note: the lint level is defined here
- --> $DIR/array-literal-index-oob.rs:4:20
+ --> $DIR/array-literal-index-oob.rs:4:9
|
-LL | #![warn(const_err, unconditional_panic)]
- | ^^^^^^^^^^^^^^^^^^^
+LL | #![warn(unconditional_panic)]
+ | ^^^^^^^^^^^^^^^^^^^
warning: 1 warning emitted
diff --git a/src/test/ui/consts/assert-type-intrinsics.rs b/src/test/ui/consts/assert-type-intrinsics.rs
index 3ce3e1bdb..263d1ae6a 100644
--- a/src/test/ui/consts/assert-type-intrinsics.rs
+++ b/src/test/ui/consts/assert-type-intrinsics.rs
@@ -1,5 +1,3 @@
-// error-pattern: any use of this value will cause an error
-
#![feature(never_type)]
#![feature(const_assert_type2)]
#![feature(core_intrinsics)]
@@ -12,11 +10,14 @@ fn main() {
const _BAD1: () = unsafe {
MaybeUninit::<!>::uninit().assume_init();
+ //~^ERROR: evaluation of constant value failed
};
const _BAD2: () = {
- intrinsics::assert_uninit_valid::<bool>();
+ intrinsics::assert_uninit_valid::<&'static i32>();
+ //~^ERROR: evaluation of constant value failed
};
const _BAD3: () = {
intrinsics::assert_zero_valid::<&'static i32>();
+ //~^ERROR: evaluation of constant value failed
};
}
diff --git a/src/test/ui/consts/assert-type-intrinsics.stderr b/src/test/ui/consts/assert-type-intrinsics.stderr
index 6eab10197..f92f9fda0 100644
--- a/src/test/ui/consts/assert-type-intrinsics.stderr
+++ b/src/test/ui/consts/assert-type-intrinsics.stderr
@@ -1,75 +1,21 @@
-error: any use of this value will cause an error
- --> $DIR/assert-type-intrinsics.rs:14:9
+error[E0080]: evaluation of constant value failed
+ --> $DIR/assert-type-intrinsics.rs:12:9
|
-LL | const _BAD1: () = unsafe {
- | ---------------
LL | MaybeUninit::<!>::uninit().assume_init();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to instantiate uninhabited type `!`
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/assert-type-intrinsics.rs:17:9
- |
-LL | const _BAD2: () = {
- | ---------------
-LL | intrinsics::assert_uninit_valid::<bool>();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `bool` uninitialized, which is invalid
+error[E0080]: evaluation of constant value failed
+ --> $DIR/assert-type-intrinsics.rs:16:9
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+LL | intrinsics::assert_uninit_valid::<&'static i32>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `&i32` uninitialized, which is invalid
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/assert-type-intrinsics.rs:20:9
|
-LL | const _BAD3: () = {
- | ---------------
LL | intrinsics::assert_zero_valid::<&'static i32>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to zero-initialize type `&i32`, which is invalid
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: aborting due to 3 previous errors
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/assert-type-intrinsics.rs:14:9
- |
-LL | const _BAD1: () = unsafe {
- | ---------------
-LL | MaybeUninit::<!>::uninit().assume_init();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to instantiate uninhabited type `!`
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/assert-type-intrinsics.rs:17:9
- |
-LL | const _BAD2: () = {
- | ---------------
-LL | intrinsics::assert_uninit_valid::<bool>();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `bool` uninitialized, which is invalid
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/assert-type-intrinsics.rs:20:9
- |
-LL | const _BAD3: () = {
- | ---------------
-LL | intrinsics::assert_zero_valid::<&'static i32>();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to zero-initialize type `&i32`, which is invalid
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/assoc_const_generic_impl.rs b/src/test/ui/consts/assoc_const_generic_impl.rs
index 71d947b0c..3475c862b 100644
--- a/src/test/ui/consts/assoc_const_generic_impl.rs
+++ b/src/test/ui/consts/assoc_const_generic_impl.rs
@@ -1,17 +1,14 @@
// build-fail
-#![warn(const_err)]
-
trait ZeroSized: Sized {
const I_AM_ZERO_SIZED: ();
fn requires_zero_size(self);
}
impl<T: Sized> ZeroSized for T {
- const I_AM_ZERO_SIZED: () = [()][std::mem::size_of::<Self>()]; //~ WARN any use of this value
- //~| WARN this was previously accepted by the compiler but is being phased out
+ const I_AM_ZERO_SIZED: () = [()][std::mem::size_of::<Self>()]; //~ ERROR evaluation of `<u32 as ZeroSized>::I_AM_ZERO_SIZED` failed
fn requires_zero_size(self) {
- let () = Self::I_AM_ZERO_SIZED; //~ ERROR erroneous constant encountered
+ let () = Self::I_AM_ZERO_SIZED;
println!("requires_zero_size called");
}
}
diff --git a/src/test/ui/consts/assoc_const_generic_impl.stderr b/src/test/ui/consts/assoc_const_generic_impl.stderr
index 17cbaef1f..854b9ce5b 100644
--- a/src/test/ui/consts/assoc_const_generic_impl.stderr
+++ b/src/test/ui/consts/assoc_const_generic_impl.stderr
@@ -1,37 +1,15 @@
-warning: any use of this value will cause an error
- --> $DIR/assoc_const_generic_impl.rs:11:34
+error[E0080]: evaluation of `<u32 as ZeroSized>::I_AM_ZERO_SIZED` failed
+ --> $DIR/assoc_const_generic_impl.rs:9:34
|
LL | const I_AM_ZERO_SIZED: () = [()][std::mem::size_of::<Self>()];
- | ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 4
- |
-note: the lint level is defined here
- --> $DIR/assoc_const_generic_impl.rs:3:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 4
-error: erroneous constant encountered
- --> $DIR/assoc_const_generic_impl.rs:14:18
+note: the above error was encountered while instantiating `fn <u32 as ZeroSized>::requires_zero_size`
+ --> $DIR/assoc_const_generic_impl.rs:18:5
|
-LL | let () = Self::I_AM_ZERO_SIZED;
- | ^^^^^^^^^^^^^^^^^^^^^
+LL | 42_u32.requires_zero_size();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to previous error; 1 warning emitted
-
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/assoc_const_generic_impl.rs:11:34
- |
-LL | const I_AM_ZERO_SIZED: () = [()][std::mem::size_of::<Self>()];
- | ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 4
- |
-note: the lint level is defined here
- --> $DIR/assoc_const_generic_impl.rs:3:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+error: aborting due to previous error
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/cast-discriminant-zst-enum.rs b/src/test/ui/consts/cast-discriminant-zst-enum.rs
index e59ae297d..2767f178f 100644
--- a/src/test/ui/consts/cast-discriminant-zst-enum.rs
+++ b/src/test/ui/consts/cast-discriminant-zst-enum.rs
@@ -1,6 +1,5 @@
// run-pass
// Test a ZST enum whose dicriminant is ~0i128. This caused an ICE when casting to an i32.
-#![feature(bench_black_box)]
use std::hint::black_box;
#[derive(Copy, Clone)]
diff --git a/src/test/ui/consts/const-err-early.rs b/src/test/ui/consts/const-err-early.rs
index d8f7635fe..a3105b4fc 100644
--- a/src/test/ui/consts/const-err-early.rs
+++ b/src/test/ui/consts/const-err-early.rs
@@ -1,15 +1,8 @@
-#![deny(const_err)]
-
-pub const A: i8 = -i8::MIN; //~ ERROR const_err
-//~| WARN this was previously accepted by the compiler but is being phased out
-pub const B: u8 = 200u8 + 200u8; //~ ERROR const_err
-//~| WARN this was previously accepted by the compiler but is being phased out
-pub const C: u8 = 200u8 * 4; //~ ERROR const_err
-//~| WARN this was previously accepted by the compiler but is being phased out
-pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err
-//~| WARN this was previously accepted by the compiler but is being phased out
-pub const E: u8 = [5u8][1]; //~ ERROR const_err
-//~| WARN this was previously accepted by the compiler but is being phased out
+pub const A: i8 = -i8::MIN; //~ ERROR constant
+pub const B: u8 = 200u8 + 200u8; //~ ERROR constant
+pub const C: u8 = 200u8 * 4; //~ ERROR constant
+pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR constant
+pub const E: u8 = [5u8][1]; //~ ERROR constant
fn main() {
let _a = A;
diff --git a/src/test/ui/consts/const-err-early.stderr b/src/test/ui/consts/const-err-early.stderr
index 1b94aa080..59bf637b7 100644
--- a/src/test/ui/consts/const-err-early.stderr
+++ b/src/test/ui/consts/const-err-early.stderr
@@ -1,127 +1,33 @@
-error: any use of this value will cause an error
- --> $DIR/const-err-early.rs:3:19
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-err-early.rs:1:19
|
LL | pub const A: i8 = -i8::MIN;
- | --------------- ^^^^^^^^ attempt to negate `i8::MIN`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-err-early.rs:1:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^ attempt to negate `i8::MIN`, which would overflow
-error: any use of this value will cause an error
- --> $DIR/const-err-early.rs:5:19
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-err-early.rs:2:19
|
LL | pub const B: u8 = 200u8 + 200u8;
- | --------------- ^^^^^^^^^^^^^ attempt to compute `200_u8 + 200_u8`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^ 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:7:19
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-err-early.rs:3:19
|
LL | pub const C: u8 = 200u8 * 4;
- | --------------- ^^^^^^^^^ attempt to compute `200_u8 * 4_u8`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^ 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:9:19
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-err-early.rs:4:19
|
LL | pub const D: u8 = 42u8 - (42u8 + 1);
- | --------------- ^^^^^^^^^^^^^^^^^ attempt to compute `42_u8 - 43_u8`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^ 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:11:19
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-err-early.rs:5:19
|
LL | pub const E: u8 = [5u8][1];
- | --------------- ^^^^^^^^ index out of bounds: the length is 1 but the index is 1
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^ index out of bounds: the length is 1 but the index is 1
error: aborting due to 5 previous errors
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-err-early.rs:3:19
- |
-LL | pub const A: i8 = -i8::MIN;
- | --------------- ^^^^^^^^ attempt to negate `i8::MIN`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-err-early.rs:1:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-err-early.rs:5:19
- |
-LL | pub const B: u8 = 200u8 + 200u8;
- | --------------- ^^^^^^^^^^^^^ attempt to compute `200_u8 + 200_u8`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-err-early.rs:1:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-err-early.rs:7:19
- |
-LL | pub const C: u8 = 200u8 * 4;
- | --------------- ^^^^^^^^^ attempt to compute `200_u8 * 4_u8`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-err-early.rs:1:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-err-early.rs:9:19
- |
-LL | pub const D: u8 = 42u8 - (42u8 + 1);
- | --------------- ^^^^^^^^^^^^^^^^^ attempt to compute `42_u8 - 43_u8`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-err-early.rs:1:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-err-early.rs:11:19
- |
-LL | pub const E: u8 = [5u8][1];
- | --------------- ^^^^^^^^ index out of bounds: the length is 1 but the index is 1
- |
-note: the lint level is defined here
- --> $DIR/const-err-early.rs:1:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-err-late.rs b/src/test/ui/consts/const-err-late.rs
new file mode 100644
index 000000000..a20ae7025
--- /dev/null
+++ b/src/test/ui/consts/const-err-late.rs
@@ -0,0 +1,22 @@
+// build-fail
+// compile-flags: -C overflow-checks=on
+
+#![allow(arithmetic_overflow, unconditional_panic)]
+
+fn black_box<T>(_: T) {
+ unimplemented!()
+}
+
+struct S<T>(T);
+
+impl<T> S<T> {
+ const FOO: u8 = [5u8][1];
+ //~^ ERROR evaluation of `S::<i32>::FOO` failed
+ //~| ERROR evaluation of `S::<u32>::FOO` failed
+}
+
+fn main() {
+ black_box((S::<i32>::FOO, S::<u32>::FOO));
+ //~^ ERROR erroneous constant
+ //~| ERROR erroneous constant
+}
diff --git a/src/test/ui/consts/const-err-late.stderr b/src/test/ui/consts/const-err-late.stderr
new file mode 100644
index 000000000..3a8b10317
--- /dev/null
+++ b/src/test/ui/consts/const-err-late.stderr
@@ -0,0 +1,27 @@
+error[E0080]: evaluation of `S::<i32>::FOO` failed
+ --> $DIR/const-err-late.rs:13:21
+ |
+LL | const FOO: u8 = [5u8][1];
+ | ^^^^^^^^ index out of bounds: the length is 1 but the index is 1
+
+error[E0080]: erroneous constant used
+ --> $DIR/const-err-late.rs:19:16
+ |
+LL | black_box((S::<i32>::FOO, S::<u32>::FOO));
+ | ^^^^^^^^^^^^^ referenced constant has errors
+
+error[E0080]: evaluation of `S::<u32>::FOO` failed
+ --> $DIR/const-err-late.rs:13:21
+ |
+LL | const FOO: u8 = [5u8][1];
+ | ^^^^^^^^ index out of bounds: the length is 1 but the index is 1
+
+error[E0080]: erroneous constant used
+ --> $DIR/const-err-late.rs:19:31
+ |
+LL | black_box((S::<i32>::FOO, S::<u32>::FOO));
+ | ^^^^^^^^^^^^^ referenced constant has errors
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-err-multi.rs b/src/test/ui/consts/const-err-multi.rs
index 62552e147..fb26e8aac 100644
--- a/src/test/ui/consts/const-err-multi.rs
+++ b/src/test/ui/consts/const-err-multi.rs
@@ -1,17 +1,11 @@
-#![deny(const_err)]
-
pub const A: i8 = -i8::MIN;
-//~^ ERROR const_err
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR constant
pub const B: i8 = A;
-//~^ ERROR const_err
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR constant
pub const C: u8 = A as u8;
-//~^ ERROR const_err
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR constant
pub const D: i8 = 50 - A;
-//~^ ERROR const_err
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR constant
fn main() {
let _ = (A, B, C, D);
diff --git a/src/test/ui/consts/const-err-multi.stderr b/src/test/ui/consts/const-err-multi.stderr
index f17984365..fca9e2270 100644
--- a/src/test/ui/consts/const-err-multi.stderr
+++ b/src/test/ui/consts/const-err-multi.stderr
@@ -1,103 +1,27 @@
-error: any use of this value will cause an error
- --> $DIR/const-err-multi.rs:3:19
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-err-multi.rs:1:19
|
LL | pub const A: i8 = -i8::MIN;
- | --------------- ^^^^^^^^ attempt to negate `i8::MIN`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-err-multi.rs:1:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^ attempt to negate `i8::MIN`, which would overflow
-error: any use of this value will cause an error
- --> $DIR/const-err-multi.rs:6:19
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-err-multi.rs:3:19
|
LL | pub const B: i8 = A;
- | --------------- ^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^ referenced constant has errors
-error: any use of this value will cause an error
- --> $DIR/const-err-multi.rs:9:19
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-err-multi.rs:5:19
|
LL | pub const C: u8 = A as u8;
- | --------------- ^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^ referenced constant has errors
-error: any use of this value will cause an error
- --> $DIR/const-err-multi.rs:12:24
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-err-multi.rs:7:24
|
LL | pub const D: i8 = 50 - A;
- | --------------- ^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^ referenced constant has errors
error: aborting due to 4 previous errors
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-err-multi.rs:3:19
- |
-LL | pub const A: i8 = -i8::MIN;
- | --------------- ^^^^^^^^ attempt to negate `i8::MIN`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-err-multi.rs:1:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-err-multi.rs:6:19
- |
-LL | pub const B: i8 = A;
- | --------------- ^ referenced constant has errors
- |
-note: the lint level is defined here
- --> $DIR/const-err-multi.rs:1:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-err-multi.rs:9:19
- |
-LL | pub const C: u8 = A as u8;
- | --------------- ^ referenced constant has errors
- |
-note: the lint level is defined here
- --> $DIR/const-err-multi.rs:1:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-err-multi.rs:12:24
- |
-LL | pub const D: i8 = 50 - A;
- | --------------- ^ referenced constant has errors
- |
-note: the lint level is defined here
- --> $DIR/const-err-multi.rs:1:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-err-rpass.rs b/src/test/ui/consts/const-err-rpass.rs
index 9851f1c58..e7fa10a2a 100644
--- a/src/test/ui/consts/const-err-rpass.rs
+++ b/src/test/ui/consts/const-err-rpass.rs
@@ -2,8 +2,6 @@
#![allow(dead_code)]
// check for const_err regressions
-#![deny(const_err)]
-
const X: *const u8 = b"" as _;
const Y: bool = 'A' == 'B';
const Z: char = 'A';
diff --git a/src/test/ui/consts/const-err.rs b/src/test/ui/consts/const-err.rs
deleted file mode 100644
index a8633fd87..000000000
--- a/src/test/ui/consts/const-err.rs
+++ /dev/null
@@ -1,19 +0,0 @@
-// build-fail
-// compile-flags: -C overflow-checks=on
-
-#![allow(arithmetic_overflow)]
-#![warn(const_err)]
-
-fn black_box<T>(_: T) {
- unimplemented!()
-}
-
-const FOO: u8 = [5u8][1];
-//~^ WARN any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
-
-fn main() {
- black_box((FOO, FOO));
- //~^ ERROR erroneous constant used
- //~| ERROR erroneous constant
-}
diff --git a/src/test/ui/consts/const-err.stderr b/src/test/ui/consts/const-err.stderr
deleted file mode 100644
index e3b0d29c8..000000000
--- a/src/test/ui/consts/const-err.stderr
+++ /dev/null
@@ -1,44 +0,0 @@
-warning: any use of this value will cause an error
- --> $DIR/const-err.rs:11:17
- |
-LL | const FOO: u8 = [5u8][1];
- | ------------- ^^^^^^^^ index out of bounds: the length is 1 but the index is 1
- |
-note: the lint level is defined here
- --> $DIR/const-err.rs:5:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-error[E0080]: erroneous constant used
- --> $DIR/const-err.rs:16:16
- |
-LL | black_box((FOO, FOO));
- | ^^^ referenced constant has errors
-
-error[E0080]: erroneous constant used
- --> $DIR/const-err.rs:16:21
- |
-LL | black_box((FOO, FOO));
- | ^^^ referenced constant has errors
-
-error: aborting due to 2 previous errors; 1 warning emitted
-
-For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/const-err.rs:11:17
- |
-LL | const FOO: u8 = [5u8][1];
- | ------------- ^^^^^^^^ index out of bounds: the length is 1 but the index is 1
- |
-note: the lint level is defined here
- --> $DIR/const-err.rs:5:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-eval/conditional_array_execution.rs b/src/test/ui/consts/const-eval/conditional_array_execution.rs
index bd517e568..27d5383d6 100644
--- a/src/test/ui/consts/const-eval/conditional_array_execution.rs
+++ b/src/test/ui/consts/const-eval/conditional_array_execution.rs
@@ -1,16 +1,8 @@
-// build-fail
-
-#![warn(const_err)]
-
const X: u32 = 5;
const Y: u32 = 6;
const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
-//~^ WARN any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR constant
fn main() {
println!("{}", FOO);
- //~^ ERROR evaluation of constant value failed
- //~| WARN erroneous constant used [const_err]
- //~| WARN this was previously accepted by the compiler but is being phased out
}
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 2953406ee..c3401fbae 100644
--- a/src/test/ui/consts/const-eval/conditional_array_execution.stderr
+++ b/src/test/ui/consts/const-eval/conditional_array_execution.stderr
@@ -1,64 +1,9 @@
-warning: any use of this value will cause an error
- --> $DIR/conditional_array_execution.rs:7:19
- |
-LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
- | -------------- ^^^^^ attempt to compute `5_u32 - 6_u32`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/conditional_array_execution.rs:3:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
error[E0080]: evaluation of constant value failed
- --> $DIR/conditional_array_execution.rs:12:20
- |
-LL | println!("{}", FOO);
- | ^^^ referenced constant has errors
-
-warning: erroneous constant used
- --> $DIR/conditional_array_execution.rs:12:20
- |
-LL | println!("{}", FOO);
- | ^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this warning originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: aborting due to previous error; 2 warnings emitted
-
-For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/conditional_array_execution.rs:7:19
+ --> $DIR/conditional_array_execution.rs:3:19
|
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
- | -------------- ^^^^^ attempt to compute `5_u32 - 6_u32`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/conditional_array_execution.rs:3:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^ attempt to compute `5_u32 - 6_u32`, which would overflow
-Future breakage diagnostic:
-warning: erroneous constant used
- --> $DIR/conditional_array_execution.rs:12:20
- |
-LL | println!("{}", FOO);
- | ^^^ referenced constant has errors
- |
-note: the lint level is defined here
- --> $DIR/conditional_array_execution.rs:3:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this warning originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+error: aborting due to previous error
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/const-eval-overflow-2.rs b/src/test/ui/consts/const-eval/const-eval-overflow-2.rs
index 9300d9576..535d91359 100644
--- a/src/test/ui/consts/const-eval/const-eval-overflow-2.rs
+++ b/src/test/ui/consts/const-eval/const-eval-overflow-2.rs
@@ -1,14 +1,14 @@
// Evaluation of constants in refutable patterns goes through
// different compiler control-flow paths.
-#![allow(unused_imports, warnings, const_err)]
+#![allow(unused_imports, warnings)]
use std::fmt;
use std::{i8, i16, i32, i64, isize};
use std::{u8, u16, u32, u64, usize};
const NEG_128: i8 = -128;
-const NEG_NEG_128: i8 = -NEG_128;
+const NEG_NEG_128: i8 = -NEG_128; //~ ERROR constant
fn main() {
match -128i8 {
diff --git a/src/test/ui/consts/const-eval/const-eval-overflow-2.stderr b/src/test/ui/consts/const-eval/const-eval-overflow-2.stderr
index cf50c19ca..7b1fe49d4 100644
--- a/src/test/ui/consts/const-eval/const-eval-overflow-2.stderr
+++ b/src/test/ui/consts/const-eval/const-eval-overflow-2.stderr
@@ -1,3 +1,9 @@
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow-2.rs:11:25
+ |
+LL | const NEG_NEG_128: i8 = -NEG_128;
+ | ^^^^^^^^ attempt to negate `i8::MIN`, which would overflow
+
error: could not evaluate constant pattern
--> $DIR/const-eval-overflow-2.rs:15:9
|
@@ -10,20 +16,6 @@ error: could not evaluate constant pattern
LL | NEG_NEG_128 => println!("A"),
| ^^^^^^^^^^^
-error: aborting due to 2 previous errors
-
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/const-eval-overflow-2.rs:11:25
- |
-LL | const NEG_NEG_128: i8 = -NEG_128;
- | --------------------- ^^^^^^^^ attempt to negate `i8::MIN`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow-2.rs:4:36
- |
-LL | #![allow(unused_imports, warnings, const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+error: aborting due to 3 previous errors
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/const-eval-overflow-3b.stderr b/src/test/ui/consts/const-eval/const-eval-overflow-3b.stderr
index 0e6be6d01..c685922c4 100644
--- a/src/test/ui/consts/const-eval/const-eval-overflow-3b.stderr
+++ b/src/test/ui/consts/const-eval/const-eval-overflow-3b.stderr
@@ -4,13 +4,13 @@ error[E0308]: mismatched types
LL | = [0; (i8::MAX + 1u8) as usize];
| ^^^ expected `i8`, found `u8`
-error[E0277]: cannot add `u8` to `i8`
+error[E0277]: cannot add `u8` to `i8` in const contexts
--> $DIR/const-eval-overflow-3b.rs:16:20
|
LL | = [0; (i8::MAX + 1u8) as usize];
| ^ no implementation for `i8 + u8`
|
- = help: the trait `Add<u8>` is not implemented for `i8`
+ = help: the trait `~const Add<u8>` is not implemented for `i8`
= help: the following other types implement trait `Add<Rhs>`:
<&'a f32 as Add<f32>>
<&'a f64 as Add<f64>>
diff --git a/src/test/ui/consts/const-eval/const-eval-overflow-4b.stderr b/src/test/ui/consts/const-eval/const-eval-overflow-4b.stderr
index 4fa017e04..b39607924 100644
--- a/src/test/ui/consts/const-eval/const-eval-overflow-4b.stderr
+++ b/src/test/ui/consts/const-eval/const-eval-overflow-4b.stderr
@@ -4,13 +4,13 @@ error[E0308]: mismatched types
LL | : [u32; (i8::MAX as i8 + 1u8) as usize]
| ^^^ expected `i8`, found `u8`
-error[E0277]: cannot add `u8` to `i8`
+error[E0277]: cannot add `u8` to `i8` in const contexts
--> $DIR/const-eval-overflow-4b.rs:9:28
|
LL | : [u32; (i8::MAX as i8 + 1u8) as usize]
| ^ no implementation for `i8 + u8`
|
- = help: the trait `Add<u8>` is not implemented for `i8`
+ = help: the trait `~const Add<u8>` is not implemented for `i8`
= help: the following other types implement trait `Add<Rhs>`:
<&'a f32 as Add<f32>>
<&'a f64 as Add<f64>>
diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2.rs b/src/test/ui/consts/const-eval/const-eval-overflow2.rs
index b11f7d698..1676f7c2a 100644
--- a/src/test/ui/consts/const-eval/const-eval-overflow2.rs
+++ b/src/test/ui/consts/const-eval/const-eval-overflow2.rs
@@ -5,63 +5,53 @@
// change this warn to a deny, then the compiler will exit before
// those errors are detected.
-#![deny(const_err)]
-
use std::fmt;
const VALS_I8: (i8,) =
(
i8::MIN - 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_I16: (i16,) =
(
i16::MIN - 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_I32: (i32,) =
(
i32::MIN - 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_I64: (i64,) =
(
i64::MIN - 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_U8: (u8,) =
(
u8::MIN - 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_U16: (u16,) = (
u16::MIN - 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_U32: (u32,) = (
u32::MIN - 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_U64: (u64,) =
(
u64::MIN - 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
fn main() {
foo(VALS_I8);
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 dab9a76c7..341c15daf 100644
--- a/src/test/ui/consts/const-eval/const-eval-overflow2.stderr
+++ b/src/test/ui/consts/const-eval/const-eval-overflow2.stderr
@@ -1,243 +1,51 @@
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:14:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2.rs:12:6
|
-LL | const VALS_I8: (i8,) =
- | --------------------
-LL | (
LL | i8::MIN - 1,
| ^^^^^^^^^^^ attempt to compute `i8::MIN - 1_i8`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:21:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2.rs:18:6
|
-LL | const VALS_I16: (i16,) =
- | ----------------------
-LL | (
LL | i16::MIN - 1,
| ^^^^^^^^^^^^ attempt to compute `i16::MIN - 1_i16`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:28:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2.rs:24:6
|
-LL | const VALS_I32: (i32,) =
- | ----------------------
-LL | (
LL | i32::MIN - 1,
| ^^^^^^^^^^^^ attempt to compute `i32::MIN - 1_i32`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:35:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2.rs:30:6
|
-LL | const VALS_I64: (i64,) =
- | ----------------------
-LL | (
LL | i64::MIN - 1,
| ^^^^^^^^^^^^ attempt to compute `i64::MIN - 1_i64`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:42:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2.rs:36:6
|
-LL | const VALS_U8: (u8,) =
- | --------------------
-LL | (
LL | u8::MIN - 1,
| ^^^^^^^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:48:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2.rs:41:6
|
-LL | const VALS_U16: (u16,) = (
- | ----------------------
LL | u16::MIN - 1,
| ^^^^^^^^^^^^ attempt to compute `0_u16 - 1_u16`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:54:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2.rs:46:6
|
-LL | const VALS_U32: (u32,) = (
- | ----------------------
LL | u32::MIN - 1,
| ^^^^^^^^^^^^ attempt to compute `0_u32 - 1_u32`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:61:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2.rs:52:6
|
-LL | const VALS_U64: (u64,) =
- | ----------------------
-LL | (
LL | u64::MIN - 1,
| ^^^^^^^^^^^^ attempt to compute `0_u64 - 1_u64`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: aborting due to 8 previous errors
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:14:6
- |
-LL | const VALS_I8: (i8,) =
- | --------------------
-LL | (
-LL | i8::MIN - 1,
- | ^^^^^^^^^^^ attempt to compute `i8::MIN - 1_i8`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:21:6
- |
-LL | const VALS_I16: (i16,) =
- | ----------------------
-LL | (
-LL | i16::MIN - 1,
- | ^^^^^^^^^^^^ attempt to compute `i16::MIN - 1_i16`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:28:6
- |
-LL | const VALS_I32: (i32,) =
- | ----------------------
-LL | (
-LL | i32::MIN - 1,
- | ^^^^^^^^^^^^ attempt to compute `i32::MIN - 1_i32`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:35:6
- |
-LL | const VALS_I64: (i64,) =
- | ----------------------
-LL | (
-LL | i64::MIN - 1,
- | ^^^^^^^^^^^^ attempt to compute `i64::MIN - 1_i64`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:42:6
- |
-LL | const VALS_U8: (u8,) =
- | --------------------
-LL | (
-LL | u8::MIN - 1,
- | ^^^^^^^^^^^ attempt to compute `0_u8 - 1_u8`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:48:6
- |
-LL | const VALS_U16: (u16,) = (
- | ----------------------
-LL | u16::MIN - 1,
- | ^^^^^^^^^^^^ attempt to compute `0_u16 - 1_u16`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:54:6
- |
-LL | const VALS_U32: (u32,) = (
- | ----------------------
-LL | u32::MIN - 1,
- | ^^^^^^^^^^^^ attempt to compute `0_u32 - 1_u32`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2.rs:61:6
- |
-LL | const VALS_U64: (u64,) =
- | ----------------------
-LL | (
-LL | u64::MIN - 1,
- | ^^^^^^^^^^^^ attempt to compute `0_u64 - 1_u64`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2b.rs b/src/test/ui/consts/const-eval/const-eval-overflow2b.rs
index 9c3ad8ef9..59d1df568 100644
--- a/src/test/ui/consts/const-eval/const-eval-overflow2b.rs
+++ b/src/test/ui/consts/const-eval/const-eval-overflow2b.rs
@@ -5,63 +5,53 @@
// change this warn to a deny, then the compiler will exit before
// those errors are detected.
-#![deny(const_err)]
-
use std::fmt;
const VALS_I8: (i8,) =
(
i8::MAX + 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_I16: (i16,) =
(
i16::MAX + 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_I32: (i32,) =
(
i32::MAX + 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_I64: (i64,) =
(
i64::MAX + 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_U8: (u8,) =
(
u8::MAX + 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_U16: (u16,) = (
u16::MAX + 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_U32: (u32,) = (
u32::MAX + 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_U64: (u64,) =
(
u64::MAX + 1,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
fn main() {
foo(VALS_I8);
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 5fe991743..e661836b4 100644
--- a/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr
+++ b/src/test/ui/consts/const-eval/const-eval-overflow2b.stderr
@@ -1,243 +1,51 @@
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:14:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2b.rs:12:6
|
-LL | const VALS_I8: (i8,) =
- | --------------------
-LL | (
LL | i8::MAX + 1,
| ^^^^^^^^^^^ attempt to compute `i8::MAX + 1_i8`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2b.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:21:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2b.rs:18:6
|
-LL | const VALS_I16: (i16,) =
- | ----------------------
-LL | (
LL | i16::MAX + 1,
| ^^^^^^^^^^^^ attempt to compute `i16::MAX + 1_i16`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:28:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2b.rs:24:6
|
-LL | const VALS_I32: (i32,) =
- | ----------------------
-LL | (
LL | i32::MAX + 1,
| ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:35:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2b.rs:30:6
|
-LL | const VALS_I64: (i64,) =
- | ----------------------
-LL | (
LL | i64::MAX + 1,
| ^^^^^^^^^^^^ attempt to compute `i64::MAX + 1_i64`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:42:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2b.rs:36:6
|
-LL | const VALS_U8: (u8,) =
- | --------------------
-LL | (
LL | u8::MAX + 1,
| ^^^^^^^^^^^ attempt to compute `u8::MAX + 1_u8`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:48:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2b.rs:41:6
|
-LL | const VALS_U16: (u16,) = (
- | ----------------------
LL | u16::MAX + 1,
| ^^^^^^^^^^^^ attempt to compute `u16::MAX + 1_u16`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:54:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2b.rs:46:6
|
-LL | const VALS_U32: (u32,) = (
- | ----------------------
LL | u32::MAX + 1,
| ^^^^^^^^^^^^ attempt to compute `u32::MAX + 1_u32`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:61:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2b.rs:52:6
|
-LL | const VALS_U64: (u64,) =
- | ----------------------
-LL | (
LL | u64::MAX + 1,
| ^^^^^^^^^^^^ attempt to compute `u64::MAX + 1_u64`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: aborting due to 8 previous errors
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:14:6
- |
-LL | const VALS_I8: (i8,) =
- | --------------------
-LL | (
-LL | i8::MAX + 1,
- | ^^^^^^^^^^^ attempt to compute `i8::MAX + 1_i8`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2b.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:21:6
- |
-LL | const VALS_I16: (i16,) =
- | ----------------------
-LL | (
-LL | i16::MAX + 1,
- | ^^^^^^^^^^^^ attempt to compute `i16::MAX + 1_i16`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2b.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:28:6
- |
-LL | const VALS_I32: (i32,) =
- | ----------------------
-LL | (
-LL | i32::MAX + 1,
- | ^^^^^^^^^^^^ attempt to compute `i32::MAX + 1_i32`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2b.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:35:6
- |
-LL | const VALS_I64: (i64,) =
- | ----------------------
-LL | (
-LL | i64::MAX + 1,
- | ^^^^^^^^^^^^ attempt to compute `i64::MAX + 1_i64`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2b.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:42:6
- |
-LL | const VALS_U8: (u8,) =
- | --------------------
-LL | (
-LL | u8::MAX + 1,
- | ^^^^^^^^^^^ attempt to compute `u8::MAX + 1_u8`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2b.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:48:6
- |
-LL | const VALS_U16: (u16,) = (
- | ----------------------
-LL | u16::MAX + 1,
- | ^^^^^^^^^^^^ attempt to compute `u16::MAX + 1_u16`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2b.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:54:6
- |
-LL | const VALS_U32: (u32,) = (
- | ----------------------
-LL | u32::MAX + 1,
- | ^^^^^^^^^^^^ attempt to compute `u32::MAX + 1_u32`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2b.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2b.rs:61:6
- |
-LL | const VALS_U64: (u64,) =
- | ----------------------
-LL | (
-LL | u64::MAX + 1,
- | ^^^^^^^^^^^^ attempt to compute `u64::MAX + 1_u64`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2b.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/const-eval-overflow2c.rs b/src/test/ui/consts/const-eval/const-eval-overflow2c.rs
index bac4d042e..33b892601 100644
--- a/src/test/ui/consts/const-eval/const-eval-overflow2c.rs
+++ b/src/test/ui/consts/const-eval/const-eval-overflow2c.rs
@@ -5,63 +5,53 @@
// change this warn to a deny, then the compiler will exit before
// those errors are detected.
-#![deny(const_err)]
-
use std::fmt;
const VALS_I8: (i8,) =
(
i8::MIN * 2,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_I16: (i16,) =
(
i16::MIN * 2,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_I32: (i32,) =
(
i32::MIN * 2,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_I64: (i64,) =
(
i64::MIN * 2,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_U8: (u8,) =
(
u8::MAX * 2,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_U16: (u16,) = (
u16::MAX * 2,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_U32: (u32,) = (
u32::MAX * 2,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
const VALS_U64: (u64,) =
(
u64::MAX * 2,
);
- //~^^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^^ ERROR evaluation of constant value failed
fn main() {
foo(VALS_I8);
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 d5f3a0fb1..1fad15492 100644
--- a/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr
+++ b/src/test/ui/consts/const-eval/const-eval-overflow2c.stderr
@@ -1,243 +1,51 @@
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:14:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2c.rs:12:6
|
-LL | const VALS_I8: (i8,) =
- | --------------------
-LL | (
LL | i8::MIN * 2,
| ^^^^^^^^^^^ attempt to compute `i8::MIN * 2_i8`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2c.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:21:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2c.rs:18:6
|
-LL | const VALS_I16: (i16,) =
- | ----------------------
-LL | (
LL | i16::MIN * 2,
| ^^^^^^^^^^^^ attempt to compute `i16::MIN * 2_i16`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:28:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2c.rs:24:6
|
-LL | const VALS_I32: (i32,) =
- | ----------------------
-LL | (
LL | i32::MIN * 2,
| ^^^^^^^^^^^^ attempt to compute `i32::MIN * 2_i32`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:35:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2c.rs:30:6
|
-LL | const VALS_I64: (i64,) =
- | ----------------------
-LL | (
LL | i64::MIN * 2,
| ^^^^^^^^^^^^ attempt to compute `i64::MIN * 2_i64`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:42:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2c.rs:36:6
|
-LL | const VALS_U8: (u8,) =
- | --------------------
-LL | (
LL | u8::MAX * 2,
| ^^^^^^^^^^^ attempt to compute `u8::MAX * 2_u8`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:48:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2c.rs:41:6
|
-LL | const VALS_U16: (u16,) = (
- | ----------------------
LL | u16::MAX * 2,
| ^^^^^^^^^^^^ attempt to compute `u16::MAX * 2_u16`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:54:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2c.rs:46:6
|
-LL | const VALS_U32: (u32,) = (
- | ----------------------
LL | u32::MAX * 2,
| ^^^^^^^^^^^^ attempt to compute `u32::MAX * 2_u32`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:61:6
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-eval-overflow2c.rs:52:6
|
-LL | const VALS_U64: (u64,) =
- | ----------------------
-LL | (
LL | u64::MAX * 2,
| ^^^^^^^^^^^^ attempt to compute `u64::MAX * 2_u64`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: aborting due to 8 previous errors
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:14:6
- |
-LL | const VALS_I8: (i8,) =
- | --------------------
-LL | (
-LL | i8::MIN * 2,
- | ^^^^^^^^^^^ attempt to compute `i8::MIN * 2_i8`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2c.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:21:6
- |
-LL | const VALS_I16: (i16,) =
- | ----------------------
-LL | (
-LL | i16::MIN * 2,
- | ^^^^^^^^^^^^ attempt to compute `i16::MIN * 2_i16`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2c.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:28:6
- |
-LL | const VALS_I32: (i32,) =
- | ----------------------
-LL | (
-LL | i32::MIN * 2,
- | ^^^^^^^^^^^^ attempt to compute `i32::MIN * 2_i32`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2c.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:35:6
- |
-LL | const VALS_I64: (i64,) =
- | ----------------------
-LL | (
-LL | i64::MIN * 2,
- | ^^^^^^^^^^^^ attempt to compute `i64::MIN * 2_i64`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2c.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:42:6
- |
-LL | const VALS_U8: (u8,) =
- | --------------------
-LL | (
-LL | u8::MAX * 2,
- | ^^^^^^^^^^^ attempt to compute `u8::MAX * 2_u8`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2c.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:48:6
- |
-LL | const VALS_U16: (u16,) = (
- | ----------------------
-LL | u16::MAX * 2,
- | ^^^^^^^^^^^^ attempt to compute `u16::MAX * 2_u16`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2c.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:54:6
- |
-LL | const VALS_U32: (u32,) = (
- | ----------------------
-LL | u32::MAX * 2,
- | ^^^^^^^^^^^^ attempt to compute `u32::MAX * 2_u32`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2c.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-eval-overflow2c.rs:61:6
- |
-LL | const VALS_U64: (u64,) =
- | ----------------------
-LL | (
-LL | u64::MAX * 2,
- | ^^^^^^^^^^^^ attempt to compute `u64::MAX * 2_u64`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/const-eval-overflow2c.rs:8:9
- |
-LL | #![deny(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/const-eval-query-stack.rs b/src/test/ui/consts/const-eval/const-eval-query-stack.rs
index c94604989..8f8a8cee3 100644
--- a/src/test/ui/consts/const-eval/const-eval-query-stack.rs
+++ b/src/test/ui/consts/const-eval/const-eval-query-stack.rs
@@ -1,5 +1,4 @@
-// compile-flags: -Ztreat-err-as-bug=2
-// build-fail
+// compile-flags: -Ztreat-err-as-bug=1
// failure-status: 101
// rustc-env:RUST_BACKTRACE=1
// normalize-stderr-test "\nerror: internal compiler error.*\n\n" -> ""
@@ -15,14 +14,9 @@
#![allow(unconditional_panic)]
-#[warn(const_err)]
-const X: i32 = 1 / 0; //~WARN any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+const X: i32 = 1 / 0; //~ERROR constant
fn main() {
let x: &'static i32 = &X;
- //~^ ERROR evaluation of constant value failed
- //~| ERROR erroneous constant used
- //~| WARNING this was previously accepted by the compiler
println!("x={}", x);
}
diff --git a/src/test/ui/consts/const-eval/const-eval-query-stack.stderr b/src/test/ui/consts/const-eval/const-eval-query-stack.stderr
index 0ae7bfa86..b97975c4c 100644
--- a/src/test/ui/consts/const-eval/const-eval-query-stack.stderr
+++ b/src/test/ui/consts/const-eval/const-eval-query-stack.stderr
@@ -1,61 +1,13 @@
-warning: any use of this value will cause an error
- --> $DIR/const-eval-query-stack.rs:19:16
- |
-LL | const X: i32 = 1 / 0;
- | ------------ ^^^^^ attempt to divide `1_i32` by zero
- |
-note: the lint level is defined here
- --> $DIR/const-eval-query-stack.rs:18:8
- |
-LL | #[warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
error[E0080]: evaluation of constant value failed
- --> $DIR/const-eval-query-stack.rs:23:28
+ --> $DIR/const-eval-query-stack.rs:17:16
|
-LL | let x: &'static i32 = &X;
- | ^ referenced constant has errors
-
-error: erroneous constant used
- --> $DIR/const-eval-query-stack.rs:23:27
- |
-LL | let x: &'static i32 = &X;
- | ^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+LL | const X: i32 = 1 / 0;
+ | ^^^^^ attempt to divide `1_i32` by zero
query stack during panic:
-#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `main`
-#1 [optimized_mir] optimizing MIR for `main`
-#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
+#0 [eval_to_allocation_raw] const-evaluating + checking `X`
+#1 [eval_to_const_value_raw] simplifying constant for the type system `X`
+#2 [eval_to_const_value_raw] simplifying constant for the type system `X`
+#3 [lint_mod] linting top-level module
+#4 [analysis] running analysis passes on this crate
end of query stack
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/const-eval-query-stack.rs:19:16
- |
-LL | const X: i32 = 1 / 0;
- | ------------ ^^^^^ attempt to divide `1_i32` by zero
- |
-note: the lint level is defined here
- --> $DIR/const-eval-query-stack.rs:18:8
- |
-LL | #[warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: erroneous constant used
- --> $DIR/const-eval-query-stack.rs:23:27
- |
-LL | let x: &'static i32 = &X;
- | ^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.64bit.stderr b/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.64bit.stderr
index 12d5b7bd6..bf98d0394 100644
--- a/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.64bit.stderr
+++ b/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.64bit.stderr
@@ -1,664 +1,258 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/const-pointer-values-in-various-types.rs:26:49
|
LL | const I32_REF_USIZE_UNION: usize = unsafe { Nonsense { int_32_ref: &3 }.u };
- | -------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:30:43
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:29:43
|
LL | const I32_REF_U8_UNION: u8 = unsafe { Nonsense { int_32_ref: &3 }.uint_8 };
- | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:34:45
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:32:45
|
LL | const I32_REF_U16_UNION: u16 = unsafe { Nonsense { int_32_ref: &3 }.uint_16 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:38:45
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:35:45
|
LL | const I32_REF_U32_UNION: u32 = unsafe { Nonsense { int_32_ref: &3 }.uint_32 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:42:45
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:38:45
|
LL | const I32_REF_U64_UNION: u64 = unsafe { Nonsense { int_32_ref: &3 }.uint_64 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: evaluation of constant value failed
- --> $DIR/const-pointer-values-in-various-types.rs:46:47
+ --> $DIR/const-pointer-values-in-various-types.rs:41:47
|
LL | const I32_REF_U128_UNION: u128 = unsafe { Nonsense { int_32_ref: &3 }.uint_128 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:50:43
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:45:43
|
LL | const I32_REF_I8_UNION: i8 = unsafe { Nonsense { int_32_ref: &3 }.int_8 };
- | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:54:45
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:48:45
|
LL | const I32_REF_I16_UNION: i16 = unsafe { Nonsense { int_32_ref: &3 }.int_16 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:58:45
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:51:45
|
LL | const I32_REF_I32_UNION: i32 = unsafe { Nonsense { int_32_ref: &3 }.int_32 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:62:45
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:54:45
|
LL | const I32_REF_I64_UNION: i64 = unsafe { Nonsense { int_32_ref: &3 }.int_64 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: evaluation of constant value failed
- --> $DIR/const-pointer-values-in-various-types.rs:66:47
+ --> $DIR/const-pointer-values-in-various-types.rs:57:47
|
LL | const I32_REF_I128_UNION: i128 = unsafe { Nonsense { int_32_ref: &3 }.int_128 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:70:45
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:61:45
|
LL | const I32_REF_F32_UNION: f32 = unsafe { Nonsense { int_32_ref: &3 }.float_32 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:74:45
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:64:45
|
LL | const I32_REF_F64_UNION: f64 = unsafe { Nonsense { int_32_ref: &3 }.float_64 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:78:47
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:67:47
|
LL | const I32_REF_BOOL_UNION: bool = unsafe { Nonsense { int_32_ref: &3 }.truthy_falsey };
- | ------------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:82:47
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:70:47
|
LL | const I32_REF_CHAR_UNION: char = unsafe { Nonsense { int_32_ref: &3 }.character };
- | ------------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:86:39
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:73:39
|
LL | const STR_U8_UNION: u8 = unsafe { Nonsense { stringy: "3" }.uint_8 };
- | ---------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:90:41
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:76:41
|
LL | const STR_U16_UNION: u16 = unsafe { Nonsense { stringy: "3" }.uint_16 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:94:41
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:79:41
|
LL | const STR_U32_UNION: u32 = unsafe { Nonsense { stringy: "3" }.uint_32 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:98:41
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:82:41
|
LL | const STR_U64_UNION: u64 = unsafe { Nonsense { stringy: "3" }.uint_64 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:102:43
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:85:43
|
LL | const STR_U128_UNION: u128 = unsafe { Nonsense { stringy: "3" }.uint_128 };
- | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:106:39
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:88:39
|
LL | const STR_I8_UNION: i8 = unsafe { Nonsense { stringy: "3" }.int_8 };
- | ---------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:110:41
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:91:41
|
LL | const STR_I16_UNION: i16 = unsafe { Nonsense { stringy: "3" }.int_16 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:114:41
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:94:41
|
LL | const STR_I32_UNION: i32 = unsafe { Nonsense { stringy: "3" }.int_32 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:118:41
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:97:41
|
LL | const STR_I64_UNION: i64 = unsafe { Nonsense { stringy: "3" }.int_64 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:122:43
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:100:43
|
LL | const STR_I128_UNION: i128 = unsafe { Nonsense { stringy: "3" }.int_128 };
- | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:126:41
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:103:41
|
LL | const STR_F32_UNION: f32 = unsafe { Nonsense { stringy: "3" }.float_32 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:130:41
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:106:41
|
LL | const STR_F64_UNION: f64 = unsafe { Nonsense { stringy: "3" }.float_64 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:134:43
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:109:43
|
LL | const STR_BOOL_UNION: bool = unsafe { Nonsense { stringy: "3" }.truthy_falsey };
- | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:138:43
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-pointer-values-in-various-types.rs:112:43
|
LL | const STR_CHAR_UNION: char = unsafe { Nonsense { stringy: "3" }.character };
- | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error: aborting due to 29 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:26:49
- |
-LL | const I32_REF_USIZE_UNION: usize = unsafe { Nonsense { int_32_ref: &3 }.u };
- | -------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:30:43
- |
-LL | const I32_REF_U8_UNION: u8 = unsafe { Nonsense { int_32_ref: &3 }.uint_8 };
- | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:34:45
- |
-LL | const I32_REF_U16_UNION: u16 = unsafe { Nonsense { int_32_ref: &3 }.uint_16 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:38:45
- |
-LL | const I32_REF_U32_UNION: u32 = unsafe { Nonsense { int_32_ref: &3 }.uint_32 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:42:45
- |
-LL | const I32_REF_U64_UNION: u64 = unsafe { Nonsense { int_32_ref: &3 }.uint_64 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:50:43
- |
-LL | const I32_REF_I8_UNION: i8 = unsafe { Nonsense { int_32_ref: &3 }.int_8 };
- | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:54:45
- |
-LL | const I32_REF_I16_UNION: i16 = unsafe { Nonsense { int_32_ref: &3 }.int_16 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:58:45
- |
-LL | const I32_REF_I32_UNION: i32 = unsafe { Nonsense { int_32_ref: &3 }.int_32 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:62:45
- |
-LL | const I32_REF_I64_UNION: i64 = unsafe { Nonsense { int_32_ref: &3 }.int_64 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:70:45
- |
-LL | const I32_REF_F32_UNION: f32 = unsafe { Nonsense { int_32_ref: &3 }.float_32 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:74:45
- |
-LL | const I32_REF_F64_UNION: f64 = unsafe { Nonsense { int_32_ref: &3 }.float_64 };
- | ---------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:78:47
- |
-LL | const I32_REF_BOOL_UNION: bool = unsafe { Nonsense { int_32_ref: &3 }.truthy_falsey };
- | ------------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:82:47
- |
-LL | const I32_REF_CHAR_UNION: char = unsafe { Nonsense { int_32_ref: &3 }.character };
- | ------------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:86:39
- |
-LL | const STR_U8_UNION: u8 = unsafe { Nonsense { stringy: "3" }.uint_8 };
- | ---------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:90:41
- |
-LL | const STR_U16_UNION: u16 = unsafe { Nonsense { stringy: "3" }.uint_16 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:94:41
- |
-LL | const STR_U32_UNION: u32 = unsafe { Nonsense { stringy: "3" }.uint_32 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:98:41
- |
-LL | const STR_U64_UNION: u64 = unsafe { Nonsense { stringy: "3" }.uint_64 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:102:43
- |
-LL | const STR_U128_UNION: u128 = unsafe { Nonsense { stringy: "3" }.uint_128 };
- | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:106:39
- |
-LL | const STR_I8_UNION: i8 = unsafe { Nonsense { stringy: "3" }.int_8 };
- | ---------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:110:41
- |
-LL | const STR_I16_UNION: i16 = unsafe { Nonsense { stringy: "3" }.int_16 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:114:41
- |
-LL | const STR_I32_UNION: i32 = unsafe { Nonsense { stringy: "3" }.int_32 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:118:41
- |
-LL | const STR_I64_UNION: i64 = unsafe { Nonsense { stringy: "3" }.int_64 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:122:43
- |
-LL | const STR_I128_UNION: i128 = unsafe { Nonsense { stringy: "3" }.int_128 };
- | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:126:41
- |
-LL | const STR_F32_UNION: f32 = unsafe { Nonsense { stringy: "3" }.float_32 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:130:41
- |
-LL | const STR_F64_UNION: f64 = unsafe { Nonsense { stringy: "3" }.float_64 };
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:134:43
- |
-LL | const STR_BOOL_UNION: bool = unsafe { Nonsense { stringy: "3" }.truthy_falsey };
- | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-pointer-values-in-various-types.rs:138:43
- |
-LL | const STR_CHAR_UNION: char = unsafe { Nonsense { stringy: "3" }.character };
- | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
diff --git a/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs b/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs
index f6a5e4d3c..45eed9d84 100644
--- a/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs
+++ b/src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs
@@ -24,118 +24,91 @@ union Nonsense {
fn main() {
const I32_REF_USIZE_UNION: usize = unsafe { Nonsense { int_32_ref: &3 }.u };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const I32_REF_U8_UNION: u8 = unsafe { Nonsense { int_32_ref: &3 }.uint_8 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const I32_REF_U16_UNION: u16 = unsafe { Nonsense { int_32_ref: &3 }.uint_16 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const I32_REF_U32_UNION: u32 = unsafe { Nonsense { int_32_ref: &3 }.uint_32 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const I32_REF_U64_UNION: u64 = unsafe { Nonsense { int_32_ref: &3 }.uint_64 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const I32_REF_U128_UNION: u128 = unsafe { Nonsense { int_32_ref: &3 }.uint_128 };
//~^ ERROR evaluation of constant value failed
//~| uninitialized
const I32_REF_I8_UNION: i8 = unsafe { Nonsense { int_32_ref: &3 }.int_8 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const I32_REF_I16_UNION: i16 = unsafe { Nonsense { int_32_ref: &3 }.int_16 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const I32_REF_I32_UNION: i32 = unsafe { Nonsense { int_32_ref: &3 }.int_32 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const I32_REF_I64_UNION: i64 = unsafe { Nonsense { int_32_ref: &3 }.int_64 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const I32_REF_I128_UNION: i128 = unsafe { Nonsense { int_32_ref: &3 }.int_128 };
//~^ ERROR evaluation of constant value failed
//~| uninitialized
const I32_REF_F32_UNION: f32 = unsafe { Nonsense { int_32_ref: &3 }.float_32 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const I32_REF_F64_UNION: f64 = unsafe { Nonsense { int_32_ref: &3 }.float_64 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const I32_REF_BOOL_UNION: bool = unsafe { Nonsense { int_32_ref: &3 }.truthy_falsey };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const I32_REF_CHAR_UNION: char = unsafe { Nonsense { int_32_ref: &3 }.character };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_U8_UNION: u8 = unsafe { Nonsense { stringy: "3" }.uint_8 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_U16_UNION: u16 = unsafe { Nonsense { stringy: "3" }.uint_16 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_U32_UNION: u32 = unsafe { Nonsense { stringy: "3" }.uint_32 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_U64_UNION: u64 = unsafe { Nonsense { stringy: "3" }.uint_64 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_U128_UNION: u128 = unsafe { Nonsense { stringy: "3" }.uint_128 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_I8_UNION: i8 = unsafe { Nonsense { stringy: "3" }.int_8 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_I16_UNION: i16 = unsafe { Nonsense { stringy: "3" }.int_16 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_I32_UNION: i32 = unsafe { Nonsense { stringy: "3" }.int_32 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_I64_UNION: i64 = unsafe { Nonsense { stringy: "3" }.int_64 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_I128_UNION: i128 = unsafe { Nonsense { stringy: "3" }.int_128 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_F32_UNION: f32 = unsafe { Nonsense { stringy: "3" }.float_32 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_F64_UNION: f64 = unsafe { Nonsense { stringy: "3" }.float_64 };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_BOOL_UNION: bool = unsafe { Nonsense { stringy: "3" }.truthy_falsey };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
const STR_CHAR_UNION: char = unsafe { Nonsense { stringy: "3" }.character };
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
}
diff --git a/src/test/ui/consts/const-eval/const_fn_ptr_fail2.rs b/src/test/ui/consts/const-eval/const_fn_ptr_fail2.rs
index 804ebf660..b873940c4 100644
--- a/src/test/ui/consts/const-eval/const_fn_ptr_fail2.rs
+++ b/src/test/ui/consts/const-eval/const_fn_ptr_fail2.rs
@@ -1,8 +1,5 @@
-// build-fail
// compile-flags: -Zunleash-the-miri-inside-of-you
-#![allow(const_err)]
-
fn double(x: usize) -> usize {
x * 2
}
@@ -10,6 +7,8 @@ const X: fn(usize) -> usize = double;
const fn bar(x: fn(usize) -> usize, y: usize) -> usize {
x(y)
+ //~^ ERROR evaluation of constant value failed
+ //~| ERROR evaluation of constant value failed
}
const Y: usize = bar(X, 2); // FIXME: should fail to typeck someday
@@ -17,7 +16,5 @@ const Z: usize = bar(double, 2); // FIXME: should fail to typeck someday
fn main() {
assert_eq!(Y, 4);
- //~^ ERROR evaluation of constant value failed
assert_eq!(Z, 4);
- //~^ ERROR evaluation of constant value failed
}
diff --git a/src/test/ui/consts/const-eval/const_fn_ptr_fail2.stderr b/src/test/ui/consts/const-eval/const_fn_ptr_fail2.stderr
index f6ffa1ef2..3784a3861 100644
--- a/src/test/ui/consts/const-eval/const_fn_ptr_fail2.stderr
+++ b/src/test/ui/consts/const-eval/const_fn_ptr_fail2.stderr
@@ -1,99 +1,35 @@
error[E0080]: evaluation of constant value failed
- --> $DIR/const_fn_ptr_fail2.rs:19:16
- |
-LL | assert_eq!(Y, 4);
- | ^ referenced constant has errors
-
-error[E0080]: evaluation of constant value failed
- --> $DIR/const_fn_ptr_fail2.rs:21:16
- |
-LL | assert_eq!(Z, 4);
- | ^ referenced constant has errors
-
-warning: skipping const checks
- |
-help: skipping check that does not even have a feature gate
- --> $DIR/const_fn_ptr_fail2.rs:12:5
- |
-LL | x(y)
- | ^^^^
-
-error: aborting due to 2 previous errors; 1 warning emitted
-
-For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/const_fn_ptr_fail2.rs:12:5
+ --> $DIR/const_fn_ptr_fail2.rs:9:5
|
LL | x(y)
| ^^^^
| |
| calling non-const function `double`
- | inside `bar` at $DIR/const_fn_ptr_fail2.rs:12:5
- | inside `Y` at $DIR/const_fn_ptr_fail2.rs:15:18
+ | inside `bar` at $DIR/const_fn_ptr_fail2.rs:9:5
...
LL | const Y: usize = bar(X, 2); // FIXME: should fail to typeck someday
- | --------------
- |
-note: the lint level is defined here
- --> $DIR/const_fn_ptr_fail2.rs:4:10
- |
-LL | #![allow(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | --------- inside `Y` at $DIR/const_fn_ptr_fail2.rs:14:18
-Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/const_fn_ptr_fail2.rs:12:5
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_fn_ptr_fail2.rs:9:5
|
LL | x(y)
| ^^^^
| |
| calling non-const function `double`
- | inside `bar` at $DIR/const_fn_ptr_fail2.rs:12:5
- | inside `Z` at $DIR/const_fn_ptr_fail2.rs:16:18
+ | inside `bar` at $DIR/const_fn_ptr_fail2.rs:9:5
...
LL | const Z: usize = bar(double, 2); // FIXME: should fail to typeck someday
- | --------------
- |
-note: the lint level is defined here
- --> $DIR/const_fn_ptr_fail2.rs:4:10
- |
-LL | #![allow(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | -------------- inside `Z` at $DIR/const_fn_ptr_fail2.rs:15:18
-Future breakage diagnostic:
-warning: erroneous constant used
- --> $DIR/const_fn_ptr_fail2.rs:19:5
- |
-LL | assert_eq!(Y, 4);
- | ^^^^^^^^^^^^^^^^ referenced constant has errors
+warning: skipping const checks
|
-note: the lint level is defined here
- --> $DIR/const_fn_ptr_fail2.rs:4:10
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_fn_ptr_fail2.rs:9:5
|
-LL | #![allow(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this warning originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+LL | x(y)
+ | ^^^^
-Future breakage diagnostic:
-warning: erroneous constant used
- --> $DIR/const_fn_ptr_fail2.rs:21:5
- |
-LL | assert_eq!(Z, 4);
- | ^^^^^^^^^^^^^^^^ referenced constant has errors
- |
-note: the lint level is defined here
- --> $DIR/const_fn_ptr_fail2.rs:4:10
- |
-LL | #![allow(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this warning originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+error: aborting due to 2 previous errors; 1 warning emitted
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/const_let.rs b/src/test/ui/consts/const-eval/const_let.rs
index 18692dbce..1e2bcc55b 100644
--- a/src/test/ui/consts/const-eval/const_let.rs
+++ b/src/test/ui/consts/const-eval/const_let.rs
@@ -14,16 +14,16 @@ const X2: FakeNeedsDrop = { let x; x = FakeNeedsDrop; x };
// error
const Y: FakeNeedsDrop = { let mut x = FakeNeedsDrop; x = FakeNeedsDrop; x };
-//~^ ERROR destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
// error
const Y2: FakeNeedsDrop = { let mut x; x = FakeNeedsDrop; x = FakeNeedsDrop; x };
-//~^ ERROR destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
// error
const Z: () = { let mut x = None; x = Some(FakeNeedsDrop); };
-//~^ ERROR destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
// error
const Z2: () = { let mut x; x = None; x = Some(FakeNeedsDrop); };
-//~^ ERROR destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
diff --git a/src/test/ui/consts/const-eval/const_let.stderr b/src/test/ui/consts/const-eval/const_let.stderr
index 47f39b703..63442f557 100644
--- a/src/test/ui/consts/const-eval/const_let.stderr
+++ b/src/test/ui/consts/const-eval/const_let.stderr
@@ -1,34 +1,34 @@
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `FakeNeedsDrop` cannot be evaluated at compile-time
--> $DIR/const_let.rs:16:32
|
LL | const Y: FakeNeedsDrop = { let mut x = FakeNeedsDrop; x = FakeNeedsDrop; x };
| ^^^^^ - value is dropped here
| |
- | constants cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constants
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `FakeNeedsDrop` cannot be evaluated at compile-time
--> $DIR/const_let.rs:20:33
|
LL | const Y2: FakeNeedsDrop = { let mut x; x = FakeNeedsDrop; x = FakeNeedsDrop; x };
| ^^^^^ - value is dropped here
| |
- | constants cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constants
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<FakeNeedsDrop>` cannot be evaluated at compile-time
--> $DIR/const_let.rs:24:21
|
LL | const Z: () = { let mut x = None; x = Some(FakeNeedsDrop); };
| ^^^^^ - value is dropped here
| |
- | constants cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constants
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<FakeNeedsDrop>` cannot be evaluated at compile-time
--> $DIR/const_let.rs:28:22
|
LL | const Z2: () = { let mut x; x = None; x = Some(FakeNeedsDrop); };
| ^^^^^ - value is dropped here
| |
- | constants cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constants
error: aborting due to 4 previous errors
diff --git a/src/test/ui/consts/const-eval/const_panic_stability.e2018.stderr b/src/test/ui/consts/const-eval/const_panic_stability.e2018.stderr
index f06dedc22..3553a18d3 100644
--- a/src/test/ui/consts/const-eval/const_panic_stability.e2018.stderr
+++ b/src/test/ui/consts/const-eval/const_panic_stability.e2018.stderr
@@ -4,9 +4,9 @@ warning: panic message is not a string literal
LL | panic!({ "foo" });
| ^^^^^^^^^
|
- = note: `#[warn(non_fmt_panics)]` on by default
= note: this usage of `panic!()` is deprecated; it will be a hard error in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
+ = note: `#[warn(non_fmt_panics)]` on by default
help: add a "{}" format string to `Display` the message
|
LL | panic!("{}", { "foo" });
diff --git a/src/test/ui/consts/const-eval/const_raw_ptr_ops.stderr b/src/test/ui/consts/const-eval/const_raw_ptr_ops.stderr
index 168fa0ad0..12244450e 100644
--- a/src/test/ui/consts/const-eval/const_raw_ptr_ops.stderr
+++ b/src/test/ui/consts/const-eval/const_raw_ptr_ops.stderr
@@ -10,16 +10,6 @@ note: the trait `PartialEq<_>` is implemented for `*const i32`, but that impleme
|
LL | const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 };
| ^^
- = help: the following other types implement trait `PartialEq<Rhs>`:
- f32
- f64
- i128
- i16
- i32
- i64
- i8
- isize
- and 6 others
error[E0277]: can't compare `*const i32` with `_` in const contexts
--> $DIR/const_raw_ptr_ops.rs:6:44
@@ -33,16 +23,6 @@ note: the trait `PartialEq<_>` is implemented for `*const i32`, but that impleme
|
LL | const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 };
| ^^
- = help: the following other types implement trait `PartialEq<Rhs>`:
- f32
- f64
- i128
- i16
- i32
- i64
- i8
- isize
- and 6 others
error: aborting due to 2 previous errors
diff --git a/src/test/ui/consts/const-eval/erroneous-const.rs b/src/test/ui/consts/const-eval/erroneous-const.rs
index bee5a7cb3..cf11531ba 100644
--- a/src/test/ui/consts/const-eval/erroneous-const.rs
+++ b/src/test/ui/consts/const-eval/erroneous-const.rs
@@ -1,11 +1,9 @@
//! Make sure we error on erroneous consts even if they are unused.
-#![warn(const_err, unconditional_panic)]
+#![allow(unconditional_panic)]
struct PrintName<T>(T);
impl<T> PrintName<T> {
- const VOID: () = [()][2]; //~WARN any use of this value will cause an error
- //~^ WARN this operation will panic at runtime
- //~| WARN this was previously accepted by the compiler but is being phased out
+ const VOID: () = [()][2]; //~ERROR evaluation of `PrintName::<i32>::VOID` failed
}
const fn no_codegen<T>() {
diff --git a/src/test/ui/consts/const-eval/erroneous-const.stderr b/src/test/ui/consts/const-eval/erroneous-const.stderr
index adfb4cc61..33579135d 100644
--- a/src/test/ui/consts/const-eval/erroneous-const.stderr
+++ b/src/test/ui/consts/const-eval/erroneous-const.stderr
@@ -1,56 +1,21 @@
-warning: this operation will panic at runtime
+error[E0080]: evaluation of `PrintName::<i32>::VOID` failed
--> $DIR/erroneous-const.rs:6:22
|
LL | const VOID: () = [()][2];
| ^^^^^^^ index out of bounds: the length is 1 but the index is 2
- |
-note: the lint level is defined here
- --> $DIR/erroneous-const.rs:2:20
- |
-LL | #![warn(const_err, unconditional_panic)]
- | ^^^^^^^^^^^^^^^^^^^
-
-warning: any use of this value will cause an error
- --> $DIR/erroneous-const.rs:6:22
- |
-LL | const VOID: () = [()][2];
- | -------------- ^^^^^^^ index out of bounds: the length is 1 but the index is 2
- |
-note: the lint level is defined here
- --> $DIR/erroneous-const.rs:2:9
- |
-LL | #![warn(const_err, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error[E0080]: could not evaluate static initializer
- --> $DIR/erroneous-const.rs:15:17
+ --> $DIR/erroneous-const.rs:13:17
|
LL | let _ = PrintName::<T>::VOID;
| ^^^^^^^^^^^^^^^^^^^^
| |
| referenced constant has errors
- | inside `no_codegen::<i32>` at $DIR/erroneous-const.rs:15:17
+ | inside `no_codegen::<i32>` at $DIR/erroneous-const.rs:13:17
...
LL | pub static FOO: () = no_codegen::<i32>();
- | ------------------- inside `FOO` at $DIR/erroneous-const.rs:19:22
+ | ------------------- inside `FOO` at $DIR/erroneous-const.rs:17:22
-error: aborting due to previous error; 2 warnings emitted
+error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/erroneous-const.rs:6:22
- |
-LL | const VOID: () = [()][2];
- | -------------- ^^^^^^^ index out of bounds: the length is 1 but the index is 2
- |
-note: the lint level is defined here
- --> $DIR/erroneous-const.rs:2:9
- |
-LL | #![warn(const_err, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-eval/erroneous-const2.rs b/src/test/ui/consts/const-eval/erroneous-const2.rs
index aa0f093bf..2fbf7be88 100644
--- a/src/test/ui/consts/const-eval/erroneous-const2.rs
+++ b/src/test/ui/consts/const-eval/erroneous-const2.rs
@@ -1,11 +1,9 @@
//! Make sure we error on erroneous consts even if they are unused.
-#![warn(const_err, unconditional_panic)]
+#![allow(unconditional_panic)]
struct PrintName<T>(T);
impl<T> PrintName<T> {
- const VOID: () = [()][2]; //~WARN any use of this value will cause an error
- //~^ WARN this operation will panic at runtime
- //~| WARN this was previously accepted by the compiler but is being phased out
+ const VOID: () = [()][2]; //~ERROR evaluation of `PrintName::<i32>::VOID` failed
}
pub static FOO: () = {
diff --git a/src/test/ui/consts/const-eval/erroneous-const2.stderr b/src/test/ui/consts/const-eval/erroneous-const2.stderr
index e947d93e4..630b1cf16 100644
--- a/src/test/ui/consts/const-eval/erroneous-const2.stderr
+++ b/src/test/ui/consts/const-eval/erroneous-const2.stderr
@@ -1,50 +1,15 @@
-warning: this operation will panic at runtime
+error[E0080]: evaluation of `PrintName::<i32>::VOID` failed
--> $DIR/erroneous-const2.rs:6:22
|
LL | const VOID: () = [()][2];
| ^^^^^^^ index out of bounds: the length is 1 but the index is 2
- |
-note: the lint level is defined here
- --> $DIR/erroneous-const2.rs:2:20
- |
-LL | #![warn(const_err, unconditional_panic)]
- | ^^^^^^^^^^^^^^^^^^^
-
-warning: any use of this value will cause an error
- --> $DIR/erroneous-const2.rs:6:22
- |
-LL | const VOID: () = [()][2];
- | -------------- ^^^^^^^ index out of bounds: the length is 1 but the index is 2
- |
-note: the lint level is defined here
- --> $DIR/erroneous-const2.rs:2:9
- |
-LL | #![warn(const_err, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error[E0080]: could not evaluate static initializer
- --> $DIR/erroneous-const2.rs:15:17
+ --> $DIR/erroneous-const2.rs:13:17
|
LL | let _ = PrintName::<i32>::VOID;
| ^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
-error: aborting due to previous error; 2 warnings emitted
+error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/erroneous-const2.rs:6:22
- |
-LL | const VOID: () = [()][2];
- | -------------- ^^^^^^^ index out of bounds: the length is 1 but the index is 2
- |
-note: the lint level is defined here
- --> $DIR/erroneous-const2.rs:2:9
- |
-LL | #![warn(const_err, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-eval/format.rs b/src/test/ui/consts/const-eval/format.rs
index e43633da3..3eef0d6c3 100644
--- a/src/test/ui/consts/const-eval/format.rs
+++ b/src/test/ui/consts/const-eval/format.rs
@@ -3,8 +3,6 @@ const fn failure() {
//~^ ERROR cannot call non-const formatting macro in constant functions
//~| ERROR erroneous constant used
//~| ERROR erroneous constant used
- //~| WARN this was previously accepted by the compiler
- //~| WARN this was previously accepted by the compiler
}
const fn print() {
@@ -14,8 +12,6 @@ const fn print() {
//~| ERROR cannot call non-const fn `_print` in constant functions
//~| ERROR erroneous constant used
//~| ERROR erroneous constant used
- //~| WARN this was previously accepted by the compiler
- //~| WARN this was previously accepted by the compiler
}
fn main() {}
diff --git a/src/test/ui/consts/const-eval/format.stderr b/src/test/ui/consts/const-eval/format.stderr
index a476b0f58..64c769648 100644
--- a/src/test/ui/consts/const-eval/format.stderr
+++ b/src/test/ui/consts/const-eval/format.stderr
@@ -8,7 +8,7 @@ LL | panic!("{:?}", 0);
= note: this error originates in the macro `$crate::const_format_args` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const formatting macro in constant functions
- --> $DIR/format.rs:11:22
+ --> $DIR/format.rs:9:22
|
LL | println!("{:?}", 0);
| ^
@@ -17,7 +17,7 @@ LL | println!("{:?}", 0);
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `Arguments::<'a>::new_v1` is not yet stable as a const fn
- --> $DIR/format.rs:11:5
+ --> $DIR/format.rs:9:5
|
LL | println!("{:?}", 0);
| ^^^^^^^^^^^^^^^^^^^
@@ -26,7 +26,7 @@ LL | println!("{:?}", 0);
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const fn `_print` in constant functions
- --> $DIR/format.rs:11:5
+ --> $DIR/format.rs:9:5
|
LL | println!("{:?}", 0);
| ^^^^^^^^^^^^^^^^^^^
@@ -34,91 +34,35 @@ LL | println!("{:?}", 0);
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: erroneous constant used
+error[E0080]: erroneous constant used
--> $DIR/format.rs:2:12
|
LL | panic!("{:?}", 0);
| ^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: erroneous constant used
+error[E0080]: erroneous constant used
--> $DIR/format.rs:2:20
|
LL | panic!("{:?}", 0);
| ^ referenced constant has errors
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= note: this error originates in the macro `$crate::const_format_args` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: erroneous constant used
- --> $DIR/format.rs:11:14
+error[E0080]: erroneous constant used
+ --> $DIR/format.rs:9:14
|
LL | println!("{:?}", 0);
| ^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: erroneous constant used
- --> $DIR/format.rs:11:22
+error[E0080]: erroneous constant used
+ --> $DIR/format.rs:9:22
|
LL | println!("{:?}", 0);
| ^ referenced constant has errors
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 8 previous errors
-For more information about this error, try `rustc --explain E0015`.
-Future incompatibility report: Future breakage diagnostic:
-error: erroneous constant used
- --> $DIR/format.rs:2:12
- |
-LL | panic!("{:?}", 0);
- | ^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: erroneous constant used
- --> $DIR/format.rs:2:20
- |
-LL | panic!("{:?}", 0);
- | ^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this error originates in the macro `$crate::const_format_args` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-Future breakage diagnostic:
-error: erroneous constant used
- --> $DIR/format.rs:11:14
- |
-LL | println!("{:?}", 0);
- | ^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: erroneous constant used
- --> $DIR/format.rs:11:22
- |
-LL | println!("{:?}", 0);
- | ^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
-
+Some errors have detailed explanations: E0015, E0080.
+For more information about an error, try `rustc --explain E0015`.
diff --git a/src/test/ui/consts/const-eval/index-out-of-bounds-never-type.rs b/src/test/ui/consts/const-eval/index-out-of-bounds-never-type.rs
index 8064cc493..bc2ea3f18 100644
--- a/src/test/ui/consts/const-eval/index-out-of-bounds-never-type.rs
+++ b/src/test/ui/consts/const-eval/index-out-of-bounds-never-type.rs
@@ -1,21 +1,19 @@
// build-fail
// Regression test for #66975
-#![warn(const_err, unconditional_panic)]
+#![warn(unconditional_panic)]
#![feature(never_type)]
struct PrintName<T>(T);
impl<T> PrintName<T> {
const VOID: ! = { let x = 0 * std::mem::size_of::<T>(); [][x] };
- //~^ WARN any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of `PrintName::<()>::VOID` failed
}
fn f<T>() {
let _ = PrintName::<T>::VOID;
- //~^ ERROR erroneous constant encountered
}
pub fn main() {
diff --git a/src/test/ui/consts/const-eval/index-out-of-bounds-never-type.stderr b/src/test/ui/consts/const-eval/index-out-of-bounds-never-type.stderr
index da4a21e08..8bcd03005 100644
--- a/src/test/ui/consts/const-eval/index-out-of-bounds-never-type.stderr
+++ b/src/test/ui/consts/const-eval/index-out-of-bounds-never-type.stderr
@@ -1,37 +1,15 @@
-warning: any use of this value will cause an error
+error[E0080]: evaluation of `PrintName::<()>::VOID` failed
--> $DIR/index-out-of-bounds-never-type.rs:10:61
|
LL | const VOID: ! = { let x = 0 * std::mem::size_of::<T>(); [][x] };
- | ------------- ^^^^^ index out of bounds: the length is 0 but the index is 0
- |
-note: the lint level is defined here
- --> $DIR/index-out-of-bounds-never-type.rs:4:9
- |
-LL | #![warn(const_err, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^ index out of bounds: the length is 0 but the index is 0
-error: erroneous constant encountered
- --> $DIR/index-out-of-bounds-never-type.rs:17:13
+note: the above error was encountered while instantiating `fn f::<()>`
+ --> $DIR/index-out-of-bounds-never-type.rs:20:5
|
-LL | let _ = PrintName::<T>::VOID;
- | ^^^^^^^^^^^^^^^^^^^^
+LL | f::<()>();
+ | ^^^^^^^^^
-error: aborting due to previous error; 1 warning emitted
-
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/index-out-of-bounds-never-type.rs:10:61
- |
-LL | const VOID: ! = { let x = 0 * std::mem::size_of::<T>(); [][x] };
- | ------------- ^^^^^ index out of bounds: the length is 0 but the index is 0
- |
-note: the lint level is defined here
- --> $DIR/index-out-of-bounds-never-type.rs:4:9
- |
-LL | #![warn(const_err, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+error: aborting due to previous error
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/infinite_loop.rs b/src/test/ui/consts/const-eval/infinite_loop.rs
index 14a573ccf..4babc9a28 100644
--- a/src/test/ui/consts/const-eval/infinite_loop.rs
+++ b/src/test/ui/consts/const-eval/infinite_loop.rs
@@ -4,8 +4,8 @@ fn main() {
let _ = [(); {
let mut n = 113383; // #20 in https://oeis.org/A006884
while n != 0 {
- n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
//~^ ERROR evaluation of constant value failed
+ n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
}
n
}];
diff --git a/src/test/ui/consts/const-eval/infinite_loop.stderr b/src/test/ui/consts/const-eval/infinite_loop.stderr
index 3b5a0f22f..8b58cb279 100644
--- a/src/test/ui/consts/const-eval/infinite_loop.stderr
+++ b/src/test/ui/consts/const-eval/infinite_loop.stderr
@@ -1,8 +1,8 @@
error[E0080]: evaluation of constant value failed
- --> $DIR/infinite_loop.rs:7:20
+ --> $DIR/infinite_loop.rs:6:15
|
-LL | n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
- | ^^^^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`)
+LL | while n != 0 {
+ | ^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`)
error: aborting due to previous error
diff --git a/src/test/ui/consts/const-eval/issue-100878.rs b/src/test/ui/consts/const-eval/issue-100878.rs
new file mode 100644
index 000000000..353ce5050
--- /dev/null
+++ b/src/test/ui/consts/const-eval/issue-100878.rs
@@ -0,0 +1,8 @@
+// This checks that the const-eval ICE in issue #100878 does not recur.
+//
+// build-pass
+pub fn bitshift_data(data: [u8; 1]) -> u8 {
+ data[0] << 8
+}
+
+fn main() {}
diff --git a/src/test/ui/consts/const-eval/issue-43197.rs b/src/test/ui/consts/const-eval/issue-43197.rs
index e15f8771d..145463f0a 100644
--- a/src/test/ui/consts/const-eval/issue-43197.rs
+++ b/src/test/ui/consts/const-eval/issue-43197.rs
@@ -1,23 +1,11 @@
-// build-fail
-
-#![warn(const_err)]
-
const fn foo(x: u32) -> u32 {
x
}
fn main() {
const X: u32 = 0 - 1;
- //~^ WARN any use of this value will cause
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR constant
const Y: u32 = foo(0 - 1);
- //~^ WARN any use of this value will cause
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR constant
println!("{} {}", X, Y);
- //~^ ERROR evaluation of constant value failed
- //~| ERROR evaluation of constant value failed
- //~| WARN erroneous constant used [const_err]
- //~| WARN erroneous constant used [const_err]
- //~| WARN this was previously accepted by the compiler but is being phased out
- //~| WARN this was previously accepted by the compiler but is being phased out
}
diff --git a/src/test/ui/consts/const-eval/issue-43197.stderr b/src/test/ui/consts/const-eval/issue-43197.stderr
index 3f67c38f8..c59f13e48 100644
--- a/src/test/ui/consts/const-eval/issue-43197.stderr
+++ b/src/test/ui/consts/const-eval/issue-43197.stderr
@@ -1,120 +1,15 @@
-warning: any use of this value will cause an error
- --> $DIR/issue-43197.rs:10:20
- |
-LL | const X: u32 = 0 - 1;
- | ------------ ^^^^^ attempt to compute `0_u32 - 1_u32`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/issue-43197.rs:3:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-warning: any use of this value will cause an error
- --> $DIR/issue-43197.rs:13:24
- |
-LL | const Y: u32 = foo(0 - 1);
- | ------------ ^^^^^ attempt to compute `0_u32 - 1_u32`, which would overflow
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
error[E0080]: evaluation of constant value failed
- --> $DIR/issue-43197.rs:16:23
- |
-LL | println!("{} {}", X, Y);
- | ^ referenced constant has errors
-
-warning: erroneous constant used
- --> $DIR/issue-43197.rs:16:23
- |
-LL | println!("{} {}", X, Y);
- | ^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this warning originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error[E0080]: evaluation of constant value failed
- --> $DIR/issue-43197.rs:16:26
- |
-LL | println!("{} {}", X, Y);
- | ^ referenced constant has errors
-
-warning: erroneous constant used
- --> $DIR/issue-43197.rs:16:26
- |
-LL | println!("{} {}", X, Y);
- | ^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this warning originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: aborting due to 2 previous errors; 4 warnings emitted
-
-For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/issue-43197.rs:10:20
+ --> $DIR/issue-43197.rs:6:20
|
LL | const X: u32 = 0 - 1;
- | ------------ ^^^^^ attempt to compute `0_u32 - 1_u32`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/issue-43197.rs:3:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^ attempt to compute `0_u32 - 1_u32`, which would overflow
-Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/issue-43197.rs:13:24
+error[E0080]: evaluation of constant value failed
+ --> $DIR/issue-43197.rs:8:24
|
LL | const Y: u32 = foo(0 - 1);
- | ------------ ^^^^^ attempt to compute `0_u32 - 1_u32`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/issue-43197.rs:3:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^ attempt to compute `0_u32 - 1_u32`, which would overflow
-Future breakage diagnostic:
-warning: erroneous constant used
- --> $DIR/issue-43197.rs:16:23
- |
-LL | println!("{} {}", X, Y);
- | ^ referenced constant has errors
- |
-note: the lint level is defined here
- --> $DIR/issue-43197.rs:3:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this warning originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-Future breakage diagnostic:
-warning: erroneous constant used
- --> $DIR/issue-43197.rs:16:26
- |
-LL | println!("{} {}", X, Y);
- | ^ referenced constant has errors
- |
-note: the lint level is defined here
- --> $DIR/issue-43197.rs:3:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this warning originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+error: aborting due to 2 previous errors
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/issue-44578.rs b/src/test/ui/consts/const-eval/issue-44578.rs
index a88e21970..2dbe1c2bd 100644
--- a/src/test/ui/consts/const-eval/issue-44578.rs
+++ b/src/test/ui/consts/const-eval/issue-44578.rs
@@ -1,7 +1,5 @@
// build-fail
-#![allow(const_err)]
-
trait Foo {
const AMT: usize;
}
@@ -12,7 +10,7 @@ enum Bar<A, B> {
}
impl<A: Foo, B: Foo> Foo for Bar<A, B> {
- const AMT: usize = [A::AMT][(A::AMT > B::AMT) as usize];
+ const AMT: usize = [A::AMT][(A::AMT > B::AMT) as usize]; //~ERROR evaluation of `<Bar<u16, u8> as Foo>::AMT` failed
}
impl Foo for u8 {
@@ -26,4 +24,5 @@ impl Foo for u16 {
fn main() {
println!("{}", <Bar<u16, u8> as Foo>::AMT);
//~^ ERROR evaluation of constant value failed
+ //~| ERROR erroneous constant used
}
diff --git a/src/test/ui/consts/const-eval/issue-44578.stderr b/src/test/ui/consts/const-eval/issue-44578.stderr
index 4c27ceea1..963381b58 100644
--- a/src/test/ui/consts/const-eval/issue-44578.stderr
+++ b/src/test/ui/consts/const-eval/issue-44578.stderr
@@ -1,40 +1,23 @@
+error[E0080]: evaluation of `<Bar<u16, u8> as Foo>::AMT` failed
+ --> $DIR/issue-44578.rs:13:24
+ |
+LL | const AMT: usize = [A::AMT][(A::AMT > B::AMT) as usize];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 1
+
error[E0080]: evaluation of constant value failed
- --> $DIR/issue-44578.rs:27:20
+ --> $DIR/issue-44578.rs:25:20
|
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/issue-44578.rs:15:24
- |
-LL | const AMT: usize = [A::AMT][(A::AMT > B::AMT) as usize];
- | ---------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 1
- |
-note: the lint level is defined here
- --> $DIR/issue-44578.rs:3:10
- |
-LL | #![allow(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-warning: erroneous constant used
- --> $DIR/issue-44578.rs:27:20
+error[E0080]: erroneous constant used
+ --> $DIR/issue-44578.rs:25:20
|
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
|
-note: the lint level is defined here
- --> $DIR/issue-44578.rs:3:10
- |
-LL | #![allow(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this warning originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 3 previous errors
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/issue-50814-2.rs b/src/test/ui/consts/const-eval/issue-50814-2.rs
index 15f4de0ae..49d1d8ff0 100644
--- a/src/test/ui/consts/const-eval/issue-50814-2.rs
+++ b/src/test/ui/consts/const-eval/issue-50814-2.rs
@@ -11,8 +11,7 @@ trait Foo<T> {
struct A<T>(T);
impl<T: C> Foo<T> for A<T> {
- const BAR: usize = [5, 6, 7][T::BOO]; //~ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ const BAR: usize = [5, 6, 7][T::BOO]; //~ ERROR evaluation of `<A<()> as Foo<()>>::BAR` failed
}
fn foo<T: C>() -> &'static usize {
diff --git a/src/test/ui/consts/const-eval/issue-50814-2.stderr b/src/test/ui/consts/const-eval/issue-50814-2.stderr
index cc19caca7..6604f2b9f 100644
--- a/src/test/ui/consts/const-eval/issue-50814-2.stderr
+++ b/src/test/ui/consts/const-eval/issue-50814-2.stderr
@@ -1,21 +1,17 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of `<A<()> as Foo<()>>::BAR` failed
--> $DIR/issue-50814-2.rs:14:24
|
LL | const BAR: usize = [5, 6, 7][T::BOO];
- | ---------------- ^^^^^^^^^^^^^^^^^ index out of bounds: the length is 3 but the index is 42
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^ index out of bounds: the length is 3 but the index is 42
error[E0080]: evaluation of `foo::<()>` failed
- --> $DIR/issue-50814-2.rs:19:6
+ --> $DIR/issue-50814-2.rs:18:6
|
LL | &<A<T> as Foo<T>>::BAR
| ^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
note: the above error was encountered while instantiating `fn foo::<()>`
- --> $DIR/issue-50814-2.rs:31:22
+ --> $DIR/issue-50814-2.rs:30:22
|
LL | println!("{:x}", foo::<()>() as *const usize as usize);
| ^^^^^^^^^^^
@@ -23,14 +19,3 @@ LL | println!("{:x}", foo::<()>() as *const usize as usize);
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/issue-50814-2.rs:14:24
- |
-LL | const BAR: usize = [5, 6, 7][T::BOO];
- | ---------------- ^^^^^^^^^^^^^^^^^ index out of bounds: the length is 3 but the index is 42
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-eval/issue-50814.rs b/src/test/ui/consts/const-eval/issue-50814.rs
index 98229f919..5a587701f 100644
--- a/src/test/ui/consts/const-eval/issue-50814.rs
+++ b/src/test/ui/consts/const-eval/issue-50814.rs
@@ -13,8 +13,7 @@ struct Sum<A,B>(A,B);
impl<A: Unsigned, B: Unsigned> Unsigned for Sum<A,B> {
const MAX: u8 = A::MAX + B::MAX;
- //~^ ERROR any use of this value will cause an error [const_err]
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of `<Sum<U8, U8> as Unsigned>::MAX` failed
}
fn foo<T>(_: T) -> &'static u8 {
diff --git a/src/test/ui/consts/const-eval/issue-50814.stderr b/src/test/ui/consts/const-eval/issue-50814.stderr
index 6ceef91a0..46dd2b89f 100644
--- a/src/test/ui/consts/const-eval/issue-50814.stderr
+++ b/src/test/ui/consts/const-eval/issue-50814.stderr
@@ -1,21 +1,17 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of `<Sum<U8, U8> as Unsigned>::MAX` failed
--> $DIR/issue-50814.rs:15:21
|
LL | const MAX: u8 = A::MAX + B::MAX;
- | ------------- ^^^^^^^^^^^^^^^ attempt to compute `u8::MAX + u8::MAX`, which would overflow
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^ attempt to compute `u8::MAX + u8::MAX`, which would overflow
error[E0080]: evaluation of `foo::<i32>` failed
- --> $DIR/issue-50814.rs:21:6
+ --> $DIR/issue-50814.rs:20:6
|
LL | &Sum::<U8,U8>::MAX
| ^^^^^^^^^^^^^^^^^ referenced constant has errors
note: the above error was encountered while instantiating `fn foo::<i32>`
- --> $DIR/issue-50814.rs:26:5
+ --> $DIR/issue-50814.rs:25:5
|
LL | foo(0);
| ^^^^^^
@@ -23,14 +19,3 @@ LL | foo(0);
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/issue-50814.rs:15:21
- |
-LL | const MAX: u8 = A::MAX + B::MAX;
- | ------------- ^^^^^^^^^^^^^^^ attempt to compute `u8::MAX + u8::MAX`, which would overflow
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-eval/issue-65394.rs b/src/test/ui/consts/const-eval/issue-65394.rs
index 2518e4ed4..e6639826c 100644
--- a/src/test/ui/consts/const-eval/issue-65394.rs
+++ b/src/test/ui/consts/const-eval/issue-65394.rs
@@ -4,7 +4,7 @@
// We will likely have to change this behavior before we allow `&mut` in a `const`.
const _: Vec<i32> = {
- let mut x = Vec::<i32>::new(); //~ ERROR destructors cannot be evaluated at compile-time
+ let mut x = Vec::<i32>::new(); //~ ERROR destructor of
let r = &mut x; //~ ERROR mutable references are not allowed in constants
let y = x;
y
diff --git a/src/test/ui/consts/const-eval/issue-65394.stderr b/src/test/ui/consts/const-eval/issue-65394.stderr
index ec229d7f5..ae6f0e937 100644
--- a/src/test/ui/consts/const-eval/issue-65394.stderr
+++ b/src/test/ui/consts/const-eval/issue-65394.stderr
@@ -7,11 +7,11 @@ LL | let r = &mut x;
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Vec<i32>` cannot be evaluated at compile-time
--> $DIR/issue-65394.rs:7:9
|
LL | let mut x = Vec::<i32>::new();
- | ^^^^^ constants cannot evaluate destructors
+ | ^^^^^ the destructor for this type cannot be evaluated in constants
...
LL | };
| - value is dropped here
diff --git a/src/test/ui/consts/const-eval/livedrop.rs b/src/test/ui/consts/const-eval/livedrop.rs
index 66b7d0580..543f1f0ec 100644
--- a/src/test/ui/consts/const-eval/livedrop.rs
+++ b/src/test/ui/consts/const-eval/livedrop.rs
@@ -1,6 +1,6 @@
const _: Option<Vec<i32>> = {
let mut never_returned = Some(Vec::new());
- let mut always_returned = None; //~ ERROR destructors cannot be evaluated at compile-time
+ let mut always_returned = None; //~ ERROR destructor of
let mut i = 0;
loop {
diff --git a/src/test/ui/consts/const-eval/livedrop.stderr b/src/test/ui/consts/const-eval/livedrop.stderr
index 1e8b4230c..d04fdb70e 100644
--- a/src/test/ui/consts/const-eval/livedrop.stderr
+++ b/src/test/ui/consts/const-eval/livedrop.stderr
@@ -1,8 +1,8 @@
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<Vec<i32>>` cannot be evaluated at compile-time
--> $DIR/livedrop.rs:3:9
|
LL | let mut always_returned = None;
- | ^^^^^^^^^^^^^^^^^^^ constants cannot evaluate destructors
+ | ^^^^^^^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants
...
LL | always_returned = never_returned;
| --------------- value is dropped here
diff --git a/src/test/ui/consts/const-eval/panic-assoc-never-type.rs b/src/test/ui/consts/const-eval/panic-assoc-never-type.rs
index 80b0a1432..d2a840932 100644
--- a/src/test/ui/consts/const-eval/panic-assoc-never-type.rs
+++ b/src/test/ui/consts/const-eval/panic-assoc-never-type.rs
@@ -1,7 +1,6 @@
// build-fail
// Regression test for #66975
-#![warn(const_err)]
#![feature(never_type)]
struct PrintName;
diff --git a/src/test/ui/consts/const-eval/panic-assoc-never-type.stderr b/src/test/ui/consts/const-eval/panic-assoc-never-type.stderr
index b26286411..4204d302b 100644
--- a/src/test/ui/consts/const-eval/panic-assoc-never-type.stderr
+++ b/src/test/ui/consts/const-eval/panic-assoc-never-type.stderr
@@ -1,13 +1,13 @@
error[E0080]: evaluation of constant value failed
- --> $DIR/panic-assoc-never-type.rs:10:21
+ --> $DIR/panic-assoc-never-type.rs:9:21
|
LL | const VOID: ! = panic!();
- | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/panic-assoc-never-type.rs:10:21
+ | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/panic-assoc-never-type.rs:9:21
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0080]: erroneous constant used
- --> $DIR/panic-assoc-never-type.rs:15:13
+ --> $DIR/panic-assoc-never-type.rs:14:13
|
LL | let _ = PrintName::VOID;
| ^^^^^^^^^^^^^^^ referenced constant has errors
diff --git a/src/test/ui/consts/const-eval/panic-never-type.rs b/src/test/ui/consts/const-eval/panic-never-type.rs
index a74d3ba29..a9e9026d9 100644
--- a/src/test/ui/consts/const-eval/panic-never-type.rs
+++ b/src/test/ui/consts/const-eval/panic-never-type.rs
@@ -1,5 +1,4 @@
// Regression test for #66975
-#![warn(const_err)]
#![feature(never_type)]
const VOID: ! = panic!();
diff --git a/src/test/ui/consts/const-eval/panic-never-type.stderr b/src/test/ui/consts/const-eval/panic-never-type.stderr
index 9728aed07..6bff14a45 100644
--- a/src/test/ui/consts/const-eval/panic-never-type.stderr
+++ b/src/test/ui/consts/const-eval/panic-never-type.stderr
@@ -1,8 +1,8 @@
error[E0080]: evaluation of constant value failed
- --> $DIR/panic-never-type.rs:5:17
+ --> $DIR/panic-never-type.rs:4:17
|
LL | const VOID: ! = panic!();
- | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/panic-never-type.rs:5:17
+ | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/panic-never-type.rs:4:17
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/src/test/ui/consts/const-eval/partial_ptr_overwrite.rs b/src/test/ui/consts/const-eval/partial_ptr_overwrite.rs
index 07bca7d64..d6c768868 100644
--- a/src/test/ui/consts/const-eval/partial_ptr_overwrite.rs
+++ b/src/test/ui/consts/const-eval/partial_ptr_overwrite.rs
@@ -5,9 +5,8 @@ const PARTIAL_OVERWRITE: () = {
let mut p = &42;
unsafe {
let ptr: *mut _ = &mut p;
- *(ptr as *mut u8) = 123; //~ ERROR any use of this value
+ *(ptr as *mut u8) = 123; //~ ERROR constant
//~| unable to overwrite parts of a pointer
- //~| WARN previously accepted
}
let x = *p;
};
diff --git a/src/test/ui/consts/const-eval/partial_ptr_overwrite.stderr b/src/test/ui/consts/const-eval/partial_ptr_overwrite.stderr
index 75e50a27b..13ca4379b 100644
--- a/src/test/ui/consts/const-eval/partial_ptr_overwrite.stderr
+++ b/src/test/ui/consts/const-eval/partial_ptr_overwrite.stderr
@@ -1,33 +1,12 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/partial_ptr_overwrite.rs:8:9
|
-LL | const PARTIAL_OVERWRITE: () = {
- | ---------------------------
-...
LL | *(ptr as *mut u8) = 123;
| ^^^^^^^^^^^^^^^^^^^^^^^ unable to overwrite parts of a pointer in memory at alloc4
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error: aborting due to previous error
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/partial_ptr_overwrite.rs:8:9
- |
-LL | const PARTIAL_OVERWRITE: () = {
- | ---------------------------
-...
-LL | *(ptr as *mut u8) = 123;
- | ^^^^^^^^^^^^^^^^^^^^^^^ unable to overwrite parts of a pointer in memory at alloc4
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail.rs b/src/test/ui/consts/const-eval/promoted_const_fn_fail.rs
index 1fc7af637..656dd33e1 100644
--- a/src/test/ui/consts/const-eval/promoted_const_fn_fail.rs
+++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail.rs
@@ -1,5 +1,3 @@
-#![allow(const_err)]
-
#[repr(C)]
union Bar {
a: &'static u8,
diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail.stderr b/src/test/ui/consts/const-eval/promoted_const_fn_fail.stderr
index c6ca30e09..596fa090d 100644
--- a/src/test/ui/consts/const-eval/promoted_const_fn_fail.stderr
+++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail.stderr
@@ -1,5 +1,5 @@
error[E0716]: temporary value dropped while borrowed
- --> $DIR/promoted_const_fn_fail.rs:19:27
+ --> $DIR/promoted_const_fn_fail.rs:17:27
|
LL | let x: &'static u8 = &(bar() + 1);
| ----------- ^^^^^^^^^^^ creates a temporary which is freed while still in use
diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs
index c53424664..5009dbcb9 100644
--- a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs
+++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs
@@ -1,5 +1,3 @@
-#![deny(const_err)]
-
#[repr(C)]
union Bar {
a: &'static u8,
diff --git a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr
index c6275a835..63dc43a41 100644
--- a/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr
+++ b/src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.stderr
@@ -1,5 +1,5 @@
error[E0716]: temporary value dropped while borrowed
- --> $DIR/promoted_const_fn_fail_deny_const_err.rs:20:27
+ --> $DIR/promoted_const_fn_fail_deny_const_err.rs:18:27
|
LL | let x: &'static u8 = &(bar() + 1);
| ----------- ^^^^^^^^^^^ creates a temporary which is freed while still in use
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 cfca8ef07..2a254bfde 100644
--- a/src/test/ui/consts/const-eval/promoted_errors.noopt.stderr
+++ b/src/test/ui/consts/const-eval/promoted_errors.noopt.stderr
@@ -5,111 +5,40 @@ LL | 0 - 1
| ^^^^^ attempt to compute `0_u32 - 1_u32`, which would overflow
|
note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:20
+ --> $DIR/promoted_errors.rs:11:9
|
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^^^^^^^^^^^
+LL | #![warn(arithmetic_overflow, unconditional_panic)]
+ | ^^^^^^^^^^^^^^^^^^^
warning: this operation will panic at runtime
- --> $DIR/promoted_errors.rs:21:5
+ --> $DIR/promoted_errors.rs:19:5
|
LL | 1 / 0
| ^^^^^ attempt to divide `1_i32` by zero
|
note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:41
+ --> $DIR/promoted_errors.rs:11:30
|
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^^^^^^^^^^^
+LL | #![warn(arithmetic_overflow, unconditional_panic)]
+ | ^^^^^^^^^^^^^^^^^^^
warning: this operation will panic at runtime
- --> $DIR/promoted_errors.rs:27:5
+ --> $DIR/promoted_errors.rs:23:5
|
LL | 1 / (1 - 1)
| ^^^^^^^^^^^ attempt to divide `1_i32` by zero
warning: this operation will panic at runtime
- --> $DIR/promoted_errors.rs:31:5
+ --> $DIR/promoted_errors.rs:27:5
|
LL | 1 / (false as i32)
| ^^^^^^^^^^^^^^^^^^ attempt to divide `1_i32` by zero
warning: this operation will panic at runtime
- --> $DIR/promoted_errors.rs:35:5
+ --> $DIR/promoted_errors.rs:31:5
|
LL | [1, 2, 3][4]
| ^^^^^^^^^^^^ index out of bounds: the length is 3 but the index is 4
-warning: any use of this value will cause an error
- --> $DIR/promoted_errors.rs:15:5
- |
-LL | 0 - 1
- | ^^^^^
- | |
- | attempt to compute `0_u32 - 1_u32`, which would overflow
- | inside `overflow` at $DIR/promoted_errors.rs:15:5
- | inside `X` at $DIR/promoted_errors.rs:43:29
-...
-LL | const X: () = {
- | -----------
- |
-note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:9
- |
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-warning: any use of this value will cause an error
- --> $DIR/promoted_errors.rs:43:28
- |
-LL | const X: () = {
- | -----------
-LL | let _x: &'static u32 = &overflow();
- | ^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-warning: 7 warnings emitted
-
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/promoted_errors.rs:15:5
- |
-LL | 0 - 1
- | ^^^^^
- | |
- | attempt to compute `0_u32 - 1_u32`, which would overflow
- | inside `overflow` at $DIR/promoted_errors.rs:15:5
- | inside `X` at $DIR/promoted_errors.rs:43:29
-...
-LL | const X: () = {
- | -----------
- |
-note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:9
- |
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/promoted_errors.rs:43:28
- |
-LL | const X: () = {
- | -----------
-LL | let _x: &'static u32 = &overflow();
- | ^^^^^^^^^^^ referenced constant has errors
- |
-note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:9
- |
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+warning: 5 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 984484a85..2a254bfde 100644
--- a/src/test/ui/consts/const-eval/promoted_errors.opt.stderr
+++ b/src/test/ui/consts/const-eval/promoted_errors.opt.stderr
@@ -5,113 +5,40 @@ LL | 0 - 1
| ^^^^^ attempt to compute `0_u32 - 1_u32`, which would overflow
|
note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:20
+ --> $DIR/promoted_errors.rs:11:9
|
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^^^^^^^^^^^
+LL | #![warn(arithmetic_overflow, unconditional_panic)]
+ | ^^^^^^^^^^^^^^^^^^^
warning: this operation will panic at runtime
- --> $DIR/promoted_errors.rs:21:5
+ --> $DIR/promoted_errors.rs:19:5
|
LL | 1 / 0
| ^^^^^ attempt to divide `1_i32` by zero
|
note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:41
+ --> $DIR/promoted_errors.rs:11:30
|
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^^^^^^^^^^^
+LL | #![warn(arithmetic_overflow, unconditional_panic)]
+ | ^^^^^^^^^^^^^^^^^^^
warning: this operation will panic at runtime
- --> $DIR/promoted_errors.rs:27:5
+ --> $DIR/promoted_errors.rs:23:5
|
LL | 1 / (1 - 1)
| ^^^^^^^^^^^ attempt to divide `1_i32` by zero
warning: this operation will panic at runtime
- --> $DIR/promoted_errors.rs:31:5
+ --> $DIR/promoted_errors.rs:27:5
|
LL | 1 / (false as i32)
| ^^^^^^^^^^^^^^^^^^ attempt to divide `1_i32` by zero
warning: this operation will panic at runtime
- --> $DIR/promoted_errors.rs:35:5
+ --> $DIR/promoted_errors.rs:31:5
|
LL | [1, 2, 3][4]
| ^^^^^^^^^^^^ index out of bounds: the length is 3 but the index is 4
-warning: any use of this value will cause an error
- --> $DIR/promoted_errors.rs:21:5
- |
-LL | 1 / 0
- | ^^^^^
- | |
- | attempt to divide `1_i32` by zero
- | inside `div_by_zero1` at $DIR/promoted_errors.rs:21:5
- | inside `X` at $DIR/promoted_errors.rs:46:29
-...
-LL | const X: () = {
- | -----------
- |
-note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:9
- |
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-warning: any use of this value will cause an error
- --> $DIR/promoted_errors.rs:46:28
- |
-LL | const X: () = {
- | -----------
-...
-LL | let _x: &'static i32 = &div_by_zero1();
- | ^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-warning: 7 warnings emitted
-
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/promoted_errors.rs:21:5
- |
-LL | 1 / 0
- | ^^^^^
- | |
- | attempt to divide `1_i32` by zero
- | inside `div_by_zero1` at $DIR/promoted_errors.rs:21:5
- | inside `X` at $DIR/promoted_errors.rs:46:29
-...
-LL | const X: () = {
- | -----------
- |
-note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:9
- |
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/promoted_errors.rs:46:28
- |
-LL | const X: () = {
- | -----------
-...
-LL | let _x: &'static i32 = &div_by_zero1();
- | ^^^^^^^^^^^^^^^ referenced constant has errors
- |
-note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:9
- |
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+warning: 5 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 cfca8ef07..2a254bfde 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
@@ -5,111 +5,40 @@ LL | 0 - 1
| ^^^^^ attempt to compute `0_u32 - 1_u32`, which would overflow
|
note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:20
+ --> $DIR/promoted_errors.rs:11:9
|
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^^^^^^^^^^^
+LL | #![warn(arithmetic_overflow, unconditional_panic)]
+ | ^^^^^^^^^^^^^^^^^^^
warning: this operation will panic at runtime
- --> $DIR/promoted_errors.rs:21:5
+ --> $DIR/promoted_errors.rs:19:5
|
LL | 1 / 0
| ^^^^^ attempt to divide `1_i32` by zero
|
note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:41
+ --> $DIR/promoted_errors.rs:11:30
|
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^^^^^^^^^^^
+LL | #![warn(arithmetic_overflow, unconditional_panic)]
+ | ^^^^^^^^^^^^^^^^^^^
warning: this operation will panic at runtime
- --> $DIR/promoted_errors.rs:27:5
+ --> $DIR/promoted_errors.rs:23:5
|
LL | 1 / (1 - 1)
| ^^^^^^^^^^^ attempt to divide `1_i32` by zero
warning: this operation will panic at runtime
- --> $DIR/promoted_errors.rs:31:5
+ --> $DIR/promoted_errors.rs:27:5
|
LL | 1 / (false as i32)
| ^^^^^^^^^^^^^^^^^^ attempt to divide `1_i32` by zero
warning: this operation will panic at runtime
- --> $DIR/promoted_errors.rs:35:5
+ --> $DIR/promoted_errors.rs:31:5
|
LL | [1, 2, 3][4]
| ^^^^^^^^^^^^ index out of bounds: the length is 3 but the index is 4
-warning: any use of this value will cause an error
- --> $DIR/promoted_errors.rs:15:5
- |
-LL | 0 - 1
- | ^^^^^
- | |
- | attempt to compute `0_u32 - 1_u32`, which would overflow
- | inside `overflow` at $DIR/promoted_errors.rs:15:5
- | inside `X` at $DIR/promoted_errors.rs:43:29
-...
-LL | const X: () = {
- | -----------
- |
-note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:9
- |
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-warning: any use of this value will cause an error
- --> $DIR/promoted_errors.rs:43:28
- |
-LL | const X: () = {
- | -----------
-LL | let _x: &'static u32 = &overflow();
- | ^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-warning: 7 warnings emitted
-
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/promoted_errors.rs:15:5
- |
-LL | 0 - 1
- | ^^^^^
- | |
- | attempt to compute `0_u32 - 1_u32`, which would overflow
- | inside `overflow` at $DIR/promoted_errors.rs:15:5
- | inside `X` at $DIR/promoted_errors.rs:43:29
-...
-LL | const X: () = {
- | -----------
- |
-note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:9
- |
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/promoted_errors.rs:43:28
- |
-LL | const X: () = {
- | -----------
-LL | let _x: &'static u32 = &overflow();
- | ^^^^^^^^^^^ referenced constant has errors
- |
-note: the lint level is defined here
- --> $DIR/promoted_errors.rs:11:9
- |
-LL | #![warn(const_err, arithmetic_overflow, unconditional_panic)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+warning: 5 warnings emitted
diff --git a/src/test/ui/consts/const-eval/promoted_errors.rs b/src/test/ui/consts/const-eval/promoted_errors.rs
index eb891de33..2c42d0356 100644
--- a/src/test/ui/consts/const-eval/promoted_errors.rs
+++ b/src/test/ui/consts/const-eval/promoted_errors.rs
@@ -8,20 +8,16 @@
//! This test ensures that when we promote code that fails to evaluate, the build still succeeds.
-#![warn(const_err, arithmetic_overflow, unconditional_panic)]
+#![warn(arithmetic_overflow, unconditional_panic)]
// The only way to have promoteds that fail is in `const fn` called from `const`/`static`.
const fn overflow() -> u32 {
0 - 1
- //[opt_with_overflow_checks,noopt]~^ WARN any use of this value will cause an error
- //[opt_with_overflow_checks,noopt]~| WARN this was previously accepted by the compiler
- //~^^^ WARN this arithmetic operation will overflow
+ //~^ WARN this arithmetic operation will overflow
}
const fn div_by_zero1() -> i32 {
1 / 0
- //[opt]~^ WARN any use of this value will cause an error
- //[opt]~| WARN this was previously accepted by the compiler but is being phased out
- //~^^^ WARN this operation will panic at runtime
+ //~^ WARN this operation will panic at runtime
}
const fn div_by_zero2() -> i32 {
1 / (1 - 1)
@@ -36,21 +32,6 @@ const fn oob() -> i32 {
//~^ WARN this operation will panic at runtime
}
-// An unused constant containing failing promoteds.
-// This should work as long as `const_err` can be turned into just a warning;
-// once it turns into a hard error, just remove `X`.
-const X: () = {
- let _x: &'static u32 = &overflow();
- //[opt_with_overflow_checks,noopt]~^ WARN any use of this value will cause an error
- //[opt_with_overflow_checks,noopt]~| WARN this was previously accepted by the compiler
- let _x: &'static i32 = &div_by_zero1();
- //[opt]~^ WARN any use of this value will cause an error
- //[opt]~| WARN this was previously accepted by the compiler but is being phased out
- let _x: &'static i32 = &div_by_zero2();
- let _x: &'static i32 = &div_by_zero3();
- let _x: &'static i32 = &oob();
-};
-
const fn mk_false() -> bool { false }
// An actually used constant referencing failing promoteds in dead code.
diff --git a/src/test/ui/consts/const-eval/pub_const_err.rs b/src/test/ui/consts/const-eval/pub_const_err.rs
deleted file mode 100644
index 5faacd556..000000000
--- a/src/test/ui/consts/const-eval/pub_const_err.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-// check-pass
-#![warn(const_err)]
-
-#![crate_type = "lib"]
-
-pub const Z: u32 = 0 - 1;
-//~^ WARN any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
-
-pub type Foo = [i32; 0 - 1];
diff --git a/src/test/ui/consts/const-eval/pub_const_err.stderr b/src/test/ui/consts/const-eval/pub_const_err.stderr
deleted file mode 100644
index 36197a7ab..000000000
--- a/src/test/ui/consts/const-eval/pub_const_err.stderr
+++ /dev/null
@@ -1,31 +0,0 @@
-warning: any use of this value will cause an error
- --> $DIR/pub_const_err.rs:6:20
- |
-LL | pub const Z: u32 = 0 - 1;
- | ---------------- ^^^^^ attempt to compute `0_u32 - 1_u32`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/pub_const_err.rs:2:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-warning: 1 warning emitted
-
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/pub_const_err.rs:6:20
- |
-LL | pub const Z: u32 = 0 - 1;
- | ---------------- ^^^^^ attempt to compute `0_u32 - 1_u32`, which would overflow
- |
-note: the lint level is defined here
- --> $DIR/pub_const_err.rs:2:9
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-eval/pub_const_err_bin.rs b/src/test/ui/consts/const-eval/pub_const_err_bin.rs
deleted file mode 100644
index 82eae2512..000000000
--- a/src/test/ui/consts/const-eval/pub_const_err_bin.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-// check-pass
-#![warn(const_err)]
-
-pub const Z: u32 = 0 - 1;
-//~^ WARN any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
-
-pub type Foo = [i32; 0 - 1];
-
-fn main() {}
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
deleted file mode 100644
index 2eef3b8f5..000000000
--- a/src/test/ui/consts/const-eval/pub_const_err_bin.stderr
+++ /dev/null
@@ -1,31 +0,0 @@
-warning: any use of this value will cause an error
- --> $DIR/pub_const_err_bin.rs:4:20
- |
-LL | pub const Z: u32 = 0 - 1;
- | ---------------- ^^^^^ 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
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-warning: 1 warning emitted
-
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/pub_const_err_bin.rs:4:20
- |
-LL | pub const Z: u32 = 0 - 1;
- | ---------------- ^^^^^ 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
- |
-LL | #![warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-eval/ref_to_int_match.32bit.stderr b/src/test/ui/consts/const-eval/ref_to_int_match.32bit.stderr
index 30935e415..032ceb246 100644
--- a/src/test/ui/consts/const-eval/ref_to_int_match.32bit.stderr
+++ b/src/test/ui/consts/const-eval/ref_to_int_match.32bit.stderr
@@ -1,12 +1,9 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/ref_to_int_match.rs:25:27
|
LL | const BAR: Int = unsafe { Foo { r: &42 }.f };
- | -------------- ^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
@@ -24,16 +21,4 @@ LL | 10..=BAR => {},
error: aborting due to 3 previous errors
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ref_to_int_match.rs:25:27
- |
-LL | const BAR: Int = unsafe { Foo { r: &42 }.f };
- | -------------- ^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/ref_to_int_match.64bit.stderr b/src/test/ui/consts/const-eval/ref_to_int_match.64bit.stderr
index 30935e415..032ceb246 100644
--- a/src/test/ui/consts/const-eval/ref_to_int_match.64bit.stderr
+++ b/src/test/ui/consts/const-eval/ref_to_int_match.64bit.stderr
@@ -1,12 +1,9 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/ref_to_int_match.rs:25:27
|
LL | const BAR: Int = unsafe { Foo { r: &42 }.f };
- | -------------- ^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
@@ -24,16 +21,4 @@ LL | 10..=BAR => {},
error: aborting due to 3 previous errors
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ref_to_int_match.rs:25:27
- |
-LL | const BAR: Int = unsafe { Foo { r: &42 }.f };
- | -------------- ^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/ref_to_int_match.rs b/src/test/ui/consts/const-eval/ref_to_int_match.rs
index 3f342d916..70c6e7d94 100644
--- a/src/test/ui/consts/const-eval/ref_to_int_match.rs
+++ b/src/test/ui/consts/const-eval/ref_to_int_match.rs
@@ -23,5 +23,4 @@ type Int = u64;
type Int = u32;
const BAR: Int = unsafe { Foo { r: &42 }.f };
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR constant
diff --git a/src/test/ui/consts/const-eval/ub-enum.32bit.stderr b/src/test/ui/consts/const-eval/ub-enum.32bit.stderr
index 752fd01f3..93bc96e67 100644
--- a/src/test/ui/consts/const-eval/ub-enum.32bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-enum.32bit.stderr
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-enum.rs:23:1
+ --> $DIR/ub-enum.rs:24:1
|
LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x00000001, but expected a valid enum tag
@@ -9,31 +9,26 @@ LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
01 00 00 00 │ ....
}
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:26:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-enum.rs:27:1
|
LL | const BAD_ENUM_PTR: Enum = unsafe { mem::transmute(&1) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/ub-enum.rs:30:1
|
LL | const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { mem::transmute(&1) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-enum.rs:43:1
+ --> $DIR/ub-enum.rs:42:1
|
LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x00000000, but expected a valid enum tag
@@ -43,47 +38,41 @@ LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
00 00 00 00 │ ....
}
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:45:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-enum.rs:44:1
|
LL | const BAD_ENUM2_PTR: Enum2 = unsafe { mem::transmute(&0) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:49:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-enum.rs:47:1
|
LL | const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { mem::transmute(&0) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-enum.rs:59:42
+ --> $DIR/ub-enum.rs:56:42
|
LL | const BAD_ENUM2_UNDEF : Enum2 = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:64:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-enum.rs:61:1
|
LL | const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { mem::transmute(&0) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-enum.rs:82:1
+ --> $DIR/ub-enum.rs:78:1
|
LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(B)>.0: encountered a value of the never type `!`
@@ -94,7 +83,7 @@ LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-enum.rs:84:1
+ --> $DIR/ub-enum.rs:80:1
|
LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(D)>.0: encountered a value of uninhabited type Never
@@ -105,7 +94,7 @@ LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-enum.rs:92:1
+ --> $DIR/ub-enum.rs:88:1
|
LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(Some)>.0.1: encountered 0xffffffff, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`)
@@ -116,13 +105,13 @@ LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::tran
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-enum.rs:97:77
+ --> $DIR/ub-enum.rs:93:77
|
LL | const BAD_UNINHABITED_WITH_DATA1: Result<(i32, Never), (i32, !)> = unsafe { mem::transmute(0u64) };
| ^^^^^^^^^^^^^^^^^^^^ transmuting to uninhabited type
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-enum.rs:99:77
+ --> $DIR/ub-enum.rs:95:77
|
LL | const BAD_UNINHABITED_WITH_DATA2: Result<(i32, !), (i32, Never)> = unsafe { mem::transmute(0u64) };
| ^^^^^^^^^^^^^^^^^^^^ transmuting to uninhabited type
@@ -130,68 +119,3 @@ LL | const BAD_UNINHABITED_WITH_DATA2: Result<(i32, !), (i32, Never)> = unsafe {
error: aborting due to 13 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:26:1
- |
-LL | const BAD_ENUM_PTR: Enum = unsafe { mem::transmute(&1) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:30:1
- |
-LL | const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { mem::transmute(&1) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:45:1
- |
-LL | const BAD_ENUM2_PTR: Enum2 = unsafe { mem::transmute(&0) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:49:1
- |
-LL | const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { mem::transmute(&0) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:64:1
- |
-LL | const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { mem::transmute(&0) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
diff --git a/src/test/ui/consts/const-eval/ub-enum.64bit.stderr b/src/test/ui/consts/const-eval/ub-enum.64bit.stderr
index 3f1546a27..280ba25a8 100644
--- a/src/test/ui/consts/const-eval/ub-enum.64bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-enum.64bit.stderr
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-enum.rs:23:1
+ --> $DIR/ub-enum.rs:24:1
|
LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x0000000000000001, but expected a valid enum tag
@@ -9,31 +9,26 @@ LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
01 00 00 00 00 00 00 00 │ ........
}
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:26:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-enum.rs:27:1
|
LL | const BAD_ENUM_PTR: Enum = unsafe { mem::transmute(&1) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/ub-enum.rs:30:1
|
LL | const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { mem::transmute(&1) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-enum.rs:43:1
+ --> $DIR/ub-enum.rs:42:1
|
LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-tag>: encountered 0x0000000000000000, but expected a valid enum tag
@@ -43,47 +38,41 @@ LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
00 00 00 00 00 00 00 00 │ ........
}
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:45:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-enum.rs:44:1
|
LL | const BAD_ENUM2_PTR: Enum2 = unsafe { mem::transmute(&0) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:49:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-enum.rs:47:1
|
LL | const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { mem::transmute(&0) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-enum.rs:59:42
+ --> $DIR/ub-enum.rs:56:42
|
LL | const BAD_ENUM2_UNDEF : Enum2 = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:64:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-enum.rs:61:1
|
LL | const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { mem::transmute(&0) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-enum.rs:82:1
+ --> $DIR/ub-enum.rs:78:1
|
LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(B)>.0: encountered a value of the never type `!`
@@ -94,7 +83,7 @@ LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-enum.rs:84:1
+ --> $DIR/ub-enum.rs:80:1
|
LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(D)>.0: encountered a value of uninhabited type Never
@@ -105,7 +94,7 @@ LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-enum.rs:92:1
+ --> $DIR/ub-enum.rs:88:1
|
LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) }));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<enum-variant(Some)>.0.1: encountered 0xffffffff, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`)
@@ -116,13 +105,13 @@ LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::tran
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-enum.rs:97:77
+ --> $DIR/ub-enum.rs:93:77
|
LL | const BAD_UNINHABITED_WITH_DATA1: Result<(i32, Never), (i32, !)> = unsafe { mem::transmute(0u64) };
| ^^^^^^^^^^^^^^^^^^^^ transmuting to uninhabited type
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-enum.rs:99:77
+ --> $DIR/ub-enum.rs:95:77
|
LL | const BAD_UNINHABITED_WITH_DATA2: Result<(i32, !), (i32, Never)> = unsafe { mem::transmute(0u64) };
| ^^^^^^^^^^^^^^^^^^^^ transmuting to uninhabited type
@@ -130,68 +119,3 @@ LL | const BAD_UNINHABITED_WITH_DATA2: Result<(i32, !), (i32, Never)> = unsafe {
error: aborting due to 13 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:26:1
- |
-LL | const BAD_ENUM_PTR: Enum = unsafe { mem::transmute(&1) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:30:1
- |
-LL | const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { mem::transmute(&1) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:45:1
- |
-LL | const BAD_ENUM2_PTR: Enum2 = unsafe { mem::transmute(&0) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:49:1
- |
-LL | const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { mem::transmute(&0) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-enum.rs:64:1
- |
-LL | const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { mem::transmute(&0) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
diff --git a/src/test/ui/consts/const-eval/ub-enum.rs b/src/test/ui/consts/const-eval/ub-enum.rs
index d8dc6d057..6935be2f9 100644
--- a/src/test/ui/consts/const-eval/ub-enum.rs
+++ b/src/test/ui/consts/const-eval/ub-enum.rs
@@ -1,5 +1,6 @@
// stderr-per-bitwidth
#![feature(never_type)]
+#![allow(invalid_value)]
use std::mem;
@@ -24,12 +25,10 @@ const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
//~^ ERROR is undefined behavior
const BAD_ENUM_PTR: Enum = unsafe { mem::transmute(&1) };
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR evaluation of constant value failed
const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { mem::transmute(&1) };
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR evaluation of constant value failed
// # simple enum with discriminant 2
@@ -43,12 +42,10 @@ enum Enum2 {
const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
//~^ ERROR is undefined behavior
const BAD_ENUM2_PTR: Enum2 = unsafe { mem::transmute(&0) };
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR evaluation of constant value failed
// something wrapping the enum so that we test layout first, not enum
const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { mem::transmute(&0) };
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR evaluation of constant value failed
// Undef enum discriminant.
#[repr(C)]
@@ -62,8 +59,7 @@ const BAD_ENUM2_UNDEF : Enum2 = unsafe { MaybeUninit { uninit: () }.init };
// Pointer value in an enum with a niche that is not just 0.
const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { mem::transmute(&0) };
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR evaluation of constant value failed
// # valid discriminant for uninhabited variant
diff --git a/src/test/ui/consts/const-eval/ub-int-array.32bit.stderr b/src/test/ui/consts/const-eval/ub-int-array.32bit.stderr
index 6100a98d1..edcde13b0 100644
--- a/src/test/ui/consts/const-eval/ub-int-array.32bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-int-array.32bit.stderr
@@ -1,17 +1,17 @@
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-int-array.rs:16:9
+ --> $DIR/ub-int-array.rs:15:9
|
LL | MaybeUninit { uninit: () }.init,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-int-array.rs:31:13
+ --> $DIR/ub-int-array.rs:30:13
|
LL | MaybeUninit { uninit: () }.init,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-int-array.rs:57:13
+ --> $DIR/ub-int-array.rs:56:13
|
LL | MaybeUninit { uninit: () }.init,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
diff --git a/src/test/ui/consts/const-eval/ub-int-array.64bit.stderr b/src/test/ui/consts/const-eval/ub-int-array.64bit.stderr
index 6100a98d1..edcde13b0 100644
--- a/src/test/ui/consts/const-eval/ub-int-array.64bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-int-array.64bit.stderr
@@ -1,17 +1,17 @@
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-int-array.rs:16:9
+ --> $DIR/ub-int-array.rs:15:9
|
LL | MaybeUninit { uninit: () }.init,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-int-array.rs:31:13
+ --> $DIR/ub-int-array.rs:30:13
|
LL | MaybeUninit { uninit: () }.init,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-int-array.rs:57:13
+ --> $DIR/ub-int-array.rs:56:13
|
LL | MaybeUninit { uninit: () }.init,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
diff --git a/src/test/ui/consts/const-eval/ub-int-array.rs b/src/test/ui/consts/const-eval/ub-int-array.rs
index cb85e3b01..a68d3fb17 100644
--- a/src/test/ui/consts/const-eval/ub-int-array.rs
+++ b/src/test/ui/consts/const-eval/ub-int-array.rs
@@ -1,4 +1,3 @@
-#![allow(const_err)] // make sure we cannot allow away the errors tested here
// stderr-per-bitwidth
//! Test the "array of int" fast path in validity checking, and in particular whether it
//! points at the right array element.
diff --git a/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr b/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr
index 693c0e99b..dbd05b8f4 100644
--- a/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr
@@ -10,13 +10,13 @@ LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-nonnull.rs:19:30
+ --> $DIR/ub-nonnull.rs:18:30
|
LL | let out_of_bounds_ptr = &ptr[255];
| ^^^^^^^^ dereferencing pointer failed: alloc11 has size 1, so pointer to 256 bytes starting at offset 0 is out-of-bounds
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-nonnull.rs:23:1
+ --> $DIR/ub-nonnull.rs:22:1
|
LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
@@ -27,7 +27,7 @@ LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-nonnull.rs:25:1
+ --> $DIR/ub-nonnull.rs:24:1
|
LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
@@ -38,13 +38,13 @@ LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-nonnull.rs:33:36
+ --> $DIR/ub-nonnull.rs:32:36
|
LL | const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-nonnull.rs:42:1
+ --> $DIR/ub-nonnull.rs:41:1
|
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 42, but expected something in the range 10..=30
@@ -55,7 +55,7 @@ LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-nonnull.rs:48:1
+ --> $DIR/ub-nonnull.rs:47:1
|
LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 20, but expected something less or equal to 10, or greater or equal to 30
diff --git a/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr b/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr
index d22191213..5a1ac09bd 100644
--- a/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr
@@ -10,13 +10,13 @@ LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-nonnull.rs:19:30
+ --> $DIR/ub-nonnull.rs:18:30
|
LL | let out_of_bounds_ptr = &ptr[255];
| ^^^^^^^^ dereferencing pointer failed: alloc11 has size 1, so pointer to 256 bytes starting at offset 0 is out-of-bounds
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-nonnull.rs:23:1
+ --> $DIR/ub-nonnull.rs:22:1
|
LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
@@ -27,7 +27,7 @@ LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-nonnull.rs:25:1
+ --> $DIR/ub-nonnull.rs:24:1
|
LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1
@@ -38,13 +38,13 @@ LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-nonnull.rs:33:36
+ --> $DIR/ub-nonnull.rs:32:36
|
LL | const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-nonnull.rs:42:1
+ --> $DIR/ub-nonnull.rs:41:1
|
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 42, but expected something in the range 10..=30
@@ -55,7 +55,7 @@ LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-nonnull.rs:48:1
+ --> $DIR/ub-nonnull.rs:47:1
|
LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 20, but expected something less or equal to 10, or greater or equal to 30
diff --git a/src/test/ui/consts/const-eval/ub-nonnull.rs b/src/test/ui/consts/const-eval/ub-nonnull.rs
index 777c6d988..d22a99cd0 100644
--- a/src/test/ui/consts/const-eval/ub-nonnull.rs
+++ b/src/test/ui/consts/const-eval/ub-nonnull.rs
@@ -1,6 +1,6 @@
// stderr-per-bitwidth
#![feature(rustc_attrs)]
-#![allow(const_err, invalid_value)] // make sure we cannot allow away the errors tested here
+#![allow(invalid_value)] // make sure we cannot allow away the errors tested here
use std::mem;
use std::ptr::NonNull;
@@ -12,7 +12,6 @@ const NON_NULL_PTR: NonNull<u8> = unsafe { mem::transmute(&1) };
const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
//~^ ERROR it is undefined behavior to use this value
-#[deny(const_err)] // this triggers a `const_err` so validation does not even happen
const OUT_OF_BOUNDS_PTR: NonNull<u8> = { unsafe {
let ptr: &[u8; 256] = mem::transmute(&0u8); // &0 gets promoted so it does not dangle
// Use address-of-element for pointer arithmetic. This could wrap around to null!
diff --git a/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr b/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr
index 3e93219c8..6f5c028cb 100644
--- a/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-ref-ptr.32bit.stderr
@@ -42,60 +42,47 @@ LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
00 00 00 00 │ ....
}
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/ub-ref-ptr.rs:31:1
|
LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:35:39
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-ref-ptr.rs:34:39
|
LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
- | ---------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:35:38
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-ref-ptr.rs:34:38
|
LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
- | ---------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:41:86
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-ref-ptr.rs:38:86
|
LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
- | ------------------------------------------ ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:41:85
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-ref-ptr.rs:38:85
|
LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
- | ------------------------------------------ ^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-ref-ptr.rs:47:1
+ --> $DIR/ub-ref-ptr.rs:42:1
|
LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (address 0x539 is unallocated)
@@ -106,7 +93,7 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-ref-ptr.rs:50:1
+ --> $DIR/ub-ref-ptr.rs:45:1
|
LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (address 0x539 is unallocated)
@@ -117,13 +104,13 @@ LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-ref-ptr.rs:53:41
+ --> $DIR/ub-ref-ptr.rs:48:41
|
LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-ref-ptr.rs:57:1
+ --> $DIR/ub-ref-ptr.rs:52:1
|
LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a function pointer
@@ -134,13 +121,13 @@ LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-ref-ptr.rs:59:38
+ --> $DIR/ub-ref-ptr.rs:54:38
|
LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-ref-ptr.rs:62:1
+ --> $DIR/ub-ref-ptr.rs:57:1
|
LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0xd[noalloc], but expected a function pointer
@@ -151,7 +138,7 @@ LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-ref-ptr.rs:64:1
+ --> $DIR/ub-ref-ptr.rs:59:1
|
LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered alloc41, but expected a function pointer
@@ -164,64 +151,3 @@ LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
error: aborting due to 16 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:31:1
- |
-LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:35:39
- |
-LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
- | ---------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:35:38
- |
-LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
- | ---------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:41:86
- |
-LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
- | ------------------------------------------ ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:41:85
- |
-LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
- | ------------------------------------------ ^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr b/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr
index bc2aa12a2..5ffb710d4 100644
--- a/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr
@@ -42,60 +42,47 @@ LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
00 00 00 00 00 00 00 00 │ ........
}
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/ub-ref-ptr.rs:31:1
|
LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:35:39
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-ref-ptr.rs:34:39
|
LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
- | ---------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:35:38
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-ref-ptr.rs:34:38
|
LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
- | ---------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:41:86
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-ref-ptr.rs:38:86
|
LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
- | ------------------------------------------ ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:41:85
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-ref-ptr.rs:38:85
|
LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
- | ------------------------------------------ ^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-ref-ptr.rs:47:1
+ --> $DIR/ub-ref-ptr.rs:42:1
|
LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (address 0x539 is unallocated)
@@ -106,7 +93,7 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-ref-ptr.rs:50:1
+ --> $DIR/ub-ref-ptr.rs:45:1
|
LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (address 0x539 is unallocated)
@@ -117,13 +104,13 @@ LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-ref-ptr.rs:53:41
+ --> $DIR/ub-ref-ptr.rs:48:41
|
LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-ref-ptr.rs:57:1
+ --> $DIR/ub-ref-ptr.rs:52:1
|
LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a function pointer
@@ -134,13 +121,13 @@ LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-ref-ptr.rs:59:38
+ --> $DIR/ub-ref-ptr.rs:54:38
|
LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-ref-ptr.rs:62:1
+ --> $DIR/ub-ref-ptr.rs:57:1
|
LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0xd[noalloc], but expected a function pointer
@@ -151,7 +138,7 @@ LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-ref-ptr.rs:64:1
+ --> $DIR/ub-ref-ptr.rs:59:1
|
LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered alloc41, but expected a function pointer
@@ -164,64 +151,3 @@ LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
error: aborting due to 16 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:31:1
- |
-LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:35:39
- |
-LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
- | ---------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:35:38
- |
-LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
- | ---------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:41:86
- |
-LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
- | ------------------------------------------ ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-ref-ptr.rs:41:85
- |
-LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
- | ------------------------------------------ ^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-eval/ub-ref-ptr.rs b/src/test/ui/consts/const-eval/ub-ref-ptr.rs
index c62848f70..92049d4c1 100644
--- a/src/test/ui/consts/const-eval/ub-ref-ptr.rs
+++ b/src/test/ui/consts/const-eval/ub-ref-ptr.rs
@@ -29,20 +29,15 @@ const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
// but that would fail to compile; so we ended up breaking user code that would
// have worked fine had we not promoted.
const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR evaluation of constant value failed
const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
-//~| ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR evaluation of constant value failed
+//~| ERROR evaluation of constant value failed
const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
-//~| ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR evaluation of constant value failed
+//~| ERROR evaluation of constant value failed
const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
//~^ ERROR it is undefined behavior to use this value
diff --git a/src/test/ui/consts/const-eval/ub-uninhabit.32bit.stderr b/src/test/ui/consts/const-eval/ub-uninhabit.32bit.stderr
index 7f0feb130..7d3232257 100644
--- a/src/test/ui/consts/const-eval/ub-uninhabit.32bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-uninhabit.32bit.stderr
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-uninhabit.rs:15:1
+ --> $DIR/ub-uninhabit.rs:14:1
|
LL | const BAD_BAD_BAD: Bar = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a value of uninhabited type Bar
@@ -8,7 +8,7 @@ LL | const BAD_BAD_BAD: Bar = unsafe { MaybeUninit { uninit: () }.init };
= note: the raw bytes of the constant (size: 0, align: 1) {}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-uninhabit.rs:18:1
+ --> $DIR/ub-uninhabit.rs:17:1
|
LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to uninhabited type Bar
@@ -19,7 +19,7 @@ LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-uninhabit.rs:21:1
+ --> $DIR/ub-uninhabit.rs:20:1
|
LL | const BAD_BAD_ARRAY: [Bar; 1] = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0]: encountered a value of uninhabited type Bar
diff --git a/src/test/ui/consts/const-eval/ub-uninhabit.64bit.stderr b/src/test/ui/consts/const-eval/ub-uninhabit.64bit.stderr
index 4dcbbc2f5..2b7659f5d 100644
--- a/src/test/ui/consts/const-eval/ub-uninhabit.64bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-uninhabit.64bit.stderr
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-uninhabit.rs:15:1
+ --> $DIR/ub-uninhabit.rs:14:1
|
LL | const BAD_BAD_BAD: Bar = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a value of uninhabited type Bar
@@ -8,7 +8,7 @@ LL | const BAD_BAD_BAD: Bar = unsafe { MaybeUninit { uninit: () }.init };
= note: the raw bytes of the constant (size: 0, align: 1) {}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-uninhabit.rs:18:1
+ --> $DIR/ub-uninhabit.rs:17:1
|
LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to uninhabited type Bar
@@ -19,7 +19,7 @@ LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-uninhabit.rs:21:1
+ --> $DIR/ub-uninhabit.rs:20:1
|
LL | const BAD_BAD_ARRAY: [Bar; 1] = unsafe { MaybeUninit { uninit: () }.init };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0]: encountered a value of uninhabited type Bar
diff --git a/src/test/ui/consts/const-eval/ub-uninhabit.rs b/src/test/ui/consts/const-eval/ub-uninhabit.rs
index 33fbd14c4..213f15b79 100644
--- a/src/test/ui/consts/const-eval/ub-uninhabit.rs
+++ b/src/test/ui/consts/const-eval/ub-uninhabit.rs
@@ -1,5 +1,4 @@
// stderr-per-bitwidth
-#![allow(const_err)] // make sure we cannot allow away the errors tested here
use std::mem;
diff --git a/src/test/ui/consts/const-eval/ub-upvars.rs b/src/test/ui/consts/const-eval/ub-upvars.rs
index 57dd7b9e5..ceac59870 100644
--- a/src/test/ui/consts/const-eval/ub-upvars.rs
+++ b/src/test/ui/consts/const-eval/ub-upvars.rs
@@ -1,5 +1,5 @@
// stderr-per-bitwidth
-#![allow(const_err, invalid_value)] // make sure we cannot allow away the errors tested here
+#![allow(invalid_value)] // make sure we cannot allow away the errors tested here
use std::mem;
diff --git a/src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr b/src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr
index 4cd974e7b..c8b46608d 100644
--- a/src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:37:1
+ --> $DIR/ub-wide-ptr.rs:36:1
|
LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
@@ -10,7 +10,7 @@ LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:39:1
+ --> $DIR/ub-wide-ptr.rs:38:1
|
LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered invalid reference metadata: slice is bigger than largest supported object
@@ -20,31 +20,26 @@ LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, us
╾─allocN─╼ ff ff ff ff │ ╾──╼....
}
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:42:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:41:1
|
LL | const STR_LENGTH_PTR: &str = unsafe { mem::transmute((&42u8, &3)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:46:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:44:1
|
LL | const MY_STR_LENGTH_PTR: &MyStr = unsafe { mem::transmute((&42u8, &3)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:49:1
+ --> $DIR/ub-wide-ptr.rs:46:1
|
LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
@@ -55,7 +50,7 @@ LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize:
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:53:1
+ --> $DIR/ub-wide-ptr.rs:50:1
|
LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered uninitialized data in `str`
@@ -66,7 +61,7 @@ LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:56:1
+ --> $DIR/ub-wide-ptr.rs:53:1
|
LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered uninitialized data in `str`
@@ -77,13 +72,13 @@ LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUni
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-wide-ptr.rs:63:1
+ --> $DIR/ub-wide-ptr.rs:60:1
|
LL | const SLICE_LENGTH_UNINIT: &[u8] = unsafe {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:70:1
+ --> $DIR/ub-wide-ptr.rs:67:1
|
LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
@@ -94,7 +89,7 @@ LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:73:1
+ --> $DIR/ub-wide-ptr.rs:70:1
|
LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
@@ -104,19 +99,17 @@ LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, is
╾─allocN─╼ ff ff ff 7f │ ╾──╼....
}
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:76:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:73:1
|
LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:80:1
+ --> $DIR/ub-wide-ptr.rs:76:1
|
LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (going beyond the bounds of its allocation)
@@ -126,19 +119,17 @@ LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999us
╾─allocN─╼ e7 03 00 00 │ ╾──╼....
}
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:83:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:79:1
|
LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:88:1
+ --> $DIR/ub-wide-ptr.rs:83:1
|
LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x03, but expected a boolean
@@ -148,17 +139,14 @@ LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
╾─allocN─╼ │ ╾──╼
}
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:88:40
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:83:40
|
LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
- | ------------------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:96:1
+ --> $DIR/ub-wide-ptr.rs:90:1
|
LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered 0x03, but expected a boolean
@@ -168,17 +156,14 @@ LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3
╾allocN─╼ │ ╾──╼
}
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:96:42
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:90:42
|
LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
- | -------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:101:1
+ --> $DIR/ub-wide-ptr.rs:94:1
|
LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.1[0]: encountered 0x03, but expected a boolean
@@ -188,23 +173,20 @@ LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::tran
╾allocN─╼ │ ╾──╼
}
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:101:42
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:94:42
|
LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
- | -------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-wide-ptr.rs:110:1
+ --> $DIR/ub-wide-ptr.rs:102:1
|
LL | const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:119:1
+ --> $DIR/ub-wide-ptr.rs:111:1
|
LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer
@@ -215,7 +197,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:123:1
+ --> $DIR/ub-wide-ptr.rs:115:1
|
LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer
@@ -226,7 +208,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:127:1
+ --> $DIR/ub-wide-ptr.rs:119:1
|
LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0x4[noalloc], but expected a vtable pointer
@@ -237,25 +219,25 @@ LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-wide-ptr.rs:130:57
+ --> $DIR/ub-wide-ptr.rs:122:57
|
LL | const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-wide-ptr.rs:133:57
+ --> $DIR/ub-wide-ptr.rs:125:57
|
LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-wide-ptr.rs:136:56
+ --> $DIR/ub-wide-ptr.rs:128:56
|
LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:139:1
+ --> $DIR/ub-wide-ptr.rs:131:1
|
LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer
@@ -266,7 +248,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::trans
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:144:1
+ --> $DIR/ub-wide-ptr.rs:136:1
|
LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean
@@ -277,7 +259,7 @@ LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_,
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:149:1
+ --> $DIR/ub-wide-ptr.rs:141:1
|
LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a vtable pointer
@@ -288,7 +270,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:151:1
+ --> $DIR/ub-wide-ptr.rs:143:1
|
LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered allocN, but expected a vtable pointer
@@ -299,13 +281,13 @@ LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transm
}
error[E0080]: could not evaluate static initializer
- --> $DIR/ub-wide-ptr.rs:157:5
+ --> $DIR/ub-wide-ptr.rs:149:5
|
LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: null pointer is a dangling pointer (it has no provenance)
error[E0080]: could not evaluate static initializer
- --> $DIR/ub-wide-ptr.rs:161:5
+ --> $DIR/ub-wide-ptr.rs:153:5
|
LL | mem::transmute::<_, &dyn Trait>((&92u8, &3u64))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
@@ -313,88 +295,3 @@ LL | mem::transmute::<_, &dyn Trait>((&92u8, &3u64))
error: aborting due to 32 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:42:1
- |
-LL | const STR_LENGTH_PTR: &str = unsafe { mem::transmute((&42u8, &3)) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:46:1
- |
-LL | const MY_STR_LENGTH_PTR: &MyStr = unsafe { mem::transmute((&42u8, &3)) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:76:1
- |
-LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:83:1
- |
-LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3)) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:88:40
- |
-LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
- | ------------------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:96:42
- |
-LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
- | -------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:101:42
- |
-LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
- | -------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr b/src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr
index 1d84b7bce..70574d2dc 100644
--- a/src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:37:1
+ --> $DIR/ub-wide-ptr.rs:36:1
|
LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
@@ -10,7 +10,7 @@ LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:39:1
+ --> $DIR/ub-wide-ptr.rs:38:1
|
LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered invalid reference metadata: slice is bigger than largest supported object
@@ -20,31 +20,26 @@ LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, us
╾───────allocN───────╼ ff ff ff ff ff ff ff ff │ ╾──────╼........
}
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:42:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:41:1
|
LL | const STR_LENGTH_PTR: &str = unsafe { mem::transmute((&42u8, &3)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:46:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:44:1
|
LL | const MY_STR_LENGTH_PTR: &MyStr = unsafe { mem::transmute((&42u8, &3)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:49:1
+ --> $DIR/ub-wide-ptr.rs:46:1
|
LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
@@ -55,7 +50,7 @@ LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize:
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:53:1
+ --> $DIR/ub-wide-ptr.rs:50:1
|
LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered uninitialized data in `str`
@@ -66,7 +61,7 @@ LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit:
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:56:1
+ --> $DIR/ub-wide-ptr.rs:53:1
|
LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered uninitialized data in `str`
@@ -77,13 +72,13 @@ LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUni
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-wide-ptr.rs:63:1
+ --> $DIR/ub-wide-ptr.rs:60:1
|
LL | const SLICE_LENGTH_UNINIT: &[u8] = unsafe {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:70:1
+ --> $DIR/ub-wide-ptr.rs:67:1
|
LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
@@ -94,7 +89,7 @@ LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:73:1
+ --> $DIR/ub-wide-ptr.rs:70:1
|
LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
@@ -104,19 +99,17 @@ LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, is
╾───────allocN───────╼ ff ff ff ff ff ff ff 7f │ ╾──────╼........
}
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:76:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:73:1
|
LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:80:1
+ --> $DIR/ub-wide-ptr.rs:76:1
|
LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (going beyond the bounds of its allocation)
@@ -126,19 +119,17 @@ LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999us
╾───────allocN───────╼ e7 03 00 00 00 00 00 00 │ ╾──────╼........
}
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:83:1
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:79:1
|
LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:88:1
+ --> $DIR/ub-wide-ptr.rs:83:1
|
LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x03, but expected a boolean
@@ -148,17 +139,14 @@ LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
╾───────allocN───────╼ │ ╾──────╼
}
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:88:40
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:83:40
|
LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
- | ------------------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:96:1
+ --> $DIR/ub-wide-ptr.rs:90:1
|
LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered 0x03, but expected a boolean
@@ -168,17 +156,14 @@ LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3
╾──────allocN───────╼ │ ╾──────╼
}
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:96:42
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:90:42
|
LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
- | -------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:101:1
+ --> $DIR/ub-wide-ptr.rs:94:1
|
LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.1[0]: encountered 0x03, but expected a boolean
@@ -188,23 +173,20 @@ LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::tran
╾──────allocN───────╼ │ ╾──────╼
}
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:101:42
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ub-wide-ptr.rs:94:42
|
LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
- | -------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-wide-ptr.rs:110:1
+ --> $DIR/ub-wide-ptr.rs:102:1
|
LL | const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:119:1
+ --> $DIR/ub-wide-ptr.rs:111:1
|
LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer
@@ -215,7 +197,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:123:1
+ --> $DIR/ub-wide-ptr.rs:115:1
|
LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer
@@ -226,7 +208,7 @@ LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:127:1
+ --> $DIR/ub-wide-ptr.rs:119:1
|
LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0x4[noalloc], but expected a vtable pointer
@@ -237,25 +219,25 @@ LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u
}
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-wide-ptr.rs:130:57
+ --> $DIR/ub-wide-ptr.rs:122:57
|
LL | const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-wide-ptr.rs:133:57
+ --> $DIR/ub-wide-ptr.rs:125:57
|
LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
error[E0080]: evaluation of constant value failed
- --> $DIR/ub-wide-ptr.rs:136:56
+ --> $DIR/ub-wide-ptr.rs:128:56
|
LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:139:1
+ --> $DIR/ub-wide-ptr.rs:131:1
|
LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer
@@ -266,7 +248,7 @@ LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::trans
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:144:1
+ --> $DIR/ub-wide-ptr.rs:136:1
|
LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean
@@ -277,7 +259,7 @@ LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_,
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:149:1
+ --> $DIR/ub-wide-ptr.rs:141:1
|
LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a vtable pointer
@@ -288,7 +270,7 @@ LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/ub-wide-ptr.rs:151:1
+ --> $DIR/ub-wide-ptr.rs:143:1
|
LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered allocN, but expected a vtable pointer
@@ -299,13 +281,13 @@ LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transm
}
error[E0080]: could not evaluate static initializer
- --> $DIR/ub-wide-ptr.rs:157:5
+ --> $DIR/ub-wide-ptr.rs:149:5
|
LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: null pointer is a dangling pointer (it has no provenance)
error[E0080]: could not evaluate static initializer
- --> $DIR/ub-wide-ptr.rs:161:5
+ --> $DIR/ub-wide-ptr.rs:153:5
|
LL | mem::transmute::<_, &dyn Trait>((&92u8, &3u64))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
@@ -313,88 +295,3 @@ LL | mem::transmute::<_, &dyn Trait>((&92u8, &3u64))
error: aborting due to 32 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:42:1
- |
-LL | const STR_LENGTH_PTR: &str = unsafe { mem::transmute((&42u8, &3)) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:46:1
- |
-LL | const MY_STR_LENGTH_PTR: &MyStr = unsafe { mem::transmute((&42u8, &3)) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:76:1
- |
-LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:83:1
- |
-LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3)) };
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:88:40
- |
-LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
- | ------------------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:96:42
- |
-LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
- | -------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ub-wide-ptr.rs:101:42
- |
-LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
- | -------------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-eval/ub-wide-ptr.rs b/src/test/ui/consts/const-eval/ub-wide-ptr.rs
index 788403a6d..65f6f0235 100644
--- a/src/test/ui/consts/const-eval/ub-wide-ptr.rs
+++ b/src/test/ui/consts/const-eval/ub-wide-ptr.rs
@@ -9,8 +9,7 @@ use std::mem;
// normalize-stderr-test "size \d+" -> "size N"
/// A newtype wrapper to prevent MIR generation from inserting reborrows that would affect the error
-/// message. Use this whenever the message is "any use of this value will cause an error" instead of
-/// "it is undefined behavior to use this value".
+/// message.
#[repr(transparent)]
struct W<T>(T);
@@ -40,12 +39,10 @@ const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::
//~^ ERROR it is undefined behavior to use this value
// bad str
const STR_LENGTH_PTR: &str = unsafe { mem::transmute((&42u8, &3)) };
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR evaluation of constant value failed
// bad str in user-defined unsized type
const MY_STR_LENGTH_PTR: &MyStr = unsafe { mem::transmute((&42u8, &3)) };
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR evaluation of constant value failed
const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) };
//~^ ERROR it is undefined behavior to use this value
@@ -74,34 +71,29 @@ const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::
//~^ ERROR it is undefined behavior to use this value
// bad slice: length not an int
const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) };
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR evaluation of constant value failed
// bad slice box: length too big
const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) };
//~^ ERROR it is undefined behavior to use this value
// bad slice box: length not an int
const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3)) };
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR evaluation of constant value failed
// bad data *inside* the slice
const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
//~^ ERROR it is undefined behavior to use this value
-//~| ERROR any use of this value will cause an error
-//~| WARNING this was previously accepted
+//~| ERROR evaluation of constant value failed
// good MySliceBool
const MYSLICE_GOOD: &MySliceBool = &MySlice(true, [false]);
// bad: sized field is not okay
const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
//~^ ERROR it is undefined behavior to use this value
-//~| ERROR any use of this value will cause an error
-//~| WARNING this was previously accepted
+//~| ERROR evaluation of constant value failed
// bad: unsized part is not okay
const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
//~^ ERROR it is undefined behavior to use this value
-//~| ERROR any use of this value will cause an error
-//~| WARNING this was previously accepted
+//~| ERROR evaluation of constant value failed
// # raw slice
const RAW_SLICE_VALID: *const [u8] = unsafe { mem::transmute((&42u8, 1usize)) }; // ok
diff --git a/src/test/ui/consts/const-eval/union-ub.32bit.stderr b/src/test/ui/consts/const-eval/union-ub.32bit.stderr
index 38ded4d65..e5c8f88be 100644
--- a/src/test/ui/consts/const-eval/union-ub.32bit.stderr
+++ b/src/test/ui/consts/const-eval/union-ub.32bit.stderr
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
- --> $DIR/union-ub.rs:33:1
+ --> $DIR/union-ub.rs:32:1
|
LL | const BAD_BOOL: bool = unsafe { DummyUnion { u8: 42 }.bool};
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0x2a, but expected a boolean
@@ -10,7 +10,7 @@ LL | const BAD_BOOL: bool = unsafe { DummyUnion { u8: 42 }.bool};
}
error[E0080]: evaluation of constant value failed
- --> $DIR/union-ub.rs:35:36
+ --> $DIR/union-ub.rs:34:36
|
LL | const UNINIT_BOOL: bool = unsafe { DummyUnion { unit: () }.bool};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
diff --git a/src/test/ui/consts/const-eval/union-ub.64bit.stderr b/src/test/ui/consts/const-eval/union-ub.64bit.stderr
index 38ded4d65..e5c8f88be 100644
--- a/src/test/ui/consts/const-eval/union-ub.64bit.stderr
+++ b/src/test/ui/consts/const-eval/union-ub.64bit.stderr
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
- --> $DIR/union-ub.rs:33:1
+ --> $DIR/union-ub.rs:32:1
|
LL | const BAD_BOOL: bool = unsafe { DummyUnion { u8: 42 }.bool};
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0x2a, but expected a boolean
@@ -10,7 +10,7 @@ LL | const BAD_BOOL: bool = unsafe { DummyUnion { u8: 42 }.bool};
}
error[E0080]: evaluation of constant value failed
- --> $DIR/union-ub.rs:35:36
+ --> $DIR/union-ub.rs:34:36
|
LL | const UNINIT_BOOL: bool = unsafe { DummyUnion { unit: () }.bool};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
diff --git a/src/test/ui/consts/const-eval/union-ub.rs b/src/test/ui/consts/const-eval/union-ub.rs
index bb29edcf8..043870c9c 100644
--- a/src/test/ui/consts/const-eval/union-ub.rs
+++ b/src/test/ui/consts/const-eval/union-ub.rs
@@ -1,5 +1,4 @@
// stderr-per-bitwidth
-#![allow(const_err)] // make sure we cannot allow away the errors tested here
#[repr(C)]
union DummyUnion {
diff --git a/src/test/ui/consts/const-eval/union_promotion.rs b/src/test/ui/consts/const-eval/union_promotion.rs
index 7167f88a1..18894c45f 100644
--- a/src/test/ui/consts/const-eval/union_promotion.rs
+++ b/src/test/ui/consts/const-eval/union_promotion.rs
@@ -1,5 +1,3 @@
-#![allow(const_err)]
-
#[repr(C)]
union Foo {
a: &'static u32,
diff --git a/src/test/ui/consts/const-eval/union_promotion.stderr b/src/test/ui/consts/const-eval/union_promotion.stderr
index ed186e3eb..70808c520 100644
--- a/src/test/ui/consts/const-eval/union_promotion.stderr
+++ b/src/test/ui/consts/const-eval/union_promotion.stderr
@@ -1,5 +1,5 @@
error[E0716]: temporary value dropped while borrowed
- --> $DIR/union_promotion.rs:10:29
+ --> $DIR/union_promotion.rs:8:29
|
LL | let x: &'static bool = &unsafe {
| ____________-------------____^
diff --git a/src/test/ui/consts/const-eval/unused-broken-const.rs b/src/test/ui/consts/const-eval/unused-broken-const.rs
index 3b4523681..0d2776bc2 100644
--- a/src/test/ui/consts/const-eval/unused-broken-const.rs
+++ b/src/test/ui/consts/const-eval/unused-broken-const.rs
@@ -3,7 +3,6 @@
// compile-flags: --emit=dep-info,metadata
const FOO: i32 = [][0];
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR evaluation of constant value failed
fn main() {}
diff --git a/src/test/ui/consts/const-eval/unused-broken-const.stderr b/src/test/ui/consts/const-eval/unused-broken-const.stderr
index df5bd524f..fbb10feb7 100644
--- a/src/test/ui/consts/const-eval/unused-broken-const.stderr
+++ b/src/test/ui/consts/const-eval/unused-broken-const.stderr
@@ -1,23 +1,9 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/unused-broken-const.rs:5:18
|
LL | const FOO: i32 = [][0];
- | -------------- ^^^^^ index out of bounds: the length is 0 but the index is 0
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^ index out of bounds: the length is 0 but the index is 0
error: aborting due to previous error
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/unused-broken-const.rs:5:18
- |
-LL | const FOO: i32 = [][0];
- | -------------- ^^^^^ index out of bounds: the length is 0 but the index is 0
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/valid-const.rs b/src/test/ui/consts/const-eval/valid-const.rs
index 9e4707182..5f47d1c4f 100644
--- a/src/test/ui/consts/const-eval/valid-const.rs
+++ b/src/test/ui/consts/const-eval/valid-const.rs
@@ -1,7 +1,6 @@
// check-pass
// Some constants that *are* valid
-#![deny(const_err)]
use std::mem;
use std::ptr::NonNull;
diff --git a/src/test/ui/consts/const-eval/validate_uninhabited_zsts.32bit.stderr b/src/test/ui/consts/const-eval/validate_uninhabited_zsts.32bit.stderr
index bdaeb4a0f..63639729a 100644
--- a/src/test/ui/consts/const-eval/validate_uninhabited_zsts.32bit.stderr
+++ b/src/test/ui/consts/const-eval/validate_uninhabited_zsts.32bit.stderr
@@ -7,8 +7,8 @@ LL | unsafe { std::mem::transmute(()) }
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
- = note: `#[warn(invalid_value)]` on by default
= note: the `!` type has no valid value
+ = note: `#[warn(invalid_value)]` on by default
error[E0080]: evaluation of constant value failed
--> $DIR/validate_uninhabited_zsts.rs:4:14
@@ -20,10 +20,10 @@ LL | unsafe { std::mem::transmute(()) }
| inside `foo` at $DIR/validate_uninhabited_zsts.rs:4:14
...
LL | const FOO: [empty::Empty; 3] = [foo(); 3];
- | ----- inside `FOO` at $DIR/validate_uninhabited_zsts.rs:20:33
+ | ----- inside `FOO` at $DIR/validate_uninhabited_zsts.rs:19:33
error[E0080]: it is undefined behavior to use this value
- --> $DIR/validate_uninhabited_zsts.rs:23:1
+ --> $DIR/validate_uninhabited_zsts.rs:21:1
|
LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0].0: encountered a value of uninhabited type empty::Void
@@ -32,7 +32,7 @@ LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
= note: the raw bytes of the constant (size: 0, align: 1) {}
warning: the type `empty::Empty` does not permit zero-initialization
- --> $DIR/validate_uninhabited_zsts.rs:23:42
+ --> $DIR/validate_uninhabited_zsts.rs:21:42
|
LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,11 +40,11 @@ LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
-note: enums with no variants have no valid value (in this struct field)
- --> $DIR/validate_uninhabited_zsts.rs:16:22
+note: enums with no inhabited variants have no valid value
+ --> $DIR/validate_uninhabited_zsts.rs:13:5
|
-LL | pub struct Empty(Void);
- | ^^^^
+LL | enum Void {}
+ | ^^^^^^^^^
error: aborting due to 2 previous errors; 2 warnings emitted
diff --git a/src/test/ui/consts/const-eval/validate_uninhabited_zsts.64bit.stderr b/src/test/ui/consts/const-eval/validate_uninhabited_zsts.64bit.stderr
index bdaeb4a0f..63639729a 100644
--- a/src/test/ui/consts/const-eval/validate_uninhabited_zsts.64bit.stderr
+++ b/src/test/ui/consts/const-eval/validate_uninhabited_zsts.64bit.stderr
@@ -7,8 +7,8 @@ LL | unsafe { std::mem::transmute(()) }
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
- = note: `#[warn(invalid_value)]` on by default
= note: the `!` type has no valid value
+ = note: `#[warn(invalid_value)]` on by default
error[E0080]: evaluation of constant value failed
--> $DIR/validate_uninhabited_zsts.rs:4:14
@@ -20,10 +20,10 @@ LL | unsafe { std::mem::transmute(()) }
| inside `foo` at $DIR/validate_uninhabited_zsts.rs:4:14
...
LL | const FOO: [empty::Empty; 3] = [foo(); 3];
- | ----- inside `FOO` at $DIR/validate_uninhabited_zsts.rs:20:33
+ | ----- inside `FOO` at $DIR/validate_uninhabited_zsts.rs:19:33
error[E0080]: it is undefined behavior to use this value
- --> $DIR/validate_uninhabited_zsts.rs:23:1
+ --> $DIR/validate_uninhabited_zsts.rs:21:1
|
LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0].0: encountered a value of uninhabited type empty::Void
@@ -32,7 +32,7 @@ LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
= note: the raw bytes of the constant (size: 0, align: 1) {}
warning: the type `empty::Empty` does not permit zero-initialization
- --> $DIR/validate_uninhabited_zsts.rs:23:42
+ --> $DIR/validate_uninhabited_zsts.rs:21:42
|
LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,11 +40,11 @@ LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
-note: enums with no variants have no valid value (in this struct field)
- --> $DIR/validate_uninhabited_zsts.rs:16:22
+note: enums with no inhabited variants have no valid value
+ --> $DIR/validate_uninhabited_zsts.rs:13:5
|
-LL | pub struct Empty(Void);
- | ^^^^
+LL | enum Void {}
+ | ^^^^^^^^^
error: aborting due to 2 previous errors; 2 warnings emitted
diff --git a/src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs b/src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs
index 96f331275..c0b326215 100644
--- a/src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs
+++ b/src/test/ui/consts/const-eval/validate_uninhabited_zsts.rs
@@ -16,10 +16,8 @@ pub mod empty {
pub struct Empty(Void);
}
-#[warn(const_err)]
const FOO: [empty::Empty; 3] = [foo(); 3];
-#[warn(const_err)]
const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3];
//~^ ERROR it is undefined behavior to use this value
//~| WARN the type `empty::Empty` does not permit zero-initialization
diff --git a/src/test/ui/consts/const-external-macro-const-err.rs b/src/test/ui/consts/const-external-macro-const-err.rs
index 440c42e32..5bd84330b 100644
--- a/src/test/ui/consts/const-external-macro-const-err.rs
+++ b/src/test/ui/consts/const-external-macro-const-err.rs
@@ -9,6 +9,5 @@ extern crate external_macro;
use external_macro::static_assert;
fn main() {
- static_assert!(2 + 2 == 5); //~ ERROR
- //~| WARN this was previously accepted by the compiler but is being phased out
+ static_assert!(2 + 2 == 5); //~ ERROR constant
}
diff --git a/src/test/ui/consts/const-external-macro-const-err.stderr b/src/test/ui/consts/const-external-macro-const-err.stderr
index 205ee92df..81f6c09ff 100644
--- a/src/test/ui/consts/const-external-macro-const-err.stderr
+++ b/src/test/ui/consts/const-external-macro-const-err.stderr
@@ -1,25 +1,11 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/const-external-macro-const-err.rs:12:5
|
LL | static_assert!(2 + 2 == 5);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 1
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= note: this error originates in the macro `static_assert` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-external-macro-const-err.rs:12:5
- |
-LL | static_assert!(2 + 2 == 5);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 1
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this error originates in the macro `static_assert` (in Nightly builds, run with -Z macro-backtrace for more info)
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-float-bits-reject-conv.rs b/src/test/ui/consts/const-float-bits-reject-conv.rs
index b156ded4a..5bf54fdbb 100644
--- a/src/test/ui/consts/const-float-bits-reject-conv.rs
+++ b/src/test/ui/consts/const-float-bits-reject-conv.rs
@@ -28,22 +28,18 @@ fn f32() {
const MASKED_NAN2: u32 = f32::NAN.to_bits() ^ 0x0055_5555;
const_assert!(f32::from_bits(MASKED_NAN1).is_nan());
- //~^ ERROR any use of this value will cause an error
- //~| WARNING this was previously accepted
+ //~^ ERROR evaluation of constant value failed
const_assert!(f32::from_bits(MASKED_NAN1).is_nan());
- //~^ ERROR any use of this value will cause an error
- //~| WARNING this was previously accepted
+ //~^ ERROR evaluation of constant value failed
// LLVM does not guarantee that loads and stores of NaNs preserve their exact bit pattern.
// In practice, this seems to only cause a problem on x86, since the most widely used calling
// convention mandates that floating point values are returned on the x87 FPU stack. See #73328.
if !cfg!(target_arch = "x86") {
const_assert!(f32::from_bits(MASKED_NAN1).to_bits(), MASKED_NAN1);
- //~^ ERROR any use of this value will cause an error
- //~| WARNING this was previously accepted
+ //~^ ERROR evaluation of constant value failed
const_assert!(f32::from_bits(MASKED_NAN2).to_bits(), MASKED_NAN2);
- //~^ ERROR any use of this value will cause an error
- //~| WARNING this was previously accepted
+ //~^ ERROR evaluation of constant value failed
}
}
@@ -55,20 +51,16 @@ fn f64() {
const MASKED_NAN2: u64 = f64::NAN.to_bits() ^ 0x0005_5555_5555_5555;
const_assert!(f64::from_bits(MASKED_NAN1).is_nan());
- //~^ ERROR any use of this value will cause an error
- //~| WARNING this was previously accepted
+ //~^ ERROR evaluation of constant value failed
const_assert!(f64::from_bits(MASKED_NAN1).is_nan());
- //~^ ERROR any use of this value will cause an error
- //~| WARNING this was previously accepted
+ //~^ ERROR evaluation of constant value failed
// See comment above.
if !cfg!(target_arch = "x86") {
const_assert!(f64::from_bits(MASKED_NAN1).to_bits(), MASKED_NAN1);
- //~^ ERROR any use of this value will cause an error
- //~| WARNING this was previously accepted
+ //~^ ERROR evaluation of constant value failed
const_assert!(f64::from_bits(MASKED_NAN2).to_bits(), MASKED_NAN2);
- //~^ ERROR any use of this value will cause an error
- //~| WARNING this was previously accepted
+ //~^ ERROR evaluation of constant value failed
}
}
diff --git a/src/test/ui/consts/const-float-bits-reject-conv.stderr b/src/test/ui/consts/const-float-bits-reject-conv.stderr
index 01f2f4895..b3575f641 100644
--- a/src/test/ui/consts/const-float-bits-reject-conv.stderr
+++ b/src/test/ui/consts/const-float-bits-reject-conv.stderr
@@ -36,54 +36,29 @@ LL | const MASKED_NAN2: u32 = f32::NAN.to_bits() ^ 0x0055_5555;
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/const-float-bits-reject-conv.rs:30:34
|
-LL | const _: () = assert!($a);
- | -----------
-...
LL | const_assert!(f32::from_bits(MASKED_NAN1).is_nan());
| ^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:33:34
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-float-bits-reject-conv.rs:32:34
|
-LL | const _: () = assert!($a);
- | -----------
-...
LL | const_assert!(f32::from_bits(MASKED_NAN1).is_nan());
| ^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:41:38
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-float-bits-reject-conv.rs:39:38
|
-LL | const _: () = assert!($a == $b);
- | -----------
-...
LL | const_assert!(f32::from_bits(MASKED_NAN1).to_bits(), MASKED_NAN1);
| ^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:44:38
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-float-bits-reject-conv.rs:41:38
|
-LL | const _: () = assert!($a == $b);
- | -----------
-...
LL | const_assert!(f32::from_bits(MASKED_NAN2).to_bits(), MASKED_NAN2);
| ^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/num/f64.rs:LL:COL
@@ -97,10 +72,10 @@ LL | panic!("const-eval error: cannot use f64::to_bits on a
LL | unsafe { intrinsics::const_eval_select((self,), ct_f64_to_u64, rt_f64_to_u64) }
| -------------------------------------------------------------------- inside `core::f64::<impl f64>::to_bits` at $SRC_DIR/core/src/num/f64.rs:LL:COL
|
- ::: $DIR/const-float-bits-reject-conv.rs:54:30
+ ::: $DIR/const-float-bits-reject-conv.rs:50:30
|
LL | const MASKED_NAN1: u64 = f64::NAN.to_bits() ^ 0x000A_AAAA_AAAA_AAAA;
- | ------------------ inside `f64::MASKED_NAN1` at $DIR/const-float-bits-reject-conv.rs:54:30
+ | ------------------ inside `f64::MASKED_NAN1` at $DIR/const-float-bits-reject-conv.rs:50:30
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -116,173 +91,37 @@ LL | panic!("const-eval error: cannot use f64::to_bits on a
LL | unsafe { intrinsics::const_eval_select((self,), ct_f64_to_u64, rt_f64_to_u64) }
| -------------------------------------------------------------------- inside `core::f64::<impl f64>::to_bits` at $SRC_DIR/core/src/num/f64.rs:LL:COL
|
- ::: $DIR/const-float-bits-reject-conv.rs:55:30
+ ::: $DIR/const-float-bits-reject-conv.rs:51:30
|
LL | const MASKED_NAN2: u64 = f64::NAN.to_bits() ^ 0x0005_5555_5555_5555;
- | ------------------ inside `f64::MASKED_NAN2` at $DIR/const-float-bits-reject-conv.rs:55:30
+ | ------------------ inside `f64::MASKED_NAN2` at $DIR/const-float-bits-reject-conv.rs:51:30
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:57:34
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-float-bits-reject-conv.rs:53:34
|
-LL | const _: () = assert!($a);
- | -----------
-...
LL | const_assert!(f64::from_bits(MASKED_NAN1).is_nan());
| ^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:60:34
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-float-bits-reject-conv.rs:55:34
|
-LL | const _: () = assert!($a);
- | -----------
-...
LL | const_assert!(f64::from_bits(MASKED_NAN1).is_nan());
| ^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:66:38
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-float-bits-reject-conv.rs:60:38
|
-LL | const _: () = assert!($a == $b);
- | -----------
-...
LL | const_assert!(f64::from_bits(MASKED_NAN1).to_bits(), MASKED_NAN1);
| ^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:69:38
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-float-bits-reject-conv.rs:62:38
|
-LL | const _: () = assert!($a == $b);
- | -----------
-...
LL | const_assert!(f64::from_bits(MASKED_NAN2).to_bits(), MASKED_NAN2);
| ^^^^^^^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: aborting due to 12 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:30:34
- |
-LL | const _: () = assert!($a);
- | -----------
-...
-LL | const_assert!(f32::from_bits(MASKED_NAN1).is_nan());
- | ^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:33:34
- |
-LL | const _: () = assert!($a);
- | -----------
-...
-LL | const_assert!(f32::from_bits(MASKED_NAN1).is_nan());
- | ^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:41:38
- |
-LL | const _: () = assert!($a == $b);
- | -----------
-...
-LL | const_assert!(f32::from_bits(MASKED_NAN1).to_bits(), MASKED_NAN1);
- | ^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:44:38
- |
-LL | const _: () = assert!($a == $b);
- | -----------
-...
-LL | const_assert!(f32::from_bits(MASKED_NAN2).to_bits(), MASKED_NAN2);
- | ^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:57:34
- |
-LL | const _: () = assert!($a);
- | -----------
-...
-LL | const_assert!(f64::from_bits(MASKED_NAN1).is_nan());
- | ^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:60:34
- |
-LL | const _: () = assert!($a);
- | -----------
-...
-LL | const_assert!(f64::from_bits(MASKED_NAN1).is_nan());
- | ^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:66:38
- |
-LL | const _: () = assert!($a == $b);
- | -----------
-...
-LL | const_assert!(f64::from_bits(MASKED_NAN1).to_bits(), MASKED_NAN1);
- | ^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-float-bits-reject-conv.rs:69:38
- |
-LL | const _: () = assert!($a == $b);
- | -----------
-...
-LL | const_assert!(f64::from_bits(MASKED_NAN2).to_bits(), MASKED_NAN2);
- | ^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-fn-error.rs b/src/test/ui/consts/const-fn-error.rs
index abe68c17a..50b7ce1f8 100644
--- a/src/test/ui/consts/const-fn-error.rs
+++ b/src/test/ui/consts/const-fn-error.rs
@@ -3,10 +3,10 @@ const X : usize = 2;
const fn f(x: usize) -> usize {
let mut sum = 0;
for i in 0..x {
- //~^ ERROR mutable references
- //~| ERROR cannot convert
- //~| ERROR cannot call non-const fn
+ //~^ ERROR cannot convert
//~| ERROR `for` is not allowed in a `const fn`
+ //~| ERROR mutable references are not allowed in constant functions
+ //~| ERROR cannot call non-const fn
sum += i;
}
sum
diff --git a/src/test/ui/consts/const-fn-error.stderr b/src/test/ui/consts/const-fn-error.stderr
index e36324f0b..02960b363 100644
--- a/src/test/ui/consts/const-fn-error.stderr
+++ b/src/test/ui/consts/const-fn-error.stderr
@@ -22,8 +22,8 @@ LL | for i in 0..x {
note: impl defined here, but it is not `const`
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
|
-LL | impl<I: ~const Iterator> const IntoIterator for I {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | impl<I: Iterator> const IntoIterator for I {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0658]: mutable references are not allowed in constant functions
diff --git a/src/test/ui/consts/const-for.rs b/src/test/ui/consts/const-for.rs
index 58bcb5f74..8db248535 100644
--- a/src/test/ui/consts/const-for.rs
+++ b/src/test/ui/consts/const-for.rs
@@ -3,8 +3,8 @@
const _: () = {
for _ in 0..5 {}
- //~^ error: cannot convert
- //~| error: cannot call non-const fn
+ //~^ error: cannot call
+ //~| error: cannot convert
};
fn main() {}
diff --git a/src/test/ui/consts/const-for.stderr b/src/test/ui/consts/const-for.stderr
index f2e1c8a49..11e4ae309 100644
--- a/src/test/ui/consts/const-for.stderr
+++ b/src/test/ui/consts/const-for.stderr
@@ -7,8 +7,8 @@ LL | for _ in 0..5 {}
note: impl defined here, but it is not `const`
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
|
-LL | impl<I: ~const Iterator> const IntoIterator for I {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | impl<I: Iterator> const IntoIterator for I {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const fn `<std::ops::Range<i32> as Iterator>::next` in constants
diff --git a/src/test/ui/consts/const-int-arithmetic-overflow.rs b/src/test/ui/consts/const-int-arithmetic-overflow.rs
index 99bbeaafd..6446e9451 100644
--- a/src/test/ui/consts/const-int-arithmetic-overflow.rs
+++ b/src/test/ui/consts/const-int-arithmetic-overflow.rs
@@ -1,6 +1,5 @@
// run-pass
// compile-flags: -O
-#![allow(const_err)]
// Make sure arithmetic unary/binary ops actually return the right result, even when overflowing.
// We have to put them in `const fn` and turn on optimizations to avoid overflow checks.
diff --git a/src/test/ui/consts/const-len-underflow-separate-spans.rs b/src/test/ui/consts/const-len-underflow-separate-spans.rs
index 7c3d1f320..478761aef 100644
--- a/src/test/ui/consts/const-len-underflow-separate-spans.rs
+++ b/src/test/ui/consts/const-len-underflow-separate-spans.rs
@@ -5,8 +5,7 @@
const ONE: usize = 1;
const TWO: usize = 2;
const LEN: usize = ONE - TWO;
-//~^ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~^ ERROR constant
fn main() {
let a: [i8; LEN] = unimplemented!();
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 d1bf4b92e..1416e695e 100644
--- a/src/test/ui/consts/const-len-underflow-separate-spans.stderr
+++ b/src/test/ui/consts/const-len-underflow-separate-spans.stderr
@@ -1,15 +1,11 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/const-len-underflow-separate-spans.rs:7:20
|
LL | const LEN: usize = ONE - TWO;
- | ---------------- ^^^^^^^^^ attempt to compute `1_usize - 2_usize`, which would overflow
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^ attempt to compute `1_usize - 2_usize`, which would overflow
error[E0080]: evaluation of constant value failed
- --> $DIR/const-len-underflow-separate-spans.rs:12:17
+ --> $DIR/const-len-underflow-separate-spans.rs:11:17
|
LL | let a: [i8; LEN] = unimplemented!();
| ^^^ referenced constant has errors
@@ -17,14 +13,3 @@ LL | let a: [i8; LEN] = unimplemented!();
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-len-underflow-separate-spans.rs:7:20
- |
-LL | const LEN: usize = ONE - TWO;
- | ---------------- ^^^^^^^^^ attempt to compute `1_usize - 2_usize`, which would overflow
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/const-negation.rs b/src/test/ui/consts/const-negation.rs
index 26c3c0b83..18bcdfb01 100644
--- a/src/test/ui/consts/const-negation.rs
+++ b/src/test/ui/consts/const-negation.rs
@@ -1,8 +1,6 @@
// run-pass
#![allow(overflowing_literals)]
-#[deny(const_err)]
-
fn main() {
#[cfg(target_pointer_width = "32")]
const I: isize = -2147483648isize;
diff --git a/src/test/ui/consts/const-prop-read-static-in-const.rs b/src/test/ui/consts/const-prop-read-static-in-const.rs
index a65b707f0..214262059 100644
--- a/src/test/ui/consts/const-prop-read-static-in-const.rs
+++ b/src/test/ui/consts/const-prop-read-static-in-const.rs
@@ -2,8 +2,7 @@
#![allow(dead_code)]
-const TEST: u8 = MY_STATIC; //~ ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+const TEST: u8 = MY_STATIC; //~ ERROR constant
static MY_STATIC: u8 = 4;
diff --git a/src/test/ui/consts/const-prop-read-static-in-const.stderr b/src/test/ui/consts/const-prop-read-static-in-const.stderr
index ea5ad24b0..793da6285 100644
--- a/src/test/ui/consts/const-prop-read-static-in-const.stderr
+++ b/src/test/ui/consts/const-prop-read-static-in-const.stderr
@@ -1,12 +1,8 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/const-prop-read-static-in-const.rs:5:18
|
LL | const TEST: u8 = MY_STATIC;
- | -------------- ^^^^^^^^^ constant accesses static
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^ constant accesses static
warning: skipping const checks
|
@@ -18,14 +14,4 @@ LL | const TEST: u8 = MY_STATIC;
error: aborting due to previous error; 1 warning emitted
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-prop-read-static-in-const.rs:5:18
- |
-LL | const TEST: u8 = MY_STATIC;
- | -------------- ^^^^^^^^^ constant accesses static
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-size_of_val-align_of_val-extern-type.rs b/src/test/ui/consts/const-size_of_val-align_of_val-extern-type.rs
index 665371777..4df3a793b 100644
--- a/src/test/ui/consts/const-size_of_val-align_of_val-extern-type.rs
+++ b/src/test/ui/consts/const-size_of_val-align_of_val-extern-type.rs
@@ -8,9 +8,7 @@ extern "C" {
type Opaque;
}
-const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) }; //~ ERROR
-//~| WARN this was previously accepted by the compiler but is being phased out
-const _ALIGN: usize = unsafe { min_align_of_val(&4 as *const i32 as *const Opaque) }; //~ ERROR
-//~| WARN this was previously accepted by the compiler but is being phased out
+const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) }; //~ ERROR constant
+const _ALIGN: usize = unsafe { min_align_of_val(&4 as *const i32 as *const Opaque) }; //~ ERROR constant
fn main() {}
diff --git a/src/test/ui/consts/const-size_of_val-align_of_val-extern-type.stderr b/src/test/ui/consts/const-size_of_val-align_of_val-extern-type.stderr
index d19a89378..ad2de0f4d 100644
--- a/src/test/ui/consts/const-size_of_val-align_of_val-extern-type.stderr
+++ b/src/test/ui/consts/const-size_of_val-align_of_val-extern-type.stderr
@@ -1,43 +1,15 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:11:31
|
LL | const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) };
- | ------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `extern type` does not have known layout
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `extern type` does not have known layout
-error: any use of this value will cause an error
- --> $DIR/const-size_of_val-align_of_val-extern-type.rs:13:32
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-size_of_val-align_of_val-extern-type.rs:12:32
|
LL | const _ALIGN: usize = unsafe { min_align_of_val(&4 as *const i32 as *const Opaque) };
- | ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `extern type` does not have known layout
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `extern type` does not have known layout
error: aborting due to 2 previous errors
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-size_of_val-align_of_val-extern-type.rs:11:31
- |
-LL | const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) };
- | ------------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `extern type` does not have known layout
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-size_of_val-align_of_val-extern-type.rs:13:32
- |
-LL | const _ALIGN: usize = unsafe { min_align_of_val(&4 as *const i32 as *const Opaque) };
- | ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `extern type` does not have known layout
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-slice-oob.rs b/src/test/ui/consts/const-slice-oob.rs
index 35e5a4d22..429b97821 100644
--- a/src/test/ui/consts/const-slice-oob.rs
+++ b/src/test/ui/consts/const-slice-oob.rs
@@ -1,10 +1,7 @@
-#[deny(const_err)]
-
const FOO: &'static[u32] = &[1, 2, 3];
const BAR: u32 = FOO[5];
//~^ index out of bounds: the length is 3 but the index is 5
-//~| ERROR any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler but is being phased out
+//~| ERROR evaluation of constant value failed
fn main() {
let _ = BAR;
diff --git a/src/test/ui/consts/const-slice-oob.stderr b/src/test/ui/consts/const-slice-oob.stderr
index 27c21e7af..746883a79 100644
--- a/src/test/ui/consts/const-slice-oob.stderr
+++ b/src/test/ui/consts/const-slice-oob.stderr
@@ -1,23 +1,9 @@
-error: any use of this value will cause an error
- --> $DIR/const-slice-oob.rs:4:18
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const-slice-oob.rs:2:18
|
LL | const BAR: u32 = FOO[5];
- | -------------- ^^^^^^ index out of bounds: the length is 3 but the index is 5
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ^^^^^^ index out of bounds: the length is 3 but the index is 5
error: aborting due to previous error
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const-slice-oob.rs:4:18
- |
-LL | const BAR: u32 = FOO[5];
- | -------------- ^^^^^^ index out of bounds: the length is 3 but the index is 5
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const_discriminant.rs b/src/test/ui/consts/const_discriminant.rs
index f623c5101..79e68590e 100644
--- a/src/test/ui/consts/const_discriminant.rs
+++ b/src/test/ui/consts/const_discriminant.rs
@@ -1,6 +1,5 @@
// run-pass
#![feature(const_discriminant)]
-#![feature(bench_black_box)]
#![allow(dead_code)]
use std::mem::{discriminant, Discriminant};
diff --git a/src/test/ui/consts/const_in_pattern/custom-eq-branch-warn.stderr b/src/test/ui/consts/const_in_pattern/custom-eq-branch-warn.stderr
index e51d6f916..223482722 100644
--- a/src/test/ui/consts/const_in_pattern/custom-eq-branch-warn.stderr
+++ b/src/test/ui/consts/const_in_pattern/custom-eq-branch-warn.stderr
@@ -4,9 +4,9 @@ warning: to use a constant of type `CustomEq` in a pattern, the constant's initi
LL | BAR_BAZ => panic!(),
| ^^^^^^^
|
- = note: `#[warn(nontrivial_structural_match)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
+ = note: `#[warn(nontrivial_structural_match)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/consts/const_in_pattern/incomplete-slice.stderr b/src/test/ui/consts/const_in_pattern/incomplete-slice.stderr
index 0ff708371..ddc576ced 100644
--- a/src/test/ui/consts/const_in_pattern/incomplete-slice.stderr
+++ b/src/test/ui/consts/const_in_pattern/incomplete-slice.stderr
@@ -4,9 +4,9 @@ warning: to use a constant of type `E` in a pattern, `E` must be annotated with
LL | E_SL => {}
| ^^^^
|
- = note: `#[warn(indirect_structural_match)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
+ = note: `#[warn(indirect_structural_match)]` on by default
error[E0004]: non-exhaustive patterns: `&_` not covered
--> $DIR/incomplete-slice.rs:9:11
diff --git a/src/test/ui/consts/const_in_pattern/issue-44333.stderr b/src/test/ui/consts/const_in_pattern/issue-44333.stderr
index 8302b09e5..731ef509c 100644
--- a/src/test/ui/consts/const_in_pattern/issue-44333.stderr
+++ b/src/test/ui/consts/const_in_pattern/issue-44333.stderr
@@ -4,13 +4,13 @@ warning: function pointers and unsized pointers in patterns behave unpredictably
LL | FOO => println!("foo"),
| ^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
note: the lint level is defined here
--> $DIR/issue-44333.rs:3:9
|
LL | #![warn(pointer_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
warning: function pointers and unsized pointers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
--> $DIR/issue-44333.rs:21:9
diff --git a/src/test/ui/consts/const_in_pattern/reject_non_structural.stderr b/src/test/ui/consts/const_in_pattern/reject_non_structural.stderr
index 56405a55d..660198349 100644
--- a/src/test/ui/consts/const_in_pattern/reject_non_structural.stderr
+++ b/src/test/ui/consts/const_in_pattern/reject_non_structural.stderr
@@ -64,13 +64,13 @@ warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be a
LL | match &Some(NoDerive) { ADDR_OF => dbg!(ADDR_OF), _ => panic!("whoops"), };
| ^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
note: the lint level is defined here
--> $DIR/reject_non_structural.rs:12:9
|
LL | #![warn(indirect_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
error: aborting due to 10 previous errors; 1 warning emitted
diff --git a/src/test/ui/consts/const_in_pattern/warn_corner_cases.stderr b/src/test/ui/consts/const_in_pattern/warn_corner_cases.stderr
index a24c8d181..e957a43a1 100644
--- a/src/test/ui/consts/const_in_pattern/warn_corner_cases.stderr
+++ b/src/test/ui/consts/const_in_pattern/warn_corner_cases.stderr
@@ -4,9 +4,9 @@ warning: to use a constant of type `NoDerive` in a pattern, the constant's initi
LL | match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), };
| ^^^^^
|
- = note: `#[warn(nontrivial_structural_match)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
+ = note: `#[warn(nontrivial_structural_match)]` on by default
warning: to use a constant of type `NoDerive` in a pattern, the constant's initializer must be trivial or `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/warn_corner_cases.rs:32:47
diff --git a/src/test/ui/consts/const_limit/const_eval_limit_reached.rs b/src/test/ui/consts/const_limit/const_eval_limit_reached.rs
index 773640b72..3ce038c1d 100644
--- a/src/test/ui/consts/const_limit/const_eval_limit_reached.rs
+++ b/src/test/ui/consts/const_limit/const_eval_limit_reached.rs
@@ -4,8 +4,7 @@
const X: usize = {
let mut x = 0;
while x != 1000 {
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler but is being phased out
+ //~^ ERROR evaluation of constant value failed
x += 1;
}
diff --git a/src/test/ui/consts/const_limit/const_eval_limit_reached.stderr b/src/test/ui/consts/const_limit/const_eval_limit_reached.stderr
index e450f4aa3..850aebdfb 100644
--- a/src/test/ui/consts/const_limit/const_eval_limit_reached.stderr
+++ b/src/test/ui/consts/const_limit/const_eval_limit_reached.stderr
@@ -1,29 +1,9 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/const_eval_limit_reached.rs:6:11
|
-LL | const X: usize = {
- | --------------
-LL | let mut x = 0;
LL | while x != 1000 {
| ^^^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`)
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: aborting due to previous error
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/const_eval_limit_reached.rs:6:11
- |
-LL | const X: usize = {
- | --------------
-LL | let mut x = 0;
-LL | while x != 1000 {
- | ^^^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`)
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const_unsafe_unreachable_ub.stderr b/src/test/ui/consts/const_unsafe_unreachable_ub.stderr
index ec6ce1f5d..f6de3699f 100644
--- a/src/test/ui/consts/const_unsafe_unreachable_ub.stderr
+++ b/src/test/ui/consts/const_unsafe_unreachable_ub.stderr
@@ -1,11 +1,11 @@
error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/hint.rs:LL:COL
|
-LL | unsafe { intrinsics::unreachable() }
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
- | |
- | entering unreachable code
- | inside `unreachable_unchecked` at $SRC_DIR/core/src/hint.rs:LL:COL
+LL | intrinsics::unreachable()
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ | |
+ | entering unreachable code
+ | inside `unreachable_unchecked` at $SRC_DIR/core/src/hint.rs:LL:COL
|
::: $DIR/const_unsafe_unreachable_ub.rs:6:18
|
diff --git a/src/test/ui/consts/constifconst-call-in-const-position.rs b/src/test/ui/consts/constifconst-call-in-const-position.rs
new file mode 100644
index 000000000..fcf01d5bc
--- /dev/null
+++ b/src/test/ui/consts/constifconst-call-in-const-position.rs
@@ -0,0 +1,22 @@
+// known-bug: #102498
+
+#![feature(const_trait_impl, generic_const_exprs)]
+
+#[const_trait]
+pub trait Tr {
+ fn a() -> usize;
+}
+
+impl Tr for () {
+ fn a() -> usize {
+ 1
+ }
+}
+
+const fn foo<T: ~const Tr>() -> [u8; T::a()] {
+ [0; T::a()]
+}
+
+fn main() {
+ foo::<()>();
+}
diff --git a/src/test/ui/consts/constifconst-call-in-const-position.stderr b/src/test/ui/consts/constifconst-call-in-const-position.stderr
new file mode 100644
index 000000000..d4a445120
--- /dev/null
+++ b/src/test/ui/consts/constifconst-call-in-const-position.stderr
@@ -0,0 +1,18 @@
+warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/constifconst-call-in-const-position.rs:3:30
+ |
+LL | #![feature(const_trait_impl, generic_const_exprs)]
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
+ = note: `#[warn(incomplete_features)]` on by default
+
+error[E0080]: evaluation of `foo::<()>::{constant#0}` failed
+ --> $DIR/constifconst-call-in-const-position.rs:16:38
+ |
+LL | const fn foo<T: ~const Tr>() -> [u8; T::a()] {
+ | ^^^^^^ calling non-const function `<() as Tr>::a`
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/control-flow/drop-fail.precise.stderr b/src/test/ui/consts/control-flow/drop-fail.precise.stderr
index 0b0b2443a..93b5f257e 100644
--- a/src/test/ui/consts/control-flow/drop-fail.precise.stderr
+++ b/src/test/ui/consts/control-flow/drop-fail.precise.stderr
@@ -1,14 +1,14 @@
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<Vec<i32>>` cannot be evaluated at compile-time
--> $DIR/drop-fail.rs:8:9
|
LL | let x = Some(Vec::new());
- | ^ constants cannot evaluate destructors
+ | ^ the destructor for this type cannot be evaluated in constants
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<Vec<i32>>` cannot be evaluated at compile-time
--> $DIR/drop-fail.rs:39:9
|
LL | let mut tmp = None;
- | ^^^^^^^ constants cannot evaluate destructors
+ | ^^^^^^^ the destructor for this type cannot be evaluated in constants
error: aborting due to 2 previous errors
diff --git a/src/test/ui/consts/control-flow/drop-fail.rs b/src/test/ui/consts/control-flow/drop-fail.rs
index efa5a11c9..41341f312 100644
--- a/src/test/ui/consts/control-flow/drop-fail.rs
+++ b/src/test/ui/consts/control-flow/drop-fail.rs
@@ -6,7 +6,7 @@
const _: Option<Vec<i32>> = {
let y: Option<Vec<i32>> = None;
let x = Some(Vec::new());
- //[stock,precise]~^ ERROR destructors cannot be evaluated at compile-time
+ //[stock,precise]~^ ERROR destructor of
if true {
x
@@ -19,7 +19,7 @@ const _: Option<Vec<i32>> = {
// existing analysis.
const _: Vec<i32> = {
let vec_tuple = (Vec::new(),);
- //[stock]~^ ERROR destructors cannot be evaluated at compile-time
+ //[stock]~^ ERROR destructor of
vec_tuple.0
};
@@ -27,7 +27,7 @@ const _: Vec<i32> = {
// This applies to single-field enum variants as well.
const _: Vec<i32> = {
let x: Result<_, Vec<i32>> = Ok(Vec::new());
- //[stock]~^ ERROR destructors cannot be evaluated at compile-time
+ //[stock]~^ ERROR destructor of
match x {
Ok(x) | Err(x) => x,
@@ -37,7 +37,7 @@ const _: Vec<i32> = {
const _: Option<Vec<i32>> = {
let mut some = Some(Vec::new());
let mut tmp = None;
- //[stock,precise]~^ ERROR destructors cannot be evaluated at compile-time
+ //[stock,precise]~^ ERROR destructor of
let mut i = 0;
while i < 10 {
diff --git a/src/test/ui/consts/control-flow/drop-fail.stock.stderr b/src/test/ui/consts/control-flow/drop-fail.stock.stderr
index 72ca4fa08..2cc856802 100644
--- a/src/test/ui/consts/control-flow/drop-fail.stock.stderr
+++ b/src/test/ui/consts/control-flow/drop-fail.stock.stderr
@@ -1,35 +1,35 @@
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<Vec<i32>>` cannot be evaluated at compile-time
--> $DIR/drop-fail.rs:8:9
|
LL | let x = Some(Vec::new());
- | ^ constants cannot evaluate destructors
+ | ^ the destructor for this type cannot be evaluated in constants
...
LL | };
| - value is dropped here
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `(Vec<i32>,)` cannot be evaluated at compile-time
--> $DIR/drop-fail.rs:21:9
|
LL | let vec_tuple = (Vec::new(),);
- | ^^^^^^^^^ constants cannot evaluate destructors
+ | ^^^^^^^^^ the destructor for this type cannot be evaluated in constants
...
LL | };
| - value is dropped here
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Result<Vec<i32>, Vec<i32>>` cannot be evaluated at compile-time
--> $DIR/drop-fail.rs:29:9
|
LL | let x: Result<_, Vec<i32>> = Ok(Vec::new());
- | ^ constants cannot evaluate destructors
+ | ^ the destructor for this type cannot be evaluated in constants
...
LL | };
| - value is dropped here
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<Vec<i32>>` cannot be evaluated at compile-time
--> $DIR/drop-fail.rs:39:9
|
LL | let mut tmp = None;
- | ^^^^^^^ constants cannot evaluate destructors
+ | ^^^^^^^ the destructor for this type cannot be evaluated in constants
...
LL | };
| - value is dropped here
diff --git a/src/test/ui/consts/control-flow/issue-50577.stderr b/src/test/ui/consts/control-flow/issue-50577.stderr
index b6e73f889..a931c89f4 100644
--- a/src/test/ui/consts/control-flow/issue-50577.stderr
+++ b/src/test/ui/consts/control-flow/issue-50577.stderr
@@ -2,7 +2,7 @@ error[E0317]: `if` may be missing an `else` clause
--> $DIR/issue-50577.rs:3:16
|
LL | Drop = assert_eq!(1, 1),
- | ^^^^^^^^^^^^^^^^ expected `()`, found `isize`
+ | ^^^^^^^^^^^^^^^^ expected `isize`, found `()`
|
= note: `if` expressions without `else` evaluate to `()`
= help: consider adding an `else` block that evaluates to the expected type
diff --git a/src/test/ui/consts/dangling-alloc-id-ice.rs b/src/test/ui/consts/dangling-alloc-id-ice.rs
index 95acacdb7..d591bfc73 100644
--- a/src/test/ui/consts/dangling-alloc-id-ice.rs
+++ b/src/test/ui/consts/dangling-alloc-id-ice.rs
@@ -1,5 +1,4 @@
// https://github.com/rust-lang/rust/issues/55223
-#![allow(const_err)]
union Foo<'a> {
y: &'a (),
diff --git a/src/test/ui/consts/dangling-alloc-id-ice.stderr b/src/test/ui/consts/dangling-alloc-id-ice.stderr
index 8410034c0..0a1cca4ca 100644
--- a/src/test/ui/consts/dangling-alloc-id-ice.stderr
+++ b/src/test/ui/consts/dangling-alloc-id-ice.stderr
@@ -1,5 +1,5 @@
error: encountered dangling pointer in final constant
- --> $DIR/dangling-alloc-id-ice.rs:9:1
+ --> $DIR/dangling-alloc-id-ice.rs:8:1
|
LL | const FOO: &() = {
| ^^^^^^^^^^^^^^
diff --git a/src/test/ui/consts/drop_box.rs b/src/test/ui/consts/drop_box.rs
index 58a373a96..679974130 100644
--- a/src/test/ui/consts/drop_box.rs
+++ b/src/test/ui/consts/drop_box.rs
@@ -1,4 +1,4 @@
const fn f<T>(_: Box<T>) {}
-//~^ ERROR destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
fn main() {}
diff --git a/src/test/ui/consts/drop_box.stderr b/src/test/ui/consts/drop_box.stderr
index b9d6581e8..62324939b 100644
--- a/src/test/ui/consts/drop_box.stderr
+++ b/src/test/ui/consts/drop_box.stderr
@@ -1,10 +1,10 @@
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Box<T>` cannot be evaluated at compile-time
--> $DIR/drop_box.rs:1:15
|
LL | const fn f<T>(_: Box<T>) {}
| ^ - value is dropped here
| |
- | constant functions cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constant functions
error: aborting due to previous error
diff --git a/src/test/ui/consts/drop_zst.stderr b/src/test/ui/consts/drop_zst.stderr
index d4be5aa56..37758a4cb 100644
--- a/src/test/ui/consts/drop_zst.stderr
+++ b/src/test/ui/consts/drop_zst.stderr
@@ -1,8 +1,8 @@
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `S` cannot be evaluated at compile-time
--> $DIR/drop_zst.rs:14:9
|
LL | let s = S;
- | ^ constant functions cannot evaluate destructors
+ | ^ the destructor for this type cannot be evaluated in constant functions
error: aborting due to previous error
diff --git a/src/test/ui/consts/extra-const-ub/detect-extra-ub.rs b/src/test/ui/consts/extra-const-ub/detect-extra-ub.rs
index 86fbadb94..159cdf257 100644
--- a/src/test/ui/consts/extra-const-ub/detect-extra-ub.rs
+++ b/src/test/ui/consts/extra-const-ub/detect-extra-ub.rs
@@ -13,15 +13,13 @@ const INVALID_BOOL: () = unsafe {
const INVALID_PTR_IN_INT: () = unsafe {
let _x: usize = transmute(&3u8);
- //[with_flag]~^ ERROR: any use of this value will cause an error
- //[with_flag]~| previously accepted
+ //[with_flag]~^ ERROR: evaluation of constant value failed
};
const INVALID_SLICE_TO_USIZE_TRANSMUTE: () = unsafe {
let x: &[u8] = &[0; 32];
let _x: (usize, usize) = transmute(x);
- //[with_flag]~^ ERROR: any use of this value will cause an error
- //[with_flag]~| previously accepted
+ //[with_flag]~^ ERROR: evaluation of constant value failed
};
const UNALIGNED_PTR: () = unsafe {
@@ -31,8 +29,7 @@ const UNALIGNED_PTR: () = unsafe {
};
const UNALIGNED_READ: () = {
- INNER; //[with_flag]~ERROR any use of this value will cause an error
- //[with_flag]~| previously accepted
+ INNER; //[with_flag]~ERROR evaluation of constant value failed
// There is an error here but its span is in the standard library so we cannot match it...
// so we have this in a *nested* const, such that the *outer* const fails to use it.
const INNER: () = unsafe {
diff --git a/src/test/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr b/src/test/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr
index 793725d3b..3e1195822 100644
--- a/src/test/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr
+++ b/src/test/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr
@@ -4,36 +4,26 @@ error[E0080]: evaluation of constant value failed
LL | let _x: bool = transmute(3u8);
| ^^^^^^^^^^^^^^ constructing invalid value: encountered 0x03, but expected a boolean
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/detect-extra-ub.rs:15:21
|
-LL | const INVALID_PTR_IN_INT: () = unsafe {
- | ----------------------------
LL | let _x: usize = transmute(&3u8);
| ^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/detect-extra-ub.rs:22:30
+error[E0080]: evaluation of constant value failed
+ --> $DIR/detect-extra-ub.rs:21:30
|
-LL | const INVALID_SLICE_TO_USIZE_TRANSMUTE: () = unsafe {
- | ------------------------------------------
-LL | let x: &[u8] = &[0; 32];
LL | let _x: (usize, usize) = transmute(x);
| ^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error[E0080]: evaluation of constant value failed
- --> $DIR/detect-extra-ub.rs:28:20
+ --> $DIR/detect-extra-ub.rs:26:20
|
LL | let _x: &u32 = transmute(&[0u8; 4]);
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 4 byte alignment but found 1)
@@ -52,66 +42,17 @@ LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
LL | unsafe { read(self) }
| ---------- inside `ptr::const_ptr::<impl *const u32>::read` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
- ::: $DIR/detect-extra-ub.rs:41:9
+ ::: $DIR/detect-extra-ub.rs:38:9
|
LL | ptr.read();
- | ---------- inside `INNER` at $DIR/detect-extra-ub.rs:41:9
+ | ---------- inside `INNER` at $DIR/detect-extra-ub.rs:38:9
-error: any use of this value will cause an error
- --> $DIR/detect-extra-ub.rs:34:5
+error[E0080]: evaluation of constant value failed
+ --> $DIR/detect-extra-ub.rs:32:5
|
-LL | const UNALIGNED_READ: () = {
- | ------------------------
LL | INNER;
| ^^^^^ referenced constant has errors
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/detect-extra-ub.rs:15:21
- |
-LL | const INVALID_PTR_IN_INT: () = unsafe {
- | ----------------------------
-LL | let _x: usize = transmute(&3u8);
- | ^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/detect-extra-ub.rs:22:30
- |
-LL | const INVALID_SLICE_TO_USIZE_TRANSMUTE: () = unsafe {
- | ------------------------------------------
-LL | let x: &[u8] = &[0; 32];
-LL | let _x: (usize, usize) = transmute(x);
- | ^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/detect-extra-ub.rs:34:5
- |
-LL | const UNALIGNED_READ: () = {
- | ------------------------
-LL | INNER;
- | ^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/invalid-union.32bit.stderr b/src/test/ui/consts/invalid-union.32bit.stderr
index ae5f6b2ba..bad07989e 100644
--- a/src/test/ui/consts/invalid-union.32bit.stderr
+++ b/src/test/ui/consts/invalid-union.32bit.stderr
@@ -9,27 +9,12 @@ LL | fn main() {
╾─alloc7──╼ │ ╾──╼
}
-error: erroneous constant used
+error[E0080]: erroneous constant used
--> $DIR/invalid-union.rs:42:25
|
LL | let _: &'static _ = &C;
| ^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: erroneous constant used
- --> $DIR/invalid-union.rs:42:25
- |
-LL | let _: &'static _ = &C;
- | ^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/invalid-union.64bit.stderr b/src/test/ui/consts/invalid-union.64bit.stderr
index d50e74a16..a209f0038 100644
--- a/src/test/ui/consts/invalid-union.64bit.stderr
+++ b/src/test/ui/consts/invalid-union.64bit.stderr
@@ -9,27 +9,12 @@ LL | fn main() {
╾───────alloc7────────╼ │ ╾──────╼
}
-error: erroneous constant used
+error[E0080]: erroneous constant used
--> $DIR/invalid-union.rs:42:25
|
LL | let _: &'static _ = &C;
| ^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: erroneous constant used
- --> $DIR/invalid-union.rs:42:25
- |
-LL | let _: &'static _ = &C;
- | ^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/invalid-union.rs b/src/test/ui/consts/invalid-union.rs
index efeddf75c..435d26d6e 100644
--- a/src/test/ui/consts/invalid-union.rs
+++ b/src/test/ui/consts/invalid-union.rs
@@ -40,5 +40,4 @@ const C: S = {
fn main() { //~ ERROR it is undefined behavior to use this value
let _: &'static _ = &C; //~ ERROR erroneous constant used
- //~^ WARN this was previously accepted
}
diff --git a/src/test/ui/consts/issue-102117.rs b/src/test/ui/consts/issue-102117.rs
new file mode 100644
index 000000000..b77342c41
--- /dev/null
+++ b/src/test/ui/consts/issue-102117.rs
@@ -0,0 +1,30 @@
+#![feature(inline_const, const_type_id)]
+
+use std::alloc::Layout;
+use std::any::TypeId;
+use std::mem::transmute;
+use std::ptr::drop_in_place;
+
+pub struct VTable {
+ layout: Layout,
+ type_id: TypeId,
+ drop_in_place: unsafe fn(*mut ()),
+}
+
+impl VTable {
+ pub fn new<T>() -> &'static Self {
+ const {
+ //~^ ERROR the parameter type `T` may not live long enough
+ //~| ERROR the parameter type `T` may not live long enough
+ &VTable {
+ layout: Layout::new::<T>(),
+ type_id: TypeId::of::<T>(),
+ drop_in_place: unsafe {
+ transmute::<unsafe fn(*mut T), unsafe fn(*mut ())>(drop_in_place::<T>)
+ },
+ }
+ }
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/consts/issue-102117.stderr b/src/test/ui/consts/issue-102117.stderr
new file mode 100644
index 000000000..eb4b329bd
--- /dev/null
+++ b/src/test/ui/consts/issue-102117.stderr
@@ -0,0 +1,37 @@
+error[E0310]: the parameter type `T` may not live long enough
+ --> $DIR/issue-102117.rs:16:9
+ |
+LL | / const {
+LL | |
+LL | |
+LL | | &VTable {
+... |
+LL | | }
+LL | | }
+ | |_________^ ...so that the type `T` will meet its required lifetime bounds
+ |
+help: consider adding an explicit lifetime bound...
+ |
+LL | pub fn new<T: 'static>() -> &'static Self {
+ | +++++++++
+
+error[E0310]: the parameter type `T` may not live long enough
+ --> $DIR/issue-102117.rs:16:9
+ |
+LL | / const {
+LL | |
+LL | |
+LL | | &VTable {
+... |
+LL | | }
+LL | | }
+ | |_________^ ...so that the type `T` will meet its required lifetime bounds
+ |
+help: consider adding an explicit lifetime bound...
+ |
+LL | pub fn new<T: 'static>() -> &'static Self {
+ | +++++++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0310`.
diff --git a/src/test/ui/consts/issue-104155.rs b/src/test/ui/consts/issue-104155.rs
new file mode 100644
index 000000000..1cc8f81b0
--- /dev/null
+++ b/src/test/ui/consts/issue-104155.rs
@@ -0,0 +1,5 @@
+// check-pass
+const _: () = core::mem::forget(Box::<u32>::default);
+const _: () = core::mem::forget(|| Box::<u32>::default());
+
+fn main() {}
diff --git a/src/test/ui/issues/issue-17718-constants-not-static.rs b/src/test/ui/consts/issue-17718-constants-not-static.rs
index 2e6aff161..2e6aff161 100644
--- a/src/test/ui/issues/issue-17718-constants-not-static.rs
+++ b/src/test/ui/consts/issue-17718-constants-not-static.rs
diff --git a/src/test/ui/issues/issue-17718-constants-not-static.stderr b/src/test/ui/consts/issue-17718-constants-not-static.stderr
index 8f3acae71..8f3acae71 100644
--- a/src/test/ui/issues/issue-17718-constants-not-static.stderr
+++ b/src/test/ui/consts/issue-17718-constants-not-static.stderr
diff --git a/src/test/ui/consts/issue-25826.stderr b/src/test/ui/consts/issue-25826.stderr
index b80befa26..905c5ee6e 100644
--- a/src/test/ui/consts/issue-25826.stderr
+++ b/src/test/ui/consts/issue-25826.stderr
@@ -10,10 +10,6 @@ note: the trait `PartialOrd` is implemented for `*const ()`, but that implementa
|
LL | const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () };
| ^
-help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
- |
-LL | fn main() where *const (): ~const PartialOrd {
- | ++++++++++++++++++++++++++++++++++
error: aborting due to previous error
diff --git a/src/test/ui/consts/issue-46553.rs b/src/test/ui/consts/issue-46553.rs
index 9438df193..abeaf10f2 100644
--- a/src/test/ui/consts/issue-46553.rs
+++ b/src/test/ui/consts/issue-46553.rs
@@ -1,5 +1,4 @@
// run-pass
-#![deny(const_err)]
pub struct Data<T> {
function: fn() -> T,
diff --git a/src/test/ui/consts/issue-56164.rs b/src/test/ui/consts/issue-56164.rs
index 094ca377e..df3e3bf90 100644
--- a/src/test/ui/consts/issue-56164.rs
+++ b/src/test/ui/consts/issue-56164.rs
@@ -1,11 +1,10 @@
const fn foo() { (||{})() }
//~^ ERROR cannot call non-const closure
-//~| ERROR erroneous constant used [const_err]
-//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+//~| ERROR erroneous constant used
const fn bad(input: fn()) {
input()
- //~^ ERROR function pointer
+ //~^ ERROR function pointer calls are not allowed
}
fn main() {
diff --git a/src/test/ui/consts/issue-56164.stderr b/src/test/ui/consts/issue-56164.stderr
index 73a0f8ec0..c5b2c57fb 100644
--- a/src/test/ui/consts/issue-56164.stderr
+++ b/src/test/ui/consts/issue-56164.stderr
@@ -8,32 +8,18 @@ LL | const fn foo() { (||{})() }
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: function pointer calls are not allowed in constant functions
- --> $DIR/issue-56164.rs:7:5
+ --> $DIR/issue-56164.rs:6:5
|
LL | input()
| ^^^^^^^
-error: erroneous constant used
+error[E0080]: erroneous constant used
--> $DIR/issue-56164.rs:1:18
|
LL | const fn foo() { (||{})() }
| ^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: aborting due to 3 previous errors
-For more information about this error, try `rustc --explain E0015`.
-Future incompatibility report: Future breakage diagnostic:
-error: erroneous constant used
- --> $DIR/issue-56164.rs:1:18
- |
-LL | const fn foo() { (||{})() }
- | ^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+Some errors have detailed explanations: E0015, E0080.
+For more information about an error, try `rustc --explain E0015`.
diff --git a/src/test/ui/consts/issue-66693.rs b/src/test/ui/consts/issue-66693.rs
index 99d28eb77..1ff250be1 100644
--- a/src/test/ui/consts/issue-66693.rs
+++ b/src/test/ui/consts/issue-66693.rs
@@ -10,8 +10,7 @@ static _FOO: () = panic!(true);
const fn _foo() {
panic!(&1);
//~^ ERROR: argument to `panic!()` in a const context must have type `&str`
- //~| ERROR: erroneous constant used [const_err]
- //~| WARNING: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ //~| ERROR: erroneous constant used
}
// ensure that conforming panics don't cause an error
diff --git a/src/test/ui/consts/issue-66693.stderr b/src/test/ui/consts/issue-66693.stderr
index 5460cc1ee..911374f50 100644
--- a/src/test/ui/consts/issue-66693.stderr
+++ b/src/test/ui/consts/issue-66693.stderr
@@ -22,26 +22,12 @@ LL | panic!(&1);
|
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: erroneous constant used
+error[E0080]: erroneous constant used
--> $DIR/issue-66693.rs:11:12
|
LL | panic!(&1);
| ^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: aborting due to 4 previous errors
-Future incompatibility report: Future breakage diagnostic:
-error: erroneous constant used
- --> $DIR/issue-66693.rs:11:12
- |
-LL | panic!(&1);
- | ^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/issue-78655.stderr b/src/test/ui/consts/issue-78655.stderr
index f5b1123e7..6b83fa0e5 100644
--- a/src/test/ui/consts/issue-78655.stderr
+++ b/src/test/ui/consts/issue-78655.stderr
@@ -5,6 +5,11 @@ LL | let x;
| - binding declared here but left uninitialized
LL | &x
| ^^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x = 0;
+ | +++
error: could not evaluate constant pattern
--> $DIR/issue-78655.rs:7:9
diff --git a/src/test/ui/consts/issue-88071.rs b/src/test/ui/consts/issue-88071.rs
index 1c38c43e6..f58cdb594 100644
--- a/src/test/ui/consts/issue-88071.rs
+++ b/src/test/ui/consts/issue-88071.rs
@@ -2,8 +2,6 @@
//
// regression test for #88071
-#![feature(const_btree_new)]
-
use std::collections::BTreeMap;
pub struct CustomMap<K, V>(BTreeMap<K, V>);
diff --git a/src/test/ui/consts/issue-94675.rs b/src/test/ui/consts/issue-94675.rs
index 0604aab3b..ce21ebdb9 100644
--- a/src/test/ui/consts/issue-94675.rs
+++ b/src/test/ui/consts/issue-94675.rs
@@ -7,9 +7,8 @@ struct Foo<'a> {
impl<'a> Foo<'a> {
const fn spam(&mut self, baz: &mut Vec<u32>) {
self.bar[0] = baz.len();
- //~^ ERROR cannot call non-const fn `Vec::<u32>::len` in constant functions
- //~| ERROR the trait bound `Vec<usize>: ~const IndexMut<usize>` is not satisfied
- //~| ERROR cannot call non-const operator in constant functions
+ //~^ the trait bound `Vec<usize>: ~const Index<_>` is not satisfied
+ //~| the trait bound `Vec<usize>: ~const IndexMut<usize>` is not satisfied
}
}
diff --git a/src/test/ui/consts/issue-94675.stderr b/src/test/ui/consts/issue-94675.stderr
index 6665e4283..f4683f7f5 100644
--- a/src/test/ui/consts/issue-94675.stderr
+++ b/src/test/ui/consts/issue-94675.stderr
@@ -1,10 +1,15 @@
-error[E0015]: cannot call non-const fn `Vec::<u32>::len` in constant functions
- --> $DIR/issue-94675.rs:9:27
+error[E0277]: the trait bound `Vec<usize>: ~const Index<_>` is not satisfied
+ --> $DIR/issue-94675.rs:9:9
|
LL | self.bar[0] = baz.len();
- | ^^^^^
+ | ^^^^^^^^^^^ vector indices are of type `usize` or ranges of `usize`
+ |
+ = help: the trait `~const Index<_>` is not implemented for `Vec<usize>`
+note: the trait `Index<_>` is implemented for `Vec<usize>`, but that implementation is not `const`
+ --> $DIR/issue-94675.rs:9:9
|
- = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
+LL | self.bar[0] = baz.len();
+ | ^^^^^^^^^^^
error[E0277]: the trait bound `Vec<usize>: ~const IndexMut<usize>` is not satisfied
--> $DIR/issue-94675.rs:9:9
@@ -19,20 +24,6 @@ note: the trait `IndexMut<usize>` is implemented for `Vec<usize>`, but that impl
LL | self.bar[0] = baz.len();
| ^^^^^^^^^^^
-error[E0015]: cannot call non-const operator in constant functions
- --> $DIR/issue-94675.rs:9:9
- |
-LL | self.bar[0] = baz.len();
- | ^^^^^^^^^^^
- |
-note: impl defined here, but it is not `const`
- --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
- |
-LL | impl<T, I: SliceIndex<[T]>, A: Allocator> IndexMut<I> for Vec<T, A> {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
-
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
-Some errors have detailed explanations: E0015, E0277.
-For more information about an error, try `rustc --explain E0015`.
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/consts/issue-miri-1910.stderr b/src/test/ui/consts/issue-miri-1910.stderr
index 0f0539e09..3872e3d4f 100644
--- a/src/test/ui/consts/issue-miri-1910.stderr
+++ b/src/test/ui/consts/issue-miri-1910.stderr
@@ -1,4 +1,4 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
@@ -6,42 +6,20 @@ LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
| |
| unable to copy parts of a pointer from memory at ALLOC
| inside `std::ptr::read::<u8>` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
- | inside `ptr::const_ptr::<impl *const u8>::read` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
- | inside `C` at $DIR/issue-miri-1910.rs:8:5
|
- ::: $DIR/issue-miri-1910.rs:5:1
+ ::: $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
-LL | const C: () = unsafe {
- | -----------
+LL | unsafe { read(self) }
+ | ---------- inside `ptr::const_ptr::<impl *const u8>::read` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-error: aborting due to previous error
-
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
+ ::: $DIR/issue-miri-1910.rs:8:5
|
-LL | copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- | |
- | unable to copy parts of a pointer from memory at ALLOC
- | inside `std::ptr::read::<u8>` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
- | inside `ptr::const_ptr::<impl *const u8>::read` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
- | inside `C` at $DIR/issue-miri-1910.rs:8:5
- |
- ::: $DIR/issue-miri-1910.rs:5:1
+LL | (&foo as *const _ as *const u8).add(one_and_a_half_pointers).read();
+ | ------------------------------------------------------------------- inside `C` at $DIR/issue-miri-1910.rs:8:5
|
-LL | const C: () = unsafe {
- | -----------
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.rs b/src/test/ui/consts/min_const_fn/min_const_fn.rs
index 0bafaf2e8..c2891488c 100644
--- a/src/test/ui/consts/min_const_fn/min_const_fn.rs
+++ b/src/test/ui/consts/min_const_fn/min_const_fn.rs
@@ -34,7 +34,7 @@ const fn foo35(a: bool, b: bool) -> bool { a ^ b }
struct Foo<T: ?Sized>(T);
impl<T> Foo<T> {
const fn new(t: T) -> Self { Foo(t) }
- const fn into_inner(self) -> T { self.0 } //~ destructors cannot be evaluated
+ const fn into_inner(self) -> T { self.0 } //~ destructor of
const fn get(&self) -> &T { &self.0 }
const fn get_mut(&mut self) -> &mut T { &mut self.0 }
//~^ mutable references
@@ -43,7 +43,7 @@ impl<T> Foo<T> {
}
impl<'a, T> Foo<T> {
const fn new_lt(t: T) -> Self { Foo(t) }
- const fn into_inner_lt(self) -> T { self.0 } //~ destructors cannot be evaluated
+ const fn into_inner_lt(self) -> T { self.0 } //~ destructor of
const fn get_lt(&'a self) -> &T { &self.0 }
const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
//~^ mutable references
@@ -52,7 +52,7 @@ impl<'a, T> Foo<T> {
}
impl<T: Sized> Foo<T> {
const fn new_s(t: T) -> Self { Foo(t) }
- const fn into_inner_s(self) -> T { self.0 } //~ ERROR destructors
+ const fn into_inner_s(self) -> T { self.0 } //~ ERROR destructor
const fn get_s(&self) -> &T { &self.0 }
const fn get_mut_s(&mut self) -> &mut T { &mut self.0 }
//~^ mutable references
diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.stderr b/src/test/ui/consts/min_const_fn/min_const_fn.stderr
index 4ad17602c..11c79e8e2 100644
--- a/src/test/ui/consts/min_const_fn/min_const_fn.stderr
+++ b/src/test/ui/consts/min_const_fn/min_const_fn.stderr
@@ -1,10 +1,10 @@
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Foo<T>` cannot be evaluated at compile-time
--> $DIR/min_const_fn.rs:37:25
|
LL | const fn into_inner(self) -> T { self.0 }
| ^^^^ - value is dropped here
| |
- | constant functions cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constant functions
error[E0658]: mutable references are not allowed in constant functions
--> $DIR/min_const_fn.rs:39:22
@@ -33,13 +33,13 @@ LL | const fn get_mut(&mut self) -> &mut T { &mut self.0 }
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Foo<T>` cannot be evaluated at compile-time
--> $DIR/min_const_fn.rs:46:28
|
LL | const fn into_inner_lt(self) -> T { self.0 }
| ^^^^ - value is dropped here
| |
- | constant functions cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constant functions
error[E0658]: mutable references are not allowed in constant functions
--> $DIR/min_const_fn.rs:48:25
@@ -68,13 +68,13 @@ LL | const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Foo<T>` cannot be evaluated at compile-time
--> $DIR/min_const_fn.rs:55:27
|
LL | const fn into_inner_s(self) -> T { self.0 }
| ^^^^ - value is dropped here
| |
- | constant functions cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constant functions
error[E0658]: mutable references are not allowed in constant functions
--> $DIR/min_const_fn.rs:57:24
@@ -191,21 +191,21 @@ LL | const fn inc(x: &mut i32) { *x += 1 }
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `AlanTuring<impl std::fmt::Debug>` cannot be evaluated at compile-time
--> $DIR/min_const_fn.rs:122:19
|
LL | const fn no_apit2(_x: AlanTuring<impl std::fmt::Debug>) {}
| ^^ - value is dropped here
| |
- | constant functions cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constant functions
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `impl std::fmt::Debug` cannot be evaluated at compile-time
--> $DIR/min_const_fn.rs:124:18
|
LL | const fn no_apit(_x: impl std::fmt::Debug) {}
| ^^ - value is dropped here
| |
- | constant functions cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constant functions
error: aborting due to 24 previous errors
diff --git a/src/test/ui/consts/miri_unleashed/abi-mismatch.rs b/src/test/ui/consts/miri_unleashed/abi-mismatch.rs
index 3360e9cac..205f7183b 100644
--- a/src/test/ui/consts/miri_unleashed/abi-mismatch.rs
+++ b/src/test/ui/consts/miri_unleashed/abi-mismatch.rs
@@ -2,7 +2,6 @@
// compile-flags: -Z unleash-the-miri-inside-of-you
#![feature(const_extern_fn)]
-#![allow(const_err)]
const extern "C" fn c_fn() {}
diff --git a/src/test/ui/consts/miri_unleashed/abi-mismatch.stderr b/src/test/ui/consts/miri_unleashed/abi-mismatch.stderr
index aaba19c2c..840d698eb 100644
--- a/src/test/ui/consts/miri_unleashed/abi-mismatch.stderr
+++ b/src/test/ui/consts/miri_unleashed/abi-mismatch.stderr
@@ -1,19 +1,19 @@
error[E0080]: could not evaluate static initializer
- --> $DIR/abi-mismatch.rs:10:5
+ --> $DIR/abi-mismatch.rs:9:5
|
LL | my_fn();
| ^^^^^^^
| |
| calling a function with calling convention C using calling convention Rust
- | inside `call_rust_fn` at $DIR/abi-mismatch.rs:10:5
+ | inside `call_rust_fn` at $DIR/abi-mismatch.rs:9:5
...
LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
- | --------------------------------------------------------------------- inside `VAL` at $DIR/abi-mismatch.rs:16:18
+ | --------------------------------------------------------------------- inside `VAL` at $DIR/abi-mismatch.rs:15:18
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
- --> $DIR/abi-mismatch.rs:10:5
+ --> $DIR/abi-mismatch.rs:9:5
|
LL | my_fn();
| ^^^^^^^
diff --git a/src/test/ui/consts/miri_unleashed/assoc_const.rs b/src/test/ui/consts/miri_unleashed/assoc_const.rs
index 5f520c2cf..76ed667a5 100644
--- a/src/test/ui/consts/miri_unleashed/assoc_const.rs
+++ b/src/test/ui/consts/miri_unleashed/assoc_const.rs
@@ -1,8 +1,6 @@
// build-fail
// compile-flags: -Zunleash-the-miri-inside-of-you
-#![allow(const_err)]
-
// a test demonstrating why we do need to run static const qualification on associated constants
// instead of just checking the final constant
diff --git a/src/test/ui/consts/miri_unleashed/assoc_const.stderr b/src/test/ui/consts/miri_unleashed/assoc_const.stderr
index 1f82ac827..519bd0748 100644
--- a/src/test/ui/consts/miri_unleashed/assoc_const.stderr
+++ b/src/test/ui/consts/miri_unleashed/assoc_const.stderr
@@ -1,22 +1,4 @@
-error[E0080]: erroneous constant used
- --> $DIR/assoc_const.rs:31:13
- |
-LL | let y = <String as Bar<Vec<u32>, String>>::F;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
-
-warning: skipping const checks
- |
-help: skipping check that does not even have a feature gate
- --> $DIR/assoc_const.rs:14:20
- |
-LL | const F: u32 = (U::X, 42).1;
- | ^^^^^^^^^^
-
-error: aborting due to previous error; 1 warning emitted
-
-For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
+error[E0080]: evaluation of `<std::string::String as Bar<std::vec::Vec<u32>, std::string::String>>::F` failed
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
LL | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
@@ -25,18 +7,26 @@ LL | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
| calling non-const function `<Vec<u32> as Drop>::drop`
| inside `std::ptr::drop_in_place::<Vec<u32>> - shim(Some(Vec<u32>))` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
| inside `std::ptr::drop_in_place::<(Vec<u32>, u32)> - shim(Some((Vec<u32>, u32)))` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
- | inside `<String as Bar<Vec<u32>, String>>::F` at $DIR/assoc_const.rs:14:31
|
- ::: $DIR/assoc_const.rs:14:5
+ ::: $DIR/assoc_const.rs:12:31
|
LL | const F: u32 = (U::X, 42).1;
- | ------------
+ | - inside `<String as Bar<Vec<u32>, String>>::F` at $DIR/assoc_const.rs:12:31
+
+error[E0080]: erroneous constant used
+ --> $DIR/assoc_const.rs:29:13
|
-note: the lint level is defined here
- --> $DIR/assoc_const.rs:4:10
+LL | let y = <String as Bar<Vec<u32>, String>>::F;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
+
+warning: skipping const checks
|
-LL | #![allow(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+help: skipping check that does not even have a feature gate
+ --> $DIR/assoc_const.rs:12:20
+ |
+LL | const F: u32 = (U::X, 42).1;
+ | ^^^^^^^^^^
+
+error: aborting due to 2 previous errors; 1 warning emitted
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/assoc_const_2.rs b/src/test/ui/consts/miri_unleashed/assoc_const_2.rs
index 30dd2a515..8377141ea 100644
--- a/src/test/ui/consts/miri_unleashed/assoc_const_2.rs
+++ b/src/test/ui/consts/miri_unleashed/assoc_const_2.rs
@@ -1,7 +1,5 @@
// build-fail
-#![allow(const_err)]
-
// a test demonstrating that const qualification cannot prevent monomorphization time errors
trait Foo {
@@ -9,7 +7,7 @@ trait Foo {
}
trait Bar<U: Foo> {
- const F: u32 = 100 / U::X;
+ const F: u32 = 100 / U::X; //~ ERROR evaluation of `<std::string::String as Bar<std::string::String>>::F` failed
}
impl Foo for () {
diff --git a/src/test/ui/consts/miri_unleashed/assoc_const_2.stderr b/src/test/ui/consts/miri_unleashed/assoc_const_2.stderr
index cbf02199f..2bf753c2b 100644
--- a/src/test/ui/consts/miri_unleashed/assoc_const_2.stderr
+++ b/src/test/ui/consts/miri_unleashed/assoc_const_2.stderr
@@ -1,24 +1,15 @@
+error[E0080]: evaluation of `<std::string::String as Bar<std::string::String>>::F` failed
+ --> $DIR/assoc_const_2.rs:10:20
+ |
+LL | const F: u32 = 100 / U::X;
+ | ^^^^^^^^^^ attempt to divide `100_u32` by zero
+
error[E0080]: erroneous constant used
- --> $DIR/assoc_const_2.rs:29:13
+ --> $DIR/assoc_const_2.rs:27:13
|
LL | let y = <String as Bar<String>>::F;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
-error: aborting due to previous error
+error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/assoc_const_2.rs:12:20
- |
-LL | const F: u32 = 100 / U::X;
- | ------------ ^^^^^^^^^^ attempt to divide `100_u32` by zero
- |
-note: the lint level is defined here
- --> $DIR/assoc_const_2.rs:3:10
- |
-LL | #![allow(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/miri_unleashed/box.rs b/src/test/ui/consts/miri_unleashed/box.rs
index 32796c672..c2a260aa1 100644
--- a/src/test/ui/consts/miri_unleashed/box.rs
+++ b/src/test/ui/consts/miri_unleashed/box.rs
@@ -1,6 +1,5 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
#![feature(box_syntax)]
-#![allow(const_err)]
use std::mem::ManuallyDrop;
diff --git a/src/test/ui/consts/miri_unleashed/box.stderr b/src/test/ui/consts/miri_unleashed/box.stderr
index 05d9858dc..bc5d4a257 100644
--- a/src/test/ui/consts/miri_unleashed/box.stderr
+++ b/src/test/ui/consts/miri_unleashed/box.stderr
@@ -1,5 +1,5 @@
error[E0080]: could not evaluate static initializer
- --> $DIR/box.rs:10:11
+ --> $DIR/box.rs:9:11
|
LL | &mut *(box 0)
| ^^^^^^^ calling non-const function `alloc::alloc::exchange_malloc`
@@ -7,22 +7,22 @@ LL | &mut *(box 0)
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
- --> $DIR/box.rs:10:11
+ --> $DIR/box.rs:9:11
|
LL | &mut *(box 0)
| ^^^^^^^
help: skipping check for `const_mut_refs` feature
- --> $DIR/box.rs:10:16
+ --> $DIR/box.rs:9:16
|
LL | &mut *(box 0)
| ^
help: skipping check for `const_mut_refs` feature
- --> $DIR/box.rs:10:5
+ --> $DIR/box.rs:9:5
|
LL | &mut *(box 0)
| ^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/box.rs:10:5
+ --> $DIR/box.rs:9:5
|
LL | &mut *(box 0)
| ^^^^^^^^^^^^^
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static.32bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static.32bit.stderr
new file mode 100644
index 000000000..a6f467b9e
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static.32bit.stderr
@@ -0,0 +1,81 @@
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static.rs:9:5
+ |
+LL | FOO.fetch_add(1, Ordering::Relaxed)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling non-const function `AtomicUsize::fetch_add`
+
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static.rs:14:14
+ |
+LL | unsafe { *(&FOO as *const _ as *const usize) }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static.rs:18:32
+ |
+LL | const READ_MUT: u32 = unsafe { MUTABLE };
+ | ^^^^^^^ constant accesses static
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static.rs:20:1
+ |
+LL | const REF_INTERIOR_MUT: &usize = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 4, align: 4) {
+ ╾─alloc4──╼ │ ╾──╼
+ }
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static.rs:27:1
+ |
+LL | const READ_IMMUT: &usize = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 4, align: 4) {
+ ╾─alloc5──╼ │ ╾──╼
+ }
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:9:5
+ |
+LL | FOO.fetch_add(1, Ordering::Relaxed)
+ | ^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:9:5
+ |
+LL | FOO.fetch_add(1, Ordering::Relaxed)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:14:17
+ |
+LL | unsafe { *(&FOO as *const _ as *const usize) }
+ | ^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:18:32
+ |
+LL | const READ_MUT: u32 = unsafe { MUTABLE };
+ | ^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:18:32
+ |
+LL | const READ_MUT: u32 = unsafe { MUTABLE };
+ | ^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:23:18
+ |
+LL | unsafe { &*(&FOO as *const _ as *const usize) }
+ | ^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:30:6
+ |
+LL | &FOO
+ | ^^^
+
+error: aborting due to 5 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static.64bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static.64bit.stderr
new file mode 100644
index 000000000..cfaf31a6e
--- /dev/null
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static.64bit.stderr
@@ -0,0 +1,81 @@
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static.rs:9:5
+ |
+LL | FOO.fetch_add(1, Ordering::Relaxed)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling non-const function `AtomicUsize::fetch_add`
+
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static.rs:14:14
+ |
+LL | unsafe { *(&FOO as *const _ as *const usize) }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
+
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static.rs:18:32
+ |
+LL | const READ_MUT: u32 = unsafe { MUTABLE };
+ | ^^^^^^^ constant accesses static
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static.rs:20:1
+ |
+LL | const REF_INTERIOR_MUT: &usize = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 8, align: 8) {
+ ╾───────alloc4────────╼ │ ╾──────╼
+ }
+
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/const_refers_to_static.rs:27:1
+ |
+LL | const READ_IMMUT: &usize = {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
+ |
+ = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+ = note: the raw bytes of the constant (size: 8, align: 8) {
+ ╾───────alloc5────────╼ │ ╾──────╼
+ }
+
+warning: skipping const checks
+ |
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:9:5
+ |
+LL | FOO.fetch_add(1, Ordering::Relaxed)
+ | ^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:9:5
+ |
+LL | FOO.fetch_add(1, Ordering::Relaxed)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:14:17
+ |
+LL | unsafe { *(&FOO as *const _ as *const usize) }
+ | ^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:18:32
+ |
+LL | const READ_MUT: u32 = unsafe { MUTABLE };
+ | ^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:18:32
+ |
+LL | const READ_MUT: u32 = unsafe { MUTABLE };
+ | ^^^^^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:23:18
+ |
+LL | unsafe { &*(&FOO as *const _ as *const usize) }
+ | ^^^
+help: skipping check that does not even have a feature gate
+ --> $DIR/const_refers_to_static.rs:30:6
+ |
+LL | &FOO
+ | ^^^
+
+error: aborting due to 5 previous errors; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static.rs b/src/test/ui/consts/miri_unleashed/const_refers_to_static.rs
index c9dc1de51..7ed5a48d9 100644
--- a/src/test/ui/consts/miri_unleashed/const_refers_to_static.rs
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static.rs
@@ -1,31 +1,33 @@
-// build-fail
// compile-flags: -Zunleash-the-miri-inside-of-you
-#![allow(const_err)]
+// stderr-per-bitwidth
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
-// These fail during CTFE (as they read a static), so they only cause an error
-// when *using* the const.
-
const MUTATE_INTERIOR_MUT: usize = {
static FOO: AtomicUsize = AtomicUsize::new(0);
- FOO.fetch_add(1, Ordering::Relaxed)
+ FOO.fetch_add(1, Ordering::Relaxed) //~ERROR evaluation of constant value failed
};
const READ_INTERIOR_MUT: usize = {
static FOO: AtomicUsize = AtomicUsize::new(0);
- unsafe { *(&FOO as *const _ as *const usize) }
+ unsafe { *(&FOO as *const _ as *const usize) } //~ERROR evaluation of constant value failed
};
static mut MUTABLE: u32 = 0;
-const READ_MUT: u32 = unsafe { MUTABLE };
+const READ_MUT: u32 = unsafe { MUTABLE }; //~ERROR evaluation of constant value failed
+
+const REF_INTERIOR_MUT: &usize = { //~ ERROR undefined behavior to use this value
+//~| encountered a reference pointing to a static variable
+ static FOO: AtomicUsize = AtomicUsize::new(0);
+ unsafe { &*(&FOO as *const _ as *const usize) }
+};
+
+// ok some day perhaps
+const READ_IMMUT: &usize = { //~ ERROR it is undefined behavior to use this value
+//~| encountered a reference pointing to a static variable
+ static FOO: usize = 0;
+ &FOO
+};
-fn main() {
- MUTATE_INTERIOR_MUT;
- //~^ ERROR: erroneous constant used
- READ_INTERIOR_MUT;
- //~^ ERROR: erroneous constant used
- READ_MUT;
- //~^ ERROR: erroneous constant used
-}
+fn main() {}
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr
deleted file mode 100644
index fa2088124..000000000
--- a/src/test/ui/consts/miri_unleashed/const_refers_to_static.stderr
+++ /dev/null
@@ -1,100 +0,0 @@
-error[E0080]: erroneous constant used
- --> $DIR/const_refers_to_static.rs:25:5
- |
-LL | MUTATE_INTERIOR_MUT;
- | ^^^^^^^^^^^^^^^^^^^ referenced constant has errors
-
-error[E0080]: erroneous constant used
- --> $DIR/const_refers_to_static.rs:27:5
- |
-LL | READ_INTERIOR_MUT;
- | ^^^^^^^^^^^^^^^^^ referenced constant has errors
-
-error[E0080]: erroneous constant used
- --> $DIR/const_refers_to_static.rs:29:5
- |
-LL | READ_MUT;
- | ^^^^^^^^ referenced constant has errors
-
-warning: skipping const checks
- |
-help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static.rs:13:5
- |
-LL | FOO.fetch_add(1, Ordering::Relaxed)
- | ^^^
-help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static.rs:13:5
- |
-LL | FOO.fetch_add(1, Ordering::Relaxed)
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static.rs:18:17
- |
-LL | unsafe { *(&FOO as *const _ as *const usize) }
- | ^^^
-help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static.rs:22:32
- |
-LL | const READ_MUT: u32 = unsafe { MUTABLE };
- | ^^^^^^^
-help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static.rs:22:32
- |
-LL | const READ_MUT: u32 = unsafe { MUTABLE };
- | ^^^^^^^
-
-error: aborting due to 3 previous errors; 1 warning emitted
-
-For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/const_refers_to_static.rs:13:5
- |
-LL | const MUTATE_INTERIOR_MUT: usize = {
- | --------------------------------
-LL | static FOO: AtomicUsize = AtomicUsize::new(0);
-LL | FOO.fetch_add(1, Ordering::Relaxed)
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling non-const function `AtomicUsize::fetch_add`
- |
-note: the lint level is defined here
- --> $DIR/const_refers_to_static.rs:3:10
- |
-LL | #![allow(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/const_refers_to_static.rs:18:14
- |
-LL | const READ_INTERIOR_MUT: usize = {
- | ------------------------------
-LL | static FOO: AtomicUsize = AtomicUsize::new(0);
-LL | unsafe { *(&FOO as *const _ as *const usize) }
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
- |
-note: the lint level is defined here
- --> $DIR/const_refers_to_static.rs:3:10
- |
-LL | #![allow(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/const_refers_to_static.rs:22:32
- |
-LL | const READ_MUT: u32 = unsafe { MUTABLE };
- | ------------------- ^^^^^^^ constant accesses static
- |
-note: the lint level is defined here
- --> $DIR/const_refers_to_static.rs:3:10
- |
-LL | #![allow(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static2.32bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static2.32bit.stderr
deleted file mode 100644
index 14173ac9f..000000000
--- a/src/test/ui/consts/miri_unleashed/const_refers_to_static2.32bit.stderr
+++ /dev/null
@@ -1,38 +0,0 @@
-error[E0080]: it is undefined behavior to use this value
- --> $DIR/const_refers_to_static2.rs:11:1
- |
-LL | const REF_INTERIOR_MUT: &usize = {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
- |
- = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
- = note: the raw bytes of the constant (size: 4, align: 4) {
- ╾─alloc1──╼ │ ╾──╼
- }
-
-error[E0080]: it is undefined behavior to use this value
- --> $DIR/const_refers_to_static2.rs:18:1
- |
-LL | const READ_IMMUT: &usize = {
- | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
- |
- = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
- = note: the raw bytes of the constant (size: 4, align: 4) {
- ╾─alloc2──╼ │ ╾──╼
- }
-
-warning: skipping const checks
- |
-help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static2.rs:14:18
- |
-LL | unsafe { &*(&FOO as *const _ as *const usize) }
- | ^^^
-help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static2.rs:21:6
- |
-LL | &FOO
- | ^^^
-
-error: aborting due to 2 previous errors; 1 warning emitted
-
-For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static2.64bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static2.64bit.stderr
deleted file mode 100644
index e7e51a418..000000000
--- a/src/test/ui/consts/miri_unleashed/const_refers_to_static2.64bit.stderr
+++ /dev/null
@@ -1,38 +0,0 @@
-error[E0080]: it is undefined behavior to use this value
- --> $DIR/const_refers_to_static2.rs:11:1
- |
-LL | const REF_INTERIOR_MUT: &usize = {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
- |
- = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
- = note: the raw bytes of the constant (size: 8, align: 8) {
- ╾───────alloc1────────╼ │ ╾──────╼
- }
-
-error[E0080]: it is undefined behavior to use this value
- --> $DIR/const_refers_to_static2.rs:18:1
- |
-LL | const READ_IMMUT: &usize = {
- | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
- |
- = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
- = note: the raw bytes of the constant (size: 8, align: 8) {
- ╾───────alloc2────────╼ │ ╾──────╼
- }
-
-warning: skipping const checks
- |
-help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static2.rs:14:18
- |
-LL | unsafe { &*(&FOO as *const _ as *const usize) }
- | ^^^
-help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static2.rs:21:6
- |
-LL | &FOO
- | ^^^
-
-error: aborting due to 2 previous errors; 1 warning emitted
-
-For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static2.rs b/src/test/ui/consts/miri_unleashed/const_refers_to_static2.rs
deleted file mode 100644
index 8b8e262fb..000000000
--- a/src/test/ui/consts/miri_unleashed/const_refers_to_static2.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-// compile-flags: -Zunleash-the-miri-inside-of-you
-// stderr-per-bitwidth
-#![allow(const_err)]
-
-use std::sync::atomic::AtomicUsize;
-use std::sync::atomic::Ordering;
-
-// These only fail during validation (they do not use but just create a reference to a static),
-// so they cause an immediate error when *defining* the const.
-
-const REF_INTERIOR_MUT: &usize = { //~ ERROR undefined behavior to use this value
-//~| encountered a reference pointing to a static variable
- static FOO: AtomicUsize = AtomicUsize::new(0);
- unsafe { &*(&FOO as *const _ as *const usize) }
-};
-
-// ok some day perhaps
-const READ_IMMUT: &usize = { //~ ERROR it is undefined behavior to use this value
-//~| encountered a reference pointing to a static variable
- static FOO: usize = 0;
- &FOO
-};
-
-fn main() {}
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr
index 3a22b0689..6df2fe3d0 100644
--- a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
- --> $DIR/const_refers_to_static_cross_crate.rs:12:1
+ --> $DIR/const_refers_to_static_cross_crate.rs:10:1
|
LL | const SLICE_MUT: &[u8; 1] = {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
@@ -10,13 +10,13 @@ LL | const SLICE_MUT: &[u8; 1] = {
}
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:40:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:34:9
|
LL | SLICE_MUT => true,
| ^^^^^^^^^
error[E0080]: it is undefined behavior to use this value
- --> $DIR/const_refers_to_static_cross_crate.rs:17:1
+ --> $DIR/const_refers_to_static_cross_crate.rs:15:1
|
LL | const U8_MUT: &u8 = {
| ^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
@@ -27,75 +27,55 @@ LL | const U8_MUT: &u8 = {
}
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:49:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:43:9
|
LL | U8_MUT => true,
| ^^^^^^
-warning: any use of this value will cause an error
- --> $DIR/const_refers_to_static_cross_crate.rs:25:15
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static_cross_crate.rs:22:15
|
-LL | const U8_MUT2: &u8 = {
- | ------------------
LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
- |
-note: the lint level is defined here
- --> $DIR/const_refers_to_static_cross_crate.rs:23:8
- |
-LL | #[warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:60:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:54:9
|
LL | U8_MUT2 => true,
| ^^^^^^^
-warning: any use of this value will cause an error
- --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static_cross_crate.rs:27:20
|
-LL | const U8_MUT3: &u8 = {
- | ------------------
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
- |
-note: the lint level is defined here
- --> $DIR/const_refers_to_static_cross_crate.rs:30:8
- |
-LL | #[warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:68:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:62:9
|
LL | U8_MUT3 => true,
| ^^^^^^^
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:40:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:34:9
|
LL | SLICE_MUT => true,
| ^^^^^^^^^
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:49:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:43:9
|
LL | U8_MUT => true,
| ^^^^^^
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:60:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:54:9
|
LL | U8_MUT2 => true,
| ^^^^^^^
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:68:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:62:9
|
LL | U8_MUT3 => true,
| ^^^^^^^
@@ -103,90 +83,56 @@ LL | U8_MUT3 => true,
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:14:15
+ --> $DIR/const_refers_to_static_cross_crate.rs:12:15
|
LL | unsafe { &static_cross_crate::ZERO }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:14:15
+ --> $DIR/const_refers_to_static_cross_crate.rs:12:15
|
LL | unsafe { &static_cross_crate::ZERO }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:19:15
+ --> $DIR/const_refers_to_static_cross_crate.rs:17:15
|
LL | unsafe { &static_cross_crate::ZERO[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:19:15
+ --> $DIR/const_refers_to_static_cross_crate.rs:17:15
|
LL | unsafe { &static_cross_crate::ZERO[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:19:15
+ --> $DIR/const_refers_to_static_cross_crate.rs:17:15
|
LL | unsafe { &static_cross_crate::ZERO[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:25:17
+ --> $DIR/const_refers_to_static_cross_crate.rs:22:17
|
LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ --> $DIR/const_refers_to_static_cross_crate.rs:27:20
|
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ --> $DIR/const_refers_to_static_cross_crate.rs:27:20
|
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ --> $DIR/const_refers_to_static_cross_crate.rs:27:20
|
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ --> $DIR/const_refers_to_static_cross_crate.rs:27:20
|
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 10 previous errors; 3 warnings emitted
+error: aborting due to 12 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/const_refers_to_static_cross_crate.rs:25:15
- |
-LL | const U8_MUT2: &u8 = {
- | ------------------
-LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
- |
-note: the lint level is defined here
- --> $DIR/const_refers_to_static_cross_crate.rs:23:8
- |
-LL | #[warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/const_refers_to_static_cross_crate.rs:32:20
- |
-LL | const U8_MUT3: &u8 = {
- | ------------------
-LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
- |
-note: the lint level is defined here
- --> $DIR/const_refers_to_static_cross_crate.rs:30:8
- |
-LL | #[warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr
index 39c874d64..8802f3ada 100644
--- a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
- --> $DIR/const_refers_to_static_cross_crate.rs:12:1
+ --> $DIR/const_refers_to_static_cross_crate.rs:10:1
|
LL | const SLICE_MUT: &[u8; 1] = {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
@@ -10,13 +10,13 @@ LL | const SLICE_MUT: &[u8; 1] = {
}
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:40:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:34:9
|
LL | SLICE_MUT => true,
| ^^^^^^^^^
error[E0080]: it is undefined behavior to use this value
- --> $DIR/const_refers_to_static_cross_crate.rs:17:1
+ --> $DIR/const_refers_to_static_cross_crate.rs:15:1
|
LL | const U8_MUT: &u8 = {
| ^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a reference pointing to a static variable in a constant
@@ -27,75 +27,55 @@ LL | const U8_MUT: &u8 = {
}
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:49:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:43:9
|
LL | U8_MUT => true,
| ^^^^^^
-warning: any use of this value will cause an error
- --> $DIR/const_refers_to_static_cross_crate.rs:25:15
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static_cross_crate.rs:22:15
|
-LL | const U8_MUT2: &u8 = {
- | ------------------
LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
- |
-note: the lint level is defined here
- --> $DIR/const_refers_to_static_cross_crate.rs:23:8
- |
-LL | #[warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:60:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:54:9
|
LL | U8_MUT2 => true,
| ^^^^^^^
-warning: any use of this value will cause an error
- --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+error[E0080]: evaluation of constant value failed
+ --> $DIR/const_refers_to_static_cross_crate.rs:27:20
|
-LL | const U8_MUT3: &u8 = {
- | ------------------
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
- |
-note: the lint level is defined here
- --> $DIR/const_refers_to_static_cross_crate.rs:30:8
- |
-LL | #[warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:68:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:62:9
|
LL | U8_MUT3 => true,
| ^^^^^^^
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:40:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:34:9
|
LL | SLICE_MUT => true,
| ^^^^^^^^^
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:49:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:43:9
|
LL | U8_MUT => true,
| ^^^^^^
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:60:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:54:9
|
LL | U8_MUT2 => true,
| ^^^^^^^
error: could not evaluate constant pattern
- --> $DIR/const_refers_to_static_cross_crate.rs:68:9
+ --> $DIR/const_refers_to_static_cross_crate.rs:62:9
|
LL | U8_MUT3 => true,
| ^^^^^^^
@@ -103,90 +83,56 @@ LL | U8_MUT3 => true,
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:14:15
+ --> $DIR/const_refers_to_static_cross_crate.rs:12:15
|
LL | unsafe { &static_cross_crate::ZERO }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:14:15
+ --> $DIR/const_refers_to_static_cross_crate.rs:12:15
|
LL | unsafe { &static_cross_crate::ZERO }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:19:15
+ --> $DIR/const_refers_to_static_cross_crate.rs:17:15
|
LL | unsafe { &static_cross_crate::ZERO[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:19:15
+ --> $DIR/const_refers_to_static_cross_crate.rs:17:15
|
LL | unsafe { &static_cross_crate::ZERO[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:19:15
+ --> $DIR/const_refers_to_static_cross_crate.rs:17:15
|
LL | unsafe { &static_cross_crate::ZERO[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:25:17
+ --> $DIR/const_refers_to_static_cross_crate.rs:22:17
|
LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ --> $DIR/const_refers_to_static_cross_crate.rs:27:20
|
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ --> $DIR/const_refers_to_static_cross_crate.rs:27:20
|
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ --> $DIR/const_refers_to_static_cross_crate.rs:27:20
|
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/const_refers_to_static_cross_crate.rs:32:20
+ --> $DIR/const_refers_to_static_cross_crate.rs:27:20
|
LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 10 previous errors; 3 warnings emitted
+error: aborting due to 12 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/const_refers_to_static_cross_crate.rs:25:15
- |
-LL | const U8_MUT2: &u8 = {
- | ------------------
-LL | unsafe { &(*static_cross_crate::ZERO_REF)[0] }
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
- |
-note: the lint level is defined here
- --> $DIR/const_refers_to_static_cross_crate.rs:23:8
- |
-LL | #[warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
-Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/const_refers_to_static_cross_crate.rs:32:20
- |
-LL | const U8_MUT3: &u8 = {
- | ------------------
-LL | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static
- |
-note: the lint level is defined here
- --> $DIR/const_refers_to_static_cross_crate.rs:30:8
- |
-LL | #[warn(const_err)]
- | ^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs
index 4638d73fc..bf4f14f4d 100644
--- a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs
@@ -1,9 +1,7 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
// aux-build:static_cross_crate.rs
// stderr-per-bitwidth
-#![allow(const_err)]
-
-#![feature(exclusive_range_pattern, half_open_range_patterns)]
+#![feature(exclusive_range_pattern, half_open_range_patterns_in_slices)]
extern crate static_cross_crate;
@@ -19,20 +17,16 @@ const U8_MUT: &u8 = { //~ ERROR undefined behavior to use this value
unsafe { &static_cross_crate::ZERO[0] }
};
-// Also test indirection that reads from other static. This causes a const_err.
-#[warn(const_err)]
+// Also test indirection that reads from other static.
const U8_MUT2: &u8 = {
unsafe { &(*static_cross_crate::ZERO_REF)[0] }
- //~^ WARN [const_err]
+ //~^ ERROR evaluation of constant value failed
//~| constant accesses static
- //~| WARN this was previously accepted by the compiler but is being phased out
};
-#[warn(const_err)]
const U8_MUT3: &u8 = {
unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } }
- //~^ WARN [const_err]
+ //~^ ERROR evaluation of constant value failed
//~| constant accesses static
- //~| WARN this was previously accepted by the compiler but is being phased out
};
pub fn test(x: &[u8; 1]) -> bool {
diff --git a/src/test/ui/consts/miri_unleashed/drop.rs b/src/test/ui/consts/miri_unleashed/drop.rs
index 4afa954d9..3942e7ef7 100644
--- a/src/test/ui/consts/miri_unleashed/drop.rs
+++ b/src/test/ui/consts/miri_unleashed/drop.rs
@@ -1,6 +1,5 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
// error-pattern: calling non-const function `<Vec<i32> as Drop>::drop`
-#![allow(const_err)]
use std::mem::ManuallyDrop;
diff --git a/src/test/ui/consts/miri_unleashed/drop.stderr b/src/test/ui/consts/miri_unleashed/drop.stderr
index 36db6b786..a3a502723 100644
--- a/src/test/ui/consts/miri_unleashed/drop.stderr
+++ b/src/test/ui/consts/miri_unleashed/drop.stderr
@@ -7,15 +7,15 @@ LL | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
| calling non-const function `<Vec<i32> as Drop>::drop`
| inside `std::ptr::drop_in_place::<Vec<i32>> - shim(Some(Vec<i32>))` at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
|
- ::: $DIR/drop.rs:18:1
+ ::: $DIR/drop.rs:17:1
|
LL | };
- | - inside `TEST_BAD` at $DIR/drop.rs:18:1
+ | - inside `TEST_BAD` at $DIR/drop.rs:17:1
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
- --> $DIR/drop.rs:17:9
+ --> $DIR/drop.rs:16:9
|
LL | let _v: Vec<i32> = Vec::new();
| ^^
diff --git a/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs b/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs
index 8b17f6885..c24d3338e 100644
--- a/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs
+++ b/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs
@@ -1,5 +1,3 @@
-#![allow(const_err)]
-
// a test demonstrating why we do need to run static const qualification on associated constants
// instead of just checking the final constant
@@ -8,7 +6,7 @@ trait Foo<T> {
}
trait Bar<T, U: Foo<T>> {
- const F: u32 = (U::X, 42).1; //~ ERROR destructors cannot be evaluated at compile-time
+ const F: u32 = (U::X, 42).1; //~ ERROR destructor of
}
impl Foo<u32> for () {
diff --git a/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr b/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr
index 0b6cb2fab..45ed88b1b 100644
--- a/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr
+++ b/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr
@@ -1,10 +1,10 @@
-error[E0493]: destructors cannot be evaluated at compile-time
- --> $DIR/feature-gate-unleash_the_miri_inside_of_you.rs:11:20
+error[E0493]: destructor of `(T, u32)` cannot be evaluated at compile-time
+ --> $DIR/feature-gate-unleash_the_miri_inside_of_you.rs:9:20
|
LL | const F: u32 = (U::X, 42).1;
| ^^^^^^^^^^ - value is dropped here
| |
- | constants cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constants
error: aborting due to previous error
diff --git a/src/test/ui/consts/miri_unleashed/inline_asm.rs b/src/test/ui/consts/miri_unleashed/inline_asm.rs
index 697117033..6fd52ceb2 100644
--- a/src/test/ui/consts/miri_unleashed/inline_asm.rs
+++ b/src/test/ui/consts/miri_unleashed/inline_asm.rs
@@ -1,6 +1,5 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
// only-x86_64
-#![allow(const_err)]
use std::arch::asm;
diff --git a/src/test/ui/consts/miri_unleashed/inline_asm.stderr b/src/test/ui/consts/miri_unleashed/inline_asm.stderr
index 595b859cb..6317cd882 100644
--- a/src/test/ui/consts/miri_unleashed/inline_asm.stderr
+++ b/src/test/ui/consts/miri_unleashed/inline_asm.stderr
@@ -1,5 +1,5 @@
error[E0080]: could not evaluate static initializer
- --> $DIR/inline_asm.rs:11:14
+ --> $DIR/inline_asm.rs:10:14
|
LL | unsafe { asm!("nop"); }
| ^^^^^^^^^^^ inline assembly is not supported
@@ -7,7 +7,7 @@ LL | unsafe { asm!("nop"); }
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
- --> $DIR/inline_asm.rs:11:14
+ --> $DIR/inline_asm.rs:10:14
|
LL | unsafe { asm!("nop"); }
| ^^^^^^^^^^^
diff --git a/src/test/ui/consts/miri_unleashed/mutable_references.rs b/src/test/ui/consts/miri_unleashed/mutable_references.rs
index ca927ef4a..4e9964647 100644
--- a/src/test/ui/consts/miri_unleashed/mutable_references.rs
+++ b/src/test/ui/consts/miri_unleashed/mutable_references.rs
@@ -1,5 +1,4 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
-#![allow(const_err)]
use std::cell::UnsafeCell;
diff --git a/src/test/ui/consts/miri_unleashed/mutable_references.stderr b/src/test/ui/consts/miri_unleashed/mutable_references.stderr
index c6180c1e0..3ed96701a 100644
--- a/src/test/ui/consts/miri_unleashed/mutable_references.stderr
+++ b/src/test/ui/consts/miri_unleashed/mutable_references.stderr
@@ -1,5 +1,5 @@
error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
- --> $DIR/mutable_references.rs:36:5
+ --> $DIR/mutable_references.rs:35:5
|
LL | *OH_YES = 99;
| ^^^^^^^^^^^^ cannot assign
@@ -7,27 +7,27 @@ LL | *OH_YES = 99;
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
- --> $DIR/mutable_references.rs:9:26
+ --> $DIR/mutable_references.rs:8:26
|
LL | static FOO: &&mut u32 = &&mut 42;
| ^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/mutable_references.rs:13:23
+ --> $DIR/mutable_references.rs:12:23
|
LL | static BAR: &mut () = &mut ();
| ^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/mutable_references.rs:18:28
+ --> $DIR/mutable_references.rs:17:28
|
LL | static BOO: &mut Foo<()> = &mut Foo(());
| ^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/mutable_references.rs:26:8
+ --> $DIR/mutable_references.rs:25:8
|
LL | x: &UnsafeCell::new(42),
| ^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/mutable_references.rs:30:27
+ --> $DIR/mutable_references.rs:29:27
|
LL | static OH_YES: &mut i32 = &mut 42;
| ^^^^^^^
diff --git a/src/test/ui/consts/miri_unleashed/mutable_references_err.32bit.stderr b/src/test/ui/consts/miri_unleashed/mutable_references_err.32bit.stderr
index 7ea35f70d..0ea179240 100644
--- a/src/test/ui/consts/miri_unleashed/mutable_references_err.32bit.stderr
+++ b/src/test/ui/consts/miri_unleashed/mutable_references_err.32bit.stderr
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
- --> $DIR/mutable_references_err.rs:17:1
+ --> $DIR/mutable_references_err.rs:15:1
|
LL | const MUH: Meh = Meh {
| ^^^^^^^^^^^^^^ constructing invalid value at .x.<deref>: encountered `UnsafeCell` in a `const`
@@ -10,7 +10,7 @@ LL | const MUH: Meh = Meh {
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/mutable_references_err.rs:27:1
+ --> $DIR/mutable_references_err.rs:25:1
|
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>.x: encountered `UnsafeCell` in a `const`
@@ -21,7 +21,7 @@ LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/mutable_references_err.rs:31:1
+ --> $DIR/mutable_references_err.rs:29:1
|
LL | const BLUNT: &mut i32 = &mut 42;
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference in a `const`
@@ -34,17 +34,17 @@ LL | const BLUNT: &mut i32 = &mut 42;
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
- --> $DIR/mutable_references_err.rs:18:8
+ --> $DIR/mutable_references_err.rs:16:8
|
LL | x: &UnsafeCell::new(42),
| ^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/mutable_references_err.rs:27:27
+ --> $DIR/mutable_references_err.rs:25:27
|
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/mutable_references_err.rs:31:25
+ --> $DIR/mutable_references_err.rs:29:25
|
LL | const BLUNT: &mut i32 = &mut 42;
| ^^^^^^^
diff --git a/src/test/ui/consts/miri_unleashed/mutable_references_err.64bit.stderr b/src/test/ui/consts/miri_unleashed/mutable_references_err.64bit.stderr
index 5ad398930..67959d256 100644
--- a/src/test/ui/consts/miri_unleashed/mutable_references_err.64bit.stderr
+++ b/src/test/ui/consts/miri_unleashed/mutable_references_err.64bit.stderr
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
- --> $DIR/mutable_references_err.rs:17:1
+ --> $DIR/mutable_references_err.rs:15:1
|
LL | const MUH: Meh = Meh {
| ^^^^^^^^^^^^^^ constructing invalid value at .x.<deref>: encountered `UnsafeCell` in a `const`
@@ -10,7 +10,7 @@ LL | const MUH: Meh = Meh {
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/mutable_references_err.rs:27:1
+ --> $DIR/mutable_references_err.rs:25:1
|
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>.x: encountered `UnsafeCell` in a `const`
@@ -21,7 +21,7 @@ LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
}
error[E0080]: it is undefined behavior to use this value
- --> $DIR/mutable_references_err.rs:31:1
+ --> $DIR/mutable_references_err.rs:29:1
|
LL | const BLUNT: &mut i32 = &mut 42;
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference in a `const`
@@ -34,17 +34,17 @@ LL | const BLUNT: &mut i32 = &mut 42;
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
- --> $DIR/mutable_references_err.rs:18:8
+ --> $DIR/mutable_references_err.rs:16:8
|
LL | x: &UnsafeCell::new(42),
| ^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/mutable_references_err.rs:27:27
+ --> $DIR/mutable_references_err.rs:25:27
|
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: skipping check that does not even have a feature gate
- --> $DIR/mutable_references_err.rs:31:25
+ --> $DIR/mutable_references_err.rs:29:25
|
LL | const BLUNT: &mut i32 = &mut 42;
| ^^^^^^^
diff --git a/src/test/ui/consts/miri_unleashed/mutable_references_err.rs b/src/test/ui/consts/miri_unleashed/mutable_references_err.rs
index 722b9cf94..6399b122b 100644
--- a/src/test/ui/consts/miri_unleashed/mutable_references_err.rs
+++ b/src/test/ui/consts/miri_unleashed/mutable_references_err.rs
@@ -1,8 +1,6 @@
// stderr-per-bitwidth
// compile-flags: -Zunleash-the-miri-inside-of-you
-#![allow(const_err)]
-
use std::cell::UnsafeCell;
// this test ensures that our mutability story is sound
diff --git a/src/test/ui/consts/miri_unleashed/mutating_global.rs b/src/test/ui/consts/miri_unleashed/mutating_global.rs
index 902fe0aa1..231f4af0a 100644
--- a/src/test/ui/consts/miri_unleashed/mutating_global.rs
+++ b/src/test/ui/consts/miri_unleashed/mutating_global.rs
@@ -1,5 +1,4 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
-#![allow(const_err)]
// Make sure we cannot mutate globals.
diff --git a/src/test/ui/consts/miri_unleashed/mutating_global.stderr b/src/test/ui/consts/miri_unleashed/mutating_global.stderr
index ba9dd5619..c8770c8d7 100644
--- a/src/test/ui/consts/miri_unleashed/mutating_global.stderr
+++ b/src/test/ui/consts/miri_unleashed/mutating_global.stderr
@@ -1,5 +1,5 @@
error[E0080]: could not evaluate static initializer
- --> $DIR/mutating_global.rs:10:9
+ --> $DIR/mutating_global.rs:9:9
|
LL | GLOBAL = 99
| ^^^^^^^^^^^ modifying a static's initial value from another static's initializer
diff --git a/src/test/ui/consts/miri_unleashed/non_const_fn.rs b/src/test/ui/consts/miri_unleashed/non_const_fn.rs
index 70da94df7..44ab60dca 100644
--- a/src/test/ui/consts/miri_unleashed/non_const_fn.rs
+++ b/src/test/ui/consts/miri_unleashed/non_const_fn.rs
@@ -1,7 +1,5 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
-#![allow(const_err)]
-
// A test demonstrating that we prevent calling non-const fn during CTFE.
fn foo() {}
diff --git a/src/test/ui/consts/miri_unleashed/non_const_fn.stderr b/src/test/ui/consts/miri_unleashed/non_const_fn.stderr
index 3e9658ad8..57836f796 100644
--- a/src/test/ui/consts/miri_unleashed/non_const_fn.stderr
+++ b/src/test/ui/consts/miri_unleashed/non_const_fn.stderr
@@ -1,5 +1,5 @@
error[E0080]: could not evaluate static initializer
- --> $DIR/non_const_fn.rs:9:16
+ --> $DIR/non_const_fn.rs:7:16
|
LL | static C: () = foo();
| ^^^^^ calling non-const function `foo`
@@ -7,7 +7,7 @@ LL | static C: () = foo();
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
- --> $DIR/non_const_fn.rs:9:16
+ --> $DIR/non_const_fn.rs:7:16
|
LL | static C: () = foo();
| ^^^^^
diff --git a/src/test/ui/consts/miri_unleashed/ptr_arith.rs b/src/test/ui/consts/miri_unleashed/ptr_arith.rs
index 6a19b2945..4d12960b8 100644
--- a/src/test/ui/consts/miri_unleashed/ptr_arith.rs
+++ b/src/test/ui/consts/miri_unleashed/ptr_arith.rs
@@ -1,6 +1,5 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
#![feature(core_intrinsics)]
-#![allow(const_err)]
// During CTFE, we prevent pointer-to-int casts.
// Pointer comparisons are prevented in the trait system.
diff --git a/src/test/ui/consts/miri_unleashed/ptr_arith.stderr b/src/test/ui/consts/miri_unleashed/ptr_arith.stderr
index e0c4fa175..30fd3a55e 100644
--- a/src/test/ui/consts/miri_unleashed/ptr_arith.stderr
+++ b/src/test/ui/consts/miri_unleashed/ptr_arith.stderr
@@ -1,11 +1,11 @@
error[E0080]: could not evaluate static initializer
- --> $DIR/ptr_arith.rs:9:13
+ --> $DIR/ptr_arith.rs:8:13
|
LL | let x = &0 as *const _ as usize;
| ^^^^^^^^^^^^^^^^^^^^^^^ exposing pointers is not possible at compile-time
error[E0080]: could not evaluate static initializer
- --> $DIR/ptr_arith.rs:17:14
+ --> $DIR/ptr_arith.rs:16:14
|
LL | let _v = x + 0;
| ^ unable to turn pointer into raw bytes
@@ -16,7 +16,7 @@ LL | let _v = x + 0;
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
- --> $DIR/ptr_arith.rs:9:13
+ --> $DIR/ptr_arith.rs:8:13
|
LL | let x = &0 as *const _ as usize;
| ^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/test/ui/consts/miri_unleashed/raw_mutable_const.rs b/src/test/ui/consts/miri_unleashed/raw_mutable_const.rs
index cabd754e0..5f8ec4e6e 100644
--- a/src/test/ui/consts/miri_unleashed/raw_mutable_const.rs
+++ b/src/test/ui/consts/miri_unleashed/raw_mutable_const.rs
@@ -1,7 +1,5 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
-#![allow(const_err)]
-
use std::cell::UnsafeCell;
const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
diff --git a/src/test/ui/consts/miri_unleashed/raw_mutable_const.stderr b/src/test/ui/consts/miri_unleashed/raw_mutable_const.stderr
index e145f6dd2..f8dc11d69 100644
--- a/src/test/ui/consts/miri_unleashed/raw_mutable_const.stderr
+++ b/src/test/ui/consts/miri_unleashed/raw_mutable_const.stderr
@@ -1,5 +1,5 @@
error: untyped pointers are not allowed in constant
- --> $DIR/raw_mutable_const.rs:7:1
+ --> $DIR/raw_mutable_const.rs:5:1
|
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -7,7 +7,7 @@ LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *m
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
- --> $DIR/raw_mutable_const.rs:7:38
+ --> $DIR/raw_mutable_const.rs:5:38
|
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
| ^^^^^^^^^^^^^^^^^^^^
diff --git a/src/test/ui/consts/miri_unleashed/tls.rs b/src/test/ui/consts/miri_unleashed/tls.rs
index 7d4f8962a..d06d7cf19 100644
--- a/src/test/ui/consts/miri_unleashed/tls.rs
+++ b/src/test/ui/consts/miri_unleashed/tls.rs
@@ -1,6 +1,5 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
#![feature(thread_local)]
-#![allow(const_err)]
use std::thread;
diff --git a/src/test/ui/consts/miri_unleashed/tls.stderr b/src/test/ui/consts/miri_unleashed/tls.stderr
index a49e50a3e..436c51123 100644
--- a/src/test/ui/consts/miri_unleashed/tls.stderr
+++ b/src/test/ui/consts/miri_unleashed/tls.stderr
@@ -1,11 +1,11 @@
error[E0080]: could not evaluate static initializer
- --> $DIR/tls.rs:12:25
+ --> $DIR/tls.rs:11:25
|
LL | unsafe { let _val = A; }
| ^ cannot access thread local static (DefId(0:6 ~ tls[78b0]::A))
error[E0080]: could not evaluate static initializer
- --> $DIR/tls.rs:19:26
+ --> $DIR/tls.rs:18:26
|
LL | unsafe { let _val = &A; }
| ^ cannot access thread local static (DefId(0:6 ~ tls[78b0]::A))
@@ -13,12 +13,12 @@ LL | unsafe { let _val = &A; }
warning: skipping const checks
|
help: skipping check that does not even have a feature gate
- --> $DIR/tls.rs:12:25
+ --> $DIR/tls.rs:11:25
|
LL | unsafe { let _val = A; }
| ^
help: skipping check that does not even have a feature gate
- --> $DIR/tls.rs:19:26
+ --> $DIR/tls.rs:18:26
|
LL | unsafe { let _val = &A; }
| ^
diff --git a/src/test/ui/consts/promote-not.rs b/src/test/ui/consts/promote-not.rs
index 6830b23cf..907617052 100644
--- a/src/test/ui/consts/promote-not.rs
+++ b/src/test/ui/consts/promote-not.rs
@@ -1,6 +1,6 @@
// ignore-tidy-linelength
// Test various things that we do not want to promote.
-#![allow(unconditional_panic, const_err)]
+#![allow(unconditional_panic)]
use std::cell::Cell;
diff --git a/src/test/ui/consts/ptr_comparisons.rs b/src/test/ui/consts/ptr_comparisons.rs
index 0a3c2d4be..f442e6138 100644
--- a/src/test/ui/consts/ptr_comparisons.rs
+++ b/src/test/ui/consts/ptr_comparisons.rs
@@ -55,11 +55,9 @@ const _: *const u8 =
//~| out-of-bounds
const _: usize = unsafe { std::mem::transmute::<*const usize, usize>(FOO) + 4 };
-//~^ ERROR any use of this value will cause an error
+//~^ ERROR evaluation of constant value failed
//~| unable to turn pointer into raw bytes
-//~| WARN this was previously accepted by the compiler but is being phased out
const _: usize = unsafe { *std::mem::transmute::<&&usize, &usize>(&FOO) + 4 };
-//~^ ERROR any use of this value will cause an error
+//~^ ERROR evaluation of constant value failed
//~| unable to turn pointer into raw bytes
-//~| WARN this was previously accepted by the compiler but is being phased out
diff --git a/src/test/ui/consts/ptr_comparisons.stderr b/src/test/ui/consts/ptr_comparisons.stderr
index 3de2aba5b..b71964b92 100644
--- a/src/test/ui/consts/ptr_comparisons.stderr
+++ b/src/test/ui/consts/ptr_comparisons.stderr
@@ -18,55 +18,24 @@ error[E0080]: evaluation of constant value failed
LL | unsafe { std::ptr::addr_of!((*(FOO as *const usize as *const [u8; 1000]))[999]) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dereferencing pointer failed: alloc3 has size $WORD, so pointer to 1000 bytes starting at offset 0 is out-of-bounds
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/ptr_comparisons.rs:57:27
|
LL | const _: usize = unsafe { std::mem::transmute::<*const usize, usize>(FOO) + 4 };
- | -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: any use of this value will cause an error
- --> $DIR/ptr_comparisons.rs:62:27
+error[E0080]: evaluation of constant value failed
+ --> $DIR/ptr_comparisons.rs:61:27
|
LL | const _: usize = unsafe { *std::mem::transmute::<&&usize, &usize>(&FOO) + 4 };
- | -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ptr_comparisons.rs:57:27
- |
-LL | const _: usize = unsafe { std::mem::transmute::<*const usize, usize>(FOO) + 4 };
- | -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
-Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/ptr_comparisons.rs:62:27
- |
-LL | const _: usize = unsafe { *std::mem::transmute::<&&usize, &usize>(&FOO) + 4 };
- | -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = help: this code performed an operation that depends on the underlying bytes representing a pointer
- = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-
diff --git a/src/test/ui/consts/qualif-indirect-mutation-fail.rs b/src/test/ui/consts/qualif-indirect-mutation-fail.rs
index f74a25a34..a6d293404 100644
--- a/src/test/ui/consts/qualif-indirect-mutation-fail.rs
+++ b/src/test/ui/consts/qualif-indirect-mutation-fail.rs
@@ -6,13 +6,13 @@
// Mutable borrow of a field with drop impl.
pub const fn f() {
- let mut a: (u32, Option<String>) = (0, None); //~ ERROR destructors cannot be evaluated
+ let mut a: (u32, Option<String>) = (0, None); //~ ERROR destructor of
let _ = &mut a.1;
}
// Mutable borrow of a type with drop impl.
pub const A1: () = {
- let mut x = None; //~ ERROR destructors cannot be evaluated
+ let mut x = None; //~ ERROR destructor of
let mut y = Some(String::new());
let a = &mut x;
let b = &mut y;
@@ -28,12 +28,12 @@ pub const A2: () = {
let b = &mut y;
std::mem::swap(a, b);
std::mem::forget(y);
- let _z = x; //~ ERROR destructors cannot be evaluated
+ let _z = x; //~ ERROR destructor of
};
// Shared borrow of a type that might be !Freeze and Drop.
pub const fn g1<T>() {
- let x: Option<T> = None; //~ ERROR destructors cannot be evaluated
+ let x: Option<T> = None; //~ ERROR destructor of
let _ = x.is_some();
}
@@ -41,24 +41,24 @@ pub const fn g1<T>() {
pub const fn g2<T>() {
let x: Option<T> = None;
let _ = x.is_some();
- let _y = x; //~ ERROR destructors cannot be evaluated
+ let _y = x; //~ ERROR destructor of
}
// Mutable raw reference to a Drop type.
pub const fn address_of_mut() {
- let mut x: Option<String> = None; //~ ERROR destructors cannot be evaluated
+ let mut x: Option<String> = None; //~ ERROR destructor of
&raw mut x;
- let mut y: Option<String> = None; //~ ERROR destructors cannot be evaluated
+ let mut y: Option<String> = None; //~ ERROR destructor of
std::ptr::addr_of_mut!(y);
}
// Const raw reference to a Drop type. Conservatively assumed to allow mutation
// until resolution of https://github.com/rust-lang/rust/issues/56604.
pub const fn address_of_const() {
- let x: Option<String> = None; //~ ERROR destructors cannot be evaluated
+ let x: Option<String> = None; //~ ERROR destructor of
&raw const x;
- let y: Option<String> = None; //~ ERROR destructors cannot be evaluated
+ let y: Option<String> = None; //~ ERROR destructor of
std::ptr::addr_of!(y);
}
diff --git a/src/test/ui/consts/qualif-indirect-mutation-fail.stderr b/src/test/ui/consts/qualif-indirect-mutation-fail.stderr
index 713df12b7..6379c00e4 100644
--- a/src/test/ui/consts/qualif-indirect-mutation-fail.stderr
+++ b/src/test/ui/consts/qualif-indirect-mutation-fail.stderr
@@ -1,56 +1,56 @@
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `(u32, Option<String>)` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:9:9
|
LL | let mut a: (u32, Option<String>) = (0, None);
- | ^^^^^ constant functions cannot evaluate destructors
+ | ^^^^^ the destructor for this type cannot be evaluated in constant functions
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:15:9
|
LL | let mut x = None;
- | ^^^^^ constants cannot evaluate destructors
+ | ^^^^^ the destructor for this type cannot be evaluated in constants
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:31:9
|
LL | let _z = x;
- | ^^ constants cannot evaluate destructors
+ | ^^ the destructor for this type cannot be evaluated in constants
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<T>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:36:9
|
LL | let x: Option<T> = None;
- | ^ constant functions cannot evaluate destructors
+ | ^ the destructor for this type cannot be evaluated in constant functions
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<T>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:44:9
|
LL | let _y = x;
- | ^^ constant functions cannot evaluate destructors
+ | ^^ the destructor for this type cannot be evaluated in constant functions
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:52:9
|
LL | let mut y: Option<String> = None;
- | ^^^^^ constant functions cannot evaluate destructors
+ | ^^^^^ the destructor for this type cannot be evaluated in constant functions
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:49:9
|
LL | let mut x: Option<String> = None;
- | ^^^^^ constant functions cannot evaluate destructors
+ | ^^^^^ the destructor for this type cannot be evaluated in constant functions
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:62:9
|
LL | let y: Option<String> = None;
- | ^ constant functions cannot evaluate destructors
+ | ^ the destructor for this type cannot be evaluated in constant functions
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Option<String>` cannot be evaluated at compile-time
--> $DIR/qualif-indirect-mutation-fail.rs:59:9
|
LL | let x: Option<String> = None;
- | ^ constant functions cannot evaluate destructors
+ | ^ the destructor for this type cannot be evaluated in constant functions
error: aborting due to 9 previous errors
diff --git a/src/test/ui/consts/raw-ptr-const.rs b/src/test/ui/consts/raw-ptr-const.rs
index 00fad046b..b9c542d03 100644
--- a/src/test/ui/consts/raw-ptr-const.rs
+++ b/src/test/ui/consts/raw-ptr-const.rs
@@ -1,5 +1,3 @@
-#![allow(const_err)] // make sure we hit the `delay_span_bug`
-
// This is a regression test for a `delay_span_bug` during interning when a constant
// evaluates to a (non-dangling) raw pointer. For now this errors; potentially it
// could also be allowed.
diff --git a/src/test/ui/consts/raw-ptr-const.stderr b/src/test/ui/consts/raw-ptr-const.stderr
index 0ebe1e95c..f7b53433b 100644
--- a/src/test/ui/consts/raw-ptr-const.stderr
+++ b/src/test/ui/consts/raw-ptr-const.stderr
@@ -1,5 +1,5 @@
error: untyped pointers are not allowed in constant
- --> $DIR/raw-ptr-const.rs:7:1
+ --> $DIR/raw-ptr-const.rs:5:1
|
LL | const CONST_RAW: *const Vec<i32> = &Vec::new() as *const _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/test/ui/consts/recursive.rs b/src/test/ui/consts/recursive.rs
index 664940c52..5d736e31b 100644
--- a/src/test/ui/consts/recursive.rs
+++ b/src/test/ui/consts/recursive.rs
@@ -2,8 +2,7 @@
const fn f<T>(x: T) { //~ WARN function cannot return without recursing
f(x);
- //~^ ERROR any use of this value will cause an error
- //~| WARN this was previously accepted by the compiler
+ //~^ ERROR evaluation of constant value failed
}
const X: () = f(1);
diff --git a/src/test/ui/consts/recursive.stderr b/src/test/ui/consts/recursive.stderr
index 647ed1db2..14fa3da7a 100644
--- a/src/test/ui/consts/recursive.stderr
+++ b/src/test/ui/consts/recursive.stderr
@@ -6,10 +6,10 @@ LL | const fn f<T>(x: T) {
LL | f(x);
| ---- recursive call site
|
- = note: `#[warn(unconditional_recursion)]` on by default
= help: a `loop` may express intention better if this is on purpose
+ = note: `#[warn(unconditional_recursion)]` on by default
-error: any use of this value will cause an error
+error[E0080]: evaluation of constant value failed
--> $DIR/recursive.rs:4:5
|
LL | f(x);
@@ -18,33 +18,10 @@ LL | f(x);
| reached the configured maximum number of stack frames
| inside `f::<i32>` at $DIR/recursive.rs:4:5
| [... 126 additional calls inside `f::<i32>` at $DIR/recursive.rs:4:5 ...]
- | inside `X` at $DIR/recursive.rs:9:15
...
LL | const X: () = f(1);
- | -----------
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ---- inside `X` at $DIR/recursive.rs:8:15
error: aborting due to previous error; 1 warning emitted
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/recursive.rs:4:5
- |
-LL | f(x);
- | ^^^^
- | |
- | reached the configured maximum number of stack frames
- | inside `f::<i32>` at $DIR/recursive.rs:4:5
- | [... 126 additional calls inside `f::<i32>` at $DIR/recursive.rs:4:5 ...]
- | inside `X` at $DIR/recursive.rs:9:15
-...
-LL | const X: () = f(1);
- | -----------
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/refs_check_const_eq-issue-88384.stderr b/src/test/ui/consts/refs_check_const_eq-issue-88384.stderr
index 4f2f5e244..3855b5f2a 100644
--- a/src/test/ui/consts/refs_check_const_eq-issue-88384.stderr
+++ b/src/test/ui/consts/refs_check_const_eq-issue-88384.stderr
@@ -4,8 +4,8 @@ warning: the feature `adt_const_params` is incomplete and may not be safe to use
LL | #![feature(adt_const_params)]
| ^^^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error[E0741]: using function pointers as const generic parameters is forbidden
--> $DIR/refs_check_const_eq-issue-88384.rs:10:21
diff --git a/src/test/ui/consts/stable-precise-live-drops-in-libcore.rs b/src/test/ui/consts/stable-precise-live-drops-in-libcore.rs
index 2b970390f..7cd3dbec9 100644
--- a/src/test/ui/consts/stable-precise-live-drops-in-libcore.rs
+++ b/src/test/ui/consts/stable-precise-live-drops-in-libcore.rs
@@ -11,7 +11,7 @@ impl<T> Either<T, T> {
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "foo", since = "1.0.0")]
pub const fn unwrap(self) -> T {
- //~^ ERROR destructors cannot be evaluated at compile-time
+ //~^ ERROR destructor of
match self {
Self::Left(t) => t,
Self::Right(t) => t,
diff --git a/src/test/ui/consts/stable-precise-live-drops-in-libcore.stderr b/src/test/ui/consts/stable-precise-live-drops-in-libcore.stderr
index a3f513541..5f70391ee 100644
--- a/src/test/ui/consts/stable-precise-live-drops-in-libcore.stderr
+++ b/src/test/ui/consts/stable-precise-live-drops-in-libcore.stderr
@@ -1,8 +1,8 @@
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `Either<T, T>` cannot be evaluated at compile-time
--> $DIR/stable-precise-live-drops-in-libcore.rs:13:25
|
LL | pub const fn unwrap(self) -> T {
- | ^^^^ constant functions cannot evaluate destructors
+ | ^^^^ the destructor for this type cannot be evaluated in constant functions
...
LL | }
| - value is dropped here
diff --git a/src/test/ui/consts/trait_specialization.stderr b/src/test/ui/consts/trait_specialization.stderr
index e80821cf4..10bebe8eb 100644
--- a/src/test/ui/consts/trait_specialization.stderr
+++ b/src/test/ui/consts/trait_specialization.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/consts/uninhabited-const-issue-61744.rs b/src/test/ui/consts/uninhabited-const-issue-61744.rs
index 860628c39..a07c39882 100644
--- a/src/test/ui/consts/uninhabited-const-issue-61744.rs
+++ b/src/test/ui/consts/uninhabited-const-issue-61744.rs
@@ -1,8 +1,7 @@
// build-fail
pub const unsafe fn fake_type<T>() -> T {
- hint_unreachable() //~ ERROR any use of this value will cause an error [const_err]
- //~| WARN this was previously accepted by the compiler but is being phased out
+ hint_unreachable() //~ ERROR evaluation of `<i32 as Const>::CONSTANT` failed
}
pub const unsafe fn hint_unreachable() -> ! {
diff --git a/src/test/ui/consts/uninhabited-const-issue-61744.stderr b/src/test/ui/consts/uninhabited-const-issue-61744.stderr
index d31777847..9c7cc8861 100644
--- a/src/test/ui/consts/uninhabited-const-issue-61744.stderr
+++ b/src/test/ui/consts/uninhabited-const-issue-61744.stderr
@@ -1,4 +1,4 @@
-error: any use of this value will cause an error
+error[E0080]: evaluation of `<i32 as Const>::CONSTANT` failed
--> $DIR/uninhabited-const-issue-61744.rs:4:5
|
LL | hint_unreachable()
@@ -6,143 +6,142 @@ LL | hint_unreachable()
| |
| reached the configured maximum number of stack frames
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
| inside `fake_type::<i32>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `<i32 as Const>::CONSTANT` at $DIR/uninhabited-const-issue-61744.rs:13:36
+...
+LL | fake_type()
+ | -----------
+ | |
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
+ | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
...
LL | const CONSTANT: i32 = unsafe { fake_type() };
- | -------------------
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ | ----------- inside `<i32 as Const>::CONSTANT` at $DIR/uninhabited-const-issue-61744.rs:12:36
error[E0080]: erroneous constant used
- --> $DIR/uninhabited-const-issue-61744.rs:19:10
+ --> $DIR/uninhabited-const-issue-61744.rs:18:10
|
LL | dbg!(i32::CONSTANT);
| ^^^^^^^^^^^^^ referenced constant has errors
@@ -150,147 +149,3 @@ LL | dbg!(i32::CONSTANT);
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: any use of this value will cause an error
- --> $DIR/uninhabited-const-issue-61744.rs:4:5
- |
-LL | hint_unreachable()
- | ^^^^^^^^^^^^^^^^^^
- | |
- | reached the configured maximum number of stack frames
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:9:5
- | inside `fake_type::<i32>` at $DIR/uninhabited-const-issue-61744.rs:4:5
- | inside `<i32 as Const>::CONSTANT` at $DIR/uninhabited-const-issue-61744.rs:13:36
-...
-LL | const CONSTANT: i32 = unsafe { fake_type() };
- | -------------------
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/consts/unstable-const-fn-in-libcore.rs b/src/test/ui/consts/unstable-const-fn-in-libcore.rs
index 16b36c8d5..ca4ed8f0b 100644
--- a/src/test/ui/consts/unstable-const-fn-in-libcore.rs
+++ b/src/test/ui/consts/unstable-const-fn-in-libcore.rs
@@ -4,7 +4,7 @@
// gate was not enabled in libcore.
#![stable(feature = "core", since = "1.6.0")]
-#![feature(staged_api)]
+#![feature(staged_api, const_trait_impl)]
enum Opt<T> {
Some(T),
@@ -14,12 +14,12 @@ enum Opt<T> {
impl<T> Opt<T> {
#[rustc_const_unstable(feature = "foo", issue = "none")]
#[stable(feature = "rust1", since = "1.0.0")]
- const fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T {
- //~^ ERROR destructors cannot be evaluated at compile-time
- //~| ERROR destructors cannot be evaluated at compile-time
+ const fn unwrap_or_else<F: ~const FnOnce() -> T>(self, f: F) -> T {
+ //~^ ERROR destructor of
+ //~| ERROR destructor of
match self {
Opt::Some(t) => t,
- Opt::None => f(), //~ ERROR E0015
+ Opt::None => f(),
}
}
}
diff --git a/src/test/ui/consts/unstable-const-fn-in-libcore.stderr b/src/test/ui/consts/unstable-const-fn-in-libcore.stderr
index 180f9f10c..e5b00dd07 100644
--- a/src/test/ui/consts/unstable-const-fn-in-libcore.stderr
+++ b/src/test/ui/consts/unstable-const-fn-in-libcore.stderr
@@ -1,34 +1,21 @@
-error[E0015]: cannot call non-const closure in constant functions
- --> $DIR/unstable-const-fn-in-libcore.rs:22:26
+error[E0493]: destructor of `F` cannot be evaluated at compile-time
+ --> $DIR/unstable-const-fn-in-libcore.rs:17:60
|
-LL | Opt::None => f(),
- | ^^^
- |
- = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
-help: consider further restricting this bound
- |
-LL | const fn unwrap_or_else<F: FnOnce() -> T + ~const std::ops::FnOnce<()>>(self, f: F) -> T {
- | +++++++++++++++++++++++++++++
-
-error[E0493]: destructors cannot be evaluated at compile-time
- --> $DIR/unstable-const-fn-in-libcore.rs:17:53
- |
-LL | const fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T {
- | ^ constant functions cannot evaluate destructors
+LL | const fn unwrap_or_else<F: ~const FnOnce() -> T>(self, f: F) -> T {
+ | ^ the destructor for this type cannot be evaluated in constant functions
...
LL | }
| - value is dropped here
-error[E0493]: destructors cannot be evaluated at compile-time
- --> $DIR/unstable-const-fn-in-libcore.rs:17:47
+error[E0493]: destructor of `Opt<T>` cannot be evaluated at compile-time
+ --> $DIR/unstable-const-fn-in-libcore.rs:17:54
|
-LL | const fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T {
- | ^^^^ constant functions cannot evaluate destructors
+LL | const fn unwrap_or_else<F: ~const FnOnce() -> T>(self, f: F) -> T {
+ | ^^^^ the destructor for this type cannot be evaluated in constant functions
...
LL | }
| - value is dropped here
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
-Some errors have detailed explanations: E0015, E0493.
-For more information about an error, try `rustc --explain E0015`.
+For more information about this error, try `rustc --explain E0493`.
diff --git a/src/test/ui/consts/write_to_static_via_mut_ref.rs b/src/test/ui/consts/write_to_static_via_mut_ref.rs
index 665c305e9..39b830ae4 100644
--- a/src/test/ui/consts/write_to_static_via_mut_ref.rs
+++ b/src/test/ui/consts/write_to_static_via_mut_ref.rs
@@ -1,5 +1,4 @@
#![feature(const_mut_refs)]
-#![allow(const_err)]
static OH_NO: &mut i32 = &mut 42; //~ ERROR mutable references are not allowed
fn main() {
diff --git a/src/test/ui/consts/write_to_static_via_mut_ref.stderr b/src/test/ui/consts/write_to_static_via_mut_ref.stderr
index d19e998d6..f64f0db6b 100644
--- a/src/test/ui/consts/write_to_static_via_mut_ref.stderr
+++ b/src/test/ui/consts/write_to_static_via_mut_ref.stderr
@@ -1,11 +1,11 @@
error[E0764]: mutable references are not allowed in the final value of statics
- --> $DIR/write_to_static_via_mut_ref.rs:4:26
+ --> $DIR/write_to_static_via_mut_ref.rs:3:26
|
LL | static OH_NO: &mut i32 = &mut 42;
| ^^^^^^^
error[E0594]: cannot assign to `*OH_NO`, as `OH_NO` is an immutable static item
- --> $DIR/write_to_static_via_mut_ref.rs:7:5
+ --> $DIR/write_to_static_via_mut_ref.rs:6:5
|
LL | *OH_NO = 43;
| ^^^^^^^^^^^ cannot assign
diff --git a/src/test/ui/deprecation/deprecation-lint.rs b/src/test/ui/deprecation/deprecation-lint.rs
index 65cc4e2ef..0417e952e 100644
--- a/src/test/ui/deprecation/deprecation-lint.rs
+++ b/src/test/ui/deprecation/deprecation-lint.rs
@@ -51,7 +51,7 @@ mod cross_crate {
let _ = nested::DeprecatedTupleStruct (1); //~ ERROR use of deprecated tuple struct `deprecation_lint::nested::DeprecatedTupleStruct`: text
- // At the moment, the lint checker only checks stability in
+ // At the moment, the lint checker only checks stability
// in the arguments of macros.
// Eventually, we will want to lint the contents of the
// macro in the module *defining* it. Also, stability levels
diff --git a/src/test/ui/derive-uninhabited-enum-38885.stderr b/src/test/ui/derive-uninhabited-enum-38885.stderr
index bd36a2568..dcdf8f843 100644
--- a/src/test/ui/derive-uninhabited-enum-38885.stderr
+++ b/src/test/ui/derive-uninhabited-enum-38885.stderr
@@ -7,8 +7,8 @@ LL | Bar(u8),
LL | Void(Void),
| ^^^^
|
- = note: `-W dead-code` implied by `-W unused`
= note: `Foo` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
+ = note: `-W dead-code` implied by `-W unused`
warning: 1 warning emitted
diff --git a/src/test/ui/derives/clone-debug-dead-code-in-the-same-struct.stderr b/src/test/ui/derives/clone-debug-dead-code-in-the-same-struct.stderr
index baf34b46d..512b870fa 100644
--- a/src/test/ui/derives/clone-debug-dead-code-in-the-same-struct.stderr
+++ b/src/test/ui/derives/clone-debug-dead-code-in-the-same-struct.stderr
@@ -13,12 +13,12 @@ LL | field3: (),
LL | field4: (),
| ^^^^^^
|
+ = note: `Whatever` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
note: the lint level is defined here
--> $DIR/clone-debug-dead-code-in-the-same-struct.rs:1:11
|
LL | #![forbid(dead_code)]
| ^^^^^^^^^
- = note: `Whatever` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
error: aborting due to previous error
diff --git a/src/test/ui/derives/deriving-with-repr-packed.stderr b/src/test/ui/derives/deriving-with-repr-packed.stderr
index d3fe550c3..0ad800c39 100644
--- a/src/test/ui/derives/deriving-with-repr-packed.stderr
+++ b/src/test/ui/derives/deriving-with-repr-packed.stderr
@@ -4,13 +4,13 @@ error: `Clone` can't be derived on this `#[repr(packed)]` struct with type or co
LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
| ^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
note: the lint level is defined here
--> $DIR/deriving-with-repr-packed.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters
@@ -52,13 +52,13 @@ error: `Clone` can't be derived on this `#[repr(packed)]` struct with type or co
LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
| ^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
note: the lint level is defined here
--> $DIR/deriving-with-repr-packed.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
Future breakage diagnostic:
@@ -68,13 +68,13 @@ error: `PartialEq` can't be derived on this `#[repr(packed)]` struct with type o
LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
| ^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
note: the lint level is defined here
--> $DIR/deriving-with-repr-packed.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
Future breakage diagnostic:
@@ -84,13 +84,13 @@ error: `Hash` can't be derived on this `#[repr(packed)]` struct that does not de
LL | #[derive(Default, Hash)]
| ^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
note: the lint level is defined here
--> $DIR/deriving-with-repr-packed.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
Future breakage diagnostic:
@@ -100,12 +100,12 @@ error: `Debug` can't be derived on this `#[repr(packed)]` struct that does not d
LL | #[derive(Debug, Default)]
| ^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
note: the lint level is defined here
--> $DIR/deriving-with-repr-packed.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/src/test/ui/deriving/deriving-all-codegen.stdout b/src/test/ui/deriving/deriving-all-codegen.stdout
index 56efc2a59..92fce6888 100644
--- a/src/test/ui/deriving/deriving-all-codegen.stdout
+++ b/src/test/ui/deriving/deriving-all-codegen.stdout
@@ -46,13 +46,15 @@ impl ::core::default::Default for Empty {
impl ::core::hash::Hash for Empty {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {}
}
-impl ::core::marker::StructuralPartialEq for Empty {}
+#[automatically_derived]
+impl ::core::marker::StructuralPartialEq for Empty { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Empty {
#[inline]
fn eq(&self, other: &Empty) -> bool { true }
}
-impl ::core::marker::StructuralEq for Empty {}
+#[automatically_derived]
+impl ::core::marker::StructuralEq for Empty { }
#[automatically_derived]
impl ::core::cmp::Eq for Empty {
#[inline]
@@ -115,7 +117,8 @@ impl ::core::hash::Hash for Point {
::core::hash::Hash::hash(&self.y, state)
}
}
-impl ::core::marker::StructuralPartialEq for Point {}
+#[automatically_derived]
+impl ::core::marker::StructuralPartialEq for Point { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Point {
#[inline]
@@ -123,7 +126,8 @@ impl ::core::cmp::PartialEq for Point {
self.x == other.x && self.y == other.y
}
}
-impl ::core::marker::StructuralEq for Point {}
+#[automatically_derived]
+impl ::core::marker::StructuralEq for Point { }
#[automatically_derived]
impl ::core::cmp::Eq for Point {
#[inline]
@@ -225,7 +229,8 @@ impl ::core::hash::Hash for Big {
::core::hash::Hash::hash(&self.b8, state)
}
}
-impl ::core::marker::StructuralPartialEq for Big {}
+#[automatically_derived]
+impl ::core::marker::StructuralPartialEq for Big { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Big {
#[inline]
@@ -236,7 +241,8 @@ impl ::core::cmp::PartialEq for Big {
self.b8 == other.b8
}
}
-impl ::core::marker::StructuralEq for Big {}
+#[automatically_derived]
+impl ::core::marker::StructuralEq for Big { }
#[automatically_derived]
impl ::core::cmp::Eq for Big {
#[inline]
@@ -345,13 +351,15 @@ impl ::core::hash::Hash for Unsized {
::core::hash::Hash::hash(&self.0, state)
}
}
-impl ::core::marker::StructuralPartialEq for Unsized {}
+#[automatically_derived]
+impl ::core::marker::StructuralPartialEq for Unsized { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Unsized {
#[inline]
fn eq(&self, other: &Unsized) -> bool { self.0 == other.0 }
}
-impl ::core::marker::StructuralEq for Unsized {}
+#[automatically_derived]
+impl ::core::marker::StructuralEq for Unsized { }
#[automatically_derived]
impl ::core::cmp::Eq for Unsized {
#[inline]
@@ -410,13 +418,15 @@ impl ::core::hash::Hash for PackedCopy {
::core::hash::Hash::hash(&{ self.0 }, state)
}
}
-impl ::core::marker::StructuralPartialEq for PackedCopy {}
+#[automatically_derived]
+impl ::core::marker::StructuralPartialEq for PackedCopy { }
#[automatically_derived]
impl ::core::cmp::PartialEq for PackedCopy {
#[inline]
fn eq(&self, other: &PackedCopy) -> bool { { self.0 } == { other.0 } }
}
-impl ::core::marker::StructuralEq for PackedCopy {}
+#[automatically_derived]
+impl ::core::marker::StructuralEq for PackedCopy { }
#[automatically_derived]
impl ::core::cmp::Eq for PackedCopy {
#[inline]
@@ -479,7 +489,8 @@ impl ::core::hash::Hash for PackedNonCopy {
::core::hash::Hash::hash(__self_0_0, state)
}
}
-impl ::core::marker::StructuralPartialEq for PackedNonCopy {}
+#[automatically_derived]
+impl ::core::marker::StructuralPartialEq for PackedNonCopy { }
#[automatically_derived]
impl ::core::cmp::PartialEq for PackedNonCopy {
#[inline]
@@ -489,7 +500,8 @@ impl ::core::cmp::PartialEq for PackedNonCopy {
*__self_0_0 == *__self_1_0
}
}
-impl ::core::marker::StructuralEq for PackedNonCopy {}
+#[automatically_derived]
+impl ::core::marker::StructuralEq for PackedNonCopy { }
#[automatically_derived]
impl ::core::cmp::Eq for PackedNonCopy {
#[inline]
@@ -540,7 +552,8 @@ impl ::core::hash::Hash for Enum0 {
unsafe { ::core::intrinsics::unreachable() }
}
}
-impl ::core::marker::StructuralPartialEq for Enum0 {}
+#[automatically_derived]
+impl ::core::marker::StructuralPartialEq for Enum0 { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Enum0 {
#[inline]
@@ -548,7 +561,8 @@ impl ::core::cmp::PartialEq for Enum0 {
unsafe { ::core::intrinsics::unreachable() }
}
}
-impl ::core::marker::StructuralEq for Enum0 {}
+#[automatically_derived]
+impl ::core::marker::StructuralEq for Enum0 { }
#[automatically_derived]
impl ::core::cmp::Eq for Enum0 {
#[inline]
@@ -607,7 +621,8 @@ impl ::core::hash::Hash for Enum1 {
}
}
}
-impl ::core::marker::StructuralPartialEq for Enum1 {}
+#[automatically_derived]
+impl ::core::marker::StructuralPartialEq for Enum1 { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Enum1 {
#[inline]
@@ -618,7 +633,8 @@ impl ::core::cmp::PartialEq for Enum1 {
}
}
}
-impl ::core::marker::StructuralEq for Enum1 {}
+#[automatically_derived]
+impl ::core::marker::StructuralEq for Enum1 { }
#[automatically_derived]
impl ::core::cmp::Eq for Enum1 {
#[inline]
@@ -676,13 +692,15 @@ impl ::core::default::Default for Fieldless1 {
impl ::core::hash::Hash for Fieldless1 {
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {}
}
-impl ::core::marker::StructuralPartialEq for Fieldless1 {}
+#[automatically_derived]
+impl ::core::marker::StructuralPartialEq for Fieldless1 { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Fieldless1 {
#[inline]
fn eq(&self, other: &Fieldless1) -> bool { true }
}
-impl ::core::marker::StructuralEq for Fieldless1 {}
+#[automatically_derived]
+impl ::core::marker::StructuralEq for Fieldless1 { }
#[automatically_derived]
impl ::core::cmp::Eq for Fieldless1 {
#[inline]
@@ -743,7 +761,8 @@ impl ::core::hash::Hash for Fieldless {
::core::hash::Hash::hash(&__self_tag, state)
}
}
-impl ::core::marker::StructuralPartialEq for Fieldless {}
+#[automatically_derived]
+impl ::core::marker::StructuralPartialEq for Fieldless { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Fieldless {
#[inline]
@@ -753,7 +772,8 @@ impl ::core::cmp::PartialEq for Fieldless {
__self_tag == __arg1_tag
}
}
-impl ::core::marker::StructuralEq for Fieldless {}
+#[automatically_derived]
+impl ::core::marker::StructuralEq for Fieldless { }
#[automatically_derived]
impl ::core::cmp::Eq for Fieldless {
#[inline]
@@ -840,7 +860,8 @@ impl ::core::hash::Hash for Mixed {
}
}
}
-impl ::core::marker::StructuralPartialEq for Mixed {}
+#[automatically_derived]
+impl ::core::marker::StructuralPartialEq for Mixed { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Mixed {
#[inline]
@@ -858,7 +879,8 @@ impl ::core::cmp::PartialEq for Mixed {
}
}
}
-impl ::core::marker::StructuralEq for Mixed {}
+#[automatically_derived]
+impl ::core::marker::StructuralEq for Mixed { }
#[automatically_derived]
impl ::core::cmp::Eq for Mixed {
#[inline]
@@ -967,7 +989,8 @@ impl ::core::hash::Hash for Fielded {
}
}
}
-impl ::core::marker::StructuralPartialEq for Fielded {}
+#[automatically_derived]
+impl ::core::marker::StructuralPartialEq for Fielded { }
#[automatically_derived]
impl ::core::cmp::PartialEq for Fielded {
#[inline]
@@ -986,7 +1009,8 @@ impl ::core::cmp::PartialEq for Fielded {
}
}
}
-impl ::core::marker::StructuralEq for Fielded {}
+#[automatically_derived]
+impl ::core::marker::StructuralEq for Fielded { }
#[automatically_derived]
impl ::core::cmp::Eq for Fielded {
#[inline]
diff --git a/src/test/ui/deriving/deriving-default-enum.rs b/src/test/ui/deriving/deriving-default-enum.rs
index d1a81c72c..1c7a501ed 100644
--- a/src/test/ui/deriving/deriving-default-enum.rs
+++ b/src/test/ui/deriving/deriving-default-enum.rs
@@ -12,6 +12,16 @@ enum Foo {
Beta(NotDefault),
}
+// #[default] on a generic enum does not add `Default` bounds to the type params.
+#[derive(Default)]
+enum MyOption<T> {
+ #[default]
+ None,
+ #[allow(dead_code)]
+ Some(T),
+}
+
fn main() {
assert_eq!(Foo::default(), Foo::Alpha);
+ assert!(matches!(MyOption::<NotDefault>::default(), MyOption::None));
}
diff --git a/src/test/ui/deriving/deriving-hash.rs b/src/test/ui/deriving/deriving-hash.rs
index 8b51370bc..16738ec4a 100644
--- a/src/test/ui/deriving/deriving-hash.rs
+++ b/src/test/ui/deriving/deriving-hash.rs
@@ -44,6 +44,17 @@ fn fake_hash<A: Hash>(v: &mut Vec<u8>, a: A) {
a.hash(&mut FakeHasher(v));
}
+struct OnlyOneByteHasher;
+impl Hasher for OnlyOneByteHasher {
+ fn finish(&self) -> u64 {
+ unreachable!()
+ }
+
+ fn write(&mut self, bytes: &[u8]) {
+ assert_eq!(bytes.len(), 1);
+ }
+}
+
fn main() {
let person1 = Person {
id: 5,
@@ -73,4 +84,13 @@ fn main() {
let mut v = vec![];
fake_hash(&mut v, SingleVariantEnum::A(17));
assert_eq!(vec![17], v);
+
+ // issue #39137
+ #[repr(u8)]
+ #[derive(Hash)]
+ enum E {
+ A,
+ B,
+ }
+ E::A.hash(&mut OnlyOneByteHasher);
}
diff --git a/src/test/ui/destructuring-assignment/warn-unused-duplication.stderr b/src/test/ui/destructuring-assignment/warn-unused-duplication.stderr
index 1df7a5f22..e16625136 100644
--- a/src/test/ui/destructuring-assignment/warn-unused-duplication.stderr
+++ b/src/test/ui/destructuring-assignment/warn-unused-duplication.stderr
@@ -4,12 +4,12 @@ warning: value assigned to `a` is never read
LL | (a, a) = (0, 1);
| ^
|
+ = help: maybe it is overwritten before being read?
note: the lint level is defined here
--> $DIR/warn-unused-duplication.rs:3:9
|
LL | #![warn(unused_assignments)]
| ^^^^^^^^^^^^^^^^^^
- = help: maybe it is overwritten before being read?
warning: 1 warning emitted
diff --git a/src/test/ui/did_you_mean/bad-assoc-ty.stderr b/src/test/ui/did_you_mean/bad-assoc-ty.stderr
index 2326af934..21f957ab5 100644
--- a/src/test/ui/did_you_mean/bad-assoc-ty.stderr
+++ b/src/test/ui/did_you_mean/bad-assoc-ty.stderr
@@ -105,9 +105,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | type H = Fn(u8) -> (u8)::Output;
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(bare_trait_objects)]` on by default
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
|
LL | type H = <dyn Fn(u8) -> (u8)>::Output;
diff --git a/src/test/ui/did_you_mean/issue-31424.stderr b/src/test/ui/did_you_mean/issue-31424.stderr
index 886173812..8fe38bf69 100644
--- a/src/test/ui/did_you_mean/issue-31424.stderr
+++ b/src/test/ui/did_you_mean/issue-31424.stderr
@@ -24,8 +24,8 @@ LL | fn bar(self: &mut Self) {
LL | (&mut self).bar();
| ----------------- recursive call site
|
- = note: `#[warn(unconditional_recursion)]` on by default
= help: a `loop` may express intention better if this is on purpose
+ = note: `#[warn(unconditional_recursion)]` on by default
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
--> $DIR/issue-31424.rs:16:9
diff --git a/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.fixed b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.fixed
index 87debfece..e566ed488 100644
--- a/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.fixed
+++ b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.fixed
@@ -2,4 +2,9 @@
fn main() {
let _x = !1; //~ ERROR cannot be used as a unary operator
+ let _y = !1; //~ ERROR unexpected `1` after identifier
+ let _z = !false; //~ ERROR unexpected keyword `false` after identifier
+ let _a = !true; //~ ERROR unexpected keyword `true` after identifier
+ let v = 1 + 2;
+ let _v = !v; //~ ERROR unexpected `v` after identifier
}
diff --git a/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs
index 015a8edce..1708a8050 100644
--- a/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs
+++ b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs
@@ -2,4 +2,9 @@
fn main() {
let _x = ~1; //~ ERROR cannot be used as a unary operator
+ let _y = not 1; //~ ERROR unexpected `1` after identifier
+ let _z = not false; //~ ERROR unexpected keyword `false` after identifier
+ let _a = not true; //~ ERROR unexpected keyword `true` after identifier
+ let v = 1 + 2;
+ let _v = not v; //~ ERROR unexpected `v` after identifier
}
diff --git a/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr
index 84b81d561..2a3242abe 100644
--- a/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr
+++ b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr
@@ -4,5 +4,37 @@ error: `~` cannot be used as a unary operator
LL | let _x = ~1;
| ^ help: use `!` to perform bitwise not
-error: aborting due to previous error
+error: unexpected `1` after identifier
+ --> $DIR/issue-41679-tilde-bitwise-negation-attempt.rs:5:18
+ |
+LL | let _y = not 1;
+ | ----^
+ | |
+ | help: use `!` to perform bitwise not
+
+error: unexpected keyword `false` after identifier
+ --> $DIR/issue-41679-tilde-bitwise-negation-attempt.rs:6:18
+ |
+LL | let _z = not false;
+ | ----^^^^^
+ | |
+ | help: use `!` to perform logical negation
+
+error: unexpected keyword `true` after identifier
+ --> $DIR/issue-41679-tilde-bitwise-negation-attempt.rs:7:18
+ |
+LL | let _a = not true;
+ | ----^^^^
+ | |
+ | help: use `!` to perform logical negation
+
+error: unexpected `v` after identifier
+ --> $DIR/issue-41679-tilde-bitwise-negation-attempt.rs:9:18
+ |
+LL | let _v = not v;
+ | ----^
+ | |
+ | help: use `!` to perform logical negation or bitwise not
+
+error: aborting due to 5 previous errors
diff --git a/src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.stderr b/src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.stderr
index bca493e67..9dde5b3eb 100644
--- a/src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.stderr
+++ b/src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.stderr
@@ -1,11 +1,3 @@
-error[E0423]: expected function, tuple struct or tuple variant, found enum `Option`
- --> $DIR/issue-43871-enum-instead-of-variant.rs:19:13
- |
-LL | let x = Option(1);
- | ^^^^^^ help: try to construct one of the enum's variants: `std::option::Option::Some`
- |
- = help: you might have meant to construct the enum's non-tuple variant
-
error[E0532]: expected tuple struct or tuple variant, found enum `Option`
--> $DIR/issue-43871-enum-instead-of-variant.rs:21:12
|
@@ -27,6 +19,14 @@ note: the enum is defined here
LL | enum Example { Ex(String), NotEx }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+error[E0423]: expected function, tuple struct or tuple variant, found enum `Option`
+ --> $DIR/issue-43871-enum-instead-of-variant.rs:19:13
+ |
+LL | let x = Option(1);
+ | ^^^^^^ help: try to construct one of the enum's variants: `std::option::Option::Some`
+ |
+ = help: you might have meant to construct the enum's non-tuple variant
+
error[E0423]: expected function, tuple struct or tuple variant, found enum `Void`
--> $DIR/issue-43871-enum-instead-of-variant.rs:31:13
|
diff --git a/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.stderr b/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.stderr
index 3ccc14bba..14918ba89 100644
--- a/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.stderr
+++ b/src/test/ui/did_you_mean/issue-46836-identifier-not-instead-of-negation.stderr
@@ -4,7 +4,7 @@ error: unexpected `for_you` after identifier
LL | if not for_you {
| ----^^^^^^^
| |
- | help: use `!` to perform logical negation
+ | help: use `!` to perform logical negation or bitwise not
error: unexpected `the_worst` after identifier
--> $DIR/issue-46836-identifier-not-instead-of-negation.rs:11:15
@@ -12,13 +12,13 @@ error: unexpected `the_worst` after identifier
LL | while not the_worst {
| ----^^^^^^^^^
| |
- | help: use `!` to perform logical negation
+ | help: use `!` to perform logical negation or bitwise not
error: unexpected `println` after identifier
--> $DIR/issue-46836-identifier-not-instead-of-negation.rs:20:9
|
LL | if not // lack of braces is [sic]
- | ----- help: use `!` to perform logical negation
+ | ----- help: use `!` to perform logical negation or bitwise not
LL | println!("Then when?");
| ^^^^^^^
@@ -42,7 +42,7 @@ error: unexpected `2` after identifier
LL | let resource = not 2;
| ----^
| |
- | help: use `!` to perform logical negation
+ | help: use `!` to perform bitwise not
error: unexpected `be_smothered_out_before` after identifier
--> $DIR/issue-46836-identifier-not-instead-of-negation.rs:32:27
@@ -50,7 +50,7 @@ error: unexpected `be_smothered_out_before` after identifier
LL | let young_souls = not be_smothered_out_before;
| ----^^^^^^^^^^^^^^^^^^^^^^^
| |
- | help: use `!` to perform logical negation
+ | help: use `!` to perform logical negation or bitwise not
error: aborting due to 6 previous errors
diff --git a/src/test/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.stderr b/src/test/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.stderr
index 26986684f..81f3f2694 100644
--- a/src/test/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.stderr
+++ b/src/test/ui/did_you_mean/issue-49746-unicode-confusable-in-float-literal-expt.stderr
@@ -15,13 +15,13 @@ help: Unicode character '−' (Minus Sign) looks like '-' (Minus/Hyphen), but it
LL | const UNIVERSAL_GRAVITATIONAL_CONSTANT: f64 = 6.674e-11; // m³⋅kgâ»Â¹â‹…sâ»Â²
| ~
-error[E0277]: cannot subtract `{integer}` from `{float}`
+error[E0277]: cannot subtract `{integer}` from `{float}` in const contexts
--> $DIR/issue-49746-unicode-confusable-in-float-literal-expt.rs:1:53
|
LL | const UNIVERSAL_GRAVITATIONAL_CONSTANT: f64 = 6.674e−11; // m³⋅kgâ»Â¹â‹…sâ»Â²
| ^ no implementation for `{float} - {integer}`
|
- = help: the trait `Sub<{integer}>` is not implemented for `{float}`
+ = help: the trait `~const Sub<{integer}>` is not implemented for `{float}`
= help: the following other types implement trait `Sub<Rhs>`:
<&'a f32 as Sub<f32>>
<&'a f64 as Sub<f64>>
diff --git a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr
index 528c62f50..cbe59e8e0 100644
--- a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr
+++ b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr
@@ -4,7 +4,7 @@ error: `and` is not a logical operator
LL | let _ = a and b;
| ^^^ help: use `&&` to perform logical conjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `and` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:9:10
@@ -12,7 +12,7 @@ error: `and` is not a logical operator
LL | if a and b {
| ^^^ help: use `&&` to perform logical conjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `or` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:20:15
@@ -20,7 +20,7 @@ error: `or` is not a logical operator
LL | let _ = a or b;
| ^^ help: use `||` to perform logical disjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `or` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:22:10
@@ -28,7 +28,7 @@ error: `or` is not a logical operator
LL | if a or b {
| ^^ help: use `||` to perform logical disjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `and` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:30:11
@@ -36,7 +36,7 @@ error: `and` is not a logical operator
LL | if (a and b) {
| ^^^ help: use `&&` to perform logical conjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `or` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:38:11
@@ -44,7 +44,7 @@ error: `or` is not a logical operator
LL | if (a or b) {
| ^^ help: use `||` to perform logical disjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `and` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:46:13
@@ -52,7 +52,7 @@ error: `and` is not a logical operator
LL | while a and b {
| ^^^ help: use `&&` to perform logical conjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `or` is not a logical operator
--> $DIR/issue-54109-and_instead_of_ampersands.rs:54:13
@@ -60,7 +60,7 @@ error: `or` is not a logical operator
LL | while a or b {
| ^^ help: use `||` to perform logical disjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error[E0308]: mismatched types
--> $DIR/issue-54109-and_instead_of_ampersands.rs:13:33
diff --git a/src/test/ui/did_you_mean/issue-54109-without-witness.stderr b/src/test/ui/did_you_mean/issue-54109-without-witness.stderr
index 0350890c1..6455b0863 100644
--- a/src/test/ui/did_you_mean/issue-54109-without-witness.stderr
+++ b/src/test/ui/did_you_mean/issue-54109-without-witness.stderr
@@ -4,7 +4,7 @@ error: `and` is not a logical operator
LL | let _ = a and b;
| ^^^ help: use `&&` to perform logical conjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `and` is not a logical operator
--> $DIR/issue-54109-without-witness.rs:15:10
@@ -12,7 +12,7 @@ error: `and` is not a logical operator
LL | if a and b {
| ^^^ help: use `&&` to perform logical conjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `or` is not a logical operator
--> $DIR/issue-54109-without-witness.rs:24:15
@@ -20,7 +20,7 @@ error: `or` is not a logical operator
LL | let _ = a or b;
| ^^ help: use `||` to perform logical disjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `or` is not a logical operator
--> $DIR/issue-54109-without-witness.rs:26:10
@@ -28,7 +28,7 @@ error: `or` is not a logical operator
LL | if a or b {
| ^^ help: use `||` to perform logical disjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `and` is not a logical operator
--> $DIR/issue-54109-without-witness.rs:34:11
@@ -36,7 +36,7 @@ error: `and` is not a logical operator
LL | if (a and b) {
| ^^^ help: use `&&` to perform logical conjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `or` is not a logical operator
--> $DIR/issue-54109-without-witness.rs:42:11
@@ -44,7 +44,7 @@ error: `or` is not a logical operator
LL | if (a or b) {
| ^^ help: use `||` to perform logical disjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `and` is not a logical operator
--> $DIR/issue-54109-without-witness.rs:50:13
@@ -52,7 +52,7 @@ error: `and` is not a logical operator
LL | while a and b {
| ^^^ help: use `&&` to perform logical conjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: `or` is not a logical operator
--> $DIR/issue-54109-without-witness.rs:58:13
@@ -60,7 +60,7 @@ error: `or` is not a logical operator
LL | while a or b {
| ^^ help: use `||` to perform logical disjunction
|
- = note: unlike in e.g., python and PHP, `&&` and `||` are used for logical operators
+ = note: unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators
error: aborting due to 8 previous errors
diff --git a/src/test/ui/drop/drop_order.rs b/src/test/ui/drop/drop_order.rs
index e42150dcc..42385216a 100644
--- a/src/test/ui/drop/drop_order.rs
+++ b/src/test/ui/drop/drop_order.rs
@@ -1,4 +1,6 @@
// run-pass
+// compile-flags: -Z validate-mir
+#![feature(let_chains)]
use std::cell::RefCell;
use std::convert::TryInto;
@@ -116,6 +118,58 @@ impl DropOrderCollector {
}
}
+ fn let_chain(&self) {
+ // take the "then" branch
+ if self.option_loud_drop(2).is_some() // 2
+ && self.option_loud_drop(1).is_some() // 1
+ && let Some(_d) = self.option_loud_drop(4) { // 4
+ self.print(3); // 3
+ }
+
+ // take the "else" branch
+ if self.option_loud_drop(6).is_some() // 2
+ && self.option_loud_drop(5).is_some() // 1
+ && let None = self.option_loud_drop(8) { // 4
+ unreachable!();
+ } else {
+ self.print(7); // 3
+ }
+
+ // let exprs interspersed
+ if self.option_loud_drop(9).is_some() // 1
+ && let Some(_d) = self.option_loud_drop(13) // 5
+ && self.option_loud_drop(10).is_some() // 2
+ && let Some(_e) = self.option_loud_drop(12) { // 4
+ self.print(11); // 3
+ }
+
+ // let exprs first
+ if let Some(_d) = self.option_loud_drop(18) // 5
+ && let Some(_e) = self.option_loud_drop(17) // 4
+ && self.option_loud_drop(14).is_some() // 1
+ && self.option_loud_drop(15).is_some() { // 2
+ self.print(16); // 3
+ }
+
+ // let exprs last
+ if self.option_loud_drop(20).is_some() // 2
+ && self.option_loud_drop(19).is_some() // 1
+ && let Some(_d) = self.option_loud_drop(23) // 5
+ && let Some(_e) = self.option_loud_drop(22) { // 4
+ self.print(21); // 3
+ }
+ }
+
+ fn while_(&self) {
+ let mut v = self.option_loud_drop(4);
+ while let Some(_d) = v
+ && self.option_loud_drop(1).is_some()
+ && self.option_loud_drop(2).is_some() {
+ self.print(3);
+ v = None;
+ }
+ }
+
fn assert_sorted(self) {
assert!(
self.0
@@ -142,4 +196,14 @@ fn main() {
let collector = DropOrderCollector::default();
collector.match_();
collector.assert_sorted();
+
+ println!("-- let chain --");
+ let collector = DropOrderCollector::default();
+ collector.let_chain();
+ collector.assert_sorted();
+
+ println!("-- while --");
+ let collector = DropOrderCollector::default();
+ collector.while_();
+ collector.assert_sorted();
}
diff --git a/src/test/ui/drop/dropck_legal_cycles.rs b/src/test/ui/drop/dropck_legal_cycles.rs
index 27a599315..6a0fe7784 100644
--- a/src/test/ui/drop/dropck_legal_cycles.rs
+++ b/src/test/ui/drop/dropck_legal_cycles.rs
@@ -1017,7 +1017,7 @@ impl<'a> Children<'a> for HM<'a> {
where C: Context + PrePost<Self>, Self: Sized
{
if let Some(ref hm) = self.contents.get() {
- for (k, v) in hm.iter().nth(index / 2) {
+ if let Some((k, v)) = hm.iter().nth(index / 2) {
[k, v][index % 2].descend_into_self(context);
}
}
@@ -1032,7 +1032,7 @@ impl<'a> Children<'a> for VD<'a> {
where C: Context + PrePost<Self>, Self: Sized
{
if let Some(ref vd) = self.contents.get() {
- for r in vd.iter().nth(index) {
+ if let Some(r) = vd.iter().nth(index) {
r.descend_into_self(context);
}
}
@@ -1047,7 +1047,7 @@ impl<'a> Children<'a> for VM<'a> {
where C: Context + PrePost<VM<'a>>
{
if let Some(ref vd) = self.contents.get() {
- for (_idx, r) in vd.iter().nth(index) {
+ if let Some((_idx, r)) = vd.iter().nth(index) {
r.descend_into_self(context);
}
}
@@ -1062,7 +1062,7 @@ impl<'a> Children<'a> for LL<'a> {
where C: Context + PrePost<LL<'a>>
{
if let Some(ref ll) = self.contents.get() {
- for r in ll.iter().nth(index) {
+ if let Some(r) = ll.iter().nth(index) {
r.descend_into_self(context);
}
}
@@ -1077,7 +1077,7 @@ impl<'a> Children<'a> for BH<'a> {
where C: Context + PrePost<BH<'a>>
{
if let Some(ref bh) = self.contents.get() {
- for r in bh.iter().nth(index) {
+ if let Some(r) = bh.iter().nth(index) {
r.descend_into_self(context);
}
}
@@ -1092,7 +1092,7 @@ impl<'a> Children<'a> for BTM<'a> {
where C: Context + PrePost<BTM<'a>>
{
if let Some(ref bh) = self.contents.get() {
- for (k, v) in bh.iter().nth(index / 2) {
+ if let Some((k, v)) = bh.iter().nth(index / 2) {
[k, v][index % 2].descend_into_self(context);
}
}
@@ -1107,7 +1107,7 @@ impl<'a> Children<'a> for BTS<'a> {
where C: Context + PrePost<BTS<'a>>
{
if let Some(ref bh) = self.contents.get() {
- for r in bh.iter().nth(index) {
+ if let Some(r) = bh.iter().nth(index) {
r.descend_into_self(context);
}
}
diff --git a/src/test/ui/drop/dynamic-drop-async.rs b/src/test/ui/drop/dynamic-drop-async.rs
index 13bd71ecb..8f1cc6691 100644
--- a/src/test/ui/drop/dynamic-drop-async.rs
+++ b/src/test/ui/drop/dynamic-drop-async.rs
@@ -6,7 +6,6 @@
// run-pass
// needs-unwind
// edition:2018
-// ignore-wasm32-bare compiled with panic=abort by default
#![allow(unused)]
diff --git a/src/test/ui/drop/dynamic-drop.rs b/src/test/ui/drop/dynamic-drop.rs
index e70686774..9e51d3ada 100644
--- a/src/test/ui/drop/dynamic-drop.rs
+++ b/src/test/ui/drop/dynamic-drop.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
#![feature(generators, generator_trait)]
diff --git a/src/test/ui/drop/issue-100276.rs b/src/test/ui/drop/issue-100276.rs
new file mode 100644
index 000000000..6401a8d14
--- /dev/null
+++ b/src/test/ui/drop/issue-100276.rs
@@ -0,0 +1,12 @@
+// check-pass
+// compile-flags: -Z validate-mir
+#![feature(let_chains)]
+
+fn let_chains(entry: std::io::Result<std::fs::DirEntry>) {
+ if let Ok(entry) = entry
+ && let Some(s) = entry.file_name().to_str()
+ && s.contains("")
+ {}
+}
+
+fn main() {}
diff --git a/src/test/ui/issues/issue-17718-const-destructors.rs b/src/test/ui/drop/issue-17718-const-destructors.rs
index c9a729c7b..c9a729c7b 100644
--- a/src/test/ui/issues/issue-17718-const-destructors.rs
+++ b/src/test/ui/drop/issue-17718-const-destructors.rs
diff --git a/src/test/ui/issues/issue-23338-ensure-param-drop-order.rs b/src/test/ui/drop/issue-23338-ensure-param-drop-order.rs
index a99f260dd..a99f260dd 100644
--- a/src/test/ui/issues/issue-23338-ensure-param-drop-order.rs
+++ b/src/test/ui/drop/issue-23338-ensure-param-drop-order.rs
diff --git a/src/test/ui/issues/issue-48962.rs b/src/test/ui/drop/issue-48962.rs
index 80d815379..80d815379 100644
--- a/src/test/ui/issues/issue-48962.rs
+++ b/src/test/ui/drop/issue-48962.rs
diff --git a/src/test/ui/drop/repeat-drop-2.rs b/src/test/ui/drop/repeat-drop-2.rs
index 59d5ef202..3cfacea5e 100644
--- a/src/test/ui/drop/repeat-drop-2.rs
+++ b/src/test/ui/drop/repeat-drop-2.rs
@@ -5,7 +5,7 @@ fn borrowck_catch() {
}
const _: [String; 0] = [String::new(); 0];
-//~^ ERROR destructors cannot be evaluated at compile-time [E0493]
+//~^ ERROR destructor of `String` cannot be evaluated at compile-time [E0493]
fn must_be_init() {
let x: u8;
diff --git a/src/test/ui/drop/repeat-drop-2.stderr b/src/test/ui/drop/repeat-drop-2.stderr
index 48fa2bfa9..7357551c4 100644
--- a/src/test/ui/drop/repeat-drop-2.stderr
+++ b/src/test/ui/drop/repeat-drop-2.stderr
@@ -8,13 +8,13 @@ LL | let _bar = foo;
LL | let _baz = [foo; 0];
| ^^^ value used here after move
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `String` cannot be evaluated at compile-time
--> $DIR/repeat-drop-2.rs:7:25
|
LL | const _: [String; 0] = [String::new(); 0];
| -^^^^^^^^^^^^^----
| ||
- | |constants cannot evaluate destructors
+ | |the destructor for this type cannot be evaluated in constants
| value is dropped here
error[E0381]: used binding `x` isn't initialized
@@ -24,6 +24,11 @@ LL | let x: u8;
| - binding declared here but left uninitialized
LL | let _ = [x; 0];
| ^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x: u8 = 0;
+ | +++
error: aborting due to 3 previous errors
diff --git a/src/test/ui/drop/repeat-drop.rs b/src/test/ui/drop/repeat-drop.rs
index a43612e5d..8fd46ecaf 100644
--- a/src/test/ui/drop/repeat-drop.rs
+++ b/src/test/ui/drop/repeat-drop.rs
@@ -1,8 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare no unwinding panic
-// ignore-avr no unwinding panic
-// ignore-nvptx64 no unwinding panic
static mut CHECK: usize = 0;
diff --git a/src/test/ui/dropck/dropck-eyepatch-implies-unsafe-impl.stderr b/src/test/ui/dropck/dropck-eyepatch-implies-unsafe-impl.stderr
index 49e55be1b..82169ee01 100644
--- a/src/test/ui/dropck/dropck-eyepatch-implies-unsafe-impl.stderr
+++ b/src/test/ui/dropck/dropck-eyepatch-implies-unsafe-impl.stderr
@@ -8,6 +8,12 @@ LL | | // (unsafe to access self.1 due to #[may_dangle] on A)
LL | | fn drop(&mut self) { println!("drop {} {:?}", self.0, self.2); }
LL | | }
| |_^
+ |
+ = note: the trait `Drop` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
+help: add `unsafe` to this trait implementation
+ |
+LL | unsafe impl<#[may_dangle] A, B: fmt::Debug> Drop for Pt<A, B> {
+ | ++++++
error[E0569]: requires an `unsafe impl` declaration due to `#[may_dangle]` attribute
--> $DIR/dropck-eyepatch-implies-unsafe-impl.rs:27:1
@@ -19,6 +25,12 @@ LL | | // (unsafe to access self.1 due to #[may_dangle] on 'a)
LL | | fn drop(&mut self) { println!("drop {} {:?}", self.0, self.2); }
LL | | }
| |_^
+ |
+ = note: the trait `Drop` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
+help: add `unsafe` to this trait implementation
+ |
+LL | unsafe impl<#[may_dangle] 'a, 'b, B: fmt::Debug> Drop for Pr<'a, 'b, B> {
+ | ++++++
error: aborting due to 2 previous errors
diff --git a/src/test/ui/issues/issue-24805-dropck-itemless.rs b/src/test/ui/dropck/issue-24805-dropck-itemless.rs
index 45761b61c..45761b61c 100644
--- a/src/test/ui/issues/issue-24805-dropck-itemless.rs
+++ b/src/test/ui/dropck/issue-24805-dropck-itemless.rs
diff --git a/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.stderr b/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.stderr
index 3eb5bb7b2..89aded913 100644
--- a/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.stderr
+++ b/src/test/ui/dyn-keyword/dyn-2015-edition-keyword-ident-lint.stderr
@@ -4,13 +4,13 @@ error: `dyn` is a keyword in the 2018 edition
LL | pub mod dyn {
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
note: the lint level is defined here
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:11:9
|
LL | #![deny(keyword_idents)]
| ^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `dyn` is a keyword in the 2018 edition
--> $DIR/dyn-2015-edition-keyword-ident-lint.rs:17:20
diff --git a/src/test/ui/dyn-keyword/dyn-2018-edition-lint.stderr b/src/test/ui/dyn-keyword/dyn-2018-edition-lint.stderr
index e7db68693..6bafff919 100644
--- a/src/test/ui/dyn-keyword/dyn-2018-edition-lint.stderr
+++ b/src/test/ui/dyn-keyword/dyn-2018-edition-lint.stderr
@@ -4,13 +4,13 @@ error: trait objects without an explicit `dyn` are deprecated
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
| ^^^^^^^^^
|
+ = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
note: the lint level is defined here
--> $DIR/dyn-2018-edition-lint.rs:2:8
|
LL | #[deny(bare_trait_objects)]
| ^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) {
diff --git a/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr b/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr
index 261c2d574..0bb764d71 100644
--- a/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr
+++ b/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr
@@ -4,13 +4,13 @@ error: trait objects without an explicit `dyn` are deprecated
LL | <fmt::Debug>::fmt(self, f)
| ^^^^^^^^^^
|
+ = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
note: the lint level is defined here
--> $DIR/dyn-angle-brackets.rs:4:9
|
LL | #![deny(bare_trait_objects)]
| ^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | <dyn fmt::Debug>::fmt(self, f)
diff --git a/src/test/ui/dyn-star/auxiliary/dyn-star-foreign.rs b/src/test/ui/dyn-star/auxiliary/dyn-star-foreign.rs
new file mode 100644
index 000000000..7673c7936
--- /dev/null
+++ b/src/test/ui/dyn-star/auxiliary/dyn-star-foreign.rs
@@ -0,0 +1,10 @@
+#![feature(dyn_star)]
+#![allow(incomplete_features)]
+
+use std::fmt::Display;
+
+pub fn require_dyn_star_display(_: dyn* Display) {}
+
+fn works_locally() {
+ require_dyn_star_display(1usize);
+}
diff --git a/src/test/ui/dyn-star/box.rs b/src/test/ui/dyn-star/box.rs
new file mode 100644
index 000000000..d1f1819d9
--- /dev/null
+++ b/src/test/ui/dyn-star/box.rs
@@ -0,0 +1,17 @@
+// run-pass
+// compile-flags: -C opt-level=0
+
+#![feature(dyn_star)]
+#![allow(incomplete_features)]
+
+use std::fmt::Display;
+
+fn make_dyn_star() -> dyn* Display {
+ Box::new(42) as dyn* Display
+}
+
+fn main() {
+ let x = make_dyn_star();
+
+ println!("{x}");
+}
diff --git a/src/test/ui/dyn-star/const.rs b/src/test/ui/dyn-star/const.rs
index e49caf649..67e3ab7ab 100644
--- a/src/test/ui/dyn-star/const.rs
+++ b/src/test/ui/dyn-star/const.rs
@@ -6,7 +6,7 @@ use std::fmt::Debug;
fn make_dyn_star() {
let i = 42usize;
- let dyn_i: dyn* Debug = i as dyn* Debug;
+ let dyn_i: dyn* Debug = i;
}
fn main() {
diff --git a/src/test/ui/dyn-star/drop.rs b/src/test/ui/dyn-star/drop.rs
index 46b232f3d..1478498c0 100644
--- a/src/test/ui/dyn-star/drop.rs
+++ b/src/test/ui/dyn-star/drop.rs
@@ -15,7 +15,7 @@ impl Drop for Foo {
}
fn make_dyn_star(i: Foo) {
- let _dyn_i: dyn* Debug = i as dyn* Debug;
+ let _dyn_i: dyn* Debug = i;
}
fn main() {
diff --git a/src/test/ui/dyn-star/error.rs b/src/test/ui/dyn-star/error.rs
index 33eff80a5..d8261387e 100644
--- a/src/test/ui/dyn-star/error.rs
+++ b/src/test/ui/dyn-star/error.rs
@@ -7,7 +7,7 @@ trait Foo {}
fn make_dyn_star() {
let i = 42;
- let dyn_i: dyn* Foo = i as dyn* Foo; //~ ERROR trait bound `{integer}: Foo` is not satisfied
+ let dyn_i: dyn* Foo = i; //~ ERROR trait bound `{integer}: Foo` is not satisfied
}
fn main() {}
diff --git a/src/test/ui/dyn-star/error.stderr b/src/test/ui/dyn-star/error.stderr
index d612ccc63..ae54b9ca7 100644
--- a/src/test/ui/dyn-star/error.stderr
+++ b/src/test/ui/dyn-star/error.stderr
@@ -1,7 +1,7 @@
error[E0277]: the trait bound `{integer}: Foo` is not satisfied
--> $DIR/error.rs:10:27
|
-LL | let dyn_i: dyn* Foo = i as dyn* Foo;
+LL | let dyn_i: dyn* Foo = i;
| ^ the trait `Foo` is not implemented for `{integer}`
error: aborting due to previous error
diff --git a/src/test/ui/dyn-star/make-dyn-star.rs b/src/test/ui/dyn-star/make-dyn-star.rs
index 708ffa25d..e5255a64b 100644
--- a/src/test/ui/dyn-star/make-dyn-star.rs
+++ b/src/test/ui/dyn-star/make-dyn-star.rs
@@ -5,9 +5,14 @@
use std::fmt::Debug;
fn make_dyn_star(i: usize) {
+ let _dyn_i: dyn* Debug = i;
+}
+
+fn make_dyn_star_explicit(i: usize) {
let _dyn_i: dyn* Debug = i as dyn* Debug;
}
fn main() {
make_dyn_star(42);
+ make_dyn_star_explicit(42);
}
diff --git a/src/test/ui/dyn-star/method.rs b/src/test/ui/dyn-star/method.rs
index d04958ca2..5a77640f0 100644
--- a/src/test/ui/dyn-star/method.rs
+++ b/src/test/ui/dyn-star/method.rs
@@ -1,4 +1,5 @@
// run-pass
+
#![feature(dyn_star)]
#![allow(incomplete_features)]
@@ -17,7 +18,7 @@ fn invoke_dyn_star(i: dyn* Foo) -> usize {
}
fn make_and_invoke_dyn_star(i: usize) -> usize {
- let dyn_i: dyn* Foo = i as dyn* Foo;
+ let dyn_i: dyn* Foo = i;
invoke_dyn_star(dyn_i)
}
diff --git a/src/test/ui/dyn-star/no-explicit-dyn-star-cast.rs b/src/test/ui/dyn-star/no-explicit-dyn-star-cast.rs
new file mode 100644
index 000000000..67240c8e8
--- /dev/null
+++ b/src/test/ui/dyn-star/no-explicit-dyn-star-cast.rs
@@ -0,0 +1,13 @@
+use std::fmt::Debug;
+
+fn make_dyn_star() {
+ let i = 42usize;
+ let dyn_i: dyn* Debug = i as dyn* Debug;
+ //~^ ERROR casting `usize` as `dyn* Debug` is invalid
+ //~| ERROR dyn* trait objects are unstable
+ //~| ERROR dyn* trait objects are unstable
+}
+
+fn main() {
+ make_dyn_star();
+}
diff --git a/src/test/ui/dyn-star/no-explicit-dyn-star-cast.stderr b/src/test/ui/dyn-star/no-explicit-dyn-star-cast.stderr
new file mode 100644
index 000000000..687d7db04
--- /dev/null
+++ b/src/test/ui/dyn-star/no-explicit-dyn-star-cast.stderr
@@ -0,0 +1,28 @@
+error[E0658]: dyn* trait objects are unstable
+ --> $DIR/no-explicit-dyn-star-cast.rs:5:16
+ |
+LL | let dyn_i: dyn* Debug = i as dyn* Debug;
+ | ^^^^^^^^^^
+ |
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = help: add `#![feature(dyn_star)]` to the crate attributes to enable
+
+error[E0658]: dyn* trait objects are unstable
+ --> $DIR/no-explicit-dyn-star-cast.rs:5:34
+ |
+LL | let dyn_i: dyn* Debug = i as dyn* Debug;
+ | ^^^^^^^^^^
+ |
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = help: add `#![feature(dyn_star)]` to the crate attributes to enable
+
+error[E0606]: casting `usize` as `dyn* Debug` is invalid
+ --> $DIR/no-explicit-dyn-star-cast.rs:5:29
+ |
+LL | let dyn_i: dyn* Debug = i as dyn* Debug;
+ | ^^^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0606, E0658.
+For more information about an error, try `rustc --explain E0606`.
diff --git a/src/test/ui/dyn-star/no-explicit-dyn-star.rs b/src/test/ui/dyn-star/no-explicit-dyn-star.rs
new file mode 100644
index 000000000..4f726b7c6
--- /dev/null
+++ b/src/test/ui/dyn-star/no-explicit-dyn-star.rs
@@ -0,0 +1,8 @@
+// aux-build:dyn-star-foreign.rs
+
+extern crate dyn_star_foreign;
+
+fn main() {
+ dyn_star_foreign::require_dyn_star_display(1usize as _);
+ //~^ ERROR casting `usize` as `dyn* std::fmt::Display` is invalid
+}
diff --git a/src/test/ui/dyn-star/no-explicit-dyn-star.stderr b/src/test/ui/dyn-star/no-explicit-dyn-star.stderr
new file mode 100644
index 000000000..49706fae1
--- /dev/null
+++ b/src/test/ui/dyn-star/no-explicit-dyn-star.stderr
@@ -0,0 +1,9 @@
+error[E0606]: casting `usize` as `dyn* std::fmt::Display` is invalid
+ --> $DIR/no-explicit-dyn-star.rs:6:48
+ |
+LL | dyn_star_foreign::require_dyn_star_display(1usize as _);
+ | ^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0606`.
diff --git a/src/test/ui/dyn-star/no-implicit-dyn-star.rs b/src/test/ui/dyn-star/no-implicit-dyn-star.rs
new file mode 100644
index 000000000..d9470e284
--- /dev/null
+++ b/src/test/ui/dyn-star/no-implicit-dyn-star.rs
@@ -0,0 +1,8 @@
+// aux-build:dyn-star-foreign.rs
+
+extern crate dyn_star_foreign;
+
+fn main() {
+ dyn_star_foreign::require_dyn_star_display(1usize);
+ //~^ ERROR mismatched types
+}
diff --git a/src/test/ui/dyn-star/no-implicit-dyn-star.stderr b/src/test/ui/dyn-star/no-implicit-dyn-star.stderr
new file mode 100644
index 000000000..e7c591862
--- /dev/null
+++ b/src/test/ui/dyn-star/no-implicit-dyn-star.stderr
@@ -0,0 +1,19 @@
+error[E0308]: mismatched types
+ --> $DIR/no-implicit-dyn-star.rs:6:48
+ |
+LL | dyn_star_foreign::require_dyn_star_display(1usize);
+ | ------------------------------------------ ^^^^^^ expected trait object `dyn std::fmt::Display`, found `usize`
+ | |
+ | arguments to this function are incorrect
+ |
+ = note: expected trait object `(dyn* std::fmt::Display + 'static)`
+ found type `usize`
+note: function defined here
+ --> $DIR/auxiliary/dyn-star-foreign.rs:6:8
+ |
+LL | pub fn require_dyn_star_display(_: dyn* Display) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/dyn-star/upcast.rs b/src/test/ui/dyn-star/upcast.rs
new file mode 100644
index 000000000..cee76ada7
--- /dev/null
+++ b/src/test/ui/dyn-star/upcast.rs
@@ -0,0 +1,33 @@
+// run-pass
+
+#![feature(dyn_star, trait_upcasting)]
+#![allow(incomplete_features)]
+
+trait Foo: Bar {
+ fn hello(&self);
+}
+
+trait Bar {
+ fn world(&self);
+}
+
+struct W(usize);
+
+impl Foo for W {
+ fn hello(&self) {
+ println!("hello!");
+ }
+}
+
+impl Bar for W {
+ fn world(&self) {
+ println!("world!");
+ }
+}
+
+fn main() {
+ let w: dyn* Foo = W(0);
+ w.hello();
+ let w: dyn* Bar = w;
+ w.world();
+}
diff --git a/src/test/ui/editions/edition-raw-pointer-method-2015.stderr b/src/test/ui/editions/edition-raw-pointer-method-2015.stderr
index 417daf36f..612dd17e7 100644
--- a/src/test/ui/editions/edition-raw-pointer-method-2015.stderr
+++ b/src/test/ui/editions/edition-raw-pointer-method-2015.stderr
@@ -4,14 +4,14 @@ error: type annotations needed
LL | let _ = y.is_null();
| ^^^^^^^
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #46906 <https://github.com/rust-lang/rust/issues/46906>
note: the lint level is defined here
--> $DIR/edition-raw-pointer-method-2015.rs:5:8
|
LL | #[deny(warnings)]
| ^^^^^^^^
= note: `#[deny(tyvar_behind_raw_pointer)]` implied by `#[deny(warnings)]`
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #46906 <https://github.com/rust-lang/rust/issues/46906>
error: aborting due to previous error
diff --git a/src/test/ui/empty/empty-attributes.stderr b/src/test/ui/empty/empty-attributes.stderr
index 8653eaf5c..01d0d5a6b 100644
--- a/src/test/ui/empty/empty-attributes.stderr
+++ b/src/test/ui/empty/empty-attributes.stderr
@@ -4,12 +4,12 @@ error: unused attribute
LL | #[repr()]
| ^^^^^^^^^ help: remove this attribute
|
+ = note: attribute `repr` with an empty list has no effect
note: the lint level is defined here
--> $DIR/empty-attributes.rs:3:9
|
LL | #![deny(unused_attributes)]
| ^^^^^^^^^^^^^^^^^
- = note: attribute `repr` with an empty list has no effect
error: unused attribute
--> $DIR/empty-attributes.rs:14:1
diff --git a/src/test/ui/empty/empty-struct-braces-expr.stderr b/src/test/ui/empty/empty-struct-braces-expr.stderr
index 5fc0a916a..5b0ca613f 100644
--- a/src/test/ui/empty/empty-struct-braces-expr.stderr
+++ b/src/test/ui/empty/empty-struct-braces-expr.stderr
@@ -21,29 +21,6 @@ help: a unit struct with a similar name exists
LL | let e1 = XEmpty2;
| ~~~~~~~
-error[E0423]: expected function, tuple struct or tuple variant, found struct `Empty1`
- --> $DIR/empty-struct-braces-expr.rs:16:14
- |
-LL | struct Empty1 {}
- | ---------------- `Empty1` defined here
-...
-LL | let e1 = Empty1();
- | ^^^^^^^^
- |
- ::: $DIR/auxiliary/empty-struct.rs:2:1
- |
-LL | pub struct XEmpty2;
- | ------------------ similarly named unit struct `XEmpty2` defined here
- |
-help: use struct literal syntax instead
- |
-LL | let e1 = Empty1 {};
- | ~~~~~~~~~
-help: a unit struct with a similar name exists
- |
-LL | let e1 = XEmpty2();
- | ~~~~~~~
-
error[E0423]: expected value, found struct variant `E::Empty3`
--> $DIR/empty-struct-braces-expr.rs:18:14
|
@@ -84,6 +61,29 @@ help: a unit struct with a similar name exists
LL | let xe1 = XEmpty2;
| ~~~~~~~
+error[E0423]: expected function, tuple struct or tuple variant, found struct `Empty1`
+ --> $DIR/empty-struct-braces-expr.rs:16:14
+ |
+LL | struct Empty1 {}
+ | ---------------- `Empty1` defined here
+...
+LL | let e1 = Empty1();
+ | ^^^^^^^^
+ |
+ ::: $DIR/auxiliary/empty-struct.rs:2:1
+ |
+LL | pub struct XEmpty2;
+ | ------------------ similarly named unit struct `XEmpty2` defined here
+ |
+help: use struct literal syntax instead
+ |
+LL | let e1 = Empty1 {};
+ | ~~~~~~~~~
+help: a unit struct with a similar name exists
+ |
+LL | let e1 = XEmpty2();
+ | ~~~~~~~
+
error[E0423]: expected function, tuple struct or tuple variant, found struct `XEmpty1`
--> $DIR/empty-struct-braces-expr.rs:23:15
|
diff --git a/src/test/ui/empty_global_asm.rs b/src/test/ui/empty_global_asm.rs
index dbcc7be05..af13762d1 100644
--- a/src/test/ui/empty_global_asm.rs
+++ b/src/test/ui/empty_global_asm.rs
@@ -1,21 +1,8 @@
+// needs-asm-support
// run-pass
-#[allow(unused_imports)]
use std::arch::global_asm;
-#[cfg(target_arch = "x86")]
-global_asm!("");
-
-#[cfg(target_arch = "x86_64")]
-global_asm!("");
-
-#[cfg(target_arch = "arm")]
-global_asm!("");
-
-#[cfg(target_arch = "aarch64")]
-global_asm!("");
-
-#[cfg(target_arch = "mips")]
global_asm!("");
fn main() {}
diff --git a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.rs b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.rs
index 4da7b5ab2..a6e5f70fd 100644
--- a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.rs
+++ b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.rs
@@ -1,5 +1,4 @@
#![crate_type="lib"]
-#![feature(arbitrary_enum_discriminant)]
enum Enum {
//~^ ERROR `#[repr(inttype)]` must be specified
diff --git a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr
index 803bb06fc..8cee74696 100644
--- a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr
+++ b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant-no-repr.stderr
@@ -1,5 +1,5 @@
error[E0732]: `#[repr(inttype)]` must be specified
- --> $DIR/arbitrary_enum_discriminant-no-repr.rs:4:1
+ --> $DIR/arbitrary_enum_discriminant-no-repr.rs:3:1
|
LL | enum Enum {
| ^^^^^^^^^
diff --git a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs
index ccc423e4a..83e74a6e6 100644
--- a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs
+++ b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs
@@ -1,5 +1,5 @@
// run-pass
-#![feature(arbitrary_enum_discriminant, test)]
+#![feature(test)]
extern crate test;
diff --git a/src/test/ui/enum-discriminant/discriminant_size.stderr b/src/test/ui/enum-discriminant/discriminant_size.stderr
index efc7d9984..9b1505b5c 100644
--- a/src/test/ui/enum-discriminant/discriminant_size.stderr
+++ b/src/test/ui/enum-discriminant/discriminant_size.stderr
@@ -4,8 +4,8 @@ warning: the feature `repr128` is incomplete and may not be safe to use and/or c
LL | #![feature(core_intrinsics, repr128)]
| ^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #56071 <https://github.com/rust-lang/rust/issues/56071> for more information
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/enum-discriminant/discriminant_value.rs b/src/test/ui/enum-discriminant/discriminant_value.rs
index 65ab411db..f3dfac298 100644
--- a/src/test/ui/enum-discriminant/discriminant_value.rs
+++ b/src/test/ui/enum-discriminant/discriminant_value.rs
@@ -1,6 +1,6 @@
// run-pass
#![allow(stable_features)]
-#![feature(arbitrary_enum_discriminant, core, core_intrinsics)]
+#![feature(core, core_intrinsics)]
extern crate core;
use core::intrinsics::discriminant_value;
diff --git a/src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.rs b/src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.rs
deleted file mode 100644
index 3e90af4d3..000000000
--- a/src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-#![crate_type="lib"]
-
-enum Enum {
- Unit = 1,
- //~^ ERROR custom discriminant values are not allowed in enums with tuple or struct variants
- Tuple() = 2,
- //~^ ERROR discriminants on non-unit variants are experimental
- Struct{} = 3,
- //~^ ERROR discriminants on non-unit variants are experimental
-}
diff --git a/src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.stderr b/src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.stderr
deleted file mode 100644
index b5f61e6e9..000000000
--- a/src/test/ui/enum-discriminant/feature-gate-arbitrary_enum_discriminant.stderr
+++ /dev/null
@@ -1,36 +0,0 @@
-error[E0658]: discriminants on non-unit variants are experimental
- --> $DIR/feature-gate-arbitrary_enum_discriminant.rs:6:13
- |
-LL | Tuple() = 2,
- | ^
- |
- = note: see issue #60553 <https://github.com/rust-lang/rust/issues/60553> for more information
- = help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable
-
-error[E0658]: discriminants on non-unit variants are experimental
- --> $DIR/feature-gate-arbitrary_enum_discriminant.rs:8:14
- |
-LL | Struct{} = 3,
- | ^
- |
- = note: see issue #60553 <https://github.com/rust-lang/rust/issues/60553> for more information
- = help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable
-
-error[E0658]: custom discriminant values are not allowed in enums with tuple or struct variants
- --> $DIR/feature-gate-arbitrary_enum_discriminant.rs:4:10
- |
-LL | Unit = 1,
- | ^ disallowed custom discriminant
-LL |
-LL | Tuple() = 2,
- | ----------- tuple variant defined here
-LL |
-LL | Struct{} = 3,
- | ------------ struct variant defined here
- |
- = note: see issue #60553 <https://github.com/rust-lang/rust/issues/60553> for more information
- = help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable
-
-error: aborting due to 3 previous errors
-
-For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/enum-discriminant/issue-43398.stderr b/src/test/ui/enum-discriminant/issue-43398.stderr
index 9a394153b..fc7bbd062 100644
--- a/src/test/ui/enum-discriminant/issue-43398.stderr
+++ b/src/test/ui/enum-discriminant/issue-43398.stderr
@@ -4,8 +4,8 @@ warning: the feature `repr128` is incomplete and may not be safe to use and/or c
LL | #![feature(repr128)]
| ^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #56071 <https://github.com/rust-lang/rust/issues/56071> for more information
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs
index f927dd189..ad9fcc25b 100644
--- a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs
+++ b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice-2.rs
@@ -1,4 +1,4 @@
-#![feature(arbitrary_enum_discriminant, core_intrinsics)]
+#![feature(core_intrinsics)]
extern crate core;
use core::intrinsics::discriminant_value;
diff --git a/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.rs b/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.rs
index e62582fb5..42a062239 100644
--- a/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.rs
+++ b/src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.rs
@@ -1,4 +1,4 @@
-#![feature(arbitrary_enum_discriminant, core_intrinsics)]
+#![feature(core_intrinsics)]
extern crate core;
use core::intrinsics::discriminant_value;
diff --git a/src/test/ui/enum-discriminant/issue-70509-partial_eq.rs b/src/test/ui/enum-discriminant/issue-70509-partial_eq.rs
index ae389e114..3adac7b72 100644
--- a/src/test/ui/enum-discriminant/issue-70509-partial_eq.rs
+++ b/src/test/ui/enum-discriminant/issue-70509-partial_eq.rs
@@ -1,5 +1,5 @@
// run-pass
-#![feature(repr128, arbitrary_enum_discriminant)]
+#![feature(repr128)]
//~^ WARN the feature `repr128` is incomplete
#[derive(PartialEq, Debug)]
diff --git a/src/test/ui/enum-discriminant/issue-70509-partial_eq.stderr b/src/test/ui/enum-discriminant/issue-70509-partial_eq.stderr
index 5bf6ea56e..2eef930c3 100644
--- a/src/test/ui/enum-discriminant/issue-70509-partial_eq.stderr
+++ b/src/test/ui/enum-discriminant/issue-70509-partial_eq.stderr
@@ -1,11 +1,11 @@
warning: the feature `repr128` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/issue-70509-partial_eq.rs:2:12
|
-LL | #![feature(repr128, arbitrary_enum_discriminant)]
+LL | #![feature(repr128)]
| ^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #56071 <https://github.com/rust-lang/rust/issues/56071> for more information
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/enum-discriminant/repr128.stderr b/src/test/ui/enum-discriminant/repr128.stderr
index 88adfb174..da8d75c11 100644
--- a/src/test/ui/enum-discriminant/repr128.stderr
+++ b/src/test/ui/enum-discriminant/repr128.stderr
@@ -4,8 +4,8 @@ warning: the feature `repr128` is incomplete and may not be safe to use and/or c
LL | #![feature(repr128, core_intrinsics, discriminant_kind)]
| ^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #56071 <https://github.com/rust-lang/rust/issues/56071> for more information
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/enum/enum-discrim-too-small2.stderr b/src/test/ui/enum/enum-discrim-too-small2.stderr
index 438306795..f79f7a043 100644
--- a/src/test/ui/enum/enum-discrim-too-small2.stderr
+++ b/src/test/ui/enum/enum-discrim-too-small2.stderr
@@ -4,13 +4,13 @@ error: literal out of range for `i8`
LL | Ci8 = 223,
| ^^^
|
+ = note: the literal `223` does not fit into the type `i8` whose range is `-128..=127`
+ = help: consider using the type `u8` instead
note: the lint level is defined here
--> $DIR/enum-discrim-too-small2.rs:1:9
|
LL | #![deny(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
- = note: the literal `223` does not fit into the type `i8` whose range is `-128..=127`
- = help: consider using the type `u8` instead
error: literal out of range for `i16`
--> $DIR/enum-discrim-too-small2.rs:15:12
diff --git a/src/test/ui/error-codes/E0017.stderr b/src/test/ui/error-codes/E0017.stderr
index 830e4db34..6e48f9582 100644
--- a/src/test/ui/error-codes/E0017.stderr
+++ b/src/test/ui/error-codes/E0017.stderr
@@ -4,7 +4,6 @@ warning: taking a mutable reference to a `const` item
LL | const CR: &'static mut i32 = &mut C;
| ^^^^^^
|
- = note: `#[warn(const_item_mutation)]` on by default
= note: each usage of a `const` item creates a new temporary
= note: the mutable reference will refer to this temporary, not the original `const` item
note: `const` item defined here
@@ -12,6 +11,7 @@ note: `const` item defined here
|
LL | const C: i32 = 2;
| ^^^^^^^^^^^^
+ = note: `#[warn(const_item_mutation)]` on by default
error[E0764]: mutable references are not allowed in the final value of constants
--> $DIR/E0017.rs:5:30
diff --git a/src/test/ui/error-codes/E0094.rs b/src/test/ui/error-codes/E0094.rs
index 0d58e5a28..a2ec932c1 100644
--- a/src/test/ui/error-codes/E0094.rs
+++ b/src/test/ui/error-codes/E0094.rs
@@ -1,5 +1,7 @@
#![feature(intrinsics)]
+
extern "rust-intrinsic" {
+ #[rustc_safe_intrinsic]
fn size_of<T, U>() -> usize; //~ ERROR E0094
}
diff --git a/src/test/ui/error-codes/E0094.stderr b/src/test/ui/error-codes/E0094.stderr
index da97f3a01..531cd4c78 100644
--- a/src/test/ui/error-codes/E0094.stderr
+++ b/src/test/ui/error-codes/E0094.stderr
@@ -1,5 +1,5 @@
error[E0094]: intrinsic has wrong number of type parameters: found 2, expected 1
- --> $DIR/E0094.rs:3:15
+ --> $DIR/E0094.rs:5:15
|
LL | fn size_of<T, U>() -> usize;
| ^^^^^^ expected 1 type parameter
diff --git a/src/test/ui/error-codes/E0199.stderr b/src/test/ui/error-codes/E0199.stderr
index 3632d26cd..99d808c0d 100644
--- a/src/test/ui/error-codes/E0199.stderr
+++ b/src/test/ui/error-codes/E0199.stderr
@@ -3,6 +3,12 @@ error[E0199]: implementing the trait `Bar` is not unsafe
|
LL | unsafe impl Bar for Foo { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove `unsafe` from this trait implementation
+ |
+LL - unsafe impl Bar for Foo { }
+LL + impl Bar for Foo { }
+ |
error: aborting due to previous error
diff --git a/src/test/ui/error-codes/E0200.stderr b/src/test/ui/error-codes/E0200.stderr
index 677271aad..1fd86aece 100644
--- a/src/test/ui/error-codes/E0200.stderr
+++ b/src/test/ui/error-codes/E0200.stderr
@@ -3,6 +3,12 @@ error[E0200]: the trait `Bar` requires an `unsafe impl` declaration
|
LL | impl Bar for Foo { }
| ^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the trait `Bar` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
+help: add `unsafe` to this trait implementation
+ |
+LL | unsafe impl Bar for Foo { }
+ | ++++++
error: aborting due to previous error
diff --git a/src/test/ui/error-codes/E0201.rs b/src/test/ui/error-codes/E0201.rs
index adefd4bcd..04b37091b 100644
--- a/src/test/ui/error-codes/E0201.rs
+++ b/src/test/ui/error-codes/E0201.rs
@@ -2,7 +2,7 @@ struct Foo(u8);
impl Foo {
fn bar(&self) -> bool { self.0 > 5 }
- fn bar() {} //~ ERROR E0201
+ fn bar() {} //~ ERROR E0592
}
trait Baz {
diff --git a/src/test/ui/error-codes/E0201.stderr b/src/test/ui/error-codes/E0201.stderr
index 94e068941..608ff6917 100644
--- a/src/test/ui/error-codes/E0201.stderr
+++ b/src/test/ui/error-codes/E0201.stderr
@@ -1,28 +1,35 @@
-error[E0201]: duplicate definitions with name `bar`:
- --> $DIR/E0201.rs:5:5
- |
-LL | fn bar(&self) -> bool { self.0 > 5 }
- | --------------------- previous definition of `bar` here
-LL | fn bar() {}
- | ^^^^^^^^ duplicate definition
-
error[E0201]: duplicate definitions with name `baz`:
--> $DIR/E0201.rs:17:5
|
+LL | fn baz(&self) -> bool;
+ | ---------------------- item in trait
+...
LL | fn baz(&self) -> bool { true }
- | --------------------- previous definition of `baz` here
+ | ------------------------------ previous definition here
LL | fn baz(&self) -> bool { self.0 > 5 }
- | ^^^^^^^^^^^^^^^^^^^^^ duplicate definition
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definition
error[E0201]: duplicate definitions with name `Quux`:
--> $DIR/E0201.rs:18:5
|
+LL | type Quux;
+ | ---------- item in trait
+...
LL | type Quux = u32;
- | --------- previous definition of `Quux` here
+ | ---------------- previous definition here
...
LL | type Quux = u32;
- | ^^^^^^^^^ duplicate definition
+ | ^^^^^^^^^^^^^^^^ duplicate definition
+
+error[E0592]: duplicate definitions with name `bar`
+ --> $DIR/E0201.rs:5:5
+ |
+LL | fn bar(&self) -> bool { self.0 > 5 }
+ | --------------------- other definition for `bar`
+LL | fn bar() {}
+ | ^^^^^^^^ duplicate definitions for `bar`
error: aborting due to 3 previous errors
-For more information about this error, try `rustc --explain E0201`.
+Some errors have detailed explanations: E0201, E0592.
+For more information about an error, try `rustc --explain E0201`.
diff --git a/src/test/ui/error-codes/E0283.stderr b/src/test/ui/error-codes/E0283.stderr
index 90a28874e..90316c6e9 100644
--- a/src/test/ui/error-codes/E0283.stderr
+++ b/src/test/ui/error-codes/E0283.stderr
@@ -9,8 +9,8 @@ LL | let cont: u32 = Generator::create();
|
help: use a fully-qualified path to a specific available implementation (2 found)
|
-LL | let cont: u32 = <::Impl as Generator>::create();
- | ++++++++++ +
+LL | let cont: u32 = <Impl as Generator>::create();
+ | ++++++++ +
error[E0283]: type annotations needed
--> $DIR/E0283.rs:35:24
diff --git a/src/test/ui/error-codes/E0308.rs b/src/test/ui/error-codes/E0308.rs
index fa79bee57..dd9e0b284 100644
--- a/src/test/ui/error-codes/E0308.rs
+++ b/src/test/ui/error-codes/E0308.rs
@@ -1,6 +1,8 @@
#![feature(intrinsics)]
+#![feature(rustc_attrs)]
extern "rust-intrinsic" {
+ #[rustc_safe_intrinsic]
fn size_of<T>(); //~ ERROR E0308
}
diff --git a/src/test/ui/error-codes/E0308.stderr b/src/test/ui/error-codes/E0308.stderr
index b71fb95e7..187b775f9 100644
--- a/src/test/ui/error-codes/E0308.stderr
+++ b/src/test/ui/error-codes/E0308.stderr
@@ -1,5 +1,5 @@
error[E0308]: intrinsic has wrong type
- --> $DIR/E0308.rs:4:5
+ --> $DIR/E0308.rs:6:5
|
LL | fn size_of<T>();
| ^^^^^^^^^^^^^^^^ expected `()`, found `usize`
diff --git a/src/test/ui/error-codes/E0311.rs b/src/test/ui/error-codes/E0311.rs
new file mode 100644
index 000000000..566b518b4
--- /dev/null
+++ b/src/test/ui/error-codes/E0311.rs
@@ -0,0 +1,9 @@
+fn no_restriction<T>(x: &()) -> &() {
+ with_restriction::<T>(x) //~ ERROR E0311
+}
+
+fn with_restriction<'a, T: 'a>(x: &'a ()) -> &'a () {
+ x
+}
+
+fn main() {}
diff --git a/src/test/ui/error-codes/E0311.stderr b/src/test/ui/error-codes/E0311.stderr
new file mode 100644
index 000000000..9873b5ae6
--- /dev/null
+++ b/src/test/ui/error-codes/E0311.stderr
@@ -0,0 +1,24 @@
+error[E0311]: the parameter type `T` may not live long enough
+ --> $DIR/E0311.rs:2:5
+ |
+LL | with_restriction::<T>(x)
+ | ^^^^^^^^^^^^^^^^^^^^^
+ |
+note: the parameter type `T` must be valid for the anonymous lifetime defined here...
+ --> $DIR/E0311.rs:1:25
+ |
+LL | fn no_restriction<T>(x: &()) -> &() {
+ | ^^^
+note: ...so that the type `T` will meet its required lifetime bounds
+ --> $DIR/E0311.rs:2:5
+ |
+LL | with_restriction::<T>(x)
+ | ^^^^^^^^^^^^^^^^^^^^^
+help: consider adding an explicit lifetime bound...
+ |
+LL | fn no_restriction<'a, T: 'a>(x: &()) -> &() {
+ | +++ ++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0311`.
diff --git a/src/test/ui/error-codes/E0388.stderr b/src/test/ui/error-codes/E0388.stderr
index 106efc19a..b51aa263d 100644
--- a/src/test/ui/error-codes/E0388.stderr
+++ b/src/test/ui/error-codes/E0388.stderr
@@ -4,7 +4,6 @@ warning: taking a mutable reference to a `const` item
LL | const CR: &'static mut i32 = &mut C;
| ^^^^^^
|
- = note: `#[warn(const_item_mutation)]` on by default
= note: each usage of a `const` item creates a new temporary
= note: the mutable reference will refer to this temporary, not the original `const` item
note: `const` item defined here
@@ -12,6 +11,7 @@ note: `const` item defined here
|
LL | const C: i32 = 2;
| ^^^^^^^^^^^^
+ = note: `#[warn(const_item_mutation)]` on by default
error[E0764]: mutable references are not allowed in the final value of constants
--> $DIR/E0388.rs:4:30
diff --git a/src/test/ui/error-codes/E0423.stderr b/src/test/ui/error-codes/E0423.stderr
index 8f2ef8c8e..ac70d905d 100644
--- a/src/test/ui/error-codes/E0423.stderr
+++ b/src/test/ui/error-codes/E0423.stderr
@@ -26,6 +26,17 @@ help: surround the struct literal with parentheses
LL | for _ in (std::ops::Range { start: 0, end: 10 }) {}
| + +
+error[E0423]: expected value, found struct `T`
+ --> $DIR/E0423.rs:14:8
+ |
+LL | if T {} == T {} { println!("Ok"); }
+ | ^ not a value
+ |
+help: surround the struct literal with parentheses
+ |
+LL | if (T {}) == T {} { println!("Ok"); }
+ | + +
+
error[E0423]: expected function, tuple struct or tuple variant, found struct `Foo`
--> $DIR/E0423.rs:4:13
|
@@ -47,17 +58,6 @@ help: a function with a similar name exists
LL | let f = foo();
| ~~~
-error[E0423]: expected value, found struct `T`
- --> $DIR/E0423.rs:14:8
- |
-LL | if T {} == T {} { println!("Ok"); }
- | ^ not a value
- |
-help: surround the struct literal with parentheses
- |
-LL | if (T {}) == T {} { println!("Ok"); }
- | + +
-
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0423`.
diff --git a/src/test/ui/error-codes/E0520.stderr b/src/test/ui/error-codes/E0520.stderr
index 65ebfcdbe..12ecead13 100644
--- a/src/test/ui/error-codes/E0520.stderr
+++ b/src/test/ui/error-codes/E0520.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0520]: `fly` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/E0520.rs:17:5
diff --git a/src/test/ui/error-codes/E0585.stderr b/src/test/ui/error-codes/E0585.stderr
index 7a31c4896..53c82fb41 100644
--- a/src/test/ui/error-codes/E0585.stderr
+++ b/src/test/ui/error-codes/E0585.stderr
@@ -4,7 +4,7 @@ error[E0585]: found a documentation comment that doesn't document anything
LL | /// Hello! I'm useless...
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: doc comments must come before what they document, maybe a comment was intended with `//`?
+ = help: doc comments must come before what they document, if a comment was intended use `//`
error: aborting due to previous error
diff --git a/src/test/ui/error-codes/E0771.stderr b/src/test/ui/error-codes/E0771.stderr
index 3ab727f5f..b759399a9 100644
--- a/src/test/ui/error-codes/E0771.stderr
+++ b/src/test/ui/error-codes/E0771.stderr
@@ -12,8 +12,8 @@ warning: the feature `adt_const_params` is incomplete and may not be safe to use
LL | #![feature(adt_const_params)]
| ^^^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error: aborting due to previous error; 1 warning emitted
diff --git a/src/test/ui/error-codes/E0790.stderr b/src/test/ui/error-codes/E0790.stderr
index 6e173a968..f68c0e7d2 100644
--- a/src/test/ui/error-codes/E0790.stderr
+++ b/src/test/ui/error-codes/E0790.stderr
@@ -9,8 +9,8 @@ LL | MyTrait::my_fn();
|
help: use the fully-qualified path to the only available implementation
|
-LL | <::inner::MyStruct as MyTrait>::my_fn();
- | +++++++++++++++++++++ +
+LL | <MyStruct as MyTrait>::my_fn();
+ | ++++++++++++ +
error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type
--> $DIR/E0790.rs:21:17
@@ -23,8 +23,8 @@ LL | let _ = MyTrait::MY_ASSOC_CONST;
|
help: use the fully-qualified path to the only available implementation
|
-LL | let _ = <::inner::MyStruct as MyTrait>::MY_ASSOC_CONST;
- | +++++++++++++++++++++ +
+LL | let _ = <MyStruct as MyTrait>::MY_ASSOC_CONST;
+ | ++++++++++++ +
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
--> $DIR/E0790.rs:26:5
@@ -37,8 +37,8 @@ LL | inner::MyTrait::my_fn();
|
help: use the fully-qualified path to the only available implementation
|
-LL | inner::<::inner::MyStruct as MyTrait>::my_fn();
- | +++++++++++++++++++++ +
+LL | inner::<MyStruct as MyTrait>::my_fn();
+ | ++++++++++++ +
error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type
--> $DIR/E0790.rs:30:13
@@ -51,8 +51,8 @@ LL | let _ = inner::MyTrait::MY_ASSOC_CONST;
|
help: use the fully-qualified path to the only available implementation
|
-LL | let _ = inner::<::inner::MyStruct as MyTrait>::MY_ASSOC_CONST;
- | +++++++++++++++++++++ +
+LL | let _ = inner::<MyStruct as MyTrait>::MY_ASSOC_CONST;
+ | ++++++++++++ +
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
--> $DIR/E0790.rs:50:5
@@ -65,8 +65,8 @@ LL | MyTrait2::my_fn();
|
help: use a fully-qualified path to a specific available implementation (2 found)
|
-LL | <::Impl1 as MyTrait2>::my_fn();
- | +++++++++++ +
+LL | <Impl1 as MyTrait2>::my_fn();
+ | +++++++++ +
error: aborting due to 5 previous errors
diff --git a/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.stderr b/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.stderr
index 4ec78a298..08eb8cfac 100644
--- a/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.stderr
+++ b/src/test/ui/errors/issue-89280-emitter-overflow-splice-lines.stderr
@@ -8,9 +8,9 @@ LL | |
LL | | )) {}
| |_____^
|
- = note: `#[warn(anonymous_parameters)]` on by default
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
+ = note: `#[warn(anonymous_parameters)]` on by default
help: try naming the parameter or explicitly ignoring it
|
LL ~ fn test(x: u32, _: (
diff --git a/src/test/ui/explain.stdout b/src/test/ui/explain.stdout
index 62f1a7f98..ef1d866c3 100644
--- a/src/test/ui/explain.stdout
+++ b/src/test/ui/explain.stdout
@@ -47,8 +47,8 @@ unsafe {
```
Here, transmute is being used to convert the types of the fn arguments.
-This pattern is incorrect because, because the type of `foo` is a function
-**item** (`typeof(foo)`), which is zero-sized, and the target type (`fn()`)
+This pattern is incorrect because the type of `foo` is a function **item**
+(`typeof(foo)`), which is zero-sized, and the target type (`fn()`)
is a function pointer, which is not zero-sized.
This pattern should be rewritten. There are a few possible ways to do this:
diff --git a/src/test/ui/expr/if/bad-if-let-suggestion.stderr b/src/test/ui/expr/if/bad-if-let-suggestion.stderr
index 60d286fed..3a53a20b4 100644
--- a/src/test/ui/expr/if/bad-if-let-suggestion.stderr
+++ b/src/test/ui/expr/if/bad-if-let-suggestion.stderr
@@ -62,6 +62,11 @@ error[E0308]: mismatched types
|
LL | if let x = 1 && i = 2 {}
| ^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
+ |
+help: you might have meant to compare for equality
+ |
+LL | if let x = 1 && i == 2 {}
+ | +
error: aborting due to 8 previous errors
diff --git a/src/test/ui/expr/if/if-let.stderr b/src/test/ui/expr/if/if-let.stderr
index 8238b3f0e..c4bba3cb1 100644
--- a/src/test/ui/expr/if/if-let.stderr
+++ b/src/test/ui/expr/if/if-let.stderr
@@ -9,9 +9,9 @@ LL | | println!("irrefutable pattern");
LL | | });
| |______- in this macro invocation
|
- = note: `#[warn(irrefutable_let_patterns)]` on by default
= note: this pattern will always match, so the `if let` is useless
= help: consider replacing the `if let` with a `let`
+ = note: `#[warn(irrefutable_let_patterns)]` on by default
= note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: irrefutable `if let` pattern
diff --git a/src/test/ui/expr/if/if-without-else-result.rs b/src/test/ui/expr/if/if-without-else-result.rs
index cf84a99e5..95604758a 100644
--- a/src/test/ui/expr/if/if-without-else-result.rs
+++ b/src/test/ui/expr/if/if-without-else-result.rs
@@ -1,6 +1,6 @@
fn main() {
let a = if true { true };
//~^ ERROR `if` may be missing an `else` clause [E0317]
- //~| expected `()`, found `bool`
+ //~| expected `bool`, found `()`
println!("{}", a);
}
diff --git a/src/test/ui/expr/if/if-without-else-result.stderr b/src/test/ui/expr/if/if-without-else-result.stderr
index 821635d37..317faf7c6 100644
--- a/src/test/ui/expr/if/if-without-else-result.stderr
+++ b/src/test/ui/expr/if/if-without-else-result.stderr
@@ -5,7 +5,7 @@ LL | let a = if true { true };
| ^^^^^^^^^^----^^
| | |
| | found here
- | expected `()`, found `bool`
+ | expected `bool`, found `()`
|
= note: `if` expressions without `else` evaluate to `()`
= help: consider adding an `else` block that evaluates to the expected type
diff --git a/src/test/ui/expr/if/issue-4201.rs b/src/test/ui/expr/if/issue-4201.rs
index 1f292229f..59c465b9e 100644
--- a/src/test/ui/expr/if/issue-4201.rs
+++ b/src/test/ui/expr/if/issue-4201.rs
@@ -3,7 +3,7 @@ fn main() {
0
} else if false {
//~^ ERROR `if` may be missing an `else` clause
-//~| expected `()`, found integer
+//~| expected integer, found `()`
1
};
}
diff --git a/src/test/ui/expr/if/issue-4201.stderr b/src/test/ui/expr/if/issue-4201.stderr
index bc638ddf5..612fe7764 100644
--- a/src/test/ui/expr/if/issue-4201.stderr
+++ b/src/test/ui/expr/if/issue-4201.stderr
@@ -8,7 +8,7 @@ LL | |
LL | | 1
| | - found here
LL | | };
- | |_____^ expected `()`, found integer
+ | |_____^ expected integer, found `()`
|
= note: `if` expressions without `else` evaluate to `()`
= help: consider adding an `else` block that evaluates to the expected type
diff --git a/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr b/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr
index 9db9cfc7f..759d79493 100644
--- a/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr
+++ b/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr
@@ -14,7 +14,7 @@ LL | let p = Some(45).and_then({
LL | |
LL | | |x| println!("doubling {}", x);
LL | | Some(x * 2)
- | | -----------
+ | | ----------- this tail expression is of type `std::option::Option<_>`
LL | |
LL | | });
| |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>`
diff --git a/src/test/ui/extenv/issue-55897.rs b/src/test/ui/extenv/issue-55897.rs
index 64c4107e8..b7533f413 100644
--- a/src/test/ui/extenv/issue-55897.rs
+++ b/src/test/ui/extenv/issue-55897.rs
@@ -14,7 +14,7 @@ mod nonexistent_env {
mod erroneous_literal {
include!(concat!("NON_EXISTENT"suffix, "/data.rs"));
- //~^ ERROR suffixes on a string literal are invalid
+ //~^ ERROR suffixes on string literals are invalid
}
fn main() {}
diff --git a/src/test/ui/extenv/issue-55897.stderr b/src/test/ui/extenv/issue-55897.stderr
index d2ac0b830..63797d4a7 100644
--- a/src/test/ui/extenv/issue-55897.stderr
+++ b/src/test/ui/extenv/issue-55897.stderr
@@ -6,7 +6,7 @@ LL | include!(concat!(env!("NON_EXISTENT"), "/data.rs"));
|
= note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: suffixes on a string literal are invalid
+error: suffixes on string literals are invalid
--> $DIR/issue-55897.rs:16:22
|
LL | include!(concat!("NON_EXISTENT"suffix, "/data.rs"));
@@ -26,6 +26,11 @@ error[E0432]: unresolved import `env`
|
LL | use env;
| ^^^ no `env` in the root
+ |
+help: consider importing this module instead
+ |
+LL | use std::env;
+ | ~~~~~~~~~
error: cannot determine resolution for the macro `env`
--> $DIR/issue-55897.rs:6:22
diff --git a/src/test/ui/extern-flag/empty-extern-arg.rs b/src/test/ui/extern-flag/empty-extern-arg.rs
index 3170537b0..2f4ae7d8e 100644
--- a/src/test/ui/extern-flag/empty-extern-arg.rs
+++ b/src/test/ui/extern-flag/empty-extern-arg.rs
@@ -1,6 +1,6 @@
// compile-flags: --extern std=
// error-pattern: extern location for std does not exist
// needs-unwind since it affects the error output
-// ignore-emscripten compiled with panic=abort, personality not required
+// ignore-emscripten missing eh_catch_typeinfo lang item
fn main() {}
diff --git a/src/test/ui/extern/extern-no-mangle.stderr b/src/test/ui/extern/extern-no-mangle.stderr
index b56428141..f20ee158a 100644
--- a/src/test/ui/extern/extern-no-mangle.stderr
+++ b/src/test/ui/extern/extern-no-mangle.stderr
@@ -7,12 +7,12 @@ LL | #[no_mangle]
LL | let x = 0_u8;
| ------------- not a free function, impl method or static
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
note: the lint level is defined here
--> $DIR/extern-no-mangle.rs:1:9
|
LL | #![warn(unused_attributes)]
| ^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
warning: `#[no_mangle]` has no effect on a foreign static
--> $DIR/extern-no-mangle.rs:11:5
diff --git a/src/test/ui/extern/extern-with-type-bounds.rs b/src/test/ui/extern/extern-with-type-bounds.rs
index 8f9683e4a..a72aa4171 100644
--- a/src/test/ui/extern/extern-with-type-bounds.rs
+++ b/src/test/ui/extern/extern-with-type-bounds.rs
@@ -2,6 +2,7 @@
extern "rust-intrinsic" {
// Real example from libcore
+ #[rustc_safe_intrinsic]
fn type_id<T: ?Sized + 'static>() -> u64;
// Silent bounds made explicit to make sure they are actually
@@ -10,6 +11,7 @@ extern "rust-intrinsic" {
// Bounds aren't checked right now, so this should work
// even though it's incorrect.
+ #[rustc_safe_intrinsic]
fn size_of<T: Clone>() -> usize;
// Unresolved bounds should still error.
diff --git a/src/test/ui/extern/extern-with-type-bounds.stderr b/src/test/ui/extern/extern-with-type-bounds.stderr
index acd059642..88be1e5dd 100644
--- a/src/test/ui/extern/extern-with-type-bounds.stderr
+++ b/src/test/ui/extern/extern-with-type-bounds.stderr
@@ -1,5 +1,5 @@
error[E0405]: cannot find trait `NoSuchTrait` in this scope
- --> $DIR/extern-with-type-bounds.rs:16:20
+ --> $DIR/extern-with-type-bounds.rs:18:20
|
LL | fn align_of<T: NoSuchTrait>() -> usize;
| ^^^^^^^^^^^ not found in this scope
diff --git a/src/test/ui/extern/issue-64655-allow-unwind-when-calling-panic-directly.rs b/src/test/ui/extern/issue-64655-allow-unwind-when-calling-panic-directly.rs
index 7a91cbdc2..233120c92 100644
--- a/src/test/ui/extern/issue-64655-allow-unwind-when-calling-panic-directly.rs
+++ b/src/test/ui/extern/issue-64655-allow-unwind-when-calling-panic-directly.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
// ignore-emscripten no threads support
// rust-lang/rust#64655: with panic=unwind, a panic from a subroutine
diff --git a/src/test/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs b/src/test/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs
index e84ff41b3..3b263e58c 100644
--- a/src/test/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs
+++ b/src/test/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
// ignore-emscripten no threads support
// rust-lang/rust#64655: with panic=unwind, a panic from a subroutine
diff --git a/src/test/ui/feature-gates/bench.stderr b/src/test/ui/feature-gates/bench.stderr
index 168ac9257..5f0aaf925 100644
--- a/src/test/ui/feature-gates/bench.stderr
+++ b/src/test/ui/feature-gates/bench.stderr
@@ -4,9 +4,9 @@ error: use of unstable library feature 'test': `bench` is a part of custom test
LL | #[bench]
| ^^^^^
|
- = note: `#[deny(soft_unstable)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
+ = note: `#[deny(soft_unstable)]` on by default
error: use of unstable library feature 'test': `bench` is a part of custom test frameworks which are unstable
--> $DIR/bench.rs:7:5
diff --git a/src/test/ui/feature-gates/feature-gate-asm_sym.rs b/src/test/ui/feature-gates/feature-gate-asm_sym.rs
deleted file mode 100644
index 0de6b3abb..000000000
--- a/src/test/ui/feature-gates/feature-gate-asm_sym.rs
+++ /dev/null
@@ -1,19 +0,0 @@
-// only-x86_64
-
-use std::arch::asm;
-
-fn bar<const N: usize>() {}
-
-fn foo<const N: usize>() {
- unsafe {
- asm!("mov eax, {}", sym bar::<N>);
- //~^ ERROR sym operands for inline assembly are unstable
- }
-}
-
-fn main() {
- unsafe {
- asm!("mov eax, {}", sym foo::<0>);
- //~^ ERROR sym operands for inline assembly are unstable
- }
-}
diff --git a/src/test/ui/feature-gates/feature-gate-asm_sym.stderr b/src/test/ui/feature-gates/feature-gate-asm_sym.stderr
deleted file mode 100644
index d4b16f60b..000000000
--- a/src/test/ui/feature-gates/feature-gate-asm_sym.stderr
+++ /dev/null
@@ -1,21 +0,0 @@
-error[E0658]: sym operands for inline assembly are unstable
- --> $DIR/feature-gate-asm_sym.rs:9:29
- |
-LL | asm!("mov eax, {}", sym bar::<N>);
- | ^^^^^^^^^^^^
- |
- = note: see issue #93333 <https://github.com/rust-lang/rust/issues/93333> for more information
- = help: add `#![feature(asm_sym)]` to the crate attributes to enable
-
-error[E0658]: sym operands for inline assembly are unstable
- --> $DIR/feature-gate-asm_sym.rs:16:29
- |
-LL | asm!("mov eax, {}", sym foo::<0>);
- | ^^^^^^^^^^^^
- |
- = note: see issue #93333 <https://github.com/rust-lang/rust/issues/93333> for more information
- = help: add `#![feature(asm_sym)]` to the crate attributes to enable
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/feature-gates/feature-gate-default_type_parameter_fallback.stderr b/src/test/ui/feature-gates/feature-gate-default_type_parameter_fallback.stderr
index a7d5c7ac3..308de2692 100644
--- a/src/test/ui/feature-gates/feature-gate-default_type_parameter_fallback.stderr
+++ b/src/test/ui/feature-gates/feature-gate-default_type_parameter_fallback.stderr
@@ -4,9 +4,9 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type`
LL | fn avg<T=i32>(_: T) {}
| ^^^^^
|
- = note: `#[deny(invalid_type_param_default)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
+ = note: `#[deny(invalid_type_param_default)]` on by default
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
--> $DIR/feature-gate-default_type_parameter_fallback.rs:8:6
diff --git a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr
index 3de08e215..4d79ce3c6 100644
--- a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr
+++ b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr
@@ -4,10 +4,10 @@ warning: unknown lint: `non_exhaustive_omitted_patterns`
LL | #![deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unknown_lints)]` on by default
= note: the `non_exhaustive_omitted_patterns` lint is unstable
= note: see issue #89554 <https://github.com/rust-lang/rust/issues/89554> for more information
= help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable
+ = note: `#[warn(unknown_lints)]` on by default
warning: unknown lint: `non_exhaustive_omitted_patterns`
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:6:1
diff --git a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr
index ae44b8020..5b1270a19 100644
--- a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr
+++ b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr
@@ -25,9 +25,9 @@ LL |
LL | #[repr(simd)]
| ^^^^
|
- = note: `#[deny(conflicting_repr_hints)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
+ = note: `#[deny(conflicting_repr_hints)]` on by default
error: aborting due to 3 previous errors
diff --git a/src/test/ui/feature-gates/feature-gate-return_position_impl_trait_in_trait.rs b/src/test/ui/feature-gates/feature-gate-return_position_impl_trait_in_trait.rs
index de7966c66..637765fff 100644
--- a/src/test/ui/feature-gates/feature-gate-return_position_impl_trait_in_trait.rs
+++ b/src/test/ui/feature-gates/feature-gate-return_position_impl_trait_in_trait.rs
@@ -1,5 +1,18 @@
+// edition:2021
+
+// async_fn_in_trait is not enough to allow use of RPITIT
+#![allow(incomplete_features)]
+#![feature(async_fn_in_trait)]
+
trait Foo {
fn bar() -> impl Sized; //~ ERROR `impl Trait` only allowed in function and inherent method return types, not in trait method return
+ fn baz() -> Box<impl std::fmt::Display>; //~ ERROR `impl Trait` only allowed in function and inherent method return types, not in trait method return
+}
+
+// Both return_position_impl_trait_in_trait and async_fn_in_trait are required for this (see also
+// feature-gate-async_fn_in_trait.rs)
+trait AsyncFoo {
+ async fn bar() -> impl Sized; //~ ERROR `impl Trait` only allowed in function and inherent method return types, not in trait method return
}
fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-return_position_impl_trait_in_trait.stderr b/src/test/ui/feature-gates/feature-gate-return_position_impl_trait_in_trait.stderr
index 36177bbe1..aeabed4a6 100644
--- a/src/test/ui/feature-gates/feature-gate-return_position_impl_trait_in_trait.stderr
+++ b/src/test/ui/feature-gates/feature-gate-return_position_impl_trait_in_trait.stderr
@@ -1,5 +1,5 @@
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in trait method return
- --> $DIR/feature-gate-return_position_impl_trait_in_trait.rs:2:17
+ --> $DIR/feature-gate-return_position_impl_trait_in_trait.rs:8:17
|
LL | fn bar() -> impl Sized;
| ^^^^^^^^^^
@@ -7,6 +7,24 @@ LL | fn bar() -> impl Sized;
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
= help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
-error: aborting due to previous error
+error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in trait method return
+ --> $DIR/feature-gate-return_position_impl_trait_in_trait.rs:9:21
+ |
+LL | fn baz() -> Box<impl std::fmt::Display>;
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+
+error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in trait method return
+ --> $DIR/feature-gate-return_position_impl_trait_in_trait.rs:15:23
+ |
+LL | async fn bar() -> impl Sized;
+ | ^^^^^^^^^^
+ |
+ = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
+ = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+
+error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0562`.
diff --git a/src/test/ui/feature-gates/feature-gate-strict_provenance.stderr b/src/test/ui/feature-gates/feature-gate-strict_provenance.stderr
index 34bd240c3..751da87cc 100644
--- a/src/test/ui/feature-gates/feature-gate-strict_provenance.stderr
+++ b/src/test/ui/feature-gates/feature-gate-strict_provenance.stderr
@@ -4,10 +4,10 @@ warning: unknown lint: `fuzzy_provenance_casts`
LL | #![deny(fuzzy_provenance_casts)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unknown_lints)]` on by default
= note: the `fuzzy_provenance_casts` lint is unstable
= note: see issue #95228 <https://github.com/rust-lang/rust/issues/95228> for more information
= help: add `#![feature(strict_provenance)]` to the crate attributes to enable
+ = note: `#[warn(unknown_lints)]` on by default
warning: unknown lint: `lossy_provenance_casts`
--> $DIR/feature-gate-strict_provenance.rs:7:1
diff --git a/src/test/ui/feature-gates/feature-gate-test_unstable_lint.stderr b/src/test/ui/feature-gates/feature-gate-test_unstable_lint.stderr
index a29322443..b4d6aa658 100644
--- a/src/test/ui/feature-gates/feature-gate-test_unstable_lint.stderr
+++ b/src/test/ui/feature-gates/feature-gate-test_unstable_lint.stderr
@@ -4,9 +4,9 @@ warning: unknown lint: `test_unstable_lint`
LL | #![allow(test_unstable_lint)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unknown_lints)]` on by default
= note: the `test_unstable_lint` lint is unstable
= help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
+ = note: `#[warn(unknown_lints)]` on by default
warning: unknown lint: `test_unstable_lint`
--> $DIR/feature-gate-test_unstable_lint.rs:4:1
diff --git a/src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr b/src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr
index f94ec7d47..5a645cf4e 100644
--- a/src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr
+++ b/src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr
@@ -12,9 +12,9 @@ error: attribute must be of the form `#[inline]` or `#[inline(always|never)]`
LL | #[inline = "2100"] fn f() { }
| ^^^^^^^^^^^^^^^^^^
|
- = note: `#[deny(ill_formed_attribute_input)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
+ = note: `#[deny(ill_formed_attribute_input)]` on by default
error: `start` attribute can only be used on functions
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:119:1
diff --git a/src/test/ui/fmt/auxiliary/format-string-proc-macro.rs b/src/test/ui/fmt/auxiliary/format-string-proc-macro.rs
new file mode 100644
index 000000000..e44a84776
--- /dev/null
+++ b/src/test/ui/fmt/auxiliary/format-string-proc-macro.rs
@@ -0,0 +1,28 @@
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::{Literal, Span, TokenStream, TokenTree};
+
+#[proc_macro]
+pub fn foo_with_input_span(input: TokenStream) -> TokenStream {
+ let span = input.into_iter().next().unwrap().span();
+
+ let mut lit = Literal::string("{foo}");
+ lit.set_span(span);
+
+ TokenStream::from(TokenTree::Literal(lit))
+}
+
+#[proc_macro]
+pub fn err_with_input_span(input: TokenStream) -> TokenStream {
+ let span = input.into_iter().next().unwrap().span();
+
+ let mut lit = Literal::string(" }");
+ lit.set_span(span);
+
+ TokenStream::from(TokenTree::Literal(lit))
+}
diff --git a/src/test/ui/fmt/format-args-capture-issue-102057.rs b/src/test/ui/fmt/format-args-capture-issue-102057.rs
new file mode 100644
index 000000000..b8089d49b
--- /dev/null
+++ b/src/test/ui/fmt/format-args-capture-issue-102057.rs
@@ -0,0 +1,19 @@
+fn main() {
+ format!("\x7Ba}");
+ //~^ ERROR cannot find value `a` in this scope
+ format!("\x7Ba\x7D");
+ //~^ ERROR cannot find value `a` in this scope
+
+ let a = 0;
+
+ format!("\x7Ba} {b}");
+ //~^ ERROR cannot find value `b` in this scope
+ format!("\x7Ba\x7D {b}");
+ //~^ ERROR cannot find value `b` in this scope
+ format!("\x7Ba} \x7Bb}");
+ //~^ ERROR cannot find value `b` in this scope
+ format!("\x7Ba\x7D \x7Bb}");
+ //~^ ERROR cannot find value `b` in this scope
+ format!("\x7Ba\x7D \x7Bb\x7D");
+ //~^ ERROR cannot find value `b` in this scope
+}
diff --git a/src/test/ui/fmt/format-args-capture-issue-102057.stderr b/src/test/ui/fmt/format-args-capture-issue-102057.stderr
new file mode 100644
index 000000000..f2d625e7f
--- /dev/null
+++ b/src/test/ui/fmt/format-args-capture-issue-102057.stderr
@@ -0,0 +1,45 @@
+error[E0425]: cannot find value `a` in this scope
+ --> $DIR/format-args-capture-issue-102057.rs:2:18
+ |
+LL | format!("\x7Ba}");
+ | ^ not found in this scope
+
+error[E0425]: cannot find value `a` in this scope
+ --> $DIR/format-args-capture-issue-102057.rs:4:18
+ |
+LL | format!("\x7Ba\x7D");
+ | ^ not found in this scope
+
+error[E0425]: cannot find value `b` in this scope
+ --> $DIR/format-args-capture-issue-102057.rs:9:22
+ |
+LL | format!("\x7Ba} {b}");
+ | ^ help: a local variable with a similar name exists: `a`
+
+error[E0425]: cannot find value `b` in this scope
+ --> $DIR/format-args-capture-issue-102057.rs:11:25
+ |
+LL | format!("\x7Ba\x7D {b}");
+ | ^ help: a local variable with a similar name exists: `a`
+
+error[E0425]: cannot find value `b` in this scope
+ --> $DIR/format-args-capture-issue-102057.rs:13:25
+ |
+LL | format!("\x7Ba} \x7Bb}");
+ | ^ help: a local variable with a similar name exists: `a`
+
+error[E0425]: cannot find value `b` in this scope
+ --> $DIR/format-args-capture-issue-102057.rs:15:28
+ |
+LL | format!("\x7Ba\x7D \x7Bb}");
+ | ^ help: a local variable with a similar name exists: `a`
+
+error[E0425]: cannot find value `b` in this scope
+ --> $DIR/format-args-capture-issue-102057.rs:17:28
+ |
+LL | format!("\x7Ba\x7D \x7Bb\x7D");
+ | ^ help: a local variable with a similar name exists: `a`
+
+error: aborting due to 7 previous errors
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/fmt/format-args-capture-issue-93378.rs b/src/test/ui/fmt/format-args-capture-issue-93378.rs
index 674444442..9d722a028 100644
--- a/src/test/ui/fmt/format-args-capture-issue-93378.rs
+++ b/src/test/ui/fmt/format-args-capture-issue-93378.rs
@@ -3,9 +3,9 @@ fn main() {
let b = "b";
println!("{a} {b} {} {} {c} {}", c = "c");
- //~^ ERROR: invalid reference to positional arguments 1 and 2 (there is 1 argument)
+ //~^ ERROR: 3 positional arguments in format string, but there is 1 argument
let n = 1;
println!("{a:.n$} {b:.*}");
- //~^ ERROR: invalid reference to positional argument 0 (no arguments were given)
+ //~^ ERROR: 1 positional argument in format string, but no arguments were given
}
diff --git a/src/test/ui/fmt/format-args-capture-issue-93378.stderr b/src/test/ui/fmt/format-args-capture-issue-93378.stderr
index b8e2b2afb..6429b0d46 100644
--- a/src/test/ui/fmt/format-args-capture-issue-93378.stderr
+++ b/src/test/ui/fmt/format-args-capture-issue-93378.stderr
@@ -1,19 +1,14 @@
-error: invalid reference to positional arguments 1 and 2 (there is 1 argument)
- --> $DIR/format-args-capture-issue-93378.rs:5:26
+error: 3 positional arguments in format string, but there is 1 argument
+ --> $DIR/format-args-capture-issue-93378.rs:5:23
|
LL | println!("{a} {b} {} {} {c} {}", c = "c");
- | ^^ ^^
- |
- = note: positional arguments are zero-based
+ | ^^ ^^ ^^ ---
-error: invalid reference to positional argument 0 (no arguments were given)
- --> $DIR/format-args-capture-issue-93378.rs:9:23
+error: 1 positional argument in format string, but no arguments were given
+ --> $DIR/format-args-capture-issue-93378.rs:9:26
|
LL | println!("{a:.n$} {b:.*}");
- | - ^^^--^
- | | |
- | | this precision flag adds an extra required argument at position 0, which is why there are 3 arguments expected
- | this parameter corresponds to the precision flag
+ | ^^ this precision flag adds an extra required argument at position 0, which is why there is 1 argument expected
|
= note: positional arguments are zero-based
= note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
diff --git a/src/test/ui/fmt/format-args-capture-macro-hygiene.rs b/src/test/ui/fmt/format-args-capture-macro-hygiene.rs
index fdbd93836..b04f80ba4 100644
--- a/src/test/ui/fmt/format-args-capture-macro-hygiene.rs
+++ b/src/test/ui/fmt/format-args-capture-macro-hygiene.rs
@@ -1,4 +1,22 @@
+// aux-build:format-string-proc-macro.rs
+
+#[macro_use]
+extern crate format_string_proc_macro;
+
+macro_rules! def_site {
+ () => { "{foo}" } //~ ERROR: there is no argument named `foo`
+}
+
+macro_rules! call_site {
+ ($fmt:literal) => { $fmt }
+}
+
fn main() {
format!(concat!("{foo}")); //~ ERROR: there is no argument named `foo`
format!(concat!("{ba", "r} {}"), 1); //~ ERROR: there is no argument named `bar`
+
+ format!(def_site!());
+ format!(call_site!("{foo}")); //~ ERROR: there is no argument named `foo`
+
+ format!(foo_with_input_span!("")); //~ ERROR: there is no argument named `foo`
}
diff --git a/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr b/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr
index 9423e8c81..1b5fbd2af 100644
--- a/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr
+++ b/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr
@@ -1,5 +1,5 @@
error: there is no argument named `foo`
- --> $DIR/format-args-capture-macro-hygiene.rs:2:13
+ --> $DIR/format-args-capture-macro-hygiene.rs:15:13
|
LL | format!(concat!("{foo}"));
| ^^^^^^^^^^^^^^^^
@@ -9,7 +9,7 @@ LL | format!(concat!("{foo}"));
= note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info)
error: there is no argument named `bar`
- --> $DIR/format-args-capture-macro-hygiene.rs:3:13
+ --> $DIR/format-args-capture-macro-hygiene.rs:16:13
|
LL | format!(concat!("{ba", "r} {}"), 1);
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -18,5 +18,36 @@ LL | format!(concat!("{ba", "r} {}"), 1);
= note: to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro
= note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: aborting due to 2 previous errors
+error: there is no argument named `foo`
+ --> $DIR/format-args-capture-macro-hygiene.rs:7:13
+ |
+LL | () => { "{foo}" }
+ | ^^^^^^^
+...
+LL | format!(def_site!());
+ | ----------- in this macro invocation
+ |
+ = note: did you intend to capture a variable `foo` from the surrounding scope?
+ = note: to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro
+ = note: this error originates in the macro `def_site` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: there is no argument named `foo`
+ --> $DIR/format-args-capture-macro-hygiene.rs:19:24
+ |
+LL | format!(call_site!("{foo}"));
+ | ^^^^^^^
+ |
+ = note: did you intend to capture a variable `foo` from the surrounding scope?
+ = note: to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro
+
+error: there is no argument named `foo`
+ --> $DIR/format-args-capture-macro-hygiene.rs:21:34
+ |
+LL | format!(foo_with_input_span!(""));
+ | ^^
+ |
+ = note: did you intend to capture a variable `foo` from the surrounding scope?
+ = note: to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro
+
+error: aborting due to 5 previous errors
diff --git a/src/test/ui/fmt/format-concat-span.stderr b/src/test/ui/fmt/format-concat-span.stderr
deleted file mode 100644
index da46f40ab..000000000
--- a/src/test/ui/fmt/format-concat-span.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-error: invalid format string: unmatched `}` found
- --> $DIR/format-concat-span.rs:13:13
- |
-LL | format!(concat!("abc}"));
- | ^^^^^^^^^^^^^^^ unmatched `}` in format string
- |
- = note: if you intended to print `}`, you can escape it using `}}`
- = note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: aborting due to previous error
-
diff --git a/src/test/ui/fmt/format-concat-span.rs b/src/test/ui/fmt/format-expanded-string.rs
index ce92df0ad..4c716f08c 100644
--- a/src/test/ui/fmt/format-concat-span.rs
+++ b/src/test/ui/fmt/format-expanded-string.rs
@@ -1,3 +1,9 @@
+// aux-build:format-string-proc-macro.rs
+
+#[macro_use]
+extern crate format_string_proc_macro;
+
+
// If the format string is another macro invocation, rustc would previously
// compute nonsensical spans, such as:
//
@@ -12,4 +18,7 @@
fn main() {
format!(concat!("abc}"));
//~^ ERROR: invalid format string: unmatched `}` found
+
+ format!(err_with_input_span!(""));
+ //~^ ERROR: invalid format string: unmatched `}` found
}
diff --git a/src/test/ui/fmt/format-expanded-string.stderr b/src/test/ui/fmt/format-expanded-string.stderr
new file mode 100644
index 000000000..26ce7f269
--- /dev/null
+++ b/src/test/ui/fmt/format-expanded-string.stderr
@@ -0,0 +1,19 @@
+error: invalid format string: unmatched `}` found
+ --> $DIR/format-expanded-string.rs:19:13
+ |
+LL | format!(concat!("abc}"));
+ | ^^^^^^^^^^^^^^^ unmatched `}` in format string
+ |
+ = note: if you intended to print `}`, you can escape it using `}}`
+ = note: this error originates in the macro `concat` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: invalid format string: unmatched `}` found
+ --> $DIR/format-expanded-string.rs:22:34
+ |
+LL | format!(err_with_input_span!(""));
+ | ^^ unmatched `}` in format string
+ |
+ = note: if you intended to print `}`, you can escape it using `}}`
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/fmt/ifmt-bad-arg.rs b/src/test/ui/fmt/ifmt-bad-arg.rs
index f00cb05c9..68861d7bf 100644
--- a/src/test/ui/fmt/ifmt-bad-arg.rs
+++ b/src/test/ui/fmt/ifmt-bad-arg.rs
@@ -20,9 +20,9 @@ fn main() {
//~^ ERROR: invalid reference to positional argument 2 (there are 2 arguments)
format!("{} {value} {} {}", 1, value=2);
- //~^ ERROR: invalid reference to positional argument 2 (there are 2 arguments)
+ //~^ ERROR: 3 positional arguments in format string, but there are 2 arguments
format!("{name} {value} {} {} {} {} {} {}", 0, name=1, value=2);
- //~^ ERROR: invalid reference to positional arguments 3, 4 and 5 (there are 3 arguments)
+ //~^ ERROR: 6 positional arguments in format string, but there are 3 arguments
format!("{} {foo} {} {bar} {}", 1, 2, 3);
//~^ ERROR: cannot find value `foo` in this scope
@@ -79,7 +79,7 @@ tenth number: {}",
//~^ ERROR 4 positional arguments in format string, but there are 3 arguments
//~| ERROR mismatched types
println!("{} {:07$.*} {}", 1, 3.2, 4);
- //~^ ERROR 4 positional arguments in format string, but there are 3 arguments
+ //~^ ERROR invalid reference to positional arguments 3 and 7 (there are 3 arguments)
//~| ERROR mismatched types
println!("{} {:07$} {}", 1, 3.2, 4);
//~^ ERROR invalid reference to positional argument 7 (there are 3 arguments)
@@ -95,5 +95,5 @@ tenth number: {}",
println!("{:.*}");
//~^ ERROR 2 positional arguments in format string, but no arguments were given
println!("{:.0$}");
- //~^ ERROR 1 positional argument in format string, but no arguments were given
+ //~^ ERROR invalid reference to positional argument 0 (no arguments were given)
}
diff --git a/src/test/ui/fmt/ifmt-bad-arg.stderr b/src/test/ui/fmt/ifmt-bad-arg.stderr
index dbb4bc6d9..1b595a50e 100644
--- a/src/test/ui/fmt/ifmt-bad-arg.stderr
+++ b/src/test/ui/fmt/ifmt-bad-arg.stderr
@@ -5,10 +5,10 @@ LL | format!("{}");
| ^^
error: invalid reference to positional argument 1 (there is 1 argument)
- --> $DIR/ifmt-bad-arg.rs:9:14
+ --> $DIR/ifmt-bad-arg.rs:9:15
|
LL | format!("{1}", 1);
- | ^^^
+ | ^
|
= note: positional arguments are zero-based
@@ -27,36 +27,32 @@ LL | format!("{} {}");
| ^^ ^^
error: invalid reference to positional argument 1 (there is 1 argument)
- --> $DIR/ifmt-bad-arg.rs:16:18
+ --> $DIR/ifmt-bad-arg.rs:16:19
|
LL | format!("{0} {1}", 1);
- | ^^^
+ | ^
|
= note: positional arguments are zero-based
error: invalid reference to positional argument 2 (there are 2 arguments)
- --> $DIR/ifmt-bad-arg.rs:19:22
+ --> $DIR/ifmt-bad-arg.rs:19:23
|
LL | format!("{0} {1} {2}", 1, 2);
- | ^^^
+ | ^
|
= note: positional arguments are zero-based
-error: invalid reference to positional argument 2 (there are 2 arguments)
- --> $DIR/ifmt-bad-arg.rs:22:28
+error: 3 positional arguments in format string, but there are 2 arguments
+ --> $DIR/ifmt-bad-arg.rs:22:14
|
LL | format!("{} {value} {} {}", 1, value=2);
- | ^^
- |
- = note: positional arguments are zero-based
+ | ^^ ^^ ^^ - -
-error: invalid reference to positional arguments 3, 4 and 5 (there are 3 arguments)
- --> $DIR/ifmt-bad-arg.rs:24:38
+error: 6 positional arguments in format string, but there are 3 arguments
+ --> $DIR/ifmt-bad-arg.rs:24:29
|
LL | format!("{name} {value} {} {} {} {} {} {}", 0, name=1, value=2);
- | ^^ ^^ ^^
- |
- = note: positional arguments are zero-based
+ | ^^ ^^ ^^ ^^ ^^ ^^ - - -
error: multiple unused formatting arguments
--> $DIR/ifmt-bad-arg.rs:32:17
@@ -117,20 +113,20 @@ LL | format!("{} {}", 1, 2, foo=1, bar=2);
| multiple missing formatting specifiers
error: duplicate argument named `foo`
- --> $DIR/ifmt-bad-arg.rs:40:33
+ --> $DIR/ifmt-bad-arg.rs:40:29
|
LL | format!("{foo}", foo=1, foo=2);
- | - ^ duplicate argument
- | |
- | previously here
+ | --- ^^^ duplicate argument
+ | |
+ | previously here
error: positional arguments cannot follow named arguments
--> $DIR/ifmt-bad-arg.rs:41:35
|
LL | format!("{foo} {} {}", foo=1, 2);
- | - ^ positional arguments must be before named arguments
- | |
- | named argument
+ | ----- ^ positional arguments must be before named arguments
+ | |
+ | named argument
error: named argument never used
--> $DIR/ifmt-bad-arg.rs:45:51
@@ -191,33 +187,26 @@ error: 4 positional arguments in format string, but there are 3 arguments
|
LL | println!("{} {:.*} {}", 1, 3.2, 4);
| ^^ ^^--^ ^^ - --- -
- | | |
- | | this parameter corresponds to the precision flag
+ | |
| this precision flag adds an extra required argument at position 1, which is why there are 4 arguments expected
|
= note: positional arguments are zero-based
= note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
-error: 4 positional arguments in format string, but there are 3 arguments
- --> $DIR/ifmt-bad-arg.rs:81:15
+error: invalid reference to positional arguments 3 and 7 (there are 3 arguments)
+ --> $DIR/ifmt-bad-arg.rs:81:21
|
LL | println!("{} {:07$.*} {}", 1, 3.2, 4);
- | ^^ ^^^----^ ^^ - --- -
- | | | |
- | | | this parameter corresponds to the precision flag
- | | this precision flag adds an extra required argument at position 1, which is why there are 4 arguments expected
- | this width flag expects an `usize` argument at position 7, but there are 3 arguments
+ | ^^ ^
|
= note: positional arguments are zero-based
= note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
error: invalid reference to positional argument 7 (there are 3 arguments)
- --> $DIR/ifmt-bad-arg.rs:84:18
+ --> $DIR/ifmt-bad-arg.rs:84:21
|
LL | println!("{} {:07$} {}", 1, 3.2, 4);
- | ^^^--^
- | |
- | this width flag expects an `usize` argument at position 7, but there are 3 arguments
+ | ^^
|
= note: positional arguments are zero-based
= note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
@@ -240,24 +229,19 @@ LL | println!("{:foo}", 1);
- `X`, which uses the `UpperHex` trait
error: invalid reference to positional arguments 4, 5, 6 and 7 (there is 1 argument)
- --> $DIR/ifmt-bad-arg.rs:87:15
+ --> $DIR/ifmt-bad-arg.rs:87:16
|
LL | println!("{5} {:4$} {6:7$}", 1);
- | ^^^ ^^--^ ^^^--^
- | | |
- | | this width flag expects an `usize` argument at position 7, but there is 1 argument
- | this width flag expects an `usize` argument at position 4, but there is 1 argument
+ | ^ ^^ ^ ^^
|
= note: positional arguments are zero-based
= note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
error: invalid reference to positional argument 0 (no arguments were given)
- --> $DIR/ifmt-bad-arg.rs:90:15
+ --> $DIR/ifmt-bad-arg.rs:90:20
|
LL | println!("{foo:0$}");
- | ^^^^^--^
- | |
- | this width flag expects an `usize` argument at position 0, but no arguments were given
+ | ^^
|
= note: positional arguments are zero-based
= note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
@@ -273,13 +257,11 @@ LL | println!("{:.*}");
= note: positional arguments are zero-based
= note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
-error: 1 positional argument in format string, but no arguments were given
- --> $DIR/ifmt-bad-arg.rs:97:15
+error: invalid reference to positional argument 0 (no arguments were given)
+ --> $DIR/ifmt-bad-arg.rs:97:16
|
LL | println!("{:.0$}");
- | ^^---^
- | |
- | this precision flag expects an `usize` argument at position 0, but no arguments were given
+ | ^^^^
|
= note: positional arguments are zero-based
= note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
@@ -318,10 +300,10 @@ error[E0308]: mismatched types
--> $DIR/ifmt-bad-arg.rs:78:32
|
LL | println!("{} {:.*} {}", 1, 3.2, 4);
- | ---------------------------^^^----
- | | |
- | | expected `usize`, found floating-point number
- | arguments to this function are incorrect
+ | ^^^
+ | |
+ | expected `usize`, found floating-point number
+ | arguments to this function are incorrect
|
= note: expected reference `&usize`
found reference `&{float}`
@@ -336,10 +318,10 @@ error[E0308]: mismatched types
--> $DIR/ifmt-bad-arg.rs:81:35
|
LL | println!("{} {:07$.*} {}", 1, 3.2, 4);
- | ------------------------------^^^----
- | | |
- | | expected `usize`, found floating-point number
- | arguments to this function are incorrect
+ | ^^^
+ | |
+ | expected `usize`, found floating-point number
+ | arguments to this function are incorrect
|
= note: expected reference `&usize`
found reference `&{float}`
diff --git a/src/test/ui/for-loop-while/while-let-2.stderr b/src/test/ui/for-loop-while/while-let-2.stderr
index 2d23a6373..1b1cf6792 100644
--- a/src/test/ui/for-loop-while/while-let-2.stderr
+++ b/src/test/ui/for-loop-while/while-let-2.stderr
@@ -9,9 +9,9 @@ LL | | println!("irrefutable pattern");
LL | | });
| |______- in this macro invocation
|
- = note: `#[warn(irrefutable_let_patterns)]` on by default
= note: this pattern will always match, so the loop will never exit
= help: consider instead using a `loop { ... }` with a `let` inside it
+ = note: `#[warn(irrefutable_let_patterns)]` on by default
= note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: irrefutable `while let` pattern
diff --git a/src/test/ui/fully-qualified-type/fully-qualified-type-name2.stderr b/src/test/ui/fully-qualified-type/fully-qualified-type-name2.stderr
index aed7f72c6..a8f23f81d 100644
--- a/src/test/ui/fully-qualified-type/fully-qualified-type-name2.stderr
+++ b/src/test/ui/fully-qualified-type/fully-qualified-type-name2.stderr
@@ -5,6 +5,18 @@ LL | fn bar(x: x::Foo) -> y::Foo {
| ------ expected `y::Foo` because of return type
LL | return x;
| ^ expected enum `y::Foo`, found enum `x::Foo`
+ |
+ = note: enum `x::Foo` and enum `y::Foo` have similar names, but are actually distinct types
+note: enum `x::Foo` is defined in module `crate::x` of the current crate
+ --> $DIR/fully-qualified-type-name2.rs:4:5
+ |
+LL | pub enum Foo { }
+ | ^^^^^^^^^^^^
+note: enum `y::Foo` is defined in module `crate::y` of the current crate
+ --> $DIR/fully-qualified-type-name2.rs:8:5
+ |
+LL | pub enum Foo { }
+ | ^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/function-pointer/issue-102289.rs b/src/test/ui/function-pointer/issue-102289.rs
new file mode 100644
index 000000000..de394ca9a
--- /dev/null
+++ b/src/test/ui/function-pointer/issue-102289.rs
@@ -0,0 +1,54 @@
+// check-pass
+
+pub(crate) trait Parser: Sized {
+ type Output;
+ fn parse(&mut self, _input: &str) -> Result<(), ()> {
+ loop {}
+ }
+ fn map<F, B>(self, _f: F) -> Map<Self, F>
+ where
+ F: FnMut(Self::Output) -> B,
+ {
+ todo!()
+ }
+}
+
+pub(crate) struct Chainl1<P, Op>(P, Op);
+impl<P, Op> Parser for Chainl1<P, Op>
+where
+ P: Parser,
+ Op: Parser,
+ Op::Output: FnOnce(P::Output, P::Output) -> P::Output,
+{
+ type Output = P::Output;
+}
+pub(crate) fn chainl1<P, Op>(_parser: P, _op: Op) -> Chainl1<P, Op>
+where
+ P: Parser,
+ Op: Parser,
+ Op::Output: FnOnce(P::Output, P::Output) -> P::Output,
+{
+ loop {}
+}
+
+pub(crate) struct Map<P, F>(P, F);
+impl<A, B, P, F> Parser for Map<P, F>
+where
+ P: Parser<Output = A>,
+ F: FnMut(A) -> B,
+{
+ type Output = B;
+}
+
+impl Parser for u32 {
+ type Output = ();
+}
+
+pub fn chainl1_error_consume() {
+ fn first<T, U>(t: T, _: U) -> T {
+ t
+ }
+ let _ = chainl1(1, 1.map(|_| first)).parse("");
+}
+
+fn main() {}
diff --git a/src/test/ui/function-pointer/sized-ret-with-binder.rs b/src/test/ui/function-pointer/sized-ret-with-binder.rs
new file mode 100644
index 000000000..104ac4d22
--- /dev/null
+++ b/src/test/ui/function-pointer/sized-ret-with-binder.rs
@@ -0,0 +1,15 @@
+// check-pass
+
+#![feature(unboxed_closures)]
+
+fn is_fn<T: for<'a> Fn<(&'a (),)>>() {}
+fn is_fn2<T: for<'a, 'b> Fn<(&'a &'b (),)>>() {}
+
+struct Outlives<'a, 'b>(std::marker::PhantomData<&'a &'b ()>);
+
+fn main() {
+ is_fn::<for<'a> fn(&'a ()) -> &'a ()>();
+ is_fn::<for<'a> fn(&'a ()) -> &'a dyn std::fmt::Debug>();
+ is_fn2::<for<'a, 'b> fn(&'a &'b ()) -> Outlives<'a, 'b>>();
+ is_fn2::<for<'a, 'b> fn(&'a &'b ()) -> (&'a (), &'a ())>();
+}
diff --git a/src/test/ui/function-pointer/unsized-ret.rs b/src/test/ui/function-pointer/unsized-ret.rs
new file mode 100644
index 000000000..60af5769d
--- /dev/null
+++ b/src/test/ui/function-pointer/unsized-ret.rs
@@ -0,0 +1,14 @@
+#![feature(fn_traits)]
+#![feature(unboxed_closures)]
+
+fn foo<F: Fn<T>, T>(f: Option<F>, t: T) {
+ let y = (f.unwrap()).call(t);
+}
+
+fn main() {
+ foo::<fn() -> str, _>(None, ());
+ //~^ ERROR the size for values of type `str` cannot be known at compilation time
+
+ foo::<for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a), _>(None, (&(),));
+ //~^ ERROR the size for values of type `(dyn std::fmt::Display + 'a)` cannot be known at compilation time
+}
diff --git a/src/test/ui/function-pointer/unsized-ret.stderr b/src/test/ui/function-pointer/unsized-ret.stderr
new file mode 100644
index 000000000..bec3e2aa3
--- /dev/null
+++ b/src/test/ui/function-pointer/unsized-ret.stderr
@@ -0,0 +1,35 @@
+error[E0277]: the size for values of type `str` cannot be known at compilation time
+ --> $DIR/unsized-ret.rs:9:27
+ |
+LL | foo::<fn() -> str, _>(None, ());
+ | --------------------- ^^^^ doesn't have a size known at compile-time
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: within `fn() -> str`, the trait `Sized` is not implemented for `str`
+ = note: required because it appears within the type `fn() -> str`
+note: required by a bound in `foo`
+ --> $DIR/unsized-ret.rs:4:11
+ |
+LL | fn foo<F: Fn<T>, T>(f: Option<F>, t: T) {
+ | ^^^^^ required by this bound in `foo`
+
+error[E0277]: the size for values of type `(dyn std::fmt::Display + 'a)` cannot be known at compilation time
+ --> $DIR/unsized-ret.rs:12:66
+ |
+LL | foo::<for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a), _>(None, (&(),));
+ | ------------------------------------------------------------ ^^^^ doesn't have a size known at compile-time
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: within `for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a)`, the trait `for<'a> Sized` is not implemented for `(dyn std::fmt::Display + 'a)`
+ = note: required because it appears within the type `for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a)`
+note: required by a bound in `foo`
+ --> $DIR/unsized-ret.rs:4:11
+ |
+LL | fn foo<F: Fn<T>, T>(f: Option<F>, t: T) {
+ | ^^^^^ required by this bound in `foo`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/future-incompatible-lint-group.stderr b/src/test/ui/future-incompatible-lint-group.stderr
index 8f6dde665..a8fb100a7 100644
--- a/src/test/ui/future-incompatible-lint-group.stderr
+++ b/src/test/ui/future-incompatible-lint-group.stderr
@@ -4,9 +4,9 @@ warning: anonymous parameters are deprecated and will be removed in the next edi
LL | fn f(u8) {}
| ^^ help: try naming the parameter or explicitly ignoring it: `_: u8`
|
- = note: `#[warn(anonymous_parameters)]` on by default
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
+ = note: `#[warn(anonymous_parameters)]` on by default
error: this attribute can only be applied at the crate level
--> $DIR/future-incompatible-lint-group.rs:13:12
@@ -14,15 +14,15 @@ error: this attribute can only be applied at the crate level
LL | #![doc(test(some_test))]
| ^^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
+ = note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
note: the lint level is defined here
--> $DIR/future-incompatible-lint-group.rs:3:9
|
LL | #![deny(future_incompatible)]
| ^^^^^^^^^^^^^^^^^^^
= note: `#[deny(invalid_doc_attributes)]` implied by `#[deny(future_incompatible)]`
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
- = note: read <https://doc.rust-lang.org/nightly/rustdoc/the-doc-attribute.html#at-the-crate-level> for more information
error: aborting due to previous error; 1 warning emitted
diff --git a/src/test/ui/generator/issue-102645.rs b/src/test/ui/generator/issue-102645.rs
new file mode 100644
index 000000000..0589c5a00
--- /dev/null
+++ b/src/test/ui/generator/issue-102645.rs
@@ -0,0 +1,23 @@
+// compile-flags: -Zdrop-tracking
+
+#![feature(generators, generator_trait)]
+
+use std::ops::Generator;
+use std::pin::Pin;
+
+fn main() {
+ let mut a = 5;
+ let mut b = || {
+ let d = 6;
+ yield;
+ _zzz(); // #break
+ a = d;
+ };
+ Pin::new(&mut b).resume();
+ //~^ ERROR this function takes 1 argument but 0 arguments were supplied
+ // This type error is required to reproduce the ICE...
+}
+
+fn _zzz() {
+ ()
+}
diff --git a/src/test/ui/generator/issue-102645.stderr b/src/test/ui/generator/issue-102645.stderr
new file mode 100644
index 000000000..7b4d50213
--- /dev/null
+++ b/src/test/ui/generator/issue-102645.stderr
@@ -0,0 +1,19 @@
+error[E0061]: this function takes 1 argument but 0 arguments were supplied
+ --> $DIR/issue-102645.rs:16:22
+ |
+LL | Pin::new(&mut b).resume();
+ | ^^^^^^-- an argument of type `()` is missing
+ |
+note: associated function defined here
+ --> $SRC_DIR/core/src/ops/generator.rs:LL:COL
+ |
+LL | fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return>;
+ | ^^^^^^
+help: provide the argument
+ |
+LL | Pin::new(&mut b).resume(());
+ | ~~~~
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0061`.
diff --git a/src/test/ui/generator/issue-52398.stderr b/src/test/ui/generator/issue-52398.stderr
index 3f8ebb5a7..30a6732f7 100644
--- a/src/test/ui/generator/issue-52398.stderr
+++ b/src/test/ui/generator/issue-52398.stderr
@@ -6,8 +6,8 @@ LL | | A.test(yield);
LL | | };
| |______^
|
- = note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed
+ = note: `#[warn(unused_must_use)]` on by default
warning: unused generator that must be used
--> $DIR/issue-52398.rs:24:5
diff --git a/src/test/ui/generator/issue-57084.stderr b/src/test/ui/generator/issue-57084.stderr
index 32a04f94d..29aca9440 100644
--- a/src/test/ui/generator/issue-57084.stderr
+++ b/src/test/ui/generator/issue-57084.stderr
@@ -9,8 +9,8 @@ LL | | }
LL | | };
| |______^
|
- = note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed
+ = note: `#[warn(unused_must_use)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/generator/match-bindings.stderr b/src/test/ui/generator/match-bindings.stderr
index 4fd1e26f0..b911b6661 100644
--- a/src/test/ui/generator/match-bindings.stderr
+++ b/src/test/ui/generator/match-bindings.stderr
@@ -10,8 +10,8 @@ LL | | }
LL | | };
| |______^
|
- = note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed
+ = note: `#[warn(unused_must_use)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/generator/panic-drops-resume.rs b/src/test/ui/generator/panic-drops-resume.rs
index 8d8eb6a97..4c3caeb14 100644
--- a/src/test/ui/generator/panic-drops-resume.rs
+++ b/src/test/ui/generator/panic-drops-resume.rs
@@ -2,8 +2,6 @@
// run-pass
// needs-unwind
-// ignore-wasm no unwind support
-// ignore-emscripten no unwind support
#![feature(generators, generator_trait)]
diff --git a/src/test/ui/generator/panic-drops.rs b/src/test/ui/generator/panic-drops.rs
index a9de4e7fc..65001fd87 100644
--- a/src/test/ui/generator/panic-drops.rs
+++ b/src/test/ui/generator/panic-drops.rs
@@ -1,7 +1,6 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
#![feature(generators, generator_trait)]
diff --git a/src/test/ui/generator/panic-safe.rs b/src/test/ui/generator/panic-safe.rs
index 14a0c8dba..3db80bb58 100644
--- a/src/test/ui/generator/panic-safe.rs
+++ b/src/test/ui/generator/panic-safe.rs
@@ -1,7 +1,6 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
#![feature(generators, generator_trait)]
diff --git a/src/test/ui/generator/print/generator-print-verbose-1.stderr b/src/test/ui/generator/print/generator-print-verbose-1.stderr
index 3a83021dd..2e0207804 100644
--- a/src/test/ui/generator/print/generator-print-verbose-1.stderr
+++ b/src/test/ui/generator/print/generator-print-verbose-1.stderr
@@ -9,7 +9,7 @@ note: generator is not `Send` as this value is used across a yield
--> $DIR/generator-print-verbose-1.rs:35:9
|
LL | let _non_send_gen = make_non_send_generator();
- | ------------- has type `Opaque(DefId(0:34 ~ generator_print_verbose_1[749a]::make_non_send_generator::{opaque#0}), [])` which is not `Send`
+ | ------------- has type `Opaque(DefId(0:44 ~ generator_print_verbose_1[749a]::make_non_send_generator::{opaque#0}), [])` which is not `Send`
LL | yield;
| ^^^^^ yield occurs here, with `_non_send_gen` maybe used later
LL | };
@@ -35,17 +35,17 @@ note: required because it's used within this generator
|
LL | || {
| ^^
-note: required because it appears within the type `Opaque(DefId(0:39 ~ generator_print_verbose_1[749a]::make_gen2::{opaque#0}), [std::sync::Arc<std::cell::RefCell<i32>>])`
+note: required because it appears within the type `Opaque(DefId(0:45 ~ generator_print_verbose_1[749a]::make_gen2::{opaque#0}), [std::sync::Arc<std::cell::RefCell<i32>>])`
--> $DIR/generator-print-verbose-1.rs:41:30
|
LL | pub fn make_gen2<T>(t: T) -> impl Generator<Return = T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
-note: required because it appears within the type `Opaque(DefId(0:42 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`
+note: required because it appears within the type `Opaque(DefId(0:46 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`
--> $DIR/generator-print-verbose-1.rs:47:34
|
LL | fn make_non_send_generator2() -> impl Generator<Return = Arc<RefCell<i32>>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: required because it captures the following types: `Opaque(DefId(0:42 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`, `()`
+ = note: required because it captures the following types: `Opaque(DefId(0:46 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`, `()`
note: required because it's used within this generator
--> $DIR/generator-print-verbose-1.rs:52:20
|
diff --git a/src/test/ui/generator/reborrow-mut-upvar.stderr b/src/test/ui/generator/reborrow-mut-upvar.stderr
index ff511b766..e83dbf833 100644
--- a/src/test/ui/generator/reborrow-mut-upvar.stderr
+++ b/src/test/ui/generator/reborrow-mut-upvar.stderr
@@ -10,8 +10,8 @@ LL | | *bar = 2;
LL | | };
| |______^
|
- = note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed
+ = note: `#[warn(unused_must_use)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/generator/resume-after-return.rs b/src/test/ui/generator/resume-after-return.rs
index 538609b98..01a059a16 100644
--- a/src/test/ui/generator/resume-after-return.rs
+++ b/src/test/ui/generator/resume-after-return.rs
@@ -1,7 +1,6 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
#![feature(generators, generator_trait)]
diff --git a/src/test/ui/generator/size-moved-locals.rs b/src/test/ui/generator/size-moved-locals.rs
index 3c756a86f..601a31418 100644
--- a/src/test/ui/generator/size-moved-locals.rs
+++ b/src/test/ui/generator/size-moved-locals.rs
@@ -12,6 +12,7 @@
// edition:2018
// ignore-wasm32 issue #62807
// ignore-asmjs issue #62807
+// needs-unwind Size of Closures change on panic=abort
#![feature(generators, generator_trait)]
diff --git a/src/test/ui/generator/too-live-local-in-immovable-gen.stderr b/src/test/ui/generator/too-live-local-in-immovable-gen.stderr
index 72a2bd4eb..5cb43067f 100644
--- a/src/test/ui/generator/too-live-local-in-immovable-gen.stderr
+++ b/src/test/ui/generator/too-live-local-in-immovable-gen.stderr
@@ -10,8 +10,8 @@ LL | | let _ = &a;
LL | | };
| |__________^
|
- = note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed
+ = note: `#[warn(unused_must_use)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/generator/yield-in-args-rev.stderr b/src/test/ui/generator/yield-in-args-rev.stderr
index a575bf886..c9e1ab722 100644
--- a/src/test/ui/generator/yield-in-args-rev.stderr
+++ b/src/test/ui/generator/yield-in-args-rev.stderr
@@ -7,8 +7,8 @@ LL | | foo(yield, &b);
LL | | };
| |______^
|
- = note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed
+ = note: `#[warn(unused_must_use)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/generator/yield-in-box.stderr b/src/test/ui/generator/yield-in-box.stderr
index 7602e8039..8587e1dc6 100644
--- a/src/test/ui/generator/yield-in-box.stderr
+++ b/src/test/ui/generator/yield-in-box.stderr
@@ -10,8 +10,8 @@ LL | | }
LL | | };
| |______^
|
- = note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed
+ = note: `#[warn(unused_must_use)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/generator/yield-in-initializer.stderr b/src/test/ui/generator/yield-in-initializer.stderr
index e79047ae7..07de24662 100644
--- a/src/test/ui/generator/yield-in-initializer.stderr
+++ b/src/test/ui/generator/yield-in-initializer.stderr
@@ -10,8 +10,8 @@ LL | | }
LL | | };
| |______^
|
- = note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed
+ = note: `#[warn(unused_must_use)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/generator/yield-subtype.stderr b/src/test/ui/generator/yield-subtype.stderr
index bded36a4c..fe10477bf 100644
--- a/src/test/ui/generator/yield-subtype.stderr
+++ b/src/test/ui/generator/yield-subtype.stderr
@@ -7,8 +7,8 @@ LL | | yield b;
LL | | };
| |______^
|
- = note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed
+ = note: `#[warn(unused_must_use)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/generic-associated-types/bugs/issue-86218.stderr b/src/test/ui/generic-associated-types/bugs/issue-86218.stderr
deleted file mode 100644
index de1b464a4..000000000
--- a/src/test/ui/generic-associated-types/bugs/issue-86218.stderr
+++ /dev/null
@@ -1,23 +0,0 @@
-error[E0477]: the type `<() as Yay<&'a ()>>::InnerStream<'s>` does not fulfill the required lifetime
- --> $DIR/issue-86218.rs:22:28
- |
-LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
-note: type must outlive the lifetime `'s` as defined here as required by this binding
- --> $DIR/issue-86218.rs:22:22
- |
-LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
- | ^^
-
-error: unconstrained opaque type
- --> $DIR/issue-86218.rs:22:28
- |
-LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: `InnerStream` must be used in combination with a concrete type within the same module
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0477`.
diff --git a/src/test/ui/generic-associated-types/bugs/issue-88382.stderr b/src/test/ui/generic-associated-types/bugs/issue-88382.stderr
index c5fd58096..a9a70bb71 100644
--- a/src/test/ui/generic-associated-types/bugs/issue-88382.stderr
+++ b/src/test/ui/generic-associated-types/bugs/issue-88382.stderr
@@ -9,8 +9,8 @@ LL | do_something(SomeImplementation(), test);
LL | fn test<'a, I: Iterable>(_: &mut I::Iterator<'a>) {}
| ------------------------------------------------- found signature defined here
|
- = note: expected function signature `for<'r> fn(&'r mut std::iter::Empty<usize>) -> _`
- found function signature `for<'a, 'r> fn(&'r mut <_ as Iterable>::Iterator<'a>) -> _`
+ = note: expected function signature `for<'a> fn(&'a mut std::iter::Empty<usize>) -> _`
+ found function signature `for<'a, 'b> fn(&'b mut <_ as Iterable>::Iterator<'a>) -> _`
note: required by a bound in `do_something`
--> $DIR/issue-88382.rs:20:48
|
diff --git a/src/test/ui/generic-associated-types/bugs/issue-89008.stderr b/src/test/ui/generic-associated-types/bugs/issue-89008.stderr
deleted file mode 100644
index 3f72734ef..000000000
--- a/src/test/ui/generic-associated-types/bugs/issue-89008.stderr
+++ /dev/null
@@ -1,19 +0,0 @@
-error[E0271]: type mismatch resolving `<Empty<_> as Stream>::Item == Repr`
- --> $DIR/issue-89008.rs:38:43
- |
-LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {
- | ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<Empty<_> as Stream>::Item == Repr`
- | |
- | this type parameter
- |
-note: expected this to be `()`
- --> $DIR/issue-89008.rs:17:17
- |
-LL | type Item = ();
- | ^^
- = note: expected unit type `()`
- found type parameter `Repr`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0271`.
diff --git a/src/test/ui/generic-associated-types/bugs/issue-91762.rs b/src/test/ui/generic-associated-types/bugs/issue-91762.rs
index 796935cc0..dec668bec 100644
--- a/src/test/ui/generic-associated-types/bugs/issue-91762.rs
+++ b/src/test/ui/generic-associated-types/bugs/issue-91762.rs
@@ -1,7 +1,7 @@
// check-fail
// known-bug
-// We almost certaintly want this to pass, but
+// We almost certainly want this to pass, but
// it's particularly difficult currently, because we need a way of specifying
// that `<Self::Base as Functor>::With<T> = Self` without using that when we have
// a `U`. See `https://github.com/rust-lang/rust/pull/92728` for a (hacky)
diff --git a/src/test/ui/generic-associated-types/issue-102114.rs b/src/test/ui/generic-associated-types/issue-102114.rs
new file mode 100644
index 000000000..de31737ef
--- /dev/null
+++ b/src/test/ui/generic-associated-types/issue-102114.rs
@@ -0,0 +1,16 @@
+trait A {
+ type B<'b>;
+ fn a() -> Self::B<'static>;
+}
+
+struct C;
+
+struct Wrapper<T>(T);
+
+impl A for C {
+ type B<T> = Wrapper<T>;
+ //~^ ERROR type `B` has 1 type parameter but its trait declaration has 0 type parameters
+ fn a() -> Self::B<'static> {}
+}
+
+fn main() {}
diff --git a/src/test/ui/generic-associated-types/issue-102114.stderr b/src/test/ui/generic-associated-types/issue-102114.stderr
new file mode 100644
index 000000000..8e41dee54
--- /dev/null
+++ b/src/test/ui/generic-associated-types/issue-102114.stderr
@@ -0,0 +1,12 @@
+error[E0049]: type `B` has 1 type parameter but its trait declaration has 0 type parameters
+ --> $DIR/issue-102114.rs:11:12
+ |
+LL | type B<'b>;
+ | -- expected 0 type parameters
+...
+LL | type B<T> = Wrapper<T>;
+ | ^ found 1 type parameter
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0049`.
diff --git a/src/test/ui/generic-associated-types/issue-86218-2.rs b/src/test/ui/generic-associated-types/issue-86218-2.rs
new file mode 100644
index 000000000..63c839ea8
--- /dev/null
+++ b/src/test/ui/generic-associated-types/issue-86218-2.rs
@@ -0,0 +1,23 @@
+// check-pass
+
+#![feature(type_alias_impl_trait)]
+
+pub trait Stream {
+ type Item;
+}
+
+impl Stream for () {
+ type Item = i32;
+}
+
+trait Yay<AdditionalValue> {
+ type InnerStream<'s>: Stream<Item = i32> + 's;
+ fn foo<'s>() -> Self::InnerStream<'s>;
+}
+
+impl<T> Yay<T> for () {
+ type InnerStream<'s> = impl Stream<Item = i32> + 's;
+ fn foo<'s>() -> Self::InnerStream<'s> { () }
+}
+
+fn main() {}
diff --git a/src/test/ui/generic-associated-types/bugs/issue-86218.rs b/src/test/ui/generic-associated-types/issue-86218.rs
index 3a2d758e7..b2c3071f0 100644
--- a/src/test/ui/generic-associated-types/bugs/issue-86218.rs
+++ b/src/test/ui/generic-associated-types/issue-86218.rs
@@ -1,7 +1,4 @@
-// check-fail
-// known-bug: #86218
-
-// This should pass, but seems to run into a TAIT issue.
+// check-pass
#![feature(type_alias_impl_trait)]
@@ -20,7 +17,8 @@ trait Yay<AdditionalValue> {
impl<'a> Yay<&'a ()> for () {
type InnerStream<'s> = impl Stream<Item = i32> + 's;
- fn foo<'s>() -> Self::InnerStream<'s> { todo!() }
+ //^ ERROR does not fulfill the required lifetime
+ fn foo<'s>() -> Self::InnerStream<'s> { () }
}
fn main() {}
diff --git a/src/test/ui/generic-associated-types/issue-87258_a.stderr b/src/test/ui/generic-associated-types/issue-87258_a.stderr
index fa0748a28..eae9bd9b1 100644
--- a/src/test/ui/generic-associated-types/issue-87258_a.stderr
+++ b/src/test/ui/generic-associated-types/issue-87258_a.stderr
@@ -4,7 +4,7 @@ error: unconstrained opaque type
LL | type FooFuture<'a> = impl Trait1;
| ^^^^^^^^^^^
|
- = note: `FooFuture` must be used in combination with a concrete type within the same module
+ = note: `FooFuture` must be used in combination with a concrete type within the same impl
error: aborting due to previous error
diff --git a/src/test/ui/generic-associated-types/issue-87429-specialization.stderr b/src/test/ui/generic-associated-types/issue-87429-specialization.stderr
index d8e889aec..11c4ebf60 100644
--- a/src/test/ui/generic-associated-types/issue-87429-specialization.stderr
+++ b/src/test/ui/generic-associated-types/issue-87429-specialization.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0277]: can't compare `Foo` with `Foo`
--> $DIR/issue-87429-specialization.rs:20:31
diff --git a/src/test/ui/generic-associated-types/bugs/issue-89008.rs b/src/test/ui/generic-associated-types/issue-89008.rs
index 012aa8df2..669dbafb5 100644
--- a/src/test/ui/generic-associated-types/bugs/issue-89008.rs
+++ b/src/test/ui/generic-associated-types/issue-89008.rs
@@ -1,42 +1,36 @@
-// check-fail
+// check-pass
// edition:2021
-// known-bug: #88908
-
-// This should pass, but seems to run into a TAIT bug.
#![feature(type_alias_impl_trait)]
use std::future::Future;
+use std::marker::PhantomData;
trait Stream {
type Item;
}
-struct Empty<T>(T);
-impl<T> Stream for Empty<T> {
- type Item = ();
+struct Empty<T> {
+ _phantom: PhantomData<T>,
}
-fn empty<T>() -> Empty<T> {
- todo!()
+
+impl<T> Stream for Empty<T> {
+ type Item = T;
}
trait X {
type LineStream<'a, Repr>: Stream<Item = Repr> where Self: 'a;
-
- type LineStreamFut<'a,Repr>: Future<Output = Self::LineStream<'a, Repr>> where Self: 'a;
-
- fn line_stream<'a,Repr>(&'a self) -> Self::LineStreamFut<'a,Repr>;
+ type LineStreamFut<'a, Repr>: Future<Output = Self::LineStream<'a, Repr>> where Self: 'a;
+ fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr>;
}
struct Y;
impl X for Y {
type LineStream<'a, Repr> = impl Stream<Item = Repr>;
-
- type LineStreamFut<'a, Repr> = impl Future<Output = Self::LineStream<'a, Repr>> ;
-
+ type LineStreamFut<'a, Repr> = impl Future<Output = Self::LineStream<'a, Repr>>;
fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {
- async {empty()}
+ async { Empty { _phantom: PhantomData } }
}
}
diff --git a/src/test/ui/generics/issue-94923.rs b/src/test/ui/generics/issue-94923.rs
new file mode 100644
index 000000000..d337a5dff
--- /dev/null
+++ b/src/test/ui/generics/issue-94923.rs
@@ -0,0 +1,49 @@
+// run-pass
+// regression test for issue #94923
+// min-llvm-version: 15.0.0
+// compile-flags: -C opt-level=3
+
+fn f0<T>(mut x: usize) -> usize {
+ for _ in 0..1000 {
+ x *= 123;
+ x %= 99
+ }
+ x + 321 // function composition is not just longer iteration
+}
+
+fn f1<T>(x: usize) -> usize {
+ f0::<(i8, T)>(f0::<(u8, T)>(x))
+}
+
+fn f2<T>(x: usize) -> usize {
+ f1::<(i8, T)>(f1::<(u8, T)>(x))
+}
+
+fn f3<T>(x: usize) -> usize {
+ f2::<(i8, T)>(f2::<(u8, T)>(x))
+}
+
+fn f4<T>(x: usize) -> usize {
+ f3::<(i8, T)>(f3::<(u8, T)>(x))
+}
+
+fn f5<T>(x: usize) -> usize {
+ f4::<(i8, T)>(f4::<(u8, T)>(x))
+}
+
+fn f6<T>(x: usize) -> usize {
+ f5::<(i8, T)>(f5::<(u8, T)>(x))
+}
+
+fn f7<T>(x: usize) -> usize {
+ f6::<(i8, T)>(f6::<(u8, T)>(x))
+}
+
+fn f8<T>(x: usize) -> usize {
+ f7::<(i8, T)>(f7::<(u8, T)>(x))
+}
+
+fn main() {
+ let y = f8::<()>(1);
+ assert_eq!(y, 348);
+}
diff --git a/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.rs b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.rs
index 3f4c17836..b2e9ffb57 100644
--- a/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.rs
+++ b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.rs
@@ -1,4 +1,4 @@
-#![feature(half_open_range_patterns)]
+#![feature(half_open_range_patterns_in_slices)]
#![feature(exclusive_range_pattern)]
fn main() {
diff --git a/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.rs b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.rs
index dedc85491..20f4d8f88 100644
--- a/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.rs
+++ b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.rs
@@ -1,4 +1,4 @@
-#![feature(half_open_range_patterns)]
+#![feature(half_open_range_patterns_in_slices)]
#![feature(exclusive_range_pattern)]
fn main() {
diff --git a/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.rs b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.rs
index 6a9b562cc..14ca07d0a 100644
--- a/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.rs
+++ b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.rs
@@ -1,4 +1,3 @@
-#![feature(half_open_range_patterns)]
#![feature(exclusive_range_pattern)]
fn main() {
diff --git a/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.stderr b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.stderr
index 665eef2fc..790a13372 100644
--- a/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.stderr
+++ b/src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.stderr
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
- --> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:12
+ --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:12
|
LL | match [5..4, 99..105, 43..44] {
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
@@ -10,7 +10,7 @@ LL | [..9, 99..100, _] => {},
found type `{integer}`
error[E0308]: mismatched types
- --> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:15
+ --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:15
|
LL | match [5..4, 99..105, 43..44] {
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
@@ -23,7 +23,7 @@ LL | [..9, 99..100, _] => {},
found type `{integer}`
error[E0308]: mismatched types
- --> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:19
+ --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:19
|
LL | match [5..4, 99..105, 43..44] {
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
diff --git a/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns-in-slices.rs b/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns-in-slices.rs
new file mode 100644
index 000000000..dac973473
--- /dev/null
+++ b/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns-in-slices.rs
@@ -0,0 +1,7 @@
+#![feature(exclusive_range_pattern)]
+
+fn main() {
+ let xs = [13, 1, 5, 2, 3, 1, 21, 8];
+ let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
+ //~^ `X..` patterns in slices are experimental
+}
diff --git a/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns-in-slices.stderr b/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns-in-slices.stderr
new file mode 100644
index 000000000..ee5b0e11c
--- /dev/null
+++ b/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns-in-slices.stderr
@@ -0,0 +1,12 @@
+error[E0658]: `X..` patterns in slices are experimental
+ --> $DIR/feature-gate-half-open-range-patterns-in-slices.rs:5:10
+ |
+LL | let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
+ | ^^^^^^^
+ |
+ = note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
+ = help: add `#![feature(half_open_range_patterns_in_slices)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.rs b/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.rs
deleted file mode 100644
index 9281dda67..000000000
--- a/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-#![feature(exclusive_range_pattern)]
-
-fn main() {}
-
-#[cfg(FALSE)]
-fn foo() {
- if let ..=5 = 0 {}
- //~^ ERROR half-open range patterns are unstable
- if let ...5 = 0 {}
- //~^ ERROR half-open range patterns are unstable
- //~| ERROR range-to patterns with `...` are not allowed
- if let ..5 = 0 {}
- //~^ ERROR half-open range patterns are unstable
- if let 5..= = 0 {}
- //~^ ERROR inclusive range with no end
- if let 5... = 0 {}
- //~^ ERROR inclusive range with no end
-}
diff --git a/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.stderr b/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.stderr
deleted file mode 100644
index a04883ae1..000000000
--- a/src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.stderr
+++ /dev/null
@@ -1,53 +0,0 @@
-error: range-to patterns with `...` are not allowed
- --> $DIR/feature-gate-half-open-range-patterns.rs:9:12
- |
-LL | if let ...5 = 0 {}
- | ^^^ help: use `..=` instead
-
-error[E0586]: inclusive range with no end
- --> $DIR/feature-gate-half-open-range-patterns.rs:14:13
- |
-LL | if let 5..= = 0 {}
- | ^^^ help: use `..` instead
- |
- = note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
-
-error[E0586]: inclusive range with no end
- --> $DIR/feature-gate-half-open-range-patterns.rs:16:13
- |
-LL | if let 5... = 0 {}
- | ^^^ help: use `..` instead
- |
- = note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
-
-error[E0658]: half-open range patterns are unstable
- --> $DIR/feature-gate-half-open-range-patterns.rs:7:12
- |
-LL | if let ..=5 = 0 {}
- | ^^^^
- |
- = note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
- = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable
-
-error[E0658]: half-open range patterns are unstable
- --> $DIR/feature-gate-half-open-range-patterns.rs:9:12
- |
-LL | if let ...5 = 0 {}
- | ^^^^
- |
- = note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
- = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable
-
-error[E0658]: half-open range patterns are unstable
- --> $DIR/feature-gate-half-open-range-patterns.rs:12:12
- |
-LL | if let ..5 = 0 {}
- | ^^^
- |
- = note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
- = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable
-
-error: aborting due to 6 previous errors
-
-Some errors have detailed explanations: E0586, E0658.
-For more information about an error, try `rustc --explain E0586`.
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.rs
index b08732219..17ea2b13f 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.rs
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.rs
@@ -1,4 +1,3 @@
-#![feature(half_open_range_patterns)]
#![feature(exclusive_range_pattern)]
fn main() {
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.stderr
index df0dae569..f7c59a196 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.stderr
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.stderr
@@ -1,17 +1,17 @@
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/half-open-range-pats-bad-types.rs:5:9
+ --> $DIR/half-open-range-pats-bad-types.rs:4:9
|
LL | let "a".. = "a";
| ^^^ this is of type `&'static str` but it should be `char` or numeric
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/half-open-range-pats-bad-types.rs:6:11
+ --> $DIR/half-open-range-pats-bad-types.rs:5:11
|
LL | let .."a" = "a";
| ^^^ this is of type `&'static str` but it should be `char` or numeric
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/half-open-range-pats-bad-types.rs:7:12
+ --> $DIR/half-open-range-pats-bad-types.rs:6:12
|
LL | let ..="a" = "a";
| ^^^ this is of type `&'static str` but it should be `char` or numeric
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.rs
index be225359b..a2a4c62fa 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.rs
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.rs
@@ -1,6 +1,5 @@
// Test various non-exhaustive matches for `X..`, `..=X` and `..X` ranges.
-#![feature(half_open_range_patterns)]
#![feature(exclusive_range_pattern)]
#![allow(illegal_floating_point_literal_pattern)]
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 d429b4e8e..6b20a820b 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
@@ -1,5 +1,5 @@
error[E0004]: non-exhaustive patterns: `_` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:16:8
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:15:8
|
LL | m!(0f32, f32::NEG_INFINITY..);
| ^^^^ pattern `_` not covered
@@ -11,7 +11,7 @@ LL | match $s { $($t)+ => {}, _ => todo!() }
| ++++++++++++++
error[E0004]: non-exhaustive patterns: `_` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:17:8
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:16:8
|
LL | m!(0f32, ..f32::INFINITY);
| ^^^^ pattern `_` not covered
@@ -23,7 +23,7 @@ LL | match $s { $($t)+ => {}, _ => todo!() }
| ++++++++++++++
error[E0004]: non-exhaustive patterns: `'\u{10ffff}'` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:26:8
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:25:8
|
LL | m!('a', ..core::char::MAX);
| ^^^ pattern `'\u{10ffff}'` not covered
@@ -35,7 +35,7 @@ LL | match $s { $($t)+ => {}, '\u{10ffff}' => todo!() }
| +++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `'\u{10fffe}'..='\u{10ffff}'` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:27:8
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:26:8
|
LL | m!('a', ..ALMOST_MAX);
| ^^^ pattern `'\u{10fffe}'..='\u{10ffff}'` not covered
@@ -47,7 +47,7 @@ LL | match $s { $($t)+ => {}, '\u{10fffe}'..='\u{10ffff}' => todo!() }
| ++++++++++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `'\0'` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:28:8
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:27:8
|
LL | m!('a', ALMOST_MIN..);
| ^^^ pattern `'\0'` not covered
@@ -59,7 +59,7 @@ LL | match $s { $($t)+ => {}, '\0' => todo!() }
| +++++++++++++++++
error[E0004]: non-exhaustive patterns: `'\u{10ffff}'` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:29:8
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:28:8
|
LL | m!('a', ..=ALMOST_MAX);
| ^^^ pattern `'\u{10ffff}'` not covered
@@ -71,7 +71,7 @@ LL | match $s { $($t)+ => {}, '\u{10ffff}' => todo!() }
| +++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `'b'` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:30:8
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:29:8
|
LL | m!('a', ..=VAL | VAL_2..);
| ^^^ pattern `'b'` not covered
@@ -83,7 +83,7 @@ LL | match $s { $($t)+ => {}, 'b' => todo!() }
| ++++++++++++++++
error[E0004]: non-exhaustive patterns: `'b'` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:31:8
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:30:8
|
LL | m!('a', ..VAL_1 | VAL_2..);
| ^^^ pattern `'b'` not covered
@@ -95,7 +95,7 @@ LL | match $s { $($t)+ => {}, 'b' => todo!() }
| ++++++++++++++++
error[E0004]: non-exhaustive patterns: `u8::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:41:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:40:12
|
LL | m!(0, ..u8::MAX);
| ^ pattern `u8::MAX` not covered
@@ -107,7 +107,7 @@ LL | match $s { $($t)+ => {}, u8::MAX => todo!() }
| ++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `254_u8..=u8::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:42:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:41:12
|
LL | m!(0, ..ALMOST_MAX);
| ^ pattern `254_u8..=u8::MAX` not covered
@@ -119,7 +119,7 @@ LL | match $s { $($t)+ => {}, 254_u8..=u8::MAX => todo!() }
| +++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `0_u8` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:43:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:42:12
|
LL | m!(0, ALMOST_MIN..);
| ^ pattern `0_u8` not covered
@@ -131,7 +131,7 @@ LL | match $s { $($t)+ => {}, 0_u8 => todo!() }
| +++++++++++++++++
error[E0004]: non-exhaustive patterns: `u8::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:44:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:43:12
|
LL | m!(0, ..=ALMOST_MAX);
| ^ pattern `u8::MAX` not covered
@@ -143,7 +143,7 @@ LL | match $s { $($t)+ => {}, u8::MAX => todo!() }
| ++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_u8` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:45:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:44:12
|
LL | m!(0, ..=VAL | VAL_2..);
| ^ pattern `43_u8` not covered
@@ -155,7 +155,7 @@ LL | match $s { $($t)+ => {}, 43_u8 => todo!() }
| ++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_u8` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:46:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:45:12
|
LL | m!(0, ..VAL_1 | VAL_2..);
| ^ pattern `43_u8` not covered
@@ -167,7 +167,7 @@ LL | match $s { $($t)+ => {}, 43_u8 => todo!() }
| ++++++++++++++++++
error[E0004]: non-exhaustive patterns: `u16::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:54:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:53:12
|
LL | m!(0, ..u16::MAX);
| ^ pattern `u16::MAX` not covered
@@ -179,7 +179,7 @@ LL | match $s { $($t)+ => {}, u16::MAX => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `65534_u16..=u16::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:55:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:54:12
|
LL | m!(0, ..ALMOST_MAX);
| ^ pattern `65534_u16..=u16::MAX` not covered
@@ -191,7 +191,7 @@ LL | match $s { $($t)+ => {}, 65534_u16..=u16::MAX => todo!() }
| +++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `0_u16` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:56:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:55:12
|
LL | m!(0, ALMOST_MIN..);
| ^ pattern `0_u16` not covered
@@ -203,7 +203,7 @@ LL | match $s { $($t)+ => {}, 0_u16 => todo!() }
| ++++++++++++++++++
error[E0004]: non-exhaustive patterns: `u16::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:57:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:56:12
|
LL | m!(0, ..=ALMOST_MAX);
| ^ pattern `u16::MAX` not covered
@@ -215,7 +215,7 @@ LL | match $s { $($t)+ => {}, u16::MAX => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_u16` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:58:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:57:12
|
LL | m!(0, ..=VAL | VAL_2..);
| ^ pattern `43_u16` not covered
@@ -227,7 +227,7 @@ LL | match $s { $($t)+ => {}, 43_u16 => todo!() }
| +++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_u16` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:59:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:58:12
|
LL | m!(0, ..VAL_1 | VAL_2..);
| ^ pattern `43_u16` not covered
@@ -239,7 +239,7 @@ LL | match $s { $($t)+ => {}, 43_u16 => todo!() }
| +++++++++++++++++++
error[E0004]: non-exhaustive patterns: `u32::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:67:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:66:12
|
LL | m!(0, ..u32::MAX);
| ^ pattern `u32::MAX` not covered
@@ -251,7 +251,7 @@ LL | match $s { $($t)+ => {}, u32::MAX => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `4294967294_u32..=u32::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:68:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:67:12
|
LL | m!(0, ..ALMOST_MAX);
| ^ pattern `4294967294_u32..=u32::MAX` not covered
@@ -263,7 +263,7 @@ LL | match $s { $($t)+ => {}, 4294967294_u32..=u32::MAX => todo!() }
| ++++++++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `0_u32` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:69:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:68:12
|
LL | m!(0, ALMOST_MIN..);
| ^ pattern `0_u32` not covered
@@ -275,7 +275,7 @@ LL | match $s { $($t)+ => {}, 0_u32 => todo!() }
| ++++++++++++++++++
error[E0004]: non-exhaustive patterns: `u32::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:70:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:69:12
|
LL | m!(0, ..=ALMOST_MAX);
| ^ pattern `u32::MAX` not covered
@@ -287,7 +287,7 @@ LL | match $s { $($t)+ => {}, u32::MAX => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_u32` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:71:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:70:12
|
LL | m!(0, ..=VAL | VAL_2..);
| ^ pattern `43_u32` not covered
@@ -299,7 +299,7 @@ LL | match $s { $($t)+ => {}, 43_u32 => todo!() }
| +++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_u32` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:72:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:71:12
|
LL | m!(0, ..VAL_1 | VAL_2..);
| ^ pattern `43_u32` not covered
@@ -311,7 +311,7 @@ LL | match $s { $($t)+ => {}, 43_u32 => todo!() }
| +++++++++++++++++++
error[E0004]: non-exhaustive patterns: `u64::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:80:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:79:12
|
LL | m!(0, ..u64::MAX);
| ^ pattern `u64::MAX` not covered
@@ -323,7 +323,7 @@ LL | match $s { $($t)+ => {}, u64::MAX => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `18446744073709551614_u64..=u64::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:81:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:80:12
|
LL | m!(0, ..ALMOST_MAX);
| ^ pattern `18446744073709551614_u64..=u64::MAX` not covered
@@ -335,7 +335,7 @@ LL | match $s { $($t)+ => {}, 18446744073709551614_u64..=u64::MAX => tod
| ++++++++++++++++++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `0_u64` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:82:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:81:12
|
LL | m!(0, ALMOST_MIN..);
| ^ pattern `0_u64` not covered
@@ -347,7 +347,7 @@ LL | match $s { $($t)+ => {}, 0_u64 => todo!() }
| ++++++++++++++++++
error[E0004]: non-exhaustive patterns: `u64::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:83:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:82:12
|
LL | m!(0, ..=ALMOST_MAX);
| ^ pattern `u64::MAX` not covered
@@ -359,7 +359,7 @@ LL | match $s { $($t)+ => {}, u64::MAX => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_u64` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:84:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:83:12
|
LL | m!(0, ..=VAL | VAL_2..);
| ^ pattern `43_u64` not covered
@@ -371,7 +371,7 @@ LL | match $s { $($t)+ => {}, 43_u64 => todo!() }
| +++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_u64` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:85:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:84:12
|
LL | m!(0, ..VAL_1 | VAL_2..);
| ^ pattern `43_u64` not covered
@@ -383,7 +383,7 @@ LL | match $s { $($t)+ => {}, 43_u64 => todo!() }
| +++++++++++++++++++
error[E0004]: non-exhaustive patterns: `u128::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:93:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:92:12
|
LL | m!(0, ..u128::MAX);
| ^ pattern `u128::MAX` not covered
@@ -395,7 +395,7 @@ LL | match $s { $($t)+ => {}, u128::MAX => todo!() }
| ++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `340282366920938463463374607431768211454_u128..=u128::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:94:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:93:12
|
LL | m!(0, ..ALMOST_MAX);
| ^ pattern `340282366920938463463374607431768211454_u128..=u128::MAX` not covered
@@ -407,7 +407,7 @@ LL | match $s { $($t)+ => {}, 340282366920938463463374607431768211454_u1
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `0_u128` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:95:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:94:12
|
LL | m!(0, ALMOST_MIN..);
| ^ pattern `0_u128` not covered
@@ -419,7 +419,7 @@ LL | match $s { $($t)+ => {}, 0_u128 => todo!() }
| +++++++++++++++++++
error[E0004]: non-exhaustive patterns: `u128::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:96:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:95:12
|
LL | m!(0, ..=ALMOST_MAX);
| ^ pattern `u128::MAX` not covered
@@ -431,7 +431,7 @@ LL | match $s { $($t)+ => {}, u128::MAX => todo!() }
| ++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_u128` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:97:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:96:12
|
LL | m!(0, ..=VAL | VAL_2..);
| ^ pattern `43_u128` not covered
@@ -443,7 +443,7 @@ LL | match $s { $($t)+ => {}, 43_u128 => todo!() }
| ++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_u128` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:98:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:97:12
|
LL | m!(0, ..VAL_1 | VAL_2..);
| ^ pattern `43_u128` not covered
@@ -455,7 +455,7 @@ LL | match $s { $($t)+ => {}, 43_u128 => todo!() }
| ++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i8::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:109:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:108:12
|
LL | m!(0, ..i8::MAX);
| ^ pattern `i8::MAX` not covered
@@ -467,7 +467,7 @@ LL | match $s { $($t)+ => {}, i8::MAX => todo!() }
| ++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `126_i8..=i8::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:110:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:109:12
|
LL | m!(0, ..ALMOST_MAX);
| ^ pattern `126_i8..=i8::MAX` not covered
@@ -479,7 +479,7 @@ LL | match $s { $($t)+ => {}, 126_i8..=i8::MAX => todo!() }
| +++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i8::MIN` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:111:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:110:12
|
LL | m!(0, ALMOST_MIN..);
| ^ pattern `i8::MIN` not covered
@@ -491,7 +491,7 @@ LL | match $s { $($t)+ => {}, i8::MIN => todo!() }
| ++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i8::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:112:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:111:12
|
LL | m!(0, ..=ALMOST_MAX);
| ^ pattern `i8::MAX` not covered
@@ -503,7 +503,7 @@ LL | match $s { $($t)+ => {}, i8::MAX => todo!() }
| ++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_i8` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:113:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:112:12
|
LL | m!(0, ..=VAL | VAL_2..);
| ^ pattern `43_i8` not covered
@@ -515,7 +515,7 @@ LL | match $s { $($t)+ => {}, 43_i8 => todo!() }
| ++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_i8` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:114:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:113:12
|
LL | m!(0, ..VAL_1 | VAL_2..);
| ^ pattern `43_i8` not covered
@@ -527,7 +527,7 @@ LL | match $s { $($t)+ => {}, 43_i8 => todo!() }
| ++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i16::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:122:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:121:12
|
LL | m!(0, ..i16::MAX);
| ^ pattern `i16::MAX` not covered
@@ -539,7 +539,7 @@ LL | match $s { $($t)+ => {}, i16::MAX => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `32766_i16..=i16::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:123:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:122:12
|
LL | m!(0, ..ALMOST_MAX);
| ^ pattern `32766_i16..=i16::MAX` not covered
@@ -551,7 +551,7 @@ LL | match $s { $($t)+ => {}, 32766_i16..=i16::MAX => todo!() }
| +++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i16::MIN` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:124:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:123:12
|
LL | m!(0, ALMOST_MIN..);
| ^ pattern `i16::MIN` not covered
@@ -563,7 +563,7 @@ LL | match $s { $($t)+ => {}, i16::MIN => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i16::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:125:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:124:12
|
LL | m!(0, ..=ALMOST_MAX);
| ^ pattern `i16::MAX` not covered
@@ -575,7 +575,7 @@ LL | match $s { $($t)+ => {}, i16::MAX => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_i16` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:126:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:125:12
|
LL | m!(0, ..=VAL | VAL_2..);
| ^ pattern `43_i16` not covered
@@ -587,7 +587,7 @@ LL | match $s { $($t)+ => {}, 43_i16 => todo!() }
| +++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_i16` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:127:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:126:12
|
LL | m!(0, ..VAL_1 | VAL_2..);
| ^ pattern `43_i16` not covered
@@ -599,7 +599,7 @@ LL | match $s { $($t)+ => {}, 43_i16 => todo!() }
| +++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i32::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:135:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:134:12
|
LL | m!(0, ..i32::MAX);
| ^ pattern `i32::MAX` not covered
@@ -611,7 +611,7 @@ LL | match $s { $($t)+ => {}, i32::MAX => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `2147483646_i32..=i32::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:136:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:135:12
|
LL | m!(0, ..ALMOST_MAX);
| ^ pattern `2147483646_i32..=i32::MAX` not covered
@@ -623,7 +623,7 @@ LL | match $s { $($t)+ => {}, 2147483646_i32..=i32::MAX => todo!() }
| ++++++++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i32::MIN` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:137:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:136:12
|
LL | m!(0, ALMOST_MIN..);
| ^ pattern `i32::MIN` not covered
@@ -635,7 +635,7 @@ LL | match $s { $($t)+ => {}, i32::MIN => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i32::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:138:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:137:12
|
LL | m!(0, ..=ALMOST_MAX);
| ^ pattern `i32::MAX` not covered
@@ -647,7 +647,7 @@ LL | match $s { $($t)+ => {}, i32::MAX => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_i32` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:139:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:138:12
|
LL | m!(0, ..=VAL | VAL_2..);
| ^ pattern `43_i32` not covered
@@ -659,7 +659,7 @@ LL | match $s { $($t)+ => {}, 43_i32 => todo!() }
| +++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_i32` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:140:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:139:12
|
LL | m!(0, ..VAL_1 | VAL_2..);
| ^ pattern `43_i32` not covered
@@ -671,7 +671,7 @@ LL | match $s { $($t)+ => {}, 43_i32 => todo!() }
| +++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i64::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:148:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:147:12
|
LL | m!(0, ..i64::MAX);
| ^ pattern `i64::MAX` not covered
@@ -683,7 +683,7 @@ LL | match $s { $($t)+ => {}, i64::MAX => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `9223372036854775806_i64..=i64::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:149:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:148:12
|
LL | m!(0, ..ALMOST_MAX);
| ^ pattern `9223372036854775806_i64..=i64::MAX` not covered
@@ -695,7 +695,7 @@ LL | match $s { $($t)+ => {}, 9223372036854775806_i64..=i64::MAX => todo
| +++++++++++++++++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i64::MIN` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:150:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:149:12
|
LL | m!(0, ALMOST_MIN..);
| ^ pattern `i64::MIN` not covered
@@ -707,7 +707,7 @@ LL | match $s { $($t)+ => {}, i64::MIN => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i64::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:151:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:150:12
|
LL | m!(0, ..=ALMOST_MAX);
| ^ pattern `i64::MAX` not covered
@@ -719,7 +719,7 @@ LL | match $s { $($t)+ => {}, i64::MAX => todo!() }
| +++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_i64` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:152:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:151:12
|
LL | m!(0, ..=VAL | VAL_2..);
| ^ pattern `43_i64` not covered
@@ -731,7 +731,7 @@ LL | match $s { $($t)+ => {}, 43_i64 => todo!() }
| +++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_i64` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:153:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:152:12
|
LL | m!(0, ..VAL_1 | VAL_2..);
| ^ pattern `43_i64` not covered
@@ -743,7 +743,7 @@ LL | match $s { $($t)+ => {}, 43_i64 => todo!() }
| +++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i128::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:161:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:160:12
|
LL | m!(0, ..i128::MAX);
| ^ pattern `i128::MAX` not covered
@@ -755,7 +755,7 @@ LL | match $s { $($t)+ => {}, i128::MAX => todo!() }
| ++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `170141183460469231731687303715884105726_i128..=i128::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:162:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:161:12
|
LL | m!(0, ..ALMOST_MAX);
| ^ pattern `170141183460469231731687303715884105726_i128..=i128::MAX` not covered
@@ -767,7 +767,7 @@ LL | match $s { $($t)+ => {}, 170141183460469231731687303715884105726_i1
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i128::MIN` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:163:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:162:12
|
LL | m!(0, ALMOST_MIN..);
| ^ pattern `i128::MIN` not covered
@@ -779,7 +779,7 @@ LL | match $s { $($t)+ => {}, i128::MIN => todo!() }
| ++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `i128::MAX` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:164:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:163:12
|
LL | m!(0, ..=ALMOST_MAX);
| ^ pattern `i128::MAX` not covered
@@ -791,7 +791,7 @@ LL | match $s { $($t)+ => {}, i128::MAX => todo!() }
| ++++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_i128` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:165:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:164:12
|
LL | m!(0, ..=VAL | VAL_2..);
| ^ pattern `43_i128` not covered
@@ -803,7 +803,7 @@ LL | match $s { $($t)+ => {}, 43_i128 => todo!() }
| ++++++++++++++++++++
error[E0004]: non-exhaustive patterns: `43_i128` not covered
- --> $DIR/half-open-range-pats-exhaustive-fail.rs:166:12
+ --> $DIR/half-open-range-pats-exhaustive-fail.rs:165:12
|
LL | m!(0, ..VAL_1 | VAL_2..);
| ^ pattern `43_i128` not covered
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-pass.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-pass.rs
index d3a59e4df..4b7eee134 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-pass.rs
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-pass.rs
@@ -2,7 +2,6 @@
// Test various exhaustive matches for `X..`, `..=X` and `..X` ranges.
-#![feature(half_open_range_patterns)]
#![feature(exclusive_range_pattern)]
fn main() {}
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs
index daed775cf..526a797e9 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs
@@ -7,8 +7,6 @@
// there's a potential confusion factor here, and we would prefer to keep patterns
// and expressions in-sync. As such, we do not allow `...X` in patterns either.
-#![feature(half_open_range_patterns)]
-
fn main() {}
#[cfg(FALSE)]
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr
index da37ff301..ddffeaf97 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr
@@ -1,29 +1,29 @@
error: range-to patterns with `...` are not allowed
- --> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:17:9
+ --> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:15:9
|
LL | ...X => {}
| ^^^ help: use `..=` instead
error: range-to patterns with `...` are not allowed
- --> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:18:9
+ --> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:16:9
|
LL | ...0 => {}
| ^^^ help: use `..=` instead
error: range-to patterns with `...` are not allowed
- --> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:19:9
+ --> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:17:9
|
LL | ...'a' => {}
| ^^^ help: use `..=` instead
error: range-to patterns with `...` are not allowed
- --> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:20:9
+ --> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:18:9
|
LL | ...0.0f32 => {}
| ^^^ help: use `..=` instead
error: range-to patterns with `...` are not allowed
- --> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:27:17
+ --> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:25:17
|
LL | let ...$e;
| ^^^ help: use `..=` instead
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.rs
index 9ace0c357..6567c8cc6 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.rs
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.rs
@@ -1,8 +1,6 @@
// Test `X...` and `X..=` range patterns not being allowed syntactically.
// FIXME(Centril): perhaps these should be semantic restrictions.
-#![feature(half_open_range_patterns)]
-
fn main() {}
#[cfg(FALSE)]
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr
index 5a504a90b..3ad84b0ef 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr
@@ -1,5 +1,5 @@
error[E0586]: inclusive range with no end
- --> $DIR/half-open-range-pats-inclusive-no-end.rs:10:13
+ --> $DIR/half-open-range-pats-inclusive-no-end.rs:8:13
|
LL | if let 0... = 1 {}
| ^^^ help: use `..` instead
@@ -7,7 +7,7 @@ LL | if let 0... = 1 {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error[E0586]: inclusive range with no end
- --> $DIR/half-open-range-pats-inclusive-no-end.rs:11:13
+ --> $DIR/half-open-range-pats-inclusive-no-end.rs:9:13
|
LL | if let 0..= = 1 {}
| ^^^ help: use `..` instead
@@ -15,7 +15,7 @@ LL | if let 0..= = 1 {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error[E0586]: inclusive range with no end
- --> $DIR/half-open-range-pats-inclusive-no-end.rs:13:13
+ --> $DIR/half-open-range-pats-inclusive-no-end.rs:11:13
|
LL | if let X... = 1 {}
| ^^^ help: use `..` instead
@@ -23,7 +23,7 @@ LL | if let X... = 1 {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error[E0586]: inclusive range with no end
- --> $DIR/half-open-range-pats-inclusive-no-end.rs:14:13
+ --> $DIR/half-open-range-pats-inclusive-no-end.rs:12:13
|
LL | if let X..= = 1 {}
| ^^^ help: use `..` instead
@@ -31,7 +31,7 @@ LL | if let X..= = 1 {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error[E0586]: inclusive range with no end
- --> $DIR/half-open-range-pats-inclusive-no-end.rs:20:19
+ --> $DIR/half-open-range-pats-inclusive-no-end.rs:18:19
|
LL | let $e...;
| ^^^ help: use `..` instead
@@ -43,7 +43,7 @@ LL | mac!(0);
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0586]: inclusive range with no end
- --> $DIR/half-open-range-pats-inclusive-no-end.rs:21:19
+ --> $DIR/half-open-range-pats-inclusive-no-end.rs:19:19
|
LL | let $e..=;
| ^^^ help: use `..` instead
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.rs
index f054bbea4..2d63fe078 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.rs
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.rs
@@ -1,5 +1,3 @@
-#![feature(half_open_range_patterns)]
-
fn main() {}
#[cfg(FALSE)]
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.stderr
index 93b73c57e..111e81799 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.stderr
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-ref-ambiguous-interp.stderr
@@ -1,11 +1,11 @@
error: the range pattern here has ambiguous interpretation
- --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:8:10
+ --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:6:10
|
LL | &0.. | _ => {}
| ^^^ help: add parentheses to clarify the precedence: `(0..)`
error[E0586]: inclusive range with no end
- --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:10:11
+ --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:8:11
|
LL | &0..= | _ => {}
| ^^^ help: use `..` instead
@@ -13,13 +13,13 @@ LL | &0..= | _ => {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error: the range pattern here has ambiguous interpretation
- --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:10:10
+ --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:8:10
|
LL | &0..= | _ => {}
| ^^^^ help: add parentheses to clarify the precedence: `(0..=)`
error[E0586]: inclusive range with no end
- --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:13:11
+ --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:11:11
|
LL | &0... | _ => {}
| ^^^ help: use `..` instead
@@ -27,25 +27,25 @@ LL | &0... | _ => {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error: the range pattern here has ambiguous interpretation
- --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:18:10
+ --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:16:10
|
LL | &..0 | _ => {}
| ^^^ help: add parentheses to clarify the precedence: `(..0)`
error: the range pattern here has ambiguous interpretation
- --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:20:10
+ --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:18:10
|
LL | &..=0 | _ => {}
| ^^^^ help: add parentheses to clarify the precedence: `(..=0)`
error: range-to patterns with `...` are not allowed
- --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:22:10
+ --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:20:10
|
LL | &...0 | _ => {}
| ^^^ help: use `..=` instead
error: the range pattern here has ambiguous interpretation
- --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:22:10
+ --> $DIR/half-open-range-pats-ref-ambiguous-interp.rs:20:10
|
LL | &...0 | _ => {}
| ^^^^ help: add parentheses to clarify the precedence: `(..=0)`
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-semantics.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-semantics.rs
index ae532d935..6c6ba9319 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-semantics.rs
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-semantics.rs
@@ -3,7 +3,6 @@
// Test half-open range patterns against their expression equivalents
// via `.contains(...)` and make sure the dynamic semantics match.
-#![feature(half_open_range_patterns)]
#![feature(exclusive_range_pattern)]
#![allow(illegal_floating_point_literal_pattern)]
#![allow(unreachable_patterns)]
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-syntactic-pass.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-syntactic-pass.rs
index 8bb98d3b5..9a73e8906 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-syntactic-pass.rs
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-syntactic-pass.rs
@@ -3,7 +3,6 @@
// Test the parsing of half-open ranges.
#![feature(exclusive_range_pattern)]
-#![feature(half_open_range_patterns)]
fn main() {}
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.rs
index 2c8e554b2..f55566602 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.rs
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.rs
@@ -1,4 +1,3 @@
-#![feature(half_open_range_patterns)]
#![feature(exclusive_range_pattern)]
#![allow(illegal_floating_point_literal_pattern)]
diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.stderr
index 4931ddfac..56b224a85 100644
--- a/src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.stderr
+++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.stderr
@@ -1,155 +1,155 @@
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:12:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:11:11
|
LL | m!(0, ..u8::MIN);
| ^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:15:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:14:11
|
LL | m!(0, ..u16::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:18:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:17:11
|
LL | m!(0, ..u32::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:21:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:20:11
|
LL | m!(0, ..u64::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:24:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:23:11
|
LL | m!(0, ..u128::MIN);
| ^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:28:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:27:11
|
LL | m!(0, ..i8::MIN);
| ^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:31:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:30:11
|
LL | m!(0, ..i16::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:34:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:33:11
|
LL | m!(0, ..i32::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:37:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:36:11
|
LL | m!(0, ..i64::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:40:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:39:11
|
LL | m!(0, ..i128::MIN);
| ^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:44:14
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:43:14
|
LL | m!(0f32, ..f32::NEG_INFINITY);
| ^^^^^^^^^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:47:14
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:46:14
|
LL | m!(0f64, ..f64::NEG_INFINITY);
| ^^^^^^^^^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:51:13
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:50:13
|
LL | m!('a', ..'\u{0}');
| ^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:12:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:11:11
|
LL | m!(0, ..u8::MIN);
| ^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:15:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:14:11
|
LL | m!(0, ..u16::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:18:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:17:11
|
LL | m!(0, ..u32::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:21:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:20:11
|
LL | m!(0, ..u64::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:24:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:23:11
|
LL | m!(0, ..u128::MIN);
| ^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:28:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:27:11
|
LL | m!(0, ..i8::MIN);
| ^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:31:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:30:11
|
LL | m!(0, ..i16::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:34:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:33:11
|
LL | m!(0, ..i32::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:37:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:36:11
|
LL | m!(0, ..i64::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:40:11
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:39:11
|
LL | m!(0, ..i128::MIN);
| ^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:44:14
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:43:14
|
LL | m!(0f32, ..f32::NEG_INFINITY);
| ^^^^^^^^^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:47:14
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:46:14
|
LL | m!(0f64, ..f64::NEG_INFINITY);
| ^^^^^^^^^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
- --> $DIR/half-open-range-pats-thir-lower-empty.rs:51:13
+ --> $DIR/half-open-range-pats-thir-lower-empty.rs:50:13
|
LL | m!('a', ..'\u{0}');
| ^^^^^^^^^
diff --git a/src/test/ui/half-open-range-patterns/pat-tuple-4.rs b/src/test/ui/half-open-range-patterns/pat-tuple-4.rs
index bd7953682..11c4ab9c5 100644
--- a/src/test/ui/half-open-range-patterns/pat-tuple-4.rs
+++ b/src/test/ui/half-open-range-patterns/pat-tuple-4.rs
@@ -1,6 +1,5 @@
// check-pass
-#![feature(half_open_range_patterns)]
#![feature(exclusive_range_pattern)]
fn main() {
diff --git a/src/test/ui/half-open-range-patterns/pat-tuple-5.rs b/src/test/ui/half-open-range-patterns/pat-tuple-5.rs
index 613d907cf..995ef03c8 100644
--- a/src/test/ui/half-open-range-patterns/pat-tuple-5.rs
+++ b/src/test/ui/half-open-range-patterns/pat-tuple-5.rs
@@ -1,4 +1,3 @@
-#![feature(half_open_range_patterns)]
#![feature(exclusive_range_pattern)]
fn main() {
diff --git a/src/test/ui/half-open-range-patterns/pat-tuple-5.stderr b/src/test/ui/half-open-range-patterns/pat-tuple-5.stderr
index 307ad711b..c60842638 100644
--- a/src/test/ui/half-open-range-patterns/pat-tuple-5.stderr
+++ b/src/test/ui/half-open-range-patterns/pat-tuple-5.stderr
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
- --> $DIR/pat-tuple-5.rs:8:10
+ --> $DIR/pat-tuple-5.rs:7:10
|
LL | match (0, 1) {
| ------ this expression has type `({integer}, {integer})`
diff --git a/src/test/ui/half-open-range-patterns/range_pat_interactions0.rs b/src/test/ui/half-open-range-patterns/range_pat_interactions0.rs
index 8f745e810..acb7feac1 100644
--- a/src/test/ui/half-open-range-patterns/range_pat_interactions0.rs
+++ b/src/test/ui/half-open-range-patterns/range_pat_interactions0.rs
@@ -1,7 +1,6 @@
// run-pass
#![allow(incomplete_features)]
#![feature(exclusive_range_pattern)]
-#![feature(half_open_range_patterns)]
#![feature(inline_const_pat)]
fn main() {
diff --git a/src/test/ui/half-open-range-patterns/range_pat_interactions3.rs b/src/test/ui/half-open-range-patterns/range_pat_interactions3.rs
index 41c7e46df..446ed45f9 100644
--- a/src/test/ui/half-open-range-patterns/range_pat_interactions3.rs
+++ b/src/test/ui/half-open-range-patterns/range_pat_interactions3.rs
@@ -16,8 +16,7 @@ fn main() {
//~| exclusive range pattern syntax is experimental
y @ -5.. => range_from.push(y),
y @ ..-7 => assert_eq!(y, -8),
- //~^ half-open range patterns are unstable
- //~| exclusive range pattern syntax is experimental
+ //~^ exclusive range pattern syntax is experimental
y => bottom.push(y),
}
}
diff --git a/src/test/ui/half-open-range-patterns/range_pat_interactions3.stderr b/src/test/ui/half-open-range-patterns/range_pat_interactions3.stderr
index 5e36996a4..f7fda6775 100644
--- a/src/test/ui/half-open-range-patterns/range_pat_interactions3.stderr
+++ b/src/test/ui/half-open-range-patterns/range_pat_interactions3.stderr
@@ -1,12 +1,3 @@
-error[E0658]: half-open range patterns are unstable
- --> $DIR/range_pat_interactions3.rs:18:17
- |
-LL | y @ ..-7 => assert_eq!(y, -8),
- | ^^^^
- |
- = note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
- = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable
-
error[E0658]: inline-const in pattern position is experimental
--> $DIR/range_pat_interactions3.rs:14:20
|
@@ -52,6 +43,6 @@ LL | y @ ..-7 => assert_eq!(y, -8),
= note: see issue #37854 <https://github.com/rust-lang/rust/issues/37854> for more information
= help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable
-error: aborting due to 6 previous errors
+error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem0.rs b/src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem0.rs
index 2884a2734..d54cbfbf4 100644
--- a/src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem0.rs
+++ b/src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem0.rs
@@ -1,4 +1,4 @@
-#![feature(half_open_range_patterns)]
+#![feature(half_open_range_patterns_in_slices)]
#![feature(exclusive_range_pattern)]
fn main() {
diff --git a/src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem1.rs b/src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem1.rs
index 9e289b591..c37af75b8 100644
--- a/src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem1.rs
+++ b/src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem1.rs
@@ -3,7 +3,6 @@ fn main() {
let xs = [13, 1, 5, 2, 3, 1, 21, 8];
let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
//~^ `X..` patterns in slices are experimental
- //~| half-open range patterns are unstable
//~| exclusive range pattern syntax is experimental
//~| exclusive range pattern syntax is experimental
}
diff --git a/src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem1.stderr b/src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem1.stderr
index eadaf8776..3bca554b1 100644
--- a/src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem1.stderr
+++ b/src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem1.stderr
@@ -1,12 +1,3 @@
-error[E0658]: half-open range patterns are unstable
- --> $DIR/slice_pattern_syntax_problem1.rs:4:23
- |
-LL | let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
- | ^^^
- |
- = note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
- = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable
-
error[E0658]: `X..` patterns in slices are experimental
--> $DIR/slice_pattern_syntax_problem1.rs:4:10
|
@@ -14,7 +5,7 @@ LL | let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
| ^^^^^^^
|
= note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
- = help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable
+ = help: add `#![feature(half_open_range_patterns_in_slices)]` to the crate attributes to enable
error[E0658]: exclusive range pattern syntax is experimental
--> $DIR/slice_pattern_syntax_problem1.rs:4:23
@@ -34,6 +25,6 @@ LL | let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
= note: see issue #37854 <https://github.com/rust-lang/rust/issues/37854> for more information
= help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable
-error: aborting due to 4 previous errors
+error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/higher-rank-trait-bounds/hrtb-perfect-forwarding.stderr b/src/test/ui/higher-rank-trait-bounds/hrtb-perfect-forwarding.stderr
index 5e75a4cc8..727b9e6be 100644
--- a/src/test/ui/higher-rank-trait-bounds/hrtb-perfect-forwarding.stderr
+++ b/src/test/ui/higher-rank-trait-bounds/hrtb-perfect-forwarding.stderr
@@ -9,8 +9,8 @@ LL | | T: Bar<&'b isize>,
LL | no_hrtb(&mut t);
| --------------- recursive call site
|
- = note: `#[warn(unconditional_recursion)]` on by default
= help: a `loop` may express intention better if this is on purpose
+ = note: `#[warn(unconditional_recursion)]` on by default
warning: function cannot return without recursing
--> $DIR/hrtb-perfect-forwarding.rs:25:1
diff --git a/src/test/ui/higher-rank-trait-bounds/issue-100689.rs b/src/test/ui/higher-rank-trait-bounds/issue-100689.rs
new file mode 100644
index 000000000..2db7f8a35
--- /dev/null
+++ b/src/test/ui/higher-rank-trait-bounds/issue-100689.rs
@@ -0,0 +1,29 @@
+// check-pass
+
+struct Foo<'a> {
+ foo: &'a mut usize,
+}
+
+trait Bar<'a> {
+ type FooRef<'b>
+ where
+ 'a: 'b;
+ fn uwu(foo: Foo<'a>, f: impl for<'b> FnMut(Self::FooRef<'b>));
+}
+impl<'a> Bar<'a> for () {
+ type FooRef<'b>
+ =
+ &'b Foo<'a>
+ where
+ 'a : 'b,
+ ;
+
+ fn uwu(
+ foo: Foo<'a>,
+ mut f: impl for<'b> FnMut(&'b Foo<'a>), //relevant part
+ ) {
+ f(&foo);
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/higher-rank-trait-bounds/issue-102899.rs b/src/test/ui/higher-rank-trait-bounds/issue-102899.rs
new file mode 100644
index 000000000..952b81584
--- /dev/null
+++ b/src/test/ui/higher-rank-trait-bounds/issue-102899.rs
@@ -0,0 +1,32 @@
+// check-pass
+
+pub trait BufferTrait<'buffer> {
+ type Subset<'channel>
+ where
+ 'buffer: 'channel;
+
+ fn for_each_subset<F>(&self, f: F)
+ where
+ F: for<'channel> Fn(Self::Subset<'channel>);
+}
+
+pub struct SomeBuffer<'buffer> {
+ samples: &'buffer [()],
+}
+
+impl<'buffer> BufferTrait<'buffer> for SomeBuffer<'buffer> {
+ type Subset<'subset> = Subset<'subset> where 'buffer: 'subset;
+
+ fn for_each_subset<F>(&self, _f: F)
+ where
+ F: for<'subset> Fn(Subset<'subset>),
+ {
+ todo!()
+ }
+}
+
+pub struct Subset<'subset> {
+ buffer: &'subset [()],
+}
+
+fn main() {}
diff --git a/src/test/ui/higher-rank-trait-bounds/issue-30786.stderr b/src/test/ui/higher-rank-trait-bounds/issue-30786.stderr
index ffe3d7b81..c1e235441 100644
--- a/src/test/ui/higher-rank-trait-bounds/issue-30786.stderr
+++ b/src/test/ui/higher-rank-trait-bounds/issue-30786.stderr
@@ -19,7 +19,7 @@ note: the following trait bounds were not satisfied:
LL | impl<T> StreamExt for T where for<'a> &'a mut T: Stream {}
| --------- - ^^^^^^ unsatisfied trait bound introduced here
-error[E0599]: the method `countx` exists for struct `Filter<Map<Repeat, for<'r> fn(&'r u64) -> &'r u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>`, but its trait bounds were not satisfied
+error[E0599]: the method `countx` exists for struct `Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>`, but its trait bounds were not satisfied
--> $DIR/issue-30786.rs:130:24
|
LL | pub struct Filter<S, F> {
@@ -29,12 +29,12 @@ LL | pub struct Filter<S, F> {
| doesn't satisfy `_: StreamExt`
...
LL | let count = filter.countx();
- | ^^^^^^ method cannot be called on `Filter<Map<Repeat, for<'r> fn(&'r u64) -> &'r u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>` due to unsatisfied trait bounds
+ | ^^^^^^ method cannot be called on `Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>` due to unsatisfied trait bounds
|
note: the following trait bounds were not satisfied:
- `&'a mut &Filter<Map<Repeat, for<'r> fn(&'r u64) -> &'r u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream`
- `&'a mut &mut Filter<Map<Repeat, for<'r> fn(&'r u64) -> &'r u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream`
- `&'a mut Filter<Map<Repeat, for<'r> fn(&'r u64) -> &'r u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream`
+ `&'a mut &Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream`
+ `&'a mut &mut Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream`
+ `&'a mut Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream`
--> $DIR/issue-30786.rs:96:50
|
LL | impl<T> StreamExt for T where for<'a> &'a mut T: Stream {}
diff --git a/src/test/ui/higher-rank-trait-bounds/issue-46989.stderr b/src/test/ui/higher-rank-trait-bounds/issue-46989.stderr
index 309e1a676..3f874220a 100644
--- a/src/test/ui/higher-rank-trait-bounds/issue-46989.stderr
+++ b/src/test/ui/higher-rank-trait-bounds/issue-46989.stderr
@@ -4,7 +4,7 @@ error: implementation of `Foo` is not general enough
LL | assert_foo::<fn(&i32)>();
| ^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
|
- = note: `Foo` would have to be implemented for the type `for<'r> fn(&'r i32)`
+ = note: `Foo` would have to be implemented for the type `for<'a> fn(&'a i32)`
= note: ...but `Foo` is actually implemented for the type `fn(&'0 i32)`, for some specific lifetime `'0`
error: aborting due to previous error
diff --git a/src/test/ui/higher-rank-trait-bounds/issue-95034.rs b/src/test/ui/higher-rank-trait-bounds/issue-95034.rs
index d8edbe7e5..af4946a18 100644
--- a/src/test/ui/higher-rank-trait-bounds/issue-95034.rs
+++ b/src/test/ui/higher-rank-trait-bounds/issue-95034.rs
@@ -1,23 +1,5 @@
-// known-bug: #95034
-// failure-status: 101
+// check-pass
// compile-flags: --edition=2021 --crate-type=lib
-// rustc-env:RUST_BACKTRACE=0
-
-// normalize-stderr-test "thread 'rustc' panicked.*" -> "thread 'rustc' panicked"
-// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> ""
-// normalize-stderr-test "\nerror: internal compiler error.*\n\n" -> ""
-// normalize-stderr-test "note:.*unexpectedly panicked.*\n\n" -> ""
-// normalize-stderr-test "note: we would appreciate a bug report.*\n\n" -> ""
-// normalize-stderr-test "note: compiler flags.*\n\n" -> ""
-// normalize-stderr-test "note: rustc.*running on.*\n\n" -> ""
-// normalize-stderr-test "query stack during panic:\n" -> ""
-// normalize-stderr-test "we're just showing a limited slice of the query stack\n" -> ""
-// normalize-stderr-test "end of query stack\n" -> ""
-// normalize-stderr-test "#.*\n" -> ""
-
-// This should not ICE.
-
-// Refer to the issue for more minimized versions.
use std::{
future::Future,
diff --git a/src/test/ui/higher-rank-trait-bounds/issue-95034.stderr b/src/test/ui/higher-rank-trait-bounds/issue-95034.stderr
deleted file mode 100644
index 1d8329142..000000000
--- a/src/test/ui/higher-rank-trait-bounds/issue-95034.stderr
+++ /dev/null
@@ -1 +0,0 @@
-thread 'rustc' panicked
diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-71955.stderr b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-71955.stderr
index eebce827d..4ef96cd95 100644
--- a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-71955.stderr
+++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-71955.stderr
@@ -4,8 +4,8 @@ error[E0308]: mismatched types
LL | foo(bar, "string", |s| s.len() == 5);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
- = note: expected trait `for<'r, 's> FnOnce<(&'r &'s str,)>`
- found trait `for<'r> FnOnce<(&'r &str,)>`
+ = note: expected trait `for<'a, 'b> FnOnce<(&'a &'b str,)>`
+ found trait `for<'a> FnOnce<(&'a &str,)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/issue-71955.rs:45:24
|
@@ -23,8 +23,8 @@ error[E0308]: mismatched types
LL | foo(bar, "string", |s| s.len() == 5);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
- = note: expected trait `for<'r, 's> FnOnce<(&'r &'s str,)>`
- found trait `for<'r> FnOnce<(&'r &str,)>`
+ = note: expected trait `for<'a, 'b> FnOnce<(&'a &'b str,)>`
+ found trait `for<'a> FnOnce<(&'a &str,)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/issue-71955.rs:45:24
|
@@ -42,8 +42,8 @@ error[E0308]: mismatched types
LL | foo(baz, "string", |s| s.0.len() == 5);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
- = note: expected trait `for<'r, 's> FnOnce<(&'r Wrapper<'s>,)>`
- found trait `for<'r> FnOnce<(&'r Wrapper<'_>,)>`
+ = note: expected trait `for<'a, 'b> FnOnce<(&'a Wrapper<'b>,)>`
+ found trait `for<'a> FnOnce<(&'a Wrapper<'_>,)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/issue-71955.rs:48:24
|
@@ -61,8 +61,8 @@ error[E0308]: mismatched types
LL | foo(baz, "string", |s| s.0.len() == 5);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
- = note: expected trait `for<'r, 's> FnOnce<(&'r Wrapper<'s>,)>`
- found trait `for<'r> FnOnce<(&'r Wrapper<'_>,)>`
+ = note: expected trait `for<'a, 'b> FnOnce<(&'a Wrapper<'b>,)>`
+ found trait `for<'a> FnOnce<(&'a Wrapper<'_>,)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/issue-71955.rs:48:24
|
diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.rs b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.rs
index de9348f53..c10a0888a 100644
--- a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.rs
+++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.rs
@@ -6,7 +6,7 @@ trait SomeTrait<'a> {
fn give_me_ice<T>() {
callee::<fn(&()) -> <T as SomeTrait<'_>>::Associated>();
- //~^ ERROR the trait bound `for<'r> T: SomeTrait<'r>` is not satisfied [E0277]
+ //~^ ERROR the trait bound `for<'a> T: SomeTrait<'a>` is not satisfied [E0277]
}
fn callee<T: Fn<(&'static (),)>>() {
diff --git a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.stderr b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.stderr
index 6a948a116..25a4f6088 100644
--- a/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.stderr
+++ b/src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.stderr
@@ -1,12 +1,12 @@
-error[E0277]: the trait bound `for<'r> T: SomeTrait<'r>` is not satisfied
+error[E0277]: the trait bound `for<'a> T: SomeTrait<'a>` is not satisfied
--> $DIR/issue-85455.rs:8:5
|
LL | callee::<fn(&()) -> <T as SomeTrait<'_>>::Associated>();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'r> SomeTrait<'r>` is not implemented for `T`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> SomeTrait<'a>` is not implemented for `T`
|
help: consider restricting type parameter `T`
|
-LL | fn give_me_ice<T: for<'r> SomeTrait<'r>>() {
+LL | fn give_me_ice<T: for<'a> SomeTrait<'a>>() {
| +++++++++++++++++++++++
error: aborting due to previous error
diff --git a/src/test/ui/hygiene/globs.stderr b/src/test/ui/hygiene/globs.stderr
index bcfcc28ad..1f2a96a4c 100644
--- a/src/test/ui/hygiene/globs.stderr
+++ b/src/test/ui/hygiene/globs.stderr
@@ -1,9 +1,16 @@
error[E0425]: cannot find function `f` in this scope
--> $DIR/globs.rs:22:9
|
+LL | pub fn g() {}
+ | ---------- similarly named function `g` defined here
+...
LL | f();
- | ^ not found in this scope
+ | ^
+ |
+help: a function with a similar name exists
|
+LL | g();
+ | ~
help: consider importing this function
|
LL | use foo::f;
@@ -12,8 +19,11 @@ LL | use foo::f;
error[E0425]: cannot find function `g` in this scope
--> $DIR/globs.rs:15:5
|
+LL | pub fn f() {}
+ | ---------- similarly named function `f` defined here
+...
LL | g();
- | ^ not found in this scope
+ | ^
...
LL | / m! {
LL | | use bar::*;
@@ -23,6 +33,10 @@ LL | | }
| |_____- in this macro invocation
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: a function with a similar name exists
+ |
+LL | f();
+ | ~
help: consider importing this function
|
LL | use bar::g;
diff --git a/src/test/ui/hygiene/impl_items-2.rs b/src/test/ui/hygiene/impl_items-2.rs
new file mode 100644
index 000000000..465e444ae
--- /dev/null
+++ b/src/test/ui/hygiene/impl_items-2.rs
@@ -0,0 +1,26 @@
+#![feature(decl_macro)]
+
+trait Trait {
+ fn foo() {}
+}
+
+macro trait_impl() {
+ fn foo() {}
+}
+
+// Check that we error on multiple impl items that resolve to the same trait item.
+impl Trait for i32 {
+ trait_impl!();
+ fn foo() {}
+ //~^ ERROR duplicate definitions with name `foo`: [E0201]
+}
+
+struct Type;
+
+// Check that we do not error with inherent impls.
+impl Type {
+ trait_impl!();
+ fn foo() {}
+}
+
+fn main() {}
diff --git a/src/test/ui/hygiene/impl_items-2.stderr b/src/test/ui/hygiene/impl_items-2.stderr
new file mode 100644
index 000000000..3c0ffeb10
--- /dev/null
+++ b/src/test/ui/hygiene/impl_items-2.stderr
@@ -0,0 +1,15 @@
+error[E0201]: duplicate definitions with name `foo`:
+ --> $DIR/impl_items-2.rs:14:5
+ |
+LL | fn foo() {}
+ | ----------- item in trait
+...
+LL | fn foo() {}
+ | ----------- previous definition here
+...
+LL | fn foo() {}
+ | ^^^^^^^^^^^ duplicate definition
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0201`.
diff --git a/src/test/ui/hygiene/impl_items.rs b/src/test/ui/hygiene/impl_items.rs
index 37794c6e0..ddb25c06b 100644
--- a/src/test/ui/hygiene/impl_items.rs
+++ b/src/test/ui/hygiene/impl_items.rs
@@ -9,7 +9,7 @@ mod foo {
}
pub macro m() {
- let _: () = S.f(); //~ ERROR type `for<'r> fn(&'r foo::S) {foo::S::f}` is private
+ let _: () = S.f(); //~ ERROR type `for<'a> fn(&'a foo::S) {foo::S::f}` is private
}
}
diff --git a/src/test/ui/hygiene/impl_items.stderr b/src/test/ui/hygiene/impl_items.stderr
index 523309f43..46a250038 100644
--- a/src/test/ui/hygiene/impl_items.stderr
+++ b/src/test/ui/hygiene/impl_items.stderr
@@ -1,4 +1,4 @@
-error: type `for<'r> fn(&'r foo::S) {foo::S::f}` is private
+error: type `for<'a> fn(&'a foo::S) {foo::S::f}` is private
--> $DIR/impl_items.rs:12:23
|
LL | let _: () = S.f();
diff --git a/src/test/ui/hygiene/rustc-macro-transparency.stderr b/src/test/ui/hygiene/rustc-macro-transparency.stderr
index 17d05dd09..1d2a1e124 100644
--- a/src/test/ui/hygiene/rustc-macro-transparency.stderr
+++ b/src/test/ui/hygiene/rustc-macro-transparency.stderr
@@ -19,14 +19,8 @@ LL | semitransparent;
error[E0423]: expected value, found macro `opaque`
--> $DIR/rustc-macro-transparency.rs:30:5
|
-LL | struct Opaque;
- | -------------- similarly named unit struct `Opaque` defined here
-...
LL | opaque;
- | ^^^^^^
- | |
- | not a value
- | help: a unit struct with a similar name exists (notice the capitalization): `Opaque`
+ | ^^^^^^ not a value
error: aborting due to 3 previous errors
diff --git a/src/test/ui/impl-duplicate-methods.stderr b/src/test/ui/impl-duplicate-methods.stderr
deleted file mode 100644
index c19702a5b..000000000
--- a/src/test/ui/impl-duplicate-methods.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-error[E0201]: duplicate definitions with name `orange`:
- --> $DIR/impl-duplicate-methods.rs:5:5
- |
-LL | fn orange(&self) {}
- | ---------------- previous definition of `orange` here
-LL | fn orange(&self) {}
- | ^^^^^^^^^^^^^^^^ duplicate definition
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0201`.
diff --git a/src/test/ui/impl-trait/auto-trait-leak.stderr b/src/test/ui/impl-trait/auto-trait-leak.stderr
index b6e283647..feedfc40a 100644
--- a/src/test/ui/impl-trait/auto-trait-leak.stderr
+++ b/src/test/ui/impl-trait/auto-trait-leak.stderr
@@ -9,12 +9,12 @@ note: ...which requires borrow-checking `cycle1`...
|
LL | fn cycle1() -> impl Clone {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires processing `cycle1`...
+note: ...which requires processing MIR for `cycle1`...
--> $DIR/auto-trait-leak.rs:12:1
|
LL | fn cycle1() -> impl Clone {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires processing MIR for `cycle1`...
+note: ...which requires preparing `cycle1` for borrow checking...
--> $DIR/auto-trait-leak.rs:12:1
|
LL | fn cycle1() -> impl Clone {
@@ -50,12 +50,12 @@ note: ...which requires borrow-checking `cycle2`...
|
LL | fn cycle2() -> impl Clone {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires processing `cycle2`...
+note: ...which requires processing MIR for `cycle2`...
--> $DIR/auto-trait-leak.rs:19:1
|
LL | fn cycle2() -> impl Clone {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires processing MIR for `cycle2`...
+note: ...which requires preparing `cycle2` for borrow checking...
--> $DIR/auto-trait-leak.rs:19:1
|
LL | fn cycle2() -> impl Clone {
diff --git a/src/test/ui/impl-trait/equality-rpass.stderr b/src/test/ui/impl-trait/equality-rpass.stderr
index 11eeceba0..bde8362fd 100644
--- a/src/test/ui/impl-trait/equality-rpass.stderr
+++ b/src/test/ui/impl-trait/equality-rpass.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/impl-trait/equality.stderr b/src/test/ui/impl-trait/equality.stderr
index d4a349551..1841b8e5d 100644
--- a/src/test/ui/impl-trait/equality.stderr
+++ b/src/test/ui/impl-trait/equality.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> $DIR/equality.rs:15:5
diff --git a/src/test/ui/impl-trait/equality2.stderr b/src/test/ui/impl-trait/equality2.stderr
index 46053c6e7..e399a6102 100644
--- a/src/test/ui/impl-trait/equality2.stderr
+++ b/src/test/ui/impl-trait/equality2.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> $DIR/equality2.rs:25:18
diff --git a/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2015.stderr b/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2015.stderr
index fd2e454e7..edf3911e2 100644
--- a/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2015.stderr
+++ b/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2015.stderr
@@ -1,8 +1,8 @@
-error[E0277]: the trait bound `(): AsRef<(dyn for<'r> Fn(&'r ()) + 'static)>` is not satisfied
+error[E0277]: the trait bound `(): AsRef<(dyn for<'a> Fn(&'a ()) + 'static)>` is not satisfied
--> $DIR/generic-with-implicit-hrtb-without-dyn.rs:6:13
|
LL | fn ice() -> impl AsRef<Fn(&())> {
- | ^^^^^^^^^^^^^^^^^^^ the trait `AsRef<(dyn for<'r> Fn(&'r ()) + 'static)>` is not implemented for `()`
+ | ^^^^^^^^^^^^^^^^^^^ the trait `AsRef<(dyn for<'a> Fn(&'a ()) + 'static)>` is not implemented for `()`
error: aborting due to previous error
diff --git a/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2021.stderr b/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2021.stderr
index 8f4092273..88e2520bf 100644
--- a/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2021.stderr
+++ b/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2021.stderr
@@ -9,11 +9,11 @@ help: add `dyn` keyword before this trait
LL | fn ice() -> impl AsRef<dyn Fn(&())> {
| +++
-error[E0277]: the trait bound `(): AsRef<(dyn for<'r> Fn(&'r ()) + 'static)>` is not satisfied
+error[E0277]: the trait bound `(): AsRef<(dyn for<'a> Fn(&'a ()) + 'static)>` is not satisfied
--> $DIR/generic-with-implicit-hrtb-without-dyn.rs:6:13
|
LL | fn ice() -> impl AsRef<Fn(&())> {
- | ^^^^^^^^^^^^^^^^^^^ the trait `AsRef<(dyn for<'r> Fn(&'r ()) + 'static)>` is not implemented for `()`
+ | ^^^^^^^^^^^^^^^^^^^ the trait `AsRef<(dyn for<'a> Fn(&'a ()) + 'static)>` is not implemented for `()`
error: aborting due to 2 previous errors
diff --git a/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rs b/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rs
index 856dc7a3f..5a922697f 100644
--- a/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rs
+++ b/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.rs
@@ -4,7 +4,7 @@
#![allow(warnings)]
fn ice() -> impl AsRef<Fn(&())> {
- //~^ ERROR: the trait bound `(): AsRef<(dyn for<'r> Fn(&'r ()) + 'static)>` is not satisfied [E0277]
+ //~^ ERROR: the trait bound `(): AsRef<(dyn for<'a> Fn(&'a ()) + 'static)>` is not satisfied [E0277]
//[edition2021]~| ERROR: trait objects must include the `dyn` keyword [E0782]
todo!()
}
diff --git a/src/test/ui/impl-trait/hidden-lifetimes.stderr b/src/test/ui/impl-trait/hidden-lifetimes.stderr
index efc228de5..3cc47e1e8 100644
--- a/src/test/ui/impl-trait/hidden-lifetimes.stderr
+++ b/src/test/ui/impl-trait/hidden-lifetimes.stderr
@@ -1,4 +1,4 @@
-error[E0700]: hidden type for `impl Swap` captures lifetime that does not appear in bounds
+error[E0700]: hidden type for `impl Swap + 'a` captures lifetime that does not appear in bounds
--> $DIR/hidden-lifetimes.rs:29:5
|
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
@@ -6,12 +6,12 @@ LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
LL | x
| ^
|
-help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
+help: to declare that `impl Swap + 'a` captures `'b`, you can add an explicit `'b` lifetime bound
|
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + 'b {
| ++++
-error[E0700]: hidden type for `impl Swap` captures lifetime that does not appear in bounds
+error[E0700]: hidden type for `impl Swap + 'a` captures lifetime that does not appear in bounds
--> $DIR/hidden-lifetimes.rs:46:5
|
LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
@@ -19,7 +19,7 @@ LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl S
LL | x
| ^
|
-help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
+help: to declare that `impl Swap + 'a` captures `'b`, you can add an explicit `'b` lifetime bound
|
LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a + 'b {
| ++++
diff --git a/src/test/ui/impl-trait/in-trait/auxiliary/rpitit.rs b/src/test/ui/impl-trait/in-trait/auxiliary/rpitit.rs
new file mode 100644
index 000000000..74df300f8
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/auxiliary/rpitit.rs
@@ -0,0 +1,11 @@
+#![feature(return_position_impl_trait_in_trait)]
+
+pub trait Foo {
+ fn bar() -> impl Sized;
+}
+
+pub struct Foreign;
+
+impl Foo for Foreign {
+ fn bar() {}
+}
diff --git a/src/test/ui/impl-trait/in-trait/default-body-type-err-2.rs b/src/test/ui/impl-trait/in-trait/default-body-type-err-2.rs
new file mode 100644
index 000000000..45ae2b8ad
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/default-body-type-err-2.rs
@@ -0,0 +1,13 @@
+// edition:2021
+
+#![allow(incomplete_features)]
+#![feature(async_fn_in_trait)]
+
+pub trait Foo {
+ async fn woopsie_async(&self) -> String {
+ 42
+ //~^ ERROR mismatched types
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/in-trait/default-body-type-err-2.stderr b/src/test/ui/impl-trait/in-trait/default-body-type-err-2.stderr
new file mode 100644
index 000000000..142b1bff1
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/default-body-type-err-2.stderr
@@ -0,0 +1,11 @@
+error[E0308]: mismatched types
+ --> $DIR/default-body-type-err-2.rs:8:9
+ |
+LL | 42
+ | ^^- help: try using a conversion method: `.to_string()`
+ | |
+ | expected struct `String`, found integer
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/impl-trait/in-trait/default-body-type-err.rs b/src/test/ui/impl-trait/in-trait/default-body-type-err.rs
new file mode 100644
index 000000000..ac9baf91c
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/default-body-type-err.rs
@@ -0,0 +1,13 @@
+#![allow(incomplete_features)]
+#![feature(return_position_impl_trait_in_trait)]
+
+use std::ops::Deref;
+
+pub trait Foo {
+ fn lol(&self) -> impl Deref<Target = String> {
+ //~^ type mismatch resolving `<&i32 as Deref>::Target == String`
+ &1i32
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/in-trait/default-body-type-err.stderr b/src/test/ui/impl-trait/in-trait/default-body-type-err.stderr
new file mode 100644
index 000000000..461247a3e
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/default-body-type-err.stderr
@@ -0,0 +1,12 @@
+error[E0271]: type mismatch resolving `<&i32 as Deref>::Target == String`
+ --> $DIR/default-body-type-err.rs:7:22
+ |
+LL | fn lol(&self) -> impl Deref<Target = String> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found struct `String`
+LL |
+LL | &1i32
+ | ----- return type was inferred to be `&i32` here
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0271`.
diff --git a/src/test/ui/impl-trait/in-trait/default-body-with-rpit.rs b/src/test/ui/impl-trait/in-trait/default-body-with-rpit.rs
new file mode 100644
index 000000000..ad3cc7c25
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/default-body-with-rpit.rs
@@ -0,0 +1,21 @@
+// check-pass
+// edition:2021
+
+#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+use std::fmt::Debug;
+
+trait Foo {
+ async fn baz(&self) -> impl Debug {
+ ""
+ }
+}
+
+struct Bar;
+
+impl Foo for Bar {}
+
+fn main() {
+ let _ = Bar.baz();
+}
diff --git a/src/test/ui/impl-trait/in-trait/default-body.rs b/src/test/ui/impl-trait/in-trait/default-body.rs
new file mode 100644
index 000000000..b0baf5bb1
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/default-body.rs
@@ -0,0 +1,21 @@
+// check-pass
+// edition:2021
+
+#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+use std::fmt::Debug;
+
+trait Foo {
+ async fn baz(&self) -> &str {
+ ""
+ }
+}
+
+struct Bar;
+
+impl Foo for Bar {}
+
+fn main() {
+ let _ = Bar.baz();
+}
diff --git a/src/test/ui/impl-trait/in-trait/early.rs b/src/test/ui/impl-trait/in-trait/early.rs
new file mode 100644
index 000000000..9c1c2b503
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/early.rs
@@ -0,0 +1,23 @@
+// check-pass
+// edition:2021
+
+#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+pub trait Foo {
+ async fn bar<'a: 'a>(&'a mut self);
+}
+
+impl Foo for () {
+ async fn bar<'a: 'a>(&'a mut self) {}
+}
+
+pub trait Foo2 {
+ fn bar<'a: 'a>(&'a mut self) -> impl Sized + 'a;
+}
+
+impl Foo2 for () {
+ fn bar<'a: 'a>(&'a mut self) -> impl Sized + 'a {}
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/in-trait/foreign.rs b/src/test/ui/impl-trait/in-trait/foreign.rs
new file mode 100644
index 000000000..6341f5b42
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/foreign.rs
@@ -0,0 +1,9 @@
+// check-pass
+// aux-build: rpitit.rs
+
+extern crate rpitit;
+
+fn main() {
+ // Witness an RPITIT from another crate
+ let () = <rpitit::Foreign as rpitit::Foo>::bar();
+}
diff --git a/src/test/ui/impl-trait/in-trait/issue-102140.rs b/src/test/ui/impl-trait/in-trait/issue-102140.rs
new file mode 100644
index 000000000..be1e012ac
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/issue-102140.rs
@@ -0,0 +1,30 @@
+#![feature(return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+trait Marker {}
+impl Marker for u32 {}
+
+trait MyTrait {
+ fn foo(&self) -> impl Marker
+ where
+ Self: Sized;
+}
+
+struct Outer;
+
+impl MyTrait for Outer {
+ fn foo(&self) -> impl Marker {
+ 42
+ }
+}
+
+impl dyn MyTrait {
+ fn other(&self) -> impl Marker {
+ MyTrait::foo(&self)
+ //~^ ERROR the trait bound `&dyn MyTrait: MyTrait` is not satisfied
+ //~| ERROR the trait bound `&dyn MyTrait: MyTrait` is not satisfied
+ //~| ERROR the trait bound `&dyn MyTrait: MyTrait` is not satisfied
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/in-trait/issue-102140.stderr b/src/test/ui/impl-trait/in-trait/issue-102140.stderr
new file mode 100644
index 000000000..08602185f
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/issue-102140.stderr
@@ -0,0 +1,29 @@
+error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied
+ --> $DIR/issue-102140.rs:23:22
+ |
+LL | MyTrait::foo(&self)
+ | ------------ -^^^^
+ | | |
+ | | the trait `MyTrait` is not implemented for `&dyn MyTrait`
+ | | help: consider removing the leading `&`-reference
+ | required by a bound introduced by this call
+
+error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied
+ --> $DIR/issue-102140.rs:23:9
+ |
+LL | MyTrait::foo(&self)
+ | ^^^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `&dyn MyTrait`
+ |
+ = help: the trait `MyTrait` is implemented for `Outer`
+
+error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied
+ --> $DIR/issue-102140.rs:23:9
+ |
+LL | MyTrait::foo(&self)
+ | ^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `&dyn MyTrait`
+ |
+ = help: the trait `MyTrait` is implemented for `Outer`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/impl-trait/in-trait/issue-102301.rs b/src/test/ui/impl-trait/in-trait/issue-102301.rs
new file mode 100644
index 000000000..a93714a65
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/issue-102301.rs
@@ -0,0 +1,18 @@
+// check-pass
+
+#![feature(return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+trait Foo<T> {
+ fn foo<F2: Foo<T>>(self) -> impl Foo<T>;
+}
+
+struct Bar;
+
+impl Foo<u8> for Bar {
+ fn foo<F2: Foo<u8>>(self) -> impl Foo<u8> {
+ self
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/in-trait/issue-102571.rs b/src/test/ui/impl-trait/in-trait/issue-102571.rs
new file mode 100644
index 000000000..61c91e644
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/issue-102571.rs
@@ -0,0 +1,24 @@
+#![feature(return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+use std::fmt::Display;
+use std::ops::Deref;
+
+trait Foo {
+ fn bar(self) -> impl Deref<Target = impl Display + ?Sized>;
+}
+
+struct A;
+
+impl Foo for A {
+ fn bar(self) -> &'static str {
+ "Hello, world"
+ }
+}
+
+fn foo<T: Foo>(t: T) {
+ let () = t.bar();
+ //~^ ERROR mismatched types
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/in-trait/issue-102571.stderr b/src/test/ui/impl-trait/in-trait/issue-102571.stderr
new file mode 100644
index 000000000..87219941d
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/issue-102571.stderr
@@ -0,0 +1,14 @@
+error[E0308]: mismatched types
+ --> $DIR/issue-102571.rs:20:9
+ |
+LL | let () = t.bar();
+ | ^^ ------- this expression has type `impl Deref<Target = impl std::fmt::Display + ?Sized>`
+ | |
+ | expected associated type, found `()`
+ |
+ = note: expected associated type `impl Deref<Target = impl std::fmt::Display + ?Sized>`
+ found unit type `()`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/impl-trait/in-trait/signature-mismatch.rs b/src/test/ui/impl-trait/in-trait/signature-mismatch.rs
new file mode 100644
index 000000000..90682631a
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/signature-mismatch.rs
@@ -0,0 +1,21 @@
+// edition:2021
+
+#![feature(return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+use std::future::Future;
+
+pub trait AsyncTrait {
+ fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
+}
+
+pub struct Struct;
+
+impl AsyncTrait for Struct {
+ fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
+ //~^ ERROR `impl` item signature doesn't match `trait` item signature
+ async move { buff.to_vec() }
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/in-trait/signature-mismatch.stderr b/src/test/ui/impl-trait/in-trait/signature-mismatch.stderr
new file mode 100644
index 000000000..6663d7faa
--- /dev/null
+++ b/src/test/ui/impl-trait/in-trait/signature-mismatch.stderr
@@ -0,0 +1,16 @@
+error: `impl` item signature doesn't match `trait` item signature
+ --> $DIR/signature-mismatch.rs:15:5
+ |
+LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
+ | ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + 'static`
+...
+LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2`
+ |
+ = note: expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + 'static`
+ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2`
+ = help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
+ = help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/impl-trait/issue-100075-2.stderr b/src/test/ui/impl-trait/issue-100075-2.stderr
index 5a1f1a97d..d2dbd8c62 100644
--- a/src/test/ui/impl-trait/issue-100075-2.stderr
+++ b/src/test/ui/impl-trait/issue-100075-2.stderr
@@ -7,8 +7,8 @@ LL | fn opaque<T>(t: T) -> impl Sized {
LL | opaque(Some(t))
| --------------- recursive call site
|
- = note: `#[warn(unconditional_recursion)]` on by default
= help: a `loop` may express intention better if this is on purpose
+ = note: `#[warn(unconditional_recursion)]` on by default
error[E0720]: cannot resolve opaque type
--> $DIR/issue-100075-2.rs:1:23
diff --git a/src/test/ui/impl-trait/issue-102605.rs b/src/test/ui/impl-trait/issue-102605.rs
new file mode 100644
index 000000000..3bbdf35af
--- /dev/null
+++ b/src/test/ui/impl-trait/issue-102605.rs
@@ -0,0 +1,15 @@
+// edition:2021
+
+async fn foo() -> Result<(), String> {
+ Ok(())
+}
+
+fn convert_result<T, E>(r: Result<T, E>) -> Option<T> {
+ None
+}
+
+fn main() -> Option<()> {
+ //~^ ERROR `main` has invalid return type `Option<()>`
+ convert_result(foo())
+ //~^ ERROR mismatched types
+}
diff --git a/src/test/ui/impl-trait/issue-102605.stderr b/src/test/ui/impl-trait/issue-102605.stderr
new file mode 100644
index 000000000..d4aba9149
--- /dev/null
+++ b/src/test/ui/impl-trait/issue-102605.stderr
@@ -0,0 +1,41 @@
+error[E0308]: mismatched types
+ --> $DIR/issue-102605.rs:13:20
+ |
+LL | convert_result(foo())
+ | -------------- ^^^^^ expected enum `Result`, found opaque type
+ | |
+ | arguments to this function are incorrect
+ |
+note: while checking the return type of the `async fn`
+ --> $DIR/issue-102605.rs:3:19
+ |
+LL | async fn foo() -> Result<(), String> {
+ | ^^^^^^^^^^^^^^^^^^ checked the `Output` of this `async fn`, found opaque type
+ = note: expected enum `Result<(), _>`
+ found opaque type `impl Future<Output = Result<(), String>>`
+note: function defined here
+ --> $DIR/issue-102605.rs:7:4
+ |
+LL | fn convert_result<T, E>(r: Result<T, E>) -> Option<T> {
+ | ^^^^^^^^^^^^^^ ---------------
+help: consider `await`ing on the `Future`
+ |
+LL | convert_result(foo().await)
+ | ++++++
+help: try wrapping the expression in `Err`
+ |
+LL | convert_result(Err(foo()))
+ | ++++ +
+
+error[E0277]: `main` has invalid return type `Option<()>`
+ --> $DIR/issue-102605.rs:11:14
+ |
+LL | fn main() -> Option<()> {
+ | ^^^^^^^^^^ `main` can only return types that implement `Termination`
+ |
+ = help: consider using `()`, or a `Result`
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0277, E0308.
+For more information about an error, try `rustc --explain E0277`.
diff --git a/src/test/ui/impl-trait/issue-103181-1.rs b/src/test/ui/impl-trait/issue-103181-1.rs
new file mode 100644
index 000000000..197aedf9d
--- /dev/null
+++ b/src/test/ui/impl-trait/issue-103181-1.rs
@@ -0,0 +1,85 @@
+// edition:2021
+
+mod hyper {
+ use std::{fmt::Debug, future::Future, marker::PhantomData, pin::Pin, task::Poll};
+
+ pub trait HttpBody {
+ type Error;
+ }
+ impl HttpBody for () {
+ //~^ ERROR not all trait items implemented, missing: `Error`
+ // don't implement `Error` here for the ICE
+ }
+
+ pub struct Server<I, S>(I, S);
+
+ pub fn serve<I, S>(_: S) -> Server<I, S> {
+ todo!()
+ }
+
+ impl<S, B> Future for Server<(), S>
+ where
+ S: MakeServiceRef<(), (), ResBody = B>,
+ B: HttpBody,
+ B::Error: Debug,
+ {
+ type Output = ();
+
+ fn poll(self: Pin<&mut Self>, _: &mut std::task::Context<'_>) -> Poll<Self::Output> {
+ todo!()
+ }
+ }
+
+ pub trait MakeServiceRef<Target, ReqBody> {
+ type ResBody;
+ }
+
+ impl<T, S> MakeServiceRef<(), ()> for T
+ where
+ T: for<'a> Service<&'a (), Response = S>,
+ S: Service<()>,
+ {
+ type ResBody = ();
+ }
+
+ pub struct MakeServiceFn<F>(pub F);
+ pub struct ServiceFn<F, R>(pub PhantomData<(F, R)>);
+
+ pub trait Service<Request> {
+ type Response;
+ }
+
+ impl<'t, F, Ret, Target, Svc> Service<&'t Target> for MakeServiceFn<F>
+ where
+ F: Fn() -> Ret,
+ Ret: Future<Output = Result<Svc, ()>>,
+ {
+ type Response = Svc;
+ }
+
+ impl<F, ReqBody, Ret, ResBody, E> Service<ReqBody> for ServiceFn<F, ReqBody>
+ where
+ F: Fn() -> Ret,
+ Ret: Future<Output = Result<ResBody, E>>,
+ {
+ type Response = ResBody;
+ }
+}
+
+async fn smarvice() -> Result<(), ()> {
+ Ok(())
+}
+
+fn service_fn<F, R, S>(f: F) -> hyper::ServiceFn<F, R>
+where
+ F: Fn() -> S,
+{
+ hyper::ServiceFn(std::marker::PhantomData)
+}
+
+async fn iceice() {
+ let service = hyper::MakeServiceFn(|| async { Ok::<_, ()>(service_fn(|| smarvice())) });
+ hyper::serve::<(), _>(service).await;
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/issue-103181-1.stderr b/src/test/ui/impl-trait/issue-103181-1.stderr
new file mode 100644
index 000000000..cd026607d
--- /dev/null
+++ b/src/test/ui/impl-trait/issue-103181-1.stderr
@@ -0,0 +1,12 @@
+error[E0046]: not all trait items implemented, missing: `Error`
+ --> $DIR/issue-103181-1.rs:9:5
+ |
+LL | type Error;
+ | ---------- `Error` from trait
+LL | }
+LL | impl HttpBody for () {
+ | ^^^^^^^^^^^^^^^^^^^^ missing `Error` in implementation
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0046`.
diff --git a/src/test/ui/impl-trait/issue-103181-2.rs b/src/test/ui/impl-trait/issue-103181-2.rs
new file mode 100644
index 000000000..b43ac4507
--- /dev/null
+++ b/src/test/ui/impl-trait/issue-103181-2.rs
@@ -0,0 +1,29 @@
+// edition:2021
+
+trait SendFuture: Send {
+ type Output;
+}
+
+impl<Fut: Send> SendFuture for Fut {
+ type Output = ();
+}
+
+async fn broken_fut() {
+ ident_error;
+ //~^ ERROR cannot find value `ident_error` in this scope
+}
+
+// triggers normalization of `<Fut as SendFuture>::Output`,
+// which requires `Fut: Send`.
+fn normalize<Fut: SendFuture>(_: Fut, _: Fut::Output) {}
+
+async fn iceice<A, B>()
+// <- async fn is necessary
+where
+ A: Send,
+ B: Send, // <- a second bound
+{
+ normalize(broken_fut(), ());
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/issue-103181-2.stderr b/src/test/ui/impl-trait/issue-103181-2.stderr
new file mode 100644
index 000000000..5eb2dd918
--- /dev/null
+++ b/src/test/ui/impl-trait/issue-103181-2.stderr
@@ -0,0 +1,9 @@
+error[E0425]: cannot find value `ident_error` in this scope
+ --> $DIR/issue-103181-2.rs:12:5
+ |
+LL | ident_error;
+ | ^^^^^^^^^^^ not found in this scope
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/impl-trait/issue-103599.stderr b/src/test/ui/impl-trait/issue-103599.stderr
index 79fb355dd..82038c1dc 100644
--- a/src/test/ui/impl-trait/issue-103599.stderr
+++ b/src/test/ui/impl-trait/issue-103599.stderr
@@ -7,8 +7,8 @@ LL |
LL | wrap(wrap(x))
| ------- recursive call site
|
- = note: `#[warn(unconditional_recursion)]` on by default
= help: a `loop` may express intention better if this is on purpose
+ = note: `#[warn(unconditional_recursion)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/impl-trait/issue-86465.rs b/src/test/ui/impl-trait/issue-86465.rs
index a79bb6474..8c7b41d73 100644
--- a/src/test/ui/impl-trait/issue-86465.rs
+++ b/src/test/ui/impl-trait/issue-86465.rs
@@ -1,6 +1,10 @@
#![feature(type_alias_impl_trait)]
-type X<'a, 'b> = impl std::fmt::Debug;
+pub trait Captures<'a> {}
+
+impl<'a, T: ?Sized> Captures<'a> for T {}
+
+type X<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
fn f<'t, 'u>(a: &'t u32, b: &'u u32) -> (X<'t, 'u>, X<'u, 't>) {
(a, a)
diff --git a/src/test/ui/impl-trait/issue-86465.stderr b/src/test/ui/impl-trait/issue-86465.stderr
index 90d6904ed..b949b2b42 100644
--- a/src/test/ui/impl-trait/issue-86465.stderr
+++ b/src/test/ui/impl-trait/issue-86465.stderr
@@ -1,5 +1,5 @@
error: concrete type differs from previous defining opaque type use
- --> $DIR/issue-86465.rs:6:5
+ --> $DIR/issue-86465.rs:10:5
|
LL | (a, a)
| ^^^^^^
diff --git a/src/test/ui/impl-trait/issue-87450.stderr b/src/test/ui/impl-trait/issue-87450.stderr
index 5019e544b..173fca63f 100644
--- a/src/test/ui/impl-trait/issue-87450.stderr
+++ b/src/test/ui/impl-trait/issue-87450.stderr
@@ -7,8 +7,8 @@ LL | fn foo() -> impl Fn() {
LL | wrap(wrap(wrap(wrap(wrap(wrap(wrap(foo())))))))
| ----- recursive call site
|
- = note: `#[warn(unconditional_recursion)]` on by default
= help: a `loop` may express intention better if this is on purpose
+ = note: `#[warn(unconditional_recursion)]` on by default
error[E0720]: cannot resolve opaque type
--> $DIR/issue-87450.rs:5:13
diff --git a/src/test/ui/impl-trait/issues/issue-78722.rs b/src/test/ui/impl-trait/issues/issue-78722.rs
index 90d1cd379..9ee1ba3d3 100644
--- a/src/test/ui/impl-trait/issues/issue-78722.rs
+++ b/src/test/ui/impl-trait/issues/issue-78722.rs
@@ -12,7 +12,7 @@ struct Bug {
}
let f: F = async { 1 };
//~^ ERROR `async` blocks are not allowed in constants
- //~| ERROR destructors cannot be evaluated at compile-time
+ //~| ERROR destructor of
1
}],
}
diff --git a/src/test/ui/impl-trait/issues/issue-78722.stderr b/src/test/ui/impl-trait/issues/issue-78722.stderr
index 9a0ffbc89..a96994f5a 100644
--- a/src/test/ui/impl-trait/issues/issue-78722.stderr
+++ b/src/test/ui/impl-trait/issues/issue-78722.stderr
@@ -7,11 +7,11 @@ LL | let f: F = async { 1 };
= note: see issue #85368 <https://github.com/rust-lang/rust/issues/85368> for more information
= help: add `#![feature(const_async_blocks)]` to the crate attributes to enable
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `F` cannot be evaluated at compile-time
--> $DIR/issue-78722.rs:13:13
|
LL | let f: F = async { 1 };
- | ^ constants cannot evaluate destructors
+ | ^ the destructor for this type cannot be evaluated in constants
...
LL | }],
| - value is dropped here
diff --git a/src/test/ui/impl-trait/issues/issue-86800.stderr b/src/test/ui/impl-trait/issues/issue-86800.stderr
index 135d06d44..6c4aa3567 100644
--- a/src/test/ui/impl-trait/issues/issue-86800.stderr
+++ b/src/test/ui/impl-trait/issues/issue-86800.stderr
@@ -1,3 +1,11 @@
+error: unconstrained opaque type
+ --> $DIR/issue-86800.rs:33:34
+ |
+LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ =
+
stack backtrace:
@@ -12,8 +20,7 @@ error: internal compiler error: unexpected panic
query stack during panic:
-#0 [mir_borrowck] borrow-checking `execute_transaction_fut`
-#1 [type_of] computing type of `TransactionFuture::{opaque#0}`
-#2 [check_mod_item_types] checking item types in top-level module
-#3 [analysis] running analysis passes on this crate
+#0 [type_of] computing type of `TransactionFuture::{opaque#0}`
+#1 [check_mod_item_types] checking item types in top-level module
+#2 [analysis] running analysis passes on this crate
end of query stack
diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr
index cb1dc0b7d..ec49a6179 100644
--- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr
+++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr
@@ -7,7 +7,7 @@ LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> im
LL | if condition() { a } else { b }
| ^
|
-help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
+help: to declare that `impl Trait<'d, 'e>` captures `'b`, you can add an explicit `'b` lifetime bound
|
LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> + 'b
| ++++
diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr
index 4388e6601..c36f9bc69 100644
--- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr
+++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr
@@ -7,7 +7,7 @@ LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a,
LL | if condition() { a } else { b }
| ^
|
-help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
+help: to declare that `impl Trait<'a, 'b>` captures `'b`, you can add an explicit `'b` lifetime bound
|
LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> + 'b
| ++++
diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
index 16767abd7..9c81791fb 100644
--- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
+++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
@@ -6,7 +6,7 @@ LL | fn elided(x: &i32) -> impl Copy { x }
| |
| hidden type `&i32` captures the anonymous lifetime defined here
|
-help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound
+help: to declare that `impl Copy` captures `'_`, you can add an explicit `'_` lifetime bound
|
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
| ++++
@@ -19,7 +19,7 @@ LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
| |
| hidden type `&'a i32` captures the lifetime `'a` as defined here
|
-help: to declare that the `impl Trait` captures `'a`, you can add an explicit `'a` lifetime bound
+help: to declare that `impl Copy` captures `'a`, you can add an explicit `'a` lifetime bound
|
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
| ++++
@@ -32,7 +32,7 @@ LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
| |
| let's call the lifetime of this reference `'1`
|
-help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
+help: consider changing `impl Copy + 'static`'s explicit `'static` bound to the lifetime of argument `x`
|
LL | fn elided2(x: &i32) -> impl Copy + '_ { x }
| ~~
@@ -47,7 +47,7 @@ error: lifetime may not live long enough
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
| -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static`
|
-help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
+help: consider changing `impl Copy + 'static`'s explicit `'static` bound to the lifetime of argument `x`
|
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x }
| ~~
@@ -76,7 +76,7 @@ help: to declare that the trait object captures data from argument `x`, you can
|
LL | fn elided5(x: &i32) -> (Box<dyn Debug + '_>, impl Debug) { (Box::new(x), x) }
| ++++
-help: to declare that the `impl Trait` captures data from argument `x`, you can add an explicit `'_` lifetime bound
+help: to declare that `impl Debug` captures data from argument `x`, you can add an explicit `'_` lifetime bound
|
LL | fn elided5(x: &i32) -> (Box<dyn Debug>, impl Debug + '_) { (Box::new(x), x) }
| ++++
@@ -87,7 +87,7 @@ error: lifetime may not live long enough
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
| -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static`
|
-help: consider changing the `impl Trait`'s explicit `'static` bound to the lifetime of argument `x`
+help: consider changing `impl LifetimeTrait<'a> + 'static`'s explicit `'static` bound to the lifetime of argument `x`
|
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x }
| ~~
@@ -104,7 +104,7 @@ LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32
LL | move |_| println!("{}", y)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: to declare that the `impl Trait` captures `'b`, you can add an explicit `'b` lifetime bound
+help: to declare that `impl Fn(&'a u32)` captures `'b`, you can add an explicit `'b` lifetime bound
|
LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + 'b {
| ++++
diff --git a/src/test/ui/impl-trait/nested-return-type2-tait.rs b/src/test/ui/impl-trait/nested-return-type2-tait.rs
index 42613d5cc..089018a1c 100644
--- a/src/test/ui/impl-trait/nested-return-type2-tait.rs
+++ b/src/test/ui/impl-trait/nested-return-type2-tait.rs
@@ -26,6 +26,7 @@ type Sendable = impl Send;
// var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque
// type does not implement `Duh`, but if its hidden type does.
fn foo() -> impl Trait<Assoc = Sendable> {
+ //~^ WARN opaque type `impl Trait<Assoc = Sendable>` does not satisfy its associated type bounds
|| 42
}
diff --git a/src/test/ui/impl-trait/nested-return-type2-tait.stderr b/src/test/ui/impl-trait/nested-return-type2-tait.stderr
new file mode 100644
index 000000000..a8eb69cfc
--- /dev/null
+++ b/src/test/ui/impl-trait/nested-return-type2-tait.stderr
@@ -0,0 +1,17 @@
+warning: opaque type `impl Trait<Assoc = Sendable>` does not satisfy its associated type bounds
+ --> $DIR/nested-return-type2-tait.rs:28:24
+ |
+LL | type Assoc: Duh;
+ | --- this associated type bound is unsatisfied for `Sendable`
+...
+LL | fn foo() -> impl Trait<Assoc = Sendable> {
+ | ^^^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(opaque_hidden_inferred_bound)]` on by default
+help: add this bound
+ |
+LL | type Sendable = impl Send + Duh;
+ | +++++
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/impl-trait/nested-return-type2.rs b/src/test/ui/impl-trait/nested-return-type2.rs
index 39928d543..cc1f1f4ec 100644
--- a/src/test/ui/impl-trait/nested-return-type2.rs
+++ b/src/test/ui/impl-trait/nested-return-type2.rs
@@ -23,6 +23,7 @@ impl<R: Duh, F: FnMut() -> R> Trait for F {
// Lazy TAIT would error out, but we inserted a hack to make it work again,
// keeping backwards compatibility.
fn foo() -> impl Trait<Assoc = impl Send> {
+ //~^ WARN opaque type `impl Trait<Assoc = impl Send>` does not satisfy its associated type bounds
|| 42
}
diff --git a/src/test/ui/impl-trait/nested-return-type2.stderr b/src/test/ui/impl-trait/nested-return-type2.stderr
new file mode 100644
index 000000000..3aed05ca1
--- /dev/null
+++ b/src/test/ui/impl-trait/nested-return-type2.stderr
@@ -0,0 +1,17 @@
+warning: opaque type `impl Trait<Assoc = impl Send>` does not satisfy its associated type bounds
+ --> $DIR/nested-return-type2.rs:25:24
+ |
+LL | type Assoc: Duh;
+ | --- this associated type bound is unsatisfied for `impl Send`
+...
+LL | fn foo() -> impl Trait<Assoc = impl Send> {
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(opaque_hidden_inferred_bound)]` on by default
+help: add this bound
+ |
+LL | fn foo() -> impl Trait<Assoc = impl Send + Duh> {
+ | +++++
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/impl-trait/nested-return-type3-tait.rs b/src/test/ui/impl-trait/nested-return-type3-tait.rs
index 3936f4dbb..3a97e35b4 100644
--- a/src/test/ui/impl-trait/nested-return-type3-tait.rs
+++ b/src/test/ui/impl-trait/nested-return-type3-tait.rs
@@ -17,6 +17,7 @@ impl<F: Duh> Trait for F {
type Sendable = impl Send;
fn foo() -> impl Trait<Assoc = Sendable> {
+ //~^ WARN opaque type `impl Trait<Assoc = Sendable>` does not satisfy its associated type bounds
42
}
diff --git a/src/test/ui/impl-trait/nested-return-type3-tait.stderr b/src/test/ui/impl-trait/nested-return-type3-tait.stderr
new file mode 100644
index 000000000..5f58c8dca
--- /dev/null
+++ b/src/test/ui/impl-trait/nested-return-type3-tait.stderr
@@ -0,0 +1,17 @@
+warning: opaque type `impl Trait<Assoc = Sendable>` does not satisfy its associated type bounds
+ --> $DIR/nested-return-type3-tait.rs:19:24
+ |
+LL | type Assoc: Duh;
+ | --- this associated type bound is unsatisfied for `Sendable`
+...
+LL | fn foo() -> impl Trait<Assoc = Sendable> {
+ | ^^^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(opaque_hidden_inferred_bound)]` on by default
+help: add this bound
+ |
+LL | type Sendable = impl Send + Duh;
+ | +++++
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/impl-trait/nested-return-type3-tait2.rs b/src/test/ui/impl-trait/nested-return-type3-tait2.rs
index 56778ed90..5b6f78a98 100644
--- a/src/test/ui/impl-trait/nested-return-type3-tait2.rs
+++ b/src/test/ui/impl-trait/nested-return-type3-tait2.rs
@@ -16,6 +16,7 @@ impl<F: Duh> Trait for F {
type Sendable = impl Send;
type Traitable = impl Trait<Assoc = Sendable>;
+//~^ WARN opaque type `Traitable` does not satisfy its associated type bounds
fn foo() -> Traitable {
42
diff --git a/src/test/ui/impl-trait/nested-return-type3-tait2.stderr b/src/test/ui/impl-trait/nested-return-type3-tait2.stderr
new file mode 100644
index 000000000..c07f6ead7
--- /dev/null
+++ b/src/test/ui/impl-trait/nested-return-type3-tait2.stderr
@@ -0,0 +1,17 @@
+warning: opaque type `Traitable` does not satisfy its associated type bounds
+ --> $DIR/nested-return-type3-tait2.rs:18:29
+ |
+LL | type Assoc: Duh;
+ | --- this associated type bound is unsatisfied for `Sendable`
+...
+LL | type Traitable = impl Trait<Assoc = Sendable>;
+ | ^^^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(opaque_hidden_inferred_bound)]` on by default
+help: add this bound
+ |
+LL | type Sendable = impl Send + Duh;
+ | +++++
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/impl-trait/nested-return-type3-tait3.rs b/src/test/ui/impl-trait/nested-return-type3-tait3.rs
index 04c6c92b1..394d8f581 100644
--- a/src/test/ui/impl-trait/nested-return-type3-tait3.rs
+++ b/src/test/ui/impl-trait/nested-return-type3-tait3.rs
@@ -15,6 +15,7 @@ impl<F: Duh> Trait for F {
}
type Traitable = impl Trait<Assoc = impl Send>;
+//~^ WARN opaque type `Traitable` does not satisfy its associated type bounds
fn foo() -> Traitable {
42
diff --git a/src/test/ui/impl-trait/nested-return-type3-tait3.stderr b/src/test/ui/impl-trait/nested-return-type3-tait3.stderr
new file mode 100644
index 000000000..d98ad8922
--- /dev/null
+++ b/src/test/ui/impl-trait/nested-return-type3-tait3.stderr
@@ -0,0 +1,17 @@
+warning: opaque type `Traitable` does not satisfy its associated type bounds
+ --> $DIR/nested-return-type3-tait3.rs:17:29
+ |
+LL | type Assoc: Duh;
+ | --- this associated type bound is unsatisfied for `impl Send`
+...
+LL | type Traitable = impl Trait<Assoc = impl Send>;
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(opaque_hidden_inferred_bound)]` on by default
+help: add this bound
+ |
+LL | type Traitable = impl Trait<Assoc = impl Send + Duh>;
+ | +++++
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/impl-trait/nested-return-type3.rs b/src/test/ui/impl-trait/nested-return-type3.rs
index 74b4dae22..5a764fc4c 100644
--- a/src/test/ui/impl-trait/nested-return-type3.rs
+++ b/src/test/ui/impl-trait/nested-return-type3.rs
@@ -13,6 +13,7 @@ impl<F: Duh> Trait for F {
}
fn foo() -> impl Trait<Assoc = impl Send> {
+ //~^ WARN opaque type `impl Trait<Assoc = impl Send>` does not satisfy its associated type bounds
42
}
diff --git a/src/test/ui/impl-trait/nested-return-type3.stderr b/src/test/ui/impl-trait/nested-return-type3.stderr
new file mode 100644
index 000000000..632de71aa
--- /dev/null
+++ b/src/test/ui/impl-trait/nested-return-type3.stderr
@@ -0,0 +1,17 @@
+warning: opaque type `impl Trait<Assoc = impl Send>` does not satisfy its associated type bounds
+ --> $DIR/nested-return-type3.rs:15:24
+ |
+LL | type Assoc: Duh;
+ | --- this associated type bound is unsatisfied for `impl Send`
+...
+LL | fn foo() -> impl Trait<Assoc = impl Send> {
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(opaque_hidden_inferred_bound)]` on by default
+help: add this bound
+ |
+LL | fn foo() -> impl Trait<Assoc = impl Send + Duh> {
+ | +++++
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/impl-trait/normalize-tait-in-const.rs b/src/test/ui/impl-trait/normalize-tait-in-const.rs
new file mode 100644
index 000000000..020bcbb83
--- /dev/null
+++ b/src/test/ui/impl-trait/normalize-tait-in-const.rs
@@ -0,0 +1,39 @@
+// known-bug: #103507
+// failure-status: 101
+// normalize-stderr-test "note: .*\n\n" -> ""
+// normalize-stderr-test "thread 'rustc' panicked.*\n" -> ""
+// rustc-env:RUST_BACKTRACE=0
+
+#![feature(type_alias_impl_trait)]
+#![feature(const_trait_impl)]
+#![feature(const_refs_to_cell)]
+#![feature(inline_const)]
+
+use std::marker::Destruct;
+
+trait T {
+ type Item;
+}
+
+type Alias<'a> = impl T<Item = &'a ()>;
+
+struct S;
+impl<'a> T for &'a S {
+ type Item = &'a ();
+}
+
+const fn filter_positive<'a>() -> &'a Alias<'a> {
+ &&S
+}
+
+const fn with_positive<F: ~const for<'a> Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
+ fun(filter_positive());
+}
+
+const fn foo(_: &Alias<'_>) {}
+
+const BAR: () = {
+ with_positive(foo);
+};
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/normalize-tait-in-const.stderr b/src/test/ui/impl-trait/normalize-tait-in-const.stderr
new file mode 100644
index 000000000..b9fc8726f
--- /dev/null
+++ b/src/test/ui/impl-trait/normalize-tait-in-const.stderr
@@ -0,0 +1,8 @@
+error: internal compiler error: compiler/rustc_middle/src/ty/normalize_erasing_regions.rs:198:90: Failed to normalize <for<'a, 'b> fn(&'a Alias<'b>) {foo} as std::ops::FnOnce<(&&S,)>>::Output, maybe try to call `try_normalize_erasing_regions` instead
+
+query stack during panic:
+#0 [eval_to_allocation_raw] const-evaluating + checking `BAR`
+#1 [eval_to_const_value_raw] simplifying constant for the type system `BAR`
+end of query stack
+error: aborting due to previous error
+
diff --git a/src/test/ui/impl-trait/region-escape-via-bound.stderr b/src/test/ui/impl-trait/region-escape-via-bound.stderr
index fdb2fe022..44a790cb1 100644
--- a/src/test/ui/impl-trait/region-escape-via-bound.stderr
+++ b/src/test/ui/impl-trait/region-escape-via-bound.stderr
@@ -7,7 +7,7 @@ LL | fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y>
LL | x
| ^
|
-help: to declare that the `impl Trait` captures `'x`, you can add an explicit `'x` lifetime bound
+help: to declare that `impl Trait<'y>` captures `'x`, you can add an explicit `'x` lifetime bound
|
LL | fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y> + 'x
| ++++
diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr
index b86815231..b365bd884 100644
--- a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr
+++ b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr
@@ -6,7 +6,7 @@ LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
LL | self.x.iter().map(|a| a.0)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound
+help: to declare that `impl Iterator<Item = u32>` captures `'_`, you can add an explicit `'_` lifetime bound
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
| ++++
@@ -19,7 +19,7 @@ LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
LL | self.x.iter().map(|a| a.0)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound
+help: to declare that `impl Iterator<Item = u32>` captures `'_`, you can add an explicit `'_` lifetime bound
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
| ++++
@@ -32,7 +32,7 @@ LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
LL | self.x.iter().map(|a| a.0)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: to declare that the `impl Trait` captures `'a`, you can add an explicit `'a` lifetime bound
+help: to declare that `impl Iterator<Item = u32>` captures `'a`, you can add an explicit `'a` lifetime bound
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {
| ++++
@@ -45,7 +45,7 @@ LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
LL | self.x.iter().map(|a| a.0)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: to declare that the `impl Trait` captures `'a`, you can add an explicit `'a` lifetime bound
+help: to declare that `impl Iterator<Item = u32>` captures `'a`, you can add an explicit `'a` lifetime bound
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {
| ++++
diff --git a/src/test/ui/impl-trait/unactionable_diagnostic.fixed b/src/test/ui/impl-trait/unactionable_diagnostic.fixed
new file mode 100644
index 000000000..6c2505177
--- /dev/null
+++ b/src/test/ui/impl-trait/unactionable_diagnostic.fixed
@@ -0,0 +1,25 @@
+// run-rustfix
+
+pub trait Trait {}
+
+pub struct Foo;
+
+impl Trait for Foo {}
+
+fn foo<'x, P>(
+ _post: P,
+ x: &'x Foo,
+) -> &'x impl Trait {
+ x
+}
+
+pub fn bar<'t, T: 't>(
+ //~^ HELP: consider adding an explicit lifetime bound...
+ post: T,
+ x: &'t Foo,
+) -> &'t impl Trait {
+ foo(post, x)
+ //~^ ERROR: the parameter type `T` may not live long enough
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/unactionable_diagnostic.rs b/src/test/ui/impl-trait/unactionable_diagnostic.rs
new file mode 100644
index 000000000..bce35cbdd
--- /dev/null
+++ b/src/test/ui/impl-trait/unactionable_diagnostic.rs
@@ -0,0 +1,25 @@
+// run-rustfix
+
+pub trait Trait {}
+
+pub struct Foo;
+
+impl Trait for Foo {}
+
+fn foo<'x, P>(
+ _post: P,
+ x: &'x Foo,
+) -> &'x impl Trait {
+ x
+}
+
+pub fn bar<'t, T>(
+ //~^ HELP: consider adding an explicit lifetime bound...
+ post: T,
+ x: &'t Foo,
+) -> &'t impl Trait {
+ foo(post, x)
+ //~^ ERROR: the parameter type `T` may not live long enough
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/unactionable_diagnostic.stderr b/src/test/ui/impl-trait/unactionable_diagnostic.stderr
new file mode 100644
index 000000000..a32004cda
--- /dev/null
+++ b/src/test/ui/impl-trait/unactionable_diagnostic.stderr
@@ -0,0 +1,14 @@
+error[E0309]: the parameter type `T` may not live long enough
+ --> $DIR/unactionable_diagnostic.rs:21:5
+ |
+LL | foo(post, x)
+ | ^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
+ |
+help: consider adding an explicit lifetime bound...
+ |
+LL | pub fn bar<'t, T: 't>(
+ | ++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0309`.
diff --git a/src/test/ui/impl-trait/where-allowed.stderr b/src/test/ui/impl-trait/where-allowed.stderr
index 9b346387d..2e7c7ca40 100644
--- a/src/test/ui/impl-trait/where-allowed.stderr
+++ b/src/test/ui/impl-trait/where-allowed.stderr
@@ -301,9 +301,9 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type`
LL | impl <T = impl Debug> T {}
| ^^^^^^^^^^^^^^
|
- = note: `#[deny(invalid_type_param_default)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
+ = note: `#[deny(invalid_type_param_default)]` on by default
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
--> $DIR/where-allowed.rs:241:36
diff --git a/src/test/ui/imports/issue-56125.stderr b/src/test/ui/imports/issue-56125.stderr
index 2e4ba8623..059ca9680 100644
--- a/src/test/ui/imports/issue-56125.stderr
+++ b/src/test/ui/imports/issue-56125.stderr
@@ -3,6 +3,18 @@ error[E0432]: unresolved import `empty::issue_56125`
|
LL | use empty::issue_56125;
| ^^^^^^^^^^^^^^^^^^ no `issue_56125` in `m3::empty`
+ |
+help: consider importing one of these items instead
+ |
+LL | use crate::m3::last_segment::issue_56125;
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+LL | use crate::m3::non_last_segment::non_last_segment::issue_56125;
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+LL | use issue_56125::issue_56125;
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~
+LL | use issue_56125::last_segment::issue_56125;
+ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ and 1 other candidate
error[E0659]: `issue_56125` is ambiguous
--> $DIR/issue-56125.rs:6:9
diff --git a/src/test/ui/imports/issue-57015.stderr b/src/test/ui/imports/issue-57015.stderr
index d200d23ab..3b72d57fe 100644
--- a/src/test/ui/imports/issue-57015.stderr
+++ b/src/test/ui/imports/issue-57015.stderr
@@ -3,6 +3,11 @@ error[E0432]: unresolved import `single_err::something`
|
LL | use single_err::something;
| ^^^^^^^^^^^^^^^^^^^^^ no `something` in `single_err`
+ |
+help: consider importing this module instead
+ |
+LL | use glob_ok::something;
+ | ~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
diff --git a/src/test/ui/imports/local-modularized-tricky-fail-2.stderr b/src/test/ui/imports/local-modularized-tricky-fail-2.stderr
index 3c20f552f..2c1965ac0 100644
--- a/src/test/ui/imports/local-modularized-tricky-fail-2.stderr
+++ b/src/test/ui/imports/local-modularized-tricky-fail-2.stderr
@@ -4,7 +4,6 @@ error: macro-expanded `macro_export` macros from the current crate cannot be ref
LL | use exported;
| ^^^^^^^^
|
- = note: `#[deny(macro_expanded_macro_exports_accessed_by_absolute_paths)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #52234 <https://github.com/rust-lang/rust/issues/52234>
note: the macro is defined here
@@ -17,6 +16,7 @@ LL | | }
...
LL | define_exported!();
| ------------------ in this macro invocation
+ = note: `#[deny(macro_expanded_macro_exports_accessed_by_absolute_paths)]` on by default
= note: this error originates in the macro `define_exported` (in Nightly builds, run with -Z macro-backtrace for more info)
error: macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
diff --git a/src/test/ui/inference/char-as-str-single.fixed b/src/test/ui/inference/char-as-str-single.fixed
index e401492a8..bab1854dc 100644
--- a/src/test/ui/inference/char-as-str-single.fixed
+++ b/src/test/ui/inference/char-as-str-single.fixed
@@ -8,4 +8,5 @@
fn main() {
let _: char = 'a'; //~ ERROR mismatched types
let _: char = '人'; //~ ERROR mismatched types
+ let _: char = '\''; //~ ERROR mismatched types
}
diff --git a/src/test/ui/inference/char-as-str-single.rs b/src/test/ui/inference/char-as-str-single.rs
index 4f23cea53..736920643 100644
--- a/src/test/ui/inference/char-as-str-single.rs
+++ b/src/test/ui/inference/char-as-str-single.rs
@@ -8,4 +8,5 @@
fn main() {
let _: char = "a"; //~ ERROR mismatched types
let _: char = "人"; //~ ERROR mismatched types
+ let _: char = "'"; //~ ERROR mismatched types
}
diff --git a/src/test/ui/inference/char-as-str-single.stderr b/src/test/ui/inference/char-as-str-single.stderr
index 29075c154..3375ec6ac 100644
--- a/src/test/ui/inference/char-as-str-single.stderr
+++ b/src/test/ui/inference/char-as-str-single.stderr
@@ -24,6 +24,19 @@ help: if you meant to write a `char` literal, use single quotes
LL | let _: char = '人';
| ~~~~
-error: aborting due to 2 previous errors
+error[E0308]: mismatched types
+ --> $DIR/char-as-str-single.rs:11:19
+ |
+LL | let _: char = "'";
+ | ---- ^^^ expected `char`, found `&str`
+ | |
+ | expected due to this
+ |
+help: if you meant to write a `char` literal, use single quotes
+ |
+LL | let _: char = '\'';
+ | ~~~~
+
+error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/inference/inference-variable-behind-raw-pointer.stderr b/src/test/ui/inference/inference-variable-behind-raw-pointer.stderr
index c38f57912..3dea09e7f 100644
--- a/src/test/ui/inference/inference-variable-behind-raw-pointer.stderr
+++ b/src/test/ui/inference/inference-variable-behind-raw-pointer.stderr
@@ -4,9 +4,9 @@ warning: type annotations needed
LL | if data.is_null() {}
| ^^^^^^^
|
- = note: `#[warn(tyvar_behind_raw_pointer)]` on by default
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
= note: for more information, see issue #46906 <https://github.com/rust-lang/rust/issues/46906>
+ = note: `#[warn(tyvar_behind_raw_pointer)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/inference/inference_unstable.stderr b/src/test/ui/inference/inference_unstable.stderr
index df7a09686..ecbf2641b 100644
--- a/src/test/ui/inference/inference_unstable.stderr
+++ b/src/test/ui/inference/inference_unstable.stderr
@@ -4,11 +4,11 @@ warning: an associated function with this name may be added to the standard libr
LL | assert_eq!('x'.ipu_flatten(), 1);
| ^^^^^^^^^^^
|
- = note: `#[warn(unstable_name_collisions)]` on by default
= warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
= note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
= help: call with fully qualified syntax `inference_unstable_itertools::IpuItertools::ipu_flatten(...)` to keep using the current method
= help: add `#![feature(ipu_flatten)]` to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_flatten`
+ = note: `#[warn(unstable_name_collisions)]` on by default
warning: an associated function with this name may be added to the standard library in the future
--> $DIR/inference_unstable.rs:19:20
diff --git a/src/test/ui/issues/issue-36053.rs b/src/test/ui/inference/issue-36053.rs
index 5c6d07804..5c6d07804 100644
--- a/src/test/ui/issues/issue-36053.rs
+++ b/src/test/ui/inference/issue-36053.rs
diff --git a/src/test/ui/inference/need_type_info/concrete-impl.stderr b/src/test/ui/inference/need_type_info/concrete-impl.stderr
index b79d34aff..aa3296995 100644
--- a/src/test/ui/inference/need_type_info/concrete-impl.stderr
+++ b/src/test/ui/inference/need_type_info/concrete-impl.stderr
@@ -3,11 +3,6 @@ error[E0282]: type annotations needed
|
LL | <Struct as Ambiguous<_>>::method();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Self` declared on the trait `Ambiguous`
- |
-help: consider specifying the generic argument
- |
-LL | <Struct as Ambiguous::<_>>::method();
- | ~~~~~
error[E0283]: type annotations needed
--> $DIR/concrete-impl.rs:13:5
@@ -22,10 +17,6 @@ LL | impl Ambiguous<One> for Struct {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | impl Ambiguous<Two> for Struct {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-help: consider specifying the generic argument
- |
-LL | <Struct as Ambiguous::<_>>::method();
- | ~~~~~
error: aborting due to 2 previous errors
diff --git a/src/test/ui/inference/need_type_info/do-not-suggest-generic-arguments-for-turbofish.rs b/src/test/ui/inference/need_type_info/do-not-suggest-generic-arguments-for-turbofish.rs
new file mode 100644
index 000000000..3084f6eac
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/do-not-suggest-generic-arguments-for-turbofish.rs
@@ -0,0 +1,11 @@
+enum OhNo<T, U> {
+ A(T),
+ B(U),
+ C,
+}
+
+fn uwu() {
+ OhNo::C::<u32, _>; //~ ERROR type annotations needed
+}
+
+fn main() {}
diff --git a/src/test/ui/inference/need_type_info/do-not-suggest-generic-arguments-for-turbofish.stderr b/src/test/ui/inference/need_type_info/do-not-suggest-generic-arguments-for-turbofish.stderr
new file mode 100644
index 000000000..2ad35ab03
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/do-not-suggest-generic-arguments-for-turbofish.stderr
@@ -0,0 +1,9 @@
+error[E0282]: type annotations needed
+ --> $DIR/do-not-suggest-generic-arguments-for-turbofish.rs:8:5
+ |
+LL | OhNo::C::<u32, _>;
+ | ^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `U` declared on the enum `OhNo`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/src/test/ui/inference/need_type_info/issue-103053.rs b/src/test/ui/inference/need_type_info/issue-103053.rs
new file mode 100644
index 000000000..05169666f
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/issue-103053.rs
@@ -0,0 +1,18 @@
+trait TypeMapper {
+ type MapType;
+}
+
+type Mapped<T> = <T as TypeMapper>::MapType;
+
+struct Test {}
+
+impl TypeMapper for () {
+ type MapType = Test;
+}
+
+fn test() {
+ Mapped::<()> {};
+ None; //~ ERROR type annotations needed
+}
+
+fn main() {}
diff --git a/src/test/ui/inference/need_type_info/issue-103053.stderr b/src/test/ui/inference/need_type_info/issue-103053.stderr
new file mode 100644
index 000000000..84f0475d8
--- /dev/null
+++ b/src/test/ui/inference/need_type_info/issue-103053.stderr
@@ -0,0 +1,14 @@
+error[E0282]: type annotations needed
+ --> $DIR/issue-103053.rs:15:5
+ |
+LL | None;
+ | ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
+ |
+help: consider specifying the generic argument
+ |
+LL | None::<T>;
+ | +++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/src/test/ui/inference/str-as-char.fixed b/src/test/ui/inference/str-as-char.fixed
index 09f3dec5a..6aea809cb 100644
--- a/src/test/ui/inference/str-as-char.fixed
+++ b/src/test/ui/inference/str-as-char.fixed
@@ -4,5 +4,7 @@
// run-rustfix
fn main() {
- let _: &str = "a"; //~ ERROR mismatched types
+ let _: &str = "a"; //~ ERROR mismatched types
+ let _: &str = "\"\"\""; //~ ERROR character literal may only contain one codepoint
+ let _: &str = "\"\"\""; //~ ERROR character literal may only contain one codepoint
}
diff --git a/src/test/ui/inference/str-as-char.rs b/src/test/ui/inference/str-as-char.rs
index 7092a6124..eaa8d788c 100644
--- a/src/test/ui/inference/str-as-char.rs
+++ b/src/test/ui/inference/str-as-char.rs
@@ -4,5 +4,7 @@
// run-rustfix
fn main() {
- let _: &str = 'a'; //~ ERROR mismatched types
+ let _: &str = 'a'; //~ ERROR mismatched types
+ let _: &str = '"""'; //~ ERROR character literal may only contain one codepoint
+ let _: &str = '\"\"\"'; //~ ERROR character literal may only contain one codepoint
}
diff --git a/src/test/ui/inference/str-as-char.stderr b/src/test/ui/inference/str-as-char.stderr
index ebbe7c80f..2c84dac8e 100644
--- a/src/test/ui/inference/str-as-char.stderr
+++ b/src/test/ui/inference/str-as-char.stderr
@@ -1,3 +1,25 @@
+error: character literal may only contain one codepoint
+ --> $DIR/str-as-char.rs:8:19
+ |
+LL | let _: &str = '"""';
+ | ^^^^^
+ |
+help: if you meant to write a `str` literal, use double quotes
+ |
+LL | let _: &str = "\"\"\"";
+ | ~~~~~~~~
+
+error: character literal may only contain one codepoint
+ --> $DIR/str-as-char.rs:9:19
+ |
+LL | let _: &str = '\"\"\"';
+ | ^^^^^^^^
+ |
+help: if you meant to write a `str` literal, use double quotes
+ |
+LL | let _: &str = "\"\"\"";
+ | ~~~~~~~~
+
error[E0308]: mismatched types
--> $DIR/str-as-char.rs:7:19
|
@@ -11,6 +33,6 @@ help: if you meant to write a `str` literal, use double quotes
LL | let _: &str = "a";
| ~~~
-error: aborting due to previous error
+error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/infinite/infinite-struct.rs b/src/test/ui/infinite/infinite-struct.rs
index 74185dc59..f08e10f6b 100644
--- a/src/test/ui/infinite/infinite-struct.rs
+++ b/src/test/ui/infinite/infinite-struct.rs
@@ -6,4 +6,11 @@ fn foo() -> Take {
Take(loop {})
}
+// mutually infinite structs
+struct Foo { //~ ERROR has infinite size
+ x: Bar<Foo>,
+}
+
+struct Bar<T>([T; 1]);
+
fn main() {}
diff --git a/src/test/ui/infinite/infinite-struct.stderr b/src/test/ui/infinite/infinite-struct.stderr
index 5a6d13786..b6c72b1de 100644
--- a/src/test/ui/infinite/infinite-struct.stderr
+++ b/src/test/ui/infinite/infinite-struct.stderr
@@ -3,14 +3,25 @@ error[E0072]: recursive type `Take` has infinite size
|
LL | struct Take(Take);
| ^^^^^^^^^^^ ---- recursive without indirection
- | |
- | recursive type has infinite size
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Take` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | struct Take(Box<Take>);
| ++++ +
-error: aborting due to previous error
+error[E0072]: recursive type `Foo` has infinite size
+ --> $DIR/infinite-struct.rs:10:1
+ |
+LL | struct Foo {
+ | ^^^^^^^^^^
+LL | x: Bar<Foo>,
+ | --- recursive without indirection
+ |
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
+ |
+LL | x: Bar<Box<Foo>>,
+ | ++++ +
+
+error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0072`.
diff --git a/src/test/ui/infinite/infinite-tag-type-recursion.stderr b/src/test/ui/infinite/infinite-tag-type-recursion.stderr
index d2dad4b91..513bbfc1b 100644
--- a/src/test/ui/infinite/infinite-tag-type-recursion.stderr
+++ b/src/test/ui/infinite/infinite-tag-type-recursion.stderr
@@ -3,10 +3,8 @@ error[E0072]: recursive type `MList` has infinite size
|
LL | enum MList { Cons(isize, MList), Nil }
| ^^^^^^^^^^ ----- recursive without indirection
- | |
- | recursive type has infinite size
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `MList` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | enum MList { Cons(isize, Box<MList>), Nil }
| ++++ +
diff --git a/src/test/ui/inline-const/const-match-pat-range.rs b/src/test/ui/inline-const/const-match-pat-range.rs
index 7dc8c1135..73d6334c3 100644
--- a/src/test/ui/inline-const/const-match-pat-range.rs
+++ b/src/test/ui/inline-const/const-match-pat-range.rs
@@ -1,7 +1,8 @@
// build-pass
#![allow(incomplete_features)]
-#![feature(inline_const_pat, half_open_range_patterns, exclusive_range_pattern)]
+#![feature(inline_const_pat, exclusive_range_pattern)]
+
fn main() {
const N: u32 = 10;
let x: u32 = 3;
diff --git a/src/test/ui/intrinsics/const-eval-select-backtrace-std.rs b/src/test/ui/intrinsics/const-eval-select-backtrace-std.rs
index 29aefe071..1164a3a5b 100644
--- a/src/test/ui/intrinsics/const-eval-select-backtrace-std.rs
+++ b/src/test/ui/intrinsics/const-eval-select-backtrace-std.rs
@@ -1,6 +1,7 @@
// See issue #100696.
// run-fail
// check-run-results
+// exec-env:RUST_BACKTRACE=0
fn main() {
&""[1..];
}
diff --git a/src/test/ui/intrinsics/const-eval-select-backtrace-std.run.stderr b/src/test/ui/intrinsics/const-eval-select-backtrace-std.run.stderr
index e53e60346..463cd52c5 100644
--- a/src/test/ui/intrinsics/const-eval-select-backtrace-std.run.stderr
+++ b/src/test/ui/intrinsics/const-eval-select-backtrace-std.run.stderr
@@ -1,2 +1,2 @@
-thread 'main' panicked at 'byte index 1 is out of bounds of ``', $DIR/const-eval-select-backtrace-std.rs:5:6
+thread 'main' panicked at 'byte index 1 is out of bounds of ``', $DIR/const-eval-select-backtrace-std.rs:6:6
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
diff --git a/src/test/ui/intrinsics/const-eval-select-backtrace.rs b/src/test/ui/intrinsics/const-eval-select-backtrace.rs
index 99f072520..ef1c7c419 100644
--- a/src/test/ui/intrinsics/const-eval-select-backtrace.rs
+++ b/src/test/ui/intrinsics/const-eval-select-backtrace.rs
@@ -2,6 +2,7 @@
// See issue #100696.
// run-fail
// check-run-results
+// exec-env:RUST_BACKTRACE=0
#[track_caller]
fn uhoh() {
diff --git a/src/test/ui/intrinsics/const-eval-select-backtrace.run.stderr b/src/test/ui/intrinsics/const-eval-select-backtrace.run.stderr
index 2fd730ac7..54e28db5e 100644
--- a/src/test/ui/intrinsics/const-eval-select-backtrace.run.stderr
+++ b/src/test/ui/intrinsics/const-eval-select-backtrace.run.stderr
@@ -1,2 +1,2 @@
-thread 'main' panicked at 'Aaah!', $DIR/const-eval-select-backtrace.rs:16:9
+thread 'main' panicked at 'Aaah!', $DIR/const-eval-select-backtrace.rs:17:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
diff --git a/src/test/ui/intrinsics/intrinsic-alignment.rs b/src/test/ui/intrinsics/intrinsic-alignment.rs
index 6007eba8c..c8b1ff1db 100644
--- a/src/test/ui/intrinsics/intrinsic-alignment.rs
+++ b/src/test/ui/intrinsics/intrinsic-alignment.rs
@@ -6,6 +6,7 @@
mod rusti {
extern "rust-intrinsic" {
pub fn pref_align_of<T>() -> usize;
+ #[rustc_safe_intrinsic]
pub fn min_align_of<T>() -> usize;
}
}
diff --git a/src/test/ui/intrinsics/intrinsic-raw_eq-const-padding.rs b/src/test/ui/intrinsics/intrinsic-raw_eq-const-padding.rs
index a205a8730..a93d777d2 100644
--- a/src/test/ui/intrinsics/intrinsic-raw_eq-const-padding.rs
+++ b/src/test/ui/intrinsics/intrinsic-raw_eq-const-padding.rs
@@ -1,6 +1,5 @@
#![feature(core_intrinsics)]
#![feature(const_intrinsic_raw_eq)]
-#![deny(const_err)]
const BAD_RAW_EQ_CALL: bool = unsafe {
std::intrinsics::raw_eq(&(1_u8, 2_u16), &(1_u8, 2_u16))
diff --git a/src/test/ui/intrinsics/intrinsic-raw_eq-const-padding.stderr b/src/test/ui/intrinsics/intrinsic-raw_eq-const-padding.stderr
index 9322654b2..56d5a4857 100644
--- a/src/test/ui/intrinsics/intrinsic-raw_eq-const-padding.stderr
+++ b/src/test/ui/intrinsics/intrinsic-raw_eq-const-padding.stderr
@@ -1,5 +1,5 @@
error[E0080]: evaluation of constant value failed
- --> $DIR/intrinsic-raw_eq-const-padding.rs:6:5
+ --> $DIR/intrinsic-raw_eq-const-padding.rs:5:5
|
LL | std::intrinsics::raw_eq(&(1_u8, 2_u16), &(1_u8, 2_u16))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reading memory at alloc3[0x0..0x4], but memory is uninitialized at [0x1..0x2], and this operation requires initialized memory
diff --git a/src/test/ui/intrinsics/intrinsic-raw_eq-const.rs b/src/test/ui/intrinsics/intrinsic-raw_eq-const.rs
index 8ea954673..32841f531 100644
--- a/src/test/ui/intrinsics/intrinsic-raw_eq-const.rs
+++ b/src/test/ui/intrinsics/intrinsic-raw_eq-const.rs
@@ -2,7 +2,6 @@
#![feature(core_intrinsics)]
#![feature(const_intrinsic_raw_eq)]
-#![deny(const_err)]
pub fn main() {
use std::intrinsics::raw_eq;
diff --git a/src/test/ui/intrinsics/intrinsics-integer.rs b/src/test/ui/intrinsics/intrinsics-integer.rs
index bac6c8d87..88bf42b68 100644
--- a/src/test/ui/intrinsics/intrinsics-integer.rs
+++ b/src/test/ui/intrinsics/intrinsics-integer.rs
@@ -1,15 +1,21 @@
// run-pass
#![feature(intrinsics)]
+#![feature(rustc_attrs)]
mod rusti {
extern "rust-intrinsic" {
+ #[rustc_safe_intrinsic]
pub fn ctpop<T>(x: T) -> T;
+ #[rustc_safe_intrinsic]
pub fn ctlz<T>(x: T) -> T;
pub fn ctlz_nonzero<T>(x: T) -> T;
+ #[rustc_safe_intrinsic]
pub fn cttz<T>(x: T) -> T;
pub fn cttz_nonzero<T>(x: T) -> T;
+ #[rustc_safe_intrinsic]
pub fn bswap<T>(x: T) -> T;
+ #[rustc_safe_intrinsic]
pub fn bitreverse<T>(x: T) -> T;
}
}
diff --git a/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs b/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs
index 255151a96..ec3860a32 100644
--- a/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs
+++ b/src/test/ui/intrinsics/panic-uninitialized-zeroed.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
// revisions: mir thir strict
// [thir]compile-flags: -Zthir-unsafeck
// [strict]compile-flags: -Zstrict-init-checks
@@ -8,7 +7,7 @@
// This test checks panic emitted from `mem::{uninitialized,zeroed}`.
-#![feature(never_type, arbitrary_enum_discriminant)]
+#![feature(never_type)]
#![allow(deprecated, invalid_value)]
use std::{
@@ -35,6 +34,12 @@ enum OneVariant_NonZero {
DeadVariant(Bar),
}
+#[allow(dead_code, non_camel_case_types)]
+enum OneVariant_Ref {
+ Variant(&'static i32),
+ DeadVariant(Bar),
+}
+
// An `Aggregate` abi enum where 0 is not a valid discriminant.
#[allow(dead_code)]
#[repr(i32)]
@@ -64,6 +69,7 @@ enum ZeroIsValid {
One(NonNull<()>) = 1,
}
+#[track_caller]
fn test_panic_msg<T>(op: impl (FnOnce() -> T) + panic::UnwindSafe, msg: &str) {
let err = panic::catch_unwind(op).err();
assert_eq!(
@@ -72,6 +78,15 @@ fn test_panic_msg<T>(op: impl (FnOnce() -> T) + panic::UnwindSafe, msg: &str) {
);
}
+#[track_caller]
+fn test_panic_msg_only_if_strict<T>(op: impl (FnOnce() -> T) + panic::UnwindSafe, msg: &str) {
+ let err = panic::catch_unwind(op).err();
+ assert_eq!(
+ err.as_ref().and_then(|a| a.downcast_ref::<&str>()),
+ if cfg!(strict) { Some(&msg) } else { None },
+ );
+}
+
fn main() {
unsafe {
// Uninhabited types
@@ -140,92 +155,216 @@ fn main() {
"attempted to instantiate uninhabited type `[Bar; 2]`"
);
- // Types that do not like zero-initialziation
+ // Types that don't allow either.
test_panic_msg(
- || mem::uninitialized::<fn()>(),
- "attempted to leave type `fn()` uninitialized, which is invalid"
+ || mem::zeroed::<&i32>(),
+ "attempted to zero-initialize type `&i32`, which is invalid"
);
test_panic_msg(
- || mem::zeroed::<fn()>(),
- "attempted to zero-initialize type `fn()`, which is invalid"
+ || mem::uninitialized::<&i32>(),
+ "attempted to leave type `&i32` uninitialized, which is invalid"
);
test_panic_msg(
- || mem::uninitialized::<*const dyn Send>(),
- "attempted to leave type `*const dyn core::marker::Send` uninitialized, which is invalid"
+ || mem::zeroed::<Box<[i32; 0]>>(),
+ "attempted to zero-initialize type `alloc::boxed::Box<[i32; 0]>`, which is invalid"
+ );
+ test_panic_msg(
+ || mem::uninitialized::<Box<[i32; 0]>>(),
+ "attempted to leave type `alloc::boxed::Box<[i32; 0]>` uninitialized, which is invalid"
+ );
+
+ test_panic_msg(
+ || mem::zeroed::<Box<u8>>(),
+ "attempted to zero-initialize type `alloc::boxed::Box<u8>`, which is invalid"
);
test_panic_msg(
+ || mem::uninitialized::<Box<u8>>(),
+ "attempted to leave type `alloc::boxed::Box<u8>` uninitialized, which is invalid"
+ );
+
+ test_panic_msg(
+ || mem::zeroed::<&[i32]>(),
+ "attempted to zero-initialize type `&[i32]`, which is invalid"
+ );
+ test_panic_msg(
+ || mem::uninitialized::<&[i32]>(),
+ "attempted to leave type `&[i32]` uninitialized, which is invalid"
+ );
+
+ test_panic_msg(
+ || mem::zeroed::<&(u8, [u8])>(),
+ "attempted to zero-initialize type `&(u8, [u8])`, which is invalid"
+ );
+ test_panic_msg(
+ || mem::uninitialized::<&(u8, [u8])>(),
+ "attempted to leave type `&(u8, [u8])` uninitialized, which is invalid"
+ );
+
+ test_panic_msg(
+ || mem::zeroed::<&dyn Send>(),
+ "attempted to zero-initialize type `&dyn core::marker::Send`, which is invalid"
+ );
+ test_panic_msg(
+ || mem::uninitialized::<&dyn Send>(),
+ "attempted to leave type `&dyn core::marker::Send` uninitialized, which is invalid"
+ );
+
+ test_panic_msg(
|| mem::zeroed::<*const dyn Send>(),
"attempted to zero-initialize type `*const dyn core::marker::Send`, which is invalid"
);
+ test_panic_msg(
+ || mem::uninitialized::<*const dyn Send>(),
+ "attempted to leave type `*const dyn core::marker::Send` uninitialized, which is invalid"
+ );
test_panic_msg(
- || mem::uninitialized::<(NonNull<u32>, u32, u32)>(),
- "attempted to leave type `(core::ptr::non_null::NonNull<u32>, u32, u32)` uninitialized, \
+ || mem::uninitialized::<NoNullVariant>(),
+ "attempted to leave type `NoNullVariant` uninitialized, \
+ which is invalid"
+ );
+ test_panic_msg(
+ || mem::zeroed::<NoNullVariant>(),
+ "attempted to zero-initialize type `NoNullVariant`, \
which is invalid"
);
test_panic_msg(
- || mem::zeroed::<(NonNull<u32>, u32, u32)>(),
- "attempted to zero-initialize type `(core::ptr::non_null::NonNull<u32>, u32, u32)`, \
+ || mem::zeroed::<OneVariant_Ref>(),
+ "attempted to zero-initialize type `OneVariant_Ref`, \
which is invalid"
);
+ test_panic_msg(
+ || mem::uninitialized::<OneVariant_Ref>(),
+ "attempted to leave type `OneVariant_Ref` uninitialized, which is invalid"
+ );
+ // Types where both are invalid, but we allow uninit since the 0x01-filling is not LLVM UB.
test_panic_msg(
- || mem::uninitialized::<OneVariant_NonZero>(),
- "attempted to leave type `OneVariant_NonZero` uninitialized, \
+ || mem::zeroed::<fn()>(),
+ "attempted to zero-initialize type `fn()`, which is invalid"
+ );
+ test_panic_msg_only_if_strict(
+ || mem::uninitialized::<fn()>(),
+ "attempted to leave type `fn()` uninitialized, which is invalid"
+ );
+
+ test_panic_msg(
+ || mem::zeroed::<&()>(),
+ "attempted to zero-initialize type `&()`, which is invalid"
+ );
+ test_panic_msg_only_if_strict(
+ || mem::uninitialized::<&()>(),
+ "attempted to leave type `&()` uninitialized, which is invalid"
+ );
+
+ test_panic_msg(
+ || mem::zeroed::<&[u8]>(),
+ "attempted to zero-initialize type `&[u8]`, which is invalid"
+ );
+ test_panic_msg_only_if_strict(
+ || mem::uninitialized::<&[u8]>(),
+ "attempted to leave type `&[u8]` uninitialized, which is invalid"
+ );
+
+ test_panic_msg(
+ || mem::zeroed::<&str>(),
+ "attempted to zero-initialize type `&str`, which is invalid"
+ );
+ test_panic_msg_only_if_strict(
+ || mem::uninitialized::<&str>(),
+ "attempted to leave type `&str` uninitialized, which is invalid"
+ );
+
+ test_panic_msg(
+ || mem::zeroed::<(NonNull<u32>, u32, u32)>(),
+ "attempted to zero-initialize type `(core::ptr::non_null::NonNull<u32>, u32, u32)`, \
which is invalid"
);
+ test_panic_msg_only_if_strict(
+ || mem::uninitialized::<(NonNull<u32>, u32, u32)>(),
+ "attempted to leave type `(core::ptr::non_null::NonNull<u32>, u32, u32)` uninitialized, which is invalid"
+ );
+
test_panic_msg(
|| mem::zeroed::<OneVariant_NonZero>(),
"attempted to zero-initialize type `OneVariant_NonZero`, \
which is invalid"
);
+ test_panic_msg_only_if_strict(
+ || mem::uninitialized::<OneVariant_NonZero>(),
+ "attempted to leave type `OneVariant_NonZero` uninitialized, which is invalid"
+ );
+ // Types where both are invalid but we allow the zeroed form since it is not LLVM UB.
+ test_panic_msg_only_if_strict(
+ || mem::zeroed::<LR_NonZero>(),
+ "attempted to zero-initialize type `LR_NonZero`, which is invalid"
+ );
test_panic_msg(
|| mem::uninitialized::<LR_NonZero>(),
"attempted to leave type `LR_NonZero` uninitialized, which is invalid"
);
+ test_panic_msg_only_if_strict(
+ || mem::zeroed::<ManuallyDrop<LR_NonZero>>(),
+ "attempted to zero-initialize type `core::mem::manually_drop::ManuallyDrop<LR_NonZero>`, \
+ which is invalid"
+ );
test_panic_msg(
|| mem::uninitialized::<ManuallyDrop<LR_NonZero>>(),
"attempted to leave type `core::mem::manually_drop::ManuallyDrop<LR_NonZero>` uninitialized, \
which is invalid"
);
- test_panic_msg(
- || mem::uninitialized::<NoNullVariant>(),
- "attempted to leave type `NoNullVariant` uninitialized, \
- which is invalid"
+ // Some strict-only things
+ test_panic_msg_only_if_strict(
+ || mem::uninitialized::<i32>(),
+ "attempted to leave type `i32` uninitialized, which is invalid"
);
- test_panic_msg(
- || mem::zeroed::<NoNullVariant>(),
- "attempted to zero-initialize type `NoNullVariant`, \
- which is invalid"
+ test_panic_msg_only_if_strict(
+ || mem::uninitialized::<*const ()>(),
+ "attempted to leave type `*const ()` uninitialized, which is invalid"
);
- // Types that can be zero, but not uninit.
- test_panic_msg(
- || mem::uninitialized::<bool>(),
- "attempted to leave type `bool` uninitialized, which is invalid"
+ test_panic_msg_only_if_strict(
+ || mem::uninitialized::<[i32; 1]>(),
+ "attempted to leave type `[i32; 1]` uninitialized, which is invalid"
);
+ test_panic_msg_only_if_strict(
+ || mem::zeroed::<[NonNull<()>; 1]>(),
+ "attempted to zero-initialize type `[core::ptr::non_null::NonNull<()>; 1]`, which is invalid"
+ );
+
+ // Types that can be zero, but not uninit (though some are mitigated).
+ let _val = mem::zeroed::<LR>();
test_panic_msg(
|| mem::uninitialized::<LR>(),
"attempted to leave type `LR` uninitialized, which is invalid"
);
+ let _val = mem::zeroed::<ManuallyDrop<LR>>();
test_panic_msg(
|| mem::uninitialized::<ManuallyDrop<LR>>(),
"attempted to leave type `core::mem::manually_drop::ManuallyDrop<LR>` uninitialized, which is invalid"
);
- // Some things that should work.
let _val = mem::zeroed::<bool>();
- let _val = mem::zeroed::<LR>();
- let _val = mem::zeroed::<ManuallyDrop<LR>>();
+ test_panic_msg_only_if_strict(
+ || mem::uninitialized::<bool>(),
+ "attempted to leave type `bool` uninitialized, which is invalid"
+ );
+
let _val = mem::zeroed::<OneVariant>();
+ test_panic_msg_only_if_strict(
+ || mem::uninitialized::<OneVariant>(),
+ "attempted to leave type `OneVariant` uninitialized, which is invalid"
+ );
+
+ // Some things that are actually allowed.
let _val = mem::zeroed::<Option<&'static i32>>();
let _val = mem::zeroed::<MaybeUninit<NonNull<u32>>>();
let _val = mem::zeroed::<[!; 0]>();
@@ -234,59 +373,5 @@ fn main() {
let _val = mem::uninitialized::<[!; 0]>();
let _val = mem::uninitialized::<()>();
let _val = mem::uninitialized::<ZeroSized>();
-
- if cfg!(strict) {
- test_panic_msg(
- || mem::uninitialized::<i32>(),
- "attempted to leave type `i32` uninitialized, which is invalid"
- );
-
- test_panic_msg(
- || mem::uninitialized::<*const ()>(),
- "attempted to leave type `*const ()` uninitialized, which is invalid"
- );
-
- test_panic_msg(
- || mem::uninitialized::<[i32; 1]>(),
- "attempted to leave type `[i32; 1]` uninitialized, which is invalid"
- );
-
- test_panic_msg(
- || mem::zeroed::<NonNull<()>>(),
- "attempted to zero-initialize type `core::ptr::non_null::NonNull<()>`, which is invalid"
- );
-
- test_panic_msg(
- || mem::zeroed::<[NonNull<()>; 1]>(),
- "attempted to zero-initialize type `[core::ptr::non_null::NonNull<()>; 1]`, which is invalid"
- );
-
- // FIXME(#66151) we conservatively do not error here yet (by default).
- test_panic_msg(
- || mem::zeroed::<LR_NonZero>(),
- "attempted to zero-initialize type `LR_NonZero`, which is invalid"
- );
-
- test_panic_msg(
- || mem::zeroed::<ManuallyDrop<LR_NonZero>>(),
- "attempted to zero-initialize type `core::mem::manually_drop::ManuallyDrop<LR_NonZero>`, \
- which is invalid"
- );
- } else {
- // These are UB because they have not been officially blessed, but we await the resolution
- // of <https://github.com/rust-lang/unsafe-code-guidelines/issues/71> before doing
- // anything about that.
- let _val = mem::uninitialized::<i32>();
- let _val = mem::uninitialized::<*const ()>();
-
- // These are UB, but best to test them to ensure we don't become unintentionally
- // stricter.
-
- // It's currently unchecked to create invalid enums and values inside arrays.
- let _val = mem::zeroed::<LR_NonZero>();
- let _val = mem::zeroed::<[LR_NonZero; 1]>();
- let _val = mem::zeroed::<[NonNull<()>; 1]>();
- let _val = mem::uninitialized::<[NonNull<()>; 1]>();
- }
}
}
diff --git a/src/test/ui/intrinsics/safe-intrinsic-mismatch.rs b/src/test/ui/intrinsics/safe-intrinsic-mismatch.rs
new file mode 100644
index 000000000..50e12eaeb
--- /dev/null
+++ b/src/test/ui/intrinsics/safe-intrinsic-mismatch.rs
@@ -0,0 +1,11 @@
+#![feature(intrinsics)]
+#![feature(rustc_attrs)]
+
+extern "rust-intrinsic" {
+ fn size_of<T>() -> usize; //~ ERROR intrinsic safety mismatch
+
+ #[rustc_safe_intrinsic]
+ fn assume(b: bool); //~ ERROR intrinsic safety mismatch
+}
+
+fn main() {}
diff --git a/src/test/ui/intrinsics/safe-intrinsic-mismatch.stderr b/src/test/ui/intrinsics/safe-intrinsic-mismatch.stderr
new file mode 100644
index 000000000..0c2f3be49
--- /dev/null
+++ b/src/test/ui/intrinsics/safe-intrinsic-mismatch.stderr
@@ -0,0 +1,14 @@
+error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `size_of`
+ --> $DIR/safe-intrinsic-mismatch.rs:5:5
+ |
+LL | fn size_of<T>() -> usize;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `assume`
+ --> $DIR/safe-intrinsic-mismatch.rs:8:5
+ |
+LL | fn assume(b: bool);
+ | ^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/invalid/invalid-inline.rs b/src/test/ui/invalid/invalid-inline.rs
index 8aa8f99f5..2501b1e23 100644
--- a/src/test/ui/invalid/invalid-inline.rs
+++ b/src/test/ui/invalid/invalid-inline.rs
@@ -1,19 +1,14 @@
#![allow(dead_code)]
-#[inline(please_no)] //~ ERROR invalid argument
-fn a() {
-}
-
#[inline(please,no)] //~ ERROR expected one argument
-fn b() {
+fn a() {
}
#[inline()] //~ ERROR expected one argument
-fn c() {
+fn b() {
}
fn main() {
a();
b();
- c();
}
diff --git a/src/test/ui/invalid/invalid-inline.stderr b/src/test/ui/invalid/invalid-inline.stderr
index f3d042641..7edbf936b 100644
--- a/src/test/ui/invalid/invalid-inline.stderr
+++ b/src/test/ui/invalid/invalid-inline.stderr
@@ -1,22 +1,15 @@
-error[E0535]: invalid argument
- --> $DIR/invalid-inline.rs:3:10
- |
-LL | #[inline(please_no)]
- | ^^^^^^^^^
-
error[E0534]: expected one argument
- --> $DIR/invalid-inline.rs:7:1
+ --> $DIR/invalid-inline.rs:3:1
|
LL | #[inline(please,no)]
| ^^^^^^^^^^^^^^^^^^^^
error[E0534]: expected one argument
- --> $DIR/invalid-inline.rs:11:1
+ --> $DIR/invalid-inline.rs:7:1
|
LL | #[inline()]
| ^^^^^^^^^^^
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
-Some errors have detailed explanations: E0534, E0535.
-For more information about an error, try `rustc --explain E0534`.
+For more information about this error, try `rustc --explain E0534`.
diff --git a/src/test/ui/invalid/invalid-llvm-passes.rs b/src/test/ui/invalid/invalid-llvm-passes.rs
index ca3c6230a..ee28f5eb6 100644
--- a/src/test/ui/invalid/invalid-llvm-passes.rs
+++ b/src/test/ui/invalid/invalid-llvm-passes.rs
@@ -1,4 +1,4 @@
// build-fail
-// compile-flags: -Cpasses=unknown-pass -Z new-llvm-pass-manager=yes
+// compile-flags: -Cpasses=unknown-pass
fn main() {}
diff --git a/src/test/ui/issues/issue-102964.rs b/src/test/ui/issues/issue-102964.rs
new file mode 100644
index 000000000..43ff23600
--- /dev/null
+++ b/src/test/ui/issues/issue-102964.rs
@@ -0,0 +1,10 @@
+use std::rc::Rc;
+type Foo<'a, T> = &'a dyn Fn(&T);
+type RcFoo<'a, T> = Rc<Foo<'a, T>>;
+
+fn bar_function<T>(function: Foo<T>) -> RcFoo<T> {
+ //~^ ERROR mismatched types
+ let rc = Rc::new(function);
+}
+
+fn main() {}
diff --git a/src/test/ui/issues/issue-102964.stderr b/src/test/ui/issues/issue-102964.stderr
new file mode 100644
index 000000000..450403909
--- /dev/null
+++ b/src/test/ui/issues/issue-102964.stderr
@@ -0,0 +1,19 @@
+error[E0308]: mismatched types
+ --> $DIR/issue-102964.rs:5:41
+ |
+LL | fn bar_function<T>(function: Foo<T>) -> RcFoo<T> {
+ | ------------ ^^^^^^^^ expected struct `Rc`, found `()`
+ | |
+ | implicitly returns `()` as its body has no tail or `return` expression
+ |
+ = note: expected struct `Rc<&dyn for<'a> Fn(&'a T)>`
+ found unit type `()`
+help: consider returning the local binding `rc`
+ |
+LL ~ let rc = Rc::new(function);
+LL + rc
+ |
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/issues/issue-11958.stderr b/src/test/ui/issues/issue-11958.stderr
index 25de6ff4c..5dca4c2f0 100644
--- a/src/test/ui/issues/issue-11958.stderr
+++ b/src/test/ui/issues/issue-11958.stderr
@@ -4,8 +4,8 @@ warning: value assigned to `x` is never read
LL | let _thunk = Box::new(move|| { x = 2; });
| ^
|
- = note: `#[warn(unused_assignments)]` on by default
= help: maybe it is overwritten before being read?
+ = note: `#[warn(unused_assignments)]` on by default
warning: unused variable: `x`
--> $DIR/issue-11958.rs:8:36
@@ -13,8 +13,8 @@ warning: unused variable: `x`
LL | let _thunk = Box::new(move|| { x = 2; });
| ^
|
- = note: `#[warn(unused_variables)]` on by default
= help: did you mean to capture by reference instead?
+ = note: `#[warn(unused_variables)]` on by default
warning: 2 warnings emitted
diff --git a/src/test/ui/issues/issue-1460.stderr b/src/test/ui/issues/issue-1460.stderr
index 26f95f5af..f0ff2cafd 100644
--- a/src/test/ui/issues/issue-1460.stderr
+++ b/src/test/ui/issues/issue-1460.stderr
@@ -4,8 +4,8 @@ warning: unused closure that must be used
LL | {|i: u32| if 1 == i { }};
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unused_must_use)]` on by default
= note: closures are lazy and do nothing unless called
+ = note: `#[warn(unused_must_use)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/issues/issue-14875.rs b/src/test/ui/issues/issue-14875.rs
index aaef2aab9..fca330915 100644
--- a/src/test/ui/issues/issue-14875.rs
+++ b/src/test/ui/issues/issue-14875.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
// Check that values are not leaked when a dtor panics (#14875)
diff --git a/src/test/ui/issues/issue-16250.stderr b/src/test/ui/issues/issue-16250.stderr
index ae3b7f334..5eb5e0864 100644
--- a/src/test/ui/issues/issue-16250.stderr
+++ b/src/test/ui/issues/issue-16250.stderr
@@ -4,12 +4,6 @@ error: `extern` block uses type `Foo`, which is not FFI-safe
LL | pub fn foo(x: (Foo));
| ^^^ not FFI-safe
|
-note: the lint level is defined here
- --> $DIR/issue-16250.rs:1:9
- |
-LL | #![deny(warnings)]
- | ^^^^^^^^
- = note: `#[deny(improper_ctypes)]` implied by `#[deny(warnings)]`
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
note: the type is defined here
@@ -17,6 +11,12 @@ note: the type is defined here
|
LL | pub struct Foo;
| ^^^^^^^^^^^^^^
+note: the lint level is defined here
+ --> $DIR/issue-16250.rs:1:9
+ |
+LL | #![deny(warnings)]
+ | ^^^^^^^^
+ = note: `#[deny(improper_ctypes)]` implied by `#[deny(warnings)]`
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-16256.stderr b/src/test/ui/issues/issue-16256.stderr
index 9c7312461..ca8e9a1be 100644
--- a/src/test/ui/issues/issue-16256.stderr
+++ b/src/test/ui/issues/issue-16256.stderr
@@ -4,8 +4,8 @@ warning: unused closure that must be used
LL | |c: u8| buf.push(c);
| ^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unused_must_use)]` on by default
= note: closures are lazy and do nothing unless called
+ = note: `#[warn(unused_must_use)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/issues/issue-17431-1.stderr b/src/test/ui/issues/issue-17431-1.stderr
index db32eb952..e3af8976c 100644
--- a/src/test/ui/issues/issue-17431-1.stderr
+++ b/src/test/ui/issues/issue-17431-1.stderr
@@ -2,14 +2,12 @@ error[E0072]: recursive type `Foo` has infinite size
--> $DIR/issue-17431-1.rs:1:1
|
LL | struct Foo { foo: Option<Option<Foo>> }
- | ^^^^^^^^^^ ------------------- recursive without indirection
- | |
- | recursive type has infinite size
+ | ^^^^^^^^^^ --- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
-LL | struct Foo { foo: Option<Box<Option<Foo>>> }
- | ++++ +
+LL | struct Foo { foo: Option<Option<Box<Foo>>> }
+ | ++++ +
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-17431-2.rs b/src/test/ui/issues/issue-17431-2.rs
index 9ed97f631..f7b9c6a55 100644
--- a/src/test/ui/issues/issue-17431-2.rs
+++ b/src/test/ui/issues/issue-17431-2.rs
@@ -1,8 +1,7 @@
struct Baz { q: Option<Foo> }
-//~^ ERROR recursive type `Baz` has infinite size
+//~^ ERROR recursive types `Baz` and `Foo` have infinite size
struct Foo { q: Option<Baz> }
-//~^ ERROR recursive type `Foo` has infinite size
impl Foo { fn bar(&self) {} }
diff --git a/src/test/ui/issues/issue-17431-2.stderr b/src/test/ui/issues/issue-17431-2.stderr
index d23fd1474..39a99ec1e 100644
--- a/src/test/ui/issues/issue-17431-2.stderr
+++ b/src/test/ui/issues/issue-17431-2.stderr
@@ -1,29 +1,20 @@
-error[E0072]: recursive type `Baz` has infinite size
+error[E0072]: recursive types `Baz` and `Foo` have infinite size
--> $DIR/issue-17431-2.rs:1:1
|
LL | struct Baz { q: Option<Foo> }
- | ^^^^^^^^^^ ----------- recursive without indirection
- | |
- | recursive type has infinite size
- |
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Baz` representable
- |
-LL | struct Baz { q: Option<Box<Foo>> }
- | ++++ +
-
-error[E0072]: recursive type `Foo` has infinite size
- --> $DIR/issue-17431-2.rs:4:1
- |
+ | ^^^^^^^^^^ --- recursive without indirection
+...
LL | struct Foo { q: Option<Baz> }
- | ^^^^^^^^^^ ----------- recursive without indirection
- | |
- | recursive type has infinite size
+ | ^^^^^^^^^^ --- recursive without indirection
+ |
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
+LL ~ struct Baz { q: Option<Box<Foo>> }
+LL |
+LL |
+LL ~ struct Foo { q: Option<Box<Baz>> }
|
-LL | struct Foo { q: Option<Box<Baz>> }
- | ++++ +
-error: aborting due to 2 previous errors
+error: aborting due to previous error
For more information about this error, try `rustc --explain E0072`.
diff --git a/src/test/ui/issues/issue-17431-3.stderr b/src/test/ui/issues/issue-17431-3.stderr
index 0dde6f382..394134c78 100644
--- a/src/test/ui/issues/issue-17431-3.stderr
+++ b/src/test/ui/issues/issue-17431-3.stderr
@@ -2,14 +2,12 @@ error[E0072]: recursive type `Foo` has infinite size
--> $DIR/issue-17431-3.rs:3:1
|
LL | struct Foo { foo: Mutex<Option<Foo>> }
- | ^^^^^^^^^^ ------------------ recursive without indirection
- | |
- | recursive type has infinite size
+ | ^^^^^^^^^^ --- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
-LL | struct Foo { foo: Box<Mutex<Option<Foo>>> }
- | ++++ +
+LL | struct Foo { foo: Mutex<Option<Box<Foo>>> }
+ | ++++ +
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-17431-4.stderr b/src/test/ui/issues/issue-17431-4.stderr
index ddf669b8f..3d141e44b 100644
--- a/src/test/ui/issues/issue-17431-4.stderr
+++ b/src/test/ui/issues/issue-17431-4.stderr
@@ -2,14 +2,12 @@ error[E0072]: recursive type `Foo` has infinite size
--> $DIR/issue-17431-4.rs:3:1
|
LL | struct Foo<T> { foo: Option<Option<Foo<T>>>, marker: marker::PhantomData<T> }
- | ^^^^^^^^^^^^^ ---------------------- recursive without indirection
- | |
- | recursive type has infinite size
+ | ^^^^^^^^^^^^^ ------ recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
-LL | struct Foo<T> { foo: Option<Box<Option<Foo<T>>>>, marker: marker::PhantomData<T> }
- | ++++ +
+LL | struct Foo<T> { foo: Option<Option<Box<Foo<T>>>>, marker: marker::PhantomData<T> }
+ | ++++ +
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-17431-5.stderr b/src/test/ui/issues/issue-17431-5.stderr
index a379598c2..44a90a6fe 100644
--- a/src/test/ui/issues/issue-17431-5.stderr
+++ b/src/test/ui/issues/issue-17431-5.stderr
@@ -3,10 +3,8 @@ error[E0072]: recursive type `Bar` has infinite size
|
LL | struct Bar<T> { x: Bar<Foo> , marker: marker::PhantomData<T> }
| ^^^^^^^^^^^^^ -------- recursive without indirection
- | |
- | recursive type has infinite size
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Bar` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | struct Bar<T> { x: Box<Bar<Foo>> , marker: marker::PhantomData<T> }
| ++++ +
diff --git a/src/test/ui/issues/issue-17431-6.stderr b/src/test/ui/issues/issue-17431-6.stderr
index fcac420b2..e0a822550 100644
--- a/src/test/ui/issues/issue-17431-6.stderr
+++ b/src/test/ui/issues/issue-17431-6.stderr
@@ -2,14 +2,12 @@ error[E0072]: recursive type `Foo` has infinite size
--> $DIR/issue-17431-6.rs:3:1
|
LL | enum Foo { X(Mutex<Option<Foo>>) }
- | ^^^^^^^^ ------------------ recursive without indirection
- | |
- | recursive type has infinite size
+ | ^^^^^^^^ --- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
-LL | enum Foo { X(Box<Mutex<Option<Foo>>>) }
- | ++++ +
+LL | enum Foo { X(Mutex<Option<Box<Foo>>>) }
+ | ++++ +
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-17431-7.stderr b/src/test/ui/issues/issue-17431-7.stderr
index 6f8a7e386..ecf072b8e 100644
--- a/src/test/ui/issues/issue-17431-7.stderr
+++ b/src/test/ui/issues/issue-17431-7.stderr
@@ -2,14 +2,12 @@ error[E0072]: recursive type `Foo` has infinite size
--> $DIR/issue-17431-7.rs:1:1
|
LL | enum Foo { Voo(Option<Option<Foo>>) }
- | ^^^^^^^^ ------------------- recursive without indirection
- | |
- | recursive type has infinite size
+ | ^^^^^^^^ --- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
-LL | enum Foo { Voo(Option<Box<Option<Foo>>>) }
- | ++++ +
+LL | enum Foo { Voo(Option<Option<Box<Foo>>>) }
+ | ++++ +
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-18919.stderr b/src/test/ui/issues/issue-18919.stderr
index d7dbb8299..b0b03a0ee 100644
--- a/src/test/ui/issues/issue-18919.stderr
+++ b/src/test/ui/issues/issue-18919.stderr
@@ -1,10 +1,10 @@
-error[E0277]: the size for values of type `dyn for<'r> Fn(&'r isize) -> isize` cannot be known at compilation time
+error[E0277]: the size for values of type `dyn for<'a> Fn(&'a isize) -> isize` cannot be known at compilation time
--> $DIR/issue-18919.rs:3:15
|
LL | fn ho_func(f: Option<FuncType>) {
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
- = help: the trait `Sized` is not implemented for `dyn for<'r> Fn(&'r isize) -> isize`
+ = help: the trait `Sized` is not implemented for `dyn for<'a> Fn(&'a isize) -> isize`
note: required by a bound in `Option`
--> $DIR/issue-18919.rs:7:13
|
diff --git a/src/test/ui/issues/issue-19991.rs b/src/test/ui/issues/issue-19991.rs
index 1f3b73f96..dd0efa972 100644
--- a/src/test/ui/issues/issue-19991.rs
+++ b/src/test/ui/issues/issue-19991.rs
@@ -3,7 +3,7 @@
fn main() {
if let Some(homura) = Some("madoka") { //~ ERROR missing an `else` clause
- //~| expected `()`, found integer
+ //~| expected integer, found `()`
765
};
}
diff --git a/src/test/ui/issues/issue-19991.stderr b/src/test/ui/issues/issue-19991.stderr
index 6e92be87a..57b0882b6 100644
--- a/src/test/ui/issues/issue-19991.stderr
+++ b/src/test/ui/issues/issue-19991.stderr
@@ -6,7 +6,7 @@ LL | |
LL | | 765
| | --- found here
LL | | };
- | |_____^ expected `()`, found integer
+ | |_____^ expected integer, found `()`
|
= note: `if` expressions without `else` evaluate to `()`
= help: consider adding an `else` block that evaluates to the expected type
diff --git a/src/test/ui/issues/issue-21174.stderr b/src/test/ui/issues/issue-21174.stderr
index 09402c3d8..5981d9dc7 100644
--- a/src/test/ui/issues/issue-21174.stderr
+++ b/src/test/ui/issues/issue-21174.stderr
@@ -4,8 +4,8 @@ error[E0512]: cannot transmute between types of different sizes, or dependently-
LL | let new: T::B = unsafe { std::mem::transmute(value) };
| ^^^^^^^^^^^^^^^^^^^
|
- = note: source type: `<T as Trait>::A` (this type does not have a fixed size)
- = note: target type: `<T as Trait>::B` (this type does not have a fixed size)
+ = note: source type: `<T as Trait<'_>>::A` (this type does not have a fixed size)
+ = note: target type: `<T as Trait<'_>>::B` (this type does not have a fixed size)
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-22644.rs b/src/test/ui/issues/issue-22644.rs
index 9244ff593..b1d69dcd8 100644
--- a/src/test/ui/issues/issue-22644.rs
+++ b/src/test/ui/issues/issue-22644.rs
@@ -29,7 +29,7 @@ fn main() {
< //~ ERROR `<` is interpreted as a start of generic
5);
- println!("{}", a as usize << long_name); //~ ERROR `<` is interpreted as a start of generic
+ println!("{}", a as usize << long_name); //~ ERROR `<<` is interpreted as a start of generic
println!("{}", a: &mut 4); //~ ERROR expected type, found `4`
}
diff --git a/src/test/ui/issues/issue-22644.stderr b/src/test/ui/issues/issue-22644.stderr
index 039ffbfd3..45027afa7 100644
--- a/src/test/ui/issues/issue-22644.stderr
+++ b/src/test/ui/issues/issue-22644.stderr
@@ -95,7 +95,7 @@ LL |
LL ~ usize)
|
-error: `<` is interpreted as a start of generic arguments for `usize`, not a shift
+error: `<<` is interpreted as a start of generic arguments for `usize`, not a shift
--> $DIR/issue-22644.rs:32:31
|
LL | println!("{}", a as usize << long_name);
diff --git a/src/test/ui/issues/issue-23122-2.rs b/src/test/ui/issues/issue-23122-2.rs
index 95e1f60d8..338789c2e 100644
--- a/src/test/ui/issues/issue-23122-2.rs
+++ b/src/test/ui/issues/issue-23122-2.rs
@@ -1,3 +1,4 @@
+// normalize-stderr-test: "long-type-\d+" -> "long-type-hash"
trait Next {
type Next: Next;
}
diff --git a/src/test/ui/issues/issue-23122-2.stderr b/src/test/ui/issues/issue-23122-2.stderr
index f6cda3de5..0111cf569 100644
--- a/src/test/ui/issues/issue-23122-2.stderr
+++ b/src/test/ui/issues/issue-23122-2.stderr
@@ -1,10 +1,15 @@
-error[E0275]: overflow evaluating the requirement `<T as Next>::Next`
- --> $DIR/issue-23122-2.rs:10:17
+error[E0275]: overflow evaluating the requirement `<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<T as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next: Sized`
+ --> $DIR/issue-23122-2.rs:11:17
|
LL | type Next = <GetNext<T::Next> as Next>::Next;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_23122_2`)
+note: required for `GetNext<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<T as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next as Next>::Next>` to implement `Next`
+ --> $DIR/issue-23122-2.rs:10:15
+ |
+LL | impl<T: Next> Next for GetNext<T> {
+ | ^^^^ ^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-24013.stderr b/src/test/ui/issues/issue-24013.stderr
index 995dce552..72102f460 100644
--- a/src/test/ui/issues/issue-24013.stderr
+++ b/src/test/ui/issues/issue-24013.stderr
@@ -3,11 +3,6 @@ error[E0282]: type annotations needed
|
LL | unsafe {swap::<&mut _>(transmute(&a), transmute(&b))};
| ^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `swap`
- |
-help: consider specifying the generic argument
- |
-LL | unsafe {swap::<&mut _>(transmute(&a), transmute(&b))};
- | ~~~~~~~~~~
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-24322.stderr b/src/test/ui/issues/issue-24322.stderr
index 1a4fab165..1e4c8ac7c 100644
--- a/src/test/ui/issues/issue-24322.stderr
+++ b/src/test/ui/issues/issue-24322.stderr
@@ -6,8 +6,8 @@ LL | let x: &fn(&B) -> u32 = &B::func;
| |
| expected due to this
|
- = note: expected reference `&for<'r> fn(&'r B) -> u32`
- found reference `&for<'r> fn(&'r B) -> u32 {B::func}`
+ = note: expected reference `&for<'a> fn(&'a B) -> u32`
+ found reference `&for<'a> fn(&'a B) -> u32 {B::func}`
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-25901.rs b/src/test/ui/issues/issue-25901.rs
index ba12e1ad0..1f7b341a9 100644
--- a/src/test/ui/issues/issue-25901.rs
+++ b/src/test/ui/issues/issue-25901.rs
@@ -2,7 +2,7 @@ struct A;
struct B;
static S: &'static B = &A;
-//~^ ERROR cannot perform deref coercion on `A` in statics
+//~^ ERROR the trait bound
use std::ops::Deref;
diff --git a/src/test/ui/issues/issue-25901.stderr b/src/test/ui/issues/issue-25901.stderr
index c6c80e41c..b9cac3222 100644
--- a/src/test/ui/issues/issue-25901.stderr
+++ b/src/test/ui/issues/issue-25901.stderr
@@ -1,23 +1,15 @@
-error[E0015]: cannot perform deref coercion on `A` in statics
+error[E0277]: the trait bound `A: Deref` is not satisfied
--> $DIR/issue-25901.rs:4:24
|
LL | static S: &'static B = &A;
- | ^^
- |
- = note: attempting to deref into `B`
-note: deref defined here
- --> $DIR/issue-25901.rs:10:5
+ | ^^ the trait `~const Deref` is not implemented for `A`
|
-LL | type Target = B;
- | ^^^^^^^^^^^
-note: impl defined here, but it is not `const`
- --> $DIR/issue-25901.rs:9:1
+note: the trait `Deref` is implemented for `A`, but that implementation is not `const`
+ --> $DIR/issue-25901.rs:4:24
|
-LL | impl Deref for A {
- | ^^^^^^^^^^^^^^^^
- = note: calls in statics are limited to constant functions, tuple structs and tuple variants
- = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
+LL | static S: &'static B = &A;
+ | ^^
error: aborting due to previous error
-For more information about this error, try `rustc --explain E0015`.
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/issues/issue-28344.stderr b/src/test/ui/issues/issue-28344.stderr
index 85a8698af..f398a5da3 100644
--- a/src/test/ui/issues/issue-28344.stderr
+++ b/src/test/ui/issues/issue-28344.stderr
@@ -4,9 +4,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
| ^^^^^^
|
- = note: `#[warn(bare_trait_objects)]` on by default
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
|
LL | let x: u8 = <dyn BitXor>::bitor(0 as u8, 0 as u8);
diff --git a/src/test/ui/issues/issue-29746.rs b/src/test/ui/issues/issue-29746.rs
index 428cc637f..3470a7e09 100644
--- a/src/test/ui/issues/issue-29746.rs
+++ b/src/test/ui/issues/issue-29746.rs
@@ -7,7 +7,7 @@ macro_rules! zip {
zip!([$($rest),*], $a.zip($b), (x,y), [x,y])
};
- // Intermediate steps to build the zipped expression, the match pattern, and
+ // Intermediate steps to build the zipped expression, the match pattern
// and the output tuple of the closure, using macro hygiene to repeatedly
// introduce new variables named 'x'.
([$a:expr, $($rest:expr),*], $zip:expr, $pat:pat, [$($flat:expr),*]) => {
diff --git a/src/test/ui/issues/issue-29948.rs b/src/test/ui/issues/issue-29948.rs
index 01c3ec648..3ed701480 100644
--- a/src/test/ui/issues/issue-29948.rs
+++ b/src/test/ui/issues/issue-29948.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
use std::panic;
diff --git a/src/test/ui/issues/issue-3008-1.stderr b/src/test/ui/issues/issue-3008-1.stderr
index e49d8e6aa..be25b9091 100644
--- a/src/test/ui/issues/issue-3008-1.stderr
+++ b/src/test/ui/issues/issue-3008-1.stderr
@@ -2,12 +2,12 @@ error[E0072]: recursive type `Bar` has infinite size
--> $DIR/issue-3008-1.rs:5:1
|
LL | enum Bar {
- | ^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^
...
LL | BarSome(Bar)
| --- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Bar` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | BarSome(Box<Bar>)
| ++++ +
diff --git a/src/test/ui/issues/issue-3008-2.stderr b/src/test/ui/issues/issue-3008-2.stderr
index b3ce6e420..858a8fd6a 100644
--- a/src/test/ui/issues/issue-3008-2.stderr
+++ b/src/test/ui/issues/issue-3008-2.stderr
@@ -3,10 +3,8 @@ error[E0072]: recursive type `Bar` has infinite size
|
LL | struct Bar { x: Bar }
| ^^^^^^^^^^ --- recursive without indirection
- | |
- | recursive type has infinite size
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Bar` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | struct Bar { x: Box<Bar> }
| ++++ +
diff --git a/src/test/ui/issues/issue-3008-3.stderr b/src/test/ui/issues/issue-3008-3.stderr
index c1c043e21..a1a81e293 100644
--- a/src/test/ui/issues/issue-3008-3.stderr
+++ b/src/test/ui/issues/issue-3008-3.stderr
@@ -3,10 +3,8 @@ error[E0072]: recursive type `E2` has infinite size
|
LL | enum E2<T> { V2(E2<E1>, marker::PhantomData<T>), }
| ^^^^^^^^^^ ------ recursive without indirection
- | |
- | recursive type has infinite size
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `E2` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | enum E2<T> { V2(Box<E2<E1>>, marker::PhantomData<T>), }
| ++++ +
diff --git a/src/test/ui/issues/issue-30371.rs b/src/test/ui/issues/issue-30371.rs
index a1ae9a36b..eea548c48 100644
--- a/src/test/ui/issues/issue-30371.rs
+++ b/src/test/ui/issues/issue-30371.rs
@@ -1,5 +1,6 @@
// run-pass
#![allow(unreachable_code)]
+#![allow(for_loops_over_fallibles)]
#![deny(unused_variables)]
fn main() {
diff --git a/src/test/ui/issues/issue-30490.rs b/src/test/ui/issues/issue-30490.rs
index 47c17e362..68d9c4de4 100644
--- a/src/test/ui/issues/issue-30490.rs
+++ b/src/test/ui/issues/issue-30490.rs
@@ -1,6 +1,7 @@
// run-pass
// ignore-emscripten no processes
// ignore-sgx no processes
+// ignore-fuchsia Child I/O swaps not privileged
// Previously libstd would set stdio descriptors of a child process
// by `dup`ing the requested descriptors to inherit directly into the
diff --git a/src/test/ui/issues/issue-32326.stderr b/src/test/ui/issues/issue-32326.stderr
index cea765850..dc51198d9 100644
--- a/src/test/ui/issues/issue-32326.stderr
+++ b/src/test/ui/issues/issue-32326.stderr
@@ -2,16 +2,14 @@ error[E0072]: recursive type `Expr` has infinite size
--> $DIR/issue-32326.rs:5:1
|
LL | enum Expr {
- | ^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^
LL | Plus(Expr, Expr),
- | ---- ---- recursive without indirection
- | |
- | recursive without indirection
+ | ---- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Expr` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
-LL | Plus(Box<Expr>, Box<Expr>),
- | ++++ + ++++ +
+LL | Plus(Box<Expr>, Expr),
+ | ++++ +
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-35241.stderr b/src/test/ui/issues/issue-35241.stderr
index 9ee7654a0..42a78ed97 100644
--- a/src/test/ui/issues/issue-35241.stderr
+++ b/src/test/ui/issues/issue-35241.stderr
@@ -11,7 +11,7 @@ LL | fn test() -> Foo { Foo }
|
= note: expected struct `Foo`
found fn item `fn(u32) -> Foo {Foo}`
-help: use parentheses to instantiate this tuple struct
+help: use parentheses to construct this tuple struct
|
LL | fn test() -> Foo { Foo(/* u32 */) }
| +++++++++++
diff --git a/src/test/ui/issues/issue-3563-2.rs b/src/test/ui/issues/issue-3563-2.rs
deleted file mode 100644
index 88a449b85..000000000
--- a/src/test/ui/issues/issue-3563-2.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-// check-pass
-// pretty-expanded FIXME #23616
-
-trait Canvas {
- fn add_point(&self, point: &isize);
- fn add_points(&self, shapes: &[isize]) {
- for pt in shapes {
- self.add_point(pt)
- }
- }
-
-}
-
-pub fn main() {}
diff --git a/src/test/ui/issues/issue-3779.stderr b/src/test/ui/issues/issue-3779.stderr
index e853d0f8c..a0dbcc920 100644
--- a/src/test/ui/issues/issue-3779.stderr
+++ b/src/test/ui/issues/issue-3779.stderr
@@ -2,12 +2,12 @@ error[E0072]: recursive type `S` has infinite size
--> $DIR/issue-3779.rs:1:1
|
LL | struct S {
- | ^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^
LL |
LL | element: Option<S>
- | --------- recursive without indirection
+ | - recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `S` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | element: Option<Box<S>>
| ++++ +
diff --git a/src/test/ui/issues/issue-40000.stderr b/src/test/ui/issues/issue-40000.stderr
index e6f0b5fbf..c41fbb9d2 100644
--- a/src/test/ui/issues/issue-40000.stderr
+++ b/src/test/ui/issues/issue-40000.stderr
@@ -4,7 +4,7 @@ error[E0308]: mismatched types
LL | foo(bar);
| ^^^ one type is more general than the other
|
- = note: expected trait object `dyn for<'r> Fn(&'r i32)`
+ = note: expected trait object `dyn for<'a> Fn(&'a i32)`
found trait object `dyn Fn(&i32)`
error[E0308]: mismatched types
@@ -13,7 +13,7 @@ error[E0308]: mismatched types
LL | foo(bar);
| ^^^ one type is more general than the other
|
- = note: expected trait object `dyn for<'r> Fn(&'r i32)`
+ = note: expected trait object `dyn for<'a> Fn(&'a i32)`
found trait object `dyn Fn(&i32)`
error: aborting due to 2 previous errors
diff --git a/src/test/ui/issues/issue-4265.stderr b/src/test/ui/issues/issue-4265.stderr
index 27e83d495..8c7303f3c 100644
--- a/src/test/ui/issues/issue-4265.stderr
+++ b/src/test/ui/issues/issue-4265.stderr
@@ -1,12 +1,12 @@
-error[E0201]: duplicate definitions with name `bar`:
+error[E0592]: duplicate definitions with name `bar`
--> $DIR/issue-4265.rs:10:5
|
LL | fn bar() {
- | -------- previous definition of `bar` here
+ | -------- other definition for `bar`
...
LL | fn bar() {
- | ^^^^^^^^ duplicate definition
+ | ^^^^^^^^ duplicate definitions for `bar`
error: aborting due to previous error
-For more information about this error, try `rustc --explain E0201`.
+For more information about this error, try `rustc --explain E0592`.
diff --git a/src/test/ui/issues/issue-43853.rs b/src/test/ui/issues/issue-43853.rs
index 3162c091c..dd42c1e3c 100644
--- a/src/test/ui/issues/issue-43853.rs
+++ b/src/test/ui/issues/issue-43853.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
use std::panic;
diff --git a/src/test/ui/issues/issue-46519.rs b/src/test/ui/issues/issue-46519.rs
index 9bd3c0948..0567923b7 100644
--- a/src/test/ui/issues/issue-46519.rs
+++ b/src/test/ui/issues/issue-46519.rs
@@ -2,7 +2,6 @@
// compile-flags:--test -O
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
#[test]
#[should_panic(expected = "creating inhabited type")]
diff --git a/src/test/ui/issues/issue-47094.stderr b/src/test/ui/issues/issue-47094.stderr
index e323ce660..970e31847 100644
--- a/src/test/ui/issues/issue-47094.stderr
+++ b/src/test/ui/issues/issue-47094.stderr
@@ -4,9 +4,9 @@ error[E0566]: conflicting representation hints
LL | #[repr(C, u8)]
| ^ ^^
|
- = note: `#[deny(conflicting_repr_hints)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/68585>
+ = note: `#[deny(conflicting_repr_hints)]` on by default
error[E0566]: conflicting representation hints
--> $DIR/issue-47094.rs:8:8
diff --git a/src/test/ui/issues/issue-47486.stderr b/src/test/ui/issues/issue-47486.stderr
index b45f57b7b..2bd24f08c 100644
--- a/src/test/ui/issues/issue-47486.stderr
+++ b/src/test/ui/issues/issue-47486.stderr
@@ -9,11 +9,6 @@ error[E0282]: type annotations needed
|
LL | [0u8; std::mem::size_of::<_>()];
| ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `size_of`
- |
-help: consider specifying the generic argument
- |
-LL | [0u8; std::mem::size_of::<_>()];
- | ~~~~~
error: aborting due to 2 previous errors
diff --git a/src/test/ui/issues/issue-47725.stderr b/src/test/ui/issues/issue-47725.stderr
index c7a9bfe31..7143fb4d6 100644
--- a/src/test/ui/issues/issue-47725.stderr
+++ b/src/test/ui/issues/issue-47725.stderr
@@ -13,12 +13,12 @@ LL | #[link_name = "foo"]
LL | struct Foo;
| ----------- not a foreign function or static
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
note: the lint level is defined here
--> $DIR/issue-47725.rs:1:9
|
LL | #![warn(unused_attributes)]
| ^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
warning: attribute should be applied to a foreign function or static
--> $DIR/issue-47725.rs:8:1
diff --git a/src/test/ui/issues/issue-50582.stderr b/src/test/ui/issues/issue-50582.stderr
index 3d527eb6b..53ecc6112 100644
--- a/src/test/ui/issues/issue-50582.stderr
+++ b/src/test/ui/issues/issue-50582.stderr
@@ -7,13 +7,13 @@ LL | Vec::<[(); 1 + for x in 0..1 {}]>::new();
= note: see issue #87575 <https://github.com/rust-lang/rust/issues/87575> for more information
= help: add `#![feature(const_for)]` to the crate attributes to enable
-error[E0277]: cannot add `()` to `{integer}`
+error[E0277]: cannot add `()` to `{integer}` in const contexts
--> $DIR/issue-50582.rs:2:18
|
LL | Vec::<[(); 1 + for x in 0..1 {}]>::new();
| ^ no implementation for `{integer} + ()`
|
- = help: the trait `Add<()>` is not implemented for `{integer}`
+ = help: the trait `~const Add<()>` is not implemented for `{integer}`
= help: the following other types implement trait `Add<Rhs>`:
<&'a f32 as Add<f32>>
<&'a f64 as Add<f64>>
diff --git a/src/test/ui/issues/issue-50781.stderr b/src/test/ui/issues/issue-50781.stderr
index 93bd951d3..e185ecdda 100644
--- a/src/test/ui/issues/issue-50781.stderr
+++ b/src/test/ui/issues/issue-50781.stderr
@@ -4,11 +4,6 @@ error: the trait `X` cannot be made into an object
LL | fn foo(&self) where Self: Trait;
| ^^^
|
-note: the lint level is defined here
- --> $DIR/issue-50781.rs:1:9
- |
-LL | #![deny(where_clauses_object_safety)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443>
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
@@ -19,6 +14,11 @@ LL | trait X {
LL | fn foo(&self) where Self: Trait;
| ^^^ ...because method `foo` references the `Self` type in its `where` clause
= help: consider moving `foo` to another trait
+note: the lint level is defined here
+ --> $DIR/issue-50781.rs:1:9
+ |
+LL | #![deny(where_clauses_object_safety)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-54044.stderr b/src/test/ui/issues/issue-54044.stderr
index 100965de1..8bd94a041 100644
--- a/src/test/ui/issues/issue-54044.stderr
+++ b/src/test/ui/issues/issue-54044.stderr
@@ -7,12 +7,12 @@ LL | #[cold]
LL | struct Foo;
| ----------- not a function definition
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
note: the lint level is defined here
--> $DIR/issue-54044.rs:1:9
|
LL | #![deny(unused_attributes)]
| ^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
error: attribute should be applied to a function definition
--> $DIR/issue-54044.rs:9:5
diff --git a/src/test/ui/issues/issue-55380.stderr b/src/test/ui/issues/issue-55380.stderr
index 65e94d796..403844c72 100644
--- a/src/test/ui/issues/issue-55380.stderr
+++ b/src/test/ui/issues/issue-55380.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/issues/issue-57271.rs b/src/test/ui/issues/issue-57271.rs
index 9940fecbe..f74222e3e 100644
--- a/src/test/ui/issues/issue-57271.rs
+++ b/src/test/ui/issues/issue-57271.rs
@@ -4,7 +4,7 @@ extern crate issue_57271_lib;
use issue_57271_lib::BaseType;
-pub enum ObjectType { //~ ERROR recursive type `ObjectType` has infinite size
+pub enum ObjectType { //~ ERROR recursive types `ObjectType` and `TypeSignature` have infinite size
Class(ClassTypeSignature),
Array(TypeSignature),
TypeVariable(()),
@@ -16,7 +16,7 @@ pub struct ClassTypeSignature {
pub inner: (),
}
-pub enum TypeSignature { //~ ERROR recursive type `TypeSignature` has infinite size
+pub enum TypeSignature {
Base(BaseType),
Object(ObjectType),
}
diff --git a/src/test/ui/issues/issue-57271.stderr b/src/test/ui/issues/issue-57271.stderr
index 825009665..391e69c91 100644
--- a/src/test/ui/issues/issue-57271.stderr
+++ b/src/test/ui/issues/issue-57271.stderr
@@ -1,31 +1,27 @@
-error[E0072]: recursive type `ObjectType` has infinite size
+error[E0072]: recursive types `ObjectType` and `TypeSignature` have infinite size
--> $DIR/issue-57271.rs:7:1
|
LL | pub enum ObjectType {
- | ^^^^^^^^^^^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^^^^^^^^^^^
LL | Class(ClassTypeSignature),
LL | Array(TypeSignature),
| ------------- recursive without indirection
- |
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `ObjectType` representable
- |
-LL | Array(Box<TypeSignature>),
- | ++++ +
-
-error[E0072]: recursive type `TypeSignature` has infinite size
- --> $DIR/issue-57271.rs:19:1
- |
+...
LL | pub enum TypeSignature {
- | ^^^^^^^^^^^^^^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^^^^^^^^^^^^^^
LL | Base(BaseType),
LL | Object(ObjectType),
| ---------- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `TypeSignature` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
+ |
+LL ~ Array(Box<TypeSignature>),
+LL | TypeVariable(()),
+ ...
+LL | Base(BaseType),
+LL ~ Object(Box<ObjectType>),
|
-LL | Object(Box<ObjectType>),
- | ++++ +
-error: aborting due to 2 previous errors
+error: aborting due to previous error
For more information about this error, try `rustc --explain E0072`.
diff --git a/src/test/ui/issues/issue-57362-2.stderr b/src/test/ui/issues/issue-57362-2.stderr
index 3b6cffeaf..7d08c4643 100644
--- a/src/test/ui/issues/issue-57362-2.stderr
+++ b/src/test/ui/issues/issue-57362-2.stderr
@@ -1,11 +1,11 @@
-error[E0599]: the function or associated item `make_g` exists for fn pointer `for<'r> fn(&'r ())`, but its trait bounds were not satisfied
+error[E0599]: the function or associated item `make_g` exists for fn pointer `for<'a> fn(&'a ())`, but its trait bounds were not satisfied
--> $DIR/issue-57362-2.rs:22:25
|
LL | let x = <fn (&())>::make_g();
- | ^^^^^^ function or associated item cannot be called on `for<'r> fn(&'r ())` due to unsatisfied trait bounds
+ | ^^^^^^ function or associated item cannot be called on `for<'a> fn(&'a ())` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
- `for<'r> fn(&'r ()): X`
+ `for<'a> fn(&'a ()): X`
= help: items from traits can only be used if the trait is implemented and in scope
note: `X` defines an item `make_g`, perhaps you need to implement it
--> $DIR/issue-57362-2.rs:8:1
diff --git a/src/test/ui/issues/issue-58022.stderr b/src/test/ui/issues/issue-58022.stderr
index 6d24209ad..56d85c066 100644
--- a/src/test/ui/issues/issue-58022.stderr
+++ b/src/test/ui/issues/issue-58022.stderr
@@ -1,9 +1,3 @@
-error[E0423]: expected function, tuple struct or tuple variant, found trait `Foo`
- --> $DIR/issue-58022.rs:14:9
- |
-LL | Foo(Box::new(*slice))
- | ^^^ not a function, tuple struct or tuple variant
-
error[E0790]: cannot refer to the associated constant on trait without specifying the corresponding `impl` type
--> $DIR/issue-58022.rs:4:25
|
@@ -13,6 +7,12 @@ LL |
LL | fn new(slice: &[u8; Foo::SIZE]) -> Self;
| ^^^^^^^^^ cannot refer to the associated constant of trait
+error[E0423]: expected function, tuple struct or tuple variant, found trait `Foo`
+ --> $DIR/issue-58022.rs:14:9
+ |
+LL | Foo(Box::new(*slice))
+ | ^^^ not a function, tuple struct or tuple variant
+
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0423, E0790.
diff --git a/src/test/ui/issues/issue-58734.stderr b/src/test/ui/issues/issue-58734.stderr
index a91a1b377..d2314626d 100644
--- a/src/test/ui/issues/issue-58734.stderr
+++ b/src/test/ui/issues/issue-58734.stderr
@@ -4,9 +4,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | Trait::nonexistent(());
| ^^^^^
|
- = note: `#[warn(bare_trait_objects)]` on by default
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
|
LL | <dyn Trait>::nonexistent(());
diff --git a/src/test/ui/issues/issue-59488.stderr b/src/test/ui/issues/issue-59488.stderr
index 08fe0b35e..f9846b62a 100644
--- a/src/test/ui/issues/issue-59488.stderr
+++ b/src/test/ui/issues/issue-59488.stderr
@@ -99,7 +99,7 @@ LL | assert_eq!(Foo::Bar, i);
extern "C" fn(A, B, C, D) -> Ret
extern "C" fn(A, B, C, D, ...) -> Ret
extern "C" fn(A, B, C, D, E) -> Ret
- and 68 others
+ and 118 others
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: `fn(usize) -> Foo {Foo::Bar}` doesn't implement `Debug`
@@ -118,7 +118,7 @@ LL | assert_eq!(Foo::Bar, i);
extern "C" fn(A, B, C, D) -> Ret
extern "C" fn(A, B, C, D, ...) -> Ret
extern "C" fn(A, B, C, D, E) -> Ret
- and 68 others
+ and 118 others
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 10 previous errors
diff --git a/src/test/ui/issues/issue-60622.stderr b/src/test/ui/issues/issue-60622.stderr
index b305cc785..ecf1ae758 100644
--- a/src/test/ui/issues/issue-60622.stderr
+++ b/src/test/ui/issues/issue-60622.stderr
@@ -7,14 +7,14 @@ LL | fn a(&self) {}
LL | b.a::<'_, T>();
| ^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
note: the lint level is defined here
--> $DIR/issue-60622.rs:1:9
|
LL | #![deny(warnings)]
| ^^^^^^^^
= note: `#[deny(late_bound_lifetime_arguments)]` implied by `#[deny(warnings)]`
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied
--> $DIR/issue-60622.rs:10:7
diff --git a/src/test/ui/issues/issue-6458-3.stderr b/src/test/ui/issues/issue-6458-3.stderr
index 2c3ec1a33..520efccae 100644
--- a/src/test/ui/issues/issue-6458-3.stderr
+++ b/src/test/ui/issues/issue-6458-3.stderr
@@ -2,12 +2,12 @@ error[E0282]: type annotations needed
--> $DIR/issue-6458-3.rs:4:5
|
LL | mem::transmute(0);
- | ^^^^^^^^^^^^^^ cannot infer type of the type parameter `U` declared on the function `transmute`
+ | ^^^^^^^^^^^^^^ cannot infer type of the type parameter `Dst` declared on the function `transmute`
|
help: consider specifying the generic arguments
|
-LL | mem::transmute::<i32, U>(0);
- | ++++++++++
+LL | mem::transmute::<i32, Dst>(0);
+ | ++++++++++++
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-6458-4.stderr b/src/test/ui/issues/issue-6458-4.stderr
index d6e74d10e..168ececac 100644
--- a/src/test/ui/issues/issue-6458-4.stderr
+++ b/src/test/ui/issues/issue-6458-4.stderr
@@ -6,7 +6,7 @@ LL | fn foo(b: bool) -> Result<bool,String> {
| |
| implicitly returns `()` as its body has no tail or `return` expression
LL | Err("bar".to_string());
- | - help: remove this semicolon
+ | - help: remove this semicolon to return this value
|
= note: expected enum `Result<bool, String>`
found unit type `()`
diff --git a/src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr b/src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr
index 7f29709ce..b30bcfb77 100644
--- a/src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr
+++ b/src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr
@@ -29,7 +29,7 @@ LL | assert_eq!(a, 0);
| ^^^^^^^^^^^^^^^^ `fn() -> i32 {a}` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= help: the trait `Debug` is not implemented for fn item `fn() -> i32 {a}`
- = help: use parentheses to call the function: `a()`
+ = help: use parentheses to call this function: `a()`
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 3 previous errors
diff --git a/src/test/ui/issues/issue-72278.stderr b/src/test/ui/issues/issue-72278.stderr
index 41dff686b..5468837a3 100644
--- a/src/test/ui/issues/issue-72278.stderr
+++ b/src/test/ui/issues/issue-72278.stderr
@@ -7,9 +7,9 @@ LL | fn func<'a, U>(&'a self) -> U {
LL | S.func::<'a, U>()
| ^^
|
- = note: `#[warn(late_bound_lifetime_arguments)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
+ = note: `#[warn(late_bound_lifetime_arguments)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/issues/issue-72554.rs b/src/test/ui/issues/issue-72554.rs
index 7287639c6..54f7e9ac5 100644
--- a/src/test/ui/issues/issue-72554.rs
+++ b/src/test/ui/issues/issue-72554.rs
@@ -3,7 +3,6 @@ use std::collections::BTreeSet;
#[derive(Hash)]
pub enum ElemDerived {
//~^ ERROR recursive type `ElemDerived` has infinite size
- //~| ERROR cycle detected when computing drop-check constraints for `ElemDerived`
A(ElemDerived)
}
diff --git a/src/test/ui/issues/issue-72554.stderr b/src/test/ui/issues/issue-72554.stderr
index 3e5adcae1..d12be539f 100644
--- a/src/test/ui/issues/issue-72554.stderr
+++ b/src/test/ui/issues/issue-72554.stderr
@@ -2,30 +2,16 @@ error[E0072]: recursive type `ElemDerived` has infinite size
--> $DIR/issue-72554.rs:4:1
|
LL | pub enum ElemDerived {
- | ^^^^^^^^^^^^^^^^^^^^ recursive type has infinite size
-...
+ | ^^^^^^^^^^^^^^^^^^^^
+LL |
LL | A(ElemDerived)
| ----------- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `ElemDerived` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | A(Box<ElemDerived>)
| ++++ +
-error[E0391]: cycle detected when computing drop-check constraints for `ElemDerived`
- --> $DIR/issue-72554.rs:4:1
- |
-LL | pub enum ElemDerived {
- | ^^^^^^^^^^^^^^^^^^^^
- |
- = note: ...which immediately requires computing drop-check constraints for `ElemDerived` again
-note: cycle used when computing drop-check constraints for `Elem`
- --> $DIR/issue-72554.rs:11:1
- |
-LL | pub enum Elem {
- | ^^^^^^^^^^^^^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
-Some errors have detailed explanations: E0072, E0391.
-For more information about an error, try `rustc --explain E0072`.
+For more information about this error, try `rustc --explain E0072`.
diff --git a/src/test/ui/issues/issue-75307.rs b/src/test/ui/issues/issue-75307.rs
index 2fe112a3b..cffa6bea8 100644
--- a/src/test/ui/issues/issue-75307.rs
+++ b/src/test/ui/issues/issue-75307.rs
@@ -1,3 +1,3 @@
fn main() {
- format!(r"{}{}{}", named_arg=1); //~ ERROR invalid reference to positional arguments 1 and 2
+ format!(r"{}{}{}", named_arg=1); //~ ERROR 3 positional arguments in format string, but there is 1 argument
}
diff --git a/src/test/ui/issues/issue-75307.stderr b/src/test/ui/issues/issue-75307.stderr
index 10c952006..c5b0b11e7 100644
--- a/src/test/ui/issues/issue-75307.stderr
+++ b/src/test/ui/issues/issue-75307.stderr
@@ -1,10 +1,8 @@
-error: invalid reference to positional arguments 1 and 2 (there is 1 argument)
- --> $DIR/issue-75307.rs:2:17
+error: 3 positional arguments in format string, but there is 1 argument
+ --> $DIR/issue-75307.rs:2:15
|
LL | format!(r"{}{}{}", named_arg=1);
- | ^^^^
- |
- = note: positional arguments are zero-based
+ | ^^^^^^ -
error: aborting due to previous error
diff --git a/src/test/ui/issues/issue-75907.rs b/src/test/ui/issues/issue-75907.rs
index 1534b6d07..6da99cf64 100644
--- a/src/test/ui/issues/issue-75907.rs
+++ b/src/test/ui/issues/issue-75907.rs
@@ -1,4 +1,4 @@
-// Test for for diagnostic improvement issue #75907
+// Test for diagnostic improvement issue #75907
mod foo {
pub(crate) struct Foo(u8);
diff --git a/src/test/ui/issues/issue-75907_b.rs b/src/test/ui/issues/issue-75907_b.rs
index e30747782..fdfc5907c 100644
--- a/src/test/ui/issues/issue-75907_b.rs
+++ b/src/test/ui/issues/issue-75907_b.rs
@@ -1,4 +1,4 @@
-// Test for for diagnostic improvement issue #75907, extern crate
+// Test for diagnostic improvement issue #75907, extern crate
// aux-build:issue-75907.rs
extern crate issue_75907 as a;
diff --git a/src/test/ui/issues/issue-77993-1.rs b/src/test/ui/issues/issue-77993-1.rs
deleted file mode 100644
index 515b3bc09..000000000
--- a/src/test/ui/issues/issue-77993-1.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-#[derive(Clone)]
-struct InGroup<F> {
- it: It,
- //~^ ERROR cannot find type `It` in this scope
- f: F,
-}
-fn dates_in_year() -> impl Clone {
- InGroup { f: |d| d }
- //~^ ERROR missing field `it` in initializer of `InGroup<_>`
-}
-
-fn main() {}
diff --git a/src/test/ui/issues/issue-77993-1.stderr b/src/test/ui/issues/issue-77993-1.stderr
deleted file mode 100644
index 3dc78ba6f..000000000
--- a/src/test/ui/issues/issue-77993-1.stderr
+++ /dev/null
@@ -1,16 +0,0 @@
-error[E0412]: cannot find type `It` in this scope
- --> $DIR/issue-77993-1.rs:3:9
- |
-LL | it: It,
- | ^^ not found in this scope
-
-error[E0063]: missing field `it` in initializer of `InGroup<_>`
- --> $DIR/issue-77993-1.rs:8:5
- |
-LL | InGroup { f: |d| d }
- | ^^^^^^^ missing `it`
-
-error: aborting due to 2 previous errors
-
-Some errors have detailed explanations: E0063, E0412.
-For more information about an error, try `rustc --explain E0063`.
diff --git a/src/test/ui/issues/issue-78957.stderr b/src/test/ui/issues/issue-78957.stderr
index 45fa69d6f..6de22d6bf 100644
--- a/src/test/ui/issues/issue-78957.stderr
+++ b/src/test/ui/issues/issue-78957.stderr
@@ -10,12 +10,12 @@ error: attribute should be applied to a function definition
LL | pub struct Bar<#[cold] const N: usize>;
| ^^^^^^^ -------------- not a function definition
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
note: the lint level is defined here
--> $DIR/issue-78957.rs:1:9
|
LL | #![deny(unused_attributes)]
| ^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-78957.rs:10:23
diff --git a/src/test/ui/issues/issue-86756.stderr b/src/test/ui/issues/issue-86756.stderr
index b26c1834d..693cfeced 100644
--- a/src/test/ui/issues/issue-86756.stderr
+++ b/src/test/ui/issues/issue-86756.stderr
@@ -20,9 +20,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | eq::<dyn, Foo>
| ^^^
|
- = note: `#[warn(bare_trait_objects)]` on by default
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
|
LL | eq::<dyn, dyn Foo>
diff --git a/src/test/ui/issues/issue-8727.stderr b/src/test/ui/issues/issue-8727.stderr
index 10daba5ef..5e1fdad60 100644
--- a/src/test/ui/issues/issue-8727.stderr
+++ b/src/test/ui/issues/issue-8727.stderr
@@ -6,8 +6,8 @@ LL | fn generic<T>() {
LL | generic::<Option<T>>();
| ---------------------- recursive call site
|
- = note: `#[warn(unconditional_recursion)]` on by default
= help: a `loop` may express intention better if this is on purpose
+ = note: `#[warn(unconditional_recursion)]` on by default
error: reached the recursion limit while instantiating `generic::<Option<Option<Option<O...>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
--> $DIR/issue-8727.rs:8:5
diff --git a/src/test/ui/issues/issue-87707.rs b/src/test/ui/issues/issue-87707.rs
index 26e9e2c8f..c14e52dfe 100644
--- a/src/test/ui/issues/issue-87707.rs
+++ b/src/test/ui/issues/issue-87707.rs
@@ -3,6 +3,7 @@
// run-fail
// exec-env:RUST_BACKTRACE=0
// check-run-results
+// needs-unwind uses catch_unwind
use std::sync::Once;
use std::panic;
diff --git a/src/test/ui/issues/issue-87707.run.stderr b/src/test/ui/issues/issue-87707.run.stderr
index e6c9ea0eb..527c78ba8 100644
--- a/src/test/ui/issues/issue-87707.run.stderr
+++ b/src/test/ui/issues/issue-87707.run.stderr
@@ -1,3 +1,3 @@
-thread 'main' panicked at 'Here Once instance is poisoned.', $DIR/issue-87707.rs:13:24
+thread 'main' panicked at 'Here Once instance is poisoned.', $DIR/issue-87707.rs:14:24
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
-thread 'main' panicked at 'Once instance has previously been poisoned', $DIR/issue-87707.rs:15:7
+thread 'main' panicked at 'Once instance has previously been poisoned', $DIR/issue-87707.rs:16:7
diff --git a/src/test/ui/issues/issue-99838.rs b/src/test/ui/issues/issue-99838.rs
index eaeeac72b..2e81d5e82 100644
--- a/src/test/ui/issues/issue-99838.rs
+++ b/src/test/ui/issues/issue-99838.rs
@@ -1,5 +1,5 @@
// run-pass
-#![feature(bench_black_box)]
+
use std::hint;
struct U16(u16);
diff --git a/src/test/ui/iterators/into-iter-on-arrays-2018.stderr b/src/test/ui/iterators/into-iter-on-arrays-2018.stderr
index 9b3125058..2378476e5 100644
--- a/src/test/ui/iterators/into-iter-on-arrays-2018.stderr
+++ b/src/test/ui/iterators/into-iter-on-arrays-2018.stderr
@@ -4,9 +4,9 @@ warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (du
LL | let _: Iter<'_, i32> = array.into_iter();
| ^^^^^^^^^
|
- = note: `#[warn(array_into_iter)]` on by default
= warning: this changes meaning in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
+ = note: `#[warn(array_into_iter)]` on by default
help: use `.iter()` instead of `.into_iter()` to avoid ambiguity
|
LL | let _: Iter<'_, i32> = array.iter();
diff --git a/src/test/ui/iterators/into-iter-on-arrays-lint.stderr b/src/test/ui/iterators/into-iter-on-arrays-lint.stderr
index e32d35d86..2fde276fa 100644
--- a/src/test/ui/iterators/into-iter-on-arrays-lint.stderr
+++ b/src/test/ui/iterators/into-iter-on-arrays-lint.stderr
@@ -4,9 +4,9 @@ warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (du
LL | small.into_iter();
| ^^^^^^^^^
|
- = note: `#[warn(array_into_iter)]` on by default
= warning: this changes meaning in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
+ = note: `#[warn(array_into_iter)]` on by default
help: use `.iter()` instead of `.into_iter()` to avoid ambiguity
|
LL | small.iter();
diff --git a/src/test/ui/iterators/iter-count-overflow-debug.rs b/src/test/ui/iterators/iter-count-overflow-debug.rs
index 15f25f1ca..8e59c11e9 100644
--- a/src/test/ui/iterators/iter-count-overflow-debug.rs
+++ b/src/test/ui/iterators/iter-count-overflow-debug.rs
@@ -1,7 +1,6 @@
// run-pass
// only-32bit too impatient for 2â¶â´ items
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C debug_assertions=yes -C opt-level=3
use std::panic;
diff --git a/src/test/ui/iterators/iter-position-overflow-debug.rs b/src/test/ui/iterators/iter-position-overflow-debug.rs
index 65124c282..7a871e744 100644
--- a/src/test/ui/iterators/iter-position-overflow-debug.rs
+++ b/src/test/ui/iterators/iter-position-overflow-debug.rs
@@ -1,7 +1,6 @@
// run-pass
// only-32bit too impatient for 2â¶â´ items
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C debug_assertions=yes -C opt-level=3
use std::panic;
diff --git a/src/test/ui/iterators/iter-step-overflow-debug.rs b/src/test/ui/iterators/iter-step-overflow-debug.rs
index e16f984de..6aa349ebe 100644
--- a/src/test/ui/iterators/iter-step-overflow-debug.rs
+++ b/src/test/ui/iterators/iter-step-overflow-debug.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C debug_assertions=yes
use std::panic;
diff --git a/src/test/ui/iterators/iter-sum-overflow-debug.rs b/src/test/ui/iterators/iter-sum-overflow-debug.rs
index d8ce43848..24c764ff9 100644
--- a/src/test/ui/iterators/iter-sum-overflow-debug.rs
+++ b/src/test/ui/iterators/iter-sum-overflow-debug.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C debug_assertions=yes
use std::panic;
diff --git a/src/test/ui/iterators/iter-sum-overflow-overflow-checks.rs b/src/test/ui/iterators/iter-sum-overflow-overflow-checks.rs
index bc8dcbdbb..be45c075d 100644
--- a/src/test/ui/iterators/iter-sum-overflow-overflow-checks.rs
+++ b/src/test/ui/iterators/iter-sum-overflow-overflow-checks.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: -C overflow-checks
use std::panic;
diff --git a/src/test/ui/keyword/keyword-self-as-type-param.stderr b/src/test/ui/keyword/keyword-self-as-type-param.stderr
index 419652e13..5aef94754 100644
--- a/src/test/ui/keyword/keyword-self-as-type-param.stderr
+++ b/src/test/ui/keyword/keyword-self-as-type-param.stderr
@@ -19,10 +19,8 @@ error[E0072]: recursive type `Foo` has infinite size
|
LL | struct Foo<Self>(Self);
| ^^^^^^^^^^^^^^^^ ---- recursive without indirection
- | |
- | recursive type has infinite size
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | struct Foo<Self>(Box<Self>);
| ++++ +
diff --git a/src/test/ui/lang-items/issue-83471.stderr b/src/test/ui/lang-items/issue-83471.stderr
index 6d796fe7f..b315df179 100644
--- a/src/test/ui/lang-items/issue-83471.stderr
+++ b/src/test/ui/lang-items/issue-83471.stderr
@@ -4,12 +4,6 @@ error[E0573]: expected type, found built-in attribute `export_name`
LL | fn call(export_name);
| ^^^^^^^^^^^ not a type
-error[E0425]: cannot find function `a` in this scope
- --> $DIR/issue-83471.rs:21:5
- |
-LL | a()
- | ^ not found in this scope
-
error[E0658]: language items are subject to change
--> $DIR/issue-83471.rs:7:1
|
@@ -32,9 +26,9 @@ warning: anonymous parameters are deprecated and will be removed in the next edi
LL | fn call(export_name);
| ^^^^^^^^^^^ help: try naming the parameter or explicitly ignoring it: `_: export_name`
|
- = note: `#[warn(anonymous_parameters)]` on by default
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
+ = note: `#[warn(anonymous_parameters)]` on by default
error[E0718]: `fn` language item must be applied to a trait with 1 generic argument
--> $DIR/issue-83471.rs:11:1
@@ -45,6 +39,12 @@ LL | #[lang = "fn"]
LL | trait Fn {
| - this trait has 0 generic arguments
+error[E0425]: cannot find function `a` in this scope
+ --> $DIR/issue-83471.rs:21:5
+ |
+LL | a()
+ | ^ not found in this scope
+
error: aborting due to 5 previous errors; 1 warning emitted
Some errors have detailed explanations: E0425, E0573, E0658, E0718.
diff --git a/src/test/ui/let-else/const-fn.rs b/src/test/ui/let-else/const-fn.rs
index 336b0b4b7..a3921b803 100644
--- a/src/test/ui/let-else/const-fn.rs
+++ b/src/test/ui/let-else/const-fn.rs
@@ -1,7 +1,6 @@
// run-pass
// issue #101932
-#![cfg_attr(bootstrap, feature(let_else))]
const fn foo(a: Option<i32>) -> i32 {
let Some(a) = a else {
diff --git a/src/test/ui/let-else/let-else-brace-before-else.stderr b/src/test/ui/let-else/let-else-brace-before-else.stderr
index 51051bbd4..cb01e4c18 100644
--- a/src/test/ui/let-else/let-else-brace-before-else.stderr
+++ b/src/test/ui/let-else/let-else-brace-before-else.stderr
@@ -4,7 +4,7 @@ error: right curly brace `}` before `else` in a `let...else` statement not allow
LL | let Some(1) = { Some(1) } else {
| ^
|
-help: try wrapping the expression in parentheses
+help: wrap the expression in parentheses
|
LL | let Some(1) = ({ Some(1) }) else {
| + +
@@ -15,7 +15,7 @@ error: right curly brace `}` before `else` in a `let...else` statement not allow
LL | let Some(1) = loop { break Some(1) } else {
| ^
|
-help: try wrapping the expression in parentheses
+help: wrap the expression in parentheses
|
LL | let Some(1) = (loop { break Some(1) }) else {
| + +
@@ -26,7 +26,7 @@ error: right curly brace `}` before `else` in a `let...else` statement not allow
LL | let 2 = 1 + match 1 { n => n } else {
| ^
|
-help: try wrapping the expression in parentheses
+help: wrap the expression in parentheses
|
LL | let 2 = 1 + (match 1 { n => n }) else {
| + +
@@ -37,7 +37,7 @@ error: right curly brace `}` before `else` in a `let...else` statement not allow
LL | let Some(1) = unsafe { unsafe_fn() } else {
| ^
|
-help: try wrapping the expression in parentheses
+help: wrap the expression in parentheses
|
LL | let Some(1) = (unsafe { unsafe_fn() }) else {
| + +
diff --git a/src/test/ui/let-else/let-else-irrefutable.stderr b/src/test/ui/let-else/let-else-irrefutable.stderr
index e030c50d4..e0581f4d9 100644
--- a/src/test/ui/let-else/let-else-irrefutable.stderr
+++ b/src/test/ui/let-else/let-else-irrefutable.stderr
@@ -4,9 +4,9 @@ warning: irrefutable `let...else` pattern
LL | let x = 1 else { return };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(irrefutable_let_patterns)]` on by default
= note: this pattern will always match, so the `else` clause is useless
= help: consider removing the `else` clause
+ = note: `#[warn(irrefutable_let_patterns)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/let-else/let-else-non-diverging.rs b/src/test/ui/let-else/let-else-non-diverging.rs
index b5bd91ceb..a5442dd82 100644
--- a/src/test/ui/let-else/let-else-non-diverging.rs
+++ b/src/test/ui/let-else/let-else-non-diverging.rs
@@ -8,4 +8,15 @@ fn main() {
}
};
let Some(x) = Some(1) else { Some(2) }; //~ ERROR does not diverge
+
+ // Ensure that uninhabited types do not "diverge".
+ // This might be relaxed in the future, but when it is,
+ // it should be an explicitly wanted decision.
+ let Some(x) = Some(1) else { foo::<Uninhabited>() }; //~ ERROR does not diverge
+}
+
+enum Uninhabited {}
+
+fn foo<T>() -> T {
+ panic!()
}
diff --git a/src/test/ui/let-else/let-else-non-diverging.stderr b/src/test/ui/let-else/let-else-non-diverging.stderr
index c999a5495..78551fcc4 100644
--- a/src/test/ui/let-else/let-else-non-diverging.stderr
+++ b/src/test/ui/let-else/let-else-non-diverging.stderr
@@ -39,6 +39,17 @@ LL | let Some(x) = Some(1) else { Some(2) };
= help: try adding a diverging expression, such as `return` or `panic!(..)`
= help: ...or use `match` instead of `let...else`
-error: aborting due to 3 previous errors
+error[E0308]: `else` clause of `let...else` does not diverge
+ --> $DIR/let-else-non-diverging.rs:15:32
+ |
+LL | let Some(x) = Some(1) else { foo::<Uninhabited>() };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `!`, found enum `Uninhabited`
+ |
+ = note: expected type `!`
+ found enum `Uninhabited`
+ = help: try adding a diverging expression, such as `return` or `panic!(..)`
+ = help: ...or use `match` instead of `let...else`
+
+error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/let-else/let-else-then-diverge.rs b/src/test/ui/let-else/let-else-then-diverge.rs
index 1c8f7d758..1a75310c9 100644
--- a/src/test/ui/let-else/let-else-then-diverge.rs
+++ b/src/test/ui/let-else/let-else-then-diverge.rs
@@ -1,8 +1,6 @@
-//
-// popped up in in #94012, where an alternative desugaring was
+// popped up in #94012, where an alternative desugaring was
// causing unreachable code errors
-
#![deny(unused_variables)]
#![deny(unreachable_code)]
diff --git a/src/test/ui/let-else/let-else-then-diverge.stderr b/src/test/ui/let-else/let-else-then-diverge.stderr
index ceb61029d..470a11d47 100644
--- a/src/test/ui/let-else/let-else-then-diverge.stderr
+++ b/src/test/ui/let-else/let-else-then-diverge.stderr
@@ -1,11 +1,11 @@
error: unused variable: `x`
- --> $DIR/let-else-then-diverge.rs:11:13
+ --> $DIR/let-else-then-diverge.rs:9:13
|
LL | let x = 5;
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
note: the lint level is defined here
- --> $DIR/let-else-then-diverge.rs:6:9
+ --> $DIR/let-else-then-diverge.rs:4:9
|
LL | #![deny(unused_variables)]
| ^^^^^^^^^^^^^^^^
diff --git a/src/test/ui/lexer/lex-emoji-identifiers.rs b/src/test/ui/lexer/lex-emoji-identifiers.rs
new file mode 100644
index 000000000..91b5929c0
--- /dev/null
+++ b/src/test/ui/lexer/lex-emoji-identifiers.rs
@@ -0,0 +1,17 @@
+fn invalid_emoji_usages() {
+ let arrowâ†”ï¸ = "basic emoji"; //~ ERROR: identifiers cannot contain emoji
+ // FIXME
+ let planet🪠= "basic emoji"; //~ ERROR: unknown start of token
+ // FIXME
+ let wireless🛜 = "basic emoji"; //~ ERROR: unknown start of token
+ // FIXME
+ let key1ï¸âƒ£ = "keycap sequence"; //~ ERROR: unknown start of token
+ //~^ WARN: identifier contains uncommon Unicode codepoints
+ let flag🇺🇳 = "flag sequence"; //~ ERROR: identifiers cannot contain emoji
+ let wales🴠= "tag sequence"; //~ ERROR: identifiers cannot contain emoji
+ let foldedðŸ™ðŸ¿ = "modifier sequence"; //~ ERROR: identifiers cannot contain emoji
+}
+
+fn main() {
+ invalid_emoji_usages();
+}
diff --git a/src/test/ui/lexer/lex-emoji-identifiers.stderr b/src/test/ui/lexer/lex-emoji-identifiers.stderr
new file mode 100644
index 000000000..6237c5d02
--- /dev/null
+++ b/src/test/ui/lexer/lex-emoji-identifiers.stderr
@@ -0,0 +1,52 @@
+error: unknown start of token: \u{1fa90}
+ --> $DIR/lex-emoji-identifiers.rs:4:15
+ |
+LL | let planet🪠= "basic emoji";
+ | ^^
+
+error: unknown start of token: \u{1f6dc}
+ --> $DIR/lex-emoji-identifiers.rs:6:17
+ |
+LL | let wireless🛜 = "basic emoji";
+ | ^^
+
+error: unknown start of token: \u{20e3}
+ --> $DIR/lex-emoji-identifiers.rs:8:14
+ |
+LL | let key1ï¸âƒ£ = "keycap sequence";
+ | ^
+
+error: identifiers cannot contain emoji: `arrow↔ï¸`
+ --> $DIR/lex-emoji-identifiers.rs:2:9
+ |
+LL | let arrowâ†”ï¸ = "basic emoji";
+ | ^^^^^^
+
+error: identifiers cannot contain emoji: `flag🇺🇳`
+ --> $DIR/lex-emoji-identifiers.rs:10:9
+ |
+LL | let flag🇺🇳 = "flag sequence";
+ | ^^^^^^
+
+error: identifiers cannot contain emoji: `walesðŸ´`
+ --> $DIR/lex-emoji-identifiers.rs:11:9
+ |
+LL | let wales🴠= "tag sequence";
+ | ^^^^^^^
+
+error: identifiers cannot contain emoji: `foldedðŸ™ðŸ¿`
+ --> $DIR/lex-emoji-identifiers.rs:12:9
+ |
+LL | let foldedðŸ™ðŸ¿ = "modifier sequence";
+ | ^^^^^^^^^^
+
+warning: identifier contains uncommon Unicode codepoints
+ --> $DIR/lex-emoji-identifiers.rs:8:9
+ |
+LL | let key1ï¸âƒ£ = "keycap sequence";
+ | ^^^^
+ |
+ = note: `#[warn(uncommon_codepoints)]` on by default
+
+error: aborting due to 7 previous errors; 1 warning emitted
+
diff --git a/src/test/ui/lexical-scopes.stderr b/src/test/ui/lexical-scopes.stderr
index 08e4be2c0..535985452 100644
--- a/src/test/ui/lexical-scopes.stderr
+++ b/src/test/ui/lexical-scopes.stderr
@@ -1,6 +1,8 @@
error[E0574]: expected struct, variant or union type, found type parameter `T`
--> $DIR/lexical-scopes.rs:3:13
|
+LL | struct T { i: i32 }
+ | ------------------- you might have meant to refer to this struct
LL | fn f<T>() {
| - found this type parameter
LL | let t = T { i: 0 };
diff --git a/src/test/ui/lifetimes/elided-lifetime-in-param-pat.rs b/src/test/ui/lifetimes/elided-lifetime-in-param-pat.rs
new file mode 100644
index 000000000..c1425fa42
--- /dev/null
+++ b/src/test/ui/lifetimes/elided-lifetime-in-param-pat.rs
@@ -0,0 +1,11 @@
+// check-pass
+
+struct S<T> {
+ _t: T,
+}
+
+fn f(S::<&i8> { .. }: S<&i8>) {}
+
+fn main() {
+ f(S { _t: &42_i8 });
+}
diff --git a/src/test/ui/lifetimes/issue-79187-2.stderr b/src/test/ui/lifetimes/issue-79187-2.stderr
index 9322e6171..c5f654b37 100644
--- a/src/test/ui/lifetimes/issue-79187-2.stderr
+++ b/src/test/ui/lifetimes/issue-79187-2.stderr
@@ -31,7 +31,7 @@ error[E0308]: mismatched types
LL | take_foo(|a| a);
| ^^^^^^^^^^^^^^^ one type is more general than the other
|
- = note: expected trait `for<'r> Fn<(&'r i32,)>`
+ = note: expected trait `for<'a> Fn<(&'a i32,)>`
found trait `Fn<(&i32,)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/issue-79187-2.rs:8:14
diff --git a/src/test/ui/lifetimes/issue-79187.stderr b/src/test/ui/lifetimes/issue-79187.stderr
index 3e75e7fed..ee6e7b89d 100644
--- a/src/test/ui/lifetimes/issue-79187.stderr
+++ b/src/test/ui/lifetimes/issue-79187.stderr
@@ -4,7 +4,7 @@ error[E0308]: mismatched types
LL | thing(f);
| ^^^^^^^^ one type is more general than the other
|
- = note: expected trait `for<'r> FnOnce<(&'r u32,)>`
+ = note: expected trait `for<'a> FnOnce<(&'a u32,)>`
found trait `FnOnce<(&u32,)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/issue-79187.rs:4:13
diff --git a/src/test/ui/lifetimes/lifetime-errors/issue_74400.stderr b/src/test/ui/lifetimes/lifetime-errors/issue_74400.stderr
index d82b2684c..7049f28e2 100644
--- a/src/test/ui/lifetimes/lifetime-errors/issue_74400.stderr
+++ b/src/test/ui/lifetimes/lifetime-errors/issue_74400.stderr
@@ -15,7 +15,7 @@ error[E0308]: mismatched types
LL | f(data, identity)
| ^^^^^^^^^^^^^^^^^ one type is more general than the other
|
- = note: expected trait `for<'r> Fn<(&'r T,)>`
+ = note: expected trait `for<'a> Fn<(&'a T,)>`
found trait `Fn<(&T,)>`
note: the lifetime requirement is introduced here
--> $DIR/issue_74400.rs:8:34
diff --git a/src/test/ui/lifetimes/nested-binder-print.rs b/src/test/ui/lifetimes/nested-binder-print.rs
new file mode 100644
index 000000000..f97f349fd
--- /dev/null
+++ b/src/test/ui/lifetimes/nested-binder-print.rs
@@ -0,0 +1,10 @@
+struct TwoLt<'a, 'b>(&'a (), &'b ());
+type Foo<'a> = fn(TwoLt<'_, 'a>);
+
+fn foo() {
+ let y: for<'a> fn(Foo<'a>);
+ let x: u32 = y;
+ //~^ ERROR mismatched types
+}
+
+fn main() {}
diff --git a/src/test/ui/lifetimes/nested-binder-print.stderr b/src/test/ui/lifetimes/nested-binder-print.stderr
new file mode 100644
index 000000000..32dd89693
--- /dev/null
+++ b/src/test/ui/lifetimes/nested-binder-print.stderr
@@ -0,0 +1,14 @@
+error[E0308]: mismatched types
+ --> $DIR/nested-binder-print.rs:6:18
+ |
+LL | let x: u32 = y;
+ | --- ^ expected `u32`, found fn pointer
+ | |
+ | expected due to this
+ |
+ = note: expected type `u32`
+ found fn pointer `for<'a> fn(for<'b> fn(TwoLt<'b, 'a>))`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/lifetimes/re-empty-in-error.stderr b/src/test/ui/lifetimes/re-empty-in-error.stderr
index 72bb0782f..c35d8ecec 100644
--- a/src/test/ui/lifetimes/re-empty-in-error.stderr
+++ b/src/test/ui/lifetimes/re-empty-in-error.stderr
@@ -4,7 +4,7 @@ error: higher-ranked lifetime error
LL | foo(&10);
| ^^^^^^^^
|
- = note: could not prove `for<'b, 'r> &'b (): 'r`
+ = note: could not prove `for<'b> &'b (): 'a`
error: aborting due to previous error
diff --git a/src/test/ui/lifetimes/suggest-introducing-and-adding-missing-lifetime.stderr b/src/test/ui/lifetimes/suggest-introducing-and-adding-missing-lifetime.stderr
index a8b0996d8..31fd8a4d6 100644
--- a/src/test/ui/lifetimes/suggest-introducing-and-adding-missing-lifetime.stderr
+++ b/src/test/ui/lifetimes/suggest-introducing-and-adding-missing-lifetime.stderr
@@ -21,3 +21,4 @@ LL | fn no_restriction<'a, T: 'a>(x: &()) -> &() {
error: aborting due to previous error
+For more information about this error, try `rustc --explain E0311`.
diff --git a/src/test/ui/lifetimes/unusual-rib-combinations.rs b/src/test/ui/lifetimes/unusual-rib-combinations.rs
new file mode 100644
index 000000000..b4c86aab8
--- /dev/null
+++ b/src/test/ui/lifetimes/unusual-rib-combinations.rs
@@ -0,0 +1,28 @@
+#![feature(inline_const)]
+
+struct S<'a>(&'a u8);
+fn foo() {}
+
+// Paren generic args in AnonConst
+fn a() -> [u8; foo::()] {
+//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
+//~| ERROR mismatched types
+ panic!()
+}
+
+// Paren generic args in ConstGeneric
+fn b<const C: u8()>() {}
+//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
+
+// Paren generic args in AnonymousReportError
+fn c<T = u8()>() {}
+//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
+//~| ERROR defaults for type parameters are only allowed in
+//~| WARN this was previously accepted
+
+// Elided lifetime in path in ConstGeneric
+fn d<const C: S>() {}
+//~^ ERROR missing lifetime specifier
+//~| ERROR `S<'static>` is forbidden as the type of a const generic parameter
+
+fn main() {}
diff --git a/src/test/ui/lifetimes/unusual-rib-combinations.stderr b/src/test/ui/lifetimes/unusual-rib-combinations.stderr
new file mode 100644
index 000000000..6d7b42506
--- /dev/null
+++ b/src/test/ui/lifetimes/unusual-rib-combinations.stderr
@@ -0,0 +1,61 @@
+error[E0106]: missing lifetime specifier
+ --> $DIR/unusual-rib-combinations.rs:24:15
+ |
+LL | fn d<const C: S>() {}
+ | ^ expected named lifetime parameter
+ |
+help: consider introducing a named lifetime parameter
+ |
+LL | fn d<'a, const C: S<'a>>() {}
+ | +++ ++++
+
+error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
+ --> $DIR/unusual-rib-combinations.rs:7:16
+ |
+LL | fn a() -> [u8; foo::()] {
+ | ^^^^^^^ only `Fn` traits may use parentheses
+
+error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
+ --> $DIR/unusual-rib-combinations.rs:14:15
+ |
+LL | fn b<const C: u8()>() {}
+ | ^^^^ only `Fn` traits may use parentheses
+
+error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
+ --> $DIR/unusual-rib-combinations.rs:18:10
+ |
+LL | fn c<T = u8()>() {}
+ | ^^^^ only `Fn` traits may use parentheses
+
+error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
+ --> $DIR/unusual-rib-combinations.rs:18:6
+ |
+LL | fn c<T = u8()>() {}
+ | ^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
+ = note: `#[deny(invalid_type_param_default)]` on by default
+
+error[E0308]: mismatched types
+ --> $DIR/unusual-rib-combinations.rs:7:16
+ |
+LL | fn a() -> [u8; foo::()] {
+ | ^^^^^^^ expected `usize`, found fn item
+ |
+ = note: expected type `usize`
+ found fn item `fn() {foo}`
+
+error: `S<'static>` is forbidden as the type of a const generic parameter
+ --> $DIR/unusual-rib-combinations.rs:24:15
+ |
+LL | fn d<const C: S>() {}
+ | ^
+ |
+ = note: the only supported types are integers, `bool` and `char`
+ = help: more complex types are supported with `#![feature(adt_const_params)]`
+
+error: aborting due to 7 previous errors
+
+Some errors have detailed explanations: E0106, E0214, E0308.
+For more information about an error, try `rustc --explain E0106`.
diff --git a/src/test/ui/limits/issue-55878.stderr b/src/test/ui/limits/issue-55878.stderr
index 6c3683d78..ee6aab748 100644
--- a/src/test/ui/limits/issue-55878.stderr
+++ b/src/test/ui/limits/issue-55878.stderr
@@ -9,29 +9,14 @@ LL | intrinsics::size_of::<T>()
LL | println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>());
| ---------------------------------------------- inside `main` at $DIR/issue-55878.rs:7:26
-error: erroneous constant used
+error[E0080]: erroneous constant used
--> $DIR/issue-55878.rs:7:26
|
LL | println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
|
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
-Future incompatibility report: Future breakage diagnostic:
-error: erroneous constant used
- --> $DIR/issue-55878.rs:7:26
- |
-LL | println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>());
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
- |
- = note: `#[deny(const_err)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
- = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
-
diff --git a/src/test/ui/linkage-attr/link-attr-validation-early.stderr b/src/test/ui/linkage-attr/link-attr-validation-early.stderr
index 903141e43..24ad9d825 100644
--- a/src/test/ui/linkage-attr/link-attr-validation-early.stderr
+++ b/src/test/ui/linkage-attr/link-attr-validation-early.stderr
@@ -4,9 +4,9 @@ error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib
LL | #[link]
| ^^^^^^^
|
- = note: `#[deny(ill_formed_attribute_input)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
+ = note: `#[deny(ill_formed_attribute_input)]` on by default
error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated")]`
--> $DIR/link-attr-validation-early.rs:4:1
diff --git a/src/test/ui/lint/auxiliary/trivial-cast-ice.rs b/src/test/ui/lint/auxiliary/trivial-cast-ice.rs
new file mode 100644
index 000000000..ab2332d06
--- /dev/null
+++ b/src/test/ui/lint/auxiliary/trivial-cast-ice.rs
@@ -0,0 +1,7 @@
+#[macro_export]
+macro_rules! foo {
+ () => {
+ let x: &Option<i32> = &Some(1);
+ let _y = x as *const Option<i32>;
+ }
+}
diff --git a/src/test/ui/lint/bare-trait-objects-path.stderr b/src/test/ui/lint/bare-trait-objects-path.stderr
index 4b8c2b539..8ed303ca6 100644
--- a/src/test/ui/lint/bare-trait-objects-path.stderr
+++ b/src/test/ui/lint/bare-trait-objects-path.stderr
@@ -4,9 +4,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | let _: Dyn::Ty;
| ^^^
|
- = note: `#[warn(bare_trait_objects)]` on by default
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
|
LL | let _: <dyn Dyn>::Ty;
diff --git a/src/test/ui/lint/clashing-extern-fn.stderr b/src/test/ui/lint/clashing-extern-fn.stderr
index 4607f6849..217eed6c9 100644
--- a/src/test/ui/lint/clashing-extern-fn.stderr
+++ b/src/test/ui/lint/clashing-extern-fn.stderr
@@ -7,13 +7,13 @@ LL | fn clash(x: u8);
LL | fn clash(x: u64);
| ^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
|
+ = note: expected `unsafe extern "C" fn(u8)`
+ found `unsafe extern "C" fn(u64)`
note: the lint level is defined here
--> $DIR/clashing-extern-fn.rs:4:9
|
LL | #![warn(clashing_extern_declarations)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: expected `unsafe extern "C" fn(u8)`
- found `unsafe extern "C" fn(u64)`
warning: `extern_link_name` redeclared with a different signature
--> $DIR/clashing-extern-fn.rs:52:9
@@ -219,9 +219,9 @@ warning: `extern` block uses type `Option<TransparentNoNiche>`, which is not FFI
LL | fn hidden_niche_transparent_no_niche() -> Option<TransparentNoNiche>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
- = note: `#[warn(improper_ctypes)]` on by default
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint
+ = note: `#[warn(improper_ctypes)]` on by default
warning: `extern` block uses type `Option<UnsafeCell<NonZeroUsize>>`, which is not FFI-safe
--> $DIR/clashing-extern-fn.rs:412:46
diff --git a/src/test/ui/lint/cli-lint-override.forbid_warn.stderr b/src/test/ui/lint/cli-lint-override.forbid_warn.stderr
index ff4dc4abc..d1c66a81c 100644
--- a/src/test/ui/lint/cli-lint-override.forbid_warn.stderr
+++ b/src/test/ui/lint/cli-lint-override.forbid_warn.stderr
@@ -4,8 +4,8 @@ error: extern declarations without an explicit ABI are deprecated
LL | extern fn foo() {}
| ^^^^^^^^^^^^^^^ ABI should be specified here
|
- = note: requested on the command line with `-F missing-abi`
= help: the default ABI is C
+ = note: requested on the command line with `-F missing-abi`
error: aborting due to previous error
diff --git a/src/test/ui/lint/cli-lint-override.force_warn_deny.stderr b/src/test/ui/lint/cli-lint-override.force_warn_deny.stderr
index 74e7823e1..779c24c93 100644
--- a/src/test/ui/lint/cli-lint-override.force_warn_deny.stderr
+++ b/src/test/ui/lint/cli-lint-override.force_warn_deny.stderr
@@ -4,8 +4,8 @@ warning: extern declarations without an explicit ABI are deprecated
LL | extern fn foo() {}
| ^^^^^^^^^^^^^^^ ABI should be specified here
|
- = note: requested on the command line with `--force-warn missing-abi`
= help: the default ABI is C
+ = note: requested on the command line with `--force-warn missing-abi`
warning: 1 warning emitted
diff --git a/src/test/ui/lint/cli-lint-override.warn_deny.stderr b/src/test/ui/lint/cli-lint-override.warn_deny.stderr
index 2d869adfd..f034cfa93 100644
--- a/src/test/ui/lint/cli-lint-override.warn_deny.stderr
+++ b/src/test/ui/lint/cli-lint-override.warn_deny.stderr
@@ -4,8 +4,8 @@ error: extern declarations without an explicit ABI are deprecated
LL | extern fn foo() {}
| ^^^^^^^^^^^^^^^ ABI should be specified here
|
- = note: requested on the command line with `-D missing-abi`
= help: the default ABI is C
+ = note: requested on the command line with `-D missing-abi`
error: aborting due to previous error
diff --git a/src/test/ui/lint/dead-code/issue-85071-2.stderr b/src/test/ui/lint/dead-code/issue-85071-2.stderr
index 86fbd1d75..5e963183d 100644
--- a/src/test/ui/lint/dead-code/issue-85071-2.stderr
+++ b/src/test/ui/lint/dead-code/issue-85071-2.stderr
@@ -7,16 +7,16 @@ LL |
LL | let _y = x;
| ^^ unreachable definition
|
-note: the lint level is defined here
- --> $DIR/issue-85071-2.rs:7:26
- |
-LL | #![warn(unused_variables,unreachable_code)]
- | ^^^^^^^^^^^^^^^^
note: this expression has type `Foo`, which is uninhabited
--> $DIR/issue-85071-2.rs:18:13
|
LL | let x = s.f();
| ^^^^^
+note: the lint level is defined here
+ --> $DIR/issue-85071-2.rs:7:26
+ |
+LL | #![warn(unused_variables,unreachable_code)]
+ | ^^^^^^^^^^^^^^^^
warning: unused variable: `x`
--> $DIR/issue-85071-2.rs:18:9
diff --git a/src/test/ui/lint/dead-code/issue-85071.stderr b/src/test/ui/lint/dead-code/issue-85071.stderr
index 49555fdaa..721fb8148 100644
--- a/src/test/ui/lint/dead-code/issue-85071.stderr
+++ b/src/test/ui/lint/dead-code/issue-85071.stderr
@@ -7,16 +7,16 @@ LL |
LL | let _ = x;
| ^ unreachable expression
|
-note: the lint level is defined here
- --> $DIR/issue-85071.rs:9:26
- |
-LL | #![warn(unused_variables,unreachable_code)]
- | ^^^^^^^^^^^^^^^^
note: this expression has type `Foo`, which is uninhabited
--> $DIR/issue-85071.rs:15:13
|
LL | let x = f();
| ^^^
+note: the lint level is defined here
+ --> $DIR/issue-85071.rs:9:26
+ |
+LL | #![warn(unused_variables,unreachable_code)]
+ | ^^^^^^^^^^^^^^^^
warning: unused variable: `x`
--> $DIR/issue-85071.rs:15:9
diff --git a/src/test/ui/lint/dead-code/unused-variant.stderr b/src/test/ui/lint/dead-code/unused-variant.stderr
index a68f64775..6029bf268 100644
--- a/src/test/ui/lint/dead-code/unused-variant.stderr
+++ b/src/test/ui/lint/dead-code/unused-variant.stderr
@@ -6,12 +6,12 @@ LL | enum Enum {
LL | Variant1,
| ^^^^^^^^
|
+ = note: `Enum` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis
note: the lint level is defined here
--> $DIR/unused-variant.rs:1:9
|
LL | #![deny(dead_code)]
| ^^^^^^^^^
- = note: `Enum` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis
error: aborting due to previous error
diff --git a/src/test/ui/lint/deny-overflowing-literals.stderr b/src/test/ui/lint/deny-overflowing-literals.stderr
index 127dd4127..beb0ad795 100644
--- a/src/test/ui/lint/deny-overflowing-literals.stderr
+++ b/src/test/ui/lint/deny-overflowing-literals.stderr
@@ -4,8 +4,8 @@ error: literal out of range for `u8`
LL | let x: u8 = 256;
| ^^^
|
- = note: `#[deny(overflowing_literals)]` on by default
= note: the literal `256` does not fit into the type `u8` whose range is `0..=255`
+ = note: `#[deny(overflowing_literals)]` on by default
error: range endpoint is out of range for `u8`
--> $DIR/deny-overflowing-literals.rs:5:14
diff --git a/src/test/ui/lint/expansion-time.stderr b/src/test/ui/lint/expansion-time.stderr
index b0fc1f8e5..064ee5fad 100644
--- a/src/test/ui/lint/expansion-time.stderr
+++ b/src/test/ui/lint/expansion-time.stderr
@@ -18,13 +18,13 @@ warning: missing fragment specifier
LL | macro_rules! m { ($i) => {} }
| ^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
note: the lint level is defined here
--> $DIR/expansion-time.rs:8:8
|
LL | #[warn(missing_fragment_specifier)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
warning: use of unstable library feature 'test': `bench` is a part of custom test frameworks which are unstable
--> $DIR/expansion-time.rs:14:7
@@ -32,13 +32,13 @@ warning: use of unstable library feature 'test': `bench` is a part of custom tes
LL | #[bench]
| ^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
note: the lint level is defined here
--> $DIR/expansion-time.rs:12:8
|
LL | #[warn(soft_unstable)]
| ^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
warning: include macro expected single expression in source
--> $DIR/expansion-time-include.rs:4:1
diff --git a/src/test/ui/lint/fn_must_use.stderr b/src/test/ui/lint/fn_must_use.stderr
index 61b7993d2..2805720f0 100644
--- a/src/test/ui/lint/fn_must_use.stderr
+++ b/src/test/ui/lint/fn_must_use.stderr
@@ -4,12 +4,12 @@ warning: unused return value of `need_to_use_this_value` that must be used
LL | need_to_use_this_value();
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
+ = note: it's important
note: the lint level is defined here
--> $DIR/fn_must_use.rs:3:9
|
LL | #![warn(unused_must_use)]
| ^^^^^^^^^^^^^^^
- = note: it's important
warning: unused return value of `MyStruct::need_to_use_this_method_value` that must be used
--> $DIR/fn_must_use.rs:60:5
diff --git a/src/test/ui/lint/for_loop_over_fallibles.rs b/src/test/ui/lint/for_loop_over_fallibles.rs
new file mode 100644
index 000000000..43d71c2e8
--- /dev/null
+++ b/src/test/ui/lint/for_loop_over_fallibles.rs
@@ -0,0 +1,43 @@
+// check-pass
+
+fn main() {
+ // Common
+ for _ in Some(1) {}
+ //~^ WARN for loop over an `Option`. This is more readably written as an `if let` statement
+ //~| HELP to check pattern in a loop use `while let`
+ //~| HELP consider using `if let` to clear intent
+ for _ in Ok::<_, ()>(1) {}
+ //~^ WARN for loop over a `Result`. This is more readably written as an `if let` statement
+ //~| HELP to check pattern in a loop use `while let`
+ //~| HELP consider using `if let` to clear intent
+
+ // `Iterator::next` specific
+ for _ in [0; 0].iter().next() {}
+ //~^ WARN for loop over an `Option`. This is more readably written as an `if let` statement
+ //~| HELP to iterate over `[0; 0].iter()` remove the call to `next`
+ //~| HELP consider using `if let` to clear intent
+
+ // `Result<impl Iterator, _>`, but function doesn't return `Result`
+ for _ in Ok::<_, ()>([0; 0].iter()) {}
+ //~^ WARN for loop over a `Result`. This is more readably written as an `if let` statement
+ //~| HELP to check pattern in a loop use `while let`
+ //~| HELP consider using `if let` to clear intent
+}
+
+fn _returns_result() -> Result<(), ()> {
+ // `Result<impl Iterator, _>`
+ for _ in Ok::<_, ()>([0; 0].iter()) {}
+ //~^ WARN for loop over a `Result`. This is more readably written as an `if let` statement
+ //~| HELP to check pattern in a loop use `while let`
+ //~| HELP consider unwrapping the `Result` with `?` to iterate over its contents
+ //~| HELP consider using `if let` to clear intent
+
+ // `Result<impl IntoIterator>`
+ for _ in Ok::<_, ()>([0; 0]) {}
+ //~^ WARN for loop over a `Result`. This is more readably written as an `if let` statement
+ //~| HELP to check pattern in a loop use `while let`
+ //~| HELP consider unwrapping the `Result` with `?` to iterate over its contents
+ //~| HELP consider using `if let` to clear intent
+
+ Ok(())
+}
diff --git a/src/test/ui/lint/for_loop_over_fallibles.stderr b/src/test/ui/lint/for_loop_over_fallibles.stderr
new file mode 100644
index 000000000..96efdf85c
--- /dev/null
+++ b/src/test/ui/lint/for_loop_over_fallibles.stderr
@@ -0,0 +1,101 @@
+warning: for loop over an `Option`. This is more readably written as an `if let` statement
+ --> $DIR/for_loop_over_fallibles.rs:5:14
+ |
+LL | for _ in Some(1) {}
+ | ^^^^^^^
+ |
+ = note: `#[warn(for_loops_over_fallibles)]` on by default
+help: to check pattern in a loop use `while let`
+ |
+LL | while let Some(_) = Some(1) {}
+ | ~~~~~~~~~~~~~~~ ~~~
+help: consider using `if let` to clear intent
+ |
+LL | if let Some(_) = Some(1) {}
+ | ~~~~~~~~~~~~ ~~~
+
+warning: for loop over a `Result`. This is more readably written as an `if let` statement
+ --> $DIR/for_loop_over_fallibles.rs:9:14
+ |
+LL | for _ in Ok::<_, ()>(1) {}
+ | ^^^^^^^^^^^^^^
+ |
+help: to check pattern in a loop use `while let`
+ |
+LL | while let Ok(_) = Ok::<_, ()>(1) {}
+ | ~~~~~~~~~~~~~ ~~~
+help: consider using `if let` to clear intent
+ |
+LL | if let Ok(_) = Ok::<_, ()>(1) {}
+ | ~~~~~~~~~~ ~~~
+
+warning: for loop over an `Option`. This is more readably written as an `if let` statement
+ --> $DIR/for_loop_over_fallibles.rs:15:14
+ |
+LL | for _ in [0; 0].iter().next() {}
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+help: to iterate over `[0; 0].iter()` remove the call to `next`
+ |
+LL | for _ in [0; 0].iter().by_ref() {}
+ | ~~~~~~~~~
+help: consider using `if let` to clear intent
+ |
+LL | if let Some(_) = [0; 0].iter().next() {}
+ | ~~~~~~~~~~~~ ~~~
+
+warning: for loop over a `Result`. This is more readably written as an `if let` statement
+ --> $DIR/for_loop_over_fallibles.rs:21:14
+ |
+LL | for _ in Ok::<_, ()>([0; 0].iter()) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: to check pattern in a loop use `while let`
+ |
+LL | while let Ok(_) = Ok::<_, ()>([0; 0].iter()) {}
+ | ~~~~~~~~~~~~~ ~~~
+help: consider using `if let` to clear intent
+ |
+LL | if let Ok(_) = Ok::<_, ()>([0; 0].iter()) {}
+ | ~~~~~~~~~~ ~~~
+
+warning: for loop over a `Result`. This is more readably written as an `if let` statement
+ --> $DIR/for_loop_over_fallibles.rs:29:14
+ |
+LL | for _ in Ok::<_, ()>([0; 0].iter()) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: to check pattern in a loop use `while let`
+ |
+LL | while let Ok(_) = Ok::<_, ()>([0; 0].iter()) {}
+ | ~~~~~~~~~~~~~ ~~~
+help: consider unwrapping the `Result` with `?` to iterate over its contents
+ |
+LL | for _ in Ok::<_, ()>([0; 0].iter())? {}
+ | +
+help: consider using `if let` to clear intent
+ |
+LL | if let Ok(_) = Ok::<_, ()>([0; 0].iter()) {}
+ | ~~~~~~~~~~ ~~~
+
+warning: for loop over a `Result`. This is more readably written as an `if let` statement
+ --> $DIR/for_loop_over_fallibles.rs:36:14
+ |
+LL | for _ in Ok::<_, ()>([0; 0]) {}
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+help: to check pattern in a loop use `while let`
+ |
+LL | while let Ok(_) = Ok::<_, ()>([0; 0]) {}
+ | ~~~~~~~~~~~~~ ~~~
+help: consider unwrapping the `Result` with `?` to iterate over its contents
+ |
+LL | for _ in Ok::<_, ()>([0; 0])? {}
+ | +
+help: consider using `if let` to clear intent
+ |
+LL | if let Ok(_) = Ok::<_, ()>([0; 0]) {}
+ | ~~~~~~~~~~ ~~~
+
+warning: 6 warnings emitted
+
diff --git a/src/test/ui/lint/forbid-group-group-2.stderr b/src/test/ui/lint/forbid-group-group-2.stderr
index 214e949c1..b2e2bcea1 100644
--- a/src/test/ui/lint/forbid-group-group-2.stderr
+++ b/src/test/ui/lint/forbid-group-group-2.stderr
@@ -7,13 +7,13 @@ LL | #![forbid(warnings)]
LL | #[allow(nonstandard_style)]
| ^^^^^^^^^^^^^^^^^ overruled by previous forbid
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
note: the lint level is defined here
--> $DIR/forbid-group-group-2.rs:5:9
|
LL | #![deny(forbidden_lint_groups)]
| ^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
error: allow(nonstandard_style) incompatible with previous forbid
--> $DIR/forbid-group-group-2.rs:7:9
diff --git a/src/test/ui/lint/forbid-group-member.stderr b/src/test/ui/lint/forbid-group-member.stderr
index 891fa9885..47336d4d8 100644
--- a/src/test/ui/lint/forbid-group-member.stderr
+++ b/src/test/ui/lint/forbid-group-member.stderr
@@ -7,9 +7,9 @@ LL |
LL | #[allow(unused_variables)]
| ^^^^^^^^^^^^^^^^ overruled by previous forbid
|
- = note: `#[warn(forbidden_lint_groups)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
+ = note: `#[warn(forbidden_lint_groups)]` on by default
warning: allow(unused_variables) incompatible with previous forbid
--> $DIR/forbid-group-member.rs:8:9
diff --git a/src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.rs b/src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.rs
index 3a3d81176..257df13ef 100644
--- a/src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.rs
+++ b/src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.rs
@@ -1,10 +1,10 @@
// --force-warn $LINT causes $LINT (which is deny-by-default) to warn
// despite $LINT being allowed on command line
-// compile-flags: -A const_err --force-warn const_err
+// compile-flags: -A mutable_transmutes --force-warn mutable_transmutes
// check-pass
-const C: i32 = 1 / 0;
-//~^ WARN any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler
-
-fn main() {}
+fn main() {
+ unsafe {
+ let y = std::mem::transmute::<&i32, &mut i32>(&5); //~WARN: undefined behavior
+ }
+}
diff --git a/src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.stderr b/src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.stderr
index 915b3b86f..6a1fc76e1 100644
--- a/src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.stderr
+++ b/src/test/ui/lint/force-warn/allowed-cli-deny-by-default-lint.stderr
@@ -1,23 +1,10 @@
-warning: any use of this value will cause an error
- --> $DIR/allowed-cli-deny-by-default-lint.rs:6:16
+warning: transmuting &T to &mut T is undefined behavior, even if the reference is unused, consider instead using an UnsafeCell
+ --> $DIR/allowed-cli-deny-by-default-lint.rs:8:17
|
-LL | const C: i32 = 1 / 0;
- | ------------ ^^^^^ attempt to divide `1_i32` by zero
+LL | let y = std::mem::transmute::<&i32, &mut i32>(&5);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: requested on the command line with `--force-warn const-err`
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ = note: requested on the command line with `--force-warn mutable-transmutes`
warning: 1 warning emitted
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/allowed-cli-deny-by-default-lint.rs:6:16
- |
-LL | const C: i32 = 1 / 0;
- | ------------ ^^^^^ attempt to divide `1_i32` by zero
- |
- = note: requested on the command line with `--force-warn const-err`
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs b/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs
index 08e75a775..0d4b468c2 100644
--- a/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs
+++ b/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.rs
@@ -1,11 +1,11 @@
// --force-warn $LINT causes $LINT (which is deny-by-default) to warn
// despite $LINT being allowed in module
-// compile-flags: --force-warn const_err
+// compile-flags: --force-warn mutable_transmutes
// check-pass
-#![allow(const_err)]
-const C: i32 = 1 / 0;
-//~^ WARN any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler
-
-fn main() {}
+#![allow(mutable_transmutes)]
+fn main() {
+ unsafe {
+ let y = std::mem::transmute::<&i32, &mut i32>(&5); //~WARN: undefined behavior
+ }
+}
diff --git a/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.stderr b/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.stderr
index 3b36d1d02..9ef53d47e 100644
--- a/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.stderr
+++ b/src/test/ui/lint/force-warn/allowed-deny-by-default-lint.stderr
@@ -1,23 +1,10 @@
-warning: any use of this value will cause an error
- --> $DIR/allowed-deny-by-default-lint.rs:7:16
+warning: transmuting &T to &mut T is undefined behavior, even if the reference is unused, consider instead using an UnsafeCell
+ --> $DIR/allowed-deny-by-default-lint.rs:9:17
|
-LL | const C: i32 = 1 / 0;
- | ------------ ^^^^^ attempt to divide `1_i32` by zero
+LL | let y = std::mem::transmute::<&i32, &mut i32>(&5);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: requested on the command line with `--force-warn const-err`
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ = note: requested on the command line with `--force-warn mutable-transmutes`
warning: 1 warning emitted
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/allowed-deny-by-default-lint.rs:7:16
- |
-LL | const C: i32 = 1 / 0;
- | ------------ ^^^^^ attempt to divide `1_i32` by zero
- |
- = note: requested on the command line with `--force-warn const-err`
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr b/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr
index 94d81c3aa..0f58953a5 100644
--- a/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr
+++ b/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr
@@ -4,9 +4,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
- = note: requested on the command line with `--force-warn bare-trait-objects`
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: requested on the command line with `--force-warn bare-trait-objects`
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
diff --git a/src/test/ui/lint/force-warn/cap-lints-allow.stderr b/src/test/ui/lint/force-warn/cap-lints-allow.stderr
index 7f0fd8530..03a32fa6f 100644
--- a/src/test/ui/lint/force-warn/cap-lints-allow.stderr
+++ b/src/test/ui/lint/force-warn/cap-lints-allow.stderr
@@ -4,9 +4,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
- = note: requested on the command line with `--force-warn bare-trait-objects`
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: requested on the command line with `--force-warn bare-trait-objects`
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
diff --git a/src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr b/src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr
index 3dafaf705..d1b764b34 100644
--- a/src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr
+++ b/src/test/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr
@@ -4,9 +4,9 @@ warning: `...` range patterns are deprecated
LL | 0...100 => true,
| ^^^ help: use `..=` for an inclusive range
|
- = note: `--force-warn ellipsis-inclusive-range-patterns` implied by `--force-warn rust-2021-compatibility`
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: `--force-warn ellipsis-inclusive-range-patterns` implied by `--force-warn rust-2021-compatibility`
warning: 1 warning emitted
diff --git a/src/test/ui/lint/force-warn/deny-by-default-lint.rs b/src/test/ui/lint/force-warn/deny-by-default-lint.rs
index e37102903..c2e9377e9 100644
--- a/src/test/ui/lint/force-warn/deny-by-default-lint.rs
+++ b/src/test/ui/lint/force-warn/deny-by-default-lint.rs
@@ -1,9 +1,9 @@
// --force-warn $LINT causes $LINT (which is deny-by-default) to warn
-// compile-flags: --force-warn const_err
+// compile-flags: --force-warn mutable_transmutes
// check-pass
-const C: i32 = 1 / 0;
-//~^ WARN any use of this value will cause an error
-//~| WARN this was previously accepted by the compiler
-
-fn main() {}
+fn main() {
+ unsafe {
+ let y = std::mem::transmute::<&i32, &mut i32>(&5); //~WARN: undefined behavior
+ }
+}
diff --git a/src/test/ui/lint/force-warn/deny-by-default-lint.stderr b/src/test/ui/lint/force-warn/deny-by-default-lint.stderr
index a2e5baa8b..c644d0fe7 100644
--- a/src/test/ui/lint/force-warn/deny-by-default-lint.stderr
+++ b/src/test/ui/lint/force-warn/deny-by-default-lint.stderr
@@ -1,23 +1,10 @@
-warning: any use of this value will cause an error
- --> $DIR/deny-by-default-lint.rs:5:16
+warning: transmuting &T to &mut T is undefined behavior, even if the reference is unused, consider instead using an UnsafeCell
+ --> $DIR/deny-by-default-lint.rs:7:17
|
-LL | const C: i32 = 1 / 0;
- | ------------ ^^^^^ attempt to divide `1_i32` by zero
+LL | let y = std::mem::transmute::<&i32, &mut i32>(&5);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: requested on the command line with `--force-warn const-err`
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
+ = note: requested on the command line with `--force-warn mutable-transmutes`
warning: 1 warning emitted
-Future incompatibility report: Future breakage diagnostic:
-warning: any use of this value will cause an error
- --> $DIR/deny-by-default-lint.rs:5:16
- |
-LL | const C: i32 = 1 / 0;
- | ------------ ^^^^^ attempt to divide `1_i32` by zero
- |
- = note: requested on the command line with `--force-warn const-err`
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
-
diff --git a/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr b/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr
index eb2bca7b8..e17630fd3 100644
--- a/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr
+++ b/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr
@@ -4,9 +4,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
- = note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
diff --git a/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.stderr b/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.stderr
index ed01937a5..72198541a 100644
--- a/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.stderr
+++ b/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.stderr
@@ -4,9 +4,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
- = note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
diff --git a/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr b/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr
index 8db7c1275..52c870ac2 100644
--- a/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr
+++ b/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr
@@ -4,9 +4,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | pub fn function(_x: Box<SomeTrait>) {}
| ^^^^^^^^^
|
- = note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
diff --git a/src/test/ui/lint/inclusive-range-pattern-syntax.stderr b/src/test/ui/lint/inclusive-range-pattern-syntax.stderr
index 91b8d2b5a..ed9fa0d41 100644
--- a/src/test/ui/lint/inclusive-range-pattern-syntax.stderr
+++ b/src/test/ui/lint/inclusive-range-pattern-syntax.stderr
@@ -4,13 +4,13 @@ warning: `...` range patterns are deprecated
LL | 1...2 => {}
| ^^^ help: use `..=` for an inclusive range
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
note: the lint level is defined here
--> $DIR/inclusive-range-pattern-syntax.rs:4:9
|
LL | #![warn(ellipsis_inclusive_range_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
warning: `...` range patterns are deprecated
--> $DIR/inclusive-range-pattern-syntax.rs:16:9
diff --git a/src/test/ui/lint/inert-attr-macro.stderr b/src/test/ui/lint/inert-attr-macro.stderr
index 3b3aa5d0b..5ccb4ffe7 100644
--- a/src/test/ui/lint/inert-attr-macro.stderr
+++ b/src/test/ui/lint/inert-attr-macro.stderr
@@ -4,17 +4,17 @@ warning: unused attribute `inline`
LL | #[inline] foo!();
| ^^^^^^^^^
|
+note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo`
+ --> $DIR/inert-attr-macro.rs:10:15
+ |
+LL | #[inline] foo!();
+ | ^^^
note: the lint level is defined here
--> $DIR/inert-attr-macro.rs:3:9
|
LL | #![warn(unused)]
| ^^^^^^
= note: `#[warn(unused_attributes)]` implied by `#[warn(unused)]`
-note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo`
- --> $DIR/inert-attr-macro.rs:10:15
- |
-LL | #[inline] foo!();
- | ^^^
warning: unused attribute `allow`
--> $DIR/inert-attr-macro.rs:14:5
diff --git a/src/test/ui/lint/inline-trait-and-foreign-items.stderr b/src/test/ui/lint/inline-trait-and-foreign-items.stderr
index fc7e89e4f..2f1fb4c46 100644
--- a/src/test/ui/lint/inline-trait-and-foreign-items.stderr
+++ b/src/test/ui/lint/inline-trait-and-foreign-items.stderr
@@ -4,13 +4,13 @@ warning: `#[inline]` is ignored on constants
LL | #[inline]
| ^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: see issue #65833 <https://github.com/rust-lang/rust/issues/65833> for more information
note: the lint level is defined here
--> $DIR/inline-trait-and-foreign-items.rs:4:9
|
LL | #![warn(unused_attributes)]
| ^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: see issue #65833 <https://github.com/rust-lang/rust/issues/65833> for more information
error[E0518]: attribute should be applied to function or closure
--> $DIR/inline-trait-and-foreign-items.rs:11:5
@@ -67,7 +67,7 @@ error: unconstrained opaque type
LL | type U = impl Trait;
| ^^^^^^^^^^
|
- = note: `U` must be used in combination with a concrete type within the same module
+ = note: `U` must be used in combination with a concrete type within the same impl
error: aborting due to 6 previous errors; 2 warnings emitted
diff --git a/src/test/ui/lint/uninitialized-zeroed.rs b/src/test/ui/lint/invalid_value.rs
index dae258407..57d8cbe7c 100644
--- a/src/test/ui/lint/uninitialized-zeroed.rs
+++ b/src/test/ui/lint/invalid_value.rs
@@ -34,6 +34,20 @@ enum OneFruit {
Banana,
}
+enum OneFruitNonZero {
+ Apple(!),
+ Banana(NonZeroU32),
+}
+
+enum TwoUninhabited {
+ A(!),
+ B(Void),
+}
+
+#[rustc_layout_scalar_valid_range_start(254)]
+#[rustc_layout_scalar_valid_range_end(1)]
+pub(crate) struct WrapAroundRange(u8);
+
#[allow(unused)]
fn generic<T: 'static>() {
unsafe {
@@ -78,12 +92,21 @@ fn main() {
let _val: NonNull<i32> = mem::zeroed(); //~ ERROR: does not permit zero-initialization
let _val: NonNull<i32> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
+ let _val: (NonZeroU32, i32) = mem::zeroed(); //~ ERROR: does not permit zero-initialization
+ let _val: (NonZeroU32, i32) = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
+
let _val: *const dyn Send = mem::zeroed(); //~ ERROR: does not permit zero-initialization
let _val: *const dyn Send = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
let _val: [fn(); 2] = mem::zeroed(); //~ ERROR: does not permit zero-initialization
let _val: [fn(); 2] = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
+ let _val: TwoUninhabited = mem::zeroed(); //~ ERROR: does not permit zero-initialization
+ let _val: TwoUninhabited = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
+
+ let _val: OneFruitNonZero = mem::zeroed(); //~ ERROR: does not permit zero-initialization
+ let _val: OneFruitNonZero = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
+
// Things that can be zero, but not uninit.
let _val: bool = mem::zeroed();
let _val: bool = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
@@ -112,6 +135,19 @@ fn main() {
let _val: *const [()] = mem::zeroed();
let _val: *const [()] = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
+ let _val: WrapAroundRange = mem::zeroed();
+ let _val: WrapAroundRange = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
+
+ // Things where 0 is okay due to rustc implementation details,
+ // but that are not guaranteed to keep working.
+ let _val: Result<i32, i32> = mem::zeroed();
+ let _val: Result<i32, i32> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
+
+ // Some things that happen to be UB-free due to rustc implementation details,
+ // but are not guaranteed to keep working.
+ let _val: OneFruit = mem::zeroed();
+ let _val: OneFruit = mem::uninitialized();
+
// Transmute-from-0
let _val: &'static i32 = mem::transmute(0usize); //~ ERROR: does not permit zero-initialization
let _val: &'static [i32] = mem::transmute((0usize, 0usize)); //~ ERROR: does not permit zero-initialization
@@ -129,9 +165,5 @@ fn main() {
let _val: bool = MaybeUninit::zeroed().assume_init();
let _val: [bool; 0] = MaybeUninit::uninit().assume_init();
let _val: [!; 0] = MaybeUninit::zeroed().assume_init();
-
- // Some things that happen to work due to rustc implementation details,
- // but are not guaranteed to keep working.
- let _val: OneFruit = mem::uninitialized();
}
}
diff --git a/src/test/ui/lint/uninitialized-zeroed.stderr b/src/test/ui/lint/invalid_value.stderr
index b46042e7b..76afb765f 100644
--- a/src/test/ui/lint/uninitialized-zeroed.stderr
+++ b/src/test/ui/lint/invalid_value.stderr
@@ -1,5 +1,5 @@
error: the type `&T` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:40:32
+ --> $DIR/invalid_value.rs:54:32
|
LL | let _val: &'static T = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -7,15 +7,15 @@ LL | let _val: &'static T = mem::zeroed();
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
+ = note: references must be non-null
note: the lint level is defined here
- --> $DIR/uninitialized-zeroed.rs:6:9
+ --> $DIR/invalid_value.rs:6:9
|
LL | #![deny(invalid_value)]
| ^^^^^^^^^^^^^
- = note: references must be non-null
error: the type `&T` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:41:32
+ --> $DIR/invalid_value.rs:55:32
|
LL | let _val: &'static T = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -26,7 +26,7 @@ LL | let _val: &'static T = mem::uninitialized();
= note: references must be non-null
error: the type `Wrap<&T>` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:43:38
+ --> $DIR/invalid_value.rs:57:38
|
LL | let _val: Wrap<&'static T> = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -35,13 +35,13 @@ LL | let _val: Wrap<&'static T> = mem::zeroed();
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
note: references must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:17:18
+ --> $DIR/invalid_value.rs:17:18
|
LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^
error: the type `Wrap<&T>` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:44:38
+ --> $DIR/invalid_value.rs:58:38
|
LL | let _val: Wrap<&'static T> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -50,13 +50,13 @@ LL | let _val: Wrap<&'static T> = mem::uninitialized();
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
note: references must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:17:18
+ --> $DIR/invalid_value.rs:17:18
|
LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^
error: the type `!` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:51:23
+ --> $DIR/invalid_value.rs:65:23
|
LL | let _val: ! = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -67,7 +67,7 @@ LL | let _val: ! = mem::zeroed();
= note: the `!` type has no valid value
error: the type `!` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:52:23
+ --> $DIR/invalid_value.rs:66:23
|
LL | let _val: ! = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -78,7 +78,7 @@ LL | let _val: ! = mem::uninitialized();
= note: the `!` type has no valid value
error: the type `(i32, !)` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:54:30
+ --> $DIR/invalid_value.rs:68:30
|
LL | let _val: (i32, !) = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -89,7 +89,7 @@ LL | let _val: (i32, !) = mem::zeroed();
= note: the `!` type has no valid value
error: the type `(i32, !)` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:55:30
+ --> $DIR/invalid_value.rs:69:30
|
LL | let _val: (i32, !) = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -100,7 +100,7 @@ LL | let _val: (i32, !) = mem::uninitialized();
= note: integers must not be uninitialized
error: the type `Void` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:57:26
+ --> $DIR/invalid_value.rs:71:26
|
LL | let _val: Void = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -108,10 +108,14 @@ LL | let _val: Void = mem::zeroed();
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
- = note: enums with no variants have no valid value
+note: enums with no inhabited variants have no valid value
+ --> $DIR/invalid_value.rs:12:1
+ |
+LL | enum Void {}
+ | ^^^^^^^^^
error: the type `Void` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:58:26
+ --> $DIR/invalid_value.rs:72:26
|
LL | let _val: Void = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -119,10 +123,14 @@ LL | let _val: Void = mem::uninitialized();
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
- = note: enums with no variants have no valid value
+note: enums with no inhabited variants have no valid value
+ --> $DIR/invalid_value.rs:12:1
+ |
+LL | enum Void {}
+ | ^^^^^^^^^
error: the type `&i32` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:60:34
+ --> $DIR/invalid_value.rs:74:34
|
LL | let _val: &'static i32 = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -133,7 +141,7 @@ LL | let _val: &'static i32 = mem::zeroed();
= note: references must be non-null
error: the type `&i32` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:61:34
+ --> $DIR/invalid_value.rs:75:34
|
LL | let _val: &'static i32 = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -144,7 +152,7 @@ LL | let _val: &'static i32 = mem::uninitialized();
= note: references must be non-null
error: the type `Ref` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:63:25
+ --> $DIR/invalid_value.rs:77:25
|
LL | let _val: Ref = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -153,13 +161,13 @@ LL | let _val: Ref = mem::zeroed();
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
note: references must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:14:12
+ --> $DIR/invalid_value.rs:14:12
|
LL | struct Ref(&'static i32);
| ^^^^^^^^^^^^
error: the type `Ref` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:64:25
+ --> $DIR/invalid_value.rs:78:25
|
LL | let _val: Ref = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -168,13 +176,13 @@ LL | let _val: Ref = mem::uninitialized();
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
note: references must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:14:12
+ --> $DIR/invalid_value.rs:14:12
|
LL | struct Ref(&'static i32);
| ^^^^^^^^^^^^
error: the type `fn()` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:66:26
+ --> $DIR/invalid_value.rs:80:26
|
LL | let _val: fn() = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -185,7 +193,7 @@ LL | let _val: fn() = mem::zeroed();
= note: function pointers must be non-null
error: the type `fn()` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:67:26
+ --> $DIR/invalid_value.rs:81:26
|
LL | let _val: fn() = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -196,7 +204,7 @@ LL | let _val: fn() = mem::uninitialized();
= note: function pointers must be non-null
error: the type `Wrap<fn()>` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:69:32
+ --> $DIR/invalid_value.rs:83:32
|
LL | let _val: Wrap<fn()> = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -205,13 +213,13 @@ LL | let _val: Wrap<fn()> = mem::zeroed();
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
note: function pointers must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:17:18
+ --> $DIR/invalid_value.rs:17:18
|
LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^
error: the type `Wrap<fn()>` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:70:32
+ --> $DIR/invalid_value.rs:84:32
|
LL | let _val: Wrap<fn()> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -220,13 +228,13 @@ LL | let _val: Wrap<fn()> = mem::uninitialized();
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
note: function pointers must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:17:18
+ --> $DIR/invalid_value.rs:17:18
|
LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^
error: the type `WrapEnum<fn()>` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:72:36
+ --> $DIR/invalid_value.rs:86:36
|
LL | let _val: WrapEnum<fn()> = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -234,14 +242,14 @@ LL | let _val: WrapEnum<fn()> = mem::zeroed();
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
-note: function pointers must be non-null (in this enum field)
- --> $DIR/uninitialized-zeroed.rs:18:28
+note: function pointers must be non-null (in this field of the only potentially inhabited enum variant)
+ --> $DIR/invalid_value.rs:18:28
|
LL | enum WrapEnum<T> { Wrapped(T) }
| ^
error: the type `WrapEnum<fn()>` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:73:36
+ --> $DIR/invalid_value.rs:87:36
|
LL | let _val: WrapEnum<fn()> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -249,14 +257,14 @@ LL | let _val: WrapEnum<fn()> = mem::uninitialized();
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
-note: function pointers must be non-null (in this enum field)
- --> $DIR/uninitialized-zeroed.rs:18:28
+note: function pointers must be non-null (in this field of the only potentially inhabited enum variant)
+ --> $DIR/invalid_value.rs:18:28
|
LL | enum WrapEnum<T> { Wrapped(T) }
| ^
error: the type `Wrap<(RefPair, i32)>` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:75:42
+ --> $DIR/invalid_value.rs:89:42
|
LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -265,13 +273,13 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::zeroed();
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
note: references must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:15:16
+ --> $DIR/invalid_value.rs:15:16
|
LL | struct RefPair((&'static i32, i32));
| ^^^^^^^^^^^^^^^^^^^
error: the type `Wrap<(RefPair, i32)>` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:76:42
+ --> $DIR/invalid_value.rs:90:42
|
LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -280,13 +288,13 @@ LL | let _val: Wrap<(RefPair, i32)> = mem::uninitialized();
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
note: references must be non-null (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:15:16
+ --> $DIR/invalid_value.rs:15:16
|
LL | struct RefPair((&'static i32, i32));
| ^^^^^^^^^^^^^^^^^^^
error: the type `NonNull<i32>` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:78:34
+ --> $DIR/invalid_value.rs:92:34
|
LL | let _val: NonNull<i32> = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -297,7 +305,7 @@ LL | let _val: NonNull<i32> = mem::zeroed();
= note: `std::ptr::NonNull<i32>` must be non-null
error: the type `NonNull<i32>` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:79:34
+ --> $DIR/invalid_value.rs:93:34
|
LL | let _val: NonNull<i32> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -307,8 +315,30 @@ LL | let _val: NonNull<i32> = mem::uninitialized();
|
= note: `std::ptr::NonNull<i32>` must be non-null
+error: the type `(NonZeroU32, i32)` does not permit zero-initialization
+ --> $DIR/invalid_value.rs:95:39
+ |
+LL | let _val: (NonZeroU32, i32) = mem::zeroed();
+ | ^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
+ |
+ = note: `std::num::NonZeroU32` must be non-null
+
+error: the type `(NonZeroU32, i32)` does not permit being left uninitialized
+ --> $DIR/invalid_value.rs:96:39
+ |
+LL | let _val: (NonZeroU32, i32) = mem::uninitialized();
+ | ^^^^^^^^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
+ |
+ = note: `std::num::NonZeroU32` must be non-null
+
error: the type `*const dyn Send` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:81:37
+ --> $DIR/invalid_value.rs:98:37
|
LL | let _val: *const dyn Send = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -319,7 +349,7 @@ LL | let _val: *const dyn Send = mem::zeroed();
= note: the vtable of a wide raw pointer must be non-null
error: the type `*const dyn Send` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:82:37
+ --> $DIR/invalid_value.rs:99:37
|
LL | let _val: *const dyn Send = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -330,7 +360,7 @@ LL | let _val: *const dyn Send = mem::uninitialized();
= note: the vtable of a wide raw pointer must be non-null
error: the type `[fn(); 2]` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:84:31
+ --> $DIR/invalid_value.rs:101:31
|
LL | let _val: [fn(); 2] = mem::zeroed();
| ^^^^^^^^^^^^^
@@ -341,7 +371,7 @@ LL | let _val: [fn(); 2] = mem::zeroed();
= note: function pointers must be non-null
error: the type `[fn(); 2]` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:85:31
+ --> $DIR/invalid_value.rs:102:31
|
LL | let _val: [fn(); 2] = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -351,8 +381,68 @@ LL | let _val: [fn(); 2] = mem::uninitialized();
|
= note: function pointers must be non-null
+error: the type `TwoUninhabited` does not permit zero-initialization
+ --> $DIR/invalid_value.rs:104:36
+ |
+LL | let _val: TwoUninhabited = mem::zeroed();
+ | ^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
+ |
+note: enums with no inhabited variants have no valid value
+ --> $DIR/invalid_value.rs:42:1
+ |
+LL | enum TwoUninhabited {
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: the type `TwoUninhabited` does not permit being left uninitialized
+ --> $DIR/invalid_value.rs:105:36
+ |
+LL | let _val: TwoUninhabited = mem::uninitialized();
+ | ^^^^^^^^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
+ |
+note: enums with no inhabited variants have no valid value
+ --> $DIR/invalid_value.rs:42:1
+ |
+LL | enum TwoUninhabited {
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: the type `OneFruitNonZero` does not permit zero-initialization
+ --> $DIR/invalid_value.rs:107:37
+ |
+LL | let _val: OneFruitNonZero = mem::zeroed();
+ | ^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
+ |
+note: `std::num::NonZeroU32` must be non-null (in this field of the only potentially inhabited enum variant)
+ --> $DIR/invalid_value.rs:39:12
+ |
+LL | Banana(NonZeroU32),
+ | ^^^^^^^^^^
+
+error: the type `OneFruitNonZero` does not permit being left uninitialized
+ --> $DIR/invalid_value.rs:108:37
+ |
+LL | let _val: OneFruitNonZero = mem::uninitialized();
+ | ^^^^^^^^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
+ |
+note: `std::num::NonZeroU32` must be non-null (in this field of the only potentially inhabited enum variant)
+ --> $DIR/invalid_value.rs:39:12
+ |
+LL | Banana(NonZeroU32),
+ | ^^^^^^^^^^
+
error: the type `bool` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:89:26
+ --> $DIR/invalid_value.rs:112:26
|
LL | let _val: bool = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -363,7 +453,7 @@ LL | let _val: bool = mem::uninitialized();
= note: booleans must be either `true` or `false`
error: the type `Wrap<char>` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:92:32
+ --> $DIR/invalid_value.rs:115:32
|
LL | let _val: Wrap<char> = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -372,13 +462,13 @@ LL | let _val: Wrap<char> = mem::uninitialized();
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
note: characters must be a valid Unicode codepoint (in this struct field)
- --> $DIR/uninitialized-zeroed.rs:17:18
+ --> $DIR/invalid_value.rs:17:18
|
LL | struct Wrap<T> { wrapped: T }
| ^^^^^^^^^^
error: the type `NonBig` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:95:28
+ --> $DIR/invalid_value.rs:118:28
|
LL | let _val: NonBig = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -389,7 +479,7 @@ LL | let _val: NonBig = mem::uninitialized();
= note: `NonBig` must be initialized inside its custom valid range
error: the type `Fruit` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:98:27
+ --> $DIR/invalid_value.rs:121:27
|
LL | let _val: Fruit = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -397,14 +487,14 @@ LL | let _val: Fruit = mem::uninitialized();
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
-note: enums have to be initialized to a variant
- --> $DIR/uninitialized-zeroed.rs:26:1
+note: enums with multiple inhabited variants have to be initialized to a variant
+ --> $DIR/invalid_value.rs:26:1
|
LL | enum Fruit {
| ^^^^^^^^^^
error: the type `[bool; 2]` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:101:31
+ --> $DIR/invalid_value.rs:124:31
|
LL | let _val: [bool; 2] = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -415,7 +505,7 @@ LL | let _val: [bool; 2] = mem::uninitialized();
= note: booleans must be either `true` or `false`
error: the type `i32` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:104:25
+ --> $DIR/invalid_value.rs:127:25
|
LL | let _val: i32 = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -426,7 +516,7 @@ LL | let _val: i32 = mem::uninitialized();
= note: integers must not be uninitialized
error: the type `f32` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:107:25
+ --> $DIR/invalid_value.rs:130:25
|
LL | let _val: f32 = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -437,7 +527,7 @@ LL | let _val: f32 = mem::uninitialized();
= note: floats must not be uninitialized
error: the type `*const ()` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:110:31
+ --> $DIR/invalid_value.rs:133:31
|
LL | let _val: *const () = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -448,7 +538,7 @@ LL | let _val: *const () = mem::uninitialized();
= note: raw pointers must not be uninitialized
error: the type `*const [()]` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:113:33
+ --> $DIR/invalid_value.rs:136:33
|
LL | let _val: *const [()] = mem::uninitialized();
| ^^^^^^^^^^^^^^^^^^^^
@@ -458,8 +548,34 @@ LL | let _val: *const [()] = mem::uninitialized();
|
= note: raw pointers must not be uninitialized
+error: the type `WrapAroundRange` does not permit being left uninitialized
+ --> $DIR/invalid_value.rs:139:37
+ |
+LL | let _val: WrapAroundRange = mem::uninitialized();
+ | ^^^^^^^^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
+ |
+ = note: `WrapAroundRange` must be initialized inside its custom valid range
+
+error: the type `Result<i32, i32>` does not permit being left uninitialized
+ --> $DIR/invalid_value.rs:144:38
+ |
+LL | let _val: Result<i32, i32> = mem::uninitialized();
+ | ^^^^^^^^^^^^^^^^^^^^
+ | |
+ | this code causes undefined behavior when executed
+ | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
+ |
+note: enums with multiple inhabited variants have to be initialized to a variant
+ --> $SRC_DIR/core/src/result.rs:LL:COL
+ |
+LL | pub enum Result<T, E> {
+ | ^^^^^^^^^^^^^^^^^^^^^
+
error: the type `&i32` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:116:34
+ --> $DIR/invalid_value.rs:152:34
|
LL | let _val: &'static i32 = mem::transmute(0usize);
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -470,7 +586,7 @@ LL | let _val: &'static i32 = mem::transmute(0usize);
= note: references must be non-null
error: the type `&[i32]` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:117:36
+ --> $DIR/invalid_value.rs:153:36
|
LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -481,7 +597,7 @@ LL | let _val: &'static [i32] = mem::transmute((0usize, 0usize));
= note: references must be non-null
error: the type `NonZeroU32` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:118:32
+ --> $DIR/invalid_value.rs:154:32
|
LL | let _val: NonZeroU32 = mem::transmute(0);
| ^^^^^^^^^^^^^^^^^
@@ -492,7 +608,7 @@ LL | let _val: NonZeroU32 = mem::transmute(0);
= note: `std::num::NonZeroU32` must be non-null
error: the type `NonNull<i32>` does not permit zero-initialization
- --> $DIR/uninitialized-zeroed.rs:121:34
+ --> $DIR/invalid_value.rs:157:34
|
LL | let _val: NonNull<i32> = MaybeUninit::zeroed().assume_init();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -503,7 +619,7 @@ LL | let _val: NonNull<i32> = MaybeUninit::zeroed().assume_init();
= note: `std::ptr::NonNull<i32>` must be non-null
error: the type `NonNull<i32>` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:122:34
+ --> $DIR/invalid_value.rs:158:34
|
LL | let _val: NonNull<i32> = MaybeUninit::uninit().assume_init();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -514,7 +630,7 @@ LL | let _val: NonNull<i32> = MaybeUninit::uninit().assume_init();
= note: `std::ptr::NonNull<i32>` must be non-null
error: the type `bool` does not permit being left uninitialized
- --> $DIR/uninitialized-zeroed.rs:123:26
+ --> $DIR/invalid_value.rs:159:26
|
LL | let _val: bool = MaybeUninit::uninit().assume_init();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -524,5 +640,5 @@ LL | let _val: bool = MaybeUninit::uninit().assume_init();
|
= note: booleans must be either `true` or `false`
-error: aborting due to 43 previous errors
+error: aborting due to 51 previous errors
diff --git a/src/test/ui/lint/issue-102705.rs b/src/test/ui/lint/issue-102705.rs
new file mode 100644
index 000000000..5bcc8950a
--- /dev/null
+++ b/src/test/ui/lint/issue-102705.rs
@@ -0,0 +1,22 @@
+// check-pass
+
+#![allow(opaque_hidden_inferred_bound)]
+#![allow(dead_code)]
+
+trait Duh {}
+
+impl Duh for i32 {}
+
+trait Trait {
+ type Assoc: Duh;
+}
+
+impl<R: Duh, F: FnMut() -> R> Trait for F {
+ type Assoc = R;
+}
+
+fn foo() -> impl Trait<Assoc = impl Send> {
+ || 42
+}
+
+fn main() {}
diff --git a/src/test/ui/lint/issue-14309.stderr b/src/test/ui/lint/issue-14309.stderr
index a9538b5e3..9ce62a6b8 100644
--- a/src/test/ui/lint/issue-14309.stderr
+++ b/src/test/ui/lint/issue-14309.stderr
@@ -4,11 +4,6 @@ error: `extern` block uses type `A`, which is not FFI-safe
LL | fn foo(x: A);
| ^ not FFI-safe
|
-note: the lint level is defined here
- --> $DIR/issue-14309.rs:1:9
- |
-LL | #![deny(improper_ctypes)]
- | ^^^^^^^^^^^^^^^
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
note: the type is defined here
@@ -16,6 +11,11 @@ note: the type is defined here
|
LL | struct A {
| ^^^^^^^^
+note: the lint level is defined here
+ --> $DIR/issue-14309.rs:1:9
+ |
+LL | #![deny(improper_ctypes)]
+ | ^^^^^^^^^^^^^^^
error: `extern` block uses type `A`, which is not FFI-safe
--> $DIR/issue-14309.rs:31:15
diff --git a/src/test/ui/lint/issue-1866.stderr b/src/test/ui/lint/issue-1866.stderr
index 5edae48a1..d19a13496 100644
--- a/src/test/ui/lint/issue-1866.stderr
+++ b/src/test/ui/lint/issue-1866.stderr
@@ -7,13 +7,13 @@ LL | pub fn rust_task_is_unwinding(rt: *const rust_task) -> bool;
LL | pub fn rust_task_is_unwinding(rt: *const rust_task) -> bool;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
|
+ = note: expected `unsafe extern "C" fn(*const usize) -> bool`
+ found `unsafe extern "C" fn(*const bool) -> bool`
note: the lint level is defined here
--> $DIR/issue-1866.rs:4:9
|
LL | #![warn(clashing_extern_declarations)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: expected `unsafe extern "C" fn(*const usize) -> bool`
- found `unsafe extern "C" fn(*const bool) -> bool`
warning: 1 warning emitted
diff --git a/src/test/ui/lint/issue-63364.stderr b/src/test/ui/lint/issue-63364.stderr
index 0375359ae..9b5453fa8 100644
--- a/src/test/ui/lint/issue-63364.stderr
+++ b/src/test/ui/lint/issue-63364.stderr
@@ -4,8 +4,8 @@ error: literal out of range for `u16`
LL | for n in 100_000.. {
| ^^^^^^^
|
- = note: `#[deny(overflowing_literals)]` on by default
= note: the literal `100_000` does not fit into the type `u16` whose range is `0..=65535`
+ = note: `#[deny(overflowing_literals)]` on by default
error: aborting due to previous error
diff --git a/src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.stderr b/src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.stderr
index 5093715de..cc44f8aa5 100644
--- a/src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.stderr
+++ b/src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.stderr
@@ -6,13 +6,13 @@ LL | #![forbid(unused)]
LL | #![deny(unused)]
| ^^^^^^ overruled by previous forbid
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
note: the lint level is defined here
--> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:17:11
|
LL | #![forbid(forbidden_lint_groups)]
| ^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
error: aborting due to previous error
diff --git a/src/test/ui/lint/issue-79744.stderr b/src/test/ui/lint/issue-79744.stderr
index 6f6dd44d2..c1b56250d 100644
--- a/src/test/ui/lint/issue-79744.stderr
+++ b/src/test/ui/lint/issue-79744.stderr
@@ -4,9 +4,9 @@ error: literal out of range for `i8`
LL | let e2 = 230;
| ^^^
|
- = note: `#[deny(overflowing_literals)]` on by default
= note: the literal `230` does not fit into the type `i8` whose range is `-128..=127`
= help: consider using the type `u8` instead
+ = note: `#[deny(overflowing_literals)]` on by default
error: aborting due to previous error
diff --git a/src/test/ui/lint/issue-80988.stderr b/src/test/ui/lint/issue-80988.stderr
index 1d397f431..73e27ffda 100644
--- a/src/test/ui/lint/issue-80988.stderr
+++ b/src/test/ui/lint/issue-80988.stderr
@@ -7,9 +7,9 @@ LL |
LL | #[deny(warnings)]
| ^^^^^^^^ overruled by previous forbid
|
- = note: `#[warn(forbidden_lint_groups)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
+ = note: `#[warn(forbidden_lint_groups)]` on by default
warning: deny(warnings) incompatible with previous forbid
--> $DIR/issue-80988.rs:7:8
diff --git a/src/test/ui/lint/issue-83477.stderr b/src/test/ui/lint/issue-83477.stderr
index e619bcfe2..f824fc09e 100644
--- a/src/test/ui/lint/issue-83477.stderr
+++ b/src/test/ui/lint/issue-83477.stderr
@@ -18,13 +18,13 @@ warning: prefer `FxHashMap` over `HashMap`, it has better performance
LL | let _ = std::collections::HashMap::<String, String>::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
+ = note: a `use rustc_data_structures::fx::FxHashMap` may be necessary
note: the lint level is defined here
--> $DIR/issue-83477.rs:3:9
|
LL | #![warn(rustc::internal)]
| ^^^^^^^^^^^^^^^
= note: `#[warn(rustc::default_hash_types)]` implied by `#[warn(rustc::internal)]`
- = note: a `use rustc_data_structures::fx::FxHashMap` may be necessary
warning: 3 warnings emitted
diff --git a/src/test/ui/lint/issue-86600-lint-twice.stderr b/src/test/ui/lint/issue-86600-lint-twice.stderr
index 8da3fb5a8..5a65c6121 100644
--- a/src/test/ui/lint/issue-86600-lint-twice.stderr
+++ b/src/test/ui/lint/issue-86600-lint-twice.stderr
@@ -4,9 +4,9 @@ warning: floating-point types cannot be used in patterns
LL | 5.0 => {}
| ^^^
|
- = note: `#[warn(illegal_floating_point_literal_pattern)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
+ = note: `#[warn(illegal_floating_point_literal_pattern)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/lint/lint-attr-everywhere-early.stderr b/src/test/ui/lint/lint-attr-everywhere-early.stderr
index 1d6e3cda4..d6c6d5fae 100644
--- a/src/test/ui/lint/lint-attr-everywhere-early.stderr
+++ b/src/test/ui/lint/lint-attr-everywhere-early.stderr
@@ -474,13 +474,13 @@ error: `...` range patterns are deprecated
LL | f1: 0...100,
| ^^^ help: use `..=` for an inclusive range
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
note: the lint level is defined here
--> $DIR/lint-attr-everywhere-early.rs:166:20
|
LL | #[deny(ellipsis_inclusive_range_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
error: aborting due to 36 previous errors
diff --git a/src/test/ui/lint/lint-attr-everywhere-late.stderr b/src/test/ui/lint/lint-attr-everywhere-late.stderr
index 977843997..a69c2e0ef 100644
--- a/src/test/ui/lint/lint-attr-everywhere-late.stderr
+++ b/src/test/ui/lint/lint-attr-everywhere-late.stderr
@@ -163,13 +163,13 @@ LL | fn clashing1();
LL | fn clashing1(_: i32);
| ^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
|
+ = note: expected `unsafe extern "C" fn()`
+ found `unsafe extern "C" fn(i32)`
note: the lint level is defined here
--> $DIR/lint-attr-everywhere-late.rs:122:13
|
LL | #![deny(clashing_extern_declarations)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: expected `unsafe extern "C" fn()`
- found `unsafe extern "C" fn(i32)`
error: `clashing2` redeclared with a different signature
--> $DIR/lint-attr-everywhere-late.rs:128:5
@@ -180,13 +180,13 @@ LL | fn clashing2();
LL | fn clashing2(_: i32);
| ^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
|
+ = note: expected `unsafe extern "C" fn()`
+ found `unsafe extern "C" fn(i32)`
note: the lint level is defined here
--> $DIR/lint-attr-everywhere-late.rs:127:12
|
LL | #[deny(clashing_extern_declarations)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: expected `unsafe extern "C" fn()`
- found `unsafe extern "C" fn(i32)`
error: types that do not implement `Drop` can still have drop glue, consider instead using `std::mem::needs_drop` to detect whether a type is trivially dropped
--> $DIR/lint-attr-everywhere-late.rs:93:38
@@ -206,16 +206,16 @@ error: the return value of `mem::discriminant` is unspecified when called with a
LL | fn assoc_fn() { discriminant::<i32>(&123); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the lint level is defined here
- --> $DIR/lint-attr-everywhere-late.rs:95:12
- |
-LL | #[deny(enum_intrinsics_non_enums)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `i32`, which is not an enum.
--> $DIR/lint-attr-everywhere-late.rs:96:41
|
LL | fn assoc_fn() { discriminant::<i32>(&123); }
| ^^^^
+note: the lint level is defined here
+ --> $DIR/lint-attr-everywhere-late.rs:95:12
+ |
+LL | #[deny(enum_intrinsics_non_enums)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: literal out of range for `u8`
--> $DIR/lint-attr-everywhere-late.rs:98:59
@@ -223,12 +223,12 @@ error: literal out of range for `u8`
LL | #[deny(overflowing_literals)] const ASSOC_CONST: u8 = 1000;
| ^^^^
|
+ = note: the literal `1000` does not fit into the type `u8` whose range is `0..=255`
note: the lint level is defined here
--> $DIR/lint-attr-everywhere-late.rs:98:12
|
LL | #[deny(overflowing_literals)] const ASSOC_CONST: u8 = 1000;
| ^^^^^^^^^^^^^^^^^^^^
- = note: the literal `1000` does not fit into the type `u8` whose range is `0..=255`
error: variable `PARAM` should have a snake case name
--> $DIR/lint-attr-everywhere-late.rs:131:37
@@ -248,16 +248,16 @@ error: the return value of `mem::discriminant` is unspecified when called with a
LL | let _ = discriminant::<i32>(&123);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the lint level is defined here
- --> $DIR/lint-attr-everywhere-late.rs:138:12
- |
-LL | #[deny(enum_intrinsics_non_enums)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `i32`, which is not an enum.
--> $DIR/lint-attr-everywhere-late.rs:139:33
|
LL | let _ = discriminant::<i32>(&123);
| ^^^^
+note: the lint level is defined here
+ --> $DIR/lint-attr-everywhere-late.rs:138:12
+ |
+LL | #[deny(enum_intrinsics_non_enums)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: variable `PARAM` should have a snake case name
--> $DIR/lint-attr-everywhere-late.rs:145:44
@@ -277,16 +277,16 @@ error: the return value of `mem::discriminant` is unspecified when called with a
LL | discriminant::<i32>(&123);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the lint level is defined here
- --> $DIR/lint-attr-everywhere-late.rs:153:17
- |
-LL | #![deny(enum_intrinsics_non_enums)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `i32`, which is not an enum.
--> $DIR/lint-attr-everywhere-late.rs:155:33
|
LL | discriminant::<i32>(&123);
| ^^^^
+note: the lint level is defined here
+ --> $DIR/lint-attr-everywhere-late.rs:153:17
+ |
+LL | #![deny(enum_intrinsics_non_enums)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: the return value of `mem::discriminant` is unspecified when called with a non-enum type
--> $DIR/lint-attr-everywhere-late.rs:161:13
@@ -294,16 +294,16 @@ error: the return value of `mem::discriminant` is unspecified when called with a
LL | discriminant::<i32>(&123);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the lint level is defined here
- --> $DIR/lint-attr-everywhere-late.rs:159:16
- |
-LL | #[deny(enum_intrinsics_non_enums)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `i32`, which is not an enum.
--> $DIR/lint-attr-everywhere-late.rs:161:33
|
LL | discriminant::<i32>(&123);
| ^^^^
+note: the lint level is defined here
+ --> $DIR/lint-attr-everywhere-late.rs:159:16
+ |
+LL | #[deny(enum_intrinsics_non_enums)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: the return value of `mem::discriminant` is unspecified when called with a non-enum type
--> $DIR/lint-attr-everywhere-late.rs:168:9
@@ -311,16 +311,16 @@ error: the return value of `mem::discriminant` is unspecified when called with a
LL | discriminant::<i32>(&123);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the lint level is defined here
- --> $DIR/lint-attr-everywhere-late.rs:167:17
- |
-LL | #![deny(enum_intrinsics_non_enums)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `i32`, which is not an enum.
--> $DIR/lint-attr-everywhere-late.rs:168:29
|
LL | discriminant::<i32>(&123);
| ^^^^
+note: the lint level is defined here
+ --> $DIR/lint-attr-everywhere-late.rs:167:17
+ |
+LL | #![deny(enum_intrinsics_non_enums)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: the return value of `mem::discriminant` is unspecified when called with a non-enum type
--> $DIR/lint-attr-everywhere-late.rs:172:9
@@ -328,16 +328,16 @@ error: the return value of `mem::discriminant` is unspecified when called with a
LL | discriminant::<i32>(&123);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the lint level is defined here
- --> $DIR/lint-attr-everywhere-late.rs:171:16
- |
-LL | #[deny(enum_intrinsics_non_enums)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `i32`, which is not an enum.
--> $DIR/lint-attr-everywhere-late.rs:172:29
|
LL | discriminant::<i32>(&123);
| ^^^^
+note: the lint level is defined here
+ --> $DIR/lint-attr-everywhere-late.rs:171:16
+ |
+LL | #[deny(enum_intrinsics_non_enums)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: the return value of `mem::discriminant` is unspecified when called with a non-enum type
--> $DIR/lint-attr-everywhere-late.rs:177:5
@@ -345,16 +345,16 @@ error: the return value of `mem::discriminant` is unspecified when called with a
LL | discriminant::<i32>(&123);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the lint level is defined here
- --> $DIR/lint-attr-everywhere-late.rs:176:12
- |
-LL | #[deny(enum_intrinsics_non_enums)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `i32`, which is not an enum.
--> $DIR/lint-attr-everywhere-late.rs:177:25
|
LL | discriminant::<i32>(&123);
| ^^^^
+note: the lint level is defined here
+ --> $DIR/lint-attr-everywhere-late.rs:176:12
+ |
+LL | #[deny(enum_intrinsics_non_enums)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: the return value of `mem::discriminant` is unspecified when called with a non-enum type
--> $DIR/lint-attr-everywhere-late.rs:179:41
@@ -362,16 +362,16 @@ error: the return value of `mem::discriminant` is unspecified when called with a
LL | [#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123)];
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the lint level is defined here
- --> $DIR/lint-attr-everywhere-late.rs:179:13
- |
-LL | [#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123)];
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `i32`, which is not an enum.
--> $DIR/lint-attr-everywhere-late.rs:179:61
|
LL | [#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123)];
| ^^^^
+note: the lint level is defined here
+ --> $DIR/lint-attr-everywhere-late.rs:179:13
+ |
+LL | [#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123)];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: the return value of `mem::discriminant` is unspecified when called with a non-enum type
--> $DIR/lint-attr-everywhere-late.rs:180:41
@@ -379,16 +379,16 @@ error: the return value of `mem::discriminant` is unspecified when called with a
LL | (#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123),);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the lint level is defined here
- --> $DIR/lint-attr-everywhere-late.rs:180:13
- |
-LL | (#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123),);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `i32`, which is not an enum.
--> $DIR/lint-attr-everywhere-late.rs:180:61
|
LL | (#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123),);
| ^^^^
+note: the lint level is defined here
+ --> $DIR/lint-attr-everywhere-late.rs:180:13
+ |
+LL | (#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123),);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: the return value of `mem::discriminant` is unspecified when called with a non-enum type
--> $DIR/lint-attr-everywhere-late.rs:182:45
@@ -396,16 +396,16 @@ error: the return value of `mem::discriminant` is unspecified when called with a
LL | call(#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123));
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the lint level is defined here
- --> $DIR/lint-attr-everywhere-late.rs:182:17
- |
-LL | call(#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `i32`, which is not an enum.
--> $DIR/lint-attr-everywhere-late.rs:182:65
|
LL | call(#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123));
| ^^^^
+note: the lint level is defined here
+ --> $DIR/lint-attr-everywhere-late.rs:182:17
+ |
+LL | call(#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: the return value of `mem::discriminant` is unspecified when called with a non-enum type
--> $DIR/lint-attr-everywhere-late.rs:184:52
@@ -413,16 +413,16 @@ error: the return value of `mem::discriminant` is unspecified when called with a
LL | TupleStruct(#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123));
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
-note: the lint level is defined here
- --> $DIR/lint-attr-everywhere-late.rs:184:24
- |
-LL | TupleStruct(#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123));
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `i32`, which is not an enum.
--> $DIR/lint-attr-everywhere-late.rs:184:72
|
LL | TupleStruct(#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123));
| ^^^^
+note: the lint level is defined here
+ --> $DIR/lint-attr-everywhere-late.rs:184:24
+ |
+LL | TupleStruct(#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 31 previous errors
diff --git a/src/test/ui/lint/lint-const-item-mutation.stderr b/src/test/ui/lint/lint-const-item-mutation.stderr
index 94d876423..9f4360e67 100644
--- a/src/test/ui/lint/lint-const-item-mutation.stderr
+++ b/src/test/ui/lint/lint-const-item-mutation.stderr
@@ -4,13 +4,13 @@ warning: attempting to modify a `const` item
LL | ARRAY[0] = 5;
| ^^^^^^^^^^^^
|
- = note: `#[warn(const_item_mutation)]` on by default
= note: each usage of a `const` item creates a new temporary; the original `const` item will not be modified
note: `const` item defined here
--> $DIR/lint-const-item-mutation.rs:26:1
|
LL | const ARRAY: [u8; 1] = [25];
| ^^^^^^^^^^^^^^^^^^^^
+ = note: `#[warn(const_item_mutation)]` on by default
warning: attempting to modify a `const` item
--> $DIR/lint-const-item-mutation.rs:38:5
diff --git a/src/test/ui/lint/lint-ctypes-73249-2.stderr b/src/test/ui/lint/lint-ctypes-73249-2.stderr
index 7c85e9fa8..8073c33dd 100644
--- a/src/test/ui/lint/lint-ctypes-73249-2.stderr
+++ b/src/test/ui/lint/lint-ctypes-73249-2.stderr
@@ -4,12 +4,12 @@ error: `extern` block uses type `Qux`, which is not FFI-safe
LL | pub fn lint_me() -> A<()>;
| ^^^^^ not FFI-safe
|
+ = note: opaque types have no C equivalent
note: the lint level is defined here
--> $DIR/lint-ctypes-73249-2.rs:2:9
|
LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
- = note: opaque types have no C equivalent
error: aborting due to previous error
diff --git a/src/test/ui/lint/lint-ctypes-73249-3.stderr b/src/test/ui/lint/lint-ctypes-73249-3.stderr
index 83e2a233c..c41ce666d 100644
--- a/src/test/ui/lint/lint-ctypes-73249-3.stderr
+++ b/src/test/ui/lint/lint-ctypes-73249-3.stderr
@@ -4,12 +4,12 @@ error: `extern` block uses type `Qux`, which is not FFI-safe
LL | pub fn lint_me() -> A;
| ^ not FFI-safe
|
+ = note: opaque types have no C equivalent
note: the lint level is defined here
--> $DIR/lint-ctypes-73249-3.rs:2:9
|
LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
- = note: opaque types have no C equivalent
error: aborting due to previous error
diff --git a/src/test/ui/lint/lint-ctypes-73249-5.stderr b/src/test/ui/lint/lint-ctypes-73249-5.stderr
index 37781d78c..98245c4f1 100644
--- a/src/test/ui/lint/lint-ctypes-73249-5.stderr
+++ b/src/test/ui/lint/lint-ctypes-73249-5.stderr
@@ -4,12 +4,12 @@ error: `extern` block uses type `Qux`, which is not FFI-safe
LL | pub fn lint_me() -> A;
| ^ not FFI-safe
|
+ = note: opaque types have no C equivalent
note: the lint level is defined here
--> $DIR/lint-ctypes-73249-5.rs:2:9
|
LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
- = note: opaque types have no C equivalent
error: aborting due to previous error
diff --git a/src/test/ui/lint/lint-ctypes-73251-1.stderr b/src/test/ui/lint/lint-ctypes-73251-1.stderr
index 76b19d37e..9f43576ad 100644
--- a/src/test/ui/lint/lint-ctypes-73251-1.stderr
+++ b/src/test/ui/lint/lint-ctypes-73251-1.stderr
@@ -4,12 +4,12 @@ error: `extern` block uses type `Qux`, which is not FFI-safe
LL | pub fn lint_me() -> <u32 as Foo>::Assoc;
| ^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
+ = note: opaque types have no C equivalent
note: the lint level is defined here
--> $DIR/lint-ctypes-73251-1.rs:2:9
|
LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
- = note: opaque types have no C equivalent
error: aborting due to previous error
diff --git a/src/test/ui/lint/lint-ctypes-73251-2.stderr b/src/test/ui/lint/lint-ctypes-73251-2.stderr
index 64f0fb2d8..0b3de379c 100644
--- a/src/test/ui/lint/lint-ctypes-73251-2.stderr
+++ b/src/test/ui/lint/lint-ctypes-73251-2.stderr
@@ -4,12 +4,12 @@ error: `extern` block uses type `AliasA`, which is not FFI-safe
LL | pub fn lint_me() -> <AliasB as TraitB>::Assoc;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
+ = note: opaque types have no C equivalent
note: the lint level is defined here
--> $DIR/lint-ctypes-73251-2.rs:2:9
|
LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
- = note: opaque types have no C equivalent
error: aborting due to previous error
diff --git a/src/test/ui/lint/lint-ctypes-enum.stderr b/src/test/ui/lint/lint-ctypes-enum.stderr
index de532f69a..8554e2617 100644
--- a/src/test/ui/lint/lint-ctypes-enum.stderr
+++ b/src/test/ui/lint/lint-ctypes-enum.stderr
@@ -4,11 +4,6 @@ error: `extern` block uses type `U`, which is not FFI-safe
LL | fn uf(x: U);
| ^ not FFI-safe
|
-note: the lint level is defined here
- --> $DIR/lint-ctypes-enum.rs:3:9
- |
-LL | #![deny(improper_ctypes)]
- | ^^^^^^^^^^^^^^^
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
= note: enum has no representation hint
note: the type is defined here
@@ -16,6 +11,11 @@ note: the type is defined here
|
LL | enum U {
| ^^^^^^
+note: the lint level is defined here
+ --> $DIR/lint-ctypes-enum.rs:3:9
+ |
+LL | #![deny(improper_ctypes)]
+ | ^^^^^^^^^^^^^^^
error: `extern` block uses type `B`, which is not FFI-safe
--> $DIR/lint-ctypes-enum.rs:61:13
diff --git a/src/test/ui/lint/lint-ctypes-fn.stderr b/src/test/ui/lint/lint-ctypes-fn.stderr
index 6f8d76411..a05206bf1 100644
--- a/src/test/ui/lint/lint-ctypes-fn.stderr
+++ b/src/test/ui/lint/lint-ctypes-fn.stderr
@@ -4,13 +4,13 @@ error: `extern` fn uses type `[u32]`, which is not FFI-safe
LL | pub extern "C" fn slice_type(p: &[u32]) { }
| ^^^^^^ not FFI-safe
|
+ = help: consider using a raw pointer instead
+ = note: slices have no C equivalent
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:76:31
diff --git a/src/test/ui/lint/lint-ctypes.stderr b/src/test/ui/lint/lint-ctypes.stderr
index bfec40e19..121ad0ce8 100644
--- a/src/test/ui/lint/lint-ctypes.stderr
+++ b/src/test/ui/lint/lint-ctypes.stderr
@@ -4,11 +4,6 @@ error: `extern` block uses type `Foo`, which is not FFI-safe
LL | pub fn ptr_type1(size: *const Foo);
| ^^^^^^^^^^ not FFI-safe
|
-note: the lint level is defined here
- --> $DIR/lint-ctypes.rs:4:9
- |
-LL | #![deny(improper_ctypes)]
- | ^^^^^^^^^^^^^^^
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
note: the type is defined here
@@ -16,6 +11,11 @@ note: the type is defined here
|
LL | pub struct Foo;
| ^^^^^^^^^^^^^^
+note: the lint level is defined here
+ --> $DIR/lint-ctypes.rs:4:9
+ |
+LL | #![deny(improper_ctypes)]
+ | ^^^^^^^^^^^^^^^
error: `extern` block uses type `Foo`, which is not FFI-safe
--> $DIR/lint-ctypes.rs:49:28
diff --git a/src/test/ui/lint/lint-enum-intrinsics-non-enums.stderr b/src/test/ui/lint/lint-enum-intrinsics-non-enums.stderr
index bec9fb62e..63ed2503c 100644
--- a/src/test/ui/lint/lint-enum-intrinsics-non-enums.stderr
+++ b/src/test/ui/lint/lint-enum-intrinsics-non-enums.stderr
@@ -4,12 +4,12 @@ error: the return value of `mem::discriminant` is unspecified when called with a
LL | discriminant(&());
| ^^^^^^^^^^^^^^^^^
|
- = note: `#[deny(enum_intrinsics_non_enums)]` on by default
note: the argument to `discriminant` should be a reference to an enum, but it was passed a reference to a `()`, which is not an enum.
--> $DIR/lint-enum-intrinsics-non-enums.rs:26:18
|
LL | discriminant(&());
| ^^^
+ = note: `#[deny(enum_intrinsics_non_enums)]` on by default
error: the return value of `mem::discriminant` is unspecified when called with a non-enum type
--> $DIR/lint-enum-intrinsics-non-enums.rs:29:5
diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr
index d7fd51461..3a84c6c1f 100644
--- a/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr
+++ b/src/test/ui/lint/lint-exceeding-bitshifts.noopt.stderr
@@ -7,7 +7,7 @@ LL | const N: i32 = T::N << 42;
note: the lint level is defined here
--> $DIR/lint-exceeding-bitshifts.rs:10:9
|
-LL | #![warn(arithmetic_overflow, const_err)]
+LL | #![warn(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^
warning: this arithmetic operation will overflow
diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr b/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr
index d7fd51461..3a84c6c1f 100644
--- a/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr
+++ b/src/test/ui/lint/lint-exceeding-bitshifts.opt.stderr
@@ -7,7 +7,7 @@ LL | const N: i32 = T::N << 42;
note: the lint level is defined here
--> $DIR/lint-exceeding-bitshifts.rs:10:9
|
-LL | #![warn(arithmetic_overflow, const_err)]
+LL | #![warn(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^
warning: this arithmetic operation will overflow
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 d7fd51461..3a84c6c1f 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
@@ -7,7 +7,7 @@ LL | const N: i32 = T::N << 42;
note: the lint level is defined here
--> $DIR/lint-exceeding-bitshifts.rs:10:9
|
-LL | #![warn(arithmetic_overflow, const_err)]
+LL | #![warn(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^
warning: this arithmetic operation will overflow
diff --git a/src/test/ui/lint/lint-exceeding-bitshifts.rs b/src/test/ui/lint/lint-exceeding-bitshifts.rs
index d8774cb4d..048c1aff8 100644
--- a/src/test/ui/lint/lint-exceeding-bitshifts.rs
+++ b/src/test/ui/lint/lint-exceeding-bitshifts.rs
@@ -7,7 +7,7 @@
// normalize-stderr-test "shift left by `(64|32)_usize`, which" -> "shift left by `%BITS%`, which"
#![crate_type="lib"]
-#![warn(arithmetic_overflow, const_err)]
+#![warn(arithmetic_overflow)]
pub trait Foo {
diff --git a/src/test/ui/lint/lint-incoherent-auto-trait-objects.stderr b/src/test/ui/lint/lint-incoherent-auto-trait-objects.stderr
index afbab9896..2cc4d382d 100644
--- a/src/test/ui/lint/lint-incoherent-auto-trait-objects.stderr
+++ b/src/test/ui/lint/lint-incoherent-auto-trait-objects.stderr
@@ -7,9 +7,9 @@ LL |
LL | impl Foo for dyn Send + Send {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + 'static)`
|
- = note: `#[deny(order_dependent_trait_objects)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
+ = note: `#[deny(order_dependent_trait_objects)]` on by default
error: conflicting implementations of trait `Foo` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119)
--> $DIR/lint-incoherent-auto-trait-objects.rs:11:1
@@ -37,3 +37,45 @@ LL | impl Foo for dyn Send + Sync + Send {}
error: aborting due to 3 previous errors
+Future incompatibility report: Future breakage diagnostic:
+error: conflicting implementations of trait `Foo` for type `(dyn std::marker::Send + 'static)`: (E0119)
+ --> $DIR/lint-incoherent-auto-trait-objects.rs:5:1
+ |
+LL | impl Foo for dyn Send {}
+ | --------------------- first implementation here
+LL |
+LL | impl Foo for dyn Send + Send {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + 'static)`
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
+ = note: `#[deny(order_dependent_trait_objects)]` on by default
+
+Future breakage diagnostic:
+error: conflicting implementations of trait `Foo` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119)
+ --> $DIR/lint-incoherent-auto-trait-objects.rs:11:1
+ |
+LL | impl Foo for dyn Send + Sync {}
+ | ---------------------------- first implementation here
+LL |
+LL | impl Foo for dyn Sync + Send {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)`
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
+ = note: `#[deny(order_dependent_trait_objects)]` on by default
+
+Future breakage diagnostic:
+error: conflicting implementations of trait `Foo` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119)
+ --> $DIR/lint-incoherent-auto-trait-objects.rs:15:1
+ |
+LL | impl Foo for dyn Sync + Send {}
+ | ---------------------------- first implementation here
+...
+LL | impl Foo for dyn Send + Sync + Send {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)`
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
+ = note: `#[deny(order_dependent_trait_objects)]` on by default
+
diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-bool.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-bool.stderr
index 2a1847b98..9f38dcb0b 100644
--- a/src/test/ui/lint/lint-invalid-atomic-ordering-bool.stderr
+++ b/src/test/ui/lint/lint-invalid-atomic-ordering-bool.stderr
@@ -4,8 +4,8 @@ error: atomic loads cannot have `Release` or `AcqRel` ordering
LL | let _ = x.load(Ordering::Release);
| ^^^^^^^^^^^^^^^^^
|
- = note: `#[deny(invalid_atomic_ordering)]` on by default
= help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`
+ = note: `#[deny(invalid_atomic_ordering)]` on by default
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-bool.rs:15:20
diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.stderr
index 021654cf3..cc075ce9e 100644
--- a/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.stderr
+++ b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.stderr
@@ -4,8 +4,8 @@ error: `compare_exchange_weak`'s failure ordering may not be `Release` or `AcqRe
LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Relaxed, Ordering::AcqRel);
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
- = note: `#[deny(invalid_atomic_ordering)]` on by default
= help: consider using `Acquire` or `Relaxed` failure ordering instead
+ = note: `#[deny(invalid_atomic_ordering)]` on by default
error: `compare_exchange_weak`'s failure ordering may not be `Release` or `AcqRel`, since a failed `compare_exchange_weak` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-exchange-weak.rs:30:67
diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.stderr
index f6f8f88e8..fe6c7e55c 100644
--- a/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.stderr
+++ b/src/test/ui/lint/lint-invalid-atomic-ordering-exchange.stderr
@@ -4,8 +4,8 @@ error: `compare_exchange`'s failure ordering may not be `Release` or `AcqRel`, s
LL | let _ = x.compare_exchange(0, 0, Ordering::Relaxed, Ordering::AcqRel);
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
- = note: `#[deny(invalid_atomic_ordering)]` on by default
= help: consider using `Acquire` or `Relaxed` failure ordering instead
+ = note: `#[deny(invalid_atomic_ordering)]` on by default
error: `compare_exchange`'s failure ordering may not be `Release` or `AcqRel`, since a failed `compare_exchange` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-exchange.rs:28:57
diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-fence.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-fence.stderr
index e0741ffed..38327d607 100644
--- a/src/test/ui/lint/lint-invalid-atomic-ordering-fence.stderr
+++ b/src/test/ui/lint/lint-invalid-atomic-ordering-fence.stderr
@@ -4,8 +4,8 @@ error: memory fences cannot have `Relaxed` ordering
LL | fence(Ordering::Relaxed);
| ^^^^^^^^^^^^^^^^^
|
- = note: `#[deny(invalid_atomic_ordering)]` on by default
= help: consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`
+ = note: `#[deny(invalid_atomic_ordering)]` on by default
error: memory fences cannot have `Relaxed` ordering
--> $DIR/lint-invalid-atomic-ordering-fence.rs:19:20
diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.stderr
index 267b1c706..33829d68f 100644
--- a/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.stderr
+++ b/src/test/ui/lint/lint-invalid-atomic-ordering-fetch-update.stderr
@@ -4,8 +4,8 @@ error: `fetch_update`'s failure ordering may not be `Release` or `AcqRel`, since
LL | let _ = x.fetch_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(old + 1));
| ^^^^^^^^^^^^^^^^ invalid failure ordering
|
- = note: `#[deny(invalid_atomic_ordering)]` on by default
= help: consider using `Acquire` or `Relaxed` failure ordering instead
+ = note: `#[deny(invalid_atomic_ordering)]` on by default
error: `fetch_update`'s failure ordering may not be `Release` or `AcqRel`, since a failed `fetch_update` does not result in a write
--> $DIR/lint-invalid-atomic-ordering-fetch-update.rs:28:47
diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-int.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-int.stderr
index dfd999045..36930e2f4 100644
--- a/src/test/ui/lint/lint-invalid-atomic-ordering-int.stderr
+++ b/src/test/ui/lint/lint-invalid-atomic-ordering-int.stderr
@@ -4,8 +4,8 @@ error: atomic loads cannot have `Release` or `AcqRel` ordering
LL | let _ = x.load(Ordering::Release);
| ^^^^^^^^^^^^^^^^^
|
- = note: `#[deny(invalid_atomic_ordering)]` on by default
= help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`
+ = note: `#[deny(invalid_atomic_ordering)]` on by default
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-int.rs:22:20
diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-ptr.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-ptr.stderr
index f00cb8e40..12f4cad90 100644
--- a/src/test/ui/lint/lint-invalid-atomic-ordering-ptr.stderr
+++ b/src/test/ui/lint/lint-invalid-atomic-ordering-ptr.stderr
@@ -4,8 +4,8 @@ error: atomic loads cannot have `Release` or `AcqRel` ordering
LL | let _ = x.load(Ordering::Release);
| ^^^^^^^^^^^^^^^^^
|
- = note: `#[deny(invalid_atomic_ordering)]` on by default
= help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`
+ = note: `#[deny(invalid_atomic_ordering)]` on by default
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-ptr.rs:17:20
diff --git a/src/test/ui/lint/lint-invalid-atomic-ordering-uint.stderr b/src/test/ui/lint/lint-invalid-atomic-ordering-uint.stderr
index 36672e434..d26621f2a 100644
--- a/src/test/ui/lint/lint-invalid-atomic-ordering-uint.stderr
+++ b/src/test/ui/lint/lint-invalid-atomic-ordering-uint.stderr
@@ -4,8 +4,8 @@ error: atomic loads cannot have `Release` or `AcqRel` ordering
LL | let _ = x.load(Ordering::Release);
| ^^^^^^^^^^^^^^^^^
|
- = note: `#[deny(invalid_atomic_ordering)]` on by default
= help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`
+ = note: `#[deny(invalid_atomic_ordering)]` on by default
error: atomic loads cannot have `Release` or `AcqRel` ordering
--> $DIR/lint-invalid-atomic-ordering-uint.rs:21:20
diff --git a/src/test/ui/lint/lint-non-snake-case-crate-2.stderr b/src/test/ui/lint/lint-non-snake-case-crate-2.stderr
index e29511293..4b42145bb 100644
--- a/src/test/ui/lint/lint-non-snake-case-crate-2.stderr
+++ b/src/test/ui/lint/lint-non-snake-case-crate-2.stderr
@@ -1,11 +1,11 @@
error: crate `NonSnakeCase` should have a snake case name
|
+ = help: convert the identifier to snake case: `non_snake_case`
note: the lint level is defined here
--> $DIR/lint-non-snake-case-crate-2.rs:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
- = help: convert the identifier to snake case: `non_snake_case`
error: aborting due to previous error
diff --git a/src/test/ui/lint/lint-output-format.rs b/src/test/ui/lint/lint-output-format.rs
index 169a98c94..67e8ec8f1 100644
--- a/src/test/ui/lint/lint-output-format.rs
+++ b/src/test/ui/lint/lint-output-format.rs
@@ -5,6 +5,7 @@
extern crate lint_output_format; //~ ERROR use of unstable library feature
use lint_output_format::{foo, bar}; //~ ERROR use of unstable library feature
+//~| ERROR use of unstable library feature
fn main() {
let _x = foo();
diff --git a/src/test/ui/lint/lint-output-format.stderr b/src/test/ui/lint/lint-output-format.stderr
index 3bc1d6fc1..0db79a156 100644
--- a/src/test/ui/lint/lint-output-format.stderr
+++ b/src/test/ui/lint/lint-output-format.stderr
@@ -7,6 +7,14 @@ LL | extern crate lint_output_format;
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
error[E0658]: use of unstable library feature 'unstable_test_feature'
+ --> $DIR/lint-output-format.rs:7:26
+ |
+LL | use lint_output_format::{foo, bar};
+ | ^^^
+ |
+ = help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
+
+error[E0658]: use of unstable library feature 'unstable_test_feature'
--> $DIR/lint-output-format.rs:7:31
|
LL | use lint_output_format::{foo, bar};
@@ -15,13 +23,13 @@ LL | use lint_output_format::{foo, bar};
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
error[E0658]: use of unstable library feature 'unstable_test_feature'
- --> $DIR/lint-output-format.rs:11:14
+ --> $DIR/lint-output-format.rs:12:14
|
LL | let _y = bar();
| ^^^
|
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/lint/lint-pre-expansion-extern-module.stderr b/src/test/ui/lint/lint-pre-expansion-extern-module.stderr
index 3355bb4e4..ce3e8806a 100644
--- a/src/test/ui/lint/lint-pre-expansion-extern-module.stderr
+++ b/src/test/ui/lint/lint-pre-expansion-extern-module.stderr
@@ -4,9 +4,9 @@ warning: `try` is a keyword in the 2018 edition
LL | pub fn try() {}
| ^^^ help: you can use a raw identifier to stay compatible: `r#try`
|
- = note: `-W keyword-idents` implied by `-W rust-2018-compatibility`
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
+ = note: `-W keyword-idents` implied by `-W rust-2018-compatibility`
warning: 1 warning emitted
diff --git a/src/test/ui/lint/lint-stability-deprecated.rs b/src/test/ui/lint/lint-stability-deprecated.rs
index bdc66e830..74c35083e 100644
--- a/src/test/ui/lint/lint-stability-deprecated.rs
+++ b/src/test/ui/lint/lint-stability-deprecated.rs
@@ -130,7 +130,7 @@ mod cross_crate {
let _ = UnstableTupleStruct (1);
let _ = StableTupleStruct (1);
- // At the moment, the lint checker only checks stability in
+ // At the moment, the lint checker only checks stability
// in the arguments of macros.
// Eventually, we will want to lint the contents of the
// macro in the module *defining* it. Also, stability levels
diff --git a/src/test/ui/lint/lint-strict-provenance-fuzzy-casts.stderr b/src/test/ui/lint/lint-strict-provenance-fuzzy-casts.stderr
index c85934aa3..383623b48 100644
--- a/src/test/ui/lint/lint-strict-provenance-fuzzy-casts.stderr
+++ b/src/test/ui/lint/lint-strict-provenance-fuzzy-casts.stderr
@@ -4,12 +4,12 @@ error: strict provenance disallows casting integer `usize` to pointer `*const u8
LL | let dangling = 16_usize as *const u8;
| ^^^^^^^^^^^^^^^^^^^^^
|
+ = help: if you can't comply with strict provenance and don't have a pointer with the correct provenance you can use `std::ptr::from_exposed_addr()` instead
note: the lint level is defined here
--> $DIR/lint-strict-provenance-fuzzy-casts.rs:2:9
|
LL | #![deny(fuzzy_provenance_casts)]
| ^^^^^^^^^^^^^^^^^^^^^^
- = help: if you can't comply with strict provenance and don't have a pointer with the correct provenance you can use `std::ptr::from_exposed_addr()` instead
help: use `.with_addr()` to adjust a valid pointer in the same allocation, to this address
|
LL | let dangling = (...).with_addr(16_usize);
diff --git a/src/test/ui/lint/lint-strict-provenance-lossy-casts.stderr b/src/test/ui/lint/lint-strict-provenance-lossy-casts.stderr
index 05178b34b..aa151fe2d 100644
--- a/src/test/ui/lint/lint-strict-provenance-lossy-casts.stderr
+++ b/src/test/ui/lint/lint-strict-provenance-lossy-casts.stderr
@@ -4,12 +4,12 @@ error: under strict provenance it is considered bad style to cast pointer `*cons
LL | let addr: usize = &x as *const u8 as usize;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
+ = help: if you can't comply with strict provenance and need to expose the pointer provenance you can use `.expose_addr()` instead
note: the lint level is defined here
--> $DIR/lint-strict-provenance-lossy-casts.rs:2:9
|
LL | #![deny(lossy_provenance_casts)]
| ^^^^^^^^^^^^^^^^^^^^^^
- = help: if you can't comply with strict provenance and need to expose the pointer provenance you can use `.expose_addr()` instead
help: use `.addr()` to obtain the address of a pointer
|
LL | let addr: usize = (&x as *const u8).addr();
diff --git a/src/test/ui/lint/lint-temporary-cstring-as-param.stderr b/src/test/ui/lint/lint-temporary-cstring-as-param.stderr
index 0a9e5a4bf..838b3bc13 100644
--- a/src/test/ui/lint/lint-temporary-cstring-as-param.stderr
+++ b/src/test/ui/lint/lint-temporary-cstring-as-param.stderr
@@ -6,13 +6,13 @@ LL | some_function(CString::new("").unwrap().as_ptr());
| |
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
+ = note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
+ = help: for more information, see https://doc.rust-lang.org/reference/destructors.html
note: the lint level is defined here
--> $DIR/lint-temporary-cstring-as-param.rs:1:9
|
LL | #![deny(temporary_cstring_as_ptr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
- = note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
- = help: for more information, see https://doc.rust-lang.org/reference/destructors.html
error: aborting due to previous error
diff --git a/src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr b/src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr
index e69d2dd53..79ef57dd1 100644
--- a/src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr
+++ b/src/test/ui/lint/lint-temporary-cstring-as-ptr.stderr
@@ -6,13 +6,13 @@ LL | let s = CString::new("some text").unwrap().as_ptr();
| |
| this `CString` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
|
+ = note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
+ = help: for more information, see https://doc.rust-lang.org/reference/destructors.html
note: the lint level is defined here
--> $DIR/lint-temporary-cstring-as-ptr.rs:2:9
|
LL | #![deny(temporary_cstring_as_ptr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
- = note: pointers do not have a lifetime; when calling `as_ptr` the `CString` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
- = help: for more information, see https://doc.rust-lang.org/reference/destructors.html
error: aborting due to previous error
diff --git a/src/test/ui/lint/lint-type-limits2.stderr b/src/test/ui/lint/lint-type-limits2.stderr
index 3562cb440..b3420ad8a 100644
--- a/src/test/ui/lint/lint-type-limits2.stderr
+++ b/src/test/ui/lint/lint-type-limits2.stderr
@@ -12,13 +12,13 @@ warning: literal out of range for `i8`
LL | 128 > bar()
| ^^^
|
+ = note: the literal `128` does not fit into the type `i8` whose range is `-128..=127`
+ = help: consider using the type `u8` instead
note: the lint level is defined here
--> $DIR/lint-type-limits2.rs:2:9
|
LL | #![warn(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
- = note: the literal `128` does not fit into the type `i8` whose range is `-128..=127`
- = help: consider using the type `u8` instead
error: aborting due to previous error; 1 warning emitted
diff --git a/src/test/ui/lint/lint-type-limits3.stderr b/src/test/ui/lint/lint-type-limits3.stderr
index 823d1a4c7..db46e7ae7 100644
--- a/src/test/ui/lint/lint-type-limits3.stderr
+++ b/src/test/ui/lint/lint-type-limits3.stderr
@@ -12,13 +12,13 @@ warning: literal out of range for `i8`
LL | while 200 != i {
| ^^^
|
+ = note: the literal `200` does not fit into the type `i8` whose range is `-128..=127`
+ = help: consider using the type `u8` instead
note: the lint level is defined here
--> $DIR/lint-type-limits3.rs:2:9
|
LL | #![warn(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
- = note: the literal `200` does not fit into the type `i8` whose range is `-128..=127`
- = help: consider using the type `u8` instead
error: aborting due to previous error; 1 warning emitted
diff --git a/src/test/ui/lint/lint-type-overflow.stderr b/src/test/ui/lint/lint-type-overflow.stderr
index 1bb1ec547..48d8228b8 100644
--- a/src/test/ui/lint/lint-type-overflow.stderr
+++ b/src/test/ui/lint/lint-type-overflow.stderr
@@ -4,12 +4,12 @@ error: literal out of range for `u8`
LL | let x1: u8 = 256;
| ^^^
|
+ = note: the literal `256` does not fit into the type `u8` whose range is `0..=255`
note: the lint level is defined here
--> $DIR/lint-type-overflow.rs:1:9
|
LL | #![deny(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
- = note: the literal `256` does not fit into the type `u8` whose range is `0..=255`
error: literal out of range for `u8`
--> $DIR/lint-type-overflow.rs:13:14
diff --git a/src/test/ui/lint/lint-type-overflow2.rs b/src/test/ui/lint/lint-type-overflow2.rs
index c1f874c07..9b1eb510b 100644
--- a/src/test/ui/lint/lint-type-overflow2.rs
+++ b/src/test/ui/lint/lint-type-overflow2.rs
@@ -1,7 +1,6 @@
// compile-flags: -O
#![deny(overflowing_literals)]
-#![deny(const_err)]
fn main() {
let x2: i8 = --128; //~ ERROR literal out of range for `i8`
diff --git a/src/test/ui/lint/lint-type-overflow2.stderr b/src/test/ui/lint/lint-type-overflow2.stderr
index 3d40cdf96..eb593d062 100644
--- a/src/test/ui/lint/lint-type-overflow2.stderr
+++ b/src/test/ui/lint/lint-type-overflow2.stderr
@@ -1,19 +1,19 @@
error: literal out of range for `i8`
- --> $DIR/lint-type-overflow2.rs:7:20
+ --> $DIR/lint-type-overflow2.rs:6:20
|
LL | let x2: i8 = --128;
| ^^^
|
+ = note: the literal `128` does not fit into the type `i8` whose range is `-128..=127`
+ = help: consider using the type `u8` instead
note: the lint level is defined here
--> $DIR/lint-type-overflow2.rs:3:9
|
LL | #![deny(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
- = note: the literal `128` does not fit into the type `i8` whose range is `-128..=127`
- = help: consider using the type `u8` instead
error: literal out of range for `f32`
- --> $DIR/lint-type-overflow2.rs:9:14
+ --> $DIR/lint-type-overflow2.rs:8:14
|
LL | let x = -3.40282357e+38_f32;
| ^^^^^^^^^^^^^^^^^^
@@ -21,7 +21,7 @@ LL | let x = -3.40282357e+38_f32;
= note: the literal `3.40282357e+38_f32` does not fit into the type `f32` and will be converted to `f32::INFINITY`
error: literal out of range for `f32`
- --> $DIR/lint-type-overflow2.rs:10:14
+ --> $DIR/lint-type-overflow2.rs:9:14
|
LL | let x = 3.40282357e+38_f32;
| ^^^^^^^^^^^^^^^^^^
@@ -29,7 +29,7 @@ LL | let x = 3.40282357e+38_f32;
= note: the literal `3.40282357e+38_f32` does not fit into the type `f32` and will be converted to `f32::INFINITY`
error: literal out of range for `f64`
- --> $DIR/lint-type-overflow2.rs:11:14
+ --> $DIR/lint-type-overflow2.rs:10:14
|
LL | let x = -1.7976931348623159e+308_f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -37,7 +37,7 @@ LL | let x = -1.7976931348623159e+308_f64;
= note: the literal `1.7976931348623159e+308_f64` does not fit into the type `f64` and will be converted to `f64::INFINITY`
error: literal out of range for `f64`
- --> $DIR/lint-type-overflow2.rs:12:14
+ --> $DIR/lint-type-overflow2.rs:11:14
|
LL | let x = 1.7976931348623159e+308_f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/test/ui/lint/lint-unconditional-recursion.stderr b/src/test/ui/lint/lint-unconditional-recursion.stderr
index c11b73f41..9d200a789 100644
--- a/src/test/ui/lint/lint-unconditional-recursion.stderr
+++ b/src/test/ui/lint/lint-unconditional-recursion.stderr
@@ -6,12 +6,12 @@ LL | fn foo() {
LL | foo();
| ----- recursive call site
|
+ = help: a `loop` may express intention better if this is on purpose
note: the lint level is defined here
--> $DIR/lint-unconditional-recursion.rs:1:9
|
LL | #![deny(unconditional_recursion)]
| ^^^^^^^^^^^^^^^^^^^^^^^
- = help: a `loop` may express intention better if this is on purpose
error: function cannot return without recursing
--> $DIR/lint-unconditional-recursion.rs:14:1
diff --git a/src/test/ui/lint/lint-unsafe-code.stderr b/src/test/ui/lint/lint-unsafe-code.stderr
index 8dde05fc4..037f0a832 100644
--- a/src/test/ui/lint/lint-unsafe-code.stderr
+++ b/src/test/ui/lint/lint-unsafe-code.stderr
@@ -4,12 +4,12 @@ error: declaration of a `no_mangle` function
LL | #[no_mangle] fn foo() {}
| ^^^^^^^^^^^^
|
+ = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
note: the lint level is defined here
--> $DIR/lint-unsafe-code.rs:3:9
|
LL | #![deny(unsafe_code)]
| ^^^^^^^^^^^
- = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
error: declaration of a `no_mangle` static
--> $DIR/lint-unsafe-code.rs:32:1
diff --git a/src/test/ui/lint/must_not_suspend/boxed.stderr b/src/test/ui/lint/must_not_suspend/boxed.stderr
index b3c9b4381..9efc7b069 100644
--- a/src/test/ui/lint/must_not_suspend/boxed.stderr
+++ b/src/test/ui/lint/must_not_suspend/boxed.stderr
@@ -6,11 +6,6 @@ LL | let _guard = bar();
LL | other().await;
| ------ the value is held across this suspend point
|
-note: the lint level is defined here
- --> $DIR/boxed.rs:3:9
- |
-LL | #![deny(must_not_suspend)]
- | ^^^^^^^^^^^^^^^^
note: You gotta use Umm's, ya know?
--> $DIR/boxed.rs:20:9
|
@@ -21,6 +16,11 @@ help: consider using a block (`{ ... }`) to shrink the value's scope, ending bef
|
LL | let _guard = bar();
| ^^^^^^
+note: the lint level is defined here
+ --> $DIR/boxed.rs:3:9
+ |
+LL | #![deny(must_not_suspend)]
+ | ^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/lint/must_not_suspend/dedup.stderr b/src/test/ui/lint/must_not_suspend/dedup.stderr
index 13fa3ae30..f8978ba57 100644
--- a/src/test/ui/lint/must_not_suspend/dedup.stderr
+++ b/src/test/ui/lint/must_not_suspend/dedup.stderr
@@ -4,16 +4,16 @@ error: `No` held across a suspend point, but should not be
LL | wheeee(&No {}).await;
| ^^^^^ ------ the value is held across this suspend point
|
-note: the lint level is defined here
- --> $DIR/dedup.rs:3:9
- |
-LL | #![deny(must_not_suspend)]
- | ^^^^^^^^^^^^^^^^
help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
--> $DIR/dedup.rs:16:13
|
LL | wheeee(&No {}).await;
| ^^^^^
+note: the lint level is defined here
+ --> $DIR/dedup.rs:3:9
+ |
+LL | #![deny(must_not_suspend)]
+ | ^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/lint/must_not_suspend/gated.stderr b/src/test/ui/lint/must_not_suspend/gated.stderr
index b58ecb555..64de1ebea 100644
--- a/src/test/ui/lint/must_not_suspend/gated.stderr
+++ b/src/test/ui/lint/must_not_suspend/gated.stderr
@@ -4,10 +4,10 @@ warning: unknown lint: `must_not_suspend`
LL | #![deny(must_not_suspend)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unknown_lints)]` on by default
= note: the `must_not_suspend` lint is unstable
= note: see issue #83310 <https://github.com/rust-lang/rust/issues/83310> for more information
= help: add `#![feature(must_not_suspend)]` to the crate attributes to enable
+ = note: `#[warn(unknown_lints)]` on by default
warning: unknown lint: `must_not_suspend`
--> $DIR/gated.rs:4:1
diff --git a/src/test/ui/lint/must_not_suspend/mutex.stderr b/src/test/ui/lint/must_not_suspend/mutex.stderr
index a968b7ca0..c251cb845 100644
--- a/src/test/ui/lint/must_not_suspend/mutex.stderr
+++ b/src/test/ui/lint/must_not_suspend/mutex.stderr
@@ -6,11 +6,6 @@ LL | let _guard = m.lock().unwrap();
LL | other().await;
| ------ the value is held across this suspend point
|
-note: the lint level is defined here
- --> $DIR/mutex.rs:3:9
- |
-LL | #![deny(must_not_suspend)]
- | ^^^^^^^^^^^^^^^^
note: holding a MutexGuard across suspend points can cause deadlocks, delays, and cause Futures to not implement `Send`
--> $DIR/mutex.rs:8:9
|
@@ -21,6 +16,11 @@ help: consider using a block (`{ ... }`) to shrink the value's scope, ending bef
|
LL | let _guard = m.lock().unwrap();
| ^^^^^^
+note: the lint level is defined here
+ --> $DIR/mutex.rs:3:9
+ |
+LL | #![deny(must_not_suspend)]
+ | ^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/lint/must_not_suspend/ref-drop-tracking.stderr b/src/test/ui/lint/must_not_suspend/ref-drop-tracking.stderr
index c49d27128..180e187c1 100644
--- a/src/test/ui/lint/must_not_suspend/ref-drop-tracking.stderr
+++ b/src/test/ui/lint/must_not_suspend/ref-drop-tracking.stderr
@@ -7,11 +7,6 @@ LL |
LL | other().await;
| ------ the value is held across this suspend point
|
-note: the lint level is defined here
- --> $DIR/ref-drop-tracking.rs:4:9
- |
-LL | #![deny(must_not_suspend)]
- | ^^^^^^^^^^^^^^^^
note: You gotta use Umm's, ya know?
--> $DIR/ref-drop-tracking.rs:19:13
|
@@ -22,6 +17,11 @@ help: consider using a block (`{ ... }`) to shrink the value's scope, ending bef
|
LL | let guard = &mut self.u;
| ^^^^^
+note: the lint level is defined here
+ --> $DIR/ref-drop-tracking.rs:4:9
+ |
+LL | #![deny(must_not_suspend)]
+ | ^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/lint/must_not_suspend/ref.drop_tracking.stderr b/src/test/ui/lint/must_not_suspend/ref.drop_tracking.stderr
index 0157c8b7f..abf76711b 100644
--- a/src/test/ui/lint/must_not_suspend/ref.drop_tracking.stderr
+++ b/src/test/ui/lint/must_not_suspend/ref.drop_tracking.stderr
@@ -7,11 +7,6 @@ LL |
LL | other().await;
| ------ the value is held across this suspend point
|
-note: the lint level is defined here
- --> $DIR/ref.rs:6:9
- |
-LL | #![deny(must_not_suspend)]
- | ^^^^^^^^^^^^^^^^
note: You gotta use Umm's, ya know?
--> $DIR/ref.rs:21:13
|
@@ -22,6 +17,11 @@ help: consider using a block (`{ ... }`) to shrink the value's scope, ending bef
|
LL | let guard = &mut self.u;
| ^^^^^
+note: the lint level is defined here
+ --> $DIR/ref.rs:6:9
+ |
+LL | #![deny(must_not_suspend)]
+ | ^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/lint/must_not_suspend/ref.no_drop_tracking.stderr b/src/test/ui/lint/must_not_suspend/ref.no_drop_tracking.stderr
index 438e6489e..41ac09ea7 100644
--- a/src/test/ui/lint/must_not_suspend/ref.no_drop_tracking.stderr
+++ b/src/test/ui/lint/must_not_suspend/ref.no_drop_tracking.stderr
@@ -7,11 +7,6 @@ LL |
LL | other().await;
| ------ the value is held across this suspend point
|
-note: the lint level is defined here
- --> $DIR/ref.rs:6:9
- |
-LL | #![deny(must_not_suspend)]
- | ^^^^^^^^^^^^^^^^
note: You gotta use Umm's, ya know?
--> $DIR/ref.rs:21:26
|
@@ -22,6 +17,11 @@ help: consider using a block (`{ ... }`) to shrink the value's scope, ending bef
|
LL | let guard = &mut self.u;
| ^^^^^^
+note: the lint level is defined here
+ --> $DIR/ref.rs:6:9
+ |
+LL | #![deny(must_not_suspend)]
+ | ^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/lint/must_not_suspend/trait.stderr b/src/test/ui/lint/must_not_suspend/trait.stderr
index 60369430a..d64d25aae 100644
--- a/src/test/ui/lint/must_not_suspend/trait.stderr
+++ b/src/test/ui/lint/must_not_suspend/trait.stderr
@@ -7,16 +7,16 @@ LL | let _guard1 = r#impl();
LL | other().await;
| ------ the value is held across this suspend point
|
-note: the lint level is defined here
- --> $DIR/trait.rs:3:9
- |
-LL | #![deny(must_not_suspend)]
- | ^^^^^^^^^^^^^^^^
help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
--> $DIR/trait.rs:21:9
|
LL | let _guard1 = r#impl();
| ^^^^^^^
+note: the lint level is defined here
+ --> $DIR/trait.rs:3:9
+ |
+LL | #![deny(must_not_suspend)]
+ | ^^^^^^^^^^^^^^^^
error: boxed `Wow` trait object held across a suspend point, but should not be
--> $DIR/trait.rs:22:9
diff --git a/src/test/ui/lint/must_not_suspend/unit.stderr b/src/test/ui/lint/must_not_suspend/unit.stderr
index 42d037b35..c967dbac5 100644
--- a/src/test/ui/lint/must_not_suspend/unit.stderr
+++ b/src/test/ui/lint/must_not_suspend/unit.stderr
@@ -6,11 +6,6 @@ LL | let _guard = bar();
LL | other().await;
| ------ the value is held across this suspend point
|
-note: the lint level is defined here
- --> $DIR/unit.rs:3:9
- |
-LL | #![deny(must_not_suspend)]
- | ^^^^^^^^^^^^^^^^
note: You gotta use Umm's, ya know?
--> $DIR/unit.rs:20:9
|
@@ -21,6 +16,11 @@ help: consider using a block (`{ ... }`) to shrink the value's scope, ending bef
|
LL | let _guard = bar();
| ^^^^^^
+note: the lint level is defined here
+ --> $DIR/unit.rs:3:9
+ |
+LL | #![deny(must_not_suspend)]
+ | ^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/lint/must_not_suspend/warn.stderr b/src/test/ui/lint/must_not_suspend/warn.stderr
index 417c397da..fe551c652 100644
--- a/src/test/ui/lint/must_not_suspend/warn.stderr
+++ b/src/test/ui/lint/must_not_suspend/warn.stderr
@@ -6,11 +6,6 @@ LL | let _guard = bar();
LL | other().await;
| ------ the value is held across this suspend point
|
-note: the lint level is defined here
- --> $DIR/warn.rs:4:9
- |
-LL | #![warn(must_not_suspend)]
- | ^^^^^^^^^^^^^^^^
note: You gotta use Umm's, ya know?
--> $DIR/warn.rs:21:9
|
@@ -21,6 +16,11 @@ help: consider using a block (`{ ... }`) to shrink the value's scope, ending bef
|
LL | let _guard = bar();
| ^^^^^^
+note: the lint level is defined here
+ --> $DIR/warn.rs:4:9
+ |
+LL | #![warn(must_not_suspend)]
+ | ^^^^^^^^^^^^^^^^
warning: 1 warning emitted
diff --git a/src/test/ui/lint/no-coverage.stderr b/src/test/ui/lint/no-coverage.stderr
index 8452ccc7a..404efbeac 100644
--- a/src/test/ui/lint/no-coverage.stderr
+++ b/src/test/ui/lint/no-coverage.stderr
@@ -94,7 +94,7 @@ error: unconstrained opaque type
LL | type U = impl Trait;
| ^^^^^^^^^^
|
- = note: `U` must be used in combination with a concrete type within the same module
+ = note: `U` must be used in combination with a concrete type within the same impl
error: aborting due to 7 previous errors; 6 warnings emitted
diff --git a/src/test/ui/lint/noop-method-call.rs b/src/test/ui/lint/noop-method-call.rs
index 9870c8135..89b296635 100644
--- a/src/test/ui/lint/noop-method-call.rs
+++ b/src/test/ui/lint/noop-method-call.rs
@@ -46,6 +46,7 @@ fn main() {
fn generic<T>(non_clone_type: &PlainType<T>) {
non_clone_type.clone();
+ //~^ WARNING call to `.clone()` on a reference in this situation does nothing
}
fn non_generic(non_clone_type: &PlainType<u32>) {
diff --git a/src/test/ui/lint/noop-method-call.stderr b/src/test/ui/lint/noop-method-call.stderr
index 7f6f96bf1..6a904d01a 100644
--- a/src/test/ui/lint/noop-method-call.stderr
+++ b/src/test/ui/lint/noop-method-call.stderr
@@ -4,12 +4,12 @@ warning: call to `.clone()` on a reference in this situation does nothing
LL | let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone();
| ^^^^^^^^ unnecessary method call
|
+ = note: the type `&PlainType<u32>` which `clone` is being called on is the same as the type returned from `clone`, so the method call does not do anything and can be removed
note: the lint level is defined here
--> $DIR/noop-method-call.rs:4:9
|
LL | #![warn(noop_method_call)]
| ^^^^^^^^^^^^^^^^
- = note: the type `&PlainType<u32>` which `clone` is being called on is the same as the type returned from `clone`, so the method call does not do anything and can be removed
warning: call to `.deref()` on a reference in this situation does nothing
--> $DIR/noop-method-call.rs:28:63
@@ -28,12 +28,20 @@ LL | let non_borrow_type_borrow: &PlainType<u32> = non_borrow_type.borrow();
= note: the type `&PlainType<u32>` which `borrow` is being called on is the same as the type returned from `borrow`, so the method call does not do anything and can be removed
warning: call to `.clone()` on a reference in this situation does nothing
- --> $DIR/noop-method-call.rs:52:19
+ --> $DIR/noop-method-call.rs:48:19
+ |
+LL | non_clone_type.clone();
+ | ^^^^^^^^ unnecessary method call
+ |
+ = note: the type `&PlainType<T>` which `clone` is being called on is the same as the type returned from `clone`, so the method call does not do anything and can be removed
+
+warning: call to `.clone()` on a reference in this situation does nothing
+ --> $DIR/noop-method-call.rs:53:19
|
LL | non_clone_type.clone();
| ^^^^^^^^ unnecessary method call
|
= note: the type `&PlainType<u32>` which `clone` is being called on is the same as the type returned from `clone`, so the method call does not do anything and can be removed
-warning: 4 warnings emitted
+warning: 5 warnings emitted
diff --git a/src/test/ui/lint/opaque-ty-ffi-unsafe.stderr b/src/test/ui/lint/opaque-ty-ffi-unsafe.stderr
index 62d00fd68..33aa95854 100644
--- a/src/test/ui/lint/opaque-ty-ffi-unsafe.stderr
+++ b/src/test/ui/lint/opaque-ty-ffi-unsafe.stderr
@@ -4,12 +4,12 @@ error: `extern` block uses type `A`, which is not FFI-safe
LL | pub fn a(_: A);
| ^ not FFI-safe
|
+ = note: opaque types have no C equivalent
note: the lint level is defined here
--> $DIR/opaque-ty-ffi-unsafe.rs:2:9
|
LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
- = note: opaque types have no C equivalent
error: aborting due to previous error
diff --git a/src/test/ui/lint/outer-forbid.stderr b/src/test/ui/lint/outer-forbid.stderr
index 781457321..a47877980 100644
--- a/src/test/ui/lint/outer-forbid.stderr
+++ b/src/test/ui/lint/outer-forbid.stderr
@@ -7,13 +7,13 @@ LL | #![forbid(unused, non_snake_case)]
LL | #[allow(unused_variables)]
| ^^^^^^^^^^^^^^^^ overruled by previous forbid
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
note: the lint level is defined here
--> $DIR/outer-forbid.rs:18:11
|
LL | #![forbid(forbidden_lint_groups)]
| ^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #81670 <https://github.com/rust-lang/rust/issues/81670>
error: allow(unused) incompatible with previous forbid
--> $DIR/outer-forbid.rs:25:9
diff --git a/src/test/ui/lint/redundant-semicolon/redundant-semi-proc-macro.stderr b/src/test/ui/lint/redundant-semicolon/redundant-semi-proc-macro.stderr
index bc0c53303..e31d14c55 100644
--- a/src/test/ui/lint/redundant-semicolon/redundant-semi-proc-macro.stderr
+++ b/src/test/ui/lint/redundant-semicolon/redundant-semi-proc-macro.stderr
@@ -1,4 +1,4 @@
-TokenStream [Ident { ident: "fn", span: #0 bytes(198..200) }, Ident { ident: "span_preservation", span: #0 bytes(201..218) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(218..220) }, Group { delimiter: Brace, stream: TokenStream [Ident { ident: "let", span: #0 bytes(228..231) }, Ident { ident: "tst", span: #0 bytes(232..235) }, Punct { ch: '=', spacing: Alone, span: #0 bytes(236..237) }, Literal { kind: Integer, symbol: "123", suffix: None, span: #0 bytes(238..241) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(241..242) }, Punct { ch: ';', spacing: Alone, span: #0 bytes(242..243) }, Ident { ident: "match", span: #0 bytes(289..294) }, Ident { ident: "tst", span: #0 bytes(295..298) }, Group { delimiter: Brace, stream: TokenStream [Literal { kind: Integer, symbol: "123", suffix: None, span: #0 bytes(483..486) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(487..489) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(487..489) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(490..492) }, Punct { ch: ',', spacing: Alone, span: #0 bytes(492..493) }, Ident { ident: "_", span: #0 bytes(502..503) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(504..506) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(504..506) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(507..509) }], span: #0 bytes(299..515) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(515..516) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(516..517) }, Punct { ch: ';', spacing: Alone, span: #0 bytes(517..518) }], span: #0 bytes(222..562) }]
+TokenStream [Ident { ident: "fn", span: #0 bytes(198..200) }, Ident { ident: "span_preservation", span: #0 bytes(201..218) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(218..220) }, Group { delimiter: Brace, stream: TokenStream [Ident { ident: "let", span: #0 bytes(228..231) }, Ident { ident: "tst", span: #0 bytes(232..235) }, Punct { ch: '=', spacing: Alone, span: #0 bytes(236..237) }, Literal { kind: Integer, symbol: "123", suffix: None, span: #0 bytes(238..241) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(241..242) }, Punct { ch: ';', spacing: Alone, span: #0 bytes(242..243) }, Ident { ident: "match", span: #0 bytes(289..294) }, Ident { ident: "tst", span: #0 bytes(295..298) }, Group { delimiter: Brace, stream: TokenStream [Literal { kind: Integer, symbol: "123", suffix: None, span: #0 bytes(483..486) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(487..488) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(488..489) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(490..492) }, Punct { ch: ',', spacing: Alone, span: #0 bytes(492..493) }, Ident { ident: "_", span: #0 bytes(502..503) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(504..505) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(505..506) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(507..509) }], span: #0 bytes(299..515) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(515..516) }, Punct { ch: ';', spacing: Joint, span: #0 bytes(516..517) }, Punct { ch: ';', spacing: Alone, span: #0 bytes(517..518) }], span: #0 bytes(222..562) }]
error: unnecessary trailing semicolon
--> $DIR/redundant-semi-proc-macro.rs:9:19
|
diff --git a/src/test/ui/lint/rfc-2383-lint-reason/expect_nested_lint_levels.stderr b/src/test/ui/lint/rfc-2383-lint-reason/expect_nested_lint_levels.stderr
index 370e51bf7..2c35647b8 100644
--- a/src/test/ui/lint/rfc-2383-lint-reason/expect_nested_lint_levels.stderr
+++ b/src/test/ui/lint/rfc-2383-lint-reason/expect_nested_lint_levels.stderr
@@ -31,8 +31,8 @@ warning: this lint expectation is unfulfilled
LL | unused_mut,
| ^^^^^^^^^^
|
- = note: `#[warn(unfulfilled_lint_expectations)]` on by default
= note: this `expect` is overridden by a `allow` attribute before the `unused_mut` lint is triggered
+ = note: `#[warn(unfulfilled_lint_expectations)]` on by default
warning: this lint expectation is unfulfilled
--> $DIR/expect_nested_lint_levels.rs:24:5
diff --git a/src/test/ui/lint/rfc-2383-lint-reason/expect_unfulfilled_expectation.stderr b/src/test/ui/lint/rfc-2383-lint-reason/expect_unfulfilled_expectation.stderr
index 9bfee79b0..9a1c3e442 100644
--- a/src/test/ui/lint/rfc-2383-lint-reason/expect_unfulfilled_expectation.stderr
+++ b/src/test/ui/lint/rfc-2383-lint-reason/expect_unfulfilled_expectation.stderr
@@ -4,9 +4,9 @@ warning: this lint expectation is unfulfilled
LL | #![expect(unfulfilled_lint_expectations, reason = "idk why you would expect this")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unfulfilled_lint_expectations)]` on by default
= note: idk why you would expect this
= note: the `unfulfilled_lint_expectations` lint can't be expected and will always produce this message
+ = note: `#[warn(unfulfilled_lint_expectations)]` on by default
warning: this lint expectation is unfulfilled
--> $DIR/expect_unfulfilled_expectation.rs:13:10
diff --git a/src/test/ui/lint/rfc-2383-lint-reason/expect_with_reason.stderr b/src/test/ui/lint/rfc-2383-lint-reason/expect_with_reason.stderr
index 82c1a4c08..e349e4081 100644
--- a/src/test/ui/lint/rfc-2383-lint-reason/expect_with_reason.stderr
+++ b/src/test/ui/lint/rfc-2383-lint-reason/expect_with_reason.stderr
@@ -4,8 +4,8 @@ warning: this lint expectation is unfulfilled
LL | #![expect(unused_variables, reason = "<This should fail and display this reason>")]
| ^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unfulfilled_lint_expectations)]` on by default
= note: <This should fail and display this reason>
+ = note: `#[warn(unfulfilled_lint_expectations)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr b/src/test/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr
index 06befcbb5..5942fa8ae 100644
--- a/src/test/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr
+++ b/src/test/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr
@@ -1,11 +1,3 @@
-warning: denote infinite loops with `loop { ... }`
- --> $DIR/force_warn_expected_lints_fulfilled.rs:10:5
- |
-LL | while true {
- | ^^^^^^^^^^ help: use `loop`
- |
- = note: requested on the command line with `--force-warn while-true`
-
warning: unused variable: `x`
--> $DIR/force_warn_expected_lints_fulfilled.rs:20:9
|
@@ -36,5 +28,13 @@ LL | let mut what_does_the_fox_say = "*ding* *deng* *dung*";
|
= note: requested on the command line with `--force-warn unused-mut`
+warning: denote infinite loops with `loop { ... }`
+ --> $DIR/force_warn_expected_lints_fulfilled.rs:10:5
+ |
+LL | while true {
+ | ^^^^^^^^^^ help: use `loop`
+ |
+ = note: requested on the command line with `--force-warn while-true`
+
warning: 5 warnings emitted
diff --git a/src/test/ui/lint/rfc-2383-lint-reason/lint-attribute-only-with-reason.stderr b/src/test/ui/lint/rfc-2383-lint-reason/lint-attribute-only-with-reason.stderr
index 3bf8137dc..3e9d70821 100644
--- a/src/test/ui/lint/rfc-2383-lint-reason/lint-attribute-only-with-reason.stderr
+++ b/src/test/ui/lint/rfc-2383-lint-reason/lint-attribute-only-with-reason.stderr
@@ -4,12 +4,12 @@ error: unused attribute
LL | #[allow(reason = "I want to allow something")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
|
+ = note: attribute `allow` without any lints has no effect
note: the lint level is defined here
--> $DIR/lint-attribute-only-with-reason.rs:3:9
|
LL | #![deny(unused_attributes)]
| ^^^^^^^^^^^^^^^^^
- = note: attribute `allow` without any lints has no effect
error: unused attribute
--> $DIR/lint-attribute-only-with-reason.rs:6:1
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
index 9ca034b71..884a4a453 100644
--- 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
@@ -4,13 +4,13 @@ error: the usage of Script Group `Greek` in this crate consists solely of mixed
LL | struct ΑctuallyNotLatin;
| ^^^^^^^^^^^^^^^^
|
+ = note: the usage includes 'Α' (U+0391)
+ = note: please recheck to make sure their usages are indeed what you want
note: the lint level is defined here
--> $DIR/lint-mixed-script-confusables.rs:1: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:10:5
diff --git a/src/test/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.stderr b/src/test/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.stderr
index 84ad32bdd..49608c205 100644
--- a/src/test/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.stderr
+++ b/src/test/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.stderr
@@ -7,15 +7,15 @@ LL | true;
LL | foo!(warn_in_block)
| ------------------- in this macro invocation
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
+ = note: macro invocations at the end of a block are treated as expressions
+ = note: to ignore the value produced by the macro, add a semicolon after the invocation of `foo`
note: the lint level is defined here
--> $DIR/semicolon-in-expressions-from-macros.rs:4:9
|
LL | #![warn(semicolon_in_expressions_from_macros)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
- = note: macro invocations at the end of a block are treated as expressions
- = note: to ignore the value produced by the macro, add a semicolon after the invocation of `foo`
= note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: trailing semicolon in macro used in expression position
diff --git a/src/test/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr b/src/test/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr
index d770a8c8f..16c152eb2 100644
--- a/src/test/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr
+++ b/src/test/ui/lint/semicolon-in-expressions-from-macros/warn-semicolon-in-expressions-from-macros.stderr
@@ -7,9 +7,9 @@ LL | true;
LL | _ => foo!()
| ------ in this macro invocation
|
- = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
+ = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
= note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: 1 warning emitted
diff --git a/src/test/ui/lint/trivial-cast-ice.rs b/src/test/ui/lint/trivial-cast-ice.rs
new file mode 100644
index 000000000..f781fab22
--- /dev/null
+++ b/src/test/ui/lint/trivial-cast-ice.rs
@@ -0,0 +1,12 @@
+// aux-build:trivial-cast-ice.rs
+// check-pass
+
+// Demonstrates the ICE in #102561
+
+#![deny(trivial_casts)]
+
+extern crate trivial_cast_ice;
+
+fn main() {
+ trivial_cast_ice::foo!();
+}
diff --git a/src/test/ui/lint/trivial-casts-featuring-type-ascription.stderr b/src/test/ui/lint/trivial-casts-featuring-type-ascription.stderr
index f7c42acb3..5087807b6 100644
--- a/src/test/ui/lint/trivial-casts-featuring-type-ascription.stderr
+++ b/src/test/ui/lint/trivial-casts-featuring-type-ascription.stderr
@@ -4,12 +4,12 @@ error: trivial numeric cast: `i32` as `i32`
LL | let lugubrious = 12i32 as i32;
| ^^^^^^^^^^^^
|
+ = help: cast can be replaced by coercion; this might require type ascription or a temporary variable
note: the lint level is defined here
--> $DIR/trivial-casts-featuring-type-ascription.rs:1:24
|
LL | #![deny(trivial_casts, trivial_numeric_casts)]
| ^^^^^^^^^^^^^^^^^^^^^
- = help: cast can be replaced by coercion; this might require type ascription or a temporary variable
error: trivial cast: `&u32` as `*const u32`
--> $DIR/trivial-casts-featuring-type-ascription.rs:8:13
@@ -17,12 +17,12 @@ error: trivial cast: `&u32` as `*const u32`
LL | let _ = haunted as *const u32;
| ^^^^^^^^^^^^^^^^^^^^^
|
+ = help: cast can be replaced by coercion; this might require type ascription or a temporary variable
note: the lint level is defined here
--> $DIR/trivial-casts-featuring-type-ascription.rs:1:9
|
LL | #![deny(trivial_casts, trivial_numeric_casts)]
| ^^^^^^^^^^^^^
- = help: cast can be replaced by coercion; this might require type ascription or a temporary variable
error: aborting due to 2 previous errors
diff --git a/src/test/ui/lint/trivial-casts.stderr b/src/test/ui/lint/trivial-casts.stderr
index 1544f553c..7ace353de 100644
--- a/src/test/ui/lint/trivial-casts.stderr
+++ b/src/test/ui/lint/trivial-casts.stderr
@@ -4,12 +4,12 @@ error: trivial numeric cast: `i32` as `i32`
LL | let lugubrious = 12i32 as i32;
| ^^^^^^^^^^^^
|
+ = help: cast can be replaced by coercion; this might require a temporary variable
note: the lint level is defined here
--> $DIR/trivial-casts.rs:1:24
|
LL | #![deny(trivial_casts, trivial_numeric_casts)]
| ^^^^^^^^^^^^^^^^^^^^^
- = help: cast can be replaced by coercion; this might require a temporary variable
error: trivial cast: `&u32` as `*const u32`
--> $DIR/trivial-casts.rs:7:13
@@ -17,12 +17,12 @@ error: trivial cast: `&u32` as `*const u32`
LL | let _ = haunted as *const u32;
| ^^^^^^^^^^^^^^^^^^^^^
|
+ = help: cast can be replaced by coercion; this might require a temporary variable
note: the lint level is defined here
--> $DIR/trivial-casts.rs:1:9
|
LL | #![deny(trivial_casts, trivial_numeric_casts)]
| ^^^^^^^^^^^^^
- = help: cast can be replaced by coercion; this might require a temporary variable
error: aborting due to 2 previous errors
diff --git a/src/test/ui/lint/trivial_casts.stderr b/src/test/ui/lint/trivial_casts.stderr
index 8a216360f..74f962835 100644
--- a/src/test/ui/lint/trivial_casts.stderr
+++ b/src/test/ui/lint/trivial_casts.stderr
@@ -4,12 +4,12 @@ error: trivial numeric cast: `i32` as `i32`
LL | let _ = 42_i32 as i32;
| ^^^^^^^^^^^^^
|
+ = help: cast can be replaced by coercion; this might require a temporary variable
note: the lint level is defined here
--> $DIR/trivial_casts.rs:4:24
|
LL | #![deny(trivial_casts, trivial_numeric_casts)]
| ^^^^^^^^^^^^^^^^^^^^^
- = help: cast can be replaced by coercion; this might require a temporary variable
error: trivial numeric cast: `u8` as `u8`
--> $DIR/trivial_casts.rs:19:13
@@ -25,12 +25,12 @@ error: trivial cast: `&u32` as `*const u32`
LL | let _ = x as *const u32;
| ^^^^^^^^^^^^^^^
|
+ = help: cast can be replaced by coercion; this might require a temporary variable
note: the lint level is defined here
--> $DIR/trivial_casts.rs:4:9
|
LL | #![deny(trivial_casts, trivial_numeric_casts)]
| ^^^^^^^^^^^^^
- = help: cast can be replaced by coercion; this might require a temporary variable
error: trivial cast: `&mut u32` as `*mut u32`
--> $DIR/trivial_casts.rs:28:13
diff --git a/src/test/ui/lint/type-overflow.stderr b/src/test/ui/lint/type-overflow.stderr
index 8a31fd447..62cb1f7f4 100644
--- a/src/test/ui/lint/type-overflow.stderr
+++ b/src/test/ui/lint/type-overflow.stderr
@@ -4,13 +4,13 @@ warning: literal out of range for `i8`
LL | let error = 255i8;
| ^^^^^
|
+ = note: the literal `255i8` does not fit into the type `i8` whose range is `-128..=127`
+ = help: consider using the type `u8` instead
note: the lint level is defined here
--> $DIR/type-overflow.rs:2:9
|
LL | #![warn(overflowing_literals)]
| ^^^^^^^^^^^^^^^^^^^^
- = note: the literal `255i8` does not fit into the type `i8` whose range is `-128..=127`
- = help: consider using the type `u8` instead
warning: literal out of range for `i8`
--> $DIR/type-overflow.rs:10:16
diff --git a/src/test/ui/lint/unaligned_references.stderr b/src/test/ui/lint/unaligned_references.stderr
index 97dbec286..346f49b92 100644
--- a/src/test/ui/lint/unaligned_references.stderr
+++ b/src/test/ui/lint/unaligned_references.stderr
@@ -4,15 +4,15 @@ error: reference to packed field is unaligned
LL | let _ = &good.ptr;
| ^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/unaligned_references.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
error: reference to packed field is unaligned
--> $DIR/unaligned_references.rs:24:17
@@ -111,15 +111,15 @@ error: reference to packed field is unaligned
LL | let _ = &good.ptr;
| ^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/unaligned_references.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -128,15 +128,15 @@ error: reference to packed field is unaligned
LL | let _ = &good.data;
| ^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/unaligned_references.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -145,15 +145,15 @@ error: reference to packed field is unaligned
LL | let _ = &good.data as *const _;
| ^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/unaligned_references.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -162,15 +162,15 @@ error: reference to packed field is unaligned
LL | let _: *const _ = &good.data;
| ^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/unaligned_references.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -179,15 +179,15 @@ error: reference to packed field is unaligned
LL | let _ = good.data.clone();
| ^^^^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/unaligned_references.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -196,15 +196,15 @@ error: reference to packed field is unaligned
LL | let _ = &good.data2[0];
| ^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/unaligned_references.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -213,15 +213,15 @@ error: reference to packed field is unaligned
LL | let _ = &packed2.x;
| ^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/unaligned_references.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -230,15 +230,15 @@ error: reference to packed field is unaligned
LL | let _ref = &m1.1.a;
| ^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/unaligned_references.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -247,13 +247,13 @@ error: reference to packed field is unaligned
LL | let _ref = &m2.1.a;
| ^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/unaligned_references.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
diff --git a/src/test/ui/lint/unaligned_references_external_macro.stderr b/src/test/ui/lint/unaligned_references_external_macro.stderr
index 1262c21ee..c46ca6742 100644
--- a/src/test/ui/lint/unaligned_references_external_macro.stderr
+++ b/src/test/ui/lint/unaligned_references_external_macro.stderr
@@ -10,6 +10,10 @@ LL | | }
LL | | }
| |_^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/unaligned_references_external_macro.rs:5:1
|
@@ -21,10 +25,6 @@ LL | | pub field: u16
LL | | }
LL | | }
| |_^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
= note: this error originates in the macro `unaligned_references_external_crate::mac` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
@@ -42,6 +42,10 @@ LL | | }
LL | | }
| |_^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/unaligned_references_external_macro.rs:5:1
|
@@ -53,9 +57,5 @@ LL | | pub field: u16
LL | | }
LL | | }
| |_^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
= note: this error originates in the macro `unaligned_references_external_crate::mac` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/src/test/ui/lint/unreachable_pub.stderr b/src/test/ui/lint/unreachable_pub.stderr
index e021f500c..762834b97 100644
--- a/src/test/ui/lint/unreachable_pub.stderr
+++ b/src/test/ui/lint/unreachable_pub.stderr
@@ -6,12 +6,12 @@ LL | pub use std::fmt;
| |
| help: consider restricting its visibility: `pub(crate)`
|
+ = help: or consider exporting it for use by other crates
note: the lint level is defined here
--> $DIR/unreachable_pub.rs:4:9
|
LL | #![warn(unreachable_pub)]
| ^^^^^^^^^^^^^^^
- = help: or consider exporting it for use by other crates
warning: unreachable `pub` item
--> $DIR/unreachable_pub.rs:9:24
diff --git a/src/test/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.stderr b/src/test/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.stderr
index 26fa6eb9b..fe2e3afc8 100644
--- a/src/test/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.stderr
+++ b/src/test/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.stderr
@@ -49,8 +49,8 @@ warning: value assigned to `hours_are_suns` is never read
LL | hours_are_suns = false;
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]`
= help: maybe it is overwritten before being read?
+ = note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]`
warning: unused variable: `fire`
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:52:32
diff --git a/src/test/ui/lint/unused/must-use-box-from-raw.stderr b/src/test/ui/lint/unused/must-use-box-from-raw.stderr
index 7769f09aa..011acc3bf 100644
--- a/src/test/ui/lint/unused/must-use-box-from-raw.stderr
+++ b/src/test/ui/lint/unused/must-use-box-from-raw.stderr
@@ -4,12 +4,12 @@ warning: unused return value of `Box::<T>::from_raw` that must be used
LL | Box::from_raw(ptr);
| ^^^^^^^^^^^^^^^^^^^
|
+ = note: call `drop(from_raw(ptr))` if you intend to drop the `Box`
note: the lint level is defined here
--> $DIR/must-use-box-from-raw.rs:5:9
|
LL | #![warn(unused_must_use)]
| ^^^^^^^^^^^^^^^
- = note: call `drop(from_raw(ptr))` if you intend to drop the `Box`
warning: 1 warning emitted
diff --git a/src/test/ui/lint/unused/must_use-in-stdlib-traits.stderr b/src/test/ui/lint/unused/must_use-in-stdlib-traits.stderr
index 76978d29d..f5199f43c 100644
--- a/src/test/ui/lint/unused/must_use-in-stdlib-traits.stderr
+++ b/src/test/ui/lint/unused/must_use-in-stdlib-traits.stderr
@@ -4,12 +4,12 @@ error: unused implementer of `Iterator` that must be used
LL | iterator();
| ^^^^^^^^^^^
|
+ = note: iterators are lazy and do nothing unless consumed
note: the lint level is defined here
--> $DIR/must_use-in-stdlib-traits.rs:1:9
|
LL | #![deny(unused_must_use)]
| ^^^^^^^^^^^^^^^
- = note: iterators are lazy and do nothing unless consumed
error: unused implementer of `Future` that must be used
--> $DIR/must_use-in-stdlib-traits.rs:43:4
diff --git a/src/test/ui/lint/unused/must_use-tuple.stderr b/src/test/ui/lint/unused/must_use-tuple.stderr
index e5709a5f0..63e0318fb 100644
--- a/src/test/ui/lint/unused/must_use-tuple.stderr
+++ b/src/test/ui/lint/unused/must_use-tuple.stderr
@@ -4,12 +4,12 @@ error: unused `Result` in tuple element 0 that must be used
LL | (Ok::<(), ()>(()),);
| ^^^^^^^^^^^^^^^^
|
+ = note: this `Result` may be an `Err` variant, which should be handled
note: the lint level is defined here
--> $DIR/must_use-tuple.rs:1:9
|
LL | #![deny(unused_must_use)]
| ^^^^^^^^^^^^^^^
- = note: this `Result` may be an `Err` variant, which should be handled
error: unused `Result` in tuple element 0 that must be used
--> $DIR/must_use-tuple.rs:10:6
diff --git a/src/test/ui/lint/unused/unused-attr-duplicate.stderr b/src/test/ui/lint/unused/unused-attr-duplicate.stderr
index f592323b5..769b17487 100644
--- a/src/test/ui/lint/unused/unused-attr-duplicate.stderr
+++ b/src/test/ui/lint/unused/unused-attr-duplicate.stderr
@@ -4,16 +4,16 @@ error: unused attribute
LL | #[no_link]
| ^^^^^^^^^^ help: remove this attribute
|
-note: the lint level is defined here
- --> $DIR/unused-attr-duplicate.rs:12:9
- |
-LL | #![deny(unused_attributes)]
- | ^^^^^^^^^^^^^^^^^
note: attribute also specified here
--> $DIR/unused-attr-duplicate.rs:32:1
|
LL | #[no_link]
| ^^^^^^^^^^
+note: the lint level is defined here
+ --> $DIR/unused-attr-duplicate.rs:12:9
+ |
+LL | #![deny(unused_attributes)]
+ | ^^^^^^^^^^^^^^^^^
error: unused attribute
--> $DIR/unused-attr-duplicate.rs:37:1
diff --git a/src/test/ui/lint/unused/unused-closure.stderr b/src/test/ui/lint/unused/unused-closure.stderr
index 265d3e8e0..4362abd20 100644
--- a/src/test/ui/lint/unused/unused-closure.stderr
+++ b/src/test/ui/lint/unused/unused-closure.stderr
@@ -6,12 +6,12 @@ LL | | println!("Hello!");
LL | | };
| |______^
|
+ = note: closures are lazy and do nothing unless called
note: the lint level is defined here
--> $DIR/unused-closure.rs:6:9
|
LL | #![deny(unused_must_use)]
| ^^^^^^^^^^^^^^^
- = note: closures are lazy and do nothing unless called
error: unused implementer of `Future` that must be used
--> $DIR/unused-closure.rs:13:5
diff --git a/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr b/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr
index 1a022c309..078b780d8 100644
--- a/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr
+++ b/src/test/ui/lint/unused/unused-doc-comments-edge-cases.stderr
@@ -23,12 +23,12 @@ LL |
LL | _ => false,
| ---------- rustdoc does not generate documentation for match arms
|
+ = help: use `//` for a plain comment
note: the lint level is defined here
--> $DIR/unused-doc-comments-edge-cases.rs:1:9
|
LL | #![deny(unused_doc_comments)]
| ^^^^^^^^^^^^^^^^^^^
- = help: use `//` for a plain comment
error: unused doc comment
--> $DIR/unused-doc-comments-edge-cases.rs:23:5
diff --git a/src/test/ui/lint/unused/unused-doc-comments-for-macros.stderr b/src/test/ui/lint/unused/unused-doc-comments-for-macros.stderr
index f4f5bb71e..26b1c2b05 100644
--- a/src/test/ui/lint/unused/unused-doc-comments-for-macros.stderr
+++ b/src/test/ui/lint/unused/unused-doc-comments-for-macros.stderr
@@ -8,12 +8,12 @@ LL | | /// line3
| |
| rustdoc does not generate documentation for macro invocations
|
+ = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion
note: the lint level is defined here
--> $DIR/unused-doc-comments-for-macros.rs:1:9
|
LL | #![deny(unused_doc_comments)]
| ^^^^^^^^^^^^^^^^^^^
- = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion
error: unused doc comment
--> $DIR/unused-doc-comments-for-macros.rs:13:5
diff --git a/src/test/ui/lint/unused/unused-supertrait.rs b/src/test/ui/lint/unused/unused-supertrait.rs
new file mode 100644
index 000000000..64a8e5204
--- /dev/null
+++ b/src/test/ui/lint/unused/unused-supertrait.rs
@@ -0,0 +1,11 @@
+#![deny(unused_must_use)]
+
+fn it() -> impl ExactSizeIterator<Item = ()> {
+ let x: Box<dyn ExactSizeIterator<Item = ()>> = todo!();
+ x
+}
+
+fn main() {
+ it();
+ //~^ ERROR unused implementer of `Iterator` that must be used
+}
diff --git a/src/test/ui/lint/unused/unused-supertrait.stderr b/src/test/ui/lint/unused/unused-supertrait.stderr
new file mode 100644
index 000000000..d2f8c0078
--- /dev/null
+++ b/src/test/ui/lint/unused/unused-supertrait.stderr
@@ -0,0 +1,15 @@
+error: unused implementer of `Iterator` that must be used
+ --> $DIR/unused-supertrait.rs:9:5
+ |
+LL | it();
+ | ^^^^^
+ |
+ = note: iterators are lazy and do nothing unless consumed
+note: the lint level is defined here
+ --> $DIR/unused-supertrait.rs:1:9
+ |
+LL | #![deny(unused_must_use)]
+ | ^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/lint/unused/unused_attributes-must_use.stderr b/src/test/ui/lint/unused/unused_attributes-must_use.stderr
index dd112c23e..ce959ddbc 100644
--- a/src/test/ui/lint/unused/unused_attributes-must_use.stderr
+++ b/src/test/ui/lint/unused/unused_attributes-must_use.stderr
@@ -4,16 +4,16 @@ error: unused attribute `must_use`
LL | #[must_use]
| ^^^^^^^^^^^
|
-note: the lint level is defined here
- --> $DIR/unused_attributes-must_use.rs:2:9
- |
-LL | #![deny(unused_attributes, unused_must_use)]
- | ^^^^^^^^^^^^^^^^^
note: the built-in attribute `must_use` will be ignored, since it's applied to the macro invocation `global_asm`
--> $DIR/unused_attributes-must_use.rs:59:1
|
LL | global_asm!("");
| ^^^^^^^^^^
+note: the lint level is defined here
+ --> $DIR/unused_attributes-must_use.rs:2:9
+ |
+LL | #![deny(unused_attributes, unused_must_use)]
+ | ^^^^^^^^^^^^^^^^^
error: `#[must_use]` has no effect when applied to an extern crate
--> $DIR/unused_attributes-must_use.rs:5:1
diff --git a/src/test/ui/lint/unused/useless-comment.stderr b/src/test/ui/lint/unused/useless-comment.stderr
index 0054426fb..8bb5bdaeb 100644
--- a/src/test/ui/lint/unused/useless-comment.stderr
+++ b/src/test/ui/lint/unused/useless-comment.stderr
@@ -4,12 +4,12 @@ error: unused doc comment
LL | /// foo
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macro invocations
|
+ = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion
note: the lint level is defined here
--> $DIR/useless-comment.rs:3:9
|
LL | #![deny(unused_doc_comments)]
| ^^^^^^^^^^^^^^^^^^^
- = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion
error: unused doc comment
--> $DIR/useless-comment.rs:32:5
diff --git a/src/test/ui/liveness/liveness-asm.stderr b/src/test/ui/liveness/liveness-asm.stderr
index d052aca33..57d89e44d 100644
--- a/src/test/ui/liveness/liveness-asm.stderr
+++ b/src/test/ui/liveness/liveness-asm.stderr
@@ -4,12 +4,12 @@ warning: value assigned to `src` is never read
LL | asm!("/*{0}*/", inout(reg) src);
| ^^^
|
+ = help: maybe it is overwritten before being read?
note: the lint level is defined here
--> $DIR/liveness-asm.rs:7:9
|
LL | #![warn(unused_assignments)]
| ^^^^^^^^^^^^^^^^^^
- = help: maybe it is overwritten before being read?
warning: value assigned to `src` is never read
--> $DIR/liveness-asm.rs:24:39
diff --git a/src/test/ui/liveness/liveness-consts.stderr b/src/test/ui/liveness/liveness-consts.stderr
index 16209d16c..6199ea96c 100644
--- a/src/test/ui/liveness/liveness-consts.stderr
+++ b/src/test/ui/liveness/liveness-consts.stderr
@@ -4,13 +4,13 @@ warning: variable `a` is assigned to, but never used
LL | let mut a = 0;
| ^
|
+ = note: consider using `_a` instead
note: the lint level is defined here
--> $DIR/liveness-consts.rs:2:9
|
LL | #![warn(unused)]
| ^^^^^^
= note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
- = note: consider using `_a` instead
warning: value assigned to `b` is never read
--> $DIR/liveness-consts.rs:17:5
@@ -18,8 +18,8 @@ warning: value assigned to `b` is never read
LL | b += 1;
| ^
|
- = note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]`
= help: maybe it is overwritten before being read?
+ = note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]`
warning: unused variable: `e`
--> $DIR/liveness-consts.rs:24:13
diff --git a/src/test/ui/liveness/liveness-dead.stderr b/src/test/ui/liveness/liveness-dead.stderr
index 12680ab11..de6d5bd99 100644
--- a/src/test/ui/liveness/liveness-dead.stderr
+++ b/src/test/ui/liveness/liveness-dead.stderr
@@ -4,12 +4,12 @@ error: value assigned to `x` is never read
LL | let mut x: isize = 3;
| ^
|
+ = help: maybe it is overwritten before being read?
note: the lint level is defined here
--> $DIR/liveness-dead.rs:2:9
|
LL | #![deny(unused_assignments)]
| ^^^^^^^^^^^^^^^^^^
- = help: maybe it is overwritten before being read?
error: value assigned to `x` is never read
--> $DIR/liveness-dead.rs:17:5
diff --git a/src/test/ui/liveness/liveness-return-last-stmt-semi.rs b/src/test/ui/liveness/liveness-return-last-stmt-semi.rs
index e8909c4a5..dff859429 100644
--- a/src/test/ui/liveness/liveness-return-last-stmt-semi.rs
+++ b/src/test/ui/liveness/liveness-return-last-stmt-semi.rs
@@ -1,4 +1,3 @@
-//
// regression test for #8005
macro_rules! test { () => { fn foo() -> i32 { 1; } } }
diff --git a/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr b/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr
index 82d136bd3..de0843aa6 100644
--- a/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr
+++ b/src/test/ui/liveness/liveness-return-last-stmt-semi.stderr
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
- --> $DIR/liveness-return-last-stmt-semi.rs:7:19
+ --> $DIR/liveness-return-last-stmt-semi.rs:6:19
|
LL | fn no_return() -> i32 {}
| --------- ^^^ expected `i32`, found `()`
@@ -7,17 +7,17 @@ LL | fn no_return() -> i32 {}
| implicitly returns `()` as its body has no tail or `return` expression
error[E0308]: mismatched types
- --> $DIR/liveness-return-last-stmt-semi.rs:9:19
+ --> $DIR/liveness-return-last-stmt-semi.rs:8:19
|
LL | fn bar(x: u32) -> u32 {
| --- ^^^ expected `u32`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
LL | x * 2;
- | - help: remove this semicolon
+ | - help: remove this semicolon to return this value
error[E0308]: mismatched types
- --> $DIR/liveness-return-last-stmt-semi.rs:13:19
+ --> $DIR/liveness-return-last-stmt-semi.rs:12:19
|
LL | fn baz(x: u64) -> u32 {
| --- ^^^ expected `u32`, found `()`
@@ -25,7 +25,7 @@ LL | fn baz(x: u64) -> u32 {
| implicitly returns `()` as its body has no tail or `return` expression
error[E0308]: mismatched types
- --> $DIR/liveness-return-last-stmt-semi.rs:4:41
+ --> $DIR/liveness-return-last-stmt-semi.rs:3:41
|
LL | macro_rules! test { () => { fn foo() -> i32 { 1; } } }
| --- ^^^ expected `i32`, found `()`
diff --git a/src/test/ui/liveness/liveness-unused.stderr b/src/test/ui/liveness/liveness-unused.stderr
index 4a6122681..f6c478ddb 100644
--- a/src/test/ui/liveness/liveness-unused.stderr
+++ b/src/test/ui/liveness/liveness-unused.stderr
@@ -57,12 +57,12 @@ error: value assigned to `x` is never read
LL | x += 4;
| ^
|
+ = help: maybe it is overwritten before being read?
note: the lint level is defined here
--> $DIR/liveness-unused.rs:3:9
|
LL | #![deny(unused_assignments)]
| ^^^^^^^^^^^^^^^^^^
- = help: maybe it is overwritten before being read?
error: variable `z` is assigned to, but never used
--> $DIR/liveness-unused.rs:37:13
diff --git a/src/test/ui/liveness/liveness-upvars.stderr b/src/test/ui/liveness/liveness-upvars.stderr
index cb104e0a3..82f62371e 100644
--- a/src/test/ui/liveness/liveness-upvars.stderr
+++ b/src/test/ui/liveness/liveness-upvars.stderr
@@ -4,13 +4,13 @@ warning: value assigned to `last` is never read
LL | last = Some(s);
| ^^^^
|
+ = help: maybe it is overwritten before being read?
note: the lint level is defined here
--> $DIR/liveness-upvars.rs:4:9
|
LL | #![warn(unused)]
| ^^^^^^
= note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]`
- = help: maybe it is overwritten before being read?
warning: unused variable: `last`
--> $DIR/liveness-upvars.rs:10:9
@@ -18,8 +18,8 @@ warning: unused variable: `last`
LL | last = Some(s);
| ^^^^
|
- = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
= help: did you mean to capture by reference instead?
+ = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
warning: unused variable: `sum`
--> $DIR/liveness-upvars.rs:22:9
diff --git a/src/test/ui/loops/loop-proper-liveness.stderr b/src/test/ui/loops/loop-proper-liveness.stderr
index 14e86aee0..f9d94b681 100644
--- a/src/test/ui/loops/loop-proper-liveness.stderr
+++ b/src/test/ui/loops/loop-proper-liveness.stderr
@@ -8,6 +8,10 @@ LL | println!("{:?}", x);
| ^ `x` used here but it isn't initialized
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let x: i32 = 0;
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/macros/format-parse-errors.stderr b/src/test/ui/macros/format-parse-errors.stderr
index 1a7578e60..f9ea4c633 100644
--- a/src/test/ui/macros/format-parse-errors.stderr
+++ b/src/test/ui/macros/format-parse-errors.stderr
@@ -22,7 +22,7 @@ error: positional arguments cannot follow named arguments
--> $DIR/format-parse-errors.rs:10:9
|
LL | foo = foo,
- | --- named argument
+ | --------- named argument
LL | bar,
| ^^^ positional arguments must be before named arguments
diff --git a/src/test/ui/macros/issue-102878.rs b/src/test/ui/macros/issue-102878.rs
new file mode 100644
index 000000000..aac589193
--- /dev/null
+++ b/src/test/ui/macros/issue-102878.rs
@@ -0,0 +1,10 @@
+macro_rules!test{($l:expr,$_:r)=>({const:y y)}
+//~^ ERROR mismatched closing delimiter: `)`
+//~| ERROR invalid fragment specifier `r`
+//~| ERROR expected identifier, found keyword `const`
+//~| ERROR expected identifier, found keyword `const`
+//~| ERROR expected identifier, found `:`
+
+fn s(){test!(1,i)}
+
+fn main() {}
diff --git a/src/test/ui/macros/issue-102878.stderr b/src/test/ui/macros/issue-102878.stderr
new file mode 100644
index 000000000..e0b8855a3
--- /dev/null
+++ b/src/test/ui/macros/issue-102878.stderr
@@ -0,0 +1,60 @@
+error: mismatched closing delimiter: `)`
+ --> $DIR/issue-102878.rs:1:35
+ |
+LL | macro_rules!test{($l:expr,$_:r)=>({const:y y)}
+ | -^ ^ mismatched closing delimiter
+ | ||
+ | |unclosed delimiter
+ | closing delimiter possibly meant for this
+
+error: invalid fragment specifier `r`
+ --> $DIR/issue-102878.rs:1:27
+ |
+LL | macro_rules!test{($l:expr,$_:r)=>({const:y y)}
+ | ^^^^
+ |
+ = help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`
+
+error: expected identifier, found keyword `const`
+ --> $DIR/issue-102878.rs:1:36
+ |
+LL | macro_rules!test{($l:expr,$_:r)=>({const:y y)}
+ | ^^^^^ expected identifier, found keyword
+...
+LL | fn s(){test!(1,i)}
+ | ---------- in this macro invocation
+ |
+ = note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: escape `const` to use it as an identifier
+ |
+LL | macro_rules!test{($l:expr,$_:r)=>({r#const:y y)}
+ | ++
+
+error: expected identifier, found keyword `const`
+ --> $DIR/issue-102878.rs:1:36
+ |
+LL | macro_rules!test{($l:expr,$_:r)=>({const:y y)}
+ | ^^^^^ expected identifier, found keyword
+...
+LL | fn s(){test!(1,i)}
+ | ---------- in this macro invocation
+ |
+ = note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: escape `const` to use it as an identifier
+ |
+LL | macro_rules!test{($l:expr,$_:r)=>({r#const:y y)}
+ | ++
+
+error: expected identifier, found `:`
+ --> $DIR/issue-102878.rs:1:41
+ |
+LL | macro_rules!test{($l:expr,$_:r)=>({const:y y)}
+ | ^ expected identifier
+...
+LL | fn s(){test!(1,i)}
+ | ---------- in this macro invocation
+ |
+ = note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 5 previous errors
+
diff --git a/src/test/ui/macros/issue-39404.stderr b/src/test/ui/macros/issue-39404.stderr
index d2f2a823c..3886a70bb 100644
--- a/src/test/ui/macros/issue-39404.stderr
+++ b/src/test/ui/macros/issue-39404.stderr
@@ -4,9 +4,9 @@ error: missing fragment specifier
LL | macro_rules! m { ($i) => {} }
| ^^
|
- = note: `#[deny(missing_fragment_specifier)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
+ = note: `#[deny(missing_fragment_specifier)]` on by default
error: aborting due to previous error
diff --git a/src/test/ui/macros/issue-84195-lint-anon-const.stderr b/src/test/ui/macros/issue-84195-lint-anon-const.stderr
index 39485d74e..306c08b13 100644
--- a/src/test/ui/macros/issue-84195-lint-anon-const.stderr
+++ b/src/test/ui/macros/issue-84195-lint-anon-const.stderr
@@ -7,13 +7,13 @@ LL | () => { 0; };
LL | let val: [u8; len!()] = [];
| ------ in this macro invocation
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
note: the lint level is defined here
--> $DIR/issue-84195-lint-anon-const.rs:5:9
|
LL | #![deny(semicolon_in_expressions_from_macros)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
= note: this error originates in the macro `len` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
diff --git a/src/test/ui/macros/issue-99265.stderr b/src/test/ui/macros/issue-99265.stderr
index 2bfeedd7d..9185dbff6 100644
--- a/src/test/ui/macros/issue-99265.stderr
+++ b/src/test/ui/macros/issue-99265.stderr
@@ -77,18 +77,18 @@ help: use the named argument by name to avoid ambiguity
LL | println!("Hello {:width$}!", "x", width = 5);
| ~~~~~~
-warning: named argument `width` is not used by name
- --> $DIR/issue-99265.rs:23:46
+warning: named argument `f` is not used by name
+ --> $DIR/issue-99265.rs:23:33
|
LL | println!("Hello {:1$.2$}!", f = 0.02f32, width = 5, precision = 2);
- | -- ^^^^^ this named argument is referred to by position in formatting string
- | |
- | this formatting argument uses named argument `width` by position
+ | -------- ^ this named argument is referred to by position in formatting string
+ | |
+ | this formatting argument uses named argument `f` by position
|
help: use the named argument by name to avoid ambiguity
|
-LL | println!("Hello {:width$.2$}!", f = 0.02f32, width = 5, precision = 2);
- | ~~~~~~
+LL | println!("Hello {f:1$.2$}!", f = 0.02f32, width = 5, precision = 2);
+ | +
warning: named argument `precision` is not used by name
--> $DIR/issue-99265.rs:23:57
@@ -103,31 +103,31 @@ help: use the named argument by name to avoid ambiguity
LL | println!("Hello {:1$.precision$}!", f = 0.02f32, width = 5, precision = 2);
| ~~~~~~~~~~
-warning: named argument `f` is not used by name
- --> $DIR/issue-99265.rs:23:33
+warning: named argument `width` is not used by name
+ --> $DIR/issue-99265.rs:23:46
|
LL | println!("Hello {:1$.2$}!", f = 0.02f32, width = 5, precision = 2);
- | -- ^ this named argument is referred to by position in formatting string
- | |
- | this formatting argument uses named argument `f` by position
+ | -- ^^^^^ this named argument is referred to by position in formatting string
+ | |
+ | this formatting argument uses named argument `width` by position
|
help: use the named argument by name to avoid ambiguity
|
-LL | println!("Hello {f:1$.2$}!", f = 0.02f32, width = 5, precision = 2);
- | +
+LL | println!("Hello {:width$.2$}!", f = 0.02f32, width = 5, precision = 2);
+ | ~~~~~~
-warning: named argument `width` is not used by name
- --> $DIR/issue-99265.rs:31:47
+warning: named argument `f` is not used by name
+ --> $DIR/issue-99265.rs:31:34
|
LL | println!("Hello {0:1$.2$}!", f = 0.02f32, width = 5, precision = 2);
- | -- ^^^^^ this named argument is referred to by position in formatting string
- | |
- | this formatting argument uses named argument `width` by position
+ | --------- ^ this named argument is referred to by position in formatting string
+ | |
+ | this formatting argument uses named argument `f` by position
|
help: use the named argument by name to avoid ambiguity
|
-LL | println!("Hello {0:width$.2$}!", f = 0.02f32, width = 5, precision = 2);
- | ~~~~~~
+LL | println!("Hello {f:1$.2$}!", f = 0.02f32, width = 5, precision = 2);
+ | ~
warning: named argument `precision` is not used by name
--> $DIR/issue-99265.rs:31:58
@@ -142,32 +142,32 @@ help: use the named argument by name to avoid ambiguity
LL | println!("Hello {0:1$.precision$}!", f = 0.02f32, width = 5, precision = 2);
| ~~~~~~~~~~
-warning: named argument `f` is not used by name
- --> $DIR/issue-99265.rs:31:34
+warning: named argument `width` is not used by name
+ --> $DIR/issue-99265.rs:31:47
|
LL | println!("Hello {0:1$.2$}!", f = 0.02f32, width = 5, precision = 2);
- | - ^ this named argument is referred to by position in formatting string
- | |
- | this formatting argument uses named argument `f` by position
+ | -- ^^^^^ this named argument is referred to by position in formatting string
+ | |
+ | this formatting argument uses named argument `width` by position
|
help: use the named argument by name to avoid ambiguity
|
-LL | println!("Hello {f:1$.2$}!", f = 0.02f32, width = 5, precision = 2);
- | ~
+LL | println!("Hello {0:width$.2$}!", f = 0.02f32, width = 5, precision = 2);
+ | ~~~~~~
-warning: named argument `width` is not used by name
- --> $DIR/issue-99265.rs:52:9
+warning: named argument `f` is not used by name
+ --> $DIR/issue-99265.rs:49:9
|
LL | "{}, Hello {1:2$.3$} {4:5$.6$}! {1}",
- | -- this formatting argument uses named argument `width` by position
+ | --------- this formatting argument uses named argument `f` by position
...
-LL | width = 5,
- | ^^^^^ this named argument is referred to by position in formatting string
+LL | f = 0.02f32,
+ | ^ this named argument is referred to by position in formatting string
|
help: use the named argument by name to avoid ambiguity
|
-LL | "{}, Hello {1:width$.3$} {4:5$.6$}! {1}",
- | ~~~~~~
+LL | "{}, Hello {f:2$.3$} {4:5$.6$}! {1}",
+ | ~
warning: named argument `precision` is not used by name
--> $DIR/issue-99265.rs:54:9
@@ -183,33 +183,33 @@ help: use the named argument by name to avoid ambiguity
LL | "{}, Hello {1:2$.precision$} {4:5$.6$}! {1}",
| ~~~~~~~~~~
-warning: named argument `f` is not used by name
- --> $DIR/issue-99265.rs:49:9
+warning: named argument `width` is not used by name
+ --> $DIR/issue-99265.rs:52:9
|
LL | "{}, Hello {1:2$.3$} {4:5$.6$}! {1}",
- | - this formatting argument uses named argument `f` by position
+ | -- this formatting argument uses named argument `width` by position
...
-LL | f = 0.02f32,
- | ^ this named argument is referred to by position in formatting string
+LL | width = 5,
+ | ^^^^^ this named argument is referred to by position in formatting string
|
help: use the named argument by name to avoid ambiguity
|
-LL | "{}, Hello {f:2$.3$} {4:5$.6$}! {1}",
- | ~
+LL | "{}, Hello {1:width$.3$} {4:5$.6$}! {1}",
+ | ~~~~~~
-warning: named argument `width2` is not used by name
- --> $DIR/issue-99265.rs:58:9
+warning: named argument `g` is not used by name
+ --> $DIR/issue-99265.rs:56:9
|
LL | "{}, Hello {1:2$.3$} {4:5$.6$}! {1}",
- | -- this formatting argument uses named argument `width2` by position
+ | --------- this formatting argument uses named argument `g` by position
...
-LL | width2 = 5,
- | ^^^^^^ this named argument is referred to by position in formatting string
+LL | g = 0.02f32,
+ | ^ this named argument is referred to by position in formatting string
|
help: use the named argument by name to avoid ambiguity
|
-LL | "{}, Hello {1:2$.3$} {4:width2$.6$}! {1}",
- | ~~~~~~~
+LL | "{}, Hello {1:2$.3$} {g:5$.6$}! {1}",
+ | ~
warning: named argument `precision2` is not used by name
--> $DIR/issue-99265.rs:60:9
@@ -225,25 +225,25 @@ help: use the named argument by name to avoid ambiguity
LL | "{}, Hello {1:2$.3$} {4:5$.precision2$}! {1}",
| ~~~~~~~~~~~
-warning: named argument `g` is not used by name
- --> $DIR/issue-99265.rs:56:9
+warning: named argument `width2` is not used by name
+ --> $DIR/issue-99265.rs:58:9
|
LL | "{}, Hello {1:2$.3$} {4:5$.6$}! {1}",
- | - this formatting argument uses named argument `g` by position
+ | -- this formatting argument uses named argument `width2` by position
...
-LL | g = 0.02f32,
- | ^ this named argument is referred to by position in formatting string
+LL | width2 = 5,
+ | ^^^^^^ this named argument is referred to by position in formatting string
|
help: use the named argument by name to avoid ambiguity
|
-LL | "{}, Hello {1:2$.3$} {g:5$.6$}! {1}",
- | ~
+LL | "{}, Hello {1:2$.3$} {4:width2$.6$}! {1}",
+ | ~~~~~~~
warning: named argument `f` is not used by name
--> $DIR/issue-99265.rs:49:9
|
LL | "{}, Hello {1:2$.3$} {4:5$.6$}! {1}",
- | - this formatting argument uses named argument `f` by position
+ | --- this formatting argument uses named argument `f` by position
...
LL | f = 0.02f32,
| ^ this named argument is referred to by position in formatting string
@@ -257,7 +257,7 @@ warning: named argument `f` is not used by name
--> $DIR/issue-99265.rs:64:31
|
LL | println!("Hello {:0.1}!", f = 0.02f32);
- | -- ^ this named argument is referred to by position in formatting string
+ | ------ ^ this named argument is referred to by position in formatting string
| |
| this formatting argument uses named argument `f` by position
|
@@ -270,9 +270,9 @@ warning: named argument `f` is not used by name
--> $DIR/issue-99265.rs:68:32
|
LL | println!("Hello {0:0.1}!", f = 0.02f32);
- | - ^ this named argument is referred to by position in formatting string
- | |
- | this formatting argument uses named argument `f` by position
+ | ------- ^ this named argument is referred to by position in formatting string
+ | |
+ | this formatting argument uses named argument `f` by position
|
help: use the named argument by name to avoid ambiguity
|
@@ -283,6 +283,19 @@ warning: named argument `v` is not used by name
--> $DIR/issue-99265.rs:79:23
|
LL | println!("{:0$}", v = val);
+ | ----- ^ this named argument is referred to by position in formatting string
+ | |
+ | this formatting argument uses named argument `v` by position
+ |
+help: use the named argument by name to avoid ambiguity
+ |
+LL | println!("{v:0$}", v = val);
+ | +
+
+warning: named argument `v` is not used by name
+ --> $DIR/issue-99265.rs:79:23
+ |
+LL | println!("{:0$}", v = val);
| -- ^ this named argument is referred to by position in formatting string
| |
| this formatting argument uses named argument `v` by position
@@ -293,17 +306,17 @@ LL | println!("{:v$}", v = val);
| ~~
warning: named argument `v` is not used by name
- --> $DIR/issue-99265.rs:79:23
+ --> $DIR/issue-99265.rs:84:24
|
-LL | println!("{:0$}", v = val);
- | -- ^ this named argument is referred to by position in formatting string
+LL | println!("{0:0$}", v = val);
+ | ------ ^ this named argument is referred to by position in formatting string
| |
| this formatting argument uses named argument `v` by position
|
help: use the named argument by name to avoid ambiguity
|
LL | println!("{v:0$}", v = val);
- | +
+ | ~
warning: named argument `v` is not used by name
--> $DIR/issue-99265.rs:84:24
@@ -319,30 +332,17 @@ LL | println!("{0:v$}", v = val);
| ~~
warning: named argument `v` is not used by name
- --> $DIR/issue-99265.rs:84:24
- |
-LL | println!("{0:0$}", v = val);
- | - ^ this named argument is referred to by position in formatting string
- | |
- | this formatting argument uses named argument `v` by position
- |
-help: use the named argument by name to avoid ambiguity
- |
-LL | println!("{v:0$}", v = val);
- | ~
-
-warning: named argument `v` is not used by name
--> $DIR/issue-99265.rs:89:26
|
LL | println!("{:0$.0$}", v = val);
- | -- ^ this named argument is referred to by position in formatting string
- | |
- | this formatting argument uses named argument `v` by position
+ | -------- ^ this named argument is referred to by position in formatting string
+ | |
+ | this formatting argument uses named argument `v` by position
|
help: use the named argument by name to avoid ambiguity
|
-LL | println!("{:v$.0$}", v = val);
- | ~~
+LL | println!("{v:0$.0$}", v = val);
+ | +
warning: named argument `v` is not used by name
--> $DIR/issue-99265.rs:89:26
@@ -361,27 +361,27 @@ warning: named argument `v` is not used by name
--> $DIR/issue-99265.rs:89:26
|
LL | println!("{:0$.0$}", v = val);
- | -- ^ this named argument is referred to by position in formatting string
- | |
- | this formatting argument uses named argument `v` by position
+ | -- ^ this named argument is referred to by position in formatting string
+ | |
+ | this formatting argument uses named argument `v` by position
|
help: use the named argument by name to avoid ambiguity
|
-LL | println!("{v:0$.0$}", v = val);
- | +
+LL | println!("{:v$.0$}", v = val);
+ | ~~
warning: named argument `v` is not used by name
--> $DIR/issue-99265.rs:96:27
|
LL | println!("{0:0$.0$}", v = val);
- | -- ^ this named argument is referred to by position in formatting string
- | |
- | this formatting argument uses named argument `v` by position
+ | --------- ^ this named argument is referred to by position in formatting string
+ | |
+ | this formatting argument uses named argument `v` by position
|
help: use the named argument by name to avoid ambiguity
|
-LL | println!("{0:v$.0$}", v = val);
- | ~~
+LL | println!("{v:0$.0$}", v = val);
+ | ~
warning: named argument `v` is not used by name
--> $DIR/issue-99265.rs:96:27
@@ -400,14 +400,14 @@ warning: named argument `v` is not used by name
--> $DIR/issue-99265.rs:96:27
|
LL | println!("{0:0$.0$}", v = val);
- | - ^ this named argument is referred to by position in formatting string
- | |
- | this formatting argument uses named argument `v` by position
+ | -- ^ this named argument is referred to by position in formatting string
+ | |
+ | this formatting argument uses named argument `v` by position
|
help: use the named argument by name to avoid ambiguity
|
-LL | println!("{v:0$.0$}", v = val);
- | ~
+LL | println!("{0:v$.0$}", v = val);
+ | ~~
warning: named argument `a` is not used by name
--> $DIR/issue-99265.rs:104:28
@@ -426,28 +426,28 @@ warning: named argument `a` is not used by name
--> $DIR/issue-99265.rs:104:28
|
LL | println!("{} {a} {0}", a = 1);
- | - ^ this named argument is referred to by position in formatting string
- | |
- | this formatting argument uses named argument `a` by position
+ | --- ^ this named argument is referred to by position in formatting string
+ | |
+ | this formatting argument uses named argument `a` by position
|
help: use the named argument by name to avoid ambiguity
|
LL | println!("{} {a} {a}", a = 1);
| ~
-warning: named argument `b` is not used by name
- --> $DIR/issue-99265.rs:115:23
+warning: named argument `a` is not used by name
+ --> $DIR/issue-99265.rs:115:14
|
LL | {:1$.2$}",
- | -- this formatting argument uses named argument `b` by position
+ | -------- this formatting argument uses named argument `a` by position
...
LL | a = 1.0, b = 1, c = 2,
- | ^ this named argument is referred to by position in formatting string
+ | ^ this named argument is referred to by position in formatting string
|
help: use the named argument by name to avoid ambiguity
|
-LL | {:b$.2$}",
- | ~~
+LL | {a:1$.2$}",
+ | +
warning: named argument `c` is not used by name
--> $DIR/issue-99265.rs:115:30
@@ -463,33 +463,33 @@ help: use the named argument by name to avoid ambiguity
LL | {:1$.c$}",
| ~~
-warning: named argument `a` is not used by name
- --> $DIR/issue-99265.rs:115:14
+warning: named argument `b` is not used by name
+ --> $DIR/issue-99265.rs:115:23
|
LL | {:1$.2$}",
- | -- this formatting argument uses named argument `a` by position
+ | -- this formatting argument uses named argument `b` by position
...
LL | a = 1.0, b = 1, c = 2,
- | ^ this named argument is referred to by position in formatting string
+ | ^ this named argument is referred to by position in formatting string
|
help: use the named argument by name to avoid ambiguity
|
-LL | {a:1$.2$}",
- | +
+LL | {:b$.2$}",
+ | ~~
-warning: named argument `b` is not used by name
- --> $DIR/issue-99265.rs:126:23
+warning: named argument `a` is not used by name
+ --> $DIR/issue-99265.rs:126:14
|
LL | {0:1$.2$}",
- | -- this formatting argument uses named argument `b` by position
+ | --------- this formatting argument uses named argument `a` by position
...
LL | a = 1.0, b = 1, c = 2,
- | ^ this named argument is referred to by position in formatting string
+ | ^ this named argument is referred to by position in formatting string
|
help: use the named argument by name to avoid ambiguity
|
-LL | {0:b$.2$}",
- | ~~
+LL | {a:1$.2$}",
+ | ~
warning: named argument `c` is not used by name
--> $DIR/issue-99265.rs:126:30
@@ -505,32 +505,32 @@ help: use the named argument by name to avoid ambiguity
LL | {0:1$.c$}",
| ~~
-warning: named argument `a` is not used by name
- --> $DIR/issue-99265.rs:126:14
+warning: named argument `b` is not used by name
+ --> $DIR/issue-99265.rs:126:23
|
LL | {0:1$.2$}",
- | - this formatting argument uses named argument `a` by position
+ | -- this formatting argument uses named argument `b` by position
...
LL | a = 1.0, b = 1, c = 2,
- | ^ this named argument is referred to by position in formatting string
+ | ^ this named argument is referred to by position in formatting string
|
help: use the named argument by name to avoid ambiguity
|
-LL | {a:1$.2$}",
- | ~
+LL | {0:b$.2$}",
+ | ~~
-warning: named argument `width` is not used by name
- --> $DIR/issue-99265.rs:132:39
+warning: named argument `x` is not used by name
+ --> $DIR/issue-99265.rs:132:30
|
LL | println!("{{{:1$.2$}}}", x = 1.0, width = 3, precision = 2);
- | -- ^^^^^ this named argument is referred to by position in formatting string
- | |
- | this formatting argument uses named argument `width` by position
+ | -------- ^ this named argument is referred to by position in formatting string
+ | |
+ | this formatting argument uses named argument `x` by position
|
help: use the named argument by name to avoid ambiguity
|
-LL | println!("{{{:width$.2$}}}", x = 1.0, width = 3, precision = 2);
- | ~~~~~~
+LL | println!("{{{x:1$.2$}}}", x = 1.0, width = 3, precision = 2);
+ | +
warning: named argument `precision` is not used by name
--> $DIR/issue-99265.rs:132:50
@@ -545,18 +545,18 @@ help: use the named argument by name to avoid ambiguity
LL | println!("{{{:1$.precision$}}}", x = 1.0, width = 3, precision = 2);
| ~~~~~~~~~~
-warning: named argument `x` is not used by name
- --> $DIR/issue-99265.rs:132:30
+warning: named argument `width` is not used by name
+ --> $DIR/issue-99265.rs:132:39
|
LL | println!("{{{:1$.2$}}}", x = 1.0, width = 3, precision = 2);
- | -- ^ this named argument is referred to by position in formatting string
- | |
- | this formatting argument uses named argument `x` by position
+ | -- ^^^^^ this named argument is referred to by position in formatting string
+ | |
+ | this formatting argument uses named argument `width` by position
|
help: use the named argument by name to avoid ambiguity
|
-LL | println!("{{{x:1$.2$}}}", x = 1.0, width = 3, precision = 2);
- | +
+LL | println!("{{{:width$.2$}}}", x = 1.0, width = 3, precision = 2);
+ | ~~~~~~
warning: 42 warnings emitted
diff --git a/src/test/ui/macros/issue-99907.stderr b/src/test/ui/macros/issue-99907.stderr
index 4786ce003..eefb28dee 100644
--- a/src/test/ui/macros/issue-99907.stderr
+++ b/src/test/ui/macros/issue-99907.stderr
@@ -2,7 +2,7 @@ warning: named argument `f` is not used by name
--> $DIR/issue-99907.rs:5:30
|
LL | println!("Hello {:.1}!", f = 0.02f32);
- | -- ^ this named argument is referred to by position in formatting string
+ | ----- ^ this named argument is referred to by position in formatting string
| |
| this formatting argument uses named argument `f` by position
|
@@ -16,7 +16,7 @@ warning: named argument `f` is not used by name
--> $DIR/issue-99907.rs:9:31
|
LL | println!("Hello {:1.1}!", f = 0.02f32);
- | -- ^ this named argument is referred to by position in formatting string
+ | ------ ^ this named argument is referred to by position in formatting string
| |
| this formatting argument uses named argument `f` by position
|
diff --git a/src/test/ui/macros/lint-trailing-macro-call.stderr b/src/test/ui/macros/lint-trailing-macro-call.stderr
index a98a559c8..6ab121f7c 100644
--- a/src/test/ui/macros/lint-trailing-macro-call.stderr
+++ b/src/test/ui/macros/lint-trailing-macro-call.stderr
@@ -7,11 +7,11 @@ LL | #[cfg(FALSE)] 25;
LL | expand_it!()
| ------------ in this macro invocation
|
- = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
= note: macro invocations at the end of a block are treated as expressions
= note: to ignore the value produced by the macro, add a semicolon after the invocation of `expand_it`
+ = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
= note: this warning originates in the macro `expand_it` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: 1 warning emitted
diff --git a/src/test/ui/macros/macro-comma-behavior-rpass.rs b/src/test/ui/macros/macro-comma-behavior-rpass.rs
index dfd58b25d..8406b4e78 100644
--- a/src/test/ui/macros/macro-comma-behavior-rpass.rs
+++ b/src/test/ui/macros/macro-comma-behavior-rpass.rs
@@ -14,7 +14,6 @@
// compile-flags: --test -C debug_assertions=yes
// revisions: std core
-// ignore-wasm32-bare compiled with panic=abort by default
#![cfg_attr(core, no_std)]
#[cfg(core)]
diff --git a/src/test/ui/macros/macro-context.stderr b/src/test/ui/macros/macro-context.stderr
index 5dc178070..f597c398b 100644
--- a/src/test/ui/macros/macro-context.stderr
+++ b/src/test/ui/macros/macro-context.stderr
@@ -57,7 +57,7 @@ error[E0425]: cannot find value `i` in this scope
--> $DIR/macro-context.rs:3:13
|
LL | () => ( i ; typeof );
- | ^ help: a local variable with a similar name exists: `a`
+ | ^ not found in this scope
...
LL | let i = m!();
| ---- in this macro invocation
@@ -73,9 +73,9 @@ LL | () => ( i ; typeof );
LL | let i = m!();
| ---- in this macro invocation
|
- = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
+ = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
= note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 6 previous errors; 1 warning emitted
diff --git a/src/test/ui/macros/macro-in-expression-context.stderr b/src/test/ui/macros/macro-in-expression-context.stderr
index 1840babd6..1023189ea 100644
--- a/src/test/ui/macros/macro-in-expression-context.stderr
+++ b/src/test/ui/macros/macro-in-expression-context.stderr
@@ -20,11 +20,11 @@ LL | assert_eq!("A", "A");
LL | foo!()
| ------ in this macro invocation
|
- = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
= note: macro invocations at the end of a block are treated as expressions
= note: to ignore the value produced by the macro, add a semicolon after the invocation of `foo`
+ = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
= note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error; 1 warning emitted
diff --git a/src/test/ui/macros/macro-match-nonterminal.stderr b/src/test/ui/macros/macro-match-nonterminal.stderr
index 48b9bc6ff..ef7261c02 100644
--- a/src/test/ui/macros/macro-match-nonterminal.stderr
+++ b/src/test/ui/macros/macro-match-nonterminal.stderr
@@ -10,9 +10,9 @@ error: missing fragment specifier
LL | ($a, $b) => {
| ^
|
- = note: `#[deny(missing_fragment_specifier)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
+ = note: `#[deny(missing_fragment_specifier)]` on by default
error: missing fragment specifier
--> $DIR/macro-match-nonterminal.rs:2:10
diff --git a/src/test/ui/macros/macro-missing-fragment-deduplication.stderr b/src/test/ui/macros/macro-missing-fragment-deduplication.stderr
index 7622ca054..3b9e716e1 100644
--- a/src/test/ui/macros/macro-missing-fragment-deduplication.stderr
+++ b/src/test/ui/macros/macro-missing-fragment-deduplication.stderr
@@ -10,9 +10,9 @@ error: missing fragment specifier
LL | ($name) => {}
| ^^^^^
|
- = note: `#[deny(missing_fragment_specifier)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
+ = note: `#[deny(missing_fragment_specifier)]` on by default
error: aborting due to 2 previous errors
diff --git a/src/test/ui/macros/macro-missing-fragment.stderr b/src/test/ui/macros/macro-missing-fragment.stderr
index 1bf6f04ec..2aa1e58f6 100644
--- a/src/test/ui/macros/macro-missing-fragment.stderr
+++ b/src/test/ui/macros/macro-missing-fragment.stderr
@@ -10,13 +10,13 @@ warning: missing fragment specifier
LL | ( $( any_token $field_rust_type )* ) => {};
| ^^^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
note: the lint level is defined here
--> $DIR/macro-missing-fragment.rs:1:9
|
LL | #![warn(missing_fragment_specifier)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
warning: missing fragment specifier
--> $DIR/macro-missing-fragment.rs:12:7
diff --git a/src/test/ui/macros/macro-or-patterns-back-compat.stderr b/src/test/ui/macros/macro-or-patterns-back-compat.stderr
index 9a5b8009f..e04dfefa4 100644
--- a/src/test/ui/macros/macro-or-patterns-back-compat.stderr
+++ b/src/test/ui/macros/macro-or-patterns-back-compat.stderr
@@ -4,13 +4,13 @@ error: the meaning of the `pat` fragment specifier is changing in Rust 2021, whi
LL | macro_rules! foo { ($x:pat | $y:pat) => {} }
| ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/or-patterns-macro-rules.html>
note: the lint level is defined here
--> $DIR/macro-or-patterns-back-compat.rs:4:9
|
LL | #![deny(rust_2021_incompatible_or_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/or-patterns-macro-rules.html>
error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
--> $DIR/macro-or-patterns-back-compat.rs:13:23
diff --git a/src/test/ui/macros/macro-use-all-and-none.stderr b/src/test/ui/macros/macro-use-all-and-none.stderr
index 6de7ffb2f..00b10dccd 100644
--- a/src/test/ui/macros/macro-use-all-and-none.stderr
+++ b/src/test/ui/macros/macro-use-all-and-none.stderr
@@ -4,12 +4,12 @@ warning: unused attribute
LL | #[macro_use()]
| ^^^^^^^^^^^^^^ help: remove this attribute
|
+ = note: attribute `macro_use` with an empty list has no effect
note: the lint level is defined here
--> $DIR/macro-use-all-and-none.rs:4:9
|
LL | #![warn(unused_attributes)]
| ^^^^^^^^^^^^^^^^^
- = note: attribute `macro_use` with an empty list has no effect
warning: 1 warning emitted
diff --git a/src/test/ui/macros/macro_rules-unmatchable-literals.rs b/src/test/ui/macros/macro_rules-unmatchable-literals.rs
new file mode 100644
index 000000000..bde0fe1a0
--- /dev/null
+++ b/src/test/ui/macros/macro_rules-unmatchable-literals.rs
@@ -0,0 +1,14 @@
+// Pinning tests for things that don't work to make sure we notice if that changes
+
+#![crate_type = "lib"]
+
+macro_rules! octal_with_bad_digit {
+ ( 0o1238 ) => {}; //~ ERROR invalid digit
+}
+
+macro_rules! binary_with_bad_digit {
+ ( 0b012 ) => {}; //~ ERROR invalid digit
+}
+
+// This can't happen for Hex and Decimal as things like `123A` and `0xFFG`
+// get treated as unknown *suffixes*, rather than digits.
diff --git a/src/test/ui/macros/macro_rules-unmatchable-literals.stderr b/src/test/ui/macros/macro_rules-unmatchable-literals.stderr
new file mode 100644
index 000000000..956a66979
--- /dev/null
+++ b/src/test/ui/macros/macro_rules-unmatchable-literals.stderr
@@ -0,0 +1,14 @@
+error: invalid digit for a base 8 literal
+ --> $DIR/macro_rules-unmatchable-literals.rs:6:12
+ |
+LL | ( 0o1238 ) => {};
+ | ^
+
+error: invalid digit for a base 2 literal
+ --> $DIR/macro_rules-unmatchable-literals.rs:10:11
+ |
+LL | ( 0b012 ) => {};
+ | ^
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/macros/macros-nonfatal-errors.rs b/src/test/ui/macros/macros-nonfatal-errors.rs
index e7a01f105..ab14c3589 100644
--- a/src/test/ui/macros/macros-nonfatal-errors.rs
+++ b/src/test/ui/macros/macros-nonfatal-errors.rs
@@ -4,7 +4,7 @@
// immediately, so that we get more errors listed at a time.
#![feature(trace_macros, concat_idents)]
-#![feature(stmt_expr_attributes, arbitrary_enum_discriminant)]
+#![feature(stmt_expr_attributes)]
use std::arch::asm;
@@ -116,3 +116,24 @@ fn main() {
trace_macros!(invalid); //~ ERROR
}
+
+/// Check that `#[derive(Default)]` does use a `T : Default` bound when the
+/// `#[default]` variant is `#[non_exhaustive]` (should this end up allowed).
+const _: () = {
+ #[derive(Default)]
+ enum NonExhaustiveDefaultGeneric<T> {
+ #[default]
+ #[non_exhaustive]
+ Foo, //~ ERROR default variant must be exhaustive
+ Bar(T),
+ }
+
+ fn assert_impls_default<T: Default>() {}
+
+ enum NotDefault {}
+
+ // Note: the `derive(Default)` currently bails early enough for trait-checking
+ // not to happen. Should it bail late enough, or even pass, make sure to
+ // assert that the following line fails.
+ let _ = assert_impls_default::<NonExhaustiveDefaultGeneric<NotDefault>>;
+};
diff --git a/src/test/ui/macros/macros-nonfatal-errors.stderr b/src/test/ui/macros/macros-nonfatal-errors.stderr
index b3c6d07f9..d42f6c179 100644
--- a/src/test/ui/macros/macros-nonfatal-errors.stderr
+++ b/src/test/ui/macros/macros-nonfatal-errors.stderr
@@ -215,11 +215,21 @@ error: trace_macros! accepts only `true` or `false`
LL | trace_macros!(invalid);
| ^^^^^^^^^^^^^^^^^^^^^^
+error: default variant must be exhaustive
+ --> $DIR/macros-nonfatal-errors.rs:127:9
+ |
+LL | #[non_exhaustive]
+ | ----------------- declared `#[non_exhaustive]` here
+LL | Foo,
+ | ^^^
+ |
+ = help: consider a manual implementation of `Default`
+
error: cannot find macro `llvm_asm` in this scope
--> $DIR/macros-nonfatal-errors.rs:99:5
|
LL | llvm_asm!(invalid);
| ^^^^^^^^
-error: aborting due to 27 previous errors
+error: aborting due to 28 previous errors
diff --git a/src/test/ui/macros/must-use-in-macro-55516.stderr b/src/test/ui/macros/must-use-in-macro-55516.stderr
index b56b00cc7..8878b0eea 100644
--- a/src/test/ui/macros/must-use-in-macro-55516.stderr
+++ b/src/test/ui/macros/must-use-in-macro-55516.stderr
@@ -4,8 +4,8 @@ warning: unused `Result` that must be used
LL | write!(&mut example, "{}", 42);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-W unused-must-use` implied by `-W unused`
= note: this `Result` may be an `Err` variant, which should be handled
+ = note: `-W unused-must-use` implied by `-W unused`
= note: this warning originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: 1 warning emitted
diff --git a/src/test/ui/macros/rfc-2011-nicer-assert-messages/all-expr-kinds.rs b/src/test/ui/macros/rfc-2011-nicer-assert-messages/all-expr-kinds.rs
index f538ec643..b8b6f0846 100644
--- a/src/test/ui/macros/rfc-2011-nicer-assert-messages/all-expr-kinds.rs
+++ b/src/test/ui/macros/rfc-2011-nicer-assert-messages/all-expr-kinds.rs
@@ -2,6 +2,7 @@
// ignore-tidy-linelength
// only-x86_64
// run-pass
+// needs-unwind Asserting on contents of error message
#![allow(path_statements, unused_allocation)]
#![feature(box_syntax, core_intrinsics, generic_assert, generic_assert_internals)]
diff --git a/src/test/ui/macros/rfc-2011-nicer-assert-messages/all-not-available-cases.rs b/src/test/ui/macros/rfc-2011-nicer-assert-messages/all-not-available-cases.rs
index 86697c58f..d46f396ee 100644
--- a/src/test/ui/macros/rfc-2011-nicer-assert-messages/all-not-available-cases.rs
+++ b/src/test/ui/macros/rfc-2011-nicer-assert-messages/all-not-available-cases.rs
@@ -2,6 +2,7 @@
// ignore-tidy-linelength
// only-x86_64
// run-pass
+// needs-unwind Asserting on contents of error message
#![feature(core_intrinsics, generic_assert, generic_assert_internals)]
diff --git a/src/test/ui/macros/rfc-2011-nicer-assert-messages/assert-without-captures-does-not-create-unnecessary-code.rs b/src/test/ui/macros/rfc-2011-nicer-assert-messages/assert-without-captures-does-not-create-unnecessary-code.rs
index 06c4993ec..1f5a29ab5 100644
--- a/src/test/ui/macros/rfc-2011-nicer-assert-messages/assert-without-captures-does-not-create-unnecessary-code.rs
+++ b/src/test/ui/macros/rfc-2011-nicer-assert-messages/assert-without-captures-does-not-create-unnecessary-code.rs
@@ -1,6 +1,7 @@
// aux-build:common.rs
// only-x86_64
// run-pass
+// needs-unwind Asserting on contents of error message
#![feature(core_intrinsics, generic_assert, generic_assert_internals)]
diff --git a/src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr b/src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr
index 0188938a3..a6cff95fd 100644
--- a/src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr
+++ b/src/test/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr
@@ -319,11 +319,11 @@ LL | unknown_metavar!(a);
|
= note: this error originates in the macro `unknown_metavar` (in Nightly builds, run with -Z macro-backtrace for more info)
-error[E0425]: cannot find function `count` in this scope
- --> $DIR/syntax-errors.rs:29:30
+error[E0425]: cannot find value `i` in this scope
+ --> $DIR/syntax-errors.rs:29:36
|
LL | ( $( $i:ident ),* ) => { count(i) };
- | ^^^^^ not found in this scope
+ | ^ not found in this scope
...
LL | no_curly__no_rhs_dollar__round!(a, b, c);
| ---------------------------------------- in this macro invocation
@@ -331,10 +331,27 @@ LL | no_curly__no_rhs_dollar__round!(a, b, c);
= note: this error originates in the macro `no_curly__no_rhs_dollar__round` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0425]: cannot find value `i` in this scope
- --> $DIR/syntax-errors.rs:29:36
+ --> $DIR/syntax-errors.rs:35:29
+ |
+LL | ( $i:ident ) => { count(i) };
+ | ^ not found in this scope
+...
+LL | no_curly__no_rhs_dollar__no_round!(a);
+ | ------------------------------------- in this macro invocation
+ |
+ = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0425]: cannot find value `a` in this scope
+ --> $DIR/syntax-errors.rs:153:37
+ |
+LL | no_curly__rhs_dollar__no_round!(a);
+ | ^ not found in this scope
+
+error[E0425]: cannot find function `count` in this scope
+ --> $DIR/syntax-errors.rs:29:30
|
LL | ( $( $i:ident ),* ) => { count(i) };
- | ^ not found in this scope
+ | ^^^^^ not found in this scope
...
LL | no_curly__no_rhs_dollar__round!(a, b, c);
| ---------------------------------------- in this macro invocation
@@ -352,17 +369,6 @@ LL | no_curly__no_rhs_dollar__no_round!(a);
|
= note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
-error[E0425]: cannot find value `i` in this scope
- --> $DIR/syntax-errors.rs:35:29
- |
-LL | ( $i:ident ) => { count(i) };
- | ^ not found in this scope
-...
-LL | no_curly__no_rhs_dollar__no_round!(a);
- | ------------------------------------- in this macro invocation
- |
- = note: this error originates in the macro `no_curly__no_rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
-
error[E0425]: cannot find function `count` in this scope
--> $DIR/syntax-errors.rs:46:23
|
@@ -374,12 +380,6 @@ LL | no_curly__rhs_dollar__no_round!(a);
|
= note: this error originates in the macro `no_curly__rhs_dollar__no_round` (in Nightly builds, run with -Z macro-backtrace for more info)
-error[E0425]: cannot find value `a` in this scope
- --> $DIR/syntax-errors.rs:153:37
- |
-LL | no_curly__rhs_dollar__no_round!(a);
- | ^ not found in this scope
-
error: aborting due to 40 previous errors
For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/macros/stringify.rs b/src/test/ui/macros/stringify.rs
index dd159cb5b..bc0d44881 100644
--- a/src/test/ui/macros/stringify.rs
+++ b/src/test/ui/macros/stringify.rs
@@ -8,7 +8,6 @@
#![feature(const_trait_impl)]
#![feature(decl_macro)]
#![feature(generators)]
-#![feature(half_open_range_patterns)]
#![feature(more_qualified_paths)]
#![feature(raw_ref_op)]
#![feature(trait_alias)]
diff --git a/src/test/ui/macros/syntax-error-recovery.rs b/src/test/ui/macros/syntax-error-recovery.rs
new file mode 100644
index 000000000..ae6de3c50
--- /dev/null
+++ b/src/test/ui/macros/syntax-error-recovery.rs
@@ -0,0 +1,18 @@
+macro_rules! values {
+ ($($token:ident($value:literal) $(as $inner:ty)? => $attr:meta,)*) => {
+ #[derive(Debug)]
+ pub enum TokenKind {
+ $(
+ #[$attr]
+ $token $($inner)? = $value,
+ )*
+ }
+ };
+}
+//~^^^^^ ERROR expected one of `(`, `,`, `=`, `{`, or `}`, found `(String)`
+//~| ERROR macro expansion ignores token `(String)` and any following
+
+values!(STRING(1) as (String) => cfg(test),);
+//~^ ERROR expected one of `!` or `::`, found `<eof>`
+
+fn main() {}
diff --git a/src/test/ui/macros/syntax-error-recovery.stderr b/src/test/ui/macros/syntax-error-recovery.stderr
new file mode 100644
index 000000000..c153b3b91
--- /dev/null
+++ b/src/test/ui/macros/syntax-error-recovery.stderr
@@ -0,0 +1,30 @@
+error: expected one of `(`, `,`, `=`, `{`, or `}`, found `(String)`
+ --> $DIR/syntax-error-recovery.rs:7:26
+ |
+LL | $token $($inner)? = $value,
+ | ^^^^^^ expected one of `(`, `,`, `=`, `{`, or `}`
+...
+LL | values!(STRING(1) as (String) => cfg(test),);
+ | -------------------------------------------- in this macro invocation
+ |
+ = note: this error originates in the macro `values` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: macro expansion ignores token `(String)` and any following
+ --> $DIR/syntax-error-recovery.rs:7:26
+ |
+LL | $token $($inner)? = $value,
+ | ^^^^^^
+...
+LL | values!(STRING(1) as (String) => cfg(test),);
+ | -------------------------------------------- caused by the macro expansion here
+ |
+ = note: the usage of `values!` is likely invalid in item context
+
+error: expected one of `!` or `::`, found `<eof>`
+ --> $DIR/syntax-error-recovery.rs:15:9
+ |
+LL | values!(STRING(1) as (String) => cfg(test),);
+ | ^^^^^^ expected one of `!` or `::`
+
+error: aborting due to 3 previous errors
+
diff --git a/src/test/ui/malformed/malformed-regressions.stderr b/src/test/ui/malformed/malformed-regressions.stderr
index 8c2625bdf..9bfbe7eba 100644
--- a/src/test/ui/malformed/malformed-regressions.stderr
+++ b/src/test/ui/malformed/malformed-regressions.stderr
@@ -4,9 +4,9 @@ error: attribute must be of the form `#[doc(hidden|inline|...)]` or `#[doc = "st
LL | #[doc]
| ^^^^^^
|
- = note: `#[deny(ill_formed_attribute_input)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
+ = note: `#[deny(ill_formed_attribute_input)]` on by default
error: attribute must be of the form `#[ignore]` or `#[ignore = "reason"]`
--> $DIR/malformed-regressions.rs:3:1
diff --git a/src/test/ui/marker_trait_attr/overlap-doesnt-conflict-with-specialization.stderr b/src/test/ui/marker_trait_attr/overlap-doesnt-conflict-with-specialization.stderr
index fca986627..649e58915 100644
--- a/src/test/ui/marker_trait_attr/overlap-doesnt-conflict-with-specialization.stderr
+++ b/src/test/ui/marker_trait_attr/overlap-doesnt-conflict-with-specialization.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/marker_trait_attr/overlap-marker-trait-with-static-lifetime.rs b/src/test/ui/marker_trait_attr/overlap-marker-trait-with-static-lifetime.rs
new file mode 100644
index 000000000..62aa22d41
--- /dev/null
+++ b/src/test/ui/marker_trait_attr/overlap-marker-trait-with-static-lifetime.rs
@@ -0,0 +1,10 @@
+// check-pass
+#![feature(marker_trait_attr)]
+
+#[marker]
+trait Marker {}
+
+impl Marker for &'static () {}
+impl Marker for &'static () {}
+
+fn main() {}
diff --git a/src/test/ui/marker_trait_attr/overlap-marker-trait-with-underscore-lifetime.rs b/src/test/ui/marker_trait_attr/overlap-marker-trait-with-underscore-lifetime.rs
new file mode 100644
index 000000000..eabce1aef
--- /dev/null
+++ b/src/test/ui/marker_trait_attr/overlap-marker-trait-with-underscore-lifetime.rs
@@ -0,0 +1,9 @@
+#![feature(marker_trait_attr)]
+
+#[marker]
+trait Marker {}
+
+impl Marker for &'_ () {} //~ ERROR type annotations needed
+impl Marker for &'_ () {} //~ ERROR type annotations needed
+
+fn main() {}
diff --git a/src/test/ui/marker_trait_attr/overlap-marker-trait-with-underscore-lifetime.stderr b/src/test/ui/marker_trait_attr/overlap-marker-trait-with-underscore-lifetime.stderr
new file mode 100644
index 000000000..235c89e20
--- /dev/null
+++ b/src/test/ui/marker_trait_attr/overlap-marker-trait-with-underscore-lifetime.stderr
@@ -0,0 +1,31 @@
+error[E0283]: type annotations needed: cannot satisfy `&(): Marker`
+ --> $DIR/overlap-marker-trait-with-underscore-lifetime.rs:6:6
+ |
+LL | impl Marker for &'_ () {}
+ | ^^^^^^
+ |
+note: multiple `impl`s satisfying `&(): Marker` found
+ --> $DIR/overlap-marker-trait-with-underscore-lifetime.rs:6:1
+ |
+LL | impl Marker for &'_ () {}
+ | ^^^^^^^^^^^^^^^^^^^^^^
+LL | impl Marker for &'_ () {}
+ | ^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0283]: type annotations needed: cannot satisfy `&(): Marker`
+ --> $DIR/overlap-marker-trait-with-underscore-lifetime.rs:7:6
+ |
+LL | impl Marker for &'_ () {}
+ | ^^^^^^
+ |
+note: multiple `impl`s satisfying `&(): Marker` found
+ --> $DIR/overlap-marker-trait-with-underscore-lifetime.rs:6:1
+ |
+LL | impl Marker for &'_ () {}
+ | ^^^^^^^^^^^^^^^^^^^^^^
+LL | impl Marker for &'_ () {}
+ | ^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0283`.
diff --git a/src/test/ui/marker_trait_attr/overlap-marker-trait.rs b/src/test/ui/marker_trait_attr/overlap-marker-trait.rs
index 8794d42f4..67e551797 100644
--- a/src/test/ui/marker_trait_attr/overlap-marker-trait.rs
+++ b/src/test/ui/marker_trait_attr/overlap-marker-trait.rs
@@ -7,7 +7,8 @@
use std::fmt::{Debug, Display};
-#[marker] trait Marker {}
+#[marker]
+trait Marker {}
impl<T: Debug> Marker for T {}
impl<T: Display> Marker for T {}
diff --git a/src/test/ui/marker_trait_attr/overlap-marker-trait.stderr b/src/test/ui/marker_trait_attr/overlap-marker-trait.stderr
index 1f3410597..133bc0484 100644
--- a/src/test/ui/marker_trait_attr/overlap-marker-trait.stderr
+++ b/src/test/ui/marker_trait_attr/overlap-marker-trait.stderr
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `NotDebugOrDisplay: Marker` is not satisfied
- --> $DIR/overlap-marker-trait.rs:27:17
+ --> $DIR/overlap-marker-trait.rs:28:17
|
LL | is_marker::<NotDebugOrDisplay>();
| ^^^^^^^^^^^^^^^^^ the trait `Marker` is not implemented for `NotDebugOrDisplay`
|
note: required by a bound in `is_marker`
- --> $DIR/overlap-marker-trait.rs:15:17
+ --> $DIR/overlap-marker-trait.rs:16:17
|
LL | fn is_marker<T: Marker>() { }
| ^^^^^^ required by this bound in `is_marker`
diff --git a/src/test/ui/marker_trait_attr/overlap-permitted-for-annotated-marker-traits.rs b/src/test/ui/marker_trait_attr/overlap-permitted-for-annotated-marker-traits.rs
index 383313902..f7654458f 100644
--- a/src/test/ui/marker_trait_attr/overlap-permitted-for-annotated-marker-traits.rs
+++ b/src/test/ui/marker_trait_attr/overlap-permitted-for-annotated-marker-traits.rs
@@ -7,7 +7,8 @@
use std::fmt::{Debug, Display};
-#[marker] trait MyMarker {}
+#[marker]
+trait MyMarker {}
impl<T: Debug> MyMarker for T {}
impl<T: Display> MyMarker for T {}
diff --git a/src/test/ui/match/expr_before_ident_pat.rs b/src/test/ui/match/expr_before_ident_pat.rs
index 47db6c3f4..27ef3d05a 100644
--- a/src/test/ui/match/expr_before_ident_pat.rs
+++ b/src/test/ui/match/expr_before_ident_pat.rs
@@ -1,5 +1,3 @@
-#![feature(half_open_range_patterns)]
-
macro_rules! funny {
($a:expr, $b:ident) => {
match [1, 2] {
diff --git a/src/test/ui/match/expr_before_ident_pat.stderr b/src/test/ui/match/expr_before_ident_pat.stderr
index 2bd1b3b94..57a2d2b26 100644
--- a/src/test/ui/match/expr_before_ident_pat.stderr
+++ b/src/test/ui/match/expr_before_ident_pat.stderr
@@ -1,11 +1,11 @@
error[E0425]: cannot find value `a` in this scope
- --> $DIR/expr_before_ident_pat.rs:12:12
+ --> $DIR/expr_before_ident_pat.rs:10:12
|
LL | funny!(a, a);
| ^ not found in this scope
error: arbitrary expressions aren't allowed in patterns
- --> $DIR/expr_before_ident_pat.rs:12:12
+ --> $DIR/expr_before_ident_pat.rs:10:12
|
LL | funny!(a, a);
| ^
diff --git a/src/test/ui/match/issue-41255.rs b/src/test/ui/match/issue-41255.rs
index 9d7072f16..d163801fd 100644
--- a/src/test/ui/match/issue-41255.rs
+++ b/src/test/ui/match/issue-41255.rs
@@ -1,7 +1,6 @@
// Matching against float literals should result in a linter error
#![feature(exclusive_range_pattern)]
-#![feature(half_open_range_patterns)]
#![allow(unused)]
#![forbid(illegal_floating_point_literal_pattern)]
diff --git a/src/test/ui/match/issue-41255.stderr b/src/test/ui/match/issue-41255.stderr
index bf81c8d37..9bc49654e 100644
--- a/src/test/ui/match/issue-41255.stderr
+++ b/src/test/ui/match/issue-41255.stderr
@@ -1,19 +1,19 @@
error: floating-point types cannot be used in patterns
- --> $DIR/issue-41255.rs:11:9
+ --> $DIR/issue-41255.rs:10:9
|
LL | 5.0 => {},
| ^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
note: the lint level is defined here
- --> $DIR/issue-41255.rs:6:11
+ --> $DIR/issue-41255.rs:5:11
|
LL | #![forbid(illegal_floating_point_literal_pattern)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns
- --> $DIR/issue-41255.rs:13:9
+ --> $DIR/issue-41255.rs:12:9
|
LL | 5.0f32 => {},
| ^^^^^^
@@ -22,7 +22,7 @@ LL | 5.0f32 => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns
- --> $DIR/issue-41255.rs:15:10
+ --> $DIR/issue-41255.rs:14:10
|
LL | -5.0 => {},
| ^^^
@@ -31,7 +31,7 @@ LL | -5.0 => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns
- --> $DIR/issue-41255.rs:17:9
+ --> $DIR/issue-41255.rs:16:9
|
LL | 1.0 .. 33.0 => {},
| ^^^
@@ -40,7 +40,7 @@ LL | 1.0 .. 33.0 => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns
- --> $DIR/issue-41255.rs:17:16
+ --> $DIR/issue-41255.rs:16:16
|
LL | 1.0 .. 33.0 => {},
| ^^^^
@@ -49,7 +49,7 @@ LL | 1.0 .. 33.0 => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns
- --> $DIR/issue-41255.rs:21:9
+ --> $DIR/issue-41255.rs:20:9
|
LL | 39.0 ..= 70.0 => {},
| ^^^^
@@ -58,7 +58,7 @@ LL | 39.0 ..= 70.0 => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns
- --> $DIR/issue-41255.rs:21:18
+ --> $DIR/issue-41255.rs:20:18
|
LL | 39.0 ..= 70.0 => {},
| ^^^^
@@ -67,7 +67,7 @@ LL | 39.0 ..= 70.0 => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns
- --> $DIR/issue-41255.rs:26:11
+ --> $DIR/issue-41255.rs:25:11
|
LL | ..71.0 => {}
| ^^^^
@@ -76,7 +76,7 @@ LL | ..71.0 => {}
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns
- --> $DIR/issue-41255.rs:29:12
+ --> $DIR/issue-41255.rs:28:12
|
LL | ..=72.0 => {}
| ^^^^
@@ -85,7 +85,7 @@ LL | ..=72.0 => {}
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns
- --> $DIR/issue-41255.rs:32:9
+ --> $DIR/issue-41255.rs:31:9
|
LL | 71.0.. => {}
| ^^^^
@@ -94,7 +94,7 @@ LL | 71.0.. => {}
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns
- --> $DIR/issue-41255.rs:40:10
+ --> $DIR/issue-41255.rs:39:10
|
LL | (3.14, 1) => {},
| ^^^^
@@ -103,7 +103,7 @@ LL | (3.14, 1) => {},
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns
- --> $DIR/issue-41255.rs:47:18
+ --> $DIR/issue-41255.rs:46:18
|
LL | Foo { x: 2.0 } => {},
| ^^^
diff --git a/src/test/ui/match/issue-92100.rs b/src/test/ui/match/issue-92100.rs
index 021166b2b..baac570dd 100644
--- a/src/test/ui/match/issue-92100.rs
+++ b/src/test/ui/match/issue-92100.rs
@@ -1,4 +1,4 @@
-#![feature(half_open_range_patterns)]
+#![feature(half_open_range_patterns_in_slices)]
fn main() {
match [1, 2] {
diff --git a/src/test/ui/methods/issues/issue-90315.rs b/src/test/ui/methods/issues/issue-90315.rs
index 01bf9f484..79cdc4195 100644
--- a/src/test/ui/methods/issues/issue-90315.rs
+++ b/src/test/ui/methods/issues/issue-90315.rs
@@ -1,7 +1,76 @@
+#![allow(unused)]
fn main() {
- let arr = &[0,1,2,3];
- for _i in 0..arr.len().rev() { //~ERROR not an iterator
- // The above error used to say “the method `rev` exists for type `usize`â€.
- // This regression test ensures it doesn't say that any more.
- }
+ let arr = &[0, 1, 2, 3];
+ for _i in 0..arr.len().rev() {
+ //~^ ERROR can't call method
+ //~| surround the range in parentheses
+ // The above error used to say “the method `rev` exists for type `usize`â€.
+ // This regression test ensures it doesn't say that any more.
+ }
+
+ // Test for #102396
+ for i in 1..11.rev() {
+ //~^ ERROR can't call method
+ //~| HELP surround the range in parentheses
+ }
+
+ let end: usize = 10;
+ for i in 1..end.rev() {
+ //~^ ERROR can't call method
+ //~| HELP surround the range in parentheses
+ }
+
+ for i in 1..(end + 1).rev() {
+ //~^ ERROR can't call method
+ //~| HELP surround the range in parentheses
+ }
+
+ if 1..(end + 1).is_empty() {
+ //~^ ERROR can't call method
+ //~| ERROR mismatched types [E0308]
+ //~| HELP surround the range in parentheses
+ }
+
+ if 1..(end + 1).is_sorted() {
+ //~^ ERROR mismatched types [E0308]
+ //~| ERROR can't call method
+ //~| HELP surround the range in parentheses
+ }
+
+ let _res: i32 = 3..6.take(2).sum();
+ //~^ ERROR can't call method
+ //~| ERROR mismatched types [E0308]
+ //~| HELP surround the range in parentheses
+
+ let _sum: i32 = 3..6.sum();
+ //~^ ERROR can't call method
+ //~| ERROR mismatched types [E0308]
+ //~| HELP surround the range in parentheses
+
+ let a = 1 as usize;
+ let b = 10 as usize;
+
+ for _a in a..=b.rev() {
+ //~^ ERROR can't call method
+ //~| HELP surround the range in parentheses
+ }
+
+ let _res = ..10.contains(3);
+ //~^ ERROR can't call method
+ //~| HELP surround the range in parentheses
+
+ if 1..end.error_method() {
+ //~^ ERROR no method named `error_method`
+ //~| ERROR mismatched types [E0308]
+ // Won't suggest
+ }
+
+ let _res = b.take(1)..a;
+ //~^ ERROR `usize` is not an iterator
+
+ let _res: i32 = ..6.take(2).sum();
+ //~^ can't call method `take` on ambiguous numeric type
+ //~| ERROR mismatched types [E0308]
+ //~| HELP you must specify a concrete type for this numeric value
+ // Won't suggest because `RangeTo` dest not implemented `take`
}
diff --git a/src/test/ui/methods/issues/issue-90315.stderr b/src/test/ui/methods/issues/issue-90315.stderr
index c6a76c9e7..070cd3054 100644
--- a/src/test/ui/methods/issues/issue-90315.stderr
+++ b/src/test/ui/methods/issues/issue-90315.stderr
@@ -1,13 +1,201 @@
+error[E0689]: can't call method `rev` on type `usize`
+ --> $DIR/issue-90315.rs:4:28
+ |
+LL | for _i in 0..arr.len().rev() {
+ | ^^^ can't call method `rev` on type `usize`
+ |
+help: you must surround the range in parentheses to call its `rev` function
+ |
+LL | for _i in (0..arr.len()).rev() {
+ | + +
+
+error[E0689]: can't call method `rev` on type `{integer}`
+ --> $DIR/issue-90315.rs:12:20
+ |
+LL | for i in 1..11.rev() {
+ | ^^^ can't call method `rev` on type `{integer}`
+ |
+help: you must surround the range in parentheses to call its `rev` function
+ |
+LL | for i in (1..11).rev() {
+ | + +
+
+error[E0689]: can't call method `rev` on type `usize`
+ --> $DIR/issue-90315.rs:18:21
+ |
+LL | for i in 1..end.rev() {
+ | ^^^ can't call method `rev` on type `usize`
+ |
+help: you must surround the range in parentheses to call its `rev` function
+ |
+LL | for i in (1..end).rev() {
+ | + +
+
+error[E0689]: can't call method `rev` on type `usize`
+ --> $DIR/issue-90315.rs:23:27
+ |
+LL | for i in 1..(end + 1).rev() {
+ | ^^^ can't call method `rev` on type `usize`
+ |
+help: you must surround the range in parentheses to call its `rev` function
+ |
+LL | for i in (1..(end + 1)).rev() {
+ | + +
+
+error[E0689]: can't call method `is_empty` on type `usize`
+ --> $DIR/issue-90315.rs:28:21
+ |
+LL | if 1..(end + 1).is_empty() {
+ | ^^^^^^^^ can't call method `is_empty` on type `usize`
+ |
+help: you must surround the range in parentheses to call its `is_empty` function
+ |
+LL | if (1..(end + 1)).is_empty() {
+ | + +
+
+error[E0308]: mismatched types
+ --> $DIR/issue-90315.rs:28:8
+ |
+LL | if 1..(end + 1).is_empty() {
+ | ^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found struct `std::ops::Range`
+ |
+ = note: expected type `bool`
+ found struct `std::ops::Range<{integer}>`
+
+error[E0689]: can't call method `is_sorted` on type `usize`
+ --> $DIR/issue-90315.rs:34:21
+ |
+LL | if 1..(end + 1).is_sorted() {
+ | ^^^^^^^^^ can't call method `is_sorted` on type `usize`
+ |
+help: you must surround the range in parentheses to call its `is_sorted` function
+ |
+LL | if (1..(end + 1)).is_sorted() {
+ | + +
+
+error[E0308]: mismatched types
+ --> $DIR/issue-90315.rs:34:8
+ |
+LL | if 1..(end + 1).is_sorted() {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found struct `std::ops::Range`
+ |
+ = note: expected type `bool`
+ found struct `std::ops::Range<{integer}>`
+
+error[E0689]: can't call method `take` on type `{integer}`
+ --> $DIR/issue-90315.rs:40:26
+ |
+LL | let _res: i32 = 3..6.take(2).sum();
+ | ^^^^ can't call method `take` on type `{integer}`
+ |
+help: you must surround the range in parentheses to call its `take` function
+ |
+LL | let _res: i32 = (3..6).take(2).sum();
+ | + +
+
+error[E0308]: mismatched types
+ --> $DIR/issue-90315.rs:40:21
+ |
+LL | let _res: i32 = 3..6.take(2).sum();
+ | --- ^^^^^^^^^^^^^^^^^^ expected `i32`, found struct `std::ops::Range`
+ | |
+ | expected due to this
+ |
+ = note: expected type `i32`
+ found struct `std::ops::Range<{integer}>`
+
+error[E0689]: can't call method `sum` on type `{integer}`
+ --> $DIR/issue-90315.rs:45:26
+ |
+LL | let _sum: i32 = 3..6.sum();
+ | ^^^ can't call method `sum` on type `{integer}`
+ |
+help: you must surround the range in parentheses to call its `sum` function
+ |
+LL | let _sum: i32 = (3..6).sum();
+ | + +
+
+error[E0308]: mismatched types
+ --> $DIR/issue-90315.rs:45:21
+ |
+LL | let _sum: i32 = 3..6.sum();
+ | --- ^^^^^^^^^^ expected `i32`, found struct `std::ops::Range`
+ | |
+ | expected due to this
+ |
+ = note: expected type `i32`
+ found struct `std::ops::Range<{integer}>`
+
+error[E0689]: can't call method `rev` on type `usize`
+ --> $DIR/issue-90315.rs:53:21
+ |
+LL | for _a in a..=b.rev() {
+ | ^^^ can't call method `rev` on type `usize`
+ |
+help: you must surround the range in parentheses to call its `rev` function
+ |
+LL | for _a in (a..=b).rev() {
+ | + +
+
+error[E0689]: can't call method `contains` on type `{integer}`
+ --> $DIR/issue-90315.rs:58:21
+ |
+LL | let _res = ..10.contains(3);
+ | ^^^^^^^^ can't call method `contains` on type `{integer}`
+ |
+help: you must surround the range in parentheses to call its `contains` function
+ |
+LL | let _res = (..10).contains(3);
+ | + +
+
+error[E0599]: no method named `error_method` found for type `usize` in the current scope
+ --> $DIR/issue-90315.rs:62:15
+ |
+LL | if 1..end.error_method() {
+ | ^^^^^^^^^^^^ method not found in `usize`
+
+error[E0308]: mismatched types
+ --> $DIR/issue-90315.rs:62:8
+ |
+LL | if 1..end.error_method() {
+ | ^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found struct `std::ops::Range`
+ |
+ = note: expected type `bool`
+ found struct `std::ops::Range<{integer}>`
+
error[E0599]: `usize` is not an iterator
- --> $DIR/issue-90315.rs:3:26
+ --> $DIR/issue-90315.rs:68:18
|
-LL | for _i in 0..arr.len().rev() {
- | ^^^ `usize` is not an iterator
+LL | let _res = b.take(1)..a;
+ | ^^^^ `usize` is not an iterator
|
= note: the following trait bounds were not satisfied:
`usize: Iterator`
which is required by `&mut usize: Iterator`
-error: aborting due to previous error
+error[E0689]: can't call method `take` on ambiguous numeric type `{integer}`
+ --> $DIR/issue-90315.rs:71:25
+ |
+LL | let _res: i32 = ..6.take(2).sum();
+ | ^^^^
+ |
+help: you must specify a concrete type for this numeric value, like `i32`
+ |
+LL | let _res: i32 = ..6_i32.take(2).sum();
+ | ~~~~~
+
+error[E0308]: mismatched types
+ --> $DIR/issue-90315.rs:71:21
+ |
+LL | let _res: i32 = ..6.take(2).sum();
+ | --- ^^^^^^^^^^^^^^^^^ expected `i32`, found struct `RangeTo`
+ | |
+ | expected due to this
+ |
+ = note: expected type `i32`
+ found struct `RangeTo<_>`
+
+error: aborting due to 19 previous errors
-For more information about this error, try `rustc --explain E0599`.
+Some errors have detailed explanations: E0308, E0599, E0689.
+For more information about an error, try `rustc --explain E0308`.
diff --git a/src/test/ui/methods/method-call-lifetime-args-lint-fail.stderr b/src/test/ui/methods/method-call-lifetime-args-lint-fail.stderr
index 9e07d5ea3..394c1ac3c 100644
--- a/src/test/ui/methods/method-call-lifetime-args-lint-fail.stderr
+++ b/src/test/ui/methods/method-call-lifetime-args-lint-fail.stderr
@@ -7,13 +7,13 @@ LL | fn late<'a, 'b>(self, _: &'a u8, _: &'b u8) {}
LL | S.late::<'static>(&0, &0);
| ^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
note: the lint level is defined here
--> $DIR/method-call-lifetime-args-lint-fail.rs:1:9
|
LL | #![deny(late_bound_lifetime_arguments)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/method-call-lifetime-args-lint-fail.rs:26:14
diff --git a/src/test/ui/methods/method-call-lifetime-args-lint.stderr b/src/test/ui/methods/method-call-lifetime-args-lint.stderr
index f31f510a3..b4fc2d717 100644
--- a/src/test/ui/methods/method-call-lifetime-args-lint.stderr
+++ b/src/test/ui/methods/method-call-lifetime-args-lint.stderr
@@ -7,13 +7,13 @@ LL | fn late<'a, 'b>(self, _: &'a u8, _: &'b u8) {}
LL | S.late::<'static>(&0, &0);
| ^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
note: the lint level is defined here
--> $DIR/method-call-lifetime-args-lint.rs:1:9
|
LL | #![deny(late_bound_lifetime_arguments)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/method-call-lifetime-args-lint.rs:16:23
diff --git a/src/test/ui/methods/method-call-lifetime-args-unresolved.stderr b/src/test/ui/methods/method-call-lifetime-args-unresolved.stderr
index 78af19586..62f20d6d5 100644
--- a/src/test/ui/methods/method-call-lifetime-args-unresolved.stderr
+++ b/src/test/ui/methods/method-call-lifetime-args-unresolved.stderr
@@ -17,9 +17,9 @@ LL | 0.clone::<'a>();
LL | fn clone(&self) -> Self;
| - the late bound lifetime parameter is introduced here
|
- = note: `#[warn(late_bound_lifetime_arguments)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
+ = note: `#[warn(late_bound_lifetime_arguments)]` on by default
error: aborting due to previous error; 1 warning emitted
diff --git a/src/test/ui/methods/method-deref-to-same-trait-object-with-separate-params.stderr b/src/test/ui/methods/method-deref-to-same-trait-object-with-separate-params.stderr
index 59075397e..82addab94 100644
--- a/src/test/ui/methods/method-deref-to-same-trait-object-with-separate-params.stderr
+++ b/src/test/ui/methods/method-deref-to-same-trait-object-with-separate-params.stderr
@@ -4,8 +4,8 @@ warning: the feature `unsized_locals` is incomplete and may not be safe to use a
LL | #![feature(unsized_locals, unsized_fn_params)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #48055 <https://github.com/rust-lang/rust/issues/48055> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> $DIR/method-deref-to-same-trait-object-with-separate-params.rs:87:24
diff --git a/src/test/ui/methods/method-macro-backtrace.stderr b/src/test/ui/methods/method-macro-backtrace.stderr
index 7ae00835c..dd616c4a5 100644
--- a/src/test/ui/methods/method-macro-backtrace.stderr
+++ b/src/test/ui/methods/method-macro-backtrace.stderr
@@ -1,11 +1,11 @@
-error[E0201]: duplicate definitions with name `bar`:
+error[E0592]: duplicate definitions with name `bar`
--> $DIR/method-macro-backtrace.rs:22:5
|
LL | fn bar(&self) { }
- | ------------- previous definition of `bar` here
+ | ------------- other definition for `bar`
LL | fn bar(&self) { }
- | ^^^^^^^^^^^^^ duplicate definition
+ | ^^^^^^^^^^^^^ duplicate definitions for `bar`
error: aborting due to previous error
-For more information about this error, try `rustc --explain E0201`.
+For more information about this error, try `rustc --explain E0592`.
diff --git a/src/test/ui/mir/drop-elaboration-after-borrowck-error.rs b/src/test/ui/mir/drop-elaboration-after-borrowck-error.rs
index fc7341a56..624b464ec 100644
--- a/src/test/ui/mir/drop-elaboration-after-borrowck-error.rs
+++ b/src/test/ui/mir/drop-elaboration-after-borrowck-error.rs
@@ -3,9 +3,9 @@
static A: () = {
let a: [String; 1];
- //~^ ERROR destructors cannot be evaluated at compile-time
+ //~^ ERROR destructor of
a[0] = String::new();
- //~^ ERROR destructors cannot be evaluated at compile-time
+ //~^ ERROR destructor of
//~| ERROR binding `a` isn't initialized
};
@@ -14,9 +14,9 @@ struct B<T>([T; 1]);
impl<T> B<T> {
pub const fn f(mut self, other: T) -> Self {
let _this = self;
- //~^ ERROR destructors cannot be evaluated at compile-time
+ //~^ ERROR destructor of
self.0[0] = other;
- //~^ ERROR destructors cannot be evaluated at compile-time
+ //~^ ERROR destructor of
//~| ERROR use of moved value
self
}
diff --git a/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr b/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr
index d8154f8d2..d96106172 100644
--- a/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr
+++ b/src/test/ui/mir/drop-elaboration-after-borrowck-error.stderr
@@ -1,17 +1,17 @@
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `String` cannot be evaluated at compile-time
--> $DIR/drop-elaboration-after-borrowck-error.rs:7:5
|
LL | a[0] = String::new();
| ^^^^
| |
- | statics cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in statics
| value is dropped here
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `[String; 1]` cannot be evaluated at compile-time
--> $DIR/drop-elaboration-after-borrowck-error.rs:5:9
|
LL | let a: [String; 1];
- | ^ statics cannot evaluate destructors
+ | ^ the destructor for this type cannot be evaluated in statics
...
LL | };
| - value is dropped here
@@ -24,21 +24,26 @@ LL | let a: [String; 1];
LL |
LL | a[0] = String::new();
| ^^^^ `a` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let a: [String; 1] = todo!();
+ | +++++++++
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `T` cannot be evaluated at compile-time
--> $DIR/drop-elaboration-after-borrowck-error.rs:18:9
|
LL | self.0[0] = other;
| ^^^^^^^^^
| |
- | constant functions cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constant functions
| value is dropped here
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `B<T>` cannot be evaluated at compile-time
--> $DIR/drop-elaboration-after-borrowck-error.rs:16:13
|
LL | let _this = self;
- | ^^^^^ constant functions cannot evaluate destructors
+ | ^^^^^ the destructor for this type cannot be evaluated in constant functions
...
LL | }
| - value is dropped here
diff --git a/src/test/ui/mir/mir_calls_to_shims.rs b/src/test/ui/mir/mir_calls_to_shims.rs
index 42eaab77d..9dc0acfbf 100644
--- a/src/test/ui/mir/mir_calls_to_shims.rs
+++ b/src/test/ui/mir/mir_calls_to_shims.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
#![feature(fn_traits)]
#![feature(never_type)]
diff --git a/src/test/ui/mir/mir_codegen_calls_diverging_drops.rs b/src/test/ui/mir/mir_codegen_calls_diverging_drops.rs
index 3d2156105..19dba4970 100644
--- a/src/test/ui/mir/mir_codegen_calls_diverging_drops.rs
+++ b/src/test/ui/mir/mir_codegen_calls_diverging_drops.rs
@@ -1,7 +1,6 @@
// run-fail
// error-pattern:diverging_fn called
// error-pattern:0 dropped
-// ignore-emscripten no processes
// needs-unwind this test checks that a destructor is called after panicking
struct Droppable(u8);
diff --git a/src/test/ui/mir/mir_drop_order.rs b/src/test/ui/mir/mir_drop_order.rs
index 853efb0fe..75f5b171a 100644
--- a/src/test/ui/mir/mir_drop_order.rs
+++ b/src/test/ui/mir/mir_drop_order.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
use std::cell::RefCell;
use std::panic;
diff --git a/src/test/ui/mir/mir_drop_panics.rs b/src/test/ui/mir/mir_drop_panics.rs
index b4093d704..0d00426d6 100644
--- a/src/test/ui/mir/mir_drop_panics.rs
+++ b/src/test/ui/mir/mir_drop_panics.rs
@@ -2,7 +2,6 @@
// needs-unwind
// error-pattern:panic 1
// error-pattern:drop 2
-// ignore-emscripten no processes
struct Droppable(u32);
impl Drop for Droppable {
diff --git a/src/test/ui/mir/mir_let_chains_drop_order.rs b/src/test/ui/mir/mir_let_chains_drop_order.rs
index 6498a5195..6471553e9 100644
--- a/src/test/ui/mir/mir_let_chains_drop_order.rs
+++ b/src/test/ui/mir/mir_let_chains_drop_order.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
// See `mir_drop_order.rs` for more information
@@ -13,7 +12,7 @@ use std::panic;
pub struct DropLogger<'a, T> {
extra: T,
id: usize,
- log: &'a panic::AssertUnwindSafe<RefCell<Vec<usize>>>
+ log: &'a panic::AssertUnwindSafe<RefCell<Vec<usize>>>,
}
impl<'a, T> Drop for DropLogger<'a, T> {
@@ -56,9 +55,9 @@ fn main() {
else {
// 10 is not constructed
d(10, None)
- }
+ },
);
- assert_eq!(get(), vec![3, 8, 7, 1, 2]);
+ assert_eq!(get(), vec![8, 7, 1, 3, 2]);
}
assert_eq!(get(), vec![0, 4, 6, 9, 5]);
@@ -90,5 +89,5 @@ fn main() {
panic::panic_any(InjectedFailure)
);
});
- assert_eq!(get(), vec![14, 19, 20, 17, 15, 11, 18, 16, 12, 13]);
+ assert_eq!(get(), vec![20, 17, 15, 11, 19, 18, 16, 12, 14, 13]);
}
diff --git a/src/test/ui/mir/thir-constparam-temp.stderr b/src/test/ui/mir/thir-constparam-temp.stderr
index ed2766c00..b77d67e08 100644
--- a/src/test/ui/mir/thir-constparam-temp.stderr
+++ b/src/test/ui/mir/thir-constparam-temp.stderr
@@ -4,7 +4,6 @@ warning: taking a mutable reference to a `const` item
LL | YIKES.mut_self()
| ^^^^^^^^^^^^^^^^
|
- = note: `#[warn(const_item_mutation)]` on by default
= note: each usage of a `const` item creates a new temporary
= note: the mutable reference will refer to this temporary, not the original `const` item
note: mutable reference created due to call to this method
@@ -17,6 +16,7 @@ note: `const` item defined here
|
LL | fn foo<const YIKES: Yikes>() {
| ^^^^^^^^^^^^^^^^^^
+ = note: `#[warn(const_item_mutation)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr b/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr
index 71469bfec..92d545b73 100644
--- a/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr
+++ b/src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr
@@ -23,7 +23,7 @@ LL | a.iter().map(|_: &(u16, u16)| 45);
| expected due to this
|
= note: expected closure signature `fn(&(u32, u32)) -> _`
- found closure signature `for<'r> fn(&'r (u16, u16)) -> _`
+ found closure signature `for<'a> fn(&'a (u16, u16)) -> _`
note: required by a bound in `map`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
diff --git a/src/test/ui/mismatched_types/closure-mismatch.stderr b/src/test/ui/mismatched_types/closure-mismatch.stderr
index ef76ec63f..a7ef8fa08 100644
--- a/src/test/ui/mismatched_types/closure-mismatch.stderr
+++ b/src/test/ui/mismatched_types/closure-mismatch.stderr
@@ -13,7 +13,7 @@ error[E0308]: mismatched types
LL | baz(|_| ());
| ^^^^^^^^^^^ one type is more general than the other
|
- = note: expected trait `for<'r> Fn<(&'r (),)>`
+ = note: expected trait `for<'a> Fn<(&'a (),)>`
found trait `Fn<(&(),)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/closure-mismatch.rs:8:9
diff --git a/src/test/ui/mismatched_types/fn-variance-1.stderr b/src/test/ui/mismatched_types/fn-variance-1.stderr
index eec6d83fe..5794e606e 100644
--- a/src/test/ui/mismatched_types/fn-variance-1.stderr
+++ b/src/test/ui/mismatched_types/fn-variance-1.stderr
@@ -10,7 +10,7 @@ LL | apply(&3, takes_mut);
| required by a bound introduced by this call
|
= note: expected function signature `fn(&{integer}) -> _`
- found function signature `for<'r> fn(&'r mut isize) -> _`
+ found function signature `for<'a> fn(&'a mut isize) -> _`
note: required by a bound in `apply`
--> $DIR/fn-variance-1.rs:5:37
|
@@ -29,7 +29,7 @@ LL | apply(&mut 3, takes_imm);
| required by a bound introduced by this call
|
= note: expected function signature `fn(&mut {integer}) -> _`
- found function signature `for<'r> fn(&'r isize) -> _`
+ found function signature `for<'a> fn(&'a isize) -> _`
note: required by a bound in `apply`
--> $DIR/fn-variance-1.rs:5:37
|
diff --git a/src/test/ui/mismatched_types/issue-36053-2.stderr b/src/test/ui/mismatched_types/issue-36053-2.stderr
index b11ea97d1..906001ca1 100644
--- a/src/test/ui/mismatched_types/issue-36053-2.stderr
+++ b/src/test/ui/mismatched_types/issue-36053-2.stderr
@@ -6,8 +6,8 @@ LL | once::<&str>("str").fuse().filter(|a: &str| true).count();
| |
| expected due to this
|
- = note: expected closure signature `for<'r> fn(&'r &str) -> _`
- found closure signature `for<'r> fn(&'r str) -> _`
+ = note: expected closure signature `for<'a> fn(&'a &str) -> _`
+ found closure signature `for<'a> fn(&'a str) -> _`
note: required by a bound in `filter`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
diff --git a/src/test/ui/mismatched_types/show_module.rs b/src/test/ui/mismatched_types/show_module.rs
new file mode 100644
index 000000000..61550b887
--- /dev/null
+++ b/src/test/ui/mismatched_types/show_module.rs
@@ -0,0 +1,18 @@
+pub mod blah {
+ pub mod baz {
+ pub struct Foo;
+ }
+}
+
+pub mod meh {
+ pub struct Foo;
+}
+
+pub type Foo = blah::baz::Foo;
+
+fn foo() -> Foo {
+ meh::Foo
+ //~^ ERROR mismatched types [E0308]
+}
+
+fn main() {}
diff --git a/src/test/ui/mismatched_types/show_module.stderr b/src/test/ui/mismatched_types/show_module.stderr
new file mode 100644
index 000000000..5e48e0955
--- /dev/null
+++ b/src/test/ui/mismatched_types/show_module.stderr
@@ -0,0 +1,23 @@
+error[E0308]: mismatched types
+ --> $DIR/show_module.rs:14:5
+ |
+LL | fn foo() -> Foo {
+ | --- expected `baz::Foo` because of return type
+LL | meh::Foo
+ | ^^^^^^^^ expected struct `baz::Foo`, found struct `meh::Foo`
+ |
+ = note: struct `meh::Foo` and struct `baz::Foo` have similar names, but are actually distinct types
+note: struct `meh::Foo` is defined in module `crate::meh` of the current crate
+ --> $DIR/show_module.rs:8:5
+ |
+LL | pub struct Foo;
+ | ^^^^^^^^^^^^^^
+note: struct `baz::Foo` is defined in module `crate::blah::baz` of the current crate
+ --> $DIR/show_module.rs:3:9
+ |
+LL | pub struct Foo;
+ | ^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/mismatched_types/similar_paths.rs b/src/test/ui/mismatched_types/similar_paths.rs
new file mode 100644
index 000000000..4b9157f39
--- /dev/null
+++ b/src/test/ui/mismatched_types/similar_paths.rs
@@ -0,0 +1,11 @@
+enum Option<T> {
+ Some(T),
+ None,
+}
+
+pub fn foo() -> Option<u8> {
+ Some(42_u8)
+ //~^ ERROR mismatched types [E0308]
+}
+
+fn main() {}
diff --git a/src/test/ui/mismatched_types/similar_paths.stderr b/src/test/ui/mismatched_types/similar_paths.stderr
new file mode 100644
index 000000000..e65ae58d4
--- /dev/null
+++ b/src/test/ui/mismatched_types/similar_paths.stderr
@@ -0,0 +1,23 @@
+error[E0308]: mismatched types
+ --> $DIR/similar_paths.rs:7:5
+ |
+LL | pub fn foo() -> Option<u8> {
+ | ---------- expected `Option<u8>` because of return type
+LL | Some(42_u8)
+ | ^^^^^^^^^^^ expected enum `Option`, found enum `std::option::Option`
+ |
+ = note: enum `std::option::Option` and enum `Option` have similar names, but are actually distinct types
+note: enum `std::option::Option` is defined in crate `core`
+ --> $SRC_DIR/core/src/option.rs:LL:COL
+ |
+LL | pub enum Option<T> {
+ | ^^^^^^^^^^^^^^^^^^
+note: enum `Option` is defined in the current crate
+ --> $DIR/similar_paths.rs:1:1
+ |
+LL | enum Option<T> {
+ | ^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/mismatched_types/similar_paths_primitive.rs b/src/test/ui/mismatched_types/similar_paths_primitive.rs
new file mode 100644
index 000000000..8f5b7cce4
--- /dev/null
+++ b/src/test/ui/mismatched_types/similar_paths_primitive.rs
@@ -0,0 +1,10 @@
+#![allow(non_camel_case_types)]
+
+struct bool;
+
+fn foo(_: bool) {}
+
+fn main() {
+ foo(true);
+ //~^ ERROR mismatched types [E0308]
+}
diff --git a/src/test/ui/mismatched_types/similar_paths_primitive.stderr b/src/test/ui/mismatched_types/similar_paths_primitive.stderr
new file mode 100644
index 000000000..8a2f73945
--- /dev/null
+++ b/src/test/ui/mismatched_types/similar_paths_primitive.stderr
@@ -0,0 +1,24 @@
+error[E0308]: mismatched types
+ --> $DIR/similar_paths_primitive.rs:8:9
+ |
+LL | foo(true);
+ | --- ^^^^ expected struct `bool`, found `bool`
+ | |
+ | arguments to this function are incorrect
+ |
+ = note: bool and struct `bool` have similar names, but are actually distinct types
+ = note: bool is a primitive defined by the language
+note: struct `bool` is defined in the current crate
+ --> $DIR/similar_paths_primitive.rs:3:1
+ |
+LL | struct bool;
+ | ^^^^^^^^^^^
+note: function defined here
+ --> $DIR/similar_paths_primitive.rs:5:4
+ |
+LL | fn foo(_: bool) {}
+ | ^^^ -------
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/modules/special_module_name.stderr b/src/test/ui/modules/special_module_name.stderr
index 8b3da2938..bc4b4f1b3 100644
--- a/src/test/ui/modules/special_module_name.stderr
+++ b/src/test/ui/modules/special_module_name.stderr
@@ -20,9 +20,9 @@ warning: found module declaration for lib.rs
LL | mod lib;
| ^^^^^^^^
|
- = note: `#[warn(special_module_name)]` on by default
= note: lib.rs is the root of this crate's library target
= help: to refer to it from other targets, use the library's name as the path
+ = note: `#[warn(special_module_name)]` on by default
warning: found module declaration for main.rs
--> $DIR/special_module_name.rs:4:1
diff --git a/src/test/ui/moves/issue-72649-uninit-in-loop.stderr b/src/test/ui/moves/issue-72649-uninit-in-loop.stderr
index c7373b5be..974994223 100644
--- a/src/test/ui/moves/issue-72649-uninit-in-loop.stderr
+++ b/src/test/ui/moves/issue-72649-uninit-in-loop.stderr
@@ -47,6 +47,11 @@ LL | let value: NonCopy;
| ----- binding declared here but left uninitialized
LL | let _used = value;
| ^^^^^ `value` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let value: NonCopy = todo!();
+ | +++++++++
error[E0381]: used binding `value` isn't initialized
--> $DIR/issue-72649-uninit-in-loop.rs:69:21
@@ -56,6 +61,11 @@ LL | let mut value: NonCopy;
LL | loop {
LL | let _used = value;
| ^^^^^ `value` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let mut value: NonCopy = todo!();
+ | +++++++++
error: aborting due to 6 previous errors
diff --git a/src/test/ui/moves/move-into-dead-array-1.stderr b/src/test/ui/moves/move-into-dead-array-1.stderr
index 344a6bbf0..6db0f0bcb 100644
--- a/src/test/ui/moves/move-into-dead-array-1.stderr
+++ b/src/test/ui/moves/move-into-dead-array-1.stderr
@@ -5,6 +5,11 @@ LL | let mut a: [D; 4];
| ----- binding declared here but left uninitialized
LL | a[i] = d();
| ^^^^ `a` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let mut a: [D; 4] = todo!();
+ | +++++++++
error: aborting due to previous error
diff --git a/src/test/ui/moves/move-of-addr-of-mut.stderr b/src/test/ui/moves/move-of-addr-of-mut.stderr
index e75f2b1c0..ddebaa012 100644
--- a/src/test/ui/moves/move-of-addr-of-mut.stderr
+++ b/src/test/ui/moves/move-of-addr-of-mut.stderr
@@ -7,6 +7,10 @@ LL | std::ptr::addr_of_mut!(x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^ `x` used here but it isn't initialized
|
= note: this error originates in the macro `std::ptr::addr_of_mut` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider assigning a value
+ |
+LL | let mut x: S = todo!();
+ | +++++++++
error: aborting due to previous error
diff --git a/src/test/ui/moves/move-out-of-slice-2.stderr b/src/test/ui/moves/move-out-of-slice-2.stderr
index 93b0dcfc2..46357ce6f 100644
--- a/src/test/ui/moves/move-out-of-slice-2.stderr
+++ b/src/test/ui/moves/move-out-of-slice-2.stderr
@@ -4,8 +4,8 @@ warning: the feature `unsized_locals` is incomplete and may not be safe to use a
LL | #![feature(unsized_locals)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #48055 <https://github.com/rust-lang/rust/issues/48055> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error[E0508]: cannot move out of type `[A]`, a non-copy slice
--> $DIR/move-out-of-slice-2.rs:10:11
diff --git a/src/test/ui/namespace/namespaced-enum-glob-import-no-impls-xcrate.stderr b/src/test/ui/namespace/namespaced-enum-glob-import-no-impls-xcrate.stderr
index f3dbcc2d7..227d30282 100644
--- a/src/test/ui/namespace/namespaced-enum-glob-import-no-impls-xcrate.stderr
+++ b/src/test/ui/namespace/namespaced-enum-glob-import-no-impls-xcrate.stderr
@@ -1,27 +1,27 @@
-error[E0425]: cannot find function `foo` in this scope
- --> $DIR/namespaced-enum-glob-import-no-impls-xcrate.rs:11:5
- |
-LL | foo();
- | ^^^ not found in this scope
-
error[E0425]: cannot find function `foo` in module `m`
--> $DIR/namespaced-enum-glob-import-no-impls-xcrate.rs:12:8
|
LL | m::foo();
| ^^^ not found in `m`
-error[E0425]: cannot find function `bar` in this scope
- --> $DIR/namespaced-enum-glob-import-no-impls-xcrate.rs:13:5
- |
-LL | bar();
- | ^^^ not found in this scope
-
error[E0425]: cannot find function `bar` in module `m`
--> $DIR/namespaced-enum-glob-import-no-impls-xcrate.rs:14:8
|
LL | m::bar();
| ^^^ not found in `m`
+error[E0425]: cannot find function `foo` in this scope
+ --> $DIR/namespaced-enum-glob-import-no-impls-xcrate.rs:11:5
+ |
+LL | foo();
+ | ^^^ not found in this scope
+
+error[E0425]: cannot find function `bar` in this scope
+ --> $DIR/namespaced-enum-glob-import-no-impls-xcrate.rs:13:5
+ |
+LL | bar();
+ | ^^^ not found in this scope
+
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/namespace/namespaced-enum-glob-import-no-impls.stderr b/src/test/ui/namespace/namespaced-enum-glob-import-no-impls.stderr
index 98784de8e..111ac7ab0 100644
--- a/src/test/ui/namespace/namespaced-enum-glob-import-no-impls.stderr
+++ b/src/test/ui/namespace/namespaced-enum-glob-import-no-impls.stderr
@@ -1,27 +1,27 @@
-error[E0425]: cannot find function `foo` in this scope
- --> $DIR/namespaced-enum-glob-import-no-impls.rs:21:5
- |
-LL | foo();
- | ^^^ not found in this scope
-
error[E0425]: cannot find function `foo` in module `m`
--> $DIR/namespaced-enum-glob-import-no-impls.rs:22:8
|
LL | m::foo();
| ^^^ not found in `m`
-error[E0425]: cannot find function `bar` in this scope
- --> $DIR/namespaced-enum-glob-import-no-impls.rs:23:5
- |
-LL | bar();
- | ^^^ not found in this scope
-
error[E0425]: cannot find function `bar` in module `m`
--> $DIR/namespaced-enum-glob-import-no-impls.rs:24:8
|
LL | m::bar();
| ^^^ not found in `m`
+error[E0425]: cannot find function `foo` in this scope
+ --> $DIR/namespaced-enum-glob-import-no-impls.rs:21:5
+ |
+LL | foo();
+ | ^^^ not found in this scope
+
+error[E0425]: cannot find function `bar` in this scope
+ --> $DIR/namespaced-enum-glob-import-no-impls.rs:23:5
+ |
+LL | bar();
+ | ^^^ not found in this scope
+
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/native-library-link-flags/suggest-libname-only-1.rs b/src/test/ui/native-library-link-flags/suggest-libname-only-1.rs
new file mode 100644
index 000000000..abf988a7c
--- /dev/null
+++ b/src/test/ui/native-library-link-flags/suggest-libname-only-1.rs
@@ -0,0 +1,9 @@
+// build-fail
+// compile-flags: --crate-type rlib
+// error-pattern: could not find native static library `libfoo.a`
+// error-pattern: only provide the library name `foo`, not the full filename
+
+#[link(name = "libfoo.a", kind = "static")]
+extern { }
+
+pub fn main() { }
diff --git a/src/test/ui/native-library-link-flags/suggest-libname-only-1.stderr b/src/test/ui/native-library-link-flags/suggest-libname-only-1.stderr
new file mode 100644
index 000000000..64d0a9077
--- /dev/null
+++ b/src/test/ui/native-library-link-flags/suggest-libname-only-1.stderr
@@ -0,0 +1,6 @@
+error: could not find native static library `libfoo.a`, perhaps an -L flag is missing?
+ |
+ = help: only provide the library name `foo`, not the full filename
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/native-library-link-flags/suggest-libname-only-2.rs b/src/test/ui/native-library-link-flags/suggest-libname-only-2.rs
new file mode 100644
index 000000000..dfa70e56d
--- /dev/null
+++ b/src/test/ui/native-library-link-flags/suggest-libname-only-2.rs
@@ -0,0 +1,9 @@
+// build-fail
+// compile-flags: --crate-type rlib
+// error-pattern: could not find native static library `bar.lib`
+// error-pattern: only provide the library name `bar`, not the full filename
+
+#[link(name = "bar.lib", kind = "static")]
+extern { }
+
+pub fn main() { }
diff --git a/src/test/ui/native-library-link-flags/suggest-libname-only-2.stderr b/src/test/ui/native-library-link-flags/suggest-libname-only-2.stderr
new file mode 100644
index 000000000..e166af9ed
--- /dev/null
+++ b/src/test/ui/native-library-link-flags/suggest-libname-only-2.stderr
@@ -0,0 +1,6 @@
+error: could not find native static library `bar.lib`, perhaps an -L flag is missing?
+ |
+ = help: only provide the library name `bar`, not the full filename
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/never_type/issue-52443.rs b/src/test/ui/never_type/issue-52443.rs
index cebcca944..0498a8a16 100644
--- a/src/test/ui/never_type/issue-52443.rs
+++ b/src/test/ui/never_type/issue-52443.rs
@@ -9,6 +9,6 @@ fn main() {
[(); { for _ in 0usize.. {}; 0}];
//~^ ERROR `for` is not allowed in a `const`
//~| ERROR cannot convert
- //~| ERROR mutable references are not allowed in constants
- //~| ERROR cannot call non-const fn
+ //~| ERROR mutable references
+ //~| ERROR cannot call
}
diff --git a/src/test/ui/never_type/issue-52443.stderr b/src/test/ui/never_type/issue-52443.stderr
index 3c0daa4c5..0910e9ad7 100644
--- a/src/test/ui/never_type/issue-52443.stderr
+++ b/src/test/ui/never_type/issue-52443.stderr
@@ -47,8 +47,8 @@ LL | [(); { for _ in 0usize.. {}; 0}];
note: impl defined here, but it is not `const`
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
|
-LL | impl<I: ~const Iterator> const IntoIterator for I {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | impl<I: Iterator> const IntoIterator for I {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error[E0658]: mutable references are not allowed in constants
diff --git a/src/test/ui/issues/issue-5500-1.rs b/src/test/ui/never_type/issue-5500-1.rs
index 98d6e1a14..98d6e1a14 100644
--- a/src/test/ui/issues/issue-5500-1.rs
+++ b/src/test/ui/never_type/issue-5500-1.rs
diff --git a/src/test/ui/nll/closure-malformed-projection-input-issue-102800.rs b/src/test/ui/nll/closure-malformed-projection-input-issue-102800.rs
new file mode 100644
index 000000000..25f47f5b6
--- /dev/null
+++ b/src/test/ui/nll/closure-malformed-projection-input-issue-102800.rs
@@ -0,0 +1,31 @@
+// Regression test for #102800
+//
+// Here we are generating higher-ranked region constraints when normalizing and relating closure
+// input types. Previously this was an ICE in the error path because we didn't register enough
+// diagnostic information to render the higher-ranked subtyping error.
+
+// check-fail
+
+trait Trait {
+ type Ty;
+}
+
+impl Trait for &'static () {
+ type Ty = ();
+}
+
+fn main() {
+ let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {};
+ //~^ ERROR lifetime may not live long enough
+ //~| ERROR higher-ranked subtype error
+ //~| ERROR higher-ranked subtype error
+ //~| ERROR implementation of `Trait` is not general enough
+ //~| ERROR implementation of `Trait` is not general enough
+ //~| ERROR implementation of `Trait` is not general enough
+ //~| ERROR implementation of `Trait` is not general enough
+ //~| ERROR implementation of `Trait` is not general enough
+ //~| ERROR implementation of `Trait` is not general enough
+ //~| ERROR implementation of `Trait` is not general enough
+ //~| ERROR implementation of `Trait` is not general enough
+ //~| ERROR implementation of `Trait` is not general enough
+}
diff --git a/src/test/ui/nll/closure-malformed-projection-input-issue-102800.stderr b/src/test/ui/nll/closure-malformed-projection-input-issue-102800.stderr
new file mode 100644
index 000000000..dbd5dabd1
--- /dev/null
+++ b/src/test/ui/nll/closure-malformed-projection-input-issue-102800.stderr
@@ -0,0 +1,104 @@
+error: lifetime may not live long enough
+ --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48
+ |
+LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {};
+ | ^-^
+ | ||
+ | |has type `<&'1 () as Trait>::Ty`
+ | requires that `'1` must outlive `'static`
+
+error: higher-ranked subtype error
+ --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48
+ |
+LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {};
+ | ^^^
+
+error: higher-ranked subtype error
+ --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48
+ |
+LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {};
+ | ^^^
+
+error: implementation of `Trait` is not general enough
+ --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48
+ |
+LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {};
+ | ^^^^^^ implementation of `Trait` is not general enough
+ |
+ = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`...
+ = note: ...but `Trait` is actually implemented for the type `&'static ()`
+
+error: implementation of `Trait` is not general enough
+ --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:12
+ |
+LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {};
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Trait` is not general enough
+ |
+ = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`...
+ = note: ...but `Trait` is actually implemented for the type `&'static ()`
+
+error: implementation of `Trait` is not general enough
+ --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:12
+ |
+LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {};
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Trait` is not general enough
+ |
+ = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`...
+ = note: ...but `Trait` is actually implemented for the type `&'static ()`
+
+error: implementation of `Trait` is not general enough
+ --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:12
+ |
+LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {};
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Trait` is not general enough
+ |
+ = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`...
+ = note: ...but `Trait` is actually implemented for the type `&'static ()`
+
+error: implementation of `Trait` is not general enough
+ --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:12
+ |
+LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {};
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Trait` is not general enough
+ |
+ = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`...
+ = note: ...but `Trait` is actually implemented for the type `&'static ()`
+
+error: implementation of `Trait` is not general enough
+ --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48
+ |
+LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {};
+ | ^^^^^^ implementation of `Trait` is not general enough
+ |
+ = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`...
+ = note: ...but `Trait` is actually implemented for the type `&'static ()`
+
+error: implementation of `Trait` is not general enough
+ --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48
+ |
+LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {};
+ | ^^^^^^ implementation of `Trait` is not general enough
+ |
+ = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`...
+ = note: ...but `Trait` is actually implemented for the type `&'static ()`
+
+error: implementation of `Trait` is not general enough
+ --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48
+ |
+LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {};
+ | ^^^^^^ implementation of `Trait` is not general enough
+ |
+ = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`...
+ = note: ...but `Trait` is actually implemented for the type `&'static ()`
+
+error: implementation of `Trait` is not general enough
+ --> $DIR/closure-malformed-projection-input-issue-102800.rs:18:48
+ |
+LL | let _: for<'a> fn(<&'a () as Trait>::Ty) = |_| {};
+ | ^^^^^^ implementation of `Trait` is not general enough
+ |
+ = note: `&'0 ()` must implement `Trait`, for any lifetime `'0`...
+ = note: ...but `Trait` is actually implemented for the type `&'static ()`
+
+error: aborting due to 12 previous errors
+
diff --git a/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr b/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr
index 59b848ea8..d2d26b23d 100644
--- a/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr
+++ b/src/test/ui/nll/closure-requirements/escape-argument-callee.stderr
@@ -6,7 +6,7 @@ LL | let mut closure = expect_sig(|p, y| *p = y);
|
= note: defining type: test::{closure#0} with closure substs [
i16,
- for<'r, 's, 't0> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) mut &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) i32, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrNamed('t0) }) i32)),
+ for<'a, 'b, 'c> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) mut &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) i32, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrNamed('c) }) i32)),
(),
]
diff --git a/src/test/ui/nll/closure-requirements/escape-argument.stderr b/src/test/ui/nll/closure-requirements/escape-argument.stderr
index ff4e8e590..6355d3295 100644
--- a/src/test/ui/nll/closure-requirements/escape-argument.stderr
+++ b/src/test/ui/nll/closure-requirements/escape-argument.stderr
@@ -6,7 +6,7 @@ LL | let mut closure = expect_sig(|p, y| *p = y);
|
= note: defining type: test::{closure#0} with closure substs [
i16,
- for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) mut &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) i32, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) i32)),
+ for<'a, 'b> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) mut &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) i32, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) i32)),
(),
]
diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr
index 0d94fca28..5f9724ce3 100644
--- a/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr
+++ b/src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr
@@ -6,7 +6,7 @@ LL | |_outlives1, _outlives2, _outlives3, x, y| {
|
= note: defining type: supply::{closure#0} with closure substs [
i16,
- for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) u32>, std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) &'_#3r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) u32>)),
+ for<'a, 'b> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) u32>, std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) &'_#3r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) u32>)),
(),
]
= note: late-bound region is '_#4r
diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr
index 435a53533..ec728ebd5 100644
--- a/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr
+++ b/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr
@@ -6,7 +6,7 @@ LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y
|
= note: defining type: supply::{closure#0} with closure substs [
i16,
- for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrNamed('t0) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('t1) }) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrNamed('t2) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 5, kind: BrNamed('t3) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('t1) }) u32>)),
+ for<'a, 'b, 'c, 'd, 'e, 'f> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrNamed('c) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('d) }) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrNamed('e) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 5, kind: BrNamed('f) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('d) }) u32>)),
(),
]
= note: late-bound region is '_#3r
diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr
index 6aafbe42c..012933797 100644
--- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr
+++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr
@@ -6,7 +6,7 @@ LL | foo(cell, |cell_a, cell_x| {
|
= note: defining type: case1::{closure#0} with closure substs [
i32,
- for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) u32>)),
+ for<'a> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) u32>)),
(),
]
@@ -36,7 +36,7 @@ LL | foo(cell, |cell_a, cell_x| {
|
= note: defining type: case2::{closure#0} with closure substs [
i32,
- for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) u32>)),
+ for<'a> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) u32>)),
(),
]
= note: number of external vids: 2
diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr
index c95907ea7..ce85b20b3 100644
--- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr
+++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr
@@ -6,7 +6,7 @@ LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
|
= note: defining type: supply::{closure#0} with closure substs [
i16,
- for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrNamed('t0) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('t1) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrNamed('t2) }) u32>)),
+ for<'a, 'b, 'c, 'd, 'e> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrNamed('c) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('d) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrNamed('e) }) u32>)),
(),
]
= note: late-bound region is '_#2r
diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr
index db58d9d6f..20c7967b7 100644
--- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr
+++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr
@@ -6,7 +6,7 @@ LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y
|
= note: defining type: supply::{closure#0} with closure substs [
i16,
- for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrNamed('t0) }) std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('t1) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrNamed('t2) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 5, kind: BrNamed('t3) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('t1) }) u32>)),
+ for<'a, 'b, 'c, 'd, 'e, 'f> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrNamed('c) }) std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('d) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrNamed('e) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 5, kind: BrNamed('f) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('d) }) u32>)),
(),
]
= note: late-bound region is '_#3r
diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr
index be5f1e5ef..f7db5ab1f 100644
--- a/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr
+++ b/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr
@@ -6,7 +6,7 @@ LL | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
|
= note: defining type: test::{closure#0} with closure substs [
i16,
- for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) u32>)),
+ for<'a, 'b> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) u32>)),
(),
]
= note: late-bound region is '_#3r
diff --git a/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr b/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr
index d18db97be..3488edc75 100644
--- a/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr
+++ b/src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr
@@ -6,7 +6,7 @@ LL | |_outlives1, _outlives2, x, y| {
|
= note: defining type: supply::{closure#0} with closure substs [
i16,
- for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) u32>)),
+ for<'a, 'b> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) u32>)),
(),
]
= note: late-bound region is '_#3r
diff --git a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr
index e6f88de4e..0dc2d0de9 100644
--- a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr
+++ b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr
@@ -6,7 +6,7 @@ LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
|
= note: defining type: supply::{closure#0} with closure substs [
i16,
- for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrNamed('t0) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('t1) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrNamed('t2) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) u32>)),
+ for<'a, 'b, 'c, 'd, 'e> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrNamed('c) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('d) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrNamed('e) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) u32>)),
(),
]
= note: late-bound region is '_#2r
diff --git a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr
index 5f5fce771..4c9e026ea 100644
--- a/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr
+++ b/src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr
@@ -6,7 +6,7 @@ LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y
|
= note: defining type: supply::{closure#0} with closure substs [
i16,
- for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrNamed('t0) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('t1) }) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrNamed('t2) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 5, kind: BrNamed('t3) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('t1) }) u32>)),
+ for<'a, 'b, 'c, 'd, 'e, 'f> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 2, kind: BrNamed('c) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('d) }) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 4, kind: BrNamed('e) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) u32>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 5, kind: BrNamed('f) }) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BoundRegion { var: 3, kind: BrNamed('d) }) u32>)),
(),
]
= note: late-bound region is '_#3r
diff --git a/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr b/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr
index da89071ea..68429142e 100644
--- a/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr
+++ b/src/test/ui/nll/closure-requirements/return-wrong-bound-region.stderr
@@ -6,7 +6,7 @@ LL | expect_sig(|a, b| b); // ought to return `a`
|
= note: defining type: test::{closure#0} with closure substs [
i16,
- for<'r, 's> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) i32, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) i32)) -> &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) i32,
+ for<'a, 'b> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) i32, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) i32)) -> &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) i32,
(),
]
diff --git a/src/test/ui/nll/closures-in-loops.stderr b/src/test/ui/nll/closures-in-loops.stderr
index 2be0460df..1c1a31d35 100644
--- a/src/test/ui/nll/closures-in-loops.stderr
+++ b/src/test/ui/nll/closures-in-loops.stderr
@@ -13,17 +13,21 @@ error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/closures-in-loops.rs:13:16
|
LL | v.push(|| x = String::new());
- | ^^ - borrows occur due to use of `x` in closure
- | |
- | `x` was mutably borrowed here in the previous iteration of the loop
+ | -------^^-------------------
+ | | | |
+ | | | borrows occur due to use of `x` in closure
+ | | `x` was mutably borrowed here in the previous iteration of the loop
+ | first borrow used here, in later iteration of loop
error[E0524]: two closures require unique access to `x` at the same time
--> $DIR/closures-in-loops.rs:20:16
|
LL | v.push(|| *x = String::new());
- | ^^ -- borrows occur due to use of `x` in closure
- | |
- | closures are constructed here in different iterations of loop
+ | -------^^--------------------
+ | | | |
+ | | | borrows occur due to use of `x` in closure
+ | | closures are constructed here in different iterations of loop
+ | first borrow used here, in later iteration of loop
error: aborting due to 3 previous errors
diff --git a/src/test/ui/nll/issue-48623-generator.stderr b/src/test/ui/nll/issue-48623-generator.stderr
index 70a83e46f..1b35165db 100644
--- a/src/test/ui/nll/issue-48623-generator.stderr
+++ b/src/test/ui/nll/issue-48623-generator.stderr
@@ -4,8 +4,8 @@ warning: unused generator that must be used
LL | move || { d; yield; &mut *r };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unused_must_use)]` on by default
= note: generators are lazy and do nothing unless resumed
+ = note: `#[warn(unused_must_use)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/nll/issue-51191.stderr b/src/test/ui/nll/issue-51191.stderr
index 9f4e971f9..63ca6ae5c 100644
--- a/src/test/ui/nll/issue-51191.stderr
+++ b/src/test/ui/nll/issue-51191.stderr
@@ -7,8 +7,8 @@ LL | fn bar(self: &mut Self) {
LL | (&mut self).bar();
| ----------------- recursive call site
|
- = note: `#[warn(unconditional_recursion)]` on by default
= help: a `loop` may express intention better if this is on purpose
+ = note: `#[warn(unconditional_recursion)]` on by default
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
--> $DIR/issue-51191.rs:7:9
diff --git a/src/test/ui/nll/issue-57642-higher-ranked-subtype.stderr b/src/test/ui/nll/issue-57642-higher-ranked-subtype.stderr
index 0ae6b7c1d..6e96f40c0 100644
--- a/src/test/ui/nll/issue-57642-higher-ranked-subtype.stderr
+++ b/src/test/ui/nll/issue-57642-higher-ranked-subtype.stderr
@@ -1,11 +1,11 @@
-error[E0599]: the function or associated item `make_g` exists for fn pointer `for<'r> fn(&'r ())`, but its trait bounds were not satisfied
+error[E0599]: the function or associated item `make_g` exists for fn pointer `for<'a> fn(&'a ())`, but its trait bounds were not satisfied
--> $DIR/issue-57642-higher-ranked-subtype.rs:31:25
|
LL | let x = <fn (&())>::make_g();
- | ^^^^^^ function or associated item cannot be called on `for<'r> fn(&'r ())` due to unsatisfied trait bounds
+ | ^^^^^^ function or associated item cannot be called on `for<'a> fn(&'a ())` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
- `for<'r> fn(&'r ()): X`
+ `for<'a> fn(&'a ()): X`
= help: items from traits can only be used if the trait is implemented and in scope
note: `X` defines an item `make_g`, perhaps you need to implement it
--> $DIR/issue-57642-higher-ranked-subtype.rs:4:1
@@ -13,11 +13,11 @@ note: `X` defines an item `make_g`, perhaps you need to implement it
LL | trait X {
| ^^^^^^^
-error[E0599]: no function or associated item named `make_f` found for fn pointer `for<'r> fn(&'r ())` in the current scope
+error[E0599]: no function or associated item named `make_f` found for fn pointer `for<'a> fn(&'a ())` in the current scope
--> $DIR/issue-57642-higher-ranked-subtype.rs:35:25
|
LL | let x = <fn (&())>::make_f();
- | ^^^^^^ function or associated item not found in `for<'r> fn(&'r ())`
+ | ^^^^^^ function or associated item not found in `for<'a> fn(&'a ())`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `Y` defines an item `make_f`, perhaps you need to implement it
diff --git a/src/test/ui/nll/issue-97997.stderr b/src/test/ui/nll/issue-97997.stderr
index 78401bbf6..46440c021 100644
--- a/src/test/ui/nll/issue-97997.stderr
+++ b/src/test/ui/nll/issue-97997.stderr
@@ -4,7 +4,7 @@ error: implementation of `Foo` is not general enough
LL | <fn(&u8) as Foo>::ASSOC;
| ^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
|
- = note: `Foo` would have to be implemented for the type `for<'r> fn(&'r u8)`
+ = note: `Foo` would have to be implemented for the type `for<'a> fn(&'a u8)`
= note: ...but `Foo` is actually implemented for the type `fn(&'0 u8)`, for some specific lifetime `'0`
error: implementation of `Foo` is not general enough
@@ -13,7 +13,7 @@ error: implementation of `Foo` is not general enough
LL | <fn(&u8) as Foo>::ASSOC;
| ^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
|
- = note: `Foo` would have to be implemented for the type `for<'r> fn(&'r u8)`
+ = note: `Foo` would have to be implemented for the type `for<'a> fn(&'a u8)`
= note: ...but `Foo` is actually implemented for the type `fn(&'0 u8)`, for some specific lifetime `'0`
error: aborting due to 2 previous errors
diff --git a/src/test/ui/nll/match-cfg-fake-edges.stderr b/src/test/ui/nll/match-cfg-fake-edges.stderr
index 250aa482e..2d48a9142 100644
--- a/src/test/ui/nll/match-cfg-fake-edges.stderr
+++ b/src/test/ui/nll/match-cfg-fake-edges.stderr
@@ -9,6 +9,11 @@ LL | _ if { x = 2; true } => 1,
LL | _ if {
LL | x;
| ^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x = 0;
+ | +++
error[E0382]: use of moved value: `x`
--> $DIR/match-cfg-fake-edges.rs:35:13
diff --git a/src/test/ui/nll/match-on-borrowed.stderr b/src/test/ui/nll/match-on-borrowed.stderr
index 664f36f69..32666529f 100644
--- a/src/test/ui/nll/match-on-borrowed.stderr
+++ b/src/test/ui/nll/match-on-borrowed.stderr
@@ -40,6 +40,11 @@ LL | let n: Never;
| - binding declared here but left uninitialized
LL | match n {}
| ^ `n` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let n: Never = todo!();
+ | +++++++++
error: aborting due to 4 previous errors
diff --git a/src/test/ui/nll/relate_tys/impl-fn-ignore-binder-via-bottom.stderr b/src/test/ui/nll/relate_tys/impl-fn-ignore-binder-via-bottom.stderr
index 8c4737988..b945ffedd 100644
--- a/src/test/ui/nll/relate_tys/impl-fn-ignore-binder-via-bottom.stderr
+++ b/src/test/ui/nll/relate_tys/impl-fn-ignore-binder-via-bottom.stderr
@@ -4,7 +4,7 @@ error: implementation of `Y` is not general enough
LL | let _x = <fn(&())>::make_f();
| ^^^^^^^^^^^^^^^^^^^ implementation of `Y` is not general enough
|
- = note: `Y` would have to be implemented for the type `for<'r> fn(&'r ())`
+ = note: `Y` would have to be implemented for the type `for<'a> fn(&'a ())`
= note: ...but `Y` is actually implemented for the type `fn(&'0 ())`, for some specific lifetime `'0`
error: implementation of `Y` is not general enough
@@ -13,7 +13,7 @@ error: implementation of `Y` is not general enough
LL | let _x = <fn(&())>::make_f();
| ^^^^^^^^^^^^^^^^^^^ implementation of `Y` is not general enough
|
- = note: `Y` would have to be implemented for the type `for<'r> fn(&'r ())`
+ = note: `Y` would have to be implemented for the type `for<'a> fn(&'a ())`
= note: ...but `Y` is actually implemented for the type `fn(&'0 ())`, for some specific lifetime `'0`
error: implementation of `Y` is not general enough
@@ -22,7 +22,7 @@ error: implementation of `Y` is not general enough
LL | let _x = <fn(&())>::make_f();
| ^^^^^^^^^^^^^^^^^^^ implementation of `Y` is not general enough
|
- = note: `Y` would have to be implemented for the type `for<'r> fn(&'r ())`
+ = note: `Y` would have to be implemented for the type `for<'a> fn(&'a ())`
= note: ...but `Y` is actually implemented for the type `fn(&'0 ())`, for some specific lifetime `'0`
error: aborting due to 3 previous errors
diff --git a/src/test/ui/nll/relate_tys/universe-violation.stderr b/src/test/ui/nll/relate_tys/universe-violation.stderr
index 6f38154e3..fe801b42c 100644
--- a/src/test/ui/nll/relate_tys/universe-violation.stderr
+++ b/src/test/ui/nll/relate_tys/universe-violation.stderr
@@ -4,7 +4,7 @@ error[E0308]: mismatched types
LL | let b: fn(&u32) -> &u32 = a;
| ^ one type is more general than the other
|
- = note: expected fn pointer `for<'r> fn(&'r u32) -> &'r u32`
+ = note: expected fn pointer `for<'a> fn(&'a u32) -> &'a u32`
found fn pointer `fn(&u32) -> &u32`
error: aborting due to previous error
diff --git a/src/test/ui/nll/trait-associated-constant.stderr b/src/test/ui/nll/trait-associated-constant.stderr
index ae0ffd904..cf1c52ba7 100644
--- a/src/test/ui/nll/trait-associated-constant.stderr
+++ b/src/test/ui/nll/trait-associated-constant.stderr
@@ -2,7 +2,7 @@ error[E0308]: const not compatible with trait
--> $DIR/trait-associated-constant.rs:21:5
|
LL | const AC: Option<&'c str> = None;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected enum `Option<&'b str>`
found enum `Option<&'c str>`
diff --git a/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr
index 330c6fafa..737cb3584 100644
--- a/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr
+++ b/src/test/ui/nll/ty-outlives/impl-trait-captures.stderr
@@ -1,14 +1,14 @@
-error[E0700]: hidden type for `Opaque(DefId(0:11 ~ impl_trait_captures[1afc]::foo::{opaque#0}), [ReStatic, T, ReEarlyBound(0, 'a)])` captures lifetime that does not appear in bounds
+error[E0700]: hidden type for `Opaque(DefId(0:13 ~ impl_trait_captures[1afc]::foo::{opaque#0}), [ReStatic, T, ReEarlyBound(0, 'a)])` captures lifetime that does not appear in bounds
--> $DIR/impl-trait-captures.rs:11:5
|
LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> {
- | -- hidden type `&ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_)) T` captures the anonymous lifetime defined here
+ | -- hidden type `&ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[1afc]::foo::'_), '_)) T` captures the anonymous lifetime defined here
LL | x
| ^
|
-help: to declare that the `impl Trait` captures `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_))`, you can add an explicit `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_))` lifetime bound
+help: to declare that `Opaque(DefId(0:13 ~ impl_trait_captures[1afc]::foo::{opaque#0}), [ReEarlyBound(0, 'a), T, ReEarlyBound(2, 'a)])` captures `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[1afc]::foo::'_), '_))`, you can add an explicit `ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[1afc]::foo::'_), '_))` lifetime bound
|
-LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:13 ~ impl_trait_captures[1afc]::foo::'_), '_)) {
+LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReFree(DefId(0:8 ~ impl_trait_captures[1afc]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[1afc]::foo::'_), '_)) {
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
error: aborting due to previous error
diff --git a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr
index 5d9a044d1..61c7d2550 100644
--- a/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr
+++ b/src/test/ui/nll/ty-outlives/ty-param-closure-approximate-lower-bound.stderr
@@ -6,7 +6,7 @@ LL | twice(cell, value, |a, b| invoke(a, b));
|
= note: defining type: generic::<T>::{closure#0} with closure substs [
i16,
- for<'r, 's> extern "rust-call" fn((std::option::Option<std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) ()>>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) T)),
+ for<'a, 'b> extern "rust-call" fn((std::option::Option<std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) ()>>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) T)),
(),
]
= note: number of external vids: 2
@@ -28,7 +28,7 @@ LL | twice(cell, value, |a, b| invoke(a, b));
|
= note: defining type: generic_fail::<T>::{closure#0} with closure substs [
i16,
- for<'r, 's> extern "rust-call" fn((std::option::Option<std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('r) }) ()>>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('s) }) T)),
+ for<'a, 'b> extern "rust-call" fn((std::option::Option<std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed('a) }) ()>>, &ReLateBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed('b) }) T)),
(),
]
= note: late-bound region is '_#2r
diff --git a/src/test/ui/no-patterns-in-args-2.stderr b/src/test/ui/no-patterns-in-args-2.stderr
index 98932349a..6adcbb9dc 100644
--- a/src/test/ui/no-patterns-in-args-2.stderr
+++ b/src/test/ui/no-patterns-in-args-2.stderr
@@ -10,13 +10,13 @@ error: patterns aren't allowed in functions without bodies
LL | fn f1(mut arg: u8);
| ^^^^^^^ help: remove `mut` from the parameter: `arg`
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #35203 <https://github.com/rust-lang/rust/issues/35203>
note: the lint level is defined here
--> $DIR/no-patterns-in-args-2.rs:1:9
|
LL | #![deny(patterns_in_fns_without_body)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #35203 <https://github.com/rust-lang/rust/issues/35203>
error: aborting due to 2 previous errors
diff --git a/src/test/ui/non-fmt-panic.stderr b/src/test/ui/non-fmt-panic.stderr
index 6e4434e6f..162802b7f 100644
--- a/src/test/ui/non-fmt-panic.stderr
+++ b/src/test/ui/non-fmt-panic.stderr
@@ -4,8 +4,8 @@ warning: panic message contains a brace
LL | panic!("here's a brace: {");
| ^
|
- = note: `#[warn(non_fmt_panics)]` on by default
= note: this message is not used as a format string, but will be in Rust 2021
+ = note: `#[warn(non_fmt_panics)]` on by default
help: add a "{}" format string to use the message literally
|
LL | panic!("{}", "here's a brace: {");
diff --git a/src/test/ui/numbers-arithmetic/float-int-invalid-const-cast.rs b/src/test/ui/numbers-arithmetic/float-int-invalid-const-cast.rs
index 769114960..260281d75 100644
--- a/src/test/ui/numbers-arithmetic/float-int-invalid-const-cast.rs
+++ b/src/test/ui/numbers-arithmetic/float-int-invalid-const-cast.rs
@@ -1,7 +1,5 @@
// run-pass
-#![deny(const_err)]
-
// Forces evaluation of constants, triggering hard error
fn force<T>(_: T) {}
diff --git a/src/test/ui/numbers-arithmetic/issue-8460-const.noopt.stderr b/src/test/ui/numbers-arithmetic/issue-8460-const.noopt.stderr
index e2eee1ccd..c4abcb784 100644
--- a/src/test/ui/numbers-arithmetic/issue-8460-const.noopt.stderr
+++ b/src/test/ui/numbers-arithmetic/issue-8460-const.noopt.stderr
@@ -1,5 +1,5 @@
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:13:36
+ --> $DIR/issue-8460-const.rs:11:36
|
LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^^^ attempt to compute `isize::MIN / -1_isize`, which would overflow
@@ -7,139 +7,139 @@ LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err());
= note: `#[deny(unconditional_panic)]` on by default
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:15:36
+ --> $DIR/issue-8460-const.rs:13:36
|
LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^ attempt to compute `i8::MIN / -1_i8`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:17:36
+ --> $DIR/issue-8460-const.rs:15:36
|
LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute `i16::MIN / -1_i16`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:19:36
+ --> $DIR/issue-8460-const.rs:17:36
|
LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute `i32::MIN / -1_i32`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:21:36
+ --> $DIR/issue-8460-const.rs:19:36
|
LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute `i64::MIN / -1_i64`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:23:36
+ --> $DIR/issue-8460-const.rs:21:36
|
LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^^ attempt to compute `i128::MIN / -1_i128`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:25:36
+ --> $DIR/issue-8460-const.rs:23:36
|
LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err());
| ^^^^^^^^^^ attempt to divide `1_isize` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:27:36
+ --> $DIR/issue-8460-const.rs:25:36
|
LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err());
| ^^^^^^^ attempt to divide `1_i8` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:29:36
+ --> $DIR/issue-8460-const.rs:27:36
|
LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err());
| ^^^^^^^^ attempt to divide `1_i16` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:31:36
+ --> $DIR/issue-8460-const.rs:29:36
|
LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err());
| ^^^^^^^^ attempt to divide `1_i32` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:33:36
+ --> $DIR/issue-8460-const.rs:31:36
|
LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err());
| ^^^^^^^^ attempt to divide `1_i64` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:35:36
+ --> $DIR/issue-8460-const.rs:33:36
|
LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err());
| ^^^^^^^^^ attempt to divide `1_i128` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:37:36
+ --> $DIR/issue-8460-const.rs:35:36
|
LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^^^ attempt to compute the remainder of `isize::MIN % -1_isize`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:39:36
+ --> $DIR/issue-8460-const.rs:37:36
|
LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^ attempt to compute the remainder of `i8::MIN % -1_i8`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:41:36
+ --> $DIR/issue-8460-const.rs:39:36
|
LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute the remainder of `i16::MIN % -1_i16`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:43:36
+ --> $DIR/issue-8460-const.rs:41:36
|
LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute the remainder of `i32::MIN % -1_i32`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:45:36
+ --> $DIR/issue-8460-const.rs:43:36
|
LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:47:36
+ --> $DIR/issue-8460-const.rs:45:36
|
LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^^ 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:49:36
+ --> $DIR/issue-8460-const.rs:47:36
|
LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err());
| ^^^^^^^^^^ 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:51:36
+ --> $DIR/issue-8460-const.rs:49:36
|
LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err());
| ^^^^^^^ 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:53:36
+ --> $DIR/issue-8460-const.rs:51:36
|
LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err());
| ^^^^^^^^ 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:55:36
+ --> $DIR/issue-8460-const.rs:53:36
|
LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err());
| ^^^^^^^^ 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:57:36
+ --> $DIR/issue-8460-const.rs:55:36
|
LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err());
| ^^^^^^^^ 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:59:36
+ --> $DIR/issue-8460-const.rs:57:36
|
LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err());
| ^^^^^^^^^ attempt to calculate the remainder of `1_i128` with a divisor of zero
diff --git a/src/test/ui/numbers-arithmetic/issue-8460-const.opt.stderr b/src/test/ui/numbers-arithmetic/issue-8460-const.opt.stderr
index e2eee1ccd..c4abcb784 100644
--- a/src/test/ui/numbers-arithmetic/issue-8460-const.opt.stderr
+++ b/src/test/ui/numbers-arithmetic/issue-8460-const.opt.stderr
@@ -1,5 +1,5 @@
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:13:36
+ --> $DIR/issue-8460-const.rs:11:36
|
LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^^^ attempt to compute `isize::MIN / -1_isize`, which would overflow
@@ -7,139 +7,139 @@ LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err());
= note: `#[deny(unconditional_panic)]` on by default
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:15:36
+ --> $DIR/issue-8460-const.rs:13:36
|
LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^ attempt to compute `i8::MIN / -1_i8`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:17:36
+ --> $DIR/issue-8460-const.rs:15:36
|
LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute `i16::MIN / -1_i16`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:19:36
+ --> $DIR/issue-8460-const.rs:17:36
|
LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute `i32::MIN / -1_i32`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:21:36
+ --> $DIR/issue-8460-const.rs:19:36
|
LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute `i64::MIN / -1_i64`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:23:36
+ --> $DIR/issue-8460-const.rs:21:36
|
LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^^ attempt to compute `i128::MIN / -1_i128`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:25:36
+ --> $DIR/issue-8460-const.rs:23:36
|
LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err());
| ^^^^^^^^^^ attempt to divide `1_isize` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:27:36
+ --> $DIR/issue-8460-const.rs:25:36
|
LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err());
| ^^^^^^^ attempt to divide `1_i8` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:29:36
+ --> $DIR/issue-8460-const.rs:27:36
|
LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err());
| ^^^^^^^^ attempt to divide `1_i16` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:31:36
+ --> $DIR/issue-8460-const.rs:29:36
|
LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err());
| ^^^^^^^^ attempt to divide `1_i32` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:33:36
+ --> $DIR/issue-8460-const.rs:31:36
|
LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err());
| ^^^^^^^^ attempt to divide `1_i64` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:35:36
+ --> $DIR/issue-8460-const.rs:33:36
|
LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err());
| ^^^^^^^^^ attempt to divide `1_i128` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:37:36
+ --> $DIR/issue-8460-const.rs:35:36
|
LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^^^ attempt to compute the remainder of `isize::MIN % -1_isize`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:39:36
+ --> $DIR/issue-8460-const.rs:37:36
|
LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^ attempt to compute the remainder of `i8::MIN % -1_i8`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:41:36
+ --> $DIR/issue-8460-const.rs:39:36
|
LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute the remainder of `i16::MIN % -1_i16`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:43:36
+ --> $DIR/issue-8460-const.rs:41:36
|
LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute the remainder of `i32::MIN % -1_i32`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:45:36
+ --> $DIR/issue-8460-const.rs:43:36
|
LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:47:36
+ --> $DIR/issue-8460-const.rs:45:36
|
LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^^ 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:49:36
+ --> $DIR/issue-8460-const.rs:47:36
|
LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err());
| ^^^^^^^^^^ 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:51:36
+ --> $DIR/issue-8460-const.rs:49:36
|
LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err());
| ^^^^^^^ 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:53:36
+ --> $DIR/issue-8460-const.rs:51:36
|
LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err());
| ^^^^^^^^ 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:55:36
+ --> $DIR/issue-8460-const.rs:53:36
|
LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err());
| ^^^^^^^^ 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:57:36
+ --> $DIR/issue-8460-const.rs:55:36
|
LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err());
| ^^^^^^^^ 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:59:36
+ --> $DIR/issue-8460-const.rs:57:36
|
LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err());
| ^^^^^^^^^ attempt to calculate the remainder of `1_i128` with a divisor of zero
diff --git a/src/test/ui/numbers-arithmetic/issue-8460-const.opt_with_overflow_checks.stderr b/src/test/ui/numbers-arithmetic/issue-8460-const.opt_with_overflow_checks.stderr
index e2eee1ccd..c4abcb784 100644
--- a/src/test/ui/numbers-arithmetic/issue-8460-const.opt_with_overflow_checks.stderr
+++ b/src/test/ui/numbers-arithmetic/issue-8460-const.opt_with_overflow_checks.stderr
@@ -1,5 +1,5 @@
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:13:36
+ --> $DIR/issue-8460-const.rs:11:36
|
LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^^^ attempt to compute `isize::MIN / -1_isize`, which would overflow
@@ -7,139 +7,139 @@ LL | assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err());
= note: `#[deny(unconditional_panic)]` on by default
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:15:36
+ --> $DIR/issue-8460-const.rs:13:36
|
LL | assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^ attempt to compute `i8::MIN / -1_i8`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:17:36
+ --> $DIR/issue-8460-const.rs:15:36
|
LL | assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute `i16::MIN / -1_i16`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:19:36
+ --> $DIR/issue-8460-const.rs:17:36
|
LL | assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute `i32::MIN / -1_i32`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:21:36
+ --> $DIR/issue-8460-const.rs:19:36
|
LL | assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute `i64::MIN / -1_i64`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:23:36
+ --> $DIR/issue-8460-const.rs:21:36
|
LL | assert!(thread::spawn(move|| { i128::MIN / -1; }).join().is_err());
| ^^^^^^^^^^^^^^ attempt to compute `i128::MIN / -1_i128`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:25:36
+ --> $DIR/issue-8460-const.rs:23:36
|
LL | assert!(thread::spawn(move|| { 1isize / 0; }).join().is_err());
| ^^^^^^^^^^ attempt to divide `1_isize` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:27:36
+ --> $DIR/issue-8460-const.rs:25:36
|
LL | assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err());
| ^^^^^^^ attempt to divide `1_i8` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:29:36
+ --> $DIR/issue-8460-const.rs:27:36
|
LL | assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err());
| ^^^^^^^^ attempt to divide `1_i16` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:31:36
+ --> $DIR/issue-8460-const.rs:29:36
|
LL | assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err());
| ^^^^^^^^ attempt to divide `1_i32` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:33:36
+ --> $DIR/issue-8460-const.rs:31:36
|
LL | assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err());
| ^^^^^^^^ attempt to divide `1_i64` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:35:36
+ --> $DIR/issue-8460-const.rs:33:36
|
LL | assert!(thread::spawn(move|| { 1i128 / 0; }).join().is_err());
| ^^^^^^^^^ attempt to divide `1_i128` by zero
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:37:36
+ --> $DIR/issue-8460-const.rs:35:36
|
LL | assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^^^ attempt to compute the remainder of `isize::MIN % -1_isize`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:39:36
+ --> $DIR/issue-8460-const.rs:37:36
|
LL | assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^ attempt to compute the remainder of `i8::MIN % -1_i8`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:41:36
+ --> $DIR/issue-8460-const.rs:39:36
|
LL | assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute the remainder of `i16::MIN % -1_i16`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:43:36
+ --> $DIR/issue-8460-const.rs:41:36
|
LL | assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute the remainder of `i32::MIN % -1_i32`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:45:36
+ --> $DIR/issue-8460-const.rs:43:36
|
LL | assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^ attempt to compute the remainder of `i64::MIN % -1_i64`, which would overflow
error: this operation will panic at runtime
- --> $DIR/issue-8460-const.rs:47:36
+ --> $DIR/issue-8460-const.rs:45:36
|
LL | assert!(thread::spawn(move|| { i128::MIN % -1; }).join().is_err());
| ^^^^^^^^^^^^^^ 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:49:36
+ --> $DIR/issue-8460-const.rs:47:36
|
LL | assert!(thread::spawn(move|| { 1isize % 0; }).join().is_err());
| ^^^^^^^^^^ 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:51:36
+ --> $DIR/issue-8460-const.rs:49:36
|
LL | assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err());
| ^^^^^^^ 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:53:36
+ --> $DIR/issue-8460-const.rs:51:36
|
LL | assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err());
| ^^^^^^^^ 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:55:36
+ --> $DIR/issue-8460-const.rs:53:36
|
LL | assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err());
| ^^^^^^^^ 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:57:36
+ --> $DIR/issue-8460-const.rs:55:36
|
LL | assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err());
| ^^^^^^^^ 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:59:36
+ --> $DIR/issue-8460-const.rs:57:36
|
LL | assert!(thread::spawn(move|| { 1i128 % 0; }).join().is_err());
| ^^^^^^^^^ attempt to calculate the remainder of `1_i128` with a divisor of zero
diff --git a/src/test/ui/numbers-arithmetic/issue-8460-const.rs b/src/test/ui/numbers-arithmetic/issue-8460-const.rs
index 8cad6deb3..02e7567da 100644
--- a/src/test/ui/numbers-arithmetic/issue-8460-const.rs
+++ b/src/test/ui/numbers-arithmetic/issue-8460-const.rs
@@ -5,8 +5,6 @@
// build-fail
-#![deny(const_err)]
-
use std::thread;
fn main() {
diff --git a/src/test/ui/numbers-arithmetic/next-power-of-two-overflow-debug.rs b/src/test/ui/numbers-arithmetic/next-power-of-two-overflow-debug.rs
index f857d4f4c..79d78da33 100644
--- a/src/test/ui/numbers-arithmetic/next-power-of-two-overflow-debug.rs
+++ b/src/test/ui/numbers-arithmetic/next-power-of-two-overflow-debug.rs
@@ -1,7 +1,6 @@
// run-pass
// compile-flags: -C debug_assertions=yes
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
// ignore-emscripten dies with an LLVM error
use std::panic;
diff --git a/src/test/ui/numbers-arithmetic/overflowing-lsh-1.rs b/src/test/ui/numbers-arithmetic/overflowing-lsh-1.rs
index e5ce80336..7f8b0c877 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-lsh-1.rs
+++ b/src/test/ui/numbers-arithmetic/overflowing-lsh-1.rs
@@ -1,7 +1,7 @@
// build-fail
// compile-flags: -C debug-assertions
-#![deny(arithmetic_overflow, const_err)]
+#![deny(arithmetic_overflow)]
fn main() {
let _x = 1_i32 << 32;
diff --git a/src/test/ui/numbers-arithmetic/overflowing-lsh-1.stderr b/src/test/ui/numbers-arithmetic/overflowing-lsh-1.stderr
index 1d029939c..434c9d5b4 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-lsh-1.stderr
+++ b/src/test/ui/numbers-arithmetic/overflowing-lsh-1.stderr
@@ -7,7 +7,7 @@ LL | let _x = 1_i32 << 32;
note: the lint level is defined here
--> $DIR/overflowing-lsh-1.rs:4:9
|
-LL | #![deny(arithmetic_overflow, const_err)]
+LL | #![deny(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/numbers-arithmetic/overflowing-lsh-2.rs b/src/test/ui/numbers-arithmetic/overflowing-lsh-2.rs
index 7fd3407a0..76718ecd1 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-lsh-2.rs
+++ b/src/test/ui/numbers-arithmetic/overflowing-lsh-2.rs
@@ -1,7 +1,7 @@
// build-fail
// compile-flags: -C debug-assertions
-#![deny(arithmetic_overflow, const_err)]
+#![deny(arithmetic_overflow)]
fn main() {
let _x = 1 << -1;
diff --git a/src/test/ui/numbers-arithmetic/overflowing-lsh-2.stderr b/src/test/ui/numbers-arithmetic/overflowing-lsh-2.stderr
index 8598792e0..c3b44e5a0 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-lsh-2.stderr
+++ b/src/test/ui/numbers-arithmetic/overflowing-lsh-2.stderr
@@ -7,7 +7,7 @@ LL | let _x = 1 << -1;
note: the lint level is defined here
--> $DIR/overflowing-lsh-2.rs:4:9
|
-LL | #![deny(arithmetic_overflow, const_err)]
+LL | #![deny(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/numbers-arithmetic/overflowing-lsh-3.rs b/src/test/ui/numbers-arithmetic/overflowing-lsh-3.rs
index e007eb4a2..b2bdd09bf 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-lsh-3.rs
+++ b/src/test/ui/numbers-arithmetic/overflowing-lsh-3.rs
@@ -1,7 +1,7 @@
// build-fail
// compile-flags: -C debug-assertions
-#![deny(arithmetic_overflow, const_err)]
+#![deny(arithmetic_overflow)]
fn main() {
let _x = 1_u64 << 64;
diff --git a/src/test/ui/numbers-arithmetic/overflowing-lsh-3.stderr b/src/test/ui/numbers-arithmetic/overflowing-lsh-3.stderr
index 9c6f806f1..9d6479bd7 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-lsh-3.stderr
+++ b/src/test/ui/numbers-arithmetic/overflowing-lsh-3.stderr
@@ -7,7 +7,7 @@ LL | let _x = 1_u64 << 64;
note: the lint level is defined here
--> $DIR/overflowing-lsh-3.rs:4:9
|
-LL | #![deny(arithmetic_overflow, const_err)]
+LL | #![deny(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/numbers-arithmetic/overflowing-lsh-4.rs b/src/test/ui/numbers-arithmetic/overflowing-lsh-4.rs
index 738d01339..1042bfcb3 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-lsh-4.rs
+++ b/src/test/ui/numbers-arithmetic/overflowing-lsh-4.rs
@@ -4,7 +4,7 @@
// This function is checking that our automatic truncation does not
// sidestep the overflow checking.
-#![deny(arithmetic_overflow, const_err)]
+#![deny(arithmetic_overflow)]
fn main() {
// this signals overflow when checking is on
diff --git a/src/test/ui/numbers-arithmetic/overflowing-lsh-4.stderr b/src/test/ui/numbers-arithmetic/overflowing-lsh-4.stderr
index 08081a0b7..2bb5b6a6d 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-lsh-4.stderr
+++ b/src/test/ui/numbers-arithmetic/overflowing-lsh-4.stderr
@@ -7,7 +7,7 @@ LL | let x = 1_i8 << 17;
note: the lint level is defined here
--> $DIR/overflowing-lsh-4.rs:7:9
|
-LL | #![deny(arithmetic_overflow, const_err)]
+LL | #![deny(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-1.rs b/src/test/ui/numbers-arithmetic/overflowing-rsh-1.rs
index f1488cf85..80593c865 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-rsh-1.rs
+++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-1.rs
@@ -1,7 +1,7 @@
// build-fail
// compile-flags: -C debug-assertions
-#![deny(arithmetic_overflow, const_err)]
+#![deny(arithmetic_overflow)]
fn main() {
let _x = -1_i32 >> 32;
diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-1.stderr b/src/test/ui/numbers-arithmetic/overflowing-rsh-1.stderr
index 4d726fa7f..b2b3114d1 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-rsh-1.stderr
+++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-1.stderr
@@ -7,7 +7,7 @@ LL | let _x = -1_i32 >> 32;
note: the lint level is defined here
--> $DIR/overflowing-rsh-1.rs:4:9
|
-LL | #![deny(arithmetic_overflow, const_err)]
+LL | #![deny(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-2.rs b/src/test/ui/numbers-arithmetic/overflowing-rsh-2.rs
index 39127b970..917352bfc 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-rsh-2.rs
+++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-2.rs
@@ -1,7 +1,7 @@
// build-fail
// compile-flags: -C debug-assertions
-#![deny(arithmetic_overflow, const_err)]
+#![deny(arithmetic_overflow)]
fn main() {
let _x = -1_i32 >> -1;
diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-2.stderr b/src/test/ui/numbers-arithmetic/overflowing-rsh-2.stderr
index 9a8349d5d..ad18c3bb7 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-rsh-2.stderr
+++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-2.stderr
@@ -7,7 +7,7 @@ LL | let _x = -1_i32 >> -1;
note: the lint level is defined here
--> $DIR/overflowing-rsh-2.rs:4:9
|
-LL | #![deny(arithmetic_overflow, const_err)]
+LL | #![deny(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-3.rs b/src/test/ui/numbers-arithmetic/overflowing-rsh-3.rs
index 8ee6dde93..1e052990a 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-rsh-3.rs
+++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-3.rs
@@ -1,7 +1,7 @@
// build-fail
// compile-flags: -C debug-assertions
-#![deny(arithmetic_overflow, const_err)]
+#![deny(arithmetic_overflow)]
fn main() {
let _x = -1_i64 >> 64;
diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-3.stderr b/src/test/ui/numbers-arithmetic/overflowing-rsh-3.stderr
index f48b7ff6d..37d02e09d 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-rsh-3.stderr
+++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-3.stderr
@@ -7,7 +7,7 @@ LL | let _x = -1_i64 >> 64;
note: the lint level is defined here
--> $DIR/overflowing-rsh-3.rs:4:9
|
-LL | #![deny(arithmetic_overflow, const_err)]
+LL | #![deny(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-4.rs b/src/test/ui/numbers-arithmetic/overflowing-rsh-4.rs
index ce7f818e3..be918becd 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-rsh-4.rs
+++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-4.rs
@@ -4,7 +4,7 @@
// This function is checking that our (type-based) automatic
// truncation does not sidestep the overflow checking.
-#![deny(arithmetic_overflow, const_err)]
+#![deny(arithmetic_overflow)]
fn main() {
// this signals overflow when checking is on
diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-4.stderr b/src/test/ui/numbers-arithmetic/overflowing-rsh-4.stderr
index 4816a3899..692602c07 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-rsh-4.stderr
+++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-4.stderr
@@ -7,7 +7,7 @@ LL | let x = 2_i8 >> 17;
note: the lint level is defined here
--> $DIR/overflowing-rsh-4.rs:7:9
|
-LL | #![deny(arithmetic_overflow, const_err)]
+LL | #![deny(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-5.rs b/src/test/ui/numbers-arithmetic/overflowing-rsh-5.rs
index 88928c995..f75e779ed 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-rsh-5.rs
+++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-5.rs
@@ -1,7 +1,7 @@
// build-fail
// compile-flags: -C debug-assertions
-#![deny(arithmetic_overflow, const_err)]
+#![deny(arithmetic_overflow)]
fn main() {
let _n = 1i64 >> [64][0];
diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-5.stderr b/src/test/ui/numbers-arithmetic/overflowing-rsh-5.stderr
index cd36f543d..e3b5859df 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-rsh-5.stderr
+++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-5.stderr
@@ -7,7 +7,7 @@ LL | let _n = 1i64 >> [64][0];
note: the lint level is defined here
--> $DIR/overflowing-rsh-5.rs:4:9
|
-LL | #![deny(arithmetic_overflow, const_err)]
+LL | #![deny(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-6.rs b/src/test/ui/numbers-arithmetic/overflowing-rsh-6.rs
index 88928c995..f75e779ed 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-rsh-6.rs
+++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-6.rs
@@ -1,7 +1,7 @@
// build-fail
// compile-flags: -C debug-assertions
-#![deny(arithmetic_overflow, const_err)]
+#![deny(arithmetic_overflow)]
fn main() {
let _n = 1i64 >> [64][0];
diff --git a/src/test/ui/numbers-arithmetic/overflowing-rsh-6.stderr b/src/test/ui/numbers-arithmetic/overflowing-rsh-6.stderr
index bec8b17df..a3475c04c 100644
--- a/src/test/ui/numbers-arithmetic/overflowing-rsh-6.stderr
+++ b/src/test/ui/numbers-arithmetic/overflowing-rsh-6.stderr
@@ -7,7 +7,7 @@ LL | let _n = 1i64 >> [64][0];
note: the lint level is defined here
--> $DIR/overflowing-rsh-6.rs:4:9
|
-LL | #![deny(arithmetic_overflow, const_err)]
+LL | #![deny(arithmetic_overflow)]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/numbers-arithmetic/promoted_overflow_opt.rs b/src/test/ui/numbers-arithmetic/promoted_overflow_opt.rs
index 4785abbc5..76279e913 100644
--- a/src/test/ui/numbers-arithmetic/promoted_overflow_opt.rs
+++ b/src/test/ui/numbers-arithmetic/promoted_overflow_opt.rs
@@ -1,5 +1,4 @@
// run-pass
-#![allow(const_err)]
// compile-flags: -O
diff --git a/src/test/ui/object-safety/issue-102762.rs b/src/test/ui/object-safety/issue-102762.rs
new file mode 100644
index 000000000..4f4c36345
--- /dev/null
+++ b/src/test/ui/object-safety/issue-102762.rs
@@ -0,0 +1,26 @@
+// compile-flags: --crate-type=lib
+// This test checks that the `where_clauses_object_safety` lint does not cause
+// other object safety *hard errors* to be suppressed, because we currently
+// only emit one object safety error per trait...
+
+use std::future::Future;
+use std::pin::Pin;
+
+pub trait Fetcher: Send + Sync {
+ fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
+ where
+ Self: Sync,
+ {
+ todo!()
+ }
+}
+
+fn fetcher() -> Box<dyn Fetcher> {
+ //~^ ERROR the trait `Fetcher` cannot be made into an object
+ todo!()
+}
+
+pub fn foo() {
+ let fetcher = fetcher();
+ let _ = fetcher.get();
+}
diff --git a/src/test/ui/object-safety/issue-102762.stderr b/src/test/ui/object-safety/issue-102762.stderr
new file mode 100644
index 000000000..5041ebe77
--- /dev/null
+++ b/src/test/ui/object-safety/issue-102762.stderr
@@ -0,0 +1,20 @@
+error[E0038]: the trait `Fetcher` cannot be made into an object
+ --> $DIR/issue-102762.rs:18:21
+ |
+LL | fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
+ | ------------- help: consider changing method `get`'s `self` parameter to be `&self`: `&Self`
+...
+LL | fn fetcher() -> Box<dyn Fetcher> {
+ | ^^^^^^^^^^^ `Fetcher` cannot be made into an object
+ |
+note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/issue-102762.rs:10:22
+ |
+LL | pub trait Fetcher: Send + Sync {
+ | ------- this trait cannot be made into an object...
+LL | fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
+ | ^^^^^^^^^^^^^ ...because method `get`'s `self` parameter cannot be dispatched on
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0038`.
diff --git a/src/test/ui/object-safety/issue-102933.rs b/src/test/ui/object-safety/issue-102933.rs
new file mode 100644
index 000000000..843391cff
--- /dev/null
+++ b/src/test/ui/object-safety/issue-102933.rs
@@ -0,0 +1,25 @@
+// check-pass
+
+use std::future::Future;
+
+pub trait Service {
+ type Response;
+ type Future: Future<Output = Self::Response>;
+}
+
+pub trait A1: Service<Response = i32> {}
+
+pub trait A2: Service<Future = Box<dyn Future<Output = i32>>> + A1 {
+ fn foo(&self) {}
+}
+
+pub trait B1: Service<Future = Box<dyn Future<Output = i32>>> {}
+
+pub trait B2: Service<Response = i32> + B1 {
+ fn foo(&self) {}
+}
+
+fn main() {
+ let x: &dyn A2 = todo!();
+ let x: &dyn B2 = todo!();
+}
diff --git a/src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.rs b/src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.rs
new file mode 100644
index 000000000..14e00d2ef
--- /dev/null
+++ b/src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.rs
@@ -0,0 +1,15 @@
+//~ ERROR the parameter type `Self` may not live long enough
+
+trait GatTrait {
+ type Gat<'a>
+ where
+ Self: 'a;
+}
+
+trait SuperTrait<T>: for<'a> GatTrait<Gat<'a> = T> {
+ fn c(&self) -> dyn SuperTrait<T>;
+ //~^ ERROR associated item referring to unboxed trait object for its own trait
+ //~| ERROR the trait `SuperTrait` cannot be made into an object
+}
+
+fn main() {}
diff --git a/src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.stderr b/src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.stderr
new file mode 100644
index 000000000..c1aaad31e
--- /dev/null
+++ b/src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.stderr
@@ -0,0 +1,43 @@
+error[E0311]: the parameter type `Self` may not live long enough
+ |
+ = help: consider adding an explicit lifetime bound `Self: 'a`...
+ = note: ...so that the type `Self` will meet its required lifetime bounds...
+note: ...that is required by this bound
+ --> $DIR/object-safety-supertrait-mentions-GAT.rs:9:39
+ |
+LL | trait SuperTrait<T>: for<'a> GatTrait<Gat<'a> = T> {
+ | ^^^^^^^^^^^
+
+error: associated item referring to unboxed trait object for its own trait
+ --> $DIR/object-safety-supertrait-mentions-GAT.rs:10:20
+ |
+LL | trait SuperTrait<T>: for<'a> GatTrait<Gat<'a> = T> {
+ | ---------- in this trait
+LL | fn c(&self) -> dyn SuperTrait<T>;
+ | ^^^^^^^^^^^^^^^^^
+ |
+help: you might have meant to use `Self` to refer to the implementing type
+ |
+LL | fn c(&self) -> Self;
+ | ~~~~
+
+error[E0038]: the trait `SuperTrait` cannot be made into an object
+ --> $DIR/object-safety-supertrait-mentions-GAT.rs:10:20
+ |
+LL | fn c(&self) -> dyn SuperTrait<T>;
+ | ^^^^^^^^^^^^^^^^^ `SuperTrait` cannot be made into an object
+ |
+note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/object-safety-supertrait-mentions-GAT.rs:4:10
+ |
+LL | type Gat<'a>
+ | ^^^ ...because it contains the generic associated type `Gat`
+...
+LL | trait SuperTrait<T>: for<'a> GatTrait<Gat<'a> = T> {
+ | ---------- this trait cannot be made into an object...
+ = help: consider moving `Gat` to another trait
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0038, E0311.
+For more information about an error, try `rustc --explain E0038`.
diff --git a/src/test/ui/oom_unwind.rs b/src/test/ui/oom_unwind.rs
index d036c817a..21a8fb2b2 100644
--- a/src/test/ui/oom_unwind.rs
+++ b/src/test/ui/oom_unwind.rs
@@ -4,8 +4,6 @@
// needs-unwind
// only-linux
-#![feature(bench_black_box)]
-
use std::hint::black_box;
use std::mem::forget;
use std::panic::catch_unwind;
diff --git a/src/test/ui/opt-in-copy.stderr b/src/test/ui/opt-in-copy.stderr
index 0a275f1aa..4461567df 100644
--- a/src/test/ui/opt-in-copy.stderr
+++ b/src/test/ui/opt-in-copy.stderr
@@ -1,20 +1,20 @@
error[E0204]: the trait `Copy` may not be implemented for this type
- --> $DIR/opt-in-copy.rs:7:6
+ --> $DIR/opt-in-copy.rs:7:15
|
LL | but_i_cant: CantCopyThis,
| ------------------------ this field does not implement `Copy`
...
LL | impl Copy for IWantToCopyThis {}
- | ^^^^
+ | ^^^^^^^^^^^^^^^
error[E0204]: the trait `Copy` may not be implemented for this type
- --> $DIR/opt-in-copy.rs:19:6
+ --> $DIR/opt-in-copy.rs:19:15
|
LL | ButICant(CantCopyThisEither),
| ------------------ this field does not implement `Copy`
...
LL | impl Copy for IWantToCopyThisToo {}
- | ^^^^
+ | ^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
diff --git a/src/test/ui/packed/issue-27060-rpass.stderr b/src/test/ui/packed/issue-27060-rpass.stderr
index 667b70afb..adf9ae9f5 100644
--- a/src/test/ui/packed/issue-27060-rpass.stderr
+++ b/src/test/ui/packed/issue-27060-rpass.stderr
@@ -5,15 +5,15 @@ warning: reference to packed field is unaligned
LL | let _ = &good.data; // ok
| ^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/issue-27060-rpass.rs:11:9
|
LL | #[allow(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
Future breakage diagnostic:
warning: reference to packed field is unaligned
@@ -22,15 +22,15 @@ warning: reference to packed field is unaligned
LL | let _ = &good.data2[0]; // ok
| ^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/issue-27060-rpass.rs:11:9
|
LL | #[allow(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
Future breakage diagnostic:
warning: reference to packed field is unaligned
@@ -39,15 +39,15 @@ warning: reference to packed field is unaligned
LL | let _ = &good.data;
| ^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/issue-27060-rpass.rs:11:9
|
LL | #[allow(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
Future breakage diagnostic:
warning: reference to packed field is unaligned
@@ -56,13 +56,13 @@ warning: reference to packed field is unaligned
LL | let _ = &good.data2[0];
| ^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/issue-27060-rpass.rs:11:9
|
LL | #[allow(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
diff --git a/src/test/ui/packed/issue-27060.stderr b/src/test/ui/packed/issue-27060.stderr
index 1bab16e6d..85e08fa02 100644
--- a/src/test/ui/packed/issue-27060.stderr
+++ b/src/test/ui/packed/issue-27060.stderr
@@ -4,11 +4,11 @@ error: reference to packed field is unaligned
LL | let _ = &good.data;
| ^^^^^^^^^^
|
- = note: `#[deny(unaligned_references)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
+ = note: `#[deny(unaligned_references)]` on by default
error: reference to packed field is unaligned
--> $DIR/issue-27060.rs:17:13
@@ -52,11 +52,11 @@ error: reference to packed field is unaligned
LL | let _ = &good.data;
| ^^^^^^^^^^
|
- = note: `#[deny(unaligned_references)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
+ = note: `#[deny(unaligned_references)]` on by default
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -65,11 +65,11 @@ error: reference to packed field is unaligned
LL | let _ = &good.data2[0];
| ^^^^^^^^^^^^^^
|
- = note: `#[deny(unaligned_references)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
+ = note: `#[deny(unaligned_references)]` on by default
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -78,11 +78,11 @@ error: reference to packed field is unaligned
LL | let _ = &good.data;
| ^^^^^^^^^^
|
- = note: `#[deny(unaligned_references)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
+ = note: `#[deny(unaligned_references)]` on by default
Future breakage diagnostic:
error: reference to packed field is unaligned
@@ -91,9 +91,9 @@ error: reference to packed field is unaligned
LL | let _ = &good.data2[0];
| ^^^^^^^^^^^^^^
|
- = note: `#[deny(unaligned_references)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
+ = note: `#[deny(unaligned_references)]` on by default
diff --git a/src/test/ui/packed/packed-struct-borrow-element-64bit.stderr b/src/test/ui/packed/packed-struct-borrow-element-64bit.stderr
index dcd1c19fa..fb2f5615c 100644
--- a/src/test/ui/packed/packed-struct-borrow-element-64bit.stderr
+++ b/src/test/ui/packed/packed-struct-borrow-element-64bit.stderr
@@ -4,15 +4,15 @@ warning: reference to packed field is unaligned
LL | let brw = &foo.baz;
| ^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/packed-struct-borrow-element-64bit.rs:12:8
|
LL | #[warn(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
warning: 1 warning emitted
@@ -23,13 +23,13 @@ warning: reference to packed field is unaligned
LL | let brw = &foo.baz;
| ^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/packed-struct-borrow-element-64bit.rs:12:8
|
LL | #[warn(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
diff --git a/src/test/ui/packed/packed-struct-borrow-element.stderr b/src/test/ui/packed/packed-struct-borrow-element.stderr
index fb483227e..75d55c4f6 100644
--- a/src/test/ui/packed/packed-struct-borrow-element.stderr
+++ b/src/test/ui/packed/packed-struct-borrow-element.stderr
@@ -4,15 +4,15 @@ warning: reference to packed field is unaligned
LL | let brw = &foo.baz;
| ^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/packed-struct-borrow-element.rs:23:8
|
LL | #[warn(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
warning: reference to packed field is unaligned
--> $DIR/packed-struct-borrow-element.rs:31:15
@@ -34,15 +34,15 @@ warning: reference to packed field is unaligned
LL | let brw = &foo.baz;
| ^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/packed-struct-borrow-element.rs:23:8
|
LL | #[warn(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
Future breakage diagnostic:
warning: reference to packed field is unaligned
@@ -51,13 +51,13 @@ warning: reference to packed field is unaligned
LL | let brw = &foo.baz;
| ^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
+ = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
+ = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
note: the lint level is defined here
--> $DIR/packed-struct-borrow-element.rs:23:8
|
LL | #[warn(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
- = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
diff --git a/src/test/ui/panic-handler/weak-lang-item.rs b/src/test/ui/panic-handler/weak-lang-item.rs
index df31e614c..14a07a9ef 100644
--- a/src/test/ui/panic-handler/weak-lang-item.rs
+++ b/src/test/ui/panic-handler/weak-lang-item.rs
@@ -2,7 +2,7 @@
// error-pattern: `#[panic_handler]` function required, but not found
// error-pattern: language item required, but not found: `eh_personality`
// needs-unwind since it affects the error output
-// ignore-emscripten compiled with panic=abort, personality not required
+// ignore-emscripten missing eh_catch_typeinfo lang item
#![no_std]
diff --git a/src/test/ui/panic-runtime/need-abort-got-unwind.rs b/src/test/ui/panic-runtime/need-abort-got-unwind.rs
index c72fb96e3..e92400931 100644
--- a/src/test/ui/panic-runtime/need-abort-got-unwind.rs
+++ b/src/test/ui/panic-runtime/need-abort-got-unwind.rs
@@ -2,7 +2,6 @@
// needs-unwind
// error-pattern:is incompatible with this crate's strategy of `unwind`
// aux-build:needs-abort.rs
-// ignore-wasm32-bare compiled with panic=abort by default
extern crate needs_abort;
diff --git a/src/test/ui/panic-runtime/transitive-link-a-bunch.rs b/src/test/ui/panic-runtime/transitive-link-a-bunch.rs
index 622535a75..0e74e300f 100644
--- a/src/test/ui/panic-runtime/transitive-link-a-bunch.rs
+++ b/src/test/ui/panic-runtime/transitive-link-a-bunch.rs
@@ -6,7 +6,6 @@
// aux-build:wants-panic-runtime-abort.rs
// aux-build:panic-runtime-lang-items.rs
// error-pattern: is not compiled with this crate's panic strategy `unwind`
-// ignore-wasm32-bare compiled with panic=abort by default
#![no_std]
#![no_main]
diff --git a/src/test/ui/panic-runtime/want-unwind-got-abort.rs b/src/test/ui/panic-runtime/want-unwind-got-abort.rs
index 23bfea6af..b6174dc4e 100644
--- a/src/test/ui/panic-runtime/want-unwind-got-abort.rs
+++ b/src/test/ui/panic-runtime/want-unwind-got-abort.rs
@@ -3,7 +3,6 @@
// error-pattern:is not compiled with this crate's panic strategy `unwind`
// aux-build:panic-runtime-abort.rs
// aux-build:panic-runtime-lang-items.rs
-// ignore-wasm32-bare compiled with panic=abort by default
#![no_std]
#![no_main]
diff --git a/src/test/ui/panic-runtime/want-unwind-got-abort2.rs b/src/test/ui/panic-runtime/want-unwind-got-abort2.rs
index 7a2e48e2f..b54babbef 100644
--- a/src/test/ui/panic-runtime/want-unwind-got-abort2.rs
+++ b/src/test/ui/panic-runtime/want-unwind-got-abort2.rs
@@ -4,7 +4,6 @@
// aux-build:panic-runtime-abort.rs
// aux-build:wants-panic-runtime-abort.rs
// aux-build:panic-runtime-lang-items.rs
-// ignore-wasm32-bare compiled with panic=abort by default
#![no_std]
#![no_main]
diff --git a/src/test/ui/panic-while-printing.rs b/src/test/ui/panic-while-printing.rs
index 098f54ac2..3abedf2a7 100644
--- a/src/test/ui/panic-while-printing.rs
+++ b/src/test/ui/panic-while-printing.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-emscripten no subprocess support
#![feature(internal_output_capture)]
diff --git a/src/test/ui/panics/issue-47429-short-backtraces.legacy.run.stderr b/src/test/ui/panics/issue-47429-short-backtraces.legacy.run.stderr
index b6223b937..ac4ed8225 100644
--- a/src/test/ui/panics/issue-47429-short-backtraces.legacy.run.stderr
+++ b/src/test/ui/panics/issue-47429-short-backtraces.legacy.run.stderr
@@ -1,4 +1,4 @@
-thread 'main' panicked at 'explicit panic', $DIR/issue-47429-short-backtraces.rs:22:5
+thread 'main' panicked at 'explicit panic', $DIR/issue-47429-short-backtraces.rs:23:5
stack backtrace:
0: std::panicking::begin_panic
1: issue_47429_short_backtraces::main
diff --git a/src/test/ui/panics/issue-47429-short-backtraces.rs b/src/test/ui/panics/issue-47429-short-backtraces.rs
index f338ace6b..58d0fa62c 100644
--- a/src/test/ui/panics/issue-47429-short-backtraces.rs
+++ b/src/test/ui/panics/issue-47429-short-backtraces.rs
@@ -12,6 +12,7 @@
// ignore-wasm no panic or subprocess support
// ignore-emscripten no panic or subprocess support
// ignore-sgx no subprocess support
+// ignore-fuchsia Backtraces not symbolized
// NOTE(eddyb) output differs between symbol mangling schemes
// revisions: legacy v0
diff --git a/src/test/ui/panics/issue-47429-short-backtraces.v0.run.stderr b/src/test/ui/panics/issue-47429-short-backtraces.v0.run.stderr
index c2bea4492..65401fe1c 100644
--- a/src/test/ui/panics/issue-47429-short-backtraces.v0.run.stderr
+++ b/src/test/ui/panics/issue-47429-short-backtraces.v0.run.stderr
@@ -1,4 +1,4 @@
-thread 'main' panicked at 'explicit panic', $DIR/issue-47429-short-backtraces.rs:22:5
+thread 'main' panicked at 'explicit panic', $DIR/issue-47429-short-backtraces.rs:23:5
stack backtrace:
0: std::panicking::begin_panic::<&str>
1: issue_47429_short_backtraces::main
diff --git a/src/test/ui/panics/runtime-switch.legacy.run.stderr b/src/test/ui/panics/runtime-switch.legacy.run.stderr
index f282f1883..0f7655163 100644
--- a/src/test/ui/panics/runtime-switch.legacy.run.stderr
+++ b/src/test/ui/panics/runtime-switch.legacy.run.stderr
@@ -1,4 +1,4 @@
-thread 'main' panicked at 'explicit panic', $DIR/runtime-switch.rs:25:5
+thread 'main' panicked at 'explicit panic', $DIR/runtime-switch.rs:26:5
stack backtrace:
0: std::panicking::begin_panic
1: runtime_switch::main
diff --git a/src/test/ui/panics/runtime-switch.rs b/src/test/ui/panics/runtime-switch.rs
index 37ef961e2..882340e49 100644
--- a/src/test/ui/panics/runtime-switch.rs
+++ b/src/test/ui/panics/runtime-switch.rs
@@ -12,6 +12,7 @@
// ignore-wasm no panic or subprocess support
// ignore-emscripten no panic or subprocess support
// ignore-sgx no subprocess support
+// ignore-fuchsia Backtrace not symbolized
// NOTE(eddyb) output differs between symbol mangling schemes
// revisions: legacy v0
diff --git a/src/test/ui/panics/runtime-switch.v0.run.stderr b/src/test/ui/panics/runtime-switch.v0.run.stderr
index 7ce9722e5..a4ae44131 100644
--- a/src/test/ui/panics/runtime-switch.v0.run.stderr
+++ b/src/test/ui/panics/runtime-switch.v0.run.stderr
@@ -1,4 +1,4 @@
-thread 'main' panicked at 'explicit panic', $DIR/runtime-switch.rs:25:5
+thread 'main' panicked at 'explicit panic', $DIR/runtime-switch.rs:26:5
stack backtrace:
0: std::panicking::begin_panic::<&str>
1: runtime_switch::main
diff --git a/src/test/ui/parser/assoc-static-semantic-fail.stderr b/src/test/ui/parser/assoc-static-semantic-fail.stderr
index 7ae092cee..8a74f49b9 100644
--- a/src/test/ui/parser/assoc-static-semantic-fail.stderr
+++ b/src/test/ui/parser/assoc-static-semantic-fail.stderr
@@ -168,9 +168,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error: aborting due to 24 previous errors; 1 warning emitted
diff --git a/src/test/ui/parser/attr-stmt-expr-attr-bad.rs b/src/test/ui/parser/attr-stmt-expr-attr-bad.rs
index 09f494bdc..469c3855c 100644
--- a/src/test/ui/parser/attr-stmt-expr-attr-bad.rs
+++ b/src/test/ui/parser/attr-stmt-expr-attr-bad.rs
@@ -1,5 +1,3 @@
-#![feature(half_open_range_patterns)]
-
fn main() {}
#[cfg(FALSE)] fn e() { let _ = box #![attr] 0; }
diff --git a/src/test/ui/parser/attr-stmt-expr-attr-bad.stderr b/src/test/ui/parser/attr-stmt-expr-attr-bad.stderr
index 7bb3db030..872c560cb 100644
--- a/src/test/ui/parser/attr-stmt-expr-attr-bad.stderr
+++ b/src/test/ui/parser/attr-stmt-expr-attr-bad.stderr
@@ -1,5 +1,5 @@
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:5:36
+ --> $DIR/attr-stmt-expr-attr-bad.rs:3:36
|
LL | #[cfg(FALSE)] fn e() { let _ = box #![attr] 0; }
| ^^^^^^^^
@@ -8,19 +8,19 @@ LL | #[cfg(FALSE)] fn e() { let _ = box #![attr] 0; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: expected expression, found `]`
- --> $DIR/attr-stmt-expr-attr-bad.rs:7:40
+ --> $DIR/attr-stmt-expr-attr-bad.rs:5:40
|
LL | #[cfg(FALSE)] fn e() { let _ = [#[attr]]; }
| ^ expected expression
error: expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `#`
- --> $DIR/attr-stmt-expr-attr-bad.rs:9:35
+ --> $DIR/attr-stmt-expr-attr-bad.rs:7:35
|
LL | #[cfg(FALSE)] fn e() { let _ = foo#[attr](); }
| ^ expected one of 8 possible tokens
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:11:36
+ --> $DIR/attr-stmt-expr-attr-bad.rs:9:36
|
LL | #[cfg(FALSE)] fn e() { let _ = foo(#![attr]); }
| ^^^^^^^^
@@ -29,13 +29,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = foo(#![attr]); }
= note: outer attributes, like `#[test]`, annotate the item following them
error: expected expression, found `)`
- --> $DIR/attr-stmt-expr-attr-bad.rs:11:44
+ --> $DIR/attr-stmt-expr-attr-bad.rs:9:44
|
LL | #[cfg(FALSE)] fn e() { let _ = foo(#![attr]); }
| ^ expected expression
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:14:38
+ --> $DIR/attr-stmt-expr-attr-bad.rs:12:38
|
LL | #[cfg(FALSE)] fn e() { let _ = x.foo(#![attr]); }
| ^^^^^^^^
@@ -44,13 +44,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = x.foo(#![attr]); }
= note: outer attributes, like `#[test]`, annotate the item following them
error: expected expression, found `)`
- --> $DIR/attr-stmt-expr-attr-bad.rs:14:46
+ --> $DIR/attr-stmt-expr-attr-bad.rs:12:46
|
LL | #[cfg(FALSE)] fn e() { let _ = x.foo(#![attr]); }
| ^ expected expression
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:17:36
+ --> $DIR/attr-stmt-expr-attr-bad.rs:15:36
|
LL | #[cfg(FALSE)] fn e() { let _ = 0 + #![attr] 0; }
| ^^^^^^^^
@@ -59,7 +59,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = 0 + #![attr] 0; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:19:33
+ --> $DIR/attr-stmt-expr-attr-bad.rs:17:33
|
LL | #[cfg(FALSE)] fn e() { let _ = !#![attr] 0; }
| ^^^^^^^^
@@ -68,7 +68,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = !#![attr] 0; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:21:33
+ --> $DIR/attr-stmt-expr-attr-bad.rs:19:33
|
LL | #[cfg(FALSE)] fn e() { let _ = -#![attr] 0; }
| ^^^^^^^^
@@ -77,13 +77,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = -#![attr] 0; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `#`
- --> $DIR/attr-stmt-expr-attr-bad.rs:23:34
+ --> $DIR/attr-stmt-expr-attr-bad.rs:21:34
|
LL | #[cfg(FALSE)] fn e() { let _ = x #![attr] as Y; }
| ^ expected one of 8 possible tokens
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:25:35
+ --> $DIR/attr-stmt-expr-attr-bad.rs:23:35
|
LL | #[cfg(FALSE)] fn e() { let _ = || #![attr] foo; }
| ^^^^^^^^
@@ -92,7 +92,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = || #![attr] foo; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:27:40
+ --> $DIR/attr-stmt-expr-attr-bad.rs:25:40
|
LL | #[cfg(FALSE)] fn e() { let _ = move || #![attr] foo; }
| ^^^^^^^^
@@ -101,7 +101,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = move || #![attr] foo; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:29:35
+ --> $DIR/attr-stmt-expr-attr-bad.rs:27:35
|
LL | #[cfg(FALSE)] fn e() { let _ = || #![attr] {foo}; }
| ^^^^^^^^
@@ -110,7 +110,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = || #![attr] {foo}; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:31:40
+ --> $DIR/attr-stmt-expr-attr-bad.rs:29:40
|
LL | #[cfg(FALSE)] fn e() { let _ = move || #![attr] {foo}; }
| ^^^^^^^^
@@ -119,19 +119,19 @@ LL | #[cfg(FALSE)] fn e() { let _ = move || #![attr] {foo}; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: expected expression, found `..`
- --> $DIR/attr-stmt-expr-attr-bad.rs:33:40
+ --> $DIR/attr-stmt-expr-attr-bad.rs:31:40
|
LL | #[cfg(FALSE)] fn e() { let _ = #[attr] ..#[attr] 0; }
| ^^ expected expression
error: expected expression, found `..`
- --> $DIR/attr-stmt-expr-attr-bad.rs:35:40
+ --> $DIR/attr-stmt-expr-attr-bad.rs:33:40
|
LL | #[cfg(FALSE)] fn e() { let _ = #[attr] ..; }
| ^^ expected expression
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:37:41
+ --> $DIR/attr-stmt-expr-attr-bad.rs:35:41
|
LL | #[cfg(FALSE)] fn e() { let _ = #[attr] &#![attr] 0; }
| ^^^^^^^^
@@ -140,7 +140,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = #[attr] &#![attr] 0; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:39:45
+ --> $DIR/attr-stmt-expr-attr-bad.rs:37:45
|
LL | #[cfg(FALSE)] fn e() { let _ = #[attr] &mut #![attr] 0; }
| ^^^^^^^^
@@ -149,7 +149,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = #[attr] &mut #![attr] 0; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: outer attributes are not allowed on `if` and `else` branches
- --> $DIR/attr-stmt-expr-attr-bad.rs:41:37
+ --> $DIR/attr-stmt-expr-attr-bad.rs:39:37
|
LL | #[cfg(FALSE)] fn e() { let _ = if 0 #[attr] {}; }
| -- ^^^^^^^ -- the attributes are attached to this branch
@@ -158,7 +158,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 #[attr] {}; }
| the branch belongs to this `if`
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:43:38
+ --> $DIR/attr-stmt-expr-attr-bad.rs:41:38
|
LL | #[cfg(FALSE)] fn e() { let _ = if 0 {#![attr]}; }
| ^^^^^^^^
@@ -167,13 +167,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 {#![attr]}; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `#`
- --> $DIR/attr-stmt-expr-attr-bad.rs:45:40
+ --> $DIR/attr-stmt-expr-attr-bad.rs:43:40
|
LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} #[attr] else {}; }
| ^ expected one of `.`, `;`, `?`, `else`, or an operator
error: outer attributes are not allowed on `if` and `else` branches
- --> $DIR/attr-stmt-expr-attr-bad.rs:47:45
+ --> $DIR/attr-stmt-expr-attr-bad.rs:45:45
|
LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else #[attr] {}; }
| ---- ^^^^^^^ -- the attributes are attached to this branch
@@ -182,7 +182,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else #[attr] {}; }
| the branch belongs to this `else`
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:49:46
+ --> $DIR/attr-stmt-expr-attr-bad.rs:47:46
|
LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else {#![attr]}; }
| ^^^^^^^^
@@ -191,7 +191,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else {#![attr]}; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: outer attributes are not allowed on `if` and `else` branches
- --> $DIR/attr-stmt-expr-attr-bad.rs:51:45
+ --> $DIR/attr-stmt-expr-attr-bad.rs:49:45
|
LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else #[attr] if 0 {}; }
| ---- ^^^^^^^ ------- the attributes are attached to this branch
@@ -200,7 +200,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else #[attr] if 0 {}; }
| the branch belongs to this `else`
error: outer attributes are not allowed on `if` and `else` branches
- --> $DIR/attr-stmt-expr-attr-bad.rs:53:50
+ --> $DIR/attr-stmt-expr-attr-bad.rs:51:50
|
LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else if 0 #[attr] {}; }
| -- ^^^^^^^ -- the attributes are attached to this branch
@@ -209,7 +209,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else if 0 #[attr] {}; }
| the branch belongs to this `if`
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:55:51
+ --> $DIR/attr-stmt-expr-attr-bad.rs:53:51
|
LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else if 0 {#![attr]}; }
| ^^^^^^^^
@@ -218,7 +218,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if 0 {} else if 0 {#![attr]}; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: outer attributes are not allowed on `if` and `else` branches
- --> $DIR/attr-stmt-expr-attr-bad.rs:57:45
+ --> $DIR/attr-stmt-expr-attr-bad.rs:55:45
|
LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 #[attr] {}; }
| -- ^^^^^^^ -- the attributes are attached to this branch
@@ -227,7 +227,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 #[attr] {}; }
| the branch belongs to this `if`
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:59:46
+ --> $DIR/attr-stmt-expr-attr-bad.rs:57:46
|
LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {#![attr]}; }
| ^^^^^^^^
@@ -236,13 +236,13 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {#![attr]}; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `#`
- --> $DIR/attr-stmt-expr-attr-bad.rs:61:48
+ --> $DIR/attr-stmt-expr-attr-bad.rs:59:48
|
LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} #[attr] else {}; }
| ^ expected one of `.`, `;`, `?`, `else`, or an operator
error: outer attributes are not allowed on `if` and `else` branches
- --> $DIR/attr-stmt-expr-attr-bad.rs:63:53
+ --> $DIR/attr-stmt-expr-attr-bad.rs:61:53
|
LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else #[attr] {}; }
| ---- ^^^^^^^ -- the attributes are attached to this branch
@@ -251,7 +251,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else #[attr] {}; }
| the branch belongs to this `else`
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:65:54
+ --> $DIR/attr-stmt-expr-attr-bad.rs:63:54
|
LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else {#![attr]}; }
| ^^^^^^^^
@@ -260,7 +260,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else {#![attr]}; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: outer attributes are not allowed on `if` and `else` branches
- --> $DIR/attr-stmt-expr-attr-bad.rs:67:53
+ --> $DIR/attr-stmt-expr-attr-bad.rs:65:53
|
LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else #[attr] if let _ = 0 {}; }
| ---- ^^^^^^^ --------------- the attributes are attached to this branch
@@ -269,7 +269,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else #[attr] if let _ = 0 {}
| the branch belongs to this `else`
error: outer attributes are not allowed on `if` and `else` branches
- --> $DIR/attr-stmt-expr-attr-bad.rs:69:66
+ --> $DIR/attr-stmt-expr-attr-bad.rs:67:66
|
LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else if let _ = 0 #[attr] {}; }
| -- ^^^^^^^ -- the attributes are attached to this branch
@@ -278,7 +278,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else if let _ = 0 #[attr] {}
| the branch belongs to this `if`
error: an inner attribute is not permitted in this context
- --> $DIR/attr-stmt-expr-attr-bad.rs:71:67
+ --> $DIR/attr-stmt-expr-attr-bad.rs:69:67
|
LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else if let _ = 0 {#![attr]}; }
| ^^^^^^^^
@@ -287,7 +287,7 @@ LL | #[cfg(FALSE)] fn e() { let _ = if let _ = 0 {} else if let _ = 0 {#![attr]}
= note: outer attributes, like `#[test]`, annotate the item following them
error: an inner attribute is not permitted following an outer attribute
- --> $DIR/attr-stmt-expr-attr-bad.rs:74:32
+ --> $DIR/attr-stmt-expr-attr-bad.rs:72:32
|
LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] let _ = 0; }
| ------- ^^^^^^^^ not permitted following an outer attribute
@@ -298,7 +298,7 @@ LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] let _ = 0; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: an inner attribute is not permitted following an outer attribute
- --> $DIR/attr-stmt-expr-attr-bad.rs:76:32
+ --> $DIR/attr-stmt-expr-attr-bad.rs:74:32
|
LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] 0; }
| ------- ^^^^^^^^ not permitted following an outer attribute
@@ -309,7 +309,7 @@ LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] 0; }
= note: outer attributes, like `#[test]`, annotate the item following them
error: an inner attribute is not permitted following an outer attribute
- --> $DIR/attr-stmt-expr-attr-bad.rs:78:32
+ --> $DIR/attr-stmt-expr-attr-bad.rs:76:32
|
LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] foo!(); }
| ------- ^^^^^^^^ ------- the inner attribute doesn't annotate this item macro invocation
@@ -325,7 +325,7 @@ LL + #[cfg(FALSE)] fn s() { #[attr] #[attr] foo!(); }
|
error: an inner attribute is not permitted following an outer attribute
- --> $DIR/attr-stmt-expr-attr-bad.rs:80:32
+ --> $DIR/attr-stmt-expr-attr-bad.rs:78:32
|
LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] foo![]; }
| ------- ^^^^^^^^ ------- the inner attribute doesn't annotate this item macro invocation
@@ -341,7 +341,7 @@ LL + #[cfg(FALSE)] fn s() { #[attr] #[attr] foo![]; }
|
error: an inner attribute is not permitted following an outer attribute
- --> $DIR/attr-stmt-expr-attr-bad.rs:82:32
+ --> $DIR/attr-stmt-expr-attr-bad.rs:80:32
|
LL | #[cfg(FALSE)] fn s() { #[attr] #![attr] foo!{}; }
| ------- ^^^^^^^^ ------ the inner attribute doesn't annotate this item macro invocation
@@ -357,7 +357,7 @@ LL + #[cfg(FALSE)] fn s() { #[attr] #[attr] foo!{}; }
|
error[E0586]: inclusive range with no end
- --> $DIR/attr-stmt-expr-attr-bad.rs:88:35
+ --> $DIR/attr-stmt-expr-attr-bad.rs:86:35
|
LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] 10 => () } }
| ^^^ help: use `..` instead
@@ -365,13 +365,13 @@ LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] 10 => () } }
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error: expected one of `=>`, `if`, or `|`, found `#`
- --> $DIR/attr-stmt-expr-attr-bad.rs:88:38
+ --> $DIR/attr-stmt-expr-attr-bad.rs:86:38
|
LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] 10 => () } }
| ^ expected one of `=>`, `if`, or `|`
error[E0586]: inclusive range with no end
- --> $DIR/attr-stmt-expr-attr-bad.rs:91:35
+ --> $DIR/attr-stmt-expr-attr-bad.rs:89:35
|
LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] -10 => () } }
| ^^^ help: use `..` instead
@@ -379,19 +379,19 @@ LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] -10 => () } }
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error: expected one of `=>`, `if`, or `|`, found `#`
- --> $DIR/attr-stmt-expr-attr-bad.rs:91:38
+ --> $DIR/attr-stmt-expr-attr-bad.rs:89:38
|
LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] -10 => () } }
| ^ expected one of `=>`, `if`, or `|`
error: unexpected token: `#`
- --> $DIR/attr-stmt-expr-attr-bad.rs:94:39
+ --> $DIR/attr-stmt-expr-attr-bad.rs:92:39
|
LL | #[cfg(FALSE)] fn e() { match 0 { 0..=-#[attr] 10 => () } }
| ^
error[E0586]: inclusive range with no end
- --> $DIR/attr-stmt-expr-attr-bad.rs:96:35
+ --> $DIR/attr-stmt-expr-attr-bad.rs:94:35
|
LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] FOO => () } }
| ^^^ help: use `..` instead
@@ -399,43 +399,43 @@ LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] FOO => () } }
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error: expected one of `=>`, `if`, or `|`, found `#`
- --> $DIR/attr-stmt-expr-attr-bad.rs:96:38
+ --> $DIR/attr-stmt-expr-attr-bad.rs:94:38
|
LL | #[cfg(FALSE)] fn e() { match 0 { 0..=#[attr] FOO => () } }
| ^ expected one of `=>`, `if`, or `|`
error: unexpected token: `#`
- --> $DIR/attr-stmt-expr-attr-bad.rs:100:34
+ --> $DIR/attr-stmt-expr-attr-bad.rs:98:34
|
LL | #[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); }
| ^
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `#`
- --> $DIR/attr-stmt-expr-attr-bad.rs:100:34
+ --> $DIR/attr-stmt-expr-attr-bad.rs:98:34
|
LL | #[cfg(FALSE)] fn e() { let _ = x.#![attr]foo(); }
| ^ expected one of `.`, `;`, `?`, `else`, or an operator
error: unexpected token: `#`
- --> $DIR/attr-stmt-expr-attr-bad.rs:103:34
+ --> $DIR/attr-stmt-expr-attr-bad.rs:101:34
|
LL | #[cfg(FALSE)] fn e() { let _ = x.#[attr]foo(); }
| ^
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `#`
- --> $DIR/attr-stmt-expr-attr-bad.rs:103:34
+ --> $DIR/attr-stmt-expr-attr-bad.rs:101:34
|
LL | #[cfg(FALSE)] fn e() { let _ = x.#[attr]foo(); }
| ^ expected one of `.`, `;`, `?`, `else`, or an operator
error: expected statement after outer attribute
- --> $DIR/attr-stmt-expr-attr-bad.rs:108:37
+ --> $DIR/attr-stmt-expr-attr-bad.rs:106:37
|
LL | #[cfg(FALSE)] fn e() { { fn foo() { #[attr]; } } }
| ^^^^^^^
error: expected statement after outer attribute
- --> $DIR/attr-stmt-expr-attr-bad.rs:110:37
+ --> $DIR/attr-stmt-expr-attr-bad.rs:108:37
|
LL | #[cfg(FALSE)] fn e() { { fn foo() { #[attr] } } }
| ^^^^^^^
diff --git a/src/test/ui/parser/bad-let-as-field.rs b/src/test/ui/parser/bad-let-as-field.rs
new file mode 100644
index 000000000..fec2bc256
--- /dev/null
+++ b/src/test/ui/parser/bad-let-as-field.rs
@@ -0,0 +1,6 @@
+struct Foo {
+ let: i32,
+ //~^ ERROR expected identifier, found keyword
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/bad-let-as-field.stderr b/src/test/ui/parser/bad-let-as-field.stderr
new file mode 100644
index 000000000..57def42b1
--- /dev/null
+++ b/src/test/ui/parser/bad-let-as-field.stderr
@@ -0,0 +1,15 @@
+error: expected identifier, found keyword `let`
+ --> $DIR/bad-let-as-field.rs:2:5
+ |
+LL | struct Foo {
+ | --- while parsing this struct
+LL | let: i32,
+ | ^^^ expected identifier, found keyword
+ |
+help: escape `let` to use it as an identifier
+ |
+LL | r#let: i32,
+ | ++
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/bad-lit-suffixes.rs b/src/test/ui/parser/bad-lit-suffixes.rs
index 446a09405..9724533c4 100644
--- a/src/test/ui/parser/bad-lit-suffixes.rs
+++ b/src/test/ui/parser/bad-lit-suffixes.rs
@@ -1,18 +1,18 @@
extern
- "C"suffix //~ ERROR suffixes on a string literal are invalid
+ "C"suffix //~ ERROR suffixes on string literals are invalid
fn foo() {}
extern
- "C"suffix //~ ERROR suffixes on a string literal are invalid
+ "C"suffix //~ ERROR suffixes on string literals are invalid
{}
fn main() {
- ""suffix; //~ ERROR suffixes on a string literal are invalid
- b""suffix; //~ ERROR suffixes on a byte string literal are invalid
- r#""#suffix; //~ ERROR suffixes on a string literal are invalid
- br#""#suffix; //~ ERROR suffixes on a byte string literal are invalid
- 'a'suffix; //~ ERROR suffixes on a char literal are invalid
- b'a'suffix; //~ ERROR suffixes on a byte literal are invalid
+ ""suffix; //~ ERROR suffixes on string literals are invalid
+ b""suffix; //~ ERROR suffixes on byte string literals are invalid
+ r#""#suffix; //~ ERROR suffixes on string literals are invalid
+ br#""#suffix; //~ ERROR suffixes on byte string literals are invalid
+ 'a'suffix; //~ ERROR suffixes on char literals are invalid
+ b'a'suffix; //~ ERROR suffixes on byte literals are invalid
1234u1024; //~ ERROR invalid width `1024` for integer literal
1234i1024; //~ ERROR invalid width `1024` for integer literal
diff --git a/src/test/ui/parser/bad-lit-suffixes.stderr b/src/test/ui/parser/bad-lit-suffixes.stderr
index 9b5965714..f74eef324 100644
--- a/src/test/ui/parser/bad-lit-suffixes.stderr
+++ b/src/test/ui/parser/bad-lit-suffixes.stderr
@@ -1,46 +1,46 @@
-error: suffixes on a string literal are invalid
+error: suffixes on string literals are invalid
--> $DIR/bad-lit-suffixes.rs:2:5
|
LL | "C"suffix
| ^^^^^^^^^ invalid suffix `suffix`
-error: suffixes on a string literal are invalid
+error: suffixes on string literals are invalid
--> $DIR/bad-lit-suffixes.rs:6:5
|
LL | "C"suffix
| ^^^^^^^^^ invalid suffix `suffix`
-error: suffixes on a string literal are invalid
+error: suffixes on string literals are invalid
--> $DIR/bad-lit-suffixes.rs:10:5
|
LL | ""suffix;
| ^^^^^^^^ invalid suffix `suffix`
-error: suffixes on a byte string literal are invalid
+error: suffixes on byte string literals are invalid
--> $DIR/bad-lit-suffixes.rs:11:5
|
LL | b""suffix;
| ^^^^^^^^^ invalid suffix `suffix`
-error: suffixes on a string literal are invalid
+error: suffixes on string literals are invalid
--> $DIR/bad-lit-suffixes.rs:12:5
|
LL | r#""#suffix;
| ^^^^^^^^^^^ invalid suffix `suffix`
-error: suffixes on a byte string literal are invalid
+error: suffixes on byte string literals are invalid
--> $DIR/bad-lit-suffixes.rs:13:5
|
LL | br#""#suffix;
| ^^^^^^^^^^^^ invalid suffix `suffix`
-error: suffixes on a char literal are invalid
+error: suffixes on char literals are invalid
--> $DIR/bad-lit-suffixes.rs:14:5
|
LL | 'a'suffix;
| ^^^^^^^^^ invalid suffix `suffix`
-error: suffixes on a byte literal are invalid
+error: suffixes on byte literals are invalid
--> $DIR/bad-lit-suffixes.rs:15:5
|
LL | b'a'suffix;
diff --git a/src/test/ui/parser/bad-pointer-type.rs b/src/test/ui/parser/bad-pointer-type.rs
index 59e5e0c5d..6a82acb4c 100644
--- a/src/test/ui/parser/bad-pointer-type.rs
+++ b/src/test/ui/parser/bad-pointer-type.rs
@@ -1,5 +1,5 @@
fn foo(_: *()) {
- //~^ ERROR expected mut or const in raw pointer type
+ //~^ ERROR expected `mut` or `const` keyword in raw pointer type
}
fn main() {}
diff --git a/src/test/ui/parser/bad-pointer-type.stderr b/src/test/ui/parser/bad-pointer-type.stderr
index e18c220af..b7225ca88 100644
--- a/src/test/ui/parser/bad-pointer-type.stderr
+++ b/src/test/ui/parser/bad-pointer-type.stderr
@@ -1,10 +1,15 @@
-error: expected mut or const in raw pointer type
+error: expected `mut` or `const` keyword in raw pointer type
--> $DIR/bad-pointer-type.rs:1:11
|
LL | fn foo(_: *()) {
- | ^ expected mut or const in raw pointer type
+ | ^
|
- = help: use `*mut T` or `*const T` as appropriate
+help: add `mut` or `const` here
+ |
+LL | fn foo(_: *const ()) {
+ | +++++
+LL | fn foo(_: *mut ()) {
+ | +++
error: aborting due to previous error
diff --git a/src/test/ui/parser/default.stderr b/src/test/ui/parser/default.stderr
index 5b763ae72..37aa48ccf 100644
--- a/src/test/ui/parser/default.stderr
+++ b/src/test/ui/parser/default.stderr
@@ -29,9 +29,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0046]: not all trait items implemented, missing: `foo`
--> $DIR/default.rs:22:1
diff --git a/src/test/ui/parser/doc-after-struct-field.rs b/src/test/ui/parser/doc-after-struct-field.rs
index 5b6f08036..03faa6733 100644
--- a/src/test/ui/parser/doc-after-struct-field.rs
+++ b/src/test/ui/parser/doc-after-struct-field.rs
@@ -1,13 +1,13 @@
struct X {
a: u8 /** document a */,
//~^ ERROR found a documentation comment that doesn't document anything
- //~| HELP maybe a comment was intended
+ //~| HELP if a comment was intended use `//`
}
struct Y {
a: u8 /// document a
//~^ ERROR found a documentation comment that doesn't document anything
- //~| HELP maybe a comment was intended
+ //~| HELP if a comment was intended use `//`
}
fn main() {
diff --git a/src/test/ui/parser/doc-after-struct-field.stderr b/src/test/ui/parser/doc-after-struct-field.stderr
index e3b32a7f0..ae177f1a2 100644
--- a/src/test/ui/parser/doc-after-struct-field.stderr
+++ b/src/test/ui/parser/doc-after-struct-field.stderr
@@ -4,7 +4,7 @@ error[E0585]: found a documentation comment that doesn't document anything
LL | a: u8 /** document a */,
| ^^^^^^^^^^^^^^^^^
|
- = help: doc comments must come before what they document, maybe a comment was intended with `//`?
+ = help: doc comments must come before what they document, if a comment was intended use `//`
error[E0585]: found a documentation comment that doesn't document anything
--> $DIR/doc-after-struct-field.rs:8:11
@@ -12,7 +12,7 @@ error[E0585]: found a documentation comment that doesn't document anything
LL | a: u8 /// document a
| ^^^^^^^^^^^^^^
|
- = help: doc comments must come before what they document, maybe a comment was intended with `//`?
+ = help: doc comments must come before what they document, if a comment was intended use `//`
error: aborting due to 2 previous errors
diff --git a/src/test/ui/parser/doc-before-extern-rbrace.stderr b/src/test/ui/parser/doc-before-extern-rbrace.stderr
index 0edceb268..8fa12ec26 100644
--- a/src/test/ui/parser/doc-before-extern-rbrace.stderr
+++ b/src/test/ui/parser/doc-before-extern-rbrace.stderr
@@ -4,7 +4,7 @@ error[E0584]: found a documentation comment that doesn't document anything
LL | /// hi
| ^^^^^^ this doc comment doesn't document anything
|
- = help: doc comments must come before what they document, maybe a comment was intended with `//`?
+ = help: doc comments must come before what they document, if a comment was intended use `//`
error: aborting due to previous error
diff --git a/src/test/ui/parser/doc-before-fn-rbrace.rs b/src/test/ui/parser/doc-before-fn-rbrace.rs
index eb355136f..c85021648 100644
--- a/src/test/ui/parser/doc-before-fn-rbrace.rs
+++ b/src/test/ui/parser/doc-before-fn-rbrace.rs
@@ -1,5 +1,5 @@
fn main() {
/// document
//~^ ERROR found a documentation comment that doesn't document anything
- //~| HELP maybe a comment was intended
+ //~| HELP if a comment was intended use `//`
}
diff --git a/src/test/ui/parser/doc-before-fn-rbrace.stderr b/src/test/ui/parser/doc-before-fn-rbrace.stderr
index 56241de70..6ea68e42b 100644
--- a/src/test/ui/parser/doc-before-fn-rbrace.stderr
+++ b/src/test/ui/parser/doc-before-fn-rbrace.stderr
@@ -4,7 +4,7 @@ error[E0585]: found a documentation comment that doesn't document anything
LL | /// document
| ^^^^^^^^^^^^
|
- = help: doc comments must come before what they document, maybe a comment was intended with `//`?
+ = help: doc comments must come before what they document, if a comment was intended use `//`
error: aborting due to previous error
diff --git a/src/test/ui/parser/doc-before-rbrace.rs b/src/test/ui/parser/doc-before-rbrace.rs
index 8ff946344..570306f2c 100644
--- a/src/test/ui/parser/doc-before-rbrace.rs
+++ b/src/test/ui/parser/doc-before-rbrace.rs
@@ -1,5 +1,5 @@
fn main() {
println!("Hi"); /// hi
//~^ ERROR found a documentation comment that doesn't document anything
- //~| HELP maybe a comment was intended
+ //~| HELP if a comment was intended use `//`
}
diff --git a/src/test/ui/parser/doc-before-rbrace.stderr b/src/test/ui/parser/doc-before-rbrace.stderr
index 55719cf64..4d4741dfe 100644
--- a/src/test/ui/parser/doc-before-rbrace.stderr
+++ b/src/test/ui/parser/doc-before-rbrace.stderr
@@ -4,7 +4,7 @@ error[E0585]: found a documentation comment that doesn't document anything
LL | println!("Hi"); /// hi
| ^^^^^^
|
- = help: doc comments must come before what they document, maybe a comment was intended with `//`?
+ = help: doc comments must come before what they document, if a comment was intended use `//`
error: aborting due to previous error
diff --git a/src/test/ui/parser/doc-before-semi.rs b/src/test/ui/parser/doc-before-semi.rs
index 405a7e1e2..444b5874e 100644
--- a/src/test/ui/parser/doc-before-semi.rs
+++ b/src/test/ui/parser/doc-before-semi.rs
@@ -1,6 +1,6 @@
fn main() {
/// hi
//~^ ERROR found a documentation comment that doesn't document anything
- //~| HELP maybe a comment was intended
+ //~| HELP if a comment was intended use `//`
;
}
diff --git a/src/test/ui/parser/doc-before-semi.stderr b/src/test/ui/parser/doc-before-semi.stderr
index e6bade18d..a879e13ff 100644
--- a/src/test/ui/parser/doc-before-semi.stderr
+++ b/src/test/ui/parser/doc-before-semi.stderr
@@ -4,7 +4,7 @@ error[E0585]: found a documentation comment that doesn't document anything
LL | /// hi
| ^^^^^^
|
- = help: doc comments must come before what they document, maybe a comment was intended with `//`?
+ = help: doc comments must come before what they document, if a comment was intended use `//`
error: aborting due to previous error
diff --git a/src/test/ui/parser/doc-before-struct-rbrace-1.rs b/src/test/ui/parser/doc-before-struct-rbrace-1.rs
index 3866a3105..0c8d90c3b 100644
--- a/src/test/ui/parser/doc-before-struct-rbrace-1.rs
+++ b/src/test/ui/parser/doc-before-struct-rbrace-1.rs
@@ -2,7 +2,7 @@ struct X {
a: u8,
/// document
//~^ ERROR found a documentation comment that doesn't document anything
- //~| HELP maybe a comment was intended
+ //~| HELP if a comment was intended use `//`
}
fn main() {
diff --git a/src/test/ui/parser/doc-before-struct-rbrace-1.stderr b/src/test/ui/parser/doc-before-struct-rbrace-1.stderr
index 19f906773..94934f734 100644
--- a/src/test/ui/parser/doc-before-struct-rbrace-1.stderr
+++ b/src/test/ui/parser/doc-before-struct-rbrace-1.stderr
@@ -1,10 +1,13 @@
error[E0585]: found a documentation comment that doesn't document anything
--> $DIR/doc-before-struct-rbrace-1.rs:3:5
|
+LL | struct X {
+ | - while parsing this struct
+LL | a: u8,
LL | /// document
| ^^^^^^^^^^^^
|
- = help: doc comments must come before what they document, maybe a comment was intended with `//`?
+ = help: doc comments must come before what they document, if a comment was intended use `//`
error: aborting due to previous error
diff --git a/src/test/ui/parser/doc-before-struct-rbrace-2.rs b/src/test/ui/parser/doc-before-struct-rbrace-2.rs
index dda138f1a..2b2aadf79 100644
--- a/src/test/ui/parser/doc-before-struct-rbrace-2.rs
+++ b/src/test/ui/parser/doc-before-struct-rbrace-2.rs
@@ -1,7 +1,7 @@
struct X {
a: u8 /// document
//~^ ERROR found a documentation comment that doesn't document anything
- //~| HELP maybe a comment was intended
+ //~| HELP if a comment was intended use `//`
}
fn main() {
diff --git a/src/test/ui/parser/doc-before-struct-rbrace-2.stderr b/src/test/ui/parser/doc-before-struct-rbrace-2.stderr
index b25ccab79..6b5c8c1f8 100644
--- a/src/test/ui/parser/doc-before-struct-rbrace-2.stderr
+++ b/src/test/ui/parser/doc-before-struct-rbrace-2.stderr
@@ -4,7 +4,7 @@ error[E0585]: found a documentation comment that doesn't document anything
LL | a: u8 /// document
| ^^^^^^^^^^^^
|
- = help: doc comments must come before what they document, maybe a comment was intended with `//`?
+ = help: doc comments must come before what they document, if a comment was intended use `//`
error: aborting due to previous error
diff --git a/src/test/ui/parser/doc-inside-trait-item.stderr b/src/test/ui/parser/doc-inside-trait-item.stderr
index 246255a0a..900124adc 100644
--- a/src/test/ui/parser/doc-inside-trait-item.stderr
+++ b/src/test/ui/parser/doc-inside-trait-item.stderr
@@ -4,7 +4,7 @@ error[E0584]: found a documentation comment that doesn't document anything
LL | /// empty doc
| ^^^^^^^^^^^^^ this doc comment doesn't document anything
|
- = help: doc comments must come before what they document, maybe a comment was intended with `//`?
+ = help: doc comments must come before what they document, if a comment was intended use `//`
error: aborting due to previous error
diff --git a/src/test/ui/parser/double-pointer.rs b/src/test/ui/parser/double-pointer.rs
new file mode 100644
index 000000000..54d34db4a
--- /dev/null
+++ b/src/test/ui/parser/double-pointer.rs
@@ -0,0 +1,7 @@
+fn main() {
+ let x: i32 = 5;
+ let ptr: *const i32 = &x;
+ let dptr: **const i32 = &ptr;
+ //~^ ERROR expected `mut` or `const` keyword in raw pointer type
+ //~| HELP add `mut` or `const` here
+}
diff --git a/src/test/ui/parser/double-pointer.stderr b/src/test/ui/parser/double-pointer.stderr
new file mode 100644
index 000000000..28037f932
--- /dev/null
+++ b/src/test/ui/parser/double-pointer.stderr
@@ -0,0 +1,15 @@
+error: expected `mut` or `const` keyword in raw pointer type
+ --> $DIR/double-pointer.rs:4:15
+ |
+LL | let dptr: **const i32 = &ptr;
+ | ^
+ |
+help: add `mut` or `const` here
+ |
+LL | let dptr: *const *const i32 = &ptr;
+ | +++++
+LL | let dptr: *mut *const i32 = &ptr;
+ | +++
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/emoji-identifiers.stderr b/src/test/ui/parser/emoji-identifiers.stderr
index 2550dc3d3..e645b68ba 100644
--- a/src/test/ui/parser/emoji-identifiers.stderr
+++ b/src/test/ui/parser/emoji-identifiers.stderr
@@ -9,15 +9,6 @@ help: Unicode character 'âž–' (Heavy Minus Sign) looks like '-' (Minus/Hyphen),
LL | let _ = i_like_to_😄_a_lot() - 4;
| ~
-error[E0425]: cannot find function `i_like_to_😄_a_lot` in this scope
- --> $DIR/emoji-identifiers.rs:13:13
- |
-LL | fn i_like_to_😅_a_lot() -> 👀 {
- | ----------------------------- similarly named function `i_like_to_😅_a_lot` defined here
-...
-LL | let _ = i_like_to_😄_a_lot() ➖ 4;
- | ^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `i_like_to_😅_a_lot`
-
error: Ferris cannot be used as an identifier
--> $DIR/emoji-identifiers.rs:17:9
|
@@ -85,6 +76,15 @@ LL | 👀::full_of✨()
| function or associated item not found in `👀`
| help: there is an associated function with a similar name: `full_of_✨`
+error[E0425]: cannot find function `i_like_to_😄_a_lot` in this scope
+ --> $DIR/emoji-identifiers.rs:13:13
+ |
+LL | fn i_like_to_😅_a_lot() -> 👀 {
+ | ----------------------------- similarly named function `i_like_to_😅_a_lot` defined here
+...
+LL | let _ = i_like_to_😄_a_lot() ➖ 4;
+ | ^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `i_like_to_😅_a_lot`
+
error: aborting due to 10 previous errors
Some errors have detailed explanations: E0425, E0599.
diff --git a/src/test/ui/parser/empty-impl-semicolon.rs b/src/test/ui/parser/empty-impl-semicolon.rs
index 207ebef64..2485f5b85 100644
--- a/src/test/ui/parser/empty-impl-semicolon.rs
+++ b/src/test/ui/parser/empty-impl-semicolon.rs
@@ -1 +1,4 @@
-impl Foo; //~ ERROR expected one of `!`, `(`, `+`, `::`, `<`, `for`, `where`, or `{`, found `;`
+struct Foo;
+impl Foo; //~ ERROR expected `{}`, found `;`
+
+fn main() {}
diff --git a/src/test/ui/parser/empty-impl-semicolon.stderr b/src/test/ui/parser/empty-impl-semicolon.stderr
index 398eb5c89..6ed309eba 100644
--- a/src/test/ui/parser/empty-impl-semicolon.stderr
+++ b/src/test/ui/parser/empty-impl-semicolon.stderr
@@ -1,8 +1,10 @@
-error: expected one of `!`, `(`, `+`, `::`, `<`, `for`, `where`, or `{`, found `;`
- --> $DIR/empty-impl-semicolon.rs:1:9
+error: expected `{}`, found `;`
+ --> $DIR/empty-impl-semicolon.rs:2:9
|
LL | impl Foo;
- | ^ expected one of 8 possible tokens
+ | ^
+ |
+ = help: try using `{}` instead
error: aborting due to previous error
diff --git a/src/test/ui/parser/expr-as-stmt-2.stderr b/src/test/ui/parser/expr-as-stmt-2.stderr
index 9b939f05e..2b6314c38 100644
--- a/src/test/ui/parser/expr-as-stmt-2.stderr
+++ b/src/test/ui/parser/expr-as-stmt-2.stderr
@@ -36,11 +36,6 @@ LL | / &&
LL | | if let Some(y) = a { true } else { false }
| |______________________________________________^ expected `bool`, found `&&bool`
|
-help: consider removing the `&&`
- |
-LL - &&
-LL + if let Some(y) = a { true } else { false }
- |
help: parentheses are required to parse this as an expression
|
LL | (if let Some(x) = a { true } else { false })
diff --git a/src/test/ui/parser/expr-as-stmt.stderr b/src/test/ui/parser/expr-as-stmt.stderr
index 858b4e8db..6da4ac340 100644
--- a/src/test/ui/parser/expr-as-stmt.stderr
+++ b/src/test/ui/parser/expr-as-stmt.stderr
@@ -170,11 +170,6 @@ LL | fn revenge_from_mars() -> bool {
LL | { true } && { true }
| ^^^^^^^^^^^ expected `bool`, found `&&bool`
|
-help: consider removing the `&&`
- |
-LL - { true } && { true }
-LL + { true } { true }
- |
help: parentheses are required to parse this as an expression
|
LL | ({ true }) && { true }
@@ -201,10 +196,6 @@ LL | { true } || { true }
|
= note: expected type `bool`
found closure `[closure@$DIR/expr-as-stmt.rs:51:14: 51:16]`
-help: use parentheses to call this closure
- |
-LL | { true } (|| { true })()
- | + +++
help: parentheses are required to parse this as an expression
|
LL | ({ true }) || { true }
diff --git a/src/test/ui/parser/fn-field-parse-error-ice.rs b/src/test/ui/parser/fn-field-parse-error-ice.rs
index 4ea55062f..188257ea5 100644
--- a/src/test/ui/parser/fn-field-parse-error-ice.rs
+++ b/src/test/ui/parser/fn-field-parse-error-ice.rs
@@ -3,7 +3,7 @@
struct Baz {
inner : dyn fn ()
//~^ ERROR expected `,`, or `}`, found keyword `fn`
- //~| ERROR functions are not allowed in struct definitions
+ //~| ERROR expected identifier, found keyword `fn`
//~| ERROR cannot find type `dyn` in this scope
}
diff --git a/src/test/ui/parser/fn-field-parse-error-ice.stderr b/src/test/ui/parser/fn-field-parse-error-ice.stderr
index d582f61cc..3bf68e8cc 100644
--- a/src/test/ui/parser/fn-field-parse-error-ice.stderr
+++ b/src/test/ui/parser/fn-field-parse-error-ice.stderr
@@ -4,14 +4,18 @@ error: expected `,`, or `}`, found keyword `fn`
LL | inner : dyn fn ()
| ^ help: try adding a comma: `,`
-error: functions are not allowed in struct definitions
+error: expected identifier, found keyword `fn`
--> $DIR/fn-field-parse-error-ice.rs:4:17
|
+LL | struct Baz {
+ | --- while parsing this struct
LL | inner : dyn fn ()
- | ^^
+ | ^^ expected identifier, found keyword
|
- = help: unlike in C++, Java, and C#, functions are declared in `impl` blocks
- = help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
+help: escape `fn` to use it as an identifier
+ |
+LL | inner : dyn r#fn ()
+ | ++
error[E0412]: cannot find type `dyn` in this scope
--> $DIR/fn-field-parse-error-ice.rs:4:13
diff --git a/src/test/ui/parser/fn-header-semantic-fail.stderr b/src/test/ui/parser/fn-header-semantic-fail.stderr
index 36304779d..038fdfb2d 100644
--- a/src/test/ui/parser/fn-header-semantic-fail.stderr
+++ b/src/test/ui/parser/fn-header-semantic-fail.stderr
@@ -147,7 +147,7 @@ LL | async fn ft1();
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
error[E0706]: functions in traits cannot be declared `async`
--> $DIR/fn-header-semantic-fail.rs:21:9
@@ -160,7 +160,7 @@ LL | const async unsafe extern "C" fn ft5();
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
error[E0706]: functions in traits cannot be declared `async`
--> $DIR/fn-header-semantic-fail.rs:29:9
@@ -173,7 +173,7 @@ LL | async fn ft1() {}
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
error[E0706]: functions in traits cannot be declared `async`
--> $DIR/fn-header-semantic-fail.rs:33:9
@@ -186,7 +186,7 @@ LL | const async unsafe extern "C" fn ft5() {}
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
error[E0391]: cycle detected when computing type of `main::ff5::{opaque#0}`
--> $DIR/fn-header-semantic-fail.rs:12:44
@@ -199,7 +199,7 @@ note: ...which requires borrow-checking `main::ff5`...
|
LL | const async unsafe extern "C" fn ff5() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires processing `main::ff5`...
+note: ...which requires processing MIR for `main::ff5`...
--> $DIR/fn-header-semantic-fail.rs:12:5
|
LL | const async unsafe extern "C" fn ff5() {}
@@ -235,7 +235,7 @@ note: ...which requires borrow-checking `main::<impl at $DIR/fn-header-semantic-
|
LL | const async unsafe extern "C" fn ft5() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires processing `main::<impl at $DIR/fn-header-semantic-fail.rs:28:5: 28:17>::ft5`...
+note: ...which requires processing MIR for `main::<impl at $DIR/fn-header-semantic-fail.rs:28:5: 28:17>::ft5`...
--> $DIR/fn-header-semantic-fail.rs:33:9
|
LL | const async unsafe extern "C" fn ft5() {}
@@ -271,7 +271,7 @@ note: ...which requires borrow-checking `main::<impl at $DIR/fn-header-semantic-
|
LL | const async unsafe extern "C" fn fi5() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-note: ...which requires processing `main::<impl at $DIR/fn-header-semantic-fail.rs:40:5: 40:11>::fi5`...
+note: ...which requires processing MIR for `main::<impl at $DIR/fn-header-semantic-fail.rs:40:5: 40:11>::fi5`...
--> $DIR/fn-header-semantic-fail.rs:45:9
|
LL | const async unsafe extern "C" fn fi5() {}
diff --git a/src/test/ui/parser/inner-attr-after-doc-comment.stderr b/src/test/ui/parser/inner-attr-after-doc-comment.stderr
index 2cfafac77..3ec3ad8e9 100644
--- a/src/test/ui/parser/inner-attr-after-doc-comment.stderr
+++ b/src/test/ui/parser/inner-attr-after-doc-comment.stderr
@@ -7,7 +7,7 @@ LL | | */
| |___- previous doc comment
LL |
LL | #![recursion_limit="100"]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^ not permitted following an outer attribute
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ not permitted following an outer doc comment
LL |
LL | fn main() {}
| ------------ the inner attribute doesn't annotate this function
diff --git a/src/test/ui/parser/issue-103143.rs b/src/test/ui/parser/issue-103143.rs
new file mode 100644
index 000000000..a584274c4
--- /dev/null
+++ b/src/test/ui/parser/issue-103143.rs
@@ -0,0 +1,5 @@
+fn main() {
+ x::<#[a]y::<z>>
+ //~^ ERROR invalid const generic expression
+ //~| ERROR cannot find value `x` in this scope
+}
diff --git a/src/test/ui/parser/issue-103143.stderr b/src/test/ui/parser/issue-103143.stderr
new file mode 100644
index 000000000..4035c69af
--- /dev/null
+++ b/src/test/ui/parser/issue-103143.stderr
@@ -0,0 +1,20 @@
+error: invalid const generic expression
+ --> $DIR/issue-103143.rs:2:13
+ |
+LL | x::<#[a]y::<z>>
+ | ^^^^^^
+ |
+help: expressions must be enclosed in braces to be used as const generic arguments
+ |
+LL | x::<#[a]{ y::<z> }>
+ | + +
+
+error[E0425]: cannot find value `x` in this scope
+ --> $DIR/issue-103143.rs:2:5
+ |
+LL | x::<#[a]y::<z>>
+ | ^ not found in this scope
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/parser/issue-103425.rs b/src/test/ui/parser/issue-103425.rs
new file mode 100644
index 000000000..c2f8123ca
--- /dev/null
+++ b/src/test/ui/parser/issue-103425.rs
@@ -0,0 +1,15 @@
+fn f() -> f32 {
+ 3
+ //~^ ERROR expected `;`
+ 5.0
+}
+
+fn k() -> f32 {
+ 2_u32
+ //~^ ERROR expected `;`
+ 3_i8
+ //~^ ERROR expected `;`
+ 5.0
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/issue-103425.stderr b/src/test/ui/parser/issue-103425.stderr
new file mode 100644
index 000000000..0efe3e3ca
--- /dev/null
+++ b/src/test/ui/parser/issue-103425.stderr
@@ -0,0 +1,29 @@
+error: expected `;`, found `5.0`
+ --> $DIR/issue-103425.rs:2:6
+ |
+LL | 3
+ | ^ help: add `;` here
+LL |
+LL | 5.0
+ | --- unexpected token
+
+error: expected `;`, found `3_i8`
+ --> $DIR/issue-103425.rs:8:10
+ |
+LL | 2_u32
+ | ^ help: add `;` here
+LL |
+LL | 3_i8
+ | ---- unexpected token
+
+error: expected `;`, found `5.0`
+ --> $DIR/issue-103425.rs:10:9
+ |
+LL | 3_i8
+ | ^ help: add `;` here
+LL |
+LL | 5.0
+ | --- unexpected token
+
+error: aborting due to 3 previous errors
+
diff --git a/src/test/ui/issues/issue-17718-parse-const.rs b/src/test/ui/parser/issue-17718-parse-const.rs
index d5a5f445d..d5a5f445d 100644
--- a/src/test/ui/issues/issue-17718-parse-const.rs
+++ b/src/test/ui/parser/issue-17718-parse-const.rs
diff --git a/src/test/ui/parser/issues/issue-101540.rs b/src/test/ui/parser/issues/issue-101540.rs
new file mode 100644
index 000000000..328ec6f90
--- /dev/null
+++ b/src/test/ui/parser/issues/issue-101540.rs
@@ -0,0 +1,7 @@
+struct S1 {
+ struct S2 {
+ //~^ ERROR structs are not allowed in struct definitions
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/issues/issue-101540.stderr b/src/test/ui/parser/issues/issue-101540.stderr
new file mode 100644
index 000000000..8af887050
--- /dev/null
+++ b/src/test/ui/parser/issues/issue-101540.stderr
@@ -0,0 +1,12 @@
+error: structs are not allowed in struct definitions
+ --> $DIR/issue-101540.rs:2:5
+ |
+LL | struct S1 {
+ | -- while parsing this struct
+LL | struct S2 {
+ | ^^^^^^^^^
+ |
+ = help: consider creating a new `struct` definition instead of nesting
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/issues/issue-102182-impl-trait-recover.rs b/src/test/ui/parser/issues/issue-102182-impl-trait-recover.rs
new file mode 100644
index 000000000..4bfc676d6
--- /dev/null
+++ b/src/test/ui/parser/issues/issue-102182-impl-trait-recover.rs
@@ -0,0 +1,3 @@
+fn foo<T: impl Trait>() {}
+//~^ ERROR expected trait bound, found `impl Trait` type
+fn main() {}
diff --git a/src/test/ui/parser/issues/issue-102182-impl-trait-recover.stderr b/src/test/ui/parser/issues/issue-102182-impl-trait-recover.stderr
new file mode 100644
index 000000000..52b6ae5df
--- /dev/null
+++ b/src/test/ui/parser/issues/issue-102182-impl-trait-recover.stderr
@@ -0,0 +1,14 @@
+error: expected trait bound, found `impl Trait` type
+ --> $DIR/issue-102182-impl-trait-recover.rs:1:11
+ |
+LL | fn foo<T: impl Trait>() {}
+ | ^^^^^^^^^^ not a trait
+ |
+help: use the trait bounds directly
+ |
+LL - fn foo<T: impl Trait>() {}
+LL + fn foo<T: Trait>() {}
+ |
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/issues/issue-17383.rs b/src/test/ui/parser/issues/issue-17383.rs
deleted file mode 100644
index 7bf0e64f2..000000000
--- a/src/test/ui/parser/issues/issue-17383.rs
+++ /dev/null
@@ -1,7 +0,0 @@
-enum X {
- A = 3,
- //~^ ERROR custom discriminant values are not allowed in enums with tuple or struct variants
- B(usize)
-}
-
-fn main() {}
diff --git a/src/test/ui/parser/issues/issue-17383.stderr b/src/test/ui/parser/issues/issue-17383.stderr
deleted file mode 100644
index 265d6e148..000000000
--- a/src/test/ui/parser/issues/issue-17383.stderr
+++ /dev/null
@@ -1,15 +0,0 @@
-error[E0658]: custom discriminant values are not allowed in enums with tuple or struct variants
- --> $DIR/issue-17383.rs:2:9
- |
-LL | A = 3,
- | ^ disallowed custom discriminant
-LL |
-LL | B(usize)
- | -------- tuple variant defined here
- |
- = note: see issue #60553 <https://github.com/rust-lang/rust/issues/60553> for more information
- = help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/parser/issues/issue-34222-1.stderr b/src/test/ui/parser/issues/issue-34222-1.stderr
index 0799656b0..b451484ba 100644
--- a/src/test/ui/parser/issues/issue-34222-1.stderr
+++ b/src/test/ui/parser/issues/issue-34222-1.stderr
@@ -4,7 +4,7 @@ error[E0585]: found a documentation comment that doesn't document anything
LL | /// comment
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: doc comments must come before what they document, maybe a comment was intended with `//`?
+ = help: doc comments must come before what they document, if a comment was intended use `//`
error: aborting due to previous error
diff --git a/src/test/ui/parser/issues/issue-48636.stderr b/src/test/ui/parser/issues/issue-48636.stderr
index 462723d1d..6177870d1 100644
--- a/src/test/ui/parser/issues/issue-48636.stderr
+++ b/src/test/ui/parser/issues/issue-48636.stderr
@@ -1,12 +1,14 @@
error[E0585]: found a documentation comment that doesn't document anything
--> $DIR/issue-48636.rs:7:5
|
+LL | struct S {
+ | - while parsing this struct
LL | x: u8
| - help: missing comma here: `,`
LL | /// The ID of the parent core
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help: doc comments must come before what they document, maybe a comment was intended with `//`?
+ = help: doc comments must come before what they document, if a comment was intended use `//`
error: aborting due to previous error
diff --git a/src/test/ui/parser/issues/issue-63115-range-pat-interpolated.rs b/src/test/ui/parser/issues/issue-63115-range-pat-interpolated.rs
index 8efb3c73f..b6e5091b6 100644
--- a/src/test/ui/parser/issues/issue-63115-range-pat-interpolated.rs
+++ b/src/test/ui/parser/issues/issue-63115-range-pat-interpolated.rs
@@ -1,7 +1,6 @@
// check-pass
#![feature(exclusive_range_pattern)]
-#![feature(half_open_range_patterns)]
#![allow(ellipsis_inclusive_range_patterns)]
diff --git a/src/test/ui/parser/issues/issue-68000-unicode-ident-after-missing-comma.stderr b/src/test/ui/parser/issues/issue-68000-unicode-ident-after-missing-comma.stderr
index ef365a616..adabb6859 100644
--- a/src/test/ui/parser/issues/issue-68000-unicode-ident-after-missing-comma.stderr
+++ b/src/test/ui/parser/issues/issue-68000-unicode-ident-after-missing-comma.stderr
@@ -7,6 +7,8 @@ LL | pub bar: Vec<i32>ö
error: expected `:`, found `}`
--> $DIR/issue-68000-unicode-ident-after-missing-comma.rs:4:1
|
+LL | pub struct Foo {
+ | --- while parsing this struct
LL | pub bar: Vec<i32>ö
| - expected `:`
LL |
diff --git a/src/test/ui/parser/issues/issue-8537.stderr b/src/test/ui/parser/issues/issue-8537.stderr
index 505d830ef..523cc9dc5 100644
--- a/src/test/ui/parser/issues/issue-8537.stderr
+++ b/src/test/ui/parser/issues/issue-8537.stderr
@@ -4,7 +4,7 @@ error[E0703]: invalid ABI: found `invalid-ab_isize`
LL | "invalid-ab_isize"
| ^^^^^^^^^^^^^^^^^^ invalid ABI
|
- = help: valid ABIs: Rust, C, C-unwind, cdecl, cdecl-unwind, stdcall, stdcall-unwind, fastcall, fastcall-unwind, vectorcall, vectorcall-unwind, thiscall, thiscall-unwind, aapcs, aapcs-unwind, win64, win64-unwind, sysv64, sysv64-unwind, ptx-kernel, msp430-interrupt, x86-interrupt, amdgpu-kernel, efiapi, avr-interrupt, avr-non-blocking-interrupt, C-cmse-nonsecure-call, wasm, system, system-unwind, rust-intrinsic, rust-call, platform-intrinsic, unadjusted, rust-cold
+ = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions.
error: aborting due to previous error
diff --git a/src/test/ui/parser/issues/issue-93282.rs b/src/test/ui/parser/issues/issue-93282.rs
index 261fcb5f9..274245f1a 100644
--- a/src/test/ui/parser/issues/issue-93282.rs
+++ b/src/test/ui/parser/issues/issue-93282.rs
@@ -12,4 +12,5 @@ fn foo() {
let x = 1;
bar('y, x);
//~^ ERROR expected
+ //~| ERROR mismatched types
}
diff --git a/src/test/ui/parser/issues/issue-93282.stderr b/src/test/ui/parser/issues/issue-93282.stderr
index ee554784b..c6140bb82 100644
--- a/src/test/ui/parser/issues/issue-93282.stderr
+++ b/src/test/ui/parser/issues/issue-93282.stderr
@@ -3,6 +3,11 @@ error: expected `while`, `for`, `loop` or `{` after a label
|
LL | f<'a,>
| ^ expected `while`, `for`, `loop` or `{` after a label
+ |
+help: add `'` to close the char literal
+ |
+LL | f<'a',>
+ | +
error: expected one of `.`, `:`, `;`, `?`, `for`, `loop`, `while`, `}`, or an operator, found `,`
--> $DIR/issue-93282.rs:2:9
@@ -20,6 +25,26 @@ error: expected `while`, `for`, `loop` or `{` after a label
|
LL | bar('y, x);
| ^ expected `while`, `for`, `loop` or `{` after a label
+ |
+help: add `'` to close the char literal
+ |
+LL | bar('y', x);
+ | +
+
+error[E0308]: mismatched types
+ --> $DIR/issue-93282.rs:13:9
+ |
+LL | bar('y, x);
+ | --- ^^ expected `usize`, found `char`
+ | |
+ | arguments to this function are incorrect
+ |
+note: function defined here
+ --> $DIR/issue-93282.rs:7:4
+ |
+LL | fn bar(a: usize, b: usize) -> usize {
+ | ^^^ --------
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/parser/item-needs-block.rs b/src/test/ui/parser/item-needs-block.rs
new file mode 100644
index 000000000..4edac588e
--- /dev/null
+++ b/src/test/ui/parser/item-needs-block.rs
@@ -0,0 +1,10 @@
+trait Trait;
+//~^ ERROR expected `{}`, found `;`
+
+impl Trait for ();
+//~^ ERROR expected `{}`, found `;`
+
+enum Enum;
+//~^ ERROR expected `{}`, found `;`
+
+fn main() {}
diff --git a/src/test/ui/parser/item-needs-block.stderr b/src/test/ui/parser/item-needs-block.stderr
new file mode 100644
index 000000000..3cabd0c73
--- /dev/null
+++ b/src/test/ui/parser/item-needs-block.stderr
@@ -0,0 +1,26 @@
+error: expected `{}`, found `;`
+ --> $DIR/item-needs-block.rs:1:12
+ |
+LL | trait Trait;
+ | ^
+ |
+ = help: try using `{}` instead
+
+error: expected `{}`, found `;`
+ --> $DIR/item-needs-block.rs:4:18
+ |
+LL | impl Trait for ();
+ | ^
+ |
+ = help: try using `{}` instead
+
+error: expected `{}`, found `;`
+ --> $DIR/item-needs-block.rs:7:10
+ |
+LL | enum Enum;
+ | ^
+ |
+ = help: try using `{}` instead
+
+error: aborting due to 3 previous errors
+
diff --git a/src/test/ui/parser/label-after-block-like.rs b/src/test/ui/parser/label-after-block-like.rs
new file mode 100644
index 000000000..55f3f8f9f
--- /dev/null
+++ b/src/test/ui/parser/label-after-block-like.rs
@@ -0,0 +1,43 @@
+fn a() {
+ if let () = () 'a {}
+ //~^ ERROR labeled expression must be followed by `:`
+ //~| ERROR expected `{`, found `'a`
+}
+
+fn b() {
+ if true 'a {}
+ //~^ ERROR labeled expression must be followed by `:`
+ //~| ERROR expected `{`, found `'a`
+}
+
+fn c() {
+ loop 'a {}
+ //~^ ERROR labeled expression must be followed by `:`
+ //~| ERROR expected `{`, found `'a`
+}
+
+fn d() {
+ while true 'a {}
+ //~^ ERROR labeled expression must be followed by `:`
+ //~| ERROR expected `{`, found `'a`
+}
+
+fn e() {
+ while let () = () 'a {}
+ //~^ ERROR labeled expression must be followed by `:`
+ //~| ERROR expected `{`, found `'a`
+}
+
+fn f() {
+ for _ in 0..0 'a {}
+ //~^ ERROR labeled expression must be followed by `:`
+ //~| ERROR expected `{`, found `'a`
+}
+
+fn g() {
+ unsafe 'a {}
+ //~^ ERROR labeled expression must be followed by `:`
+ //~| ERROR expected `{`, found `'a`
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/label-after-block-like.stderr b/src/test/ui/parser/label-after-block-like.stderr
new file mode 100644
index 000000000..8ff50b124
--- /dev/null
+++ b/src/test/ui/parser/label-after-block-like.stderr
@@ -0,0 +1,176 @@
+error: labeled expression must be followed by `:`
+ --> $DIR/label-after-block-like.rs:2:20
+ |
+LL | if let () = () 'a {}
+ | ---^^
+ | | |
+ | | help: add `:` after the label
+ | the label
+ |
+ = note: labels are used before loops and blocks, allowing e.g., `break 'label` to them
+
+error: expected `{`, found `'a`
+ --> $DIR/label-after-block-like.rs:2:20
+ |
+LL | if let () = () 'a {}
+ | ^^ expected `{`
+ |
+note: the `if` expression is missing a block after this condition
+ --> $DIR/label-after-block-like.rs:2:8
+ |
+LL | if let () = () 'a {}
+ | ^^^^^^^^^^^
+help: try placing this code inside a block
+ |
+LL | if let () = () { 'a {} }
+ | + +
+
+error: labeled expression must be followed by `:`
+ --> $DIR/label-after-block-like.rs:8:13
+ |
+LL | if true 'a {}
+ | ---^^
+ | | |
+ | | help: add `:` after the label
+ | the label
+ |
+ = note: labels are used before loops and blocks, allowing e.g., `break 'label` to them
+
+error: expected `{`, found `'a`
+ --> $DIR/label-after-block-like.rs:8:13
+ |
+LL | if true 'a {}
+ | ^^ expected `{`
+ |
+note: the `if` expression is missing a block after this condition
+ --> $DIR/label-after-block-like.rs:8:8
+ |
+LL | if true 'a {}
+ | ^^^^
+help: try placing this code inside a block
+ |
+LL | if true { 'a {} }
+ | + +
+
+error: labeled expression must be followed by `:`
+ --> $DIR/label-after-block-like.rs:14:10
+ |
+LL | loop 'a {}
+ | ---^^
+ | | |
+ | | help: add `:` after the label
+ | the label
+ |
+ = note: labels are used before loops and blocks, allowing e.g., `break 'label` to them
+
+error: expected `{`, found `'a`
+ --> $DIR/label-after-block-like.rs:14:10
+ |
+LL | loop 'a {}
+ | ---- ^^ expected `{`
+ | |
+ | while parsing this `loop` expression
+ |
+help: try placing this code inside a block
+ |
+LL | loop { 'a {} }
+ | + +
+
+error: labeled expression must be followed by `:`
+ --> $DIR/label-after-block-like.rs:20:16
+ |
+LL | while true 'a {}
+ | ---^^
+ | | |
+ | | help: add `:` after the label
+ | the label
+ |
+ = note: labels are used before loops and blocks, allowing e.g., `break 'label` to them
+
+error: expected `{`, found `'a`
+ --> $DIR/label-after-block-like.rs:20:16
+ |
+LL | while true 'a {}
+ | ----- ---- ^^ expected `{`
+ | | |
+ | | this `while` condition successfully parsed
+ | while parsing the body of this `while` expression
+ |
+help: try placing this code inside a block
+ |
+LL | while true { 'a {} }
+ | + +
+
+error: labeled expression must be followed by `:`
+ --> $DIR/label-after-block-like.rs:26:23
+ |
+LL | while let () = () 'a {}
+ | ---^^
+ | | |
+ | | help: add `:` after the label
+ | the label
+ |
+ = note: labels are used before loops and blocks, allowing e.g., `break 'label` to them
+
+error: expected `{`, found `'a`
+ --> $DIR/label-after-block-like.rs:26:23
+ |
+LL | while let () = () 'a {}
+ | ----- ----------- ^^ expected `{`
+ | | |
+ | | this `while` condition successfully parsed
+ | while parsing the body of this `while` expression
+ |
+help: try placing this code inside a block
+ |
+LL | while let () = () { 'a {} }
+ | + +
+
+error: labeled expression must be followed by `:`
+ --> $DIR/label-after-block-like.rs:32:19
+ |
+LL | for _ in 0..0 'a {}
+ | ---^^
+ | | |
+ | | help: add `:` after the label
+ | the label
+ |
+ = note: labels are used before loops and blocks, allowing e.g., `break 'label` to them
+
+error: expected `{`, found `'a`
+ --> $DIR/label-after-block-like.rs:32:19
+ |
+LL | for _ in 0..0 'a {}
+ | ^^ expected `{`
+ |
+help: try placing this code inside a block
+ |
+LL | for _ in 0..0 { 'a {} }
+ | + +
+
+error: labeled expression must be followed by `:`
+ --> $DIR/label-after-block-like.rs:38:12
+ |
+LL | unsafe 'a {}
+ | ---^^
+ | | |
+ | | help: add `:` after the label
+ | the label
+ |
+ = note: labels are used before loops and blocks, allowing e.g., `break 'label` to them
+
+error: expected `{`, found `'a`
+ --> $DIR/label-after-block-like.rs:38:12
+ |
+LL | unsafe 'a {}
+ | ------ ^^ expected `{`
+ | |
+ | while parsing this `unsafe` expression
+ |
+help: try placing this code inside a block
+ |
+LL | unsafe { 'a {} }
+ | + +
+
+error: aborting due to 14 previous errors
+
diff --git a/src/test/ui/parser/label-is-actually-char.rs b/src/test/ui/parser/label-is-actually-char.rs
new file mode 100644
index 000000000..183da603d
--- /dev/null
+++ b/src/test/ui/parser/label-is-actually-char.rs
@@ -0,0 +1,16 @@
+fn main() {
+ let c = 'a;
+ //~^ ERROR expected `while`, `for`, `loop` or `{` after a label
+ //~| HELP add `'` to close the char literal
+ match c {
+ 'a'..='b => {}
+ //~^ ERROR unexpected token: `'b`
+ //~| HELP add `'` to close the char literal
+ _ => {}
+ }
+ let x = ['a, 'b];
+ //~^ ERROR expected `while`, `for`, `loop` or `{` after a label
+ //~| ERROR expected `while`, `for`, `loop` or `{` after a label
+ //~| HELP add `'` to close the char literal
+ //~| HELP add `'` to close the char literal
+}
diff --git a/src/test/ui/parser/label-is-actually-char.stderr b/src/test/ui/parser/label-is-actually-char.stderr
new file mode 100644
index 000000000..28c8d2ada
--- /dev/null
+++ b/src/test/ui/parser/label-is-actually-char.stderr
@@ -0,0 +1,46 @@
+error: expected `while`, `for`, `loop` or `{` after a label
+ --> $DIR/label-is-actually-char.rs:2:15
+ |
+LL | let c = 'a;
+ | ^ expected `while`, `for`, `loop` or `{` after a label
+ |
+help: add `'` to close the char literal
+ |
+LL | let c = 'a';
+ | +
+
+error: unexpected token: `'b`
+ --> $DIR/label-is-actually-char.rs:6:15
+ |
+LL | 'a'..='b => {}
+ | ^^
+ |
+help: add `'` to close the char literal
+ |
+LL | 'a'..='b' => {}
+ | +
+
+error: expected `while`, `for`, `loop` or `{` after a label
+ --> $DIR/label-is-actually-char.rs:11:16
+ |
+LL | let x = ['a, 'b];
+ | ^ expected `while`, `for`, `loop` or `{` after a label
+ |
+help: add `'` to close the char literal
+ |
+LL | let x = ['a', 'b];
+ | +
+
+error: expected `while`, `for`, `loop` or `{` after a label
+ --> $DIR/label-is-actually-char.rs:11:20
+ |
+LL | let x = ['a, 'b];
+ | ^ expected `while`, `for`, `loop` or `{` after a label
+ |
+help: add `'` to close the char literal
+ |
+LL | let x = ['a, 'b'];
+ | +
+
+error: aborting due to 4 previous errors
+
diff --git a/src/test/ui/parser/macro/issue-33569.stderr b/src/test/ui/parser/macro/issue-33569.stderr
index 39d49fd03..0dca090fb 100644
--- a/src/test/ui/parser/macro/issue-33569.stderr
+++ b/src/test/ui/parser/macro/issue-33569.stderr
@@ -22,9 +22,9 @@ error: missing fragment specifier
LL | { $+ } => {
| ^
|
- = note: `#[deny(missing_fragment_specifier)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #40107 <https://github.com/rust-lang/rust/issues/40107>
+ = note: `#[deny(missing_fragment_specifier)]` on by default
error: aborting due to 4 previous errors
diff --git a/src/test/ui/parser/macro/issue-37113.stderr b/src/test/ui/parser/macro/issue-37113.stderr
index 0912858dd..b1f8674fb 100644
--- a/src/test/ui/parser/macro/issue-37113.stderr
+++ b/src/test/ui/parser/macro/issue-37113.stderr
@@ -1,6 +1,8 @@
error: expected identifier, found `String`
--> $DIR/issue-37113.rs:4:16
|
+LL | enum SomeEnum {
+ | -------- while parsing this enum
LL | $( $t, )*
| ^^ expected identifier
...
diff --git a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr
index a47d5506e..ad1e90e43 100644
--- a/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr
+++ b/src/test/ui/parser/mismatched-braces/missing-close-brace-in-struct.stderr
@@ -10,6 +10,9 @@ LL | fn main() {}
error: expected identifier, found keyword `trait`
--> $DIR/missing-close-brace-in-struct.rs:4:1
|
+LL | pub(crate) struct Bar<T> {
+ | --- while parsing this struct
+...
LL | trait T {
| ^^^^^ expected identifier, found keyword
diff --git a/src/test/ui/parser/missing-closing-angle-bracket-struct-field-ty.stderr b/src/test/ui/parser/missing-closing-angle-bracket-struct-field-ty.stderr
index 46ca1f06b..6d8b0c3fc 100644
--- a/src/test/ui/parser/missing-closing-angle-bracket-struct-field-ty.stderr
+++ b/src/test/ui/parser/missing-closing-angle-bracket-struct-field-ty.stderr
@@ -1,6 +1,9 @@
error: expected one of `>`, a const expression, lifetime, or type, found `}`
--> $DIR/missing-closing-angle-bracket-struct-field-ty.rs:9:1
|
+LL | pub struct Foo {
+ | --- while parsing this struct
+...
LL | c: Arc<Mutex<usize>>,
| - expected one of `>`, a const expression, lifetime, or type
LL | }
diff --git a/src/test/ui/parser/numeric-lifetime.stderr b/src/test/ui/parser/numeric-lifetime.stderr
index 73a828952..7c1bcb726 100644
--- a/src/test/ui/parser/numeric-lifetime.stderr
+++ b/src/test/ui/parser/numeric-lifetime.stderr
@@ -1,3 +1,11 @@
+error[E0308]: mismatched types
+ --> $DIR/numeric-lifetime.rs:6:20
+ |
+LL | let x: usize = "";
+ | ----- ^^ expected `usize`, found `&str`
+ | |
+ | expected due to this
+
error: lifetimes cannot start with a number
--> $DIR/numeric-lifetime.rs:1:10
|
@@ -10,14 +18,6 @@ error: lifetimes cannot start with a number
LL | struct S<'1> { s: &'1 usize }
| ^^
-error[E0308]: mismatched types
- --> $DIR/numeric-lifetime.rs:6:20
- |
-LL | let x: usize = "";
- | ----- ^^ expected `usize`, found `&str`
- | |
- | expected due to this
-
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/parser/parser-recovery-1.stderr b/src/test/ui/parser/parser-recovery-1.stderr
index f56060c3e..0cb771ea3 100644
--- a/src/test/ui/parser/parser-recovery-1.stderr
+++ b/src/test/ui/parser/parser-recovery-1.stderr
@@ -18,18 +18,18 @@ error: unexpected token: `;`
LL | let x = y.;
| ^
-error[E0425]: cannot find function `foo` in this scope
- --> $DIR/parser-recovery-1.rs:5:17
- |
-LL | let x = foo();
- | ^^^ not found in this scope
-
error[E0425]: cannot find value `y` in this scope
--> $DIR/parser-recovery-1.rs:10:13
|
LL | let x = y.;
| ^ not found in this scope
+error[E0425]: cannot find function `foo` in this scope
+ --> $DIR/parser-recovery-1.rs:5:17
+ |
+LL | let x = foo();
+ | ^^^ not found in this scope
+
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/parser/parser-recovery-2.stderr b/src/test/ui/parser/parser-recovery-2.stderr
index 0980d033f..8829cf4c1 100644
--- a/src/test/ui/parser/parser-recovery-2.stderr
+++ b/src/test/ui/parser/parser-recovery-2.stderr
@@ -13,18 +13,18 @@ LL | let x = foo();
LL | )
| ^ mismatched closing delimiter
-error[E0425]: cannot find function `foo` in this scope
- --> $DIR/parser-recovery-2.rs:5:17
- |
-LL | let x = foo();
- | ^^^ not found in this scope
-
error[E0425]: cannot find value `y` in this scope
--> $DIR/parser-recovery-2.rs:10:13
|
LL | let x = y.;
| ^ not found in this scope
+error[E0425]: cannot find function `foo` in this scope
+ --> $DIR/parser-recovery-2.rs:5:17
+ |
+LL | let x = foo();
+ | ^^^ not found in this scope
+
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/parser/recover-enum2.stderr b/src/test/ui/parser/recover-enum2.stderr
index ee29f0663..7634bca92 100644
--- a/src/test/ui/parser/recover-enum2.stderr
+++ b/src/test/ui/parser/recover-enum2.stderr
@@ -1,6 +1,8 @@
error: expected type, found `{`
--> $DIR/recover-enum2.rs:6:18
|
+LL | Var3 {
+ | ---- while parsing this struct
LL | abc: {},
| ^ expected type
diff --git a/src/test/ui/parser/recover-field-semi.stderr b/src/test/ui/parser/recover-field-semi.stderr
index 657366db9..3cf484748 100644
--- a/src/test/ui/parser/recover-field-semi.stderr
+++ b/src/test/ui/parser/recover-field-semi.stderr
@@ -1,12 +1,16 @@
error: struct fields are separated by `,`
--> $DIR/recover-field-semi.rs:2:13
|
+LL | struct Foo {
+ | --- while parsing this struct
LL | foo: i32;
| ^ help: replace `;` with `,`
error: union fields are separated by `,`
--> $DIR/recover-field-semi.rs:7:13
|
+LL | union Bar {
+ | --- while parsing this union
LL | foo: i32;
| ^ help: replace `;` with `,`
@@ -14,7 +18,9 @@ error: struct fields are separated by `,`
--> $DIR/recover-field-semi.rs:12:19
|
LL | Qux { foo: i32; }
- | ^ help: replace `;` with `,`
+ | --- ^ help: replace `;` with `,`
+ | |
+ | while parsing this struct
error: unions cannot have zero fields
--> $DIR/recover-field-semi.rs:6:1
diff --git a/src/test/ui/parser/recover-range-pats.rs b/src/test/ui/parser/recover-range-pats.rs
index 2e5a99154..156c7ad94 100644
--- a/src/test/ui/parser/recover-range-pats.rs
+++ b/src/test/ui/parser/recover-range-pats.rs
@@ -4,7 +4,6 @@
// 2. Or at least we have parser recovery if they don't.
#![feature(exclusive_range_pattern)]
-#![feature(half_open_range_patterns)]
#![deny(ellipsis_inclusive_range_patterns)]
fn main() {}
diff --git a/src/test/ui/parser/recover-range-pats.stderr b/src/test/ui/parser/recover-range-pats.stderr
index d0979b23f..c54f13e01 100644
--- a/src/test/ui/parser/recover-range-pats.stderr
+++ b/src/test/ui/parser/recover-range-pats.stderr
@@ -1,47 +1,47 @@
error: float literals must have an integer part
- --> $DIR/recover-range-pats.rs:22:12
+ --> $DIR/recover-range-pats.rs:21:12
|
LL | if let .0..Y = 0 {}
| ^^ help: must have an integer part: `0.0`
error: float literals must have an integer part
- --> $DIR/recover-range-pats.rs:24:16
+ --> $DIR/recover-range-pats.rs:23:16
|
LL | if let X.. .0 = 0 {}
| ^^ help: must have an integer part: `0.0`
error: float literals must have an integer part
- --> $DIR/recover-range-pats.rs:35:12
+ --> $DIR/recover-range-pats.rs:34:12
|
LL | if let .0..=Y = 0 {}
| ^^ help: must have an integer part: `0.0`
error: float literals must have an integer part
- --> $DIR/recover-range-pats.rs:37:16
+ --> $DIR/recover-range-pats.rs:36:16
|
LL | if let X..=.0 = 0 {}
| ^^ help: must have an integer part: `0.0`
error: float literals must have an integer part
- --> $DIR/recover-range-pats.rs:60:12
+ --> $DIR/recover-range-pats.rs:59:12
|
LL | if let .0...Y = 0 {}
| ^^ help: must have an integer part: `0.0`
error: float literals must have an integer part
- --> $DIR/recover-range-pats.rs:64:17
+ --> $DIR/recover-range-pats.rs:63:17
|
LL | if let X... .0 = 0 {}
| ^^ help: must have an integer part: `0.0`
error: float literals must have an integer part
- --> $DIR/recover-range-pats.rs:75:12
+ --> $DIR/recover-range-pats.rs:74:12
|
LL | if let .0.. = 0 {}
| ^^ help: must have an integer part: `0.0`
error[E0586]: inclusive range with no end
- --> $DIR/recover-range-pats.rs:81:13
+ --> $DIR/recover-range-pats.rs:80:13
|
LL | if let 0..= = 0 {}
| ^^^ help: use `..` instead
@@ -49,7 +49,7 @@ LL | if let 0..= = 0 {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error[E0586]: inclusive range with no end
- --> $DIR/recover-range-pats.rs:82:13
+ --> $DIR/recover-range-pats.rs:81:13
|
LL | if let X..= = 0 {}
| ^^^ help: use `..` instead
@@ -57,7 +57,7 @@ LL | if let X..= = 0 {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error[E0586]: inclusive range with no end
- --> $DIR/recover-range-pats.rs:83:16
+ --> $DIR/recover-range-pats.rs:82:16
|
LL | if let true..= = 0 {}
| ^^^ help: use `..` instead
@@ -65,13 +65,13 @@ LL | if let true..= = 0 {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error: float literals must have an integer part
- --> $DIR/recover-range-pats.rs:85:12
+ --> $DIR/recover-range-pats.rs:84:12
|
LL | if let .0..= = 0 {}
| ^^ help: must have an integer part: `0.0`
error[E0586]: inclusive range with no end
- --> $DIR/recover-range-pats.rs:85:14
+ --> $DIR/recover-range-pats.rs:84:14
|
LL | if let .0..= = 0 {}
| ^^^ help: use `..` instead
@@ -79,7 +79,7 @@ LL | if let .0..= = 0 {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error[E0586]: inclusive range with no end
- --> $DIR/recover-range-pats.rs:91:13
+ --> $DIR/recover-range-pats.rs:90:13
|
LL | if let 0... = 0 {}
| ^^^ help: use `..` instead
@@ -87,7 +87,7 @@ LL | if let 0... = 0 {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error[E0586]: inclusive range with no end
- --> $DIR/recover-range-pats.rs:92:13
+ --> $DIR/recover-range-pats.rs:91:13
|
LL | if let X... = 0 {}
| ^^^ help: use `..` instead
@@ -95,7 +95,7 @@ LL | if let X... = 0 {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error[E0586]: inclusive range with no end
- --> $DIR/recover-range-pats.rs:93:16
+ --> $DIR/recover-range-pats.rs:92:16
|
LL | if let true... = 0 {}
| ^^^ help: use `..` instead
@@ -103,13 +103,13 @@ LL | if let true... = 0 {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error: float literals must have an integer part
- --> $DIR/recover-range-pats.rs:95:12
+ --> $DIR/recover-range-pats.rs:94:12
|
LL | if let .0... = 0 {}
| ^^ help: must have an integer part: `0.0`
error[E0586]: inclusive range with no end
- --> $DIR/recover-range-pats.rs:95:14
+ --> $DIR/recover-range-pats.rs:94:14
|
LL | if let .0... = 0 {}
| ^^^ help: use `..` instead
@@ -117,49 +117,49 @@ LL | if let .0... = 0 {}
= note: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error: float literals must have an integer part
- --> $DIR/recover-range-pats.rs:105:15
+ --> $DIR/recover-range-pats.rs:104:15
|
LL | if let .. .0 = 0 {}
| ^^ help: must have an integer part: `0.0`
error: float literals must have an integer part
- --> $DIR/recover-range-pats.rs:115:15
+ --> $DIR/recover-range-pats.rs:114:15
|
LL | if let ..=.0 = 0 {}
| ^^ help: must have an integer part: `0.0`
error: range-to patterns with `...` are not allowed
- --> $DIR/recover-range-pats.rs:121:12
+ --> $DIR/recover-range-pats.rs:120:12
|
LL | if let ...3 = 0 {}
| ^^^ help: use `..=` instead
error: range-to patterns with `...` are not allowed
- --> $DIR/recover-range-pats.rs:123:12
+ --> $DIR/recover-range-pats.rs:122:12
|
LL | if let ...Y = 0 {}
| ^^^ help: use `..=` instead
error: range-to patterns with `...` are not allowed
- --> $DIR/recover-range-pats.rs:125:12
+ --> $DIR/recover-range-pats.rs:124:12
|
LL | if let ...true = 0 {}
| ^^^ help: use `..=` instead
error: float literals must have an integer part
- --> $DIR/recover-range-pats.rs:128:15
+ --> $DIR/recover-range-pats.rs:127:15
|
LL | if let ....3 = 0 {}
| ^^ help: must have an integer part: `0.3`
error: range-to patterns with `...` are not allowed
- --> $DIR/recover-range-pats.rs:128:12
+ --> $DIR/recover-range-pats.rs:127:12
|
LL | if let ....3 = 0 {}
| ^^^ help: use `..=` instead
error: range-to patterns with `...` are not allowed
- --> $DIR/recover-range-pats.rs:150:17
+ --> $DIR/recover-range-pats.rs:149:17
|
LL | let ...$e;
| ^^^ help: use `..=` instead
@@ -170,7 +170,7 @@ LL | mac!(0);
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0586]: inclusive range with no end
- --> $DIR/recover-range-pats.rs:154:19
+ --> $DIR/recover-range-pats.rs:153:19
|
LL | let $e...;
| ^^^ help: use `..` instead
@@ -182,7 +182,7 @@ LL | mac!(0);
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0586]: inclusive range with no end
- --> $DIR/recover-range-pats.rs:155:19
+ --> $DIR/recover-range-pats.rs:154:19
|
LL | let $e..=;
| ^^^ help: use `..` instead
@@ -194,21 +194,21 @@ LL | mac!(0);
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
error: `...` range patterns are deprecated
- --> $DIR/recover-range-pats.rs:42:13
+ --> $DIR/recover-range-pats.rs:41:13
|
LL | if let 0...3 = 0 {}
| ^^^ help: use `..=` for an inclusive range
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
note: the lint level is defined here
- --> $DIR/recover-range-pats.rs:8:9
+ --> $DIR/recover-range-pats.rs:7:9
|
LL | #![deny(ellipsis_inclusive_range_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
error: `...` range patterns are deprecated
- --> $DIR/recover-range-pats.rs:45:13
+ --> $DIR/recover-range-pats.rs:44:13
|
LL | if let 0...Y = 0 {}
| ^^^ help: use `..=` for an inclusive range
@@ -217,7 +217,7 @@ LL | if let 0...Y = 0 {}
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
error: `...` range patterns are deprecated
- --> $DIR/recover-range-pats.rs:48:13
+ --> $DIR/recover-range-pats.rs:47:13
|
LL | if let X...3 = 0 {}
| ^^^ help: use `..=` for an inclusive range
@@ -226,7 +226,7 @@ LL | if let X...3 = 0 {}
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
error: `...` range patterns are deprecated
- --> $DIR/recover-range-pats.rs:51:13
+ --> $DIR/recover-range-pats.rs:50:13
|
LL | if let X...Y = 0 {}
| ^^^ help: use `..=` for an inclusive range
@@ -235,7 +235,7 @@ LL | if let X...Y = 0 {}
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
error: `...` range patterns are deprecated
- --> $DIR/recover-range-pats.rs:54:16
+ --> $DIR/recover-range-pats.rs:53:16
|
LL | if let true...Y = 0 {}
| ^^^ help: use `..=` for an inclusive range
@@ -244,7 +244,7 @@ LL | if let true...Y = 0 {}
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
error: `...` range patterns are deprecated
- --> $DIR/recover-range-pats.rs:57:13
+ --> $DIR/recover-range-pats.rs:56:13
|
LL | if let X...true = 0 {}
| ^^^ help: use `..=` for an inclusive range
@@ -253,7 +253,7 @@ LL | if let X...true = 0 {}
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
error: `...` range patterns are deprecated
- --> $DIR/recover-range-pats.rs:60:14
+ --> $DIR/recover-range-pats.rs:59:14
|
LL | if let .0...Y = 0 {}
| ^^^ help: use `..=` for an inclusive range
@@ -262,7 +262,7 @@ LL | if let .0...Y = 0 {}
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
error: `...` range patterns are deprecated
- --> $DIR/recover-range-pats.rs:64:13
+ --> $DIR/recover-range-pats.rs:63:13
|
LL | if let X... .0 = 0 {}
| ^^^ help: use `..=` for an inclusive range
@@ -271,7 +271,7 @@ LL | if let X... .0 = 0 {}
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
error: `...` range patterns are deprecated
- --> $DIR/recover-range-pats.rs:138:20
+ --> $DIR/recover-range-pats.rs:137:20
|
LL | let $e1...$e2;
| ^^^ help: use `..=` for an inclusive range
@@ -284,7 +284,7 @@ LL | mac2!(0, 1);
= note: this error originates in the macro `mac2` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/recover-range-pats.rs:20:12
+ --> $DIR/recover-range-pats.rs:19:12
|
LL | if let true..Y = 0 {}
| ^^^^ - this is of type `u8`
@@ -292,7 +292,7 @@ LL | if let true..Y = 0 {}
| this is of type `bool` but it should be `char` or numeric
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/recover-range-pats.rs:21:15
+ --> $DIR/recover-range-pats.rs:20:15
|
LL | if let X..true = 0 {}
| - ^^^^ this is of type `bool` but it should be `char` or numeric
@@ -300,7 +300,7 @@ LL | if let X..true = 0 {}
| this is of type `u8`
error[E0308]: mismatched types
- --> $DIR/recover-range-pats.rs:22:12
+ --> $DIR/recover-range-pats.rs:21:12
|
LL | if let .0..Y = 0 {}
| ^^ - - this expression has type `{integer}`
@@ -309,7 +309,7 @@ LL | if let .0..Y = 0 {}
| expected integer, found floating-point number
error[E0308]: mismatched types
- --> $DIR/recover-range-pats.rs:24:16
+ --> $DIR/recover-range-pats.rs:23:16
|
LL | if let X.. .0 = 0 {}
| - ^^ - this expression has type `u8`
@@ -321,7 +321,7 @@ LL | if let X.. .0 = 0 {}
found type `{float}`
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/recover-range-pats.rs:33:12
+ --> $DIR/recover-range-pats.rs:32:12
|
LL | if let true..=Y = 0 {}
| ^^^^ - this is of type `u8`
@@ -329,7 +329,7 @@ LL | if let true..=Y = 0 {}
| this is of type `bool` but it should be `char` or numeric
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/recover-range-pats.rs:34:16
+ --> $DIR/recover-range-pats.rs:33:16
|
LL | if let X..=true = 0 {}
| - ^^^^ this is of type `bool` but it should be `char` or numeric
@@ -337,7 +337,7 @@ LL | if let X..=true = 0 {}
| this is of type `u8`
error[E0308]: mismatched types
- --> $DIR/recover-range-pats.rs:35:12
+ --> $DIR/recover-range-pats.rs:34:12
|
LL | if let .0..=Y = 0 {}
| ^^ - - this expression has type `{integer}`
@@ -346,7 +346,7 @@ LL | if let .0..=Y = 0 {}
| expected integer, found floating-point number
error[E0308]: mismatched types
- --> $DIR/recover-range-pats.rs:37:16
+ --> $DIR/recover-range-pats.rs:36:16
|
LL | if let X..=.0 = 0 {}
| - ^^ - this expression has type `u8`
@@ -358,7 +358,7 @@ LL | if let X..=.0 = 0 {}
found type `{float}`
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/recover-range-pats.rs:54:12
+ --> $DIR/recover-range-pats.rs:53:12
|
LL | if let true...Y = 0 {}
| ^^^^ - this is of type `u8`
@@ -366,7 +366,7 @@ LL | if let true...Y = 0 {}
| this is of type `bool` but it should be `char` or numeric
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/recover-range-pats.rs:57:16
+ --> $DIR/recover-range-pats.rs:56:16
|
LL | if let X...true = 0 {}
| - ^^^^ this is of type `bool` but it should be `char` or numeric
@@ -374,7 +374,7 @@ LL | if let X...true = 0 {}
| this is of type `u8`
error[E0308]: mismatched types
- --> $DIR/recover-range-pats.rs:60:12
+ --> $DIR/recover-range-pats.rs:59:12
|
LL | if let .0...Y = 0 {}
| ^^ - - this expression has type `{integer}`
@@ -383,7 +383,7 @@ LL | if let .0...Y = 0 {}
| expected integer, found floating-point number
error[E0308]: mismatched types
- --> $DIR/recover-range-pats.rs:64:17
+ --> $DIR/recover-range-pats.rs:63:17
|
LL | if let X... .0 = 0 {}
| - ^^ - this expression has type `u8`
@@ -395,13 +395,13 @@ LL | if let X... .0 = 0 {}
found type `{float}`
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/recover-range-pats.rs:73:12
+ --> $DIR/recover-range-pats.rs:72:12
|
LL | if let true.. = 0 {}
| ^^^^ this is of type `bool` but it should be `char` or numeric
error[E0308]: mismatched types
- --> $DIR/recover-range-pats.rs:75:12
+ --> $DIR/recover-range-pats.rs:74:12
|
LL | if let .0.. = 0 {}
| ^^ - this expression has type `{integer}`
@@ -409,13 +409,13 @@ LL | if let .0.. = 0 {}
| expected integer, found floating-point number
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/recover-range-pats.rs:83:12
+ --> $DIR/recover-range-pats.rs:82:12
|
LL | if let true..= = 0 {}
| ^^^^ this is of type `bool` but it should be `char` or numeric
error[E0308]: mismatched types
- --> $DIR/recover-range-pats.rs:85:12
+ --> $DIR/recover-range-pats.rs:84:12
|
LL | if let .0..= = 0 {}
| ^^ - this expression has type `{integer}`
@@ -423,13 +423,13 @@ LL | if let .0..= = 0 {}
| expected integer, found floating-point number
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/recover-range-pats.rs:93:12
+ --> $DIR/recover-range-pats.rs:92:12
|
LL | if let true... = 0 {}
| ^^^^ this is of type `bool` but it should be `char` or numeric
error[E0308]: mismatched types
- --> $DIR/recover-range-pats.rs:95:12
+ --> $DIR/recover-range-pats.rs:94:12
|
LL | if let .0... = 0 {}
| ^^ - this expression has type `{integer}`
@@ -437,13 +437,13 @@ LL | if let .0... = 0 {}
| expected integer, found floating-point number
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/recover-range-pats.rs:103:14
+ --> $DIR/recover-range-pats.rs:102:14
|
LL | if let ..true = 0 {}
| ^^^^ this is of type `bool` but it should be `char` or numeric
error[E0308]: mismatched types
- --> $DIR/recover-range-pats.rs:105:15
+ --> $DIR/recover-range-pats.rs:104:15
|
LL | if let .. .0 = 0 {}
| ^^ - this expression has type `{integer}`
@@ -451,13 +451,13 @@ LL | if let .. .0 = 0 {}
| expected integer, found floating-point number
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/recover-range-pats.rs:113:15
+ --> $DIR/recover-range-pats.rs:112:15
|
LL | if let ..=true = 0 {}
| ^^^^ this is of type `bool` but it should be `char` or numeric
error[E0308]: mismatched types
- --> $DIR/recover-range-pats.rs:115:15
+ --> $DIR/recover-range-pats.rs:114:15
|
LL | if let ..=.0 = 0 {}
| ^^ - this expression has type `{integer}`
@@ -465,13 +465,13 @@ LL | if let ..=.0 = 0 {}
| expected integer, found floating-point number
error[E0029]: only `char` and numeric types are allowed in range patterns
- --> $DIR/recover-range-pats.rs:125:15
+ --> $DIR/recover-range-pats.rs:124:15
|
LL | if let ...true = 0 {}
| ^^^^ this is of type `bool` but it should be `char` or numeric
error[E0308]: mismatched types
- --> $DIR/recover-range-pats.rs:128:15
+ --> $DIR/recover-range-pats.rs:127:15
|
LL | if let ....3 = 0 {}
| ^^ - this expression has type `{integer}`
diff --git a/src/test/ui/parser/recover-struct.stderr b/src/test/ui/parser/recover-struct.stderr
index 1b72184b0..9f6fb06ca 100644
--- a/src/test/ui/parser/recover-struct.stderr
+++ b/src/test/ui/parser/recover-struct.stderr
@@ -1,6 +1,8 @@
error: expected `:`, found `Bad`
--> $DIR/recover-struct.rs:4:9
|
+LL | struct Test {
+ | ---- while parsing this struct
LL | Very
| - expected `:`
LL | Bad
diff --git a/src/test/ui/parser/recovered-struct-variant.stderr b/src/test/ui/parser/recovered-struct-variant.stderr
index 51aaf8bb3..78c67866f 100644
--- a/src/test/ui/parser/recovered-struct-variant.stderr
+++ b/src/test/ui/parser/recovered-struct-variant.stderr
@@ -2,7 +2,9 @@ error: expected `:`, found `,`
--> $DIR/recovered-struct-variant.rs:2:10
|
LL | A { a, b: usize }
- | ^ expected `:`
+ | - ^ expected `:`
+ | |
+ | while parsing this struct
error: aborting due to previous error
diff --git a/src/test/ui/parser/removed-syntax-enum-newtype.stderr b/src/test/ui/parser/removed-syntax-enum-newtype.stderr
index 2daa6249b..8f7ca3567 100644
--- a/src/test/ui/parser/removed-syntax-enum-newtype.stderr
+++ b/src/test/ui/parser/removed-syntax-enum-newtype.stderr
@@ -2,7 +2,9 @@ error: expected one of `<`, `where`, or `{`, found `=`
--> $DIR/removed-syntax-enum-newtype.rs:1:8
|
LL | enum e = isize;
- | ^ expected one of `<`, `where`, or `{`
+ | - ^ expected one of `<`, `where`, or `{`
+ | |
+ | while parsing this enum
error: aborting due to previous error
diff --git a/src/test/ui/parser/removed-syntax-field-let-2.rs b/src/test/ui/parser/removed-syntax-field-let-2.rs
new file mode 100644
index 000000000..7ff91b476
--- /dev/null
+++ b/src/test/ui/parser/removed-syntax-field-let-2.rs
@@ -0,0 +1,12 @@
+struct Foo {
+ let x: i32,
+ //~^ ERROR expected identifier, found keyword
+ let y: i32,
+ //~^ ERROR expected identifier, found keyword
+}
+
+fn main() {
+ let _ = Foo {
+ //~^ ERROR missing fields `x` and `y` in initializer of `Foo`
+ };
+}
diff --git a/src/test/ui/parser/removed-syntax-field-let-2.stderr b/src/test/ui/parser/removed-syntax-field-let-2.stderr
new file mode 100644
index 000000000..fda0919b9
--- /dev/null
+++ b/src/test/ui/parser/removed-syntax-field-let-2.stderr
@@ -0,0 +1,33 @@
+error: expected identifier, found keyword `let`
+ --> $DIR/removed-syntax-field-let-2.rs:2:5
+ |
+LL | let x: i32,
+ | ^^^-
+ | |
+ | expected identifier, found keyword
+ | help: remove this `let` keyword
+ |
+ = note: the `let` keyword is not allowed in `struct` fields
+ = note: see <https://doc.rust-lang.org/book/ch05-01-defining-structs.html> for more information
+
+error: expected identifier, found keyword `let`
+ --> $DIR/removed-syntax-field-let-2.rs:4:5
+ |
+LL | let y: i32,
+ | ^^^-
+ | |
+ | expected identifier, found keyword
+ | help: remove this `let` keyword
+ |
+ = note: the `let` keyword is not allowed in `struct` fields
+ = note: see <https://doc.rust-lang.org/book/ch05-01-defining-structs.html> for more information
+
+error[E0063]: missing fields `x` and `y` in initializer of `Foo`
+ --> $DIR/removed-syntax-field-let-2.rs:9:13
+ |
+LL | let _ = Foo {
+ | ^^^ missing `x` and `y`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0063`.
diff --git a/src/test/ui/parser/removed-syntax-field-let.stderr b/src/test/ui/parser/removed-syntax-field-let.stderr
index 10be2e045..9bc18dabd 100644
--- a/src/test/ui/parser/removed-syntax-field-let.stderr
+++ b/src/test/ui/parser/removed-syntax-field-let.stderr
@@ -2,7 +2,13 @@ error: expected identifier, found keyword `let`
--> $DIR/removed-syntax-field-let.rs:2:5
|
LL | let foo: (),
- | ^^^ expected identifier, found keyword
+ | ^^^-
+ | |
+ | expected identifier, found keyword
+ | help: remove this `let` keyword
+ |
+ = note: the `let` keyword is not allowed in `struct` fields
+ = note: see <https://doc.rust-lang.org/book/ch05-01-defining-structs.html> for more information
error: aborting due to previous error
diff --git a/src/test/ui/parser/removed-syntax-field-semicolon.stderr b/src/test/ui/parser/removed-syntax-field-semicolon.stderr
index e4f75f672..532d4fb2b 100644
--- a/src/test/ui/parser/removed-syntax-field-semicolon.stderr
+++ b/src/test/ui/parser/removed-syntax-field-semicolon.stderr
@@ -1,6 +1,8 @@
error: struct fields are separated by `,`
--> $DIR/removed-syntax-field-semicolon.rs:2:12
|
+LL | struct S {
+ | - while parsing this struct
LL | bar: ();
| ^ help: replace `;` with `,`
diff --git a/src/test/ui/parser/require-parens-for-chained-comparison.rs b/src/test/ui/parser/require-parens-for-chained-comparison.rs
index f29fd7a54..5b90e905a 100644
--- a/src/test/ui/parser/require-parens-for-chained-comparison.rs
+++ b/src/test/ui/parser/require-parens-for-chained-comparison.rs
@@ -23,11 +23,13 @@ fn main() {
//~^ ERROR expected one of
//~| HELP use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
//~| ERROR expected
+ //~| HELP add `'` to close the char literal
f<'_>();
//~^ comparison operators cannot be chained
//~| HELP use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
//~| ERROR expected
+ //~| HELP add `'` to close the char literal
let _ = f<u8>;
//~^ ERROR comparison operators cannot be chained
diff --git a/src/test/ui/parser/require-parens-for-chained-comparison.stderr b/src/test/ui/parser/require-parens-for-chained-comparison.stderr
index 0bf52854e..52e201c43 100644
--- a/src/test/ui/parser/require-parens-for-chained-comparison.stderr
+++ b/src/test/ui/parser/require-parens-for-chained-comparison.stderr
@@ -58,6 +58,11 @@ error: expected `while`, `for`, `loop` or `{` after a label
|
LL | let _ = f<'_, i8>();
| ^ expected `while`, `for`, `loop` or `{` after a label
+ |
+help: add `'` to close the char literal
+ |
+LL | let _ = f<'_', i8>();
+ | +
error: expected one of `.`, `:`, `;`, `?`, `else`, `for`, `loop`, `while`, or an operator, found `,`
--> $DIR/require-parens-for-chained-comparison.rs:22:17
@@ -71,13 +76,18 @@ LL | let _ = f::<'_, i8>();
| ++
error: expected `while`, `for`, `loop` or `{` after a label
- --> $DIR/require-parens-for-chained-comparison.rs:27:9
+ --> $DIR/require-parens-for-chained-comparison.rs:28:9
|
LL | f<'_>();
| ^ expected `while`, `for`, `loop` or `{` after a label
+ |
+help: add `'` to close the char literal
+ |
+LL | f<'_'>();
+ | +
error: comparison operators cannot be chained
- --> $DIR/require-parens-for-chained-comparison.rs:27:6
+ --> $DIR/require-parens-for-chained-comparison.rs:28:6
|
LL | f<'_>();
| ^ ^
@@ -88,7 +98,7 @@ LL | f::<'_>();
| ++
error: comparison operators cannot be chained
- --> $DIR/require-parens-for-chained-comparison.rs:32:14
+ --> $DIR/require-parens-for-chained-comparison.rs:34:14
|
LL | let _ = f<u8>;
| ^ ^
diff --git a/src/test/ui/parser/semi-after-closure-in-macro.rs b/src/test/ui/parser/semi-after-closure-in-macro.rs
new file mode 100644
index 000000000..14efb6100
--- /dev/null
+++ b/src/test/ui/parser/semi-after-closure-in-macro.rs
@@ -0,0 +1,14 @@
+// check-pass
+
+// Checks that the fix in #103222 doesn't also disqualify semicolons after
+// closures within parentheses *in macros*, where they're totally allowed.
+
+macro_rules! m {
+ (($expr:expr ; )) => {
+ $expr
+ };
+}
+
+fn main() {
+ let x = m!(( ||() ; ));
+}
diff --git a/src/test/ui/parser/tag-variant-disr-non-nullary.rs b/src/test/ui/parser/tag-variant-disr-non-nullary.rs
deleted file mode 100644
index a9cfdd549..000000000
--- a/src/test/ui/parser/tag-variant-disr-non-nullary.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-enum Color {
- Red = 0xff0000,
- //~^ ERROR custom discriminant values are not allowed in enums with tuple or struct variants
- Green = 0x00ff00,
- Blue = 0x0000ff,
- Black = 0x000000,
- White = 0xffffff,
- Other(usize),
- Other2(usize, usize),
-}
-
-fn main() {}
diff --git a/src/test/ui/parser/tag-variant-disr-non-nullary.stderr b/src/test/ui/parser/tag-variant-disr-non-nullary.stderr
deleted file mode 100644
index 79f044a06..000000000
--- a/src/test/ui/parser/tag-variant-disr-non-nullary.stderr
+++ /dev/null
@@ -1,25 +0,0 @@
-error[E0658]: custom discriminant values are not allowed in enums with tuple or struct variants
- --> $DIR/tag-variant-disr-non-nullary.rs:2:11
- |
-LL | Red = 0xff0000,
- | ^^^^^^^^ disallowed custom discriminant
-LL |
-LL | Green = 0x00ff00,
- | ^^^^^^^^ disallowed custom discriminant
-LL | Blue = 0x0000ff,
- | ^^^^^^^^ disallowed custom discriminant
-LL | Black = 0x000000,
- | ^^^^^^^^ disallowed custom discriminant
-LL | White = 0xffffff,
- | ^^^^^^^^ disallowed custom discriminant
-LL | Other(usize),
- | ------------ tuple variant defined here
-LL | Other2(usize, usize),
- | -------------------- tuple variant defined here
- |
- = note: see issue #60553 <https://github.com/rust-lang/rust/issues/60553> for more information
- = help: add `#![feature(arbitrary_enum_discriminant)]` to the crate attributes to enable
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/parser/trait-item-with-defaultness-fail-semantic.stderr b/src/test/ui/parser/trait-item-with-defaultness-fail-semantic.stderr
index 76fa86033..be858cd65 100644
--- a/src/test/ui/parser/trait-item-with-defaultness-fail-semantic.stderr
+++ b/src/test/ui/parser/trait-item-with-defaultness-fail-semantic.stderr
@@ -52,9 +52,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error: aborting due to 6 previous errors; 1 warning emitted
diff --git a/src/test/ui/parser/trait-object-trait-parens.stderr b/src/test/ui/parser/trait-object-trait-parens.stderr
index 823f75bfa..5e07a3fe6 100644
--- a/src/test/ui/parser/trait-object-trait-parens.stderr
+++ b/src/test/ui/parser/trait-object-trait-parens.stderr
@@ -22,9 +22,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | let _: Box<(Obj) + (?Sized) + (for<'a> Trait<'a>)>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(bare_trait_objects)]` on by default
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
|
LL | let _: Box<dyn (Obj) + (?Sized) + (for<'a> Trait<'a>)>;
diff --git a/src/test/ui/parser/type-alias-where-fixable.stderr b/src/test/ui/parser/type-alias-where-fixable.stderr
index 2e516d5c4..f0acb388b 100644
--- a/src/test/ui/parser/type-alias-where-fixable.stderr
+++ b/src/test/ui/parser/type-alias-where-fixable.stderr
@@ -4,8 +4,8 @@ warning: where clause not allowed here
LL | type Assoc where u32: Copy = ();
| ^^^^^^^^^^^^^^^
|
- = note: `#[warn(deprecated_where_clause_location)]` on by default
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
+ = note: `#[warn(deprecated_where_clause_location)]` on by default
help: move it to the end of the type declaration
|
LL - type Assoc where u32: Copy = ();
diff --git a/src/test/ui/parser/unicode-control-codepoints.stderr b/src/test/ui/parser/unicode-control-codepoints.stderr
index 71509fe41..44548c72f 100644
--- a/src/test/ui/parser/unicode-control-codepoints.stderr
+++ b/src/test/ui/parser/unicode-control-codepoints.stderr
@@ -92,8 +92,8 @@ LL | // if access_level != "user" { // Check if admin
| | '\u{202b}'
| this comment contains invisible unicode text flow control codepoints
|
- = note: `#[deny(text_direction_codepoint_in_comment)]` on by default
= note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
+ = note: `#[deny(text_direction_codepoint_in_comment)]` on by default
= help: if their presence wasn't intentional, you can remove them
error: unicode codepoint changing visible direction of text present in comment
@@ -123,8 +123,8 @@ LL | println!("{:?}", "/* } if isAdmin begin admins only ");
| | '\u{202e}'
| this literal contains invisible unicode text flow control codepoints
|
- = note: `#[deny(text_direction_codepoint_in_literal)]` on by default
= note: these kind of unicode codepoints change the way text flows on applications that support them, but can cause confusion because they change the order of characters on the screen
+ = note: `#[deny(text_direction_codepoint_in_literal)]` on by default
= help: if their presence wasn't intentional, you can remove them
help: if you want to keep them but make them visible in your source code, you can escape them
|
diff --git a/src/test/ui/parser/unmatched-langle-1.stderr b/src/test/ui/parser/unmatched-langle-1.stderr
index c8072b4c5..cdf74bded 100644
--- a/src/test/ui/parser/unmatched-langle-1.stderr
+++ b/src/test/ui/parser/unmatched-langle-1.stderr
@@ -4,18 +4,18 @@ error: unmatched angle brackets
LL | foo::<<<<Ty<i32>>();
| ^^^ help: remove extra angle brackets
-error[E0425]: cannot find function `foo` in this scope
- --> $DIR/unmatched-langle-1.rs:5:5
- |
-LL | foo::<<<<Ty<i32>>();
- | ^^^ not found in this scope
-
error[E0412]: cannot find type `Ty` in this scope
--> $DIR/unmatched-langle-1.rs:5:14
|
LL | foo::<<<<Ty<i32>>();
| ^^ not found in this scope
+error[E0425]: cannot find function `foo` in this scope
+ --> $DIR/unmatched-langle-1.rs:5:5
+ |
+LL | foo::<<<<Ty<i32>>();
+ | ^^^ not found in this scope
+
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0412, E0425.
diff --git a/src/test/ui/issues/issue-17718-patterns.rs b/src/test/ui/pattern/issue-17718-patterns.rs
index 2ca0f67f8..2ca0f67f8 100644
--- a/src/test/ui/issues/issue-17718-patterns.rs
+++ b/src/test/ui/pattern/issue-17718-patterns.rs
diff --git a/src/test/ui/issues/issue-17718-patterns.stderr b/src/test/ui/pattern/issue-17718-patterns.stderr
index 109091c2a..109091c2a 100644
--- a/src/test/ui/issues/issue-17718-patterns.stderr
+++ b/src/test/ui/pattern/issue-17718-patterns.stderr
diff --git a/src/test/ui/pattern/issue-66270-pat-struct-parser-recovery.stderr b/src/test/ui/pattern/issue-66270-pat-struct-parser-recovery.stderr
index fef0f3c0e..f40642f30 100644
--- a/src/test/ui/pattern/issue-66270-pat-struct-parser-recovery.stderr
+++ b/src/test/ui/pattern/issue-66270-pat-struct-parser-recovery.stderr
@@ -1,6 +1,8 @@
error: expected type, found `0`
--> $DIR/issue-66270-pat-struct-parser-recovery.rs:4:22
|
+LL | struct Bug {
+ | --- while parsing this struct
LL | incorrect_field: 0,
| ^ expected type
diff --git a/src/test/ui/pattern/usefulness/consts-opaque.stderr b/src/test/ui/pattern/usefulness/consts-opaque.stderr
index 05c009a6f..35396751a 100644
--- a/src/test/ui/pattern/usefulness/consts-opaque.stderr
+++ b/src/test/ui/pattern/usefulness/consts-opaque.stderr
@@ -40,9 +40,9 @@ warning: to use a constant of type `Foo` in a pattern, `Foo` must be annotated w
LL | FOO_REF_REF => {}
| ^^^^^^^^^^^
|
- = note: `#[warn(indirect_structural_match)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
+ = note: `#[warn(indirect_structural_match)]` on by default
error: to use a constant of type `Bar` in a pattern, `Bar` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/consts-opaque.rs:53:9
diff --git a/src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.stderr b/src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.stderr
index b97683526..cdb6b5c7a 100644
--- a/src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.stderr
+++ b/src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.stderr
@@ -4,13 +4,13 @@ error: irrefutable `if let` pattern
LL | if let _ = 5 {}
| ^^^^^^^^^
|
+ = note: this pattern will always match, so the `if let` is useless
+ = help: consider replacing the `if let` with a `let`
note: the lint level is defined here
--> $DIR/deny-irrefutable-let-patterns.rs:3:9
|
LL | #![deny(irrefutable_let_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
- = note: this pattern will always match, so the `if let` is useless
- = help: consider replacing the `if let` with a `let`
error: irrefutable `while let` pattern
--> $DIR/deny-irrefutable-let-patterns.rs:8:11
diff --git a/src/test/ui/pattern/usefulness/integer-ranges/overlapping_range_endpoints.stderr b/src/test/ui/pattern/usefulness/integer-ranges/overlapping_range_endpoints.stderr
index 24c0419e1..ea0e8f6e4 100644
--- a/src/test/ui/pattern/usefulness/integer-ranges/overlapping_range_endpoints.stderr
+++ b/src/test/ui/pattern/usefulness/integer-ranges/overlapping_range_endpoints.stderr
@@ -6,12 +6,12 @@ LL | m!(0u8, 20..=30, 30..=40);
| |
| this range overlaps on `30_u8`...
|
+ = note: you likely meant to write mutually exclusive ranges
note: the lint level is defined here
--> $DIR/overlapping_range_endpoints.rs:2:9
|
LL | #![deny(overlapping_range_endpoints)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: you likely meant to write mutually exclusive ranges
error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:16:22
diff --git a/src/test/ui/polymorphization/const_parameters/closures.stderr b/src/test/ui/polymorphization/const_parameters/closures.stderr
index fdf817cae..4e927f773 100644
--- a/src/test/ui/polymorphization/const_parameters/closures.stderr
+++ b/src/test/ui/polymorphization/const_parameters/closures.stderr
@@ -4,8 +4,8 @@ warning: the feature `generic_const_exprs` is incomplete and may not be safe to
LL | #![feature(generic_const_exprs, rustc_attrs)]
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error: item has unused generic parameters
--> $DIR/closures.rs:19:19
diff --git a/src/test/ui/polymorphization/const_parameters/functions.stderr b/src/test/ui/polymorphization/const_parameters/functions.stderr
index f2b5a7307..9d0922ac7 100644
--- a/src/test/ui/polymorphization/const_parameters/functions.stderr
+++ b/src/test/ui/polymorphization/const_parameters/functions.stderr
@@ -4,8 +4,8 @@ warning: the feature `generic_const_exprs` is incomplete and may not be safe to
LL | #![feature(generic_const_exprs, rustc_attrs)]
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error: item has unused generic parameters
--> $DIR/functions.rs:15:8
diff --git a/src/test/ui/polymorphization/generators.stderr b/src/test/ui/polymorphization/generators.stderr
index a24eee5fe..84888f6fb 100644
--- a/src/test/ui/polymorphization/generators.stderr
+++ b/src/test/ui/polymorphization/generators.stderr
@@ -4,8 +4,8 @@ warning: the feature `generic_const_exprs` is incomplete and may not be safe to
LL | #![feature(generic_const_exprs, generators, generator_trait, rustc_attrs)]
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error: item has unused generic parameters
--> $DIR/generators.rs:35:5
diff --git a/src/test/ui/polymorphization/predicates.stderr b/src/test/ui/polymorphization/predicates.stderr
index e5af1d751..80bb2af25 100644
--- a/src/test/ui/polymorphization/predicates.stderr
+++ b/src/test/ui/polymorphization/predicates.stderr
@@ -41,7 +41,7 @@ error: item has unused generic parameters
LL | fn bar<I>() {
| ^^^ - generic parameter `I` is unused
-note: the above error was encountered while instantiating `fn foo::<std::slice::Iter<u32>, T>`
+note: the above error was encountered while instantiating `fn foo::<std::slice::Iter<'_, u32>, T>`
--> $DIR/predicates.rs:86:5
|
LL | foo(x.iter());
diff --git a/src/test/ui/polymorphization/promoted-function-2.stderr b/src/test/ui/polymorphization/promoted-function-2.stderr
index 4d7bab6aa..547569df7 100644
--- a/src/test/ui/polymorphization/promoted-function-2.stderr
+++ b/src/test/ui/polymorphization/promoted-function-2.stderr
@@ -4,8 +4,8 @@ warning: the feature `generic_const_exprs` is incomplete and may not be safe to
LL | #![feature(generic_const_exprs, rustc_attrs)]
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error: item has unused generic parameters
--> $DIR/promoted-function-2.rs:8:4
diff --git a/src/test/ui/privacy/access_levels.rs b/src/test/ui/privacy/access_levels.rs
deleted file mode 100644
index d51d2b572..000000000
--- a/src/test/ui/privacy/access_levels.rs
+++ /dev/null
@@ -1,49 +0,0 @@
-#![feature(rustc_attrs)]
-
-#[rustc_access_level] mod outer { //~ ERROR None
- #[rustc_access_level] pub mod inner { //~ ERROR Some(Exported)
- #[rustc_access_level]
- extern "C" { //~ ERROR Some(Exported)
- #[rustc_access_level] static a: u8; //~ ERROR None
- #[rustc_access_level] pub fn b(); //~ ERROR Some(Exported)
- }
- #[rustc_access_level]
- pub trait Trait { //~ ERROR Some(Exported)
- #[rustc_access_level] const A: i32; //~ ERROR Some(Exported)
- #[rustc_access_level] type B; //~ ERROR Some(Exported)
- }
-
- #[rustc_access_level]
- pub struct Struct { //~ ERROR Some(Exported)
- #[rustc_access_level] a: u8, //~ ERROR None
- #[rustc_access_level] pub b: u8, //~ ERROR Some(Exported)
- }
-
- #[rustc_access_level]
- pub union Union { //~ ERROR Some(Exported)
- #[rustc_access_level] a: u8, //~ ERROR None
- #[rustc_access_level] pub b: u8, //~ ERROR Some(Exported)
- }
-
- #[rustc_access_level]
- pub enum Enum { //~ ERROR Some(Exported)
- #[rustc_access_level] A( //~ ERROR Some(Exported)
- #[rustc_access_level] Struct, //~ ERROR Some(Exported)
- #[rustc_access_level] Union, //~ ERROR Some(Exported)
- ),
- }
- }
-
- #[rustc_access_level] macro_rules! none_macro { //~ ERROR None
- () => {};
- }
-
- #[macro_export]
- #[rustc_access_level] macro_rules! public_macro { //~ ERROR Some(Public)
- () => {};
- }
-}
-
-pub use outer::inner;
-
-fn main() {}
diff --git a/src/test/ui/privacy/access_levels.stderr b/src/test/ui/privacy/access_levels.stderr
deleted file mode 100644
index f326293c3..000000000
--- a/src/test/ui/privacy/access_levels.stderr
+++ /dev/null
@@ -1,125 +0,0 @@
-error: None
- --> $DIR/access_levels.rs:3:23
- |
-LL | #[rustc_access_level] mod outer {
- | ^^^^^^^^^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:4:27
- |
-LL | #[rustc_access_level] pub mod inner {
- | ^^^^^^^^^^^^^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:6:9
- |
-LL | / extern "C" {
-LL | | #[rustc_access_level] static a: u8;
-LL | | #[rustc_access_level] pub fn b();
-LL | | }
- | |_________^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:11:9
- |
-LL | pub trait Trait {
- | ^^^^^^^^^^^^^^^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:17:9
- |
-LL | pub struct Struct {
- | ^^^^^^^^^^^^^^^^^
-
-error: None
- --> $DIR/access_levels.rs:18:35
- |
-LL | #[rustc_access_level] a: u8,
- | ^^^^^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:19:35
- |
-LL | #[rustc_access_level] pub b: u8,
- | ^^^^^^^^^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:23:9
- |
-LL | pub union Union {
- | ^^^^^^^^^^^^^^^
-
-error: None
- --> $DIR/access_levels.rs:24:35
- |
-LL | #[rustc_access_level] a: u8,
- | ^^^^^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:25:35
- |
-LL | #[rustc_access_level] pub b: u8,
- | ^^^^^^^^^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:29:9
- |
-LL | pub enum Enum {
- | ^^^^^^^^^^^^^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:30:35
- |
-LL | #[rustc_access_level] A(
- | ^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:31:39
- |
-LL | #[rustc_access_level] Struct,
- | ^^^^^^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:32:39
- |
-LL | #[rustc_access_level] Union,
- | ^^^^^
-
-error: None
- --> $DIR/access_levels.rs:37:27
- |
-LL | #[rustc_access_level] macro_rules! none_macro {
- | ^^^^^^^^^^^^^^^^^^^^^^^
-
-error: Some(Public)
- --> $DIR/access_levels.rs:42:27
- |
-LL | #[rustc_access_level] macro_rules! public_macro {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:12:35
- |
-LL | #[rustc_access_level] const A: i32;
- | ^^^^^^^^^^^^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:13:35
- |
-LL | #[rustc_access_level] type B;
- | ^^^^^^
-
-error: None
- --> $DIR/access_levels.rs:7:35
- |
-LL | #[rustc_access_level] static a: u8;
- | ^^^^^^^^^^^^
-
-error: Some(Exported)
- --> $DIR/access_levels.rs:8:35
- |
-LL | #[rustc_access_level] pub fn b();
- | ^^^^^^^^^^
-
-error: aborting due to 20 previous errors
-
diff --git a/src/test/ui/privacy/associated-item-privacy-inherent.rs b/src/test/ui/privacy/associated-item-privacy-inherent.rs
index c3ae92023..7b7c734a9 100644
--- a/src/test/ui/privacy/associated-item-privacy-inherent.rs
+++ b/src/test/ui/privacy/associated-item-privacy-inherent.rs
@@ -11,11 +11,11 @@ mod priv_nominal {
pub macro mac() {
let value = Pub::method;
- //~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
+ //~^ ERROR type `for<'a> fn(&'a priv_nominal::Pub) {priv_nominal::Pub::method}` is private
value;
- //~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
+ //~^ ERROR type `for<'a> fn(&'a priv_nominal::Pub) {priv_nominal::Pub::method}` is private
Pub.method();
- //~^ ERROR type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
+ //~^ ERROR type `for<'a> fn(&'a priv_nominal::Pub) {priv_nominal::Pub::method}` is private
Pub::CONST;
//~^ ERROR associated constant `CONST` is private
// let _: Pub::AssocTy;
diff --git a/src/test/ui/privacy/associated-item-privacy-inherent.stderr b/src/test/ui/privacy/associated-item-privacy-inherent.stderr
index 4478e5c2a..f4d4ee459 100644
--- a/src/test/ui/privacy/associated-item-privacy-inherent.stderr
+++ b/src/test/ui/privacy/associated-item-privacy-inherent.stderr
@@ -1,4 +1,4 @@
-error: type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
+error: type `for<'a> fn(&'a priv_nominal::Pub) {priv_nominal::Pub::method}` is private
--> $DIR/associated-item-privacy-inherent.rs:13:21
|
LL | let value = Pub::method;
@@ -9,7 +9,7 @@ LL | priv_nominal::mac!();
|
= note: this error originates in the macro `priv_nominal::mac` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
+error: type `for<'a> fn(&'a priv_nominal::Pub) {priv_nominal::Pub::method}` is private
--> $DIR/associated-item-privacy-inherent.rs:15:9
|
LL | value;
@@ -20,7 +20,7 @@ LL | priv_nominal::mac!();
|
= note: this error originates in the macro `priv_nominal::mac` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: type `for<'r> fn(&'r priv_nominal::Pub) {priv_nominal::Pub::method}` is private
+error: type `for<'a> fn(&'a priv_nominal::Pub) {priv_nominal::Pub::method}` is private
--> $DIR/associated-item-privacy-inherent.rs:17:13
|
LL | Pub.method();
diff --git a/src/test/ui/privacy/associated-item-privacy-trait.rs b/src/test/ui/privacy/associated-item-privacy-trait.rs
index c07aeed99..ad9a5e15c 100644
--- a/src/test/ui/privacy/associated-item-privacy-trait.rs
+++ b/src/test/ui/privacy/associated-item-privacy-trait.rs
@@ -13,11 +13,11 @@ mod priv_trait {
pub macro mac() {
let value = <Pub as PrivTr>::method;
- //~^ ERROR type `for<'r> fn(&'r priv_trait::Pub) {<priv_trait::Pub as PrivTr>::method}` is private
+ //~^ ERROR type `for<'a> fn(&'a priv_trait::Pub) {<priv_trait::Pub as PrivTr>::method}` is private
value;
- //~^ ERROR type `for<'r> fn(&'r priv_trait::Pub) {<priv_trait::Pub as PrivTr>::method}` is private
+ //~^ ERROR type `for<'a> fn(&'a priv_trait::Pub) {<priv_trait::Pub as PrivTr>::method}` is private
Pub.method();
- //~^ ERROR type `for<'r> fn(&'r Self) {<Self as PrivTr>::method}` is private
+ //~^ ERROR type `for<'a> fn(&'a Self) {<Self as PrivTr>::method}` is private
<Pub as PrivTr>::CONST;
//~^ ERROR associated constant `<Pub as PrivTr>::CONST` is private
let _: <Pub as PrivTr>::AssocTy;
diff --git a/src/test/ui/privacy/associated-item-privacy-trait.stderr b/src/test/ui/privacy/associated-item-privacy-trait.stderr
index 6095f5f42..c4be1a9d9 100644
--- a/src/test/ui/privacy/associated-item-privacy-trait.stderr
+++ b/src/test/ui/privacy/associated-item-privacy-trait.stderr
@@ -1,4 +1,4 @@
-error: type `for<'r> fn(&'r priv_trait::Pub) {<priv_trait::Pub as PrivTr>::method}` is private
+error: type `for<'a> fn(&'a priv_trait::Pub) {<priv_trait::Pub as PrivTr>::method}` is private
--> $DIR/associated-item-privacy-trait.rs:15:21
|
LL | let value = <Pub as PrivTr>::method;
@@ -9,7 +9,7 @@ LL | priv_trait::mac!();
|
= note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: type `for<'r> fn(&'r priv_trait::Pub) {<priv_trait::Pub as PrivTr>::method}` is private
+error: type `for<'a> fn(&'a priv_trait::Pub) {<priv_trait::Pub as PrivTr>::method}` is private
--> $DIR/associated-item-privacy-trait.rs:17:9
|
LL | value;
@@ -20,7 +20,7 @@ LL | priv_trait::mac!();
|
= note: this error originates in the macro `priv_trait::mac` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: type `for<'r> fn(&'r Self) {<Self as PrivTr>::method}` is private
+error: type `for<'a> fn(&'a Self) {<Self as PrivTr>::method}` is private
--> $DIR/associated-item-privacy-trait.rs:19:13
|
LL | Pub.method();
diff --git a/src/test/ui/issues/auxiliary/issue-17718-const-privacy.rs b/src/test/ui/privacy/auxiliary/issue-17718-const-privacy.rs
index 93cf4bf3e..93cf4bf3e 100644
--- a/src/test/ui/issues/auxiliary/issue-17718-const-privacy.rs
+++ b/src/test/ui/privacy/auxiliary/issue-17718-const-privacy.rs
diff --git a/src/test/ui/privacy/effective_visibilities.rs b/src/test/ui/privacy/effective_visibilities.rs
new file mode 100644
index 000000000..1d806a1d1
--- /dev/null
+++ b/src/test/ui/privacy/effective_visibilities.rs
@@ -0,0 +1,75 @@
+#![feature(rustc_attrs)]
+
+#[rustc_effective_visibility]
+mod outer { //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
+ #[rustc_effective_visibility]
+ pub mod inner1 { //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+
+ #[rustc_effective_visibility]
+ extern "C" {} //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+
+ #[rustc_effective_visibility]
+ pub trait PubTrait { //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ #[rustc_effective_visibility]
+ const A: i32; //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ #[rustc_effective_visibility]
+ type B; //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ }
+
+ #[rustc_effective_visibility]
+ struct PrivStruct; //~ ERROR not in the table
+
+ #[rustc_effective_visibility]
+ pub union PubUnion { //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ #[rustc_effective_visibility]
+ a: u8, //~ ERROR not in the table
+ #[rustc_effective_visibility]
+ pub b: u8, //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ }
+
+ #[rustc_effective_visibility]
+ pub enum Enum { //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ #[rustc_effective_visibility]
+ A( //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ #[rustc_effective_visibility]
+ PubUnion, //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ ),
+ }
+ }
+
+ #[rustc_effective_visibility]
+ macro_rules! none_macro { //~ Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
+ () => {};
+ }
+
+ #[macro_export]
+ #[rustc_effective_visibility]
+ macro_rules! public_macro { //~ Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ () => {};
+ }
+
+ #[rustc_effective_visibility]
+ pub struct ReachableStruct { //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub
+ #[rustc_effective_visibility]
+ pub a: u8, //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub
+ }
+}
+
+#[rustc_effective_visibility]
+pub use outer::inner1; //~ ERROR Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+
+pub fn foo() -> outer::ReachableStruct { outer::ReachableStruct {a: 0} }
+
+mod half_public_import {
+ #[rustc_effective_visibility]
+ pub type HalfPublicImport = u8; //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ #[rustc_effective_visibility]
+ #[allow(non_upper_case_globals)]
+ pub(crate) const HalfPublicImport: u8 = 0; //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
+}
+
+#[rustc_effective_visibility]
+pub use half_public_import::HalfPublicImport; //~ ERROR Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ //~^ ERROR Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+
+fn main() {}
diff --git a/src/test/ui/privacy/effective_visibilities.stderr b/src/test/ui/privacy/effective_visibilities.stderr
new file mode 100644
index 000000000..1c6201600
--- /dev/null
+++ b/src/test/ui/privacy/effective_visibilities.stderr
@@ -0,0 +1,134 @@
+error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
+ --> $DIR/effective_visibilities.rs:4:1
+ |
+LL | mod outer {
+ | ^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:6:5
+ |
+LL | pub mod inner1 {
+ | ^^^^^^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:9:9
+ |
+LL | extern "C" {}
+ | ^^^^^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:12:9
+ |
+LL | pub trait PubTrait {
+ | ^^^^^^^^^^^^^^^^^^
+
+error: not in the table
+ --> $DIR/effective_visibilities.rs:20:9
+ |
+LL | struct PrivStruct;
+ | ^^^^^^^^^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:23:9
+ |
+LL | pub union PubUnion {
+ | ^^^^^^^^^^^^^^^^^^
+
+error: not in the table
+ --> $DIR/effective_visibilities.rs:25:13
+ |
+LL | a: u8,
+ | ^^^^^
+
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:27:13
+ |
+LL | pub b: u8,
+ | ^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:31:9
+ |
+LL | pub enum Enum {
+ | ^^^^^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:33:13
+ |
+LL | A(
+ | ^
+
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:35:17
+ |
+LL | PubUnion,
+ | ^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
+ --> $DIR/effective_visibilities.rs:41:5
+ |
+LL | macro_rules! none_macro {
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+
+error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:47:5
+ |
+LL | macro_rules! public_macro {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:52:5
+ |
+LL | pub struct ReachableStruct {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:54:9
+ |
+LL | pub a: u8,
+ | ^^^^^^^^^
+
+error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:59:9
+ |
+LL | pub use outer::inner1;
+ | ^^^^^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:65:5
+ |
+LL | pub type HalfPublicImport = u8;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
+ --> $DIR/effective_visibilities.rs:68:5
+ |
+LL | pub(crate) const HalfPublicImport: u8 = 0;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:72:9
+ |
+LL | pub use half_public_import::HalfPublicImport;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:72:9
+ |
+LL | pub use half_public_import::HalfPublicImport;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:14:13
+ |
+LL | const A: i32;
+ | ^^^^^^^^^^^^
+
+error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
+ --> $DIR/effective_visibilities.rs:16:13
+ |
+LL | type B;
+ | ^^^^^^
+
+error: aborting due to 22 previous errors
+
diff --git a/src/test/ui/issues/issue-17718-const-privacy.rs b/src/test/ui/privacy/issue-17718-const-privacy.rs
index 6ab3a60df..6ab3a60df 100644
--- a/src/test/ui/issues/issue-17718-const-privacy.rs
+++ b/src/test/ui/privacy/issue-17718-const-privacy.rs
diff --git a/src/test/ui/issues/issue-17718-const-privacy.stderr b/src/test/ui/privacy/issue-17718-const-privacy.stderr
index 133a6360b..133a6360b 100644
--- a/src/test/ui/issues/issue-17718-const-privacy.stderr
+++ b/src/test/ui/privacy/issue-17718-const-privacy.stderr
diff --git a/src/test/ui/privacy/issue-30079.stderr b/src/test/ui/privacy/issue-30079.stderr
index dc98cfe3b..9179ff339 100644
--- a/src/test/ui/privacy/issue-30079.stderr
+++ b/src/test/ui/privacy/issue-30079.stderr
@@ -4,9 +4,9 @@ warning: private type `m1::Priv` in public interface (error E0446)
LL | pub fn f(_: Priv) {}
| ^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(private_in_public)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
+ = note: `#[warn(private_in_public)]` on by default
error[E0446]: private type `m2::Priv` in public interface
--> $DIR/issue-30079.rs:18:9
diff --git a/src/test/ui/privacy/private-in-public-assoc-ty.stderr b/src/test/ui/privacy/private-in-public-assoc-ty.stderr
index 1abeafe39..a59027d81 100644
--- a/src/test/ui/privacy/private-in-public-assoc-ty.stderr
+++ b/src/test/ui/privacy/private-in-public-assoc-ty.stderr
@@ -13,9 +13,9 @@ warning: private trait `PrivTr` in public interface (error E0445)
LL | type Alias1: PrivTr;
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(private_in_public)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
+ = note: `#[warn(private_in_public)]` on by default
warning: private type `Priv` in public interface (error E0446)
--> $DIR/private-in-public-assoc-ty.rs:27:9
diff --git a/src/test/ui/privacy/private-in-public-non-principal.stderr b/src/test/ui/privacy/private-in-public-non-principal.stderr
index 5b4123ea8..de20cada4 100644
--- a/src/test/ui/privacy/private-in-public-non-principal.stderr
+++ b/src/test/ui/privacy/private-in-public-non-principal.stderr
@@ -4,9 +4,9 @@ warning: private trait `PrivNonPrincipal` in public interface (error E0445)
LL | pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loop {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(private_in_public)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
+ = note: `#[warn(private_in_public)]` on by default
error: missing documentation for an associated function
--> $DIR/private-in-public-non-principal.rs:14:9
diff --git a/src/test/ui/privacy/private-in-public-warn.stderr b/src/test/ui/privacy/private-in-public-warn.stderr
index f2ff6cf2f..66f91ce6f 100644
--- a/src/test/ui/privacy/private-in-public-warn.stderr
+++ b/src/test/ui/privacy/private-in-public-warn.stderr
@@ -4,13 +4,13 @@ error: private type `types::Priv` in public interface (error E0446)
LL | pub type Alias = Priv;
| ^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: the lint level is defined here
--> $DIR/private-in-public-warn.rs:5:9
|
LL | #![deny(private_in_public)]
| ^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
error: private type `types::Priv` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:18:12
diff --git a/src/test/ui/privacy/private-inferred-type-3.rs b/src/test/ui/privacy/private-inferred-type-3.rs
index 00f0a715a..0337aedd0 100644
--- a/src/test/ui/privacy/private-inferred-type-3.rs
+++ b/src/test/ui/privacy/private-inferred-type-3.rs
@@ -6,7 +6,7 @@
// error-pattern:type `fn() {<u8 as ext::PrivTrait>::method}` is private
// error-pattern:type `fn(u8) -> ext::PrivTupleStruct {ext::PrivTupleStruct}` is private
// error-pattern:type `fn(u8) -> PubTupleStruct {PubTupleStruct}` is private
-// error-pattern:type `for<'r> fn(&'r Pub<u8>) {Pub::<u8>::priv_method}` is private
+// error-pattern:type `for<'a> fn(&'a Pub<u8>) {Pub::<u8>::priv_method}` is private
#![feature(decl_macro)]
diff --git a/src/test/ui/privacy/private-inferred-type-3.stderr b/src/test/ui/privacy/private-inferred-type-3.stderr
index f9dd1c3d0..00b61512d 100644
--- a/src/test/ui/privacy/private-inferred-type-3.stderr
+++ b/src/test/ui/privacy/private-inferred-type-3.stderr
@@ -46,7 +46,7 @@ LL | ext::m!();
|
= note: this error originates in the macro `ext::m` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: type `for<'r> fn(&'r Pub<u8>) {Pub::<u8>::priv_method}` is private
+error: type `for<'a> fn(&'a Pub<u8>) {Pub::<u8>::priv_method}` is private
--> $DIR/private-inferred-type-3.rs:16:5
|
LL | ext::m!();
diff --git a/src/test/ui/privacy/private-inferred-type.rs b/src/test/ui/privacy/private-inferred-type.rs
index b083a3970..e8743dd96 100644
--- a/src/test/ui/privacy/private-inferred-type.rs
+++ b/src/test/ui/privacy/private-inferred-type.rs
@@ -47,7 +47,7 @@ mod m {
PubTupleStruct;
//~^ ERROR type `fn(u8) -> PubTupleStruct {PubTupleStruct}` is private
Pub(0u8).priv_method();
- //~^ ERROR type `for<'r> fn(&'r Pub<u8>) {Pub::<u8>::priv_method}` is private
+ //~^ ERROR type `for<'a> fn(&'a Pub<u8>) {Pub::<u8>::priv_method}` is private
}
trait Trait {}
diff --git a/src/test/ui/privacy/private-inferred-type.stderr b/src/test/ui/privacy/private-inferred-type.stderr
index aecd8b58c..fc3f9ab62 100644
--- a/src/test/ui/privacy/private-inferred-type.stderr
+++ b/src/test/ui/privacy/private-inferred-type.stderr
@@ -161,7 +161,7 @@ LL | m::m!();
|
= note: this error originates in the macro `m::m` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: type `for<'r> fn(&'r Pub<u8>) {Pub::<u8>::priv_method}` is private
+error: type `for<'a> fn(&'a Pub<u8>) {Pub::<u8>::priv_method}` is private
--> $DIR/private-inferred-type.rs:49:18
|
LL | Pub(0u8).priv_method();
diff --git a/src/test/ui/privacy/reachable-unnameable-items.rs b/src/test/ui/privacy/reachable-unnameable-items.rs
index 1c91541e6..1babe0119 100644
--- a/src/test/ui/privacy/reachable-unnameable-items.rs
+++ b/src/test/ui/privacy/reachable-unnameable-items.rs
@@ -1,5 +1,4 @@
// run-pass
-// ignore-wasm32-bare compiled with panic=abort by default
// needs-unwind
// aux-build:reachable-unnameable-items.rs
diff --git a/src/test/ui/privacy/where-priv-type.stderr b/src/test/ui/privacy/where-priv-type.stderr
index 7eb71346a..c5fb2cdb0 100644
--- a/src/test/ui/privacy/where-priv-type.stderr
+++ b/src/test/ui/privacy/where-priv-type.stderr
@@ -4,9 +4,9 @@ warning: private type `PrivTy` in public interface (error E0446)
LL | pub struct S
| ^^^^^^^^^^^^
|
- = note: `#[warn(private_in_public)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
+ = note: `#[warn(private_in_public)]` on by default
warning: private type `PrivTy` in public interface (error E0446)
--> $DIR/where-priv-type.rs:27:1
diff --git a/src/test/ui/proc-macro/attr-complex-fn.stdout b/src/test/ui/proc-macro/attr-complex-fn.stdout
index fc69a13dd..b12eb587f 100644
--- a/src/test/ui/proc-macro/attr-complex-fn.stdout
+++ b/src/test/ui/proc-macro/attr-complex-fn.stdout
@@ -53,12 +53,12 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '>',
spacing: Joint,
- span: $DIR/attr-complex-fn.rs:19:36: 19:38 (#0),
+ span: $DIR/attr-complex-fn.rs:19:36: 19:37 (#0),
},
Punct {
ch: '>',
spacing: Joint,
- span: $DIR/attr-complex-fn.rs:19:36: 19:38 (#0),
+ span: $DIR/attr-complex-fn.rs:19:37: 19:38 (#0),
},
Punct {
ch: '>',
diff --git a/src/test/ui/proc-macro/call-deprecated.rs b/src/test/ui/proc-macro/call-deprecated.rs
index b92cc2363..cb634671b 100644
--- a/src/test/ui/proc-macro/call-deprecated.rs
+++ b/src/test/ui/proc-macro/call-deprecated.rs
@@ -5,7 +5,7 @@ extern crate call_deprecated;
// These first two `#[allow(deprecated)]` attributes
// do nothing, since the AST nodes for `First` and `Second`
-// haven't been been assigned a `NodeId`.
+// haven't been assigned a `NodeId`.
// See #63221 for a discussion about how we should
// handle the interaction of 'inert' attributes and
// proc-macro attributes.
diff --git a/src/test/ui/proc-macro/capture-macro-rules-invoke.stdout b/src/test/ui/proc-macro/capture-macro-rules-invoke.stdout
index 4de8746a1..b88fbd3e8 100644
--- a/src/test/ui/proc-macro/capture-macro-rules-invoke.stdout
+++ b/src/test/ui/proc-macro/capture-macro-rules-invoke.stdout
@@ -177,12 +177,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
Punct {
ch: ':',
spacing: Joint,
- span: $DIR/capture-macro-rules-invoke.rs:45:16: 45:18 (#0),
+ span: $DIR/capture-macro-rules-invoke.rs:45:16: 45:17 (#0),
},
Punct {
ch: ':',
spacing: Alone,
- span: $DIR/capture-macro-rules-invoke.rs:45:16: 45:18 (#0),
+ span: $DIR/capture-macro-rules-invoke.rs:45:17: 45:18 (#0),
},
Ident {
ident: "option",
@@ -191,12 +191,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
Punct {
ch: ':',
spacing: Joint,
- span: $DIR/capture-macro-rules-invoke.rs:45:24: 45:26 (#0),
+ span: $DIR/capture-macro-rules-invoke.rs:45:24: 45:25 (#0),
},
Punct {
ch: ':',
spacing: Alone,
- span: $DIR/capture-macro-rules-invoke.rs:45:24: 45:26 (#0),
+ span: $DIR/capture-macro-rules-invoke.rs:45:25: 45:26 (#0),
},
Ident {
ident: "Option",
@@ -231,12 +231,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
Punct {
ch: ':',
spacing: Joint,
- span: $DIR/capture-macro-rules-invoke.rs:46:24: 46:26 (#0),
+ span: $DIR/capture-macro-rules-invoke.rs:46:24: 46:25 (#0),
},
Punct {
ch: ':',
spacing: Alone,
- span: $DIR/capture-macro-rules-invoke.rs:46:24: 46:26 (#0),
+ span: $DIR/capture-macro-rules-invoke.rs:46:25: 46:26 (#0),
},
Ident {
ident: "path",
diff --git a/src/test/ui/proc-macro/debug/dump-debug-span-debug.rs b/src/test/ui/proc-macro/debug/dump-debug-span-debug.rs
index fd34eb974..102bd6b7b 100644
--- a/src/test/ui/proc-macro/debug/dump-debug-span-debug.rs
+++ b/src/test/ui/proc-macro/debug/dump-debug-span-debug.rs
@@ -2,6 +2,7 @@
// aux-build:macro-dump-debug.rs
// compile-flags: -Z span-debug
+
extern crate macro_dump_debug;
use macro_dump_debug::dump_debug;
@@ -9,7 +10,11 @@ dump_debug! {
ident // ident
r#ident // raw ident
, // alone punct
- ==> // joint punct
+ && // joint punct, two-char op
+ ||> // joint punct, two-char op + one-char op
+ ||<< // joint punct, two-char op + two-char op
+ ..= // joint punct, three-char op
+ <<=! // joint punct, three-char op + one-char-op
() // empty group
[_] // nonempty group
diff --git a/src/test/ui/proc-macro/debug/dump-debug-span-debug.stderr b/src/test/ui/proc-macro/debug/dump-debug-span-debug.stderr
index 2c05bdbc4..fa65cbbf1 100644
--- a/src/test/ui/proc-macro/debug/dump-debug-span-debug.stderr
+++ b/src/test/ui/proc-macro/debug/dump-debug-span-debug.stderr
@@ -1,166 +1,231 @@
-TokenStream [Ident { ident: "ident", span: $DIR/dump-debug-span-debug.rs:9:5: 9:10 (#0) }, Ident { ident: "r#ident", span: $DIR/dump-debug-span-debug.rs:10:5: 10:12 (#0) }, Punct { ch: ',', spacing: Alone, span: $DIR/dump-debug-span-debug.rs:11:5: 11:6 (#0) }, Punct { ch: '=', spacing: Joint, span: $DIR/dump-debug-span-debug.rs:12:5: 12:7 (#0) }, Punct { ch: '=', spacing: Joint, span: $DIR/dump-debug-span-debug.rs:12:5: 12:7 (#0) }, Punct { ch: '>', spacing: Alone, span: $DIR/dump-debug-span-debug.rs:12:7: 12:8 (#0) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: $DIR/dump-debug-span-debug.rs:13:5: 13:7 (#0) }, Group { delimiter: Bracket, stream: TokenStream [Ident { ident: "_", span: $DIR/dump-debug-span-debug.rs:14:6: 14:7 (#0) }], span: $DIR/dump-debug-span-debug.rs:14:5: 14:8 (#0) }, Literal { kind: Integer, symbol: "0", suffix: None, span: $DIR/dump-debug-span-debug.rs:17:5: 17:6 (#0) }, Literal { kind: Float, symbol: "1.0", suffix: None, span: $DIR/dump-debug-span-debug.rs:18:5: 18:8 (#0) }, Literal { kind: Str, symbol: "S", suffix: None, span: $DIR/dump-debug-span-debug.rs:19:5: 19:8 (#0) }, Literal { kind: ByteStr, symbol: "B", suffix: None, span: $DIR/dump-debug-span-debug.rs:20:5: 20:9 (#0) }, Literal { kind: StrRaw(0), symbol: "R", suffix: None, span: $DIR/dump-debug-span-debug.rs:21:5: 21:9 (#0) }, Literal { kind: StrRaw(2), symbol: "R", suffix: None, span: $DIR/dump-debug-span-debug.rs:22:5: 22:13 (#0) }, Literal { kind: ByteStrRaw(0), symbol: "BR", suffix: None, span: $DIR/dump-debug-span-debug.rs:23:5: 23:11 (#0) }, Literal { kind: ByteStrRaw(2), symbol: "BR", suffix: None, span: $DIR/dump-debug-span-debug.rs:24:5: 24:15 (#0) }, Literal { kind: Char, symbol: "C", suffix: None, span: $DIR/dump-debug-span-debug.rs:25:5: 25:8 (#0) }, Literal { kind: Byte, symbol: "B", suffix: None, span: $DIR/dump-debug-span-debug.rs:26:5: 26:9 (#0) }, Literal { kind: Integer, symbol: "0", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:29:5: 29:7 (#0) }, Literal { kind: Float, symbol: "1.0", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:30:5: 30:9 (#0) }, Literal { kind: Str, symbol: "S", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:31:5: 31:9 (#0) }, Literal { kind: ByteStr, symbol: "B", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:32:5: 32:10 (#0) }, Literal { kind: StrRaw(0), symbol: "R", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:33:5: 33:10 (#0) }, Literal { kind: StrRaw(2), symbol: "R", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:34:5: 34:14 (#0) }, Literal { kind: ByteStrRaw(0), symbol: "BR", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:35:5: 35:12 (#0) }, Literal { kind: ByteStrRaw(2), symbol: "BR", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:36:5: 36:16 (#0) }, Literal { kind: Char, symbol: "C", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:37:5: 37:9 (#0) }, Literal { kind: Byte, symbol: "B", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:38:5: 38:10 (#0) }]
+TokenStream [Ident { ident: "ident", span: $DIR/dump-debug-span-debug.rs:10:5: 10:10 (#0) }, Ident { ident: "r#ident", span: $DIR/dump-debug-span-debug.rs:11:5: 11:12 (#0) }, Punct { ch: ',', spacing: Alone, span: $DIR/dump-debug-span-debug.rs:12:5: 12:6 (#0) }, Punct { ch: '&', spacing: Joint, span: $DIR/dump-debug-span-debug.rs:13:5: 13:6 (#0) }, Punct { ch: '&', spacing: Alone, span: $DIR/dump-debug-span-debug.rs:13:6: 13:7 (#0) }, Punct { ch: '|', spacing: Joint, span: $DIR/dump-debug-span-debug.rs:14:5: 14:6 (#0) }, Punct { ch: '|', spacing: Joint, span: $DIR/dump-debug-span-debug.rs:14:6: 14:7 (#0) }, Punct { ch: '>', spacing: Alone, span: $DIR/dump-debug-span-debug.rs:14:7: 14:8 (#0) }, Punct { ch: '|', spacing: Joint, span: $DIR/dump-debug-span-debug.rs:15:5: 15:6 (#0) }, Punct { ch: '|', spacing: Joint, span: $DIR/dump-debug-span-debug.rs:15:6: 15:7 (#0) }, Punct { ch: '<', spacing: Joint, span: $DIR/dump-debug-span-debug.rs:15:7: 15:8 (#0) }, Punct { ch: '<', spacing: Alone, span: $DIR/dump-debug-span-debug.rs:15:8: 15:9 (#0) }, Punct { ch: '.', spacing: Joint, span: $DIR/dump-debug-span-debug.rs:16:5: 16:6 (#0) }, Punct { ch: '.', spacing: Joint, span: $DIR/dump-debug-span-debug.rs:16:6: 16:7 (#0) }, Punct { ch: '=', spacing: Alone, span: $DIR/dump-debug-span-debug.rs:16:7: 16:8 (#0) }, Punct { ch: '<', spacing: Joint, span: $DIR/dump-debug-span-debug.rs:17:5: 17:6 (#0) }, Punct { ch: '<', spacing: Joint, span: $DIR/dump-debug-span-debug.rs:17:6: 17:7 (#0) }, Punct { ch: '=', spacing: Joint, span: $DIR/dump-debug-span-debug.rs:17:7: 17:8 (#0) }, Punct { ch: '!', spacing: Alone, span: $DIR/dump-debug-span-debug.rs:17:8: 17:9 (#0) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: $DIR/dump-debug-span-debug.rs:18:5: 18:7 (#0) }, Group { delimiter: Bracket, stream: TokenStream [Ident { ident: "_", span: $DIR/dump-debug-span-debug.rs:19:6: 19:7 (#0) }], span: $DIR/dump-debug-span-debug.rs:19:5: 19:8 (#0) }, Literal { kind: Integer, symbol: "0", suffix: None, span: $DIR/dump-debug-span-debug.rs:22:5: 22:6 (#0) }, Literal { kind: Float, symbol: "1.0", suffix: None, span: $DIR/dump-debug-span-debug.rs:23:5: 23:8 (#0) }, Literal { kind: Str, symbol: "S", suffix: None, span: $DIR/dump-debug-span-debug.rs:24:5: 24:8 (#0) }, Literal { kind: ByteStr, symbol: "B", suffix: None, span: $DIR/dump-debug-span-debug.rs:25:5: 25:9 (#0) }, Literal { kind: StrRaw(0), symbol: "R", suffix: None, span: $DIR/dump-debug-span-debug.rs:26:5: 26:9 (#0) }, Literal { kind: StrRaw(2), symbol: "R", suffix: None, span: $DIR/dump-debug-span-debug.rs:27:5: 27:13 (#0) }, Literal { kind: ByteStrRaw(0), symbol: "BR", suffix: None, span: $DIR/dump-debug-span-debug.rs:28:5: 28:11 (#0) }, Literal { kind: ByteStrRaw(2), symbol: "BR", suffix: None, span: $DIR/dump-debug-span-debug.rs:29:5: 29:15 (#0) }, Literal { kind: Char, symbol: "C", suffix: None, span: $DIR/dump-debug-span-debug.rs:30:5: 30:8 (#0) }, Literal { kind: Byte, symbol: "B", suffix: None, span: $DIR/dump-debug-span-debug.rs:31:5: 31:9 (#0) }, Literal { kind: Integer, symbol: "0", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:34:5: 34:7 (#0) }, Literal { kind: Float, symbol: "1.0", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:35:5: 35:9 (#0) }, Literal { kind: Str, symbol: "S", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:36:5: 36:9 (#0) }, Literal { kind: ByteStr, symbol: "B", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:37:5: 37:10 (#0) }, Literal { kind: StrRaw(0), symbol: "R", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:38:5: 38:10 (#0) }, Literal { kind: StrRaw(2), symbol: "R", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:39:5: 39:14 (#0) }, Literal { kind: ByteStrRaw(0), symbol: "BR", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:40:5: 40:12 (#0) }, Literal { kind: ByteStrRaw(2), symbol: "BR", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:41:5: 41:16 (#0) }, Literal { kind: Char, symbol: "C", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:42:5: 42:9 (#0) }, Literal { kind: Byte, symbol: "B", suffix: Some("q"), span: $DIR/dump-debug-span-debug.rs:43:5: 43:10 (#0) }]
TokenStream [
Ident {
ident: "ident",
- span: $DIR/dump-debug-span-debug.rs:9:5: 9:10 (#0),
+ span: $DIR/dump-debug-span-debug.rs:10:5: 10:10 (#0),
},
Ident {
ident: "r#ident",
- span: $DIR/dump-debug-span-debug.rs:10:5: 10:12 (#0),
+ span: $DIR/dump-debug-span-debug.rs:11:5: 11:12 (#0),
},
Punct {
ch: ',',
spacing: Alone,
- span: $DIR/dump-debug-span-debug.rs:11:5: 11:6 (#0),
+ span: $DIR/dump-debug-span-debug.rs:12:5: 12:6 (#0),
+ },
+ Punct {
+ ch: '&',
+ spacing: Joint,
+ span: $DIR/dump-debug-span-debug.rs:13:5: 13:6 (#0),
+ },
+ Punct {
+ ch: '&',
+ spacing: Alone,
+ span: $DIR/dump-debug-span-debug.rs:13:6: 13:7 (#0),
+ },
+ Punct {
+ ch: '|',
+ spacing: Joint,
+ span: $DIR/dump-debug-span-debug.rs:14:5: 14:6 (#0),
+ },
+ Punct {
+ ch: '|',
+ spacing: Joint,
+ span: $DIR/dump-debug-span-debug.rs:14:6: 14:7 (#0),
+ },
+ Punct {
+ ch: '>',
+ spacing: Alone,
+ span: $DIR/dump-debug-span-debug.rs:14:7: 14:8 (#0),
+ },
+ Punct {
+ ch: '|',
+ spacing: Joint,
+ span: $DIR/dump-debug-span-debug.rs:15:5: 15:6 (#0),
+ },
+ Punct {
+ ch: '|',
+ spacing: Joint,
+ span: $DIR/dump-debug-span-debug.rs:15:6: 15:7 (#0),
+ },
+ Punct {
+ ch: '<',
+ spacing: Joint,
+ span: $DIR/dump-debug-span-debug.rs:15:7: 15:8 (#0),
+ },
+ Punct {
+ ch: '<',
+ spacing: Alone,
+ span: $DIR/dump-debug-span-debug.rs:15:8: 15:9 (#0),
+ },
+ Punct {
+ ch: '.',
+ spacing: Joint,
+ span: $DIR/dump-debug-span-debug.rs:16:5: 16:6 (#0),
+ },
+ Punct {
+ ch: '.',
+ spacing: Joint,
+ span: $DIR/dump-debug-span-debug.rs:16:6: 16:7 (#0),
},
Punct {
ch: '=',
+ spacing: Alone,
+ span: $DIR/dump-debug-span-debug.rs:16:7: 16:8 (#0),
+ },
+ Punct {
+ ch: '<',
spacing: Joint,
- span: $DIR/dump-debug-span-debug.rs:12:5: 12:7 (#0),
+ span: $DIR/dump-debug-span-debug.rs:17:5: 17:6 (#0),
+ },
+ Punct {
+ ch: '<',
+ spacing: Joint,
+ span: $DIR/dump-debug-span-debug.rs:17:6: 17:7 (#0),
},
Punct {
ch: '=',
spacing: Joint,
- span: $DIR/dump-debug-span-debug.rs:12:5: 12:7 (#0),
+ span: $DIR/dump-debug-span-debug.rs:17:7: 17:8 (#0),
},
Punct {
- ch: '>',
+ ch: '!',
spacing: Alone,
- span: $DIR/dump-debug-span-debug.rs:12:7: 12:8 (#0),
+ span: $DIR/dump-debug-span-debug.rs:17:8: 17:9 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [],
- span: $DIR/dump-debug-span-debug.rs:13:5: 13:7 (#0),
+ span: $DIR/dump-debug-span-debug.rs:18:5: 18:7 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "_",
- span: $DIR/dump-debug-span-debug.rs:14:6: 14:7 (#0),
+ span: $DIR/dump-debug-span-debug.rs:19:6: 19:7 (#0),
},
],
- span: $DIR/dump-debug-span-debug.rs:14:5: 14:8 (#0),
+ span: $DIR/dump-debug-span-debug.rs:19:5: 19:8 (#0),
},
Literal {
kind: Integer,
symbol: "0",
suffix: None,
- span: $DIR/dump-debug-span-debug.rs:17:5: 17:6 (#0),
+ span: $DIR/dump-debug-span-debug.rs:22:5: 22:6 (#0),
},
Literal {
kind: Float,
symbol: "1.0",
suffix: None,
- span: $DIR/dump-debug-span-debug.rs:18:5: 18:8 (#0),
+ span: $DIR/dump-debug-span-debug.rs:23:5: 23:8 (#0),
},
Literal {
kind: Str,
symbol: "S",
suffix: None,
- span: $DIR/dump-debug-span-debug.rs:19:5: 19:8 (#0),
+ span: $DIR/dump-debug-span-debug.rs:24:5: 24:8 (#0),
},
Literal {
kind: ByteStr,
symbol: "B",
suffix: None,
- span: $DIR/dump-debug-span-debug.rs:20:5: 20:9 (#0),
+ span: $DIR/dump-debug-span-debug.rs:25:5: 25:9 (#0),
},
Literal {
kind: StrRaw(0),
symbol: "R",
suffix: None,
- span: $DIR/dump-debug-span-debug.rs:21:5: 21:9 (#0),
+ span: $DIR/dump-debug-span-debug.rs:26:5: 26:9 (#0),
},
Literal {
kind: StrRaw(2),
symbol: "R",
suffix: None,
- span: $DIR/dump-debug-span-debug.rs:22:5: 22:13 (#0),
+ span: $DIR/dump-debug-span-debug.rs:27:5: 27:13 (#0),
},
Literal {
kind: ByteStrRaw(0),
symbol: "BR",
suffix: None,
- span: $DIR/dump-debug-span-debug.rs:23:5: 23:11 (#0),
+ span: $DIR/dump-debug-span-debug.rs:28:5: 28:11 (#0),
},
Literal {
kind: ByteStrRaw(2),
symbol: "BR",
suffix: None,
- span: $DIR/dump-debug-span-debug.rs:24:5: 24:15 (#0),
+ span: $DIR/dump-debug-span-debug.rs:29:5: 29:15 (#0),
},
Literal {
kind: Char,
symbol: "C",
suffix: None,
- span: $DIR/dump-debug-span-debug.rs:25:5: 25:8 (#0),
+ span: $DIR/dump-debug-span-debug.rs:30:5: 30:8 (#0),
},
Literal {
kind: Byte,
symbol: "B",
suffix: None,
- span: $DIR/dump-debug-span-debug.rs:26:5: 26:9 (#0),
+ span: $DIR/dump-debug-span-debug.rs:31:5: 31:9 (#0),
},
Literal {
kind: Integer,
symbol: "0",
suffix: Some("q"),
- span: $DIR/dump-debug-span-debug.rs:29:5: 29:7 (#0),
+ span: $DIR/dump-debug-span-debug.rs:34:5: 34:7 (#0),
},
Literal {
kind: Float,
symbol: "1.0",
suffix: Some("q"),
- span: $DIR/dump-debug-span-debug.rs:30:5: 30:9 (#0),
+ span: $DIR/dump-debug-span-debug.rs:35:5: 35:9 (#0),
},
Literal {
kind: Str,
symbol: "S",
suffix: Some("q"),
- span: $DIR/dump-debug-span-debug.rs:31:5: 31:9 (#0),
+ span: $DIR/dump-debug-span-debug.rs:36:5: 36:9 (#0),
},
Literal {
kind: ByteStr,
symbol: "B",
suffix: Some("q"),
- span: $DIR/dump-debug-span-debug.rs:32:5: 32:10 (#0),
+ span: $DIR/dump-debug-span-debug.rs:37:5: 37:10 (#0),
},
Literal {
kind: StrRaw(0),
symbol: "R",
suffix: Some("q"),
- span: $DIR/dump-debug-span-debug.rs:33:5: 33:10 (#0),
+ span: $DIR/dump-debug-span-debug.rs:38:5: 38:10 (#0),
},
Literal {
kind: StrRaw(2),
symbol: "R",
suffix: Some("q"),
- span: $DIR/dump-debug-span-debug.rs:34:5: 34:14 (#0),
+ span: $DIR/dump-debug-span-debug.rs:39:5: 39:14 (#0),
},
Literal {
kind: ByteStrRaw(0),
symbol: "BR",
suffix: Some("q"),
- span: $DIR/dump-debug-span-debug.rs:35:5: 35:12 (#0),
+ span: $DIR/dump-debug-span-debug.rs:40:5: 40:12 (#0),
},
Literal {
kind: ByteStrRaw(2),
symbol: "BR",
suffix: Some("q"),
- span: $DIR/dump-debug-span-debug.rs:36:5: 36:16 (#0),
+ span: $DIR/dump-debug-span-debug.rs:41:5: 41:16 (#0),
},
Literal {
kind: Char,
symbol: "C",
suffix: Some("q"),
- span: $DIR/dump-debug-span-debug.rs:37:5: 37:9 (#0),
+ span: $DIR/dump-debug-span-debug.rs:42:5: 42:9 (#0),
},
Literal {
kind: Byte,
symbol: "B",
suffix: Some("q"),
- span: $DIR/dump-debug-span-debug.rs:38:5: 38:10 (#0),
+ span: $DIR/dump-debug-span-debug.rs:43:5: 43:10 (#0),
},
]
diff --git a/src/test/ui/proc-macro/debug/dump-debug.stderr b/src/test/ui/proc-macro/debug/dump-debug.stderr
index 0aedefd4e..db422b601 100644
--- a/src/test/ui/proc-macro/debug/dump-debug.stderr
+++ b/src/test/ui/proc-macro/debug/dump-debug.stderr
@@ -1,4 +1,4 @@
-TokenStream [Ident { ident: "ident", span: #0 bytes(130..135) }, Ident { ident: "r#ident", span: #0 bytes(151..158) }, Punct { ch: ',', spacing: Alone, span: #0 bytes(176..177) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(203..205) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(203..205) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(205..206) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(230..232) }, Group { delimiter: Bracket, stream: TokenStream [Ident { ident: "_", span: #0 bytes(258..259) }], span: #0 bytes(257..260) }, Literal { kind: Integer, symbol: "0", suffix: None, span: #0 bytes(315..316) }, Literal { kind: Float, symbol: "1.0", suffix: None, span: #0 bytes(321..324) }, Literal { kind: Str, symbol: "S", suffix: None, span: #0 bytes(329..332) }, Literal { kind: ByteStr, symbol: "B", suffix: None, span: #0 bytes(337..341) }, Literal { kind: StrRaw(0), symbol: "R", suffix: None, span: #0 bytes(346..350) }, Literal { kind: StrRaw(2), symbol: "R", suffix: None, span: #0 bytes(355..363) }, Literal { kind: ByteStrRaw(0), symbol: "BR", suffix: None, span: #0 bytes(368..374) }, Literal { kind: ByteStrRaw(2), symbol: "BR", suffix: None, span: #0 bytes(379..389) }, Literal { kind: Char, symbol: "C", suffix: None, span: #0 bytes(394..397) }, Literal { kind: Byte, symbol: "B", suffix: None, span: #0 bytes(402..406) }, Literal { kind: Integer, symbol: "0", suffix: Some("q"), span: #0 bytes(437..439) }, Literal { kind: Float, symbol: "1.0", suffix: Some("q"), span: #0 bytes(444..448) }, Literal { kind: Str, symbol: "S", suffix: Some("q"), span: #0 bytes(453..457) }, Literal { kind: ByteStr, symbol: "B", suffix: Some("q"), span: #0 bytes(462..467) }, Literal { kind: StrRaw(0), symbol: "R", suffix: Some("q"), span: #0 bytes(472..477) }, Literal { kind: StrRaw(2), symbol: "R", suffix: Some("q"), span: #0 bytes(482..491) }, Literal { kind: ByteStrRaw(0), symbol: "BR", suffix: Some("q"), span: #0 bytes(496..503) }, Literal { kind: ByteStrRaw(2), symbol: "BR", suffix: Some("q"), span: #0 bytes(508..519) }, Literal { kind: Char, symbol: "C", suffix: Some("q"), span: #0 bytes(524..528) }, Literal { kind: Byte, symbol: "B", suffix: Some("q"), span: #0 bytes(533..538) }]
+TokenStream [Ident { ident: "ident", span: #0 bytes(130..135) }, Ident { ident: "r#ident", span: #0 bytes(151..158) }, Punct { ch: ',', spacing: Alone, span: #0 bytes(176..177) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(203..204) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(204..205) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(205..206) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(230..232) }, Group { delimiter: Bracket, stream: TokenStream [Ident { ident: "_", span: #0 bytes(258..259) }], span: #0 bytes(257..260) }, Literal { kind: Integer, symbol: "0", suffix: None, span: #0 bytes(315..316) }, Literal { kind: Float, symbol: "1.0", suffix: None, span: #0 bytes(321..324) }, Literal { kind: Str, symbol: "S", suffix: None, span: #0 bytes(329..332) }, Literal { kind: ByteStr, symbol: "B", suffix: None, span: #0 bytes(337..341) }, Literal { kind: StrRaw(0), symbol: "R", suffix: None, span: #0 bytes(346..350) }, Literal { kind: StrRaw(2), symbol: "R", suffix: None, span: #0 bytes(355..363) }, Literal { kind: ByteStrRaw(0), symbol: "BR", suffix: None, span: #0 bytes(368..374) }, Literal { kind: ByteStrRaw(2), symbol: "BR", suffix: None, span: #0 bytes(379..389) }, Literal { kind: Char, symbol: "C", suffix: None, span: #0 bytes(394..397) }, Literal { kind: Byte, symbol: "B", suffix: None, span: #0 bytes(402..406) }, Literal { kind: Integer, symbol: "0", suffix: Some("q"), span: #0 bytes(437..439) }, Literal { kind: Float, symbol: "1.0", suffix: Some("q"), span: #0 bytes(444..448) }, Literal { kind: Str, symbol: "S", suffix: Some("q"), span: #0 bytes(453..457) }, Literal { kind: ByteStr, symbol: "B", suffix: Some("q"), span: #0 bytes(462..467) }, Literal { kind: StrRaw(0), symbol: "R", suffix: Some("q"), span: #0 bytes(472..477) }, Literal { kind: StrRaw(2), symbol: "R", suffix: Some("q"), span: #0 bytes(482..491) }, Literal { kind: ByteStrRaw(0), symbol: "BR", suffix: Some("q"), span: #0 bytes(496..503) }, Literal { kind: ByteStrRaw(2), symbol: "BR", suffix: Some("q"), span: #0 bytes(508..519) }, Literal { kind: Char, symbol: "C", suffix: Some("q"), span: #0 bytes(524..528) }, Literal { kind: Byte, symbol: "B", suffix: Some("q"), span: #0 bytes(533..538) }]
TokenStream [
Ident {
ident: "ident",
@@ -16,12 +16,12 @@ TokenStream [
Punct {
ch: '=',
spacing: Joint,
- span: #0 bytes(203..205),
+ span: #0 bytes(203..204),
},
Punct {
ch: '=',
spacing: Joint,
- span: #0 bytes(203..205),
+ span: #0 bytes(204..205),
},
Punct {
ch: '>',
diff --git a/src/test/ui/proc-macro/derive-bad.stderr b/src/test/ui/proc-macro/derive-bad.stderr
index ae48141fb..241f99b28 100644
--- a/src/test/ui/proc-macro/derive-bad.stderr
+++ b/src/test/ui/proc-macro/derive-bad.stderr
@@ -2,7 +2,10 @@ error: expected `:`, found `}`
--> $DIR/derive-bad.rs:6:10
|
LL | #[derive(A)]
- | ^ expected `:`
+ | ^
+ | |
+ | expected `:`
+ | while parsing this struct
|
= note: this error originates in the derive macro `A` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/src/test/ui/proc-macro/derive-helper-shadowing.stderr b/src/test/ui/proc-macro/derive-helper-shadowing.stderr
index d8287eb73..9c52ca422 100644
--- a/src/test/ui/proc-macro/derive-helper-shadowing.stderr
+++ b/src/test/ui/proc-macro/derive-helper-shadowing.stderr
@@ -80,9 +80,9 @@ LL | #[empty_helper]
LL | #[derive(Empty)]
| ----- the attribute is introduced here
|
- = note: `#[warn(legacy_derive_helpers)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #79202 <https://github.com/rust-lang/rust/issues/79202>
+ = note: `#[warn(legacy_derive_helpers)]` on by default
error: aborting due to 5 previous errors; 1 warning emitted
diff --git a/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout b/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout
index c0c9ed72c..2622c005d 100644
--- a/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout
+++ b/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout
@@ -18,12 +18,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
Punct {
ch: ':',
spacing: Joint,
- span: $DIR/dollar-crate-issue-57089.rs:17:28: 17:30 (#4),
+ span: $DIR/dollar-crate-issue-57089.rs:17:28: 17:29 (#4),
},
Punct {
ch: ':',
spacing: Alone,
- span: $DIR/dollar-crate-issue-57089.rs:17:28: 17:30 (#4),
+ span: $DIR/dollar-crate-issue-57089.rs:17:29: 17:30 (#4),
},
Ident {
ident: "S",
@@ -58,12 +58,12 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: ':',
spacing: Joint,
- span: $DIR/dollar-crate-issue-57089.rs:21:24: 21:26 (#4),
+ span: $DIR/dollar-crate-issue-57089.rs:21:24: 21:25 (#4),
},
Punct {
ch: ':',
spacing: Alone,
- span: $DIR/dollar-crate-issue-57089.rs:21:24: 21:26 (#4),
+ span: $DIR/dollar-crate-issue-57089.rs:21:25: 21:26 (#4),
},
Ident {
ident: "S",
diff --git a/src/test/ui/proc-macro/dollar-crate-issue-62325.stdout b/src/test/ui/proc-macro/dollar-crate-issue-62325.stdout
index e6148a687..a91908239 100644
--- a/src/test/ui/proc-macro/dollar-crate-issue-62325.stdout
+++ b/src/test/ui/proc-macro/dollar-crate-issue-62325.stdout
@@ -30,12 +30,12 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: ':',
spacing: Joint,
- span: $DIR/dollar-crate-issue-62325.rs:19:30: 19:32 (#4),
+ span: $DIR/dollar-crate-issue-62325.rs:19:30: 19:31 (#4),
},
Punct {
ch: ':',
spacing: Alone,
- span: $DIR/dollar-crate-issue-62325.rs:19:30: 19:32 (#4),
+ span: $DIR/dollar-crate-issue-62325.rs:19:31: 19:32 (#4),
},
Ident {
ident: "S",
@@ -85,12 +85,12 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: ':',
spacing: Joint,
- span: $DIR/auxiliary/dollar-crate-external.rs:21:30: 21:32 (#12),
+ span: $DIR/auxiliary/dollar-crate-external.rs:21:30: 21:31 (#12),
},
Punct {
ch: ':',
spacing: Alone,
- span: $DIR/auxiliary/dollar-crate-external.rs:21:30: 21:32 (#12),
+ span: $DIR/auxiliary/dollar-crate-external.rs:21:31: 21:32 (#12),
},
Ident {
ident: "S",
diff --git a/src/test/ui/proc-macro/dollar-crate.stdout b/src/test/ui/proc-macro/dollar-crate.stdout
index d01fcb9d0..4e169d47e 100644
--- a/src/test/ui/proc-macro/dollar-crate.stdout
+++ b/src/test/ui/proc-macro/dollar-crate.stdout
@@ -18,12 +18,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
Punct {
ch: ':',
spacing: Joint,
- span: $DIR/dollar-crate.rs:20:32: 20:34 (#4),
+ span: $DIR/dollar-crate.rs:20:32: 20:33 (#4),
},
Punct {
ch: ':',
spacing: Alone,
- span: $DIR/dollar-crate.rs:20:32: 20:34 (#4),
+ span: $DIR/dollar-crate.rs:20:33: 20:34 (#4),
},
Ident {
ident: "S",
@@ -58,12 +58,12 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: ':',
spacing: Joint,
- span: $DIR/dollar-crate.rs:24:28: 24:30 (#4),
+ span: $DIR/dollar-crate.rs:24:28: 24:29 (#4),
},
Punct {
ch: ':',
spacing: Alone,
- span: $DIR/dollar-crate.rs:24:28: 24:30 (#4),
+ span: $DIR/dollar-crate.rs:24:29: 24:30 (#4),
},
Ident {
ident: "S",
@@ -98,12 +98,12 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
Punct {
ch: ':',
spacing: Joint,
- span: $DIR/dollar-crate.rs:27:28: 27:30 (#4),
+ span: $DIR/dollar-crate.rs:27:28: 27:29 (#4),
},
Punct {
ch: ':',
spacing: Alone,
- span: $DIR/dollar-crate.rs:27:28: 27:30 (#4),
+ span: $DIR/dollar-crate.rs:27:29: 27:30 (#4),
},
Ident {
ident: "S",
@@ -138,12 +138,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
Punct {
ch: ':',
spacing: Joint,
- span: $DIR/auxiliary/dollar-crate-external.rs:7:28: 7:30 (#15),
+ span: $DIR/auxiliary/dollar-crate-external.rs:7:28: 7:29 (#15),
},
Punct {
ch: ':',
spacing: Alone,
- span: $DIR/auxiliary/dollar-crate-external.rs:7:28: 7:30 (#15),
+ span: $DIR/auxiliary/dollar-crate-external.rs:7:29: 7:30 (#15),
},
Ident {
ident: "S",
@@ -178,12 +178,12 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: ':',
spacing: Joint,
- span: $DIR/auxiliary/dollar-crate-external.rs:11:24: 11:26 (#15),
+ span: $DIR/auxiliary/dollar-crate-external.rs:11:24: 11:25 (#15),
},
Punct {
ch: ':',
spacing: Alone,
- span: $DIR/auxiliary/dollar-crate-external.rs:11:24: 11:26 (#15),
+ span: $DIR/auxiliary/dollar-crate-external.rs:11:25: 11:26 (#15),
},
Ident {
ident: "S",
@@ -218,12 +218,12 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
Punct {
ch: ':',
spacing: Joint,
- span: $DIR/auxiliary/dollar-crate-external.rs:14:24: 14:26 (#15),
+ span: $DIR/auxiliary/dollar-crate-external.rs:14:24: 14:25 (#15),
},
Punct {
ch: ':',
spacing: Alone,
- span: $DIR/auxiliary/dollar-crate-external.rs:14:24: 14:26 (#15),
+ span: $DIR/auxiliary/dollar-crate-external.rs:14:25: 14:26 (#15),
},
Ident {
ident: "S",
diff --git a/src/test/ui/proc-macro/expand-with-a-macro.rs b/src/test/ui/proc-macro/expand-with-a-macro.rs
index 21a4547d1..042a28365 100644
--- a/src/test/ui/proc-macro/expand-with-a-macro.rs
+++ b/src/test/ui/proc-macro/expand-with-a-macro.rs
@@ -2,7 +2,6 @@
// needs-unwind
// aux-build:expand-with-a-macro.rs
-// ignore-wasm32-bare compiled with panic=abort by default
#![deny(warnings)]
diff --git a/src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr b/src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr
index 6060f872f..df7c4f72e 100644
--- a/src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr
+++ b/src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr
@@ -13,7 +13,7 @@ error[E0425]: cannot find value `local_use` in this scope
--> $DIR/gen-macro-rules-hygiene.rs:12:1
|
LL | gen_macro_rules!();
- | ^^^^^^^^^^^^^^^^^^ not found in this scope
+ | ^^^^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `local_def`
...
LL | generated!();
| ------------ in this macro invocation
@@ -24,7 +24,7 @@ error[E0425]: cannot find value `local_def` in this scope
--> $DIR/gen-macro-rules-hygiene.rs:21:9
|
LL | local_def;
- | ^^^^^^^^^ not found in this scope
+ | ^^^^^^^^^ help: a local variable with a similar name exists: `local_use`
error: aborting due to 3 previous errors
diff --git a/src/test/ui/proc-macro/generate-mod.stderr b/src/test/ui/proc-macro/generate-mod.stderr
index f1a167e37..39bf28dba 100644
--- a/src/test/ui/proc-macro/generate-mod.stderr
+++ b/src/test/ui/proc-macro/generate-mod.stderr
@@ -44,9 +44,9 @@ error: cannot find type `FromOutside` in this scope
LL | #[derive(generate_mod::CheckDerive)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
|
- = note: `#[deny(proc_macro_derive_resolution_fallback)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
+ = note: `#[deny(proc_macro_derive_resolution_fallback)]` on by default
= note: this error originates in the derive macro `generate_mod::CheckDerive` (in Nightly builds, run with -Z macro-backtrace for more info)
error: cannot find type `OuterDerive` in this scope
@@ -89,9 +89,9 @@ error: cannot find type `FromOutside` in this scope
LL | #[derive(generate_mod::CheckDerive)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
|
- = note: `#[deny(proc_macro_derive_resolution_fallback)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
+ = note: `#[deny(proc_macro_derive_resolution_fallback)]` on by default
= note: this error originates in the derive macro `generate_mod::CheckDerive` (in Nightly builds, run with -Z macro-backtrace for more info)
Future breakage diagnostic:
@@ -101,9 +101,9 @@ error: cannot find type `OuterDerive` in this scope
LL | #[derive(generate_mod::CheckDerive)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
|
- = note: `#[deny(proc_macro_derive_resolution_fallback)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
+ = note: `#[deny(proc_macro_derive_resolution_fallback)]` on by default
= note: this error originates in the derive macro `generate_mod::CheckDerive` (in Nightly builds, run with -Z macro-backtrace for more info)
Future breakage diagnostic:
@@ -113,9 +113,9 @@ error: cannot find type `FromOutside` in this scope
LL | #[derive(generate_mod::CheckDerive)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
|
- = note: `#[deny(proc_macro_derive_resolution_fallback)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
+ = note: `#[deny(proc_macro_derive_resolution_fallback)]` on by default
= note: this error originates in the derive macro `generate_mod::CheckDerive` (in Nightly builds, run with -Z macro-backtrace for more info)
Future breakage diagnostic:
@@ -125,9 +125,9 @@ error: cannot find type `OuterDerive` in this scope
LL | #[derive(generate_mod::CheckDerive)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
|
- = note: `#[deny(proc_macro_derive_resolution_fallback)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
+ = note: `#[deny(proc_macro_derive_resolution_fallback)]` on by default
= note: this error originates in the derive macro `generate_mod::CheckDerive` (in Nightly builds, run with -Z macro-backtrace for more info)
Future breakage diagnostic:
@@ -137,13 +137,13 @@ warning: cannot find type `FromOutside` in this scope
LL | #[derive(generate_mod::CheckDeriveLint)] // OK, lint is suppressed
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
note: the lint level is defined here
--> $DIR/generate-mod.rs:30:10
|
LL | #[derive(generate_mod::CheckDeriveLint)] // OK, lint is suppressed
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
= note: this warning originates in the derive macro `generate_mod::CheckDeriveLint` (in Nightly builds, run with -Z macro-backtrace for more info)
Future breakage diagnostic:
@@ -153,12 +153,12 @@ warning: cannot find type `OuterDeriveLint` in this scope
LL | #[derive(generate_mod::CheckDeriveLint)] // OK, lint is suppressed
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
note: the lint level is defined here
--> $DIR/generate-mod.rs:30:10
|
LL | #[derive(generate_mod::CheckDeriveLint)] // OK, lint is suppressed
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #83583 <https://github.com/rust-lang/rust/issues/83583>
= note: this warning originates in the derive macro `generate_mod::CheckDeriveLint` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/src/test/ui/proc-macro/helper-attr-blocked-by-import-ambig.stderr b/src/test/ui/proc-macro/helper-attr-blocked-by-import-ambig.stderr
index 45b014c4b..9441cdcc8 100644
--- a/src/test/ui/proc-macro/helper-attr-blocked-by-import-ambig.stderr
+++ b/src/test/ui/proc-macro/helper-attr-blocked-by-import-ambig.stderr
@@ -26,9 +26,9 @@ LL | #[empty_helper]
LL | #[derive(Empty)]
| ----- the attribute is introduced here
|
- = note: `#[warn(legacy_derive_helpers)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #79202 <https://github.com/rust-lang/rust/issues/79202>
+ = note: `#[warn(legacy_derive_helpers)]` on by default
error: aborting due to previous error; 1 warning emitted
diff --git a/src/test/ui/proc-macro/inner-attr-non-inline-mod.stderr b/src/test/ui/proc-macro/inner-attr-non-inline-mod.stderr
index 4286896df..2d357d04d 100644
--- a/src/test/ui/proc-macro/inner-attr-non-inline-mod.stderr
+++ b/src/test/ui/proc-macro/inner-attr-non-inline-mod.stderr
@@ -31,9 +31,9 @@ error: custom inner attributes are unstable
LL | #![rustfmt::skip]
| ^^^^^^^^^^^^^
|
- = note: `#[deny(soft_unstable)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
+ = note: `#[deny(soft_unstable)]` on by default
error: aborting due to 4 previous errors
diff --git a/src/test/ui/proc-macro/inner-attrs.stdout b/src/test/ui/proc-macro/inner-attrs.stdout
index 490fc02f5..ee8adf0b4 100644
--- a/src/test/ui/proc-macro/inner-attrs.stdout
+++ b/src/test/ui/proc-macro/inner-attrs.stdout
@@ -627,12 +627,12 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
Punct {
ch: '=',
spacing: Joint,
- span: $DIR/inner-attrs.rs:39:15: 39:17 (#0),
+ span: $DIR/inner-attrs.rs:39:15: 39:16 (#0),
},
Punct {
ch: '>',
spacing: Alone,
- span: $DIR/inner-attrs.rs:39:15: 39:17 (#0),
+ span: $DIR/inner-attrs.rs:39:16: 39:17 (#0),
},
Group {
delimiter: Brace,
diff --git a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.rs b/src/test/ui/proc-macro/issue-73933-procedural-masquerade.rs
index 0c1c51c01..a573c6e1c 100644
--- a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.rs
+++ b/src/test/ui/proc-macro/issue-73933-procedural-masquerade.rs
@@ -1,18 +1,11 @@
// aux-build:test-macros.rs
+// check-pass
#[macro_use]
extern crate test_macros;
#[derive(Print)]
enum ProceduralMasqueradeDummyType {
-//~^ ERROR using
-//~| WARN this was previously
-//~| ERROR using
-//~| WARN this was previously
-//~| ERROR using
-//~| WARN this was previously
-//~| ERROR using
-//~| WARN this was previously
Input
}
diff --git a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stderr b/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stderr
deleted file mode 100644
index be4239089..000000000
--- a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stderr
+++ /dev/null
@@ -1,91 +0,0 @@
-error: using `procedural-masquerade` crate
- --> $DIR/issue-73933-procedural-masquerade.rs:7:6
- |
-LL | enum ProceduralMasqueradeDummyType {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: `#[deny(proc_macro_back_compat)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
- = note: The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. Versions of this crate below 0.1.7 will eventually stop compiling.
-
-error: using `procedural-masquerade` crate
- --> $DIR/issue-73933-procedural-masquerade.rs:7:6
- |
-LL | enum ProceduralMasqueradeDummyType {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
- = note: The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. Versions of this crate below 0.1.7 will eventually stop compiling.
-
-error: using `procedural-masquerade` crate
- --> $DIR/issue-73933-procedural-masquerade.rs:7:6
- |
-LL | enum ProceduralMasqueradeDummyType {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
- = note: The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. Versions of this crate below 0.1.7 will eventually stop compiling.
-
-error: using `procedural-masquerade` crate
- --> $DIR/issue-73933-procedural-masquerade.rs:7:6
- |
-LL | enum ProceduralMasqueradeDummyType {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
- = note: The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. Versions of this crate below 0.1.7 will eventually stop compiling.
-
-error: aborting due to 4 previous errors
-
-Future incompatibility report: Future breakage diagnostic:
-error: using `procedural-masquerade` crate
- --> $DIR/issue-73933-procedural-masquerade.rs:7:6
- |
-LL | enum ProceduralMasqueradeDummyType {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: `#[deny(proc_macro_back_compat)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
- = note: The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. Versions of this crate below 0.1.7 will eventually stop compiling.
-
-Future breakage diagnostic:
-error: using `procedural-masquerade` crate
- --> $DIR/issue-73933-procedural-masquerade.rs:7:6
- |
-LL | enum ProceduralMasqueradeDummyType {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: `#[deny(proc_macro_back_compat)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
- = note: The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. Versions of this crate below 0.1.7 will eventually stop compiling.
-
-Future breakage diagnostic:
-error: using `procedural-masquerade` crate
- --> $DIR/issue-73933-procedural-masquerade.rs:7:6
- |
-LL | enum ProceduralMasqueradeDummyType {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: `#[deny(proc_macro_back_compat)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
- = note: The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. Versions of this crate below 0.1.7 will eventually stop compiling.
-
-Future breakage diagnostic:
-error: using `procedural-masquerade` crate
- --> $DIR/issue-73933-procedural-masquerade.rs:7:6
- |
-LL | enum ProceduralMasqueradeDummyType {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: `#[deny(proc_macro_back_compat)]` on by default
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
- = note: The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. Versions of this crate below 0.1.7 will eventually stop compiling.
-
diff --git a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stdout b/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stdout
index 50334589d..8cd981e03 100644
--- a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stdout
+++ b/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stdout
@@ -1,22 +1,21 @@
-PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input, }
-PRINT-DERIVE RE-COLLECTED (DISPLAY): enum ProceduralMasqueradeDummyType { Input }
+PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input }
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "enum",
- span: #0 bytes(86..90),
+ span: #0 bytes(100..104),
},
Ident {
ident: "ProceduralMasqueradeDummyType",
- span: #0 bytes(91..120),
+ span: #0 bytes(105..134),
},
Group {
delimiter: Brace,
stream: TokenStream [
Ident {
ident: "Input",
- span: #0 bytes(315..320),
+ span: #0 bytes(141..146),
},
],
- span: #0 bytes(121..322),
+ span: #0 bytes(135..148),
},
]
diff --git a/src/test/ui/proc-macro/issue-75930-derive-cfg.stderr b/src/test/ui/proc-macro/issue-75930-derive-cfg.stderr
index 69d72b55c..6d1efb0dc 100644
--- a/src/test/ui/proc-macro/issue-75930-derive-cfg.stderr
+++ b/src/test/ui/proc-macro/issue-75930-derive-cfg.stderr
@@ -7,9 +7,9 @@ LL | #[print_helper(a)]
LL | #[derive(Print)]
| ----- the attribute is introduced here
|
- = note: `#[warn(legacy_derive_helpers)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #79202 <https://github.com/rust-lang/rust/issues/79202>
+ = note: `#[warn(legacy_derive_helpers)]` on by default
warning: derive helper attribute is used before it is introduced
--> $DIR/issue-75930-derive-cfg.rs:19:3
diff --git a/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout b/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout
index c81fa201c..83afd0d3e 100644
--- a/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout
+++ b/src/test/ui/proc-macro/issue-75930-derive-cfg.stdout
@@ -489,12 +489,12 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '=',
spacing: Joint,
- span: $DIR/issue-75930-derive-cfg.rs:33:32: 33:34 (#0),
+ span: $DIR/issue-75930-derive-cfg.rs:33:32: 33:33 (#0),
},
Punct {
ch: '>',
spacing: Alone,
- span: $DIR/issue-75930-derive-cfg.rs:33:32: 33:34 (#0),
+ span: $DIR/issue-75930-derive-cfg.rs:33:33: 33:34 (#0),
},
Group {
delimiter: Brace,
@@ -567,12 +567,12 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '=',
spacing: Joint,
- span: $DIR/issue-75930-derive-cfg.rs:34:60: 34:62 (#0),
+ span: $DIR/issue-75930-derive-cfg.rs:34:60: 34:61 (#0),
},
Punct {
ch: '>',
spacing: Alone,
- span: $DIR/issue-75930-derive-cfg.rs:34:60: 34:62 (#0),
+ span: $DIR/issue-75930-derive-cfg.rs:34:61: 34:62 (#0),
},
Group {
delimiter: Brace,
@@ -591,12 +591,12 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '=',
spacing: Joint,
- span: $DIR/issue-75930-derive-cfg.rs:35:15: 35:17 (#0),
+ span: $DIR/issue-75930-derive-cfg.rs:35:15: 35:16 (#0),
},
Punct {
ch: '>',
spacing: Alone,
- span: $DIR/issue-75930-derive-cfg.rs:35:15: 35:17 (#0),
+ span: $DIR/issue-75930-derive-cfg.rs:35:16: 35:17 (#0),
},
Group {
delimiter: Brace,
@@ -1519,12 +1519,12 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
Punct {
ch: '=',
spacing: Joint,
- span: $DIR/issue-75930-derive-cfg.rs:34:60: 34:62 (#0),
+ span: $DIR/issue-75930-derive-cfg.rs:34:60: 34:61 (#0),
},
Punct {
ch: '>',
spacing: Alone,
- span: $DIR/issue-75930-derive-cfg.rs:34:60: 34:62 (#0),
+ span: $DIR/issue-75930-derive-cfg.rs:34:61: 34:62 (#0),
},
Group {
delimiter: Brace,
@@ -1543,12 +1543,12 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
Punct {
ch: '=',
spacing: Joint,
- span: $DIR/issue-75930-derive-cfg.rs:35:15: 35:17 (#0),
+ span: $DIR/issue-75930-derive-cfg.rs:35:15: 35:16 (#0),
},
Punct {
ch: '>',
spacing: Alone,
- span: $DIR/issue-75930-derive-cfg.rs:35:15: 35:17 (#0),
+ span: $DIR/issue-75930-derive-cfg.rs:35:16: 35:17 (#0),
},
Group {
delimiter: Brace,
diff --git a/src/test/ui/proc-macro/issue-76182-leading-vert-pat.stdout b/src/test/ui/proc-macro/issue-76182-leading-vert-pat.stdout
index 5493f9c7b..09eb33f7e 100644
--- a/src/test/ui/proc-macro/issue-76182-leading-vert-pat.stdout
+++ b/src/test/ui/proc-macro/issue-76182-leading-vert-pat.stdout
@@ -41,12 +41,12 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '=',
spacing: Joint,
- span: $DIR/issue-76182-leading-vert-pat.rs:15:21: 15:23 (#0),
+ span: $DIR/issue-76182-leading-vert-pat.rs:15:21: 15:22 (#0),
},
Punct {
ch: '>',
spacing: Alone,
- span: $DIR/issue-76182-leading-vert-pat.rs:15:21: 15:23 (#0),
+ span: $DIR/issue-76182-leading-vert-pat.rs:15:22: 15:23 (#0),
},
Group {
delimiter: Parenthesis,
diff --git a/src/test/ui/proc-macro/keep-expr-tokens.stderr b/src/test/ui/proc-macro/keep-expr-tokens.stderr
index 11052d11c..1a1f83cc1 100644
--- a/src/test/ui/proc-macro/keep-expr-tokens.stderr
+++ b/src/test/ui/proc-macro/keep-expr-tokens.stderr
@@ -1,15 +1,15 @@
-error[E0425]: cannot find function `missing_fn` in this scope
- --> $DIR/keep-expr-tokens.rs:17:17
- |
-LL | for item in missing_fn() {}
- | ^^^^^^^^^^ not found in this scope
-
error[E0425]: cannot find value `bad` in this scope
--> $DIR/keep-expr-tokens.rs:19:62
|
LL | (#[recollect_attr] #[recollect_attr] ((#[recollect_attr] bad)));
| ^^^ not found in this scope
+error[E0425]: cannot find function `missing_fn` in this scope
+ --> $DIR/keep-expr-tokens.rs:17:17
+ |
+LL | for item in missing_fn() {}
+ | ^^^^^^^^^^ not found in this scope
+
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/proc-macro/meta-macro-hygiene.rs b/src/test/ui/proc-macro/meta-macro-hygiene.rs
index 62968ea54..70b8d8da1 100644
--- a/src/test/ui/proc-macro/meta-macro-hygiene.rs
+++ b/src/test/ui/proc-macro/meta-macro-hygiene.rs
@@ -19,8 +19,8 @@ macro_rules! produce_it {
// `print_def_site!` will respan the `$crate` identifier
// with `Span::def_site()`. This should cause it to resolve
// relative to `meta_macro`, *not* `make_macro` (despite
- // the fact that that `print_def_site` is produced by
- // a `macro_rules!` macro in `make_macro`).
+ // the fact that `print_def_site` is produced by a
+ // `macro_rules!` macro in `make_macro`).
meta_macro::print_def_site!($crate::dummy!());
}
}
diff --git a/src/test/ui/proc-macro/meta-macro-hygiene.stdout b/src/test/ui/proc-macro/meta-macro-hygiene.stdout
index 5d04fe1e3..6b7b0c819 100644
--- a/src/test/ui/proc-macro/meta-macro-hygiene.stdout
+++ b/src/test/ui/proc-macro/meta-macro-hygiene.stdout
@@ -1,5 +1,5 @@
Def site: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#5)
-Input: TokenStream [Ident { ident: "$crate", span: $DIR/meta-macro-hygiene.rs:24:37: 24:43 (#4) }, Punct { ch: ':', spacing: Joint, span: $DIR/meta-macro-hygiene.rs:24:43: 24:45 (#4) }, Punct { ch: ':', spacing: Alone, span: $DIR/meta-macro-hygiene.rs:24:43: 24:45 (#4) }, Ident { ident: "dummy", span: $DIR/meta-macro-hygiene.rs:24:45: 24:50 (#4) }, Punct { ch: '!', spacing: Alone, span: $DIR/meta-macro-hygiene.rs:24:50: 24:51 (#4) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: $DIR/meta-macro-hygiene.rs:24:51: 24:53 (#4) }]
+Input: TokenStream [Ident { ident: "$crate", span: $DIR/meta-macro-hygiene.rs:24:37: 24:43 (#4) }, Punct { ch: ':', spacing: Joint, span: $DIR/meta-macro-hygiene.rs:24:43: 24:44 (#4) }, Punct { ch: ':', spacing: Alone, span: $DIR/meta-macro-hygiene.rs:24:44: 24:45 (#4) }, Ident { ident: "dummy", span: $DIR/meta-macro-hygiene.rs:24:45: 24:50 (#4) }, Punct { ch: '!', spacing: Alone, span: $DIR/meta-macro-hygiene.rs:24:50: 24:51 (#4) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: $DIR/meta-macro-hygiene.rs:24:51: 24:53 (#4) }]
Respanned: TokenStream [Ident { ident: "$crate", span: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#5) }, Punct { ch: ':', spacing: Joint, span: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#5) }, Punct { ch: ':', spacing: Alone, span: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#5) }, Ident { ident: "dummy", span: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#5) }, Punct { ch: '!', spacing: Alone, span: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#5) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: $DIR/auxiliary/make-macro.rs:7:9: 7:56 (#5) }]
#![feature /* 0#0 */(prelude_import)]
// aux-build:make-macro.rs
@@ -35,8 +35,8 @@ macro_rules! produce_it
// `print_def_site!` will respan the `$crate` identifier
// with `Span::def_site()`. This should cause it to resolve
// relative to `meta_macro`, *not* `make_macro` (despite
- // the fact that that `print_def_site` is produced by
- // a `macro_rules!` macro in `make_macro`).
+ // the fact that `print_def_site` is produced by a
+ // `macro_rules!` macro in `make_macro`).
}
}
diff --git a/src/test/ui/proc-macro/mixed-site-span.stderr b/src/test/ui/proc-macro/mixed-site-span.stderr
index eab4317de..137860801 100644
--- a/src/test/ui/proc-macro/mixed-site-span.stderr
+++ b/src/test/ui/proc-macro/mixed-site-span.stderr
@@ -10,7 +10,7 @@ error[E0425]: cannot find value `local_use` in this scope
--> $DIR/mixed-site-span.rs:13:9
|
LL | proc_macro_rules!();
- | ^^^^^^^^^^^^^^^^^^^ not found in this scope
+ | ^^^^^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `local_def`
|
= note: this error originates in the macro `proc_macro_rules` (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -18,7 +18,7 @@ error[E0425]: cannot find value `local_def` in this scope
--> $DIR/mixed-site-span.rs:17:9
|
LL | local_def;
- | ^^^^^^^^^ not found in this scope
+ | ^^^^^^^^^ help: a local variable with a similar name exists: `local_use`
error[E0412]: cannot find type `ItemUse` in crate `$crate`
--> $DIR/mixed-site-span.rs:24:1
diff --git a/src/test/ui/proc-macro/pretty-print-hack-hide.rs b/src/test/ui/proc-macro/pretty-print-hack-hide.rs
new file mode 100644
index 000000000..f53e8fe82
--- /dev/null
+++ b/src/test/ui/proc-macro/pretty-print-hack-hide.rs
@@ -0,0 +1,12 @@
+// aux-build:test-macros.rs
+// compile-flags: -Z span-debug
+// check-pass
+
+#![no_std] // Don't load unnecessary hygiene information from std
+extern crate std;
+
+#[macro_use] extern crate test_macros;
+
+include!("pretty-print-hack/rental-0.5.6/src/lib.rs");
+
+fn main() {}
diff --git a/src/test/ui/proc-macro/pretty-print-hack-hide.stdout b/src/test/ui/proc-macro/pretty-print-hack-hide.stdout
new file mode 100644
index 000000000..ea796bb26
--- /dev/null
+++ b/src/test/ui/proc-macro/pretty-print-hack-hide.stdout
@@ -0,0 +1,21 @@
+PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input }
+PRINT-DERIVE INPUT (DEBUG): TokenStream [
+ Ident {
+ ident: "enum",
+ span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:4:1: 4:5 (#0),
+ },
+ Ident {
+ ident: "ProceduralMasqueradeDummyType",
+ span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:4:6: 4:35 (#0),
+ },
+ Group {
+ delimiter: Brace,
+ stream: TokenStream [
+ Ident {
+ ident: "Input",
+ span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:13:5: 13:10 (#0),
+ },
+ ],
+ span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:4:36: 14:2 (#0),
+ },
+]
diff --git a/src/test/ui/proc-macro/pretty-print-hack-show.rs b/src/test/ui/proc-macro/pretty-print-hack-show.rs
new file mode 100644
index 000000000..9b1899e49
--- /dev/null
+++ b/src/test/ui/proc-macro/pretty-print-hack-show.rs
@@ -0,0 +1,17 @@
+// aux-build:test-macros.rs
+// compile-flags: -Z span-debug
+
+#![no_std] // Don't load unnecessary hygiene information from std
+extern crate std;
+
+#[macro_use] extern crate test_macros;
+
+mod first {
+ include!("pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs");
+}
+
+mod second {
+ include!("pretty-print-hack/rental-0.5.5/src/lib.rs");
+}
+
+fn main() {}
diff --git a/src/test/ui/proc-macro/pretty-print-hack-show.stderr b/src/test/ui/proc-macro/pretty-print-hack-show.stderr
new file mode 100644
index 000000000..873054927
--- /dev/null
+++ b/src/test/ui/proc-macro/pretty-print-hack-show.stderr
@@ -0,0 +1,179 @@
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+ = note: `#[deny(proc_macro_back_compat)]` on by default
+
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+
+error: aborting due to 8 previous errors
+
+Future incompatibility report: Future breakage diagnostic:
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+ = note: `#[deny(proc_macro_back_compat)]` on by default
+
+Future breakage diagnostic:
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+ = note: `#[deny(proc_macro_back_compat)]` on by default
+
+Future breakage diagnostic:
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+ = note: `#[deny(proc_macro_back_compat)]` on by default
+
+Future breakage diagnostic:
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+ = note: `#[deny(proc_macro_back_compat)]` on by default
+
+Future breakage diagnostic:
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+ = note: `#[deny(proc_macro_back_compat)]` on by default
+
+Future breakage diagnostic:
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+ = note: `#[deny(proc_macro_back_compat)]` on by default
+
+Future breakage diagnostic:
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+ = note: `#[deny(proc_macro_back_compat)]` on by default
+
+Future breakage diagnostic:
+error: using an old version of `rental`
+ --> $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6
+ |
+LL | enum ProceduralMasqueradeDummyType {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ = note: older versions of the `rental` crate will stop compiling in future versions of Rust; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives
+ = note: `#[deny(proc_macro_back_compat)]` on by default
+
diff --git a/src/test/ui/proc-macro/pretty-print-hack-show.stdout b/src/test/ui/proc-macro/pretty-print-hack-show.stdout
new file mode 100644
index 000000000..3d793d2a0
--- /dev/null
+++ b/src/test/ui/proc-macro/pretty-print-hack-show.stdout
@@ -0,0 +1,44 @@
+PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input, }
+PRINT-DERIVE RE-COLLECTED (DISPLAY): enum ProceduralMasqueradeDummyType { Input }
+PRINT-DERIVE INPUT (DEBUG): TokenStream [
+ Ident {
+ ident: "enum",
+ span: $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:1: 4:5 (#0),
+ },
+ Ident {
+ ident: "ProceduralMasqueradeDummyType",
+ span: $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:6: 4:35 (#0),
+ },
+ Group {
+ delimiter: Brace,
+ stream: TokenStream [
+ Ident {
+ ident: "Input",
+ span: $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:13:5: 13:10 (#0),
+ },
+ ],
+ span: $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:36: 14:2 (#0),
+ },
+]
+PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input, }
+PRINT-DERIVE RE-COLLECTED (DISPLAY): enum ProceduralMasqueradeDummyType { Input }
+PRINT-DERIVE INPUT (DEBUG): TokenStream [
+ Ident {
+ ident: "enum",
+ span: $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:1: 4:5 (#0),
+ },
+ Ident {
+ ident: "ProceduralMasqueradeDummyType",
+ span: $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:6: 4:35 (#0),
+ },
+ Group {
+ delimiter: Brace,
+ stream: TokenStream [
+ Ident {
+ ident: "Input",
+ span: $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:13:5: 13:10 (#0),
+ },
+ ],
+ span: $DIR/pretty-print-hack/rental-0.5.5/src/lib.rs:4:36: 14:2 (#0),
+ },
+]
diff --git a/src/test/ui/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs b/src/test/ui/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs
new file mode 100644
index 000000000..9501980fa
--- /dev/null
+++ b/src/test/ui/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs
@@ -0,0 +1,14 @@
+// ignore-test
+
+#[derive(Print)]
+enum ProceduralMasqueradeDummyType {
+//~^ ERROR using
+//~| WARN this was previously
+//~| ERROR using
+//~| WARN this was previously
+//~| ERROR using
+//~| WARN this was previously
+//~| ERROR using
+//~| WARN this was previously
+ Input
+}
diff --git a/src/test/ui/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs b/src/test/ui/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs
new file mode 100644
index 000000000..9501980fa
--- /dev/null
+++ b/src/test/ui/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs
@@ -0,0 +1,14 @@
+// ignore-test
+
+#[derive(Print)]
+enum ProceduralMasqueradeDummyType {
+//~^ ERROR using
+//~| WARN this was previously
+//~| ERROR using
+//~| WARN this was previously
+//~| ERROR using
+//~| WARN this was previously
+//~| ERROR using
+//~| WARN this was previously
+ Input
+}
diff --git a/src/test/ui/proc-macro/pretty-print-hack/rental-0.5.6/src/lib.rs b/src/test/ui/proc-macro/pretty-print-hack/rental-0.5.6/src/lib.rs
new file mode 100644
index 000000000..9501980fa
--- /dev/null
+++ b/src/test/ui/proc-macro/pretty-print-hack/rental-0.5.6/src/lib.rs
@@ -0,0 +1,14 @@
+// ignore-test
+
+#[derive(Print)]
+enum ProceduralMasqueradeDummyType {
+//~^ ERROR using
+//~| WARN this was previously
+//~| ERROR using
+//~| WARN this was previously
+//~| ERROR using
+//~| WARN this was previously
+//~| ERROR using
+//~| WARN this was previously
+ Input
+}
diff --git a/src/test/ui/proc-macro/proc-macro-attributes.stderr b/src/test/ui/proc-macro/proc-macro-attributes.stderr
index b66e4575e..140d87906 100644
--- a/src/test/ui/proc-macro/proc-macro-attributes.stderr
+++ b/src/test/ui/proc-macro/proc-macro-attributes.stderr
@@ -85,9 +85,9 @@ LL | #[B]
LL | #[derive(B)]
| - the attribute is introduced here
|
- = note: `#[warn(legacy_derive_helpers)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #79202 <https://github.com/rust-lang/rust/issues/79202>
+ = note: `#[warn(legacy_derive_helpers)]` on by default
warning: derive helper attribute is used before it is introduced
--> $DIR/proc-macro-attributes.rs:10:3
diff --git a/src/test/ui/proc-macro/proc-macro-gates.stderr b/src/test/ui/proc-macro/proc-macro-gates.stderr
index 118213a17..3feb9b829 100644
--- a/src/test/ui/proc-macro/proc-macro-gates.stderr
+++ b/src/test/ui/proc-macro/proc-macro-gates.stderr
@@ -82,9 +82,9 @@ error: inner macro attributes are unstable
LL | #![test]
| ^^^^
|
- = note: `#[deny(soft_unstable)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
+ = note: `#[deny(soft_unstable)]` on by default
error: aborting due to 10 previous errors
diff --git a/src/test/ui/proc-macro/three-equals.stderr b/src/test/ui/proc-macro/three-equals.stderr
index 1ce5e02bd..9cdb2a21b 100644
--- a/src/test/ui/proc-macro/three-equals.stderr
+++ b/src/test/ui/proc-macro/three-equals.stderr
@@ -8,16 +8,16 @@ LL | three_equals!(==);
= note: this error originates in the macro `three_equals` (in Nightly builds, run with -Z macro-backtrace for more info)
error: expected EOF, found `=`.
- --> $DIR/three-equals.rs:15:21
+ --> $DIR/three-equals.rs:15:22
|
LL | three_equals!(=====);
- | ^^
+ | ^
|
note: last good input was here
--> $DIR/three-equals.rs:15:21
|
LL | three_equals!(=====);
- | ^^
+ | ^
= help: input must be: `===`
error: expected `=`, found `abc`.
diff --git a/src/test/ui/process/process-panic-after-fork.rs b/src/test/ui/process/process-panic-after-fork.rs
index 1ccf6bb05..6d4d24922 100644
--- a/src/test/ui/process/process-panic-after-fork.rs
+++ b/src/test/ui/process/process-panic-after-fork.rs
@@ -5,9 +5,8 @@
// ignore-sgx no libc
// ignore-emscripten no processes
// ignore-sgx no processes
-// ignore-android: FIXME(#85261)
+// ignore-fuchsia no fork
-#![feature(bench_black_box)]
#![feature(rustc_private)]
#![feature(never_type)]
#![feature(panic_always_abort)]
@@ -79,7 +78,49 @@ unsafe impl<A:GlobalAlloc> GlobalAlloc for PidChecking<A> {
fn expect_aborted(status: ExitStatus) {
dbg!(status);
let signal = status.signal().expect("expected child process to die of signal");
+
+ #[cfg(not(target_os = "android"))]
assert!(signal == libc::SIGABRT || signal == libc::SIGILL || signal == libc::SIGTRAP);
+
+ #[cfg(target_os = "android")]
+ {
+ // Android signals an abort() call with SIGSEGV at address 0xdeadbaad
+ // See e.g. https://groups.google.com/g/android-ndk/c/laW1CJc7Icc
+ assert!(signal == libc::SIGSEGV);
+
+ // Additional checks performed:
+ // 1. Find last tombstone (similar to coredump but in text format) from the
+ // same executable (path) as we are (must be because of usage of fork):
+ // This ensures that we look into the correct tombstone.
+ // 2. Cause of crash is a SIGSEGV with address 0xdeadbaad.
+ // 3. libc::abort call is in one of top two functions on callstack.
+ // The last two steps distinguish between a normal SIGSEGV and one caused
+ // by libc::abort.
+
+ let this_exe = std::env::current_exe().unwrap().into_os_string().into_string().unwrap();
+ let exe_string = format!(">>> {this_exe} <<<");
+ let tombstone = (0..100)
+ .map(|n| format!("/data/tombstones/tombstone_{n:02}"))
+ .filter(|f| std::path::Path::new(&f).exists())
+ .map(|f| std::fs::read_to_string(&f).expect("Cannot read tombstone file"))
+ .filter(|f| f.contains(&exe_string))
+ .last()
+ .expect("no tombstone found");
+
+ println!("Content of tombstone:\n{tombstone}");
+
+ assert!(
+ tombstone.contains("signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad")
+ );
+ let abort_on_top = tombstone
+ .lines()
+ .skip_while(|l| !l.contains("backtrace:"))
+ .skip(1)
+ .take_while(|l| l.starts_with(" #"))
+ .take(2)
+ .any(|f| f.contains("/system/lib/libc.so (abort"));
+ assert!(abort_on_top);
+ }
}
fn main() {
diff --git a/src/test/ui/process/process-spawn-nonexistent.rs b/src/test/ui/process/process-spawn-nonexistent.rs
index a51372263..9dd608986 100644
--- a/src/test/ui/process/process-spawn-nonexistent.rs
+++ b/src/test/ui/process/process-spawn-nonexistent.rs
@@ -1,6 +1,7 @@
// run-pass
// ignore-emscripten no processes
// ignore-sgx no processes
+// ignore-fuchsia ErrorKind not translated
use std::io::ErrorKind;
use std::process::Command;
diff --git a/src/test/ui/process/process-spawn-with-unicode-params.rs b/src/test/ui/process/process-spawn-with-unicode-params.rs
index 6e9229b62..16dba6292 100644
--- a/src/test/ui/process/process-spawn-with-unicode-params.rs
+++ b/src/test/ui/process/process-spawn-with-unicode-params.rs
@@ -9,6 +9,7 @@
// ignore-emscripten no processes
// ignore-sgx no processes
+// ignore-fuchsia Filesystem manipulation privileged
use std::io::prelude::*;
use std::io;
diff --git a/src/test/ui/process/signal-exit-status.rs b/src/test/ui/process/signal-exit-status.rs
index 0963dcc80..9519ed7b4 100644
--- a/src/test/ui/process/signal-exit-status.rs
+++ b/src/test/ui/process/signal-exit-status.rs
@@ -2,6 +2,7 @@
// ignore-emscripten no processes
// ignore-sgx no processes
// ignore-windows
+// ignore-fuchsia code returned as ZX_TASK_RETCODE_EXCEPTION_KILL, FIXME (#58590)
use std::env;
use std::process::Command;
diff --git a/src/test/ui/pub/pub-reexport-priv-extern-crate.stderr b/src/test/ui/pub/pub-reexport-priv-extern-crate.stderr
index e4d73c647..c7fadc6f9 100644
--- a/src/test/ui/pub/pub-reexport-priv-extern-crate.stderr
+++ b/src/test/ui/pub/pub-reexport-priv-extern-crate.stderr
@@ -28,9 +28,9 @@ error: extern crate `core` is private, and cannot be re-exported (error E0365),
LL | pub use core as reexported_core;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[deny(pub_use_of_private_extern_crate)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
+ = note: `#[deny(pub_use_of_private_extern_crate)]` on by default
error: aborting due to 3 previous errors
diff --git a/src/test/ui/pub/pub-restricted-error.stderr b/src/test/ui/pub/pub-restricted-error.stderr
index 95bf498c7..b47328f34 100644
--- a/src/test/ui/pub/pub-restricted-error.stderr
+++ b/src/test/ui/pub/pub-restricted-error.stderr
@@ -1,6 +1,8 @@
error: expected identifier, found `(`
--> $DIR/pub-restricted-error.rs:4:16
|
+LL | struct Foo {
+ | --- while parsing this struct
LL | pub(crate) () foo: usize,
| ^ expected identifier
diff --git a/src/test/ui/query-system/query_depth.rs b/src/test/ui/query-system/query_depth.rs
new file mode 100644
index 000000000..e600c1c08
--- /dev/null
+++ b/src/test/ui/query-system/query_depth.rs
@@ -0,0 +1,31 @@
+// build-fail
+
+#![recursion_limit = "64"]
+type Byte = Option<Option<Option<Option< Option<Option<Option<Option<
+ Option<Option<Option<Option< Option<Option<Option<Option<
+ Option<Option<Option<Option< Option<Option<Option<Option<
+ Option<Option<Option<Option< Option<Option<Option<Option<
+ Option<Option<Option<Option< Option<Option<Option<Option<
+ Option<Option<Option<Option< Option<Option<Option<Option<
+ Option<Option<Option<Option< Option<Option<Option<Option<
+ Option<Option<Option<Option< Option<Option<Option<Option<
+ Option<Option<Option<Option< Option<Option<Option<Option<
+ Option<Option<Option<Option< Option<Option<Option<Option<
+ Option<Option<Option<Option< Option<Option<Option<Option<
+ Box<String>
+ >>>> >>>>
+ >>>> >>>>
+ >>>> >>>>
+ >>>> >>>>
+ >>>> >>>>
+ >>>> >>>>
+ >>>> >>>>
+ >>>> >>>>
+ >>>> >>>>
+ >>>> >>>>
+>>>> >>>>;
+
+fn main() {
+//~^ ERROR: queries overflow the depth limit!
+ println!("{}", std::mem::size_of::<Byte>());
+}
diff --git a/src/test/ui/query-system/query_depth.stderr b/src/test/ui/query-system/query_depth.stderr
new file mode 100644
index 000000000..43a18b4e0
--- /dev/null
+++ b/src/test/ui/query-system/query_depth.stderr
@@ -0,0 +1,11 @@
+error: queries overflow the depth limit!
+ --> $DIR/query_depth.rs:28:1
+ |
+LL | fn main() {
+ | ^^^^^^^^^
+ |
+ = help: consider increasing the recursion limit by adding a `#![recursion_limit = "128"]` attribute to your crate (`query_depth`)
+ = note: query depth increased by 66 when computing layout of `core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<core::option::Option<alloc::boxed::Box<alloc::string::String>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/query-visibility.rs b/src/test/ui/query-visibility.rs
new file mode 100644
index 000000000..09a289d85
--- /dev/null
+++ b/src/test/ui/query-visibility.rs
@@ -0,0 +1,9 @@
+// check-pass
+// Check that it doesn't panic when `Input` gets its visibility checked.
+
+#![crate_type = "lib"]
+
+pub trait Layer<
+ /// Hello.
+ Input,
+> {}
diff --git a/src/test/ui/range/range-inclusive-pattern-precedence.stderr b/src/test/ui/range/range-inclusive-pattern-precedence.stderr
index 10513374c..f6788d034 100644
--- a/src/test/ui/range/range-inclusive-pattern-precedence.stderr
+++ b/src/test/ui/range/range-inclusive-pattern-precedence.stderr
@@ -10,13 +10,13 @@ warning: `...` range patterns are deprecated
LL | &0...9 => {}
| ^^^^^^ help: use `..=` for an inclusive range: `&(0..=9)`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
note: the lint level is defined here
--> $DIR/range-inclusive-pattern-precedence.rs:7:9
|
LL | #![warn(ellipsis_inclusive_range_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
error: aborting due to previous error; 1 warning emitted
diff --git a/src/test/ui/range/range-inclusive-pattern-precedence2.stderr b/src/test/ui/range/range-inclusive-pattern-precedence2.stderr
index cdec41d7f..bb4e3a13a 100644
--- a/src/test/ui/range/range-inclusive-pattern-precedence2.stderr
+++ b/src/test/ui/range/range-inclusive-pattern-precedence2.stderr
@@ -10,13 +10,13 @@ warning: `...` range patterns are deprecated
LL | box 0...9 => {}
| ^^^ help: use `..=` for an inclusive range
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
note: the lint level is defined here
--> $DIR/range-inclusive-pattern-precedence2.rs:5:9
|
LL | #![warn(ellipsis_inclusive_range_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
error: aborting due to previous error; 1 warning emitted
diff --git a/src/test/ui/recursion/issue-83150.stderr b/src/test/ui/recursion/issue-83150.stderr
index 32f25faf3..3e0229717 100644
--- a/src/test/ui/recursion/issue-83150.stderr
+++ b/src/test/ui/recursion/issue-83150.stderr
@@ -6,14 +6,12 @@ LL | fn func<T: Iterator<Item = u8>>(iter: &mut T) {
LL | func(&mut iter.map(|x| x + 1))
| ------------------------------ recursive call site
|
- = note: `#[warn(unconditional_recursion)]` on by default
= help: a `loop` may express intention better if this is on purpose
+ = note: `#[warn(unconditional_recursion)]` on by default
-error[E0275]: overflow evaluating the requirement `<std::ops::Range<u8> as Iterator>::Item`
+error[E0275]: overflow evaluating the requirement `Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut std::ops::Range<u8>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>: Iterator`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_83150`)
- = note: required for `Map<&mut std::ops::Range<u8>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>` to implement `Iterator`
- = note: 64 redundant requirements hidden
= note: required for `&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut Map<&mut std::ops::Range<u8>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>, [closure@$DIR/issue-83150.rs:11:24: 11:27]>` to implement `Iterator`
error: aborting due to previous error; 1 warning emitted
diff --git a/src/test/ui/recursion/issue-95134.rs b/src/test/ui/recursion/issue-95134.rs
index adc9c6ee2..fdc4d5369 100644
--- a/src/test/ui/recursion/issue-95134.rs
+++ b/src/test/ui/recursion/issue-95134.rs
@@ -1,6 +1,8 @@
// build-fail
+// known-bug: #95134
// compile-flags: -Copt-level=0
-//~^^ ERROR overflow evaluating the requirement
+// failure-status: 101
+// dont-check-compiler-stderr
pub fn encode_num<Writer: ExampleWriter>(n: u32, mut writer: Writer) -> Result<(), Writer::Error> {
if n > 15 {
diff --git a/src/test/ui/recursion/issue-95134.stderr b/src/test/ui/recursion/issue-95134.stderr
deleted file mode 100644
index 57a498694..000000000
--- a/src/test/ui/recursion/issue-95134.stderr
+++ /dev/null
@@ -1,7 +0,0 @@
-error[E0275]: overflow evaluating the requirement `<EmptyWriter as ExampleWriter>::Error`
- |
- = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_95134`)
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0275`.
diff --git a/src/test/ui/recursion/recursive-enum.stderr b/src/test/ui/recursion/recursive-enum.stderr
index f5d25c564..d662d1022 100644
--- a/src/test/ui/recursion/recursive-enum.stderr
+++ b/src/test/ui/recursion/recursive-enum.stderr
@@ -3,10 +3,8 @@ error[E0072]: recursive type `List` has infinite size
|
LL | enum List<T> { Cons(T, List<T>), Nil }
| ^^^^^^^^^^^^ ------- recursive without indirection
- | |
- | recursive type has infinite size
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `List` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | enum List<T> { Cons(T, Box<List<T>>), Nil }
| ++++ +
diff --git a/src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr b/src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr
index 321ee0a36..f2307899d 100644
--- a/src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr
+++ b/src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr
@@ -6,7 +6,7 @@ LL | let Ok(x) = res;
|
= 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
-note: `Result<u32, &R>` defined here
+note: `Result<u32, &R<'_>>` defined here
--> $SRC_DIR/core/src/result.rs:LL:COL
|
LL | pub enum Result<T, E> {
@@ -14,7 +14,7 @@ LL | pub enum Result<T, E> {
...
LL | Err(#[stable(feature = "rust1", since = "1.0.0")] E),
| ^^^ not covered
- = note: the matched value is of type `Result<u32, &R>`
+ = note: the matched value is of type `Result<u32, &R<'_>>`
help: you might want to use `if let` to ignore the variant that isn't matched
|
LL | let x = if let Ok(x) = res { x } else { todo!() };
diff --git a/src/test/ui/regions/issue-101280.rs b/src/test/ui/regions/issue-101280.rs
new file mode 100644
index 000000000..29f158366
--- /dev/null
+++ b/src/test/ui/regions/issue-101280.rs
@@ -0,0 +1,10 @@
+use std::cell::Cell;
+
+type Ty = for<'r> fn(Cell<(&'r i32, &'r i32)>);
+
+fn f<'r>(f: fn(Cell<(&'r i32, &i32)>)) -> Ty {
+ f
+ //~^ ERROR mismatched types
+}
+
+fn main() {}
diff --git a/src/test/ui/regions/issue-101280.stderr b/src/test/ui/regions/issue-101280.stderr
new file mode 100644
index 000000000..320d008ae
--- /dev/null
+++ b/src/test/ui/regions/issue-101280.stderr
@@ -0,0 +1,14 @@
+error[E0308]: mismatched types
+ --> $DIR/issue-101280.rs:6:5
+ |
+LL | fn f<'r>(f: fn(Cell<(&'r i32, &i32)>)) -> Ty {
+ | -- expected `for<'r> fn(Cell<(&'r i32, &'r i32)>)` because of return type
+LL | f
+ | ^ one type is more general than the other
+ |
+ = note: expected fn pointer `for<'r> fn(Cell<(&'r i32, &'r i32)>)`
+ found fn pointer `for<'a> fn(Cell<(&'r i32, &'a i32)>)`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/regions/issue-102374.rs b/src/test/ui/regions/issue-102374.rs
new file mode 100644
index 000000000..e0a116421
--- /dev/null
+++ b/src/test/ui/regions/issue-102374.rs
@@ -0,0 +1,20 @@
+use std::cell::Cell;
+
+#[rustfmt::skip]
+fn f(
+ f: for<'a, 'b, 'c, 'd, 'e, 'f, 'g,
+ 'h, 'i, 'j, 'k, 'l, 'm, 'n,
+ 'o, 'p, 'q, 'r, 's, 't, 'u,
+ 'v, 'w, 'x, 'y, 'z, 'z0>
+ fn(Cell<(& i32, &'a i32, &'b i32, &'c i32, &'d i32,
+ &'e i32, &'f i32, &'g i32, &'h i32, &'i i32,
+ &'j i32, &'k i32, &'l i32, &'m i32, &'n i32,
+ &'o i32, &'p i32, &'q i32, &'r i32, &'s i32,
+ &'t i32, &'u i32, &'v i32, &'w i32, &'x i32,
+ &'y i32, &'z i32, &'z0 i32)>),
+) -> i32 {
+ f
+ //~^ ERROR mismatched types
+}
+
+fn main() {}
diff --git a/src/test/ui/regions/issue-102374.stderr b/src/test/ui/regions/issue-102374.stderr
new file mode 100644
index 000000000..31b855c36
--- /dev/null
+++ b/src/test/ui/regions/issue-102374.stderr
@@ -0,0 +1,14 @@
+error[E0308]: mismatched types
+ --> $DIR/issue-102374.rs:16:5
+ |
+LL | ) -> i32 {
+ | --- expected `i32` because of return type
+LL | f
+ | ^ expected `i32`, found fn pointer
+ |
+ = note: expected type `i32`
+ found fn pointer `for<'z1, 'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, 'l, 'm, 'n, 'o, 'p, 'q, 'r, 's, 't, 'u, 'v, 'w, 'x, 'y, 'z, 'z0> fn(Cell<(&'z1 i32, &'a i32, &'b i32, &'c i32, &'d i32, &'e i32, &'f i32, &'g i32, &'h i32, &'i i32, &'j i32, &'k i32, &'l i32, &'m i32, &'n i32, &'o i32, &'p i32, &'q i32, &'r i32, &'s i32, &'t i32, &'u i32, &'v i32, &'w i32, &'x i32, &'y i32, &'z i32, &'z0 i32)>)`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/regions/issue-102392.rs b/src/test/ui/regions/issue-102392.rs
new file mode 100644
index 000000000..87cc1a8e7
--- /dev/null
+++ b/src/test/ui/regions/issue-102392.rs
@@ -0,0 +1,6 @@
+fn g(f: for<'a> fn(fn(&str, &'a str))) -> bool {
+ f
+ //~^ ERROR mismatched types
+}
+
+fn main() {}
diff --git a/src/test/ui/regions/issue-102392.stderr b/src/test/ui/regions/issue-102392.stderr
new file mode 100644
index 000000000..56f4c0c5d
--- /dev/null
+++ b/src/test/ui/regions/issue-102392.stderr
@@ -0,0 +1,14 @@
+error[E0308]: mismatched types
+ --> $DIR/issue-102392.rs:2:5
+ |
+LL | fn g(f: for<'a> fn(fn(&str, &'a str))) -> bool {
+ | ---- expected `bool` because of return type
+LL | f
+ | ^ expected `bool`, found fn pointer
+ |
+ = note: expected type `bool`
+ found fn pointer `for<'a> fn(for<'b> fn(&'b str, &'a str))`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/regions/region-bound-on-closure-outlives-call.stderr b/src/test/ui/regions/region-bound-on-closure-outlives-call.stderr
index a2396ad42..ea43dde11 100644
--- a/src/test/ui/regions/region-bound-on-closure-outlives-call.stderr
+++ b/src/test/ui/regions/region-bound-on-closure-outlives-call.stderr
@@ -7,8 +7,8 @@ LL |
LL | (|x| f(x))(call_rec(f))
| ----------- recursive call site
|
- = note: `#[warn(unconditional_recursion)]` on by default
= help: a `loop` may express intention better if this is on purpose
+ = note: `#[warn(unconditional_recursion)]` on by default
error[E0505]: cannot move out of `f` because it is borrowed
--> $DIR/region-bound-on-closure-outlives-call.rs:3:25
diff --git a/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr b/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr
index 48f2e1a2f..3b62c7b61 100644
--- a/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr
+++ b/src/test/ui/regions/region-lifetime-bounds-on-fns-where-clause.stderr
@@ -4,8 +4,8 @@ error[E0308]: mismatched types
LL | let _: fn(&mut &isize, &mut &isize) = a;
| ^ one type is more general than the other
|
- = note: expected fn pointer `for<'r, 's, 't0, 't1> fn(&'r mut &'s isize, &'t0 mut &'t1 isize)`
- found fn item `for<'r, 's> fn(&'r mut &isize, &'s mut &isize) {a::<'_, '_>}`
+ = note: expected fn pointer `for<'a, 'b, 'c, 'd> fn(&'a mut &'b isize, &'c mut &'d isize)`
+ found fn item `for<'a, 'b> fn(&'a mut &isize, &'b mut &isize) {a::<'_, '_>}`
error: aborting due to previous error
diff --git a/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr b/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr
index 36f40cd9a..8a18a234b 100644
--- a/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr
+++ b/src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.stderr
@@ -4,8 +4,8 @@ error[E0308]: mismatched types
LL | let _: fn(&mut &isize, &mut &isize, &mut &isize) = a;
| ^ one type is more general than the other
|
- = note: expected fn pointer `for<'r, 's, 't0, 't1, 't2, 't3> fn(&'r mut &'s isize, &'t0 mut &'t1 isize, &'t2 mut &'t3 isize)`
- found fn item `for<'r, 's, 't0> fn(&'r mut &isize, &'s mut &isize, &'t0 mut &isize) {a::<'_, '_, '_>}`
+ = note: expected fn pointer `for<'a, 'b, 'c, 'd, 'e, 'f> fn(&'a mut &'b isize, &'c mut &'d isize, &'e mut &'f isize)`
+ found fn item `for<'a, 'b, 'c> fn(&'a mut &isize, &'b mut &isize, &'c mut &isize) {a::<'_, '_, '_>}`
error: aborting due to previous error
diff --git a/src/test/ui/regions/regions-fn-subtyping-return-static-fail.stderr b/src/test/ui/regions/regions-fn-subtyping-return-static-fail.stderr
index d87d0d2f6..8d82ff958 100644
--- a/src/test/ui/regions/regions-fn-subtyping-return-static-fail.stderr
+++ b/src/test/ui/regions/regions-fn-subtyping-return-static-fail.stderr
@@ -7,7 +7,7 @@ LL | want_G(baz);
| arguments to this function are incorrect
|
= note: expected fn pointer `for<'cx> fn(&'cx S) -> &'static S`
- found fn item `for<'r> fn(&'r S) -> &'r S {baz}`
+ found fn item `for<'a> fn(&'a S) -> &'a S {baz}`
note: function defined here
--> $DIR/regions-fn-subtyping-return-static-fail.rs:20:4
|
diff --git a/src/test/ui/regions/regions-lifetime-bounds-on-fns.stderr b/src/test/ui/regions/regions-lifetime-bounds-on-fns.stderr
index a0daf58c6..17a901943 100644
--- a/src/test/ui/regions/regions-lifetime-bounds-on-fns.stderr
+++ b/src/test/ui/regions/regions-lifetime-bounds-on-fns.stderr
@@ -4,8 +4,8 @@ error[E0308]: mismatched types
LL | let _: fn(&mut &isize, &mut &isize) = a;
| ^ one type is more general than the other
|
- = note: expected fn pointer `for<'r, 's, 't0, 't1> fn(&'r mut &'s isize, &'t0 mut &'t1 isize)`
- found fn item `for<'r, 's> fn(&'r mut &isize, &'s mut &isize) {a::<'_, '_>}`
+ = note: expected fn pointer `for<'a, 'b, 'c, 'd> fn(&'a mut &'b isize, &'c mut &'d isize)`
+ found fn item `for<'a, 'b> fn(&'a mut &isize, &'b mut &isize) {a::<'_, '_>}`
error: aborting due to previous error
diff --git a/src/test/ui/repr/repr-transparent-issue-87496.stderr b/src/test/ui/repr/repr-transparent-issue-87496.stderr
index 3dc13b1c1..aee31212b 100644
--- a/src/test/ui/repr/repr-transparent-issue-87496.stderr
+++ b/src/test/ui/repr/repr-transparent-issue-87496.stderr
@@ -4,13 +4,13 @@ warning: `extern` block uses type `TransparentCustomZst`, which is not FFI-safe
LL | fn good17(p: TransparentCustomZst);
| ^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
- = note: `#[warn(improper_ctypes)]` on by default
= note: this struct contains only zero-sized fields
note: the type is defined here
--> $DIR/repr-transparent-issue-87496.rs:6:1
|
LL | struct TransparentCustomZst(());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: `#[warn(improper_ctypes)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/repr/repr-transparent-non-exhaustive.rs b/src/test/ui/repr/repr-transparent-non-exhaustive.rs
index 9ccd8610d..506f1dcf3 100644
--- a/src/test/ui/repr/repr-transparent-non-exhaustive.rs
+++ b/src/test/ui/repr/repr-transparent-non-exhaustive.rs
@@ -35,62 +35,62 @@ pub struct T4(Sized, ExternalIndirection<(InternalPrivate, InternalNonExhaustive
#[repr(transparent)]
pub struct T5(Sized, Private);
-//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
//~| WARN this was previously accepted by the compiler
#[repr(transparent)]
pub struct T6(Sized, NonExhaustive);
-//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
//~| WARN this was previously accepted by the compiler
#[repr(transparent)]
pub struct T7(Sized, NonExhaustiveEnum);
-//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
//~| WARN this was previously accepted by the compiler
#[repr(transparent)]
pub struct T8(Sized, NonExhaustiveVariant);
-//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
//~| WARN this was previously accepted by the compiler
#[repr(transparent)]
pub struct T9(Sized, InternalIndirection<Private>);
-//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
//~| WARN this was previously accepted by the compiler
#[repr(transparent)]
pub struct T10(Sized, InternalIndirection<NonExhaustive>);
-//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
//~| WARN this was previously accepted by the compiler
#[repr(transparent)]
pub struct T11(Sized, InternalIndirection<NonExhaustiveEnum>);
-//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
//~| WARN this was previously accepted by the compiler
#[repr(transparent)]
pub struct T12(Sized, InternalIndirection<NonExhaustiveVariant>);
-//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
//~| WARN this was previously accepted by the compiler
#[repr(transparent)]
pub struct T13(Sized, ExternalIndirection<Private>);
-//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
//~| WARN this was previously accepted by the compiler
#[repr(transparent)]
pub struct T14(Sized, ExternalIndirection<NonExhaustive>);
-//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
//~| WARN this was previously accepted by the compiler
#[repr(transparent)]
pub struct T15(Sized, ExternalIndirection<NonExhaustiveEnum>);
-//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
//~| WARN this was previously accepted by the compiler
#[repr(transparent)]
pub struct T16(Sized, ExternalIndirection<NonExhaustiveVariant>);
-//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+//~^ ERROR zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
//~| WARN this was previously accepted by the compiler
fn main() {}
diff --git a/src/test/ui/repr/repr-transparent-non-exhaustive.stderr b/src/test/ui/repr/repr-transparent-non-exhaustive.stderr
index 3b1e334a0..16edf59c7 100644
--- a/src/test/ui/repr/repr-transparent-non-exhaustive.stderr
+++ b/src/test/ui/repr/repr-transparent-non-exhaustive.stderr
@@ -1,19 +1,19 @@
-error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
--> $DIR/repr-transparent-non-exhaustive.rs:37:22
|
LL | pub struct T5(Sized, Private);
| ^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
+ = note: this struct contains `Private`, which contains private fields, and makes it not a breaking change to become non-zero-sized in the future.
note: the lint level is defined here
--> $DIR/repr-transparent-non-exhaustive.rs:1:9
|
LL | #![deny(repr_transparent_external_private_fields)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
- = note: this struct contains `Private`, which contains private fields, and makes it not a breaking change to become non-zero-sized in the future.
-error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
--> $DIR/repr-transparent-non-exhaustive.rs:42:22
|
LL | pub struct T6(Sized, NonExhaustive);
@@ -23,7 +23,7 @@ LL | pub struct T6(Sized, NonExhaustive);
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
= note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
-error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
--> $DIR/repr-transparent-non-exhaustive.rs:47:22
|
LL | pub struct T7(Sized, NonExhaustiveEnum);
@@ -33,7 +33,7 @@ LL | pub struct T7(Sized, NonExhaustiveEnum);
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
= note: this enum contains `NonExhaustiveEnum`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
-error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
--> $DIR/repr-transparent-non-exhaustive.rs:52:22
|
LL | pub struct T8(Sized, NonExhaustiveVariant);
@@ -43,7 +43,7 @@ LL | pub struct T8(Sized, NonExhaustiveVariant);
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
= note: this enum contains `NonExhaustiveVariant`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
-error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
--> $DIR/repr-transparent-non-exhaustive.rs:57:22
|
LL | pub struct T9(Sized, InternalIndirection<Private>);
@@ -53,7 +53,7 @@ LL | pub struct T9(Sized, InternalIndirection<Private>);
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
= note: this struct contains `Private`, which contains private fields, and makes it not a breaking change to become non-zero-sized in the future.
-error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
--> $DIR/repr-transparent-non-exhaustive.rs:62:23
|
LL | pub struct T10(Sized, InternalIndirection<NonExhaustive>);
@@ -63,7 +63,7 @@ LL | pub struct T10(Sized, InternalIndirection<NonExhaustive>);
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
= note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
-error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
--> $DIR/repr-transparent-non-exhaustive.rs:67:23
|
LL | pub struct T11(Sized, InternalIndirection<NonExhaustiveEnum>);
@@ -73,7 +73,7 @@ LL | pub struct T11(Sized, InternalIndirection<NonExhaustiveEnum>);
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
= note: this enum contains `NonExhaustiveEnum`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
-error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
--> $DIR/repr-transparent-non-exhaustive.rs:72:23
|
LL | pub struct T12(Sized, InternalIndirection<NonExhaustiveVariant>);
@@ -83,7 +83,7 @@ LL | pub struct T12(Sized, InternalIndirection<NonExhaustiveVariant>);
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
= note: this enum contains `NonExhaustiveVariant`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
-error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
--> $DIR/repr-transparent-non-exhaustive.rs:77:23
|
LL | pub struct T13(Sized, ExternalIndirection<Private>);
@@ -93,7 +93,7 @@ LL | pub struct T13(Sized, ExternalIndirection<Private>);
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
= note: this struct contains `Private`, which contains private fields, and makes it not a breaking change to become non-zero-sized in the future.
-error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
--> $DIR/repr-transparent-non-exhaustive.rs:82:23
|
LL | pub struct T14(Sized, ExternalIndirection<NonExhaustive>);
@@ -103,7 +103,7 @@ LL | pub struct T14(Sized, ExternalIndirection<NonExhaustive>);
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
= note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
-error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
--> $DIR/repr-transparent-non-exhaustive.rs:87:23
|
LL | pub struct T15(Sized, ExternalIndirection<NonExhaustiveEnum>);
@@ -113,7 +113,7 @@ LL | pub struct T15(Sized, ExternalIndirection<NonExhaustiveEnum>);
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
= note: this enum contains `NonExhaustiveEnum`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
-error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
+error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
--> $DIR/repr-transparent-non-exhaustive.rs:92:23
|
LL | pub struct T16(Sized, ExternalIndirection<NonExhaustiveVariant>);
diff --git a/src/test/ui/resolve/bad-env-capture.stderr b/src/test/ui/resolve/bad-env-capture.stderr
index f78a38a3d..59b1fabfd 100644
--- a/src/test/ui/resolve/bad-env-capture.stderr
+++ b/src/test/ui/resolve/bad-env-capture.stderr
@@ -6,18 +6,18 @@ LL | fn bar() { log(debug, x); }
|
= help: use the `|| { ... }` closure form instead
-error[E0425]: cannot find function `log` in this scope
- --> $DIR/bad-env-capture.rs:4:16
- |
-LL | fn bar() { log(debug, x); }
- | ^^^ not found in this scope
-
error[E0425]: cannot find value `debug` in this scope
--> $DIR/bad-env-capture.rs:4:20
|
LL | fn bar() { log(debug, x); }
| ^^^^^ not found in this scope
+error[E0425]: cannot find function `log` in this scope
+ --> $DIR/bad-env-capture.rs:4:16
+ |
+LL | fn bar() { log(debug, x); }
+ | ^^^ not found in this scope
+
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0425, E0434.
diff --git a/src/test/ui/resolve/bad-env-capture2.stderr b/src/test/ui/resolve/bad-env-capture2.stderr
index 57c807fd7..811c259de 100644
--- a/src/test/ui/resolve/bad-env-capture2.stderr
+++ b/src/test/ui/resolve/bad-env-capture2.stderr
@@ -6,18 +6,18 @@ LL | fn bar() { log(debug, x); }
|
= help: use the `|| { ... }` closure form instead
-error[E0425]: cannot find function `log` in this scope
- --> $DIR/bad-env-capture2.rs:3:16
- |
-LL | fn bar() { log(debug, x); }
- | ^^^ not found in this scope
-
error[E0425]: cannot find value `debug` in this scope
--> $DIR/bad-env-capture2.rs:3:20
|
LL | fn bar() { log(debug, x); }
| ^^^^^ not found in this scope
+error[E0425]: cannot find function `log` in this scope
+ --> $DIR/bad-env-capture2.rs:3:16
+ |
+LL | fn bar() { log(debug, x); }
+ | ^^^ not found in this scope
+
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0425, E0434.
diff --git a/src/test/ui/resolve/bad-env-capture3.stderr b/src/test/ui/resolve/bad-env-capture3.stderr
index d6eb4f86e..eab37fde9 100644
--- a/src/test/ui/resolve/bad-env-capture3.stderr
+++ b/src/test/ui/resolve/bad-env-capture3.stderr
@@ -6,18 +6,18 @@ LL | fn bar() { log(debug, x); }
|
= help: use the `|| { ... }` closure form instead
-error[E0425]: cannot find function `log` in this scope
- --> $DIR/bad-env-capture3.rs:4:20
- |
-LL | fn bar() { log(debug, x); }
- | ^^^ not found in this scope
-
error[E0425]: cannot find value `debug` in this scope
--> $DIR/bad-env-capture3.rs:4:24
|
LL | fn bar() { log(debug, x); }
| ^^^^^ not found in this scope
+error[E0425]: cannot find function `log` in this scope
+ --> $DIR/bad-env-capture3.rs:4:20
+ |
+LL | fn bar() { log(debug, x); }
+ | ^^^ not found in this scope
+
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0425, E0434.
diff --git a/src/test/ui/resolve/bad-expr-path.stderr b/src/test/ui/resolve/bad-expr-path.stderr
index 77c48c951..8261e8e53 100644
--- a/src/test/ui/resolve/bad-expr-path.stderr
+++ b/src/test/ui/resolve/bad-expr-path.stderr
@@ -1,9 +1,3 @@
-error[E0425]: cannot find function `log` in this scope
- --> $DIR/bad-expr-path.rs:4:5
- |
-LL | log(debug, m1::arguments);
- | ^^^ not found in this scope
-
error[E0425]: cannot find value `debug` in this scope
--> $DIR/bad-expr-path.rs:4:9
|
@@ -16,6 +10,12 @@ error[E0425]: cannot find value `arguments` in module `m1`
LL | log(debug, m1::arguments);
| ^^^^^^^^^ not found in `m1`
+error[E0425]: cannot find function `log` in this scope
+ --> $DIR/bad-expr-path.rs:4:5
+ |
+LL | log(debug, m1::arguments);
+ | ^^^ not found in this scope
+
error[E0580]: `main` function has wrong type
--> $DIR/bad-expr-path.rs:3:1
|
diff --git a/src/test/ui/resolve/bad-expr-path2.stderr b/src/test/ui/resolve/bad-expr-path2.stderr
index d06e10271..6e11296d9 100644
--- a/src/test/ui/resolve/bad-expr-path2.stderr
+++ b/src/test/ui/resolve/bad-expr-path2.stderr
@@ -1,9 +1,3 @@
-error[E0425]: cannot find function `log` in this scope
- --> $DIR/bad-expr-path2.rs:6:5
- |
-LL | log(debug, m1::arguments);
- | ^^^ not found in this scope
-
error[E0425]: cannot find value `debug` in this scope
--> $DIR/bad-expr-path2.rs:6:9
|
@@ -16,6 +10,12 @@ error[E0423]: expected value, found module `m1::arguments`
LL | log(debug, m1::arguments);
| ^^^^^^^^^^^^^ not a value
+error[E0425]: cannot find function `log` in this scope
+ --> $DIR/bad-expr-path2.rs:6:5
+ |
+LL | log(debug, m1::arguments);
+ | ^^^ not found in this scope
+
error[E0580]: `main` function has wrong type
--> $DIR/bad-expr-path2.rs:5:1
|
diff --git a/src/test/ui/resolve/issue-102946.rs b/src/test/ui/resolve/issue-102946.rs
new file mode 100644
index 000000000..c6feca6f3
--- /dev/null
+++ b/src/test/ui/resolve/issue-102946.rs
@@ -0,0 +1,7 @@
+impl Error for str::Utf8Error {
+ //~^ ERROR cannot find trait `Error` in this scope
+ //~| ERROR ambiguous associated type
+ fn description(&self) {}
+}
+
+fn main() {}
diff --git a/src/test/ui/resolve/issue-102946.stderr b/src/test/ui/resolve/issue-102946.stderr
new file mode 100644
index 000000000..65be0258e
--- /dev/null
+++ b/src/test/ui/resolve/issue-102946.stderr
@@ -0,0 +1,26 @@
+error[E0405]: cannot find trait `Error` in this scope
+ --> $DIR/issue-102946.rs:1:6
+ |
+LL | impl Error for str::Utf8Error {
+ | ^^^^^ not found in this scope
+ |
+help: consider importing this trait
+ |
+LL | use std::error::Error;
+ |
+
+error[E0223]: ambiguous associated type
+ --> $DIR/issue-102946.rs:1:16
+ |
+LL | impl Error for str::Utf8Error {
+ | ^^^^^^^^^^^^^^
+ |
+help: you are looking for the module in `std`, not the primitive type
+ |
+LL | impl Error for std::str::Utf8Error {
+ | +++++
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0223, E0405.
+For more information about an error, try `rustc --explain E0223`.
diff --git a/src/test/ui/resolve/issue-103202.rs b/src/test/ui/resolve/issue-103202.rs
new file mode 100644
index 000000000..469d9d7c8
--- /dev/null
+++ b/src/test/ui/resolve/issue-103202.rs
@@ -0,0 +1,7 @@
+struct S {}
+
+impl S {
+ fn f(self: &S::x) {} //~ ERROR ambiguous associated type
+}
+
+fn main() {}
diff --git a/src/test/ui/resolve/issue-103202.stderr b/src/test/ui/resolve/issue-103202.stderr
new file mode 100644
index 000000000..880389371
--- /dev/null
+++ b/src/test/ui/resolve/issue-103202.stderr
@@ -0,0 +1,9 @@
+error[E0223]: ambiguous associated type
+ --> $DIR/issue-103202.rs:4:17
+ |
+LL | fn f(self: &S::x) {}
+ | ^^^^ help: use fully-qualified syntax: `<S as Trait>::x`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0223`.
diff --git a/src/test/ui/resolve/issue-14254.stderr b/src/test/ui/resolve/issue-14254.stderr
index b1f45adb8..690a40f7e 100644
--- a/src/test/ui/resolve/issue-14254.stderr
+++ b/src/test/ui/resolve/issue-14254.stderr
@@ -1,21 +1,9 @@
-error[E0425]: cannot find function `baz` in this scope
- --> $DIR/issue-14254.rs:19:9
- |
-LL | baz();
- | ^^^ help: you might have meant to call the method: `self.baz`
-
error[E0425]: cannot find value `a` in this scope
--> $DIR/issue-14254.rs:21:9
|
LL | a;
| ^ not found in this scope
-error[E0425]: cannot find function `baz` in this scope
- --> $DIR/issue-14254.rs:28:9
- |
-LL | baz();
- | ^^^ help: you might have meant to call the method: `self.baz`
-
error[E0425]: cannot find value `x` in this scope
--> $DIR/issue-14254.rs:30:9
|
@@ -38,7 +26,12 @@ error[E0425]: cannot find value `bah` in this scope
--> $DIR/issue-14254.rs:36:9
|
LL | bah;
- | ^^^ help: you might have meant to call the associated function: `Self::bah`
+ | ^^^
+ |
+help: you might have meant to refer to the associated function
+ |
+LL | Self::bah;
+ | ~~~~~~~~~
error[E0425]: cannot find value `b` in this scope
--> $DIR/issue-14254.rs:38:9
@@ -46,12 +39,6 @@ error[E0425]: cannot find value `b` in this scope
LL | b;
| ^ not found in this scope
-error[E0425]: cannot find function `baz` in this scope
- --> $DIR/issue-14254.rs:45:9
- |
-LL | baz();
- | ^^^ help: you might have meant to call the method: `self.baz`
-
error[E0425]: cannot find value `x` in this scope
--> $DIR/issue-14254.rs:47:9
|
@@ -74,7 +61,12 @@ error[E0425]: cannot find value `bah` in this scope
--> $DIR/issue-14254.rs:53:9
|
LL | bah;
- | ^^^ help: you might have meant to call the associated function: `Self::bah`
+ | ^^^
+ |
+help: you might have meant to refer to the associated function
+ |
+LL | Self::bah;
+ | ~~~~~~~~~
error[E0425]: cannot find value `b` in this scope
--> $DIR/issue-14254.rs:55:9
@@ -82,65 +74,108 @@ error[E0425]: cannot find value `b` in this scope
LL | b;
| ^ not found in this scope
-error[E0425]: cannot find function `baz` in this scope
- --> $DIR/issue-14254.rs:62:9
+error[E0425]: cannot find value `bah` in this scope
+ --> $DIR/issue-14254.rs:64:9
|
-LL | baz();
- | ^^^ help: you might have meant to call the method: `self.baz`
+LL | bah;
+ | ^^^
+ |
+help: you might have meant to refer to the associated function
+ |
+LL | Self::bah;
+ | ~~~~~~~~~
error[E0425]: cannot find value `bah` in this scope
- --> $DIR/issue-14254.rs:64:9
+ --> $DIR/issue-14254.rs:73:9
+ |
+LL | bah;
+ | ^^^
+ |
+help: you might have meant to refer to the associated function
+ |
+LL | Self::bah;
+ | ~~~~~~~~~
+
+error[E0425]: cannot find value `bah` in this scope
+ --> $DIR/issue-14254.rs:82:9
+ |
+LL | bah;
+ | ^^^
+ |
+help: you might have meant to refer to the associated function
+ |
+LL | Self::bah;
+ | ~~~~~~~~~
+
+error[E0425]: cannot find value `bah` in this scope
+ --> $DIR/issue-14254.rs:91:9
+ |
+LL | bah;
+ | ^^^
+ |
+help: you might have meant to refer to the associated function
+ |
+LL | Self::bah;
+ | ~~~~~~~~~
+
+error[E0425]: cannot find value `bah` in this scope
+ --> $DIR/issue-14254.rs:100:9
|
LL | bah;
- | ^^^ help: you might have meant to call the associated function: `Self::bah`
+ | ^^^
+ |
+help: you might have meant to refer to the associated function
+ |
+LL | Self::bah;
+ | ~~~~~~~~~
error[E0425]: cannot find function `baz` in this scope
- --> $DIR/issue-14254.rs:71:9
+ --> $DIR/issue-14254.rs:19:9
|
LL | baz();
| ^^^ help: you might have meant to call the method: `self.baz`
-error[E0425]: cannot find value `bah` in this scope
- --> $DIR/issue-14254.rs:73:9
+error[E0425]: cannot find function `baz` in this scope
+ --> $DIR/issue-14254.rs:28:9
|
-LL | bah;
- | ^^^ help: you might have meant to call the associated function: `Self::bah`
+LL | baz();
+ | ^^^ help: you might have meant to call the method: `self.baz`
error[E0425]: cannot find function `baz` in this scope
- --> $DIR/issue-14254.rs:80:9
+ --> $DIR/issue-14254.rs:45:9
|
LL | baz();
| ^^^ help: you might have meant to call the method: `self.baz`
-error[E0425]: cannot find value `bah` in this scope
- --> $DIR/issue-14254.rs:82:9
+error[E0425]: cannot find function `baz` in this scope
+ --> $DIR/issue-14254.rs:62:9
|
-LL | bah;
- | ^^^ help: you might have meant to call the associated function: `Self::bah`
+LL | baz();
+ | ^^^ help: you might have meant to call the method: `self.baz`
error[E0425]: cannot find function `baz` in this scope
- --> $DIR/issue-14254.rs:89:9
+ --> $DIR/issue-14254.rs:71:9
|
LL | baz();
| ^^^ help: you might have meant to call the method: `self.baz`
-error[E0425]: cannot find value `bah` in this scope
- --> $DIR/issue-14254.rs:91:9
+error[E0425]: cannot find function `baz` in this scope
+ --> $DIR/issue-14254.rs:80:9
|
-LL | bah;
- | ^^^ help: you might have meant to call the associated function: `Self::bah`
+LL | baz();
+ | ^^^ help: you might have meant to call the method: `self.baz`
error[E0425]: cannot find function `baz` in this scope
- --> $DIR/issue-14254.rs:98:9
+ --> $DIR/issue-14254.rs:89:9
|
LL | baz();
| ^^^ help: you might have meant to call the method: `self.baz`
-error[E0425]: cannot find value `bah` in this scope
- --> $DIR/issue-14254.rs:100:9
+error[E0425]: cannot find function `baz` in this scope
+ --> $DIR/issue-14254.rs:98:9
|
-LL | bah;
- | ^^^ help: you might have meant to call the associated function: `Self::bah`
+LL | baz();
+ | ^^^ help: you might have meant to call the method: `self.baz`
error: aborting due to 24 previous errors
diff --git a/src/test/ui/resolve/issue-23305.rs b/src/test/ui/resolve/issue-23305.rs
index 95635e12a..6d7fe7c50 100644
--- a/src/test/ui/resolve/issue-23305.rs
+++ b/src/test/ui/resolve/issue-23305.rs
@@ -3,6 +3,6 @@ pub trait ToNbt<T> {
}
impl dyn ToNbt<Self> {}
-//~^ ERROR cycle detected
+//~^ ERROR `Self` is not valid in the self type of an impl block
fn main() {}
diff --git a/src/test/ui/resolve/issue-23305.stderr b/src/test/ui/resolve/issue-23305.stderr
index 20aeb7b99..aad1b583a 100644
--- a/src/test/ui/resolve/issue-23305.stderr
+++ b/src/test/ui/resolve/issue-23305.stderr
@@ -1,22 +1,10 @@
-error[E0391]: cycle detected when computing type of `<impl at $DIR/issue-23305.rs:5:1: 5:21>`
+error: `Self` is not valid in the self type of an impl block
--> $DIR/issue-23305.rs:5:16
|
LL | impl dyn ToNbt<Self> {}
| ^^^^
|
- = note: ...which immediately requires computing type of `<impl at $DIR/issue-23305.rs:5:1: 5:21>` again
-note: cycle used when collecting item types in top-level module
- --> $DIR/issue-23305.rs:1:1
- |
-LL | / pub trait ToNbt<T> {
-LL | | fn new(val: T) -> Self;
-LL | | }
-LL | |
-... |
-LL | |
-LL | | fn main() {}
- | |____________^
+ = note: replace `Self` with a different type
error: aborting due to previous error
-For more information about this error, try `rustc --explain E0391`.
diff --git a/src/test/ui/resolve/issue-2356.stderr b/src/test/ui/resolve/issue-2356.stderr
index b8d528efc..e7c53ff44 100644
--- a/src/test/ui/resolve/issue-2356.stderr
+++ b/src/test/ui/resolve/issue-2356.stderr
@@ -1,15 +1,3 @@
-error[E0425]: cannot find function `shave` in this scope
- --> $DIR/issue-2356.rs:17:5
- |
-LL | shave();
- | ^^^^^ not found in this scope
-
-error[E0425]: cannot find function `clone` in this scope
- --> $DIR/issue-2356.rs:24:5
- |
-LL | clone();
- | ^^^^^ help: you might have meant to call the method: `self.clone`
-
error[E0425]: cannot find function `default` in this scope
--> $DIR/issue-2356.rs:31:5
|
@@ -31,6 +19,51 @@ error[E0425]: cannot find value `whiskers` in this scope
LL | whiskers -= other;
| ^^^^^^^^ a field by this name exists in `Self`
+error[E0424]: expected value, found module `self`
+ --> $DIR/issue-2356.rs:65:8
+ |
+LL | fn meow() {
+ | ---- this function doesn't have a `self` parameter
+LL | if self.whiskers > 3 {
+ | ^^^^ `self` value is a keyword only available in methods with a `self` parameter
+ |
+help: add a `self` receiver parameter to make the associated `fn` a method
+ |
+LL | fn meow(&self) {
+ | +++++
+
+error[E0425]: cannot find value `whiskers` in this scope
+ --> $DIR/issue-2356.rs:79:5
+ |
+LL | whiskers = 0;
+ | ^^^^^^^^ help: you might have meant to use the available field: `self.whiskers`
+
+error[E0425]: cannot find value `whiskers` in this scope
+ --> $DIR/issue-2356.rs:84:5
+ |
+LL | whiskers = 4;
+ | ^^^^^^^^ a field by this name exists in `Self`
+
+error[E0424]: expected value, found module `self`
+ --> $DIR/issue-2356.rs:92:5
+ |
+LL | fn main() {
+ | ---- this function can't have a `self` parameter
+LL | self += 1;
+ | ^^^^ `self` value is a keyword only available in methods with a `self` parameter
+
+error[E0425]: cannot find function `shave` in this scope
+ --> $DIR/issue-2356.rs:17:5
+ |
+LL | shave();
+ | ^^^^^ not found in this scope
+
+error[E0425]: cannot find function `clone` in this scope
+ --> $DIR/issue-2356.rs:24:5
+ |
+LL | clone();
+ | ^^^^^ help: you might have meant to call the method: `self.clone`
+
error[E0425]: cannot find function `shave` in this scope
--> $DIR/issue-2356.rs:41:5
|
@@ -72,19 +105,6 @@ error[E0425]: cannot find function `purr` in this scope
LL | purr();
| ^^^^ not found in this scope
-error[E0424]: expected value, found module `self`
- --> $DIR/issue-2356.rs:65:8
- |
-LL | fn meow() {
- | ---- this function doesn't have a `self` parameter
-LL | if self.whiskers > 3 {
- | ^^^^ `self` value is a keyword only available in methods with a `self` parameter
- |
-help: add a `self` receiver parameter to make the associated `fn` a method
- |
-LL | fn meow(&self) {
- | +++++
-
error[E0425]: cannot find function `grow_older` in this scope
--> $DIR/issue-2356.rs:72:5
|
@@ -102,32 +122,12 @@ error[E0425]: cannot find function `shave` in this scope
LL | shave();
| ^^^^^ not found in this scope
-error[E0425]: cannot find value `whiskers` in this scope
- --> $DIR/issue-2356.rs:79:5
- |
-LL | whiskers = 0;
- | ^^^^^^^^ help: you might have meant to use the available field: `self.whiskers`
-
-error[E0425]: cannot find value `whiskers` in this scope
- --> $DIR/issue-2356.rs:84:5
- |
-LL | whiskers = 4;
- | ^^^^^^^^ a field by this name exists in `Self`
-
error[E0425]: cannot find function `purr_louder` in this scope
--> $DIR/issue-2356.rs:86:5
|
LL | purr_louder();
| ^^^^^^^^^^^ not found in this scope
-error[E0424]: expected value, found module `self`
- --> $DIR/issue-2356.rs:92:5
- |
-LL | fn main() {
- | ---- this function can't have a `self` parameter
-LL | self += 1;
- | ^^^^ `self` value is a keyword only available in methods with a `self` parameter
-
error: aborting due to 17 previous errors
Some errors have detailed explanations: E0424, E0425.
diff --git a/src/test/ui/resolve/issue-42944.stderr b/src/test/ui/resolve/issue-42944.stderr
index cad3ccc4a..0ee9fd391 100644
--- a/src/test/ui/resolve/issue-42944.stderr
+++ b/src/test/ui/resolve/issue-42944.stderr
@@ -1,15 +1,3 @@
-error[E0423]: cannot initialize a tuple struct which contains private fields
- --> $DIR/issue-42944.rs:9:9
- |
-LL | Bx(());
- | ^^
- |
-note: constructor is not visible here due to private fields
- --> $DIR/issue-42944.rs:2:19
- |
-LL | pub struct Bx(());
- | ^^ private field
-
error[E0425]: cannot find function, tuple struct or tuple variant `Bx` in this scope
--> $DIR/issue-42944.rs:16:9
|
@@ -22,6 +10,18 @@ note: tuple struct `foo::Bx` exists but is inaccessible
LL | pub struct Bx(());
| ^^^^^^^^^^^^^^^^^^ not accessible
+error[E0423]: cannot initialize a tuple struct which contains private fields
+ --> $DIR/issue-42944.rs:9:9
+ |
+LL | Bx(());
+ | ^^
+ |
+note: constructor is not visible here due to private fields
+ --> $DIR/issue-42944.rs:2:19
+ |
+LL | pub struct Bx(());
+ | ^^ private field
+
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0423, E0425.
diff --git a/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr b/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr
index 55c3b66f1..1354abb4f 100644
--- a/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr
+++ b/src/test/ui/resolve/issue-70736-async-fn-no-body-def-collector.stderr
@@ -33,7 +33,7 @@ LL | async fn associated();
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
error[E0706]: functions in traits cannot be declared `async`
--> $DIR/issue-70736-async-fn-no-body-def-collector.rs:15:5
@@ -46,7 +46,7 @@ LL | async fn associated();
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
error: aborting due to 5 previous errors
diff --git a/src/test/ui/resolve/issue-73427.stderr b/src/test/ui/resolve/issue-73427.stderr
index a2ca46f0c..d31c5e477 100644
--- a/src/test/ui/resolve/issue-73427.stderr
+++ b/src/test/ui/resolve/issue-73427.stderr
@@ -124,13 +124,13 @@ LL | use std::f32::consts::E;
LL | use std::f64::consts::E;
|
-error[E0423]: expected function, tuple struct or tuple variant, found enum `A`
- --> $DIR/issue-73427.rs:46:13
+error[E0532]: expected tuple struct or tuple variant, found enum `A`
+ --> $DIR/issue-73427.rs:48:12
|
-LL | let x = A(3);
- | ^
+LL | if let A(3) = x { }
+ | ^
|
- = help: you might have meant to construct one of the enum's non-tuple variants
+ = help: you might have meant to match against one of the enum's non-tuple variants
note: the enum is defined here
--> $DIR/issue-73427.rs:1:1
|
@@ -142,20 +142,20 @@ LL | | Tuple(),
LL | | Unit,
LL | | }
| |_^
-help: try to construct one of the enum's variants
+help: try to match against one of the enum's variants
|
-LL | let x = A::Tuple(3);
- | ~~~~~~~~
-LL | let x = A::TupleWithFields(3);
- | ~~~~~~~~~~~~~~~~~~
+LL | if let A::Tuple(3) = x { }
+ | ~~~~~~~~
+LL | if let A::TupleWithFields(3) = x { }
+ | ~~~~~~~~~~~~~~~~~~
-error[E0532]: expected tuple struct or tuple variant, found enum `A`
- --> $DIR/issue-73427.rs:48:12
+error[E0423]: expected function, tuple struct or tuple variant, found enum `A`
+ --> $DIR/issue-73427.rs:46:13
|
-LL | if let A(3) = x { }
- | ^
+LL | let x = A(3);
+ | ^
|
- = help: you might have meant to match against one of the enum's non-tuple variants
+ = help: you might have meant to construct one of the enum's non-tuple variants
note: the enum is defined here
--> $DIR/issue-73427.rs:1:1
|
@@ -167,12 +167,12 @@ LL | | Tuple(),
LL | | Unit,
LL | | }
| |_^
-help: try to match against one of the enum's variants
+help: try to construct one of the enum's variants
|
-LL | if let A::Tuple(3) = x { }
- | ~~~~~~~~
-LL | if let A::TupleWithFields(3) = x { }
- | ~~~~~~~~~~~~~~~~~~
+LL | let x = A::Tuple(3);
+ | ~~~~~~~~
+LL | let x = A::TupleWithFields(3);
+ | ~~~~~~~~~~~~~~~~~~
error: aborting due to 7 previous errors
diff --git a/src/test/ui/resolve/levenshtein.stderr b/src/test/ui/resolve/levenshtein.stderr
index 249a7e53d..9a2d61ea4 100644
--- a/src/test/ui/resolve/levenshtein.stderr
+++ b/src/test/ui/resolve/levenshtein.stderr
@@ -39,15 +39,6 @@ LL | const MAX_ITEM: usize = 10;
LL | let v = [0u32; MAXITEM]; // Misspelled constant name.
| ^^^^^^^ help: a constant with a similar name exists: `MAX_ITEM`
-error[E0425]: cannot find function `foobar` in this scope
- --> $DIR/levenshtein.rs:26:5
- |
-LL | fn foo_bar() {}
- | ------------ similarly named function `foo_bar` defined here
-...
-LL | foobar(); // Misspelled function name.
- | ^^^^^^ help: a function with a similar name exists: `foo_bar`
-
error[E0412]: cannot find type `first` in module `m`
--> $DIR/levenshtein.rs:28:15
|
@@ -66,6 +57,15 @@ LL | pub struct Second;
LL | let b: m::first = m::second; // Misspelled item in module.
| ^^^^^^ help: a unit struct with a similar name exists (notice the capitalization): `Second`
+error[E0425]: cannot find function `foobar` in this scope
+ --> $DIR/levenshtein.rs:26:5
+ |
+LL | fn foo_bar() {}
+ | ------------ similarly named function `foo_bar` defined here
+...
+LL | foobar(); // Misspelled function name.
+ | ^^^^^^ help: a function with a similar name exists: `foo_bar`
+
error: aborting due to 8 previous errors
Some errors have detailed explanations: E0412, E0425.
diff --git a/src/test/ui/resolve/name-collision-in-trait-fn-sig.rs b/src/test/ui/resolve/name-collision-in-trait-fn-sig.rs
new file mode 100644
index 000000000..fba4ffa1c
--- /dev/null
+++ b/src/test/ui/resolve/name-collision-in-trait-fn-sig.rs
@@ -0,0 +1,11 @@
+// check-pass
+// This is currently stable behavior, which was almost accidentally made an
+// error in #102161 since there is no test exercising it. I am not sure if
+// this _should_ be the desired behavior, but at least we should know if it
+// changes.
+
+fn main() {}
+
+trait Foo {
+ fn fn_with_type_named_same_as_local_in_param(b: i32, b: i32);
+}
diff --git a/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.stderr b/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.stderr
index af9f4612a..eb26cd9ca 100644
--- a/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.stderr
+++ b/src/test/ui/resolve/point-at-type-parameter-shadowing-another-type.stderr
@@ -1,11 +1,16 @@
error[E0574]: expected struct, variant or union type, found type parameter `Baz`
--> $DIR/point-at-type-parameter-shadowing-another-type.rs:16:13
|
-LL | impl<Baz> Foo<Baz> for Bar {
- | --- found this type parameter
+LL | / struct Baz {
+LL | | num: usize,
+LL | | }
+ | |_- you might have meant to refer to this struct
+LL |
+LL | impl<Baz> Foo<Baz> for Bar {
+ | --- found this type parameter
...
-LL | Baz { num } => num,
- | ^^^ not a struct, variant or union type
+LL | Baz { num } => num,
+ | ^^^ not a struct, variant or union type
error: aborting due to previous error
diff --git a/src/test/ui/resolve/privacy-enum-ctor.stderr b/src/test/ui/resolve/privacy-enum-ctor.stderr
index a369dc6db..82a4211f0 100644
--- a/src/test/ui/resolve/privacy-enum-ctor.stderr
+++ b/src/test/ui/resolve/privacy-enum-ctor.stderr
@@ -327,7 +327,7 @@ LL | let _: Z = Z::Fn;
|
= note: expected enum `Z`
found fn item `fn(u8) -> Z {Z::Fn}`
-help: use parentheses to instantiate this tuple variant
+help: use parentheses to construct this tuple variant
|
LL | let _: Z = Z::Fn(/* u8 */);
| ++++++++++
@@ -362,7 +362,7 @@ LL | let _: E = m::E::Fn;
|
= note: expected enum `E`
found fn item `fn(u8) -> E {E::Fn}`
-help: use parentheses to instantiate this tuple variant
+help: use parentheses to construct this tuple variant
|
LL | let _: E = m::E::Fn(/* u8 */);
| ++++++++++
@@ -397,7 +397,7 @@ LL | let _: E = E::Fn;
|
= note: expected enum `E`
found fn item `fn(u8) -> E {E::Fn}`
-help: use parentheses to instantiate this tuple variant
+help: use parentheses to construct this tuple variant
|
LL | let _: E = E::Fn(/* u8 */);
| ++++++++++
diff --git a/src/test/ui/resolve/resolve-assoc-suggestions.stderr b/src/test/ui/resolve/resolve-assoc-suggestions.stderr
index b6acaeb8c..8def9aa20 100644
--- a/src/test/ui/resolve/resolve-assoc-suggestions.stderr
+++ b/src/test/ui/resolve/resolve-assoc-suggestions.stderr
@@ -50,7 +50,7 @@ error[E0425]: cannot find value `method` in this scope
--> $DIR/resolve-assoc-suggestions.rs:34:9
|
LL | method;
- | ^^^^^^ help: you might have meant to call the method: `self.method`
+ | ^^^^^^ help: you might have meant to refer to the method: `self.method`
error: aborting due to 9 previous errors
diff --git a/src/test/ui/resolve/resolve-hint-macro.stderr b/src/test/ui/resolve/resolve-hint-macro.stderr
index bc69ddd8f..1e7ab48ef 100644
--- a/src/test/ui/resolve/resolve-hint-macro.stderr
+++ b/src/test/ui/resolve/resolve-hint-macro.stderr
@@ -14,17 +14,6 @@ LL | assert_eq { 1, 1 };
| |
| while parsing this struct
-error[E0423]: expected function, found macro `assert_eq`
- --> $DIR/resolve-hint-macro.rs:3:5
- |
-LL | assert_eq(1, 1);
- | ^^^^^^^^^ not a function
- |
-help: use `!` to invoke the macro
- |
-LL | assert_eq!(1, 1);
- | +
-
error[E0574]: expected struct, variant or union type, found macro `assert_eq`
--> $DIR/resolve-hint-macro.rs:5:5
|
@@ -47,6 +36,17 @@ help: use `!` to invoke the macro
LL | assert![true];
| +
+error[E0423]: expected function, found macro `assert_eq`
+ --> $DIR/resolve-hint-macro.rs:3:5
+ |
+LL | assert_eq(1, 1);
+ | ^^^^^^^^^ not a function
+ |
+help: use `!` to invoke the macro
+ |
+LL | assert_eq!(1, 1);
+ | +
+
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0423, E0574.
diff --git a/src/test/ui/resolve/resolve-self-in-impl.rs b/src/test/ui/resolve/resolve-self-in-impl.rs
index 024fdc51e..d0872d1b7 100644
--- a/src/test/ui/resolve/resolve-self-in-impl.rs
+++ b/src/test/ui/resolve/resolve-self-in-impl.rs
@@ -11,10 +11,11 @@ impl Tr for S where Self: Copy {} // OK
impl Tr for S where S<Self>: Copy {} // OK
impl Tr for S where Self::A: Copy {} // OK
-impl Tr for Self {} //~ ERROR cycle detected
-impl Tr for S<Self> {} //~ ERROR cycle detected
-impl Self {} //~ ERROR cycle detected
-impl S<Self> {} //~ ERROR cycle detected
+impl Tr for Self {} //~ ERROR `Self` is not valid in the self type of an impl block
+impl Tr for S<Self> {} //~ ERROR `Self` is not valid in the self type of an impl block
+impl Self {} //~ ERROR `Self` is not valid in the self type of an impl block
+impl S<Self> {} //~ ERROR `Self` is not valid in the self type of an impl block
+impl (Self, Self) {} //~ ERROR `Self` is not valid in the self type of an impl block
impl Tr<Self::A> for S {} //~ ERROR cycle detected
fn main() {}
diff --git a/src/test/ui/resolve/resolve-self-in-impl.stderr b/src/test/ui/resolve/resolve-self-in-impl.stderr
index aa99c1a33..9f9ed6889 100644
--- a/src/test/ui/resolve/resolve-self-in-impl.stderr
+++ b/src/test/ui/resolve/resolve-self-in-impl.stderr
@@ -1,86 +1,50 @@
-error[E0391]: cycle detected when computing type of `<impl at $DIR/resolve-self-in-impl.rs:14:1: 14:17>`
+error: `Self` is not valid in the self type of an impl block
--> $DIR/resolve-self-in-impl.rs:14:13
|
LL | impl Tr for Self {}
| ^^^^
|
- = note: ...which immediately requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:14:1: 14:17>` again
-note: cycle used when collecting item types in top-level module
- --> $DIR/resolve-self-in-impl.rs:1:1
- |
-LL | / #![feature(associated_type_defaults)]
-LL | |
-LL | | struct S<T = u8>(T);
-LL | | trait Tr<T = u8> {
-... |
-LL | |
-LL | | fn main() {}
- | |____________^
+ = note: replace `Self` with a different type
-error[E0391]: cycle detected when computing type of `<impl at $DIR/resolve-self-in-impl.rs:15:1: 15:20>`
+error: `Self` is not valid in the self type of an impl block
--> $DIR/resolve-self-in-impl.rs:15:15
|
LL | impl Tr for S<Self> {}
| ^^^^
|
- = note: ...which immediately requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:15:1: 15:20>` again
-note: cycle used when collecting item types in top-level module
- --> $DIR/resolve-self-in-impl.rs:1:1
- |
-LL | / #![feature(associated_type_defaults)]
-LL | |
-LL | | struct S<T = u8>(T);
-LL | | trait Tr<T = u8> {
-... |
-LL | |
-LL | | fn main() {}
- | |____________^
+ = note: replace `Self` with a different type
-error[E0391]: cycle detected when computing type of `<impl at $DIR/resolve-self-in-impl.rs:16:1: 16:10>`
+error: `Self` is not valid in the self type of an impl block
--> $DIR/resolve-self-in-impl.rs:16:6
|
LL | impl Self {}
| ^^^^
|
- = note: ...which immediately requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:16:1: 16:10>` again
-note: cycle used when collecting item types in top-level module
- --> $DIR/resolve-self-in-impl.rs:1:1
- |
-LL | / #![feature(associated_type_defaults)]
-LL | |
-LL | | struct S<T = u8>(T);
-LL | | trait Tr<T = u8> {
-... |
-LL | |
-LL | | fn main() {}
- | |____________^
+ = note: replace `Self` with a different type
-error[E0391]: cycle detected when computing type of `<impl at $DIR/resolve-self-in-impl.rs:17:1: 17:13>`
+error: `Self` is not valid in the self type of an impl block
--> $DIR/resolve-self-in-impl.rs:17:8
|
LL | impl S<Self> {}
| ^^^^
|
- = note: ...which immediately requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:17:1: 17:13>` again
-note: cycle used when collecting item types in top-level module
- --> $DIR/resolve-self-in-impl.rs:1:1
+ = note: replace `Self` with a different type
+
+error: `Self` is not valid in the self type of an impl block
+ --> $DIR/resolve-self-in-impl.rs:18:7
|
-LL | / #![feature(associated_type_defaults)]
-LL | |
-LL | | struct S<T = u8>(T);
-LL | | trait Tr<T = u8> {
-... |
-LL | |
-LL | | fn main() {}
- | |____________^
+LL | impl (Self, Self) {}
+ | ^^^^ ^^^^
+ |
+ = note: replace `Self` with a different type
-error[E0391]: cycle detected when computing trait implemented by `<impl at $DIR/resolve-self-in-impl.rs:18:1: 18:23>`
- --> $DIR/resolve-self-in-impl.rs:18:1
+error[E0391]: cycle detected when computing trait implemented by `<impl at $DIR/resolve-self-in-impl.rs:19:1: 19:23>`
+ --> $DIR/resolve-self-in-impl.rs:19:1
|
LL | impl Tr<Self::A> for S {}
| ^^^^^^^^^^^^^^^^^^^^^^
|
- = note: ...which immediately requires computing trait implemented by `<impl at $DIR/resolve-self-in-impl.rs:18:1: 18:23>` again
+ = note: ...which immediately requires computing trait implemented by `<impl at $DIR/resolve-self-in-impl.rs:19:1: 19:23>` again
note: cycle used when collecting item types in top-level module
--> $DIR/resolve-self-in-impl.rs:1:1
|
@@ -93,6 +57,6 @@ LL | |
LL | | fn main() {}
| |____________^
-error: aborting due to 5 previous errors
+error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0391`.
diff --git a/src/test/ui/resolve/resolve-speculative-adjustment.stderr b/src/test/ui/resolve/resolve-speculative-adjustment.stderr
index 1c34af6d0..be11a7ebe 100644
--- a/src/test/ui/resolve/resolve-speculative-adjustment.stderr
+++ b/src/test/ui/resolve/resolve-speculative-adjustment.stderr
@@ -4,12 +4,6 @@ error[E0425]: cannot find value `field` in this scope
LL | field;
| ^^^^^ not found in this scope
-error[E0425]: cannot find function `method` in this scope
- --> $DIR/resolve-speculative-adjustment.rs:19:13
- |
-LL | method();
- | ^^^^^^ not found in this scope
-
error[E0425]: cannot find value `field` in this scope
--> $DIR/resolve-speculative-adjustment.rs:23:9
|
@@ -22,6 +16,12 @@ error[E0425]: cannot find function `method` in this scope
LL | method();
| ^^^^^^ help: you might have meant to call the method: `self.method`
+error[E0425]: cannot find function `method` in this scope
+ --> $DIR/resolve-speculative-adjustment.rs:19:13
+ |
+LL | method();
+ | ^^^^^^ not found in this scope
+
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/resolve/tuple-struct-alias.stderr b/src/test/ui/resolve/tuple-struct-alias.stderr
index 5a7873301..a739ea43e 100644
--- a/src/test/ui/resolve/tuple-struct-alias.stderr
+++ b/src/test/ui/resolve/tuple-struct-alias.stderr
@@ -1,22 +1,22 @@
-error[E0423]: expected function, tuple struct or tuple variant, found type alias `A`
- --> $DIR/tuple-struct-alias.rs:5:13
+error[E0532]: expected tuple struct or tuple variant, found type alias `A`
+ --> $DIR/tuple-struct-alias.rs:7:9
|
LL | struct S(u8, u16);
| ------------------ similarly named tuple struct `S` defined here
...
-LL | let s = A(0, 1);
- | ^ help: a tuple struct with a similar name exists: `S`
+LL | A(..) => {}
+ | ^ help: a tuple struct with a similar name exists: `S`
|
= note: can't use a type alias as a constructor
-error[E0532]: expected tuple struct or tuple variant, found type alias `A`
- --> $DIR/tuple-struct-alias.rs:7:9
+error[E0423]: expected function, tuple struct or tuple variant, found type alias `A`
+ --> $DIR/tuple-struct-alias.rs:5:13
|
LL | struct S(u8, u16);
| ------------------ similarly named tuple struct `S` defined here
...
-LL | A(..) => {}
- | ^ help: a tuple struct with a similar name exists: `S`
+LL | let s = A(0, 1);
+ | ^ help: a tuple struct with a similar name exists: `S`
|
= note: can't use a type alias as a constructor
diff --git a/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr b/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr
index 0b0a37f24..f32e0404e 100644
--- a/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr
+++ b/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr
@@ -31,24 +31,6 @@ help: a local variable with a similar name exists
LL | println!("{cofig}");
| ~~~~~
-error[E0425]: cannot find function `baz` in this scope
- --> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:31:9
- |
-LL | baz();
- | ^^^
-...
-LL | fn ba() {}
- | ------- similarly named function `ba` defined here
- |
-help: you might have meant to call the method
- |
-LL | self.baz();
- | ~~~~~~~~
-help: a function with a similar name exists
- |
-LL | ba();
- | ~~
-
error[E0425]: cannot find value `bah` in this scope
--> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:33:9
|
@@ -58,7 +40,7 @@ LL | bah;
LL | fn ba() {}
| ------- similarly named function `ba` defined here
|
-help: you might have meant to call the associated function
+help: you might have meant to refer to the associated function
|
LL | Self::bah;
| ~~~~~~~~~
@@ -103,6 +85,24 @@ help: a type alias with a similar name exists
LL | let foo: Bar = "".to_string();
| ~~~
+error[E0425]: cannot find function `baz` in this scope
+ --> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:31:9
+ |
+LL | baz();
+ | ^^^
+...
+LL | fn ba() {}
+ | ------- similarly named function `ba` defined here
+ |
+help: you might have meant to call the method
+ |
+LL | self.baz();
+ | ~~~~~~~~
+help: a function with a similar name exists
+ |
+LL | ba();
+ | ~~
+
error: aborting due to 7 previous errors
Some errors have detailed explanations: E0412, E0425.
diff --git a/src/test/ui/issues/issue-64620.rs b/src/test/ui/return/issue-64620.rs
index a62e5bf8d..a62e5bf8d 100644
--- a/src/test/ui/issues/issue-64620.rs
+++ b/src/test/ui/return/issue-64620.rs
diff --git a/src/test/ui/issues/issue-64620.stderr b/src/test/ui/return/issue-64620.stderr
index f40ac4de3..f40ac4de3 100644
--- a/src/test/ui/issues/issue-64620.stderr
+++ b/src/test/ui/return/issue-64620.stderr
diff --git a/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-doubly-indirect-embedded.stderr b/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-doubly-indirect-embedded.stderr
index 659a98126..10dd635ff 100644
--- a/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-doubly-indirect-embedded.stderr
+++ b/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-doubly-indirect-embedded.stderr
@@ -4,13 +4,13 @@ warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be a
LL | WRAP_DOUBLY_INDIRECT_INLINE => { panic!("WRAP_DOUBLY_INDIRECT_INLINE matched itself"); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
note: the lint level is defined here
--> $DIR/cant-hide-behind-doubly-indirect-embedded.rs:7:9
|
LL | #![warn(indirect_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
warning: 1 warning emitted
diff --git a/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-doubly-indirect-param.stderr b/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-doubly-indirect-param.stderr
index c8c365105..66aecbc4f 100644
--- a/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-doubly-indirect-param.stderr
+++ b/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-doubly-indirect-param.stderr
@@ -4,13 +4,13 @@ warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be a
LL | WRAP_DOUBLY_INDIRECT_PARAM => { panic!("WRAP_DOUBLY_INDIRECT_PARAM matched itself"); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
note: the lint level is defined here
--> $DIR/cant-hide-behind-doubly-indirect-param.rs:7:9
|
LL | #![warn(indirect_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
warning: 1 warning emitted
diff --git a/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-indirect-struct-embedded.stderr b/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-indirect-struct-embedded.stderr
index 8abbd5d34..ee92954a6 100644
--- a/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-indirect-struct-embedded.stderr
+++ b/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-indirect-struct-embedded.stderr
@@ -4,13 +4,13 @@ warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be a
LL | WRAP_INDIRECT_INLINE => { panic!("WRAP_INDIRECT_INLINE matched itself"); }
| ^^^^^^^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
note: the lint level is defined here
--> $DIR/cant-hide-behind-indirect-struct-embedded.rs:7:9
|
LL | #![warn(indirect_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
warning: 1 warning emitted
diff --git a/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-indirect-struct-param.stderr b/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-indirect-struct-param.stderr
index 3a716d54f..f0c492d6a 100644
--- a/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-indirect-struct-param.stderr
+++ b/src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-indirect-struct-param.stderr
@@ -4,13 +4,13 @@ warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be a
LL | WRAP_INDIRECT_PARAM => { panic!("WRAP_INDIRECT_PARAM matched itself"); }
| ^^^^^^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
note: the lint level is defined here
--> $DIR/cant-hide-behind-indirect-struct-param.rs:7:9
|
LL | #![warn(indirect_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
warning: 1 warning emitted
diff --git a/src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-62307-match-ref-ref-forbidden-without-eq.stderr b/src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-62307-match-ref-ref-forbidden-without-eq.stderr
index a50093a5b..955ab4b54 100644
--- a/src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-62307-match-ref-ref-forbidden-without-eq.stderr
+++ b/src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-62307-match-ref-ref-forbidden-without-eq.stderr
@@ -4,13 +4,13 @@ warning: to use a constant of type `B` in a pattern, `B` must be annotated with
LL | RR_B1 => { println!("CLAIM RR0: {:?} matches {:?}", RR_B1, RR_B0); }
| ^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
note: the lint level is defined here
--> $DIR/issue-62307-match-ref-ref-forbidden-without-eq.rs:13:9
|
LL | #![warn(indirect_structural_match, nontrivial_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
warning: to use a constant of type `B` in a pattern, `B` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/issue-62307-match-ref-ref-forbidden-without-eq.rs:38:9
diff --git a/src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-63479-match-fnptr.stderr b/src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-63479-match-fnptr.stderr
index 8cf87cc85..d6afc0255 100644
--- a/src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-63479-match-fnptr.stderr
+++ b/src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-63479-match-fnptr.stderr
@@ -4,13 +4,13 @@ warning: function pointers and unsized pointers in patterns behave unpredictably
LL | B(TEST) => println!("matched"),
| ^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
note: the lint level is defined here
--> $DIR/issue-63479-match-fnptr.rs:8:9
|
LL | #![warn(pointer_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
warning: 1 warning emitted
diff --git a/src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-6804.stderr b/src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-6804.stderr
index 4e2961e5e..f37255d08 100644
--- a/src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-6804.stderr
+++ b/src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-6804.stderr
@@ -4,13 +4,13 @@ error: floating-point types cannot be used in patterns
LL | NAN => {},
| ^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
note: the lint level is defined here
--> $DIR/issue-6804.rs:4:9
|
LL | #![deny(illegal_floating_point_literal_pattern)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
error: floating-point types cannot be used in patterns
--> $DIR/issue-6804.rs:17:10
diff --git a/src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.stderr b/src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.stderr
index df4809dab..616ed9e48 100644
--- a/src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.stderr
+++ b/src/test/ui/rfc-1445-restrict-constants-in-patterns/match-forbidden-without-eq.stderr
@@ -10,9 +10,9 @@ warning: floating-point types cannot be used in patterns
LL | f32::INFINITY => { }
| ^^^^^^^^^^^^^
|
- = note: `#[warn(illegal_floating_point_literal_pattern)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #41620 <https://github.com/rust-lang/rust/issues/41620>
+ = note: `#[warn(illegal_floating_point_literal_pattern)]` on by default
error: aborting due to previous error; 1 warning emitted
diff --git a/src/test/ui/rfc-1937-termination-trait/issue-103052-1.rs b/src/test/ui/rfc-1937-termination-trait/issue-103052-1.rs
new file mode 100644
index 000000000..a75c91cc9
--- /dev/null
+++ b/src/test/ui/rfc-1937-termination-trait/issue-103052-1.rs
@@ -0,0 +1,11 @@
+// Check that we don't blindly emit a diagnostic claiming that "`main` has an invalid return type"
+// if we encounter a type that doesn't implement `std::process::Termination` and is not actually
+// the return type of the program entry `main`.
+
+fn receive(_: impl std::process::Termination) {}
+
+struct Something;
+
+fn main() {
+ receive(Something); //~ ERROR the trait bound `Something: Termination` is not satisfied
+}
diff --git a/src/test/ui/rfc-1937-termination-trait/issue-103052-1.stderr b/src/test/ui/rfc-1937-termination-trait/issue-103052-1.stderr
new file mode 100644
index 000000000..409dede1a
--- /dev/null
+++ b/src/test/ui/rfc-1937-termination-trait/issue-103052-1.stderr
@@ -0,0 +1,17 @@
+error[E0277]: the trait bound `Something: Termination` is not satisfied
+ --> $DIR/issue-103052-1.rs:10:13
+ |
+LL | receive(Something);
+ | ------- ^^^^^^^^^ the trait `Termination` is not implemented for `Something`
+ | |
+ | required by a bound introduced by this call
+ |
+note: required by a bound in `receive`
+ --> $DIR/issue-103052-1.rs:5:20
+ |
+LL | fn receive(_: impl std::process::Termination) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `receive`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/rfc-1937-termination-trait/issue-103052-2.rs b/src/test/ui/rfc-1937-termination-trait/issue-103052-2.rs
new file mode 100644
index 000000000..fa9182b6d
--- /dev/null
+++ b/src/test/ui/rfc-1937-termination-trait/issue-103052-2.rs
@@ -0,0 +1,18 @@
+#![feature(return_position_impl_trait_in_trait)]
+#![allow(incomplete_features)]
+
+mod child {
+ trait Main {
+ fn main() -> impl std::process::Termination;
+ }
+
+ struct Something;
+
+ impl Main for () {
+ fn main() -> Something { //~ ERROR the trait bound `Something: Termination` is not satisfied
+ Something
+ }
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-1937-termination-trait/issue-103052-2.stderr b/src/test/ui/rfc-1937-termination-trait/issue-103052-2.stderr
new file mode 100644
index 000000000..a700c72ea
--- /dev/null
+++ b/src/test/ui/rfc-1937-termination-trait/issue-103052-2.stderr
@@ -0,0 +1,15 @@
+error[E0277]: the trait bound `Something: Termination` is not satisfied
+ --> $DIR/issue-103052-2.rs:12:22
+ |
+LL | fn main() -> Something {
+ | ^^^^^^^^^ the trait `Termination` is not implemented for `Something`
+ |
+note: required by a bound in `Main::main::{opaque#0}`
+ --> $DIR/issue-103052-2.rs:6:27
+ |
+LL | fn main() -> impl std::process::Termination;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Main::main::{opaque#0}`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/rfc-1937-termination-trait/termination-trait-in-test.rs b/src/test/ui/rfc-1937-termination-trait/termination-trait-in-test.rs
index cd57d9bca..43888cece 100644
--- a/src/test/ui/rfc-1937-termination-trait/termination-trait-in-test.rs
+++ b/src/test/ui/rfc-1937-termination-trait/termination-trait-in-test.rs
@@ -2,7 +2,6 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
#![feature(test)]
diff --git a/src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr b/src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr
index 7d81de438..6ee323146 100644
--- a/src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr
+++ b/src/test/ui/rfc-1937-termination-trait/termination-trait-test-wrong-type.stderr
@@ -1,4 +1,4 @@
-error[E0277]: `main` has invalid return type `f32`
+error[E0277]: the trait bound `f32: Termination` is not satisfied
--> $DIR/termination-trait-test-wrong-type.rs:6:1
|
LL | #[test]
@@ -6,14 +6,13 @@ LL | #[test]
LL | / fn can_parse_zero_as_f32() -> Result<f32, ParseFloatError> {
LL | | "0".parse()
LL | | }
- | |_^ `main` can only return types that implement `Termination`
+ | |_^ the trait `Termination` is not implemented for `f32`
|
- = help: the trait `Termination` is not implemented for `f32`
= note: required for `Result<f32, ParseFloatError>` to implement `Termination`
note: required by a bound in `assert_test_result`
--> $SRC_DIR/test/src/lib.rs:LL:COL
|
-LL | pub fn assert_test_result<T: Termination>(result: T) {
+LL | pub fn assert_test_result<T: Termination>(result: T) -> Result<(), String> {
| ^^^^^^^^^^^ required by this bound in `assert_test_result`
= note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/src/test/ui/rfc-2008-non-exhaustive/improper_ctypes/extern_crate_improper.stderr b/src/test/ui/rfc-2008-non-exhaustive/improper_ctypes/extern_crate_improper.stderr
index 8a18ebc16..43c8e1015 100644
--- a/src/test/ui/rfc-2008-non-exhaustive/improper_ctypes/extern_crate_improper.stderr
+++ b/src/test/ui/rfc-2008-non-exhaustive/improper_ctypes/extern_crate_improper.stderr
@@ -4,12 +4,12 @@ error: `extern` block uses type `NonExhaustiveEnum`, which is not FFI-safe
LL | pub fn non_exhaustive_enum(_: NonExhaustiveEnum);
| ^^^^^^^^^^^^^^^^^ not FFI-safe
|
+ = note: this enum is non-exhaustive
note: the lint level is defined here
--> $DIR/extern_crate_improper.rs:2:9
|
LL | #![deny(improper_ctypes)]
| ^^^^^^^^^^^^^^^
- = note: this enum is non-exhaustive
error: `extern` block uses type `NormalStruct`, which is not FFI-safe
--> $DIR/extern_crate_improper.rs:14:44
diff --git a/src/test/ui/rfc-2008-non-exhaustive/omitted-patterns.stderr b/src/test/ui/rfc-2008-non-exhaustive/omitted-patterns.stderr
index 4b9f8564d..996bd4a12 100644
--- a/src/test/ui/rfc-2008-non-exhaustive/omitted-patterns.stderr
+++ b/src/test/ui/rfc-2008-non-exhaustive/omitted-patterns.stderr
@@ -4,13 +4,13 @@ warning: some fields are not explicitly listed
LL | VariantNonExhaustive::Bar { x, .. } => {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `y` not listed
|
+ = help: ensure that all fields are mentioned explicitly by adding the suggested fields
+ = note: the pattern is of type `VariantNonExhaustive` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/omitted-patterns.rs:99:12
|
LL | #[warn(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all fields are mentioned explicitly by adding the suggested fields
- = note: the pattern is of type `VariantNonExhaustive` and the `non_exhaustive_omitted_patterns` attribute was found
warning: some fields are not explicitly listed
--> $DIR/omitted-patterns.rs:107:9
@@ -18,13 +18,13 @@ warning: some fields are not explicitly listed
LL | let FunctionalRecord { first_field, second_field, .. } = FunctionalRecord::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `third_field` not listed
|
+ = help: ensure that all fields are mentioned explicitly by adding the suggested fields
+ = note: the pattern is of type `FunctionalRecord` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/omitted-patterns.rs:106:12
|
LL | #[warn(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all fields are mentioned explicitly by adding the suggested fields
- = note: the pattern is of type `FunctionalRecord` and the `non_exhaustive_omitted_patterns` attribute was found
warning: some fields are not explicitly listed
--> $DIR/omitted-patterns.rs:115:29
@@ -32,13 +32,13 @@ warning: some fields are not explicitly listed
LL | let NestedStruct { bar: NormalStruct { first_field, .. }, .. } = NestedStruct::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `second_field` not listed
|
+ = help: ensure that all fields are mentioned explicitly by adding the suggested fields
+ = note: the pattern is of type `NormalStruct` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/omitted-patterns.rs:114:12
|
LL | #[warn(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all fields are mentioned explicitly by adding the suggested fields
- = note: the pattern is of type `NormalStruct` and the `non_exhaustive_omitted_patterns` attribute was found
warning: some fields are not explicitly listed
--> $DIR/omitted-patterns.rs:115:9
@@ -55,13 +55,13 @@ warning: some fields are not explicitly listed
LL | let OnlyUnstableStruct { unstable, .. } = OnlyUnstableStruct::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `unstable2` not listed
|
+ = help: ensure that all fields are mentioned explicitly by adding the suggested fields
+ = note: the pattern is of type `OnlyUnstableStruct` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/omitted-patterns.rs:172:12
|
LL | #[warn(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all fields are mentioned explicitly by adding the suggested fields
- = note: the pattern is of type `OnlyUnstableStruct` and the `non_exhaustive_omitted_patterns` attribute was found
warning: some fields are not explicitly listed
--> $DIR/omitted-patterns.rs:181:9
@@ -69,13 +69,13 @@ warning: some fields are not explicitly listed
LL | let UnstableStruct { stable, stable2, .. } = UnstableStruct::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `unstable` not listed
|
+ = help: ensure that all fields are mentioned explicitly by adding the suggested fields
+ = note: the pattern is of type `UnstableStruct` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/omitted-patterns.rs:180:12
|
LL | #[warn(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all fields are mentioned explicitly by adding the suggested fields
- = note: the pattern is of type `UnstableStruct` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/omitted-patterns.rs:58:9
@@ -83,13 +83,13 @@ error: some variants are not matched explicitly
LL | _ => {}
| ^ pattern `NonExhaustiveEnum::Struct { .. }` not covered
|
+ = help: ensure that all variants are matched explicitly by adding the suggested match arms
+ = note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/omitted-patterns.rs:57:16
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all variants are matched explicitly by adding the suggested match arms
- = note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/omitted-patterns.rs:65:9
@@ -97,13 +97,13 @@ error: some variants are not matched explicitly
LL | _ => {}
| ^ pattern `NonExhaustiveEnum::Tuple(_)` not covered
|
+ = help: ensure that all variants are matched explicitly by adding the suggested match arms
+ = note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/omitted-patterns.rs:64:16
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all variants are matched explicitly by adding the suggested match arms
- = note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/omitted-patterns.rs:75:9
@@ -111,13 +111,13 @@ error: some variants are not matched explicitly
LL | _ => {}
| ^ pattern `NonExhaustiveEnum::Unit` not covered
|
+ = help: ensure that all variants are matched explicitly by adding the suggested match arms
+ = note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/omitted-patterns.rs:74:16
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all variants are matched explicitly by adding the suggested match arms
- = note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/omitted-patterns.rs:92:32
@@ -125,13 +125,13 @@ error: some variants are not matched explicitly
LL | NestedNonExhaustive::A(_) => {}
| ^ patterns `NonExhaustiveEnum::Tuple(_)` and `NonExhaustiveEnum::Struct { .. }` not covered
|
+ = help: ensure that all variants are matched explicitly by adding the suggested match arms
+ = note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/omitted-patterns.rs:89:12
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all variants are matched explicitly by adding the suggested match arms
- = note: the matched value is of type `NonExhaustiveEnum` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/omitted-patterns.rs:94:9
@@ -148,13 +148,13 @@ error: some variants are not matched explicitly
LL | _ => {}
| ^ pattern `NonExhaustiveSingleVariant::A(_)` not covered
|
+ = help: ensure that all variants are matched explicitly by adding the suggested match arms
+ = note: the matched value is of type `NonExhaustiveSingleVariant` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/omitted-patterns.rs:130:12
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all variants are matched explicitly by adding the suggested match arms
- = note: the matched value is of type `NonExhaustiveSingleVariant` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/omitted-patterns.rs:144:9
@@ -162,13 +162,13 @@ error: some variants are not matched explicitly
LL | _ => {}
| ^ pattern `UnstableEnum::Unstable` not covered
|
+ = help: ensure that all variants are matched explicitly by adding the suggested match arms
+ = note: the matched value is of type `UnstableEnum` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/omitted-patterns.rs:143:16
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all variants are matched explicitly by adding the suggested match arms
- = note: the matched value is of type `UnstableEnum` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/omitted-patterns.rs:168:9
@@ -176,13 +176,13 @@ error: some variants are not matched explicitly
LL | _ => {}
| ^ pattern `OnlyUnstableEnum::Unstable2` not covered
|
+ = help: ensure that all variants are matched explicitly by adding the suggested match arms
+ = note: the matched value is of type `OnlyUnstableEnum` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/omitted-patterns.rs:165:12
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all variants are matched explicitly by adding the suggested match arms
- = note: the matched value is of type `OnlyUnstableEnum` and the `non_exhaustive_omitted_patterns` attribute was found
error: aborting due to 8 previous errors; 6 warnings emitted
diff --git a/src/test/ui/rfc-2008-non-exhaustive/stable-omitted-patterns.stderr b/src/test/ui/rfc-2008-non-exhaustive/stable-omitted-patterns.stderr
index 533e8abf2..f38368590 100644
--- a/src/test/ui/rfc-2008-non-exhaustive/stable-omitted-patterns.stderr
+++ b/src/test/ui/rfc-2008-non-exhaustive/stable-omitted-patterns.stderr
@@ -4,13 +4,13 @@ warning: some fields are not explicitly listed
LL | let UnstableStruct { stable, .. } = UnstableStruct::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ field `stable2` not listed
|
+ = help: ensure that all fields are mentioned explicitly by adding the suggested fields
+ = note: the pattern is of type `UnstableStruct` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/stable-omitted-patterns.rs:38:12
|
LL | #[warn(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all fields are mentioned explicitly by adding the suggested fields
- = note: the pattern is of type `UnstableStruct` and the `non_exhaustive_omitted_patterns` attribute was found
error: some variants are not matched explicitly
--> $DIR/stable-omitted-patterns.rs:23:9
@@ -18,13 +18,13 @@ error: some variants are not matched explicitly
LL | _ => {}
| ^ pattern `UnstableEnum::Stable2` not covered
|
+ = help: ensure that all variants are matched explicitly by adding the suggested match arms
+ = note: the matched value is of type `UnstableEnum` and the `non_exhaustive_omitted_patterns` attribute was found
note: the lint level is defined here
--> $DIR/stable-omitted-patterns.rs:22:16
|
LL | #[deny(non_exhaustive_omitted_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: ensure that all variants are matched explicitly by adding the suggested match arms
- = note: the matched value is of type `UnstableEnum` and the `non_exhaustive_omitted_patterns` attribute was found
error: aborting due to previous error; 1 warning emitted
diff --git a/src/test/ui/rfc-2008-non-exhaustive/struct.stderr b/src/test/ui/rfc-2008-non-exhaustive/struct.stderr
index 2b34d0711..2cb9ba0d1 100644
--- a/src/test/ui/rfc-2008-non-exhaustive/struct.stderr
+++ b/src/test/ui/rfc-2008-non-exhaustive/struct.stderr
@@ -1,9 +1,3 @@
-error[E0423]: cannot initialize a tuple struct which contains private fields
- --> $DIR/struct.rs:20:14
- |
-LL | let ts = TupleStruct(640, 480);
- | ^^^^^^^^^^^
-
error[E0423]: expected value, found struct `UnitStruct`
--> $DIR/struct.rs:29:14
|
@@ -68,6 +62,12 @@ help: add `..` at the end of the field list to ignore all other fields
LL | let NormalStruct { first_field, second_field , .. } = ns;
| ~~~~~~
+error[E0423]: cannot initialize a tuple struct which contains private fields
+ --> $DIR/struct.rs:20:14
+ |
+LL | let ts = TupleStruct(640, 480);
+ | ^^^^^^^^^^^
+
error[E0638]: `..` required with struct marked as non-exhaustive
--> $DIR/struct.rs:26:9
|
diff --git a/src/test/ui/rfc-2091-track-caller/std-panic-locations.rs b/src/test/ui/rfc-2091-track-caller/std-panic-locations.rs
index b067994a5..f11456250 100644
--- a/src/test/ui/rfc-2091-track-caller/std-panic-locations.rs
+++ b/src/test/ui/rfc-2091-track-caller/std-panic-locations.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
// revisions: default mir-opt
//[mir-opt] compile-flags: -Zmir-opt-level=4
diff --git a/src/test/ui/rfc-2126-extern-absolute-paths/not-allowed.stderr b/src/test/ui/rfc-2126-extern-absolute-paths/not-allowed.stderr
index a66330ccc..761089cd3 100644
--- a/src/test/ui/rfc-2126-extern-absolute-paths/not-allowed.stderr
+++ b/src/test/ui/rfc-2126-extern-absolute-paths/not-allowed.stderr
@@ -3,6 +3,13 @@ error[E0432]: unresolved import `alloc`
|
LL | use alloc;
| ^^^^^ no external crate `alloc`
+ |
+help: consider importing one of these items instead
+ |
+LL | use core::alloc;
+ | ~~~~~~~~~~~~
+LL | use std::alloc;
+ | ~~~~~~~~~~~
error: aborting due to previous error
diff --git a/src/test/ui/rfc-2294-if-let-guard/warns.stderr b/src/test/ui/rfc-2294-if-let-guard/warns.stderr
index cf64513f9..75f22ac8d 100644
--- a/src/test/ui/rfc-2294-if-let-guard/warns.stderr
+++ b/src/test/ui/rfc-2294-if-let-guard/warns.stderr
@@ -4,13 +4,13 @@ error: irrefutable `if let` guard pattern
LL | Some(x) if let () = x => {}
| ^^
|
+ = note: this pattern will always match, so the guard is useless
+ = help: consider removing the guard and adding a `let` inside the match arm
note: the lint level is defined here
--> $DIR/warns.rs:3:8
|
LL | #[deny(irrefutable_let_patterns)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
- = note: this pattern will always match, so the guard is useless
- = help: consider removing the guard and adding a `let` inside the match arm
error: unreachable pattern
--> $DIR/warns.rs:15:25
diff --git a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr
index bc06fde49..91c001151 100644
--- a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr
+++ b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr
@@ -1510,7 +1510,7 @@ LL | if x = let 0 = 0 {}
help: you might have meant to compare for equality
|
LL | if x == let 0 = 0 {}
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:157:8
@@ -1704,7 +1704,7 @@ LL | while x = let 0 = 0 {}
help: you might have meant to compare for equality
|
LL | while x == let 0 = 0 {}
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:249:11
diff --git a/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.disallowed.stderr b/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.disallowed.stderr
index d1d5288ae..be4a52315 100644
--- a/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.disallowed.stderr
+++ b/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.disallowed.stderr
@@ -4,13 +4,13 @@ error: leading irrefutable pattern in let chain
LL | if let first = &opt && let Some(ref second) = first && let None = second.start {}
| ^^^^^^^^^^^^^^^^
|
+ = note: this pattern will always match
+ = help: consider moving it outside of the construct
note: the lint level is defined here
--> $DIR/irrefutable-lets.rs:6:30
|
LL | #![cfg_attr(disallowed, deny(irrefutable_let_patterns))]
| ^^^^^^^^^^^^^^^^^^^^^^^^
- = note: this pattern will always match
- = help: consider moving it outside of the construct
error: irrefutable `if let` patterns
--> $DIR/irrefutable-lets.rs:19:8
@@ -75,26 +75,26 @@ LL | if let first = &opt && let None = Some(1) {}
= note: this pattern will always match
= help: consider moving it outside of the construct
-error: irrefutable `let` patterns
+error: irrefutable `if let` guard patterns
--> $DIR/irrefutable-lets.rs:44:28
|
LL | Some(ref first) if let second = first && let _third = second && let v = 4 + 4 => {},
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: these patterns will always match, so the `let` is useless
- = help: consider removing `let`
+ = note: these patterns will always match, so the guard is useless
+ = help: consider removing the guard and adding a `let` inside the match arm
-error: leading irrefutable pattern in let chain
- --> $DIR/irrefutable-lets.rs:50:28
+error: trailing irrefutable patterns in let chain
+ --> $DIR/irrefutable-lets.rs:59:16
|
-LL | Some(ref first) if let Range { start: local_start, end: _ } = first
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | && let v = local_end && let w = v => {},
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: this pattern will always match
- = help: consider moving it outside of the construct
+ = note: these patterns will always match
+ = help: consider moving them into the body
error: irrefutable `while let` patterns
- --> $DIR/irrefutable-lets.rs:59:11
+ --> $DIR/irrefutable-lets.rs:68:11
|
LL | while let first = &opt && let (a, b) = (1, 2) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -103,7 +103,7 @@ LL | while let first = &opt && let (a, b) = (1, 2) {}
= help: consider instead using a `loop { ... }` with a `let` inside it
error: trailing irrefutable patterns in let chain
- --> $DIR/irrefutable-lets.rs:62:40
+ --> $DIR/irrefutable-lets.rs:71:40
|
LL | while let Some(ref first) = opt && let second = first && let _third = second {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs b/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs
index 3d1626e8f..9afb6853b 100644
--- a/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs
+++ b/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs
@@ -42,18 +42,27 @@ fn main() {
match opt {
Some(ref first) if let second = first && let _third = second && let v = 4 + 4 => {},
- //[disallowed]~^ ERROR irrefutable `let` patterns
+ //[disallowed]~^ ERROR irrefutable `if let` guard patterns
_ => {}
}
+ // No error about leading irrefutable patterns: the expr on the rhs might
+ // use the bindings created by the match.
match opt {
Some(ref first) if let Range { start: local_start, end: _ } = first
- //[disallowed]~^ ERROR leading irrefutable pattern in let chain
&& let None = local_start => {},
_ => {}
}
- // No error, despite the prefix being irrefutable
+ match opt {
+ Some(ref first) if let Range { start: Some(_), end: local_end } = first
+ && let v = local_end && let w = v => {},
+ //[disallowed]~^ ERROR trailing irrefutable patterns in let chain
+ _ => {}
+ }
+
+ // No error, despite the prefix being irrefutable: moving out could change the behaviour,
+ // due to possible side effects of the operation.
while let first = &opt && let Some(ref second) = first && let None = second.start {}
while let first = &opt && let (a, b) = (1, 2) {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.rs b/src/test/ui/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.rs
new file mode 100644
index 000000000..780a510c5
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.rs
@@ -0,0 +1,14 @@
+// check-pass
+#![feature(const_trait_impl)]
+
+#[const_trait]
+trait Foo {
+ type Assoc: ~const Foo;
+ fn foo() {}
+}
+
+const fn foo<T: ~const Foo>() {
+ <T as Foo>::Assoc::foo();
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs
index 99eacaa83..7d9dae52c 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs
@@ -10,6 +10,7 @@ impl std::ops::Add for NonConstAdd {
}
}
+#[const_trait]
trait Foo {
type Bar: ~const std::ops::Add;
}
@@ -19,6 +20,7 @@ impl const Foo for NonConstAdd {
//~^ ERROR: cannot add `NonConstAdd` to `NonConstAdd` in const contexts
}
+#[const_trait]
trait Baz {
type Qux: std::ops::Add;
}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr
index 64501c523..89177b0f1 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr
@@ -1,24 +1,20 @@
error[E0277]: cannot add `NonConstAdd` to `NonConstAdd` in const contexts
- --> $DIR/assoc-type.rs:18:16
+ --> $DIR/assoc-type.rs:19:16
|
LL | type Bar = NonConstAdd;
| ^^^^^^^^^^^ no implementation for `NonConstAdd + NonConstAdd`
|
= help: the trait `~const Add` is not implemented for `NonConstAdd`
note: the trait `Add` is implemented for `NonConstAdd`, but that implementation is not `const`
- --> $DIR/assoc-type.rs:18:16
+ --> $DIR/assoc-type.rs:19:16
|
LL | type Bar = NonConstAdd;
| ^^^^^^^^^^^
note: required by a bound in `Foo::Bar`
- --> $DIR/assoc-type.rs:14:15
+ --> $DIR/assoc-type.rs:15:15
|
LL | type Bar: ~const std::ops::Add;
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `Foo::Bar`
-help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
- |
-LL | impl const Foo for NonConstAdd where NonConstAdd: ~const Add {
- | +++++++++++++++++++++++++++++
error: aborting due to previous error
diff --git a/src/test/ui/rfc-2632-const-trait-impl/auxiliary/staged-api.rs b/src/test/ui/rfc-2632-const-trait-impl/auxiliary/staged-api.rs
index 19e900609..589e3f024 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/auxiliary/staged-api.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/auxiliary/staged-api.rs
@@ -3,6 +3,7 @@
#![stable(feature = "rust1", since = "1.0.0")]
#[stable(feature = "rust1", since = "1.0.0")]
+#[const_trait]
pub trait MyTrait {
#[stable(feature = "rust1", since = "1.0.0")]
fn func();
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs
index 24b9235bb..dd9933974 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs
@@ -1,5 +1,6 @@
#![feature(const_trait_impl)]
+#[const_trait]
pub trait Plus {
fn plus(self, rhs: Self) -> Self;
}
@@ -23,7 +24,6 @@ pub const fn add_i32(a: i32, b: i32) -> i32 {
pub const fn add_u32(a: u32, b: u32) -> u32 {
a.plus(b)
//~^ ERROR the trait bound
- //~| ERROR cannot call non-const fn
}
fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr
index 1fc9db277..7350909ba 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr
@@ -1,24 +1,15 @@
error[E0277]: the trait bound `u32: ~const Plus` is not satisfied
- --> $DIR/call-const-trait-method-fail.rs:24:7
+ --> $DIR/call-const-trait-method-fail.rs:25:7
|
LL | a.plus(b)
- | ^^^^^^^ the trait `~const Plus` is not implemented for `u32`
+ | ^^^^ the trait `~const Plus` is not implemented for `u32`
|
note: the trait `Plus` is implemented for `u32`, but that implementation is not `const`
- --> $DIR/call-const-trait-method-fail.rs:24:7
+ --> $DIR/call-const-trait-method-fail.rs:25:7
|
LL | a.plus(b)
- | ^^^^^^^
+ | ^^^^
-error[E0015]: cannot call non-const fn `<u32 as Plus>::plus` in constant functions
- --> $DIR/call-const-trait-method-fail.rs:24:7
- |
-LL | a.plus(b)
- | ^^^^^^^
- |
- = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
-Some errors have detailed explanations: E0015, E0277.
-For more information about an error, try `rustc --explain E0015`.
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs
index cf38bc3c9..b64161b6a 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs
@@ -21,6 +21,7 @@ impl const PartialEq for Int {
}
}
+#[const_trait]
pub trait Plus {
fn plus(self, rhs: Self) -> Self;
}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs
index 89dc47aad..50c465790 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs
@@ -1,6 +1,7 @@
// check-pass
#![feature(const_trait_impl)]
+#[const_trait]
trait MyPartialEq {
fn eq(&self, other: &Self) -> bool;
}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.stderr
index 83d395dda..31e6dbdab 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.stderr
@@ -9,7 +9,6 @@ note: the trait `PartialEq<_>` is implemented for `T`, but that implementation i
|
LL | *t == *t
| ^^
- = help: the trait `PartialEq<&B>` is implemented for `&A`
error: aborting due to previous error
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs
index d3e14a53a..414a8c87d 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs
@@ -2,13 +2,18 @@
struct S;
-impl PartialEq for S {
+#[const_trait]
+trait Foo {
+ fn eq(&self, _: &Self) -> bool;
+}
+
+impl Foo for S {
fn eq(&self, _: &S) -> bool {
true
}
}
-const fn equals_self<T: ~const PartialEq>(t: &T) -> bool {
+const fn equals_self<T: ~const Foo>(t: &T) -> bool {
true
}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr
index 0a2a5f0f2..706f52343 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr
@@ -1,26 +1,21 @@
-error[E0277]: can't compare `S` with `S` in const contexts
- --> $DIR/call-generic-method-nonconst.rs:18:34
+error[E0277]: the trait bound `S: ~const Foo` is not satisfied
+ --> $DIR/call-generic-method-nonconst.rs:23:34
|
LL | pub const EQ: bool = equals_self(&S);
- | ----------- ^^ no implementation for `S == S`
+ | ----------- ^^ the trait `~const Foo` is not implemented for `S`
| |
| required by a bound introduced by this call
|
- = help: the trait `~const PartialEq` is not implemented for `S`
-note: the trait `PartialEq` is implemented for `S`, but that implementation is not `const`
- --> $DIR/call-generic-method-nonconst.rs:18:34
+note: the trait `Foo` is implemented for `S`, but that implementation is not `const`
+ --> $DIR/call-generic-method-nonconst.rs:23:34
|
LL | pub const EQ: bool = equals_self(&S);
| ^^
note: required by a bound in `equals_self`
- --> $DIR/call-generic-method-nonconst.rs:11:25
- |
-LL | const fn equals_self<T: ~const PartialEq>(t: &T) -> bool {
- | ^^^^^^^^^^^^^^^^ required by this bound in `equals_self`
-help: consider annotating `S` with `#[derive(PartialEq)]`
- |
-LL | #[derive(PartialEq)]
+ --> $DIR/call-generic-method-nonconst.rs:16:25
|
+LL | const fn equals_self<T: ~const Foo>(t: &T) -> bool {
+ | ^^^^^^^^^^ required by this bound in `equals_self`
error: aborting due to previous error
diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.rs b/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.rs
index b3e3dd62b..52984fb6b 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.rs
@@ -1,6 +1,7 @@
#![feature(const_trait_impl)]
struct S;
+#[const_trait]
trait T {
fn foo();
}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.stderr
index 9e49785c5..c8783de4c 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.stderr
@@ -1,5 +1,5 @@
error[E0015]: cannot call non-const fn `non_const` in constant functions
- --> $DIR/const-check-fns-in-const-impl.rs:11:16
+ --> $DIR/const-check-fns-in-const-impl.rs:12:16
|
LL | fn foo() { non_const() }
| ^^^^^^^^^^^
diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr
index fddc8d37f..c64930db9 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr
@@ -11,10 +11,6 @@ note: the trait `ConstDefaultFn` is implemented for `NonConstImpl`, but that imp
|
LL | NonConstImpl.a();
| ^^^^^^^^^^^^
-help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
- |
-LL | const fn test() where NonConstImpl: ~const ConstDefaultFn {
- | +++++++++++++++++++++++++++++++++++++++++
error: aborting due to previous error
diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr
index 2295a822f..796c0d388 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr
@@ -1,5 +1,5 @@
error[E0277]: can't drop `NonTrivialDrop` in const contexts
- --> $DIR/const-drop-fail.rs:43:5
+ --> $DIR/const-drop-fail.rs:44:5
|
LL | const _: () = check($exp);
| ----- required by a bound introduced by this call
@@ -9,7 +9,7 @@ LL | NonTrivialDrop,
|
= note: the trait bound `NonTrivialDrop: ~const Destruct` is not satisfied
note: required by a bound in `check`
- --> $DIR/const-drop-fail.rs:34:19
+ --> $DIR/const-drop-fail.rs:35:19
|
LL | const fn check<T: ~const Destruct>(_: T) {}
| ^^^^^^^^^^^^^^^ required by this bound in `check`
@@ -21,7 +21,7 @@ LL | &mut NonTrivialDrop,
| ++++
error[E0277]: can't drop `NonTrivialDrop` in const contexts
- --> $DIR/const-drop-fail.rs:45:5
+ --> $DIR/const-drop-fail.rs:46:5
|
LL | const _: () = check($exp);
| ----- required by a bound introduced by this call
@@ -30,7 +30,7 @@ LL | ConstImplWithDropGlue(NonTrivialDrop),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `ConstImplWithDropGlue`, the trait `~const Destruct` is not implemented for `NonTrivialDrop`
|
note: the trait `Destruct` is implemented for `NonTrivialDrop`, but that implementation is not `const`
- --> $DIR/const-drop-fail.rs:45:5
+ --> $DIR/const-drop-fail.rs:46:5
|
LL | ConstImplWithDropGlue(NonTrivialDrop),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,39 +40,60 @@ note: required because it appears within the type `ConstImplWithDropGlue`
LL | struct ConstImplWithDropGlue(NonTrivialDrop);
| ^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `check`
- --> $DIR/const-drop-fail.rs:34:19
+ --> $DIR/const-drop-fail.rs:35:19
|
LL | const fn check<T: ~const Destruct>(_: T) {}
| ^^^^^^^^^^^^^^^ required by this bound in `check`
-error[E0277]: the trait bound `ConstDropImplWithBounds<NonTrivialDrop>: ~const Destruct` is not satisfied
- --> $DIR/const-drop-fail.rs:47:5
+error[E0277]: the trait bound `NonTrivialDrop: ~const A` is not satisfied
+ --> $DIR/const-drop-fail.rs:48:47
|
-LL | const _: () = check($exp);
- | ----- required by a bound introduced by this call
-...
LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `~const Destruct` is not implemented for `ConstDropImplWithBounds<NonTrivialDrop>`
+ | ----------------------------------------- ^^^^^^^^^^^ the trait `~const A` is not implemented for `NonTrivialDrop`
+ | |
+ | required by a bound introduced by this call
|
-note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct`
- --> $DIR/const-drop-fail.rs:28:25
+note: the trait `A` is implemented for `NonTrivialDrop`, but that implementation is not `const`
+ --> $DIR/const-drop-fail.rs:48:47
|
-LL | impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> {
- | ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: 1 redundant requirement hidden
- = note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct`
-note: required by a bound in `check`
- --> $DIR/const-drop-fail.rs:34:19
+LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
+ | ^^^^^^^^^^^
+note: required by a bound in `ConstDropImplWithBounds`
+ --> $DIR/const-drop-fail.rs:27:35
|
-LL | const fn check<T: ~const Destruct>(_: T) {}
- | ^^^^^^^^^^^^^^^ required by this bound in `check`
-help: consider borrowing here
+LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
+ | ^^^^^^^^ required by this bound in `ConstDropImplWithBounds`
+
+error[E0277]: the trait bound `NonTrivialDrop: ~const A` is not satisfied
+ --> $DIR/const-drop-fail.rs:48:5
|
-LL | &ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
- | +
-LL | &mut ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
- | ++++
+LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `~const A` is not implemented for `NonTrivialDrop`
+ |
+note: the trait `A` is implemented for `NonTrivialDrop`, but that implementation is not `const`
+ --> $DIR/const-drop-fail.rs:48:5
+ |
+LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+note: required by a bound in `ConstDropImplWithBounds`
+ --> $DIR/const-drop-fail.rs:27:35
+ |
+LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
+ | ^^^^^^^^ required by this bound in `ConstDropImplWithBounds`
+
+error[E0367]: `Drop` impl requires `T: ~const A` but the struct it is implemented for does not
+ --> $DIR/const-drop-fail.rs:55:9
+ |
+LL | impl<T: ~const A> const Drop for ConstDropImplWithNonConstBounds<T> {
+ | ^^^^^^^^
+ |
+note: the implementor must specify the same requirement
+ --> $DIR/const-drop-fail.rs:53:1
+ |
+LL | struct ConstDropImplWithNonConstBounds<T: A>(PhantomData<T>);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 3 previous errors
+error: aborting due to 5 previous errors
-For more information about this error, try `rustc --explain E0277`.
+Some errors have detailed explanations: E0277, E0367.
+For more information about an error, try `rustc --explain E0277`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs
index 001dd430a..d36c7f81c 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs
@@ -19,11 +19,12 @@ impl const Drop for ConstImplWithDropGlue {
fn drop(&mut self) {}
}
-trait A { fn a() { println!("A"); } }
+#[const_trait]
+trait A { fn a() { } }
impl A for NonTrivialDrop {}
-struct ConstDropImplWithBounds<T: A>(PhantomData<T>);
+struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> {
fn drop(&mut self) {
@@ -46,6 +47,16 @@ check_all! {
//~^ ERROR can't drop
ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
//~^ ERROR the trait bound
+ //~| ERROR the trait bound
+}
+
+struct ConstDropImplWithNonConstBounds<T: A>(PhantomData<T>);
+
+impl<T: ~const A> const Drop for ConstDropImplWithNonConstBounds<T> {
+//~^ ERROR `Drop` impl requires `T: ~const A` but the struct it is implemented for does not
+ fn drop(&mut self) {
+ T::a();
+ }
}
fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr
index 2295a822f..796c0d388 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr
@@ -1,5 +1,5 @@
error[E0277]: can't drop `NonTrivialDrop` in const contexts
- --> $DIR/const-drop-fail.rs:43:5
+ --> $DIR/const-drop-fail.rs:44:5
|
LL | const _: () = check($exp);
| ----- required by a bound introduced by this call
@@ -9,7 +9,7 @@ LL | NonTrivialDrop,
|
= note: the trait bound `NonTrivialDrop: ~const Destruct` is not satisfied
note: required by a bound in `check`
- --> $DIR/const-drop-fail.rs:34:19
+ --> $DIR/const-drop-fail.rs:35:19
|
LL | const fn check<T: ~const Destruct>(_: T) {}
| ^^^^^^^^^^^^^^^ required by this bound in `check`
@@ -21,7 +21,7 @@ LL | &mut NonTrivialDrop,
| ++++
error[E0277]: can't drop `NonTrivialDrop` in const contexts
- --> $DIR/const-drop-fail.rs:45:5
+ --> $DIR/const-drop-fail.rs:46:5
|
LL | const _: () = check($exp);
| ----- required by a bound introduced by this call
@@ -30,7 +30,7 @@ LL | ConstImplWithDropGlue(NonTrivialDrop),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `ConstImplWithDropGlue`, the trait `~const Destruct` is not implemented for `NonTrivialDrop`
|
note: the trait `Destruct` is implemented for `NonTrivialDrop`, but that implementation is not `const`
- --> $DIR/const-drop-fail.rs:45:5
+ --> $DIR/const-drop-fail.rs:46:5
|
LL | ConstImplWithDropGlue(NonTrivialDrop),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -40,39 +40,60 @@ note: required because it appears within the type `ConstImplWithDropGlue`
LL | struct ConstImplWithDropGlue(NonTrivialDrop);
| ^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `check`
- --> $DIR/const-drop-fail.rs:34:19
+ --> $DIR/const-drop-fail.rs:35:19
|
LL | const fn check<T: ~const Destruct>(_: T) {}
| ^^^^^^^^^^^^^^^ required by this bound in `check`
-error[E0277]: the trait bound `ConstDropImplWithBounds<NonTrivialDrop>: ~const Destruct` is not satisfied
- --> $DIR/const-drop-fail.rs:47:5
+error[E0277]: the trait bound `NonTrivialDrop: ~const A` is not satisfied
+ --> $DIR/const-drop-fail.rs:48:47
|
-LL | const _: () = check($exp);
- | ----- required by a bound introduced by this call
-...
LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `~const Destruct` is not implemented for `ConstDropImplWithBounds<NonTrivialDrop>`
+ | ----------------------------------------- ^^^^^^^^^^^ the trait `~const A` is not implemented for `NonTrivialDrop`
+ | |
+ | required by a bound introduced by this call
|
-note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct`
- --> $DIR/const-drop-fail.rs:28:25
+note: the trait `A` is implemented for `NonTrivialDrop`, but that implementation is not `const`
+ --> $DIR/const-drop-fail.rs:48:47
|
-LL | impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> {
- | ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: 1 redundant requirement hidden
- = note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct`
-note: required by a bound in `check`
- --> $DIR/const-drop-fail.rs:34:19
+LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
+ | ^^^^^^^^^^^
+note: required by a bound in `ConstDropImplWithBounds`
+ --> $DIR/const-drop-fail.rs:27:35
|
-LL | const fn check<T: ~const Destruct>(_: T) {}
- | ^^^^^^^^^^^^^^^ required by this bound in `check`
-help: consider borrowing here
+LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
+ | ^^^^^^^^ required by this bound in `ConstDropImplWithBounds`
+
+error[E0277]: the trait bound `NonTrivialDrop: ~const A` is not satisfied
+ --> $DIR/const-drop-fail.rs:48:5
|
-LL | &ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
- | +
-LL | &mut ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
- | ++++
+LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `~const A` is not implemented for `NonTrivialDrop`
+ |
+note: the trait `A` is implemented for `NonTrivialDrop`, but that implementation is not `const`
+ --> $DIR/const-drop-fail.rs:48:5
+ |
+LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+note: required by a bound in `ConstDropImplWithBounds`
+ --> $DIR/const-drop-fail.rs:27:35
+ |
+LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
+ | ^^^^^^^^ required by this bound in `ConstDropImplWithBounds`
+
+error[E0367]: `Drop` impl requires `T: ~const A` but the struct it is implemented for does not
+ --> $DIR/const-drop-fail.rs:55:9
+ |
+LL | impl<T: ~const A> const Drop for ConstDropImplWithNonConstBounds<T> {
+ | ^^^^^^^^
+ |
+note: the implementor must specify the same requirement
+ --> $DIR/const-drop-fail.rs:53:1
+ |
+LL | struct ConstDropImplWithNonConstBounds<T: A>(PhantomData<T>);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 3 previous errors
+error: aborting due to 5 previous errors
-For more information about this error, try `rustc --explain E0277`.
+Some errors have detailed explanations: E0277, E0367.
+For more information about an error, try `rustc --explain E0277`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-drop.rs b/src/test/ui/rfc-2632-const-trait-impl/const-drop.rs
index 04462c0a1..b0fc3adf9 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/const-drop.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/const-drop.rs
@@ -48,6 +48,7 @@ mod t {
pub struct HasConstDrop(pub ConstDrop);
pub struct TrivialFields(pub u8, pub i8, pub usize, pub isize);
+ #[const_trait]
pub trait SomeTrait {
fn foo();
}
@@ -59,7 +60,7 @@ mod t {
fn foo() {}
}
- pub struct ConstDropWithBound<T: SomeTrait>(pub core::marker::PhantomData<T>);
+ pub struct ConstDropWithBound<T: ~const SomeTrait>(pub core::marker::PhantomData<T>);
impl<T: ~const SomeTrait> const Drop for ConstDropWithBound<T> {
fn drop(&mut self) {
diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.rs b/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.rs
index 470c653dd..837124db0 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.rs
@@ -1,9 +1,11 @@
#![feature(const_trait_impl)]
+#[const_trait]
trait Foo {}
const impl Foo for i32 {} //~ ERROR: expected identifier, found keyword
+#[const_trait]
trait Bar {}
const impl<T: Foo> Bar for T {} //~ ERROR: expected identifier, found keyword
diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.stderr
index 709084c86..7217fc855 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.stderr
@@ -1,5 +1,5 @@
error: expected identifier, found keyword `impl`
- --> $DIR/const-impl-recovery.rs:5:7
+ --> $DIR/const-impl-recovery.rs:6:7
|
LL | const impl Foo for i32 {}
| ^^^^ expected identifier, found keyword
@@ -11,7 +11,7 @@ LL + impl const Foo for i32 {}
|
error: expected identifier, found keyword `impl`
- --> $DIR/const-impl-recovery.rs:9:7
+ --> $DIR/const-impl-recovery.rs:11:7
|
LL | const impl<T: Foo> Bar for T {}
| ^^^^ expected identifier, found keyword
diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.rs b/src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.rs
new file mode 100644
index 000000000..2b4963991
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.rs
@@ -0,0 +1,9 @@
+#![feature(const_trait_impl)]
+
+pub trait A {}
+//~^ HELP: mark `A` as const
+
+impl const A for () {}
+//~^ ERROR: const `impl` for trait `A` which is not marked with `#[const_trait]`
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.stderr
new file mode 100644
index 000000000..478adcf3e
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.stderr
@@ -0,0 +1,14 @@
+error: const `impl` for trait `A` which is not marked with `#[const_trait]`
+ --> $DIR/const-impl-requires-const-trait.rs:6:12
+ |
+LL | pub trait A {}
+ | - help: mark `A` as const: `#[const_trait]`
+...
+LL | impl const A for () {}
+ | ^
+ |
+ = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
+ = note: adding a non-const method body in the future would be a breaking change
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr b/src/test/ui/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr
index d4fa44b4b..925ae53e3 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr
@@ -11,10 +11,6 @@ note: the trait `cross_crate::MyTrait` is implemented for `cross_crate::NonConst
|
LL | NonConst.func();
| ^^^^^^^^
-help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
- |
-LL | const fn const_context() where cross_crate::NonConst: ~const cross_crate::MyTrait {
- | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
error: aborting due to previous error
diff --git a/src/test/ui/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr b/src/test/ui/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr
index 71ecd9b06..11db0c2b8 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr
@@ -11,10 +11,6 @@ note: the trait `cross_crate::MyTrait` is implemented for `cross_crate::NonConst
|
LL | NonConst.func();
| ^^^^^^^^
-help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
- |
-LL | const fn const_context() where cross_crate::NonConst: ~const cross_crate::MyTrait {
- | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
error: aborting due to previous error
diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.rs b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.rs
index d27291231..96acdc300 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.rs
@@ -1,5 +1,6 @@
#![feature(const_trait_impl)]
+#[const_trait]
trait Tr {}
impl Tr for () {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.stderr b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.stderr
index 7542b81fe..a244ab10c 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.stderr
@@ -1,23 +1,19 @@
error[E0277]: the trait bound `(): ~const Tr` is not satisfied
- --> $DIR/default-method-body-is-const-body-checking.rs:11:15
+ --> $DIR/default-method-body-is-const-body-checking.rs:12:15
|
LL | foo::<()>();
| ^^ the trait `~const Tr` is not implemented for `()`
|
note: the trait `Tr` is implemented for `()`, but that implementation is not `const`
- --> $DIR/default-method-body-is-const-body-checking.rs:11:15
+ --> $DIR/default-method-body-is-const-body-checking.rs:12:15
|
LL | foo::<()>();
| ^^
note: required by a bound in `foo`
- --> $DIR/default-method-body-is-const-body-checking.rs:6:28
+ --> $DIR/default-method-body-is-const-body-checking.rs:7:28
|
LL | const fn foo<T>() where T: ~const Tr {}
| ^^^^^^^^^ required by this bound in `foo`
-help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
- |
-LL | pub trait Foo where (): ~const Tr {
- | +++++++++++++++++++
error: aborting due to previous error
diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr
index 85285ba84..c2c16921c 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr
@@ -11,10 +11,6 @@ note: the trait `Tr` is implemented for `()`, but that implementation is not `co
|
LL | ().a()
| ^^
-help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
- |
-LL | pub trait Tr where (): ~const Tr {
- | +++++++++++++++++++
error: aborting due to previous error
diff --git a/src/test/ui/rfc-2632-const-trait-impl/feature-gate.gated.stderr b/src/test/ui/rfc-2632-const-trait-impl/feature-gate.gated.stderr
index af4d3909e..4c630d33c 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/feature-gate.gated.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/feature-gate.gated.stderr
@@ -1,5 +1,5 @@
error: fatal error triggered by #[rustc_error]
- --> $DIR/feature-gate.rs:13:1
+ --> $DIR/feature-gate.rs:14:1
|
LL | fn main() {}
| ^^^^^^^^^
diff --git a/src/test/ui/rfc-2632-const-trait-impl/feature-gate.rs b/src/test/ui/rfc-2632-const-trait-impl/feature-gate.rs
index 7bac72e1b..0b409fbaa 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/feature-gate.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/feature-gate.rs
@@ -5,6 +5,7 @@
#![feature(rustc_attrs)]
struct S;
+#[const_trait] //[stock]~ ERROR `const_trait` is a temporary placeholder
trait T {}
impl const T for S {}
//[stock]~^ ERROR const trait impls are experimental
diff --git a/src/test/ui/rfc-2632-const-trait-impl/feature-gate.stock.stderr b/src/test/ui/rfc-2632-const-trait-impl/feature-gate.stock.stderr
index 91a8bb578..0e938c1c5 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/feature-gate.stock.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/feature-gate.stock.stderr
@@ -1,5 +1,5 @@
error[E0658]: const trait impls are experimental
- --> $DIR/feature-gate.rs:9:6
+ --> $DIR/feature-gate.rs:10:6
|
LL | impl const T for S {}
| ^^^^^
@@ -7,6 +7,15 @@ LL | impl const T for S {}
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
-error: aborting due to previous error
+error[E0658]: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future.
+ --> $DIR/feature-gate.rs:8:1
+ |
+LL | #[const_trait]
+ | ^^^^^^^^^^^^^^
+ |
+ = note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
+ = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
+
+error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs
index 80a4442de..337c73340 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs
@@ -2,6 +2,7 @@
#![feature(const_trait_impl)]
+#[const_trait]
pub trait MyTrait {
fn method(&self) -> Option<()>;
}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr
index 32df63e44..6d2be1daa 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr
@@ -1,5 +1,5 @@
error[E0658]: `?` is not allowed in a `const fn`
- --> $DIR/hir-const-check.rs:11:9
+ --> $DIR/hir-const-check.rs:12:9
|
LL | Some(())?;
| ^^^^^^^^^
diff --git a/src/test/ui/rfc-2632-const-trait-impl/inherent-impl-const-bounds.rs b/src/test/ui/rfc-2632-const-trait-impl/inherent-impl-const-bounds.rs
index 2cef803a9..f8ac793e4 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/inherent-impl-const-bounds.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/inherent-impl-const-bounds.rs
@@ -3,7 +3,9 @@
struct S;
+#[const_trait]
trait A {}
+#[const_trait]
trait B {}
impl const A for S {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-100222.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-100222.rs
index 1004bb28c..9f3f38ad4 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/issue-100222.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/issue-100222.rs
@@ -16,6 +16,7 @@ pub trait IndexMut where Self: Index {
impl Index for () { type Output = (); }
+#[cfg(not(any(nn, yn)))]
impl const IndexMut for <() as Index>::Output {
const C: <Self as Index>::Output = ();
type Assoc = <Self as Index>::Output;
@@ -24,6 +25,15 @@ impl const IndexMut for <() as Index>::Output {
{}
}
+#[cfg(any(nn, yn))]
+impl IndexMut for <() as Index>::Output {
+ const C: <Self as Index>::Output = ();
+ type Assoc = <Self as Index>::Output;
+ fn foo(&mut self, x: <Self as Index>::Output) -> <Self as Index>::Output
+ where <Self as Index>::Output:,
+ {}
+}
+
const C: <() as Index>::Output = ();
fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs
new file mode 100644
index 000000000..fe4e91081
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs
@@ -0,0 +1,15 @@
+#![feature(allocator_api)]
+#![feature(const_trait_impl)]
+
+use core::convert::{From, TryFrom};
+//~^ ERROR
+//~| ERROR
+
+use std::pin::Pin;
+use std::alloc::Allocator;
+impl<T: ?Sized, A: Allocator> const From<Box<T, A>> for Pin<Box<T, A>>
+where
+ A: 'static,
+{}
+
+pub fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr
new file mode 100644
index 000000000..8bf00eaff
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr
@@ -0,0 +1,19 @@
+error[E0433]: failed to resolve: maybe a missing crate `core`?
+ --> $DIR/issue-102156.rs:4:5
+ |
+LL | use core::convert::{From, TryFrom};
+ | ^^^^ maybe a missing crate `core`?
+ |
+ = help: consider adding `extern crate core` to use the `core` crate
+
+error[E0433]: failed to resolve: maybe a missing crate `core`?
+ --> $DIR/issue-102156.rs:4:5
+ |
+LL | use core::convert::{From, TryFrom};
+ | ^^^^ maybe a missing crate `core`?
+ |
+ = help: consider adding `extern crate core` to use the `core` crate
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0433`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-102985.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-102985.rs
new file mode 100644
index 000000000..07d3f51ed
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/issue-102985.rs
@@ -0,0 +1,12 @@
+#![feature(const_trait_impl)]
+
+struct Bug {
+ inner: [(); match || 1 {
+ n => n(),
+ //~^ ERROR the trait bound
+ //~| ERROR the trait bound
+ //~| ERROR cannot call non-const closure in constants
+ }],
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-102985.stderr b/src/test/ui/rfc-2632-const-trait-impl/issue-102985.stderr
new file mode 100644
index 000000000..b98ccbe5d
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/issue-102985.stderr
@@ -0,0 +1,41 @@
+error[E0277]: the trait bound `[closure@$DIR/issue-102985.rs:4:23: 4:25]: ~const Fn<()>` is not satisfied
+ --> $DIR/issue-102985.rs:5:14
+ |
+LL | n => n(),
+ | ^^^ expected an `Fn<()>` closure, found `[closure@$DIR/issue-102985.rs:4:23: 4:25]`
+ |
+ = help: the trait `~const Fn<()>` is not implemented for closure `[closure@$DIR/issue-102985.rs:4:23: 4:25]`
+note: the trait `Fn<()>` is implemented for `[closure@$DIR/issue-102985.rs:4:23: 4:25]`, but that implementation is not `const`
+ --> $DIR/issue-102985.rs:5:14
+ |
+LL | n => n(),
+ | ^^^
+ = note: wrap the `[closure@$DIR/issue-102985.rs:4:23: 4:25]` in a closure with no arguments: `|| { /* code */ }`
+
+error[E0277]: the trait bound `[closure@$DIR/issue-102985.rs:4:23: 4:25]: ~const Fn<()>` is not satisfied
+ --> $DIR/issue-102985.rs:5:14
+ |
+LL | n => n(),
+ | ^^^ expected an `Fn<()>` closure, found `[closure@$DIR/issue-102985.rs:4:23: 4:25]`
+ |
+ = help: the trait `~const Fn<()>` is not implemented for closure `[closure@$DIR/issue-102985.rs:4:23: 4:25]`
+note: the trait `Fn<()>` is implemented for `[closure@$DIR/issue-102985.rs:4:23: 4:25]`, but that implementation is not `const`
+ --> $DIR/issue-102985.rs:5:14
+ |
+LL | n => n(),
+ | ^^^
+ = note: wrap the `[closure@$DIR/issue-102985.rs:4:23: 4:25]` in a closure with no arguments: `|| { /* code */ }`
+
+error[E0015]: cannot call non-const closure in constants
+ --> $DIR/issue-102985.rs:5:14
+ |
+LL | n => n(),
+ | ^^^
+ |
+ = note: closures need an RFC before allowed to be called in constants
+ = note: calls in constants are limited to constant functions, tuple structs and tuple variants
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0015, E0277.
+For more information about an error, try `rustc --explain E0015`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-103677.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-103677.rs
new file mode 100644
index 000000000..d81724a36
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/issue-103677.rs
@@ -0,0 +1,5 @@
+// check-pass
+
+const _: fn(&String) = |s| { &*s as &str; };
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-90052.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-90052.rs
new file mode 100644
index 000000000..21ddf4ab4
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/issue-90052.rs
@@ -0,0 +1,9 @@
+#![feature(const_trait_impl)]
+
+#[const_trait]
+trait Bar {}
+
+fn foo<T>() where T: ~const Bar {}
+//~^ ERROR `~const` is not allowed
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-90052.stderr b/src/test/ui/rfc-2632-const-trait-impl/issue-90052.stderr
new file mode 100644
index 000000000..b2a936537
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/issue-90052.stderr
@@ -0,0 +1,14 @@
+error: `~const` is not allowed here
+ --> $DIR/issue-90052.rs:6:22
+ |
+LL | fn foo<T>() where T: ~const Bar {}
+ | ^^^^^^^^^^
+ |
+note: this function is not `const`, so it cannot have `~const` trait bounds
+ --> $DIR/issue-90052.rs:6:4
+ |
+LL | fn foo<T>() where T: ~const Bar {}
+ | ^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-92230-wf-super-trait-env.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-92230-wf-super-trait-env.rs
index 97c27ce1a..4d3469653 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/issue-92230-wf-super-trait-env.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/issue-92230-wf-super-trait-env.rs
@@ -4,7 +4,9 @@
#![feature(const_trait_impl)]
+#[const_trait]
pub trait Super {}
+#[const_trait]
pub trait Sub: Super {}
impl<A> const Super for &A where A: ~const Super {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/nested-closure.rs b/src/test/ui/rfc-2632-const-trait-impl/nested-closure.rs
new file mode 100644
index 000000000..a85113600
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/nested-closure.rs
@@ -0,0 +1,12 @@
+// check-pass
+
+#![feature(const_trait_impl, once_cell)]
+
+use std::sync::LazyLock;
+
+static EXTERN_FLAGS: LazyLock<String> = LazyLock::new(|| {
+ let x = || String::new();
+ x()
+});
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/non-const-op-in-closure-in-const.rs b/src/test/ui/rfc-2632-const-trait-impl/non-const-op-in-closure-in-const.rs
index defef9e04..1a4509b18 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/non-const-op-in-closure-in-const.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/non-const-op-in-closure-in-const.rs
@@ -2,6 +2,7 @@
#![feature(const_trait_impl)]
+#[const_trait]
trait Convert<T> {
fn to(self) -> T;
}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.rs b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.rs
new file mode 100644
index 000000000..633543700
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.rs
@@ -0,0 +1,31 @@
+#![feature(const_trait_impl, min_specialization, rustc_attrs)]
+
+#[rustc_specialization_trait]
+#[const_trait]
+pub trait Sup {}
+
+impl const Sup for () {}
+
+#[const_trait]
+pub trait A {
+ fn a() -> u32;
+}
+
+impl<T: Default> A for T {
+ default fn a() -> u32 {
+ 2
+ }
+}
+
+impl<T: Default + ~const Sup> const A for T {
+ fn a() -> u32 {
+ 3
+ }
+}
+
+const fn generic<T: Default>() {
+ <T as A>::a();
+ //~^ ERROR: the trait bound `T: ~const Sup` is not satisfied
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.stderr b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.stderr
new file mode 100644
index 000000000..c554671e1
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.stderr
@@ -0,0 +1,19 @@
+error[E0277]: the trait bound `T: ~const Sup` is not satisfied
+ --> $DIR/specializing-constness-2.rs:27:5
+ |
+LL | <T as A>::a();
+ | ^^^^^^^^^^^^^ the trait `~const Sup` is not implemented for `T`
+ |
+note: required for `T` to implement `~const A`
+ --> $DIR/specializing-constness-2.rs:20:37
+ |
+LL | impl<T: Default + ~const Sup> const A for T {
+ | ^ ^
+help: consider further restricting this bound
+ |
+LL | const fn generic<T: Default + ~const Sup>() {
+ | ++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/specializing-constness.rs b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness.rs
new file mode 100644
index 000000000..ff0cd489d
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness.rs
@@ -0,0 +1,26 @@
+#![feature(const_trait_impl, min_specialization, rustc_attrs)]
+
+#[rustc_specialization_trait]
+#[const_trait]
+pub trait Sup {}
+
+impl const Sup for () {}
+
+#[const_trait]
+pub trait A {
+ fn a() -> u32;
+}
+
+impl<T: ~const Default> const A for T {
+ default fn a() -> u32 {
+ 2
+ }
+}
+
+impl<T: Default + Sup> A for T { //~ ERROR: cannot specialize
+ fn a() -> u32 {
+ 3
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/specializing-constness.stderr b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness.stderr
new file mode 100644
index 000000000..3296c109c
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness.stderr
@@ -0,0 +1,8 @@
+error: cannot specialize on trait `Default`
+ --> $DIR/specializing-constness.rs:20:9
+ |
+LL | impl<T: Default + Sup> A for T {
+ | ^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/rfc-2632-const-trait-impl/static-const-trait-bound.rs b/src/test/ui/rfc-2632-const-trait-impl/static-const-trait-bound.rs
new file mode 100644
index 000000000..4520a3696
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/static-const-trait-bound.rs
@@ -0,0 +1,18 @@
+// check-pass
+pub struct S<T, F: FnOnce() -> T = fn() -> T> {
+ f: F,
+ x: Option<T>,
+}
+
+impl<T, F: FnOnce() -> T> S<T, F> {
+ pub const fn new(f: F) -> Self {
+ Self { f, x: None }
+ }
+}
+
+#[derive(Default)]
+pub struct Foo;
+
+static LOCKED_CALLSITES: S<Foo> = S::new(Default::default);
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.nn.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.nn.stderr
new file mode 100644
index 000000000..d4f42b787
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.nn.stderr
@@ -0,0 +1,8 @@
+error: ~const can only be applied to `#[const_trait]` traits
+ --> $DIR/super-traits-fail-2.rs:11:19
+ |
+LL | trait Bar: ~const Foo {}
+ | ^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.ny.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.ny.stderr
new file mode 100644
index 000000000..d4f42b787
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.ny.stderr
@@ -0,0 +1,8 @@
+error: ~const can only be applied to `#[const_trait]` traits
+ --> $DIR/super-traits-fail-2.rs:11:19
+ |
+LL | trait Bar: ~const Foo {}
+ | ^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs
index 7b38c15af..d183efde2 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs
@@ -1,14 +1,19 @@
#![feature(const_trait_impl)]
+// revisions: yy yn ny nn
+
+#[cfg_attr(any(yy, yn), const_trait)]
trait Foo {
fn a(&self);
}
+
+#[cfg_attr(any(yy, ny), const_trait)]
trait Bar: ~const Foo {}
+//[ny,nn]~^ ERROR: ~const can only be applied to `#[const_trait]`
const fn foo<T: Bar>(x: &T) {
x.a();
- //~^ ERROR the trait bound
- //~| ERROR cannot call
+ //[yn,yy]~^ ERROR the trait bound
}
fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr
deleted file mode 100644
index 1766cdbee..000000000
--- a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr
+++ /dev/null
@@ -1,24 +0,0 @@
-error[E0277]: the trait bound `T: ~const Foo` is not satisfied
- --> $DIR/super-traits-fail-2.rs:9:7
- |
-LL | x.a();
- | ^^^ the trait `~const Foo` is not implemented for `T`
- |
-note: the trait `Foo` is implemented for `T`, but that implementation is not `const`
- --> $DIR/super-traits-fail-2.rs:9:7
- |
-LL | x.a();
- | ^^^
-
-error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
- --> $DIR/super-traits-fail-2.rs:9:7
- |
-LL | x.a();
- | ^^^
- |
- = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
-
-error: aborting due to 2 previous errors
-
-Some errors have detailed explanations: E0015, E0277.
-For more information about an error, try `rustc --explain E0015`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yn.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yn.stderr
new file mode 100644
index 000000000..b52eb2c03
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yn.stderr
@@ -0,0 +1,21 @@
+error[E0277]: the trait bound `T: ~const Foo` is not satisfied
+ --> $DIR/super-traits-fail-2.rs:15:5
+ |
+LL | x.a();
+ | ^ - required by a bound introduced by this call
+ | |
+ | the trait `~const Foo` is not implemented for `T`
+ |
+note: the trait `Foo` is implemented for `T`, but that implementation is not `const`
+ --> $DIR/super-traits-fail-2.rs:15:5
+ |
+LL | x.a();
+ | ^
+help: consider further restricting this bound
+ |
+LL | const fn foo<T: Bar + ~const Foo>(x: &T) {
+ | ++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yy.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yy.stderr
new file mode 100644
index 000000000..b52eb2c03
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yy.stderr
@@ -0,0 +1,21 @@
+error[E0277]: the trait bound `T: ~const Foo` is not satisfied
+ --> $DIR/super-traits-fail-2.rs:15:5
+ |
+LL | x.a();
+ | ^ - required by a bound introduced by this call
+ | |
+ | the trait `~const Foo` is not implemented for `T`
+ |
+note: the trait `Foo` is implemented for `T`, but that implementation is not `const`
+ --> $DIR/super-traits-fail-2.rs:15:5
+ |
+LL | x.a();
+ | ^
+help: consider further restricting this bound
+ |
+LL | const fn foo<T: Bar + ~const Foo>(x: &T) {
+ | ++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.nn.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.nn.stderr
new file mode 100644
index 000000000..d433e1cfa
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.nn.stderr
@@ -0,0 +1,14 @@
+error: ~const can only be applied to `#[const_trait]` traits
+ --> $DIR/super-traits-fail-3.rs:12:19
+ |
+LL | trait Bar: ~const Foo {}
+ | ^^^
+
+error: ~const can only be applied to `#[const_trait]` traits
+ --> $DIR/super-traits-fail-3.rs:15:24
+ |
+LL | const fn foo<T: ~const Bar>(x: &T) {
+ | ^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.ny.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.ny.stderr
new file mode 100644
index 000000000..2a7e8e00b
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.ny.stderr
@@ -0,0 +1,8 @@
+error: ~const can only be applied to `#[const_trait]` traits
+ --> $DIR/super-traits-fail-3.rs:12:19
+ |
+LL | trait Bar: ~const Foo {}
+ | ^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.rs
new file mode 100644
index 000000000..70d2936d3
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.rs
@@ -0,0 +1,20 @@
+#![feature(const_trait_impl)]
+
+// revisions: yy yn ny nn
+//[yy] check-pass
+
+#[cfg_attr(any(yy, yn), const_trait)]
+trait Foo {
+ fn a(&self);
+}
+
+#[cfg_attr(any(yy, ny), const_trait)]
+trait Bar: ~const Foo {}
+//[ny,nn]~^ ERROR: ~const can only be applied to `#[const_trait]`
+
+const fn foo<T: ~const Bar>(x: &T) {
+ //[yn,nn]~^ ERROR: ~const can only be applied to `#[const_trait]`
+ x.a();
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.yn.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.yn.stderr
new file mode 100644
index 000000000..e5978c12a
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.yn.stderr
@@ -0,0 +1,8 @@
+error: ~const can only be applied to `#[const_trait]` traits
+ --> $DIR/super-traits-fail-3.rs:15:24
+ |
+LL | const fn foo<T: ~const Bar>(x: &T) {
+ | ^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs
index af465cad3..3e2b81368 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs
@@ -1,8 +1,10 @@
#![feature(const_trait_impl)]
+#[const_trait]
trait Foo {
fn a(&self);
}
+#[const_trait]
trait Bar: ~const Foo {}
struct S;
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr
index 9e8b8f8c6..1f8f312df 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr
@@ -1,23 +1,19 @@
error[E0277]: the trait bound `S: ~const Foo` is not satisfied
- --> $DIR/super-traits-fail.rs:13:12
+ --> $DIR/super-traits-fail.rs:15:12
|
LL | impl const Bar for S {}
| ^^^ the trait `~const Foo` is not implemented for `S`
|
note: the trait `Foo` is implemented for `S`, but that implementation is not `const`
- --> $DIR/super-traits-fail.rs:13:12
+ --> $DIR/super-traits-fail.rs:15:12
|
LL | impl const Bar for S {}
| ^^^
note: required by a bound in `Bar`
- --> $DIR/super-traits-fail.rs:6:12
+ --> $DIR/super-traits-fail.rs:8:12
|
LL | trait Bar: ~const Foo {}
| ^^^^^^^^^^ required by this bound in `Bar`
-help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
- |
-LL | impl const Bar for S where S: ~const Foo {}
- | +++++++++++++++++++
error: aborting due to previous error
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs
index aded4ca9a..df96f6fb4 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs
@@ -1,9 +1,12 @@
// check-pass
#![feature(const_trait_impl)]
+#[const_trait]
trait Foo {
fn a(&self);
}
+
+#[const_trait]
trait Bar: ~const Foo {}
struct S;
diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs
new file mode 100644
index 000000000..78a64b901
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs
@@ -0,0 +1,34 @@
+#![feature(const_trait_impl)]
+#![feature(generic_arg_infer)]
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+struct Foo<const N: usize>;
+
+impl<const N: usize> Foo<N> {
+ fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
+ Foo
+ }
+}
+
+#[const_trait]
+trait Add42 {
+ fn add(a: usize) -> usize;
+}
+
+impl const Add42 for () {
+ fn add(a: usize) -> usize {
+ a + 42
+ }
+}
+
+fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
+ //~^ ERROR `~const` is not allowed here
+ Foo
+}
+
+fn main() {
+ let foo = Foo::<0>;
+ let foo = bar::<(), _>(foo);
+ let _foo = bar::<(), _>(foo);
+}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.stderr b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.stderr
new file mode 100644
index 000000000..aae72f36e
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.stderr
@@ -0,0 +1,14 @@
+error: `~const` is not allowed here
+ --> $DIR/tilde-const-and-const-params.rs:25:11
+ |
+LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
+ | ^^^^^^^^^^^^
+ |
+note: this function is not `const`, so it cannot have `~const` trait bounds
+ --> $DIR/tilde-const-and-const-params.rs:25:4
+ |
+LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
+ | ^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs
index b4302f3e7..5bd52151f 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs
@@ -1,6 +1,7 @@
#![feature(const_trait_impl)]
#![feature(associated_type_bounds)]
+#[const_trait]
trait T {}
struct S;
impl T for S {}
@@ -17,12 +18,6 @@ fn rpit_assoc_bound() -> impl IntoIterator<Item: ~const T> { Some(S) }
fn apit_assoc_bound(_: impl IntoIterator<Item: ~const T>) {}
//~^ ERROR `~const` is not allowed
-fn generic<P: ~const T>() {}
-//~^ ERROR `~const` is not allowed
-
-fn where_clause<P>() where P: ~const T {}
-//~^ ERROR `~const` is not allowed
-
struct TildeQuestion<T: ~const ?Sized>(std::marker::PhantomData<T>);
//~^ ERROR `~const` and `?` are mutually exclusive
diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr
index 033ec21ba..84867cb4a 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr
@@ -1,56 +1,40 @@
error: `~const` is not allowed here
- --> $DIR/tilde-const-invalid-places.rs:8:19
+ --> $DIR/tilde-const-invalid-places.rs:9:19
|
LL | fn rpit() -> impl ~const T { S }
| ^^^^^^^^
|
- = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions
+ = note: `impl Trait`s cannot have `~const` trait bounds
error: `~const` is not allowed here
- --> $DIR/tilde-const-invalid-places.rs:11:17
+ --> $DIR/tilde-const-invalid-places.rs:12:17
|
LL | fn apit(_: impl ~const T) {}
| ^^^^^^^^
|
- = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions
+ = note: `impl Trait`s cannot have `~const` trait bounds
error: `~const` is not allowed here
- --> $DIR/tilde-const-invalid-places.rs:14:50
+ --> $DIR/tilde-const-invalid-places.rs:15:50
|
LL | fn rpit_assoc_bound() -> impl IntoIterator<Item: ~const T> { Some(S) }
| ^^^^^^^^
|
- = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions
+ = note: `impl Trait`s cannot have `~const` trait bounds
error: `~const` is not allowed here
- --> $DIR/tilde-const-invalid-places.rs:17:48
+ --> $DIR/tilde-const-invalid-places.rs:18:48
|
LL | fn apit_assoc_bound(_: impl IntoIterator<Item: ~const T>) {}
| ^^^^^^^^
|
- = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions
-
-error: `~const` is not allowed here
- --> $DIR/tilde-const-invalid-places.rs:20:15
- |
-LL | fn generic<P: ~const T>() {}
- | ^^^^^^^^
- |
- = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions
-
-error: `~const` is not allowed here
- --> $DIR/tilde-const-invalid-places.rs:23:31
- |
-LL | fn where_clause<P>() where P: ~const T {}
- | ^^^^^^^^
- |
- = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions
+ = note: `impl Trait`s cannot have `~const` trait bounds
error: `~const` and `?` are mutually exclusive
- --> $DIR/tilde-const-invalid-places.rs:26:25
+ --> $DIR/tilde-const-invalid-places.rs:21:25
|
LL | struct TildeQuestion<T: ~const ?Sized>(std::marker::PhantomData<T>);
| ^^^^^^^^^^^^^
-error: aborting due to 7 previous errors
+error: aborting due to 5 previous errors
diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.rs
new file mode 100644
index 000000000..285cef571
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.rs
@@ -0,0 +1,17 @@
+// check-pass
+#![feature(const_trait_impl)]
+
+#[const_trait]
+trait Foo {
+ fn foo(&self) {}
+}
+
+struct Bar<T>(T);
+
+impl<T: ~const Foo> Bar<T> {
+ const fn foo(&self) {
+ self.0.foo()
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.rs
new file mode 100644
index 000000000..bfe98b98c
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.rs
@@ -0,0 +1,31 @@
+// Like trait-where-clause.rs, but we are calling from a const context.
+// Checking the validity of traits' where clauses happen at a later stage.
+// (`rustc_const_eval` instead of `rustc_hir_analysis`) Therefore one file as a
+// test is not enough.
+#![feature(const_trait_impl)]
+
+#[const_trait]
+trait Bar {}
+
+#[const_trait]
+trait Foo {
+ fn a();
+ fn b() where Self: ~const Bar;
+ fn c<T: ~const Bar>();
+}
+
+const fn test1<T: ~const Foo + Bar>() {
+ T::a();
+ T::b();
+ //~^ ERROR the trait bound
+ T::c::<T>();
+ //~^ ERROR the trait bound
+}
+
+const fn test2<T: ~const Foo + ~const Bar>() {
+ T::a();
+ T::b();
+ T::c::<T>();
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.stderr b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.stderr
new file mode 100644
index 000000000..f2846b6a6
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.stderr
@@ -0,0 +1,35 @@
+error[E0277]: the trait bound `T: ~const Bar` is not satisfied
+ --> $DIR/trait-where-clause-const.rs:19:5
+ |
+LL | T::b();
+ | ^^^^^^ the trait `~const Bar` is not implemented for `T`
+ |
+note: the trait `Bar` is implemented for `T`, but that implementation is not `const`
+ --> $DIR/trait-where-clause-const.rs:19:5
+ |
+LL | T::b();
+ | ^^^^^^
+help: consider further restricting this bound
+ |
+LL | const fn test1<T: ~const Foo + Bar + ~const Bar>() {
+ | ++++++++++++
+
+error[E0277]: the trait bound `T: ~const Bar` is not satisfied
+ --> $DIR/trait-where-clause-const.rs:21:5
+ |
+LL | T::c::<T>();
+ | ^^^^^^^^^^^ the trait `~const Bar` is not implemented for `T`
+ |
+note: the trait `Bar` is implemented for `T`, but that implementation is not `const`
+ --> $DIR/trait-where-clause-const.rs:21:5
+ |
+LL | T::c::<T>();
+ | ^^^^^^^^^^^
+help: consider further restricting this bound
+ |
+LL | const fn test1<T: ~const Foo + Bar + ~const Bar>() {
+ | ++++++++++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs
index b7cf9a13b..4b8b00406 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs
@@ -2,6 +2,7 @@
#![feature(const_trait_impl)]
+#[const_trait]
trait Bar {
fn bar() -> u8;
}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs
index acea58eae..3b028ac48 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs
@@ -2,6 +2,7 @@
#![feature(const_trait_impl)]
+#[const_trait]
trait Foo {
fn bar() where Self: ~const Foo;
}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs
index d37ed3bb8..85ca5fc90 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs
@@ -1,5 +1,6 @@
#![feature(const_trait_impl)]
+#[const_trait]
trait Bar {}
trait Foo {
@@ -8,7 +9,7 @@ trait Foo {
fn c<T: ~const Bar>();
}
-const fn test1<T: ~const Foo + Bar>() {
+fn test1<T: Foo>() {
T::a();
T::b();
//~^ ERROR the trait bound
@@ -16,21 +17,7 @@ const fn test1<T: ~const Foo + Bar>() {
//~^ ERROR the trait bound
}
-const fn test2<T: ~const Foo + ~const Bar>() {
- T::a();
- T::b();
- T::c::<T>();
-}
-
-fn test3<T: Foo>() {
- T::a();
- T::b();
- //~^ ERROR the trait bound
- T::c::<T>();
- //~^ ERROR the trait bound
-}
-
-fn test4<T: Foo + Bar>() {
+fn test2<T: Foo + Bar>() {
T::a();
T::b();
T::c::<T>();
diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr
index fd5fe25dd..11f0c4016 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr
@@ -1,77 +1,35 @@
-error[E0277]: the trait bound `T: ~const Bar` is not satisfied
- --> $DIR/trait-where-clause.rs:13:5
- |
-LL | T::b();
- | ^^^^ the trait `~const Bar` is not implemented for `T`
- |
-note: the trait `Bar` is implemented for `T`, but that implementation is not `const`
- --> $DIR/trait-where-clause.rs:13:5
- |
-LL | T::b();
- | ^^^^
-note: required by a bound in `Foo::b`
- --> $DIR/trait-where-clause.rs:7:24
- |
-LL | fn b() where Self: ~const Bar;
- | ^^^^^^^^^^ required by this bound in `Foo::b`
-help: consider further restricting this bound
- |
-LL | const fn test1<T: ~const Foo + Bar + ~const Bar>() {
- | ++++++++++++
-
-error[E0277]: the trait bound `T: ~const Bar` is not satisfied
- --> $DIR/trait-where-clause.rs:15:12
- |
-LL | T::c::<T>();
- | ^ the trait `~const Bar` is not implemented for `T`
- |
-note: the trait `Bar` is implemented for `T`, but that implementation is not `const`
- --> $DIR/trait-where-clause.rs:15:12
- |
-LL | T::c::<T>();
- | ^
-note: required by a bound in `Foo::c`
- --> $DIR/trait-where-clause.rs:8:13
- |
-LL | fn c<T: ~const Bar>();
- | ^^^^^^^^^^ required by this bound in `Foo::c`
-help: consider further restricting this bound
- |
-LL | const fn test1<T: ~const Foo + Bar + ~const Bar>() {
- | ++++++++++++
-
error[E0277]: the trait bound `T: Bar` is not satisfied
- --> $DIR/trait-where-clause.rs:27:5
+ --> $DIR/trait-where-clause.rs:14:5
|
LL | T::b();
| ^^^^ the trait `Bar` is not implemented for `T`
|
note: required by a bound in `Foo::b`
- --> $DIR/trait-where-clause.rs:7:24
+ --> $DIR/trait-where-clause.rs:8:24
|
LL | fn b() where Self: ~const Bar;
| ^^^^^^^^^^ required by this bound in `Foo::b`
help: consider further restricting this bound
|
-LL | fn test3<T: Foo + Bar>() {
+LL | fn test1<T: Foo + Bar>() {
| +++++
error[E0277]: the trait bound `T: Bar` is not satisfied
- --> $DIR/trait-where-clause.rs:29:12
+ --> $DIR/trait-where-clause.rs:16:12
|
LL | T::c::<T>();
| ^ the trait `Bar` is not implemented for `T`
|
note: required by a bound in `Foo::c`
- --> $DIR/trait-where-clause.rs:8:13
+ --> $DIR/trait-where-clause.rs:9:13
|
LL | fn c<T: ~const Bar>();
| ^^^^^^^^^^ required by this bound in `Foo::c`
help: consider further restricting this bound
|
-LL | fn test3<T: Foo + Bar>() {
+LL | fn test1<T: Foo + Bar>() {
| +++++
-error: aborting due to 4 previous errors
+error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/rfc1623-2.stderr b/src/test/ui/rfc1623-2.stderr
index 495d45e22..945c6533c 100644
--- a/src/test/ui/rfc1623-2.stderr
+++ b/src/test/ui/rfc1623-2.stderr
@@ -23,7 +23,7 @@ help: consider making the type lifetime-generic with a new `'a` lifetime
LL | &(non_elidable as for<'a> fn(&'a u8, &'a u8) -> &'a u8);
| +++++++ ++ ++ ++
-error[E0605]: non-primitive cast: `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8 {non_elidable}` as `for<'r, 's> fn(&'r u8, &'s u8) -> &u8`
+error[E0605]: non-primitive cast: `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8 {non_elidable}` as `for<'a, 'b> fn(&'a u8, &'b u8) -> &u8`
--> $DIR/rfc1623-2.rs:10:6
|
LL | &(non_elidable as fn(&u8, &u8) -> &u8);
diff --git a/src/test/ui/rfcs/rfc1857-drop-order.rs b/src/test/ui/rfcs/rfc1857-drop-order.rs
index 243b7fb6f..4c4816c2f 100644
--- a/src/test/ui/rfcs/rfc1857-drop-order.rs
+++ b/src/test/ui/rfcs/rfc1857-drop-order.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
#![allow(dead_code, unreachable_code)]
diff --git a/src/test/ui/runtime/backtrace-debuginfo.rs b/src/test/ui/runtime/backtrace-debuginfo.rs
index 7c9f1a7f2..8b5466b6c 100644
--- a/src/test/ui/runtime/backtrace-debuginfo.rs
+++ b/src/test/ui/runtime/backtrace-debuginfo.rs
@@ -12,6 +12,7 @@
// ignore-pretty issue #37195
// ignore-emscripten spawning processes is not supported
// ignore-sgx no processes
+// ignore-fuchsia Backtrace not symbolized, trace different line alignment
use std::env;
diff --git a/src/test/ui/runtime/out-of-stack.rs b/src/test/ui/runtime/out-of-stack.rs
index 73c31cd97..6873abc49 100644
--- a/src/test/ui/runtime/out-of-stack.rs
+++ b/src/test/ui/runtime/out-of-stack.rs
@@ -5,6 +5,7 @@
// ignore-android: FIXME (#20004)
// ignore-emscripten no processes
// ignore-sgx no processes
+// ignore-fuchsia must translate zircon signal to SIGABRT, FIXME (#58590)
#![feature(core_intrinsics)]
#![feature(rustc_private)]
diff --git a/src/test/ui/runtime/rt-explody-panic-payloads.rs b/src/test/ui/runtime/rt-explody-panic-payloads.rs
index eb5bf8f67..755d3df42 100644
--- a/src/test/ui/runtime/rt-explody-panic-payloads.rs
+++ b/src/test/ui/runtime/rt-explody-panic-payloads.rs
@@ -2,9 +2,6 @@
// needs-unwind
// ignore-emscripten no processes
// ignore-sgx no processes
-// ignore-wasm32-bare no unwinding panic
-// ignore-avr no unwinding panic
-// ignore-nvptx64 no unwinding panic
use std::env;
use std::process::Command;
@@ -25,7 +22,12 @@ fn main() {
}.expect("running the command should have succeeded");
println!("{:#?}", output);
let stderr = std::str::from_utf8(&output.stderr);
- assert!(stderr.map(|v| {
- v.ends_with("fatal runtime error: drop of the panic payload panicked\n")
- }).unwrap_or(false));
+ assert!(stderr
+ .map(|v| {
+ // When running inside QEMU user-mode emulation, there will be an extra message printed
+ // by QEMU in the stderr whenever a core dump happens. Remove it before the check.
+ v.strip_suffix("qemu: uncaught target signal 6 (Aborted) - core dumped\n").unwrap_or(v)
+ })
+ .map(|v| { v.ends_with("fatal runtime error: drop of the panic payload panicked\n") })
+ .unwrap_or(false));
}
diff --git a/src/test/ui/rust-2018/async-ident-allowed.stderr b/src/test/ui/rust-2018/async-ident-allowed.stderr
index 5b63eab8e..992b29750 100644
--- a/src/test/ui/rust-2018/async-ident-allowed.stderr
+++ b/src/test/ui/rust-2018/async-ident-allowed.stderr
@@ -4,14 +4,14 @@ error: `async` is a keyword in the 2018 edition
LL | let async = 3;
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
note: the lint level is defined here
--> $DIR/async-ident-allowed.rs:3:9
|
LL | #![deny(rust_2018_compatibility)]
| ^^^^^^^^^^^^^^^^^^^^^^^
= note: `#[deny(keyword_idents)]` implied by `#[deny(rust_2018_compatibility)]`
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: aborting due to previous error
diff --git a/src/test/ui/rust-2018/async-ident.stderr b/src/test/ui/rust-2018/async-ident.stderr
index 6396e9dee..d15250c54 100644
--- a/src/test/ui/rust-2018/async-ident.stderr
+++ b/src/test/ui/rust-2018/async-ident.stderr
@@ -4,13 +4,13 @@ error: `async` is a keyword in the 2018 edition
LL | fn async() {}
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
note: the lint level is defined here
--> $DIR/async-ident.rs:2:9
|
LL | #![deny(keyword_idents)]
| ^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: `async` is a keyword in the 2018 edition
--> $DIR/async-ident.rs:12:7
diff --git a/src/test/ui/rust-2018/dyn-keyword.stderr b/src/test/ui/rust-2018/dyn-keyword.stderr
index 699242f2d..b6f5b10cf 100644
--- a/src/test/ui/rust-2018/dyn-keyword.stderr
+++ b/src/test/ui/rust-2018/dyn-keyword.stderr
@@ -4,13 +4,13 @@ error: `dyn` is a keyword in the 2018 edition
LL | let dyn = ();
| ^^^ help: you can use a raw identifier to stay compatible: `r#dyn`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
note: the lint level is defined here
--> $DIR/dyn-keyword.rs:5:9
|
LL | #![deny(keyword_idents)]
| ^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
error: aborting due to previous error
diff --git a/src/test/ui/rust-2018/edition-lint-fully-qualified-paths.stderr b/src/test/ui/rust-2018/edition-lint-fully-qualified-paths.stderr
index 6f529fa91..e1709db09 100644
--- a/src/test/ui/rust-2018/edition-lint-fully-qualified-paths.stderr
+++ b/src/test/ui/rust-2018/edition-lint-fully-qualified-paths.stderr
@@ -4,13 +4,13 @@ error: absolute paths must start with `self`, `super`, `crate`, or an external c
LL | let _: <foo::Baz as ::foo::Foo>::Bar = ();
| ^^^^^^^^^^ help: use `crate`: `crate::foo::Foo`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
note: the lint level is defined here
--> $DIR/edition-lint-fully-qualified-paths.rs:4:9
|
LL | #![deny(absolute_paths_not_starting_with_crate)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
--> $DIR/edition-lint-fully-qualified-paths.rs:23:13
diff --git a/src/test/ui/rust-2018/edition-lint-nested-empty-paths.stderr b/src/test/ui/rust-2018/edition-lint-nested-empty-paths.stderr
index e47c320f7..8769cbb35 100644
--- a/src/test/ui/rust-2018/edition-lint-nested-empty-paths.stderr
+++ b/src/test/ui/rust-2018/edition-lint-nested-empty-paths.stderr
@@ -4,13 +4,13 @@ error: absolute paths must start with `self`, `super`, `crate`, or an external c
LL | use foo::{bar::{baz::{}}};
| ^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{bar::{baz::{}}}`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
note: the lint level is defined here
--> $DIR/edition-lint-nested-empty-paths.rs:4:9
|
LL | #![deny(absolute_paths_not_starting_with_crate)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
--> $DIR/edition-lint-nested-empty-paths.rs:21:5
diff --git a/src/test/ui/rust-2018/edition-lint-nested-paths.stderr b/src/test/ui/rust-2018/edition-lint-nested-paths.stderr
index 24b17f212..354a6fe32 100644
--- a/src/test/ui/rust-2018/edition-lint-nested-paths.stderr
+++ b/src/test/ui/rust-2018/edition-lint-nested-paths.stderr
@@ -4,13 +4,13 @@ error: absolute paths must start with `self`, `super`, `crate`, or an external c
LL | use foo::{a, b};
| ^^^^^^^^^^^ help: use `crate`: `crate::foo::{a, b}`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
note: the lint level is defined here
--> $DIR/edition-lint-nested-paths.rs:4:9
|
LL | #![deny(absolute_paths_not_starting_with_crate)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
--> $DIR/edition-lint-nested-paths.rs:6:5
diff --git a/src/test/ui/rust-2018/edition-lint-paths.stderr b/src/test/ui/rust-2018/edition-lint-paths.stderr
index 1ded8cd36..42652be94 100644
--- a/src/test/ui/rust-2018/edition-lint-paths.stderr
+++ b/src/test/ui/rust-2018/edition-lint-paths.stderr
@@ -4,13 +4,13 @@ error: absolute paths must start with `self`, `super`, `crate`, or an external c
LL | use bar::Bar;
| ^^^^^^^^ help: use `crate`: `crate::bar::Bar`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
note: the lint level is defined here
--> $DIR/edition-lint-paths.rs:5:9
|
LL | #![deny(absolute_paths_not_starting_with_crate)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
--> $DIR/edition-lint-paths.rs:19:9
diff --git a/src/test/ui/rust-2018/extern-crate-rename.stderr b/src/test/ui/rust-2018/extern-crate-rename.stderr
index 4bccbc512..eb040f5de 100644
--- a/src/test/ui/rust-2018/extern-crate-rename.stderr
+++ b/src/test/ui/rust-2018/extern-crate-rename.stderr
@@ -4,13 +4,13 @@ error: absolute paths must start with `self`, `super`, `crate`, or an external c
LL | use my_crate::foo;
| ^^^^^^^^^^^^^ help: use `crate`: `crate::my_crate::foo`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
note: the lint level is defined here
--> $DIR/extern-crate-rename.rs:8:9
|
LL | #![deny(absolute_paths_not_starting_with_crate)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
error: aborting due to previous error
diff --git a/src/test/ui/rust-2018/extern-crate-submod.stderr b/src/test/ui/rust-2018/extern-crate-submod.stderr
index 3c75319ae..1a9aa7578 100644
--- a/src/test/ui/rust-2018/extern-crate-submod.stderr
+++ b/src/test/ui/rust-2018/extern-crate-submod.stderr
@@ -4,13 +4,13 @@ error: absolute paths must start with `self`, `super`, `crate`, or an external c
LL | use m::edition_lint_paths::foo;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::m::edition_lint_paths::foo`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
note: the lint level is defined here
--> $DIR/extern-crate-submod.rs:9:9
|
LL | #![deny(absolute_paths_not_starting_with_crate)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
error: aborting due to previous error
diff --git a/src/test/ui/rust-2018/try-ident.stderr b/src/test/ui/rust-2018/try-ident.stderr
index 3d93b433c..74015ac9d 100644
--- a/src/test/ui/rust-2018/try-ident.stderr
+++ b/src/test/ui/rust-2018/try-ident.stderr
@@ -4,14 +4,14 @@ warning: `try` is a keyword in the 2018 edition
LL | try();
| ^^^ help: you can use a raw identifier to stay compatible: `r#try`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
note: the lint level is defined here
--> $DIR/try-ident.rs:4:9
|
LL | #![warn(rust_2018_compatibility)]
| ^^^^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(keyword_idents)]` implied by `#[warn(rust_2018_compatibility)]`
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
warning: `try` is a keyword in the 2018 edition
--> $DIR/try-ident.rs:12:4
diff --git a/src/test/ui/rust-2018/try-macro.stderr b/src/test/ui/rust-2018/try-macro.stderr
index f315b4d4a..760378f09 100644
--- a/src/test/ui/rust-2018/try-macro.stderr
+++ b/src/test/ui/rust-2018/try-macro.stderr
@@ -4,14 +4,14 @@ warning: `try` is a keyword in the 2018 edition
LL | try!(x);
| ^^^ help: you can use a raw identifier to stay compatible: `r#try`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
+ = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
note: the lint level is defined here
--> $DIR/try-macro.rs:6:9
|
LL | #![warn(rust_2018_compatibility)]
| ^^^^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(keyword_idents)]` implied by `#[warn(rust_2018_compatibility)]`
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
- = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
warning: 1 warning emitted
diff --git a/src/test/ui/rust-2021/array-into-iter-ambiguous.stderr b/src/test/ui/rust-2021/array-into-iter-ambiguous.stderr
index fac8d21c7..2a724bd30 100644
--- a/src/test/ui/rust-2021/array-into-iter-ambiguous.stderr
+++ b/src/test/ui/rust-2021/array-into-iter-ambiguous.stderr
@@ -4,13 +4,13 @@ warning: trait method `into_iter` will become ambiguous in Rust 2021
LL | let y = points.into_iter();
| ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `MyIntoIter::into_iter(points)`
|
+ = warning: this changes meaning in Rust 2021
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
note: the lint level is defined here
--> $DIR/array-into-iter-ambiguous.rs:5:9
|
LL | #![warn(array_into_iter)]
| ^^^^^^^^^^^^^^^
- = warning: this changes meaning in Rust 2021
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
warning: 1 warning emitted
diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic-trait.stderr b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.stderr
index 14ad9b017..f38da132b 100644
--- a/src/test/ui/rust-2021/future-prelude-collision-generic-trait.stderr
+++ b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.stderr
@@ -4,13 +4,13 @@ warning: trait-associated function `try_from` will become ambiguous in Rust 2021
LL | U::try_from(self)
| ^^^^^^^^^^^ help: disambiguate the associated function: `<U as PyTryFrom<'_, _>>::try_from`
|
+ = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
note: the lint level is defined here
--> $DIR/future-prelude-collision-generic-trait.rs:5:9
|
LL | #![warn(rust_2021_prelude_collisions)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
warning: 1 warning emitted
diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic.stderr b/src/test/ui/rust-2021/future-prelude-collision-generic.stderr
index e1d3f3c0a..9893b3eba 100644
--- a/src/test/ui/rust-2021/future-prelude-collision-generic.stderr
+++ b/src/test/ui/rust-2021/future-prelude-collision-generic.stderr
@@ -4,13 +4,13 @@ warning: trait-associated function `from_iter` will become ambiguous in Rust 202
LL | Generic::from_iter(1);
| ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic<'_, _> as MyFromIter>::from_iter`
|
+ = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
note: the lint level is defined here
--> $DIR/future-prelude-collision-generic.rs:5:9
|
LL | #![warn(rust_2021_prelude_collisions)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
warning: trait-associated function `from_iter` will become ambiguous in Rust 2021
--> $DIR/future-prelude-collision-generic.rs:31:5
diff --git a/src/test/ui/rust-2021/future-prelude-collision-imported.stderr b/src/test/ui/rust-2021/future-prelude-collision-imported.stderr
index 56abb8abd..c1d72d0df 100644
--- a/src/test/ui/rust-2021/future-prelude-collision-imported.stderr
+++ b/src/test/ui/rust-2021/future-prelude-collision-imported.stderr
@@ -4,13 +4,13 @@ warning: trait method `try_into` will become ambiguous in Rust 2021
LL | let _: u32 = 3u8.try_into().unwrap();
| ^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(3u8)`
|
+ = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
note: the lint level is defined here
--> $DIR/future-prelude-collision-imported.rs:4:9
|
LL | #![warn(rust_2021_prelude_collisions)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
warning: trait method `try_into` will become ambiguous in Rust 2021
--> $DIR/future-prelude-collision-imported.rs:40:22
diff --git a/src/test/ui/rust-2021/future-prelude-collision-macros.stderr b/src/test/ui/rust-2021/future-prelude-collision-macros.stderr
index 4c3543ca7..4d4a07699 100644
--- a/src/test/ui/rust-2021/future-prelude-collision-macros.stderr
+++ b/src/test/ui/rust-2021/future-prelude-collision-macros.stderr
@@ -4,13 +4,13 @@ warning: trait method `try_into` will become ambiguous in Rust 2021
LL | foo!().try_into(todo!());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `MyTry::try_into(foo!(), todo!())`
|
+ = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
note: the lint level is defined here
--> $DIR/future-prelude-collision-macros.rs:4:9
|
LL | #![warn(rust_2021_prelude_collisions)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
warning: trait-associated function `try_from` will become ambiguous in Rust 2021
--> $DIR/future-prelude-collision-macros.rs:42:5
diff --git a/src/test/ui/rust-2021/future-prelude-collision-turbofish.stderr b/src/test/ui/rust-2021/future-prelude-collision-turbofish.stderr
index 2de9020bc..c0ef80fd8 100644
--- a/src/test/ui/rust-2021/future-prelude-collision-turbofish.stderr
+++ b/src/test/ui/rust-2021/future-prelude-collision-turbofish.stderr
@@ -4,13 +4,13 @@ warning: trait method `try_into` will become ambiguous in Rust 2021
LL | x.try_into::<usize>().or(Err("foo"))?.checked_sub(1);
| ^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `AnnotatableTryInto::try_into::<usize>(x)`
|
+ = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
note: the lint level is defined here
--> $DIR/future-prelude-collision-turbofish.rs:6:9
|
LL | #![warn(rust_2021_prelude_collisions)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
warning: trait method `try_into` will become ambiguous in Rust 2021
--> $DIR/future-prelude-collision-turbofish.rs:23:5
diff --git a/src/test/ui/rust-2021/future-prelude-collision.stderr b/src/test/ui/rust-2021/future-prelude-collision.stderr
index 889e66de0..cae113ff7 100644
--- a/src/test/ui/rust-2021/future-prelude-collision.stderr
+++ b/src/test/ui/rust-2021/future-prelude-collision.stderr
@@ -4,13 +4,13 @@ warning: trait method `try_into` will become ambiguous in Rust 2021
LL | let _: u32 = 3u8.try_into().unwrap();
| ^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(3u8)`
|
+ = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
note: the lint level is defined here
--> $DIR/future-prelude-collision.rs:4:9
|
LL | #![warn(rust_2021_prelude_collisions)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
warning: trait-associated function `try_from` will become ambiguous in Rust 2021
--> $DIR/future-prelude-collision.rs:61:13
diff --git a/src/test/ui/rust-2021/generic-type-collision.stderr b/src/test/ui/rust-2021/generic-type-collision.stderr
index e6ea28d71..1ec61044f 100644
--- a/src/test/ui/rust-2021/generic-type-collision.stderr
+++ b/src/test/ui/rust-2021/generic-type-collision.stderr
@@ -4,13 +4,13 @@ warning: trait-associated function `from_iter` will become ambiguous in Rust 202
LL | <Vec<i32>>::from_iter(None);
| ^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Vec<i32> as MyTrait<_>>::from_iter`
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
note: the lint level is defined here
--> $DIR/generic-type-collision.rs:4:9
|
LL | #![warn(rust_2021_prelude_collisions)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
warning: 1 warning emitted
diff --git a/src/test/ui/rust-2021/inherent-dyn-collision.stderr b/src/test/ui/rust-2021/inherent-dyn-collision.stderr
index 77b4c3851..f5905574a 100644
--- a/src/test/ui/rust-2021/inherent-dyn-collision.stderr
+++ b/src/test/ui/rust-2021/inherent-dyn-collision.stderr
@@ -4,13 +4,13 @@ warning: trait method `try_into` will become ambiguous in Rust 2021
LL | get_dyn_trait().try_into().unwrap()
| ^^^^^^^^^^^^^^^ help: disambiguate the method call: `(&*get_dyn_trait())`
|
+ = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
note: the lint level is defined here
--> $DIR/inherent-dyn-collision.rs:8:9
|
LL | #![warn(rust_2021_prelude_collisions)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
warning: 1 warning emitted
diff --git a/src/test/ui/rust-2021/reserved-prefixes-migration.stderr b/src/test/ui/rust-2021/reserved-prefixes-migration.stderr
index c6bc082cf..20914d1b9 100644
--- a/src/test/ui/rust-2021/reserved-prefixes-migration.stderr
+++ b/src/test/ui/rust-2021/reserved-prefixes-migration.stderr
@@ -4,13 +4,13 @@ warning: prefix `z` is unknown
LL | m2!(z"hey");
| ^ unknown prefix
|
+ = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/reserving-syntax.html>
note: the lint level is defined here
--> $DIR/reserved-prefixes-migration.rs:5:9
|
LL | #![warn(rust_2021_prefixes_incompatible_syntax)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/reserving-syntax.html>
help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021
|
LL | m2!(z "hey");
diff --git a/src/test/ui/rustdoc/deny-invalid-doc-attrs.stderr b/src/test/ui/rustdoc/deny-invalid-doc-attrs.stderr
index a14ab8fe4..e9a4c1dd5 100644
--- a/src/test/ui/rustdoc/deny-invalid-doc-attrs.stderr
+++ b/src/test/ui/rustdoc/deny-invalid-doc-attrs.stderr
@@ -4,13 +4,13 @@ error: unknown `doc` attribute `x`
LL | #![doc(x)]
| ^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
note: the lint level is defined here
--> $DIR/deny-invalid-doc-attrs.rs:1:9
|
LL | #![deny(invalid_doc_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: aborting due to previous error
diff --git a/src/test/ui/rustdoc/doc-test-attr.stderr b/src/test/ui/rustdoc/doc-test-attr.stderr
index 7f5e2d6bc..5e6014954 100644
--- a/src/test/ui/rustdoc/doc-test-attr.stderr
+++ b/src/test/ui/rustdoc/doc-test-attr.stderr
@@ -4,13 +4,13 @@ error: `#[doc(test(...)]` takes a list of attributes
LL | #![doc(test)]
| ^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
note: the lint level is defined here
--> $DIR/doc-test-attr.rs:2:9
|
LL | #![deny(invalid_doc_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
error: `#[doc(test(...)]` takes a list of attributes
--> $DIR/doc-test-attr.rs:7:8
diff --git a/src/test/ui/rustdoc/feature-gate-doc_primitive.stderr b/src/test/ui/rustdoc/feature-gate-doc_primitive.stderr
index 736bf29c5..194b2d87d 100644
--- a/src/test/ui/rustdoc/feature-gate-doc_primitive.stderr
+++ b/src/test/ui/rustdoc/feature-gate-doc_primitive.stderr
@@ -4,9 +4,9 @@ warning: `doc(primitive)` should never have been stable
LL | #[doc(primitive = "usize")]
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(invalid_doc_attributes)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
+ = note: `#[warn(invalid_doc_attributes)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/sanitize/address.rs b/src/test/ui/sanitize/address.rs
index 9a26a351d..5b2cea875 100644
--- a/src/test/ui/sanitize/address.rs
+++ b/src/test/ui/sanitize/address.rs
@@ -5,9 +5,7 @@
//
// run-fail
// error-pattern: AddressSanitizer: stack-buffer-overflow
-// error-pattern: 'xs' (line 15) <== Memory access at offset
-
-#![feature(bench_black_box)]
+// error-pattern: 'xs' (line 13) <== Memory access at offset
use std::hint::black_box;
diff --git a/src/test/ui/sanitize/hwaddress.rs b/src/test/ui/sanitize/hwaddress.rs
index b988035f7..f9b37a155 100644
--- a/src/test/ui/sanitize/hwaddress.rs
+++ b/src/test/ui/sanitize/hwaddress.rs
@@ -10,8 +10,6 @@
// run-fail
// error-pattern: HWAddressSanitizer: tag-mismatch
-#![feature(bench_black_box)]
-
use std::hint::black_box;
fn main() {
diff --git a/src/test/ui/sanitize/inline-always.stderr b/src/test/ui/sanitize/inline-always.stderr
index 918762d1f..74fba3c0e 100644
--- a/src/test/ui/sanitize/inline-always.stderr
+++ b/src/test/ui/sanitize/inline-always.stderr
@@ -4,12 +4,12 @@ warning: `no_sanitize` will have no effect after inlining
LL | #[no_sanitize(address)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(inline_no_sanitize)]` on by default
note: inlining requested here
--> $DIR/inline-always.rs:5:1
|
LL | #[inline(always)]
| ^^^^^^^^^^^^^^^^^
+ = note: `#[warn(inline_no_sanitize)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/sanitize/leak.rs b/src/test/ui/sanitize/leak.rs
index f63f81352..cbb44ae8a 100644
--- a/src/test/ui/sanitize/leak.rs
+++ b/src/test/ui/sanitize/leak.rs
@@ -6,8 +6,6 @@
// run-fail
// error-pattern: LeakSanitizer: detected memory leaks
-#![feature(bench_black_box)]
-
use std::hint::black_box;
use std::mem;
diff --git a/src/test/ui/sanitize/memory-eager.rs b/src/test/ui/sanitize/memory-eager.rs
index cc0593ec0..0018c2f75 100644
--- a/src/test/ui/sanitize/memory-eager.rs
+++ b/src/test/ui/sanitize/memory-eager.rs
@@ -17,7 +17,6 @@
#![feature(core_intrinsics)]
#![feature(start)]
-#![feature(bench_black_box)]
use std::hint::black_box;
use std::mem::MaybeUninit;
diff --git a/src/test/ui/sanitize/memory.rs b/src/test/ui/sanitize/memory.rs
index 14d4de65d..1a9ac3a4f 100644
--- a/src/test/ui/sanitize/memory.rs
+++ b/src/test/ui/sanitize/memory.rs
@@ -16,7 +16,6 @@
#![feature(core_intrinsics)]
#![feature(start)]
-#![feature(bench_black_box)]
#![allow(invalid_value)]
use std::hint::black_box;
diff --git a/src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs b/src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs
index 1542c7f31..33e18e355 100644
--- a/src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs
+++ b/src/test/ui/sanitize/new-llvm-pass-manager-thin-lto.rs
@@ -7,7 +7,7 @@
//
// no-prefer-dynamic
// revisions: opt0 opt1
-// compile-flags: -Znew-llvm-pass-manager=yes -Zsanitizer=address -Clto=thin
+// compile-flags: -Zsanitizer=address -Clto=thin
//[opt0]compile-flags: -Copt-level=0
//[opt1]compile-flags: -Copt-level=1
// run-fail
diff --git a/src/test/ui/save-analysis/issue-68621.stderr b/src/test/ui/save-analysis/issue-68621.stderr
index 4a4bf9a69..4452ee791 100644
--- a/src/test/ui/save-analysis/issue-68621.stderr
+++ b/src/test/ui/save-analysis/issue-68621.stderr
@@ -4,7 +4,7 @@ error: unconstrained opaque type
LL | type Future = impl Trait;
| ^^^^^^^^^^
|
- = note: `Future` must be used in combination with a concrete type within the same module
+ = note: `Future` must be used in combination with a concrete type within the same impl
error: aborting due to previous error
diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr
index 7e7d60d0f..eb3d3e4a6 100644
--- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr
+++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr
@@ -6,7 +6,7 @@ LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
| |
| hidden type `Pin<&Foo>` captures the anonymous lifetime defined here
|
-help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound
+help: to declare that `impl Clone` captures `'_`, you can add an explicit `'_` lifetime bound
|
LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
| ++++
diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr
index 30d2250c0..2c0b2a0d9 100644
--- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr
+++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr
@@ -6,7 +6,7 @@ LL | fn f(self: Pin<&Self>) -> impl Clone { self }
| |
| hidden type `Pin<&Foo>` captures the anonymous lifetime defined here
|
-help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound
+help: to declare that `impl Clone` captures `'_`, you can add an explicit `'_` lifetime bound
|
LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
| ++++
diff --git a/src/test/ui/simd/portable-intrinsics-arent-exposed.stderr b/src/test/ui/simd/portable-intrinsics-arent-exposed.stderr
index 870f4064d..8881ede0d 100644
--- a/src/test/ui/simd/portable-intrinsics-arent-exposed.stderr
+++ b/src/test/ui/simd/portable-intrinsics-arent-exposed.stderr
@@ -11,6 +11,11 @@ error[E0432]: unresolved import `std::simd::intrinsics`
|
LL | use std::simd::intrinsics;
| ^^^^^^^^^^^^^^^^^^^^^ no `intrinsics` in `simd`
+ |
+help: consider importing this module instead
+ |
+LL | use std::intrinsics;
+ | ~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
diff --git a/src/test/ui/simd/target-feature-mixup.rs b/src/test/ui/simd/target-feature-mixup.rs
index 6d7688191..5dd163715 100644
--- a/src/test/ui/simd/target-feature-mixup.rs
+++ b/src/test/ui/simd/target-feature-mixup.rs
@@ -5,6 +5,7 @@
// ignore-emscripten
// ignore-sgx no processes
+// ignore-fuchsia must translate zircon signal to SIGILL, FIXME (#58590)
#![feature(repr_simd, target_feature, cfg_target_feature)]
#![feature(avx512_target_feature)]
diff --git a/src/test/ui/single-use-lifetime/derive-eq.rs b/src/test/ui/single-use-lifetime/derive-eq.rs
new file mode 100644
index 000000000..e5bdfc55d
--- /dev/null
+++ b/src/test/ui/single-use-lifetime/derive-eq.rs
@@ -0,0 +1,11 @@
+// check-pass
+
+#![deny(single_use_lifetimes)]
+
+#[derive(PartialEq, Eq)]
+struct Foo<'a, T> {
+ /// a reference to the underlying secret data that will be derefed
+ pub data: &'a mut T,
+}
+
+fn main() {}
diff --git a/src/test/ui/sized-cycle-note.rs b/src/test/ui/sized-cycle-note.rs
index ca8be5692..766a5fa0d 100644
--- a/src/test/ui/sized-cycle-note.rs
+++ b/src/test/ui/sized-cycle-note.rs
@@ -1,15 +1,6 @@
-// Test the error message resulting from a cycle in solving `Foo:
-// Sized`. The specifics of the message will of course but the main
-// thing we want to preserve is that:
-//
-// 1. the message should appear attached to one of the structs
-// defined in this file;
-// 2. it should elaborate the steps that led to the cycle.
-
struct Baz { q: Option<Foo> }
-//~^ ERROR recursive type `Baz` has infinite size
+//~^ ERROR recursive types `Baz` and `Foo` have infinite size
struct Foo { q: Option<Baz> }
-//~^ ERROR recursive type `Foo` has infinite size
impl Foo { fn bar(&self) {} }
diff --git a/src/test/ui/sized-cycle-note.stderr b/src/test/ui/sized-cycle-note.stderr
index 536510814..06c87b61f 100644
--- a/src/test/ui/sized-cycle-note.stderr
+++ b/src/test/ui/sized-cycle-note.stderr
@@ -1,29 +1,19 @@
-error[E0072]: recursive type `Baz` has infinite size
- --> $DIR/sized-cycle-note.rs:9:1
+error[E0072]: recursive types `Baz` and `Foo` have infinite size
+ --> $DIR/sized-cycle-note.rs:1:1
|
LL | struct Baz { q: Option<Foo> }
- | ^^^^^^^^^^ ----------- recursive without indirection
- | |
- | recursive type has infinite size
- |
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Baz` representable
- |
-LL | struct Baz { q: Option<Box<Foo>> }
- | ++++ +
-
-error[E0072]: recursive type `Foo` has infinite size
- --> $DIR/sized-cycle-note.rs:11:1
- |
+ | ^^^^^^^^^^ --- recursive without indirection
+LL |
LL | struct Foo { q: Option<Baz> }
- | ^^^^^^^^^^ ----------- recursive without indirection
- | |
- | recursive type has infinite size
+ | ^^^^^^^^^^ --- recursive without indirection
+ |
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
+LL ~ struct Baz { q: Option<Box<Foo>> }
+LL |
+LL ~ struct Foo { q: Option<Box<Baz>> }
|
-LL | struct Foo { q: Option<Box<Baz>> }
- | ++++ +
-error: aborting due to 2 previous errors
+error: aborting due to previous error
For more information about this error, try `rustc --explain E0072`.
diff --git a/src/test/ui/span/E0072.stderr b/src/test/ui/span/E0072.stderr
index 882ed577c..20f2e0df0 100644
--- a/src/test/ui/span/E0072.stderr
+++ b/src/test/ui/span/E0072.stderr
@@ -2,12 +2,12 @@ error[E0072]: recursive type `ListNode` has infinite size
--> $DIR/E0072.rs:1:1
|
LL | struct ListNode {
- | ^^^^^^^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^^^^^^^
LL | head: u8,
LL | tail: Option<ListNode>,
- | ---------------- recursive without indirection
+ | -------- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `ListNode` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | tail: Option<Box<ListNode>>,
| ++++ +
diff --git a/src/test/ui/span/E0204.stderr b/src/test/ui/span/E0204.stderr
index 257584843..0b2166eed 100644
--- a/src/test/ui/span/E0204.stderr
+++ b/src/test/ui/span/E0204.stderr
@@ -1,11 +1,11 @@
error[E0204]: the trait `Copy` may not be implemented for this type
- --> $DIR/E0204.rs:5:6
+ --> $DIR/E0204.rs:5:15
|
LL | foo: Vec<u32>,
| ------------- this field does not implement `Copy`
...
LL | impl Copy for Foo { }
- | ^^^^
+ | ^^^
error[E0204]: the trait `Copy` may not be implemented for this type
--> $DIR/E0204.rs:7:10
@@ -19,13 +19,13 @@ LL | ty: &'a mut bool,
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0204]: the trait `Copy` may not be implemented for this type
- --> $DIR/E0204.rs:17:6
+ --> $DIR/E0204.rs:17:15
|
LL | Bar { x: Vec<u32> },
| ----------- this field does not implement `Copy`
...
LL | impl Copy for EFoo { }
- | ^^^^
+ | ^^^^
error[E0204]: the trait `Copy` may not be implemented for this type
--> $DIR/E0204.rs:19:10
diff --git a/src/test/ui/span/E0493.rs b/src/test/ui/span/E0493.rs
index ad4100205..625da25a7 100644
--- a/src/test/ui/span/E0493.rs
+++ b/src/test/ui/span/E0493.rs
@@ -15,7 +15,7 @@ impl Drop for Bar {
}
const F : Foo = (Foo { a : 0 }, Foo { a : 1 }).1;
-//~^ destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
fn main() {
}
diff --git a/src/test/ui/span/E0493.stderr b/src/test/ui/span/E0493.stderr
index 29d1b0009..9db627562 100644
--- a/src/test/ui/span/E0493.stderr
+++ b/src/test/ui/span/E0493.stderr
@@ -1,10 +1,10 @@
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `(Foo, Foo)` cannot be evaluated at compile-time
--> $DIR/E0493.rs:17:17
|
LL | const F : Foo = (Foo { a : 0 }, Foo { a : 1 }).1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - value is dropped here
| |
- | constants cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constants
error: aborting due to previous error
diff --git a/src/test/ui/span/E0535.stderr b/src/test/ui/span/E0535.stderr
index f52c3f9f2..b1411bc43 100644
--- a/src/test/ui/span/E0535.stderr
+++ b/src/test/ui/span/E0535.stderr
@@ -3,6 +3,8 @@ error[E0535]: invalid argument
|
LL | #[inline(unknown)]
| ^^^^^^^
+ |
+ = help: valid inline arguments are `always` and `never`
error: aborting due to previous error
diff --git a/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs
index 94f578af2..4559da91e 100644
--- a/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs
+++ b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs
@@ -12,7 +12,6 @@ impl A {
trait C{async fn new(val: T) {} //~ ERROR `async fn` is not permitted in Rust 2015
//~^ ERROR functions in traits cannot be declared `async`
-//~| ERROR mismatched types
//~| ERROR cannot find type `T` in this scope
//~| WARN changes to closure capture in Rust 2021 will affect drop order [rust_2021_incompatible_closure_captures]
diff --git a/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr
index 3814c568e..df1cafdb7 100644
--- a/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr
+++ b/src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr
@@ -1,5 +1,5 @@
error: this file contains an unclosed delimiter
- --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:19:53
+ --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:18:53
|
LL | trait C{async fn new(val: T) {}
| - unclosed delimiter
@@ -25,12 +25,6 @@ LL | trait C{async fn new(val: T) {}
= help: pass `--edition 2021` to `rustc`
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
-error[E0423]: expected function, found module `crate`
- --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:9:5
- |
-LL | crate(move || {} ).await
- | ^^^^^ not a function
-
error[E0412]: cannot find type `T` in this scope
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:27
|
@@ -51,7 +45,13 @@ LL | trait C{async fn new(val: T) {}
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
- = help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
+ = help: add `#![feature(async_fn_in_trait)]` to the crate attributes to enable
+
+error[E0423]: expected function, found module `crate`
+ --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:9:5
+ |
+LL | crate(move || {} ).await
+ | ^^^^^ not a function
warning: changes to closure capture in Rust 2021 will affect drop order
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:6:57
@@ -67,27 +67,13 @@ LL | | crate(move || {} ).await
LL | | }
| |_____^
|
- = note: requested on the command line with `-W rust-2021-incompatible-closure-captures`
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/disjoint-capture-in-closures.html>
+ = note: requested on the command line with `-W rust-2021-incompatible-closure-captures`
help: add a dummy let to cause `path` to be fully captured
|
LL | async fn create(path: impl AsRef<std::path::Path>) { let _ = &path;
| ++++++++++++++
-error[E0308]: mismatched types
- --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:30
- |
-LL | trait C{async fn new(val: T) {}
- | ^^ expected associated type, found opaque type
- |
- ::: $SRC_DIR/core/src/future/mod.rs:LL:COL
- |
-LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
- | ------------------------------- the found opaque type
- |
- = note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:30>)
- found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
-
warning: changes to closure capture in Rust 2021 will affect drop order
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:30
|
@@ -103,7 +89,7 @@ help: add a dummy let to cause `val` to be fully captured
LL | trait C{async fn new(val: T) { let _ = &val;}
| +++++++++++++
-error: aborting due to 7 previous errors; 2 warnings emitted
+error: aborting due to 6 previous errors; 2 warnings emitted
-Some errors have detailed explanations: E0308, E0412, E0423, E0670, E0706.
-For more information about an error, try `rustc --explain E0308`.
+Some errors have detailed explanations: E0412, E0423, E0670, E0706.
+For more information about an error, try `rustc --explain E0412`.
diff --git a/src/test/ui/span/issue-7575.rs b/src/test/ui/span/issue-7575.rs
deleted file mode 100644
index eddd158ae..000000000
--- a/src/test/ui/span/issue-7575.rs
+++ /dev/null
@@ -1,75 +0,0 @@
-// Test the mechanism for warning about possible missing `self` declarations.
-trait CtxtFn {
- fn f8(self, _: usize) -> usize;
- fn f9(_: usize) -> usize;
-}
-
-trait OtherTrait {
- fn f9(_: usize) -> usize;
-}
-
-// Note: this trait is not implemented, but we can't really tell
-// whether or not an impl would match anyhow without a self
-// declaration to match against, so we wind up prisizeing it as a
-// candidate. This seems not unreasonable -- perhaps the user meant to
-// implement it, after all.
-trait UnusedTrait {
- fn f9(_: usize) -> usize;
-}
-
-impl CtxtFn for usize {
- fn f8(self, i: usize) -> usize {
- i * 4
- }
-
- fn f9(i: usize) -> usize {
- i * 4
- }
-}
-
-impl OtherTrait for usize {
- fn f9(i: usize) -> usize {
- i * 8
- }
-}
-
-struct Myisize(isize);
-
-impl Myisize {
- fn fff(i: isize) -> isize {
- i
- }
-}
-
-trait ManyImplTrait {
- fn is_str() -> bool {
- false
- }
-}
-
-impl ManyImplTrait for String {
- fn is_str() -> bool {
- true
- }
-}
-
-impl ManyImplTrait for usize {}
-impl ManyImplTrait for isize {}
-impl ManyImplTrait for char {}
-impl ManyImplTrait for Myisize {}
-
-fn no_param_bound(u: usize, m: Myisize) -> usize {
- u.f8(42) + u.f9(342) + m.fff(42)
- //~^ ERROR no method named `f9` found
- //~| ERROR no method named `fff` found
-
-
-}
-
-fn param_bound<T: ManyImplTrait>(t: T) -> bool {
- t.is_str()
- //~^ ERROR no method named `is_str` found
-}
-
-fn main() {
-}
diff --git a/src/test/ui/span/issue-7575.stderr b/src/test/ui/span/issue-7575.stderr
deleted file mode 100644
index 4f30edb3f..000000000
--- a/src/test/ui/span/issue-7575.stderr
+++ /dev/null
@@ -1,82 +0,0 @@
-error[E0599]: no method named `f9` found for type `usize` in the current scope
- --> $DIR/issue-7575.rs:62:18
- |
-LL | u.f8(42) + u.f9(342) + m.fff(42)
- | ^^ this is an associated function, not a method
- |
- = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
-note: candidate #1 is defined in the trait `CtxtFn`
- --> $DIR/issue-7575.rs:4:5
- |
-LL | fn f9(_: usize) -> usize;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
-note: candidate #2 is defined in the trait `OtherTrait`
- --> $DIR/issue-7575.rs:8:5
- |
-LL | fn f9(_: usize) -> usize;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
-note: candidate #3 is defined in the trait `UnusedTrait`
- --> $DIR/issue-7575.rs:17:5
- |
-LL | fn f9(_: usize) -> usize;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: items from traits can only be used if the trait is implemented and in scope
- = note: the following traits define an item `f9`, perhaps you need to implement one of them:
- candidate #1: `CtxtFn`
- candidate #2: `OtherTrait`
- candidate #3: `UnusedTrait`
-help: disambiguate the associated function for candidate #1
- |
-LL | u.f8(42) + <usize as CtxtFn>::f9(u, 342) + m.fff(42)
- | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-help: disambiguate the associated function for candidate #2
- |
-LL | u.f8(42) + <usize as OtherTrait>::f9(u, 342) + m.fff(42)
- | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-help: disambiguate the associated function for candidate #3
- |
-LL | u.f8(42) + <usize as UnusedTrait>::f9(u, 342) + m.fff(42)
- | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-error[E0599]: no method named `fff` found for struct `Myisize` in the current scope
- --> $DIR/issue-7575.rs:62:30
- |
-LL | struct Myisize(isize);
- | -------------- method `fff` not found for this struct
-...
-LL | u.f8(42) + u.f9(342) + m.fff(42)
- | --^^^
- | | |
- | | this is an associated function, not a method
- | help: use associated function syntax instead: `Myisize::fff`
- |
- = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
-note: the candidate is defined in an impl for the type `Myisize`
- --> $DIR/issue-7575.rs:39:5
- |
-LL | fn fff(i: isize) -> isize {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error[E0599]: no method named `is_str` found for type parameter `T` in the current scope
- --> $DIR/issue-7575.rs:70:7
- |
-LL | fn param_bound<T: ManyImplTrait>(t: T) -> bool {
- | - method `is_str` not found for this type parameter
-LL | t.is_str()
- | ^^^^^^ this is an associated function, not a method
- |
- = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
-note: the candidate is defined in the trait `ManyImplTrait`
- --> $DIR/issue-7575.rs:45:5
- |
-LL | fn is_str() -> bool {
- | ^^^^^^^^^^^^^^^^^^^
- = help: items from traits can only be used if the type parameter is bounded by the trait
-help: disambiguate the associated function for the candidate
- |
-LL | <T as ManyImplTrait>::is_str(t)
- |
-
-error: aborting due to 3 previous errors
-
-For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/span/multiline-span-E0072.stderr b/src/test/ui/span/multiline-span-E0072.stderr
index 79b13f45f..fc2f6e662 100644
--- a/src/test/ui/span/multiline-span-E0072.stderr
+++ b/src/test/ui/span/multiline-span-E0072.stderr
@@ -3,12 +3,12 @@ error[E0072]: recursive type `ListNode` has infinite size
|
LL | / struct
LL | | ListNode
- | |________^ recursive type has infinite size
+ | |________^
...
LL | tail: Option<ListNode>,
- | ---------------- recursive without indirection
+ | -------- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `ListNode` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | tail: Option<Box<ListNode>>,
| ++++ +
diff --git a/src/test/ui/span/recursive-type-field.rs b/src/test/ui/span/recursive-type-field.rs
index 58ea81b83..bd4c43534 100644
--- a/src/test/ui/span/recursive-type-field.rs
+++ b/src/test/ui/span/recursive-type-field.rs
@@ -1,11 +1,11 @@
use std::rc::Rc;
-struct Foo<'a> { //~ ERROR recursive type
+struct Foo<'a> { //~ ERROR recursive types `Foo` and `Bar` have infinite size
bar: Bar<'a>,
b: Rc<Bar<'a>>,
}
-struct Bar<'a> { //~ ERROR recursive type
+struct Bar<'a> {
y: (Foo<'a>, Foo<'a>),
z: Option<Bar<'a>>,
a: &'a Foo<'a>,
diff --git a/src/test/ui/span/recursive-type-field.stderr b/src/test/ui/span/recursive-type-field.stderr
index 08e97e750..10af4c36b 100644
--- a/src/test/ui/span/recursive-type-field.stderr
+++ b/src/test/ui/span/recursive-type-field.stderr
@@ -1,35 +1,27 @@
-error[E0072]: recursive type `Foo` has infinite size
+error[E0072]: recursive types `Foo` and `Bar` have infinite size
--> $DIR/recursive-type-field.rs:3:1
|
LL | struct Foo<'a> {
- | ^^^^^^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^^^^^^
LL | bar: Bar<'a>,
| ------- recursive without indirection
+...
+LL | struct Bar<'a> {
+ | ^^^^^^^^^^^^^^
+LL | y: (Foo<'a>, Foo<'a>),
+ | ------- ------- recursive without indirection
+ | |
+ | recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
- |
-LL | bar: Box<Bar<'a>>,
- | ++++ +
-
-error[E0072]: recursive type `Bar` has infinite size
- --> $DIR/recursive-type-field.rs:8:1
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
+LL ~ bar: Box<Bar<'a>>,
+LL | b: Rc<Bar<'a>>,
+ ...
LL | struct Bar<'a> {
- | ^^^^^^^^^^^^^^ recursive type has infinite size
-LL | y: (Foo<'a>, Foo<'a>),
- | ------------------ recursive without indirection
-LL | z: Option<Bar<'a>>,
- | --------------- recursive without indirection
-...
-LL | d: [Bar<'a>; 1],
- | ------------ recursive without indirection
-LL | e: Foo<'a>,
- | ------- recursive without indirection
-LL | x: Bar<'a>,
- | ------- recursive without indirection
+LL ~ y: (Box<Foo<'a>>, Box<Foo<'a>>),
|
- = help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Bar` representable
-error: aborting due to 2 previous errors
+error: aborting due to previous error
For more information about this error, try `rustc --explain E0072`.
diff --git a/src/test/ui/specialization/assoc-ty-graph-cycle.stderr b/src/test/ui/specialization/assoc-ty-graph-cycle.stderr
index 17da34caa..f5529c24d 100644
--- a/src/test/ui/specialization/assoc-ty-graph-cycle.stderr
+++ b/src/test/ui/specialization/assoc-ty-graph-cycle.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/const_trait_impl.rs b/src/test/ui/specialization/const_trait_impl.rs
new file mode 100644
index 000000000..05ba4c8d4
--- /dev/null
+++ b/src/test/ui/specialization/const_trait_impl.rs
@@ -0,0 +1,55 @@
+// check-pass
+#![feature(const_trait_impl, min_specialization, rustc_attrs)]
+
+#[rustc_specialization_trait]
+#[const_trait]
+pub unsafe trait Sup {
+ fn foo() -> u32;
+}
+
+#[rustc_specialization_trait]
+#[const_trait]
+pub unsafe trait Sub: ~const Sup {}
+
+unsafe impl const Sup for u8 {
+ default fn foo() -> u32 {
+ 1
+ }
+}
+
+unsafe impl const Sup for () {
+ fn foo() -> u32 {
+ 42
+ }
+}
+
+unsafe impl const Sub for () {}
+
+#[const_trait]
+pub trait A {
+ fn a() -> u32;
+}
+
+impl<T: ~const Default> const A for T {
+ default fn a() -> u32 {
+ 2
+ }
+}
+
+impl<T: ~const Default + ~const Sup> const A for T {
+ default fn a() -> u32 {
+ 3
+ }
+}
+
+impl<T: ~const Default + ~const Sub> const A for T {
+ fn a() -> u32 {
+ T::foo()
+ }
+}
+
+const _: () = assert!(<()>::a() == 42);
+const _: () = assert!(<u8>::a() == 3);
+const _: () = assert!(<u16>::a() == 2);
+
+fn main() {}
diff --git a/src/test/ui/specialization/cross-crate-defaults.stderr b/src/test/ui/specialization/cross-crate-defaults.stderr
index e368c2e73..ee5c77a76 100644
--- a/src/test/ui/specialization/cross-crate-defaults.stderr
+++ b/src/test/ui/specialization/cross-crate-defaults.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/default-associated-type-bound-1.stderr b/src/test/ui/specialization/default-associated-type-bound-1.stderr
index af9f2f7c2..e498187c0 100644
--- a/src/test/ui/specialization/default-associated-type-bound-1.stderr
+++ b/src/test/ui/specialization/default-associated-type-bound-1.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0277]: the trait bound `str: Clone` is not satisfied
--> $DIR/default-associated-type-bound-1.rs:18:22
diff --git a/src/test/ui/specialization/default-associated-type-bound-2.stderr b/src/test/ui/specialization/default-associated-type-bound-2.stderr
index 91778ed0f..4dbe251ed 100644
--- a/src/test/ui/specialization/default-associated-type-bound-2.stderr
+++ b/src/test/ui/specialization/default-associated-type-bound-2.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0277]: can't compare `&'static B` with `B`
--> $DIR/default-associated-type-bound-2.rs:16:22
diff --git a/src/test/ui/specialization/default-generic-associated-type-bound.stderr b/src/test/ui/specialization/default-generic-associated-type-bound.stderr
index 44c24c1e5..c597eed37 100644
--- a/src/test/ui/specialization/default-generic-associated-type-bound.stderr
+++ b/src/test/ui/specialization/default-generic-associated-type-bound.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0277]: can't compare `T` with `T`
--> $DIR/default-generic-associated-type-bound.rs:17:26
diff --git a/src/test/ui/specialization/defaultimpl/allowed-cross-crate.stderr b/src/test/ui/specialization/defaultimpl/allowed-cross-crate.stderr
index d8b9c48c7..02f13d461 100644
--- a/src/test/ui/specialization/defaultimpl/allowed-cross-crate.stderr
+++ b/src/test/ui/specialization/defaultimpl/allowed-cross-crate.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/defaultimpl/out-of-order.stderr b/src/test/ui/specialization/defaultimpl/out-of-order.stderr
index 9ca915686..2cf1ac909 100644
--- a/src/test/ui/specialization/defaultimpl/out-of-order.stderr
+++ b/src/test/ui/specialization/defaultimpl/out-of-order.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/defaultimpl/overlap-projection.stderr b/src/test/ui/specialization/defaultimpl/overlap-projection.stderr
index 31d0e6e38..75fdfafd9 100644
--- a/src/test/ui/specialization/defaultimpl/overlap-projection.stderr
+++ b/src/test/ui/specialization/defaultimpl/overlap-projection.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/defaultimpl/projection.stderr b/src/test/ui/specialization/defaultimpl/projection.stderr
index 2d5c80d05..cc3fe8237 100644
--- a/src/test/ui/specialization/defaultimpl/projection.stderr
+++ b/src/test/ui/specialization/defaultimpl/projection.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/defaultimpl/specialization-no-default.stderr b/src/test/ui/specialization/defaultimpl/specialization-no-default.stderr
index 360b7bc78..770be2af2 100644
--- a/src/test/ui/specialization/defaultimpl/specialization-no-default.stderr
+++ b/src/test/ui/specialization/defaultimpl/specialization-no-default.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/specialization-no-default.rs:20:5
diff --git a/src/test/ui/specialization/defaultimpl/specialization-trait-item-not-implemented-rpass.stderr b/src/test/ui/specialization/defaultimpl/specialization-trait-item-not-implemented-rpass.stderr
index 163c93550..407c1ab77 100644
--- a/src/test/ui/specialization/defaultimpl/specialization-trait-item-not-implemented-rpass.stderr
+++ b/src/test/ui/specialization/defaultimpl/specialization-trait-item-not-implemented-rpass.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/defaultimpl/specialization-trait-item-not-implemented.stderr b/src/test/ui/specialization/defaultimpl/specialization-trait-item-not-implemented.stderr
index 250f0017b..f19975060 100644
--- a/src/test/ui/specialization/defaultimpl/specialization-trait-item-not-implemented.stderr
+++ b/src/test/ui/specialization/defaultimpl/specialization-trait-item-not-implemented.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0046]: not all trait items implemented, missing: `foo_two`
--> $DIR/specialization-trait-item-not-implemented.rs:18:1
diff --git a/src/test/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr b/src/test/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr
index d1004a690..33ca7a2c2 100644
--- a/src/test/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr
+++ b/src/test/ui/specialization/defaultimpl/specialization-trait-not-implemented.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0599]: the method `foo_one` exists for struct `MyStruct`, but its trait bounds were not satisfied
--> $DIR/specialization-trait-not-implemented.rs:22:29
diff --git a/src/test/ui/specialization/defaultimpl/specialization-wfcheck.stderr b/src/test/ui/specialization/defaultimpl/specialization-wfcheck.stderr
index a8fdbc528..e78016034 100644
--- a/src/test/ui/specialization/defaultimpl/specialization-wfcheck.stderr
+++ b/src/test/ui/specialization/defaultimpl/specialization-wfcheck.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0277]: the trait bound `U: Eq` is not satisfied
--> $DIR/specialization-wfcheck.rs:7:17
diff --git a/src/test/ui/specialization/defaultimpl/validation.stderr b/src/test/ui/specialization/defaultimpl/validation.stderr
index cbf0cef5e..eb6dc9355 100644
--- a/src/test/ui/specialization/defaultimpl/validation.stderr
+++ b/src/test/ui/specialization/defaultimpl/validation.stderr
@@ -14,9 +14,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error: impls of auto traits cannot be default
--> $DIR/validation.rs:9:21
diff --git a/src/test/ui/specialization/issue-35376.stderr b/src/test/ui/specialization/issue-35376.stderr
index 835277d40..6c4167f3f 100644
--- a/src/test/ui/specialization/issue-35376.stderr
+++ b/src/test/ui/specialization/issue-35376.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/issue-36804.stderr b/src/test/ui/specialization/issue-36804.stderr
index 783a38e6b..c2113b25f 100644
--- a/src/test/ui/specialization/issue-36804.stderr
+++ b/src/test/ui/specialization/issue-36804.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/issue-38091-2.stderr b/src/test/ui/specialization/issue-38091-2.stderr
index 146a56358..117fb10bb 100644
--- a/src/test/ui/specialization/issue-38091-2.stderr
+++ b/src/test/ui/specialization/issue-38091-2.stderr
@@ -4,13 +4,13 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0275]: overflow evaluating the requirement `i32: Check`
|
-note: required for `i32` to implement `Iterate`
+note: required for `i32` to implement `Iterate<'_>`
--> $DIR/issue-38091-2.rs:11:13
|
LL | impl<'a, T> Iterate<'a> for T
diff --git a/src/test/ui/specialization/issue-38091.stderr b/src/test/ui/specialization/issue-38091.stderr
index cc5536c9e..f2210a407 100644
--- a/src/test/ui/specialization/issue-38091.stderr
+++ b/src/test/ui/specialization/issue-38091.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0277]: the trait bound `(): Valid` is not satisfied
--> $DIR/issue-38091.rs:12:23
diff --git a/src/test/ui/specialization/issue-39448.stderr b/src/test/ui/specialization/issue-39448.stderr
index 9b74f684b..60157d9a3 100644
--- a/src/test/ui/specialization/issue-39448.stderr
+++ b/src/test/ui/specialization/issue-39448.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0275]: overflow evaluating the requirement `T: FromA<U>`
--> $DIR/issue-39448.rs:45:13
diff --git a/src/test/ui/specialization/issue-39618.stderr b/src/test/ui/specialization/issue-39618.stderr
index 77a45806e..19de60c7c 100644
--- a/src/test/ui/specialization/issue-39618.stderr
+++ b/src/test/ui/specialization/issue-39618.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/issue-50452-fail.stderr b/src/test/ui/specialization/issue-50452-fail.stderr
index 7249ad738..5c136adc4 100644
--- a/src/test/ui/specialization/issue-50452-fail.stderr
+++ b/src/test/ui/specialization/issue-50452-fail.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/issue-50452-fail.rs:10:5
diff --git a/src/test/ui/specialization/issue-50452.stderr b/src/test/ui/specialization/issue-50452.stderr
index 2f05c4134..48cab9dcd 100644
--- a/src/test/ui/specialization/issue-50452.stderr
+++ b/src/test/ui/specialization/issue-50452.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/issue-52050.stderr b/src/test/ui/specialization/issue-52050.stderr
index 6d24997a5..c263fe467 100644
--- a/src/test/ui/specialization/issue-52050.stderr
+++ b/src/test/ui/specialization/issue-52050.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0119]: conflicting implementations of trait `IntoPyDictPointer` for type `()`
--> $DIR/issue-52050.rs:28:1
diff --git a/src/test/ui/specialization/issue-63716-parse-async.stderr b/src/test/ui/specialization/issue-63716-parse-async.stderr
index cde17872d..a00572da8 100644
--- a/src/test/ui/specialization/issue-63716-parse-async.stderr
+++ b/src/test/ui/specialization/issue-63716-parse-async.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/issue-70442.stderr b/src/test/ui/specialization/issue-70442.stderr
index 5ee82e991..aa72c3286 100644
--- a/src/test/ui/specialization/issue-70442.stderr
+++ b/src/test/ui/specialization/issue-70442.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/non-defaulted-item-fail.stderr b/src/test/ui/specialization/non-defaulted-item-fail.stderr
index 8b7d67972..faa14555a 100644
--- a/src/test/ui/specialization/non-defaulted-item-fail.stderr
+++ b/src/test/ui/specialization/non-defaulted-item-fail.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization, associated_type_defaults)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0520]: `Ty` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/non-defaulted-item-fail.rs:30:5
diff --git a/src/test/ui/specialization/specialization-allowed-cross-crate.stderr b/src/test/ui/specialization/specialization-allowed-cross-crate.stderr
index 9605bd089..3eea4a53b 100644
--- a/src/test/ui/specialization/specialization-allowed-cross-crate.stderr
+++ b/src/test/ui/specialization/specialization-allowed-cross-crate.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/specialization-assoc-fns.stderr b/src/test/ui/specialization/specialization-assoc-fns.stderr
index a7c0661a8..69f7cece7 100644
--- a/src/test/ui/specialization/specialization-assoc-fns.stderr
+++ b/src/test/ui/specialization/specialization-assoc-fns.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/specialization-basics.stderr b/src/test/ui/specialization/specialization-basics.stderr
index afb2af380..7714d4af4 100644
--- a/src/test/ui/specialization/specialization-basics.stderr
+++ b/src/test/ui/specialization/specialization-basics.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/specialization-cross-crate.stderr b/src/test/ui/specialization/specialization-cross-crate.stderr
index c69130c0a..06818bb56 100644
--- a/src/test/ui/specialization/specialization-cross-crate.stderr
+++ b/src/test/ui/specialization/specialization-cross-crate.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/specialization-default-methods.stderr b/src/test/ui/specialization/specialization-default-methods.stderr
index ef6365ed3..d78d30bd8 100644
--- a/src/test/ui/specialization/specialization-default-methods.stderr
+++ b/src/test/ui/specialization/specialization-default-methods.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/specialization-default-projection.stderr b/src/test/ui/specialization/specialization-default-projection.stderr
index 7a2b75a1c..b8b81876d 100644
--- a/src/test/ui/specialization/specialization-default-projection.stderr
+++ b/src/test/ui/specialization/specialization-default-projection.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> $DIR/specialization-default-projection.rs:21:5
diff --git a/src/test/ui/specialization/specialization-default-types.stderr b/src/test/ui/specialization/specialization-default-types.stderr
index 5ba38face..61a556a93 100644
--- a/src/test/ui/specialization/specialization-default-types.stderr
+++ b/src/test/ui/specialization/specialization-default-types.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> $DIR/specialization-default-types.rs:15:9
diff --git a/src/test/ui/specialization/specialization-no-default.stderr b/src/test/ui/specialization/specialization-no-default.stderr
index 28c869a70..842cec9c7 100644
--- a/src/test/ui/specialization/specialization-no-default.stderr
+++ b/src/test/ui/specialization/specialization-no-default.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/specialization-no-default.rs:20:5
diff --git a/src/test/ui/specialization/specialization-on-projection.stderr b/src/test/ui/specialization/specialization-on-projection.stderr
index d051ffe0a..00fc7ffc5 100644
--- a/src/test/ui/specialization/specialization-on-projection.stderr
+++ b/src/test/ui/specialization/specialization-on-projection.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/specialization-out-of-order.stderr b/src/test/ui/specialization/specialization-out-of-order.stderr
index 785ec2923..b524e00f0 100644
--- a/src/test/ui/specialization/specialization-out-of-order.stderr
+++ b/src/test/ui/specialization/specialization-out-of-order.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/specialization-overlap-negative.stderr b/src/test/ui/specialization/specialization-overlap-negative.stderr
index 552b04a60..fb3d9723a 100644
--- a/src/test/ui/specialization/specialization-overlap-negative.stderr
+++ b/src/test/ui/specialization/specialization-overlap-negative.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0751]: found both positive and negative implementation of trait `std::marker::Send` for type `TestType<_>`:
--> $DIR/specialization-overlap-negative.rs:9:1
diff --git a/src/test/ui/specialization/specialization-overlap-projection.stderr b/src/test/ui/specialization/specialization-overlap-projection.stderr
index c92db7307..708c0817f 100644
--- a/src/test/ui/specialization/specialization-overlap-projection.stderr
+++ b/src/test/ui/specialization/specialization-overlap-projection.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/specialization-overlap.stderr b/src/test/ui/specialization/specialization-overlap.stderr
index 3ccbe1616..989264467 100644
--- a/src/test/ui/specialization/specialization-overlap.stderr
+++ b/src/test/ui/specialization/specialization-overlap.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0119]: conflicting implementations of trait `Foo` for type `std::vec::Vec<_>`
--> $DIR/specialization-overlap.rs:5:1
diff --git a/src/test/ui/specialization/specialization-polarity.stderr b/src/test/ui/specialization/specialization-polarity.stderr
index be013552f..f287018ba 100644
--- a/src/test/ui/specialization/specialization-polarity.stderr
+++ b/src/test/ui/specialization/specialization-polarity.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0751]: found both positive and negative implementation of trait `Foo` for type `u8`:
--> $DIR/specialization-polarity.rs:10:1
diff --git a/src/test/ui/specialization/specialization-projection-alias.stderr b/src/test/ui/specialization/specialization-projection-alias.stderr
index 6d2bca5d2..c94d9ed07 100644
--- a/src/test/ui/specialization/specialization-projection-alias.stderr
+++ b/src/test/ui/specialization/specialization-projection-alias.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/specialization-projection.stderr b/src/test/ui/specialization/specialization-projection.stderr
index 0f1ecf5e3..bfc4e0a0f 100644
--- a/src/test/ui/specialization/specialization-projection.stderr
+++ b/src/test/ui/specialization/specialization-projection.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/specialization-supertraits.stderr b/src/test/ui/specialization/specialization-supertraits.stderr
index d32e47a24..e716bc215 100644
--- a/src/test/ui/specialization/specialization-supertraits.stderr
+++ b/src/test/ui/specialization/specialization-supertraits.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/specialization-translate-projections-with-lifetimes.stderr b/src/test/ui/specialization/specialization-translate-projections-with-lifetimes.stderr
index d30f7af2c..c7aad3c0f 100644
--- a/src/test/ui/specialization/specialization-translate-projections-with-lifetimes.stderr
+++ b/src/test/ui/specialization/specialization-translate-projections-with-lifetimes.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/specialization-translate-projections-with-params.stderr b/src/test/ui/specialization/specialization-translate-projections-with-params.stderr
index 1762248f6..1c4fd9325 100644
--- a/src/test/ui/specialization/specialization-translate-projections-with-params.stderr
+++ b/src/test/ui/specialization/specialization-translate-projections-with-params.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/specialization-translate-projections.stderr b/src/test/ui/specialization/specialization-translate-projections.stderr
index 94a0e79dd..22bbb12a0 100644
--- a/src/test/ui/specialization/specialization-translate-projections.stderr
+++ b/src/test/ui/specialization/specialization-translate-projections.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/specialization/transmute-specialization.stderr b/src/test/ui/specialization/transmute-specialization.stderr
index a0ea72415..b1c26d7da 100644
--- a/src/test/ui/specialization/transmute-specialization.stderr
+++ b/src/test/ui/specialization/transmute-specialization.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/stability-attribute/missing-const-stability.rs b/src/test/ui/stability-attribute/missing-const-stability.rs
index d89886af3..6eff899bf 100644
--- a/src/test/ui/stability-attribute/missing-const-stability.rs
+++ b/src/test/ui/stability-attribute/missing-const-stability.rs
@@ -19,6 +19,7 @@ impl Foo {
}
#[stable(feature = "stable", since = "1.0.0")]
+#[const_trait]
pub trait Bar {
#[stable(feature = "stable", since = "1.0.0")]
fn fun();
diff --git a/src/test/ui/stability-attribute/missing-const-stability.stderr b/src/test/ui/stability-attribute/missing-const-stability.stderr
index 10978728f..4cfbe1528 100644
--- a/src/test/ui/stability-attribute/missing-const-stability.stderr
+++ b/src/test/ui/stability-attribute/missing-const-stability.stderr
@@ -5,7 +5,7 @@ LL | pub const fn foo() {}
| ^^^^^^^^^^^^^^^^^^^^^
error: implementation has missing const stability attribute
- --> $DIR/missing-const-stability.rs:27:1
+ --> $DIR/missing-const-stability.rs:28:1
|
LL | / impl const Bar for Foo {
LL | |
diff --git a/src/test/ui/stability-attribute/stability-attribute-trait-impl.rs b/src/test/ui/stability-attribute/stability-attribute-trait-impl.rs
index ce2726ffd..0c771ae87 100644
--- a/src/test/ui/stability-attribute/stability-attribute-trait-impl.rs
+++ b/src/test/ui/stability-attribute/stability-attribute-trait-impl.rs
@@ -1,4 +1,4 @@
-#![feature(staged_api)]
+#![feature(staged_api, never_type, c_unwind)]
//~^ ERROR module has missing stability attribute
#[stable(feature = "a", since = "1")]
@@ -23,7 +23,21 @@ impl StableTrait for UnstableType {}
impl UnstableTrait for StableType {}
#[unstable(feature = "h", issue = "none")]
+impl StableTrait for ! {}
+
+// Note: If C-unwind is stabilized, switch this to another (unstable) ABI.
+#[unstable(feature = "i", issue = "none")]
+impl StableTrait for extern "C-unwind" fn() {}
+
+#[unstable(feature = "j", issue = "none")]
//~^ ERROR an `#[unstable]` annotation here has no effect [ineffective_unstable_trait_impl]
impl StableTrait for StableType {}
+#[unstable(feature = "k", issue = "none")]
+//~^ ERROR an `#[unstable]` annotation here has no effect [ineffective_unstable_trait_impl]
+impl StableTrait for fn() -> ! {}
+
+#[unstable(feature = "l", issue = "none")]
+impl StableTrait for fn() -> UnstableType {}
+
fn main() {}
diff --git a/src/test/ui/stability-attribute/stability-attribute-trait-impl.stderr b/src/test/ui/stability-attribute/stability-attribute-trait-impl.stderr
index 310f02024..b91a1d2e1 100644
--- a/src/test/ui/stability-attribute/stability-attribute-trait-impl.stderr
+++ b/src/test/ui/stability-attribute/stability-attribute-trait-impl.stderr
@@ -1,16 +1,24 @@
error: an `#[unstable]` annotation here has no effect
- --> $DIR/stability-attribute-trait-impl.rs:25:1
+ --> $DIR/stability-attribute-trait-impl.rs:32:1
|
-LL | #[unstable(feature = "h", issue = "none")]
+LL | #[unstable(feature = "j", issue = "none")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
+ = note: see issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information
= note: `#[deny(ineffective_unstable_trait_impl)]` on by default
+
+error: an `#[unstable]` annotation here has no effect
+ --> $DIR/stability-attribute-trait-impl.rs:36:1
+ |
+LL | #[unstable(feature = "k", issue = "none")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
= note: see issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information
error: module has missing stability attribute
--> $DIR/stability-attribute-trait-impl.rs:1:1
|
-LL | / #![feature(staged_api)]
+LL | / #![feature(staged_api, never_type, c_unwind)]
LL | |
LL | |
LL | | #[stable(feature = "a", since = "1")]
@@ -19,5 +27,5 @@ LL | |
LL | | fn main() {}
| |____________^
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors
diff --git a/src/test/ui/stability-attribute/stable-in-unstable.rs b/src/test/ui/stability-attribute/stable-in-unstable.rs
index 272a1a972..226367c39 100644
--- a/src/test/ui/stability-attribute/stable-in-unstable.rs
+++ b/src/test/ui/stability-attribute/stable-in-unstable.rs
@@ -44,3 +44,11 @@ mod isolated5 {
impl stable_in_unstable_std::old_stable_module::OldTrait for LocalType {}
}
+
+mod isolated6 {
+ use stable_in_unstable_core::new_unstable_module::{OldTrait}; //~ ERROR use of unstable library feature 'unstable_test_feature'
+}
+
+mod isolated7 {
+ use stable_in_unstable_core::new_unstable_module::*; //~ ERROR use of unstable library feature 'unstable_test_feature'
+}
diff --git a/src/test/ui/stability-attribute/stable-in-unstable.stderr b/src/test/ui/stability-attribute/stable-in-unstable.stderr
index e123d8358..b5e3e5f12 100644
--- a/src/test/ui/stability-attribute/stable-in-unstable.stderr
+++ b/src/test/ui/stability-attribute/stable-in-unstable.stderr
@@ -34,6 +34,24 @@ LL | impl stable_in_unstable_core::new_unstable_module::OldTrait for LocalTy
= note: see issue #1 <https://github.com/rust-lang/rust/issues/1> for more information
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
-error: aborting due to 4 previous errors
+error[E0658]: use of unstable library feature 'unstable_test_feature'
+ --> $DIR/stable-in-unstable.rs:49:56
+ |
+LL | use stable_in_unstable_core::new_unstable_module::{OldTrait};
+ | ^^^^^^^^
+ |
+ = note: see issue #1 <https://github.com/rust-lang/rust/issues/1> for more information
+ = help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
+
+error[E0658]: use of unstable library feature 'unstable_test_feature'
+ --> $DIR/stable-in-unstable.rs:53:9
+ |
+LL | use stable_in_unstable_core::new_unstable_module::*;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: see issue #1 <https://github.com/rust-lang/rust/issues/1> for more information
+ = help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
+
+error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/static/static-drop-scope.rs b/src/test/ui/static/static-drop-scope.rs
index e7ea8663d..34afa9873 100644
--- a/src/test/ui/static/static-drop-scope.rs
+++ b/src/test/ui/static/static-drop-scope.rs
@@ -5,33 +5,33 @@ impl Drop for WithDtor {
}
static PROMOTION_FAIL_S: Option<&'static WithDtor> = Some(&WithDtor);
-//~^ ERROR destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
//~| ERROR temporary value dropped while borrowed
const PROMOTION_FAIL_C: Option<&'static WithDtor> = Some(&WithDtor);
-//~^ ERROR destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
//~| ERROR temporary value dropped while borrowed
static EARLY_DROP_S: i32 = (WithDtor, 0).1;
-//~^ ERROR destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
const EARLY_DROP_C: i32 = (WithDtor, 0).1;
-//~^ ERROR destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
const fn const_drop<T>(_: T) {}
-//~^ ERROR destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
const fn const_drop2<T>(x: T) {
(x, ()).1
- //~^ ERROR destructors cannot be evaluated at compile-time
+ //~^ ERROR destructor of
}
const EARLY_DROP_C_OPTION: i32 = (Some(WithDtor), 0).1;
-//~^ ERROR destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
const HELPER: Option<WithDtor> = Some(WithDtor);
const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1;
-//~^ ERROR destructors cannot be evaluated at compile-time
+//~^ ERROR destructor of
fn main () {}
diff --git a/src/test/ui/static/static-drop-scope.stderr b/src/test/ui/static/static-drop-scope.stderr
index ac32f217f..112bfc003 100644
--- a/src/test/ui/static/static-drop-scope.stderr
+++ b/src/test/ui/static/static-drop-scope.stderr
@@ -1,10 +1,10 @@
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `WithDtor` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:7:60
|
LL | static PROMOTION_FAIL_S: Option<&'static WithDtor> = Some(&WithDtor);
| ^^^^^^^^- value is dropped here
| |
- | statics cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in statics
error[E0716]: temporary value dropped while borrowed
--> $DIR/static-drop-scope.rs:7:60
@@ -16,13 +16,13 @@ LL | static PROMOTION_FAIL_S: Option<&'static WithDtor> = Some(&WithDtor);
| | creates a temporary which is freed while still in use
| using this value as a static requires that borrow lasts for `'static`
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `WithDtor` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:11:59
|
LL | const PROMOTION_FAIL_C: Option<&'static WithDtor> = Some(&WithDtor);
| ^^^^^^^^- value is dropped here
| |
- | constants cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constants
error[E0716]: temporary value dropped while borrowed
--> $DIR/static-drop-scope.rs:11:59
@@ -34,54 +34,54 @@ LL | const PROMOTION_FAIL_C: Option<&'static WithDtor> = Some(&WithDtor);
| | creates a temporary which is freed while still in use
| using this value as a constant requires that borrow lasts for `'static`
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `(WithDtor, i32)` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:15:28
|
LL | static EARLY_DROP_S: i32 = (WithDtor, 0).1;
| ^^^^^^^^^^^^^ - value is dropped here
| |
- | statics cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in statics
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `(WithDtor, i32)` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:18:27
|
LL | const EARLY_DROP_C: i32 = (WithDtor, 0).1;
| ^^^^^^^^^^^^^ - value is dropped here
| |
- | constants cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constants
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `T` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:21:24
|
LL | const fn const_drop<T>(_: T) {}
| ^ - value is dropped here
| |
- | constant functions cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constant functions
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `(T, ())` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:25:5
|
LL | (x, ()).1
- | ^^^^^^^ constant functions cannot evaluate destructors
+ | ^^^^^^^ the destructor for this type cannot be evaluated in constant functions
LL |
LL | }
| - value is dropped here
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `(Option<WithDtor>, i32)` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:29:34
|
LL | const EARLY_DROP_C_OPTION: i32 = (Some(WithDtor), 0).1;
| ^^^^^^^^^^^^^^^^^^^ - value is dropped here
| |
- | constants cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constants
-error[E0493]: destructors cannot be evaluated at compile-time
+error[E0493]: destructor of `(Option<WithDtor>, i32)` cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:34:43
|
LL | const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1;
| ^^^^^^^^^^^ - value is dropped here
| |
- | constants cannot evaluate destructors
+ | the destructor for this type cannot be evaluated in constants
error: aborting due to 10 previous errors
diff --git a/src/test/ui/issues/issue-17718-static-sync.rs b/src/test/ui/statics/issue-17718-static-sync.rs
index 6f278d76b..6f278d76b 100644
--- a/src/test/ui/issues/issue-17718-static-sync.rs
+++ b/src/test/ui/statics/issue-17718-static-sync.rs
diff --git a/src/test/ui/issues/issue-17718-static-sync.stderr b/src/test/ui/statics/issue-17718-static-sync.stderr
index bc6e45e59..bc6e45e59 100644
--- a/src/test/ui/issues/issue-17718-static-sync.stderr
+++ b/src/test/ui/statics/issue-17718-static-sync.stderr
diff --git a/src/test/ui/issues/issue-17718-static-unsafe-interior.rs b/src/test/ui/statics/issue-17718-static-unsafe-interior.rs
index 65a8713ba..65a8713ba 100644
--- a/src/test/ui/issues/issue-17718-static-unsafe-interior.rs
+++ b/src/test/ui/statics/issue-17718-static-unsafe-interior.rs
diff --git a/src/test/ui/statics/uninhabited-static.stderr b/src/test/ui/statics/uninhabited-static.stderr
index 88ee4cbdc..ef794bb36 100644
--- a/src/test/ui/statics/uninhabited-static.stderr
+++ b/src/test/ui/statics/uninhabited-static.stderr
@@ -4,14 +4,14 @@ error: static of uninhabited type
LL | static VOID: Void;
| ^^^^^^^^^^^^^^^^^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840>
+ = note: uninhabited statics cannot be initialized, and any access would be an immediate error
note: the lint level is defined here
--> $DIR/uninhabited-static.rs:2:9
|
LL | #![deny(uninhabited_static)]
| ^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #74840 <https://github.com/rust-lang/rust/issues/74840>
- = note: uninhabited statics cannot be initialized, and any access would be an immediate error
error: static of uninhabited type
--> $DIR/uninhabited-static.rs:8:5
@@ -58,8 +58,12 @@ LL | static VOID2: Void = unsafe { std::mem::transmute(()) };
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
+note: enums with no inhabited variants have no valid value
+ --> $DIR/uninhabited-static.rs:4:1
+ |
+LL | enum Void {}
+ | ^^^^^^^^^
= note: `#[warn(invalid_value)]` on by default
- = note: enums with no variants have no valid value
error[E0080]: could not evaluate static initializer
--> $DIR/uninhabited-static.rs:16:32
@@ -76,7 +80,11 @@ LL | static NEVER2: Void = unsafe { std::mem::transmute(()) };
| this code causes undefined behavior when executed
| help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
|
- = note: enums with no variants have no valid value
+note: enums with no inhabited variants have no valid value
+ --> $DIR/uninhabited-static.rs:4:1
+ |
+LL | enum Void {}
+ | ^^^^^^^^^
error: aborting due to 6 previous errors; 2 warnings emitted
diff --git a/src/test/ui/stats/hir-stats.rs b/src/test/ui/stats/hir-stats.rs
index 5102574d4..a24b3ada5 100644
--- a/src/test/ui/stats/hir-stats.rs
+++ b/src/test/ui/stats/hir-stats.rs
@@ -1,7 +1,6 @@
// check-pass
// compile-flags: -Zhir-stats
// only-x86_64
-// ignore-stage1
// The aim here is to include at least one of every different type of top-level
// AST/HIR node reported by `-Zhir-stats`.
diff --git a/src/test/ui/stats/hir-stats.stderr b/src/test/ui/stats/hir-stats.stderr
index 8d9776065..1521b692a 100644
--- a/src/test/ui/stats/hir-stats.stderr
+++ b/src/test/ui/stats/hir-stats.stderr
@@ -26,7 +26,7 @@ ast-stats-1 Block 288 ( 3.4%) 6 48
ast-stats-1 GenericBound 352 ( 4.2%) 4 88
ast-stats-1 - Trait 352 ( 4.2%) 4
ast-stats-1 AssocItem 416 ( 4.9%) 4 104
-ast-stats-1 - TyAlias 208 ( 2.5%) 2
+ast-stats-1 - Type 208 ( 2.5%) 2
ast-stats-1 - Fn 208 ( 2.5%) 2
ast-stats-1 GenericParam 480 ( 5.7%) 5 96
ast-stats-1 PathSegment 720 ( 8.6%) 30 24
@@ -84,7 +84,7 @@ ast-stats-2 Block 288 ( 3.1%) 6 48
ast-stats-2 GenericBound 352 ( 3.8%) 4 88
ast-stats-2 - Trait 352 ( 3.8%) 4
ast-stats-2 AssocItem 416 ( 4.5%) 4 104
-ast-stats-2 - TyAlias 208 ( 2.3%) 2
+ast-stats-2 - Type 208 ( 2.3%) 2
ast-stats-2 - Fn 208 ( 2.3%) 2
ast-stats-2 GenericParam 480 ( 5.2%) 5 96
ast-stats-2 PathSegment 792 ( 8.7%) 33 24
@@ -118,61 +118,61 @@ ast-stats-2
hir-stats HIR STATS
hir-stats Name Accumulated Size Count Item Size
hir-stats ----------------------------------------------------------------
-hir-stats ForeignItemRef 24 ( 0.2%) 1 24
-hir-stats Lifetime 32 ( 0.3%) 1 32
-hir-stats Mod 32 ( 0.3%) 1 32
+hir-stats ForeignItemRef 24 ( 0.3%) 1 24
+hir-stats Lifetime 32 ( 0.4%) 1 32
+hir-stats Mod 32 ( 0.4%) 1 32
hir-stats ExprField 40 ( 0.4%) 1 40
hir-stats TraitItemRef 56 ( 0.6%) 2 28
hir-stats Local 64 ( 0.7%) 1 64
hir-stats Param 64 ( 0.7%) 2 32
-hir-stats InlineAsm 72 ( 0.7%) 1 72
-hir-stats ImplItemRef 72 ( 0.7%) 2 36
-hir-stats Body 96 ( 1.0%) 3 32
-hir-stats GenericArg 96 ( 1.0%) 4 24
-hir-stats - Type 24 ( 0.2%) 1
-hir-stats - Lifetime 72 ( 0.7%) 3
-hir-stats FieldDef 96 ( 1.0%) 2 48
-hir-stats Arm 96 ( 1.0%) 2 48
-hir-stats Stmt 96 ( 1.0%) 3 32
-hir-stats - Local 32 ( 0.3%) 1
-hir-stats - Semi 32 ( 0.3%) 1
-hir-stats - Expr 32 ( 0.3%) 1
-hir-stats FnDecl 120 ( 1.2%) 3 40
-hir-stats Attribute 128 ( 1.3%) 4 32
-hir-stats GenericArgs 144 ( 1.5%) 3 48
-hir-stats Variant 160 ( 1.7%) 2 80
-hir-stats WherePredicate 168 ( 1.7%) 3 56
-hir-stats - BoundPredicate 168 ( 1.7%) 3
-hir-stats GenericBound 192 ( 2.0%) 4 48
-hir-stats - Trait 192 ( 2.0%) 4
-hir-stats Block 288 ( 3.0%) 6 48
-hir-stats Pat 360 ( 3.7%) 5 72
-hir-stats - Wild 72 ( 0.7%) 1
-hir-stats - Struct 72 ( 0.7%) 1
-hir-stats - Binding 216 ( 2.2%) 3
-hir-stats GenericParam 400 ( 4.1%) 5 80
-hir-stats Generics 560 ( 5.8%) 10 56
-hir-stats Ty 720 ( 7.4%) 15 48
+hir-stats InlineAsm 72 ( 0.8%) 1 72
+hir-stats ImplItemRef 72 ( 0.8%) 2 36
+hir-stats Body 96 ( 1.1%) 3 32
+hir-stats GenericArg 96 ( 1.1%) 4 24
+hir-stats - Type 24 ( 0.3%) 1
+hir-stats - Lifetime 72 ( 0.8%) 3
+hir-stats FieldDef 96 ( 1.1%) 2 48
+hir-stats Arm 96 ( 1.1%) 2 48
+hir-stats Stmt 96 ( 1.1%) 3 32
+hir-stats - Local 32 ( 0.4%) 1
+hir-stats - Semi 32 ( 0.4%) 1
+hir-stats - Expr 32 ( 0.4%) 1
+hir-stats FnDecl 120 ( 1.3%) 3 40
+hir-stats Attribute 128 ( 1.4%) 4 32
+hir-stats GenericArgs 144 ( 1.6%) 3 48
+hir-stats Variant 160 ( 1.8%) 2 80
+hir-stats GenericBound 192 ( 2.1%) 4 48
+hir-stats - Trait 192 ( 2.1%) 4
+hir-stats WherePredicate 192 ( 2.1%) 3 64
+hir-stats - BoundPredicate 192 ( 2.1%) 3
+hir-stats Block 288 ( 3.2%) 6 48
+hir-stats Pat 360 ( 3.9%) 5 72
+hir-stats - Wild 72 ( 0.8%) 1
+hir-stats - Struct 72 ( 0.8%) 1
+hir-stats - Binding 216 ( 2.4%) 3
+hir-stats GenericParam 400 ( 4.4%) 5 80
+hir-stats Generics 560 ( 6.1%) 10 56
+hir-stats Ty 720 ( 7.9%) 15 48
hir-stats - Ptr 48 ( 0.5%) 1
hir-stats - Rptr 48 ( 0.5%) 1
-hir-stats - Path 624 ( 6.4%) 13
-hir-stats Expr 768 ( 7.9%) 12 64
+hir-stats - Path 624 ( 6.8%) 13
+hir-stats Expr 768 ( 8.4%) 12 64
hir-stats - Path 64 ( 0.7%) 1
hir-stats - Struct 64 ( 0.7%) 1
hir-stats - Match 64 ( 0.7%) 1
hir-stats - InlineAsm 64 ( 0.7%) 1
-hir-stats - Lit 128 ( 1.3%) 2
-hir-stats - Block 384 ( 4.0%) 6
-hir-stats Item 960 ( 9.9%) 12 80
-hir-stats - Trait 80 ( 0.8%) 1
-hir-stats - Enum 80 ( 0.8%) 1
-hir-stats - ExternCrate 80 ( 0.8%) 1
-hir-stats - ForeignMod 80 ( 0.8%) 1
-hir-stats - Impl 80 ( 0.8%) 1
-hir-stats - Fn 160 ( 1.7%) 2
-hir-stats - Use 400 ( 4.1%) 5
-hir-stats Path 1_536 (15.9%) 32 48
-hir-stats PathSegment 2_240 (23.1%) 40 56
+hir-stats - Lit 128 ( 1.4%) 2
+hir-stats - Block 384 ( 4.2%) 6
+hir-stats Item 960 (10.5%) 12 80
+hir-stats - Trait 80 ( 0.9%) 1
+hir-stats - Enum 80 ( 0.9%) 1
+hir-stats - ExternCrate 80 ( 0.9%) 1
+hir-stats - ForeignMod 80 ( 0.9%) 1
+hir-stats - Impl 80 ( 0.9%) 1
+hir-stats - Fn 160 ( 1.8%) 2
+hir-stats - Use 400 ( 4.4%) 5
+hir-stats Path 1_280 (14.0%) 32 40
+hir-stats PathSegment 1_920 (21.0%) 40 48
hir-stats ----------------------------------------------------------------
-hir-stats Total 9_680
+hir-stats Total 9_128
hir-stats
diff --git a/src/test/ui/std-backtrace.rs b/src/test/ui/std-backtrace.rs
index 3f8306baf..59574b471 100644
--- a/src/test/ui/std-backtrace.rs
+++ b/src/test/ui/std-backtrace.rs
@@ -4,6 +4,7 @@
// ignore-openbsd no support for libbacktrace without filename
// ignore-sgx no processes
// ignore-msvc see #62897 and `backtrace-debuginfo.rs` test
+// ignore-fuchsia Backtraces not symbolized
// compile-flags:-g
// compile-flags:-Cstrip=none
diff --git a/src/test/ui/issues/issue-2718-a.rs b/src/test/ui/structs-enums/issue-2718-a.rs
index 6c4915845..6c4915845 100644
--- a/src/test/ui/issues/issue-2718-a.rs
+++ b/src/test/ui/structs-enums/issue-2718-a.rs
diff --git a/src/test/ui/issues/issue-2718-a.stderr b/src/test/ui/structs-enums/issue-2718-a.stderr
index c6e703f48..7ea620f38 100644
--- a/src/test/ui/issues/issue-2718-a.stderr
+++ b/src/test/ui/structs-enums/issue-2718-a.stderr
@@ -3,10 +3,8 @@ error[E0072]: recursive type `Pong` has infinite size
|
LL | pub struct Pong(SendPacket<Ping>);
| ^^^^^^^^^^^^^^^ ---------------- recursive without indirection
- | |
- | recursive type has infinite size
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Pong` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | pub struct Pong(Box<SendPacket<Ping>>);
| ++++ +
diff --git a/src/test/ui/structs-enums/rec-align-u32.rs b/src/test/ui/structs-enums/rec-align-u32.rs
index 889294daa..ee704198d 100644
--- a/src/test/ui/structs-enums/rec-align-u32.rs
+++ b/src/test/ui/structs-enums/rec-align-u32.rs
@@ -10,6 +10,7 @@ use std::mem;
mod rusti {
extern "rust-intrinsic" {
pub fn pref_align_of<T>() -> usize;
+ #[rustc_safe_intrinsic]
pub fn min_align_of<T>() -> usize;
}
}
diff --git a/src/test/ui/structs-enums/rec-align-u64.rs b/src/test/ui/structs-enums/rec-align-u64.rs
index 3bc2d16cf..40ede9705 100644
--- a/src/test/ui/structs-enums/rec-align-u64.rs
+++ b/src/test/ui/structs-enums/rec-align-u64.rs
@@ -12,6 +12,7 @@ use std::mem;
mod rusti {
extern "rust-intrinsic" {
pub fn pref_align_of<T>() -> usize;
+ #[rustc_safe_intrinsic]
pub fn min_align_of<T>() -> usize;
}
}
diff --git a/src/test/ui/structs-enums/struct-rec/issue-74224.stderr b/src/test/ui/structs-enums/struct-rec/issue-74224.stderr
index 619917846..f1d50bc8a 100644
--- a/src/test/ui/structs-enums/struct-rec/issue-74224.stderr
+++ b/src/test/ui/structs-enums/struct-rec/issue-74224.stderr
@@ -2,12 +2,12 @@ error[E0072]: recursive type `A` has infinite size
--> $DIR/issue-74224.rs:1:1
|
LL | struct A<T> {
- | ^^^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^^^
...
LL | y: A<A<T>>,
| ------- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `A` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | y: Box<A<A<T>>>,
| ++++ +
diff --git a/src/test/ui/structs-enums/struct-rec/issue-84611.stderr b/src/test/ui/structs-enums/struct-rec/issue-84611.stderr
index 2e99435e0..536f54e3e 100644
--- a/src/test/ui/structs-enums/struct-rec/issue-84611.stderr
+++ b/src/test/ui/structs-enums/struct-rec/issue-84611.stderr
@@ -2,12 +2,12 @@ error[E0072]: recursive type `Foo` has infinite size
--> $DIR/issue-84611.rs:1:1
|
LL | struct Foo<T> {
- | ^^^^^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^^^^^
LL |
LL | x: Foo<[T; 1]>,
| ----------- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | x: Box<Foo<[T; 1]>>,
| ++++ +
diff --git a/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.rs b/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.rs
index cca97f43e..3bfce8b4f 100644
--- a/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.rs
+++ b/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.rs
@@ -1,22 +1,20 @@
struct A<T> {
-//~^ ERROR recursive type `A` has infinite size
+//~^ ERROR recursive types `A` and `B` have infinite size
x: T,
y: B<T>,
}
struct B<T> {
-//~^ ERROR recursive type `B` has infinite size
z: A<T>
}
struct C<T> {
-//~^ ERROR recursive type `C` has infinite size
+//~^ ERROR recursive types `C` and `D` have infinite size
x: T,
y: Option<Option<D<T>>>,
}
struct D<T> {
-//~^ ERROR recursive type `D` has infinite size
z: Option<Option<C<T>>>,
}
diff --git a/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr b/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr
index 80a494f3f..881bc2819 100644
--- a/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr
+++ b/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr
@@ -1,59 +1,49 @@
-error[E0072]: recursive type `A` has infinite size
+error[E0072]: recursive types `A` and `B` have infinite size
--> $DIR/mutual-struct-recursion.rs:1:1
|
LL | struct A<T> {
- | ^^^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^^^
...
LL | y: B<T>,
| ---- recursive without indirection
- |
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `A` representable
- |
-LL | y: Box<B<T>>,
- | ++++ +
-
-error[E0072]: recursive type `B` has infinite size
- --> $DIR/mutual-struct-recursion.rs:7:1
- |
+...
LL | struct B<T> {
- | ^^^^^^^^^^^ recursive type has infinite size
-LL |
+ | ^^^^^^^^^^^
LL | z: A<T>
| ---- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `B` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
+ |
+LL ~ y: Box<B<T>>,
+LL | }
+LL |
+LL | struct B<T> {
+LL ~ z: Box<A<T>>
|
-LL | z: Box<A<T>>
- | ++++ +
-error[E0072]: recursive type `C` has infinite size
- --> $DIR/mutual-struct-recursion.rs:12:1
+error[E0072]: recursive types `C` and `D` have infinite size
+ --> $DIR/mutual-struct-recursion.rs:11:1
|
LL | struct C<T> {
- | ^^^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^^^
...
LL | y: Option<Option<D<T>>>,
- | -------------------- recursive without indirection
- |
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `C` representable
- |
-LL | y: Option<Box<Option<D<T>>>>,
- | ++++ +
-
-error[E0072]: recursive type `D` has infinite size
- --> $DIR/mutual-struct-recursion.rs:18:1
- |
+ | ---- recursive without indirection
+...
LL | struct D<T> {
- | ^^^^^^^^^^^ recursive type has infinite size
-LL |
+ | ^^^^^^^^^^^
LL | z: Option<Option<C<T>>>,
- | -------------------- recursive without indirection
+ | ---- recursive without indirection
+ |
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `D` representable
+LL ~ y: Option<Option<Box<D<T>>>>,
+LL | }
+LL |
+LL | struct D<T> {
+LL ~ z: Option<Option<Box<C<T>>>>,
|
-LL | z: Option<Box<Option<C<T>>>>,
- | ++++ +
-error: aborting due to 4 previous errors
+error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0072`.
diff --git a/src/test/ui/structs/incomplete-fn-in-struct-definition.rs b/src/test/ui/structs/incomplete-fn-in-struct-definition.rs
new file mode 100644
index 000000000..cd8a79ba6
--- /dev/null
+++ b/src/test/ui/structs/incomplete-fn-in-struct-definition.rs
@@ -0,0 +1,5 @@
+fn main() {}
+
+struct S {
+ fn: u8 //~ ERROR expected identifier, found keyword `fn`
+}
diff --git a/src/test/ui/structs/incomplete-fn-in-struct-definition.stderr b/src/test/ui/structs/incomplete-fn-in-struct-definition.stderr
new file mode 100644
index 000000000..0d12ba9c9
--- /dev/null
+++ b/src/test/ui/structs/incomplete-fn-in-struct-definition.stderr
@@ -0,0 +1,15 @@
+error: expected identifier, found keyword `fn`
+ --> $DIR/incomplete-fn-in-struct-definition.rs:4:5
+ |
+LL | struct S {
+ | - while parsing this struct
+LL | fn: u8
+ | ^^ expected identifier, found keyword
+ |
+help: escape `fn` to use it as an identifier
+ |
+LL | r#fn: u8
+ | ++
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/structs/struct-fn-in-definition.stderr b/src/test/ui/structs/struct-fn-in-definition.stderr
index 1d7cd5272..472365c6e 100644
--- a/src/test/ui/structs/struct-fn-in-definition.stderr
+++ b/src/test/ui/structs/struct-fn-in-definition.stderr
@@ -1,6 +1,9 @@
error: functions are not allowed in struct definitions
--> $DIR/struct-fn-in-definition.rs:9:5
|
+LL | struct S {
+ | - while parsing this struct
+...
LL | fn foo() {}
| ^^^^^^^^^^^
|
@@ -10,6 +13,9 @@ LL | fn foo() {}
error: functions are not allowed in union definitions
--> $DIR/struct-fn-in-definition.rs:18:5
|
+LL | union U {
+ | - while parsing this union
+...
LL | fn foo() {}
| ^^^^^^^^^^^
|
@@ -19,6 +25,9 @@ LL | fn foo() {}
error: functions are not allowed in enum definitions
--> $DIR/struct-fn-in-definition.rs:27:5
|
+LL | enum E {
+ | - while parsing this enum
+...
LL | fn foo() {}
| ^^^^^^^^^^^
|
diff --git a/src/test/ui/structs/struct-path-associated-type.rs b/src/test/ui/structs/struct-path-associated-type.rs
index f88572f84..2dd7174a9 100644
--- a/src/test/ui/structs/struct-path-associated-type.rs
+++ b/src/test/ui/structs/struct-path-associated-type.rs
@@ -13,7 +13,7 @@ fn f<T: Tr>() {
//~^ ERROR expected struct, variant or union type, found associated type
let z = T::A::<u8> {};
//~^ ERROR expected struct, variant or union type, found associated type
- //~| ERROR type arguments are not allowed on this type
+ //~| ERROR this associated type takes 0 generic arguments but 1 generic argument was supplied
match S {
T::A {} => {}
//~^ ERROR expected struct, variant or union type, found associated type
@@ -22,7 +22,7 @@ fn f<T: Tr>() {
fn g<T: Tr<A = S>>() {
let s = T::A {}; // OK
- let z = T::A::<u8> {}; //~ ERROR type arguments are not allowed on this type
+ let z = T::A::<u8> {}; //~ ERROR this associated type takes 0 generic arguments but 1 generic argument was supplied
match S {
T::A {} => {} // OK
}
diff --git a/src/test/ui/structs/struct-path-associated-type.stderr b/src/test/ui/structs/struct-path-associated-type.stderr
index bdce0e1b3..abb445214 100644
--- a/src/test/ui/structs/struct-path-associated-type.stderr
+++ b/src/test/ui/structs/struct-path-associated-type.stderr
@@ -4,13 +4,19 @@ error[E0071]: expected struct, variant or union type, found associated type
LL | let s = T::A {};
| ^^^^ not a struct
-error[E0109]: type arguments are not allowed on this type
- --> $DIR/struct-path-associated-type.rs:14:20
+error[E0107]: this associated type takes 0 generic arguments but 1 generic argument was supplied
+ --> $DIR/struct-path-associated-type.rs:14:16
|
LL | let z = T::A::<u8> {};
- | - ^^ type argument not allowed
+ | ^------ help: remove these generics
| |
- | not allowed on this type
+ | expected 0 generic arguments
+ |
+note: associated type defined here, with 0 generic parameters
+ --> $DIR/struct-path-associated-type.rs:4:10
+ |
+LL | type A;
+ | ^
error[E0071]: expected struct, variant or union type, found associated type
--> $DIR/struct-path-associated-type.rs:14:13
@@ -24,13 +30,19 @@ error[E0071]: expected struct, variant or union type, found associated type
LL | T::A {} => {}
| ^^^^ not a struct
-error[E0109]: type arguments are not allowed on this type
- --> $DIR/struct-path-associated-type.rs:25:20
+error[E0107]: this associated type takes 0 generic arguments but 1 generic argument was supplied
+ --> $DIR/struct-path-associated-type.rs:25:16
|
LL | let z = T::A::<u8> {};
- | - ^^ type argument not allowed
+ | ^------ help: remove these generics
| |
- | not allowed on this type
+ | expected 0 generic arguments
+ |
+note: associated type defined here, with 0 generic parameters
+ --> $DIR/struct-path-associated-type.rs:4:10
+ |
+LL | type A;
+ | ^
error[E0223]: ambiguous associated type
--> $DIR/struct-path-associated-type.rs:32:13
@@ -52,5 +64,5 @@ LL | S::A {} => {}
error: aborting due to 8 previous errors
-Some errors have detailed explanations: E0071, E0109, E0223.
+Some errors have detailed explanations: E0071, E0107, E0223.
For more information about an error, try `rustc --explain E0071`.
diff --git a/src/test/ui/suggestions/abi-typo.fixed b/src/test/ui/suggestions/abi-typo.fixed
new file mode 100644
index 000000000..04d265865
--- /dev/null
+++ b/src/test/ui/suggestions/abi-typo.fixed
@@ -0,0 +1,6 @@
+// run-rustfix
+extern "cdecl" fn cdedl() {} //~ ERROR invalid ABI
+
+fn main() {
+ cdedl();
+}
diff --git a/src/test/ui/suggestions/abi-typo.rs b/src/test/ui/suggestions/abi-typo.rs
new file mode 100644
index 000000000..6d80db522
--- /dev/null
+++ b/src/test/ui/suggestions/abi-typo.rs
@@ -0,0 +1,6 @@
+// run-rustfix
+extern "cdedl" fn cdedl() {} //~ ERROR invalid ABI
+
+fn main() {
+ cdedl();
+}
diff --git a/src/test/ui/suggestions/abi-typo.stderr b/src/test/ui/suggestions/abi-typo.stderr
new file mode 100644
index 000000000..67a84f119
--- /dev/null
+++ b/src/test/ui/suggestions/abi-typo.stderr
@@ -0,0 +1,14 @@
+error[E0703]: invalid ABI: found `cdedl`
+ --> $DIR/abi-typo.rs:2:8
+ |
+LL | extern "cdedl" fn cdedl() {}
+ | ^^^^^^^
+ | |
+ | invalid ABI
+ | help: did you mean: `"cdecl"`
+ |
+ = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions.
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0703`.
diff --git a/src/test/ui/suggestions/assoc_fn_without_self.stderr b/src/test/ui/suggestions/assoc_fn_without_self.stderr
index 4a0e62e73..88920b852 100644
--- a/src/test/ui/suggestions/assoc_fn_without_self.stderr
+++ b/src/test/ui/suggestions/assoc_fn_without_self.stderr
@@ -1,10 +1,4 @@
error[E0425]: cannot find function `foo` in this scope
- --> $DIR/assoc_fn_without_self.rs:14:13
- |
-LL | foo();
- | ^^^ not found in this scope
-
-error[E0425]: cannot find function `foo` in this scope
--> $DIR/assoc_fn_without_self.rs:16:9
|
LL | foo();
@@ -32,6 +26,12 @@ help: consider using the associated function
LL | Self::baz(2, 3);
| ~~~~~~~~~
+error[E0425]: cannot find function `foo` in this scope
+ --> $DIR/assoc_fn_without_self.rs:14:13
+ |
+LL | foo();
+ | ^^^ not found in this scope
+
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr b/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
index bfd506c9f..8ed62f854 100644
--- a/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
+++ b/src/test/ui/suggestions/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
@@ -1,9 +1,6 @@
error[E0277]: `fn() -> impl Future<Output = ()> {foo}` is not a future
--> $DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:10:9
|
-LL | async fn foo() {}
- | --- consider calling this function
-...
LL | bar(foo);
| --- ^^^ `fn() -> impl Future<Output = ()> {foo}` is not a future
| |
@@ -16,7 +13,7 @@ note: required by a bound in `bar`
|
LL | fn bar(f: impl Future<Output=()>) {}
| ^^^^^^^^^^^^^^^^^ required by this bound in `bar`
-help: use parentheses to call the function
+help: use parentheses to call this function
|
LL | bar(foo());
| ++
@@ -24,8 +21,6 @@ LL | bar(foo());
error[E0277]: `[closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:33]` is not a future
--> $DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:12:9
|
-LL | let async_closure = async || ();
- | -------- consider calling this closure
LL | bar(async_closure);
| --- ^^^^^^^^^^^^^ `[closure@$DIR/async-fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:11:25: 11:33]` is not a future
| |
@@ -38,7 +33,7 @@ note: required by a bound in `bar`
|
LL | fn bar(f: impl Future<Output=()>) {}
| ^^^^^^^^^^^^^^^^^ required by this bound in `bar`
-help: use parentheses to call the closure
+help: use parentheses to call this closure
|
LL | bar(async_closure());
| ++
diff --git a/src/test/ui/suggestions/boxed-variant-field.rs b/src/test/ui/suggestions/boxed-variant-field.rs
index e79be2f61..6050963c4 100644
--- a/src/test/ui/suggestions/boxed-variant-field.rs
+++ b/src/test/ui/suggestions/boxed-variant-field.rs
@@ -9,7 +9,6 @@ fn foo(x: Ty) -> Ty {
Ty::List(elem) => foo(elem),
//~^ ERROR mismatched types
//~| HELP consider unboxing the value
- //~| HELP try wrapping
}
}
diff --git a/src/test/ui/suggestions/boxed-variant-field.stderr b/src/test/ui/suggestions/boxed-variant-field.stderr
index 6dfb73480..9ae36a06a 100644
--- a/src/test/ui/suggestions/boxed-variant-field.stderr
+++ b/src/test/ui/suggestions/boxed-variant-field.stderr
@@ -17,10 +17,6 @@ help: consider unboxing the value
|
LL | Ty::List(elem) => foo(*elem),
| +
-help: try wrapping the expression in `Ty::List`
- |
-LL | Ty::List(elem) => foo(Ty::List(elem)),
- | +++++++++ +
error: aborting due to previous error
diff --git a/src/test/ui/suggestions/call-on-unimplemented-ctor.rs b/src/test/ui/suggestions/call-on-unimplemented-ctor.rs
new file mode 100644
index 000000000..5f811044e
--- /dev/null
+++ b/src/test/ui/suggestions/call-on-unimplemented-ctor.rs
@@ -0,0 +1,17 @@
+fn main() {
+ insert_resource(Marker);
+ insert_resource(Time);
+ //~^ ERROR the trait bound `fn(u32) -> Time {Time}: Resource` is not satisfied
+ //~| HELP use parentheses to construct this tuple struct
+}
+
+trait Resource {}
+
+fn insert_resource<R: Resource>(resource: R) {}
+
+struct Marker;
+impl Resource for Marker {}
+
+struct Time(u32);
+
+impl Resource for Time {}
diff --git a/src/test/ui/suggestions/call-on-unimplemented-ctor.stderr b/src/test/ui/suggestions/call-on-unimplemented-ctor.stderr
new file mode 100644
index 000000000..58612cbfb
--- /dev/null
+++ b/src/test/ui/suggestions/call-on-unimplemented-ctor.stderr
@@ -0,0 +1,21 @@
+error[E0277]: the trait bound `fn(u32) -> Time {Time}: Resource` is not satisfied
+ --> $DIR/call-on-unimplemented-ctor.rs:3:21
+ |
+LL | insert_resource(Time);
+ | --------------- ^^^^ the trait `Resource` is not implemented for fn item `fn(u32) -> Time {Time}`
+ | |
+ | required by a bound introduced by this call
+ |
+note: required by a bound in `insert_resource`
+ --> $DIR/call-on-unimplemented-ctor.rs:10:23
+ |
+LL | fn insert_resource<R: Resource>(resource: R) {}
+ | ^^^^^^^^ required by this bound in `insert_resource`
+help: use parentheses to construct this tuple struct
+ |
+LL | insert_resource(Time(/* u32 */));
+ | +++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/suggestions/call-on-unimplemented-fn-ptr.rs b/src/test/ui/suggestions/call-on-unimplemented-fn-ptr.rs
new file mode 100644
index 000000000..86490c724
--- /dev/null
+++ b/src/test/ui/suggestions/call-on-unimplemented-fn-ptr.rs
@@ -0,0 +1,15 @@
+struct Foo;
+
+trait Bar {}
+
+impl Bar for Foo {}
+
+fn needs_bar<T: Bar>(_: T) {}
+
+fn blah(f: fn() -> Foo) {
+ needs_bar(f);
+ //~^ ERROR the trait bound `fn() -> Foo: Bar` is not satisfied
+ //~| HELP use parentheses to call this function pointer
+}
+
+fn main() {}
diff --git a/src/test/ui/suggestions/call-on-unimplemented-fn-ptr.stderr b/src/test/ui/suggestions/call-on-unimplemented-fn-ptr.stderr
new file mode 100644
index 000000000..167f7e592
--- /dev/null
+++ b/src/test/ui/suggestions/call-on-unimplemented-fn-ptr.stderr
@@ -0,0 +1,21 @@
+error[E0277]: the trait bound `fn() -> Foo: Bar` is not satisfied
+ --> $DIR/call-on-unimplemented-fn-ptr.rs:10:15
+ |
+LL | needs_bar(f);
+ | --------- ^ the trait `Bar` is not implemented for `fn() -> Foo`
+ | |
+ | required by a bound introduced by this call
+ |
+note: required by a bound in `needs_bar`
+ --> $DIR/call-on-unimplemented-fn-ptr.rs:7:17
+ |
+LL | fn needs_bar<T: Bar>(_: T) {}
+ | ^^^ required by this bound in `needs_bar`
+help: use parentheses to call this function pointer
+ |
+LL | needs_bar(f());
+ | ++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr b/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
index fe603b675..955148315 100644
--- a/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
+++ b/src/test/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr
@@ -1,9 +1,6 @@
error[E0277]: the trait bound `fn() -> impl T<O = ()> {foo}: T` is not satisfied
--> $DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:17:9
|
-LL | fn foo() -> impl T<O=()> { S }
- | --- consider calling this function
-...
LL | bar(foo);
| --- ^^^ the trait `T` is not implemented for fn item `fn() -> impl T<O = ()> {foo}`
| |
@@ -14,7 +11,7 @@ note: required by a bound in `bar`
|
LL | fn bar(f: impl T<O=()>) {}
| ^^^^^^^ required by this bound in `bar`
-help: use parentheses to call the function
+help: use parentheses to call this function
|
LL | bar(foo());
| ++
@@ -22,8 +19,6 @@ LL | bar(foo());
error[E0277]: the trait bound `[closure@$DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:18:19: 18:21]: T` is not satisfied
--> $DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:19:9
|
-LL | let closure = || S;
- | -- consider calling this closure
LL | bar(closure);
| --- ^^^^^^^ the trait `T` is not implemented for closure `[closure@$DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:18:19: 18:21]`
| |
@@ -34,7 +29,7 @@ note: required by a bound in `bar`
|
LL | fn bar(f: impl T<O=()>) {}
| ^^^^^^^ required by this bound in `bar`
-help: use parentheses to call the closure
+help: use parentheses to call this closure
|
LL | bar(closure());
| ++
diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr
index 3c7b895e3..597dc61c3 100644
--- a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr
+++ b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr
@@ -49,7 +49,7 @@ LL | let _: S = S;
|
= note: expected struct `S`
found fn item `fn(usize, usize) -> S {S}`
-help: use parentheses to instantiate this tuple struct
+help: use parentheses to construct this tuple struct
|
LL | let _: S = S(/* usize */, /* usize */);
| ++++++++++++++++++++++++++
@@ -85,7 +85,7 @@ LL | let _: V = V;
|
= note: expected struct `V`
found fn item `fn() -> V {V}`
-help: use parentheses to instantiate this tuple struct
+help: use parentheses to construct this tuple struct
|
LL | let _: V = V();
| ++
@@ -139,7 +139,7 @@ LL | let _: E = E::A;
|
= note: expected enum `E`
found fn item `fn(usize) -> E {E::A}`
-help: use parentheses to instantiate this tuple variant
+help: use parentheses to construct this tuple variant
|
LL | let _: E = E::A(/* usize */);
| +++++++++++++
@@ -220,7 +220,7 @@ error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:41:20
|
LL | fn ban(&self) -> usize { 42 }
- | ---------------------- for<'r> fn(&'r X) -> usize {<X as T>::ban} defined here
+ | ---------------------- for<'a> fn(&'a X) -> usize {<X as T>::ban} defined here
...
LL | let _: usize = X::ban;
| ----- ^^^^^^ expected `usize`, found fn item
@@ -228,7 +228,7 @@ LL | let _: usize = X::ban;
| expected due to this
|
= note: expected type `usize`
- found fn item `for<'r> fn(&'r X) -> usize {<X as T>::ban}`
+ found fn item `for<'a> fn(&'a X) -> usize {<X as T>::ban}`
help: use parentheses to call this associated function
|
LL | let _: usize = X::ban(/* &X */);
@@ -238,7 +238,7 @@ error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:42:20
|
LL | fn bal(&self) -> usize;
- | ----------------------- for<'r> fn(&'r X) -> usize {<X as T>::bal} defined here
+ | ----------------------- for<'a> fn(&'a X) -> usize {<X as T>::bal} defined here
...
LL | let _: usize = X::bal;
| ----- ^^^^^^ expected `usize`, found fn item
@@ -246,7 +246,7 @@ LL | let _: usize = X::bal;
| expected due to this
|
= note: expected type `usize`
- found fn item `for<'r> fn(&'r X) -> usize {<X as T>::bal}`
+ found fn item `for<'a> fn(&'a X) -> usize {<X as T>::bal}`
help: use parentheses to call this associated function
|
LL | let _: usize = X::bal(/* &X */);
diff --git a/src/test/ui/suggestions/fn-to-method.rs b/src/test/ui/suggestions/fn-to-method.rs
new file mode 100644
index 000000000..9a35c3efc
--- /dev/null
+++ b/src/test/ui/suggestions/fn-to-method.rs
@@ -0,0 +1,19 @@
+struct Foo;
+
+impl Foo {
+ fn bar(self) {}
+}
+
+fn main() {
+ let x = cmp(&1, &2);
+ //~^ ERROR cannot find function `cmp` in this scope
+ //~| HELP use the `.` operator to call the method `Ord::cmp` on `&{integer}`
+
+ let y = len([1, 2, 3]);
+ //~^ ERROR cannot find function `len` in this scope
+ //~| HELP use the `.` operator to call the method `len` on `&[{integer}]`
+
+ let z = bar(Foo);
+ //~^ ERROR cannot find function `bar` in this scope
+ //~| HELP use the `.` operator to call the method `bar` on `Foo`
+}
diff --git a/src/test/ui/suggestions/fn-to-method.stderr b/src/test/ui/suggestions/fn-to-method.stderr
new file mode 100644
index 000000000..36c17e60d
--- /dev/null
+++ b/src/test/ui/suggestions/fn-to-method.stderr
@@ -0,0 +1,38 @@
+error[E0425]: cannot find function `cmp` in this scope
+ --> $DIR/fn-to-method.rs:8:13
+ |
+LL | let x = cmp(&1, &2);
+ | ^^^ not found in this scope
+ |
+help: use the `.` operator to call the method `Ord::cmp` on `&{integer}`
+ |
+LL | let x = (&1).cmp(&2);
+ | ~ ~~~~~~~~~
+
+error[E0425]: cannot find function `len` in this scope
+ --> $DIR/fn-to-method.rs:12:13
+ |
+LL | let y = len([1, 2, 3]);
+ | ^^^ not found in this scope
+ |
+help: use the `.` operator to call the method `len` on `&[{integer}]`
+ |
+LL - let y = len([1, 2, 3]);
+LL + let y = [1, 2, 3].len();
+ |
+
+error[E0425]: cannot find function `bar` in this scope
+ --> $DIR/fn-to-method.rs:16:13
+ |
+LL | let z = bar(Foo);
+ | ^^^ not found in this scope
+ |
+help: use the `.` operator to call the method `bar` on `Foo`
+ |
+LL - let z = bar(Foo);
+LL + let z = Foo.bar();
+ |
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/suggestions/format-borrow.stderr b/src/test/ui/suggestions/format-borrow.stderr
index fac6a5a5f..8ed2b9c9a 100644
--- a/src/test/ui/suggestions/format-borrow.stderr
+++ b/src/test/ui/suggestions/format-borrow.stderr
@@ -11,6 +11,10 @@ help: consider removing the borrow
LL - let a: String = &String::from("a");
LL + let a: String = String::from("a");
|
+help: alternatively, consider changing the type annotation
+ |
+LL | let a: &String = &String::from("a");
+ | +
error[E0308]: mismatched types
--> $DIR/format-borrow.rs:4:21
@@ -25,6 +29,10 @@ help: consider removing the borrow
LL - let b: String = &format!("b");
LL + let b: String = format!("b");
|
+help: alternatively, consider changing the type annotation
+ |
+LL | let b: &String = &format!("b");
+ | +
error[E0308]: mismatched types
--> $DIR/format-borrow.rs:6:21
@@ -39,6 +47,10 @@ help: consider removing the borrow
LL - let c: String = &mut format!("c");
LL + let c: String = format!("c");
|
+help: alternatively, consider changing the type annotation
+ |
+LL | let c: &mut String = &mut format!("c");
+ | ++++
error[E0308]: mismatched types
--> $DIR/format-borrow.rs:8:21
@@ -53,6 +65,10 @@ help: consider removing the borrow
LL - let d: String = &mut (format!("d"));
LL + let d: String = format!("d"));
|
+help: alternatively, consider changing the type annotation
+ |
+LL | let d: &mut String = &mut (format!("d"));
+ | ++++
error: aborting due to 4 previous errors
diff --git a/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr b/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr
index e82a6f769..9833da13f 100644
--- a/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr
+++ b/src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr
@@ -26,17 +26,25 @@ error[E0658]: anonymous lifetimes in `impl Trait` are unstable
--> $DIR/impl-trait-missing-lifetime-gated.rs:5:31
|
LL | fn f(_: impl Iterator<Item = &'_ ()>) {}
- | ^^
+ | ^^ expected named lifetime parameter
|
= help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable
+help: consider introducing a named lifetime parameter
+ |
+LL | fn f<'a>(_: impl Iterator<Item = &'_'a ()>) {}
+ | ++++ ++
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
--> $DIR/impl-trait-missing-lifetime-gated.rs:8:31
|
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
- | ^^
+ | ^^ expected named lifetime parameter
|
= help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable
+help: consider introducing a named lifetime parameter
+ |
+LL | fn g<'a>(x: impl Iterator<Item = &'_'a ()>) -> Option<&'_ ()> { x.next() }
+ | ++++ ++
error: aborting due to 4 previous errors
diff --git a/src/test/ui/suggestions/inner_type.fixed b/src/test/ui/suggestions/inner_type.fixed
new file mode 100644
index 000000000..7af7391ca
--- /dev/null
+++ b/src/test/ui/suggestions/inner_type.fixed
@@ -0,0 +1,40 @@
+// compile-flags: --edition=2021
+// run-rustfix
+
+pub struct Struct<T> {
+ pub p: T,
+}
+
+impl<T> Struct<T> {
+ pub fn method(&self) {}
+
+ pub fn some_mutable_method(&mut self) {}
+}
+
+fn main() {
+ let other_item = std::cell::RefCell::new(Struct { p: 42_u32 });
+
+ other_item.borrow().method();
+ //~^ ERROR no method named `method` found for struct `RefCell` in the current scope [E0599]
+ //~| HELP use `.borrow()` to borrow the `Struct<u32>`, panicking if a mutable borrow exists
+
+ other_item.borrow_mut().some_mutable_method();
+ //~^ ERROR no method named `some_mutable_method` found for struct `RefCell` in the current scope [E0599]
+ //~| HELP .borrow_mut()` to mutably borrow the `Struct<u32>`, panicking if any borrows exist
+
+ let another_item = std::sync::Mutex::new(Struct { p: 42_u32 });
+
+ another_item.lock().unwrap().method();
+ //~^ ERROR no method named `method` found for struct `Mutex` in the current scope [E0599]
+ //~| HELP use `.lock().unwrap()` to borrow the `Struct<u32>`, blocking the current thread until it can be acquired
+
+ let another_item = std::sync::RwLock::new(Struct { p: 42_u32 });
+
+ another_item.read().unwrap().method();
+ //~^ ERROR no method named `method` found for struct `RwLock` in the current scope [E0599]
+ //~| HELP use `.read().unwrap()` to borrow the `Struct<u32>`, blocking the current thread until it can be acquired
+
+ another_item.write().unwrap().some_mutable_method();
+ //~^ ERROR no method named `some_mutable_method` found for struct `RwLock` in the current scope [E0599]
+ //~| HELP use `.write().unwrap()` to mutably borrow the `Struct<u32>`, blocking the current thread until it can be acquired
+}
diff --git a/src/test/ui/suggestions/inner_type.rs b/src/test/ui/suggestions/inner_type.rs
new file mode 100644
index 000000000..4aca50716
--- /dev/null
+++ b/src/test/ui/suggestions/inner_type.rs
@@ -0,0 +1,40 @@
+// compile-flags: --edition=2021
+// run-rustfix
+
+pub struct Struct<T> {
+ pub p: T,
+}
+
+impl<T> Struct<T> {
+ pub fn method(&self) {}
+
+ pub fn some_mutable_method(&mut self) {}
+}
+
+fn main() {
+ let other_item = std::cell::RefCell::new(Struct { p: 42_u32 });
+
+ other_item.method();
+ //~^ ERROR no method named `method` found for struct `RefCell` in the current scope [E0599]
+ //~| HELP use `.borrow()` to borrow the `Struct<u32>`, panicking if a mutable borrow exists
+
+ other_item.some_mutable_method();
+ //~^ ERROR no method named `some_mutable_method` found for struct `RefCell` in the current scope [E0599]
+ //~| HELP .borrow_mut()` to mutably borrow the `Struct<u32>`, panicking if any borrows exist
+
+ let another_item = std::sync::Mutex::new(Struct { p: 42_u32 });
+
+ another_item.method();
+ //~^ ERROR no method named `method` found for struct `Mutex` in the current scope [E0599]
+ //~| HELP use `.lock().unwrap()` to borrow the `Struct<u32>`, blocking the current thread until it can be acquired
+
+ let another_item = std::sync::RwLock::new(Struct { p: 42_u32 });
+
+ another_item.method();
+ //~^ ERROR no method named `method` found for struct `RwLock` in the current scope [E0599]
+ //~| HELP use `.read().unwrap()` to borrow the `Struct<u32>`, blocking the current thread until it can be acquired
+
+ another_item.some_mutable_method();
+ //~^ ERROR no method named `some_mutable_method` found for struct `RwLock` in the current scope [E0599]
+ //~| HELP use `.write().unwrap()` to mutably borrow the `Struct<u32>`, blocking the current thread until it can be acquired
+}
diff --git a/src/test/ui/suggestions/inner_type.stderr b/src/test/ui/suggestions/inner_type.stderr
new file mode 100644
index 000000000..5ac3d04f1
--- /dev/null
+++ b/src/test/ui/suggestions/inner_type.stderr
@@ -0,0 +1,83 @@
+error[E0599]: no method named `method` found for struct `RefCell` in the current scope
+ --> $DIR/inner_type.rs:17:16
+ |
+LL | other_item.method();
+ | ^^^^^^ method not found in `RefCell<Struct<u32>>`
+ |
+note: the method `method` exists on the type `Struct<u32>`
+ --> $DIR/inner_type.rs:9:5
+ |
+LL | pub fn method(&self) {}
+ | ^^^^^^^^^^^^^^^^^^^^
+help: use `.borrow()` to borrow the `Struct<u32>`, panicking if a mutable borrow exists
+ |
+LL | other_item.borrow().method();
+ | +++++++++
+
+error[E0599]: no method named `some_mutable_method` found for struct `RefCell` in the current scope
+ --> $DIR/inner_type.rs:21:16
+ |
+LL | other_item.some_mutable_method();
+ | ^^^^^^^^^^^^^^^^^^^ method not found in `RefCell<Struct<u32>>`
+ |
+note: the method `some_mutable_method` exists on the type `Struct<u32>`
+ --> $DIR/inner_type.rs:11:5
+ |
+LL | pub fn some_mutable_method(&mut self) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: use `.borrow_mut()` to mutably borrow the `Struct<u32>`, panicking if any borrows exist
+ |
+LL | other_item.borrow_mut().some_mutable_method();
+ | +++++++++++++
+
+error[E0599]: no method named `method` found for struct `Mutex` in the current scope
+ --> $DIR/inner_type.rs:27:18
+ |
+LL | another_item.method();
+ | ^^^^^^ method not found in `Mutex<Struct<u32>>`
+ |
+note: the method `method` exists on the type `Struct<u32>`
+ --> $DIR/inner_type.rs:9:5
+ |
+LL | pub fn method(&self) {}
+ | ^^^^^^^^^^^^^^^^^^^^
+help: use `.lock().unwrap()` to borrow the `Struct<u32>`, blocking the current thread until it can be acquired
+ |
+LL | another_item.lock().unwrap().method();
+ | ++++++++++++++++
+
+error[E0599]: no method named `method` found for struct `RwLock` in the current scope
+ --> $DIR/inner_type.rs:33:18
+ |
+LL | another_item.method();
+ | ^^^^^^ method not found in `RwLock<Struct<u32>>`
+ |
+note: the method `method` exists on the type `Struct<u32>`
+ --> $DIR/inner_type.rs:9:5
+ |
+LL | pub fn method(&self) {}
+ | ^^^^^^^^^^^^^^^^^^^^
+help: use `.read().unwrap()` to borrow the `Struct<u32>`, blocking the current thread until it can be acquired
+ |
+LL | another_item.read().unwrap().method();
+ | ++++++++++++++++
+
+error[E0599]: no method named `some_mutable_method` found for struct `RwLock` in the current scope
+ --> $DIR/inner_type.rs:37:18
+ |
+LL | another_item.some_mutable_method();
+ | ^^^^^^^^^^^^^^^^^^^ method not found in `RwLock<Struct<u32>>`
+ |
+note: the method `some_mutable_method` exists on the type `Struct<u32>`
+ --> $DIR/inner_type.rs:11:5
+ |
+LL | pub fn some_mutable_method(&mut self) {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+help: use `.write().unwrap()` to mutably borrow the `Struct<u32>`, blocking the current thread until it can be acquired
+ |
+LL | another_item.write().unwrap().some_mutable_method();
+ | +++++++++++++++++
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/suggestions/inner_type2.rs b/src/test/ui/suggestions/inner_type2.rs
new file mode 100644
index 000000000..c56ea7c03
--- /dev/null
+++ b/src/test/ui/suggestions/inner_type2.rs
@@ -0,0 +1,26 @@
+pub struct Struct<T> {
+ pub p: T,
+}
+
+impl<T> Struct<T> {
+ pub fn method(&self) {}
+
+ pub fn some_mutable_method(&mut self) {}
+}
+
+thread_local! {
+ static STRUCT: Struct<u32> = Struct {
+ p: 42_u32
+ };
+}
+
+fn main() {
+ STRUCT.method();
+ //~^ ERROR no method named `method` found for struct `LocalKey` in the current scope [E0599]
+ //~| HELP use `with` or `try_with` to access thread local storage
+
+ let item = std::mem::MaybeUninit::new(Struct { p: 42_u32 });
+ item.method();
+ //~^ ERROR no method named `method` found for union `MaybeUninit` in the current scope [E0599]
+ //~| HELP if this `MaybeUninit::<Struct<u32>>` has been initialized, use one of the `assume_init` methods to access the inner value
+}
diff --git a/src/test/ui/suggestions/inner_type2.stderr b/src/test/ui/suggestions/inner_type2.stderr
new file mode 100644
index 000000000..eddfd9d63
--- /dev/null
+++ b/src/test/ui/suggestions/inner_type2.stderr
@@ -0,0 +1,29 @@
+error[E0599]: no method named `method` found for struct `LocalKey` in the current scope
+ --> $DIR/inner_type2.rs:18:12
+ |
+LL | STRUCT.method();
+ | ^^^^^^ method not found in `LocalKey<Struct<u32>>`
+ |
+ = help: use `with` or `try_with` to access thread local storage
+note: the method `method` exists on the type `Struct<u32>`
+ --> $DIR/inner_type2.rs:6:5
+ |
+LL | pub fn method(&self) {}
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error[E0599]: no method named `method` found for union `MaybeUninit` in the current scope
+ --> $DIR/inner_type2.rs:23:10
+ |
+LL | item.method();
+ | ^^^^^^ method not found in `MaybeUninit<Struct<u32>>`
+ |
+ = help: if this `MaybeUninit::<Struct<u32>>` has been initialized, use one of the `assume_init` methods to access the inner value
+note: the method `method` exists on the type `Struct<u32>`
+ --> $DIR/inner_type2.rs:6:5
+ |
+LL | pub fn method(&self) {}
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/suggestions/into-convert.rs b/src/test/ui/suggestions/into-convert.rs
new file mode 100644
index 000000000..1c9a9e0aa
--- /dev/null
+++ b/src/test/ui/suggestions/into-convert.rs
@@ -0,0 +1,26 @@
+use std::path::{Path, PathBuf};
+use std::sync::atomic::AtomicU32;
+use std::sync::Arc;
+
+fn main() {
+ let x: A = B;
+ //~^ ERROR mismatched types
+ //~| HELP call `Into::into` on this expression to convert `B` into `A`
+
+ let y: Arc<Path> = PathBuf::new();
+ //~^ ERROR mismatched types
+ //~| HELP call `Into::into` on this expression to convert `PathBuf` into `Arc<Path>`
+
+ let z: AtomicU32 = 1;
+ //~^ ERROR mismatched types
+ //~| HELP call `Into::into` on this expression to convert `{integer}` into `AtomicU32`
+}
+
+struct A;
+struct B;
+
+impl From<B> for A {
+ fn from(_: B) -> Self {
+ A
+ }
+}
diff --git a/src/test/ui/suggestions/into-convert.stderr b/src/test/ui/suggestions/into-convert.stderr
new file mode 100644
index 000000000..d43104a21
--- /dev/null
+++ b/src/test/ui/suggestions/into-convert.stderr
@@ -0,0 +1,44 @@
+error[E0308]: mismatched types
+ --> $DIR/into-convert.rs:6:16
+ |
+LL | let x: A = B;
+ | - ^ expected struct `A`, found struct `B`
+ | |
+ | expected due to this
+ |
+help: call `Into::into` on this expression to convert `B` into `A`
+ |
+LL | let x: A = B.into();
+ | +++++++
+
+error[E0308]: mismatched types
+ --> $DIR/into-convert.rs:10:24
+ |
+LL | let y: Arc<Path> = PathBuf::new();
+ | --------- ^^^^^^^^^^^^^^ expected struct `Arc`, found struct `PathBuf`
+ | |
+ | expected due to this
+ |
+ = note: expected struct `Arc<Path>`
+ found struct `PathBuf`
+help: call `Into::into` on this expression to convert `PathBuf` into `Arc<Path>`
+ |
+LL | let y: Arc<Path> = PathBuf::new().into();
+ | +++++++
+
+error[E0308]: mismatched types
+ --> $DIR/into-convert.rs:14:24
+ |
+LL | let z: AtomicU32 = 1;
+ | --------- ^ expected struct `AtomicU32`, found integer
+ | |
+ | expected due to this
+ |
+help: call `Into::into` on this expression to convert `{integer}` into `AtomicU32`
+ |
+LL | let z: AtomicU32 = 1.into();
+ | +++++++
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/suggestions/issue-101065.fixed b/src/test/ui/suggestions/issue-101065.fixed
new file mode 100644
index 000000000..88c716cc8
--- /dev/null
+++ b/src/test/ui/suggestions/issue-101065.fixed
@@ -0,0 +1,14 @@
+// check-fail
+// run-rustfix
+
+enum FakeResult<T> {
+ Ok(T)
+}
+
+fn main() {
+ let _x = if true {
+ FakeResult::Ok(FakeResult::Ok(()))
+ } else {
+ FakeResult::Ok(FakeResult::Ok(())) //~ERROR E0308
+ };
+}
diff --git a/src/test/ui/suggestions/issue-101065.rs b/src/test/ui/suggestions/issue-101065.rs
new file mode 100644
index 000000000..2715f1027
--- /dev/null
+++ b/src/test/ui/suggestions/issue-101065.rs
@@ -0,0 +1,14 @@
+// check-fail
+// run-rustfix
+
+enum FakeResult<T> {
+ Ok(T)
+}
+
+fn main() {
+ let _x = if true {
+ FakeResult::Ok(FakeResult::Ok(()))
+ } else {
+ FakeResult::Ok(()) //~ERROR E0308
+ };
+}
diff --git a/src/test/ui/suggestions/issue-101065.stderr b/src/test/ui/suggestions/issue-101065.stderr
new file mode 100644
index 000000000..6f7ecd24c
--- /dev/null
+++ b/src/test/ui/suggestions/issue-101065.stderr
@@ -0,0 +1,23 @@
+error[E0308]: `if` and `else` have incompatible types
+ --> $DIR/issue-101065.rs:12:9
+ |
+LL | let _x = if true {
+ | ______________-
+LL | | FakeResult::Ok(FakeResult::Ok(()))
+ | | ---------------------------------- expected because of this
+LL | | } else {
+LL | | FakeResult::Ok(())
+ | | ^^^^^^^^^^^^^^^^^^ expected enum `FakeResult`, found `()`
+LL | | };
+ | |_____- `if` and `else` have incompatible types
+ |
+ = note: expected enum `FakeResult<FakeResult<()>>`
+ found enum `FakeResult<()>`
+help: try wrapping the expression in `FakeResult::Ok`
+ |
+LL | FakeResult::Ok(FakeResult::Ok(()))
+ | +++++++++++++++ +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/suggestions/issue-101623.rs b/src/test/ui/suggestions/issue-101623.rs
new file mode 100644
index 000000000..d18a4a21f
--- /dev/null
+++ b/src/test/ui/suggestions/issue-101623.rs
@@ -0,0 +1,25 @@
+pub struct Stuff {
+ inner: *mut (),
+}
+
+pub struct Wrap<T>(T);
+
+fn fun<T>(t: T) -> Wrap<T> {
+ todo!()
+}
+
+pub trait Trait<'de> {
+ fn do_stuff(_: Wrap<&'de mut Self>);
+}
+
+impl<'a> Trait<'a> for () {
+ fn do_stuff(_: Wrap<&'a mut Self>) {}
+}
+
+fn fun2(t: &mut Stuff) -> () {
+ let Stuff { inner, .. } = t;
+ Trait::do_stuff({ fun(&mut *inner) });
+ //~^ ERROR the trait bound `*mut (): Trait<'_>` is not satisfied
+}
+
+fn main() {}
diff --git a/src/test/ui/suggestions/issue-101623.stderr b/src/test/ui/suggestions/issue-101623.stderr
new file mode 100644
index 000000000..361483cc0
--- /dev/null
+++ b/src/test/ui/suggestions/issue-101623.stderr
@@ -0,0 +1,14 @@
+error[E0277]: the trait bound `*mut (): Trait<'_>` is not satisfied
+ --> $DIR/issue-101623.rs:21:21
+ |
+LL | Trait::do_stuff({ fun(&mut *inner) });
+ | --------------- ^^----------------^^
+ | | |
+ | | the trait `Trait<'_>` is not implemented for `*mut ()`
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Trait<'a>` is implemented for `()`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/suggestions/issue-101984.stderr b/src/test/ui/suggestions/issue-101984.stderr
index c744c62d1..81758a700 100644
--- a/src/test/ui/suggestions/issue-101984.stderr
+++ b/src/test/ui/suggestions/issue-101984.stderr
@@ -2,11 +2,11 @@ error[E0308]: mismatched types
--> $DIR/issue-101984.rs:21:13
|
LL | let (cmp, router) = self.router.at()?;
- | ^^^^^^^^^^^^^ ----------------- this expression has type `Match<&(for<'r> fn(&'r ()), Box<Wrapper>)>`
+ | ^^^^^^^^^^^^^ ----------------- this expression has type `Match<&(for<'a> fn(&'a ()), Box<Wrapper>)>`
| |
| expected struct `Match`, found tuple
|
- = note: expected struct `Match<&(for<'r> fn(&'r ()), Box<Wrapper>)>`
+ = note: expected struct `Match<&(for<'a> fn(&'a ()), Box<Wrapper>)>`
found tuple `(_, _)`
error: aborting due to previous error
diff --git a/src/test/ui/suggestions/issue-102354.rs b/src/test/ui/suggestions/issue-102354.rs
new file mode 100644
index 000000000..f881feb00
--- /dev/null
+++ b/src/test/ui/suggestions/issue-102354.rs
@@ -0,0 +1,10 @@
+trait Trait {
+ fn func() {}
+}
+
+impl Trait for i32 {}
+
+fn main() {
+ let x: i32 = 123;
+ x.func(); //~ERROR no method
+}
diff --git a/src/test/ui/suggestions/issue-102354.stderr b/src/test/ui/suggestions/issue-102354.stderr
new file mode 100644
index 000000000..4f76c5f2e
--- /dev/null
+++ b/src/test/ui/suggestions/issue-102354.stderr
@@ -0,0 +1,24 @@
+error[E0599]: no method named `func` found for type `i32` in the current scope
+ --> $DIR/issue-102354.rs:9:7
+ |
+LL | x.func();
+ | ^^^^ this is an associated function, not a method
+ |
+ = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
+note: the candidate is defined in the trait `Trait`
+ --> $DIR/issue-102354.rs:2:5
+ |
+LL | fn func() {}
+ | ^^^^^^^^^
+help: use associated function syntax instead
+ |
+LL | i32::func();
+ | ~~~~~~~~~
+help: disambiguate the associated function for the candidate
+ |
+LL | <i32 as Trait>::func(x);
+ | ~~~~~~~~~~~~~~~~~~~~~~~
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/suggestions/issue-102892.rs b/src/test/ui/suggestions/issue-102892.rs
new file mode 100644
index 000000000..c1a791d8d
--- /dev/null
+++ b/src/test/ui/suggestions/issue-102892.rs
@@ -0,0 +1,25 @@
+#![allow(dead_code, unused_variables)]
+
+use std::sync::Arc;
+
+#[derive(Debug)]
+struct A;
+#[derive(Debug)]
+struct B;
+
+fn process_without_annot(arc: &Arc<(A, B)>) {
+ let (a, b) = **arc; // suggests putting `&**arc` here; with that, fixed!
+}
+
+fn process_with_annot(arc: &Arc<(A, B)>) {
+ let (a, b): (A, B) = &**arc; // suggests putting `&**arc` here too
+ //~^ ERROR mismatched types
+}
+
+fn process_with_tuple_annot(mutation: &mut (A, B), arc: &Arc<(A, B)>) {
+ let (a, b): ((A, B), A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too
+ //~^ ERROR mismatched types
+ //~| ERROR mismatched types
+}
+
+fn main() {}
diff --git a/src/test/ui/suggestions/issue-102892.stderr b/src/test/ui/suggestions/issue-102892.stderr
new file mode 100644
index 000000000..a3dbc7cb8
--- /dev/null
+++ b/src/test/ui/suggestions/issue-102892.stderr
@@ -0,0 +1,57 @@
+error[E0308]: mismatched types
+ --> $DIR/issue-102892.rs:15:26
+ |
+LL | let (a, b): (A, B) = &**arc; // suggests putting `&**arc` here too
+ | ------ ^^^^^^ expected tuple, found `&(A, B)`
+ | |
+ | expected due to this
+ |
+ = note: expected tuple `(A, B)`
+ found reference `&(A, B)`
+help: consider removing the borrow
+ |
+LL - let (a, b): (A, B) = &**arc; // suggests putting `&**arc` here too
+LL + let (a, b): (A, B) = **arc; // suggests putting `&**arc` here too
+ |
+help: alternatively, consider changing the type annotation
+ |
+LL | let (a, b): &(A, B) = &**arc; // suggests putting `&**arc` here too
+ | +
+
+error[E0308]: mismatched types
+ --> $DIR/issue-102892.rs:20:32
+ |
+LL | let (a, b): ((A, B), A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too
+ | ^^^^^^^^^^^^^^ expected tuple, found `&mut (A, B)`
+ |
+ = note: expected tuple `(A, B)`
+ found mutable reference `&mut (A, B)`
+help: consider removing the borrow
+ |
+LL - let (a, b): ((A, B), A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too
+LL + let (a, b): ((A, B), A) = (*mutation, &(**arc).0); // suggests putting `&**arc` here too
+ |
+help: alternatively, consider changing the type annotation
+ |
+LL | let (a, b): (&mut (A, B), A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too
+ | ++++
+
+error[E0308]: mismatched types
+ --> $DIR/issue-102892.rs:20:48
+ |
+LL | let (a, b): ((A, B), A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too
+ | ^^^^^^^^^^ expected struct `A`, found `&A`
+ |
+help: consider removing the borrow
+ |
+LL - let (a, b): ((A, B), A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too
+LL + let (a, b): ((A, B), A) = (&mut *mutation, (**arc).0); // suggests putting `&**arc` here too
+ |
+help: alternatively, consider changing the type annotation
+ |
+LL | let (a, b): ((A, B), &A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too
+ | +
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/suggestions/issue-103112.rs b/src/test/ui/suggestions/issue-103112.rs
new file mode 100644
index 000000000..111ae7c73
--- /dev/null
+++ b/src/test/ui/suggestions/issue-103112.rs
@@ -0,0 +1,4 @@
+fn main() {
+ std::process::abort!();
+ //~^ ERROR: failed to resolve
+}
diff --git a/src/test/ui/suggestions/issue-103112.stderr b/src/test/ui/suggestions/issue-103112.stderr
new file mode 100644
index 000000000..4ca7fdf9b
--- /dev/null
+++ b/src/test/ui/suggestions/issue-103112.stderr
@@ -0,0 +1,15 @@
+error[E0433]: failed to resolve: could not find `abort` in `process`
+ --> $DIR/issue-103112.rs:2:19
+ |
+LL | std::process::abort!();
+ | ^^^^^ could not find `abort` in `process`
+ |
+help: std::process::abort is not a macro, but a function, try to remove `!`
+ |
+LL - std::process::abort!();
+LL + std::process::abort();
+ |
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0433`.
diff --git a/src/test/ui/suggestions/issue-61963.stderr b/src/test/ui/suggestions/issue-61963.stderr
index a788cab6e..b99b1b0b9 100644
--- a/src/test/ui/suggestions/issue-61963.stderr
+++ b/src/test/ui/suggestions/issue-61963.stderr
@@ -4,13 +4,13 @@ error: trait objects without an explicit `dyn` are deprecated
LL | bar: Box<Bar>,
| ^^^
|
+ = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
+ = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
note: the lint level is defined here
--> $DIR/issue-61963.rs:3:9
|
LL | #![deny(bare_trait_objects)]
| ^^^^^^^^^^^^^^^^^^
- = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
- = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: use `dyn`
|
LL | bar: Box<dyn Bar>,
diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr
index e5d2ead6a..872263fd7 100644
--- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr
+++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr
@@ -27,3 +27,4 @@ LL | fn func<'a, T: Test + 'a>(foo: &Foo, t: T) {
error: aborting due to previous error
+For more information about this error, try `rustc --explain E0311`.
diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr
index ed1b91676..fa758bf05 100644
--- a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr
+++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature.stderr
@@ -18,7 +18,7 @@ LL | | *dest = g.get();
LL | | }
| |_____^
|
-help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound
+help: to declare that `impl FnOnce()` captures `'_`, you can add an explicit `'_` lifetime bound
|
LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
| ++++
@@ -164,5 +164,5 @@ LL | G: Get<T> + 'a,
error: aborting due to 8 previous errors
-Some errors have detailed explanations: E0261, E0309, E0621, E0700.
+Some errors have detailed explanations: E0261, E0309, E0311, E0621, E0700.
For more information about an error, try `rustc --explain E0261`.
diff --git a/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.stderr b/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.stderr
index f49876bcd..c77ef79e7 100644
--- a/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.stderr
+++ b/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.stderr
@@ -10,7 +10,7 @@ LL | | remaining: self.0.iter(),
LL | | }
| |_________^ returning this value requires that `'1` must outlive `'static`
|
-help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'_` lifetime bound
+help: to declare that `impl Iterator<Item = Box<(dyn Foo + 'static)>>` captures data from argument `self`, you can add an explicit `'_` lifetime bound
|
LL | fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> + '_ {
| ++++
@@ -65,7 +65,7 @@ LL | | remaining: self.0.iter(),
LL | | }
| |_________^ returning this value requires that `'a` must outlive `'static`
|
-help: to declare that the `impl Trait` captures data from argument `self`, you can add an explicit `'a` lifetime bound
+help: to declare that `impl Iterator<Item = Box<(dyn Foo + 'static)>>` captures data from argument `self`, you can add an explicit `'a` lifetime bound
|
LL | fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> + 'a {
| ++++
diff --git a/src/test/ui/suggestions/match-with-different-arm-types-as-stmt-instead-of-expr.stderr b/src/test/ui/suggestions/match-with-different-arm-types-as-stmt-instead-of-expr.stderr
index be6fc2615..00aa7d18a 100644
--- a/src/test/ui/suggestions/match-with-different-arm-types-as-stmt-instead-of-expr.stderr
+++ b/src/test/ui/suggestions/match-with-different-arm-types-as-stmt-instead-of-expr.stderr
@@ -7,7 +7,7 @@ LL | fn not_all_paths(a: &str) -> u32 {
| implicitly returns `()` as its body has no tail or `return` expression
...
LL | };
- | - help: remove this semicolon
+ | - help: remove this semicolon to return this value
error[E0308]: `match` arms have incompatible types
--> $DIR/match-with-different-arm-types-as-stmt-instead-of-expr.rs:26:14
diff --git a/src/test/ui/suggestions/missing-bound-in-manual-copy-impl-2.stderr b/src/test/ui/suggestions/missing-bound-in-manual-copy-impl-2.stderr
index e0f405eed..9e6f0d9eb 100644
--- a/src/test/ui/suggestions/missing-bound-in-manual-copy-impl-2.stderr
+++ b/src/test/ui/suggestions/missing-bound-in-manual-copy-impl-2.stderr
@@ -1,11 +1,11 @@
error[E0204]: the trait `Copy` may not be implemented for this type
- --> $DIR/missing-bound-in-manual-copy-impl-2.rs:16:9
+ --> $DIR/missing-bound-in-manual-copy-impl-2.rs:16:18
|
LL | struct Wrapper<T>(T);
| - this field does not implement `Copy`
...
LL | impl<S> Copy for Wrapper<OnlyCopyIfDisplay<S>> {}
- | ^^^^
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the `Copy` impl for `OnlyCopyIfDisplay<S>` requires that `S: std::fmt::Display`
--> $DIR/missing-bound-in-manual-copy-impl-2.rs:4:19
diff --git a/src/test/ui/suggestions/missing-bound-in-manual-copy-impl.stderr b/src/test/ui/suggestions/missing-bound-in-manual-copy-impl.stderr
index 218988511..fe2d133c8 100644
--- a/src/test/ui/suggestions/missing-bound-in-manual-copy-impl.stderr
+++ b/src/test/ui/suggestions/missing-bound-in-manual-copy-impl.stderr
@@ -1,11 +1,11 @@
error[E0204]: the trait `Copy` may not be implemented for this type
- --> $DIR/missing-bound-in-manual-copy-impl.rs:6:9
+ --> $DIR/missing-bound-in-manual-copy-impl.rs:6:18
|
LL | struct Wrapper<T>(T);
| - this field does not implement `Copy`
LL |
LL | impl<S> Copy for Wrapper<S> {}
- | ^^^^
+ | ^^^^^^^^^^
|
help: consider restricting type parameter `S`
|
diff --git a/src/test/ui/suggestions/non-existent-field-present-in-subfield-recursion-limit.rs b/src/test/ui/suggestions/non-existent-field-present-in-subfield-recursion-limit.rs
index 98b408daa..a7a3f9818 100644
--- a/src/test/ui/suggestions/non-existent-field-present-in-subfield-recursion-limit.rs
+++ b/src/test/ui/suggestions/non-existent-field-present-in-subfield-recursion-limit.rs
@@ -1,4 +1,4 @@
-// In rustc_typeck::check::expr::no_such_field_err we recursively
+// In rustc_hir_analysis::check::expr::no_such_field_err we recursively
// look in subfields for the field. This recursive search is limited
// in depth for compile-time reasons and to avoid infinite recursion
// in case of cycles. This file tests that the limit in the recursion
diff --git a/src/test/ui/suggestions/return-closures.stderr b/src/test/ui/suggestions/return-closures.stderr
index e273793ea..8b856d8de 100644
--- a/src/test/ui/suggestions/return-closures.stderr
+++ b/src/test/ui/suggestions/return-closures.stderr
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/return-closures.rs:3:5
|
LL | fn foo() {
- | - help: try adding a return type: `-> impl for<'r> Fn(&'r i32) -> i32`
+ | - help: try adding a return type: `-> impl for<'a> Fn(&'a i32) -> i32`
LL |
LL | |x: &i32| 1i32
| ^^^^^^^^^^^^^^ expected `()`, found closure
diff --git a/src/test/ui/suggestions/struct-field-type-including-single-colon.stderr b/src/test/ui/suggestions/struct-field-type-including-single-colon.stderr
index 189759d64..4dd514480 100644
--- a/src/test/ui/suggestions/struct-field-type-including-single-colon.stderr
+++ b/src/test/ui/suggestions/struct-field-type-including-single-colon.stderr
@@ -12,6 +12,8 @@ LL | a: foo::A,
error: expected `,`, or `}`, found `:`
--> $DIR/struct-field-type-including-single-colon.rs:9:11
|
+LL | struct Foo {
+ | --- while parsing this struct
LL | a: foo:A,
| ^
@@ -29,6 +31,8 @@ LL | b: foo::bar::B,
error: expected `,`, or `}`, found `:`
--> $DIR/struct-field-type-including-single-colon.rs:15:16
|
+LL | struct Bar {
+ | --- while parsing this struct
LL | b: foo::bar:B,
| ^
diff --git a/src/test/ui/suggestions/sugg-else-for-closure.fixed b/src/test/ui/suggestions/sugg-else-for-closure.fixed
new file mode 100644
index 000000000..cf381d9da
--- /dev/null
+++ b/src/test/ui/suggestions/sugg-else-for-closure.fixed
@@ -0,0 +1,8 @@
+// run-rustfix
+
+fn main() {
+ let x = "com.example.app";
+ let y: Option<&str> = None;
+ let _s = y.unwrap_or_else(|| x.split('.').nth(1).unwrap());
+ //~^ ERROR: mismatched types [E0308]
+}
diff --git a/src/test/ui/suggestions/sugg-else-for-closure.rs b/src/test/ui/suggestions/sugg-else-for-closure.rs
new file mode 100644
index 000000000..540ced91f
--- /dev/null
+++ b/src/test/ui/suggestions/sugg-else-for-closure.rs
@@ -0,0 +1,8 @@
+// run-rustfix
+
+fn main() {
+ let x = "com.example.app";
+ let y: Option<&str> = None;
+ let _s = y.unwrap_or(|| x.split('.').nth(1).unwrap());
+ //~^ ERROR: mismatched types [E0308]
+}
diff --git a/src/test/ui/suggestions/sugg-else-for-closure.stderr b/src/test/ui/suggestions/sugg-else-for-closure.stderr
new file mode 100644
index 000000000..55a0eee18
--- /dev/null
+++ b/src/test/ui/suggestions/sugg-else-for-closure.stderr
@@ -0,0 +1,23 @@
+error[E0308]: mismatched types
+ --> $DIR/sugg-else-for-closure.rs:6:26
+ |
+LL | let _s = y.unwrap_or(|| x.split('.').nth(1).unwrap());
+ | --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found closure
+ | |
+ | arguments to this function are incorrect
+ |
+ = note: expected reference `&str`
+ found closure `[closure@$DIR/sugg-else-for-closure.rs:6:26: 6:28]`
+note: associated function defined here
+ --> $SRC_DIR/core/src/option.rs:LL:COL
+ |
+LL | pub const fn unwrap_or(self, default: T) -> T
+ | ^^^^^^^^^
+help: try calling `unwrap_or_else` instead
+ |
+LL | let _s = y.unwrap_or_else(|| x.split('.').nth(1).unwrap());
+ | +++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/suggestions/suggest-let-for-assignment.fixed b/src/test/ui/suggestions/suggest-let-for-assignment.fixed
new file mode 100644
index 000000000..3a25e25ee
--- /dev/null
+++ b/src/test/ui/suggestions/suggest-let-for-assignment.fixed
@@ -0,0 +1,17 @@
+// run-rustfix
+
+fn main() {
+ let demo = 1; //~ ERROR cannot find value `demo` in this scope
+ dbg!(demo); //~ ERROR cannot find value `demo` in this scope
+
+ let x = "x"; //~ ERROR cannot find value `x` in this scope
+ println!("x: {}", x); //~ ERROR cannot find value `x` in this scope
+
+ if x == "x" {
+ //~^ ERROR cannot find value `x` in this scope
+ println!("x is 1");
+ }
+
+ let y = 1 + 2; //~ ERROR cannot find value `y` in this scope
+ println!("y: {}", y); //~ ERROR cannot find value `y` in this scope
+}
diff --git a/src/test/ui/suggestions/suggest-let-for-assignment.rs b/src/test/ui/suggestions/suggest-let-for-assignment.rs
new file mode 100644
index 000000000..67705fe06
--- /dev/null
+++ b/src/test/ui/suggestions/suggest-let-for-assignment.rs
@@ -0,0 +1,17 @@
+// run-rustfix
+
+fn main() {
+ demo = 1; //~ ERROR cannot find value `demo` in this scope
+ dbg!(demo); //~ ERROR cannot find value `demo` in this scope
+
+ x = "x"; //~ ERROR cannot find value `x` in this scope
+ println!("x: {}", x); //~ ERROR cannot find value `x` in this scope
+
+ if x == "x" {
+ //~^ ERROR cannot find value `x` in this scope
+ println!("x is 1");
+ }
+
+ y = 1 + 2; //~ ERROR cannot find value `y` in this scope
+ println!("y: {}", y); //~ ERROR cannot find value `y` in this scope
+}
diff --git a/src/test/ui/suggestions/suggest-let-for-assignment.stderr b/src/test/ui/suggestions/suggest-let-for-assignment.stderr
new file mode 100644
index 000000000..3f6a3da4b
--- /dev/null
+++ b/src/test/ui/suggestions/suggest-let-for-assignment.stderr
@@ -0,0 +1,60 @@
+error[E0425]: cannot find value `demo` in this scope
+ --> $DIR/suggest-let-for-assignment.rs:4:5
+ |
+LL | demo = 1;
+ | ^^^^
+ |
+help: you might have meant to introduce a new binding
+ |
+LL | let demo = 1;
+ | +++
+
+error[E0425]: cannot find value `demo` in this scope
+ --> $DIR/suggest-let-for-assignment.rs:5:10
+ |
+LL | dbg!(demo);
+ | ^^^^ not found in this scope
+
+error[E0425]: cannot find value `x` in this scope
+ --> $DIR/suggest-let-for-assignment.rs:7:5
+ |
+LL | x = "x";
+ | ^
+ |
+help: you might have meant to introduce a new binding
+ |
+LL | let x = "x";
+ | +++
+
+error[E0425]: cannot find value `x` in this scope
+ --> $DIR/suggest-let-for-assignment.rs:8:23
+ |
+LL | println!("x: {}", x);
+ | ^ not found in this scope
+
+error[E0425]: cannot find value `x` in this scope
+ --> $DIR/suggest-let-for-assignment.rs:10:8
+ |
+LL | if x == "x" {
+ | ^ not found in this scope
+
+error[E0425]: cannot find value `y` in this scope
+ --> $DIR/suggest-let-for-assignment.rs:15:5
+ |
+LL | y = 1 + 2;
+ | ^
+ |
+help: you might have meant to introduce a new binding
+ |
+LL | let y = 1 + 2;
+ | +++
+
+error[E0425]: cannot find value `y` in this scope
+ --> $DIR/suggest-let-for-assignment.rs:16:23
+ |
+LL | println!("y: {}", y);
+ | ^ not found in this scope
+
+error: aborting due to 7 previous errors
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr b/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr
index f716e6c17..ffd505fff 100644
--- a/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr
+++ b/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr
@@ -37,9 +37,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | impl<'a, T> Struct<T> for Trait<'a, T> {}
| ^^^^^^^^^^^^
|
- = note: `#[warn(bare_trait_objects)]` on by default
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
|
LL | impl<'a, T> Struct<T> for dyn Trait<'a, T> {}
diff --git a/src/test/ui/symbol-names/impl1.legacy.stderr b/src/test/ui/symbol-names/impl1.legacy.stderr
index b6012e415..3d438df92 100644
--- a/src/test/ui/symbol-names/impl1.legacy.stderr
+++ b/src/test/ui/symbol-names/impl1.legacy.stderr
@@ -64,7 +64,7 @@ error: demangling-alt(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::A
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
-error: def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8, ...)> + AutoTrait; 3] as main::{closure#1}::Bar>::method)
+error: def-path(<[&dyn Foo<Assoc = for<'a> extern "C" fn(&'a u8, ...)> + AutoTrait; 3] as main::{closure#1}::Bar>::method)
--> $DIR/impl1.rs:69:13
|
LL | #[rustc_def_path]
diff --git a/src/test/ui/symbol-names/impl1.rs b/src/test/ui/symbol-names/impl1.rs
index 86f0a8b0b..629c2f33d 100644
--- a/src/test/ui/symbol-names/impl1.rs
+++ b/src/test/ui/symbol-names/impl1.rs
@@ -67,8 +67,8 @@ fn main() {
//[v0]~| ERROR demangling(<[&dyn
//[v0]~| ERROR demangling-alt(<[&dyn impl1::Foo<Assoc = for<'a> extern "C" fn(&'a u8, ...)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method)
#[rustc_def_path]
- //[legacy]~^ ERROR def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8, ...)> + AutoTrait; 3] as main::{closure#1}::Bar>::method)
- //[v0]~^^ ERROR def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8, ...)> + AutoTrait; 3] as main::{closure#1}::Bar>::method)
+ //[legacy]~^ ERROR def-path(<[&dyn Foo<Assoc = for<'a> extern "C" fn(&'a u8, ...)> + AutoTrait; 3] as main::{closure#1}::Bar>::method)
+ //[v0]~^^ ERROR def-path(<[&dyn Foo<Assoc = for<'a> extern "C" fn(&'a u8, ...)> + AutoTrait; 3] as main::{closure#1}::Bar>::method)
fn method(&self) {}
}
};
diff --git a/src/test/ui/symbol-names/impl1.v0.stderr b/src/test/ui/symbol-names/impl1.v0.stderr
index 48f7473b6..33caad71f 100644
--- a/src/test/ui/symbol-names/impl1.v0.stderr
+++ b/src/test/ui/symbol-names/impl1.v0.stderr
@@ -64,7 +64,7 @@ error: demangling-alt(<[&dyn impl1::Foo<Assoc = for<'a> extern "C" fn(&'a u8, ..
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
-error: def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8, ...)> + AutoTrait; 3] as main::{closure#1}::Bar>::method)
+error: def-path(<[&dyn Foo<Assoc = for<'a> extern "C" fn(&'a u8, ...)> + AutoTrait; 3] as main::{closure#1}::Bar>::method)
--> $DIR/impl1.rs:69:13
|
LL | #[rustc_def_path]
diff --git a/src/test/ui/test-attrs/inaccessible-test-modules.stderr b/src/test/ui/test-attrs/inaccessible-test-modules.stderr
index a94ea1e79..0c16ecd4c 100644
--- a/src/test/ui/test-attrs/inaccessible-test-modules.stderr
+++ b/src/test/ui/test-attrs/inaccessible-test-modules.stderr
@@ -11,10 +11,16 @@ error[E0432]: unresolved import `test`
--> $DIR/inaccessible-test-modules.rs:6:5
|
LL | use test as y;
- | ----^^^^^
- | |
- | no `test` in the root
- | help: a similar name exists in the module: `test`
+ | ^^^^^^^^^ no `test` in the root
+ |
+help: a similar name exists in the module
+ |
+LL | use test as y;
+ | ~~~~
+help: consider importing this module instead
+ |
+LL | use test::test;
+ | ~~~~~~~~~~~
error: aborting due to 2 previous errors
diff --git a/src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs b/src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs
index ff62d8492..585874e27 100644
--- a/src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs
+++ b/src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs
@@ -1,4 +1,5 @@
// run-pass
+// needs-unwind (#73509)
#![feature(test)]
diff --git a/src/test/ui/test-attrs/test-on-not-fn.stderr b/src/test/ui/test-attrs/test-on-not-fn.stderr
index 23efd5bc0..fc2c5f62b 100644
--- a/src/test/ui/test-attrs/test-on-not-fn.stderr
+++ b/src/test/ui/test-attrs/test-on-not-fn.stderr
@@ -2,7 +2,7 @@ error: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:3:1
|
LL | #[test]
- | ^^^^^^^ the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
LL | mod test {}
| ----------- expected a non-associated function, found a module
|
@@ -15,7 +15,7 @@ error: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:6:1
|
LL | #[test]
- | ^^^^^^^ the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
LL | / mod loooooooooooooong_teeeeeeeeeest {
LL | | /*
LL | | this is a comment
@@ -34,7 +34,7 @@ error: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:20:1
|
LL | #[test]
- | ^^^^^^^ the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
LL | extern "C" {}
| ------------- expected a non-associated function, found an extern block
|
@@ -47,7 +47,7 @@ error: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:23:1
|
LL | #[test]
- | ^^^^^^^ the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
LL | trait Foo {}
| ------------ expected a non-associated function, found a trait
|
@@ -60,7 +60,7 @@ error: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:26:1
|
LL | #[test]
- | ^^^^^^^ the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
LL | impl Foo for i32 {}
| ------------------- expected a non-associated function, found an implementation
|
@@ -73,7 +73,7 @@ error: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:29:1
|
LL | #[test]
- | ^^^^^^^ the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
LL | const FOO: i32 = -1_i32;
| ------------------------ expected a non-associated function, found a constant item
|
@@ -86,7 +86,7 @@ error: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:32:1
|
LL | #[test]
- | ^^^^^^^ the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
LL | static BAR: u64 = 10_000_u64;
| ----------------------------- expected a non-associated function, found a static item
|
@@ -99,7 +99,7 @@ error: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:35:1
|
LL | #[test]
- | ^^^^^^^ the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
LL | / enum MyUnit {
LL | | Unit,
LL | | }
@@ -114,7 +114,7 @@ error: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:40:1
|
LL | #[test]
- | ^^^^^^^ the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
LL | struct NewI32(i32);
| ------------------- expected a non-associated function, found a struct
|
@@ -127,7 +127,7 @@ error: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:43:1
|
LL | #[test]
- | ^^^^^^^ the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
LL | / union Spooky {
LL | | x: i32,
LL | | y: u32,
@@ -143,7 +143,7 @@ error: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:50:1
|
LL | #[test]
- | ^^^^^^^ the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
LL | #[derive(Copy, Clone, Debug)]
LL | / struct MoreAttrs {
LL | | a: i32,
@@ -160,7 +160,7 @@ warning: the `#[test]` attribute may only be used on a non-associated function
--> $DIR/test-on-not-fn.rs:61:1
|
LL | #[test]
- | ^^^^^^^ the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
+ | ^^^^^^^ the `#[test]` macro causes a function to be run on a test and has no effect on non-functions
LL | foo!();
| ------- expected a non-associated function, found an item macro invocation
|
diff --git a/src/test/ui/test-attrs/test-panic-while-printing.rs b/src/test/ui/test-attrs/test-panic-while-printing.rs
index 01e460da5..033c8beb4 100644
--- a/src/test/ui/test-attrs/test-panic-while-printing.rs
+++ b/src/test/ui/test-attrs/test-panic-while-printing.rs
@@ -1,7 +1,6 @@
// compile-flags:--test
// run-pass
// needs-unwind
-// ignore-emscripten no subprocess support
use std::fmt;
use std::fmt::{Display, Formatter};
diff --git a/src/test/ui/test-attrs/test-should-fail-good-message.rs b/src/test/ui/test-attrs/test-should-fail-good-message.rs
index 3260b6938..83519c452 100644
--- a/src/test/ui/test-attrs/test-should-fail-good-message.rs
+++ b/src/test/ui/test-attrs/test-should-fail-good-message.rs
@@ -1,6 +1,5 @@
// run-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
// compile-flags: --test
#[test]
#[should_panic(expected = "foo")]
diff --git a/src/test/ui/test-attrs/test-thread-capture.rs b/src/test/ui/test-attrs/test-thread-capture.rs
index edc972837..53acca341 100644
--- a/src/test/ui/test-attrs/test-thread-capture.rs
+++ b/src/test/ui/test-attrs/test-thread-capture.rs
@@ -5,6 +5,7 @@
// exec-env:RUST_BACKTRACE=0
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
// ignore-emscripten no threads support
+// needs-unwind
#[test]
fn thready_pass() {
diff --git a/src/test/ui/test-attrs/test-thread-capture.run.stdout b/src/test/ui/test-attrs/test-thread-capture.run.stdout
index 487cfb55e..c712a78af 100644
--- a/src/test/ui/test-attrs/test-thread-capture.run.stdout
+++ b/src/test/ui/test-attrs/test-thread-capture.run.stdout
@@ -10,7 +10,7 @@ fee
fie
foe
fum
-thread 'main' panicked at 'explicit panic', $DIR/test-thread-capture.rs:31:5
+thread 'main' panicked at 'explicit panic', $DIR/test-thread-capture.rs:32:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
diff --git a/src/test/ui/test-attrs/test-thread-nocapture.rs b/src/test/ui/test-attrs/test-thread-nocapture.rs
index 8e8e9bbfd..2b57eb8aa 100644
--- a/src/test/ui/test-attrs/test-thread-nocapture.rs
+++ b/src/test/ui/test-attrs/test-thread-nocapture.rs
@@ -5,6 +5,7 @@
// exec-env:RUST_BACKTRACE=0
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
// ignore-emscripten no threads support
+// needs-unwind
#[test]
fn thready_pass() {
diff --git a/src/test/ui/test-attrs/test-thread-nocapture.run.stderr b/src/test/ui/test-attrs/test-thread-nocapture.run.stderr
index 06495681b..0a12a0528 100644
--- a/src/test/ui/test-attrs/test-thread-nocapture.run.stderr
+++ b/src/test/ui/test-attrs/test-thread-nocapture.run.stderr
@@ -1,2 +1,2 @@
-thread 'main' panicked at 'explicit panic', $DIR/test-thread-nocapture.rs:31:5
+thread 'main' panicked at 'explicit panic', $DIR/test-thread-nocapture.rs:32:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
diff --git a/src/test/ui/thir-tree.stdout b/src/test/ui/thir-tree.stdout
index 5fcdfca18..7fb90581f 100644
--- a/src/test/ui/thir-tree.stdout
+++ b/src/test/ui/thir-tree.stdout
@@ -33,7 +33,9 @@ Thir {
region_scope: Node(2),
lint_level: Explicit(
HirId {
- owner: DefId(0:3 ~ thir_tree[8f1d]::main),
+ owner: OwnerId {
+ def_id: DefId(0:3 ~ thir_tree[8f1d]::main),
+ },
local_id: 2,
},
),
diff --git a/src/test/ui/threads-sendsync/issue-43733-2.rs b/src/test/ui/threads-sendsync/issue-43733-2.rs
index 21ea8e9a2..32baeec43 100644
--- a/src/test/ui/threads-sendsync/issue-43733-2.rs
+++ b/src/test/ui/threads-sendsync/issue-43733-2.rs
@@ -1,5 +1,5 @@
+// ignore-wasm32
// dont-check-compiler-stderr
-
#![feature(cfg_target_thread_local, thread_local_internals)]
// On platforms *without* `#[thread_local]`, use
diff --git a/src/test/ui/threads-sendsync/issue-43733.rs b/src/test/ui/threads-sendsync/issue-43733.rs
index 0ac6f588f..935e02944 100644
--- a/src/test/ui/threads-sendsync/issue-43733.rs
+++ b/src/test/ui/threads-sendsync/issue-43733.rs
@@ -1,8 +1,8 @@
+// ignore-wasm32
// revisions: mir thir
// [thir]compile-flags: -Z thir-unsafeck
// normalize-stderr-test: "__FastLocalKeyInner::<T>::get" -> "$$LOCALKEYINNER::<T>::get"
// normalize-stderr-test: "__OsLocalKeyInner::<T>::get" -> "$$LOCALKEYINNER::<T>::get"
-
#![feature(thread_local)]
#![feature(cfg_target_thread_local, thread_local_internals)]
diff --git a/src/test/ui/threads-sendsync/sync-send-in-std.rs b/src/test/ui/threads-sendsync/sync-send-in-std.rs
index b8ae214dc..6d1fba64e 100644
--- a/src/test/ui/threads-sendsync/sync-send-in-std.rs
+++ b/src/test/ui/threads-sendsync/sync-send-in-std.rs
@@ -2,6 +2,7 @@
// ignore-wasm32-bare networking not available
// ignore-sgx ToSocketAddrs cannot be used for DNS Resolution
+// ignore-fuchsia Req. test-harness networking privileges
use std::net::ToSocketAddrs;
diff --git a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-2.stderr b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-2.stderr
index 4084f69a6..10e82c54e 100644
--- a/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-2.stderr
+++ b/src/test/ui/traits/associated_type_bound/check-trait-object-bounds-2.stderr
@@ -4,7 +4,7 @@ error[E0277]: expected a `FnOnce<(&i32,)>` closure, found `i32`
LL | f::<dyn for<'x> X<'x, F = i32>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `FnOnce<(&i32,)>` closure, found `i32`
|
- = help: the trait `for<'r> FnOnce<(&'r i32,)>` is not implemented for `i32`
+ = help: the trait `for<'a> FnOnce<(&'a i32,)>` is not implemented for `i32`
note: required by a bound in `f`
--> $DIR/check-trait-object-bounds-2.rs:8:9
|
diff --git a/src/test/ui/traits/bound/not-on-bare-trait.stderr b/src/test/ui/traits/bound/not-on-bare-trait.stderr
index 1c52629da..8da0b6d6b 100644
--- a/src/test/ui/traits/bound/not-on-bare-trait.stderr
+++ b/src/test/ui/traits/bound/not-on-bare-trait.stderr
@@ -4,9 +4,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | fn foo(_x: Foo + Send) {
| ^^^^^^^^^^
|
- = note: `#[warn(bare_trait_objects)]` on by default
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
|
LL | fn foo(_x: dyn Foo + Send) {
diff --git a/src/test/ui/traits/copy-impl-cannot-normalize.stderr b/src/test/ui/traits/copy-impl-cannot-normalize.stderr
index afdad1609..68b95b42b 100644
--- a/src/test/ui/traits/copy-impl-cannot-normalize.stderr
+++ b/src/test/ui/traits/copy-impl-cannot-normalize.stderr
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `T: TraitFoo` is not satisfied
- --> $DIR/copy-impl-cannot-normalize.rs:22:1
+ --> $DIR/copy-impl-cannot-normalize.rs:22:18
|
LL | impl<T> Copy for Foo<T> {}
- | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TraitFoo` is not implemented for `T`
+ | ^^^^^^ the trait `TraitFoo` is not implemented for `T`
|
help: consider restricting type parameter `T`
|
diff --git a/src/test/ui/traits/issue-102989.rs b/src/test/ui/traits/issue-102989.rs
new file mode 100644
index 000000000..62f95272f
--- /dev/null
+++ b/src/test/ui/traits/issue-102989.rs
@@ -0,0 +1,16 @@
+// normalize-stderr-test "loaded from .*libcore-.*.rlib" -> "loaded from SYSROOT/libcore-*.rlib"
+
+#![feature(lang_items)]
+#[lang="sized"]
+trait Sized { } //~ ERROR found duplicate lang item `sized`
+
+fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
+ //~^ ERROR `self` parameter is only allowed in associated functions
+ //~| ERROR cannot find type `Struct` in this scope
+ //~| ERROR mismatched types
+ let x = x << 1;
+ //~^ ERROR the size for values of type `{integer}` cannot be known at compilation time
+ //~| ERROR cannot find value `x` in this scope
+}
+
+fn main() {}
diff --git a/src/test/ui/traits/issue-102989.stderr b/src/test/ui/traits/issue-102989.stderr
new file mode 100644
index 000000000..efe1a2467
--- /dev/null
+++ b/src/test/ui/traits/issue-102989.stderr
@@ -0,0 +1,59 @@
+error: `self` parameter is only allowed in associated functions
+ --> $DIR/issue-102989.rs:7:15
+ |
+LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
+ | ^^^^ not semantically valid as function parameter
+ |
+ = note: associated functions are those in `impl` or `trait` definitions
+
+error[E0412]: cannot find type `Struct` in this scope
+ --> $DIR/issue-102989.rs:7:22
+ |
+LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
+ | ^^^^^^ not found in this scope
+
+error[E0425]: cannot find value `x` in this scope
+ --> $DIR/issue-102989.rs:11:13
+ |
+LL | let x = x << 1;
+ | ^ help: a local variable with a similar name exists: `f`
+
+error[E0152]: found duplicate lang item `sized`
+ --> $DIR/issue-102989.rs:5:1
+ |
+LL | trait Sized { }
+ | ^^^^^^^^^^^
+ |
+ = note: the lang item is first defined in crate `core` (which `std` depends on)
+ = note: first definition in `core` loaded from SYSROOT/libcore-*.rlib
+ = note: second definition in the local crate (`issue_102989`)
+
+error[E0277]: the size for values of type `{integer}` cannot be known at compilation time
+ --> $DIR/issue-102989.rs:11:15
+ |
+LL | let x = x << 1;
+ | ^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `std::marker::Sized` is not implemented for `{integer}`
+
+error[E0308]: mismatched types
+ --> $DIR/issue-102989.rs:7:42
+ |
+LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
+ | ---------- ^^^^ expected `&u32`, found `()`
+ | |
+ | implicitly returns `()` as its body has no tail or `return` expression
+ |
+note: consider returning one of these bindings
+ --> $DIR/issue-102989.rs:7:30
+ |
+LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
+ | ^
+...
+LL | let x = x << 1;
+ | ^
+
+error: aborting due to 6 previous errors
+
+Some errors have detailed explanations: E0152, E0277, E0308, E0412, E0425.
+For more information about an error, try `rustc --explain E0152`.
diff --git a/src/test/ui/traits/issue-33140-hack-boundaries.stderr b/src/test/ui/traits/issue-33140-hack-boundaries.stderr
index 62cfca545..58286648d 100644
--- a/src/test/ui/traits/issue-33140-hack-boundaries.stderr
+++ b/src/test/ui/traits/issue-33140-hack-boundaries.stderr
@@ -66,3 +66,20 @@ error: aborting due to 8 previous errors
Some errors have detailed explanations: E0119, E0751.
For more information about an error, try `rustc --explain E0119`.
+Future incompatibility report: Future breakage diagnostic:
+warning: conflicting implementations of trait `Trait0` for type `(dyn std::marker::Send + 'static)`: (E0119)
+ --> $DIR/issue-33140-hack-boundaries.rs:10:1
+ |
+LL | impl Trait0 for dyn Send {}
+ | ------------------------ first implementation here
+LL | impl Trait0 for dyn Send {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + 'static)`
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
+note: the lint level is defined here
+ --> $DIR/issue-33140-hack-boundaries.rs:2:10
+ |
+LL | #![allow(order_dependent_trait_objects)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
diff --git a/src/test/ui/issues/issue-43784-supertrait.rs b/src/test/ui/traits/issue-43784-supertrait.rs
index 55c26ccd2..55c26ccd2 100644
--- a/src/test/ui/issues/issue-43784-supertrait.rs
+++ b/src/test/ui/traits/issue-43784-supertrait.rs
diff --git a/src/test/ui/issues/issue-43784-supertrait.stderr b/src/test/ui/traits/issue-43784-supertrait.stderr
index bb890cb99..bb890cb99 100644
--- a/src/test/ui/issues/issue-43784-supertrait.stderr
+++ b/src/test/ui/traits/issue-43784-supertrait.stderr
diff --git a/src/test/ui/traits/issue-8153.stderr b/src/test/ui/traits/issue-8153.stderr
index b76bbc023..ae214bb9e 100644
--- a/src/test/ui/traits/issue-8153.stderr
+++ b/src/test/ui/traits/issue-8153.stderr
@@ -1,10 +1,13 @@
error[E0201]: duplicate definitions with name `bar`:
--> $DIR/issue-8153.rs:11:5
|
+LL | fn bar(&self) -> isize;
+ | ----------------------- item in trait
+...
LL | fn bar(&self) -> isize {1}
- | ---------------------- previous definition of `bar` here
+ | -------------------------- previous definition here
LL | fn bar(&self) -> isize {2}
- | ^^^^^^^^^^^^^^^^^^^^^^ duplicate definition
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definition
error: aborting due to previous error
diff --git a/src/test/ui/traits/issue-91949-hangs-on-recursion.stderr b/src/test/ui/traits/issue-91949-hangs-on-recursion.stderr
index 6acf2fe65..61b6d4b08 100644
--- a/src/test/ui/traits/issue-91949-hangs-on-recursion.stderr
+++ b/src/test/ui/traits/issue-91949-hangs-on-recursion.stderr
@@ -9,8 +9,8 @@ LL | {
LL | recurse(IteratorOfWrapped(elements).map(|t| t.0))
| ------------------------------------------------- recursive call site
|
- = note: `#[warn(unconditional_recursion)]` on by default
= help: a `loop` may express intention better if this is on purpose
+ = note: `#[warn(unconditional_recursion)]` on by default
error[E0275]: overflow evaluating the requirement `(): Sized`
|
diff --git a/src/test/ui/traits/negative-impls/negative-default-impls.stderr b/src/test/ui/traits/negative-impls/negative-default-impls.stderr
index ceb86559d..7b54cf542 100644
--- a/src/test/ui/traits/negative-impls/negative-default-impls.stderr
+++ b/src/test/ui/traits/negative-impls/negative-default-impls.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0750]: negative impls cannot be default impls
--> $DIR/negative-default-impls.rs:9:1
diff --git a/src/test/ui/traits/negative-impls/negative-specializes-negative.stderr b/src/test/ui/traits/negative-impls/negative-specializes-negative.stderr
index 9a846143d..751e29c3b 100644
--- a/src/test/ui/traits/negative-impls/negative-specializes-negative.stderr
+++ b/src/test/ui/traits/negative-impls/negative-specializes-negative.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted
diff --git a/src/test/ui/traits/negative-impls/negative-specializes-positive-item.stderr b/src/test/ui/traits/negative-impls/negative-specializes-positive-item.stderr
index 77b4373a2..1cfa49b20 100644
--- a/src/test/ui/traits/negative-impls/negative-specializes-positive-item.stderr
+++ b/src/test/ui/traits/negative-impls/negative-specializes-positive-item.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0751]: found both positive and negative implementation of trait `MyTrait` for type `u32`:
--> $DIR/negative-specializes-positive-item.rs:11:1
diff --git a/src/test/ui/traits/negative-impls/negative-specializes-positive.stderr b/src/test/ui/traits/negative-impls/negative-specializes-positive.stderr
index e5dc81b3e..9f9e28678 100644
--- a/src/test/ui/traits/negative-impls/negative-specializes-positive.stderr
+++ b/src/test/ui/traits/negative-impls/negative-specializes-positive.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0751]: found both positive and negative implementation of trait `MyTrait` for type `u32`:
--> $DIR/negative-specializes-positive.rs:7:1
diff --git a/src/test/ui/traits/negative-impls/positive-specializes-negative.stderr b/src/test/ui/traits/negative-impls/positive-specializes-negative.stderr
index c091bc81d..545f94143 100644
--- a/src/test/ui/traits/negative-impls/positive-specializes-negative.stderr
+++ b/src/test/ui/traits/negative-impls/positive-specializes-negative.stderr
@@ -4,9 +4,9 @@ warning: the feature `specialization` is incomplete and may not be safe to use a
LL | #![feature(specialization)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
= help: consider using `min_specialization` instead, which is more stable and complete
+ = note: `#[warn(incomplete_features)]` on by default
error[E0751]: found both positive and negative implementation of trait `MyTrait` for type `u32`:
--> $DIR/positive-specializes-negative.rs:7:1
diff --git a/src/test/ui/traits/object/issue-33140-traitobject-crate.stderr b/src/test/ui/traits/object/issue-33140-traitobject-crate.stderr
index 77d71360b..0af4df2ae 100644
--- a/src/test/ui/traits/object/issue-33140-traitobject-crate.stderr
+++ b/src/test/ui/traits/object/issue-33140-traitobject-crate.stderr
@@ -6,13 +6,13 @@ LL | unsafe impl Trait for dyn (::std::marker::Send) + Sync { }
LL | unsafe impl Trait for dyn (::std::marker::Send) + Send + Sync { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)`
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
note: the lint level is defined here
--> $DIR/issue-33140-traitobject-crate.rs:3:9
|
LL | #![warn(order_dependent_trait_objects)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119)
--> $DIR/issue-33140-traitobject-crate.rs:89:1
@@ -40,3 +40,56 @@ LL | unsafe impl Trait for dyn (::std::marker::Sync) + Send + Sync { }
warning: 3 warnings emitted
+Future incompatibility report: Future breakage diagnostic:
+warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119)
+ --> $DIR/issue-33140-traitobject-crate.rs:86:1
+ |
+LL | unsafe impl Trait for dyn (::std::marker::Send) + Sync { }
+ | ------------------------------------------------------ first implementation here
+LL | unsafe impl Trait for dyn (::std::marker::Send) + Send + Sync { }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)`
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
+note: the lint level is defined here
+ --> $DIR/issue-33140-traitobject-crate.rs:3:9
+ |
+LL | #![warn(order_dependent_trait_objects)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Future breakage diagnostic:
+warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119)
+ --> $DIR/issue-33140-traitobject-crate.rs:89:1
+ |
+LL | unsafe impl Trait for dyn (::std::marker::Send) + Send + Sync { }
+ | ------------------------------------------------------------- first implementation here
+...
+LL | unsafe impl Trait for dyn (::std::marker::Sync) + Send { }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)`
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
+note: the lint level is defined here
+ --> $DIR/issue-33140-traitobject-crate.rs:3:9
+ |
+LL | #![warn(order_dependent_trait_objects)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Future breakage diagnostic:
+warning: conflicting implementations of trait `Trait` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119)
+ --> $DIR/issue-33140-traitobject-crate.rs:93:1
+ |
+LL | unsafe impl Trait for dyn (::std::marker::Sync) + Send { }
+ | ------------------------------------------------------ first implementation here
+...
+LL | unsafe impl Trait for dyn (::std::marker::Sync) + Send + Sync { }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)`
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
+note: the lint level is defined here
+ --> $DIR/issue-33140-traitobject-crate.rs:3:9
+ |
+LL | #![warn(order_dependent_trait_objects)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
diff --git a/src/test/ui/traits/safety-trait-impl-cc.stderr b/src/test/ui/traits/safety-trait-impl-cc.stderr
index 5a0f8d3b8..0b1fb3047 100644
--- a/src/test/ui/traits/safety-trait-impl-cc.stderr
+++ b/src/test/ui/traits/safety-trait-impl-cc.stderr
@@ -7,6 +7,12 @@ LL | | panic!();
LL | | }
LL | | }
| |_^
+ |
+ = note: the trait `Foo` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
+help: add `unsafe` to this trait implementation
+ |
+LL | unsafe impl lib::Foo for Bar {
+ | ++++++
error: aborting due to previous error
diff --git a/src/test/ui/traits/safety-trait-impl.stderr b/src/test/ui/traits/safety-trait-impl.stderr
index fc0f6c693..721e2b48b 100644
--- a/src/test/ui/traits/safety-trait-impl.stderr
+++ b/src/test/ui/traits/safety-trait-impl.stderr
@@ -3,12 +3,24 @@ error[E0200]: the trait `UnsafeTrait` requires an `unsafe impl` declaration
|
LL | impl UnsafeTrait for u16 { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the trait `UnsafeTrait` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
+help: add `unsafe` to this trait implementation
+ |
+LL | unsafe impl UnsafeTrait for u16 { }
+ | ++++++
error[E0199]: implementing the trait `SafeTrait` is not unsafe
--> $DIR/safety-trait-impl.rs:16:1
|
LL | unsafe impl SafeTrait for u32 { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove `unsafe` from this trait implementation
+ |
+LL - unsafe impl SafeTrait for u32 { }
+LL + impl SafeTrait for u32 { }
+ |
error: aborting due to 2 previous errors
diff --git a/src/test/ui/traits/static-method-generic-inference.stderr b/src/test/ui/traits/static-method-generic-inference.stderr
index f1b8f23ec..5f74d0c3b 100644
--- a/src/test/ui/traits/static-method-generic-inference.stderr
+++ b/src/test/ui/traits/static-method-generic-inference.stderr
@@ -9,8 +9,8 @@ LL | let _f: base::Foo = base::HasNew::new();
|
help: use the fully-qualified path to the only available implementation
|
-LL | let _f: base::Foo = base::<::base::Foo as HasNew>::new();
- | +++++++++++++++ +
+LL | let _f: base::Foo = base::<Foo as HasNew>::new();
+ | +++++++ +
error: aborting due to previous error
diff --git a/src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr b/src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr
index 35af9112a..6c359b698 100644
--- a/src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr
+++ b/src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr
@@ -4,13 +4,13 @@ error: `dyn B` implements `Deref` with supertrait `(dyn A + 'static)` as output
LL | take_a(b)
| ^
|
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #89460 <https://github.com/rust-lang/rust/issues/89460>
note: the lint level is defined here
--> $DIR/migrate-lint-deny.rs:1:9
|
LL | #![deny(deref_into_dyn_supertrait)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #89460 <https://github.com/rust-lang/rust/issues/89460>
error: aborting due to previous error
diff --git a/src/test/ui/traits/trait-upcasting/multiple-occurence-ambiguousity.rs b/src/test/ui/traits/trait-upcasting/multiple-occurrence-ambiguousity.rs
index 6986ad621..6986ad621 100644
--- a/src/test/ui/traits/trait-upcasting/multiple-occurence-ambiguousity.rs
+++ b/src/test/ui/traits/trait-upcasting/multiple-occurrence-ambiguousity.rs
diff --git a/src/test/ui/traits/trait-upcasting/multiple-occurence-ambiguousity.stderr b/src/test/ui/traits/trait-upcasting/multiple-occurrence-ambiguousity.stderr
index e9670ad7d..956481351 100644
--- a/src/test/ui/traits/trait-upcasting/multiple-occurence-ambiguousity.stderr
+++ b/src/test/ui/traits/trait-upcasting/multiple-occurrence-ambiguousity.stderr
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
- --> $DIR/multiple-occurence-ambiguousity.rs:21:26
+ --> $DIR/multiple-occurrence-ambiguousity.rs:21:26
|
LL | let t: &dyn Bar<_> = s;
| ----------- ^ expected trait `Bar`, found trait `Foo`
diff --git a/src/test/ui/traits/unspecified-self-in-trait-ref.stderr b/src/test/ui/traits/unspecified-self-in-trait-ref.stderr
index 7869176bb..b5e8e8867 100644
--- a/src/test/ui/traits/unspecified-self-in-trait-ref.stderr
+++ b/src/test/ui/traits/unspecified-self-in-trait-ref.stderr
@@ -4,9 +4,9 @@ warning: trait objects without an explicit `dyn` are deprecated
LL | let a = Foo::lol();
| ^^^
|
- = note: `#[warn(bare_trait_objects)]` on by default
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
+ = note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
|
LL | let a = <dyn Foo>::lol();
diff --git a/src/test/ui/transmutability/enums/should_order_correctly.rs b/src/test/ui/transmutability/enums/should_order_correctly.rs
index b753cf0e6..1335cc9d2 100644
--- a/src/test/ui/transmutability/enums/should_order_correctly.rs
+++ b/src/test/ui/transmutability/enums/should_order_correctly.rs
@@ -2,7 +2,6 @@
//! The payloads of an enum variant should be ordered after its tag.
#![crate_type = "lib"]
-#![feature(arbitrary_enum_discriminant)]
#![feature(transmutability)]
#![allow(dead_code)]
diff --git a/src/test/ui/transmutability/enums/should_respect_endianness.rs b/src/test/ui/transmutability/enums/should_respect_endianness.rs
index 19ff69005..f3567b405 100644
--- a/src/test/ui/transmutability/enums/should_respect_endianness.rs
+++ b/src/test/ui/transmutability/enums/should_respect_endianness.rs
@@ -2,7 +2,6 @@
//! an enum with a multi-byte tag.
#![crate_type = "lib"]
-#![feature(arbitrary_enum_discriminant)]
#![feature(transmutability)]
#![allow(dead_code)]
diff --git a/src/test/ui/transmutability/enums/should_respect_endianness.stderr b/src/test/ui/transmutability/enums/should_respect_endianness.stderr
index fcb70813b..0845a5edf 100644
--- a/src/test/ui/transmutability/enums/should_respect_endianness.stderr
+++ b/src/test/ui/transmutability/enums/should_respect_endianness.stderr
@@ -1,12 +1,12 @@
error[E0277]: `Src` cannot be safely transmuted into `Unexpected` in the defining scope of `assert::Context`.
- --> $DIR/should_respect_endianness.rs:37:36
+ --> $DIR/should_respect_endianness.rs:36:36
|
LL | assert::is_transmutable::<Src, Unexpected>();
| ^^^^^^^^^^ `Src` cannot be safely transmuted into `Unexpected` in the defining scope of `assert::Context`.
|
= help: the trait `BikeshedIntrinsicFrom<Src, assert::Context, Assume { alignment: true, lifetimes: true, safety: true, validity: true }>` is not implemented for `Unexpected`
note: required by a bound in `is_transmutable`
- --> $DIR/should_respect_endianness.rs:15:14
+ --> $DIR/should_respect_endianness.rs:14:14
|
LL | pub fn is_transmutable<Src, Dst>()
| --------------- required by a bound in this
diff --git a/src/test/ui/transmutability/issue-101739-1.rs b/src/test/ui/transmutability/issue-101739-1.rs
new file mode 100644
index 000000000..bcb8b158e
--- /dev/null
+++ b/src/test/ui/transmutability/issue-101739-1.rs
@@ -0,0 +1,21 @@
+#![feature(transmutability)]
+
+mod assert {
+ use std::mem::BikeshedIntrinsicFrom;
+
+ pub fn is_transmutable<Src, Context, const ASSUME_ALIGNMENT: bool>()
+ where
+ Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME_ALIGNMENT>, //~ ERROR cannot find type `Dst` in this scope
+ //~^ ERROR mismatched types
+ {
+ }
+}
+
+fn via_const() {
+ struct Context;
+ struct Src;
+
+ assert::is_transmutable::<Src, Context, false>();
+}
+
+fn main() {}
diff --git a/src/test/ui/transmutability/issue-101739-1.stderr b/src/test/ui/transmutability/issue-101739-1.stderr
new file mode 100644
index 000000000..5fa741f26
--- /dev/null
+++ b/src/test/ui/transmutability/issue-101739-1.stderr
@@ -0,0 +1,16 @@
+error[E0412]: cannot find type `Dst` in this scope
+ --> $DIR/issue-101739-1.rs:8:9
+ |
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME_ALIGNMENT>,
+ | ^^^ not found in this scope
+
+error[E0308]: mismatched types
+ --> $DIR/issue-101739-1.rs:8:50
+ |
+LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME_ALIGNMENT>,
+ | ^^^^^^^^^^^^^^^^ expected struct `Assume`, found `bool`
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0308, E0412.
+For more information about an error, try `rustc --explain E0308`.
diff --git a/src/test/ui/transmutability/issue-101739-2.rs b/src/test/ui/transmutability/issue-101739-2.rs
new file mode 100644
index 000000000..964a7e49e
--- /dev/null
+++ b/src/test/ui/transmutability/issue-101739-2.rs
@@ -0,0 +1,37 @@
+#![crate_type = "lib"]
+#![feature(transmutability)]
+#![allow(dead_code, incomplete_features, non_camel_case_types)]
+
+mod assert {
+ use std::mem::BikeshedIntrinsicFrom;
+
+ pub fn is_transmutable<
+ Src,
+ Dst,
+ Context,
+ const ASSUME_ALIGNMENT: bool,
+ const ASSUME_LIFETIMES: bool,
+ const ASSUME_VALIDITY: bool,
+ const ASSUME_VISIBILITY: bool,
+ >()
+ where
+ Dst: BikeshedIntrinsicFrom< //~ ERROR this trait takes at most 3 generic arguments but 6 generic arguments were supplied
+ Src,
+ Context,
+ ASSUME_ALIGNMENT,
+ ASSUME_LIFETIMES,
+ ASSUME_VALIDITY,
+ ASSUME_VISIBILITY,
+ >,
+ {}
+}
+
+fn via_const() {
+ struct Context;
+ #[repr(C)] struct Src;
+ #[repr(C)] struct Dst;
+
+ const FALSE: bool = false;
+
+ assert::is_transmutable::<Src, Dst, Context, FALSE, FALSE, FALSE, FALSE>();
+}
diff --git a/src/test/ui/transmutability/issue-101739-2.stderr b/src/test/ui/transmutability/issue-101739-2.stderr
new file mode 100644
index 000000000..3f83d6583
--- /dev/null
+++ b/src/test/ui/transmutability/issue-101739-2.stderr
@@ -0,0 +1,20 @@
+error[E0107]: this trait takes at most 3 generic arguments but 6 generic arguments were supplied
+ --> $DIR/issue-101739-2.rs:18:14
+ |
+LL | Dst: BikeshedIntrinsicFrom<
+ | ^^^^^^^^^^^^^^^^^^^^^ expected at most 3 generic arguments
+...
+LL | / ASSUME_LIFETIMES,
+LL | | ASSUME_VALIDITY,
+LL | | ASSUME_VISIBILITY,
+ | |_____________________________- help: remove these generic arguments
+ |
+note: trait defined here, with at most 3 generic parameters: `Src`, `Context`, `ASSUME`
+ --> $SRC_DIR/core/src/mem/transmutability.rs:LL:COL
+ |
+LL | pub unsafe trait BikeshedIntrinsicFrom<Src, Context, const ASSUME: Assume = { Assume::NOTHING }>
+ | ^^^^^^^^^^^^^^^^^^^^^ --- ------- ------------------------------------------
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0107`.
diff --git a/src/test/ui/transmutability/malformed-program-gracefulness/wrong-type-assume.rs b/src/test/ui/transmutability/malformed-program-gracefulness/wrong-type-assume.rs
index 354abf99d..52aa4bb31 100644
--- a/src/test/ui/transmutability/malformed-program-gracefulness/wrong-type-assume.rs
+++ b/src/test/ui/transmutability/malformed-program-gracefulness/wrong-type-assume.rs
@@ -24,10 +24,6 @@ mod assert {
Src,
Context,
{ from_options(ASSUME_ALIGNMENT, ASSUME_LIFETIMES, ASSUME_SAFETY, ASSUME_VALIDITY) }
- //~^ ERROR E0080
- //~| ERROR E0080
- //~| ERROR E0080
- //~| ERROR E0080
>,
{}
diff --git a/src/test/ui/transmutability/malformed-program-gracefulness/wrong-type-assume.stderr b/src/test/ui/transmutability/malformed-program-gracefulness/wrong-type-assume.stderr
index a258f2ece..c6d93876c 100644
--- a/src/test/ui/transmutability/malformed-program-gracefulness/wrong-type-assume.stderr
+++ b/src/test/ui/transmutability/malformed-program-gracefulness/wrong-type-assume.stderr
@@ -1,52 +1,27 @@
error[E0308]: mismatched types
- --> $DIR/wrong-type-assume.rs:53:51
+ --> $DIR/wrong-type-assume.rs:49:51
|
LL | assert::is_transmutable::<Src, Dst, Context, {0u8}, false, false, false>();
| ^^^ expected `bool`, found `u8`
-error[E0080]: evaluation of `assert::is_transmutable::<test::Src, test::Dst, test::Context, {0u8}, false, false, false>::{constant#0}` failed
- --> $DIR/wrong-type-assume.rs:26:15
- |
-LL | { from_options(ASSUME_ALIGNMENT, ASSUME_LIFETIMES, ASSUME_SAFETY, ASSUME_VALIDITY) }
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
-
error[E0308]: mismatched types
- --> $DIR/wrong-type-assume.rs:54:58
+ --> $DIR/wrong-type-assume.rs:50:58
|
LL | assert::is_transmutable::<Src, Dst, Context, false, {0u8}, false, false>();
| ^^^ expected `bool`, found `u8`
-error[E0080]: evaluation of `assert::is_transmutable::<test::Src, test::Dst, test::Context, false, {0u8}, false, false>::{constant#0}` failed
- --> $DIR/wrong-type-assume.rs:26:15
- |
-LL | { from_options(ASSUME_ALIGNMENT, ASSUME_LIFETIMES, ASSUME_SAFETY, ASSUME_VALIDITY) }
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
-
error[E0308]: mismatched types
- --> $DIR/wrong-type-assume.rs:55:65
+ --> $DIR/wrong-type-assume.rs:51:65
|
LL | assert::is_transmutable::<Src, Dst, Context, false, false, {0u8}, false>();
| ^^^ expected `bool`, found `u8`
-error[E0080]: evaluation of `assert::is_transmutable::<test::Src, test::Dst, test::Context, false, false, {0u8}, false>::{constant#0}` failed
- --> $DIR/wrong-type-assume.rs:26:15
- |
-LL | { from_options(ASSUME_ALIGNMENT, ASSUME_LIFETIMES, ASSUME_SAFETY, ASSUME_VALIDITY) }
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
-
error[E0308]: mismatched types
- --> $DIR/wrong-type-assume.rs:56:72
+ --> $DIR/wrong-type-assume.rs:52:72
|
LL | assert::is_transmutable::<Src, Dst, Context, false, false, false, {0u8}>();
| ^^^ expected `bool`, found `u8`
-error[E0080]: evaluation of `assert::is_transmutable::<test::Src, test::Dst, test::Context, false, false, false, {0u8}>::{constant#0}` failed
- --> $DIR/wrong-type-assume.rs:26:15
- |
-LL | { from_options(ASSUME_ALIGNMENT, ASSUME_LIFETIMES, ASSUME_SAFETY, ASSUME_VALIDITY) }
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
-
-error: aborting due to 8 previous errors
+error: aborting due to 4 previous errors
-Some errors have detailed explanations: E0080, E0308.
-For more information about an error, try `rustc --explain E0080`.
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/transmute-equal-assoc-types.rs b/src/test/ui/transmute-equal-assoc-types.rs
index 6f357543e..d1b593b7f 100644
--- a/src/test/ui/transmute-equal-assoc-types.rs
+++ b/src/test/ui/transmute-equal-assoc-types.rs
@@ -1,9 +1,11 @@
+// check-pass
+
trait Foo {
type Bar;
}
unsafe fn noop<F: Foo>(foo: F::Bar) -> F::Bar {
- ::std::mem::transmute(foo) //~ ERROR cannot transmute between types of different sizes
+ ::std::mem::transmute(foo)
}
fn main() {}
diff --git a/src/test/ui/transmute-equal-assoc-types.stderr b/src/test/ui/transmute-equal-assoc-types.stderr
deleted file mode 100644
index ce7657f96..000000000
--- a/src/test/ui/transmute-equal-assoc-types.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
- --> $DIR/transmute-equal-assoc-types.rs:6:5
- |
-LL | ::std::mem::transmute(foo)
- | ^^^^^^^^^^^^^^^^^^^^^
- |
- = note: `<F as Foo>::Bar` does not have a fixed size
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0512`.
diff --git a/src/test/ui/transmute/lifetimes.rs b/src/test/ui/transmute/lifetimes.rs
new file mode 100644
index 000000000..943191551
--- /dev/null
+++ b/src/test/ui/transmute/lifetimes.rs
@@ -0,0 +1,23 @@
+// check-pass
+
+use std::ptr::NonNull;
+
+struct Foo<'a, T: ?Sized>(&'a (), NonNull<T>);
+
+fn foo<'a, 'b, T: ?Sized>(x: Foo<'a, T>) -> Foo<'b, T> {
+ unsafe { std::mem::transmute(x) }
+}
+
+struct Bar<'a, T: ?Sized>(&'a T);
+
+fn bar<'a, 'b, T: ?Sized>(x: Bar<'a, T>) -> Bar<'b, T> {
+ unsafe { std::mem::transmute(x) }
+}
+
+struct Boo<'a, T: ?Sized>(&'a T, u32);
+
+fn boo<'a, 'b, T: ?Sized>(x: Boo<'a, T>) -> Boo<'b, T> {
+ unsafe { std::mem::transmute(x) }
+}
+
+fn main() {}
diff --git a/src/test/ui/transmute/main.rs b/src/test/ui/transmute/main.rs
index cb46fc5ec..da4a0a660 100644
--- a/src/test/ui/transmute/main.rs
+++ b/src/test/ui/transmute/main.rs
@@ -10,7 +10,7 @@ pub trait TypeConstructor<'a> {
unsafe fn transmute_lifetime<'a, 'b, C>(x: <C as TypeConstructor<'a>>::T)
-> <C as TypeConstructor<'b>>::T
where for<'z> C: TypeConstructor<'z> {
- transmute(x) //~ ERROR cannot transmute between types of different sizes
+ transmute(x)
}
unsafe fn sizes() {
diff --git a/src/test/ui/transmute/main.stderr b/src/test/ui/transmute/main.stderr
index f48562094..6cb0d7f67 100644
--- a/src/test/ui/transmute/main.stderr
+++ b/src/test/ui/transmute/main.stderr
@@ -1,12 +1,4 @@
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
- --> $DIR/main.rs:13:5
- |
-LL | transmute(x)
- | ^^^^^^^^^
- |
- = note: `<C as TypeConstructor>::T` does not have a fixed size
-
-error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/main.rs:17:17
|
LL | let x: u8 = transmute(10u16);
@@ -33,6 +25,6 @@ LL | let x: Foo = transmute(10);
= note: source type: `i32` (32 bits)
= note: target type: `Foo` (0 bits)
-error: aborting due to 4 previous errors
+error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0512`.
diff --git a/src/test/ui/treat-err-as-bug/delay_span_bug.rs b/src/test/ui/treat-err-as-bug/delay_span_bug.rs
index d4d44049c..832afddf8 100644
--- a/src/test/ui/treat-err-as-bug/delay_span_bug.rs
+++ b/src/test/ui/treat-err-as-bug/delay_span_bug.rs
@@ -1,7 +1,7 @@
// compile-flags: -Ztreat-err-as-bug
// failure-status: 101
// error-pattern: aborting due to `-Z treat-err-as-bug=1`
-// error-pattern: [trigger_delay_span_bug] trigger a delay span bug
+// error-pattern: [trigger_delay_span_bug] triggering a delay span bug
// normalize-stderr-test "note: .*\n\n" -> ""
// normalize-stderr-test "thread 'rustc' panicked.*\n" -> ""
// rustc-env:RUST_BACKTRACE=0
diff --git a/src/test/ui/treat-err-as-bug/delay_span_bug.stderr b/src/test/ui/treat-err-as-bug/delay_span_bug.stderr
index c23c2b81b..e9457c8fa 100644
--- a/src/test/ui/treat-err-as-bug/delay_span_bug.stderr
+++ b/src/test/ui/treat-err-as-bug/delay_span_bug.stderr
@@ -7,5 +7,5 @@ LL | fn main() {}
error: internal compiler error: unexpected panic
query stack during panic:
-#0 [trigger_delay_span_bug] trigger a delay span bug
+#0 [trigger_delay_span_bug] triggering a delay span bug
end of query stack
diff --git a/src/test/ui/try-trait/bad-interconversion.stderr b/src/test/ui/try-trait/bad-interconversion.stderr
index 27e6a603a..419a86bf3 100644
--- a/src/test/ui/try-trait/bad-interconversion.stderr
+++ b/src/test/ui/try-trait/bad-interconversion.stderr
@@ -16,7 +16,7 @@ LL | Ok(Err(123_i32)?)
<f64 as From<i16>>
<f64 as From<i32>>
<f64 as From<i8>>
- and 67 others
+ and 68 others
= note: required for `Result<u64, u8>` to implement `FromResidual<Result<Infallible, i32>>`
error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`
diff --git a/src/test/ui/type-alias-enum-variants/enum-variant-priority-lint-ambiguous_associated_items.stderr b/src/test/ui/type-alias-enum-variants/enum-variant-priority-lint-ambiguous_associated_items.stderr
index aaa3159e0..0202a2fea 100644
--- a/src/test/ui/type-alias-enum-variants/enum-variant-priority-lint-ambiguous_associated_items.stderr
+++ b/src/test/ui/type-alias-enum-variants/enum-variant-priority-lint-ambiguous_associated_items.stderr
@@ -4,7 +4,6 @@ error: ambiguous associated item
LL | fn f() -> Self::V { 0 }
| ^^^^^^^ help: use fully-qualified syntax: `<E as Tr>::V`
|
- = note: `#[deny(ambiguous_associated_items)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #57644 <https://github.com/rust-lang/rust/issues/57644>
note: `V` could refer to the variant defined here
@@ -17,6 +16,7 @@ note: `V` could also refer to the associated type defined here
|
LL | type V;
| ^^^^^^
+ = note: `#[deny(ambiguous_associated_items)]` on by default
error: ambiguous associated item
--> $DIR/enum-variant-priority-lint-ambiguous_associated_items.rs:32:15
diff --git a/src/test/ui/type-alias-impl-trait/closure_parent_substs.rs b/src/test/ui/type-alias-impl-trait/closure_parent_substs.rs
new file mode 100644
index 000000000..475f4724f
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/closure_parent_substs.rs
@@ -0,0 +1,65 @@
+// When WF checking the hidden type in the ParamEnv of the opaque type,
+// one complication arises when the hidden type is a closure/generator:
+// the "parent_substs" of the type may reference lifetime parameters
+// not present in the opaque type.
+// These region parameters are not really useful in this check.
+// So here we ignore them and replace them with fresh region variables.
+
+// check-pass
+
+#![feature(type_alias_impl_trait)]
+#![allow(dead_code)]
+
+// Basic test
+mod test1 {
+ // Hidden type = Closure['_#0r]
+ type Opaque = impl Sized;
+
+ fn define<'a: 'a>() -> Opaque {
+ || {}
+ }
+}
+
+// the region vars cannot both be equal to `'static` or `'empty`
+mod test2 {
+ trait Trait {}
+
+ // Hidden type = Closure['a, '_#0r, '_#1r]
+ // Constraints = [('_#0r: 'a), ('a: '_#1r)]
+ type Opaque<'a>
+ where
+ &'a (): Trait,
+ = impl Sized + 'a;
+
+ fn define<'a, 'x, 'y>() -> Opaque<'a>
+ where
+ &'a (): Trait,
+ 'x: 'a,
+ 'a: 'y,
+ {
+ || {}
+ }
+}
+
+// the region var cannot be equal to `'a` or `'b`
+mod test3 {
+ trait Trait {}
+
+ // Hidden type = Closure['a, 'b, '_#0r]
+ // Constraints = [('_#0r: 'a), ('_#0r: 'b)]
+ type Opaque<'a, 'b>
+ where
+ (&'a (), &'b ()): Trait,
+ = impl Sized + 'a + 'b;
+
+ fn define<'a, 'b, 'x>() -> Opaque<'a, 'b>
+ where
+ (&'a (), &'b ()): Trait,
+ 'x: 'a,
+ 'x: 'b,
+ {
+ || {}
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/type-alias-impl-trait/closure_wf_outlives.rs b/src/test/ui/type-alias-impl-trait/closure_wf_outlives.rs
new file mode 100644
index 000000000..53974dbb3
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/closure_wf_outlives.rs
@@ -0,0 +1,65 @@
+// If the hidden type is a closure, we require the "outlives" bounds that appear on the
+// defining site to also appear on the opaque type.
+//
+// It's not clear if this is the desired behavior but at least
+// it's consistent and has no back-compat risk.
+
+// check-fail
+
+#![feature(type_alias_impl_trait)]
+#![allow(dead_code)]
+
+// requires `'a: 'b` bound
+mod test1 {
+ type Opaque<'a, 'b> = impl Sized + 'a + 'b;
+ //~^ ERROR lifetime bound not satisfied
+
+ fn define<'a, 'b>() -> Opaque<'a, 'b>
+ where
+ 'a: 'b,
+ {
+ || {}
+ }
+}
+
+// Same as the above but through indirection `'x`
+mod test2 {
+ type Opaque<'a, 'b> = impl Sized + 'a + 'b;
+ //~^ ERROR cannot infer an appropriate lifetime
+
+ fn define<'a, 'b, 'x>() -> Opaque<'a, 'b>
+ where
+ 'a: 'x,
+ 'x: 'b,
+ {
+ || {}
+ }
+}
+
+// fixed version of the above
+mod test2_fixed {
+ type Opaque<'a: 'b, 'b> = impl Sized + 'a + 'b;
+
+ fn define<'a, 'b, 'x>() -> Opaque<'a, 'b>
+ where
+ 'a: 'x,
+ 'x: 'b,
+ {
+ || {}
+ }
+}
+
+// requires `T: 'static`
+mod test3 {
+ type Opaque<T> = impl Sized;
+ //~^ ERROR the parameter type `T` may not live long enough
+
+ fn define<T>() -> Opaque<T>
+ where
+ T: 'static,
+ {
+ || {}
+ }
+}
+
+fn main() {}
diff --git a/src/test/ui/type-alias-impl-trait/closure_wf_outlives.stderr b/src/test/ui/type-alias-impl-trait/closure_wf_outlives.stderr
new file mode 100644
index 000000000..ae6462bb6
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/closure_wf_outlives.stderr
@@ -0,0 +1,64 @@
+error[E0478]: lifetime bound not satisfied
+ --> $DIR/closure_wf_outlives.rs:14:27
+ |
+LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b;
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+note: lifetime parameter instantiated with the lifetime `'a` as defined here
+ --> $DIR/closure_wf_outlives.rs:14:17
+ |
+LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b;
+ | ^^
+note: but lifetime parameter must outlive the lifetime `'b` as defined here
+ --> $DIR/closure_wf_outlives.rs:14:21
+ |
+LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b;
+ | ^^
+
+error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
+ --> $DIR/closure_wf_outlives.rs:27:27
+ |
+LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b;
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+note: first, the lifetime cannot outlive the lifetime `'a` as defined here...
+ --> $DIR/closure_wf_outlives.rs:27:17
+ |
+LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b;
+ | ^^
+note: ...so that the declared lifetime parameter bounds are satisfied
+ --> $DIR/closure_wf_outlives.rs:27:27
+ |
+LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b;
+ | ^^^^^^^^^^^^^^^^^^^^
+note: but, the lifetime must be valid for the lifetime `'b` as defined here...
+ --> $DIR/closure_wf_outlives.rs:27:21
+ |
+LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b;
+ | ^^
+note: ...so that the declared lifetime parameter bounds are satisfied
+ --> $DIR/closure_wf_outlives.rs:27:27
+ |
+LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b;
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error[E0310]: the parameter type `T` may not live long enough
+ --> $DIR/closure_wf_outlives.rs:54:22
+ |
+LL | type Opaque<T> = impl Sized;
+ | ^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds...
+ |
+note: ...that is required by this bound
+ --> $DIR/closure_wf_outlives.rs:59:12
+ |
+LL | T: 'static,
+ | ^^^^^^^
+help: consider adding an explicit lifetime bound...
+ |
+LL | type Opaque<T: 'static> = impl Sized;
+ | +++++++++
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0310, E0478, E0495.
+For more information about an error, try `rustc --explain E0310`.
diff --git a/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs b/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs
index 811832848..9a50c0f98 100644
--- a/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs
+++ b/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs
@@ -1,8 +1,9 @@
// compile-flags: --edition=2021
+// check-pass
#![feature(type_alias_impl_trait)]
fn main() {
- type T = impl Copy; //~ ERROR unconstrained opaque type
+ type T = impl Copy;
let foo: T = (1u32, 2u32);
let (a, b): (u32, u32) = foo;
}
diff --git a/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.stderr b/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.stderr
deleted file mode 100644
index 03b172e6d..000000000
--- a/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.stderr
+++ /dev/null
@@ -1,10 +0,0 @@
-error: unconstrained opaque type
- --> $DIR/cross_inference_pattern_bug.rs:5:14
- |
-LL | type T = impl Copy;
- | ^^^^^^^^^
- |
- = note: `T` must be used in combination with a concrete type within the same module
-
-error: aborting due to previous error
-
diff --git a/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug_no_type.rs b/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug_no_type.rs
index 328096d44..b929122a6 100644
--- a/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug_no_type.rs
+++ b/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug_no_type.rs
@@ -1,13 +1,13 @@
-// known-bug: #96572
// compile-flags: --edition=2021 --crate-type=lib
// rustc-env:RUST_BACKTRACE=0
+// check-pass
// tracked in https://github.com/rust-lang/rust/issues/96572
#![feature(type_alias_impl_trait)]
fn main() {
- type T = impl Copy; // error: unconstrained opaque type
+ type T = impl Copy;
let foo: T = (1u32, 2u32);
- let (a, b) = foo; // removing this line makes the code compile
+ let (a, b) = foo; // this line used to make the code fail
}
diff --git a/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug_no_type.stderr b/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug_no_type.stderr
deleted file mode 100644
index 8aa1f4956..000000000
--- a/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug_no_type.stderr
+++ /dev/null
@@ -1,10 +0,0 @@
-error: unconstrained opaque type
- --> $DIR/cross_inference_pattern_bug_no_type.rs:10:14
- |
-LL | type T = impl Copy; // error: unconstrained opaque type
- | ^^^^^^^^^
- |
- = note: `T` must be used in combination with a concrete type within the same module
-
-error: aborting due to previous error
-
diff --git a/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.rs b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.rs
index 7740f774e..0b8157fe3 100644
--- a/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.rs
+++ b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.rs
@@ -1,5 +1,5 @@
#![feature(type_alias_impl_trait)]
-// check-pass
+
fn main() {}
// two definitions with different types
@@ -9,7 +9,7 @@ fn foo() -> Foo {
""
}
-fn bar() -> Foo {
+fn bar() -> Foo { //~ ERROR: concrete type differs from previous defining opaque type use
panic!()
}
diff --git a/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.stderr b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.stderr
new file mode 100644
index 000000000..09dadb0af
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.stderr
@@ -0,0 +1,14 @@
+error: concrete type differs from previous defining opaque type use
+ --> $DIR/different_defining_uses_never_type.rs:12:13
+ |
+LL | fn bar() -> Foo {
+ | ^^^ expected `&'static str`, got `()`
+ |
+note: previous use here
+ --> $DIR/different_defining_uses_never_type.rs:9:5
+ |
+LL | ""
+ | ^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type3.rs b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type3.rs
new file mode 100644
index 000000000..bc827a8f2
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type3.rs
@@ -0,0 +1,12 @@
+#![feature(type_alias_impl_trait)]
+
+type Tait = impl Sized;
+
+struct One;
+fn one() -> Tait { One }
+
+struct Two<T>(T);
+fn two() -> Tait { Two::<()>(todo!()) }
+//~^ ERROR concrete type differs from previous defining opaque type use
+
+fn main() {}
diff --git a/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type3.stderr b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type3.stderr
new file mode 100644
index 000000000..146a57cbb
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type3.stderr
@@ -0,0 +1,14 @@
+error: concrete type differs from previous defining opaque type use
+ --> $DIR/different_defining_uses_never_type3.rs:9:13
+ |
+LL | fn two() -> Tait { Two::<()>(todo!()) }
+ | ^^^^ expected `One`, got `Two<()>`
+ |
+note: previous use here
+ --> $DIR/different_defining_uses_never_type3.rs:6:20
+ |
+LL | fn one() -> Tait { One }
+ | ^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs b/src/test/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs
index 4f424b8c6..5f75fdc71 100644
--- a/src/test/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs
+++ b/src/test/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs
@@ -1,7 +1,11 @@
#![feature(type_alias_impl_trait)]
#![allow(dead_code)]
-type OneLifetime<'a, 'b> = impl std::fmt::Debug;
+pub trait Captures<'a> {}
+
+impl<'a, T: ?Sized> Captures<'a> for T {}
+
+type OneLifetime<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
fn foo<'a, 'b>(a: &'a u32, b: &'b u32) -> OneLifetime<'a, 'b> {
a
diff --git a/src/test/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr b/src/test/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr
index 0c50a84e8..546598e8a 100644
--- a/src/test/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr
+++ b/src/test/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr
@@ -1,11 +1,11 @@
error: concrete type differs from previous defining opaque type use
- --> $DIR/different_lifetimes_defining_uses.rs:11:5
+ --> $DIR/different_lifetimes_defining_uses.rs:15:5
|
LL | b
| ^ expected `&'a u32`, got `&'b u32`
|
note: previous use here
- --> $DIR/different_lifetimes_defining_uses.rs:7:5
+ --> $DIR/different_lifetimes_defining_uses.rs:11:5
|
LL | a
| ^
diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs
index c9b9e128f..9d938a616 100644
--- a/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs
+++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs
@@ -2,8 +2,11 @@
fn main() {}
-type Two<'a, 'b> = impl std::fmt::Debug;
+pub trait Captures<'a> {}
+impl<'a, T: ?Sized> Captures<'a> for T {}
+
+type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
fn one<'a>(t: &'a ()) -> Two<'a, 'a> {
t
diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr
index 222aaea78..72e1ef4b4 100644
--- a/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr
+++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr
@@ -1,13 +1,13 @@
error: non-defining opaque type use in defining scope
- --> $DIR/generic_duplicate_lifetime_param.rs:9:5
+ --> $DIR/generic_duplicate_lifetime_param.rs:12:5
|
LL | t
| ^
|
note: lifetime used multiple times
- --> $DIR/generic_duplicate_lifetime_param.rs:5:10
+ --> $DIR/generic_duplicate_lifetime_param.rs:9:10
|
-LL | type Two<'a, 'b> = impl std::fmt::Debug;
+LL | type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
| ^^ ^^
error: aborting due to previous error
diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs
index 093c1c231..80462f8ac 100644
--- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs
+++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs
@@ -7,7 +7,12 @@ fn main() {}
// test that unused generic parameters are ok
type TwoTys<T, U> = impl Debug;
-type TwoLifetimes<'a, 'b> = impl Debug;
+
+pub trait Captures<'a> {}
+
+impl<'a, T: ?Sized> Captures<'a> for T {}
+
+type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>;
type TwoConsts<const X: usize, const Y: usize> = impl Debug;
diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr
index b2edcc552..98e4bfea1 100644
--- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr
+++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr
@@ -1,5 +1,5 @@
error: non-defining opaque type use in defining scope
- --> $DIR/generic_duplicate_param_use.rs:16:5
+ --> $DIR/generic_duplicate_param_use.rs:21:5
|
LL | t
| ^
@@ -11,25 +11,25 @@ LL | type TwoTys<T, U> = impl Debug;
| ^ ^
error: non-defining opaque type use in defining scope
- --> $DIR/generic_duplicate_param_use.rs:21:5
+ --> $DIR/generic_duplicate_param_use.rs:26:5
|
LL | t
| ^
|
note: lifetime used multiple times
- --> $DIR/generic_duplicate_param_use.rs:10:19
+ --> $DIR/generic_duplicate_param_use.rs:15:19
|
-LL | type TwoLifetimes<'a, 'b> = impl Debug;
+LL | type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>;
| ^^ ^^
error: non-defining opaque type use in defining scope
- --> $DIR/generic_duplicate_param_use.rs:26:5
+ --> $DIR/generic_duplicate_param_use.rs:31:5
|
LL | t
| ^
|
note: constant used multiple times
- --> $DIR/generic_duplicate_param_use.rs:12:16
+ --> $DIR/generic_duplicate_param_use.rs:17:16
|
LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
| ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
diff --git a/src/test/ui/type-alias-impl-trait/generic_lifetime_param.rs b/src/test/ui/type-alias-impl-trait/generic_lifetime_param.rs
index e109c38c9..106efefba 100644
--- a/src/test/ui/type-alias-impl-trait/generic_lifetime_param.rs
+++ b/src/test/ui/type-alias-impl-trait/generic_lifetime_param.rs
@@ -1,10 +1,11 @@
-// build-pass (FIXME(62277): could be check-pass?)
+// check-pass
#![feature(type_alias_impl_trait)]
fn main() {}
-type Region<'a> = impl std::fmt::Debug;
+type Region<'a> = impl std::fmt::Debug + 'a;
+
fn region<'b>(a: &'b ()) -> Region<'b> {
a
diff --git a/src/test/ui/type-alias-impl-trait/implied_bounds.rs b/src/test/ui/type-alias-impl-trait/implied_bounds.rs
new file mode 100644
index 000000000..53cbf8d22
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/implied_bounds.rs
@@ -0,0 +1,51 @@
+#![feature(type_alias_impl_trait)]
+
+type WithLifetime<'a> = impl Equals<SelfType = ()>;
+fn _defining_use<'a>() -> WithLifetime<'a> {}
+
+trait Convert<'a> {
+ type Witness;
+ fn convert<'b, T: ?Sized>(_proof: &'b Self::Witness, x: &'a T) -> &'b T;
+}
+
+impl<'a> Convert<'a> for () {
+ type Witness = WithLifetime<'a>;
+
+ fn convert<'b, T: ?Sized>(_proof: &'b WithLifetime<'a>, x: &'a T) -> &'b T {
+ // compiler used to think it gets to assume 'a: 'b here because
+ // of the `&'b WithLifetime<'a>` argument
+ x
+ //~^ ERROR lifetime may not live long enough
+ }
+}
+
+fn extend_lifetime<'a, 'b, T: ?Sized>(x: &'a T) -> &'b T {
+ WithLifetime::<'a>::convert_helper::<(), T>(&(), x)
+}
+
+trait Equals {
+ type SelfType;
+ fn convert_helper<'a, 'b, W: Convert<'a, Witness = Self>, T: ?Sized>(
+ proof: &'b Self::SelfType,
+ x: &'a T,
+ ) -> &'b T;
+}
+
+impl<S> Equals for S {
+ type SelfType = Self;
+ fn convert_helper<'a, 'b, W: Convert<'a, Witness = Self>, T: ?Sized>(
+ proof: &'b Self,
+ x: &'a T,
+ ) -> &'b T {
+ W::convert(proof, x)
+ }
+}
+
+fn main() {
+ let r;
+ {
+ let x = String::from("Hello World?");
+ r = extend_lifetime(&x);
+ }
+ println!("{}", r);
+}
diff --git a/src/test/ui/type-alias-impl-trait/implied_bounds.stderr b/src/test/ui/type-alias-impl-trait/implied_bounds.stderr
new file mode 100644
index 000000000..6f11b6663
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/implied_bounds.stderr
@@ -0,0 +1,16 @@
+error: lifetime may not live long enough
+ --> $DIR/implied_bounds.rs:17:9
+ |
+LL | impl<'a> Convert<'a> for () {
+ | -- lifetime `'a` defined here
+...
+LL | fn convert<'b, T: ?Sized>(_proof: &'b WithLifetime<'a>, x: &'a T) -> &'b T {
+ | -- lifetime `'b` defined here
+...
+LL | x
+ | ^ associated function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
+ |
+ = help: consider adding the following bound: `'a: 'b`
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/type-alias-impl-trait/implied_bounds2.rs b/src/test/ui/type-alias-impl-trait/implied_bounds2.rs
new file mode 100644
index 000000000..b4c4c013c
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/implied_bounds2.rs
@@ -0,0 +1,10 @@
+// check-pass
+
+#![feature(type_alias_impl_trait)]
+
+type Ty<'a, A> = impl Sized + 'a;
+fn defining<'a, A>() -> Ty<'a, A> {}
+fn assert_static<T: 'static>() {}
+fn test<'a, A>() where Ty<'a, A>: 'static, { assert_static::<Ty<'a, A>>() }
+
+fn main() {}
diff --git a/src/test/ui/type-alias-impl-trait/implied_bounds3.rs b/src/test/ui/type-alias-impl-trait/implied_bounds3.rs
new file mode 100644
index 000000000..e39c61328
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/implied_bounds3.rs
@@ -0,0 +1,18 @@
+// check-pass
+
+fn foo<F>(_: F)
+where
+ F: 'static,
+{
+}
+
+fn from<F: Send>(f: F) -> impl Send {
+ f
+}
+
+fn bar<T>() {
+ foo(from(|| ()))
+}
+
+fn main() {
+}
diff --git a/src/test/ui/type-alias-impl-trait/implied_bounds_closure.rs b/src/test/ui/type-alias-impl-trait/implied_bounds_closure.rs
new file mode 100644
index 000000000..4cf35f951
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/implied_bounds_closure.rs
@@ -0,0 +1,31 @@
+trait StaticDefaultRef: 'static {
+ fn default_ref() -> &'static Self;
+}
+
+impl StaticDefaultRef for str {
+ fn default_ref() -> &'static str {
+ ""
+ }
+}
+
+fn into_impl(x: &str) -> &(impl ?Sized + AsRef<str> + StaticDefaultRef + '_) {
+ x
+}
+
+fn extend_lifetime<'a>(x: &'a str) -> &'static str {
+ let t = into_impl(x);
+ helper(|_| t) //~ ERROR lifetime may not live long enough
+}
+
+fn helper<T: ?Sized + AsRef<str> + StaticDefaultRef>(f: impl FnOnce(&T) -> &T) -> &'static str {
+ f(T::default_ref()).as_ref()
+}
+
+fn main() {
+ let r;
+ {
+ let x = String::from("Hello World?");
+ r = extend_lifetime(&x);
+ }
+ println!("{}", r);
+}
diff --git a/src/test/ui/type-alias-impl-trait/implied_bounds_closure.stderr b/src/test/ui/type-alias-impl-trait/implied_bounds_closure.stderr
new file mode 100644
index 000000000..151564c3b
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/implied_bounds_closure.stderr
@@ -0,0 +1,11 @@
+error: lifetime may not live long enough
+ --> $DIR/implied_bounds_closure.rs:17:16
+ |
+LL | fn extend_lifetime<'a>(x: &'a str) -> &'static str {
+ | -- lifetime `'a` defined here
+LL | let t = into_impl(x);
+LL | helper(|_| t)
+ | ^ returning this value requires that `'a` must outlive `'static`
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/type-alias-impl-trait/implied_bounds_from_types.rs b/src/test/ui/type-alias-impl-trait/implied_bounds_from_types.rs
new file mode 100644
index 000000000..8023cd24f
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/implied_bounds_from_types.rs
@@ -0,0 +1,51 @@
+#![feature(type_alias_impl_trait)]
+
+type WithLifetime<T> = impl Equals<SelfType = ()>;
+fn _defining_use<T>() -> WithLifetime<T> {}
+
+trait Convert<'a> {
+ type Witness;
+ fn convert<'b, T: ?Sized>(_proof: &'b Self::Witness, x: &'a T) -> &'b T;
+}
+
+impl<'a> Convert<'a> for () {
+ type Witness = WithLifetime<&'a ()>;
+
+ fn convert<'b, T: ?Sized>(_proof: &'b WithLifetime<&'a ()>, x: &'a T) -> &'b T {
+ // compiler used to think it gets to assume 'a: 'b here because
+ // of the `&'b WithLifetime<&'a ()>` argument
+ x
+ //~^ ERROR lifetime may not live long enough
+ }
+}
+
+fn extend_lifetime<'a, 'b, T: ?Sized>(x: &'a T) -> &'b T {
+ WithLifetime::<&'a ()>::convert_helper::<(), T>(&(), x)
+}
+
+trait Equals {
+ type SelfType;
+ fn convert_helper<'a, 'b, W: Convert<'a, Witness = Self>, T: ?Sized>(
+ proof: &'b Self::SelfType,
+ x: &'a T,
+ ) -> &'b T;
+}
+
+impl<S> Equals for S {
+ type SelfType = Self;
+ fn convert_helper<'a, 'b, W: Convert<'a, Witness = Self>, T: ?Sized>(
+ proof: &'b Self,
+ x: &'a T,
+ ) -> &'b T {
+ W::convert(proof, x)
+ }
+}
+
+fn main() {
+ let r;
+ {
+ let x = String::from("Hello World?");
+ r = extend_lifetime(&x);
+ }
+ println!("{}", r);
+}
diff --git a/src/test/ui/type-alias-impl-trait/implied_bounds_from_types.stderr b/src/test/ui/type-alias-impl-trait/implied_bounds_from_types.stderr
new file mode 100644
index 000000000..cbc5e6073
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/implied_bounds_from_types.stderr
@@ -0,0 +1,16 @@
+error: lifetime may not live long enough
+ --> $DIR/implied_bounds_from_types.rs:17:9
+ |
+LL | impl<'a> Convert<'a> for () {
+ | -- lifetime `'a` defined here
+...
+LL | fn convert<'b, T: ?Sized>(_proof: &'b WithLifetime<&'a ()>, x: &'a T) -> &'b T {
+ | -- lifetime `'b` defined here
+...
+LL | x
+ | ^ associated function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
+ |
+ = help: consider adding the following bound: `'a: 'b`
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check.rs b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check.rs
new file mode 100644
index 000000000..b6a7264a5
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check.rs
@@ -0,0 +1,27 @@
+#![feature(type_alias_impl_trait)]
+
+// known-bug: #99840
+// this should not compile
+// check-pass
+
+type Alias = impl Sized;
+
+fn constrain() -> Alias {
+ 1i32
+}
+
+trait HideIt {
+ type Assoc;
+}
+
+impl HideIt for () {
+ type Assoc = Alias;
+}
+
+pub trait Yay {}
+
+impl Yay for <() as HideIt>::Assoc {}
+// impl Yay for i32 {} // this already errors
+// impl Yay for u32 {} // this also already errors
+
+fn main() {}
diff --git a/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs
new file mode 100644
index 000000000..07f825aea
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs
@@ -0,0 +1,43 @@
+#![feature(type_alias_impl_trait)]
+
+mod test_lifetime_param {
+ type Ty<'a> = impl Sized + 'a;
+ fn defining(a: &str) -> Ty<'_> { a }
+ fn assert_static<'a: 'static>() {}
+ //~^ WARN: unnecessary lifetime parameter `'a`
+ fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
+ //~^ ERROR: lifetime may not live long enough
+}
+
+mod test_higher_kinded_lifetime_param {
+ type Ty<'a> = impl Sized + 'a;
+ fn defining(a: &str) -> Ty<'_> { a }
+ fn assert_static<'a: 'static>() {}
+ //~^ WARN: unnecessary lifetime parameter `'a`
+ fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() }
+ //~^ ERROR: lifetime may not live long enough
+}
+
+mod test_higher_kinded_lifetime_param2 {
+ fn assert_static<'a: 'static>() {}
+ //~^ WARN: unnecessary lifetime parameter `'a`
+ fn test<'a>() { assert_static::<'a>() }
+ //~^ ERROR: lifetime may not live long enough
+}
+
+mod test_type_param {
+ type Ty<A> = impl Sized;
+ fn defining<A>(s: A) -> Ty<A> { s }
+ fn assert_static<A: 'static>() {}
+ fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
+ //~^ ERROR: parameter type `A` may not live long enough
+}
+
+mod test_implied_from_fn_sig {
+ type Opaque<T: 'static> = impl Sized;
+ fn defining<T: 'static>() -> Opaque<T> {}
+ fn assert_static<T: 'static>() {}
+ fn test<T>(_: Opaque<T>) { assert_static::<T>(); }
+}
+
+fn main() {}
diff --git a/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr
new file mode 100644
index 000000000..887620a4d
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr
@@ -0,0 +1,58 @@
+warning: unnecessary lifetime parameter `'a`
+ --> $DIR/implied_lifetime_wf_check3.rs:6:22
+ |
+LL | fn assert_static<'a: 'static>() {}
+ | ^^
+ |
+ = help: you can use the `'static` lifetime directly, in place of `'a`
+
+warning: unnecessary lifetime parameter `'a`
+ --> $DIR/implied_lifetime_wf_check3.rs:15:22
+ |
+LL | fn assert_static<'a: 'static>() {}
+ | ^^
+ |
+ = help: you can use the `'static` lifetime directly, in place of `'a`
+
+warning: unnecessary lifetime parameter `'a`
+ --> $DIR/implied_lifetime_wf_check3.rs:22:22
+ |
+LL | fn assert_static<'a: 'static>() {}
+ | ^^
+ |
+ = help: you can use the `'static` lifetime directly, in place of `'a`
+
+error: lifetime may not live long enough
+ --> $DIR/implied_lifetime_wf_check3.rs:8:43
+ |
+LL | fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() }
+ | -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
+
+error: lifetime may not live long enough
+ --> $DIR/implied_lifetime_wf_check3.rs:17:46
+ |
+LL | fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() }
+ | -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
+
+error: lifetime may not live long enough
+ --> $DIR/implied_lifetime_wf_check3.rs:24:21
+ |
+LL | fn test<'a>() { assert_static::<'a>() }
+ | -- ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
+ | |
+ | lifetime `'a` defined here
+
+error[E0310]: the parameter type `A` may not live long enough
+ --> $DIR/implied_lifetime_wf_check3.rs:32:41
+ |
+LL | fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
+ | ^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds
+ |
+help: consider adding an explicit lifetime bound...
+ |
+LL | fn test<A: 'static>() where Ty<A>: 'static { assert_static::<A>() }
+ | +++++++++
+
+error: aborting due to 4 previous errors; 3 warnings emitted
+
+For more information about this error, try `rustc --explain E0310`.
diff --git a/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs
new file mode 100644
index 000000000..ac32dbde0
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs
@@ -0,0 +1,11 @@
+#![feature(type_alias_impl_trait)]
+
+mod test_type_param_static {
+ type Ty<A> = impl Sized + 'static;
+ //~^ ERROR: the parameter type `A` may not live long enough
+ fn defining<A: 'static>(s: A) -> Ty<A> { s }
+ fn assert_static<A: 'static>() {}
+ fn test<A>() where Ty<A>: 'static { assert_static::<A>() }
+}
+
+fn main() {}
diff --git a/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr
new file mode 100644
index 000000000..47bc31e78
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr
@@ -0,0 +1,14 @@
+error[E0310]: the parameter type `A` may not live long enough
+ --> $DIR/implied_lifetime_wf_check4_static.rs:4:18
+ |
+LL | type Ty<A> = impl Sized + 'static;
+ | ^^^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds
+ |
+help: consider adding an explicit lifetime bound...
+ |
+LL | type Ty<A: 'static> = impl Sized + 'static;
+ | +++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0310`.
diff --git a/src/test/ui/type-alias-impl-trait/issue-101750.rs b/src/test/ui/type-alias-impl-trait/issue-101750.rs
new file mode 100644
index 000000000..f564f4fa7
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/issue-101750.rs
@@ -0,0 +1,37 @@
+#![feature(type_alias_impl_trait)]
+
+// check-pass
+
+trait Trait {}
+
+type TAIT = impl Trait;
+
+struct Concrete;
+impl Trait for Concrete {}
+
+fn tait() -> TAIT {
+ Concrete
+}
+
+trait OuterTrait {
+ type Item;
+}
+struct Dummy<T> {
+ t: T,
+}
+impl<T> OuterTrait for Dummy<T> {
+ type Item = T;
+}
+
+fn tait_and_impl_trait() -> impl OuterTrait<Item = (TAIT, impl Trait)> {
+ Dummy {
+ t: (tait(), Concrete),
+ }
+}
+
+fn tait_and_dyn_trait() -> impl OuterTrait<Item = (TAIT, Box<dyn Trait>)> {
+ let b: Box<dyn Trait> = Box::new(Concrete);
+ Dummy { t: (tait(), b) }
+}
+
+fn main() {}
diff --git a/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr b/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr
index d20b1cc6d..0a34e8486 100644
--- a/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr
+++ b/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr
@@ -1,10 +1,11 @@
-error[E0275]: overflow evaluating the requirement `fn() -> Foo {foo}: Sized`
+error[E0275]: overflow evaluating the requirement `Foo: Sized`
--> $DIR/issue-53398-cyclic-types.rs:5:13
|
LL | fn foo() -> Foo {
| ^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_53398_cyclic_types`)
+ = note: required because it appears within the type `fn() -> Foo {foo}`
error: aborting due to previous error
diff --git a/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr b/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr
index f14bf6b0f..6344f114a 100644
--- a/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr
+++ b/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr
@@ -4,7 +4,7 @@ error[E0308]: mismatched types
LL | |x| x
| ^^^^^ one type is more general than the other
|
- = note: expected trait `for<'r> Fn<(&'r X,)>`
+ = note: expected trait `for<'a> Fn<(&'a X,)>`
found trait `Fn<(&X,)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/issue-57611-trait-alias.rs:21:9
diff --git a/src/test/ui/type-alias-impl-trait/issue-58662-generator-with-lifetime.rs b/src/test/ui/type-alias-impl-trait/issue-58662-generator-with-lifetime.rs
index f20ddf020..477b61390 100644
--- a/src/test/ui/type-alias-impl-trait/issue-58662-generator-with-lifetime.rs
+++ b/src/test/ui/type-alias-impl-trait/issue-58662-generator-with-lifetime.rs
@@ -16,7 +16,7 @@ fn rand_generator<'a>(rng: &'a ()) -> RandGenerator<'a> {
}
}
-pub type RandGeneratorWithIndirection<'a> = impl Generator<Return = (), Yield = u64> + 'a;
+pub type RandGeneratorWithIndirection<'c> = impl Generator<Return = (), Yield = u64> + 'c;
pub fn rand_generator_with_indirection<'a>(rng: &'a ()) -> RandGeneratorWithIndirection<'a> {
fn helper<'b>(rng: &'b ()) -> impl 'b + Generator<Return = (), Yield = u64> {
move || {
diff --git a/src/test/ui/type-alias-impl-trait/issue-58662-simplified.rs b/src/test/ui/type-alias-impl-trait/issue-58662-simplified.rs
new file mode 100644
index 000000000..27ca7d0fd
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/issue-58662-simplified.rs
@@ -0,0 +1,20 @@
+// check-pass
+
+#![feature(generators, generator_trait)]
+#![feature(type_alias_impl_trait)]
+
+trait Trait {}
+
+impl<T> Trait for T {}
+
+type Foo<'c> = impl Trait + 'c;
+fn foo<'a>(rng: &'a ()) -> Foo<'a> {
+ fn helper<'b>(rng: &'b ()) -> impl 'b + Trait {
+ rng
+ }
+
+ helper(rng)
+}
+
+fn main() {
+}
diff --git a/src/test/ui/type-alias-impl-trait/issue-89686.rs b/src/test/ui/type-alias-impl-trait/issue-89686.rs
index de070fc9d..058417bdb 100644
--- a/src/test/ui/type-alias-impl-trait/issue-89686.rs
+++ b/src/test/ui/type-alias-impl-trait/issue-89686.rs
@@ -4,7 +4,7 @@
use std::future::Future;
-type G<'a, T> = impl Future<Output = ()>;
+type G<'a, T> = impl Future<Output = ()> + 'a;
trait Trait {
type F: Future<Output = ()>;
diff --git a/src/test/ui/type-alias-impl-trait/issue-89686.stderr b/src/test/ui/type-alias-impl-trait/issue-89686.stderr
index b636ada8b..3b95a575a 100644
--- a/src/test/ui/type-alias-impl-trait/issue-89686.stderr
+++ b/src/test/ui/type-alias-impl-trait/issue-89686.stderr
@@ -6,7 +6,7 @@ LL | async move { self.f().await }
|
help: consider restricting type parameter `T`
|
-LL | type G<'a, T: Trait> = impl Future<Output = ()>;
+LL | type G<'a, T: Trait> = impl Future<Output = ()> + 'a;
| +++++++
error: aborting due to previous error
diff --git a/src/test/ui/type-alias-impl-trait/issue-96572-unconstrained-mismatch.rs b/src/test/ui/type-alias-impl-trait/issue-96572-unconstrained-mismatch.rs
new file mode 100644
index 000000000..825710851
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/issue-96572-unconstrained-mismatch.rs
@@ -0,0 +1,10 @@
+#![feature(type_alias_impl_trait)]
+
+fn main() {
+ type T = impl Copy;
+ let foo: T = Some((1u32, 2u32));
+ match foo {
+ None => (),
+ Some((a, b, c)) => (), //~ ERROR mismatched types
+ }
+}
diff --git a/src/test/ui/type-alias-impl-trait/issue-96572-unconstrained-mismatch.stderr b/src/test/ui/type-alias-impl-trait/issue-96572-unconstrained-mismatch.stderr
new file mode 100644
index 000000000..728244a18
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/issue-96572-unconstrained-mismatch.stderr
@@ -0,0 +1,15 @@
+error[E0308]: mismatched types
+ --> $DIR/issue-96572-unconstrained-mismatch.rs:8:14
+ |
+LL | match foo {
+ | --- this expression has type `T`
+LL | None => (),
+LL | Some((a, b, c)) => (),
+ | ^^^^^^^^^ expected a tuple with 2 elements, found one with 3 elements
+ |
+ = note: expected tuple `(u32, u32)`
+ found tuple `(_, _, _)`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/type-alias-impl-trait/issue-96572-unconstrained.rs b/src/test/ui/type-alias-impl-trait/issue-96572-unconstrained.rs
new file mode 100644
index 000000000..2c740ccc1
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/issue-96572-unconstrained.rs
@@ -0,0 +1,92 @@
+#![feature(type_alias_impl_trait)]
+// check-pass
+
+fn main() {
+ type T = impl Copy;
+ let foo: T = Some((1u32, 2u32));
+ match foo {
+ None => (),
+ Some((a, b)) => (),
+ }
+}
+
+fn upvar() {
+ #[derive(Copy, Clone)]
+ struct Foo((u32, u32));
+
+ type T = impl Copy;
+ let foo: T = Foo((1u32, 2u32));
+ let x = move || {
+ let Foo((a, b)) = foo;
+ };
+}
+
+fn enum_upvar() {
+ type T = impl Copy;
+ let foo: T = Some((1u32, 2u32));
+ let x = move || {
+ match foo {
+ None => (),
+ Some((a, b)) => (),
+ }
+ };
+}
+
+fn r#struct() {
+ #[derive(Copy, Clone)]
+ struct Foo((u32, u32));
+
+ type U = impl Copy;
+ let foo: U = Foo((1u32, 2u32));
+ let Foo((a, b)) = foo;
+}
+
+mod only_pattern {
+ type T = impl Copy;
+
+ fn foo(foo: T) {
+ let (mut x, mut y) = foo;
+ x = 42;
+ y = "foo";
+ }
+
+ type U = impl Copy;
+
+ fn bar(bar: Option<U>) {
+ match bar {
+ Some((mut x, mut y)) => {
+ x = 42;
+ y = "foo";
+ }
+ None => {}
+ }
+ }
+}
+
+mod only_pattern_rpit {
+ #[allow(unconditional_recursion)]
+ fn foo(b: bool) -> impl Copy {
+ let (mut x, mut y) = foo(false);
+ x = 42;
+ y = "foo";
+ if b {
+ panic!()
+ } else {
+ foo(true)
+ }
+ }
+
+ fn bar(b: bool) -> Option<impl Copy> {
+ if b {
+ return None;
+ }
+ match bar(!b) {
+ Some((mut x, mut y)) => {
+ x = 42;
+ y = "foo";
+ }
+ None => {}
+ }
+ None
+ }
+}
diff --git a/src/test/ui/type-alias-impl-trait/missing_lifetime_bound.rs b/src/test/ui/type-alias-impl-trait/missing_lifetime_bound.rs
new file mode 100644
index 000000000..428194058
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/missing_lifetime_bound.rs
@@ -0,0 +1,7 @@
+#![feature(type_alias_impl_trait)]
+
+type Opaque<'a, T> = impl Sized;
+fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x }
+//~^ ERROR: non-defining opaque type use in defining scope
+
+fn main() {}
diff --git a/src/test/ui/type-alias-impl-trait/missing_lifetime_bound.stderr b/src/test/ui/type-alias-impl-trait/missing_lifetime_bound.stderr
new file mode 100644
index 000000000..df2b3ed19
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/missing_lifetime_bound.stderr
@@ -0,0 +1,8 @@
+error: non-defining opaque type use in defining scope
+ --> $DIR/missing_lifetime_bound.rs:4:47
+ |
+LL | fn defining<'a, T>(x: &'a i32) -> Opaque<T> { x }
+ | ^ lifetime `'a` is part of concrete type but not used in parameter list of the `impl Trait` type alias
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs
index 3f122f106..65eb2952e 100644
--- a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs
+++ b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs
@@ -1,6 +1,10 @@
#![feature(type_alias_impl_trait)]
-type Foo<'a, 'b> = impl std::fmt::Debug;
+pub trait Captures<'a> {}
+
+impl<'a, T: ?Sized> Captures<'a> for T {}
+
+type Foo<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) {
(i, i) //~ ERROR concrete type differs from previous
diff --git a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr
index 81e603e23..d7676b8e9 100644
--- a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr
+++ b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr
@@ -1,5 +1,5 @@
error: concrete type differs from previous defining opaque type use
- --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5
+ --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:10:5
|
LL | (i, i)
| ^^^^^^
diff --git a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs
index 83fd9a1da..21fca047a 100644
--- a/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs
+++ b/src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs
@@ -7,7 +7,11 @@ fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>)
(a.clone(), a)
}
-type Foo<'a, 'b> = impl std::fmt::Debug;
+pub trait Captures<'a> {}
+
+impl<'a, T: ?Sized> Captures<'a> for T {}
+
+type Foo<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>;
fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) {
(i, j)
diff --git a/src/test/ui/type-alias-impl-trait/unbounded_opaque_type.rs b/src/test/ui/type-alias-impl-trait/unbounded_opaque_type.rs
new file mode 100644
index 000000000..f43ad7dce
--- /dev/null
+++ b/src/test/ui/type-alias-impl-trait/unbounded_opaque_type.rs
@@ -0,0 +1,14 @@
+// check-pass
+
+#![feature(type_alias_impl_trait)]
+type Opaque<T> = impl Sized;
+fn defining<T>() -> Opaque<T> {}
+struct Ss<'a, T>(&'a Opaque<T>);
+
+
+fn test<'a, T>(_: Ss<'a, T>) {
+ // test that we have an implied bound `Opaque<T>: 'a` from fn signature
+ None::<&'a Opaque<T>>;
+}
+
+fn main() {}
diff --git a/src/test/ui/type/issue-101866.rs b/src/test/ui/type/issue-101866.rs
new file mode 100644
index 000000000..d332c4adb
--- /dev/null
+++ b/src/test/ui/type/issue-101866.rs
@@ -0,0 +1,15 @@
+trait TraitA<T> {
+ fn func();
+}
+
+struct StructA {}
+
+impl TraitA<i32> for StructA {
+ fn func() {}
+}
+
+fn main() {
+ TraitA::<i32>::func();
+ //~^ ERROR: cannot call associated function on trait without specifying the corresponding `impl` type [E0790]
+ //~| help: use the fully-qualified path to the only available implementation
+}
diff --git a/src/test/ui/type/issue-101866.stderr b/src/test/ui/type/issue-101866.stderr
new file mode 100644
index 000000000..fe9982119
--- /dev/null
+++ b/src/test/ui/type/issue-101866.stderr
@@ -0,0 +1,18 @@
+error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
+ --> $DIR/issue-101866.rs:12:5
+ |
+LL | fn func();
+ | ---------- `TraitA::func` defined here
+...
+LL | TraitA::<i32>::func();
+ | ^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
+ |
+help: use the fully-qualified path to the only available implementation
+ |
+LL - TraitA::<i32>::func();
+LL + <StructA as TraitA<i32>>::func();
+ |
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0790`.
diff --git a/src/test/ui/type/issue-94187-verbose-type-name.rs b/src/test/ui/type/issue-94187-verbose-type-name.rs
new file mode 100644
index 000000000..902ef5ade
--- /dev/null
+++ b/src/test/ui/type/issue-94187-verbose-type-name.rs
@@ -0,0 +1,13 @@
+// Check to insure that the output of `std::any::type_name` does not change based on -Zverbose
+// when printing constants
+// run-pass
+// edition: 2018
+// revisions: normal verbose
+// [verbose]compile-flags:-Zverbose
+
+struct Wrapper<const VALUE: usize>;
+
+fn main() {
+ assert_eq!(std::any::type_name::<[u32; 0]>(), "[u32; 0]");
+ assert_eq!(std::any::type_name::<Wrapper<0>>(), "issue_94187_verbose_type_name::Wrapper<0>");
+}
diff --git a/src/test/ui/type/type-check/assignment-expected-bool.stderr b/src/test/ui/type/type-check/assignment-expected-bool.stderr
index e2b821f7b..56494baff 100644
--- a/src/test/ui/type/type-check/assignment-expected-bool.stderr
+++ b/src/test/ui/type/type-check/assignment-expected-bool.stderr
@@ -7,7 +7,7 @@ LL | let _: bool = 0 = 0;
help: you might have meant to compare for equality
|
LL | let _: bool = 0 == 0;
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:9:14
@@ -18,7 +18,7 @@ LL | 0 => 0 = 0,
help: you might have meant to compare for equality
|
LL | 0 => 0 == 0,
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:10:14
@@ -29,7 +29,7 @@ LL | _ => 0 = 0,
help: you might have meant to compare for equality
|
LL | _ => 0 == 0,
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:14:17
@@ -40,7 +40,7 @@ LL | true => 0 = 0,
help: you might have meant to compare for equality
|
LL | true => 0 == 0,
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:18:8
@@ -51,7 +51,7 @@ LL | if 0 = 0 {}
help: you might have meant to compare for equality
|
LL | if 0 == 0 {}
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:20:24
@@ -62,7 +62,7 @@ LL | let _: bool = if { 0 = 0 } {
help: you might have meant to compare for equality
|
LL | let _: bool = if { 0 == 0 } {
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:21:9
@@ -73,7 +73,7 @@ LL | 0 = 0
help: you might have meant to compare for equality
|
LL | 0 == 0
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:23:9
@@ -84,7 +84,7 @@ LL | 0 = 0
help: you might have meant to compare for equality
|
LL | 0 == 0
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:26:13
@@ -95,7 +95,7 @@ LL | let _ = (0 = 0)
help: you might have meant to compare for equality
|
LL | let _ = (0 == 0)
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:27:14
@@ -106,7 +106,7 @@ LL | && { 0 = 0 }
help: you might have meant to compare for equality
|
LL | && { 0 == 0 }
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:28:12
@@ -117,7 +117,7 @@ LL | || (0 = 0);
help: you might have meant to compare for equality
|
LL | || (0 == 0);
- | ~~
+ | +
error[E0070]: invalid left-hand side of assignment
--> $DIR/assignment-expected-bool.rs:31:22
diff --git a/src/test/ui/type/type-check/assignment-in-if.rs b/src/test/ui/type/type-check/assignment-in-if.rs
index 8da7b32b4..ada250df2 100644
--- a/src/test/ui/type/type-check/assignment-in-if.rs
+++ b/src/test/ui/type/type-check/assignment-in-if.rs
@@ -40,4 +40,23 @@ fn main() {
) {
println!("{}", x);
}
+
+ if x == x && x = x && x == x {
+ //~^ ERROR mismatched types
+ //~| ERROR mismatched types
+ //~| ERROR mismatched types
+ println!("{}", x);
+ }
+
+ if x == x && x == x && x = x {
+ //~^ ERROR mismatched types
+ //~| ERROR mismatched types
+ println!("{}", x);
+ }
+
+ if x = 1 && x == 1 {
+ //~^ ERROR mismatched types
+ //~| ERROR mismatched types
+ println!("{}", x);
+ }
}
diff --git a/src/test/ui/type/type-check/assignment-in-if.stderr b/src/test/ui/type/type-check/assignment-in-if.stderr
index f4ef44e24..8ab08e25e 100644
--- a/src/test/ui/type/type-check/assignment-in-if.stderr
+++ b/src/test/ui/type/type-check/assignment-in-if.stderr
@@ -7,7 +7,7 @@ LL | if x = x {
help: you might have meant to compare for equality
|
LL | if x == x {
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-in-if.rs:20:8
@@ -18,7 +18,7 @@ LL | if (x = x) {
help: you might have meant to compare for equality
|
LL | if (x == x) {
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-in-if.rs:25:8
@@ -29,7 +29,7 @@ LL | if y = (Foo { foo: x }) {
help: you might have meant to compare for equality
|
LL | if y == (Foo { foo: x }) {
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-in-if.rs:30:8
@@ -40,7 +40,7 @@ LL | if 3 = x {
help: you might have meant to compare for equality
|
LL | if 3 == x {
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-in-if.rs:36:13
@@ -51,7 +51,7 @@ LL | x = 4
help: you might have meant to compare for equality
|
LL | x == 4
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/assignment-in-if.rs:38:13
@@ -62,8 +62,65 @@ LL | x = 5
help: you might have meant to compare for equality
|
LL | x == 5
- | ~~
+ | +
-error: aborting due to 6 previous errors
+error[E0308]: mismatched types
+ --> $DIR/assignment-in-if.rs:44:18
+ |
+LL | if x == x && x = x && x == x {
+ | ^ expected `bool`, found `usize`
+
+error[E0308]: mismatched types
+ --> $DIR/assignment-in-if.rs:44:22
+ |
+LL | if x == x && x = x && x == x {
+ | ^ expected `bool`, found `usize`
+
+error[E0308]: mismatched types
+ --> $DIR/assignment-in-if.rs:44:8
+ |
+LL | if x == x && x = x && x == x {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
+ |
+help: you might have meant to compare for equality
+ |
+LL | if x == x && x == x && x == x {
+ | +
+
+error[E0308]: mismatched types
+ --> $DIR/assignment-in-if.rs:51:28
+ |
+LL | if x == x && x == x && x = x {
+ | ^ expected `bool`, found `usize`
+
+error[E0308]: mismatched types
+ --> $DIR/assignment-in-if.rs:51:8
+ |
+LL | if x == x && x == x && x = x {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
+ |
+help: you might have meant to compare for equality
+ |
+LL | if x == x && x == x && x == x {
+ | +
+
+error[E0308]: mismatched types
+ --> $DIR/assignment-in-if.rs:57:12
+ |
+LL | if x = 1 && x == 1 {
+ | ^ expected `bool`, found integer
+
+error[E0308]: mismatched types
+ --> $DIR/assignment-in-if.rs:57:8
+ |
+LL | if x = 1 && x == 1 {
+ | ^^^^^^^^^^^^^^^ expected `bool`, found `()`
+ |
+help: you might have meant to compare for equality
+ |
+LL | if x == 1 && x == 1 {
+ | +
+
+error: aborting due to 13 previous errors
For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/type/type-mismatch-same-crate-name.stderr b/src/test/ui/type/type-mismatch-same-crate-name.stderr
index 783f747fa..fcafd315e 100644
--- a/src/test/ui/type/type-mismatch-same-crate-name.stderr
+++ b/src/test/ui/type/type-mismatch-same-crate-name.stderr
@@ -6,6 +6,17 @@ LL | a::try_foo(foo2);
| |
| arguments to this function are incorrect
|
+ = note: struct `main::a::Foo` and struct `main::a::Foo` have similar names, but are actually distinct types
+note: struct `main::a::Foo` is defined in crate `crate_a2`
+ --> $DIR/auxiliary/crate_a2.rs:1:1
+ |
+LL | pub struct Foo;
+ | ^^^^^^^^^^^^^^
+note: struct `main::a::Foo` is defined in crate `crate_a1`
+ --> $DIR/auxiliary/crate_a1.rs:1:1
+ |
+LL | pub struct Foo;
+ | ^^^^^^^^^^^^^^
= note: perhaps two different versions of crate `crate_a1` are being used?
note: function defined here
--> $DIR/auxiliary/crate_a1.rs:10:8
diff --git a/src/test/ui/type/type-recursive-box-shadowed.stderr b/src/test/ui/type/type-recursive-box-shadowed.stderr
index c22d848f3..cb0e98287 100644
--- a/src/test/ui/type/type-recursive-box-shadowed.stderr
+++ b/src/test/ui/type/type-recursive-box-shadowed.stderr
@@ -2,12 +2,12 @@ error[E0072]: recursive type `Foo` has infinite size
--> $DIR/type-recursive-box-shadowed.rs:7:1
|
LL | struct Foo {
- | ^^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^^
LL |
LL | inner: Foo,
| --- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | inner: Box<Foo>,
| ++++ +
diff --git a/src/test/ui/type/type-recursive.stderr b/src/test/ui/type/type-recursive.stderr
index 320271028..9a4d798f6 100644
--- a/src/test/ui/type/type-recursive.stderr
+++ b/src/test/ui/type/type-recursive.stderr
@@ -2,12 +2,12 @@ error[E0072]: recursive type `T1` has infinite size
--> $DIR/type-recursive.rs:1:1
|
LL | struct T1 {
- | ^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^
LL | foo: isize,
LL | foolish: T1,
| -- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T1` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | foolish: Box<T1>,
| ++++ +
@@ -16,11 +16,11 @@ error[E0072]: recursive type `T2` has infinite size
--> $DIR/type-recursive.rs:6:1
|
LL | struct T2 {
- | ^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^
LL | inner: Option<T2>,
- | ---------- recursive without indirection
+ | -- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T2` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | inner: Option<Box<T2>>,
| ++++ +
@@ -29,11 +29,11 @@ error[E0072]: recursive type `T3` has infinite size
--> $DIR/type-recursive.rs:12:1
|
LL | struct T3 {
- | ^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^
LL | inner: OptionT3,
| -------- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T3` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | inner: Box<OptionT3>,
| ++++ +
@@ -42,11 +42,9 @@ error[E0072]: recursive type `T4` has infinite size
--> $DIR/type-recursive.rs:16:1
|
LL | struct T4(Option<T4>);
- | ^^^^^^^^^ ---------- recursive without indirection
- | |
- | recursive type has infinite size
+ | ^^^^^^^^^ -- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T4` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | struct T4(Option<Box<T4>>);
| ++++ +
@@ -55,11 +53,11 @@ error[E0072]: recursive type `T5` has infinite size
--> $DIR/type-recursive.rs:18:1
|
LL | enum T5 {
- | ^^^^^^^ recursive type has infinite size
+ | ^^^^^^^
LL | Variant(Option<T5>),
- | ---------- recursive without indirection
+ | -- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T5` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | Variant(Option<Box<T5>>),
| ++++ +
@@ -68,11 +66,11 @@ error[E0072]: recursive type `T6` has infinite size
--> $DIR/type-recursive.rs:22:1
|
LL | enum T6 {
- | ^^^^^^^ recursive type has infinite size
+ | ^^^^^^^
LL | Variant{ field: Option<T6> },
- | ---------- recursive without indirection
+ | -- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T6` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | Variant{ field: Option<Box<T6>> },
| ++++ +
@@ -81,14 +79,14 @@ error[E0072]: recursive type `T7` has infinite size
--> $DIR/type-recursive.rs:26:1
|
LL | struct T7 {
- | ^^^^^^^^^ recursive type has infinite size
+ | ^^^^^^^^^
LL | foo: std::cell::Cell<Option<T7>>,
- | --------------------------- recursive without indirection
+ | -- recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T7` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
-LL | foo: Box<std::cell::Cell<Option<T7>>>,
- | ++++ +
+LL | foo: std::cell::Cell<Option<Box<T7>>>,
+ | ++++ +
error: aborting due to 7 previous errors
diff --git a/src/test/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.stderr b/src/test/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.stderr
index 6bc9c8498..fc7c23a22 100644
--- a/src/test/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.stderr
+++ b/src/test/ui/typeck/issue-69378-ice-on-invalid-type-node-after-recovery.stderr
@@ -2,7 +2,9 @@ error: expected identifier, found `0`
--> $DIR/issue-69378-ice-on-invalid-type-node-after-recovery.rs:3:14
|
LL | struct Foo { 0: u8 }
- | ^ expected identifier
+ | --- ^ expected identifier
+ | |
+ | while parsing this struct
error: aborting due to previous error
diff --git a/src/test/ui/typeck/issue-87181/empty-tuple-method.stderr b/src/test/ui/typeck/issue-87181/empty-tuple-method.stderr
index a18c54a29..23e7b7cc3 100644
--- a/src/test/ui/typeck/issue-87181/empty-tuple-method.stderr
+++ b/src/test/ui/typeck/issue-87181/empty-tuple-method.stderr
@@ -4,7 +4,7 @@ error[E0599]: no method named `foo` found for fn item `fn() -> Foo {Foo}` in the
LL | thing.bar.foo();
| ^^^ method not found in `fn() -> Foo {Foo}`
|
-help: use parentheses to instantiate this tuple struct
+help: use parentheses to construct this tuple struct
|
LL | (thing.bar)().foo();
| + +++
diff --git a/src/test/ui/typeck/issue-87181/enum-variant.stderr b/src/test/ui/typeck/issue-87181/enum-variant.stderr
index 90641410d..2247ea270 100644
--- a/src/test/ui/typeck/issue-87181/enum-variant.stderr
+++ b/src/test/ui/typeck/issue-87181/enum-variant.stderr
@@ -4,7 +4,7 @@ error[E0599]: no method named `foo` found for fn item `fn() -> Foo {Foo::Tup}` i
LL | thing.bar.foo();
| ^^^ method not found in `fn() -> Foo {Foo::Tup}`
|
-help: use parentheses to instantiate this tuple variant
+help: use parentheses to construct this tuple variant
|
LL | (thing.bar)().foo();
| + +++
diff --git a/src/test/ui/typeck/issue-87181/tuple-field.stderr b/src/test/ui/typeck/issue-87181/tuple-field.stderr
index c1ca26ee9..0a7d30b61 100644
--- a/src/test/ui/typeck/issue-87181/tuple-field.stderr
+++ b/src/test/ui/typeck/issue-87181/tuple-field.stderr
@@ -4,7 +4,7 @@ error[E0609]: no field `0` on type `fn(char, u16) -> Foo {Foo}`
LL | thing.bar.0;
| ^
|
-help: use parentheses to instantiate this tuple struct
+help: use parentheses to construct this tuple struct
|
LL | (thing.bar)(/* char */, /* u16 */).0;
| + ++++++++++++++++++++++++
diff --git a/src/test/ui/typeck/slow-lhs-suggestion.rs b/src/test/ui/typeck/slow-lhs-suggestion.rs
new file mode 100644
index 000000000..80dfd6835
--- /dev/null
+++ b/src/test/ui/typeck/slow-lhs-suggestion.rs
@@ -0,0 +1,26 @@
+fn main() {
+ 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ //~^ ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+ //~| ERROR invalid left-hand side of assignment
+}
diff --git a/src/test/ui/typeck/slow-lhs-suggestion.stderr b/src/test/ui/typeck/slow-lhs-suggestion.stderr
new file mode 100644
index 000000000..c5bf795ee
--- /dev/null
+++ b/src/test/ui/typeck/slow-lhs-suggestion.stderr
@@ -0,0 +1,187 @@
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:95
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:91
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:87
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:83
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:79
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:75
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:71
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:67
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:63
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:59
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:55
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:51
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:47
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:43
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:39
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:35
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:31
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:27
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:23
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:19
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:15
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:11
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error[E0070]: invalid left-hand side of assignment
+ --> $DIR/slow-lhs-suggestion.rs:2:7
+ |
+LL | 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1 = 1;
+ | - ^
+ | |
+ | cannot assign to this expression
+
+error: aborting due to 23 previous errors
+
+For more information about this error, try `rustc --explain E0070`.
diff --git a/src/test/ui/unboxed-closures/unboxed-closures-counter-not-moved.stderr b/src/test/ui/unboxed-closures/unboxed-closures-counter-not-moved.stderr
index ba4b3dac6..6450cc30a 100644
--- a/src/test/ui/unboxed-closures/unboxed-closures-counter-not-moved.stderr
+++ b/src/test/ui/unboxed-closures/unboxed-closures-counter-not-moved.stderr
@@ -12,8 +12,8 @@ warning: value assigned to `counter` is never read
LL | counter += 1;
| ^^^^^^^
|
- = note: `#[warn(unused_assignments)]` on by default
= help: maybe it is overwritten before being read?
+ = note: `#[warn(unused_assignments)]` on by default
warning: unused variable: `counter`
--> $DIR/unboxed-closures-counter-not-moved.rs:24:9
diff --git a/src/test/ui/unboxed-closures/unboxed-closures-move-mutable.stderr b/src/test/ui/unboxed-closures/unboxed-closures-move-mutable.stderr
index 1254f8dbc..5c06f4e62 100644
--- a/src/test/ui/unboxed-closures/unboxed-closures-move-mutable.stderr
+++ b/src/test/ui/unboxed-closures/unboxed-closures-move-mutable.stderr
@@ -4,8 +4,8 @@ warning: unused variable: `x`
LL | move || x += 1;
| ^
|
- = note: `#[warn(unused_variables)]` on by default
= help: did you mean to capture by reference instead?
+ = note: `#[warn(unused_variables)]` on by default
warning: unused variable: `x`
--> $DIR/unboxed-closures-move-mutable.rs:21:17
diff --git a/src/test/ui/unboxed-closures/unboxed-closures-unsafe-extern-fn.stderr b/src/test/ui/unboxed-closures/unboxed-closures-unsafe-extern-fn.stderr
index 9833304c6..802696e1b 100644
--- a/src/test/ui/unboxed-closures/unboxed-closures-unsafe-extern-fn.stderr
+++ b/src/test/ui/unboxed-closures/unboxed-closures-unsafe-extern-fn.stderr
@@ -1,4 +1,4 @@
-error[E0277]: expected a `Fn<(&isize,)>` closure, found `for<'r> unsafe fn(&'r isize) -> isize {square}`
+error[E0277]: expected a `Fn<(&isize,)>` closure, found `for<'a> unsafe fn(&'a isize) -> isize {square}`
--> $DIR/unboxed-closures-unsafe-extern-fn.rs:20:21
|
LL | let x = call_it(&square, 22);
@@ -6,7 +6,7 @@ LL | let x = call_it(&square, 22);
| |
| required by a bound introduced by this call
|
- = help: the trait `for<'r> Fn<(&'r isize,)>` is not implemented for fn item `for<'r> unsafe fn(&'r isize) -> isize {square}`
+ = help: the trait `for<'a> Fn<(&'a isize,)>` is not implemented for fn item `for<'a> unsafe fn(&'a isize) -> isize {square}`
= note: unsafe function cannot be called generically without an unsafe block
note: required by a bound in `call_it`
--> $DIR/unboxed-closures-unsafe-extern-fn.rs:9:15
@@ -14,7 +14,7 @@ note: required by a bound in `call_it`
LL | fn call_it<F: Fn(&isize) -> isize>(_: &F, _: isize) -> isize {
| ^^^^^^^^^^^^^^^^^^^ required by this bound in `call_it`
-error[E0277]: expected a `FnMut<(&isize,)>` closure, found `for<'r> unsafe fn(&'r isize) -> isize {square}`
+error[E0277]: expected a `FnMut<(&isize,)>` closure, found `for<'a> unsafe fn(&'a isize) -> isize {square}`
--> $DIR/unboxed-closures-unsafe-extern-fn.rs:25:25
|
LL | let y = call_it_mut(&mut square, 22);
@@ -22,7 +22,7 @@ LL | let y = call_it_mut(&mut square, 22);
| |
| required by a bound introduced by this call
|
- = help: the trait `for<'r> FnMut<(&'r isize,)>` is not implemented for fn item `for<'r> unsafe fn(&'r isize) -> isize {square}`
+ = help: the trait `for<'a> FnMut<(&'a isize,)>` is not implemented for fn item `for<'a> unsafe fn(&'a isize) -> isize {square}`
= note: unsafe function cannot be called generically without an unsafe block
note: required by a bound in `call_it_mut`
--> $DIR/unboxed-closures-unsafe-extern-fn.rs:12:19
@@ -30,7 +30,7 @@ note: required by a bound in `call_it_mut`
LL | fn call_it_mut<F: FnMut(&isize) -> isize>(_: &mut F, _: isize) -> isize {
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `call_it_mut`
-error[E0277]: expected a `FnOnce<(&isize,)>` closure, found `for<'r> unsafe fn(&'r isize) -> isize {square}`
+error[E0277]: expected a `FnOnce<(&isize,)>` closure, found `for<'a> unsafe fn(&'a isize) -> isize {square}`
--> $DIR/unboxed-closures-unsafe-extern-fn.rs:30:26
|
LL | let z = call_it_once(square, 22);
@@ -38,7 +38,7 @@ LL | let z = call_it_once(square, 22);
| |
| required by a bound introduced by this call
|
- = help: the trait `for<'r> FnOnce<(&'r isize,)>` is not implemented for fn item `for<'r> unsafe fn(&'r isize) -> isize {square}`
+ = help: the trait `for<'a> FnOnce<(&'a isize,)>` is not implemented for fn item `for<'a> unsafe fn(&'a isize) -> isize {square}`
= note: unsafe function cannot be called generically without an unsafe block
note: required by a bound in `call_it_once`
--> $DIR/unboxed-closures-unsafe-extern-fn.rs:15:20
diff --git a/src/test/ui/unboxed-closures/unboxed-closures-wrong-abi.stderr b/src/test/ui/unboxed-closures/unboxed-closures-wrong-abi.stderr
index 54c92e0cd..0bbb9836c 100644
--- a/src/test/ui/unboxed-closures/unboxed-closures-wrong-abi.stderr
+++ b/src/test/ui/unboxed-closures/unboxed-closures-wrong-abi.stderr
@@ -1,42 +1,42 @@
-error[E0277]: expected a `Fn<(&isize,)>` closure, found `for<'r> extern "C" fn(&'r isize) -> isize {square}`
+error[E0277]: expected a `Fn<(&isize,)>` closure, found `for<'a> extern "C" fn(&'a isize) -> isize {square}`
--> $DIR/unboxed-closures-wrong-abi.rs:20:21
|
LL | let x = call_it(&square, 22);
- | ------- ^^^^^^^ expected an `Fn<(&isize,)>` closure, found `for<'r> extern "C" fn(&'r isize) -> isize {square}`
+ | ------- ^^^^^^^ expected an `Fn<(&isize,)>` closure, found `for<'a> extern "C" fn(&'a isize) -> isize {square}`
| |
| required by a bound introduced by this call
|
- = help: the trait `for<'r> Fn<(&'r isize,)>` is not implemented for fn item `for<'r> extern "C" fn(&'r isize) -> isize {square}`
+ = help: the trait `for<'a> Fn<(&'a isize,)>` is not implemented for fn item `for<'a> extern "C" fn(&'a isize) -> isize {square}`
note: required by a bound in `call_it`
--> $DIR/unboxed-closures-wrong-abi.rs:9:15
|
LL | fn call_it<F: Fn(&isize) -> isize>(_: &F, _: isize) -> isize {
| ^^^^^^^^^^^^^^^^^^^ required by this bound in `call_it`
-error[E0277]: expected a `FnMut<(&isize,)>` closure, found `for<'r> extern "C" fn(&'r isize) -> isize {square}`
+error[E0277]: expected a `FnMut<(&isize,)>` closure, found `for<'a> extern "C" fn(&'a isize) -> isize {square}`
--> $DIR/unboxed-closures-wrong-abi.rs:25:25
|
LL | let y = call_it_mut(&mut square, 22);
- | ----------- ^^^^^^^^^^^ expected an `FnMut<(&isize,)>` closure, found `for<'r> extern "C" fn(&'r isize) -> isize {square}`
+ | ----------- ^^^^^^^^^^^ expected an `FnMut<(&isize,)>` closure, found `for<'a> extern "C" fn(&'a isize) -> isize {square}`
| |
| required by a bound introduced by this call
|
- = help: the trait `for<'r> FnMut<(&'r isize,)>` is not implemented for fn item `for<'r> extern "C" fn(&'r isize) -> isize {square}`
+ = help: the trait `for<'a> FnMut<(&'a isize,)>` is not implemented for fn item `for<'a> extern "C" fn(&'a isize) -> isize {square}`
note: required by a bound in `call_it_mut`
--> $DIR/unboxed-closures-wrong-abi.rs:12:19
|
LL | fn call_it_mut<F: FnMut(&isize) -> isize>(_: &mut F, _: isize) -> isize {
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `call_it_mut`
-error[E0277]: expected a `FnOnce<(&isize,)>` closure, found `for<'r> extern "C" fn(&'r isize) -> isize {square}`
+error[E0277]: expected a `FnOnce<(&isize,)>` closure, found `for<'a> extern "C" fn(&'a isize) -> isize {square}`
--> $DIR/unboxed-closures-wrong-abi.rs:30:26
|
LL | let z = call_it_once(square, 22);
- | ------------ ^^^^^^ expected an `FnOnce<(&isize,)>` closure, found `for<'r> extern "C" fn(&'r isize) -> isize {square}`
+ | ------------ ^^^^^^ expected an `FnOnce<(&isize,)>` closure, found `for<'a> extern "C" fn(&'a isize) -> isize {square}`
| |
| required by a bound introduced by this call
|
- = help: the trait `for<'r> FnOnce<(&'r isize,)>` is not implemented for fn item `for<'r> extern "C" fn(&'r isize) -> isize {square}`
+ = help: the trait `for<'a> FnOnce<(&'a isize,)>` is not implemented for fn item `for<'a> extern "C" fn(&'a isize) -> isize {square}`
note: required by a bound in `call_it_once`
--> $DIR/unboxed-closures-wrong-abi.rs:15:20
|
diff --git a/src/test/ui/unboxed-closures/unboxed-closures-wrong-arg-type-extern-fn.stderr b/src/test/ui/unboxed-closures/unboxed-closures-wrong-arg-type-extern-fn.stderr
index 2fedb5b92..31a66790c 100644
--- a/src/test/ui/unboxed-closures/unboxed-closures-wrong-arg-type-extern-fn.stderr
+++ b/src/test/ui/unboxed-closures/unboxed-closures-wrong-arg-type-extern-fn.stderr
@@ -6,7 +6,7 @@ LL | let x = call_it(&square, 22);
| |
| required by a bound introduced by this call
|
- = help: the trait `for<'r> Fn<(&'r isize,)>` is not implemented for fn item `unsafe fn(isize) -> isize {square}`
+ = help: the trait `for<'a> Fn<(&'a isize,)>` is not implemented for fn item `unsafe fn(isize) -> isize {square}`
= note: unsafe function cannot be called generically without an unsafe block
note: required by a bound in `call_it`
--> $DIR/unboxed-closures-wrong-arg-type-extern-fn.rs:10:15
@@ -22,7 +22,7 @@ LL | let y = call_it_mut(&mut square, 22);
| |
| required by a bound introduced by this call
|
- = help: the trait `for<'r> FnMut<(&'r isize,)>` is not implemented for fn item `unsafe fn(isize) -> isize {square}`
+ = help: the trait `for<'a> FnMut<(&'a isize,)>` is not implemented for fn item `unsafe fn(isize) -> isize {square}`
= note: unsafe function cannot be called generically without an unsafe block
note: required by a bound in `call_it_mut`
--> $DIR/unboxed-closures-wrong-arg-type-extern-fn.rs:13:19
@@ -38,7 +38,7 @@ LL | let z = call_it_once(square, 22);
| |
| required by a bound introduced by this call
|
- = help: the trait `for<'r> FnOnce<(&'r isize,)>` is not implemented for fn item `unsafe fn(isize) -> isize {square}`
+ = help: the trait `for<'a> FnOnce<(&'a isize,)>` is not implemented for fn item `unsafe fn(isize) -> isize {square}`
= note: unsafe function cannot be called generically without an unsafe block
note: required by a bound in `call_it_once`
--> $DIR/unboxed-closures-wrong-arg-type-extern-fn.rs:16:20
diff --git a/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr b/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr
index 95c209f47..0dfd22a30 100644
--- a/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr
+++ b/src/test/ui/uninhabited/privately-uninhabited-mir-call.stderr
@@ -6,6 +6,11 @@ LL | let y: &mut u32;
...
LL | *y = 2;
| ^^^^^^ `y` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let y: &mut u32 = todo!();
+ | +++++++++
error: aborting due to previous error
diff --git a/src/test/ui/union/union-copy.stderr b/src/test/ui/union/union-copy.stderr
index 8ecdafdde..53ee4dd2e 100644
--- a/src/test/ui/union/union-copy.stderr
+++ b/src/test/ui/union/union-copy.stderr
@@ -1,11 +1,11 @@
error[E0204]: the trait `Copy` may not be implemented for this type
- --> $DIR/union-copy.rs:12:6
+ --> $DIR/union-copy.rs:12:15
|
LL | a: std::mem::ManuallyDrop<String>
| --------------------------------- this field does not implement `Copy`
...
LL | impl Copy for W {}
- | ^^^^
+ | ^
|
note: the `Copy` impl for `ManuallyDrop<String>` requires that `String: Copy`
--> $DIR/union-copy.rs:8:8
diff --git a/src/test/ui/union/union-nonrepresentable.stderr b/src/test/ui/union/union-nonrepresentable.stderr
index 9804b1418..c266d2e9e 100644
--- a/src/test/ui/union/union-nonrepresentable.stderr
+++ b/src/test/ui/union/union-nonrepresentable.stderr
@@ -2,15 +2,15 @@ error[E0072]: recursive type `U` has infinite size
--> $DIR/union-nonrepresentable.rs:1:1
|
LL | union U {
- | ^^^^^^^ recursive type has infinite size
+ | ^^^^^^^
LL | a: u8,
LL | b: std::mem::ManuallyDrop<U>,
- | ------------------------- recursive without indirection
+ | - recursive without indirection
|
-help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `U` representable
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
-LL | b: Box<std::mem::ManuallyDrop<U>>,
- | ++++ +
+LL | b: std::mem::ManuallyDrop<Box<U>>,
+ | ++++ +
error: aborting due to previous error
diff --git a/src/test/ui/union/union-repr-c.stderr b/src/test/ui/union/union-repr-c.stderr
index 9abf440f7..49124eee5 100644
--- a/src/test/ui/union/union-repr-c.stderr
+++ b/src/test/ui/union/union-repr-c.stderr
@@ -4,11 +4,6 @@ error: `extern` block uses type `W`, which is not FFI-safe
LL | static FOREIGN2: W;
| ^ not FFI-safe
|
-note: the lint level is defined here
- --> $DIR/union-repr-c.rs:2:9
- |
-LL | #![deny(improper_ctypes)]
- | ^^^^^^^^^^^^^^^
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this union
= note: this union has unspecified layout
note: the type is defined here
@@ -16,6 +11,11 @@ note: the type is defined here
|
LL | union W {
| ^^^^^^^
+note: the lint level is defined here
+ --> $DIR/union-repr-c.rs:2:9
+ |
+LL | #![deny(improper_ctypes)]
+ | ^^^^^^^^^^^^^^^
error: aborting due to previous error
diff --git a/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.stderr b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.stderr
index 7e6885bd7..aa73b824a 100644
--- a/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.stderr
+++ b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-command-line.stderr
@@ -1,8 +1,8 @@
error: unknown lint: `test_unstable_lint`
|
- = note: requested on the command line with `-D unknown-lints`
= note: the `test_unstable_lint` lint is unstable
= help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
+ = note: requested on the command line with `-D unknown-lints`
error: unknown lint: `test_unstable_lint`
|
diff --git a/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.stderr b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.stderr
index 2d1027dd0..2a2a9811b 100644
--- a/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.stderr
+++ b/src/test/ui/unknown-unstable-lints/deny-unstable-lint-inline.stderr
@@ -4,13 +4,13 @@ error: unknown lint: `test_unstable_lint`
LL | #![allow(test_unstable_lint)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
+ = note: the `test_unstable_lint` lint is unstable
+ = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
note: the lint level is defined here
--> $DIR/deny-unstable-lint-inline.rs:3:9
|
LL | #![deny(unknown_lints)]
| ^^^^^^^^^^^^^
- = note: the `test_unstable_lint` lint is unstable
- = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
error: unknown lint: `test_unstable_lint`
--> $DIR/deny-unstable-lint-inline.rs:4:1
diff --git a/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.stderr b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.stderr
index 799d740b0..82851c800 100644
--- a/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.stderr
+++ b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-command-line.stderr
@@ -1,8 +1,8 @@
warning: unknown lint: `test_unstable_lint`
|
- = note: requested on the command line with `-W unknown-lints`
= note: the `test_unstable_lint` lint is unstable
= help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
+ = note: requested on the command line with `-W unknown-lints`
warning: unknown lint: `test_unstable_lint`
|
diff --git a/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.stderr b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.stderr
index 142558b47..0548cd226 100644
--- a/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.stderr
+++ b/src/test/ui/unknown-unstable-lints/warn-unknown-unstable-lint-inline.stderr
@@ -4,13 +4,13 @@ warning: unknown lint: `test_unstable_lint`
LL | #![allow(test_unstable_lint)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
+ = note: the `test_unstable_lint` lint is unstable
+ = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
note: the lint level is defined here
--> $DIR/warn-unknown-unstable-lint-inline.rs:3:9
|
LL | #![warn(unknown_lints)]
| ^^^^^^^^^^^^^
- = note: the `test_unstable_lint` lint is unstable
- = help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
warning: unknown lint: `test_unstable_lint`
--> $DIR/warn-unknown-unstable-lint-inline.rs:4:1
diff --git a/src/test/ui/unresolved/unresolved-candidates.rs b/src/test/ui/unresolved/unresolved-candidates.rs
new file mode 100644
index 000000000..38b227f60
--- /dev/null
+++ b/src/test/ui/unresolved/unresolved-candidates.rs
@@ -0,0 +1,13 @@
+mod a {
+ pub trait Trait {}
+}
+
+mod b {
+ use Trait; //~ ERROR unresolved import `Trait`
+}
+
+mod c {
+ impl Trait for () {} //~ ERROR cannot find trait `Trait` in this scope
+}
+
+fn main() {}
diff --git a/src/test/ui/unresolved/unresolved-candidates.stderr b/src/test/ui/unresolved/unresolved-candidates.stderr
new file mode 100644
index 000000000..bbd3eec2a
--- /dev/null
+++ b/src/test/ui/unresolved/unresolved-candidates.stderr
@@ -0,0 +1,26 @@
+error[E0432]: unresolved import `Trait`
+ --> $DIR/unresolved-candidates.rs:6:9
+ |
+LL | use Trait;
+ | ^^^^^ no `Trait` in the root
+ |
+help: consider importing this trait instead
+ |
+LL | use a::Trait;
+ | ~~~~~~~~~
+
+error[E0405]: cannot find trait `Trait` in this scope
+ --> $DIR/unresolved-candidates.rs:10:10
+ |
+LL | impl Trait for () {}
+ | ^^^^^ not found in this scope
+ |
+help: consider importing this trait
+ |
+LL | use a::Trait;
+ |
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0405, E0432.
+For more information about an error, try `rustc --explain E0405`.
diff --git a/src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.mir.stderr b/src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.mir.stderr
index b968174dd..6f005fe89 100644
--- a/src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.mir.stderr
+++ b/src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.mir.stderr
@@ -4,12 +4,12 @@ error: call to unsafe function is unsafe and requires unsafe block (error E0133)
LL | unsf();
| ^^^^^^ call to unsafe function
|
+ = note: consult the function's documentation for information on how to avoid undefined behavior
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:4:9
|
LL | #![deny(unsafe_op_in_unsafe_fn)]
| ^^^^^^^^^^^^^^^^^^^^^^
- = note: consult the function's documentation for information on how to avoid undefined behavior
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:15:5
@@ -45,13 +45,13 @@ error: call to unsafe function is unsafe and requires unsafe block (error E0133)
LL | unsf();
| ^^^^^^ call to unsafe function
|
+ = note: consult the function's documentation for information on how to avoid undefined behavior
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:26:8
|
LL | #[deny(warnings)]
| ^^^^^^^^
= note: `#[deny(unsafe_op_in_unsafe_fn)]` implied by `#[deny(warnings)]`
- = note: consult the function's documentation for information on how to avoid undefined behavior
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:31:5
diff --git a/src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.thir.stderr b/src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.thir.stderr
index e36529365..13c080e5b 100644
--- a/src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.thir.stderr
+++ b/src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.thir.stderr
@@ -4,12 +4,12 @@ error: call to unsafe function `unsf` is unsafe and requires unsafe block (error
LL | unsf();
| ^^^^^^ call to unsafe function
|
+ = note: consult the function's documentation for information on how to avoid undefined behavior
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:4:9
|
LL | #![deny(unsafe_op_in_unsafe_fn)]
| ^^^^^^^^^^^^^^^^^^^^^^
- = note: consult the function's documentation for information on how to avoid undefined behavior
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:15:5
@@ -45,13 +45,13 @@ error: call to unsafe function `unsf` is unsafe and requires unsafe block (error
LL | unsf();
| ^^^^^^ call to unsafe function
|
+ = note: consult the function's documentation for information on how to avoid undefined behavior
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:26:8
|
LL | #[deny(warnings)]
| ^^^^^^^^
= note: `#[deny(unsafe_op_in_unsafe_fn)]` implied by `#[deny(warnings)]`
- = note: consult the function's documentation for information on how to avoid undefined behavior
error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:31:5
diff --git a/src/test/ui/unsized-locals/borrow-after-move.stderr b/src/test/ui/unsized-locals/borrow-after-move.stderr
index 4f2bc06d4..28ae1c068 100644
--- a/src/test/ui/unsized-locals/borrow-after-move.stderr
+++ b/src/test/ui/unsized-locals/borrow-after-move.stderr
@@ -4,8 +4,8 @@ warning: the feature `unsized_locals` is incomplete and may not be safe to use a
LL | #![feature(unsized_locals, unsized_fn_params)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #48055 <https://github.com/rust-lang/rust/issues/48055> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error[E0382]: borrow of moved value: `x`
--> $DIR/borrow-after-move.rs:21:24
diff --git a/src/test/ui/unsized-locals/by-value-trait-object-safety.stderr b/src/test/ui/unsized-locals/by-value-trait-object-safety.stderr
index 59d91bc0c..4f13ec7ac 100644
--- a/src/test/ui/unsized-locals/by-value-trait-object-safety.stderr
+++ b/src/test/ui/unsized-locals/by-value-trait-object-safety.stderr
@@ -4,8 +4,8 @@ warning: the feature `unsized_locals` is incomplete and may not be safe to use a
LL | #![feature(unsized_locals)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #48055 <https://github.com/rust-lang/rust/issues/48055> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error: the `foo` method cannot be invoked on a trait object
--> $DIR/by-value-trait-object-safety.rs:20:7
diff --git a/src/test/ui/unsized-locals/double-move.stderr b/src/test/ui/unsized-locals/double-move.stderr
index 4bb2ad88f..dfae6cc75 100644
--- a/src/test/ui/unsized-locals/double-move.stderr
+++ b/src/test/ui/unsized-locals/double-move.stderr
@@ -4,8 +4,8 @@ warning: the feature `unsized_locals` is incomplete and may not be safe to use a
LL | #![feature(unsized_locals, unsized_fn_params)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #48055 <https://github.com/rust-lang/rust/issues/48055> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error[E0382]: use of moved value: `y`
--> $DIR/double-move.rs:21:22
diff --git a/src/test/ui/unsized-locals/issue-30276-feature-flagged.stderr b/src/test/ui/unsized-locals/issue-30276-feature-flagged.stderr
index 0f0ff5793..b6002cf89 100644
--- a/src/test/ui/unsized-locals/issue-30276-feature-flagged.stderr
+++ b/src/test/ui/unsized-locals/issue-30276-feature-flagged.stderr
@@ -4,8 +4,8 @@ warning: the feature `unsized_locals` is incomplete and may not be safe to use a
LL | #![feature(unsized_locals)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #48055 <https://github.com/rust-lang/rust/issues/48055> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
--> $DIR/issue-30276-feature-flagged.rs:7:29
diff --git a/src/test/ui/unsized-locals/issue-50940-with-feature.stderr b/src/test/ui/unsized-locals/issue-50940-with-feature.stderr
index 4523d41b6..8bbe317ec 100644
--- a/src/test/ui/unsized-locals/issue-50940-with-feature.stderr
+++ b/src/test/ui/unsized-locals/issue-50940-with-feature.stderr
@@ -4,8 +4,8 @@ warning: the feature `unsized_locals` is incomplete and may not be safe to use a
LL | #![feature(unsized_locals, unsized_fn_params)]
| ^^^^^^^^^^^^^^
|
- = note: `#[warn(incomplete_features)]` on by default
= note: see issue #48055 <https://github.com/rust-lang/rust/issues/48055> for more information
+ = note: `#[warn(incomplete_features)]` on by default
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/issue-50940-with-feature.rs:6:5
diff --git a/src/test/ui/unwind-abis/feature-gate-c-unwind.stderr b/src/test/ui/unwind-abis/feature-gate-c-unwind.stderr
index a67f46cd2..214ddc45c 100644
--- a/src/test/ui/unwind-abis/feature-gate-c-unwind.stderr
+++ b/src/test/ui/unwind-abis/feature-gate-c-unwind.stderr
@@ -4,10 +4,10 @@ warning: unknown lint: `ffi_unwind_calls`
LL | #![allow(ffi_unwind_calls)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `#[warn(unknown_lints)]` on by default
= note: the `ffi_unwind_calls` lint is unstable
= note: see issue #74990 <https://github.com/rust-lang/rust/issues/74990> for more information
= help: add `#![feature(c_unwind)]` to the crate attributes to enable
+ = note: `#[warn(unknown_lints)]` on by default
error[E0658]: C-unwind ABI is experimental and subject to change
--> $DIR/feature-gate-c-unwind.rs:8:8
diff --git a/src/test/ui/unwind-abis/ffi-unwind-calls-lint.rs b/src/test/ui/unwind-abis/ffi-unwind-calls-lint.rs
index dadf4b121..9a324f004 100644
--- a/src/test/ui/unwind-abis/ffi-unwind-calls-lint.rs
+++ b/src/test/ui/unwind-abis/ffi-unwind-calls-lint.rs
@@ -1,6 +1,5 @@
// build-pass
// needs-unwind
-// ignore-wasm32-bare compiled with panic=abort by default
#![feature(c_unwind)]
#![warn(ffi_unwind_calls)]
diff --git a/src/test/ui/unwind-abis/ffi-unwind-calls-lint.stderr b/src/test/ui/unwind-abis/ffi-unwind-calls-lint.stderr
index ed41cb746..937a2b3df 100644
--- a/src/test/ui/unwind-abis/ffi-unwind-calls-lint.stderr
+++ b/src/test/ui/unwind-abis/ffi-unwind-calls-lint.stderr
@@ -1,17 +1,17 @@
warning: call to foreign function with FFI-unwind ABI
- --> $DIR/ffi-unwind-calls-lint.rs:21:14
+ --> $DIR/ffi-unwind-calls-lint.rs:20:14
|
LL | unsafe { foo(); }
| ^^^^^ call to foreign function with FFI-unwind ABI
|
note: the lint level is defined here
- --> $DIR/ffi-unwind-calls-lint.rs:6:9
+ --> $DIR/ffi-unwind-calls-lint.rs:5:9
|
LL | #![warn(ffi_unwind_calls)]
| ^^^^^^^^^^^^^^^^
warning: call to function pointer with FFI-unwind ABI
- --> $DIR/ffi-unwind-calls-lint.rs:25:5
+ --> $DIR/ffi-unwind-calls-lint.rs:24:5
|
LL | ptr();
| ^^^^^ call to function pointer with FFI-unwind ABI
diff --git a/src/test/ui/unwind-no-uwtable.rs b/src/test/ui/unwind-no-uwtable.rs
index 0440cf488..3bc309233 100644
--- a/src/test/ui/unwind-no-uwtable.rs
+++ b/src/test/ui/unwind-no-uwtable.rs
@@ -1,7 +1,6 @@
// run-pass
// needs-unwind
// ignore-windows target requires uwtable
-// ignore-wasm32-bare no proper panic=unwind support
// compile-flags: -C panic=unwind -C force-unwind-tables=n
use std::panic::{self, AssertUnwindSafe};
diff --git a/src/test/ui/variance/variance-regions-unused-indirect.rs b/src/test/ui/variance/variance-regions-unused-indirect.rs
index 1514e3956..6c2c24ddb 100644
--- a/src/test/ui/variance/variance-regions-unused-indirect.rs
+++ b/src/test/ui/variance/variance-regions-unused-indirect.rs
@@ -1,6 +1,7 @@
// Test that disallow lifetime parameters that are unused.
enum Foo<'a> { //~ ERROR parameter `'a` is never used
+ //~^ ERROR recursive types `Foo` and `Bar` have infinite size
Foo1(Bar<'a>)
}
diff --git a/src/test/ui/variance/variance-regions-unused-indirect.stderr b/src/test/ui/variance/variance-regions-unused-indirect.stderr
index 93710cc13..14fdd8492 100644
--- a/src/test/ui/variance/variance-regions-unused-indirect.stderr
+++ b/src/test/ui/variance/variance-regions-unused-indirect.stderr
@@ -1,3 +1,26 @@
+error[E0072]: recursive types `Foo` and `Bar` have infinite size
+ --> $DIR/variance-regions-unused-indirect.rs:3:1
+ |
+LL | enum Foo<'a> {
+ | ^^^^^^^^^^^^
+LL |
+LL | Foo1(Bar<'a>)
+ | ------- recursive without indirection
+...
+LL | enum Bar<'a> {
+ | ^^^^^^^^^^^^
+LL | Bar1(Foo<'a>)
+ | ------- recursive without indirection
+ |
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
+ |
+LL ~ Foo1(Box<Bar<'a>>)
+LL | }
+LL |
+LL | enum Bar<'a> {
+LL ~ Bar1(Box<Foo<'a>>)
+ |
+
error[E0392]: parameter `'a` is never used
--> $DIR/variance-regions-unused-indirect.rs:3:10
|
@@ -7,13 +30,14 @@ LL | enum Foo<'a> {
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`
error[E0392]: parameter `'a` is never used
- --> $DIR/variance-regions-unused-indirect.rs:7:10
+ --> $DIR/variance-regions-unused-indirect.rs:8:10
|
LL | enum Bar<'a> {
| ^^ unused parameter
|
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors
-For more information about this error, try `rustc --explain E0392`.
+Some errors have detailed explanations: E0072, E0392.
+For more information about an error, try `rustc --explain E0072`.
diff --git a/src/test/ui/wf/issue-103573.rs b/src/test/ui/wf/issue-103573.rs
new file mode 100644
index 000000000..bcbf4f941
--- /dev/null
+++ b/src/test/ui/wf/issue-103573.rs
@@ -0,0 +1,22 @@
+trait TraitA {
+ type TypeA;
+}
+
+trait TraitD {
+ type TypeD;
+}
+
+pub trait TraitB {
+ type TypeB: TraitD;
+
+ fn f(_: &<Self::TypeB as TraitD>::TypeD);
+}
+
+pub trait TraitC<E> {
+ type TypeC<'a>: TraitB;
+
+ fn g<'a>(_: &<<Self::TypeC<'a> as TraitB>::TypeB as TraitA>::TypeA);
+ //~^ ERROR the trait bound `<<Self as TraitC<E>>::TypeC<'a> as TraitB>::TypeB: TraitA` is not satisfied
+}
+
+fn main() {}
diff --git a/src/test/ui/wf/issue-103573.stderr b/src/test/ui/wf/issue-103573.stderr
new file mode 100644
index 000000000..fcf3f15e4
--- /dev/null
+++ b/src/test/ui/wf/issue-103573.stderr
@@ -0,0 +1,14 @@
+error[E0277]: the trait bound `<<Self as TraitC<E>>::TypeC<'a> as TraitB>::TypeB: TraitA` is not satisfied
+ --> $DIR/issue-103573.rs:18:5
+ |
+LL | fn g<'a>(_: &<<Self::TypeC<'a> as TraitB>::TypeB as TraitA>::TypeA);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TraitA` is not implemented for `<<Self as TraitC<E>>::TypeC<'a> as TraitB>::TypeB`
+ |
+help: consider further restricting the associated type
+ |
+LL | fn g<'a>(_: &<<Self::TypeC<'a> as TraitB>::TypeB as TraitA>::TypeA) where <<Self as TraitC<E>>::TypeC<'a> as TraitB>::TypeB: TraitA;
+ | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/where-clauses/higher-ranked-fn-type.quiet.stderr b/src/test/ui/where-clauses/higher-ranked-fn-type.quiet.stderr
new file mode 100644
index 000000000..30248a7a3
--- /dev/null
+++ b/src/test/ui/where-clauses/higher-ranked-fn-type.quiet.stderr
@@ -0,0 +1,18 @@
+error[E0277]: the trait bound `for<'b> fn(&'b ()): Foo` is not satisfied
+ --> $DIR/higher-ranked-fn-type.rs:20:5
+ |
+LL | called()
+ | ^^^^^^ the trait `for<'b> Foo` is not implemented for `fn(&'b ())`
+ |
+note: required by a bound in `called`
+ --> $DIR/higher-ranked-fn-type.rs:12:25
+ |
+LL | fn called()
+ | ------ required by a bound in this
+LL | where
+LL | for<'b> fn(&'b ()): Foo,
+ | ^^^ required by this bound in `called`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/where-clauses/higher-ranked-fn-type.rs b/src/test/ui/where-clauses/higher-ranked-fn-type.rs
new file mode 100644
index 000000000..ab6edde4e
--- /dev/null
+++ b/src/test/ui/where-clauses/higher-ranked-fn-type.rs
@@ -0,0 +1,25 @@
+// revisions: quiet verbose
+// [verbose]compile-flags: -Zverbose
+
+#![allow(unused_parens)]
+
+trait Foo {
+ type Assoc;
+}
+
+fn called()
+where
+ for<'b> fn(&'b ()): Foo,
+{
+}
+
+fn caller()
+where
+ (for<'a> fn(&'a ())): Foo,
+{
+ called()
+ //[quiet]~^ ERROR the trait bound `for<'b> fn(&'b ()): Foo` is not satisfied
+ //[verbose]~^^ ERROR the trait bound `for<'b> fn(&ReLateBound(
+}
+
+fn main() {}
diff --git a/src/test/ui/where-clauses/higher-ranked-fn-type.verbose.stderr b/src/test/ui/where-clauses/higher-ranked-fn-type.verbose.stderr
new file mode 100644
index 000000000..24660ec35
--- /dev/null
+++ b/src/test/ui/where-clauses/higher-ranked-fn-type.verbose.stderr
@@ -0,0 +1,18 @@
+error[E0277]: the trait bound `for<'b> fn(&ReLateBound(DebruijnIndex(1), BoundRegion { var: 0, kind: BrNamed(DefId(0:6 ~ higher_ranked_fn_type[1209]::called::'b), 'b) }) ()): Foo` is not satisfied
+ --> $DIR/higher-ranked-fn-type.rs:20:5
+ |
+LL | called()
+ | ^^^^^^ the trait `for<'b> Foo` is not implemented for `fn(&ReLateBound(DebruijnIndex(1), BoundRegion { var: 0, kind: BrNamed(DefId(0:6 ~ higher_ranked_fn_type[1209]::called::'b), 'b) }) ())`
+ |
+note: required by a bound in `called`
+ --> $DIR/higher-ranked-fn-type.rs:12:25
+ |
+LL | fn called()
+ | ------ required by a bound in this
+LL | where
+LL | for<'b> fn(&'b ()): Foo,
+ | ^^^ required by this bound in `called`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs
index 1a6760d8c..b0006cb90 100644
--- a/src/tools/build-manifest/src/main.rs
+++ b/src/tools/build-manifest/src/main.rs
@@ -11,9 +11,9 @@ mod versions;
use crate::checksum::Checksums;
use crate::manifest::{Component, Manifest, Package, Rename, Target};
use crate::versions::{PkgType, Versions};
-use std::collections::{BTreeMap, HashMap, HashSet};
+use std::collections::{BTreeMap, HashSet};
use std::env;
-use std::fs::{self, File};
+use std::fs;
use std::path::{Path, PathBuf};
static HOSTS: &[&str] = &[
@@ -184,7 +184,7 @@ static PKG_INSTALLERS: &[&str] = &["x86_64-apple-darwin", "aarch64-apple-darwin"
static MINGW: &[&str] = &["i686-pc-windows-gnu", "x86_64-pc-windows-gnu"];
-static NIGHTLY_ONLY_COMPONENTS: &[&str] = &["miri-preview"];
+static NIGHTLY_ONLY_COMPONENTS: &[&str] = &["miri-preview", "rust-docs-json-preview"];
macro_rules! t {
($e:expr) => {
@@ -193,6 +193,12 @@ macro_rules! t {
Err(e) => panic!("{} failed with {}", stringify!($e), e),
}
};
+ ($e:expr, $extra:expr) => {
+ match $e {
+ Ok(e) => e,
+ Err(e) => panic!("{} failed with {}: {}", stringify!($e), e, $extra),
+ }
+ };
}
struct Builder {
@@ -239,7 +245,6 @@ fn main() {
impl Builder {
fn build(&mut self) {
- self.check_toolstate();
let manifest = self.build_manifest();
let channel = self.versions.channel().to_string();
@@ -261,29 +266,6 @@ impl Builder {
t!(self.checksums.store_cache());
}
- /// If a tool does not pass its tests on *any* of Linux and Windows, don't ship
- /// it on *all* targets, because tools like Miri can "cross-run" programs for
- /// different targets, for example, run a program for `x86_64-pc-windows-msvc`
- /// on `x86_64-unknown-linux-gnu`.
- /// Right now, we do this only for Miri.
- fn check_toolstate(&mut self) {
- for file in &["toolstates-linux.json", "toolstates-windows.json"] {
- let toolstates: Option<HashMap<String, String>> = File::open(self.input.join(file))
- .ok()
- .and_then(|f| serde_json::from_reader(&f).ok());
- let toolstates = toolstates.unwrap_or_else(|| {
- println!("WARNING: `{}` missing/malformed; assuming all tools failed", file);
- HashMap::default() // Use empty map if anything went wrong.
- });
- // Mark some tools as missing based on toolstate.
- if toolstates.get("miri").map(|s| &*s as &str) != Some("test-pass") {
- println!("Miri tests are not passing, removing component");
- self.versions.disable_version(&PkgType::Miri);
- break;
- }
- }
- }
-
fn build_manifest(&mut self) -> Manifest {
let mut manifest = Manifest {
manifest_version: "2".to_string(),
@@ -318,6 +300,7 @@ impl Builder {
package!("rust-mingw", MINGW);
package!("rust-std", TARGETS);
self.package("rust-docs", &mut manifest.pkg, HOSTS, DOCS_FALLBACK);
+ self.package("rust-docs-json-preview", &mut manifest.pkg, HOSTS, DOCS_FALLBACK);
package!("rust-src", &["*"]);
package!("rls-preview", HOSTS);
package!("rust-analyzer-preview", HOSTS);
@@ -403,6 +386,7 @@ impl Builder {
rename("rustfmt", "rustfmt-preview");
rename("clippy", "clippy-preview");
rename("miri", "miri-preview");
+ rename("rust-docs-json", "rust-docs-json-preview");
rename("rust-analyzer", "rust-analyzer-preview");
}
@@ -459,6 +443,7 @@ impl Builder {
host_component("rustfmt-preview"),
host_component("llvm-tools-preview"),
host_component("rust-analysis"),
+ host_component("rust-docs-json-preview"),
]);
extensions.extend(
@@ -543,8 +528,18 @@ impl Builder {
for (substr, fallback_target) in fallback {
if target_name.contains(substr) {
let t = Target::from_compressed_tar(self, &tarball_name!(fallback_target));
- // Fallbacks must always be available.
- assert!(t.available);
+ // Fallbacks should typically be available on 'production' builds
+ // but may not be available for try builds, which only build one target by
+ // default. Ideally we'd gate this being a hard error on whether we're in a
+ // production build or not, but it's not information that's readily available
+ // here.
+ if !t.available {
+ eprintln!(
+ "{:?} not available for fallback",
+ tarball_name!(fallback_target)
+ );
+ continue;
+ }
return t;
}
}
@@ -595,7 +590,7 @@ impl Builder {
self.shipped_files.insert(name.clone());
let dst = self.output.join(name);
- t!(fs::write(&dst, contents));
+ t!(fs::write(&dst, contents), format!("failed to create manifest {}", dst.display()));
}
fn write_shipped_files(&self, path: &Path) {
diff --git a/src/tools/build-manifest/src/versions.rs b/src/tools/build-manifest/src/versions.rs
index 95c2297de..0186194a4 100644
--- a/src/tools/build-manifest/src/versions.rs
+++ b/src/tools/build-manifest/src/versions.rs
@@ -20,6 +20,7 @@ pub(crate) enum PkgType {
Rustfmt,
LlvmTools,
Miri,
+ JsonDocs,
Other(String),
}
@@ -36,6 +37,7 @@ impl PkgType {
"rustfmt" | "rustfmt-preview" => PkgType::Rustfmt,
"llvm-tools" | "llvm-tools-preview" => PkgType::LlvmTools,
"miri" | "miri-preview" => PkgType::Miri,
+ "rust-docs-json" | "rust-docs-json-preview" => PkgType::JsonDocs,
other => PkgType::Other(other.into()),
}
}
@@ -53,6 +55,7 @@ impl PkgType {
PkgType::Rustfmt => "rustfmt",
PkgType::LlvmTools => "llvm-tools",
PkgType::Miri => "miri",
+ PkgType::JsonDocs => "rust-docs-json",
PkgType::Other(component) => component,
}
}
@@ -72,6 +75,7 @@ impl PkgType {
PkgType::Rust => true,
PkgType::RustSrc => true,
PkgType::Rustc => true,
+ PkgType::JsonDocs => true,
PkgType::Other(_) => true,
}
}
@@ -113,6 +117,9 @@ impl Versions {
Some(version) => Ok(version.clone()),
None => {
let version_info = self.load_version_from_tarball(package)?;
+ if *package == PkgType::Rust && version_info.version.is_none() {
+ panic!("missing version info for toolchain");
+ }
self.versions.insert(package.clone(), version_info.clone());
Ok(version_info)
}
@@ -127,6 +134,7 @@ impl Versions {
Ok(file) => file,
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
// Missing tarballs do not return an error, but return empty data.
+ println!("warning: missing tarball {}", tarball.display());
return Ok(VersionInfo::default());
}
Err(err) => return Err(err.into()),
@@ -157,17 +165,6 @@ impl Versions {
Ok(VersionInfo { version, git_commit, present: true })
}
- pub(crate) fn disable_version(&mut self, package: &PkgType) {
- match self.versions.get_mut(package) {
- Some(version) => {
- *version = VersionInfo::default();
- }
- None => {
- self.versions.insert(package.clone(), VersionInfo::default());
- }
- }
- }
-
pub(crate) fn archive_name(
&self,
package: &PkgType,
diff --git a/src/tools/cargotest/main.rs b/src/tools/cargotest/main.rs
index 95fe98a68..7044cb892 100644
--- a/src/tools/cargotest/main.rs
+++ b/src/tools/cargotest/main.rs
@@ -73,7 +73,7 @@ const TEST_REPOS: &[Test] = &[
Test {
name: "servo",
repo: "https://github.com/servo/servo",
- sha: "caac107ae8145ef2fd20365e2b8fadaf09c2eb3b",
+ sha: "785a344e32db58d4e631fd3cae17fd1f29a721ab",
lock: None,
// Only test Stylo a.k.a. Quantum CSS, the parts of Servo going into Firefox.
// This takes much less time to build than all of Servo and supports stable Rust.
@@ -206,6 +206,10 @@ fn run_cargo_test(
.env("CFG_DISABLE_CROSS_TESTS", "1")
// Relax #![deny(warnings)] in some crates
.env("RUSTFLAGS", "--cap-lints warn")
+ // servo tries to use 'lld-link.exe' on windows, but we don't
+ // have lld on our PATH in CI. Override it to use 'link.exe'
+ .env("CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER", "link.exe")
+ .env("CARGO_TARGET_I686_PC_WINDOWS_MSVC_LINKER", "link.exe")
.current_dir(crate_path)
.status()
.unwrap();
diff --git a/src/tools/clippy/.github/workflows/clippy.yml b/src/tools/clippy/.github/workflows/clippy.yml
index fac2c9971..b99213011 100644
--- a/src/tools/clippy/.github/workflows/clippy.yml
+++ b/src/tools/clippy/.github/workflows/clippy.yml
@@ -25,6 +25,7 @@ env:
CARGO_TARGET_DIR: '${{ github.workspace }}/target'
NO_FMT_TEST: 1
CARGO_INCREMENTAL: 0
+ CARGO_UNSTABLE_SPARSE_REGISTRY: true
jobs:
base:
diff --git a/src/tools/clippy/.github/workflows/clippy_bors.yml b/src/tools/clippy/.github/workflows/clippy_bors.yml
index 30607af49..6448b2d40 100644
--- a/src/tools/clippy/.github/workflows/clippy_bors.yml
+++ b/src/tools/clippy/.github/workflows/clippy_bors.yml
@@ -11,6 +11,7 @@ env:
CARGO_TARGET_DIR: '${{ github.workspace }}/target'
NO_FMT_TEST: 1
CARGO_INCREMENTAL: 0
+ CARGO_UNSTABLE_SPARSE_REGISTRY: true
defaults:
run:
diff --git a/src/tools/clippy/.github/workflows/clippy_dev.yml b/src/tools/clippy/.github/workflows/clippy_dev.yml
index 22051093c..14f20212a 100644
--- a/src/tools/clippy/.github/workflows/clippy_dev.yml
+++ b/src/tools/clippy/.github/workflows/clippy_dev.yml
@@ -15,6 +15,8 @@ on:
env:
RUST_BACKTRACE: 1
+ CARGO_INCREMENTAL: 0
+ CARGO_UNSTABLE_SPARSE_REGISTRY: true
jobs:
clippy_dev:
diff --git a/src/tools/clippy/CHANGELOG.md b/src/tools/clippy/CHANGELOG.md
index d847e4c74..2d7bda27e 100644
--- a/src/tools/clippy/CHANGELOG.md
+++ b/src/tools/clippy/CHANGELOG.md
@@ -6,11 +6,161 @@ document.
## Unreleased / In Rust Nightly
-[d7b5cbf0...master](https://github.com/rust-lang/rust-clippy/compare/d7b5cbf0...master)
+[3c7e7dbc...master](https://github.com/rust-lang/rust-clippy/compare/3c7e7dbc...master)
+
+## Rust 1.64
+
+Current stable, released 2022-09-22
+
+[d7b5cbf0...3c7e7dbc](https://github.com/rust-lang/rust-clippy/compare/d7b5cbf0...3c7e7dbc)
+
+### New Lints
+
+* [`arithmetic_side_effects`]
+ [#9130](https://github.com/rust-lang/rust-clippy/pull/9130)
+* [`invalid_utf8_in_unchecked`]
+ [#9105](https://github.com/rust-lang/rust-clippy/pull/9105)
+* [`assertions_on_result_states`]
+ [#9225](https://github.com/rust-lang/rust-clippy/pull/9225)
+* [`manual_find`]
+ [#8649](https://github.com/rust-lang/rust-clippy/pull/8649)
+* [`manual_retain`]
+ [#8972](https://github.com/rust-lang/rust-clippy/pull/8972)
+* [`default_instead_of_iter_empty`]
+ [#8989](https://github.com/rust-lang/rust-clippy/pull/8989)
+* [`manual_rem_euclid`]
+ [#9031](https://github.com/rust-lang/rust-clippy/pull/9031)
+* [`obfuscated_if_else`]
+ [#9148](https://github.com/rust-lang/rust-clippy/pull/9148)
+* [`std_instead_of_core`]
+ [#9103](https://github.com/rust-lang/rust-clippy/pull/9103)
+* [`std_instead_of_alloc`]
+ [#9103](https://github.com/rust-lang/rust-clippy/pull/9103)
+* [`alloc_instead_of_core`]
+ [#9103](https://github.com/rust-lang/rust-clippy/pull/9103)
+* [`explicit_auto_deref`]
+ [#8355](https://github.com/rust-lang/rust-clippy/pull/8355)
+
+
+### Moves and Deprecations
+
+* Moved [`format_push_string`] to `restriction` (now allow-by-default)
+ [#9161](https://github.com/rust-lang/rust-clippy/pull/9161)
+
+### Enhancements
+
+* [`significant_drop_in_scrutinee`]: Now gives more context in the lint message
+ [#8981](https://github.com/rust-lang/rust-clippy/pull/8981)
+* [`single_match`], [`single_match_else`]: Now catches more `Option` cases
+ [#8985](https://github.com/rust-lang/rust-clippy/pull/8985)
+* [`unused_async`]: Now works for async methods
+ [#9025](https://github.com/rust-lang/rust-clippy/pull/9025)
+* [`manual_filter_map`], [`manual_find_map`]: Now lint more expressions
+ [#8958](https://github.com/rust-lang/rust-clippy/pull/8958)
+* [`question_mark`]: Now works for simple `if let` expressions
+ [#8356](https://github.com/rust-lang/rust-clippy/pull/8356)
+* [`undocumented_unsafe_blocks`]: Now finds comments before the start of closures
+ [#9117](https://github.com/rust-lang/rust-clippy/pull/9117)
+* [`trait_duplication_in_bounds`]: Now catches duplicate bounds in where clauses
+ [#8703](https://github.com/rust-lang/rust-clippy/pull/8703)
+* [`shadow_reuse`], [`shadow_same`], [`shadow_unrelated`]: Now lint in const blocks
+ [#9124](https://github.com/rust-lang/rust-clippy/pull/9124)
+* [`slow_vector_initialization`]: Now detects cases with `vec.capacity()`
+ [#8953](https://github.com/rust-lang/rust-clippy/pull/8953)
+* [`unused_self`]: Now respects the `avoid-breaking-exported-api` config option
+ [#9199](https://github.com/rust-lang/rust-clippy/pull/9199)
+* [`box_collection`]: Now supports all std collections
+ [#9170](https://github.com/rust-lang/rust-clippy/pull/9170)
+
+### False Positive Fixes
+
+* [`significant_drop_in_scrutinee`]: Now ignores calls to `IntoIterator::into_iter`
+ [#9140](https://github.com/rust-lang/rust-clippy/pull/9140)
+* [`while_let_loop`]: Now ignores cases when the significant drop order would change
+ [#8981](https://github.com/rust-lang/rust-clippy/pull/8981)
+* [`branches_sharing_code`]: Now ignores cases where moved variables have a significant
+ drop or variable modifications can affect the conditions
+ [#9138](https://github.com/rust-lang/rust-clippy/pull/9138)
+* [`let_underscore_lock`]: Now ignores bindings that aren't locked
+ [#8990](https://github.com/rust-lang/rust-clippy/pull/8990)
+* [`trivially_copy_pass_by_ref`]: Now tracks lifetimes and ignores cases where unsafe
+ pointers are used
+ [#8639](https://github.com/rust-lang/rust-clippy/pull/8639)
+* [`let_unit_value`]: No longer ignores `#[allow]` attributes on the value
+ [#9082](https://github.com/rust-lang/rust-clippy/pull/9082)
+* [`declare_interior_mutable_const`]: Now ignores the `thread_local!` macro
+ [#9015](https://github.com/rust-lang/rust-clippy/pull/9015)
+* [`if_same_then_else`]: Now ignores branches with `todo!` and `unimplemented!`
+ [#9006](https://github.com/rust-lang/rust-clippy/pull/9006)
+* [`enum_variant_names`]: Now ignores names with `_` prefixes
+ [#9032](https://github.com/rust-lang/rust-clippy/pull/9032)
+* [`let_unit_value`]: Now ignores cases, where the unit type is manually specified
+ [#9056](https://github.com/rust-lang/rust-clippy/pull/9056)
+* [`match_same_arms`]: Now ignores branches with `todo!`
+ [#9207](https://github.com/rust-lang/rust-clippy/pull/9207)
+* [`assign_op_pattern`]: Ignores cases that break borrowing rules
+ [#9214](https://github.com/rust-lang/rust-clippy/pull/9214)
+* [`extra_unused_lifetimes`]: No longer triggers in derive macros
+ [#9037](https://github.com/rust-lang/rust-clippy/pull/9037)
+* [`mismatching_type_param_order`]: Now ignores complicated generic parameters
+ [#9146](https://github.com/rust-lang/rust-clippy/pull/9146)
+* [`equatable_if_let`]: No longer lints in macros
+ [#9074](https://github.com/rust-lang/rust-clippy/pull/9074)
+* [`new_without_default`]: Now ignores generics and lifetime parameters on `fn new`
+ [#9115](https://github.com/rust-lang/rust-clippy/pull/9115)
+* [`needless_borrow`]: Now ignores cases that result in the execution of different traits
+ [#9096](https://github.com/rust-lang/rust-clippy/pull/9096)
+* [`declare_interior_mutable_const`]: No longer triggers in thread-local initializers
+ [#9246](https://github.com/rust-lang/rust-clippy/pull/9246)
+
+### Suggestion Fixes/Improvements
+
+* [`type_repetition_in_bounds`]: The suggestion now works with maybe bounds
+ [#9132](https://github.com/rust-lang/rust-clippy/pull/9132)
+* [`transmute_ptr_to_ref`]: Now suggests `pointer::cast` when possible
+ [#8939](https://github.com/rust-lang/rust-clippy/pull/8939)
+* [`useless_format`]: Now suggests the correct variable name
+ [#9237](https://github.com/rust-lang/rust-clippy/pull/9237)
+* [`or_fun_call`]: The lint emission will now only span over the `unwrap_or` call
+ [#9144](https://github.com/rust-lang/rust-clippy/pull/9144)
+* [`neg_multiply`]: Now suggests adding parentheses around suggestion if needed
+ [#9026](https://github.com/rust-lang/rust-clippy/pull/9026)
+* [`unnecessary_lazy_evaluations`]: Now suggest for `bool::then_some` for lazy evaluation
+ [#9099](https://github.com/rust-lang/rust-clippy/pull/9099)
+* [`manual_flatten`]: Improved message for long code snippets
+ [#9156](https://github.com/rust-lang/rust-clippy/pull/9156)
+* [`explicit_counter_loop`]: The suggestion is now machine applicable
+ [#9149](https://github.com/rust-lang/rust-clippy/pull/9149)
+* [`needless_borrow`]: Now keeps parentheses around fields, when needed
+ [#9210](https://github.com/rust-lang/rust-clippy/pull/9210)
+* [`while_let_on_iterator`]: The suggestion now works in `FnOnce` closures
+ [#9134](https://github.com/rust-lang/rust-clippy/pull/9134)
+
+### ICE Fixes
+
+* Fix ICEs related to `#![feature(generic_const_exprs)]` usage
+ [#9241](https://github.com/rust-lang/rust-clippy/pull/9241)
+* Fix ICEs related to reference lints
+ [#9093](https://github.com/rust-lang/rust-clippy/pull/9093)
+* [`question_mark`]: Fix ICE on zero field tuple structs
+ [#9244](https://github.com/rust-lang/rust-clippy/pull/9244)
+
+### Documentation Improvements
+
+* [`needless_option_take`]: Now includes a "What it does" and "Why is this bad?" section.
+ [#9022](https://github.com/rust-lang/rust-clippy/pull/9022)
+
+### Others
+
+* Using `--cap-lints=allow` and only `--force-warn`ing some will now work with Clippy's driver
+ [#9036](https://github.com/rust-lang/rust-clippy/pull/9036)
+* Clippy now tries to read the `rust-version` from `Cargo.toml` to identify the
+ minimum supported rust version
+ [#8774](https://github.com/rust-lang/rust-clippy/pull/8774)
## Rust 1.63
-Current stable, released 2022-08-11
+Released 2022-08-11
[7c21f91b...d7b5cbf0](https://github.com/rust-lang/rust-clippy/compare/7c21f91b...d7b5cbf0)
@@ -3585,6 +3735,7 @@ Released 2018-09-13
[`approx_constant`]: https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant
[`arithmetic_side_effects`]: https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects
[`as_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_conversions
+[`as_ptr_cast_mut`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_ptr_cast_mut
[`as_underscore`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_underscore
[`assertions_on_constants`]: https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants
[`assertions_on_result_states`]: https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_result_states
@@ -3609,6 +3760,7 @@ Released 2018-09-13
[`borrow_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const
[`borrowed_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrowed_box
[`box_collection`]: https://rust-lang.github.io/rust-clippy/master/index.html#box_collection
+[`box_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#box_default
[`box_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#box_vec
[`boxed_local`]: https://rust-lang.github.io/rust-clippy/master/index.html#boxed_local
[`branches_sharing_code`]: https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code
@@ -3621,6 +3773,7 @@ Released 2018-09-13
[`cast_enum_constructor`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_enum_constructor
[`cast_enum_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_enum_truncation
[`cast_lossless`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
+[`cast_nan_to_int`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_nan_to_int
[`cast_possible_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation
[`cast_possible_wrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap
[`cast_precision_loss`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_precision_loss
@@ -3669,6 +3822,7 @@ Released 2018-09-13
[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
[`derive_partial_eq_without_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq
+[`disallowed_macros`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_macros
[`disallowed_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method
[`disallowed_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods
[`disallowed_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names
@@ -3766,6 +3920,7 @@ Released 2018-09-13
[`implicit_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_clone
[`implicit_hasher`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher
[`implicit_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_return
+[`implicit_saturating_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_add
[`implicit_saturating_sub`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_sub
[`imprecise_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#imprecise_flops
[`inconsistent_digit_grouping`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_digit_grouping
@@ -3800,6 +3955,7 @@ Released 2018-09-13
[`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
[`iter_cloned_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_cloned_collect
[`iter_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_count
+[`iter_kv_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_kv_map
[`iter_next_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_loop
[`iter_next_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_slice
[`iter_not_returning_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator
@@ -3833,6 +3989,8 @@ Released 2018-09-13
[`manual_assert`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert
[`manual_async_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_async_fn
[`manual_bits`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_bits
+[`manual_clamp`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_clamp
+[`manual_filter`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter
[`manual_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter_map
[`manual_find`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find
[`manual_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find_map
@@ -3891,6 +4049,7 @@ Released 2018-09-13
[`missing_panics_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc
[`missing_safety_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc
[`missing_spin_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_spin_loop
+[`missing_trait_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_trait_methods
[`mistyped_literal_suffixes`]: https://rust-lang.github.io/rust-clippy/master/index.html#mistyped_literal_suffixes
[`mixed_case_hex_literals`]: https://rust-lang.github.io/rust-clippy/master/index.html#mixed_case_hex_literals
[`mixed_read_write_in_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#mixed_read_write_in_expression
@@ -3976,6 +4135,7 @@ Released 2018-09-13
[`panic_in_result_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_in_result_fn
[`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params
[`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap
+[`partial_pub_fields`]: https://rust-lang.github.io/rust-clippy/master/index.html#partial_pub_fields
[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
[`partialeq_to_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_to_none
[`path_buf_push_overwrite`]: https://rust-lang.github.io/rust-clippy/master/index.html#path_buf_push_overwrite
@@ -4123,6 +4283,7 @@ Released 2018-09-13
[`unimplemented`]: https://rust-lang.github.io/rust-clippy/master/index.html#unimplemented
[`uninit_assumed_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init
[`uninit_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_vec
+[`uninlined_format_args`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
[`unit_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
[`unit_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_cmp
[`unit_hash`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_hash
@@ -4156,6 +4317,7 @@ Released 2018-09-13
[`unstable_as_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_slice
[`unused_async`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_async
[`unused_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_collect
+[`unused_format_specs`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_format_specs
[`unused_io_amount`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_io_amount
[`unused_label`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_label
[`unused_peekable`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_peekable
diff --git a/src/tools/clippy/CONTRIBUTING.md b/src/tools/clippy/CONTRIBUTING.md
index 28b4cfd5f..85f94a74a 100644
--- a/src/tools/clippy/CONTRIBUTING.md
+++ b/src/tools/clippy/CONTRIBUTING.md
@@ -29,7 +29,7 @@ All contributors are expected to follow the [Rust Code of Conduct].
## The Clippy book
-If you're new to Clippy and don't know where to start the [Clippy book] includes
+If you're new to Clippy and don't know where to start, the [Clippy book] includes
a [developer guide] and is a good place to start your journey.
[Clippy book]: https://doc.rust-lang.org/nightly/clippy/index.html
@@ -110,23 +110,28 @@ Just make sure to remove the dependencies again before finally making a pull req
[IntelliJ_rust_homepage]: https://intellij-rust.github.io/
### Rust Analyzer
-As of [#6869][6869], [`rust-analyzer`][ra_homepage] can understand that Clippy uses compiler-internals
-using `extern crate` when `package.metadata.rust-analyzer.rustc_private` is set to `true` in Clippy's `Cargo.toml.`
-You will require a `nightly` toolchain with the `rustc-dev` component installed.
-Make sure that in the `rust-analyzer` configuration, you set
+For [`rust-analyzer`][ra_homepage] to work correctly make sure that in the `rust-analyzer` configuration you set
+
```json
{ "rust-analyzer.rustc.source": "discover" }
```
-and
-```json
-{ "rust-analyzer.updates.channel": "nightly" }
-```
+
You should be able to see information on things like `Expr` or `EarlyContext` now if you hover them, also
a lot more type hints.
-This will work with `rust-analyzer 2021-03-15` shipped in nightly `1.52.0-nightly (107896c32 2021-03-15)` or later.
+
+To have `rust-analyzer` also work in the `clippy_dev` and `lintcheck` crates, add the following configuration
+
+```json
+{
+ "rust-analyzer.linkedProjects": [
+ "./Cargo.toml",
+ "clippy_dev/Cargo.toml",
+ "lintcheck/Cargo.toml",
+ ]
+}
+```
[ra_homepage]: https://rust-analyzer.github.io/
-[6869]: https://github.com/rust-lang/rust-clippy/pull/6869
## How Clippy works
diff --git a/src/tools/clippy/Cargo.toml b/src/tools/clippy/Cargo.toml
index b7e136ce9..60200a88b 100644
--- a/src/tools/clippy/Cargo.toml
+++ b/src/tools/clippy/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "clippy"
-version = "0.1.65"
+version = "0.1.66"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
@@ -23,12 +23,12 @@ path = "src/driver.rs"
[dependencies]
clippy_lints = { path = "clippy_lints" }
semver = "1.0"
-rustc_tools_util = { path = "rustc_tools_util" }
+rustc_tools_util = "0.2.1"
tempfile = { version = "3.2", optional = true }
termize = "0.1"
[dev-dependencies]
-compiletest_rs = { version = "0.8", features = ["tmp"] }
+compiletest_rs = { version = "0.9", features = ["tmp"] }
tester = "0.9"
regex = "1.5"
toml = "0.5"
@@ -55,7 +55,7 @@ tokio = { version = "1", features = ["io-util"] }
rustc-semver = "1.1"
[build-dependencies]
-rustc_tools_util = { version = "0.2", path = "rustc_tools_util" }
+rustc_tools_util = "0.2.1"
[features]
deny-warnings = ["clippy_lints/deny-warnings"]
diff --git a/src/tools/clippy/README.md b/src/tools/clippy/README.md
index 1193771ff..a8a6b86d2 100644
--- a/src/tools/clippy/README.md
+++ b/src/tools/clippy/README.md
@@ -139,25 +139,6 @@ line. (You can swap `clippy::all` with the specific lint category you are target
## Configuration
-Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml`. It contains a basic `variable =
-value` mapping e.g.
-
-```toml
-avoid-breaking-exported-api = false
-disallowed-names = ["toto", "tata", "titi"]
-cognitive-complexity-threshold = 30
-```
-
-See the [list of lints](https://rust-lang.github.io/rust-clippy/master/index.html) for more information about which
-lints can be configured and the meaning of the variables.
-
-Note that configuration changes will not apply for code that has already been compiled and cached under `./target/`;
-for example, adding a new string to `doc-valid-idents` may still result in Clippy flagging that string. To be sure that
-any configuration changes are applied, you may want to run `cargo clean` and re-compile your crate from scratch.
-
-To deactivate the “for further information visit *lint-link*†message you can
-define the `CLIPPY_DISABLE_DOCS_LINKS` environment variable.
-
### Allowing/denying lints
You can add options to your code to `allow`/`warn`/`deny` Clippy lints:
@@ -205,6 +186,33 @@ the lint(s) you are interested in:
cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::...
```
+### Configure the behavior of some lints
+
+Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml`. It contains a basic `variable =
+value` mapping e.g.
+
+```toml
+avoid-breaking-exported-api = false
+disallowed-names = ["toto", "tata", "titi"]
+cognitive-complexity-threshold = 30
+```
+
+See the [list of lints](https://rust-lang.github.io/rust-clippy/master/index.html) for more information about which
+lints can be configured and the meaning of the variables.
+
+> **Note**
+>
+> `clippy.toml` or `.clippy.toml` cannot be used to allow/deny lints.
+
+> **Note**
+>
+> Configuration changes will not apply for code that has already been compiled and cached under `./target/`;
+> for example, adding a new string to `doc-valid-idents` may still result in Clippy flagging that string. To be sure
+> that any configuration changes are applied, you may want to run `cargo clean` and re-compile your crate from scratch.
+
+To deactivate the “for further information visit *lint-link*†message you can
+define the `CLIPPY_DISABLE_DOCS_LINKS` environment variable.
+
### Specifying the minimum supported Rust version
Projects that intend to support old versions of Rust can disable lints pertaining to newer features by
diff --git a/src/tools/clippy/book/src/development/adding_lints.md b/src/tools/clippy/book/src/development/adding_lints.md
index da781eb97..3c3f368a5 100644
--- a/src/tools/clippy/book/src/development/adding_lints.md
+++ b/src/tools/clippy/book/src/development/adding_lints.md
@@ -90,6 +90,7 @@ We start by opening the test file created at `tests/ui/foo_functions.rs`.
Update the file with some examples to get started:
```rust
+#![allow(unused)]
#![warn(clippy::foo_functions)]
// Impl methods
@@ -477,8 +478,27 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip {
```
Once the `msrv` is added to the lint, a relevant test case should be added to
-`tests/ui/min_rust_version_attr.rs` which verifies that the lint isn't emitted
-if the project's MSRV is lower.
+the lint's test file, `tests/ui/manual_strip.rs` in this example. It should
+have a case for the version below the MSRV and one with the same contents but
+for the MSRV version itself.
+
+```rust
+#![feature(custom_inner_attributes)]
+
+...
+
+fn msrv_1_44() {
+ #![clippy::msrv = "1.44"]
+
+ /* something that would trigger the lint */
+}
+
+fn msrv_1_45() {
+ #![clippy::msrv = "1.45"]
+
+ /* something that would trigger the lint */
+}
+```
As a last step, the lint should be added to the lint documentation. This is done
in `clippy_lints/src/utils/conf.rs`:
diff --git a/src/tools/clippy/book/src/development/basics.md b/src/tools/clippy/book/src/development/basics.md
index 44ba6e327..6fb53236e 100644
--- a/src/tools/clippy/book/src/development/basics.md
+++ b/src/tools/clippy/book/src/development/basics.md
@@ -69,7 +69,7 @@ the reference file with:
cargo dev bless
```
-For example, this is necessary, if you fix a typo in an error message of a lint
+For example, this is necessary if you fix a typo in an error message of a lint,
or if you modify a test file to add a test case.
> _Note:_ This command may update more files than you intended. In that case
@@ -101,8 +101,9 @@ cargo dev setup intellij
cargo dev dogfood
```
-More about intellij command usage and reasons
-[here](https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md#intellij-rust)
+More about [intellij] command usage and reasons.
+
+[intellij]: https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md#intellij-rust
## lintcheck
diff --git a/src/tools/clippy/book/src/development/common_tools_writing_lints.md b/src/tools/clippy/book/src/development/common_tools_writing_lints.md
index 2bc275cef..f5aa06e4b 100644
--- a/src/tools/clippy/book/src/development/common_tools_writing_lints.md
+++ b/src/tools/clippy/book/src/development/common_tools_writing_lints.md
@@ -123,7 +123,8 @@ There are three ways to do this, depending on if the target trait has a
diagnostic item, lang item or neither.
```rust
-use clippy_utils::{implements_trait, is_trait_method, match_trait_method, paths};
+use clippy_utils::ty::implements_trait;
+use clippy_utils::is_trait_method;
use rustc_span::symbol::sym;
impl LateLintPass<'_> for MyStructLint {
@@ -143,13 +144,6 @@ impl LateLintPass<'_> for MyStructLint {
.map_or(false, |id| implements_trait(cx, ty, id, &[])) {
// `expr` implements `Drop` trait
}
-
- // 3. Using the type path with the expression
- // we use `match_trait_method` function from Clippy's utils
- // (This method should be avoided if possible)
- if match_trait_method(cx, expr, &paths::INTO) {
- // `expr` implements `Into` trait
- }
}
}
```
@@ -233,8 +227,9 @@ functions to deal with macros:
crates
```rust
- #[macro_use]
- extern crate a_crate_with_macros;
+ use rustc_middle::lint::in_external_macro;
+
+ use a_crate_with_macros::foo;
// `foo` is defined in `a_crate_with_macros`
foo!("bar");
diff --git a/src/tools/clippy/clippy_dev/src/fmt.rs b/src/tools/clippy/clippy_dev/src/fmt.rs
index 357cf6fc4..256231441 100644
--- a/src/tools/clippy/clippy_dev/src/fmt.rs
+++ b/src/tools/clippy/clippy_dev/src/fmt.rs
@@ -82,16 +82,16 @@ pub fn run(check: bool, verbose: bool) {
fn output_err(err: CliError) {
match err {
CliError::CommandFailed(command, stderr) => {
- eprintln!("error: A command failed! `{}`\nstderr: {}", command, stderr);
+ eprintln!("error: A command failed! `{command}`\nstderr: {stderr}");
},
CliError::IoError(err) => {
- eprintln!("error: {}", err);
+ eprintln!("error: {err}");
},
CliError::RustfmtNotInstalled => {
eprintln!("error: rustfmt nightly is not installed.");
},
CliError::WalkDirError(err) => {
- eprintln!("error: {}", err);
+ eprintln!("error: {err}");
},
CliError::IntellijSetupActive => {
eprintln!(
diff --git a/src/tools/clippy/clippy_dev/src/lib.rs b/src/tools/clippy/clippy_dev/src/lib.rs
index 54c7456a2..80bb83af4 100644
--- a/src/tools/clippy/clippy_dev/src/lib.rs
+++ b/src/tools/clippy/clippy_dev/src/lib.rs
@@ -1,5 +1,4 @@
#![feature(let_chains)]
-#![cfg_attr(bootstrap, feature(let_else))]
#![feature(once_cell)]
#![feature(rustc_private)]
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
diff --git a/src/tools/clippy/clippy_dev/src/main.rs b/src/tools/clippy/clippy_dev/src/main.rs
index a417d3dd8..d3e036692 100644
--- a/src/tools/clippy/clippy_dev/src/main.rs
+++ b/src/tools/clippy/clippy_dev/src/main.rs
@@ -41,7 +41,7 @@ fn main() {
matches.contains_id("msrv"),
) {
Ok(_) => update_lints::update(update_lints::UpdateMode::Change),
- Err(e) => eprintln!("Unable to create lint: {}", e),
+ Err(e) => eprintln!("Unable to create lint: {e}"),
}
},
Some(("setup", sub_command)) => match sub_command.subcommand() {
diff --git a/src/tools/clippy/clippy_dev/src/new_lint.rs b/src/tools/clippy/clippy_dev/src/new_lint.rs
index 331b76484..9e15f1504 100644
--- a/src/tools/clippy/clippy_dev/src/new_lint.rs
+++ b/src/tools/clippy/clippy_dev/src/new_lint.rs
@@ -1,5 +1,5 @@
use crate::clippy_project_root;
-use indoc::{indoc, writedoc};
+use indoc::{formatdoc, writedoc};
use std::fmt::Write as _;
use std::fs::{self, OpenOptions};
use std::io::prelude::*;
@@ -23,7 +23,7 @@ impl<T> Context for io::Result<T> {
match self {
Ok(t) => Ok(t),
Err(e) => {
- let message = format!("{}: {}", text.as_ref(), e);
+ let message = format!("{}: {e}", text.as_ref());
Err(io::Error::new(ErrorKind::Other, message))
},
}
@@ -72,7 +72,7 @@ fn create_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> {
let lint_contents = get_lint_file_contents(lint, enable_msrv);
let lint_path = format!("clippy_lints/src/{}.rs", lint.name);
write_file(lint.project_root.join(&lint_path), lint_contents.as_bytes())?;
- println!("Generated lint file: `{}`", lint_path);
+ println!("Generated lint file: `{lint_path}`");
Ok(())
}
@@ -86,7 +86,7 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
path.push("src");
fs::create_dir(&path)?;
- let header = format!("// compile-flags: --crate-name={}", lint_name);
+ let header = format!("// compile-flags: --crate-name={lint_name}");
write_file(path.join("main.rs"), get_test_file_contents(lint_name, Some(&header)))?;
Ok(())
@@ -106,7 +106,7 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
let test_contents = get_test_file_contents(lint.name, None);
write_file(lint.project_root.join(&test_path), test_contents)?;
- println!("Generated test file: `{}`", test_path);
+ println!("Generated test file: `{test_path}`");
}
Ok(())
@@ -186,37 +186,36 @@ pub(crate) fn get_stabilization_version() -> String {
}
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {
- let mut contents = format!(
- indoc! {"
- #![warn(clippy::{})]
-
- fn main() {{
- // test code goes here
- }}
- "},
- lint_name
+ let mut contents = formatdoc!(
+ r#"
+ #![allow(unused)]
+ #![warn(clippy::{lint_name})]
+
+ fn main() {{
+ // test code goes here
+ }}
+ "#
);
if let Some(header) = header_commands {
- contents = format!("{}\n{}", header, contents);
+ contents = format!("{header}\n{contents}");
}
contents
}
fn get_manifest_contents(lint_name: &str, hint: &str) -> String {
- format!(
- indoc! {r#"
- # {}
-
- [package]
- name = "{}"
- version = "0.1.0"
- publish = false
-
- [workspace]
- "#},
- hint, lint_name
+ formatdoc!(
+ r#"
+ # {hint}
+
+ [package]
+ name = "{lint_name}"
+ version = "0.1.0"
+ publish = false
+
+ [workspace]
+ "#
)
}
@@ -237,76 +236,61 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
let name_upper = lint_name.to_uppercase();
result.push_str(&if enable_msrv {
- format!(
- indoc! {"
- use clippy_utils::msrvs;
- {pass_import}
- use rustc_lint::{{{context_import}, {pass_type}, LintContext}};
- use rustc_semver::RustcVersion;
- use rustc_session::{{declare_tool_lint, impl_lint_pass}};
+ formatdoc!(
+ r#"
+ use clippy_utils::msrvs;
+ {pass_import}
+ use rustc_lint::{{{context_import}, {pass_type}, LintContext}};
+ use rustc_semver::RustcVersion;
+ use rustc_session::{{declare_tool_lint, impl_lint_pass}};
- "},
- pass_type = pass_type,
- pass_import = pass_import,
- context_import = context_import,
+ "#
)
} else {
- format!(
- indoc! {"
- {pass_import}
- use rustc_lint::{{{context_import}, {pass_type}}};
- use rustc_session::{{declare_lint_pass, declare_tool_lint}};
-
- "},
- pass_import = pass_import,
- pass_type = pass_type,
- context_import = context_import
+ formatdoc!(
+ r#"
+ {pass_import}
+ use rustc_lint::{{{context_import}, {pass_type}}};
+ use rustc_session::{{declare_lint_pass, declare_tool_lint}};
+
+ "#
)
});
let _ = write!(result, "{}", get_lint_declaration(&name_upper, category));
result.push_str(&if enable_msrv {
- format!(
- indoc! {"
- pub struct {name_camel} {{
- msrv: Option<RustcVersion>,
- }}
+ formatdoc!(
+ r#"
+ pub struct {name_camel} {{
+ msrv: Option<RustcVersion>,
+ }}
- impl {name_camel} {{
- #[must_use]
- pub fn new(msrv: Option<RustcVersion>) -> Self {{
- Self {{ msrv }}
- }}
+ impl {name_camel} {{
+ #[must_use]
+ pub fn new(msrv: Option<RustcVersion>) -> Self {{
+ Self {{ msrv }}
}}
+ }}
- impl_lint_pass!({name_camel} => [{name_upper}]);
+ impl_lint_pass!({name_camel} => [{name_upper}]);
- impl {pass_type}{pass_lifetimes} for {name_camel} {{
- extract_msrv_attr!({context_import});
- }}
+ impl {pass_type}{pass_lifetimes} for {name_camel} {{
+ extract_msrv_attr!({context_import});
+ }}
- // TODO: Add MSRV level to `clippy_utils/src/msrvs.rs` if needed.
- // TODO: Add MSRV test to `tests/ui/min_rust_version_attr.rs`.
- // TODO: Update msrv config comment in `clippy_lints/src/utils/conf.rs`
- "},
- pass_type = pass_type,
- pass_lifetimes = pass_lifetimes,
- name_upper = name_upper,
- name_camel = name_camel,
- context_import = context_import,
+ // TODO: Add MSRV level to `clippy_utils/src/msrvs.rs` if needed.
+ // TODO: Add MSRV test to `tests/ui/min_rust_version_attr.rs`.
+ // TODO: Update msrv config comment in `clippy_lints/src/utils/conf.rs`
+ "#
)
} else {
- format!(
- indoc! {"
- declare_lint_pass!({name_camel} => [{name_upper}]);
+ formatdoc!(
+ r#"
+ declare_lint_pass!({name_camel} => [{name_upper}]);
- impl {pass_type}{pass_lifetimes} for {name_camel} {{}}
- "},
- pass_type = pass_type,
- pass_lifetimes = pass_lifetimes,
- name_upper = name_upper,
- name_camel = name_camel,
+ impl {pass_type}{pass_lifetimes} for {name_camel} {{}}
+ "#
)
});
@@ -314,8 +298,8 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
}
fn get_lint_declaration(name_upper: &str, category: &str) -> String {
- format!(
- indoc! {r#"
+ formatdoc!(
+ r#"
declare_clippy_lint! {{
/// ### What it does
///
@@ -329,15 +313,13 @@ fn get_lint_declaration(name_upper: &str, category: &str) -> String {
/// ```rust
/// // example code which does not raise clippy warning
/// ```
- #[clippy::version = "{version}"]
+ #[clippy::version = "{}"]
pub {name_upper},
{category},
"default lint description"
}}
- "#},
- version = get_stabilization_version(),
- name_upper = name_upper,
- category = category,
+ "#,
+ get_stabilization_version(),
)
}
@@ -351,7 +333,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
_ => {},
}
- let ty_dir = lint.project_root.join(format!("clippy_lints/src/{}", ty));
+ let ty_dir = lint.project_root.join(format!("clippy_lints/src/{ty}"));
assert!(
ty_dir.exists() && ty_dir.is_dir(),
"Directory `{}` does not exist!",
@@ -411,10 +393,10 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
}
write_file(lint_file_path.as_path(), lint_file_contents)?;
- println!("Generated lint file: `clippy_lints/src/{}/{}.rs`", ty, lint.name);
+ println!("Generated lint file: `clippy_lints/src/{ty}/{}.rs`", lint.name);
println!(
- "Be sure to add a call to `{}::check` in `clippy_lints/src/{}/mod.rs`!",
- lint.name, ty
+ "Be sure to add a call to `{}::check` in `clippy_lints/src/{ty}/mod.rs`!",
+ lint.name
);
Ok(())
@@ -541,7 +523,7 @@ fn setup_mod_file(path: &Path, lint: &LintData<'_>) -> io::Result<&'static str>
.chain(std::iter::once(&*lint_name_upper))
.filter(|s| !s.is_empty())
{
- let _ = write!(new_arr_content, "\n {},", ident);
+ let _ = write!(new_arr_content, "\n {ident},");
}
new_arr_content.push('\n');
diff --git a/src/tools/clippy/clippy_dev/src/serve.rs b/src/tools/clippy/clippy_dev/src/serve.rs
index f15f24da9..535c25e69 100644
--- a/src/tools/clippy/clippy_dev/src/serve.rs
+++ b/src/tools/clippy/clippy_dev/src/serve.rs
@@ -10,8 +10,8 @@ use std::time::{Duration, SystemTime};
/// Panics if the python commands could not be spawned
pub fn run(port: u16, lint: Option<&String>) -> ! {
let mut url = Some(match lint {
- None => format!("http://localhost:{}", port),
- Some(lint) => format!("http://localhost:{}/#{}", port, lint),
+ None => format!("http://localhost:{port}"),
+ Some(lint) => format!("http://localhost:{port}/#{lint}"),
});
loop {
@@ -49,7 +49,7 @@ fn mtime(path: impl AsRef<Path>) -> SystemTime {
.into_iter()
.flatten()
.flatten()
- .map(|entry| mtime(&entry.path()))
+ .map(|entry| mtime(entry.path()))
.max()
.unwrap_or(SystemTime::UNIX_EPOCH)
} else {
diff --git a/src/tools/clippy/clippy_dev/src/setup/git_hook.rs b/src/tools/clippy/clippy_dev/src/setup/git_hook.rs
index 3fbb77d59..1de5b1940 100644
--- a/src/tools/clippy/clippy_dev/src/setup/git_hook.rs
+++ b/src/tools/clippy/clippy_dev/src/setup/git_hook.rs
@@ -30,10 +30,7 @@ pub fn install_hook(force_override: bool) {
println!("info: the hook can be removed with `cargo dev remove git-hook`");
println!("git hook successfully installed");
},
- Err(err) => eprintln!(
- "error: unable to copy `{}` to `{}` ({})",
- HOOK_SOURCE_FILE, HOOK_TARGET_FILE, err
- ),
+ Err(err) => eprintln!("error: unable to copy `{HOOK_SOURCE_FILE}` to `{HOOK_TARGET_FILE}` ({err})"),
}
}
@@ -77,7 +74,7 @@ pub fn remove_hook() {
fn delete_git_hook_file(path: &Path) -> bool {
if let Err(err) = fs::remove_file(path) {
- eprintln!("error: unable to delete existing pre-commit git hook ({})", err);
+ eprintln!("error: unable to delete existing pre-commit git hook ({err})");
false
} else {
true
diff --git a/src/tools/clippy/clippy_dev/src/setup/intellij.rs b/src/tools/clippy/clippy_dev/src/setup/intellij.rs
index bf741e6d1..efdb158c2 100644
--- a/src/tools/clippy/clippy_dev/src/setup/intellij.rs
+++ b/src/tools/clippy/clippy_dev/src/setup/intellij.rs
@@ -36,9 +36,8 @@ impl ClippyProjectInfo {
}
pub fn setup_rustc_src(rustc_path: &str) {
- let rustc_source_dir = match check_and_get_rustc_dir(rustc_path) {
- Ok(path) => path,
- Err(_) => return,
+ let Ok(rustc_source_dir) = check_and_get_rustc_dir(rustc_path) else {
+ return
};
for project in CLIPPY_PROJECTS {
@@ -60,7 +59,7 @@ fn check_and_get_rustc_dir(rustc_path: &str) -> Result<PathBuf, ()> {
path = absolute_path;
},
Err(err) => {
- eprintln!("error: unable to get the absolute path of rustc ({})", err);
+ eprintln!("error: unable to get the absolute path of rustc ({err})");
return Err(());
},
};
@@ -103,14 +102,14 @@ fn inject_deps_into_project(rustc_source_dir: &Path, project: &ClippyProjectInfo
fn read_project_file(file_path: &str) -> Result<String, ()> {
let path = Path::new(file_path);
if !path.exists() {
- eprintln!("error: unable to find the file `{}`", file_path);
+ eprintln!("error: unable to find the file `{file_path}`");
return Err(());
}
match fs::read_to_string(path) {
Ok(content) => Ok(content),
Err(err) => {
- eprintln!("error: the file `{}` could not be read ({})", file_path, err);
+ eprintln!("error: the file `{file_path}` could not be read ({err})");
Err(())
},
}
@@ -124,10 +123,7 @@ fn inject_deps_into_manifest(
) -> std::io::Result<()> {
// do not inject deps if we have already done so
if cargo_toml.contains(RUSTC_PATH_SECTION) {
- eprintln!(
- "warn: dependencies are already setup inside {}, skipping file",
- manifest_path
- );
+ eprintln!("warn: dependencies are already setup inside {manifest_path}, skipping file");
return Ok(());
}
@@ -142,11 +138,7 @@ fn inject_deps_into_manifest(
let new_deps = extern_crates.map(|dep| {
// format the dependencies that are going to be put inside the Cargo.toml
- format!(
- "{dep} = {{ path = \"{source_path}/{dep}\" }}\n",
- dep = dep,
- source_path = rustc_source_dir.display()
- )
+ format!("{dep} = {{ path = \"{}/{dep}\" }}\n", rustc_source_dir.display())
});
// format a new [dependencies]-block with the new deps we need to inject
@@ -163,11 +155,11 @@ fn inject_deps_into_manifest(
// etc
let new_manifest = cargo_toml.replacen("[dependencies]\n", &all_deps, 1);
- // println!("{}", new_manifest);
+ // println!("{new_manifest}");
let mut file = File::create(manifest_path)?;
file.write_all(new_manifest.as_bytes())?;
- println!("info: successfully setup dependencies inside {}", manifest_path);
+ println!("info: successfully setup dependencies inside {manifest_path}");
Ok(())
}
@@ -179,14 +171,10 @@ pub fn remove_rustc_src() {
}
fn remove_rustc_src_from_project(project: &ClippyProjectInfo) -> bool {
- let mut cargo_content = if let Ok(content) = read_project_file(project.cargo_file) {
- content
- } else {
+ let Ok(mut cargo_content) = read_project_file(project.cargo_file) else {
return false;
};
- let section_start = if let Some(section_start) = cargo_content.find(RUSTC_PATH_SECTION) {
- section_start
- } else {
+ let Some(section_start) = cargo_content.find(RUSTC_PATH_SECTION) else {
println!(
"info: dependencies could not be found in `{}` for {}, skipping file",
project.cargo_file, project.name
@@ -194,9 +182,7 @@ fn remove_rustc_src_from_project(project: &ClippyProjectInfo) -> bool {
return true;
};
- let end_point = if let Some(end_point) = cargo_content.find(DEPENDENCIES_SECTION) {
- end_point
- } else {
+ let Some(end_point) = cargo_content.find(DEPENDENCIES_SECTION) else {
eprintln!(
"error: the end of the rustc dependencies section could not be found in `{}`",
project.cargo_file
@@ -214,8 +200,8 @@ fn remove_rustc_src_from_project(project: &ClippyProjectInfo) -> bool {
},
Err(err) => {
eprintln!(
- "error: unable to open file `{}` to remove rustc dependencies for {} ({})",
- project.cargo_file, project.name, err
+ "error: unable to open file `{}` to remove rustc dependencies for {} ({err})",
+ project.cargo_file, project.name
);
false
},
diff --git a/src/tools/clippy/clippy_dev/src/setup/vscode.rs b/src/tools/clippy/clippy_dev/src/setup/vscode.rs
index d59001b2c..dbcdc9b59 100644
--- a/src/tools/clippy/clippy_dev/src/setup/vscode.rs
+++ b/src/tools/clippy/clippy_dev/src/setup/vscode.rs
@@ -17,10 +17,7 @@ pub fn install_tasks(force_override: bool) {
println!("info: the task file can be removed with `cargo dev remove vscode-tasks`");
println!("vscode tasks successfully installed");
},
- Err(err) => eprintln!(
- "error: unable to copy `{}` to `{}` ({})",
- TASK_SOURCE_FILE, TASK_TARGET_FILE, err
- ),
+ Err(err) => eprintln!("error: unable to copy `{TASK_SOURCE_FILE}` to `{TASK_TARGET_FILE}` ({err})"),
}
}
@@ -44,23 +41,17 @@ fn check_install_precondition(force_override: bool) -> bool {
return delete_vs_task_file(path);
}
- eprintln!(
- "error: there is already a `task.json` file inside the `{}` directory",
- VSCODE_DIR
- );
+ eprintln!("error: there is already a `task.json` file inside the `{VSCODE_DIR}` directory");
println!("info: use the `--force-override` flag to override the existing `task.json` file");
return false;
}
} else {
match fs::create_dir(vs_dir_path) {
Ok(_) => {
- println!("info: created `{}` directory for clippy", VSCODE_DIR);
+ println!("info: created `{VSCODE_DIR}` directory for clippy");
},
Err(err) => {
- eprintln!(
- "error: the task target directory `{}` could not be created ({})",
- VSCODE_DIR, err
- );
+ eprintln!("error: the task target directory `{VSCODE_DIR}` could not be created ({err})");
},
}
}
@@ -82,7 +73,7 @@ pub fn remove_tasks() {
fn delete_vs_task_file(path: &Path) -> bool {
if let Err(err) = fs::remove_file(path) {
- eprintln!("error: unable to delete the existing `tasks.json` file ({})", err);
+ eprintln!("error: unable to delete the existing `tasks.json` file ({err})");
return false;
}
diff --git a/src/tools/clippy/clippy_dev/src/update_lints.rs b/src/tools/clippy/clippy_dev/src/update_lints.rs
index b95061bf8..e690bc369 100644
--- a/src/tools/clippy/clippy_dev/src/update_lints.rs
+++ b/src/tools/clippy/clippy_dev/src/update_lints.rs
@@ -45,9 +45,8 @@ fn generate_lint_files(
renamed_lints: &[RenamedLint],
) {
let internal_lints = Lint::internal_lints(lints);
- let usable_lints = Lint::usable_lints(lints);
- let mut sorted_usable_lints = usable_lints.clone();
- sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
+ let mut usable_lints = Lint::usable_lints(lints);
+ usable_lints.sort_by_key(|lint| lint.name.clone());
replace_region_in_file(
update_mode,
@@ -86,7 +85,7 @@ fn generate_lint_files(
)
.sorted()
{
- writeln!(res, "[`{}`]: {}#{}", lint, DOCS_LINK, lint).unwrap();
+ writeln!(res, "[`{lint}`]: {DOCS_LINK}#{lint}").unwrap();
}
},
);
@@ -99,7 +98,7 @@ fn generate_lint_files(
"// end lints modules, do not remove this comment, it’s used in `update_lints`",
|res| {
for lint_mod in usable_lints.iter().map(|l| &l.module).unique().sorted() {
- writeln!(res, "mod {};", lint_mod).unwrap();
+ writeln!(res, "mod {lint_mod};").unwrap();
}
},
);
@@ -129,7 +128,7 @@ fn generate_lint_files(
for (lint_group, lints) in Lint::by_lint_group(usable_lints.into_iter().chain(internal_lints)) {
let content = gen_lint_group_list(&lint_group, lints.iter());
process_file(
- &format!("clippy_lints/src/lib.register_{}.rs", lint_group),
+ format!("clippy_lints/src/lib.register_{lint_group}.rs"),
update_mode,
&content,
);
@@ -190,9 +189,9 @@ fn print_lint_names(header: &str, lints: &BTreeSet<String>) -> bool {
if lints.is_empty() {
return false;
}
- println!("{}", header);
+ println!("{header}");
for lint in lints.iter().sorted() {
- println!(" {}", lint);
+ println!(" {lint}");
}
println!();
true
@@ -205,16 +204,16 @@ pub fn print_lints() {
let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
for (lint_group, mut lints) in grouped_by_lint_group {
- println!("\n## {}", lint_group);
+ println!("\n## {lint_group}");
lints.sort_by_key(|l| l.name.clone());
for lint in lints {
- println!("* [{}]({}#{}) ({})", lint.name, DOCS_LINK, lint.name, lint.desc);
+ println!("* [{}]({DOCS_LINK}#{}) ({})", lint.name, lint.name, lint.desc);
}
}
- println!("there are {} lints", usable_lint_count);
+ println!("there are {usable_lint_count} lints");
}
/// Runs the `rename_lint` command.
@@ -235,10 +234,10 @@ pub fn print_lints() {
#[allow(clippy::too_many_lines)]
pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
if let Some((prefix, _)) = old_name.split_once("::") {
- panic!("`{}` should not contain the `{}` prefix", old_name, prefix);
+ panic!("`{old_name}` should not contain the `{prefix}` prefix");
}
if let Some((prefix, _)) = new_name.split_once("::") {
- panic!("`{}` should not contain the `{}` prefix", new_name, prefix);
+ panic!("`{new_name}` should not contain the `{prefix}` prefix");
}
let (mut lints, deprecated_lints, mut renamed_lints) = gather_all();
@@ -251,14 +250,14 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
found_new_name = true;
}
}
- let old_lint_index = old_lint_index.unwrap_or_else(|| panic!("could not find lint `{}`", old_name));
+ let old_lint_index = old_lint_index.unwrap_or_else(|| panic!("could not find lint `{old_name}`"));
let lint = RenamedLint {
- old_name: format!("clippy::{}", old_name),
+ old_name: format!("clippy::{old_name}"),
new_name: if uplift {
new_name.into()
} else {
- format!("clippy::{}", new_name)
+ format!("clippy::{new_name}")
},
};
@@ -266,13 +265,11 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
// case.
assert!(
!renamed_lints.iter().any(|l| lint.old_name == l.old_name),
- "`{}` has already been renamed",
- old_name
+ "`{old_name}` has already been renamed"
);
assert!(
!deprecated_lints.iter().any(|l| lint.old_name == l.name),
- "`{}` has already been deprecated",
- old_name
+ "`{old_name}` has already been deprecated"
);
// Update all lint level attributes. (`clippy::lint_name`)
@@ -309,14 +306,12 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
if uplift {
write_file(Path::new("tests/ui/rename.rs"), &gen_renamed_lints_test(&renamed_lints));
println!(
- "`{}` has be uplifted. All the code inside `clippy_lints` related to it needs to be removed manually.",
- old_name
+ "`{old_name}` has be uplifted. All the code inside `clippy_lints` related to it needs to be removed manually."
);
} else if found_new_name {
write_file(Path::new("tests/ui/rename.rs"), &gen_renamed_lints_test(&renamed_lints));
println!(
- "`{}` is already defined. The old linting code inside `clippy_lints` needs to be updated/removed manually.",
- new_name
+ "`{new_name}` is already defined. The old linting code inside `clippy_lints` needs to be updated/removed manually."
);
} else {
// Rename the lint struct and source files sharing a name with the lint.
@@ -327,16 +322,16 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
// Rename test files. only rename `.stderr` and `.fixed` files if the new test name doesn't exist.
if try_rename_file(
- Path::new(&format!("tests/ui/{}.rs", old_name)),
- Path::new(&format!("tests/ui/{}.rs", new_name)),
+ Path::new(&format!("tests/ui/{old_name}.rs")),
+ Path::new(&format!("tests/ui/{new_name}.rs")),
) {
try_rename_file(
- Path::new(&format!("tests/ui/{}.stderr", old_name)),
- Path::new(&format!("tests/ui/{}.stderr", new_name)),
+ Path::new(&format!("tests/ui/{old_name}.stderr")),
+ Path::new(&format!("tests/ui/{new_name}.stderr")),
);
try_rename_file(
- Path::new(&format!("tests/ui/{}.fixed", old_name)),
- Path::new(&format!("tests/ui/{}.fixed", new_name)),
+ Path::new(&format!("tests/ui/{old_name}.fixed")),
+ Path::new(&format!("tests/ui/{new_name}.fixed")),
);
}
@@ -344,8 +339,8 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
let replacements;
let replacements = if lint.module == old_name
&& try_rename_file(
- Path::new(&format!("clippy_lints/src/{}.rs", old_name)),
- Path::new(&format!("clippy_lints/src/{}.rs", new_name)),
+ Path::new(&format!("clippy_lints/src/{old_name}.rs")),
+ Path::new(&format!("clippy_lints/src/{new_name}.rs")),
) {
// Edit the module name in the lint list. Note there could be multiple lints.
for lint in lints.iter_mut().filter(|l| l.module == old_name) {
@@ -356,14 +351,14 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
} else if !lint.module.contains("::")
// Catch cases like `methods/lint_name.rs` where the lint is stored in `methods/mod.rs`
&& try_rename_file(
- Path::new(&format!("clippy_lints/src/{}/{}.rs", lint.module, old_name)),
- Path::new(&format!("clippy_lints/src/{}/{}.rs", lint.module, new_name)),
+ Path::new(&format!("clippy_lints/src/{}/{old_name}.rs", lint.module)),
+ Path::new(&format!("clippy_lints/src/{}/{new_name}.rs", lint.module)),
)
{
// Edit the module name in the lint list. Note there could be multiple lints, or none.
- let renamed_mod = format!("{}::{}", lint.module, old_name);
+ let renamed_mod = format!("{}::{old_name}", lint.module);
for lint in lints.iter_mut().filter(|l| l.module == renamed_mod) {
- lint.module = format!("{}::{}", lint.module, new_name);
+ lint.module = format!("{}::{new_name}", lint.module);
}
replacements = [(&*old_name_upper, &*new_name_upper), (old_name, new_name)];
replacements.as_slice()
@@ -379,7 +374,7 @@ pub fn rename(old_name: &str, new_name: &str, uplift: bool) {
}
generate_lint_files(UpdateMode::Change, &lints, &deprecated_lints, &renamed_lints);
- println!("{} has been successfully renamed", old_name);
+ println!("{old_name} has been successfully renamed");
}
println!("note: `cargo uitest` still needs to be run to update the test results");
@@ -408,7 +403,7 @@ pub fn deprecate(name: &str, reason: Option<&String>) {
});
generate_lint_files(UpdateMode::Change, &lints, &deprecated_lints, &renamed_lints);
- println!("info: `{}` has successfully been deprecated", name);
+ println!("info: `{name}` has successfully been deprecated");
if reason == DEFAULT_DEPRECATION_REASON {
println!("note: the deprecation reason must be updated in `clippy_lints/src/deprecated_lints.rs`");
@@ -421,7 +416,7 @@ pub fn deprecate(name: &str, reason: Option<&String>) {
let name_upper = name.to_uppercase();
let (mut lints, deprecated_lints, renamed_lints) = gather_all();
- let Some(lint) = lints.iter().find(|l| l.name == name_lower) else { eprintln!("error: failed to find lint `{}`", name); return; };
+ let Some(lint) = lints.iter().find(|l| l.name == name_lower) else { eprintln!("error: failed to find lint `{name}`"); return; };
let mod_path = {
let mut mod_path = PathBuf::from(format!("clippy_lints/src/{}", lint.module));
@@ -450,7 +445,7 @@ fn remove_lint_declaration(name: &str, path: &Path, lints: &mut Vec<Lint>) -> io
}
fn remove_test_assets(name: &str) {
- let test_file_stem = format!("tests/ui/{}", name);
+ let test_file_stem = format!("tests/ui/{name}");
let path = Path::new(&test_file_stem);
// Some lints have their own directories, delete them
@@ -512,8 +507,7 @@ fn remove_lint_declaration(name: &str, path: &Path, lints: &mut Vec<Lint>) -> io
fs::read_to_string(path).unwrap_or_else(|_| panic!("failed to read `{}`", path.to_string_lossy()));
eprintln!(
- "warn: you will have to manually remove any code related to `{}` from `{}`",
- name,
+ "warn: you will have to manually remove any code related to `{name}` from `{}`",
path.display()
);
@@ -528,7 +522,7 @@ fn remove_lint_declaration(name: &str, path: &Path, lints: &mut Vec<Lint>) -> io
content.replace_range(lint.declaration_range.clone(), "");
// Remove the module declaration (mod xyz;)
- let mod_decl = format!("\nmod {};", name);
+ let mod_decl = format!("\nmod {name};");
content = content.replacen(&mod_decl, "", 1);
remove_impl_lint_pass(&lint.name.to_uppercase(), &mut content);
@@ -621,13 +615,13 @@ fn round_to_fifty(count: usize) -> usize {
fn process_file(path: impl AsRef<Path>, update_mode: UpdateMode, content: &str) {
if update_mode == UpdateMode::Check {
let old_content =
- fs::read_to_string(&path).unwrap_or_else(|e| panic!("Cannot read from {}: {}", path.as_ref().display(), e));
+ fs::read_to_string(&path).unwrap_or_else(|e| panic!("Cannot read from {}: {e}", path.as_ref().display()));
if content != old_content {
exit_with_failure();
}
} else {
fs::write(&path, content.as_bytes())
- .unwrap_or_else(|e| panic!("Cannot write to {}: {}", path.as_ref().display(), e));
+ .unwrap_or_else(|e| panic!("Cannot write to {}: {e}", path.as_ref().display()));
}
}
@@ -731,11 +725,10 @@ fn gen_lint_group_list<'a>(group_name: &str, lints: impl Iterator<Item = &'a Lin
let _ = writeln!(
output,
- "store.register_group(true, \"clippy::{0}\", Some(\"clippy_{0}\"), vec![",
- group_name
+ "store.register_group(true, \"clippy::{group_name}\", Some(\"clippy_{group_name}\"), vec![",
);
for (module, name) in details {
- let _ = writeln!(output, " LintId::of({}::{}),", module, name);
+ let _ = writeln!(output, " LintId::of({module}::{name}),");
}
output.push_str("])\n");
@@ -783,7 +776,7 @@ fn gen_register_lint_list<'a>(
if !is_public {
output.push_str(" #[cfg(feature = \"internal\")]\n");
}
- let _ = writeln!(output, " {}::{},", module_name, lint_name);
+ let _ = writeln!(output, " {module_name}::{lint_name},");
}
output.push_str("])\n");
@@ -841,7 +834,7 @@ fn gather_all() -> (Vec<Lint>, Vec<DeprecatedLint>, Vec<RenamedLint>) {
for (rel_path, file) in clippy_lints_src_files() {
let path = file.path();
let contents =
- fs::read_to_string(path).unwrap_or_else(|e| panic!("Cannot read from `{}`: {}", path.display(), e));
+ fs::read_to_string(path).unwrap_or_else(|e| panic!("Cannot read from `{}`: {e}", path.display()));
let module = rel_path
.components()
.map(|c| c.as_os_str().to_str().unwrap())
@@ -876,13 +869,11 @@ fn clippy_lints_src_files() -> impl Iterator<Item = (PathBuf, DirEntry)> {
macro_rules! match_tokens {
($iter:ident, $($token:ident $({$($fields:tt)*})? $(($capture:ident))?)*) => {
{
- $($(let $capture =)? if let Some(LintDeclSearchResult {
+ $(#[allow(clippy::redundant_pattern)] let Some(LintDeclSearchResult {
token_kind: TokenKind::$token $({$($fields)*})?,
- content: _x,
+ content: $($capture @)? _,
..
- }) = $iter.next() {
- _x
- } else {
+ }) = $iter.next() else {
continue;
};)*
#[allow(clippy::unused_unit)]
@@ -1050,7 +1041,7 @@ fn remove_line_splices(s: &str) -> String {
.trim_matches('#')
.strip_prefix('"')
.and_then(|s| s.strip_suffix('"'))
- .unwrap_or_else(|| panic!("expected quoted string, found `{}`", s));
+ .unwrap_or_else(|| panic!("expected quoted string, found `{s}`"));
let mut res = String::with_capacity(s.len());
unescape::unescape_literal(s, unescape::Mode::Str, &mut |range, ch| {
if ch.is_ok() {
@@ -1076,10 +1067,10 @@ fn replace_region_in_file(
end: &str,
write_replacement: impl FnMut(&mut String),
) {
- let contents = fs::read_to_string(path).unwrap_or_else(|e| panic!("Cannot read from `{}`: {}", path.display(), e));
+ let contents = fs::read_to_string(path).unwrap_or_else(|e| panic!("Cannot read from `{}`: {e}", path.display()));
let new_contents = match replace_region_in_text(&contents, start, end, write_replacement) {
Ok(x) => x,
- Err(delim) => panic!("Couldn't find `{}` in file `{}`", delim, path.display()),
+ Err(delim) => panic!("Couldn't find `{delim}` in file `{}`", path.display()),
};
match update_mode {
@@ -1087,7 +1078,7 @@ fn replace_region_in_file(
UpdateMode::Check => (),
UpdateMode::Change => {
if let Err(e) = fs::write(path, new_contents.as_bytes()) {
- panic!("Cannot write to `{}`: {}", path.display(), e);
+ panic!("Cannot write to `{}`: {e}", path.display());
}
},
}
@@ -1135,7 +1126,7 @@ fn try_rename_file(old_name: &Path, new_name: &Path) -> bool {
#[allow(clippy::needless_pass_by_value)]
fn panic_file(error: io::Error, name: &Path, action: &str) -> ! {
- panic!("failed to {} file `{}`: {}", action, name.display(), error)
+ panic!("failed to {action} file `{}`: {error}", name.display())
}
fn rewrite_file(path: &Path, f: impl FnOnce(&str) -> Option<String>) {
diff --git a/src/tools/clippy/clippy_lints/Cargo.toml b/src/tools/clippy/clippy_lints/Cargo.toml
index 738562ef8..6fbd6401e 100644
--- a/src/tools/clippy/clippy_lints/Cargo.toml
+++ b/src/tools/clippy/clippy_lints/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "clippy_lints"
-version = "0.1.65"
+version = "0.1.66"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
diff --git a/src/tools/clippy/clippy_lints/src/almost_complete_letter_range.rs b/src/tools/clippy/clippy_lints/src/almost_complete_letter_range.rs
index 59a7c5354..073e4af13 100644
--- a/src/tools/clippy/clippy_lints/src/almost_complete_letter_range.rs
+++ b/src/tools/clippy/clippy_lints/src/almost_complete_letter_range.rs
@@ -4,6 +4,7 @@ use clippy_utils::{meets_msrv, msrvs};
use rustc_ast::ast::{Expr, ExprKind, LitKind, Pat, PatKind, RangeEnd, RangeLimits};
use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
+use rustc_middle::lint::in_external_macro;
use rustc_semver::RustcVersion;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::Span;
@@ -79,6 +80,7 @@ fn check_range(cx: &EarlyContext<'_>, span: Span, start: &Expr, end: &Expr, sugg
(LitKind::Byte(b'a') | LitKind::Char('a'), LitKind::Byte(b'z') | LitKind::Char('z'))
| (LitKind::Byte(b'A') | LitKind::Char('A'), LitKind::Byte(b'Z') | LitKind::Char('Z'))
)
+ && !in_external_macro(cx.sess(), span)
{
span_lint_and_then(
cx,
diff --git a/src/tools/clippy/clippy_lints/src/approx_const.rs b/src/tools/clippy/clippy_lints/src/approx_const.rs
index 159f3b0cd..724490fb4 100644
--- a/src/tools/clippy/clippy_lints/src/approx_const.rs
+++ b/src/tools/clippy/clippy_lints/src/approx_const.rs
@@ -92,7 +92,7 @@ impl ApproxConstant {
cx,
APPROX_CONSTANT,
e.span,
- &format!("approximate value of `{}::consts::{}` found", module, &name),
+ &format!("approximate value of `{module}::consts::{}` found", &name),
None,
"consider using the constant directly",
);
@@ -126,7 +126,7 @@ fn is_approx_const(constant: f64, value: &str, min_digits: usize) -> bool {
// The value is a truncated constant
true
} else {
- let round_const = format!("{:.*}", value.len() - 2, constant);
+ let round_const = format!("{constant:.*}", value.len() - 2);
value == round_const
}
}
diff --git a/src/tools/clippy/clippy_lints/src/asm_syntax.rs b/src/tools/clippy/clippy_lints/src/asm_syntax.rs
index f419781db..9717aa9e9 100644
--- a/src/tools/clippy/clippy_lints/src/asm_syntax.rs
+++ b/src/tools/clippy/clippy_lints/src/asm_syntax.rs
@@ -44,7 +44,7 @@ fn check_expr_asm_syntax(lint: &'static Lint, cx: &EarlyContext<'_>, expr: &Expr
cx,
lint,
expr.span,
- &format!("{} x86 assembly syntax used", style),
+ &format!("{style} x86 assembly syntax used"),
None,
&format!("use {} x86 assembly syntax", !style),
);
@@ -64,6 +64,7 @@ declare_clippy_lint! {
///
/// ```rust,no_run
/// # #![feature(asm)]
+ /// # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
/// # unsafe { let ptr = "".as_ptr();
/// # use std::arch::asm;
/// asm!("lea {}, [{}]", lateout(reg) _, in(reg) ptr);
@@ -72,6 +73,7 @@ declare_clippy_lint! {
/// Use instead:
/// ```rust,no_run
/// # #![feature(asm)]
+ /// # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
/// # unsafe { let ptr = "".as_ptr();
/// # use std::arch::asm;
/// asm!("lea ({}), {}", in(reg) ptr, lateout(reg) _, options(att_syntax));
@@ -103,6 +105,7 @@ declare_clippy_lint! {
///
/// ```rust,no_run
/// # #![feature(asm)]
+ /// # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
/// # unsafe { let ptr = "".as_ptr();
/// # use std::arch::asm;
/// asm!("lea ({}), {}", in(reg) ptr, lateout(reg) _, options(att_syntax));
@@ -111,6 +114,7 @@ declare_clippy_lint! {
/// Use instead:
/// ```rust,no_run
/// # #![feature(asm)]
+ /// # #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
/// # unsafe { let ptr = "".as_ptr();
/// # use std::arch::asm;
/// asm!("lea {}, [{}]", lateout(reg) _, in(reg) ptr);
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 2705ffffd..a36df55d0 100644
--- a/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs
+++ b/src/tools/clippy/clippy_lints/src/assertions_on_constants.rs
@@ -60,9 +60,9 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
cx,
ASSERTIONS_ON_CONSTANTS,
macro_call.span,
- &format!("`assert!(false{})` should probably be replaced", assert_arg),
+ &format!("`assert!(false{assert_arg})` should probably be replaced"),
None,
- &format!("use `panic!({})` or `unreachable!({0})`", panic_arg),
+ &format!("use `panic!({panic_arg})` or `unreachable!({panic_arg})`"),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/assertions_on_result_states.rs b/src/tools/clippy/clippy_lints/src/assertions_on_result_states.rs
index 7cd198ace..f6d6c23bb 100644
--- a/src/tools/clippy/clippy_lints/src/assertions_on_result_states.rs
+++ b/src/tools/clippy/clippy_lints/src/assertions_on_result_states.rs
@@ -1,9 +1,9 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::macros::{find_assert_args, root_macro_call_first_node, PanicExpn};
-use clippy_utils::path_res;
use clippy_utils::source::snippet_with_context;
-use clippy_utils::ty::{implements_trait, is_copy, is_type_diagnostic_item};
+use clippy_utils::ty::{has_debug_impl, is_copy, is_type_diagnostic_item};
use clippy_utils::usage::local_used_after_expr;
+use clippy_utils::{is_expr_final_block_expr, path_res};
use rustc_errors::Applicability;
use rustc_hir::def::Res;
use rustc_hir::{Expr, ExprKind};
@@ -58,6 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
return;
}
}
+ let semicolon = if is_expr_final_block_expr(cx.tcx, e) {";"} else {""};
let mut app = Applicability::MachineApplicable;
match method_segment.ident.as_str() {
"is_ok" if type_suitable_to_unwrap(cx, substs.type_at(1)) => {
@@ -68,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
"called `assert!` with `Result::is_ok`",
"replace with",
format!(
- "{}.unwrap()",
+ "{}.unwrap(){semicolon}",
snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0
),
app,
@@ -82,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
"called `assert!` with `Result::is_err`",
"replace with",
format!(
- "{}.unwrap_err()",
+ "{}.unwrap_err(){semicolon}",
snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0
),
app,
@@ -94,13 +95,6 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
}
}
-/// This checks whether a given type is known to implement Debug.
-fn has_debug_impl<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
- cx.tcx
- .get_diagnostic_item(sym::Debug)
- .map_or(false, |debug| implements_trait(cx, ty, debug, &[]))
-}
-
fn type_suitable_to_unwrap<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
has_debug_impl(cx, ty) && !ty.is_unit() && !ty.is_never()
}
diff --git a/src/tools/clippy/clippy_lints/src/attrs.rs b/src/tools/clippy/clippy_lints/src/attrs.rs
index 732dc2b43..0bd1f8b78 100644
--- a/src/tools/clippy/clippy_lints/src/attrs.rs
+++ b/src/tools/clippy/clippy_lints/src/attrs.rs
@@ -357,7 +357,8 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
"wildcard_imports"
| "enum_glob_use"
| "redundant_pub_crate"
- | "macro_use_imports",
+ | "macro_use_imports"
+ | "unsafe_removed_from_name",
)
})
{
@@ -541,10 +542,7 @@ fn check_attrs(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribut
cx,
INLINE_ALWAYS,
attr.span,
- &format!(
- "you have declared `#[inline(always)]` on `{}`. This is usually a bad idea",
- name
- ),
+ &format!("you have declared `#[inline(always)]` on `{name}`. This is usually a bad idea"),
);
}
}
@@ -720,7 +718,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
let mut unix_suggested = false;
for (os, span) in mismatched {
- let sugg = format!("target_os = \"{}\"", os);
+ let sugg = format!("target_os = \"{os}\"");
diag.span_suggestion(span, "try", sugg, Applicability::MaybeIncorrect);
if !unix_suggested && is_unix(os) {
diff --git a/src/tools/clippy/clippy_lints/src/await_holding_invalid.rs b/src/tools/clippy/clippy_lints/src/await_holding_invalid.rs
index 1761360fb..347178118 100644
--- a/src/tools/clippy/clippy_lints/src/await_holding_invalid.rs
+++ b/src/tools/clippy/clippy_lints/src/await_holding_invalid.rs
@@ -1,14 +1,15 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::{match_def_path, paths};
use rustc_data_structures::fx::FxHashMap;
+use rustc_hir::def::{Namespace, Res};
use rustc_hir::def_id::DefId;
-use rustc_hir::{def::Res, AsyncGeneratorKind, Body, BodyId, GeneratorKind};
+use rustc_hir::{AsyncGeneratorKind, Body, BodyId, GeneratorKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::GeneratorInteriorTypeCause;
use rustc_session::{declare_tool_lint, impl_lint_pass};
-use rustc_span::Span;
+use rustc_span::{sym, Span};
-use crate::utils::conf::DisallowedType;
+use crate::utils::conf::DisallowedPath;
declare_clippy_lint! {
/// ### What it does
@@ -171,12 +172,12 @@ impl_lint_pass!(AwaitHolding => [AWAIT_HOLDING_LOCK, AWAIT_HOLDING_REFCELL_REF,
#[derive(Debug)]
pub struct AwaitHolding {
- conf_invalid_types: Vec<DisallowedType>,
- def_ids: FxHashMap<DefId, DisallowedType>,
+ conf_invalid_types: Vec<DisallowedPath>,
+ def_ids: FxHashMap<DefId, DisallowedPath>,
}
impl AwaitHolding {
- pub(crate) fn new(conf_invalid_types: Vec<DisallowedType>) -> Self {
+ pub(crate) fn new(conf_invalid_types: Vec<DisallowedPath>) -> Self {
Self {
conf_invalid_types,
def_ids: FxHashMap::default(),
@@ -187,11 +188,8 @@ impl AwaitHolding {
impl LateLintPass<'_> for AwaitHolding {
fn check_crate(&mut self, cx: &LateContext<'_>) {
for conf in &self.conf_invalid_types {
- let path = match conf {
- DisallowedType::Simple(path) | DisallowedType::WithReason { path, .. } => path,
- };
- let segs: Vec<_> = path.split("::").collect();
- if let Res::Def(_, id) = clippy_utils::def_path_res(cx, &segs) {
+ let segs: Vec<_> = conf.path().split("::").collect();
+ if let Res::Def(_, id) = clippy_utils::def_path_res(cx, &segs, Some(Namespace::TypeNS)) {
self.def_ids.insert(id, conf.clone());
}
}
@@ -256,29 +254,27 @@ impl AwaitHolding {
}
}
-fn emit_invalid_type(cx: &LateContext<'_>, span: Span, disallowed: &DisallowedType) {
- let (type_name, reason) = match disallowed {
- DisallowedType::Simple(path) => (path, &None),
- DisallowedType::WithReason { path, reason } => (path, reason),
- };
-
+fn emit_invalid_type(cx: &LateContext<'_>, span: Span, disallowed: &DisallowedPath) {
span_lint_and_then(
cx,
AWAIT_HOLDING_INVALID_TYPE,
span,
- &format!("`{type_name}` may not be held across an `await` point per `clippy.toml`",),
+ &format!(
+ "`{}` may not be held across an `await` point per `clippy.toml`",
+ disallowed.path()
+ ),
|diag| {
- if let Some(reason) = reason {
- diag.note(reason.clone());
+ if let Some(reason) = disallowed.reason() {
+ diag.note(reason);
}
},
);
}
fn is_mutex_guard(cx: &LateContext<'_>, def_id: DefId) -> bool {
- match_def_path(cx, def_id, &paths::MUTEX_GUARD)
- || match_def_path(cx, def_id, &paths::RWLOCK_READ_GUARD)
- || match_def_path(cx, def_id, &paths::RWLOCK_WRITE_GUARD)
+ cx.tcx.is_diagnostic_item(sym::MutexGuard, def_id)
+ || cx.tcx.is_diagnostic_item(sym::RwLockReadGuard, def_id)
+ || cx.tcx.is_diagnostic_item(sym::RwLockWriteGuard, def_id)
|| match_def_path(cx, def_id, &paths::PARKING_LOT_MUTEX_GUARD)
|| match_def_path(cx, def_id, &paths::PARKING_LOT_RWLOCK_READ_GUARD)
|| match_def_path(cx, def_id, &paths::PARKING_LOT_RWLOCK_WRITE_GUARD)
diff --git a/src/tools/clippy/clippy_lints/src/blocks_in_if_conditions.rs b/src/tools/clippy/clippy_lints/src/blocks_in_if_conditions.rs
index d9e2c9c85..9c0532474 100644
--- a/src/tools/clippy/clippy_lints/src/blocks_in_if_conditions.rs
+++ b/src/tools/clippy/clippy_lints/src/blocks_in_if_conditions.rs
@@ -3,10 +3,11 @@ use clippy_utils::get_parent_expr;
use clippy_utils::higher;
use clippy_utils::source::snippet_block_with_applicability;
use clippy_utils::ty::implements_trait;
+use clippy_utils::visitors::{for_each_expr, Descend};
+use core::ops::ControlFlow;
use if_chain::if_chain;
use rustc_errors::Applicability;
-use rustc_hir::intravisit::{walk_expr, Visitor};
-use rustc_hir::{BlockCheckMode, Closure, Expr, ExprKind};
+use rustc_hir::{BlockCheckMode, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -44,39 +45,6 @@ declare_clippy_lint! {
declare_lint_pass!(BlocksInIfConditions => [BLOCKS_IN_IF_CONDITIONS]);
-struct ExVisitor<'a, 'tcx> {
- found_block: Option<&'tcx Expr<'tcx>>,
- cx: &'a LateContext<'tcx>,
-}
-
-impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
- fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
- if let ExprKind::Closure(&Closure { body, .. }) = expr.kind {
- // do not lint if the closure is called using an iterator (see #1141)
- if_chain! {
- if let Some(parent) = get_parent_expr(self.cx, expr);
- if let ExprKind::MethodCall(_, self_arg, ..) = &parent.kind;
- let caller = self.cx.typeck_results().expr_ty(self_arg);
- if let Some(iter_id) = self.cx.tcx.get_diagnostic_item(sym::Iterator);
- if implements_trait(self.cx, caller, iter_id, &[]);
- then {
- return;
- }
- }
-
- let body = self.cx.tcx.hir().body(body);
- let ex = &body.value;
- if let ExprKind::Block(block, _) = ex.kind {
- if !body.value.span.from_expansion() && !block.stmts.is_empty() {
- self.found_block = Some(ex);
- return;
- }
- }
- }
- walk_expr(self, expr);
- }
-}
-
const BRACED_EXPR_MESSAGE: &str = "omit braces around single expression condition";
const COMPLEX_BLOCK_MESSAGE: &str = "in an `if` condition, avoid complex blocks or closures with blocks; \
instead, move the block or closure higher and bind it with a `let`";
@@ -145,11 +113,31 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions {
}
}
} else {
- let mut visitor = ExVisitor { found_block: None, cx };
- walk_expr(&mut visitor, cond);
- if let Some(block) = visitor.found_block {
- span_lint(cx, BLOCKS_IN_IF_CONDITIONS, block.span, COMPLEX_BLOCK_MESSAGE);
- }
+ let _: Option<!> = for_each_expr(cond, |e| {
+ if let ExprKind::Closure(closure) = e.kind {
+ // do not lint if the closure is called using an iterator (see #1141)
+ if_chain! {
+ if let Some(parent) = get_parent_expr(cx, e);
+ if let ExprKind::MethodCall(_, self_arg, _, _) = &parent.kind;
+ let caller = cx.typeck_results().expr_ty(self_arg);
+ if let Some(iter_id) = cx.tcx.get_diagnostic_item(sym::Iterator);
+ if implements_trait(cx, caller, iter_id, &[]);
+ then {
+ return ControlFlow::Continue(Descend::No);
+ }
+ }
+
+ let body = cx.tcx.hir().body(closure.body);
+ let ex = &body.value;
+ if let ExprKind::Block(block, _) = ex.kind {
+ if !body.value.span.from_expansion() && !block.stmts.is_empty() {
+ span_lint(cx, BLOCKS_IN_IF_CONDITIONS, ex.span, COMPLEX_BLOCK_MESSAGE);
+ return ControlFlow::Continue(Descend::No);
+ }
+ }
+ }
+ ControlFlow::Continue(Descend::Yes)
+ });
}
}
}
diff --git a/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs b/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs
index 95abe8aa5..4bd55c142 100644
--- a/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs
+++ b/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs
@@ -98,9 +98,9 @@ impl<'tcx> LateLintPass<'tcx> for BoolAssertComparison {
cx,
BOOL_ASSERT_COMPARISON,
macro_call.span,
- &format!("used `{}!` with a literal bool", macro_name),
+ &format!("used `{macro_name}!` with a literal bool"),
"replace it with",
- format!("{}!(..)", non_eq_mac),
+ format!("{non_eq_mac}!(..)"),
Applicability::MaybeIncorrect,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/bool_to_int_with_if.rs b/src/tools/clippy/clippy_lints/src/bool_to_int_with_if.rs
index a4b8cbb0d..001d74c26 100644
--- a/src/tools/clippy/clippy_lints/src/bool_to_int_with_if.rs
+++ b/src/tools/clippy/clippy_lints/src/bool_to_int_with_if.rs
@@ -1,9 +1,9 @@
-use rustc_ast::{ExprPrecedence, LitKind};
+use rustc_ast::LitKind;
use rustc_hir::{Block, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
-use clippy_utils::{diagnostics::span_lint_and_then, is_else_clause, source::snippet_block_with_applicability};
+use clippy_utils::{diagnostics::span_lint_and_then, is_else_clause, is_integer_literal, sugg::Sugg};
use rustc_errors::Applicability;
declare_clippy_lint! {
@@ -55,27 +55,38 @@ fn check_if_else<'tcx>(ctx: &LateContext<'tcx>, expr: &'tcx rustc_hir::Expr<'tcx
if let ExprKind::If(check, then, Some(else_)) = expr.kind
&& let Some(then_lit) = int_literal(then)
&& let Some(else_lit) = int_literal(else_)
- && check_int_literal_equals_val(then_lit, 1)
- && check_int_literal_equals_val(else_lit, 0)
{
+ let inverted = if is_integer_literal(then_lit, 1) && is_integer_literal(else_lit, 0) {
+ false
+ } else if is_integer_literal(then_lit, 0) && is_integer_literal(else_lit, 1) {
+ true
+ } else {
+ // Expression isn't boolean, exit
+ return;
+ };
let mut applicability = Applicability::MachineApplicable;
- let snippet = snippet_block_with_applicability(ctx, check.span, "..", None, &mut applicability);
- let snippet_with_braces = {
- let need_parens = should_have_parentheses(check);
- let (left_paren, right_paren) = if need_parens {("(", ")")} else {("", "")};
- format!("{left_paren}{snippet}{right_paren}")
+ let snippet = {
+ let mut sugg = Sugg::hir_with_applicability(ctx, check, "..", &mut applicability);
+ if inverted {
+ sugg = !sugg;
+ }
+ sugg
};
let ty = ctx.typeck_results().expr_ty(then_lit); // then and else must be of same type
let suggestion = {
let wrap_in_curly = is_else_clause(ctx.tcx, expr);
- let (left_curly, right_curly) = if wrap_in_curly {("{", "}")} else {("", "")};
- format!(
- "{left_curly}{ty}::from({snippet}){right_curly}"
- )
+ let mut s = Sugg::NonParen(format!("{ty}::from({snippet})").into());
+ if wrap_in_curly {
+ s = s.blockify();
+ }
+ s
}; // when used in else clause if statement should be wrapped in curly braces
+ let into_snippet = snippet.clone().maybe_par();
+ let as_snippet = snippet.as_ty(ty);
+
span_lint_and_then(ctx,
BOOL_TO_INT_WITH_IF,
expr.span,
@@ -87,7 +98,7 @@ fn check_if_else<'tcx>(ctx: &LateContext<'tcx>, expr: &'tcx rustc_hir::Expr<'tcx
suggestion,
applicability,
);
- diag.note(format!("`{snippet_with_braces} as {ty}` or `{snippet_with_braces}.into()` can also be valid options"));
+ diag.note(format!("`{as_snippet}` or `{into_snippet}.into()` can also be valid options"));
});
};
}
@@ -108,18 +119,3 @@ fn int_literal<'tcx>(expr: &'tcx rustc_hir::Expr<'tcx>) -> Option<&'tcx rustc_hi
None
}
}
-
-fn check_int_literal_equals_val<'tcx>(expr: &'tcx rustc_hir::Expr<'tcx>, expected_value: u128) -> bool {
- if let ExprKind::Lit(lit) = &expr.kind
- && let LitKind::Int(val, _) = lit.node
- && val == expected_value
- {
- true
- } else {
- false
- }
-}
-
-fn should_have_parentheses<'tcx>(check: &'tcx rustc_hir::Expr<'tcx>) -> bool {
- check.precedence().order() < ExprPrecedence::Cast.order()
-}
diff --git a/src/tools/clippy/clippy_lints/src/booleans.rs b/src/tools/clippy/clippy_lints/src/booleans.rs
index 656d639f0..08164c0b6 100644
--- a/src/tools/clippy/clippy_lints/src/booleans.rs
+++ b/src/tools/clippy/clippy_lints/src/booleans.rs
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
+use clippy_utils::eq_expr_value;
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
-use clippy_utils::{eq_expr_value, get_trait_def_id, paths};
use if_chain::if_chain;
use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
@@ -237,7 +237,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
}
},
&Term(n) => {
- let snip = snippet_opt(self.cx, self.terminals[n as usize].span)?;
+ let snip = snippet_opt(self.cx, self.terminals[n as usize].span.source_callsite())?;
self.output.push_str(&snip);
},
}
@@ -263,9 +263,8 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
}
.and_then(|op| {
Some(format!(
- "{}{}{}",
+ "{}{op}{}",
snippet_opt(cx, lhs.span)?,
- op,
snippet_opt(cx, rhs.span)?
))
})
@@ -285,7 +284,7 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
let path: &str = path.ident.name.as_str();
a == path
})
- .and_then(|(_, neg_method)| Some(format!("{}.{}()", snippet_opt(cx, receiver.span)?, neg_method)))
+ .and_then(|(_, neg_method)| Some(format!("{}.{neg_method}()", snippet_opt(cx, receiver.span)?)))
},
_ => None,
}
@@ -484,7 +483,9 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
fn implements_ord<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool {
let ty = cx.typeck_results().expr_ty(expr);
- get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]))
+ cx.tcx
+ .get_diagnostic_item(sym::Ord)
+ .map_or(false, |id| implements_trait(cx, ty, id, &[]))
}
struct NotSimplificationVisitor<'a, 'tcx> {
diff --git a/src/tools/clippy/clippy_lints/src/box_default.rs b/src/tools/clippy/clippy_lints/src/box_default.rs
new file mode 100644
index 000000000..36daceabe
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/box_default.rs
@@ -0,0 +1,129 @@
+use clippy_utils::{
+ diagnostics::span_lint_and_sugg, get_parent_node, is_default_equivalent, macros::macro_backtrace, match_path,
+ path_def_id, paths, ty::expr_sig,
+};
+use rustc_errors::Applicability;
+use rustc_hir::{
+ intravisit::{walk_ty, Visitor},
+ Block, Expr, ExprKind, Local, Node, QPath, TyKind,
+};
+use rustc_lint::{LateContext, LateLintPass, LintContext};
+use rustc_middle::lint::in_external_macro;
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::sym;
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// checks for `Box::new(T::default())`, which is better written as
+ /// `Box::<T>::default()`.
+ ///
+ /// ### Why is this bad?
+ /// First, it's more complex, involving two calls instead of one.
+ /// Second, `Box::default()` can be faster
+ /// [in certain cases](https://nnethercote.github.io/perf-book/standard-library-types.html#box).
+ ///
+ /// ### Example
+ /// ```rust
+ /// let x: Box<String> = Box::new(Default::default());
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// let x: Box<String> = Box::default();
+ /// ```
+ #[clippy::version = "1.65.0"]
+ pub BOX_DEFAULT,
+ perf,
+ "Using Box::new(T::default()) instead of Box::default()"
+}
+
+declare_lint_pass!(BoxDefault => [BOX_DEFAULT]);
+
+impl LateLintPass<'_> for BoxDefault {
+ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
+ if let ExprKind::Call(box_new, [arg]) = expr.kind
+ && let ExprKind::Path(QPath::TypeRelative(ty, seg)) = box_new.kind
+ && let ExprKind::Call(arg_path, ..) = arg.kind
+ && !in_external_macro(cx.sess(), expr.span)
+ && (expr.span.eq_ctxt(arg.span) || is_vec_expn(cx, arg))
+ && seg.ident.name == sym::new
+ && path_def_id(cx, ty).map_or(false, |id| Some(id) == cx.tcx.lang_items().owned_box())
+ && is_default_equivalent(cx, arg)
+ {
+ let arg_ty = cx.typeck_results().expr_ty(arg);
+ span_lint_and_sugg(
+ cx,
+ BOX_DEFAULT,
+ expr.span,
+ "`Box::new(_)` of default value",
+ "try",
+ if is_plain_default(arg_path) || given_type(cx, expr) {
+ "Box::default()".into()
+ } else {
+ format!("Box::<{arg_ty}>::default()")
+ },
+ Applicability::MachineApplicable
+ );
+ }
+ }
+}
+
+fn is_plain_default(arg_path: &Expr<'_>) -> bool {
+ // we need to match the actual path so we don't match e.g. "u8::default"
+ if let ExprKind::Path(QPath::Resolved(None, path)) = &arg_path.kind {
+ // avoid generic parameters
+ match_path(path, &paths::DEFAULT_TRAIT_METHOD) && path.segments.iter().all(|seg| seg.args.is_none())
+ } else {
+ false
+ }
+}
+
+fn is_vec_expn(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
+ macro_backtrace(expr.span)
+ .next()
+ .map_or(false, |call| cx.tcx.is_diagnostic_item(sym::vec_macro, call.def_id))
+}
+
+#[derive(Default)]
+struct InferVisitor(bool);
+
+impl<'tcx> Visitor<'tcx> for InferVisitor {
+ fn visit_ty(&mut self, t: &rustc_hir::Ty<'_>) {
+ self.0 |= matches!(t.kind, TyKind::Infer | TyKind::OpaqueDef(..) | TyKind::TraitObject(..));
+ if !self.0 {
+ walk_ty(self, t);
+ }
+ }
+}
+
+fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
+ match get_parent_node(cx.tcx, expr.hir_id) {
+ Some(Node::Local(Local { ty: Some(ty), .. })) => {
+ let mut v = InferVisitor::default();
+ v.visit_ty(ty);
+ !v.0
+ },
+ Some(
+ Node::Expr(Expr {
+ kind: ExprKind::Call(path, args),
+ ..
+ }) | Node::Block(Block {
+ expr:
+ Some(Expr {
+ kind: ExprKind::Call(path, args),
+ ..
+ }),
+ ..
+ }),
+ ) => {
+ if let Some(index) = args.iter().position(|arg| arg.hir_id == expr.hir_id) &&
+ let Some(sig) = expr_sig(cx, path) &&
+ let Some(input) = sig.input(index)
+ {
+ input.no_bound_vars().is_some()
+ } else {
+ false
+ }
+ },
+ _ => false,
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/cargo/common_metadata.rs b/src/tools/clippy/clippy_lints/src/cargo/common_metadata.rs
index e0442dda4..805121bcc 100644
--- a/src/tools/clippy/clippy_lints/src/cargo/common_metadata.rs
+++ b/src/tools/clippy/clippy_lints/src/cargo/common_metadata.rs
@@ -40,7 +40,7 @@ pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata, ignore_publish: b
}
fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, field: &str) {
- let message = format!("package `{}` is missing `{}` metadata", package.name, field);
+ let message = format!("package `{}` is missing `{field}` metadata", package.name);
span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, &message);
}
diff --git a/src/tools/clippy/clippy_lints/src/cargo/feature_name.rs b/src/tools/clippy/clippy_lints/src/cargo/feature_name.rs
index 79a469a42..37c169dbd 100644
--- a/src/tools/clippy/clippy_lints/src/cargo/feature_name.rs
+++ b/src/tools/clippy/clippy_lints/src/cargo/feature_name.rs
@@ -57,10 +57,8 @@ fn lint(cx: &LateContext<'_>, feature: &str, substring: &str, is_prefix: bool) {
},
DUMMY_SP,
&format!(
- "the \"{}\" {} in the feature name \"{}\" is {}",
- substring,
+ "the \"{substring}\" {} in the feature name \"{feature}\" is {}",
if is_prefix { "prefix" } else { "suffix" },
- feature,
if is_negative { "negative" } else { "redundant" }
),
None,
diff --git a/src/tools/clippy/clippy_lints/src/cargo/mod.rs b/src/tools/clippy/clippy_lints/src/cargo/mod.rs
index 9f45db86a..3a872e54c 100644
--- a/src/tools/clippy/clippy_lints/src/cargo/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/cargo/mod.rs
@@ -196,7 +196,7 @@ impl LateLintPass<'_> for Cargo {
},
Err(e) => {
for lint in NO_DEPS_LINTS {
- span_lint(cx, lint, DUMMY_SP, &format!("could not read cargo metadata: {}", e));
+ span_lint(cx, lint, DUMMY_SP, &format!("could not read cargo metadata: {e}"));
}
},
}
@@ -212,7 +212,7 @@ impl LateLintPass<'_> for Cargo {
},
Err(e) => {
for lint in WITH_DEPS_LINTS {
- span_lint(cx, lint, DUMMY_SP, &format!("could not read cargo metadata: {}", e));
+ span_lint(cx, lint, DUMMY_SP, &format!("could not read cargo metadata: {e}"));
}
},
}
diff --git a/src/tools/clippy/clippy_lints/src/cargo/multiple_crate_versions.rs b/src/tools/clippy/clippy_lints/src/cargo/multiple_crate_versions.rs
index 76fd0819a..f9b17d45e 100644
--- a/src/tools/clippy/clippy_lints/src/cargo/multiple_crate_versions.rs
+++ b/src/tools/clippy/clippy_lints/src/cargo/multiple_crate_versions.rs
@@ -37,7 +37,7 @@ pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata) {
cx,
MULTIPLE_CRATE_VERSIONS,
DUMMY_SP,
- &format!("multiple versions for dependency `{}`: {}", name, versions),
+ &format!("multiple versions for dependency `{name}`: {versions}"),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/casts/as_ptr_cast_mut.rs b/src/tools/clippy/clippy_lints/src/casts/as_ptr_cast_mut.rs
new file mode 100644
index 000000000..9409f4844
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/casts/as_ptr_cast_mut.rs
@@ -0,0 +1,38 @@
+use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::source::snippet_opt;
+use rustc_errors::Applicability;
+use rustc_hir::{Expr, ExprKind};
+use rustc_lint::LateContext;
+use rustc_middle::{
+ mir::Mutability,
+ ty::{self, Ty, TypeAndMut},
+};
+
+use super::AS_PTR_CAST_MUT;
+
+pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>) {
+ if let ty::RawPtr(ptrty @ TypeAndMut { mutbl: Mutability::Mut, .. }) = cast_to.kind()
+ && let ty::RawPtr(TypeAndMut { mutbl: Mutability::Not, .. }) =
+ cx.typeck_results().node_type(cast_expr.hir_id).kind()
+ && let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind
+ && method_name.ident.name == rustc_span::sym::as_ptr
+ && let Some(as_ptr_did) = cx.typeck_results().type_dependent_def_id(cast_expr.peel_blocks().hir_id)
+ && let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did)
+ && let Some(first_param_ty) = as_ptr_sig.skip_binder().inputs().iter().next()
+ && let ty::Ref(_, _, Mutability::Not) = first_param_ty.kind()
+ && let Some(recv) = snippet_opt(cx, receiver.span)
+ {
+ // `as_mut_ptr` might not exist
+ let applicability = Applicability::MaybeIncorrect;
+
+ span_lint_and_sugg(
+ cx,
+ AS_PTR_CAST_MUT,
+ expr.span,
+ &format!("casting the result of `as_ptr` to *{ptrty}"),
+ "replace with",
+ format!("{recv}.as_mut_ptr()"),
+ applicability
+ );
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/casts/borrow_as_ptr.rs b/src/tools/clippy/clippy_lints/src/casts/borrow_as_ptr.rs
index 6e1f8cd64..294d22d34 100644
--- a/src/tools/clippy/clippy_lints/src/casts/borrow_as_ptr.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/borrow_as_ptr.rs
@@ -30,7 +30,7 @@ pub(super) fn check<'tcx>(
expr.span,
"borrow as raw pointer",
"try",
- format!("{}::ptr::{}!({})", core_or_std, macro_name, snip),
+ format!("{core_or_std}::ptr::{macro_name}!({snip})"),
Applicability::MachineApplicable,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_lossless.rs b/src/tools/clippy/clippy_lints/src/casts/cast_lossless.rs
index 938458e30..13c403234 100644
--- a/src/tools/clippy/clippy_lints/src/casts/cast_lossless.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/cast_lossless.rs
@@ -41,15 +41,9 @@ pub(super) fn check(
);
let message = if cast_from.is_bool() {
- format!(
- "casting `{0:}` to `{1:}` is more cleanly stated with `{1:}::from(_)`",
- cast_from, cast_to
- )
+ format!("casting `{cast_from:}` to `{cast_to:}` is more cleanly stated with `{cast_to:}::from(_)`")
} else {
- format!(
- "casting `{}` to `{}` may become silently lossy if you later change the type",
- cast_from, cast_to
- )
+ format!("casting `{cast_from}` to `{cast_to}` may become silently lossy if you later change the type")
};
span_lint_and_sugg(
@@ -58,7 +52,7 @@ pub(super) fn check(
expr.span,
&message,
"try",
- format!("{}::from({})", cast_to, sugg),
+ format!("{cast_to}::from({sugg})"),
applicability,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_nan_to_int.rs b/src/tools/clippy/clippy_lints/src/casts/cast_nan_to_int.rs
new file mode 100644
index 000000000..322dc41b3
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/casts/cast_nan_to_int.rs
@@ -0,0 +1,28 @@
+use super::CAST_NAN_TO_INT;
+
+use clippy_utils::consts::{constant, Constant};
+use clippy_utils::diagnostics::span_lint_and_note;
+use rustc_hir::Expr;
+use rustc_lint::LateContext;
+use rustc_middle::ty::Ty;
+
+pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, from_ty: Ty<'_>, to_ty: Ty<'_>) {
+ if from_ty.is_floating_point() && to_ty.is_integral() && is_known_nan(cx, cast_expr) {
+ span_lint_and_note(
+ cx,
+ CAST_NAN_TO_INT,
+ expr.span,
+ &format!("casting a known NaN to {to_ty}"),
+ None,
+ "this always evaluates to 0",
+ );
+ }
+}
+
+fn is_known_nan(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
+ match constant(cx, cx.typeck_results(), e) {
+ Some((Constant::F64(n), _)) => n.is_nan(),
+ Some((Constant::F32(n), _)) => n.is_nan(),
+ _ => false,
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs b/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs
index 406547a44..88deb4565 100644
--- a/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs
@@ -103,10 +103,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
return;
}
- format!(
- "casting `{}` to `{}` may truncate the value{}",
- cast_from, cast_to, suffix,
- )
+ format!("casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}",)
},
(ty::Adt(def, _), true) if def.is_enum() => {
@@ -142,20 +139,17 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
CAST_ENUM_TRUNCATION,
expr.span,
&format!(
- "casting `{}::{}` to `{}` will truncate the value{}",
- cast_from, variant.name, cast_to, suffix,
+ "casting `{cast_from}::{}` to `{cast_to}` will truncate the value{suffix}",
+ variant.name,
),
);
return;
}
- format!(
- "casting `{}` to `{}` may truncate the value{}",
- cast_from, cast_to, suffix,
- )
+ format!("casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}",)
},
(ty::Float(_), true) => {
- format!("casting `{}` to `{}` may truncate the value", cast_from, cast_to)
+ format!("casting `{cast_from}` to `{cast_to}` may truncate the value")
},
(ty::Float(FloatTy::F64), false) if matches!(cast_to.kind(), &ty::Float(FloatTy::F32)) => {
diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_possible_wrap.rs b/src/tools/clippy/clippy_lints/src/casts/cast_possible_wrap.rs
index 2c5c1d7cb..28ecdea7e 100644
--- a/src/tools/clippy/clippy_lints/src/casts/cast_possible_wrap.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/cast_possible_wrap.rs
@@ -35,10 +35,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, ca
cx,
CAST_POSSIBLE_WRAP,
expr.span,
- &format!(
- "casting `{}` to `{}` may wrap around the value{}",
- cast_from, cast_to, suffix,
- ),
+ &format!("casting `{cast_from}` to `{cast_to}` may wrap around the value{suffix}",),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs b/src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs
index da7b12f67..97054a0d1 100644
--- a/src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs
@@ -49,9 +49,7 @@ fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_f
CAST_PTR_ALIGNMENT,
expr.span,
&format!(
- "casting from `{}` to a more-strictly-aligned pointer (`{}`) ({} < {} bytes)",
- cast_from,
- cast_to,
+ "casting from `{cast_from}` to a more-strictly-aligned pointer (`{cast_to}`) ({} < {} bytes)",
from_layout.align.abi.bytes(),
to_layout.align.abi.bytes(),
),
diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs b/src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs
index 5b59350be..a20a97d4e 100644
--- a/src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs
@@ -14,10 +14,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_op: &Expr<'_>, c
cx,
CAST_SIGN_LOSS,
expr.span,
- &format!(
- "casting `{}` to `{}` may lose the sign of the value",
- cast_from, cast_to
- ),
+ &format!("casting `{cast_from}` to `{cast_to}` may lose the sign of the value"),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_slice_different_sizes.rs b/src/tools/clippy/clippy_lints/src/casts/cast_slice_different_sizes.rs
index 027c660ce..d31d10d22 100644
--- a/src/tools/clippy/clippy_lints/src/casts/cast_slice_different_sizes.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/cast_slice_different_sizes.rs
@@ -35,8 +35,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: Optio
CAST_SLICE_DIFFERENT_SIZES,
expr.span,
&format!(
- "casting between raw pointers to `[{}]` (element size {}) and `[{}]` (element size {}) does not adjust the count",
- start_ty.ty, from_size, end_ty.ty, to_size,
+ "casting between raw pointers to `[{}]` (element size {from_size}) and `[{}]` (element size {to_size}) does not adjust the count",
+ start_ty.ty, end_ty.ty,
),
|diag| {
let ptr_snippet = source::snippet(cx, left_cast.span, "..");
diff --git a/src/tools/clippy/clippy_lints/src/casts/char_lit_as_u8.rs b/src/tools/clippy/clippy_lints/src/casts/char_lit_as_u8.rs
index 7cc406018..82e07c98a 100644
--- a/src/tools/clippy/clippy_lints/src/casts/char_lit_as_u8.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/char_lit_as_u8.rs
@@ -31,7 +31,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
diag.span_suggestion(
expr.span,
"use a byte literal instead",
- format!("b{}", snippet),
+ format!("b{snippet}"),
applicability,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast.rs b/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast.rs
index 35350d8a2..a26bfab4e 100644
--- a/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast.rs
@@ -25,9 +25,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
cx,
FN_TO_NUMERIC_CAST,
expr.span,
- &format!("casting function pointer `{}` to `{}`", from_snippet, cast_to),
+ &format!("casting function pointer `{from_snippet}` to `{cast_to}`"),
"try",
- format!("{} as usize", from_snippet),
+ format!("{from_snippet} as usize"),
applicability,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast_any.rs b/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast_any.rs
index 03621887a..756541294 100644
--- a/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast_any.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast_any.rs
@@ -23,9 +23,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
cx,
FN_TO_NUMERIC_CAST_ANY,
expr.span,
- &format!("casting function pointer `{}` to `{}`", from_snippet, cast_to),
+ &format!("casting function pointer `{from_snippet}` to `{cast_to}`"),
"did you mean to invoke the function?",
- format!("{}() as {}", from_snippet, cast_to),
+ format!("{from_snippet}() as {cast_to}"),
applicability,
);
},
diff --git a/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs b/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs
index 6287f479b..556be1d15 100644
--- a/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast_with_truncation.rs
@@ -24,12 +24,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
cx,
FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
expr.span,
- &format!(
- "casting function pointer `{}` to `{}`, which truncates the value",
- from_snippet, cast_to
- ),
+ &format!("casting function pointer `{from_snippet}` to `{cast_to}`, which truncates the value"),
"try",
- format!("{} as usize", from_snippet),
+ format!("{from_snippet} as usize"),
applicability,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/casts/mod.rs b/src/tools/clippy/clippy_lints/src/casts/mod.rs
index cc5d346b9..b72c4c772 100644
--- a/src/tools/clippy/clippy_lints/src/casts/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/mod.rs
@@ -1,8 +1,10 @@
+mod as_ptr_cast_mut;
mod as_underscore;
mod borrow_as_ptr;
mod cast_abs_to_unsigned;
mod cast_enum_constructor;
mod cast_lossless;
+mod cast_nan_to_int;
mod cast_possible_truncation;
mod cast_possible_wrap;
mod cast_precision_loss;
@@ -569,6 +571,7 @@ declare_clippy_lint! {
pedantic,
"borrowing just to cast to a raw pointer"
}
+
declare_clippy_lint! {
/// ### What it does
/// Checks for a raw slice being cast to a slice pointer
@@ -596,6 +599,54 @@ declare_clippy_lint! {
"casting a slice created from a pointer and length to a slice pointer"
}
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for the result of a `&self`-taking `as_ptr` being cast to a mutable pointer
+ ///
+ /// ### Why is this bad?
+ /// Since `as_ptr` takes a `&self`, the pointer won't have write permissions unless interior
+ /// mutability is used, making it unlikely that having it as a mutable pointer is correct.
+ ///
+ /// ### Example
+ /// ```rust
+ /// let string = String::with_capacity(1);
+ /// let ptr = string.as_ptr() as *mut u8;
+ /// unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// let mut string = String::with_capacity(1);
+ /// let ptr = string.as_mut_ptr();
+ /// unsafe { ptr.write(4) };
+ /// ```
+ #[clippy::version = "1.66.0"]
+ pub AS_PTR_CAST_MUT,
+ nursery,
+ "casting the result of the `&self`-taking `as_ptr` to a mutabe pointer"
+}
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for a known NaN float being cast to an integer
+ ///
+ /// ### Why is this bad?
+ /// NaNs are cast into zero, so one could simply use this and make the
+ /// code more readable. The lint could also hint at a programmer error.
+ ///
+ /// ### Example
+ /// ```rust,ignore
+ /// let _: (0.0_f32 / 0.0) as u64;
+ /// ```
+ /// Use instead:
+ /// ```rust,ignore
+ /// let _: = 0_u64;
+ /// ```
+ #[clippy::version = "1.64.0"]
+ pub CAST_NAN_TO_INT,
+ suspicious,
+ "casting a known floating-point NaN into an integer"
+}
+
pub struct Casts {
msrv: Option<RustcVersion>,
}
@@ -627,7 +678,9 @@ impl_lint_pass!(Casts => [
CAST_ABS_TO_UNSIGNED,
AS_UNDERSCORE,
BORROW_AS_PTR,
- CAST_SLICE_FROM_RAW_PARTS
+ CAST_SLICE_FROM_RAW_PARTS,
+ AS_PTR_CAST_MUT,
+ CAST_NAN_TO_INT,
]);
impl<'tcx> LateLintPass<'tcx> for Casts {
@@ -653,6 +706,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
return;
}
cast_slice_from_raw_parts::check(cx, expr, cast_expr, cast_to, self.msrv);
+ as_ptr_cast_mut::check(cx, expr, cast_expr, cast_to);
fn_to_numeric_cast_any::check(cx, expr, cast_expr, cast_from, cast_to);
fn_to_numeric_cast::check(cx, expr, cast_expr, cast_from, cast_to);
fn_to_numeric_cast_with_truncation::check(cx, expr, cast_expr, cast_from, cast_to);
@@ -664,6 +718,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
cast_precision_loss::check(cx, expr, cast_from, cast_to);
cast_sign_loss::check(cx, expr, cast_expr, cast_from, cast_to);
cast_abs_to_unsigned::check(cx, expr, cast_expr, cast_from, cast_to, self.msrv);
+ cast_nan_to_int::check(cx, expr, cast_expr, cast_from, cast_to);
}
cast_lossless::check(cx, expr, cast_expr, cast_from, cast_to, self.msrv);
cast_enum_constructor::check(cx, expr, cast_expr, cast_from);
diff --git a/src/tools/clippy/clippy_lints/src/casts/ptr_as_ptr.rs b/src/tools/clippy/clippy_lints/src/casts/ptr_as_ptr.rs
index 46d45d096..b9509ca65 100644
--- a/src/tools/clippy/clippy_lints/src/casts/ptr_as_ptr.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/ptr_as_ptr.rs
@@ -26,14 +26,14 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Option<RustcVer
(Mutability::Not, Mutability::Not) | (Mutability::Mut, Mutability::Mut));
// The `U` in `pointer::cast` have to be `Sized`
// as explained here: https://github.com/rust-lang/rust/issues/60602.
- if to_pointee_ty.is_sized(cx.tcx.at(expr.span), cx.param_env);
+ if to_pointee_ty.is_sized(cx.tcx, cx.param_env);
then {
let mut applicability = Applicability::MachineApplicable;
let cast_expr_sugg = Sugg::hir_with_applicability(cx, cast_expr, "_", &mut applicability);
let turbofish = match &cast_to_hir_ty.kind {
TyKind::Infer => Cow::Borrowed(""),
TyKind::Ptr(mut_ty) if matches!(mut_ty.ty.kind, TyKind::Infer) => Cow::Borrowed(""),
- _ => Cow::Owned(format!("::<{}>", to_pointee_ty)),
+ _ => Cow::Owned(format!("::<{to_pointee_ty}>")),
};
span_lint_and_sugg(
cx,
@@ -41,7 +41,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Option<RustcVer
expr.span,
"`as` casting between raw pointers without changing its mutability",
"try `pointer::cast`, a safer alternative",
- format!("{}.cast{}()", cast_expr_sugg.maybe_par(), turbofish),
+ format!("{}.cast{turbofish}()", cast_expr_sugg.maybe_par()),
applicability,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs b/src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs
index 19d2e6e1d..c8596987e 100644
--- a/src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs
+++ b/src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs
@@ -1,4 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::get_parent_expr;
use clippy_utils::numeric_literal::NumericLiteral;
use clippy_utils::source::snippet_opt;
use if_chain::if_chain;
@@ -30,8 +31,10 @@ pub(super) fn check<'tcx>(
}
}
+ let cast_str = snippet_opt(cx, cast_expr.span).unwrap_or_default();
+
if let Some(lit) = get_numeric_literal(cast_expr) {
- let literal_str = snippet_opt(cx, cast_expr.span).unwrap_or_default();
+ let literal_str = &cast_str;
if_chain! {
if let LitKind::Int(n, _) = lit.node;
@@ -49,12 +52,13 @@ pub(super) fn check<'tcx>(
match lit.node {
LitKind::Int(_, LitIntType::Unsuffixed) if cast_to.is_integral() => {
- lint_unnecessary_cast(cx, expr, &literal_str, cast_from, cast_to);
+ lint_unnecessary_cast(cx, expr, literal_str, cast_from, cast_to);
+ return false;
},
LitKind::Float(_, LitFloatType::Unsuffixed) if cast_to.is_floating_point() => {
- lint_unnecessary_cast(cx, expr, &literal_str, cast_from, cast_to);
+ lint_unnecessary_cast(cx, expr, literal_str, cast_from, cast_to);
+ return false;
},
- LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed) => {},
LitKind::Int(_, LitIntType::Signed(_) | LitIntType::Unsigned(_))
| LitKind::Float(_, LitFloatType::Suffixed(_))
if cast_from.kind() == cast_to.kind() =>
@@ -62,48 +66,62 @@ pub(super) fn check<'tcx>(
if let Some(src) = snippet_opt(cx, cast_expr.span) {
if let Some(num_lit) = NumericLiteral::from_lit_kind(&src, &lit.node) {
lint_unnecessary_cast(cx, expr, num_lit.integer, cast_from, cast_to);
+ return true;
}
}
},
- _ => {
- if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) {
- span_lint_and_sugg(
- cx,
- UNNECESSARY_CAST,
- expr.span,
- &format!(
- "casting to the same type is unnecessary (`{}` -> `{}`)",
- cast_from, cast_to
- ),
- "try",
- literal_str,
- Applicability::MachineApplicable,
- );
- return true;
- }
- },
+ _ => {},
}
}
+ if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) {
+ span_lint_and_sugg(
+ cx,
+ UNNECESSARY_CAST,
+ expr.span,
+ &format!("casting to the same type is unnecessary (`{cast_from}` -> `{cast_to}`)"),
+ "try",
+ cast_str,
+ Applicability::MachineApplicable,
+ );
+ return true;
+ }
+
false
}
-fn lint_unnecessary_cast(cx: &LateContext<'_>, expr: &Expr<'_>, literal_str: &str, cast_from: Ty<'_>, cast_to: Ty<'_>) {
+fn lint_unnecessary_cast(
+ cx: &LateContext<'_>,
+ expr: &Expr<'_>,
+ raw_literal_str: &str,
+ cast_from: Ty<'_>,
+ cast_to: Ty<'_>,
+) {
let literal_kind_name = if cast_from.is_integral() { "integer" } else { "float" };
- let replaced_literal;
- let matchless = if literal_str.contains(['(', ')']) {
- replaced_literal = literal_str.replace(['(', ')'], "");
- &replaced_literal
- } else {
- literal_str
+ // first we remove all matches so `-(1)` become `-1`, and remove trailing dots, so `1.` become `1`
+ let literal_str = raw_literal_str
+ .replace(['(', ')'], "")
+ .trim_end_matches('.')
+ .to_string();
+ // we know need to check if the parent is a method call, to add parenthesis accordingly (eg:
+ // (-1).foo() instead of -1.foo())
+ let sugg = if let Some(parent_expr) = get_parent_expr(cx, expr)
+ && let ExprKind::MethodCall(..) = parent_expr.kind
+ && literal_str.starts_with('-')
+ {
+ format!("({literal_str}_{cast_to})")
+
+ } else {
+ format!("{literal_str}_{cast_to}")
};
+
span_lint_and_sugg(
cx,
UNNECESSARY_CAST,
expr.span,
- &format!("casting {} literal to `{}` is unnecessary", literal_kind_name, cast_to),
+ &format!("casting {literal_kind_name} literal to `{cast_to}` is unnecessary"),
"try",
- format!("{}_{}", matchless.trim_end_matches('.'), cast_to),
+ sugg,
Applicability::MachineApplicable,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/checked_conversions.rs b/src/tools/clippy/clippy_lints/src/checked_conversions.rs
index 37b2fdcff..78e9921f0 100644
--- a/src/tools/clippy/clippy_lints/src/checked_conversions.rs
+++ b/src/tools/clippy/clippy_lints/src/checked_conversions.rs
@@ -2,9 +2,8 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
-use clippy_utils::{in_constant, meets_msrv, msrvs, SpanlessEq};
+use clippy_utils::{in_constant, is_integer_literal, meets_msrv, msrvs, SpanlessEq};
use if_chain::if_chain;
-use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
use rustc_hir::{BinOp, BinOpKind, Expr, ExprKind, QPath, TyKind};
use rustc_lint::{LateContext, LateLintPass, LintContext};
@@ -82,7 +81,7 @@ impl<'tcx> LateLintPass<'tcx> for CheckedConversions {
item.span,
"checked cast can be simplified",
"try",
- format!("{}::try_from({}).is_ok()", to_type, snippet),
+ format!("{to_type}::try_from({snippet}).is_ok()"),
applicability,
);
}
@@ -223,16 +222,7 @@ fn check_lower_bound<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<Conversion<'tcx>> {
/// Check for `expr >= 0`
fn check_lower_bound_zero<'a>(candidate: &'a Expr<'_>, check: &'a Expr<'_>) -> Option<Conversion<'a>> {
- if_chain! {
- if let ExprKind::Lit(ref lit) = &check.kind;
- if let LitKind::Int(0, _) = &lit.node;
-
- then {
- Some(Conversion::new_any(candidate))
- } else {
- None
- }
- }
+ is_integer_literal(check, 0).then(|| Conversion::new_any(candidate))
}
/// Check for `expr >= (to_type::MIN as from_type)`
diff --git a/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs b/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs
index 33c44f8b2..77af3b53d 100644
--- a/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs
+++ b/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs
@@ -3,10 +3,12 @@
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::is_type_diagnostic_item;
+use clippy_utils::visitors::for_each_expr;
use clippy_utils::LimitStack;
+use core::ops::ControlFlow;
use rustc_ast::ast::Attribute;
-use rustc_hir::intravisit::{walk_expr, FnKind, Visitor};
-use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId};
+use rustc_hir::intravisit::FnKind;
+use rustc_hir::{Body, ExprKind, FnDecl, HirId};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::source_map::Span;
@@ -61,11 +63,27 @@ impl CognitiveComplexity {
return;
}
- let expr = &body.value;
+ let expr = body.value;
+
+ let mut cc = 1u64;
+ let mut returns = 0u64;
+ let _: Option<!> = for_each_expr(expr, |e| {
+ match e.kind {
+ ExprKind::If(_, _, _) => {
+ cc += 1;
+ },
+ ExprKind::Match(_, arms, _) => {
+ if arms.len() > 1 {
+ cc += 1;
+ }
+ cc += arms.iter().filter(|arm| arm.guard.is_some()).count() as u64;
+ },
+ ExprKind::Ret(_) => returns += 1,
+ _ => {},
+ }
+ ControlFlow::Continue(())
+ });
- let mut helper = CcHelper { cc: 1, returns: 0 };
- helper.visit_expr(expr);
- let CcHelper { cc, returns } = helper;
let ret_ty = cx.typeck_results().node_type(expr.hir_id);
let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym::Result) {
returns
@@ -74,13 +92,12 @@ impl CognitiveComplexity {
(returns / 2)
};
- let mut rust_cc = cc;
// prevent degenerate cases where unreachable code contains `return` statements
- if rust_cc >= ret_adjust {
- rust_cc -= ret_adjust;
+ if cc >= ret_adjust {
+ cc -= ret_adjust;
}
- if rust_cc > self.limit.limit() {
+ if cc > self.limit.limit() {
let fn_span = match kind {
FnKind::ItemFn(ident, _, _) | FnKind::Method(ident, _) => ident.span,
FnKind::Closure => {
@@ -107,8 +124,7 @@ impl CognitiveComplexity {
COGNITIVE_COMPLEXITY,
fn_span,
&format!(
- "the function has a cognitive complexity of ({}/{})",
- rust_cc,
+ "the function has a cognitive complexity of ({cc}/{})",
self.limit.limit()
),
None,
@@ -141,27 +157,3 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity {
self.limit.pop_attrs(cx.sess(), attrs, "cognitive_complexity");
}
}
-
-struct CcHelper {
- cc: u64,
- returns: u64,
-}
-
-impl<'tcx> Visitor<'tcx> for CcHelper {
- fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
- walk_expr(self, e);
- match e.kind {
- ExprKind::If(_, _, _) => {
- self.cc += 1;
- },
- ExprKind::Match(_, arms, _) => {
- if arms.len() > 1 {
- self.cc += 1;
- }
- self.cc += arms.iter().filter(|arm| arm.guard.is_some()).count() as u64;
- },
- ExprKind::Ret(_) => self.returns += 1,
- _ => {},
- }
- }
-}
diff --git a/src/tools/clippy/clippy_lints/src/comparison_chain.rs b/src/tools/clippy/clippy_lints/src/comparison_chain.rs
index a05b41eb3..0fe973b49 100644
--- a/src/tools/clippy/clippy_lints/src/comparison_chain.rs
+++ b/src/tools/clippy/clippy_lints/src/comparison_chain.rs
@@ -1,9 +1,10 @@
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::ty::implements_trait;
-use clippy_utils::{get_trait_def_id, if_sequence, in_constant, is_else_clause, paths, SpanlessEq};
+use clippy_utils::{if_sequence, in_constant, is_else_clause, SpanlessEq};
use rustc_hir::{BinOpKind, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::sym;
declare_clippy_lint! {
/// ### What it does
@@ -106,7 +107,10 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain {
// Check that the type being compared implements `core::cmp::Ord`
let ty = cx.typeck_results().expr_ty(lhs1);
- let is_ord = get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]));
+ let is_ord = cx
+ .tcx
+ .get_diagnostic_item(sym::Ord)
+ .map_or(false, |id| implements_trait(cx, ty, id, &[]));
if !is_ord {
return;
diff --git a/src/tools/clippy/clippy_lints/src/copy_iterator.rs b/src/tools/clippy/clippy_lints/src/copy_iterator.rs
index 026683f60..e38f77268 100644
--- a/src/tools/clippy/clippy_lints/src/copy_iterator.rs
+++ b/src/tools/clippy/clippy_lints/src/copy_iterator.rs
@@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator {
of_trait: Some(ref trait_ref),
..
}) = item.kind;
- let ty = cx.tcx.type_of(item.def_id);
+ let ty = cx.tcx.type_of(item.owner_id);
if is_copy(cx, ty);
if let Some(trait_id) = trait_ref.trait_def_id();
if cx.tcx.is_diagnostic_item(sym::Iterator, trait_id);
diff --git a/src/tools/clippy/clippy_lints/src/default.rs b/src/tools/clippy/clippy_lints/src/default.rs
index 4e68d6810..7f937de1d 100644
--- a/src/tools/clippy/clippy_lints/src/default.rs
+++ b/src/tools/clippy/clippy_lints/src/default.rs
@@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
cx,
DEFAULT_TRAIT_ACCESS,
expr.span,
- &format!("calling `{}` is more clear than this expression", replacement),
+ &format!("calling `{replacement}` is more clear than this expression"),
"try",
replacement,
Applicability::Unspecified, // First resolve the TODO above
@@ -210,7 +210,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
.map(|(field, rhs)| {
// extract and store the assigned value for help message
let value_snippet = snippet_with_macro_callsite(cx, rhs.span, "..");
- format!("{}: {}", field, value_snippet)
+ format!("{field}: {value_snippet}")
})
.collect::<Vec<String>>()
.join(", ");
@@ -227,7 +227,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(", ");
- format!("{}::<{}>", adt_def_ty_name, &tys_str)
+ format!("{adt_def_ty_name}::<{}>", &tys_str)
} else {
binding_type.to_string()
}
@@ -235,12 +235,12 @@ impl<'tcx> LateLintPass<'tcx> for Default {
let sugg = if ext_with_default {
if field_list.is_empty() {
- format!("{}::default()", binding_type)
+ format!("{binding_type}::default()")
} else {
- format!("{} {{ {}, ..Default::default() }}", binding_type, field_list)
+ format!("{binding_type} {{ {field_list}, ..Default::default() }}")
}
} else {
- format!("{} {{ {} }}", binding_type, field_list)
+ format!("{binding_type} {{ {field_list} }}")
};
// span lint once per statement that binds default
@@ -250,10 +250,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
first_assign.unwrap().span,
"field assignment outside of initializer for an instance created with Default::default()",
Some(local.span),
- &format!(
- "consider initializing the variable with `{}` and removing relevant reassignments",
- sugg
- ),
+ &format!("consider initializing the variable with `{sugg}` and removing relevant reassignments"),
);
self.reassigned_linted.insert(span);
}
diff --git a/src/tools/clippy/clippy_lints/src/default_instead_of_iter_empty.rs b/src/tools/clippy/clippy_lints/src/default_instead_of_iter_empty.rs
index 3c996d3d2..1ad929864 100644
--- a/src/tools/clippy/clippy_lints/src/default_instead_of_iter_empty.rs
+++ b/src/tools/clippy/clippy_lints/src/default_instead_of_iter_empty.rs
@@ -23,7 +23,7 @@ declare_clippy_lint! {
/// let _ = std::iter::empty::<usize>();
/// let iter: std::iter::Empty<usize> = std::iter::empty();
/// ```
- #[clippy::version = "1.63.0"]
+ #[clippy::version = "1.64.0"]
pub DEFAULT_INSTEAD_OF_ITER_EMPTY,
style,
"check `std::iter::Empty::default()` and replace with `std::iter::empty()`"
diff --git a/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs b/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs
index be02f328e..03460689e 100644
--- a/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs
+++ b/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs
@@ -1,12 +1,12 @@
use clippy_utils::diagnostics::span_lint_hir_and_then;
-use clippy_utils::numeric_literal;
use clippy_utils::source::snippet_opt;
+use clippy_utils::{get_parent_node, numeric_literal};
use if_chain::if_chain;
use rustc_ast::ast::{LitFloatType, LitIntType, LitKind};
use rustc_errors::Applicability;
use rustc_hir::{
intravisit::{walk_expr, walk_stmt, Visitor},
- Body, Expr, ExprKind, HirId, Lit, Stmt, StmtKind,
+ Body, Expr, ExprKind, HirId, ItemKind, Lit, Node, Stmt, StmtKind,
};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::{
@@ -55,22 +55,31 @@ declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]);
impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback {
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
- let mut visitor = NumericFallbackVisitor::new(cx);
+ let is_parent_const = if let Some(Node::Item(item)) = get_parent_node(cx.tcx, body.id().hir_id) {
+ matches!(item.kind, ItemKind::Const(..))
+ } else {
+ false
+ };
+ let mut visitor = NumericFallbackVisitor::new(cx, is_parent_const);
visitor.visit_body(body);
}
}
struct NumericFallbackVisitor<'a, 'tcx> {
/// Stack manages type bound of exprs. The top element holds current expr type.
- ty_bounds: Vec<TyBound<'tcx>>,
+ ty_bounds: Vec<ExplicitTyBound>,
cx: &'a LateContext<'tcx>,
}
impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> {
- fn new(cx: &'a LateContext<'tcx>) -> Self {
+ fn new(cx: &'a LateContext<'tcx>, is_parent_const: bool) -> Self {
Self {
- ty_bounds: vec![TyBound::Nothing],
+ ty_bounds: vec![if is_parent_const {
+ ExplicitTyBound(true)
+ } else {
+ ExplicitTyBound(false)
+ }],
cx,
}
}
@@ -79,10 +88,9 @@ impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> {
fn check_lit(&self, lit: &Lit, lit_ty: Ty<'tcx>, emit_hir_id: HirId) {
if_chain! {
if !in_external_macro(self.cx.sess(), lit.span);
- if let Some(ty_bound) = self.ty_bounds.last();
+ if matches!(self.ty_bounds.last(), Some(ExplicitTyBound(false)));
if matches!(lit.node,
LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed));
- if !ty_bound.is_numeric();
then {
let (suffix, is_float) = match lit_ty.kind() {
ty::Int(IntTy::I32) => ("i32", false),
@@ -95,8 +103,8 @@ impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> {
src
} else {
match lit.node {
- LitKind::Int(src, _) => format!("{}", src),
- LitKind::Float(src, _) => format!("{}", src),
+ LitKind::Int(src, _) => format!("{src}"),
+ LitKind::Float(src, _) => format!("{src}"),
_ => return,
}
};
@@ -123,7 +131,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
if let Some(fn_sig) = fn_sig_opt(self.cx, func.hir_id) {
for (expr, bound) in iter::zip(*args, fn_sig.skip_binder().inputs()) {
// Push found arg type, then visit arg.
- self.ty_bounds.push(TyBound::Ty(*bound));
+ self.ty_bounds.push((*bound).into());
self.visit_expr(expr);
self.ty_bounds.pop();
}
@@ -135,7 +143,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) {
let fn_sig = self.cx.tcx.fn_sig(def_id).skip_binder();
for (expr, bound) in iter::zip(std::iter::once(*receiver).chain(args.iter()), fn_sig.inputs()) {
- self.ty_bounds.push(TyBound::Ty(*bound));
+ self.ty_bounds.push((*bound).into());
self.visit_expr(expr);
self.ty_bounds.pop();
}
@@ -169,7 +177,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
// Visit base with no bound.
if let Some(base) = base {
- self.ty_bounds.push(TyBound::Nothing);
+ self.ty_bounds.push(ExplicitTyBound(false));
self.visit_expr(base);
self.ty_bounds.pop();
}
@@ -192,15 +200,10 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) {
match stmt.kind {
- StmtKind::Local(local) => {
- if local.ty.is_some() {
- self.ty_bounds.push(TyBound::Any);
- } else {
- self.ty_bounds.push(TyBound::Nothing);
- }
- },
+ // we cannot check the exact type since it's a hir::Ty which does not implement `is_numeric`
+ StmtKind::Local(local) => self.ty_bounds.push(ExplicitTyBound(local.ty.is_some())),
- _ => self.ty_bounds.push(TyBound::Nothing),
+ _ => self.ty_bounds.push(ExplicitTyBound(false)),
}
walk_stmt(self, stmt);
@@ -218,28 +221,18 @@ fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<PolyFnSig<'
}
}
+/// Wrapper around a `bool` to make the meaning of the value clearer
#[derive(Debug, Clone, Copy)]
-enum TyBound<'tcx> {
- Any,
- Ty(Ty<'tcx>),
- Nothing,
-}
+struct ExplicitTyBound(pub bool);
-impl<'tcx> TyBound<'tcx> {
- fn is_numeric(self) -> bool {
- match self {
- TyBound::Any => true,
- TyBound::Ty(t) => t.is_numeric(),
- TyBound::Nothing => false,
- }
+impl<'tcx> From<Ty<'tcx>> for ExplicitTyBound {
+ fn from(v: Ty<'tcx>) -> Self {
+ Self(v.is_numeric())
}
}
-impl<'tcx> From<Option<Ty<'tcx>>> for TyBound<'tcx> {
+impl<'tcx> From<Option<Ty<'tcx>>> for ExplicitTyBound {
fn from(v: Option<Ty<'tcx>>) -> Self {
- match v {
- Some(t) => TyBound::Ty(t),
- None => TyBound::Nothing,
- }
+ Self(v.map_or(false, Ty::is_numeric))
}
}
diff --git a/src/tools/clippy/clippy_lints/src/default_union_representation.rs b/src/tools/clippy/clippy_lints/src/default_union_representation.rs
index d559ad423..dec357ab7 100644
--- a/src/tools/clippy/clippy_lints/src/default_union_representation.rs
+++ b/src/tools/clippy/clippy_lints/src/default_union_representation.rs
@@ -1,10 +1,10 @@
use clippy_utils::diagnostics::span_lint_and_help;
use rustc_hir::{self as hir, HirId, Item, ItemKind};
+use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::layout::LayoutOf;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::sym;
-use rustc_typeck::hir_ty_to_ty;
declare_clippy_lint! {
/// ### What it does
@@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultUnionRepresentation {
None,
&format!(
"consider annotating `{}` with `#[repr(C)]` to explicitly specify memory layout",
- cx.tcx.def_path_str(item.def_id.to_def_id())
+ cx.tcx.def_path_str(item.owner_id.to_def_id())
),
);
}
diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs
index 88e28018e..a37ee82d4 100644
--- a/src/tools/clippy/clippy_lints/src/dereference.rs
+++ b/src/tools/clippy/clippy_lints/src/dereference.rs
@@ -1,4 +1,5 @@
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
+use clippy_utils::mir::{enclosing_mir, expr_local, local_assignments, used_exactly_once, PossibleBorrowerMap};
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
use clippy_utils::sugg::has_enclosing_paren;
use clippy_utils::ty::{expr_sig, is_copy, peel_mid_ty_refs, ty_sig, variant_of_res};
@@ -11,21 +12,24 @@ use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::Applicability;
use rustc_hir::intravisit::{walk_ty, Visitor};
use rustc_hir::{
- self as hir, def_id::DefId, BindingAnnotation, Body, BodyId, BorrowKind, Closure, Expr, ExprKind, FnRetTy,
- GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, Local, MatchSource, Mutability, Node, Pat, PatKind,
- Path, QPath, TraitItem, TraitItemKind, TyKind, UnOp,
+ self as hir,
+ def_id::{DefId, LocalDefId},
+ BindingAnnotation, Body, BodyId, BorrowKind, Closure, Expr, ExprKind, FnRetTy, GenericArg, HirId, ImplItem,
+ ImplItemKind, Item, ItemKind, Local, MatchSource, Mutability, Node, Pat, PatKind, Path, QPath, TraitItem,
+ TraitItemKind, TyKind, UnOp,
};
use rustc_index::bit_set::BitSet;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::mir::{Rvalue, StatementKind};
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
use rustc_middle::ty::{
- self, subst::Subst, Binder, BoundVariableKind, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind,
+ self, Binder, BoundVariableKind, EarlyBinder, FnSig, GenericArgKind, List, ParamTy, PredicateKind,
ProjectionPredicate, Ty, TyCtxt, TypeVisitable, TypeckResults,
};
use rustc_semver::RustcVersion;
use rustc_session::{declare_tool_lint, impl_lint_pass};
-use rustc_span::{symbol::sym, Span, Symbol, DUMMY_SP};
+use rustc_span::{symbol::sym, Span, Symbol};
use rustc_trait_selection::infer::InferCtxtExt as _;
use rustc_trait_selection::traits::{query::evaluate_obligation::InferCtxtExt as _, Obligation, ObligationCause};
use std::collections::VecDeque;
@@ -135,13 +139,13 @@ declare_clippy_lint! {
/// let x = String::new();
/// let y: &str = &x;
/// ```
- #[clippy::version = "1.60.0"]
+ #[clippy::version = "1.64.0"]
pub EXPLICIT_AUTO_DEREF,
complexity,
"dereferencing when the compiler would automatically dereference"
}
-impl_lint_pass!(Dereferencing => [
+impl_lint_pass!(Dereferencing<'_> => [
EXPLICIT_DEREF_METHODS,
NEEDLESS_BORROW,
REF_BINDING_TO_REFERENCE,
@@ -149,7 +153,7 @@ impl_lint_pass!(Dereferencing => [
]);
#[derive(Default)]
-pub struct Dereferencing {
+pub struct Dereferencing<'tcx> {
state: Option<(State, StateData)>,
// While parsing a `deref` method call in ufcs form, the path to the function is itself an
@@ -170,11 +174,16 @@ pub struct Dereferencing {
/// e.g. `m!(x) | Foo::Bar(ref x)`
ref_locals: FxIndexMap<HirId, Option<RefPat>>,
+ /// Stack of (body owner, `PossibleBorrowerMap`) pairs. Used by
+ /// `needless_borrow_impl_arg_position` to determine when a borrowed expression can instead
+ /// be moved.
+ possible_borrowers: Vec<(LocalDefId, PossibleBorrowerMap<'tcx, 'tcx>)>,
+
// `IntoIterator` for arrays requires Rust 1.53.
msrv: Option<RustcVersion>,
}
-impl Dereferencing {
+impl<'tcx> Dereferencing<'tcx> {
#[must_use]
pub fn new(msrv: Option<RustcVersion>) -> Self {
Self {
@@ -184,6 +193,7 @@ impl Dereferencing {
}
}
+#[derive(Debug)]
struct StateData {
/// Span of the top level expression
span: Span,
@@ -191,12 +201,14 @@ struct StateData {
position: Position,
}
+#[derive(Debug)]
struct DerefedBorrow {
count: usize,
msg: &'static str,
snip_expr: Option<HirId>,
}
+#[derive(Debug)]
enum State {
// Any number of deref method calls.
DerefMethod {
@@ -241,7 +253,7 @@ struct RefPat {
hir_id: HirId,
}
-impl<'tcx> LateLintPass<'tcx> for Dereferencing {
+impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
#[expect(clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
// Skip path expressions from deref calls. e.g. `Deref::deref(e)`
@@ -275,11 +287,13 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {
match (self.state.take(), kind) {
(None, kind) => {
let expr_ty = typeck.expr_ty(expr);
- let (position, adjustments) = walk_parents(cx, expr, self.msrv);
-
+ let (position, adjustments) = walk_parents(cx, &mut self.possible_borrowers, expr, self.msrv);
match kind {
RefOp::Deref => {
- if let Position::FieldAccess(name) = position
+ if let Position::FieldAccess {
+ name,
+ of_union: false,
+ } = position
&& !ty_contains_field(typeck.expr_ty(sub_expr), name)
{
self.state = Some((
@@ -297,13 +311,10 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {
if !is_lint_allowed(cx, EXPLICIT_DEREF_METHODS, expr.hir_id)
&& position.lint_explicit_deref() =>
{
+ let ty_changed_count = usize::from(!deref_method_same_type(expr_ty, typeck.expr_ty(sub_expr)));
self.state = Some((
State::DerefMethod {
- ty_changed_count: if deref_method_same_type(expr_ty, typeck.expr_ty(sub_expr)) {
- 0
- } else {
- 1
- },
+ ty_changed_count,
is_final_ufcs: matches!(expr.kind, ExprKind::Call(..)),
target_mut,
},
@@ -454,7 +465,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {
(Some((State::DerefedBorrow(state), data)), RefOp::Deref) => {
let position = data.position;
report(cx, expr, State::DerefedBorrow(state), data);
- if let Position::FieldAccess(name) = position
+ if let Position::FieldAccess{name, ..} = position
&& !ty_contains_field(typeck.expr_ty(sub_expr), name)
{
self.state = Some((
@@ -548,6 +559,12 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {
}
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
+ if self.possible_borrowers.last().map_or(false, |&(local_def_id, _)| {
+ local_def_id == cx.tcx.hir().body_owner_def_id(body.id())
+ }) {
+ self.possible_borrowers.pop();
+ }
+
if Some(body.id()) == self.current_body {
for pat in self.ref_locals.drain(..).filter_map(|(_, x)| x) {
let replacements = pat.replacements;
@@ -619,14 +636,17 @@ fn deref_method_same_type<'tcx>(result_ty: Ty<'tcx>, arg_ty: Ty<'tcx>) -> bool {
}
/// The position of an expression relative to it's parent.
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, Debug)]
enum Position {
MethodReceiver,
/// The method is defined on a reference type. e.g. `impl Foo for &T`
MethodReceiverRefImpl,
Callee,
ImplArg(HirId),
- FieldAccess(Symbol),
+ FieldAccess {
+ name: Symbol,
+ of_union: bool,
+ }, // union fields cannot be auto borrowed
Postfix,
Deref,
/// Any other location which will trigger auto-deref to a specific time.
@@ -648,7 +668,10 @@ impl Position {
}
fn can_auto_borrow(self) -> bool {
- matches!(self, Self::MethodReceiver | Self::FieldAccess(_) | Self::Callee)
+ matches!(
+ self,
+ Self::MethodReceiver | Self::FieldAccess { of_union: false, .. } | Self::Callee
+ )
}
fn lint_explicit_deref(self) -> bool {
@@ -660,7 +683,7 @@ impl Position {
Self::MethodReceiver
| Self::MethodReceiverRefImpl
| Self::Callee
- | Self::FieldAccess(_)
+ | Self::FieldAccess { .. }
| Self::Postfix => PREC_POSTFIX,
Self::ImplArg(_) | Self::Deref => PREC_PREFIX,
Self::DerefStable(p, _) | Self::ReborrowStable(p) | Self::Other(p) => p,
@@ -674,6 +697,7 @@ impl Position {
#[expect(clippy::too_many_lines)]
fn walk_parents<'tcx>(
cx: &LateContext<'tcx>,
+ possible_borrowers: &mut Vec<(LocalDefId, PossibleBorrowerMap<'tcx, 'tcx>)>,
e: &'tcx Expr<'_>,
msrv: Option<RustcVersion>,
) -> (Position, &'tcx [Adjustment<'tcx>]) {
@@ -691,47 +715,47 @@ fn walk_parents<'tcx>(
},
Node::Item(&Item {
kind: ItemKind::Static(..) | ItemKind::Const(..),
- def_id,
+ owner_id,
span,
..
})
| Node::TraitItem(&TraitItem {
kind: TraitItemKind::Const(..),
- def_id,
+ owner_id,
span,
..
})
| Node::ImplItem(&ImplItem {
kind: ImplItemKind::Const(..),
- def_id,
+ owner_id,
span,
..
}) if span.ctxt() == ctxt => {
- let ty = cx.tcx.type_of(def_id);
+ let ty = cx.tcx.type_of(owner_id.def_id);
Some(ty_auto_deref_stability(cx, ty, precedence).position_for_result(cx))
},
Node::Item(&Item {
kind: ItemKind::Fn(..),
- def_id,
+ owner_id,
span,
..
})
| Node::TraitItem(&TraitItem {
kind: TraitItemKind::Fn(..),
- def_id,
+ owner_id,
span,
..
})
| Node::ImplItem(&ImplItem {
kind: ImplItemKind::Fn(..),
- def_id,
+ owner_id,
span,
..
}) if span.ctxt() == ctxt => {
let output = cx
.tcx
- .erase_late_bound_regions(cx.tcx.fn_sig(def_id.to_def_id()).output());
+ .erase_late_bound_regions(cx.tcx.fn_sig(owner_id.to_def_id()).output());
Some(ty_auto_deref_stability(cx, output, precedence).position_for_result(cx))
},
@@ -788,7 +812,16 @@ fn walk_parents<'tcx>(
Some(hir_ty) => binding_ty_auto_deref_stability(cx, hir_ty, precedence, ty.bound_vars()),
None => {
if let ty::Param(param_ty) = ty.skip_binder().kind() {
- needless_borrow_impl_arg_position(cx, parent, i, *param_ty, e, precedence, msrv)
+ needless_borrow_impl_arg_position(
+ cx,
+ possible_borrowers,
+ parent,
+ i,
+ *param_ty,
+ e,
+ precedence,
+ msrv,
+ )
} else {
ty_auto_deref_stability(cx, cx.tcx.erase_late_bound_regions(ty), precedence)
.position_for_arg()
@@ -823,11 +856,10 @@ fn walk_parents<'tcx>(
// Trait methods taking `self`
arg_ty
} && impl_ty.is_ref()
- && cx.tcx.infer_ctxt().enter(|infcx|
- infcx
- .type_implements_trait(trait_id, impl_ty, subs, cx.param_env)
- .must_apply_modulo_regions()
- )
+ && let infcx = cx.tcx.infer_ctxt().build()
+ && infcx
+ .type_implements_trait(trait_id, impl_ty, subs, cx.param_env)
+ .must_apply_modulo_regions()
{
return Some(Position::MethodReceiverRefImpl)
}
@@ -836,7 +868,16 @@ fn walk_parents<'tcx>(
args.iter().position(|arg| arg.hir_id == child_id).map(|i| {
let ty = cx.tcx.fn_sig(id).skip_binder().inputs()[i + 1];
if let ty::Param(param_ty) = ty.kind() {
- needless_borrow_impl_arg_position(cx, parent, i + 1, *param_ty, e, precedence, msrv)
+ needless_borrow_impl_arg_position(
+ cx,
+ possible_borrowers,
+ parent,
+ i + 1,
+ *param_ty,
+ e,
+ precedence,
+ msrv,
+ )
} else {
ty_auto_deref_stability(
cx,
@@ -847,7 +888,10 @@ fn walk_parents<'tcx>(
}
})
},
- ExprKind::Field(child, name) if child.hir_id == e.hir_id => Some(Position::FieldAccess(name.name)),
+ ExprKind::Field(child, name) if child.hir_id == e.hir_id => Some(Position::FieldAccess {
+ name: name.name,
+ of_union: is_union(cx.typeck_results(), child),
+ }),
ExprKind::Unary(UnOp::Deref, child) if child.hir_id == e.hir_id => Some(Position::Deref),
ExprKind::Match(child, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar)
| ExprKind::Index(child, _)
@@ -868,6 +912,13 @@ fn walk_parents<'tcx>(
(position, adjustments)
}
+fn is_union<'tcx>(typeck: &'tcx TypeckResults<'_>, path_expr: &'tcx Expr<'_>) -> bool {
+ typeck
+ .expr_ty_adjusted(path_expr)
+ .ty_adt_def()
+ .map_or(false, rustc_middle::ty::AdtDef::is_union)
+}
+
fn closure_result_position<'tcx>(
cx: &LateContext<'tcx>,
closure: &'tcx Closure<'_>,
@@ -939,7 +990,7 @@ fn binding_ty_auto_deref_stability<'tcx>(
cx.typeck_results().node_type(ty.ty.hir_id),
binder_args,
))
- .is_sized(cx.tcx.at(DUMMY_SP), cx.param_env.without_caller_bounds()),
+ .is_sized(cx.tcx, cx.param_env.without_caller_bounds()),
)
}
},
@@ -954,7 +1005,7 @@ fn binding_ty_auto_deref_stability<'tcx>(
cx.typeck_results().node_type(ty.ty.hir_id),
binder_args,
))
- .is_sized(cx.tcx.at(DUMMY_SP), cx.param_env.without_caller_bounds()),
+ .is_sized(cx.tcx, cx.param_env.without_caller_bounds()),
),
TyKind::OpaqueDef(..) | TyKind::Infer | TyKind::Typeof(..) | TyKind::TraitObject(..) | TyKind::Err => {
Position::ReborrowStable(precedence)
@@ -1000,8 +1051,10 @@ fn ty_contains_infer(ty: &hir::Ty<'_>) -> bool {
// If the conditions are met, returns `Some(Position::ImplArg(..))`; otherwise, returns `None`.
// The "is copyable" condition is to avoid the case where removing the `&` means `e` would have to
// be moved, but it cannot be.
+#[expect(clippy::too_many_arguments)]
fn needless_borrow_impl_arg_position<'tcx>(
cx: &LateContext<'tcx>,
+ possible_borrowers: &mut Vec<(LocalDefId, PossibleBorrowerMap<'tcx, 'tcx>)>,
parent: &Expr<'tcx>,
arg_index: usize,
param_ty: ParamTy,
@@ -1064,10 +1117,13 @@ fn needless_borrow_impl_arg_position<'tcx>(
// elements are modified each time `check_referent` is called.
let mut substs_with_referent_ty = substs_with_expr_ty.to_vec();
- let mut check_referent = |referent| {
+ let mut check_reference_and_referent = |reference, referent| {
let referent_ty = cx.typeck_results().expr_ty(referent);
- if !is_copy(cx, referent_ty) {
+ if !is_copy(cx, referent_ty)
+ && (referent_ty.has_significant_drop(cx.tcx, cx.param_env)
+ || !referent_used_exactly_once(cx, possible_borrowers, reference))
+ {
return false;
}
@@ -1101,15 +1157,14 @@ fn needless_borrow_impl_arg_position<'tcx>(
let predicate = EarlyBinder(predicate).subst(cx.tcx, &substs_with_referent_ty);
let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate);
- cx.tcx
- .infer_ctxt()
- .enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation))
+ let infcx = cx.tcx.infer_ctxt().build();
+ infcx.predicate_must_hold_modulo_regions(&obligation)
})
};
let mut needless_borrow = false;
while let ExprKind::AddrOf(_, _, referent) = expr.kind {
- if !check_referent(referent) {
+ if !check_reference_and_referent(expr, referent) {
break;
}
expr = referent;
@@ -1137,6 +1192,36 @@ fn has_ref_mut_self_method(cx: &LateContext<'_>, trait_def_id: DefId) -> bool {
})
}
+fn referent_used_exactly_once<'tcx>(
+ cx: &LateContext<'tcx>,
+ possible_borrowers: &mut Vec<(LocalDefId, PossibleBorrowerMap<'tcx, 'tcx>)>,
+ reference: &Expr<'tcx>,
+) -> bool {
+ let mir = enclosing_mir(cx.tcx, reference.hir_id);
+ if let Some(local) = expr_local(cx.tcx, reference)
+ && let [location] = *local_assignments(mir, local).as_slice()
+ && let Some(statement) = mir.basic_blocks[location.block].statements.get(location.statement_index)
+ && let StatementKind::Assign(box (_, Rvalue::Ref(_, _, place))) = statement.kind
+ && !place.has_deref()
+ {
+ let body_owner_local_def_id = cx.tcx.hir().enclosing_body_owner(reference.hir_id);
+ if possible_borrowers
+ .last()
+ .map_or(true, |&(local_def_id, _)| local_def_id != body_owner_local_def_id)
+ {
+ possible_borrowers.push((body_owner_local_def_id, PossibleBorrowerMap::new(cx, mir)));
+ }
+ let possible_borrower = &mut possible_borrowers.last_mut().unwrap().1;
+ // If `only_borrowers` were used here, the `copyable_iterator::warn` test would fail. The reason is
+ // that `PossibleBorrowerVisitor::visit_terminator` considers `place.local` a possible borrower of
+ // itself. See the comment in that method for an explanation as to why.
+ possible_borrower.bounded_borrowers(&[local], &[local, place.local], place.local, location)
+ && used_exactly_once(mir, place.local).unwrap_or(false)
+ } else {
+ false
+ }
+}
+
// Iteratively replaces `param_ty` with `new_ty` in `substs`, and similarly for each resulting
// projected type that is a type parameter. Returns `false` if replacing the types would have an
// effect on the function signature beyond substituting `new_ty` for `param_ty`.
@@ -1212,7 +1297,7 @@ impl<'tcx> TyPosition<'tcx> {
fn position_for_result(self, cx: &LateContext<'tcx>) -> Position {
match (self.position, self.ty) {
(Position::ReborrowStable(precedence), Some(ty)) => {
- Position::DerefStable(precedence, ty.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env))
+ Position::DerefStable(precedence, ty.is_sized(cx.tcx, cx.param_env))
},
(position, _) => position,
}
@@ -1241,7 +1326,7 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc
ty::Adt(..) if ty.has_placeholders() || ty.has_opaque_types() => {
Position::ReborrowStable(precedence).into()
},
- ty::Adt(_, substs) if substs.has_param_types_or_consts() => {
+ ty::Adt(_, substs) if substs.has_non_region_param() => {
TyPosition::new_deref_stable_for_result(precedence, ty)
},
ty::Bool
@@ -1263,7 +1348,7 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc
| ty::Tuple(_)
| ty::Projection(_) => Position::DerefStable(
precedence,
- ty.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env.without_caller_bounds()),
+ ty.is_sized(cx.tcx, cx.param_env.without_caller_bounds()),
)
.into(),
};
@@ -1311,7 +1396,7 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data
};
let expr_str = if !expr_is_macro_call && is_final_ufcs && expr.precedence().order() < PREC_PREFIX {
- format!("({})", expr_str)
+ format!("({expr_str})")
} else {
expr_str.into_owned()
};
@@ -1325,7 +1410,7 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data
Mutability::Mut => "explicit `deref_mut` method call",
},
"try this",
- format!("{}{}{}", addr_of_str, deref_str, expr_str),
+ format!("{addr_of_str}{deref_str}{expr_str}"),
app,
);
},
@@ -1339,7 +1424,7 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data
&& !has_enclosing_paren(&snip)
&& (expr.precedence().order() < data.position.precedence() || calls_field)
{
- format!("({})", snip)
+ format!("({snip})")
} else {
snip.into()
};
@@ -1382,9 +1467,9 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data
let (snip, snip_is_macro) = snippet_with_context(cx, expr.span, data.span.ctxt(), "..", &mut app);
let sugg =
if !snip_is_macro && expr.precedence().order() < precedence && !has_enclosing_paren(&snip) {
- format!("{}({})", prefix, snip)
+ format!("{prefix}({snip})")
} else {
- format!("{}{}", prefix, snip)
+ format!("{prefix}{snip}")
};
diag.span_suggestion(data.span, "try this", sugg, app);
},
@@ -1421,8 +1506,8 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data
}
}
-impl Dereferencing {
- fn check_local_usage<'tcx>(&mut self, cx: &LateContext<'tcx>, e: &Expr<'tcx>, local: HirId) {
+impl<'tcx> Dereferencing<'tcx> {
+ fn check_local_usage(&mut self, cx: &LateContext<'tcx>, e: &Expr<'tcx>, local: HirId) {
if let Some(outer_pat) = self.ref_locals.get_mut(&local) {
if let Some(pat) = outer_pat {
// Check for auto-deref
@@ -1463,14 +1548,14 @@ impl Dereferencing {
} else {
pat.always_deref = false;
let snip = snippet_with_context(cx, e.span, parent.span.ctxt(), "..", &mut pat.app).0;
- pat.replacements.push((e.span, format!("&{}", snip)));
+ pat.replacements.push((e.span, format!("&{snip}")));
}
},
_ if !e.span.from_expansion() => {
// Double reference might be needed at this point.
pat.always_deref = false;
let snip = snippet_with_applicability(cx, e.span, "..", &mut pat.app);
- pat.replacements.push((e.span, format!("&{}", snip)));
+ pat.replacements.push((e.span, format!("&{snip}")));
},
// Edge case for macros. The span of the identifier will usually match the context of the
// binding, but not if the identifier was created in a macro. e.g. `concat_idents` and proc
diff --git a/src/tools/clippy/clippy_lints/src/derivable_impls.rs b/src/tools/clippy/clippy_lints/src/derivable_impls.rs
index ef9eeecc6..ae8f6b794 100644
--- a/src/tools/clippy/clippy_lints/src/derivable_impls.rs
+++ b/src/tools/clippy/clippy_lints/src/derivable_impls.rs
@@ -1,5 +1,6 @@
-use clippy_utils::diagnostics::span_lint_and_help;
+use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::{is_default_equivalent, peel_blocks};
+use rustc_errors::Applicability;
use rustc_hir::{
def::{DefKind, Res},
Body, Expr, ExprKind, GenericArg, Impl, ImplItemKind, Item, ItemKind, Node, PathSegment, QPath, TyKind,
@@ -69,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
self_ty,
..
}) = item.kind;
- if !cx.tcx.has_attr(item.def_id.to_def_id(), sym::automatically_derived);
+ if !cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived);
if !item.span.from_expansion();
if let Some(def_id) = trait_ref.trait_def_id();
if cx.tcx.is_diagnostic_item(sym::Default, def_id);
@@ -77,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
if let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir);
if let ImplItemKind::Fn(_, b) = &impl_item.kind;
if let Body { value: func_expr, .. } = cx.tcx.hir().body(*b);
- if let Some(adt_def) = cx.tcx.type_of(item.def_id).ty_adt_def();
+ if let Some(adt_def) = cx.tcx.type_of(item.owner_id).ty_adt_def();
if let attrs = cx.tcx.hir().attrs(item.hir_id());
if !attrs.iter().any(|attr| attr.doc_str().is_some());
if let child_attrs = cx.tcx.hir().attrs(impl_item_hir);
@@ -100,15 +101,28 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
ExprKind::Struct(_, fields, _) => fields.iter().all(|ef| is_default_equivalent(cx, ef.expr)),
_ => false,
};
+
if should_emit {
- let path_string = cx.tcx.def_path_str(adt_def.did());
- span_lint_and_help(
+ let struct_span = cx.tcx.def_span(adt_def.did());
+ span_lint_and_then(
cx,
DERIVABLE_IMPLS,
item.span,
"this `impl` can be derived",
- None,
- &format!("try annotating `{}` with `#[derive(Default)]`", path_string),
+ |diag| {
+ diag.span_suggestion_hidden(
+ item.span,
+ "remove the manual implementation...",
+ String::new(),
+ Applicability::MachineApplicable
+ );
+ diag.span_suggestion(
+ struct_span.shrink_to_lo(),
+ "...and instead derive it",
+ "#[derive(Default)]\n".to_string(),
+ Applicability::MachineApplicable
+ );
+ }
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/derive.rs b/src/tools/clippy/clippy_lints/src/derive.rs
index 751ca24d5..102a02138 100644
--- a/src/tools/clippy/clippy_lints/src/derive.rs
+++ b/src/tools/clippy/clippy_lints/src/derive.rs
@@ -191,7 +191,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.63.0"]
pub DERIVE_PARTIAL_EQ_WITHOUT_EQ,
- style,
+ nursery,
"deriving `PartialEq` on a type that can implement `Eq`, without implementing `Eq`"
}
@@ -210,8 +210,8 @@ impl<'tcx> LateLintPass<'tcx> for Derive {
..
}) = item.kind
{
- let ty = cx.tcx.type_of(item.def_id);
- let is_automatically_derived = cx.tcx.has_attr(item.def_id.to_def_id(), sym::automatically_derived);
+ let ty = cx.tcx.type_of(item.owner_id);
+ let is_automatically_derived = cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived);
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);
check_ord_partial_ord(cx, item.span, trait_ref, ty, is_automatically_derived);
@@ -339,10 +339,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h
Some(id) if trait_ref.trait_def_id() == Some(id) => id,
_ => return,
};
- let copy_id = match cx.tcx.lang_items().copy_trait() {
- Some(id) => id,
- None => return,
- };
+ let Some(copy_id) = cx.tcx.lang_items().copy_trait() else { return };
let (ty_adt, ty_subs) = match *ty.kind() {
// Unions can't derive clone.
ty::Adt(adt, subs) if !adt.is_union() => (adt, subs),
diff --git a/src/tools/clippy/clippy_lints/src/disallowed_macros.rs b/src/tools/clippy/clippy_lints/src/disallowed_macros.rs
new file mode 100644
index 000000000..5ab7144e2
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/disallowed_macros.rs
@@ -0,0 +1,151 @@
+use clippy_utils::diagnostics::span_lint_and_then;
+use clippy_utils::macros::macro_backtrace;
+use rustc_data_structures::fx::FxHashSet;
+use rustc_hir::def::{Namespace, Res};
+use rustc_hir::def_id::DefIdMap;
+use rustc_hir::{Expr, ForeignItem, HirId, ImplItem, Item, Pat, Path, Stmt, TraitItem, Ty};
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_session::{declare_tool_lint, impl_lint_pass};
+use rustc_span::{ExpnId, Span};
+
+use crate::utils::conf;
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Denies the configured macros in clippy.toml
+ ///
+ /// Note: Even though this lint is warn-by-default, it will only trigger if
+ /// macros are defined in the clippy.toml file.
+ ///
+ /// ### Why is this bad?
+ /// Some macros are undesirable in certain contexts, and it's beneficial to
+ /// lint for them as needed.
+ ///
+ /// ### Example
+ /// An example clippy.toml configuration:
+ /// ```toml
+ /// # clippy.toml
+ /// disallowed-macros = [
+ /// # Can use a string as the path of the disallowed macro.
+ /// "std::print",
+ /// # Can also use an inline table with a `path` key.
+ /// { path = "std::println" },
+ /// # When using an inline table, can add a `reason` for why the macro
+ /// # is disallowed.
+ /// { path = "serde::Serialize", reason = "no serializing" },
+ /// ]
+ /// ```
+ /// ```
+ /// use serde::Serialize;
+ ///
+ /// // Example code where clippy issues a warning
+ /// println!("warns");
+ ///
+ /// // The diagnostic will contain the message "no serializing"
+ /// #[derive(Serialize)]
+ /// struct Data {
+ /// name: String,
+ /// value: usize,
+ /// }
+ /// ```
+ #[clippy::version = "1.65.0"]
+ pub DISALLOWED_MACROS,
+ style,
+ "use of a disallowed macro"
+}
+
+pub struct DisallowedMacros {
+ conf_disallowed: Vec<conf::DisallowedPath>,
+ disallowed: DefIdMap<usize>,
+ seen: FxHashSet<ExpnId>,
+}
+
+impl DisallowedMacros {
+ pub fn new(conf_disallowed: Vec<conf::DisallowedPath>) -> Self {
+ Self {
+ conf_disallowed,
+ disallowed: DefIdMap::default(),
+ seen: FxHashSet::default(),
+ }
+ }
+
+ fn check(&mut self, cx: &LateContext<'_>, span: Span) {
+ if self.conf_disallowed.is_empty() {
+ return;
+ }
+
+ for mac in macro_backtrace(span) {
+ if !self.seen.insert(mac.expn) {
+ return;
+ }
+
+ if let Some(&index) = self.disallowed.get(&mac.def_id) {
+ let conf = &self.conf_disallowed[index];
+
+ span_lint_and_then(
+ cx,
+ DISALLOWED_MACROS,
+ mac.span,
+ &format!("use of a disallowed macro `{}`", conf.path()),
+ |diag| {
+ if let Some(reason) = conf.reason() {
+ diag.note(&format!("{reason} (from clippy.toml)"));
+ }
+ },
+ );
+ }
+ }
+ }
+}
+
+impl_lint_pass!(DisallowedMacros => [DISALLOWED_MACROS]);
+
+impl LateLintPass<'_> for DisallowedMacros {
+ fn check_crate(&mut self, cx: &LateContext<'_>) {
+ for (index, conf) in self.conf_disallowed.iter().enumerate() {
+ let segs: Vec<_> = conf.path().split("::").collect();
+ if let Res::Def(_, id) = clippy_utils::def_path_res(cx, &segs, Some(Namespace::MacroNS)) {
+ self.disallowed.insert(id, index);
+ }
+ }
+ }
+
+ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
+ self.check(cx, expr.span);
+ }
+
+ fn check_stmt(&mut self, cx: &LateContext<'_>, stmt: &Stmt<'_>) {
+ self.check(cx, stmt.span);
+ }
+
+ fn check_ty(&mut self, cx: &LateContext<'_>, ty: &Ty<'_>) {
+ self.check(cx, ty.span);
+ }
+
+ fn check_pat(&mut self, cx: &LateContext<'_>, pat: &Pat<'_>) {
+ self.check(cx, pat.span);
+ }
+
+ fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
+ self.check(cx, item.span);
+ self.check(cx, item.vis_span);
+ }
+
+ fn check_foreign_item(&mut self, cx: &LateContext<'_>, item: &ForeignItem<'_>) {
+ self.check(cx, item.span);
+ self.check(cx, item.vis_span);
+ }
+
+ fn check_impl_item(&mut self, cx: &LateContext<'_>, item: &ImplItem<'_>) {
+ self.check(cx, item.span);
+ self.check(cx, item.vis_span);
+ }
+
+ fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &TraitItem<'_>) {
+ self.check(cx, item.span);
+ }
+
+ fn check_path(&mut self, cx: &LateContext<'_>, path: &Path<'_>, _: HirId) {
+ self.check(cx, path.span);
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/disallowed_methods.rs b/src/tools/clippy/clippy_lints/src/disallowed_methods.rs
index 53973ab79..6ac85606d 100644
--- a/src/tools/clippy/clippy_lints/src/disallowed_methods.rs
+++ b/src/tools/clippy/clippy_lints/src/disallowed_methods.rs
@@ -1,7 +1,9 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::{fn_def_id, get_parent_expr, path_def_id};
-use rustc_hir::{def::Res, def_id::DefIdMap, Expr, ExprKind};
+use rustc_hir::def::{Namespace, Res};
+use rustc_hir::def_id::DefIdMap;
+use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -58,12 +60,12 @@ declare_clippy_lint! {
#[derive(Clone, Debug)]
pub struct DisallowedMethods {
- conf_disallowed: Vec<conf::DisallowedMethod>,
+ conf_disallowed: Vec<conf::DisallowedPath>,
disallowed: DefIdMap<usize>,
}
impl DisallowedMethods {
- pub fn new(conf_disallowed: Vec<conf::DisallowedMethod>) -> Self {
+ pub fn new(conf_disallowed: Vec<conf::DisallowedPath>) -> Self {
Self {
conf_disallowed,
disallowed: DefIdMap::default(),
@@ -77,7 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedMethods {
fn check_crate(&mut self, cx: &LateContext<'_>) {
for (index, conf) in self.conf_disallowed.iter().enumerate() {
let segs: Vec<_> = conf.path().split("::").collect();
- if let Res::Def(_, id) = clippy_utils::def_path_res(cx, &segs) {
+ if let Res::Def(_, id) = clippy_utils::def_path_res(cx, &segs, Some(Namespace::ValueNS)) {
self.disallowed.insert(id, index);
}
}
@@ -92,9 +94,8 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedMethods {
} else {
path_def_id(cx, expr)
};
- let def_id = match uncalled_path.or_else(|| fn_def_id(cx, expr)) {
- Some(def_id) => def_id,
- None => return,
+ let Some(def_id) = uncalled_path.or_else(|| fn_def_id(cx, expr)) else {
+ return
};
let conf = match self.disallowed.get(&def_id) {
Some(&index) => &self.conf_disallowed[index],
@@ -102,11 +103,8 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedMethods {
};
let msg = format!("use of a disallowed method `{}`", conf.path());
span_lint_and_then(cx, DISALLOWED_METHODS, expr.span, &msg, |diag| {
- if let conf::DisallowedMethod::WithReason {
- reason: Some(reason), ..
- } = conf
- {
- diag.note(&format!("{} (from clippy.toml)", reason));
+ if let Some(reason) = conf.reason() {
+ diag.note(&format!("{reason} (from clippy.toml)"));
}
});
}
diff --git a/src/tools/clippy/clippy_lints/src/disallowed_script_idents.rs b/src/tools/clippy/clippy_lints/src/disallowed_script_idents.rs
index 0c27c3f92..084190f00 100644
--- a/src/tools/clippy/clippy_lints/src/disallowed_script_idents.rs
+++ b/src/tools/clippy/clippy_lints/src/disallowed_script_idents.rs
@@ -99,8 +99,7 @@ impl EarlyLintPass for DisallowedScriptIdents {
DISALLOWED_SCRIPT_IDENTS,
span,
&format!(
- "identifier `{}` has a Unicode script that is not allowed by configuration: {}",
- symbol_str,
+ "identifier `{symbol_str}` has a Unicode script that is not allowed by configuration: {}",
script.full_name()
),
);
diff --git a/src/tools/clippy/clippy_lints/src/disallowed_types.rs b/src/tools/clippy/clippy_lints/src/disallowed_types.rs
index 28dbfbab2..c7131fc16 100644
--- a/src/tools/clippy/clippy_lints/src/disallowed_types.rs
+++ b/src/tools/clippy/clippy_lints/src/disallowed_types.rs
@@ -1,9 +1,9 @@
use clippy_utils::diagnostics::span_lint_and_then;
use rustc_data_structures::fx::FxHashMap;
-use rustc_hir::{
- def::Res, def_id::DefId, Item, ItemKind, PolyTraitRef, PrimTy, Ty, TyKind, UseKind,
-};
+use rustc_hir::def::{Namespace, Res};
+use rustc_hir::def_id::DefId;
+use rustc_hir::{Item, ItemKind, PolyTraitRef, PrimTy, Ty, TyKind, UseKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::Span;
@@ -52,13 +52,13 @@ declare_clippy_lint! {
}
#[derive(Clone, Debug)]
pub struct DisallowedTypes {
- conf_disallowed: Vec<conf::DisallowedType>,
+ conf_disallowed: Vec<conf::DisallowedPath>,
def_ids: FxHashMap<DefId, Option<String>>,
prim_tys: FxHashMap<PrimTy, Option<String>>,
}
impl DisallowedTypes {
- pub fn new(conf_disallowed: Vec<conf::DisallowedType>) -> Self {
+ pub fn new(conf_disallowed: Vec<conf::DisallowedPath>) -> Self {
Self {
conf_disallowed,
def_ids: FxHashMap::default(),
@@ -88,15 +88,9 @@ impl_lint_pass!(DisallowedTypes => [DISALLOWED_TYPES]);
impl<'tcx> LateLintPass<'tcx> for DisallowedTypes {
fn check_crate(&mut self, cx: &LateContext<'_>) {
for conf in &self.conf_disallowed {
- let (path, reason) = match conf {
- conf::DisallowedType::Simple(path) => (path, None),
- conf::DisallowedType::WithReason { path, reason } => (
- path,
- reason.as_ref().map(|reason| format!("{} (from clippy.toml)", reason)),
- ),
- };
- let segs: Vec<_> = path.split("::").collect();
- match clippy_utils::def_path_res(cx, &segs) {
+ let segs: Vec<_> = conf.path().split("::").collect();
+ let reason = conf.reason().map(|reason| format!("{reason} (from clippy.toml)"));
+ match clippy_utils::def_path_res(cx, &segs, Some(Namespace::TypeNS)) {
Res::Def(_, id) => {
self.def_ids.insert(id, reason);
},
@@ -130,7 +124,7 @@ fn emit(cx: &LateContext<'_>, name: &str, span: Span, reason: Option<&str>) {
cx,
DISALLOWED_TYPES,
span,
- &format!("`{}` is not allowed according to config", name),
+ &format!("`{name}` is not allowed according to config"),
|diag| {
if let Some(reason) = reason {
diag.note(reason);
diff --git a/src/tools/clippy/clippy_lints/src/doc.rs b/src/tools/clippy/clippy_lints/src/doc.rs
index eb158d850..24d6a6951 100644
--- a/src/tools/clippy/clippy_lints/src/doc.rs
+++ b/src/tools/clippy/clippy_lints/src/doc.rs
@@ -198,6 +198,29 @@ declare_clippy_lint! {
"presence of `fn main() {` in code examples"
}
+declare_clippy_lint! {
+ /// ### What it does
+ /// Detects the syntax `['foo']` in documentation comments (notice quotes instead of backticks)
+ /// outside of code blocks
+ /// ### Why is this bad?
+ /// It is likely a typo when defining an intra-doc link
+ ///
+ /// ### Example
+ /// ```rust
+ /// /// See also: ['foo']
+ /// fn bar() {}
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// /// See also: [`foo`]
+ /// fn bar() {}
+ /// ```
+ #[clippy::version = "1.63.0"]
+ pub DOC_LINK_WITH_QUOTES,
+ pedantic,
+ "possible typo for an intra-doc link"
+}
+
#[expect(clippy::module_name_repetitions)]
#[derive(Clone)]
pub struct DocMarkdown {
@@ -214,9 +237,14 @@ impl DocMarkdown {
}
}
-impl_lint_pass!(DocMarkdown =>
- [DOC_MARKDOWN, MISSING_SAFETY_DOC, MISSING_ERRORS_DOC, MISSING_PANICS_DOC, NEEDLESS_DOCTEST_MAIN]
-);
+impl_lint_pass!(DocMarkdown => [
+ DOC_LINK_WITH_QUOTES,
+ DOC_MARKDOWN,
+ MISSING_SAFETY_DOC,
+ MISSING_ERRORS_DOC,
+ MISSING_PANICS_DOC,
+ NEEDLESS_DOCTEST_MAIN
+]);
impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
@@ -229,15 +257,23 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
let headers = check_attrs(cx, &self.valid_idents, attrs);
match item.kind {
hir::ItemKind::Fn(ref sig, _, body_id) => {
- if !(is_entrypoint_fn(cx, item.def_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) {
+ if !(is_entrypoint_fn(cx, item.owner_id.to_def_id()) || in_external_macro(cx.tcx.sess, item.span)) {
let body = cx.tcx.hir().body(body_id);
let mut fpu = FindPanicUnwrap {
cx,
- typeck_results: cx.tcx.typeck(item.def_id),
+ typeck_results: cx.tcx.typeck(item.owner_id.def_id),
panic_span: None,
};
fpu.visit_expr(body.value);
- lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
+ lint_for_missing_headers(
+ cx,
+ item.owner_id.def_id,
+ item.span,
+ sig,
+ headers,
+ Some(body_id),
+ fpu.panic_span,
+ );
}
},
hir::ItemKind::Impl(impl_) => {
@@ -268,7 +304,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
let headers = check_attrs(cx, &self.valid_idents, attrs);
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
if !in_external_macro(cx.tcx.sess, item.span) {
- lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, None, None);
+ lint_for_missing_headers(cx, item.owner_id.def_id, item.span, sig, headers, None, None);
}
}
}
@@ -283,11 +319,19 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
let body = cx.tcx.hir().body(body_id);
let mut fpu = FindPanicUnwrap {
cx,
- typeck_results: cx.tcx.typeck(item.def_id),
+ typeck_results: cx.tcx.typeck(item.owner_id.def_id),
panic_span: None,
};
fpu.visit_expr(body.value);
- lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, Some(body_id), fpu.panic_span);
+ lint_for_missing_headers(
+ cx,
+ item.owner_id.def_id,
+ item.span,
+ sig,
+ headers,
+ Some(body_id),
+ fpu.panic_span,
+ );
}
}
}
@@ -301,7 +345,7 @@ fn lint_for_missing_headers<'tcx>(
body_id: Option<hir::BodyId>,
panic_span: Option<Span>,
) {
- if !cx.access_levels.is_exported(def_id) {
+ if !cx.effective_visibilities.is_exported(def_id) {
return; // Private functions do not require doc comments
}
@@ -416,7 +460,7 @@ pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span:
(no_stars, sizes)
}
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, Default)]
struct DocHeaders {
safety: bool,
errors: bool,
@@ -460,11 +504,7 @@ fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs
}
if doc.is_empty() {
- return DocHeaders {
- safety: false,
- errors: false,
- panics: false,
- };
+ return DocHeaders::default();
}
let mut cb = fake_broken_link_callback;
@@ -505,11 +545,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
use pulldown_cmark::Tag::{CodeBlock, Heading, Item, Link, Paragraph};
use pulldown_cmark::{CodeBlockKind, CowStr};
- let mut headers = DocHeaders {
- safety: false,
- errors: false,
- panics: false,
- };
+ let mut headers = DocHeaders::default();
let mut in_code = false;
let mut in_link = None;
let mut in_heading = false;
@@ -596,6 +632,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
check_code(cx, &text, edition, span);
}
} else {
+ check_link_quotes(cx, in_link.is_some(), trimmed_text, span, &range, begin, text.len());
// Adjust for the beginning of the current `Event`
let span = span.with_lo(span.lo() + BytePos::from_usize(range.start - begin));
text_to_check.push((text, span));
@@ -606,6 +643,27 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
headers
}
+fn check_link_quotes(
+ cx: &LateContext<'_>,
+ in_link: bool,
+ trimmed_text: &str,
+ span: Span,
+ range: &Range<usize>,
+ begin: usize,
+ text_len: usize,
+) {
+ if in_link && trimmed_text.starts_with('\'') && trimmed_text.ends_with('\'') {
+ // fix the span to only point at the text within the link
+ let lo = span.lo() + BytePos::from_usize(range.start - begin);
+ span_lint(
+ cx,
+ DOC_LINK_WITH_QUOTES,
+ span.with_lo(lo).with_hi(lo + BytePos::from_usize(text_len)),
+ "possible intra-doc link using quotes instead of backticks",
+ );
+ }
+}
+
fn get_current_span(spans: &[(usize, Span)], idx: usize) -> (usize, Span) {
let index = match spans.binary_search_by(|c| c.0.cmp(&idx)) {
Ok(o) => o,
@@ -790,7 +848,7 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span) {
diag.span_suggestion_with_style(
span,
"try",
- format!("`{}`", snippet),
+ format!("`{snippet}`"),
applicability,
// always show the suggestion in a separate line, since the
// inline presentation adds another pair of backticks
diff --git a/src/tools/clippy/clippy_lints/src/doc_link_with_quotes.rs b/src/tools/clippy/clippy_lints/src/doc_link_with_quotes.rs
deleted file mode 100644
index 0ff1d2755..000000000
--- a/src/tools/clippy/clippy_lints/src/doc_link_with_quotes.rs
+++ /dev/null
@@ -1,60 +0,0 @@
-use clippy_utils::diagnostics::span_lint;
-use itertools::Itertools;
-use rustc_ast::{AttrKind, Attribute};
-use rustc_lint::{EarlyContext, EarlyLintPass};
-use rustc_session::{declare_lint_pass, declare_tool_lint};
-
-declare_clippy_lint! {
- /// ### What it does
- /// Detects the syntax `['foo']` in documentation comments (notice quotes instead of backticks)
- /// outside of code blocks
- /// ### Why is this bad?
- /// It is likely a typo when defining an intra-doc link
- ///
- /// ### Example
- /// ```rust
- /// /// See also: ['foo']
- /// fn bar() {}
- /// ```
- /// Use instead:
- /// ```rust
- /// /// See also: [`foo`]
- /// fn bar() {}
- /// ```
- #[clippy::version = "1.63.0"]
- pub DOC_LINK_WITH_QUOTES,
- pedantic,
- "possible typo for an intra-doc link"
-}
-declare_lint_pass!(DocLinkWithQuotes => [DOC_LINK_WITH_QUOTES]);
-
-impl EarlyLintPass for DocLinkWithQuotes {
- fn check_attribute(&mut self, ctx: &EarlyContext<'_>, attr: &Attribute) {
- if let AttrKind::DocComment(_, symbol) = attr.kind {
- if contains_quote_link(symbol.as_str()) {
- span_lint(
- ctx,
- DOC_LINK_WITH_QUOTES,
- attr.span,
- "possible intra-doc link using quotes instead of backticks",
- );
- }
- }
- }
-}
-
-fn contains_quote_link(s: &str) -> bool {
- let mut in_backticks = false;
- let mut found_opening = false;
-
- for c in s.chars().tuple_windows::<(char, char)>() {
- match c {
- ('`', _) => in_backticks = !in_backticks,
- ('[', '\'') if !in_backticks => found_opening = true,
- ('\'', ']') if !in_backticks && found_opening => return true,
- _ => {},
- }
- }
-
- false
-}
diff --git a/src/tools/clippy/clippy_lints/src/double_parens.rs b/src/tools/clippy/clippy_lints/src/double_parens.rs
index a33ef5ce6..0f1d70186 100644
--- a/src/tools/clippy/clippy_lints/src/double_parens.rs
+++ b/src/tools/clippy/clippy_lints/src/double_parens.rs
@@ -61,9 +61,8 @@ impl EarlyLintPass for DoubleParens {
}
}
},
- ExprKind::MethodCall(_, ref params, _) => {
- if params.len() == 2 {
- let param = &params[1];
+ ExprKind::MethodCall(_, _, ref params, _) => {
+ if let [ref param] = params[..] {
if let ExprKind::Paren(_) = param.kind {
span_lint(cx, DOUBLE_PARENS, param.span, msg);
}
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 b35f0b8ca..4721a7b37 100644
--- a/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs
+++ b/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs
@@ -1,7 +1,8 @@
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note};
+use clippy_utils::get_parent_node;
use clippy_utils::is_must_use_func_call;
use clippy_utils::ty::{is_copy, is_must_use_ty, is_type_lang_item};
-use rustc_hir::{Expr, ExprKind, LangItem};
+use rustc_hir::{Arm, Expr, ExprKind, LangItem, Node};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::sym;
@@ -202,11 +203,13 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
&& let Some(fn_name) = cx.tcx.get_diagnostic_name(def_id)
{
let arg_ty = cx.typeck_results().expr_ty(arg);
+ let is_copy = is_copy(cx, arg_ty);
+ let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr);
let (lint, msg) = match fn_name {
sym::mem_drop if arg_ty.is_ref() => (DROP_REF, DROP_REF_SUMMARY),
sym::mem_forget if arg_ty.is_ref() => (FORGET_REF, FORGET_REF_SUMMARY),
- sym::mem_drop if is_copy(cx, arg_ty) => (DROP_COPY, DROP_COPY_SUMMARY),
- sym::mem_forget if is_copy(cx, arg_ty) => (FORGET_COPY, FORGET_COPY_SUMMARY),
+ sym::mem_drop if is_copy && !drop_is_single_call_in_arm => (DROP_COPY, DROP_COPY_SUMMARY),
+ sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY),
sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => {
span_lint_and_help(
cx,
@@ -221,7 +224,9 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
sym::mem_drop
if !(arg_ty.needs_drop(cx.tcx, cx.param_env)
|| is_must_use_func_call(cx, arg)
- || is_must_use_ty(cx, arg_ty)) =>
+ || is_must_use_ty(cx, arg_ty)
+ || drop_is_single_call_in_arm
+ ) =>
{
(DROP_NON_DROP, DROP_NON_DROP_SUMMARY)
},
@@ -236,8 +241,23 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
expr.span,
msg,
Some(arg.span),
- &format!("argument has type `{}`", arg_ty),
+ &format!("argument has type `{arg_ty}`"),
);
}
}
}
+
+// dropping returned value of a function like in the following snippet is considered idiomatic, see
+// #9482 for examples match <var> {
+// <pat> => drop(fn_with_side_effect_and_returning_some_value()),
+// ..
+// }
+fn is_single_call_in_arm<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'_>, drop_expr: &'tcx Expr<'_>) -> bool {
+ if matches!(arg.kind, ExprKind::Call(..) | ExprKind::MethodCall(..)) {
+ let parent_node = get_parent_node(cx.tcx, drop_expr.hir_id);
+ if let Some(Node::Arm(Arm { body, .. })) = &parent_node {
+ return body.hir_id == drop_expr.hir_id;
+ }
+ }
+ false
+}
diff --git a/src/tools/clippy/clippy_lints/src/empty_enum.rs b/src/tools/clippy/clippy_lints/src/empty_enum.rs
index bbebc0244..0570c2a10 100644
--- a/src/tools/clippy/clippy_lints/src/empty_enum.rs
+++ b/src/tools/clippy/clippy_lints/src/empty_enum.rs
@@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
}
if let ItemKind::Enum(..) = item.kind {
- let ty = cx.tcx.type_of(item.def_id);
+ let ty = cx.tcx.type_of(item.owner_id);
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
if adt.variants().is_empty() {
span_lint_and_help(
diff --git a/src/tools/clippy/clippy_lints/src/entry.rs b/src/tools/clippy/clippy_lints/src/entry.rs
index e70df3f53..b44e62435 100644
--- a/src/tools/clippy/clippy_lints/src/entry.rs
+++ b/src/tools/clippy/clippy_lints/src/entry.rs
@@ -65,28 +65,24 @@ declare_lint_pass!(HashMapPass => [MAP_ENTRY]);
impl<'tcx> LateLintPass<'tcx> for HashMapPass {
#[expect(clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
- let (cond_expr, then_expr, else_expr) = match higher::If::hir(expr) {
- Some(higher::If { cond, then, r#else }) => (cond, then, r#else),
- _ => return,
+ let Some(higher::If { cond: cond_expr, then: then_expr, r#else: else_expr }) = higher::If::hir(expr) else {
+ return
};
- let (map_ty, contains_expr) = match try_parse_contains(cx, cond_expr) {
- Some(x) => x,
- None => return,
+ let Some((map_ty, contains_expr)) = try_parse_contains(cx, cond_expr) else {
+ return
};
- let then_search = match find_insert_calls(cx, &contains_expr, then_expr) {
- Some(x) => x,
- None => return,
+ let Some(then_search) = find_insert_calls(cx, &contains_expr, then_expr) else {
+ return
};
let mut app = Applicability::MachineApplicable;
let map_str = snippet_with_context(cx, contains_expr.map.span, contains_expr.call_ctxt, "..", &mut app).0;
let key_str = snippet_with_context(cx, contains_expr.key.span, contains_expr.call_ctxt, "..", &mut app).0;
let sugg = if let Some(else_expr) = else_expr {
- let else_search = match find_insert_calls(cx, &contains_expr, else_expr) {
- Some(search) => search,
- None => return,
+ let Some(else_search) = find_insert_calls(cx, &contains_expr, else_expr) else {
+ return;
};
if then_search.edits.is_empty() && else_search.edits.is_empty() {
@@ -113,13 +109,8 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass {
),
};
format!(
- "if let {}::{} = {}.entry({}) {} else {}",
+ "if let {}::{entry_kind} = {map_str}.entry({key_str}) {then_str} else {else_str}",
map_ty.entry_path(),
- entry_kind,
- map_str,
- key_str,
- then_str,
- else_str,
)
} else {
// if .. { insert } else { insert }
@@ -137,16 +128,11 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass {
let indent_str = snippet_indent(cx, expr.span);
let indent_str = indent_str.as_deref().unwrap_or("");
format!(
- "match {}.entry({}) {{\n{indent} {entry}::{} => {}\n\
- {indent} {entry}::{} => {}\n{indent}}}",
- map_str,
- key_str,
- then_entry,
+ "match {map_str}.entry({key_str}) {{\n{indent_str} {entry}::{then_entry} => {}\n\
+ {indent_str} {entry}::{else_entry} => {}\n{indent_str}}}",
reindent_multiline(then_str.into(), true, Some(4 + indent_str.len())),
- else_entry,
reindent_multiline(else_str.into(), true, Some(4 + indent_str.len())),
entry = map_ty.entry_path(),
- indent = indent_str,
)
}
} else {
@@ -163,20 +149,16 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass {
then_search.snippet_occupied(cx, then_expr.span, &mut app)
};
format!(
- "if let {}::{} = {}.entry({}) {}",
+ "if let {}::{entry_kind} = {map_str}.entry({key_str}) {body_str}",
map_ty.entry_path(),
- entry_kind,
- map_str,
- key_str,
- body_str,
)
} else if let Some(insertion) = then_search.as_single_insertion() {
let value_str = snippet_with_context(cx, insertion.value.span, then_expr.span.ctxt(), "..", &mut app).0;
if contains_expr.negated {
if insertion.value.can_have_side_effects() {
- format!("{}.entry({}).or_insert_with(|| {});", map_str, key_str, value_str)
+ format!("{map_str}.entry({key_str}).or_insert_with(|| {value_str});")
} else {
- format!("{}.entry({}).or_insert({});", map_str, key_str, value_str)
+ format!("{map_str}.entry({key_str}).or_insert({value_str});")
}
} else {
// TODO: suggest using `if let Some(v) = map.get_mut(k) { .. }` here.
@@ -186,7 +168,7 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass {
} else {
let block_str = then_search.snippet_closure(cx, then_expr.span, &mut app);
if contains_expr.negated {
- format!("{}.entry({}).or_insert_with(|| {});", map_str, key_str, block_str)
+ format!("{map_str}.entry({key_str}).or_insert_with(|| {block_str});")
} else {
// TODO: suggest using `if let Some(v) = map.get_mut(k) { .. }` here.
// This would need to be a different lint.
diff --git a/src/tools/clippy/clippy_lints/src/enum_variants.rs b/src/tools/clippy/clippy_lints/src/enum_variants.rs
index cd36f9fcd..223545fa7 100644
--- a/src/tools/clippy/clippy_lints/src/enum_variants.rs
+++ b/src/tools/clippy/clippy_lints/src/enum_variants.rs
@@ -202,12 +202,11 @@ fn check_variant(cx: &LateContext<'_>, threshold: u64, def: &EnumDef<'_>, item_n
cx,
ENUM_VARIANT_NAMES,
span,
- &format!("all variants have the same {}fix: `{}`", what, value),
+ &format!("all variants have the same {what}fix: `{value}`"),
None,
&format!(
- "remove the {}fixes and use full paths to \
- the variants instead of glob imports",
- what
+ "remove the {what}fixes and use full paths to \
+ the variants instead of glob imports"
),
);
}
@@ -266,7 +265,7 @@ impl LateLintPass<'_> for EnumVariantNames {
}
// The `module_name_repetitions` lint should only trigger if the item has the module in its
// name. Having the same name is accepted.
- if cx.tcx.visibility(item.def_id).is_public() && item_camel.len() > mod_camel.len() {
+ if cx.tcx.visibility(item.owner_id).is_public() && item_camel.len() > mod_camel.len() {
let matching = count_match_start(mod_camel, &item_camel);
let rmatching = count_match_end(mod_camel, &item_camel);
let nchars = mod_camel.chars().count();
@@ -297,7 +296,7 @@ impl LateLintPass<'_> for EnumVariantNames {
}
}
if let ItemKind::Enum(ref def, _) = item.kind {
- if !(self.avoid_breaking_exported_api && cx.access_levels.is_exported(item.def_id)) {
+ if !(self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(item.owner_id.def_id)) {
check_variant(cx, self.threshold, def, item_name, item.span);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/equatable_if_let.rs b/src/tools/clippy/clippy_lints/src/equatable_if_let.rs
index bce49165e..b40cb7cdd 100644
--- a/src/tools/clippy/clippy_lints/src/equatable_if_let.rs
+++ b/src/tools/clippy/clippy_lints/src/equatable_if_let.rs
@@ -51,9 +51,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
false
},
PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)),
- PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => {
- !etc.as_opt_usize().is_some() && array_rec(a)
- }
+ PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a),
PatKind::Ref(x, _) | PatKind::Box(x) => unary_pattern(x),
PatKind::Path(_) | PatKind::Lit(_) => true,
}
@@ -93,9 +91,8 @@ impl<'tcx> LateLintPass<'tcx> for PatternEquality {
"this pattern matching can be expressed using equality",
"try",
format!(
- "{} == {}",
+ "{} == {pat_str}",
snippet_with_context(cx, let_expr.init.span, expr.span.ctxt(), "..", &mut applicability).0,
- pat_str,
),
applicability,
);
diff --git a/src/tools/clippy/clippy_lints/src/escape.rs b/src/tools/clippy/clippy_lints/src/escape.rs
index 327865e4c..7f1a4c4be 100644
--- a/src/tools/clippy/clippy_lints/src/escape.rs
+++ b/src/tools/clippy/clippy_lints/src/escape.rs
@@ -1,6 +1,7 @@
use clippy_utils::diagnostics::span_lint_hir;
use rustc_hir::intravisit;
use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind};
+use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir::FakeReadCause;
@@ -10,7 +11,6 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::source_map::Span;
use rustc_span::symbol::kw;
use rustc_target::spec::abi::Abi;
-use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
#[derive(Copy, Clone)]
pub struct BoxedLocal {
@@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
}
}
- let parent_id = cx.tcx.hir().get_parent_item(hir_id);
+ let parent_id = cx.tcx.hir().get_parent_item(hir_id).def_id;
let parent_node = cx.tcx.hir().find_by_def_id(parent_id);
let mut trait_self_ty = None;
@@ -88,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
// be sure we have `self` parameter in this function
if trait_item.kind == (AssocItemKind::Fn { has_self: true }) {
trait_self_ty = Some(
- TraitRef::identity(cx.tcx, trait_item.id.def_id.to_def_id())
+ TraitRef::identity(cx.tcx, trait_item.id.owner_id.to_def_id())
.self_ty()
.skip_binder(),
);
@@ -106,9 +106,8 @@ impl<'tcx> LateLintPass<'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.typeck_results()).consume_body(body);
- });
+ let infcx = cx.tcx.infer_ctxt().build();
+ ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
for node in v.set {
span_lint_hir(
@@ -177,7 +176,13 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
}
}
- fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {}
+ fn fake_read(
+ &mut self,
+ _: &rustc_hir_typeck::expr_use_visitor::PlaceWithHirId<'tcx>,
+ _: FakeReadCause,
+ _: HirId,
+ ) {
+ }
}
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {
diff --git a/src/tools/clippy/clippy_lints/src/eta_reduction.rs b/src/tools/clippy/clippy_lints/src/eta_reduction.rs
index 53bc617a4..7b9786d7e 100644
--- a/src/tools/clippy/clippy_lints/src/eta_reduction.rs
+++ b/src/tools/clippy/clippy_lints/src/eta_reduction.rs
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
use clippy_utils::higher::VecArgs;
use clippy_utils::source::snippet_opt;
-use clippy_utils::ty::is_type_diagnostic_item;
+use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
use clippy_utils::usage::local_used_after_expr;
use clippy_utils::{higher, is_adjusted, path_to_local, path_to_local_id};
use if_chain::if_chain;
@@ -11,8 +11,7 @@ use rustc_hir::{Closure, Expr, ExprKind, Param, PatKind, Unsafety};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
use rustc_middle::ty::binding::BindingMode;
-use rustc_middle::ty::subst::Subst;
-use rustc_middle::ty::{self, ClosureKind, Ty, TypeVisitable};
+use rustc_middle::ty::{self, Ty, TypeVisitable};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::sym;
@@ -123,15 +122,12 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
then {
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure", |diag| {
if let Some(mut snippet) = snippet_opt(cx, callee.span) {
- if_chain! {
- if let ty::Closure(_, substs) = callee_ty.peel_refs().kind();
- if substs.as_closure().kind() == ClosureKind::FnMut;
- if path_to_local(callee).map_or(false, |l| local_used_after_expr(cx, l, expr));
-
- then {
+ if let Some(fn_mut_id) = cx.tcx.lang_items().fn_mut_trait()
+ && implements_trait(cx, callee_ty.peel_refs(), fn_mut_id, &[])
+ && path_to_local(callee).map_or(false, |l| local_used_after_expr(cx, l, expr))
+ {
// Mutable closure is used after current expr; we cannot consume it.
- snippet = format!("&mut {}", snippet);
- }
+ snippet = format!("&mut {snippet}");
}
diag.span_suggestion(
expr.span,
@@ -158,7 +154,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
diag.span_suggestion(
expr.span,
"replace the closure with the method itself",
- format!("{}::{}", name, path.ident.name),
+ format!("{name}::{}", path.ident.name),
Applicability::MachineApplicable,
);
})
@@ -217,9 +213,8 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure_ty: Ty<'tcx>, call_ty: Ty<'tc
if !closure_ty.has_late_bound_regions() {
return true;
}
- let substs = match closure_ty.kind() {
- ty::Closure(_, substs) => substs,
- _ => return false,
+ let ty::Closure(_, substs) = closure_ty.kind() else {
+ return false;
};
let closure_sig = cx.tcx.signature_unclosure(substs.as_closure().sig(), Unsafety::Normal);
cx.tcx.erase_late_bound_regions(closure_sig) == cx.tcx.erase_late_bound_regions(call_sig)
diff --git a/src/tools/clippy/clippy_lints/src/exhaustive_items.rs b/src/tools/clippy/clippy_lints/src/exhaustive_items.rs
index 173d41b4b..1fece5d1c 100644
--- a/src/tools/clippy/clippy_lints/src/exhaustive_items.rs
+++ b/src/tools/clippy/clippy_lints/src/exhaustive_items.rs
@@ -73,7 +73,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
if_chain! {
if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind;
- if cx.access_levels.is_exported(item.def_id);
+ if cx.effective_visibilities.is_exported(item.owner_id.def_id);
let attrs = cx.tcx.hir().attrs(item.hir_id());
if !attrs.iter().any(|a| a.has_name(sym::non_exhaustive));
then {
@@ -97,7 +97,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
item.span,
msg,
|diag| {
- let sugg = format!("#[non_exhaustive]\n{}", indent);
+ let sugg = format!("#[non_exhaustive]\n{indent}");
diag.span_suggestion(suggestion_span,
"try adding #[non_exhaustive]",
sugg,
diff --git a/src/tools/clippy/clippy_lints/src/exit.rs b/src/tools/clippy/clippy_lints/src/exit.rs
index cbf52d193..407dd1b39 100644
--- a/src/tools/clippy/clippy_lints/src/exit.rs
+++ b/src/tools/clippy/clippy_lints/src/exit.rs
@@ -33,7 +33,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit {
if let ExprKind::Path(ref path) = path_expr.kind;
if let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id();
if match_def_path(cx, def_id, &paths::EXIT);
- let parent = cx.tcx.hir().get_parent_item(e.hir_id);
+ let parent = cx.tcx.hir().get_parent_item(e.hir_id).def_id;
if let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find_by_def_id(parent);
// If the next item up is a function we check if it is an entry point
// and only then emit a linter warning
diff --git a/src/tools/clippy/clippy_lints/src/explicit_write.rs b/src/tools/clippy/clippy_lints/src/explicit_write.rs
index b9ed4af02..c0ea6f338 100644
--- a/src/tools/clippy/clippy_lints/src/explicit_write.rs
+++ b/src/tools/clippy/clippy_lints/src/explicit_write.rs
@@ -80,12 +80,12 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite {
// used.
let (used, sugg_mac) = if let Some(macro_name) = calling_macro {
(
- format!("{}!({}(), ...)", macro_name, dest_name),
+ format!("{macro_name}!({dest_name}(), ...)"),
macro_name.replace("write", "print"),
)
} else {
(
- format!("{}().write_fmt(...)", dest_name),
+ format!("{dest_name}().write_fmt(...)"),
"print".into(),
)
};
@@ -100,9 +100,9 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite {
cx,
EXPLICIT_WRITE,
expr.span,
- &format!("use of `{}.unwrap()`", used),
+ &format!("use of `{used}.unwrap()`"),
"try this",
- format!("{}{}!({})", prefix, sugg_mac, inputs_snippet),
+ format!("{prefix}{sugg_mac}!({inputs_snippet})"),
applicability,
)
}
diff --git a/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs b/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs
index 1f69f34a2..0a633f242 100644
--- a/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs
+++ b/src/tools/clippy/clippy_lints/src/fallible_impl_from.rs
@@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
// check for `impl From<???> for ..`
if_chain! {
if let hir::ItemKind::Impl(impl_) = &item.kind;
- if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id);
+ if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id);
if cx.tcx.is_diagnostic_item(sym::From, impl_trait_ref.def_id);
then {
lint_impl_body(cx, item.span, impl_.items);
@@ -107,7 +107,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
let body = cx.tcx.hir().body(body_id);
let mut fpu = FindPanicUnwrap {
lcx: cx,
- typeck_results: cx.tcx.typeck(impl_item.id.def_id),
+ typeck_results: cx.tcx.typeck(impl_item.id.owner_id.def_id),
result: Vec::new(),
};
fpu.visit_expr(body.value);
diff --git a/src/tools/clippy/clippy_lints/src/float_literal.rs b/src/tools/clippy/clippy_lints/src/float_literal.rs
index f2e079809..6fee7fb30 100644
--- a/src/tools/clippy/clippy_lints/src/float_literal.rs
+++ b/src/tools/clippy/clippy_lints/src/float_literal.rs
@@ -173,9 +173,9 @@ impl FloatFormat {
T: fmt::UpperExp + fmt::LowerExp + fmt::Display,
{
match self {
- Self::LowerExp => format!("{:e}", f),
- Self::UpperExp => format!("{:E}", f),
- Self::Normal => format!("{}", f),
+ Self::LowerExp => format!("{f:e}"),
+ Self::UpperExp => format!("{f:E}"),
+ Self::Normal => format!("{f}"),
}
}
}
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 ba53a9678..0ed301964 100644
--- a/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs
+++ b/src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs
@@ -142,8 +142,7 @@ fn prepare_receiver_sugg<'a>(cx: &LateContext<'_>, mut expr: &'a Expr<'a>) -> Su
if let ast::LitKind::Float(sym, ast::LitFloatType::Unsuffixed) = lit.node;
then {
let op = format!(
- "{}{}{}",
- suggestion,
+ "{suggestion}{}{}",
// Check for float literals without numbers following the decimal
// separator such as `2.` and adds a trailing zero
if sym.as_str().ends_with('.') {
@@ -172,7 +171,7 @@ fn check_log_base(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, ar
expr.span,
"logarithm for bases 2, 10 and e can be computed more accurately",
"consider using",
- format!("{}.{}()", Sugg::hir(cx, receiver, "..").maybe_par(), method),
+ format!("{}.{method}()", Sugg::hir(cx, receiver, "..").maybe_par()),
Applicability::MachineApplicable,
);
}
@@ -251,7 +250,7 @@ fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args:
expr.span,
"exponent for bases 2 and e can be computed more accurately",
"consider using",
- format!("{}.{}()", prepare_receiver_sugg(cx, &args[0]), method),
+ format!("{}.{method}()", prepare_receiver_sugg(cx, &args[0])),
Applicability::MachineApplicable,
);
}
@@ -312,7 +311,8 @@ fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args:
if let ExprKind::Binary(
Spanned {
- node: BinOpKind::Add, ..
+ node: op @ (BinOpKind::Add | BinOpKind::Sub),
+ ..
},
lhs,
rhs,
@@ -320,6 +320,16 @@ fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args:
{
let other_addend = if lhs.hir_id == expr.hir_id { rhs } else { lhs };
+ // Negate expr if original code has subtraction and expr is on the right side
+ let maybe_neg_sugg = |expr, hir_id| {
+ let sugg = Sugg::hir(cx, expr, "..");
+ if matches!(op, BinOpKind::Sub) && hir_id == rhs.hir_id {
+ format!("-{sugg}")
+ } else {
+ sugg.to_string()
+ }
+ };
+
span_lint_and_sugg(
cx,
SUBOPTIMAL_FLOPS,
@@ -329,8 +339,8 @@ fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args:
format!(
"{}.mul_add({}, {})",
Sugg::hir(cx, receiver, "..").maybe_par(),
- Sugg::hir(cx, receiver, ".."),
- Sugg::hir(cx, other_addend, ".."),
+ maybe_neg_sugg(receiver, expr.hir_id),
+ maybe_neg_sugg(other_addend, other_addend.hir_id),
),
Applicability::MachineApplicable,
);
@@ -444,7 +454,8 @@ fn is_float_mul_expr<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(&'
fn check_mul_add(cx: &LateContext<'_>, expr: &Expr<'_>) {
if let ExprKind::Binary(
Spanned {
- node: BinOpKind::Add, ..
+ node: op @ (BinOpKind::Add | BinOpKind::Sub),
+ ..
},
lhs,
rhs,
@@ -458,10 +469,27 @@ fn check_mul_add(cx: &LateContext<'_>, expr: &Expr<'_>) {
}
}
+ let maybe_neg_sugg = |expr| {
+ let sugg = Sugg::hir(cx, expr, "..");
+ if let BinOpKind::Sub = op {
+ format!("-{sugg}")
+ } else {
+ sugg.to_string()
+ }
+ };
+
let (recv, arg1, arg2) = if let Some((inner_lhs, inner_rhs)) = is_float_mul_expr(cx, lhs) {
- (inner_lhs, inner_rhs, rhs)
+ (
+ inner_lhs,
+ Sugg::hir(cx, inner_rhs, "..").to_string(),
+ maybe_neg_sugg(rhs),
+ )
} else if let Some((inner_lhs, inner_rhs)) = is_float_mul_expr(cx, rhs) {
- (inner_lhs, inner_rhs, lhs)
+ (
+ inner_lhs,
+ maybe_neg_sugg(inner_rhs),
+ Sugg::hir(cx, lhs, "..").to_string(),
+ )
} else {
return;
};
@@ -472,12 +500,7 @@ fn check_mul_add(cx: &LateContext<'_>, expr: &Expr<'_>) {
expr.span,
"multiply and add expressions can be calculated more efficiently and accurately",
"consider using",
- format!(
- "{}.mul_add({}, {})",
- prepare_receiver_sugg(cx, recv),
- Sugg::hir(cx, arg1, ".."),
- Sugg::hir(cx, arg2, ".."),
- ),
+ format!("{}.mul_add({arg1}, {arg2})", prepare_receiver_sugg(cx, recv)),
Applicability::MachineApplicable,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/format.rs b/src/tools/clippy/clippy_lints/src/format.rs
index 0c5851cdb..bc0c68f53 100644
--- a/src/tools/clippy/clippy_lints/src/format.rs
+++ b/src/tools/clippy/clippy_lints/src/format.rs
@@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat {
[_] => {
// Simulate macro expansion, converting {{ and }} to { and }.
let s_expand = format_args.format_string.snippet.replace("{{", "{").replace("}}", "}");
- let sugg = format!("{}.to_string()", s_expand);
+ let sugg = format!("{s_expand}.to_string()");
span_useless_format(cx, call_site, sugg, applicability);
},
[..] => {},
@@ -71,12 +71,12 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat {
let value = arg.param.value;
if_chain! {
if format_args.format_string.parts == [kw::Empty];
+ if arg.format.is_default();
if match cx.typeck_results().expr_ty(value).peel_refs().kind() {
ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(sym::String, adt.did()),
ty::Str => true,
_ => false,
};
- if !arg.format.has_string_formatting();
then {
let is_new_string = match value.kind {
ExprKind::Binary(..) => true,
diff --git a/src/tools/clippy/clippy_lints/src/format_args.rs b/src/tools/clippy/clippy_lints/src/format_args.rs
index 2a55c48cf..f0fe845d3 100644
--- a/src/tools/clippy/clippy_lints/src/format_args.rs
+++ b/src/tools/clippy/clippy_lints/src/format_args.rs
@@ -1,16 +1,22 @@
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
-use clippy_utils::is_diag_trait_item;
-use clippy_utils::macros::{is_format_macro, FormatArgsExpn};
+use clippy_utils::macros::FormatParamKind::{Implicit, Named, Numbered, Starred};
+use clippy_utils::macros::{
+ is_format_macro, is_panic, root_macro_call, Count, FormatArg, FormatArgsExpn, FormatParam, FormatParamUsage,
+};
use clippy_utils::source::snippet_opt;
-use clippy_utils::ty::implements_trait;
+use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
+use clippy_utils::{is_diag_trait_item, meets_msrv, msrvs};
use if_chain::if_chain;
use itertools::Itertools;
use rustc_errors::Applicability;
-use rustc_hir::{Expr, ExprKind, HirId};
-use rustc_lint::{LateContext, LateLintPass};
+use rustc_hir::{Expr, ExprKind, HirId, QPath};
+use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
use rustc_middle::ty::Ty;
-use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_semver::RustcVersion;
+use rustc_session::{declare_tool_lint, impl_lint_pass};
+use rustc_span::def_id::DefId;
+use rustc_span::edition::Edition::Edition2021;
use rustc_span::{sym, ExpnData, ExpnKind, Span, Symbol};
declare_clippy_lint! {
@@ -64,31 +70,256 @@ declare_clippy_lint! {
"`to_string` applied to a type that implements `Display` in format args"
}
-declare_lint_pass!(FormatArgs => [FORMAT_IN_FORMAT_ARGS, TO_STRING_IN_FORMAT_ARGS]);
+declare_clippy_lint! {
+ /// ### What it does
+ /// Detect when a variable is not inlined in a format string,
+ /// and suggests to inline it.
+ ///
+ /// ### Why is this bad?
+ /// Non-inlined code is slightly more difficult to read and understand,
+ /// as it requires arguments to be matched against the format string.
+ /// The inlined syntax, where allowed, is simpler.
+ ///
+ /// ### Example
+ /// ```rust
+ /// # let var = 42;
+ /// # let width = 1;
+ /// # let prec = 2;
+ /// format!("{}", var);
+ /// format!("{v:?}", v = var);
+ /// format!("{0} {0}", var);
+ /// format!("{0:1$}", var, width);
+ /// format!("{:.*}", prec, var);
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// # let var = 42;
+ /// # let width = 1;
+ /// # let prec = 2;
+ /// format!("{var}");
+ /// format!("{var:?}");
+ /// format!("{var} {var}");
+ /// format!("{var:width$}");
+ /// format!("{var:.prec$}");
+ /// ```
+ ///
+ /// ### Known Problems
+ ///
+ /// There may be a false positive if the format string is expanded from certain proc macros:
+ ///
+ /// ```ignore
+ /// println!(indoc!("{}"), var);
+ /// ```
+ ///
+ /// If a format string contains a numbered argument that cannot be inlined
+ /// nothing will be suggested, e.g. `println!("{0}={1}", var, 1+2)`.
+ #[clippy::version = "1.65.0"]
+ pub UNINLINED_FORMAT_ARGS,
+ pedantic,
+ "using non-inlined variables in `format!` calls"
+}
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Detects [formatting parameters] that have no effect on the output of
+ /// `format!()`, `println!()` or similar macros.
+ ///
+ /// ### Why is this bad?
+ /// Shorter format specifiers are easier to read, it may also indicate that
+ /// an expected formatting operation such as adding padding isn't happening.
+ ///
+ /// ### Example
+ /// ```rust
+ /// println!("{:.}", 1.0);
+ ///
+ /// println!("not padded: {:5}", format_args!("..."));
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// println!("{}", 1.0);
+ ///
+ /// println!("not padded: {}", format_args!("..."));
+ /// // OR
+ /// println!("padded: {:5}", format!("..."));
+ /// ```
+ ///
+ /// [formatting parameters]: https://doc.rust-lang.org/std/fmt/index.html#formatting-parameters
+ #[clippy::version = "1.66.0"]
+ pub UNUSED_FORMAT_SPECS,
+ complexity,
+ "use of a format specifier that has no effect"
+}
+
+impl_lint_pass!(FormatArgs => [
+ FORMAT_IN_FORMAT_ARGS,
+ TO_STRING_IN_FORMAT_ARGS,
+ UNINLINED_FORMAT_ARGS,
+ UNUSED_FORMAT_SPECS,
+]);
+
+pub struct FormatArgs {
+ msrv: Option<RustcVersion>,
+}
+
+impl FormatArgs {
+ #[must_use]
+ pub fn new(msrv: Option<RustcVersion>) -> Self {
+ Self { msrv }
+ }
+}
impl<'tcx> LateLintPass<'tcx> for FormatArgs {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
- if_chain! {
- if let Some(format_args) = FormatArgsExpn::parse(cx, expr);
- let expr_expn_data = expr.span.ctxt().outer_expn_data();
- let outermost_expn_data = outermost_expn_data(expr_expn_data);
- if let Some(macro_def_id) = outermost_expn_data.macro_def_id;
- if is_format_macro(cx, macro_def_id);
- if let ExpnKind::Macro(_, name) = outermost_expn_data.kind;
- then {
- for arg in &format_args.args {
- if arg.format.has_string_formatting() {
- continue;
- }
- if is_aliased(&format_args, arg.param.value.hir_id) {
- continue;
- }
- check_format_in_format_args(cx, outermost_expn_data.call_site, name, arg.param.value);
- check_to_string_in_format_args(cx, name, arg.param.value);
+ if let Some(format_args) = FormatArgsExpn::parse(cx, expr)
+ && let expr_expn_data = expr.span.ctxt().outer_expn_data()
+ && let outermost_expn_data = outermost_expn_data(expr_expn_data)
+ && let Some(macro_def_id) = outermost_expn_data.macro_def_id
+ && is_format_macro(cx, macro_def_id)
+ && let ExpnKind::Macro(_, name) = outermost_expn_data.kind
+ {
+ for arg in &format_args.args {
+ check_unused_format_specifier(cx, arg);
+ if !arg.format.is_default() {
+ continue;
}
+ if is_aliased(&format_args, arg.param.value.hir_id) {
+ continue;
+ }
+ check_format_in_format_args(cx, outermost_expn_data.call_site, name, arg.param.value);
+ check_to_string_in_format_args(cx, name, arg.param.value);
+ }
+ if meets_msrv(self.msrv, msrvs::FORMAT_ARGS_CAPTURE) {
+ check_uninlined_args(cx, &format_args, outermost_expn_data.call_site, macro_def_id);
}
}
}
+
+ extract_msrv_attr!(LateContext);
+}
+
+fn check_unused_format_specifier(cx: &LateContext<'_>, arg: &FormatArg<'_>) {
+ let param_ty = cx.typeck_results().expr_ty(arg.param.value).peel_refs();
+
+ if let Count::Implied(Some(mut span)) = arg.format.precision
+ && !span.is_empty()
+ {
+ span_lint_and_then(
+ cx,
+ UNUSED_FORMAT_SPECS,
+ span,
+ "empty precision specifier has no effect",
+ |diag| {
+ if param_ty.is_floating_point() {
+ diag.note("a precision specifier is not required to format floats");
+ }
+
+ if arg.format.is_default() {
+ // If there's no other specifiers remove the `:` too
+ span = arg.format_span();
+ }
+
+ diag.span_suggestion_verbose(span, "remove the `.`", "", Applicability::MachineApplicable);
+ },
+ );
+ }
+
+ if is_type_diagnostic_item(cx, param_ty, sym::Arguments) && !arg.format.is_default_for_trait() {
+ span_lint_and_then(
+ cx,
+ UNUSED_FORMAT_SPECS,
+ arg.span,
+ "format specifiers have no effect on `format_args!()`",
+ |diag| {
+ let mut suggest_format = |spec, span| {
+ let message = format!("for the {spec} to apply consider using `format!()`");
+
+ if let Some(mac_call) = root_macro_call(arg.param.value.span)
+ && cx.tcx.is_diagnostic_item(sym::format_args_macro, mac_call.def_id)
+ && arg.span.eq_ctxt(mac_call.span)
+ {
+ diag.span_suggestion(
+ cx.sess().source_map().span_until_char(mac_call.span, '!'),
+ message,
+ "format",
+ Applicability::MaybeIncorrect,
+ );
+ } else if let Some(span) = span {
+ diag.span_help(span, message);
+ }
+ };
+
+ if !arg.format.width.is_implied() {
+ suggest_format("width", arg.format.width.span());
+ }
+
+ if !arg.format.precision.is_implied() {
+ suggest_format("precision", arg.format.precision.span());
+ }
+
+ diag.span_suggestion_verbose(
+ arg.format_span(),
+ "if the current behavior is intentional, remove the format specifiers",
+ "",
+ Applicability::MaybeIncorrect,
+ );
+ },
+ );
+ }
+}
+
+fn check_uninlined_args(cx: &LateContext<'_>, args: &FormatArgsExpn<'_>, call_site: Span, def_id: DefId) {
+ if args.format_string.span.from_expansion() {
+ return;
+ }
+ if call_site.edition() < Edition2021 && is_panic(cx, def_id) {
+ // panic! before 2021 edition considers a single string argument as non-format
+ return;
+ }
+
+ let mut fixes = Vec::new();
+ // If any of the arguments are referenced by an index number,
+ // and that argument is not a simple variable and cannot be inlined,
+ // we cannot remove any other arguments in the format string,
+ // because the index numbers might be wrong after inlining.
+ // Example of an un-inlinable format: print!("{}{1}", foo, 2)
+ if !args.params().all(|p| check_one_arg(args, &p, &mut fixes)) || fixes.is_empty() {
+ return;
+ }
+
+ // Temporarily ignore multiline spans: https://github.com/rust-lang/rust/pull/102729#discussion_r988704308
+ if fixes.iter().any(|(span, _)| cx.sess().source_map().is_multiline(*span)) {
+ return;
+ }
+
+ span_lint_and_then(
+ cx,
+ UNINLINED_FORMAT_ARGS,
+ call_site,
+ "variables can be used directly in the `format!` string",
+ |diag| {
+ diag.multipart_suggestion("change this to", fixes, Applicability::MachineApplicable);
+ },
+ );
+}
+
+fn check_one_arg(args: &FormatArgsExpn<'_>, param: &FormatParam<'_>, fixes: &mut Vec<(Span, String)>) -> bool {
+ if matches!(param.kind, Implicit | Starred | Named(_) | Numbered)
+ && let ExprKind::Path(QPath::Resolved(None, path)) = param.value.kind
+ && let [segment] = path.segments
+ && let Some(arg_span) = args.value_with_prev_comma_span(param.value.hir_id)
+ {
+ let replacement = match param.usage {
+ FormatParamUsage::Argument => segment.ident.name.to_string(),
+ FormatParamUsage::Width => format!("{}$", segment.ident.name),
+ FormatParamUsage::Precision => format!(".{}$", segment.ident.name),
+ };
+ fixes.push((param.span, replacement));
+ fixes.push((arg_span, String::new()));
+ true // successful inlining, continue checking
+ } else {
+ // if we can't inline a numbered argument, we can't continue
+ param.kind != Numbered
+ }
}
fn outermost_expn_data(expn_data: ExpnData) -> ExpnData {
@@ -117,11 +348,10 @@ fn check_format_in_format_args(
cx,
FORMAT_IN_FORMAT_ARGS,
call_site,
- &format!("`format!` in `{}!` args", name),
+ &format!("`format!` in `{name}!` args"),
|diag| {
diag.help(&format!(
- "combine the `format!(..)` arguments with the outer `{}!(..)` call",
- name
+ "combine the `format!(..)` arguments with the outer `{name}!(..)` call"
));
diag.help("or consider changing `format!` to `format_args!`");
},
@@ -131,7 +361,7 @@ fn check_format_in_format_args(
fn check_to_string_in_format_args(cx: &LateContext<'_>, name: Symbol, value: &Expr<'_>) {
if_chain! {
if !value.span.from_expansion();
- if let ExprKind::MethodCall(_, receiver, [], _) = value.kind;
+ if let ExprKind::MethodCall(_, receiver, [], to_string_span) = value.kind;
if let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(value.hir_id);
if is_diag_trait_item(cx, method_def_id, sym::ToString);
let receiver_ty = cx.typeck_results().expr_ty(receiver);
@@ -147,10 +377,9 @@ fn check_to_string_in_format_args(cx: &LateContext<'_>, name: Symbol, value: &Ex
span_lint_and_sugg(
cx,
TO_STRING_IN_FORMAT_ARGS,
- value.span.with_lo(receiver.span.hi()),
+ to_string_span.with_lo(receiver.span.hi()),
&format!(
- "`to_string` applied to a type that implements `Display` in `{}!` args",
- name
+ "`to_string` applied to a type that implements `Display` in `{name}!` args"
),
"remove this",
String::new(),
@@ -162,16 +391,13 @@ fn check_to_string_in_format_args(cx: &LateContext<'_>, name: Symbol, value: &Ex
TO_STRING_IN_FORMAT_ARGS,
value.span,
&format!(
- "`to_string` applied to a type that implements `Display` in `{}!` args",
- name
+ "`to_string` applied to a type that implements `Display` in `{name}!` args"
),
"use this",
format!(
- "{}{:*>width$}{}",
+ "{}{:*>n_needed_derefs$}{receiver_snippet}",
if needs_ref { "&" } else { "" },
- "",
- receiver_snippet,
- width = n_needed_derefs
+ ""
),
Applicability::MachineApplicable,
);
@@ -180,7 +406,7 @@ fn check_to_string_in_format_args(cx: &LateContext<'_>, name: Symbol, value: &Ex
}
}
-// Returns true if `hir_id` is referred to by multiple format params
+/// Returns true if `hir_id` is referred to by multiple format params
fn is_aliased(args: &FormatArgsExpn<'_>, hir_id: HirId) -> bool {
args.params().filter(|param| param.value.hir_id == hir_id).at_most_one().is_err()
}
diff --git a/src/tools/clippy/clippy_lints/src/format_impl.rs b/src/tools/clippy/clippy_lints/src/format_impl.rs
index b628fd9f7..ed1342a54 100644
--- a/src/tools/clippy/clippy_lints/src/format_impl.rs
+++ b/src/tools/clippy/clippy_lints/src/format_impl.rs
@@ -214,12 +214,12 @@ fn check_print_in_format_impl(cx: &LateContext<'_>, expr: &Expr<'_>, impl_trait:
cx,
PRINT_IN_FORMAT_IMPL,
macro_call.span,
- &format!("use of `{}!` in `{}` impl", name, impl_trait.name),
+ &format!("use of `{name}!` in `{}` impl", impl_trait.name),
"replace with",
if let Some(formatter_name) = impl_trait.formatter_name {
- format!("{}!({}, ..)", replacement, formatter_name)
+ format!("{replacement}!({formatter_name}, ..)")
} else {
- format!("{}!(..)", replacement)
+ format!("{replacement}!(..)")
},
Applicability::HasPlaceholders,
);
diff --git a/src/tools/clippy/clippy_lints/src/formatting.rs b/src/tools/clippy/clippy_lints/src/formatting.rs
index 01cefe4af..a866a6898 100644
--- a/src/tools/clippy/clippy_lints/src/formatting.rs
+++ b/src/tools/clippy/clippy_lints/src/formatting.rs
@@ -154,11 +154,10 @@ fn check_assign(cx: &EarlyContext<'_>, expr: &Expr) {
eqop_span,
&format!(
"this looks like you are trying to use `.. {op}= ..`, but you \
- really are doing `.. = ({op} ..)`",
- op = op
+ really are doing `.. = ({op} ..)`"
),
None,
- &format!("to remove this lint, use either `{op}=` or `= {op}`", op = op),
+ &format!("to remove this lint, use either `{op}=` or `= {op}`"),
);
}
}
@@ -191,16 +190,12 @@ fn check_unop(cx: &EarlyContext<'_>, expr: &Expr) {
SUSPICIOUS_UNARY_OP_FORMATTING,
eqop_span,
&format!(
- "by not having a space between `{binop}` and `{unop}` it looks like \
- `{binop}{unop}` is a single operator",
- binop = binop_str,
- unop = unop_str
+ "by not having a space between `{binop_str}` and `{unop_str}` it looks like \
+ `{binop_str}{unop_str}` is a single operator"
),
None,
&format!(
- "put a space between `{binop}` and `{unop}` and remove the space after `{unop}`",
- binop = binop_str,
- unop = unop_str
+ "put a space between `{binop_str}` and `{unop_str}` and remove the space after `{unop_str}`"
),
);
}
@@ -246,12 +241,11 @@ fn check_else(cx: &EarlyContext<'_>, expr: &Expr) {
cx,
SUSPICIOUS_ELSE_FORMATTING,
else_span,
- &format!("this is an `else {}` but the formatting might hide it", else_desc),
+ &format!("this is an `else {else_desc}` but the formatting might hide it"),
None,
&format!(
"to remove this lint, remove the `else` or remove the new line between \
- `else` and `{}`",
- else_desc,
+ `else` and `{else_desc}`",
),
);
}
@@ -320,11 +314,10 @@ fn check_missing_else(cx: &EarlyContext<'_>, first: &Expr, second: &Expr) {
cx,
SUSPICIOUS_ELSE_FORMATTING,
else_span,
- &format!("this looks like {} but the `else` is missing", looks_like),
+ &format!("this looks like {looks_like} but the `else` is missing"),
None,
&format!(
- "to remove this lint, add the missing `else` or add a new line before {}",
- next_thing,
+ "to remove this lint, add the missing `else` or add a new line before {next_thing}",
),
);
}
diff --git a/src/tools/clippy/clippy_lints/src/from_over_into.rs b/src/tools/clippy/clippy_lints/src/from_over_into.rs
index 5d25c1d06..8b24a4962 100644
--- a/src/tools/clippy/clippy_lints/src/from_over_into.rs
+++ b/src/tools/clippy/clippy_lints/src/from_over_into.rs
@@ -1,11 +1,19 @@
-use clippy_utils::diagnostics::span_lint_and_help;
-use clippy_utils::{meets_msrv, msrvs};
-use if_chain::if_chain;
-use rustc_hir as hir;
+use clippy_utils::diagnostics::span_lint_and_then;
+use clippy_utils::macros::span_is_local;
+use clippy_utils::source::snippet_opt;
+use clippy_utils::{meets_msrv, msrvs, path_def_id};
+use rustc_errors::Applicability;
+use rustc_hir::intravisit::{walk_path, Visitor};
+use rustc_hir::{
+ GenericArg, GenericArgs, HirId, Impl, ImplItemKind, ImplItemRef, Item, ItemKind, PatKind, Path, PathSegment, Ty,
+ TyKind,
+};
use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::hir::nested_filter::OnlyBodies;
use rustc_semver::RustcVersion;
use rustc_session::{declare_tool_lint, impl_lint_pass};
-use rustc_span::symbol::sym;
+use rustc_span::symbol::{kw, sym};
+use rustc_span::{Span, Symbol};
declare_clippy_lint! {
/// ### What it does
@@ -54,28 +62,152 @@ impl FromOverInto {
impl_lint_pass!(FromOverInto => [FROM_OVER_INTO]);
impl<'tcx> LateLintPass<'tcx> for FromOverInto {
- fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
- if !meets_msrv(self.msrv, msrvs::RE_REBALANCING_COHERENCE) {
+ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
+ if !meets_msrv(self.msrv, msrvs::RE_REBALANCING_COHERENCE) || !span_is_local(item.span) {
return;
}
- if_chain! {
- if let hir::ItemKind::Impl{ .. } = &item.kind;
- if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(item.def_id);
- if cx.tcx.is_diagnostic_item(sym::Into, impl_trait_ref.def_id);
-
- then {
- span_lint_and_help(
- cx,
- FROM_OVER_INTO,
- cx.tcx.sess.source_map().guess_head_span(item.span),
- "an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true",
- None,
- &format!("consider to implement `From<{}>` instead", impl_trait_ref.self_ty()),
- );
- }
+ if let ItemKind::Impl(Impl {
+ of_trait: Some(hir_trait_ref),
+ self_ty,
+ items: [impl_item_ref],
+ ..
+ }) = item.kind
+ && let Some(into_trait_seg) = hir_trait_ref.path.segments.last()
+ // `impl Into<target_ty> for self_ty`
+ && let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args
+ && let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
+ && cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
+ {
+ span_lint_and_then(
+ cx,
+ FROM_OVER_INTO,
+ cx.tcx.sess.source_map().guess_head_span(item.span),
+ "an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true",
+ |diag| {
+ // If the target type is likely foreign mention the orphan rules as it's a common source of confusion
+ if path_def_id(cx, target_ty.peel_refs()).map_or(true, |id| !id.is_local()) {
+ diag.help(
+ "`impl From<Local> for Foreign` is allowed by the orphan rules, for more information see\n\
+ https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence"
+ );
+ }
+
+ let message = format!("replace the `Into` implentation with `From<{}>`", middle_trait_ref.self_ty());
+ if let Some(suggestions) = convert_to_from(cx, into_trait_seg, target_ty, self_ty, impl_item_ref) {
+ diag.multipart_suggestion(message, suggestions, Applicability::MachineApplicable);
+ } else {
+ diag.help(message);
+ }
+ },
+ );
}
}
extract_msrv_attr!(LateContext);
}
+
+/// Finds the occurences of `Self` and `self`
+struct SelfFinder<'a, 'tcx> {
+ cx: &'a LateContext<'tcx>,
+ /// Occurences of `Self`
+ upper: Vec<Span>,
+ /// Occurences of `self`
+ lower: Vec<Span>,
+ /// If any of the `self`/`Self` usages were from an expansion, or the body contained a binding
+ /// already named `val`
+ invalid: bool,
+}
+
+impl<'a, 'tcx> Visitor<'tcx> for SelfFinder<'a, 'tcx> {
+ type NestedFilter = OnlyBodies;
+
+ fn nested_visit_map(&mut self) -> Self::Map {
+ self.cx.tcx.hir()
+ }
+
+ fn visit_path(&mut self, path: &'tcx Path<'tcx>, _id: HirId) {
+ for segment in path.segments {
+ match segment.ident.name {
+ kw::SelfLower => self.lower.push(segment.ident.span),
+ kw::SelfUpper => self.upper.push(segment.ident.span),
+ _ => continue,
+ }
+ }
+
+ self.invalid |= path.span.from_expansion();
+ if !self.invalid {
+ walk_path(self, path);
+ }
+ }
+
+ fn visit_name(&mut self, name: Symbol) {
+ if name == sym::val {
+ self.invalid = true;
+ }
+ }
+}
+
+fn convert_to_from(
+ cx: &LateContext<'_>,
+ into_trait_seg: &PathSegment<'_>,
+ target_ty: &Ty<'_>,
+ self_ty: &Ty<'_>,
+ impl_item_ref: &ImplItemRef,
+) -> Option<Vec<(Span, String)>> {
+ let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id);
+ let ImplItemKind::Fn(ref sig, body_id) = impl_item.kind else { return None };
+ let body = cx.tcx.hir().body(body_id);
+ let [input] = body.params else { return None };
+ let PatKind::Binding(.., self_ident, None) = input.pat.kind else { return None };
+
+ let from = snippet_opt(cx, self_ty.span)?;
+ let into = snippet_opt(cx, target_ty.span)?;
+
+ let mut suggestions = vec![
+ // impl Into<T> for U -> impl From<T> for U
+ // ~~~~ ~~~~
+ (into_trait_seg.ident.span, String::from("From")),
+ // impl Into<T> for U -> impl Into<U> for U
+ // ~ ~
+ (target_ty.span, from.clone()),
+ // impl Into<T> for U -> impl Into<T> for T
+ // ~ ~
+ (self_ty.span, into),
+ // fn into(self) -> T -> fn from(self) -> T
+ // ~~~~ ~~~~
+ (impl_item.ident.span, String::from("from")),
+ // fn into([mut] self) -> T -> fn into([mut] v: T) -> T
+ // ~~~~ ~~~~
+ (self_ident.span, format!("val: {from}")),
+ // fn into(self) -> T -> fn into(self) -> Self
+ // ~ ~~~~
+ (sig.decl.output.span(), String::from("Self")),
+ ];
+
+ let mut finder = SelfFinder {
+ cx,
+ upper: Vec::new(),
+ lower: Vec::new(),
+ invalid: false,
+ };
+ finder.visit_expr(body.value);
+
+ if finder.invalid {
+ return None;
+ }
+
+ // don't try to replace e.g. `Self::default()` with `&[T]::default()`
+ if !finder.upper.is_empty() && !matches!(self_ty.kind, TyKind::Path(_)) {
+ return None;
+ }
+
+ for span in finder.upper {
+ suggestions.push((span, from.clone()));
+ }
+ for span in finder.lower {
+ suggestions.push((span, String::from("val")));
+ }
+
+ Some(suggestions)
+}
diff --git a/src/tools/clippy/clippy_lints/src/from_str_radix_10.rs b/src/tools/clippy/clippy_lints/src/from_str_radix_10.rs
index 74941d817..cf8b7acd6 100644
--- a/src/tools/clippy/clippy_lints/src/from_str_radix_10.rs
+++ b/src/tools/clippy/clippy_lints/src/from_str_radix_10.rs
@@ -1,4 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::is_integer_literal;
use clippy_utils::sugg::Sugg;
use clippy_utils::ty::is_type_diagnostic_item;
use if_chain::if_chain;
@@ -60,8 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for FromStrRadix10 {
if pathseg.ident.name.as_str() == "from_str_radix";
// check if the second argument is a primitive `10`
- if let ExprKind::Lit(lit) = &radix.kind;
- if let rustc_ast::ast::LitKind::Int(10, _) = lit.node;
+ if is_integer_literal(radix, 10);
then {
let expr = if let ExprKind::AddrOf(_, _, expr) = &src.kind {
@@ -88,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for FromStrRadix10 {
exp.span,
"this call to `from_str_radix` can be replaced with a call to `str::parse`",
"try",
- format!("{}.parse::<{}>()", sugg, prim_ty.name_str()),
+ format!("{sugg}.parse::<{}>()", prim_ty.name_str()),
Applicability::MaybeIncorrect
);
}
diff --git a/src/tools/clippy/clippy_lints/src/functions/must_use.rs b/src/tools/clippy/clippy_lints/src/functions/must_use.rs
index 00a493776..bff69f915 100644
--- a/src/tools/clippy/clippy_lints/src/functions/must_use.rs
+++ b/src/tools/clippy/clippy_lints/src/functions/must_use.rs
@@ -1,27 +1,30 @@
use rustc_ast::ast::Attribute;
use rustc_errors::Applicability;
use rustc_hir::def_id::{DefIdSet, LocalDefId};
-use rustc_hir::{self as hir, def::Res, intravisit, QPath};
+use rustc_hir::{self as hir, def::Res, QPath};
use rustc_lint::{LateContext, LintContext};
use rustc_middle::{
lint::in_external_macro,
ty::{self, Ty},
};
-use rustc_span::{sym, Span};
+use rustc_span::{sym, Span, Symbol};
use clippy_utils::attrs::is_proc_macro;
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::is_must_use_ty;
-use clippy_utils::{match_def_path, return_ty, trait_ref_of_method};
+use clippy_utils::visitors::for_each_expr;
+use clippy_utils::{return_ty, trait_ref_of_method};
+
+use core::ops::ControlFlow;
use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT};
pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
let attrs = cx.tcx.hir().attrs(item.hir_id());
- let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use);
+ let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use);
if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind {
- let is_public = cx.access_levels.is_exported(item.def_id);
+ let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
if let Some(attr) = attr {
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
@@ -31,7 +34,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
sig.decl,
cx.tcx.hir().body(*body_id),
item.span,
- item.def_id,
+ item.owner_id.def_id,
item.span.with_hi(sig.decl.output.span().hi()),
"this function could have a `#[must_use]` attribute",
);
@@ -41,19 +44,20 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind {
- let is_public = cx.access_levels.is_exported(item.def_id);
+ let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
let attrs = cx.tcx.hir().attrs(item.hir_id());
- let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use);
+ let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use);
if let Some(attr) = attr {
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
- } else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.def_id).is_none() {
+ } else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.owner_id.def_id).is_none()
+ {
check_must_use_candidate(
cx,
sig.decl,
cx.tcx.hir().body(*body_id),
item.span,
- item.def_id,
+ item.owner_id.def_id,
item.span.with_hi(sig.decl.output.span().hi()),
"this method could have a `#[must_use]` attribute",
);
@@ -63,11 +67,11 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind {
- let is_public = cx.access_levels.is_exported(item.def_id);
+ let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
let attrs = cx.tcx.hir().attrs(item.hir_id());
- let attr = cx.tcx.get_attr(item.def_id.to_def_id(), sym::must_use);
+ let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use);
if let Some(attr) = attr {
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
} else if let hir::TraitFn::Provided(eid) = *eid {
@@ -78,7 +82,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr
sig.decl,
body,
item.span,
- item.def_id,
+ item.owner_id.def_id,
item.span.with_hi(sig.decl.output.span().hi()),
"this method could have a `#[must_use]` attribute",
);
@@ -133,7 +137,7 @@ fn check_must_use_candidate<'tcx>(
|| mutates_static(cx, body)
|| in_external_macro(cx.sess(), item_span)
|| returns_unit(decl)
- || !cx.access_levels.is_exported(item_id)
+ || !cx.effective_visibilities.is_exported(item_id)
|| is_must_use_ty(cx, return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(item_id)))
{
return;
@@ -143,7 +147,7 @@ fn check_must_use_candidate<'tcx>(
diag.span_suggestion(
fn_span,
"add the attribute",
- format!("#[must_use] {}", snippet),
+ format!("#[must_use] {snippet}"),
Applicability::MachineApplicable,
);
}
@@ -171,21 +175,23 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut DefIdSet)
return false; // ignore `_` patterns
}
if cx.tcx.has_typeck_results(pat.hir_id.owner.to_def_id()) {
- is_mutable_ty(cx, cx.tcx.typeck(pat.hir_id.owner).pat_ty(pat), pat.span, tys)
+ is_mutable_ty(cx, cx.tcx.typeck(pat.hir_id.owner.def_id).pat_ty(pat), pat.span, tys)
} else {
false
}
}
-static KNOWN_WRAPPER_TYS: &[&[&str]] = &[&["alloc", "rc", "Rc"], &["std", "sync", "Arc"]];
+static KNOWN_WRAPPER_TYS: &[Symbol] = &[sym::Rc, sym::Arc];
fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, tys: &mut DefIdSet) -> bool {
match *ty.kind() {
// primitive types are never mutable
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false,
ty::Adt(adt, substs) => {
- tys.insert(adt.did()) && !ty.is_freeze(cx.tcx.at(span), cx.param_env)
- || KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did(), path))
+ tys.insert(adt.did()) && !ty.is_freeze(cx.tcx, cx.param_env)
+ || KNOWN_WRAPPER_TYS
+ .iter()
+ .any(|&sym| cx.tcx.is_diagnostic_item(sym, adt.did()))
&& substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys))
},
ty::Tuple(substs) => substs.iter().any(|ty| is_mutable_ty(cx, ty, span, tys)),
@@ -199,79 +205,65 @@ fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, tys: &m
}
}
-struct StaticMutVisitor<'a, 'tcx> {
- cx: &'a LateContext<'tcx>,
- mutates_static: bool,
+fn is_mutated_static(e: &hir::Expr<'_>) -> bool {
+ use hir::ExprKind::{Field, Index, Path};
+
+ match e.kind {
+ Path(QPath::Resolved(_, path)) => !matches!(path.res, Res::Local(_)),
+ Path(_) => true,
+ Field(inner, _) | Index(inner, _) => is_mutated_static(inner),
+ _ => false,
+ }
}
-impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
- fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
+fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bool {
+ for_each_expr(body.value, |e| {
use hir::ExprKind::{AddrOf, Assign, AssignOp, Call, MethodCall};
- if self.mutates_static {
- return;
- }
- match expr.kind {
+ match e.kind {
Call(_, args) => {
let mut tys = DefIdSet::default();
for arg in args {
- if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
+ if cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
&& is_mutable_ty(
- self.cx,
- self.cx.tcx.typeck(arg.hir_id.owner).expr_ty(arg),
+ cx,
+ cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg),
arg.span,
&mut tys,
)
&& is_mutated_static(arg)
{
- self.mutates_static = true;
- return;
+ return ControlFlow::Break(());
}
tys.clear();
}
+ ControlFlow::Continue(())
},
MethodCall(_, receiver, args, _) => {
let mut tys = DefIdSet::default();
for arg in std::iter::once(receiver).chain(args.iter()) {
- if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
+ if cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
&& is_mutable_ty(
- self.cx,
- self.cx.tcx.typeck(arg.hir_id.owner).expr_ty(arg),
+ cx,
+ cx.tcx.typeck(arg.hir_id.owner.def_id).expr_ty(arg),
arg.span,
&mut tys,
)
&& is_mutated_static(arg)
{
- self.mutates_static = true;
- return;
+ return ControlFlow::Break(());
}
tys.clear();
}
+ ControlFlow::Continue(())
},
- Assign(target, ..) | AssignOp(_, target, _) | AddrOf(_, hir::Mutability::Mut, target) => {
- self.mutates_static |= is_mutated_static(target);
+ Assign(target, ..) | AssignOp(_, target, _) | AddrOf(_, hir::Mutability::Mut, target)
+ if is_mutated_static(target) =>
+ {
+ ControlFlow::Break(())
},
- _ => {},
+ _ => ControlFlow::Continue(()),
}
- }
-}
-
-fn is_mutated_static(e: &hir::Expr<'_>) -> bool {
- use hir::ExprKind::{Field, Index, Path};
-
- match e.kind {
- Path(QPath::Resolved(_, path)) => !matches!(path.res, Res::Local(_)),
- Path(_) => true,
- Field(inner, _) | Index(inner, _) => is_mutated_static(inner),
- _ => false,
- }
-}
-
-fn mutates_static<'tcx>(cx: &LateContext<'tcx>, body: &'tcx hir::Body<'_>) -> bool {
- let mut v = StaticMutVisitor {
- cx,
- mutates_static: false,
- };
- intravisit::walk_expr(&mut v, body.value);
- v.mutates_static
+ })
+ .is_some()
}
diff --git a/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs
index 3bbfa52e8..2c0bf551f 100644
--- a/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs
+++ b/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs
@@ -5,8 +5,11 @@ use rustc_span::def_id::LocalDefId;
use clippy_utils::diagnostics::span_lint;
use clippy_utils::ty::type_is_unsafe_function;
+use clippy_utils::visitors::for_each_expr_with_closures;
use clippy_utils::{iter_input_pats, path_to_local};
+use core::ops::ControlFlow;
+
use super::NOT_UNSAFE_PTR_ARG_DEREF;
pub(super) fn check_fn<'tcx>(
@@ -28,7 +31,7 @@ pub(super) fn check_fn<'tcx>(
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind {
let body = cx.tcx.hir().body(eid);
- check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.def_id);
+ check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.owner_id.def_id);
}
}
@@ -39,21 +42,34 @@ fn check_raw_ptr<'tcx>(
body: &'tcx hir::Body<'tcx>,
def_id: LocalDefId,
) {
- let expr = &body.value;
- if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(def_id) {
+ if unsafety == hir::Unsafety::Normal && cx.effective_visibilities.is_exported(def_id) {
let raw_ptrs = iter_input_pats(decl, body)
.filter_map(|arg| raw_ptr_arg(cx, arg))
.collect::<HirIdSet>();
if !raw_ptrs.is_empty() {
- let typeck_results = cx.tcx.typeck_body(body.id());
- let mut v = DerefVisitor {
- cx,
- ptrs: raw_ptrs,
- typeck_results,
- };
-
- intravisit::walk_expr(&mut v, expr);
+ let typeck = cx.tcx.typeck_body(body.id());
+ let _: Option<!> = for_each_expr_with_closures(cx, body.value, |e| {
+ match e.kind {
+ hir::ExprKind::Call(f, args) if type_is_unsafe_function(cx, typeck.expr_ty(f)) => {
+ for arg in args {
+ check_arg(cx, &raw_ptrs, arg);
+ }
+ },
+ hir::ExprKind::MethodCall(_, recv, args, _) => {
+ let def_id = typeck.type_dependent_def_id(e.hir_id).unwrap();
+ if cx.tcx.fn_sig(def_id).skip_binder().unsafety == hir::Unsafety::Unsafe {
+ check_arg(cx, &raw_ptrs, recv);
+ for arg in args {
+ check_arg(cx, &raw_ptrs, arg);
+ }
+ }
+ },
+ hir::ExprKind::Unary(hir::UnOp::Deref, ptr) => check_arg(cx, &raw_ptrs, ptr),
+ _ => (),
+ }
+ ControlFlow::Continue(())
+ });
}
}
}
@@ -70,54 +86,13 @@ fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<hir::HirId>
}
}
-struct DerefVisitor<'a, 'tcx> {
- cx: &'a LateContext<'tcx>,
- ptrs: HirIdSet,
- typeck_results: &'a ty::TypeckResults<'tcx>,
-}
-
-impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
- fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
- match expr.kind {
- hir::ExprKind::Call(f, args) => {
- let ty = self.typeck_results.expr_ty(f);
-
- if type_is_unsafe_function(self.cx, ty) {
- for arg in args {
- self.check_arg(arg);
- }
- }
- },
- hir::ExprKind::MethodCall(_, receiver, args, _) => {
- let def_id = self.typeck_results.type_dependent_def_id(expr.hir_id).unwrap();
- let base_type = self.cx.tcx.type_of(def_id);
-
- if type_is_unsafe_function(self.cx, base_type) {
- self.check_arg(receiver);
- for arg in args {
- self.check_arg(arg);
- }
- }
- },
- hir::ExprKind::Unary(hir::UnOp::Deref, ptr) => self.check_arg(ptr),
- _ => (),
- }
-
- intravisit::walk_expr(self, expr);
- }
-}
-
-impl<'a, 'tcx> DerefVisitor<'a, 'tcx> {
- fn check_arg(&self, ptr: &hir::Expr<'_>) {
- if let Some(id) = path_to_local(ptr) {
- if self.ptrs.contains(&id) {
- span_lint(
- self.cx,
- NOT_UNSAFE_PTR_ARG_DEREF,
- ptr.span,
- "this public function might dereference a raw pointer but is not marked `unsafe`",
- );
- }
- }
+fn check_arg(cx: &LateContext<'_>, raw_ptrs: &HirIdSet, arg: &hir::Expr<'_>) {
+ if path_to_local(arg).map_or(false, |id| raw_ptrs.contains(&id)) {
+ span_lint(
+ cx,
+ NOT_UNSAFE_PTR_ARG_DEREF,
+ arg.span,
+ "this public function might dereference a raw pointer but is not marked `unsafe`",
+ );
}
}
diff --git a/src/tools/clippy/clippy_lints/src/functions/result.rs b/src/tools/clippy/clippy_lints/src/functions/result.rs
index 9591405cb..5c63fb2ac 100644
--- a/src/tools/clippy/clippy_lints/src/functions/result.rs
+++ b/src/tools/clippy/clippy_lints/src/functions/result.rs
@@ -34,9 +34,9 @@ fn result_err_ty<'tcx>(
pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, large_err_threshold: u64) {
if let hir::ItemKind::Fn(ref sig, _generics, _) = item.kind
- && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span)
+ && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.owner_id.def_id, item.span)
{
- if cx.access_levels.is_exported(item.def_id) {
+ if cx.effective_visibilities.is_exported(item.owner_id.def_id) {
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
check_result_unit_err(cx, err_ty, fn_header_span);
}
@@ -47,10 +47,10 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, l
pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem<'tcx>, large_err_threshold: u64) {
// Don't lint if method is a trait's implementation, we can't do anything about those
if let hir::ImplItemKind::Fn(ref sig, _) = item.kind
- && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span)
- && trait_ref_of_method(cx, item.def_id).is_none()
+ && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.owner_id.def_id, item.span)
+ && trait_ref_of_method(cx, item.owner_id.def_id).is_none()
{
- if cx.access_levels.is_exported(item.def_id) {
+ if cx.effective_visibilities.is_exported(item.owner_id.def_id) {
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
check_result_unit_err(cx, err_ty, fn_header_span);
}
@@ -61,8 +61,8 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::TraitItem<'tcx>, large_err_threshold: u64) {
if let hir::TraitItemKind::Fn(ref sig, _) = item.kind {
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
- if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span) {
- if cx.access_levels.is_exported(item.def_id) {
+ if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.owner_id.def_id, item.span) {
+ if cx.effective_visibilities.is_exported(item.owner_id.def_id) {
check_result_unit_err(cx, err_ty, fn_header_span);
}
check_result_large_err(cx, err_ty, hir_ty.span, large_err_threshold);
diff --git a/src/tools/clippy/clippy_lints/src/functions/too_many_arguments.rs b/src/tools/clippy/clippy_lints/src/functions/too_many_arguments.rs
index 5c8d8b8e7..1e08922a6 100644
--- a/src/tools/clippy/clippy_lints/src/functions/too_many_arguments.rs
+++ b/src/tools/clippy/clippy_lints/src/functions/too_many_arguments.rs
@@ -59,10 +59,7 @@ fn check_arg_number(cx: &LateContext<'_>, decl: &hir::FnDecl<'_>, fn_span: Span,
cx,
TOO_MANY_ARGUMENTS,
fn_span,
- &format!(
- "this function has too many arguments ({}/{})",
- args, too_many_arguments_threshold
- ),
+ &format!("this function has too many arguments ({args}/{too_many_arguments_threshold})"),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/functions/too_many_lines.rs b/src/tools/clippy/clippy_lints/src/functions/too_many_lines.rs
index 54bdea7ea..bd473ac7e 100644
--- a/src/tools/clippy/clippy_lints/src/functions/too_many_lines.rs
+++ b/src/tools/clippy/clippy_lints/src/functions/too_many_lines.rs
@@ -22,9 +22,8 @@ pub(super) fn check_fn(
return;
}
- let code_snippet = match snippet_opt(cx, body.value.span) {
- Some(s) => s,
- _ => return,
+ let Some(code_snippet) = snippet_opt(cx, body.value.span) else {
+ return
};
let mut line_count: u64 = 0;
let mut in_comment = false;
@@ -78,10 +77,7 @@ pub(super) fn check_fn(
cx,
TOO_MANY_LINES,
span,
- &format!(
- "this function has too many lines ({}/{})",
- line_count, too_many_lines_threshold
- ),
+ &format!("this function has too many lines ({line_count}/{too_many_lines_threshold})"),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs
index ef7d75aa8..0519f9ac2 100644
--- a/src/tools/clippy/clippy_lints/src/future_not_send.rs
+++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs
@@ -4,11 +4,10 @@ use rustc_hir::intravisit::FnKind;
use rustc_hir::{Body, FnDecl, HirId};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass};
-use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{EarlyBinder, Opaque, PredicateKind::Trait};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{sym, Span};
-use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt;
+use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
use rustc_trait_selection::traits::{self, FulfillmentError};
declare_clippy_lint! {
@@ -78,10 +77,9 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
if is_future {
let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap();
let span = decl.output.span();
- let send_errors = cx.tcx.infer_ctxt().enter(|infcx| {
- let cause = traits::ObligationCause::misc(span, hir_id);
- traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait)
- });
+ let infcx = cx.tcx.infer_ctxt().build();
+ let cause = traits::ObligationCause::misc(span, hir_id);
+ let send_errors = traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait);
if !send_errors.is_empty() {
span_lint_and_then(
cx,
@@ -89,18 +87,18 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
span,
"future cannot be sent between threads safely",
|db| {
- cx.tcx.infer_ctxt().enter(|infcx| {
- for FulfillmentError { obligation, .. } in send_errors {
- infcx.maybe_note_obligation_cause_for_async_await(db, &obligation);
- if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() {
- db.note(&format!(
- "`{}` doesn't implement `{}`",
- trait_pred.self_ty(),
- trait_pred.trait_ref.print_only_trait_path(),
- ));
- }
+ for FulfillmentError { obligation, .. } in send_errors {
+ infcx
+ .err_ctxt()
+ .maybe_note_obligation_cause_for_async_await(db, &obligation);
+ if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() {
+ db.note(&format!(
+ "`{}` doesn't implement `{}`",
+ trait_pred.self_ty(),
+ trait_pred.trait_ref.print_only_trait_path(),
+ ));
}
- });
+ }
},
);
}
diff --git a/src/tools/clippy/clippy_lints/src/if_then_some_else_none.rs b/src/tools/clippy/clippy_lints/src/if_then_some_else_none.rs
index 11c432478..0d6718c16 100644
--- a/src/tools/clippy/clippy_lints/src/if_then_some_else_none.rs
+++ b/src/tools/clippy/clippy_lints/src/if_then_some_else_none.rs
@@ -1,7 +1,9 @@
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::eager_or_lazy::switch_to_eager_eval;
use clippy_utils::source::snippet_with_macro_callsite;
-use clippy_utils::{contains_return, higher, is_else_clause, is_lang_ctor, meets_msrv, msrvs, peel_blocks};
+use clippy_utils::{
+ contains_return, higher, is_else_clause, is_res_lang_ctor, meets_msrv, msrvs, path_res, peel_blocks,
+};
use rustc_hir::LangItem::{OptionNone, OptionSome};
use rustc_hir::{Expr, ExprKind, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass, LintContext};
@@ -76,15 +78,13 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone {
&& let ExprKind::Block(then_block, _) = then.kind
&& let Some(then_expr) = then_block.expr
&& let ExprKind::Call(then_call, [then_arg]) = then_expr.kind
- && let ExprKind::Path(ref then_call_qpath) = then_call.kind
- && is_lang_ctor(cx, then_call_qpath, OptionSome)
- && let ExprKind::Path(ref qpath) = peel_blocks(els).kind
- && is_lang_ctor(cx, qpath, OptionNone)
+ && is_res_lang_ctor(cx, path_res(cx, then_call), OptionSome)
+ && is_res_lang_ctor(cx, path_res(cx, peel_blocks(els)), OptionNone)
&& !stmts_contains_early_return(then_block.stmts)
{
let cond_snip = snippet_with_macro_callsite(cx, cond.span, "[condition]");
let cond_snip = if matches!(cond.kind, ExprKind::Unary(_, _) | ExprKind::Binary(_, _, _)) {
- format!("({})", cond_snip)
+ format!("({cond_snip})")
} else {
cond_snip.into_owned()
};
@@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone {
let mut method_body = if then_block.stmts.is_empty() {
arg_snip.into_owned()
} else {
- format!("{{ /* snippet */ {} }}", arg_snip)
+ format!("{{ /* snippet */ {arg_snip} }}")
};
let method_name = if switch_to_eager_eval(cx, expr) && meets_msrv(self.msrv, msrvs::BOOL_THEN_SOME) {
"then_some"
@@ -102,14 +102,13 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone {
};
let help = format!(
- "consider using `bool::{}` like: `{}.{}({})`",
- method_name, cond_snip, method_name, method_body,
+ "consider using `bool::{method_name}` like: `{cond_snip}.{method_name}({method_body})`",
);
span_lint_and_help(
cx,
IF_THEN_SOME_ELSE_NONE,
expr.span,
- &format!("this could be simplified with `bool::{}`", method_name),
+ &format!("this could be simplified with `bool::{method_name}`"),
None,
&help,
);
diff --git a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs
index 4f9680f60..94e06cf70 100644
--- a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs
+++ b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs
@@ -5,6 +5,7 @@ use rustc_errors::Diagnostic;
use rustc_hir as hir;
use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, Visitor};
use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind};
+use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::hir::nested_filter;
use rustc_middle::lint::in_external_macro;
@@ -12,7 +13,6 @@ use rustc_middle::ty::{Ty, TypeckResults};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;
use rustc_span::symbol::sym;
-use rustc_typeck::hir_ty_to_ty;
use if_chain::if_chain;
@@ -89,8 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
(
generics_suggestion_span,
format!(
- "<{}{}S: ::std::hash::BuildHasher{}>",
- generics_snip,
+ "<{generics_snip}{}S: ::std::hash::BuildHasher{}>",
if generics_snip.is_empty() { "" } else { ", " },
if vis.suggestions.is_empty() {
""
@@ -112,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
}
}
- if !cx.access_levels.is_exported(item.def_id) {
+ if !cx.effective_visibilities.is_exported(item.owner_id.def_id) {
return;
}
@@ -263,8 +262,8 @@ impl<'tcx> ImplicitHasherType<'tcx> {
fn type_arguments(&self) -> String {
match *self {
- ImplicitHasherType::HashMap(.., ref k, ref v) => format!("{}, {}", k, v),
- ImplicitHasherType::HashSet(.., ref t) => format!("{}", t),
+ ImplicitHasherType::HashMap(.., ref k, ref v) => format!("{k}, {v}"),
+ ImplicitHasherType::HashSet(.., ref t) => format!("{t}"),
}
}
diff --git a/src/tools/clippy/clippy_lints/src/implicit_return.rs b/src/tools/clippy/clippy_lints/src/implicit_return.rs
index feec8ec2e..946d04eff 100644
--- a/src/tools/clippy/clippy_lints/src/implicit_return.rs
+++ b/src/tools/clippy/clippy_lints/src/implicit_return.rs
@@ -2,10 +2,11 @@ use clippy_utils::{
diagnostics::span_lint_hir_and_then,
get_async_fn_body, is_async_fn,
source::{snippet_with_applicability, snippet_with_context, walk_span_to_context},
- visitors::expr_visitor_no_bodies,
+ visitors::for_each_expr,
};
+use core::ops::ControlFlow;
use rustc_errors::Applicability;
-use rustc_hir::intravisit::{FnKind, Visitor};
+use rustc_hir::intravisit::FnKind;
use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, FnRetTy, HirId};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
@@ -53,7 +54,7 @@ fn lint_return(cx: &LateContext<'_>, emission_place: HirId, span: Span) {
span,
"missing `return` statement",
|diag| {
- diag.span_suggestion(span, "add `return` as shown", format!("return {}", snip), app);
+ diag.span_suggestion(span, "add `return` as shown", format!("return {snip}"), app);
},
);
}
@@ -71,7 +72,7 @@ fn lint_break(cx: &LateContext<'_>, emission_place: HirId, break_span: Span, exp
diag.span_suggestion(
break_span,
"change `break` to `return` as shown",
- format!("return {}", snip),
+ format!("return {snip}"),
app,
);
},
@@ -152,7 +153,7 @@ fn lint_implicit_returns(
ExprKind::Loop(block, ..) => {
let mut add_return = false;
- expr_visitor_no_bodies(|e| {
+ let _: Option<!> = for_each_expr(block, |e| {
if let ExprKind::Break(dest, sub_expr) = e.kind {
if dest.target_id.ok() == Some(expr.hir_id) {
if call_site_span.is_none() && e.span.ctxt() == ctxt {
@@ -167,9 +168,8 @@ fn lint_implicit_returns(
}
}
}
- true
- })
- .visit_block(block);
+ ControlFlow::Continue(())
+ });
if add_return {
#[expect(clippy::option_if_let_else)]
if let Some(span) = call_site_span {
diff --git a/src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs b/src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs
new file mode 100644
index 000000000..bf1351829
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs
@@ -0,0 +1,114 @@
+use clippy_utils::consts::{constant, Constant};
+use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::get_parent_expr;
+use clippy_utils::source::snippet_with_applicability;
+use if_chain::if_chain;
+use rustc_ast::ast::{LitIntType, LitKind};
+use rustc_errors::Applicability;
+use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind};
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::ty::{Int, IntTy, Ty, Uint, UintTy};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for implicit saturating addition.
+ ///
+ /// ### Why is this bad?
+ /// The built-in function is more readable and may be faster.
+ ///
+ /// ### Example
+ /// ```rust
+ ///let mut u:u32 = 7000;
+ ///
+ /// if u != u32::MAX {
+ /// u += 1;
+ /// }
+ /// ```
+ /// Use instead:
+ /// ```rust
+ ///let mut u:u32 = 7000;
+ ///
+ /// u = u.saturating_add(1);
+ /// ```
+ #[clippy::version = "1.65.0"]
+ pub IMPLICIT_SATURATING_ADD,
+ style,
+ "Perform saturating addition instead of implicitly checking max bound of data type"
+}
+declare_lint_pass!(ImplicitSaturatingAdd => [IMPLICIT_SATURATING_ADD]);
+
+impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd {
+ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
+ if_chain! {
+ if let ExprKind::If(cond, then, None) = expr.kind;
+ if let ExprKind::DropTemps(expr1) = cond.kind;
+ if let Some((c, op_node, l)) = get_const(cx, expr1);
+ if let BinOpKind::Ne | BinOpKind::Lt = op_node;
+ if let ExprKind::Block(block, None) = then.kind;
+ if let Block {
+ stmts:
+ [Stmt
+ { kind: StmtKind::Expr(ex) | StmtKind::Semi(ex), .. }],
+ expr: None, ..} |
+ Block { stmts: [], expr: Some(ex), ..} = block;
+ if let ExprKind::AssignOp(op1, target, value) = ex.kind;
+ let ty = cx.typeck_results().expr_ty(target);
+ if Some(c) == get_int_max(ty);
+ if clippy_utils::SpanlessEq::new(cx).eq_expr(l, target);
+ if BinOpKind::Add == op1.node;
+ if let ExprKind::Lit(ref lit) = value.kind;
+ if let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node;
+ if block.expr.is_none();
+ then {
+ let mut app = Applicability::MachineApplicable;
+ let code = snippet_with_applicability(cx, target.span, "_", &mut app);
+ let sugg = if let Some(parent) = get_parent_expr(cx, expr) && let ExprKind::If(_cond, _then, Some(else_)) = parent.kind && else_.hir_id == expr.hir_id {format!("{{{code} = {code}.saturating_add(1); }}")} else {format!("{code} = {code}.saturating_add(1);")};
+ span_lint_and_sugg(cx, IMPLICIT_SATURATING_ADD, expr.span, "manual saturating add detected", "use instead", sugg, app);
+ }
+ }
+ }
+}
+
+fn get_int_max(ty: Ty<'_>) -> Option<u128> {
+ match ty.peel_refs().kind() {
+ Int(IntTy::I8) => i8::max_value().try_into().ok(),
+ Int(IntTy::I16) => i16::max_value().try_into().ok(),
+ Int(IntTy::I32) => i32::max_value().try_into().ok(),
+ Int(IntTy::I64) => i64::max_value().try_into().ok(),
+ Int(IntTy::I128) => i128::max_value().try_into().ok(),
+ Int(IntTy::Isize) => isize::max_value().try_into().ok(),
+ Uint(UintTy::U8) => u8::max_value().try_into().ok(),
+ Uint(UintTy::U16) => u16::max_value().try_into().ok(),
+ Uint(UintTy::U32) => u32::max_value().try_into().ok(),
+ Uint(UintTy::U64) => u64::max_value().try_into().ok(),
+ Uint(UintTy::U128) => Some(u128::max_value()),
+ Uint(UintTy::Usize) => usize::max_value().try_into().ok(),
+ _ => None,
+ }
+}
+
+fn get_const<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> Option<(u128, BinOpKind, &'tcx Expr<'tcx>)> {
+ if let ExprKind::Binary(op, l, r) = expr.kind {
+ let tr = cx.typeck_results();
+ if let Some((Constant::Int(c), _)) = constant(cx, tr, r) {
+ return Some((c, op.node, l));
+ };
+ if let Some((Constant::Int(c), _)) = constant(cx, tr, l) {
+ return Some((c, invert_op(op.node)?, r));
+ }
+ }
+ None
+}
+
+fn invert_op(op: BinOpKind) -> Option<BinOpKind> {
+ use rustc_hir::BinOpKind::{Ge, Gt, Le, Lt, Ne};
+ match op {
+ Lt => Some(Gt),
+ Le => Some(Ge),
+ Ne => Some(Ne),
+ Ge => Some(Le),
+ Gt => Some(Lt),
+ _ => None,
+ }
+}
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 46654bc61..29d59c26d 100644
--- a/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs
+++ b/src/tools/clippy/clippy_lints/src/implicit_saturating_sub.rs
@@ -1,5 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
-use clippy_utils::{higher, peel_blocks_with_stmt, SpanlessEq};
+use clippy_utils::{higher, is_integer_literal, peel_blocks_with_stmt, SpanlessEq};
use if_chain::if_chain;
use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
@@ -35,7 +35,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.44.0"]
pub IMPLICIT_SATURATING_SUB,
- pedantic,
+ style,
"Perform saturating subtraction instead of implicitly checking lower bound of data type"
}
@@ -131,17 +131,8 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
fn subtracts_one<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<&'a Expr<'a>> {
match peel_blocks_with_stmt(expr).kind {
ExprKind::AssignOp(ref op1, target, value) => {
- if_chain! {
- if BinOpKind::Sub == op1.node;
- // Check if literal being subtracted is one
- if let ExprKind::Lit(ref lit1) = value.kind;
- if let LitKind::Int(1, _) = lit1.node;
- then {
- Some(target)
- } else {
- None
- }
- }
+ // Check if literal being subtracted is one
+ (BinOpKind::Sub == op1.node && is_integer_literal(value, 1)).then_some(target)
},
ExprKind::Assign(target, value, _) => {
if_chain! {
@@ -150,8 +141,7 @@ fn subtracts_one<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<&'a Exp
if SpanlessEq::new(cx).eq_expr(left1, target);
- if let ExprKind::Lit(ref lit1) = right1.kind;
- if let LitKind::Int(1, _) = lit1.node;
+ if is_integer_literal(right1, 1);
then {
Some(target)
} else {
@@ -170,7 +160,7 @@ fn print_lint_and_sugg(cx: &LateContext<'_>, var_name: &str, expr: &Expr<'_>) {
expr.span,
"implicitly performing saturating subtraction",
"try",
- format!("{} = {}.saturating_sub({});", var_name, var_name, '1'),
+ format!("{var_name} = {var_name}.saturating_sub({});", '1'),
Applicability::MachineApplicable,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs b/src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs
index 14b22d2b5..e2f2d3d42 100644
--- a/src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs
+++ b/src/tools/clippy/clippy_lints/src/inconsistent_struct_constructor.rs
@@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for InconsistentStructConstructor {
let mut fields_snippet = String::new();
let (last_ident, idents) = ordered_fields.split_last().unwrap();
for ident in idents {
- let _ = write!(fields_snippet, "{}, ", ident);
+ let _ = write!(fields_snippet, "{ident}, ");
}
fields_snippet.push_str(&last_ident.to_string());
@@ -100,10 +100,8 @@ impl<'tcx> LateLintPass<'tcx> for InconsistentStructConstructor {
String::new()
};
- let sugg = format!("{} {{ {}{} }}",
+ let sugg = format!("{} {{ {fields_snippet}{base_snippet} }}",
snippet(cx, qpath.span(), ".."),
- fields_snippet,
- base_snippet,
);
span_lint_and_sugg(
diff --git a/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs b/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs
index 0dd7f5bf0..c7b5badaa 100644
--- a/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs
+++ b/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs
@@ -139,14 +139,14 @@ fn lint_slice(cx: &LateContext<'_>, slice: &SliceLintInformation) {
.map(|(index, _)| *index)
.collect::<FxHashSet<_>>();
- let value_name = |index| format!("{}_{}", slice.ident.name, index);
+ let value_name = |index| format!("{}_{index}", slice.ident.name);
if let Some(max_index) = used_indices.iter().max() {
let opt_ref = if slice.needs_ref { "ref " } else { "" };
let pat_sugg_idents = (0..=*max_index)
.map(|index| {
if used_indices.contains(&index) {
- format!("{}{}", opt_ref, value_name(index))
+ format!("{opt_ref}{}", value_name(index))
} else {
"_".to_string()
}
diff --git a/src/tools/clippy/clippy_lints/src/indexing_slicing.rs b/src/tools/clippy/clippy_lints/src/indexing_slicing.rs
index 4a375752e..af40a5a81 100644
--- a/src/tools/clippy/clippy_lints/src/indexing_slicing.rs
+++ b/src/tools/clippy/clippy_lints/src/indexing_slicing.rs
@@ -19,7 +19,6 @@ declare_clippy_lint! {
///
/// ### Example
/// ```rust,no_run
- /// # #![allow(const_err)]
/// let x = [1, 2, 3, 4];
///
/// x[9];
diff --git a/src/tools/clippy/clippy_lints/src/infinite_iter.rs b/src/tools/clippy/clippy_lints/src/infinite_iter.rs
index 8c2c96fa1..d1d2db27c 100644
--- a/src/tools/clippy/clippy_lints/src/infinite_iter.rs
+++ b/src/tools/clippy/clippy_lints/src/infinite_iter.rs
@@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint;
+use clippy_utils::higher;
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
-use clippy_utils::{higher, match_def_path, path_def_id, paths};
use rustc_hir::{BorrowKind, Closure, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -168,9 +168,16 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
},
ExprKind::Block(block, _) => block.expr.as_ref().map_or(Finite, |e| is_infinite(cx, e)),
ExprKind::Box(e) | ExprKind::AddrOf(BorrowKind::Ref, _, e) => is_infinite(cx, e),
- ExprKind::Call(path, _) => path_def_id(cx, path)
- .map_or(false, |id| match_def_path(cx, id, &paths::ITER_REPEAT))
- .into(),
+ ExprKind::Call(path, _) => {
+ if let ExprKind::Path(ref qpath) = path.kind {
+ cx.qpath_res(qpath, path.hir_id)
+ .opt_def_id()
+ .map_or(false, |id| cx.tcx.is_diagnostic_item(sym::iter_repeat, id))
+ .into()
+ } else {
+ Finite
+ }
+ },
ExprKind::Struct(..) => higher::Range::hir(expr).map_or(false, |r| r.end.is_none()).into(),
_ => Finite,
}
diff --git a/src/tools/clippy/clippy_lints/src/inherent_to_string.rs b/src/tools/clippy/clippy_lints/src/inherent_to_string.rs
index 17d867aac..14a37f535 100644
--- a/src/tools/clippy/clippy_lints/src/inherent_to_string.rs
+++ b/src/tools/clippy/clippy_lints/src/inherent_to_string.rs
@@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
-use clippy_utils::{get_trait_def_id, paths, return_ty, trait_ref_of_method};
+use clippy_utils::{return_ty, trait_ref_of_method};
use if_chain::if_chain;
use rustc_hir::{GenericParamKind, ImplItem, ImplItemKind};
use rustc_lint::{LateContext, LateLintPass};
@@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
if is_type_diagnostic_item(cx, return_ty(cx, impl_item.hir_id()), sym::String);
// Filters instances of to_string which are required by a trait
- if trait_ref_of_method(cx, impl_item.def_id).is_none();
+ if trait_ref_of_method(cx, impl_item.owner_id.def_id).is_none();
then {
show_lint(cx, impl_item);
@@ -118,10 +118,13 @@ impl<'tcx> LateLintPass<'tcx> for InherentToString {
}
fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) {
- let display_trait_id = get_trait_def_id(cx, &paths::DISPLAY_TRAIT).expect("Failed to get trait ID of `Display`!");
+ let display_trait_id = cx
+ .tcx
+ .get_diagnostic_item(sym::Display)
+ .expect("Failed to get trait ID of `Display`!");
// Get the real type of 'self'
- let self_type = cx.tcx.fn_sig(item.def_id).input(0);
+ let self_type = cx.tcx.fn_sig(item.owner_id).input(0);
let self_type = self_type.skip_binder().peel_refs();
// Emit either a warning or an error
@@ -131,23 +134,19 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) {
INHERENT_TO_STRING_SHADOW_DISPLAY,
item.span,
&format!(
- "type `{}` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`",
- self_type
+ "type `{self_type}` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`"
),
None,
- &format!("remove the inherent method from type `{}`", self_type),
+ &format!("remove the inherent method from type `{self_type}`"),
);
} else {
span_lint_and_help(
cx,
INHERENT_TO_STRING,
item.span,
- &format!(
- "implementation of inherent method `to_string(&self) -> String` for type `{}`",
- self_type
- ),
+ &format!("implementation of inherent method `to_string(&self) -> String` for type `{self_type}`"),
None,
- &format!("implement trait `Display` for type `{}` instead", self_type),
+ &format!("implement trait `Display` for type `{self_type}` instead"),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/inline_fn_without_body.rs b/src/tools/clippy/clippy_lints/src/inline_fn_without_body.rs
index dd7177e01..d609a5ca4 100644
--- a/src/tools/clippy/clippy_lints/src/inline_fn_without_body.rs
+++ b/src/tools/clippy/clippy_lints/src/inline_fn_without_body.rs
@@ -51,7 +51,7 @@ fn check_attrs(cx: &LateContext<'_>, name: Symbol, attrs: &[Attribute]) {
cx,
INLINE_FN_WITHOUT_BODY,
attr.span,
- &format!("use of `#[inline]` on trait method `{}` which has no body", name),
+ &format!("use of `#[inline]` on trait method `{name}` which has no body"),
|diag| {
diag.suggest_remove_item(cx, attr.span, "remove", Applicability::MachineApplicable);
},
diff --git a/src/tools/clippy/clippy_lints/src/int_plus_one.rs b/src/tools/clippy/clippy_lints/src/int_plus_one.rs
index 9a944def3..33491da3f 100644
--- a/src/tools/clippy/clippy_lints/src/int_plus_one.rs
+++ b/src/tools/clippy/clippy_lints/src/int_plus_one.rs
@@ -138,8 +138,8 @@ impl IntPlusOne {
if let Some(snippet) = snippet_opt(cx, node.span) {
if let Some(other_side_snippet) = snippet_opt(cx, other_side.span) {
let rec = match side {
- Side::Lhs => Some(format!("{} {} {}", snippet, binop_string, other_side_snippet)),
- Side::Rhs => Some(format!("{} {} {}", other_side_snippet, binop_string, snippet)),
+ Side::Lhs => Some(format!("{snippet} {binop_string} {other_side_snippet}")),
+ Side::Rhs => Some(format!("{other_side_snippet} {binop_string} {snippet}")),
};
return rec;
}
diff --git a/src/tools/clippy/clippy_lints/src/invalid_upcast_comparisons.rs b/src/tools/clippy/clippy_lints/src/invalid_upcast_comparisons.rs
index 36e03e50a..0ef77e03d 100644
--- a/src/tools/clippy/clippy_lints/src/invalid_upcast_comparisons.rs
+++ b/src/tools/clippy/clippy_lints/src/invalid_upcast_comparisons.rs
@@ -145,9 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidUpcastComparisons {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::Binary(ref cmp, lhs, rhs) = expr.kind {
let normalized = comparisons::normalize_comparison(cmp.node, lhs, rhs);
- let (rel, normalized_lhs, normalized_rhs) = if let Some(val) = normalized {
- val
- } else {
+ let Some((rel, normalized_lhs, normalized_rhs)) = normalized else {
return;
};
diff --git a/src/tools/clippy/clippy_lints/src/iter_not_returning_iterator.rs b/src/tools/clippy/clippy_lints/src/iter_not_returning_iterator.rs
index b56d87c53..e76de77f1 100644
--- a/src/tools/clippy/clippy_lints/src/iter_not_returning_iterator.rs
+++ b/src/tools/clippy/clippy_lints/src/iter_not_returning_iterator.rs
@@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator {
let name = item.ident.name.as_str();
if matches!(name, "iter" | "iter_mut") {
if let TraitItemKind::Fn(fn_sig, _) = &item.kind {
- check_sig(cx, name, fn_sig, item.def_id);
+ check_sig(cx, name, fn_sig, item.owner_id.def_id);
}
}
}
@@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator {
)
{
if let ImplItemKind::Fn(fn_sig, _) = &item.kind {
- check_sig(cx, name, fn_sig, item.def_id);
+ check_sig(cx, name, fn_sig, item.owner_id.def_id);
}
}
}
@@ -80,10 +80,7 @@ fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefI
cx,
ITER_NOT_RETURNING_ITERATOR,
sig.span,
- &format!(
- "this method is named `{}` but its return type does not implement `Iterator`",
- name
- ),
+ &format!("this method is named `{name}` but its return type does not implement `Iterator`"),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/large_const_arrays.rs b/src/tools/clippy/clippy_lints/src/large_const_arrays.rs
index 984c5cd4e..76c83ab47 100644
--- a/src/tools/clippy/clippy_lints/src/large_const_arrays.rs
+++ b/src/tools/clippy/clippy_lints/src/large_const_arrays.rs
@@ -2,12 +2,12 @@ use clippy_utils::diagnostics::span_lint_and_then;
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{Item, ItemKind};
+use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self, ConstKind};
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::{BytePos, Pos, Span};
-use rustc_typeck::hir_ty_to_ty;
declare_clippy_lint! {
/// ### What it does
diff --git a/src/tools/clippy/clippy_lints/src/large_enum_variant.rs b/src/tools/clippy/clippy_lints/src/large_enum_variant.rs
index eb13d0869..06e957285 100644
--- a/src/tools/clippy/clippy_lints/src/large_enum_variant.rs
+++ b/src/tools/clippy/clippy_lints/src/large_enum_variant.rs
@@ -123,10 +123,9 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
return;
}
if let ItemKind::Enum(ref def, _) = item.kind {
- let ty = cx.tcx.type_of(item.def_id);
- let (adt, subst) = match ty.kind() {
- Adt(adt, subst) => (adt, subst),
- _ => panic!("already checked whether this is an enum"),
+ let ty = cx.tcx.type_of(item.owner_id);
+ let Adt(adt, subst) = ty.kind() else {
+ panic!("already checked whether this is an enum")
};
if adt.variants().len() <= 1 {
return;
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 0acbd81ae..5857d81ab 100644
--- a/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs
+++ b/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs
@@ -1,7 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::source::snippet;
-use if_chain::if_chain;
-use rustc_hir::{Expr, ExprKind};
+use rustc_hir::{Expr, ExprKind, Item, ItemKind, Node};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self, ConstKind};
@@ -39,29 +38,28 @@ impl_lint_pass!(LargeStackArrays => [LARGE_STACK_ARRAYS]);
impl<'tcx> LateLintPass<'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.typeck_results().expr_ty(expr).kind();
- if let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind();
- if let Ok(element_count) = element_count.try_to_machine_usize(cx.tcx);
- if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes());
- if self.maximum_allowed_size < element_count * element_size;
- then {
- span_lint_and_help(
- cx,
- LARGE_STACK_ARRAYS,
- expr.span,
- &format!(
- "allocating a local array larger than {} bytes",
- self.maximum_allowed_size
- ),
- None,
- &format!(
- "consider allocating on the heap with `vec!{}.into_boxed_slice()`",
- snippet(cx, expr.span, "[...]")
- ),
- );
- }
- }
+ if let ExprKind::Repeat(_, _) = expr.kind
+ && let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind()
+ && let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind()
+ && let Ok(element_count) = element_count.try_to_machine_usize(cx.tcx)
+ && let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes())
+ && !cx.tcx.hir().parent_iter(expr.hir_id)
+ .any(|(_, node)| matches!(node, Node::Item(Item { kind: ItemKind::Static(..), .. })))
+ && self.maximum_allowed_size < element_count * element_size {
+ span_lint_and_help(
+ cx,
+ LARGE_STACK_ARRAYS,
+ expr.span,
+ &format!(
+ "allocating a local array larger than {} bytes",
+ self.maximum_allowed_size
+ ),
+ None,
+ &format!(
+ "consider allocating on the heap with `vec!{}.into_boxed_slice()`",
+ snippet(cx, expr.span, "[...]")
+ ),
+ );
+ }
}
}
diff --git a/src/tools/clippy/clippy_lints/src/len_zero.rs b/src/tools/clippy/clippy_lints/src/len_zero.rs
index 7ae8ef830..b0cba40c2 100644
--- a/src/tools/clippy/clippy_lints/src/len_zero.rs
+++ b/src/tools/clippy/clippy_lints/src/len_zero.rs
@@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
if item.ident.name == sym::len;
if let ImplItemKind::Fn(sig, _) = &item.kind;
if sig.decl.implicit_self.has_implicit_self();
- if cx.access_levels.is_exported(item.def_id);
+ if cx.effective_visibilities.is_exported(item.owner_id.def_id);
if matches!(sig.decl.output, FnRetTy::Return(_));
if let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id());
if imp.of_trait.is_none();
@@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
if let Some(local_id) = ty_id.as_local();
let ty_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_id);
if !is_lint_allowed(cx, LEN_WITHOUT_IS_EMPTY, ty_hir_id);
- if let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.def_id).skip_binder());
+ if let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.owner_id).skip_binder());
then {
let (name, kind) = match cx.tcx.hir().find(ty_hir_id) {
Some(Node::ForeignItem(x)) => (x.ident.name, "extern type"),
@@ -195,7 +195,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: Symbol) -> bool {
item.ident.name == name
&& if let AssocItemKind::Fn { has_self } = item.kind {
- has_self && { cx.tcx.fn_sig(item.id.def_id).inputs().skip_binder().len() == 1 }
+ has_self && { cx.tcx.fn_sig(item.id.owner_id).inputs().skip_binder().len() == 1 }
} else {
false
}
@@ -210,10 +210,11 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
}
}
- if cx.access_levels.is_exported(visited_trait.def_id) && trait_items.iter().any(|i| is_named_self(cx, i, sym::len))
+ if cx.effective_visibilities.is_exported(visited_trait.owner_id.def_id)
+ && trait_items.iter().any(|i| is_named_self(cx, i, sym::len))
{
let mut current_and_super_traits = DefIdSet::default();
- fill_trait_set(visited_trait.def_id.to_def_id(), &mut current_and_super_traits, cx);
+ fill_trait_set(visited_trait.owner_id.to_def_id(), &mut current_and_super_traits, cx);
let is_empty = sym!(is_empty);
let is_empty_method_found = current_and_super_traits
@@ -278,15 +279,13 @@ impl<'tcx> LenOutput<'tcx> {
_ => "",
};
match self {
- Self::Integral => format!("expected signature: `({}self) -> bool`", self_ref),
- Self::Option(_) => format!(
- "expected signature: `({}self) -> bool` or `({}self) -> Option<bool>",
- self_ref, self_ref
- ),
- Self::Result(..) => format!(
- "expected signature: `({}self) -> bool` or `({}self) -> Result<bool>",
- self_ref, self_ref
- ),
+ Self::Integral => format!("expected signature: `({self_ref}self) -> bool`"),
+ Self::Option(_) => {
+ format!("expected signature: `({self_ref}self) -> bool` or `({self_ref}self) -> Option<bool>")
+ },
+ Self::Result(..) => {
+ format!("expected signature: `({self_ref}self) -> bool` or `({self_ref}self) -> Result<bool>")
+ },
}
}
}
@@ -326,17 +325,15 @@ fn check_for_is_empty<'tcx>(
let (msg, is_empty_span, self_kind) = match is_empty {
None => (
format!(
- "{} `{}` has a public `len` method, but no `is_empty` method",
- item_kind,
+ "{item_kind} `{}` has a public `len` method, but no `is_empty` method",
item_name.as_str(),
),
None,
None,
),
- Some(is_empty) if !cx.access_levels.is_exported(is_empty.def_id.expect_local()) => (
+ Some(is_empty) if !cx.effective_visibilities.is_exported(is_empty.def_id.expect_local()) => (
format!(
- "{} `{}` has a public `len` method, but a private `is_empty` method",
- item_kind,
+ "{item_kind} `{}` has a public `len` method, but a private `is_empty` method",
item_name.as_str(),
),
Some(cx.tcx.def_span(is_empty.def_id)),
@@ -348,8 +345,7 @@ fn check_for_is_empty<'tcx>(
{
(
format!(
- "{} `{}` has a public `len` method, but the `is_empty` method has an unexpected signature",
- item_kind,
+ "{item_kind} `{}` has a public `len` method, but the `is_empty` method has an unexpected signature",
item_name.as_str(),
),
Some(cx.tcx.def_span(is_empty.def_id)),
@@ -419,10 +415,9 @@ fn check_len(
LEN_ZERO,
span,
&format!("length comparison to {}", if compare_to == 0 { "zero" } else { "one" }),
- &format!("using `{}is_empty` is clearer and more explicit", op),
+ &format!("using `{op}is_empty` is clearer and more explicit"),
format!(
- "{}{}.is_empty()",
- op,
+ "{op}{}.is_empty()",
snippet_with_applicability(cx, receiver.span, "_", &mut applicability)
),
applicability,
@@ -439,10 +434,9 @@ fn check_empty_expr(cx: &LateContext<'_>, span: Span, lit1: &Expr<'_>, lit2: &Ex
COMPARISON_TO_EMPTY,
span,
"comparison to empty slice",
- &format!("using `{}is_empty` is clearer and more explicit", op),
+ &format!("using `{op}is_empty` is clearer and more explicit"),
format!(
- "{}{}.is_empty()",
- op,
+ "{op}{}.is_empty()",
snippet_with_applicability(cx, lit1.span, "_", &mut applicability)
),
applicability,
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 10fc0f401..db41bc67d 100644
--- a/src/tools/clippy/clippy_lints/src/let_if_seq.rs
+++ b/src/tools/clippy/clippy_lints/src/let_if_seq.rs
@@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
let span = stmt.span.to(if_.span);
let has_interior_mutability = !cx.typeck_results().node_type(canonical_id).is_freeze(
- cx.tcx.at(span),
+ cx.tcx,
cx.param_env,
);
if has_interior_mutability { return; }
@@ -106,8 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
// use mutably after the `if`
let sug = format!(
- "let {mut}{name} = if {cond} {{{then} {value} }} else {{{else} {default} }};",
- mut=mutability,
+ "let {mutability}{name} = if {cond} {{{then} {value} }} else {{{else} {default} }};",
name=ident.name,
cond=snippet(cx, cond.span, "_"),
then=if then.stmts.len() > 1 { " ..;" } else { "" },
diff --git a/src/tools/clippy/clippy_lints/src/let_underscore.rs b/src/tools/clippy/clippy_lints/src/let_underscore.rs
index 176787497..b7798b1c1 100644
--- a/src/tools/clippy/clippy_lints/src/let_underscore.rs
+++ b/src/tools/clippy/clippy_lints/src/let_underscore.rs
@@ -1,5 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_help;
-use clippy_utils::ty::{is_must_use_ty, match_type};
+use clippy_utils::ty::{is_must_use_ty, is_type_diagnostic_item, match_type};
use clippy_utils::{is_must_use_func_call, paths};
use if_chain::if_chain;
use rustc_hir::{Local, PatKind};
@@ -7,6 +7,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::subst::GenericArgKind;
use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::{sym, Symbol};
declare_clippy_lint! {
/// ### What it does
@@ -99,10 +100,9 @@ declare_clippy_lint! {
declare_lint_pass!(LetUnderscore => [LET_UNDERSCORE_MUST_USE, LET_UNDERSCORE_LOCK, LET_UNDERSCORE_DROP]);
-const SYNC_GUARD_PATHS: [&[&str]; 6] = [
- &paths::MUTEX_GUARD,
- &paths::RWLOCK_READ_GUARD,
- &paths::RWLOCK_WRITE_GUARD,
+const SYNC_GUARD_SYMS: [Symbol; 3] = [sym::MutexGuard, sym::RwLockReadGuard, sym::RwLockWriteGuard];
+
+const SYNC_GUARD_PATHS: [&[&str]; 3] = [
&paths::PARKING_LOT_MUTEX_GUARD,
&paths::PARKING_LOT_RWLOCK_READ_GUARD,
&paths::PARKING_LOT_RWLOCK_WRITE_GUARD,
@@ -121,7 +121,10 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
let init_ty = cx.typeck_results().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))
+ SYNC_GUARD_SYMS
+ .iter()
+ .any(|&sym| is_type_diagnostic_item(cx, inner_ty, sym))
+ || SYNC_GUARD_PATHS.iter().any(|path| match_type(cx, inner_ty, path))
},
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
@@ -134,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
"non-binding let on a synchronization lock",
None,
"consider using an underscore-prefixed named \
- binding or dropping explicitly with `std::mem::drop`"
+ binding or dropping explicitly with `std::mem::drop`",
);
} else if init_ty.needs_drop(cx.tcx, cx.param_env) {
span_lint_and_help(
@@ -144,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
"non-binding `let` on a type that implements `Drop`",
None,
"consider using an underscore-prefixed named \
- binding or dropping explicitly with `std::mem::drop`"
+ binding or dropping explicitly with `std::mem::drop`",
);
} else if is_must_use_ty(cx, cx.typeck_results().expr_ty(init)) {
span_lint_and_help(
@@ -153,7 +156,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
local.span,
"non-binding let on an expression with `#[must_use]` type",
None,
- "consider explicitly using expression value"
+ "consider explicitly using expression value",
);
} else if is_must_use_func_call(cx, init) {
span_lint_and_help(
@@ -162,7 +165,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
local.span,
"non-binding let on a result of a `#[must_use]` function",
None,
- "consider explicitly using function result"
+ "consider explicitly using function result",
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/lib.register_all.rs b/src/tools/clippy/clippy_lints/src/lib.register_all.rs
index 751409602..c455e1561 100644
--- a/src/tools/clippy/clippy_lints/src/lib.register_all.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.register_all.rs
@@ -21,9 +21,11 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(booleans::NONMINIMAL_BOOL),
LintId::of(booleans::OVERLY_COMPLEX_BOOL_EXPR),
LintId::of(borrow_deref_ref::BORROW_DEREF_REF),
+ LintId::of(box_default::BOX_DEFAULT),
LintId::of(casts::CAST_ABS_TO_UNSIGNED),
LintId::of(casts::CAST_ENUM_CONSTRUCTOR),
LintId::of(casts::CAST_ENUM_TRUNCATION),
+ LintId::of(casts::CAST_NAN_TO_INT),
LintId::of(casts::CAST_REF_TO_MUT),
LintId::of(casts::CAST_SLICE_DIFFERENT_SIZES),
LintId::of(casts::CAST_SLICE_FROM_RAW_PARTS),
@@ -44,7 +46,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(derivable_impls::DERIVABLE_IMPLS),
LintId::of(derive::DERIVE_HASH_XOR_EQ),
LintId::of(derive::DERIVE_ORD_XOR_PARTIAL_ORD),
- LintId::of(derive::DERIVE_PARTIAL_EQ_WITHOUT_EQ),
+ LintId::of(disallowed_macros::DISALLOWED_MACROS),
LintId::of(disallowed_methods::DISALLOWED_METHODS),
LintId::of(disallowed_names::DISALLOWED_NAMES),
LintId::of(disallowed_types::DISALLOWED_TYPES),
@@ -70,6 +72,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(format::USELESS_FORMAT),
LintId::of(format_args::FORMAT_IN_FORMAT_ARGS),
LintId::of(format_args::TO_STRING_IN_FORMAT_ARGS),
+ LintId::of(format_args::UNUSED_FORMAT_SPECS),
LintId::of(format_impl::PRINT_IN_FORMAT_IMPL),
LintId::of(format_impl::RECURSIVE_FORMAT_IMPL),
LintId::of(formatting::POSSIBLE_MISSING_COMMA),
@@ -85,6 +88,8 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(functions::RESULT_UNIT_ERR),
LintId::of(functions::TOO_MANY_ARGUMENTS),
LintId::of(if_let_mutex::IF_LET_MUTEX),
+ LintId::of(implicit_saturating_add::IMPLICIT_SATURATING_ADD),
+ LintId::of(implicit_saturating_sub::IMPLICIT_SATURATING_SUB),
LintId::of(indexing_slicing::OUT_OF_BOUNDS_INDEXING),
LintId::of(infinite_iter::INFINITE_ITER),
LintId::of(inherent_to_string::INHERENT_TO_STRING),
@@ -107,7 +112,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(loops::EMPTY_LOOP),
LintId::of(loops::EXPLICIT_COUNTER_LOOP),
LintId::of(loops::FOR_KV_MAP),
- LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES),
LintId::of(loops::ITER_NEXT_LOOP),
LintId::of(loops::MANUAL_FIND),
LintId::of(loops::MANUAL_FLATTEN),
@@ -125,6 +129,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(main_recursion::MAIN_RECURSION),
LintId::of(manual_async_fn::MANUAL_ASYNC_FN),
LintId::of(manual_bits::MANUAL_BITS),
+ LintId::of(manual_clamp::MANUAL_CLAMP),
LintId::of(manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE),
LintId::of(manual_rem_euclid::MANUAL_REM_EUCLID),
LintId::of(manual_retain::MANUAL_RETAIN),
@@ -134,6 +139,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(match_result_ok::MATCH_RESULT_OK),
LintId::of(matches::COLLAPSIBLE_MATCH),
LintId::of(matches::INFALLIBLE_DESTRUCTURING_MATCH),
+ LintId::of(matches::MANUAL_FILTER),
LintId::of(matches::MANUAL_MAP),
LintId::of(matches::MANUAL_UNWRAP_OR),
LintId::of(matches::MATCH_AS_REF),
@@ -171,6 +177,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(methods::ITERATOR_STEP_BY_ZERO),
LintId::of(methods::ITER_CLONED_COLLECT),
LintId::of(methods::ITER_COUNT),
+ LintId::of(methods::ITER_KV_MAP),
LintId::of(methods::ITER_NEXT_SLICE),
LintId::of(methods::ITER_NTH),
LintId::of(methods::ITER_NTH_ZERO),
@@ -289,6 +296,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(ranges::MANUAL_RANGE_CONTAINS),
LintId::of(ranges::REVERSED_EMPTY_RANGES),
LintId::of(rc_clone_in_vec_init::RC_CLONE_IN_VEC_INIT),
+ LintId::of(read_zero_byte_vec::READ_ZERO_BYTE_VEC),
LintId::of(redundant_clone::REDUNDANT_CLONE),
LintId::of(redundant_closure_call::REDUNDANT_CLOSURE_CALL),
LintId::of(redundant_field_names::REDUNDANT_FIELD_NAMES),
@@ -350,7 +358,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(useless_conversion::USELESS_CONVERSION),
LintId::of(vec::USELESS_VEC),
LintId::of(vec_init_then_push::VEC_INIT_THEN_PUSH),
- LintId::of(write::POSITIONAL_NAMED_FORMAT_PARAMETERS),
LintId::of(write::PRINTLN_EMPTY_STRING),
LintId::of(write::PRINT_LITERAL),
LintId::of(write::PRINT_WITH_NEWLINE),
diff --git a/src/tools/clippy/clippy_lints/src/lib.register_complexity.rs b/src/tools/clippy/clippy_lints/src/lib.register_complexity.rs
index aa247352f..8be9dc4ba 100644
--- a/src/tools/clippy/clippy_lints/src/lib.register_complexity.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.register_complexity.rs
@@ -13,6 +13,7 @@ store.register_group(true, "clippy::complexity", Some("clippy_complexity"), vec!
LintId::of(double_parens::DOUBLE_PARENS),
LintId::of(explicit_write::EXPLICIT_WRITE),
LintId::of(format::USELESS_FORMAT),
+ LintId::of(format_args::UNUSED_FORMAT_SPECS),
LintId::of(functions::TOO_MANY_ARGUMENTS),
LintId::of(int_plus_one::INT_PLUS_ONE),
LintId::of(lifetimes::EXTRA_UNUSED_LIFETIMES),
@@ -22,10 +23,12 @@ store.register_group(true, "clippy::complexity", Some("clippy_complexity"), vec!
LintId::of(loops::MANUAL_FLATTEN),
LintId::of(loops::SINGLE_ELEMENT_LOOP),
LintId::of(loops::WHILE_LET_LOOP),
+ LintId::of(manual_clamp::MANUAL_CLAMP),
LintId::of(manual_rem_euclid::MANUAL_REM_EUCLID),
LintId::of(manual_strip::MANUAL_STRIP),
LintId::of(map_unit_fn::OPTION_MAP_UNIT_FN),
LintId::of(map_unit_fn::RESULT_MAP_UNIT_FN),
+ LintId::of(matches::MANUAL_FILTER),
LintId::of(matches::MANUAL_UNWRAP_OR),
LintId::of(matches::MATCH_AS_REF),
LintId::of(matches::MATCH_SINGLE_BINDING),
@@ -40,6 +43,7 @@ store.register_group(true, "clippy::complexity", Some("clippy_complexity"), vec!
LintId::of(methods::GET_LAST_WITH_LEN),
LintId::of(methods::INSPECT_FOR_EACH),
LintId::of(methods::ITER_COUNT),
+ LintId::of(methods::ITER_KV_MAP),
LintId::of(methods::MANUAL_FILTER_MAP),
LintId::of(methods::MANUAL_FIND_MAP),
LintId::of(methods::MANUAL_SPLIT_ONCE),
diff --git a/src/tools/clippy/clippy_lints/src/lib.register_correctness.rs b/src/tools/clippy/clippy_lints/src/lib.register_correctness.rs
index ecec5cf57..bb94037ec 100644
--- a/src/tools/clippy/clippy_lints/src/lib.register_correctness.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.register_correctness.rs
@@ -59,6 +59,7 @@ store.register_group(true, "clippy::correctness", Some("clippy_correctness"), ve
LintId::of(ptr::INVALID_NULL_PTR_USAGE),
LintId::of(ptr::MUT_FROM_REF),
LintId::of(ranges::REVERSED_EMPTY_RANGES),
+ LintId::of(read_zero_byte_vec::READ_ZERO_BYTE_VEC),
LintId::of(regex::INVALID_REGEX),
LintId::of(serde_api::SERDE_API_MISUSE),
LintId::of(size_of_in_element_count::SIZE_OF_IN_ELEMENT_COUNT),
diff --git a/src/tools/clippy/clippy_lints/src/lib.register_internal.rs b/src/tools/clippy/clippy_lints/src/lib.register_internal.rs
index be63646a1..40c94c6e8 100644
--- a/src/tools/clippy/clippy_lints/src/lib.register_internal.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.register_internal.rs
@@ -3,20 +3,20 @@
// Manual edits will be overwritten.
store.register_group(true, "clippy::internal", Some("clippy_internal"), vec![
- LintId::of(utils::internal_lints::CLIPPY_LINTS_INTERNAL),
- LintId::of(utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS),
- LintId::of(utils::internal_lints::COMPILER_LINT_FUNCTIONS),
- LintId::of(utils::internal_lints::DEFAULT_DEPRECATION_REASON),
- LintId::of(utils::internal_lints::DEFAULT_LINT),
- LintId::of(utils::internal_lints::IF_CHAIN_STYLE),
- LintId::of(utils::internal_lints::INTERNING_DEFINED_SYMBOL),
- LintId::of(utils::internal_lints::INVALID_CLIPPY_VERSION_ATTRIBUTE),
- LintId::of(utils::internal_lints::INVALID_PATHS),
- LintId::of(utils::internal_lints::LINT_WITHOUT_LINT_PASS),
- LintId::of(utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM),
- LintId::of(utils::internal_lints::MISSING_CLIPPY_VERSION_ATTRIBUTE),
- LintId::of(utils::internal_lints::MISSING_MSRV_ATTR_IMPL),
- LintId::of(utils::internal_lints::OUTER_EXPN_EXPN_DATA),
- LintId::of(utils::internal_lints::PRODUCE_ICE),
- LintId::of(utils::internal_lints::UNNECESSARY_SYMBOL_STR),
+ LintId::of(utils::internal_lints::clippy_lints_internal::CLIPPY_LINTS_INTERNAL),
+ LintId::of(utils::internal_lints::collapsible_calls::COLLAPSIBLE_SPAN_LINT_CALLS),
+ LintId::of(utils::internal_lints::compiler_lint_functions::COMPILER_LINT_FUNCTIONS),
+ LintId::of(utils::internal_lints::if_chain_style::IF_CHAIN_STYLE),
+ LintId::of(utils::internal_lints::interning_defined_symbol::INTERNING_DEFINED_SYMBOL),
+ LintId::of(utils::internal_lints::interning_defined_symbol::UNNECESSARY_SYMBOL_STR),
+ LintId::of(utils::internal_lints::invalid_paths::INVALID_PATHS),
+ LintId::of(utils::internal_lints::lint_without_lint_pass::DEFAULT_DEPRECATION_REASON),
+ LintId::of(utils::internal_lints::lint_without_lint_pass::DEFAULT_LINT),
+ LintId::of(utils::internal_lints::lint_without_lint_pass::INVALID_CLIPPY_VERSION_ATTRIBUTE),
+ LintId::of(utils::internal_lints::lint_without_lint_pass::LINT_WITHOUT_LINT_PASS),
+ LintId::of(utils::internal_lints::lint_without_lint_pass::MISSING_CLIPPY_VERSION_ATTRIBUTE),
+ LintId::of(utils::internal_lints::msrv_attr_impl::MISSING_MSRV_ATTR_IMPL),
+ LintId::of(utils::internal_lints::outer_expn_data_pass::OUTER_EXPN_EXPN_DATA),
+ LintId::of(utils::internal_lints::produce_ice::PRODUCE_ICE),
+ LintId::of(utils::internal_lints::unnecessary_def_path::UNNECESSARY_DEF_PATH),
])
diff --git a/src/tools/clippy/clippy_lints/src/lib.register_lints.rs b/src/tools/clippy/clippy_lints/src/lib.register_lints.rs
index 962e67220..800e3a876 100644
--- a/src/tools/clippy/clippy_lints/src/lib.register_lints.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.register_lints.rs
@@ -4,37 +4,37 @@
store.register_lints(&[
#[cfg(feature = "internal")]
- utils::internal_lints::CLIPPY_LINTS_INTERNAL,
+ utils::internal_lints::clippy_lints_internal::CLIPPY_LINTS_INTERNAL,
#[cfg(feature = "internal")]
- utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS,
+ utils::internal_lints::collapsible_calls::COLLAPSIBLE_SPAN_LINT_CALLS,
#[cfg(feature = "internal")]
- utils::internal_lints::COMPILER_LINT_FUNCTIONS,
+ utils::internal_lints::compiler_lint_functions::COMPILER_LINT_FUNCTIONS,
#[cfg(feature = "internal")]
- utils::internal_lints::DEFAULT_DEPRECATION_REASON,
+ utils::internal_lints::if_chain_style::IF_CHAIN_STYLE,
#[cfg(feature = "internal")]
- utils::internal_lints::DEFAULT_LINT,
+ utils::internal_lints::interning_defined_symbol::INTERNING_DEFINED_SYMBOL,
#[cfg(feature = "internal")]
- utils::internal_lints::IF_CHAIN_STYLE,
+ utils::internal_lints::interning_defined_symbol::UNNECESSARY_SYMBOL_STR,
#[cfg(feature = "internal")]
- utils::internal_lints::INTERNING_DEFINED_SYMBOL,
+ utils::internal_lints::invalid_paths::INVALID_PATHS,
#[cfg(feature = "internal")]
- utils::internal_lints::INVALID_CLIPPY_VERSION_ATTRIBUTE,
+ utils::internal_lints::lint_without_lint_pass::DEFAULT_DEPRECATION_REASON,
#[cfg(feature = "internal")]
- utils::internal_lints::INVALID_PATHS,
+ utils::internal_lints::lint_without_lint_pass::DEFAULT_LINT,
#[cfg(feature = "internal")]
- utils::internal_lints::LINT_WITHOUT_LINT_PASS,
+ utils::internal_lints::lint_without_lint_pass::INVALID_CLIPPY_VERSION_ATTRIBUTE,
#[cfg(feature = "internal")]
- utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM,
+ utils::internal_lints::lint_without_lint_pass::LINT_WITHOUT_LINT_PASS,
#[cfg(feature = "internal")]
- utils::internal_lints::MISSING_CLIPPY_VERSION_ATTRIBUTE,
+ utils::internal_lints::lint_without_lint_pass::MISSING_CLIPPY_VERSION_ATTRIBUTE,
#[cfg(feature = "internal")]
- utils::internal_lints::MISSING_MSRV_ATTR_IMPL,
+ utils::internal_lints::msrv_attr_impl::MISSING_MSRV_ATTR_IMPL,
#[cfg(feature = "internal")]
- utils::internal_lints::OUTER_EXPN_EXPN_DATA,
+ utils::internal_lints::outer_expn_data_pass::OUTER_EXPN_EXPN_DATA,
#[cfg(feature = "internal")]
- utils::internal_lints::PRODUCE_ICE,
+ utils::internal_lints::produce_ice::PRODUCE_ICE,
#[cfg(feature = "internal")]
- utils::internal_lints::UNNECESSARY_SYMBOL_STR,
+ utils::internal_lints::unnecessary_def_path::UNNECESSARY_DEF_PATH,
almost_complete_letter_range::ALMOST_COMPLETE_LETTER_RANGE,
approx_const::APPROX_CONSTANT,
as_conversions::AS_CONVERSIONS,
@@ -60,17 +60,20 @@ store.register_lints(&[
booleans::NONMINIMAL_BOOL,
booleans::OVERLY_COMPLEX_BOOL_EXPR,
borrow_deref_ref::BORROW_DEREF_REF,
+ box_default::BOX_DEFAULT,
cargo::CARGO_COMMON_METADATA,
cargo::MULTIPLE_CRATE_VERSIONS,
cargo::NEGATIVE_FEATURE_NAMES,
cargo::REDUNDANT_FEATURE_NAMES,
cargo::WILDCARD_DEPENDENCIES,
+ casts::AS_PTR_CAST_MUT,
casts::AS_UNDERSCORE,
casts::BORROW_AS_PTR,
casts::CAST_ABS_TO_UNSIGNED,
casts::CAST_ENUM_CONSTRUCTOR,
casts::CAST_ENUM_TRUNCATION,
casts::CAST_LOSSLESS,
+ casts::CAST_NAN_TO_INT,
casts::CAST_POSSIBLE_TRUNCATION,
casts::CAST_POSSIBLE_WRAP,
casts::CAST_PRECISION_LOSS,
@@ -113,16 +116,17 @@ store.register_lints(&[
derive::DERIVE_PARTIAL_EQ_WITHOUT_EQ,
derive::EXPL_IMPL_CLONE_ON_COPY,
derive::UNSAFE_DERIVE_DESERIALIZE,
+ disallowed_macros::DISALLOWED_MACROS,
disallowed_methods::DISALLOWED_METHODS,
disallowed_names::DISALLOWED_NAMES,
disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS,
disallowed_types::DISALLOWED_TYPES,
+ doc::DOC_LINK_WITH_QUOTES,
doc::DOC_MARKDOWN,
doc::MISSING_ERRORS_DOC,
doc::MISSING_PANICS_DOC,
doc::MISSING_SAFETY_DOC,
doc::NEEDLESS_DOCTEST_MAIN,
- doc_link_with_quotes::DOC_LINK_WITH_QUOTES,
double_parens::DOUBLE_PARENS,
drop_forget_ref::DROP_COPY,
drop_forget_ref::DROP_NON_DROP,
@@ -159,6 +163,8 @@ store.register_lints(&[
format::USELESS_FORMAT,
format_args::FORMAT_IN_FORMAT_ARGS,
format_args::TO_STRING_IN_FORMAT_ARGS,
+ format_args::UNINLINED_FORMAT_ARGS,
+ format_args::UNUSED_FORMAT_SPECS,
format_impl::PRINT_IN_FORMAT_IMPL,
format_impl::RECURSIVE_FORMAT_IMPL,
format_push_string::FORMAT_PUSH_STRING,
@@ -182,6 +188,7 @@ store.register_lints(&[
if_then_some_else_none::IF_THEN_SOME_ELSE_NONE,
implicit_hasher::IMPLICIT_HASHER,
implicit_return::IMPLICIT_RETURN,
+ implicit_saturating_add::IMPLICIT_SATURATING_ADD,
implicit_saturating_sub::IMPLICIT_SATURATING_SUB,
inconsistent_struct_constructor::INCONSISTENT_STRUCT_CONSTRUCTOR,
index_refutable_slice::INDEX_REFUTABLE_SLICE,
@@ -223,7 +230,6 @@ store.register_lints(&[
loops::EXPLICIT_INTO_ITER_LOOP,
loops::EXPLICIT_ITER_LOOP,
loops::FOR_KV_MAP,
- loops::FOR_LOOPS_OVER_FALLIBLES,
loops::ITER_NEXT_LOOP,
loops::MANUAL_FIND,
loops::MANUAL_FLATTEN,
@@ -243,6 +249,7 @@ store.register_lints(&[
manual_assert::MANUAL_ASSERT,
manual_async_fn::MANUAL_ASYNC_FN,
manual_bits::MANUAL_BITS,
+ manual_clamp::MANUAL_CLAMP,
manual_instant_elapsed::MANUAL_INSTANT_ELAPSED,
manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE,
manual_rem_euclid::MANUAL_REM_EUCLID,
@@ -254,6 +261,7 @@ store.register_lints(&[
match_result_ok::MATCH_RESULT_OK,
matches::COLLAPSIBLE_MATCH,
matches::INFALLIBLE_DESTRUCTURING_MATCH,
+ matches::MANUAL_FILTER,
matches::MANUAL_MAP,
matches::MANUAL_UNWRAP_OR,
matches::MATCH_AS_REF,
@@ -313,6 +321,7 @@ store.register_lints(&[
methods::ITERATOR_STEP_BY_ZERO,
methods::ITER_CLONED_COLLECT,
methods::ITER_COUNT,
+ methods::ITER_KV_MAP,
methods::ITER_NEXT_SLICE,
methods::ITER_NTH,
methods::ITER_NTH_ZERO,
@@ -398,6 +407,7 @@ store.register_lints(&[
missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS,
missing_enforced_import_rename::MISSING_ENFORCED_IMPORT_RENAMES,
missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS,
+ missing_trait_methods::MISSING_TRAIT_METHODS,
mixed_read_write_in_expression::DIVERGING_SUB_EXPRESSION,
mixed_read_write_in_expression::MIXED_READ_WRITE_IN_EXPRESSION,
module_style::MOD_MODULE_FILES,
@@ -470,6 +480,7 @@ store.register_lints(&[
panic_unimplemented::TODO,
panic_unimplemented::UNIMPLEMENTED,
panic_unimplemented::UNREACHABLE,
+ partial_pub_fields::PARTIAL_PUB_FIELDS,
partialeq_ne_impl::PARTIALEQ_NE_IMPL,
partialeq_to_none::PARTIALEQ_TO_NONE,
pass_by_ref_or_value::LARGE_TYPES_PASSED_BY_VALUE,
@@ -595,7 +606,6 @@ store.register_lints(&[
vec_init_then_push::VEC_INIT_THEN_PUSH,
wildcard_imports::ENUM_GLOB_USE,
wildcard_imports::WILDCARD_IMPORTS,
- write::POSITIONAL_NAMED_FORMAT_PARAMETERS,
write::PRINTLN_EMPTY_STRING,
write::PRINT_LITERAL,
write::PRINT_STDERR,
diff --git a/src/tools/clippy/clippy_lints/src/lib.register_nursery.rs b/src/tools/clippy/clippy_lints/src/lib.register_nursery.rs
index 0876b2c3b..65616d28d 100644
--- a/src/tools/clippy/clippy_lints/src/lib.register_nursery.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.register_nursery.rs
@@ -4,8 +4,10 @@
store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
LintId::of(attrs::EMPTY_LINE_AFTER_OUTER_ATTR),
+ LintId::of(casts::AS_PTR_CAST_MUT),
LintId::of(cognitive_complexity::COGNITIVE_COMPLEXITY),
LintId::of(copies::BRANCHES_SHARING_CODE),
+ LintId::of(derive::DERIVE_PARTIAL_EQ_WITHOUT_EQ),
LintId::of(equatable_if_let::EQUATABLE_IF_LET),
LintId::of(fallible_impl_from::FALLIBLE_IMPL_FROM),
LintId::of(floating_point_arithmetic::IMPRECISE_FLOPS),
@@ -25,14 +27,11 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
LintId::of(non_send_fields_in_send_ty::NON_SEND_FIELDS_IN_SEND_TY),
LintId::of(nonstandard_macro_braces::NONSTANDARD_MACRO_BRACES),
LintId::of(option_if_let_else::OPTION_IF_LET_ELSE),
- LintId::of(read_zero_byte_vec::READ_ZERO_BYTE_VEC),
LintId::of(redundant_pub_crate::REDUNDANT_PUB_CRATE),
LintId::of(regex::TRIVIAL_REGEX),
LintId::of(strings::STRING_LIT_AS_BYTES),
LintId::of(suspicious_operation_groupings::SUSPICIOUS_OPERATION_GROUPINGS),
LintId::of(trailing_empty_array::TRAILING_EMPTY_ARRAY),
- LintId::of(trait_bounds::TRAIT_DUPLICATION_IN_BOUNDS),
- LintId::of(trait_bounds::TYPE_REPETITION_IN_BOUNDS),
LintId::of(transmute::TRANSMUTE_UNDEFINED_REPR),
LintId::of(unused_peekable::UNUSED_PEEKABLE),
LintId::of(unused_rounding::UNUSED_ROUNDING),
diff --git a/src/tools/clippy/clippy_lints/src/lib.register_pedantic.rs b/src/tools/clippy/clippy_lints/src/lib.register_pedantic.rs
index 03c3c202e..44e969585 100644
--- a/src/tools/clippy/clippy_lints/src/lib.register_pedantic.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.register_pedantic.rs
@@ -20,20 +20,20 @@ store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![
LintId::of(dereference::REF_BINDING_TO_REFERENCE),
LintId::of(derive::EXPL_IMPL_CLONE_ON_COPY),
LintId::of(derive::UNSAFE_DERIVE_DESERIALIZE),
+ LintId::of(doc::DOC_LINK_WITH_QUOTES),
LintId::of(doc::DOC_MARKDOWN),
LintId::of(doc::MISSING_ERRORS_DOC),
LintId::of(doc::MISSING_PANICS_DOC),
- LintId::of(doc_link_with_quotes::DOC_LINK_WITH_QUOTES),
LintId::of(empty_enum::EMPTY_ENUM),
LintId::of(enum_variants::MODULE_NAME_REPETITIONS),
LintId::of(eta_reduction::REDUNDANT_CLOSURE_FOR_METHOD_CALLS),
LintId::of(excessive_bools::FN_PARAMS_EXCESSIVE_BOOLS),
LintId::of(excessive_bools::STRUCT_EXCESSIVE_BOOLS),
+ LintId::of(format_args::UNINLINED_FORMAT_ARGS),
LintId::of(functions::MUST_USE_CANDIDATE),
LintId::of(functions::TOO_MANY_LINES),
LintId::of(if_not_else::IF_NOT_ELSE),
LintId::of(implicit_hasher::IMPLICIT_HASHER),
- LintId::of(implicit_saturating_sub::IMPLICIT_SATURATING_SUB),
LintId::of(inconsistent_struct_constructor::INCONSISTENT_STRUCT_CONSTRUCTOR),
LintId::of(infinite_iter::MAYBE_INFINITE_ITER),
LintId::of(invalid_upcast_comparisons::INVALID_UPCAST_COMPARISONS),
@@ -88,6 +88,8 @@ store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![
LintId::of(return_self_not_must_use::RETURN_SELF_NOT_MUST_USE),
LintId::of(semicolon_if_nothing_returned::SEMICOLON_IF_NOTHING_RETURNED),
LintId::of(strings::STRING_ADD_ASSIGN),
+ LintId::of(trait_bounds::TRAIT_DUPLICATION_IN_BOUNDS),
+ LintId::of(trait_bounds::TYPE_REPETITION_IN_BOUNDS),
LintId::of(transmute::TRANSMUTE_PTR_TO_PTR),
LintId::of(types::LINKEDLIST),
LintId::of(types::OPTION_OPTION),
diff --git a/src/tools/clippy/clippy_lints/src/lib.register_perf.rs b/src/tools/clippy/clippy_lints/src/lib.register_perf.rs
index 195ce41e3..8e927470e 100644
--- a/src/tools/clippy/clippy_lints/src/lib.register_perf.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.register_perf.rs
@@ -3,6 +3,7 @@
// Manual edits will be overwritten.
store.register_group(true, "clippy::perf", Some("clippy_perf"), vec![
+ LintId::of(box_default::BOX_DEFAULT),
LintId::of(entry::MAP_ENTRY),
LintId::of(escape::BOXED_LOCAL),
LintId::of(format_args::FORMAT_IN_FORMAT_ARGS),
diff --git a/src/tools/clippy/clippy_lints/src/lib.register_restriction.rs b/src/tools/clippy/clippy_lints/src/lib.register_restriction.rs
index 6eb9b3d3b..f62d57af5 100644
--- a/src/tools/clippy/clippy_lints/src/lib.register_restriction.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.register_restriction.rs
@@ -47,6 +47,7 @@ store.register_group(true, "clippy::restriction", Some("clippy_restriction"), ve
LintId::of(missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS),
LintId::of(missing_enforced_import_rename::MISSING_ENFORCED_IMPORT_RENAMES),
LintId::of(missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS),
+ LintId::of(missing_trait_methods::MISSING_TRAIT_METHODS),
LintId::of(mixed_read_write_in_expression::MIXED_READ_WRITE_IN_EXPRESSION),
LintId::of(module_style::MOD_MODULE_FILES),
LintId::of(module_style::SELF_NAMED_MODULE_FILES),
@@ -61,6 +62,7 @@ store.register_group(true, "clippy::restriction", Some("clippy_restriction"), ve
LintId::of(panic_unimplemented::TODO),
LintId::of(panic_unimplemented::UNIMPLEMENTED),
LintId::of(panic_unimplemented::UNREACHABLE),
+ LintId::of(partial_pub_fields::PARTIAL_PUB_FIELDS),
LintId::of(pattern_type_mismatch::PATTERN_TYPE_MISMATCH),
LintId::of(pub_use::PUB_USE),
LintId::of(redundant_slicing::DEREF_BY_SLICING),
diff --git a/src/tools/clippy/clippy_lints/src/lib.register_style.rs b/src/tools/clippy/clippy_lints/src/lib.register_style.rs
index 05d2ec2e9..3312f5648 100644
--- a/src/tools/clippy/clippy_lints/src/lib.register_style.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.register_style.rs
@@ -15,7 +15,7 @@ store.register_group(true, "clippy::style", Some("clippy_style"), vec![
LintId::of(default::FIELD_REASSIGN_WITH_DEFAULT),
LintId::of(default_instead_of_iter_empty::DEFAULT_INSTEAD_OF_ITER_EMPTY),
LintId::of(dereference::NEEDLESS_BORROW),
- LintId::of(derive::DERIVE_PARTIAL_EQ_WITHOUT_EQ),
+ LintId::of(disallowed_macros::DISALLOWED_MACROS),
LintId::of(disallowed_methods::DISALLOWED_METHODS),
LintId::of(disallowed_names::DISALLOWED_NAMES),
LintId::of(disallowed_types::DISALLOWED_TYPES),
@@ -30,6 +30,8 @@ store.register_group(true, "clippy::style", Some("clippy_style"), vec![
LintId::of(functions::DOUBLE_MUST_USE),
LintId::of(functions::MUST_USE_UNIT),
LintId::of(functions::RESULT_UNIT_ERR),
+ LintId::of(implicit_saturating_add::IMPLICIT_SATURATING_ADD),
+ LintId::of(implicit_saturating_sub::IMPLICIT_SATURATING_SUB),
LintId::of(inherent_to_string::INHERENT_TO_STRING),
LintId::of(init_numbered_fields::INIT_NUMBERED_FIELDS),
LintId::of(len_zero::COMPARISON_TO_EMPTY),
diff --git a/src/tools/clippy/clippy_lints/src/lib.register_suspicious.rs b/src/tools/clippy/clippy_lints/src/lib.register_suspicious.rs
index bede91f18..b70c4bb73 100644
--- a/src/tools/clippy/clippy_lints/src/lib.register_suspicious.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.register_suspicious.rs
@@ -11,6 +11,7 @@ store.register_group(true, "clippy::suspicious", Some("clippy_suspicious"), vec!
LintId::of(casts::CAST_ABS_TO_UNSIGNED),
LintId::of(casts::CAST_ENUM_CONSTRUCTOR),
LintId::of(casts::CAST_ENUM_TRUNCATION),
+ LintId::of(casts::CAST_NAN_TO_INT),
LintId::of(casts::CAST_SLICE_FROM_RAW_PARTS),
LintId::of(crate_in_macro_def::CRATE_IN_MACRO_DEF),
LintId::of(drop_forget_ref::DROP_NON_DROP),
@@ -21,7 +22,6 @@ store.register_group(true, "clippy::suspicious", Some("clippy_suspicious"), vec!
LintId::of(formatting::SUSPICIOUS_ELSE_FORMATTING),
LintId::of(formatting::SUSPICIOUS_UNARY_OP_FORMATTING),
LintId::of(loops::EMPTY_LOOP),
- LintId::of(loops::FOR_LOOPS_OVER_FALLIBLES),
LintId::of(loops::MUT_RANGE_BOUND),
LintId::of(methods::NO_EFFECT_REPLACE),
LintId::of(methods::SUSPICIOUS_MAP),
@@ -35,5 +35,4 @@ store.register_group(true, "clippy::suspicious", Some("clippy_suspicious"), vec!
LintId::of(suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL),
LintId::of(suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL),
LintId::of(swap_ptr_to_ref::SWAP_PTR_TO_REF),
- LintId::of(write::POSITIONAL_NAMED_FORMAT_PARAMETERS),
])
diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs
index ceaaf5c6d..1307096b2 100644
--- a/src/tools/clippy/clippy_lints/src/lib.rs
+++ b/src/tools/clippy/clippy_lints/src/lib.rs
@@ -5,7 +5,6 @@
#![feature(drain_filter)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
-#![cfg_attr(bootstrap, feature(let_else))]
#![feature(lint_reasons)]
#![feature(never_type)]
#![feature(once_cell)]
@@ -32,20 +31,19 @@ extern crate rustc_data_structures;
extern crate rustc_driver;
extern crate rustc_errors;
extern crate rustc_hir;
+extern crate rustc_hir_analysis;
+extern crate rustc_hir_typeck;
extern crate rustc_hir_pretty;
extern crate rustc_index;
extern crate rustc_infer;
extern crate rustc_lexer;
extern crate rustc_lint;
extern crate rustc_middle;
-extern crate rustc_mir_dataflow;
extern crate rustc_parse;
-extern crate rustc_parse_format;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_target;
extern crate rustc_trait_selection;
-extern crate rustc_typeck;
#[macro_use]
extern crate clippy_utils;
@@ -182,6 +180,7 @@ mod bool_assert_comparison;
mod bool_to_int_with_if;
mod booleans;
mod borrow_deref_ref;
+mod box_default;
mod cargo;
mod casts;
mod checked_conversions;
@@ -200,12 +199,12 @@ mod default_union_representation;
mod dereference;
mod derivable_impls;
mod derive;
+mod disallowed_macros;
mod disallowed_methods;
mod disallowed_names;
mod disallowed_script_idents;
mod disallowed_types;
mod doc;
-mod doc_link_with_quotes;
mod double_parens;
mod drop_forget_ref;
mod duplicate_mod;
@@ -240,6 +239,7 @@ mod if_not_else;
mod if_then_some_else_none;
mod implicit_hasher;
mod implicit_return;
+mod implicit_saturating_add;
mod implicit_saturating_sub;
mod inconsistent_struct_constructor;
mod index_refutable_slice;
@@ -269,6 +269,7 @@ mod main_recursion;
mod manual_assert;
mod manual_async_fn;
mod manual_bits;
+mod manual_clamp;
mod manual_instant_elapsed;
mod manual_non_exhaustive;
mod manual_rem_euclid;
@@ -289,6 +290,7 @@ mod missing_const_for_fn;
mod missing_doc;
mod missing_enforced_import_rename;
mod missing_inline;
+mod missing_trait_methods;
mod mixed_read_write_in_expression;
mod module_style;
mod multi_assignments;
@@ -324,6 +326,7 @@ mod option_if_let_else;
mod overflow_check_conditional;
mod panic_in_result_fn;
mod panic_unimplemented;
+mod partial_pub_fields;
mod partialeq_ne_impl;
mod partialeq_to_none;
mod pass_by_ref_or_value;
@@ -417,15 +420,13 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, sess: &Se
let msrv = conf.msrv.as_ref().and_then(|s| {
parse_msrv(s, None, None).or_else(|| {
- sess.err(&format!(
- "error reading Clippy's configuration file. `{}` is not a valid Rust version",
- s
+ sess.err(format!(
+ "error reading Clippy's configuration file. `{s}` is not a valid Rust version"
));
None
})
});
- store.register_pre_expansion_pass(|| Box::new(write::Write::default()));
store.register_pre_expansion_pass(move || Box::new(attrs::EarlyAttributes { msrv }));
}
@@ -435,9 +436,8 @@ fn read_msrv(conf: &Conf, sess: &Session) -> Option<RustcVersion> {
.and_then(|v| parse_msrv(&v, None, None));
let clippy_msrv = conf.msrv.as_ref().and_then(|s| {
parse_msrv(s, None, None).or_else(|| {
- sess.err(&format!(
- "error reading Clippy's configuration file. `{}` is not a valid Rust version",
- s
+ sess.err(format!(
+ "error reading Clippy's configuration file. `{s}` is not a valid Rust version"
));
None
})
@@ -447,9 +447,8 @@ fn read_msrv(conf: &Conf, sess: &Session) -> Option<RustcVersion> {
if let Some(clippy_msrv) = clippy_msrv {
// if both files have an msrv, let's compare them and emit a warning if they differ
if clippy_msrv != cargo_msrv {
- sess.warn(&format!(
- "the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{}` from `clippy.toml`",
- clippy_msrv
+ sess.warn(format!(
+ "the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{clippy_msrv}` from `clippy.toml`"
));
}
@@ -468,7 +467,7 @@ pub fn read_conf(sess: &Session) -> Conf {
Ok(Some(path)) => path,
Ok(None) => return Conf::default(),
Err(error) => {
- sess.struct_err(&format!("error finding Clippy's configuration file: {}", error))
+ sess.struct_err(&format!("error finding Clippy's configuration file: {error}"))
.emit();
return Conf::default();
},
@@ -477,7 +476,7 @@ pub fn read_conf(sess: &Session) -> Conf {
let TryConf { conf, errors, warnings } = utils::conf::read(&file_name);
// all conf errors are non-fatal, we just use the default conf in case of error
for error in errors {
- sess.err(&format!(
+ sess.err(format!(
"error reading Clippy's configuration file `{}`: {}",
file_name.display(),
format_error(error)
@@ -485,7 +484,7 @@ pub fn read_conf(sess: &Session) -> Conf {
}
for warning in warnings {
- sess.struct_warn(&format!(
+ sess.struct_warn(format!(
"error reading Clippy's configuration file `{}`: {}",
file_name.display(),
format_error(warning)
@@ -524,7 +523,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
#[cfg(feature = "internal")]
{
if std::env::var("ENABLE_METADATA_COLLECTION").eq(&Ok("1".to_string())) {
- store.register_late_pass(|| Box::new(utils::internal_lints::metadata_collector::MetadataCollector::new()));
+ store.register_late_pass(|_| Box::new(utils::internal_lints::metadata_collector::MetadataCollector::new()));
return;
}
}
@@ -532,17 +531,23 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
// all the internal lints
#[cfg(feature = "internal")]
{
- store.register_early_pass(|| Box::new(utils::internal_lints::ClippyLintsInternal));
- store.register_early_pass(|| Box::new(utils::internal_lints::ProduceIce));
- store.register_late_pass(|_| Box::new(utils::internal_lints::CollapsibleCalls));
- store.register_late_pass(|_| Box::new(utils::internal_lints::CompilerLintFunctions::new()));
- store.register_late_pass(|_| Box::new(utils::internal_lints::IfChainStyle));
- store.register_late_pass(|_| Box::new(utils::internal_lints::InvalidPaths));
- store.register_late_pass(|_| Box::new(utils::internal_lints::InterningDefinedSymbol::default()));
- store.register_late_pass(|_| Box::new(utils::internal_lints::LintWithoutLintPass::default()));
- store.register_late_pass(|_| Box::new(utils::internal_lints::MatchTypeOnDiagItem));
- store.register_late_pass(|_| Box::new(utils::internal_lints::OuterExpnDataPass));
- store.register_late_pass(|_| Box::new(utils::internal_lints::MsrvAttrImpl));
+ store.register_early_pass(|| Box::new(utils::internal_lints::clippy_lints_internal::ClippyLintsInternal));
+ store.register_early_pass(|| Box::new(utils::internal_lints::produce_ice::ProduceIce));
+ store.register_late_pass(|_| Box::new(utils::internal_lints::collapsible_calls::CollapsibleCalls));
+ store.register_late_pass(|_| {
+ Box::new(utils::internal_lints::compiler_lint_functions::CompilerLintFunctions::new())
+ });
+ store.register_late_pass(|_| Box::new(utils::internal_lints::if_chain_style::IfChainStyle));
+ store.register_late_pass(|_| Box::new(utils::internal_lints::invalid_paths::InvalidPaths));
+ store.register_late_pass(|_| {
+ Box::<utils::internal_lints::interning_defined_symbol::InterningDefinedSymbol>::default()
+ });
+ store.register_late_pass(|_| {
+ Box::<utils::internal_lints::lint_without_lint_pass::LintWithoutLintPass>::default()
+ });
+ store.register_late_pass(|_| Box::<utils::internal_lints::unnecessary_def_path::UnnecessaryDefPath>::default());
+ store.register_late_pass(|_| Box::new(utils::internal_lints::outer_expn_data_pass::OuterExpnDataPass));
+ store.register_late_pass(|_| Box::new(utils::internal_lints::msrv_attr_impl::MsrvAttrImpl));
}
let arithmetic_side_effects_allowed = conf.arithmetic_side_effects_allowed.clone();
@@ -632,10 +637,10 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
msrv,
))
});
- store.register_late_pass(|_| Box::new(shadow::Shadow::default()));
+ store.register_late_pass(|_| Box::<shadow::Shadow>::default());
store.register_late_pass(|_| Box::new(unit_types::UnitTypes));
store.register_late_pass(|_| Box::new(loops::Loops));
- store.register_late_pass(|_| Box::new(main_recursion::MainRecursion::default()));
+ store.register_late_pass(|_| Box::<main_recursion::MainRecursion>::default());
store.register_late_pass(|_| Box::new(lifetimes::Lifetimes));
store.register_late_pass(|_| Box::new(entry::HashMapPass));
store.register_late_pass(|_| Box::new(minmax::MinMaxPass));
@@ -669,7 +674,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|_| Box::new(format::UselessFormat));
store.register_late_pass(|_| Box::new(swap::Swap));
store.register_late_pass(|_| Box::new(overflow_check_conditional::OverflowCheckConditional));
- store.register_late_pass(|_| Box::new(new_without_default::NewWithoutDefault::default()));
+ store.register_late_pass(|_| Box::<new_without_default::NewWithoutDefault>::default());
let disallowed_names = conf.disallowed_names.iter().cloned().collect::<FxHashSet<_>>();
store.register_late_pass(move |_| Box::new(disallowed_names::DisallowedNames::new(disallowed_names.clone())));
let too_many_arguments_threshold = conf.too_many_arguments_threshold;
@@ -708,7 +713,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|_| Box::new(ref_option_ref::RefOptionRef));
store.register_late_pass(|_| Box::new(infinite_iter::InfiniteIter));
store.register_late_pass(|_| Box::new(inline_fn_without_body::InlineFnWithoutBody));
- store.register_late_pass(|_| Box::new(useless_conversion::UselessConversion::default()));
+ store.register_late_pass(|_| Box::<useless_conversion::UselessConversion>::default());
store.register_late_pass(|_| Box::new(implicit_hasher::ImplicitHasher));
store.register_late_pass(|_| Box::new(fallible_impl_from::FallibleImplFrom));
store.register_late_pass(|_| Box::new(question_mark::QuestionMark));
@@ -778,7 +783,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
upper_case_acronyms_aggressive,
))
});
- store.register_late_pass(|_| Box::new(default::Default::default()));
+ store.register_late_pass(|_| Box::<default::Default>::default());
store.register_late_pass(move |_| Box::new(unused_self::UnusedSelf::new(avoid_breaking_exported_api)));
store.register_late_pass(|_| Box::new(mutable_debug_assertion::DebugAssertWithMutCall));
store.register_late_pass(|_| Box::new(exit::Exit));
@@ -801,7 +806,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_early_pass(|| Box::new(option_env_unwrap::OptionEnvUnwrap));
let warn_on_all_wildcard_imports = conf.warn_on_all_wildcard_imports;
store.register_late_pass(move |_| Box::new(wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports)));
- store.register_late_pass(|_| Box::new(redundant_pub_crate::RedundantPubCrate::default()));
+ store.register_late_pass(|_| Box::<redundant_pub_crate::RedundantPubCrate>::default());
store.register_late_pass(|_| Box::new(unnamed_address::UnnamedAddress));
store.register_late_pass(move |_| Box::new(dereference::Dereferencing::new(msrv)));
store.register_late_pass(|_| Box::new(option_if_let_else::OptionIfLetElse));
@@ -819,11 +824,13 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
});
let macro_matcher = conf.standard_macro_braces.iter().cloned().collect::<FxHashSet<_>>();
store.register_early_pass(move || Box::new(nonstandard_macro_braces::MacroBraces::new(&macro_matcher)));
- store.register_late_pass(|_| Box::new(macro_use::MacroUseImports::default()));
+ store.register_late_pass(|_| Box::<macro_use::MacroUseImports>::default());
store.register_late_pass(|_| Box::new(pattern_type_mismatch::PatternTypeMismatch));
store.register_late_pass(|_| Box::new(unwrap_in_result::UnwrapInResult));
store.register_late_pass(|_| Box::new(semicolon_if_nothing_returned::SemicolonIfNothingReturned));
store.register_late_pass(|_| Box::new(async_yields_async::AsyncYieldsAsync));
+ let disallowed_macros = conf.disallowed_macros.clone();
+ store.register_late_pass(move |_| Box::new(disallowed_macros::DisallowedMacros::new(disallowed_macros.clone())));
let disallowed_methods = conf.disallowed_methods.clone();
store.register_late_pass(move |_| Box::new(disallowed_methods::DisallowedMethods::new(disallowed_methods.clone())));
store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86AttSyntax));
@@ -832,7 +839,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|_| Box::new(strings::StrToString));
store.register_late_pass(|_| Box::new(strings::StringToString));
store.register_late_pass(|_| Box::new(zero_sized_map_values::ZeroSizedMapValues));
- store.register_late_pass(|_| Box::new(vec_init_then_push::VecInitThenPush::default()));
+ store.register_late_pass(|_| Box::<vec_init_then_push::VecInitThenPush>::default());
store.register_late_pass(|_| Box::new(redundant_slicing::RedundantSlicing));
store.register_late_pass(|_| Box::new(from_str_radix_10::FromStrRadix10));
store.register_late_pass(move |_| Box::new(if_then_some_else_none::IfThenSomeElseNone::new(msrv)));
@@ -860,7 +867,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
))
});
store.register_late_pass(move |_| Box::new(undocumented_unsafe_blocks::UndocumentedUnsafeBlocks));
- store.register_late_pass(move |_| Box::new(format_args::FormatArgs));
+ store.register_late_pass(move |_| Box::new(format_args::FormatArgs::new(msrv)));
store.register_late_pass(|_| Box::new(trailing_empty_array::TrailingEmptyArray));
store.register_early_pass(|| Box::new(octal_escapes::OctalEscapes));
store.register_late_pass(|_| Box::new(needless_late_init::NeedlessLateInit));
@@ -869,8 +876,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_early_pass(|| Box::new(single_char_lifetime_names::SingleCharLifetimeNames));
store.register_late_pass(move |_| Box::new(manual_bits::ManualBits::new(msrv)));
store.register_late_pass(|_| Box::new(default_union_representation::DefaultUnionRepresentation));
- store.register_early_pass(|| Box::new(doc_link_with_quotes::DocLinkWithQuotes));
- store.register_late_pass(|_| Box::new(only_used_in_recursion::OnlyUsedInRecursion::default()));
+ store.register_late_pass(|_| Box::<only_used_in_recursion::OnlyUsedInRecursion>::default());
let allow_dbg_in_tests = conf.allow_dbg_in_tests;
store.register_late_pass(move |_| Box::new(dbg_macro::DbgMacro::new(allow_dbg_in_tests)));
let cargo_ignore_publish = conf.cargo_ignore_publish;
@@ -879,6 +885,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
ignore_publish: cargo_ignore_publish,
})
});
+ store.register_late_pass(|_| Box::<write::Write>::default());
store.register_early_pass(|| Box::new(crate_in_macro_def::CrateInMacroDef));
store.register_early_pass(|| Box::new(empty_structs_with_brackets::EmptyStructsWithBrackets));
store.register_late_pass(|_| Box::new(unnecessary_owned_empty_strings::UnnecessaryOwnedEmptyStrings));
@@ -888,7 +895,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(move |_| Box::new(large_include_file::LargeIncludeFile::new(max_include_file_size)));
store.register_late_pass(|_| Box::new(strings::TrimSplitWhitespace));
store.register_late_pass(|_| Box::new(rc_clone_in_vec_init::RcCloneInVecInit));
- store.register_early_pass(|| Box::new(duplicate_mod::DuplicateMod::default()));
+ store.register_early_pass(|| Box::<duplicate_mod::DuplicateMod>::default());
store.register_early_pass(|| Box::new(unused_rounding::UnusedRounding));
store.register_early_pass(move || Box::new(almost_complete_letter_range::AlmostCompleteLetterRange::new(msrv)));
store.register_late_pass(|_| Box::new(swap_ptr_to_ref::SwapPtrToRef));
@@ -900,13 +907,18 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
let verbose_bit_mask_threshold = conf.verbose_bit_mask_threshold;
store.register_late_pass(move |_| Box::new(operators::Operators::new(verbose_bit_mask_threshold)));
store.register_late_pass(|_| Box::new(invalid_utf8_in_unchecked::InvalidUtf8InUnchecked));
- store.register_late_pass(|_| Box::new(std_instead_of_core::StdReexports::default()));
+ store.register_late_pass(|_| Box::<std_instead_of_core::StdReexports>::default());
store.register_late_pass(|_| Box::new(manual_instant_elapsed::ManualInstantElapsed));
store.register_late_pass(|_| Box::new(partialeq_to_none::PartialeqToNone));
+ store.register_late_pass(move |_| Box::new(manual_clamp::ManualClamp::new(msrv)));
store.register_late_pass(|_| Box::new(manual_string_new::ManualStringNew));
store.register_late_pass(|_| Box::new(unused_peekable::UnusedPeekable));
store.register_early_pass(|| Box::new(multi_assignments::MultiAssignments));
store.register_late_pass(|_| Box::new(bool_to_int_with_if::BoolToIntWithIf));
+ store.register_late_pass(|_| Box::new(box_default::BoxDefault));
+ store.register_late_pass(|_| Box::new(implicit_saturating_add::ImplicitSaturatingAdd));
+ store.register_early_pass(|| Box::new(partial_pub_fields::PartialPubFields));
+ store.register_late_pass(|_| Box::new(missing_trait_methods::MissingTraitMethods));
// add lints here, do not remove this comment, it's used in `new_lint`
}
diff --git a/src/tools/clippy/clippy_lints/src/lifetimes.rs b/src/tools/clippy/clippy_lints/src/lifetimes.rs
index 643a7cfd5..3bf2d7e4e 100644
--- a/src/tools/clippy/clippy_lints/src/lifetimes.rs
+++ b/src/tools/clippy/clippy_lints/src/lifetimes.rs
@@ -9,8 +9,8 @@ use rustc_hir::intravisit::{
use rustc_hir::FnRetTy::Return;
use rustc_hir::{
BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem,
- ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin,
- TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate,
+ ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin, TraitFn,
+ TraitItem, TraitItemKind, Ty, TyKind, WherePredicate,
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::nested_filter as middle_nested_filter;
@@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
if let ImplItemKind::Fn(ref sig, id) = item.kind {
- let report_extra_lifetimes = trait_ref_of_method(cx, item.def_id).is_none();
+ let report_extra_lifetimes = trait_ref_of_method(cx, item.owner_id.def_id).is_none();
check_fn_inner(
cx,
sig.decl,
diff --git a/src/tools/clippy/clippy_lints/src/literal_representation.rs b/src/tools/clippy/clippy_lints/src/literal_representation.rs
index fb2104861..25f19b9c6 100644
--- a/src/tools/clippy/clippy_lints/src/literal_representation.rs
+++ b/src/tools/clippy/clippy_lints/src/literal_representation.rs
@@ -478,7 +478,7 @@ impl DecimalLiteralRepresentation {
if num_lit.radix == Radix::Decimal;
if val >= u128::from(self.threshold);
then {
- let hex = format!("{:#X}", val);
+ let hex = format!("{val:#X}");
let num_lit = NumericLiteral::new(&hex, num_lit.suffix, false);
let _ = Self::do_lint(num_lit.integer).map_err(|warning_type| {
warning_type.display(num_lit.format(), cx, lit.span);
diff --git a/src/tools/clippy/clippy_lints/src/loops/explicit_counter_loop.rs b/src/tools/clippy/clippy_lints/src/loops/explicit_counter_loop.rs
index 8e3ab26a9..14f223481 100644
--- a/src/tools/clippy/clippy_lints/src/loops/explicit_counter_loop.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/explicit_counter_loop.rs
@@ -44,11 +44,10 @@ pub(super) fn check<'tcx>(
cx,
EXPLICIT_COUNTER_LOOP,
span,
- &format!("the variable `{}` is used as a loop counter", name),
+ &format!("the variable `{name}` is used as a loop counter"),
"consider using",
format!(
- "for ({}, {}) in {}.enumerate()",
- name,
+ "for ({name}, {}) in {}.enumerate()",
snippet_with_applicability(cx, pat.span, "item", &mut applicability),
make_iterator_snippet(cx, arg, &mut applicability),
),
@@ -65,24 +64,21 @@ pub(super) fn check<'tcx>(
cx,
EXPLICIT_COUNTER_LOOP,
span,
- &format!("the variable `{}` is used as a loop counter", name),
+ &format!("the variable `{name}` is used as a loop counter"),
|diag| {
diag.span_suggestion(
span,
"consider using",
format!(
- "for ({}, {}) in (0_{}..).zip({})",
- name,
+ "for ({name}, {}) in (0_{int_name}..).zip({})",
snippet_with_applicability(cx, pat.span, "item", &mut applicability),
- int_name,
make_iterator_snippet(cx, arg, &mut applicability),
),
applicability,
);
diag.note(&format!(
- "`{}` is of type `{}`, making it ineligible for `Iterator::enumerate`",
- name, int_name
+ "`{name}` is of type `{int_name}`, making it ineligible for `Iterator::enumerate`"
));
},
);
diff --git a/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs b/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs
index 5f5beccd0..b1f294162 100644
--- a/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs
@@ -41,7 +41,7 @@ pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, arg: &Expr<'_>, m
"it is more concise to loop over references to containers instead of using explicit \
iteration methods",
"to write this more concisely, try",
- format!("&{}{}", muta, object),
+ format!("&{muta}{object}"),
applicability,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/loops/for_kv_map.rs b/src/tools/clippy/clippy_lints/src/loops/for_kv_map.rs
index bee0e1d76..ed620460d 100644
--- a/src/tools/clippy/clippy_lints/src/loops/for_kv_map.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/for_kv_map.rs
@@ -38,7 +38,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx
cx,
FOR_KV_MAP,
arg_span,
- &format!("you seem to want to iterate on a map's {}s", kind),
+ &format!("you seem to want to iterate on a map's {kind}s"),
|diag| {
let map = sugg::Sugg::hir(cx, arg, "map");
multispan_sugg(
@@ -46,7 +46,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx
"use the corresponding method",
vec![
(pat_span, snippet(cx, new_pat_span, kind).into_owned()),
- (arg_span, format!("{}.{}s{}()", map.maybe_par(), kind, mutbl)),
+ (arg_span, format!("{}.{kind}s{mutbl}()", map.maybe_par())),
],
);
},
diff --git a/src/tools/clippy/clippy_lints/src/loops/for_loops_over_fallibles.rs b/src/tools/clippy/clippy_lints/src/loops/for_loops_over_fallibles.rs
deleted file mode 100644
index 77de90fd7..000000000
--- a/src/tools/clippy/clippy_lints/src/loops/for_loops_over_fallibles.rs
+++ /dev/null
@@ -1,65 +0,0 @@
-use super::FOR_LOOPS_OVER_FALLIBLES;
-use clippy_utils::diagnostics::span_lint_and_help;
-use clippy_utils::source::snippet;
-use clippy_utils::ty::is_type_diagnostic_item;
-use rustc_hir::{Expr, Pat};
-use rustc_lint::LateContext;
-use rustc_span::symbol::sym;
-
-/// Checks for `for` loops over `Option`s and `Result`s.
-pub(super) fn check(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>, method_name: Option<&str>) {
- let ty = cx.typeck_results().expr_ty(arg);
- if is_type_diagnostic_item(cx, ty, sym::Option) {
- let help_string = if let Some(method_name) = method_name {
- format!(
- "consider replacing `for {0} in {1}.{method_name}()` with `if let Some({0}) = {1}`",
- snippet(cx, pat.span, "_"),
- snippet(cx, arg.span, "_")
- )
- } else {
- format!(
- "consider replacing `for {0} in {1}` with `if let Some({0}) = {1}`",
- snippet(cx, pat.span, "_"),
- snippet(cx, arg.span, "_")
- )
- };
- span_lint_and_help(
- cx,
- FOR_LOOPS_OVER_FALLIBLES,
- arg.span,
- &format!(
- "for loop over `{0}`, which is an `Option`. This is more readably written as an \
- `if let` statement",
- snippet(cx, arg.span, "_")
- ),
- None,
- &help_string,
- );
- } else if is_type_diagnostic_item(cx, ty, sym::Result) {
- let help_string = if let Some(method_name) = method_name {
- format!(
- "consider replacing `for {0} in {1}.{method_name}()` with `if let Ok({0}) = {1}`",
- snippet(cx, pat.span, "_"),
- snippet(cx, arg.span, "_")
- )
- } else {
- format!(
- "consider replacing `for {0} in {1}` with `if let Ok({0}) = {1}`",
- snippet(cx, pat.span, "_"),
- snippet(cx, arg.span, "_")
- )
- };
- span_lint_and_help(
- cx,
- FOR_LOOPS_OVER_FALLIBLES,
- arg.span,
- &format!(
- "for loop over `{0}`, which is a `Result`. This is more readably written as an \
- `if let` statement",
- snippet(cx, arg.span, "_")
- ),
- None,
- &help_string,
- );
- }
-}
diff --git a/src/tools/clippy/clippy_lints/src/loops/iter_next_loop.rs b/src/tools/clippy/clippy_lints/src/loops/iter_next_loop.rs
index e640c62eb..b8a263817 100644
--- a/src/tools/clippy/clippy_lints/src/loops/iter_next_loop.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/iter_next_loop.rs
@@ -5,7 +5,7 @@ use rustc_hir::Expr;
use rustc_lint::LateContext;
use rustc_span::sym;
-pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>) -> bool {
+pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>) {
if is_trait_method(cx, arg, sym::Iterator) {
span_lint(
cx,
@@ -14,8 +14,5 @@ pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>) -> bool {
"you are iterating over `Iterator::next()` which is an Option; this will compile but is \
probably not what you want",
);
- true
- } else {
- false
}
}
diff --git a/src/tools/clippy/clippy_lints/src/loops/manual_find.rs b/src/tools/clippy/clippy_lints/src/loops/manual_find.rs
index 09b2376d5..4bb9936e9 100644
--- a/src/tools/clippy/clippy_lints/src/loops/manual_find.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/manual_find.rs
@@ -1,7 +1,7 @@
use super::utils::make_iterator_snippet;
use super::MANUAL_FIND;
use clippy_utils::{
- diagnostics::span_lint_and_then, higher, is_lang_ctor, path_res, peel_blocks_with_stmt,
+ diagnostics::span_lint_and_then, higher, is_res_lang_ctor, path_res, peel_blocks_with_stmt,
source::snippet_with_applicability, ty::implements_trait,
};
use if_chain::if_chain;
@@ -30,8 +30,8 @@ pub(super) fn check<'tcx>(
if let [stmt] = block.stmts;
if let StmtKind::Semi(semi) = stmt.kind;
if let ExprKind::Ret(Some(ret_value)) = semi.kind;
- if let ExprKind::Call(Expr { kind: ExprKind::Path(ctor), .. }, [inner_ret]) = ret_value.kind;
- if is_lang_ctor(cx, ctor, LangItem::OptionSome);
+ if let ExprKind::Call(ctor, [inner_ret]) = ret_value.kind;
+ if is_res_lang_ctor(cx, path_res(cx, ctor), LangItem::OptionSome);
if path_res(cx, inner_ret) == Res::Local(binding_id);
if let Some((last_stmt, last_ret)) = last_stmt_and_ret(cx, expr);
then {
@@ -143,8 +143,7 @@ fn last_stmt_and_ret<'tcx>(
if let Some((_, Node::Block(block))) = parent_iter.next();
if let Some((last_stmt, last_ret)) = extract(block);
if last_stmt.hir_id == node_hir;
- if let ExprKind::Path(path) = &last_ret.kind;
- if is_lang_ctor(cx, path, LangItem::OptionNone);
+ if is_res_lang_ctor(cx, path_res(cx, last_ret), LangItem::OptionNone);
if let Some((_, Node::Expr(_block))) = parent_iter.next();
// This includes the function header
if let Some((_, func)) = parent_iter.next();
diff --git a/src/tools/clippy/clippy_lints/src/loops/manual_flatten.rs b/src/tools/clippy/clippy_lints/src/loops/manual_flatten.rs
index 1d6ddf4b9..8c27c0940 100644
--- a/src/tools/clippy/clippy_lints/src/loops/manual_flatten.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/manual_flatten.rs
@@ -3,13 +3,13 @@ use super::MANUAL_FLATTEN;
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::higher;
use clippy_utils::visitors::is_local_used;
-use clippy_utils::{is_lang_ctor, path_to_local_id, peel_blocks_with_stmt};
+use clippy_utils::{path_to_local_id, peel_blocks_with_stmt};
use if_chain::if_chain;
use rustc_errors::Applicability;
-use rustc_hir::LangItem::{OptionSome, ResultOk};
+use rustc_hir::def::{DefKind, Res};
use rustc_hir::{Expr, Pat, PatKind};
use rustc_lint::LateContext;
-use rustc_middle::ty;
+use rustc_middle::ty::{self, DefIdTree};
use rustc_span::source_map::Span;
/// Check for unnecessary `if let` usage in a for loop where only the `Some` or `Ok` variant of the
@@ -30,15 +30,17 @@ pub(super) fn check<'tcx>(
if path_to_local_id(let_expr, pat_hir_id);
// Ensure the `if let` statement is for the `Some` variant of `Option` or the `Ok` variant of `Result`
if let PatKind::TupleStruct(ref qpath, _, _) = let_pat.kind;
- let some_ctor = is_lang_ctor(cx, qpath, OptionSome);
- let ok_ctor = is_lang_ctor(cx, qpath, ResultOk);
+ if let Res::Def(DefKind::Ctor(..), ctor_id) = cx.qpath_res(qpath, let_pat.hir_id);
+ if let Some(variant_id) = cx.tcx.opt_parent(ctor_id);
+ let some_ctor = cx.tcx.lang_items().option_some_variant() == Some(variant_id);
+ let ok_ctor = cx.tcx.lang_items().result_ok_variant() == Some(variant_id);
if some_ctor || ok_ctor;
// Ensure expr in `if let` is not used afterwards
if !is_local_used(cx, if_then, pat_hir_id);
then {
let if_let_type = if some_ctor { "Some" } else { "Ok" };
// Prepare the error message
- let msg = format!("unnecessary `if let` since only the `{}` variant of the iterator element is used", if_let_type);
+ let msg = format!("unnecessary `if let` since only the `{if_let_type}` variant of the iterator element is used");
// Prepare the help message
let mut applicability = Applicability::MaybeIncorrect;
diff --git a/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs b/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs
index 3fc569af8..c87fc4f90 100644
--- a/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs
@@ -177,13 +177,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
let dst = if dst_offset == sugg::EMPTY && dst_limit == sugg::EMPTY {
dst_base_str
} else {
- format!(
- "{}[{}..{}]",
- dst_base_str,
- dst_offset.maybe_par(),
- dst_limit.maybe_par()
- )
- .into()
+ format!("{dst_base_str}[{}..{}]", dst_offset.maybe_par(), dst_limit.maybe_par()).into()
};
let method_str = if is_copy(cx, elem_ty) {
@@ -193,10 +187,7 @@ fn build_manual_memcpy_suggestion<'tcx>(
};
format!(
- "{}.{}(&{}[{}..{}]);",
- dst,
- method_str,
- src_base_str,
+ "{dst}.{method_str}(&{src_base_str}[{}..{}]);",
src_offset.maybe_par(),
src_limit.maybe_par()
)
diff --git a/src/tools/clippy/clippy_lints/src/loops/mod.rs b/src/tools/clippy/clippy_lints/src/loops/mod.rs
index 74f3bda9f..bcf278d9c 100644
--- a/src/tools/clippy/clippy_lints/src/loops/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/mod.rs
@@ -3,7 +3,6 @@ mod explicit_counter_loop;
mod explicit_into_iter_loop;
mod explicit_iter_loop;
mod for_kv_map;
-mod for_loops_over_fallibles;
mod iter_next_loop;
mod manual_find;
mod manual_flatten;
@@ -175,49 +174,6 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
- /// Checks for `for` loops over `Option` or `Result` values.
- ///
- /// ### Why is this bad?
- /// Readability. This is more clearly expressed as an `if
- /// let`.
- ///
- /// ### Example
- /// ```rust
- /// # let opt = Some(1);
- /// # let res: Result<i32, std::io::Error> = Ok(1);
- /// for x in opt {
- /// // ..
- /// }
- ///
- /// for x in &res {
- /// // ..
- /// }
- ///
- /// for x in res.iter() {
- /// // ..
- /// }
- /// ```
- ///
- /// Use instead:
- /// ```rust
- /// # let opt = Some(1);
- /// # let res: Result<i32, std::io::Error> = Ok(1);
- /// if let Some(x) = opt {
- /// // ..
- /// }
- ///
- /// if let Ok(x) = res {
- /// // ..
- /// }
- /// ```
- #[clippy::version = "1.45.0"]
- pub FOR_LOOPS_OVER_FALLIBLES,
- suspicious,
- "for-looping over an `Option` or a `Result`, which is more clearly expressed as an `if let`"
-}
-
-declare_clippy_lint! {
- /// ### What it does
/// Detects `loop + match` combinations that are easier
/// written as a `while let` loop.
///
@@ -635,7 +591,7 @@ declare_clippy_lint! {
/// arr.into_iter().find(|&el| el == 1)
/// }
/// ```
- #[clippy::version = "1.61.0"]
+ #[clippy::version = "1.64.0"]
pub MANUAL_FIND,
complexity,
"manual implementation of `Iterator::find`"
@@ -648,7 +604,6 @@ declare_lint_pass!(Loops => [
EXPLICIT_ITER_LOOP,
EXPLICIT_INTO_ITER_LOOP,
ITER_NEXT_LOOP,
- FOR_LOOPS_OVER_FALLIBLES,
WHILE_LET_LOOP,
NEEDLESS_COLLECT,
EXPLICIT_COUNTER_LOOP,
@@ -739,30 +694,22 @@ fn check_for_loop<'tcx>(
manual_find::check(cx, pat, arg, body, span, expr);
}
-fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
- let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used
-
+fn check_for_loop_arg(cx: &LateContext<'_>, _: &Pat<'_>, arg: &Expr<'_>) {
if let ExprKind::MethodCall(method, self_arg, [], _) = arg.kind {
let method_name = method.ident.as_str();
// check for looping over x.iter() or x.iter_mut(), could use &x or &mut x
match method_name {
"iter" | "iter_mut" => {
explicit_iter_loop::check(cx, self_arg, arg, method_name);
- for_loops_over_fallibles::check(cx, pat, self_arg, Some(method_name));
},
"into_iter" => {
explicit_iter_loop::check(cx, self_arg, arg, method_name);
explicit_into_iter_loop::check(cx, self_arg, arg);
- for_loops_over_fallibles::check(cx, pat, self_arg, Some(method_name));
},
"next" => {
- next_loop_linted = iter_next_loop::check(cx, arg);
+ iter_next_loop::check(cx, arg);
},
_ => {},
}
}
-
- if !next_loop_linted {
- for_loops_over_fallibles::check(cx, pat, arg, None);
- }
}
diff --git a/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs b/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs
index fce2d5463..91b321c44 100644
--- a/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs
@@ -4,11 +4,11 @@ use clippy_utils::{get_enclosing_block, higher, path_to_local};
use if_chain::if_chain;
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{BindingAnnotation, Expr, ExprKind, HirId, Node, PatKind};
+use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::LateContext;
use rustc_middle::{mir::FakeReadCause, ty};
use rustc_span::source_map::Span;
-use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'_>) {
if_chain! {
@@ -65,16 +65,15 @@ fn check_for_mutation<'tcx>(
span_low: None,
span_high: None,
};
- cx.tcx.infer_ctxt().enter(|infcx| {
- ExprUseVisitor::new(
- &mut delegate,
- &infcx,
- body.hir_id.owner,
- cx.param_env,
- cx.typeck_results(),
- )
- .walk_expr(body);
- });
+ let infcx = cx.tcx.infer_ctxt().build();
+ ExprUseVisitor::new(
+ &mut delegate,
+ &infcx,
+ body.hir_id.owner.def_id,
+ cx.param_env,
+ cx.typeck_results(),
+ )
+ .walk_expr(body);
delegate.mutation_span()
}
@@ -114,7 +113,13 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
}
}
- fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {}
+ fn fake_read(
+ &mut self,
+ _: &rustc_hir_typeck::expr_use_visitor::PlaceWithHirId<'tcx>,
+ _: FakeReadCause,
+ _: HirId,
+ ) {
+ }
}
impl MutatePairDelegate<'_, '_> {
diff --git a/src/tools/clippy/clippy_lints/src/loops/needless_collect.rs b/src/tools/clippy/clippy_lints/src/loops/needless_collect.rs
index 6e6faa79a..66f9e2859 100644
--- a/src/tools/clippy/clippy_lints/src/loops/needless_collect.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/needless_collect.rs
@@ -45,7 +45,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
let (arg, pred) = contains_arg
.strip_prefix('&')
.map_or(("&x", &*contains_arg), |s| ("x", s));
- format!("any(|{}| x == {})", arg, pred)
+ format!("any(|{arg}| x == {pred})")
}
_ => return,
}
@@ -141,9 +141,9 @@ impl IterFunction {
IterFunctionKind::Contains(span) => {
let s = snippet(cx, *span, "..");
if let Some(stripped) = s.strip_prefix('&') {
- format!(".any(|x| x == {})", stripped)
+ format!(".any(|x| x == {stripped})")
} else {
- format!(".any(|x| x == *{})", s)
+ format!(".any(|x| x == *{s})")
}
},
}
diff --git a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs
index 8ab640051..27ba27202 100644
--- a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs
@@ -3,7 +3,7 @@ use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_then};
use clippy_utils::source::snippet;
use clippy_utils::ty::has_iter_method;
use clippy_utils::visitors::is_local_used;
-use clippy_utils::{contains_name, higher, is_integer_const, match_trait_method, paths, sugg, SpanlessEq};
+use clippy_utils::{contains_name, higher, is_integer_const, sugg, SpanlessEq};
use if_chain::if_chain;
use rustc_ast::ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -145,7 +145,7 @@ pub(super) fn check<'tcx>(
cx,
NEEDLESS_RANGE_LOOP,
arg.span,
- &format!("the loop variable `{}` is used to index `{}`", ident.name, indexed),
+ &format!("the loop variable `{}` is used to index `{indexed}`", ident.name),
|diag| {
multispan_sugg(
diag,
@@ -154,7 +154,7 @@ pub(super) fn check<'tcx>(
(pat.span, format!("({}, <item>)", ident.name)),
(
arg.span,
- format!("{}.{}().enumerate(){}{}", indexed, method, method_1, method_2),
+ format!("{indexed}.{method}().enumerate(){method_1}{method_2}"),
),
],
);
@@ -162,16 +162,16 @@ pub(super) fn check<'tcx>(
);
} else {
let repl = if starts_at_zero && take_is_empty {
- format!("&{}{}", ref_mut, indexed)
+ format!("&{ref_mut}{indexed}")
} else {
- format!("{}.{}(){}{}", indexed, method, method_1, method_2)
+ format!("{indexed}.{method}(){method_1}{method_2}")
};
span_lint_and_then(
cx,
NEEDLESS_RANGE_LOOP,
arg.span,
- &format!("the loop variable `{}` is only used to index `{}`", ident.name, indexed),
+ &format!("the loop variable `{}` is only used to index `{indexed}`", ident.name),
|diag| {
multispan_sugg(
diag,
@@ -263,7 +263,8 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
match res {
Res::Local(hir_id) => {
let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
- let extent = self.cx
+ let extent = self
+ .cx
.tcx
.region_scope_tree(parent_def_id)
.var_scope(hir_id.local_id)
@@ -274,11 +275,12 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
(Some(extent), self.cx.typeck_results().node_type(seqexpr.hir_id)),
);
} else {
- self.indexed_indirectly.insert(seqvar.segments[0].ident.name, Some(extent));
+ self.indexed_indirectly
+ .insert(seqvar.segments[0].ident.name, Some(extent));
}
- return false; // no need to walk further *on the variable*
- }
- Res::Def(DefKind::Static (_)| DefKind::Const, ..) => {
+ return false; // no need to walk further *on the variable*
+ },
+ Res::Def(DefKind::Static(_) | DefKind::Const, ..) => {
if index_used_directly {
self.indexed_directly.insert(
seqvar.segments[0].ident.name,
@@ -287,8 +289,8 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
} else {
self.indexed_indirectly.insert(seqvar.segments[0].ident.name, None);
}
- return false; // no need to walk further *on the variable*
- }
+ return false; // no need to walk further *on the variable*
+ },
_ => (),
}
}
@@ -302,17 +304,26 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
if_chain! {
// a range index op
if let ExprKind::MethodCall(meth, args_0, [args_1, ..], _) = &expr.kind;
- if (meth.ident.name == sym::index && match_trait_method(self.cx, expr, &paths::INDEX))
- || (meth.ident.name == sym::index_mut && match_trait_method(self.cx, expr, &paths::INDEX_MUT));
+ if let Some(trait_id) = self
+ .cx
+ .typeck_results()
+ .type_dependent_def_id(expr.hir_id)
+ .and_then(|def_id| self.cx.tcx.trait_of_item(def_id));
+ if (meth.ident.name == sym::index && self.cx.tcx.lang_items().index_trait() == Some(trait_id))
+ || (meth.ident.name == sym::index_mut && self.cx.tcx.lang_items().index_mut_trait() == Some(trait_id));
if !self.check(args_1, args_0, expr);
- then { return }
+ then {
+ return;
+ }
}
if_chain! {
// an index op
if let ExprKind::Index(seqexpr, idx) = expr.kind;
if !self.check(idx, seqexpr, expr);
- then { return }
+ then {
+ return;
+ }
}
if_chain! {
diff --git a/src/tools/clippy/clippy_lints/src/loops/never_loop.rs b/src/tools/clippy/clippy_lints/src/loops/never_loop.rs
index 116e589ca..16b00ad66 100644
--- a/src/tools/clippy/clippy_lints/src/loops/never_loop.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/never_loop.rs
@@ -42,6 +42,7 @@ pub(super) fn check(
}
}
+#[derive(Copy, Clone)]
enum NeverLoopResult {
// A break/return always get triggered but not necessarily for the main loop.
AlwaysBreak,
@@ -51,8 +52,8 @@ enum NeverLoopResult {
}
#[must_use]
-fn absorb_break(arg: &NeverLoopResult) -> NeverLoopResult {
- match *arg {
+fn absorb_break(arg: NeverLoopResult) -> NeverLoopResult {
+ match arg {
NeverLoopResult::AlwaysBreak | NeverLoopResult::Otherwise => NeverLoopResult::Otherwise,
NeverLoopResult::MayContinueMainLoop => NeverLoopResult::MayContinueMainLoop,
}
@@ -92,19 +93,29 @@ fn combine_branches(b1: NeverLoopResult, b2: NeverLoopResult) -> NeverLoopResult
}
fn never_loop_block(block: &Block<'_>, main_loop_id: HirId) -> NeverLoopResult {
- let mut iter = block.stmts.iter().filter_map(stmt_to_expr).chain(block.expr);
+ let mut iter = block
+ .stmts
+ .iter()
+ .filter_map(stmt_to_expr)
+ .chain(block.expr.map(|expr| (expr, None)));
never_loop_expr_seq(&mut iter, main_loop_id)
}
-fn never_loop_expr_seq<'a, T: Iterator<Item = &'a Expr<'a>>>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult {
- es.map(|e| never_loop_expr(e, main_loop_id))
- .fold(NeverLoopResult::Otherwise, combine_seq)
+fn never_loop_expr_seq<'a, T: Iterator<Item = (&'a Expr<'a>, Option<&'a Block<'a>>)>>(
+ es: &mut T,
+ main_loop_id: HirId,
+) -> NeverLoopResult {
+ es.map(|(e, els)| {
+ let e = never_loop_expr(e, main_loop_id);
+ els.map_or(e, |els| combine_branches(e, never_loop_block(els, main_loop_id)))
+ })
+ .fold(NeverLoopResult::Otherwise, combine_seq)
}
-fn stmt_to_expr<'tcx>(stmt: &Stmt<'tcx>) -> Option<&'tcx Expr<'tcx>> {
+fn stmt_to_expr<'tcx>(stmt: &Stmt<'tcx>) -> Option<(&'tcx Expr<'tcx>, Option<&'tcx Block<'tcx>>)> {
match stmt.kind {
- StmtKind::Semi(e, ..) | StmtKind::Expr(e, ..) => Some(e),
- StmtKind::Local(local) => local.init,
+ StmtKind::Semi(e, ..) | StmtKind::Expr(e, ..) => Some((e, None)),
+ StmtKind::Local(local) => local.init.map(|init| (init, local.els)),
StmtKind::Item(..) => None,
}
}
@@ -139,7 +150,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
| ExprKind::Index(e1, e2) => never_loop_expr_all(&mut [e1, e2].iter().copied(), main_loop_id),
ExprKind::Loop(b, _, _, _) => {
// Break can come from the inner loop so remove them.
- absorb_break(&never_loop_block(b, main_loop_id))
+ absorb_break(never_loop_block(b, main_loop_id))
},
ExprKind::If(e, e2, e3) => {
let e1 = never_loop_expr(e, main_loop_id);
@@ -211,9 +222,5 @@ fn for_to_if_let_sugg(cx: &LateContext<'_>, iterator: &Expr<'_>, pat: &Pat<'_>)
let pat_snippet = snippet(cx, pat.span, "_");
let iter_snippet = make_iterator_snippet(cx, iterator, &mut Applicability::Unspecified);
- format!(
- "if let Some({pat}) = {iter}.next()",
- pat = pat_snippet,
- iter = iter_snippet
- )
+ format!("if let Some({pat_snippet}) = {iter_snippet}.next()")
}
diff --git a/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs b/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs
index aeefe6e33..07edee46f 100644
--- a/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs
@@ -30,10 +30,7 @@ pub(super) fn check<'tcx>(
vec.span,
"it looks like the same item is being pushed into this Vec",
None,
- &format!(
- "try using vec![{};SIZE] or {}.resize(NEW_SIZE, {})",
- item_str, vec_str, item_str
- ),
+ &format!("try using vec![{item_str};SIZE] or {vec_str}.resize(NEW_SIZE, {item_str})"),
);
}
diff --git a/src/tools/clippy/clippy_lints/src/loops/utils.rs b/src/tools/clippy/clippy_lints/src/loops/utils.rs
index 4801a84eb..b6f4cf7bb 100644
--- a/src/tools/clippy/clippy_lints/src/loops/utils.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/utils.rs
@@ -5,12 +5,12 @@ use rustc_ast::ast::{LitIntType, LitKind};
use rustc_errors::Applicability;
use rustc_hir::intravisit::{walk_expr, walk_local, walk_pat, walk_stmt, Visitor};
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, Local, Mutability, Pat, PatKind, Stmt};
+use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::LateContext;
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, Ty};
use rustc_span::source_map::Spanned;
use rustc_span::symbol::{sym, Symbol};
-use rustc_typeck::hir_ty_to_ty;
use std::iter::Iterator;
#[derive(Debug, PartialEq, Eq)]
@@ -344,9 +344,8 @@ pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic
_ => arg,
};
format!(
- "{}.{}()",
+ "{}.{method_name}()",
sugg::Sugg::hir_with_applicability(cx, caller, "_", applic_ref).maybe_par(),
- method_name,
)
},
_ => format!(
diff --git a/src/tools/clippy/clippy_lints/src/loops/while_let_on_iterator.rs b/src/tools/clippy/clippy_lints/src/loops/while_let_on_iterator.rs
index deb21894f..55989f8a4 100644
--- a/src/tools/clippy/clippy_lints/src/loops/while_let_on_iterator.rs
+++ b/src/tools/clippy/clippy_lints/src/loops/while_let_on_iterator.rs
@@ -3,13 +3,12 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::higher;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::{
- get_enclosing_loop_or_multi_call_closure, is_refutable, is_trait_method, match_def_path, paths,
- visitors::is_res_used,
+ get_enclosing_loop_or_multi_call_closure, is_refutable, is_res_lang_ctor, is_trait_method, visitors::is_res_used,
};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::intravisit::{walk_expr, Visitor};
-use rustc_hir::{def::Res, Closure, Expr, ExprKind, HirId, Local, Mutability, PatKind, QPath, UnOp};
+use rustc_hir::{def::Res, Closure, Expr, ExprKind, HirId, LangItem, Local, Mutability, PatKind, UnOp};
use rustc_lint::LateContext;
use rustc_middle::hir::nested_filter::OnlyBodies;
use rustc_middle::ty::adjustment::Adjust;
@@ -19,9 +18,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
let (scrutinee_expr, iter_expr_struct, iter_expr, some_pat, loop_expr) = if_chain! {
if let Some(higher::WhileLet { if_then, let_pat, let_expr }) = higher::WhileLet::hir(expr);
// check for `Some(..)` pattern
- if let PatKind::TupleStruct(QPath::Resolved(None, pat_path), some_pat, _) = let_pat.kind;
- if let Res::Def(_, pat_did) = pat_path.res;
- if match_def_path(cx, pat_did, &paths::OPTION_SOME);
+ if let PatKind::TupleStruct(ref pat_path, some_pat, _) = let_pat.kind;
+ if is_res_lang_ctor(cx, cx.qpath_res(pat_path, let_pat.hir_id), LangItem::OptionSome);
// check for call to `Iterator::next`
if let ExprKind::MethodCall(method_name, iter_expr, [], _) = let_expr.kind;
if method_name.ident.name == sym::next;
@@ -67,7 +65,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
expr.span.with_hi(scrutinee_expr.span.hi()),
"this loop could be written as a `for` loop",
"try",
- format!("for {} in {}{}", loop_var, iterator, by_ref),
+ format!("for {loop_var} in {iterator}{by_ref}"),
applicability,
);
}
@@ -333,9 +331,8 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
}
if let Some(e) = get_enclosing_loop_or_multi_call_closure(cx, loop_expr) {
- let local_id = match iter_expr.path {
- Res::Local(id) => id,
- _ => return true,
+ let Res::Local(local_id) = iter_expr.path else {
+ return true
};
let mut v = NestedLoopVisitor {
cx,
diff --git a/src/tools/clippy/clippy_lints/src/macro_use.rs b/src/tools/clippy/clippy_lints/src/macro_use.rs
index d573a1b4f..594f6af76 100644
--- a/src/tools/clippy/clippy_lints/src/macro_use.rs
+++ b/src/tools/clippy/clippy_lints/src/macro_use.rs
@@ -189,9 +189,9 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports {
let mut suggestions = vec![];
for ((root, span, hir_id), path) in used {
if path.len() == 1 {
- suggestions.push((span, format!("{}::{}", root, path[0]), hir_id));
+ suggestions.push((span, format!("{root}::{}", path[0]), hir_id));
} else {
- suggestions.push((span, format!("{}::{{{}}}", root, path.join(", ")), hir_id));
+ suggestions.push((span, format!("{root}::{{{}}}", path.join(", ")), hir_id));
}
}
@@ -199,7 +199,7 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports {
// such as `std::prelude::v1::foo` or some other macro that expands to an import.
if self.mac_refs.is_empty() {
for (span, import, hir_id) in suggestions {
- let help = format!("use {};", import);
+ let help = format!("use {import};");
span_lint_hir_and_then(
cx,
MACRO_USE_IMPORTS,
diff --git a/src/tools/clippy/clippy_lints/src/manual_assert.rs b/src/tools/clippy/clippy_lints/src/manual_assert.rs
index 26b53ab5d..b8ed9b9ec 100644
--- a/src/tools/clippy/clippy_lints/src/manual_assert.rs
+++ b/src/tools/clippy/clippy_lints/src/manual_assert.rs
@@ -1,7 +1,8 @@
-use clippy_utils::diagnostics::span_lint_and_sugg;
+use crate::rustc_lint::LintContext;
+use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::macros::{root_macro_call, FormatArgsExpn};
use clippy_utils::source::snippet_with_applicability;
-use clippy_utils::{peel_blocks_with_stmt, sugg};
+use clippy_utils::{peel_blocks_with_stmt, span_extract_comment, sugg};
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, UnOp};
use rustc_lint::{LateContext, LateLintPass};
@@ -50,20 +51,38 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert {
let mut applicability = Applicability::MachineApplicable;
let format_args_snip = snippet_with_applicability(cx, format_args.inputs_span(), "..", &mut applicability);
let cond = cond.peel_drop_temps();
+ let mut comments = span_extract_comment(cx.sess().source_map(), expr.span);
+ if !comments.is_empty() {
+ comments += "\n";
+ }
let (cond, not) = match cond.kind {
ExprKind::Unary(UnOp::Not, e) => (e, ""),
_ => (cond, "!"),
};
let cond_sugg = sugg::Sugg::hir_with_applicability(cx, cond, "..", &mut applicability).maybe_par();
let sugg = format!("assert!({not}{cond_sugg}, {format_args_snip});");
- span_lint_and_sugg(
+ // we show to the user the suggestion without the comments, but when applicating the fix, include the comments in the block
+ span_lint_and_then(
cx,
MANUAL_ASSERT,
expr.span,
"only a `panic!` in `if`-then statement",
- "try",
- sugg,
- Applicability::MachineApplicable,
+ |diag| {
+ // comments can be noisy, do not show them to the user
+ if !comments.is_empty() {
+ diag.tool_only_span_suggestion(
+ expr.span.shrink_to_lo(),
+ "add comments back",
+ comments,
+ applicability);
+ }
+ diag.span_suggestion(
+ expr.span,
+ "try instead",
+ sugg,
+ applicability);
+ }
+
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/manual_async_fn.rs b/src/tools/clippy/clippy_lints/src/manual_async_fn.rs
index 754b0e78a..090f9f8ff 100644
--- a/src/tools/clippy/clippy_lints/src/manual_async_fn.rs
+++ b/src/tools/clippy/clippy_lints/src/manual_async_fn.rs
@@ -1,6 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_then;
-use clippy_utils::match_function_call;
-use clippy_utils::paths::FUTURE_FROM_GENERATOR;
+use clippy_utils::match_function_call_with_def_id;
use clippy_utils::source::{position_before_rarrow, snippet_block, snippet_opt};
use if_chain::if_chain;
use rustc_errors::Applicability;
@@ -74,11 +73,11 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
if let Some(ret_pos) = position_before_rarrow(&header_snip);
if let Some((ret_sugg, ret_snip)) = suggested_ret(cx, output);
then {
- let help = format!("make the function `async` and {}", ret_sugg);
+ let help = format!("make the function `async` and {ret_sugg}");
diag.span_suggestion(
header_span,
&help,
- format!("async {}{}", &header_snip[..ret_pos], ret_snip),
+ format!("async {}{ret_snip}", &header_snip[..ret_pos]),
Applicability::MachineApplicable
);
@@ -140,9 +139,9 @@ fn future_output_ty<'tcx>(trait_ref: &'tcx TraitRef<'tcx>) -> Option<&'tcx Ty<'t
if args.bindings.len() == 1;
let binding = &args.bindings[0];
if binding.ident.name == sym::Output;
- if let TypeBindingKind::Equality{term: Term::Ty(output)} = binding.kind;
+ if let TypeBindingKind::Equality { term: Term::Ty(output) } = binding.kind;
then {
- return Some(output)
+ return Some(output);
}
}
@@ -175,9 +174,16 @@ fn captures_all_lifetimes(inputs: &[Ty<'_>], output_lifetimes: &[LifetimeName])
fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) -> Option<&'tcx Body<'tcx>> {
if_chain! {
if let Some(block_expr) = block.expr;
- if let Some(args) = match_function_call(cx, block_expr, &FUTURE_FROM_GENERATOR);
+ if let Some(args) = cx
+ .tcx
+ .lang_items()
+ .from_generator_fn()
+ .and_then(|def_id| match_function_call_with_def_id(cx, block_expr, def_id));
if args.len() == 1;
- if let Expr{kind: ExprKind::Closure(&Closure { body, .. }), ..} = args[0];
+ if let Expr {
+ kind: ExprKind::Closure(&Closure { body, .. }),
+ ..
+ } = args[0];
let closure_body = cx.tcx.hir().body(body);
if closure_body.generator_kind == Some(GeneratorKind::Async(AsyncGeneratorKind::Block));
then {
@@ -196,7 +202,7 @@ fn suggested_ret(cx: &LateContext<'_>, output: &Ty<'_>) -> Option<(&'static str,
},
_ => {
let sugg = "return the output of the future directly";
- snippet_opt(cx, output.span).map(|snip| (sugg, format!(" -> {}", snip)))
+ snippet_opt(cx, output.span).map(|snip| (sugg, format!(" -> {snip}")))
},
}
}
diff --git a/src/tools/clippy/clippy_lints/src/manual_clamp.rs b/src/tools/clippy/clippy_lints/src/manual_clamp.rs
new file mode 100644
index 000000000..02dc8755d
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/manual_clamp.rs
@@ -0,0 +1,717 @@
+use itertools::Itertools;
+use rustc_errors::Diagnostic;
+use rustc_hir::{
+ def::Res, Arm, BinOpKind, Block, Expr, ExprKind, Guard, HirId, PatKind, PathSegment, PrimTy, QPath, StmtKind,
+};
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::ty::Ty;
+use rustc_semver::RustcVersion;
+use rustc_session::{declare_tool_lint, impl_lint_pass};
+use rustc_span::{symbol::sym, Span};
+use std::ops::Deref;
+
+use clippy_utils::{
+ diagnostics::{span_lint_and_then, span_lint_hir_and_then},
+ eq_expr_value,
+ higher::If,
+ is_diag_trait_item, is_trait_method, meets_msrv, msrvs, path_res, path_to_local_id, peel_blocks,
+ peel_blocks_with_stmt,
+ sugg::Sugg,
+ ty::implements_trait,
+ visitors::is_const_evaluatable,
+ MaybePath,
+};
+use rustc_errors::Applicability;
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Identifies good opportunities for a clamp function from std or core, and suggests using it.
+ ///
+ /// ### Why is this bad?
+ /// clamp is much shorter, easier to read, and doesn't use any control flow.
+ ///
+ /// ### Known issue(s)
+ /// If the clamped variable is NaN this suggestion will cause the code to propagate NaN
+ /// rather than returning either `max` or `min`.
+ ///
+ /// `clamp` functions will panic if `max < min`, `max.is_nan()`, or `min.is_nan()`.
+ /// Some may consider panicking in these situations to be desirable, but it also may
+ /// introduce panicking where there wasn't any before.
+ ///
+ /// ### Examples
+ /// ```rust
+ /// # let (input, min, max) = (0, -2, 1);
+ /// if input > max {
+ /// max
+ /// } else if input < min {
+ /// min
+ /// } else {
+ /// input
+ /// }
+ /// # ;
+ /// ```
+ ///
+ /// ```rust
+ /// # let (input, min, max) = (0, -2, 1);
+ /// input.max(min).min(max)
+ /// # ;
+ /// ```
+ ///
+ /// ```rust
+ /// # let (input, min, max) = (0, -2, 1);
+ /// match input {
+ /// x if x > max => max,
+ /// x if x < min => min,
+ /// x => x,
+ /// }
+ /// # ;
+ /// ```
+ ///
+ /// ```rust
+ /// # let (input, min, max) = (0, -2, 1);
+ /// let mut x = input;
+ /// if x < min { x = min; }
+ /// if x > max { x = max; }
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// # let (input, min, max) = (0, -2, 1);
+ /// input.clamp(min, max)
+ /// # ;
+ /// ```
+ #[clippy::version = "1.66.0"]
+ pub MANUAL_CLAMP,
+ complexity,
+ "using a clamp pattern instead of the clamp function"
+}
+impl_lint_pass!(ManualClamp => [MANUAL_CLAMP]);
+
+pub struct ManualClamp {
+ msrv: Option<RustcVersion>,
+}
+
+impl ManualClamp {
+ pub fn new(msrv: Option<RustcVersion>) -> Self {
+ Self { msrv }
+ }
+}
+
+#[derive(Debug)]
+struct ClampSuggestion<'tcx> {
+ params: InputMinMax<'tcx>,
+ span: Span,
+ make_assignment: Option<&'tcx Expr<'tcx>>,
+ hir_with_ignore_attr: Option<HirId>,
+}
+
+#[derive(Debug)]
+struct InputMinMax<'tcx> {
+ input: &'tcx Expr<'tcx>,
+ min: &'tcx Expr<'tcx>,
+ max: &'tcx Expr<'tcx>,
+ is_float: bool,
+}
+
+impl<'tcx> LateLintPass<'tcx> for ManualClamp {
+ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
+ if !meets_msrv(self.msrv, msrvs::CLAMP) {
+ return;
+ }
+ if !expr.span.from_expansion() {
+ let suggestion = is_if_elseif_else_pattern(cx, expr)
+ .or_else(|| is_max_min_pattern(cx, expr))
+ .or_else(|| is_call_max_min_pattern(cx, expr))
+ .or_else(|| is_match_pattern(cx, expr))
+ .or_else(|| is_if_elseif_pattern(cx, expr));
+ if let Some(suggestion) = suggestion {
+ emit_suggestion(cx, &suggestion);
+ }
+ }
+ }
+
+ fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
+ if !meets_msrv(self.msrv, msrvs::CLAMP) {
+ return;
+ }
+ for suggestion in is_two_if_pattern(cx, block) {
+ emit_suggestion(cx, &suggestion);
+ }
+ }
+ extract_msrv_attr!(LateContext);
+}
+
+fn emit_suggestion<'tcx>(cx: &LateContext<'tcx>, suggestion: &ClampSuggestion<'tcx>) {
+ let ClampSuggestion {
+ params: InputMinMax {
+ input,
+ min,
+ max,
+ is_float,
+ },
+ span,
+ make_assignment,
+ hir_with_ignore_attr,
+ } = suggestion;
+ let input = Sugg::hir(cx, input, "..").maybe_par();
+ let min = Sugg::hir(cx, min, "..");
+ let max = Sugg::hir(cx, max, "..");
+ let semicolon = if make_assignment.is_some() { ";" } else { "" };
+ let assignment = if let Some(assignment) = make_assignment {
+ let assignment = Sugg::hir(cx, assignment, "..");
+ format!("{assignment} = ")
+ } else {
+ String::new()
+ };
+ let suggestion = format!("{assignment}{input}.clamp({min}, {max}){semicolon}");
+ let msg = "clamp-like pattern without using clamp function";
+ let lint_builder = |d: &mut Diagnostic| {
+ d.span_suggestion(*span, "replace with clamp", suggestion, Applicability::MaybeIncorrect);
+ if *is_float {
+ d.note("clamp will panic if max < min, min.is_nan(), or max.is_nan()")
+ .note("clamp returns NaN if the input is NaN");
+ } else {
+ d.note("clamp will panic if max < min");
+ }
+ };
+ if let Some(hir_id) = hir_with_ignore_attr {
+ span_lint_hir_and_then(cx, MANUAL_CLAMP, *hir_id, *span, msg, lint_builder);
+ } else {
+ span_lint_and_then(cx, MANUAL_CLAMP, *span, msg, lint_builder);
+ }
+}
+
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
+enum TypeClampability {
+ Float,
+ Ord,
+}
+
+impl TypeClampability {
+ fn is_clampable<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<TypeClampability> {
+ if ty.is_floating_point() {
+ Some(TypeClampability::Float)
+ } else if cx
+ .tcx
+ .get_diagnostic_item(sym::Ord)
+ .map_or(false, |id| implements_trait(cx, ty, id, &[]))
+ {
+ Some(TypeClampability::Ord)
+ } else {
+ None
+ }
+ }
+
+ fn is_float(self) -> bool {
+ matches!(self, TypeClampability::Float)
+ }
+}
+
+/// Targets patterns like
+///
+/// ```
+/// # let (input, min, max) = (0, -3, 12);
+///
+/// if input < min {
+/// min
+/// } else if input > max {
+/// max
+/// } else {
+/// input
+/// }
+/// # ;
+/// ```
+fn is_if_elseif_else_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<ClampSuggestion<'tcx>> {
+ if let Some(If {
+ cond,
+ then,
+ r#else: Some(else_if),
+ }) = If::hir(expr)
+ && let Some(If {
+ cond: else_if_cond,
+ then: else_if_then,
+ r#else: Some(else_body),
+ }) = If::hir(peel_blocks(else_if))
+ {
+ let params = is_clamp_meta_pattern(
+ cx,
+ &BinaryOp::new(peel_blocks(cond))?,
+ &BinaryOp::new(peel_blocks(else_if_cond))?,
+ peel_blocks(then),
+ peel_blocks(else_if_then),
+ None,
+ )?;
+ // Contents of the else should be the resolved input.
+ if !eq_expr_value(cx, params.input, peel_blocks(else_body)) {
+ return None;
+ }
+ Some(ClampSuggestion {
+ params,
+ span: expr.span,
+ make_assignment: None,
+ hir_with_ignore_attr: None,
+ })
+ } else {
+ None
+ }
+}
+
+/// Targets patterns like
+///
+/// ```
+/// # let (input, min_value, max_value) = (0, -3, 12);
+///
+/// input.max(min_value).min(max_value)
+/// # ;
+/// ```
+fn is_max_min_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<ClampSuggestion<'tcx>> {
+ if let ExprKind::MethodCall(seg_second, receiver, [arg_second], _) = &expr.kind
+ && (cx.typeck_results().expr_ty_adjusted(receiver).is_floating_point() || is_trait_method(cx, expr, sym::Ord))
+ && let ExprKind::MethodCall(seg_first, input, [arg_first], _) = &receiver.kind
+ && (cx.typeck_results().expr_ty_adjusted(input).is_floating_point() || is_trait_method(cx, receiver, sym::Ord))
+ {
+ let is_float = cx.typeck_results().expr_ty_adjusted(input).is_floating_point();
+ let (min, max) = match (seg_first.ident.as_str(), seg_second.ident.as_str()) {
+ ("min", "max") => (arg_second, arg_first),
+ ("max", "min") => (arg_first, arg_second),
+ _ => return None,
+ };
+ Some(ClampSuggestion {
+ params: InputMinMax { input, min, max, is_float },
+ span: expr.span,
+ make_assignment: None,
+ hir_with_ignore_attr: None,
+ })
+ } else {
+ None
+ }
+}
+
+/// Targets patterns like
+///
+/// ```
+/// # let (input, min_value, max_value) = (0, -3, 12);
+/// # use std::cmp::{max, min};
+/// min(max(input, min_value), max_value)
+/// # ;
+/// ```
+fn is_call_max_min_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<ClampSuggestion<'tcx>> {
+ fn segment<'tcx>(cx: &LateContext<'_>, func: &Expr<'tcx>) -> Option<FunctionType<'tcx>> {
+ match func.kind {
+ ExprKind::Path(QPath::Resolved(None, path)) => {
+ let id = path.res.opt_def_id()?;
+ match cx.tcx.get_diagnostic_name(id) {
+ Some(sym::cmp_min) => Some(FunctionType::CmpMin),
+ Some(sym::cmp_max) => Some(FunctionType::CmpMax),
+ _ if is_diag_trait_item(cx, id, sym::Ord) => {
+ Some(FunctionType::OrdOrFloat(path.segments.last().expect("infallible")))
+ },
+ _ => None,
+ }
+ },
+ ExprKind::Path(QPath::TypeRelative(ty, seg)) => {
+ matches!(path_res(cx, ty), Res::PrimTy(PrimTy::Float(_))).then(|| FunctionType::OrdOrFloat(seg))
+ },
+ _ => None,
+ }
+ }
+
+ enum FunctionType<'tcx> {
+ CmpMin,
+ CmpMax,
+ OrdOrFloat(&'tcx PathSegment<'tcx>),
+ }
+
+ fn check<'tcx>(
+ cx: &LateContext<'tcx>,
+ outer_fn: &'tcx Expr<'tcx>,
+ inner_call: &'tcx Expr<'tcx>,
+ outer_arg: &'tcx Expr<'tcx>,
+ span: Span,
+ ) -> Option<ClampSuggestion<'tcx>> {
+ if let ExprKind::Call(inner_fn, [first, second]) = &inner_call.kind
+ && let Some(inner_seg) = segment(cx, inner_fn)
+ && let Some(outer_seg) = segment(cx, outer_fn)
+ {
+ let (input, inner_arg) = match (is_const_evaluatable(cx, first), is_const_evaluatable(cx, second)) {
+ (true, false) => (second, first),
+ (false, true) => (first, second),
+ _ => return None,
+ };
+ let is_float = cx.typeck_results().expr_ty_adjusted(input).is_floating_point();
+ let (min, max) = match (inner_seg, outer_seg) {
+ (FunctionType::CmpMin, FunctionType::CmpMax) => (outer_arg, inner_arg),
+ (FunctionType::CmpMax, FunctionType::CmpMin) => (inner_arg, outer_arg),
+ (FunctionType::OrdOrFloat(first_segment), FunctionType::OrdOrFloat(second_segment)) => {
+ match (first_segment.ident.as_str(), second_segment.ident.as_str()) {
+ ("min", "max") => (outer_arg, inner_arg),
+ ("max", "min") => (inner_arg, outer_arg),
+ _ => return None,
+ }
+ }
+ _ => return None,
+ };
+ Some(ClampSuggestion {
+ params: InputMinMax { input, min, max, is_float },
+ span,
+ make_assignment: None,
+ hir_with_ignore_attr: None,
+ })
+ } else {
+ None
+ }
+ }
+
+ if let ExprKind::Call(outer_fn, [first, second]) = &expr.kind {
+ check(cx, outer_fn, first, second, expr.span).or_else(|| check(cx, outer_fn, second, first, expr.span))
+ } else {
+ None
+ }
+}
+
+/// Targets patterns like
+///
+/// ```
+/// # let (input, min, max) = (0, -3, 12);
+///
+/// match input {
+/// input if input > max => max,
+/// input if input < min => min,
+/// input => input,
+/// }
+/// # ;
+/// ```
+fn is_match_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<ClampSuggestion<'tcx>> {
+ if let ExprKind::Match(value, [first_arm, second_arm, last_arm], rustc_hir::MatchSource::Normal) = &expr.kind {
+ // Find possible min/max branches
+ let minmax_values = |a: &'tcx Arm<'tcx>| {
+ if let PatKind::Binding(_, var_hir_id, _, None) = &a.pat.kind
+ && let Some(Guard::If(e)) = a.guard {
+ Some((e, var_hir_id, a.body))
+ } else {
+ None
+ }
+ };
+ let (first, first_hir_id, first_expr) = minmax_values(first_arm)?;
+ let (second, second_hir_id, second_expr) = minmax_values(second_arm)?;
+ let first = BinaryOp::new(first)?;
+ let second = BinaryOp::new(second)?;
+ if let PatKind::Binding(_, binding, _, None) = &last_arm.pat.kind
+ && path_to_local_id(peel_blocks_with_stmt(last_arm.body), *binding)
+ && last_arm.guard.is_none()
+ {
+ // Proceed as normal
+ } else {
+ return None;
+ }
+ if let Some(params) = is_clamp_meta_pattern(
+ cx,
+ &first,
+ &second,
+ first_expr,
+ second_expr,
+ Some((*first_hir_id, *second_hir_id)),
+ ) {
+ return Some(ClampSuggestion {
+ params: InputMinMax {
+ input: value,
+ min: params.min,
+ max: params.max,
+ is_float: params.is_float,
+ },
+ span: expr.span,
+ make_assignment: None,
+ hir_with_ignore_attr: None,
+ });
+ }
+ }
+ None
+}
+
+/// Targets patterns like
+///
+/// ```
+/// # let (input, min, max) = (0, -3, 12);
+///
+/// let mut x = input;
+/// if x < min { x = min; }
+/// if x > max { x = max; }
+/// ```
+fn is_two_if_pattern<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) -> Vec<ClampSuggestion<'tcx>> {
+ block_stmt_with_last(block)
+ .tuple_windows()
+ .filter_map(|(maybe_set_first, maybe_set_second)| {
+ if let StmtKind::Expr(first_expr) = *maybe_set_first
+ && let StmtKind::Expr(second_expr) = *maybe_set_second
+ && let Some(If { cond: first_cond, then: first_then, r#else: None }) = If::hir(first_expr)
+ && let Some(If { cond: second_cond, then: second_then, r#else: None }) = If::hir(second_expr)
+ && let ExprKind::Assign(
+ maybe_input_first_path,
+ maybe_min_max_first,
+ _
+ ) = peel_blocks_with_stmt(first_then).kind
+ && let ExprKind::Assign(
+ maybe_input_second_path,
+ maybe_min_max_second,
+ _
+ ) = peel_blocks_with_stmt(second_then).kind
+ && eq_expr_value(cx, maybe_input_first_path, maybe_input_second_path)
+ && let Some(first_bin) = BinaryOp::new(first_cond)
+ && let Some(second_bin) = BinaryOp::new(second_cond)
+ && let Some(input_min_max) = is_clamp_meta_pattern(
+ cx,
+ &first_bin,
+ &second_bin,
+ maybe_min_max_first,
+ maybe_min_max_second,
+ None
+ )
+ {
+ Some(ClampSuggestion {
+ params: InputMinMax {
+ input: maybe_input_first_path,
+ min: input_min_max.min,
+ max: input_min_max.max,
+ is_float: input_min_max.is_float,
+ },
+ span: first_expr.span.to(second_expr.span),
+ make_assignment: Some(maybe_input_first_path),
+ hir_with_ignore_attr: Some(first_expr.hir_id()),
+ })
+ } else {
+ None
+ }
+ })
+ .collect()
+}
+
+/// Targets patterns like
+///
+/// ```
+/// # let (mut input, min, max) = (0, -3, 12);
+///
+/// if input < min {
+/// input = min;
+/// } else if input > max {
+/// input = max;
+/// }
+/// ```
+fn is_if_elseif_pattern<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<ClampSuggestion<'tcx>> {
+ if let Some(If {
+ cond,
+ then,
+ r#else: Some(else_if),
+ }) = If::hir(expr)
+ && let Some(If {
+ cond: else_if_cond,
+ then: else_if_then,
+ r#else: None,
+ }) = If::hir(peel_blocks(else_if))
+ && let ExprKind::Assign(
+ maybe_input_first_path,
+ maybe_min_max_first,
+ _
+ ) = peel_blocks_with_stmt(then).kind
+ && let ExprKind::Assign(
+ maybe_input_second_path,
+ maybe_min_max_second,
+ _
+ ) = peel_blocks_with_stmt(else_if_then).kind
+ {
+ let params = is_clamp_meta_pattern(
+ cx,
+ &BinaryOp::new(peel_blocks(cond))?,
+ &BinaryOp::new(peel_blocks(else_if_cond))?,
+ peel_blocks(maybe_min_max_first),
+ peel_blocks(maybe_min_max_second),
+ None,
+ )?;
+ if !eq_expr_value(cx, maybe_input_first_path, maybe_input_second_path) {
+ return None;
+ }
+ Some(ClampSuggestion {
+ params,
+ span: expr.span,
+ make_assignment: Some(maybe_input_first_path),
+ hir_with_ignore_attr: None,
+ })
+ } else {
+ None
+ }
+}
+
+/// `ExprKind::Binary` but more narrowly typed
+#[derive(Debug, Clone, Copy)]
+struct BinaryOp<'tcx> {
+ op: BinOpKind,
+ left: &'tcx Expr<'tcx>,
+ right: &'tcx Expr<'tcx>,
+}
+
+impl<'tcx> BinaryOp<'tcx> {
+ fn new(e: &'tcx Expr<'tcx>) -> Option<BinaryOp<'tcx>> {
+ match &e.kind {
+ ExprKind::Binary(op, left, right) => Some(BinaryOp {
+ op: op.node,
+ left,
+ right,
+ }),
+ _ => None,
+ }
+ }
+
+ fn flip(&self) -> Self {
+ Self {
+ op: match self.op {
+ BinOpKind::Le => BinOpKind::Ge,
+ BinOpKind::Lt => BinOpKind::Gt,
+ BinOpKind::Ge => BinOpKind::Le,
+ BinOpKind::Gt => BinOpKind::Lt,
+ other => other,
+ },
+ left: self.right,
+ right: self.left,
+ }
+ }
+}
+
+/// The clamp meta pattern is a pattern shared between many (but not all) patterns.
+/// In summary, this pattern consists of two if statements that meet many criteria,
+/// - binary operators that are one of [`>`, `<`, `>=`, `<=`].
+/// - Both binary statements must have a shared argument
+/// - Which can appear on the left or right side of either statement
+/// - The binary operators must define a finite range for the shared argument. To put this in
+/// the terms of Rust `std` library, the following ranges are acceptable
+/// - `Range`
+/// - `RangeInclusive`
+/// And all other range types are not accepted. For the purposes of `clamp` it's irrelevant
+/// whether the range is inclusive or not, the output is the same.
+/// - The result of each if statement must be equal to the argument unique to that if statement. The
+/// result can not be the shared argument in either case.
+fn is_clamp_meta_pattern<'tcx>(
+ cx: &LateContext<'tcx>,
+ first_bin: &BinaryOp<'tcx>,
+ second_bin: &BinaryOp<'tcx>,
+ first_expr: &'tcx Expr<'tcx>,
+ second_expr: &'tcx Expr<'tcx>,
+ // This parameters is exclusively for the match pattern.
+ // It exists because the variable bindings used in that pattern
+ // refer to the variable bound in the match arm, not the variable
+ // bound outside of it. Fortunately due to context we know this has to
+ // be the input variable, not the min or max.
+ input_hir_ids: Option<(HirId, HirId)>,
+) -> Option<InputMinMax<'tcx>> {
+ fn check<'tcx>(
+ cx: &LateContext<'tcx>,
+ first_bin: &BinaryOp<'tcx>,
+ second_bin: &BinaryOp<'tcx>,
+ first_expr: &'tcx Expr<'tcx>,
+ second_expr: &'tcx Expr<'tcx>,
+ input_hir_ids: Option<(HirId, HirId)>,
+ is_float: bool,
+ ) -> Option<InputMinMax<'tcx>> {
+ match (&first_bin.op, &second_bin.op) {
+ (BinOpKind::Ge | BinOpKind::Gt, BinOpKind::Le | BinOpKind::Lt) => {
+ let (min, max) = (second_expr, first_expr);
+ let refers_to_input = match input_hir_ids {
+ Some((first_hir_id, second_hir_id)) => {
+ path_to_local_id(peel_blocks(first_bin.left), first_hir_id)
+ && path_to_local_id(peel_blocks(second_bin.left), second_hir_id)
+ },
+ None => eq_expr_value(cx, first_bin.left, second_bin.left),
+ };
+ (refers_to_input
+ && eq_expr_value(cx, first_bin.right, first_expr)
+ && eq_expr_value(cx, second_bin.right, second_expr))
+ .then_some(InputMinMax {
+ input: first_bin.left,
+ min,
+ max,
+ is_float,
+ })
+ },
+ _ => None,
+ }
+ }
+ // First filter out any expressions with side effects
+ let exprs = [
+ first_bin.left,
+ first_bin.right,
+ second_bin.left,
+ second_bin.right,
+ first_expr,
+ second_expr,
+ ];
+ let clampability = TypeClampability::is_clampable(cx, cx.typeck_results().expr_ty(first_expr))?;
+ let is_float = clampability.is_float();
+ if exprs.iter().any(|e| peel_blocks(e).can_have_side_effects()) {
+ return None;
+ }
+ if !(is_ord_op(first_bin.op) && is_ord_op(second_bin.op)) {
+ return None;
+ }
+ let cases = [
+ (*first_bin, *second_bin),
+ (first_bin.flip(), second_bin.flip()),
+ (first_bin.flip(), *second_bin),
+ (*first_bin, second_bin.flip()),
+ ];
+
+ cases.into_iter().find_map(|(first, second)| {
+ check(cx, &first, &second, first_expr, second_expr, input_hir_ids, is_float).or_else(|| {
+ check(
+ cx,
+ &second,
+ &first,
+ second_expr,
+ first_expr,
+ input_hir_ids.map(|(l, r)| (r, l)),
+ is_float,
+ )
+ })
+ })
+}
+
+fn block_stmt_with_last<'tcx>(block: &'tcx Block<'tcx>) -> impl Iterator<Item = MaybeBorrowedStmtKind<'tcx>> {
+ block
+ .stmts
+ .iter()
+ .map(|s| MaybeBorrowedStmtKind::Borrowed(&s.kind))
+ .chain(
+ block
+ .expr
+ .as_ref()
+ .map(|e| MaybeBorrowedStmtKind::Owned(StmtKind::Expr(e))),
+ )
+}
+
+fn is_ord_op(op: BinOpKind) -> bool {
+ matches!(op, BinOpKind::Ge | BinOpKind::Gt | BinOpKind::Le | BinOpKind::Lt)
+}
+
+/// Really similar to Cow, but doesn't have a `Clone` requirement.
+#[derive(Debug)]
+enum MaybeBorrowedStmtKind<'a> {
+ Borrowed(&'a StmtKind<'a>),
+ Owned(StmtKind<'a>),
+}
+
+impl<'a> Clone for MaybeBorrowedStmtKind<'a> {
+ fn clone(&self) -> Self {
+ match self {
+ Self::Borrowed(t) => Self::Borrowed(t),
+ Self::Owned(StmtKind::Expr(e)) => Self::Owned(StmtKind::Expr(e)),
+ Self::Owned(_) => unreachable!("Owned should only ever contain a StmtKind::Expr."),
+ }
+ }
+}
+
+impl<'a> Deref for MaybeBorrowedStmtKind<'a> {
+ type Target = StmtKind<'a>;
+
+ fn deref(&self) -> &Self::Target {
+ match self {
+ Self::Borrowed(t) => t,
+ Self::Owned(t) => t,
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs b/src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs
index 2b04475c7..6806c1466 100644
--- a/src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs
+++ b/src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs
@@ -133,7 +133,7 @@ impl EarlyLintPass for ManualNonExhaustiveStruct {
diag.span_suggestion(
header_span,
"add the attribute",
- format!("#[non_exhaustive] {}", snippet),
+ format!("#[non_exhaustive] {snippet}"),
Applicability::Unspecified,
);
}
@@ -166,7 +166,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
if let Some((id, span)) = iter.next()
&& iter.next().is_none()
{
- self.potential_enums.push((item.def_id, id, item.span, span));
+ self.potential_enums.push((item.owner_id.def_id, id, item.span, span));
}
}
}
@@ -207,7 +207,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
diag.span_suggestion(
header_span,
"add the attribute",
- format!("#[non_exhaustive] {}", snippet),
+ format!("#[non_exhaustive] {snippet}"),
Applicability::Unspecified,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/manual_rem_euclid.rs b/src/tools/clippy/clippy_lints/src/manual_rem_euclid.rs
index 95cc6bdbd..6f25a2ed8 100644
--- a/src/tools/clippy/clippy_lints/src/manual_rem_euclid.rs
+++ b/src/tools/clippy/clippy_lints/src/manual_rem_euclid.rs
@@ -27,7 +27,7 @@ declare_clippy_lint! {
/// let x: i32 = 24;
/// let rem = x.rem_euclid(4);
/// ```
- #[clippy::version = "1.63.0"]
+ #[clippy::version = "1.64.0"]
pub MANUAL_REM_EUCLID,
complexity,
"manually reimplementing `rem_euclid`"
diff --git a/src/tools/clippy/clippy_lints/src/manual_retain.rs b/src/tools/clippy/clippy_lints/src/manual_retain.rs
index f28c37d3d..3181bc86d 100644
--- a/src/tools/clippy/clippy_lints/src/manual_retain.rs
+++ b/src/tools/clippy/clippy_lints/src/manual_retain.rs
@@ -43,7 +43,7 @@ declare_clippy_lint! {
/// let mut vec = vec![0, 1, 2];
/// vec.retain(|x| x % 2 == 0);
/// ```
- #[clippy::version = "1.63.0"]
+ #[clippy::version = "1.64.0"]
pub MANUAL_RETAIN,
perf,
"`retain()` is simpler and the same functionalitys"
@@ -92,7 +92,7 @@ fn check_into_iter(
&& match_def_path(cx, filter_def_id, &paths::CORE_ITER_FILTER)
&& let hir::ExprKind::MethodCall(_, struct_expr, [], _) = &into_iter_expr.kind
&& let Some(into_iter_def_id) = cx.typeck_results().type_dependent_def_id(into_iter_expr.hir_id)
- && match_def_path(cx, into_iter_def_id, &paths::CORE_ITER_INTO_ITER)
+ && cx.tcx.lang_items().require(hir::LangItem::IntoIterIntoIter).ok() == Some(into_iter_def_id)
&& match_acceptable_type(cx, left_expr, msrv)
&& SpanlessEq::new(cx).eq_expr(left_expr, struct_expr) {
suggest(cx, parent_expr, left_expr, target_expr);
@@ -153,7 +153,7 @@ fn suggest(cx: &LateContext<'_>, parent_expr: &hir::Expr<'_>, left_expr: &hir::E
&& let [filter_params] = filter_body.params
&& let Some(sugg) = match filter_params.pat.kind {
hir::PatKind::Binding(_, _, filter_param_ident, None) => {
- Some(format!("{}.retain(|{}| {})", snippet(cx, left_expr.span, ".."), filter_param_ident, snippet(cx, filter_body.value.span, "..")))
+ Some(format!("{}.retain(|{filter_param_ident}| {})", snippet(cx, left_expr.span, ".."), snippet(cx, filter_body.value.span, "..")))
},
hir::PatKind::Tuple([key_pat, value_pat], _) => {
make_sugg(cx, key_pat, value_pat, left_expr, filter_body)
@@ -161,7 +161,7 @@ fn suggest(cx: &LateContext<'_>, parent_expr: &hir::Expr<'_>, left_expr: &hir::E
hir::PatKind::Ref(pat, _) => {
match pat.kind {
hir::PatKind::Binding(_, _, filter_param_ident, None) => {
- Some(format!("{}.retain(|{}| {})", snippet(cx, left_expr.span, ".."), filter_param_ident, snippet(cx, filter_body.value.span, "..")))
+ Some(format!("{}.retain(|{filter_param_ident}| {})", snippet(cx, left_expr.span, ".."), snippet(cx, filter_body.value.span, "..")))
},
_ => None
}
@@ -190,23 +190,19 @@ fn make_sugg(
match (&key_pat.kind, &value_pat.kind) {
(hir::PatKind::Binding(_, _, key_param_ident, None), hir::PatKind::Binding(_, _, value_param_ident, None)) => {
Some(format!(
- "{}.retain(|{}, &mut {}| {})",
+ "{}.retain(|{key_param_ident}, &mut {value_param_ident}| {})",
snippet(cx, left_expr.span, ".."),
- key_param_ident,
- value_param_ident,
snippet(cx, filter_body.value.span, "..")
))
},
(hir::PatKind::Binding(_, _, key_param_ident, None), hir::PatKind::Wild) => Some(format!(
- "{}.retain(|{}, _| {})",
+ "{}.retain(|{key_param_ident}, _| {})",
snippet(cx, left_expr.span, ".."),
- key_param_ident,
snippet(cx, filter_body.value.span, "..")
)),
(hir::PatKind::Wild, hir::PatKind::Binding(_, _, value_param_ident, None)) => Some(format!(
- "{}.retain(|_, &mut {}| {})",
+ "{}.retain(|_, &mut {value_param_ident}| {})",
snippet(cx, left_expr.span, ".."),
- value_param_ident,
snippet(cx, filter_body.value.span, "..")
)),
_ => None,
diff --git a/src/tools/clippy/clippy_lints/src/manual_strip.rs b/src/tools/clippy/clippy_lints/src/manual_strip.rs
index 7941c8c9c..0976940af 100644
--- a/src/tools/clippy/clippy_lints/src/manual_strip.rs
+++ b/src/tools/clippy/clippy_lints/src/manual_strip.rs
@@ -108,15 +108,14 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip {
};
let test_span = expr.span.until(then.span);
- span_lint_and_then(cx, MANUAL_STRIP, strippings[0], &format!("stripping a {} manually", kind_word), |diag| {
- diag.span_note(test_span, &format!("the {} was tested here", kind_word));
+ span_lint_and_then(cx, MANUAL_STRIP, strippings[0], &format!("stripping a {kind_word} manually"), |diag| {
+ diag.span_note(test_span, &format!("the {kind_word} was tested here"));
multispan_sugg(
diag,
- &format!("try using the `strip_{}` method", kind_word),
+ &format!("try using the `strip_{kind_word}` method"),
vec![(test_span,
- format!("if let Some(<stripped>) = {}.strip_{}({}) ",
+ format!("if let Some(<stripped>) = {}.strip_{kind_word}({}) ",
snippet(cx, target_arg.span, ".."),
- kind_word,
snippet(cx, pattern.span, "..")))]
.into_iter().chain(strippings.into_iter().map(|span| (span, "<stripped>".into()))),
);
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 33d744815..32da37a86 100644
--- a/src/tools/clippy/clippy_lints/src/map_unit_fn.rs
+++ b/src/tools/clippy/clippy_lints/src/map_unit_fn.rs
@@ -131,12 +131,12 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_>, expr: &'a hir::Expr<'_>) ->
},
hir::ExprKind::Block(block, _) => {
match (block.stmts, block.expr.as_ref()) {
- (&[], Some(inner_expr)) => {
+ ([], Some(inner_expr)) => {
// If block only contains an expression,
// reduce `{ X }` to `X`
reduce_unit_expression(cx, inner_expr)
},
- (&[ref inner_stmt], None) => {
+ ([inner_stmt], None) => {
// If block only contains statements,
// reduce `{ X; }` to `X` or `X;`
match inner_stmt.kind {
@@ -194,10 +194,7 @@ fn let_binding_name(cx: &LateContext<'_>, var_arg: &hir::Expr<'_>) -> String {
#[must_use]
fn suggestion_msg(function_type: &str, map_type: &str) -> String {
- format!(
- "called `map(f)` on an `{0}` value where `f` is a {1} that returns the unit type `()`",
- map_type, function_type
- )
+ format!("called `map(f)` on an `{map_type}` value where `f` is a {function_type} that returns the unit type `()`")
}
fn lint_map_unit_fn(
diff --git a/src/tools/clippy/clippy_lints/src/match_result_ok.rs b/src/tools/clippy/clippy_lints/src/match_result_ok.rs
index 8588ab1ed..a020282d2 100644
--- a/src/tools/clippy/clippy_lints/src/match_result_ok.rs
+++ b/src/tools/clippy/clippy_lints/src/match_result_ok.rs
@@ -70,9 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchResultOk {
let some_expr_string = snippet_with_applicability(cx, y[0].span, "", &mut applicability);
let trimmed_ok = snippet_with_applicability(cx, let_expr.span.until(ok_path.ident.span), "", &mut applicability);
let sugg = format!(
- "{} let Ok({}) = {}",
- ifwhile,
- some_expr_string,
+ "{ifwhile} let Ok({some_expr_string}) = {}",
trimmed_ok.trim().trim_end_matches('.'),
);
span_lint_and_sugg(
@@ -80,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchResultOk {
MATCH_RESULT_OK,
expr.span.with_hi(let_expr.span.hi()),
"matching on `Some` with `ok()` is redundant",
- &format!("consider matching on `Ok({})` and removing the call to `ok` instead", some_expr_string),
+ &format!("consider matching on `Ok({some_expr_string})` and removing the call to `ok` instead"),
sugg,
applicability,
);
diff --git a/src/tools/clippy/clippy_lints/src/matches/collapsible_match.rs b/src/tools/clippy/clippy_lints/src/matches/collapsible_match.rs
index 07021f1bc..33a052c41 100644
--- a/src/tools/clippy/clippy_lints/src/matches/collapsible_match.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/collapsible_match.rs
@@ -1,7 +1,10 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::higher::IfLetOrMatch;
+use clippy_utils::source::snippet;
use clippy_utils::visitors::is_local_used;
-use clippy_utils::{is_lang_ctor, is_unit_expr, path_to_local, peel_blocks_with_stmt, peel_ref_operators, SpanlessEq};
+use clippy_utils::{
+ is_res_lang_ctor, is_unit_expr, path_to_local, peel_blocks_with_stmt, peel_ref_operators, SpanlessEq,
+};
use if_chain::if_chain;
use rustc_errors::MultiSpan;
use rustc_hir::LangItem::OptionNone;
@@ -61,7 +64,8 @@ fn check_arm<'tcx>(
if !pat_contains_or(inner_then_pat);
// the binding must come from the pattern of the containing match arm
// ..<local>.. => match <local> { .. }
- if let Some(binding_span) = find_pat_binding(outer_pat, binding_id);
+ if let (Some(binding_span), is_innermost_parent_pat_struct)
+ = find_pat_binding_and_is_innermost_parent_pat_struct(outer_pat, binding_id);
// the "else" branches must be equal
if match (outer_else_body, inner_else_body) {
(None, None) => true,
@@ -86,6 +90,13 @@ fn check_arm<'tcx>(
if matches!(inner, IfLetOrMatch::Match(..)) { "match" } else { "if let" },
if outer_is_match { "match" } else { "if let" },
);
+ // collapsing patterns need an explicit field name in struct pattern matching
+ // ex: Struct {x: Some(1)}
+ let replace_msg = if is_innermost_parent_pat_struct {
+ format!(", prefixed by {}:", snippet(cx, binding_span, "their field name"))
+ } else {
+ String::new()
+ };
span_lint_and_then(
cx,
COLLAPSIBLE_MATCH,
@@ -94,7 +105,7 @@ fn check_arm<'tcx>(
|diag| {
let mut help_span = MultiSpan::from_spans(vec![binding_span, inner_then_pat.span]);
help_span.push_span_label(binding_span, "replace this binding");
- help_span.push_span_label(inner_then_pat.span, "with this pattern");
+ help_span.push_span_label(inner_then_pat.span, format!("with this pattern{replace_msg}"));
diag.span_help(help_span, "the outer pattern can be modified to include the inner pattern");
},
);
@@ -110,13 +121,14 @@ fn arm_is_wild_like(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
}
match arm.pat.kind {
PatKind::Binding(..) | PatKind::Wild => true,
- PatKind::Path(ref qpath) => is_lang_ctor(cx, qpath, OptionNone),
+ PatKind::Path(ref qpath) => is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), OptionNone),
_ => false,
}
}
-fn find_pat_binding(pat: &Pat<'_>, hir_id: HirId) -> Option<Span> {
+fn find_pat_binding_and_is_innermost_parent_pat_struct(pat: &Pat<'_>, hir_id: HirId) -> (Option<Span>, bool) {
let mut span = None;
+ let mut is_innermost_parent_pat_struct = false;
pat.walk_short(|p| match &p.kind {
// ignore OR patterns
PatKind::Or(_) => false,
@@ -127,9 +139,12 @@ fn find_pat_binding(pat: &Pat<'_>, hir_id: HirId) -> Option<Span> {
}
!found
},
- _ => true,
+ _ => {
+ is_innermost_parent_pat_struct = matches!(p.kind, PatKind::Struct(..));
+ true
+ },
});
- span
+ (span, is_innermost_parent_pat_struct)
}
fn pat_contains_or(pat: &Pat<'_>) -> bool {
diff --git a/src/tools/clippy/clippy_lints/src/matches/manual_filter.rs b/src/tools/clippy/clippy_lints/src/matches/manual_filter.rs
new file mode 100644
index 000000000..66ba1f6f9
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/matches/manual_filter.rs
@@ -0,0 +1,153 @@
+use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::ty::is_type_diagnostic_item;
+use clippy_utils::visitors::contains_unsafe_block;
+use clippy_utils::{is_res_lang_ctor, path_res, path_to_local_id};
+
+use rustc_hir::LangItem::OptionSome;
+use rustc_hir::{Arm, Expr, ExprKind, HirId, Pat, PatKind};
+use rustc_lint::LateContext;
+use rustc_span::{sym, SyntaxContext};
+
+use super::manual_utils::{check_with, SomeExpr};
+use super::MANUAL_FILTER;
+
+// Function called on the <expr> of `[&+]Some((ref | ref mut) x) => <expr>`
+// Need to check if it's of the form `<expr>=if <cond> {<then_expr>} else {<else_expr>}`
+// AND that only one `then/else_expr` resolves to `Some(x)` while the other resolves to `None`
+// return the `cond` expression if so.
+fn get_cond_expr<'tcx>(
+ cx: &LateContext<'tcx>,
+ pat: &Pat<'_>,
+ expr: &'tcx Expr<'_>,
+ ctxt: SyntaxContext,
+) -> Option<SomeExpr<'tcx>> {
+ if_chain! {
+ if let Some(block_expr) = peels_blocks_incl_unsafe_opt(expr);
+ if let ExprKind::If(cond, then_expr, Some(else_expr)) = block_expr.kind;
+ if let PatKind::Binding(_,target, ..) = pat.kind;
+ if let (then_visitor, else_visitor)
+ = (is_some_expr(cx, target, ctxt, then_expr),
+ is_some_expr(cx, target, ctxt, else_expr));
+ if then_visitor != else_visitor; // check that one expr resolves to `Some(x)`, the other to `None`
+ then {
+ return Some(SomeExpr {
+ expr: peels_blocks_incl_unsafe(cond.peel_drop_temps()),
+ needs_unsafe_block: contains_unsafe_block(cx, expr),
+ needs_negated: !then_visitor // if the `then_expr` resolves to `None`, need to negate the cond
+ })
+ }
+ };
+ None
+}
+
+fn peels_blocks_incl_unsafe_opt<'a>(expr: &'a Expr<'a>) -> Option<&'a Expr<'a>> {
+ // we don't want to use `peel_blocks` here because we don't care if the block is unsafe, it's
+ // checked by `contains_unsafe_block`
+ if let ExprKind::Block(block, None) = expr.kind {
+ if block.stmts.is_empty() {
+ return block.expr;
+ }
+ };
+ None
+}
+
+fn peels_blocks_incl_unsafe<'a>(expr: &'a Expr<'a>) -> &'a Expr<'a> {
+ peels_blocks_incl_unsafe_opt(expr).unwrap_or(expr)
+}
+
+// function called for each <expr> expression:
+// Some(x) => if <cond> {
+// <expr>
+// } else {
+// <expr>
+// }
+// Returns true if <expr> resolves to `Some(x)`, `false` otherwise
+fn is_some_expr<'tcx>(cx: &LateContext<'_>, target: HirId, ctxt: SyntaxContext, expr: &'tcx Expr<'_>) -> bool {
+ if let Some(inner_expr) = peels_blocks_incl_unsafe_opt(expr) {
+ // there can be not statements in the block as they would be removed when switching to `.filter`
+ if let ExprKind::Call(callee, [arg]) = inner_expr.kind {
+ return ctxt == expr.span.ctxt()
+ && is_res_lang_ctor(cx, path_res(cx, callee), OptionSome)
+ && path_to_local_id(arg, target);
+ }
+ };
+ false
+}
+
+// given the closure: `|<pattern>| <expr>`
+// returns `|&<pattern>| <expr>`
+fn add_ampersand_if_copy(body_str: String, has_copy_trait: bool) -> String {
+ if has_copy_trait {
+ let mut with_ampersand = body_str;
+ with_ampersand.insert(1, '&');
+ with_ampersand
+ } else {
+ body_str
+ }
+}
+
+pub(super) fn check_match<'tcx>(
+ cx: &LateContext<'tcx>,
+ scrutinee: &'tcx Expr<'_>,
+ arms: &'tcx [Arm<'_>],
+ expr: &'tcx Expr<'_>,
+) {
+ let ty = cx.typeck_results().expr_ty(expr);
+ if is_type_diagnostic_item(cx, ty, sym::Option)
+ && let [first_arm, second_arm] = arms
+ && first_arm.guard.is_none()
+ && second_arm.guard.is_none()
+ {
+ check(cx, expr, scrutinee, first_arm.pat, first_arm.body, Some(second_arm.pat), second_arm.body);
+ }
+}
+
+pub(super) fn check_if_let<'tcx>(
+ cx: &LateContext<'tcx>,
+ expr: &'tcx Expr<'_>,
+ let_pat: &'tcx Pat<'_>,
+ let_expr: &'tcx Expr<'_>,
+ then_expr: &'tcx Expr<'_>,
+ else_expr: &'tcx Expr<'_>,
+) {
+ check(cx, expr, let_expr, let_pat, then_expr, None, else_expr);
+}
+
+fn check<'tcx>(
+ cx: &LateContext<'tcx>,
+ expr: &'tcx Expr<'_>,
+ scrutinee: &'tcx Expr<'_>,
+ then_pat: &'tcx Pat<'_>,
+ then_body: &'tcx Expr<'_>,
+ else_pat: Option<&'tcx Pat<'_>>,
+ else_body: &'tcx Expr<'_>,
+) {
+ if let Some(sugg_info) = check_with(
+ cx,
+ expr,
+ scrutinee,
+ then_pat,
+ then_body,
+ else_pat,
+ else_body,
+ get_cond_expr,
+ ) {
+ let body_str = add_ampersand_if_copy(sugg_info.body_str, sugg_info.scrutinee_impl_copy);
+ span_lint_and_sugg(
+ cx,
+ MANUAL_FILTER,
+ expr.span,
+ "manual implementation of `Option::filter`",
+ "try this",
+ if sugg_info.needs_brackets {
+ format!(
+ "{{ {}{}.filter({body_str}) }}",
+ sugg_info.scrutinee_str, sugg_info.as_ref_str
+ )
+ } else {
+ format!("{}{}.filter({body_str})", sugg_info.scrutinee_str, sugg_info.as_ref_str)
+ },
+ sugg_info.app,
+ );
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/matches/manual_map.rs b/src/tools/clippy/clippy_lints/src/matches/manual_map.rs
index b0198e856..aaba23967 100644
--- a/src/tools/clippy/clippy_lints/src/matches/manual_map.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/manual_map.rs
@@ -1,22 +1,13 @@
-use crate::{map_unit_fn::OPTION_MAP_UNIT_FN, matches::MATCH_AS_REF};
+use super::manual_utils::{check_with, SomeExpr};
+use super::MANUAL_MAP;
use clippy_utils::diagnostics::span_lint_and_sugg;
-use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
-use clippy_utils::ty::{is_type_diagnostic_item, peel_mid_ty_refs_is_mutable, type_is_unsafe_function};
-use clippy_utils::{
- can_move_expr_to_closure, is_else_clause, is_lang_ctor, is_lint_allowed, path_to_local_id, peel_blocks,
- peel_hir_expr_refs, peel_hir_expr_while, CaptureKind,
-};
-use rustc_ast::util::parser::PREC_POSTFIX;
-use rustc_errors::Applicability;
-use rustc_hir::LangItem::{OptionNone, OptionSome};
-use rustc_hir::{
- def::Res, Arm, BindingAnnotation, Block, BlockCheckMode, Expr, ExprKind, HirId, Mutability, Pat, PatKind, Path,
- QPath, UnsafeSource,
-};
-use rustc_lint::LateContext;
-use rustc_span::{sym, SyntaxContext};
-use super::MANUAL_MAP;
+use clippy_utils::{is_res_lang_ctor, path_res};
+
+use rustc_hir::LangItem::OptionSome;
+use rustc_hir::{Arm, Block, BlockCheckMode, Expr, ExprKind, Pat, UnsafeSource};
+use rustc_lint::LateContext;
+use rustc_span::SyntaxContext;
pub(super) fn check_match<'tcx>(
cx: &LateContext<'tcx>,
@@ -43,7 +34,6 @@ pub(super) fn check_if_let<'tcx>(
check(cx, expr, let_expr, let_pat, then_expr, None, else_expr);
}
-#[expect(clippy::too_many_lines)]
fn check<'tcx>(
cx: &LateContext<'tcx>,
expr: &'tcx Expr<'_>,
@@ -53,254 +43,74 @@ fn check<'tcx>(
else_pat: Option<&'tcx Pat<'_>>,
else_body: &'tcx Expr<'_>,
) {
- let (scrutinee_ty, ty_ref_count, ty_mutability) =
- peel_mid_ty_refs_is_mutable(cx.typeck_results().expr_ty(scrutinee));
- if !(is_type_diagnostic_item(cx, scrutinee_ty, sym::Option)
- && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::Option))
- {
- return;
- }
-
- let expr_ctxt = expr.span.ctxt();
- let (some_expr, some_pat, pat_ref_count, is_wild_none) = match (
- try_parse_pattern(cx, then_pat, expr_ctxt),
- else_pat.map_or(Some(OptionPat::Wild), |p| try_parse_pattern(cx, p, expr_ctxt)),
+ if let Some(sugg_info) = check_with(
+ cx,
+ expr,
+ scrutinee,
+ then_pat,
+ then_body,
+ else_pat,
+ else_body,
+ get_some_expr,
) {
- (Some(OptionPat::Wild), Some(OptionPat::Some { pattern, ref_count })) if is_none_expr(cx, then_body) => {
- (else_body, pattern, ref_count, true)
- },
- (Some(OptionPat::None), Some(OptionPat::Some { pattern, ref_count })) if is_none_expr(cx, then_body) => {
- (else_body, pattern, ref_count, false)
- },
- (Some(OptionPat::Some { pattern, ref_count }), Some(OptionPat::Wild)) if is_none_expr(cx, else_body) => {
- (then_body, pattern, ref_count, true)
- },
- (Some(OptionPat::Some { pattern, ref_count }), Some(OptionPat::None)) if is_none_expr(cx, else_body) => {
- (then_body, pattern, ref_count, false)
- },
- _ => return,
- };
-
- // Top level or patterns aren't allowed in closures.
- if matches!(some_pat.kind, PatKind::Or(_)) {
- return;
- }
-
- let some_expr = match get_some_expr(cx, some_expr, false, expr_ctxt) {
- Some(expr) => expr,
- None => return,
- };
-
- // These two lints will go back and forth with each other.
- if cx.typeck_results().expr_ty(some_expr.expr) == cx.tcx.types.unit
- && !is_lint_allowed(cx, OPTION_MAP_UNIT_FN, expr.hir_id)
- {
- return;
- }
-
- // `map` won't perform any adjustments.
- if !cx.typeck_results().expr_adjustments(some_expr.expr).is_empty() {
- return;
- }
-
- // Determine which binding mode to use.
- let explicit_ref = some_pat.contains_explicit_ref_binding();
- let binding_ref = explicit_ref.or_else(|| (ty_ref_count != pat_ref_count).then_some(ty_mutability));
-
- let as_ref_str = match binding_ref {
- Some(Mutability::Mut) => ".as_mut()",
- Some(Mutability::Not) => ".as_ref()",
- None => "",
- };
-
- match can_move_expr_to_closure(cx, some_expr.expr) {
- Some(captures) => {
- // Check if captures the closure will need conflict with borrows made in the scrutinee.
- // TODO: check all the references made in the scrutinee expression. This will require interacting
- // with the borrow checker. Currently only `<local>[.<field>]*` is checked for.
- if let Some(binding_ref_mutability) = binding_ref {
- let e = peel_hir_expr_while(scrutinee, |e| match e.kind {
- ExprKind::Field(e, _) | ExprKind::AddrOf(_, _, e) => Some(e),
- _ => None,
- });
- if let ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(l), .. })) = e.kind {
- match captures.get(l) {
- Some(CaptureKind::Value | CaptureKind::Ref(Mutability::Mut)) => return,
- Some(CaptureKind::Ref(Mutability::Not)) if binding_ref_mutability == Mutability::Mut => {
- return;
- },
- Some(CaptureKind::Ref(Mutability::Not)) | None => (),
- }
- }
- }
- },
- None => return,
- };
-
- let mut app = Applicability::MachineApplicable;
-
- // Remove address-of expressions from the scrutinee. Either `as_ref` will be called, or
- // it's being passed by value.
- let scrutinee = peel_hir_expr_refs(scrutinee).0;
- let (scrutinee_str, _) = snippet_with_context(cx, scrutinee.span, expr_ctxt, "..", &mut app);
- let scrutinee_str = if scrutinee.span.ctxt() == expr.span.ctxt() && scrutinee.precedence().order() < PREC_POSTFIX {
- format!("({})", scrutinee_str)
- } else {
- scrutinee_str.into()
- };
-
- let body_str = if let PatKind::Binding(annotation, id, some_binding, None) = some_pat.kind {
- if_chain! {
- if !some_expr.needs_unsafe_block;
- if let Some(func) = can_pass_as_func(cx, id, some_expr.expr);
- if func.span.ctxt() == some_expr.expr.span.ctxt();
- then {
- snippet_with_applicability(cx, func.span, "..", &mut app).into_owned()
+ span_lint_and_sugg(
+ cx,
+ MANUAL_MAP,
+ expr.span,
+ "manual implementation of `Option::map`",
+ "try this",
+ if sugg_info.needs_brackets {
+ format!(
+ "{{ {}{}.map({}) }}",
+ sugg_info.scrutinee_str, sugg_info.as_ref_str, sugg_info.body_str
+ )
} else {
- if path_to_local_id(some_expr.expr, id)
- && !is_lint_allowed(cx, MATCH_AS_REF, expr.hir_id)
- && binding_ref.is_some()
- {
- return;
- }
-
- // `ref` and `ref mut` annotations were handled earlier.
- let annotation = if matches!(annotation, BindingAnnotation::MUT) {
- "mut "
- } else {
- ""
- };
- let expr_snip = snippet_with_context(cx, some_expr.expr.span, expr_ctxt, "..", &mut app).0;
- if some_expr.needs_unsafe_block {
- format!("|{}{}| unsafe {{ {} }}", annotation, some_binding, expr_snip)
- } else {
- format!("|{}{}| {}", annotation, some_binding, expr_snip)
- }
- }
- }
- } else if !is_wild_none && explicit_ref.is_none() {
- // TODO: handle explicit reference annotations.
- let pat_snip = snippet_with_context(cx, some_pat.span, expr_ctxt, "..", &mut app).0;
- let expr_snip = snippet_with_context(cx, some_expr.expr.span, expr_ctxt, "..", &mut app).0;
- if some_expr.needs_unsafe_block {
- format!("|{}| unsafe {{ {} }}", pat_snip, expr_snip)
- } else {
- format!("|{}| {}", pat_snip, expr_snip)
- }
- } else {
- // Refutable bindings and mixed reference annotations can't be handled by `map`.
- return;
- };
-
- span_lint_and_sugg(
- cx,
- MANUAL_MAP,
- expr.span,
- "manual implementation of `Option::map`",
- "try this",
- if else_pat.is_none() && is_else_clause(cx.tcx, expr) {
- format!("{{ {}{}.map({}) }}", scrutinee_str, as_ref_str, body_str)
- } else {
- format!("{}{}.map({})", scrutinee_str, as_ref_str, body_str)
- },
- app,
- );
-}
-
-// Checks whether the expression could be passed as a function, or whether a closure is needed.
-// Returns the function to be passed to `map` if it exists.
-fn can_pass_as_func<'tcx>(cx: &LateContext<'tcx>, binding: HirId, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
- match expr.kind {
- ExprKind::Call(func, [arg])
- if path_to_local_id(arg, binding)
- && cx.typeck_results().expr_adjustments(arg).is_empty()
- && !type_is_unsafe_function(cx, cx.typeck_results().expr_ty(func).peel_refs()) =>
- {
- Some(func)
- },
- _ => None,
- }
-}
-
-enum OptionPat<'a> {
- Wild,
- None,
- Some {
- // The pattern contained in the `Some` tuple.
- pattern: &'a Pat<'a>,
- // The number of references before the `Some` tuple.
- // e.g. `&&Some(_)` has a ref count of 2.
- ref_count: usize,
- },
-}
-
-struct SomeExpr<'tcx> {
- expr: &'tcx Expr<'tcx>,
- needs_unsafe_block: bool,
-}
-
-// Try to parse into a recognized `Option` pattern.
-// i.e. `_`, `None`, `Some(..)`, or a reference to any of those.
-fn try_parse_pattern<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, ctxt: SyntaxContext) -> Option<OptionPat<'tcx>> {
- fn f<'tcx>(
- cx: &LateContext<'tcx>,
- pat: &'tcx Pat<'_>,
- ref_count: usize,
- ctxt: SyntaxContext,
- ) -> Option<OptionPat<'tcx>> {
- match pat.kind {
- PatKind::Wild => Some(OptionPat::Wild),
- PatKind::Ref(pat, _) => f(cx, pat, ref_count + 1, ctxt),
- PatKind::Path(ref qpath) if is_lang_ctor(cx, qpath, OptionNone) => Some(OptionPat::None),
- PatKind::TupleStruct(ref qpath, [pattern], _)
- if is_lang_ctor(cx, qpath, OptionSome) && pat.span.ctxt() == ctxt =>
- {
- Some(OptionPat::Some { pattern, ref_count })
+ format!(
+ "{}{}.map({})",
+ sugg_info.scrutinee_str, sugg_info.as_ref_str, sugg_info.body_str
+ )
},
- _ => None,
- }
+ sugg_info.app,
+ );
}
- f(cx, pat, 0, ctxt)
}
// Checks for an expression wrapped by the `Some` constructor. Returns the contained expression.
fn get_some_expr<'tcx>(
cx: &LateContext<'tcx>,
+ _: &'tcx Pat<'_>,
expr: &'tcx Expr<'_>,
- needs_unsafe_block: bool,
ctxt: SyntaxContext,
) -> Option<SomeExpr<'tcx>> {
- // TODO: Allow more complex expressions.
- match expr.kind {
- ExprKind::Call(
- Expr {
- kind: ExprKind::Path(ref qpath),
- ..
- },
- [arg],
- ) if ctxt == expr.span.ctxt() && is_lang_ctor(cx, qpath, OptionSome) => Some(SomeExpr {
- expr: arg,
- needs_unsafe_block,
- }),
- ExprKind::Block(
- Block {
- stmts: [],
- expr: Some(expr),
- rules,
- ..
+ fn get_some_expr_internal<'tcx>(
+ cx: &LateContext<'tcx>,
+ expr: &'tcx Expr<'_>,
+ needs_unsafe_block: bool,
+ ctxt: SyntaxContext,
+ ) -> Option<SomeExpr<'tcx>> {
+ // TODO: Allow more complex expressions.
+ match expr.kind {
+ ExprKind::Call(callee, [arg])
+ if ctxt == expr.span.ctxt() && is_res_lang_ctor(cx, path_res(cx, callee), OptionSome) =>
+ {
+ Some(SomeExpr::new_no_negated(arg, needs_unsafe_block))
},
- _,
- ) => get_some_expr(
- cx,
- expr,
- needs_unsafe_block || *rules == BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided),
- ctxt,
- ),
- _ => None,
+ ExprKind::Block(
+ Block {
+ stmts: [],
+ expr: Some(expr),
+ rules,
+ ..
+ },
+ _,
+ ) => get_some_expr_internal(
+ cx,
+ expr,
+ needs_unsafe_block || *rules == BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided),
+ ctxt,
+ ),
+ _ => None,
+ }
}
-}
-
-// Checks for the `None` value.
-fn is_none_expr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
- matches!(peel_blocks(expr).kind, ExprKind::Path(ref qpath) if is_lang_ctor(cx, qpath, OptionNone))
+ get_some_expr_internal(cx, expr, false, ctxt)
}
diff --git a/src/tools/clippy/clippy_lints/src/matches/manual_unwrap_or.rs b/src/tools/clippy/clippy_lints/src/matches/manual_unwrap_or.rs
index e1111c80f..587c926dc 100644
--- a/src/tools/clippy/clippy_lints/src/matches/manual_unwrap_or.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/manual_unwrap_or.rs
@@ -3,12 +3,14 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::{indent_of, reindent_multiline, snippet_opt};
use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::usage::contains_return_break_continue_macro;
-use clippy_utils::{is_lang_ctor, path_to_local_id, sugg};
+use clippy_utils::{is_res_lang_ctor, path_to_local_id, sugg};
use if_chain::if_chain;
use rustc_errors::Applicability;
-use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk};
+use rustc_hir::def::{DefKind, Res};
+use rustc_hir::LangItem::{OptionNone, ResultErr};
use rustc_hir::{Arm, Expr, PatKind};
use rustc_lint::LateContext;
+use rustc_middle::ty::DefIdTree;
use rustc_span::sym;
use super::MANUAL_UNWRAP_OR;
@@ -42,12 +44,10 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, scrutinee:
span_lint_and_sugg(
cx,
MANUAL_UNWRAP_OR, expr.span,
- &format!("this pattern reimplements `{}::unwrap_or`", ty_name),
+ &format!("this pattern reimplements `{ty_name}::unwrap_or`"),
"replace with",
format!(
- "{}.unwrap_or({})",
- suggestion,
- reindented_or_body,
+ "{suggestion}.unwrap_or({reindented_or_body})",
),
Applicability::MachineApplicable,
);
@@ -61,15 +61,19 @@ fn applicable_or_arm<'a>(cx: &LateContext<'_>, arms: &'a [Arm<'a>]) -> Option<&'
if arms.iter().all(|arm| arm.guard.is_none());
if let Some((idx, or_arm)) = arms.iter().enumerate().find(|(_, arm)| {
match arm.pat.kind {
- PatKind::Path(ref qpath) => is_lang_ctor(cx, qpath, OptionNone),
+ PatKind::Path(ref qpath) => is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), OptionNone),
PatKind::TupleStruct(ref qpath, [pat], _) =>
- matches!(pat.kind, PatKind::Wild) && is_lang_ctor(cx, qpath, ResultErr),
+ matches!(pat.kind, PatKind::Wild)
+ && is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), ResultErr),
_ => false,
}
});
let unwrap_arm = &arms[1 - idx];
if let PatKind::TupleStruct(ref qpath, [unwrap_pat], _) = unwrap_arm.pat.kind;
- if is_lang_ctor(cx, qpath, OptionSome) || is_lang_ctor(cx, qpath, ResultOk);
+ if let Res::Def(DefKind::Ctor(..), ctor_id) = cx.qpath_res(qpath, unwrap_arm.pat.hir_id);
+ if let Some(variant_id) = cx.tcx.opt_parent(ctor_id);
+ if cx.tcx.lang_items().option_some_variant() == Some(variant_id)
+ || cx.tcx.lang_items().result_ok_variant() == Some(variant_id);
if let PatKind::Binding(_, binding_hir_id, ..) = unwrap_pat.kind;
if path_to_local_id(unwrap_arm.body, binding_hir_id);
if cx.typeck_results().expr_adjustments(unwrap_arm.body).is_empty();
diff --git a/src/tools/clippy/clippy_lints/src/matches/manual_utils.rs b/src/tools/clippy/clippy_lints/src/matches/manual_utils.rs
new file mode 100644
index 000000000..5b7644a53
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/matches/manual_utils.rs
@@ -0,0 +1,277 @@
+use crate::{map_unit_fn::OPTION_MAP_UNIT_FN, matches::MATCH_AS_REF};
+use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
+use clippy_utils::ty::{is_copy, is_type_diagnostic_item, peel_mid_ty_refs_is_mutable, type_is_unsafe_function};
+use clippy_utils::{
+ can_move_expr_to_closure, is_else_clause, is_lint_allowed, is_res_lang_ctor, path_res, path_to_local_id,
+ peel_blocks, peel_hir_expr_refs, peel_hir_expr_while, sugg::Sugg, CaptureKind,
+};
+use rustc_ast::util::parser::PREC_POSTFIX;
+use rustc_errors::Applicability;
+use rustc_hir::LangItem::{OptionNone, OptionSome};
+use rustc_hir::{def::Res, BindingAnnotation, Expr, ExprKind, HirId, Mutability, Pat, PatKind, Path, QPath};
+use rustc_lint::LateContext;
+use rustc_span::{sym, SyntaxContext};
+
+#[expect(clippy::too_many_arguments)]
+#[expect(clippy::too_many_lines)]
+pub(super) fn check_with<'tcx, F>(
+ cx: &LateContext<'tcx>,
+ expr: &'tcx Expr<'_>,
+ scrutinee: &'tcx Expr<'_>,
+ then_pat: &'tcx Pat<'_>,
+ then_body: &'tcx Expr<'_>,
+ else_pat: Option<&'tcx Pat<'_>>,
+ else_body: &'tcx Expr<'_>,
+ get_some_expr_fn: F,
+) -> Option<SuggInfo<'tcx>>
+where
+ F: Fn(&LateContext<'tcx>, &'tcx Pat<'_>, &'tcx Expr<'_>, SyntaxContext) -> Option<SomeExpr<'tcx>>,
+{
+ let (scrutinee_ty, ty_ref_count, ty_mutability) =
+ peel_mid_ty_refs_is_mutable(cx.typeck_results().expr_ty(scrutinee));
+ if !(is_type_diagnostic_item(cx, scrutinee_ty, sym::Option)
+ && is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::Option))
+ {
+ return None;
+ }
+
+ let expr_ctxt = expr.span.ctxt();
+ let (some_expr, some_pat, pat_ref_count, is_wild_none) = match (
+ try_parse_pattern(cx, then_pat, expr_ctxt),
+ else_pat.map_or(Some(OptionPat::Wild), |p| try_parse_pattern(cx, p, expr_ctxt)),
+ ) {
+ (Some(OptionPat::Wild), Some(OptionPat::Some { pattern, ref_count })) if is_none_expr(cx, then_body) => {
+ (else_body, pattern, ref_count, true)
+ },
+ (Some(OptionPat::None), Some(OptionPat::Some { pattern, ref_count })) if is_none_expr(cx, then_body) => {
+ (else_body, pattern, ref_count, false)
+ },
+ (Some(OptionPat::Some { pattern, ref_count }), Some(OptionPat::Wild)) if is_none_expr(cx, else_body) => {
+ (then_body, pattern, ref_count, true)
+ },
+ (Some(OptionPat::Some { pattern, ref_count }), Some(OptionPat::None)) if is_none_expr(cx, else_body) => {
+ (then_body, pattern, ref_count, false)
+ },
+ _ => return None,
+ };
+
+ // Top level or patterns aren't allowed in closures.
+ if matches!(some_pat.kind, PatKind::Or(_)) {
+ return None;
+ }
+
+ let Some(some_expr) = get_some_expr_fn(cx, some_pat, some_expr, expr_ctxt) else {
+ return None;
+ };
+
+ // These two lints will go back and forth with each other.
+ if cx.typeck_results().expr_ty(some_expr.expr) == cx.tcx.types.unit
+ && !is_lint_allowed(cx, OPTION_MAP_UNIT_FN, expr.hir_id)
+ {
+ return None;
+ }
+
+ // `map` won't perform any adjustments.
+ if !cx.typeck_results().expr_adjustments(some_expr.expr).is_empty() {
+ return None;
+ }
+
+ // Determine which binding mode to use.
+ let explicit_ref = some_pat.contains_explicit_ref_binding();
+ let binding_ref = explicit_ref.or_else(|| (ty_ref_count != pat_ref_count).then_some(ty_mutability));
+
+ let as_ref_str = match binding_ref {
+ Some(Mutability::Mut) => ".as_mut()",
+ Some(Mutability::Not) => ".as_ref()",
+ None => "",
+ };
+
+ match can_move_expr_to_closure(cx, some_expr.expr) {
+ Some(captures) => {
+ // Check if captures the closure will need conflict with borrows made in the scrutinee.
+ // TODO: check all the references made in the scrutinee expression. This will require interacting
+ // with the borrow checker. Currently only `<local>[.<field>]*` is checked for.
+ if let Some(binding_ref_mutability) = binding_ref {
+ let e = peel_hir_expr_while(scrutinee, |e| match e.kind {
+ ExprKind::Field(e, _) | ExprKind::AddrOf(_, _, e) => Some(e),
+ _ => None,
+ });
+ if let ExprKind::Path(QPath::Resolved(None, Path { res: Res::Local(l), .. })) = e.kind {
+ match captures.get(l) {
+ Some(CaptureKind::Value | CaptureKind::Ref(Mutability::Mut)) => return None,
+ Some(CaptureKind::Ref(Mutability::Not)) if binding_ref_mutability == Mutability::Mut => {
+ return None;
+ },
+ Some(CaptureKind::Ref(Mutability::Not)) | None => (),
+ }
+ }
+ }
+ },
+ None => return None,
+ };
+
+ let mut app = Applicability::MachineApplicable;
+
+ // Remove address-of expressions from the scrutinee. Either `as_ref` will be called, or
+ // it's being passed by value.
+ let scrutinee = peel_hir_expr_refs(scrutinee).0;
+ let (scrutinee_str, _) = snippet_with_context(cx, scrutinee.span, expr_ctxt, "..", &mut app);
+ let scrutinee_str = if scrutinee.span.ctxt() == expr.span.ctxt() && scrutinee.precedence().order() < PREC_POSTFIX {
+ format!("({scrutinee_str})")
+ } else {
+ scrutinee_str.into()
+ };
+
+ let closure_expr_snip = some_expr.to_snippet_with_context(cx, expr_ctxt, &mut app);
+ let body_str = if let PatKind::Binding(annotation, id, some_binding, None) = some_pat.kind {
+ if_chain! {
+ if !some_expr.needs_unsafe_block;
+ if let Some(func) = can_pass_as_func(cx, id, some_expr.expr);
+ if func.span.ctxt() == some_expr.expr.span.ctxt();
+ then {
+ snippet_with_applicability(cx, func.span, "..", &mut app).into_owned()
+ } else {
+ if path_to_local_id(some_expr.expr, id)
+ && !is_lint_allowed(cx, MATCH_AS_REF, expr.hir_id)
+ && binding_ref.is_some()
+ {
+ return None;
+ }
+
+ // `ref` and `ref mut` annotations were handled earlier.
+ let annotation = if matches!(annotation, BindingAnnotation::MUT) {
+ "mut "
+ } else {
+ ""
+ };
+
+ if some_expr.needs_unsafe_block {
+ format!("|{annotation}{some_binding}| unsafe {{ {closure_expr_snip} }}")
+ } else {
+ format!("|{annotation}{some_binding}| {closure_expr_snip}")
+ }
+ }
+ }
+ } else if !is_wild_none && explicit_ref.is_none() {
+ // TODO: handle explicit reference annotations.
+ let pat_snip = snippet_with_context(cx, some_pat.span, expr_ctxt, "..", &mut app).0;
+ if some_expr.needs_unsafe_block {
+ format!("|{pat_snip}| unsafe {{ {closure_expr_snip} }}")
+ } else {
+ format!("|{pat_snip}| {closure_expr_snip}")
+ }
+ } else {
+ // Refutable bindings and mixed reference annotations can't be handled by `map`.
+ return None;
+ };
+
+ // relies on the fact that Option<T>: Copy where T: copy
+ let scrutinee_impl_copy = is_copy(cx, scrutinee_ty);
+
+ Some(SuggInfo {
+ needs_brackets: else_pat.is_none() && is_else_clause(cx.tcx, expr),
+ scrutinee_impl_copy,
+ scrutinee_str,
+ as_ref_str,
+ body_str,
+ app,
+ })
+}
+
+pub struct SuggInfo<'a> {
+ pub needs_brackets: bool,
+ pub scrutinee_impl_copy: bool,
+ pub scrutinee_str: String,
+ pub as_ref_str: &'a str,
+ pub body_str: String,
+ pub app: Applicability,
+}
+
+// Checks whether the expression could be passed as a function, or whether a closure is needed.
+// Returns the function to be passed to `map` if it exists.
+fn can_pass_as_func<'tcx>(cx: &LateContext<'tcx>, binding: HirId, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
+ match expr.kind {
+ ExprKind::Call(func, [arg])
+ if path_to_local_id(arg, binding)
+ && cx.typeck_results().expr_adjustments(arg).is_empty()
+ && !type_is_unsafe_function(cx, cx.typeck_results().expr_ty(func).peel_refs()) =>
+ {
+ Some(func)
+ },
+ _ => None,
+ }
+}
+
+#[derive(Debug)]
+pub(super) enum OptionPat<'a> {
+ Wild,
+ None,
+ Some {
+ // The pattern contained in the `Some` tuple.
+ pattern: &'a Pat<'a>,
+ // The number of references before the `Some` tuple.
+ // e.g. `&&Some(_)` has a ref count of 2.
+ ref_count: usize,
+ },
+}
+
+pub(super) struct SomeExpr<'tcx> {
+ pub expr: &'tcx Expr<'tcx>,
+ pub needs_unsafe_block: bool,
+ pub needs_negated: bool, // for `manual_filter` lint
+}
+
+impl<'tcx> SomeExpr<'tcx> {
+ pub fn new_no_negated(expr: &'tcx Expr<'tcx>, needs_unsafe_block: bool) -> Self {
+ Self {
+ expr,
+ needs_unsafe_block,
+ needs_negated: false,
+ }
+ }
+
+ pub fn to_snippet_with_context(
+ &self,
+ cx: &LateContext<'tcx>,
+ ctxt: SyntaxContext,
+ app: &mut Applicability,
+ ) -> Sugg<'tcx> {
+ let sugg = Sugg::hir_with_context(cx, self.expr, ctxt, "..", app);
+ if self.needs_negated { !sugg } else { sugg }
+ }
+}
+
+// Try to parse into a recognized `Option` pattern.
+// i.e. `_`, `None`, `Some(..)`, or a reference to any of those.
+pub(super) fn try_parse_pattern<'tcx>(
+ cx: &LateContext<'tcx>,
+ pat: &'tcx Pat<'_>,
+ ctxt: SyntaxContext,
+) -> Option<OptionPat<'tcx>> {
+ fn f<'tcx>(
+ cx: &LateContext<'tcx>,
+ pat: &'tcx Pat<'_>,
+ ref_count: usize,
+ ctxt: SyntaxContext,
+ ) -> Option<OptionPat<'tcx>> {
+ match pat.kind {
+ PatKind::Wild => Some(OptionPat::Wild),
+ PatKind::Ref(pat, _) => f(cx, pat, ref_count + 1, ctxt),
+ PatKind::Path(ref qpath) if is_res_lang_ctor(cx, cx.qpath_res(qpath, pat.hir_id), OptionNone) => {
+ Some(OptionPat::None)
+ },
+ PatKind::TupleStruct(ref qpath, [pattern], _)
+ if is_res_lang_ctor(cx, cx.qpath_res(qpath, pat.hir_id), OptionSome) && pat.span.ctxt() == ctxt =>
+ {
+ Some(OptionPat::Some { pattern, ref_count })
+ },
+ _ => None,
+ }
+ }
+ f(cx, pat, 0, ctxt)
+}
+
+// Checks for the `None` value.
+fn is_none_expr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
+ is_res_lang_ctor(cx, path_res(cx, peel_blocks(expr)), OptionNone)
+}
diff --git a/src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs b/src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs
index 91d17f481..2818f030b 100644
--- a/src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs
@@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
-use clippy_utils::{is_lang_ctor, peel_blocks};
+use clippy_utils::{is_res_lang_ctor, path_res, peel_blocks};
use rustc_errors::Applicability;
use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, LangItem, Mutability, PatKind, QPath};
use rustc_lint::LateContext;
@@ -45,13 +45,11 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr:
cx,
MATCH_AS_REF,
expr.span,
- &format!("use `{}()` instead", suggestion),
+ &format!("use `{suggestion}()` instead"),
"try this",
format!(
- "{}.{}(){}",
+ "{}.{suggestion}(){cast}",
snippet_with_applicability(cx, ex.span, "_", &mut applicability),
- suggestion,
- cast,
),
applicability,
);
@@ -61,18 +59,20 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr:
// Checks if arm has the form `None => None`
fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
- matches!(arm.pat.kind, PatKind::Path(ref qpath) if is_lang_ctor(cx, qpath, LangItem::OptionNone))
+ matches!(
+ arm.pat.kind,
+ PatKind::Path(ref qpath) if is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), LangItem::OptionNone)
+ )
}
// Checks if arm has the form `Some(ref v) => Some(v)` (checks for `ref` and `ref mut`)
fn is_ref_some_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> Option<Mutability> {
if_chain! {
if let PatKind::TupleStruct(ref qpath, [first_pat, ..], _) = arm.pat.kind;
- if is_lang_ctor(cx, qpath, LangItem::OptionSome);
+ if is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), LangItem::OptionSome);
if let PatKind::Binding(BindingAnnotation(ByRef::Yes, mutabl), .., ident, _) = first_pat.kind;
if let ExprKind::Call(e, [arg]) = peel_blocks(arm.body).kind;
- if let ExprKind::Path(ref some_path) = e.kind;
- if is_lang_ctor(cx, some_path, LangItem::OptionSome);
+ if is_res_lang_ctor(cx, path_res(cx, e), LangItem::OptionSome);
if let ExprKind::Path(QPath::Resolved(_, path2)) = arg.kind;
if path2.segments.len() == 1 && ident.name == path2.segments[0].ident.name;
then {
diff --git a/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs b/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs
index 34cc08268..107fad323 100644
--- a/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/match_like_matches.rs
@@ -112,7 +112,7 @@ where
.join(" | ")
};
let pat_and_guard = if let Some(Guard::If(g)) = first_guard {
- format!("{} if {}", pat, snippet_with_applicability(cx, g.span, "..", &mut applicability))
+ format!("{pat} if {}", snippet_with_applicability(cx, g.span, "..", &mut applicability))
} else {
pat
};
@@ -131,10 +131,9 @@ where
&format!("{} expression looks like `matches!` macro", if is_if_let { "if let .. else" } else { "match" }),
"try this",
format!(
- "{}matches!({}, {})",
+ "{}matches!({}, {pat_and_guard})",
if b0 { "" } else { "!" },
snippet_with_applicability(cx, ex_new.span, "..", &mut applicability),
- pat_and_guard,
),
applicability,
);
diff --git a/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs b/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs
index d37f44d4a..168c1e4d2 100644
--- a/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs
@@ -134,7 +134,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
diag.span_suggestion(
keep_arm.pat.span,
"try merging the arm patterns",
- format!("{} | {}", keep_pat_snip, move_pat_snip),
+ format!("{keep_pat_snip} | {move_pat_snip}"),
Applicability::MaybeIncorrect,
)
.help("or try changing either arm body")
@@ -221,7 +221,6 @@ fn iter_matching_struct_fields<'a>(
#[expect(clippy::similar_names)]
impl<'a> NormalizedPat<'a> {
- #[expect(clippy::too_many_lines)]
fn from_pat(cx: &LateContext<'_>, arena: &'a DroplessArena, pat: &'a Pat<'_>) -> Self {
match pat.kind {
PatKind::Wild | PatKind::Binding(.., None) => Self::Wild,
@@ -235,9 +234,8 @@ impl<'a> NormalizedPat<'a> {
Self::Struct(cx.qpath_res(path, pat.hir_id).opt_def_id(), fields)
},
PatKind::TupleStruct(ref path, pats, wild_idx) => {
- let adt = match cx.typeck_results().pat_ty(pat).ty_adt_def() {
- Some(x) => x,
- None => return Self::Wild,
+ let Some(adt) = cx.typeck_results().pat_ty(pat).ty_adt_def() else {
+ return Self::Wild
};
let (var_id, variant) = if adt.is_enum() {
match cx.qpath_res(path, pat.hir_id).opt_def_id() {
diff --git a/src/tools/clippy/clippy_lints/src/matches/match_single_binding.rs b/src/tools/clippy/clippy_lints/src/matches/match_single_binding.rs
index 5ae4a65ac..1bf8d4e96 100644
--- a/src/tools/clippy/clippy_lints/src/matches/match_single_binding.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/match_single_binding.rs
@@ -58,6 +58,7 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
&snippet_body,
&mut applicability,
Some(span),
+ true,
);
span_lint_and_sugg(
@@ -75,12 +76,11 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
Some(AssignmentExpr::Local { span, pat_span }) => (
span,
format!(
- "let {} = {};\n{}let {} = {};",
+ "let {} = {};\n{}let {} = {snippet_body};",
snippet_with_applicability(cx, bind_names, "..", &mut applicability),
snippet_with_applicability(cx, matched_vars, "..", &mut applicability),
" ".repeat(indent_of(cx, expr.span).unwrap_or(0)),
- snippet_with_applicability(cx, pat_span, "..", &mut applicability),
- snippet_body
+ snippet_with_applicability(cx, pat_span, "..", &mut applicability)
),
),
None => {
@@ -91,6 +91,7 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
&snippet_body,
&mut applicability,
None,
+ true,
);
(expr.span, sugg)
},
@@ -108,12 +109,14 @@ pub(crate) fn check<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[Arm<'_>], e
},
PatKind::Wild => {
if ex.can_have_side_effects() {
- let indent = " ".repeat(indent_of(cx, expr.span).unwrap_or(0));
- let sugg = format!(
- "{};\n{}{}",
- snippet_with_applicability(cx, ex.span, "..", &mut applicability),
- indent,
- snippet_body
+ let sugg = sugg_with_curlies(
+ cx,
+ (ex, expr),
+ (bind_names, matched_vars),
+ &snippet_body,
+ &mut applicability,
+ None,
+ false,
);
span_lint_and_sugg(
@@ -172,16 +175,17 @@ fn sugg_with_curlies<'a>(
snippet_body: &str,
applicability: &mut Applicability,
assignment: Option<Span>,
+ needs_var_binding: bool,
) -> String {
let mut indent = " ".repeat(indent_of(cx, ex.span).unwrap_or(0));
let (mut cbrace_start, mut cbrace_end) = (String::new(), String::new());
if let Some(parent_expr) = get_parent_expr(cx, match_expr) {
if let ExprKind::Closure { .. } = parent_expr.kind {
- cbrace_end = format!("\n{}}}", indent);
+ cbrace_end = format!("\n{indent}}}");
// Fix body indent due to the closure
indent = " ".repeat(indent_of(cx, bind_names).unwrap_or(0));
- cbrace_start = format!("{{\n{}", indent);
+ cbrace_start = format!("{{\n{indent}");
}
}
@@ -190,10 +194,10 @@ fn sugg_with_curlies<'a>(
let parent_node_id = cx.tcx.hir().get_parent_node(match_expr.hir_id);
if let Node::Arm(arm) = &cx.tcx.hir().get(parent_node_id) {
if let ExprKind::Match(..) = arm.body.kind {
- cbrace_end = format!("\n{}}}", indent);
+ cbrace_end = format!("\n{indent}}}");
// Fix body indent due to the match
indent = " ".repeat(indent_of(cx, bind_names).unwrap_or(0));
- cbrace_start = format!("{{\n{}", indent);
+ cbrace_start = format!("{{\n{indent}");
}
}
@@ -203,14 +207,15 @@ fn sugg_with_curlies<'a>(
s
});
- format!(
- "{}let {} = {};\n{}{}{}{}",
- cbrace_start,
- snippet_with_applicability(cx, bind_names, "..", applicability),
- snippet_with_applicability(cx, matched_vars, "..", applicability),
- indent,
- assignment_str,
- snippet_body,
- cbrace_end
- )
+ let scrutinee = if needs_var_binding {
+ format!(
+ "let {} = {}",
+ snippet_with_applicability(cx, bind_names, "..", applicability),
+ snippet_with_applicability(cx, matched_vars, "..", applicability)
+ )
+ } else {
+ snippet_with_applicability(cx, matched_vars, "..", applicability).to_string()
+ };
+
+ format!("{cbrace_start}{scrutinee};\n{indent}{assignment_str}{snippet_body}{cbrace_end}")
}
diff --git a/src/tools/clippy/clippy_lints/src/matches/match_str_case_mismatch.rs b/src/tools/clippy/clippy_lints/src/matches/match_str_case_mismatch.rs
index 1e80b6cf2..6647322ca 100644
--- a/src/tools/clippy/clippy_lints/src/matches/match_str_case_mismatch.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/match_str_case_mismatch.rs
@@ -118,8 +118,8 @@ fn lint(cx: &LateContext<'_>, case_method: &CaseMethod, bad_case_span: Span, bad
MATCH_STR_CASE_MISMATCH,
bad_case_span,
"this `match` arm has a differing case than its expression",
- &format!("consider changing the case of this arm to respect `{}`", method_str),
- format!("\"{}\"", suggestion),
+ &format!("consider changing the case of this arm to respect `{method_str}`"),
+ format!("\"{suggestion}\""),
Applicability::MachineApplicable,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/matches/match_wild_err_arm.rs b/src/tools/clippy/clippy_lints/src/matches/match_wild_err_arm.rs
index a3aa2e4b3..42f1e2629 100644
--- a/src/tools/clippy/clippy_lints/src/matches/match_wild_err_arm.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/match_wild_err_arm.rs
@@ -38,7 +38,7 @@ pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm<'
span_lint_and_note(cx,
MATCH_WILD_ERR_ARM,
arm.pat.span,
- &format!("`Err({})` matches all errors", ident_bind_name),
+ &format!("`Err({ident_bind_name})` matches all errors"),
None,
"match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable",
);
diff --git a/src/tools/clippy/clippy_lints/src/matches/mod.rs b/src/tools/clippy/clippy_lints/src/matches/mod.rs
index e6b183fc0..7d8171ead 100644
--- a/src/tools/clippy/clippy_lints/src/matches/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/mod.rs
@@ -1,7 +1,9 @@
mod collapsible_match;
mod infallible_destructuring_match;
+mod manual_filter;
mod manual_map;
mod manual_unwrap_or;
+mod manual_utils;
mod match_as_ref;
mod match_bool;
mod match_like_matches;
@@ -898,6 +900,34 @@ declare_clippy_lint! {
"reimplementation of `map`"
}
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for usages of `match` which could be implemented using `filter`
+ ///
+ /// ### Why is this bad?
+ /// Using the `filter` method is clearer and more concise.
+ ///
+ /// ### Example
+ /// ```rust
+ /// match Some(0) {
+ /// Some(x) => if x % 2 == 0 {
+ /// Some(x)
+ /// } else {
+ /// None
+ /// },
+ /// None => None,
+ /// };
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// Some(0).filter(|&x| x % 2 == 0);
+ /// ```
+ #[clippy::version = "1.66.0"]
+ pub MANUAL_FILTER,
+ complexity,
+ "reimplentation of `filter`"
+}
+
#[derive(Default)]
pub struct Matches {
msrv: Option<RustcVersion>,
@@ -939,6 +969,7 @@ impl_lint_pass!(Matches => [
SIGNIFICANT_DROP_IN_SCRUTINEE,
TRY_ERR,
MANUAL_MAP,
+ MANUAL_FILTER,
]);
impl<'tcx> LateLintPass<'tcx> for Matches {
@@ -988,6 +1019,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
if !in_constant(cx, expr.hir_id) {
manual_unwrap_or::check(cx, expr, ex, arms);
manual_map::check_match(cx, expr, ex, arms);
+ manual_filter::check_match(cx, ex, arms, expr);
}
if self.infallible_destructuring_match_linted {
@@ -1014,6 +1046,14 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
}
if !in_constant(cx, expr.hir_id) {
manual_map::check_if_let(cx, expr, if_let.let_pat, if_let.let_expr, if_let.if_then, else_expr);
+ manual_filter::check_if_let(
+ cx,
+ expr,
+ if_let.let_pat,
+ if_let.let_expr,
+ if_let.if_then,
+ else_expr,
+ );
}
}
redundant_pattern_match::check_if_let(
diff --git a/src/tools/clippy/clippy_lints/src/matches/needless_match.rs b/src/tools/clippy/clippy_lints/src/matches/needless_match.rs
index 634eef82e..c4f6852ae 100644
--- a/src/tools/clippy/clippy_lints/src/matches/needless_match.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/needless_match.rs
@@ -3,15 +3,15 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::{is_type_diagnostic_item, same_type_and_consts};
use clippy_utils::{
- eq_expr_value, get_parent_expr_for_hir, get_parent_node, higher, is_else_clause, is_lang_ctor, over,
+ eq_expr_value, get_parent_expr_for_hir, get_parent_node, higher, is_else_clause, is_res_lang_ctor, over, path_res,
peel_blocks_with_stmt,
};
use rustc_errors::Applicability;
use rustc_hir::LangItem::OptionNone;
use rustc_hir::{Arm, BindingAnnotation, ByRef, Expr, ExprKind, FnRetTy, Guard, Node, Pat, PatKind, Path, QPath};
+use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::LateContext;
use rustc_span::sym;
-use rustc_typeck::hir_ty_to_ty;
pub(crate) fn check_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
if arms.len() > 1 && expr_ty_matches_p_ty(cx, ex, expr) && check_all_arms(cx, ex, arms) {
@@ -112,10 +112,7 @@ fn check_if_let_inner(cx: &LateContext<'_>, if_let: &higher::IfLet<'_>) -> bool
let ret = strip_return(else_expr);
let let_expr_ty = cx.typeck_results().expr_ty(if_let.let_expr);
if is_type_diagnostic_item(cx, let_expr_ty, sym::Option) {
- if let ExprKind::Path(ref qpath) = ret.kind {
- return is_lang_ctor(cx, qpath, OptionNone) || eq_expr_value(cx, if_let.let_expr, ret);
- }
- return false;
+ return is_res_lang_ctor(cx, path_res(cx, ret), OptionNone) || eq_expr_value(cx, if_let.let_expr, ret);
}
return eq_expr_value(cx, if_let.let_expr, ret);
}
diff --git a/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs b/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs
index c89784065..81bebff34 100644
--- a/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs
@@ -4,11 +4,12 @@ use clippy_utils::source::snippet;
use clippy_utils::sugg::Sugg;
use clippy_utils::ty::{is_type_diagnostic_item, needs_ordered_drop};
use clippy_utils::visitors::any_temporaries_need_ordered_drop;
-use clippy_utils::{higher, is_lang_ctor, is_trait_method};
+use clippy_utils::{higher, is_trait_method};
use if_chain::if_chain;
use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
-use rustc_hir::LangItem::{self, OptionSome, OptionNone, PollPending, PollReady, ResultOk, ResultErr};
+use rustc_hir::def::{DefKind, Res};
+use rustc_hir::LangItem::{self, OptionNone, OptionSome, PollPending, PollReady, ResultErr, ResultOk};
use rustc_hir::{Arm, Expr, ExprKind, Node, Pat, PatKind, QPath, UnOp};
use rustc_lint::LateContext;
use rustc_middle::ty::{self, subst::GenericArgKind, DefIdTree, Ty};
@@ -87,15 +88,21 @@ fn find_sugg_for_if_let<'tcx>(
}
},
PatKind::Path(ref path) => {
- let method = if is_lang_ctor(cx, path, OptionNone) {
- "is_none()"
- } else if is_lang_ctor(cx, path, PollPending) {
- "is_pending()"
+ if let Res::Def(DefKind::Ctor(..), ctor_id) = cx.qpath_res(path, check_pat.hir_id)
+ && let Some(variant_id) = cx.tcx.opt_parent(ctor_id)
+ {
+ let method = if cx.tcx.lang_items().option_none_variant() == Some(variant_id) {
+ "is_none()"
+ } else if cx.tcx.lang_items().poll_pending_variant() == Some(variant_id) {
+ "is_pending()"
+ } else {
+ return;
+ };
+ // `None` and `Pending` don't have an inner type.
+ (method, cx.tcx.types.unit)
} else {
return;
- };
- // `None` and `Pending` don't have an inner type.
- (method, cx.tcx.types.unit)
+ }
},
_ => return,
};
@@ -138,7 +145,7 @@ fn find_sugg_for_if_let<'tcx>(
cx,
REDUNDANT_PATTERN_MATCHING,
let_pat.span,
- &format!("redundant pattern matching, consider using `{}`", good_method),
+ &format!("redundant pattern matching, consider using `{good_method}`"),
|diag| {
// if/while let ... = ... { ... }
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -162,7 +169,7 @@ fn find_sugg_for_if_let<'tcx>(
.maybe_par()
.to_string();
- diag.span_suggestion(span, "try this", format!("{} {}.{}", keyword, sugg, good_method), app);
+ diag.span_suggestion(span, "try this", format!("{keyword} {sugg}.{good_method}"), app);
if needs_drop {
diag.note("this will change drop order of the result, as well as all temporaries");
@@ -213,7 +220,6 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op
if patterns.len() == 1 =>
{
if let PatKind::Wild = patterns[0].kind {
-
find_good_method_for_match(
cx,
arms,
@@ -253,12 +259,12 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op
cx,
REDUNDANT_PATTERN_MATCHING,
expr.span,
- &format!("redundant pattern matching, consider using `{}`", good_method),
+ &format!("redundant pattern matching, consider using `{good_method}`"),
|diag| {
diag.span_suggestion(
span,
"try this",
- format!("{}.{}", snippet(cx, result_expr.span, "_"), good_method),
+ format!("{}.{good_method}", snippet(cx, result_expr.span, "_")),
Applicability::MaybeIncorrect, // snippet
);
},
@@ -269,8 +275,8 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op
#[derive(Clone, Copy)]
enum Item {
- Lang(LangItem),
- Diag(Symbol, Symbol),
+ Lang(LangItem),
+ Diag(Symbol, Symbol),
}
fn is_pat_variant(cx: &LateContext<'_>, pat: &Pat<'_>, path: &QPath<'_>, expected_item: Item) -> bool {
@@ -285,15 +291,16 @@ fn is_pat_variant(cx: &LateContext<'_>, pat: &Pat<'_>, path: &QPath<'_>, expecte
let ty = cx.typeck_results().pat_ty(pat);
if is_type_diagnostic_item(cx, ty, expected_ty) {
- let variant = ty.ty_adt_def()
+ let variant = ty
+ .ty_adt_def()
.expect("struct pattern type is not an ADT")
.variant_of_res(cx.qpath_res(path, pat.hir_id));
- return variant.name == expected_variant
+ return variant.name == expected_variant;
}
false
- }
+ },
}
}
@@ -308,20 +315,16 @@ fn find_good_method_for_match<'a>(
should_be_left: &'a str,
should_be_right: &'a str,
) -> Option<&'a str> {
- let pat_left = arms[0].pat;
- let pat_right = arms[1].pat;
+ let first_pat = arms[0].pat;
+ let second_pat = arms[1].pat;
- let body_node_pair = if (
- is_pat_variant(cx, pat_left, path_left, expected_item_left)
- ) && (
- is_pat_variant(cx, pat_right, path_right, expected_item_right)
- ) {
+ let body_node_pair = if (is_pat_variant(cx, first_pat, path_left, expected_item_left))
+ && (is_pat_variant(cx, second_pat, path_right, expected_item_right))
+ {
(&arms[0].body.kind, &arms[1].body.kind)
- } else if (
- is_pat_variant(cx, pat_left, path_left, expected_item_right)
- ) && (
- is_pat_variant(cx, pat_right, path_right, expected_item_left)
- ) {
+ } else if (is_pat_variant(cx, first_pat, path_left, expected_item_right))
+ && (is_pat_variant(cx, second_pat, path_right, expected_item_left))
+ {
(&arms[1].body.kind, &arms[0].body.kind)
} else {
return None;
diff --git a/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs
index 86a9df034..85269e533 100644
--- a/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs
@@ -50,13 +50,13 @@ fn set_diagnostic<'tcx>(diag: &mut Diagnostic, cx: &LateContext<'tcx>, expr: &'t
let trailing_indent = " ".repeat(indent_of(cx, found.found_span).unwrap_or(0));
let replacement = if found.lint_suggestion == LintSuggestion::MoveAndDerefToCopy {
- format!("let value = *{};\n{}", original, trailing_indent)
+ format!("let value = *{original};\n{trailing_indent}")
} else if found.is_unit_return_val {
// If the return value of the expression to be moved is unit, then we don't need to
// capture the result in a temporary -- we can just replace it completely with `()`.
- format!("{};\n{}", original, trailing_indent)
+ format!("{original};\n{trailing_indent}")
} else {
- format!("let value = {};\n{}", original, trailing_indent)
+ format!("let value = {original};\n{trailing_indent}")
};
let suggestion_message = if found.lint_suggestion == LintSuggestion::MoveOnly {
diff --git a/src/tools/clippy/clippy_lints/src/matches/single_match.rs b/src/tools/clippy/clippy_lints/src/matches/single_match.rs
index 56bcdc01f..e5a15b2e1 100644
--- a/src/tools/clippy/clippy_lints/src/matches/single_match.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/single_match.rs
@@ -1,14 +1,13 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::{expr_block, snippet};
-use clippy_utils::ty::{implements_trait, match_type, peel_mid_ty_refs};
-use clippy_utils::{
- is_lint_allowed, is_unit_expr, is_wild, paths, peel_blocks, peel_hir_pat_refs, peel_n_hir_expr_refs,
-};
+use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, peel_mid_ty_refs};
+use clippy_utils::{is_lint_allowed, is_unit_expr, is_wild, peel_blocks, peel_hir_pat_refs, peel_n_hir_expr_refs};
use core::cmp::max;
use rustc_errors::Applicability;
use rustc_hir::{Arm, BindingAnnotation, Block, Expr, ExprKind, Pat, PatKind};
use rustc_lint::LateContext;
use rustc_middle::ty::{self, Ty};
+use rustc_span::sym;
use super::{MATCH_BOOL, SINGLE_MATCH, SINGLE_MATCH_ELSE};
@@ -99,23 +98,21 @@ fn report_single_pattern(
let msg = "you seem to be trying to use `match` for an equality check. Consider using `if`";
let sugg = format!(
- "if {} == {}{} {}{}",
+ "if {} == {}{} {}{els_str}",
snippet(cx, ex.span, ".."),
// PartialEq for different reference counts may not exist.
"&".repeat(ref_count_diff),
snippet(cx, arms[0].pat.span, ".."),
expr_block(cx, arms[0].body, None, "..", Some(expr.span)),
- els_str,
);
(msg, sugg)
} else {
let msg = "you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`";
let sugg = format!(
- "if let {} = {} {}{}",
+ "if let {} = {} {}{els_str}",
snippet(cx, arms[0].pat.span, ".."),
snippet(cx, ex.span, ".."),
expr_block(cx, arms[0].body, None, "..", Some(expr.span)),
- els_str,
);
(msg, sugg)
}
@@ -158,10 +155,10 @@ fn pat_in_candidate_enum<'a>(cx: &LateContext<'a>, ty: Ty<'a>, pat: &Pat<'_>) ->
/// Returns `true` if the given type is an enum we know won't be expanded in the future
fn in_candidate_enum<'a>(cx: &LateContext<'a>, ty: Ty<'_>) -> bool {
// list of candidate `Enum`s we know will never get any more members
- let candidates = [&paths::COW, &paths::OPTION, &paths::RESULT];
+ let candidates = [sym::Cow, sym::Option, sym::Result];
for candidate_ty in candidates {
- if match_type(cx, ty, candidate_ty) {
+ if is_type_diagnostic_item(cx, ty, candidate_ty) {
return true;
}
}
diff --git a/src/tools/clippy/clippy_lints/src/matches/try_err.rs b/src/tools/clippy/clippy_lints/src/matches/try_err.rs
index 663277d11..c6cba81d8 100644
--- a/src/tools/clippy/clippy_lints/src/matches/try_err.rs
+++ b/src/tools/clippy/clippy_lints/src/matches/try_err.rs
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::is_type_diagnostic_item;
-use clippy_utils::{get_parent_expr, is_lang_ctor, match_def_path, paths};
+use clippy_utils::{get_parent_expr, is_res_lang_ctor, match_def_path, path_res, paths};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::LangItem::ResultErr;
@@ -27,8 +27,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, scrutine
if let ExprKind::Path(ref match_fun_path) = match_fun.kind;
if matches!(match_fun_path, QPath::LangItem(LangItem::TryTraitBranch, ..));
if let ExprKind::Call(err_fun, [err_arg, ..]) = try_arg.kind;
- if let ExprKind::Path(ref err_fun_path) = err_fun.kind;
- if is_lang_ctor(cx, err_fun_path, ResultErr);
+ if is_res_lang_ctor(cx, path_res(cx, err_fun), ResultErr);
if let Some(return_ty) = find_return_type(cx, &expr.kind);
then {
let prefix;
@@ -61,9 +60,9 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, scrutine
"return "
};
let suggestion = if err_ty == expr_err_ty {
- format!("{}{}{}{}", ret_prefix, prefix, origin_snippet, suffix)
+ format!("{ret_prefix}{prefix}{origin_snippet}{suffix}")
} else {
- format!("{}{}{}.into(){}", ret_prefix, prefix, origin_snippet, suffix)
+ format!("{ret_prefix}{prefix}{origin_snippet}.into(){suffix}")
};
span_lint_and_sugg(
diff --git a/src/tools/clippy/clippy_lints/src/mem_replace.rs b/src/tools/clippy/clippy_lints/src/mem_replace.rs
index cad3ea2a1..0c4d9f100 100644
--- a/src/tools/clippy/clippy_lints/src/mem_replace.rs
+++ b/src/tools/clippy/clippy_lints/src/mem_replace.rs
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
use clippy_utils::source::{snippet, snippet_with_applicability};
use clippy_utils::ty::is_non_aggregate_primitive_type;
-use clippy_utils::{is_default_equivalent, is_lang_ctor, meets_msrv, msrvs};
+use clippy_utils::{is_default_equivalent, is_res_lang_ctor, meets_msrv, msrvs, path_res};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::LangItem::OptionNone;
@@ -102,40 +102,38 @@ impl_lint_pass!(MemReplace =>
[MEM_REPLACE_OPTION_WITH_NONE, MEM_REPLACE_WITH_UNINIT, MEM_REPLACE_WITH_DEFAULT]);
fn check_replace_option_with_none(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) {
- if let ExprKind::Path(ref replacement_qpath) = src.kind {
- // Check that second argument is `Option::None`
- if is_lang_ctor(cx, replacement_qpath, OptionNone) {
- // Since this is a late pass (already type-checked),
- // and we already know that the second argument is an
- // `Option`, we do not need to check the first
- // argument's type. All that's left is to get
- // replacee's path.
- let replaced_path = match dest.kind {
- ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, replaced) => {
- if let ExprKind::Path(QPath::Resolved(None, replaced_path)) = replaced.kind {
- replaced_path
- } else {
- return;
- }
- },
- ExprKind::Path(QPath::Resolved(None, replaced_path)) => replaced_path,
- _ => return,
- };
+ // Check that second argument is `Option::None`
+ if is_res_lang_ctor(cx, path_res(cx, src), OptionNone) {
+ // Since this is a late pass (already type-checked),
+ // and we already know that the second argument is an
+ // `Option`, we do not need to check the first
+ // argument's type. All that's left is to get
+ // replacee's path.
+ let replaced_path = match dest.kind {
+ ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, replaced) => {
+ if let ExprKind::Path(QPath::Resolved(None, replaced_path)) = replaced.kind {
+ replaced_path
+ } else {
+ return;
+ }
+ },
+ ExprKind::Path(QPath::Resolved(None, replaced_path)) => replaced_path,
+ _ => return,
+ };
- let mut applicability = Applicability::MachineApplicable;
- span_lint_and_sugg(
- cx,
- MEM_REPLACE_OPTION_WITH_NONE,
- expr_span,
- "replacing an `Option` with `None`",
- "consider `Option::take()` instead",
- format!(
- "{}.take()",
- snippet_with_applicability(cx, replaced_path.span, "", &mut applicability)
- ),
- applicability,
- );
- }
+ let mut applicability = Applicability::MachineApplicable;
+ span_lint_and_sugg(
+ cx,
+ MEM_REPLACE_OPTION_WITH_NONE,
+ expr_span,
+ "replacing an `Option` with `None`",
+ "consider `Option::take()` instead",
+ format!(
+ "{}.take()",
+ snippet_with_applicability(cx, replaced_path.span, "", &mut applicability)
+ ),
+ applicability,
+ );
}
}
@@ -203,10 +201,8 @@ fn check_replace_with_default(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<
return;
}
// disable lint for Option since it is covered in another lint
- if let ExprKind::Path(q) = &src.kind {
- if is_lang_ctor(cx, q, OptionNone) {
- return;
- }
+ if is_res_lang_ctor(cx, path_res(cx, src), OptionNone) {
+ return;
}
if is_default_equivalent(cx, src) && !in_external_macro(cx.tcx.sess, expr_span) {
span_lint_and_then(
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 22f5635a5..cc26b0f7f 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
@@ -85,7 +85,7 @@ pub(crate) trait BindInsteadOfMap {
let closure_args_snip = snippet(cx, closure_args_span, "..");
let option_snip = snippet(cx, recv.span, "..");
- let note = format!("{}.{}({} {})", option_snip, Self::GOOD_METHOD_NAME, closure_args_snip, some_inner_snip);
+ let note = format!("{option_snip}.{}({closure_args_snip} {some_inner_snip})", Self::GOOD_METHOD_NAME);
span_lint_and_sugg(
cx,
BIND_INSTEAD_OF_MAP,
diff --git a/src/tools/clippy/clippy_lints/src/methods/bytes_nth.rs b/src/tools/clippy/clippy_lints/src/methods/bytes_nth.rs
index 44857d61f..2e96346be 100644
--- a/src/tools/clippy/clippy_lints/src/methods/bytes_nth.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/bytes_nth.rs
@@ -22,7 +22,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, recv: &'tcx E
cx,
BYTES_NTH,
expr.span,
- &format!("called `.bytes().nth()` on a `{}`", caller_type),
+ &format!("called `.bytes().nth()` on a `{caller_type}`"),
"try",
format!(
"{}.as_bytes().get({})",
diff --git a/src/tools/clippy/clippy_lints/src/methods/chars_cmp.rs b/src/tools/clippy/clippy_lints/src/methods/chars_cmp.rs
index b2bc1ad5c..56b7fbb9d 100644
--- a/src/tools/clippy/clippy_lints/src/methods/chars_cmp.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/chars_cmp.rs
@@ -33,12 +33,11 @@ pub(super) fn check(
cx,
lint,
info.expr.span,
- &format!("you should use the `{}` method", suggest),
+ &format!("you should use the `{suggest}` method"),
"like this",
- format!("{}{}.{}({})",
+ format!("{}{}.{suggest}({})",
if info.eq { "" } else { "!" },
snippet_with_applicability(cx, args[0].0.span, "..", &mut applicability),
- suggest,
snippet_with_applicability(cx, arg_char.span, "..", &mut applicability)),
applicability,
);
diff --git a/src/tools/clippy/clippy_lints/src/methods/chars_cmp_with_unwrap.rs b/src/tools/clippy/clippy_lints/src/methods/chars_cmp_with_unwrap.rs
index b85bfec2b..7e8087606 100644
--- a/src/tools/clippy/clippy_lints/src/methods/chars_cmp_with_unwrap.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/chars_cmp_with_unwrap.rs
@@ -26,12 +26,11 @@ pub(super) fn check<'tcx>(
cx,
lint,
info.expr.span,
- &format!("you should use the `{}` method", suggest),
+ &format!("you should use the `{suggest}` method"),
"like this",
- format!("{}{}.{}('{}')",
+ format!("{}{}.{suggest}('{}')",
if info.eq { "" } else { "!" },
snippet_with_applicability(cx, args[0].0.span, "..", &mut applicability),
- suggest,
c.escape_default()),
applicability,
);
diff --git a/src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs b/src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs
index 7ab6b84c2..7c7938dd2 100644
--- a/src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs
@@ -49,8 +49,7 @@ pub(super) fn check(
expr.span,
&format!(
"using `clone` on a double-reference; \
- this will copy the reference of type `{}` instead of cloning the inner type",
- ty
+ this will copy the reference of type `{ty}` instead of cloning the inner type"
),
|diag| {
if let Some(snip) = sugg::Sugg::hir_opt(cx, arg) {
@@ -62,11 +61,11 @@ pub(super) fn check(
}
let refs = "&".repeat(n + 1);
let derefs = "*".repeat(n);
- let explicit = format!("<{}{}>::clone({})", refs, ty, snip);
+ let explicit = format!("<{refs}{ty}>::clone({snip})");
diag.span_suggestion(
expr.span,
"try dereferencing it",
- format!("{}({}{}).clone()", refs, derefs, snip.deref()),
+ format!("{refs}({derefs}{}).clone()", snip.deref()),
Applicability::MaybeIncorrect,
);
diag.span_suggestion(
@@ -121,16 +120,16 @@ pub(super) fn check(
let (help, sugg) = if deref_count == 0 {
("try removing the `clone` call", snip.into())
} else if parent_is_suffix_expr {
- ("try dereferencing it", format!("({}{})", "*".repeat(deref_count), snip))
+ ("try dereferencing it", format!("({}{snip})", "*".repeat(deref_count)))
} else {
- ("try dereferencing it", format!("{}{}", "*".repeat(deref_count), snip))
+ ("try dereferencing it", format!("{}{snip}", "*".repeat(deref_count)))
};
span_lint_and_sugg(
cx,
CLONE_ON_COPY,
expr.span,
- &format!("using `clone` on type `{}` which implements the `Copy` trait", ty),
+ &format!("using `clone` on type `{ty}` which implements the `Copy` trait"),
help,
sugg,
app,
diff --git a/src/tools/clippy/clippy_lints/src/methods/clone_on_ref_ptr.rs b/src/tools/clippy/clippy_lints/src/methods/clone_on_ref_ptr.rs
index f82ca8912..355f53532 100644
--- a/src/tools/clippy/clippy_lints/src/methods/clone_on_ref_ptr.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/clone_on_ref_ptr.rs
@@ -41,7 +41,7 @@ pub(super) fn check(
expr.span,
"using `.clone()` on a ref-counted pointer",
"try this",
- format!("{}::<{}>::clone(&{})", caller_type, subst.type_at(0), snippet),
+ format!("{caller_type}::<{}>::clone(&{snippet})", subst.type_at(0)),
Applicability::Unspecified, // Sometimes unnecessary ::<_> after Rc/Arc/Weak
);
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/err_expect.rs b/src/tools/clippy/clippy_lints/src/methods/err_expect.rs
index 570a1b873..720d9a68c 100644
--- a/src/tools/clippy/clippy_lints/src/methods/err_expect.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/err_expect.rs
@@ -1,6 +1,6 @@
use super::ERR_EXPECT;
use clippy_utils::diagnostics::span_lint_and_sugg;
-use clippy_utils::ty::implements_trait;
+use clippy_utils::ty::has_debug_impl;
use clippy_utils::{meets_msrv, msrvs, ty::is_type_diagnostic_item};
use rustc_errors::Applicability;
use rustc_lint::LateContext;
@@ -28,7 +28,7 @@ pub(super) fn check(
// Tests if the T type in a `Result<T, E>` is not None
if let Some(data_type) = get_data_type(cx, result_type);
// Tests if the T type in a `Result<T, E>` implements debug
- if has_debug_impl(data_type, cx);
+ if has_debug_impl(cx, data_type);
then {
span_lint_and_sugg(
@@ -51,10 +51,3 @@ fn get_data_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option<Ty<'a>> {
_ => None,
}
}
-
-/// Given a type, very if the Debug trait has been impl'd
-fn has_debug_impl<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool {
- cx.tcx
- .get_diagnostic_item(sym::Debug)
- .map_or(false, |debug| implements_trait(cx, ty, debug, &[]))
-}
diff --git a/src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs b/src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs
index bd846d71d..d0cf411df 100644
--- a/src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/expect_fun_call.rs
@@ -143,9 +143,9 @@ pub(super) fn check<'tcx>(
cx,
EXPECT_FUN_CALL,
span_replace_word,
- &format!("use of `{}` followed by a function call", name),
+ &format!("use of `{name}` followed by a function call"),
"try this",
- format!("unwrap_or_else({} panic!({}))", closure_args, sugg),
+ format!("unwrap_or_else({closure_args} panic!({sugg}))"),
applicability,
);
return;
@@ -160,12 +160,9 @@ pub(super) fn check<'tcx>(
cx,
EXPECT_FUN_CALL,
span_replace_word,
- &format!("use of `{}` followed by a function call", name),
+ &format!("use of `{name}` followed by a function call"),
"try this",
- format!(
- "unwrap_or_else({} {{ panic!(\"{{}}\", {}) }})",
- closure_args, arg_root_snippet
- ),
+ format!("unwrap_or_else({closure_args} {{ panic!(\"{{}}\", {arg_root_snippet}) }})"),
applicability,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/filetype_is_file.rs b/src/tools/clippy/clippy_lints/src/methods/filetype_is_file.rs
index 7b2967feb..3fef53739 100644
--- a/src/tools/clippy/clippy_lints/src/methods/filetype_is_file.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/filetype_is_file.rs
@@ -1,17 +1,18 @@
use clippy_utils::diagnostics::span_lint_and_help;
-use clippy_utils::ty::match_type;
-use clippy_utils::{get_parent_expr, paths};
+use clippy_utils::get_parent_expr;
+use clippy_utils::ty::is_type_diagnostic_item;
use if_chain::if_chain;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_span::source_map::Span;
+use rustc_span::sym;
use super::FILETYPE_IS_FILE;
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
let ty = cx.typeck_results().expr_ty(recv);
- if !match_type(cx, ty, &paths::FILE_TYPE) {
+ if !is_type_diagnostic_item(cx, ty, sym::FileType) {
return;
}
@@ -35,7 +36,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
span = expr.span;
}
}
- let lint_msg = format!("`{}FileType::is_file()` only {} regular files", lint_unary, verb);
- let help_msg = format!("use `{}FileType::is_dir()` instead", help_unary);
+ let lint_msg = format!("`{lint_unary}FileType::is_file()` only {verb} regular files");
+ let help_msg = format!("use `{help_unary}FileType::is_dir()` instead");
span_lint_and_help(cx, FILETYPE_IS_FILE, span, &lint_msg, None, &help_msg);
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/filter_map_next.rs b/src/tools/clippy/clippy_lints/src/methods/filter_map_next.rs
index 38ec4d8e3..ddf8a1f09 100644
--- a/src/tools/clippy/clippy_lints/src/methods/filter_map_next.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/filter_map_next.rs
@@ -32,7 +32,7 @@ pub(super) fn check<'tcx>(
expr.span,
msg,
"try this",
- format!("{}.find_map({})", iter_snippet, filter_snippet),
+ format!("{iter_snippet}.find_map({filter_snippet})"),
Applicability::MachineApplicable,
);
} else {
diff --git a/src/tools/clippy/clippy_lints/src/methods/filter_next.rs b/src/tools/clippy/clippy_lints/src/methods/filter_next.rs
index bcf8d93b6..edcec0fc1 100644
--- a/src/tools/clippy/clippy_lints/src/methods/filter_next.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/filter_next.rs
@@ -32,7 +32,7 @@ pub(super) fn check<'tcx>(
expr.span,
msg,
"try this",
- format!("{}.find({})", iter_snippet, filter_snippet),
+ format!("{iter_snippet}.find({filter_snippet})"),
Applicability::MachineApplicable,
);
} else {
diff --git a/src/tools/clippy/clippy_lints/src/methods/from_iter_instead_of_collect.rs b/src/tools/clippy/clippy_lints/src/methods/from_iter_instead_of_collect.rs
index 6436e28a6..66dfce368 100644
--- a/src/tools/clippy/clippy_lints/src/methods/from_iter_instead_of_collect.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/from_iter_instead_of_collect.rs
@@ -23,7 +23,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Exp
// `expr` implements `FromIterator` trait
let iter_expr = sugg::Sugg::hir(cx, &args[0], "..").maybe_par();
let turbofish = extract_turbofish(cx, expr, ty);
- let sugg = format!("{}.collect::<{}>()", iter_expr, turbofish);
+ let sugg = format!("{iter_expr}.collect::<{turbofish}>()");
span_lint_and_sugg(
cx,
FROM_ITER_INSTEAD_OF_COLLECT,
@@ -63,7 +63,7 @@ fn extract_turbofish(cx: &LateContext<'_>, expr: &hir::Expr<'_>, ty: Ty<'_>) ->
if e == type_specifier { None } else { Some((*e).to_string()) }
}).collect::<Vec<_>>();
// join and add the type specifier at the end (i.e.: `collections::BTreeSet<u32>`)
- format!("{}{}", without_ts.join("::"), type_specifier)
+ format!("{}{type_specifier}", without_ts.join("::"))
} else {
// type is not explicitly specified so wildcards are needed
// i.e.: 2 wildcards in `std::collections::BTreeMap<&i32, &char>`
@@ -72,7 +72,7 @@ fn extract_turbofish(cx: &LateContext<'_>, expr: &hir::Expr<'_>, ty: Ty<'_>) ->
let end = ty_str.find('>').unwrap_or(ty_str.len());
let nb_wildcard = ty_str[start..end].split(',').count();
let wildcards = format!("_{}", ", _".repeat(nb_wildcard - 1));
- format!("{}<{}>", elements.join("::"), wildcards)
+ format!("{}<{wildcards}>", elements.join("::"))
}
}
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/get_first.rs b/src/tools/clippy/clippy_lints/src/methods/get_first.rs
index 4de77de74..cb17af608 100644
--- a/src/tools/clippy/clippy_lints/src/methods/get_first.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/get_first.rs
@@ -29,9 +29,9 @@ pub(super) fn check<'tcx>(
cx,
GET_FIRST,
expr.span,
- &format!("accessing first element with `{0}.get(0)`", slice_name),
+ &format!("accessing first element with `{slice_name}.get(0)`"),
"try",
- format!("{}.first()", slice_name),
+ format!("{slice_name}.first()"),
app,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/get_last_with_len.rs b/src/tools/clippy/clippy_lints/src/methods/get_last_with_len.rs
index 02aada872..3bdc154df 100644
--- a/src/tools/clippy/clippy_lints/src/methods/get_last_with_len.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/get_last_with_len.rs
@@ -1,7 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
-use clippy_utils::SpanlessEq;
-use rustc_ast::LitKind;
+use clippy_utils::{is_integer_literal, SpanlessEq};
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Expr, ExprKind};
use rustc_lint::LateContext;
@@ -26,8 +25,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg:
&& lhs_path.ident.name == sym::len
// RHS of subtraction is 1
- && let ExprKind::Lit(rhs_lit) = &rhs.kind
- && let LitKind::Int(1, ..) = rhs_lit.node
+ && is_integer_literal(rhs, 1)
// check that recv == lhs_recv `recv.get(lhs_recv.len() - 1)`
&& SpanlessEq::new(cx).eq_expr(recv, lhs_recv)
diff --git a/src/tools/clippy/clippy_lints/src/methods/get_unwrap.rs b/src/tools/clippy/clippy_lints/src/methods/get_unwrap.rs
index 18e08d6ee..ffc3a4d78 100644
--- a/src/tools/clippy/clippy_lints/src/methods/get_unwrap.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/get_unwrap.rs
@@ -71,16 +71,11 @@ pub(super) fn check<'tcx>(
cx,
GET_UNWRAP,
span,
- &format!(
- "called `.get{0}().unwrap()` on a {1}. Using `[]` is more clear and more concise",
- mut_str, caller_type
- ),
+ &format!("called `.get{mut_str}().unwrap()` on a {caller_type}. Using `[]` is more clear and more concise"),
"try this",
format!(
- "{}{}[{}]",
- borrow_str,
- snippet_with_applicability(cx, recv.span, "..", &mut applicability),
- get_args_str
+ "{borrow_str}{}[{get_args_str}]",
+ snippet_with_applicability(cx, recv.span, "..", &mut applicability)
),
applicability,
);
diff --git a/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs b/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs
index 9651a52be..429cdc191 100644
--- a/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs
@@ -26,12 +26,12 @@ pub fn check(cx: &LateContext<'_>, method_name: &str, expr: &hir::Expr<'_>, recv
cx,
IMPLICIT_CLONE,
expr.span,
- &format!("implicitly cloning a `{}` by calling `{}` on its dereferenced type", ty_name, method_name),
+ &format!("implicitly cloning a `{ty_name}` by calling `{method_name}` on its dereferenced type"),
"consider using",
if ref_count > 1 {
- format!("({}{}).clone()", "*".repeat(ref_count - 1), recv_snip)
+ format!("({}{recv_snip}).clone()", "*".repeat(ref_count - 1))
} else {
- format!("{}.clone()", recv_snip)
+ format!("{recv_snip}.clone()")
},
app,
);
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 e1c9b5248..ede3b8bb7 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
@@ -34,18 +34,17 @@ pub fn check<'tcx>(
cx,
INEFFICIENT_TO_STRING,
expr.span,
- &format!("calling `to_string` on `{}`", arg_ty),
+ &format!("calling `to_string` on `{arg_ty}`"),
|diag| {
diag.help(&format!(
- "`{}` implements `ToString` through a slower blanket impl, but `{}` has a fast specialization of `ToString`",
- self_ty, deref_self_ty
+ "`{self_ty}` implements `ToString` through a slower blanket impl, but `{deref_self_ty}` has a fast specialization of `ToString`"
));
let mut applicability = Applicability::MachineApplicable;
let arg_snippet = snippet_with_applicability(cx, receiver.span, "..", &mut applicability);
diag.span_suggestion(
expr.span,
"try dereferencing the receiver",
- format!("({}{}).to_string()", "*".repeat(deref_count), arg_snippet),
+ format!("({}{arg_snippet}).to_string()", "*".repeat(deref_count)),
applicability,
);
},
@@ -66,7 +65,7 @@ fn specializes_tostring(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
}
if let ty::Adt(adt, substs) = ty.kind() {
- match_def_path(cx, adt.did(), &paths::COW) && substs.type_at(1).is_str()
+ cx.tcx.is_diagnostic_item(sym::Cow, adt.did()) && substs.type_at(1).is_str()
} else {
false
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/into_iter_on_ref.rs b/src/tools/clippy/clippy_lints/src/methods/into_iter_on_ref.rs
index 11e76841e..8adf9e370 100644
--- a/src/tools/clippy/clippy_lints/src/methods/into_iter_on_ref.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/into_iter_on_ref.rs
@@ -30,8 +30,7 @@ pub(super) fn check(
INTO_ITER_ON_REF,
method_span,
&format!(
- "this `.into_iter()` call is equivalent to `.{}()` and will not consume the `{}`",
- method_name, kind,
+ "this `.into_iter()` call is equivalent to `.{method_name}()` and will not consume the `{kind}`",
),
"call directly",
method_name.to_string(),
@@ -43,9 +42,8 @@ pub(super) fn check(
fn ty_has_iter_method(cx: &LateContext<'_>, self_ref_ty: Ty<'_>) -> Option<(Symbol, &'static str)> {
has_iter_method(cx, self_ref_ty).map(|ty_name| {
- let mutbl = match self_ref_ty.kind() {
- ty::Ref(_, _, mutbl) => mutbl,
- _ => unreachable!(),
+ let ty::Ref(_, _, mutbl) = self_ref_ty.kind() else {
+ unreachable!()
};
let method_name = match mutbl {
hir::Mutability::Not => "iter",
diff --git a/src/tools/clippy/clippy_lints/src/methods/is_digit_ascii_radix.rs b/src/tools/clippy/clippy_lints/src/methods/is_digit_ascii_radix.rs
index aa176dcc8..304024e80 100644
--- a/src/tools/clippy/clippy_lints/src/methods/is_digit_ascii_radix.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/is_digit_ascii_radix.rs
@@ -37,12 +37,11 @@ pub(super) fn check<'tcx>(
cx,
IS_DIGIT_ASCII_RADIX,
expr.span,
- &format!("use of `char::is_digit` with literal radix of {}", num),
+ &format!("use of `char::is_digit` with literal radix of {num}"),
"try",
format!(
- "{}.{}()",
- snippet_with_applicability(cx, self_arg.span, "..", &mut applicability),
- replacement
+ "{}.{replacement}()",
+ snippet_with_applicability(cx, self_arg.span, "..", &mut applicability)
),
applicability,
);
diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_cloned_collect.rs b/src/tools/clippy/clippy_lints/src/methods/iter_cloned_collect.rs
index 30d56113c..bde6f92b0 100644
--- a/src/tools/clippy/clippy_lints/src/methods/iter_cloned_collect.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/iter_cloned_collect.rs
@@ -20,8 +20,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, method_name: &str, expr: &hir:
cx,
ITER_CLONED_COLLECT,
to_replace,
- &format!("called `iter().{}().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and \
- more readable", method_name),
+ &format!("called `iter().{method_name}().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and \
+ more readable"),
"try",
".to_vec()".to_string(),
Applicability::MachineApplicable,
diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_count.rs b/src/tools/clippy/clippy_lints/src/methods/iter_count.rs
index 052be3d8e..bcddc7c78 100644
--- a/src/tools/clippy/clippy_lints/src/methods/iter_count.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/iter_count.rs
@@ -37,7 +37,7 @@ pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, recv: &'tcx E
cx,
ITER_COUNT,
expr.span,
- &format!("called `.{}().count()` on a `{}`", iter_method, caller_type),
+ &format!("called `.{iter_method}().count()` on a `{caller_type}`"),
"try",
format!(
"{}.len()",
diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_kv_map.rs b/src/tools/clippy/clippy_lints/src/methods/iter_kv_map.rs
new file mode 100644
index 000000000..2244ebfb1
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/methods/iter_kv_map.rs
@@ -0,0 +1,87 @@
+#![allow(unused_imports)]
+
+use super::ITER_KV_MAP;
+use clippy_utils::diagnostics::{multispan_sugg, span_lint_and_sugg, span_lint_and_then};
+use clippy_utils::source::{snippet, snippet_with_applicability};
+use clippy_utils::sugg;
+use clippy_utils::ty::is_type_diagnostic_item;
+use clippy_utils::visitors::is_local_used;
+use rustc_hir::{BindingAnnotation, Body, BorrowKind, Expr, ExprKind, Mutability, Pat, PatKind};
+use rustc_lint::{LateContext, LintContext};
+use rustc_middle::ty;
+use rustc_span::sym;
+use rustc_span::Span;
+
+/// lint use of:
+/// - `hashmap.iter().map(|(_, v)| v)`
+/// - `hashmap.into_iter().map(|(_, v)| v)`
+/// on `HashMaps` and `BTreeMaps` in std
+
+pub(super) fn check<'tcx>(
+ cx: &LateContext<'tcx>,
+ map_type: &'tcx str, // iter / into_iter
+ expr: &'tcx Expr<'tcx>, // .iter().map(|(_, v_| v))
+ recv: &'tcx Expr<'tcx>, // hashmap
+ m_arg: &'tcx Expr<'tcx>, // |(_, v)| v
+) {
+ if_chain! {
+ if !expr.span.from_expansion();
+ if let ExprKind::Closure(c) = m_arg.kind;
+ if let Body {params: [p], value: body_expr, generator_kind: _ } = cx.tcx.hir().body(c.body);
+ if let PatKind::Tuple([key_pat, val_pat], _) = p.pat.kind;
+
+ let (replacement_kind, binded_ident) = match (&key_pat.kind, &val_pat.kind) {
+ (key, PatKind::Binding(_, _, value, _)) if pat_is_wild(cx, key, m_arg) => ("value", value),
+ (PatKind::Binding(_, _, key, _), value) if pat_is_wild(cx, value, m_arg) => ("key", key),
+ _ => return,
+ };
+
+ let ty = cx.typeck_results().expr_ty(recv);
+ if is_type_diagnostic_item(cx, ty, sym::HashMap) || is_type_diagnostic_item(cx, ty, sym::BTreeMap);
+
+ then {
+ let mut applicability = rustc_errors::Applicability::MachineApplicable;
+ let recv_snippet = snippet_with_applicability(cx, recv.span, "map", &mut applicability);
+ let into_prefix = if map_type == "into_iter" {"into_"} else {""};
+
+ if_chain! {
+ if let ExprKind::Path(rustc_hir::QPath::Resolved(_, path)) = body_expr.kind;
+ if let [local_ident] = path.segments;
+ if local_ident.ident.as_str() == binded_ident.as_str();
+
+ then {
+ span_lint_and_sugg(
+ cx,
+ ITER_KV_MAP,
+ expr.span,
+ &format!("iterating on a map's {replacement_kind}s"),
+ "try",
+ format!("{recv_snippet}.{into_prefix}{replacement_kind}s()"),
+ applicability,
+ );
+ } else {
+ span_lint_and_sugg(
+ cx,
+ ITER_KV_MAP,
+ expr.span,
+ &format!("iterating on a map's {replacement_kind}s"),
+ "try",
+ format!("{recv_snippet}.{into_prefix}{replacement_kind}s().map(|{binded_ident}| {})",
+ snippet_with_applicability(cx, body_expr.span, "/* body */", &mut applicability)),
+ applicability,
+ );
+ }
+ }
+ }
+ }
+}
+
+/// Returns `true` if the pattern is a `PatWild`, or is an ident prefixed with `_`
+/// that is not locally used.
+fn pat_is_wild<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx PatKind<'_>, body: &'tcx Expr<'_>) -> bool {
+ match *pat {
+ PatKind::Wild => true,
+ PatKind::Binding(_, id, ident, None) if ident.as_str().starts_with('_') => !is_local_used(cx, body, id),
+ _ => false,
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_next_slice.rs b/src/tools/clippy/clippy_lints/src/methods/iter_next_slice.rs
index b8d1dabe0..83c1bf203 100644
--- a/src/tools/clippy/clippy_lints/src/methods/iter_next_slice.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/iter_next_slice.rs
@@ -37,7 +37,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, cal
let suggest = if start_idx == 0 {
format!("{}.first()", snippet_with_applicability(cx, caller_var.span, "..", &mut applicability))
} else {
- format!("{}.get({})", snippet_with_applicability(cx, caller_var.span, "..", &mut applicability), start_idx)
+ format!("{}.get({start_idx})", snippet_with_applicability(cx, caller_var.span, "..", &mut applicability))
};
span_lint_and_sugg(
cx,
diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_nth.rs b/src/tools/clippy/clippy_lints/src/methods/iter_nth.rs
index 80ca4c942..ceee12784 100644
--- a/src/tools/clippy/clippy_lints/src/methods/iter_nth.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/iter_nth.rs
@@ -32,8 +32,8 @@ pub(super) fn check<'tcx>(
cx,
ITER_NTH,
expr.span,
- &format!("called `.iter{0}().nth()` on a {1}", mut_str, caller_type),
+ &format!("called `.iter{mut_str}().nth()` on a {caller_type}"),
None,
- &format!("calling `.get{}()` is both faster and more readable", mut_str),
+ &format!("calling `.get{mut_str}()` is both faster and more readable"),
);
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs b/src/tools/clippy/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs
index cea7b0d82..4f73b3ec4 100644
--- a/src/tools/clippy/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs
@@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet;
-use clippy_utils::{get_expr_use_or_unification_node, is_lang_ctor, is_no_std_crate};
+use clippy_utils::{get_expr_use_or_unification_node, is_no_std_crate, is_res_lang_ctor, path_res};
use rustc_errors::Applicability;
use rustc_hir::LangItem::{OptionNone, OptionSome};
@@ -26,26 +26,11 @@ impl IterType {
}
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, method_name: &str, recv: &Expr<'_>) {
- let item = match &recv.kind {
- ExprKind::Array(v) if v.len() <= 1 => v.first(),
- ExprKind::Path(p) => {
- if is_lang_ctor(cx, p, OptionNone) {
- None
- } else {
- return;
- }
- },
- ExprKind::Call(f, some_args) if some_args.len() == 1 => {
- if let ExprKind::Path(p) = &f.kind {
- if is_lang_ctor(cx, p, OptionSome) {
- Some(&some_args[0])
- } else {
- return;
- }
- } else {
- return;
- }
- },
+ let item = match recv.kind {
+ ExprKind::Array([]) => None,
+ ExprKind::Array([e]) => Some(e),
+ ExprKind::Path(ref p) if is_res_lang_ctor(cx, cx.qpath_res(p, recv.hir_id), OptionNone) => None,
+ ExprKind::Call(f, [arg]) if is_res_lang_ctor(cx, path_res(cx, f), OptionSome) => Some(arg),
_ => return,
};
let iter_type = match method_name {
diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_with_drain.rs b/src/tools/clippy/clippy_lints/src/methods/iter_with_drain.rs
index a669cbbbc..3da230e12 100644
--- a/src/tools/clippy/clippy_lints/src/methods/iter_with_drain.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/iter_with_drain.rs
@@ -22,7 +22,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span
cx,
ITER_WITH_DRAIN,
span.with_hi(expr.span.hi()),
- &format!("`drain(..)` used on a `{}`", ty_name),
+ &format!("`drain(..)` used on a `{ty_name}`"),
"try this",
"into_iter()".to_string(),
Applicability::MaybeIncorrect,
diff --git a/src/tools/clippy/clippy_lints/src/methods/manual_ok_or.rs b/src/tools/clippy/clippy_lints/src/methods/manual_ok_or.rs
index ffd2f4a38..5b758f1e6 100644
--- a/src/tools/clippy/clippy_lints/src/methods/manual_ok_or.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/manual_ok_or.rs
@@ -1,11 +1,11 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::{indent_of, reindent_multiline, snippet_opt};
use clippy_utils::ty::is_type_diagnostic_item;
-use clippy_utils::{is_lang_ctor, path_to_local_id};
+use clippy_utils::{is_res_lang_ctor, path_res, path_to_local_id};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::LangItem::{ResultErr, ResultOk};
-use rustc_hir::{Closure, Expr, ExprKind, PatKind};
+use rustc_hir::{Expr, ExprKind, PatKind};
use rustc_lint::LateContext;
use rustc_span::symbol::sym;
@@ -22,8 +22,8 @@ pub(super) fn check<'tcx>(
if let Some(method_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
if let Some(impl_id) = cx.tcx.impl_of_method(method_id);
if is_type_diagnostic_item(cx, cx.tcx.type_of(impl_id), sym::Option);
- if let ExprKind::Call(Expr { kind: ExprKind::Path(err_path), .. }, [err_arg]) = or_expr.kind;
- if is_lang_ctor(cx, err_path, ResultErr);
+ if let ExprKind::Call(err_path, [err_arg]) = or_expr.kind;
+ if is_res_lang_ctor(cx, path_res(cx, err_path), ResultErr);
if is_ok_wrapping(cx, map_expr);
if let Some(recv_snippet) = snippet_opt(cx, recv.span);
if let Some(err_arg_snippet) = snippet_opt(cx, err_arg.span);
@@ -37,9 +37,7 @@ pub(super) fn check<'tcx>(
"this pattern reimplements `Option::ok_or`",
"replace with",
format!(
- "{}.ok_or({})",
- recv_snippet,
- reindented_err_arg_snippet
+ "{recv_snippet}.ok_or({reindented_err_arg_snippet})"
),
Applicability::MachineApplicable,
);
@@ -48,17 +46,19 @@ pub(super) fn check<'tcx>(
}
fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool {
- if let ExprKind::Path(ref qpath) = map_expr.kind {
- if is_lang_ctor(cx, qpath, ResultOk) {
- return true;
- }
- }
- if_chain! {
- if let ExprKind::Closure(&Closure { body, .. }) = map_expr.kind;
- let body = cx.tcx.hir().body(body);
- if let PatKind::Binding(_, param_id, ..) = body.params[0].pat.kind;
- if let ExprKind::Call(Expr { kind: ExprKind::Path(ok_path), .. }, &[ref ok_arg]) = body.value.kind;
- if is_lang_ctor(cx, ok_path, ResultOk);
- then { path_to_local_id(ok_arg, param_id) } else { false }
+ match map_expr.kind {
+ ExprKind::Path(ref qpath) if is_res_lang_ctor(cx, cx.qpath_res(qpath, map_expr.hir_id), ResultOk) => true,
+ ExprKind::Closure(closure) => {
+ let body = cx.tcx.hir().body(closure.body);
+ if let PatKind::Binding(_, param_id, ..) = body.params[0].pat.kind
+ && let ExprKind::Call(callee, [ok_arg]) = body.value.kind
+ && is_res_lang_ctor(cx, path_res(cx, callee), ResultOk)
+ {
+ path_to_local_id(ok_arg, param_id)
+ } else {
+ false
+ }
+ },
+ _ => false,
}
}
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 0fe510bea..b80541b86 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
@@ -21,11 +21,7 @@ pub fn check(
return;
}
- let mm = if let Some(mm) = is_min_or_max(cx, unwrap_arg) {
- mm
- } else {
- return;
- };
+ let Some(mm) = is_min_or_max(cx, unwrap_arg) else { return };
if ty.is_signed() {
use self::{
@@ -33,9 +29,7 @@ pub fn check(
Sign::{Neg, Pos},
};
- let sign = if let Some(sign) = lit_sign(arith_rhs) {
- sign
- } else {
+ let Some(sign) = lit_sign(arith_rhs) else {
return;
};
@@ -57,11 +51,10 @@ pub fn check(
super::MANUAL_SATURATING_ARITHMETIC,
expr.span,
"manual saturating arithmetic",
- &format!("try using `saturating_{}`", arith),
+ &format!("try using `saturating_{arith}`"),
format!(
- "{}.saturating_{}({})",
+ "{}.saturating_{arith}({})",
snippet_with_applicability(cx, arith_lhs.span, "..", &mut applicability),
- arith,
snippet_with_applicability(cx, arith_rhs.span, "..", &mut applicability),
),
applicability,
diff --git a/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs b/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs
index 46d2fc493..8b6b8f1bf 100644
--- a/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs
@@ -1,8 +1,8 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::is_path_diagnostic_item;
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
use clippy_utils::sugg::Sugg;
-use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item, match_type};
-use clippy_utils::{is_expr_path_def_path, paths};
+use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
use if_chain::if_chain;
use rustc_ast::LitKind;
use rustc_errors::Applicability;
@@ -38,7 +38,7 @@ fn parse_repeat_arg(cx: &LateContext<'_>, e: &Expr<'_>) -> Option<RepeatKind> {
let ty = cx.typeck_results().expr_ty(e);
if is_type_diagnostic_item(cx, ty, sym::String)
|| (is_type_lang_item(cx, ty, LangItem::OwnedBox) && get_ty_param(ty).map_or(false, Ty::is_str))
- || (match_type(cx, ty, &paths::COW) && get_ty_param(ty).map_or(false, Ty::is_str))
+ || (is_type_diagnostic_item(cx, ty, sym::Cow) && get_ty_param(ty).map_or(false, Ty::is_str))
{
Some(RepeatKind::String)
} else {
@@ -57,7 +57,7 @@ pub(super) fn check(
) {
if_chain! {
if let ExprKind::Call(repeat_fn, [repeat_arg]) = take_self_arg.kind;
- if is_expr_path_def_path(cx, repeat_fn, &paths::ITER_REPEAT);
+ if is_path_diagnostic_item(cx, repeat_fn, sym::iter_repeat);
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(collect_expr), sym::String);
if let Some(collect_id) = cx.typeck_results().type_dependent_def_id(collect_expr.hir_id);
if let Some(take_id) = cx.typeck_results().type_dependent_def_id(take_expr.hir_id);
@@ -91,7 +91,7 @@ pub(super) fn check(
collect_expr.span,
"manual implementation of `str::repeat` using iterators",
"try this",
- format!("{}.repeat({})", val_str, count_snip),
+ format!("{val_str}.repeat({count_snip})"),
app
)
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/map_clone.rs b/src/tools/clippy/clippy_lints/src/methods/map_clone.rs
index 8261ef5e1..7ce14ec08 100644
--- a/src/tools/clippy/clippy_lints/src/methods/map_clone.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/map_clone.rs
@@ -111,11 +111,10 @@ fn lint_explicit_closure(cx: &LateContext<'_>, replace: Span, root: Span, is_cop
MAP_CLONE,
replace,
message,
- &format!("consider calling the dedicated `{}` method", sugg_method),
+ &format!("consider calling the dedicated `{sugg_method}` method"),
format!(
- "{}.{}()",
+ "{}.{sugg_method}()",
snippet_with_applicability(cx, root, "..", &mut applicability),
- sugg_method,
),
applicability,
);
diff --git a/src/tools/clippy/clippy_lints/src/methods/map_flatten.rs b/src/tools/clippy/clippy_lints/src/methods/map_flatten.rs
index 13853dec9..361ffcb5e 100644
--- a/src/tools/clippy/clippy_lints/src/methods/map_flatten.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/map_flatten.rs
@@ -20,12 +20,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, map_
cx,
MAP_FLATTEN,
expr.span.with_lo(map_span.lo()),
- &format!("called `map(..).flatten()` on `{}`", caller_ty_name),
- &format!(
- "try replacing `map` with `{}` and remove the `.flatten()`",
- method_to_use
- ),
- format!("{}({})", method_to_use, closure_snippet),
+ &format!("called `map(..).flatten()` on `{caller_ty_name}`"),
+ &format!("try replacing `map` with `{method_to_use}` and remove the `.flatten()`"),
+ format!("{method_to_use}({closure_snippet})"),
applicability,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/map_identity.rs b/src/tools/clippy/clippy_lints/src/methods/map_identity.rs
index 862a9578e..0f25ef82e 100644
--- a/src/tools/clippy/clippy_lints/src/methods/map_identity.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/map_identity.rs
@@ -30,7 +30,7 @@ pub(super) fn check(
MAP_IDENTITY,
sugg_span,
"unnecessary map of the identity function",
- &format!("remove the call to `{}`", name),
+ &format!("remove the call to `{name}`"),
String::new(),
Applicability::MachineApplicable,
)
diff --git a/src/tools/clippy/clippy_lints/src/methods/map_unwrap_or.rs b/src/tools/clippy/clippy_lints/src/methods/map_unwrap_or.rs
index 4a8e7ce4d..74fdead21 100644
--- a/src/tools/clippy/clippy_lints/src/methods/map_unwrap_or.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/map_unwrap_or.rs
@@ -65,7 +65,7 @@ pub(super) fn check<'tcx>(
expr.span,
msg,
"try this",
- format!("{}.map_or_else({}, {})", var_snippet, unwrap_snippet, map_snippet),
+ format!("{var_snippet}.map_or_else({unwrap_snippet}, {map_snippet})"),
Applicability::MachineApplicable,
);
return true;
diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs
index 41942b20e..8a76ba0b0 100644
--- a/src/tools/clippy/clippy_lints/src/methods/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs
@@ -35,6 +35,7 @@ mod into_iter_on_ref;
mod is_digit_ascii_radix;
mod iter_cloned_collect;
mod iter_count;
+mod iter_kv_map;
mod iter_next_slice;
mod iter_nth;
mod iter_nth_zero;
@@ -101,20 +102,18 @@ use bind_instead_of_map::BindInsteadOfMap;
use clippy_utils::consts::{constant, Constant};
use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
use clippy_utils::ty::{contains_adt_constructor, implements_trait, is_copy, is_type_diagnostic_item};
-use clippy_utils::{
- contains_return, get_trait_def_id, is_trait_method, iter_input_pats, meets_msrv, msrvs, paths, return_ty,
-};
+use clippy_utils::{contains_return, is_trait_method, iter_input_pats, meets_msrv, msrvs, return_ty};
use if_chain::if_chain;
use rustc_hir as hir;
use rustc_hir::def::Res;
use rustc_hir::{Expr, ExprKind, PrimTy, QPath, TraitItem, TraitItemKind};
+use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{self, TraitRef, Ty};
use rustc_semver::RustcVersion;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::{sym, Span};
-use rustc_typeck::hir_ty_to_ty;
declare_clippy_lint! {
/// ### What it does
@@ -3036,6 +3035,37 @@ declare_clippy_lint! {
"use of `File::read_to_end` or `File::read_to_string`"
}
+declare_clippy_lint! {
+ /// ### What it does
+ ///
+ /// Checks for iterating a map (`HashMap` or `BTreeMap`) and
+ /// ignoring either the keys or values.
+ ///
+ /// ### Why is this bad?
+ ///
+ /// Readability. There are `keys` and `values` methods that
+ /// can be used to express that we only need the keys or the values.
+ ///
+ /// ### Example
+ ///
+ /// ```
+ /// # use std::collections::HashMap;
+ /// let map: HashMap<u32, u32> = HashMap::new();
+ /// let values = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
+ /// ```
+ ///
+ /// Use instead:
+ /// ```
+ /// # use std::collections::HashMap;
+ /// let map: HashMap<u32, u32> = HashMap::new();
+ /// let values = map.values().collect::<Vec<_>>();
+ /// ```
+ #[clippy::version = "1.65.0"]
+ pub ITER_KV_MAP,
+ complexity,
+ "iterating on map using `iter` when `keys` or `values` would do"
+}
+
pub struct Methods {
avoid_breaking_exported_api: bool,
msrv: Option<RustcVersion>,
@@ -3159,6 +3189,7 @@ impl_lint_pass!(Methods => [
UNNECESSARY_SORT_BY,
VEC_RESIZE_TO_ZERO,
VERBOSE_FILE_READS,
+ ITER_KV_MAP,
]);
/// Extracts a method call name, args, and `Span` of the method name.
@@ -3217,70 +3248,64 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
return;
}
let name = impl_item.ident.name.as_str();
- let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
+ let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
let item = cx.tcx.hir().expect_item(parent);
- let self_ty = cx.tcx.type_of(item.def_id);
+ let self_ty = cx.tcx.type_of(item.owner_id);
let implements_trait = matches!(item.kind, hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }));
- if_chain! {
- if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind;
- if let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir().body(id)).next();
-
- let method_sig = cx.tcx.fn_sig(impl_item.def_id);
+ if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind {
+ let method_sig = cx.tcx.fn_sig(impl_item.owner_id);
let method_sig = cx.tcx.erase_late_bound_regions(method_sig);
-
- let first_arg_ty = method_sig.inputs().iter().next();
-
- // check conventions w.r.t. conversion method names and predicates
- if let Some(first_arg_ty) = first_arg_ty;
-
- then {
- // if this impl block implements a trait, lint in trait definition instead
- if !implements_trait && cx.access_levels.is_exported(impl_item.def_id) {
- // check missing trait implementations
- for method_config in &TRAIT_METHODS {
- if name == method_config.method_name &&
- sig.decl.inputs.len() == method_config.param_count &&
- method_config.output_type.matches(&sig.decl.output) &&
- method_config.self_kind.matches(cx, self_ty, *first_arg_ty) &&
- fn_header_equals(method_config.fn_header, sig.header) &&
- method_config.lifetime_param_cond(impl_item)
- {
- span_lint_and_help(
- cx,
- SHOULD_IMPLEMENT_TRAIT,
- impl_item.span,
- &format!(
- "method `{}` can be confused for the standard trait method `{}::{}`",
- method_config.method_name,
- method_config.trait_name,
- method_config.method_name
- ),
- None,
- &format!(
- "consider implementing the trait `{}` or choosing a less ambiguous method name",
- method_config.trait_name
- )
- );
- }
+ let first_arg_ty_opt = method_sig.inputs().iter().next().copied();
+ // if this impl block implements a trait, lint in trait definition instead
+ if !implements_trait && cx.effective_visibilities.is_exported(impl_item.owner_id.def_id) {
+ // check missing trait implementations
+ for method_config in &TRAIT_METHODS {
+ if name == method_config.method_name
+ && sig.decl.inputs.len() == method_config.param_count
+ && method_config.output_type.matches(&sig.decl.output)
+ // in case there is no first arg, since we already have checked the number of arguments
+ // it's should be always true
+ && first_arg_ty_opt.map_or(true, |first_arg_ty| method_config
+ .self_kind.matches(cx, self_ty, first_arg_ty)
+ )
+ && fn_header_equals(method_config.fn_header, sig.header)
+ && method_config.lifetime_param_cond(impl_item)
+ {
+ span_lint_and_help(
+ cx,
+ SHOULD_IMPLEMENT_TRAIT,
+ impl_item.span,
+ &format!(
+ "method `{}` can be confused for the standard trait method `{}::{}`",
+ method_config.method_name, method_config.trait_name, method_config.method_name
+ ),
+ None,
+ &format!(
+ "consider implementing the trait `{}` or choosing a less ambiguous method name",
+ method_config.trait_name
+ ),
+ );
}
}
+ }
- if sig.decl.implicit_self.has_implicit_self()
+ if sig.decl.implicit_self.has_implicit_self()
&& !(self.avoid_breaking_exported_api
- && cx.access_levels.is_exported(impl_item.def_id))
+ && cx.effective_visibilities.is_exported(impl_item.owner_id.def_id))
+ && let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir().body(id)).next()
+ && let Some(first_arg_ty) = first_arg_ty_opt
{
wrong_self_convention::check(
cx,
name,
self_ty,
- *first_arg_ty,
+ first_arg_ty,
first_arg.pat.span,
implements_trait,
false
);
}
- }
}
// if this impl block implements a trait, lint in trait definition instead
@@ -3345,7 +3370,9 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
then {
let first_arg_span = first_arg_ty.span;
let first_arg_ty = hir_ty_to_ty(cx.tcx, first_arg_ty);
- let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty().skip_binder();
+ let self_ty = TraitRef::identity(cx.tcx, item.owner_id.to_def_id())
+ .self_ty()
+ .skip_binder();
wrong_self_convention::check(
cx,
item.ident.name.as_str(),
@@ -3353,7 +3380,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
first_arg_ty,
first_arg_span,
false,
- true
+ true,
);
}
}
@@ -3362,7 +3389,9 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if item.ident.name == sym::new;
if let TraitItemKind::Fn(_, _) = item.kind;
let ret_ty = return_ty(cx, item.hir_id());
- let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty().skip_binder();
+ let self_ty = TraitRef::identity(cx.tcx, item.owner_id.to_def_id())
+ .self_ty()
+ .skip_binder();
if !ret_ty.contains(self_ty);
then {
@@ -3498,6 +3527,9 @@ impl Methods {
(name @ ("map" | "map_err"), [m_arg]) => {
if name == "map" {
map_clone::check(cx, expr, recv, m_arg, self.msrv);
+ if let Some((map_name @ ("iter" | "into_iter"), recv2, _, _)) = method_call(recv) {
+ iter_kv_map::check(cx, map_name, expr, recv2, m_arg);
+ }
} else {
map_err_ignore::check(cx, expr, m_arg);
}
@@ -3763,7 +3795,6 @@ const TRAIT_METHODS: [ShouldImplTraitCase; 30] = [
ShouldImplTraitCase::new("std::borrow::BorrowMut", "borrow_mut", 1, FN_HEADER, SelfKind::RefMut, OutType::Ref, true),
ShouldImplTraitCase::new("std::clone::Clone", "clone", 1, FN_HEADER, SelfKind::Ref, OutType::Any, true),
ShouldImplTraitCase::new("std::cmp::Ord", "cmp", 2, FN_HEADER, SelfKind::Ref, OutType::Any, true),
- // FIXME: default doesn't work
ShouldImplTraitCase::new("std::default::Default", "default", 0, FN_HEADER, SelfKind::No, OutType::Any, true),
ShouldImplTraitCase::new("std::ops::Deref", "deref", 1, FN_HEADER, SelfKind::Ref, OutType::Ref, true),
ShouldImplTraitCase::new("std::ops::DerefMut", "deref_mut", 1, FN_HEADER, SelfKind::RefMut, OutType::Ref, true),
@@ -3791,7 +3822,7 @@ enum SelfKind {
Value,
Ref,
RefMut,
- No,
+ No, // When we want the first argument type to be different than `Self`
}
impl SelfKind {
@@ -3817,14 +3848,13 @@ impl SelfKind {
return m == mutability && t == parent_ty;
}
- let trait_path = match mutability {
- hir::Mutability::Not => &paths::ASREF_TRAIT,
- hir::Mutability::Mut => &paths::ASMUT_TRAIT,
+ let trait_sym = match mutability {
+ hir::Mutability::Not => sym::AsRef,
+ hir::Mutability::Mut => sym::AsMut,
};
- let trait_def_id = match get_trait_def_id(cx, trait_path) {
- Some(did) => did,
- None => return false,
+ let Some(trait_def_id) = cx.tcx.get_diagnostic_item(trait_sym) else {
+ return false
};
implements_trait(cx, ty, trait_def_id, &[parent_ty.into()])
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs b/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs
index d64a9f320..646fc4a7b 100644
--- a/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/ok_expect.rs
@@ -1,5 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_help;
-use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
+use clippy_utils::ty::{has_debug_impl, is_type_diagnostic_item};
use if_chain::if_chain;
use rustc_hir as hir;
use rustc_lint::LateContext;
@@ -15,7 +15,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
let result_type = cx.typeck_results().expr_ty(recv);
if let Some(error_type) = get_error_type(cx, result_type);
- if has_debug_impl(error_type, cx);
+ if has_debug_impl(cx, error_type);
then {
span_lint_and_help(
@@ -37,10 +37,3 @@ fn get_error_type<'a>(cx: &LateContext<'_>, ty: Ty<'a>) -> Option<Ty<'a>> {
_ => None,
}
}
-
-/// This checks whether a given type is known to implement Debug.
-fn has_debug_impl<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'tcx>) -> bool {
- cx.tcx
- .get_diagnostic_item(sym::Debug)
- .map_or(false, |debug| implements_trait(cx, ty, debug, &[]))
-}
diff --git a/src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs b/src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs
index c409268de..742483e6b 100644
--- a/src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs
@@ -32,8 +32,7 @@ pub(super) fn check<'tcx>(
return;
}
- let deref_aliases: [&[&str]; 9] = [
- &paths::DEREF_TRAIT_METHOD,
+ let deref_aliases: [&[&str]; 8] = [
&paths::DEREF_MUT_TRAIT_METHOD,
&paths::CSTRING_AS_C_STR,
&paths::OS_STRING_AS_OS_STR,
@@ -45,12 +44,14 @@ pub(super) fn check<'tcx>(
];
let is_deref = match map_arg.kind {
- hir::ExprKind::Path(ref expr_qpath) => cx
- .qpath_res(expr_qpath, map_arg.hir_id)
- .opt_def_id()
- .map_or(false, |fun_def_id| {
- deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path))
- }),
+ hir::ExprKind::Path(ref expr_qpath) => {
+ cx.qpath_res(expr_qpath, map_arg.hir_id)
+ .opt_def_id()
+ .map_or(false, |fun_def_id| {
+ cx.tcx.is_diagnostic_item(sym::deref_method, fun_def_id)
+ || deref_aliases.iter().any(|path| match_def_path(cx, fun_def_id, path))
+ })
+ },
hir::ExprKind::Closure(&hir::Closure { body, .. }) => {
let closure_body = cx.tcx.hir().body(body);
let closure_expr = peel_blocks(closure_body.value);
@@ -68,7 +69,8 @@ pub(super) fn check<'tcx>(
if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj;
then {
let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap();
- deref_aliases.iter().any(|path| match_def_path(cx, method_did, path))
+ cx.tcx.is_diagnostic_item(sym::deref_method, method_did)
+ || deref_aliases.iter().any(|path| match_def_path(cx, method_did, path))
} else {
false
}
@@ -98,13 +100,12 @@ pub(super) fn check<'tcx>(
format!(".as_ref().map({})", snippet(cx, map_arg.span, ".."))
};
let method_hint = if is_mut { "as_deref_mut" } else { "as_deref" };
- let hint = format!("{}.{}()", snippet(cx, as_ref_recv.span, ".."), method_hint);
- let suggestion = format!("try using {} instead", method_hint);
+ let hint = format!("{}.{method_hint}()", snippet(cx, as_ref_recv.span, ".."));
+ let suggestion = format!("try using {method_hint} instead");
let msg = format!(
- "called `{0}` on an Option value. This can be done more directly \
- by calling `{1}` instead",
- current_method, hint
+ "called `{current_method}` on an Option value. This can be done more directly \
+ by calling `{hint}` instead"
);
span_lint_and_sugg(
cx,
diff --git a/src/tools/clippy/clippy_lints/src/methods/option_map_or_none.rs b/src/tools/clippy/clippy_lints/src/methods/option_map_or_none.rs
index 6657cdccd..3a23ecc50 100644
--- a/src/tools/clippy/clippy_lints/src/methods/option_map_or_none.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/option_map_or_none.rs
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet;
use clippy_utils::ty::is_type_diagnostic_item;
-use clippy_utils::{is_lang_ctor, path_def_id};
+use clippy_utils::{is_res_lang_ctor, path_def_id, path_res};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::LangItem::{OptionNone, OptionSome};
@@ -51,22 +51,12 @@ pub(super) fn check<'tcx>(
return;
}
- let default_arg_is_none = if let hir::ExprKind::Path(ref qpath) = def_arg.kind {
- is_lang_ctor(cx, qpath, OptionNone)
- } else {
- return;
- };
-
- if !default_arg_is_none {
+ if !is_res_lang_ctor(cx, path_res(cx, def_arg), OptionNone) {
// nothing to lint!
return;
}
- let f_arg_is_some = if let hir::ExprKind::Path(ref qpath) = map_arg.kind {
- is_lang_ctor(cx, qpath, OptionSome)
- } else {
- false
- };
+ let f_arg_is_some = is_res_lang_ctor(cx, path_res(cx, map_arg), OptionSome);
if is_option {
let self_snippet = snippet(cx, recv.span, "..");
@@ -87,7 +77,7 @@ pub(super) fn check<'tcx>(
expr.span,
msg,
"try using `map` instead",
- format!("{0}.map({1} {2})", self_snippet, arg_snippet,func_snippet),
+ format!("{self_snippet}.map({arg_snippet} {func_snippet})"),
Applicability::MachineApplicable,
);
}
@@ -102,7 +92,7 @@ pub(super) fn check<'tcx>(
expr.span,
msg,
"try using `and_then` instead",
- format!("{0}.and_then({1})", self_snippet, func_snippet),
+ format!("{self_snippet}.and_then({func_snippet})"),
Applicability::MachineApplicable,
);
} else if f_arg_is_some {
@@ -115,7 +105,7 @@ pub(super) fn check<'tcx>(
expr.span,
msg,
"try using `ok` instead",
- format!("{0}.ok()", self_snippet),
+ format!("{self_snippet}.ok()"),
Applicability::MachineApplicable,
);
}
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 3c4002a3a..30421a6dd 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
@@ -65,9 +65,8 @@ pub(super) fn check<'tcx>(
"map_or(<a>, <f>)"
};
let msg = &format!(
- "called `map(<f>).unwrap_or({})` on an `Option` value. \
- This can be done more directly by calling `{}` instead",
- arg, suggest
+ "called `map(<f>).unwrap_or({arg})` on an `Option` value. \
+ This can be done more directly by calling `{suggest}` instead"
);
span_lint_and_then(cx, MAP_UNWRAP_OR, expr.span, msg, |diag| {
@@ -82,10 +81,10 @@ pub(super) fn check<'tcx>(
];
if !unwrap_snippet_none {
- suggestion.push((map_arg_span.with_hi(map_arg_span.lo()), format!("{}, ", unwrap_snippet)));
+ suggestion.push((map_arg_span.with_hi(map_arg_span.lo()), format!("{unwrap_snippet}, ")));
}
- diag.multipart_suggestion(&format!("use `{}` instead", suggest), suggestion, applicability);
+ diag.multipart_suggestion(&format!("use `{suggest}` instead"), suggestion, applicability);
});
}
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs b/src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs
index b43b9258c..991d3dd53 100644
--- a/src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs
@@ -1,14 +1,14 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::eager_or_lazy::switch_to_lazy_eval;
use clippy_utils::source::{snippet, snippet_with_macro_callsite};
-use clippy_utils::ty::{implements_trait, match_type};
-use clippy_utils::{contains_return, is_trait_item, last_path_segment, paths};
+use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
+use clippy_utils::{contains_return, is_trait_item, last_path_segment};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_span::source_map::Span;
-use rustc_span::symbol::{kw, sym};
+use rustc_span::symbol::{kw, sym, Symbol};
use std::borrow::Cow;
use super::OR_FUN_CALL;
@@ -62,9 +62,9 @@ pub(super) fn check<'tcx>(
cx,
OR_FUN_CALL,
method_span.with_hi(span.hi()),
- &format!("use of `{}` followed by a call to `{}`", name, path),
+ &format!("use of `{name}` followed by a call to `{path}`"),
"try this",
- format!("{}()", sugg),
+ format!("{sugg}()"),
Applicability::MachineApplicable,
);
@@ -88,11 +88,11 @@ pub(super) fn check<'tcx>(
fun_span: Option<Span>,
) {
// (path, fn_has_argument, methods, suffix)
- const KNOW_TYPES: [(&[&str], bool, &[&str], &str); 4] = [
- (&paths::BTREEMAP_ENTRY, false, &["or_insert"], "with"),
- (&paths::HASHMAP_ENTRY, false, &["or_insert"], "with"),
- (&paths::OPTION, false, &["map_or", "ok_or", "or", "unwrap_or"], "else"),
- (&paths::RESULT, true, &["or", "unwrap_or"], "else"),
+ const KNOW_TYPES: [(Symbol, bool, &[&str], &str); 4] = [
+ (sym::BTreeEntry, false, &["or_insert"], "with"),
+ (sym::HashMapEntry, false, &["or_insert"], "with"),
+ (sym::Option, false, &["map_or", "ok_or", "or", "unwrap_or"], "else"),
+ (sym::Result, true, &["or", "unwrap_or"], "else"),
];
if_chain! {
@@ -104,7 +104,7 @@ pub(super) fn check<'tcx>(
let self_ty = cx.typeck_results().expr_ty(self_expr);
if let Some(&(_, fn_has_arguments, poss, suffix)) =
- KNOW_TYPES.iter().find(|&&i| match_type(cx, self_ty, i.0));
+ KNOW_TYPES.iter().find(|&&i| is_type_diagnostic_item(cx, self_ty, i.0));
if poss.contains(&name);
@@ -121,17 +121,16 @@ pub(super) fn check<'tcx>(
macro_expanded_snipped = snippet(cx, snippet_span, "..");
match macro_expanded_snipped.strip_prefix("$crate::vec::") {
Some(stripped) => Cow::from(stripped),
- None => macro_expanded_snipped
+ None => macro_expanded_snipped,
}
- }
- else {
+ } else {
not_macro_argument_snippet
}
};
if use_lambda {
let l_arg = if fn_has_arguments { "_" } else { "" };
- format!("|{}| {}", l_arg, snippet).into()
+ format!("|{l_arg}| {snippet}").into()
} else {
snippet
}
@@ -141,9 +140,9 @@ pub(super) fn check<'tcx>(
cx,
OR_FUN_CALL,
span_replace_word,
- &format!("use of `{}` followed by a function call", name),
+ &format!("use of `{name}` followed by a function call"),
"try this",
- format!("{}_{}({})", name, suffix, sugg),
+ format!("{name}_{suffix}({sugg})"),
Applicability::HasPlaceholders,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/or_then_unwrap.rs b/src/tools/clippy/clippy_lints/src/methods/or_then_unwrap.rs
index be5768c35..55ba6e262 100644
--- a/src/tools/clippy/clippy_lints/src/methods/or_then_unwrap.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/or_then_unwrap.rs
@@ -1,6 +1,6 @@
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::is_type_diagnostic_item;
-use clippy_utils::{diagnostics::span_lint_and_sugg, is_lang_ctor};
+use clippy_utils::{diagnostics::span_lint_and_sugg, is_res_lang_ctor, path_res};
use rustc_errors::Applicability;
use rustc_hir::{lang_items::LangItem, Expr, ExprKind};
use rustc_lint::LateContext;
@@ -58,8 +58,7 @@ pub(super) fn check<'tcx>(
fn get_content_if_ctor_matches(cx: &LateContext<'_>, expr: &Expr<'_>, item: LangItem) -> Option<Span> {
if let ExprKind::Call(some_expr, [arg]) = expr.kind
- && let ExprKind::Path(qpath) = &some_expr.kind
- && is_lang_ctor(cx, qpath, item)
+ && is_res_lang_ctor(cx, path_res(cx, some_expr), item)
{
Some(arg.span)
} else {
diff --git a/src/tools/clippy/clippy_lints/src/methods/search_is_some.rs b/src/tools/clippy/clippy_lints/src/methods/search_is_some.rs
index 7572ba3fe..324c9c17b 100644
--- a/src/tools/clippy/clippy_lints/src/methods/search_is_some.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/search_is_some.rs
@@ -30,10 +30,7 @@ pub(super) fn check<'tcx>(
let option_check_method = if is_some { "is_some" } else { "is_none" };
// lint if caller of search is an Iterator
if is_trait_method(cx, is_some_recv, sym::Iterator) {
- let msg = format!(
- "called `{}()` after searching an `Iterator` with `{}`",
- option_check_method, search_method
- );
+ let msg = format!("called `{option_check_method}()` after searching an `Iterator` with `{search_method}`");
let search_snippet = snippet(cx, search_arg.span, "..");
if search_snippet.lines().count() <= 1 {
// suggest `any(|x| ..)` instead of `any(|&x| ..)` for `find(|&x| ..).is_some()`
@@ -86,8 +83,7 @@ pub(super) fn check<'tcx>(
&msg,
"use `!_.any()` instead",
format!(
- "!{}.any({})",
- iter,
+ "!{iter}.any({})",
any_search_snippet.as_ref().map_or(&*search_snippet, String::as_str)
),
applicability,
@@ -119,7 +115,7 @@ pub(super) fn check<'tcx>(
if is_string_or_str_slice(search_recv);
if is_string_or_str_slice(search_arg);
then {
- let msg = format!("called `{}()` after calling `find()` on a string", option_check_method);
+ let msg = format!("called `{option_check_method}()` after calling `find()` on a string");
match option_check_method {
"is_some" => {
let mut applicability = Applicability::MachineApplicable;
@@ -130,7 +126,7 @@ pub(super) fn check<'tcx>(
method_span.with_hi(expr.span.hi()),
&msg,
"use `contains()` instead",
- format!("contains({})", find_arg),
+ format!("contains({find_arg})"),
applicability,
);
},
@@ -144,7 +140,7 @@ pub(super) fn check<'tcx>(
expr.span,
&msg,
"use `!_.contains()` instead",
- format!("!{}.contains({})", string, find_arg),
+ format!("!{string}.contains({find_arg})"),
applicability,
);
},
diff --git a/src/tools/clippy/clippy_lints/src/methods/single_char_insert_string.rs b/src/tools/clippy/clippy_lints/src/methods/single_char_insert_string.rs
index 18b6b5be1..44a7ad394 100644
--- a/src/tools/clippy/clippy_lints/src/methods/single_char_insert_string.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/single_char_insert_string.rs
@@ -14,7 +14,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, receiver: &hir::
let base_string_snippet =
snippet_with_applicability(cx, receiver.span.source_callsite(), "_", &mut applicability);
let pos_arg = snippet_with_applicability(cx, args[0].span, "..", &mut applicability);
- let sugg = format!("{}.insert({}, {})", base_string_snippet, pos_arg, extension_string);
+ let sugg = format!("{base_string_snippet}.insert({pos_arg}, {extension_string})");
span_lint_and_sugg(
cx,
SINGLE_CHAR_ADD_STR,
diff --git a/src/tools/clippy/clippy_lints/src/methods/single_char_push_string.rs b/src/tools/clippy/clippy_lints/src/methods/single_char_push_string.rs
index 9ea675195..0698bd6a0 100644
--- a/src/tools/clippy/clippy_lints/src/methods/single_char_push_string.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/single_char_push_string.rs
@@ -13,7 +13,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, receiver: &hir::
if let Some(extension_string) = get_hint_if_single_char_arg(cx, &args[0], &mut applicability) {
let base_string_snippet =
snippet_with_applicability(cx, receiver.span.source_callsite(), "..", &mut applicability);
- let sugg = format!("{}.push({})", base_string_snippet, extension_string);
+ let sugg = format!("{base_string_snippet}.push({extension_string})");
span_lint_and_sugg(
cx,
SINGLE_CHAR_ADD_STR,
diff --git a/src/tools/clippy/clippy_lints/src/methods/stable_sort_primitive.rs b/src/tools/clippy/clippy_lints/src/methods/stable_sort_primitive.rs
index 91951c65b..09c8ca4cb 100644
--- a/src/tools/clippy/clippy_lints/src/methods/stable_sort_primitive.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/stable_sort_primitive.rs
@@ -17,11 +17,11 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, recv: &'tcx
cx,
STABLE_SORT_PRIMITIVE,
e.span,
- &format!("used `sort` on primitive type `{}`", slice_type),
+ &format!("used `sort` on primitive type `{slice_type}`"),
|diag| {
let mut app = Applicability::MachineApplicable;
let recv_snip = snippet_with_context(cx, recv.span, e.span.ctxt(), "..", &mut app).0;
- diag.span_suggestion(e.span, "try", format!("{}.sort_unstable()", recv_snip), app);
+ diag.span_suggestion(e.span, "try", format!("{recv_snip}.sort_unstable()"), app);
diag.note(
"an unstable sort typically performs faster without any observable difference for this data type",
);
diff --git a/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs b/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs
index 9ca4d6555..1acac5914 100644
--- a/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/str_splitn.rs
@@ -2,11 +2,11 @@ use clippy_utils::consts::{constant, Constant};
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
use clippy_utils::source::snippet_with_context;
use clippy_utils::usage::local_used_after_expr;
-use clippy_utils::visitors::expr_visitor;
+use clippy_utils::visitors::{for_each_expr_with_closures, Descend};
use clippy_utils::{is_diag_item_method, match_def_path, meets_msrv, msrvs, path_to_local_id, paths};
+use core::ops::ControlFlow;
use if_chain::if_chain;
use rustc_errors::Applicability;
-use rustc_hir::intravisit::Visitor;
use rustc_hir::{
BindingAnnotation, Expr, ExprKind, HirId, LangItem, Local, MatchSource, Node, Pat, PatKind, QPath, Stmt, StmtKind,
};
@@ -211,7 +211,7 @@ fn indirect_usage<'tcx>(
binding: HirId,
ctxt: SyntaxContext,
) -> Option<IndirectUsage<'tcx>> {
- if let StmtKind::Local(Local {
+ if let StmtKind::Local(&Local {
pat: Pat {
kind: PatKind::Binding(BindingAnnotation::NONE, _, ident, None),
..
@@ -222,14 +222,12 @@ fn indirect_usage<'tcx>(
}) = stmt.kind
{
let mut path_to_binding = None;
- expr_visitor(cx, |expr| {
- if path_to_local_id(expr, binding) {
- path_to_binding = Some(expr);
+ let _: Option<!> = for_each_expr_with_closures(cx, init_expr, |e| {
+ if path_to_local_id(e, binding) {
+ path_to_binding = Some(e);
}
-
- path_to_binding.is_none()
- })
- .visit_expr(init_expr);
+ ControlFlow::Continue(Descend::from(path_to_binding.is_none()))
+ });
let mut parents = cx.tcx.hir().parent_iter(path_to_binding?.hir_id);
let iter_usage = parse_iter_usage(cx, ctxt, &mut parents)?;
@@ -250,7 +248,7 @@ fn indirect_usage<'tcx>(
..
} = iter_usage
{
- if parent_id == *local_hir_id {
+ if parent_id == local_hir_id {
return Some(IndirectUsage {
name: ident.name,
span: stmt.span,
@@ -291,9 +289,7 @@ fn parse_iter_usage<'tcx>(
) -> Option<IterUsage> {
let (kind, span) = match iter.next() {
Some((_, Node::Expr(e))) if e.span.ctxt() == ctxt => {
- let (name, args) = if let ExprKind::MethodCall(name, _, [args @ ..], _) = e.kind {
- (name, args)
- } else {
+ let ExprKind::MethodCall(name, _, [args @ ..], _) = e.kind else {
return None;
};
let did = cx.typeck_results().type_dependent_def_id(e.hir_id)?;
diff --git a/src/tools/clippy/clippy_lints/src/methods/string_extend_chars.rs b/src/tools/clippy/clippy_lints/src/methods/string_extend_chars.rs
index 143dcee35..6974260f7 100644
--- a/src/tools/clippy/clippy_lints/src/methods/string_extend_chars.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/string_extend_chars.rs
@@ -34,9 +34,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
"calling `.extend(_.chars())`",
"try this",
format!(
- "{}.push_str({}{})",
+ "{}.push_str({ref_str}{})",
snippet_with_applicability(cx, recv.span, "..", &mut applicability),
- ref_str,
snippet_with_applicability(cx, target.span, "..", &mut applicability)
),
applicability,
diff --git a/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs b/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs
index 55567d862..219a9edd6 100644
--- a/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/suspicious_splitn.rs
@@ -24,10 +24,10 @@ pub(super) fn check(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, se
}
let (msg, note_msg) = if count == 0 {
- (format!("`{}` called with `0` splits", method_name),
+ (format!("`{method_name}` called with `0` splits"),
"the resulting iterator will always return `None`")
} else {
- (format!("`{}` called with `1` split", method_name),
+ (format!("`{method_name}` called with `1` split"),
if self_ty.is_slice() {
"the resulting iterator will always return the entire slice followed by `None`"
} else {
diff --git a/src/tools/clippy/clippy_lints/src/methods/suspicious_to_owned.rs b/src/tools/clippy/clippy_lints/src/methods/suspicious_to_owned.rs
index 6b306fbf0..15c1c618c 100644
--- a/src/tools/clippy/clippy_lints/src/methods/suspicious_to_owned.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/suspicious_to_owned.rs
@@ -24,9 +24,9 @@ pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) -
cx,
SUSPICIOUS_TO_OWNED,
expr.span,
- &format!("this `to_owned` call clones the {0} itself and does not cause the {0} contents to become owned", input_type),
+ &format!("this `to_owned` call clones the {input_type} itself and does not cause the {input_type} contents to become owned"),
"consider using, depending on intent",
- format!("{0}.clone()` or `{0}.into_owned()", recv_snip),
+ format!("{recv_snip}.clone()` or `{recv_snip}.into_owned()"),
app,
);
return true;
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 4e8c201f4..1cef6226a 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
@@ -2,9 +2,10 @@ use super::utils::clone_or_copy_needed;
use clippy_utils::diagnostics::span_lint;
use clippy_utils::ty::is_copy;
use clippy_utils::usage::mutated_variables;
-use clippy_utils::{is_lang_ctor, is_trait_method, path_to_local_id};
+use clippy_utils::visitors::{for_each_expr, Descend};
+use clippy_utils::{is_res_lang_ctor, is_trait_method, path_res, path_to_local_id};
+use core::ops::ControlFlow;
use rustc_hir as hir;
-use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::LangItem::{OptionNone, OptionSome};
use rustc_lint::LateContext;
use rustc_middle::ty;
@@ -13,7 +14,7 @@ use rustc_span::sym;
use super::UNNECESSARY_FILTER_MAP;
use super::UNNECESSARY_FIND_MAP;
-pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, name: &str) {
+pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>, arg: &'tcx hir::Expr<'tcx>, name: &str) {
if !is_trait_method(cx, expr, sym::Iterator) {
return;
}
@@ -26,10 +27,16 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<
let (mut found_mapping, mut found_filtering) = check_expression(cx, arg_id, body.value);
- let mut return_visitor = ReturnVisitor::new(cx, arg_id);
- return_visitor.visit_expr(body.value);
- found_mapping |= return_visitor.found_mapping;
- found_filtering |= return_visitor.found_filtering;
+ let _: Option<!> = for_each_expr(body.value, |e| {
+ if let hir::ExprKind::Ret(Some(e)) = &e.kind {
+ let (found_mapping_res, found_filtering_res) = check_expression(cx, arg_id, e);
+ found_mapping |= found_mapping_res;
+ found_filtering |= found_filtering_res;
+ ControlFlow::Continue(Descend::No)
+ } else {
+ ControlFlow::Continue(Descend::Yes)
+ }
+ });
let in_ty = cx.typeck_results().node_type(body.params[0].hir_id);
let sugg = if !found_filtering {
@@ -54,22 +61,20 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<
UNNECESSARY_FIND_MAP
},
expr.span,
- &format!("this `.{}` can be written more simply using `.{}`", name, sugg),
+ &format!("this `.{name}` can be written more simply using `.{sugg}`"),
);
}
}
// returns (found_mapping, found_filtering)
fn check_expression<'tcx>(cx: &LateContext<'tcx>, arg_id: hir::HirId, expr: &'tcx hir::Expr<'_>) -> (bool, bool) {
- match &expr.kind {
+ match expr.kind {
hir::ExprKind::Call(func, args) => {
- if let hir::ExprKind::Path(ref path) = func.kind {
- if is_lang_ctor(cx, path, OptionSome) {
- if path_to_local_id(&args[0], arg_id) {
- return (false, false);
- }
- return (true, false);
+ if is_res_lang_ctor(cx, path_res(cx, func), OptionSome) {
+ if path_to_local_id(&args[0], arg_id) {
+ return (false, false);
}
+ return (true, false);
}
(true, true)
},
@@ -80,7 +85,7 @@ fn check_expression<'tcx>(cx: &LateContext<'tcx>, arg_id: hir::HirId, expr: &'tc
hir::ExprKind::Match(_, arms, _) => {
let mut found_mapping = false;
let mut found_filtering = false;
- for arm in *arms {
+ for arm in arms {
let (m, f) = check_expression(cx, arg_id, arm.body);
found_mapping |= m;
found_filtering |= f;
@@ -93,39 +98,9 @@ fn check_expression<'tcx>(cx: &LateContext<'tcx>, arg_id: hir::HirId, expr: &'tc
let else_check = check_expression(cx, arg_id, else_arm);
(if_check.0 | else_check.0, if_check.1 | else_check.1)
},
- hir::ExprKind::Path(path) if is_lang_ctor(cx, path, OptionNone) => (false, true),
+ hir::ExprKind::Path(ref path) if is_res_lang_ctor(cx, cx.qpath_res(path, expr.hir_id), OptionNone) => {
+ (false, true)
+ },
_ => (true, true),
}
}
-
-struct ReturnVisitor<'a, 'tcx> {
- cx: &'a LateContext<'tcx>,
- arg_id: hir::HirId,
- // Found a non-None return that isn't Some(input)
- found_mapping: bool,
- // Found a return that isn't Some
- found_filtering: bool,
-}
-
-impl<'a, 'tcx> ReturnVisitor<'a, 'tcx> {
- fn new(cx: &'a LateContext<'tcx>, arg_id: hir::HirId) -> ReturnVisitor<'a, 'tcx> {
- ReturnVisitor {
- cx,
- arg_id,
- found_mapping: false,
- found_filtering: false,
- }
- }
-}
-
-impl<'a, 'tcx> Visitor<'tcx> for ReturnVisitor<'a, 'tcx> {
- fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
- if let hir::ExprKind::Ret(Some(expr)) = &expr.kind {
- let (found_mapping, found_filtering) = check_expression(self.cx, self.arg_id, expr);
- self.found_mapping |= found_mapping;
- self.found_filtering |= found_filtering;
- } else {
- walk_expr(self, expr);
- }
- }
-}
diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs
index c17ef6809..aa87dead3 100644
--- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_fold.rs
@@ -49,15 +49,12 @@ pub(super) fn check(
let mut applicability = Applicability::MachineApplicable;
let sugg = if replacement_has_args {
format!(
- "{replacement}(|{s}| {r})",
- replacement = replacement_method_name,
- s = second_arg_ident,
+ "{replacement_method_name}(|{second_arg_ident}| {r})",
r = snippet_with_applicability(cx, right_expr.span, "EXPR", &mut applicability),
)
} else {
format!(
- "{replacement}()",
- replacement = replacement_method_name,
+ "{replacement_method_name}()",
)
};
diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_iter_cloned.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_iter_cloned.rs
index 95138c0e2..1966a85f7 100644
--- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_iter_cloned.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_iter_cloned.rs
@@ -68,7 +68,7 @@ pub fn check_for_loop_iter(
cx,
UNNECESSARY_TO_OWNED,
expr.span,
- &format!("unnecessary use of `{}`", method_name),
+ &format!("unnecessary use of `{method_name}`"),
|diag| {
// If `check_into_iter_call_arg` called `check_for_loop_iter` because a call to
// a `to_owned`-like function was removed, then the next suggestion may be
diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_lazy_eval.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_lazy_eval.rs
index a187a8d60..0e73459ad 100644
--- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_lazy_eval.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_lazy_eval.rs
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::snippet;
use clippy_utils::ty::is_type_diagnostic_item;
-use clippy_utils::{eager_or_lazy, usage};
+use clippy_utils::{eager_or_lazy, is_from_proc_macro, usage};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
@@ -18,6 +18,10 @@ pub(super) fn check<'tcx>(
arg: &'tcx hir::Expr<'_>,
simplify_using: &str,
) {
+ if is_from_proc_macro(cx, expr) {
+ return;
+ }
+
let is_option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Option);
let is_result = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result);
let is_bool = cx.typeck_results().expr_ty(recv).is_bool();
@@ -58,8 +62,8 @@ pub(super) fn check<'tcx>(
span_lint_and_then(cx, UNNECESSARY_LAZY_EVALUATIONS, expr.span, msg, |diag| {
diag.span_suggestion(
span,
- &format!("use `{}(..)` instead", simplify_using),
- format!("{}({})", simplify_using, snippet(cx, body_expr.span, "..")),
+ &format!("use `{simplify_using}(..)` instead"),
+ format!("{simplify_using}({})", snippet(cx, body_expr.span, "..")),
applicability,
);
});
diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs
index 763bfafec..3566fe9a0 100644
--- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs
@@ -1,6 +1,5 @@
use super::implicit_clone::is_clone_like;
use super::unnecessary_iter_cloned::{self, is_into_iter};
-use crate::rustc_middle::ty::Subst;
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::{get_associated_type, get_iterator_item_ty, implements_trait, is_copy, peel_mid_ty_refs};
@@ -8,7 +7,8 @@ use clippy_utils::visitors::find_all_ret_expressions;
use clippy_utils::{fn_def_id, get_parent_expr, is_diag_item_method, is_diag_trait_item, return_ty};
use clippy_utils::{meets_msrv, msrvs};
use rustc_errors::Applicability;
-use rustc_hir::{def_id::DefId, BorrowKind, Expr, ExprKind, ItemKind, Node};
+use rustc_hir::{def_id::DefId, BorrowKind, Expr, ExprKind, ItemKind, LangItem, Node};
+use rustc_hir_typeck::{FnCtxt, Inherited};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::LateContext;
use rustc_middle::mir::Mutability;
@@ -19,7 +19,6 @@ use rustc_middle::ty::{self, ParamTy, PredicateKind, ProjectionPredicate, TraitP
use rustc_semver::RustcVersion;
use rustc_span::{sym, Symbol};
use rustc_trait_selection::traits::{query::evaluate_obligation::InferCtxtExt as _, Obligation, ObligationCause};
-use rustc_typeck::check::{FnCtxt, Inherited};
use std::cmp::max;
use super::UNNECESSARY_TO_OWNED;
@@ -133,12 +132,11 @@ fn check_addr_of_expr(
cx,
UNNECESSARY_TO_OWNED,
parent.span,
- &format!("unnecessary use of `{}`", method_name),
+ &format!("unnecessary use of `{method_name}`"),
"use",
format!(
- "{:&>width$}{}",
+ "{:&>width$}{receiver_snippet}",
"",
- receiver_snippet,
width = n_target_refs - n_receiver_refs
),
Applicability::MachineApplicable,
@@ -155,7 +153,7 @@ fn check_addr_of_expr(
cx,
UNNECESSARY_TO_OWNED,
parent.span,
- &format!("unnecessary use of `{}`", method_name),
+ &format!("unnecessary use of `{method_name}`"),
"use",
receiver_snippet,
Applicability::MachineApplicable,
@@ -165,7 +163,7 @@ fn check_addr_of_expr(
cx,
UNNECESSARY_TO_OWNED,
expr.span.with_lo(receiver.span.hi()),
- &format!("unnecessary use of `{}`", method_name),
+ &format!("unnecessary use of `{method_name}`"),
"remove this",
String::new(),
Applicability::MachineApplicable,
@@ -182,9 +180,9 @@ fn check_addr_of_expr(
cx,
UNNECESSARY_TO_OWNED,
parent.span,
- &format!("unnecessary use of `{}`", method_name),
+ &format!("unnecessary use of `{method_name}`"),
"use",
- format!("{}.as_ref()", receiver_snippet),
+ format!("{receiver_snippet}.as_ref()"),
Applicability::MachineApplicable,
);
return true;
@@ -229,9 +227,9 @@ fn check_into_iter_call_arg(
cx,
UNNECESSARY_TO_OWNED,
parent.span,
- &format!("unnecessary use of `{}`", method_name),
+ &format!("unnecessary use of `{method_name}`"),
"use",
- format!("{}.iter().{}()", receiver_snippet, cloned_or_copied),
+ format!("{receiver_snippet}.iter().{cloned_or_copied}()"),
Applicability::MaybeIncorrect,
);
return true;
@@ -269,16 +267,16 @@ fn check_other_call_arg<'tcx>(
// We can't add an `&` when the trait is `Deref` because `Target = &T` won't match
// `Target = T`.
if n_refs > 0 || is_copy(cx, receiver_ty) || trait_predicate.def_id() != deref_trait_id;
- let n_refs = max(n_refs, if is_copy(cx, receiver_ty) { 0 } else { 1 });
+ let n_refs = max(n_refs, usize::from(!is_copy(cx, receiver_ty)));
if let Some(receiver_snippet) = snippet_opt(cx, receiver.span);
then {
span_lint_and_sugg(
cx,
UNNECESSARY_TO_OWNED,
maybe_arg.span,
- &format!("unnecessary use of `{}`", method_name),
+ &format!("unnecessary use of `{method_name}`"),
"use",
- format!("{:&>width$}{}", "", receiver_snippet, width = n_refs),
+ format!("{:&>n_refs$}{receiver_snippet}", ""),
Applicability::MachineApplicable,
);
return true;
@@ -365,7 +363,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
&& let output_ty = return_ty(cx, item.hir_id())
&& let local_def_id = cx.tcx.hir().local_def_id(item.hir_id())
&& Inherited::build(cx.tcx, local_def_id).enter(|inherited| {
- let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, item.hir_id());
+ let fn_ctxt = FnCtxt::new(inherited, cx.param_env, item.hir_id());
fn_ctxt.can_coerce(ty, output_ty)
}) {
if has_lifetime(output_ty) && has_lifetime(ty) {
@@ -380,6 +378,10 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
Node::Expr(parent_expr) => {
if let Some((callee_def_id, call_substs, recv, call_args)) = get_callee_substs_and_args(cx, parent_expr)
{
+ if cx.tcx.lang_items().require(LangItem::IntoFutureIntoFuture) == Ok(callee_def_id) {
+ return false;
+ }
+
let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder();
if let Some(arg_index) = recv.into_iter().chain(call_args).position(|arg| arg.hir_id == expr.hir_id)
&& let Some(param_ty) = fn_sig.inputs().get(arg_index)
@@ -418,9 +420,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
if trait_predicates.any(|predicate| {
let predicate = EarlyBinder(predicate).subst(cx.tcx, new_subst);
let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate);
- !cx.tcx
- .infer_ctxt()
- .enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation))
+ !cx.tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation)
}) {
return false;
}
diff --git a/src/tools/clippy/clippy_lints/src/methods/useless_asref.rs b/src/tools/clippy/clippy_lints/src/methods/useless_asref.rs
index ca5d33ee8..c1139d84e 100644
--- a/src/tools/clippy/clippy_lints/src/methods/useless_asref.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/useless_asref.rs
@@ -1,11 +1,12 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::walk_ptrs_ty_depth;
-use clippy_utils::{get_parent_expr, match_trait_method, paths};
+use clippy_utils::{get_parent_expr, is_trait_method};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
+use rustc_span::sym;
use super::USELESS_ASREF;
@@ -13,7 +14,7 @@ use super::USELESS_ASREF;
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, recvr: &hir::Expr<'_>) {
// when we get here, we've already checked that the call name is "as_ref" or "as_mut"
// check if the call is to the actual `AsRef` or `AsMut` trait
- if match_trait_method(cx, expr, &paths::ASREF_TRAIT) || match_trait_method(cx, expr, &paths::ASMUT_TRAIT) {
+ if is_trait_method(cx, expr, sym::AsRef) || is_trait_method(cx, expr, sym::AsMut) {
// check if the type after `as_ref` or `as_mut` is the same as before
let rcv_ty = cx.typeck_results().expr_ty(recvr);
let res_ty = cx.typeck_results().expr_ty(expr);
@@ -35,7 +36,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str,
cx,
USELESS_ASREF,
expr.span,
- &format!("this call to `{}` does nothing", call_name),
+ &format!("this call to `{call_name}` does nothing"),
"try this",
snippet_with_applicability(cx, recvr.span, "..", &mut applicability).to_string(),
applicability,
diff --git a/src/tools/clippy/clippy_lints/src/methods/wrong_self_convention.rs b/src/tools/clippy/clippy_lints/src/methods/wrong_self_convention.rs
index 4b368d3ff..1fbf783b8 100644
--- a/src/tools/clippy/clippy_lints/src/methods/wrong_self_convention.rs
+++ b/src/tools/clippy/clippy_lints/src/methods/wrong_self_convention.rs
@@ -61,20 +61,20 @@ impl Convention {
impl fmt::Display for Convention {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match *self {
- Self::Eq(this) => format!("`{}`", this).fmt(f),
- Self::StartsWith(this) => format!("`{}*`", this).fmt(f),
- Self::EndsWith(this) => format!("`*{}`", this).fmt(f),
- Self::NotEndsWith(this) => format!("`~{}`", this).fmt(f),
+ Self::Eq(this) => format!("`{this}`").fmt(f),
+ Self::StartsWith(this) => format!("`{this}*`").fmt(f),
+ Self::EndsWith(this) => format!("`*{this}`").fmt(f),
+ Self::NotEndsWith(this) => format!("`~{this}`").fmt(f),
Self::IsSelfTypeCopy(is_true) => {
format!("`self` type is{} `Copy`", if is_true { "" } else { " not" }).fmt(f)
},
Self::ImplementsTrait(is_true) => {
let (negation, s_suffix) = if is_true { ("", "s") } else { (" does not", "") };
- format!("method{} implement{} a trait", negation, s_suffix).fmt(f)
+ format!("method{negation} implement{s_suffix} a trait").fmt(f)
},
Self::IsTraitItem(is_true) => {
let suffix = if is_true { " is" } else { " is not" };
- format!("method{} a trait item", suffix).fmt(f)
+ format!("method{suffix} a trait item").fmt(f)
},
}
}
@@ -138,8 +138,7 @@ pub(super) fn check<'tcx>(
WRONG_SELF_CONVENTION,
first_arg_span,
&format!(
- "{} usually take {}",
- suggestion,
+ "{suggestion} usually take {}",
&self_kinds
.iter()
.map(|k| k.description())
diff --git a/src/tools/clippy/clippy_lints/src/minmax.rs b/src/tools/clippy/clippy_lints/src/minmax.rs
index 4d8579135..4f967755b 100644
--- a/src/tools/clippy/clippy_lints/src/minmax.rs
+++ b/src/tools/clippy/clippy_lints/src/minmax.rs
@@ -1,6 +1,6 @@
use clippy_utils::consts::{constant_simple, Constant};
use clippy_utils::diagnostics::span_lint;
-use clippy_utils::{match_trait_method, paths};
+use clippy_utils::is_trait_method;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -83,7 +83,7 @@ fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Cons
}
},
ExprKind::MethodCall(path, receiver, args @ [_], _) => {
- if cx.typeck_results().expr_ty(receiver).is_floating_point() || match_trait_method(cx, expr, &paths::ORD) {
+ if cx.typeck_results().expr_ty(receiver).is_floating_point() || is_trait_method(cx, expr, sym::Ord) {
if path.ident.name == sym!(max) {
fetch_const(cx, Some(receiver), args, MinMax::Max)
} else if path.ident.name == sym!(min) {
diff --git a/src/tools/clippy/clippy_lints/src/misc.rs b/src/tools/clippy/clippy_lints/src/misc.rs
index ea245edd7..516dee20f 100644
--- a/src/tools/clippy/clippy_lints/src/misc.rs
+++ b/src/tools/clippy/clippy_lints/src/misc.rs
@@ -1,7 +1,6 @@
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_hir_and_then};
use clippy_utils::source::{snippet, snippet_opt};
use if_chain::if_chain;
-use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
use rustc_hir::intravisit::FnKind;
use rustc_hir::{
@@ -15,7 +14,7 @@ use rustc_span::hygiene::DesugaringKind;
use rustc_span::source_map::{ExpnKind, Span};
use clippy_utils::sugg::Sugg;
-use clippy_utils::{get_parent_expr, in_constant, iter_input_pats, last_path_segment, SpanlessEq};
+use clippy_utils::{get_parent_expr, in_constant, is_integer_literal, iter_input_pats, last_path_segment, SpanlessEq};
declare_clippy_lint! {
/// ### What it does
@@ -178,7 +177,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
("", sugg_init.addr())
};
let tyopt = if let Some(ty) = local.ty {
- format!(": &{mutopt}{ty}", mutopt=mutopt, ty=snippet(cx, ty.span, ".."))
+ format!(": &{mutopt}{ty}", ty=snippet(cx, ty.span, ".."))
} else {
String::new()
};
@@ -195,8 +194,6 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
format!(
"let {name}{tyopt} = {initref};",
name=snippet(cx, name.span, ".."),
- tyopt=tyopt,
- initref=initref,
),
Applicability::MachineApplicable,
);
@@ -222,8 +219,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
stmt.span,
"replace it with",
format!(
- "if {} {{ {}; }}",
- sugg,
+ "if {sugg} {{ {}; }}",
&snippet(cx, b.span, ".."),
),
Applicability::MachineApplicable, // snippet
@@ -275,9 +271,8 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
USED_UNDERSCORE_BINDING,
expr.span,
&format!(
- "used binding `{}` which is prefixed with an underscore. A leading \
- underscore signals that a binding will not be used",
- binding
+ "used binding `{binding}` which is prefixed with an underscore. A leading \
+ underscore signals that a binding will not be used"
),
);
}
@@ -318,8 +313,7 @@ fn non_macro_local(cx: &LateContext<'_>, res: def::Res) -> bool {
fn check_cast(cx: &LateContext<'_>, span: Span, e: &Expr<'_>, ty: &hir::Ty<'_>) {
if_chain! {
if let TyKind::Ptr(ref mut_ty) = ty.kind;
- if let ExprKind::Lit(ref lit) = e.kind;
- if let LitKind::Int(0, _) = lit.node;
+ if is_integer_literal(e, 0);
if !in_constant(cx, e.hir_id);
then {
let (msg, sugg_fn) = match mut_ty.mutbl {
@@ -328,12 +322,12 @@ fn check_cast(cx: &LateContext<'_>, span: Span, e: &Expr<'_>, ty: &hir::Ty<'_>)
};
let (sugg, appl) = if let TyKind::Infer = mut_ty.ty.kind {
- (format!("{}()", sugg_fn), Applicability::MachineApplicable)
+ (format!("{sugg_fn}()"), Applicability::MachineApplicable)
} else if let Some(mut_ty_snip) = snippet_opt(cx, mut_ty.ty.span) {
- (format!("{}::<{}>()", sugg_fn, mut_ty_snip), Applicability::MachineApplicable)
+ (format!("{sugg_fn}::<{mut_ty_snip}>()"), Applicability::MachineApplicable)
} else {
// `MaybeIncorrect` as type inference may not work with the suggested code
- (format!("{}()", sugg_fn), Applicability::MaybeIncorrect)
+ (format!("{sugg_fn}()"), Applicability::MaybeIncorrect)
};
span_lint_and_sugg(cx, ZERO_PTR, span, msg, "try", sugg, appl);
}
diff --git a/src/tools/clippy/clippy_lints/src/misc_early/literal_suffix.rs b/src/tools/clippy/clippy_lints/src/misc_early/literal_suffix.rs
index 1165c19a0..27e7f8505 100644
--- a/src/tools/clippy/clippy_lints/src/misc_early/literal_suffix.rs
+++ b/src/tools/clippy/clippy_lints/src/misc_early/literal_suffix.rs
@@ -6,9 +6,7 @@ use rustc_lint::EarlyContext;
use super::{SEPARATED_LITERAL_SUFFIX, UNSEPARATED_LITERAL_SUFFIX};
pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str, suffix: &str, sugg_type: &str) {
- let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) {
- val
- } else {
+ let Some(maybe_last_sep_idx) = lit_snip.len().checked_sub(suffix.len() + 1) else {
return; // It's useless so shouldn't lint.
};
// Do not lint when literal is unsuffixed.
@@ -18,9 +16,9 @@ pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str, suffix: &s
cx,
SEPARATED_LITERAL_SUFFIX,
lit.span,
- &format!("{} type suffix should not be separated by an underscore", sugg_type),
+ &format!("{sugg_type} type suffix should not be separated by an underscore"),
"remove the underscore",
- format!("{}{}", &lit_snip[..maybe_last_sep_idx], suffix),
+ format!("{}{suffix}", &lit_snip[..maybe_last_sep_idx]),
Applicability::MachineApplicable,
);
} else {
@@ -28,9 +26,9 @@ pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str, suffix: &s
cx,
UNSEPARATED_LITERAL_SUFFIX,
lit.span,
- &format!("{} type suffix should be separated by an underscore", sugg_type),
+ &format!("{sugg_type} type suffix should be separated by an underscore"),
"add an underscore",
- format!("{}_{}", &lit_snip[..=maybe_last_sep_idx], suffix),
+ format!("{}_{suffix}", &lit_snip[..=maybe_last_sep_idx]),
Applicability::MachineApplicable,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/misc_early/mixed_case_hex_literals.rs b/src/tools/clippy/clippy_lints/src/misc_early/mixed_case_hex_literals.rs
index 80e242131..263ee1e94 100644
--- a/src/tools/clippy/clippy_lints/src/misc_early/mixed_case_hex_literals.rs
+++ b/src/tools/clippy/clippy_lints/src/misc_early/mixed_case_hex_literals.rs
@@ -5,9 +5,7 @@ use rustc_lint::EarlyContext;
use super::MIXED_CASE_HEX_LITERALS;
pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, suffix: &str, lit_snip: &str) {
- let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) {
- val
- } else {
+ let Some(maybe_last_sep_idx) = lit_snip.len().checked_sub(suffix.len() + 1) else {
return; // It's useless so shouldn't lint.
};
if maybe_last_sep_idx <= 2 {
diff --git a/src/tools/clippy/clippy_lints/src/misc_early/mod.rs b/src/tools/clippy/clippy_lints/src/misc_early/mod.rs
index 704918c0b..c8227ca44 100644
--- a/src/tools/clippy/clippy_lints/src/misc_early/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/misc_early/mod.rs
@@ -357,9 +357,8 @@ impl EarlyLintPass for MiscEarlyLints {
DUPLICATE_UNDERSCORE_ARGUMENT,
*correspondence,
&format!(
- "`{}` already exists, having another argument having almost the same \
- name makes code comprehension and documentation more difficult",
- arg_name
+ "`{arg_name}` already exists, having another argument having almost the same \
+ name makes code comprehension and documentation more difficult"
),
);
}
diff --git a/src/tools/clippy/clippy_lints/src/misc_early/unneeded_field_pattern.rs b/src/tools/clippy/clippy_lints/src/misc_early/unneeded_field_pattern.rs
index fff533167..676e5d40b 100644
--- a/src/tools/clippy/clippy_lints/src/misc_early/unneeded_field_pattern.rs
+++ b/src/tools/clippy/clippy_lints/src/misc_early/unneeded_field_pattern.rs
@@ -27,7 +27,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) {
pat.span,
"all the struct fields are matched to a wildcard pattern, consider using `..`",
None,
- &format!("try with `{} {{ .. }}` instead", type_name),
+ &format!("try with `{type_name} {{ .. }}` instead"),
);
return;
}
@@ -63,7 +63,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) {
"you matched a field with a wildcard pattern, consider using `..` \
instead",
None,
- &format!("try with `{} {{ {}, .. }}`", type_name, normal[..].join(", ")),
+ &format!("try with `{type_name} {{ {}, .. }}`", normal[..].join(", ")),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/misc_early/zero_prefixed_literal.rs b/src/tools/clippy/clippy_lints/src/misc_early/zero_prefixed_literal.rs
index 4963bba82..9ead43ea4 100644
--- a/src/tools/clippy/clippy_lints/src/misc_early/zero_prefixed_literal.rs
+++ b/src/tools/clippy/clippy_lints/src/misc_early/zero_prefixed_literal.rs
@@ -6,6 +6,7 @@ use rustc_lint::EarlyContext;
use super::ZERO_PREFIXED_LITERAL;
pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str) {
+ let trimmed_lit_snip = lit_snip.trim_start_matches(|c| c == '_' || c == '0');
span_lint_and_then(
cx,
ZERO_PREFIXED_LITERAL,
@@ -15,15 +16,18 @@ pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str) {
diag.span_suggestion(
lit.span,
"if you mean to use a decimal constant, remove the `0` to avoid confusion",
- lit_snip.trim_start_matches(|c| c == '_' || c == '0').to_string(),
- Applicability::MaybeIncorrect,
- );
- diag.span_suggestion(
- lit.span,
- "if you mean to use an octal constant, use `0o`",
- format!("0o{}", lit_snip.trim_start_matches(|c| c == '_' || c == '0')),
+ trimmed_lit_snip.to_string(),
Applicability::MaybeIncorrect,
);
+ // do not advise to use octal form if the literal cannot be expressed in base 8.
+ if !lit_snip.contains(|c| c == '8' || c == '9') {
+ diag.span_suggestion(
+ lit.span,
+ "if you mean to use an octal constant, use `0o`",
+ format!("0o{trimmed_lit_snip}"),
+ Applicability::MaybeIncorrect,
+ );
+ }
},
);
}
diff --git a/src/tools/clippy/clippy_lints/src/mismatching_type_param_order.rs b/src/tools/clippy/clippy_lints/src/mismatching_type_param_order.rs
index 020efeaeb..9de4b56b7 100644
--- a/src/tools/clippy/clippy_lints/src/mismatching_type_param_order.rs
+++ b/src/tools/clippy/clippy_lints/src/mismatching_type_param_order.rs
@@ -70,9 +70,8 @@ impl<'tcx> LateLintPass<'tcx> for TypeParamMismatch {
// find the type that the Impl is for
// only lint on struct/enum/union for now
- let defid = match path.res {
- Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union, defid) => defid,
- _ => return,
+ let Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union, defid) = path.res else {
+ return
};
// get the names of the generic parameters in the type
@@ -91,10 +90,9 @@ impl<'tcx> LateLintPass<'tcx> for TypeParamMismatch {
let type_name = segment.ident;
for (i, (impl_param_name, impl_param_span)) in impl_params.iter().enumerate() {
if mismatch_param_name(i, impl_param_name, &type_param_names_hashmap) {
- let msg = format!("`{}` has a similarly named generic type parameter `{}` in its declaration, but in a different order",
- type_name, impl_param_name);
- let help = format!("try `{}`, or a name that does not conflict with `{}`'s generic params",
- type_param_names[i], type_name);
+ let msg = format!("`{type_name}` has a similarly named generic type parameter `{impl_param_name}` in its declaration, but in a different order");
+ let help = format!("try `{}`, or a name that does not conflict with `{type_name}`'s generic params",
+ type_param_names[i]);
span_lint_and_help(
cx,
MISMATCHING_TYPE_PARAM_ORDER,
diff --git a/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs b/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs
index bc304c081..71cc0d0a8 100644
--- a/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs
+++ b/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs
@@ -8,12 +8,12 @@ use rustc_hir as hir;
use rustc_hir::def_id::CRATE_DEF_ID;
use rustc_hir::intravisit::FnKind;
use rustc_hir::{Body, Constness, FnDecl, GenericParamKind, HirId};
+use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_semver::RustcVersion;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::Span;
-use rustc_typeck::hir_ty_to_ty;
declare_clippy_lint! {
/// ### What it does
@@ -136,7 +136,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
// Const fns are not allowed as methods in a trait.
{
- let parent = cx.tcx.hir().get_parent_item(hir_id);
+ let parent = cx.tcx.hir().get_parent_item(hir_id).def_id;
if parent != CRATE_DEF_ID {
if let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent) {
if let hir::ItemKind::Trait(..) = &item.kind {
diff --git a/src/tools/clippy/clippy_lints/src/missing_doc.rs b/src/tools/clippy/clippy_lints/src/missing_doc.rs
index 3701fdb4a..2a63681db 100644
--- a/src/tools/clippy/clippy_lints/src/missing_doc.rs
+++ b/src/tools/clippy/clippy_lints/src/missing_doc.rs
@@ -103,7 +103,7 @@ impl MissingDoc {
cx,
MISSING_DOCS_IN_PRIVATE_ITEMS,
sp,
- &format!("missing documentation for {} {}", article, desc),
+ &format!("missing documentation for {article} {desc}"),
);
}
}
@@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
hir::ItemKind::Fn(..) => {
// ignore main()
if it.ident.name == sym::main {
- let at_root = cx.tcx.local_parent(it.def_id) == CRATE_DEF_ID;
+ let at_root = cx.tcx.local_parent(it.owner_id.def_id) == CRATE_DEF_ID;
if at_root {
return;
}
@@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
| hir::ItemKind::Use(..) => return,
};
- let (article, desc) = cx.tcx.article_and_description(it.def_id.to_def_id());
+ let (article, desc) = cx.tcx.article_and_description(it.owner_id.to_def_id());
let attrs = cx.tcx.hir().attrs(it.hir_id());
if !is_from_proc_macro(cx, it) {
@@ -164,7 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
}
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) {
- let (article, desc) = cx.tcx.article_and_description(trait_item.def_id.to_def_id());
+ let (article, desc) = cx.tcx.article_and_description(trait_item.owner_id.to_def_id());
let attrs = cx.tcx.hir().attrs(trait_item.hir_id());
if !is_from_proc_macro(cx, trait_item) {
@@ -174,7 +174,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
// If the method is an impl for a trait, don't doc.
- if let Some(cid) = cx.tcx.associated_item(impl_item.def_id).impl_container(cx.tcx) {
+ if let Some(cid) = cx.tcx.associated_item(impl_item.owner_id).impl_container(cx.tcx) {
if cx.tcx.impl_trait_ref(cid).is_some() {
return;
}
@@ -182,7 +182,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
return;
}
- let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id());
+ let (article, desc) = cx.tcx.article_and_description(impl_item.owner_id.to_def_id());
let attrs = cx.tcx.hir().attrs(impl_item.hir_id());
if !is_from_proc_macro(cx, impl_item) {
self.check_missing_docs_attrs(cx, attrs, impl_item.span, article, desc);
diff --git a/src/tools/clippy/clippy_lints/src/missing_enforced_import_rename.rs b/src/tools/clippy/clippy_lints/src/missing_enforced_import_rename.rs
index 3d0a23822..872679f25 100644
--- a/src/tools/clippy/clippy_lints/src/missing_enforced_import_rename.rs
+++ b/src/tools/clippy/clippy_lints/src/missing_enforced_import_rename.rs
@@ -58,7 +58,8 @@ impl_lint_pass!(ImportRename => [MISSING_ENFORCED_IMPORT_RENAMES]);
impl LateLintPass<'_> for ImportRename {
fn check_crate(&mut self, cx: &LateContext<'_>) {
for Rename { path, rename } in &self.conf_renames {
- if let Res::Def(_, id) = clippy_utils::def_path_res(cx, &path.split("::").collect::<Vec<_>>()) {
+ let segs = path.split("::").collect::<Vec<_>>();
+ if let Res::Def(_, id) = clippy_utils::def_path_res(cx, &segs, None) {
self.renames.insert(id, Symbol::intern(rename));
}
}
@@ -90,9 +91,7 @@ impl LateLintPass<'_> for ImportRename {
"this import should be renamed",
"try",
format!(
- "{} as {}",
- import,
- name,
+ "{import} as {name}",
),
Applicability::MachineApplicable,
);
diff --git a/src/tools/clippy/clippy_lints/src/missing_inline.rs b/src/tools/clippy/clippy_lints/src/missing_inline.rs
index 07bc2ca5d..758ce47cf 100644
--- a/src/tools/clippy/clippy_lints/src/missing_inline.rs
+++ b/src/tools/clippy/clippy_lints/src/missing_inline.rs
@@ -65,7 +65,7 @@ fn check_missing_inline_attrs(cx: &LateContext<'_>, attrs: &[ast::Attribute], sp
cx,
MISSING_INLINE_IN_PUBLIC_ITEMS,
sp,
- &format!("missing `#[inline]` for {}", desc),
+ &format!("missing `#[inline]` for {desc}"),
);
}
}
@@ -88,7 +88,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
return;
}
- if !cx.access_levels.is_exported(it.def_id) {
+ if !cx.effective_visibilities.is_exported(it.owner_id.def_id) {
return;
}
match it.kind {
@@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
match tit_.kind {
hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {},
hir::TraitItemKind::Fn(..) => {
- if cx.tcx.impl_defaultness(tit.id.def_id).has_value() {
+ if cx.tcx.impl_defaultness(tit.id.owner_id).has_value() {
// trait method with default body needs inline in case
// an impl is not provided
let desc = "a default trait method";
@@ -142,16 +142,16 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
}
// If the item being implemented is not exported, then we don't need #[inline]
- if !cx.access_levels.is_exported(impl_item.def_id) {
+ if !cx.effective_visibilities.is_exported(impl_item.owner_id.def_id) {
return;
}
let desc = match impl_item.kind {
hir::ImplItemKind::Fn(..) => "a method",
- hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return,
+ hir::ImplItemKind::Const(..) | hir::ImplItemKind::Type(_) => return,
};
- let assoc_item = cx.tcx.associated_item(impl_item.def_id);
+ let assoc_item = cx.tcx.associated_item(impl_item.owner_id);
let container_id = assoc_item.container_id(cx.tcx);
let trait_def_id = match assoc_item.container {
TraitContainer => Some(container_id),
@@ -159,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
};
if let Some(trait_def_id) = trait_def_id {
- if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.def_id) {
+ if trait_def_id.is_local() && !cx.effective_visibilities.is_exported(impl_item.owner_id.def_id) {
// If a trait is being implemented for an item, and the
// trait is not exported, we don't need #[inline]
return;
diff --git a/src/tools/clippy/clippy_lints/src/missing_trait_methods.rs b/src/tools/clippy/clippy_lints/src/missing_trait_methods.rs
new file mode 100644
index 000000000..68af8a672
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/missing_trait_methods.rs
@@ -0,0 +1,98 @@
+use clippy_utils::diagnostics::span_lint_and_help;
+use clippy_utils::is_lint_allowed;
+use clippy_utils::macros::span_is_local;
+use rustc_hir::def_id::DefIdMap;
+use rustc_hir::{Impl, Item, ItemKind};
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::ty::AssocItem;
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks if a provided method is used implicitly by a trait
+ /// implementation. A usage example would be a wrapper where every method
+ /// should perform some operation before delegating to the inner type's
+ /// implemenation.
+ ///
+ /// This lint should typically be enabled on a specific trait `impl` item
+ /// rather than globally.
+ ///
+ /// ### Why is this bad?
+ /// Indicates that a method is missing.
+ ///
+ /// ### Example
+ /// ```rust
+ /// trait Trait {
+ /// fn required();
+ ///
+ /// fn provided() {}
+ /// }
+ ///
+ /// # struct Type;
+ /// #[warn(clippy::missing_trait_methods)]
+ /// impl Trait for Type {
+ /// fn required() { /* ... */ }
+ /// }
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// trait Trait {
+ /// fn required();
+ ///
+ /// fn provided() {}
+ /// }
+ ///
+ /// # struct Type;
+ /// #[warn(clippy::missing_trait_methods)]
+ /// impl Trait for Type {
+ /// fn required() { /* ... */ }
+ ///
+ /// fn provided() { /* ... */ }
+ /// }
+ /// ```
+ #[clippy::version = "1.66.0"]
+ pub MISSING_TRAIT_METHODS,
+ restriction,
+ "trait implementation uses default provided method"
+}
+declare_lint_pass!(MissingTraitMethods => [MISSING_TRAIT_METHODS]);
+
+impl<'tcx> LateLintPass<'tcx> for MissingTraitMethods {
+ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
+ if !is_lint_allowed(cx, MISSING_TRAIT_METHODS, item.hir_id())
+ && span_is_local(item.span)
+ && let ItemKind::Impl(Impl {
+ items,
+ of_trait: Some(trait_ref),
+ ..
+ }) = item.kind
+ && let Some(trait_id) = trait_ref.trait_def_id()
+ {
+ let mut provided: DefIdMap<&AssocItem> = cx
+ .tcx
+ .provided_trait_methods(trait_id)
+ .map(|assoc| (assoc.def_id, assoc))
+ .collect();
+
+ for impl_item in *items {
+ if let Some(def_id) = impl_item.trait_item_def_id {
+ provided.remove(&def_id);
+ }
+ }
+
+ for assoc in provided.values() {
+ let source_map = cx.tcx.sess.source_map();
+ let definition_span = source_map.guess_head_span(cx.tcx.def_span(assoc.def_id));
+
+ span_lint_and_help(
+ cx,
+ MISSING_TRAIT_METHODS,
+ source_map.guess_head_span(item.span),
+ &format!("missing trait method provided by default: `{}`", assoc.name),
+ Some(definition_span),
+ "implement the method",
+ );
+ }
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/mixed_read_write_in_expression.rs b/src/tools/clippy/clippy_lints/src/mixed_read_write_in_expression.rs
index a2419c277..675297634 100644
--- a/src/tools/clippy/clippy_lints/src/mixed_read_write_in_expression.rs
+++ b/src/tools/clippy/clippy_lints/src/mixed_read_write_in_expression.rs
@@ -190,10 +190,7 @@ fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) {
if parent_id == cur_id {
break;
}
- let parent_node = match map.find(parent_id) {
- Some(parent) => parent,
- None => break,
- };
+ let Some(parent_node) = map.find(parent_id) else { break };
let stop_early = match parent_node {
Node::Expr(expr) => check_expr(vis, expr),
diff --git a/src/tools/clippy/clippy_lints/src/module_style.rs b/src/tools/clippy/clippy_lints/src/module_style.rs
index 0a3936572..0742943df 100644
--- a/src/tools/clippy/clippy_lints/src/module_style.rs
+++ b/src/tools/clippy/clippy_lints/src/module_style.rs
@@ -2,7 +2,7 @@ use rustc_ast::ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext};
use rustc_session::{declare_tool_lint, impl_lint_pass};
-use rustc_span::{FileName, RealFileName, SourceFile, Span, SyntaxContext};
+use rustc_span::{FileName, SourceFile, Span, SyntaxContext};
use std::ffi::OsStr;
use std::path::{Component, Path};
@@ -79,7 +79,7 @@ impl EarlyLintPass for ModStyle {
let files = cx.sess().source_map().files();
- let RealFileName::LocalPath(trim_to_src) = &cx.sess().opts.working_dir else { return };
+ let Some(trim_to_src) = cx.sess().opts.working_dir.local_path() else { return };
// `folder_segments` is all unique folder path segments `path/to/foo.rs` gives
// `[path, to]` but not foo
@@ -90,7 +90,7 @@ impl EarlyLintPass for ModStyle {
// `{ foo => path/to/foo.rs, .. }
let mut file_map = FxHashMap::default();
for file in files.iter() {
- if let FileName::Real(RealFileName::LocalPath(lp)) = &file.name {
+ if let FileName::Real(name) = &file.name && let Some(lp) = name.local_path() {
let path = if lp.is_relative() {
lp
} else if let Ok(relative) = lp.strip_prefix(trim_to_src) {
@@ -117,12 +117,8 @@ impl EarlyLintPass for ModStyle {
cx.struct_span_lint(
SELF_NAMED_MODULE_FILES,
Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None),
- |build| {
- let mut lint =
- build.build(&format!("`mod.rs` files are required, found `{}`", path.display()));
- lint.help(&format!("move `{}` to `{}`", path.display(), correct.display(),));
- lint.emit();
- },
+ format!("`mod.rs` files are required, found `{}`", path.display()),
+ |lint| lint.help(format!("move `{}` to `{}`", path.display(), correct.display(),)),
);
}
}
@@ -156,11 +152,8 @@ fn check_self_named_mod_exists(cx: &EarlyContext<'_>, path: &Path, file: &Source
cx.struct_span_lint(
MOD_MODULE_FILES,
Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None),
- |build| {
- let mut lint = build.build(&format!("`mod.rs` files are not allowed, found `{}`", path.display()));
- lint.help(&format!("move `{}` to `{}`", path.display(), mod_file.display(),));
- lint.emit();
- },
+ format!("`mod.rs` files are not allowed, found `{}`", path.display()),
+ |lint| lint.help(format!("move `{}` to `{}`", path.display(), mod_file.display())),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/mut_key.rs b/src/tools/clippy/clippy_lints/src/mut_key.rs
index 4db103bbc..4b62dcdff 100644
--- a/src/tools/clippy/clippy_lints/src/mut_key.rs
+++ b/src/tools/clippy/clippy_lints/src/mut_key.rs
@@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableKeyType {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) {
if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind {
- if trait_ref_of_method(cx, item.def_id).is_none() {
+ if trait_ref_of_method(cx, item.owner_id.def_id).is_none() {
check_sig(cx, item.hir_id(), sig.decl);
}
}
@@ -136,12 +136,14 @@ fn check_ty<'tcx>(cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) {
/// [`Hash`] or [`Ord`].
fn is_interior_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span) -> bool {
match *ty.kind() {
- Ref(_, inner_ty, mutbl) => mutbl == hir::Mutability::Mut || is_interior_mutable_type(cx, inner_ty, span),
+ Ref(_, inner_ty, mutbl) => {
+ mutbl == hir::Mutability::Mut || is_interior_mutable_type(cx, inner_ty, span)
+ }
Slice(inner_ty) => is_interior_mutable_type(cx, inner_ty, span),
Array(inner_ty, size) => {
size.try_eval_usize(cx.tcx, cx.param_env).map_or(true, |u| u != 0)
&& is_interior_mutable_type(cx, inner_ty, span)
- },
+ }
Tuple(fields) => fields.iter().any(|ty| is_interior_mutable_type(cx, ty, span)),
Adt(def, substs) => {
// Special case for collections in `std` who's impl of `Hash` or `Ord` delegates to
@@ -167,9 +169,9 @@ fn is_interior_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Sp
} else {
!ty.has_escaping_bound_vars()
&& cx.tcx.layout_of(cx.param_env.and(ty)).is_ok()
- && !ty.is_freeze(cx.tcx.at(span), cx.param_env)
+ && !ty.is_freeze(cx.tcx, cx.param_env)
}
- },
+ }
_ => false,
}
}
diff --git a/src/tools/clippy/clippy_lints/src/mut_reference.rs b/src/tools/clippy/clippy_lints/src/mut_reference.rs
index 82dc03ef5..4547ed7ea 100644
--- a/src/tools/clippy/clippy_lints/src/mut_reference.rs
+++ b/src/tools/clippy/clippy_lints/src/mut_reference.rs
@@ -1,7 +1,6 @@
use clippy_utils::diagnostics::span_lint;
use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability};
use rustc_lint::{LateContext, LateLintPass};
-use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, Ty};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use std::iter;
@@ -88,7 +87,7 @@ fn check_arguments<'tcx>(
cx,
UNNECESSARY_MUT_PASSED,
argument.span,
- &format!("the {} `{}` doesn't need a mutable reference", fn_kind, name),
+ &format!("the {fn_kind} `{name}` doesn't need a mutable reference"),
);
}
},
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 44fdf84c6..d8647a991 100644
--- a/src/tools/clippy/clippy_lints/src/mutable_debug_assertion.rs
+++ b/src/tools/clippy/clippy_lints/src/mutable_debug_assertion.rs
@@ -56,10 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for DebugAssertWithMutCall {
cx,
DEBUG_ASSERT_WITH_MUT_CALL,
span,
- &format!(
- "do not call a function with mutable arguments inside of `{}!`",
- macro_name
- ),
+ &format!("do not call a function with mutable arguments inside of `{macro_name}!`"),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/mutex_atomic.rs b/src/tools/clippy/clippy_lints/src/mutex_atomic.rs
index a98577093..09cb53331 100644
--- a/src/tools/clippy/clippy_lints/src/mutex_atomic.rs
+++ b/src/tools/clippy/clippy_lints/src/mutex_atomic.rs
@@ -84,9 +84,8 @@ impl<'tcx> LateLintPass<'tcx> for Mutex {
let mutex_param = subst.type_at(0);
if let Some(atomic_name) = get_atomic_name(mutex_param) {
let msg = format!(
- "consider using an `{}` instead of a `Mutex` here; if you just want the locking \
- behavior and not the internal type, consider using `Mutex<()>`",
- atomic_name
+ "consider using an `{atomic_name}` instead of a `Mutex` here; if you just want the locking \
+ behavior and not the internal type, consider using `Mutex<()>`"
);
match *mutex_param.kind() {
ty::Uint(t) if t != ty::UintTy::Usize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg),
diff --git a/src/tools/clippy/clippy_lints/src/needless_borrowed_ref.rs b/src/tools/clippy/clippy_lints/src/needless_borrowed_ref.rs
index b8855e5ad..10c3ff026 100644
--- a/src/tools/clippy/clippy_lints/src/needless_borrowed_ref.rs
+++ b/src/tools/clippy/clippy_lints/src/needless_borrowed_ref.rs
@@ -1,6 +1,4 @@
use clippy_utils::diagnostics::span_lint_and_then;
-use clippy_utils::source::snippet_with_applicability;
-use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{BindingAnnotation, Mutability, Node, Pat, PatKind};
use rustc_lint::{LateContext, LateLintPass};
@@ -8,36 +6,26 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! {
/// ### What it does
- /// Checks for bindings that destructure a reference and borrow the inner
+ /// Checks for bindings that needlessly destructure a reference and borrow the inner
/// value with `&ref`.
///
/// ### Why is this bad?
/// This pattern has no effect in almost all cases.
///
- /// ### Known problems
- /// In some cases, `&ref` is needed to avoid a lifetime mismatch error.
- /// Example:
- /// ```rust
- /// fn foo(a: &Option<String>, b: &Option<String>) {
- /// match (a, b) {
- /// (None, &ref c) | (&ref c, None) => (),
- /// (&Some(ref c), _) => (),
- /// };
- /// }
- /// ```
- ///
/// ### Example
/// ```rust
/// let mut v = Vec::<String>::new();
- /// # #[allow(unused)]
/// v.iter_mut().filter(|&ref a| a.is_empty());
+ ///
+ /// if let &[ref first, ref second] = v.as_slice() {}
/// ```
///
/// Use instead:
/// ```rust
/// let mut v = Vec::<String>::new();
- /// # #[allow(unused)]
/// v.iter_mut().filter(|a| a.is_empty());
+ ///
+ /// if let [first, second] = v.as_slice() {}
/// ```
#[clippy::version = "pre 1.29.0"]
pub NEEDLESS_BORROWED_REFERENCE,
@@ -54,34 +42,83 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowedRef {
return;
}
- if_chain! {
- // Only lint immutable refs, because `&mut ref T` may be useful.
- if let PatKind::Ref(sub_pat, Mutability::Not) = pat.kind;
+ // Do not lint patterns that are part of an OR `|` pattern, the binding mode must match in all arms
+ for (_, node) in cx.tcx.hir().parent_iter(pat.hir_id) {
+ let Node::Pat(pat) = node else { break };
+
+ if matches!(pat.kind, PatKind::Or(_)) {
+ return;
+ }
+ }
+
+ // Only lint immutable refs, because `&mut ref T` may be useful.
+ let PatKind::Ref(sub_pat, Mutability::Not) = pat.kind else { return };
+ match sub_pat.kind {
// Check sub_pat got a `ref` keyword (excluding `ref mut`).
- if let PatKind::Binding(BindingAnnotation::REF, .., spanned_name, _) = sub_pat.kind;
- let parent_id = cx.tcx.hir().get_parent_node(pat.hir_id);
- if let Some(parent_node) = cx.tcx.hir().find(parent_id);
- then {
- // do not recurse within patterns, as they may have other references
- // XXXManishearth we can relax this constraint if we only check patterns
- // with a single ref pattern inside them
- if let Node::Pat(_) = parent_node {
- return;
+ PatKind::Binding(BindingAnnotation::REF, _, ident, None) => {
+ span_lint_and_then(
+ cx,
+ NEEDLESS_BORROWED_REFERENCE,
+ pat.span,
+ "this pattern takes a reference on something that is being dereferenced",
+ |diag| {
+ // `&ref ident`
+ // ^^^^^
+ let span = pat.span.until(ident.span);
+ diag.span_suggestion_verbose(
+ span,
+ "try removing the `&ref` part",
+ String::new(),
+ Applicability::MachineApplicable,
+ );
+ },
+ );
+ },
+ // Slices where each element is `ref`: `&[ref a, ref b, ..., ref z]`
+ PatKind::Slice(
+ before,
+ None
+ | Some(Pat {
+ kind: PatKind::Wild, ..
+ }),
+ after,
+ ) => {
+ let mut suggestions = Vec::new();
+
+ for element_pat in itertools::chain(before, after) {
+ if let PatKind::Binding(BindingAnnotation::REF, _, ident, None) = element_pat.kind {
+ // `&[..., ref ident, ...]`
+ // ^^^^
+ let span = element_pat.span.until(ident.span);
+ suggestions.push((span, String::new()));
+ } else {
+ return;
+ }
}
- let mut applicability = Applicability::MachineApplicable;
- span_lint_and_then(cx, NEEDLESS_BORROWED_REFERENCE, pat.span,
- "this pattern takes a reference on something that is being de-referenced",
- |diag| {
- let hint = snippet_with_applicability(cx, spanned_name.span, "..", &mut applicability).into_owned();
- diag.span_suggestion(
- pat.span,
- "try removing the `&ref` part and just keep",
- hint,
- applicability,
- );
- });
- }
+
+ if !suggestions.is_empty() {
+ span_lint_and_then(
+ cx,
+ NEEDLESS_BORROWED_REFERENCE,
+ pat.span,
+ "dereferencing a slice pattern where every element takes a reference",
+ |diag| {
+ // `&[...]`
+ // ^
+ let span = pat.span.until(sub_pat.span);
+ suggestions.push((span, String::new()));
+
+ diag.multipart_suggestion(
+ "try removing the `&` and `ref` parts",
+ suggestions,
+ Applicability::MachineApplicable,
+ );
+ },
+ );
+ }
+ },
+ _ => {},
}
}
}
diff --git a/src/tools/clippy/clippy_lints/src/needless_continue.rs b/src/tools/clippy/clippy_lints/src/needless_continue.rs
index 98a3bce1f..6f0e75546 100644
--- a/src/tools/clippy/clippy_lints/src/needless_continue.rs
+++ b/src/tools/clippy/clippy_lints/src/needless_continue.rs
@@ -309,7 +309,7 @@ fn emit_warning<'a>(cx: &EarlyContext<'_>, data: &'a LintData<'_>, header: &str,
expr.span,
message,
None,
- &format!("{}\n{}", header, snip),
+ &format!("{header}\n{snip}"),
);
}
@@ -322,10 +322,7 @@ fn suggestion_snippet_for_continue_inside_if<'a>(cx: &EarlyContext<'_>, data: &'
let indent_if = indent_of(cx, data.if_expr.span).unwrap_or(0);
format!(
- "{indent}if {} {}\n{indent}{}",
- cond_code,
- continue_code,
- else_code,
+ "{indent}if {cond_code} {continue_code}\n{indent}{else_code}",
indent = " ".repeat(indent_if),
)
}
@@ -349,7 +346,7 @@ fn suggestion_snippet_for_continue_inside_else<'a>(cx: &EarlyContext<'_>, data:
let span = cx.sess().source_map().stmt_span(stmt.span, data.loop_block.span);
let snip = snippet_block(cx, span, "..", None).into_owned();
snip.lines()
- .map(|line| format!("{}{}", " ".repeat(indent), line))
+ .map(|line| format!("{}{line}", " ".repeat(indent)))
.collect::<Vec<_>>()
.join("\n")
})
@@ -358,10 +355,7 @@ fn suggestion_snippet_for_continue_inside_else<'a>(cx: &EarlyContext<'_>, data:
let indent_if = indent_of(cx, data.if_expr.span).unwrap_or(0);
format!(
- "{indent_if}if {} {}\n{indent}// merged code follows:\n{}\n{indent_if}}}",
- cond_code,
- block_code,
- to_annex,
+ "{indent_if}if {cond_code} {block_code}\n{indent}// merged code follows:\n{to_annex}\n{indent_if}}}",
indent = " ".repeat(indent),
indent_if = " ".repeat(indent_if),
)
diff --git a/src/tools/clippy/clippy_lints/src/needless_for_each.rs b/src/tools/clippy/clippy_lints/src/needless_for_each.rs
index 3233d87c0..c3b633fd6 100644
--- a/src/tools/clippy/clippy_lints/src/needless_for_each.rs
+++ b/src/tools/clippy/clippy_lints/src/needless_for_each.rs
@@ -49,9 +49,8 @@ declare_lint_pass!(NeedlessForEach => [NEEDLESS_FOR_EACH]);
impl<'tcx> LateLintPass<'tcx> for NeedlessForEach {
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
- let expr = match stmt.kind {
- StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr,
- _ => return,
+ let (StmtKind::Expr(expr) | StmtKind::Semi(expr)) = stmt.kind else {
+ return
};
if_chain! {
diff --git a/src/tools/clippy/clippy_lints/src/needless_late_init.rs b/src/tools/clippy/clippy_lints/src/needless_late_init.rs
index de99f1d70..67debe7e0 100644
--- a/src/tools/clippy/clippy_lints/src/needless_late_init.rs
+++ b/src/tools/clippy/clippy_lints/src/needless_late_init.rs
@@ -2,9 +2,9 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::path_to_local;
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::needs_ordered_drop;
-use clippy_utils::visitors::{expr_visitor, expr_visitor_no_bodies, is_local_used};
+use clippy_utils::visitors::{for_each_expr, for_each_expr_with_closures, is_local_used};
+use core::ops::ControlFlow;
use rustc_errors::{Applicability, MultiSpan};
-use rustc_hir::intravisit::Visitor;
use rustc_hir::{
BindingAnnotation, Block, Expr, ExprKind, HirId, Local, LocalSource, MatchSource, Node, Pat, PatKind, Stmt,
StmtKind,
@@ -64,31 +64,25 @@ declare_clippy_lint! {
declare_lint_pass!(NeedlessLateInit => [NEEDLESS_LATE_INIT]);
fn contains_assign_expr<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'tcx>) -> bool {
- let mut seen = false;
- expr_visitor(cx, |expr| {
- if let ExprKind::Assign(..) = expr.kind {
- seen = true;
+ for_each_expr_with_closures(cx, stmt, |e| {
+ if matches!(e.kind, ExprKind::Assign(..)) {
+ ControlFlow::Break(())
+ } else {
+ ControlFlow::Continue(())
}
-
- !seen
})
- .visit_stmt(stmt);
-
- seen
+ .is_some()
}
fn contains_let(cond: &Expr<'_>) -> bool {
- let mut seen = false;
- expr_visitor_no_bodies(|expr| {
- if let ExprKind::Let(_) = expr.kind {
- seen = true;
+ for_each_expr(cond, |e| {
+ if matches!(e.kind, ExprKind::Let(_)) {
+ ControlFlow::Break(())
+ } else {
+ ControlFlow::Continue(())
}
-
- !seen
})
- .visit_expr(cond);
-
- seen
+ .is_some()
}
fn stmt_needs_ordered_drop(cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool {
@@ -186,10 +180,13 @@ fn assignment_suggestions<'tcx>(
let suggestions = assignments
.iter()
.flat_map(|assignment| {
- [
- assignment.span.until(assignment.rhs_span),
- assignment.rhs_span.shrink_to_hi().with_hi(assignment.span.hi()),
- ]
+ let mut spans = vec![assignment.span.until(assignment.rhs_span)];
+
+ if assignment.rhs_span.hi() != assignment.span.hi() {
+ spans.push(assignment.rhs_span.shrink_to_hi().with_hi(assignment.span.hi()));
+ }
+
+ spans
})
.map(|span| (span, String::new()))
.collect::<Vec<(Span, String)>>();
@@ -287,7 +284,7 @@ fn check<'tcx>(
diag.span_suggestion(
assign.lhs_span,
- &format!("declare `{}` here", binding_name),
+ &format!("declare `{binding_name}` here"),
let_snippet,
Applicability::MachineApplicable,
);
@@ -307,8 +304,8 @@ fn check<'tcx>(
diag.span_suggestion_verbose(
usage.stmt.span.shrink_to_lo(),
- &format!("declare `{}` here", binding_name),
- format!("{} = ", let_snippet),
+ &format!("declare `{binding_name}` here"),
+ format!("{let_snippet} = "),
applicability,
);
@@ -338,8 +335,8 @@ fn check<'tcx>(
diag.span_suggestion_verbose(
usage.stmt.span.shrink_to_lo(),
- &format!("declare `{}` here", binding_name),
- format!("{} = ", let_snippet),
+ &format!("declare `{binding_name}` here"),
+ format!("{let_snippet} = "),
applicability,
);
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 060037ed4..b2e9ce5c9 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
@@ -12,6 +12,7 @@ use rustc_hir::{
BindingAnnotation, Body, FnDecl, GenericArg, HirId, Impl, ItemKind, Mutability, Node, PatKind, QPath, TyKind,
};
use rustc_hir::{HirIdMap, HirIdSet};
+use rustc_hir_typeck::expr_use_visitor as euv;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir::FakeReadCause;
@@ -22,7 +23,6 @@ use rustc_span::{sym, Span};
use rustc_target::spec::abi::Abi;
use rustc_trait_selection::traits;
use rustc_trait_selection::traits::misc::can_type_implement_copy;
-use rustc_typeck::expr_use_visitor as euv;
use std::borrow::Cow;
declare_clippy_lint! {
@@ -138,10 +138,8 @@ impl<'tcx> LateLintPass<'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.typeck_results())
- .consume_body(body);
- });
+ let infcx = cx.tcx.infer_ctxt().build();
+ euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
ctx
};
@@ -186,6 +184,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
if !is_self(arg);
if !ty.is_mutable_ptr();
if !is_copy(cx, ty);
+ if ty.is_sized(cx.tcx, cx.param_env);
if !allowed_traits.iter().any(|&t| implements_trait(cx, ty, t, &[]));
if !implements_borrow_trait;
if !all_borrowable_trait;
@@ -236,7 +235,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
snippet_opt(cx, span)
.map_or(
"change the call to".into(),
- |x| Cow::from(format!("change `{}` to", x)),
+ |x| Cow::from(format!("change `{x}` to")),
)
.as_ref(),
suggestion,
@@ -266,7 +265,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
snippet_opt(cx, span)
.map_or(
"change the call to".into(),
- |x| Cow::from(format!("change `{}` to", x))
+ |x| Cow::from(format!("change `{x}` to"))
)
.as_ref(),
suggestion,
@@ -341,5 +340,11 @@ impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt {
fn mutate(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId) {}
- fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {}
+ fn fake_read(
+ &mut self,
+ _: &rustc_hir_typeck::expr_use_visitor::PlaceWithHirId<'tcx>,
+ _: FakeReadCause,
+ _: HirId,
+ ) {
+ }
}
diff --git a/src/tools/clippy/clippy_lints/src/needless_question_mark.rs b/src/tools/clippy/clippy_lints/src/needless_question_mark.rs
index 8f85b0059..97c8cfbd3 100644
--- a/src/tools/clippy/clippy_lints/src/needless_question_mark.rs
+++ b/src/tools/clippy/clippy_lints/src/needless_question_mark.rs
@@ -1,11 +1,12 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
-use clippy_utils::is_lang_ctor;
+use clippy_utils::path_res;
use clippy_utils::source::snippet;
use if_chain::if_chain;
use rustc_errors::Applicability;
-use rustc_hir::LangItem::{OptionSome, ResultOk};
+use rustc_hir::def::{DefKind, Res};
use rustc_hir::{AsyncGeneratorKind, Block, Body, Expr, ExprKind, GeneratorKind, LangItem, MatchSource, QPath};
use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::ty::DefIdTree;
use rustc_session::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! {
@@ -112,11 +113,12 @@ impl LateLintPass<'_> for NeedlessQuestionMark {
fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
if_chain! {
- if let ExprKind::Call(path, [arg]) = &expr.kind;
- if let ExprKind::Path(ref qpath) = &path.kind;
- let sugg_remove = if is_lang_ctor(cx, qpath, OptionSome) {
+ if let ExprKind::Call(path, [arg]) = expr.kind;
+ if let Res::Def(DefKind::Ctor(..), ctor_id) = path_res(cx, path);
+ if let Some(variant_id) = cx.tcx.opt_parent(ctor_id);
+ let sugg_remove = if cx.tcx.lang_items().option_some_variant() == Some(variant_id) {
"Some()"
- } else if is_lang_ctor(cx, qpath, ResultOk) {
+ } else if cx.tcx.lang_items().result_ok_variant() == Some(variant_id) {
"Ok()"
} else {
return;
@@ -134,7 +136,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
NEEDLESS_QUESTION_MARK,
expr.span,
"question mark operator is useless here",
- &format!("try removing question mark and `{}`", sugg_remove),
+ &format!("try removing question mark and `{sugg_remove}`"),
format!("{}", snippet(cx, inner_expr.span, r#""...""#)),
Applicability::MachineApplicable,
);
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 a7e0e3578..5c2b96f5b 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
@@ -1,11 +1,11 @@
use clippy_utils::diagnostics::span_lint;
use clippy_utils::ty::implements_trait;
-use clippy_utils::{self, get_trait_def_id, paths};
use if_chain::if_chain;
use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::sym;
declare_clippy_lint! {
/// ### What it does
@@ -47,18 +47,16 @@ declare_lint_pass!(NoNegCompOpForPartialOrd => [NEG_CMP_OP_ON_PARTIAL_ORD]);
impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! {
-
if !in_external_macro(cx.sess(), expr.span);
if let ExprKind::Unary(UnOp::Not, inner) = expr.kind;
if let ExprKind::Binary(ref op, left, _) = inner.kind;
if let BinOpKind::Le | BinOpKind::Ge | BinOpKind::Lt | BinOpKind::Gt = op.node;
then {
-
let ty = cx.typeck_results().expr_ty(left);
let implements_ord = {
- if let Some(id) = get_trait_def_id(cx, &paths::ORD) {
+ if let Some(id) = cx.tcx.get_diagnostic_item(sym::Ord) {
implements_trait(cx, ty, id, &[])
} else {
return;
@@ -81,7 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for NoNegCompOpForPartialOrd {
"the use of negated comparison operators on partially ordered \
types produces code that is hard to read and refactor, please \
consider using the `partial_cmp` method instead, to make it \
- clear that the two values could be incomparable"
+ clear that the two values could be incomparable",
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/neg_multiply.rs b/src/tools/clippy/clippy_lints/src/neg_multiply.rs
index b087cfb36..fb9a4abd0 100644
--- a/src/tools/clippy/clippy_lints/src/neg_multiply.rs
+++ b/src/tools/clippy/clippy_lints/src/neg_multiply.rs
@@ -62,9 +62,9 @@ fn check_mul(cx: &LateContext<'_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) {
let mut applicability = Applicability::MachineApplicable;
let snip = snippet_with_applicability(cx, exp.span, "..", &mut applicability);
let suggestion = if exp.precedence().order() < PREC_PREFIX && !has_enclosing_paren(&snip) {
- format!("-({})", snip)
+ format!("-({snip})")
} else {
- format!("-{}", snip)
+ format!("-{snip}")
};
span_lint_and_sugg(
cx,
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 5c45ee6d9..54a3c82b7 100644
--- a/src/tools/clippy/clippy_lints/src/new_without_default.rs
+++ b/src/tools/clippy/clippy_lints/src/new_without_default.rs
@@ -84,7 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
// can't be implemented for unsafe new
return;
}
- if cx.tcx.is_doc_hidden(impl_item.def_id) {
+ if cx.tcx.is_doc_hidden(impl_item.owner_id.def_id) {
// shouldn't be implemented when it is hidden in docs
return;
}
@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
if_chain! {
if sig.decl.inputs.is_empty();
if name == sym::new;
- if cx.access_levels.is_reachable(impl_item.def_id);
+ if cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id);
let self_def_id = cx.tcx.hir().get_parent_item(id);
let self_ty = cx.tcx.type_of(self_def_id);
if self_ty == return_ty(cx, id);
@@ -136,8 +136,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
id,
impl_item.span,
&format!(
- "you should consider adding a `Default` implementation for `{}`",
- self_type_snip
+ "you should consider adding a `Default` implementation for `{self_type_snip}`"
),
|diag| {
diag.suggest_prepend_item(
@@ -161,9 +160,9 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
fn create_new_without_default_suggest_msg(self_type_snip: &str, generics_sugg: &str) -> String {
#[rustfmt::skip]
format!(
-"impl{} Default for {} {{
+"impl{generics_sugg} Default for {self_type_snip} {{
fn default() -> Self {{
Self::new()
}}
-}}", generics_sugg, self_type_snip)
+}}")
}
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 72c86f28b..2a3bd4ee6 100644
--- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs
+++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs
@@ -13,14 +13,14 @@ use rustc_hir::def_id::DefId;
use rustc_hir::{
BodyId, Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp,
};
+use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::{LateContext, LateLintPass, Lint};
use rustc_middle::mir;
use rustc_middle::mir::interpret::{ConstValue, ErrorHandled};
use rustc_middle::ty::adjustment::Adjust;
use rustc_middle::ty::{self, Ty};
use rustc_session::{declare_lint_pass, declare_tool_lint};
-use rustc_span::{sym, InnerSpan, Span, DUMMY_SP};
-use rustc_typeck::hir_ty_to_ty;
+use rustc_span::{sym, InnerSpan, Span};
// FIXME: this is a correctness problem but there's no suitable
// warn-by-default category.
@@ -136,7 +136,7 @@ fn is_unfrozen<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
// since it works when a pointer indirection involves (`Cell<*const T>`).
// Making up a `ParamEnv` where every generic params and assoc types are `Freeze`is another option;
// but I'm not sure whether it's a decent way, if possible.
- cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() && !ty.is_freeze(cx.tcx.at(DUMMY_SP), cx.param_env)
+ cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() && !ty.is_freeze(cx.tcx, cx.param_env)
}
fn is_value_unfrozen_raw<'tcx>(
@@ -149,6 +149,9 @@ fn is_value_unfrozen_raw<'tcx>(
// the fact that we have to dig into every structs to search enums
// leads us to the point checking `UnsafeCell` directly is the only option.
ty::Adt(ty_def, ..) if ty_def.is_unsafe_cell() => true,
+ // As of 2022-09-08 miri doesn't track which union field is active so there's no safe way to check the
+ // contained value.
+ ty::Adt(def, ..) if def.is_union() => false,
ty::Array(..) | ty::Adt(..) | ty::Tuple(..) => {
let val = cx.tcx.destructure_mir_constant(cx.param_env, val);
val.fields.iter().any(|field| inner(cx, *field))
@@ -195,7 +198,7 @@ fn is_value_unfrozen_expr<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId, def_id: D
let result = cx.tcx.const_eval_resolve(
cx.param_env,
- ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs),
+ mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs),
None,
);
is_value_unfrozen_raw(cx, result, ty)
@@ -286,7 +289,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) {
if let ImplItemKind::Const(hir_ty, body_id) = &impl_item.kind {
- let item_def_id = cx.tcx.hir().get_parent_item(impl_item.hir_id());
+ let item_def_id = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
let item = cx.tcx.hir().expect_item(item_def_id);
match &item.kind {
@@ -300,7 +303,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
if let Some(of_trait_def_id) = of_trait_ref.trait_def_id();
if let Some(of_assoc_item) = cx
.tcx
- .associated_item(impl_item.def_id)
+ .associated_item(impl_item.owner_id)
.trait_item_def_id;
if cx
.tcx
@@ -354,9 +357,8 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
}
// Make sure it is a const item.
- let item_def_id = match cx.qpath_res(qpath, expr.hir_id) {
- Res::Def(DefKind::Const | DefKind::AssocConst, did) => did,
- _ => return,
+ let Res::Def(DefKind::Const | DefKind::AssocConst, item_def_id) = cx.qpath_res(qpath, expr.hir_id) else {
+ return
};
// Climb up to resolve any field access and explicit referencing.
diff --git a/src/tools/clippy/clippy_lints/src/non_expressive_names.rs b/src/tools/clippy/clippy_lints/src/non_expressive_names.rs
index b96af06b8..9f6917c14 100644
--- a/src/tools/clippy/clippy_lints/src/non_expressive_names.rs
+++ b/src/tools/clippy/clippy_lints/src/non_expressive_names.rs
@@ -15,6 +15,10 @@ declare_clippy_lint! {
/// ### What it does
/// Checks for names that are very similar and thus confusing.
///
+ /// Note: this lint looks for similar names throughout each
+ /// scope. To allow it, you need to allow it on the scope
+ /// level, not on the name that is reported.
+ ///
/// ### Why is this bad?
/// It's hard to distinguish between names that differ only
/// by a single character.
@@ -108,10 +112,7 @@ impl<'a, 'tcx> SimilarNamesLocalVisitor<'a, 'tcx> {
self.cx,
MANY_SINGLE_CHAR_NAMES,
span,
- &format!(
- "{} bindings with single-character names in scope",
- num_single_char_names
- ),
+ &format!("{num_single_char_names} bindings with single-character names in scope"),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/non_octal_unix_permissions.rs b/src/tools/clippy/clippy_lints/src/non_octal_unix_permissions.rs
index 25fb4f0f4..2ecb04874 100644
--- a/src/tools/clippy/clippy_lints/src/non_octal_unix_permissions.rs
+++ b/src/tools/clippy/clippy_lints/src/non_octal_unix_permissions.rs
@@ -1,12 +1,13 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::{snippet_opt, snippet_with_applicability};
-use clippy_utils::ty::match_type;
+use clippy_utils::ty::{is_type_diagnostic_item, match_type};
use clippy_utils::{match_def_path, paths};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::sym;
declare_clippy_lint! {
/// ### What it does
@@ -49,14 +50,13 @@ impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions {
if_chain! {
if (path.ident.name == sym!(mode)
&& (match_type(cx, obj_ty, &paths::OPEN_OPTIONS)
- || match_type(cx, obj_ty, &paths::DIR_BUILDER)))
+ || is_type_diagnostic_item(cx, obj_ty, sym::DirBuilder)))
|| (path.ident.name == sym!(set_mode) && match_type(cx, obj_ty, &paths::PERMISSIONS));
if let ExprKind::Lit(_) = param.kind;
then {
- let snip = match snippet_opt(cx, param.span) {
- Some(s) => s,
- _ => return,
+ let Some(snip) = snippet_opt(cx, param.span) else {
+ return
};
if !snip.starts_with("0o") {
@@ -71,16 +71,10 @@ impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions {
if let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id();
if match_def_path(cx, def_id, &paths::PERMISSIONS_FROM_MODE);
if let ExprKind::Lit(_) = param.kind;
-
+ if let Some(snip) = snippet_opt(cx, param.span);
+ if !snip.starts_with("0o");
then {
- let snip = match snippet_opt(cx, param.span) {
- Some(s) => s,
- _ => return,
- };
-
- if !snip.starts_with("0o") {
- show_error(cx, param);
- }
+ show_error(cx, param);
}
}
},
diff --git a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs
index ddef7352d..714c0ff22 100644
--- a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs
+++ b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs
@@ -89,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
if let Some(trait_id) = trait_ref.trait_def_id();
if send_trait == trait_id;
if hir_impl.polarity == ImplPolarity::Positive;
- if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.def_id);
+ if let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id);
if let self_ty = ty_trait_ref.self_ty();
if let ty::Adt(adt_def, impl_trait_substs) = self_ty.kind();
then {
diff --git a/src/tools/clippy/clippy_lints/src/nonstandard_macro_braces.rs b/src/tools/clippy/clippy_lints/src/nonstandard_macro_braces.rs
index 4722c0310..6c909e5ed 100644
--- a/src/tools/clippy/clippy_lints/src/nonstandard_macro_braces.rs
+++ b/src/tools/clippy/clippy_lints/src/nonstandard_macro_braces.rs
@@ -3,16 +3,17 @@ use std::{
hash::{Hash, Hasher},
};
-use clippy_utils::diagnostics::span_lint_and_help;
+use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_opt;
use if_chain::if_chain;
use rustc_ast::ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
+use rustc_errors::Applicability;
use rustc_hir::def_id::DefId;
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::hygiene::{ExpnKind, MacroKind};
-use rustc_span::{Span, Symbol};
+use rustc_span::Span;
use serde::{de, Deserialize};
declare_clippy_lint! {
@@ -39,8 +40,8 @@ declare_clippy_lint! {
const BRACES: &[(&str, &str)] = &[("(", ")"), ("{", "}"), ("[", "]")];
-/// The (name, (open brace, close brace), source snippet)
-type MacroInfo<'a> = (Symbol, &'a (String, String), String);
+/// The (callsite span, (open brace, close brace), source snippet)
+type MacroInfo<'a> = (Span, &'a (String, String), String);
#[derive(Clone, Debug, Default)]
pub struct MacroBraces {
@@ -62,33 +63,29 @@ impl_lint_pass!(MacroBraces => [NONSTANDARD_MACRO_BRACES]);
impl EarlyLintPass for MacroBraces {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
- if let Some((name, braces, snip)) = is_offending_macro(cx, item.span, self) {
- let span = item.span.ctxt().outer_expn_data().call_site;
- emit_help(cx, snip, braces, name, span);
+ if let Some((span, braces, snip)) = is_offending_macro(cx, item.span, self) {
+ emit_help(cx, &snip, braces, span);
self.done.insert(span);
}
}
fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &ast::Stmt) {
- if let Some((name, braces, snip)) = is_offending_macro(cx, stmt.span, self) {
- let span = stmt.span.ctxt().outer_expn_data().call_site;
- emit_help(cx, snip, braces, name, span);
+ if let Some((span, braces, snip)) = is_offending_macro(cx, stmt.span, self) {
+ emit_help(cx, &snip, braces, span);
self.done.insert(span);
}
}
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
- if let Some((name, braces, snip)) = is_offending_macro(cx, expr.span, self) {
- let span = expr.span.ctxt().outer_expn_data().call_site;
- emit_help(cx, snip, braces, name, span);
+ if let Some((span, braces, snip)) = is_offending_macro(cx, expr.span, self) {
+ emit_help(cx, &snip, braces, span);
self.done.insert(span);
}
}
fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
- if let Some((name, braces, snip)) = is_offending_macro(cx, ty.span, self) {
- let span = ty.span.ctxt().outer_expn_data().call_site;
- emit_help(cx, snip, braces, name, span);
+ if let Some((span, braces, snip)) = is_offending_macro(cx, ty.span, self) {
+ emit_help(cx, &snip, braces, span);
self.done.insert(span);
}
}
@@ -102,48 +99,44 @@ fn is_offending_macro<'a>(cx: &EarlyContext<'_>, span: Span, mac_braces: &'a Mac
.last()
.map_or(false, |e| e.macro_def_id.map_or(false, DefId::is_local))
};
+ let span_call_site = span.ctxt().outer_expn_data().call_site;
if_chain! {
if let ExpnKind::Macro(MacroKind::Bang, mac_name) = span.ctxt().outer_expn_data().kind;
let name = mac_name.as_str();
if let Some(braces) = mac_braces.macro_braces.get(name);
- if let Some(snip) = snippet_opt(cx, span.ctxt().outer_expn_data().call_site);
+ if let Some(snip) = snippet_opt(cx, span_call_site);
// we must check only invocation sites
// https://github.com/rust-lang/rust-clippy/issues/7422
- if snip.starts_with(&format!("{}!", name));
+ if snip.starts_with(&format!("{name}!"));
if unnested_or_local();
// make formatting consistent
let c = snip.replace(' ', "");
- if !c.starts_with(&format!("{}!{}", name, braces.0));
- if !mac_braces.done.contains(&span.ctxt().outer_expn_data().call_site);
+ if !c.starts_with(&format!("{name}!{}", braces.0));
+ if !mac_braces.done.contains(&span_call_site);
then {
- Some((mac_name, braces, snip))
+ Some((span_call_site, braces, snip))
} else {
None
}
}
}
-fn emit_help(cx: &EarlyContext<'_>, snip: String, braces: &(String, String), name: Symbol, span: Span) {
- let with_space = &format!("! {}", braces.0);
- let without_space = &format!("!{}", braces.0);
- let mut help = snip;
- for b in BRACES.iter().filter(|b| b.0 != braces.0) {
- help = help.replace(b.0, &braces.0).replace(b.1, &braces.1);
- // Only `{` traditionally has space before the brace
- if braces.0 != "{" && help.contains(with_space) {
- help = help.replace(with_space, without_space);
- } else if braces.0 == "{" && help.contains(without_space) {
- help = help.replace(without_space, with_space);
- }
+fn emit_help(cx: &EarlyContext<'_>, snip: &str, braces: &(String, String), span: Span) {
+ if let Some((macro_name, macro_args_str)) = snip.split_once('!') {
+ let mut macro_args = macro_args_str.trim().to_string();
+ // now remove the wrong braces
+ macro_args.remove(0);
+ macro_args.pop();
+ span_lint_and_sugg(
+ cx,
+ NONSTANDARD_MACRO_BRACES,
+ span,
+ &format!("use of irregular braces for `{macro_name}!` macro"),
+ "consider writing",
+ format!("{macro_name}!{}{macro_args}{}", braces.0, braces.1),
+ Applicability::MachineApplicable,
+ );
}
- span_lint_and_help(
- cx,
- NONSTANDARD_MACRO_BRACES,
- span,
- &format!("use of irregular braces for `{}!` macro", name),
- Some(span),
- &format!("consider writing `{}`", help),
- );
}
fn macro_braces(conf: FxHashSet<MacroMatcher>) -> FxHashMap<String, (String, String)> {
@@ -184,6 +177,10 @@ fn macro_braces(conf: FxHashSet<MacroMatcher>) -> FxHashMap<String, (String, Str
name: "vec",
braces: ("[", "]"),
),
+ macro_matcher!(
+ name: "matches",
+ braces: ("(", ")"),
+ ),
]
.into_iter()
.collect::<FxHashMap<_, _>>();
@@ -269,9 +266,7 @@ impl<'de> Deserialize<'de> for MacroMatcher {
.iter()
.find(|b| b.0 == brace)
.map(|(o, c)| ((*o).to_owned(), (*c).to_owned()))
- .ok_or_else(|| {
- de::Error::custom(&format!("expected one of `(`, `{{`, `[` found `{}`", brace))
- })?,
+ .ok_or_else(|| de::Error::custom(format!("expected one of `(`, `{{`, `[` found `{brace}`")))?,
})
}
}
diff --git a/src/tools/clippy/clippy_lints/src/octal_escapes.rs b/src/tools/clippy/clippy_lints/src/octal_escapes.rs
index bffbf20b4..f380a5065 100644
--- a/src/tools/clippy/clippy_lints/src/octal_escapes.rs
+++ b/src/tools/clippy/clippy_lints/src/octal_escapes.rs
@@ -102,7 +102,7 @@ fn check_lit(cx: &EarlyContext<'_>, lit: &Lit, span: Span, is_string: bool) {
// construct a replacement escape
// the maximum value is \077, or \x3f, so u8 is sufficient here
if let Ok(n) = u8::from_str_radix(&contents[from + 1..to], 8) {
- write!(suggest_1, "\\x{:02x}", n).unwrap();
+ write!(suggest_1, "\\x{n:02x}").unwrap();
}
// append the null byte as \x00 and the following digits literally
diff --git a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs
index 6217110a1..7722a476d 100644
--- a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs
+++ b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs
@@ -227,25 +227,25 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
// `skip_params` is either `0` or `1` to skip the `self` parameter in trait functions.
// It can't be renamed, and it can't be removed without removing it from multiple functions.
let (fn_id, fn_kind, skip_params) = match get_parent_node(cx.tcx, body.value.hir_id) {
- Some(Node::Item(i)) => (i.def_id.to_def_id(), FnKind::Fn, 0),
+ Some(Node::Item(i)) => (i.owner_id.to_def_id(), FnKind::Fn, 0),
Some(Node::TraitItem(&TraitItem {
kind: TraitItemKind::Fn(ref sig, _),
- def_id,
+ owner_id,
..
})) => (
- def_id.to_def_id(),
+ owner_id.to_def_id(),
FnKind::TraitFn,
usize::from(sig.decl.implicit_self.has_implicit_self()),
),
Some(Node::ImplItem(&ImplItem {
kind: ImplItemKind::Fn(ref sig, _),
- def_id,
+ owner_id,
..
})) => {
#[allow(trivial_casts)]
- if let Some(Node::Item(item)) = get_parent_node(cx.tcx, cx.tcx.hir().local_def_id_to_hir_id(def_id))
- && let Some(trait_ref) = cx.tcx.impl_trait_ref(item.def_id)
- && let Some(trait_item_id) = cx.tcx.associated_item(def_id).trait_item_def_id
+ if let Some(Node::Item(item)) = get_parent_node(cx.tcx, owner_id.into())
+ && let Some(trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
+ && let Some(trait_item_id) = cx.tcx.associated_item(owner_id).trait_item_def_id
{
(
trait_item_id,
@@ -253,7 +253,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
usize::from(sig.decl.implicit_self.has_implicit_self()),
)
} else {
- (def_id.to_def_id(), FnKind::Fn, 0)
+ (owner_id.to_def_id(), FnKind::Fn, 0)
}
},
_ => return,
diff --git a/src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs b/src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs
index 1ec4240af..d29ca37ea 100644
--- a/src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs
@@ -34,13 +34,12 @@ pub(super) fn check<'tcx>(
};
let help = format!(
- "because `{}` is the {} value for this type, {}",
+ "because `{}` is the {} value for this type, {conclusion}",
snippet(cx, culprit.expr.span, "x"),
match culprit.which {
ExtremeType::Minimum => "minimum",
ExtremeType::Maximum => "maximum",
- },
- conclusion
+ }
);
span_lint_and_help(cx, ABSURD_EXTREME_COMPARISONS, expr.span, msg, None, &help);
diff --git a/src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs b/src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs
index 83b69fbb3..8827daaa3 100644
--- a/src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs
@@ -1,8 +1,3 @@
-#![allow(
- // False positive
- clippy::match_same_arms
-)]
-
use super::ARITHMETIC_SIDE_EFFECTS;
use clippy_utils::{consts::constant_simple, diagnostics::span_lint};
use rustc_ast as ast;
@@ -14,11 +9,12 @@ use rustc_session::impl_lint_pass;
use rustc_span::source_map::{Span, Spanned};
const HARD_CODED_ALLOWED: &[&str] = &[
+ "&str",
"f32",
"f64",
"std::num::Saturating",
- "std::string::String",
"std::num::Wrapping",
+ "std::string::String",
];
#[derive(Debug)]
@@ -42,60 +38,62 @@ impl ArithmeticSideEffects {
}
}
- /// Checks assign operators (+=, -=, *=, /=) of integers in a non-constant environment that
- /// won't overflow.
- fn has_valid_assign_op(op: &Spanned<hir::BinOpKind>, rhs: &hir::Expr<'_>, rhs_refs: Ty<'_>) -> bool {
- if !Self::is_literal_integer(rhs, rhs_refs) {
- return false;
- }
- if let hir::BinOpKind::Div | hir::BinOpKind::Mul = op.node
- && let hir::ExprKind::Lit(ref lit) = rhs.kind
- && let ast::LitKind::Int(1, _) = lit.node
+ /// Assuming that `expr` is a literal integer, checks operators (+=, -=, *, /) in a
+ /// non-constant environment that won't overflow.
+ fn has_valid_op(op: &Spanned<hir::BinOpKind>, expr: &hir::Expr<'_>) -> bool {
+ if let hir::ExprKind::Lit(ref lit) = expr.kind &&
+ let ast::LitKind::Int(value, _) = lit.node
{
- return true;
+ match (&op.node, value) {
+ (hir::BinOpKind::Div | hir::BinOpKind::Rem, 0) => false,
+ (hir::BinOpKind::Add | hir::BinOpKind::Sub, 0)
+ | (hir::BinOpKind::Div | hir::BinOpKind::Rem, _)
+ | (hir::BinOpKind::Mul, 0 | 1) => true,
+ _ => false,
+ }
+ } else {
+ false
}
- false
- }
-
- /// Checks "raw" binary operators (+, -, *, /) of integers in a non-constant environment
- /// already handled by the CTFE.
- fn has_valid_bin_op(lhs: &hir::Expr<'_>, lhs_refs: Ty<'_>, rhs: &hir::Expr<'_>, rhs_refs: Ty<'_>) -> bool {
- Self::is_literal_integer(lhs, lhs_refs) && Self::is_literal_integer(rhs, rhs_refs)
}
/// Checks if the given `expr` has any of the inner `allowed` elements.
- fn is_allowed_ty(&self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
- self.allowed.contains(
- cx.typeck_results()
- .expr_ty(expr)
- .to_string()
- .split('<')
- .next()
- .unwrap_or_default(),
- )
+ fn is_allowed_ty(&self, ty: Ty<'_>) -> bool {
+ self.allowed
+ .contains(ty.to_string().split('<').next().unwrap_or_default())
}
- /// Explicit integers like `1` or `i32::MAX`. Does not take into consideration references.
- fn is_literal_integer(expr: &hir::Expr<'_>, expr_refs: Ty<'_>) -> bool {
- let is_integral = expr_refs.is_integral();
- let is_literal = matches!(expr.kind, hir::ExprKind::Lit(_));
- is_integral && is_literal
+ // For example, 8i32 or &i64::MAX.
+ fn is_integral(ty: Ty<'_>) -> bool {
+ ty.peel_refs().is_integral()
}
+ // Common entry-point to avoid code duplication.
fn issue_lint(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) {
- span_lint(cx, ARITHMETIC_SIDE_EFFECTS, expr.span, "arithmetic detected");
+ let msg = "arithmetic operation that can potentially result in unexpected side-effects";
+ span_lint(cx, ARITHMETIC_SIDE_EFFECTS, expr.span, msg);
self.expr_span = Some(expr.span);
}
+ /// If `expr` does not match any variant of `LiteralIntegerTy`, returns `None`.
+ fn literal_integer<'expr, 'tcx>(expr: &'expr hir::Expr<'tcx>) -> Option<LiteralIntegerTy<'expr, 'tcx>> {
+ if matches!(expr.kind, hir::ExprKind::Lit(_)) {
+ return Some(LiteralIntegerTy::Value(expr));
+ }
+ if let hir::ExprKind::AddrOf(.., inn) = expr.kind && let hir::ExprKind::Lit(_) = inn.kind {
+ return Some(LiteralIntegerTy::Ref(inn));
+ }
+ None
+ }
+
/// Manages when the lint should be triggered. Operations in constant environments, hard coded
/// types, custom allowed types and non-constant operations that won't overflow are ignored.
- fn manage_bin_ops(
+ fn manage_bin_ops<'tcx>(
&mut self,
- cx: &LateContext<'_>,
- expr: &hir::Expr<'_>,
+ cx: &LateContext<'tcx>,
+ expr: &hir::Expr<'tcx>,
op: &Spanned<hir::BinOpKind>,
- lhs: &hir::Expr<'_>,
- rhs: &hir::Expr<'_>,
+ lhs: &hir::Expr<'tcx>,
+ rhs: &hir::Expr<'tcx>,
) {
if constant_simple(cx, cx.typeck_results(), expr).is_some() {
return;
@@ -112,21 +110,29 @@ impl ArithmeticSideEffects {
) {
return;
};
- if self.is_allowed_ty(cx, lhs) || self.is_allowed_ty(cx, rhs) {
+ let lhs_ty = cx.typeck_results().expr_ty(lhs);
+ let rhs_ty = cx.typeck_results().expr_ty(rhs);
+ let lhs_and_rhs_have_the_same_ty = lhs_ty == rhs_ty;
+ if lhs_and_rhs_have_the_same_ty && self.is_allowed_ty(lhs_ty) && self.is_allowed_ty(rhs_ty) {
return;
}
- let lhs_refs = cx.typeck_results().expr_ty(lhs).peel_refs();
- let rhs_refs = cx.typeck_results().expr_ty(rhs).peel_refs();
- let has_valid_assign_op = Self::has_valid_assign_op(op, rhs, rhs_refs);
- if has_valid_assign_op || Self::has_valid_bin_op(lhs, lhs_refs, rhs, rhs_refs) {
- return;
+ let has_valid_op = if Self::is_integral(lhs_ty) && Self::is_integral(rhs_ty) {
+ match (Self::literal_integer(lhs), Self::literal_integer(rhs)) {
+ (None, Some(lit_int_ty)) | (Some(lit_int_ty), None) => Self::has_valid_op(op, lit_int_ty.into()),
+ (Some(LiteralIntegerTy::Value(_)), Some(LiteralIntegerTy::Value(_))) => true,
+ (None, None) | (Some(_), Some(_)) => false,
+ }
+ } else {
+ false
+ };
+ if !has_valid_op {
+ self.issue_lint(cx, expr);
}
- self.issue_lint(cx, expr);
}
}
impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
- fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
+ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'tcx>) {
if self.expr_span.is_some() || self.const_span.map_or(false, |sp| sp.contains(expr.span)) {
return;
}
@@ -171,3 +177,22 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
}
}
}
+
+/// Tells if an expression is a integer declared by value or by reference.
+///
+/// If `LiteralIntegerTy::Ref`, then the contained value will be `hir::ExprKind::Lit` rather
+/// than `hirExprKind::Addr`.
+enum LiteralIntegerTy<'expr, 'tcx> {
+ /// For example, `&199`
+ Ref(&'expr hir::Expr<'tcx>),
+ /// For example, `1` or `i32::MAX`
+ Value(&'expr hir::Expr<'tcx>),
+}
+
+impl<'expr, 'tcx> From<LiteralIntegerTy<'expr, 'tcx>> for &'expr hir::Expr<'tcx> {
+ fn from(from: LiteralIntegerTy<'expr, 'tcx>) -> Self {
+ match from {
+ LiteralIntegerTy::Ref(elem) | LiteralIntegerTy::Value(elem) => elem,
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs b/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs
index 945a09a64..ee9fd9406 100644
--- a/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs
@@ -2,16 +2,17 @@ use clippy_utils::binop_traits;
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::implements_trait;
+use clippy_utils::visitors::for_each_expr;
use clippy_utils::{eq_expr_value, trait_ref_of_method};
+use core::ops::ControlFlow;
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir as hir;
-use rustc_hir::intravisit::{walk_expr, Visitor};
+use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
use rustc_lint::LateContext;
use rustc_middle::mir::FakeReadCause;
use rustc_middle::ty::BorrowKind;
use rustc_trait_selection::infer::TyCtxtInferExt;
-use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
use super::ASSIGN_OP_PATTERN;
@@ -28,7 +29,7 @@ pub(super) fn check<'tcx>(
if_chain! {
if let Some((_, lang_item)) = binop_traits(op.node);
if let Ok(trait_id) = cx.tcx.lang_items().require(lang_item);
- let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id);
+ let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id).def_id;
if trait_ref_of_method(cx, parent_fn)
.map_or(true, |t| t.path.res.def_id() != trait_id);
if implements_trait(cx, ty, trait_id, &[rty.into()]);
@@ -55,7 +56,7 @@ pub(super) fn check<'tcx>(
diag.span_suggestion(
expr.span,
"replace it with",
- format!("{} {}= {}", snip_a, op.node.as_str(), snip_r),
+ format!("{snip_a} {}= {snip_r}", op.node.as_str()),
Applicability::MachineApplicable,
);
}
@@ -65,15 +66,19 @@ pub(super) fn check<'tcx>(
}
};
- let mut visitor = ExprVisitor {
- assignee,
- counter: 0,
- cx,
- };
-
- walk_expr(&mut visitor, e);
+ let mut found = false;
+ let found_multiple = for_each_expr(e, |e| {
+ if eq_expr_value(cx, assignee, e) {
+ if found {
+ return ControlFlow::Break(());
+ }
+ found = true;
+ }
+ ControlFlow::Continue(())
+ })
+ .is_some();
- if visitor.counter == 1 {
+ if found && !found_multiple {
// a = a op b
if eq_expr_value(cx, assignee, l) {
lint(assignee, r);
@@ -98,22 +103,6 @@ pub(super) fn check<'tcx>(
}
}
-struct ExprVisitor<'a, 'tcx> {
- assignee: &'a hir::Expr<'a>,
- counter: u8,
- cx: &'a LateContext<'tcx>,
-}
-
-impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {
- fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
- if eq_expr_value(self.cx, self.assignee, expr) {
- self.counter += 1;
- }
-
- walk_expr(self, expr);
- }
-}
-
fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet {
struct S(hir::HirIdSet);
impl Delegate<'_> for S {
@@ -134,16 +123,15 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
}
let mut s = S(hir::HirIdSet::default());
- cx.tcx.infer_ctxt().enter(|infcx| {
- let mut v = ExprUseVisitor::new(
- &mut s,
- &infcx,
- cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
- cx.param_env,
- cx.typeck_results(),
- );
- v.consume_expr(e);
- });
+ let infcx = cx.tcx.infer_ctxt().build();
+ let mut v = ExprUseVisitor::new(
+ &mut s,
+ &infcx,
+ cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
+ cx.param_env,
+ cx.typeck_results(),
+ );
+ v.consume_expr(e);
s.0
}
@@ -167,15 +155,14 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
}
let mut s = S(hir::HirIdSet::default());
- cx.tcx.infer_ctxt().enter(|infcx| {
- let mut v = ExprUseVisitor::new(
- &mut s,
- &infcx,
- cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
- cx.param_env,
- cx.typeck_results(),
- );
- v.consume_expr(e);
- });
+ let infcx = cx.tcx.infer_ctxt().build();
+ let mut v = ExprUseVisitor::new(
+ &mut s,
+ &infcx,
+ cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
+ cx.param_env,
+ cx.typeck_results(),
+ );
+ v.consume_expr(e);
s.0
}
diff --git a/src/tools/clippy/clippy_lints/src/operators/bit_mask.rs b/src/tools/clippy/clippy_lints/src/operators/bit_mask.rs
index 74387fbc8..1369b3e74 100644
--- a/src/tools/clippy/clippy_lints/src/operators/bit_mask.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/bit_mask.rs
@@ -64,10 +64,7 @@ fn check_bit_mask(
cx,
BAD_BIT_MASK,
span,
- &format!(
- "incompatible bit mask: `_ & {}` can never be equal to `{}`",
- mask_value, cmp_value
- ),
+ &format!("incompatible bit mask: `_ & {mask_value}` can never be equal to `{cmp_value}`"),
);
}
} else if mask_value == 0 {
@@ -80,10 +77,7 @@ fn check_bit_mask(
cx,
BAD_BIT_MASK,
span,
- &format!(
- "incompatible bit mask: `_ | {}` can never be equal to `{}`",
- mask_value, cmp_value
- ),
+ &format!("incompatible bit mask: `_ | {mask_value}` can never be equal to `{cmp_value}`"),
);
}
},
@@ -96,10 +90,7 @@ fn check_bit_mask(
cx,
BAD_BIT_MASK,
span,
- &format!(
- "incompatible bit mask: `_ & {}` will always be lower than `{}`",
- mask_value, cmp_value
- ),
+ &format!("incompatible bit mask: `_ & {mask_value}` will always be lower than `{cmp_value}`"),
);
} else if mask_value == 0 {
span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
@@ -111,10 +102,7 @@ fn check_bit_mask(
cx,
BAD_BIT_MASK,
span,
- &format!(
- "incompatible bit mask: `_ | {}` will never be lower than `{}`",
- mask_value, cmp_value
- ),
+ &format!("incompatible bit mask: `_ | {mask_value}` will never be lower than `{cmp_value}`"),
);
} else {
check_ineffective_lt(cx, span, mask_value, cmp_value, "|");
@@ -130,10 +118,7 @@ fn check_bit_mask(
cx,
BAD_BIT_MASK,
span,
- &format!(
- "incompatible bit mask: `_ & {}` will never be higher than `{}`",
- mask_value, cmp_value
- ),
+ &format!("incompatible bit mask: `_ & {mask_value}` will never be higher than `{cmp_value}`"),
);
} else if mask_value == 0 {
span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
@@ -145,10 +130,7 @@ fn check_bit_mask(
cx,
BAD_BIT_MASK,
span,
- &format!(
- "incompatible bit mask: `_ | {}` will always be higher than `{}`",
- mask_value, cmp_value
- ),
+ &format!("incompatible bit mask: `_ | {mask_value}` will always be higher than `{cmp_value}`"),
);
} else {
check_ineffective_gt(cx, span, mask_value, cmp_value, "|");
@@ -167,10 +149,7 @@ fn check_ineffective_lt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op:
cx,
INEFFECTIVE_BIT_MASK,
span,
- &format!(
- "ineffective bit mask: `x {} {}` compared to `{}`, is the same as x compared directly",
- op, m, c
- ),
+ &format!("ineffective bit mask: `x {op} {m}` compared to `{c}`, is the same as x compared directly"),
);
}
}
@@ -181,10 +160,7 @@ fn check_ineffective_gt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op:
cx,
INEFFECTIVE_BIT_MASK,
span,
- &format!(
- "ineffective bit mask: `x {} {}` compared to `{}`, is the same as x compared directly",
- op, m, c
- ),
+ &format!("ineffective bit mask: `x {op} {m}` compared to `{c}`, is the same as x compared directly"),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/operators/cmp_owned.rs b/src/tools/clippy/clippy_lints/src/operators/cmp_owned.rs
index 638a514ff..24aeb82a3 100644
--- a/src/tools/clippy/clippy_lints/src/operators/cmp_owned.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/cmp_owned.rs
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::snippet;
use clippy_utils::ty::{implements_trait, is_copy};
-use clippy_utils::{match_any_def_paths, path_def_id, paths};
+use clippy_utils::{match_def_path, path_def_id, paths};
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp};
use rustc_lint::LateContext;
@@ -49,13 +49,15 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool)
(arg, arg.span)
},
ExprKind::Call(path, [arg])
- if path_def_id(cx, path)
- .and_then(|id| match_any_def_paths(cx, id, &[&paths::FROM_STR_METHOD, &paths::FROM_FROM]))
- .map_or(false, |idx| match idx {
- 0 => true,
- 1 => !is_copy(cx, typeck.expr_ty(expr)),
- _ => false,
- }) =>
+ if path_def_id(cx, path).map_or(false, |id| {
+ if match_def_path(cx, id, &paths::FROM_STR_METHOD) {
+ true
+ } else if cx.tcx.lang_items().from_fn() == Some(id) {
+ !is_copy(cx, typeck.expr_ty(expr))
+ } else {
+ false
+ }
+ }) =>
{
(arg, arg.span)
},
@@ -99,7 +101,7 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool)
let expr_snip;
let eq_impl;
if with_deref.is_implemented() {
- expr_snip = format!("*{}", arg_snip);
+ expr_snip = format!("*{arg_snip}");
eq_impl = with_deref;
} else {
expr_snip = arg_snip.to_string();
@@ -121,17 +123,15 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool)
};
if eq_impl.ty_eq_other {
hint = format!(
- "{}{}{}",
- expr_snip,
+ "{expr_snip}{}{}",
snippet(cx, cmp_span, ".."),
snippet(cx, other.span, "..")
);
} else {
hint = format!(
- "{}{}{}",
+ "{}{}{expr_snip}",
snippet(cx, other.span, ".."),
- snippet(cx, cmp_span, ".."),
- expr_snip
+ snippet(cx, cmp_span, "..")
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/operators/duration_subsec.rs b/src/tools/clippy/clippy_lints/src/operators/duration_subsec.rs
index 827a2b267..49e662cac 100644
--- a/src/tools/clippy/clippy_lints/src/operators/duration_subsec.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/duration_subsec.rs
@@ -31,12 +31,11 @@ pub(crate) fn check<'tcx>(
cx,
DURATION_SUBSEC,
expr.span,
- &format!("calling `{}()` is more concise than this calculation", suggested_fn),
+ &format!("calling `{suggested_fn}()` is more concise than this calculation"),
"try",
format!(
- "{}.{}()",
- snippet_with_applicability(cx, self_arg.span, "_", &mut applicability),
- suggested_fn
+ "{}.{suggested_fn}()",
+ snippet_with_applicability(cx, self_arg.span, "_", &mut applicability)
),
applicability,
);
diff --git a/src/tools/clippy/clippy_lints/src/operators/eq_op.rs b/src/tools/clippy/clippy_lints/src/operators/eq_op.rs
index 44cf0bb06..67913f739 100644
--- a/src/tools/clippy/clippy_lints/src/operators/eq_op.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/eq_op.rs
@@ -22,7 +22,7 @@ pub(crate) fn check_assert<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
cx,
EQ_OP,
lhs.span.to(rhs.span),
- &format!("identical args used in this `{}!` macro call", macro_name),
+ &format!("identical args used in this `{macro_name}!` macro call"),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/operators/misrefactored_assign_op.rs b/src/tools/clippy/clippy_lints/src/operators/misrefactored_assign_op.rs
index 0024384d9..ae805147f 100644
--- a/src/tools/clippy/clippy_lints/src/operators/misrefactored_assign_op.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/misrefactored_assign_op.rs
@@ -47,18 +47,14 @@ fn lint_misrefactored_assign_op(
if let (Some(snip_a), Some(snip_r)) = (snippet_opt(cx, assignee.span), snippet_opt(cx, rhs_other.span)) {
let a = &sugg::Sugg::hir(cx, assignee, "..");
let r = &sugg::Sugg::hir(cx, rhs, "..");
- let long = format!("{} = {}", snip_a, sugg::make_binop(op.into(), a, r));
+ let long = format!("{snip_a} = {}", sugg::make_binop(op.into(), a, r));
diag.span_suggestion(
expr.span,
&format!(
- "did you mean `{} = {} {} {}` or `{}`? Consider replacing it with",
- snip_a,
- snip_a,
- op.as_str(),
- snip_r,
- long
+ "did you mean `{snip_a} = {snip_a} {} {snip_r}` or `{long}`? Consider replacing it with",
+ op.as_str()
),
- format!("{} {}= {}", snip_a, op.as_str(), snip_r),
+ format!("{snip_a} {}= {snip_r}", op.as_str()),
Applicability::MaybeIncorrect,
);
diag.span_suggestion(
diff --git a/src/tools/clippy/clippy_lints/src/operators/mod.rs b/src/tools/clippy/clippy_lints/src/operators/mod.rs
index c32b4df4f..b8a20d5eb 100644
--- a/src/tools/clippy/clippy_lints/src/operators/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/mod.rs
@@ -67,7 +67,7 @@ declare_clippy_lint! {
/// Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow),
/// or can panic (`/`, `%`).
///
- /// Known safe built-in types like `Wrapping` or `Saturing`, floats, operations in constant
+ /// Known safe built-in types like `Wrapping` or `Saturating`, floats, operations in constant
/// environments, allowed types and non-constant operations that won't overflow are ignored.
///
/// ### Why is this bad?
diff --git a/src/tools/clippy/clippy_lints/src/operators/needless_bitwise_bool.rs b/src/tools/clippy/clippy_lints/src/operators/needless_bitwise_bool.rs
index e902235a0..ab5fb1787 100644
--- a/src/tools/clippy/clippy_lints/src/operators/needless_bitwise_bool.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/needless_bitwise_bool.rs
@@ -27,7 +27,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &Expr<'_>, op: BinOpKind, lhs: &Exp
if let Some(lhs_snip) = snippet_opt(cx, lhs.span)
&& let Some(rhs_snip) = snippet_opt(cx, rhs.span)
{
- let sugg = format!("{} {} {}", lhs_snip, op_str, rhs_snip);
+ let sugg = format!("{lhs_snip} {op_str} {rhs_snip}");
diag.span_suggestion(e.span, "try", sugg, Applicability::MachineApplicable);
}
},
diff --git a/src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs b/src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs
index b6097710d..0830a106f 100644
--- a/src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs
@@ -1,5 +1,6 @@
use clippy_utils::consts::constant_simple;
use clippy_utils::diagnostics::span_lint;
+use clippy_utils::is_integer_literal;
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_span::source_map::Span;
@@ -50,11 +51,9 @@ impl Context {
hir::BinOpKind::Div | hir::BinOpKind::Rem => match &r.kind {
hir::ExprKind::Lit(_lit) => (),
hir::ExprKind::Unary(hir::UnOp::Neg, expr) => {
- if let hir::ExprKind::Lit(lit) = &expr.kind {
- if let rustc_ast::ast::LitKind::Int(1, _) = lit.node {
- span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
- self.expr_id = Some(expr.hir_id);
- }
+ if is_integer_literal(expr, 1) {
+ span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
+ self.expr_id = Some(expr.hir_id);
}
},
_ => {
diff --git a/src/tools/clippy/clippy_lints/src/operators/op_ref.rs b/src/tools/clippy/clippy_lints/src/operators/op_ref.rs
index 1085e6089..71b31b5e4 100644
--- a/src/tools/clippy/clippy_lints/src/operators/op_ref.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/op_ref.rs
@@ -204,7 +204,7 @@ fn are_equal<'tcx>(cx: &LateContext<'tcx>, middle_ty: Ty<'_>, hir_ty: &rustc_hir
if let ty::Adt(adt_def, _) = middle_ty.kind();
if let Some(local_did) = adt_def.did().as_local();
let item = cx.tcx.hir().expect_item(local_did);
- let middle_ty_id = item.def_id.to_def_id();
+ let middle_ty_id = item.owner_id.to_def_id();
if let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind;
if let Res::Def(_, hir_ty_id) = path.res;
diff --git a/src/tools/clippy/clippy_lints/src/operators/ptr_eq.rs b/src/tools/clippy/clippy_lints/src/operators/ptr_eq.rs
index 1aefc2741..1229c202f 100644
--- a/src/tools/clippy/clippy_lints/src/operators/ptr_eq.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/ptr_eq.rs
@@ -34,7 +34,7 @@ pub(super) fn check<'tcx>(
expr.span,
LINT_MSG,
"try",
- format!("std::ptr::eq({}, {})", left_snip, right_snip),
+ format!("std::ptr::eq({left_snip}, {right_snip})"),
Applicability::MachineApplicable,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/operators/self_assignment.rs b/src/tools/clippy/clippy_lints/src/operators/self_assignment.rs
index 9d6bec05b..7c9d5320a 100644
--- a/src/tools/clippy/clippy_lints/src/operators/self_assignment.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/self_assignment.rs
@@ -14,7 +14,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, lhs: &'tcx
cx,
SELF_ASSIGNMENT,
e.span,
- &format!("self-assignment of `{}` to `{}`", rhs, lhs),
+ &format!("self-assignment of `{rhs}` to `{lhs}`"),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/operators/verbose_bit_mask.rs b/src/tools/clippy/clippy_lints/src/operators/verbose_bit_mask.rs
index ff85fd554..fbf65e92b 100644
--- a/src/tools/clippy/clippy_lints/src/operators/verbose_bit_mask.rs
+++ b/src/tools/clippy/clippy_lints/src/operators/verbose_bit_mask.rs
@@ -35,7 +35,7 @@ pub(super) fn check<'tcx>(
diag.span_suggestion(
e.span,
"try",
- format!("{}.trailing_zeros() >= {}", sugg, n.count_ones()),
+ format!("{sugg}.trailing_zeros() >= {}", n.count_ones()),
Applicability::MaybeIncorrect,
);
},
diff --git a/src/tools/clippy/clippy_lints/src/option_env_unwrap.rs b/src/tools/clippy/clippy_lints/src/option_env_unwrap.rs
index 3f5286ba0..d9ee031c9 100644
--- a/src/tools/clippy/clippy_lints/src/option_env_unwrap.rs
+++ b/src/tools/clippy/clippy_lints/src/option_env_unwrap.rs
@@ -37,9 +37,9 @@ declare_lint_pass!(OptionEnvUnwrap => [OPTION_ENV_UNWRAP]);
impl EarlyLintPass for OptionEnvUnwrap {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if_chain! {
- if let ExprKind::MethodCall(path_segment, args, _) = &expr.kind;
+ if let ExprKind::MethodCall(path_segment, receiver, _, _) = &expr.kind;
if matches!(path_segment.ident.name, sym::expect | sym::unwrap);
- if let ExprKind::Call(caller, _) = &args[0].kind;
+ if let ExprKind::Call(caller, _) = &receiver.kind;
if is_direct_expn_of(caller.span, "option_env").is_some();
then {
span_lint_and_help(
diff --git a/src/tools/clippy/clippy_lints/src/option_if_let_else.rs b/src/tools/clippy/clippy_lints/src/option_if_let_else.rs
index 0315678bf..4eb42da1f 100644
--- a/src/tools/clippy/clippy_lints/src/option_if_let_else.rs
+++ b/src/tools/clippy/clippy_lints/src/option_if_let_else.rs
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::sugg::Sugg;
use clippy_utils::{
- can_move_expr_to_closure, eager_or_lazy, higher, in_constant, is_else_clause, is_lang_ctor, peel_blocks,
+ can_move_expr_to_closure, eager_or_lazy, higher, in_constant, is_else_clause, is_res_lang_ctor, peel_blocks,
peel_hir_expr_while, CaptureKind,
};
use if_chain::if_chain;
@@ -88,7 +88,7 @@ declare_lint_pass!(OptionIfLetElse => [OPTION_IF_LET_ELSE]);
/// None/_ => {..}
/// }
/// ```
-struct OptionOccurence {
+struct OptionOccurrence {
option: String,
method_sugg: String,
some_expr: String,
@@ -109,13 +109,13 @@ fn format_option_in_sugg(cx: &LateContext<'_>, cond_expr: &Expr<'_>, as_ref: boo
)
}
-fn try_get_option_occurence<'tcx>(
+fn try_get_option_occurrence<'tcx>(
cx: &LateContext<'tcx>,
pat: &Pat<'tcx>,
expr: &Expr<'_>,
if_then: &'tcx Expr<'_>,
if_else: &'tcx Expr<'_>,
-) -> Option<OptionOccurence> {
+) -> Option<OptionOccurrence> {
let cond_expr = match expr.kind {
ExprKind::Unary(UnOp::Deref, inner_expr) | ExprKind::AddrOf(_, _, inner_expr) => inner_expr,
_ => expr,
@@ -160,10 +160,10 @@ fn try_get_option_occurence<'tcx>(
}
}
- return Some(OptionOccurence {
+ return Some(OptionOccurrence {
option: format_option_in_sugg(cx, cond_expr, as_ref, as_mut),
method_sugg: method_sugg.to_string(),
- some_expr: format!("|{}{}| {}", capture_mut, capture_name, Sugg::hir_with_macro_callsite(cx, some_body, "..")),
+ some_expr: format!("|{capture_mut}{capture_name}| {}", Sugg::hir_with_macro_callsite(cx, some_body, "..")),
none_expr: format!("{}{}", if method_sugg == "map_or" { "" } else { "|| " }, Sugg::hir_with_macro_callsite(cx, none_body, "..")),
});
}
@@ -174,7 +174,8 @@ fn try_get_option_occurence<'tcx>(
fn try_get_inner_pat<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'tcx>) -> Option<&'tcx Pat<'tcx>> {
if let PatKind::TupleStruct(ref qpath, [inner_pat], ..) = pat.kind {
- if is_lang_ctor(cx, qpath, OptionSome) || is_lang_ctor(cx, qpath, ResultOk) {
+ let res = cx.qpath_res(qpath, pat.hir_id);
+ if is_res_lang_ctor(cx, res, OptionSome) || is_res_lang_ctor(cx, res, ResultOk) {
return Some(inner_pat);
}
}
@@ -182,9 +183,9 @@ fn try_get_inner_pat<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'tcx>) -> Option<&'
}
/// If this expression is the option if let/else construct we're detecting, then
-/// this function returns an `OptionOccurence` struct with details if
+/// this function returns an `OptionOccurrence` struct with details if
/// this construct is found, or None if this construct is not found.
-fn detect_option_if_let_else<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> Option<OptionOccurence> {
+fn detect_option_if_let_else<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> Option<OptionOccurrence> {
if let Some(higher::IfLet {
let_pat,
let_expr,
@@ -193,16 +194,16 @@ fn detect_option_if_let_else<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) ->
}) = higher::IfLet::hir(cx, expr)
{
if !is_else_clause(cx.tcx, expr) {
- return try_get_option_occurence(cx, let_pat, let_expr, if_then, if_else);
+ return try_get_option_occurrence(cx, let_pat, let_expr, if_then, if_else);
}
}
None
}
-fn detect_option_match<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> Option<OptionOccurence> {
+fn detect_option_match<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> Option<OptionOccurrence> {
if let ExprKind::Match(ex, arms, MatchSource::Normal) = expr.kind {
if let Some((let_pat, if_then, if_else)) = try_convert_match(cx, arms) {
- return try_get_option_occurence(cx, let_pat, ex, if_then, if_else);
+ return try_get_option_occurrence(cx, let_pat, ex, if_then, if_else);
}
}
None
@@ -226,9 +227,10 @@ fn try_convert_match<'tcx>(
fn is_none_or_err_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
match arm.pat.kind {
- PatKind::Path(ref qpath) => is_lang_ctor(cx, qpath, OptionNone),
+ PatKind::Path(ref qpath) => is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), OptionNone),
PatKind::TupleStruct(ref qpath, [first_pat], _) => {
- is_lang_ctor(cx, qpath, ResultErr) && matches!(first_pat.kind, PatKind::Wild)
+ is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), ResultErr)
+ && matches!(first_pat.kind, PatKind::Wild)
},
PatKind::Wild => true,
_ => false,
diff --git a/src/tools/clippy/clippy_lints/src/panic_in_result_fn.rs b/src/tools/clippy/clippy_lints/src/panic_in_result_fn.rs
index 4aa0d9227..efec12489 100644
--- a/src/tools/clippy/clippy_lints/src/panic_in_result_fn.rs
+++ b/src/tools/clippy/clippy_lints/src/panic_in_result_fn.rs
@@ -2,9 +2,10 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::macros::root_macro_call_first_node;
use clippy_utils::return_ty;
use clippy_utils::ty::is_type_diagnostic_item;
-use clippy_utils::visitors::expr_visitor_no_bodies;
+use clippy_utils::visitors::{for_each_expr, Descend};
+use core::ops::ControlFlow;
use rustc_hir as hir;
-use rustc_hir::intravisit::{FnKind, Visitor};
+use rustc_hir::intravisit::FnKind;
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{sym, Span};
@@ -58,18 +59,20 @@ impl<'tcx> LateLintPass<'tcx> for PanicInResultFn {
fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir::Body<'tcx>) {
let mut panics = Vec::new();
- expr_visitor_no_bodies(|expr| {
- let Some(macro_call) = root_macro_call_first_node(cx, expr) else { return true };
+ let _: Option<!> = for_each_expr(body.value, |e| {
+ let Some(macro_call) = root_macro_call_first_node(cx, e) else {
+ return ControlFlow::Continue(Descend::Yes);
+ };
if matches!(
cx.tcx.item_name(macro_call.def_id).as_str(),
"unimplemented" | "unreachable" | "panic" | "todo" | "assert" | "assert_eq" | "assert_ne"
) {
panics.push(macro_call.span);
- return false;
+ ControlFlow::Continue(Descend::No)
+ } else {
+ ControlFlow::Continue(Descend::Yes)
}
- true
- })
- .visit_expr(body.value);
+ });
if !panics.is_empty() {
span_lint_and_then(
cx,
diff --git a/src/tools/clippy/clippy_lints/src/partial_pub_fields.rs b/src/tools/clippy/clippy_lints/src/partial_pub_fields.rs
new file mode 100644
index 000000000..f60d9d65b
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/partial_pub_fields.rs
@@ -0,0 +1,81 @@
+use clippy_utils::diagnostics::span_lint_and_help;
+use rustc_ast::ast::{Item, ItemKind};
+use rustc_lint::{EarlyContext, EarlyLintPass};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks whether partial fields of a struct are public.
+ ///
+ /// Either make all fields of a type public, or make none of them public
+ ///
+ /// ### Why is this bad?
+ /// Most types should either be:
+ /// * Abstract data types: complex objects with opaque implementation which guard
+ /// interior invariants and expose intentionally limited API to the outside world.
+ /// * Data: relatively simple objects which group a bunch of related attributes together.
+ ///
+ /// ### Example
+ /// ```rust
+ /// pub struct Color {
+ /// pub r: u8,
+ /// pub g: u8,
+ /// b: u8,
+ /// }
+ /// ```
+ /// Use instead:
+ /// ```rust
+ /// pub struct Color {
+ /// pub r: u8,
+ /// pub g: u8,
+ /// pub b: u8,
+ /// }
+ /// ```
+ #[clippy::version = "1.66.0"]
+ pub PARTIAL_PUB_FIELDS,
+ restriction,
+ "partial fields of a struct are public"
+}
+declare_lint_pass!(PartialPubFields => [PARTIAL_PUB_FIELDS]);
+
+impl EarlyLintPass for PartialPubFields {
+ fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
+ let ItemKind::Struct(ref st, _) = item.kind else {
+ return;
+ };
+
+ let mut fields = st.fields().iter();
+ let Some(first_field) = fields.next() else {
+ // Empty struct.
+ return;
+ };
+ let all_pub = first_field.vis.kind.is_pub();
+ let all_priv = !all_pub;
+
+ let msg = "mixed usage of pub and non-pub fields";
+
+ for field in fields {
+ if all_priv && field.vis.kind.is_pub() {
+ span_lint_and_help(
+ cx,
+ PARTIAL_PUB_FIELDS,
+ field.vis.span,
+ msg,
+ None,
+ "consider using private field here",
+ );
+ return;
+ } else if all_pub && !field.vis.kind.is_pub() {
+ span_lint_and_help(
+ cx,
+ PARTIAL_PUB_FIELDS,
+ field.vis.span,
+ msg,
+ None,
+ "consider using public field here",
+ );
+ return;
+ }
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/partialeq_ne_impl.rs b/src/tools/clippy/clippy_lints/src/partialeq_ne_impl.rs
index 09ac514d0..5aa3c6f2f 100644
--- a/src/tools/clippy/clippy_lints/src/partialeq_ne_impl.rs
+++ b/src/tools/clippy/clippy_lints/src/partialeq_ne_impl.rs
@@ -36,7 +36,7 @@ impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if_chain! {
if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items: impl_items, .. }) = item.kind;
- if !cx.tcx.has_attr(item.def_id.to_def_id(), sym::automatically_derived);
+ if !cx.tcx.has_attr(item.owner_id.to_def_id(), sym::automatically_derived);
if let Some(eq_trait) = cx.tcx.lang_items().eq_trait();
if trait_ref.path.res.def_id() == eq_trait;
then {
diff --git a/src/tools/clippy/clippy_lints/src/partialeq_to_none.rs b/src/tools/clippy/clippy_lints/src/partialeq_to_none.rs
index 000b0ba7a..6810a2431 100644
--- a/src/tools/clippy/clippy_lints/src/partialeq_to_none.rs
+++ b/src/tools/clippy/clippy_lints/src/partialeq_to_none.rs
@@ -1,5 +1,5 @@
use clippy_utils::{
- diagnostics::span_lint_and_sugg, is_lang_ctor, peel_hir_expr_refs, peel_ref_operators, sugg,
+ diagnostics::span_lint_and_sugg, is_res_lang_ctor, path_res, peel_hir_expr_refs, peel_ref_operators, sugg,
ty::is_type_diagnostic_item,
};
use rustc_errors::Applicability;
@@ -54,8 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for PartialeqToNone {
// If the expression is a literal `Option::None`
let is_none_ctor = |expr: &Expr<'_>| {
!expr.span.from_expansion()
- && matches!(&peel_hir_expr_refs(expr).0.kind,
- ExprKind::Path(p) if is_lang_ctor(cx, p, LangItem::OptionNone))
+ && is_res_lang_ctor(cx, path_res(cx, peel_hir_expr_refs(expr).0), LangItem::OptionNone)
};
let mut applicability = Applicability::MachineApplicable;
diff --git a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs
index 0960b050c..f9fd36456 100644
--- a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs
+++ b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs
@@ -139,7 +139,7 @@ impl<'tcx> PassByRefOrValue {
}
fn check_poly_fn(&mut self, cx: &LateContext<'tcx>, def_id: LocalDefId, decl: &FnDecl<'_>, span: Option<Span>) {
- if self.avoid_breaking_exported_api && cx.access_levels.is_exported(def_id) {
+ if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(def_id) {
return;
}
@@ -209,7 +209,7 @@ impl<'tcx> PassByRefOrValue {
cx,
TRIVIALLY_COPY_PASS_BY_REF,
input.span,
- &format!("this argument ({} byte) is passed by reference, but would be more efficient if passed by value (limit: {} byte)", size, self.ref_min_size),
+ &format!("this argument ({size} byte) is passed by reference, but would be more efficient if passed by value (limit: {} byte)", self.ref_min_size),
"consider passing by value instead",
value_type,
Applicability::Unspecified,
@@ -237,7 +237,7 @@ impl<'tcx> PassByRefOrValue {
cx,
LARGE_TYPES_PASSED_BY_VALUE,
input.span,
- &format!("this argument ({} byte) is passed by value, but might be more efficient if passed by reference (limit: {} byte)", size, self.value_max_size),
+ &format!("this argument ({size} byte) is passed by value, but might be more efficient if passed by reference (limit: {} byte)", self.value_max_size),
"consider passing by reference instead",
format!("&{}", snippet(cx, input.span, "_")),
Applicability::MaybeIncorrect,
@@ -261,7 +261,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue {
}
if let hir::TraitItemKind::Fn(method_sig, _) = &item.kind {
- self.check_poly_fn(cx, item.def_id, method_sig.decl, None);
+ self.check_poly_fn(cx, item.owner_id.def_id, method_sig.decl, None);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/precedence.rs b/src/tools/clippy/clippy_lints/src/precedence.rs
index cc0533c9f..e6e3ad05a 100644
--- a/src/tools/clippy/clippy_lints/src/precedence.rs
+++ b/src/tools/clippy/clippy_lints/src/precedence.rs
@@ -109,12 +109,12 @@ impl EarlyLintPass for Precedence {
let mut arg = operand;
let mut all_odd = true;
- while let ExprKind::MethodCall(path_segment, args, _) = &arg.kind {
+ while let ExprKind::MethodCall(path_segment, receiver, _, _) = &arg.kind {
let path_segment_str = path_segment.ident.name.as_str();
all_odd &= ALLOWED_ODD_FUNCTIONS
.iter()
.any(|odd_function| **odd_function == *path_segment_str);
- arg = args.first().expect("A method always has a receiver.");
+ arg = receiver;
}
if_chain! {
diff --git a/src/tools/clippy/clippy_lints/src/ptr.rs b/src/tools/clippy/clippy_lints/src/ptr.rs
index 41d1baba6..0d74c90a8 100644
--- a/src/tools/clippy/clippy_lints/src/ptr.rs
+++ b/src/tools/clippy/clippy_lints/src/ptr.rs
@@ -15,13 +15,17 @@ use rustc_hir::{
ImplItemKind, ItemKind, Lifetime, LifetimeName, Mutability, Node, Param, ParamName, PatKind, QPath, TraitFn,
TraitItem, TraitItemKind, TyKind, Unsafety,
};
+use rustc_infer::infer::TyCtxtInferExt;
+use rustc_infer::traits::{Obligation, ObligationCause};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::nested_filter;
-use rustc_middle::ty::{self, Ty};
+use rustc_middle::ty::{self, Binder, ExistentialPredicate, List, PredicateKind, Ty};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;
use rustc_span::sym;
use rustc_span::symbol::Symbol;
+use rustc_trait_selection::infer::InferCtxtExt as _;
+use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
use std::fmt;
use std::iter;
@@ -160,7 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
check_mut_from_ref(cx, sig, None);
for arg in check_fn_args(
cx,
- cx.tcx.fn_sig(item.def_id).skip_binder().inputs(),
+ cx.tcx.fn_sig(item.owner_id).skip_binder().inputs(),
sig.decl.inputs,
&[],
)
@@ -184,7 +188,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
let (item_id, sig, is_trait_item) = match parents.next() {
Some((_, Node::Item(i))) => {
if let ItemKind::Fn(sig, ..) = &i.kind {
- (i.def_id, sig, false)
+ (i.owner_id, sig, false)
} else {
return;
}
@@ -196,14 +200,14 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
return;
}
if let ImplItemKind::Fn(sig, _) = &i.kind {
- (i.def_id, sig, false)
+ (i.owner_id, sig, false)
} else {
return;
}
},
Some((_, Node::TraitItem(i))) => {
if let TraitItemKind::Fn(sig, _) = &i.kind {
- (i.def_id, sig, true)
+ (i.owner_id, sig, true)
} else {
return;
}
@@ -384,6 +388,17 @@ enum DerefTy<'tcx> {
Slice(Option<Span>, Ty<'tcx>),
}
impl<'tcx> DerefTy<'tcx> {
+ fn ty(&self, cx: &LateContext<'tcx>) -> Ty<'tcx> {
+ match *self {
+ Self::Str => cx.tcx.types.str_,
+ Self::Path => cx.tcx.mk_adt(
+ cx.tcx.adt_def(cx.tcx.get_diagnostic_item(sym::Path).unwrap()),
+ List::empty(),
+ ),
+ Self::Slice(_, ty) => cx.tcx.mk_slice(ty),
+ }
+ }
+
fn argless_str(&self) -> &'static str {
match *self {
Self::Str => "str",
@@ -463,7 +478,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
diag.span_suggestion(
hir_ty.span,
"change this to",
- format!("&{}{}", mutability.prefix_str(), ty_name),
+ format!("&{}{ty_name}", mutability.prefix_str()),
Applicability::Unspecified,
);
}
@@ -552,9 +567,8 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args:
}
// Check if this is local we care about
- let args_idx = match path_to_local(e).and_then(|id| self.bindings.get(&id)) {
- Some(&i) => i,
- None => return walk_expr(self, e),
+ let Some(&args_idx) = path_to_local(e).and_then(|id| self.bindings.get(&id)) else {
+ return walk_expr(self, e);
};
let args = &self.args[args_idx];
let result = &mut self.results[args_idx];
@@ -582,6 +596,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args:
let i = expr_args.iter().position(|arg| arg.hir_id == child_id).unwrap_or(0);
if expr_sig(self.cx, f).and_then(|sig| sig.input(i)).map_or(true, |ty| {
match *ty.skip_binder().peel_refs().kind() {
+ ty::Dynamic(preds, _, _) => !matches_preds(self.cx, args.deref_ty.ty(self.cx), preds),
ty::Param(_) => true,
ty::Adt(def, _) => def.did() == args.ty_did,
_ => false,
@@ -609,14 +624,15 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args:
}
}
- let id = if let Some(x) = self.cx.typeck_results().type_dependent_def_id(e.hir_id) {
- x
- } else {
+ let Some(id) = self.cx.typeck_results().type_dependent_def_id(e.hir_id) else {
set_skip_flag();
return;
};
match *self.cx.tcx.fn_sig(id).skip_binder().inputs()[i].peel_refs().kind() {
+ ty::Dynamic(preds, _, _) if !matches_preds(self.cx, args.deref_ty.ty(self.cx), preds) => {
+ set_skip_flag();
+ },
ty::Param(_) => {
set_skip_flag();
},
@@ -668,8 +684,32 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args:
v.results
}
+fn matches_preds<'tcx>(
+ cx: &LateContext<'tcx>,
+ ty: Ty<'tcx>,
+ preds: &'tcx [Binder<'tcx, ExistentialPredicate<'tcx>>],
+) -> bool {
+ let infcx = cx.tcx.infer_ctxt().build();
+ preds.iter().all(|&p| match cx.tcx.erase_late_bound_regions(p) {
+ ExistentialPredicate::Trait(p) => infcx
+ .type_implements_trait(p.def_id, ty, p.substs, cx.param_env)
+ .must_apply_modulo_regions(),
+ ExistentialPredicate::Projection(p) => infcx.predicate_must_hold_modulo_regions(&Obligation::new(
+ ObligationCause::dummy(),
+ cx.param_env,
+ cx.tcx.mk_predicate(Binder::bind_with_vars(
+ PredicateKind::Projection(p.with_self_ty(cx.tcx, ty)),
+ List::empty(),
+ )),
+ )),
+ ExistentialPredicate::AutoTrait(p) => infcx
+ .type_implements_trait(p, ty, List::empty(), cx.param_env)
+ .must_apply_modulo_regions(),
+ })
+}
+
fn get_rptr_lm<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> Option<(&'tcx Lifetime, Mutability, Span)> {
- if let TyKind::Rptr(ref lt, ref m) = ty.kind {
+ if let TyKind::Rptr(lt, ref m) = ty.kind {
Some((lt, m.mutbl, ty.span))
} else {
None
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 4dc65da3e..72dda67c7 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
@@ -49,18 +49,16 @@ declare_lint_pass!(PtrOffsetWithCast => [PTR_OFFSET_WITH_CAST]);
impl<'tcx> LateLintPass<'tcx> for PtrOffsetWithCast {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
// Check if the expressions is a ptr.offset or ptr.wrapping_offset method call
- let (receiver_expr, arg_expr, method) = match expr_as_ptr_offset_call(cx, expr) {
- Some(call_arg) => call_arg,
- None => return,
+ let Some((receiver_expr, arg_expr, method)) = expr_as_ptr_offset_call(cx, expr) else {
+ return
};
// Check if the argument to the method call is a cast from usize
- let cast_lhs_expr = match expr_as_cast_from_usize(cx, arg_expr) {
- Some(cast_lhs_expr) => cast_lhs_expr,
- None => return,
+ let Some(cast_lhs_expr) = expr_as_cast_from_usize(cx, arg_expr) else {
+ return
};
- let msg = format!("use of `{}` with a `usize` casted to an `isize`", method);
+ let msg = format!("use of `{method}` with a `usize` casted to an `isize`");
if let Some(sugg) = build_suggestion(cx, method, receiver_expr, cast_lhs_expr) {
span_lint_and_sugg(
cx,
@@ -124,7 +122,7 @@ fn build_suggestion<'tcx>(
) -> Option<String> {
let receiver = snippet_opt(cx, receiver_expr.span)?;
let cast_lhs = snippet_opt(cx, cast_lhs_expr.span)?;
- Some(format!("{}.{}({})", receiver, method.suggestion(), cast_lhs))
+ Some(format!("{receiver}.{}({cast_lhs})", method.suggestion()))
}
#[derive(Copy, Clone)]
diff --git a/src/tools/clippy/clippy_lints/src/question_mark.rs b/src/tools/clippy/clippy_lints/src/question_mark.rs
index 569870ab2..bb86fb3b7 100644
--- a/src/tools/clippy/clippy_lints/src/question_mark.rs
+++ b/src/tools/clippy/clippy_lints/src/question_mark.rs
@@ -3,11 +3,12 @@ use clippy_utils::higher;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::{
- eq_expr_value, get_parent_node, is_else_clause, is_lang_ctor, path_to_local, path_to_local_id, peel_blocks,
- peel_blocks_with_stmt,
+ eq_expr_value, get_parent_node, in_constant, is_else_clause, is_res_lang_ctor, path_to_local, path_to_local_id,
+ peel_blocks, peel_blocks_with_stmt,
};
use if_chain::if_chain;
use rustc_errors::Applicability;
+use rustc_hir::def::Res;
use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk};
use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, Node, PatKind, PathSegment, QPath};
use rustc_lint::{LateContext, LateLintPass};
@@ -58,7 +59,7 @@ enum IfBlockType<'hir> {
/// Contains: let_pat_qpath (Xxx), let_pat_type, let_pat_sym (a), let_expr (b), if_then (c),
/// if_else (d)
IfLet(
- &'hir QPath<'hir>,
+ Res,
Ty<'hir>,
Symbol,
&'hir Expr<'hir>,
@@ -93,16 +94,16 @@ fn check_is_none_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr: &Ex
then {
let mut applicability = Applicability::MachineApplicable;
let receiver_str = snippet_with_applicability(cx, caller.span, "..", &mut applicability);
- let by_ref = !caller_ty.is_copy_modulo_regions(cx.tcx.at(caller.span), cx.param_env) &&
+ let by_ref = !caller_ty.is_copy_modulo_regions(cx.tcx, cx.param_env) &&
!matches!(caller.kind, ExprKind::Call(..) | ExprKind::MethodCall(..));
let sugg = if let Some(else_inner) = r#else {
if eq_expr_value(cx, caller, peel_blocks(else_inner)) {
- format!("Some({}?)", receiver_str)
+ format!("Some({receiver_str}?)")
} else {
return;
}
} else {
- format!("{}{}?;", receiver_str, if by_ref { ".as_ref()" } else { "" })
+ format!("{receiver_str}{}?;", if by_ref { ".as_ref()" } else { "" })
};
span_lint_and_sugg(
@@ -126,7 +127,14 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr:
if ddpos.as_opt_usize().is_none();
if let PatKind::Binding(BindingAnnotation(by_ref, _), bind_id, ident, None) = field.kind;
let caller_ty = cx.typeck_results().expr_ty(let_expr);
- let if_block = IfBlockType::IfLet(path1, caller_ty, ident.name, let_expr, if_then, if_else);
+ let if_block = IfBlockType::IfLet(
+ cx.qpath_res(path1, let_pat.hir_id),
+ caller_ty,
+ ident.name,
+ let_expr,
+ if_then,
+ if_else
+ );
if (is_early_return(sym::Option, cx, &if_block) && path_to_local_id(peel_blocks(if_then), bind_id))
|| is_early_return(sym::Result, cx, &if_block);
if if_else.map(|e| eq_expr_value(cx, let_expr, peel_blocks(e))).filter(|e| *e).is_none();
@@ -135,8 +143,7 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr:
let receiver_str = snippet_with_applicability(cx, let_expr.span, "..", &mut applicability);
let requires_semi = matches!(get_parent_node(cx.tcx, expr.hir_id), Some(Node::Stmt(_)));
let sugg = format!(
- "{}{}?{}",
- receiver_str,
+ "{receiver_str}{}?{}",
if by_ref == ByRef::Yes { ".as_ref()" } else { "" },
if requires_semi { ";" } else { "" }
);
@@ -166,21 +173,21 @@ fn is_early_return(smbl: Symbol, cx: &LateContext<'_>, if_block: &IfBlockType<'_
_ => false,
}
},
- IfBlockType::IfLet(qpath, let_expr_ty, let_pat_sym, let_expr, if_then, if_else) => {
+ IfBlockType::IfLet(res, let_expr_ty, let_pat_sym, let_expr, if_then, if_else) => {
is_type_diagnostic_item(cx, let_expr_ty, smbl)
&& match smbl {
sym::Option => {
// We only need to check `if let Some(x) = option` not `if let None = option`,
// because the later one will be suggested as `if option.is_none()` thus causing conflict.
- is_lang_ctor(cx, qpath, OptionSome)
+ is_res_lang_ctor(cx, res, OptionSome)
&& if_else.is_some()
&& expr_return_none_or_err(smbl, cx, if_else.unwrap(), let_expr, None)
},
sym::Result => {
- (is_lang_ctor(cx, qpath, ResultOk)
+ (is_res_lang_ctor(cx, res, ResultOk)
&& if_else.is_some()
&& expr_return_none_or_err(smbl, cx, if_else.unwrap(), let_expr, Some(let_pat_sym)))
- || is_lang_ctor(cx, qpath, ResultErr)
+ || is_res_lang_ctor(cx, res, ResultErr)
&& expr_return_none_or_err(smbl, cx, if_then, let_expr, Some(let_pat_sym))
},
_ => false,
@@ -199,7 +206,7 @@ fn expr_return_none_or_err(
match peel_blocks_with_stmt(expr).kind {
ExprKind::Ret(Some(ret_expr)) => expr_return_none_or_err(smbl, cx, ret_expr, cond_expr, err_sym),
ExprKind::Path(ref qpath) => match smbl {
- sym::Option => is_lang_ctor(cx, qpath, OptionNone),
+ sym::Option => is_res_lang_ctor(cx, cx.qpath_res(qpath, expr.hir_id), OptionNone),
sym::Result => path_to_local(expr).is_some() && path_to_local(expr) == path_to_local(cond_expr),
_ => false,
},
@@ -224,7 +231,9 @@ fn expr_return_none_or_err(
impl<'tcx> LateLintPass<'tcx> for QuestionMark {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
- check_is_none_or_err_and_early_return(cx, expr);
- check_if_let_some_or_err_and_early_return(cx, expr);
+ if !in_constant(cx, expr.hir_id) {
+ check_is_none_or_err_and_early_return(cx, expr);
+ check_if_let_some_or_err_and_early_return(cx, expr);
+ }
}
}
diff --git a/src/tools/clippy/clippy_lints/src/ranges.rs b/src/tools/clippy/clippy_lints/src/ranges.rs
index 918d624ee..c6fbb5e80 100644
--- a/src/tools/clippy/clippy_lints/src/ranges.rs
+++ b/src/tools/clippy/clippy_lints/src/ranges.rs
@@ -243,9 +243,9 @@ fn check_possible_range_contains(
cx,
MANUAL_RANGE_CONTAINS,
span,
- &format!("manual `{}::contains` implementation", range_type),
+ &format!("manual `{range_type}::contains` implementation"),
"use",
- format!("({}{}{}{}).contains(&{})", lo, space, range_op, hi, name),
+ format!("({lo}{space}{range_op}{hi}).contains(&{name})"),
applicability,
);
} else if !combine_and && ord == Some(l.ord) {
@@ -273,9 +273,9 @@ fn check_possible_range_contains(
cx,
MANUAL_RANGE_CONTAINS,
span,
- &format!("manual `!{}::contains` implementation", range_type),
+ &format!("manual `!{range_type}::contains` implementation"),
"use",
- format!("!({}{}{}{}).contains(&{})", lo, space, range_op, hi, name),
+ format!("!({lo}{space}{range_op}{hi}).contains(&{name})"),
applicability,
);
}
@@ -372,14 +372,14 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_>, expr: &Expr<'_>) {
diag.span_suggestion(
span,
"use",
- format!("({}..={})", start, end),
+ format!("({start}..={end})"),
Applicability::MaybeIncorrect,
);
} else {
diag.span_suggestion(
span,
"use",
- format!("{}..={}", start, end),
+ format!("{start}..={end}"),
Applicability::MachineApplicable, // snippet
);
}
@@ -408,7 +408,7 @@ fn check_inclusive_range_minus_one(cx: &LateContext<'_>, expr: &Expr<'_>) {
diag.span_suggestion(
expr.span,
"use",
- format!("{}..{}", start, end),
+ format!("{start}..{end}"),
Applicability::MachineApplicable, // snippet
);
},
@@ -486,7 +486,7 @@ fn check_reversed_empty_range(cx: &LateContext<'_>, expr: &Expr<'_>) {
expr.span,
"consider using the following if you are attempting to iterate over this \
range in reverse",
- format!("({}{}{}).rev()", end_snippet, dots, start_snippet),
+ format!("({end_snippet}{dots}{start_snippet}).rev()"),
Applicability::MaybeIncorrect,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/read_zero_byte_vec.rs b/src/tools/clippy/clippy_lints/src/read_zero_byte_vec.rs
index 2882ba033..fa1078588 100644
--- a/src/tools/clippy/clippy_lints/src/read_zero_byte_vec.rs
+++ b/src/tools/clippy/clippy_lints/src/read_zero_byte_vec.rs
@@ -2,9 +2,10 @@ use clippy_utils::{
diagnostics::{span_lint, span_lint_and_sugg},
higher::{get_vec_init_kind, VecInitKind},
source::snippet,
- visitors::expr_visitor_no_bodies,
+ visitors::for_each_expr,
};
-use hir::{intravisit::Visitor, ExprKind, Local, PatKind, PathSegment, QPath, StmtKind};
+use core::ops::ControlFlow;
+use hir::{Expr, ExprKind, Local, PatKind, PathSegment, QPath, StmtKind};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass};
@@ -43,7 +44,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.63.0"]
pub READ_ZERO_BYTE_VEC,
- nursery,
+ correctness,
"checks for reads into a zero-length `Vec`"
}
declare_lint_pass!(ReadZeroByteVec => [READ_ZERO_BYTE_VEC]);
@@ -58,10 +59,8 @@ impl<'tcx> LateLintPass<'tcx> for ReadZeroByteVec {
&& let PatKind::Binding(_, _, ident, _) = pat.kind
&& let Some(vec_init_kind) = get_vec_init_kind(cx, init)
{
- // finds use of `_.read(&mut v)`
- let mut read_found = false;
- let mut visitor = expr_visitor_no_bodies(|expr| {
- if let ExprKind::MethodCall(path, _self, [arg], _) = expr.kind
+ let visitor = |expr: &Expr<'_>| {
+ if let ExprKind::MethodCall(path, _, [arg], _) = expr.kind
&& let PathSegment { ident: read_or_read_exact, .. } = *path
&& matches!(read_or_read_exact.as_str(), "read" | "read_exact")
&& let ExprKind::AddrOf(_, hir::Mutability::Mut, inner) = arg.kind
@@ -69,27 +68,22 @@ impl<'tcx> LateLintPass<'tcx> for ReadZeroByteVec {
&& let [inner_seg] = inner_path.segments
&& ident.name == inner_seg.ident.name
{
- read_found = true;
+ ControlFlow::Break(())
+ } else {
+ ControlFlow::Continue(())
}
- !read_found
- });
+ };
- let next_stmt_span;
- if idx == block.stmts.len() - 1 {
+ let (read_found, next_stmt_span) =
+ if let Some(next_stmt) = block.stmts.get(idx + 1) {
+ // case { .. stmt; stmt; .. }
+ (for_each_expr(next_stmt, visitor).is_some(), next_stmt.span)
+ } else if let Some(e) = block.expr {
// case { .. stmt; expr }
- if let Some(e) = block.expr {
- visitor.visit_expr(e);
- next_stmt_span = e.span;
- } else {
- return;
- }
+ (for_each_expr(e, visitor).is_some(), e.span)
} else {
- // case { .. stmt; stmt; .. }
- let next_stmt = &block.stmts[idx + 1];
- visitor.visit_stmt(next_stmt);
- next_stmt_span = next_stmt.span;
- }
- drop(visitor);
+ return
+ };
if read_found && !next_stmt_span.from_expansion() {
let applicability = Applicability::MaybeIncorrect;
@@ -101,9 +95,8 @@ impl<'tcx> LateLintPass<'tcx> for ReadZeroByteVec {
next_stmt_span,
"reading zero byte data to `Vec`",
"try",
- format!("{}.resize({}, 0); {}",
+ format!("{}.resize({len}, 0); {}",
ident.as_str(),
- len,
snippet(cx, next_stmt_span, "..")
),
applicability,
diff --git a/src/tools/clippy/clippy_lints/src/redundant_clone.rs b/src/tools/clippy/clippy_lints/src/redundant_clone.rs
index 9fd86331e..aedbe08e3 100644
--- a/src/tools/clippy/clippy_lints/src/redundant_clone.rs
+++ b/src/tools/clippy/clippy_lints/src/redundant_clone.rs
@@ -1,25 +1,18 @@
use clippy_utils::diagnostics::{span_lint_hir, span_lint_hir_and_then};
+use clippy_utils::mir::{visit_local_usage, LocalUsage, PossibleBorrowerMap};
use clippy_utils::source::snippet_opt;
use clippy_utils::ty::{has_drop, is_copy, is_type_diagnostic_item, walk_ptrs_ty_depth};
use clippy_utils::{fn_has_unsatisfiable_preds, match_def_path, paths};
use if_chain::if_chain;
-use rustc_data_structures::fx::FxHashMap;
use rustc_errors::Applicability;
use rustc_hir::intravisit::FnKind;
use rustc_hir::{def_id, Body, FnDecl, HirId};
-use rustc_index::bit_set::{BitSet, HybridBitSet};
use rustc_lint::{LateContext, LateLintPass};
-use rustc_middle::mir::{
- self, traversal,
- visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor as _},
- Mutability,
-};
-use rustc_middle::ty::{self, visit::TypeVisitor, Ty};
-use rustc_mir_dataflow::{Analysis, AnalysisDomain, CallReturnPlaces, GenKill, GenKillAnalysis, ResultsCursor};
+use rustc_middle::mir;
+use rustc_middle::ty::{self, Ty};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::{BytePos, Span};
use rustc_span::sym;
-use std::ops::ControlFlow;
macro_rules! unwrap_or_continue {
($x:expr) => {
@@ -89,21 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone {
let mir = cx.tcx.optimized_mir(def_id.to_def_id());
- let possible_origin = {
- let mut vis = PossibleOriginVisitor::new(mir);
- vis.visit_body(mir);
- vis.into_map(cx)
- };
- let maybe_storage_live_result = MaybeStorageLive
- .into_engine(cx.tcx, mir)
- .pass_name("redundant_clone")
- .iterate_to_fixpoint()
- .into_results_cursor(mir);
- let mut possible_borrower = {
- let mut vis = PossibleBorrowerVisitor::new(cx, mir, possible_origin);
- vis.visit_body(mir);
- vis.into_map(cx, maybe_storage_live_result)
- };
+ let mut possible_borrower = PossibleBorrowerMap::new(cx, mir);
for (bb, bbdata) in mir.basic_blocks.iter_enumerated() {
let terminator = bbdata.terminator();
@@ -374,403 +353,40 @@ struct CloneUsage {
/// Whether the clone value is mutated.
clone_consumed_or_mutated: bool,
}
-fn visit_clone_usage(cloned: mir::Local, clone: mir::Local, mir: &mir::Body<'_>, bb: mir::BasicBlock) -> CloneUsage {
- struct V {
- cloned: mir::Local,
- clone: mir::Local,
- result: CloneUsage,
- }
- impl<'tcx> mir::visit::Visitor<'tcx> for V {
- fn visit_basic_block_data(&mut self, block: mir::BasicBlock, data: &mir::BasicBlockData<'tcx>) {
- let statements = &data.statements;
- for (statement_index, statement) in statements.iter().enumerate() {
- self.visit_statement(statement, mir::Location { block, statement_index });
- }
-
- self.visit_terminator(
- data.terminator(),
- mir::Location {
- block,
- statement_index: statements.len(),
- },
- );
- }
-
- fn visit_place(&mut self, place: &mir::Place<'tcx>, ctx: PlaceContext, loc: mir::Location) {
- let local = place.local;
-
- if local == self.cloned
- && !matches!(
- ctx,
- PlaceContext::MutatingUse(MutatingUseContext::Drop) | PlaceContext::NonUse(_)
- )
- {
- self.result.cloned_used = true;
- self.result.cloned_consume_or_mutate_loc = self.result.cloned_consume_or_mutate_loc.or_else(|| {
- matches!(
- ctx,
- PlaceContext::NonMutatingUse(NonMutatingUseContext::Move)
- | PlaceContext::MutatingUse(MutatingUseContext::Borrow)
- )
- .then(|| loc)
- });
- } else if local == self.clone {
- match ctx {
- PlaceContext::NonMutatingUse(NonMutatingUseContext::Move)
- | PlaceContext::MutatingUse(MutatingUseContext::Borrow) => {
- self.result.clone_consumed_or_mutated = true;
- },
- _ => {},
- }
- }
- }
- }
-
- let init = CloneUsage {
- cloned_used: false,
- cloned_consume_or_mutate_loc: None,
- // Consider non-temporary clones consumed.
- // TODO: Actually check for mutation of non-temporaries.
- clone_consumed_or_mutated: mir.local_kind(clone) != mir::LocalKind::Temp,
- };
- traversal::ReversePostorder::new(mir, bb)
- .skip(1)
- .fold(init, |usage, (tbb, tdata)| {
- // Short-circuit
- if (usage.cloned_used && usage.clone_consumed_or_mutated) ||
- // Give up on loops
- tdata.terminator().successors().any(|s| s == bb)
- {
- return CloneUsage {
- cloned_used: true,
- clone_consumed_or_mutated: true,
- ..usage
- };
- }
-
- let mut v = V {
- cloned,
- clone,
- result: usage,
- };
- v.visit_basic_block_data(tbb, tdata);
- v.result
- })
-}
-
-/// Determines liveness of each local purely based on `StorageLive`/`Dead`.
-#[derive(Copy, Clone)]
-struct MaybeStorageLive;
-
-impl<'tcx> AnalysisDomain<'tcx> for MaybeStorageLive {
- type Domain = BitSet<mir::Local>;
- const NAME: &'static str = "maybe_storage_live";
-
- fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain {
- // bottom = dead
- BitSet::new_empty(body.local_decls.len())
- }
-
- fn initialize_start_block(&self, body: &mir::Body<'tcx>, state: &mut Self::Domain) {
- for arg in body.args_iter() {
- state.insert(arg);
- }
- }
-}
-
-impl<'tcx> GenKillAnalysis<'tcx> for MaybeStorageLive {
- type Idx = mir::Local;
-
- fn statement_effect(&self, trans: &mut impl GenKill<Self::Idx>, stmt: &mir::Statement<'tcx>, _: mir::Location) {
- match stmt.kind {
- mir::StatementKind::StorageLive(l) => trans.gen(l),
- mir::StatementKind::StorageDead(l) => trans.kill(l),
- _ => (),
- }
- }
-
- fn terminator_effect(
- &self,
- _trans: &mut impl GenKill<Self::Idx>,
- _terminator: &mir::Terminator<'tcx>,
- _loc: mir::Location,
- ) {
- }
-
- fn call_return_effect(
- &self,
- _trans: &mut impl GenKill<Self::Idx>,
- _block: mir::BasicBlock,
- _return_places: CallReturnPlaces<'_, 'tcx>,
- ) {
- // Nothing to do when a call returns successfully
- }
-}
-
-/// Collects the possible borrowers of each local.
-/// For example, `b = &a; c = &a;` will make `b` and (transitively) `c`
-/// possible borrowers of `a`.
-struct PossibleBorrowerVisitor<'a, 'tcx> {
- possible_borrower: TransitiveRelation,
- body: &'a mir::Body<'tcx>,
- cx: &'a LateContext<'tcx>,
- possible_origin: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
-}
-
-impl<'a, 'tcx> PossibleBorrowerVisitor<'a, 'tcx> {
- fn new(
- cx: &'a LateContext<'tcx>,
- body: &'a mir::Body<'tcx>,
- possible_origin: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
- ) -> Self {
- Self {
- possible_borrower: TransitiveRelation::default(),
- cx,
- body,
- possible_origin,
- }
- }
-
- fn into_map(
- self,
- cx: &LateContext<'tcx>,
- maybe_live: ResultsCursor<'tcx, 'tcx, MaybeStorageLive>,
- ) -> PossibleBorrowerMap<'a, 'tcx> {
- let mut map = FxHashMap::default();
- for row in (1..self.body.local_decls.len()).map(mir::Local::from_usize) {
- if is_copy(cx, self.body.local_decls[row].ty) {
- continue;
- }
-
- let mut borrowers = self.possible_borrower.reachable_from(row, self.body.local_decls.len());
- borrowers.remove(mir::Local::from_usize(0));
- if !borrowers.is_empty() {
- map.insert(row, borrowers);
- }
- }
-
- let bs = BitSet::new_empty(self.body.local_decls.len());
- PossibleBorrowerMap {
- map,
- maybe_live,
- bitset: (bs.clone(), bs),
- }
- }
-}
-
-impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'tcx> {
- fn visit_assign(&mut self, place: &mir::Place<'tcx>, rvalue: &mir::Rvalue<'_>, _location: mir::Location) {
- let lhs = place.local;
- match rvalue {
- mir::Rvalue::Ref(_, _, borrowed) => {
- self.possible_borrower.add(borrowed.local, lhs);
- },
- other => {
- if ContainsRegion
- .visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty)
- .is_continue()
- {
- return;
- }
- rvalue_locals(other, |rhs| {
- if lhs != rhs {
- self.possible_borrower.add(rhs, lhs);
- }
- });
- },
- }
- }
-
- fn visit_terminator(&mut self, terminator: &mir::Terminator<'_>, _loc: mir::Location) {
- if let mir::TerminatorKind::Call {
- args,
- destination: mir::Place { local: dest, .. },
- ..
- } = &terminator.kind
- {
- // TODO add doc
- // If the call returns something with lifetimes,
- // let's conservatively assume the returned value contains lifetime of all the arguments.
- // For example, given `let y: Foo<'a> = foo(x)`, `y` is considered to be a possible borrower of `x`.
-
- let mut immutable_borrowers = vec![];
- let mut mutable_borrowers = vec![];
-
- for op in args {
- match op {
- mir::Operand::Copy(p) | mir::Operand::Move(p) => {
- if let ty::Ref(_, _, Mutability::Mut) = self.body.local_decls[p.local].ty.kind() {
- mutable_borrowers.push(p.local);
- } else {
- immutable_borrowers.push(p.local);
- }
- },
- mir::Operand::Constant(..) => (),
- }
- }
-
- let mut mutable_variables: Vec<mir::Local> = mutable_borrowers
- .iter()
- .filter_map(|r| self.possible_origin.get(r))
- .flat_map(HybridBitSet::iter)
- .collect();
-
- if ContainsRegion.visit_ty(self.body.local_decls[*dest].ty).is_break() {
- mutable_variables.push(*dest);
- }
-
- for y in mutable_variables {
- for x in &immutable_borrowers {
- self.possible_borrower.add(*x, y);
- }
- for x in &mutable_borrowers {
- self.possible_borrower.add(*x, y);
- }
- }
- }
- }
-}
-
-/// Collect possible borrowed for every `&mut` local.
-/// For example, `_1 = &mut _2` generate _1: {_2,...}
-/// Known Problems: not sure all borrowed are tracked
-struct PossibleOriginVisitor<'a, 'tcx> {
- possible_origin: TransitiveRelation,
- body: &'a mir::Body<'tcx>,
-}
-
-impl<'a, 'tcx> PossibleOriginVisitor<'a, 'tcx> {
- fn new(body: &'a mir::Body<'tcx>) -> Self {
- Self {
- possible_origin: TransitiveRelation::default(),
- body,
- }
- }
-
- fn into_map(self, cx: &LateContext<'tcx>) -> FxHashMap<mir::Local, HybridBitSet<mir::Local>> {
- let mut map = FxHashMap::default();
- for row in (1..self.body.local_decls.len()).map(mir::Local::from_usize) {
- if is_copy(cx, self.body.local_decls[row].ty) {
- continue;
- }
-
- let mut borrowers = self.possible_origin.reachable_from(row, self.body.local_decls.len());
- borrowers.remove(mir::Local::from_usize(0));
- if !borrowers.is_empty() {
- map.insert(row, borrowers);
- }
- }
- map
- }
-}
-
-impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleOriginVisitor<'a, 'tcx> {
- fn visit_assign(&mut self, place: &mir::Place<'tcx>, rvalue: &mir::Rvalue<'_>, _location: mir::Location) {
- let lhs = place.local;
- match rvalue {
- // Only consider `&mut`, which can modify origin place
- mir::Rvalue::Ref(_, rustc_middle::mir::BorrowKind::Mut { .. }, borrowed) |
- // _2: &mut _;
- // _3 = move _2
- mir::Rvalue::Use(mir::Operand::Move(borrowed)) |
- // _3 = move _2 as &mut _;
- mir::Rvalue::Cast(_, mir::Operand::Move(borrowed), _)
- => {
- self.possible_origin.add(lhs, borrowed.local);
- },
- _ => {},
- }
- }
-}
-
-struct ContainsRegion;
-
-impl TypeVisitor<'_> for ContainsRegion {
- type BreakTy = ();
-
- fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow<Self::BreakTy> {
- ControlFlow::BREAK
- }
-}
-
-fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) {
- use rustc_middle::mir::Rvalue::{Aggregate, BinaryOp, Cast, CheckedBinaryOp, Repeat, UnaryOp, Use};
-
- let mut visit_op = |op: &mir::Operand<'_>| match op {
- mir::Operand::Copy(p) | mir::Operand::Move(p) => visit(p.local),
- mir::Operand::Constant(..) => (),
- };
- match rvalue {
- Use(op) | Repeat(op, _) | Cast(_, op, _) | UnaryOp(_, op) => visit_op(op),
- Aggregate(_, ops) => ops.iter().for_each(visit_op),
- BinaryOp(_, box (lhs, rhs)) | CheckedBinaryOp(_, box (lhs, rhs)) => {
- visit_op(lhs);
- visit_op(rhs);
+fn visit_clone_usage(cloned: mir::Local, clone: mir::Local, mir: &mir::Body<'_>, bb: mir::BasicBlock) -> CloneUsage {
+ if let Some((
+ LocalUsage {
+ local_use_locs: cloned_use_locs,
+ local_consume_or_mutate_locs: cloned_consume_or_mutate_locs,
},
- _ => (),
- }
-}
-
-/// Result of `PossibleBorrowerVisitor`.
-struct PossibleBorrowerMap<'a, 'tcx> {
- /// Mapping `Local -> its possible borrowers`
- map: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
- maybe_live: ResultsCursor<'a, 'tcx, MaybeStorageLive>,
- // Caches to avoid allocation of `BitSet` on every query
- bitset: (BitSet<mir::Local>, BitSet<mir::Local>),
-}
-
-impl PossibleBorrowerMap<'_, '_> {
- /// Returns true if the set of borrowers of `borrowed` living at `at` matches with `borrowers`.
- fn only_borrowers(&mut self, borrowers: &[mir::Local], borrowed: mir::Local, at: mir::Location) -> bool {
- self.maybe_live.seek_after_primary_effect(at);
-
- self.bitset.0.clear();
- let maybe_live = &mut self.maybe_live;
- if let Some(bitset) = self.map.get(&borrowed) {
- for b in bitset.iter().filter(move |b| maybe_live.contains(*b)) {
- self.bitset.0.insert(b);
- }
- } else {
- return false;
- }
-
- self.bitset.1.clear();
- for b in borrowers {
- self.bitset.1.insert(*b);
+ LocalUsage {
+ local_use_locs: _,
+ local_consume_or_mutate_locs: clone_consume_or_mutate_locs,
+ },
+ )) = visit_local_usage(
+ &[cloned, clone],
+ mir,
+ mir::Location {
+ block: bb,
+ statement_index: mir.basic_blocks[bb].statements.len(),
+ },
+ )
+ .map(|mut vec| (vec.remove(0), vec.remove(0)))
+ {
+ CloneUsage {
+ cloned_used: !cloned_use_locs.is_empty(),
+ cloned_consume_or_mutate_loc: cloned_consume_or_mutate_locs.first().copied(),
+ // Consider non-temporary clones consumed.
+ // TODO: Actually check for mutation of non-temporaries.
+ clone_consumed_or_mutated: mir.local_kind(clone) != mir::LocalKind::Temp
+ || !clone_consume_or_mutate_locs.is_empty(),
}
-
- self.bitset.0 == self.bitset.1
- }
-
- fn local_is_alive_at(&mut self, local: mir::Local, at: mir::Location) -> bool {
- self.maybe_live.seek_after_primary_effect(at);
- self.maybe_live.contains(local)
- }
-}
-
-#[derive(Default)]
-struct TransitiveRelation {
- relations: FxHashMap<mir::Local, Vec<mir::Local>>,
-}
-impl TransitiveRelation {
- fn add(&mut self, a: mir::Local, b: mir::Local) {
- self.relations.entry(a).or_default().push(b);
- }
-
- fn reachable_from(&self, a: mir::Local, domain_size: usize) -> HybridBitSet<mir::Local> {
- let mut seen = HybridBitSet::new_empty(domain_size);
- let mut stack = vec![a];
- while let Some(u) = stack.pop() {
- if let Some(edges) = self.relations.get(&u) {
- for &v in edges {
- if seen.insert(v) {
- stack.push(v);
- }
- }
- }
+ } else {
+ CloneUsage {
+ cloned_used: true,
+ cloned_consume_or_mutate_loc: None,
+ clone_consumed_or_mutated: true,
}
- seen
}
}
diff --git a/src/tools/clippy/clippy_lints/src/redundant_pub_crate.rs b/src/tools/clippy/clippy_lints/src/redundant_pub_crate.rs
index 323326381..26075e9f7 100644
--- a/src/tools/clippy/clippy_lints/src/redundant_pub_crate.rs
+++ b/src/tools/clippy/clippy_lints/src/redundant_pub_crate.rs
@@ -46,17 +46,17 @@ impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]);
impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
if_chain! {
- if cx.tcx.visibility(item.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id());
- if !cx.access_levels.is_exported(item.def_id) && self.is_exported.last() == Some(&false);
+ if cx.tcx.visibility(item.owner_id.def_id) == ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id());
+ if !cx.effective_visibilities.is_exported(item.owner_id.def_id) && self.is_exported.last() == Some(&false);
if is_not_macro_export(item);
then {
let span = item.span.with_hi(item.ident.span.hi());
- let descr = cx.tcx.def_kind(item.def_id).descr(item.def_id.to_def_id());
+ let descr = cx.tcx.def_kind(item.owner_id).descr(item.owner_id.to_def_id());
span_lint_and_then(
cx,
REDUNDANT_PUB_CRATE,
span,
- &format!("pub(crate) {} inside private module", descr),
+ &format!("pub(crate) {descr} inside private module"),
|diag| {
diag.span_suggestion(
item.vis_span,
@@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
}
if let ItemKind::Mod { .. } = item.kind {
- self.is_exported.push(cx.access_levels.is_exported(item.def_id));
+ self.is_exported.push(cx.effective_visibilities.is_exported(item.owner_id.def_id));
}
}
diff --git a/src/tools/clippy/clippy_lints/src/redundant_slicing.rs b/src/tools/clippy/clippy_lints/src/redundant_slicing.rs
index 8693ca9af..245a02ea2 100644
--- a/src/tools/clippy/clippy_lints/src/redundant_slicing.rs
+++ b/src/tools/clippy/clippy_lints/src/redundant_slicing.rs
@@ -127,9 +127,9 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0;
let sugg = if (deref_count != 0 || !reborrow_str.is_empty()) && needs_parens_for_prefix {
- format!("({}{}{})", reborrow_str, "*".repeat(deref_count), snip)
+ format!("({reborrow_str}{}{snip})", "*".repeat(deref_count))
} else {
- format!("{}{}{}", reborrow_str, "*".repeat(deref_count), snip)
+ format!("{reborrow_str}{}{snip}", "*".repeat(deref_count))
};
(lint, help_str, sugg)
@@ -141,9 +141,9 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
if deref_ty == expr_ty {
let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0;
let sugg = if needs_parens_for_prefix {
- format!("(&{}{}*{})", mutability.prefix_str(), "*".repeat(indexed_ref_count), snip)
+ format!("(&{}{}*{snip})", mutability.prefix_str(), "*".repeat(indexed_ref_count))
} else {
- format!("&{}{}*{}", mutability.prefix_str(), "*".repeat(indexed_ref_count), snip)
+ format!("&{}{}*{snip}", mutability.prefix_str(), "*".repeat(indexed_ref_count))
};
(DEREF_BY_SLICING_LINT, "dereference the original value instead", sugg)
} else {
diff --git a/src/tools/clippy/clippy_lints/src/redundant_static_lifetimes.rs b/src/tools/clippy/clippy_lints/src/redundant_static_lifetimes.rs
index 2d751c274..60ba62c4a 100644
--- a/src/tools/clippy/clippy_lints/src/redundant_static_lifetimes.rs
+++ b/src/tools/clippy/clippy_lints/src/redundant_static_lifetimes.rs
@@ -67,7 +67,7 @@ impl RedundantStaticLifetimes {
TyKind::Path(..) | TyKind::Slice(..) | TyKind::Array(..) | TyKind::Tup(..) => {
if lifetime.ident.name == rustc_span::symbol::kw::StaticLifetime {
let snip = snippet(cx, borrow_type.ty.span, "<type>");
- let sugg = format!("&{}", snip);
+ let sugg = format!("&{snip}");
span_lint_and_then(
cx,
REDUNDANT_STATIC_LIFETIMES,
diff --git a/src/tools/clippy/clippy_lints/src/ref_option_ref.rs b/src/tools/clippy/clippy_lints/src/ref_option_ref.rs
index 42514f861..f21b3ea6c 100644
--- a/src/tools/clippy/clippy_lints/src/ref_option_ref.rs
+++ b/src/tools/clippy/clippy_lints/src/ref_option_ref.rs
@@ -52,7 +52,8 @@ impl<'tcx> LateLintPass<'tcx> for RefOptionRef {
GenericArg::Type(inner_ty) => Some(inner_ty),
_ => None,
});
- if let TyKind::Rptr(_, _) = inner_ty.kind;
+ if let TyKind::Rptr(_, ref inner_mut_ty) = inner_ty.kind;
+ if inner_mut_ty.mutbl == Mutability::Not;
then {
span_lint_and_sugg(
diff --git a/src/tools/clippy/clippy_lints/src/regex.rs b/src/tools/clippy/clippy_lints/src/regex.rs
index 6bcae0da8..1fda58fa5 100644
--- a/src/tools/clippy/clippy_lints/src/regex.rs
+++ b/src/tools/clippy/clippy_lints/src/regex.rs
@@ -172,7 +172,7 @@ fn check_regex<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) {
);
},
Err(e) => {
- span_lint(cx, INVALID_REGEX, expr.span, &format!("regex syntax error: {}", e));
+ span_lint(cx, INVALID_REGEX, expr.span, &format!("regex syntax error: {e}"));
},
}
}
@@ -200,7 +200,7 @@ fn check_regex<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) {
);
},
Err(e) => {
- span_lint(cx, INVALID_REGEX, expr.span, &format!("regex syntax error: {}", e));
+ span_lint(cx, INVALID_REGEX, expr.span, &format!("regex syntax error: {e}"));
},
}
}
diff --git a/src/tools/clippy/clippy_lints/src/renamed_lints.rs b/src/tools/clippy/clippy_lints/src/renamed_lints.rs
index 6bea6dc07..76d6ad0b2 100644
--- a/src/tools/clippy/clippy_lints/src/renamed_lints.rs
+++ b/src/tools/clippy/clippy_lints/src/renamed_lints.rs
@@ -11,8 +11,8 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
("clippy::disallowed_method", "clippy::disallowed_methods"),
("clippy::disallowed_type", "clippy::disallowed_types"),
("clippy::eval_order_dependence", "clippy::mixed_read_write_in_expression"),
- ("clippy::for_loop_over_option", "clippy::for_loops_over_fallibles"),
- ("clippy::for_loop_over_result", "clippy::for_loops_over_fallibles"),
+ ("clippy::for_loop_over_option", "for_loops_over_fallibles"),
+ ("clippy::for_loop_over_result", "for_loops_over_fallibles"),
("clippy::identity_conversion", "clippy::useless_conversion"),
("clippy::if_let_some_result", "clippy::match_result_ok"),
("clippy::logic_bug", "clippy::overly_complex_bool_expr"),
@@ -31,11 +31,13 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
("clippy::to_string_in_display", "clippy::recursive_format_impl"),
("clippy::zero_width_space", "clippy::invisible_characters"),
("clippy::drop_bounds", "drop_bounds"),
+ ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"),
("clippy::into_iter_on_array", "array_into_iter"),
("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"),
("clippy::invalid_ref", "invalid_value"),
("clippy::mem_discriminant_non_enum", "enum_intrinsics_non_enums"),
("clippy::panic_params", "non_fmt_panics"),
+ ("clippy::positional_named_format_parameters", "named_arguments_used_positionally"),
("clippy::temporary_cstring_as_ptr", "temporary_cstring_as_ptr"),
("clippy::unknown_clippy_lints", "unknown_lints"),
("clippy::unused_label", "unused_labels"),
diff --git a/src/tools/clippy/clippy_lints/src/return_self_not_must_use.rs b/src/tools/clippy/clippy_lints/src/return_self_not_must_use.rs
index 60be6bd33..b77faf732 100644
--- a/src/tools/clippy/clippy_lints/src/return_self_not_must_use.rs
+++ b/src/tools/clippy/clippy_lints/src/return_self_not_must_use.rs
@@ -74,7 +74,7 @@ fn check_method(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_def: LocalDefId, spa
if !in_external_macro(cx.sess(), span);
if decl.implicit_self.has_implicit_self();
// We only show this warning for public exported methods.
- if cx.access_levels.is_exported(fn_def);
+ if cx.effective_visibilities.is_exported(fn_def);
// We don't want to emit this lint if the `#[must_use]` attribute is already there.
if !cx.tcx.hir().attrs(hir_id).iter().any(|attr| attr.has_name(sym::must_use));
if cx.tcx.visibility(fn_def.to_def_id()).is_public();
@@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for ReturnSelfNotMustUse {
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'tcx>) {
if let TraitItemKind::Fn(ref sig, _) = item.kind {
- check_method(cx, sig.decl, item.def_id, item.span, item.hir_id());
+ check_method(cx, sig.decl, item.owner_id.def_id, item.span, item.hir_id());
}
}
}
diff --git a/src/tools/clippy/clippy_lints/src/returns.rs b/src/tools/clippy/clippy_lints/src/returns.rs
index 91553240e..2b2a41d16 100644
--- a/src/tools/clippy/clippy_lints/src/returns.rs
+++ b/src/tools/clippy/clippy_lints/src/returns.rs
@@ -1,9 +1,11 @@
-use clippy_utils::diagnostics::span_lint_hir_and_then;
+use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then};
use clippy_utils::source::{snippet_opt, snippet_with_context};
+use clippy_utils::visitors::{for_each_expr, Descend};
use clippy_utils::{fn_def_id, path_to_local_id};
+use core::ops::ControlFlow;
use if_chain::if_chain;
use rustc_errors::Applicability;
-use rustc_hir::intravisit::{walk_expr, FnKind, Visitor};
+use rustc_hir::intravisit::FnKind;
use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, HirId, MatchSource, PatKind, StmtKind};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
@@ -72,6 +74,27 @@ enum RetReplacement {
Unit,
}
+impl RetReplacement {
+ fn sugg_help(self) -> &'static str {
+ match self {
+ Self::Empty => "remove `return`",
+ Self::Block => "replace `return` with an empty block",
+ Self::Unit => "replace `return` with a unit value",
+ }
+ }
+}
+
+impl ToString for RetReplacement {
+ fn to_string(&self) -> String {
+ match *self {
+ Self::Empty => "",
+ Self::Block => "{}",
+ Self::Unit => "()",
+ }
+ .to_string()
+ }
+}
+
declare_lint_pass!(Return => [LET_AND_RETURN, NEEDLESS_RETURN]);
impl<'tcx> LateLintPass<'tcx> for Return {
@@ -139,26 +162,35 @@ impl<'tcx> LateLintPass<'tcx> for Return {
} else {
RetReplacement::Empty
};
- check_final_expr(cx, body.value, Some(body.value.span), replacement);
+ check_final_expr(cx, body.value, vec![], replacement);
},
FnKind::ItemFn(..) | FnKind::Method(..) => {
- if let ExprKind::Block(block, _) = body.value.kind {
- check_block_return(cx, block);
- }
+ check_block_return(cx, &body.value.kind, vec![]);
},
}
}
}
-fn check_block_return<'tcx>(cx: &LateContext<'tcx>, block: &Block<'tcx>) {
- if let Some(expr) = block.expr {
- check_final_expr(cx, expr, Some(expr.span), RetReplacement::Empty);
- } else if let Some(stmt) = block.stmts.iter().last() {
- match stmt.kind {
- StmtKind::Expr(expr) | StmtKind::Semi(expr) => {
- check_final_expr(cx, expr, Some(stmt.span), RetReplacement::Empty);
- },
- _ => (),
+// if `expr` is a block, check if there are needless returns in it
+fn check_block_return<'tcx>(cx: &LateContext<'tcx>, expr_kind: &ExprKind<'tcx>, semi_spans: Vec<Span>) {
+ if let ExprKind::Block(block, _) = expr_kind {
+ if let Some(block_expr) = block.expr {
+ check_final_expr(cx, block_expr, semi_spans, RetReplacement::Empty);
+ } else if let Some(stmt) = block.stmts.iter().last() {
+ match stmt.kind {
+ StmtKind::Expr(expr) => {
+ check_final_expr(cx, expr, semi_spans, RetReplacement::Empty);
+ },
+ StmtKind::Semi(semi_expr) => {
+ let mut semi_spans_and_this_one = semi_spans;
+ // we only want the span containing the semicolon so we can remove it later. From `entry.rs:382`
+ if let Some(semicolon_span) = stmt.span.trim_start(semi_expr.span) {
+ semi_spans_and_this_one.push(semicolon_span);
+ check_final_expr(cx, semi_expr, semi_spans_and_this_one, RetReplacement::Empty);
+ }
+ },
+ _ => (),
+ }
}
}
}
@@ -166,10 +198,12 @@ fn check_block_return<'tcx>(cx: &LateContext<'tcx>, block: &Block<'tcx>) {
fn check_final_expr<'tcx>(
cx: &LateContext<'tcx>,
expr: &'tcx Expr<'tcx>,
- span: Option<Span>,
+ semi_spans: Vec<Span>, /* containing all the places where we would need to remove semicolons if finding an
+ * needless return */
replacement: RetReplacement,
) {
- match expr.kind {
+ let peeled_drop_expr = expr.peel_drop_temps();
+ match &peeled_drop_expr.kind {
// simple return is always "bad"
ExprKind::Ret(ref inner) => {
if cx.tcx.hir().attrs(expr.hir_id).is_empty() {
@@ -177,24 +211,18 @@ fn check_final_expr<'tcx>(
if !borrows {
emit_return_lint(
cx,
- inner.map_or(expr.hir_id, |inner| inner.hir_id),
- span.expect("`else return` is not possible"),
+ peeled_drop_expr.span,
+ semi_spans,
inner.as_ref().map(|i| i.span),
replacement,
);
}
}
},
- // a whole block? check it!
- ExprKind::Block(block, _) => {
- check_block_return(cx, block);
- },
ExprKind::If(_, then, else_clause_opt) => {
- if let ExprKind::Block(ifblock, _) = then.kind {
- check_block_return(cx, ifblock);
- }
+ check_block_return(cx, &then.kind, semi_spans.clone());
if let Some(else_clause) = else_clause_opt {
- check_final_expr(cx, else_clause, None, RetReplacement::Empty);
+ check_block_return(cx, &else_clause.kind, semi_spans);
}
},
// a match expr, check all arms
@@ -203,123 +231,61 @@ fn check_final_expr<'tcx>(
// (except for unit type functions) so we don't match it
ExprKind::Match(_, arms, MatchSource::Normal) => {
for arm in arms.iter() {
- check_final_expr(cx, arm.body, Some(arm.body.span), RetReplacement::Unit);
+ check_final_expr(cx, arm.body, semi_spans.clone(), RetReplacement::Unit);
}
},
- ExprKind::DropTemps(expr) => check_final_expr(cx, expr, None, RetReplacement::Empty),
- _ => (),
+ // if it's a whole block, check it
+ other_expr_kind => check_block_return(cx, other_expr_kind, semi_spans),
}
}
fn emit_return_lint(
cx: &LateContext<'_>,
- emission_place: HirId,
ret_span: Span,
+ semi_spans: Vec<Span>,
inner_span: Option<Span>,
replacement: RetReplacement,
) {
if ret_span.from_expansion() {
return;
}
- match inner_span {
- Some(inner_span) => {
- let mut applicability = Applicability::MachineApplicable;
- span_lint_hir_and_then(
- cx,
- NEEDLESS_RETURN,
- emission_place,
- ret_span,
- "unneeded `return` statement",
- |diag| {
- let (snippet, _) = snippet_with_context(cx, inner_span, ret_span.ctxt(), "..", &mut applicability);
- diag.span_suggestion(ret_span, "remove `return`", snippet, applicability);
- },
- );
- },
- None => match replacement {
- RetReplacement::Empty => {
- span_lint_hir_and_then(
- cx,
- NEEDLESS_RETURN,
- emission_place,
- ret_span,
- "unneeded `return` statement",
- |diag| {
- diag.span_suggestion(
- ret_span,
- "remove `return`",
- String::new(),
- Applicability::MachineApplicable,
- );
- },
- );
- },
- RetReplacement::Block => {
- span_lint_hir_and_then(
- cx,
- NEEDLESS_RETURN,
- emission_place,
- ret_span,
- "unneeded `return` statement",
- |diag| {
- diag.span_suggestion(
- ret_span,
- "replace `return` with an empty block",
- "{}".to_string(),
- Applicability::MachineApplicable,
- );
- },
- );
- },
- RetReplacement::Unit => {
- span_lint_hir_and_then(
- cx,
- NEEDLESS_RETURN,
- emission_place,
- ret_span,
- "unneeded `return` statement",
- |diag| {
- diag.span_suggestion(
- ret_span,
- "replace `return` with a unit value",
- "()".to_string(),
- Applicability::MachineApplicable,
- );
- },
- );
- },
+ let mut applicability = Applicability::MachineApplicable;
+ let return_replacement = inner_span.map_or_else(
+ || replacement.to_string(),
+ |inner_span| {
+ let (snippet, _) = snippet_with_context(cx, inner_span, ret_span.ctxt(), "..", &mut applicability);
+ snippet.to_string()
},
- }
+ );
+ let sugg_help = if inner_span.is_some() {
+ "remove `return`"
+ } else {
+ replacement.sugg_help()
+ };
+ span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded `return` statement", |diag| {
+ diag.span_suggestion_hidden(ret_span, sugg_help, return_replacement, applicability);
+ // for each parent statement, we need to remove the semicolon
+ for semi_stmt_span in semi_spans {
+ diag.tool_only_span_suggestion(semi_stmt_span, "remove this semicolon", "", applicability);
+ }
+ });
}
fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool {
- let mut visitor = BorrowVisitor { cx, borrows: false };
- walk_expr(&mut visitor, expr);
- visitor.borrows
-}
-
-struct BorrowVisitor<'a, 'tcx> {
- cx: &'a LateContext<'tcx>,
- borrows: bool,
-}
-
-impl<'tcx> Visitor<'tcx> for BorrowVisitor<'_, 'tcx> {
- fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
- if self.borrows || expr.span.from_expansion() {
- return;
- }
-
- if let Some(def_id) = fn_def_id(self.cx, expr) {
- self.borrows = self
- .cx
+ for_each_expr(expr, |e| {
+ if let Some(def_id) = fn_def_id(cx, e)
+ && cx
.tcx
.fn_sig(def_id)
- .output()
.skip_binder()
+ .output()
.walk()
- .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_)));
+ .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_)))
+ {
+ ControlFlow::Break(())
+ } else {
+ ControlFlow::Continue(Descend::from(!expr.span.from_expansion()))
}
-
- walk_expr(self, expr);
- }
+ })
+ .is_some()
}
diff --git a/src/tools/clippy/clippy_lints/src/same_name_method.rs b/src/tools/clippy/clippy_lints/src/same_name_method.rs
index 20184d54b..caab5851b 100644
--- a/src/tools/clippy/clippy_lints/src/same_name_method.rs
+++ b/src/tools/clippy/clippy_lints/src/same_name_method.rs
@@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
let mut map = FxHashMap::<Res, ExistingName>::default();
for id in cx.tcx.hir().items() {
- if matches!(cx.tcx.def_kind(id.def_id), DefKind::Impl)
+ if matches!(cx.tcx.def_kind(id.owner_id), DefKind::Impl)
&& let item = cx.tcx.hir().item(id)
&& let ItemKind::Impl(Impl {
items,
@@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
|diag| {
diag.span_note(
trait_method_span,
- &format!("existing `{}` defined here", method_name),
+ &format!("existing `{method_name}` defined here"),
);
},
);
@@ -151,7 +151,7 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
// iterate on trait_spans?
diag.span_note(
trait_spans[0],
- &format!("existing `{}` defined here", method_name),
+ &format!("existing `{method_name}` defined here"),
);
},
);
diff --git a/src/tools/clippy/clippy_lints/src/self_named_constructors.rs b/src/tools/clippy/clippy_lints/src/self_named_constructors.rs
index 9cea4d880..71b387c66 100644
--- a/src/tools/clippy/clippy_lints/src/self_named_constructors.rs
+++ b/src/tools/clippy/clippy_lints/src/self_named_constructors.rs
@@ -51,9 +51,9 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors {
_ => return,
}
- let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
+ let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
let item = cx.tcx.hir().expect_item(parent);
- let self_ty = cx.tcx.type_of(item.def_id);
+ let self_ty = cx.tcx.type_of(item.owner_id);
let ret_ty = return_ty(cx, impl_item.hir_id());
// Do not check trait impls
diff --git a/src/tools/clippy/clippy_lints/src/semicolon_if_nothing_returned.rs b/src/tools/clippy/clippy_lints/src/semicolon_if_nothing_returned.rs
index 729694da4..66638eed9 100644
--- a/src/tools/clippy/clippy_lints/src/semicolon_if_nothing_returned.rs
+++ b/src/tools/clippy/clippy_lints/src/semicolon_if_nothing_returned.rs
@@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for SemicolonIfNothingReturned {
}
let sugg = sugg::Sugg::hir_with_macro_callsite(cx, expr, "..");
- let suggestion = format!("{0};", sugg);
+ let suggestion = format!("{sugg};");
span_lint_and_sugg(
cx,
SEMICOLON_IF_NOTHING_RETURNED,
diff --git a/src/tools/clippy/clippy_lints/src/shadow.rs b/src/tools/clippy/clippy_lints/src/shadow.rs
index 5dcdab5b8..87f966ced 100644
--- a/src/tools/clippy/clippy_lints/src/shadow.rs
+++ b/src/tools/clippy/clippy_lints/src/shadow.rs
@@ -106,10 +106,7 @@ impl_lint_pass!(Shadow => [SHADOW_SAME, SHADOW_REUSE, SHADOW_UNRELATED]);
impl<'tcx> LateLintPass<'tcx> for Shadow {
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
- let (id, ident) = match pat.kind {
- PatKind::Binding(_, hir_id, ident, _) => (hir_id, ident),
- _ => return,
- };
+ let PatKind::Binding(_, id, ident, _) = pat.kind else { return };
if pat.span.desugaring_kind().is_some() {
return;
diff --git a/src/tools/clippy/clippy_lints/src/slow_vector_initialization.rs b/src/tools/clippy/clippy_lints/src/slow_vector_initialization.rs
index c07aa00a1..760399231 100644
--- a/src/tools/clippy/clippy_lints/src/slow_vector_initialization.rs
+++ b/src/tools/clippy/clippy_lints/src/slow_vector_initialization.rs
@@ -1,9 +1,10 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::sugg::Sugg;
use clippy_utils::ty::is_type_diagnostic_item;
-use clippy_utils::{get_enclosing_block, is_expr_path_def_path, path_to_local, path_to_local_id, paths, SpanlessEq};
+use clippy_utils::{
+ get_enclosing_block, is_integer_literal, is_path_diagnostic_item, path_to_local, path_to_local_id, SpanlessEq,
+};
use if_chain::if_chain;
-use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
use rustc_hir::intravisit::{walk_block, walk_expr, walk_stmt, Visitor};
use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, PatKind, QPath, Stmt, StmtKind};
@@ -174,7 +175,7 @@ impl SlowVectorInit {
diag.span_suggestion(
vec_alloc.allocation_expr.span,
"consider replace allocation with",
- format!("vec![0; {}]", len_expr),
+ format!("vec![0; {len_expr}]"),
Applicability::Unspecified,
);
});
@@ -219,8 +220,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> {
&& path_to_local_id(self_arg, self.vec_alloc.local_id)
&& path.ident.name == sym!(resize)
// Check that is filled with 0
- && let ExprKind::Lit(ref lit) = fill_arg.kind
- && let LitKind::Int(0, _) = lit.node {
+ && is_integer_literal(fill_arg, 0) {
// Check that len expression is equals to `with_capacity` expression
if SpanlessEq::new(self.cx).eq_expr(len_arg, self.vec_alloc.len_expr) {
self.slow_expression = Some(InitializationType::Resize(expr));
@@ -254,10 +254,8 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> {
fn is_repeat_zero(&self, expr: &Expr<'_>) -> bool {
if_chain! {
if let ExprKind::Call(fn_expr, [repeat_arg]) = expr.kind;
- if is_expr_path_def_path(self.cx, fn_expr, &paths::ITER_REPEAT);
- if let ExprKind::Lit(ref lit) = repeat_arg.kind;
- if let LitKind::Int(0, _) = lit.node;
-
+ if is_path_diagnostic_item(self.cx, fn_expr, sym::iter_repeat);
+ if is_integer_literal(repeat_arg, 0);
then {
true
} else {
diff --git a/src/tools/clippy/clippy_lints/src/std_instead_of_core.rs b/src/tools/clippy/clippy_lints/src/std_instead_of_core.rs
index ffd63cc68..d6b336bef 100644
--- a/src/tools/clippy/clippy_lints/src/std_instead_of_core.rs
+++ b/src/tools/clippy/clippy_lints/src/std_instead_of_core.rs
@@ -1,6 +1,8 @@
use clippy_utils::diagnostics::span_lint_and_help;
+use rustc_hir::def_id::DefId;
use rustc_hir::{def::Res, HirId, Path, PathSegment};
use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::ty::DefIdTree;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::{sym, symbol::kw, Span};
@@ -94,6 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for StdReexports {
fn check_path(&mut self, cx: &LateContext<'tcx>, path: &Path<'tcx>, _: HirId) {
if let Res::Def(_, def_id) = path.res
&& let Some(first_segment) = get_first_segment(path)
+ && is_stable(cx, def_id)
{
let (lint, msg, help) = match first_segment.ident.name {
sym::std => match cx.tcx.crate_name(def_id.krate) {
@@ -146,3 +149,22 @@ fn get_first_segment<'tcx>(path: &Path<'tcx>) -> Option<&'tcx PathSegment<'tcx>>
_ => None,
}
}
+
+/// Checks if all ancestors of `def_id` are stable, to avoid linting
+/// [unstable moves](https://github.com/rust-lang/rust/pull/95956)
+fn is_stable(cx: &LateContext<'_>, mut def_id: DefId) -> bool {
+ loop {
+ if cx
+ .tcx
+ .lookup_stability(def_id)
+ .map_or(false, |stability| stability.is_unstable())
+ {
+ return false;
+ }
+
+ match cx.tcx.opt_parent(def_id) {
+ Some(parent) => def_id = parent,
+ None => return true,
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/strings.rs b/src/tools/clippy/clippy_lints/src/strings.rs
index 662d399ca..d356c99c8 100644
--- a/src/tools/clippy/clippy_lints/src/strings.rs
+++ b/src/tools/clippy/clippy_lints/src/strings.rs
@@ -284,7 +284,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes {
e.span,
"calling a slice of `as_bytes()` with `from_utf8` should be not necessary",
"try",
- format!("Some(&{}[{}])", snippet_app, snippet(cx, right.span, "..")),
+ format!("Some(&{snippet_app}[{}])", snippet(cx, right.span, "..")),
applicability
)
}
@@ -500,8 +500,8 @@ impl<'tcx> LateLintPass<'tcx> for TrimSplitWhitespace {
cx,
TRIM_SPLIT_WHITESPACE,
trim_span.with_hi(split_ws_span.lo()),
- &format!("found call to `str::{}` before `str::split_whitespace`", trim_fn_name),
- &format!("remove `{}()`", trim_fn_name),
+ &format!("found call to `str::{trim_fn_name}` before `str::split_whitespace`"),
+ &format!("remove `{trim_fn_name}()`"),
String::new(),
Applicability::MachineApplicable,
);
diff --git a/src/tools/clippy/clippy_lints/src/strlen_on_c_strings.rs b/src/tools/clippy/clippy_lints/src/strlen_on_c_strings.rs
index 78403d9fd..03324c66e 100644
--- a/src/tools/clippy/clippy_lints/src/strlen_on_c_strings.rs
+++ b/src/tools/clippy/clippy_lints/src/strlen_on_c_strings.rs
@@ -79,7 +79,7 @@ impl<'tcx> LateLintPass<'tcx> for StrlenOnCStrings {
span,
"using `libc::strlen` on a `CString` or `CStr` value",
"try this",
- format!("{}.{}().len()", val_name, method_name),
+ format!("{val_name}.{method_name}().len()"),
app,
);
}
diff --git a/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs b/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs
index fe8859905..eef9bdc78 100644
--- a/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs
+++ b/src/tools/clippy/clippy_lints/src/suspicious_operation_groupings.rs
@@ -326,8 +326,7 @@ fn replace_left_sugg(
applicability: &mut Applicability,
) -> String {
format!(
- "{} {} {}",
- left_suggestion,
+ "{left_suggestion} {} {}",
binop.op.to_string(),
snippet_with_applicability(cx, binop.right.span, "..", applicability),
)
@@ -340,10 +339,9 @@ fn replace_right_sugg(
applicability: &mut Applicability,
) -> String {
format!(
- "{} {} {}",
+ "{} {} {right_suggestion}",
snippet_with_applicability(cx, binop.left.span, "..", applicability),
binop.op.to_string(),
- right_suggestion,
)
}
@@ -595,7 +593,7 @@ fn ident_difference_expr_with_base_location(
| (Unary(_, _), Unary(_, _))
| (Binary(_, _, _), Binary(_, _, _))
| (Tup(_), Tup(_))
- | (MethodCall(_, _, _), MethodCall(_, _, _))
+ | (MethodCall(_, _, _, _), MethodCall(_, _, _, _))
| (Call(_, _), Call(_, _))
| (ConstBlock(_), ConstBlock(_))
| (Array(_), Array(_))
@@ -676,9 +674,8 @@ fn suggestion_with_swapped_ident(
}
Some(format!(
- "{}{}{}",
+ "{}{new_ident}{}",
snippet_with_applicability(cx, expr.span.with_hi(current_ident.span.lo()), "..", applicability),
- new_ident,
snippet_with_applicability(cx, expr.span.with_lo(current_ident.span.hi()), "..", applicability),
))
})
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 6add20c1f..b57b484bd 100644
--- a/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs
+++ b/src/tools/clippy/clippy_lints/src/suspicious_trait_impl.rs
@@ -1,8 +1,9 @@
use clippy_utils::diagnostics::span_lint;
+use clippy_utils::visitors::for_each_expr;
use clippy_utils::{binop_traits, trait_ref_of_method, BINOP_TRAITS, OP_ASSIGN_TRAITS};
+use core::ops::ControlFlow;
use if_chain::if_chain;
use rustc_hir as hir;
-use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -64,11 +65,11 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl {
// Check for more than one binary operation in the implemented function
// Linting when multiple operations are involved can result in false positives
- let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id);
+ let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id;
if let hir::Node::ImplItem(impl_item) = cx.tcx.hir().get_by_def_id(parent_fn);
if let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind;
let body = cx.tcx.hir().body(body_id);
- let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id);
+ let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id;
if let Some(trait_ref) = trait_ref_of_method(cx, parent_fn);
let trait_id = trait_ref.path.res.def_id();
if ![binop_trait_id, op_assign_trait_id].contains(&trait_id);
@@ -92,25 +93,17 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl {
}
fn count_binops(expr: &hir::Expr<'_>) -> u32 {
- let mut visitor = BinaryExprVisitor::default();
- visitor.visit_expr(expr);
- visitor.nb_binops
-}
-
-#[derive(Default)]
-struct BinaryExprVisitor {
- nb_binops: u32,
-}
-
-impl<'tcx> Visitor<'tcx> for BinaryExprVisitor {
- fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
- match expr.kind {
+ let mut count = 0u32;
+ let _: Option<!> = for_each_expr(expr, |e| {
+ if matches!(
+ e.kind,
hir::ExprKind::Binary(..)
- | hir::ExprKind::Unary(hir::UnOp::Not | hir::UnOp::Neg, _)
- | hir::ExprKind::AssignOp(..) => self.nb_binops += 1,
- _ => {},
+ | hir::ExprKind::Unary(hir::UnOp::Not | hir::UnOp::Neg, _)
+ | hir::ExprKind::AssignOp(..)
+ ) {
+ count += 1;
}
-
- walk_expr(self, expr);
- }
+ ControlFlow::Continue(())
+ });
+ count
}
diff --git a/src/tools/clippy/clippy_lints/src/swap.rs b/src/tools/clippy/clippy_lints/src/swap.rs
index 1885f3ca4..f46c21e12 100644
--- a/src/tools/clippy/clippy_lints/src/swap.rs
+++ b/src/tools/clippy/clippy_lints/src/swap.rs
@@ -96,7 +96,7 @@ fn generate_swap_warning(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>, spa
cx,
MANUAL_SWAP,
span,
- &format!("this looks like you are swapping elements of `{}` manually", slice),
+ &format!("this looks like you are swapping elements of `{slice}` manually"),
"try",
format!(
"{}.swap({}, {})",
@@ -121,16 +121,16 @@ fn generate_swap_warning(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>, spa
cx,
MANUAL_SWAP,
span,
- &format!("this looks like you are swapping `{}` and `{}` manually", first, second),
+ &format!("this looks like you are swapping `{first}` and `{second}` manually"),
|diag| {
diag.span_suggestion(
span,
"try",
- format!("{}::mem::swap({}, {})", sugg, first.mut_addr(), second.mut_addr()),
+ format!("{sugg}::mem::swap({}, {})", first.mut_addr(), second.mut_addr()),
applicability,
);
if !is_xor_based {
- diag.note(&format!("or maybe you should use `{}::mem::replace`?", sugg));
+ diag.note(&format!("or maybe you should use `{sugg}::mem::replace`?"));
}
},
);
@@ -182,7 +182,7 @@ fn check_suspicious_swap(cx: &LateContext<'_>, block: &Block<'_>) {
let rhs0 = Sugg::hir_opt(cx, rhs0);
let (what, lhs, rhs) = if let (Some(first), Some(second)) = (lhs0, rhs0) {
(
- format!(" `{}` and `{}`", first, second),
+ format!(" `{first}` and `{second}`"),
first.mut_addr().to_string(),
second.mut_addr().to_string(),
)
@@ -196,22 +196,19 @@ fn check_suspicious_swap(cx: &LateContext<'_>, block: &Block<'_>) {
span_lint_and_then(cx,
ALMOST_SWAPPED,
span,
- &format!("this looks like you are trying to swap{}", what),
+ &format!("this looks like you are trying to swap{what}"),
|diag| {
if !what.is_empty() {
diag.span_suggestion(
span,
"try",
format!(
- "{}::mem::swap({}, {})",
- sugg,
- lhs,
- rhs,
+ "{sugg}::mem::swap({lhs}, {rhs})",
),
Applicability::MaybeIncorrect,
);
diag.note(
- &format!("or maybe you should use `{}::mem::replace`?", sugg)
+ &format!("or maybe you should use `{sugg}::mem::replace`?")
);
}
});
diff --git a/src/tools/clippy/clippy_lints/src/swap_ptr_to_ref.rs b/src/tools/clippy/clippy_lints/src/swap_ptr_to_ref.rs
index 3cbbda80f..d085dda35 100644
--- a/src/tools/clippy/clippy_lints/src/swap_ptr_to_ref.rs
+++ b/src/tools/clippy/clippy_lints/src/swap_ptr_to_ref.rs
@@ -58,7 +58,7 @@ impl LateLintPass<'_> for SwapPtrToRef {
let mut app = Applicability::MachineApplicable;
let snip1 = snippet_with_context(cx, arg1_span.unwrap_or(arg1.span), ctxt, "..", &mut app).0;
let snip2 = snippet_with_context(cx, arg2_span.unwrap_or(arg2.span), ctxt, "..", &mut app).0;
- diag.span_suggestion(e.span, "use ptr::swap", format!("core::ptr::swap({}, {})", snip1, snip2), app);
+ diag.span_suggestion(e.span, "use ptr::swap", format!("core::ptr::swap({snip1}, {snip2})"), app);
}
}
);
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 651201f34..2512500a6 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
@@ -84,9 +84,9 @@ impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome {
"use of `.to_digit(..).is_some()`",
"try this",
if is_method_call {
- format!("{}.is_digit({})", char_arg_snip, radix_snip)
+ format!("{char_arg_snip}.is_digit({radix_snip})")
} else {
- format!("char::is_digit({}, {})", char_arg_snip, radix_snip)
+ format!("char::is_digit({char_arg_snip}, {radix_snip})")
},
applicability,
);
diff --git a/src/tools/clippy/clippy_lints/src/trailing_empty_array.rs b/src/tools/clippy/clippy_lints/src/trailing_empty_array.rs
index 58cc057a3..8cf3efc8d 100644
--- a/src/tools/clippy/clippy_lints/src/trailing_empty_array.rs
+++ b/src/tools/clippy/clippy_lints/src/trailing_empty_array.rs
@@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for TrailingEmptyArray {
None,
&format!(
"consider annotating `{}` with `#[repr(C)]` or another `repr` attribute",
- cx.tcx.def_path_str(item.def_id.to_def_id())
+ cx.tcx.def_path_str(item.owner_id.to_def_id())
),
);
}
diff --git a/src/tools/clippy/clippy_lints/src/trait_bounds.rs b/src/tools/clippy/clippy_lints/src/trait_bounds.rs
index a25be93b8..b5f11b4ac 100644
--- a/src/tools/clippy/clippy_lints/src/trait_bounds.rs
+++ b/src/tools/clippy/clippy_lints/src/trait_bounds.rs
@@ -128,7 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
if !bound_predicate.span.from_expansion();
if let TyKind::Path(QPath::Resolved(_, Path { segments, .. })) = bound_predicate.bounded_ty.kind;
if let Some(PathSegment {
- res: Res::SelfTy{ trait_: Some(def_id), alias_to: _ }, ..
+ res: Res::SelfTyParam { trait_: def_id }, ..
}) = segments.first();
if let Some(
Node::Item(
@@ -215,9 +215,8 @@ impl TraitBounds {
.map(|(_, _, span)| snippet_with_applicability(cx, span, "..", &mut applicability))
.join(" + ");
let hint_string = format!(
- "consider combining the bounds: `{}: {}`",
+ "consider combining the bounds: `{}: {trait_bounds}`",
snippet(cx, p.bounded_ty.span, "_"),
- trait_bounds,
);
span_lint_and_help(
cx,
diff --git a/src/tools/clippy/clippy_lints/src/transmute/crosspointer_transmute.rs b/src/tools/clippy/clippy_lints/src/transmute/crosspointer_transmute.rs
index 25d0543c8..c4b9d82fc 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/crosspointer_transmute.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/crosspointer_transmute.rs
@@ -13,10 +13,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty
cx,
CROSSPOINTER_TRANSMUTE,
e.span,
- &format!(
- "transmute from a type (`{}`) to the type that it points to (`{}`)",
- from_ty, to_ty
- ),
+ &format!("transmute from a type (`{from_ty}`) to the type that it points to (`{to_ty}`)"),
);
true
},
@@ -25,10 +22,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty
cx,
CROSSPOINTER_TRANSMUTE,
e.span,
- &format!(
- "transmute from a type (`{}`) to a pointer to that type (`{}`)",
- from_ty, to_ty
- ),
+ &format!("transmute from a type (`{from_ty}`) to a pointer to that type (`{to_ty}`)"),
);
true
},
diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_float_to_int.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_float_to_int.rs
index 1bde977cf..5ecba512b 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/transmute_float_to_int.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_float_to_int.rs
@@ -24,7 +24,7 @@ pub(super) fn check<'tcx>(
cx,
TRANSMUTE_FLOAT_TO_INT,
e.span,
- &format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
+ &format!("transmute from a `{from_ty}` to a `{to_ty}`"),
|diag| {
let mut sugg = sugg::Sugg::hir(cx, arg, "..");
@@ -38,7 +38,7 @@ pub(super) fn check<'tcx>(
if let ExprKind::Lit(lit) = &arg.kind;
if let ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) = lit.node;
then {
- let op = format!("{}{}", sugg, float_ty.name_str()).into();
+ let op = format!("{sugg}{}", float_ty.name_str()).into();
match sugg {
sugg::Sugg::MaybeParen(_) => sugg = sugg::Sugg::MaybeParen(op),
_ => sugg = sugg::Sugg::NonParen(op)
diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_bool.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_bool.rs
index 8c50b58ca..58227c53d 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_bool.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_bool.rs
@@ -23,7 +23,7 @@ pub(super) fn check<'tcx>(
cx,
TRANSMUTE_INT_TO_BOOL,
e.span,
- &format!("transmute from a `{}` to a `bool`", from_ty),
+ &format!("transmute from a `{from_ty}` to a `bool`"),
|diag| {
let arg = sugg::Sugg::hir(cx, arg, "..");
let zero = sugg::Sugg::NonParen(Cow::from("0"));
diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_char.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_char.rs
index 9e1823c37..7d31c375f 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_char.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_char.rs
@@ -23,7 +23,7 @@ pub(super) fn check<'tcx>(
cx,
TRANSMUTE_INT_TO_CHAR,
e.span,
- &format!("transmute from a `{}` to a `char`", from_ty),
+ &format!("transmute from a `{from_ty}` to a `char`"),
|diag| {
let arg = sugg::Sugg::hir(cx, arg, "..");
let arg = if let ty::Int(_) = from_ty.kind() {
@@ -34,7 +34,7 @@ pub(super) fn check<'tcx>(
diag.span_suggestion(
e.span,
"consider using",
- format!("std::char::from_u32({}).unwrap()", arg),
+ format!("std::char::from_u32({arg}).unwrap()"),
Applicability::Unspecified,
);
},
diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_float.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_float.rs
index b8703052e..cc3422edb 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_float.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_int_to_float.rs
@@ -22,7 +22,7 @@ pub(super) fn check<'tcx>(
cx,
TRANSMUTE_INT_TO_FLOAT,
e.span,
- &format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
+ &format!("transmute from a `{from_ty}` to a `{to_ty}`"),
|diag| {
let arg = sugg::Sugg::hir(cx, arg, "..");
let arg = if let ty::Int(int_ty) = from_ty.kind() {
@@ -36,7 +36,7 @@ pub(super) fn check<'tcx>(
diag.span_suggestion(
e.span,
"consider using",
- format!("{}::from_bits({})", to_ty, arg),
+ format!("{to_ty}::from_bits({arg})"),
Applicability::Unspecified,
);
},
diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_num_to_bytes.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_num_to_bytes.rs
index 52d193d11..009d5a7c8 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/transmute_num_to_bytes.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_num_to_bytes.rs
@@ -31,13 +31,13 @@ pub(super) fn check<'tcx>(
cx,
TRANSMUTE_NUM_TO_BYTES,
e.span,
- &format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
+ &format!("transmute from a `{from_ty}` to a `{to_ty}`"),
|diag| {
let arg = sugg::Sugg::hir(cx, arg, "..");
diag.span_suggestion(
e.span,
"consider using `to_ne_bytes()`",
- format!("{}.to_ne_bytes()", arg),
+ format!("{arg}.to_ne_bytes()"),
Applicability::Unspecified,
);
},
diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_ptr_to_ref.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_ptr_to_ref.rs
index 5eb03275b..12d0b866e 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/transmute_ptr_to_ref.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_ptr_to_ref.rs
@@ -25,10 +25,7 @@ pub(super) fn check<'tcx>(
cx,
TRANSMUTE_PTR_TO_REF,
e.span,
- &format!(
- "transmute from a pointer type (`{}`) to a reference type (`{}`)",
- from_ty, to_ty
- ),
+ &format!("transmute from a pointer type (`{from_ty}`) to a reference type (`{to_ty}`)"),
|diag| {
let arg = sugg::Sugg::hir(cx, arg, "..");
let (deref, cast) = if *mutbl == Mutability::Mut {
@@ -41,26 +38,25 @@ pub(super) fn check<'tcx>(
let sugg = if let Some(ty) = get_explicit_type(path) {
let ty_snip = snippet_with_applicability(cx, ty.span, "..", &mut app);
if meets_msrv(msrv, msrvs::POINTER_CAST) {
- format!("{}{}.cast::<{}>()", deref, arg.maybe_par(), ty_snip)
+ format!("{deref}{}.cast::<{ty_snip}>()", arg.maybe_par())
} else if from_ptr_ty.has_erased_regions() {
- sugg::make_unop(deref, arg.as_ty(format!("{} () as {} {}", cast, cast, ty_snip)))
- .to_string()
+ sugg::make_unop(deref, arg.as_ty(format!("{cast} () as {cast} {ty_snip}"))).to_string()
} else {
- sugg::make_unop(deref, arg.as_ty(format!("{} {}", cast, ty_snip))).to_string()
+ sugg::make_unop(deref, arg.as_ty(format!("{cast} {ty_snip}"))).to_string()
}
} else if from_ptr_ty.ty == *to_ref_ty {
if from_ptr_ty.has_erased_regions() {
if meets_msrv(msrv, msrvs::POINTER_CAST) {
- format!("{}{}.cast::<{}>()", deref, arg.maybe_par(), to_ref_ty)
+ format!("{deref}{}.cast::<{to_ref_ty}>()", arg.maybe_par())
} else {
- sugg::make_unop(deref, arg.as_ty(format!("{} () as {} {}", cast, cast, to_ref_ty)))
+ sugg::make_unop(deref, arg.as_ty(format!("{cast} () as {cast} {to_ref_ty}")))
.to_string()
}
} else {
sugg::make_unop(deref, arg).to_string()
}
} else {
- sugg::make_unop(deref, arg.as_ty(format!("{} {}", cast, to_ref_ty))).to_string()
+ sugg::make_unop(deref, arg.as_ty(format!("{cast} {to_ref_ty}"))).to_string()
};
diag.span_suggestion(e.span, "try", sugg, app);
diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_ref_to_ref.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_ref_to_ref.rs
index 707a11d36..afb7f2e13 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/transmute_ref_to_ref.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_ref_to_ref.rs
@@ -38,7 +38,7 @@ pub(super) fn check<'tcx>(
cx,
TRANSMUTE_BYTES_TO_STR,
e.span,
- &format!("transmute from a `{}` to a `{}`", from_ty, to_ty),
+ &format!("transmute from a `{from_ty}` to a `{to_ty}`"),
"consider using",
if const_context {
format!("std::str::from_utf8_unchecked{postfix}({snippet})")
diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs
index b6d7d9f5b..3d4bbbf64 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs
@@ -3,9 +3,8 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::ty::is_c_void;
use rustc_hir::Expr;
use rustc_lint::LateContext;
-use rustc_middle::ty::subst::{Subst, SubstsRef};
+use rustc_middle::ty::SubstsRef;
use rustc_middle::ty::{self, IntTy, Ty, TypeAndMut, UintTy};
-use rustc_span::DUMMY_SP;
#[expect(clippy::too_many_lines)]
pub(super) fn check<'tcx>(
@@ -28,24 +27,32 @@ pub(super) fn check<'tcx>(
// `Repr(C)` <-> unordered type.
// If the first field of the `Repr(C)` type matches then the transmute is ok
- (ReducedTy::OrderedFields(_, Some(from_sub_ty)), ReducedTy::UnorderedFields(to_sub_ty))
- | (ReducedTy::UnorderedFields(from_sub_ty), ReducedTy::OrderedFields(_, Some(to_sub_ty))) => {
+ (
+ ReducedTy::OrderedFields(_, Some(from_sub_ty)),
+ ReducedTy::UnorderedFields(to_sub_ty),
+ )
+ | (
+ ReducedTy::UnorderedFields(from_sub_ty),
+ ReducedTy::OrderedFields(_, Some(to_sub_ty)),
+ ) => {
from_ty = from_sub_ty;
to_ty = to_sub_ty;
continue;
- },
- (ReducedTy::OrderedFields(_, Some(from_sub_ty)), ReducedTy::Other(to_sub_ty)) if reduced_tys.to_fat_ptr => {
+ }
+ (ReducedTy::OrderedFields(_, Some(from_sub_ty)), ReducedTy::Other(to_sub_ty))
+ if reduced_tys.to_fat_ptr =>
+ {
from_ty = from_sub_ty;
to_ty = to_sub_ty;
continue;
- },
+ }
(ReducedTy::Other(from_sub_ty), ReducedTy::OrderedFields(_, Some(to_sub_ty)))
if reduced_tys.from_fat_ptr =>
{
from_ty = from_sub_ty;
to_ty = to_sub_ty;
continue;
- },
+ }
// ptr <-> ptr
(ReducedTy::Other(from_sub_ty), ReducedTy::Other(to_sub_ty))
@@ -55,19 +62,19 @@ pub(super) fn check<'tcx>(
from_ty = from_sub_ty;
to_ty = to_sub_ty;
continue;
- },
+ }
// fat ptr <-> (*size, *size)
(ReducedTy::Other(_), ReducedTy::UnorderedFields(to_ty))
if reduced_tys.from_fat_ptr && is_size_pair(to_ty) =>
{
return false;
- },
+ }
(ReducedTy::UnorderedFields(from_ty), ReducedTy::Other(_))
if reduced_tys.to_fat_ptr && is_size_pair(from_ty) =>
{
return false;
- },
+ }
// fat ptr -> some struct | some struct -> fat ptr
(ReducedTy::Other(_), _) if reduced_tys.from_fat_ptr => {
@@ -75,31 +82,37 @@ pub(super) fn check<'tcx>(
cx,
TRANSMUTE_UNDEFINED_REPR,
e.span,
- &format!("transmute from `{}` which has an undefined layout", from_ty_orig),
+ &format!("transmute from `{from_ty_orig}` which has an undefined layout"),
|diag| {
if from_ty_orig.peel_refs() != from_ty.peel_refs() {
- diag.note(&format!("the contained type `{}` has an undefined layout", from_ty));
+ diag.note(&format!(
+ "the contained type `{from_ty}` has an undefined layout"
+ ));
}
},
);
return true;
- },
+ }
(_, ReducedTy::Other(_)) if reduced_tys.to_fat_ptr => {
span_lint_and_then(
cx,
TRANSMUTE_UNDEFINED_REPR,
e.span,
- &format!("transmute to `{}` which has an undefined layout", to_ty_orig),
+ &format!("transmute to `{to_ty_orig}` which has an undefined layout"),
|diag| {
if to_ty_orig.peel_refs() != to_ty.peel_refs() {
- diag.note(&format!("the contained type `{}` has an undefined layout", to_ty));
+ diag.note(&format!(
+ "the contained type `{to_ty}` has an undefined layout"
+ ));
}
},
);
return true;
- },
+ }
- (ReducedTy::UnorderedFields(from_ty), ReducedTy::UnorderedFields(to_ty)) if from_ty != to_ty => {
+ (ReducedTy::UnorderedFields(from_ty), ReducedTy::UnorderedFields(to_ty))
+ if from_ty != to_ty =>
+ {
let same_adt_did = if let (ty::Adt(from_def, from_subs), ty::Adt(to_def, to_subs))
= (from_ty.kind(), to_ty.kind())
&& from_def == to_def
@@ -116,8 +129,7 @@ pub(super) fn check<'tcx>(
TRANSMUTE_UNDEFINED_REPR,
e.span,
&format!(
- "transmute from `{}` to `{}`, both of which have an undefined layout",
- from_ty_orig, to_ty_orig
+ "transmute from `{from_ty_orig}` to `{to_ty_orig}`, both of which have an undefined layout"
),
|diag| {
if let Some(same_adt_did) = same_adt_did {
@@ -127,57 +139,73 @@ pub(super) fn check<'tcx>(
));
} else {
if from_ty_orig.peel_refs() != from_ty {
- diag.note(&format!("the contained type `{}` has an undefined layout", from_ty));
+ diag.note(&format!(
+ "the contained type `{from_ty}` has an undefined layout"
+ ));
}
if to_ty_orig.peel_refs() != to_ty {
- diag.note(&format!("the contained type `{}` has an undefined layout", to_ty));
+ diag.note(&format!(
+ "the contained type `{to_ty}` has an undefined layout"
+ ));
}
}
},
);
return true;
- },
+ }
(
ReducedTy::UnorderedFields(from_ty),
- ReducedTy::Other(_) | ReducedTy::OrderedFields(..) | ReducedTy::TypeErasure { raw_ptr_only: true },
+ ReducedTy::Other(_)
+ | ReducedTy::OrderedFields(..)
+ | ReducedTy::TypeErasure { raw_ptr_only: true },
) => {
span_lint_and_then(
cx,
TRANSMUTE_UNDEFINED_REPR,
e.span,
- &format!("transmute from `{}` which has an undefined layout", from_ty_orig),
+ &format!("transmute from `{from_ty_orig}` which has an undefined layout"),
|diag| {
if from_ty_orig.peel_refs() != from_ty {
- diag.note(&format!("the contained type `{}` has an undefined layout", from_ty));
+ diag.note(&format!(
+ "the contained type `{from_ty}` has an undefined layout"
+ ));
}
},
);
return true;
- },
+ }
(
- ReducedTy::Other(_) | ReducedTy::OrderedFields(..) | ReducedTy::TypeErasure { raw_ptr_only: true },
+ ReducedTy::Other(_)
+ | ReducedTy::OrderedFields(..)
+ | ReducedTy::TypeErasure { raw_ptr_only: true },
ReducedTy::UnorderedFields(to_ty),
) => {
span_lint_and_then(
cx,
TRANSMUTE_UNDEFINED_REPR,
e.span,
- &format!("transmute into `{}` which has an undefined layout", to_ty_orig),
+ &format!("transmute into `{to_ty_orig}` which has an undefined layout"),
|diag| {
if to_ty_orig.peel_refs() != to_ty {
- diag.note(&format!("the contained type `{}` has an undefined layout", to_ty));
+ diag.note(&format!(
+ "the contained type `{to_ty}` has an undefined layout"
+ ));
}
},
);
return true;
- },
+ }
(
- ReducedTy::OrderedFields(..) | ReducedTy::Other(_) | ReducedTy::TypeErasure { raw_ptr_only: true },
- ReducedTy::OrderedFields(..) | ReducedTy::Other(_) | ReducedTy::TypeErasure { raw_ptr_only: true },
+ ReducedTy::OrderedFields(..)
+ | ReducedTy::Other(_)
+ | ReducedTy::TypeErasure { raw_ptr_only: true },
+ ReducedTy::OrderedFields(..)
+ | ReducedTy::Other(_)
+ | ReducedTy::TypeErasure { raw_ptr_only: true },
)
| (ReducedTy::UnorderedFields(_), ReducedTy::UnorderedFields(_)) => {
break;
- },
+ }
}
}
@@ -195,42 +223,38 @@ struct ReducedTys<'tcx> {
}
/// Remove references so long as both types are references.
-fn reduce_refs<'tcx>(cx: &LateContext<'tcx>, mut from_ty: Ty<'tcx>, mut to_ty: Ty<'tcx>) -> ReducedTys<'tcx> {
+fn reduce_refs<'tcx>(
+ cx: &LateContext<'tcx>,
+ mut from_ty: Ty<'tcx>,
+ mut to_ty: Ty<'tcx>,
+) -> ReducedTys<'tcx> {
let mut from_raw_ptr = false;
let mut to_raw_ptr = false;
- let (from_fat_ptr, to_fat_ptr) = loop {
- break match (from_ty.kind(), to_ty.kind()) {
- (
- &(ty::Ref(_, from_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: from_sub_ty, .. })),
- &(ty::Ref(_, to_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: to_sub_ty, .. })),
- ) => {
- from_raw_ptr = matches!(*from_ty.kind(), ty::RawPtr(_));
- from_ty = from_sub_ty;
- to_raw_ptr = matches!(*to_ty.kind(), ty::RawPtr(_));
- to_ty = to_sub_ty;
- continue;
- },
- (&(ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. })), _)
- if !unsized_ty.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env) =>
- {
- (true, false)
- },
- (_, &(ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. })))
- if !unsized_ty.is_sized(cx.tcx.at(DUMMY_SP), cx.param_env) =>
- {
- (false, true)
- },
- _ => (false, false),
+ let (from_fat_ptr, to_fat_ptr) =
+ loop {
+ break match (from_ty.kind(), to_ty.kind()) {
+ (
+ &(ty::Ref(_, from_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: from_sub_ty, .. })),
+ &(ty::Ref(_, to_sub_ty, _) | ty::RawPtr(TypeAndMut { ty: to_sub_ty, .. })),
+ ) => {
+ from_raw_ptr = matches!(*from_ty.kind(), ty::RawPtr(_));
+ from_ty = from_sub_ty;
+ to_raw_ptr = matches!(*to_ty.kind(), ty::RawPtr(_));
+ to_ty = to_sub_ty;
+ continue;
+ }
+ (
+ &(ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. })),
+ _,
+ ) if !unsized_ty.is_sized(cx.tcx, cx.param_env) => (true, false),
+ (
+ _,
+ &(ty::Ref(_, unsized_ty, _) | ty::RawPtr(TypeAndMut { ty: unsized_ty, .. })),
+ ) if !unsized_ty.is_sized(cx.tcx, cx.param_env) => (false, true),
+ _ => (false, false),
+ };
};
- };
- ReducedTys {
- from_ty,
- to_ty,
- from_raw_ptr,
- to_raw_ptr,
- from_fat_ptr,
- to_fat_ptr,
- }
+ ReducedTys { from_ty, to_ty, from_raw_ptr, to_raw_ptr, from_fat_ptr, to_fat_ptr }
}
enum ReducedTy<'tcx> {
@@ -253,11 +277,11 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
return match *ty.kind() {
ty::Array(sub_ty, _) if matches!(sub_ty.kind(), ty::Int(_) | ty::Uint(_)) => {
ReducedTy::TypeErasure { raw_ptr_only: false }
- },
+ }
ty::Array(sub_ty, _) | ty::Slice(sub_ty) => {
ty = sub_ty;
continue;
- },
+ }
ty::Tuple(args) if args.is_empty() => ReducedTy::TypeErasure { raw_ptr_only: false },
ty::Tuple(args) => {
let mut iter = args.iter();
@@ -269,7 +293,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
continue;
}
ReducedTy::UnorderedFields(ty)
- },
+ }
ty::Adt(def, substs) if def.is_struct() => {
let mut iter = def
.non_enum_variant()
@@ -288,10 +312,12 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
} else {
ReducedTy::UnorderedFields(ty)
}
- },
- ty::Adt(def, _) if def.is_enum() && (def.variants().is_empty() || is_c_void(cx, ty)) => {
+ }
+ ty::Adt(def, _)
+ if def.is_enum() && (def.variants().is_empty() || is_c_void(cx, ty)) =>
+ {
ReducedTy::TypeErasure { raw_ptr_only: false }
- },
+ }
// TODO: Check if the conversion to or from at least one of a union's fields is valid.
ty::Adt(def, _) if def.is_union() => ReducedTy::TypeErasure { raw_ptr_only: false },
ty::Foreign(_) | ty::Param(_) => ReducedTy::TypeErasure { raw_ptr_only: false },
@@ -330,7 +356,11 @@ fn same_except_params<'tcx>(subs1: SubstsRef<'tcx>, subs2: SubstsRef<'tcx>) -> b
for (ty1, ty2) in subs1.types().zip(subs2.types()).filter(|(ty1, ty2)| ty1 != ty2) {
match (ty1.kind(), ty2.kind()) {
(ty::Param(_), _) | (_, ty::Param(_)) => (),
- (ty::Adt(adt1, subs1), ty::Adt(adt2, subs2)) if adt1 == adt2 && same_except_params(subs1, subs2) => (),
+ (ty::Adt(adt1, subs1), ty::Adt(adt2, subs2))
+ if adt1 == adt2 && same_except_params(subs1, subs2) =>
+ {
+ ()
+ }
_ => return false,
}
}
diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs b/src/tools/clippy/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs
index 626d7cd46..6b444922a 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs
@@ -21,10 +21,7 @@ pub(super) fn check<'tcx>(
cx,
TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS,
e.span,
- &format!(
- "transmute from `{}` to `{}` which could be expressed as a pointer cast instead",
- from_ty, to_ty
- ),
+ &format!("transmute from `{from_ty}` to `{to_ty}` which could be expressed as a pointer cast instead"),
|diag| {
if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) {
let sugg = arg.as_ty(&to_ty.to_string()).to_string();
diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs b/src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs
index d8e349af7..19ce5ae72 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/transmuting_null.rs
@@ -1,8 +1,6 @@
use clippy_utils::consts::{constant_context, Constant};
use clippy_utils::diagnostics::span_lint;
-use clippy_utils::is_path_diagnostic_item;
-use if_chain::if_chain;
-use rustc_ast::LitKind;
+use clippy_utils::{is_integer_literal, is_path_diagnostic_item};
use rustc_hir::{Expr, ExprKind};
use rustc_lint::LateContext;
use rustc_middle::ty::Ty;
@@ -19,37 +17,28 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arg: &'t
// Catching transmute over constants that resolve to `null`.
let mut const_eval_context = constant_context(cx, cx.typeck_results());
- if_chain! {
- if let ExprKind::Path(ref _qpath) = arg.kind;
- if let Some(Constant::RawPtr(x)) = const_eval_context.expr(arg);
- if x == 0;
- then {
- span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG);
- return true;
- }
+ if let ExprKind::Path(ref _qpath) = arg.kind &&
+ let Some(Constant::RawPtr(x)) = const_eval_context.expr(arg) &&
+ x == 0
+ {
+ span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG);
+ return true;
}
// Catching:
// `std::mem::transmute(0 as *const i32)`
- if_chain! {
- if let ExprKind::Cast(inner_expr, _cast_ty) = arg.kind;
- if let ExprKind::Lit(ref lit) = inner_expr.kind;
- if let LitKind::Int(0, _) = lit.node;
- then {
- span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG);
- return true;
- }
+ if let ExprKind::Cast(inner_expr, _cast_ty) = arg.kind && is_integer_literal(inner_expr, 0) {
+ span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG);
+ return true;
}
// Catching:
// `std::mem::transmute(std::ptr::null::<i32>())`
- if_chain! {
- if let ExprKind::Call(func1, []) = arg.kind;
- if is_path_diagnostic_item(cx, func1, sym::ptr_null);
- then {
- span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG);
- return true;
- }
+ if let ExprKind::Call(func1, []) = arg.kind &&
+ is_path_diagnostic_item(cx, func1, sym::ptr_null)
+ {
+ span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG);
+ return true;
}
// FIXME:
diff --git a/src/tools/clippy/clippy_lints/src/transmute/unsound_collection_transmute.rs b/src/tools/clippy/clippy_lints/src/transmute/unsound_collection_transmute.rs
index 831b0d450..b1445311b 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/unsound_collection_transmute.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/unsound_collection_transmute.rs
@@ -37,10 +37,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty
cx,
UNSOUND_COLLECTION_TRANSMUTE,
e.span,
- &format!(
- "transmute from `{}` to `{}` with mismatched layout is unsound",
- from_ty, to_ty
- ),
+ &format!("transmute from `{from_ty}` to `{to_ty}` with mismatched layout is unsound"),
);
true
} else {
diff --git a/src/tools/clippy/clippy_lints/src/transmute/useless_transmute.rs b/src/tools/clippy/clippy_lints/src/transmute/useless_transmute.rs
index 8122cd716..f919bbd5a 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/useless_transmute.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/useless_transmute.rs
@@ -21,7 +21,7 @@ pub(super) fn check<'tcx>(
cx,
USELESS_TRANSMUTE,
e.span,
- &format!("transmute from a type (`{}`) to itself", from_ty),
+ &format!("transmute from a type (`{from_ty}`) to itself"),
);
true
},
diff --git a/src/tools/clippy/clippy_lints/src/transmute/utils.rs b/src/tools/clippy/clippy_lints/src/transmute/utils.rs
index 8bdadf244..641cdf5d3 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/utils.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/utils.rs
@@ -1,8 +1,9 @@
use rustc_hir::Expr;
+use rustc_hir_typeck::{cast, FnCtxt, Inherited};
use rustc_lint::LateContext;
use rustc_middle::ty::{cast::CastKind, Ty};
use rustc_span::DUMMY_SP;
-use rustc_typeck::check::{cast::{self, CastCheckResult}, FnCtxt, Inherited};
+use rustc_hir as hir;
// check if the component types of the transmuted collection and the result have different ABI,
// size or alignment
@@ -42,10 +43,10 @@ pub(super) fn can_be_expressed_as_pointer_cast<'tcx>(
/// messages. This function will panic if that occurs.
fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> Option<CastKind> {
let hir_id = e.hir_id;
- let local_def_id = hir_id.owner;
+ let local_def_id = hir_id.owner.def_id;
Inherited::build(cx.tcx, local_def_id).enter(|inherited| {
- let fn_ctxt = FnCtxt::new(&inherited, cx.param_env, hir_id);
+ let fn_ctxt = FnCtxt::new(inherited, cx.param_env, hir_id);
// If we already have errors, we can't be sure we can pointer cast.
assert!(
@@ -53,10 +54,10 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>
"Newly created FnCtxt contained errors"
);
- if let CastCheckResult::Deferred(check) = cast::check_cast(
+ if let Ok(check) = cast::CastCheck::new(
&fn_ctxt, e, from_ty, to_ty,
// We won't show any error to the user, so we don't care what the span is here.
- DUMMY_SP, DUMMY_SP,
+ DUMMY_SP, DUMMY_SP, hir::Constness::NotConst,
) {
let res = check.do_check(&fn_ctxt);
diff --git a/src/tools/clippy/clippy_lints/src/transmute/wrong_transmute.rs b/src/tools/clippy/clippy_lints/src/transmute/wrong_transmute.rs
index 2118f3d69..d1965565b 100644
--- a/src/tools/clippy/clippy_lints/src/transmute/wrong_transmute.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute/wrong_transmute.rs
@@ -13,7 +13,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty
cx,
WRONG_TRANSMUTE,
e.span,
- &format!("transmute from a `{}` to a pointer", from_ty),
+ &format!("transmute from a `{from_ty}` to a pointer"),
);
true
},
diff --git a/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs b/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs
index 94945b2e1..9c6629958 100644
--- a/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs
+++ b/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs
@@ -49,15 +49,15 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
let inner_snippet = snippet(cx, inner.span, "..");
let suggestion = match &inner.kind {
TyKind::TraitObject(bounds, lt_bound, _) if bounds.len() > 1 || !lt_bound.is_elided() => {
- format!("&{}({})", ltopt, &inner_snippet)
+ format!("&{ltopt}({})", &inner_snippet)
},
TyKind::Path(qpath)
if get_bounds_if_impl_trait(cx, qpath, inner.hir_id)
.map_or(false, |bounds| bounds.len() > 1) =>
{
- format!("&{}({})", ltopt, &inner_snippet)
+ format!("&{ltopt}({})", &inner_snippet)
},
- _ => format!("&{}{}", ltopt, &inner_snippet),
+ _ => format!("&{ltopt}{}", &inner_snippet),
};
span_lint_and_sugg(
cx,
@@ -104,7 +104,7 @@ fn get_bounds_if_impl_trait<'tcx>(cx: &LateContext<'tcx>, qpath: &QPath<'_>, id:
if let Some(Node::GenericParam(generic_param)) = cx.tcx.hir().get_if_local(did);
if let GenericParamKind::Type { synthetic, .. } = generic_param.kind;
if synthetic;
- if let Some(generics) = cx.tcx.hir().get_generics(id.owner);
+ if let Some(generics) = cx.tcx.hir().get_generics(id.owner.def_id);
if let Some(pred) = generics.bounds_for_param(did.expect_local()).next();
then {
Some(pred.bounds)
diff --git a/src/tools/clippy/clippy_lints/src/types/box_collection.rs b/src/tools/clippy/clippy_lints/src/types/box_collection.rs
index ba51404d2..08020ce66 100644
--- a/src/tools/clippy/clippy_lints/src/types/box_collection.rs
+++ b/src/tools/clippy/clippy_lints/src/types/box_collection.rs
@@ -16,7 +16,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
_ => "<..>",
};
- let box_content = format!("{outer}{generic}", outer = item_type);
+ let box_content = format!("{item_type}{generic}");
span_lint_and_help(
cx,
BOX_COLLECTION,
diff --git a/src/tools/clippy/clippy_lints/src/types/mod.rs b/src/tools/clippy/clippy_lints/src/types/mod.rs
index 353a6f6b8..f6de87b05 100644
--- a/src/tools/clippy/clippy_lints/src/types/mod.rs
+++ b/src/tools/clippy/clippy_lints/src/types/mod.rs
@@ -313,13 +313,13 @@ impl_lint_pass!(Types => [BOX_COLLECTION, VEC_BOX, OPTION_OPTION, LINKEDLIST, BO
impl<'tcx> LateLintPass<'tcx> for Types {
fn check_fn(&mut self, cx: &LateContext<'_>, _: FnKind<'_>, decl: &FnDecl<'_>, _: &Body<'_>, _: Span, id: HirId) {
let is_in_trait_impl =
- if let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_def_id(cx.tcx.hir().get_parent_item(id)) {
+ if let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_def_id(cx.tcx.hir().get_parent_item(id).def_id) {
matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }))
} else {
false
};
- let is_exported = cx.access_levels.is_exported(cx.tcx.hir().local_def_id(id));
+ let is_exported = cx.effective_visibilities.is_exported(cx.tcx.hir().local_def_id(id));
self.check_fn_decl(
cx,
@@ -333,7 +333,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
}
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
- let is_exported = cx.access_levels.is_exported(item.def_id);
+ let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id);
match item.kind {
ItemKind::Static(ty, _, _) | ItemKind::Const(ty, _) => self.check_ty(
@@ -352,8 +352,10 @@ impl<'tcx> LateLintPass<'tcx> for Types {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
match item.kind {
ImplItemKind::Const(ty, _) => {
- let is_in_trait_impl = if let Some(hir::Node::Item(item)) =
- cx.tcx.hir().find_by_def_id(cx.tcx.hir().get_parent_item(item.hir_id()))
+ let is_in_trait_impl = if let Some(hir::Node::Item(item)) = cx
+ .tcx
+ .hir()
+ .find_by_def_id(cx.tcx.hir().get_parent_item(item.hir_id()).def_id)
{
matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }))
} else {
@@ -372,12 +374,12 @@ impl<'tcx> LateLintPass<'tcx> for Types {
// Methods are covered by check_fn.
// Type aliases are ignored because oftentimes it's impossible to
// make type alias declaration in trait simpler, see #1013
- ImplItemKind::Fn(..) | ImplItemKind::TyAlias(..) => (),
+ ImplItemKind::Fn(..) | ImplItemKind::Type(..) => (),
}
}
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
- let is_exported = cx.access_levels.is_exported(cx.tcx.hir().local_def_id(field.hir_id));
+ let is_exported = cx.effective_visibilities.is_exported(cx.tcx.hir().local_def_id(field.hir_id));
self.check_ty(
cx,
@@ -390,7 +392,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
}
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &TraitItem<'_>) {
- let is_exported = cx.access_levels.is_exported(item.def_id);
+ let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id);
let context = CheckTyContext {
is_exported,
@@ -535,7 +537,7 @@ impl Types {
QPath::LangItem(..) => {},
}
},
- TyKind::Rptr(ref lt, ref mut_ty) => {
+ TyKind::Rptr(lt, ref mut_ty) => {
context.is_nested_call = true;
if !borrowed_box::check(cx, hir_ty, lt, mut_ty) {
self.check_ty(cx, mut_ty.ty, context);
diff --git a/src/tools/clippy/clippy_lints/src/types/rc_buffer.rs b/src/tools/clippy/clippy_lints/src/types/rc_buffer.rs
index 4d72a29e8..fa567b9b2 100644
--- a/src/tools/clippy/clippy_lints/src/types/rc_buffer.rs
+++ b/src/tools/clippy/clippy_lints/src/types/rc_buffer.rs
@@ -9,6 +9,7 @@ use rustc_span::symbol::sym;
use super::RC_BUFFER;
pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
+ let app = Applicability::Unspecified;
if cx.tcx.is_diagnostic_item(sym::Rc, def_id) {
if let Some(alternate) = match_buffer_type(cx, qpath) {
span_lint_and_sugg(
@@ -17,8 +18,8 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
hir_ty.span,
"usage of `Rc<T>` when T is a buffer type",
"try",
- format!("Rc<{}>", alternate),
- Applicability::MachineApplicable,
+ format!("Rc<{alternate}>"),
+ app,
);
} else {
let Some(ty) = qpath_generic_tys(qpath).next() else { return false };
@@ -26,15 +27,12 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
if !cx.tcx.is_diagnostic_item(sym::Vec, id) {
return false;
}
- let qpath = match &ty.kind {
- TyKind::Path(qpath) => qpath,
- _ => return false,
- };
+ let TyKind::Path(qpath) = &ty.kind else { return false };
let inner_span = match qpath_generic_tys(qpath).next() {
Some(ty) => ty.span,
None => return false,
};
- let mut applicability = Applicability::MachineApplicable;
+ let mut applicability = app;
span_lint_and_sugg(
cx,
RC_BUFFER,
@@ -45,7 +43,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
"Rc<[{}]>",
snippet_with_applicability(cx, inner_span, "..", &mut applicability)
),
- Applicability::MachineApplicable,
+ app,
);
return true;
}
@@ -57,23 +55,20 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
hir_ty.span,
"usage of `Arc<T>` when T is a buffer type",
"try",
- format!("Arc<{}>", alternate),
- Applicability::MachineApplicable,
+ format!("Arc<{alternate}>"),
+ app,
);
} else if let Some(ty) = qpath_generic_tys(qpath).next() {
let Some(id) = path_def_id(cx, ty) else { return false };
if !cx.tcx.is_diagnostic_item(sym::Vec, id) {
return false;
}
- let qpath = match &ty.kind {
- TyKind::Path(qpath) => qpath,
- _ => return false,
- };
+ let TyKind::Path(qpath) = &ty.kind else { return false };
let inner_span = match qpath_generic_tys(qpath).next() {
Some(ty) => ty.span,
None => return false,
};
- let mut applicability = Applicability::MachineApplicable;
+ let mut applicability = app;
span_lint_and_sugg(
cx,
RC_BUFFER,
@@ -84,7 +79,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
"Arc<[{}]>",
snippet_with_applicability(cx, inner_span, "..", &mut applicability)
),
- Applicability::MachineApplicable,
+ app,
);
return true;
}
diff --git a/src/tools/clippy/clippy_lints/src/types/redundant_allocation.rs b/src/tools/clippy/clippy_lints/src/types/redundant_allocation.rs
index a1312fcda..2b964b64a 100644
--- a/src/tools/clippy/clippy_lints/src/types/redundant_allocation.rs
+++ b/src/tools/clippy/clippy_lints/src/types/redundant_allocation.rs
@@ -3,13 +3,19 @@ use clippy_utils::source::{snippet, snippet_with_applicability};
use clippy_utils::{path_def_id, qpath_generic_tys};
use rustc_errors::Applicability;
use rustc_hir::{self as hir, def_id::DefId, QPath, TyKind};
+use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::LateContext;
use rustc_span::symbol::sym;
-use rustc_typeck::hir_ty_to_ty;
use super::{utils, REDUNDANT_ALLOCATION};
-pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
+pub(super) fn check(
+ cx: &LateContext<'_>,
+ hir_ty: &hir::Ty<'_>,
+ qpath: &QPath<'_>,
+ def_id: DefId,
+) -> bool {
+ let mut applicability = Applicability::MaybeIncorrect;
let outer_sym = if Some(def_id) == cx.tcx.lang_items().owned_box() {
"Box"
} else if cx.tcx.is_diagnostic_item(sym::Rc, def_id) {
@@ -21,19 +27,21 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
};
if let Some(span) = utils::match_borrows_parameter(cx, qpath) {
- let mut applicability = Applicability::MaybeIncorrect;
let generic_snippet = snippet_with_applicability(cx, span, "..", &mut applicability);
span_lint_and_then(
cx,
REDUNDANT_ALLOCATION,
hir_ty.span,
- &format!("usage of `{}<{}>`", outer_sym, generic_snippet),
+ &format!("usage of `{outer_sym}<{generic_snippet}>`"),
|diag| {
- diag.span_suggestion(hir_ty.span, "try", format!("{}", generic_snippet), applicability);
+ diag.span_suggestion(
+ hir_ty.span,
+ "try",
+ format!("{generic_snippet}"),
+ applicability,
+ );
diag.note(&format!(
- "`{generic}` is already a pointer, `{outer}<{generic}>` allocates a pointer on the heap",
- outer = outer_sym,
- generic = generic_snippet
+ "`{generic_snippet}` is already a pointer, `{outer_sym}<{generic_snippet}>` allocates a pointer on the heap"
));
},
);
@@ -49,42 +57,37 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
_ => return false,
};
- let inner_qpath = match &ty.kind {
- TyKind::Path(inner_qpath) => inner_qpath,
- _ => return false,
+ let TyKind::Path(inner_qpath) = &ty.kind else {
+ return false
};
let inner_span = match qpath_generic_tys(inner_qpath).next() {
Some(ty) => {
// Reallocation of a fat pointer causes it to become thin. `hir_ty_to_ty` is safe to use
// here because `mod.rs` guarantees this lint is only run on types outside of bodies and
// is not run on locals.
- if !hir_ty_to_ty(cx.tcx, ty).is_sized(cx.tcx.at(ty.span), cx.param_env) {
+ if !hir_ty_to_ty(cx.tcx, ty).is_sized(cx.tcx, cx.param_env) {
return false;
}
ty.span
- },
+ }
None => return false,
};
if inner_sym == outer_sym {
- let mut applicability = Applicability::MaybeIncorrect;
let generic_snippet = snippet_with_applicability(cx, inner_span, "..", &mut applicability);
span_lint_and_then(
cx,
REDUNDANT_ALLOCATION,
hir_ty.span,
- &format!("usage of `{}<{}<{}>>`", outer_sym, inner_sym, generic_snippet),
+ &format!("usage of `{outer_sym}<{inner_sym}<{generic_snippet}>>`"),
|diag| {
diag.span_suggestion(
hir_ty.span,
"try",
- format!("{}<{}>", outer_sym, generic_snippet),
+ format!("{outer_sym}<{generic_snippet}>"),
applicability,
);
diag.note(&format!(
- "`{inner}<{generic}>` is already on the heap, `{outer}<{inner}<{generic}>>` makes an extra allocation",
- outer = outer_sym,
- inner = inner_sym,
- generic = generic_snippet
+ "`{inner_sym}<{generic_snippet}>` is already on the heap, `{outer_sym}<{inner_sym}<{generic_snippet}>>` makes an extra allocation"
));
},
);
@@ -94,19 +97,13 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
cx,
REDUNDANT_ALLOCATION,
hir_ty.span,
- &format!("usage of `{}<{}<{}>>`", outer_sym, inner_sym, generic_snippet),
+ &format!("usage of `{outer_sym}<{inner_sym}<{generic_snippet}>>`"),
|diag| {
diag.note(&format!(
- "`{inner}<{generic}>` is already on the heap, `{outer}<{inner}<{generic}>>` makes an extra allocation",
- outer = outer_sym,
- inner = inner_sym,
- generic = generic_snippet
+ "`{inner_sym}<{generic_snippet}>` is already on the heap, `{outer_sym}<{inner_sym}<{generic_snippet}>>` makes an extra allocation"
));
diag.help(&format!(
- "consider using just `{outer}<{generic}>` or `{inner}<{generic}>`",
- outer = outer_sym,
- inner = inner_sym,
- generic = generic_snippet
+ "consider using just `{outer_sym}<{generic_snippet}>` or `{inner_sym}<{generic_snippet}>`"
));
},
);
diff --git a/src/tools/clippy/clippy_lints/src/types/vec_box.rs b/src/tools/clippy/clippy_lints/src/types/vec_box.rs
index b2f536ca7..9ad2cb853 100644
--- a/src/tools/clippy/clippy_lints/src/types/vec_box.rs
+++ b/src/tools/clippy/clippy_lints/src/types/vec_box.rs
@@ -4,11 +4,11 @@ use clippy_utils::source::snippet;
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{self as hir, def_id::DefId, GenericArg, QPath, TyKind};
+use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::LateContext;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::TypeVisitable;
use rustc_span::symbol::sym;
-use rustc_typeck::hir_ty_to_ty;
use super::VEC_BOX;
@@ -40,7 +40,7 @@ pub(super) fn check(
});
let ty_ty = hir_ty_to_ty(cx.tcx, boxed_ty);
if !ty_ty.has_escaping_bound_vars();
- if ty_ty.is_sized(cx.tcx.at(ty.span), cx.param_env);
+ if ty_ty.is_sized(cx.tcx, cx.param_env);
if let Ok(ty_ty_size) = cx.layout_of(ty_ty).map(|l| l.size.bytes());
if ty_ty_size <= box_size_threshold;
then {
diff --git a/src/tools/clippy/clippy_lints/src/uninit_vec.rs b/src/tools/clippy/clippy_lints/src/uninit_vec.rs
index 3f99bd3f3..1ab0162a8 100644
--- a/src/tools/clippy/clippy_lints/src/uninit_vec.rs
+++ b/src/tools/clippy/clippy_lints/src/uninit_vec.rs
@@ -1,7 +1,7 @@
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
use clippy_utils::higher::{get_vec_init_kind, VecInitKind};
use clippy_utils::ty::{is_type_diagnostic_item, is_uninit_value_valid_for_ty};
-use clippy_utils::{is_lint_allowed, path_to_local_id, peel_hir_expr_while, SpanlessEq};
+use clippy_utils::{is_integer_literal, is_lint_allowed, path_to_local_id, peel_hir_expr_while, SpanlessEq};
use rustc_hir::{Block, Expr, ExprKind, HirId, PatKind, PathSegment, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
@@ -211,9 +211,12 @@ fn extract_set_len_self<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Opt
}
});
match expr.kind {
- ExprKind::MethodCall(path, self_expr, [_], _) => {
+ ExprKind::MethodCall(path, self_expr, [arg], _) => {
let self_type = cx.typeck_results().expr_ty(self_expr).peel_refs();
- if is_type_diagnostic_item(cx, self_type, sym::Vec) && path.ident.name.as_str() == "set_len" {
+ if is_type_diagnostic_item(cx, self_type, sym::Vec)
+ && path.ident.name.as_str() == "set_len"
+ && !is_integer_literal(arg, 0)
+ {
Some((self_expr, expr.span))
} else {
None
diff --git a/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs b/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs
index c0a4f3fba..130728862 100644
--- a/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs
+++ b/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs
@@ -1,5 +1,4 @@
use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
-use clippy_utils::{get_trait_def_id, paths};
use if_chain::if_chain;
use rustc_hir::def_id::DefId;
use rustc_hir::{Closure, Expr, ExprKind, StmtKind};
@@ -7,7 +6,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_middle::ty::{GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate};
use rustc_session::{declare_lint_pass, declare_tool_lint};
-use rustc_span::{BytePos, Span};
+use rustc_span::{sym, BytePos, Span};
declare_clippy_lint! {
/// ### What it does
@@ -80,7 +79,7 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve
let fn_sig = cx.tcx.fn_sig(def_id);
let generics = cx.tcx.predicates_of(def_id);
let fn_mut_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().fn_mut_trait());
- let ord_preds = get_trait_predicates_for_trait_id(cx, generics, get_trait_def_id(cx, &paths::ORD));
+ let ord_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.get_diagnostic_item(sym::Ord));
let partial_ord_preds =
get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().partial_ord_trait());
// Trying to call erase_late_bound_regions on fn_sig.inputs() gives the following error
@@ -99,11 +98,15 @@ fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Ve
if trait_pred.self_ty() == inp;
if let Some(return_ty_pred) = get_projection_pred(cx, generics, *trait_pred);
then {
- if ord_preds.iter().any(|ord| Some(ord.self_ty()) == return_ty_pred.term.ty()) {
+ if ord_preds
+ .iter()
+ .any(|ord| Some(ord.self_ty()) == return_ty_pred.term.ty())
+ {
args_to_check.push((i, "Ord".to_string()));
- } else if partial_ord_preds.iter().any(|pord| {
- pord.self_ty() == return_ty_pred.term.ty().unwrap()
- }) {
+ } else if partial_ord_preds
+ .iter()
+ .any(|pord| pord.self_ty() == return_ty_pred.term.ty().unwrap())
+ {
args_to_check.push((i, "PartialOrd".to_string()));
}
}
@@ -157,8 +160,7 @@ impl<'tcx> LateLintPass<'tcx> for UnitReturnExpectingOrd {
span,
&format!(
"this closure returns \
- the unit type which also implements {}",
- trait_name
+ the unit type which also implements {trait_name}"
),
);
},
@@ -169,8 +171,7 @@ impl<'tcx> LateLintPass<'tcx> for UnitReturnExpectingOrd {
span,
&format!(
"this closure returns \
- the unit type which also implements {}",
- trait_name
+ the unit type which also implements {trait_name}"
),
Some(last_semi),
"probably caused by this trailing semicolon",
diff --git a/src/tools/clippy/clippy_lints/src/unit_types/unit_arg.rs b/src/tools/clippy/clippy_lints/src/unit_types/unit_arg.rs
index a6f777abc..f6d3fb00f 100644
--- a/src/tools/clippy/clippy_lints/src/unit_types/unit_arg.rs
+++ b/src/tools/clippy/clippy_lints/src/unit_types/unit_arg.rs
@@ -74,7 +74,7 @@ fn lint_unit_args(cx: &LateContext<'_>, expr: &Expr<'_>, args_to_recover: &[&Exp
cx,
UNIT_ARG,
expr.span,
- &format!("passing {}unit value{} to a function", singular, plural),
+ &format!("passing {singular}unit value{plural} to a function"),
|db| {
let mut or = "";
args_to_recover
@@ -129,7 +129,7 @@ fn lint_unit_args(cx: &LateContext<'_>, expr: &Expr<'_>, args_to_recover: &[&Exp
if arg_snippets_without_empty_blocks.is_empty() {
db.multipart_suggestion(
- &format!("use {}unit literal{} instead", singular, plural),
+ &format!("use {singular}unit literal{plural} instead"),
args_to_recover
.iter()
.map(|arg| (arg.span, "()".to_string()))
@@ -143,8 +143,7 @@ fn lint_unit_args(cx: &LateContext<'_>, expr: &Expr<'_>, args_to_recover: &[&Exp
db.span_suggestion(
expr.span,
&format!(
- "{}move the expression{} in front of the call and replace {} with the unit literal `()`",
- or, empty_or_s, it_or_them
+ "{or}move the expression{empty_or_s} in front of the call and replace {it_or_them} with the unit literal `()`"
),
sugg,
applicability,
diff --git a/src/tools/clippy/clippy_lints/src/unit_types/unit_cmp.rs b/src/tools/clippy/clippy_lints/src/unit_types/unit_cmp.rs
index 1dd8895eb..226495dcb 100644
--- a/src/tools/clippy/clippy_lints/src/unit_types/unit_cmp.rs
+++ b/src/tools/clippy/clippy_lints/src/unit_types/unit_cmp.rs
@@ -22,7 +22,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
cx,
UNIT_CMP,
macro_call.span,
- &format!("`{}` of unit values detected. This will always {}", macro_name, result),
+ &format!("`{macro_name}` of unit values detected. This will always {result}"),
);
}
return;
@@ -40,9 +40,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
UNIT_CMP,
expr.span,
&format!(
- "{}-comparison of unit values detected. This will always be {}",
- op.as_str(),
- result
+ "{}-comparison of unit values detected. This will always be {result}",
+ op.as_str()
),
);
}
diff --git a/src/tools/clippy/clippy_lints/src/unnecessary_owned_empty_strings.rs b/src/tools/clippy/clippy_lints/src/unnecessary_owned_empty_strings.rs
index 8a4f4c0ad..016aacbf9 100644
--- a/src/tools/clippy/clippy_lints/src/unnecessary_owned_empty_strings.rs
+++ b/src/tools/clippy/clippy_lints/src/unnecessary_owned_empty_strings.rs
@@ -3,7 +3,7 @@ use clippy_utils::{match_def_path, paths};
use if_chain::if_chain;
use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
-use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability};
+use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryOwnedEmptyStrings {
);
} else {
if_chain! {
- if match_def_path(cx, fun_def_id, &paths::FROM_FROM);
+ if cx.tcx.lang_items().require(LangItem::FromFrom).ok() == Some(fun_def_id);
if let [.., last_arg] = args;
if let ExprKind::Lit(spanned) = &last_arg.kind;
if let LitKind::Str(symbol, _) = spanned.node;
diff --git a/src/tools/clippy/clippy_lints/src/unnecessary_self_imports.rs b/src/tools/clippy/clippy_lints/src/unnecessary_self_imports.rs
index 839a4bdab..bc0dd263d 100644
--- a/src/tools/clippy/clippy_lints/src/unnecessary_self_imports.rs
+++ b/src/tools/clippy/clippy_lints/src/unnecessary_self_imports.rs
@@ -57,7 +57,7 @@ impl EarlyLintPass for UnnecessarySelfImports {
format!(
"{}{};",
last_segment.ident,
- if let UseTreeKind::Simple(Some(alias), ..) = self_tree.kind { format!(" as {}", alias) } else { String::new() },
+ if let UseTreeKind::Simple(Some(alias), ..) = self_tree.kind { format!(" as {alias}") } else { String::new() },
),
Applicability::MaybeIncorrect,
);
diff --git a/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs b/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs
index 2c40827db..60b46854b 100644
--- a/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs
+++ b/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs
@@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::snippet;
-use clippy_utils::{contains_return, is_lang_ctor, return_ty, visitors::find_all_ret_expressions};
+use clippy_utils::{contains_return, is_res_lang_ctor, path_res, return_ty, visitors::find_all_ret_expressions};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::intravisit::FnKind;
@@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
match fn_kind {
FnKind::ItemFn(..) | FnKind::Method(..) => {
let def_id = cx.tcx.hir().local_def_id(hir_id);
- if self.avoid_breaking_exported_api && cx.access_levels.is_exported(def_id) {
+ if self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(def_id) {
return;
}
},
@@ -120,9 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
if !ret_expr.span.from_expansion();
// Check if a function call.
if let ExprKind::Call(func, [arg]) = ret_expr.kind;
- // Check if OPTION_SOME or RESULT_OK, depending on return type.
- if let ExprKind::Path(qpath) = &func.kind;
- if is_lang_ctor(cx, qpath, lang_item);
+ if is_res_lang_ctor(cx, path_res(cx, func), lang_item);
// Make sure the function argument does not contain a return expression.
if !contains_return(arg);
then {
@@ -153,11 +151,8 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
)
} else {
(
- format!(
- "this function's return value is unnecessarily wrapped by `{}`",
- return_type_label
- ),
- format!("remove `{}` from the return type...", return_type_label),
+ format!("this function's return value is unnecessarily wrapped by `{return_type_label}`"),
+ format!("remove `{return_type_label}` from the return type..."),
inner_type.to_string(),
"...and then change returning expressions",
)
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 fb73c3866..b305dae76 100644
--- a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs
+++ b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs
@@ -163,9 +163,8 @@ fn unnest_or_patterns(pat: &mut P<Pat>) -> bool {
noop_visit_pat(p, self);
// Don't have an or-pattern? Just quit early on.
- let alternatives = match &mut p.kind {
- Or(ps) => ps,
- _ => return,
+ let Or(alternatives) = &mut p.kind else {
+ return
};
// Collapse or-patterns directly nested in or-patterns.
diff --git a/src/tools/clippy/clippy_lints/src/unsafe_removed_from_name.rs b/src/tools/clippy/clippy_lints/src/unsafe_removed_from_name.rs
index 64f7a055c..32cd46812 100644
--- a/src/tools/clippy/clippy_lints/src/unsafe_removed_from_name.rs
+++ b/src/tools/clippy/clippy_lints/src/unsafe_removed_from_name.rs
@@ -65,10 +65,7 @@ fn unsafe_to_safe_check(old_name: Ident, new_name: Ident, cx: &EarlyContext<'_>,
cx,
UNSAFE_REMOVED_FROM_NAME,
span,
- &format!(
- "removed `unsafe` from the name of `{}` in use as `{}`",
- old_str, new_str
- ),
+ &format!("removed `unsafe` from the name of `{old_str}` in use as `{new_str}`"),
);
}
}
diff --git a/src/tools/clippy/clippy_lints/src/unused_io_amount.rs b/src/tools/clippy/clippy_lints/src/unused_io_amount.rs
index b38d71784..92053cec5 100644
--- a/src/tools/clippy/clippy_lints/src/unused_io_amount.rs
+++ b/src/tools/clippy/clippy_lints/src/unused_io_amount.rs
@@ -1,8 +1,9 @@
use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
-use clippy_utils::{is_try, match_trait_method, paths};
+use clippy_utils::{is_trait_method, is_try, match_trait_method, paths};
use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::sym;
declare_clippy_lint! {
/// ### What it does
@@ -46,9 +47,8 @@ declare_lint_pass!(UnusedIoAmount => [UNUSED_IO_AMOUNT]);
impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) {
- let expr = match s.kind {
- hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr) => expr,
- _ => return,
+ let (hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr)) = s.kind else {
+ return
};
match expr.kind {
@@ -116,13 +116,13 @@ fn check_method_call(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Exp
match_trait_method(cx, call, &paths::FUTURES_IO_ASYNCREADEXT)
|| match_trait_method(cx, call, &paths::TOKIO_IO_ASYNCREADEXT)
} else {
- match_trait_method(cx, call, &paths::IO_READ)
+ is_trait_method(cx, call, sym::IoRead)
};
let write_trait = if is_await {
match_trait_method(cx, call, &paths::FUTURES_IO_ASYNCWRITEEXT)
|| match_trait_method(cx, call, &paths::TOKIO_IO_ASYNCWRITEEXT)
} else {
- match_trait_method(cx, call, &paths::IO_WRITE)
+ is_trait_method(cx, call, sym::IoWrite)
};
match (read_trait, write_trait, symbol, is_await) {
diff --git a/src/tools/clippy/clippy_lints/src/unused_peekable.rs b/src/tools/clippy/clippy_lints/src/unused_peekable.rs
index cc8656435..f1cebf0f9 100644
--- a/src/tools/clippy/clippy_lints/src/unused_peekable.rs
+++ b/src/tools/clippy/clippy_lints/src/unused_peekable.rs
@@ -6,6 +6,7 @@ use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::lang_items::LangItem;
use rustc_hir::{Block, Expr, ExprKind, HirId, Local, Node, PatKind, PathSegment, StmtKind};
use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::hir::nested_filter::OnlyBodies;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::sym;
@@ -109,8 +110,14 @@ impl<'a, 'tcx> PeekableVisitor<'a, 'tcx> {
}
}
-impl<'tcx> Visitor<'_> for PeekableVisitor<'_, 'tcx> {
- fn visit_expr(&mut self, ex: &'_ Expr<'_>) {
+impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
+ type NestedFilter = OnlyBodies;
+
+ fn nested_visit_map(&mut self) -> Self::Map {
+ self.cx.tcx.hir()
+ }
+
+ fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
if self.found_peek_call {
return;
}
@@ -136,12 +143,11 @@ impl<'tcx> Visitor<'_> for PeekableVisitor<'_, 'tcx> {
return;
}
- if args.iter().any(|arg| {
- matches!(arg.kind, ExprKind::Path(_)) && arg_is_mut_peekable(self.cx, arg)
- }) {
+ if args.iter().any(|arg| arg_is_mut_peekable(self.cx, arg)) {
self.found_peek_call = true;
- return;
}
+
+ return;
},
// Catch anything taking a Peekable mutably
ExprKind::MethodCall(
@@ -190,21 +196,21 @@ impl<'tcx> Visitor<'_> for PeekableVisitor<'_, 'tcx> {
Node::Local(Local { init: Some(init), .. }) => {
if arg_is_mut_peekable(self.cx, init) {
self.found_peek_call = true;
- return;
}
- break;
+ return;
},
- Node::Stmt(stmt) => match stmt.kind {
- StmtKind::Expr(_) | StmtKind::Semi(_) => {},
- _ => {
- self.found_peek_call = true;
- return;
- },
+ Node::Stmt(stmt) => {
+ match stmt.kind {
+ StmtKind::Local(_) | StmtKind::Item(_) => self.found_peek_call = true,
+ StmtKind::Expr(_) | StmtKind::Semi(_) => {},
+ }
+
+ return;
},
Node::Block(_) | Node::ExprField(_) => {},
_ => {
- break;
+ return;
},
}
}
diff --git a/src/tools/clippy/clippy_lints/src/unused_rounding.rs b/src/tools/clippy/clippy_lints/src/unused_rounding.rs
index 72d8a4431..316493729 100644
--- a/src/tools/clippy/clippy_lints/src/unused_rounding.rs
+++ b/src/tools/clippy/clippy_lints/src/unused_rounding.rs
@@ -30,11 +30,10 @@ declare_clippy_lint! {
declare_lint_pass!(UnusedRounding => [UNUSED_ROUNDING]);
fn is_useless_rounding(expr: &Expr) -> Option<(&str, String)> {
- if let ExprKind::MethodCall(name_ident, args, _) = &expr.kind
+ if let ExprKind::MethodCall(name_ident, receiver, _, _) = &expr.kind
&& let method_name = name_ident.ident.name.as_str()
&& (method_name == "ceil" || method_name == "round" || method_name == "floor")
- && !args.is_empty()
- && let ExprKind::Lit(spanned) = &args[0].kind
+ && let ExprKind::Lit(spanned) = &receiver.kind
&& let LitKind::Float(symbol, ty) = spanned.kind {
let f = symbol.as_str().parse::<f64>().unwrap();
let f_str = symbol.to_string() + if let LitFloatType::Suffixed(ty) = ty {
@@ -59,8 +58,8 @@ impl EarlyLintPass for UnusedRounding {
cx,
UNUSED_ROUNDING,
expr.span,
- &format!("used the `{}` method with a whole number float", method_name),
- &format!("remove the `{}` method call", method_name),
+ &format!("used the `{method_name}` method with a whole number float"),
+ &format!("remove the `{method_name}` method call"),
float,
Applicability::MachineApplicable,
);
diff --git a/src/tools/clippy/clippy_lints/src/unused_self.rs b/src/tools/clippy/clippy_lints/src/unused_self.rs
index 51c65d898..42bccc721 100644
--- a/src/tools/clippy/clippy_lints/src/unused_self.rs
+++ b/src/tools/clippy/clippy_lints/src/unused_self.rs
@@ -54,14 +54,14 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf {
if impl_item.span.from_expansion() {
return;
}
- let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
+ let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
let parent_item = cx.tcx.hir().expect_item(parent);
- let assoc_item = cx.tcx.associated_item(impl_item.def_id);
+ let assoc_item = cx.tcx.associated_item(impl_item.owner_id);
if_chain! {
if let ItemKind::Impl(Impl { of_trait: None, .. }) = parent_item.kind;
if assoc_item.fn_has_self_parameter;
if let ImplItemKind::Fn(.., body_id) = &impl_item.kind;
- if !cx.access_levels.is_exported(impl_item.def_id) || !self.avoid_breaking_exported_api;
+ if !cx.effective_visibilities.is_exported(impl_item.owner_id.def_id) || !self.avoid_breaking_exported_api;
let body = cx.tcx.hir().body(*body_id);
if let [self_param, ..] = body.params;
if !is_local_used(cx, body, self_param.pat.hir_id);
diff --git a/src/tools/clippy/clippy_lints/src/unwrap.rs b/src/tools/clippy/clippy_lints/src/unwrap.rs
index 3ef265580..ea878043c 100644
--- a/src/tools/clippy/clippy_lints/src/unwrap.rs
+++ b/src/tools/clippy/clippy_lints/src/unwrap.rs
@@ -257,9 +257,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
expr.hir_id,
expr.span,
&format!(
- "called `{}` on `{}` after checking its variant with `{}`",
+ "called `{}` on `{unwrappable_variable_name}` after checking its variant with `{}`",
method_name.ident.name,
- unwrappable_variable_name,
unwrappable.check_name.ident.as_str(),
),
|diag| {
@@ -268,9 +267,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
unwrappable.check.span.with_lo(unwrappable.if_expr.span.lo()),
"try",
format!(
- "if let {} = {}",
- suggested_pattern,
- unwrappable_variable_name,
+ "if let {suggested_pattern} = {unwrappable_variable_name}",
),
// We don't track how the unwrapped value is used inside the
// block or suggest deleting the unwrap, so we can't offer a
diff --git a/src/tools/clippy/clippy_lints/src/unwrap_in_result.rs b/src/tools/clippy/clippy_lints/src/unwrap_in_result.rs
index 46020adca..f3611d174 100644
--- a/src/tools/clippy/clippy_lints/src/unwrap_in_result.rs
+++ b/src/tools/clippy/clippy_lints/src/unwrap_in_result.rs
@@ -1,12 +1,12 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::ty::is_type_diagnostic_item;
+use clippy_utils::visitors::for_each_expr;
use clippy_utils::{method_chain_args, return_ty};
+use core::ops::ControlFlow;
use if_chain::if_chain;
use rustc_hir as hir;
-use rustc_hir::intravisit::{self, Visitor};
-use rustc_hir::{Expr, ImplItemKind};
+use rustc_hir::ImplItemKind;
use rustc_lint::{LateContext, LateLintPass};
-use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{sym, Span};
@@ -73,51 +73,37 @@ impl<'tcx> LateLintPass<'tcx> for UnwrapInResult {
}
}
-struct FindExpectUnwrap<'a, 'tcx> {
- lcx: &'a LateContext<'tcx>,
- typeck_results: &'tcx ty::TypeckResults<'tcx>,
- result: Vec<Span>,
-}
-
-impl<'a, 'tcx> Visitor<'tcx> for FindExpectUnwrap<'a, 'tcx> {
- fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
- // check for `expect`
- if let Some(arglists) = method_chain_args(expr, &["expect"]) {
- let receiver_ty = self.typeck_results.expr_ty(arglists[0].0).peel_refs();
- if is_type_diagnostic_item(self.lcx, receiver_ty, sym::Option)
- || is_type_diagnostic_item(self.lcx, receiver_ty, sym::Result)
- {
- self.result.push(expr.span);
+fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tcx hir::ImplItem<'_>) {
+ if let ImplItemKind::Fn(_, body_id) = impl_item.kind {
+ let body = cx.tcx.hir().body(body_id);
+ let typeck = cx.tcx.typeck(impl_item.owner_id.def_id);
+ let mut result = Vec::new();
+ let _: Option<!> = for_each_expr(body.value, |e| {
+ // check for `expect`
+ if let Some(arglists) = method_chain_args(e, &["expect"]) {
+ let receiver_ty = typeck.expr_ty(arglists[0].0).peel_refs();
+ if is_type_diagnostic_item(cx, receiver_ty, sym::Option)
+ || is_type_diagnostic_item(cx, receiver_ty, sym::Result)
+ {
+ result.push(e.span);
+ }
}
- }
- // check for `unwrap`
- if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
- let receiver_ty = self.typeck_results.expr_ty(arglists[0].0).peel_refs();
- if is_type_diagnostic_item(self.lcx, receiver_ty, sym::Option)
- || is_type_diagnostic_item(self.lcx, receiver_ty, sym::Result)
- {
- self.result.push(expr.span);
+ // check for `unwrap`
+ if let Some(arglists) = method_chain_args(e, &["unwrap"]) {
+ let receiver_ty = typeck.expr_ty(arglists[0].0).peel_refs();
+ if is_type_diagnostic_item(cx, receiver_ty, sym::Option)
+ || is_type_diagnostic_item(cx, receiver_ty, sym::Result)
+ {
+ result.push(e.span);
+ }
}
- }
- // and check sub-expressions
- intravisit::walk_expr(self, expr);
- }
-}
-
-fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tcx hir::ImplItem<'_>) {
- if let ImplItemKind::Fn(_, body_id) = impl_item.kind {
- let body = cx.tcx.hir().body(body_id);
- let mut fpu = FindExpectUnwrap {
- lcx: cx,
- typeck_results: cx.tcx.typeck(impl_item.def_id),
- result: Vec::new(),
- };
- fpu.visit_expr(body.value);
+ ControlFlow::Continue(())
+ });
// if we've found one, lint
- if !fpu.result.is_empty() {
+ if !result.is_empty() {
span_lint_and_then(
cx,
UNWRAP_IN_RESULT,
@@ -125,7 +111,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tc
"used unwrap or expect in a function that returns result or option",
move |diag| {
diag.help("unwrap and expect should not be used in a function that returns result or option");
- diag.span_note(fpu.result, "potential non-recoverable error(s)");
+ diag.span_note(result, "potential non-recoverable error(s)");
},
);
}
diff --git a/src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs b/src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs
index 02bf09ed5..1d2d3eb12 100644
--- a/src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs
+++ b/src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs
@@ -93,7 +93,7 @@ fn check_ident(cx: &LateContext<'_>, ident: &Ident, be_aggressive: bool) {
cx,
UPPER_CASE_ACRONYMS,
span,
- &format!("name `{}` contains a capitalized acronym", ident),
+ &format!("name `{ident}` contains a capitalized acronym"),
"consider making the acronym lowercase, except the initial letter",
corrected,
Applicability::MaybeIncorrect,
@@ -105,7 +105,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms {
fn check_item(&mut self, cx: &LateContext<'_>, it: &Item<'_>) {
// do not lint public items or in macros
if in_external_macro(cx.sess(), it.span)
- || (self.avoid_breaking_exported_api && cx.access_levels.is_exported(it.def_id))
+ || (self.avoid_breaking_exported_api && cx.effective_visibilities.is_exported(it.owner_id.def_id))
{
return;
}
@@ -114,6 +114,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms {
check_ident(cx, &it.ident, self.upper_case_acronyms_aggressive);
},
ItemKind::Enum(ref enumdef, _) => {
+ check_ident(cx, &it.ident, self.upper_case_acronyms_aggressive);
// check enum variants separately because again we only want to lint on private enums and
// the fn check_variant does not know about the vis of the enum of its variants
enumdef
diff --git a/src/tools/clippy/clippy_lints/src/use_self.rs b/src/tools/clippy/clippy_lints/src/use_self.rs
index 486ea5e5c..c6cdf3f85 100644
--- a/src/tools/clippy/clippy_lints/src/use_self.rs
+++ b/src/tools/clippy/clippy_lints/src/use_self.rs
@@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::ty::same_type_and_consts;
-use clippy_utils::{meets_msrv, msrvs};
+use clippy_utils::{is_from_proc_macro, meets_msrv, msrvs};
use if_chain::if_chain;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability;
@@ -12,11 +12,11 @@ use rustc_hir::{
Expr, ExprKind, FnRetTy, FnSig, GenericArg, HirId, Impl, ImplItemKind, Item, ItemKind, Pat, PatKind, Path, QPath,
TyKind,
};
+use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::{LateContext, LateLintPass};
use rustc_semver::RustcVersion;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::Span;
-use rustc_typeck::hir_ty_to_ty;
declare_clippy_lint! {
/// ### What it does
@@ -87,7 +87,7 @@ impl_lint_pass!(UseSelf => [USE_SELF]);
const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element";
impl<'tcx> LateLintPass<'tcx> for UseSelf {
- fn check_item(&mut self, _cx: &LateContext<'_>, item: &Item<'_>) {
+ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) {
if matches!(item.kind, ItemKind::OpaqueTy(_)) {
// skip over `ItemKind::OpaqueTy` in order to lint `foo() -> impl <..>`
return;
@@ -103,9 +103,10 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
if parameters.as_ref().map_or(true, |params| {
!params.parenthesized && !params.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)))
});
+ if !is_from_proc_macro(cx, item); // expensive, should be last check
then {
StackItem::Check {
- impl_id: item.def_id,
+ impl_id: item.owner_id.def_id,
in_body: 0,
types_to_skip: std::iter::once(self_ty.hir_id).collect(),
}
@@ -142,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
// trait, not in the impl of the trait.
let trait_method = cx
.tcx
- .associated_item(impl_item.def_id)
+ .associated_item(impl_item.owner_id)
.trait_item_def_id
.expect("impl method matches a trait method");
let trait_method_sig = cx.tcx.fn_sig(trait_method);
@@ -205,7 +206,12 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
ref types_to_skip,
}) = self.stack.last();
if let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind;
- if !matches!(path.res, Res::SelfTy { .. } | Res::Def(DefKind::TyParam, _));
+ if !matches!(
+ path.res,
+ Res::SelfTyParam { .. }
+ | Res::SelfTyAlias { .. }
+ | Res::Def(DefKind::TyParam, _)
+ );
if !types_to_skip.contains(&hir_ty.hir_id);
let ty = if in_body > 0 {
cx.typeck_results().node_type(hir_ty.hir_id)
@@ -213,9 +219,6 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
hir_ty_to_ty(cx.tcx, hir_ty)
};
if same_type_and_consts(ty, cx.tcx.type_of(impl_id));
- let hir = cx.tcx.hir();
- // prevents false positive on `#[derive(serde::Deserialize)]`
- if !hir.span(hir.get_parent_node(hir_ty.hir_id)).in_derive_expansion();
then {
span_lint(cx, hir_ty.span);
}
@@ -232,7 +235,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
}
match expr.kind {
ExprKind::Struct(QPath::Resolved(_, path), ..) => match path.res {
- Res::SelfTy { .. } => (),
+ Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => (),
Res::Def(DefKind::Variant, _) => lint_path_to_variant(cx, path),
_ => span_lint(cx, path.span),
},
diff --git a/src/tools/clippy/clippy_lints/src/useless_conversion.rs b/src/tools/clippy/clippy_lints/src/useless_conversion.rs
index f1b6463ad..1f69db1cb 100644
--- a/src/tools/clippy/clippy_lints/src/useless_conversion.rs
+++ b/src/tools/clippy/clippy_lints/src/useless_conversion.rs
@@ -5,7 +5,7 @@ use clippy_utils::ty::{is_type_diagnostic_item, same_type_and_consts};
use clippy_utils::{get_parent_expr, is_trait_method, match_def_path, paths};
use if_chain::if_chain;
use rustc_errors::Applicability;
-use rustc_hir::{Expr, ExprKind, HirId, MatchSource};
+use rustc_hir::{Expr, ExprKind, HirId, LangItem, MatchSource};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -55,9 +55,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
match e.kind {
ExprKind::Match(_, arms, MatchSource::TryDesugar) => {
- let e = match arms[0].body.kind {
- ExprKind::Ret(Some(e)) | ExprKind::Break(_, Some(e)) => e,
- _ => return,
+ let (ExprKind::Ret(Some(e)) | ExprKind::Break(_, Some(e))) = arms[0].body.kind else {
+ return
};
if let ExprKind::Call(_, [arg, ..]) = e.kind {
self.try_desugar_arm.push(arg.hir_id);
@@ -74,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
cx,
USELESS_CONVERSION,
e.span,
- &format!("useless conversion to the same type: `{}`", b),
+ &format!("useless conversion to the same type: `{b}`"),
"consider removing `.into()`",
sugg,
Applicability::MachineApplicable, // snippet
@@ -97,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
cx,
USELESS_CONVERSION,
e.span,
- &format!("useless conversion to the same type: `{}`", b),
+ &format!("useless conversion to the same type: `{b}`"),
"consider removing `.into_iter()`",
sugg,
Applicability::MachineApplicable, // snippet
@@ -118,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
cx,
USELESS_CONVERSION,
e.span,
- &format!("useless conversion to the same type: `{}`", b),
+ &format!("useless conversion to the same type: `{b}`"),
None,
"consider removing `.try_into()`",
);
@@ -146,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
cx,
USELESS_CONVERSION,
e.span,
- &format!("useless conversion to the same type: `{}`", b),
+ &format!("useless conversion to the same type: `{b}`"),
None,
&hint,
);
@@ -154,7 +153,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
}
if_chain! {
- if match_def_path(cx, def_id, &paths::FROM_FROM);
+ if cx.tcx.lang_items().require(LangItem::FromFrom).ok() == Some(def_id);
if same_type_and_consts(a, b);
then {
@@ -165,7 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
cx,
USELESS_CONVERSION,
e.span,
- &format!("useless conversion to the same type: `{}`", b),
+ &format!("useless conversion to the same type: `{b}`"),
&sugg_msg,
sugg.to_string(),
Applicability::MachineApplicable, // snippet
diff --git a/src/tools/clippy/clippy_lints/src/utils/author.rs b/src/tools/clippy/clippy_lints/src/utils/author.rs
index 4003fff27..0c052d86e 100644
--- a/src/tools/clippy/clippy_lints/src/utils/author.rs
+++ b/src/tools/clippy/clippy_lints/src/utils/author.rs
@@ -12,6 +12,7 @@ use rustc_hir::{
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::{Ident, Symbol};
+use std::cell::Cell;
use std::fmt::{Display, Formatter, Write as _};
declare_clippy_lint! {
@@ -37,15 +38,13 @@ declare_clippy_lint! {
///
/// ```rust,ignore
/// // ./tests/ui/new_lint.stdout
- /// if_chain! {
- /// if let ExprKind::If(ref cond, ref then, None) = item.kind,
- /// if let ExprKind::Binary(BinOp::Eq, ref left, ref right) = cond.kind,
- /// if let ExprKind::Path(ref path) = left.kind,
- /// if let ExprKind::Lit(ref lit) = right.kind,
- /// if let LitKind::Int(42, _) = lit.node,
- /// then {
- /// // report your lint here
- /// }
+ /// if ExprKind::If(ref cond, ref then, None) = item.kind
+ /// && let ExprKind::Binary(BinOp::Eq, ref left, ref right) = cond.kind
+ /// && let ExprKind::Path(ref path) = left.kind
+ /// && let ExprKind::Lit(ref lit) = right.kind
+ /// && let LitKind::Int(42, _) = lit.node
+ /// {
+ /// // report your lint here
/// }
/// ```
pub LINT_AUTHOR,
@@ -91,15 +90,16 @@ macro_rules! field {
};
}
-fn prelude() {
- println!("if_chain! {{");
-}
-
-fn done() {
- println!(" then {{");
- println!(" // report your lint here");
- println!(" }}");
- println!("}}");
+/// Print a condition of a let chain, `chain!(self, "let Some(x) = y")` will print
+/// `if let Some(x) = y` on the first call and ` && let Some(x) = y` thereafter
+macro_rules! chain {
+ ($self:ident, $($t:tt)*) => {
+ if $self.first.take() {
+ println!("if {}", format_args!($($t)*));
+ } else {
+ println!(" && {}", format_args!($($t)*));
+ }
+ }
}
impl<'tcx> LateLintPass<'tcx> for Author {
@@ -140,7 +140,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
fn check_item(cx: &LateContext<'_>, hir_id: HirId) {
let hir = cx.tcx.hir();
- if let Some(body_id) = hir.maybe_body_owned_by(hir_id.expect_owner()) {
+ if let Some(body_id) = hir.maybe_body_owned_by(hir_id.expect_owner().def_id) {
check_node(cx, hir_id, |v| {
v.expr(&v.bind("expr", hir.body(body_id).value));
});
@@ -149,9 +149,10 @@ fn check_item(cx: &LateContext<'_>, hir_id: HirId) {
fn check_node(cx: &LateContext<'_>, hir_id: HirId, f: impl Fn(&PrintVisitor<'_, '_>)) {
if has_attr(cx, hir_id) {
- prelude();
f(&PrintVisitor::new(cx));
- done();
+ println!("{{");
+ println!(" // report your lint here");
+ println!("}}");
}
}
@@ -195,7 +196,9 @@ struct PrintVisitor<'a, 'tcx> {
cx: &'a LateContext<'tcx>,
/// Fields are the current index that needs to be appended to pattern
/// binding names
- ids: std::cell::Cell<FxHashMap<&'static str, u32>>,
+ ids: Cell<FxHashMap<&'static str, u32>>,
+ /// Currently at the first condition in the if chain
+ first: Cell<bool>,
}
#[allow(clippy::unused_self)]
@@ -203,7 +206,8 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
fn new(cx: &'a LateContext<'tcx>) -> Self {
Self {
cx,
- ids: std::cell::Cell::default(),
+ ids: Cell::default(),
+ first: Cell::new(true),
}
}
@@ -226,10 +230,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
fn option<T: Copy>(&self, option: &Binding<Option<T>>, name: &'static str, f: impl Fn(&Binding<T>)) {
match option.value {
- None => out!("if {option}.is_none();"),
+ None => chain!(self, "{option}.is_none()"),
Some(value) => {
let value = &self.bind(name, value);
- out!("if let Some({value}) = {option};");
+ chain!(self, "let Some({value}) = {option}");
f(value);
},
}
@@ -237,9 +241,9 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
fn slice<T>(&self, slice: &Binding<&[T]>, f: impl Fn(&Binding<&T>)) {
if slice.value.is_empty() {
- out!("if {slice}.is_empty();");
+ chain!(self, "{slice}.is_empty()");
} else {
- out!("if {slice}.len() == {};", slice.value.len());
+ chain!(self, "{slice}.len() == {}", slice.value.len());
for (i, value) in slice.value.iter().enumerate() {
let name = format!("{slice}[{i}]");
f(&Binding { name, value });
@@ -254,23 +258,23 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
}
fn ident(&self, ident: &Binding<Ident>) {
- out!("if {ident}.as_str() == {:?};", ident.value.as_str());
+ chain!(self, "{ident}.as_str() == {:?}", ident.value.as_str());
}
fn symbol(&self, symbol: &Binding<Symbol>) {
- out!("if {symbol}.as_str() == {:?};", symbol.value.as_str());
+ chain!(self, "{symbol}.as_str() == {:?}", symbol.value.as_str());
}
fn qpath(&self, qpath: &Binding<&QPath<'_>>) {
if let QPath::LangItem(lang_item, ..) = *qpath.value {
- out!("if matches!({qpath}, QPath::LangItem(LangItem::{lang_item:?}, _));");
+ chain!(self, "matches!({qpath}, QPath::LangItem(LangItem::{lang_item:?}, _))");
} else {
- out!("if match_qpath({qpath}, &[{}]);", path_to_string(qpath.value));
+ chain!(self, "match_qpath({qpath}, &[{}])", path_to_string(qpath.value));
}
}
fn lit(&self, lit: &Binding<&Lit>) {
- let kind = |kind| out!("if let LitKind::{kind} = {lit}.node;");
+ let kind = |kind| chain!(self, "let LitKind::{kind} = {lit}.node");
macro_rules! kind {
($($t:tt)*) => (kind(format_args!($($t)*)));
}
@@ -298,7 +302,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
LitKind::ByteStr(ref vec) => {
bind!(self, vec);
kind!("ByteStr(ref {vec})");
- out!("if let [{:?}] = **{vec};", vec.value);
+ chain!(self, "let [{:?}] = **{vec}", vec.value);
},
LitKind::Str(s, _) => {
bind!(self, s);
@@ -311,15 +315,15 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
fn arm(&self, arm: &Binding<&hir::Arm<'_>>) {
self.pat(field!(arm.pat));
match arm.value.guard {
- None => out!("if {arm}.guard.is_none();"),
+ None => chain!(self, "{arm}.guard.is_none()"),
Some(hir::Guard::If(expr)) => {
bind!(self, expr);
- out!("if let Some(Guard::If({expr})) = {arm}.guard;");
+ chain!(self, "let Some(Guard::If({expr})) = {arm}.guard");
self.expr(expr);
},
Some(hir::Guard::IfLet(let_expr)) => {
bind!(self, let_expr);
- out!("if let Some(Guard::IfLet({let_expr}) = {arm}.guard;");
+ chain!(self, "let Some(Guard::IfLet({let_expr}) = {arm}.guard");
self.pat(field!(let_expr.pat));
self.expr(field!(let_expr.init));
},
@@ -331,9 +335,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
fn expr(&self, expr: &Binding<&hir::Expr<'_>>) {
if let Some(higher::While { condition, body }) = higher::While::hir(expr.value) {
bind!(self, condition, body);
- out!(
- "if let Some(higher::While {{ condition: {condition}, body: {body} }}) \
- = higher::While::hir({expr});"
+ chain!(
+ self,
+ "let Some(higher::While {{ condition: {condition}, body: {body} }}) \
+ = higher::While::hir({expr})"
);
self.expr(condition);
self.expr(body);
@@ -347,9 +352,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
}) = higher::WhileLet::hir(expr.value)
{
bind!(self, let_pat, let_expr, if_then);
- out!(
- "if let Some(higher::WhileLet {{ let_pat: {let_pat}, let_expr: {let_expr}, if_then: {if_then} }}) \
- = higher::WhileLet::hir({expr});"
+ chain!(
+ self,
+ "let Some(higher::WhileLet {{ let_pat: {let_pat}, let_expr: {let_expr}, if_then: {if_then} }}) \
+ = higher::WhileLet::hir({expr})"
);
self.pat(let_pat);
self.expr(let_expr);
@@ -359,9 +365,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
if let Some(higher::ForLoop { pat, arg, body, .. }) = higher::ForLoop::hir(expr.value) {
bind!(self, pat, arg, body);
- out!(
- "if let Some(higher::ForLoop {{ pat: {pat}, arg: {arg}, body: {body}, .. }}) \
- = higher::ForLoop::hir({expr});"
+ chain!(
+ self,
+ "let Some(higher::ForLoop {{ pat: {pat}, arg: {arg}, body: {body}, .. }}) \
+ = higher::ForLoop::hir({expr})"
);
self.pat(pat);
self.expr(arg);
@@ -369,7 +376,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
return;
}
- let kind = |kind| out!("if let ExprKind::{kind} = {expr}.kind;");
+ let kind = |kind| chain!(self, "let ExprKind::{kind} = {expr}.kind");
macro_rules! kind {
($($t:tt)*) => (kind(format_args!($($t)*)));
}
@@ -383,7 +390,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
// if it's a path
if let Some(TyKind::Path(ref qpath)) = let_expr.value.ty.as_ref().map(|ty| &ty.kind) {
bind!(self, qpath);
- out!("if let TyKind::Path(ref {qpath}) = {let_expr}.ty.kind;");
+ chain!(self, "let TyKind::Path(ref {qpath}) = {let_expr}.ty.kind");
self.qpath(qpath);
}
self.expr(field!(let_expr.init));
@@ -419,7 +426,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
ExprKind::Binary(op, left, right) => {
bind!(self, op, left, right);
kind!("Binary({op}, {left}, {right})");
- out!("if BinOpKind::{:?} == {op}.node;", op.value.node);
+ chain!(self, "BinOpKind::{:?} == {op}.node", op.value.node);
self.expr(left);
self.expr(right);
},
@@ -438,7 +445,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
kind!("Cast({expr}, {cast_ty})");
if let TyKind::Path(ref qpath) = cast_ty.value.kind {
bind!(self, qpath);
- out!("if let TyKind::Path(ref {qpath}) = {cast_ty}.kind;");
+ chain!(self, "let TyKind::Path(ref {qpath}) = {cast_ty}.kind");
self.qpath(qpath);
}
self.expr(expr);
@@ -485,7 +492,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
bind!(self, fn_decl, body_id);
kind!("Closure(CaptureBy::{capture_clause:?}, {fn_decl}, {body_id}, _, {movability})");
- out!("if let {ret_ty} = {fn_decl}.output;");
+ chain!(self, "let {ret_ty} = {fn_decl}.output");
self.body(body_id);
},
ExprKind::Yield(sub, source) => {
@@ -509,7 +516,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
ExprKind::AssignOp(op, target, value) => {
bind!(self, op, target, value);
kind!("AssignOp({op}, {target}, {value})");
- out!("if BinOpKind::{:?} == {op}.node;", op.value.node);
+ chain!(self, "BinOpKind::{:?} == {op}.node", op.value.node);
self.expr(target);
self.expr(value);
},
@@ -573,10 +580,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
kind!("Repeat({value}, {length})");
self.expr(value);
match length.value {
- ArrayLen::Infer(..) => out!("if let ArrayLen::Infer(..) = length;"),
+ ArrayLen::Infer(..) => chain!(self, "let ArrayLen::Infer(..) = length"),
ArrayLen::Body(anon_const) => {
bind!(self, anon_const);
- out!("if let ArrayLen::Body({anon_const}) = {length};");
+ chain!(self, "let ArrayLen::Body({anon_const}) = {length}");
self.body(field!(anon_const.body));
},
}
@@ -600,12 +607,12 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
fn body(&self, body_id: &Binding<hir::BodyId>) {
let expr = self.cx.tcx.hir().body(body_id.value).value;
bind!(self, expr);
- out!("let {expr} = &cx.tcx.hir().body({body_id}).value;");
+ chain!(self, "{expr} = &cx.tcx.hir().body({body_id}).value");
self.expr(expr);
}
fn pat(&self, pat: &Binding<&hir::Pat<'_>>) {
- let kind = |kind| out!("if let PatKind::{kind} = {pat}.kind;");
+ let kind = |kind| chain!(self, "let PatKind::{kind} = {pat}.kind");
macro_rules! kind {
($($t:tt)*) => (kind(format_args!($($t)*)));
}
@@ -688,7 +695,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
}
fn stmt(&self, stmt: &Binding<&hir::Stmt<'_>>) {
- let kind = |kind| out!("if let StmtKind::{kind} = {stmt}.kind;");
+ let kind = |kind| chain!(self, "let StmtKind::{kind} = {stmt}.kind");
macro_rules! kind {
($($t:tt)*) => (kind(format_args!($($t)*)));
}
@@ -739,7 +746,7 @@ fn path_to_string(path: &QPath<'_>) -> String {
*s += ", ";
write!(s, "{:?}", segment.ident.as_str()).unwrap();
},
- other => write!(s, "/* unimplemented: {:?}*/", other).unwrap(),
+ other => write!(s, "/* unimplemented: {other:?}*/").unwrap(),
},
QPath::LangItem(..) => panic!("path_to_string: called for lang item qpath"),
}
diff --git a/src/tools/clippy/clippy_lints/src/utils/conf.rs b/src/tools/clippy/clippy_lints/src/utils/conf.rs
index a8500beb2..668123e4d 100644
--- a/src/tools/clippy/clippy_lints/src/utils/conf.rs
+++ b/src/tools/clippy/clippy_lints/src/utils/conf.rs
@@ -39,28 +39,28 @@ pub struct Rename {
pub rename: String,
}
-/// A single disallowed method, used by the `DISALLOWED_METHODS` lint.
#[derive(Clone, Debug, Deserialize)]
#[serde(untagged)]
-pub enum DisallowedMethod {
+pub enum DisallowedPath {
Simple(String),
WithReason { path: String, reason: Option<String> },
}
-impl DisallowedMethod {
+impl DisallowedPath {
pub fn path(&self) -> &str {
let (Self::Simple(path) | Self::WithReason { path, .. }) = self;
path
}
-}
-/// A single disallowed type, used by the `DISALLOWED_TYPES` lint.
-#[derive(Clone, Debug, Deserialize)]
-#[serde(untagged)]
-pub enum DisallowedType {
- Simple(String),
- WithReason { path: String, reason: Option<String> },
+ pub fn reason(&self) -> Option<&str> {
+ match self {
+ Self::WithReason {
+ reason: Some(reason), ..
+ } => Some(reason),
+ _ => None,
+ }
+ }
}
/// Conf with parse errors
@@ -213,7 +213,7 @@ define_Conf! {
///
/// Suppress lints whenever the suggested change would cause breakage for other crates.
(avoid_breaking_exported_api: bool = true),
- /// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED.
+ /// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP.
///
/// The minimum rust version that the project supports
(msrv: Option<String> = None),
@@ -315,14 +315,18 @@ define_Conf! {
///
/// Whether to allow certain wildcard imports (prelude, super in tests).
(warn_on_all_wildcard_imports: bool = false),
+ /// Lint: DISALLOWED_MACROS.
+ ///
+ /// The list of disallowed macros, written as fully qualified paths.
+ (disallowed_macros: Vec<crate::utils::conf::DisallowedPath> = Vec::new()),
/// Lint: DISALLOWED_METHODS.
///
/// The list of disallowed methods, written as fully qualified paths.
- (disallowed_methods: Vec<crate::utils::conf::DisallowedMethod> = Vec::new()),
+ (disallowed_methods: Vec<crate::utils::conf::DisallowedPath> = Vec::new()),
/// Lint: DISALLOWED_TYPES.
///
/// The list of disallowed types, written as fully qualified paths.
- (disallowed_types: Vec<crate::utils::conf::DisallowedType> = Vec::new()),
+ (disallowed_types: Vec<crate::utils::conf::DisallowedPath> = Vec::new()),
/// Lint: UNREADABLE_LITERAL.
///
/// Should the fraction of a decimal be linted to include separators.
@@ -362,7 +366,7 @@ define_Conf! {
/// For example, `[_, _, _, e, ..]` is a slice pattern with 4 elements.
(max_suggested_slice_pattern_length: u64 = 3),
/// Lint: AWAIT_HOLDING_INVALID_TYPE
- (await_holding_invalid_types: Vec<crate::utils::conf::DisallowedType> = Vec::new()),
+ (await_holding_invalid_types: Vec<crate::utils::conf::DisallowedPath> = Vec::new()),
/// Lint: LARGE_INCLUDE_FILE.
///
/// The maximum size of a file included via `include_bytes!()` or `include_str!()`, in bytes
@@ -476,22 +480,19 @@ pub fn format_error(error: Box<dyn Error>) -> String {
let mut msg = String::from(prefix);
for row in 0..rows {
- write!(msg, "\n").unwrap();
+ writeln!(msg).unwrap();
for (column, column_width) in column_widths.iter().copied().enumerate() {
let index = column * rows + row;
let field = fields.get(index).copied().unwrap_or_default();
write!(
msg,
- "{:separator_width$}{:field_width$}",
- " ",
- field,
- separator_width = SEPARATOR_WIDTH,
- field_width = column_width
+ "{:SEPARATOR_WIDTH$}{field:column_width$}",
+ " "
)
.unwrap();
}
}
- write!(msg, "\n{}", suffix).unwrap();
+ write!(msg, "\n{suffix}").unwrap();
msg
} else {
s
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 17d9a0418..71f6c9909 100644
--- a/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints.rs
@@ -1,1437 +1,12 @@
-use crate::utils::internal_lints::metadata_collector::is_deprecated_lint;
-use clippy_utils::consts::{constant_simple, Constant};
-use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
-use clippy_utils::macros::root_macro_call_first_node;
-use clippy_utils::source::snippet;
-use clippy_utils::ty::match_type;
-use clippy_utils::{
- def_path_res, higher, is_else_clause, is_expn_of, is_expr_path_def_path, is_lint_allowed, match_def_path,
- method_calls, paths, peel_blocks_with_stmt, SpanlessEq,
-};
-use if_chain::if_chain;
-use rustc_ast as ast;
-use rustc_ast::ast::{Crate, ItemKind, LitKind, ModKind, NodeId};
-use rustc_ast::visit::FnKind;
-use rustc_data_structures::fx::{FxHashMap, FxHashSet};
-use rustc_errors::Applicability;
-use rustc_hir as hir;
-use rustc_hir::def::{DefKind, Res};
-use rustc_hir::def_id::DefId;
-use rustc_hir::hir_id::CRATE_HIR_ID;
-use rustc_hir::intravisit::Visitor;
-use rustc_hir::{
- BinOpKind, Block, Closure, Expr, ExprKind, HirId, Item, Local, MutTy, Mutability, Node, Path, Stmt, StmtKind, Ty,
- TyKind, UnOp,
-};
-use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
-use rustc_middle::hir::nested_filter;
-use rustc_middle::mir::interpret::ConstValue;
-use rustc_middle::ty::{self, fast_reject::SimplifiedTypeGen, subst::GenericArgKind, FloatTy};
-use rustc_semver::RustcVersion;
-use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
-use rustc_span::source_map::Spanned;
-use rustc_span::symbol::Symbol;
-use rustc_span::{sym, BytePos, Span};
-use rustc_typeck::hir_ty_to_ty;
-
-use std::borrow::{Borrow, Cow};
-
-#[cfg(feature = "internal")]
+pub mod clippy_lints_internal;
+pub mod collapsible_calls;
+pub mod compiler_lint_functions;
+pub mod if_chain_style;
+pub mod interning_defined_symbol;
+pub mod invalid_paths;
+pub mod lint_without_lint_pass;
pub mod metadata_collector;
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks for various things we like to keep tidy in clippy.
- ///
- /// ### Why is this bad?
- /// We like to pretend we're an example of tidy code.
- ///
- /// ### Example
- /// Wrong ordering of the util::paths constants.
- pub CLIPPY_LINTS_INTERNAL,
- internal,
- "various things that will negatively affect your clippy experience"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Ensures every lint is associated to a `LintPass`.
- ///
- /// ### Why is this bad?
- /// The compiler only knows lints via a `LintPass`. Without
- /// putting a lint to a `LintPass::get_lints()`'s return, the compiler will not
- /// know the name of the lint.
- ///
- /// ### Known problems
- /// Only checks for lints associated using the
- /// `declare_lint_pass!`, `impl_lint_pass!`, and `lint_array!` macros.
- ///
- /// ### Example
- /// ```rust,ignore
- /// declare_lint! { pub LINT_1, ... }
- /// declare_lint! { pub LINT_2, ... }
- /// declare_lint! { pub FORGOTTEN_LINT, ... }
- /// // ...
- /// declare_lint_pass!(Pass => [LINT_1, LINT_2]);
- /// // missing FORGOTTEN_LINT
- /// ```
- pub LINT_WITHOUT_LINT_PASS,
- internal,
- "declaring a lint without associating it in a LintPass"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks for calls to `cx.span_lint*` and suggests to use the `utils::*`
- /// variant of the function.
- ///
- /// ### Why is this bad?
- /// The `utils::*` variants also add a link to the Clippy documentation to the
- /// warning/error messages.
- ///
- /// ### Example
- /// ```rust,ignore
- /// cx.span_lint(LINT_NAME, "message");
- /// ```
- ///
- /// Use instead:
- /// ```rust,ignore
- /// utils::span_lint(cx, LINT_NAME, "message");
- /// ```
- pub COMPILER_LINT_FUNCTIONS,
- internal,
- "usage of the lint functions of the compiler instead of the utils::* variant"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks for calls to `cx.outer().expn_data()` and suggests to use
- /// the `cx.outer_expn_data()`
- ///
- /// ### Why is this bad?
- /// `cx.outer_expn_data()` is faster and more concise.
- ///
- /// ### Example
- /// ```rust,ignore
- /// expr.span.ctxt().outer().expn_data()
- /// ```
- ///
- /// Use instead:
- /// ```rust,ignore
- /// expr.span.ctxt().outer_expn_data()
- /// ```
- pub OUTER_EXPN_EXPN_DATA,
- internal,
- "using `cx.outer_expn().expn_data()` instead of `cx.outer_expn_data()`"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Not an actual lint. This lint is only meant for testing our customized internal compiler
- /// error message by calling `panic`.
- ///
- /// ### Why is this bad?
- /// ICE in large quantities can damage your teeth
- ///
- /// ### Example
- /// ```rust,ignore
- /// ðŸ¦ðŸ¦ðŸ¦ðŸ¦ðŸ¦
- /// ```
- pub PRODUCE_ICE,
- internal,
- "this message should not appear anywhere as we ICE before and don't emit the lint"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks for cases of an auto-generated lint without an updated description,
- /// i.e. `default lint description`.
- ///
- /// ### Why is this bad?
- /// Indicates that the lint is not finished.
- ///
- /// ### Example
- /// ```rust,ignore
- /// declare_lint! { pub COOL_LINT, nursery, "default lint description" }
- /// ```
- ///
- /// Use instead:
- /// ```rust,ignore
- /// declare_lint! { pub COOL_LINT, nursery, "a great new lint" }
- /// ```
- pub DEFAULT_LINT,
- internal,
- "found 'default lint description' in a lint declaration"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Lints `span_lint_and_then` function calls, where the
- /// closure argument has only one statement and that statement is a method
- /// call to `span_suggestion`, `span_help`, `span_note` (using the same
- /// span), `help` or `note`.
- ///
- /// These usages of `span_lint_and_then` should be replaced with one of the
- /// wrapper functions `span_lint_and_sugg`, span_lint_and_help`, or
- /// `span_lint_and_note`.
- ///
- /// ### Why is this bad?
- /// Using the wrapper `span_lint_and_*` functions, is more
- /// convenient, readable and less error prone.
- ///
- /// ### Example
- /// ```rust,ignore
- /// span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |diag| {
- /// diag.span_suggestion(
- /// expr.span,
- /// help_msg,
- /// sugg.to_string(),
- /// Applicability::MachineApplicable,
- /// );
- /// });
- /// span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |diag| {
- /// diag.span_help(expr.span, help_msg);
- /// });
- /// span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |diag| {
- /// diag.help(help_msg);
- /// });
- /// span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |diag| {
- /// diag.span_note(expr.span, note_msg);
- /// });
- /// span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |diag| {
- /// diag.note(note_msg);
- /// });
- /// ```
- ///
- /// Use instead:
- /// ```rust,ignore
- /// span_lint_and_sugg(
- /// cx,
- /// TEST_LINT,
- /// expr.span,
- /// lint_msg,
- /// help_msg,
- /// sugg.to_string(),
- /// Applicability::MachineApplicable,
- /// );
- /// span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg);
- /// span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg);
- /// span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg);
- /// span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, None, note_msg);
- /// ```
- pub COLLAPSIBLE_SPAN_LINT_CALLS,
- internal,
- "found collapsible `span_lint_and_then` calls"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks for calls to `utils::match_type()` on a type diagnostic item
- /// and suggests to use `utils::is_type_diagnostic_item()` instead.
- ///
- /// ### Why is this bad?
- /// `utils::is_type_diagnostic_item()` does not require hardcoded paths.
- ///
- /// ### Example
- /// ```rust,ignore
- /// utils::match_type(cx, ty, &paths::VEC)
- /// ```
- ///
- /// Use instead:
- /// ```rust,ignore
- /// utils::is_type_diagnostic_item(cx, ty, sym::Vec)
- /// ```
- pub MATCH_TYPE_ON_DIAGNOSTIC_ITEM,
- internal,
- "using `utils::match_type()` instead of `utils::is_type_diagnostic_item()`"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks the paths module for invalid paths.
- ///
- /// ### Why is this bad?
- /// It indicates a bug in the code.
- ///
- /// ### Example
- /// None.
- pub INVALID_PATHS,
- internal,
- "invalid path"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks for interning symbols that have already been pre-interned and defined as constants.
- ///
- /// ### Why is this bad?
- /// It's faster and easier to use the symbol constant.
- ///
- /// ### Example
- /// ```rust,ignore
- /// let _ = sym!(f32);
- /// ```
- ///
- /// Use instead:
- /// ```rust,ignore
- /// let _ = sym::f32;
- /// ```
- pub INTERNING_DEFINED_SYMBOL,
- internal,
- "interning a symbol that is pre-interned and defined as a constant"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks for unnecessary conversion from Symbol to a string.
- ///
- /// ### Why is this bad?
- /// It's faster use symbols directly instead of strings.
- ///
- /// ### Example
- /// ```rust,ignore
- /// symbol.as_str() == "clippy";
- /// ```
- ///
- /// Use instead:
- /// ```rust,ignore
- /// symbol == sym::clippy;
- /// ```
- pub UNNECESSARY_SYMBOL_STR,
- internal,
- "unnecessary conversion between Symbol and string"
-}
-
-declare_clippy_lint! {
- /// Finds unidiomatic usage of `if_chain!`
- pub IF_CHAIN_STYLE,
- internal,
- "non-idiomatic `if_chain!` usage"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks for invalid `clippy::version` attributes.
- ///
- /// Valid values are:
- /// * "pre 1.29.0"
- /// * any valid semantic version
- pub INVALID_CLIPPY_VERSION_ATTRIBUTE,
- internal,
- "found an invalid `clippy::version` attribute"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks for declared clippy lints without the `clippy::version` attribute.
- ///
- pub MISSING_CLIPPY_VERSION_ATTRIBUTE,
- internal,
- "found clippy lint without `clippy::version` attribute"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Check that the `extract_msrv_attr!` macro is used, when a lint has a MSRV.
- ///
- pub MISSING_MSRV_ATTR_IMPL,
- internal,
- "checking if all necessary steps were taken when adding a MSRV to a lint"
-}
-
-declare_clippy_lint! {
- /// ### What it does
- /// Checks for cases of an auto-generated deprecated lint without an updated reason,
- /// i.e. `"default deprecation note"`.
- ///
- /// ### Why is this bad?
- /// Indicates that the documentation is incomplete.
- ///
- /// ### Example
- /// ```rust,ignore
- /// declare_deprecated_lint! {
- /// /// ### What it does
- /// /// Nothing. This lint has been deprecated.
- /// ///
- /// /// ### Deprecation reason
- /// /// TODO
- /// #[clippy::version = "1.63.0"]
- /// pub COOL_LINT,
- /// "default deprecation note"
- /// }
- /// ```
- ///
- /// Use instead:
- /// ```rust,ignore
- /// declare_deprecated_lint! {
- /// /// ### What it does
- /// /// Nothing. This lint has been deprecated.
- /// ///
- /// /// ### Deprecation reason
- /// /// This lint has been replaced by `cooler_lint`
- /// #[clippy::version = "1.63.0"]
- /// pub COOL_LINT,
- /// "this lint has been replaced by `cooler_lint`"
- /// }
- /// ```
- pub DEFAULT_DEPRECATION_REASON,
- internal,
- "found 'default deprecation note' in a deprecated lint declaration"
-}
-
-declare_lint_pass!(ClippyLintsInternal => [CLIPPY_LINTS_INTERNAL]);
-
-impl EarlyLintPass for ClippyLintsInternal {
- fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &Crate) {
- if let Some(utils) = krate.items.iter().find(|item| item.ident.name.as_str() == "utils") {
- if let ItemKind::Mod(_, ModKind::Loaded(ref items, ..)) = utils.kind {
- if let Some(paths) = items.iter().find(|item| item.ident.name.as_str() == "paths") {
- if let ItemKind::Mod(_, ModKind::Loaded(ref items, ..)) = paths.kind {
- let mut last_name: Option<&str> = None;
- for item in items {
- let name = item.ident.as_str();
- if let Some(last_name) = last_name {
- if *last_name > *name {
- span_lint(
- cx,
- CLIPPY_LINTS_INTERNAL,
- item.span,
- "this constant should be before the previous constant due to lexical \
- ordering",
- );
- }
- }
- last_name = Some(name);
- }
- }
- }
- }
- }
- }
-}
-
-#[derive(Clone, Debug, Default)]
-pub struct LintWithoutLintPass {
- declared_lints: FxHashMap<Symbol, Span>,
- registered_lints: FxHashSet<Symbol>,
-}
-
-impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS, INVALID_CLIPPY_VERSION_ATTRIBUTE, MISSING_CLIPPY_VERSION_ATTRIBUTE, DEFAULT_DEPRECATION_REASON]);
-
-impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
- fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
- if is_lint_allowed(cx, DEFAULT_LINT, item.hir_id())
- || is_lint_allowed(cx, DEFAULT_DEPRECATION_REASON, item.hir_id())
- {
- return;
- }
-
- if let hir::ItemKind::Static(ty, Mutability::Not, body_id) = item.kind {
- let is_lint_ref_ty = is_lint_ref_type(cx, ty);
- if is_deprecated_lint(cx, ty) || is_lint_ref_ty {
- check_invalid_clippy_version_attribute(cx, item);
-
- let expr = &cx.tcx.hir().body(body_id).value;
- let fields;
- if is_lint_ref_ty {
- if let ExprKind::AddrOf(_, _, inner_exp) = expr.kind
- && let ExprKind::Struct(_, struct_fields, _) = inner_exp.kind {
- fields = struct_fields;
- } else {
- return;
- }
- } else if let ExprKind::Struct(_, struct_fields, _) = expr.kind {
- fields = struct_fields;
- } else {
- return;
- }
-
- let field = fields
- .iter()
- .find(|f| f.ident.as_str() == "desc")
- .expect("lints must have a description field");
-
- if let ExprKind::Lit(Spanned {
- node: LitKind::Str(ref sym, _),
- ..
- }) = field.expr.kind
- {
- let sym_str = sym.as_str();
- if is_lint_ref_ty {
- if sym_str == "default lint description" {
- span_lint(
- cx,
- DEFAULT_LINT,
- item.span,
- &format!("the lint `{}` has the default lint description", item.ident.name),
- );
- }
-
- self.declared_lints.insert(item.ident.name, item.span);
- } else if sym_str == "default deprecation note" {
- span_lint(
- cx,
- DEFAULT_DEPRECATION_REASON,
- item.span,
- &format!("the lint `{}` has the default deprecation reason", item.ident.name),
- );
- }
- }
- }
- } else if let Some(macro_call) = root_macro_call_first_node(cx, item) {
- if !matches!(
- cx.tcx.item_name(macro_call.def_id).as_str(),
- "impl_lint_pass" | "declare_lint_pass"
- ) {
- return;
- }
- if let hir::ItemKind::Impl(hir::Impl {
- of_trait: None,
- items: impl_item_refs,
- ..
- }) = item.kind
- {
- let mut collector = LintCollector {
- output: &mut self.registered_lints,
- cx,
- };
- let body_id = cx.tcx.hir().body_owned_by(
- cx.tcx.hir().local_def_id(
- impl_item_refs
- .iter()
- .find(|iiref| iiref.ident.as_str() == "get_lints")
- .expect("LintPass needs to implement get_lints")
- .id
- .hir_id(),
- ),
- );
- collector.visit_expr(cx.tcx.hir().body(body_id).value);
- }
- }
- }
-
- fn check_crate_post(&mut self, cx: &LateContext<'tcx>) {
- if is_lint_allowed(cx, LINT_WITHOUT_LINT_PASS, CRATE_HIR_ID) {
- return;
- }
-
- for (lint_name, &lint_span) in &self.declared_lints {
- // When using the `declare_tool_lint!` macro, the original `lint_span`'s
- // file points to "<rustc macros>".
- // `compiletest-rs` thinks that's an error in a different file and
- // just ignores it. This causes the test in compile-fail/lint_pass
- // not able to capture the error.
- // Therefore, we need to climb the macro expansion tree and find the
- // actual span that invoked `declare_tool_lint!`:
- let lint_span = lint_span.ctxt().outer_expn_data().call_site;
-
- if !self.registered_lints.contains(lint_name) {
- span_lint(
- cx,
- LINT_WITHOUT_LINT_PASS,
- lint_span,
- &format!("the lint `{}` is not added to any `LintPass`", lint_name),
- );
- }
- }
- }
-}
-
-fn is_lint_ref_type<'tcx>(cx: &LateContext<'tcx>, ty: &Ty<'_>) -> bool {
- if let TyKind::Rptr(
- _,
- MutTy {
- ty: inner,
- mutbl: Mutability::Not,
- },
- ) = ty.kind
- {
- if let TyKind::Path(ref path) = inner.kind {
- if let Res::Def(DefKind::Struct, def_id) = cx.qpath_res(path, inner.hir_id) {
- return match_def_path(cx, def_id, &paths::LINT);
- }
- }
- }
-
- false
-}
-
-fn check_invalid_clippy_version_attribute(cx: &LateContext<'_>, item: &'_ Item<'_>) {
- if let Some(value) = extract_clippy_version_value(cx, item) {
- // The `sym!` macro doesn't work as it only expects a single token.
- // It's better to keep it this way and have a direct `Symbol::intern` call here.
- if value == Symbol::intern("pre 1.29.0") {
- return;
- }
-
- if RustcVersion::parse(value.as_str()).is_err() {
- span_lint_and_help(
- cx,
- INVALID_CLIPPY_VERSION_ATTRIBUTE,
- item.span,
- "this item has an invalid `clippy::version` attribute",
- None,
- "please use a valid semantic version, see `doc/adding_lints.md`",
- );
- }
- } else {
- span_lint_and_help(
- cx,
- MISSING_CLIPPY_VERSION_ATTRIBUTE,
- item.span,
- "this lint is missing the `clippy::version` attribute or version value",
- None,
- "please use a `clippy::version` attribute, see `doc/adding_lints.md`",
- );
- }
-}
-
-/// This function extracts the version value of a `clippy::version` attribute if the given value has
-/// one
-fn extract_clippy_version_value(cx: &LateContext<'_>, item: &'_ Item<'_>) -> Option<Symbol> {
- let attrs = cx.tcx.hir().attrs(item.hir_id());
- attrs.iter().find_map(|attr| {
- if_chain! {
- // Identify attribute
- if let ast::AttrKind::Normal(ref attr_kind) = &attr.kind;
- if let [tool_name, attr_name] = &attr_kind.item.path.segments[..];
- if tool_name.ident.name == sym::clippy;
- if attr_name.ident.name == sym::version;
- if let Some(version) = attr.value_str();
- then {
- Some(version)
- } else {
- None
- }
- }
- })
-}
-
-struct LintCollector<'a, 'tcx> {
- output: &'a mut FxHashSet<Symbol>,
- cx: &'a LateContext<'tcx>,
-}
-
-impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> {
- type NestedFilter = nested_filter::All;
-
- fn visit_path(&mut self, path: &'tcx Path<'_>, _: HirId) {
- if path.segments.len() == 1 {
- self.output.insert(path.segments[0].ident.name);
- }
- }
-
- fn nested_visit_map(&mut self) -> Self::Map {
- self.cx.tcx.hir()
- }
-}
-
-#[derive(Clone, Default)]
-pub struct CompilerLintFunctions {
- map: FxHashMap<&'static str, &'static str>,
-}
-
-impl CompilerLintFunctions {
- #[must_use]
- pub fn new() -> Self {
- let mut map = FxHashMap::default();
- map.insert("span_lint", "utils::span_lint");
- map.insert("struct_span_lint", "utils::span_lint");
- map.insert("lint", "utils::span_lint");
- map.insert("span_lint_note", "utils::span_lint_and_note");
- map.insert("span_lint_help", "utils::span_lint_and_help");
- Self { map }
- }
-}
-
-impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]);
-
-impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions {
- fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
- if is_lint_allowed(cx, COMPILER_LINT_FUNCTIONS, expr.hir_id) {
- return;
- }
-
- if_chain! {
- if let ExprKind::MethodCall(path, self_arg, _, _) = &expr.kind;
- let fn_name = path.ident;
- if let Some(sugg) = self.map.get(fn_name.as_str());
- let ty = cx.typeck_results().expr_ty(self_arg).peel_refs();
- if match_type(cx, ty, &paths::EARLY_CONTEXT)
- || match_type(cx, ty, &paths::LATE_CONTEXT);
- then {
- span_lint_and_help(
- cx,
- COMPILER_LINT_FUNCTIONS,
- path.ident.span,
- "usage of a compiler lint function",
- None,
- &format!("please use the Clippy variant of this function: `{}`", sugg),
- );
- }
- }
- }
-}
-
-declare_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]);
-
-impl<'tcx> LateLintPass<'tcx> for OuterExpnDataPass {
- fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
- if is_lint_allowed(cx, OUTER_EXPN_EXPN_DATA, expr.hir_id) {
- return;
- }
-
- let (method_names, arg_lists, spans) = method_calls(expr, 2);
- let method_names: Vec<&str> = method_names.iter().map(Symbol::as_str).collect();
- if_chain! {
- if let ["expn_data", "outer_expn"] = method_names.as_slice();
- let (self_arg, args)= arg_lists[1];
- if args.is_empty();
- let self_ty = cx.typeck_results().expr_ty(self_arg).peel_refs();
- if match_type(cx, self_ty, &paths::SYNTAX_CONTEXT);
- then {
- span_lint_and_sugg(
- cx,
- OUTER_EXPN_EXPN_DATA,
- spans[1].with_hi(expr.span.hi()),
- "usage of `outer_expn().expn_data()`",
- "try",
- "outer_expn_data()".to_string(),
- Applicability::MachineApplicable,
- );
- }
- }
- }
-}
-
-declare_lint_pass!(ProduceIce => [PRODUCE_ICE]);
-
-impl EarlyLintPass for ProduceIce {
- fn check_fn(&mut self, _: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: NodeId) {
- assert!(!is_trigger_fn(fn_kind), "Would you like some help with that?");
- }
-}
-
-fn is_trigger_fn(fn_kind: FnKind<'_>) -> bool {
- match fn_kind {
- FnKind::Fn(_, ident, ..) => ident.name.as_str() == "it_looks_like_you_are_trying_to_kill_clippy",
- FnKind::Closure(..) => false,
- }
-}
-
-declare_lint_pass!(CollapsibleCalls => [COLLAPSIBLE_SPAN_LINT_CALLS]);
-
-impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls {
- fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
- if is_lint_allowed(cx, COLLAPSIBLE_SPAN_LINT_CALLS, expr.hir_id) {
- return;
- }
-
- if_chain! {
- if let ExprKind::Call(func, and_then_args) = expr.kind;
- if is_expr_path_def_path(cx, func, &["clippy_utils", "diagnostics", "span_lint_and_then"]);
- if and_then_args.len() == 5;
- if let ExprKind::Closure(&Closure { body, .. }) = &and_then_args[4].kind;
- let body = cx.tcx.hir().body(body);
- let only_expr = peel_blocks_with_stmt(body.value);
- if let ExprKind::MethodCall(ps, recv, span_call_args, _) = &only_expr.kind;
- if let ExprKind::Path(..) = recv.kind;
- then {
- let and_then_snippets = get_and_then_snippets(cx, and_then_args);
- let mut sle = SpanlessEq::new(cx).deny_side_effects();
- match ps.ident.as_str() {
- "span_suggestion" if sle.eq_expr(&and_then_args[2], &span_call_args[0]) => {
- suggest_suggestion(cx, expr, &and_then_snippets, &span_suggestion_snippets(cx, span_call_args));
- },
- "span_help" if sle.eq_expr(&and_then_args[2], &span_call_args[0]) => {
- let help_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
- suggest_help(cx, expr, &and_then_snippets, help_snippet.borrow(), true);
- },
- "span_note" if sle.eq_expr(&and_then_args[2], &span_call_args[0]) => {
- let note_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
- suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow(), true);
- },
- "help" => {
- let help_snippet = snippet(cx, span_call_args[0].span, r#""...""#);
- suggest_help(cx, expr, &and_then_snippets, help_snippet.borrow(), false);
- }
- "note" => {
- let note_snippet = snippet(cx, span_call_args[0].span, r#""...""#);
- suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow(), false);
- }
- _ => (),
- }
- }
- }
- }
-}
-
-struct AndThenSnippets<'a> {
- cx: Cow<'a, str>,
- lint: Cow<'a, str>,
- span: Cow<'a, str>,
- msg: Cow<'a, str>,
-}
-
-fn get_and_then_snippets<'a, 'hir>(cx: &LateContext<'_>, and_then_snippets: &'hir [Expr<'hir>]) -> AndThenSnippets<'a> {
- let cx_snippet = snippet(cx, and_then_snippets[0].span, "cx");
- let lint_snippet = snippet(cx, and_then_snippets[1].span, "..");
- let span_snippet = snippet(cx, and_then_snippets[2].span, "span");
- let msg_snippet = snippet(cx, and_then_snippets[3].span, r#""...""#);
-
- AndThenSnippets {
- cx: cx_snippet,
- lint: lint_snippet,
- span: span_snippet,
- msg: msg_snippet,
- }
-}
-
-struct SpanSuggestionSnippets<'a> {
- help: Cow<'a, str>,
- sugg: Cow<'a, str>,
- applicability: Cow<'a, str>,
-}
-
-fn span_suggestion_snippets<'a, 'hir>(
- cx: &LateContext<'_>,
- span_call_args: &'hir [Expr<'hir>],
-) -> SpanSuggestionSnippets<'a> {
- let help_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
- let sugg_snippet = snippet(cx, span_call_args[2].span, "..");
- let applicability_snippet = snippet(cx, span_call_args[3].span, "Applicability::MachineApplicable");
-
- SpanSuggestionSnippets {
- help: help_snippet,
- sugg: sugg_snippet,
- applicability: applicability_snippet,
- }
-}
-
-fn suggest_suggestion(
- cx: &LateContext<'_>,
- expr: &Expr<'_>,
- and_then_snippets: &AndThenSnippets<'_>,
- span_suggestion_snippets: &SpanSuggestionSnippets<'_>,
-) {
- span_lint_and_sugg(
- cx,
- COLLAPSIBLE_SPAN_LINT_CALLS,
- expr.span,
- "this call is collapsible",
- "collapse into",
- format!(
- "span_lint_and_sugg({}, {}, {}, {}, {}, {}, {})",
- and_then_snippets.cx,
- and_then_snippets.lint,
- and_then_snippets.span,
- and_then_snippets.msg,
- span_suggestion_snippets.help,
- span_suggestion_snippets.sugg,
- span_suggestion_snippets.applicability
- ),
- Applicability::MachineApplicable,
- );
-}
-
-fn suggest_help(
- cx: &LateContext<'_>,
- expr: &Expr<'_>,
- and_then_snippets: &AndThenSnippets<'_>,
- help: &str,
- with_span: bool,
-) {
- let option_span = if with_span {
- format!("Some({})", and_then_snippets.span)
- } else {
- "None".to_string()
- };
-
- span_lint_and_sugg(
- cx,
- COLLAPSIBLE_SPAN_LINT_CALLS,
- expr.span,
- "this call is collapsible",
- "collapse into",
- format!(
- "span_lint_and_help({}, {}, {}, {}, {}, {})",
- and_then_snippets.cx,
- and_then_snippets.lint,
- and_then_snippets.span,
- and_then_snippets.msg,
- &option_span,
- help
- ),
- Applicability::MachineApplicable,
- );
-}
-
-fn suggest_note(
- cx: &LateContext<'_>,
- expr: &Expr<'_>,
- and_then_snippets: &AndThenSnippets<'_>,
- note: &str,
- with_span: bool,
-) {
- let note_span = if with_span {
- format!("Some({})", and_then_snippets.span)
- } else {
- "None".to_string()
- };
-
- span_lint_and_sugg(
- cx,
- COLLAPSIBLE_SPAN_LINT_CALLS,
- expr.span,
- "this call is collapsible",
- "collapse into",
- format!(
- "span_lint_and_note({}, {}, {}, {}, {}, {})",
- and_then_snippets.cx,
- and_then_snippets.lint,
- and_then_snippets.span,
- and_then_snippets.msg,
- note_span,
- note
- ),
- Applicability::MachineApplicable,
- );
-}
-
-declare_lint_pass!(MatchTypeOnDiagItem => [MATCH_TYPE_ON_DIAGNOSTIC_ITEM]);
-
-impl<'tcx> LateLintPass<'tcx> for MatchTypeOnDiagItem {
- fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
- if is_lint_allowed(cx, MATCH_TYPE_ON_DIAGNOSTIC_ITEM, expr.hir_id) {
- return;
- }
-
- if_chain! {
- // Check if this is a call to utils::match_type()
- if let ExprKind::Call(fn_path, [context, ty, ty_path]) = expr.kind;
- if is_expr_path_def_path(cx, fn_path, &["clippy_utils", "ty", "match_type"]);
- // Extract the path to the matched type
- if let Some(segments) = path_to_matched_type(cx, ty_path);
- let segments: Vec<&str> = segments.iter().map(Symbol::as_str).collect();
- if let Some(ty_did) = def_path_res(cx, &segments[..]).opt_def_id();
- // Check if the matched type is a diagnostic item
- if let Some(item_name) = cx.tcx.get_diagnostic_name(ty_did);
- then {
- // TODO: check paths constants from external crates.
- let cx_snippet = snippet(cx, context.span, "_");
- let ty_snippet = snippet(cx, ty.span, "_");
-
- span_lint_and_sugg(
- cx,
- MATCH_TYPE_ON_DIAGNOSTIC_ITEM,
- expr.span,
- "usage of `clippy_utils::ty::match_type()` on a type diagnostic item",
- "try",
- format!("clippy_utils::ty::is_type_diagnostic_item({}, {}, sym::{})", cx_snippet, ty_snippet, item_name),
- Applicability::MaybeIncorrect,
- );
- }
- }
- }
-}
-
-fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<Vec<Symbol>> {
- use rustc_hir::ItemKind;
-
- match &expr.kind {
- ExprKind::AddrOf(.., expr) => return path_to_matched_type(cx, expr),
- ExprKind::Path(qpath) => match cx.qpath_res(qpath, expr.hir_id) {
- Res::Local(hir_id) => {
- let parent_id = cx.tcx.hir().get_parent_node(hir_id);
- if let Some(Node::Local(local)) = cx.tcx.hir().find(parent_id) {
- if let Some(init) = local.init {
- return path_to_matched_type(cx, init);
- }
- }
- },
- Res::Def(DefKind::Const | DefKind::Static(..), def_id) => {
- if let Some(Node::Item(item)) = cx.tcx.hir().get_if_local(def_id) {
- if let ItemKind::Const(.., body_id) | ItemKind::Static(.., body_id) = item.kind {
- let body = cx.tcx.hir().body(body_id);
- return path_to_matched_type(cx, body.value);
- }
- }
- },
- _ => {},
- },
- ExprKind::Array(exprs) => {
- let segments: Vec<Symbol> = exprs
- .iter()
- .filter_map(|expr| {
- if let ExprKind::Lit(lit) = &expr.kind {
- if let LitKind::Str(sym, _) = lit.node {
- return Some(sym);
- }
- }
-
- None
- })
- .collect();
-
- if segments.len() == exprs.len() {
- return Some(segments);
- }
- },
- _ => {},
- }
-
- None
-}
-
-// This is not a complete resolver for paths. It works on all the paths currently used in the paths
-// module. That's all it does and all it needs to do.
-pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
- if def_path_res(cx, path) != Res::Err {
- return true;
- }
-
- // Some implementations can't be found by `path_to_res`, particularly inherent
- // implementations of native types. Check lang items.
- let path_syms: Vec<_> = path.iter().map(|p| Symbol::intern(p)).collect();
- let lang_items = cx.tcx.lang_items();
- // This list isn't complete, but good enough for our current list of paths.
- let incoherent_impls = [
- SimplifiedTypeGen::FloatSimplifiedType(FloatTy::F32),
- SimplifiedTypeGen::FloatSimplifiedType(FloatTy::F64),
- SimplifiedTypeGen::SliceSimplifiedType,
- SimplifiedTypeGen::StrSimplifiedType,
- ]
- .iter()
- .flat_map(|&ty| cx.tcx.incoherent_impls(ty));
- for item_def_id in lang_items.items().iter().flatten().chain(incoherent_impls) {
- let lang_item_path = cx.get_def_path(*item_def_id);
- if path_syms.starts_with(&lang_item_path) {
- if let [item] = &path_syms[lang_item_path.len()..] {
- if matches!(
- cx.tcx.def_kind(*item_def_id),
- DefKind::Mod | DefKind::Enum | DefKind::Trait
- ) {
- for child in cx.tcx.module_children(*item_def_id) {
- if child.ident.name == *item {
- return true;
- }
- }
- } else {
- for child in cx.tcx.associated_item_def_ids(*item_def_id) {
- if cx.tcx.item_name(*child) == *item {
- return true;
- }
- }
- }
- }
- }
- }
-
- false
-}
-
-declare_lint_pass!(InvalidPaths => [INVALID_PATHS]);
-
-impl<'tcx> LateLintPass<'tcx> for InvalidPaths {
- fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
- let local_def_id = &cx.tcx.parent_module(item.hir_id());
- let mod_name = &cx.tcx.item_name(local_def_id.to_def_id());
- if_chain! {
- if mod_name.as_str() == "paths";
- if let hir::ItemKind::Const(ty, body_id) = item.kind;
- let ty = hir_ty_to_ty(cx.tcx, ty);
- if let ty::Array(el_ty, _) = &ty.kind();
- if let ty::Ref(_, el_ty, _) = &el_ty.kind();
- if el_ty.is_str();
- let body = cx.tcx.hir().body(body_id);
- let typeck_results = cx.tcx.typeck_body(body_id);
- if let Some(Constant::Vec(path)) = constant_simple(cx, typeck_results, body.value);
- let path: Vec<&str> = path.iter().map(|x| {
- if let Constant::Str(s) = x {
- s.as_str()
- } else {
- // We checked the type of the constant above
- unreachable!()
- }
- }).collect();
- if !check_path(cx, &path[..]);
- then {
- span_lint(cx, INVALID_PATHS, item.span, "invalid path");
- }
- }
- }
-}
-
-#[derive(Default)]
-pub struct InterningDefinedSymbol {
- // Maps the symbol value to the constant DefId.
- symbol_map: FxHashMap<u32, DefId>,
-}
-
-impl_lint_pass!(InterningDefinedSymbol => [INTERNING_DEFINED_SYMBOL, UNNECESSARY_SYMBOL_STR]);
-
-impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol {
- fn check_crate(&mut self, cx: &LateContext<'_>) {
- if !self.symbol_map.is_empty() {
- return;
- }
-
- for &module in &[&paths::KW_MODULE, &paths::SYM_MODULE] {
- if let Some(def_id) = def_path_res(cx, module).opt_def_id() {
- for item in cx.tcx.module_children(def_id).iter() {
- if_chain! {
- if let Res::Def(DefKind::Const, item_def_id) = item.res;
- let ty = cx.tcx.type_of(item_def_id);
- if match_type(cx, ty, &paths::SYMBOL);
- if let Ok(ConstValue::Scalar(value)) = cx.tcx.const_eval_poly(item_def_id);
- if let Ok(value) = value.to_u32();
- then {
- self.symbol_map.insert(value, item_def_id);
- }
- }
- }
- }
- }
- }
-
- fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
- if_chain! {
- if let ExprKind::Call(func, [arg]) = &expr.kind;
- if let ty::FnDef(def_id, _) = cx.typeck_results().expr_ty(func).kind();
- if match_def_path(cx, *def_id, &paths::SYMBOL_INTERN);
- if let Some(Constant::Str(arg)) = constant_simple(cx, cx.typeck_results(), arg);
- let value = Symbol::intern(&arg).as_u32();
- if let Some(&def_id) = self.symbol_map.get(&value);
- then {
- span_lint_and_sugg(
- cx,
- INTERNING_DEFINED_SYMBOL,
- is_expn_of(expr.span, "sym").unwrap_or(expr.span),
- "interning a defined symbol",
- "try",
- cx.tcx.def_path_str(def_id),
- Applicability::MachineApplicable,
- );
- }
- }
- if let ExprKind::Binary(op, left, right) = expr.kind {
- if matches!(op.node, BinOpKind::Eq | BinOpKind::Ne) {
- let data = [
- (left, self.symbol_str_expr(left, cx)),
- (right, self.symbol_str_expr(right, cx)),
- ];
- match data {
- // both operands are a symbol string
- [(_, Some(left)), (_, Some(right))] => {
- span_lint_and_sugg(
- cx,
- UNNECESSARY_SYMBOL_STR,
- expr.span,
- "unnecessary `Symbol` to string conversion",
- "try",
- format!(
- "{} {} {}",
- left.as_symbol_snippet(cx),
- op.node.as_str(),
- right.as_symbol_snippet(cx),
- ),
- Applicability::MachineApplicable,
- );
- },
- // one of the operands is a symbol string
- [(expr, Some(symbol)), _] | [_, (expr, Some(symbol))] => {
- // creating an owned string for comparison
- if matches!(symbol, SymbolStrExpr::Expr { is_to_owned: true, .. }) {
- span_lint_and_sugg(
- cx,
- UNNECESSARY_SYMBOL_STR,
- expr.span,
- "unnecessary string allocation",
- "try",
- format!("{}.as_str()", symbol.as_symbol_snippet(cx)),
- Applicability::MachineApplicable,
- );
- }
- },
- // nothing found
- [(_, None), (_, None)] => {},
- }
- }
- }
- }
-}
-
-impl InterningDefinedSymbol {
- fn symbol_str_expr<'tcx>(&self, expr: &'tcx Expr<'tcx>, cx: &LateContext<'tcx>) -> Option<SymbolStrExpr<'tcx>> {
- static IDENT_STR_PATHS: &[&[&str]] = &[&paths::IDENT_AS_STR, &paths::TO_STRING_METHOD];
- static SYMBOL_STR_PATHS: &[&[&str]] = &[
- &paths::SYMBOL_AS_STR,
- &paths::SYMBOL_TO_IDENT_STRING,
- &paths::TO_STRING_METHOD,
- ];
- let call = if_chain! {
- if let ExprKind::AddrOf(_, _, e) = expr.kind;
- if let ExprKind::Unary(UnOp::Deref, e) = e.kind;
- then { e } else { expr }
- };
- if_chain! {
- // is a method call
- if let ExprKind::MethodCall(_, item, [], _) = call.kind;
- if let Some(did) = cx.typeck_results().type_dependent_def_id(call.hir_id);
- let ty = cx.typeck_results().expr_ty(item);
- // ...on either an Ident or a Symbol
- if let Some(is_ident) = if match_type(cx, ty, &paths::SYMBOL) {
- Some(false)
- } else if match_type(cx, ty, &paths::IDENT) {
- Some(true)
- } else {
- None
- };
- // ...which converts it to a string
- let paths = if is_ident { IDENT_STR_PATHS } else { SYMBOL_STR_PATHS };
- if let Some(path) = paths.iter().find(|path| match_def_path(cx, did, path));
- then {
- let is_to_owned = path.last().unwrap().ends_with("string");
- return Some(SymbolStrExpr::Expr {
- item,
- is_ident,
- is_to_owned,
- });
- }
- }
- // is a string constant
- if let Some(Constant::Str(s)) = constant_simple(cx, cx.typeck_results(), expr) {
- let value = Symbol::intern(&s).as_u32();
- // ...which matches a symbol constant
- if let Some(&def_id) = self.symbol_map.get(&value) {
- return Some(SymbolStrExpr::Const(def_id));
- }
- }
- None
- }
-}
-
-enum SymbolStrExpr<'tcx> {
- /// a string constant with a corresponding symbol constant
- Const(DefId),
- /// a "symbol to string" expression like `symbol.as_str()`
- Expr {
- /// part that evaluates to `Symbol` or `Ident`
- item: &'tcx Expr<'tcx>,
- is_ident: bool,
- /// whether an owned `String` is created like `to_ident_string()`
- is_to_owned: bool,
- },
-}
-
-impl<'tcx> SymbolStrExpr<'tcx> {
- /// Returns a snippet that evaluates to a `Symbol` and is const if possible
- fn as_symbol_snippet(&self, cx: &LateContext<'_>) -> Cow<'tcx, str> {
- match *self {
- Self::Const(def_id) => cx.tcx.def_path_str(def_id).into(),
- Self::Expr { item, is_ident, .. } => {
- let mut snip = snippet(cx, item.span.source_callsite(), "..");
- if is_ident {
- // get `Ident.name`
- snip.to_mut().push_str(".name");
- }
- snip
- },
- }
- }
-}
-
-declare_lint_pass!(IfChainStyle => [IF_CHAIN_STYLE]);
-
-impl<'tcx> LateLintPass<'tcx> for IfChainStyle {
- fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'_>) {
- let (local, after, if_chain_span) = if_chain! {
- if let [Stmt { kind: StmtKind::Local(local), .. }, after @ ..] = block.stmts;
- if let Some(if_chain_span) = is_expn_of(block.span, "if_chain");
- then { (local, after, if_chain_span) } else { return }
- };
- if is_first_if_chain_expr(cx, block.hir_id, if_chain_span) {
- span_lint(
- cx,
- IF_CHAIN_STYLE,
- if_chain_local_span(cx, local, if_chain_span),
- "`let` expression should be above the `if_chain!`",
- );
- } else if local.span.ctxt() == block.span.ctxt() && is_if_chain_then(after, block.expr, if_chain_span) {
- span_lint(
- cx,
- IF_CHAIN_STYLE,
- if_chain_local_span(cx, local, if_chain_span),
- "`let` expression should be inside `then { .. }`",
- );
- }
- }
-
- fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
- let (cond, then, els) = if let Some(higher::IfOrIfLet { cond, r#else, then }) = higher::IfOrIfLet::hir(expr) {
- (cond, then, r#else.is_some())
- } else {
- return;
- };
- let then_block = match then.kind {
- ExprKind::Block(block, _) => block,
- _ => return,
- };
- let if_chain_span = is_expn_of(expr.span, "if_chain");
- if !els {
- check_nested_if_chains(cx, expr, then_block, if_chain_span);
- }
- let if_chain_span = match if_chain_span {
- None => return,
- Some(span) => span,
- };
- // check for `if a && b;`
- if_chain! {
- if let ExprKind::Binary(op, _, _) = cond.kind;
- if op.node == BinOpKind::And;
- if cx.sess().source_map().is_multiline(cond.span);
- then {
- span_lint(cx, IF_CHAIN_STYLE, cond.span, "`if a && b;` should be `if a; if b;`");
- }
- }
- if is_first_if_chain_expr(cx, expr.hir_id, if_chain_span)
- && is_if_chain_then(then_block.stmts, then_block.expr, if_chain_span)
- {
- span_lint(cx, IF_CHAIN_STYLE, expr.span, "`if_chain!` only has one `if`");
- }
- }
-}
-
-fn check_nested_if_chains(
- cx: &LateContext<'_>,
- if_expr: &Expr<'_>,
- then_block: &Block<'_>,
- if_chain_span: Option<Span>,
-) {
- #[rustfmt::skip]
- let (head, tail) = match *then_block {
- Block { stmts, expr: Some(tail), .. } => (stmts, tail),
- Block {
- stmts: &[
- ref head @ ..,
- Stmt { kind: StmtKind::Expr(tail) | StmtKind::Semi(tail), .. }
- ],
- ..
- } => (head, tail),
- _ => return,
- };
- if_chain! {
- if let Some(higher::IfOrIfLet { r#else: None, .. }) = higher::IfOrIfLet::hir(tail);
- let sm = cx.sess().source_map();
- if head
- .iter()
- .all(|stmt| matches!(stmt.kind, StmtKind::Local(..)) && !sm.is_multiline(stmt.span));
- if if_chain_span.is_some() || !is_else_clause(cx.tcx, if_expr);
- then {} else { return }
- }
- let (span, msg) = match (if_chain_span, is_expn_of(tail.span, "if_chain")) {
- (None, Some(_)) => (if_expr.span, "this `if` can be part of the inner `if_chain!`"),
- (Some(_), None) => (tail.span, "this `if` can be part of the outer `if_chain!`"),
- (Some(a), Some(b)) if a != b => (b, "this `if_chain!` can be merged with the outer `if_chain!`"),
- _ => return,
- };
- span_lint_and_then(cx, IF_CHAIN_STYLE, span, msg, |diag| {
- let (span, msg) = match head {
- [] => return,
- [stmt] => (stmt.span, "this `let` statement can also be in the `if_chain!`"),
- [a, .., b] => (
- a.span.to(b.span),
- "these `let` statements can also be in the `if_chain!`",
- ),
- };
- diag.span_help(span, msg);
- });
-}
-
-fn is_first_if_chain_expr(cx: &LateContext<'_>, hir_id: HirId, if_chain_span: Span) -> bool {
- cx.tcx
- .hir()
- .parent_iter(hir_id)
- .find(|(_, node)| {
- #[rustfmt::skip]
- !matches!(node, Node::Expr(Expr { kind: ExprKind::Block(..), .. }) | Node::Stmt(_))
- })
- .map_or(false, |(id, _)| {
- is_expn_of(cx.tcx.hir().span(id), "if_chain") != Some(if_chain_span)
- })
-}
-
-/// Checks a trailing slice of statements and expression of a `Block` to see if they are part
-/// of the `then {..}` portion of an `if_chain!`
-fn is_if_chain_then(stmts: &[Stmt<'_>], expr: Option<&Expr<'_>>, if_chain_span: Span) -> bool {
- let span = if let [stmt, ..] = stmts {
- stmt.span
- } else if let Some(expr) = expr {
- expr.span
- } else {
- // empty `then {}`
- return true;
- };
- is_expn_of(span, "if_chain").map_or(true, |span| span != if_chain_span)
-}
-
-/// Creates a `Span` for `let x = ..;` in an `if_chain!` call.
-fn if_chain_local_span(cx: &LateContext<'_>, local: &Local<'_>, if_chain_span: Span) -> Span {
- let mut span = local.pat.span;
- if let Some(init) = local.init {
- span = span.to(init.span);
- }
- span.adjust(if_chain_span.ctxt().outer_expn());
- let sm = cx.sess().source_map();
- let span = sm.span_extend_to_prev_str(span, "let", false, true).unwrap_or(span);
- let span = sm.span_extend_to_next_char(span, ';', false);
- Span::new(
- span.lo() - BytePos(3),
- span.hi() + BytePos(1),
- span.ctxt(),
- span.parent(),
- )
-}
-
-declare_lint_pass!(MsrvAttrImpl => [MISSING_MSRV_ATTR_IMPL]);
-
-impl LateLintPass<'_> for MsrvAttrImpl {
- fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
- if_chain! {
- if let hir::ItemKind::Impl(hir::Impl {
- of_trait: Some(lint_pass_trait_ref),
- self_ty,
- items,
- ..
- }) = &item.kind;
- if let Some(lint_pass_trait_def_id) = lint_pass_trait_ref.trait_def_id();
- let is_late_pass = match_def_path(cx, lint_pass_trait_def_id, &paths::LATE_LINT_PASS);
- if is_late_pass || match_def_path(cx, lint_pass_trait_def_id, &paths::EARLY_LINT_PASS);
- let self_ty = hir_ty_to_ty(cx.tcx, self_ty);
- if let ty::Adt(self_ty_def, _) = self_ty.kind();
- if self_ty_def.is_struct();
- if self_ty_def.all_fields().any(|f| {
- cx.tcx
- .type_of(f.did)
- .walk()
- .filter(|t| matches!(t.unpack(), GenericArgKind::Type(_)))
- .any(|t| match_type(cx, t.expect_ty(), &paths::RUSTC_VERSION))
- });
- if !items.iter().any(|item| item.ident.name == sym!(enter_lint_attrs));
- then {
- let context = if is_late_pass { "LateContext" } else { "EarlyContext" };
- let lint_pass = if is_late_pass { "LateLintPass" } else { "EarlyLintPass" };
- let span = cx.sess().source_map().span_through_char(item.span, '{');
- span_lint_and_sugg(
- cx,
- MISSING_MSRV_ATTR_IMPL,
- span,
- &format!("`extract_msrv_attr!` macro missing from `{lint_pass}` implementation"),
- &format!("add `extract_msrv_attr!({context})` to the `{lint_pass}` implementation"),
- format!("{}\n extract_msrv_attr!({context});", snippet(cx, span, "..")),
- Applicability::MachineApplicable,
- );
- }
- }
- }
-}
+pub mod msrv_attr_impl;
+pub mod outer_expn_data_pass;
+pub mod produce_ice;
+pub mod unnecessary_def_path;
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/clippy_lints_internal.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/clippy_lints_internal.rs
new file mode 100644
index 000000000..da9514dd1
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/clippy_lints_internal.rs
@@ -0,0 +1,49 @@
+use clippy_utils::diagnostics::span_lint;
+use rustc_ast::ast::{Crate, ItemKind, ModKind};
+use rustc_lint::{EarlyContext, EarlyLintPass};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for various things we like to keep tidy in clippy.
+ ///
+ /// ### Why is this bad?
+ /// We like to pretend we're an example of tidy code.
+ ///
+ /// ### Example
+ /// Wrong ordering of the util::paths constants.
+ pub CLIPPY_LINTS_INTERNAL,
+ internal,
+ "various things that will negatively affect your clippy experience"
+}
+
+declare_lint_pass!(ClippyLintsInternal => [CLIPPY_LINTS_INTERNAL]);
+
+impl EarlyLintPass for ClippyLintsInternal {
+ fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &Crate) {
+ if let Some(utils) = krate.items.iter().find(|item| item.ident.name.as_str() == "utils") {
+ if let ItemKind::Mod(_, ModKind::Loaded(ref items, ..)) = utils.kind {
+ if let Some(paths) = items.iter().find(|item| item.ident.name.as_str() == "paths") {
+ if let ItemKind::Mod(_, ModKind::Loaded(ref items, ..)) = paths.kind {
+ let mut last_name: Option<&str> = None;
+ for item in items {
+ let name = item.ident.as_str();
+ if let Some(last_name) = last_name {
+ if *last_name > *name {
+ span_lint(
+ cx,
+ CLIPPY_LINTS_INTERNAL,
+ item.span,
+ "this constant should be before the previous constant due to lexical \
+ ordering",
+ );
+ }
+ }
+ last_name = Some(name);
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/collapsible_calls.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/collapsible_calls.rs
new file mode 100644
index 000000000..d7666b77f
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/collapsible_calls.rs
@@ -0,0 +1,245 @@
+use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::source::snippet;
+use clippy_utils::{is_expr_path_def_path, is_lint_allowed, peel_blocks_with_stmt, SpanlessEq};
+use if_chain::if_chain;
+use rustc_errors::Applicability;
+use rustc_hir as hir;
+use rustc_hir::{Closure, Expr, ExprKind};
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+
+use std::borrow::{Borrow, Cow};
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Lints `span_lint_and_then` function calls, where the
+ /// closure argument has only one statement and that statement is a method
+ /// call to `span_suggestion`, `span_help`, `span_note` (using the same
+ /// span), `help` or `note`.
+ ///
+ /// These usages of `span_lint_and_then` should be replaced with one of the
+ /// wrapper functions `span_lint_and_sugg`, span_lint_and_help`, or
+ /// `span_lint_and_note`.
+ ///
+ /// ### Why is this bad?
+ /// Using the wrapper `span_lint_and_*` functions, is more
+ /// convenient, readable and less error prone.
+ ///
+ /// ### Example
+ /// ```rust,ignore
+ /// span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |diag| {
+ /// diag.span_suggestion(
+ /// expr.span,
+ /// help_msg,
+ /// sugg.to_string(),
+ /// Applicability::MachineApplicable,
+ /// );
+ /// });
+ /// span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |diag| {
+ /// diag.span_help(expr.span, help_msg);
+ /// });
+ /// span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |diag| {
+ /// diag.help(help_msg);
+ /// });
+ /// span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |diag| {
+ /// diag.span_note(expr.span, note_msg);
+ /// });
+ /// span_lint_and_then(cx, TEST_LINT, expr.span, lint_msg, |diag| {
+ /// diag.note(note_msg);
+ /// });
+ /// ```
+ ///
+ /// Use instead:
+ /// ```rust,ignore
+ /// span_lint_and_sugg(
+ /// cx,
+ /// TEST_LINT,
+ /// expr.span,
+ /// lint_msg,
+ /// help_msg,
+ /// sugg.to_string(),
+ /// Applicability::MachineApplicable,
+ /// );
+ /// span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), help_msg);
+ /// span_lint_and_help(cx, TEST_LINT, expr.span, lint_msg, None, help_msg);
+ /// span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, Some(expr.span), note_msg);
+ /// span_lint_and_note(cx, TEST_LINT, expr.span, lint_msg, None, note_msg);
+ /// ```
+ pub COLLAPSIBLE_SPAN_LINT_CALLS,
+ internal,
+ "found collapsible `span_lint_and_then` calls"
+}
+
+declare_lint_pass!(CollapsibleCalls => [COLLAPSIBLE_SPAN_LINT_CALLS]);
+
+impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls {
+ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
+ if is_lint_allowed(cx, COLLAPSIBLE_SPAN_LINT_CALLS, expr.hir_id) {
+ return;
+ }
+
+ if_chain! {
+ if let ExprKind::Call(func, and_then_args) = expr.kind;
+ if is_expr_path_def_path(cx, func, &["clippy_utils", "diagnostics", "span_lint_and_then"]);
+ if and_then_args.len() == 5;
+ if let ExprKind::Closure(&Closure { body, .. }) = &and_then_args[4].kind;
+ let body = cx.tcx.hir().body(body);
+ let only_expr = peel_blocks_with_stmt(body.value);
+ if let ExprKind::MethodCall(ps, recv, span_call_args, _) = &only_expr.kind;
+ if let ExprKind::Path(..) = recv.kind;
+ then {
+ let and_then_snippets = get_and_then_snippets(cx, and_then_args);
+ let mut sle = SpanlessEq::new(cx).deny_side_effects();
+ match ps.ident.as_str() {
+ "span_suggestion" if sle.eq_expr(&and_then_args[2], &span_call_args[0]) => {
+ suggest_suggestion(
+ cx,
+ expr,
+ &and_then_snippets,
+ &span_suggestion_snippets(cx, span_call_args),
+ );
+ },
+ "span_help" if sle.eq_expr(&and_then_args[2], &span_call_args[0]) => {
+ let help_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
+ suggest_help(cx, expr, &and_then_snippets, help_snippet.borrow(), true);
+ },
+ "span_note" if sle.eq_expr(&and_then_args[2], &span_call_args[0]) => {
+ let note_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
+ suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow(), true);
+ },
+ "help" => {
+ let help_snippet = snippet(cx, span_call_args[0].span, r#""...""#);
+ suggest_help(cx, expr, &and_then_snippets, help_snippet.borrow(), false);
+ },
+ "note" => {
+ let note_snippet = snippet(cx, span_call_args[0].span, r#""...""#);
+ suggest_note(cx, expr, &and_then_snippets, note_snippet.borrow(), false);
+ },
+ _ => (),
+ }
+ }
+ }
+ }
+}
+
+struct AndThenSnippets<'a> {
+ cx: Cow<'a, str>,
+ lint: Cow<'a, str>,
+ span: Cow<'a, str>,
+ msg: Cow<'a, str>,
+}
+
+fn get_and_then_snippets<'a, 'hir>(cx: &LateContext<'_>, and_then_snippets: &'hir [Expr<'hir>]) -> AndThenSnippets<'a> {
+ let cx_snippet = snippet(cx, and_then_snippets[0].span, "cx");
+ let lint_snippet = snippet(cx, and_then_snippets[1].span, "..");
+ let span_snippet = snippet(cx, and_then_snippets[2].span, "span");
+ let msg_snippet = snippet(cx, and_then_snippets[3].span, r#""...""#);
+
+ AndThenSnippets {
+ cx: cx_snippet,
+ lint: lint_snippet,
+ span: span_snippet,
+ msg: msg_snippet,
+ }
+}
+
+struct SpanSuggestionSnippets<'a> {
+ help: Cow<'a, str>,
+ sugg: Cow<'a, str>,
+ applicability: Cow<'a, str>,
+}
+
+fn span_suggestion_snippets<'a, 'hir>(
+ cx: &LateContext<'_>,
+ span_call_args: &'hir [Expr<'hir>],
+) -> SpanSuggestionSnippets<'a> {
+ let help_snippet = snippet(cx, span_call_args[1].span, r#""...""#);
+ let sugg_snippet = snippet(cx, span_call_args[2].span, "..");
+ let applicability_snippet = snippet(cx, span_call_args[3].span, "Applicability::MachineApplicable");
+
+ SpanSuggestionSnippets {
+ help: help_snippet,
+ sugg: sugg_snippet,
+ applicability: applicability_snippet,
+ }
+}
+
+fn suggest_suggestion(
+ cx: &LateContext<'_>,
+ expr: &Expr<'_>,
+ and_then_snippets: &AndThenSnippets<'_>,
+ span_suggestion_snippets: &SpanSuggestionSnippets<'_>,
+) {
+ span_lint_and_sugg(
+ cx,
+ COLLAPSIBLE_SPAN_LINT_CALLS,
+ expr.span,
+ "this call is collapsible",
+ "collapse into",
+ format!(
+ "span_lint_and_sugg({}, {}, {}, {}, {}, {}, {})",
+ and_then_snippets.cx,
+ and_then_snippets.lint,
+ and_then_snippets.span,
+ and_then_snippets.msg,
+ span_suggestion_snippets.help,
+ span_suggestion_snippets.sugg,
+ span_suggestion_snippets.applicability
+ ),
+ Applicability::MachineApplicable,
+ );
+}
+
+fn suggest_help(
+ cx: &LateContext<'_>,
+ expr: &Expr<'_>,
+ and_then_snippets: &AndThenSnippets<'_>,
+ help: &str,
+ with_span: bool,
+) {
+ let option_span = if with_span {
+ format!("Some({})", and_then_snippets.span)
+ } else {
+ "None".to_string()
+ };
+
+ span_lint_and_sugg(
+ cx,
+ COLLAPSIBLE_SPAN_LINT_CALLS,
+ expr.span,
+ "this call is collapsible",
+ "collapse into",
+ format!(
+ "span_lint_and_help({}, {}, {}, {}, {}, {help})",
+ and_then_snippets.cx, and_then_snippets.lint, and_then_snippets.span, and_then_snippets.msg, &option_span,
+ ),
+ Applicability::MachineApplicable,
+ );
+}
+
+fn suggest_note(
+ cx: &LateContext<'_>,
+ expr: &Expr<'_>,
+ and_then_snippets: &AndThenSnippets<'_>,
+ note: &str,
+ with_span: bool,
+) {
+ let note_span = if with_span {
+ format!("Some({})", and_then_snippets.span)
+ } else {
+ "None".to_string()
+ };
+
+ span_lint_and_sugg(
+ cx,
+ COLLAPSIBLE_SPAN_LINT_CALLS,
+ expr.span,
+ "this call is collapsible",
+ "collapse into",
+ format!(
+ "span_lint_and_note({}, {}, {}, {}, {note_span}, {note})",
+ and_then_snippets.cx, and_then_snippets.lint, and_then_snippets.span, and_then_snippets.msg,
+ ),
+ Applicability::MachineApplicable,
+ );
+}
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/compiler_lint_functions.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/compiler_lint_functions.rs
new file mode 100644
index 000000000..cacd05262
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/compiler_lint_functions.rs
@@ -0,0 +1,77 @@
+use clippy_utils::diagnostics::span_lint_and_help;
+use clippy_utils::ty::match_type;
+use clippy_utils::{is_lint_allowed, paths};
+use if_chain::if_chain;
+use rustc_data_structures::fx::FxHashMap;
+use rustc_hir::{Expr, ExprKind};
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_session::{declare_tool_lint, impl_lint_pass};
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for calls to `cx.span_lint*` and suggests to use the `utils::*`
+ /// variant of the function.
+ ///
+ /// ### Why is this bad?
+ /// The `utils::*` variants also add a link to the Clippy documentation to the
+ /// warning/error messages.
+ ///
+ /// ### Example
+ /// ```rust,ignore
+ /// cx.span_lint(LINT_NAME, "message");
+ /// ```
+ ///
+ /// Use instead:
+ /// ```rust,ignore
+ /// utils::span_lint(cx, LINT_NAME, "message");
+ /// ```
+ pub COMPILER_LINT_FUNCTIONS,
+ internal,
+ "usage of the lint functions of the compiler instead of the utils::* variant"
+}
+
+impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]);
+
+#[derive(Clone, Default)]
+pub struct CompilerLintFunctions {
+ map: FxHashMap<&'static str, &'static str>,
+}
+
+impl CompilerLintFunctions {
+ #[must_use]
+ pub fn new() -> Self {
+ let mut map = FxHashMap::default();
+ map.insert("span_lint", "utils::span_lint");
+ map.insert("struct_span_lint", "utils::span_lint");
+ map.insert("lint", "utils::span_lint");
+ map.insert("span_lint_note", "utils::span_lint_and_note");
+ map.insert("span_lint_help", "utils::span_lint_and_help");
+ Self { map }
+ }
+}
+
+impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions {
+ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
+ if is_lint_allowed(cx, COMPILER_LINT_FUNCTIONS, expr.hir_id) {
+ return;
+ }
+
+ if_chain! {
+ if let ExprKind::MethodCall(path, self_arg, _, _) = &expr.kind;
+ let fn_name = path.ident;
+ if let Some(sugg) = self.map.get(fn_name.as_str());
+ let ty = cx.typeck_results().expr_ty(self_arg).peel_refs();
+ if match_type(cx, ty, &paths::EARLY_CONTEXT) || match_type(cx, ty, &paths::LATE_CONTEXT);
+ then {
+ span_lint_and_help(
+ cx,
+ COMPILER_LINT_FUNCTIONS,
+ path.ident.span,
+ "usage of a compiler lint function",
+ None,
+ &format!("please use the Clippy variant of this function: `{sugg}`"),
+ );
+ }
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/if_chain_style.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/if_chain_style.rs
new file mode 100644
index 000000000..883a5c08e
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/if_chain_style.rs
@@ -0,0 +1,164 @@
+use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
+use clippy_utils::{higher, is_else_clause, is_expn_of};
+use if_chain::if_chain;
+use rustc_hir as hir;
+use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, Local, Node, Stmt, StmtKind};
+use rustc_lint::{LateContext, LateLintPass, LintContext};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::{BytePos, Span};
+
+declare_clippy_lint! {
+ /// Finds unidiomatic usage of `if_chain!`
+ pub IF_CHAIN_STYLE,
+ internal,
+ "non-idiomatic `if_chain!` usage"
+}
+
+declare_lint_pass!(IfChainStyle => [IF_CHAIN_STYLE]);
+
+impl<'tcx> LateLintPass<'tcx> for IfChainStyle {
+ fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'_>) {
+ let (local, after, if_chain_span) = if_chain! {
+ if let [Stmt { kind: StmtKind::Local(local), .. }, after @ ..] = block.stmts;
+ if let Some(if_chain_span) = is_expn_of(block.span, "if_chain");
+ then { (local, after, if_chain_span) } else { return }
+ };
+ if is_first_if_chain_expr(cx, block.hir_id, if_chain_span) {
+ span_lint(
+ cx,
+ IF_CHAIN_STYLE,
+ if_chain_local_span(cx, local, if_chain_span),
+ "`let` expression should be above the `if_chain!`",
+ );
+ } else if local.span.ctxt() == block.span.ctxt() && is_if_chain_then(after, block.expr, if_chain_span) {
+ span_lint(
+ cx,
+ IF_CHAIN_STYLE,
+ if_chain_local_span(cx, local, if_chain_span),
+ "`let` expression should be inside `then { .. }`",
+ );
+ }
+ }
+
+ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
+ let (cond, then, els) = if let Some(higher::IfOrIfLet { cond, r#else, then }) = higher::IfOrIfLet::hir(expr) {
+ (cond, then, r#else.is_some())
+ } else {
+ return;
+ };
+ let ExprKind::Block(then_block, _) = then.kind else { return };
+ let if_chain_span = is_expn_of(expr.span, "if_chain");
+ if !els {
+ check_nested_if_chains(cx, expr, then_block, if_chain_span);
+ }
+ let Some(if_chain_span) = if_chain_span else { return };
+ // check for `if a && b;`
+ if_chain! {
+ if let ExprKind::Binary(op, _, _) = cond.kind;
+ if op.node == BinOpKind::And;
+ if cx.sess().source_map().is_multiline(cond.span);
+ then {
+ span_lint(cx, IF_CHAIN_STYLE, cond.span, "`if a && b;` should be `if a; if b;`");
+ }
+ }
+ if is_first_if_chain_expr(cx, expr.hir_id, if_chain_span)
+ && is_if_chain_then(then_block.stmts, then_block.expr, if_chain_span)
+ {
+ span_lint(cx, IF_CHAIN_STYLE, expr.span, "`if_chain!` only has one `if`");
+ }
+ }
+}
+
+fn check_nested_if_chains(
+ cx: &LateContext<'_>,
+ if_expr: &Expr<'_>,
+ then_block: &Block<'_>,
+ if_chain_span: Option<Span>,
+) {
+ #[rustfmt::skip]
+ let (head, tail) = match *then_block {
+ Block { stmts, expr: Some(tail), .. } => (stmts, tail),
+ Block {
+ stmts: &[
+ ref head @ ..,
+ Stmt { kind: StmtKind::Expr(tail) | StmtKind::Semi(tail), .. }
+ ],
+ ..
+ } => (head, tail),
+ _ => return,
+ };
+ if_chain! {
+ if let Some(higher::IfOrIfLet { r#else: None, .. }) = higher::IfOrIfLet::hir(tail);
+ let sm = cx.sess().source_map();
+ if head
+ .iter()
+ .all(|stmt| matches!(stmt.kind, StmtKind::Local(..)) && !sm.is_multiline(stmt.span));
+ if if_chain_span.is_some() || !is_else_clause(cx.tcx, if_expr);
+ then {
+ } else {
+ return;
+ }
+ }
+ let (span, msg) = match (if_chain_span, is_expn_of(tail.span, "if_chain")) {
+ (None, Some(_)) => (if_expr.span, "this `if` can be part of the inner `if_chain!`"),
+ (Some(_), None) => (tail.span, "this `if` can be part of the outer `if_chain!`"),
+ (Some(a), Some(b)) if a != b => (b, "this `if_chain!` can be merged with the outer `if_chain!`"),
+ _ => return,
+ };
+ span_lint_and_then(cx, IF_CHAIN_STYLE, span, msg, |diag| {
+ let (span, msg) = match head {
+ [] => return,
+ [stmt] => (stmt.span, "this `let` statement can also be in the `if_chain!`"),
+ [a, .., b] => (
+ a.span.to(b.span),
+ "these `let` statements can also be in the `if_chain!`",
+ ),
+ };
+ diag.span_help(span, msg);
+ });
+}
+
+fn is_first_if_chain_expr(cx: &LateContext<'_>, hir_id: HirId, if_chain_span: Span) -> bool {
+ cx.tcx
+ .hir()
+ .parent_iter(hir_id)
+ .find(|(_, node)| {
+ #[rustfmt::skip]
+ !matches!(node, Node::Expr(Expr { kind: ExprKind::Block(..), .. }) | Node::Stmt(_))
+ })
+ .map_or(false, |(id, _)| {
+ is_expn_of(cx.tcx.hir().span(id), "if_chain") != Some(if_chain_span)
+ })
+}
+
+/// Checks a trailing slice of statements and expression of a `Block` to see if they are part
+/// of the `then {..}` portion of an `if_chain!`
+fn is_if_chain_then(stmts: &[Stmt<'_>], expr: Option<&Expr<'_>>, if_chain_span: Span) -> bool {
+ let span = if let [stmt, ..] = stmts {
+ stmt.span
+ } else if let Some(expr) = expr {
+ expr.span
+ } else {
+ // empty `then {}`
+ return true;
+ };
+ is_expn_of(span, "if_chain").map_or(true, |span| span != if_chain_span)
+}
+
+/// Creates a `Span` for `let x = ..;` in an `if_chain!` call.
+fn if_chain_local_span(cx: &LateContext<'_>, local: &Local<'_>, if_chain_span: Span) -> Span {
+ let mut span = local.pat.span;
+ if let Some(init) = local.init {
+ span = span.to(init.span);
+ }
+ span.adjust(if_chain_span.ctxt().outer_expn());
+ let sm = cx.sess().source_map();
+ let span = sm.span_extend_to_prev_str(span, "let", false, true).unwrap_or(span);
+ let span = sm.span_extend_to_next_char(span, ';', false);
+ Span::new(
+ span.lo() - BytePos(3),
+ span.hi() + BytePos(1),
+ span.ctxt(),
+ span.parent(),
+ )
+}
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs
new file mode 100644
index 000000000..096b60157
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/interning_defined_symbol.rs
@@ -0,0 +1,239 @@
+use clippy_utils::consts::{constant_simple, Constant};
+use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::source::snippet;
+use clippy_utils::ty::match_type;
+use clippy_utils::{def_path_res, is_expn_of, match_def_path, paths};
+use if_chain::if_chain;
+use rustc_data_structures::fx::FxHashMap;
+use rustc_errors::Applicability;
+use rustc_hir::def::{DefKind, Res};
+use rustc_hir::def_id::DefId;
+use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp};
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::mir::interpret::ConstValue;
+use rustc_middle::ty::{self};
+use rustc_session::{declare_tool_lint, impl_lint_pass};
+use rustc_span::symbol::Symbol;
+
+use std::borrow::Cow;
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for interning symbols that have already been pre-interned and defined as constants.
+ ///
+ /// ### Why is this bad?
+ /// It's faster and easier to use the symbol constant.
+ ///
+ /// ### Example
+ /// ```rust,ignore
+ /// let _ = sym!(f32);
+ /// ```
+ ///
+ /// Use instead:
+ /// ```rust,ignore
+ /// let _ = sym::f32;
+ /// ```
+ pub INTERNING_DEFINED_SYMBOL,
+ internal,
+ "interning a symbol that is pre-interned and defined as a constant"
+}
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for unnecessary conversion from Symbol to a string.
+ ///
+ /// ### Why is this bad?
+ /// It's faster use symbols directly instead of strings.
+ ///
+ /// ### Example
+ /// ```rust,ignore
+ /// symbol.as_str() == "clippy";
+ /// ```
+ ///
+ /// Use instead:
+ /// ```rust,ignore
+ /// symbol == sym::clippy;
+ /// ```
+ pub UNNECESSARY_SYMBOL_STR,
+ internal,
+ "unnecessary conversion between Symbol and string"
+}
+
+#[derive(Default)]
+pub struct InterningDefinedSymbol {
+ // Maps the symbol value to the constant DefId.
+ symbol_map: FxHashMap<u32, DefId>,
+}
+
+impl_lint_pass!(InterningDefinedSymbol => [INTERNING_DEFINED_SYMBOL, UNNECESSARY_SYMBOL_STR]);
+
+impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol {
+ fn check_crate(&mut self, cx: &LateContext<'_>) {
+ if !self.symbol_map.is_empty() {
+ return;
+ }
+
+ for &module in &[&paths::KW_MODULE, &paths::SYM_MODULE] {
+ if let Some(def_id) = def_path_res(cx, module, None).opt_def_id() {
+ for item in cx.tcx.module_children(def_id).iter() {
+ if_chain! {
+ if let Res::Def(DefKind::Const, item_def_id) = item.res;
+ let ty = cx.tcx.type_of(item_def_id);
+ if match_type(cx, ty, &paths::SYMBOL);
+ if let Ok(ConstValue::Scalar(value)) = cx.tcx.const_eval_poly(item_def_id);
+ if let Ok(value) = value.to_u32();
+ then {
+ self.symbol_map.insert(value, item_def_id);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
+ if_chain! {
+ if let ExprKind::Call(func, [arg]) = &expr.kind;
+ if let ty::FnDef(def_id, _) = cx.typeck_results().expr_ty(func).kind();
+ if match_def_path(cx, *def_id, &paths::SYMBOL_INTERN);
+ if let Some(Constant::Str(arg)) = constant_simple(cx, cx.typeck_results(), arg);
+ let value = Symbol::intern(&arg).as_u32();
+ if let Some(&def_id) = self.symbol_map.get(&value);
+ then {
+ span_lint_and_sugg(
+ cx,
+ INTERNING_DEFINED_SYMBOL,
+ is_expn_of(expr.span, "sym").unwrap_or(expr.span),
+ "interning a defined symbol",
+ "try",
+ cx.tcx.def_path_str(def_id),
+ Applicability::MachineApplicable,
+ );
+ }
+ }
+ if let ExprKind::Binary(op, left, right) = expr.kind {
+ if matches!(op.node, BinOpKind::Eq | BinOpKind::Ne) {
+ let data = [
+ (left, self.symbol_str_expr(left, cx)),
+ (right, self.symbol_str_expr(right, cx)),
+ ];
+ match data {
+ // both operands are a symbol string
+ [(_, Some(left)), (_, Some(right))] => {
+ span_lint_and_sugg(
+ cx,
+ UNNECESSARY_SYMBOL_STR,
+ expr.span,
+ "unnecessary `Symbol` to string conversion",
+ "try",
+ format!(
+ "{} {} {}",
+ left.as_symbol_snippet(cx),
+ op.node.as_str(),
+ right.as_symbol_snippet(cx),
+ ),
+ Applicability::MachineApplicable,
+ );
+ },
+ // one of the operands is a symbol string
+ [(expr, Some(symbol)), _] | [_, (expr, Some(symbol))] => {
+ // creating an owned string for comparison
+ if matches!(symbol, SymbolStrExpr::Expr { is_to_owned: true, .. }) {
+ span_lint_and_sugg(
+ cx,
+ UNNECESSARY_SYMBOL_STR,
+ expr.span,
+ "unnecessary string allocation",
+ "try",
+ format!("{}.as_str()", symbol.as_symbol_snippet(cx)),
+ Applicability::MachineApplicable,
+ );
+ }
+ },
+ // nothing found
+ [(_, None), (_, None)] => {},
+ }
+ }
+ }
+ }
+}
+
+impl InterningDefinedSymbol {
+ fn symbol_str_expr<'tcx>(&self, expr: &'tcx Expr<'tcx>, cx: &LateContext<'tcx>) -> Option<SymbolStrExpr<'tcx>> {
+ static IDENT_STR_PATHS: &[&[&str]] = &[&paths::IDENT_AS_STR, &paths::TO_STRING_METHOD];
+ static SYMBOL_STR_PATHS: &[&[&str]] = &[
+ &paths::SYMBOL_AS_STR,
+ &paths::SYMBOL_TO_IDENT_STRING,
+ &paths::TO_STRING_METHOD,
+ ];
+ let call = if_chain! {
+ if let ExprKind::AddrOf(_, _, e) = expr.kind;
+ if let ExprKind::Unary(UnOp::Deref, e) = e.kind;
+ then { e } else { expr }
+ };
+ if_chain! {
+ // is a method call
+ if let ExprKind::MethodCall(_, item, [], _) = call.kind;
+ if let Some(did) = cx.typeck_results().type_dependent_def_id(call.hir_id);
+ let ty = cx.typeck_results().expr_ty(item);
+ // ...on either an Ident or a Symbol
+ if let Some(is_ident) = if match_type(cx, ty, &paths::SYMBOL) {
+ Some(false)
+ } else if match_type(cx, ty, &paths::IDENT) {
+ Some(true)
+ } else {
+ None
+ };
+ // ...which converts it to a string
+ let paths = if is_ident { IDENT_STR_PATHS } else { SYMBOL_STR_PATHS };
+ if let Some(path) = paths.iter().find(|path| match_def_path(cx, did, path));
+ then {
+ let is_to_owned = path.last().unwrap().ends_with("string");
+ return Some(SymbolStrExpr::Expr {
+ item,
+ is_ident,
+ is_to_owned,
+ });
+ }
+ }
+ // is a string constant
+ if let Some(Constant::Str(s)) = constant_simple(cx, cx.typeck_results(), expr) {
+ let value = Symbol::intern(&s).as_u32();
+ // ...which matches a symbol constant
+ if let Some(&def_id) = self.symbol_map.get(&value) {
+ return Some(SymbolStrExpr::Const(def_id));
+ }
+ }
+ None
+ }
+}
+
+enum SymbolStrExpr<'tcx> {
+ /// a string constant with a corresponding symbol constant
+ Const(DefId),
+ /// a "symbol to string" expression like `symbol.as_str()`
+ Expr {
+ /// part that evaluates to `Symbol` or `Ident`
+ item: &'tcx Expr<'tcx>,
+ is_ident: bool,
+ /// whether an owned `String` is created like `to_ident_string()`
+ is_to_owned: bool,
+ },
+}
+
+impl<'tcx> SymbolStrExpr<'tcx> {
+ /// Returns a snippet that evaluates to a `Symbol` and is const if possible
+ fn as_symbol_snippet(&self, cx: &LateContext<'_>) -> Cow<'tcx, str> {
+ match *self {
+ Self::Const(def_id) => cx.tcx.def_path_str(def_id).into(),
+ Self::Expr { item, is_ident, .. } => {
+ let mut snip = snippet(cx, item.span.source_callsite(), "..");
+ if is_ident {
+ // get `Ident.name`
+ snip.to_mut().push_str(".name");
+ }
+ snip
+ },
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/invalid_paths.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/invalid_paths.rs
new file mode 100644
index 000000000..25532dd4e
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/invalid_paths.rs
@@ -0,0 +1,108 @@
+use clippy_utils::consts::{constant_simple, Constant};
+use clippy_utils::def_path_res;
+use clippy_utils::diagnostics::span_lint;
+use if_chain::if_chain;
+use rustc_hir as hir;
+use rustc_hir::def::{DefKind, Res};
+use rustc_hir::Item;
+use rustc_hir_analysis::hir_ty_to_ty;
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::ty::{self, fast_reject::SimplifiedTypeGen, FloatTy};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::symbol::Symbol;
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks the paths module for invalid paths.
+ ///
+ /// ### Why is this bad?
+ /// It indicates a bug in the code.
+ ///
+ /// ### Example
+ /// None.
+ pub INVALID_PATHS,
+ internal,
+ "invalid path"
+}
+
+declare_lint_pass!(InvalidPaths => [INVALID_PATHS]);
+
+impl<'tcx> LateLintPass<'tcx> for InvalidPaths {
+ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
+ let local_def_id = &cx.tcx.parent_module(item.hir_id());
+ let mod_name = &cx.tcx.item_name(local_def_id.to_def_id());
+ if_chain! {
+ if mod_name.as_str() == "paths";
+ if let hir::ItemKind::Const(ty, body_id) = item.kind;
+ let ty = hir_ty_to_ty(cx.tcx, ty);
+ if let ty::Array(el_ty, _) = &ty.kind();
+ if let ty::Ref(_, el_ty, _) = &el_ty.kind();
+ if el_ty.is_str();
+ let body = cx.tcx.hir().body(body_id);
+ let typeck_results = cx.tcx.typeck_body(body_id);
+ if let Some(Constant::Vec(path)) = constant_simple(cx, typeck_results, body.value);
+ let path: Vec<&str> = path
+ .iter()
+ .map(|x| {
+ if let Constant::Str(s) = x {
+ s.as_str()
+ } else {
+ // We checked the type of the constant above
+ unreachable!()
+ }
+ })
+ .collect();
+ if !check_path(cx, &path[..]);
+ then {
+ span_lint(cx, INVALID_PATHS, item.span, "invalid path");
+ }
+ }
+ }
+}
+
+// This is not a complete resolver for paths. It works on all the paths currently used in the paths
+// module. That's all it does and all it needs to do.
+pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
+ if def_path_res(cx, path, None) != Res::Err {
+ return true;
+ }
+
+ // Some implementations can't be found by `path_to_res`, particularly inherent
+ // implementations of native types. Check lang items.
+ let path_syms: Vec<_> = path.iter().map(|p| Symbol::intern(p)).collect();
+ let lang_items = cx.tcx.lang_items();
+ // This list isn't complete, but good enough for our current list of paths.
+ let incoherent_impls = [
+ SimplifiedTypeGen::FloatSimplifiedType(FloatTy::F32),
+ SimplifiedTypeGen::FloatSimplifiedType(FloatTy::F64),
+ SimplifiedTypeGen::SliceSimplifiedType,
+ SimplifiedTypeGen::StrSimplifiedType,
+ ]
+ .iter()
+ .flat_map(|&ty| cx.tcx.incoherent_impls(ty));
+ for item_def_id in lang_items.items().iter().flatten().chain(incoherent_impls) {
+ let lang_item_path = cx.get_def_path(*item_def_id);
+ if path_syms.starts_with(&lang_item_path) {
+ if let [item] = &path_syms[lang_item_path.len()..] {
+ if matches!(
+ cx.tcx.def_kind(*item_def_id),
+ DefKind::Mod | DefKind::Enum | DefKind::Trait
+ ) {
+ for child in cx.tcx.module_children(*item_def_id) {
+ if child.ident.name == *item {
+ return true;
+ }
+ }
+ } else {
+ for child in cx.tcx.associated_item_def_ids(*item_def_id) {
+ if cx.tcx.item_name(*child) == *item {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ false
+}
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs
new file mode 100644
index 000000000..0dac64376
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs
@@ -0,0 +1,342 @@
+use crate::utils::internal_lints::metadata_collector::is_deprecated_lint;
+use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
+use clippy_utils::macros::root_macro_call_first_node;
+use clippy_utils::{is_lint_allowed, match_def_path, paths};
+use if_chain::if_chain;
+use rustc_ast as ast;
+use rustc_ast::ast::LitKind;
+use rustc_data_structures::fx::{FxHashMap, FxHashSet};
+use rustc_hir as hir;
+use rustc_hir::def::{DefKind, Res};
+use rustc_hir::hir_id::CRATE_HIR_ID;
+use rustc_hir::intravisit::Visitor;
+use rustc_hir::{ExprKind, HirId, Item, MutTy, Mutability, Path, TyKind};
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::hir::nested_filter;
+use rustc_semver::RustcVersion;
+use rustc_session::{declare_tool_lint, impl_lint_pass};
+use rustc_span::source_map::Spanned;
+use rustc_span::symbol::Symbol;
+use rustc_span::{sym, Span};
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Ensures every lint is associated to a `LintPass`.
+ ///
+ /// ### Why is this bad?
+ /// The compiler only knows lints via a `LintPass`. Without
+ /// putting a lint to a `LintPass::get_lints()`'s return, the compiler will not
+ /// know the name of the lint.
+ ///
+ /// ### Known problems
+ /// Only checks for lints associated using the
+ /// `declare_lint_pass!`, `impl_lint_pass!`, and `lint_array!` macros.
+ ///
+ /// ### Example
+ /// ```rust,ignore
+ /// declare_lint! { pub LINT_1, ... }
+ /// declare_lint! { pub LINT_2, ... }
+ /// declare_lint! { pub FORGOTTEN_LINT, ... }
+ /// // ...
+ /// declare_lint_pass!(Pass => [LINT_1, LINT_2]);
+ /// // missing FORGOTTEN_LINT
+ /// ```
+ pub LINT_WITHOUT_LINT_PASS,
+ internal,
+ "declaring a lint without associating it in a LintPass"
+}
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for cases of an auto-generated lint without an updated description,
+ /// i.e. `default lint description`.
+ ///
+ /// ### Why is this bad?
+ /// Indicates that the lint is not finished.
+ ///
+ /// ### Example
+ /// ```rust,ignore
+ /// declare_lint! { pub COOL_LINT, nursery, "default lint description" }
+ /// ```
+ ///
+ /// Use instead:
+ /// ```rust,ignore
+ /// declare_lint! { pub COOL_LINT, nursery, "a great new lint" }
+ /// ```
+ pub DEFAULT_LINT,
+ internal,
+ "found 'default lint description' in a lint declaration"
+}
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for invalid `clippy::version` attributes.
+ ///
+ /// Valid values are:
+ /// * "pre 1.29.0"
+ /// * any valid semantic version
+ pub INVALID_CLIPPY_VERSION_ATTRIBUTE,
+ internal,
+ "found an invalid `clippy::version` attribute"
+}
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for declared clippy lints without the `clippy::version` attribute.
+ ///
+ pub MISSING_CLIPPY_VERSION_ATTRIBUTE,
+ internal,
+ "found clippy lint without `clippy::version` attribute"
+}
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for cases of an auto-generated deprecated lint without an updated reason,
+ /// i.e. `"default deprecation note"`.
+ ///
+ /// ### Why is this bad?
+ /// Indicates that the documentation is incomplete.
+ ///
+ /// ### Example
+ /// ```rust,ignore
+ /// declare_deprecated_lint! {
+ /// /// ### What it does
+ /// /// Nothing. This lint has been deprecated.
+ /// ///
+ /// /// ### Deprecation reason
+ /// /// TODO
+ /// #[clippy::version = "1.63.0"]
+ /// pub COOL_LINT,
+ /// "default deprecation note"
+ /// }
+ /// ```
+ ///
+ /// Use instead:
+ /// ```rust,ignore
+ /// declare_deprecated_lint! {
+ /// /// ### What it does
+ /// /// Nothing. This lint has been deprecated.
+ /// ///
+ /// /// ### Deprecation reason
+ /// /// This lint has been replaced by `cooler_lint`
+ /// #[clippy::version = "1.63.0"]
+ /// pub COOL_LINT,
+ /// "this lint has been replaced by `cooler_lint`"
+ /// }
+ /// ```
+ pub DEFAULT_DEPRECATION_REASON,
+ internal,
+ "found 'default deprecation note' in a deprecated lint declaration"
+}
+
+#[derive(Clone, Debug, Default)]
+pub struct LintWithoutLintPass {
+ declared_lints: FxHashMap<Symbol, Span>,
+ registered_lints: FxHashSet<Symbol>,
+}
+
+impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS, INVALID_CLIPPY_VERSION_ATTRIBUTE, MISSING_CLIPPY_VERSION_ATTRIBUTE, DEFAULT_DEPRECATION_REASON]);
+
+impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
+ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
+ if is_lint_allowed(cx, DEFAULT_LINT, item.hir_id())
+ || is_lint_allowed(cx, DEFAULT_DEPRECATION_REASON, item.hir_id())
+ {
+ return;
+ }
+
+ if let hir::ItemKind::Static(ty, Mutability::Not, body_id) = item.kind {
+ let is_lint_ref_ty = is_lint_ref_type(cx, ty);
+ if is_deprecated_lint(cx, ty) || is_lint_ref_ty {
+ check_invalid_clippy_version_attribute(cx, item);
+
+ let expr = &cx.tcx.hir().body(body_id).value;
+ let fields;
+ if is_lint_ref_ty {
+ if let ExprKind::AddrOf(_, _, inner_exp) = expr.kind
+ && let ExprKind::Struct(_, struct_fields, _) = inner_exp.kind {
+ fields = struct_fields;
+ } else {
+ return;
+ }
+ } else if let ExprKind::Struct(_, struct_fields, _) = expr.kind {
+ fields = struct_fields;
+ } else {
+ return;
+ }
+
+ let field = fields
+ .iter()
+ .find(|f| f.ident.as_str() == "desc")
+ .expect("lints must have a description field");
+
+ if let ExprKind::Lit(Spanned {
+ node: LitKind::Str(ref sym, _),
+ ..
+ }) = field.expr.kind
+ {
+ let sym_str = sym.as_str();
+ if is_lint_ref_ty {
+ if sym_str == "default lint description" {
+ span_lint(
+ cx,
+ DEFAULT_LINT,
+ item.span,
+ &format!("the lint `{}` has the default lint description", item.ident.name),
+ );
+ }
+
+ self.declared_lints.insert(item.ident.name, item.span);
+ } else if sym_str == "default deprecation note" {
+ span_lint(
+ cx,
+ DEFAULT_DEPRECATION_REASON,
+ item.span,
+ &format!("the lint `{}` has the default deprecation reason", item.ident.name),
+ );
+ }
+ }
+ }
+ } else if let Some(macro_call) = root_macro_call_first_node(cx, item) {
+ if !matches!(
+ cx.tcx.item_name(macro_call.def_id).as_str(),
+ "impl_lint_pass" | "declare_lint_pass"
+ ) {
+ return;
+ }
+ if let hir::ItemKind::Impl(hir::Impl {
+ of_trait: None,
+ items: impl_item_refs,
+ ..
+ }) = item.kind
+ {
+ let mut collector = LintCollector {
+ output: &mut self.registered_lints,
+ cx,
+ };
+ let body_id = cx.tcx.hir().body_owned_by(
+ cx.tcx.hir().local_def_id(
+ impl_item_refs
+ .iter()
+ .find(|iiref| iiref.ident.as_str() == "get_lints")
+ .expect("LintPass needs to implement get_lints")
+ .id
+ .hir_id(),
+ ),
+ );
+ collector.visit_expr(cx.tcx.hir().body(body_id).value);
+ }
+ }
+ }
+
+ fn check_crate_post(&mut self, cx: &LateContext<'tcx>) {
+ if is_lint_allowed(cx, LINT_WITHOUT_LINT_PASS, CRATE_HIR_ID) {
+ return;
+ }
+
+ for (lint_name, &lint_span) in &self.declared_lints {
+ // When using the `declare_tool_lint!` macro, the original `lint_span`'s
+ // file points to "<rustc macros>".
+ // `compiletest-rs` thinks that's an error in a different file and
+ // just ignores it. This causes the test in compile-fail/lint_pass
+ // not able to capture the error.
+ // Therefore, we need to climb the macro expansion tree and find the
+ // actual span that invoked `declare_tool_lint!`:
+ let lint_span = lint_span.ctxt().outer_expn_data().call_site;
+
+ if !self.registered_lints.contains(lint_name) {
+ span_lint(
+ cx,
+ LINT_WITHOUT_LINT_PASS,
+ lint_span,
+ &format!("the lint `{lint_name}` is not added to any `LintPass`"),
+ );
+ }
+ }
+ }
+}
+
+pub(super) fn is_lint_ref_type<'tcx>(cx: &LateContext<'tcx>, ty: &hir::Ty<'_>) -> bool {
+ if let TyKind::Rptr(
+ _,
+ MutTy {
+ ty: inner,
+ mutbl: Mutability::Not,
+ },
+ ) = ty.kind
+ {
+ if let TyKind::Path(ref path) = inner.kind {
+ if let Res::Def(DefKind::Struct, def_id) = cx.qpath_res(path, inner.hir_id) {
+ return match_def_path(cx, def_id, &paths::LINT);
+ }
+ }
+ }
+
+ false
+}
+
+fn check_invalid_clippy_version_attribute(cx: &LateContext<'_>, item: &'_ Item<'_>) {
+ if let Some(value) = extract_clippy_version_value(cx, item) {
+ // The `sym!` macro doesn't work as it only expects a single token.
+ // It's better to keep it this way and have a direct `Symbol::intern` call here.
+ if value == Symbol::intern("pre 1.29.0") {
+ return;
+ }
+
+ if RustcVersion::parse(value.as_str()).is_err() {
+ span_lint_and_help(
+ cx,
+ INVALID_CLIPPY_VERSION_ATTRIBUTE,
+ item.span,
+ "this item has an invalid `clippy::version` attribute",
+ None,
+ "please use a valid semantic version, see `doc/adding_lints.md`",
+ );
+ }
+ } else {
+ span_lint_and_help(
+ cx,
+ MISSING_CLIPPY_VERSION_ATTRIBUTE,
+ item.span,
+ "this lint is missing the `clippy::version` attribute or version value",
+ None,
+ "please use a `clippy::version` attribute, see `doc/adding_lints.md`",
+ );
+ }
+}
+
+/// This function extracts the version value of a `clippy::version` attribute if the given value has
+/// one
+pub(super) fn extract_clippy_version_value(cx: &LateContext<'_>, item: &'_ Item<'_>) -> Option<Symbol> {
+ let attrs = cx.tcx.hir().attrs(item.hir_id());
+ attrs.iter().find_map(|attr| {
+ if_chain! {
+ // Identify attribute
+ if let ast::AttrKind::Normal(ref attr_kind) = &attr.kind;
+ if let [tool_name, attr_name] = &attr_kind.item.path.segments[..];
+ if tool_name.ident.name == sym::clippy;
+ if attr_name.ident.name == sym::version;
+ if let Some(version) = attr.value_str();
+ then { Some(version) } else { None }
+ }
+ })
+}
+
+struct LintCollector<'a, 'tcx> {
+ output: &'a mut FxHashSet<Symbol>,
+ cx: &'a LateContext<'tcx>,
+}
+
+impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> {
+ type NestedFilter = nested_filter::All;
+
+ fn visit_path(&mut self, path: &'tcx Path<'_>, _: HirId) {
+ if path.segments.len() == 1 {
+ self.output.insert(path.segments[0].ident.name);
+ }
+ }
+
+ fn nested_visit_map(&mut self) -> Self::Map {
+ self.cx.tcx.hir()
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs
index 342f627e3..d06a616e4 100644
--- a/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/metadata_collector.rs
@@ -8,7 +8,7 @@
//! a simple mistake)
use crate::renamed_lints::RENAMED_LINTS;
-use crate::utils::internal_lints::{extract_clippy_version_value, is_lint_ref_type};
+use crate::utils::internal_lints::lint_without_lint_pass::{extract_clippy_version_value, is_lint_ref_type};
use clippy_utils::diagnostics::span_lint;
use clippy_utils::ty::{match_type, walk_ptrs_ty_depth};
@@ -64,46 +64,6 @@ const DEFAULT_LINT_LEVELS: &[(&str, &str)] = &[
/// This prefix is in front of the lint groups in the lint store. The prefix will be trimmed
/// to only keep the actual lint group in the output.
const CLIPPY_LINT_GROUP_PREFIX: &str = "clippy::";
-
-/// This template will be used to format the configuration section in the lint documentation.
-/// The `configurations` parameter will be replaced with one or multiple formatted
-/// `ClippyConfiguration` instances. See `CONFIGURATION_VALUE_TEMPLATE` for further customizations
-macro_rules! CONFIGURATION_SECTION_TEMPLATE {
- () => {
- r#"
-### Configuration
-This lint has the following configuration variables:
-
-{configurations}
-"#
- };
-}
-/// This template will be used to format an individual `ClippyConfiguration` instance in the
-/// lint documentation.
-///
-/// The format function will provide strings for the following parameters: `name`, `ty`, `doc` and
-/// `default`
-macro_rules! CONFIGURATION_VALUE_TEMPLATE {
- () => {
- "* `{name}`: `{ty}`: {doc} (defaults to `{default}`)\n"
- };
-}
-
-macro_rules! RENAMES_SECTION_TEMPLATE {
- () => {
- r#"
-### Past names
-
-{names}
-"#
- };
-}
-macro_rules! RENAME_VALUE_TEMPLATE {
- () => {
- "* `{name}`\n"
- };
-}
-
const LINT_EMISSION_FUNCTIONS: [&[&str]; 7] = [
&["clippy_utils", "diagnostics", "span_lint"],
&["clippy_utils", "diagnostics", "span_lint_and_help"],
@@ -205,7 +165,16 @@ impl MetadataCollector {
.filter(|config| config.lints.iter().any(|lint| lint == lint_name))
.map(ToString::to_string)
.reduce(|acc, x| acc + &x)
- .map(|configurations| format!(CONFIGURATION_SECTION_TEMPLATE!(), configurations = configurations))
+ .map(|configurations| {
+ format!(
+ r#"
+### Configuration
+This lint has the following configuration variables:
+
+{configurations}
+"#
+ )
+ })
}
}
@@ -291,16 +260,13 @@ fn replace_produces(lint_name: &str, docs: &mut String, clippy_project_root: &Pa
continue;
}
- panic!("lint `{}` has an unterminated code block", lint_name)
+ panic!("lint `{lint_name}` has an unterminated code block")
}
break;
},
Some(line) if line.trim_start() == "{{produces}}" => {
- panic!(
- "lint `{}` has marker {{{{produces}}}} with an ignored or missing code block",
- lint_name
- )
+ panic!("lint `{lint_name}` has marker {{{{produces}}}} with an ignored or missing code block")
},
Some(line) => {
let line = line.trim();
@@ -319,7 +285,7 @@ fn replace_produces(lint_name: &str, docs: &mut String, clippy_project_root: &Pa
match lines.next() {
Some(line) if line.trim_start() == "```" => break,
Some(line) => example.push(line),
- None => panic!("lint `{}` has an unterminated code block", lint_name),
+ None => panic!("lint `{lint_name}` has an unterminated code block"),
}
}
@@ -336,10 +302,9 @@ fn replace_produces(lint_name: &str, docs: &mut String, clippy_project_root: &Pa
<summary>Produces</summary>\n\
\n\
```text\n\
- {}\n\
+ {output}\n\
```\n\
- </details>",
- output
+ </details>"
),
);
@@ -394,7 +359,7 @@ fn get_lint_output(lint_name: &str, example: &[&mut String], clippy_project_root
panic!("failed to write to `{}`: {e}", file.as_path().to_string_lossy());
}
- let prefixed_name = format!("{}{lint_name}", CLIPPY_LINT_GROUP_PREFIX);
+ let prefixed_name = format!("{CLIPPY_LINT_GROUP_PREFIX}{lint_name}");
let mut cmd = Command::new("cargo");
@@ -417,7 +382,7 @@ fn get_lint_output(lint_name: &str, example: &[&mut String], clippy_project_root
let output = cmd
.arg(file.as_path())
.output()
- .unwrap_or_else(|e| panic!("failed to run `{:?}`: {e}", cmd));
+ .unwrap_or_else(|e| panic!("failed to run `{cmd:?}`: {e}"));
let tmp_file_path = file.to_string_lossy();
let stderr = std::str::from_utf8(&output.stderr).unwrap();
@@ -441,8 +406,7 @@ fn get_lint_output(lint_name: &str, example: &[&mut String], clippy_project_root
let rendered: Vec<&str> = msgs.iter().filter_map(|msg| msg["rendered"].as_str()).collect();
let non_json: Vec<&str> = stderr.lines().filter(|line| !line.starts_with('{')).collect();
panic!(
- "did not find lint `{}` in output of example, got:\n{}\n{}",
- lint_name,
+ "did not find lint `{lint_name}` in output of example, got:\n{}\n{}",
non_json.join("\n"),
rendered.join("\n")
);
@@ -568,7 +532,11 @@ fn parse_config_field_doc(doc_comment: &str) -> Option<(Vec<String>, String)> {
// Extract lints
doc_comment.make_ascii_lowercase();
- let lints: Vec<String> = doc_comment.split_off(DOC_START.len()).split(", ").map(str::to_string).collect();
+ let lints: Vec<String> = doc_comment
+ .split_off(DOC_START.len())
+ .split(", ")
+ .map(str::to_string)
+ .collect();
// Format documentation correctly
// split off leading `.` from lint name list and indent for correct formatting
@@ -588,13 +556,10 @@ fn to_kebab(config_name: &str) -> String {
impl fmt::Display for ClippyConfiguration {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> fmt::Result {
- write!(
+ writeln!(
f,
- CONFIGURATION_VALUE_TEMPLATE!(),
- name = self.name,
- ty = self.config_type,
- doc = self.doc,
- default = self.default
+ "* `{}`: `{}`: {} (defaults to `{}`)",
+ self.name, self.config_type, self.doc, self.default
)
}
}
@@ -811,7 +776,7 @@ fn get_lint_group_and_level_or_lint(
lint_collection_error_item(
cx,
item,
- &format!("Unable to determine lint level for found group `{}`", group),
+ &format!("Unable to determine lint level for found group `{group}`"),
);
None
}
@@ -869,7 +834,7 @@ fn collect_renames(lints: &mut Vec<LintMetadata>) {
if name == lint_name;
if let Some(past_name) = k.strip_prefix(CLIPPY_LINT_GROUP_PREFIX);
then {
- write!(collected, RENAME_VALUE_TEMPLATE!(), name = past_name).unwrap();
+ writeln!(collected, "* `{past_name}`").unwrap();
names.push(past_name.to_string());
}
}
@@ -882,7 +847,15 @@ fn collect_renames(lints: &mut Vec<LintMetadata>) {
}
if !collected.is_empty() {
- write!(&mut lint.docs, RENAMES_SECTION_TEMPLATE!(), names = collected).unwrap();
+ write!(
+ &mut lint.docs,
+ r#"
+### Past names
+
+{collected}
+"#
+ )
+ .unwrap();
}
}
}
@@ -895,7 +868,7 @@ fn lint_collection_error_item(cx: &LateContext<'_>, item: &Item<'_>, message: &s
cx,
INTERNAL_METADATA_COLLECTOR,
item.ident.span,
- &format!("metadata collection error for `{}`: {}", item.ident.name, message),
+ &format!("metadata collection error for `{}`: {message}", item.ident.name),
);
}
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs
new file mode 100644
index 000000000..1e994e3f2
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/msrv_attr_impl.rs
@@ -0,0 +1,63 @@
+use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::source::snippet;
+use clippy_utils::ty::match_type;
+use clippy_utils::{match_def_path, paths};
+use if_chain::if_chain;
+use rustc_errors::Applicability;
+use rustc_hir as hir;
+use rustc_hir_analysis::hir_ty_to_ty;
+use rustc_lint::{LateContext, LateLintPass, LintContext};
+use rustc_middle::ty::{self, subst::GenericArgKind};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Check that the `extract_msrv_attr!` macro is used, when a lint has a MSRV.
+ ///
+ pub MISSING_MSRV_ATTR_IMPL,
+ internal,
+ "checking if all necessary steps were taken when adding a MSRV to a lint"
+}
+
+declare_lint_pass!(MsrvAttrImpl => [MISSING_MSRV_ATTR_IMPL]);
+
+impl LateLintPass<'_> for MsrvAttrImpl {
+ fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
+ if_chain! {
+ if let hir::ItemKind::Impl(hir::Impl {
+ of_trait: Some(lint_pass_trait_ref),
+ self_ty,
+ items,
+ ..
+ }) = &item.kind;
+ if let Some(lint_pass_trait_def_id) = lint_pass_trait_ref.trait_def_id();
+ let is_late_pass = match_def_path(cx, lint_pass_trait_def_id, &paths::LATE_LINT_PASS);
+ if is_late_pass || match_def_path(cx, lint_pass_trait_def_id, &paths::EARLY_LINT_PASS);
+ let self_ty = hir_ty_to_ty(cx.tcx, self_ty);
+ if let ty::Adt(self_ty_def, _) = self_ty.kind();
+ if self_ty_def.is_struct();
+ if self_ty_def.all_fields().any(|f| {
+ cx.tcx
+ .type_of(f.did)
+ .walk()
+ .filter(|t| matches!(t.unpack(), GenericArgKind::Type(_)))
+ .any(|t| match_type(cx, t.expect_ty(), &paths::RUSTC_VERSION))
+ });
+ if !items.iter().any(|item| item.ident.name == sym!(enter_lint_attrs));
+ then {
+ let context = if is_late_pass { "LateContext" } else { "EarlyContext" };
+ let lint_pass = if is_late_pass { "LateLintPass" } else { "EarlyLintPass" };
+ let span = cx.sess().source_map().span_through_char(item.span, '{');
+ span_lint_and_sugg(
+ cx,
+ MISSING_MSRV_ATTR_IMPL,
+ span,
+ &format!("`extract_msrv_attr!` macro missing from `{lint_pass}` implementation"),
+ &format!("add `extract_msrv_attr!({context})` to the `{lint_pass}` implementation"),
+ format!("{}\n extract_msrv_attr!({context});", snippet(cx, span, "..")),
+ Applicability::MachineApplicable,
+ );
+ }
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/outer_expn_data_pass.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/outer_expn_data_pass.rs
new file mode 100644
index 000000000..2b13fad80
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/outer_expn_data_pass.rs
@@ -0,0 +1,62 @@
+use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::ty::match_type;
+use clippy_utils::{is_lint_allowed, method_calls, paths};
+use if_chain::if_chain;
+use rustc_errors::Applicability;
+use rustc_hir as hir;
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::symbol::Symbol;
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for calls to `cx.outer().expn_data()` and suggests to use
+ /// the `cx.outer_expn_data()`
+ ///
+ /// ### Why is this bad?
+ /// `cx.outer_expn_data()` is faster and more concise.
+ ///
+ /// ### Example
+ /// ```rust,ignore
+ /// expr.span.ctxt().outer().expn_data()
+ /// ```
+ ///
+ /// Use instead:
+ /// ```rust,ignore
+ /// expr.span.ctxt().outer_expn_data()
+ /// ```
+ pub OUTER_EXPN_EXPN_DATA,
+ internal,
+ "using `cx.outer_expn().expn_data()` instead of `cx.outer_expn_data()`"
+}
+
+declare_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]);
+
+impl<'tcx> LateLintPass<'tcx> for OuterExpnDataPass {
+ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
+ if is_lint_allowed(cx, OUTER_EXPN_EXPN_DATA, expr.hir_id) {
+ return;
+ }
+
+ let (method_names, arg_lists, spans) = method_calls(expr, 2);
+ let method_names: Vec<&str> = method_names.iter().map(Symbol::as_str).collect();
+ if_chain! {
+ if let ["expn_data", "outer_expn"] = method_names.as_slice();
+ let (self_arg, args) = arg_lists[1];
+ if args.is_empty();
+ let self_ty = cx.typeck_results().expr_ty(self_arg).peel_refs();
+ if match_type(cx, self_ty, &paths::SYNTAX_CONTEXT);
+ then {
+ span_lint_and_sugg(
+ cx,
+ OUTER_EXPN_EXPN_DATA,
+ spans[1].with_hi(expr.span.hi()),
+ "usage of `outer_expn().expn_data()`",
+ "try",
+ "outer_expn_data()".to_string(),
+ Applicability::MachineApplicable,
+ );
+ }
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/produce_ice.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/produce_ice.rs
new file mode 100644
index 000000000..5899b94e1
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/produce_ice.rs
@@ -0,0 +1,37 @@
+use rustc_ast::ast::NodeId;
+use rustc_ast::visit::FnKind;
+use rustc_lint::{EarlyContext, EarlyLintPass};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::Span;
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Not an actual lint. This lint is only meant for testing our customized internal compiler
+ /// error message by calling `panic`.
+ ///
+ /// ### Why is this bad?
+ /// ICE in large quantities can damage your teeth
+ ///
+ /// ### Example
+ /// ```rust,ignore
+ /// ðŸ¦ðŸ¦ðŸ¦ðŸ¦ðŸ¦
+ /// ```
+ pub PRODUCE_ICE,
+ internal,
+ "this message should not appear anywhere as we ICE before and don't emit the lint"
+}
+
+declare_lint_pass!(ProduceIce => [PRODUCE_ICE]);
+
+impl EarlyLintPass for ProduceIce {
+ fn check_fn(&mut self, _: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: NodeId) {
+ assert!(!is_trigger_fn(fn_kind), "Would you like some help with that?");
+ }
+}
+
+fn is_trigger_fn(fn_kind: FnKind<'_>) -> bool {
+ match fn_kind {
+ FnKind::Fn(_, ident, ..) => ident.name.as_str() == "it_looks_like_you_are_trying_to_kill_clippy",
+ FnKind::Closure(..) => false,
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs b/src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs
new file mode 100644
index 000000000..4cf76f536
--- /dev/null
+++ b/src/tools/clippy/clippy_lints/src/utils/internal_lints/unnecessary_def_path.rs
@@ -0,0 +1,343 @@
+use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
+use clippy_utils::source::snippet_with_applicability;
+use clippy_utils::{def_path_res, is_lint_allowed, match_any_def_paths, peel_hir_expr_refs};
+use if_chain::if_chain;
+use rustc_ast::ast::LitKind;
+use rustc_data_structures::fx::FxHashSet;
+use rustc_errors::Applicability;
+use rustc_hir as hir;
+use rustc_hir::def::{DefKind, Namespace, Res};
+use rustc_hir::def_id::DefId;
+use rustc_hir::{Expr, ExprKind, Local, Mutability, Node};
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::mir::interpret::{Allocation, ConstValue, GlobalAlloc};
+use rustc_middle::ty::{self, AssocKind, DefIdTree, Ty};
+use rustc_session::{declare_tool_lint, impl_lint_pass};
+use rustc_span::symbol::{Ident, Symbol};
+use rustc_span::Span;
+
+use std::str;
+
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for usages of def paths when a diagnostic item or a `LangItem` could be used.
+ ///
+ /// ### Why is this bad?
+ /// The path for an item is subject to change and is less efficient to look up than a
+ /// diagnostic item or a `LangItem`.
+ ///
+ /// ### Example
+ /// ```rust,ignore
+ /// utils::match_type(cx, ty, &paths::VEC)
+ /// ```
+ ///
+ /// Use instead:
+ /// ```rust,ignore
+ /// utils::is_type_diagnostic_item(cx, ty, sym::Vec)
+ /// ```
+ pub UNNECESSARY_DEF_PATH,
+ internal,
+ "using a def path when a diagnostic item or a `LangItem` is available"
+}
+
+impl_lint_pass!(UnnecessaryDefPath => [UNNECESSARY_DEF_PATH]);
+
+#[derive(Default)]
+pub struct UnnecessaryDefPath {
+ array_def_ids: FxHashSet<(DefId, Span)>,
+ linted_def_ids: FxHashSet<DefId>,
+}
+
+impl<'tcx> LateLintPass<'tcx> for UnnecessaryDefPath {
+ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
+ if is_lint_allowed(cx, UNNECESSARY_DEF_PATH, expr.hir_id) {
+ return;
+ }
+
+ match expr.kind {
+ ExprKind::Call(func, args) => self.check_call(cx, func, args, expr.span),
+ ExprKind::Array(elements) => self.check_array(cx, elements, expr.span),
+ _ => {},
+ }
+ }
+
+ fn check_crate_post(&mut self, cx: &LateContext<'tcx>) {
+ for &(def_id, span) in &self.array_def_ids {
+ if self.linted_def_ids.contains(&def_id) {
+ continue;
+ }
+
+ let (msg, sugg) = if let Some(sym) = cx.tcx.get_diagnostic_name(def_id) {
+ ("diagnostic item", format!("sym::{sym}"))
+ } else if let Some(sym) = get_lang_item_name(cx, def_id) {
+ ("language item", format!("LangItem::{sym}"))
+ } else {
+ continue;
+ };
+
+ span_lint_and_help(
+ cx,
+ UNNECESSARY_DEF_PATH,
+ span,
+ &format!("hardcoded path to a {msg}"),
+ None,
+ &format!("convert all references to use `{sugg}`"),
+ );
+ }
+ }
+}
+
+impl UnnecessaryDefPath {
+ #[allow(clippy::too_many_lines)]
+ fn check_call(&mut self, cx: &LateContext<'_>, func: &Expr<'_>, args: &[Expr<'_>], span: Span) {
+ enum Item {
+ LangItem(Symbol),
+ DiagnosticItem(Symbol),
+ }
+ static PATHS: &[&[&str]] = &[
+ &["clippy_utils", "match_def_path"],
+ &["clippy_utils", "match_trait_method"],
+ &["clippy_utils", "ty", "match_type"],
+ &["clippy_utils", "is_expr_path_def_path"],
+ ];
+
+ if_chain! {
+ if let [cx_arg, def_arg, args @ ..] = args;
+ if let ExprKind::Path(path) = &func.kind;
+ if let Some(id) = cx.qpath_res(path, func.hir_id).opt_def_id();
+ if let Some(which_path) = match_any_def_paths(cx, id, PATHS);
+ let item_arg = if which_path == 4 { &args[1] } else { &args[0] };
+ // Extract the path to the matched type
+ if let Some(segments) = path_to_matched_type(cx, item_arg);
+ let segments: Vec<&str> = segments.iter().map(|sym| &**sym).collect();
+ if let Some(def_id) = inherent_def_path_res(cx, &segments[..]);
+ then {
+ // Check if the target item is a diagnostic item or LangItem.
+ #[rustfmt::skip]
+ let (msg, item) = if let Some(item_name)
+ = cx.tcx.diagnostic_items(def_id.krate).id_to_name.get(&def_id)
+ {
+ (
+ "use of a def path to a diagnostic item",
+ Item::DiagnosticItem(*item_name),
+ )
+ } else if let Some(item_name) = get_lang_item_name(cx, def_id) {
+ (
+ "use of a def path to a `LangItem`",
+ Item::LangItem(item_name),
+ )
+ } else {
+ return;
+ };
+
+ let has_ctor = match cx.tcx.def_kind(def_id) {
+ DefKind::Struct => {
+ let variant = cx.tcx.adt_def(def_id).non_enum_variant();
+ variant.ctor_def_id.is_some() && variant.fields.iter().all(|f| f.vis.is_public())
+ },
+ DefKind::Variant => {
+ let variant = cx.tcx.adt_def(cx.tcx.parent(def_id)).variant_with_id(def_id);
+ variant.ctor_def_id.is_some() && variant.fields.iter().all(|f| f.vis.is_public())
+ },
+ _ => false,
+ };
+
+ let mut app = Applicability::MachineApplicable;
+ let cx_snip = snippet_with_applicability(cx, cx_arg.span, "..", &mut app);
+ let def_snip = snippet_with_applicability(cx, def_arg.span, "..", &mut app);
+ let (sugg, with_note) = match (which_path, item) {
+ // match_def_path
+ (0, Item::DiagnosticItem(item)) => (
+ format!("{cx_snip}.tcx.is_diagnostic_item(sym::{item}, {def_snip})"),
+ has_ctor,
+ ),
+ (0, Item::LangItem(item)) => (
+ format!("{cx_snip}.tcx.lang_items().require(LangItem::{item}).ok() == Some({def_snip})"),
+ has_ctor,
+ ),
+ // match_trait_method
+ (1, Item::DiagnosticItem(item)) => {
+ (format!("is_trait_method({cx_snip}, {def_snip}, sym::{item})"), false)
+ },
+ // match_type
+ (2, Item::DiagnosticItem(item)) => (
+ format!("is_type_diagnostic_item({cx_snip}, {def_snip}, sym::{item})"),
+ false,
+ ),
+ (2, Item::LangItem(item)) => (
+ format!("is_type_lang_item({cx_snip}, {def_snip}, LangItem::{item})"),
+ false,
+ ),
+ // is_expr_path_def_path
+ (3, Item::DiagnosticItem(item)) if has_ctor => (
+ format!("is_res_diag_ctor({cx_snip}, path_res({cx_snip}, {def_snip}), sym::{item})",),
+ false,
+ ),
+ (3, Item::LangItem(item)) if has_ctor => (
+ format!("is_res_lang_ctor({cx_snip}, path_res({cx_snip}, {def_snip}), LangItem::{item})",),
+ false,
+ ),
+ (3, Item::DiagnosticItem(item)) => (
+ format!("is_path_diagnostic_item({cx_snip}, {def_snip}, sym::{item})"),
+ false,
+ ),
+ (3, Item::LangItem(item)) => (
+ format!(
+ "path_res({cx_snip}, {def_snip}).opt_def_id()\
+ .map_or(false, |id| {cx_snip}.tcx.lang_items().require(LangItem::{item}).ok() == Some(id))",
+ ),
+ false,
+ ),
+ _ => return,
+ };
+
+ span_lint_and_then(cx, UNNECESSARY_DEF_PATH, span, msg, |diag| {
+ diag.span_suggestion(span, "try", sugg, app);
+ if with_note {
+ diag.help(
+ "if this `DefId` came from a constructor expression or pattern then the \
+ parent `DefId` should be used instead",
+ );
+ }
+ });
+
+ self.linted_def_ids.insert(def_id);
+ }
+ }
+ }
+
+ fn check_array(&mut self, cx: &LateContext<'_>, elements: &[Expr<'_>], span: Span) {
+ let Some(path) = path_from_array(elements) else { return };
+
+ if let Some(def_id) = inherent_def_path_res(cx, &path.iter().map(AsRef::as_ref).collect::<Vec<_>>()) {
+ self.array_def_ids.insert((def_id, span));
+ }
+ }
+}
+
+fn path_to_matched_type(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<Vec<String>> {
+ match peel_hir_expr_refs(expr).0.kind {
+ ExprKind::Path(ref qpath) => match cx.qpath_res(qpath, expr.hir_id) {
+ Res::Local(hir_id) => {
+ let parent_id = cx.tcx.hir().get_parent_node(hir_id);
+ if let Some(Node::Local(Local { init: Some(init), .. })) = cx.tcx.hir().find(parent_id) {
+ path_to_matched_type(cx, init)
+ } else {
+ None
+ }
+ },
+ Res::Def(DefKind::Static(_), def_id) => read_mir_alloc_def_path(
+ cx,
+ cx.tcx.eval_static_initializer(def_id).ok()?.inner(),
+ cx.tcx.type_of(def_id),
+ ),
+ Res::Def(DefKind::Const, def_id) => match cx.tcx.const_eval_poly(def_id).ok()? {
+ ConstValue::ByRef { alloc, offset } if offset.bytes() == 0 => {
+ read_mir_alloc_def_path(cx, alloc.inner(), cx.tcx.type_of(def_id))
+ },
+ _ => None,
+ },
+ _ => None,
+ },
+ ExprKind::Array(exprs) => path_from_array(exprs),
+ _ => None,
+ }
+}
+
+fn read_mir_alloc_def_path<'tcx>(cx: &LateContext<'tcx>, alloc: &'tcx Allocation, ty: Ty<'_>) -> Option<Vec<String>> {
+ let (alloc, ty) = if let ty::Ref(_, ty, Mutability::Not) = *ty.kind() {
+ let &alloc = alloc.provenance().values().next()?;
+ if let GlobalAlloc::Memory(alloc) = cx.tcx.global_alloc(alloc) {
+ (alloc.inner(), ty)
+ } else {
+ return None;
+ }
+ } else {
+ (alloc, ty)
+ };
+
+ if let ty::Array(ty, _) | ty::Slice(ty) = *ty.kind()
+ && let ty::Ref(_, ty, Mutability::Not) = *ty.kind()
+ && ty.is_str()
+ {
+ alloc
+ .provenance()
+ .values()
+ .map(|&alloc| {
+ if let GlobalAlloc::Memory(alloc) = cx.tcx.global_alloc(alloc) {
+ let alloc = alloc.inner();
+ str::from_utf8(alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()))
+ .ok().map(ToOwned::to_owned)
+ } else {
+ None
+ }
+ })
+ .collect()
+ } else {
+ None
+ }
+}
+
+fn path_from_array(exprs: &[Expr<'_>]) -> Option<Vec<String>> {
+ exprs
+ .iter()
+ .map(|expr| {
+ if let ExprKind::Lit(lit) = &expr.kind {
+ if let LitKind::Str(sym, _) = lit.node {
+ return Some((*sym.as_str()).to_owned());
+ }
+ }
+
+ None
+ })
+ .collect()
+}
+
+// def_path_res will match field names before anything else, but for this we want to match
+// inherent functions first.
+fn inherent_def_path_res(cx: &LateContext<'_>, segments: &[&str]) -> Option<DefId> {
+ def_path_res(cx, segments, None).opt_def_id().map(|def_id| {
+ if cx.tcx.def_kind(def_id) == DefKind::Field {
+ let method_name = *segments.last().unwrap();
+ cx.tcx
+ .def_key(def_id)
+ .parent
+ .and_then(|parent_idx| {
+ cx.tcx
+ .inherent_impls(DefId {
+ index: parent_idx,
+ krate: def_id.krate,
+ })
+ .iter()
+ .find_map(|impl_id| {
+ cx.tcx.associated_items(*impl_id).find_by_name_and_kind(
+ cx.tcx,
+ Ident::from_str(method_name),
+ AssocKind::Fn,
+ *impl_id,
+ )
+ })
+ })
+ .map_or(def_id, |item| item.def_id)
+ } else {
+ def_id
+ }
+ })
+}
+
+fn get_lang_item_name(cx: &LateContext<'_>, def_id: DefId) -> Option<Symbol> {
+ if let Some(lang_item) = cx.tcx.lang_items().items().iter().position(|id| *id == Some(def_id)) {
+ let lang_items = def_path_res(cx, &["rustc_hir", "lang_items", "LangItem"], Some(Namespace::TypeNS)).def_id();
+ let item_name = cx
+ .tcx
+ .adt_def(lang_items)
+ .variants()
+ .iter()
+ .nth(lang_item)
+ .unwrap()
+ .name;
+ Some(item_name)
+ } else {
+ None
+ }
+}
diff --git a/src/tools/clippy/clippy_lints/src/wildcard_imports.rs b/src/tools/clippy/clippy_lints/src/wildcard_imports.rs
index 5418eca38..be9834447 100644
--- a/src/tools/clippy/clippy_lints/src/wildcard_imports.rs
+++ b/src/tools/clippy/clippy_lints/src/wildcard_imports.rs
@@ -120,14 +120,14 @@ impl LateLintPass<'_> for WildcardImports {
if is_test_module_or_function(cx.tcx, item) {
self.test_modules_deep = self.test_modules_deep.saturating_add(1);
}
- let module = cx.tcx.parent_module_from_def_id(item.def_id);
- if cx.tcx.visibility(item.def_id) != ty::Visibility::Restricted(module.to_def_id()) {
+ let module = cx.tcx.parent_module_from_def_id(item.owner_id.def_id);
+ if cx.tcx.visibility(item.owner_id.def_id) != ty::Visibility::Restricted(module.to_def_id()) {
return;
}
if_chain! {
if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind;
if self.warn_on_all || !self.check_exceptions(item, use_path.segments);
- let used_imports = cx.tcx.names_imported_by_glob_use(item.def_id);
+ let used_imports = cx.tcx.names_imported_by_glob_use(item.owner_id.def_id);
if !used_imports.is_empty(); // Already handled by `unused_imports`
then {
let mut applicability = Applicability::MachineApplicable;
@@ -173,7 +173,7 @@ impl LateLintPass<'_> for WildcardImports {
let sugg = if braced_glob {
imports_string
} else {
- format!("{}::{}", import_source_snippet, imports_string)
+ format!("{import_source_snippet}::{imports_string}")
};
let (lint, message) = if let Res::Def(DefKind::Enum, _) = use_path.res {
diff --git a/src/tools/clippy/clippy_lints/src/write.rs b/src/tools/clippy/clippy_lints/src/write.rs
index 640a09a7a..36574198f 100644
--- a/src/tools/clippy/clippy_lints/src/write.rs
+++ b/src/tools/clippy/clippy_lints/src/write.rs
@@ -1,20 +1,12 @@
-use std::borrow::Cow;
-use std::iter;
-use std::ops::{Deref, Range};
-
-use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then};
-use clippy_utils::source::{snippet, snippet_opt, snippet_with_applicability};
-use rustc_ast::ast::{Expr, ExprKind, Impl, Item, ItemKind, MacCall, Path, StrLit, StrStyle};
-use rustc_ast::ptr::P;
-use rustc_ast::token::{self, LitKind};
-use rustc_ast::tokenstream::TokenStream;
-use rustc_errors::{Applicability, DiagnosticBuilder};
-use rustc_lexer::unescape::{self, EscapeError};
-use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
-use rustc_parse::parser;
+use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
+use clippy_utils::macros::{root_macro_call_first_node, FormatArgsExpn, MacroCall};
+use clippy_utils::source::{expand_past_previous_comma, snippet_opt};
+use rustc_ast::LitKind;
+use rustc_errors::Applicability;
+use rustc_hir::{Expr, ExprKind, HirIdMap, Impl, Item, ItemKind};
+use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_session::{declare_tool_lint, impl_lint_pass};
-use rustc_span::symbol::{kw, Symbol};
-use rustc_span::{sym, BytePos, InnerSpan, Span, DUMMY_SP};
+use rustc_span::{sym, BytePos};
declare_clippy_lint! {
/// ### What it does
@@ -74,13 +66,7 @@ declare_clippy_lint! {
/// application and might forget to remove those prints afterward.
///
/// ### Known problems
- /// * Only catches `print!` and `println!` calls.
- /// * The lint level is unaffected by crate attributes. The level can still
- /// be set for functions, modules and other items. To change the level for
- /// the entire crate, please use command line flags. More information and a
- /// configuration example can be found in [clippy#6610].
- ///
- /// [clippy#6610]: https://github.com/rust-lang/rust-clippy/issues/6610#issuecomment-977120558
+ /// Only catches `print!` and `println!` calls.
///
/// ### Example
/// ```rust
@@ -102,13 +88,7 @@ declare_clippy_lint! {
/// application and might forget to remove those prints afterward.
///
/// ### Known problems
- /// * Only catches `eprint!` and `eprintln!` calls.
- /// * The lint level is unaffected by crate attributes. The level can still
- /// be set for functions, modules and other items. To change the level for
- /// the entire crate, please use command line flags. More information and a
- /// configuration example can be found in [clippy#6610].
- ///
- /// [clippy#6610]: https://github.com/rust-lang/rust-clippy/issues/6610#issuecomment-977120558
+ /// Only catches `eprint!` and `eprintln!` calls.
///
/// ### Example
/// ```rust
@@ -149,10 +129,6 @@ declare_clippy_lint! {
/// (c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary
/// (i.e., just put the literal in the format string)
///
- /// ### Known problems
- /// Will also warn with macro calls as arguments that expand to literals
- /// -- e.g., `println!("{}", env!("FOO"))`.
- ///
/// ### Example
/// ```rust
/// println!("{}", "foo");
@@ -234,10 +210,6 @@ declare_clippy_lint! {
/// (c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary
/// (i.e., just put the literal in the format string)
///
- /// ### Known problems
- /// Will also warn with macro calls as arguments that expand to literals
- /// -- e.g., `writeln!(buf, "{}", env!("FOO"))`.
- ///
/// ### Example
/// ```rust
/// # use std::fmt::Write;
@@ -257,28 +229,6 @@ declare_clippy_lint! {
"writing a literal with a format string"
}
-declare_clippy_lint! {
- /// ### What it does
- /// This lint warns when a named parameter in a format string is used as a positional one.
- ///
- /// ### Why is this bad?
- /// It may be confused for an assignment and obfuscates which parameter is being used.
- ///
- /// ### Example
- /// ```rust
- /// println!("{}", x = 10);
- /// ```
- ///
- /// Use instead:
- /// ```rust
- /// println!("{x}", x = 10);
- /// ```
- #[clippy::version = "1.63.0"]
- pub POSITIONAL_NAMED_FORMAT_PARAMETERS,
- suspicious,
- "named parameter in a format string is used positionally"
-}
-
#[derive(Default)]
pub struct Write {
in_debug_impl: bool,
@@ -294,537 +244,301 @@ impl_lint_pass!(Write => [
WRITE_WITH_NEWLINE,
WRITELN_EMPTY_STRING,
WRITE_LITERAL,
- POSITIONAL_NAMED_FORMAT_PARAMETERS,
]);
-impl EarlyLintPass for Write {
- fn check_item(&mut self, _: &EarlyContext<'_>, item: &Item) {
- if let ItemKind::Impl(box Impl {
- of_trait: Some(trait_ref),
- ..
- }) = &item.kind
- {
- let trait_name = trait_ref
- .path
- .segments
- .iter()
- .last()
- .expect("path has at least one segment")
- .ident
- .name;
- if trait_name == sym::Debug {
- self.in_debug_impl = true;
- }
+impl<'tcx> LateLintPass<'tcx> for Write {
+ fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
+ if is_debug_impl(cx, item) {
+ self.in_debug_impl = true;
}
}
- fn check_item_post(&mut self, _: &EarlyContext<'_>, _: &Item) {
- self.in_debug_impl = false;
+ fn check_item_post(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
+ if is_debug_impl(cx, item) {
+ self.in_debug_impl = false;
+ }
}
- fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &MacCall) {
- fn is_build_script(cx: &EarlyContext<'_>) -> bool {
- // Cargo sets the crate name for build scripts to `build_script_build`
- cx.sess()
- .opts
- .crate_name
- .as_ref()
- .map_or(false, |crate_name| crate_name == "build_script_build")
- }
+ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
+ let Some(macro_call) = root_macro_call_first_node(cx, expr) else { return };
+ let Some(diag_name) = cx.tcx.get_diagnostic_name(macro_call.def_id) else { return };
+ let Some(name) = diag_name.as_str().strip_suffix("_macro") else { return };
- if mac.path == sym!(print) {
- if !is_build_script(cx) {
- span_lint(cx, PRINT_STDOUT, mac.span(), "use of `print!`");
- }
- self.lint_print_with_newline(cx, mac);
- } else if mac.path == sym!(println) {
- if !is_build_script(cx) {
- span_lint(cx, PRINT_STDOUT, mac.span(), "use of `println!`");
- }
- self.lint_println_empty_string(cx, mac);
- } else if mac.path == sym!(eprint) {
- span_lint(cx, PRINT_STDERR, mac.span(), "use of `eprint!`");
- self.lint_print_with_newline(cx, mac);
- } else if mac.path == sym!(eprintln) {
- span_lint(cx, PRINT_STDERR, mac.span(), "use of `eprintln!`");
- self.lint_println_empty_string(cx, mac);
- } else if mac.path == sym!(write) {
- if let (Some(fmt_str), dest) = self.check_tts(cx, mac.args.inner_tokens(), true) {
- if check_newlines(&fmt_str) {
- let (nl_span, only_nl) = newline_span(&fmt_str);
- let nl_span = match (dest, only_nl) {
- // Special case of `write!(buf, "\n")`: Mark everything from the end of
- // `buf` for removal so no trailing comma [`writeln!(buf, )`] remains.
- (Some(dest_expr), true) => nl_span.with_lo(dest_expr.span.hi()),
- _ => nl_span,
- };
- span_lint_and_then(
- cx,
- WRITE_WITH_NEWLINE,
- mac.span(),
- "using `write!()` with a format string that ends in a single newline",
- |err| {
- err.multipart_suggestion(
- "use `writeln!()` instead",
- vec![(mac.path.span, String::from("writeln")), (nl_span, String::new())],
- Applicability::MachineApplicable,
- );
- },
- );
- }
- }
- } else if mac.path == sym!(writeln) {
- if let (Some(fmt_str), expr) = self.check_tts(cx, mac.args.inner_tokens(), true) {
- if fmt_str.symbol == kw::Empty {
- let mut applicability = Applicability::MachineApplicable;
- let suggestion = if let Some(e) = expr {
- snippet_with_applicability(cx, e.span, "v", &mut applicability)
- } else {
- applicability = Applicability::HasPlaceholders;
- Cow::Borrowed("v")
- };
-
- span_lint_and_sugg(
- cx,
- WRITELN_EMPTY_STRING,
- mac.span(),
- format!("using `writeln!({}, \"\")`", suggestion).as_str(),
- "replace it with",
- format!("writeln!({})", suggestion),
- applicability,
- );
+ let is_build_script = cx
+ .sess()
+ .opts
+ .crate_name
+ .as_ref()
+ .map_or(false, |crate_name| crate_name == "build_script_build");
+
+ match diag_name {
+ sym::print_macro | sym::println_macro => {
+ if !is_build_script {
+ span_lint(cx, PRINT_STDOUT, macro_call.span, &format!("use of `{name}!`"));
}
- }
+ },
+ sym::eprint_macro | sym::eprintln_macro => {
+ span_lint(cx, PRINT_STDERR, macro_call.span, &format!("use of `{name}!`"));
+ },
+ sym::write_macro | sym::writeln_macro => {},
+ _ => return,
}
- }
-}
-/// Given a format string that ends in a newline and its span, calculates the span of the
-/// newline, or the format string itself if the format string consists solely of a newline.
-/// Return this and a boolean indicating whether it only consisted of a newline.
-fn newline_span(fmtstr: &StrLit) -> (Span, bool) {
- let sp = fmtstr.span;
- let contents = fmtstr.symbol.as_str();
-
- if contents == r"\n" {
- return (sp, true);
- }
+ let Some(format_args) = FormatArgsExpn::find_nested(cx, expr, macro_call.expn) else { return };
- let newline_sp_hi = sp.hi()
- - match fmtstr.style {
- StrStyle::Cooked => BytePos(1),
- StrStyle::Raw(hashes) => BytePos((1 + hashes).into()),
- };
+ // ignore `writeln!(w)` and `write!(v, some_macro!())`
+ if format_args.format_string.span.from_expansion() {
+ return;
+ }
- let newline_sp_len = if contents.ends_with('\n') {
- BytePos(1)
- } else if contents.ends_with(r"\n") {
- BytePos(2)
- } else {
- panic!("expected format string to contain a newline");
- };
+ match diag_name {
+ sym::print_macro | sym::eprint_macro | sym::write_macro => {
+ check_newline(cx, &format_args, &macro_call, name);
+ },
+ sym::println_macro | sym::eprintln_macro | sym::writeln_macro => {
+ check_empty_string(cx, &format_args, &macro_call, name);
+ },
+ _ => {},
+ }
- (sp.with_lo(newline_sp_hi - newline_sp_len).with_hi(newline_sp_hi), false)
-}
+ check_literal(cx, &format_args, name);
-/// Stores a list of replacement spans for each argument, but only if all the replacements used an
-/// empty format string.
-#[derive(Default)]
-struct SimpleFormatArgs {
- unnamed: Vec<Vec<Span>>,
- complex_unnamed: Vec<Vec<Span>>,
- named: Vec<(Symbol, Vec<Span>)>,
+ if !self.in_debug_impl {
+ for arg in &format_args.args {
+ if arg.format.r#trait == sym::Debug {
+ span_lint(cx, USE_DEBUG, arg.span, "use of `Debug`-based formatting");
+ }
+ }
+ }
+ }
}
-impl SimpleFormatArgs {
- fn get_unnamed(&self) -> impl Iterator<Item = &[Span]> {
- self.unnamed.iter().map(|x| match x.as_slice() {
- // Ignore the dummy span added from out of order format arguments.
- [DUMMY_SP] => &[],
- x => x,
- })
+fn is_debug_impl(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
+ if let ItemKind::Impl(Impl { of_trait: Some(trait_ref), .. }) = &item.kind
+ && let Some(trait_id) = trait_ref.trait_def_id()
+ {
+ cx.tcx.is_diagnostic_item(sym::Debug, trait_id)
+ } else {
+ false
}
+}
- fn get_complex_unnamed(&self) -> impl Iterator<Item = &[Span]> {
- self.complex_unnamed.iter().map(Vec::as_slice)
- }
+fn check_newline(cx: &LateContext<'_>, format_args: &FormatArgsExpn<'_>, macro_call: &MacroCall, name: &str) {
+ let format_string_parts = &format_args.format_string.parts;
+ let mut format_string_span = format_args.format_string.span;
- fn get_named(&self, n: &Path) -> &[Span] {
- self.named.iter().find(|x| *n == x.0).map_or(&[], |x| x.1.as_slice())
- }
+ let Some(last) = format_string_parts.last() else { return };
- fn push(&mut self, arg: rustc_parse_format::Argument<'_>, span: Span) {
- use rustc_parse_format::{
- AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec,
- };
+ let count_vertical_whitespace = || {
+ format_string_parts
+ .iter()
+ .flat_map(|part| part.as_str().chars())
+ .filter(|ch| matches!(ch, '\r' | '\n'))
+ .count()
+ };
- const SIMPLE: FormatSpec<'_> = FormatSpec {
- fill: None,
- align: AlignUnknown,
- flags: 0,
- precision: CountImplied,
- precision_span: None,
- width: CountImplied,
- width_span: None,
- ty: "",
- ty_span: None,
- };
+ if last.as_str().ends_with('\n')
+ // ignore format strings with other internal vertical whitespace
+ && count_vertical_whitespace() == 1
- match arg.position {
- ArgumentIs(n) | ArgumentImplicitlyIs(n) => {
- if self.unnamed.len() <= n {
- // Use a dummy span to mark all unseen arguments.
- self.unnamed.resize_with(n, || vec![DUMMY_SP]);
- if arg.format == SIMPLE {
- self.unnamed.push(vec![span]);
- } else {
- self.unnamed.push(Vec::new());
- }
- } else {
- let args = &mut self.unnamed[n];
- match (args.as_mut_slice(), arg.format == SIMPLE) {
- // A non-empty format string has been seen already.
- ([], _) => (),
- // Replace the dummy span, if it exists.
- ([dummy @ DUMMY_SP], true) => *dummy = span,
- ([_, ..], true) => args.push(span),
- ([_, ..], false) => *args = Vec::new(),
- }
- }
- },
- ArgumentNamed(n) => {
- let n = Symbol::intern(n);
- if let Some(x) = self.named.iter_mut().find(|x| x.0 == n) {
- match x.1.as_slice() {
- // A non-empty format string has been seen already.
- [] => (),
- [_, ..] if arg.format == SIMPLE => x.1.push(span),
- [_, ..] => x.1 = Vec::new(),
- }
- } else if arg.format == SIMPLE {
- self.named.push((n, vec![span]));
- } else {
- self.named.push((n, Vec::new()));
- }
- },
- };
- }
+ // ignore trailing arguments: `print!("Issue\n{}", 1265);`
+ && format_string_parts.len() > format_args.args.len()
+ {
+ let lint = if name == "write" {
+ format_string_span = expand_past_previous_comma(cx, format_string_span);
- fn push_to_complex(&mut self, span: Span, position: usize) {
- if self.complex_unnamed.len() <= position {
- self.complex_unnamed.resize_with(position, Vec::new);
- self.complex_unnamed.push(vec![span]);
+ WRITE_WITH_NEWLINE
} else {
- let args: &mut Vec<Span> = &mut self.complex_unnamed[position];
- args.push(span);
- }
- }
-
- fn push_complex(
- &mut self,
- cx: &EarlyContext<'_>,
- arg: rustc_parse_format::Argument<'_>,
- str_lit_span: Span,
- fmt_span: Span,
- ) {
- use rustc_parse_format::{ArgumentImplicitlyIs, ArgumentIs, CountIsParam, CountIsStar};
-
- let snippet = snippet_opt(cx, fmt_span);
-
- let end = snippet
- .as_ref()
- .and_then(|s| s.find(':'))
- .or_else(|| fmt_span.hi().0.checked_sub(fmt_span.lo().0 + 1).map(|u| u as usize));
-
- if let (ArgumentIs(n) | ArgumentImplicitlyIs(n), Some(end)) = (arg.position, end) {
- let span = fmt_span.from_inner(InnerSpan::new(1, end));
- self.push_to_complex(span, n);
+ PRINT_WITH_NEWLINE
};
- if let (CountIsParam(n) | CountIsStar(n), Some(span)) = (arg.format.precision, arg.format.precision_span) {
- // We need to do this hack as precision spans should be converted from .* to .foo$
- let hack = if snippet.as_ref().and_then(|s| s.find('*')).is_some() {
- 0
- } else {
- 1
- };
+ span_lint_and_then(
+ cx,
+ lint,
+ macro_call.span,
+ &format!("using `{name}!()` with a format string that ends in a single newline"),
+ |diag| {
+ let name_span = cx.sess().source_map().span_until_char(macro_call.span, '!');
+ let Some(format_snippet) = snippet_opt(cx, format_string_span) else { return };
+
+ if format_string_parts.len() == 1 && last.as_str() == "\n" {
+ // print!("\n"), write!(f, "\n")
+
+ diag.multipart_suggestion(
+ &format!("use `{name}ln!` instead"),
+ vec![(name_span, format!("{name}ln")), (format_string_span, String::new())],
+ Applicability::MachineApplicable,
+ );
+ } else if format_snippet.ends_with("\\n\"") {
+ // print!("...\n"), write!(f, "...\n")
- let span = str_lit_span.from_inner(InnerSpan {
- start: span.start + 1,
- end: span.end - hack,
- });
- self.push_to_complex(span, n);
- };
+ let hi = format_string_span.hi();
+ let newline_span = format_string_span.with_lo(hi - BytePos(3)).with_hi(hi - BytePos(1));
- if let (CountIsParam(n), Some(span)) = (arg.format.width, arg.format.width_span) {
- let span = str_lit_span.from_inner(InnerSpan {
- start: span.start,
- end: span.end - 1,
- });
- self.push_to_complex(span, n);
- };
+ diag.multipart_suggestion(
+ &format!("use `{name}ln!` instead"),
+ vec![(name_span, format!("{name}ln")), (newline_span, String::new())],
+ Applicability::MachineApplicable,
+ );
+ }
+ },
+ );
}
}
-impl Write {
- /// Parses a format string into a collection of spans for each argument. This only keeps track
- /// of empty format arguments. Will also lint usages of debug format strings outside of debug
- /// impls.
- fn parse_fmt_string(&self, cx: &EarlyContext<'_>, str_lit: &StrLit) -> Option<SimpleFormatArgs> {
- use rustc_parse_format::{ParseMode, Parser, Piece};
-
- let str_sym = str_lit.symbol_unescaped.as_str();
- let style = match str_lit.style {
- StrStyle::Cooked => None,
- StrStyle::Raw(n) => Some(n as usize),
- };
-
- let mut parser = Parser::new(str_sym, style, snippet_opt(cx, str_lit.span), false, ParseMode::Format);
- let mut args = SimpleFormatArgs::default();
-
- while let Some(arg) = parser.next() {
- let arg = match arg {
- Piece::String(_) => continue,
- Piece::NextArgument(arg) => arg,
- };
- let span = parser
- .arg_places
- .last()
- .map_or(DUMMY_SP, |&x| str_lit.span.from_inner(InnerSpan::new(x.start, x.end)));
-
- if !self.in_debug_impl && arg.format.ty == "?" {
- // FIXME: modify rustc's fmt string parser to give us the current span
- span_lint(cx, USE_DEBUG, span, "use of `Debug`-based formatting");
- }
- args.push(arg, span);
- args.push_complex(cx, arg, str_lit.span, span);
- }
-
- parser.errors.is_empty().then_some(args)
- }
+fn check_empty_string(cx: &LateContext<'_>, format_args: &FormatArgsExpn<'_>, macro_call: &MacroCall, name: &str) {
+ if let [part] = &format_args.format_string.parts[..]
+ && let mut span = format_args.format_string.span
+ && part.as_str() == "\n"
+ {
+ let lint = if name == "writeln" {
+ span = expand_past_previous_comma(cx, span);
- /// Checks the arguments of `print[ln]!` and `write[ln]!` calls. It will return a tuple of two
- /// `Option`s. The first `Option` of the tuple is the macro's format string. It includes
- /// the contents of the string, whether it's a raw string, and the span of the literal in the
- /// source. The second `Option` in the tuple is, in the `write[ln]!` case, the expression the
- /// `format_str` should be written to.
- ///
- /// Example:
- ///
- /// Calling this function on
- /// ```rust
- /// # use std::fmt::Write;
- /// # let mut buf = String::new();
- /// # let something = "something";
- /// writeln!(buf, "string to write: {}", something);
- /// ```
- /// will return
- /// ```rust,ignore
- /// (Some("string to write: {}"), Some(buf))
- /// ```
- fn check_tts<'a>(&self, cx: &EarlyContext<'a>, tts: TokenStream, is_write: bool) -> (Option<StrLit>, Option<Expr>) {
- let mut parser = parser::Parser::new(&cx.sess().parse_sess, tts, false, None);
- let expr = if is_write {
- match parser
- .parse_expr()
- .map(rustc_ast::ptr::P::into_inner)
- .map_err(DiagnosticBuilder::cancel)
- {
- // write!(e, ...)
- Ok(p) if parser.eat(&token::Comma) => Some(p),
- // write!(e) or error
- e => return (None, e.ok()),
- }
+ WRITELN_EMPTY_STRING
} else {
- None
+ PRINTLN_EMPTY_STRING
};
- let fmtstr = match parser.parse_str_lit() {
- Ok(fmtstr) => fmtstr,
- Err(_) => return (None, expr),
- };
+ span_lint_and_then(
+ cx,
+ lint,
+ macro_call.span,
+ &format!("empty string literal in `{name}!`"),
+ |diag| {
+ diag.span_suggestion(
+ span,
+ "remove the empty string",
+ String::new(),
+ Applicability::MachineApplicable,
+ );
+ },
+ );
+ }
+}
- let args = match self.parse_fmt_string(cx, &fmtstr) {
- Some(args) => args,
- None => return (Some(fmtstr), expr),
- };
+fn check_literal(cx: &LateContext<'_>, format_args: &FormatArgsExpn<'_>, name: &str) {
+ let mut counts = HirIdMap::<usize>::default();
+ for param in format_args.params() {
+ *counts.entry(param.value.hir_id).or_default() += 1;
+ }
- let lint = if is_write { WRITE_LITERAL } else { PRINT_LITERAL };
- let mut unnamed_args = args.get_unnamed();
- let mut complex_unnamed_args = args.get_complex_unnamed();
- loop {
- if !parser.eat(&token::Comma) {
- return (Some(fmtstr), expr);
- }
+ for arg in &format_args.args {
+ let value = arg.param.value;
- let comma_span = parser.prev_token.span;
- let token_expr = if let Ok(expr) = parser.parse_expr().map_err(DiagnosticBuilder::cancel) {
- expr
- } else {
- return (Some(fmtstr), None);
- };
- let complex_unnamed_arg = complex_unnamed_args.next();
-
- let (fmt_spans, lit) = match &token_expr.kind {
- ExprKind::Lit(lit) => (unnamed_args.next().unwrap_or(&[]), lit),
- ExprKind::Assign(lhs, rhs, _) => {
- if let Some(span) = complex_unnamed_arg {
- for x in span {
- Self::report_positional_named_param(cx, *x, lhs, rhs);
- }
- }
- match (&lhs.kind, &rhs.kind) {
- (ExprKind::Path(_, p), ExprKind::Lit(lit)) => (args.get_named(p), lit),
- _ => continue,
+ if counts[&value.hir_id] == 1
+ && arg.format.is_default()
+ && let ExprKind::Lit(lit) = &value.kind
+ && !value.span.from_expansion()
+ && let Some(value_string) = snippet_opt(cx, value.span)
+ {
+ let (replacement, replace_raw) = match lit.node {
+ LitKind::Str(..) => extract_str_literal(&value_string),
+ LitKind::Char(ch) => (
+ match ch {
+ '"' => "\\\"",
+ '\'' => "'",
+ _ => &value_string[1..value_string.len() - 1],
}
- },
- _ => {
- unnamed_args.next();
- continue;
- },
+ .to_string(),
+ false,
+ ),
+ LitKind::Bool(b) => (b.to_string(), false),
+ _ => continue,
};
- let replacement: String = match lit.token_lit.kind {
- LitKind::StrRaw(_) | LitKind::ByteStrRaw(_) if matches!(fmtstr.style, StrStyle::Raw(_)) => {
- lit.token_lit.symbol.as_str().replace('{', "{{").replace('}', "}}")
+ let lint = if name.starts_with("write") {
+ WRITE_LITERAL
+ } else {
+ PRINT_LITERAL
+ };
+
+ let format_string_is_raw = format_args.format_string.style.is_some();
+ let replacement = match (format_string_is_raw, replace_raw) {
+ (false, false) => Some(replacement),
+ (false, true) => Some(replacement.replace('"', "\\\"").replace('\\', "\\\\")),
+ (true, false) => match conservative_unescape(&replacement) {
+ Ok(unescaped) => Some(unescaped),
+ Err(UnescapeErr::Lint) => None,
+ Err(UnescapeErr::Ignore) => continue,
},
- LitKind::Str | LitKind::ByteStr if matches!(fmtstr.style, StrStyle::Cooked) => {
- lit.token_lit.symbol.as_str().replace('{', "{{").replace('}', "}}")
+ (true, true) => {
+ if replacement.contains(['#', '"']) {
+ None
+ } else {
+ Some(replacement)
+ }
},
- LitKind::StrRaw(_)
- | LitKind::Str
- | LitKind::ByteStrRaw(_)
- | LitKind::ByteStr
- | LitKind::Integer
- | LitKind::Float
- | LitKind::Err => continue,
- LitKind::Byte | LitKind::Char => match lit.token_lit.symbol.as_str() {
- "\"" if matches!(fmtstr.style, StrStyle::Cooked) => "\\\"",
- "\"" if matches!(fmtstr.style, StrStyle::Raw(0)) => continue,
- "\\\\" if matches!(fmtstr.style, StrStyle::Raw(_)) => "\\",
- "\\'" => "'",
- "{" => "{{",
- "}" => "}}",
- x if matches!(fmtstr.style, StrStyle::Raw(_)) && x.starts_with('\\') => continue,
- x => x,
- }
- .into(),
- LitKind::Bool => lit.token_lit.symbol.as_str().deref().into(),
};
- if !fmt_spans.is_empty() {
- span_lint_and_then(
- cx,
- lint,
- token_expr.span,
- "literal with an empty format string",
- |diag| {
+ span_lint_and_then(
+ cx,
+ lint,
+ value.span,
+ "literal with an empty format string",
+ |diag| {
+ if let Some(replacement) = replacement
+ // `format!("{}", "a")`, `format!("{named}", named = "b")
+ // ~~~~~ ~~~~~~~~~~~~~
+ && let Some(value_span) = format_args.value_with_prev_comma_span(value.hir_id)
+ {
+ let replacement = replacement.replace('{', "{{").replace('}', "}}");
diag.multipart_suggestion(
"try this",
- iter::once((comma_span.to(token_expr.span), String::new()))
- .chain(fmt_spans.iter().copied().zip(iter::repeat(replacement)))
- .collect(),
+ vec![(arg.span, replacement), (value_span, String::new())],
Applicability::MachineApplicable,
);
- },
- );
- }
- }
- }
-
- fn report_positional_named_param(cx: &EarlyContext<'_>, span: Span, lhs: &P<Expr>, _rhs: &P<Expr>) {
- if let ExprKind::Path(_, _p) = &lhs.kind {
- let mut applicability = Applicability::MachineApplicable;
- let name = snippet_with_applicability(cx, lhs.span, "name", &mut applicability);
- // We need to do this hack as precision spans should be converted from .* to .foo$
- let hack = snippet(cx, span, "").contains('*');
-
- span_lint_and_sugg(
- cx,
- POSITIONAL_NAMED_FORMAT_PARAMETERS,
- span,
- &format!("named parameter {} is used as a positional parameter", name),
- "replace it with",
- if hack {
- format!("{}$", name)
- } else {
- format!("{}", name)
+ }
},
- applicability,
);
- };
- }
-
- fn lint_println_empty_string(&self, cx: &EarlyContext<'_>, mac: &MacCall) {
- if let (Some(fmt_str), _) = self.check_tts(cx, mac.args.inner_tokens(), false) {
- if fmt_str.symbol == kw::Empty {
- let name = mac.path.segments[0].ident.name;
- span_lint_and_sugg(
- cx,
- PRINTLN_EMPTY_STRING,
- mac.span(),
- &format!("using `{}!(\"\")`", name),
- "replace it with",
- format!("{}!()", name),
- Applicability::MachineApplicable,
- );
- }
- }
- }
-
- fn lint_print_with_newline(&self, cx: &EarlyContext<'_>, mac: &MacCall) {
- if let (Some(fmt_str), _) = self.check_tts(cx, mac.args.inner_tokens(), false) {
- if check_newlines(&fmt_str) {
- let name = mac.path.segments[0].ident.name;
- let suggested = format!("{}ln", name);
- span_lint_and_then(
- cx,
- PRINT_WITH_NEWLINE,
- mac.span(),
- &format!("using `{}!()` with a format string that ends in a single newline", name),
- |err| {
- err.multipart_suggestion(
- &format!("use `{}!` instead", suggested),
- vec![(mac.path.span, suggested), (newline_span(&fmt_str).0, String::new())],
- Applicability::MachineApplicable,
- );
- },
- );
- }
}
}
}
-/// Checks if the format string contains a single newline that terminates it.
+/// Removes the raw marker, `#`s and quotes from a str, and returns if the literal is raw
///
-/// Literal and escaped newlines are both checked (only literal for raw strings).
-fn check_newlines(fmtstr: &StrLit) -> bool {
- let mut has_internal_newline = false;
- let mut last_was_cr = false;
- let mut should_lint = false;
-
- let contents = fmtstr.symbol.as_str();
-
- let mut cb = |r: Range<usize>, c: Result<char, EscapeError>| {
- let c = match c {
- Ok(c) => c,
- Err(e) if !e.is_fatal() => return,
- Err(e) => panic!("{:?}", e),
- };
-
- if r.end == contents.len() && c == '\n' && !last_was_cr && !has_internal_newline {
- should_lint = true;
- } else {
- last_was_cr = c == '\r';
- if c == '\n' {
- has_internal_newline = true;
- }
- }
+/// `r#"a"#` -> (`a`, true)
+///
+/// `"b"` -> (`b`, false)
+fn extract_str_literal(literal: &str) -> (String, bool) {
+ let (literal, raw) = match literal.strip_prefix('r') {
+ Some(stripped) => (stripped.trim_matches('#'), true),
+ None => (literal, false),
};
- match fmtstr.style {
- StrStyle::Cooked => unescape::unescape_literal(contents, unescape::Mode::Str, &mut cb),
- StrStyle::Raw(_) => unescape::unescape_literal(contents, unescape::Mode::RawStr, &mut cb),
+ (literal[1..literal.len() - 1].to_string(), raw)
+}
+
+enum UnescapeErr {
+ /// Should still be linted, can be manually resolved by author, e.g.
+ ///
+ /// ```ignore
+ /// print!(r"{}", '"');
+ /// ```
+ Lint,
+ /// Should not be linted, e.g.
+ ///
+ /// ```ignore
+ /// print!(r"{}", '\r');
+ /// ```
+ Ignore,
+}
+
+/// Unescape a normal string into a raw string
+fn conservative_unescape(literal: &str) -> Result<String, UnescapeErr> {
+ let mut unescaped = String::with_capacity(literal.len());
+ let mut chars = literal.chars();
+ let mut err = false;
+
+ while let Some(ch) = chars.next() {
+ match ch {
+ '#' => err = true,
+ '\\' => match chars.next() {
+ Some('\\') => unescaped.push('\\'),
+ Some('"') => err = true,
+ _ => return Err(UnescapeErr::Ignore),
+ },
+ _ => unescaped.push(ch),
+ }
}
- should_lint
+ if err { Err(UnescapeErr::Lint) } else { Ok(unescaped) }
}
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 50d3c079f..9b3de35db 100644
--- a/src/tools/clippy/clippy_lints/src/zero_div_zero.rs
+++ b/src/tools/clippy/clippy_lints/src/zero_div_zero.rs
@@ -57,8 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for ZeroDiv {
"constant division of `0.0` with `0.0` will always result in NaN",
None,
&format!(
- "consider using `{}::NAN` if you would like a constant representing NaN",
- float_type,
+ "consider using `{float_type}::NAN` if you would like a constant representing NaN",
),
);
}
diff --git a/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs b/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs
index 8dc43c0e2..6cf2a955f 100644
--- a/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs
+++ b/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs
@@ -2,12 +2,12 @@ use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item};
use if_chain::if_chain;
use rustc_hir::{self as hir, HirId, ItemKind, Node};
+use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::layout::LayoutOf as _;
use rustc_middle::ty::{Adt, Ty, TypeVisitable};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::sym;
-use rustc_typeck::hir_ty_to_ty;
declare_clippy_lint! {
/// ### What it does
@@ -69,10 +69,7 @@ impl LateLintPass<'_> for ZeroSizedMapValues {
fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool {
let parent_id = cx.tcx.hir().get_parent_item(hir_id);
- let second_parent_id = cx
- .tcx
- .hir()
- .get_parent_item(cx.tcx.hir().local_def_id_to_hir_id(parent_id));
+ let second_parent_id = cx.tcx.hir().get_parent_item(parent_id.into()).def_id;
if let Some(Node::Item(item)) = cx.tcx.hir().find_by_def_id(second_parent_id) {
if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind {
return true;
diff --git a/src/tools/clippy/clippy_utils/Cargo.toml b/src/tools/clippy/clippy_utils/Cargo.toml
index c36bca065..83fee7bb3 100644
--- a/src/tools/clippy/clippy_utils/Cargo.toml
+++ b/src/tools/clippy/clippy_utils/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "clippy_utils"
-version = "0.1.65"
+version = "0.1.66"
edition = "2021"
publish = false
diff --git a/src/tools/clippy/clippy_utils/src/ast_utils.rs b/src/tools/clippy/clippy_utils/src/ast_utils.rs
index e84adee9d..013399756 100644
--- a/src/tools/clippy/clippy_utils/src/ast_utils.rs
+++ b/src/tools/clippy/clippy_utils/src/ast_utils.rs
@@ -147,7 +147,9 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
(Array(l), Array(r)) | (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
(Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value),
(Call(lc, la), Call(rc, ra)) => eq_expr(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)),
- (MethodCall(lc, la, _), MethodCall(rc, ra, _)) => eq_path_seg(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)),
+ (MethodCall(lc, ls, la, _), MethodCall(rc, rs, ra, _)) => {
+ eq_path_seg(lc, rc) && eq_expr(ls, rs) && over(la, ra, |l, r| eq_expr(l, r))
+ },
(Binary(lo, ll, lr), Binary(ro, rl, rr)) => lo.node == ro.node && eq_expr(ll, rl) && eq_expr(lr, rr),
(Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r),
(Lit(l), Lit(r)) => l.kind == r.kind,
@@ -436,14 +438,14 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool {
eq_defaultness(*ld, *rd) && eq_fn_sig(lf, rf) && eq_generics(lg, rg) && both(lb, rb, |l, r| eq_block(l, r))
},
(
- TyAlias(box ast::TyAlias {
+ Type(box ast::TyAlias {
defaultness: ld,
generics: lg,
bounds: lb,
ty: lt,
..
}),
- TyAlias(box ast::TyAlias {
+ Type(box ast::TyAlias {
defaultness: rd,
generics: rg,
bounds: rb,
diff --git a/src/tools/clippy/clippy_utils/src/attrs.rs b/src/tools/clippy/clippy_utils/src/attrs.rs
index 8ab77c881..cd8575c90 100644
--- a/src/tools/clippy/clippy_utils/src/attrs.rs
+++ b/src/tools/clippy/clippy_utils/src/attrs.rs
@@ -131,12 +131,12 @@ pub fn get_unique_inner_attr(sess: &Session, attrs: &[ast::Attribute], name: &'s
match attr.style {
ast::AttrStyle::Inner if unique_attr.is_none() => unique_attr = Some(attr.clone()),
ast::AttrStyle::Inner => {
- sess.struct_span_err(attr.span, &format!("`{}` is defined multiple times", name))
+ sess.struct_span_err(attr.span, &format!("`{name}` is defined multiple times"))
.span_note(unique_attr.as_ref().unwrap().span, "first definition found here")
.emit();
},
ast::AttrStyle::Outer => {
- sess.span_err(attr.span, &format!("`{}` cannot be an outer attribute", name));
+ sess.span_err(attr.span, format!("`{name}` cannot be an outer attribute"));
},
}
}
diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs
index 7a8d4e806..c6bf98b7b 100644
--- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs
+++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs
@@ -220,7 +220,7 @@ fn trait_item_search_pat(item: &TraitItem<'_>) -> (Pat, Pat) {
fn impl_item_search_pat(item: &ImplItem<'_>) -> (Pat, Pat) {
let (start_pat, end_pat) = match &item.kind {
ImplItemKind::Const(..) => (Pat::Str("const"), Pat::Str(";")),
- ImplItemKind::TyAlias(..) => (Pat::Str("type"), Pat::Str(";")),
+ ImplItemKind::Type(..) => (Pat::Str("type"), Pat::Str(";")),
ImplItemKind::Fn(sig, ..) => (fn_header_search_pat(sig.header), Pat::Str("")),
};
if item.vis_span.is_empty() {
diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs
index e053708ed..07e4ef6a2 100644
--- a/src/tools/clippy/clippy_utils/src/consts.rs
+++ b/src/tools/clippy/clippy_utils/src/consts.rs
@@ -9,7 +9,7 @@ use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind,
use rustc_lint::LateContext;
use rustc_middle::mir;
use rustc_middle::mir::interpret::Scalar;
-use rustc_middle::ty::subst::{Subst, SubstsRef};
+use rustc_middle::ty::SubstsRef;
use rustc_middle::ty::{self, EarlyBinder, FloatTy, ScalarInt, Ty, TyCtxt};
use rustc_middle::{bug, span_bug};
use rustc_span::symbol::Symbol;
@@ -136,17 +136,49 @@ impl Constant {
(&Self::F64(l), &Self::F64(r)) => l.partial_cmp(&r),
(&Self::F32(l), &Self::F32(r)) => l.partial_cmp(&r),
(&Self::Bool(ref l), &Self::Bool(ref r)) => Some(l.cmp(r)),
- (&Self::Tuple(ref l), &Self::Tuple(ref r)) | (&Self::Vec(ref l), &Self::Vec(ref r)) => iter::zip(l, r)
- .map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri))
- .find(|r| r.map_or(true, |o| o != Ordering::Equal))
- .unwrap_or_else(|| Some(l.len().cmp(&r.len()))),
+ (&Self::Tuple(ref l), &Self::Tuple(ref r)) if l.len() == r.len() => match *cmp_type.kind() {
+ ty::Tuple(tys) if tys.len() == l.len() => l
+ .iter()
+ .zip(r)
+ .zip(tys)
+ .map(|((li, ri), cmp_type)| Self::partial_cmp(tcx, cmp_type, li, ri))
+ .find(|r| r.map_or(true, |o| o != Ordering::Equal))
+ .unwrap_or_else(|| Some(l.len().cmp(&r.len()))),
+ _ => None,
+ },
+ (&Self::Vec(ref l), &Self::Vec(ref r)) => {
+ let cmp_type = match *cmp_type.kind() {
+ ty::Array(ty, _) | ty::Slice(ty) => ty,
+ _ => return None,
+ };
+ iter::zip(l, r)
+ .map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri))
+ .find(|r| r.map_or(true, |o| o != Ordering::Equal))
+ .unwrap_or_else(|| Some(l.len().cmp(&r.len())))
+ },
(&Self::Repeat(ref lv, ref ls), &Self::Repeat(ref rv, ref rs)) => {
- match Self::partial_cmp(tcx, cmp_type, lv, rv) {
+ match Self::partial_cmp(
+ tcx,
+ match *cmp_type.kind() {
+ ty::Array(ty, _) => ty,
+ _ => return None,
+ },
+ lv,
+ rv,
+ ) {
Some(Equal) => Some(ls.cmp(rs)),
x => x,
}
},
- (&Self::Ref(ref lb), &Self::Ref(ref rb)) => Self::partial_cmp(tcx, cmp_type, lb, rb),
+ (&Self::Ref(ref lb), &Self::Ref(ref rb)) => Self::partial_cmp(
+ tcx,
+ match *cmp_type.kind() {
+ ty::Ref(_, ty, _) => ty,
+ _ => return None,
+ },
+ lb,
+ rb,
+ ),
// TODO: are there any useful inter-type orderings?
_ => None,
}
@@ -424,7 +456,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
.tcx
.const_eval_resolve(
self.param_env,
- ty::Unevaluated::new(ty::WithOptConstParam::unknown(def_id), substs),
+ mir::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs),
None,
)
.ok()
@@ -501,8 +533,8 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
BinOpKind::Mul => l.checked_mul(r).map(zext),
BinOpKind::Div if r != 0 => l.checked_div(r).map(zext),
BinOpKind::Rem if r != 0 => l.checked_rem(r).map(zext),
- BinOpKind::Shr => l.checked_shr(r.try_into().expect("invalid shift")).map(zext),
- BinOpKind::Shl => l.checked_shl(r.try_into().expect("invalid shift")).map(zext),
+ BinOpKind::Shr => l.checked_shr(r.try_into().ok()?).map(zext),
+ BinOpKind::Shl => l.checked_shl(r.try_into().ok()?).map(zext),
BinOpKind::BitXor => Some(zext(l ^ r)),
BinOpKind::BitOr => Some(zext(l | r)),
BinOpKind::BitAnd => Some(zext(l & r)),
@@ -521,8 +553,8 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
BinOpKind::Mul => l.checked_mul(r).map(Constant::Int),
BinOpKind::Div => l.checked_div(r).map(Constant::Int),
BinOpKind::Rem => l.checked_rem(r).map(Constant::Int),
- BinOpKind::Shr => l.checked_shr(r.try_into().expect("shift too large")).map(Constant::Int),
- BinOpKind::Shl => l.checked_shl(r.try_into().expect("shift too large")).map(Constant::Int),
+ BinOpKind::Shr => l.checked_shr(r.try_into().ok()?).map(Constant::Int),
+ BinOpKind::Shl => l.checked_shl(r.try_into().ok()?).map(Constant::Int),
BinOpKind::BitXor => Some(Constant::Int(l ^ r)),
BinOpKind::BitOr => Some(Constant::Int(l | r)),
BinOpKind::BitAnd => Some(Constant::Int(l & r)),
diff --git a/src/tools/clippy/clippy_utils/src/diagnostics.rs b/src/tools/clippy/clippy_utils/src/diagnostics.rs
index ad95369b9..78f93755b 100644
--- a/src/tools/clippy/clippy_utils/src/diagnostics.rs
+++ b/src/tools/clippy/clippy_utils/src/diagnostics.rs
@@ -18,12 +18,11 @@ fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) {
if env::var("CLIPPY_DISABLE_DOCS_LINKS").is_err() {
if let Some(lint) = lint.name_lower().strip_prefix("clippy::") {
diag.help(&format!(
- "for further information visit https://rust-lang.github.io/rust-clippy/{}/index.html#{}",
+ "for further information visit https://rust-lang.github.io/rust-clippy/{}/index.html#{lint}",
&option_env!("RUST_RELEASE_NUM").map_or("master".to_string(), |n| {
// extract just major + minor version and ignore patch versions
format!("rust-{}", n.rsplit_once('.').unwrap().1)
- }),
- lint
+ })
));
}
}
@@ -47,10 +46,9 @@ fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) {
/// | ^^^^^^^^^^^^^^^^^^^^^^^
/// ```
pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<MultiSpan>, msg: &str) {
- cx.struct_span_lint(lint, sp, |diag| {
- let mut diag = diag.build(msg);
- docs_link(&mut diag, lint);
- diag.emit();
+ cx.struct_span_lint(lint, sp, msg, |diag| {
+ docs_link(diag, lint);
+ diag
});
}
@@ -82,15 +80,14 @@ pub fn span_lint_and_help<'a, T: LintContext>(
help_span: Option<Span>,
help: &str,
) {
- cx.struct_span_lint(lint, span, |diag| {
- let mut diag = diag.build(msg);
+ cx.struct_span_lint(lint, span, msg, |diag| {
if let Some(help_span) = help_span {
diag.span_help(help_span, help);
} else {
diag.help(help);
}
- docs_link(&mut diag, lint);
- diag.emit();
+ docs_link(diag, lint);
+ diag
});
}
@@ -125,15 +122,14 @@ pub fn span_lint_and_note<'a, T: LintContext>(
note_span: Option<Span>,
note: &str,
) {
- cx.struct_span_lint(lint, span, |diag| {
- let mut diag = diag.build(msg);
+ cx.struct_span_lint(lint, span, msg, |diag| {
if let Some(note_span) = note_span {
diag.span_note(note_span, note);
} else {
diag.note(note);
}
- docs_link(&mut diag, lint);
- diag.emit();
+ docs_link(diag, lint);
+ diag
});
}
@@ -147,19 +143,17 @@ where
S: Into<MultiSpan>,
F: FnOnce(&mut Diagnostic),
{
- cx.struct_span_lint(lint, sp, |diag| {
- let mut diag = diag.build(msg);
- f(&mut diag);
- docs_link(&mut diag, lint);
- diag.emit();
+ cx.struct_span_lint(lint, sp, msg, |diag| {
+ f(diag);
+ docs_link(diag, lint);
+ diag
});
}
pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) {
- cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| {
- let mut diag = diag.build(msg);
- docs_link(&mut diag, lint);
- diag.emit();
+ cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |diag| {
+ docs_link(diag, lint);
+ diag
});
}
@@ -171,11 +165,10 @@ pub fn span_lint_hir_and_then(
msg: &str,
f: impl FnOnce(&mut Diagnostic),
) {
- cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| {
- let mut diag = diag.build(msg);
- f(&mut diag);
- docs_link(&mut diag, lint);
- diag.emit();
+ cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |diag| {
+ f(diag);
+ docs_link(diag, lint);
+ diag
});
}
diff --git a/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs b/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs
index 91c9c382c..95b3e651e 100644
--- a/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs
+++ b/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs
@@ -113,7 +113,17 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
},
args,
) => match self.cx.qpath_res(path, hir_id) {
- Res::Def(DefKind::Ctor(..) | DefKind::Variant, _) | Res::SelfCtor(_) => (),
+ Res::Def(DefKind::Ctor(..) | DefKind::Variant, _) | Res::SelfCtor(_) => {
+ if self
+ .cx
+ .typeck_results()
+ .expr_ty(e)
+ .has_significant_drop(self.cx.tcx, self.cx.param_env)
+ {
+ self.eagerness = ForceNoChange;
+ return;
+ }
+ },
Res::Def(_, id) if self.cx.tcx.is_promotable_const_fn(id) => (),
// No need to walk the arguments here, `is_const_evaluatable` already did
Res::Def(..) if is_const_evaluatable(self.cx, e) => {
diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs
index 7212d9cd7..cf24ec8b6 100644
--- a/src/tools/clippy/clippy_utils/src/hir_utils.rs
+++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs
@@ -962,7 +962,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
mut_ty.mutbl.hash(&mut self.s);
},
TyKind::Rptr(lifetime, ref mut_ty) => {
- self.hash_lifetime(*lifetime);
+ self.hash_lifetime(lifetime);
self.hash_ty(mut_ty.ty);
mut_ty.mutbl.hash(&mut self.s);
},
@@ -992,7 +992,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
in_trait.hash(&mut self.s);
},
TyKind::TraitObject(_, lifetime, _) => {
- self.hash_lifetime(*lifetime);
+ self.hash_lifetime(lifetime);
},
TyKind::Typeof(anon_const) => {
self.hash_body(anon_const.body);
diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs
index 62da850a1..3ebfc5e00 100644
--- a/src/tools/clippy/clippy_utils/src/lib.rs
+++ b/src/tools/clippy/clippy_utils/src/lib.rs
@@ -3,7 +3,7 @@
#![feature(control_flow_enum)]
#![feature(let_chains)]
#![feature(lint_reasons)]
-#![cfg_attr(bootstrap, feature(let_else))]
+#![feature(never_type)]
#![feature(once_cell)]
#![feature(rustc_private)]
#![recursion_limit = "512"]
@@ -24,16 +24,18 @@ extern crate rustc_attr;
extern crate rustc_data_structures;
extern crate rustc_errors;
extern crate rustc_hir;
+extern crate rustc_hir_typeck;
+extern crate rustc_index;
extern crate rustc_infer;
extern crate rustc_lexer;
extern crate rustc_lint;
extern crate rustc_middle;
+extern crate rustc_mir_dataflow;
extern crate rustc_parse_format;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_target;
extern crate rustc_trait_selection;
-extern crate rustc_typeck;
#[macro_use]
pub mod sym_helper;
@@ -48,6 +50,7 @@ pub mod eager_or_lazy;
pub mod higher;
mod hir_utils;
pub mod macros;
+pub mod mir;
pub mod msrvs;
pub mod numeric_literal;
pub mod paths;
@@ -66,6 +69,7 @@ pub use self::hir_utils::{
both, count_eq, eq_expr_value, hash_expr, hash_stmt, over, HirEqInterExpr, SpanlessEq, SpanlessHash,
};
+use core::ops::ControlFlow;
use std::collections::hash_map::Entry;
use std::hash::BuildHasherDefault;
use std::sync::OnceLock;
@@ -77,8 +81,8 @@ use rustc_ast::Attribute;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::unhash::UnhashMap;
use rustc_hir as hir;
-use rustc_hir::def::{DefKind, Res};
-use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_ID};
+use rustc_hir::def::{DefKind, Namespace, Res};
+use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
use rustc_hir::hir_id::{HirIdMap, HirIdSet};
use rustc_hir::intravisit::{walk_expr, FnKind, Visitor};
use rustc_hir::LangItem::{OptionNone, ResultErr, ResultOk};
@@ -114,14 +118,14 @@ use rustc_target::abi::Integer;
use crate::consts::{constant, Constant};
use crate::ty::{can_partially_move_ty, expr_sig, is_copy, is_recursively_primitive_type, ty_is_fn_once_param};
-use crate::visitors::expr_visitor_no_bodies;
+use crate::visitors::for_each_expr;
pub fn parse_msrv(msrv: &str, sess: Option<&Session>, span: Option<Span>) -> Option<RustcVersion> {
if let Ok(version) = RustcVersion::parse(msrv) {
return Some(version);
} else if let Some(sess) = sess {
if let Some(span) = span {
- sess.span_err(span, &format!("`{}` is not a valid Rust version", msrv));
+ sess.span_err(span, format!("`{msrv}` is not a valid Rust version"));
}
}
None
@@ -212,7 +216,7 @@ pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<
/// }
/// ```
pub fn in_constant(cx: &LateContext<'_>, id: HirId) -> bool {
- let parent_id = cx.tcx.hir().get_parent_item(id);
+ let parent_id = cx.tcx.hir().get_parent_item(id).def_id;
match cx.tcx.hir().get_by_def_id(parent_id) {
Node::Item(&Item {
kind: ItemKind::Const(..) | ItemKind::Static(..),
@@ -239,19 +243,69 @@ pub fn in_constant(cx: &LateContext<'_>, id: HirId) -> bool {
}
}
-/// Checks if a `QPath` resolves to a constructor of a `LangItem`.
+/// Checks if a `Res` refers to a constructor of a `LangItem`
/// For example, use this to check whether a function call or a pattern is `Some(..)`.
-pub fn is_lang_ctor(cx: &LateContext<'_>, qpath: &QPath<'_>, lang_item: LangItem) -> bool {
+pub fn is_res_lang_ctor(cx: &LateContext<'_>, res: Res, lang_item: LangItem) -> bool {
+ if let Res::Def(DefKind::Ctor(..), id) = res
+ && let Ok(lang_id) = cx.tcx.lang_items().require(lang_item)
+ && let Some(id) = cx.tcx.opt_parent(id)
+ {
+ id == lang_id
+ } else {
+ false
+ }
+}
+
+pub fn is_res_diagnostic_ctor(cx: &LateContext<'_>, res: Res, diag_item: Symbol) -> bool {
+ if let Res::Def(DefKind::Ctor(..), id) = res
+ && let Some(id) = cx.tcx.opt_parent(id)
+ {
+ cx.tcx.is_diagnostic_item(diag_item, id)
+ } else {
+ false
+ }
+}
+
+/// Checks if a `QPath` resolves to a constructor of a diagnostic item.
+pub fn is_diagnostic_ctor(cx: &LateContext<'_>, qpath: &QPath<'_>, diagnostic_item: Symbol) -> bool {
if let QPath::Resolved(_, path) = qpath {
if let Res::Def(DefKind::Ctor(..), ctor_id) = path.res {
- if let Ok(item_id) = cx.tcx.lang_items().require(lang_item) {
- return cx.tcx.parent(ctor_id) == item_id;
- }
+ return cx.tcx.is_diagnostic_item(diagnostic_item, cx.tcx.parent(ctor_id));
}
}
false
}
+/// Checks if the `DefId` matches the given diagnostic item or it's constructor.
+pub fn is_diagnostic_item_or_ctor(cx: &LateContext<'_>, did: DefId, item: Symbol) -> bool {
+ let did = match cx.tcx.def_kind(did) {
+ DefKind::Ctor(..) => cx.tcx.parent(did),
+ // Constructors for types in external crates seem to have `DefKind::Variant`
+ DefKind::Variant => match cx.tcx.opt_parent(did) {
+ Some(did) if matches!(cx.tcx.def_kind(did), DefKind::Variant) => did,
+ _ => did,
+ },
+ _ => did,
+ };
+
+ cx.tcx.is_diagnostic_item(item, did)
+}
+
+/// Checks if the `DefId` matches the given `LangItem` or it's constructor.
+pub fn is_lang_item_or_ctor(cx: &LateContext<'_>, did: DefId, item: LangItem) -> bool {
+ let did = match cx.tcx.def_kind(did) {
+ DefKind::Ctor(..) => cx.tcx.parent(did),
+ // Constructors for types in external crates seem to have `DefKind::Variant`
+ DefKind::Variant => match cx.tcx.opt_parent(did) {
+ Some(did) if matches!(cx.tcx.def_kind(did), DefKind::Variant) => did,
+ _ => did,
+ },
+ _ => did,
+ };
+
+ cx.tcx.lang_items().require(item).map_or(false, |id| id == did)
+}
+
pub fn is_unit_expr(expr: &Expr<'_>) -> bool {
matches!(
expr.kind,
@@ -471,15 +525,49 @@ pub fn path_def_id<'tcx>(cx: &LateContext<'_>, maybe_path: &impl MaybePath<'tcx>
path_res(cx, maybe_path).opt_def_id()
}
-/// Resolves a def path like `std::vec::Vec`.
+fn find_primitive<'tcx>(tcx: TyCtxt<'tcx>, name: &str) -> impl Iterator<Item = DefId> + 'tcx {
+ let single = |ty| tcx.incoherent_impls(ty).iter().copied();
+ let empty = || [].iter().copied();
+ match name {
+ "bool" => single(BoolSimplifiedType),
+ "char" => single(CharSimplifiedType),
+ "str" => single(StrSimplifiedType),
+ "array" => single(ArraySimplifiedType),
+ "slice" => single(SliceSimplifiedType),
+ // FIXME: rustdoc documents these two using just `pointer`.
+ //
+ // Maybe this is something we should do here too.
+ "const_ptr" => single(PtrSimplifiedType(Mutability::Not)),
+ "mut_ptr" => single(PtrSimplifiedType(Mutability::Mut)),
+ "isize" => single(IntSimplifiedType(IntTy::Isize)),
+ "i8" => single(IntSimplifiedType(IntTy::I8)),
+ "i16" => single(IntSimplifiedType(IntTy::I16)),
+ "i32" => single(IntSimplifiedType(IntTy::I32)),
+ "i64" => single(IntSimplifiedType(IntTy::I64)),
+ "i128" => single(IntSimplifiedType(IntTy::I128)),
+ "usize" => single(UintSimplifiedType(UintTy::Usize)),
+ "u8" => single(UintSimplifiedType(UintTy::U8)),
+ "u16" => single(UintSimplifiedType(UintTy::U16)),
+ "u32" => single(UintSimplifiedType(UintTy::U32)),
+ "u64" => single(UintSimplifiedType(UintTy::U64)),
+ "u128" => single(UintSimplifiedType(UintTy::U128)),
+ "f32" => single(FloatSimplifiedType(FloatTy::F32)),
+ "f64" => single(FloatSimplifiedType(FloatTy::F64)),
+ _ => empty(),
+ }
+}
+
+/// Resolves a def path like `std::vec::Vec`. `namespace_hint` can be supplied to disambiguate
+/// between `std::vec` the module and `std::vec` the macro
+///
/// This function is expensive and should be used sparingly.
-pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
- fn item_child_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: &str) -> Option<Res> {
+pub fn def_path_res(cx: &LateContext<'_>, path: &[&str], namespace_hint: Option<Namespace>) -> Res {
+ fn item_child_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: &str, matches_ns: impl Fn(Res) -> bool) -> Option<Res> {
match tcx.def_kind(def_id) {
DefKind::Mod | DefKind::Enum | DefKind::Trait => tcx
.module_children(def_id)
.iter()
- .find(|item| item.ident.name.as_str() == name)
+ .find(|item| item.ident.name.as_str() == name && matches_ns(item.res.expect_non_local()))
.map(|child| child.res.expect_non_local()),
DefKind::Impl => tcx
.associated_item_def_ids(def_id)
@@ -487,40 +575,17 @@ pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
.copied()
.find(|assoc_def_id| tcx.item_name(*assoc_def_id).as_str() == name)
.map(|assoc_def_id| Res::Def(tcx.def_kind(assoc_def_id), assoc_def_id)),
+ DefKind::Struct | DefKind::Union => tcx
+ .adt_def(def_id)
+ .non_enum_variant()
+ .fields
+ .iter()
+ .find(|f| f.name.as_str() == name)
+ .map(|f| Res::Def(DefKind::Field, f.did)),
_ => None,
}
}
- fn find_primitive<'tcx>(tcx: TyCtxt<'tcx>, name: &str) -> impl Iterator<Item = DefId> + 'tcx {
- let single = |ty| tcx.incoherent_impls(ty).iter().copied();
- let empty = || [].iter().copied();
- match name {
- "bool" => single(BoolSimplifiedType),
- "char" => single(CharSimplifiedType),
- "str" => single(StrSimplifiedType),
- "array" => single(ArraySimplifiedType),
- "slice" => single(SliceSimplifiedType),
- // FIXME: rustdoc documents these two using just `pointer`.
- //
- // Maybe this is something we should do here too.
- "const_ptr" => single(PtrSimplifiedType(Mutability::Not)),
- "mut_ptr" => single(PtrSimplifiedType(Mutability::Mut)),
- "isize" => single(IntSimplifiedType(IntTy::Isize)),
- "i8" => single(IntSimplifiedType(IntTy::I8)),
- "i16" => single(IntSimplifiedType(IntTy::I16)),
- "i32" => single(IntSimplifiedType(IntTy::I32)),
- "i64" => single(IntSimplifiedType(IntTy::I64)),
- "i128" => single(IntSimplifiedType(IntTy::I128)),
- "usize" => single(UintSimplifiedType(UintTy::Usize)),
- "u8" => single(UintSimplifiedType(UintTy::U8)),
- "u16" => single(UintSimplifiedType(UintTy::U16)),
- "u32" => single(UintSimplifiedType(UintTy::U32)),
- "u64" => single(UintSimplifiedType(UintTy::U64)),
- "u128" => single(UintSimplifiedType(UintTy::U128)),
- "f32" => single(FloatSimplifiedType(FloatTy::F32)),
- "f64" => single(FloatSimplifiedType(FloatTy::F64)),
- _ => empty(),
- }
- }
+
fn find_crate(tcx: TyCtxt<'_>, name: &str) -> Option<DefId> {
tcx.crates(())
.iter()
@@ -529,32 +594,45 @@ pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
.map(CrateNum::as_def_id)
}
- let (base, first, path) = match *path {
- [base, first, ref path @ ..] => (base, first, path),
+ let (base, path) = match *path {
[primitive] => {
return PrimTy::from_name(Symbol::intern(primitive)).map_or(Res::Err, Res::PrimTy);
},
+ [base, ref path @ ..] => (base, path),
_ => return Res::Err,
};
let tcx = cx.tcx;
let starts = find_primitive(tcx, base)
.chain(find_crate(tcx, base))
- .filter_map(|id| item_child_by_name(tcx, id, first));
+ .map(|id| Res::Def(tcx.def_kind(id), id));
for first in starts {
let last = path
.iter()
.copied()
+ .enumerate()
// for each segment, find the child item
- .try_fold(first, |res, segment| {
+ .try_fold(first, |res, (idx, segment)| {
+ let matches_ns = |res: Res| {
+ // If at the last segment in the path, respect the namespace hint
+ if idx == path.len() - 1 {
+ match namespace_hint {
+ Some(ns) => res.matches_ns(ns),
+ None => true,
+ }
+ } else {
+ res.matches_ns(Namespace::TypeNS)
+ }
+ };
+
let def_id = res.def_id();
- if let Some(item) = item_child_by_name(tcx, def_id, segment) {
+ if let Some(item) = item_child_by_name(tcx, def_id, segment, matches_ns) {
Some(item)
} else if matches!(res, Res::Def(DefKind::Enum | DefKind::Struct, _)) {
// it is not a child item so check inherent impl items
tcx.inherent_impls(def_id)
.iter()
- .find_map(|&impl_def_id| item_child_by_name(tcx, impl_def_id, segment))
+ .find_map(|&impl_def_id| item_child_by_name(tcx, impl_def_id, segment, matches_ns))
} else {
None
}
@@ -570,8 +648,10 @@ pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Res {
/// Convenience function to get the `DefId` of a trait by path.
/// It could be a trait or trait alias.
+///
+/// This function is expensive and should be used sparingly.
pub fn get_trait_def_id(cx: &LateContext<'_>, path: &[&str]) -> Option<DefId> {
- match def_path_res(cx, path) {
+ match def_path_res(cx, path, Some(Namespace::TypeNS)) {
Res::Def(DefKind::Trait | DefKind::TraitAlias, trait_id) => Some(trait_id),
_ => None,
}
@@ -597,8 +677,8 @@ pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, def_id: LocalDefId) ->
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
let parent_impl = cx.tcx.hir().get_parent_item(hir_id);
if_chain! {
- if parent_impl != CRATE_DEF_ID;
- if let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent_impl);
+ if parent_impl != hir::CRATE_OWNER_ID;
+ if let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent_impl.def_id);
if let hir::ItemKind::Impl(impl_) = &item.kind;
then {
return impl_.of_trait.as_ref();
@@ -738,13 +818,37 @@ pub fn is_default_equivalent(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
false
}
},
- ExprKind::Call(repl_func, _) => is_default_equivalent_call(cx, repl_func),
- ExprKind::Path(qpath) => is_lang_ctor(cx, qpath, OptionNone),
+ ExprKind::Call(repl_func, []) => is_default_equivalent_call(cx, repl_func),
+ ExprKind::Call(from_func, [ref arg]) => is_default_equivalent_from(cx, from_func, arg),
+ ExprKind::Path(qpath) => is_res_lang_ctor(cx, cx.qpath_res(qpath, e.hir_id), OptionNone),
ExprKind::AddrOf(rustc_hir::BorrowKind::Ref, _, expr) => matches!(expr.kind, ExprKind::Array([])),
_ => false,
}
}
+fn is_default_equivalent_from(cx: &LateContext<'_>, from_func: &Expr<'_>, arg: &Expr<'_>) -> bool {
+ if let ExprKind::Path(QPath::TypeRelative(ty, seg)) = from_func.kind &&
+ seg.ident.name == sym::from
+ {
+ match arg.kind {
+ ExprKind::Lit(hir::Lit {
+ node: LitKind::Str(ref sym, _),
+ ..
+ }) => return sym.is_empty() && is_path_diagnostic_item(cx, ty, sym::String),
+ ExprKind::Array([]) => return is_path_diagnostic_item(cx, ty, sym::Vec),
+ ExprKind::Repeat(_, ArrayLen::Body(len)) => {
+ if let ExprKind::Lit(ref const_lit) = cx.tcx.hir().body(len.body).value.kind &&
+ let LitKind::Int(v, _) = const_lit.node
+ {
+ return v == 0 && is_path_diagnostic_item(cx, ty, sym::Vec);
+ }
+ }
+ _ => (),
+ }
+ }
+ false
+}
+
/// Checks if the top level expression can be moved into a closure as is.
/// Currently checks for:
/// * Break/Continue outside the given loop HIR ids.
@@ -1104,7 +1208,7 @@ pub fn is_in_panic_handler(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
/// Gets the name of the item the expression is in, if available.
pub fn get_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Symbol> {
- let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id);
+ let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id).def_id;
match cx.tcx.hir().find_by_def_id(parent_id) {
Some(
Node::Item(Item { ident, .. })
@@ -1137,17 +1241,14 @@ pub fn contains_name(name: Symbol, expr: &Expr<'_>) -> bool {
/// Returns `true` if `expr` contains a return expression
pub fn contains_return(expr: &hir::Expr<'_>) -> bool {
- let mut found = false;
- expr_visitor_no_bodies(|expr| {
- if !found {
- if let hir::ExprKind::Ret(..) = &expr.kind {
- found = true;
- }
+ for_each_expr(expr, |e| {
+ if matches!(e.kind, hir::ExprKind::Ret(..)) {
+ ControlFlow::Break(())
+ } else {
+ ControlFlow::Continue(())
}
- !found
})
- .visit_expr(expr);
- found
+ .is_some()
}
/// Extends the span to the beginning of the spans line, incl. whitespaces.
@@ -1387,8 +1488,8 @@ pub fn is_integer_literal(expr: &Expr<'_>, value: u128) -> bool {
/// Examples of coercions can be found in the Nomicon at
/// <https://doc.rust-lang.org/nomicon/coercions.html>.
///
-/// See `rustc_middle::ty::adjustment::Adjustment` and `rustc_typeck::check::coercion` for more
-/// information on adjustments and coercions.
+/// See `rustc_middle::ty::adjustment::Adjustment` and `rustc_hir_analysis::check::coercion` for
+/// more information on adjustments and coercions.
pub fn is_adjusted(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
cx.typeck_results().adjustments().get(e.hir_id).is_some()
}
@@ -1536,7 +1637,7 @@ pub fn is_self(slf: &Param<'_>) -> bool {
pub fn is_self_ty(slf: &hir::Ty<'_>) -> bool {
if let TyKind::Path(QPath::Resolved(None, path)) = slf.kind {
- if let Res::SelfTy { .. } = path.res {
+ if let Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } = path.res {
return true;
}
}
@@ -1554,7 +1655,7 @@ pub fn is_try<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option<&'tc
if_chain! {
if let PatKind::TupleStruct(ref path, pat, ddpos) = arm.pat.kind;
if ddpos.as_opt_usize().is_none();
- if is_lang_ctor(cx, path, ResultOk);
+ if is_res_lang_ctor(cx, cx.qpath_res(path, arm.pat.hir_id), ResultOk);
if let PatKind::Binding(_, hir_id, _, None) = pat[0].kind;
if path_to_local_id(arm.body, hir_id);
then {
@@ -1566,7 +1667,7 @@ pub fn is_try<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option<&'tc
fn is_err(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
if let PatKind::TupleStruct(ref path, _, _) = arm.pat.kind {
- is_lang_ctor(cx, path, ResultErr)
+ is_res_lang_ctor(cx, cx.qpath_res(path, arm.pat.hir_id), ResultErr)
} else {
false
}
@@ -1648,7 +1749,7 @@ pub fn any_parent_has_attr(tcx: TyCtxt<'_>, node: HirId, symbol: Symbol) -> bool
return true;
}
prev_enclosing_node = Some(enclosing_node);
- enclosing_node = map.local_def_id_to_hir_id(map.get_parent_item(enclosing_node));
+ enclosing_node = map.get_parent_item(enclosing_node).into();
}
false
@@ -1665,6 +1766,7 @@ pub fn any_parent_is_automatically_derived(tcx: TyCtxt<'_>, node: HirId) -> bool
/// ```rust,ignore
/// if let Some(args) = match_function_call(cx, cmp_max_call, &paths::CMP_MAX);
/// ```
+/// This function is deprecated. Use [`match_function_call_with_def_id`].
pub fn match_function_call<'tcx>(
cx: &LateContext<'tcx>,
expr: &'tcx Expr<'_>,
@@ -1682,6 +1784,22 @@ pub fn match_function_call<'tcx>(
None
}
+pub fn match_function_call_with_def_id<'tcx>(
+ cx: &LateContext<'tcx>,
+ expr: &'tcx Expr<'_>,
+ fun_def_id: DefId,
+) -> Option<&'tcx [Expr<'tcx>]> {
+ if_chain! {
+ if let ExprKind::Call(fun, args) = expr.kind;
+ if let ExprKind::Path(ref qpath) = fun.kind;
+ if cx.qpath_res(qpath, fun.hir_id).opt_def_id() == Some(fun_def_id);
+ then {
+ return Some(args);
+ }
+ };
+ None
+}
+
/// Checks if the given `DefId` matches any of the paths. Returns the index of matching path, if
/// any.
///
@@ -1990,9 +2108,9 @@ pub fn fn_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<DefId> {
}
}
-/// Returns Option<String> where String is a textual representation of the type encapsulated in the
-/// slice iff the given expression is a slice of primitives (as defined in the
-/// `is_recursively_primitive_type` function) and None otherwise.
+/// Returns `Option<String>` where String is a textual representation of the type encapsulated in
+/// the slice iff the given expression is a slice of primitives (as defined in the
+/// `is_recursively_primitive_type` function) and `None` otherwise.
pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
let expr_type = cx.typeck_results().expr_ty_adjusted(expr);
let expr_kind = expr_type.kind();
@@ -2163,7 +2281,7 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalDefId, f: impl Fn(&[Symbol
Entry::Vacant(entry) => {
let mut names = Vec::new();
for id in tcx.hir().module_items(module) {
- if matches!(tcx.def_kind(id.def_id), DefKind::Const)
+ if matches!(tcx.def_kind(id.owner_id), DefKind::Const)
&& let item = tcx.hir().item(id)
&& let ItemKind::Const(ty, _body) = item.kind {
if let TyKind::Path(QPath::Resolved(_, path)) = ty.kind {
@@ -2296,6 +2414,29 @@ pub fn span_contains_comment(sm: &SourceMap, span: Span) -> bool {
});
}
+/// Return all the comments a given span contains
+/// Comments are returned wrapped with their relevant delimiters
+pub fn span_extract_comment(sm: &SourceMap, span: Span) -> String {
+ let snippet = sm.span_to_snippet(span).unwrap_or_default();
+ let mut comments_buf: Vec<String> = Vec::new();
+ let mut index: usize = 0;
+
+ for token in tokenize(&snippet) {
+ let token_range = index..(index + token.len as usize);
+ index += token.len as usize;
+ match token.kind {
+ TokenKind::BlockComment { .. } | TokenKind::LineComment { .. } => {
+ if let Some(comment) = snippet.get(token_range) {
+ comments_buf.push(comment.to_string());
+ }
+ },
+ _ => (),
+ }
+ }
+
+ comments_buf.join("\n")
+}
+
macro_rules! op_utils {
($($name:ident $assign:ident)*) => {
/// Binary operation traits like `LangItem::Add`
diff --git a/src/tools/clippy/clippy_utils/src/macros.rs b/src/tools/clippy/clippy_utils/src/macros.rs
index bd89ff977..9a682fbe6 100644
--- a/src/tools/clippy/clippy_utils/src/macros.rs
+++ b/src/tools/clippy/clippy_utils/src/macros.rs
@@ -2,13 +2,13 @@
use crate::is_path_diagnostic_item;
use crate::source::snippet_opt;
-use crate::visitors::expr_visitor_no_bodies;
+use crate::visitors::{for_each_expr, Descend};
use arrayvec::ArrayVec;
use itertools::{izip, Either, Itertools};
use rustc_ast::ast::LitKind;
-use rustc_hir::intravisit::Visitor;
-use rustc_hir::{self as hir, Expr, ExprKind, HirId, Node, QPath};
+use rustc_hir::intravisit::{walk_expr, Visitor};
+use rustc_hir::{self as hir, Expr, ExprField, ExprKind, HirId, Node, QPath};
use rustc_lexer::unescape::unescape_literal;
use rustc_lexer::{tokenize, unescape, LiteralKind, TokenKind};
use rustc_lint::LateContext;
@@ -16,6 +16,7 @@ use rustc_parse_format::{self as rpf, Alignment};
use rustc_span::def_id::DefId;
use rustc_span::hygiene::{self, MacroKind, SyntaxContext};
use rustc_span::{sym, BytePos, ExpnData, ExpnId, ExpnKind, Pos, Span, SpanData, Symbol};
+use std::iter::{once, zip};
use std::ops::ControlFlow;
const FORMAT_MACRO_DIAG_ITEMS: &[Symbol] = &[
@@ -270,20 +271,19 @@ fn find_assert_args_inner<'a, const N: usize>(
};
let mut args = ArrayVec::new();
let mut panic_expn = None;
- expr_visitor_no_bodies(|e| {
+ let _: Option<!> = for_each_expr(expr, |e| {
if args.is_full() {
if panic_expn.is_none() && e.span.ctxt() != expr.span.ctxt() {
panic_expn = PanicExpn::parse(cx, e);
}
- panic_expn.is_none()
+ ControlFlow::Continue(Descend::from(panic_expn.is_none()))
} else if is_assert_arg(cx, e, expn) {
args.push(e);
- false
+ ControlFlow::Continue(Descend::No)
} else {
- true
+ ControlFlow::Continue(Descend::Yes)
}
- })
- .visit_expr(expr);
+ });
let args = args.into_inner().ok()?;
// if no `panic!(..)` is found, use `PanicExpn::Empty`
// to indicate that the default assertion message is used
@@ -297,22 +297,19 @@ fn find_assert_within_debug_assert<'a>(
expn: ExpnId,
assert_name: Symbol,
) -> Option<(&'a Expr<'a>, ExpnId)> {
- let mut found = None;
- expr_visitor_no_bodies(|e| {
- if found.is_some() || !e.span.from_expansion() {
- return false;
+ for_each_expr(expr, |e| {
+ if !e.span.from_expansion() {
+ return ControlFlow::Continue(Descend::No);
}
let e_expn = e.span.ctxt().outer_expn();
if e_expn == expn {
- return true;
- }
- if e_expn.expn_data().macro_def_id.map(|id| cx.tcx.item_name(id)) == Some(assert_name) {
- found = Some((e, e_expn));
+ ControlFlow::Continue(Descend::Yes)
+ } else if e_expn.expn_data().macro_def_id.map(|id| cx.tcx.item_name(id)) == Some(assert_name) {
+ ControlFlow::Break((e, e_expn))
+ } else {
+ ControlFlow::Continue(Descend::No)
}
- false
})
- .visit_expr(expr);
- found
}
fn is_assert_arg(cx: &LateContext<'_>, expr: &Expr<'_>, assert_expn: ExpnId) -> bool {
@@ -392,20 +389,18 @@ impl FormatString {
unescape_literal(inner, mode, &mut |_, ch| match ch {
Ok(ch) => unescaped.push(ch),
Err(e) if !e.is_fatal() => (),
- Err(e) => panic!("{:?}", e),
+ Err(e) => panic!("{e:?}"),
});
let mut parts = Vec::new();
- expr_visitor_no_bodies(|expr| {
- if let ExprKind::Lit(lit) = &expr.kind {
- if let LitKind::Str(symbol, _) = lit.node {
- parts.push(symbol);
- }
+ let _: Option<!> = for_each_expr(pieces, |expr| {
+ if let ExprKind::Lit(lit) = &expr.kind
+ && let LitKind::Str(symbol, _) = lit.node
+ {
+ parts.push(symbol);
}
-
- true
- })
- .visit_expr(pieces);
+ ControlFlow::Continue(())
+ });
Some(Self {
span,
@@ -418,7 +413,8 @@ impl FormatString {
}
struct FormatArgsValues<'tcx> {
- /// See `FormatArgsExpn::value_args`
+ /// Values passed after the format string and implicit captures. `[1, z + 2, x]` for
+ /// `format!("{x} {} {}", 1, z + 2)`.
value_args: Vec<&'tcx Expr<'tcx>>,
/// Maps an `rt::v1::Argument::position` or an `rt::v1::Count::Param` to its index in
/// `value_args`
@@ -431,7 +427,7 @@ impl<'tcx> FormatArgsValues<'tcx> {
fn new(args: &'tcx Expr<'tcx>, format_string_span: SpanData) -> Self {
let mut pos_to_value_index = Vec::new();
let mut value_args = Vec::new();
- expr_visitor_no_bodies(|expr| {
+ let _: Option<!> = for_each_expr(args, |expr| {
if expr.span.ctxt() == args.span.ctxt() {
// ArgumentV1::new_<format_trait>(<val>)
// ArgumentV1::from_usize(<val>)
@@ -453,16 +449,13 @@ impl<'tcx> FormatArgsValues<'tcx> {
pos_to_value_index.push(val_idx);
}
-
- true
+ ControlFlow::Continue(Descend::Yes)
} else {
// assume that any expr with a differing span is a value
value_args.push(expr);
-
- false
+ ControlFlow::Continue(Descend::No)
}
- })
- .visit_expr(args);
+ });
Self {
value_args,
@@ -485,64 +478,49 @@ struct ParamPosition {
precision: Option<usize>,
}
-/// Parses the `fmt` arg of `Arguments::new_v1_formatted(pieces, args, fmt, _)`
-fn parse_rt_fmt<'tcx>(fmt_arg: &'tcx Expr<'tcx>) -> Option<impl Iterator<Item = ParamPosition> + 'tcx> {
- fn parse_count(expr: &Expr<'_>) -> Option<usize> {
- // ::core::fmt::rt::v1::Count::Param(1usize),
- if let ExprKind::Call(ctor, [val]) = expr.kind
- && let ExprKind::Path(QPath::Resolved(_, path)) = ctor.kind
- && path.segments.last()?.ident.name == sym::Param
- && let ExprKind::Lit(lit) = &val.kind
- && let LitKind::Int(pos, _) = lit.node
- {
- Some(pos as usize)
- } else {
- None
+impl<'tcx> Visitor<'tcx> for ParamPosition {
+ fn visit_expr_field(&mut self, field: &'tcx ExprField<'tcx>) {
+ fn parse_count(expr: &Expr<'_>) -> Option<usize> {
+ // ::core::fmt::rt::v1::Count::Param(1usize),
+ if let ExprKind::Call(ctor, [val]) = expr.kind
+ && let ExprKind::Path(QPath::Resolved(_, path)) = ctor.kind
+ && path.segments.last()?.ident.name == sym::Param
+ && let ExprKind::Lit(lit) = &val.kind
+ && let LitKind::Int(pos, _) = lit.node
+ {
+ Some(pos as usize)
+ } else {
+ None
+ }
+ }
+
+ match field.ident.name {
+ sym::position => {
+ if let ExprKind::Lit(lit) = &field.expr.kind
+ && let LitKind::Int(pos, _) = lit.node
+ {
+ self.value = pos as usize;
+ }
+ },
+ sym::precision => {
+ self.precision = parse_count(field.expr);
+ },
+ sym::width => {
+ self.width = parse_count(field.expr);
+ },
+ _ => walk_expr(self, field.expr),
}
}
+}
+/// Parses the `fmt` arg of `Arguments::new_v1_formatted(pieces, args, fmt, _)`
+fn parse_rt_fmt<'tcx>(fmt_arg: &'tcx Expr<'tcx>) -> Option<impl Iterator<Item = ParamPosition> + 'tcx> {
if let ExprKind::AddrOf(.., array) = fmt_arg.kind
&& let ExprKind::Array(specs) = array.kind
{
Some(specs.iter().map(|spec| {
let mut position = ParamPosition::default();
-
- // ::core::fmt::rt::v1::Argument {
- // position: 0usize,
- // format: ::core::fmt::rt::v1::FormatSpec {
- // ..
- // precision: ::core::fmt::rt::v1::Count::Implied,
- // width: ::core::fmt::rt::v1::Count::Implied,
- // },
- // }
-
- // TODO: this can be made much nicer next sync with `Visitor::visit_expr_field`
- if let ExprKind::Struct(_, fields, _) = spec.kind {
- for field in fields {
- match (field.ident.name, &field.expr.kind) {
- (sym::position, ExprKind::Lit(lit)) => {
- if let LitKind::Int(pos, _) = lit.node {
- position.value = pos as usize;
- }
- },
- (sym::format, &ExprKind::Struct(_, spec_fields, _)) => {
- for spec_field in spec_fields {
- match spec_field.ident.name {
- sym::precision => {
- position.precision = parse_count(spec_field.expr);
- },
- sym::width => {
- position.width = parse_count(spec_field.expr);
- },
- _ => {},
- }
- }
- },
- _ => {},
- }
- }
- }
-
+ position.visit_expr(spec);
position
}))
} else {
@@ -560,19 +538,32 @@ fn span_from_inner(base: SpanData, inner: rpf::InnerSpan) -> Span {
)
}
+/// How a format parameter is used in the format string
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum FormatParamKind {
/// An implicit parameter , such as `{}` or `{:?}`.
Implicit,
- /// A parameter with an explicit number, or an asterisk precision. e.g. `{1}`, `{0:?}`,
- /// `{:.0$}` or `{:.*}`.
+ /// A parameter with an explicit number, e.g. `{1}`, `{0:?}`, or `{:.0$}`
Numbered,
+ /// A parameter with an asterisk precision. e.g. `{:.*}`.
+ Starred,
/// A named parameter with a named `value_arg`, such as the `x` in `format!("{x}", x = 1)`.
Named(Symbol),
/// An implicit named parameter, such as the `y` in `format!("{y}")`.
NamedInline(Symbol),
}
+/// Where a format parameter is being used in the format string
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
+pub enum FormatParamUsage {
+ /// Appears as an argument, e.g. `format!("{}", foo)`
+ Argument,
+ /// Appears as a width, e.g. `format!("{:width$}", foo, width = 1)`
+ Width,
+ /// Appears as a precision, e.g. `format!("{:.precision$}", foo, precision = 1)`
+ Precision,
+}
+
/// A `FormatParam` is any place in a `FormatArgument` that refers to a supplied value, e.g.
///
/// ```
@@ -588,6 +579,8 @@ pub struct FormatParam<'tcx> {
pub value: &'tcx Expr<'tcx>,
/// How this parameter refers to its `value`.
pub kind: FormatParamKind,
+ /// Where this format param is being used - argument/width/precision
+ pub usage: FormatParamUsage,
/// Span of the parameter, may be zero width. Includes the whitespace of implicit parameters.
///
/// ```text
@@ -600,6 +593,7 @@ pub struct FormatParam<'tcx> {
impl<'tcx> FormatParam<'tcx> {
fn new(
mut kind: FormatParamKind,
+ usage: FormatParamUsage,
position: usize,
inner: rpf::InnerSpan,
values: &FormatArgsValues<'tcx>,
@@ -614,7 +608,12 @@ impl<'tcx> FormatParam<'tcx> {
kind = FormatParamKind::NamedInline(name);
}
- Some(Self { value, kind, span })
+ Some(Self {
+ value,
+ kind,
+ usage,
+ span,
+ })
}
}
@@ -628,33 +627,48 @@ pub enum Count<'tcx> {
/// `FormatParamKind::Numbered`.
Param(FormatParam<'tcx>),
/// Not specified.
- Implied,
+ Implied(Option<Span>),
}
impl<'tcx> Count<'tcx> {
fn new(
+ usage: FormatParamUsage,
count: rpf::Count<'_>,
position: Option<usize>,
inner: Option<rpf::InnerSpan>,
values: &FormatArgsValues<'tcx>,
) -> Option<Self> {
+ let span = inner.map(|inner| span_from_inner(values.format_string_span, inner));
+
Some(match count {
- rpf::Count::CountIs(val) => Self::Is(val, span_from_inner(values.format_string_span, inner?)),
- rpf::Count::CountIsName(name, span) => Self::Param(FormatParam::new(
+ rpf::Count::CountIs(val) => Self::Is(val, span?),
+ rpf::Count::CountIsName(name, _) => Self::Param(FormatParam::new(
FormatParamKind::Named(Symbol::intern(name)),
+ usage,
position?,
- span,
+ inner?,
values,
)?),
- rpf::Count::CountIsParam(_) | rpf::Count::CountIsStar(_) => {
- Self::Param(FormatParam::new(FormatParamKind::Numbered, position?, inner?, values)?)
- },
- rpf::Count::CountImplied => Self::Implied,
+ rpf::Count::CountIsParam(_) => Self::Param(FormatParam::new(
+ FormatParamKind::Numbered,
+ usage,
+ position?,
+ inner?,
+ values,
+ )?),
+ rpf::Count::CountIsStar(_) => Self::Param(FormatParam::new(
+ FormatParamKind::Starred,
+ usage,
+ position?,
+ inner?,
+ values,
+ )?),
+ rpf::Count::CountImplied => Self::Implied(span),
})
}
pub fn is_implied(self) -> bool {
- matches!(self, Count::Implied)
+ matches!(self, Count::Implied(_))
}
pub fn param(self) -> Option<FormatParam<'tcx>> {
@@ -663,6 +677,14 @@ impl<'tcx> Count<'tcx> {
_ => None,
}
}
+
+ pub fn span(self) -> Option<Span> {
+ match self {
+ Count::Is(_, span) => Some(span),
+ Count::Param(param) => Some(param.span),
+ Count::Implied(span) => span,
+ }
+ }
}
/// Specification for the formatting of an argument in the format string. See
@@ -691,8 +713,20 @@ impl<'tcx> FormatSpec<'tcx> {
fill: spec.fill,
align: spec.align,
flags: spec.flags,
- precision: Count::new(spec.precision, positions.precision, spec.precision_span, values)?,
- width: Count::new(spec.width, positions.width, spec.width_span, values)?,
+ precision: Count::new(
+ FormatParamUsage::Precision,
+ spec.precision,
+ positions.precision,
+ spec.precision_span,
+ values,
+ )?,
+ width: Count::new(
+ FormatParamUsage::Width,
+ spec.width,
+ positions.width,
+ spec.width_span,
+ values,
+ )?,
r#trait: match spec.ty {
"" => sym::Display,
"?" => sym::Debug,
@@ -711,9 +745,19 @@ impl<'tcx> FormatSpec<'tcx> {
})
}
- /// Returns true if this format spec would change the contents of a string when formatted
- pub fn has_string_formatting(&self) -> bool {
- self.r#trait != sym::Display || !self.width.is_implied() || !self.precision.is_implied()
+ /// Returns true if this format spec is unchanged from the default. e.g. returns true for `{}`,
+ /// `{foo}` and `{2}`, but false for `{:?}`, `{foo:5}` and `{3:.5}`
+ pub fn is_default(&self) -> bool {
+ self.r#trait == sym::Display && self.is_default_for_trait()
+ }
+
+ /// Has no other formatting specifiers than setting the format trait. returns true for `{}`,
+ /// `{foo}`, `{:?}`, but false for `{foo:5}`, `{3:.5?}`
+ pub fn is_default_for_trait(&self) -> bool {
+ self.width.is_implied()
+ && self.precision.is_implied()
+ && self.align == Alignment::AlignUnknown
+ && self.flags == 0
}
}
@@ -728,22 +772,108 @@ pub struct FormatArg<'tcx> {
pub span: Span,
}
+impl<'tcx> FormatArg<'tcx> {
+ /// Span of the `:` and format specifiers
+ ///
+ /// ```ignore
+ /// format!("{:.}"), format!("{foo:.}")
+ /// ^^ ^^
+ /// ```
+ pub fn format_span(&self) -> Span {
+ let base = self.span.data();
+
+ // `base.hi` is `{...}|`, subtract 1 byte (the length of '}') so that it points before the closing
+ // brace `{...|}`
+ Span::new(self.param.span.hi(), base.hi - BytePos(1), base.ctxt, base.parent)
+ }
+}
+
/// A parsed `format_args!` expansion.
#[derive(Debug)]
pub struct FormatArgsExpn<'tcx> {
/// The format string literal.
pub format_string: FormatString,
- // The format arguments, such as `{:?}`.
+ /// The format arguments, such as `{:?}`.
pub args: Vec<FormatArg<'tcx>>,
/// Has an added newline due to `println!()`/`writeln!()`/etc. The last format string part will
/// include this added newline.
pub newline: bool,
- /// Values passed after the format string and implicit captures. `[1, z + 2, x]` for
+ /// Spans of the commas between the format string and explicit values, excluding any trailing
+ /// comma
+ ///
+ /// ```ignore
+ /// format!("..", 1, 2, 3,)
+ /// // ^ ^ ^
+ /// ```
+ comma_spans: Vec<Span>,
+ /// Explicit values passed after the format string, ignoring implicit captures. `[1, z + 2]` for
/// `format!("{x} {} {y}", 1, z + 2)`.
- value_args: Vec<&'tcx Expr<'tcx>>,
+ explicit_values: Vec<&'tcx Expr<'tcx>>,
}
impl<'tcx> FormatArgsExpn<'tcx> {
+ /// Gets the spans of the commas inbetween the format string and explicit args, not including
+ /// any trailing comma
+ ///
+ /// ```ignore
+ /// format!("{} {}", a, b)
+ /// // ^ ^
+ /// ```
+ ///
+ /// Ensures that the format string and values aren't coming from a proc macro that sets the
+ /// output span to that of its input
+ fn comma_spans(cx: &LateContext<'_>, explicit_values: &[&Expr<'_>], fmt_span: Span) -> Option<Vec<Span>> {
+ // `format!("{} {} {c}", "one", "two", c = "three")`
+ // ^^^^^ ^^^^^ ^^^^^^^
+ let value_spans = explicit_values
+ .iter()
+ .map(|val| hygiene::walk_chain(val.span, fmt_span.ctxt()));
+
+ // `format!("{} {} {c}", "one", "two", c = "three")`
+ // ^^ ^^ ^^^^^^
+ let between_spans = once(fmt_span)
+ .chain(value_spans)
+ .tuple_windows()
+ .map(|(start, end)| start.between(end));
+
+ let mut comma_spans = Vec::new();
+ for between_span in between_spans {
+ let mut offset = 0;
+ let mut seen_comma = false;
+
+ for token in tokenize(&snippet_opt(cx, between_span)?) {
+ match token.kind {
+ TokenKind::LineComment { .. } | TokenKind::BlockComment { .. } | TokenKind::Whitespace => {},
+ TokenKind::Comma if !seen_comma => {
+ seen_comma = true;
+
+ let base = between_span.data();
+ comma_spans.push(Span::new(
+ base.lo + BytePos(offset),
+ base.lo + BytePos(offset + 1),
+ base.ctxt,
+ base.parent,
+ ));
+ },
+ // named arguments, `start_val, name = end_val`
+ // ^^^^^^^^^ between_span
+ TokenKind::Ident | TokenKind::Eq if seen_comma => {},
+ // An unexpected token usually indicates the format string or a value came from a proc macro output
+ // that sets the span of its output to an input, e.g. `println!(some_proc_macro!("input"), ..)` that
+ // emits a string literal with the span set to that of `"input"`
+ _ => return None,
+ }
+ offset += token.len;
+ }
+
+ if !seen_comma {
+ return None;
+ }
+ }
+
+ Some(comma_spans)
+ }
+
pub fn parse(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option<Self> {
let macro_name = macro_backtrace(expr.span)
.map(|macro_call| cx.tcx.item_name(macro_call.def_id))
@@ -807,6 +937,7 @@ impl<'tcx> FormatArgsExpn<'tcx> {
// NamedInline is handled by `FormatParam::new()`
rpf::Position::ArgumentNamed(name) => FormatParamKind::Named(Symbol::intern(name)),
},
+ FormatParamUsage::Argument,
position.value,
parsed_arg.position_span,
&values,
@@ -817,11 +948,22 @@ impl<'tcx> FormatArgsExpn<'tcx> {
})
.collect::<Option<Vec<_>>>()?;
+ let mut explicit_values = values.value_args;
+ // remove values generated for implicitly captured vars
+ let len = explicit_values
+ .iter()
+ .take_while(|val| !format_string.span.contains(val.span))
+ .count();
+ explicit_values.truncate(len);
+
+ let comma_spans = Self::comma_spans(cx, &explicit_values, format_string.span)?;
+
Some(Self {
format_string,
args,
- value_args: values.value_args,
newline,
+ comma_spans,
+ explicit_values,
})
} else {
None
@@ -829,27 +971,25 @@ impl<'tcx> FormatArgsExpn<'tcx> {
}
pub fn find_nested(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, expn_id: ExpnId) -> Option<Self> {
- let mut format_args = None;
- expr_visitor_no_bodies(|e| {
- if format_args.is_some() {
- return false;
- }
+ for_each_expr(expr, |e| {
let e_ctxt = e.span.ctxt();
if e_ctxt == expr.span.ctxt() {
- return true;
- }
- if e_ctxt.outer_expn().is_descendant_of(expn_id) {
- format_args = FormatArgsExpn::parse(cx, e);
+ ControlFlow::Continue(Descend::Yes)
+ } else if e_ctxt.outer_expn().is_descendant_of(expn_id) {
+ if let Some(args) = FormatArgsExpn::parse(cx, e) {
+ ControlFlow::Break(args)
+ } else {
+ ControlFlow::Continue(Descend::No)
+ }
+ } else {
+ ControlFlow::Continue(Descend::No)
}
- false
})
- .visit_expr(expr);
- format_args
}
/// Source callsite span of all inputs
pub fn inputs_span(&self) -> Span {
- match *self.value_args {
+ match *self.explicit_values {
[] => self.format_string.span,
[.., last] => self
.format_string
@@ -858,6 +998,22 @@ impl<'tcx> FormatArgsExpn<'tcx> {
}
}
+ /// Get the span of a value expanded to the previous comma, e.g. for the value `10`
+ ///
+ /// ```ignore
+ /// format("{}.{}", 10, 11)
+ /// // ^^^^
+ /// ```
+ pub fn value_with_prev_comma_span(&self, value_id: HirId) -> Option<Span> {
+ for (comma_span, value) in zip(&self.comma_spans, &self.explicit_values) {
+ if value.hir_id == value_id {
+ return Some(comma_span.to(hygiene::walk_chain(value.span, comma_span.ctxt())));
+ }
+ }
+
+ None
+ }
+
/// Iterator of all format params, both values and those referenced by `width`/`precision`s.
pub fn params(&'tcx self) -> impl Iterator<Item = FormatParam<'tcx>> {
self.args
diff --git a/src/tools/clippy/clippy_utils/src/mir/maybe_storage_live.rs b/src/tools/clippy/clippy_utils/src/mir/maybe_storage_live.rs
new file mode 100644
index 000000000..d262b335d
--- /dev/null
+++ b/src/tools/clippy/clippy_utils/src/mir/maybe_storage_live.rs
@@ -0,0 +1,52 @@
+use rustc_index::bit_set::BitSet;
+use rustc_middle::mir;
+use rustc_mir_dataflow::{AnalysisDomain, CallReturnPlaces, GenKill, GenKillAnalysis};
+
+/// Determines liveness of each local purely based on `StorageLive`/`Dead`.
+#[derive(Copy, Clone)]
+pub(super) struct MaybeStorageLive;
+
+impl<'tcx> AnalysisDomain<'tcx> for MaybeStorageLive {
+ type Domain = BitSet<mir::Local>;
+ const NAME: &'static str = "maybe_storage_live";
+
+ fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain {
+ // bottom = dead
+ BitSet::new_empty(body.local_decls.len())
+ }
+
+ fn initialize_start_block(&self, body: &mir::Body<'tcx>, state: &mut Self::Domain) {
+ for arg in body.args_iter() {
+ state.insert(arg);
+ }
+ }
+}
+
+impl<'tcx> GenKillAnalysis<'tcx> for MaybeStorageLive {
+ type Idx = mir::Local;
+
+ fn statement_effect(&self, trans: &mut impl GenKill<Self::Idx>, stmt: &mir::Statement<'tcx>, _: mir::Location) {
+ match stmt.kind {
+ mir::StatementKind::StorageLive(l) => trans.gen(l),
+ mir::StatementKind::StorageDead(l) => trans.kill(l),
+ _ => (),
+ }
+ }
+
+ fn terminator_effect(
+ &self,
+ _trans: &mut impl GenKill<Self::Idx>,
+ _terminator: &mir::Terminator<'tcx>,
+ _loc: mir::Location,
+ ) {
+ }
+
+ fn call_return_effect(
+ &self,
+ _trans: &mut impl GenKill<Self::Idx>,
+ _block: mir::BasicBlock,
+ _return_places: CallReturnPlaces<'_, 'tcx>,
+ ) {
+ // Nothing to do when a call returns successfully
+ }
+}
diff --git a/src/tools/clippy/clippy_utils/src/mir/mod.rs b/src/tools/clippy/clippy_utils/src/mir/mod.rs
new file mode 100644
index 000000000..818e603f6
--- /dev/null
+++ b/src/tools/clippy/clippy_utils/src/mir/mod.rs
@@ -0,0 +1,164 @@
+use rustc_hir::{Expr, HirId};
+use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
+use rustc_middle::mir::{
+ traversal, Body, InlineAsmOperand, Local, Location, Place, StatementKind, TerminatorKind, START_BLOCK,
+};
+use rustc_middle::ty::TyCtxt;
+
+mod maybe_storage_live;
+
+mod possible_borrower;
+pub use possible_borrower::PossibleBorrowerMap;
+
+mod possible_origin;
+
+mod transitive_relation;
+
+#[derive(Clone, Debug, Default)]
+pub struct LocalUsage {
+ /// The locations where the local is used, if any.
+ pub local_use_locs: Vec<Location>,
+ /// The locations where the local is consumed or mutated, if any.
+ pub local_consume_or_mutate_locs: Vec<Location>,
+}
+
+pub fn visit_local_usage(locals: &[Local], mir: &Body<'_>, location: Location) -> Option<Vec<LocalUsage>> {
+ let init = vec![
+ LocalUsage {
+ local_use_locs: Vec::new(),
+ local_consume_or_mutate_locs: Vec::new(),
+ };
+ locals.len()
+ ];
+
+ traversal::ReversePostorder::new(mir, location.block).try_fold(init, |usage, (tbb, tdata)| {
+ // Give up on loops
+ if tdata.terminator().successors().any(|s| s == location.block) {
+ return None;
+ }
+
+ let mut v = V {
+ locals,
+ location,
+ results: usage,
+ };
+ v.visit_basic_block_data(tbb, tdata);
+ Some(v.results)
+ })
+}
+
+struct V<'a> {
+ locals: &'a [Local],
+ location: Location,
+ results: Vec<LocalUsage>,
+}
+
+impl<'a, 'tcx> Visitor<'tcx> for V<'a> {
+ fn visit_place(&mut self, place: &Place<'tcx>, ctx: PlaceContext, loc: Location) {
+ if loc.block == self.location.block && loc.statement_index <= self.location.statement_index {
+ return;
+ }
+
+ let local = place.local;
+
+ for (i, self_local) in self.locals.iter().enumerate() {
+ if local == *self_local {
+ if !matches!(
+ ctx,
+ PlaceContext::MutatingUse(MutatingUseContext::Drop) | PlaceContext::NonUse(_)
+ ) {
+ self.results[i].local_use_locs.push(loc);
+ }
+ if matches!(
+ ctx,
+ PlaceContext::NonMutatingUse(NonMutatingUseContext::Move)
+ | PlaceContext::MutatingUse(MutatingUseContext::Borrow)
+ ) {
+ self.results[i].local_consume_or_mutate_locs.push(loc);
+ }
+ }
+ }
+ }
+}
+
+/// Convenience wrapper around `visit_local_usage`.
+pub fn used_exactly_once(mir: &rustc_middle::mir::Body<'_>, local: rustc_middle::mir::Local) -> Option<bool> {
+ visit_local_usage(
+ &[local],
+ mir,
+ Location {
+ block: START_BLOCK,
+ statement_index: 0,
+ },
+ )
+ .map(|mut vec| {
+ let LocalUsage { local_use_locs, .. } = vec.remove(0);
+ local_use_locs
+ .into_iter()
+ .filter(|location| !is_local_assignment(mir, local, *location))
+ .count()
+ == 1
+ })
+}
+
+/// Returns the `mir::Body` containing the node associated with `hir_id`.
+#[allow(clippy::module_name_repetitions)]
+pub fn enclosing_mir(tcx: TyCtxt<'_>, hir_id: HirId) -> &Body<'_> {
+ let body_owner_local_def_id = tcx.hir().enclosing_body_owner(hir_id);
+ tcx.optimized_mir(body_owner_local_def_id.to_def_id())
+}
+
+/// Tries to determine the `Local` corresponding to `expr`, if any.
+/// This function is expensive and should be used sparingly.
+pub fn expr_local(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> Option<Local> {
+ let mir = enclosing_mir(tcx, expr.hir_id);
+ mir.local_decls.iter_enumerated().find_map(|(local, local_decl)| {
+ if local_decl.source_info.span == expr.span {
+ Some(local)
+ } else {
+ None
+ }
+ })
+}
+
+/// Returns a vector of `mir::Location` where `local` is assigned.
+pub fn local_assignments(mir: &Body<'_>, local: Local) -> Vec<Location> {
+ let mut locations = Vec::new();
+ for (block, data) in mir.basic_blocks.iter_enumerated() {
+ for statement_index in 0..=data.statements.len() {
+ let location = Location { block, statement_index };
+ if is_local_assignment(mir, local, location) {
+ locations.push(location);
+ }
+ }
+ }
+ locations
+}
+
+// `is_local_assignment` is based on `is_place_assignment`:
+// https://github.com/rust-lang/rust/blob/b7413511dc85ec01ef4b91785f86614589ac6103/compiler/rustc_middle/src/mir/visit.rs#L1350
+fn is_local_assignment(mir: &Body<'_>, local: Local, location: Location) -> bool {
+ let Location { block, statement_index } = location;
+ let basic_block = &mir.basic_blocks[block];
+ if statement_index < basic_block.statements.len() {
+ let statement = &basic_block.statements[statement_index];
+ if let StatementKind::Assign(box (place, _)) = statement.kind {
+ place.as_local() == Some(local)
+ } else {
+ false
+ }
+ } else {
+ let terminator = basic_block.terminator();
+ match &terminator.kind {
+ TerminatorKind::Call { destination, .. } => destination.as_local() == Some(local),
+ TerminatorKind::InlineAsm { operands, .. } => operands.iter().any(|operand| {
+ if let InlineAsmOperand::Out { place: Some(place), .. } = operand {
+ place.as_local() == Some(local)
+ } else {
+ false
+ }
+ }),
+ _ => false,
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_utils/src/mir/possible_borrower.rs b/src/tools/clippy/clippy_utils/src/mir/possible_borrower.rs
new file mode 100644
index 000000000..25717bf3d
--- /dev/null
+++ b/src/tools/clippy/clippy_utils/src/mir/possible_borrower.rs
@@ -0,0 +1,241 @@
+use super::{
+ maybe_storage_live::MaybeStorageLive, possible_origin::PossibleOriginVisitor,
+ transitive_relation::TransitiveRelation,
+};
+use crate::ty::is_copy;
+use rustc_data_structures::fx::FxHashMap;
+use rustc_index::bit_set::{BitSet, HybridBitSet};
+use rustc_lint::LateContext;
+use rustc_middle::mir::{self, visit::Visitor as _, Mutability};
+use rustc_middle::ty::{self, visit::TypeVisitor};
+use rustc_mir_dataflow::{Analysis, ResultsCursor};
+use std::ops::ControlFlow;
+
+/// Collects the possible borrowers of each local.
+/// For example, `b = &a; c = &a;` will make `b` and (transitively) `c`
+/// possible borrowers of `a`.
+#[allow(clippy::module_name_repetitions)]
+struct PossibleBorrowerVisitor<'a, 'b, 'tcx> {
+ possible_borrower: TransitiveRelation,
+ body: &'b mir::Body<'tcx>,
+ cx: &'a LateContext<'tcx>,
+ possible_origin: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
+}
+
+impl<'a, 'b, 'tcx> PossibleBorrowerVisitor<'a, 'b, 'tcx> {
+ fn new(
+ cx: &'a LateContext<'tcx>,
+ body: &'b mir::Body<'tcx>,
+ possible_origin: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
+ ) -> Self {
+ Self {
+ possible_borrower: TransitiveRelation::default(),
+ cx,
+ body,
+ possible_origin,
+ }
+ }
+
+ fn into_map(
+ self,
+ cx: &'a LateContext<'tcx>,
+ maybe_live: ResultsCursor<'b, 'tcx, MaybeStorageLive>,
+ ) -> PossibleBorrowerMap<'b, 'tcx> {
+ let mut map = FxHashMap::default();
+ for row in (1..self.body.local_decls.len()).map(mir::Local::from_usize) {
+ if is_copy(cx, self.body.local_decls[row].ty) {
+ continue;
+ }
+
+ let mut borrowers = self.possible_borrower.reachable_from(row, self.body.local_decls.len());
+ borrowers.remove(mir::Local::from_usize(0));
+ if !borrowers.is_empty() {
+ map.insert(row, borrowers);
+ }
+ }
+
+ let bs = BitSet::new_empty(self.body.local_decls.len());
+ PossibleBorrowerMap {
+ map,
+ maybe_live,
+ bitset: (bs.clone(), bs),
+ }
+ }
+}
+
+impl<'a, 'b, 'tcx> mir::visit::Visitor<'tcx> for PossibleBorrowerVisitor<'a, 'b, 'tcx> {
+ fn visit_assign(&mut self, place: &mir::Place<'tcx>, rvalue: &mir::Rvalue<'_>, _location: mir::Location) {
+ let lhs = place.local;
+ match rvalue {
+ mir::Rvalue::Ref(_, _, borrowed) => {
+ self.possible_borrower.add(borrowed.local, lhs);
+ },
+ other => {
+ if ContainsRegion
+ .visit_ty(place.ty(&self.body.local_decls, self.cx.tcx).ty)
+ .is_continue()
+ {
+ return;
+ }
+ rvalue_locals(other, |rhs| {
+ if lhs != rhs {
+ self.possible_borrower.add(rhs, lhs);
+ }
+ });
+ },
+ }
+ }
+
+ fn visit_terminator(&mut self, terminator: &mir::Terminator<'_>, _loc: mir::Location) {
+ if let mir::TerminatorKind::Call {
+ args,
+ destination: mir::Place { local: dest, .. },
+ ..
+ } = &terminator.kind
+ {
+ // TODO add doc
+ // If the call returns something with lifetimes,
+ // let's conservatively assume the returned value contains lifetime of all the arguments.
+ // For example, given `let y: Foo<'a> = foo(x)`, `y` is considered to be a possible borrower of `x`.
+
+ let mut immutable_borrowers = vec![];
+ let mut mutable_borrowers = vec![];
+
+ for op in args {
+ match op {
+ mir::Operand::Copy(p) | mir::Operand::Move(p) => {
+ if let ty::Ref(_, _, Mutability::Mut) = self.body.local_decls[p.local].ty.kind() {
+ mutable_borrowers.push(p.local);
+ } else {
+ immutable_borrowers.push(p.local);
+ }
+ },
+ mir::Operand::Constant(..) => (),
+ }
+ }
+
+ let mut mutable_variables: Vec<mir::Local> = mutable_borrowers
+ .iter()
+ .filter_map(|r| self.possible_origin.get(r))
+ .flat_map(HybridBitSet::iter)
+ .collect();
+
+ if ContainsRegion.visit_ty(self.body.local_decls[*dest].ty).is_break() {
+ mutable_variables.push(*dest);
+ }
+
+ for y in mutable_variables {
+ for x in &immutable_borrowers {
+ self.possible_borrower.add(*x, y);
+ }
+ for x in &mutable_borrowers {
+ self.possible_borrower.add(*x, y);
+ }
+ }
+ }
+ }
+}
+
+struct ContainsRegion;
+
+impl TypeVisitor<'_> for ContainsRegion {
+ type BreakTy = ();
+
+ fn visit_region(&mut self, _: ty::Region<'_>) -> ControlFlow<Self::BreakTy> {
+ ControlFlow::BREAK
+ }
+}
+
+fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) {
+ use rustc_middle::mir::Rvalue::{Aggregate, BinaryOp, Cast, CheckedBinaryOp, Repeat, UnaryOp, Use};
+
+ let mut visit_op = |op: &mir::Operand<'_>| match op {
+ mir::Operand::Copy(p) | mir::Operand::Move(p) => visit(p.local),
+ mir::Operand::Constant(..) => (),
+ };
+
+ match rvalue {
+ Use(op) | Repeat(op, _) | Cast(_, op, _) | UnaryOp(_, op) => visit_op(op),
+ Aggregate(_, ops) => ops.iter().for_each(visit_op),
+ BinaryOp(_, box (lhs, rhs)) | CheckedBinaryOp(_, box (lhs, rhs)) => {
+ visit_op(lhs);
+ visit_op(rhs);
+ },
+ _ => (),
+ }
+}
+
+/// Result of `PossibleBorrowerVisitor`.
+#[allow(clippy::module_name_repetitions)]
+pub struct PossibleBorrowerMap<'b, 'tcx> {
+ /// Mapping `Local -> its possible borrowers`
+ pub map: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
+ maybe_live: ResultsCursor<'b, 'tcx, MaybeStorageLive>,
+ // Caches to avoid allocation of `BitSet` on every query
+ pub bitset: (BitSet<mir::Local>, BitSet<mir::Local>),
+}
+
+impl<'a, 'b, 'tcx> PossibleBorrowerMap<'b, 'tcx> {
+ pub fn new(cx: &'a LateContext<'tcx>, mir: &'b mir::Body<'tcx>) -> Self {
+ let possible_origin = {
+ let mut vis = PossibleOriginVisitor::new(mir);
+ vis.visit_body(mir);
+ vis.into_map(cx)
+ };
+ let maybe_storage_live_result = MaybeStorageLive
+ .into_engine(cx.tcx, mir)
+ .pass_name("redundant_clone")
+ .iterate_to_fixpoint()
+ .into_results_cursor(mir);
+ let mut vis = PossibleBorrowerVisitor::new(cx, mir, possible_origin);
+ vis.visit_body(mir);
+ vis.into_map(cx, maybe_storage_live_result)
+ }
+
+ /// Returns true if the set of borrowers of `borrowed` living at `at` matches with `borrowers`.
+ pub fn only_borrowers(&mut self, borrowers: &[mir::Local], borrowed: mir::Local, at: mir::Location) -> bool {
+ self.bounded_borrowers(borrowers, borrowers, borrowed, at)
+ }
+
+ /// Returns true if the set of borrowers of `borrowed` living at `at` includes at least `below`
+ /// but no more than `above`.
+ pub fn bounded_borrowers(
+ &mut self,
+ below: &[mir::Local],
+ above: &[mir::Local],
+ borrowed: mir::Local,
+ at: mir::Location,
+ ) -> bool {
+ self.maybe_live.seek_after_primary_effect(at);
+
+ self.bitset.0.clear();
+ let maybe_live = &mut self.maybe_live;
+ if let Some(bitset) = self.map.get(&borrowed) {
+ for b in bitset.iter().filter(move |b| maybe_live.contains(*b)) {
+ self.bitset.0.insert(b);
+ }
+ } else {
+ return false;
+ }
+
+ self.bitset.1.clear();
+ for b in below {
+ self.bitset.1.insert(*b);
+ }
+
+ if !self.bitset.0.superset(&self.bitset.1) {
+ return false;
+ }
+
+ for b in above {
+ self.bitset.0.remove(*b);
+ }
+
+ self.bitset.0.is_empty()
+ }
+
+ pub fn local_is_alive_at(&mut self, local: mir::Local, at: mir::Location) -> bool {
+ self.maybe_live.seek_after_primary_effect(at);
+ self.maybe_live.contains(local)
+ }
+}
diff --git a/src/tools/clippy/clippy_utils/src/mir/possible_origin.rs b/src/tools/clippy/clippy_utils/src/mir/possible_origin.rs
new file mode 100644
index 000000000..8e7513d74
--- /dev/null
+++ b/src/tools/clippy/clippy_utils/src/mir/possible_origin.rs
@@ -0,0 +1,59 @@
+use super::transitive_relation::TransitiveRelation;
+use crate::ty::is_copy;
+use rustc_data_structures::fx::FxHashMap;
+use rustc_index::bit_set::HybridBitSet;
+use rustc_lint::LateContext;
+use rustc_middle::mir;
+
+/// Collect possible borrowed for every `&mut` local.
+/// For example, `_1 = &mut _2` generate _1: {_2,...}
+/// Known Problems: not sure all borrowed are tracked
+#[allow(clippy::module_name_repetitions)]
+pub(super) struct PossibleOriginVisitor<'a, 'tcx> {
+ possible_origin: TransitiveRelation,
+ body: &'a mir::Body<'tcx>,
+}
+
+impl<'a, 'tcx> PossibleOriginVisitor<'a, 'tcx> {
+ pub fn new(body: &'a mir::Body<'tcx>) -> Self {
+ Self {
+ possible_origin: TransitiveRelation::default(),
+ body,
+ }
+ }
+
+ pub fn into_map(self, cx: &LateContext<'tcx>) -> FxHashMap<mir::Local, HybridBitSet<mir::Local>> {
+ let mut map = FxHashMap::default();
+ for row in (1..self.body.local_decls.len()).map(mir::Local::from_usize) {
+ if is_copy(cx, self.body.local_decls[row].ty) {
+ continue;
+ }
+
+ let mut borrowers = self.possible_origin.reachable_from(row, self.body.local_decls.len());
+ borrowers.remove(mir::Local::from_usize(0));
+ if !borrowers.is_empty() {
+ map.insert(row, borrowers);
+ }
+ }
+ map
+ }
+}
+
+impl<'a, 'tcx> mir::visit::Visitor<'tcx> for PossibleOriginVisitor<'a, 'tcx> {
+ fn visit_assign(&mut self, place: &mir::Place<'tcx>, rvalue: &mir::Rvalue<'_>, _location: mir::Location) {
+ let lhs = place.local;
+ match rvalue {
+ // Only consider `&mut`, which can modify origin place
+ mir::Rvalue::Ref(_, rustc_middle::mir::BorrowKind::Mut { .. }, borrowed) |
+ // _2: &mut _;
+ // _3 = move _2
+ mir::Rvalue::Use(mir::Operand::Move(borrowed)) |
+ // _3 = move _2 as &mut _;
+ mir::Rvalue::Cast(_, mir::Operand::Move(borrowed), _)
+ => {
+ self.possible_origin.add(lhs, borrowed.local);
+ },
+ _ => {},
+ }
+ }
+}
diff --git a/src/tools/clippy/clippy_utils/src/mir/transitive_relation.rs b/src/tools/clippy/clippy_utils/src/mir/transitive_relation.rs
new file mode 100644
index 000000000..7fe296073
--- /dev/null
+++ b/src/tools/clippy/clippy_utils/src/mir/transitive_relation.rs
@@ -0,0 +1,29 @@
+use rustc_data_structures::fx::FxHashMap;
+use rustc_index::bit_set::HybridBitSet;
+use rustc_middle::mir;
+
+#[derive(Default)]
+pub(super) struct TransitiveRelation {
+ relations: FxHashMap<mir::Local, Vec<mir::Local>>,
+}
+
+impl TransitiveRelation {
+ pub fn add(&mut self, a: mir::Local, b: mir::Local) {
+ self.relations.entry(a).or_default().push(b);
+ }
+
+ pub fn reachable_from(&self, a: mir::Local, domain_size: usize) -> HybridBitSet<mir::Local> {
+ let mut seen = HybridBitSet::new_empty(domain_size);
+ let mut stack = vec![a];
+ while let Some(u) = stack.pop() {
+ if let Some(edges) = self.relations.get(&u) {
+ for &v in edges {
+ if seen.insert(v) {
+ stack.push(v);
+ }
+ }
+ }
+ }
+ seen
+ }
+}
diff --git a/src/tools/clippy/clippy_utils/src/msrvs.rs b/src/tools/clippy/clippy_utils/src/msrvs.rs
index 62020e21c..8b843732a 100644
--- a/src/tools/clippy/clippy_utils/src/msrvs.rs
+++ b/src/tools/clippy/clippy_utils/src/msrvs.rs
@@ -13,10 +13,11 @@ macro_rules! msrv_aliases {
// names may refer to stabilized feature flags or library items
msrv_aliases! {
1,62,0 { BOOL_THEN_SOME }
+ 1,58,0 { FORMAT_ARGS_CAPTURE }
1,53,0 { OR_PATTERNS, MANUAL_BITS, BTREE_MAP_RETAIN, BTREE_SET_RETAIN, ARRAY_INTO_ITERATOR }
1,52,0 { STR_SPLIT_ONCE, REM_EUCLID_CONST }
1,51,0 { BORROW_AS_PTR, UNSIGNED_ABS }
- 1,50,0 { BOOL_THEN }
+ 1,50,0 { BOOL_THEN, CLAMP }
1,47,0 { TAU }
1,46,0 { CONST_IF_MATCH }
1,45,0 { STR_STRIP_PREFIX }
diff --git a/src/tools/clippy/clippy_utils/src/numeric_literal.rs b/src/tools/clippy/clippy_utils/src/numeric_literal.rs
index 80098d976..c5dcd7b31 100644
--- a/src/tools/clippy/clippy_utils/src/numeric_literal.rs
+++ b/src/tools/clippy/clippy_utils/src/numeric_literal.rs
@@ -69,12 +69,13 @@ impl<'a> NumericLiteral<'a> {
#[must_use]
pub fn new(lit: &'a str, suffix: Option<&'a str>, float: bool) -> Self {
+ let unsigned_lit = lit.trim_start_matches('-');
// Determine delimiter for radix prefix, if present, and radix.
- let radix = if lit.starts_with("0x") {
+ let radix = if unsigned_lit.starts_with("0x") {
Radix::Hexadecimal
- } else if lit.starts_with("0b") {
+ } else if unsigned_lit.starts_with("0b") {
Radix::Binary
- } else if lit.starts_with("0o") {
+ } else if unsigned_lit.starts_with("0o") {
Radix::Octal
} else {
Radix::Decimal
diff --git a/src/tools/clippy/clippy_utils/src/paths.rs b/src/tools/clippy/clippy_utils/src/paths.rs
index 07170e2df..bc8514734 100644
--- a/src/tools/clippy/clippy_utils/src/paths.rs
+++ b/src/tools/clippy/clippy_utils/src/paths.rs
@@ -16,26 +16,17 @@ pub const APPLICABILITY_VALUES: [[&str; 3]; 4] = [
#[cfg(feature = "internal")]
pub const DIAGNOSTIC_BUILDER: [&str; 3] = ["rustc_errors", "diagnostic_builder", "DiagnosticBuilder"];
pub const ARC_PTR_EQ: [&str; 4] = ["alloc", "sync", "Arc", "ptr_eq"];
-pub const ASMUT_TRAIT: [&str; 3] = ["core", "convert", "AsMut"];
-pub const ASREF_TRAIT: [&str; 3] = ["core", "convert", "AsRef"];
pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"];
-pub const BTREEMAP_ENTRY: [&str; 6] = ["alloc", "collections", "btree", "map", "entry", "Entry"];
pub const BTREEMAP_INSERT: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "insert"];
pub const BTREESET_ITER: [&str; 6] = ["alloc", "collections", "btree", "set", "BTreeSet", "iter"];
pub const CLONE_TRAIT_METHOD: [&str; 4] = ["core", "clone", "Clone", "clone"];
-pub const COW: [&str; 3] = ["alloc", "borrow", "Cow"];
pub const CORE_ITER_COLLECT: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "collect"];
pub const CORE_ITER_CLONED: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "cloned"];
pub const CORE_ITER_COPIED: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "copied"];
pub const CORE_ITER_FILTER: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "filter"];
-pub const CORE_ITER_INTO_ITER: [&str; 6] = ["core", "iter", "traits", "collect", "IntoIterator", "into_iter"];
pub const CSTRING_AS_C_STR: [&str; 5] = ["alloc", "ffi", "c_str", "CString", "as_c_str"];
pub const DEFAULT_TRAIT_METHOD: [&str; 4] = ["core", "default", "Default", "default"];
pub const DEREF_MUT_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "DerefMut", "deref_mut"];
-/// Preferably use the diagnostic item `sym::deref_method` where possible
-pub const DEREF_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "Deref", "deref"];
-pub const DIR_BUILDER: [&str; 3] = ["std", "fs", "DirBuilder"];
-pub const DISPLAY_TRAIT: [&str; 3] = ["core", "fmt", "Display"];
#[cfg(feature = "internal")]
pub const EARLY_CONTEXT: [&str; 2] = ["rustc_lint", "EarlyContext"];
#[cfg(feature = "internal")]
@@ -43,32 +34,22 @@ pub const EARLY_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "EarlyLintPass"]
pub const EXIT: [&str; 3] = ["std", "process", "exit"];
pub const F32_EPSILON: [&str; 4] = ["core", "f32", "<impl f32>", "EPSILON"];
pub const F64_EPSILON: [&str; 4] = ["core", "f64", "<impl f64>", "EPSILON"];
-pub const FILE: [&str; 3] = ["std", "fs", "File"];
-pub const FILE_TYPE: [&str; 3] = ["std", "fs", "FileType"];
-pub const FROM_FROM: [&str; 4] = ["core", "convert", "From", "from"];
pub const FROM_ITERATOR_METHOD: [&str; 6] = ["core", "iter", "traits", "collect", "FromIterator", "from_iter"];
pub const FROM_STR_METHOD: [&str; 5] = ["core", "str", "traits", "FromStr", "from_str"];
-pub const FUTURE_FROM_GENERATOR: [&str; 3] = ["core", "future", "from_generator"];
#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
pub const FUTURES_IO_ASYNCREADEXT: [&str; 3] = ["futures_util", "io", "AsyncReadExt"];
#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
pub const FUTURES_IO_ASYNCWRITEEXT: [&str; 3] = ["futures_util", "io", "AsyncWriteExt"];
pub const HASHMAP_CONTAINS_KEY: [&str; 6] = ["std", "collections", "hash", "map", "HashMap", "contains_key"];
-pub const HASHMAP_ENTRY: [&str; 5] = ["std", "collections", "hash", "map", "Entry"];
pub const HASHMAP_INSERT: [&str; 6] = ["std", "collections", "hash", "map", "HashMap", "insert"];
pub const HASHSET_ITER: [&str; 6] = ["std", "collections", "hash", "set", "HashSet", "iter"];
#[cfg(feature = "internal")]
pub const IDENT: [&str; 3] = ["rustc_span", "symbol", "Ident"];
#[cfg(feature = "internal")]
pub const IDENT_AS_STR: [&str; 4] = ["rustc_span", "symbol", "Ident", "as_str"];
-pub const INDEX: [&str; 3] = ["core", "ops", "Index"];
-pub const INDEX_MUT: [&str; 3] = ["core", "ops", "IndexMut"];
pub const INSERT_STR: [&str; 4] = ["alloc", "string", "String", "insert_str"];
-pub const IO_READ: [&str; 3] = ["std", "io", "Read"];
-pub const IO_WRITE: [&str; 3] = ["std", "io", "Write"];
pub const ITER_COUNT: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "count"];
pub const ITER_EMPTY: [&str; 5] = ["core", "iter", "sources", "empty", "Empty"];
-pub const ITER_REPEAT: [&str; 5] = ["core", "iter", "sources", "repeat", "repeat"];
pub const ITERTOOLS_NEXT_TUPLE: [&str; 3] = ["itertools", "Itertools", "next_tuple"];
#[cfg(feature = "internal")]
pub const KW_MODULE: [&str; 3] = ["rustc_span", "symbol", "kw"];
@@ -79,13 +60,7 @@ pub const LATE_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "LateLintPass"];
#[cfg(feature = "internal")]
pub const LINT: [&str; 2] = ["rustc_lint_defs", "Lint"];
pub const MEM_SWAP: [&str; 3] = ["core", "mem", "swap"];
-pub const MUTEX_GUARD: [&str; 4] = ["std", "sync", "mutex", "MutexGuard"];
pub const OPEN_OPTIONS: [&str; 3] = ["std", "fs", "OpenOptions"];
-/// Preferably use the diagnostic item `sym::Option` where possible
-pub const OPTION: [&str; 3] = ["core", "option", "Option"];
-pub const OPTION_NONE: [&str; 4] = ["core", "option", "Option", "None"];
-pub const OPTION_SOME: [&str; 4] = ["core", "option", "Option", "Some"];
-pub const ORD: [&str; 3] = ["core", "cmp", "Ord"];
pub const OS_STRING_AS_OS_STR: [&str; 5] = ["std", "ffi", "os_str", "OsString", "as_os_str"];
pub const OS_STR_TO_OS_STRING: [&str; 5] = ["std", "ffi", "os_str", "OsStr", "to_os_string"];
pub const PARKING_LOT_MUTEX_GUARD: [&str; 3] = ["lock_api", "mutex", "MutexGuard"];
@@ -98,8 +73,6 @@ pub const PERMISSIONS: [&str; 3] = ["std", "fs", "Permissions"];
#[cfg_attr(not(unix), allow(clippy::invalid_paths))]
pub const PERMISSIONS_FROM_MODE: [&str; 6] = ["std", "os", "unix", "fs", "PermissionsExt", "from_mode"];
pub const POLL: [&str; 4] = ["core", "task", "poll", "Poll"];
-pub const POLL_PENDING: [&str; 5] = ["core", "task", "poll", "Poll", "Pending"];
-pub const POLL_READY: [&str; 5] = ["core", "task", "poll", "Poll", "Ready"];
pub const PTR_COPY: [&str; 3] = ["core", "intrinsics", "copy"];
pub const PTR_COPY_NONOVERLAPPING: [&str; 3] = ["core", "intrinsics", "copy_nonoverlapping"];
pub const PTR_EQ: [&str; 3] = ["core", "ptr", "eq"];
@@ -122,26 +95,14 @@ pub const RANGE_ARGUMENT_TRAIT: [&str; 3] = ["core", "ops", "RangeBounds"];
pub const RC_PTR_EQ: [&str; 4] = ["alloc", "rc", "Rc", "ptr_eq"];
pub const REFCELL_REF: [&str; 3] = ["core", "cell", "Ref"];
pub const REFCELL_REFMUT: [&str; 3] = ["core", "cell", "RefMut"];
-#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
pub const REGEX_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "unicode", "RegexBuilder", "new"];
-#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
pub const REGEX_BYTES_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "bytes", "RegexBuilder", "new"];
-#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
pub const REGEX_BYTES_NEW: [&str; 4] = ["regex", "re_bytes", "Regex", "new"];
-#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
pub const REGEX_BYTES_SET_NEW: [&str; 5] = ["regex", "re_set", "bytes", "RegexSet", "new"];
-#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
pub const REGEX_NEW: [&str; 4] = ["regex", "re_unicode", "Regex", "new"];
-#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
pub const REGEX_SET_NEW: [&str; 5] = ["regex", "re_set", "unicode", "RegexSet", "new"];
-/// Preferably use the diagnostic item `sym::Result` where possible
-pub const RESULT: [&str; 3] = ["core", "result", "Result"];
-pub const RESULT_ERR: [&str; 4] = ["core", "result", "Result", "Err"];
-pub const RESULT_OK: [&str; 4] = ["core", "result", "Result", "Ok"];
#[cfg(feature = "internal")]
pub const RUSTC_VERSION: [&str; 2] = ["rustc_semver", "RustcVersion"];
-pub const RWLOCK_READ_GUARD: [&str; 4] = ["std", "sync", "rwlock", "RwLockReadGuard"];
-pub const RWLOCK_WRITE_GUARD: [&str; 4] = ["std", "sync", "rwlock", "RwLockWriteGuard"];
pub const SERDE_DESERIALIZE: [&str; 3] = ["serde", "de", "Deserialize"];
pub const SERDE_DE_VISITOR: [&str; 3] = ["serde", "de", "Visitor"];
pub const SLICE_FROM_RAW_PARTS: [&str; 4] = ["core", "slice", "raw", "from_raw_parts"];
diff --git a/src/tools/clippy/clippy_utils/src/ptr.rs b/src/tools/clippy/clippy_utils/src/ptr.rs
index 0226f7490..88837d8a1 100644
--- a/src/tools/clippy/clippy_utils/src/ptr.rs
+++ b/src/tools/clippy/clippy_utils/src/ptr.rs
@@ -1,7 +1,7 @@
use crate::source::snippet;
-use crate::visitors::expr_visitor_no_bodies;
+use crate::visitors::{for_each_expr, Descend};
use crate::{path_to_local_id, strip_pat_refs};
-use rustc_hir::intravisit::Visitor;
+use core::ops::ControlFlow;
use rustc_hir::{Body, BodyId, ExprKind, HirId, PatKind};
use rustc_lint::LateContext;
use rustc_span::Span;
@@ -30,28 +30,23 @@ fn extract_clone_suggestions<'tcx>(
replace: &[(&'static str, &'static str)],
body: &'tcx Body<'_>,
) -> Option<Vec<(Span, Cow<'static, str>)>> {
- let mut abort = false;
let mut spans = Vec::new();
- expr_visitor_no_bodies(|expr| {
- if abort {
- return false;
- }
- if let ExprKind::MethodCall(seg, recv, [], _) = expr.kind {
- if path_to_local_id(recv, id) {
- if seg.ident.name.as_str() == "capacity" {
- abort = true;
- return false;
- }
- for &(fn_name, suffix) in replace {
- if seg.ident.name.as_str() == fn_name {
- spans.push((expr.span, snippet(cx, recv.span, "_") + suffix));
- return false;
- }
+ for_each_expr(body, |e| {
+ if let ExprKind::MethodCall(seg, recv, [], _) = e.kind
+ && path_to_local_id(recv, id)
+ {
+ if seg.ident.as_str() == "capacity" {
+ return ControlFlow::Break(());
+ }
+ for &(fn_name, suffix) in replace {
+ if seg.ident.as_str() == fn_name {
+ spans.push((e.span, snippet(cx, recv.span, "_") + suffix));
+ return ControlFlow::Continue(Descend::No);
}
}
}
- !abort
+ ControlFlow::Continue(Descend::Yes)
})
- .visit_body(body);
- if abort { None } else { Some(spans) }
+ .is_none()
+ .then_some(spans)
}
diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
index 8835b9329..45b63a4aa 100644
--- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
+++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
@@ -33,10 +33,10 @@ pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv:
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::Trait(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => continue,
- ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate),
- ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate),
- ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate),
- ty::PredicateKind::Coerce(_) => panic!("coerce predicate on function: {:#?}", predicate),
+ ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {predicate:#?}"),
+ ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {predicate:#?}"),
+ ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {predicate:#?}"),
+ ty::PredicateKind::Coerce(_) => panic!("coerce predicate on function: {predicate:#?}"),
}
}
match predicates.parent {
@@ -129,7 +129,12 @@ fn check_rvalue<'tcx>(
| Rvalue::Use(operand)
| Rvalue::Cast(
CastKind::PointerFromExposedAddress
- | CastKind::Misc
+ | CastKind::IntToInt
+ | CastKind::FloatToInt
+ | CastKind::IntToFloat
+ | CastKind::FloatToFloat
+ | CastKind::FnPtrToPtr
+ | CastKind::PtrToPtr
| CastKind::Pointer(PointerCast::MutToConstPointer | PointerCast::ArrayToPointer),
operand,
_,
@@ -260,6 +265,7 @@ fn check_place<'tcx>(tcx: TyCtxt<'tcx>, place: Place<'tcx>, span: Span, body: &B
}
},
ProjectionElem::ConstantIndex { .. }
+ | ProjectionElem::OpaqueCast(..)
| ProjectionElem::Downcast(..)
| ProjectionElem::Subslice { .. }
| ProjectionElem::Deref
@@ -318,8 +324,7 @@ fn check_terminator<'a, 'tcx>(
span,
format!(
"can only call other `const fn` within a `const fn`, \
- but `{:?}` is not stable as `const fn`",
- func,
+ but `{func:?}` is not stable as `const fn`",
)
.into(),
));
@@ -366,10 +371,23 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<RustcVersion>) -> bo
// Checking MSRV is manually necessary because `rustc` has no such concept. This entire
// function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`.
// as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.
+
+ // HACK(nilstrieb): CURRENT_RUSTC_VERSION can return versions like 1.66.0-dev. `rustc-semver`
+ // doesn't accept the `-dev` version number so we have to strip it
+ // off.
+ let short_version = since
+ .as_str()
+ .split('-')
+ .next()
+ .expect("rustc_attr::StabilityLevel::Stable::since` is empty");
+
+ let since = rustc_span::Symbol::intern(short_version);
+
crate::meets_msrv(
msrv,
- RustcVersion::parse(since.as_str())
- .expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"),
+ RustcVersion::parse(since.as_str()).unwrap_or_else(|err| {
+ panic!("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted: `{since}`, {err:?}")
+ }),
)
} else {
// Unstable const fn with the feature enabled.
diff --git a/src/tools/clippy/clippy_utils/src/source.rs b/src/tools/clippy/clippy_utils/src/source.rs
index d85f591fb..d28bd92d7 100644
--- a/src/tools/clippy/clippy_utils/src/source.rs
+++ b/src/tools/clippy/clippy_utils/src/source.rs
@@ -25,11 +25,11 @@ pub fn expr_block<'a, T: LintContext>(
if expr.span.from_expansion() {
Cow::Owned(format!("{{ {} }}", snippet_with_macro_callsite(cx, expr.span, default)))
} else if let ExprKind::Block(_, _) = expr.kind {
- Cow::Owned(format!("{}{}", code, string))
+ Cow::Owned(format!("{code}{string}"))
} else if string.is_empty() {
- Cow::Owned(format!("{{ {} }}", code))
+ Cow::Owned(format!("{{ {code} }}"))
} else {
- Cow::Owned(format!("{{\n{};\n{}\n}}", code, string))
+ Cow::Owned(format!("{{\n{code};\n{string}\n}}"))
}
}
@@ -392,6 +392,16 @@ pub fn trim_span(sm: &SourceMap, span: Span) -> Span {
.span()
}
+/// Expand a span to include a preceding comma
+/// ```rust,ignore
+/// writeln!(o, "") -> writeln!(o, "")
+/// ^^ ^^^^
+/// ```
+pub fn expand_past_previous_comma(cx: &LateContext<'_>, span: Span) -> Span {
+ let extended = cx.sess().source_map().span_extend_to_prev_char(span, ',', true);
+ extended.with_lo(extended.lo() - BytePos(1))
+}
+
#[cfg(test)]
mod test {
use super::{reindent_multiline, without_block_comments};
@@ -466,7 +476,7 @@ mod test {
#[test]
fn test_without_block_comments_lines_without_block_comments() {
let result = without_block_comments(vec!["/*", "", "*/"]);
- println!("result: {:?}", result);
+ println!("result: {result:?}");
assert!(result.is_empty());
let result = without_block_comments(vec!["", "/*", "", "*/", "#[crate_type = \"lib\"]", "/*", "", "*/", ""]);
diff --git a/src/tools/clippy/clippy_utils/src/sugg.rs b/src/tools/clippy/clippy_utils/src/sugg.rs
index cca71bbf7..aad7da61a 100644
--- a/src/tools/clippy/clippy_utils/src/sugg.rs
+++ b/src/tools/clippy/clippy_utils/src/sugg.rs
@@ -1,7 +1,9 @@
//! Contains utility functions to generate suggestions.
#![deny(clippy::missing_docs_in_private_items)]
-use crate::source::{snippet, snippet_opt, snippet_with_applicability, snippet_with_macro_callsite};
+use crate::source::{
+ snippet, snippet_opt, snippet_with_applicability, snippet_with_context, snippet_with_macro_callsite,
+};
use crate::ty::expr_sig;
use crate::{get_parent_expr_for_hir, higher};
use rustc_ast::util::parser::AssocOp;
@@ -10,19 +12,19 @@ use rustc_ast_pretty::pprust::token_kind_to_string;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::{Closure, ExprKind, HirId, MutTy, TyKind};
+use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{EarlyContext, LateContext, LintContext};
use rustc_middle::hir::place::ProjectionKind;
use rustc_middle::mir::{FakeReadCause, Mutability};
use rustc_middle::ty;
use rustc_span::source_map::{BytePos, CharPos, Pos, Span, SyntaxContext};
-use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
use std::borrow::Cow;
use std::fmt::{Display, Write as _};
use std::ops::{Add, Neg, Not, Sub};
/// A helper type to build suggestion correctly handling parentheses.
-#[derive(Clone, PartialEq)]
+#[derive(Clone, Debug, PartialEq)]
pub enum Sugg<'a> {
/// An expression that never needs parentheses such as `1337` or `[0; 42]`.
NonParen(Cow<'a, str>),
@@ -110,7 +112,7 @@ impl<'a> Sugg<'a> {
if expr.span.ctxt() == ctxt {
Self::hir_from_snippet(expr, |span| snippet(cx, span, default))
} else {
- let snip = snippet_with_applicability(cx, expr.span, default, applicability);
+ let (snip, _) = snippet_with_context(cx, expr.span, ctxt, default, applicability);
Sugg::NonParen(snip)
}
}
@@ -155,8 +157,8 @@ impl<'a> Sugg<'a> {
| hir::ExprKind::Ret(..)
| hir::ExprKind::Struct(..)
| hir::ExprKind::Tup(..)
- | hir::ExprKind::DropTemps(_)
| hir::ExprKind::Err => Sugg::NonParen(get_snippet(expr.span)),
+ hir::ExprKind::DropTemps(inner) => Self::hir_from_snippet(inner, get_snippet),
hir::ExprKind::Assign(lhs, rhs, _) => {
Sugg::BinOp(AssocOp::Assign, get_snippet(lhs.span), get_snippet(rhs.span))
},
@@ -177,11 +179,11 @@ impl<'a> Sugg<'a> {
pub fn ast(cx: &EarlyContext<'_>, expr: &ast::Expr, default: &'a str) -> Self {
use rustc_ast::ast::RangeLimits;
- let get_whole_snippet = || {
- if expr.span.from_expansion() {
- snippet_with_macro_callsite(cx, expr.span, default)
+ let snippet_without_expansion = |cx, span: Span, default| {
+ if span.from_expansion() {
+ snippet_with_macro_callsite(cx, span, default)
} else {
- snippet(cx, expr.span, default)
+ snippet(cx, span, default)
}
};
@@ -192,7 +194,7 @@ impl<'a> Sugg<'a> {
| ast::ExprKind::If(..)
| ast::ExprKind::Let(..)
| ast::ExprKind::Unary(..)
- | ast::ExprKind::Match(..) => Sugg::MaybeParen(get_whole_snippet()),
+ | ast::ExprKind::Match(..) => Sugg::MaybeParen(snippet_without_expansion(cx, expr.span, default)),
ast::ExprKind::Async(..)
| ast::ExprKind::Block(..)
| ast::ExprKind::Break(..)
@@ -221,41 +223,45 @@ impl<'a> Sugg<'a> {
| ast::ExprKind::Array(..)
| ast::ExprKind::While(..)
| ast::ExprKind::Await(..)
- | ast::ExprKind::Err => Sugg::NonParen(get_whole_snippet()),
+ | ast::ExprKind::Err => Sugg::NonParen(snippet_without_expansion(cx, expr.span, default)),
ast::ExprKind::Range(ref lhs, ref rhs, RangeLimits::HalfOpen) => Sugg::BinOp(
AssocOp::DotDot,
- lhs.as_ref().map_or("".into(), |lhs| snippet(cx, lhs.span, default)),
- rhs.as_ref().map_or("".into(), |rhs| snippet(cx, rhs.span, default)),
+ lhs.as_ref()
+ .map_or("".into(), |lhs| snippet_without_expansion(cx, lhs.span, default)),
+ rhs.as_ref()
+ .map_or("".into(), |rhs| snippet_without_expansion(cx, rhs.span, default)),
),
ast::ExprKind::Range(ref lhs, ref rhs, RangeLimits::Closed) => Sugg::BinOp(
AssocOp::DotDotEq,
- lhs.as_ref().map_or("".into(), |lhs| snippet(cx, lhs.span, default)),
- rhs.as_ref().map_or("".into(), |rhs| snippet(cx, rhs.span, default)),
+ lhs.as_ref()
+ .map_or("".into(), |lhs| snippet_without_expansion(cx, lhs.span, default)),
+ rhs.as_ref()
+ .map_or("".into(), |rhs| snippet_without_expansion(cx, rhs.span, default)),
),
ast::ExprKind::Assign(ref lhs, ref rhs, _) => Sugg::BinOp(
AssocOp::Assign,
- snippet(cx, lhs.span, default),
- snippet(cx, rhs.span, default),
+ snippet_without_expansion(cx, lhs.span, default),
+ snippet_without_expansion(cx, rhs.span, default),
),
ast::ExprKind::AssignOp(op, ref lhs, ref rhs) => Sugg::BinOp(
astbinop2assignop(op),
- snippet(cx, lhs.span, default),
- snippet(cx, rhs.span, default),
+ snippet_without_expansion(cx, lhs.span, default),
+ snippet_without_expansion(cx, rhs.span, default),
),
ast::ExprKind::Binary(op, ref lhs, ref rhs) => Sugg::BinOp(
AssocOp::from_ast_binop(op.node),
- snippet(cx, lhs.span, default),
- snippet(cx, rhs.span, default),
+ snippet_without_expansion(cx, lhs.span, default),
+ snippet_without_expansion(cx, rhs.span, default),
),
ast::ExprKind::Cast(ref lhs, ref ty) => Sugg::BinOp(
AssocOp::As,
- snippet(cx, lhs.span, default),
- snippet(cx, ty.span, default),
+ snippet_without_expansion(cx, lhs.span, default),
+ snippet_without_expansion(cx, ty.span, default),
),
ast::ExprKind::Type(ref lhs, ref ty) => Sugg::BinOp(
AssocOp::Colon,
- snippet(cx, lhs.span, default),
- snippet(cx, ty.span, default),
+ snippet_without_expansion(cx, lhs.span, default),
+ snippet_without_expansion(cx, ty.span, default),
),
}
}
@@ -306,19 +312,19 @@ impl<'a> Sugg<'a> {
/// Convenience method to transform suggestion into a return call
pub fn make_return(self) -> Sugg<'static> {
- Sugg::NonParen(Cow::Owned(format!("return {}", self)))
+ Sugg::NonParen(Cow::Owned(format!("return {self}")))
}
/// Convenience method to transform suggestion into a block
/// where the suggestion is a trailing expression
pub fn blockify(self) -> Sugg<'static> {
- Sugg::NonParen(Cow::Owned(format!("{{ {} }}", self)))
+ Sugg::NonParen(Cow::Owned(format!("{{ {self} }}")))
}
/// Convenience method to prefix the expression with the `async` keyword.
/// Can be used after `blockify` to create an async block.
pub fn asyncify(self) -> Sugg<'static> {
- Sugg::NonParen(Cow::Owned(format!("async {}", self)))
+ Sugg::NonParen(Cow::Owned(format!("async {self}")))
}
/// Convenience method to create the `<lhs>..<rhs>` or `<lhs>...<rhs>`
@@ -342,12 +348,12 @@ impl<'a> Sugg<'a> {
if has_enclosing_paren(&sugg) {
Sugg::MaybeParen(sugg)
} else {
- Sugg::NonParen(format!("({})", sugg).into())
+ Sugg::NonParen(format!("({sugg})").into())
}
},
Sugg::BinOp(op, lhs, rhs) => {
let sugg = binop_to_string(op, &lhs, &rhs);
- Sugg::NonParen(format!("({})", sugg).into())
+ Sugg::NonParen(format!("({sugg})").into())
},
}
}
@@ -375,20 +381,18 @@ fn binop_to_string(op: AssocOp, lhs: &str, rhs: &str) -> String {
| AssocOp::Greater
| AssocOp::GreaterEqual => {
format!(
- "{} {} {}",
- lhs,
- op.to_ast_binop().expect("Those are AST ops").to_string(),
- rhs
+ "{lhs} {} {rhs}",
+ op.to_ast_binop().expect("Those are AST ops").to_string()
)
},
- AssocOp::Assign => format!("{} = {}", lhs, rhs),
+ AssocOp::Assign => format!("{lhs} = {rhs}"),
AssocOp::AssignOp(op) => {
- format!("{} {}= {}", lhs, token_kind_to_string(&token::BinOp(op)), rhs)
+ format!("{lhs} {}= {rhs}", token_kind_to_string(&token::BinOp(op)))
},
- AssocOp::As => format!("{} as {}", lhs, rhs),
- AssocOp::DotDot => format!("{}..{}", lhs, rhs),
- AssocOp::DotDotEq => format!("{}..={}", lhs, rhs),
- AssocOp::Colon => format!("{}: {}", lhs, rhs),
+ AssocOp::As => format!("{lhs} as {rhs}"),
+ AssocOp::DotDot => format!("{lhs}..{rhs}"),
+ AssocOp::DotDotEq => format!("{lhs}..={rhs}"),
+ AssocOp::Colon => format!("{lhs}: {rhs}"),
}
}
@@ -519,7 +523,7 @@ impl<T: Display> Display for ParenHelper<T> {
/// operators have the same
/// precedence.
pub fn make_unop(op: &str, expr: Sugg<'_>) -> Sugg<'static> {
- Sugg::MaybeParen(format!("{}{}", op, expr.maybe_par()).into())
+ Sugg::MaybeParen(format!("{op}{}", expr.maybe_par()).into())
}
/// Builds the string for `<lhs> <op> <rhs>` adding parenthesis when necessary.
@@ -740,7 +744,7 @@ impl<T: LintContext> DiagnosticExt<T> for rustc_errors::Diagnostic {
if let Some(indent) = indentation(cx, item) {
let span = item.with_hi(item.lo());
- self.span_suggestion(span, msg, format!("{}\n{}", attr, indent), applicability);
+ self.span_suggestion(span, msg, format!("{attr}\n{indent}"), applicability);
}
}
@@ -754,21 +758,20 @@ impl<T: LintContext> DiagnosticExt<T> for rustc_errors::Diagnostic {
.map(|l| {
if first {
first = false;
- format!("{}\n", l)
+ format!("{l}\n")
} else {
- format!("{}{}\n", indent, l)
+ format!("{indent}{l}\n")
}
})
.collect::<String>();
- self.span_suggestion(span, msg, format!("{}\n{}", new_item, indent), applicability);
+ self.span_suggestion(span, msg, format!("{new_item}\n{indent}"), applicability);
}
}
fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability) {
let mut remove_span = item;
- let hi = cx.sess().source_map().next_point(remove_span).hi();
- let fmpos = cx.sess().source_map().lookup_byte_offset(hi);
+ let fmpos = cx.sess().source_map().lookup_byte_offset(remove_span.hi());
if let Some(ref src) = fmpos.sf.src {
let non_whitespace_offset = src[fmpos.pos.to_usize()..].find(|c| c != ' ' && c != '\t' && c != '\n');
@@ -819,10 +822,9 @@ pub fn deref_closure_args<'tcx>(cx: &LateContext<'_>, closure: &'tcx hir::Expr<'
};
let fn_def_id = cx.tcx.hir().local_def_id(closure.hir_id);
- cx.tcx.infer_ctxt().enter(|infcx| {
- ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
- .consume_body(closure_body);
- });
+ let infcx = cx.tcx.infer_ctxt().build();
+ ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
+ .consume_body(closure_body);
if !visitor.suggestion_start.is_empty() {
return Some(DerefClosure {
@@ -859,7 +861,7 @@ impl<'tcx> DerefDelegate<'_, 'tcx> {
pub fn finish(&mut self) -> String {
let end_span = Span::new(self.next_pos, self.closure_span.hi(), self.closure_span.ctxt(), None);
let end_snip = snippet_with_applicability(self.cx, end_span, "..", &mut self.applicability);
- let sugg = format!("{}{}", self.suggestion_start, end_snip);
+ let sugg = format!("{}{end_snip}", self.suggestion_start);
if self.closure_arg_is_type_annotated_double_ref {
sugg.replacen('&', "", 1)
} else {
@@ -921,7 +923,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
if cmt.place.projections.is_empty() {
// handle item without any projection, that needs an explicit borrowing
// i.e.: suggest `&x` instead of `x`
- let _ = write!(self.suggestion_start, "{}&{}", start_snip, ident_str);
+ let _ = write!(self.suggestion_start, "{start_snip}&{ident_str}");
} else {
// cases where a parent `Call` or `MethodCall` is using the item
// i.e.: suggest `.contains(&x)` for `.find(|x| [1, 2, 3].contains(x)).is_none()`
@@ -936,7 +938,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
// given expression is the self argument and will be handled completely by the compiler
// i.e.: `|x| x.is_something()`
ExprKind::MethodCall(_, self_expr, ..) if self_expr.hir_id == cmt.hir_id => {
- let _ = write!(self.suggestion_start, "{}{}", start_snip, ident_str_with_proj);
+ let _ = write!(self.suggestion_start, "{start_snip}{ident_str_with_proj}");
self.next_pos = span.hi();
return;
},
@@ -969,9 +971,9 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
} else {
ident_str
};
- format!("{}{}", start_snip, ident)
+ format!("{start_snip}{ident}")
} else {
- format!("{}&{}", start_snip, ident_str)
+ format!("{start_snip}&{ident_str}")
};
self.suggestion_start.push_str(&ident_sugg);
self.next_pos = span.hi();
@@ -1038,13 +1040,13 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
for item in projections {
if item.kind == ProjectionKind::Deref {
- replacement_str = format!("*{}", replacement_str);
+ replacement_str = format!("*{replacement_str}");
}
}
}
}
- let _ = write!(self.suggestion_start, "{}{}", start_snip, replacement_str);
+ let _ = write!(self.suggestion_start, "{start_snip}{replacement_str}");
}
self.next_pos = span.hi();
}
@@ -1052,7 +1054,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
fn mutate(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
- fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {}
+ fn fake_read(&mut self, _: &PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {}
}
#[cfg(test)]
diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs
index a8ad6cf4f..4e024ce40 100644
--- a/src/tools/clippy/clippy_utils/src/ty.rs
+++ b/src/tools/clippy/clippy_utils/src/ty.rs
@@ -12,13 +12,13 @@ use rustc_hir::{Expr, FnDecl, LangItem, TyKind, Unsafety};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::LateContext;
use rustc_middle::mir::interpret::{ConstValue, Scalar};
-use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
use rustc_middle::ty::{
self, AdtDef, Binder, BoundRegion, DefIdTree, FnSig, IntTy, ParamEnv, Predicate, PredicateKind, ProjectionTy,
Region, RegionKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, VariantDef, VariantDiscr,
};
+use rustc_middle::ty::{GenericArg, GenericArgKind};
use rustc_span::symbol::Ident;
-use rustc_span::{sym, Span, Symbol, DUMMY_SP};
+use rustc_span::{sym, Span, Symbol};
use rustc_target::abi::{Size, VariantIdx};
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::query::normalize::AtExt;
@@ -28,7 +28,14 @@ use crate::{match_def_path, path_res, paths};
// Checks if the given type implements copy.
pub fn is_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
- ty.is_copy_modulo_regions(cx.tcx.at(DUMMY_SP), cx.param_env)
+ ty.is_copy_modulo_regions(cx.tcx, cx.param_env)
+}
+
+/// This checks whether a given type is known to implement Debug.
+pub fn has_debug_impl<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
+ cx.tcx
+ .get_diagnostic_item(sym::Debug)
+ .map_or(false, |debug| implements_trait(cx, ty, debug, &[]))
}
/// Checks whether a type can be partially moved.
@@ -165,11 +172,10 @@ pub fn implements_trait_with_env<'tcx>(
return false;
}
let ty_params = tcx.mk_substs(ty_params.iter());
- tcx.infer_ctxt().enter(|infcx| {
- infcx
- .type_implements_trait(trait_id, ty, ty_params, param_env)
- .must_apply_modulo_regions()
- })
+ let infcx = tcx.infer_ctxt().build();
+ infcx
+ .type_implements_trait(trait_id, ty, ty_params, param_env)
+ .must_apply_modulo_regions()
}
/// Checks whether this type implements `Drop`.
@@ -235,27 +241,26 @@ fn is_normalizable_helper<'tcx>(
}
// prevent recursive loops, false-negative is better than endless loop leading to stack overflow
cache.insert(ty, false);
- let result = cx.tcx.infer_ctxt().enter(|infcx| {
- let cause = rustc_middle::traits::ObligationCause::dummy();
- if infcx.at(&cause, param_env).normalize(ty).is_ok() {
- match ty.kind() {
- ty::Adt(def, substs) => def.variants().iter().all(|variant| {
- variant
- .fields
- .iter()
- .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache))
- }),
- _ => ty.walk().all(|generic_arg| match generic_arg.unpack() {
- GenericArgKind::Type(inner_ty) if inner_ty != ty => {
- is_normalizable_helper(cx, param_env, inner_ty, cache)
- },
- _ => true, // if inner_ty == ty, we've already checked it
- }),
- }
- } else {
- false
+ let infcx = cx.tcx.infer_ctxt().build();
+ let cause = rustc_middle::traits::ObligationCause::dummy();
+ let result = if infcx.at(&cause, param_env).normalize(ty).is_ok() {
+ match ty.kind() {
+ ty::Adt(def, substs) => def.variants().iter().all(|variant| {
+ variant
+ .fields
+ .iter()
+ .all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache))
+ }),
+ _ => ty.walk().all(|generic_arg| match generic_arg.unpack() {
+ GenericArgKind::Type(inner_ty) if inner_ty != ty => {
+ is_normalizable_helper(cx, param_env, inner_ty, cache)
+ },
+ _ => true, // if inner_ty == ty, we've already checked it
+ }),
}
- });
+ } else {
+ false
+ };
cache.insert(ty, result);
result
}
@@ -652,21 +657,18 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O
let mut output = None;
let lang_items = cx.tcx.lang_items();
- for pred in cx
+ for (pred, _) in cx
.tcx
.bound_explicit_item_bounds(ty.item_def_id)
- .transpose_iter()
- .map(|x| x.map_bound(|(p, _)| p))
+ .subst_iter_copied(cx.tcx, ty.substs)
{
- match pred.0.kind().skip_binder() {
+ match pred.kind().skip_binder() {
PredicateKind::Trait(p)
if (lang_items.fn_trait() == Some(p.def_id())
|| lang_items.fn_mut_trait() == Some(p.def_id())
|| lang_items.fn_once_trait() == Some(p.def_id())) =>
{
- let i = pred
- .map_bound(|pred| pred.kind().rebind(p.trait_ref.substs.type_at(1)))
- .subst(cx.tcx, ty.substs);
+ let i = pred.kind().rebind(p.trait_ref.substs.type_at(1));
if inputs.map_or(false, |inputs| inputs != i) {
// Multiple different fn trait impls. Is this even allowed?
@@ -679,10 +681,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O
// Multiple different fn trait impls. Is this even allowed?
return None;
}
- output = Some(
- pred.map_bound(|pred| pred.kind().rebind(p.term.ty().unwrap()))
- .subst(cx.tcx, ty.substs),
- );
+ output = pred.kind().rebind(p.term.ty()).transpose();
},
_ => (),
}
diff --git a/src/tools/clippy/clippy_utils/src/usage.rs b/src/tools/clippy/clippy_utils/src/usage.rs
index 3af5dfb62..000fb51c0 100644
--- a/src/tools/clippy/clippy_utils/src/usage.rs
+++ b/src/tools/clippy/clippy_utils/src/usage.rs
@@ -1,15 +1,16 @@
use crate as utils;
-use crate::visitors::{expr_visitor, expr_visitor_no_bodies};
+use crate::visitors::{for_each_expr, for_each_expr_with_closures, Descend};
+use core::ops::ControlFlow;
use rustc_hir as hir;
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::HirIdSet;
use rustc_hir::{Expr, ExprKind, HirId, Node};
+use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::LateContext;
use rustc_middle::hir::nested_filter;
use rustc_middle::mir::FakeReadCause;
use rustc_middle::ty;
-use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
/// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined.
pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> Option<HirIdSet> {
@@ -17,16 +18,15 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) ->
used_mutably: HirIdSet::default(),
skip: false,
};
- cx.tcx.infer_ctxt().enter(|infcx| {
- ExprUseVisitor::new(
- &mut delegate,
- &infcx,
- expr.hir_id.owner,
- cx.param_env,
- cx.typeck_results(),
- )
- .walk_expr(expr);
- });
+ let infcx = cx.tcx.infer_ctxt().build();
+ ExprUseVisitor::new(
+ &mut delegate,
+ &infcx,
+ expr.hir_id.owner.def_id,
+ cx.param_env,
+ cx.typeck_results(),
+ )
+ .walk_expr(expr);
if delegate.skip {
return None;
@@ -73,7 +73,12 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
self.update(cmt);
}
- fn fake_read(&mut self, _: &rustc_typeck::expr_use_visitor::PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {}
+ fn fake_read(
+ &mut self,
+ _: &rustc_hir_typeck::expr_use_visitor::PlaceWithHirId<'tcx>,
+ _: FakeReadCause,
+ _: HirId,
+ ) {}
}
pub struct ParamBindingIdCollector {
@@ -142,28 +147,17 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for BindingUsageFinder<'a, 'tcx> {
}
pub fn contains_return_break_continue_macro(expression: &Expr<'_>) -> bool {
- let mut seen_return_break_continue = false;
- expr_visitor_no_bodies(|ex| {
- if seen_return_break_continue {
- return false;
- }
- match &ex.kind {
- ExprKind::Ret(..) | ExprKind::Break(..) | ExprKind::Continue(..) => {
- seen_return_break_continue = true;
- },
+ for_each_expr(expression, |e| {
+ match e.kind {
+ ExprKind::Ret(..) | ExprKind::Break(..) | ExprKind::Continue(..) => ControlFlow::Break(()),
// Something special could be done here to handle while or for loop
// desugaring, as this will detect a break if there's a while loop
// or a for loop inside the expression.
- _ => {
- if ex.span.from_expansion() {
- seen_return_break_continue = true;
- }
- },
+ _ if e.span.from_expansion() => ControlFlow::Break(()),
+ _ => ControlFlow::Continue(()),
}
- !seen_return_break_continue
})
- .visit_expr(expression);
- seen_return_break_continue
+ .is_some()
}
pub fn local_used_after_expr(cx: &LateContext<'_>, local_id: HirId, after: &Expr<'_>) -> bool {
@@ -194,23 +188,16 @@ pub fn local_used_after_expr(cx: &LateContext<'_>, local_id: HirId, after: &Expr
return true;
}
- let mut used_after_expr = false;
let mut past_expr = false;
- expr_visitor(cx, |expr| {
- if used_after_expr {
- return false;
- }
-
- if expr.hir_id == after.hir_id {
+ for_each_expr_with_closures(cx, block, |e| {
+ if e.hir_id == after.hir_id {
past_expr = true;
- return false;
- }
-
- if past_expr && utils::path_to_local_id(expr, local_id) {
- used_after_expr = true;
+ ControlFlow::Continue(Descend::No)
+ } else if past_expr && utils::path_to_local_id(e, local_id) {
+ ControlFlow::Break(())
+ } else {
+ ControlFlow::Continue(Descend::Yes)
}
- !used_after_expr
})
- .visit_block(block);
- used_after_expr
+ .is_some()
}
diff --git a/src/tools/clippy/clippy_utils/src/visitors.rs b/src/tools/clippy/clippy_utils/src/visitors.rs
index 232d57190..d4294f18f 100644
--- a/src/tools/clippy/clippy_utils/src/visitors.rs
+++ b/src/tools/clippy/clippy_utils/src/visitors.rs
@@ -5,14 +5,13 @@ use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::intravisit::{self, walk_block, walk_expr, Visitor};
use rustc_hir::{
- Arm, Block, BlockCheckMode, Body, BodyId, Expr, ExprKind, HirId, ItemId, ItemKind, Let, Pat, QPath, Stmt, UnOp,
- UnsafeSource, Unsafety,
+ AnonConst, Arm, Block, BlockCheckMode, Body, BodyId, Expr, ExprKind, HirId, ItemId, ItemKind, Let, Pat, QPath,
+ Stmt, UnOp, UnsafeSource, Unsafety,
};
use rustc_lint::LateContext;
-use rustc_middle::hir::map::Map;
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::adjustment::Adjust;
-use rustc_middle::ty::{self, Ty, TypeckResults};
+use rustc_middle::ty::{self, Ty, TyCtxt, TypeckResults};
use rustc_span::Span;
mod internal {
@@ -48,6 +47,26 @@ impl Continue for Descend {
}
}
+/// A type which can be visited.
+pub trait Visitable<'tcx> {
+ /// Calls the corresponding `visit_*` function on the visitor.
+ fn visit<V: Visitor<'tcx>>(self, visitor: &mut V);
+}
+macro_rules! visitable_ref {
+ ($t:ident, $f:ident) => {
+ impl<'tcx> Visitable<'tcx> for &'tcx $t<'tcx> {
+ fn visit<V: Visitor<'tcx>>(self, visitor: &mut V) {
+ visitor.$f(self);
+ }
+ }
+ };
+}
+visitable_ref!(Arm, visit_arm);
+visitable_ref!(Block, visit_block);
+visitable_ref!(Body, visit_body);
+visitable_ref!(Expr, visit_expr);
+visitable_ref!(Stmt, visit_stmt);
+
/// Calls the given function once for each expression contained. This does not enter any bodies or
/// nested items.
pub fn for_each_expr<'tcx, B, C: Continue>(
@@ -82,57 +101,63 @@ pub fn for_each_expr<'tcx, B, C: Continue>(
v.res
}
-/// Convenience method for creating a `Visitor` with just `visit_expr` overridden and nested
-/// bodies (i.e. closures) are visited.
-/// If the callback returns `true`, the expr just provided to the callback is walked.
-#[must_use]
-pub fn expr_visitor<'tcx>(cx: &LateContext<'tcx>, f: impl FnMut(&'tcx Expr<'tcx>) -> bool) -> impl Visitor<'tcx> {
- struct V<'tcx, F> {
- hir: Map<'tcx>,
+/// Calls the given function once for each expression contained. This will enter bodies, but not
+/// nested items.
+pub fn for_each_expr_with_closures<'tcx, B, C: Continue>(
+ cx: &LateContext<'tcx>,
+ node: impl Visitable<'tcx>,
+ f: impl FnMut(&'tcx Expr<'tcx>) -> ControlFlow<B, C>,
+) -> Option<B> {
+ struct V<'tcx, B, F> {
+ tcx: TyCtxt<'tcx>,
f: F,
+ res: Option<B>,
}
- impl<'tcx, F: FnMut(&'tcx Expr<'tcx>) -> bool> Visitor<'tcx> for V<'tcx, F> {
+ impl<'tcx, B, C: Continue, F: FnMut(&'tcx Expr<'tcx>) -> ControlFlow<B, C>> Visitor<'tcx> for V<'tcx, B, F> {
type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map {
- self.hir
+ self.tcx.hir()
}
- fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
- if (self.f)(expr) {
- walk_expr(self, expr);
+ fn visit_expr(&mut self, e: &'tcx Expr<'tcx>) {
+ if self.res.is_some() {
+ return;
}
- }
- }
- V { hir: cx.tcx.hir(), f }
-}
-
-/// Convenience method for creating a `Visitor` with just `visit_expr` overridden and nested
-/// bodies (i.e. closures) are not visited.
-/// If the callback returns `true`, the expr just provided to the callback is walked.
-#[must_use]
-pub fn expr_visitor_no_bodies<'tcx>(f: impl FnMut(&'tcx Expr<'tcx>) -> bool) -> impl Visitor<'tcx> {
- struct V<F>(F);
- impl<'tcx, F: FnMut(&'tcx Expr<'tcx>) -> bool> Visitor<'tcx> for V<F> {
- fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
- if (self.0)(e) {
- walk_expr(self, e);
+ match (self.f)(e) {
+ ControlFlow::Continue(c) if c.descend() => walk_expr(self, e),
+ ControlFlow::Break(b) => self.res = Some(b),
+ ControlFlow::Continue(_) => (),
}
}
+
+ // Only walk closures
+ fn visit_anon_const(&mut self, _: &'tcx AnonConst) {}
+ // Avoid unnecessary `walk_*` calls.
+ fn visit_ty(&mut self, _: &'tcx hir::Ty<'tcx>) {}
+ fn visit_pat(&mut self, _: &'tcx Pat<'tcx>) {}
+ fn visit_qpath(&mut self, _: &'tcx QPath<'tcx>, _: HirId, _: Span) {}
+ // Avoid monomorphising all `visit_*` functions.
+ fn visit_nested_item(&mut self, _: ItemId) {}
}
- V(f)
+ let mut v = V {
+ tcx: cx.tcx,
+ f,
+ res: None,
+ };
+ node.visit(&mut v);
+ v.res
}
/// returns `true` if expr contains match expr desugared from try
fn contains_try(expr: &hir::Expr<'_>) -> bool {
- let mut found = false;
- expr_visitor_no_bodies(|e| {
- if !found {
- found = matches!(e.kind, hir::ExprKind::Match(_, _, hir::MatchSource::TryDesugar));
+ for_each_expr(expr, |e| {
+ if matches!(e.kind, hir::ExprKind::Match(_, _, hir::MatchSource::TryDesugar)) {
+ ControlFlow::Break(())
+ } else {
+ ControlFlow::Continue(())
}
- !found
})
- .visit_expr(expr);
- found
+ .is_some()
}
pub fn find_all_ret_expressions<'hir, F>(_cx: &LateContext<'_>, expr: &'hir hir::Expr<'hir>, callback: F) -> bool
@@ -228,68 +253,29 @@ where
}
}
-/// A type which can be visited.
-pub trait Visitable<'tcx> {
- /// Calls the corresponding `visit_*` function on the visitor.
- fn visit<V: Visitor<'tcx>>(self, visitor: &mut V);
-}
-macro_rules! visitable_ref {
- ($t:ident, $f:ident) => {
- impl<'tcx> Visitable<'tcx> for &'tcx $t<'tcx> {
- fn visit<V: Visitor<'tcx>>(self, visitor: &mut V) {
- visitor.$f(self);
- }
- }
- };
-}
-visitable_ref!(Arm, visit_arm);
-visitable_ref!(Block, visit_block);
-visitable_ref!(Body, visit_body);
-visitable_ref!(Expr, visit_expr);
-visitable_ref!(Stmt, visit_stmt);
-
-// impl<'tcx, I: IntoIterator> Visitable<'tcx> for I
-// where
-// I::Item: Visitable<'tcx>,
-// {
-// fn visit<V: Visitor<'tcx>>(self, visitor: &mut V) {
-// for x in self {
-// x.visit(visitor);
-// }
-// }
-// }
-
/// Checks if the given resolved path is used in the given body.
pub fn is_res_used(cx: &LateContext<'_>, res: Res, body: BodyId) -> bool {
- let mut found = false;
- expr_visitor(cx, |e| {
- if found {
- return false;
- }
-
+ for_each_expr_with_closures(cx, cx.tcx.hir().body(body).value, |e| {
if let ExprKind::Path(p) = &e.kind {
if cx.qpath_res(p, e.hir_id) == res {
- found = true;
+ return ControlFlow::Break(());
}
}
- !found
+ ControlFlow::Continue(())
})
- .visit_expr(cx.tcx.hir().body(body).value);
- found
+ .is_some()
}
/// Checks if the given local is used.
pub fn is_local_used<'tcx>(cx: &LateContext<'tcx>, visitable: impl Visitable<'tcx>, id: HirId) -> bool {
- let mut is_used = false;
- let mut visitor = expr_visitor(cx, |expr| {
- if !is_used {
- is_used = path_to_local_id(expr, id);
+ for_each_expr_with_closures(cx, visitable, |e| {
+ if path_to_local_id(e, id) {
+ ControlFlow::Break(())
+ } else {
+ ControlFlow::Continue(())
}
- !is_used
- });
- visitable.visit(&mut visitor);
- drop(visitor);
- is_used
+ })
+ .is_some()
}
/// Checks if the given expression is a constant.
diff --git a/src/tools/clippy/lintcheck/Cargo.toml b/src/tools/clippy/lintcheck/Cargo.toml
index 737c845c0..de31c16b8 100644
--- a/src/tools/clippy/lintcheck/Cargo.toml
+++ b/src/tools/clippy/lintcheck/Cargo.toml
@@ -12,9 +12,11 @@ publish = false
[dependencies]
cargo_metadata = "0.14"
clap = "3.2"
+crossbeam-channel = "0.5.6"
flate2 = "1.0"
rayon = "1.5.1"
serde = { version = "1.0", features = ["derive"] }
+serde_json = "1.0.85"
tar = "0.4"
toml = "0.5"
ureq = "2.2"
diff --git a/src/tools/clippy/lintcheck/README.md b/src/tools/clippy/lintcheck/README.md
index 6f3d23382..6142de5e3 100644
--- a/src/tools/clippy/lintcheck/README.md
+++ b/src/tools/clippy/lintcheck/README.md
@@ -69,9 +69,27 @@ is checked.
is explicitly specified in the options.
### Fix mode
-You can run `./lintcheck/target/debug/lintcheck --fix` which will run Clippy with `--fix` and
+You can run `cargo lintcheck --fix` which will run Clippy with `--fix` and
print a warning if Clippy's suggestions fail to apply (if the resulting code does not build).
This lets us spot bad suggestions or false positives automatically in some cases.
Please note that the target dir should be cleaned afterwards since clippy will modify
the downloaded sources which can lead to unexpected results when running lintcheck again afterwards.
+
+### Recursive mode
+You can run `cargo lintcheck --recursive` to also run Clippy on the dependencies
+of the crates listed in the crates source `.toml`. e.g. adding `rand 0.8.5`
+would also lint `rand_core`, `rand_chacha`, etc.
+
+Particularly slow crates in the dependency graph can be ignored using
+`recursive.ignore`:
+
+```toml
+[crates]
+cargo = {name = "cargo", versions = ['0.64.0']}
+
+[recursive]
+ignore = [
+ "unicode-normalization",
+]
+```
diff --git a/src/tools/clippy/lintcheck/lintcheck_crates.toml b/src/tools/clippy/lintcheck/lintcheck_crates.toml
index ebbe9c9ae..52f7fee47 100644
--- a/src/tools/clippy/lintcheck/lintcheck_crates.toml
+++ b/src/tools/clippy/lintcheck/lintcheck_crates.toml
@@ -33,3 +33,11 @@ cfg-expr = {name = "cfg-expr", versions = ['0.7.1']}
puffin = {name = "puffin", git_url = "https://github.com/EmbarkStudios/puffin", git_hash = "02dd4a3"}
rpmalloc = {name = "rpmalloc", versions = ['0.2.0']}
tame-oidc = {name = "tame-oidc", versions = ['0.1.0']}
+
+[recursive]
+ignore = [
+ # Takes ~30s to lint
+ "combine",
+ # Has 1.2 million `clippy::match_same_arms`s
+ "unicode-normalization",
+]
diff --git a/src/tools/clippy/lintcheck/src/config.rs b/src/tools/clippy/lintcheck/src/config.rs
index 1742cf677..b8824024e 100644
--- a/src/tools/clippy/lintcheck/src/config.rs
+++ b/src/tools/clippy/lintcheck/src/config.rs
@@ -34,11 +34,16 @@ fn get_clap_config() -> ArgMatches {
Arg::new("markdown")
.long("markdown")
.help("Change the reports table to use markdown links"),
+ Arg::new("recursive")
+ .long("--recursive")
+ .help("Run clippy on the dependencies of crates specified in crates-toml")
+ .conflicts_with("threads")
+ .conflicts_with("fix"),
])
.get_matches()
}
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub(crate) struct LintcheckConfig {
/// max number of jobs to spawn (default 1)
pub max_jobs: usize,
@@ -54,6 +59,8 @@ pub(crate) struct LintcheckConfig {
pub lint_filter: Vec<String>,
/// Indicate if the output should support markdown syntax
pub markdown: bool,
+ /// Run clippy on the dependencies of crates
+ pub recursive: bool,
}
impl LintcheckConfig {
@@ -66,8 +73,7 @@ impl LintcheckConfig {
let sources_toml = env::var("LINTCHECK_TOML").unwrap_or_else(|_| {
clap_config
.get_one::<String>("crates-toml")
- .map(|s| &**s)
- .unwrap_or("lintcheck/lintcheck_crates.toml")
+ .map_or("lintcheck/lintcheck_crates.toml", |s| &**s)
.into()
});
@@ -90,7 +96,7 @@ impl LintcheckConfig {
Some(&0) => {
// automatic choice
// Rayon seems to return thread count so half that for core count
- (rayon::current_num_threads() / 2) as usize
+ rayon::current_num_threads() / 2
},
Some(&threads) => threads,
// no -j passed, use a single thread
@@ -119,6 +125,7 @@ impl LintcheckConfig {
fix: clap_config.contains_id("fix"),
lint_filter,
markdown,
+ recursive: clap_config.contains_id("recursive"),
}
}
}
diff --git a/src/tools/clippy/lintcheck/src/driver.rs b/src/tools/clippy/lintcheck/src/driver.rs
new file mode 100644
index 000000000..47724a2fe
--- /dev/null
+++ b/src/tools/clippy/lintcheck/src/driver.rs
@@ -0,0 +1,67 @@
+use crate::recursive::{deserialize_line, serialize_line, DriverInfo};
+
+use std::io::{self, BufReader, Write};
+use std::net::TcpStream;
+use std::process::{self, Command, Stdio};
+use std::{env, mem};
+
+/// 1. Sends [`DriverInfo`] to the [`crate::recursive::LintcheckServer`] running on `addr`
+/// 2. Receives [bool] from the server, if `false` returns `None`
+/// 3. Otherwise sends the stderr of running `clippy-driver` to the server
+fn run_clippy(addr: &str) -> Option<i32> {
+ let driver_info = DriverInfo {
+ package_name: env::var("CARGO_PKG_NAME").ok()?,
+ crate_name: env::var("CARGO_CRATE_NAME").ok()?,
+ version: env::var("CARGO_PKG_VERSION").ok()?,
+ };
+
+ let mut stream = BufReader::new(TcpStream::connect(addr).unwrap());
+
+ serialize_line(&driver_info, stream.get_mut());
+
+ let should_run = deserialize_line::<bool, _>(&mut stream);
+ if !should_run {
+ return None;
+ }
+
+ // Remove --cap-lints allow so that clippy runs and lints are emitted
+ let mut include_next = true;
+ let args = env::args().skip(1).filter(|arg| match arg.as_str() {
+ "--cap-lints=allow" => false,
+ "--cap-lints" => {
+ include_next = false;
+ false
+ },
+ _ => mem::replace(&mut include_next, true),
+ });
+
+ let output = Command::new(env::var("CLIPPY_DRIVER").expect("missing env CLIPPY_DRIVER"))
+ .args(args)
+ .stdout(Stdio::inherit())
+ .output()
+ .expect("failed to run clippy-driver");
+
+ stream
+ .get_mut()
+ .write_all(&output.stderr)
+ .unwrap_or_else(|e| panic!("{e:?} in {driver_info:?}"));
+
+ match output.status.code() {
+ Some(0) => Some(0),
+ code => {
+ io::stderr().write_all(&output.stderr).unwrap();
+ Some(code.expect("killed by signal"))
+ },
+ }
+}
+
+pub fn drive(addr: &str) {
+ process::exit(run_clippy(addr).unwrap_or_else(|| {
+ Command::new("rustc")
+ .args(env::args_os().skip(2))
+ .status()
+ .unwrap()
+ .code()
+ .unwrap()
+ }))
+}
diff --git a/src/tools/clippy/lintcheck/src/main.rs b/src/tools/clippy/lintcheck/src/main.rs
index 9ee25280f..54c1b80c4 100644
--- a/src/tools/clippy/lintcheck/src/main.rs
+++ b/src/tools/clippy/lintcheck/src/main.rs
@@ -8,13 +8,17 @@
#![allow(clippy::collapsible_else_if)]
mod config;
+mod driver;
+mod recursive;
-use config::LintcheckConfig;
+use crate::config::LintcheckConfig;
+use crate::recursive::LintcheckServer;
-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
use std::env;
+use std::env::consts::EXE_SUFFIX;
use std::fmt::Write as _;
-use std::fs::write;
+use std::fs;
use std::io::ErrorKind;
use std::path::{Path, PathBuf};
use std::process::Command;
@@ -22,22 +26,12 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;
use std::time::Duration;
-use cargo_metadata::diagnostic::DiagnosticLevel;
+use cargo_metadata::diagnostic::{Diagnostic, DiagnosticLevel};
use cargo_metadata::Message;
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use walkdir::{DirEntry, WalkDir};
-#[cfg(not(windows))]
-const CLIPPY_DRIVER_PATH: &str = "target/debug/clippy-driver";
-#[cfg(not(windows))]
-const CARGO_CLIPPY_PATH: &str = "target/debug/cargo-clippy";
-
-#[cfg(windows)]
-const CLIPPY_DRIVER_PATH: &str = "target/debug/clippy-driver.exe";
-#[cfg(windows)]
-const CARGO_CLIPPY_PATH: &str = "target/debug/cargo-clippy.exe";
-
const LINTCHECK_DOWNLOADS: &str = "target/lintcheck/downloads";
const LINTCHECK_SOURCES: &str = "target/lintcheck/sources";
@@ -45,6 +39,13 @@ const LINTCHECK_SOURCES: &str = "target/lintcheck/sources";
#[derive(Debug, Serialize, Deserialize)]
struct SourceList {
crates: HashMap<String, TomlCrate>,
+ #[serde(default)]
+ recursive: RecursiveOptions,
+}
+
+#[derive(Debug, Serialize, Deserialize, Default)]
+struct RecursiveOptions {
+ ignore: HashSet<String>,
}
/// A crate source stored inside the .toml
@@ -105,12 +106,7 @@ struct ClippyWarning {
#[allow(unused)]
impl ClippyWarning {
- fn new(cargo_message: Message, krate: &Crate) -> Option<Self> {
- let diag = match cargo_message {
- Message::CompilerMessage(message) => message.message,
- _ => return None,
- };
-
+ fn new(diag: Diagnostic, crate_name: &str, crate_version: &str) -> Option<Self> {
let lint_type = diag.code?.code;
if !(lint_type.contains("clippy") || diag.message.contains("clippy"))
|| diag.message.contains("could not read cargo metadata")
@@ -120,16 +116,17 @@ impl ClippyWarning {
let span = diag.spans.into_iter().find(|span| span.is_primary)?;
- let file = match Path::new(&span.file_name).strip_prefix(env!("CARGO_HOME")) {
- Ok(stripped) => format!("$CARGO_HOME/{}", stripped.display()),
- Err(_) => format!(
+ let file = if let Ok(stripped) = Path::new(&span.file_name).strip_prefix(env!("CARGO_HOME")) {
+ format!("$CARGO_HOME/{}", stripped.display())
+ } else {
+ format!(
"target/lintcheck/sources/{}-{}/{}",
- krate.name, krate.version, span.file_name
- ),
+ crate_name, crate_version, span.file_name
+ )
};
Some(Self {
- crate_name: krate.name.clone(),
+ crate_name: crate_name.to_owned(),
file,
line: span.line_start,
column: span.column_start,
@@ -142,24 +139,23 @@ impl ClippyWarning {
fn to_output(&self, markdown: bool) -> String {
let file_with_pos = format!("{}:{}:{}", &self.file, &self.line, &self.column);
if markdown {
- let lint = format!("`{}`", self.lint_type);
-
let mut file = self.file.clone();
if !file.starts_with('$') {
file.insert_str(0, "../");
}
let mut output = String::from("| ");
- let _ = write!(output, "[`{}`]({}#L{})", file_with_pos, file, self.line);
- let _ = write!(output, r#" | {:<50} | "{}" |"#, lint, self.message);
+ let _ = write!(output, "[`{file_with_pos}`]({file}#L{})", self.line);
+ let _ = write!(output, r#" | `{:<50}` | "{}" |"#, self.lint_type, self.message);
output.push('\n');
output
} else {
- format!("{} {} \"{}\"\n", file_with_pos, self.lint_type, self.message)
+ format!("{file_with_pos} {} \"{}\"\n", self.lint_type, self.message)
}
}
}
+#[allow(clippy::result_large_err)]
fn get(path: &str) -> Result<ureq::Response, ureq::Error> {
const MAX_RETRIES: u8 = 4;
let mut retries = 0;
@@ -167,11 +163,11 @@ fn get(path: &str) -> Result<ureq::Response, ureq::Error> {
match ureq::get(path).call() {
Ok(res) => return Ok(res),
Err(e) if retries >= MAX_RETRIES => return Err(e),
- Err(ureq::Error::Transport(e)) => eprintln!("Error: {}", e),
+ Err(ureq::Error::Transport(e)) => eprintln!("Error: {e}"),
Err(e) => return Err(e),
}
- eprintln!("retrying in {} seconds...", retries);
- thread::sleep(Duration::from_secs(retries as u64));
+ eprintln!("retrying in {retries} seconds...");
+ thread::sleep(Duration::from_secs(u64::from(retries)));
retries += 1;
}
}
@@ -187,11 +183,11 @@ impl CrateSource {
let krate_download_dir = PathBuf::from(LINTCHECK_DOWNLOADS);
// url to download the crate from crates.io
- let url = format!("https://crates.io/api/v1/crates/{}/{}/download", name, version);
- println!("Downloading and extracting {} {} from {}", name, version, url);
+ let url = format!("https://crates.io/api/v1/crates/{name}/{version}/download");
+ println!("Downloading and extracting {name} {version} from {url}");
create_dirs(&krate_download_dir, &extract_dir);
- let krate_file_path = krate_download_dir.join(format!("{}-{}.crate.tar.gz", name, version));
+ let krate_file_path = krate_download_dir.join(format!("{name}-{version}.crate.tar.gz"));
// don't download/extract if we already have done so
if !krate_file_path.is_file() {
// create a file path to download and write the crate data into
@@ -211,7 +207,7 @@ impl CrateSource {
Crate {
version: version.clone(),
name: name.clone(),
- path: extract_dir.join(format!("{}-{}/", name, version)),
+ path: extract_dir.join(format!("{name}-{version}/")),
options: options.clone(),
}
},
@@ -224,12 +220,12 @@ impl CrateSource {
let repo_path = {
let mut repo_path = PathBuf::from(LINTCHECK_SOURCES);
// add a -git suffix in case we have the same crate from crates.io and a git repo
- repo_path.push(format!("{}-git", name));
+ repo_path.push(format!("{name}-git"));
repo_path
};
// clone the repo if we have not done so
if !repo_path.is_dir() {
- println!("Cloning {} and checking out {}", url, commit);
+ println!("Cloning {url} and checking out {commit}");
if !Command::new("git")
.arg("clone")
.arg(url)
@@ -238,11 +234,12 @@ impl CrateSource {
.expect("Failed to clone git repo!")
.success()
{
- eprintln!("Failed to clone {} into {}", url, repo_path.display())
+ eprintln!("Failed to clone {url} into {}", repo_path.display());
}
}
// check out the commit/branch/whatever
if !Command::new("git")
+ .args(["-c", "advice.detachedHead=false"])
.arg("checkout")
.arg(commit)
.current_dir(&repo_path)
@@ -250,7 +247,7 @@ impl CrateSource {
.expect("Failed to check out commit")
.success()
{
- eprintln!("Failed to checkout {} of repo at {}", commit, repo_path.display())
+ eprintln!("Failed to checkout {commit} of repo at {}", repo_path.display());
}
Crate {
@@ -261,22 +258,22 @@ impl CrateSource {
}
},
CrateSource::Path { name, path, options } => {
+ fn is_cache_dir(entry: &DirEntry) -> bool {
+ std::fs::read(entry.path().join("CACHEDIR.TAG"))
+ .map(|x| x.starts_with(b"Signature: 8a477f597d28d172789f06886806bc55"))
+ .unwrap_or(false)
+ }
+
// copy path into the dest_crate_root but skip directories that contain a CACHEDIR.TAG file.
// The target/ directory contains a CACHEDIR.TAG file so it is the most commonly skipped directory
// as a result of this filter.
let dest_crate_root = PathBuf::from(LINTCHECK_SOURCES).join(name);
if dest_crate_root.exists() {
- println!("Deleting existing directory at {:?}", dest_crate_root);
+ println!("Deleting existing directory at {dest_crate_root:?}");
std::fs::remove_dir_all(&dest_crate_root).unwrap();
}
- println!("Copying {:?} to {:?}", path, dest_crate_root);
-
- fn is_cache_dir(entry: &DirEntry) -> bool {
- std::fs::read(entry.path().join("CACHEDIR.TAG"))
- .map(|x| x.starts_with(b"Signature: 8a477f597d28d172789f06886806bc55"))
- .unwrap_or(false)
- }
+ println!("Copying {path:?} to {dest_crate_root:?}");
for entry in WalkDir::new(path).into_iter().filter_entry(|e| !is_cache_dir(e)) {
let entry = entry.unwrap();
@@ -306,13 +303,16 @@ impl CrateSource {
impl Crate {
/// Run `cargo clippy` on the `Crate` and collect and return all the lint warnings that clippy
/// issued
+ #[allow(clippy::too_many_arguments)]
fn run_clippy_lints(
&self,
cargo_clippy_path: &Path,
+ clippy_driver_path: &Path,
target_dir_index: &AtomicUsize,
total_crates_to_lint: usize,
config: &LintcheckConfig,
lint_filter: &Vec<String>,
+ server: &Option<LintcheckServer>,
) -> Vec<ClippyWarning> {
// advance the atomic index by one
let index = target_dir_index.fetch_add(1, Ordering::SeqCst);
@@ -336,36 +336,64 @@ impl Crate {
let shared_target_dir = clippy_project_root().join("target/lintcheck/shared_target_dir");
- let mut args = if config.fix {
+ let mut cargo_clippy_args = if config.fix {
vec!["--fix", "--"]
} else {
vec!["--", "--message-format=json", "--"]
};
+ let mut clippy_args = Vec::<&str>::new();
if let Some(options) = &self.options {
for opt in options {
- args.push(opt);
+ clippy_args.push(opt);
}
} else {
- args.extend(&["-Wclippy::pedantic", "-Wclippy::cargo"])
+ clippy_args.extend(["-Wclippy::pedantic", "-Wclippy::cargo"]);
}
if lint_filter.is_empty() {
- args.push("--cap-lints=warn");
+ clippy_args.push("--cap-lints=warn");
} else {
- args.push("--cap-lints=allow");
- args.extend(lint_filter.iter().map(|filter| filter.as_str()))
+ clippy_args.push("--cap-lints=allow");
+ clippy_args.extend(lint_filter.iter().map(std::string::String::as_str));
}
- let all_output = std::process::Command::new(&cargo_clippy_path)
+ if let Some(server) = server {
+ let target = shared_target_dir.join("recursive");
+
+ // `cargo clippy` is a wrapper around `cargo check` that mainly sets `RUSTC_WORKSPACE_WRAPPER` to
+ // `clippy-driver`. We do the same thing here with a couple changes:
+ //
+ // `RUSTC_WRAPPER` is used instead of `RUSTC_WORKSPACE_WRAPPER` so that we can lint all crate
+ // dependencies rather than only workspace members
+ //
+ // The wrapper is set to the `lintcheck` so we can force enable linting and ignore certain crates
+ // (see `crate::driver`)
+ let status = Command::new("cargo")
+ .arg("check")
+ .arg("--quiet")
+ .current_dir(&self.path)
+ .env("CLIPPY_ARGS", clippy_args.join("__CLIPPY_HACKERY__"))
+ .env("CARGO_TARGET_DIR", target)
+ .env("RUSTC_WRAPPER", env::current_exe().unwrap())
+ // Pass the absolute path so `crate::driver` can find `clippy-driver`, as it's executed in various
+ // different working directories
+ .env("CLIPPY_DRIVER", clippy_driver_path)
+ .env("LINTCHECK_SERVER", server.local_addr.to_string())
+ .status()
+ .expect("failed to run cargo");
+
+ assert_eq!(status.code(), Some(0));
+
+ return Vec::new();
+ }
+
+ cargo_clippy_args.extend(clippy_args);
+
+ let all_output = Command::new(&cargo_clippy_path)
// use the looping index to create individual target dirs
- .env(
- "CARGO_TARGET_DIR",
- shared_target_dir.join(format!("_{:?}", thread_index)),
- )
- // lint warnings will look like this:
- // src/cargo/ops/cargo_compile.rs:127:35: warning: usage of `FromIterator::from_iter`
- .args(&args)
+ .env("CARGO_TARGET_DIR", shared_target_dir.join(format!("_{thread_index:?}")))
+ .args(&cargo_clippy_args)
.current_dir(&self.path)
.output()
.unwrap_or_else(|error| {
@@ -394,8 +422,8 @@ impl Crate {
{
let subcrate = &stderr[63..];
println!(
- "ERROR: failed to apply some suggetion to {} / to (sub)crate {}",
- self.name, subcrate
+ "ERROR: failed to apply some suggetion to {} / to (sub)crate {subcrate}",
+ self.name
);
}
// fast path, we don't need the warnings anyway
@@ -404,7 +432,10 @@ impl Crate {
// get all clippy warnings and ICEs
let warnings: Vec<ClippyWarning> = Message::parse_stream(stdout.as_bytes())
- .filter_map(|msg| ClippyWarning::new(msg.unwrap(), &self))
+ .filter_map(|msg| match msg {
+ Ok(Message::CompilerMessage(message)) => ClippyWarning::new(message.message, &self.name, &self.version),
+ _ => None,
+ })
.collect();
warnings
@@ -423,23 +454,19 @@ fn build_clippy() {
}
}
-/// Read a `toml` file and return a list of `CrateSources` that we want to check with clippy
-fn read_crates(toml_path: &Path) -> Vec<CrateSource> {
+/// Read a `lintcheck_crates.toml` file
+fn read_crates(toml_path: &Path) -> (Vec<CrateSource>, RecursiveOptions) {
let toml_content: String =
- std::fs::read_to_string(&toml_path).unwrap_or_else(|_| panic!("Failed to read {}", toml_path.display()));
+ std::fs::read_to_string(toml_path).unwrap_or_else(|_| panic!("Failed to read {}", toml_path.display()));
let crate_list: SourceList =
- toml::from_str(&toml_content).unwrap_or_else(|e| panic!("Failed to parse {}: \n{}", toml_path.display(), e));
+ toml::from_str(&toml_content).unwrap_or_else(|e| panic!("Failed to parse {}: \n{e}", toml_path.display()));
// parse the hashmap of the toml file into a list of crates
- let tomlcrates: Vec<TomlCrate> = crate_list
- .crates
- .into_iter()
- .map(|(_cratename, tomlcrate)| tomlcrate)
- .collect();
+ let tomlcrates: Vec<TomlCrate> = crate_list.crates.into_values().collect();
// flatten TomlCrates into CrateSources (one TomlCrates may represent several versions of a crate =>
// multiple Cratesources)
let mut crate_sources = Vec::new();
- tomlcrates.into_iter().for_each(|tk| {
+ for tk in tomlcrates {
if let Some(ref path) = tk.path {
crate_sources.push(CrateSource::Path {
name: tk.name.clone(),
@@ -448,13 +475,13 @@ fn read_crates(toml_path: &Path) -> Vec<CrateSource> {
});
} else if let Some(ref versions) = tk.versions {
// if we have multiple versions, save each one
- versions.iter().for_each(|ver| {
+ for ver in versions.iter() {
crate_sources.push(CrateSource::CratesIo {
name: tk.name.clone(),
version: ver.to_string(),
options: tk.options.clone(),
});
- })
+ }
} else if tk.git_url.is_some() && tk.git_hash.is_some() {
// otherwise, we should have a git source
crate_sources.push(CrateSource::Git {
@@ -471,20 +498,23 @@ fn read_crates(toml_path: &Path) -> Vec<CrateSource> {
if tk.versions.is_some() && (tk.git_url.is_some() || tk.git_hash.is_some())
|| tk.git_hash.is_some() != tk.git_url.is_some()
{
- eprintln!("tomlkrate: {:?}", tk);
- if tk.git_hash.is_some() != tk.git_url.is_some() {
- panic!("Error: Encountered TomlCrate with only one of git_hash and git_url!");
- }
- if tk.path.is_some() && (tk.git_hash.is_some() || tk.versions.is_some()) {
- panic!("Error: TomlCrate can only have one of 'git_.*', 'version' or 'path' fields");
- }
+ eprintln!("tomlkrate: {tk:?}");
+ assert_eq!(
+ tk.git_hash.is_some(),
+ tk.git_url.is_some(),
+ "Error: Encountered TomlCrate with only one of git_hash and git_url!"
+ );
+ assert!(
+ tk.path.is_none() || (tk.git_hash.is_none() && tk.versions.is_none()),
+ "Error: TomlCrate can only have one of 'git_.*', 'version' or 'path' fields"
+ );
unreachable!("Failed to translate TomlCrate into CrateSource!");
}
- });
+ }
// sort the crates
crate_sources.sort();
- crate_sources
+ (crate_sources, crate_list.recursive)
}
/// Generate a short list of occurring lints-types and their count
@@ -499,13 +529,13 @@ fn gather_stats(clippy_warnings: &[ClippyWarning]) -> (String, HashMap<&String,
let mut stats: Vec<(&&String, &usize)> = counter.iter().map(|(lint, count)| (lint, count)).collect();
// sort by "000{count} {clippy::lintname}"
// to not have a lint with 200 and 2 warnings take the same spot
- stats.sort_by_key(|(lint, count)| format!("{:0>4}, {}", count, lint));
+ stats.sort_by_key(|(lint, count)| format!("{count:0>4}, {lint}"));
let mut header = String::from("| lint | count |\n");
header.push_str("| -------------------------------------------------- | ----- |\n");
let stats_string = stats
.iter()
- .map(|(lint, count)| format!("| {:<50} | {:>4} |\n", lint, count))
+ .map(|(lint, count)| format!("| {lint:<50} | {count:>4} |\n"))
.fold(header, |mut table, line| {
table.push_str(&line);
table
@@ -516,20 +546,20 @@ fn gather_stats(clippy_warnings: &[ClippyWarning]) -> (String, HashMap<&String,
/// check if the latest modification of the logfile is older than the modification date of the
/// clippy binary, if this is true, we should clean the lintchec shared target directory and recheck
-fn lintcheck_needs_rerun(lintcheck_logs_path: &Path) -> bool {
+fn lintcheck_needs_rerun(lintcheck_logs_path: &Path, paths: [&Path; 2]) -> bool {
if !lintcheck_logs_path.exists() {
return true;
}
let clippy_modified: std::time::SystemTime = {
- let mut times = [CLIPPY_DRIVER_PATH, CARGO_CLIPPY_PATH].iter().map(|p| {
+ let [cargo, driver] = paths.map(|p| {
std::fs::metadata(p)
.expect("failed to get metadata of file")
.modified()
.expect("failed to get modification date")
});
// the oldest modification of either of the binaries
- std::cmp::max(times.next().unwrap(), times.next().unwrap())
+ std::cmp::max(cargo, driver)
};
let logs_modified: std::time::SystemTime = std::fs::metadata(lintcheck_logs_path)
@@ -542,7 +572,13 @@ fn lintcheck_needs_rerun(lintcheck_logs_path: &Path) -> bool {
logs_modified < clippy_modified
}
+#[allow(clippy::too_many_lines)]
fn main() {
+ // We're being executed as a `RUSTC_WRAPPER` as part of `--recursive`
+ if let Ok(addr) = env::var("LINTCHECK_SERVER") {
+ driver::drive(&addr);
+ }
+
// assert that we launch lintcheck from the repo root (via cargo lintcheck)
if std::fs::metadata("lintcheck/Cargo.toml").is_err() {
eprintln!("lintcheck needs to be run from clippy's repo root!\nUse `cargo lintcheck` alternatively.");
@@ -555,24 +591,26 @@ fn main() {
build_clippy();
println!("Done compiling");
+ let cargo_clippy_path = fs::canonicalize(format!("target/debug/cargo-clippy{EXE_SUFFIX}")).unwrap();
+ let clippy_driver_path = fs::canonicalize(format!("target/debug/clippy-driver{EXE_SUFFIX}")).unwrap();
+
// if the clippy bin is newer than our logs, throw away target dirs to force clippy to
// refresh the logs
- if lintcheck_needs_rerun(&config.lintcheck_results_path) {
+ if lintcheck_needs_rerun(
+ &config.lintcheck_results_path,
+ [&cargo_clippy_path, &clippy_driver_path],
+ ) {
let shared_target_dir = "target/lintcheck/shared_target_dir";
// if we get an Err here, the shared target dir probably does simply not exist
- if let Ok(metadata) = std::fs::metadata(&shared_target_dir) {
+ if let Ok(metadata) = std::fs::metadata(shared_target_dir) {
if metadata.is_dir() {
println!("Clippy is newer than lint check logs, clearing lintcheck shared target dir...");
- std::fs::remove_dir_all(&shared_target_dir)
+ std::fs::remove_dir_all(shared_target_dir)
.expect("failed to remove target/lintcheck/shared_target_dir");
}
}
}
- let cargo_clippy_path: PathBuf = PathBuf::from(CARGO_CLIPPY_PATH)
- .canonicalize()
- .expect("failed to canonicalize path to clippy binary");
-
// assert that clippy is found
assert!(
cargo_clippy_path.is_file(),
@@ -580,7 +618,7 @@ fn main() {
cargo_clippy_path.display()
);
- let clippy_ver = std::process::Command::new(CARGO_CLIPPY_PATH)
+ let clippy_ver = std::process::Command::new(&cargo_clippy_path)
.arg("--version")
.output()
.map(|o| String::from_utf8_lossy(&o.stdout).into_owned())
@@ -589,7 +627,7 @@ fn main() {
// download and extract the crates, then run clippy on them and collect clippy's warnings
// flatten into one big list of warnings
- let crates = read_crates(&config.sources_toml_path);
+ let (crates, recursive_options) = read_crates(&config.sources_toml_path);
let old_stats = read_stats_from_file(&config.lintcheck_results_path);
let counter = AtomicUsize::new(1);
@@ -639,11 +677,31 @@ fn main() {
.build_global()
.unwrap();
- let clippy_warnings: Vec<ClippyWarning> = crates
+ let server = config.recursive.then(|| {
+ fs::remove_dir_all("target/lintcheck/shared_target_dir/recursive").unwrap_or_default();
+
+ LintcheckServer::spawn(recursive_options)
+ });
+
+ let mut clippy_warnings: Vec<ClippyWarning> = crates
.par_iter()
- .flat_map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, crates.len(), &config, &lint_filter))
+ .flat_map(|krate| {
+ krate.run_clippy_lints(
+ &cargo_clippy_path,
+ &clippy_driver_path,
+ &counter,
+ crates.len(),
+ &config,
+ &lint_filter,
+ &server,
+ )
+ })
.collect();
+ if let Some(server) = server {
+ clippy_warnings.extend(server.warnings());
+ }
+
// if we are in --fix mode, don't change the log files, terminate here
if config.fix {
return;
@@ -676,13 +734,13 @@ fn main() {
}
write!(text, "{}", all_msgs.join("")).unwrap();
text.push_str("\n\n### ICEs:\n");
- for (cratename, msg) in ices.iter() {
- let _ = write!(text, "{}: '{}'", cratename, msg);
+ for (cratename, msg) in &ices {
+ let _ = write!(text, "{cratename}: '{msg}'");
}
println!("Writing logs to {}", config.lintcheck_results_path.display());
- std::fs::create_dir_all(config.lintcheck_results_path.parent().unwrap()).unwrap();
- write(&config.lintcheck_results_path, text).unwrap();
+ fs::create_dir_all(config.lintcheck_results_path.parent().unwrap()).unwrap();
+ fs::write(&config.lintcheck_results_path, text).unwrap();
print_stats(old_stats, new_stats, &config.lint_filter);
}
@@ -721,7 +779,7 @@ fn read_stats_from_file(file_path: &Path) -> HashMap<String, usize> {
fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, usize>, lint_filter: &Vec<String>) {
let same_in_both_hashmaps = old_stats
.iter()
- .filter(|(old_key, old_val)| new_stats.get::<&String>(&old_key) == Some(old_val))
+ .filter(|(old_key, old_val)| new_stats.get::<&String>(old_key) == Some(old_val))
.map(|(k, v)| (k.to_string(), *v))
.collect::<Vec<(String, usize)>>();
@@ -729,37 +787,37 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
let mut new_stats_deduped = new_stats;
// remove duplicates from both hashmaps
- same_in_both_hashmaps.iter().for_each(|(k, v)| {
+ for (k, v) in &same_in_both_hashmaps {
assert!(old_stats_deduped.remove(k) == Some(*v));
assert!(new_stats_deduped.remove(k) == Some(*v));
- });
+ }
println!("\nStats:");
// list all new counts (key is in new stats but not in old stats)
new_stats_deduped
.iter()
- .filter(|(new_key, _)| old_stats_deduped.get::<str>(&new_key).is_none())
+ .filter(|(new_key, _)| old_stats_deduped.get::<str>(new_key).is_none())
.for_each(|(new_key, new_value)| {
- println!("{} 0 => {}", new_key, new_value);
+ println!("{new_key} 0 => {new_value}");
});
// list all changed counts (key is in both maps but value differs)
new_stats_deduped
.iter()
- .filter(|(new_key, _new_val)| old_stats_deduped.get::<str>(&new_key).is_some())
+ .filter(|(new_key, _new_val)| old_stats_deduped.get::<str>(new_key).is_some())
.for_each(|(new_key, new_val)| {
- let old_val = old_stats_deduped.get::<str>(&new_key).unwrap();
- println!("{} {} => {}", new_key, old_val, new_val);
+ let old_val = old_stats_deduped.get::<str>(new_key).unwrap();
+ println!("{new_key} {old_val} => {new_val}");
});
// list all gone counts (key is in old status but not in new stats)
old_stats_deduped
.iter()
- .filter(|(old_key, _)| new_stats_deduped.get::<&String>(&old_key).is_none())
+ .filter(|(old_key, _)| new_stats_deduped.get::<&String>(old_key).is_none())
.filter(|(old_key, _)| lint_filter.is_empty() || lint_filter.contains(old_key))
.for_each(|(old_key, old_value)| {
- println!("{} {} => 0", old_key, old_value);
+ println!("{old_key} {old_value} => 0");
});
}
@@ -770,19 +828,21 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
/// This function panics if creating one of the dirs fails.
fn create_dirs(krate_download_dir: &Path, extract_dir: &Path) {
std::fs::create_dir("target/lintcheck/").unwrap_or_else(|err| {
- if err.kind() != ErrorKind::AlreadyExists {
- panic!("cannot create lintcheck target dir");
- }
+ assert_eq!(
+ err.kind(),
+ ErrorKind::AlreadyExists,
+ "cannot create lintcheck target dir"
+ );
});
- std::fs::create_dir(&krate_download_dir).unwrap_or_else(|err| {
- if err.kind() != ErrorKind::AlreadyExists {
- panic!("cannot create crate download dir");
- }
+ std::fs::create_dir(krate_download_dir).unwrap_or_else(|err| {
+ assert_eq!(err.kind(), ErrorKind::AlreadyExists, "cannot create crate download dir");
});
- std::fs::create_dir(&extract_dir).unwrap_or_else(|err| {
- if err.kind() != ErrorKind::AlreadyExists {
- panic!("cannot create crate extraction dir");
- }
+ std::fs::create_dir(extract_dir).unwrap_or_else(|err| {
+ assert_eq!(
+ err.kind(),
+ ErrorKind::AlreadyExists,
+ "cannot create crate extraction dir"
+ );
});
}
@@ -805,7 +865,7 @@ fn lintcheck_test() {
"lintcheck/test_sources.toml",
];
let status = std::process::Command::new("cargo")
- .args(&args)
+ .args(args)
.current_dir("..") // repo root
.status();
//.output();
diff --git a/src/tools/clippy/lintcheck/src/recursive.rs b/src/tools/clippy/lintcheck/src/recursive.rs
new file mode 100644
index 000000000..49072e651
--- /dev/null
+++ b/src/tools/clippy/lintcheck/src/recursive.rs
@@ -0,0 +1,123 @@
+//! In `--recursive` mode we set the `lintcheck` binary as the `RUSTC_WRAPPER` of `cargo check`,
+//! this allows [`crate::driver`] to be run for every dependency. The driver connects to
+//! [`LintcheckServer`] to ask if it should be skipped, and if not sends the stderr of running
+//! clippy on the crate to the server
+
+use crate::ClippyWarning;
+use crate::RecursiveOptions;
+
+use std::collections::HashSet;
+use std::io::{BufRead, BufReader, Read, Write};
+use std::net::{SocketAddr, TcpListener, TcpStream};
+use std::sync::{Arc, Mutex};
+use std::thread;
+
+use cargo_metadata::diagnostic::Diagnostic;
+use crossbeam_channel::{Receiver, Sender};
+use serde::de::DeserializeOwned;
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Eq, Hash, PartialEq, Clone, Serialize, Deserialize)]
+pub(crate) struct DriverInfo {
+ pub package_name: String,
+ pub crate_name: String,
+ pub version: String,
+}
+
+pub(crate) fn serialize_line<T, W>(value: &T, writer: &mut W)
+where
+ T: Serialize,
+ W: Write,
+{
+ let mut buf = serde_json::to_vec(&value).expect("failed to serialize");
+ buf.push(b'\n');
+ writer.write_all(&buf).expect("write_all failed");
+}
+
+pub(crate) fn deserialize_line<T, R>(reader: &mut R) -> T
+where
+ T: DeserializeOwned,
+ R: BufRead,
+{
+ let mut string = String::new();
+ reader.read_line(&mut string).expect("read_line failed");
+ serde_json::from_str(&string).expect("failed to deserialize")
+}
+
+fn process_stream(
+ stream: TcpStream,
+ sender: &Sender<ClippyWarning>,
+ options: &RecursiveOptions,
+ seen: &Mutex<HashSet<DriverInfo>>,
+) {
+ let mut stream = BufReader::new(stream);
+
+ let driver_info: DriverInfo = deserialize_line(&mut stream);
+
+ let unseen = seen.lock().unwrap().insert(driver_info.clone());
+ let ignored = options.ignore.contains(&driver_info.package_name);
+ let should_run = unseen && !ignored;
+
+ serialize_line(&should_run, stream.get_mut());
+
+ let mut stderr = String::new();
+ stream.read_to_string(&mut stderr).unwrap();
+
+ let messages = stderr
+ .lines()
+ .filter_map(|json_msg| serde_json::from_str::<Diagnostic>(json_msg).ok())
+ .filter_map(|diag| ClippyWarning::new(diag, &driver_info.package_name, &driver_info.version));
+
+ for message in messages {
+ sender.send(message).unwrap();
+ }
+}
+
+pub(crate) struct LintcheckServer {
+ pub local_addr: SocketAddr,
+ receiver: Receiver<ClippyWarning>,
+ sender: Arc<Sender<ClippyWarning>>,
+}
+
+impl LintcheckServer {
+ pub fn spawn(options: RecursiveOptions) -> Self {
+ let listener = TcpListener::bind("localhost:0").unwrap();
+ let local_addr = listener.local_addr().unwrap();
+
+ let (sender, receiver) = crossbeam_channel::unbounded::<ClippyWarning>();
+ let sender = Arc::new(sender);
+ // The spawned threads hold a `Weak<Sender>` so that they don't keep the channel connected
+ // indefinitely
+ let sender_weak = Arc::downgrade(&sender);
+
+ // Ignore dependencies multiple times, e.g. for when it's both checked and compiled for a
+ // build dependency
+ let seen = Mutex::default();
+
+ thread::spawn(move || {
+ thread::scope(|s| {
+ s.spawn(|| {
+ while let Ok((stream, _)) = listener.accept() {
+ let sender = sender_weak.upgrade().expect("received connection after server closed");
+ let options = &options;
+ let seen = &seen;
+ s.spawn(move || process_stream(stream, &sender, options, seen));
+ }
+ });
+ });
+ });
+
+ Self {
+ local_addr,
+ receiver,
+ sender,
+ }
+ }
+
+ pub fn warnings(self) -> impl Iterator<Item = ClippyWarning> {
+ // causes the channel to become disconnected so that the receiver iterator ends
+ drop(self.sender);
+
+ self.receiver.into_iter()
+ }
+}
diff --git a/src/tools/clippy/rust-toolchain b/src/tools/clippy/rust-toolchain
index b6976366d..748d8a317 100644
--- a/src/tools/clippy/rust-toolchain
+++ b/src/tools/clippy/rust-toolchain
@@ -1,3 +1,3 @@
[toolchain]
-channel = "nightly-2022-09-08"
+channel = "nightly-2022-10-20"
components = ["cargo", "llvm-tools-preview", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
diff --git a/src/tools/clippy/rustc_tools_util/Cargo.toml b/src/tools/clippy/rustc_tools_util/Cargo.toml
index 9554d4d6c..89c3d6aaa 100644
--- a/src/tools/clippy/rustc_tools_util/Cargo.toml
+++ b/src/tools/clippy/rustc_tools_util/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rustc_tools_util"
-version = "0.2.0"
+version = "0.2.1"
description = "small helper to generate version information for git packages"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
diff --git a/src/tools/clippy/rustc_tools_util/README.md b/src/tools/clippy/rustc_tools_util/README.md
index 01891b51d..e947f9c7e 100644
--- a/src/tools/clippy/rustc_tools_util/README.md
+++ b/src/tools/clippy/rustc_tools_util/README.md
@@ -6,17 +6,17 @@ for packages installed from a git repo
## Usage
Add a `build.rs` file to your repo and list it in `Cargo.toml`
-````
+````toml
build = "build.rs"
````
List rustc_tools_util as regular AND build dependency.
-````
+````toml
[dependencies]
-rustc_tools_util = "0.1"
+rustc_tools_util = "0.2.1"
[build-dependencies]
-rustc_tools_util = "0.1"
+rustc_tools_util = "0.2.1"
````
In `build.rs`, generate the data in your `main()`
diff --git a/src/tools/clippy/rustc_tools_util/src/lib.rs b/src/tools/clippy/rustc_tools_util/src/lib.rs
index 429dddc42..01d25c531 100644
--- a/src/tools/clippy/rustc_tools_util/src/lib.rs
+++ b/src/tools/clippy/rustc_tools_util/src/lib.rs
@@ -48,8 +48,8 @@ impl std::fmt::Display for VersionInfo {
if (hash_trimmed.len() + date_trimmed.len()) > 0 {
write!(
f,
- "{} {}.{}.{} ({} {})",
- self.crate_name, self.major, self.minor, self.patch, hash_trimmed, date_trimmed,
+ "{} {}.{}.{} ({hash_trimmed} {date_trimmed})",
+ self.crate_name, self.major, self.minor, self.patch,
)?;
} else {
write!(f, "{} {}.{}.{}", self.crate_name, self.major, self.minor, self.patch)?;
@@ -137,7 +137,7 @@ mod test {
let vi = get_version_info!();
assert_eq!(vi.major, 0);
assert_eq!(vi.minor, 2);
- assert_eq!(vi.patch, 0);
+ assert_eq!(vi.patch, 1);
assert_eq!(vi.crate_name, "rustc_tools_util");
// hard to make positive tests for these since they will always change
assert!(vi.commit_hash.is_none());
@@ -147,16 +147,16 @@ mod test {
#[test]
fn test_display_local() {
let vi = get_version_info!();
- assert_eq!(vi.to_string(), "rustc_tools_util 0.2.0");
+ assert_eq!(vi.to_string(), "rustc_tools_util 0.2.1");
}
#[test]
fn test_debug_local() {
let vi = get_version_info!();
- let s = format!("{:?}", vi);
+ let s = format!("{vi:?}");
assert_eq!(
s,
- "VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 2, patch: 0 }"
+ "VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 2, patch: 1 }"
);
}
}
diff --git a/src/tools/clippy/src/docs.rs b/src/tools/clippy/src/docs.rs
index f3a5048e7..c033ad294 100644
--- a/src/tools/clippy/src/docs.rs
+++ b/src/tools/clippy/src/docs.rs
@@ -28,6 +28,7 @@ docs! {
"approx_constant",
"arithmetic_side_effects",
"as_conversions",
+ "as_ptr_cast_mut",
"as_underscore",
"assertions_on_constants",
"assertions_on_result_states",
@@ -48,6 +49,7 @@ docs! {
"borrow_interior_mutable_const",
"borrowed_box",
"box_collection",
+ "box_default",
"boxed_local",
"branches_sharing_code",
"builtin_type_shadow",
@@ -59,6 +61,7 @@ docs! {
"cast_enum_constructor",
"cast_enum_truncation",
"cast_lossless",
+ "cast_nan_to_int",
"cast_possible_truncation",
"cast_possible_wrap",
"cast_precision_loss",
@@ -105,6 +108,7 @@ docs! {
"derive_hash_xor_eq",
"derive_ord_xor_partial_ord",
"derive_partial_eq_without_eq",
+ "disallowed_macros",
"disallowed_methods",
"disallowed_names",
"disallowed_script_idents",
@@ -168,7 +172,6 @@ docs! {
"fn_to_numeric_cast_any",
"fn_to_numeric_cast_with_truncation",
"for_kv_map",
- "for_loops_over_fallibles",
"forget_copy",
"forget_non_drop",
"forget_ref",
@@ -190,6 +193,7 @@ docs! {
"implicit_clone",
"implicit_hasher",
"implicit_return",
+ "implicit_saturating_add",
"implicit_saturating_sub",
"imprecise_flops",
"inconsistent_digit_grouping",
@@ -221,6 +225,7 @@ docs! {
"items_after_statements",
"iter_cloned_collect",
"iter_count",
+ "iter_kv_map",
"iter_next_loop",
"iter_next_slice",
"iter_not_returning_iterator",
@@ -253,6 +258,8 @@ docs! {
"manual_assert",
"manual_async_fn",
"manual_bits",
+ "manual_clamp",
+ "manual_filter",
"manual_filter_map",
"manual_find",
"manual_find_map",
@@ -309,6 +316,7 @@ docs! {
"missing_panics_doc",
"missing_safety_doc",
"missing_spin_loop",
+ "missing_trait_methods",
"mistyped_literal_suffixes",
"mixed_case_hex_literals",
"mixed_read_write_in_expression",
@@ -387,11 +395,11 @@ docs! {
"panic",
"panic_in_result_fn",
"panicking_unwrap",
+ "partial_pub_fields",
"partialeq_ne_impl",
"partialeq_to_none",
"path_buf_push_overwrite",
"pattern_type_mismatch",
- "positional_named_format_parameters",
"possible_missing_comma",
"precedence",
"print_in_format_impl",
@@ -521,6 +529,7 @@ docs! {
"unimplemented",
"uninit_assumed_init",
"uninit_vec",
+ "uninlined_format_args",
"unit_arg",
"unit_cmp",
"unit_hash",
@@ -549,6 +558,7 @@ docs! {
"unseparated_literal_suffix",
"unsound_collection_transmute",
"unused_async",
+ "unused_format_specs",
"unused_io_amount",
"unused_peekable",
"unused_rounding",
diff --git a/src/tools/clippy/src/docs/arithmetic_side_effects.txt b/src/tools/clippy/src/docs/arithmetic_side_effects.txt
index 6c7d51a49..4ae8bce88 100644
--- a/src/tools/clippy/src/docs/arithmetic_side_effects.txt
+++ b/src/tools/clippy/src/docs/arithmetic_side_effects.txt
@@ -5,7 +5,7 @@ Operators like `+`, `-`, `*` or `<<` are usually capable of overflowing accordin
Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow),
or can panic (`/`, `%`).
-Known safe built-in types like `Wrapping` or `Saturing`, floats, operations in constant
+Known safe built-in types like `Wrapping` or `Saturating`, floats, operations in constant
environments, allowed types and non-constant operations that won't overflow are ignored.
### Why is this bad?
diff --git a/src/tools/clippy/src/docs/as_ptr_cast_mut.txt b/src/tools/clippy/src/docs/as_ptr_cast_mut.txt
new file mode 100644
index 000000000..228dde996
--- /dev/null
+++ b/src/tools/clippy/src/docs/as_ptr_cast_mut.txt
@@ -0,0 +1,19 @@
+### What it does
+Checks for the result of a `&self`-taking `as_ptr` being cast to a mutable pointer
+
+### Why is this bad?
+Since `as_ptr` takes a `&self`, the pointer won't have write permissions unless interior
+mutability is used, making it unlikely that having it as a mutable pointer is correct.
+
+### Example
+```
+let string = String::with_capacity(1);
+let ptr = string.as_ptr() as *mut u8;
+unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR
+```
+Use instead:
+```
+let mut string = String::with_capacity(1);
+let ptr = string.as_mut_ptr();
+unsafe { ptr.write(4) };
+``` \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/box_default.txt b/src/tools/clippy/src/docs/box_default.txt
new file mode 100644
index 000000000..1c670c773
--- /dev/null
+++ b/src/tools/clippy/src/docs/box_default.txt
@@ -0,0 +1,17 @@
+### What it does
+checks for `Box::new(T::default())`, which is better written as
+`Box::<T>::default()`.
+
+### Why is this bad?
+First, it's more complex, involving two calls instead of one.
+Second, `Box::default()` can be faster
+[in certain cases](https://nnethercote.github.io/perf-book/standard-library-types.html#box).
+
+### Example
+```
+let x: Box<String> = Box::new(Default::default());
+```
+Use instead:
+```
+let x: Box<String> = Box::default();
+``` \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/cast_nan_to_int.txt b/src/tools/clippy/src/docs/cast_nan_to_int.txt
new file mode 100644
index 000000000..122f5da0c
--- /dev/null
+++ b/src/tools/clippy/src/docs/cast_nan_to_int.txt
@@ -0,0 +1,15 @@
+### What it does
+Checks for a known NaN float being cast to an integer
+
+### Why is this bad?
+NaNs are cast into zero, so one could simply use this and make the
+code more readable. The lint could also hint at a programmer error.
+
+### Example
+```
+let _: (0.0_f32 / 0.0) as u64;
+```
+Use instead:
+```
+let _: = 0_u64;
+``` \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/disallowed_macros.txt b/src/tools/clippy/src/docs/disallowed_macros.txt
new file mode 100644
index 000000000..96fa15afa
--- /dev/null
+++ b/src/tools/clippy/src/docs/disallowed_macros.txt
@@ -0,0 +1,36 @@
+### What it does
+Denies the configured macros in clippy.toml
+
+Note: Even though this lint is warn-by-default, it will only trigger if
+macros are defined in the clippy.toml file.
+
+### Why is this bad?
+Some macros are undesirable in certain contexts, and it's beneficial to
+lint for them as needed.
+
+### Example
+An example clippy.toml configuration:
+```
+disallowed-macros = [
+ # Can use a string as the path of the disallowed macro.
+ "std::print",
+ # Can also use an inline table with a `path` key.
+ { path = "std::println" },
+ # When using an inline table, can add a `reason` for why the macro
+ # is disallowed.
+ { path = "serde::Serialize", reason = "no serializing" },
+]
+```
+```
+use serde::Serialize;
+
+// Example code where clippy issues a warning
+println!("warns");
+
+// The diagnostic will contain the message "no serializing"
+#[derive(Serialize)]
+struct Data {
+ name: String,
+ value: usize,
+}
+``` \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/for_loops_over_fallibles.txt b/src/tools/clippy/src/docs/for_loops_over_fallibles.txt
deleted file mode 100644
index c5a7508e4..000000000
--- a/src/tools/clippy/src/docs/for_loops_over_fallibles.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-### What it does
-Checks for `for` loops over `Option` or `Result` values.
-
-### Why is this bad?
-Readability. This is more clearly expressed as an `if
-let`.
-
-### Example
-```
-for x in opt {
- // ..
-}
-
-for x in &res {
- // ..
-}
-
-for x in res.iter() {
- // ..
-}
-```
-
-Use instead:
-```
-if let Some(x) = opt {
- // ..
-}
-
-if let Ok(x) = res {
- // ..
-}
-``` \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/implicit_saturating_add.txt b/src/tools/clippy/src/docs/implicit_saturating_add.txt
new file mode 100644
index 000000000..5883a5363
--- /dev/null
+++ b/src/tools/clippy/src/docs/implicit_saturating_add.txt
@@ -0,0 +1,20 @@
+### What it does
+Checks for implicit saturating addition.
+
+### Why is this bad?
+The built-in function is more readable and may be faster.
+
+### Example
+```
+let mut u:u32 = 7000;
+
+if u != u32::MAX {
+ u += 1;
+}
+```
+Use instead:
+```
+let mut u:u32 = 7000;
+
+u = u.saturating_add(1);
+``` \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/iter_kv_map.txt b/src/tools/clippy/src/docs/iter_kv_map.txt
new file mode 100644
index 000000000..a063c8195
--- /dev/null
+++ b/src/tools/clippy/src/docs/iter_kv_map.txt
@@ -0,0 +1,22 @@
+### What it does
+
+Checks for iterating a map (`HashMap` or `BTreeMap`) and
+ignoring either the keys or values.
+
+### Why is this bad?
+
+Readability. There are `keys` and `values` methods that
+can be used to express that we only need the keys or the values.
+
+### Example
+
+```
+let map: HashMap<u32, u32> = HashMap::new();
+let values = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
+```
+
+Use instead:
+```
+let map: HashMap<u32, u32> = HashMap::new();
+let values = map.values().collect::<Vec<_>>();
+``` \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/manual_clamp.txt b/src/tools/clippy/src/docs/manual_clamp.txt
new file mode 100644
index 000000000..8993f6683
--- /dev/null
+++ b/src/tools/clippy/src/docs/manual_clamp.txt
@@ -0,0 +1,46 @@
+### What it does
+Identifies good opportunities for a clamp function from std or core, and suggests using it.
+
+### Why is this bad?
+clamp is much shorter, easier to read, and doesn't use any control flow.
+
+### Known issue(s)
+If the clamped variable is NaN this suggestion will cause the code to propagate NaN
+rather than returning either `max` or `min`.
+
+`clamp` functions will panic if `max < min`, `max.is_nan()`, or `min.is_nan()`.
+Some may consider panicking in these situations to be desirable, but it also may
+introduce panicking where there wasn't any before.
+
+### Examples
+```
+if input > max {
+ max
+} else if input < min {
+ min
+} else {
+ input
+}
+```
+
+```
+input.max(min).min(max)
+```
+
+```
+match input {
+ x if x > max => max,
+ x if x < min => min,
+ x => x,
+}
+```
+
+```
+let mut x = input;
+if x < min { x = min; }
+if x > max { x = max; }
+```
+Use instead:
+```
+input.clamp(min, max)
+``` \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/manual_filter.txt b/src/tools/clippy/src/docs/manual_filter.txt
new file mode 100644
index 000000000..19a4d9319
--- /dev/null
+++ b/src/tools/clippy/src/docs/manual_filter.txt
@@ -0,0 +1,21 @@
+### What it does
+Checks for usages of `match` which could be implemented using `filter`
+
+### Why is this bad?
+Using the `filter` method is clearer and more concise.
+
+### Example
+```
+match Some(0) {
+ Some(x) => if x % 2 == 0 {
+ Some(x)
+ } else {
+ None
+ },
+ None => None,
+};
+```
+Use instead:
+```
+Some(0).filter(|&x| x % 2 == 0);
+``` \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/missing_trait_methods.txt b/src/tools/clippy/src/docs/missing_trait_methods.txt
new file mode 100644
index 000000000..788ad764f
--- /dev/null
+++ b/src/tools/clippy/src/docs/missing_trait_methods.txt
@@ -0,0 +1,40 @@
+### What it does
+Checks if a provided method is used implicitly by a trait
+implementation. A usage example would be a wrapper where every method
+should perform some operation before delegating to the inner type's
+implemenation.
+
+This lint should typically be enabled on a specific trait `impl` item
+rather than globally.
+
+### Why is this bad?
+Indicates that a method is missing.
+
+### Example
+```
+trait Trait {
+ fn required();
+
+ fn provided() {}
+}
+
+#[warn(clippy::missing_trait_methods)]
+impl Trait for Type {
+ fn required() { /* ... */ }
+}
+```
+Use instead:
+```
+trait Trait {
+ fn required();
+
+ fn provided() {}
+}
+
+#[warn(clippy::missing_trait_methods)]
+impl Trait for Type {
+ fn required() { /* ... */ }
+
+ fn provided() { /* ... */ }
+}
+``` \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/needless_borrowed_reference.txt b/src/tools/clippy/src/docs/needless_borrowed_reference.txt
index 55faa0cf5..152459ba1 100644
--- a/src/tools/clippy/src/docs/needless_borrowed_reference.txt
+++ b/src/tools/clippy/src/docs/needless_borrowed_reference.txt
@@ -1,30 +1,22 @@
### What it does
-Checks for bindings that destructure a reference and borrow the inner
+Checks for bindings that needlessly destructure a reference and borrow the inner
value with `&ref`.
### Why is this bad?
This pattern has no effect in almost all cases.
-### Known problems
-In some cases, `&ref` is needed to avoid a lifetime mismatch error.
-Example:
-```
-fn foo(a: &Option<String>, b: &Option<String>) {
- match (a, b) {
- (None, &ref c) | (&ref c, None) => (),
- (&Some(ref c), _) => (),
- };
-}
-```
-
### Example
```
let mut v = Vec::<String>::new();
v.iter_mut().filter(|&ref a| a.is_empty());
+
+if let &[ref first, ref second] = v.as_slice() {}
```
Use instead:
```
let mut v = Vec::<String>::new();
v.iter_mut().filter(|a| a.is_empty());
+
+if let [first, second] = v.as_slice() {}
``` \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/partial_pub_fields.txt b/src/tools/clippy/src/docs/partial_pub_fields.txt
new file mode 100644
index 000000000..b529adf15
--- /dev/null
+++ b/src/tools/clippy/src/docs/partial_pub_fields.txt
@@ -0,0 +1,27 @@
+### What it does
+Checks whether partial fields of a struct are public.
+
+Either make all fields of a type public, or make none of them public
+
+### Why is this bad?
+Most types should either be:
+* Abstract data types: complex objects with opaque implementation which guard
+interior invariants and expose intentionally limited API to the outside world.
+* Data: relatively simple objects which group a bunch of related attributes together.
+
+### Example
+```
+pub struct Color {
+ pub r: u8,
+ pub g: u8,
+ b: u8,
+}
+```
+Use instead:
+```
+pub struct Color {
+ pub r: u8,
+ pub g: u8,
+ pub b: u8,
+}
+``` \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/positional_named_format_parameters.txt b/src/tools/clippy/src/docs/positional_named_format_parameters.txt
deleted file mode 100644
index e391d2406..000000000
--- a/src/tools/clippy/src/docs/positional_named_format_parameters.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-### What it does
-This lint warns when a named parameter in a format string is used as a positional one.
-
-### Why is this bad?
-It may be confused for an assignment and obfuscates which parameter is being used.
-
-### Example
-```
-println!("{}", x = 10);
-```
-
-Use instead:
-```
-println!("{x}", x = 10);
-``` \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/print_literal.txt b/src/tools/clippy/src/docs/print_literal.txt
index 160073414..a6252a687 100644
--- a/src/tools/clippy/src/docs/print_literal.txt
+++ b/src/tools/clippy/src/docs/print_literal.txt
@@ -6,10 +6,6 @@ Using literals as `println!` args is inefficient
(c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary
(i.e., just put the literal in the format string)
-### Known problems
-Will also warn with macro calls as arguments that expand to literals
--- e.g., `println!("{}", env!("FOO"))`.
-
### Example
```
println!("{}", "foo");
diff --git a/src/tools/clippy/src/docs/print_stderr.txt b/src/tools/clippy/src/docs/print_stderr.txt
index fc14511cd..9c6edeeef 100644
--- a/src/tools/clippy/src/docs/print_stderr.txt
+++ b/src/tools/clippy/src/docs/print_stderr.txt
@@ -7,13 +7,7 @@ People often print on *stderr* while debugging an
application and might forget to remove those prints afterward.
### Known problems
-* Only catches `eprint!` and `eprintln!` calls.
-* The lint level is unaffected by crate attributes. The level can still
- be set for functions, modules and other items. To change the level for
- the entire crate, please use command line flags. More information and a
- configuration example can be found in [clippy#6610].
-
-[clippy#6610]: https://github.com/rust-lang/rust-clippy/issues/6610#issuecomment-977120558
+Only catches `eprint!` and `eprintln!` calls.
### Example
```
diff --git a/src/tools/clippy/src/docs/print_stdout.txt b/src/tools/clippy/src/docs/print_stdout.txt
index 6c9a4b98e..d2cbd811d 100644
--- a/src/tools/clippy/src/docs/print_stdout.txt
+++ b/src/tools/clippy/src/docs/print_stdout.txt
@@ -7,13 +7,7 @@ People often print on *stdout* while debugging an
application and might forget to remove those prints afterward.
### Known problems
-* Only catches `print!` and `println!` calls.
-* The lint level is unaffected by crate attributes. The level can still
- be set for functions, modules and other items. To change the level for
- the entire crate, please use command line flags. More information and a
- configuration example can be found in [clippy#6610].
-
-[clippy#6610]: https://github.com/rust-lang/rust-clippy/issues/6610#issuecomment-977120558
+Only catches `print!` and `println!` calls.
### Example
```
diff --git a/src/tools/clippy/src/docs/similar_names.txt b/src/tools/clippy/src/docs/similar_names.txt
index 13aca9c0b..f9eff21b6 100644
--- a/src/tools/clippy/src/docs/similar_names.txt
+++ b/src/tools/clippy/src/docs/similar_names.txt
@@ -1,6 +1,10 @@
### What it does
Checks for names that are very similar and thus confusing.
+Note: this lint looks for similar names throughout each
+scope. To allow it, you need to allow it on the scope
+level, not on the name that is reported.
+
### Why is this bad?
It's hard to distinguish between names that differ only
by a single character.
diff --git a/src/tools/clippy/src/docs/uninlined_format_args.txt b/src/tools/clippy/src/docs/uninlined_format_args.txt
new file mode 100644
index 000000000..3d2966c84
--- /dev/null
+++ b/src/tools/clippy/src/docs/uninlined_format_args.txt
@@ -0,0 +1,36 @@
+### What it does
+Detect when a variable is not inlined in a format string,
+and suggests to inline it.
+
+### Why is this bad?
+Non-inlined code is slightly more difficult to read and understand,
+as it requires arguments to be matched against the format string.
+The inlined syntax, where allowed, is simpler.
+
+### Example
+```
+format!("{}", var);
+format!("{v:?}", v = var);
+format!("{0} {0}", var);
+format!("{0:1$}", var, width);
+format!("{:.*}", prec, var);
+```
+Use instead:
+```
+format!("{var}");
+format!("{var:?}");
+format!("{var} {var}");
+format!("{var:width$}");
+format!("{var:.prec$}");
+```
+
+### Known Problems
+
+There may be a false positive if the format string is expanded from certain proc macros:
+
+```
+println!(indoc!("{}"), var);
+```
+
+If a format string contains a numbered argument that cannot be inlined
+nothing will be suggested, e.g. `println!("{0}={1}", var, 1+2)`. \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/unused_format_specs.txt b/src/tools/clippy/src/docs/unused_format_specs.txt
new file mode 100644
index 000000000..77be3a2fb
--- /dev/null
+++ b/src/tools/clippy/src/docs/unused_format_specs.txt
@@ -0,0 +1,24 @@
+### What it does
+Detects [formatting parameters] that have no effect on the output of
+`format!()`, `println!()` or similar macros.
+
+### Why is this bad?
+Shorter format specifiers are easier to read, it may also indicate that
+an expected formatting operation such as adding padding isn't happening.
+
+### Example
+```
+println!("{:.}", 1.0);
+
+println!("not padded: {:5}", format_args!("..."));
+```
+Use instead:
+```
+println!("{}", 1.0);
+
+println!("not padded: {}", format_args!("..."));
+// OR
+println!("padded: {:5}", format!("..."));
+```
+
+[formatting parameters]: https://doc.rust-lang.org/std/fmt/index.html#formatting-parameters \ No newline at end of file
diff --git a/src/tools/clippy/src/docs/write_literal.txt b/src/tools/clippy/src/docs/write_literal.txt
index 9c41a48f9..a7a884d08 100644
--- a/src/tools/clippy/src/docs/write_literal.txt
+++ b/src/tools/clippy/src/docs/write_literal.txt
@@ -6,10 +6,6 @@ Using literals as `writeln!` args is inefficient
(c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary
(i.e., just put the literal in the format string)
-### Known problems
-Will also warn with macro calls as arguments that expand to literals
--- e.g., `writeln!(buf, "{}", env!("FOO"))`.
-
### Example
```
writeln!(buf, "{}", "foo");
diff --git a/src/tools/clippy/src/driver.rs b/src/tools/clippy/src/driver.rs
index 235eae5af..b12208ac6 100644
--- a/src/tools/clippy/src/driver.rs
+++ b/src/tools/clippy/src/driver.rs
@@ -193,8 +193,8 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
let xs: Vec<Cow<'static, str>> = vec![
"the compiler unexpectedly panicked. this is a bug.".into(),
- format!("we would appreciate a bug report: {}", bug_report_url).into(),
- format!("Clippy version: {}", version_info).into(),
+ format!("we would appreciate a bug report: {bug_report_url}").into(),
+ format!("Clippy version: {version_info}").into(),
];
for note in &xs {
@@ -290,7 +290,7 @@ pub fn main() {
if orig_args.iter().any(|a| a == "--version" || a == "-V") {
let version_info = rustc_tools_util::get_version_info!();
- println!("{}", version_info);
+ println!("{version_info}");
exit(0);
}
diff --git a/src/tools/clippy/src/main.rs b/src/tools/clippy/src/main.rs
index 4a32e0e54..fce3cdfc4 100644
--- a/src/tools/clippy/src/main.rs
+++ b/src/tools/clippy/src/main.rs
@@ -37,12 +37,12 @@ You can use tool lints to allow or deny lints from your code, eg.:
"#;
fn show_help() {
- println!("{}", CARGO_CLIPPY_HELP);
+ println!("{CARGO_CLIPPY_HELP}");
}
fn show_version() {
let version_info = rustc_tools_util::get_version_info!();
- println!("{}", version_info);
+ println!("{version_info}");
}
pub fn main() {
@@ -133,7 +133,7 @@ impl ClippyCmd {
let clippy_args: String = self
.clippy_args
.iter()
- .map(|arg| format!("{}__CLIPPY_HACKERY__", arg))
+ .map(|arg| format!("{arg}__CLIPPY_HACKERY__"))
.collect();
// Currently, `CLIPPY_TERMINAL_WIDTH` is used only to format "unknown field" error messages.
diff --git a/src/tools/clippy/tests/compile-test.rs b/src/tools/clippy/tests/compile-test.rs
index ba6186e59..c10ee969c 100644
--- a/src/tools/clippy/tests/compile-test.rs
+++ b/src/tools/clippy/tests/compile-test.rs
@@ -111,15 +111,14 @@ static EXTERN_FLAGS: LazyLock<String> = LazyLock::new(|| {
.collect();
assert!(
not_found.is_empty(),
- "dependencies not found in depinfo: {:?}\n\
+ "dependencies not found in depinfo: {not_found:?}\n\
help: Make sure the `-Z binary-dep-depinfo` rust flag is enabled\n\
help: Try adding to dev-dependencies in Cargo.toml\n\
help: Be sure to also add `extern crate ...;` to tests/compile-test.rs",
- not_found,
);
crates
.into_iter()
- .map(|(name, path)| format!(" --extern {}={}", name, path))
+ .map(|(name, path)| format!(" --extern {name}={path}"))
.collect()
});
@@ -150,9 +149,8 @@ fn base_config(test_dir: &str) -> compiletest::Config {
.map(|p| format!(" -L dependency={}", Path::new(p).join("deps").display()))
.unwrap_or_default();
config.target_rustcflags = Some(format!(
- "--emit=metadata -Dwarnings -Zui-testing -L dependency={}{}{}",
+ "--emit=metadata -Dwarnings -Zui-testing -L dependency={}{host_libs}{}",
deps_path.display(),
- host_libs,
&*EXTERN_FLAGS,
));
@@ -239,7 +237,7 @@ fn run_ui_toml() {
Ok(true) => {},
Ok(false) => panic!("Some tests failed"),
Err(e) => {
- panic!("I/O failure during tests: {:?}", e);
+ panic!("I/O failure during tests: {e:?}");
},
}
}
@@ -285,7 +283,7 @@ fn run_ui_cargo() {
env::set_current_dir(&src_path)?;
let cargo_toml_path = case.path().join("Cargo.toml");
- let cargo_content = fs::read(&cargo_toml_path)?;
+ let cargo_content = fs::read(cargo_toml_path)?;
let cargo_parsed: toml::Value = toml::from_str(
std::str::from_utf8(&cargo_content).expect("`Cargo.toml` is not a valid utf-8 file!"),
)
@@ -348,7 +346,7 @@ fn run_ui_cargo() {
Ok(true) => {},
Ok(false) => panic!("Some tests failed"),
Err(e) => {
- panic!("I/O failure during tests: {:?}", e);
+ panic!("I/O failure during tests: {e:?}");
},
}
}
@@ -419,16 +417,15 @@ fn check_rustfix_coverage() {
if rs_path.starts_with("tests/ui/crashes") {
continue;
}
- assert!(rs_path.starts_with("tests/ui/"), "{:?}", rs_file);
+ assert!(rs_path.starts_with("tests/ui/"), "{rs_file:?}");
let filename = rs_path.strip_prefix("tests/ui/").unwrap();
assert!(
RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS
.binary_search_by_key(&filename, Path::new)
.is_ok(),
- "`{}` runs `MachineApplicable` diagnostics but is missing a `run-rustfix` annotation. \
+ "`{rs_file}` runs `MachineApplicable` diagnostics but is missing a `run-rustfix` annotation. \
Please either add `// run-rustfix` at the top of the file or add the file to \
`RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS` in `tests/compile-test.rs`.",
- rs_file,
);
}
}
@@ -478,15 +475,13 @@ fn ui_cargo_toml_metadata() {
.map(|component| component.as_os_str().to_string_lossy().replace('-', "_"))
.any(|s| *s == name)
|| path.starts_with(&cargo_common_metadata_path),
- "{:?} has incorrect package name",
- path
+ "{path:?} has incorrect package name"
);
let publish = package.get("publish").and_then(toml::Value::as_bool).unwrap_or(true);
assert!(
!publish || publish_exceptions.contains(&path.parent().unwrap().to_path_buf()),
- "{:?} lacks `publish = false`",
- path
+ "{path:?} lacks `publish = false`"
);
}
}
diff --git a/src/tools/clippy/tests/dogfood.rs b/src/tools/clippy/tests/dogfood.rs
index 961525bbd..6d0022f7a 100644
--- a/src/tools/clippy/tests/dogfood.rs
+++ b/src/tools/clippy/tests/dogfood.rs
@@ -20,7 +20,14 @@ fn dogfood_clippy() {
}
// "" is the root package
- for package in &["", "clippy_dev", "clippy_lints", "clippy_utils", "rustc_tools_util"] {
+ for package in &[
+ "",
+ "clippy_dev",
+ "clippy_lints",
+ "clippy_utils",
+ "lintcheck",
+ "rustc_tools_util",
+ ] {
run_clippy_for_package(package, &["-D", "clippy::all", "-D", "clippy::pedantic"]);
}
}
diff --git a/src/tools/clippy/tests/integration.rs b/src/tools/clippy/tests/integration.rs
index 23a9bef3c..818ff70b3 100644
--- a/src/tools/clippy/tests/integration.rs
+++ b/src/tools/clippy/tests/integration.rs
@@ -6,10 +6,15 @@ use std::env;
use std::ffi::OsStr;
use std::process::Command;
+#[cfg(not(windows))]
+const CARGO_CLIPPY: &str = "cargo-clippy";
+#[cfg(windows)]
+const CARGO_CLIPPY: &str = "cargo-clippy.exe";
+
#[cfg_attr(feature = "integration", test)]
fn integration_test() {
let repo_name = env::var("INTEGRATION").expect("`INTEGRATION` var not set");
- let repo_url = format!("https://github.com/{}", repo_name);
+ let repo_url = format!("https://github.com/{repo_name}");
let crate_name = repo_name
.split('/')
.nth(1)
@@ -31,7 +36,7 @@ fn integration_test() {
let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let target_dir = std::path::Path::new(&root_dir).join("target");
- let clippy_binary = target_dir.join(env!("PROFILE")).join("cargo-clippy");
+ let clippy_binary = target_dir.join(env!("PROFILE")).join(CARGO_CLIPPY);
let output = Command::new(clippy_binary)
.current_dir(repo_dir)
@@ -51,17 +56,15 @@ fn integration_test() {
.expect("unable to run clippy");
let stderr = String::from_utf8_lossy(&output.stderr);
- if stderr.contains("internal compiler error") {
- let backtrace_start = stderr
- .find("thread 'rustc' panicked at")
- .expect("start of backtrace not found");
- let backtrace_end = stderr
- .rfind("error: internal compiler error")
+ if let Some(backtrace_start) = stderr.find("error: internal compiler error") {
+ static BACKTRACE_END_MSG: &str = "end of query stack";
+ let backtrace_end = stderr[backtrace_start..]
+ .find(BACKTRACE_END_MSG)
.expect("end of backtrace not found");
panic!(
"internal compiler error\nBacktrace:\n\n{}",
- &stderr[backtrace_start..backtrace_end]
+ &stderr[backtrace_start..backtrace_start + backtrace_end + BACKTRACE_END_MSG.len()]
);
} else if stderr.contains("query stack during panic") {
panic!("query stack during panic in the output");
@@ -83,7 +86,7 @@ fn integration_test() {
match output.status.code() {
Some(0) => println!("Compilation successful"),
- Some(code) => eprintln!("Compilation failed. Exit code: {}", code),
+ Some(code) => eprintln!("Compilation failed. Exit code: {code}"),
None => panic!("Process terminated by signal"),
}
}
diff --git a/src/tools/clippy/tests/lint_message_convention.rs b/src/tools/clippy/tests/lint_message_convention.rs
index 2e0f4e760..abd0d1bc5 100644
--- a/src/tools/clippy/tests/lint_message_convention.rs
+++ b/src/tools/clippy/tests/lint_message_convention.rs
@@ -102,7 +102,7 @@ fn lint_message_convention() {
"error: the test '{}' contained the following nonconforming lines :",
message.path.display()
);
- message.bad_lines.iter().for_each(|line| eprintln!("{}", line));
+ message.bad_lines.iter().for_each(|line| eprintln!("{line}"));
eprintln!("\n\n");
}
diff --git a/src/tools/clippy/tests/missing-test-files.rs b/src/tools/clippy/tests/missing-test-files.rs
index 7d6edc2b1..caedd5d76 100644
--- a/src/tools/clippy/tests/missing-test-files.rs
+++ b/src/tools/clippy/tests/missing-test-files.rs
@@ -17,7 +17,7 @@ fn test_missing_tests() {
"Didn't see a test file for the following files:\n\n{}\n",
missing_files
.iter()
- .map(|s| format!("\t{}", s))
+ .map(|s| format!("\t{s}"))
.collect::<Vec<_>>()
.join("\n")
);
diff --git a/src/tools/clippy/tests/ui-cargo/duplicate_mod/fail/src/main.stderr b/src/tools/clippy/tests/ui-cargo/duplicate_mod/fail/src/main.stderr
index b450a2b18..3b80d89a6 100644
--- a/src/tools/clippy/tests/ui-cargo/duplicate_mod/fail/src/main.stderr
+++ b/src/tools/clippy/tests/ui-cargo/duplicate_mod/fail/src/main.stderr
@@ -7,8 +7,8 @@ LL | / #[path = "b.rs"]
LL | | mod b2;
| |_______^ loaded again here
|
- = note: `-D clippy::duplicate-mod` implied by `-D warnings`
= help: replace all but one `mod` item with `use` items
+ = note: `-D clippy::duplicate-mod` implied by `-D warnings`
error: file is loaded as a module multiple times: `$DIR/c.rs`
--> $DIR/main.rs:9:1
diff --git a/src/tools/clippy/tests/ui-cargo/feature_name/fail/src/main.stderr b/src/tools/clippy/tests/ui-cargo/feature_name/fail/src/main.stderr
index b9e6cb49b..c6a11fa93 100644
--- a/src/tools/clippy/tests/ui-cargo/feature_name/fail/src/main.stderr
+++ b/src/tools/clippy/tests/ui-cargo/feature_name/fail/src/main.stderr
@@ -1,7 +1,7 @@
error: the "no-" prefix in the feature name "no-qaq" is negative
|
- = note: `-D clippy::negative-feature-names` implied by `-D warnings`
= help: consider renaming the feature to "qaq", but make sure the feature adds functionality
+ = note: `-D clippy::negative-feature-names` implied by `-D warnings`
error: the "no_" prefix in the feature name "no_qaq" is negative
|
@@ -17,8 +17,8 @@ error: the "not_" prefix in the feature name "not_orz" is negative
error: the "-support" suffix in the feature name "qvq-support" is redundant
|
- = note: `-D clippy::redundant-feature-names` implied by `-D warnings`
= help: consider renaming the feature to "qvq"
+ = note: `-D clippy::redundant-feature-names` implied by `-D warnings`
error: the "_support" suffix in the feature name "qvq_support" is redundant
|
diff --git a/src/tools/clippy/tests/ui-cargo/module_style/fail_mod/src/main.stderr b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod/src/main.stderr
index e2010e998..697c8b57c 100644
--- a/src/tools/clippy/tests/ui-cargo/module_style/fail_mod/src/main.stderr
+++ b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod/src/main.stderr
@@ -4,8 +4,8 @@ error: `mod.rs` files are required, found `bad/inner.rs`
LL | pub mod stuff;
| ^
|
- = note: `-D clippy::self-named-module-files` implied by `-D warnings`
= help: move `bad/inner.rs` to `bad/inner/mod.rs`
+ = note: `-D clippy::self-named-module-files` implied by `-D warnings`
error: `mod.rs` files are required, found `bad/inner/stuff.rs`
--> $DIR/bad/inner/stuff.rs:1:1
diff --git a/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/Cargo.toml b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/Cargo.toml
new file mode 100644
index 000000000..a822fad38
--- /dev/null
+++ b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "fail-mod-remap"
+version = "0.1.0"
+edition = "2018"
+publish = false
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/bad.rs b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/bad.rs
new file mode 100644
index 000000000..509aad186
--- /dev/null
+++ b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/bad.rs
@@ -0,0 +1 @@
+pub mod inner;
diff --git a/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/bad/inner.rs b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/bad/inner.rs
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/bad/inner.rs
@@ -0,0 +1 @@
+
diff --git a/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.rs b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.rs
new file mode 100644
index 000000000..ba4c8c873
--- /dev/null
+++ b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.rs
@@ -0,0 +1,7 @@
+// compile-flags: --remap-path-prefix {{src-base}}=/remapped
+
+#![warn(clippy::self_named_module_files)]
+
+mod bad;
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.stderr b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.stderr
new file mode 100644
index 000000000..ea6ea9806
--- /dev/null
+++ b/src/tools/clippy/tests/ui-cargo/module_style/fail_mod_remap/src/main.stderr
@@ -0,0 +1,11 @@
+error: `mod.rs` files are required, found `bad.rs`
+ --> /remapped/module_style/fail_mod_remap/src/bad.rs:1:1
+ |
+LL | pub mod inner;
+ | ^
+ |
+ = help: move `bad.rs` to `bad/mod.rs`
+ = note: `-D clippy::self-named-module-files` implied by `-D warnings`
+
+error: aborting due to previous error
+
diff --git a/src/tools/clippy/tests/ui-cargo/module_style/fail_no_mod/src/main.stderr b/src/tools/clippy/tests/ui-cargo/module_style/fail_no_mod/src/main.stderr
index f91940209..f40ceea23 100644
--- a/src/tools/clippy/tests/ui-cargo/module_style/fail_no_mod/src/main.stderr
+++ b/src/tools/clippy/tests/ui-cargo/module_style/fail_no_mod/src/main.stderr
@@ -4,8 +4,8 @@ error: `mod.rs` files are not allowed, found `bad/mod.rs`
LL | pub struct Thing;
| ^
|
- = note: `-D clippy::mod-module-files` implied by `-D warnings`
= help: move `bad/mod.rs` to `bad.rs`
+ = note: `-D clippy::mod-module-files` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui-internal/auxiliary/paths.rs b/src/tools/clippy/tests/ui-internal/auxiliary/paths.rs
new file mode 100644
index 000000000..52fcaec4d
--- /dev/null
+++ b/src/tools/clippy/tests/ui-internal/auxiliary/paths.rs
@@ -0,0 +1,2 @@
+pub static OPTION: [&str; 3] = ["core", "option", "Option"];
+pub const RESULT: &[&str] = &["core", "result", "Result"];
diff --git a/src/tools/clippy/tests/ui-internal/check_clippy_version_attribute.stderr b/src/tools/clippy/tests/ui-internal/check_clippy_version_attribute.stderr
index 2aa4de490..fd8c8379f 100644
--- a/src/tools/clippy/tests/ui-internal/check_clippy_version_attribute.stderr
+++ b/src/tools/clippy/tests/ui-internal/check_clippy_version_attribute.stderr
@@ -10,13 +10,13 @@ LL | | report_in_external_macro: true
LL | | }
| |_^
|
+ = help: please use a valid semantic version, see `doc/adding_lints.md`
note: the lint level is defined here
--> $DIR/check_clippy_version_attribute.rs:1:9
|
LL | #![deny(clippy::internal)]
| ^^^^^^^^^^^^^^^^
= note: `#[deny(clippy::invalid_clippy_version_attribute)]` implied by `#[deny(clippy::internal)]`
- = help: please use a valid semantic version, see `doc/adding_lints.md`
= note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this item has an invalid `clippy::version` attribute
@@ -46,8 +46,8 @@ LL | | report_in_external_macro: true
LL | | }
| |_^
|
- = note: `#[deny(clippy::missing_clippy_version_attribute)]` implied by `#[deny(clippy::internal)]`
= help: please use a `clippy::version` attribute, see `doc/adding_lints.md`
+ = note: `#[deny(clippy::missing_clippy_version_attribute)]` implied by `#[deny(clippy::internal)]`
= note: this error originates in the macro `$crate::declare_tool_lint` which comes from the expansion of the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this lint is missing the `clippy::version` attribute or version value
diff --git a/src/tools/clippy/tests/ui-internal/custom_ice_message.stderr b/src/tools/clippy/tests/ui-internal/custom_ice_message.stderr
index a1b8e2ee1..07c594101 100644
--- a/src/tools/clippy/tests/ui-internal/custom_ice_message.stderr
+++ b/src/tools/clippy/tests/ui-internal/custom_ice_message.stderr
@@ -1,4 +1,4 @@
-thread 'rustc' panicked at 'Would you like some help with that?', clippy_lints/src/utils/internal_lints.rs
+thread 'rustc' panicked at 'Would you like some help with that?', clippy_lints/src/utils/internal_lints/produce_ice.rs:28:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: internal compiler error: unexpected panic
diff --git a/src/tools/clippy/tests/ui-internal/if_chain_style.stderr b/src/tools/clippy/tests/ui-internal/if_chain_style.stderr
index 24106510e..d8f1ffb21 100644
--- a/src/tools/clippy/tests/ui-internal/if_chain_style.stderr
+++ b/src/tools/clippy/tests/ui-internal/if_chain_style.stderr
@@ -10,12 +10,12 @@ LL | | }
LL | | }
| |_____^
|
- = note: `-D clippy::if-chain-style` implied by `-D warnings`
help: this `let` statement can also be in the `if_chain!`
--> $DIR/if_chain_style.rs:10:9
|
LL | let x = "";
| ^^^^^^^^^^^
+ = note: `-D clippy::if-chain-style` implied by `-D warnings`
error: `if a && b;` should be `if a; if b;`
--> $DIR/if_chain_style.rs:19:12
diff --git a/src/tools/clippy/tests/ui-internal/invalid_paths.rs b/src/tools/clippy/tests/ui-internal/invalid_paths.rs
index b823ff7fe..9a9790a4b 100644
--- a/src/tools/clippy/tests/ui-internal/invalid_paths.rs
+++ b/src/tools/clippy/tests/ui-internal/invalid_paths.rs
@@ -1,5 +1,5 @@
#![warn(clippy::internal)]
-#![allow(clippy::missing_clippy_version_attribute)]
+#![allow(clippy::missing_clippy_version_attribute, clippy::unnecessary_def_path)]
mod paths {
// Good path
diff --git a/src/tools/clippy/tests/ui-internal/match_type_on_diag_item.rs b/src/tools/clippy/tests/ui-internal/match_type_on_diag_item.rs
deleted file mode 100644
index 4b41ff15e..000000000
--- a/src/tools/clippy/tests/ui-internal/match_type_on_diag_item.rs
+++ /dev/null
@@ -1,39 +0,0 @@
-#![deny(clippy::internal)]
-#![allow(clippy::missing_clippy_version_attribute)]
-#![feature(rustc_private)]
-
-extern crate clippy_utils;
-extern crate rustc_hir;
-extern crate rustc_lint;
-extern crate rustc_middle;
-
-#[macro_use]
-extern crate rustc_session;
-use clippy_utils::{paths, ty::match_type};
-use rustc_hir::Expr;
-use rustc_lint::{LateContext, LateLintPass};
-use rustc_middle::ty::Ty;
-
-declare_lint! {
- pub TEST_LINT,
- Warn,
- ""
-}
-
-declare_lint_pass!(Pass => [TEST_LINT]);
-
-static OPTION: [&str; 3] = ["core", "option", "Option"];
-
-impl<'tcx> LateLintPass<'tcx> for Pass {
- fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr) {
- let ty = cx.typeck_results().expr_ty(expr);
-
- let _ = match_type(cx, ty, &OPTION);
- let _ = match_type(cx, ty, &["core", "result", "Result"]);
-
- let rc_path = &["alloc", "rc", "Rc"];
- let _ = clippy_utils::ty::match_type(cx, ty, rc_path);
- }
-}
-
-fn main() {}
diff --git a/src/tools/clippy/tests/ui-internal/match_type_on_diag_item.stderr b/src/tools/clippy/tests/ui-internal/match_type_on_diag_item.stderr
deleted file mode 100644
index e3cb6b6c2..000000000
--- a/src/tools/clippy/tests/ui-internal/match_type_on_diag_item.stderr
+++ /dev/null
@@ -1,27 +0,0 @@
-error: usage of `clippy_utils::ty::match_type()` on a type diagnostic item
- --> $DIR/match_type_on_diag_item.rs:31:17
- |
-LL | let _ = match_type(cx, ty, &OPTION);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clippy_utils::ty::is_type_diagnostic_item(cx, ty, sym::Option)`
- |
-note: the lint level is defined here
- --> $DIR/match_type_on_diag_item.rs:1:9
- |
-LL | #![deny(clippy::internal)]
- | ^^^^^^^^^^^^^^^^
- = note: `#[deny(clippy::match_type_on_diagnostic_item)]` implied by `#[deny(clippy::internal)]`
-
-error: usage of `clippy_utils::ty::match_type()` on a type diagnostic item
- --> $DIR/match_type_on_diag_item.rs:32:17
- |
-LL | let _ = match_type(cx, ty, &["core", "result", "Result"]);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clippy_utils::ty::is_type_diagnostic_item(cx, ty, sym::Result)`
-
-error: usage of `clippy_utils::ty::match_type()` on a type diagnostic item
- --> $DIR/match_type_on_diag_item.rs:35:17
- |
-LL | let _ = clippy_utils::ty::match_type(cx, ty, rc_path);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `clippy_utils::ty::is_type_diagnostic_item(cx, ty, sym::Rc)`
-
-error: aborting due to 3 previous errors
-
diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed
new file mode 100644
index 000000000..cbbb46523
--- /dev/null
+++ b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.fixed
@@ -0,0 +1,62 @@
+// run-rustfix
+// aux-build:paths.rs
+#![deny(clippy::internal)]
+#![feature(rustc_private)]
+
+extern crate clippy_utils;
+extern crate paths;
+extern crate rustc_hir;
+extern crate rustc_lint;
+extern crate rustc_middle;
+extern crate rustc_span;
+
+#[allow(unused)]
+use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item, match_type};
+#[allow(unused)]
+use clippy_utils::{
+ is_expr_path_def_path, is_path_diagnostic_item, is_res_diagnostic_ctor, is_res_lang_ctor, is_trait_method,
+ match_def_path, match_trait_method, path_res,
+};
+
+#[allow(unused)]
+use rustc_hir::LangItem;
+#[allow(unused)]
+use rustc_span::sym;
+
+use rustc_hir::def_id::DefId;
+use rustc_hir::Expr;
+use rustc_lint::LateContext;
+use rustc_middle::ty::Ty;
+
+#[allow(unused, clippy::unnecessary_def_path)]
+static OPTION: [&str; 3] = ["core", "option", "Option"];
+#[allow(unused, clippy::unnecessary_def_path)]
+const RESULT: &[&str] = &["core", "result", "Result"];
+
+fn _f<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, did: DefId, expr: &Expr<'_>) {
+ let _ = is_type_diagnostic_item(cx, ty, sym::Option);
+ let _ = is_type_diagnostic_item(cx, ty, sym::Result);
+ let _ = is_type_diagnostic_item(cx, ty, sym::Result);
+
+ #[allow(unused, clippy::unnecessary_def_path)]
+ let rc_path = &["alloc", "rc", "Rc"];
+ let _ = is_type_diagnostic_item(cx, ty, sym::Rc);
+
+ let _ = is_type_diagnostic_item(cx, ty, sym::Option);
+ let _ = is_type_diagnostic_item(cx, ty, sym::Result);
+
+ let _ = is_type_lang_item(cx, ty, LangItem::OwnedBox);
+ let _ = is_type_diagnostic_item(cx, ty, sym::maybe_uninit_uninit);
+
+ let _ = cx.tcx.lang_items().require(LangItem::OwnedBox).ok() == Some(did);
+ let _ = cx.tcx.is_diagnostic_item(sym::Option, did);
+ let _ = cx.tcx.lang_items().require(LangItem::OptionSome).ok() == Some(did);
+
+ let _ = is_trait_method(cx, expr, sym::AsRef);
+
+ let _ = is_path_diagnostic_item(cx, expr, sym::Option);
+ let _ = path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().require(LangItem::IteratorNext).ok() == Some(id));
+ let _ = is_res_lang_ctor(cx, path_res(cx, expr), LangItem::OptionSome);
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs
new file mode 100644
index 000000000..f17fed6c6
--- /dev/null
+++ b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.rs
@@ -0,0 +1,62 @@
+// run-rustfix
+// aux-build:paths.rs
+#![deny(clippy::internal)]
+#![feature(rustc_private)]
+
+extern crate clippy_utils;
+extern crate paths;
+extern crate rustc_hir;
+extern crate rustc_lint;
+extern crate rustc_middle;
+extern crate rustc_span;
+
+#[allow(unused)]
+use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item, match_type};
+#[allow(unused)]
+use clippy_utils::{
+ is_expr_path_def_path, is_path_diagnostic_item, is_res_diagnostic_ctor, is_res_lang_ctor, is_trait_method,
+ match_def_path, match_trait_method, path_res,
+};
+
+#[allow(unused)]
+use rustc_hir::LangItem;
+#[allow(unused)]
+use rustc_span::sym;
+
+use rustc_hir::def_id::DefId;
+use rustc_hir::Expr;
+use rustc_lint::LateContext;
+use rustc_middle::ty::Ty;
+
+#[allow(unused, clippy::unnecessary_def_path)]
+static OPTION: [&str; 3] = ["core", "option", "Option"];
+#[allow(unused, clippy::unnecessary_def_path)]
+const RESULT: &[&str] = &["core", "result", "Result"];
+
+fn _f<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, did: DefId, expr: &Expr<'_>) {
+ let _ = match_type(cx, ty, &OPTION);
+ let _ = match_type(cx, ty, RESULT);
+ let _ = match_type(cx, ty, &["core", "result", "Result"]);
+
+ #[allow(unused, clippy::unnecessary_def_path)]
+ let rc_path = &["alloc", "rc", "Rc"];
+ let _ = clippy_utils::ty::match_type(cx, ty, rc_path);
+
+ let _ = match_type(cx, ty, &paths::OPTION);
+ let _ = match_type(cx, ty, paths::RESULT);
+
+ let _ = match_type(cx, ty, &["alloc", "boxed", "Box"]);
+ let _ = match_type(cx, ty, &["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"]);
+
+ let _ = match_def_path(cx, did, &["alloc", "boxed", "Box"]);
+ let _ = match_def_path(cx, did, &["core", "option", "Option"]);
+ let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]);
+
+ let _ = match_trait_method(cx, expr, &["core", "convert", "AsRef"]);
+
+ let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option"]);
+ let _ = is_expr_path_def_path(cx, expr, &["core", "iter", "traits", "Iterator", "next"]);
+ let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option", "Some"]);
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_def_path.stderr b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.stderr
new file mode 100644
index 000000000..a99a8f71f
--- /dev/null
+++ b/src/tools/clippy/tests/ui-internal/unnecessary_def_path.stderr
@@ -0,0 +1,101 @@
+error: use of a def path to a diagnostic item
+ --> $DIR/unnecessary_def_path.rs:37:13
+ |
+LL | let _ = match_type(cx, ty, &OPTION);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Option)`
+ |
+note: the lint level is defined here
+ --> $DIR/unnecessary_def_path.rs:3:9
+ |
+LL | #![deny(clippy::internal)]
+ | ^^^^^^^^^^^^^^^^
+ = note: `#[deny(clippy::unnecessary_def_path)]` implied by `#[deny(clippy::internal)]`
+
+error: use of a def path to a diagnostic item
+ --> $DIR/unnecessary_def_path.rs:38:13
+ |
+LL | let _ = match_type(cx, ty, RESULT);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)`
+
+error: use of a def path to a diagnostic item
+ --> $DIR/unnecessary_def_path.rs:39:13
+ |
+LL | let _ = match_type(cx, ty, &["core", "result", "Result"]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)`
+
+error: use of a def path to a diagnostic item
+ --> $DIR/unnecessary_def_path.rs:43:13
+ |
+LL | let _ = clippy_utils::ty::match_type(cx, ty, rc_path);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Rc)`
+
+error: use of a def path to a diagnostic item
+ --> $DIR/unnecessary_def_path.rs:45:13
+ |
+LL | let _ = match_type(cx, ty, &paths::OPTION);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Option)`
+
+error: use of a def path to a diagnostic item
+ --> $DIR/unnecessary_def_path.rs:46:13
+ |
+LL | let _ = match_type(cx, ty, paths::RESULT);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::Result)`
+
+error: use of a def path to a `LangItem`
+ --> $DIR/unnecessary_def_path.rs:48:13
+ |
+LL | let _ = match_type(cx, ty, &["alloc", "boxed", "Box"]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_lang_item(cx, ty, LangItem::OwnedBox)`
+
+error: use of a def path to a diagnostic item
+ --> $DIR/unnecessary_def_path.rs:49:13
+ |
+LL | let _ = match_type(cx, ty, &["core", "mem", "maybe_uninit", "MaybeUninit", "uninit"]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_type_diagnostic_item(cx, ty, sym::maybe_uninit_uninit)`
+
+error: use of a def path to a `LangItem`
+ --> $DIR/unnecessary_def_path.rs:51:13
+ |
+LL | let _ = match_def_path(cx, did, &["alloc", "boxed", "Box"]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().require(LangItem::OwnedBox).ok() == Some(did)`
+
+error: use of a def path to a diagnostic item
+ --> $DIR/unnecessary_def_path.rs:52:13
+ |
+LL | let _ = match_def_path(cx, did, &["core", "option", "Option"]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.is_diagnostic_item(sym::Option, did)`
+
+error: use of a def path to a `LangItem`
+ --> $DIR/unnecessary_def_path.rs:53:13
+ |
+LL | let _ = match_def_path(cx, did, &["core", "option", "Option", "Some"]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `cx.tcx.lang_items().require(LangItem::OptionSome).ok() == Some(did)`
+ |
+ = help: if this `DefId` came from a constructor expression or pattern then the parent `DefId` should be used instead
+
+error: use of a def path to a diagnostic item
+ --> $DIR/unnecessary_def_path.rs:55:13
+ |
+LL | let _ = match_trait_method(cx, expr, &["core", "convert", "AsRef"]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_trait_method(cx, expr, sym::AsRef)`
+
+error: use of a def path to a diagnostic item
+ --> $DIR/unnecessary_def_path.rs:57:13
+ |
+LL | let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option"]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_path_diagnostic_item(cx, expr, sym::Option)`
+
+error: use of a def path to a `LangItem`
+ --> $DIR/unnecessary_def_path.rs:58:13
+ |
+LL | let _ = is_expr_path_def_path(cx, expr, &["core", "iter", "traits", "Iterator", "next"]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `path_res(cx, expr).opt_def_id().map_or(false, |id| cx.tcx.lang_items().require(LangItem::IteratorNext).ok() == Some(id))`
+
+error: use of a def path to a `LangItem`
+ --> $DIR/unnecessary_def_path.rs:59:13
+ |
+LL | let _ = is_expr_path_def_path(cx, expr, &["core", "option", "Option", "Some"]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `is_res_lang_ctor(cx, path_res(cx, expr), LangItem::OptionSome)`
+
+error: aborting due to 15 previous errors
+
diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_def_path_hardcoded_path.rs b/src/tools/clippy/tests/ui-internal/unnecessary_def_path_hardcoded_path.rs
new file mode 100644
index 000000000..b5ff3a542
--- /dev/null
+++ b/src/tools/clippy/tests/ui-internal/unnecessary_def_path_hardcoded_path.rs
@@ -0,0 +1,16 @@
+#![feature(rustc_private)]
+#![allow(unused)]
+#![warn(clippy::unnecessary_def_path)]
+
+extern crate rustc_hir;
+
+use rustc_hir::LangItem;
+
+fn main() {
+ const DEREF_TRAIT: [&str; 4] = ["core", "ops", "deref", "Deref"];
+ const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"];
+ const DEREF_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "Deref", "deref"];
+
+ // Don't lint, not yet a diagnostic or language item
+ const DEREF_MUT_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "DerefMut", "deref_mut"];
+}
diff --git a/src/tools/clippy/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr b/src/tools/clippy/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr
new file mode 100644
index 000000000..af46d87bf
--- /dev/null
+++ b/src/tools/clippy/tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr
@@ -0,0 +1,27 @@
+error: hardcoded path to a language item
+ --> $DIR/unnecessary_def_path_hardcoded_path.rs:11:40
+ |
+LL | const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: convert all references to use `LangItem::DerefMut`
+ = note: `-D clippy::unnecessary-def-path` implied by `-D warnings`
+
+error: hardcoded path to a diagnostic item
+ --> $DIR/unnecessary_def_path_hardcoded_path.rs:12:43
+ |
+LL | const DEREF_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "Deref", "deref"];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: convert all references to use `sym::deref_method`
+
+error: hardcoded path to a diagnostic item
+ --> $DIR/unnecessary_def_path_hardcoded_path.rs:10:36
+ |
+LL | const DEREF_TRAIT: [&str; 4] = ["core", "ops", "deref", "Deref"];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: convert all references to use `sym::Deref`
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr b/src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr
index 62c45b546..4c7599843 100644
--- a/src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr
+++ b/src/tools/clippy/tests/ui-toml/await_holding_invalid_type/await_holding_invalid_type.stderr
@@ -4,8 +4,8 @@ error: `std::string::String` may not be held across an `await` point per `clippy
LL | let _x = String::from("hello");
| ^^
|
- = note: `-D clippy::await-holding-invalid-type` implied by `-D warnings`
= note: strings are bad
+ = note: `-D clippy::await-holding-invalid-type` implied by `-D warnings`
error: `std::net::Ipv4Addr` may not be held across an `await` point per `clippy.toml`
--> $DIR/await_holding_invalid_type.rs:10:9
diff --git a/src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs b/src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs
index b4e677ea1..7f1c512d7 100644
--- a/src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs
+++ b/src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::uninlined_format_args)]
+
fn main() {}
#[warn(clippy::cognitive_complexity)]
diff --git a/src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr b/src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr
index 4c560299e..630bad07c 100644
--- a/src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr
+++ b/src/tools/clippy/tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr
@@ -3,13 +3,13 @@ warning: error reading Clippy's configuration file `$DIR/clippy.toml`: deprecate
warning: error reading Clippy's configuration file `$DIR/clippy.toml`: deprecated field `blacklisted-names`. Please use `disallowed-names` instead
error: the function has a cognitive complexity of (3/2)
- --> $DIR/conf_deprecated_key.rs:4:4
+ --> $DIR/conf_deprecated_key.rs:6:4
|
LL | fn cognitive_complexity() {
| ^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::cognitive-complexity` implied by `-D warnings`
= help: you could split it up into multiple smaller functions
+ = note: `-D clippy::cognitive-complexity` implied by `-D warnings`
error: aborting due to previous error; 2 warnings emitted
diff --git a/src/tools/clippy/tests/ui-toml/disallowed_macros/auxiliary/macros.rs b/src/tools/clippy/tests/ui-toml/disallowed_macros/auxiliary/macros.rs
new file mode 100644
index 000000000..fcaeace0e
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/disallowed_macros/auxiliary/macros.rs
@@ -0,0 +1,32 @@
+#[macro_export]
+macro_rules! expr {
+ () => {
+ 1
+ };
+}
+
+#[macro_export]
+macro_rules! stmt {
+ () => {
+ let _x = ();
+ };
+}
+
+#[macro_export]
+macro_rules! ty {
+ () => { &'static str };
+}
+
+#[macro_export]
+macro_rules! pat {
+ () => {
+ _
+ };
+}
+
+#[macro_export]
+macro_rules! item {
+ () => {
+ const ITEM: usize = 1;
+ };
+}
diff --git a/src/tools/clippy/tests/ui-toml/disallowed_macros/clippy.toml b/src/tools/clippy/tests/ui-toml/disallowed_macros/clippy.toml
new file mode 100644
index 000000000..c8fe8be9a
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/disallowed_macros/clippy.toml
@@ -0,0 +1,11 @@
+disallowed-macros = [
+ "std::println",
+ "std::vec",
+ { path = "std::cfg" },
+ { path = "serde::Serialize", reason = "no serializing" },
+ "macros::expr",
+ "macros::stmt",
+ "macros::ty",
+ "macros::pat",
+ "macros::item",
+]
diff --git a/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.rs b/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.rs
new file mode 100644
index 000000000..2bb537607
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.rs
@@ -0,0 +1,39 @@
+// aux-build:macros.rs
+
+#![allow(unused)]
+
+extern crate macros;
+
+use serde::Serialize;
+
+fn main() {
+ println!("one");
+ println!("two");
+ cfg!(unix);
+ vec![1, 2, 3];
+
+ #[derive(Serialize)]
+ struct Derive;
+
+ let _ = macros::expr!();
+ macros::stmt!();
+ let macros::pat!() = 1;
+ let _: macros::ty!() = "";
+ macros::item!();
+
+ eprintln!("allowed");
+}
+
+struct S;
+
+impl S {
+ macros::item!();
+}
+
+trait Y {
+ macros::item!();
+}
+
+impl Y for S {
+ macros::item!();
+}
diff --git a/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.stderr b/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.stderr
new file mode 100644
index 000000000..aed9feb6f
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/disallowed_macros/disallowed_macros.stderr
@@ -0,0 +1,84 @@
+error: use of a disallowed macro `std::println`
+ --> $DIR/disallowed_macros.rs:10:5
+ |
+LL | println!("one");
+ | ^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::disallowed-macros` implied by `-D warnings`
+
+error: use of a disallowed macro `std::println`
+ --> $DIR/disallowed_macros.rs:11:5
+ |
+LL | println!("two");
+ | ^^^^^^^^^^^^^^^
+
+error: use of a disallowed macro `std::cfg`
+ --> $DIR/disallowed_macros.rs:12:5
+ |
+LL | cfg!(unix);
+ | ^^^^^^^^^^
+
+error: use of a disallowed macro `std::vec`
+ --> $DIR/disallowed_macros.rs:13:5
+ |
+LL | vec![1, 2, 3];
+ | ^^^^^^^^^^^^^
+
+error: use of a disallowed macro `serde::Serialize`
+ --> $DIR/disallowed_macros.rs:15:14
+ |
+LL | #[derive(Serialize)]
+ | ^^^^^^^^^
+ |
+ = note: no serializing (from clippy.toml)
+
+error: use of a disallowed macro `macros::expr`
+ --> $DIR/disallowed_macros.rs:18:13
+ |
+LL | let _ = macros::expr!();
+ | ^^^^^^^^^^^^^^^
+
+error: use of a disallowed macro `macros::stmt`
+ --> $DIR/disallowed_macros.rs:19:5
+ |
+LL | macros::stmt!();
+ | ^^^^^^^^^^^^^^^
+
+error: use of a disallowed macro `macros::pat`
+ --> $DIR/disallowed_macros.rs:20:9
+ |
+LL | let macros::pat!() = 1;
+ | ^^^^^^^^^^^^^^
+
+error: use of a disallowed macro `macros::ty`
+ --> $DIR/disallowed_macros.rs:21:12
+ |
+LL | let _: macros::ty!() = "";
+ | ^^^^^^^^^^^^^
+
+error: use of a disallowed macro `macros::item`
+ --> $DIR/disallowed_macros.rs:22:5
+ |
+LL | macros::item!();
+ | ^^^^^^^^^^^^^^^
+
+error: use of a disallowed macro `macros::item`
+ --> $DIR/disallowed_macros.rs:30:5
+ |
+LL | macros::item!();
+ | ^^^^^^^^^^^^^^^
+
+error: use of a disallowed macro `macros::item`
+ --> $DIR/disallowed_macros.rs:34:5
+ |
+LL | macros::item!();
+ | ^^^^^^^^^^^^^^^
+
+error: use of a disallowed macro `macros::item`
+ --> $DIR/disallowed_macros.rs:38:5
+ |
+LL | macros::item!();
+ | ^^^^^^^^^^^^^^^
+
+error: aborting due to 13 previous errors
+
diff --git a/src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr b/src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr
index c5d95cb8a..28a08599c 100644
--- a/src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr
+++ b/src/tools/clippy/tests/ui-toml/expect_used/expect_used.stderr
@@ -4,8 +4,8 @@ error: used `expect()` on `an Option` value
LL | let _ = opt.expect("");
| ^^^^^^^^^^^^^^
|
- = note: `-D clippy::expect-used` implied by `-D warnings`
= help: if this value is `None`, it will panic
+ = note: `-D clippy::expect-used` implied by `-D warnings`
error: used `expect()` on `a Result` value
--> $DIR/expect_used.rs:11:13
diff --git a/src/tools/clippy/tests/ui-toml/fn_params_excessive_bools/test.stderr b/src/tools/clippy/tests/ui-toml/fn_params_excessive_bools/test.stderr
index d05adc3d3..87bdb61c6 100644
--- a/src/tools/clippy/tests/ui-toml/fn_params_excessive_bools/test.stderr
+++ b/src/tools/clippy/tests/ui-toml/fn_params_excessive_bools/test.stderr
@@ -4,8 +4,8 @@ error: more than 1 bools in function parameters
LL | fn g(_: bool, _: bool) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings`
= help: consider refactoring bools into two-variant enums
+ = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr b/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr
index 6a685a583..7b5fb9e87 100644
--- a/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr
+++ b/src/tools/clippy/tests/ui-toml/large_include_file/large_include_file.stderr
@@ -4,8 +4,8 @@ error: attempted to include a large file
LL | const TOO_BIG_INCLUDE_BYTES: &[u8; 654] = include_bytes!("too_big.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::large-include-file` implied by `-D warnings`
= note: the configuration allows a maximum size of 600 bytes
+ = note: `-D clippy::large-include-file` implied by `-D warnings`
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: attempted to include a large file
diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed
new file mode 100644
index 000000000..01d135764
--- /dev/null
+++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.fixed
@@ -0,0 +1,62 @@
+// aux-build:proc_macro_derive.rs
+// run-rustfix
+
+#![warn(clippy::nonstandard_macro_braces)]
+
+extern crate proc_macro_derive;
+extern crate quote;
+
+use quote::quote;
+
+#[derive(proc_macro_derive::DeriveSomething)]
+pub struct S;
+
+proc_macro_derive::foo_bar!();
+
+#[rustfmt::skip]
+macro_rules! test {
+ () => {
+ vec![0, 0, 0]
+ };
+}
+
+#[rustfmt::skip]
+macro_rules! test2 {
+ ($($arg:tt)*) => {
+ format_args!($($arg)*)
+ };
+}
+
+macro_rules! type_pos {
+ ($what:ty) => {
+ Vec<$what>
+ };
+}
+
+macro_rules! printlnfoo {
+ ($thing:expr) => {
+ println!("{}", $thing)
+ };
+}
+
+#[rustfmt::skip]
+fn main() {
+ let _ = vec![1, 2, 3];
+ let _ = format!("ugh {} stop being such a good compiler", "hello");
+ let _ = matches!({}, ());
+ let _ = quote!{let x = 1;};
+ let _ = quote::quote!{match match match};
+ let _ = test!(); // trigger when macro def is inside our own crate
+ let _ = vec![1,2,3];
+
+ let _ = quote::quote! {true || false};
+ let _ = vec! [0 ,0 ,0];
+ let _ = format!("fds{}fds", 10);
+ let _ = test2!["{}{}{}", 1, 2, 3];
+
+ let _: type_pos![usize] = vec![];
+
+ eprint!["test if user config overrides defaults"];
+
+ printlnfoo!["test if printlnfoo is triggered by println"];
+}
diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs
index 5b4adc868..72883e827 100644
--- a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs
+++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.rs
@@ -1,4 +1,5 @@
// aux-build:proc_macro_derive.rs
+// run-rustfix
#![warn(clippy::nonstandard_macro_braces)]
@@ -42,6 +43,7 @@ macro_rules! printlnfoo {
fn main() {
let _ = vec! {1, 2, 3};
let _ = format!["ugh {} stop being such a good compiler", "hello"];
+ let _ = matches!{{}, ()};
let _ = quote!(let x = 1;);
let _ = quote::quote!(match match match);
let _ = test!(); // trigger when macro def is inside our own crate
diff --git a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr
index 039b23b1b..7ae381597 100644
--- a/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr
+++ b/src/tools/clippy/tests/ui-toml/nonstandard_macro_braces/conf_nonstandard_macro_braces.stderr
@@ -1,94 +1,57 @@
error: use of irregular braces for `vec!` macro
- --> $DIR/conf_nonstandard_macro_braces.rs:43:13
+ --> $DIR/conf_nonstandard_macro_braces.rs:44:13
|
LL | let _ = vec! {1, 2, 3};
- | ^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^ help: consider writing: `vec![1, 2, 3]`
|
= note: `-D clippy::nonstandard-macro-braces` implied by `-D warnings`
-help: consider writing `vec![1, 2, 3]`
- --> $DIR/conf_nonstandard_macro_braces.rs:43:13
- |
-LL | let _ = vec! {1, 2, 3};
- | ^^^^^^^^^^^^^^
error: use of irregular braces for `format!` macro
- --> $DIR/conf_nonstandard_macro_braces.rs:44:13
+ --> $DIR/conf_nonstandard_macro_braces.rs:45:13
|
LL | let _ = format!["ugh {} stop being such a good compiler", "hello"];
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
-help: consider writing `format!("ugh () stop being such a good compiler", "hello")`
- --> $DIR/conf_nonstandard_macro_braces.rs:44:13
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `format!("ugh {} stop being such a good compiler", "hello")`
+
+error: use of irregular braces for `matches!` macro
+ --> $DIR/conf_nonstandard_macro_braces.rs:46:13
|
-LL | let _ = format!["ugh {} stop being such a good compiler", "hello"];
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _ = matches!{{}, ()};
+ | ^^^^^^^^^^^^^^^^ help: consider writing: `matches!({}, ())`
error: use of irregular braces for `quote!` macro
- --> $DIR/conf_nonstandard_macro_braces.rs:45:13
- |
-LL | let _ = quote!(let x = 1;);
- | ^^^^^^^^^^^^^^^^^^
- |
-help: consider writing `quote! {let x = 1;}`
- --> $DIR/conf_nonstandard_macro_braces.rs:45:13
+ --> $DIR/conf_nonstandard_macro_braces.rs:47:13
|
LL | let _ = quote!(let x = 1;);
- | ^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^ help: consider writing: `quote!{let x = 1;}`
error: use of irregular braces for `quote::quote!` macro
- --> $DIR/conf_nonstandard_macro_braces.rs:46:13
+ --> $DIR/conf_nonstandard_macro_braces.rs:48:13
|
LL | let _ = quote::quote!(match match match);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
-help: consider writing `quote::quote! {match match match}`
- --> $DIR/conf_nonstandard_macro_braces.rs:46:13
- |
-LL | let _ = quote::quote!(match match match);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `quote::quote!{match match match}`
error: use of irregular braces for `vec!` macro
- --> $DIR/conf_nonstandard_macro_braces.rs:18:9
+ --> $DIR/conf_nonstandard_macro_braces.rs:19:9
|
LL | vec!{0, 0, 0}
- | ^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^ help: consider writing: `vec![0, 0, 0]`
...
LL | let _ = test!(); // trigger when macro def is inside our own crate
| ------- in this macro invocation
|
-help: consider writing `vec![0, 0, 0]`
- --> $DIR/conf_nonstandard_macro_braces.rs:18:9
- |
-LL | vec!{0, 0, 0}
- | ^^^^^^^^^^^^^
-...
-LL | let _ = test!(); // trigger when macro def is inside our own crate
- | ------- in this macro invocation
= note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
error: use of irregular braces for `type_pos!` macro
- --> $DIR/conf_nonstandard_macro_braces.rs:55:12
- |
-LL | let _: type_pos!(usize) = vec![];
- | ^^^^^^^^^^^^^^^^
- |
-help: consider writing `type_pos![usize]`
- --> $DIR/conf_nonstandard_macro_braces.rs:55:12
+ --> $DIR/conf_nonstandard_macro_braces.rs:57:12
|
LL | let _: type_pos!(usize) = vec![];
- | ^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^ help: consider writing: `type_pos![usize]`
error: use of irregular braces for `eprint!` macro
- --> $DIR/conf_nonstandard_macro_braces.rs:57:5
- |
-LL | eprint!("test if user config overrides defaults");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
-help: consider writing `eprint!["test if user config overrides defaults"]`
- --> $DIR/conf_nonstandard_macro_braces.rs:57:5
+ --> $DIR/conf_nonstandard_macro_braces.rs:59:5
|
LL | eprint!("test if user config overrides defaults");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider writing: `eprint!["test if user config overrides defaults"]`
-error: aborting due to 7 previous errors
+error: aborting due to 8 previous errors
diff --git a/src/tools/clippy/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr b/src/tools/clippy/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr
index 49eecf18b..c72f8c648 100644
--- a/src/tools/clippy/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr
+++ b/src/tools/clippy/tests/ui-toml/strict_non_send_fields_in_send_ty/test.stderr
@@ -4,13 +4,13 @@ error: some fields in `NoGeneric` are not safe to be sent to another thread
LL | unsafe impl Send for NoGeneric {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings`
note: it is not safe to send field `rc_is_not_send` to another thread
--> $DIR/test.rs:8:5
|
LL | rc_is_not_send: Rc<String>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use a thread-safe type that implements `Send`
+ = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings`
error: some fields in `MultiField<T>` are not safe to be sent to another thread
--> $DIR/test.rs:19:1
diff --git a/src/tools/clippy/tests/ui-toml/struct_excessive_bools/test.stderr b/src/tools/clippy/tests/ui-toml/struct_excessive_bools/test.stderr
index 65861d10d..4e7c70d18 100644
--- a/src/tools/clippy/tests/ui-toml/struct_excessive_bools/test.stderr
+++ b/src/tools/clippy/tests/ui-toml/struct_excessive_bools/test.stderr
@@ -6,8 +6,8 @@ LL | | a: bool,
LL | | }
| |_^
|
- = note: `-D clippy::struct-excessive-bools` implied by `-D warnings`
= help: consider using a state machine or refactoring bools into two-variant enums
+ = note: `-D clippy::struct-excessive-bools` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/clippy.toml b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/clippy.toml
index c902d2112..28774db62 100644
--- a/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/clippy.toml
+++ b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/clippy.toml
@@ -3,6 +3,7 @@ disallowed-methods = [
"std::iter::Iterator::sum",
"f32::clamp",
"slice::sort_unstable",
+ "futures::stream::select_all",
# can give path and reason with an inline table
{ path = "regex::Regex::is_match", reason = "no matching allowed" },
# can use an inline table but omit reason
diff --git a/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs
index 3397fa1ec..b483f1600 100644
--- a/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs
+++ b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs
@@ -1,6 +1,9 @@
#![warn(clippy::disallowed_methods)]
+extern crate futures;
extern crate regex;
+
+use futures::stream::{empty, select_all};
use regex::Regex;
fn main() {
@@ -20,4 +23,7 @@ fn main() {
let in_call = Box::new(f32::clamp);
let in_method_call = ["^", "$"].into_iter().map(Regex::new);
+
+ // resolve ambiguity between `futures::stream::select_all` the module and the function
+ let same_name_as_module = select_all(vec![empty::<()>()]);
}
diff --git a/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr
index 5cbb56754..6d78c32e1 100644
--- a/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr
+++ b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr
@@ -1,5 +1,5 @@
error: use of a disallowed method `regex::Regex::new`
- --> $DIR/conf_disallowed_methods.rs:7:14
+ --> $DIR/conf_disallowed_methods.rs:10:14
|
LL | let re = Regex::new(r"ab.*c").unwrap();
| ^^^^^^^^^^^^^^^^^^^^
@@ -7,7 +7,7 @@ LL | let re = Regex::new(r"ab.*c").unwrap();
= note: `-D clippy::disallowed-methods` implied by `-D warnings`
error: use of a disallowed method `regex::Regex::is_match`
- --> $DIR/conf_disallowed_methods.rs:8:5
+ --> $DIR/conf_disallowed_methods.rs:11:5
|
LL | re.is_match("abc");
| ^^^^^^^^^^^^^^^^^^
@@ -15,40 +15,46 @@ LL | re.is_match("abc");
= note: no matching allowed (from clippy.toml)
error: use of a disallowed method `std::iter::Iterator::sum`
- --> $DIR/conf_disallowed_methods.rs:11:5
+ --> $DIR/conf_disallowed_methods.rs:14:5
|
LL | a.iter().sum::<i32>();
| ^^^^^^^^^^^^^^^^^^^^^
error: use of a disallowed method `slice::sort_unstable`
- --> $DIR/conf_disallowed_methods.rs:13:5
+ --> $DIR/conf_disallowed_methods.rs:16:5
|
LL | a.sort_unstable();
| ^^^^^^^^^^^^^^^^^
error: use of a disallowed method `f32::clamp`
- --> $DIR/conf_disallowed_methods.rs:15:13
+ --> $DIR/conf_disallowed_methods.rs:18:13
|
LL | let _ = 2.0f32.clamp(3.0f32, 4.0f32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: use of a disallowed method `regex::Regex::new`
- --> $DIR/conf_disallowed_methods.rs:18:61
+ --> $DIR/conf_disallowed_methods.rs:21:61
|
LL | let indirect: fn(&str) -> Result<Regex, regex::Error> = Regex::new;
| ^^^^^^^^^^
error: use of a disallowed method `f32::clamp`
- --> $DIR/conf_disallowed_methods.rs:21:28
+ --> $DIR/conf_disallowed_methods.rs:24:28
|
LL | let in_call = Box::new(f32::clamp);
| ^^^^^^^^^^
error: use of a disallowed method `regex::Regex::new`
- --> $DIR/conf_disallowed_methods.rs:22:53
+ --> $DIR/conf_disallowed_methods.rs:25:53
|
LL | let in_method_call = ["^", "$"].into_iter().map(Regex::new);
| ^^^^^^^^^^
-error: aborting due to 8 previous errors
+error: use of a disallowed method `futures::stream::select_all`
+ --> $DIR/conf_disallowed_methods.rs:28:31
+ |
+LL | let same_name_as_module = select_all(vec![empty::<()>()]);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
index f27f78d15..82ee80541 100644
--- a/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
+++ b/src/tools/clippy/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
@@ -11,6 +11,7 @@ error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown fie
cargo-ignore-publish
cognitive-complexity-threshold
cyclomatic-complexity-threshold
+ disallowed-macros
disallowed-methods
disallowed-names
disallowed-types
diff --git a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr
index 6bcfa0a8b..681b5eaf5 100644
--- a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr
+++ b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr
@@ -16,8 +16,8 @@ error: used `unwrap()` on `an Option` value
LL | let _ = boxed_slice.get(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::unwrap-used` implied by `-D warnings`
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
+ = note: `-D clippy::unwrap-used` implied by `-D warnings`
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
--> $DIR/unwrap_used.rs:36:17
diff --git a/src/tools/clippy/tests/ui/absurd-extreme-comparisons.stderr b/src/tools/clippy/tests/ui/absurd-extreme-comparisons.stderr
index 6de554378..21cb11fa1 100644
--- a/src/tools/clippy/tests/ui/absurd-extreme-comparisons.stderr
+++ b/src/tools/clippy/tests/ui/absurd-extreme-comparisons.stderr
@@ -4,8 +4,8 @@ error: this comparison involving the minimum or maximum element for this type co
LL | u <= 0;
| ^^^^^^
|
- = note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings`
= help: because `0` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == 0` instead
+ = note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings`
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
--> $DIR/absurd-extreme-comparisons.rs:15:5
diff --git a/src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr b/src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr
index cd040a144..23f17e9a7 100644
--- a/src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr
+++ b/src/tools/clippy/tests/ui/allow_attributes_without_reason.stderr
@@ -4,12 +4,12 @@ error: `allow` attribute without specifying a reason
LL | #[allow(dead_code)]
| ^^^^^^^^^^^^^^^^^^^
|
+ = help: try adding a reason at the end with `, reason = ".."`
note: the lint level is defined here
--> $DIR/allow_attributes_without_reason.rs:2:9
|
LL | #![deny(clippy::allow_attributes_without_reason)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: try adding a reason at the end with `, reason = ".."`
error: `allow` attribute without specifying a reason
--> $DIR/allow_attributes_without_reason.rs:6:1
diff --git a/src/tools/clippy/tests/ui/almost_complete_letter_range.fixed b/src/tools/clippy/tests/ui/almost_complete_letter_range.fixed
index e69b40f35..079b7c000 100644
--- a/src/tools/clippy/tests/ui/almost_complete_letter_range.fixed
+++ b/src/tools/clippy/tests/ui/almost_complete_letter_range.fixed
@@ -1,5 +1,6 @@
// run-rustfix
// edition:2018
+// aux-build:macro_rules.rs
#![feature(custom_inner_attributes)]
#![feature(exclusive_range_pattern)]
@@ -8,12 +9,21 @@
#![allow(ellipsis_inclusive_range_patterns)]
#![allow(clippy::needless_parens_on_range_literals)]
+#[macro_use]
+extern crate macro_rules;
+
macro_rules! a {
() => {
'a'
};
}
+macro_rules! b {
+ () => {
+ let _ = 'a'..='z';
+ };
+}
+
fn main() {
#[rustfmt::skip]
{
@@ -47,6 +57,9 @@ fn main() {
'B'..'Z' => 4,
_ => 5,
};
+
+ almost_complete_letter_range!();
+ b!();
}
fn _under_msrv() {
diff --git a/src/tools/clippy/tests/ui/almost_complete_letter_range.rs b/src/tools/clippy/tests/ui/almost_complete_letter_range.rs
index f2240981d..a66900a97 100644
--- a/src/tools/clippy/tests/ui/almost_complete_letter_range.rs
+++ b/src/tools/clippy/tests/ui/almost_complete_letter_range.rs
@@ -1,5 +1,6 @@
// run-rustfix
// edition:2018
+// aux-build:macro_rules.rs
#![feature(custom_inner_attributes)]
#![feature(exclusive_range_pattern)]
@@ -8,12 +9,21 @@
#![allow(ellipsis_inclusive_range_patterns)]
#![allow(clippy::needless_parens_on_range_literals)]
+#[macro_use]
+extern crate macro_rules;
+
macro_rules! a {
() => {
'a'
};
}
+macro_rules! b {
+ () => {
+ let _ = 'a'..'z';
+ };
+}
+
fn main() {
#[rustfmt::skip]
{
@@ -47,6 +57,9 @@ fn main() {
'B'..'Z' => 4,
_ => 5,
};
+
+ almost_complete_letter_range!();
+ b!();
}
fn _under_msrv() {
diff --git a/src/tools/clippy/tests/ui/almost_complete_letter_range.stderr b/src/tools/clippy/tests/ui/almost_complete_letter_range.stderr
index 5b5dc40ee..3de44c72c 100644
--- a/src/tools/clippy/tests/ui/almost_complete_letter_range.stderr
+++ b/src/tools/clippy/tests/ui/almost_complete_letter_range.stderr
@@ -1,5 +1,5 @@
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:20:17
+ --> $DIR/almost_complete_letter_range.rs:30:17
|
LL | let _ = ('a') ..'z';
| ^^^^^^--^^^
@@ -9,7 +9,7 @@ LL | let _ = ('a') ..'z';
= note: `-D clippy::almost-complete-letter-range` implied by `-D warnings`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:21:17
+ --> $DIR/almost_complete_letter_range.rs:31:17
|
LL | let _ = 'A' .. ('Z');
| ^^^^--^^^^^^
@@ -17,7 +17,7 @@ LL | let _ = 'A' .. ('Z');
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:27:13
+ --> $DIR/almost_complete_letter_range.rs:37:13
|
LL | let _ = (b'a')..(b'z');
| ^^^^^^--^^^^^^
@@ -25,7 +25,7 @@ LL | let _ = (b'a')..(b'z');
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:28:13
+ --> $DIR/almost_complete_letter_range.rs:38:13
|
LL | let _ = b'A'..b'Z';
| ^^^^--^^^^
@@ -33,7 +33,7 @@ LL | let _ = b'A'..b'Z';
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:33:13
+ --> $DIR/almost_complete_letter_range.rs:43:13
|
LL | let _ = a!()..'z';
| ^^^^--^^^
@@ -41,7 +41,7 @@ LL | let _ = a!()..'z';
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:36:9
+ --> $DIR/almost_complete_letter_range.rs:46:9
|
LL | b'a'..b'z' if true => 1,
| ^^^^--^^^^
@@ -49,7 +49,7 @@ LL | b'a'..b'z' if true => 1,
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:37:9
+ --> $DIR/almost_complete_letter_range.rs:47:9
|
LL | b'A'..b'Z' if true => 2,
| ^^^^--^^^^
@@ -57,7 +57,7 @@ LL | b'A'..b'Z' if true => 2,
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:44:9
+ --> $DIR/almost_complete_letter_range.rs:54:9
|
LL | 'a'..'z' if true => 1,
| ^^^--^^^
@@ -65,7 +65,7 @@ LL | 'a'..'z' if true => 1,
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:45:9
+ --> $DIR/almost_complete_letter_range.rs:55:9
|
LL | 'A'..'Z' if true => 2,
| ^^^--^^^
@@ -73,7 +73,20 @@ LL | 'A'..'Z' if true => 2,
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:55:9
+ --> $DIR/almost_complete_letter_range.rs:23:17
+ |
+LL | let _ = 'a'..'z';
+ | ^^^--^^^
+ | |
+ | help: use an inclusive range: `..=`
+...
+LL | b!();
+ | ---- in this macro invocation
+ |
+ = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: almost complete ascii letter range
+ --> $DIR/almost_complete_letter_range.rs:68:9
|
LL | 'a'..'z' => 1,
| ^^^--^^^
@@ -81,7 +94,7 @@ LL | 'a'..'z' => 1,
| help: use an inclusive range: `...`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:62:13
+ --> $DIR/almost_complete_letter_range.rs:75:13
|
LL | let _ = 'a'..'z';
| ^^^--^^^
@@ -89,12 +102,12 @@ LL | let _ = 'a'..'z';
| help: use an inclusive range: `..=`
error: almost complete ascii letter range
- --> $DIR/almost_complete_letter_range.rs:64:9
+ --> $DIR/almost_complete_letter_range.rs:77:9
|
LL | 'a'..'z' => 1,
| ^^^--^^^
| |
| help: use an inclusive range: `..=`
-error: aborting due to 12 previous errors
+error: aborting due to 13 previous errors
diff --git a/src/tools/clippy/tests/ui/approx_const.stderr b/src/tools/clippy/tests/ui/approx_const.stderr
index 4da1b8215..0932a2eec 100644
--- a/src/tools/clippy/tests/ui/approx_const.stderr
+++ b/src/tools/clippy/tests/ui/approx_const.stderr
@@ -4,8 +4,8 @@ error: approximate value of `f{32, 64}::consts::E` found
LL | let my_e = 2.7182;
| ^^^^^^
|
- = note: `-D clippy::approx-constant` implied by `-D warnings`
= help: consider using the constant directly
+ = note: `-D clippy::approx-constant` implied by `-D warnings`
error: approximate value of `f{32, 64}::consts::E` found
--> $DIR/approx_const.rs:5:20
diff --git a/src/tools/clippy/tests/ui/arithmetic_side_effects.rs b/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
index f5390c746..b25e68f13 100644
--- a/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
+++ b/src/tools/clippy/tests/ui/arithmetic_side_effects.rs
@@ -1,9 +1,75 @@
-#![allow(clippy::assign_op_pattern, clippy::unnecessary_owned_empty_strings)]
-#![feature(inline_const, saturating_int_impl)]
+#![allow(
+ clippy::assign_op_pattern,
+ clippy::erasing_op,
+ clippy::identity_op,
+ clippy::op_ref,
+ clippy::unnecessary_owned_empty_strings,
+ arithmetic_overflow,
+ unconditional_panic
+)]
+#![feature(const_mut_refs, inline_const, saturating_int_impl)]
#![warn(clippy::arithmetic_side_effects)]
use core::num::{Saturating, Wrapping};
+pub struct Custom;
+
+macro_rules! impl_arith {
+ ( $( $_trait:ident, $ty:ty, $method:ident; )* ) => {
+ $(
+ impl core::ops::$_trait<$ty> for Custom {
+ type Output = Self;
+ fn $method(self, _: $ty) -> Self::Output { Self }
+ }
+ )*
+ }
+}
+
+impl_arith!(
+ Add, i32, add;
+ Div, i32, div;
+ Mul, i32, mul;
+ Sub, i32, sub;
+
+ Add, f64, add;
+ Div, f64, div;
+ Mul, f64, mul;
+ Sub, f64, sub;
+);
+
+pub fn association_with_structures_should_not_trigger_the_lint() {
+ enum Foo {
+ Bar = -2,
+ }
+
+ impl Trait for Foo {
+ const ASSOC: i32 = {
+ let _: [i32; 1 + 1];
+ fn foo() {}
+ 1 + 1
+ };
+ }
+
+ struct Baz([i32; 1 + 1]);
+
+ trait Trait {
+ const ASSOC: i32 = 1 + 1;
+ }
+
+ type Alias = [i32; 1 + 1];
+
+ union Qux {
+ field: [i32; 1 + 1],
+ }
+
+ let _: [i32; 1 + 1] = [0, 0];
+
+ let _: [i32; 1 + 1] = {
+ let a: [i32; 1 + 1] = [0, 0];
+ a
+ };
+}
+
pub fn hard_coded_allowed() {
let _ = 1f32 + 1f32;
let _ = 1f64 + 1f64;
@@ -26,7 +92,7 @@ pub fn hard_coded_allowed() {
}
#[rustfmt::skip]
-pub fn non_overflowing_ops() {
+pub fn const_ops_should_not_trigger_the_lint() {
const _: i32 = { let mut n = 1; n += 1; n };
let _ = const { let mut n = 1; n += 1; n };
@@ -37,21 +103,122 @@ pub fn non_overflowing_ops() {
let _ = const { let mut n = 1; n = 1 + n; n };
const _: i32 = 1 + 1;
- let _ = 1 + 1;
let _ = const { 1 + 1 };
- let mut _a = 1;
- _a *= 1;
- _a /= 1;
+ const _: i32 = { let mut n = 1; n = -1; n = -(-1); n = -n; n };
+ let _ = const { let mut n = 1; n = -1; n = -(-1); n = -n; n };
}
-#[rustfmt::skip]
-pub fn overflowing_ops() {
- let mut _a = 1; _a += 1;
+pub fn non_overflowing_ops_or_ops_already_handled_by_the_compiler_should_not_trigger_the_lint() {
+ let mut _n = i32::MAX;
+
+ // Assign
+ _n += 0;
+ _n += &0;
+ _n -= 0;
+ _n -= &0;
+ _n /= 99;
+ _n /= &99;
+ _n %= 99;
+ _n %= &99;
+ _n *= 0;
+ _n *= &0;
+ _n *= 1;
+ _n *= &1;
+
+ // Binary
+ _n = _n + 0;
+ _n = _n + &0;
+ _n = 0 + _n;
+ _n = &0 + _n;
+ _n = _n - 0;
+ _n = _n - &0;
+ _n = 0 - _n;
+ _n = &0 - _n;
+ _n = _n / 99;
+ _n = _n / &99;
+ _n = _n % 99;
+ _n = _n % &99;
+ _n = _n * 0;
+ _n = _n * &0;
+ _n = 0 * _n;
+ _n = &0 * _n;
+ _n = _n * 1;
+ _n = _n * &1;
+ _n = 1 * _n;
+ _n = &1 * _n;
+ _n = 23 + 85;
+
+ // Unary
+ _n = -1;
+ _n = -(-1);
+}
+
+pub fn runtime_ops() {
+ let mut _n = i32::MAX;
+
+ // Assign
+ _n += 1;
+ _n += &1;
+ _n -= 1;
+ _n -= &1;
+ _n /= 0;
+ _n /= &0;
+ _n %= 0;
+ _n %= &0;
+ _n *= 2;
+ _n *= &2;
+
+ // Binary
+ _n = _n + 1;
+ _n = _n + &1;
+ _n = 1 + _n;
+ _n = &1 + _n;
+ _n = _n - 1;
+ _n = _n - &1;
+ _n = 1 - _n;
+ _n = &1 - _n;
+ _n = _n / 0;
+ _n = _n / &0;
+ _n = _n % 0;
+ _n = _n % &0;
+ _n = _n * 2;
+ _n = _n * &2;
+ _n = 2 * _n;
+ _n = &2 * _n;
+ _n = 23 + &85;
+ _n = &23 + 85;
+ _n = &23 + &85;
- let mut _b = 1; _b = _b + 1;
+ // Custom
+ let _ = Custom + 0;
+ let _ = Custom + 1;
+ let _ = Custom + 2;
+ let _ = Custom + 0.0;
+ let _ = Custom + 1.0;
+ let _ = Custom + 2.0;
+ let _ = Custom - 0;
+ let _ = Custom - 1;
+ let _ = Custom - 2;
+ let _ = Custom - 0.0;
+ let _ = Custom - 1.0;
+ let _ = Custom - 2.0;
+ let _ = Custom / 0;
+ let _ = Custom / 1;
+ let _ = Custom / 2;
+ let _ = Custom / 0.0;
+ let _ = Custom / 1.0;
+ let _ = Custom / 2.0;
+ let _ = Custom * 0;
+ let _ = Custom * 1;
+ let _ = Custom * 2;
+ let _ = Custom * 0.0;
+ let _ = Custom * 1.0;
+ let _ = Custom * 2.0;
- let mut _c = 1; _c = 1 + _c;
+ // Unary
+ _n = -_n;
+ _n = -&_n;
}
fn main() {}
diff --git a/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr b/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr
index 6c4c8bdec..0f06e22ba 100644
--- a/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr
+++ b/src/tools/clippy/tests/ui/arithmetic_side_effects.stderr
@@ -1,22 +1,352 @@
-error: arithmetic detected
- --> $DIR/arithmetic_side_effects.rs:50:21
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:78:13
|
-LL | let mut _a = 1; _a += 1;
- | ^^^^^^^
+LL | let _ = String::new() + "";
+ | ^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
-error: arithmetic detected
- --> $DIR/arithmetic_side_effects.rs:52:26
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:86:27
|
-LL | let mut _b = 1; _b = _b + 1;
- | ^^^^^^
+LL | let inferred_string = string + "";
+ | ^^^^^^^^^^^
-error: arithmetic detected
- --> $DIR/arithmetic_side_effects.rs:54:26
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:90:13
|
-LL | let mut _c = 1; _c = 1 + _c;
- | ^^^^^^
+LL | let _ = inferred_string + "";
+ | ^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 3 previous errors
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:161:5
+ |
+LL | _n += 1;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:162:5
+ |
+LL | _n += &1;
+ | ^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:163:5
+ |
+LL | _n -= 1;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:164:5
+ |
+LL | _n -= &1;
+ | ^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:165:5
+ |
+LL | _n /= 0;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:166:5
+ |
+LL | _n /= &0;
+ | ^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:167:5
+ |
+LL | _n %= 0;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:168:5
+ |
+LL | _n %= &0;
+ | ^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:169:5
+ |
+LL | _n *= 2;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:170:5
+ |
+LL | _n *= &2;
+ | ^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:173:10
+ |
+LL | _n = _n + 1;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:174:10
+ |
+LL | _n = _n + &1;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:175:10
+ |
+LL | _n = 1 + _n;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:176:10
+ |
+LL | _n = &1 + _n;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:177:10
+ |
+LL | _n = _n - 1;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:178:10
+ |
+LL | _n = _n - &1;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:179:10
+ |
+LL | _n = 1 - _n;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:180:10
+ |
+LL | _n = &1 - _n;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:181:10
+ |
+LL | _n = _n / 0;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:182:10
+ |
+LL | _n = _n / &0;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:183:10
+ |
+LL | _n = _n % 0;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:184:10
+ |
+LL | _n = _n % &0;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:185:10
+ |
+LL | _n = _n * 2;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:186:10
+ |
+LL | _n = _n * &2;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:187:10
+ |
+LL | _n = 2 * _n;
+ | ^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:188:10
+ |
+LL | _n = &2 * _n;
+ | ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:189:10
+ |
+LL | _n = 23 + &85;
+ | ^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:190:10
+ |
+LL | _n = &23 + 85;
+ | ^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:191:10
+ |
+LL | _n = &23 + &85;
+ | ^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:194:13
+ |
+LL | let _ = Custom + 0;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:195:13
+ |
+LL | let _ = Custom + 1;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:196:13
+ |
+LL | let _ = Custom + 2;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:197:13
+ |
+LL | let _ = Custom + 0.0;
+ | ^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:198:13
+ |
+LL | let _ = Custom + 1.0;
+ | ^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:199:13
+ |
+LL | let _ = Custom + 2.0;
+ | ^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:200:13
+ |
+LL | let _ = Custom - 0;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:201:13
+ |
+LL | let _ = Custom - 1;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:202:13
+ |
+LL | let _ = Custom - 2;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:203:13
+ |
+LL | let _ = Custom - 0.0;
+ | ^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:204:13
+ |
+LL | let _ = Custom - 1.0;
+ | ^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:205:13
+ |
+LL | let _ = Custom - 2.0;
+ | ^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:206:13
+ |
+LL | let _ = Custom / 0;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:207:13
+ |
+LL | let _ = Custom / 1;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:208:13
+ |
+LL | let _ = Custom / 2;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:209:13
+ |
+LL | let _ = Custom / 0.0;
+ | ^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:210:13
+ |
+LL | let _ = Custom / 1.0;
+ | ^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:211:13
+ |
+LL | let _ = Custom / 2.0;
+ | ^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:212:13
+ |
+LL | let _ = Custom * 0;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:213:13
+ |
+LL | let _ = Custom * 1;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:214:13
+ |
+LL | let _ = Custom * 2;
+ | ^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:215:13
+ |
+LL | let _ = Custom * 0.0;
+ | ^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:216:13
+ |
+LL | let _ = Custom * 1.0;
+ | ^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:217:13
+ |
+LL | let _ = Custom * 2.0;
+ | ^^^^^^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:220:10
+ |
+LL | _n = -_n;
+ | ^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+ --> $DIR/arithmetic_side_effects.rs:221:10
+ |
+LL | _n = -&_n;
+ | ^^^^
+
+error: aborting due to 58 previous errors
diff --git a/src/tools/clippy/tests/ui/as_conversions.stderr b/src/tools/clippy/tests/ui/as_conversions.stderr
index d11b56171..f5d59e1e5 100644
--- a/src/tools/clippy/tests/ui/as_conversions.stderr
+++ b/src/tools/clippy/tests/ui/as_conversions.stderr
@@ -4,8 +4,8 @@ error: using a potentially dangerous silent `as` conversion
LL | let i = 0u32 as u64;
| ^^^^^^^^^^^
|
- = note: `-D clippy::as-conversions` implied by `-D warnings`
= help: consider using a safe wrapper for this conversion
+ = note: `-D clippy::as-conversions` implied by `-D warnings`
error: using a potentially dangerous silent `as` conversion
--> $DIR/as_conversions.rs:17:13
diff --git a/src/tools/clippy/tests/ui/as_ptr_cast_mut.rs b/src/tools/clippy/tests/ui/as_ptr_cast_mut.rs
new file mode 100644
index 000000000..0d1d92584
--- /dev/null
+++ b/src/tools/clippy/tests/ui/as_ptr_cast_mut.rs
@@ -0,0 +1,37 @@
+#![allow(unused)]
+#![warn(clippy::as_ptr_cast_mut)]
+#![allow(clippy::wrong_self_convention)]
+
+struct MutPtrWrapper(Vec<u8>);
+impl MutPtrWrapper {
+ fn as_ptr(&mut self) -> *const u8 {
+ self.0.as_mut_ptr() as *const u8
+ }
+}
+
+struct Covariant<T>(*const T);
+impl<T> Covariant<T> {
+ fn as_ptr(self) -> *const T {
+ self.0
+ }
+}
+
+fn main() {
+ let mut string = String::new();
+ let _ = string.as_ptr() as *mut u8;
+ let _: *mut i8 = string.as_ptr() as *mut _;
+ let _ = string.as_ptr() as *const i8;
+ let _ = string.as_mut_ptr();
+ let _ = string.as_mut_ptr() as *mut u8;
+ let _ = string.as_mut_ptr() as *const u8;
+
+ let nn = std::ptr::NonNull::new(4 as *mut u8).unwrap();
+ let _ = nn.as_ptr() as *mut u8;
+
+ let mut wrap = MutPtrWrapper(Vec::new());
+ let _ = wrap.as_ptr() as *mut u8;
+
+ let mut local = 4;
+ let ref_with_write_perm = Covariant(std::ptr::addr_of_mut!(local) as *const _);
+ let _ = ref_with_write_perm.as_ptr() as *mut u8;
+}
diff --git a/src/tools/clippy/tests/ui/as_ptr_cast_mut.stderr b/src/tools/clippy/tests/ui/as_ptr_cast_mut.stderr
new file mode 100644
index 000000000..2189c3d2f
--- /dev/null
+++ b/src/tools/clippy/tests/ui/as_ptr_cast_mut.stderr
@@ -0,0 +1,16 @@
+error: casting the result of `as_ptr` to *mut u8
+ --> $DIR/as_ptr_cast_mut.rs:21:13
+ |
+LL | let _ = string.as_ptr() as *mut u8;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `string.as_mut_ptr()`
+ |
+ = note: `-D clippy::as-ptr-cast-mut` implied by `-D warnings`
+
+error: casting the result of `as_ptr` to *mut i8
+ --> $DIR/as_ptr_cast_mut.rs:22:22
+ |
+LL | let _: *mut i8 = string.as_ptr() as *mut _;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `string.as_mut_ptr()`
+
+error: aborting due to 2 previous errors
+
diff --git a/src/tools/clippy/tests/ui/asm_syntax.stderr b/src/tools/clippy/tests/ui/asm_syntax.stderr
index e9b150121..9c7c3ba7d 100644
--- a/src/tools/clippy/tests/ui/asm_syntax.stderr
+++ b/src/tools/clippy/tests/ui/asm_syntax.stderr
@@ -4,8 +4,8 @@ error: Intel x86 assembly syntax used
LL | asm!("");
| ^^^^^^^^
|
- = note: `-D clippy::inline-asm-x86-intel-syntax` implied by `-D warnings`
= help: use AT&T x86 assembly syntax
+ = note: `-D clippy::inline-asm-x86-intel-syntax` implied by `-D warnings`
error: Intel x86 assembly syntax used
--> $DIR/asm_syntax.rs:9:9
@@ -29,8 +29,8 @@ error: AT&T x86 assembly syntax used
LL | asm!("", options(att_syntax));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::inline-asm-x86-att-syntax` implied by `-D warnings`
= help: use Intel x86 assembly syntax
+ = note: `-D clippy::inline-asm-x86-att-syntax` implied by `-D warnings`
error: AT&T x86 assembly syntax used
--> $DIR/asm_syntax.rs:24:9
diff --git a/src/tools/clippy/tests/ui/assertions_on_constants.stderr b/src/tools/clippy/tests/ui/assertions_on_constants.stderr
index e1f818814..29fe00903 100644
--- a/src/tools/clippy/tests/ui/assertions_on_constants.stderr
+++ b/src/tools/clippy/tests/ui/assertions_on_constants.stderr
@@ -4,8 +4,8 @@ error: `assert!(true)` will be optimized out by the compiler
LL | assert!(true);
| ^^^^^^^^^^^^^
|
- = note: `-D clippy::assertions-on-constants` implied by `-D warnings`
= help: remove it
+ = note: `-D clippy::assertions-on-constants` implied by `-D warnings`
error: `assert!(false)` should probably be replaced
--> $DIR/assertions_on_constants.rs:11:5
diff --git a/src/tools/clippy/tests/ui/assertions_on_result_states.fixed b/src/tools/clippy/tests/ui/assertions_on_result_states.fixed
index 795f435f2..2bb755290 100644
--- a/src/tools/clippy/tests/ui/assertions_on_result_states.fixed
+++ b/src/tools/clippy/tests/ui/assertions_on_result_states.fixed
@@ -75,3 +75,9 @@ fn main() {
let r: Result<Foo, Foo> = Err(Foo);
assert!(r.is_err());
}
+
+#[allow(dead_code)]
+fn issue9450() {
+ let res: Result<i32, i32> = Ok(1);
+ res.unwrap_err();
+}
diff --git a/src/tools/clippy/tests/ui/assertions_on_result_states.rs b/src/tools/clippy/tests/ui/assertions_on_result_states.rs
index 1101aec1e..d8a9bd2f1 100644
--- a/src/tools/clippy/tests/ui/assertions_on_result_states.rs
+++ b/src/tools/clippy/tests/ui/assertions_on_result_states.rs
@@ -75,3 +75,9 @@ fn main() {
let r: Result<Foo, Foo> = Err(Foo);
assert!(r.is_err());
}
+
+#[allow(dead_code)]
+fn issue9450() {
+ let res: Result<i32, i32> = Ok(1);
+ assert!(res.is_err())
+}
diff --git a/src/tools/clippy/tests/ui/assertions_on_result_states.stderr b/src/tools/clippy/tests/ui/assertions_on_result_states.stderr
index 97a5f3dfc..298d63c9c 100644
--- a/src/tools/clippy/tests/ui/assertions_on_result_states.stderr
+++ b/src/tools/clippy/tests/ui/assertions_on_result_states.stderr
@@ -36,5 +36,11 @@ error: called `assert!` with `Result::is_err`
LL | assert!(r.is_err());
| ^^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap_err()`
-error: aborting due to 6 previous errors
+error: called `assert!` with `Result::is_err`
+ --> $DIR/assertions_on_result_states.rs:82:5
+ |
+LL | assert!(res.is_err())
+ | ^^^^^^^^^^^^^^^^^^^^^ help: replace with: `res.unwrap_err();`
+
+error: aborting due to 7 previous errors
diff --git a/src/tools/clippy/tests/ui/assign_ops2.rs b/src/tools/clippy/tests/ui/assign_ops2.rs
index f6d3a8fa3..2c876a96c 100644
--- a/src/tools/clippy/tests/ui/assign_ops2.rs
+++ b/src/tools/clippy/tests/ui/assign_ops2.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::uninlined_format_args)]
+
#[allow(unused_assignments)]
#[warn(clippy::misrefactored_assign_op, clippy::assign_op_pattern)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/assign_ops2.stderr b/src/tools/clippy/tests/ui/assign_ops2.stderr
index 04b1dc93d..25e746022 100644
--- a/src/tools/clippy/tests/ui/assign_ops2.stderr
+++ b/src/tools/clippy/tests/ui/assign_ops2.stderr
@@ -1,5 +1,5 @@
error: variable appears on both sides of an assignment operation
- --> $DIR/assign_ops2.rs:5:5
+ --> $DIR/assign_ops2.rs:7:5
|
LL | a += a + 1;
| ^^^^^^^^^^
@@ -15,7 +15,7 @@ LL | a = a + a + 1;
| ~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
- --> $DIR/assign_ops2.rs:6:5
+ --> $DIR/assign_ops2.rs:8:5
|
LL | a += 1 + a;
| ^^^^^^^^^^
@@ -30,7 +30,7 @@ LL | a = a + 1 + a;
| ~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
- --> $DIR/assign_ops2.rs:7:5
+ --> $DIR/assign_ops2.rs:9:5
|
LL | a -= a - 1;
| ^^^^^^^^^^
@@ -45,7 +45,7 @@ LL | a = a - (a - 1);
| ~~~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
- --> $DIR/assign_ops2.rs:8:5
+ --> $DIR/assign_ops2.rs:10:5
|
LL | a *= a * 99;
| ^^^^^^^^^^^
@@ -60,7 +60,7 @@ LL | a = a * a * 99;
| ~~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
- --> $DIR/assign_ops2.rs:9:5
+ --> $DIR/assign_ops2.rs:11:5
|
LL | a *= 42 * a;
| ^^^^^^^^^^^
@@ -75,7 +75,7 @@ LL | a = a * 42 * a;
| ~~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
- --> $DIR/assign_ops2.rs:10:5
+ --> $DIR/assign_ops2.rs:12:5
|
LL | a /= a / 2;
| ^^^^^^^^^^
@@ -90,7 +90,7 @@ LL | a = a / (a / 2);
| ~~~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
- --> $DIR/assign_ops2.rs:11:5
+ --> $DIR/assign_ops2.rs:13:5
|
LL | a %= a % 5;
| ^^^^^^^^^^
@@ -105,7 +105,7 @@ LL | a = a % (a % 5);
| ~~~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
- --> $DIR/assign_ops2.rs:12:5
+ --> $DIR/assign_ops2.rs:14:5
|
LL | a &= a & 1;
| ^^^^^^^^^^
@@ -120,7 +120,7 @@ LL | a = a & a & 1;
| ~~~~~~~~~~~~~
error: variable appears on both sides of an assignment operation
- --> $DIR/assign_ops2.rs:13:5
+ --> $DIR/assign_ops2.rs:15:5
|
LL | a *= a * a;
| ^^^^^^^^^^
@@ -135,7 +135,7 @@ LL | a = a * a * a;
| ~~~~~~~~~~~~~
error: manual implementation of an assign operation
- --> $DIR/assign_ops2.rs:50:5
+ --> $DIR/assign_ops2.rs:52:5
|
LL | buf = buf + cows.clone();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()`
diff --git a/src/tools/clippy/tests/ui/author.stdout b/src/tools/clippy/tests/ui/author.stdout
index 597318a55..27ad538f2 100644
--- a/src/tools/clippy/tests/ui/author.stdout
+++ b/src/tools/clippy/tests/ui/author.stdout
@@ -1,14 +1,12 @@
-if_chain! {
- if let StmtKind::Local(local) = stmt.kind;
- if let Some(init) = local.init;
- if let ExprKind::Cast(expr, cast_ty) = init.kind;
- if let TyKind::Path(ref qpath) = cast_ty.kind;
- if match_qpath(qpath, &["char"]);
- if let ExprKind::Lit(ref lit) = expr.kind;
- if let LitKind::Int(69, LitIntType::Unsuffixed) = lit.node;
- if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind;
- if name.as_str() == "x";
- then {
- // report your lint here
- }
+if let StmtKind::Local(local) = stmt.kind
+ && let Some(init) = local.init
+ && let ExprKind::Cast(expr, cast_ty) = init.kind
+ && let TyKind::Path(ref qpath) = cast_ty.kind
+ && match_qpath(qpath, &["char"])
+ && let ExprKind::Lit(ref lit) = expr.kind
+ && let LitKind::Int(69, LitIntType::Unsuffixed) = lit.node
+ && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind
+ && name.as_str() == "x"
+{
+ // report your lint here
}
diff --git a/src/tools/clippy/tests/ui/author/blocks.stdout b/src/tools/clippy/tests/ui/author/blocks.stdout
index a529981e2..9de0550d8 100644
--- a/src/tools/clippy/tests/ui/author/blocks.stdout
+++ b/src/tools/clippy/tests/ui/author/blocks.stdout
@@ -1,64 +1,58 @@
-if_chain! {
- if let ExprKind::Block(block, None) = expr.kind;
- if block.stmts.len() == 3;
- if let StmtKind::Local(local) = block.stmts[0].kind;
- if let Some(init) = local.init;
- if let ExprKind::Lit(ref lit) = init.kind;
- if let LitKind::Int(42, LitIntType::Signed(IntTy::I32)) = lit.node;
- if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind;
- if name.as_str() == "x";
- if let StmtKind::Local(local1) = block.stmts[1].kind;
- if let Some(init1) = local1.init;
- if let ExprKind::Lit(ref lit1) = init1.kind;
- if let LitKind::Float(_, LitFloatType::Suffixed(FloatTy::F32)) = lit1.node;
- if let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local1.pat.kind;
- if name1.as_str() == "_t";
- if let StmtKind::Semi(e) = block.stmts[2].kind;
- if let ExprKind::Unary(UnOp::Neg, inner) = e.kind;
- if let ExprKind::Path(ref qpath) = inner.kind;
- if match_qpath(qpath, &["x"]);
- if block.expr.is_none();
- then {
- // report your lint here
- }
+if let ExprKind::Block(block, None) = expr.kind
+ && block.stmts.len() == 3
+ && let StmtKind::Local(local) = block.stmts[0].kind
+ && let Some(init) = local.init
+ && let ExprKind::Lit(ref lit) = init.kind
+ && let LitKind::Int(42, LitIntType::Signed(IntTy::I32)) = lit.node
+ && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind
+ && name.as_str() == "x"
+ && let StmtKind::Local(local1) = block.stmts[1].kind
+ && let Some(init1) = local1.init
+ && let ExprKind::Lit(ref lit1) = init1.kind
+ && let LitKind::Float(_, LitFloatType::Suffixed(FloatTy::F32)) = lit1.node
+ && let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local1.pat.kind
+ && name1.as_str() == "_t"
+ && let StmtKind::Semi(e) = block.stmts[2].kind
+ && let ExprKind::Unary(UnOp::Neg, inner) = e.kind
+ && let ExprKind::Path(ref qpath) = inner.kind
+ && match_qpath(qpath, &["x"])
+ && block.expr.is_none()
+{
+ // report your lint here
}
-if_chain! {
- if let ExprKind::Block(block, None) = expr.kind;
- if block.stmts.len() == 1;
- if let StmtKind::Local(local) = block.stmts[0].kind;
- if let Some(init) = local.init;
- if let ExprKind::Call(func, args) = init.kind;
- if let ExprKind::Path(ref qpath) = func.kind;
- if match_qpath(qpath, &["String", "new"]);
- if args.is_empty();
- if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind;
- if name.as_str() == "expr";
- if let Some(trailing_expr) = block.expr;
- if let ExprKind::Call(func1, args1) = trailing_expr.kind;
- if let ExprKind::Path(ref qpath1) = func1.kind;
- if match_qpath(qpath1, &["drop"]);
- if args1.len() == 1;
- if let ExprKind::Path(ref qpath2) = args1[0].kind;
- if match_qpath(qpath2, &["expr"]);
- then {
- // report your lint here
- }
+if let ExprKind::Block(block, None) = expr.kind
+ && block.stmts.len() == 1
+ && let StmtKind::Local(local) = block.stmts[0].kind
+ && let Some(init) = local.init
+ && let ExprKind::Call(func, args) = init.kind
+ && let ExprKind::Path(ref qpath) = func.kind
+ && match_qpath(qpath, &["String", "new"])
+ && args.is_empty()
+ && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind
+ && name.as_str() == "expr"
+ && let Some(trailing_expr) = block.expr
+ && let ExprKind::Call(func1, args1) = trailing_expr.kind
+ && let ExprKind::Path(ref qpath1) = func1.kind
+ && match_qpath(qpath1, &["drop"])
+ && args1.len() == 1
+ && let ExprKind::Path(ref qpath2) = args1[0].kind
+ && match_qpath(qpath2, &["expr"])
+{
+ // report your lint here
}
-if_chain! {
- if let ExprKind::Closure(CaptureBy::Value, fn_decl, body_id, _, None) = expr.kind;
- if let FnRetTy::DefaultReturn(_) = fn_decl.output;
- let expr1 = &cx.tcx.hir().body(body_id).value;
- if let ExprKind::Call(func, args) = expr1.kind;
- if let ExprKind::Path(ref qpath) = func.kind;
- if matches!(qpath, QPath::LangItem(LangItem::FromGenerator, _));
- if args.len() == 1;
- if let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = args[0].kind;
- if let FnRetTy::DefaultReturn(_) = fn_decl1.output;
- let expr2 = &cx.tcx.hir().body(body_id1).value;
- if let ExprKind::Block(block, None) = expr2.kind;
- if block.stmts.is_empty();
- if block.expr.is_none();
- then {
- // report your lint here
- }
+if let ExprKind::Closure(CaptureBy::Value, fn_decl, body_id, _, None) = expr.kind
+ && let FnRetTy::DefaultReturn(_) = fn_decl.output
+ && expr1 = &cx.tcx.hir().body(body_id).value
+ && let ExprKind::Call(func, args) = expr1.kind
+ && let ExprKind::Path(ref qpath) = func.kind
+ && matches!(qpath, QPath::LangItem(LangItem::FromGenerator, _))
+ && args.len() == 1
+ && let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = args[0].kind
+ && let FnRetTy::DefaultReturn(_) = fn_decl1.output
+ && expr2 = &cx.tcx.hir().body(body_id1).value
+ && let ExprKind::Block(block, None) = expr2.kind
+ && block.stmts.is_empty()
+ && block.expr.is_none()
+{
+ // report your lint here
}
diff --git a/src/tools/clippy/tests/ui/author/call.stdout b/src/tools/clippy/tests/ui/author/call.stdout
index 266312d63..f040f6330 100644
--- a/src/tools/clippy/tests/ui/author/call.stdout
+++ b/src/tools/clippy/tests/ui/author/call.stdout
@@ -1,16 +1,14 @@
-if_chain! {
- if let StmtKind::Local(local) = stmt.kind;
- if let Some(init) = local.init;
- if let ExprKind::Call(func, args) = init.kind;
- if let ExprKind::Path(ref qpath) = func.kind;
- if match_qpath(qpath, &["{{root}}", "std", "cmp", "min"]);
- if args.len() == 2;
- if let ExprKind::Lit(ref lit) = args[0].kind;
- if let LitKind::Int(3, LitIntType::Unsuffixed) = lit.node;
- if let ExprKind::Lit(ref lit1) = args[1].kind;
- if let LitKind::Int(4, LitIntType::Unsuffixed) = lit1.node;
- if let PatKind::Wild = local.pat.kind;
- then {
- // report your lint here
- }
+if let StmtKind::Local(local) = stmt.kind
+ && let Some(init) = local.init
+ && let ExprKind::Call(func, args) = init.kind
+ && let ExprKind::Path(ref qpath) = func.kind
+ && match_qpath(qpath, &["{{root}}", "std", "cmp", "min"])
+ && args.len() == 2
+ && let ExprKind::Lit(ref lit) = args[0].kind
+ && let LitKind::Int(3, LitIntType::Unsuffixed) = lit.node
+ && let ExprKind::Lit(ref lit1) = args[1].kind
+ && let LitKind::Int(4, LitIntType::Unsuffixed) = lit1.node
+ && let PatKind::Wild = local.pat.kind
+{
+ // report your lint here
}
diff --git a/src/tools/clippy/tests/ui/author/if.stdout b/src/tools/clippy/tests/ui/author/if.stdout
index 8d92849b3..5d7961882 100644
--- a/src/tools/clippy/tests/ui/author/if.stdout
+++ b/src/tools/clippy/tests/ui/author/if.stdout
@@ -1,50 +1,46 @@
-if_chain! {
- if let StmtKind::Local(local) = stmt.kind;
- if let Some(init) = local.init;
- if let ExprKind::If(cond, then, Some(else_expr)) = init.kind;
- if let ExprKind::DropTemps(expr) = cond.kind;
- if let ExprKind::Lit(ref lit) = expr.kind;
- if let LitKind::Bool(true) = lit.node;
- if let ExprKind::Block(block, None) = then.kind;
- if block.stmts.len() == 1;
- if let StmtKind::Semi(e) = block.stmts[0].kind;
- if let ExprKind::Binary(op, left, right) = e.kind;
- if BinOpKind::Eq == op.node;
- if let ExprKind::Lit(ref lit1) = left.kind;
- if let LitKind::Int(1, LitIntType::Unsuffixed) = lit1.node;
- if let ExprKind::Lit(ref lit2) = right.kind;
- if let LitKind::Int(1, LitIntType::Unsuffixed) = lit2.node;
- if block.expr.is_none();
- if let ExprKind::Block(block1, None) = else_expr.kind;
- if block1.stmts.len() == 1;
- if let StmtKind::Semi(e1) = block1.stmts[0].kind;
- if let ExprKind::Binary(op1, left1, right1) = e1.kind;
- if BinOpKind::Eq == op1.node;
- if let ExprKind::Lit(ref lit3) = left1.kind;
- if let LitKind::Int(2, LitIntType::Unsuffixed) = lit3.node;
- if let ExprKind::Lit(ref lit4) = right1.kind;
- if let LitKind::Int(2, LitIntType::Unsuffixed) = lit4.node;
- if block1.expr.is_none();
- if let PatKind::Wild = local.pat.kind;
- then {
- // report your lint here
- }
+if let StmtKind::Local(local) = stmt.kind
+ && let Some(init) = local.init
+ && let ExprKind::If(cond, then, Some(else_expr)) = init.kind
+ && let ExprKind::DropTemps(expr) = cond.kind
+ && let ExprKind::Lit(ref lit) = expr.kind
+ && let LitKind::Bool(true) = lit.node
+ && let ExprKind::Block(block, None) = then.kind
+ && block.stmts.len() == 1
+ && let StmtKind::Semi(e) = block.stmts[0].kind
+ && let ExprKind::Binary(op, left, right) = e.kind
+ && BinOpKind::Eq == op.node
+ && let ExprKind::Lit(ref lit1) = left.kind
+ && let LitKind::Int(1, LitIntType::Unsuffixed) = lit1.node
+ && let ExprKind::Lit(ref lit2) = right.kind
+ && let LitKind::Int(1, LitIntType::Unsuffixed) = lit2.node
+ && block.expr.is_none()
+ && let ExprKind::Block(block1, None) = else_expr.kind
+ && block1.stmts.len() == 1
+ && let StmtKind::Semi(e1) = block1.stmts[0].kind
+ && let ExprKind::Binary(op1, left1, right1) = e1.kind
+ && BinOpKind::Eq == op1.node
+ && let ExprKind::Lit(ref lit3) = left1.kind
+ && let LitKind::Int(2, LitIntType::Unsuffixed) = lit3.node
+ && let ExprKind::Lit(ref lit4) = right1.kind
+ && let LitKind::Int(2, LitIntType::Unsuffixed) = lit4.node
+ && block1.expr.is_none()
+ && let PatKind::Wild = local.pat.kind
+{
+ // report your lint here
}
-if_chain! {
- if let ExprKind::If(cond, then, Some(else_expr)) = expr.kind;
- if let ExprKind::Let(let_expr) = cond.kind;
- if let PatKind::Lit(lit_expr) = let_expr.pat.kind;
- if let ExprKind::Lit(ref lit) = lit_expr.kind;
- if let LitKind::Bool(true) = lit.node;
- if let ExprKind::Path(ref qpath) = let_expr.init.kind;
- if match_qpath(qpath, &["a"]);
- if let ExprKind::Block(block, None) = then.kind;
- if block.stmts.is_empty();
- if block.expr.is_none();
- if let ExprKind::Block(block1, None) = else_expr.kind;
- if block1.stmts.is_empty();
- if block1.expr.is_none();
- then {
- // report your lint here
- }
+if let ExprKind::If(cond, then, Some(else_expr)) = expr.kind
+ && let ExprKind::Let(let_expr) = cond.kind
+ && let PatKind::Lit(lit_expr) = let_expr.pat.kind
+ && let ExprKind::Lit(ref lit) = lit_expr.kind
+ && let LitKind::Bool(true) = lit.node
+ && let ExprKind::Path(ref qpath) = let_expr.init.kind
+ && match_qpath(qpath, &["a"])
+ && let ExprKind::Block(block, None) = then.kind
+ && block.stmts.is_empty()
+ && block.expr.is_none()
+ && let ExprKind::Block(block1, None) = else_expr.kind
+ && block1.stmts.is_empty()
+ && block1.expr.is_none()
+{
+ // report your lint here
}
diff --git a/src/tools/clippy/tests/ui/author/issue_3849.stdout b/src/tools/clippy/tests/ui/author/issue_3849.stdout
index bce4bc702..32a3127b8 100644
--- a/src/tools/clippy/tests/ui/author/issue_3849.stdout
+++ b/src/tools/clippy/tests/ui/author/issue_3849.stdout
@@ -1,14 +1,12 @@
-if_chain! {
- if let StmtKind::Local(local) = stmt.kind;
- if let Some(init) = local.init;
- if let ExprKind::Call(func, args) = init.kind;
- if let ExprKind::Path(ref qpath) = func.kind;
- if match_qpath(qpath, &["std", "mem", "transmute"]);
- if args.len() == 1;
- if let ExprKind::Path(ref qpath1) = args[0].kind;
- if match_qpath(qpath1, &["ZPTR"]);
- if let PatKind::Wild = local.pat.kind;
- then {
- // report your lint here
- }
+if let StmtKind::Local(local) = stmt.kind
+ && let Some(init) = local.init
+ && let ExprKind::Call(func, args) = init.kind
+ && let ExprKind::Path(ref qpath) = func.kind
+ && match_qpath(qpath, &["std", "mem", "transmute"])
+ && args.len() == 1
+ && let ExprKind::Path(ref qpath1) = args[0].kind
+ && match_qpath(qpath1, &["ZPTR"])
+ && let PatKind::Wild = local.pat.kind
+{
+ // report your lint here
}
diff --git a/src/tools/clippy/tests/ui/author/loop.stdout b/src/tools/clippy/tests/ui/author/loop.stdout
index ceb53fcd4..94a6436ed 100644
--- a/src/tools/clippy/tests/ui/author/loop.stdout
+++ b/src/tools/clippy/tests/ui/author/loop.stdout
@@ -1,113 +1,101 @@
-if_chain! {
- if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr);
- if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = pat.kind;
- if name.as_str() == "y";
- if let ExprKind::Struct(qpath, fields, None) = arg.kind;
- if matches!(qpath, QPath::LangItem(LangItem::Range, _));
- if fields.len() == 2;
- if fields[0].ident.as_str() == "start";
- if let ExprKind::Lit(ref lit) = fields[0].expr.kind;
- if let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node;
- if fields[1].ident.as_str() == "end";
- if let ExprKind::Lit(ref lit1) = fields[1].expr.kind;
- if let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node;
- if let ExprKind::Block(block, None) = body.kind;
- if block.stmts.len() == 1;
- if let StmtKind::Local(local) = block.stmts[0].kind;
- if let Some(init) = local.init;
- if let ExprKind::Path(ref qpath1) = init.kind;
- if match_qpath(qpath1, &["y"]);
- if let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind;
- if name1.as_str() == "z";
- if block.expr.is_none();
- then {
- // report your lint here
- }
+if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr)
+ && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = pat.kind
+ && name.as_str() == "y"
+ && let ExprKind::Struct(qpath, fields, None) = arg.kind
+ && matches!(qpath, QPath::LangItem(LangItem::Range, _))
+ && fields.len() == 2
+ && fields[0].ident.as_str() == "start"
+ && let ExprKind::Lit(ref lit) = fields[0].expr.kind
+ && let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node
+ && fields[1].ident.as_str() == "end"
+ && let ExprKind::Lit(ref lit1) = fields[1].expr.kind
+ && let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node
+ && let ExprKind::Block(block, None) = body.kind
+ && block.stmts.len() == 1
+ && let StmtKind::Local(local) = block.stmts[0].kind
+ && let Some(init) = local.init
+ && let ExprKind::Path(ref qpath1) = init.kind
+ && match_qpath(qpath1, &["y"])
+ && let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind
+ && name1.as_str() == "z"
+ && block.expr.is_none()
+{
+ // report your lint here
}
-if_chain! {
- if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr);
- if let PatKind::Wild = pat.kind;
- if let ExprKind::Struct(qpath, fields, None) = arg.kind;
- if matches!(qpath, QPath::LangItem(LangItem::Range, _));
- if fields.len() == 2;
- if fields[0].ident.as_str() == "start";
- if let ExprKind::Lit(ref lit) = fields[0].expr.kind;
- if let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node;
- if fields[1].ident.as_str() == "end";
- if let ExprKind::Lit(ref lit1) = fields[1].expr.kind;
- if let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node;
- if let ExprKind::Block(block, None) = body.kind;
- if block.stmts.len() == 1;
- if let StmtKind::Semi(e) = block.stmts[0].kind;
- if let ExprKind::Break(destination, None) = e.kind;
- if destination.label.is_none();
- if block.expr.is_none();
- then {
- // report your lint here
- }
+if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr)
+ && let PatKind::Wild = pat.kind
+ && let ExprKind::Struct(qpath, fields, None) = arg.kind
+ && matches!(qpath, QPath::LangItem(LangItem::Range, _))
+ && fields.len() == 2
+ && fields[0].ident.as_str() == "start"
+ && let ExprKind::Lit(ref lit) = fields[0].expr.kind
+ && let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node
+ && fields[1].ident.as_str() == "end"
+ && let ExprKind::Lit(ref lit1) = fields[1].expr.kind
+ && let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node
+ && let ExprKind::Block(block, None) = body.kind
+ && block.stmts.len() == 1
+ && let StmtKind::Semi(e) = block.stmts[0].kind
+ && let ExprKind::Break(destination, None) = e.kind
+ && destination.label.is_none()
+ && block.expr.is_none()
+{
+ // report your lint here
}
-if_chain! {
- if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr);
- if let PatKind::Wild = pat.kind;
- if let ExprKind::Struct(qpath, fields, None) = arg.kind;
- if matches!(qpath, QPath::LangItem(LangItem::Range, _));
- if fields.len() == 2;
- if fields[0].ident.as_str() == "start";
- if let ExprKind::Lit(ref lit) = fields[0].expr.kind;
- if let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node;
- if fields[1].ident.as_str() == "end";
- if let ExprKind::Lit(ref lit1) = fields[1].expr.kind;
- if let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node;
- if let ExprKind::Block(block, None) = body.kind;
- if block.stmts.len() == 1;
- if let StmtKind::Semi(e) = block.stmts[0].kind;
- if let ExprKind::Break(destination, None) = e.kind;
- if let Some(label) = destination.label;
- if label.ident.as_str() == "'label";
- if block.expr.is_none();
- then {
- // report your lint here
- }
+if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr)
+ && let PatKind::Wild = pat.kind
+ && let ExprKind::Struct(qpath, fields, None) = arg.kind
+ && matches!(qpath, QPath::LangItem(LangItem::Range, _))
+ && fields.len() == 2
+ && fields[0].ident.as_str() == "start"
+ && let ExprKind::Lit(ref lit) = fields[0].expr.kind
+ && let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node
+ && fields[1].ident.as_str() == "end"
+ && let ExprKind::Lit(ref lit1) = fields[1].expr.kind
+ && let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node
+ && let ExprKind::Block(block, None) = body.kind
+ && block.stmts.len() == 1
+ && let StmtKind::Semi(e) = block.stmts[0].kind
+ && let ExprKind::Break(destination, None) = e.kind
+ && let Some(label) = destination.label
+ && label.ident.as_str() == "'label"
+ && block.expr.is_none()
+{
+ // report your lint here
}
-if_chain! {
- if let Some(higher::While { condition: condition, body: body }) = higher::While::hir(expr);
- if let ExprKind::Path(ref qpath) = condition.kind;
- if match_qpath(qpath, &["a"]);
- if let ExprKind::Block(block, None) = body.kind;
- if block.stmts.len() == 1;
- if let StmtKind::Semi(e) = block.stmts[0].kind;
- if let ExprKind::Break(destination, None) = e.kind;
- if destination.label.is_none();
- if block.expr.is_none();
- then {
- // report your lint here
- }
+if let Some(higher::While { condition: condition, body: body }) = higher::While::hir(expr)
+ && let ExprKind::Path(ref qpath) = condition.kind
+ && match_qpath(qpath, &["a"])
+ && let ExprKind::Block(block, None) = body.kind
+ && block.stmts.len() == 1
+ && let StmtKind::Semi(e) = block.stmts[0].kind
+ && let ExprKind::Break(destination, None) = e.kind
+ && destination.label.is_none()
+ && block.expr.is_none()
+{
+ // report your lint here
}
-if_chain! {
- if let Some(higher::WhileLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then }) = higher::WhileLet::hir(expr);
- if let PatKind::Lit(lit_expr) = let_pat.kind;
- if let ExprKind::Lit(ref lit) = lit_expr.kind;
- if let LitKind::Bool(true) = lit.node;
- if let ExprKind::Path(ref qpath) = let_expr.kind;
- if match_qpath(qpath, &["a"]);
- if let ExprKind::Block(block, None) = if_then.kind;
- if block.stmts.len() == 1;
- if let StmtKind::Semi(e) = block.stmts[0].kind;
- if let ExprKind::Break(destination, None) = e.kind;
- if destination.label.is_none();
- if block.expr.is_none();
- then {
- // report your lint here
- }
+if let Some(higher::WhileLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then }) = higher::WhileLet::hir(expr)
+ && let PatKind::Lit(lit_expr) = let_pat.kind
+ && let ExprKind::Lit(ref lit) = lit_expr.kind
+ && let LitKind::Bool(true) = lit.node
+ && let ExprKind::Path(ref qpath) = let_expr.kind
+ && match_qpath(qpath, &["a"])
+ && let ExprKind::Block(block, None) = if_then.kind
+ && block.stmts.len() == 1
+ && let StmtKind::Semi(e) = block.stmts[0].kind
+ && let ExprKind::Break(destination, None) = e.kind
+ && destination.label.is_none()
+ && block.expr.is_none()
+{
+ // report your lint here
}
-if_chain! {
- if let ExprKind::Loop(body, None, LoopSource::Loop, _) = expr.kind;
- if body.stmts.len() == 1;
- if let StmtKind::Semi(e) = body.stmts[0].kind;
- if let ExprKind::Break(destination, None) = e.kind;
- if destination.label.is_none();
- if body.expr.is_none();
- then {
- // report your lint here
- }
+if let ExprKind::Loop(body, None, LoopSource::Loop, _) = expr.kind
+ && body.stmts.len() == 1
+ && let StmtKind::Semi(e) = body.stmts[0].kind
+ && let ExprKind::Break(destination, None) = e.kind
+ && destination.label.is_none()
+ && body.expr.is_none()
+{
+ // report your lint here
}
diff --git a/src/tools/clippy/tests/ui/author/matches.stdout b/src/tools/clippy/tests/ui/author/matches.stdout
index 2cf69a035..88e2ca656 100644
--- a/src/tools/clippy/tests/ui/author/matches.stdout
+++ b/src/tools/clippy/tests/ui/author/matches.stdout
@@ -1,38 +1,36 @@
-if_chain! {
- if let StmtKind::Local(local) = stmt.kind;
- if let Some(init) = local.init;
- if let ExprKind::Match(scrutinee, arms, MatchSource::Normal) = init.kind;
- if let ExprKind::Lit(ref lit) = scrutinee.kind;
- if let LitKind::Int(42, LitIntType::Unsuffixed) = lit.node;
- if arms.len() == 3;
- if let PatKind::Lit(lit_expr) = arms[0].pat.kind;
- if let ExprKind::Lit(ref lit1) = lit_expr.kind;
- if let LitKind::Int(16, LitIntType::Unsuffixed) = lit1.node;
- if arms[0].guard.is_none();
- if let ExprKind::Lit(ref lit2) = arms[0].body.kind;
- if let LitKind::Int(5, LitIntType::Unsuffixed) = lit2.node;
- if let PatKind::Lit(lit_expr1) = arms[1].pat.kind;
- if let ExprKind::Lit(ref lit3) = lit_expr1.kind;
- if let LitKind::Int(17, LitIntType::Unsuffixed) = lit3.node;
- if arms[1].guard.is_none();
- if let ExprKind::Block(block, None) = arms[1].body.kind;
- if block.stmts.len() == 1;
- if let StmtKind::Local(local1) = block.stmts[0].kind;
- if let Some(init1) = local1.init;
- if let ExprKind::Lit(ref lit4) = init1.kind;
- if let LitKind::Int(3, LitIntType::Unsuffixed) = lit4.node;
- if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local1.pat.kind;
- if name.as_str() == "x";
- if let Some(trailing_expr) = block.expr;
- if let ExprKind::Path(ref qpath) = trailing_expr.kind;
- if match_qpath(qpath, &["x"]);
- if let PatKind::Wild = arms[2].pat.kind;
- if arms[2].guard.is_none();
- if let ExprKind::Lit(ref lit5) = arms[2].body.kind;
- if let LitKind::Int(1, LitIntType::Unsuffixed) = lit5.node;
- if let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind;
- if name1.as_str() == "a";
- then {
- // report your lint here
- }
+if let StmtKind::Local(local) = stmt.kind
+ && let Some(init) = local.init
+ && let ExprKind::Match(scrutinee, arms, MatchSource::Normal) = init.kind
+ && let ExprKind::Lit(ref lit) = scrutinee.kind
+ && let LitKind::Int(42, LitIntType::Unsuffixed) = lit.node
+ && arms.len() == 3
+ && let PatKind::Lit(lit_expr) = arms[0].pat.kind
+ && let ExprKind::Lit(ref lit1) = lit_expr.kind
+ && let LitKind::Int(16, LitIntType::Unsuffixed) = lit1.node
+ && arms[0].guard.is_none()
+ && let ExprKind::Lit(ref lit2) = arms[0].body.kind
+ && let LitKind::Int(5, LitIntType::Unsuffixed) = lit2.node
+ && let PatKind::Lit(lit_expr1) = arms[1].pat.kind
+ && let ExprKind::Lit(ref lit3) = lit_expr1.kind
+ && let LitKind::Int(17, LitIntType::Unsuffixed) = lit3.node
+ && arms[1].guard.is_none()
+ && let ExprKind::Block(block, None) = arms[1].body.kind
+ && block.stmts.len() == 1
+ && let StmtKind::Local(local1) = block.stmts[0].kind
+ && let Some(init1) = local1.init
+ && let ExprKind::Lit(ref lit4) = init1.kind
+ && let LitKind::Int(3, LitIntType::Unsuffixed) = lit4.node
+ && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local1.pat.kind
+ && name.as_str() == "x"
+ && let Some(trailing_expr) = block.expr
+ && let ExprKind::Path(ref qpath) = trailing_expr.kind
+ && match_qpath(qpath, &["x"])
+ && let PatKind::Wild = arms[2].pat.kind
+ && arms[2].guard.is_none()
+ && let ExprKind::Lit(ref lit5) = arms[2].body.kind
+ && let LitKind::Int(1, LitIntType::Unsuffixed) = lit5.node
+ && let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind
+ && name1.as_str() == "a"
+{
+ // report your lint here
}
diff --git a/src/tools/clippy/tests/ui/author/repeat.stdout b/src/tools/clippy/tests/ui/author/repeat.stdout
index 471bbce4f..c2a369610 100644
--- a/src/tools/clippy/tests/ui/author/repeat.stdout
+++ b/src/tools/clippy/tests/ui/author/repeat.stdout
@@ -1,12 +1,10 @@
-if_chain! {
- if let ExprKind::Repeat(value, length) = expr.kind;
- if let ExprKind::Lit(ref lit) = value.kind;
- if let LitKind::Int(1, LitIntType::Unsigned(UintTy::U8)) = lit.node;
- if let ArrayLen::Body(anon_const) = length;
- let expr1 = &cx.tcx.hir().body(anon_const.body).value;
- if let ExprKind::Lit(ref lit1) = expr1.kind;
- if let LitKind::Int(5, LitIntType::Unsuffixed) = lit1.node;
- then {
- // report your lint here
- }
+if let ExprKind::Repeat(value, length) = expr.kind
+ && let ExprKind::Lit(ref lit) = value.kind
+ && let LitKind::Int(1, LitIntType::Unsigned(UintTy::U8)) = lit.node
+ && let ArrayLen::Body(anon_const) = length
+ && expr1 = &cx.tcx.hir().body(anon_const.body).value
+ && let ExprKind::Lit(ref lit1) = expr1.kind
+ && let LitKind::Int(5, LitIntType::Unsuffixed) = lit1.node
+{
+ // report your lint here
}
diff --git a/src/tools/clippy/tests/ui/author/struct.stdout b/src/tools/clippy/tests/ui/author/struct.stdout
index b5bbc9e21..0b332d5e7 100644
--- a/src/tools/clippy/tests/ui/author/struct.stdout
+++ b/src/tools/clippy/tests/ui/author/struct.stdout
@@ -1,64 +1,56 @@
-if_chain! {
- if let ExprKind::Struct(qpath, fields, None) = expr.kind;
- if match_qpath(qpath, &["Test"]);
- if fields.len() == 1;
- if fields[0].ident.as_str() == "field";
- if let ExprKind::If(cond, then, Some(else_expr)) = fields[0].expr.kind;
- if let ExprKind::DropTemps(expr1) = cond.kind;
- if let ExprKind::Lit(ref lit) = expr1.kind;
- if let LitKind::Bool(true) = lit.node;
- if let ExprKind::Block(block, None) = then.kind;
- if block.stmts.is_empty();
- if let Some(trailing_expr) = block.expr;
- if let ExprKind::Lit(ref lit1) = trailing_expr.kind;
- if let LitKind::Int(1, LitIntType::Unsuffixed) = lit1.node;
- if let ExprKind::Block(block1, None) = else_expr.kind;
- if block1.stmts.is_empty();
- if let Some(trailing_expr1) = block1.expr;
- if let ExprKind::Lit(ref lit2) = trailing_expr1.kind;
- if let LitKind::Int(0, LitIntType::Unsuffixed) = lit2.node;
- then {
- // report your lint here
- }
+if let ExprKind::Struct(qpath, fields, None) = expr.kind
+ && match_qpath(qpath, &["Test"])
+ && fields.len() == 1
+ && fields[0].ident.as_str() == "field"
+ && let ExprKind::If(cond, then, Some(else_expr)) = fields[0].expr.kind
+ && let ExprKind::DropTemps(expr1) = cond.kind
+ && let ExprKind::Lit(ref lit) = expr1.kind
+ && let LitKind::Bool(true) = lit.node
+ && let ExprKind::Block(block, None) = then.kind
+ && block.stmts.is_empty()
+ && let Some(trailing_expr) = block.expr
+ && let ExprKind::Lit(ref lit1) = trailing_expr.kind
+ && let LitKind::Int(1, LitIntType::Unsuffixed) = lit1.node
+ && let ExprKind::Block(block1, None) = else_expr.kind
+ && block1.stmts.is_empty()
+ && let Some(trailing_expr1) = block1.expr
+ && let ExprKind::Lit(ref lit2) = trailing_expr1.kind
+ && let LitKind::Int(0, LitIntType::Unsuffixed) = lit2.node
+{
+ // report your lint here
}
-if_chain! {
- if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind;
- if match_qpath(qpath, &["Test"]);
- if fields.len() == 1;
- if fields[0].ident.as_str() == "field";
- if let PatKind::Lit(lit_expr) = fields[0].pat.kind;
- if let ExprKind::Lit(ref lit) = lit_expr.kind;
- if let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node;
- if arm.guard.is_none();
- if let ExprKind::Block(block, None) = arm.body.kind;
- if block.stmts.is_empty();
- if block.expr.is_none();
- then {
- // report your lint here
- }
+if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind
+ && match_qpath(qpath, &["Test"])
+ && fields.len() == 1
+ && fields[0].ident.as_str() == "field"
+ && let PatKind::Lit(lit_expr) = fields[0].pat.kind
+ && let ExprKind::Lit(ref lit) = lit_expr.kind
+ && let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
+ && arm.guard.is_none()
+ && let ExprKind::Block(block, None) = arm.body.kind
+ && block.stmts.is_empty()
+ && block.expr.is_none()
+{
+ // report your lint here
}
-if_chain! {
- if let PatKind::TupleStruct(ref qpath, fields, None) = arm.pat.kind;
- if match_qpath(qpath, &["TestTuple"]);
- if fields.len() == 1;
- if let PatKind::Lit(lit_expr) = fields[0].kind;
- if let ExprKind::Lit(ref lit) = lit_expr.kind;
- if let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node;
- if arm.guard.is_none();
- if let ExprKind::Block(block, None) = arm.body.kind;
- if block.stmts.is_empty();
- if block.expr.is_none();
- then {
- // report your lint here
- }
+if let PatKind::TupleStruct(ref qpath, fields, None) = arm.pat.kind
+ && match_qpath(qpath, &["TestTuple"])
+ && fields.len() == 1
+ && let PatKind::Lit(lit_expr) = fields[0].kind
+ && let ExprKind::Lit(ref lit) = lit_expr.kind
+ && let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
+ && arm.guard.is_none()
+ && let ExprKind::Block(block, None) = arm.body.kind
+ && block.stmts.is_empty()
+ && block.expr.is_none()
+{
+ // report your lint here
}
-if_chain! {
- if let ExprKind::MethodCall(method_name, receiver, args, _) = expr.kind;
- if method_name.ident.as_str() == "test";
- if let ExprKind::Path(ref qpath) = receiver.kind;
- if match_qpath(qpath, &["test_method_call"]);
- if args.is_empty();
- then {
- // report your lint here
- }
+if let ExprKind::MethodCall(method_name, receiver, args, _) = expr.kind
+ && method_name.ident.as_str() == "test"
+ && let ExprKind::Path(ref qpath) = receiver.kind
+ && match_qpath(qpath, &["test_method_call"])
+ && args.is_empty()
+{
+ // report your lint here
}
diff --git a/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs b/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs
index 83a0af6b8..ef3ca9aea 100644
--- a/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/macro_rules.rs
@@ -140,3 +140,10 @@ macro_rules! manual_rem_euclid {
macro_rules! equatable_if_let {
($a:ident) => {{ if let 2 = $a {} }};
}
+
+#[macro_export]
+macro_rules! almost_complete_letter_range {
+ () => {
+ let _ = 'a'..'z';
+ };
+}
diff --git a/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs b/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs
index ae2cc2492..4914f14b5 100644
--- a/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs
+++ b/src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs
@@ -4,7 +4,7 @@
#![crate_type = "proc-macro"]
#![feature(repr128, proc_macro_hygiene, proc_macro_quote, box_patterns)]
#![allow(incomplete_features)]
-#![allow(clippy::useless_conversion)]
+#![allow(clippy::useless_conversion, clippy::uninlined_format_args)]
extern crate proc_macro;
extern crate quote;
diff --git a/src/tools/clippy/tests/ui/await_holding_lock.stderr b/src/tools/clippy/tests/ui/await_holding_lock.stderr
index 976da8d92..81a2d0524 100644
--- a/src/tools/clippy/tests/ui/await_holding_lock.stderr
+++ b/src/tools/clippy/tests/ui/await_holding_lock.stderr
@@ -4,7 +4,6 @@ error: this `MutexGuard` is held across an `await` point
LL | let guard = x.lock().unwrap();
| ^^^^^
|
- = note: `-D clippy::await-holding-lock` implied by `-D warnings`
= help: consider using an async-aware `Mutex` type or ensuring the `MutexGuard` is dropped before calling await
note: these are all the `await` points this lock is held through
--> $DIR/await_holding_lock.rs:9:9
@@ -13,6 +12,7 @@ LL | / let guard = x.lock().unwrap();
LL | | baz().await
LL | | }
| |_____^
+ = note: `-D clippy::await-holding-lock` implied by `-D warnings`
error: this `MutexGuard` is held across an `await` point
--> $DIR/await_holding_lock.rs:24:13
diff --git a/src/tools/clippy/tests/ui/await_holding_refcell_ref.stderr b/src/tools/clippy/tests/ui/await_holding_refcell_ref.stderr
index 4339fca73..25c15ab80 100644
--- a/src/tools/clippy/tests/ui/await_holding_refcell_ref.stderr
+++ b/src/tools/clippy/tests/ui/await_holding_refcell_ref.stderr
@@ -4,7 +4,6 @@ error: this `RefCell` reference is held across an `await` point
LL | let b = x.borrow();
| ^
|
- = note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings`
= help: ensure the reference is dropped before calling `await`
note: these are all the `await` points this reference is held through
--> $DIR/await_holding_refcell_ref.rs:6:5
@@ -13,6 +12,7 @@ LL | / let b = x.borrow();
LL | | baz().await
LL | | }
| |_^
+ = note: `-D clippy::await-holding-refcell-ref` implied by `-D warnings`
error: this `RefCell` reference is held across an `await` point
--> $DIR/await_holding_refcell_ref.rs:11:9
diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map.fixed b/src/tools/clippy/tests/ui/bind_instead_of_map.fixed
index 5815550d7..d94e2ac60 100644
--- a/src/tools/clippy/tests/ui/bind_instead_of_map.fixed
+++ b/src/tools/clippy/tests/ui/bind_instead_of_map.fixed
@@ -1,5 +1,6 @@
// run-rustfix
#![deny(clippy::bind_instead_of_map)]
+#![allow(clippy::uninlined_format_args)]
// need a main anyway, use it get rid of unused warnings too
pub fn main() {
diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map.rs b/src/tools/clippy/tests/ui/bind_instead_of_map.rs
index 623b100a4..86f31f582 100644
--- a/src/tools/clippy/tests/ui/bind_instead_of_map.rs
+++ b/src/tools/clippy/tests/ui/bind_instead_of_map.rs
@@ -1,5 +1,6 @@
// run-rustfix
#![deny(clippy::bind_instead_of_map)]
+#![allow(clippy::uninlined_format_args)]
// need a main anyway, use it get rid of unused warnings too
pub fn main() {
diff --git a/src/tools/clippy/tests/ui/bind_instead_of_map.stderr b/src/tools/clippy/tests/ui/bind_instead_of_map.stderr
index 24c6b7f9e..b6a81d21b 100644
--- a/src/tools/clippy/tests/ui/bind_instead_of_map.stderr
+++ b/src/tools/clippy/tests/ui/bind_instead_of_map.stderr
@@ -1,5 +1,5 @@
error: using `Option.and_then(Some)`, which is a no-op
- --> $DIR/bind_instead_of_map.rs:8:13
+ --> $DIR/bind_instead_of_map.rs:9:13
|
LL | let _ = x.and_then(Some);
| ^^^^^^^^^^^^^^^^ help: use the expression directly: `x`
@@ -11,13 +11,13 @@ LL | #![deny(clippy::bind_instead_of_map)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`
- --> $DIR/bind_instead_of_map.rs:9:13
+ --> $DIR/bind_instead_of_map.rs:10:13
|
LL | let _ = x.and_then(|o| Some(o + 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `x.map(|o| o + 1)`
error: using `Result.and_then(Ok)`, which is a no-op
- --> $DIR/bind_instead_of_map.rs:15:13
+ --> $DIR/bind_instead_of_map.rs:16:13
|
LL | let _ = x.and_then(Ok);
| ^^^^^^^^^^^^^^ help: use the expression directly: `x`
diff --git a/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr b/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr
index 537557f8b..e83eb4d60 100644
--- a/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr
+++ b/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr
@@ -4,8 +4,8 @@ error: restriction lints are not meant to be all enabled
LL | #![warn(clippy::restriction)]
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings`
= help: try enabling only the lints you really need
+ = note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings`
error: restriction lints are not meant to be all enabled
--> $DIR/blanket_clippy_restriction_lints.rs:5:9
diff --git a/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed b/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed
index 9c1098dc4..2c8339cdd 100644
--- a/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed
+++ b/src/tools/clippy/tests/ui/bool_to_int_with_if.fixed
@@ -14,6 +14,7 @@ fn main() {
// precedence
i32::from(a);
i32::from(!a);
+ i32::from(!a);
i32::from(a || b);
i32::from(cond(a, b));
i32::from(x + y < 4);
@@ -21,7 +22,12 @@ fn main() {
// if else if
if a {
123
- } else {i32::from(b)};
+ } else { i32::from(b) };
+
+ // if else if inverted
+ if a {
+ 123
+ } else { i32::from(!b) };
// Shouldn't lint
diff --git a/src/tools/clippy/tests/ui/bool_to_int_with_if.rs b/src/tools/clippy/tests/ui/bool_to_int_with_if.rs
index 0c967dac6..5d9496f01 100644
--- a/src/tools/clippy/tests/ui/bool_to_int_with_if.rs
+++ b/src/tools/clippy/tests/ui/bool_to_int_with_if.rs
@@ -17,6 +17,11 @@ fn main() {
} else {
0
};
+ if a {
+ 0
+ } else {
+ 1
+ };
if !a {
1
} else {
@@ -47,6 +52,15 @@ fn main() {
0
};
+ // if else if inverted
+ if a {
+ 123
+ } else if b {
+ 0
+ } else {
+ 1
+ };
+
// Shouldn't lint
if a {
diff --git a/src/tools/clippy/tests/ui/bool_to_int_with_if.stderr b/src/tools/clippy/tests/ui/bool_to_int_with_if.stderr
index 8647a9cff..4cb5531be 100644
--- a/src/tools/clippy/tests/ui/bool_to_int_with_if.stderr
+++ b/src/tools/clippy/tests/ui/bool_to_int_with_if.stderr
@@ -8,12 +8,24 @@ LL | | 0
LL | | };
| |_____^ help: replace with from: `i32::from(a)`
|
- = note: `-D clippy::bool-to-int-with-if` implied by `-D warnings`
= note: `a as i32` or `a.into()` can also be valid options
+ = note: `-D clippy::bool-to-int-with-if` implied by `-D warnings`
error: boolean to int conversion using if
--> $DIR/bool_to_int_with_if.rs:20:5
|
+LL | / if a {
+LL | | 0
+LL | | } else {
+LL | | 1
+LL | | };
+ | |_____^ help: replace with from: `i32::from(!a)`
+ |
+ = note: `!a as i32` or `(!a).into()` can also be valid options
+
+error: boolean to int conversion using if
+ --> $DIR/bool_to_int_with_if.rs:25:5
+ |
LL | / if !a {
LL | | 1
LL | | } else {
@@ -21,10 +33,10 @@ LL | | 0
LL | | };
| |_____^ help: replace with from: `i32::from(!a)`
|
- = note: `!a as i32` or `!a.into()` can also be valid options
+ = note: `!a as i32` or `(!a).into()` can also be valid options
error: boolean to int conversion using if
- --> $DIR/bool_to_int_with_if.rs:25:5
+ --> $DIR/bool_to_int_with_if.rs:30:5
|
LL | / if a || b {
LL | | 1
@@ -36,7 +48,7 @@ LL | | };
= note: `(a || b) as i32` or `(a || b).into()` can also be valid options
error: boolean to int conversion using if
- --> $DIR/bool_to_int_with_if.rs:30:5
+ --> $DIR/bool_to_int_with_if.rs:35:5
|
LL | / if cond(a, b) {
LL | | 1
@@ -48,7 +60,7 @@ LL | | };
= note: `cond(a, b) as i32` or `cond(a, b).into()` can also be valid options
error: boolean to int conversion using if
- --> $DIR/bool_to_int_with_if.rs:35:5
+ --> $DIR/bool_to_int_with_if.rs:40:5
|
LL | / if x + y < 4 {
LL | | 1
@@ -60,7 +72,7 @@ LL | | };
= note: `(x + y < 4) as i32` or `(x + y < 4).into()` can also be valid options
error: boolean to int conversion using if
- --> $DIR/bool_to_int_with_if.rs:44:12
+ --> $DIR/bool_to_int_with_if.rs:49:12
|
LL | } else if b {
| ____________^
@@ -68,17 +80,30 @@ LL | | 1
LL | | } else {
LL | | 0
LL | | };
- | |_____^ help: replace with from: `{i32::from(b)}`
+ | |_____^ help: replace with from: `{ i32::from(b) }`
|
= note: `b as i32` or `b.into()` can also be valid options
error: boolean to int conversion using if
- --> $DIR/bool_to_int_with_if.rs:102:5
+ --> $DIR/bool_to_int_with_if.rs:58:12
+ |
+LL | } else if b {
+ | ____________^
+LL | | 0
+LL | | } else {
+LL | | 1
+LL | | };
+ | |_____^ help: replace with from: `{ i32::from(!b) }`
+ |
+ = note: `!b as i32` or `(!b).into()` can also be valid options
+
+error: boolean to int conversion using if
+ --> $DIR/bool_to_int_with_if.rs:116:5
|
LL | if a { 1 } else { 0 }
| ^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `u8::from(a)`
|
= note: `a as u8` or `a.into()` can also be valid options
-error: aborting due to 7 previous errors
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/borrow_box.rs b/src/tools/clippy/tests/ui/borrow_box.rs
index 35ed87b0f..3b5b6bf4c 100644
--- a/src/tools/clippy/tests/ui/borrow_box.rs
+++ b/src/tools/clippy/tests/ui/borrow_box.rs
@@ -1,7 +1,6 @@
#![deny(clippy::borrowed_box)]
-#![allow(clippy::disallowed_names)]
-#![allow(unused_variables)]
-#![allow(dead_code)]
+#![allow(dead_code, unused_variables)]
+#![allow(clippy::uninlined_format_args, clippy::disallowed_names)]
use std::fmt::Display;
diff --git a/src/tools/clippy/tests/ui/borrow_box.stderr b/src/tools/clippy/tests/ui/borrow_box.stderr
index 3eac32815..99cb60a1e 100644
--- a/src/tools/clippy/tests/ui/borrow_box.stderr
+++ b/src/tools/clippy/tests/ui/borrow_box.stderr
@@ -1,5 +1,5 @@
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:21:14
+ --> $DIR/borrow_box.rs:20:14
|
LL | let foo: &Box<bool>;
| ^^^^^^^^^^ help: try: `&bool`
@@ -11,55 +11,55 @@ LL | #![deny(clippy::borrowed_box)]
| ^^^^^^^^^^^^^^^^^^^^
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:25:10
+ --> $DIR/borrow_box.rs:24:10
|
LL | foo: &'a Box<bool>,
| ^^^^^^^^^^^^^ help: try: `&'a bool`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:29:17
+ --> $DIR/borrow_box.rs:28:17
|
LL | fn test4(a: &Box<bool>);
| ^^^^^^^^^^ help: try: `&bool`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:95:25
+ --> $DIR/borrow_box.rs:94:25
|
LL | pub fn test14(_display: &Box<dyn Display>) {}
| ^^^^^^^^^^^^^^^^^ help: try: `&dyn Display`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:96:25
+ --> $DIR/borrow_box.rs:95:25
|
LL | pub fn test15(_display: &Box<dyn Display + Send>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:97:29
+ --> $DIR/borrow_box.rs:96:29
|
LL | pub fn test16<'a>(_display: &'a Box<dyn Display + 'a>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (dyn Display + 'a)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:99:25
+ --> $DIR/borrow_box.rs:98:25
|
LL | pub fn test17(_display: &Box<impl Display>) {}
| ^^^^^^^^^^^^^^^^^^ help: try: `&impl Display`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:100:25
+ --> $DIR/borrow_box.rs:99:25
|
LL | pub fn test18(_display: &Box<impl Display + Send>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(impl Display + Send)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:101:29
+ --> $DIR/borrow_box.rs:100:29
|
LL | pub fn test19<'a>(_display: &'a Box<impl Display + 'a>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&'a (impl Display + 'a)`
error: you seem to be trying to use `&Box<T>`. Consider using just `&T`
- --> $DIR/borrow_box.rs:106:25
+ --> $DIR/borrow_box.rs:105:25
|
LL | pub fn test20(_display: &Box<(dyn Display + Send)>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&(dyn Display + Send)`
diff --git a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.stderr b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.stderr
index 654a1ee7d..b0cab977a 100644
--- a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.stderr
+++ b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/enums.stderr
@@ -4,8 +4,8 @@ error: a `const` item with interior mutability should not be borrowed
LL | let _ = &UNFROZEN_VARIANT; //~ ERROR interior mutability
| ^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
= help: assign this const to a local or static variable, and use the variable here
+ = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
error: a `const` item with interior mutability should not be borrowed
--> $DIR/enums.rs:37:18
diff --git a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.stderr b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.stderr
index 9a908cf30..c87ad206c 100644
--- a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.stderr
+++ b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/others.stderr
@@ -4,8 +4,8 @@ error: a `const` item with interior mutability should not be borrowed
LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
| ^^^^^^
|
- = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
= help: assign this const to a local or static variable, and use the variable here
+ = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
error: a `const` item with interior mutability should not be borrowed
--> $DIR/others.rs:55:16
diff --git a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.stderr b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.stderr
index 8f26403ab..f34ae8814 100644
--- a/src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.stderr
+++ b/src/tools/clippy/tests/ui/borrow_interior_mutable_const/traits.stderr
@@ -4,8 +4,8 @@ error: a `const` item with interior mutability should not be borrowed
LL | let _ = &Self::ATOMIC; //~ ERROR interior mutable
| ^^^^^^^^^^^^
|
- = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
= help: assign this const to a local or static variable, and use the variable here
+ = note: `-D clippy::borrow-interior-mutable-const` implied by `-D warnings`
error: a `const` item with interior mutability should not be borrowed
--> $DIR/traits.rs:26:18
diff --git a/src/tools/clippy/tests/ui/box_collection.rs b/src/tools/clippy/tests/ui/box_collection.rs
index 0780c8f05..4c9947b9a 100644
--- a/src/tools/clippy/tests/ui/box_collection.rs
+++ b/src/tools/clippy/tests/ui/box_collection.rs
@@ -15,7 +15,7 @@ macro_rules! boxit {
}
fn test_macro() {
- boxit!(Vec::new(), Vec<u8>);
+ boxit!(vec![1], Vec<u8>);
}
fn test1(foo: Box<Vec<bool>>) {}
@@ -50,7 +50,7 @@ fn test_local_not_linted() {
pub fn pub_test(foo: Box<Vec<bool>>) {}
pub fn pub_test_ret() -> Box<Vec<bool>> {
- Box::new(Vec::new())
+ Box::default()
}
fn main() {}
diff --git a/src/tools/clippy/tests/ui/box_collection.stderr b/src/tools/clippy/tests/ui/box_collection.stderr
index 2b28598de..40b6f9be6 100644
--- a/src/tools/clippy/tests/ui/box_collection.stderr
+++ b/src/tools/clippy/tests/ui/box_collection.stderr
@@ -4,8 +4,8 @@ error: you seem to be trying to use `Box<Vec<..>>`. Consider using just `Vec<..>
LL | fn test1(foo: Box<Vec<bool>>) {}
| ^^^^^^^^^^^^^^
|
- = note: `-D clippy::box-collection` implied by `-D warnings`
= help: `Vec<..>` is already on the heap, `Box<Vec<..>>` makes an extra allocation
+ = note: `-D clippy::box-collection` implied by `-D warnings`
error: you seem to be trying to use `Box<String>`. Consider using just `String`
--> $DIR/box_collection.rs:28:15
diff --git a/src/tools/clippy/tests/ui/box_default.fixed b/src/tools/clippy/tests/ui/box_default.fixed
new file mode 100644
index 000000000..911fa856a
--- /dev/null
+++ b/src/tools/clippy/tests/ui/box_default.fixed
@@ -0,0 +1,57 @@
+// run-rustfix
+#![warn(clippy::box_default)]
+
+#[derive(Default)]
+struct ImplementsDefault;
+
+struct OwnDefault;
+
+impl OwnDefault {
+ fn default() -> Self {
+ Self
+ }
+}
+
+macro_rules! outer {
+ ($e: expr) => {
+ $e
+ };
+}
+
+fn main() {
+ let _string: Box<String> = Box::default();
+ let _byte = Box::<u8>::default();
+ let _vec = Box::<std::vec::Vec<u8>>::default();
+ let _impl = Box::<ImplementsDefault>::default();
+ let _impl2 = Box::<ImplementsDefault>::default();
+ let _impl3: Box<ImplementsDefault> = Box::default();
+ let _own = Box::new(OwnDefault::default()); // should not lint
+ let _in_macro = outer!(Box::<std::string::String>::default());
+ let _string_default = outer!(Box::<std::string::String>::default());
+ let _vec2: Box<Vec<ImplementsDefault>> = Box::default();
+ let _vec3: Box<Vec<bool>> = Box::default();
+ let _vec4: Box<_> = Box::<std::vec::Vec<bool>>::default();
+ let _more = ret_ty_fn();
+ call_ty_fn(Box::default());
+}
+
+fn ret_ty_fn() -> Box<bool> {
+ Box::<bool>::default()
+}
+
+#[allow(clippy::boxed_local)]
+fn call_ty_fn(_b: Box<u8>) {
+ issue_9621_dyn_trait();
+}
+
+use std::io::{Read, Result};
+
+impl Read for ImplementsDefault {
+ fn read(&mut self, _: &mut [u8]) -> Result<usize> {
+ Ok(0)
+ }
+}
+
+fn issue_9621_dyn_trait() {
+ let _: Box<dyn Read> = Box::<ImplementsDefault>::default();
+}
diff --git a/src/tools/clippy/tests/ui/box_default.rs b/src/tools/clippy/tests/ui/box_default.rs
new file mode 100644
index 000000000..20019c2ee
--- /dev/null
+++ b/src/tools/clippy/tests/ui/box_default.rs
@@ -0,0 +1,57 @@
+// run-rustfix
+#![warn(clippy::box_default)]
+
+#[derive(Default)]
+struct ImplementsDefault;
+
+struct OwnDefault;
+
+impl OwnDefault {
+ fn default() -> Self {
+ Self
+ }
+}
+
+macro_rules! outer {
+ ($e: expr) => {
+ $e
+ };
+}
+
+fn main() {
+ let _string: Box<String> = Box::new(Default::default());
+ let _byte = Box::new(u8::default());
+ let _vec = Box::new(Vec::<u8>::new());
+ let _impl = Box::new(ImplementsDefault::default());
+ let _impl2 = Box::new(<ImplementsDefault as Default>::default());
+ let _impl3: Box<ImplementsDefault> = Box::new(Default::default());
+ let _own = Box::new(OwnDefault::default()); // should not lint
+ let _in_macro = outer!(Box::new(String::new()));
+ let _string_default = outer!(Box::new(String::from("")));
+ let _vec2: Box<Vec<ImplementsDefault>> = Box::new(vec![]);
+ let _vec3: Box<Vec<bool>> = Box::new(Vec::from([]));
+ let _vec4: Box<_> = Box::new(Vec::from([false; 0]));
+ let _more = ret_ty_fn();
+ call_ty_fn(Box::new(u8::default()));
+}
+
+fn ret_ty_fn() -> Box<bool> {
+ Box::new(bool::default())
+}
+
+#[allow(clippy::boxed_local)]
+fn call_ty_fn(_b: Box<u8>) {
+ issue_9621_dyn_trait();
+}
+
+use std::io::{Read, Result};
+
+impl Read for ImplementsDefault {
+ fn read(&mut self, _: &mut [u8]) -> Result<usize> {
+ Ok(0)
+ }
+}
+
+fn issue_9621_dyn_trait() {
+ let _: Box<dyn Read> = Box::new(ImplementsDefault::default());
+}
diff --git a/src/tools/clippy/tests/ui/box_default.stderr b/src/tools/clippy/tests/ui/box_default.stderr
new file mode 100644
index 000000000..5ea410331
--- /dev/null
+++ b/src/tools/clippy/tests/ui/box_default.stderr
@@ -0,0 +1,88 @@
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:22:32
+ |
+LL | let _string: Box<String> = Box::new(Default::default());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()`
+ |
+ = note: `-D clippy::box-default` implied by `-D warnings`
+
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:23:17
+ |
+LL | let _byte = Box::new(u8::default());
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<u8>::default()`
+
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:24:16
+ |
+LL | let _vec = Box::new(Vec::<u8>::new());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::vec::Vec<u8>>::default()`
+
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:25:17
+ |
+LL | let _impl = Box::new(ImplementsDefault::default());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<ImplementsDefault>::default()`
+
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:26:18
+ |
+LL | let _impl2 = Box::new(<ImplementsDefault as Default>::default());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<ImplementsDefault>::default()`
+
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:27:42
+ |
+LL | let _impl3: Box<ImplementsDefault> = Box::new(Default::default());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()`
+
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:29:28
+ |
+LL | let _in_macro = outer!(Box::new(String::new()));
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::string::String>::default()`
+
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:30:34
+ |
+LL | let _string_default = outer!(Box::new(String::from("")));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::string::String>::default()`
+
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:31:46
+ |
+LL | let _vec2: Box<Vec<ImplementsDefault>> = Box::new(vec![]);
+ | ^^^^^^^^^^^^^^^^ help: try: `Box::default()`
+
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:32:33
+ |
+LL | let _vec3: Box<Vec<bool>> = Box::new(Vec::from([]));
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()`
+
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:33:25
+ |
+LL | let _vec4: Box<_> = Box::new(Vec::from([false; 0]));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::vec::Vec<bool>>::default()`
+
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:35:16
+ |
+LL | call_ty_fn(Box::new(u8::default()));
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()`
+
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:39:5
+ |
+LL | Box::new(bool::default())
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<bool>::default()`
+
+error: `Box::new(_)` of default value
+ --> $DIR/box_default.rs:56:28
+ |
+LL | let _: Box<dyn Read> = Box::new(ImplementsDefault::default());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<ImplementsDefault>::default()`
+
+error: aborting due to 14 previous errors
+
diff --git a/src/tools/clippy/tests/ui/box_default_no_std.rs b/src/tools/clippy/tests/ui/box_default_no_std.rs
new file mode 100644
index 000000000..4326abc9a
--- /dev/null
+++ b/src/tools/clippy/tests/ui/box_default_no_std.rs
@@ -0,0 +1,33 @@
+#![feature(lang_items, start, libc)]
+#![warn(clippy::box_default)]
+#![no_std]
+
+pub struct NotBox<T> {
+ _value: T,
+}
+
+impl<T> NotBox<T> {
+ pub fn new(value: T) -> Self {
+ Self { _value: value }
+ }
+}
+
+impl<T: Default> Default for NotBox<T> {
+ fn default() -> Self {
+ Self::new(T::default())
+ }
+}
+
+#[start]
+fn main(_argc: isize, _argv: *const *const u8) -> isize {
+ let _p = NotBox::new(isize::default());
+ 0
+}
+
+#[panic_handler]
+fn panic(_info: &core::panic::PanicInfo) -> ! {
+ loop {}
+}
+
+#[lang = "eh_personality"]
+extern "C" fn eh_personality() {}
diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.rs b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.rs
index 12f550d9c..6a63008b5 100644
--- a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.rs
+++ b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.rs
@@ -1,5 +1,6 @@
-#![allow(dead_code, clippy::equatable_if_let)]
#![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
+#![allow(dead_code)]
+#![allow(clippy::equatable_if_let, clippy::uninlined_format_args)]
// This tests the branches_sharing_code lint at the end of blocks
diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.stderr b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.stderr
index 5e1a68d21..b9b113dc0 100644
--- a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.stderr
+++ b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_bottom.stderr
@@ -1,5 +1,5 @@
error: all if blocks contain the same code at the end
- --> $DIR/shared_at_bottom.rs:30:5
+ --> $DIR/shared_at_bottom.rs:31:5
|
LL | / let result = false;
LL | | println!("Block end!");
@@ -7,12 +7,12 @@ LL | | result
LL | | };
| |_____^
|
+ = note: the end suggestion probably needs some adjustments to use the expression result correctly
note: the lint level is defined here
- --> $DIR/shared_at_bottom.rs:2:36
+ --> $DIR/shared_at_bottom.rs:1:36
|
LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: the end suggestion probably needs some adjustments to use the expression result correctly
help: consider moving these statements after the if
|
LL ~ }
@@ -22,7 +22,7 @@ LL ~ result;
|
error: all if blocks contain the same code at the end
- --> $DIR/shared_at_bottom.rs:48:5
+ --> $DIR/shared_at_bottom.rs:49:5
|
LL | / println!("Same end of block");
LL | | }
@@ -35,7 +35,7 @@ LL + println!("Same end of block");
|
error: all if blocks contain the same code at the end
- --> $DIR/shared_at_bottom.rs:65:5
+ --> $DIR/shared_at_bottom.rs:66:5
|
LL | / println!(
LL | | "I'm moveable because I know: `outer_scope_value`: '{}'",
@@ -54,7 +54,7 @@ LL + );
|
error: all if blocks contain the same code at the end
- --> $DIR/shared_at_bottom.rs:77:9
+ --> $DIR/shared_at_bottom.rs:78:9
|
LL | / println!("Hello World");
LL | | }
@@ -67,7 +67,7 @@ LL + println!("Hello World");
|
error: all if blocks contain the same code at the end
- --> $DIR/shared_at_bottom.rs:93:5
+ --> $DIR/shared_at_bottom.rs:94:5
|
LL | / let later_used_value = "A string value";
LL | | println!("{}", later_used_value);
@@ -84,7 +84,7 @@ LL + println!("{}", later_used_value);
|
error: all if blocks contain the same code at the end
- --> $DIR/shared_at_bottom.rs:106:5
+ --> $DIR/shared_at_bottom.rs:107:5
|
LL | / let simple_examples = "I now identify as a &str :)";
LL | | println!("This is the new simple_example: {}", simple_examples);
@@ -100,7 +100,7 @@ LL + println!("This is the new simple_example: {}", simple_examples);
|
error: all if blocks contain the same code at the end
- --> $DIR/shared_at_bottom.rs:171:5
+ --> $DIR/shared_at_bottom.rs:172:5
|
LL | / x << 2
LL | | };
@@ -114,7 +114,7 @@ LL ~ x << 2;
|
error: all if blocks contain the same code at the end
- --> $DIR/shared_at_bottom.rs:178:5
+ --> $DIR/shared_at_bottom.rs:179:5
|
LL | / x * 4
LL | | }
@@ -128,7 +128,7 @@ LL + x * 4
|
error: all if blocks contain the same code at the end
- --> $DIR/shared_at_bottom.rs:190:44
+ --> $DIR/shared_at_bottom.rs:191:44
|
LL | if x == 17 { b = 1; a = 0x99; } else { a = 0x99; }
| ^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.rs b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.rs
index bdeb0a395..9e0b99f16 100644
--- a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.rs
+++ b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.rs
@@ -1,5 +1,6 @@
-#![allow(dead_code, clippy::mixed_read_write_in_expression)]
-#![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
+#![deny(clippy::branches_sharing_code, clippy::if_same_then_else)]
+#![allow(dead_code)]
+#![allow(clippy::mixed_read_write_in_expression, clippy::uninlined_format_args)]
// This tests the branches_sharing_code lint at the start of blocks
diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.stderr b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.stderr
index d890b12ec..3e3242a75 100644
--- a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.stderr
+++ b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top.stderr
@@ -1,15 +1,15 @@
error: all if blocks contain the same code at the start
- --> $DIR/shared_at_top.rs:10:5
+ --> $DIR/shared_at_top.rs:11:5
|
LL | / if true {
LL | | println!("Hello World!");
| |_________________________________^
|
note: the lint level is defined here
- --> $DIR/shared_at_top.rs:2:36
+ --> $DIR/shared_at_top.rs:1:9
|
-LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider moving these statements before the if
|
LL ~ println!("Hello World!");
@@ -17,7 +17,7 @@ LL + if true {
|
error: all if blocks contain the same code at the start
- --> $DIR/shared_at_top.rs:19:5
+ --> $DIR/shared_at_top.rs:20:5
|
LL | / if x == 0 {
LL | | let y = 9;
@@ -35,7 +35,7 @@ LL + if x == 0 {
|
error: all if blocks contain the same code at the start
- --> $DIR/shared_at_top.rs:40:5
+ --> $DIR/shared_at_top.rs:41:5
|
LL | / let _ = if x == 7 {
LL | | let y = 16;
@@ -48,7 +48,7 @@ LL + let _ = if x == 7 {
|
error: all if blocks contain the same code at the start
- --> $DIR/shared_at_top.rs:58:5
+ --> $DIR/shared_at_top.rs:59:5
|
LL | / if x == 10 {
LL | | let used_value_name = "Different type";
@@ -64,7 +64,7 @@ LL + if x == 10 {
|
error: all if blocks contain the same code at the start
- --> $DIR/shared_at_top.rs:72:5
+ --> $DIR/shared_at_top.rs:73:5
|
LL | / if x == 11 {
LL | | let can_be_overridden = "Move me";
@@ -80,7 +80,7 @@ LL + if x == 11 {
|
error: all if blocks contain the same code at the start
- --> $DIR/shared_at_top.rs:88:5
+ --> $DIR/shared_at_top.rs:89:5
|
LL | / if x == 2020 {
LL | | println!("This should trigger the `SHARED_CODE_IN_IF_BLOCKS` lint.");
@@ -95,7 +95,7 @@ LL + if x == 2020 {
|
error: this `if` has identical blocks
- --> $DIR/shared_at_top.rs:96:18
+ --> $DIR/shared_at_top.rs:97:18
|
LL | if x == 2019 {
| __________________^
@@ -103,19 +103,19 @@ LL | | println!("This should trigger `IS_SAME_THAN_ELSE` as usual");
LL | | } else {
| |_____^
|
-note: the lint level is defined here
- --> $DIR/shared_at_top.rs:2:9
- |
-LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: same as this
- --> $DIR/shared_at_top.rs:98:12
+ --> $DIR/shared_at_top.rs:99:12
|
LL | } else {
| ____________^
LL | | println!("This should trigger `IS_SAME_THAN_ELSE` as usual");
LL | | }
| |_____^
+note: the lint level is defined here
+ --> $DIR/shared_at_top.rs:1:40
+ |
+LL | #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 7 previous errors
diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs
index deefdad32..93b8c6e10 100644
--- a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs
+++ b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs
@@ -1,5 +1,6 @@
+#![deny(clippy::branches_sharing_code, clippy::if_same_then_else)]
#![allow(dead_code)]
-#![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
+#![allow(clippy::uninlined_format_args)]
// branches_sharing_code at the top and bottom of the if blocks
diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr
index a270f637f..ccd697a42 100644
--- a/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr
+++ b/src/tools/clippy/tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr
@@ -1,5 +1,5 @@
error: all if blocks contain the same code at both the start and the end
- --> $DIR/shared_at_top_and_bottom.rs:16:5
+ --> $DIR/shared_at_top_and_bottom.rs:17:5
|
LL | / if x == 7 {
LL | | let t = 7;
@@ -7,17 +7,17 @@ LL | | let _overlap_start = t * 2;
LL | | let _overlap_end = 2 * t;
| |_________________________________^
|
-note: the lint level is defined here
- --> $DIR/shared_at_top_and_bottom.rs:2:36
- |
-LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: this code is shared at the end
- --> $DIR/shared_at_top_and_bottom.rs:28:5
+ --> $DIR/shared_at_top_and_bottom.rs:29:5
|
LL | / let _u = 9;
LL | | }
| |_____^
+note: the lint level is defined here
+ --> $DIR/shared_at_top_and_bottom.rs:1:9
+ |
+LL | #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider moving these statements before the if
|
LL ~ let t = 7;
@@ -32,7 +32,7 @@ LL + let _u = 9;
|
error: all if blocks contain the same code at both the start and the end
- --> $DIR/shared_at_top_and_bottom.rs:32:5
+ --> $DIR/shared_at_top_and_bottom.rs:33:5
|
LL | / if x == 99 {
LL | | let r = 7;
@@ -41,7 +41,7 @@ LL | | let _overlap_middle = r * r;
| |____________________________________^
|
note: this code is shared at the end
- --> $DIR/shared_at_top_and_bottom.rs:43:5
+ --> $DIR/shared_at_top_and_bottom.rs:44:5
|
LL | / let _overlap_end = r * r * r;
LL | | let z = "end";
@@ -63,7 +63,7 @@ LL + let z = "end";
|
error: all if blocks contain the same code at both the start and the end
- --> $DIR/shared_at_top_and_bottom.rs:61:5
+ --> $DIR/shared_at_top_and_bottom.rs:62:5
|
LL | / if (x > 7 && y < 13) || (x + y) % 2 == 1 {
LL | | let a = 0xcafe;
@@ -72,7 +72,7 @@ LL | | let e_id = gen_id(a, b);
| |________________________________^
|
note: this code is shared at the end
- --> $DIR/shared_at_top_and_bottom.rs:81:5
+ --> $DIR/shared_at_top_and_bottom.rs:82:5
|
LL | / let pack = DataPack {
LL | | id: e_id,
@@ -102,14 +102,14 @@ LL + process_data(pack);
|
error: all if blocks contain the same code at both the start and the end
- --> $DIR/shared_at_top_and_bottom.rs:94:5
+ --> $DIR/shared_at_top_and_bottom.rs:95:5
|
LL | / let _ = if x == 7 {
LL | | let _ = 19;
| |___________________^
|
note: this code is shared at the end
- --> $DIR/shared_at_top_and_bottom.rs:103:5
+ --> $DIR/shared_at_top_and_bottom.rs:104:5
|
LL | / x << 2
LL | | };
@@ -127,14 +127,14 @@ LL ~ x << 2;
|
error: all if blocks contain the same code at both the start and the end
- --> $DIR/shared_at_top_and_bottom.rs:106:5
+ --> $DIR/shared_at_top_and_bottom.rs:107:5
|
LL | / if x == 9 {
LL | | let _ = 17;
| |___________________^
|
note: this code is shared at the end
- --> $DIR/shared_at_top_and_bottom.rs:115:5
+ --> $DIR/shared_at_top_and_bottom.rs:116:5
|
LL | / x * 4
LL | | }
diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.rs b/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.rs
index a26141be2..2d6055eb6 100644
--- a/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.rs
+++ b/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.rs
@@ -1,5 +1,6 @@
-#![allow(dead_code, clippy::mixed_read_write_in_expression)]
-#![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
+#![deny(clippy::branches_sharing_code, clippy::if_same_then_else)]
+#![allow(dead_code)]
+#![allow(clippy::mixed_read_write_in_expression, clippy::uninlined_format_args)]
// This tests valid if blocks that shouldn't trigger the lint
diff --git a/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.stderr b/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.stderr
index a815995e7..ce7fff012 100644
--- a/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.stderr
+++ b/src/tools/clippy/tests/ui/branches_sharing_code/valid_if_blocks.stderr
@@ -1,26 +1,26 @@
error: this `if` has identical blocks
- --> $DIR/valid_if_blocks.rs:104:14
+ --> $DIR/valid_if_blocks.rs:105:14
|
LL | if false {
| ______________^
LL | | } else {
| |_____^
|
-note: the lint level is defined here
- --> $DIR/valid_if_blocks.rs:2:9
- |
-LL | #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
note: same as this
- --> $DIR/valid_if_blocks.rs:105:12
+ --> $DIR/valid_if_blocks.rs:106:12
|
LL | } else {
| ____________^
LL | | }
| |_____^
+note: the lint level is defined here
+ --> $DIR/valid_if_blocks.rs:1:40
+ |
+LL | #![deny(clippy::branches_sharing_code, clippy::if_same_then_else)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: this `if` has identical blocks
- --> $DIR/valid_if_blocks.rs:115:15
+ --> $DIR/valid_if_blocks.rs:116:15
|
LL | if x == 0 {
| _______________^
@@ -31,7 +31,7 @@ LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/valid_if_blocks.rs:119:12
+ --> $DIR/valid_if_blocks.rs:120:12
|
LL | } else {
| ____________^
@@ -42,19 +42,19 @@ LL | | }
| |_____^
error: this `if` has identical blocks
- --> $DIR/valid_if_blocks.rs:126:23
+ --> $DIR/valid_if_blocks.rs:127:23
|
LL | let _ = if x == 6 { 7 } else { 7 };
| ^^^^^
|
note: same as this
- --> $DIR/valid_if_blocks.rs:126:34
+ --> $DIR/valid_if_blocks.rs:127:34
|
LL | let _ = if x == 6 { 7 } else { 7 };
| ^^^^^
error: this `if` has identical blocks
- --> $DIR/valid_if_blocks.rs:132:23
+ --> $DIR/valid_if_blocks.rs:133:23
|
LL | } else if x == 68 {
| _______________________^
@@ -66,7 +66,7 @@ LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/valid_if_blocks.rs:137:12
+ --> $DIR/valid_if_blocks.rs:138:12
|
LL | } else {
| ____________^
@@ -78,7 +78,7 @@ LL | | };
| |_____^
error: this `if` has identical blocks
- --> $DIR/valid_if_blocks.rs:146:23
+ --> $DIR/valid_if_blocks.rs:147:23
|
LL | } else if x == 68 {
| _______________________^
@@ -88,7 +88,7 @@ LL | | } else {
| |_____^
|
note: same as this
- --> $DIR/valid_if_blocks.rs:149:12
+ --> $DIR/valid_if_blocks.rs:150:12
|
LL | } else {
| ____________^
diff --git a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr
index 5d9a043ed..a28dd8bd5 100644
--- a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr
+++ b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.stderr
@@ -4,8 +4,8 @@ error: case-sensitive file extension comparison
LL | filename.ends_with(".rs")
| ^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::case-sensitive-file-extension-comparisons` implied by `-D warnings`
= help: consider using a case-insensitive comparison instead
+ = note: `-D clippy::case-sensitive-file-extension-comparisons` implied by `-D warnings`
error: case-sensitive file extension comparison
--> $DIR/case_sensitive_file_extension_comparisons.rs:17:27
diff --git a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed
index 7ecefd7b1..e6bf944c7 100644
--- a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed
+++ b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.fixed
@@ -1,5 +1,8 @@
// run-rustfix
+
+#![feature(custom_inner_attributes)]
#![warn(clippy::cast_abs_to_unsigned)]
+#![allow(clippy::uninlined_format_args, unused)]
fn main() {
let x: i32 = -42;
@@ -29,3 +32,17 @@ fn main() {
let _ = (x as i64 - y as i64).unsigned_abs() as u32;
}
+
+fn msrv_1_50() {
+ #![clippy::msrv = "1.50"]
+
+ let x: i32 = 10;
+ assert_eq!(10u32, x.abs() as u32);
+}
+
+fn msrv_1_51() {
+ #![clippy::msrv = "1.51"]
+
+ let x: i32 = 10;
+ assert_eq!(10u32, x.unsigned_abs());
+}
diff --git a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs
index 30c603fca..c87320b52 100644
--- a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs
+++ b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.rs
@@ -1,5 +1,8 @@
// run-rustfix
+
+#![feature(custom_inner_attributes)]
#![warn(clippy::cast_abs_to_unsigned)]
+#![allow(clippy::uninlined_format_args, unused)]
fn main() {
let x: i32 = -42;
@@ -29,3 +32,17 @@ fn main() {
let _ = (x as i64 - y as i64).abs() as u32;
}
+
+fn msrv_1_50() {
+ #![clippy::msrv = "1.50"]
+
+ let x: i32 = 10;
+ assert_eq!(10u32, x.abs() as u32);
+}
+
+fn msrv_1_51() {
+ #![clippy::msrv = "1.51"]
+
+ let x: i32 = 10;
+ assert_eq!(10u32, x.abs() as u32);
+}
diff --git a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr
index 045537745..1b39c554b 100644
--- a/src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr
+++ b/src/tools/clippy/tests/ui/cast_abs_to_unsigned.stderr
@@ -1,5 +1,5 @@
error: casting the result of `i32::abs()` to u32
- --> $DIR/cast_abs_to_unsigned.rs:6:18
+ --> $DIR/cast_abs_to_unsigned.rs:9:18
|
LL | let y: u32 = x.abs() as u32;
| ^^^^^^^^^^^^^^ help: replace with: `x.unsigned_abs()`
@@ -7,100 +7,106 @@ LL | let y: u32 = x.abs() as u32;
= note: `-D clippy::cast-abs-to-unsigned` implied by `-D warnings`
error: casting the result of `i32::abs()` to usize
- --> $DIR/cast_abs_to_unsigned.rs:10:20
+ --> $DIR/cast_abs_to_unsigned.rs:13:20
|
LL | let _: usize = a.abs() as usize;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i32::abs()` to usize
- --> $DIR/cast_abs_to_unsigned.rs:11:20
+ --> $DIR/cast_abs_to_unsigned.rs:14:20
|
LL | let _: usize = a.abs() as _;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i32::abs()` to usize
- --> $DIR/cast_abs_to_unsigned.rs:12:13
+ --> $DIR/cast_abs_to_unsigned.rs:15:13
|
LL | let _ = a.abs() as usize;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to usize
- --> $DIR/cast_abs_to_unsigned.rs:15:13
+ --> $DIR/cast_abs_to_unsigned.rs:18:13
|
LL | let _ = a.abs() as usize;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to u8
- --> $DIR/cast_abs_to_unsigned.rs:16:13
+ --> $DIR/cast_abs_to_unsigned.rs:19:13
|
LL | let _ = a.abs() as u8;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to u16
- --> $DIR/cast_abs_to_unsigned.rs:17:13
+ --> $DIR/cast_abs_to_unsigned.rs:20:13
|
LL | let _ = a.abs() as u16;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to u32
- --> $DIR/cast_abs_to_unsigned.rs:18:13
+ --> $DIR/cast_abs_to_unsigned.rs:21:13
|
LL | let _ = a.abs() as u32;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to u64
- --> $DIR/cast_abs_to_unsigned.rs:19:13
+ --> $DIR/cast_abs_to_unsigned.rs:22:13
|
LL | let _ = a.abs() as u64;
| ^^^^^^^^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to u128
- --> $DIR/cast_abs_to_unsigned.rs:20:13
+ --> $DIR/cast_abs_to_unsigned.rs:23:13
|
LL | let _ = a.abs() as u128;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `isize::abs()` to usize
- --> $DIR/cast_abs_to_unsigned.rs:23:13
+ --> $DIR/cast_abs_to_unsigned.rs:26:13
|
LL | let _ = a.abs() as usize;
| ^^^^^^^^^^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `isize::abs()` to u8
- --> $DIR/cast_abs_to_unsigned.rs:24:13
+ --> $DIR/cast_abs_to_unsigned.rs:27:13
|
LL | let _ = a.abs() as u8;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `isize::abs()` to u16
- --> $DIR/cast_abs_to_unsigned.rs:25:13
+ --> $DIR/cast_abs_to_unsigned.rs:28:13
|
LL | let _ = a.abs() as u16;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `isize::abs()` to u32
- --> $DIR/cast_abs_to_unsigned.rs:26:13
+ --> $DIR/cast_abs_to_unsigned.rs:29:13
|
LL | let _ = a.abs() as u32;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `isize::abs()` to u64
- --> $DIR/cast_abs_to_unsigned.rs:27:13
+ --> $DIR/cast_abs_to_unsigned.rs:30:13
|
LL | let _ = a.abs() as u64;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `isize::abs()` to u128
- --> $DIR/cast_abs_to_unsigned.rs:28:13
+ --> $DIR/cast_abs_to_unsigned.rs:31:13
|
LL | let _ = a.abs() as u128;
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
error: casting the result of `i64::abs()` to u32
- --> $DIR/cast_abs_to_unsigned.rs:30:13
+ --> $DIR/cast_abs_to_unsigned.rs:33:13
|
LL | let _ = (x as i64 - y as i64).abs() as u32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `(x as i64 - y as i64).unsigned_abs()`
-error: aborting due to 17 previous errors
+error: casting the result of `i32::abs()` to u32
+ --> $DIR/cast_abs_to_unsigned.rs:47:23
+ |
+LL | assert_eq!(10u32, x.abs() as u32);
+ | ^^^^^^^^^^^^^^ help: replace with: `x.unsigned_abs()`
+
+error: aborting due to 18 previous errors
diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.fixed b/src/tools/clippy/tests/ui/cast_lossless_bool.fixed
index 9e2da45c3..af13b755e 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_bool.fixed
+++ b/src/tools/clippy/tests/ui/cast_lossless_bool.fixed
@@ -1,5 +1,6 @@
// run-rustfix
+#![feature(custom_inner_attributes)]
#![allow(dead_code)]
#![warn(clippy::cast_lossless)]
@@ -40,3 +41,15 @@ mod cast_lossless_in_impl {
}
}
}
+
+fn msrv_1_27() {
+ #![clippy::msrv = "1.27"]
+
+ let _ = true as u8;
+}
+
+fn msrv_1_28() {
+ #![clippy::msrv = "1.28"]
+
+ let _ = u8::from(true);
+}
diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.rs b/src/tools/clippy/tests/ui/cast_lossless_bool.rs
index b6f6c59a0..3b06af899 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_bool.rs
+++ b/src/tools/clippy/tests/ui/cast_lossless_bool.rs
@@ -1,5 +1,6 @@
// run-rustfix
+#![feature(custom_inner_attributes)]
#![allow(dead_code)]
#![warn(clippy::cast_lossless)]
@@ -40,3 +41,15 @@ mod cast_lossless_in_impl {
}
}
}
+
+fn msrv_1_27() {
+ #![clippy::msrv = "1.27"]
+
+ let _ = true as u8;
+}
+
+fn msrv_1_28() {
+ #![clippy::msrv = "1.28"]
+
+ let _ = true as u8;
+}
diff --git a/src/tools/clippy/tests/ui/cast_lossless_bool.stderr b/src/tools/clippy/tests/ui/cast_lossless_bool.stderr
index 6b1483360..768b033d1 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_bool.stderr
+++ b/src/tools/clippy/tests/ui/cast_lossless_bool.stderr
@@ -1,5 +1,5 @@
error: casting `bool` to `u8` is more cleanly stated with `u8::from(_)`
- --> $DIR/cast_lossless_bool.rs:8:13
+ --> $DIR/cast_lossless_bool.rs:9:13
|
LL | let _ = true as u8;
| ^^^^^^^^^^ help: try: `u8::from(true)`
@@ -7,76 +7,82 @@ LL | let _ = true as u8;
= note: `-D clippy::cast-lossless` implied by `-D warnings`
error: casting `bool` to `u16` is more cleanly stated with `u16::from(_)`
- --> $DIR/cast_lossless_bool.rs:9:13
+ --> $DIR/cast_lossless_bool.rs:10:13
|
LL | let _ = true as u16;
| ^^^^^^^^^^^ help: try: `u16::from(true)`
error: casting `bool` to `u32` is more cleanly stated with `u32::from(_)`
- --> $DIR/cast_lossless_bool.rs:10:13
+ --> $DIR/cast_lossless_bool.rs:11:13
|
LL | let _ = true as u32;
| ^^^^^^^^^^^ help: try: `u32::from(true)`
error: casting `bool` to `u64` is more cleanly stated with `u64::from(_)`
- --> $DIR/cast_lossless_bool.rs:11:13
+ --> $DIR/cast_lossless_bool.rs:12:13
|
LL | let _ = true as u64;
| ^^^^^^^^^^^ help: try: `u64::from(true)`
error: casting `bool` to `u128` is more cleanly stated with `u128::from(_)`
- --> $DIR/cast_lossless_bool.rs:12:13
+ --> $DIR/cast_lossless_bool.rs:13:13
|
LL | let _ = true as u128;
| ^^^^^^^^^^^^ help: try: `u128::from(true)`
error: casting `bool` to `usize` is more cleanly stated with `usize::from(_)`
- --> $DIR/cast_lossless_bool.rs:13:13
+ --> $DIR/cast_lossless_bool.rs:14:13
|
LL | let _ = true as usize;
| ^^^^^^^^^^^^^ help: try: `usize::from(true)`
error: casting `bool` to `i8` is more cleanly stated with `i8::from(_)`
- --> $DIR/cast_lossless_bool.rs:15:13
+ --> $DIR/cast_lossless_bool.rs:16:13
|
LL | let _ = true as i8;
| ^^^^^^^^^^ help: try: `i8::from(true)`
error: casting `bool` to `i16` is more cleanly stated with `i16::from(_)`
- --> $DIR/cast_lossless_bool.rs:16:13
+ --> $DIR/cast_lossless_bool.rs:17:13
|
LL | let _ = true as i16;
| ^^^^^^^^^^^ help: try: `i16::from(true)`
error: casting `bool` to `i32` is more cleanly stated with `i32::from(_)`
- --> $DIR/cast_lossless_bool.rs:17:13
+ --> $DIR/cast_lossless_bool.rs:18:13
|
LL | let _ = true as i32;
| ^^^^^^^^^^^ help: try: `i32::from(true)`
error: casting `bool` to `i64` is more cleanly stated with `i64::from(_)`
- --> $DIR/cast_lossless_bool.rs:18:13
+ --> $DIR/cast_lossless_bool.rs:19:13
|
LL | let _ = true as i64;
| ^^^^^^^^^^^ help: try: `i64::from(true)`
error: casting `bool` to `i128` is more cleanly stated with `i128::from(_)`
- --> $DIR/cast_lossless_bool.rs:19:13
+ --> $DIR/cast_lossless_bool.rs:20:13
|
LL | let _ = true as i128;
| ^^^^^^^^^^^^ help: try: `i128::from(true)`
error: casting `bool` to `isize` is more cleanly stated with `isize::from(_)`
- --> $DIR/cast_lossless_bool.rs:20:13
+ --> $DIR/cast_lossless_bool.rs:21:13
|
LL | let _ = true as isize;
| ^^^^^^^^^^^^^ help: try: `isize::from(true)`
error: casting `bool` to `u16` is more cleanly stated with `u16::from(_)`
- --> $DIR/cast_lossless_bool.rs:23:13
+ --> $DIR/cast_lossless_bool.rs:24:13
|
LL | let _ = (true | false) as u16;
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::from(true | false)`
-error: aborting due to 13 previous errors
+error: casting `bool` to `u8` is more cleanly stated with `u8::from(_)`
+ --> $DIR/cast_lossless_bool.rs:54:13
+ |
+LL | let _ = true as u8;
+ | ^^^^^^^^^^ help: try: `u8::from(true)`
+
+error: aborting due to 14 previous errors
diff --git a/src/tools/clippy/tests/ui/cast_nan_to_int.rs b/src/tools/clippy/tests/ui/cast_nan_to_int.rs
new file mode 100644
index 000000000..287c5aa21
--- /dev/null
+++ b/src/tools/clippy/tests/ui/cast_nan_to_int.rs
@@ -0,0 +1,18 @@
+#![warn(clippy::cast_nan_to_int)]
+#![allow(clippy::eq_op)]
+
+fn main() {
+ let _ = (0.0_f32 / -0.0) as usize;
+ let _ = (f64::INFINITY * -0.0) as usize;
+ let _ = (0.0 * f32::INFINITY) as usize;
+
+ let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize;
+ let _ = (f32::INFINITY - f32::INFINITY) as usize;
+ let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize;
+
+ // those won't be linted:
+ let _ = (1.0_f32 / 0.0) as usize;
+ let _ = (f32::INFINITY * f32::NEG_INFINITY) as usize;
+ let _ = (f32::INFINITY - f32::NEG_INFINITY) as usize;
+ let _ = (f64::INFINITY - 0.0) as usize;
+}
diff --git a/src/tools/clippy/tests/ui/cast_nan_to_int.stderr b/src/tools/clippy/tests/ui/cast_nan_to_int.stderr
new file mode 100644
index 000000000..3539be75a
--- /dev/null
+++ b/src/tools/clippy/tests/ui/cast_nan_to_int.stderr
@@ -0,0 +1,51 @@
+error: casting a known NaN to usize
+ --> $DIR/cast_nan_to_int.rs:5:13
+ |
+LL | let _ = (0.0_f32 / -0.0) as usize;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: this always evaluates to 0
+ = note: `-D clippy::cast-nan-to-int` implied by `-D warnings`
+
+error: casting a known NaN to usize
+ --> $DIR/cast_nan_to_int.rs:6:13
+ |
+LL | let _ = (f64::INFINITY * -0.0) as usize;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: this always evaluates to 0
+
+error: casting a known NaN to usize
+ --> $DIR/cast_nan_to_int.rs:7:13
+ |
+LL | let _ = (0.0 * f32::INFINITY) as usize;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: this always evaluates to 0
+
+error: casting a known NaN to usize
+ --> $DIR/cast_nan_to_int.rs:9:13
+ |
+LL | let _ = (f64::INFINITY + f64::NEG_INFINITY) as usize;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: this always evaluates to 0
+
+error: casting a known NaN to usize
+ --> $DIR/cast_nan_to_int.rs:10:13
+ |
+LL | let _ = (f32::INFINITY - f32::INFINITY) as usize;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: this always evaluates to 0
+
+error: casting a known NaN to usize
+ --> $DIR/cast_nan_to_int.rs:11:13
+ |
+LL | let _ = (f32::INFINITY / f32::NEG_INFINITY) as usize;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: this always evaluates to 0
+
+error: aborting due to 6 previous errors
+
diff --git a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed
index 061a4ab9b..8a5645b22 100644
--- a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed
+++ b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.fixed
@@ -1,5 +1,5 @@
// run-rustfix
-#![feature(stmt_expr_attributes)]
+#![feature(stmt_expr_attributes, custom_inner_attributes)]
#![allow(unused, clippy::no_effect, clippy::unnecessary_operation)]
#![warn(clippy::deprecated_cfg_attr)]
@@ -29,3 +29,17 @@ mod foo {
pub fn f() {}
}
+
+fn msrv_1_29() {
+ #![clippy::msrv = "1.29"]
+
+ #[cfg_attr(rustfmt, rustfmt::skip)]
+ 1+29;
+}
+
+fn msrv_1_30() {
+ #![clippy::msrv = "1.30"]
+
+ #[rustfmt::skip]
+ 1+30;
+}
diff --git a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs
index 035169fab..2fb140efa 100644
--- a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs
+++ b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.rs
@@ -1,5 +1,5 @@
// run-rustfix
-#![feature(stmt_expr_attributes)]
+#![feature(stmt_expr_attributes, custom_inner_attributes)]
#![allow(unused, clippy::no_effect, clippy::unnecessary_operation)]
#![warn(clippy::deprecated_cfg_attr)]
@@ -29,3 +29,17 @@ mod foo {
pub fn f() {}
}
+
+fn msrv_1_29() {
+ #![clippy::msrv = "1.29"]
+
+ #[cfg_attr(rustfmt, rustfmt::skip)]
+ 1+29;
+}
+
+fn msrv_1_30() {
+ #![clippy::msrv = "1.30"]
+
+ #[cfg_attr(rustfmt, rustfmt::skip)]
+ 1+30;
+}
diff --git a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr
index c1efd47db..08df7b2b3 100644
--- a/src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr
+++ b/src/tools/clippy/tests/ui/cfg_attr_rustfmt.stderr
@@ -12,5 +12,11 @@ error: `cfg_attr` is deprecated for rustfmt and got replaced by tool attributes
LL | #[cfg_attr(rustfmt, rustfmt_skip)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]`
-error: aborting due to 2 previous errors
+error: `cfg_attr` is deprecated for rustfmt and got replaced by tool attributes
+ --> $DIR/cfg_attr_rustfmt.rs:43:5
+ |
+LL | #[cfg_attr(rustfmt, rustfmt::skip)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `#[rustfmt::skip]`
+
+error: aborting due to 3 previous errors
diff --git a/src/tools/clippy/tests/ui/char_lit_as_u8.stderr b/src/tools/clippy/tests/ui/char_lit_as_u8.stderr
index b9836d2f2..39fc9d6dd 100644
--- a/src/tools/clippy/tests/ui/char_lit_as_u8.stderr
+++ b/src/tools/clippy/tests/ui/char_lit_as_u8.stderr
@@ -4,8 +4,8 @@ error: casting a character literal to `u8` truncates
LL | let _ = 'â¤' as u8; // no suggestion, since a byte literal won't work.
| ^^^^^^^^^
|
- = note: `-D clippy::char-lit-as-u8` implied by `-D warnings`
= note: `char` is four bytes wide, but `u8` is a single byte
+ = note: `-D clippy::char-lit-as-u8` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.stderr b/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.stderr
index bf7cb1607..586174c50 100644
--- a/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.stderr
+++ b/src/tools/clippy/tests/ui/char_lit_as_u8_suggestions.stderr
@@ -4,8 +4,8 @@ error: casting a character literal to `u8` truncates
LL | let _ = 'a' as u8;
| ^^^^^^^^^ help: use a byte literal instead: `b'a'`
|
- = note: `-D clippy::char-lit-as-u8` implied by `-D warnings`
= note: `char` is four bytes wide, but `u8` is a single byte
+ = note: `-D clippy::char-lit-as-u8` implied by `-D warnings`
error: casting a character literal to `u8` truncates
--> $DIR/char_lit_as_u8_suggestions.rs:7:13
diff --git a/src/tools/clippy/tests/ui/checked_conversions.fixed b/src/tools/clippy/tests/ui/checked_conversions.fixed
index cb7100bc9..f936957cb 100644
--- a/src/tools/clippy/tests/ui/checked_conversions.fixed
+++ b/src/tools/clippy/tests/ui/checked_conversions.fixed
@@ -1,7 +1,9 @@
// run-rustfix
+#![feature(custom_inner_attributes)]
#![allow(
clippy::cast_lossless,
+ unused,
// Int::max_value will be deprecated in the future
deprecated,
)]
@@ -76,4 +78,18 @@ pub const fn issue_8898(i: u32) -> bool {
i <= i32::MAX as u32
}
+fn msrv_1_33() {
+ #![clippy::msrv = "1.33"]
+
+ let value: i64 = 33;
+ let _ = value <= (u32::MAX as i64) && value >= 0;
+}
+
+fn msrv_1_34() {
+ #![clippy::msrv = "1.34"]
+
+ let value: i64 = 34;
+ let _ = u32::try_from(value).is_ok();
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/checked_conversions.rs b/src/tools/clippy/tests/ui/checked_conversions.rs
index ed4e06923..77aec713f 100644
--- a/src/tools/clippy/tests/ui/checked_conversions.rs
+++ b/src/tools/clippy/tests/ui/checked_conversions.rs
@@ -1,7 +1,9 @@
// run-rustfix
+#![feature(custom_inner_attributes)]
#![allow(
clippy::cast_lossless,
+ unused,
// Int::max_value will be deprecated in the future
deprecated,
)]
@@ -76,4 +78,18 @@ pub const fn issue_8898(i: u32) -> bool {
i <= i32::MAX as u32
}
+fn msrv_1_33() {
+ #![clippy::msrv = "1.33"]
+
+ let value: i64 = 33;
+ let _ = value <= (u32::MAX as i64) && value >= 0;
+}
+
+fn msrv_1_34() {
+ #![clippy::msrv = "1.34"]
+
+ let value: i64 = 34;
+ let _ = value <= (u32::MAX as i64) && value >= 0;
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/checked_conversions.stderr b/src/tools/clippy/tests/ui/checked_conversions.stderr
index 2e5180405..b2bf7af8d 100644
--- a/src/tools/clippy/tests/ui/checked_conversions.stderr
+++ b/src/tools/clippy/tests/ui/checked_conversions.stderr
@@ -1,5 +1,5 @@
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:15:13
+ --> $DIR/checked_conversions.rs:17:13
|
LL | let _ = value <= (u32::max_value() as i64) && value >= 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()`
@@ -7,94 +7,100 @@ LL | let _ = value <= (u32::max_value() as i64) && value >= 0;
= note: `-D clippy::checked-conversions` implied by `-D warnings`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:16:13
+ --> $DIR/checked_conversions.rs:18:13
|
LL | let _ = value <= (u32::MAX as i64) && value >= 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:20:13
+ --> $DIR/checked_conversions.rs:22:13
|
LL | let _ = value <= i64::from(u16::max_value()) && value >= 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:21:13
+ --> $DIR/checked_conversions.rs:23:13
|
LL | let _ = value <= i64::from(u16::MAX) && value >= 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:25:13
+ --> $DIR/checked_conversions.rs:27:13
|
LL | let _ = value <= (u8::max_value() as isize) && value >= 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u8::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:26:13
+ --> $DIR/checked_conversions.rs:28:13
|
LL | let _ = value <= (u8::MAX as isize) && value >= 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u8::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:32:13
+ --> $DIR/checked_conversions.rs:34:13
|
LL | let _ = value <= (i32::max_value() as i64) && value >= (i32::min_value() as i64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:33:13
+ --> $DIR/checked_conversions.rs:35:13
|
LL | let _ = value <= (i32::MAX as i64) && value >= (i32::MIN as i64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:37:13
+ --> $DIR/checked_conversions.rs:39:13
|
LL | let _ = value <= i64::from(i16::max_value()) && value >= i64::from(i16::min_value());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i16::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:38:13
+ --> $DIR/checked_conversions.rs:40:13
|
LL | let _ = value <= i64::from(i16::MAX) && value >= i64::from(i16::MIN);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i16::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:44:13
+ --> $DIR/checked_conversions.rs:46:13
|
LL | let _ = value <= i32::max_value() as u32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:45:13
+ --> $DIR/checked_conversions.rs:47:13
|
LL | let _ = value <= i32::MAX as u32;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:49:13
+ --> $DIR/checked_conversions.rs:51:13
|
LL | let _ = value <= isize::max_value() as usize && value as i32 == 5;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `isize::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:50:13
+ --> $DIR/checked_conversions.rs:52:13
|
LL | let _ = value <= isize::MAX as usize && value as i32 == 5;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `isize::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:54:13
+ --> $DIR/checked_conversions.rs:56:13
|
LL | let _ = value <= u16::max_value() as u32 && value as i32 == 5;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()`
error: checked cast can be simplified
- --> $DIR/checked_conversions.rs:55:13
+ --> $DIR/checked_conversions.rs:57:13
|
LL | let _ = value <= u16::MAX as u32 && value as i32 == 5;
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::try_from(value).is_ok()`
-error: aborting due to 16 previous errors
+error: checked cast can be simplified
+ --> $DIR/checked_conversions.rs:92:13
+ |
+LL | let _ = value <= (u32::MAX as i64) && value >= 0;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `u32::try_from(value).is_ok()`
+
+error: aborting due to 17 previous errors
diff --git a/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.stderr b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.stderr
index 46c6f6970..d44d5072e 100644
--- a/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.stderr
+++ b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.stderr
@@ -6,12 +6,12 @@ LL | if x.is_ok() && y.is_err() {
LL | x.unwrap(); // unnecessary
| ^^^^^^^^^^
|
+ = help: try using `if let` or `match`
note: the lint level is defined here
--> $DIR/complex_conditionals.rs:1:35
|
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: try using `if let` or `match`
error: this call to `unwrap_err()` will always panic
--> $DIR/complex_conditionals.rs:9:9
diff --git a/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed b/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed
index 4eb999e18..42ed232d1 100644
--- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed
+++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.fixed
@@ -1,5 +1,8 @@
// run-rustfix
+
+#![feature(custom_inner_attributes)]
#![warn(clippy::cloned_instead_of_copied)]
+#![allow(unused)]
fn main() {
// yay
@@ -13,3 +16,24 @@ fn main() {
let _ = [String::new()].iter().cloned();
let _ = Some(&String::new()).cloned();
}
+
+fn msrv_1_34() {
+ #![clippy::msrv = "1.34"]
+
+ let _ = [1].iter().cloned();
+ let _ = Some(&1).cloned();
+}
+
+fn msrv_1_35() {
+ #![clippy::msrv = "1.35"]
+
+ let _ = [1].iter().cloned();
+ let _ = Some(&1).copied(); // Option::copied needs 1.35
+}
+
+fn msrv_1_36() {
+ #![clippy::msrv = "1.36"]
+
+ let _ = [1].iter().copied(); // Iterator::copied needs 1.36
+ let _ = Some(&1).copied();
+}
diff --git a/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs b/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs
index 894496c0e..471bd9654 100644
--- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs
+++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.rs
@@ -1,5 +1,8 @@
// run-rustfix
+
+#![feature(custom_inner_attributes)]
#![warn(clippy::cloned_instead_of_copied)]
+#![allow(unused)]
fn main() {
// yay
@@ -13,3 +16,24 @@ fn main() {
let _ = [String::new()].iter().cloned();
let _ = Some(&String::new()).cloned();
}
+
+fn msrv_1_34() {
+ #![clippy::msrv = "1.34"]
+
+ let _ = [1].iter().cloned();
+ let _ = Some(&1).cloned();
+}
+
+fn msrv_1_35() {
+ #![clippy::msrv = "1.35"]
+
+ let _ = [1].iter().cloned();
+ let _ = Some(&1).cloned(); // Option::copied needs 1.35
+}
+
+fn msrv_1_36() {
+ #![clippy::msrv = "1.36"]
+
+ let _ = [1].iter().cloned(); // Iterator::copied needs 1.36
+ let _ = Some(&1).cloned();
+}
diff --git a/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr b/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr
index e0707d321..914c9a91e 100644
--- a/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr
+++ b/src/tools/clippy/tests/ui/cloned_instead_of_copied.stderr
@@ -1,5 +1,5 @@
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:6:24
+ --> $DIR/cloned_instead_of_copied.rs:9:24
|
LL | let _ = [1].iter().cloned();
| ^^^^^^ help: try: `copied`
@@ -7,28 +7,46 @@ LL | let _ = [1].iter().cloned();
= note: `-D clippy::cloned-instead-of-copied` implied by `-D warnings`
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:7:31
+ --> $DIR/cloned_instead_of_copied.rs:10:31
|
LL | let _ = vec!["hi"].iter().cloned();
| ^^^^^^ help: try: `copied`
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:8:22
+ --> $DIR/cloned_instead_of_copied.rs:11:22
|
LL | let _ = Some(&1).cloned();
| ^^^^^^ help: try: `copied`
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:9:34
+ --> $DIR/cloned_instead_of_copied.rs:12:34
|
LL | let _ = Box::new([1].iter()).cloned();
| ^^^^^^ help: try: `copied`
error: used `cloned` where `copied` could be used instead
- --> $DIR/cloned_instead_of_copied.rs:10:32
+ --> $DIR/cloned_instead_of_copied.rs:13:32
|
LL | let _ = Box::new(Some(&1)).cloned();
| ^^^^^^ help: try: `copied`
-error: aborting due to 5 previous errors
+error: used `cloned` where `copied` could be used instead
+ --> $DIR/cloned_instead_of_copied.rs:31:22
+ |
+LL | let _ = Some(&1).cloned(); // Option::copied needs 1.35
+ | ^^^^^^ help: try: `copied`
+
+error: used `cloned` where `copied` could be used instead
+ --> $DIR/cloned_instead_of_copied.rs:37:24
+ |
+LL | let _ = [1].iter().cloned(); // Iterator::copied needs 1.36
+ | ^^^^^^ help: try: `copied`
+
+error: used `cloned` where `copied` could be used instead
+ --> $DIR/cloned_instead_of_copied.rs:38:22
+ |
+LL | let _ = Some(&1).cloned();
+ | ^^^^^^ help: try: `copied`
+
+error: aborting due to 8 previous errors
diff --git a/src/tools/clippy/tests/ui/cognitive_complexity.stderr b/src/tools/clippy/tests/ui/cognitive_complexity.stderr
index a0ddc673a..d7f2f24e5 100644
--- a/src/tools/clippy/tests/ui/cognitive_complexity.stderr
+++ b/src/tools/clippy/tests/ui/cognitive_complexity.stderr
@@ -4,8 +4,8 @@ error: the function has a cognitive complexity of (28/25)
LL | fn main() {
| ^^^^
|
- = note: `-D clippy::cognitive-complexity` implied by `-D warnings`
= help: you could split it up into multiple smaller functions
+ = note: `-D clippy::cognitive-complexity` implied by `-D warnings`
error: the function has a cognitive complexity of (7/1)
--> $DIR/cognitive_complexity.rs:91:4
diff --git a/src/tools/clippy/tests/ui/cognitive_complexity_attr_used.stderr b/src/tools/clippy/tests/ui/cognitive_complexity_attr_used.stderr
index f5ff53dda..bb48f3297 100644
--- a/src/tools/clippy/tests/ui/cognitive_complexity_attr_used.stderr
+++ b/src/tools/clippy/tests/ui/cognitive_complexity_attr_used.stderr
@@ -4,8 +4,8 @@ error: the function has a cognitive complexity of (3/0)
LL | fn kaboom() {
| ^^^^^^
|
- = note: `-D clippy::cognitive-complexity` implied by `-D warnings`
= help: you could split it up into multiple smaller functions
+ = note: `-D clippy::cognitive-complexity` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/collapsible_if.fixed b/src/tools/clippy/tests/ui/collapsible_if.fixed
index 5b0e4a473..6bb7682ba 100644
--- a/src/tools/clippy/tests/ui/collapsible_if.fixed
+++ b/src/tools/clippy/tests/ui/collapsible_if.fixed
@@ -139,6 +139,9 @@ fn main() {
// Fix #5962
if matches!(true, true) && matches!(true, true) {}
+ // Issue #9375
+ if matches!(true, true) && truth() && matches!(true, true) {}
+
if true {
#[cfg(not(teehee))]
if true {
diff --git a/src/tools/clippy/tests/ui/collapsible_if.rs b/src/tools/clippy/tests/ui/collapsible_if.rs
index cd231a5d7..e216a9ee5 100644
--- a/src/tools/clippy/tests/ui/collapsible_if.rs
+++ b/src/tools/clippy/tests/ui/collapsible_if.rs
@@ -155,6 +155,11 @@ fn main() {
if matches!(true, true) {}
}
+ // Issue #9375
+ if matches!(true, true) && truth() {
+ if matches!(true, true) {}
+ }
+
if true {
#[cfg(not(teehee))]
if true {
diff --git a/src/tools/clippy/tests/ui/collapsible_if.stderr b/src/tools/clippy/tests/ui/collapsible_if.stderr
index 674961238..6327444df 100644
--- a/src/tools/clippy/tests/ui/collapsible_if.stderr
+++ b/src/tools/clippy/tests/ui/collapsible_if.stderr
@@ -126,5 +126,13 @@ LL | | if matches!(true, true) {}
LL | | }
| |_____^ help: collapse nested if block: `if matches!(true, true) && matches!(true, true) {}`
-error: aborting due to 8 previous errors
+error: this `if` statement can be collapsed
+ --> $DIR/collapsible_if.rs:159:5
+ |
+LL | / if matches!(true, true) && truth() {
+LL | | if matches!(true, true) {}
+LL | | }
+ | |_____^ help: collapse nested if block: `if matches!(true, true) && truth() && matches!(true, true) {}`
+
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/collapsible_match.rs b/src/tools/clippy/tests/ui/collapsible_match.rs
index 603ae7dc9..1d7a72846 100644
--- a/src/tools/clippy/tests/ui/collapsible_match.rs
+++ b/src/tools/clippy/tests/ui/collapsible_match.rs
@@ -1,9 +1,10 @@
#![warn(clippy::collapsible_match)]
#![allow(
+ clippy::equatable_if_let,
clippy::needless_return,
clippy::no_effect,
clippy::single_match,
- clippy::equatable_if_let
+ clippy::uninlined_format_args
)]
fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>) {
@@ -252,6 +253,27 @@ fn negative_cases(res_opt: Result<Option<u32>, String>, res_res: Result<Result<u
};
}
+pub enum Issue9647 {
+ A { a: Option<Option<u8>>, b: () },
+ B,
+}
+
+pub fn test_1(x: Issue9647) {
+ if let Issue9647::A { a, .. } = x {
+ if let Some(u) = a {
+ println!("{u:?}")
+ }
+ }
+}
+
+pub fn test_2(x: Issue9647) {
+ if let Issue9647::A { a: Some(a), .. } = x {
+ if let Some(u) = a {
+ println!("{u}")
+ }
+ }
+}
+
fn make<T>() -> T {
unimplemented!()
}
diff --git a/src/tools/clippy/tests/ui/collapsible_match.stderr b/src/tools/clippy/tests/ui/collapsible_match.stderr
index 5f18b6935..0294be60b 100644
--- a/src/tools/clippy/tests/ui/collapsible_match.stderr
+++ b/src/tools/clippy/tests/ui/collapsible_match.stderr
@@ -1,5 +1,5 @@
error: this `match` can be collapsed into the outer `match`
- --> $DIR/collapsible_match.rs:12:20
+ --> $DIR/collapsible_match.rs:13:20
|
LL | Ok(val) => match val {
| ____________________^
@@ -8,17 +8,17 @@ LL | | _ => return,
LL | | },
| |_________^
|
- = note: `-D clippy::collapsible-match` implied by `-D warnings`
help: the outer pattern can be modified to include the inner pattern
- --> $DIR/collapsible_match.rs:12:12
+ --> $DIR/collapsible_match.rs:13:12
|
LL | Ok(val) => match val {
| ^^^ replace this binding
LL | Some(n) => foo(n),
| ^^^^^^^ with this pattern
+ = note: `-D clippy::collapsible-match` implied by `-D warnings`
error: this `match` can be collapsed into the outer `match`
- --> $DIR/collapsible_match.rs:21:20
+ --> $DIR/collapsible_match.rs:22:20
|
LL | Ok(val) => match val {
| ____________________^
@@ -28,7 +28,7 @@ LL | | },
| |_________^
|
help: the outer pattern can be modified to include the inner pattern
- --> $DIR/collapsible_match.rs:21:12
+ --> $DIR/collapsible_match.rs:22:12
|
LL | Ok(val) => match val {
| ^^^ replace this binding
@@ -36,7 +36,7 @@ LL | Some(n) => foo(n),
| ^^^^^^^ with this pattern
error: this `if let` can be collapsed into the outer `if let`
- --> $DIR/collapsible_match.rs:30:9
+ --> $DIR/collapsible_match.rs:31:9
|
LL | / if let Some(n) = val {
LL | | take(n);
@@ -44,7 +44,7 @@ LL | | }
| |_________^
|
help: the outer pattern can be modified to include the inner pattern
- --> $DIR/collapsible_match.rs:29:15
+ --> $DIR/collapsible_match.rs:30:15
|
LL | if let Ok(val) = res_opt {
| ^^^ replace this binding
@@ -52,7 +52,7 @@ LL | if let Some(n) = val {
| ^^^^^^^ with this pattern
error: this `if let` can be collapsed into the outer `if let`
- --> $DIR/collapsible_match.rs:37:9
+ --> $DIR/collapsible_match.rs:38:9
|
LL | / if let Some(n) = val {
LL | | take(n);
@@ -62,7 +62,7 @@ LL | | }
| |_________^
|
help: the outer pattern can be modified to include the inner pattern
- --> $DIR/collapsible_match.rs:36:15
+ --> $DIR/collapsible_match.rs:37:15
|
LL | if let Ok(val) = res_opt {
| ^^^ replace this binding
@@ -70,7 +70,7 @@ LL | if let Some(n) = val {
| ^^^^^^^ with this pattern
error: this `match` can be collapsed into the outer `if let`
- --> $DIR/collapsible_match.rs:48:9
+ --> $DIR/collapsible_match.rs:49:9
|
LL | / match val {
LL | | Some(n) => foo(n),
@@ -79,7 +79,7 @@ LL | | }
| |_________^
|
help: the outer pattern can be modified to include the inner pattern
- --> $DIR/collapsible_match.rs:47:15
+ --> $DIR/collapsible_match.rs:48:15
|
LL | if let Ok(val) = res_opt {
| ^^^ replace this binding
@@ -88,7 +88,7 @@ LL | Some(n) => foo(n),
| ^^^^^^^ with this pattern
error: this `if let` can be collapsed into the outer `match`
- --> $DIR/collapsible_match.rs:57:13
+ --> $DIR/collapsible_match.rs:58:13
|
LL | / if let Some(n) = val {
LL | | take(n);
@@ -96,7 +96,7 @@ LL | | }
| |_____________^
|
help: the outer pattern can be modified to include the inner pattern
- --> $DIR/collapsible_match.rs:56:12
+ --> $DIR/collapsible_match.rs:57:12
|
LL | Ok(val) => {
| ^^^ replace this binding
@@ -104,7 +104,7 @@ LL | if let Some(n) = val {
| ^^^^^^^ with this pattern
error: this `match` can be collapsed into the outer `if let`
- --> $DIR/collapsible_match.rs:66:9
+ --> $DIR/collapsible_match.rs:67:9
|
LL | / match val {
LL | | Some(n) => foo(n),
@@ -113,7 +113,7 @@ LL | | }
| |_________^
|
help: the outer pattern can be modified to include the inner pattern
- --> $DIR/collapsible_match.rs:65:15
+ --> $DIR/collapsible_match.rs:66:15
|
LL | if let Ok(val) = res_opt {
| ^^^ replace this binding
@@ -122,7 +122,7 @@ LL | Some(n) => foo(n),
| ^^^^^^^ with this pattern
error: this `if let` can be collapsed into the outer `match`
- --> $DIR/collapsible_match.rs:77:13
+ --> $DIR/collapsible_match.rs:78:13
|
LL | / if let Some(n) = val {
LL | | take(n);
@@ -132,7 +132,7 @@ LL | | }
| |_____________^
|
help: the outer pattern can be modified to include the inner pattern
- --> $DIR/collapsible_match.rs:76:12
+ --> $DIR/collapsible_match.rs:77:12
|
LL | Ok(val) => {
| ^^^ replace this binding
@@ -140,7 +140,7 @@ LL | if let Some(n) = val {
| ^^^^^^^ with this pattern
error: this `match` can be collapsed into the outer `match`
- --> $DIR/collapsible_match.rs:88:20
+ --> $DIR/collapsible_match.rs:89:20
|
LL | Ok(val) => match val {
| ____________________^
@@ -150,7 +150,7 @@ LL | | },
| |_________^
|
help: the outer pattern can be modified to include the inner pattern
- --> $DIR/collapsible_match.rs:88:12
+ --> $DIR/collapsible_match.rs:89:12
|
LL | Ok(val) => match val {
| ^^^ replace this binding
@@ -158,7 +158,7 @@ LL | Some(n) => foo(n),
| ^^^^^^^ with this pattern
error: this `match` can be collapsed into the outer `match`
- --> $DIR/collapsible_match.rs:97:22
+ --> $DIR/collapsible_match.rs:98:22
|
LL | Some(val) => match val {
| ______________________^
@@ -168,12 +168,44 @@ LL | | },
| |_________^
|
help: the outer pattern can be modified to include the inner pattern
- --> $DIR/collapsible_match.rs:97:14
+ --> $DIR/collapsible_match.rs:98:14
|
LL | Some(val) => match val {
| ^^^ replace this binding
LL | Some(n) => foo(n),
| ^^^^^^^ with this pattern
-error: aborting due to 10 previous errors
+error: this `if let` can be collapsed into the outer `if let`
+ --> $DIR/collapsible_match.rs:263:9
+ |
+LL | / if let Some(u) = a {
+LL | | println!("{u:?}")
+LL | | }
+ | |_________^
+ |
+help: the outer pattern can be modified to include the inner pattern
+ --> $DIR/collapsible_match.rs:262:27
+ |
+LL | if let Issue9647::A { a, .. } = x {
+ | ^ replace this binding
+LL | if let Some(u) = a {
+ | ^^^^^^^ with this pattern, prefixed by a:
+
+error: this `if let` can be collapsed into the outer `if let`
+ --> $DIR/collapsible_match.rs:271:9
+ |
+LL | / if let Some(u) = a {
+LL | | println!("{u}")
+LL | | }
+ | |_________^
+ |
+help: the outer pattern can be modified to include the inner pattern
+ --> $DIR/collapsible_match.rs:270:35
+ |
+LL | if let Issue9647::A { a: Some(a), .. } = x {
+ | ^ replace this binding
+LL | if let Some(u) = a {
+ | ^^^^^^^ with this pattern
+
+error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/collapsible_match2.stderr b/src/tools/clippy/tests/ui/collapsible_match2.stderr
index fe64e4693..144dbe40a 100644
--- a/src/tools/clippy/tests/ui/collapsible_match2.stderr
+++ b/src/tools/clippy/tests/ui/collapsible_match2.stderr
@@ -8,7 +8,6 @@ LL | | _ => return,
LL | | },
| |_____________^
|
- = note: `-D clippy::collapsible-match` implied by `-D warnings`
help: the outer pattern can be modified to include the inner pattern
--> $DIR/collapsible_match2.rs:13:16
|
@@ -16,6 +15,7 @@ LL | Ok(val) if make() => match val {
| ^^^ replace this binding
LL | Some(n) => foo(n),
| ^^^^^^^ with this pattern
+ = note: `-D clippy::collapsible-match` implied by `-D warnings`
error: this `match` can be collapsed into the outer `match`
--> $DIR/collapsible_match2.rs:20:24
diff --git a/src/tools/clippy/tests/ui/comparison_chain.stderr b/src/tools/clippy/tests/ui/comparison_chain.stderr
index be25a80dd..2eeb50202 100644
--- a/src/tools/clippy/tests/ui/comparison_chain.stderr
+++ b/src/tools/clippy/tests/ui/comparison_chain.stderr
@@ -8,8 +8,8 @@ LL | | b()
LL | | }
| |_____^
|
- = note: `-D clippy::comparison-chain` implied by `-D warnings`
= help: consider rewriting the `if` chain to use `cmp` and `match`
+ = note: `-D clippy::comparison-chain` implied by `-D warnings`
error: `if` chain can be rewritten with `match`
--> $DIR/comparison_chain.rs:27:5
diff --git a/src/tools/clippy/tests/ui/copy_iterator.stderr b/src/tools/clippy/tests/ui/copy_iterator.stderr
index f8ce6af79..6bc6fd6b6 100644
--- a/src/tools/clippy/tests/ui/copy_iterator.stderr
+++ b/src/tools/clippy/tests/ui/copy_iterator.stderr
@@ -10,8 +10,8 @@ LL | | }
LL | | }
| |_^
|
- = note: `-D clippy::copy-iterator` implied by `-D warnings`
= note: consider implementing `IntoIterator` instead
+ = note: `-D clippy::copy-iterator` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/crashes/ice-360.stderr b/src/tools/clippy/tests/ui/crashes/ice-360.stderr
index 0eb7bb12b..a2e2ab8fd 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-360.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-360.stderr
@@ -18,8 +18,8 @@ error: empty `loop {}` wastes CPU cycles
LL | loop {}
| ^^^^^^^
|
- = note: `-D clippy::empty-loop` implied by `-D warnings`
= help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body
+ = note: `-D clippy::empty-loop` implied by `-D warnings`
error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/crashes/ice-4775.rs b/src/tools/clippy/tests/ui/crashes/ice-4775.rs
index 405e3039e..f693aafd1 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-4775.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-4775.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::uninlined_format_args)]
+
pub struct ArrayWrapper<const N: usize>([usize; N]);
impl<const N: usize> ArrayWrapper<{ N }> {
diff --git a/src/tools/clippy/tests/ui/crashes/ice-6254.stderr b/src/tools/clippy/tests/ui/crashes/ice-6254.stderr
index f37ab2e9b..22d82a30c 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-6254.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-6254.stderr
@@ -4,9 +4,9 @@ error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated wit
LL | FOO_REF_REF => {},
| ^^^^^^^^^^^
|
- = note: `-D indirect-structural-match` implied by `-D warnings`
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
+ = note: `-D indirect-structural-match` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/crashes/ice-7126.rs b/src/tools/clippy/tests/ui/crashes/ice-7126.rs
index ca563ba09..b2dc2248b 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-7126.rs
+++ b/src/tools/clippy/tests/ui/crashes/ice-7126.rs
@@ -1,13 +1,13 @@
// This test requires a feature gated const fn and will stop working in the future.
-#![feature(const_btree_new)]
+#![feature(const_btree_len)]
use std::collections::BTreeMap;
-struct Foo(BTreeMap<i32, i32>);
+struct Foo(usize);
impl Foo {
fn new() -> Self {
- Self(BTreeMap::new())
+ Self(BTreeMap::len(&BTreeMap::<u8, u8>::new()))
}
}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-7868.stderr b/src/tools/clippy/tests/ui/crashes/ice-7868.stderr
index 1a33e6475..1d8314e88 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-7868.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-7868.stderr
@@ -4,8 +4,8 @@ error: unsafe block missing a safety comment
LL | unsafe { 0 };
| ^^^^^^^^^^^^
|
- = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
= help: consider adding a safety comment on the preceding line
+ = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/crashes/ice-7869.stderr b/src/tools/clippy/tests/ui/crashes/ice-7869.stderr
index 4fa9fb27e..35d1e8fd2 100644
--- a/src/tools/clippy/tests/ui/crashes/ice-7869.stderr
+++ b/src/tools/clippy/tests/ui/crashes/ice-7869.stderr
@@ -8,8 +8,8 @@ LL | | TyöValmis,
LL | | }
| |_^
|
- = note: `-D clippy::enum-variant-names` implied by `-D warnings`
= help: remove the prefixes and use full paths to the variants instead of glob imports
+ = note: `-D clippy::enum-variant-names` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/crashes/ice-9445.rs b/src/tools/clippy/tests/ui/crashes/ice-9445.rs
new file mode 100644
index 000000000..c67b22f6f
--- /dev/null
+++ b/src/tools/clippy/tests/ui/crashes/ice-9445.rs
@@ -0,0 +1,3 @@
+const UNINIT: core::mem::MaybeUninit<core::cell::Cell<&'static ()>> = core::mem::MaybeUninit::uninit();
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-9459.rs b/src/tools/clippy/tests/ui/crashes/ice-9459.rs
new file mode 100644
index 000000000..55615124f
--- /dev/null
+++ b/src/tools/clippy/tests/ui/crashes/ice-9459.rs
@@ -0,0 +1,5 @@
+#![feature(unsized_fn_params)]
+
+pub fn f0(_f: dyn FnOnce()) {}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-9463.rs b/src/tools/clippy/tests/ui/crashes/ice-9463.rs
new file mode 100644
index 000000000..9564e77c2
--- /dev/null
+++ b/src/tools/clippy/tests/ui/crashes/ice-9463.rs
@@ -0,0 +1,5 @@
+#![deny(arithmetic_overflow)]
+fn main() {
+ let _x = -1_i32 >> -1;
+ let _y = 1u32 >> 10000000000000u32;
+}
diff --git a/src/tools/clippy/tests/ui/crashes/ice-9463.stderr b/src/tools/clippy/tests/ui/crashes/ice-9463.stderr
new file mode 100644
index 000000000..2b425e85a
--- /dev/null
+++ b/src/tools/clippy/tests/ui/crashes/ice-9463.stderr
@@ -0,0 +1,29 @@
+error: this arithmetic operation will overflow
+ --> $DIR/ice-9463.rs:3:14
+ |
+LL | let _x = -1_i32 >> -1;
+ | ^^^^^^^^^^^^ attempt to shift right by `-1_i32`, which would overflow
+ |
+note: the lint level is defined here
+ --> $DIR/ice-9463.rs:1:9
+ |
+LL | #![deny(arithmetic_overflow)]
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: this arithmetic operation will overflow
+ --> $DIR/ice-9463.rs:4:14
+ |
+LL | let _y = 1u32 >> 10000000000000u32;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to shift right by `1316134912_u32`, which would overflow
+
+error: literal out of range for `u32`
+ --> $DIR/ice-9463.rs:4:22
+ |
+LL | let _y = 1u32 >> 10000000000000u32;
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: the literal `10000000000000u32` does not fit into the type `u32` whose range is `0..=4294967295`
+ = note: `#[deny(overflowing_literals)]` on by default
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/crashes/ice-9625.rs b/src/tools/clippy/tests/ui/crashes/ice-9625.rs
new file mode 100644
index 000000000..a765882b5
--- /dev/null
+++ b/src/tools/clippy/tests/ui/crashes/ice-9625.rs
@@ -0,0 +1,4 @@
+fn main() {
+ let x = &1;
+ let _ = &1 < x && x < &10;
+}
diff --git a/src/tools/clippy/tests/ui/crashes/regressions.rs b/src/tools/clippy/tests/ui/crashes/regressions.rs
index 55a8b4034..b34997d4e 100644
--- a/src/tools/clippy/tests/ui/crashes/regressions.rs
+++ b/src/tools/clippy/tests/ui/crashes/regressions.rs
@@ -1,4 +1,4 @@
-#![allow(clippy::disallowed_names)]
+#![allow(clippy::disallowed_names, clippy::uninlined_format_args)]
pub fn foo(bar: *const u8) {
println!("{:#p}", bar);
diff --git a/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.stderr b/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.stderr
index 459cf12a1..3d79a115c 100644
--- a/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.stderr
+++ b/src/tools/clippy/tests/ui/crate_level_checks/entrypoint_recursion.stderr
@@ -4,8 +4,8 @@ error: recursing into entrypoint `a`
LL | a();
| ^
|
- = note: `-D clippy::main-recursion` implied by `-D warnings`
= help: consider using another function for this recursion
+ = note: `-D clippy::main-recursion` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.stderr b/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.stderr
index 48152d8ad..7d8ea3f76 100644
--- a/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.stderr
+++ b/src/tools/clippy/tests/ui/crate_level_checks/no_std_swap.stderr
@@ -5,8 +5,8 @@ LL | / a = b;
LL | | b = a;
| |_________^ help: try: `core::mem::swap(&mut a, &mut b)`
|
- = note: `-D clippy::almost-swapped` implied by `-D warnings`
= note: or maybe you should use `core::mem::replace`?
+ = note: `-D clippy::almost-swapped` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/crate_level_checks/std_main_recursion.stderr b/src/tools/clippy/tests/ui/crate_level_checks/std_main_recursion.stderr
index 0a260f9d2..82c68bd1c 100644
--- a/src/tools/clippy/tests/ui/crate_level_checks/std_main_recursion.stderr
+++ b/src/tools/clippy/tests/ui/crate_level_checks/std_main_recursion.stderr
@@ -4,8 +4,8 @@ error: recursing into entrypoint `main`
LL | main();
| ^^^^
|
- = note: `-D clippy::main-recursion` implied by `-D warnings`
= help: consider using another function for this recursion
+ = note: `-D clippy::main-recursion` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/def_id_nocore.stderr b/src/tools/clippy/tests/ui/def_id_nocore.stderr
index 6210d7c6c..f8fc17e87 100644
--- a/src/tools/clippy/tests/ui/def_id_nocore.stderr
+++ b/src/tools/clippy/tests/ui/def_id_nocore.stderr
@@ -4,8 +4,8 @@ error: methods called `as_*` usually take `self` by reference or `self` by mutab
LL | pub fn as_ref(self) -> &'static str {
| ^^^^
|
- = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
= help: consider choosing a less ambiguous name
+ = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed
index a28bff767..a370ccc76 100644
--- a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed
+++ b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.fixed
@@ -33,6 +33,7 @@ mod basic_expr {
let x: [f64; 3] = [1., 2., 3.];
let x: (f64, f64) = if true { (1., 2.) } else { (3., 4.) };
let x: _ = 1.;
+ const X: f32 = 1.;
}
}
@@ -59,6 +60,14 @@ mod nested_local {
// Should NOT lint this because this literal is bound to `_` of outer `Local`.
2.
};
+
+ const X: f32 = {
+ // Should lint this because this literal is not bound to any types.
+ let y = 1.0_f64;
+
+ // Should NOT lint this because this literal is bound to `_` of outer `Local`.
+ 1.
+ };
}
}
diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs
index b48435cc7..2476fe951 100644
--- a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs
+++ b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.rs
@@ -33,6 +33,7 @@ mod basic_expr {
let x: [f64; 3] = [1., 2., 3.];
let x: (f64, f64) = if true { (1., 2.) } else { (3., 4.) };
let x: _ = 1.;
+ const X: f32 = 1.;
}
}
@@ -59,6 +60,14 @@ mod nested_local {
// Should NOT lint this because this literal is bound to `_` of outer `Local`.
2.
};
+
+ const X: f32 = {
+ // Should lint this because this literal is not bound to any types.
+ let y = 1.;
+
+ // Should NOT lint this because this literal is bound to `_` of outer `Local`.
+ 1.
+ };
}
}
diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.stderr b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.stderr
index f8b6c7746..5df2f6423 100644
--- a/src/tools/clippy/tests/ui/default_numeric_fallback_f64.stderr
+++ b/src/tools/clippy/tests/ui/default_numeric_fallback_f64.stderr
@@ -61,79 +61,85 @@ LL | _ => 1.,
| ^^ help: consider adding suffix: `1.0_f64`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_f64.rs:43:21
+ --> $DIR/default_numeric_fallback_f64.rs:44:21
|
LL | let y = 1.;
| ^^ help: consider adding suffix: `1.0_f64`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_f64.rs:51:21
+ --> $DIR/default_numeric_fallback_f64.rs:52:21
|
LL | let y = 1.;
| ^^ help: consider adding suffix: `1.0_f64`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_f64.rs:57:21
+ --> $DIR/default_numeric_fallback_f64.rs:58:21
|
LL | let y = 1.;
| ^^ help: consider adding suffix: `1.0_f64`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_f64.rs:69:9
+ --> $DIR/default_numeric_fallback_f64.rs:66:21
+ |
+LL | let y = 1.;
+ | ^^ help: consider adding suffix: `1.0_f64`
+
+error: default numeric fallback might occur
+ --> $DIR/default_numeric_fallback_f64.rs:78:9
|
LL | 1.
| ^^ help: consider adding suffix: `1.0_f64`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_f64.rs:75:27
+ --> $DIR/default_numeric_fallback_f64.rs:84:27
|
LL | let f = || -> _ { 1. };
| ^^ help: consider adding suffix: `1.0_f64`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_f64.rs:79:29
+ --> $DIR/default_numeric_fallback_f64.rs:88:29
|
LL | let f = || -> f64 { 1. };
| ^^ help: consider adding suffix: `1.0_f64`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_f64.rs:93:21
+ --> $DIR/default_numeric_fallback_f64.rs:102:21
|
LL | generic_arg(1.);
| ^^ help: consider adding suffix: `1.0_f64`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_f64.rs:96:32
+ --> $DIR/default_numeric_fallback_f64.rs:105:32
|
LL | let x: _ = generic_arg(1.);
| ^^ help: consider adding suffix: `1.0_f64`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_f64.rs:114:28
+ --> $DIR/default_numeric_fallback_f64.rs:123:28
|
LL | GenericStruct { x: 1. };
| ^^ help: consider adding suffix: `1.0_f64`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_f64.rs:117:36
+ --> $DIR/default_numeric_fallback_f64.rs:126:36
|
LL | let _ = GenericStruct { x: 1. };
| ^^ help: consider adding suffix: `1.0_f64`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_f64.rs:135:24
+ --> $DIR/default_numeric_fallback_f64.rs:144:24
|
LL | GenericEnum::X(1.);
| ^^ help: consider adding suffix: `1.0_f64`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_f64.rs:155:23
+ --> $DIR/default_numeric_fallback_f64.rs:164:23
|
LL | s.generic_arg(1.);
| ^^ help: consider adding suffix: `1.0_f64`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_f64.rs:162:21
+ --> $DIR/default_numeric_fallback_f64.rs:171:21
|
LL | let x = 22.;
| ^^^ help: consider adding suffix: `22.0_f64`
@@ -143,5 +149,5 @@ LL | internal_macro!();
|
= note: this error originates in the macro `internal_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: aborting due to 23 previous errors
+error: aborting due to 24 previous errors
diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed
index 55451cf2f..3f4994f04 100644
--- a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed
+++ b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.fixed
@@ -33,6 +33,8 @@ mod basic_expr {
let x: [i32; 3] = [1, 2, 3];
let x: (i32, i32) = if true { (1, 2) } else { (3, 4) };
let x: _ = 1;
+ let x: u64 = 1;
+ const CONST_X: i8 = 1;
}
}
@@ -59,6 +61,14 @@ mod nested_local {
// Should NOT lint this because this literal is bound to `_` of outer `Local`.
2
};
+
+ const CONST_X: i32 = {
+ // Should lint this because this literal is not bound to any types.
+ let y = 1_i32;
+
+ // Should NOT lint this because this literal is bound to `_` of outer `Local`.
+ 1
+ };
}
}
diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs
index 62d72f2fe..2df0e0978 100644
--- a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs
+++ b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.rs
@@ -33,6 +33,8 @@ mod basic_expr {
let x: [i32; 3] = [1, 2, 3];
let x: (i32, i32) = if true { (1, 2) } else { (3, 4) };
let x: _ = 1;
+ let x: u64 = 1;
+ const CONST_X: i8 = 1;
}
}
@@ -59,6 +61,14 @@ mod nested_local {
// Should NOT lint this because this literal is bound to `_` of outer `Local`.
2
};
+
+ const CONST_X: i32 = {
+ // Should lint this because this literal is not bound to any types.
+ let y = 1;
+
+ // Should NOT lint this because this literal is bound to `_` of outer `Local`.
+ 1
+ };
}
}
diff --git a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.stderr b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.stderr
index f7c5e724c..6f219c3fc 100644
--- a/src/tools/clippy/tests/ui/default_numeric_fallback_i32.stderr
+++ b/src/tools/clippy/tests/ui/default_numeric_fallback_i32.stderr
@@ -73,79 +73,85 @@ LL | _ => 2,
| ^ help: consider adding suffix: `2_i32`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_i32.rs:43:21
+ --> $DIR/default_numeric_fallback_i32.rs:45:21
|
LL | let y = 1;
| ^ help: consider adding suffix: `1_i32`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_i32.rs:51:21
+ --> $DIR/default_numeric_fallback_i32.rs:53:21
|
LL | let y = 1;
| ^ help: consider adding suffix: `1_i32`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_i32.rs:57:21
+ --> $DIR/default_numeric_fallback_i32.rs:59:21
|
LL | let y = 1;
| ^ help: consider adding suffix: `1_i32`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_i32.rs:69:9
+ --> $DIR/default_numeric_fallback_i32.rs:67:21
+ |
+LL | let y = 1;
+ | ^ help: consider adding suffix: `1_i32`
+
+error: default numeric fallback might occur
+ --> $DIR/default_numeric_fallback_i32.rs:79:9
|
LL | 1
| ^ help: consider adding suffix: `1_i32`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_i32.rs:75:27
+ --> $DIR/default_numeric_fallback_i32.rs:85:27
|
LL | let f = || -> _ { 1 };
| ^ help: consider adding suffix: `1_i32`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_i32.rs:79:29
+ --> $DIR/default_numeric_fallback_i32.rs:89:29
|
LL | let f = || -> i32 { 1 };
| ^ help: consider adding suffix: `1_i32`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_i32.rs:93:21
+ --> $DIR/default_numeric_fallback_i32.rs:103:21
|
LL | generic_arg(1);
| ^ help: consider adding suffix: `1_i32`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_i32.rs:96:32
+ --> $DIR/default_numeric_fallback_i32.rs:106:32
|
LL | let x: _ = generic_arg(1);
| ^ help: consider adding suffix: `1_i32`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_i32.rs:114:28
+ --> $DIR/default_numeric_fallback_i32.rs:124:28
|
LL | GenericStruct { x: 1 };
| ^ help: consider adding suffix: `1_i32`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_i32.rs:117:36
+ --> $DIR/default_numeric_fallback_i32.rs:127:36
|
LL | let _ = GenericStruct { x: 1 };
| ^ help: consider adding suffix: `1_i32`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_i32.rs:135:24
+ --> $DIR/default_numeric_fallback_i32.rs:145:24
|
LL | GenericEnum::X(1);
| ^ help: consider adding suffix: `1_i32`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_i32.rs:155:23
+ --> $DIR/default_numeric_fallback_i32.rs:165:23
|
LL | s.generic_arg(1);
| ^ help: consider adding suffix: `1_i32`
error: default numeric fallback might occur
- --> $DIR/default_numeric_fallback_i32.rs:162:21
+ --> $DIR/default_numeric_fallback_i32.rs:172:21
|
LL | let x = 22;
| ^^ help: consider adding suffix: `22_i32`
@@ -155,5 +161,5 @@ LL | internal_macro!();
|
= note: this error originates in the macro `internal_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: aborting due to 25 previous errors
+error: aborting due to 26 previous errors
diff --git a/src/tools/clippy/tests/ui/default_trait_access.fixed b/src/tools/clippy/tests/ui/default_trait_access.fixed
index fce66eb17..eedd43619 100644
--- a/src/tools/clippy/tests/ui/default_trait_access.fixed
+++ b/src/tools/clippy/tests/ui/default_trait_access.fixed
@@ -1,8 +1,8 @@
// run-rustfix
// aux-build: proc_macro_with_span.rs
-
-#![allow(unused_imports, dead_code)]
#![deny(clippy::default_trait_access)]
+#![allow(dead_code, unused_imports)]
+#![allow(clippy::uninlined_format_args)]
extern crate proc_macro_with_span;
diff --git a/src/tools/clippy/tests/ui/default_trait_access.rs b/src/tools/clippy/tests/ui/default_trait_access.rs
index 3e8e898b7..11d4bc5c5 100644
--- a/src/tools/clippy/tests/ui/default_trait_access.rs
+++ b/src/tools/clippy/tests/ui/default_trait_access.rs
@@ -1,8 +1,8 @@
// run-rustfix
// aux-build: proc_macro_with_span.rs
-
-#![allow(unused_imports, dead_code)]
#![deny(clippy::default_trait_access)]
+#![allow(dead_code, unused_imports)]
+#![allow(clippy::uninlined_format_args)]
extern crate proc_macro_with_span;
diff --git a/src/tools/clippy/tests/ui/default_trait_access.stderr b/src/tools/clippy/tests/ui/default_trait_access.stderr
index 3493de37a..49b2dde3f 100644
--- a/src/tools/clippy/tests/ui/default_trait_access.stderr
+++ b/src/tools/clippy/tests/ui/default_trait_access.stderr
@@ -5,7 +5,7 @@ LL | let s1: String = Default::default();
| ^^^^^^^^^^^^^^^^^^ help: try: `std::string::String::default()`
|
note: the lint level is defined here
- --> $DIR/default_trait_access.rs:5:9
+ --> $DIR/default_trait_access.rs:3:9
|
LL | #![deny(clippy::default_trait_access)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/default_union_representation.stderr b/src/tools/clippy/tests/ui/default_union_representation.stderr
index 138884af8..8b7ed94cb 100644
--- a/src/tools/clippy/tests/ui/default_union_representation.stderr
+++ b/src/tools/clippy/tests/ui/default_union_representation.stderr
@@ -7,8 +7,8 @@ LL | | b: u32,
LL | | }
| |_^
|
- = note: `-D clippy::default-union-representation` implied by `-D warnings`
= help: consider annotating `NoAttribute` with `#[repr(C)]` to explicitly specify memory layout
+ = note: `-D clippy::default-union-representation` implied by `-D warnings`
error: this union has the default representation
--> $DIR/default_union_representation.rs:16:1
diff --git a/src/tools/clippy/tests/ui/derivable_impls.fixed b/src/tools/clippy/tests/ui/derivable_impls.fixed
new file mode 100644
index 000000000..7dcdfb093
--- /dev/null
+++ b/src/tools/clippy/tests/ui/derivable_impls.fixed
@@ -0,0 +1,213 @@
+// run-rustfix
+
+#![allow(dead_code)]
+
+use std::collections::HashMap;
+
+#[derive(Default)]
+struct FooDefault<'a> {
+ a: bool,
+ b: i32,
+ c: u64,
+ d: Vec<i32>,
+ e: FooND1,
+ f: FooND2,
+ g: HashMap<i32, i32>,
+ h: (i32, Vec<i32>),
+ i: [Vec<i32>; 3],
+ j: [i32; 5],
+ k: Option<i32>,
+ l: &'a [i32],
+}
+
+
+
+#[derive(Default)]
+struct TupleDefault(bool, i32, u64);
+
+
+
+struct FooND1 {
+ a: bool,
+}
+
+impl std::default::Default for FooND1 {
+ fn default() -> Self {
+ Self { a: true }
+ }
+}
+
+struct FooND2 {
+ a: i32,
+}
+
+impl std::default::Default for FooND2 {
+ fn default() -> Self {
+ Self { a: 5 }
+ }
+}
+
+struct FooNDNew {
+ a: bool,
+}
+
+impl FooNDNew {
+ fn new() -> Self {
+ Self { a: true }
+ }
+}
+
+impl Default for FooNDNew {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+struct FooNDVec(Vec<i32>);
+
+impl Default for FooNDVec {
+ fn default() -> Self {
+ Self(vec![5, 12])
+ }
+}
+
+#[derive(Default)]
+struct StrDefault<'a>(&'a str);
+
+
+
+#[derive(Default)]
+struct AlreadyDerived(i32, bool);
+
+macro_rules! mac {
+ () => {
+ 0
+ };
+ ($e:expr) => {
+ struct X(u32);
+ impl Default for X {
+ fn default() -> Self {
+ Self($e)
+ }
+ }
+ };
+}
+
+mac!(0);
+
+#[derive(Default)]
+struct Y(u32);
+
+
+struct RustIssue26925<T> {
+ a: Option<T>,
+}
+
+// We should watch out for cases where a manual impl is needed because a
+// derive adds different type bounds (https://github.com/rust-lang/rust/issues/26925).
+// For example, a struct with Option<T> does not require T: Default, but a derive adds
+// that type bound anyways. So until #26925 get fixed we should disable lint
+// for the following case
+impl<T> Default for RustIssue26925<T> {
+ fn default() -> Self {
+ Self { a: None }
+ }
+}
+
+struct SpecializedImpl<A, B> {
+ a: A,
+ b: B,
+}
+
+impl<T: Default> Default for SpecializedImpl<T, T> {
+ fn default() -> Self {
+ Self {
+ a: T::default(),
+ b: T::default(),
+ }
+ }
+}
+
+#[derive(Default)]
+struct WithoutSelfCurly {
+ a: bool,
+}
+
+
+
+#[derive(Default)]
+struct WithoutSelfParan(bool);
+
+
+
+// https://github.com/rust-lang/rust-clippy/issues/7655
+
+pub struct SpecializedImpl2<T> {
+ v: Vec<T>,
+}
+
+impl Default for SpecializedImpl2<String> {
+ fn default() -> Self {
+ Self { v: Vec::new() }
+ }
+}
+
+// https://github.com/rust-lang/rust-clippy/issues/7654
+
+pub struct Color {
+ pub r: u8,
+ pub g: u8,
+ pub b: u8,
+}
+
+/// `#000000`
+impl Default for Color {
+ fn default() -> Self {
+ Color { r: 0, g: 0, b: 0 }
+ }
+}
+
+pub struct Color2 {
+ pub r: u8,
+ pub g: u8,
+ pub b: u8,
+}
+
+impl Default for Color2 {
+ /// `#000000`
+ fn default() -> Self {
+ Self { r: 0, g: 0, b: 0 }
+ }
+}
+
+#[derive(Default)]
+pub struct RepeatDefault1 {
+ a: [i8; 32],
+}
+
+
+
+pub struct RepeatDefault2 {
+ a: [i8; 33],
+}
+
+impl Default for RepeatDefault2 {
+ fn default() -> Self {
+ RepeatDefault2 { a: [0; 33] }
+ }
+}
+
+// https://github.com/rust-lang/rust-clippy/issues/7753
+
+pub enum IntOrString {
+ Int(i32),
+ String(String),
+}
+
+impl Default for IntOrString {
+ fn default() -> Self {
+ IntOrString::Int(0)
+ }
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/derivable_impls.rs b/src/tools/clippy/tests/ui/derivable_impls.rs
index a64120047..625cbcdde 100644
--- a/src/tools/clippy/tests/ui/derivable_impls.rs
+++ b/src/tools/clippy/tests/ui/derivable_impls.rs
@@ -1,3 +1,7 @@
+// run-rustfix
+
+#![allow(dead_code)]
+
use std::collections::HashMap;
struct FooDefault<'a> {
diff --git a/src/tools/clippy/tests/ui/derivable_impls.stderr b/src/tools/clippy/tests/ui/derivable_impls.stderr
index 49fb471a2..c1db5a58b 100644
--- a/src/tools/clippy/tests/ui/derivable_impls.stderr
+++ b/src/tools/clippy/tests/ui/derivable_impls.stderr
@@ -1,5 +1,5 @@
error: this `impl` can be derived
- --> $DIR/derivable_impls.rs:18:1
+ --> $DIR/derivable_impls.rs:22:1
|
LL | / impl std::default::Default for FooDefault<'_> {
LL | | fn default() -> Self {
@@ -11,10 +11,14 @@ LL | | }
| |_^
|
= note: `-D clippy::derivable-impls` implied by `-D warnings`
- = help: try annotating `FooDefault` with `#[derive(Default)]`
+ = help: remove the manual implementation...
+help: ...and instead derive it
+ |
+LL | #[derive(Default)]
+ |
error: this `impl` can be derived
- --> $DIR/derivable_impls.rs:39:1
+ --> $DIR/derivable_impls.rs:43:1
|
LL | / impl std::default::Default for TupleDefault {
LL | | fn default() -> Self {
@@ -23,10 +27,14 @@ LL | | }
LL | | }
| |_^
|
- = help: try annotating `TupleDefault` with `#[derive(Default)]`
+ = help: remove the manual implementation...
+help: ...and instead derive it
+ |
+LL | #[derive(Default)]
+ |
error: this `impl` can be derived
- --> $DIR/derivable_impls.rs:91:1
+ --> $DIR/derivable_impls.rs:95:1
|
LL | / impl Default for StrDefault<'_> {
LL | | fn default() -> Self {
@@ -35,10 +43,14 @@ LL | | }
LL | | }
| |_^
|
- = help: try annotating `StrDefault` with `#[derive(Default)]`
+ = help: remove the manual implementation...
+help: ...and instead derive it
+ |
+LL | #[derive(Default)]
+ |
error: this `impl` can be derived
- --> $DIR/derivable_impls.rs:117:1
+ --> $DIR/derivable_impls.rs:121:1
|
LL | / impl Default for Y {
LL | | fn default() -> Self {
@@ -47,10 +59,14 @@ LL | | }
LL | | }
| |_^
|
- = help: try annotating `Y` with `#[derive(Default)]`
+ = help: remove the manual implementation...
+help: ...and instead derive it
+ |
+LL | #[derive(Default)]
+ |
error: this `impl` can be derived
- --> $DIR/derivable_impls.rs:156:1
+ --> $DIR/derivable_impls.rs:160:1
|
LL | / impl Default for WithoutSelfCurly {
LL | | fn default() -> Self {
@@ -59,10 +75,14 @@ LL | | }
LL | | }
| |_^
|
- = help: try annotating `WithoutSelfCurly` with `#[derive(Default)]`
+ = help: remove the manual implementation...
+help: ...and instead derive it
+ |
+LL | #[derive(Default)]
+ |
error: this `impl` can be derived
- --> $DIR/derivable_impls.rs:164:1
+ --> $DIR/derivable_impls.rs:168:1
|
LL | / impl Default for WithoutSelfParan {
LL | | fn default() -> Self {
@@ -71,10 +91,14 @@ LL | | }
LL | | }
| |_^
|
- = help: try annotating `WithoutSelfParan` with `#[derive(Default)]`
+ = help: remove the manual implementation...
+help: ...and instead derive it
+ |
+LL | #[derive(Default)]
+ |
error: this `impl` can be derived
- --> $DIR/derivable_impls.rs:214:1
+ --> $DIR/derivable_impls.rs:218:1
|
LL | / impl Default for RepeatDefault1 {
LL | | fn default() -> Self {
@@ -83,7 +107,11 @@ LL | | }
LL | | }
| |_^
|
- = help: try annotating `RepeatDefault1` with `#[derive(Default)]`
+ = help: remove the manual implementation...
+help: ...and instead derive it
+ |
+LL | #[derive(Default)]
+ |
error: aborting due to 7 previous errors
diff --git a/src/tools/clippy/tests/ui/derive.stderr b/src/tools/clippy/tests/ui/derive.stderr
index 82a70ceec..e1fbb8dcd 100644
--- a/src/tools/clippy/tests/ui/derive.stderr
+++ b/src/tools/clippy/tests/ui/derive.stderr
@@ -8,7 +8,6 @@ LL | | }
LL | | }
| |_^
|
- = note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings`
note: consider deriving `Clone` or removing `Copy`
--> $DIR/derive.rs:8:1
|
@@ -18,6 +17,7 @@ LL | | Qux
LL | | }
LL | | }
| |_^
+ = note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings`
error: you are implementing `Clone` explicitly on a `Copy` type
--> $DIR/derive.rs:32:1
diff --git a/src/tools/clippy/tests/ui/derive_hash_xor_eq.stderr b/src/tools/clippy/tests/ui/derive_hash_xor_eq.stderr
index 2a4abb0c5..16c923978 100644
--- a/src/tools/clippy/tests/ui/derive_hash_xor_eq.stderr
+++ b/src/tools/clippy/tests/ui/derive_hash_xor_eq.stderr
@@ -4,12 +4,12 @@ error: you are deriving `Hash` but have implemented `PartialEq` explicitly
LL | #[derive(Hash)]
| ^^^^
|
- = note: `#[deny(clippy::derive_hash_xor_eq)]` on by default
note: `PartialEq` implemented here
--> $DIR/derive_hash_xor_eq.rs:15:1
|
LL | impl PartialEq for Bar {
| ^^^^^^^^^^^^^^^^^^^^^^
+ = note: `#[deny(clippy::derive_hash_xor_eq)]` on by default
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
error: you are deriving `Hash` but have implemented `PartialEq` explicitly
diff --git a/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr b/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr
index baf8341ab..58efbb854 100644
--- a/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr
+++ b/src/tools/clippy/tests/ui/derive_ord_xor_partial_ord.stderr
@@ -4,12 +4,12 @@ error: you are deriving `Ord` but have implemented `PartialOrd` explicitly
LL | #[derive(Ord, PartialEq, Eq)]
| ^^^
|
- = note: `-D clippy::derive-ord-xor-partial-ord` implied by `-D warnings`
note: `PartialOrd` implemented here
--> $DIR/derive_ord_xor_partial_ord.rs:24:1
|
LL | impl PartialOrd for DeriveOrd {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: `-D clippy::derive-ord-xor-partial-ord` implied by `-D warnings`
= note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info)
error: you are deriving `Ord` but have implemented `PartialOrd` explicitly
diff --git a/src/tools/clippy/tests/ui/doc/unbalanced_ticks.stderr b/src/tools/clippy/tests/ui/doc/unbalanced_ticks.stderr
index a462b9887..f2ac6bc32 100644
--- a/src/tools/clippy/tests/ui/doc/unbalanced_ticks.stderr
+++ b/src/tools/clippy/tests/ui/doc/unbalanced_ticks.stderr
@@ -7,8 +7,8 @@ LL | | /// Because of the initial `unbalanced_tick` pair, the error message is
LL | | /// very `confusing_and_misleading`.
| |____________________________________^
|
- = note: `-D clippy::doc-markdown` implied by `-D warnings`
= help: a backtick may be missing a pair
+ = note: `-D clippy::doc-markdown` implied by `-D warnings`
error: backticks are unbalanced
--> $DIR/unbalanced_ticks.rs:13:1
diff --git a/src/tools/clippy/tests/ui/doc_link_with_quotes.rs b/src/tools/clippy/tests/ui/doc_link_with_quotes.rs
index ab52fb1a4..17c04c34e 100644
--- a/src/tools/clippy/tests/ui/doc_link_with_quotes.rs
+++ b/src/tools/clippy/tests/ui/doc_link_with_quotes.rs
@@ -4,9 +4,14 @@ fn main() {
foo()
}
-/// Calls ['bar']
+/// Calls ['bar'] uselessly
pub fn foo() {
bar()
}
+/// # Examples
+/// This demonstrates issue \#8961
+/// ```
+/// let _ = vec!['w', 'a', 't'];
+/// ```
pub fn bar() {}
diff --git a/src/tools/clippy/tests/ui/doc_link_with_quotes.stderr b/src/tools/clippy/tests/ui/doc_link_with_quotes.stderr
index bf6d57d8a..ea730e667 100644
--- a/src/tools/clippy/tests/ui/doc_link_with_quotes.stderr
+++ b/src/tools/clippy/tests/ui/doc_link_with_quotes.stderr
@@ -1,8 +1,8 @@
error: possible intra-doc link using quotes instead of backticks
- --> $DIR/doc_link_with_quotes.rs:7:1
+ --> $DIR/doc_link_with_quotes.rs:7:12
|
-LL | /// Calls ['bar']
- | ^^^^^^^^^^^^^^^^^
+LL | /// Calls ['bar'] uselessly
+ | ^^^^^
|
= note: `-D clippy::doc-link-with-quotes` implied by `-D warnings`
diff --git a/src/tools/clippy/tests/ui/double_must_use.stderr b/src/tools/clippy/tests/ui/double_must_use.stderr
index 8290ece1c..3d34557a8 100644
--- a/src/tools/clippy/tests/ui/double_must_use.stderr
+++ b/src/tools/clippy/tests/ui/double_must_use.stderr
@@ -4,8 +4,8 @@ error: this function has an empty `#[must_use]` attribute, but returns a type al
LL | pub fn must_use_result() -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::double-must-use` implied by `-D warnings`
= help: either add some descriptive text or remove the attribute
+ = note: `-D clippy::double-must-use` implied by `-D warnings`
error: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]`
--> $DIR/double_must_use.rs:10:1
diff --git a/src/tools/clippy/tests/ui/drop_forget_copy.rs b/src/tools/clippy/tests/ui/drop_forget_copy.rs
index 7c7a9ecff..a7276dd59 100644
--- a/src/tools/clippy/tests/ui/drop_forget_copy.rs
+++ b/src/tools/clippy/tests/ui/drop_forget_copy.rs
@@ -64,3 +64,23 @@ fn main() {
let a5 = a1.clone();
forget(a5);
}
+
+#[allow(unused)]
+#[allow(clippy::unit_cmp)]
+fn issue9482(x: u8) {
+ fn println_and<T>(t: T) -> T {
+ println!("foo");
+ t
+ }
+
+ match x {
+ 0 => drop(println_and(12)), // Don't lint (copy type), we only care about side-effects
+ 1 => drop(println_and(String::new())), // Don't lint (no copy type), we only care about side-effects
+ 2 => {
+ drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block
+ },
+ 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
+ 4 => drop(2), // Lint, not a fn/method call
+ _ => (),
+ }
+}
diff --git a/src/tools/clippy/tests/ui/drop_forget_copy.stderr b/src/tools/clippy/tests/ui/drop_forget_copy.stderr
index 88228afae..90bef1c3c 100644
--- a/src/tools/clippy/tests/ui/drop_forget_copy.stderr
+++ b/src/tools/clippy/tests/ui/drop_forget_copy.stderr
@@ -4,12 +4,12 @@ error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a
LL | drop(s1);
| ^^^^^^^^
|
- = note: `-D clippy::drop-copy` implied by `-D warnings`
note: argument has type `SomeStruct`
--> $DIR/drop_forget_copy.rs:33:10
|
LL | drop(s1);
| ^^
+ = note: `-D clippy::drop-copy` implied by `-D warnings`
error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
--> $DIR/drop_forget_copy.rs:34:5
@@ -41,12 +41,12 @@ error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetti
LL | forget(s1);
| ^^^^^^^^^^
|
- = note: `-D clippy::forget-copy` implied by `-D warnings`
note: argument has type `SomeStruct`
--> $DIR/drop_forget_copy.rs:39:12
|
LL | forget(s1);
| ^^
+ = note: `-D clippy::forget-copy` implied by `-D warnings`
error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact
--> $DIR/drop_forget_copy.rs:40:5
@@ -72,5 +72,41 @@ note: argument has type `SomeStruct`
LL | forget(s4);
| ^^
-error: aborting due to 6 previous errors
+error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
+ --> $DIR/drop_forget_copy.rs:80:13
+ |
+LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block
+ | ^^^^^^^^^^^^^^^^^^^^^
+ |
+note: argument has type `i32`
+ --> $DIR/drop_forget_copy.rs:80:18
+ |
+LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block
+ | ^^^^^^^^^^^^^^^
+
+error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
+ --> $DIR/drop_forget_copy.rs:82:14
+ |
+LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
+ | ^^^^^^^^^^^^^^^^^^^^^
+ |
+note: argument has type `i32`
+ --> $DIR/drop_forget_copy.rs:82:19
+ |
+LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm`
+ | ^^^^^^^^^^^^^^^
+
+error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact
+ --> $DIR/drop_forget_copy.rs:83:14
+ |
+LL | 4 => drop(2), // Lint, not a fn/method call
+ | ^^^^^^^
+ |
+note: argument has type `i32`
+ --> $DIR/drop_forget_copy.rs:83:19
+ |
+LL | 4 => drop(2), // Lint, not a fn/method call
+ | ^
+
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/drop_non_drop.stderr b/src/tools/clippy/tests/ui/drop_non_drop.stderr
index 30121033d..b86057c0c 100644
--- a/src/tools/clippy/tests/ui/drop_non_drop.stderr
+++ b/src/tools/clippy/tests/ui/drop_non_drop.stderr
@@ -4,12 +4,12 @@ error: call to `std::mem::drop` with a value that does not implement `Drop`. Dro
LL | drop(Foo);
| ^^^^^^^^^
|
- = note: `-D clippy::drop-non-drop` implied by `-D warnings`
note: argument has type `main::Foo`
--> $DIR/drop_non_drop.rs:22:10
|
LL | drop(Foo);
| ^^^
+ = note: `-D clippy::drop-non-drop` implied by `-D warnings`
error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
--> $DIR/drop_non_drop.rs:37:5
diff --git a/src/tools/clippy/tests/ui/drop_ref.stderr b/src/tools/clippy/tests/ui/drop_ref.stderr
index 531849f06..4743cf79b 100644
--- a/src/tools/clippy/tests/ui/drop_ref.stderr
+++ b/src/tools/clippy/tests/ui/drop_ref.stderr
@@ -4,12 +4,12 @@ error: calls to `std::mem::drop` with a reference instead of an owned value. Dro
LL | drop(&SomeStruct);
| ^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::drop-ref` implied by `-D warnings`
note: argument has type `&SomeStruct`
--> $DIR/drop_ref.rs:11:10
|
LL | drop(&SomeStruct);
| ^^^^^^^^^^^
+ = note: `-D clippy::drop-ref` implied by `-D warnings`
error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing
--> $DIR/drop_ref.rs:14:5
diff --git a/src/tools/clippy/tests/ui/else_if_without_else.stderr b/src/tools/clippy/tests/ui/else_if_without_else.stderr
index 6f47658cf..90ccfb4fa 100644
--- a/src/tools/clippy/tests/ui/else_if_without_else.stderr
+++ b/src/tools/clippy/tests/ui/else_if_without_else.stderr
@@ -8,8 +8,8 @@ LL | | println!("else if");
LL | | }
| |_____^
|
- = note: `-D clippy::else-if-without-else` implied by `-D warnings`
= help: add an `else` block here
+ = note: `-D clippy::else-if-without-else` implied by `-D warnings`
error: `if` expression with an `else if`, but without a final `else`
--> $DIR/else_if_without_else.rs:54:12
diff --git a/src/tools/clippy/tests/ui/empty_enum.stderr b/src/tools/clippy/tests/ui/empty_enum.stderr
index 7125e5f60..0d9aa5818 100644
--- a/src/tools/clippy/tests/ui/empty_enum.stderr
+++ b/src/tools/clippy/tests/ui/empty_enum.stderr
@@ -4,8 +4,8 @@ error: enum with no variants
LL | enum Empty {}
| ^^^^^^^^^^^^^
|
- = note: `-D clippy::empty-enum` implied by `-D warnings`
= help: consider using the uninhabited type `!` (never type) or a wrapper around it to introduce a type which can't be instantiated
+ = note: `-D clippy::empty-enum` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/empty_loop.stderr b/src/tools/clippy/tests/ui/empty_loop.stderr
index 555f3d3d8..760241233 100644
--- a/src/tools/clippy/tests/ui/empty_loop.stderr
+++ b/src/tools/clippy/tests/ui/empty_loop.stderr
@@ -4,8 +4,8 @@ error: empty `loop {}` wastes CPU cycles
LL | loop {}
| ^^^^^^^
|
- = note: `-D clippy::empty-loop` implied by `-D warnings`
= help: you should either use `panic!()` or add `std::thread::sleep(..);` to the loop body
+ = note: `-D clippy::empty-loop` implied by `-D warnings`
error: empty `loop {}` wastes CPU cycles
--> $DIR/empty_loop.rs:11:9
diff --git a/src/tools/clippy/tests/ui/empty_loop_no_std.stderr b/src/tools/clippy/tests/ui/empty_loop_no_std.stderr
index 5ded35a6f..71af64f49 100644
--- a/src/tools/clippy/tests/ui/empty_loop_no_std.stderr
+++ b/src/tools/clippy/tests/ui/empty_loop_no_std.stderr
@@ -4,8 +4,8 @@ error: empty `loop {}` wastes CPU cycles
LL | loop {}
| ^^^^^^^
|
- = note: `-D clippy::empty-loop` implied by `-D warnings`
= help: you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body
+ = note: `-D clippy::empty-loop` implied by `-D warnings`
error: empty `loop {}` wastes CPU cycles
--> $DIR/empty_loop_no_std.rs:25:5
diff --git a/src/tools/clippy/tests/ui/entry.fixed b/src/tools/clippy/tests/ui/entry.fixed
index e43635abc..79c29c04e 100644
--- a/src/tools/clippy/tests/ui/entry.fixed
+++ b/src/tools/clippy/tests/ui/entry.fixed
@@ -1,3 +1,4 @@
+// needs-asm-support
// run-rustfix
#![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
diff --git a/src/tools/clippy/tests/ui/entry.rs b/src/tools/clippy/tests/ui/entry.rs
index d999b3b7d..2d7985457 100644
--- a/src/tools/clippy/tests/ui/entry.rs
+++ b/src/tools/clippy/tests/ui/entry.rs
@@ -1,3 +1,4 @@
+// needs-asm-support
// run-rustfix
#![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
diff --git a/src/tools/clippy/tests/ui/entry.stderr b/src/tools/clippy/tests/ui/entry.stderr
index 2ef996652..2c4c49d25 100644
--- a/src/tools/clippy/tests/ui/entry.stderr
+++ b/src/tools/clippy/tests/ui/entry.stderr
@@ -1,5 +1,5 @@
error: usage of `contains_key` followed by `insert` on a `HashMap`
- --> $DIR/entry.rs:24:5
+ --> $DIR/entry.rs:25:5
|
LL | / if !m.contains_key(&k) {
LL | | m.insert(k, v);
@@ -9,7 +9,7 @@ LL | | }
= note: `-D clippy::map-entry` implied by `-D warnings`
error: usage of `contains_key` followed by `insert` on a `HashMap`
- --> $DIR/entry.rs:29:5
+ --> $DIR/entry.rs:30:5
|
LL | / if !m.contains_key(&k) {
LL | | if true {
@@ -32,7 +32,7 @@ LL + });
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
- --> $DIR/entry.rs:38:5
+ --> $DIR/entry.rs:39:5
|
LL | / if !m.contains_key(&k) {
LL | | if true {
@@ -55,7 +55,7 @@ LL + });
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
- --> $DIR/entry.rs:47:5
+ --> $DIR/entry.rs:48:5
|
LL | / if !m.contains_key(&k) {
LL | | if true {
@@ -79,7 +79,7 @@ LL + }
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
- --> $DIR/entry.rs:57:5
+ --> $DIR/entry.rs:58:5
|
LL | / if !m.contains_key(&k) {
LL | | foo();
@@ -96,7 +96,7 @@ LL + });
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
- --> $DIR/entry.rs:63:5
+ --> $DIR/entry.rs:64:5
|
LL | / if !m.contains_key(&k) {
LL | | match 0 {
@@ -122,7 +122,7 @@ LL + });
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
- --> $DIR/entry.rs:75:5
+ --> $DIR/entry.rs:76:5
|
LL | / if !m.contains_key(&k) {
LL | | match 0 {
@@ -146,7 +146,7 @@ LL + }
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
- --> $DIR/entry.rs:85:5
+ --> $DIR/entry.rs:86:5
|
LL | / if !m.contains_key(&k) {
LL | | foo();
@@ -187,7 +187,7 @@ LL + });
|
error: usage of `contains_key` followed by `insert` on a `HashMap`
- --> $DIR/entry.rs:119:5
+ --> $DIR/entry.rs:120:5
|
LL | / if !m.contains_key(&m!(k)) {
LL | | m.insert(m!(k), m!(v));
@@ -195,7 +195,7 @@ LL | | }
| |_____^ help: try this: `m.entry(m!(k)).or_insert_with(|| m!(v));`
error: usage of `contains_key` followed by `insert` on a `HashMap`
- --> $DIR/entry.rs:151:5
+ --> $DIR/entry.rs:152:5
|
LL | / if !m.contains_key(&k) {
LL | | let x = (String::new(), String::new());
diff --git a/src/tools/clippy/tests/ui/eprint_with_newline.rs b/src/tools/clippy/tests/ui/eprint_with_newline.rs
index 8df32649a..de5e121be 100644
--- a/src/tools/clippy/tests/ui/eprint_with_newline.rs
+++ b/src/tools/clippy/tests/ui/eprint_with_newline.rs
@@ -45,5 +45,13 @@ fn main() {
eprint!("\r\n");
eprint!("foo\r\n");
eprint!("\\r\n"); //~ ERROR
- eprint!("foo\rbar\n") // ~ ERROR
+ eprint!("foo\rbar\n");
+
+ // Ignore expanded format strings
+ macro_rules! newline {
+ () => {
+ "\n"
+ };
+ }
+ eprint!(newline!());
}
diff --git a/src/tools/clippy/tests/ui/eprint_with_newline.stderr b/src/tools/clippy/tests/ui/eprint_with_newline.stderr
index f137787bf..0eefb9f0c 100644
--- a/src/tools/clippy/tests/ui/eprint_with_newline.stderr
+++ b/src/tools/clippy/tests/ui/eprint_with_newline.stderr
@@ -83,7 +83,7 @@ LL | | );
help: use `eprintln!` instead
|
LL ~ eprintln!(
-LL ~ ""
+LL ~
|
error: using `eprint!()` with a format string that ends in a single newline
@@ -98,7 +98,7 @@ LL | | );
help: use `eprintln!` instead
|
LL ~ eprintln!(
-LL ~ r""
+LL ~
|
error: using `eprint!()` with a format string that ends in a single newline
@@ -113,17 +113,5 @@ LL - eprint!("/r/n"); //~ ERROR
LL + eprintln!("/r"); //~ ERROR
|
-error: using `eprint!()` with a format string that ends in a single newline
- --> $DIR/eprint_with_newline.rs:48:5
- |
-LL | eprint!("foo/rbar/n") // ~ ERROR
- | ^^^^^^^^^^^^^^^^^^^^^
- |
-help: use `eprintln!` instead
- |
-LL - eprint!("foo/rbar/n") // ~ ERROR
-LL + eprintln!("foo/rbar") // ~ ERROR
- |
-
-error: aborting due to 10 previous errors
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/err_expect.fixed b/src/tools/clippy/tests/ui/err_expect.fixed
index 7e18d70ba..3bac738ac 100644
--- a/src/tools/clippy/tests/ui/err_expect.fixed
+++ b/src/tools/clippy/tests/ui/err_expect.fixed
@@ -1,5 +1,8 @@
// run-rustfix
+#![feature(custom_inner_attributes)]
+#![allow(unused)]
+
struct MyTypeNonDebug;
#[derive(Debug)]
@@ -12,3 +15,17 @@ fn main() {
let test_non_debug: Result<MyTypeNonDebug, u32> = Ok(MyTypeNonDebug);
test_non_debug.err().expect("Testing non debug type");
}
+
+fn msrv_1_16() {
+ #![clippy::msrv = "1.16"]
+
+ let x: Result<u32, &str> = Ok(16);
+ x.err().expect("16");
+}
+
+fn msrv_1_17() {
+ #![clippy::msrv = "1.17"]
+
+ let x: Result<u32, &str> = Ok(17);
+ x.expect_err("17");
+}
diff --git a/src/tools/clippy/tests/ui/err_expect.rs b/src/tools/clippy/tests/ui/err_expect.rs
index bf8c3c9fb..6e7c47d9a 100644
--- a/src/tools/clippy/tests/ui/err_expect.rs
+++ b/src/tools/clippy/tests/ui/err_expect.rs
@@ -1,5 +1,8 @@
// run-rustfix
+#![feature(custom_inner_attributes)]
+#![allow(unused)]
+
struct MyTypeNonDebug;
#[derive(Debug)]
@@ -12,3 +15,17 @@ fn main() {
let test_non_debug: Result<MyTypeNonDebug, u32> = Ok(MyTypeNonDebug);
test_non_debug.err().expect("Testing non debug type");
}
+
+fn msrv_1_16() {
+ #![clippy::msrv = "1.16"]
+
+ let x: Result<u32, &str> = Ok(16);
+ x.err().expect("16");
+}
+
+fn msrv_1_17() {
+ #![clippy::msrv = "1.17"]
+
+ let x: Result<u32, &str> = Ok(17);
+ x.err().expect("17");
+}
diff --git a/src/tools/clippy/tests/ui/err_expect.stderr b/src/tools/clippy/tests/ui/err_expect.stderr
index ffd97e00a..91a6cf8de 100644
--- a/src/tools/clippy/tests/ui/err_expect.stderr
+++ b/src/tools/clippy/tests/ui/err_expect.stderr
@@ -1,10 +1,16 @@
error: called `.err().expect()` on a `Result` value
- --> $DIR/err_expect.rs:10:16
+ --> $DIR/err_expect.rs:13:16
|
LL | test_debug.err().expect("Testing debug type");
| ^^^^^^^^^^^^ help: try: `expect_err`
|
= note: `-D clippy::err-expect` implied by `-D warnings`
-error: aborting due to previous error
+error: called `.err().expect()` on a `Result` value
+ --> $DIR/err_expect.rs:30:7
+ |
+LL | x.err().expect("17");
+ | ^^^^^^^^^^^^ help: try: `expect_err`
+
+error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/eta.fixed b/src/tools/clippy/tests/ui/eta.fixed
index f8d559bf2..a9cc80aaa 100644
--- a/src/tools/clippy/tests/ui/eta.fixed
+++ b/src/tools/clippy/tests/ui/eta.fixed
@@ -1,14 +1,14 @@
// run-rustfix
-
+#![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)]
+#![allow(unused)]
#![allow(
- unused,
- clippy::no_effect,
- clippy::redundant_closure_call,
+ clippy::needless_borrow,
clippy::needless_pass_by_value,
+ clippy::no_effect,
clippy::option_map_unit_fn,
- clippy::needless_borrow
+ clippy::redundant_closure_call,
+ clippy::uninlined_format_args
)]
-#![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)]
use std::path::{Path, PathBuf};
@@ -303,3 +303,16 @@ fn not_general_enough() {
fn f(_: impl FnMut(&Path) -> std::io::Result<()>) {}
f(|path| std::fs::remove_file(path));
}
+
+// https://github.com/rust-lang/rust-clippy/issues/9369
+pub fn mutable_impl_fn_mut(mut f: impl FnMut(), mut f_used_once: impl FnMut()) -> impl FnMut() {
+ fn takes_fn_mut(_: impl FnMut()) {}
+ takes_fn_mut(&mut f);
+
+ fn takes_fn_once(_: impl FnOnce()) {}
+ takes_fn_once(&mut f);
+
+ f();
+
+ move || takes_fn_mut(&mut f_used_once)
+}
diff --git a/src/tools/clippy/tests/ui/eta.rs b/src/tools/clippy/tests/ui/eta.rs
index f0fb55a1e..cc99906cc 100644
--- a/src/tools/clippy/tests/ui/eta.rs
+++ b/src/tools/clippy/tests/ui/eta.rs
@@ -1,14 +1,14 @@
// run-rustfix
-
+#![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)]
+#![allow(unused)]
#![allow(
- unused,
- clippy::no_effect,
- clippy::redundant_closure_call,
+ clippy::needless_borrow,
clippy::needless_pass_by_value,
+ clippy::no_effect,
clippy::option_map_unit_fn,
- clippy::needless_borrow
+ clippy::redundant_closure_call,
+ clippy::uninlined_format_args
)]
-#![warn(clippy::redundant_closure, clippy::redundant_closure_for_method_calls)]
use std::path::{Path, PathBuf};
@@ -303,3 +303,16 @@ fn not_general_enough() {
fn f(_: impl FnMut(&Path) -> std::io::Result<()>) {}
f(|path| std::fs::remove_file(path));
}
+
+// https://github.com/rust-lang/rust-clippy/issues/9369
+pub fn mutable_impl_fn_mut(mut f: impl FnMut(), mut f_used_once: impl FnMut()) -> impl FnMut() {
+ fn takes_fn_mut(_: impl FnMut()) {}
+ takes_fn_mut(|| f());
+
+ fn takes_fn_once(_: impl FnOnce()) {}
+ takes_fn_once(|| f());
+
+ f();
+
+ move || takes_fn_mut(|| f_used_once())
+}
diff --git a/src/tools/clippy/tests/ui/eta.stderr b/src/tools/clippy/tests/ui/eta.stderr
index bf2e97e74..434706b7e 100644
--- a/src/tools/clippy/tests/ui/eta.stderr
+++ b/src/tools/clippy/tests/ui/eta.stderr
@@ -116,5 +116,23 @@ error: redundant closure
LL | Some(1).map(|n| in_loop(n));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop`
-error: aborting due to 19 previous errors
+error: redundant closure
+ --> $DIR/eta.rs:310:18
+ |
+LL | takes_fn_mut(|| f());
+ | ^^^^^^ help: replace the closure with the function itself: `&mut f`
+
+error: redundant closure
+ --> $DIR/eta.rs:313:19
+ |
+LL | takes_fn_once(|| f());
+ | ^^^^^^ help: replace the closure with the function itself: `&mut f`
+
+error: redundant closure
+ --> $DIR/eta.rs:317:26
+ |
+LL | move || takes_fn_mut(|| f_used_once())
+ | ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once`
+
+error: aborting due to 22 previous errors
diff --git a/src/tools/clippy/tests/ui/expect.stderr b/src/tools/clippy/tests/ui/expect.stderr
index 904c09046..f6738865c 100644
--- a/src/tools/clippy/tests/ui/expect.stderr
+++ b/src/tools/clippy/tests/ui/expect.stderr
@@ -4,8 +4,8 @@ error: used `expect()` on `an Option` value
LL | let _ = opt.expect("");
| ^^^^^^^^^^^^^^
|
- = note: `-D clippy::expect-used` implied by `-D warnings`
= help: if this value is `None`, it will panic
+ = note: `-D clippy::expect-used` implied by `-D warnings`
error: used `expect()` on `a Result` value
--> $DIR/expect.rs:10:13
diff --git a/src/tools/clippy/tests/ui/expect_fun_call.fixed b/src/tools/clippy/tests/ui/expect_fun_call.fixed
index 53e45d28b..15172ae34 100644
--- a/src/tools/clippy/tests/ui/expect_fun_call.fixed
+++ b/src/tools/clippy/tests/ui/expect_fun_call.fixed
@@ -1,7 +1,6 @@
// run-rustfix
-
#![warn(clippy::expect_fun_call)]
-#![allow(clippy::to_string_in_format_args)]
+#![allow(clippy::to_string_in_format_args, clippy::uninlined_format_args)]
/// Checks implementation of the `EXPECT_FUN_CALL` lint
@@ -101,4 +100,10 @@ fn main() {
let opt_ref = &opt;
opt_ref.unwrap_or_else(|| panic!("{:?}", opt_ref));
}
+
+ let format_capture: Option<i32> = None;
+ format_capture.unwrap_or_else(|| panic!("{error_code}"));
+
+ let format_capture_and_value: Option<i32> = None;
+ format_capture_and_value.unwrap_or_else(|| panic!("{error_code}, {}", 1));
}
diff --git a/src/tools/clippy/tests/ui/expect_fun_call.rs b/src/tools/clippy/tests/ui/expect_fun_call.rs
index 22e530b80..0f448d004 100644
--- a/src/tools/clippy/tests/ui/expect_fun_call.rs
+++ b/src/tools/clippy/tests/ui/expect_fun_call.rs
@@ -1,7 +1,6 @@
// run-rustfix
-
#![warn(clippy::expect_fun_call)]
-#![allow(clippy::to_string_in_format_args)]
+#![allow(clippy::to_string_in_format_args, clippy::uninlined_format_args)]
/// Checks implementation of the `EXPECT_FUN_CALL` lint
@@ -101,4 +100,10 @@ fn main() {
let opt_ref = &opt;
opt_ref.expect(&format!("{:?}", opt_ref));
}
+
+ let format_capture: Option<i32> = None;
+ format_capture.expect(&format!("{error_code}"));
+
+ let format_capture_and_value: Option<i32> = None;
+ format_capture_and_value.expect(&format!("{error_code}, {}", 1));
}
diff --git a/src/tools/clippy/tests/ui/expect_fun_call.stderr b/src/tools/clippy/tests/ui/expect_fun_call.stderr
index aca15935f..cb55e32ae 100644
--- a/src/tools/clippy/tests/ui/expect_fun_call.stderr
+++ b/src/tools/clippy/tests/ui/expect_fun_call.stderr
@@ -1,5 +1,5 @@
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:35:26
+ --> $DIR/expect_fun_call.rs:34:26
|
LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
@@ -7,76 +7,88 @@ LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code
= note: `-D clippy::expect-fun-call` implied by `-D warnings`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:38:26
+ --> $DIR/expect_fun_call.rs:37:26
|
LL | with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:41:37
+ --> $DIR/expect_fun_call.rs:40:37
|
LL | with_none_and_format_with_macro.expect(format!("Error {}: fake error", one!()).as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", one!()))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:51:25
+ --> $DIR/expect_fun_call.rs:50:25
|
LL | with_err_and_format.expect(&format!("Error {}: fake error", error_code));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:54:25
+ --> $DIR/expect_fun_call.rs:53:25
|
LL | with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:66:17
+ --> $DIR/expect_fun_call.rs:65:17
|
LL | Some("foo").expect(format!("{} {}", 1, 2).as_ref());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{} {}", 1, 2))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:87:21
+ --> $DIR/expect_fun_call.rs:86:21
|
LL | Some("foo").expect(&get_string());
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:88:21
+ --> $DIR/expect_fun_call.rs:87:21
|
LL | Some("foo").expect(get_string().as_ref());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:89:21
+ --> $DIR/expect_fun_call.rs:88:21
|
LL | Some("foo").expect(get_string().as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:91:21
+ --> $DIR/expect_fun_call.rs:90:21
|
LL | Some("foo").expect(get_static_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_static_str()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:92:21
+ --> $DIR/expect_fun_call.rs:91:21
|
LL | Some("foo").expect(get_non_static_str(&0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:96:16
+ --> $DIR/expect_fun_call.rs:95:16
|
LL | Some(true).expect(&format!("key {}, {}", 1, 2));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:102:17
+ --> $DIR/expect_fun_call.rs:101:17
|
LL | opt_ref.expect(&format!("{:?}", opt_ref));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{:?}", opt_ref))`
-error: aborting due to 13 previous errors
+error: use of `expect` followed by a function call
+ --> $DIR/expect_fun_call.rs:105:20
+ |
+LL | format_capture.expect(&format!("{error_code}"));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{error_code}"))`
+
+error: use of `expect` followed by a function call
+ --> $DIR/expect_fun_call.rs:108:30
+ |
+LL | format_capture_and_value.expect(&format!("{error_code}, {}", 1));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{error_code}, {}", 1))`
+
+error: aborting due to 15 previous errors
diff --git a/src/tools/clippy/tests/ui/explicit_counter_loop.rs b/src/tools/clippy/tests/ui/explicit_counter_loop.rs
index aa966761f..6eddc01e2 100644
--- a/src/tools/clippy/tests/ui/explicit_counter_loop.rs
+++ b/src/tools/clippy/tests/ui/explicit_counter_loop.rs
@@ -1,4 +1,5 @@
#![warn(clippy::explicit_counter_loop)]
+#![allow(clippy::uninlined_format_args)]
fn main() {
let mut vec = vec![1, 2, 3, 4];
diff --git a/src/tools/clippy/tests/ui/explicit_counter_loop.stderr b/src/tools/clippy/tests/ui/explicit_counter_loop.stderr
index f9f8407d5..d3f3c626b 100644
--- a/src/tools/clippy/tests/ui/explicit_counter_loop.stderr
+++ b/src/tools/clippy/tests/ui/explicit_counter_loop.stderr
@@ -1,5 +1,5 @@
error: the variable `_index` is used as a loop counter
- --> $DIR/explicit_counter_loop.rs:6:5
+ --> $DIR/explicit_counter_loop.rs:7:5
|
LL | for _v in &vec {
| ^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter().enumerate()`
@@ -7,49 +7,49 @@ LL | for _v in &vec {
= note: `-D clippy::explicit-counter-loop` implied by `-D warnings`
error: the variable `_index` is used as a loop counter
- --> $DIR/explicit_counter_loop.rs:12:5
+ --> $DIR/explicit_counter_loop.rs:13:5
|
LL | for _v in &vec {
| ^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter().enumerate()`
error: the variable `_index` is used as a loop counter
- --> $DIR/explicit_counter_loop.rs:17:5
+ --> $DIR/explicit_counter_loop.rs:18:5
|
LL | for _v in &mut vec {
| ^^^^^^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.iter_mut().enumerate()`
error: the variable `_index` is used as a loop counter
- --> $DIR/explicit_counter_loop.rs:22:5
+ --> $DIR/explicit_counter_loop.rs:23:5
|
LL | for _v in vec {
| ^^^^^^^^^^^^^ help: consider using: `for (_index, _v) in vec.into_iter().enumerate()`
error: the variable `count` is used as a loop counter
- --> $DIR/explicit_counter_loop.rs:61:9
+ --> $DIR/explicit_counter_loop.rs:62:9
|
LL | for ch in text.chars() {
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()`
error: the variable `count` is used as a loop counter
- --> $DIR/explicit_counter_loop.rs:72:9
+ --> $DIR/explicit_counter_loop.rs:73:9
|
LL | for ch in text.chars() {
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `for (count, ch) in text.chars().enumerate()`
error: the variable `count` is used as a loop counter
- --> $DIR/explicit_counter_loop.rs:130:9
+ --> $DIR/explicit_counter_loop.rs:131:9
|
LL | for _i in 3..10 {
| ^^^^^^^^^^^^^^^ help: consider using: `for (count, _i) in (3..10).enumerate()`
error: the variable `idx_usize` is used as a loop counter
- --> $DIR/explicit_counter_loop.rs:170:9
+ --> $DIR/explicit_counter_loop.rs:171:9
|
LL | for _item in slice {
| ^^^^^^^^^^^^^^^^^^ help: consider using: `for (idx_usize, _item) in slice.iter().enumerate()`
error: the variable `idx_u32` is used as a loop counter
- --> $DIR/explicit_counter_loop.rs:182:9
+ --> $DIR/explicit_counter_loop.rs:183:9
|
LL | for _item in slice {
| ^^^^^^^^^^^^^^^^^^ help: consider using: `for (idx_u32, _item) in (0_u32..).zip(slice.iter())`
diff --git a/src/tools/clippy/tests/ui/explicit_deref_methods.fixed b/src/tools/clippy/tests/ui/explicit_deref_methods.fixed
index 523cae183..6d32bbece 100644
--- a/src/tools/clippy/tests/ui/explicit_deref_methods.fixed
+++ b/src/tools/clippy/tests/ui/explicit_deref_methods.fixed
@@ -1,13 +1,13 @@
// run-rustfix
-
+#![warn(clippy::explicit_deref_methods)]
+#![allow(unused_variables)]
#![allow(
- unused_variables,
+ clippy::borrow_deref_ref,
clippy::clone_double_ref,
+ clippy::explicit_auto_deref,
clippy::needless_borrow,
- clippy::borrow_deref_ref,
- clippy::explicit_auto_deref
+ clippy::uninlined_format_args
)]
-#![warn(clippy::explicit_deref_methods)]
use std::ops::{Deref, DerefMut};
diff --git a/src/tools/clippy/tests/ui/explicit_deref_methods.rs b/src/tools/clippy/tests/ui/explicit_deref_methods.rs
index 0bbc1ae57..779909e42 100644
--- a/src/tools/clippy/tests/ui/explicit_deref_methods.rs
+++ b/src/tools/clippy/tests/ui/explicit_deref_methods.rs
@@ -1,13 +1,13 @@
// run-rustfix
-
+#![warn(clippy::explicit_deref_methods)]
+#![allow(unused_variables)]
#![allow(
- unused_variables,
+ clippy::borrow_deref_ref,
clippy::clone_double_ref,
+ clippy::explicit_auto_deref,
clippy::needless_borrow,
- clippy::borrow_deref_ref,
- clippy::explicit_auto_deref
+ clippy::uninlined_format_args
)]
-#![warn(clippy::explicit_deref_methods)]
use std::ops::{Deref, DerefMut};
diff --git a/src/tools/clippy/tests/ui/explicit_write.fixed b/src/tools/clippy/tests/ui/explicit_write.fixed
index 74d0e5290..862c3fea9 100644
--- a/src/tools/clippy/tests/ui/explicit_write.fixed
+++ b/src/tools/clippy/tests/ui/explicit_write.fixed
@@ -1,6 +1,7 @@
// run-rustfix
-#![allow(unused_imports)]
#![warn(clippy::explicit_write)]
+#![allow(unused_imports)]
+#![allow(clippy::uninlined_format_args)]
fn stdout() -> String {
String::new()
@@ -36,6 +37,8 @@ fn main() {
eprintln!("with {} {}", 2, value);
eprintln!("with {value}");
eprintln!("macro arg {}", one!());
+ let width = 2;
+ eprintln!("{:w$}", value, w = width);
}
// these should not warn, different destination
{
diff --git a/src/tools/clippy/tests/ui/explicit_write.rs b/src/tools/clippy/tests/ui/explicit_write.rs
index e7a698d3e..41d7c2255 100644
--- a/src/tools/clippy/tests/ui/explicit_write.rs
+++ b/src/tools/clippy/tests/ui/explicit_write.rs
@@ -1,6 +1,7 @@
// run-rustfix
-#![allow(unused_imports)]
#![warn(clippy::explicit_write)]
+#![allow(unused_imports)]
+#![allow(clippy::uninlined_format_args)]
fn stdout() -> String {
String::new()
@@ -36,6 +37,8 @@ fn main() {
writeln!(std::io::stderr(), "with {} {}", 2, value).unwrap();
writeln!(std::io::stderr(), "with {value}").unwrap();
writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap();
+ let width = 2;
+ writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap();
}
// these should not warn, different destination
{
diff --git a/src/tools/clippy/tests/ui/explicit_write.stderr b/src/tools/clippy/tests/ui/explicit_write.stderr
index 29ae0cdec..457e9c627 100644
--- a/src/tools/clippy/tests/ui/explicit_write.stderr
+++ b/src/tools/clippy/tests/ui/explicit_write.stderr
@@ -1,5 +1,5 @@
error: use of `write!(stdout(), ...).unwrap()`
- --> $DIR/explicit_write.rs:23:9
+ --> $DIR/explicit_write.rs:24:9
|
LL | write!(std::io::stdout(), "test").unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")`
@@ -7,70 +7,76 @@ LL | write!(std::io::stdout(), "test").unwrap();
= note: `-D clippy::explicit-write` implied by `-D warnings`
error: use of `write!(stderr(), ...).unwrap()`
- --> $DIR/explicit_write.rs:24:9
+ --> $DIR/explicit_write.rs:25:9
|
LL | write!(std::io::stderr(), "test").unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")`
error: use of `writeln!(stdout(), ...).unwrap()`
- --> $DIR/explicit_write.rs:25:9
+ --> $DIR/explicit_write.rs:26:9
|
LL | writeln!(std::io::stdout(), "test").unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test")`
error: use of `writeln!(stderr(), ...).unwrap()`
- --> $DIR/explicit_write.rs:26:9
+ --> $DIR/explicit_write.rs:27:9
|
LL | writeln!(std::io::stderr(), "test").unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test")`
error: use of `stdout().write_fmt(...).unwrap()`
- --> $DIR/explicit_write.rs:27:9
+ --> $DIR/explicit_write.rs:28:9
|
LL | std::io::stdout().write_fmt(format_args!("test")).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")`
error: use of `stderr().write_fmt(...).unwrap()`
- --> $DIR/explicit_write.rs:28:9
+ --> $DIR/explicit_write.rs:29:9
|
LL | std::io::stderr().write_fmt(format_args!("test")).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")`
error: use of `writeln!(stdout(), ...).unwrap()`
- --> $DIR/explicit_write.rs:31:9
+ --> $DIR/explicit_write.rs:32:9
|
LL | writeln!(std::io::stdout(), "test/ntest").unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test/ntest")`
error: use of `writeln!(stderr(), ...).unwrap()`
- --> $DIR/explicit_write.rs:32:9
+ --> $DIR/explicit_write.rs:33:9
|
LL | writeln!(std::io::stderr(), "test/ntest").unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test/ntest")`
error: use of `writeln!(stderr(), ...).unwrap()`
- --> $DIR/explicit_write.rs:35:9
+ --> $DIR/explicit_write.rs:36:9
|
LL | writeln!(std::io::stderr(), "with {}", value).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("with {}", value)`
error: use of `writeln!(stderr(), ...).unwrap()`
- --> $DIR/explicit_write.rs:36:9
+ --> $DIR/explicit_write.rs:37:9
|
LL | writeln!(std::io::stderr(), "with {} {}", 2, value).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("with {} {}", 2, value)`
error: use of `writeln!(stderr(), ...).unwrap()`
- --> $DIR/explicit_write.rs:37:9
+ --> $DIR/explicit_write.rs:38:9
|
LL | writeln!(std::io::stderr(), "with {value}").unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("with {value}")`
error: use of `writeln!(stderr(), ...).unwrap()`
- --> $DIR/explicit_write.rs:38:9
+ --> $DIR/explicit_write.rs:39:9
|
LL | writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("macro arg {}", one!())`
-error: aborting due to 12 previous errors
+error: use of `writeln!(stderr(), ...).unwrap()`
+ --> $DIR/explicit_write.rs:41:9
+ |
+LL | writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("{:w$}", value, w = width)`
+
+error: aborting due to 13 previous errors
diff --git a/src/tools/clippy/tests/ui/fallible_impl_from.rs b/src/tools/clippy/tests/ui/fallible_impl_from.rs
index 5d5af4e46..fb6e8ec70 100644
--- a/src/tools/clippy/tests/ui/fallible_impl_from.rs
+++ b/src/tools/clippy/tests/ui/fallible_impl_from.rs
@@ -1,4 +1,5 @@
#![deny(clippy::fallible_impl_from)]
+#![allow(clippy::uninlined_format_args)]
// docs example
struct Foo(i32);
diff --git a/src/tools/clippy/tests/ui/fallible_impl_from.stderr b/src/tools/clippy/tests/ui/fallible_impl_from.stderr
index d637dbce5..21761484f 100644
--- a/src/tools/clippy/tests/ui/fallible_impl_from.stderr
+++ b/src/tools/clippy/tests/ui/fallible_impl_from.stderr
@@ -1,5 +1,5 @@
error: consider implementing `TryFrom` instead
- --> $DIR/fallible_impl_from.rs:5:1
+ --> $DIR/fallible_impl_from.rs:6:1
|
LL | / impl From<String> for Foo {
LL | | fn from(s: String) -> Self {
@@ -8,20 +8,20 @@ LL | | }
LL | | }
| |_^
|
-note: the lint level is defined here
- --> $DIR/fallible_impl_from.rs:1:9
- |
-LL | #![deny(clippy::fallible_impl_from)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
note: potential failure(s)
- --> $DIR/fallible_impl_from.rs:7:13
+ --> $DIR/fallible_impl_from.rs:8:13
|
LL | Foo(s.parse().unwrap())
| ^^^^^^^^^^^^^^^^^^
+note: the lint level is defined here
+ --> $DIR/fallible_impl_from.rs:1:9
+ |
+LL | #![deny(clippy::fallible_impl_from)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: consider implementing `TryFrom` instead
- --> $DIR/fallible_impl_from.rs:26:1
+ --> $DIR/fallible_impl_from.rs:27:1
|
LL | / impl From<usize> for Invalid {
LL | | fn from(i: usize) -> Invalid {
@@ -34,14 +34,14 @@ LL | | }
|
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
note: potential failure(s)
- --> $DIR/fallible_impl_from.rs:29:13
+ --> $DIR/fallible_impl_from.rs:30:13
|
LL | panic!();
| ^^^^^^^^
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error: consider implementing `TryFrom` instead
- --> $DIR/fallible_impl_from.rs:35:1
+ --> $DIR/fallible_impl_from.rs:36:1
|
LL | / impl From<Option<String>> for Invalid {
LL | | fn from(s: Option<String>) -> Invalid {
@@ -54,7 +54,7 @@ LL | | }
|
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
note: potential failure(s)
- --> $DIR/fallible_impl_from.rs:37:17
+ --> $DIR/fallible_impl_from.rs:38:17
|
LL | let s = s.unwrap();
| ^^^^^^^^^^
@@ -68,7 +68,7 @@ LL | panic!("{:?}", s);
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
error: consider implementing `TryFrom` instead
- --> $DIR/fallible_impl_from.rs:53:1
+ --> $DIR/fallible_impl_from.rs:54:1
|
LL | / impl<'a> From<&'a mut <Box<u32> as ProjStrTrait>::ProjString> for Invalid {
LL | | fn from(s: &'a mut <Box<u32> as ProjStrTrait>::ProjString) -> Invalid {
@@ -81,7 +81,7 @@ LL | | }
|
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
note: potential failure(s)
- --> $DIR/fallible_impl_from.rs:55:12
+ --> $DIR/fallible_impl_from.rs:56:12
|
LL | if s.parse::<u32>().ok().unwrap() != 42 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/field_reassign_with_default.stderr b/src/tools/clippy/tests/ui/field_reassign_with_default.stderr
index 3ce4b91a5..710bb66a4 100644
--- a/src/tools/clippy/tests/ui/field_reassign_with_default.stderr
+++ b/src/tools/clippy/tests/ui/field_reassign_with_default.stderr
@@ -4,12 +4,12 @@ error: field assignment outside of initializer for an instance created with Defa
LL | a.i = 42;
| ^^^^^^^^^
|
- = note: `-D clippy::field-reassign-with-default` implied by `-D warnings`
note: consider initializing the variable with `main::A { i: 42, ..Default::default() }` and removing relevant reassignments
--> $DIR/field_reassign_with_default.rs:62:5
|
LL | let mut a: A = Default::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: `-D clippy::field-reassign-with-default` implied by `-D warnings`
error: field assignment outside of initializer for an instance created with Default::default()
--> $DIR/field_reassign_with_default.rs:103:5
diff --git a/src/tools/clippy/tests/ui/filetype_is_file.stderr b/src/tools/clippy/tests/ui/filetype_is_file.stderr
index cd1e3ac37..e51a90d6c 100644
--- a/src/tools/clippy/tests/ui/filetype_is_file.stderr
+++ b/src/tools/clippy/tests/ui/filetype_is_file.stderr
@@ -4,8 +4,8 @@ error: `FileType::is_file()` only covers regular files
LL | if fs::metadata("foo.txt")?.file_type().is_file() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::filetype-is-file` implied by `-D warnings`
= help: use `!FileType::is_dir()` instead
+ = note: `-D clippy::filetype-is-file` implied by `-D warnings`
error: `!FileType::is_file()` only denies regular files
--> $DIR/filetype_is_file.rs:13:8
diff --git a/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed b/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed
index c3992d7e9..41828ddd7 100644
--- a/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed
+++ b/src/tools/clippy/tests/ui/filter_map_next_fixable.fixed
@@ -1,6 +1,8 @@
// run-rustfix
+#![feature(custom_inner_attributes)]
#![warn(clippy::all, clippy::pedantic)]
+#![allow(unused)]
fn main() {
let a = ["1", "lol", "3", "NaN", "5"];
@@ -8,3 +10,17 @@ fn main() {
let element: Option<i32> = a.iter().find_map(|s| s.parse().ok());
assert_eq!(element, Some(1));
}
+
+fn msrv_1_29() {
+ #![clippy::msrv = "1.29"]
+
+ let a = ["1", "lol", "3", "NaN", "5"];
+ let _: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
+}
+
+fn msrv_1_30() {
+ #![clippy::msrv = "1.30"]
+
+ let a = ["1", "lol", "3", "NaN", "5"];
+ let _: Option<i32> = a.iter().find_map(|s| s.parse().ok());
+}
diff --git a/src/tools/clippy/tests/ui/filter_map_next_fixable.rs b/src/tools/clippy/tests/ui/filter_map_next_fixable.rs
index 447219a96..be492a81b 100644
--- a/src/tools/clippy/tests/ui/filter_map_next_fixable.rs
+++ b/src/tools/clippy/tests/ui/filter_map_next_fixable.rs
@@ -1,6 +1,8 @@
// run-rustfix
+#![feature(custom_inner_attributes)]
#![warn(clippy::all, clippy::pedantic)]
+#![allow(unused)]
fn main() {
let a = ["1", "lol", "3", "NaN", "5"];
@@ -8,3 +10,17 @@ fn main() {
let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
assert_eq!(element, Some(1));
}
+
+fn msrv_1_29() {
+ #![clippy::msrv = "1.29"]
+
+ let a = ["1", "lol", "3", "NaN", "5"];
+ let _: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
+}
+
+fn msrv_1_30() {
+ #![clippy::msrv = "1.30"]
+
+ let a = ["1", "lol", "3", "NaN", "5"];
+ let _: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
+}
diff --git a/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr b/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr
index 3bb062ffd..e789efeab 100644
--- a/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr
+++ b/src/tools/clippy/tests/ui/filter_map_next_fixable.stderr
@@ -1,10 +1,16 @@
error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead
- --> $DIR/filter_map_next_fixable.rs:8:32
+ --> $DIR/filter_map_next_fixable.rs:10:32
|
LL | let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `a.iter().find_map(|s| s.parse().ok())`
|
= note: `-D clippy::filter-map-next` implied by `-D warnings`
-error: aborting due to previous error
+error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead
+ --> $DIR/filter_map_next_fixable.rs:25:26
+ |
+LL | let _: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `a.iter().find_map(|s| s.parse().ok())`
+
+error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/float_cmp.stderr b/src/tools/clippy/tests/ui/float_cmp.stderr
index 9cc1f1b75..e3e9f3949 100644
--- a/src/tools/clippy/tests/ui/float_cmp.stderr
+++ b/src/tools/clippy/tests/ui/float_cmp.stderr
@@ -4,8 +4,8 @@ error: strict comparison of `f32` or `f64`
LL | ONE as f64 != 2.0;
| ^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE as f64 - 2.0).abs() > error_margin`
|
- = note: `-D clippy::float-cmp` implied by `-D warnings`
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
+ = note: `-D clippy::float-cmp` implied by `-D warnings`
error: strict comparison of `f32` or `f64`
--> $DIR/float_cmp.rs:62:5
diff --git a/src/tools/clippy/tests/ui/float_cmp_const.stderr b/src/tools/clippy/tests/ui/float_cmp_const.stderr
index d8182cf85..65c45648a 100644
--- a/src/tools/clippy/tests/ui/float_cmp_const.stderr
+++ b/src/tools/clippy/tests/ui/float_cmp_const.stderr
@@ -4,8 +4,8 @@ error: strict comparison of `f32` or `f64` constant
LL | 1f32 == ONE;
| ^^^^^^^^^^^ help: consider comparing them within some margin of error: `(1f32 - ONE).abs() < error_margin`
|
- = note: `-D clippy::float-cmp-const` implied by `-D warnings`
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
+ = note: `-D clippy::float-cmp-const` implied by `-D warnings`
error: strict comparison of `f32` or `f64` constant
--> $DIR/float_cmp_const.rs:17:5
diff --git a/src/tools/clippy/tests/ui/floating_point_exp.fixed b/src/tools/clippy/tests/ui/floating_point_exp.fixed
index c86a502d1..b9e3d89c2 100644
--- a/src/tools/clippy/tests/ui/floating_point_exp.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_exp.fixed
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::imprecise_flops)]
+#![allow(clippy::unnecessary_cast)]
fn main() {
let x = 2f32;
diff --git a/src/tools/clippy/tests/ui/floating_point_exp.rs b/src/tools/clippy/tests/ui/floating_point_exp.rs
index e59589f91..ef008dd9b 100644
--- a/src/tools/clippy/tests/ui/floating_point_exp.rs
+++ b/src/tools/clippy/tests/ui/floating_point_exp.rs
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::imprecise_flops)]
+#![allow(clippy::unnecessary_cast)]
fn main() {
let x = 2f32;
diff --git a/src/tools/clippy/tests/ui/floating_point_exp.stderr b/src/tools/clippy/tests/ui/floating_point_exp.stderr
index f84eede19..b92fae56e 100644
--- a/src/tools/clippy/tests/ui/floating_point_exp.stderr
+++ b/src/tools/clippy/tests/ui/floating_point_exp.stderr
@@ -1,5 +1,5 @@
error: (e.pow(x) - 1) can be computed more accurately
- --> $DIR/floating_point_exp.rs:6:13
+ --> $DIR/floating_point_exp.rs:7:13
|
LL | let _ = x.exp() - 1.0;
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
@@ -7,25 +7,25 @@ LL | let _ = x.exp() - 1.0;
= note: `-D clippy::imprecise-flops` implied by `-D warnings`
error: (e.pow(x) - 1) can be computed more accurately
- --> $DIR/floating_point_exp.rs:7:13
+ --> $DIR/floating_point_exp.rs:8:13
|
LL | let _ = x.exp() - 1.0 + 2.0;
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
error: (e.pow(x) - 1) can be computed more accurately
- --> $DIR/floating_point_exp.rs:8:13
+ --> $DIR/floating_point_exp.rs:9:13
|
LL | let _ = (x as f32).exp() - 1.0 + 2.0;
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).exp_m1()`
error: (e.pow(x) - 1) can be computed more accurately
- --> $DIR/floating_point_exp.rs:14:13
+ --> $DIR/floating_point_exp.rs:15:13
|
LL | let _ = x.exp() - 1.0;
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
error: (e.pow(x) - 1) can be computed more accurately
- --> $DIR/floating_point_exp.rs:15:13
+ --> $DIR/floating_point_exp.rs:16:13
|
LL | let _ = x.exp() - 1.0 + 2.0;
| ^^^^^^^^^^^^^ help: consider using: `x.exp_m1()`
diff --git a/src/tools/clippy/tests/ui/floating_point_log.fixed b/src/tools/clippy/tests/ui/floating_point_log.fixed
index 4def9300b..ee5406461 100644
--- a/src/tools/clippy/tests/ui/floating_point_log.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_log.fixed
@@ -1,5 +1,5 @@
// run-rustfix
-#![allow(dead_code, clippy::double_parens)]
+#![allow(dead_code, clippy::double_parens, clippy::unnecessary_cast)]
#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)]
const TWO: f32 = 2.0;
diff --git a/src/tools/clippy/tests/ui/floating_point_log.rs b/src/tools/clippy/tests/ui/floating_point_log.rs
index 1e04caa7d..0590670a5 100644
--- a/src/tools/clippy/tests/ui/floating_point_log.rs
+++ b/src/tools/clippy/tests/ui/floating_point_log.rs
@@ -1,5 +1,5 @@
// run-rustfix
-#![allow(dead_code, clippy::double_parens)]
+#![allow(dead_code, clippy::double_parens, clippy::unnecessary_cast)]
#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)]
const TWO: f32 = 2.0;
diff --git a/src/tools/clippy/tests/ui/floating_point_logbase.fixed b/src/tools/clippy/tests/ui/floating_point_logbase.fixed
index 936462f94..7347bf72c 100644
--- a/src/tools/clippy/tests/ui/floating_point_logbase.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_logbase.fixed
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::suboptimal_flops)]
+#![allow(clippy::unnecessary_cast)]
fn main() {
let x = 3f32;
diff --git a/src/tools/clippy/tests/ui/floating_point_logbase.rs b/src/tools/clippy/tests/ui/floating_point_logbase.rs
index 0b56fa8fa..ba5b8d406 100644
--- a/src/tools/clippy/tests/ui/floating_point_logbase.rs
+++ b/src/tools/clippy/tests/ui/floating_point_logbase.rs
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::suboptimal_flops)]
+#![allow(clippy::unnecessary_cast)]
fn main() {
let x = 3f32;
diff --git a/src/tools/clippy/tests/ui/floating_point_logbase.stderr b/src/tools/clippy/tests/ui/floating_point_logbase.stderr
index 384e3554c..9d736b5e1 100644
--- a/src/tools/clippy/tests/ui/floating_point_logbase.stderr
+++ b/src/tools/clippy/tests/ui/floating_point_logbase.stderr
@@ -1,5 +1,5 @@
error: log base can be expressed more clearly
- --> $DIR/floating_point_logbase.rs:7:13
+ --> $DIR/floating_point_logbase.rs:8:13
|
LL | let _ = x.ln() / y.ln();
| ^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
@@ -7,25 +7,25 @@ LL | let _ = x.ln() / y.ln();
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
error: log base can be expressed more clearly
- --> $DIR/floating_point_logbase.rs:8:13
+ --> $DIR/floating_point_logbase.rs:9:13
|
LL | let _ = (x as f32).ln() / y.ln();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).log(y)`
error: log base can be expressed more clearly
- --> $DIR/floating_point_logbase.rs:9:13
+ --> $DIR/floating_point_logbase.rs:10:13
|
LL | let _ = x.log2() / y.log2();
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
error: log base can be expressed more clearly
- --> $DIR/floating_point_logbase.rs:10:13
+ --> $DIR/floating_point_logbase.rs:11:13
|
LL | let _ = x.log10() / y.log10();
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
error: log base can be expressed more clearly
- --> $DIR/floating_point_logbase.rs:11:13
+ --> $DIR/floating_point_logbase.rs:12:13
|
LL | let _ = x.log(5f32) / y.log(5f32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.log(y)`
diff --git a/src/tools/clippy/tests/ui/floating_point_mul_add.fixed b/src/tools/clippy/tests/ui/floating_point_mul_add.fixed
index 169ec02f8..d3e536ba3 100644
--- a/src/tools/clippy/tests/ui/floating_point_mul_add.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_mul_add.fixed
@@ -19,7 +19,9 @@ fn main() {
let d: f64 = 0.0001;
let _ = a.mul_add(b, c);
+ let _ = a.mul_add(b, -c);
let _ = a.mul_add(b, c);
+ let _ = a.mul_add(-b, c);
let _ = 2.0f64.mul_add(4.0, a);
let _ = 2.0f64.mul_add(4., a);
diff --git a/src/tools/clippy/tests/ui/floating_point_mul_add.rs b/src/tools/clippy/tests/ui/floating_point_mul_add.rs
index 5338d4fc2..5d4a9e35c 100644
--- a/src/tools/clippy/tests/ui/floating_point_mul_add.rs
+++ b/src/tools/clippy/tests/ui/floating_point_mul_add.rs
@@ -19,7 +19,9 @@ fn main() {
let d: f64 = 0.0001;
let _ = a * b + c;
+ let _ = a * b - c;
let _ = c + a * b;
+ let _ = c - a * b;
let _ = a + 2.0 * 4.0;
let _ = a + 2. * 4.;
diff --git a/src/tools/clippy/tests/ui/floating_point_mul_add.stderr b/src/tools/clippy/tests/ui/floating_point_mul_add.stderr
index e637bbf90..a79ae94e8 100644
--- a/src/tools/clippy/tests/ui/floating_point_mul_add.stderr
+++ b/src/tools/clippy/tests/ui/floating_point_mul_add.stderr
@@ -9,56 +9,68 @@ LL | let _ = a * b + c;
error: multiply and add expressions can be calculated more efficiently and accurately
--> $DIR/floating_point_mul_add.rs:22:13
|
+LL | let _ = a * b - c;
+ | ^^^^^^^^^ help: consider using: `a.mul_add(b, -c)`
+
+error: multiply and add expressions can be calculated more efficiently and accurately
+ --> $DIR/floating_point_mul_add.rs:23:13
+ |
LL | let _ = c + a * b;
| ^^^^^^^^^ help: consider using: `a.mul_add(b, c)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> $DIR/floating_point_mul_add.rs:23:13
+ --> $DIR/floating_point_mul_add.rs:24:13
+ |
+LL | let _ = c - a * b;
+ | ^^^^^^^^^ help: consider using: `a.mul_add(-b, c)`
+
+error: multiply and add expressions can be calculated more efficiently and accurately
+ --> $DIR/floating_point_mul_add.rs:25:13
|
LL | let _ = a + 2.0 * 4.0;
| ^^^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4.0, a)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> $DIR/floating_point_mul_add.rs:24:13
+ --> $DIR/floating_point_mul_add.rs:26:13
|
LL | let _ = a + 2. * 4.;
| ^^^^^^^^^^^ help: consider using: `2.0f64.mul_add(4., a)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> $DIR/floating_point_mul_add.rs:26:13
+ --> $DIR/floating_point_mul_add.rs:28:13
|
LL | let _ = (a * b) + c;
| ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> $DIR/floating_point_mul_add.rs:27:13
+ --> $DIR/floating_point_mul_add.rs:29:13
|
LL | let _ = c + (a * b);
| ^^^^^^^^^^^ help: consider using: `a.mul_add(b, c)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> $DIR/floating_point_mul_add.rs:28:13
+ --> $DIR/floating_point_mul_add.rs:30:13
|
LL | let _ = a * b * c + d;
| ^^^^^^^^^^^^^ help: consider using: `(a * b).mul_add(c, d)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> $DIR/floating_point_mul_add.rs:30:13
+ --> $DIR/floating_point_mul_add.rs:32:13
|
LL | let _ = a.mul_add(b, c) * a.mul_add(b, c) + a.mul_add(b, c) + c;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `a.mul_add(b, c).mul_add(a.mul_add(b, c), a.mul_add(b, c))`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> $DIR/floating_point_mul_add.rs:31:13
+ --> $DIR/floating_point_mul_add.rs:33:13
|
LL | let _ = 1234.567_f64 * 45.67834_f64 + 0.0004_f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1234.567_f64.mul_add(45.67834_f64, 0.0004_f64)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> $DIR/floating_point_mul_add.rs:33:13
+ --> $DIR/floating_point_mul_add.rs:35:13
|
LL | let _ = (a * a + b).sqrt();
| ^^^^^^^^^^^ help: consider using: `a.mul_add(a, b)`
-error: aborting due to 10 previous errors
+error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/floating_point_powf.fixed b/src/tools/clippy/tests/ui/floating_point_powf.fixed
index e7ef45634..f7f93de29 100644
--- a/src/tools/clippy/tests/ui/floating_point_powf.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_powf.fixed
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)]
+#![allow(clippy::unnecessary_cast)]
fn main() {
let x = 3f32;
diff --git a/src/tools/clippy/tests/ui/floating_point_powf.rs b/src/tools/clippy/tests/ui/floating_point_powf.rs
index d749aa2d4..499fc0e15 100644
--- a/src/tools/clippy/tests/ui/floating_point_powf.rs
+++ b/src/tools/clippy/tests/ui/floating_point_powf.rs
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::suboptimal_flops, clippy::imprecise_flops)]
+#![allow(clippy::unnecessary_cast)]
fn main() {
let x = 3f32;
diff --git a/src/tools/clippy/tests/ui/floating_point_powf.stderr b/src/tools/clippy/tests/ui/floating_point_powf.stderr
index e9693de8f..7c9d50db2 100644
--- a/src/tools/clippy/tests/ui/floating_point_powf.stderr
+++ b/src/tools/clippy/tests/ui/floating_point_powf.stderr
@@ -1,5 +1,5 @@
error: exponent for bases 2 and e can be computed more accurately
- --> $DIR/floating_point_powf.rs:6:13
+ --> $DIR/floating_point_powf.rs:7:13
|
LL | let _ = 2f32.powf(x);
| ^^^^^^^^^^^^ help: consider using: `x.exp2()`
@@ -7,43 +7,43 @@ LL | let _ = 2f32.powf(x);
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
error: exponent for bases 2 and e can be computed more accurately
- --> $DIR/floating_point_powf.rs:7:13
+ --> $DIR/floating_point_powf.rs:8:13
|
LL | let _ = 2f32.powf(3.1);
| ^^^^^^^^^^^^^^ help: consider using: `3.1f32.exp2()`
error: exponent for bases 2 and e can be computed more accurately
- --> $DIR/floating_point_powf.rs:8:13
+ --> $DIR/floating_point_powf.rs:9:13
|
LL | let _ = 2f32.powf(-3.1);
| ^^^^^^^^^^^^^^^ help: consider using: `(-3.1f32).exp2()`
error: exponent for bases 2 and e can be computed more accurately
- --> $DIR/floating_point_powf.rs:9:13
+ --> $DIR/floating_point_powf.rs:10:13
|
LL | let _ = std::f32::consts::E.powf(x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()`
error: exponent for bases 2 and e can be computed more accurately
- --> $DIR/floating_point_powf.rs:10:13
+ --> $DIR/floating_point_powf.rs:11:13
|
LL | let _ = std::f32::consts::E.powf(3.1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `3.1f32.exp()`
error: exponent for bases 2 and e can be computed more accurately
- --> $DIR/floating_point_powf.rs:11:13
+ --> $DIR/floating_point_powf.rs:12:13
|
LL | let _ = std::f32::consts::E.powf(-3.1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-3.1f32).exp()`
error: square-root of a number can be computed more efficiently and accurately
- --> $DIR/floating_point_powf.rs:12:13
+ --> $DIR/floating_point_powf.rs:13:13
|
LL | let _ = x.powf(1.0 / 2.0);
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()`
error: cube-root of a number can be computed more accurately
- --> $DIR/floating_point_powf.rs:13:13
+ --> $DIR/floating_point_powf.rs:14:13
|
LL | let _ = x.powf(1.0 / 3.0);
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()`
@@ -51,139 +51,139 @@ LL | let _ = x.powf(1.0 / 3.0);
= note: `-D clippy::imprecise-flops` implied by `-D warnings`
error: cube-root of a number can be computed more accurately
- --> $DIR/floating_point_powf.rs:14:13
+ --> $DIR/floating_point_powf.rs:15:13
|
LL | let _ = (x as f32).powf(1.0 / 3.0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).cbrt()`
error: exponentiation with integer powers can be computed more efficiently
- --> $DIR/floating_point_powf.rs:15:13
+ --> $DIR/floating_point_powf.rs:16:13
|
LL | let _ = x.powf(3.0);
| ^^^^^^^^^^^ help: consider using: `x.powi(3)`
error: exponentiation with integer powers can be computed more efficiently
- --> $DIR/floating_point_powf.rs:16:13
+ --> $DIR/floating_point_powf.rs:17:13
|
LL | let _ = x.powf(-2.0);
| ^^^^^^^^^^^^ help: consider using: `x.powi(-2)`
error: exponentiation with integer powers can be computed more efficiently
- --> $DIR/floating_point_powf.rs:17:13
+ --> $DIR/floating_point_powf.rs:18:13
|
LL | let _ = x.powf(16_777_215.0);
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(16_777_215)`
error: exponentiation with integer powers can be computed more efficiently
- --> $DIR/floating_point_powf.rs:18:13
+ --> $DIR/floating_point_powf.rs:19:13
|
LL | let _ = x.powf(-16_777_215.0);
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(-16_777_215)`
error: exponentiation with integer powers can be computed more efficiently
- --> $DIR/floating_point_powf.rs:19:13
+ --> $DIR/floating_point_powf.rs:20:13
|
LL | let _ = (x as f32).powf(-16_777_215.0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).powi(-16_777_215)`
error: exponentiation with integer powers can be computed more efficiently
- --> $DIR/floating_point_powf.rs:20:13
+ --> $DIR/floating_point_powf.rs:21:13
|
LL | let _ = (x as f32).powf(3.0);
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `(x as f32).powi(3)`
error: cube-root of a number can be computed more accurately
- --> $DIR/floating_point_powf.rs:21:13
+ --> $DIR/floating_point_powf.rs:22:13
|
LL | let _ = (1.5_f32 + 1.0).powf(1.0 / 3.0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(1.5_f32 + 1.0).cbrt()`
error: cube-root of a number can be computed more accurately
- --> $DIR/floating_point_powf.rs:22:13
+ --> $DIR/floating_point_powf.rs:23:13
|
LL | let _ = 1.5_f64.powf(1.0 / 3.0);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.5_f64.cbrt()`
error: square-root of a number can be computed more efficiently and accurately
- --> $DIR/floating_point_powf.rs:23:13
+ --> $DIR/floating_point_powf.rs:24:13
|
LL | let _ = 1.5_f64.powf(1.0 / 2.0);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `1.5_f64.sqrt()`
error: exponentiation with integer powers can be computed more efficiently
- --> $DIR/floating_point_powf.rs:24:13
+ --> $DIR/floating_point_powf.rs:25:13
|
LL | let _ = 1.5_f64.powf(3.0);
| ^^^^^^^^^^^^^^^^^ help: consider using: `1.5_f64.powi(3)`
error: exponent for bases 2 and e can be computed more accurately
- --> $DIR/floating_point_powf.rs:33:13
+ --> $DIR/floating_point_powf.rs:34:13
|
LL | let _ = 2f64.powf(x);
| ^^^^^^^^^^^^ help: consider using: `x.exp2()`
error: exponent for bases 2 and e can be computed more accurately
- --> $DIR/floating_point_powf.rs:34:13
+ --> $DIR/floating_point_powf.rs:35:13
|
LL | let _ = 2f64.powf(3.1);
| ^^^^^^^^^^^^^^ help: consider using: `3.1f64.exp2()`
error: exponent for bases 2 and e can be computed more accurately
- --> $DIR/floating_point_powf.rs:35:13
+ --> $DIR/floating_point_powf.rs:36:13
|
LL | let _ = 2f64.powf(-3.1);
| ^^^^^^^^^^^^^^^ help: consider using: `(-3.1f64).exp2()`
error: exponent for bases 2 and e can be computed more accurately
- --> $DIR/floating_point_powf.rs:36:13
+ --> $DIR/floating_point_powf.rs:37:13
|
LL | let _ = std::f64::consts::E.powf(x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.exp()`
error: exponent for bases 2 and e can be computed more accurately
- --> $DIR/floating_point_powf.rs:37:13
+ --> $DIR/floating_point_powf.rs:38:13
|
LL | let _ = std::f64::consts::E.powf(3.1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `3.1f64.exp()`
error: exponent for bases 2 and e can be computed more accurately
- --> $DIR/floating_point_powf.rs:38:13
+ --> $DIR/floating_point_powf.rs:39:13
|
LL | let _ = std::f64::consts::E.powf(-3.1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(-3.1f64).exp()`
error: square-root of a number can be computed more efficiently and accurately
- --> $DIR/floating_point_powf.rs:39:13
+ --> $DIR/floating_point_powf.rs:40:13
|
LL | let _ = x.powf(1.0 / 2.0);
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.sqrt()`
error: cube-root of a number can be computed more accurately
- --> $DIR/floating_point_powf.rs:40:13
+ --> $DIR/floating_point_powf.rs:41:13
|
LL | let _ = x.powf(1.0 / 3.0);
| ^^^^^^^^^^^^^^^^^ help: consider using: `x.cbrt()`
error: exponentiation with integer powers can be computed more efficiently
- --> $DIR/floating_point_powf.rs:41:13
+ --> $DIR/floating_point_powf.rs:42:13
|
LL | let _ = x.powf(3.0);
| ^^^^^^^^^^^ help: consider using: `x.powi(3)`
error: exponentiation with integer powers can be computed more efficiently
- --> $DIR/floating_point_powf.rs:42:13
+ --> $DIR/floating_point_powf.rs:43:13
|
LL | let _ = x.powf(-2.0);
| ^^^^^^^^^^^^ help: consider using: `x.powi(-2)`
error: exponentiation with integer powers can be computed more efficiently
- --> $DIR/floating_point_powf.rs:43:13
+ --> $DIR/floating_point_powf.rs:44:13
|
LL | let _ = x.powf(-2_147_483_648.0);
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(-2_147_483_648)`
error: exponentiation with integer powers can be computed more efficiently
- --> $DIR/floating_point_powf.rs:44:13
+ --> $DIR/floating_point_powf.rs:45:13
|
LL | let _ = x.powf(2_147_483_647.0);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `x.powi(2_147_483_647)`
diff --git a/src/tools/clippy/tests/ui/floating_point_powi.fixed b/src/tools/clippy/tests/ui/floating_point_powi.fixed
index 5758db7c6..884d05fed 100644
--- a/src/tools/clippy/tests/ui/floating_point_powi.fixed
+++ b/src/tools/clippy/tests/ui/floating_point_powi.fixed
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::suboptimal_flops)]
+#![allow(clippy::unnecessary_cast)]
fn main() {
let one = 1;
@@ -7,7 +8,9 @@ fn main() {
let y = 4f32;
let _ = x.mul_add(x, y);
+ let _ = x.mul_add(x, -y);
let _ = y.mul_add(y, x);
+ let _ = y.mul_add(-y, x);
let _ = (y as f32).mul_add(y as f32, x);
let _ = x.mul_add(x, y).sqrt();
let _ = y.mul_add(y, x).sqrt();
diff --git a/src/tools/clippy/tests/ui/floating_point_powi.rs b/src/tools/clippy/tests/ui/floating_point_powi.rs
index 5926bf1b0..e6a1c8953 100644
--- a/src/tools/clippy/tests/ui/floating_point_powi.rs
+++ b/src/tools/clippy/tests/ui/floating_point_powi.rs
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::suboptimal_flops)]
+#![allow(clippy::unnecessary_cast)]
fn main() {
let one = 1;
@@ -7,7 +8,9 @@ fn main() {
let y = 4f32;
let _ = x.powi(2) + y;
+ let _ = x.powi(2) - y;
let _ = x + y.powi(2);
+ let _ = x - y.powi(2);
let _ = x + (y as f32).powi(2);
let _ = (x.powi(2) + y).sqrt();
let _ = (x + y.powi(2)).sqrt();
diff --git a/src/tools/clippy/tests/ui/floating_point_powi.stderr b/src/tools/clippy/tests/ui/floating_point_powi.stderr
index a3c745442..5df0de1fe 100644
--- a/src/tools/clippy/tests/ui/floating_point_powi.stderr
+++ b/src/tools/clippy/tests/ui/floating_point_powi.stderr
@@ -1,5 +1,5 @@
error: multiply and add expressions can be calculated more efficiently and accurately
- --> $DIR/floating_point_powi.rs:9:13
+ --> $DIR/floating_point_powi.rs:10:13
|
LL | let _ = x.powi(2) + y;
| ^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, y)`
@@ -7,28 +7,40 @@ LL | let _ = x.powi(2) + y;
= note: `-D clippy::suboptimal-flops` implied by `-D warnings`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> $DIR/floating_point_powi.rs:10:13
+ --> $DIR/floating_point_powi.rs:11:13
+ |
+LL | let _ = x.powi(2) - y;
+ | ^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, -y)`
+
+error: multiply and add expressions can be calculated more efficiently and accurately
+ --> $DIR/floating_point_powi.rs:12:13
|
LL | let _ = x + y.powi(2);
| ^^^^^^^^^^^^^ help: consider using: `y.mul_add(y, x)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> $DIR/floating_point_powi.rs:11:13
+ --> $DIR/floating_point_powi.rs:13:13
+ |
+LL | let _ = x - y.powi(2);
+ | ^^^^^^^^^^^^^ help: consider using: `y.mul_add(-y, x)`
+
+error: multiply and add expressions can be calculated more efficiently and accurately
+ --> $DIR/floating_point_powi.rs:14:13
|
LL | let _ = x + (y as f32).powi(2);
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(y as f32).mul_add(y as f32, x)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> $DIR/floating_point_powi.rs:12:13
+ --> $DIR/floating_point_powi.rs:15:13
|
LL | let _ = (x.powi(2) + y).sqrt();
| ^^^^^^^^^^^^^^^ help: consider using: `x.mul_add(x, y)`
error: multiply and add expressions can be calculated more efficiently and accurately
- --> $DIR/floating_point_powi.rs:13:13
+ --> $DIR/floating_point_powi.rs:16:13
|
LL | let _ = (x + y.powi(2)).sqrt();
| ^^^^^^^^^^^^^^^ help: consider using: `y.mul_add(y, x)`
-error: aborting due to 5 previous errors
+error: aborting due to 7 previous errors
diff --git a/src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr b/src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr
index cd9d07fa1..116271056 100644
--- a/src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr
+++ b/src/tools/clippy/tests/ui/fn_params_excessive_bools.stderr
@@ -4,8 +4,8 @@ error: more than 3 bools in function parameters
LL | fn g(_: bool, _: bool, _: bool, _: bool) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings`
= help: consider refactoring bools into two-variant enums
+ = note: `-D clippy::fn-params-excessive-bools` implied by `-D warnings`
error: more than 3 bools in function parameters
--> $DIR/fn_params_excessive_bools.rs:21:1
diff --git a/src/tools/clippy/tests/ui/for_loop_fixable.fixed b/src/tools/clippy/tests/ui/for_loop_fixable.fixed
index aa69781d1..e9dd38fe4 100644
--- a/src/tools/clippy/tests/ui/for_loop_fixable.fixed
+++ b/src/tools/clippy/tests/ui/for_loop_fixable.fixed
@@ -1,6 +1,6 @@
// run-rustfix
-
#![allow(dead_code, unused)]
+#![allow(clippy::uninlined_format_args)]
use std::collections::*;
diff --git a/src/tools/clippy/tests/ui/for_loop_fixable.rs b/src/tools/clippy/tests/ui/for_loop_fixable.rs
index 7c063d995..534fb4dd4 100644
--- a/src/tools/clippy/tests/ui/for_loop_fixable.rs
+++ b/src/tools/clippy/tests/ui/for_loop_fixable.rs
@@ -1,6 +1,6 @@
// run-rustfix
-
#![allow(dead_code, unused)]
+#![allow(clippy::uninlined_format_args)]
use std::collections::*;
diff --git a/src/tools/clippy/tests/ui/for_loop_unfixable.rs b/src/tools/clippy/tests/ui/for_loop_unfixable.rs
index efcaffce2..55fb3788a 100644
--- a/src/tools/clippy/tests/ui/for_loop_unfixable.rs
+++ b/src/tools/clippy/tests/ui/for_loop_unfixable.rs
@@ -8,6 +8,7 @@
clippy::for_kv_map
)]
#[allow(clippy::linkedlist, clippy::unnecessary_mut_passed, clippy::similar_names)]
+#[allow(for_loops_over_fallibles)]
fn main() {
let vec = vec![1, 2, 3, 4];
diff --git a/src/tools/clippy/tests/ui/for_loop_unfixable.stderr b/src/tools/clippy/tests/ui/for_loop_unfixable.stderr
index f769b4bdc..50a86eaa6 100644
--- a/src/tools/clippy/tests/ui/for_loop_unfixable.stderr
+++ b/src/tools/clippy/tests/ui/for_loop_unfixable.stderr
@@ -1,5 +1,5 @@
error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
- --> $DIR/for_loop_unfixable.rs:14:15
+ --> $DIR/for_loop_unfixable.rs:15:15
|
LL | for _v in vec.iter().next() {}
| ^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/for_loops_over_fallibles.rs b/src/tools/clippy/tests/ui/for_loops_over_fallibles.rs
deleted file mode 100644
index 3390111d0..000000000
--- a/src/tools/clippy/tests/ui/for_loops_over_fallibles.rs
+++ /dev/null
@@ -1,72 +0,0 @@
-#![warn(clippy::for_loops_over_fallibles)]
-
-fn for_loops_over_fallibles() {
- let option = Some(1);
- let mut result = option.ok_or("x not found");
- let v = vec![0, 1, 2];
-
- // check over an `Option`
- for x in option {
- println!("{}", x);
- }
-
- // check over an `Option`
- for x in option.iter() {
- println!("{}", x);
- }
-
- // check over a `Result`
- for x in result {
- println!("{}", x);
- }
-
- // check over a `Result`
- for x in result.iter_mut() {
- println!("{}", x);
- }
-
- // check over a `Result`
- for x in result.into_iter() {
- println!("{}", x);
- }
-
- for x in option.ok_or("x not found") {
- println!("{}", x);
- }
-
- // make sure LOOP_OVER_NEXT lint takes clippy::precedence when next() is the last call
- // in the chain
- for x in v.iter().next() {
- println!("{}", x);
- }
-
- // make sure we lint when next() is not the last call in the chain
- for x in v.iter().next().and(Some(0)) {
- println!("{}", x);
- }
-
- for x in v.iter().next().ok_or("x not found") {
- println!("{}", x);
- }
-
- // check for false positives
-
- // for loop false positive
- for x in v {
- println!("{}", x);
- }
-
- // while let false positive for Option
- while let Some(x) = option {
- println!("{}", x);
- break;
- }
-
- // while let false positive for Result
- while let Ok(x) = result {
- println!("{}", x);
- break;
- }
-}
-
-fn main() {}
diff --git a/src/tools/clippy/tests/ui/for_loops_over_fallibles.stderr b/src/tools/clippy/tests/ui/for_loops_over_fallibles.stderr
deleted file mode 100644
index 8c8c02224..000000000
--- a/src/tools/clippy/tests/ui/for_loops_over_fallibles.stderr
+++ /dev/null
@@ -1,95 +0,0 @@
-error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement
- --> $DIR/for_loops_over_fallibles.rs:9:14
- |
-LL | for x in option {
- | ^^^^^^
- |
- = note: `-D clippy::for-loops-over-fallibles` implied by `-D warnings`
- = help: consider replacing `for x in option` with `if let Some(x) = option`
-
-error: for loop over `option`, which is an `Option`. This is more readably written as an `if let` statement
- --> $DIR/for_loops_over_fallibles.rs:14:14
- |
-LL | for x in option.iter() {
- | ^^^^^^
- |
- = help: consider replacing `for x in option.iter()` with `if let Some(x) = option`
-
-error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement
- --> $DIR/for_loops_over_fallibles.rs:19:14
- |
-LL | for x in result {
- | ^^^^^^
- |
- = help: consider replacing `for x in result` with `if let Ok(x) = result`
-
-error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement
- --> $DIR/for_loops_over_fallibles.rs:24:14
- |
-LL | for x in result.iter_mut() {
- | ^^^^^^
- |
- = help: consider replacing `for x in result.iter_mut()` with `if let Ok(x) = result`
-
-error: for loop over `result`, which is a `Result`. This is more readably written as an `if let` statement
- --> $DIR/for_loops_over_fallibles.rs:29:14
- |
-LL | for x in result.into_iter() {
- | ^^^^^^
- |
- = help: consider replacing `for x in result.into_iter()` with `if let Ok(x) = result`
-
-error: for loop over `option.ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement
- --> $DIR/for_loops_over_fallibles.rs:33:14
- |
-LL | for x in option.ok_or("x not found") {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: consider replacing `for x in option.ok_or("x not found")` with `if let Ok(x) = option.ok_or("x not found")`
-
-error: you are iterating over `Iterator::next()` which is an Option; this will compile but is probably not what you want
- --> $DIR/for_loops_over_fallibles.rs:39:14
- |
-LL | for x in v.iter().next() {
- | ^^^^^^^^^^^^^^^
- |
- = note: `#[deny(clippy::iter_next_loop)]` on by default
-
-error: for loop over `v.iter().next().and(Some(0))`, which is an `Option`. This is more readably written as an `if let` statement
- --> $DIR/for_loops_over_fallibles.rs:44:14
- |
-LL | for x in v.iter().next().and(Some(0)) {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: consider replacing `for x in v.iter().next().and(Some(0))` with `if let Some(x) = v.iter().next().and(Some(0))`
-
-error: for loop over `v.iter().next().ok_or("x not found")`, which is a `Result`. This is more readably written as an `if let` statement
- --> $DIR/for_loops_over_fallibles.rs:48:14
- |
-LL | for x in v.iter().next().ok_or("x not found") {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: consider replacing `for x in v.iter().next().ok_or("x not found")` with `if let Ok(x) = v.iter().next().ok_or("x not found")`
-
-error: this loop never actually loops
- --> $DIR/for_loops_over_fallibles.rs:60:5
- |
-LL | / while let Some(x) = option {
-LL | | println!("{}", x);
-LL | | break;
-LL | | }
- | |_____^
- |
- = note: `#[deny(clippy::never_loop)]` on by default
-
-error: this loop never actually loops
- --> $DIR/for_loops_over_fallibles.rs:66:5
- |
-LL | / while let Ok(x) = result {
-LL | | println!("{}", x);
-LL | | break;
-LL | | }
- | |_____^
-
-error: aborting due to 11 previous errors
-
diff --git a/src/tools/clippy/tests/ui/forget_non_drop.stderr b/src/tools/clippy/tests/ui/forget_non_drop.stderr
index 03fb00960..194e37c8b 100644
--- a/src/tools/clippy/tests/ui/forget_non_drop.stderr
+++ b/src/tools/clippy/tests/ui/forget_non_drop.stderr
@@ -4,12 +4,12 @@ error: call to `std::mem::forget` with a value that does not implement `Drop`. F
LL | forget(Foo);
| ^^^^^^^^^^^
|
- = note: `-D clippy::forget-non-drop` implied by `-D warnings`
note: argument has type `main::Foo`
--> $DIR/forget_non_drop.rs:13:12
|
LL | forget(Foo);
| ^^^
+ = note: `-D clippy::forget-non-drop` implied by `-D warnings`
error: call to `std::mem::forget` with a value that does not implement `Drop`. Forgetting such a type is the same as dropping it
--> $DIR/forget_non_drop.rs:24:5
diff --git a/src/tools/clippy/tests/ui/forget_ref.stderr b/src/tools/clippy/tests/ui/forget_ref.stderr
index df5cd8cac..011cdefc6 100644
--- a/src/tools/clippy/tests/ui/forget_ref.stderr
+++ b/src/tools/clippy/tests/ui/forget_ref.stderr
@@ -4,12 +4,12 @@ error: calls to `std::mem::forget` with a reference instead of an owned value. F
LL | forget(&SomeStruct);
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::forget-ref` implied by `-D warnings`
note: argument has type `&SomeStruct`
--> $DIR/forget_ref.rs:11:12
|
LL | forget(&SomeStruct);
| ^^^^^^^^^^^
+ = note: `-D clippy::forget-ref` implied by `-D warnings`
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing
--> $DIR/forget_ref.rs:14:5
diff --git a/src/tools/clippy/tests/ui/format.fixed b/src/tools/clippy/tests/ui/format.fixed
index b56d6aec5..beedf2c1d 100644
--- a/src/tools/clippy/tests/ui/format.fixed
+++ b/src/tools/clippy/tests/ui/format.fixed
@@ -1,13 +1,13 @@
// run-rustfix
-
+#![warn(clippy::useless_format)]
#![allow(
unused_tuple_struct_fields,
clippy::print_literal,
clippy::redundant_clone,
clippy::to_string_in_format_args,
- clippy::needless_borrow
+ clippy::needless_borrow,
+ clippy::uninlined_format_args
)]
-#![warn(clippy::useless_format)]
struct Foo(pub String);
@@ -28,8 +28,6 @@ fn main() {
format!("{:?}", "foo"); // Don't warn about `Debug`.
format!("{:8}", "foo");
format!("{:width$}", "foo", width = 8);
- "foo".to_string(); // Warn when the format makes no difference.
- "foo".to_string(); // Warn when the format makes no difference.
format!("foo {}", "bar");
format!("{} bar", "foo");
@@ -38,8 +36,6 @@ fn main() {
format!("{:?}", arg); // Don't warn about debug.
format!("{:8}", arg);
format!("{:width$}", arg, width = 8);
- arg.to_string(); // Warn when the format makes no difference.
- arg.to_string(); // Warn when the format makes no difference.
format!("foo {}", arg);
format!("{} bar", arg);
diff --git a/src/tools/clippy/tests/ui/format.rs b/src/tools/clippy/tests/ui/format.rs
index 4c1a3a840..e805f1818 100644
--- a/src/tools/clippy/tests/ui/format.rs
+++ b/src/tools/clippy/tests/ui/format.rs
@@ -1,13 +1,13 @@
// run-rustfix
-
+#![warn(clippy::useless_format)]
#![allow(
unused_tuple_struct_fields,
clippy::print_literal,
clippy::redundant_clone,
clippy::to_string_in_format_args,
- clippy::needless_borrow
+ clippy::needless_borrow,
+ clippy::uninlined_format_args
)]
-#![warn(clippy::useless_format)]
struct Foo(pub String);
@@ -30,8 +30,6 @@ fn main() {
format!("{:?}", "foo"); // Don't warn about `Debug`.
format!("{:8}", "foo");
format!("{:width$}", "foo", width = 8);
- format!("{:+}", "foo"); // Warn when the format makes no difference.
- format!("{:<}", "foo"); // Warn when the format makes no difference.
format!("foo {}", "bar");
format!("{} bar", "foo");
@@ -40,8 +38,6 @@ fn main() {
format!("{:?}", arg); // Don't warn about debug.
format!("{:8}", arg);
format!("{:width$}", arg, width = 8);
- format!("{:+}", arg); // Warn when the format makes no difference.
- format!("{:<}", arg); // Warn when the format makes no difference.
format!("foo {}", arg);
format!("{} bar", arg);
diff --git a/src/tools/clippy/tests/ui/format.stderr b/src/tools/clippy/tests/ui/format.stderr
index 6c35caeb0..0ef0ac655 100644
--- a/src/tools/clippy/tests/ui/format.stderr
+++ b/src/tools/clippy/tests/ui/format.stderr
@@ -46,82 +46,58 @@ LL | format!("{}", "foo");
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:33:5
- |
-LL | format!("{:+}", "foo"); // Warn when the format makes no difference.
- | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
-
-error: useless use of `format!`
- --> $DIR/format.rs:34:5
- |
-LL | format!("{:<}", "foo"); // Warn when the format makes no difference.
- | ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
-
-error: useless use of `format!`
- --> $DIR/format.rs:39:5
+ --> $DIR/format.rs:37:5
|
LL | format!("{}", arg);
| ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:43:5
- |
-LL | format!("{:+}", arg); // Warn when the format makes no difference.
- | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
-
-error: useless use of `format!`
- --> $DIR/format.rs:44:5
- |
-LL | format!("{:<}", arg); // Warn when the format makes no difference.
- | ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
-
-error: useless use of `format!`
- --> $DIR/format.rs:71:5
+ --> $DIR/format.rs:67:5
|
LL | format!("{}", 42.to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:73:5
+ --> $DIR/format.rs:69:5
|
LL | format!("{}", x.display().to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:77:18
+ --> $DIR/format.rs:73:18
|
LL | let _ = Some(format!("{}", a + "bar"));
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"`
error: useless use of `format!`
- --> $DIR/format.rs:81:22
+ --> $DIR/format.rs:77:22
|
LL | let _s: String = format!("{}", &*v.join("/n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("/n")).to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:87:13
+ --> $DIR/format.rs:83:13
|
LL | let _ = format!("{x}");
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:89:13
+ --> $DIR/format.rs:85:13
|
LL | let _ = format!("{y}", y = x);
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:93:13
+ --> $DIR/format.rs:89:13
|
LL | let _ = format!("{abc}");
| ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `abc.to_string()`
error: useless use of `format!`
- --> $DIR/format.rs:95:13
+ --> $DIR/format.rs:91:13
|
LL | let _ = format!("{xx}");
| ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `xx.to_string()`
-error: aborting due to 19 previous errors
+error: aborting due to 15 previous errors
diff --git a/src/tools/clippy/tests/ui/format_args.fixed b/src/tools/clippy/tests/ui/format_args.fixed
index e1c2d4d70..825e122be 100644
--- a/src/tools/clippy/tests/ui/format_args.fixed
+++ b/src/tools/clippy/tests/ui/format_args.fixed
@@ -1,10 +1,13 @@
// run-rustfix
-
-#![allow(unused)]
-#![allow(clippy::assertions_on_constants)]
-#![allow(clippy::eq_op)]
-#![allow(clippy::print_literal)]
#![warn(clippy::to_string_in_format_args)]
+#![allow(unused)]
+#![allow(
+ clippy::assertions_on_constants,
+ clippy::double_parens,
+ clippy::eq_op,
+ clippy::print_literal,
+ clippy::uninlined_format_args
+)]
use std::io::{stdout, Write};
use std::ops::Deref;
@@ -112,6 +115,8 @@ fn main() {
println!("error: something failed at {}", my_other_macro!());
// https://github.com/rust-lang/rust-clippy/issues/7903
println!("{foo}{foo:?}", foo = "foo".to_string());
+ print!("{}", (Location::caller()));
+ print!("{}", ((Location::caller())));
}
fn issue8643(vendor_id: usize, product_id: usize, name: &str) {
diff --git a/src/tools/clippy/tests/ui/format_args.rs b/src/tools/clippy/tests/ui/format_args.rs
index b9a4d66c2..a41e53389 100644
--- a/src/tools/clippy/tests/ui/format_args.rs
+++ b/src/tools/clippy/tests/ui/format_args.rs
@@ -1,10 +1,13 @@
// run-rustfix
-
-#![allow(unused)]
-#![allow(clippy::assertions_on_constants)]
-#![allow(clippy::eq_op)]
-#![allow(clippy::print_literal)]
#![warn(clippy::to_string_in_format_args)]
+#![allow(unused)]
+#![allow(
+ clippy::assertions_on_constants,
+ clippy::double_parens,
+ clippy::eq_op,
+ clippy::print_literal,
+ clippy::uninlined_format_args
+)]
use std::io::{stdout, Write};
use std::ops::Deref;
@@ -112,6 +115,8 @@ fn main() {
println!("error: something failed at {}", my_other_macro!());
// https://github.com/rust-lang/rust-clippy/issues/7903
println!("{foo}{foo:?}", foo = "foo".to_string());
+ print!("{}", (Location::caller().to_string()));
+ print!("{}", ((Location::caller()).to_string()));
}
fn issue8643(vendor_id: usize, product_id: usize, name: &str) {
diff --git a/src/tools/clippy/tests/ui/format_args.stderr b/src/tools/clippy/tests/ui/format_args.stderr
index aa6e3659b..f1832b970 100644
--- a/src/tools/clippy/tests/ui/format_args.stderr
+++ b/src/tools/clippy/tests/ui/format_args.stderr
@@ -1,5 +1,5 @@
error: `to_string` applied to a type that implements `Display` in `format!` args
- --> $DIR/format_args.rs:74:72
+ --> $DIR/format_args.rs:77:72
|
LL | let _ = format!("error: something failed at {}", Location::caller().to_string());
| ^^^^^^^^^^^^ help: remove this
@@ -7,136 +7,148 @@ LL | let _ = format!("error: something failed at {}", Location::caller().to_
= note: `-D clippy::to-string-in-format-args` implied by `-D warnings`
error: `to_string` applied to a type that implements `Display` in `write!` args
- --> $DIR/format_args.rs:78:27
+ --> $DIR/format_args.rs:81:27
|
LL | Location::caller().to_string()
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `writeln!` args
- --> $DIR/format_args.rs:83:27
+ --> $DIR/format_args.rs:86:27
|
LL | Location::caller().to_string()
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `print!` args
- --> $DIR/format_args.rs:85:63
+ --> $DIR/format_args.rs:88:63
|
LL | print!("error: something failed at {}", Location::caller().to_string());
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `println!` args
- --> $DIR/format_args.rs:86:65
+ --> $DIR/format_args.rs:89:65
|
LL | println!("error: something failed at {}", Location::caller().to_string());
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `eprint!` args
- --> $DIR/format_args.rs:87:64
+ --> $DIR/format_args.rs:90:64
|
LL | eprint!("error: something failed at {}", Location::caller().to_string());
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `eprintln!` args
- --> $DIR/format_args.rs:88:66
+ --> $DIR/format_args.rs:91:66
|
LL | eprintln!("error: something failed at {}", Location::caller().to_string());
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `format_args!` args
- --> $DIR/format_args.rs:89:77
+ --> $DIR/format_args.rs:92:77
|
LL | let _ = format_args!("error: something failed at {}", Location::caller().to_string());
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `assert!` args
- --> $DIR/format_args.rs:90:70
+ --> $DIR/format_args.rs:93:70
|
LL | assert!(true, "error: something failed at {}", Location::caller().to_string());
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `assert_eq!` args
- --> $DIR/format_args.rs:91:73
+ --> $DIR/format_args.rs:94:73
|
LL | assert_eq!(0, 0, "error: something failed at {}", Location::caller().to_string());
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `assert_ne!` args
- --> $DIR/format_args.rs:92:73
+ --> $DIR/format_args.rs:95:73
|
LL | assert_ne!(0, 0, "error: something failed at {}", Location::caller().to_string());
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `panic!` args
- --> $DIR/format_args.rs:93:63
+ --> $DIR/format_args.rs:96:63
|
LL | panic!("error: something failed at {}", Location::caller().to_string());
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `println!` args
- --> $DIR/format_args.rs:94:20
+ --> $DIR/format_args.rs:97:20
|
LL | println!("{}", X(1).to_string());
| ^^^^^^^^^^^^^^^^ help: use this: `*X(1)`
error: `to_string` applied to a type that implements `Display` in `println!` args
- --> $DIR/format_args.rs:95:20
+ --> $DIR/format_args.rs:98:20
|
LL | println!("{}", Y(&X(1)).to_string());
| ^^^^^^^^^^^^^^^^^^^^ help: use this: `***Y(&X(1))`
error: `to_string` applied to a type that implements `Display` in `println!` args
- --> $DIR/format_args.rs:96:24
+ --> $DIR/format_args.rs:99:24
|
LL | println!("{}", Z(1).to_string());
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `println!` args
- --> $DIR/format_args.rs:97:20
+ --> $DIR/format_args.rs:100:20
|
LL | println!("{}", x.to_string());
| ^^^^^^^^^^^^^ help: use this: `**x`
error: `to_string` applied to a type that implements `Display` in `println!` args
- --> $DIR/format_args.rs:98:20
+ --> $DIR/format_args.rs:101:20
|
LL | println!("{}", x_ref.to_string());
| ^^^^^^^^^^^^^^^^^ help: use this: `***x_ref`
error: `to_string` applied to a type that implements `Display` in `println!` args
- --> $DIR/format_args.rs:100:39
+ --> $DIR/format_args.rs:103:39
|
LL | println!("{foo}{bar}", foo = "foo".to_string(), bar = "bar");
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `println!` args
- --> $DIR/format_args.rs:101:52
+ --> $DIR/format_args.rs:104:52
|
LL | println!("{foo}{bar}", foo = "foo", bar = "bar".to_string());
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `println!` args
- --> $DIR/format_args.rs:102:39
+ --> $DIR/format_args.rs:105:39
|
LL | println!("{foo}{bar}", bar = "bar".to_string(), foo = "foo");
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `println!` args
- --> $DIR/format_args.rs:103:52
+ --> $DIR/format_args.rs:106:52
|
LL | println!("{foo}{bar}", bar = "bar", foo = "foo".to_string());
| ^^^^^^^^^^^^ help: remove this
+error: `to_string` applied to a type that implements `Display` in `print!` args
+ --> $DIR/format_args.rs:118:37
+ |
+LL | print!("{}", (Location::caller().to_string()));
+ | ^^^^^^^^^^^^ help: remove this
+
+error: `to_string` applied to a type that implements `Display` in `print!` args
+ --> $DIR/format_args.rs:119:39
+ |
+LL | print!("{}", ((Location::caller()).to_string()));
+ | ^^^^^^^^^^^^ help: remove this
+
error: `to_string` applied to a type that implements `Display` in `format!` args
- --> $DIR/format_args.rs:142:38
+ --> $DIR/format_args.rs:147:38
|
LL | let x = format!("{} {}", a, b.to_string());
| ^^^^^^^^^^^^ help: remove this
error: `to_string` applied to a type that implements `Display` in `println!` args
- --> $DIR/format_args.rs:156:24
+ --> $DIR/format_args.rs:161:24
|
LL | println!("{}", original[..10].to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use this: `&original[..10]`
-error: aborting due to 23 previous errors
+error: aborting due to 25 previous errors
diff --git a/src/tools/clippy/tests/ui/format_args_unfixable.rs b/src/tools/clippy/tests/ui/format_args_unfixable.rs
index b24ddf732..eb0ac15bf 100644
--- a/src/tools/clippy/tests/ui/format_args_unfixable.rs
+++ b/src/tools/clippy/tests/ui/format_args_unfixable.rs
@@ -1,7 +1,5 @@
-#![allow(clippy::assertions_on_constants)]
-#![allow(clippy::eq_op)]
-#![warn(clippy::format_in_format_args)]
-#![warn(clippy::to_string_in_format_args)]
+#![warn(clippy::format_in_format_args, clippy::to_string_in_format_args)]
+#![allow(clippy::assertions_on_constants, clippy::eq_op, clippy::uninlined_format_args)]
use std::io::{stdout, Error, ErrorKind, Write};
use std::ops::Deref;
diff --git a/src/tools/clippy/tests/ui/format_args_unfixable.stderr b/src/tools/clippy/tests/ui/format_args_unfixable.stderr
index 4476218ad..b291d475a 100644
--- a/src/tools/clippy/tests/ui/format_args_unfixable.stderr
+++ b/src/tools/clippy/tests/ui/format_args_unfixable.stderr
@@ -1,15 +1,15 @@
error: `format!` in `println!` args
- --> $DIR/format_args_unfixable.rs:27:5
+ --> $DIR/format_args_unfixable.rs:25:5
|
LL | println!("error: {}", format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::format-in-format-args` implied by `-D warnings`
= help: combine the `format!(..)` arguments with the outer `println!(..)` call
= help: or consider changing `format!` to `format_args!`
+ = note: `-D clippy::format-in-format-args` implied by `-D warnings`
error: `format!` in `println!` args
- --> $DIR/format_args_unfixable.rs:28:5
+ --> $DIR/format_args_unfixable.rs:26:5
|
LL | println!("{}: {}", error, format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -18,7 +18,7 @@ LL | println!("{}: {}", error, format!("something failed at {}", Location::c
= help: or consider changing `format!` to `format_args!`
error: `format!` in `println!` args
- --> $DIR/format_args_unfixable.rs:29:5
+ --> $DIR/format_args_unfixable.rs:27:5
|
LL | println!("{:?}: {}", error, format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -27,7 +27,7 @@ LL | println!("{:?}: {}", error, format!("something failed at {}", Location:
= help: or consider changing `format!` to `format_args!`
error: `format!` in `println!` args
- --> $DIR/format_args_unfixable.rs:30:5
+ --> $DIR/format_args_unfixable.rs:28:5
|
LL | println!("{{}}: {}", format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -36,7 +36,7 @@ LL | println!("{{}}: {}", format!("something failed at {}", Location::caller
= help: or consider changing `format!` to `format_args!`
error: `format!` in `println!` args
- --> $DIR/format_args_unfixable.rs:31:5
+ --> $DIR/format_args_unfixable.rs:29:5
|
LL | println!(r#"error: "{}""#, format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -45,7 +45,7 @@ LL | println!(r#"error: "{}""#, format!("something failed at {}", Location::
= help: or consider changing `format!` to `format_args!`
error: `format!` in `println!` args
- --> $DIR/format_args_unfixable.rs:32:5
+ --> $DIR/format_args_unfixable.rs:30:5
|
LL | println!("error: {}", format!(r#"something failed at "{}""#, Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -54,7 +54,7 @@ LL | println!("error: {}", format!(r#"something failed at "{}""#, Location::
= help: or consider changing `format!` to `format_args!`
error: `format!` in `println!` args
- --> $DIR/format_args_unfixable.rs:33:5
+ --> $DIR/format_args_unfixable.rs:31:5
|
LL | println!("error: {}", format!("something failed at {} {0}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -63,7 +63,7 @@ LL | println!("error: {}", format!("something failed at {} {0}", Location::c
= help: or consider changing `format!` to `format_args!`
error: `format!` in `format!` args
- --> $DIR/format_args_unfixable.rs:34:13
+ --> $DIR/format_args_unfixable.rs:32:13
|
LL | let _ = format!("error: {}", format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -72,7 +72,7 @@ LL | let _ = format!("error: {}", format!("something failed at {}", Location
= help: or consider changing `format!` to `format_args!`
error: `format!` in `write!` args
- --> $DIR/format_args_unfixable.rs:35:13
+ --> $DIR/format_args_unfixable.rs:33:13
|
LL | let _ = write!(
| _____________^
@@ -86,7 +86,7 @@ LL | | );
= help: or consider changing `format!` to `format_args!`
error: `format!` in `writeln!` args
- --> $DIR/format_args_unfixable.rs:40:13
+ --> $DIR/format_args_unfixable.rs:38:13
|
LL | let _ = writeln!(
| _____________^
@@ -100,7 +100,7 @@ LL | | );
= help: or consider changing `format!` to `format_args!`
error: `format!` in `print!` args
- --> $DIR/format_args_unfixable.rs:45:5
+ --> $DIR/format_args_unfixable.rs:43:5
|
LL | print!("error: {}", format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -109,7 +109,7 @@ LL | print!("error: {}", format!("something failed at {}", Location::caller(
= help: or consider changing `format!` to `format_args!`
error: `format!` in `eprint!` args
- --> $DIR/format_args_unfixable.rs:46:5
+ --> $DIR/format_args_unfixable.rs:44:5
|
LL | eprint!("error: {}", format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -118,7 +118,7 @@ LL | eprint!("error: {}", format!("something failed at {}", Location::caller
= help: or consider changing `format!` to `format_args!`
error: `format!` in `eprintln!` args
- --> $DIR/format_args_unfixable.rs:47:5
+ --> $DIR/format_args_unfixable.rs:45:5
|
LL | eprintln!("error: {}", format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -127,7 +127,7 @@ LL | eprintln!("error: {}", format!("something failed at {}", Location::call
= help: or consider changing `format!` to `format_args!`
error: `format!` in `format_args!` args
- --> $DIR/format_args_unfixable.rs:48:13
+ --> $DIR/format_args_unfixable.rs:46:13
|
LL | let _ = format_args!("error: {}", format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -136,7 +136,7 @@ LL | let _ = format_args!("error: {}", format!("something failed at {}", Loc
= help: or consider changing `format!` to `format_args!`
error: `format!` in `assert!` args
- --> $DIR/format_args_unfixable.rs:49:5
+ --> $DIR/format_args_unfixable.rs:47:5
|
LL | assert!(true, "error: {}", format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -145,7 +145,7 @@ LL | assert!(true, "error: {}", format!("something failed at {}", Location::
= help: or consider changing `format!` to `format_args!`
error: `format!` in `assert_eq!` args
- --> $DIR/format_args_unfixable.rs:50:5
+ --> $DIR/format_args_unfixable.rs:48:5
|
LL | assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -154,7 +154,7 @@ LL | assert_eq!(0, 0, "error: {}", format!("something failed at {}", Locatio
= help: or consider changing `format!` to `format_args!`
error: `format!` in `assert_ne!` args
- --> $DIR/format_args_unfixable.rs:51:5
+ --> $DIR/format_args_unfixable.rs:49:5
|
LL | assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -163,7 +163,7 @@ LL | assert_ne!(0, 0, "error: {}", format!("something failed at {}", Locatio
= help: or consider changing `format!` to `format_args!`
error: `format!` in `panic!` args
- --> $DIR/format_args_unfixable.rs:52:5
+ --> $DIR/format_args_unfixable.rs:50:5
|
LL | panic!("error: {}", format!("something failed at {}", Location::caller()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/format_push_string.stderr b/src/tools/clippy/tests/ui/format_push_string.stderr
index 953784bcc..d7be9a5f2 100644
--- a/src/tools/clippy/tests/ui/format_push_string.stderr
+++ b/src/tools/clippy/tests/ui/format_push_string.stderr
@@ -4,8 +4,8 @@ error: `format!(..)` appended to existing `String`
LL | string += &format!("{:?}", 1234);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::format-push-string` implied by `-D warnings`
= help: consider using `write!` to avoid the extra allocation
+ = note: `-D clippy::format-push-string` implied by `-D warnings`
error: `format!(..)` appended to existing `String`
--> $DIR/format_push_string.rs:6:5
diff --git a/src/tools/clippy/tests/ui/formatting.stderr b/src/tools/clippy/tests/ui/formatting.stderr
index 9272cd604..caccd5cba 100644
--- a/src/tools/clippy/tests/ui/formatting.stderr
+++ b/src/tools/clippy/tests/ui/formatting.stderr
@@ -4,8 +4,8 @@ error: this looks like you are trying to use `.. -= ..`, but you really are doin
LL | a =- 35;
| ^^^^
|
- = note: `-D clippy::suspicious-assignment-formatting` implied by `-D warnings`
= note: to remove this lint, use either `-=` or `= -`
+ = note: `-D clippy::suspicious-assignment-formatting` implied by `-D warnings`
error: this looks like you are trying to use `.. *= ..`, but you really are doing `.. = (* ..)`
--> $DIR/formatting.rs:17:6
@@ -29,8 +29,8 @@ error: possibly missing a comma here
LL | -1, -2, -3 // <= no comma here
| ^
|
- = note: `-D clippy::possible-missing-comma` implied by `-D warnings`
= note: to remove this lint, add a comma or write the expr in a single line
+ = note: `-D clippy::possible-missing-comma` implied by `-D warnings`
error: possibly missing a comma here
--> $DIR/formatting.rs:33:19
diff --git a/src/tools/clippy/tests/ui/from_over_into.fixed b/src/tools/clippy/tests/ui/from_over_into.fixed
new file mode 100644
index 000000000..1cf49ca45
--- /dev/null
+++ b/src/tools/clippy/tests/ui/from_over_into.fixed
@@ -0,0 +1,87 @@
+// run-rustfix
+
+#![feature(custom_inner_attributes)]
+#![warn(clippy::from_over_into)]
+#![allow(unused)]
+
+// this should throw an error
+struct StringWrapper(String);
+
+impl From<String> for StringWrapper {
+ fn from(val: String) -> Self {
+ StringWrapper(val)
+ }
+}
+
+struct SelfType(String);
+
+impl From<String> for SelfType {
+ fn from(val: String) -> Self {
+ SelfType(String::new())
+ }
+}
+
+#[derive(Default)]
+struct X;
+
+impl X {
+ const FOO: &'static str = "a";
+}
+
+struct SelfKeywords;
+
+impl From<X> for SelfKeywords {
+ fn from(val: X) -> Self {
+ let _ = X::default();
+ let _ = X::FOO;
+ let _: X = val;
+
+ SelfKeywords
+ }
+}
+
+struct ExplicitPaths(bool);
+
+impl core::convert::From<crate::ExplicitPaths> for bool {
+ fn from(mut val: crate::ExplicitPaths) -> Self {
+ let in_closure = || val.0;
+
+ val.0 = false;
+ val.0
+ }
+}
+
+// this is fine
+struct A(String);
+
+impl From<String> for A {
+ fn from(s: String) -> A {
+ A(s)
+ }
+}
+
+fn msrv_1_40() {
+ #![clippy::msrv = "1.40"]
+
+ struct FromOverInto<T>(Vec<T>);
+
+ impl<T> Into<FromOverInto<T>> for Vec<T> {
+ fn into(self) -> FromOverInto<T> {
+ FromOverInto(self)
+ }
+ }
+}
+
+fn msrv_1_41() {
+ #![clippy::msrv = "1.41"]
+
+ struct FromOverInto<T>(Vec<T>);
+
+ impl<T> From<Vec<T>> for FromOverInto<T> {
+ fn from(val: Vec<T>) -> Self {
+ FromOverInto(val)
+ }
+ }
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/from_over_into.rs b/src/tools/clippy/tests/ui/from_over_into.rs
index 292d0924f..d30f3c3fc 100644
--- a/src/tools/clippy/tests/ui/from_over_into.rs
+++ b/src/tools/clippy/tests/ui/from_over_into.rs
@@ -1,4 +1,8 @@
+// run-rustfix
+
+#![feature(custom_inner_attributes)]
#![warn(clippy::from_over_into)]
+#![allow(unused)]
// this should throw an error
struct StringWrapper(String);
@@ -9,6 +13,44 @@ impl Into<StringWrapper> for String {
}
}
+struct SelfType(String);
+
+impl Into<SelfType> for String {
+ fn into(self) -> SelfType {
+ SelfType(Self::new())
+ }
+}
+
+#[derive(Default)]
+struct X;
+
+impl X {
+ const FOO: &'static str = "a";
+}
+
+struct SelfKeywords;
+
+impl Into<SelfKeywords> for X {
+ fn into(self) -> SelfKeywords {
+ let _ = Self::default();
+ let _ = Self::FOO;
+ let _: Self = self;
+
+ SelfKeywords
+ }
+}
+
+struct ExplicitPaths(bool);
+
+impl core::convert::Into<bool> for crate::ExplicitPaths {
+ fn into(mut self) -> bool {
+ let in_closure = || self.0;
+
+ self.0 = false;
+ self.0
+ }
+}
+
// this is fine
struct A(String);
@@ -18,4 +60,28 @@ impl From<String> for A {
}
}
+fn msrv_1_40() {
+ #![clippy::msrv = "1.40"]
+
+ struct FromOverInto<T>(Vec<T>);
+
+ impl<T> Into<FromOverInto<T>> for Vec<T> {
+ fn into(self) -> FromOverInto<T> {
+ FromOverInto(self)
+ }
+ }
+}
+
+fn msrv_1_41() {
+ #![clippy::msrv = "1.41"]
+
+ struct FromOverInto<T>(Vec<T>);
+
+ impl<T> Into<FromOverInto<T>> for Vec<T> {
+ fn into(self) -> FromOverInto<T> {
+ FromOverInto(self)
+ }
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/from_over_into.stderr b/src/tools/clippy/tests/ui/from_over_into.stderr
index 2951e6bda..9c2a7c04c 100644
--- a/src/tools/clippy/tests/ui/from_over_into.stderr
+++ b/src/tools/clippy/tests/ui/from_over_into.stderr
@@ -1,11 +1,75 @@
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
- --> $DIR/from_over_into.rs:6:1
+ --> $DIR/from_over_into.rs:10:1
|
LL | impl Into<StringWrapper> for String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::from-over-into` implied by `-D warnings`
- = help: consider to implement `From<std::string::String>` instead
+help: replace the `Into` implentation with `From<std::string::String>`
+ |
+LL ~ impl From<String> for StringWrapper {
+LL ~ fn from(val: String) -> Self {
+LL ~ StringWrapper(val)
+ |
+
+error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
+ --> $DIR/from_over_into.rs:18:1
+ |
+LL | impl Into<SelfType> for String {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: replace the `Into` implentation with `From<std::string::String>`
+ |
+LL ~ impl From<String> for SelfType {
+LL ~ fn from(val: String) -> Self {
+LL ~ SelfType(String::new())
+ |
+
+error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
+ --> $DIR/from_over_into.rs:33:1
+ |
+LL | impl Into<SelfKeywords> for X {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: replace the `Into` implentation with `From<X>`
+ |
+LL ~ impl From<X> for SelfKeywords {
+LL ~ fn from(val: X) -> Self {
+LL ~ let _ = X::default();
+LL ~ let _ = X::FOO;
+LL ~ let _: X = val;
+ |
+
+error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
+ --> $DIR/from_over_into.rs:45:1
+ |
+LL | impl core::convert::Into<bool> for crate::ExplicitPaths {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
+ https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
+help: replace the `Into` implentation with `From<ExplicitPaths>`
+ |
+LL ~ impl core::convert::From<crate::ExplicitPaths> for bool {
+LL ~ fn from(mut val: crate::ExplicitPaths) -> Self {
+LL ~ let in_closure = || val.0;
+LL |
+LL ~ val.0 = false;
+LL ~ val.0
+ |
+
+error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
+ --> $DIR/from_over_into.rs:80:5
+ |
+LL | impl<T> Into<FromOverInto<T>> for Vec<T> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: replace the `Into` implentation with `From<std::vec::Vec<T>>`
+ |
+LL ~ impl<T> From<Vec<T>> for FromOverInto<T> {
+LL ~ fn from(val: Vec<T>) -> Self {
+LL ~ FromOverInto(val)
+ |
-error: aborting due to previous error
+error: aborting due to 5 previous errors
diff --git a/src/tools/clippy/tests/ui/from_over_into_unfixable.rs b/src/tools/clippy/tests/ui/from_over_into_unfixable.rs
new file mode 100644
index 000000000..3b280b748
--- /dev/null
+++ b/src/tools/clippy/tests/ui/from_over_into_unfixable.rs
@@ -0,0 +1,35 @@
+#![warn(clippy::from_over_into)]
+
+struct InMacro(String);
+
+macro_rules! in_macro {
+ ($e:ident) => {
+ $e
+ };
+}
+
+impl Into<InMacro> for String {
+ fn into(self) -> InMacro {
+ InMacro(in_macro!(self))
+ }
+}
+
+struct WeirdUpperSelf;
+
+impl Into<WeirdUpperSelf> for &'static [u8] {
+ fn into(self) -> WeirdUpperSelf {
+ let _ = Self::default();
+ WeirdUpperSelf
+ }
+}
+
+struct ContainsVal;
+
+impl Into<u8> for ContainsVal {
+ fn into(self) -> u8 {
+ let val = 1;
+ val + 1
+ }
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/from_over_into_unfixable.stderr b/src/tools/clippy/tests/ui/from_over_into_unfixable.stderr
new file mode 100644
index 000000000..6f6ce3519
--- /dev/null
+++ b/src/tools/clippy/tests/ui/from_over_into_unfixable.stderr
@@ -0,0 +1,29 @@
+error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
+ --> $DIR/from_over_into_unfixable.rs:11:1
+ |
+LL | impl Into<InMacro> for String {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: replace the `Into` implentation with `From<std::string::String>`
+ = note: `-D clippy::from-over-into` implied by `-D warnings`
+
+error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
+ --> $DIR/from_over_into_unfixable.rs:19:1
+ |
+LL | impl Into<WeirdUpperSelf> for &'static [u8] {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: replace the `Into` implentation with `From<&'static [u8]>`
+
+error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
+ --> $DIR/from_over_into_unfixable.rs:28:1
+ |
+LL | impl Into<u8> for ContainsVal {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
+ https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
+ = help: replace the `Into` implentation with `From<ContainsVal>`
+
+error: aborting due to 3 previous errors
+
diff --git a/src/tools/clippy/tests/ui/functions.rs b/src/tools/clippy/tests/ui/functions.rs
index 5521870ea..18149bfbc 100644
--- a/src/tools/clippy/tests/ui/functions.rs
+++ b/src/tools/clippy/tests/ui/functions.rs
@@ -1,6 +1,6 @@
#![warn(clippy::all)]
-#![allow(dead_code)]
-#![allow(unused_unsafe, clippy::missing_safety_doc)]
+#![allow(dead_code, unused_unsafe)]
+#![allow(clippy::missing_safety_doc, clippy::uninlined_format_args)]
// TOO_MANY_ARGUMENTS
fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
diff --git a/src/tools/clippy/tests/ui/future_not_send.stderr b/src/tools/clippy/tests/ui/future_not_send.stderr
index a9f2ad36d..5b6858e45 100644
--- a/src/tools/clippy/tests/ui/future_not_send.stderr
+++ b/src/tools/clippy/tests/ui/future_not_send.stderr
@@ -4,7 +4,6 @@ error: future cannot be sent between threads safely
LL | async fn private_future(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
| ^^^^ future returned by `private_future` is not `Send`
|
- = note: `-D clippy::future-not-send` implied by `-D warnings`
note: future is not `Send` as this value is used across an await
--> $DIR/future_not_send.rs:8:19
|
@@ -25,6 +24,7 @@ LL | async { true }.await
LL | }
| - `cell` is later dropped here
= note: `std::cell::Cell<usize>` doesn't implement `std::marker::Sync`
+ = note: `-D clippy::future-not-send` implied by `-D warnings`
error: future cannot be sent between threads safely
--> $DIR/future_not_send.rs:11:42
diff --git a/src/tools/clippy/tests/ui/get_unwrap.stderr b/src/tools/clippy/tests/ui/get_unwrap.stderr
index ea8fec527..937f85904 100644
--- a/src/tools/clippy/tests/ui/get_unwrap.stderr
+++ b/src/tools/clippy/tests/ui/get_unwrap.stderr
@@ -16,8 +16,8 @@ error: used `unwrap()` on `an Option` value
LL | let _ = boxed_slice.get(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::unwrap-used` implied by `-D warnings`
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
+ = note: `-D clippy::unwrap-used` implied by `-D warnings`
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
--> $DIR/get_unwrap.rs:36:17
diff --git a/src/tools/clippy/tests/ui/identity_op.fixed b/src/tools/clippy/tests/ui/identity_op.fixed
index fa564e23c..e7b9a78c5 100644
--- a/src/tools/clippy/tests/ui/identity_op.fixed
+++ b/src/tools/clippy/tests/ui/identity_op.fixed
@@ -1,13 +1,13 @@
// run-rustfix
-
#![warn(clippy::identity_op)]
+#![allow(unused)]
#![allow(
clippy::eq_op,
clippy::no_effect,
clippy::unnecessary_operation,
clippy::op_ref,
clippy::double_parens,
- unused
+ clippy::uninlined_format_args
)]
use std::fmt::Write as _;
diff --git a/src/tools/clippy/tests/ui/identity_op.rs b/src/tools/clippy/tests/ui/identity_op.rs
index 3d06d2a73..9a435cdbb 100644
--- a/src/tools/clippy/tests/ui/identity_op.rs
+++ b/src/tools/clippy/tests/ui/identity_op.rs
@@ -1,13 +1,13 @@
// run-rustfix
-
#![warn(clippy::identity_op)]
+#![allow(unused)]
#![allow(
clippy::eq_op,
clippy::no_effect,
clippy::unnecessary_operation,
clippy::op_ref,
clippy::double_parens,
- unused
+ clippy::uninlined_format_args
)]
use std::fmt::Write as _;
diff --git a/src/tools/clippy/tests/ui/if_let_mutex.stderr b/src/tools/clippy/tests/ui/if_let_mutex.stderr
index 8a4d5dbac..da0cc25f0 100644
--- a/src/tools/clippy/tests/ui/if_let_mutex.stderr
+++ b/src/tools/clippy/tests/ui/if_let_mutex.stderr
@@ -13,8 +13,8 @@ LL | | do_stuff(lock);
LL | | };
| |_____^
|
- = note: `-D clippy::if-let-mutex` implied by `-D warnings`
= help: move the lock call outside of the `if let ...` expression
+ = note: `-D clippy::if-let-mutex` implied by `-D warnings`
error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock
--> $DIR/if_let_mutex.rs:22:5
diff --git a/src/tools/clippy/tests/ui/if_not_else.stderr b/src/tools/clippy/tests/ui/if_not_else.stderr
index 8c8cc44bb..46671c152 100644
--- a/src/tools/clippy/tests/ui/if_not_else.stderr
+++ b/src/tools/clippy/tests/ui/if_not_else.stderr
@@ -8,8 +8,8 @@ LL | | println!("Bunny");
LL | | }
| |_____^
|
- = note: `-D clippy::if-not-else` implied by `-D warnings`
= help: remove the `!` and swap the blocks of the `if`/`else`
+ = note: `-D clippy::if-not-else` implied by `-D warnings`
error: unnecessary `!=` operation
--> $DIR/if_not_else.rs:17:5
diff --git a/src/tools/clippy/tests/ui/if_same_then_else.stderr b/src/tools/clippy/tests/ui/if_same_then_else.stderr
index 2cdf44248..fb23b81d3 100644
--- a/src/tools/clippy/tests/ui/if_same_then_else.stderr
+++ b/src/tools/clippy/tests/ui/if_same_then_else.stderr
@@ -11,7 +11,6 @@ LL | | foo();
LL | | } else {
| |_____^
|
- = note: `-D clippy::if-same-then-else` implied by `-D warnings`
note: same as this
--> $DIR/if_same_then_else.rs:31:12
|
@@ -24,6 +23,7 @@ LL | | 0..10;
LL | | foo();
LL | | }
| |_____^
+ = note: `-D clippy::if-same-then-else` implied by `-D warnings`
error: this `if` has identical blocks
--> $DIR/if_same_then_else.rs:67:21
diff --git a/src/tools/clippy/tests/ui/if_same_then_else2.stderr b/src/tools/clippy/tests/ui/if_same_then_else2.stderr
index cac788f85..704cfd966 100644
--- a/src/tools/clippy/tests/ui/if_same_then_else2.stderr
+++ b/src/tools/clippy/tests/ui/if_same_then_else2.stderr
@@ -11,7 +11,6 @@ LL | | }
LL | | } else {
| |_____^
|
- = note: `-D clippy::if-same-then-else` implied by `-D warnings`
note: same as this
--> $DIR/if_same_then_else2.rs:23:12
|
@@ -24,6 +23,7 @@ LL | | let bar: &Option<_> = &Some::<u8>(42);
LL | | }
LL | | }
| |_____^
+ = note: `-D clippy::if-same-then-else` implied by `-D warnings`
error: this `if` has identical blocks
--> $DIR/if_same_then_else2.rs:35:13
diff --git a/src/tools/clippy/tests/ui/if_then_some_else_none.stderr b/src/tools/clippy/tests/ui/if_then_some_else_none.stderr
index c22ace30d..24e0b5947 100644
--- a/src/tools/clippy/tests/ui/if_then_some_else_none.stderr
+++ b/src/tools/clippy/tests/ui/if_then_some_else_none.stderr
@@ -10,8 +10,8 @@ LL | | None
LL | | };
| |_____^
|
- = note: `-D clippy::if-then-some-else-none` implied by `-D warnings`
= help: consider using `bool::then` like: `foo().then(|| { /* snippet */ "foo" })`
+ = note: `-D clippy::if-then-some-else-none` implied by `-D warnings`
error: this could be simplified with `bool::then`
--> $DIR/if_then_some_else_none.rs:14:13
diff --git a/src/tools/clippy/tests/ui/ifs_same_cond.stderr b/src/tools/clippy/tests/ui/ifs_same_cond.stderr
index 0c8f49b86..411308732 100644
--- a/src/tools/clippy/tests/ui/ifs_same_cond.stderr
+++ b/src/tools/clippy/tests/ui/ifs_same_cond.stderr
@@ -4,12 +4,12 @@ error: this `if` has the same condition as a previous `if`
LL | } else if b {
| ^
|
- = note: `-D clippy::ifs-same-cond` implied by `-D warnings`
note: same as this
--> $DIR/ifs_same_cond.rs:8:8
|
LL | if b {
| ^
+ = note: `-D clippy::ifs-same-cond` implied by `-D warnings`
error: this `if` has the same condition as a previous `if`
--> $DIR/ifs_same_cond.rs:14:15
diff --git a/src/tools/clippy/tests/ui/impl.stderr b/src/tools/clippy/tests/ui/impl.stderr
index 8703ecac9..e28b1bf0c 100644
--- a/src/tools/clippy/tests/ui/impl.stderr
+++ b/src/tools/clippy/tests/ui/impl.stderr
@@ -6,7 +6,6 @@ LL | | fn second() {}
LL | | }
| |_^
|
- = note: `-D clippy::multiple-inherent-impl` implied by `-D warnings`
note: first implementation here
--> $DIR/impl.rs:6:1
|
@@ -14,6 +13,7 @@ LL | / impl MyStruct {
LL | | fn first() {}
LL | | }
| |_^
+ = note: `-D clippy::multiple-inherent-impl` implied by `-D warnings`
error: multiple implementations of this structure
--> $DIR/impl.rs:24:5
diff --git a/src/tools/clippy/tests/ui/implicit_saturating_add.fixed b/src/tools/clippy/tests/ui/implicit_saturating_add.fixed
new file mode 100644
index 000000000..7d363d59a
--- /dev/null
+++ b/src/tools/clippy/tests/ui/implicit_saturating_add.fixed
@@ -0,0 +1,106 @@
+// run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::implicit_saturating_add)]
+
+fn main() {
+ let mut u_8: u8 = 255;
+ let mut u_16: u16 = 500;
+ let mut u_32: u32 = 7000;
+ let mut u_64: u64 = 7000;
+ let mut i_8: i8 = 30;
+ let mut i_16: i16 = 500;
+ let mut i_32: i32 = 7000;
+ let mut i_64: i64 = 7000;
+
+ if i_8 < 42 {
+ i_8 += 1;
+ }
+ if i_8 != 42 {
+ i_8 += 1;
+ }
+
+ u_8 = u_8.saturating_add(1);
+
+ u_8 = u_8.saturating_add(1);
+
+ if u_8 < 15 {
+ u_8 += 1;
+ }
+
+ u_16 = u_16.saturating_add(1);
+
+ u_16 = u_16.saturating_add(1);
+
+ u_16 = u_16.saturating_add(1);
+
+ u_32 = u_32.saturating_add(1);
+
+ u_32 = u_32.saturating_add(1);
+
+ u_32 = u_32.saturating_add(1);
+
+ u_64 = u_64.saturating_add(1);
+
+ u_64 = u_64.saturating_add(1);
+
+ u_64 = u_64.saturating_add(1);
+
+ i_8 = i_8.saturating_add(1);
+
+ i_8 = i_8.saturating_add(1);
+
+ i_8 = i_8.saturating_add(1);
+
+ i_16 = i_16.saturating_add(1);
+
+ i_16 = i_16.saturating_add(1);
+
+ i_16 = i_16.saturating_add(1);
+
+ i_32 = i_32.saturating_add(1);
+
+ i_32 = i_32.saturating_add(1);
+
+ i_32 = i_32.saturating_add(1);
+
+ i_64 = i_64.saturating_add(1);
+
+ i_64 = i_64.saturating_add(1);
+
+ i_64 = i_64.saturating_add(1);
+
+ if i_64 < 42 {
+ i_64 += 1;
+ }
+
+ if 42 > i_64 {
+ i_64 += 1;
+ }
+
+ let a = 12;
+ let mut b = 8;
+
+ if a < u8::MAX {
+ b += 1;
+ }
+
+ if u8::MAX > a {
+ b += 1;
+ }
+
+ if u_32 < u32::MAX {
+ u_32 += 1;
+ } else {
+ println!("don't lint this");
+ }
+
+ if u_32 < u32::MAX {
+ println!("don't lint this");
+ u_32 += 1;
+ }
+
+ if u_32 < 42 {
+ println!("brace yourself!");
+ } else {u_32 = u_32.saturating_add(1); }
+}
diff --git a/src/tools/clippy/tests/ui/implicit_saturating_add.rs b/src/tools/clippy/tests/ui/implicit_saturating_add.rs
new file mode 100644
index 000000000..31a591627
--- /dev/null
+++ b/src/tools/clippy/tests/ui/implicit_saturating_add.rs
@@ -0,0 +1,154 @@
+// run-rustfix
+
+#![allow(unused)]
+#![warn(clippy::implicit_saturating_add)]
+
+fn main() {
+ let mut u_8: u8 = 255;
+ let mut u_16: u16 = 500;
+ let mut u_32: u32 = 7000;
+ let mut u_64: u64 = 7000;
+ let mut i_8: i8 = 30;
+ let mut i_16: i16 = 500;
+ let mut i_32: i32 = 7000;
+ let mut i_64: i64 = 7000;
+
+ if i_8 < 42 {
+ i_8 += 1;
+ }
+ if i_8 != 42 {
+ i_8 += 1;
+ }
+
+ if u_8 != u8::MAX {
+ u_8 += 1;
+ }
+
+ if u_8 < u8::MAX {
+ u_8 += 1;
+ }
+
+ if u_8 < 15 {
+ u_8 += 1;
+ }
+
+ if u_16 != u16::MAX {
+ u_16 += 1;
+ }
+
+ if u_16 < u16::MAX {
+ u_16 += 1;
+ }
+
+ if u16::MAX > u_16 {
+ u_16 += 1;
+ }
+
+ if u_32 != u32::MAX {
+ u_32 += 1;
+ }
+
+ if u_32 < u32::MAX {
+ u_32 += 1;
+ }
+
+ if u32::MAX > u_32 {
+ u_32 += 1;
+ }
+
+ if u_64 != u64::MAX {
+ u_64 += 1;
+ }
+
+ if u_64 < u64::MAX {
+ u_64 += 1;
+ }
+
+ if u64::MAX > u_64 {
+ u_64 += 1;
+ }
+
+ if i_8 != i8::MAX {
+ i_8 += 1;
+ }
+
+ if i_8 < i8::MAX {
+ i_8 += 1;
+ }
+
+ if i8::MAX > i_8 {
+ i_8 += 1;
+ }
+
+ if i_16 != i16::MAX {
+ i_16 += 1;
+ }
+
+ if i_16 < i16::MAX {
+ i_16 += 1;
+ }
+
+ if i16::MAX > i_16 {
+ i_16 += 1;
+ }
+
+ if i_32 != i32::MAX {
+ i_32 += 1;
+ }
+
+ if i_32 < i32::MAX {
+ i_32 += 1;
+ }
+
+ if i32::MAX > i_32 {
+ i_32 += 1;
+ }
+
+ if i_64 != i64::MAX {
+ i_64 += 1;
+ }
+
+ if i_64 < i64::MAX {
+ i_64 += 1;
+ }
+
+ if i64::MAX > i_64 {
+ i_64 += 1;
+ }
+
+ if i_64 < 42 {
+ i_64 += 1;
+ }
+
+ if 42 > i_64 {
+ i_64 += 1;
+ }
+
+ let a = 12;
+ let mut b = 8;
+
+ if a < u8::MAX {
+ b += 1;
+ }
+
+ if u8::MAX > a {
+ b += 1;
+ }
+
+ if u_32 < u32::MAX {
+ u_32 += 1;
+ } else {
+ println!("don't lint this");
+ }
+
+ if u_32 < u32::MAX {
+ println!("don't lint this");
+ u_32 += 1;
+ }
+
+ if u_32 < 42 {
+ println!("brace yourself!");
+ } else if u_32 < u32::MAX {
+ u_32 += 1;
+ }
+}
diff --git a/src/tools/clippy/tests/ui/implicit_saturating_add.stderr b/src/tools/clippy/tests/ui/implicit_saturating_add.stderr
new file mode 100644
index 000000000..42ae1b488
--- /dev/null
+++ b/src/tools/clippy/tests/ui/implicit_saturating_add.stderr
@@ -0,0 +1,197 @@
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:23:5
+ |
+LL | / if u_8 != u8::MAX {
+LL | | u_8 += 1;
+LL | | }
+ | |_____^ help: use instead: `u_8 = u_8.saturating_add(1);`
+ |
+ = note: `-D clippy::implicit-saturating-add` implied by `-D warnings`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:27:5
+ |
+LL | / if u_8 < u8::MAX {
+LL | | u_8 += 1;
+LL | | }
+ | |_____^ help: use instead: `u_8 = u_8.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:35:5
+ |
+LL | / if u_16 != u16::MAX {
+LL | | u_16 += 1;
+LL | | }
+ | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:39:5
+ |
+LL | / if u_16 < u16::MAX {
+LL | | u_16 += 1;
+LL | | }
+ | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:43:5
+ |
+LL | / if u16::MAX > u_16 {
+LL | | u_16 += 1;
+LL | | }
+ | |_____^ help: use instead: `u_16 = u_16.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:47:5
+ |
+LL | / if u_32 != u32::MAX {
+LL | | u_32 += 1;
+LL | | }
+ | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:51:5
+ |
+LL | / if u_32 < u32::MAX {
+LL | | u_32 += 1;
+LL | | }
+ | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:55:5
+ |
+LL | / if u32::MAX > u_32 {
+LL | | u_32 += 1;
+LL | | }
+ | |_____^ help: use instead: `u_32 = u_32.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:59:5
+ |
+LL | / if u_64 != u64::MAX {
+LL | | u_64 += 1;
+LL | | }
+ | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:63:5
+ |
+LL | / if u_64 < u64::MAX {
+LL | | u_64 += 1;
+LL | | }
+ | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:67:5
+ |
+LL | / if u64::MAX > u_64 {
+LL | | u_64 += 1;
+LL | | }
+ | |_____^ help: use instead: `u_64 = u_64.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:71:5
+ |
+LL | / if i_8 != i8::MAX {
+LL | | i_8 += 1;
+LL | | }
+ | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:75:5
+ |
+LL | / if i_8 < i8::MAX {
+LL | | i_8 += 1;
+LL | | }
+ | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:79:5
+ |
+LL | / if i8::MAX > i_8 {
+LL | | i_8 += 1;
+LL | | }
+ | |_____^ help: use instead: `i_8 = i_8.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:83:5
+ |
+LL | / if i_16 != i16::MAX {
+LL | | i_16 += 1;
+LL | | }
+ | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:87:5
+ |
+LL | / if i_16 < i16::MAX {
+LL | | i_16 += 1;
+LL | | }
+ | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:91:5
+ |
+LL | / if i16::MAX > i_16 {
+LL | | i_16 += 1;
+LL | | }
+ | |_____^ help: use instead: `i_16 = i_16.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:95:5
+ |
+LL | / if i_32 != i32::MAX {
+LL | | i_32 += 1;
+LL | | }
+ | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:99:5
+ |
+LL | / if i_32 < i32::MAX {
+LL | | i_32 += 1;
+LL | | }
+ | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:103:5
+ |
+LL | / if i32::MAX > i_32 {
+LL | | i_32 += 1;
+LL | | }
+ | |_____^ help: use instead: `i_32 = i_32.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:107:5
+ |
+LL | / if i_64 != i64::MAX {
+LL | | i_64 += 1;
+LL | | }
+ | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:111:5
+ |
+LL | / if i_64 < i64::MAX {
+LL | | i_64 += 1;
+LL | | }
+ | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:115:5
+ |
+LL | / if i64::MAX > i_64 {
+LL | | i_64 += 1;
+LL | | }
+ | |_____^ help: use instead: `i_64 = i_64.saturating_add(1);`
+
+error: manual saturating add detected
+ --> $DIR/implicit_saturating_add.rs:151:12
+ |
+LL | } else if u_32 < u32::MAX {
+ | ____________^
+LL | | u_32 += 1;
+LL | | }
+ | |_____^ help: use instead: `{u_32 = u_32.saturating_add(1); }`
+
+error: aborting due to 24 previous errors
+
diff --git a/src/tools/clippy/tests/ui/implicit_saturating_sub.fixed b/src/tools/clippy/tests/ui/implicit_saturating_sub.fixed
index e6f57e926..93df81b1a 100644
--- a/src/tools/clippy/tests/ui/implicit_saturating_sub.fixed
+++ b/src/tools/clippy/tests/ui/implicit_saturating_sub.fixed
@@ -2,6 +2,21 @@
#![allow(unused_assignments, unused_mut, clippy::assign_op_pattern)]
#![warn(clippy::implicit_saturating_sub)]
+use std::cmp::PartialEq;
+use std::ops::SubAssign;
+// Mock type
+struct Mock;
+
+impl PartialEq<u32> for Mock {
+ fn eq(&self, _: &u32) -> bool {
+ true
+ }
+}
+
+impl SubAssign<u32> for Mock {
+ fn sub_assign(&mut self, _: u32) {}
+}
+
fn main() {
// Tests for unsigned integers
@@ -165,4 +180,39 @@ fn main() {
} else {
println!("side effect");
}
+
+ // Extended tests
+ let mut m = Mock;
+ let mut u_32 = 3000;
+ let a = 200;
+ let mut _b = 8;
+
+ if m != 0 {
+ m -= 1;
+ }
+
+ if a > 0 {
+ _b -= 1;
+ }
+
+ if 0 > a {
+ _b -= 1;
+ }
+
+ if u_32 > 0 {
+ u_32 -= 1;
+ } else {
+ println!("don't lint this");
+ }
+
+ if u_32 > 0 {
+ println!("don't lint this");
+ u_32 -= 1;
+ }
+
+ if u_32 > 42 {
+ println!("brace yourself!");
+ } else if u_32 > 0 {
+ u_32 -= 1;
+ }
}
diff --git a/src/tools/clippy/tests/ui/implicit_saturating_sub.rs b/src/tools/clippy/tests/ui/implicit_saturating_sub.rs
index 8bb28d149..8340bc826 100644
--- a/src/tools/clippy/tests/ui/implicit_saturating_sub.rs
+++ b/src/tools/clippy/tests/ui/implicit_saturating_sub.rs
@@ -2,6 +2,21 @@
#![allow(unused_assignments, unused_mut, clippy::assign_op_pattern)]
#![warn(clippy::implicit_saturating_sub)]
+use std::cmp::PartialEq;
+use std::ops::SubAssign;
+// Mock type
+struct Mock;
+
+impl PartialEq<u32> for Mock {
+ fn eq(&self, _: &u32) -> bool {
+ true
+ }
+}
+
+impl SubAssign<u32> for Mock {
+ fn sub_assign(&mut self, _: u32) {}
+}
+
fn main() {
// Tests for unsigned integers
@@ -211,4 +226,39 @@ fn main() {
} else {
println!("side effect");
}
+
+ // Extended tests
+ let mut m = Mock;
+ let mut u_32 = 3000;
+ let a = 200;
+ let mut _b = 8;
+
+ if m != 0 {
+ m -= 1;
+ }
+
+ if a > 0 {
+ _b -= 1;
+ }
+
+ if 0 > a {
+ _b -= 1;
+ }
+
+ if u_32 > 0 {
+ u_32 -= 1;
+ } else {
+ println!("don't lint this");
+ }
+
+ if u_32 > 0 {
+ println!("don't lint this");
+ u_32 -= 1;
+ }
+
+ if u_32 > 42 {
+ println!("brace yourself!");
+ } else if u_32 > 0 {
+ u_32 -= 1;
+ }
}
diff --git a/src/tools/clippy/tests/ui/implicit_saturating_sub.stderr b/src/tools/clippy/tests/ui/implicit_saturating_sub.stderr
index 5bb9a6064..5e589d931 100644
--- a/src/tools/clippy/tests/ui/implicit_saturating_sub.stderr
+++ b/src/tools/clippy/tests/ui/implicit_saturating_sub.stderr
@@ -1,5 +1,5 @@
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:13:5
+ --> $DIR/implicit_saturating_sub.rs:28:5
|
LL | / if u_8 > 0 {
LL | | u_8 = u_8 - 1;
@@ -9,7 +9,7 @@ LL | | }
= note: `-D clippy::implicit-saturating-sub` implied by `-D warnings`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:20:13
+ --> $DIR/implicit_saturating_sub.rs:35:13
|
LL | / if u_8 > 0 {
LL | | u_8 -= 1;
@@ -17,7 +17,7 @@ LL | | }
| |_____________^ help: try: `u_8 = u_8.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:34:5
+ --> $DIR/implicit_saturating_sub.rs:49:5
|
LL | / if u_16 > 0 {
LL | | u_16 -= 1;
@@ -25,7 +25,7 @@ LL | | }
| |_____^ help: try: `u_16 = u_16.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:44:5
+ --> $DIR/implicit_saturating_sub.rs:59:5
|
LL | / if u_32 != 0 {
LL | | u_32 -= 1;
@@ -33,7 +33,7 @@ LL | | }
| |_____^ help: try: `u_32 = u_32.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:65:5
+ --> $DIR/implicit_saturating_sub.rs:80:5
|
LL | / if u_64 > 0 {
LL | | u_64 -= 1;
@@ -41,7 +41,7 @@ LL | | }
| |_____^ help: try: `u_64 = u_64.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:70:5
+ --> $DIR/implicit_saturating_sub.rs:85:5
|
LL | / if 0 < u_64 {
LL | | u_64 -= 1;
@@ -49,7 +49,7 @@ LL | | }
| |_____^ help: try: `u_64 = u_64.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:75:5
+ --> $DIR/implicit_saturating_sub.rs:90:5
|
LL | / if 0 != u_64 {
LL | | u_64 -= 1;
@@ -57,7 +57,7 @@ LL | | }
| |_____^ help: try: `u_64 = u_64.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:96:5
+ --> $DIR/implicit_saturating_sub.rs:111:5
|
LL | / if u_usize > 0 {
LL | | u_usize -= 1;
@@ -65,7 +65,7 @@ LL | | }
| |_____^ help: try: `u_usize = u_usize.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:108:5
+ --> $DIR/implicit_saturating_sub.rs:123:5
|
LL | / if i_8 > i8::MIN {
LL | | i_8 -= 1;
@@ -73,7 +73,7 @@ LL | | }
| |_____^ help: try: `i_8 = i_8.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:113:5
+ --> $DIR/implicit_saturating_sub.rs:128:5
|
LL | / if i_8 > i8::MIN {
LL | | i_8 -= 1;
@@ -81,7 +81,7 @@ LL | | }
| |_____^ help: try: `i_8 = i_8.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:118:5
+ --> $DIR/implicit_saturating_sub.rs:133:5
|
LL | / if i_8 != i8::MIN {
LL | | i_8 -= 1;
@@ -89,7 +89,7 @@ LL | | }
| |_____^ help: try: `i_8 = i_8.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:123:5
+ --> $DIR/implicit_saturating_sub.rs:138:5
|
LL | / if i_8 != i8::MIN {
LL | | i_8 -= 1;
@@ -97,7 +97,7 @@ LL | | }
| |_____^ help: try: `i_8 = i_8.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:133:5
+ --> $DIR/implicit_saturating_sub.rs:148:5
|
LL | / if i_16 > i16::MIN {
LL | | i_16 -= 1;
@@ -105,7 +105,7 @@ LL | | }
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:138:5
+ --> $DIR/implicit_saturating_sub.rs:153:5
|
LL | / if i_16 > i16::MIN {
LL | | i_16 -= 1;
@@ -113,7 +113,7 @@ LL | | }
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:143:5
+ --> $DIR/implicit_saturating_sub.rs:158:5
|
LL | / if i_16 != i16::MIN {
LL | | i_16 -= 1;
@@ -121,7 +121,7 @@ LL | | }
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:148:5
+ --> $DIR/implicit_saturating_sub.rs:163:5
|
LL | / if i_16 != i16::MIN {
LL | | i_16 -= 1;
@@ -129,7 +129,7 @@ LL | | }
| |_____^ help: try: `i_16 = i_16.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:158:5
+ --> $DIR/implicit_saturating_sub.rs:173:5
|
LL | / if i_32 > i32::MIN {
LL | | i_32 -= 1;
@@ -137,7 +137,7 @@ LL | | }
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:163:5
+ --> $DIR/implicit_saturating_sub.rs:178:5
|
LL | / if i_32 > i32::MIN {
LL | | i_32 -= 1;
@@ -145,7 +145,7 @@ LL | | }
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:168:5
+ --> $DIR/implicit_saturating_sub.rs:183:5
|
LL | / if i_32 != i32::MIN {
LL | | i_32 -= 1;
@@ -153,7 +153,7 @@ LL | | }
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:173:5
+ --> $DIR/implicit_saturating_sub.rs:188:5
|
LL | / if i_32 != i32::MIN {
LL | | i_32 -= 1;
@@ -161,7 +161,7 @@ LL | | }
| |_____^ help: try: `i_32 = i_32.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:183:5
+ --> $DIR/implicit_saturating_sub.rs:198:5
|
LL | / if i64::MIN < i_64 {
LL | | i_64 -= 1;
@@ -169,7 +169,7 @@ LL | | }
| |_____^ help: try: `i_64 = i_64.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:188:5
+ --> $DIR/implicit_saturating_sub.rs:203:5
|
LL | / if i64::MIN != i_64 {
LL | | i_64 -= 1;
@@ -177,7 +177,7 @@ LL | | }
| |_____^ help: try: `i_64 = i_64.saturating_sub(1);`
error: implicitly performing saturating subtraction
- --> $DIR/implicit_saturating_sub.rs:193:5
+ --> $DIR/implicit_saturating_sub.rs:208:5
|
LL | / if i64::MIN < i_64 {
LL | | i_64 -= 1;
diff --git a/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs b/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs
index c2c0c520d..0a3374d11 100644
--- a/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs
+++ b/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs
@@ -1,4 +1,5 @@
#![deny(clippy::index_refutable_slice)]
+#![allow(clippy::uninlined_format_args)]
enum SomeEnum<T> {
One(T),
diff --git a/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.stderr b/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.stderr
index a607df9b8..0a13ac135 100644
--- a/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.stderr
+++ b/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.stderr
@@ -1,5 +1,5 @@
error: this binding can be a slice pattern to avoid indexing
- --> $DIR/if_let_slice_binding.rs:13:17
+ --> $DIR/if_let_slice_binding.rs:14:17
|
LL | if let Some(slice) = slice {
| ^^^^^
@@ -19,7 +19,7 @@ LL | println!("{}", slice_0);
| ~~~~~~~
error: this binding can be a slice pattern to avoid indexing
- --> $DIR/if_let_slice_binding.rs:19:17
+ --> $DIR/if_let_slice_binding.rs:20:17
|
LL | if let Some(slice) = slice {
| ^^^^^
@@ -34,7 +34,7 @@ LL | println!("{}", slice_0);
| ~~~~~~~
error: this binding can be a slice pattern to avoid indexing
- --> $DIR/if_let_slice_binding.rs:25:17
+ --> $DIR/if_let_slice_binding.rs:26:17
|
LL | if let Some(slice) = slice {
| ^^^^^
@@ -50,7 +50,7 @@ LL ~ println!("{}", slice_0);
|
error: this binding can be a slice pattern to avoid indexing
- --> $DIR/if_let_slice_binding.rs:32:26
+ --> $DIR/if_let_slice_binding.rs:33:26
|
LL | if let SomeEnum::One(slice) | SomeEnum::Three(slice) = slice_wrapped {
| ^^^^^
@@ -65,7 +65,7 @@ LL | println!("{}", slice_0);
| ~~~~~~~
error: this binding can be a slice pattern to avoid indexing
- --> $DIR/if_let_slice_binding.rs:39:29
+ --> $DIR/if_let_slice_binding.rs:40:29
|
LL | if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) {
| ^
@@ -80,7 +80,7 @@ LL | println!("{} -> {}", a_2, b[1]);
| ~~~
error: this binding can be a slice pattern to avoid indexing
- --> $DIR/if_let_slice_binding.rs:39:38
+ --> $DIR/if_let_slice_binding.rs:40:38
|
LL | if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) {
| ^
@@ -95,7 +95,7 @@ LL | println!("{} -> {}", a[2], b_1);
| ~~~
error: this binding can be a slice pattern to avoid indexing
- --> $DIR/if_let_slice_binding.rs:46:21
+ --> $DIR/if_let_slice_binding.rs:47:21
|
LL | if let Some(ref slice) = slice {
| ^^^^^
@@ -110,7 +110,7 @@ LL | println!("{:?}", slice_1);
| ~~~~~~~
error: this binding can be a slice pattern to avoid indexing
- --> $DIR/if_let_slice_binding.rs:54:17
+ --> $DIR/if_let_slice_binding.rs:55:17
|
LL | if let Some(slice) = &slice {
| ^^^^^
@@ -125,7 +125,7 @@ LL | println!("{:?}", slice_0);
| ~~~~~~~
error: this binding can be a slice pattern to avoid indexing
- --> $DIR/if_let_slice_binding.rs:123:17
+ --> $DIR/if_let_slice_binding.rs:124:17
|
LL | if let Some(slice) = wrap.inner {
| ^^^^^
@@ -140,7 +140,7 @@ LL | println!("This is awesome! {}", slice_0);
| ~~~~~~~
error: this binding can be a slice pattern to avoid indexing
- --> $DIR/if_let_slice_binding.rs:130:17
+ --> $DIR/if_let_slice_binding.rs:131:17
|
LL | if let Some(slice) = wrap.inner {
| ^^^^^
diff --git a/src/tools/clippy/tests/ui/indexing_slicing_index.rs b/src/tools/clippy/tests/ui/indexing_slicing_index.rs
index 7ebf6ee99..4476e0eb9 100644
--- a/src/tools/clippy/tests/ui/indexing_slicing_index.rs
+++ b/src/tools/clippy/tests/ui/indexing_slicing_index.rs
@@ -3,7 +3,7 @@
// We also check the out_of_bounds_indexing lint here, because it lints similar things and
// we want to avoid false positives.
#![warn(clippy::out_of_bounds_indexing)]
-#![allow(const_err, unconditional_panic, clippy::no_effect, clippy::unnecessary_operation)]
+#![allow(unconditional_panic, clippy::no_effect, clippy::unnecessary_operation)]
const ARR: [i32; 2] = [1, 2];
const REF: &i32 = &ARR[idx()]; // Ok, should not produce stderr.
diff --git a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
index 6ae700753..da5bc38b3 100644
--- a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
+++ b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
@@ -16,8 +16,8 @@ error: indexing may panic
LL | x[index];
| ^^^^^^^^
|
- = note: `-D clippy::indexing-slicing` implied by `-D warnings`
= help: consider using `.get(n)` or `.get_mut(n)` instead
+ = note: `-D clippy::indexing-slicing` implied by `-D warnings`
error: indexing may panic
--> $DIR/indexing_slicing_index.rs:38:5
@@ -59,6 +59,12 @@ LL | v[M];
|
= help: consider using `.get(n)` or `.get_mut(n)` instead
-error: aborting due to 8 previous errors
+error[E0080]: evaluation of constant value failed
+ --> $DIR/indexing_slicing_index.rs:10:24
+ |
+LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
+ | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
+
+error: aborting due to 9 previous errors
For more information about this error, try `rustc --explain E0080`.
diff --git a/src/tools/clippy/tests/ui/indexing_slicing_slice.stderr b/src/tools/clippy/tests/ui/indexing_slicing_slice.stderr
index f70722b92..dc54bd413 100644
--- a/src/tools/clippy/tests/ui/indexing_slicing_slice.stderr
+++ b/src/tools/clippy/tests/ui/indexing_slicing_slice.stderr
@@ -4,8 +4,8 @@ error: slicing may panic
LL | &x[index..];
| ^^^^^^^^^^
|
- = note: `-D clippy::indexing-slicing` implied by `-D warnings`
= help: consider using `.get(n..)` or .get_mut(n..)` instead
+ = note: `-D clippy::indexing-slicing` implied by `-D warnings`
error: slicing may panic
--> $DIR/indexing_slicing_slice.rs:13:6
diff --git a/src/tools/clippy/tests/ui/inefficient_to_string.stderr b/src/tools/clippy/tests/ui/inefficient_to_string.stderr
index 4be46161e..914dc92bf 100644
--- a/src/tools/clippy/tests/ui/inefficient_to_string.stderr
+++ b/src/tools/clippy/tests/ui/inefficient_to_string.stderr
@@ -4,12 +4,12 @@ error: calling `to_string` on `&&str`
LL | let _: String = rrstr.to_string();
| ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrstr).to_string()`
|
+ = help: `&str` implements `ToString` through a slower blanket impl, but `str` has a fast specialization of `ToString`
note: the lint level is defined here
--> $DIR/inefficient_to_string.rs:2:9
|
LL | #![deny(clippy::inefficient_to_string)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: `&str` implements `ToString` through a slower blanket impl, but `str` has a fast specialization of `ToString`
error: calling `to_string` on `&&&str`
--> $DIR/inefficient_to_string.rs:12:21
@@ -35,21 +35,21 @@ LL | let _: String = rrrstring.to_string();
|
= help: `&&std::string::String` implements `ToString` through a slower blanket impl, but `std::string::String` has a fast specialization of `ToString`
-error: calling `to_string` on `&&std::borrow::Cow<str>`
+error: calling `to_string` on `&&std::borrow::Cow<'_, str>`
--> $DIR/inefficient_to_string.rs:29:21
|
LL | let _: String = rrcow.to_string();
| ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrcow).to_string()`
|
- = help: `&std::borrow::Cow<str>` implements `ToString` through a slower blanket impl, but `std::borrow::Cow<str>` has a fast specialization of `ToString`
+ = help: `&std::borrow::Cow<'_, str>` implements `ToString` through a slower blanket impl, but `std::borrow::Cow<'_, str>` has a fast specialization of `ToString`
-error: calling `to_string` on `&&&std::borrow::Cow<str>`
+error: calling `to_string` on `&&&std::borrow::Cow<'_, str>`
--> $DIR/inefficient_to_string.rs:30:21
|
LL | let _: String = rrrcow.to_string();
| ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrcow).to_string()`
|
- = help: `&&std::borrow::Cow<str>` implements `ToString` through a slower blanket impl, but `std::borrow::Cow<str>` has a fast specialization of `ToString`
+ = help: `&&std::borrow::Cow<'_, str>` implements `ToString` through a slower blanket impl, but `std::borrow::Cow<'_, str>` has a fast specialization of `ToString`
error: aborting due to 6 previous errors
diff --git a/src/tools/clippy/tests/ui/infinite_iter.rs b/src/tools/clippy/tests/ui/infinite_iter.rs
index a1e5fad0c..622644f67 100644
--- a/src/tools/clippy/tests/ui/infinite_iter.rs
+++ b/src/tools/clippy/tests/ui/infinite_iter.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::uninlined_format_args)]
+
use std::iter::repeat;
fn square_is_lower_64(x: &u32) -> bool {
x * x < 64
diff --git a/src/tools/clippy/tests/ui/infinite_iter.stderr b/src/tools/clippy/tests/ui/infinite_iter.stderr
index ba277e363..b911163f7 100644
--- a/src/tools/clippy/tests/ui/infinite_iter.stderr
+++ b/src/tools/clippy/tests/ui/infinite_iter.stderr
@@ -1,29 +1,29 @@
error: infinite iteration detected
- --> $DIR/infinite_iter.rs:9:5
+ --> $DIR/infinite_iter.rs:11:5
|
LL | repeat(0_u8).collect::<Vec<_>>(); // infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
- --> $DIR/infinite_iter.rs:7:8
+ --> $DIR/infinite_iter.rs:9:8
|
LL | #[deny(clippy::infinite_iter)]
| ^^^^^^^^^^^^^^^^^^^^^
error: infinite iteration detected
- --> $DIR/infinite_iter.rs:10:5
+ --> $DIR/infinite_iter.rs:12:5
|
LL | (0..8_u32).take_while(square_is_lower_64).cycle().count(); // infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: infinite iteration detected
- --> $DIR/infinite_iter.rs:11:5
+ --> $DIR/infinite_iter.rs:13:5
|
LL | (0..8_u64).chain(0..).max(); // infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: infinite iteration detected
- --> $DIR/infinite_iter.rs:16:5
+ --> $DIR/infinite_iter.rs:18:5
|
LL | / (0..8_u32)
LL | | .rev()
@@ -33,37 +33,37 @@ LL | | .for_each(|x| println!("{}", x)); // infinite iter
| |________________________________________^
error: infinite iteration detected
- --> $DIR/infinite_iter.rs:22:5
+ --> $DIR/infinite_iter.rs:24:5
|
LL | (0_usize..).flat_map(|x| 0..x).product::<usize>(); // infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: infinite iteration detected
- --> $DIR/infinite_iter.rs:23:5
+ --> $DIR/infinite_iter.rs:25:5
|
LL | (0_u64..).filter(|x| x % 2 == 0).last(); // infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: possible infinite iteration detected
- --> $DIR/infinite_iter.rs:30:5
+ --> $DIR/infinite_iter.rs:32:5
|
LL | (0..).zip((0..).take_while(square_is_lower_64)).count(); // maybe infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
- --> $DIR/infinite_iter.rs:28:8
+ --> $DIR/infinite_iter.rs:30:8
|
LL | #[deny(clippy::maybe_infinite_iter)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: possible infinite iteration detected
- --> $DIR/infinite_iter.rs:31:5
+ --> $DIR/infinite_iter.rs:33:5
|
LL | repeat(42).take_while(|x| *x == 42).chain(0..42).max(); // maybe infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: possible infinite iteration detected
- --> $DIR/infinite_iter.rs:32:5
+ --> $DIR/infinite_iter.rs:34:5
|
LL | / (1..)
LL | | .scan(0, |state, x| {
@@ -74,31 +74,31 @@ LL | | .min(); // maybe infinite iter
| |______________^
error: possible infinite iteration detected
- --> $DIR/infinite_iter.rs:38:5
+ --> $DIR/infinite_iter.rs:40:5
|
LL | (0..).find(|x| *x == 24); // maybe infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: possible infinite iteration detected
- --> $DIR/infinite_iter.rs:39:5
+ --> $DIR/infinite_iter.rs:41:5
|
LL | (0..).position(|x| x == 24); // maybe infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: possible infinite iteration detected
- --> $DIR/infinite_iter.rs:40:5
+ --> $DIR/infinite_iter.rs:42:5
|
LL | (0..).any(|x| x == 24); // maybe infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^
error: possible infinite iteration detected
- --> $DIR/infinite_iter.rs:41:5
+ --> $DIR/infinite_iter.rs:43:5
|
LL | (0..).all(|x| x == 24); // maybe infinite iter
| ^^^^^^^^^^^^^^^^^^^^^^
error: infinite iteration detected
- --> $DIR/infinite_iter.rs:63:31
+ --> $DIR/infinite_iter.rs:65:31
|
LL | let _: HashSet<i32> = (0..).collect(); // Infinite iter
| ^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/infinite_loop.stderr b/src/tools/clippy/tests/ui/infinite_loop.stderr
index 4ec7d900a..85258b9d6 100644
--- a/src/tools/clippy/tests/ui/infinite_loop.stderr
+++ b/src/tools/clippy/tests/ui/infinite_loop.stderr
@@ -4,8 +4,8 @@ error: variables in the condition are not mutated in the loop body
LL | while y < 10 {
| ^^^^^^
|
- = note: `#[deny(clippy::while_immutable_condition)]` on by default
= note: this may lead to an infinite or to a never running loop
+ = note: `#[deny(clippy::while_immutable_condition)]` on by default
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:25:11
diff --git a/src/tools/clippy/tests/ui/inherent_to_string.stderr b/src/tools/clippy/tests/ui/inherent_to_string.stderr
index 4f331f5be..443fecae1 100644
--- a/src/tools/clippy/tests/ui/inherent_to_string.stderr
+++ b/src/tools/clippy/tests/ui/inherent_to_string.stderr
@@ -6,8 +6,8 @@ LL | | "A.to_string()".to_string()
LL | | }
| |_____^
|
- = note: `-D clippy::inherent-to-string` implied by `-D warnings`
= help: implement trait `Display` for type `A` instead
+ = note: `-D clippy::inherent-to-string` implied by `-D warnings`
error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`
--> $DIR/inherent_to_string.rs:44:5
@@ -17,12 +17,12 @@ LL | | "C.to_string()".to_string()
LL | | }
| |_____^
|
+ = help: remove the inherent method from type `C`
note: the lint level is defined here
--> $DIR/inherent_to_string.rs:2:9
|
LL | #![deny(clippy::inherent_to_string_shadow_display)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: remove the inherent method from type `C`
error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/inspect_for_each.stderr b/src/tools/clippy/tests/ui/inspect_for_each.stderr
index 9f976bb74..67c2d5e53 100644
--- a/src/tools/clippy/tests/ui/inspect_for_each.stderr
+++ b/src/tools/clippy/tests/ui/inspect_for_each.stderr
@@ -9,8 +9,8 @@ LL | | b.push(z);
LL | | });
| |______^
|
- = note: `-D clippy::inspect-for-each` implied by `-D warnings`
= help: move the code from `inspect(..)` to `for_each(..)` and remove the `inspect(..)`
+ = note: `-D clippy::inspect-for-each` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/integer_division.stderr b/src/tools/clippy/tests/ui/integer_division.stderr
index cbb7f8814..ca8001279 100644
--- a/src/tools/clippy/tests/ui/integer_division.stderr
+++ b/src/tools/clippy/tests/ui/integer_division.stderr
@@ -4,8 +4,8 @@ error: integer division
LL | let n = 1 / 2;
| ^^^^^
|
- = note: `-D clippy::integer-division` implied by `-D warnings`
= help: division of integers may cause loss of precision. consider using floats
+ = note: `-D clippy::integer-division` implied by `-D warnings`
error: integer division
--> $DIR/integer_division.rs:6:13
diff --git a/src/tools/clippy/tests/ui/issue_2356.fixed b/src/tools/clippy/tests/ui/issue_2356.fixed
index 942e99fa8..a73ee0fb2 100644
--- a/src/tools/clippy/tests/ui/issue_2356.fixed
+++ b/src/tools/clippy/tests/ui/issue_2356.fixed
@@ -1,6 +1,7 @@
// run-rustfix
#![deny(clippy::while_let_on_iterator)]
#![allow(unused_mut)]
+#![allow(clippy::uninlined_format_args)]
use std::iter::Iterator;
diff --git a/src/tools/clippy/tests/ui/issue_2356.rs b/src/tools/clippy/tests/ui/issue_2356.rs
index b000234ea..9dd906960 100644
--- a/src/tools/clippy/tests/ui/issue_2356.rs
+++ b/src/tools/clippy/tests/ui/issue_2356.rs
@@ -1,6 +1,7 @@
// run-rustfix
#![deny(clippy::while_let_on_iterator)]
#![allow(unused_mut)]
+#![allow(clippy::uninlined_format_args)]
use std::iter::Iterator;
diff --git a/src/tools/clippy/tests/ui/issue_2356.stderr b/src/tools/clippy/tests/ui/issue_2356.stderr
index 4e3ff7522..a24b0b32e 100644
--- a/src/tools/clippy/tests/ui/issue_2356.stderr
+++ b/src/tools/clippy/tests/ui/issue_2356.stderr
@@ -1,5 +1,5 @@
error: this loop could be written as a `for` loop
- --> $DIR/issue_2356.rs:17:9
+ --> $DIR/issue_2356.rs:18:9
|
LL | while let Some(e) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for e in it`
diff --git a/src/tools/clippy/tests/ui/issue_4266.rs b/src/tools/clippy/tests/ui/issue_4266.rs
index d9d48189b..8e0620e52 100644
--- a/src/tools/clippy/tests/ui/issue_4266.rs
+++ b/src/tools/clippy/tests/ui/issue_4266.rs
@@ -1,4 +1,5 @@
#![allow(dead_code)]
+#![allow(clippy::uninlined_format_args)]
async fn sink1<'a>(_: &'a str) {} // lint
async fn sink1_elided(_: &str) {} // ok
diff --git a/src/tools/clippy/tests/ui/issue_4266.stderr b/src/tools/clippy/tests/ui/issue_4266.stderr
index e5042aaa7..fb2a93c95 100644
--- a/src/tools/clippy/tests/ui/issue_4266.stderr
+++ b/src/tools/clippy/tests/ui/issue_4266.stderr
@@ -1,5 +1,5 @@
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/issue_4266.rs:3:1
+ --> $DIR/issue_4266.rs:4:1
|
LL | async fn sink1<'a>(_: &'a str) {} // lint
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -7,19 +7,19 @@ LL | async fn sink1<'a>(_: &'a str) {} // lint
= note: `-D clippy::needless-lifetimes` implied by `-D warnings`
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
- --> $DIR/issue_4266.rs:7:1
+ --> $DIR/issue_4266.rs:8:1
|
LL | async fn one_to_one<'a>(s: &'a str) -> &'a str {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: methods called `new` usually take no `self`
- --> $DIR/issue_4266.rs:27:22
+ --> $DIR/issue_4266.rs:28:22
|
LL | pub async fn new(&mut self) -> Self {
| ^^^^^^^^^
|
- = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
= help: consider choosing a less ambiguous name
+ = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
error: aborting due to 3 previous errors
diff --git a/src/tools/clippy/tests/ui/item_after_statement.rs b/src/tools/clippy/tests/ui/item_after_statement.rs
index d439ca1e4..5e92dcab1 100644
--- a/src/tools/clippy/tests/ui/item_after_statement.rs
+++ b/src/tools/clippy/tests/ui/item_after_statement.rs
@@ -1,4 +1,5 @@
#![warn(clippy::items_after_statements)]
+#![allow(clippy::uninlined_format_args)]
fn ok() {
fn foo() {
diff --git a/src/tools/clippy/tests/ui/item_after_statement.stderr b/src/tools/clippy/tests/ui/item_after_statement.stderr
index ab4a6374c..2523c53ac 100644
--- a/src/tools/clippy/tests/ui/item_after_statement.stderr
+++ b/src/tools/clippy/tests/ui/item_after_statement.stderr
@@ -1,5 +1,5 @@
error: adding items after statements is confusing, since items exist from the start of the scope
- --> $DIR/item_after_statement.rs:12:5
+ --> $DIR/item_after_statement.rs:13:5
|
LL | / fn foo() {
LL | | println!("foo");
@@ -9,7 +9,7 @@ LL | | }
= note: `-D clippy::items-after-statements` implied by `-D warnings`
error: adding items after statements is confusing, since items exist from the start of the scope
- --> $DIR/item_after_statement.rs:19:5
+ --> $DIR/item_after_statement.rs:20:5
|
LL | / fn foo() {
LL | | println!("foo");
@@ -17,7 +17,7 @@ LL | | }
| |_____^
error: adding items after statements is confusing, since items exist from the start of the scope
- --> $DIR/item_after_statement.rs:32:13
+ --> $DIR/item_after_statement.rs:33:13
|
LL | / fn say_something() {
LL | | println!("something");
diff --git a/src/tools/clippy/tests/ui/iter_kv_map.fixed b/src/tools/clippy/tests/ui/iter_kv_map.fixed
new file mode 100644
index 000000000..83fee0408
--- /dev/null
+++ b/src/tools/clippy/tests/ui/iter_kv_map.fixed
@@ -0,0 +1,64 @@
+// run-rustfix
+
+#![warn(clippy::iter_kv_map)]
+#![allow(clippy::redundant_clone)]
+#![allow(clippy::suspicious_map)]
+#![allow(clippy::map_identity)]
+
+use std::collections::{BTreeMap, HashMap};
+
+fn main() {
+ let get_key = |(key, _val)| key;
+
+ let map: HashMap<u32, u32> = HashMap::new();
+
+ let _ = map.keys().collect::<Vec<_>>();
+ let _ = map.values().collect::<Vec<_>>();
+ let _ = map.values().map(|v| v + 2).collect::<Vec<_>>();
+
+ let _ = map.clone().into_keys().collect::<Vec<_>>();
+ let _ = map.clone().into_keys().map(|key| key + 2).collect::<Vec<_>>();
+
+ let _ = map.clone().into_values().collect::<Vec<_>>();
+ let _ = map.clone().into_values().map(|val| val + 2).collect::<Vec<_>>();
+
+ let _ = map.clone().values().collect::<Vec<_>>();
+ let _ = map.keys().filter(|x| *x % 2 == 0).count();
+
+ // Don't lint
+ let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
+ let _ = map.iter().map(get_key).collect::<Vec<_>>();
+
+ // Linting the following could be an improvement to the lint
+ // map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
+
+ // Lint
+ let _ = map.keys().map(|key| key * 9).count();
+ let _ = map.values().map(|value| value * 17).count();
+
+ let map: BTreeMap<u32, u32> = BTreeMap::new();
+
+ let _ = map.keys().collect::<Vec<_>>();
+ let _ = map.values().collect::<Vec<_>>();
+ let _ = map.values().map(|v| v + 2).collect::<Vec<_>>();
+
+ let _ = map.clone().into_keys().collect::<Vec<_>>();
+ let _ = map.clone().into_keys().map(|key| key + 2).collect::<Vec<_>>();
+
+ let _ = map.clone().into_values().collect::<Vec<_>>();
+ let _ = map.clone().into_values().map(|val| val + 2).collect::<Vec<_>>();
+
+ let _ = map.clone().values().collect::<Vec<_>>();
+ let _ = map.keys().filter(|x| *x % 2 == 0).count();
+
+ // Don't lint
+ let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
+ let _ = map.iter().map(get_key).collect::<Vec<_>>();
+
+ // Linting the following could be an improvement to the lint
+ // map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
+
+ // Lint
+ let _ = map.keys().map(|key| key * 9).count();
+ let _ = map.values().map(|value| value * 17).count();
+}
diff --git a/src/tools/clippy/tests/ui/iter_kv_map.rs b/src/tools/clippy/tests/ui/iter_kv_map.rs
new file mode 100644
index 000000000..7a1f1fb01
--- /dev/null
+++ b/src/tools/clippy/tests/ui/iter_kv_map.rs
@@ -0,0 +1,64 @@
+// run-rustfix
+
+#![warn(clippy::iter_kv_map)]
+#![allow(clippy::redundant_clone)]
+#![allow(clippy::suspicious_map)]
+#![allow(clippy::map_identity)]
+
+use std::collections::{BTreeMap, HashMap};
+
+fn main() {
+ let get_key = |(key, _val)| key;
+
+ let map: HashMap<u32, u32> = HashMap::new();
+
+ let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
+ let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
+ let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
+
+ let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
+ let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
+
+ let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>();
+ let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
+
+ let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
+ let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
+
+ // Don't lint
+ let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
+ let _ = map.iter().map(get_key).collect::<Vec<_>>();
+
+ // Linting the following could be an improvement to the lint
+ // map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
+
+ // Lint
+ let _ = map.iter().map(|(key, _value)| key * 9).count();
+ let _ = map.iter().map(|(_key, value)| value * 17).count();
+
+ let map: BTreeMap<u32, u32> = BTreeMap::new();
+
+ let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
+ let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
+ let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
+
+ let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
+ let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
+
+ let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>();
+ let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
+
+ let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
+ let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
+
+ // Don't lint
+ let _ = map.iter().filter(|(_, val)| *val % 2 == 0).map(|(key, _)| key).count();
+ let _ = map.iter().map(get_key).collect::<Vec<_>>();
+
+ // Linting the following could be an improvement to the lint
+ // map.iter().filter_map(|(_, val)| (val % 2 == 0).then(val * 17)).count();
+
+ // Lint
+ let _ = map.iter().map(|(key, _value)| key * 9).count();
+ let _ = map.iter().map(|(_key, value)| value * 17).count();
+}
diff --git a/src/tools/clippy/tests/ui/iter_kv_map.stderr b/src/tools/clippy/tests/ui/iter_kv_map.stderr
new file mode 100644
index 000000000..9b9b04c97
--- /dev/null
+++ b/src/tools/clippy/tests/ui/iter_kv_map.stderr
@@ -0,0 +1,136 @@
+error: iterating on a map's keys
+ --> $DIR/iter_kv_map.rs:15:13
+ |
+LL | let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
+ |
+ = note: `-D clippy::iter-kv-map` implied by `-D warnings`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:16:13
+ |
+LL | let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:17:13
+ |
+LL | let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)`
+
+error: iterating on a map's keys
+ --> $DIR/iter_kv_map.rs:19:13
+ |
+LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()`
+
+error: iterating on a map's keys
+ --> $DIR/iter_kv_map.rs:20:13
+ |
+LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:22:13
+ |
+LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:23:13
+ |
+LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:25:13
+ |
+LL | let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()`
+
+error: iterating on a map's keys
+ --> $DIR/iter_kv_map.rs:26:13
+ |
+LL | let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
+
+error: iterating on a map's keys
+ --> $DIR/iter_kv_map.rs:36:13
+ |
+LL | let _ = map.iter().map(|(key, _value)| key * 9).count();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:37:13
+ |
+LL | let _ = map.iter().map(|(_key, value)| value * 17).count();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
+
+error: iterating on a map's keys
+ --> $DIR/iter_kv_map.rs:41:13
+ |
+LL | let _ = map.iter().map(|(key, _)| key).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:42:13
+ |
+LL | let _ = map.iter().map(|(_, value)| value).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values()`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:43:13
+ |
+LL | let _ = map.iter().map(|(_, v)| v + 2).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|v| v + 2)`
+
+error: iterating on a map's keys
+ --> $DIR/iter_kv_map.rs:45:13
+ |
+LL | let _ = map.clone().into_iter().map(|(key, _)| key).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys()`
+
+error: iterating on a map's keys
+ --> $DIR/iter_kv_map.rs:46:13
+ |
+LL | let _ = map.clone().into_iter().map(|(key, _)| key + 2).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_keys().map(|key| key + 2)`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:48:13
+ |
+LL | let _ = map.clone().into_iter().map(|(_, val)| val).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values()`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:49:13
+ |
+LL | let _ = map.clone().into_iter().map(|(_, val)| val + 2).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().into_values().map(|val| val + 2)`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:51:13
+ |
+LL | let _ = map.clone().iter().map(|(_, val)| val).collect::<Vec<_>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.clone().values()`
+
+error: iterating on a map's keys
+ --> $DIR/iter_kv_map.rs:52:13
+ |
+LL | let _ = map.iter().map(|(key, _)| key).filter(|x| *x % 2 == 0).count();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys()`
+
+error: iterating on a map's keys
+ --> $DIR/iter_kv_map.rs:62:13
+ |
+LL | let _ = map.iter().map(|(key, _value)| key * 9).count();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.keys().map(|key| key * 9)`
+
+error: iterating on a map's values
+ --> $DIR/iter_kv_map.rs:63:13
+ |
+LL | let _ = map.iter().map(|(_key, value)| value * 17).count();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `map.values().map(|value| value * 17)`
+
+error: aborting due to 22 previous errors
+
diff --git a/src/tools/clippy/tests/ui/iter_nth.stderr b/src/tools/clippy/tests/ui/iter_nth.stderr
index d00b2fb67..a0fe353bc 100644
--- a/src/tools/clippy/tests/ui/iter_nth.stderr
+++ b/src/tools/clippy/tests/ui/iter_nth.stderr
@@ -4,8 +4,8 @@ error: called `.iter().nth()` on a Vec
LL | let bad_vec = some_vec.iter().nth(3);
| ^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::iter-nth` implied by `-D warnings`
= help: calling `.get()` is both faster and more readable
+ = note: `-D clippy::iter-nth` implied by `-D warnings`
error: called `.iter().nth()` on a slice
--> $DIR/iter_nth.rs:34:26
diff --git a/src/tools/clippy/tests/ui/iter_skip_next_unfixable.stderr b/src/tools/clippy/tests/ui/iter_skip_next_unfixable.stderr
index 74c327c74..4062706f9 100644
--- a/src/tools/clippy/tests/ui/iter_skip_next_unfixable.stderr
+++ b/src/tools/clippy/tests/ui/iter_skip_next_unfixable.stderr
@@ -4,12 +4,12 @@ error: called `skip(..).next()` on an iterator
LL | let _: Vec<&str> = sp.skip(1).next().unwrap().split(' ').collect();
| ^^^^^^^^^^^^^^^ help: use `nth` instead: `.nth(1)`
|
- = note: `-D clippy::iter-skip-next` implied by `-D warnings`
help: for this change `sp` has to be mutable
--> $DIR/iter_skip_next_unfixable.rs:8:9
|
LL | let sp = test_string.split('|').map(|s| s.trim());
| ^^
+ = note: `-D clippy::iter-skip-next` implied by `-D warnings`
error: called `skip(..).next()` on an iterator
--> $DIR/iter_skip_next_unfixable.rs:11:29
diff --git a/src/tools/clippy/tests/ui/large_enum_variant.rs b/src/tools/clippy/tests/ui/large_enum_variant.rs
index 717009e4c..3b96f09d7 100644
--- a/src/tools/clippy/tests/ui/large_enum_variant.rs
+++ b/src/tools/clippy/tests/ui/large_enum_variant.rs
@@ -101,12 +101,12 @@ struct Struct2 {
#[derive(Copy, Clone)]
enum CopyableLargeEnum {
A(bool),
- B([u128; 4000]),
+ B([u64; 8000]),
}
enum ManuallyCopyLargeEnum {
A(bool),
- B([u128; 4000]),
+ B([u64; 8000]),
}
impl Clone for ManuallyCopyLargeEnum {
diff --git a/src/tools/clippy/tests/ui/large_enum_variant.stderr b/src/tools/clippy/tests/ui/large_enum_variant.stderr
index c6ed97487..709972b4a 100644
--- a/src/tools/clippy/tests/ui/large_enum_variant.stderr
+++ b/src/tools/clippy/tests/ui/large_enum_variant.stderr
@@ -167,8 +167,8 @@ error: large size difference between variants
LL | / enum CopyableLargeEnum {
LL | | A(bool),
| | ------- the second-largest variant contains at least 1 bytes
-LL | | B([u128; 4000]),
- | | --------------- the largest variant contains at least 64000 bytes
+LL | | B([u64; 8000]),
+ | | -------------- the largest variant contains at least 64000 bytes
LL | | }
| |_^ the entire enum is at least 64008 bytes
|
@@ -180,8 +180,8 @@ LL | enum CopyableLargeEnum {
help: consider boxing the large fields to reduce the total size of the enum
--> $DIR/large_enum_variant.rs:104:5
|
-LL | B([u128; 4000]),
- | ^^^^^^^^^^^^^^^
+LL | B([u64; 8000]),
+ | ^^^^^^^^^^^^^^
error: large size difference between variants
--> $DIR/large_enum_variant.rs:107:1
@@ -189,8 +189,8 @@ error: large size difference between variants
LL | / enum ManuallyCopyLargeEnum {
LL | | A(bool),
| | ------- the second-largest variant contains at least 1 bytes
-LL | | B([u128; 4000]),
- | | --------------- the largest variant contains at least 64000 bytes
+LL | | B([u64; 8000]),
+ | | -------------- the largest variant contains at least 64000 bytes
LL | | }
| |_^ the entire enum is at least 64008 bytes
|
@@ -202,8 +202,8 @@ LL | enum ManuallyCopyLargeEnum {
help: consider boxing the large fields to reduce the total size of the enum
--> $DIR/large_enum_variant.rs:109:5
|
-LL | B([u128; 4000]),
- | ^^^^^^^^^^^^^^^
+LL | B([u64; 8000]),
+ | ^^^^^^^^^^^^^^
error: large size difference between variants
--> $DIR/large_enum_variant.rs:120:1
diff --git a/src/tools/clippy/tests/ui/large_stack_arrays.rs b/src/tools/clippy/tests/ui/large_stack_arrays.rs
index d9161bfcf..6790765f8 100644
--- a/src/tools/clippy/tests/ui/large_stack_arrays.rs
+++ b/src/tools/clippy/tests/ui/large_stack_arrays.rs
@@ -12,6 +12,12 @@ enum E {
T(u32),
}
+pub static DOESNOTLINT: [u8; 512_001] = [0; 512_001];
+pub static DOESNOTLINT2: [u8; 512_001] = {
+ let x = 0;
+ [x; 512_001]
+};
+
fn main() {
let bad = (
[0u32; 20_000_000],
diff --git a/src/tools/clippy/tests/ui/large_stack_arrays.stderr b/src/tools/clippy/tests/ui/large_stack_arrays.stderr
index 58c0a77c1..c7bf941ad 100644
--- a/src/tools/clippy/tests/ui/large_stack_arrays.stderr
+++ b/src/tools/clippy/tests/ui/large_stack_arrays.stderr
@@ -1,14 +1,14 @@
error: allocating a local array larger than 512000 bytes
- --> $DIR/large_stack_arrays.rs:17:9
+ --> $DIR/large_stack_arrays.rs:23:9
|
LL | [0u32; 20_000_000],
| ^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::large-stack-arrays` implied by `-D warnings`
= help: consider allocating on the heap with `vec![0u32; 20_000_000].into_boxed_slice()`
+ = note: `-D clippy::large-stack-arrays` implied by `-D warnings`
error: allocating a local array larger than 512000 bytes
- --> $DIR/large_stack_arrays.rs:18:9
+ --> $DIR/large_stack_arrays.rs:24:9
|
LL | [S { data: [0; 32] }; 5000],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,7 +16,7 @@ LL | [S { data: [0; 32] }; 5000],
= help: consider allocating on the heap with `vec![S { data: [0; 32] }; 5000].into_boxed_slice()`
error: allocating a local array larger than 512000 bytes
- --> $DIR/large_stack_arrays.rs:19:9
+ --> $DIR/large_stack_arrays.rs:25:9
|
LL | [Some(""); 20_000_000],
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +24,7 @@ LL | [Some(""); 20_000_000],
= help: consider allocating on the heap with `vec![Some(""); 20_000_000].into_boxed_slice()`
error: allocating a local array larger than 512000 bytes
- --> $DIR/large_stack_arrays.rs:20:9
+ --> $DIR/large_stack_arrays.rs:26:9
|
LL | [E::T(0); 5000],
| ^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/len_without_is_empty.rs b/src/tools/clippy/tests/ui/len_without_is_empty.rs
index 1e938e72b..78397c2af 100644
--- a/src/tools/clippy/tests/ui/len_without_is_empty.rs
+++ b/src/tools/clippy/tests/ui/len_without_is_empty.rs
@@ -274,7 +274,7 @@ impl AsyncLen {
}
pub async fn len(&self) -> usize {
- if self.async_task().await { 0 } else { 1 }
+ usize::from(!self.async_task().await)
}
pub async fn is_empty(&self) -> bool {
diff --git a/src/tools/clippy/tests/ui/len_without_is_empty.stderr b/src/tools/clippy/tests/ui/len_without_is_empty.stderr
index a1f48f761..8e890e2e2 100644
--- a/src/tools/clippy/tests/ui/len_without_is_empty.stderr
+++ b/src/tools/clippy/tests/ui/len_without_is_empty.stderr
@@ -92,8 +92,8 @@ error: this returns a `Result<_, ()>`
LL | pub fn len(&self) -> Result<usize, ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::result-unit-err` implied by `-D warnings`
= help: use a custom `Error` type instead
+ = note: `-D clippy::result-unit-err` implied by `-D warnings`
error: this returns a `Result<_, ()>`
--> $DIR/len_without_is_empty.rs:240:5
diff --git a/src/tools/clippy/tests/ui/let_if_seq.stderr b/src/tools/clippy/tests/ui/let_if_seq.stderr
index 271ccce68..f2e0edb6f 100644
--- a/src/tools/clippy/tests/ui/let_if_seq.stderr
+++ b/src/tools/clippy/tests/ui/let_if_seq.stderr
@@ -7,8 +7,8 @@ LL | | foo = 42;
LL | | }
| |_____^ help: it is more idiomatic to write: `let <mut> foo = if f() { 42 } else { 0 };`
|
- = note: `-D clippy::useless-let-if-seq` implied by `-D warnings`
= note: you might not need `mut` at all
+ = note: `-D clippy::useless-let-if-seq` implied by `-D warnings`
error: `if _ { .. } else { .. }` is an expression
--> $DIR/let_if_seq.rs:71:5
diff --git a/src/tools/clippy/tests/ui/let_underscore_drop.stderr b/src/tools/clippy/tests/ui/let_underscore_drop.stderr
index ee7bbe995..324b7cd43 100644
--- a/src/tools/clippy/tests/ui/let_underscore_drop.stderr
+++ b/src/tools/clippy/tests/ui/let_underscore_drop.stderr
@@ -4,8 +4,8 @@ error: non-binding `let` on a type that implements `Drop`
LL | let _ = Box::new(());
| ^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::let-underscore-drop` implied by `-D warnings`
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
+ = note: `-D clippy::let-underscore-drop` implied by `-D warnings`
error: non-binding `let` on a type that implements `Drop`
--> $DIR/let_underscore_drop.rs:18:5
diff --git a/src/tools/clippy/tests/ui/let_underscore_lock.stderr b/src/tools/clippy/tests/ui/let_underscore_lock.stderr
index 4365b48fa..d7779e7b6 100644
--- a/src/tools/clippy/tests/ui/let_underscore_lock.stderr
+++ b/src/tools/clippy/tests/ui/let_underscore_lock.stderr
@@ -4,8 +4,8 @@ error: non-binding let on a synchronization lock
LL | let _ = m.lock();
| ^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::let-underscore-lock` implied by `-D warnings`
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
+ = note: `-D clippy::let-underscore-lock` implied by `-D warnings`
error: non-binding let on a synchronization lock
--> $DIR/let_underscore_lock.rs:10:5
diff --git a/src/tools/clippy/tests/ui/let_underscore_must_use.stderr b/src/tools/clippy/tests/ui/let_underscore_must_use.stderr
index 5b751ea56..bae60f2ff 100644
--- a/src/tools/clippy/tests/ui/let_underscore_must_use.stderr
+++ b/src/tools/clippy/tests/ui/let_underscore_must_use.stderr
@@ -4,8 +4,8 @@ error: non-binding let on a result of a `#[must_use]` function
LL | let _ = f();
| ^^^^^^^^^^^^
|
- = note: `-D clippy::let-underscore-must-use` implied by `-D warnings`
= help: consider explicitly using function result
+ = note: `-D clippy::let-underscore-must-use` implied by `-D warnings`
error: non-binding let on an expression with `#[must_use]` type
--> $DIR/let_underscore_must_use.rs:68:5
diff --git a/src/tools/clippy/tests/ui/linkedlist.stderr b/src/tools/clippy/tests/ui/linkedlist.stderr
index 51327df13..c76c94961 100644
--- a/src/tools/clippy/tests/ui/linkedlist.stderr
+++ b/src/tools/clippy/tests/ui/linkedlist.stderr
@@ -4,8 +4,8 @@ error: you seem to be using a `LinkedList`! Perhaps you meant some other data st
LL | const C: LinkedList<i32> = LinkedList::new();
| ^^^^^^^^^^^^^^^
|
- = note: `-D clippy::linkedlist` implied by `-D warnings`
= help: a `VecDeque` might work
+ = note: `-D clippy::linkedlist` implied by `-D warnings`
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
--> $DIR/linkedlist.rs:9:11
diff --git a/src/tools/clippy/tests/ui/literals.rs b/src/tools/clippy/tests/ui/literals.rs
index 0cadd5a3d..1a646e49c 100644
--- a/src/tools/clippy/tests/ui/literals.rs
+++ b/src/tools/clippy/tests/ui/literals.rs
@@ -40,3 +40,10 @@ fn main() {
let ok26 = 0x6_A0_BF;
let ok27 = 0b1_0010_0101;
}
+
+fn issue9651() {
+ // lint but octal form is not possible here
+ let _ = 08;
+ let _ = 09;
+ let _ = 089;
+}
diff --git a/src/tools/clippy/tests/ui/literals.stderr b/src/tools/clippy/tests/ui/literals.stderr
index 365b24074..603d47bac 100644
--- a/src/tools/clippy/tests/ui/literals.stderr
+++ b/src/tools/clippy/tests/ui/literals.stderr
@@ -135,5 +135,38 @@ error: digits of hex or binary literal not grouped by four
LL | let fail25 = 0b01_100_101;
| ^^^^^^^^^^^^ help: consider: `0b0110_0101`
-error: aborting due to 18 previous errors
+error: this is a decimal constant
+ --> $DIR/literals.rs:46:13
+ |
+LL | let _ = 08;
+ | ^^
+ |
+help: if you mean to use a decimal constant, remove the `0` to avoid confusion
+ |
+LL | let _ = 8;
+ | ~
+
+error: this is a decimal constant
+ --> $DIR/literals.rs:47:13
+ |
+LL | let _ = 09;
+ | ^^
+ |
+help: if you mean to use a decimal constant, remove the `0` to avoid confusion
+ |
+LL | let _ = 9;
+ | ~
+
+error: this is a decimal constant
+ --> $DIR/literals.rs:48:13
+ |
+LL | let _ = 089;
+ | ^^^
+ |
+help: if you mean to use a decimal constant, remove the `0` to avoid confusion
+ |
+LL | let _ = 89;
+ | ~~
+
+error: aborting due to 21 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed b/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed
index 65598f1ea..c9a819ba5 100644
--- a/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed
+++ b/src/tools/clippy/tests/ui/manual_assert.edition2018.fixed
@@ -1,10 +1,11 @@
// revisions: edition2018 edition2021
-// [edition2018] edition:2018
-// [edition2021] edition:2021
+//[edition2018] edition:2018
+//[edition2021] edition:2021
// run-rustfix
#![warn(clippy::manual_assert)]
-#![allow(clippy::nonminimal_bool)]
+#![allow(dead_code, unused_doc_comments)]
+#![allow(clippy::nonminimal_bool, clippy::uninlined_format_args)]
macro_rules! one {
() => {
@@ -28,7 +29,9 @@ fn main() {
panic!("qaqaq{:?}", a);
}
assert!(a.is_empty(), "qaqaq{:?}", a);
- assert!(a.is_empty(), "qwqwq");
+ if !a.is_empty() {
+ panic!("qwqwq");
+ }
if a.len() == 3 {
println!("qwq");
println!("qwq");
@@ -43,10 +46,32 @@ fn main() {
println!("qwq");
}
let b = vec![1, 2, 3];
- assert!(!b.is_empty(), "panic1");
- assert!(!(b.is_empty() && a.is_empty()), "panic2");
- assert!(!(a.is_empty() && !b.is_empty()), "panic3");
- assert!(!(b.is_empty() || a.is_empty()), "panic4");
- assert!(!(a.is_empty() || !b.is_empty()), "panic5");
+ if b.is_empty() {
+ panic!("panic1");
+ }
+ if b.is_empty() && a.is_empty() {
+ panic!("panic2");
+ }
+ if a.is_empty() && !b.is_empty() {
+ panic!("panic3");
+ }
+ if b.is_empty() || a.is_empty() {
+ panic!("panic4");
+ }
+ if a.is_empty() || !b.is_empty() {
+ panic!("panic5");
+ }
assert!(!a.is_empty(), "with expansion {}", one!());
}
+
+fn issue7730(a: u8) {
+ // Suggestion should preserve comment
+ if a > 2 {
+ // comment
+ /* this is a
+ multiline
+ comment */
+ /// Doc comment
+ panic!("panic with comment") // comment after `panic!`
+ }
+}
diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2018.stderr b/src/tools/clippy/tests/ui/manual_assert.edition2018.stderr
index a0f31afd6..1f2e1e308 100644
--- a/src/tools/clippy/tests/ui/manual_assert.edition2018.stderr
+++ b/src/tools/clippy/tests/ui/manual_assert.edition2018.stderr
@@ -1,68 +1,20 @@
error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:30:5
+ --> $DIR/manual_assert.rs:31:5
|
LL | / if !a.is_empty() {
LL | | panic!("qaqaq{:?}", a);
LL | | }
- | |_____^ help: try: `assert!(a.is_empty(), "qaqaq{:?}", a);`
+ | |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);`
|
= note: `-D clippy::manual-assert` implied by `-D warnings`
error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:33:5
- |
-LL | / if !a.is_empty() {
-LL | | panic!("qwqwq");
-LL | | }
- | |_____^ help: try: `assert!(a.is_empty(), "qwqwq");`
-
-error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:50:5
- |
-LL | / if b.is_empty() {
-LL | | panic!("panic1");
-LL | | }
- | |_____^ help: try: `assert!(!b.is_empty(), "panic1");`
-
-error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:53:5
- |
-LL | / if b.is_empty() && a.is_empty() {
-LL | | panic!("panic2");
-LL | | }
- | |_____^ help: try: `assert!(!(b.is_empty() && a.is_empty()), "panic2");`
-
-error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:56:5
- |
-LL | / if a.is_empty() && !b.is_empty() {
-LL | | panic!("panic3");
-LL | | }
- | |_____^ help: try: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");`
-
-error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:59:5
- |
-LL | / if b.is_empty() || a.is_empty() {
-LL | | panic!("panic4");
-LL | | }
- | |_____^ help: try: `assert!(!(b.is_empty() || a.is_empty()), "panic4");`
-
-error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:62:5
- |
-LL | / if a.is_empty() || !b.is_empty() {
-LL | | panic!("panic5");
-LL | | }
- | |_____^ help: try: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");`
-
-error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:65:5
+ --> $DIR/manual_assert.rs:66:5
|
LL | / if a.is_empty() {
LL | | panic!("with expansion {}", one!())
LL | | }
- | |_____^ help: try: `assert!(!a.is_empty(), "with expansion {}", one!());`
+ | |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());`
-error: aborting due to 8 previous errors
+error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed b/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed
index 65598f1ea..2f62de51c 100644
--- a/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed
+++ b/src/tools/clippy/tests/ui/manual_assert.edition2021.fixed
@@ -1,10 +1,11 @@
// revisions: edition2018 edition2021
-// [edition2018] edition:2018
-// [edition2021] edition:2021
+//[edition2018] edition:2018
+//[edition2021] edition:2021
// run-rustfix
#![warn(clippy::manual_assert)]
-#![allow(clippy::nonminimal_bool)]
+#![allow(dead_code, unused_doc_comments)]
+#![allow(clippy::nonminimal_bool, clippy::uninlined_format_args)]
macro_rules! one {
() => {
@@ -50,3 +51,14 @@ fn main() {
assert!(!(a.is_empty() || !b.is_empty()), "panic5");
assert!(!a.is_empty(), "with expansion {}", one!());
}
+
+fn issue7730(a: u8) {
+ // Suggestion should preserve comment
+ // comment
+/* this is a
+ multiline
+ comment */
+/// Doc comment
+// comment after `panic!`
+assert!(!(a > 2), "panic with comment");
+}
diff --git a/src/tools/clippy/tests/ui/manual_assert.edition2021.stderr b/src/tools/clippy/tests/ui/manual_assert.edition2021.stderr
index a0f31afd6..237638ee1 100644
--- a/src/tools/clippy/tests/ui/manual_assert.edition2021.stderr
+++ b/src/tools/clippy/tests/ui/manual_assert.edition2021.stderr
@@ -1,68 +1,85 @@
error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:30:5
+ --> $DIR/manual_assert.rs:31:5
|
LL | / if !a.is_empty() {
LL | | panic!("qaqaq{:?}", a);
LL | | }
- | |_____^ help: try: `assert!(a.is_empty(), "qaqaq{:?}", a);`
+ | |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);`
|
= note: `-D clippy::manual-assert` implied by `-D warnings`
error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:33:5
+ --> $DIR/manual_assert.rs:34:5
|
LL | / if !a.is_empty() {
LL | | panic!("qwqwq");
LL | | }
- | |_____^ help: try: `assert!(a.is_empty(), "qwqwq");`
+ | |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");`
error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:50:5
+ --> $DIR/manual_assert.rs:51:5
|
LL | / if b.is_empty() {
LL | | panic!("panic1");
LL | | }
- | |_____^ help: try: `assert!(!b.is_empty(), "panic1");`
+ | |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");`
error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:53:5
+ --> $DIR/manual_assert.rs:54:5
|
LL | / if b.is_empty() && a.is_empty() {
LL | | panic!("panic2");
LL | | }
- | |_____^ help: try: `assert!(!(b.is_empty() && a.is_empty()), "panic2");`
+ | |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");`
error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:56:5
+ --> $DIR/manual_assert.rs:57:5
|
LL | / if a.is_empty() && !b.is_empty() {
LL | | panic!("panic3");
LL | | }
- | |_____^ help: try: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");`
+ | |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");`
error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:59:5
+ --> $DIR/manual_assert.rs:60:5
|
LL | / if b.is_empty() || a.is_empty() {
LL | | panic!("panic4");
LL | | }
- | |_____^ help: try: `assert!(!(b.is_empty() || a.is_empty()), "panic4");`
+ | |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");`
error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:62:5
+ --> $DIR/manual_assert.rs:63:5
|
LL | / if a.is_empty() || !b.is_empty() {
LL | | panic!("panic5");
LL | | }
- | |_____^ help: try: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");`
+ | |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");`
error: only a `panic!` in `if`-then statement
- --> $DIR/manual_assert.rs:65:5
+ --> $DIR/manual_assert.rs:66:5
|
LL | / if a.is_empty() {
LL | | panic!("with expansion {}", one!())
LL | | }
- | |_____^ help: try: `assert!(!a.is_empty(), "with expansion {}", one!());`
+ | |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());`
-error: aborting due to 8 previous errors
+error: only a `panic!` in `if`-then statement
+ --> $DIR/manual_assert.rs:73:5
+ |
+LL | / if a > 2 {
+LL | | // comment
+LL | | /* this is a
+LL | | multiline
+... |
+LL | | panic!("panic with comment") // comment after `panic!`
+LL | | }
+ | |_____^
+ |
+help: try instead
+ |
+LL | assert!(!(a > 2), "panic with comment");
+ |
+
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_assert.fixed b/src/tools/clippy/tests/ui/manual_assert.fixed
deleted file mode 100644
index a2393674f..000000000
--- a/src/tools/clippy/tests/ui/manual_assert.fixed
+++ /dev/null
@@ -1,45 +0,0 @@
-// revisions: edition2018 edition2021
-// [edition2018] edition:2018
-// [edition2021] edition:2021
-// run-rustfix
-
-#![warn(clippy::manual_assert)]
-#![allow(clippy::nonminimal_bool)]
-
-fn main() {
- let a = vec![1, 2, 3];
- let c = Some(2);
- if !a.is_empty()
- && a.len() == 3
- && c.is_some()
- && !a.is_empty()
- && a.len() == 3
- && !a.is_empty()
- && a.len() == 3
- && !a.is_empty()
- && a.len() == 3
- {
- panic!("qaqaq{:?}", a);
- }
- assert!(a.is_empty(), "qaqaq{:?}", a);
- assert!(a.is_empty(), "qwqwq");
- if a.len() == 3 {
- println!("qwq");
- println!("qwq");
- println!("qwq");
- }
- if let Some(b) = c {
- panic!("orz {}", b);
- }
- if a.len() == 3 {
- panic!("qaqaq");
- } else {
- println!("qwq");
- }
- let b = vec![1, 2, 3];
- assert!(!b.is_empty(), "panic1");
- assert!(!(b.is_empty() && a.is_empty()), "panic2");
- assert!(!(a.is_empty() && !b.is_empty()), "panic3");
- assert!(!(b.is_empty() || a.is_empty()), "panic4");
- assert!(!(a.is_empty() || !b.is_empty()), "panic5");
-}
diff --git a/src/tools/clippy/tests/ui/manual_assert.rs b/src/tools/clippy/tests/ui/manual_assert.rs
index 4d2706dd6..6a4cc2468 100644
--- a/src/tools/clippy/tests/ui/manual_assert.rs
+++ b/src/tools/clippy/tests/ui/manual_assert.rs
@@ -1,10 +1,11 @@
// revisions: edition2018 edition2021
-// [edition2018] edition:2018
-// [edition2021] edition:2021
+//[edition2018] edition:2018
+//[edition2021] edition:2021
// run-rustfix
#![warn(clippy::manual_assert)]
-#![allow(clippy::nonminimal_bool)]
+#![allow(dead_code, unused_doc_comments)]
+#![allow(clippy::nonminimal_bool, clippy::uninlined_format_args)]
macro_rules! one {
() => {
@@ -66,3 +67,15 @@ fn main() {
panic!("with expansion {}", one!())
}
}
+
+fn issue7730(a: u8) {
+ // Suggestion should preserve comment
+ if a > 2 {
+ // comment
+ /* this is a
+ multiline
+ comment */
+ /// Doc comment
+ panic!("panic with comment") // comment after `panic!`
+ }
+}
diff --git a/src/tools/clippy/tests/ui/manual_bits.fixed b/src/tools/clippy/tests/ui/manual_bits.fixed
index 386360dbd..e7f8cd878 100644
--- a/src/tools/clippy/tests/ui/manual_bits.fixed
+++ b/src/tools/clippy/tests/ui/manual_bits.fixed
@@ -6,7 +6,8 @@
clippy::useless_conversion,
path_statements,
unused_must_use,
- clippy::unnecessary_operation
+ clippy::unnecessary_operation,
+ clippy::unnecessary_cast
)]
use std::mem::{size_of, size_of_val};
diff --git a/src/tools/clippy/tests/ui/manual_bits.rs b/src/tools/clippy/tests/ui/manual_bits.rs
index 62638f047..7b1d15495 100644
--- a/src/tools/clippy/tests/ui/manual_bits.rs
+++ b/src/tools/clippy/tests/ui/manual_bits.rs
@@ -6,7 +6,8 @@
clippy::useless_conversion,
path_statements,
unused_must_use,
- clippy::unnecessary_operation
+ clippy::unnecessary_operation,
+ clippy::unnecessary_cast
)]
use std::mem::{size_of, size_of_val};
diff --git a/src/tools/clippy/tests/ui/manual_bits.stderr b/src/tools/clippy/tests/ui/manual_bits.stderr
index 69c591a20..652fafbc4 100644
--- a/src/tools/clippy/tests/ui/manual_bits.stderr
+++ b/src/tools/clippy/tests/ui/manual_bits.stderr
@@ -1,5 +1,5 @@
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:15:5
+ --> $DIR/manual_bits.rs:16:5
|
LL | size_of::<i8>() * 8;
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `i8::BITS as usize`
@@ -7,169 +7,169 @@ LL | size_of::<i8>() * 8;
= note: `-D clippy::manual-bits` implied by `-D warnings`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:16:5
+ --> $DIR/manual_bits.rs:17:5
|
LL | size_of::<i16>() * 8;
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i16::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:17:5
+ --> $DIR/manual_bits.rs:18:5
|
LL | size_of::<i32>() * 8;
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i32::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:18:5
+ --> $DIR/manual_bits.rs:19:5
|
LL | size_of::<i64>() * 8;
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i64::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:19:5
+ --> $DIR/manual_bits.rs:20:5
|
LL | size_of::<i128>() * 8;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `i128::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:20:5
+ --> $DIR/manual_bits.rs:21:5
|
LL | size_of::<isize>() * 8;
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `isize::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:22:5
+ --> $DIR/manual_bits.rs:23:5
|
LL | size_of::<u8>() * 8;
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `u8::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:23:5
+ --> $DIR/manual_bits.rs:24:5
|
LL | size_of::<u16>() * 8;
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u16::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:24:5
+ --> $DIR/manual_bits.rs:25:5
|
LL | size_of::<u32>() * 8;
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u32::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:25:5
+ --> $DIR/manual_bits.rs:26:5
|
LL | size_of::<u64>() * 8;
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u64::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:26:5
+ --> $DIR/manual_bits.rs:27:5
|
LL | size_of::<u128>() * 8;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:27:5
+ --> $DIR/manual_bits.rs:28:5
|
LL | size_of::<usize>() * 8;
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `usize::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:29:5
+ --> $DIR/manual_bits.rs:30:5
|
LL | 8 * size_of::<i8>();
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `i8::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:30:5
+ --> $DIR/manual_bits.rs:31:5
|
LL | 8 * size_of::<i16>();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i16::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:31:5
+ --> $DIR/manual_bits.rs:32:5
|
LL | 8 * size_of::<i32>();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i32::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:32:5
+ --> $DIR/manual_bits.rs:33:5
|
LL | 8 * size_of::<i64>();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `i64::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:33:5
+ --> $DIR/manual_bits.rs:34:5
|
LL | 8 * size_of::<i128>();
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `i128::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:34:5
+ --> $DIR/manual_bits.rs:35:5
|
LL | 8 * size_of::<isize>();
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `isize::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:36:5
+ --> $DIR/manual_bits.rs:37:5
|
LL | 8 * size_of::<u8>();
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `u8::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:37:5
+ --> $DIR/manual_bits.rs:38:5
|
LL | 8 * size_of::<u16>();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u16::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:38:5
+ --> $DIR/manual_bits.rs:39:5
|
LL | 8 * size_of::<u32>();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u32::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:39:5
+ --> $DIR/manual_bits.rs:40:5
|
LL | 8 * size_of::<u64>();
| ^^^^^^^^^^^^^^^^^^^^ help: consider using: `u64::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:40:5
+ --> $DIR/manual_bits.rs:41:5
|
LL | 8 * size_of::<u128>();
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:41:5
+ --> $DIR/manual_bits.rs:42:5
|
LL | 8 * size_of::<usize>();
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `usize::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:51:5
+ --> $DIR/manual_bits.rs:52:5
|
LL | size_of::<Word>() * 8;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `Word::BITS as usize`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:55:18
+ --> $DIR/manual_bits.rs:56:18
|
LL | let _: u32 = (size_of::<u128>() * 8) as u32;
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:56:18
+ --> $DIR/manual_bits.rs:57:18
|
LL | let _: u32 = (size_of::<u128>() * 8).try_into().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u128::BITS`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:57:13
+ --> $DIR/manual_bits.rs:58:13
|
LL | let _ = (size_of::<u128>() * 8).pow(5);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(u128::BITS as usize)`
error: usage of `mem::size_of::<T>()` to obtain the size of `T` in bits
- --> $DIR/manual_bits.rs:58:14
+ --> $DIR/manual_bits.rs:59:14
|
LL | let _ = &(size_of::<u128>() * 8);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `(u128::BITS as usize)`
diff --git a/src/tools/clippy/tests/ui/manual_clamp.rs b/src/tools/clippy/tests/ui/manual_clamp.rs
new file mode 100644
index 000000000..331fd29b7
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_clamp.rs
@@ -0,0 +1,331 @@
+#![feature(custom_inner_attributes)]
+#![warn(clippy::manual_clamp)]
+#![allow(
+ unused,
+ dead_code,
+ clippy::unnecessary_operation,
+ clippy::no_effect,
+ clippy::if_same_then_else
+)]
+
+use std::cmp::{max as cmp_max, min as cmp_min};
+
+const CONST_MAX: i32 = 10;
+const CONST_MIN: i32 = 4;
+
+const CONST_F64_MAX: f64 = 10.0;
+const CONST_F64_MIN: f64 = 4.0;
+
+fn main() {
+ let (input, min, max) = (0, -2, 3);
+ // Lint
+ let x0 = if max < input {
+ max
+ } else if min > input {
+ min
+ } else {
+ input
+ };
+
+ let x1 = if input > max {
+ max
+ } else if input < min {
+ min
+ } else {
+ input
+ };
+
+ let x2 = if input < min {
+ min
+ } else if input > max {
+ max
+ } else {
+ input
+ };
+
+ let x3 = if min > input {
+ min
+ } else if max < input {
+ max
+ } else {
+ input
+ };
+
+ let x4 = input.max(min).min(max);
+
+ let x5 = input.min(max).max(min);
+
+ let x6 = match input {
+ x if x > max => max,
+ x if x < min => min,
+ x => x,
+ };
+
+ let x7 = match input {
+ x if x < min => min,
+ x if x > max => max,
+ x => x,
+ };
+
+ let x8 = match input {
+ x if max < x => max,
+ x if min > x => min,
+ x => x,
+ };
+
+ let mut x9 = input;
+ if x9 < min {
+ x9 = min;
+ }
+ if x9 > max {
+ x9 = max;
+ }
+
+ let x10 = match input {
+ x if min > x => min,
+ x if max < x => max,
+ x => x,
+ };
+
+ let mut x11 = input;
+ let _ = 1;
+ if x11 > max {
+ x11 = max;
+ }
+ if x11 < min {
+ x11 = min;
+ }
+
+ let mut x12 = input;
+ if min > x12 {
+ x12 = min;
+ }
+ if max < x12 {
+ x12 = max;
+ }
+
+ let mut x13 = input;
+ if max < x13 {
+ x13 = max;
+ }
+ if min > x13 {
+ x13 = min;
+ }
+
+ let x14 = if input > CONST_MAX {
+ CONST_MAX
+ } else if input < CONST_MIN {
+ CONST_MIN
+ } else {
+ input
+ };
+ {
+ let (input, min, max) = (0.0f64, -2.0, 3.0);
+ let x15 = if input > max {
+ max
+ } else if input < min {
+ min
+ } else {
+ input
+ };
+ }
+ {
+ let input: i32 = cmp_min_max(1);
+ // These can only be detected if exactly one of the arguments to the inner function is const.
+ let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN);
+ let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX);
+ let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX));
+ let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN));
+ let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN);
+ let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX);
+ let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input));
+ let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input));
+ let input: f64 = cmp_min_max(1) as f64;
+ let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN);
+ let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX);
+ let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX));
+ let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN));
+ let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN);
+ let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX);
+ let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input));
+ let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input));
+ }
+ let mut x32 = input;
+ if x32 < min {
+ x32 = min;
+ } else if x32 > max {
+ x32 = max;
+ }
+
+ // It's important this be the last set of statements
+ let mut x33 = input;
+ if max < x33 {
+ x33 = max;
+ }
+ if min > x33 {
+ x33 = min;
+ }
+}
+
+// This code intentionally nonsense.
+fn no_lint() {
+ let (input, min, max) = (0, -2, 3);
+ let x0 = if max < input {
+ max
+ } else if min > input {
+ max
+ } else {
+ min
+ };
+
+ let x1 = if input > max {
+ max
+ } else if input > min {
+ min
+ } else {
+ max
+ };
+
+ let x2 = if max < min {
+ min
+ } else if input > max {
+ input
+ } else {
+ input
+ };
+
+ let x3 = if min > input {
+ input
+ } else if max < input {
+ max
+ } else {
+ max
+ };
+
+ let x6 = match input {
+ x if x < max => x,
+ x if x < min => x,
+ x => x,
+ };
+
+ let x7 = match input {
+ x if x < min => max,
+ x if x > max => min,
+ x => x,
+ };
+
+ let x8 = match input {
+ x if max > x => max,
+ x if min > x => min,
+ x => x,
+ };
+
+ let mut x9 = input;
+ if x9 > min {
+ x9 = min;
+ }
+ if x9 > max {
+ x9 = max;
+ }
+
+ let x10 = match input {
+ x if min > x => min,
+ x if max < x => max,
+ x => min,
+ };
+
+ let mut x11 = input;
+ if x11 > max {
+ x11 = min;
+ }
+ if x11 < min {
+ x11 = max;
+ }
+
+ let mut x12 = input;
+ if min > x12 {
+ x12 = max * 3;
+ }
+ if max < x12 {
+ x12 = min;
+ }
+
+ let mut x13 = input;
+ if max < x13 {
+ let x13 = max;
+ }
+ if min > x13 {
+ x13 = min;
+ }
+ let mut x14 = input;
+ if x14 < min {
+ x14 = 3;
+ } else if x14 > max {
+ x14 = max;
+ }
+ {
+ let input: i32 = cmp_min_max(1);
+ // These can only be detected if exactly one of the arguments to the inner function is const.
+ let x16 = cmp_max(cmp_max(input, CONST_MAX), CONST_MIN);
+ let x17 = cmp_min(cmp_min(input, CONST_MIN), CONST_MAX);
+ let x18 = cmp_max(CONST_MIN, cmp_max(input, CONST_MAX));
+ let x19 = cmp_min(CONST_MAX, cmp_min(input, CONST_MIN));
+ let x20 = cmp_max(cmp_max(CONST_MAX, input), CONST_MIN);
+ let x21 = cmp_min(cmp_min(CONST_MIN, input), CONST_MAX);
+ let x22 = cmp_max(CONST_MIN, cmp_max(CONST_MAX, input));
+ let x23 = cmp_min(CONST_MAX, cmp_min(CONST_MIN, input));
+ let input: f64 = cmp_min_max(1) as f64;
+ let x24 = f64::max(f64::max(input, CONST_F64_MAX), CONST_F64_MIN);
+ let x25 = f64::min(f64::min(input, CONST_F64_MIN), CONST_F64_MAX);
+ let x26 = f64::max(CONST_F64_MIN, f64::max(input, CONST_F64_MAX));
+ let x27 = f64::min(CONST_F64_MAX, f64::min(input, CONST_F64_MIN));
+ let x28 = f64::max(f64::max(CONST_F64_MAX, input), CONST_F64_MIN);
+ let x29 = f64::min(f64::min(CONST_F64_MIN, input), CONST_F64_MAX);
+ let x30 = f64::max(CONST_F64_MIN, f64::max(CONST_F64_MAX, input));
+ let x31 = f64::min(CONST_F64_MAX, f64::min(CONST_F64_MIN, input));
+ let x32 = f64::min(CONST_F64_MAX, f64::min(CONST_F64_MIN, CONST_F64_MAX));
+ }
+}
+
+fn dont_tell_me_what_to_do() {
+ let (input, min, max) = (0, -2, 3);
+ let mut x_never = input;
+ #[allow(clippy::manual_clamp)]
+ if x_never < min {
+ x_never = min;
+ }
+ if x_never > max {
+ x_never = max;
+ }
+}
+
+/// Just to ensure this isn't const evaled
+fn cmp_min_max(input: i32) -> i32 {
+ input * 3
+}
+
+fn msrv_1_49() {
+ #![clippy::msrv = "1.49"]
+
+ let (input, min, max) = (0, -1, 2);
+ let _ = if input < min {
+ min
+ } else if input > max {
+ max
+ } else {
+ input
+ };
+}
+
+fn msrv_1_50() {
+ #![clippy::msrv = "1.50"]
+
+ let (input, min, max) = (0, -1, 2);
+ let _ = if input < min {
+ min
+ } else if input > max {
+ max
+ } else {
+ input
+ };
+}
diff --git a/src/tools/clippy/tests/ui/manual_clamp.stderr b/src/tools/clippy/tests/ui/manual_clamp.stderr
new file mode 100644
index 000000000..70abe2809
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_clamp.stderr
@@ -0,0 +1,390 @@
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:77:5
+ |
+LL | / if x9 < min {
+LL | | x9 = min;
+LL | | }
+LL | | if x9 > max {
+LL | | x9 = max;
+LL | | }
+ | |_____^ help: replace with clamp: `x9 = x9.clamp(min, max);`
+ |
+ = note: clamp will panic if max < min
+ = note: `-D clippy::manual-clamp` implied by `-D warnings`
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:92:5
+ |
+LL | / if x11 > max {
+LL | | x11 = max;
+LL | | }
+LL | | if x11 < min {
+LL | | x11 = min;
+LL | | }
+ | |_____^ help: replace with clamp: `x11 = x11.clamp(min, max);`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:100:5
+ |
+LL | / if min > x12 {
+LL | | x12 = min;
+LL | | }
+LL | | if max < x12 {
+LL | | x12 = max;
+LL | | }
+ | |_____^ help: replace with clamp: `x12 = x12.clamp(min, max);`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:108:5
+ |
+LL | / if max < x13 {
+LL | | x13 = max;
+LL | | }
+LL | | if min > x13 {
+LL | | x13 = min;
+LL | | }
+ | |_____^ help: replace with clamp: `x13 = x13.clamp(min, max);`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:162:5
+ |
+LL | / if max < x33 {
+LL | | x33 = max;
+LL | | }
+LL | | if min > x33 {
+LL | | x33 = min;
+LL | | }
+ | |_____^ help: replace with clamp: `x33 = x33.clamp(min, max);`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:22:14
+ |
+LL | let x0 = if max < input {
+ | ______________^
+LL | | max
+LL | | } else if min > input {
+LL | | min
+LL | | } else {
+LL | | input
+LL | | };
+ | |_____^ help: replace with clamp: `input.clamp(min, max)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:30:14
+ |
+LL | let x1 = if input > max {
+ | ______________^
+LL | | max
+LL | | } else if input < min {
+LL | | min
+LL | | } else {
+LL | | input
+LL | | };
+ | |_____^ help: replace with clamp: `input.clamp(min, max)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:38:14
+ |
+LL | let x2 = if input < min {
+ | ______________^
+LL | | min
+LL | | } else if input > max {
+LL | | max
+LL | | } else {
+LL | | input
+LL | | };
+ | |_____^ help: replace with clamp: `input.clamp(min, max)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:46:14
+ |
+LL | let x3 = if min > input {
+ | ______________^
+LL | | min
+LL | | } else if max < input {
+LL | | max
+LL | | } else {
+LL | | input
+LL | | };
+ | |_____^ help: replace with clamp: `input.clamp(min, max)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:54:14
+ |
+LL | let x4 = input.max(min).min(max);
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(min, max)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:56:14
+ |
+LL | let x5 = input.min(max).max(min);
+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(min, max)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:58:14
+ |
+LL | let x6 = match input {
+ | ______________^
+LL | | x if x > max => max,
+LL | | x if x < min => min,
+LL | | x => x,
+LL | | };
+ | |_____^ help: replace with clamp: `input.clamp(min, max)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:64:14
+ |
+LL | let x7 = match input {
+ | ______________^
+LL | | x if x < min => min,
+LL | | x if x > max => max,
+LL | | x => x,
+LL | | };
+ | |_____^ help: replace with clamp: `input.clamp(min, max)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:70:14
+ |
+LL | let x8 = match input {
+ | ______________^
+LL | | x if max < x => max,
+LL | | x if min > x => min,
+LL | | x => x,
+LL | | };
+ | |_____^ help: replace with clamp: `input.clamp(min, max)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:84:15
+ |
+LL | let x10 = match input {
+ | _______________^
+LL | | x if min > x => min,
+LL | | x if max < x => max,
+LL | | x => x,
+LL | | };
+ | |_____^ help: replace with clamp: `input.clamp(min, max)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:115:15
+ |
+LL | let x14 = if input > CONST_MAX {
+ | _______________^
+LL | | CONST_MAX
+LL | | } else if input < CONST_MIN {
+LL | | CONST_MIN
+LL | | } else {
+LL | | input
+LL | | };
+ | |_____^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:124:19
+ |
+LL | let x15 = if input > max {
+ | ___________________^
+LL | | max
+LL | | } else if input < min {
+LL | | min
+LL | | } else {
+LL | | input
+LL | | };
+ | |_________^ help: replace with clamp: `input.clamp(min, max)`
+ |
+ = note: clamp will panic if max < min, min.is_nan(), or max.is_nan()
+ = note: clamp returns NaN if the input is NaN
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:135:19
+ |
+LL | let x16 = cmp_max(cmp_min(input, CONST_MAX), CONST_MIN);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:136:19
+ |
+LL | let x17 = cmp_min(cmp_max(input, CONST_MIN), CONST_MAX);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:137:19
+ |
+LL | let x18 = cmp_max(CONST_MIN, cmp_min(input, CONST_MAX));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:138:19
+ |
+LL | let x19 = cmp_min(CONST_MAX, cmp_max(input, CONST_MIN));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:139:19
+ |
+LL | let x20 = cmp_max(cmp_min(CONST_MAX, input), CONST_MIN);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:140:19
+ |
+LL | let x21 = cmp_min(cmp_max(CONST_MIN, input), CONST_MAX);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:141:19
+ |
+LL | let x22 = cmp_max(CONST_MIN, cmp_min(CONST_MAX, input));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:142:19
+ |
+LL | let x23 = cmp_min(CONST_MAX, cmp_max(CONST_MIN, input));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_MIN, CONST_MAX)`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:144:19
+ |
+LL | let x24 = f64::max(f64::min(input, CONST_F64_MAX), CONST_F64_MIN);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
+ |
+ = note: clamp will panic if max < min, min.is_nan(), or max.is_nan()
+ = note: clamp returns NaN if the input is NaN
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:145:19
+ |
+LL | let x25 = f64::min(f64::max(input, CONST_F64_MIN), CONST_F64_MAX);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
+ |
+ = note: clamp will panic if max < min, min.is_nan(), or max.is_nan()
+ = note: clamp returns NaN if the input is NaN
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:146:19
+ |
+LL | let x26 = f64::max(CONST_F64_MIN, f64::min(input, CONST_F64_MAX));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
+ |
+ = note: clamp will panic if max < min, min.is_nan(), or max.is_nan()
+ = note: clamp returns NaN if the input is NaN
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:147:19
+ |
+LL | let x27 = f64::min(CONST_F64_MAX, f64::max(input, CONST_F64_MIN));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
+ |
+ = note: clamp will panic if max < min, min.is_nan(), or max.is_nan()
+ = note: clamp returns NaN if the input is NaN
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:148:19
+ |
+LL | let x28 = f64::max(f64::min(CONST_F64_MAX, input), CONST_F64_MIN);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
+ |
+ = note: clamp will panic if max < min, min.is_nan(), or max.is_nan()
+ = note: clamp returns NaN if the input is NaN
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:149:19
+ |
+LL | let x29 = f64::min(f64::max(CONST_F64_MIN, input), CONST_F64_MAX);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
+ |
+ = note: clamp will panic if max < min, min.is_nan(), or max.is_nan()
+ = note: clamp returns NaN if the input is NaN
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:150:19
+ |
+LL | let x30 = f64::max(CONST_F64_MIN, f64::min(CONST_F64_MAX, input));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
+ |
+ = note: clamp will panic if max < min, min.is_nan(), or max.is_nan()
+ = note: clamp returns NaN if the input is NaN
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:151:19
+ |
+LL | let x31 = f64::min(CONST_F64_MAX, f64::max(CONST_F64_MIN, input));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `input.clamp(CONST_F64_MIN, CONST_F64_MAX)`
+ |
+ = note: clamp will panic if max < min, min.is_nan(), or max.is_nan()
+ = note: clamp returns NaN if the input is NaN
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:154:5
+ |
+LL | / if x32 < min {
+LL | | x32 = min;
+LL | | } else if x32 > max {
+LL | | x32 = max;
+LL | | }
+ | |_____^ help: replace with clamp: `x32 = x32.clamp(min, max);`
+ |
+ = note: clamp will panic if max < min
+
+error: clamp-like pattern without using clamp function
+ --> $DIR/manual_clamp.rs:324:13
+ |
+LL | let _ = if input < min {
+ | _____________^
+LL | | min
+LL | | } else if input > max {
+LL | | max
+LL | | } else {
+LL | | input
+LL | | };
+ | |_____^ help: replace with clamp: `input.clamp(min, max)`
+ |
+ = note: clamp will panic if max < min
+
+error: aborting due to 35 previous errors
+
diff --git a/src/tools/clippy/tests/ui/manual_filter.fixed b/src/tools/clippy/tests/ui/manual_filter.fixed
new file mode 100644
index 000000000..3553291b8
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_filter.fixed
@@ -0,0 +1,119 @@
+// run-rustfix
+
+#![warn(clippy::manual_filter)]
+#![allow(unused_variables, dead_code)]
+
+fn main() {
+ Some(0).filter(|&x| x <= 0);
+
+ Some(1).filter(|&x| x <= 0);
+
+ Some(2).filter(|&x| x <= 0);
+
+ Some(3).filter(|&x| x > 0);
+
+ let y = Some(4);
+ y.filter(|&x| x <= 0);
+
+ Some(5).filter(|&x| x > 0);
+
+ Some(6).as_ref().filter(|&x| x > &0);
+
+ let external_cond = true;
+ Some(String::new()).filter(|x| external_cond);
+
+ Some(7).filter(|&x| external_cond);
+
+ Some(8).filter(|&x| x != 0);
+
+ Some(9).filter(|&x| x > 10 && x < 100);
+
+ const fn f1() {
+ // Don't lint, `.filter` is not const
+ match Some(10) {
+ Some(x) => {
+ if x > 10 && x < 100 {
+ Some(x)
+ } else {
+ None
+ }
+ },
+ None => None,
+ };
+ }
+
+ #[allow(clippy::blocks_in_if_conditions)]
+ Some(11).filter(|&x| {
+ println!("foo");
+ x > 10 && x < 100
+ });
+
+ match Some(12) {
+ // Don't Lint, statement is lost by `.filter`
+ Some(x) => {
+ if x > 10 && x < 100 {
+ println!("foo");
+ Some(x)
+ } else {
+ None
+ }
+ },
+ None => None,
+ };
+
+ match Some(13) {
+ // Don't Lint, because of `None => Some(1)`
+ Some(x) => {
+ if x > 10 && x < 100 {
+ println!("foo");
+ Some(x)
+ } else {
+ None
+ }
+ },
+ None => Some(1),
+ };
+
+ unsafe fn f(x: u32) -> bool {
+ true
+ }
+ let _ = Some(14).filter(|&x| unsafe { f(x) });
+ let _ = Some(15).filter(|&x| unsafe { f(x) });
+
+ #[allow(clippy::redundant_pattern_matching)]
+ if let Some(_) = Some(16) {
+ Some(16)
+ } else { Some(16).filter(|&x| x % 2 == 0) };
+
+ match Some((17, 17)) {
+ // Not linted for now could be
+ Some((x, y)) => {
+ if y != x {
+ Some((x, y))
+ } else {
+ None
+ }
+ },
+ None => None,
+ };
+
+ struct NamedTuple {
+ pub x: u8,
+ pub y: (i32, u32),
+ }
+
+ match Some(NamedTuple {
+ // Not linted for now could be
+ x: 17,
+ y: (18, 19),
+ }) {
+ Some(NamedTuple { x, y }) => {
+ if y.1 != x as u32 {
+ Some(NamedTuple { x, y })
+ } else {
+ None
+ }
+ },
+ None => None,
+ };
+}
diff --git a/src/tools/clippy/tests/ui/manual_filter.rs b/src/tools/clippy/tests/ui/manual_filter.rs
new file mode 100644
index 000000000..aa9f90f75
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_filter.rs
@@ -0,0 +1,243 @@
+// run-rustfix
+
+#![warn(clippy::manual_filter)]
+#![allow(unused_variables, dead_code)]
+
+fn main() {
+ match Some(0) {
+ None => None,
+ Some(x) => {
+ if x > 0 {
+ None
+ } else {
+ Some(x)
+ }
+ },
+ };
+
+ match Some(1) {
+ Some(x) => {
+ if x > 0 {
+ None
+ } else {
+ Some(x)
+ }
+ },
+ None => None,
+ };
+
+ match Some(2) {
+ Some(x) => {
+ if x > 0 {
+ None
+ } else {
+ Some(x)
+ }
+ },
+ _ => None,
+ };
+
+ match Some(3) {
+ Some(x) => {
+ if x > 0 {
+ Some(x)
+ } else {
+ None
+ }
+ },
+ None => None,
+ };
+
+ let y = Some(4);
+ match y {
+ // Some(4)
+ None => None,
+ Some(x) => {
+ if x > 0 {
+ None
+ } else {
+ Some(x)
+ }
+ },
+ };
+
+ match Some(5) {
+ Some(x) => {
+ if x > 0 {
+ Some(x)
+ } else {
+ None
+ }
+ },
+ _ => None,
+ };
+
+ match Some(6) {
+ Some(ref x) => {
+ if x > &0 {
+ Some(x)
+ } else {
+ None
+ }
+ },
+ _ => None,
+ };
+
+ let external_cond = true;
+ match Some(String::new()) {
+ Some(x) => {
+ if external_cond {
+ Some(x)
+ } else {
+ None
+ }
+ },
+ _ => None,
+ };
+
+ if let Some(x) = Some(7) {
+ if external_cond { Some(x) } else { None }
+ } else {
+ None
+ };
+
+ match &Some(8) {
+ &Some(x) => {
+ if x != 0 {
+ Some(x)
+ } else {
+ None
+ }
+ },
+ _ => None,
+ };
+
+ match Some(9) {
+ Some(x) => {
+ if x > 10 && x < 100 {
+ Some(x)
+ } else {
+ None
+ }
+ },
+ None => None,
+ };
+
+ const fn f1() {
+ // Don't lint, `.filter` is not const
+ match Some(10) {
+ Some(x) => {
+ if x > 10 && x < 100 {
+ Some(x)
+ } else {
+ None
+ }
+ },
+ None => None,
+ };
+ }
+
+ #[allow(clippy::blocks_in_if_conditions)]
+ match Some(11) {
+ // Lint, statement is preserved by `.filter`
+ Some(x) => {
+ if {
+ println!("foo");
+ x > 10 && x < 100
+ } {
+ Some(x)
+ } else {
+ None
+ }
+ },
+ None => None,
+ };
+
+ match Some(12) {
+ // Don't Lint, statement is lost by `.filter`
+ Some(x) => {
+ if x > 10 && x < 100 {
+ println!("foo");
+ Some(x)
+ } else {
+ None
+ }
+ },
+ None => None,
+ };
+
+ match Some(13) {
+ // Don't Lint, because of `None => Some(1)`
+ Some(x) => {
+ if x > 10 && x < 100 {
+ println!("foo");
+ Some(x)
+ } else {
+ None
+ }
+ },
+ None => Some(1),
+ };
+
+ unsafe fn f(x: u32) -> bool {
+ true
+ }
+ let _ = match Some(14) {
+ Some(x) => {
+ if unsafe { f(x) } {
+ Some(x)
+ } else {
+ None
+ }
+ },
+ None => None,
+ };
+ let _ = match Some(15) {
+ Some(x) => unsafe {
+ if f(x) { Some(x) } else { None }
+ },
+ None => None,
+ };
+
+ #[allow(clippy::redundant_pattern_matching)]
+ if let Some(_) = Some(16) {
+ Some(16)
+ } else if let Some(x) = Some(16) {
+ // Lint starting from here
+ if x % 2 == 0 { Some(x) } else { None }
+ } else {
+ None
+ };
+
+ match Some((17, 17)) {
+ // Not linted for now could be
+ Some((x, y)) => {
+ if y != x {
+ Some((x, y))
+ } else {
+ None
+ }
+ },
+ None => None,
+ };
+
+ struct NamedTuple {
+ pub x: u8,
+ pub y: (i32, u32),
+ }
+
+ match Some(NamedTuple {
+ // Not linted for now could be
+ x: 17,
+ y: (18, 19),
+ }) {
+ Some(NamedTuple { x, y }) => {
+ if y.1 != x as u32 {
+ Some(NamedTuple { x, y })
+ } else {
+ None
+ }
+ },
+ None => None,
+ };
+}
diff --git a/src/tools/clippy/tests/ui/manual_filter.stderr b/src/tools/clippy/tests/ui/manual_filter.stderr
new file mode 100644
index 000000000..53dea9229
--- /dev/null
+++ b/src/tools/clippy/tests/ui/manual_filter.stderr
@@ -0,0 +1,191 @@
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:7:5
+ |
+LL | / match Some(0) {
+LL | | None => None,
+LL | | Some(x) => {
+LL | | if x > 0 {
+... |
+LL | | },
+LL | | };
+ | |_____^ help: try this: `Some(0).filter(|&x| x <= 0)`
+ |
+ = note: `-D clippy::manual-filter` implied by `-D warnings`
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:18:5
+ |
+LL | / match Some(1) {
+LL | | Some(x) => {
+LL | | if x > 0 {
+LL | | None
+... |
+LL | | None => None,
+LL | | };
+ | |_____^ help: try this: `Some(1).filter(|&x| x <= 0)`
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:29:5
+ |
+LL | / match Some(2) {
+LL | | Some(x) => {
+LL | | if x > 0 {
+LL | | None
+... |
+LL | | _ => None,
+LL | | };
+ | |_____^ help: try this: `Some(2).filter(|&x| x <= 0)`
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:40:5
+ |
+LL | / match Some(3) {
+LL | | Some(x) => {
+LL | | if x > 0 {
+LL | | Some(x)
+... |
+LL | | None => None,
+LL | | };
+ | |_____^ help: try this: `Some(3).filter(|&x| x > 0)`
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:52:5
+ |
+LL | / match y {
+LL | | // Some(4)
+LL | | None => None,
+LL | | Some(x) => {
+... |
+LL | | },
+LL | | };
+ | |_____^ help: try this: `y.filter(|&x| x <= 0)`
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:64:5
+ |
+LL | / match Some(5) {
+LL | | Some(x) => {
+LL | | if x > 0 {
+LL | | Some(x)
+... |
+LL | | _ => None,
+LL | | };
+ | |_____^ help: try this: `Some(5).filter(|&x| x > 0)`
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:75:5
+ |
+LL | / match Some(6) {
+LL | | Some(ref x) => {
+LL | | if x > &0 {
+LL | | Some(x)
+... |
+LL | | _ => None,
+LL | | };
+ | |_____^ help: try this: `Some(6).as_ref().filter(|&x| x > &0)`
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:87:5
+ |
+LL | / match Some(String::new()) {
+LL | | Some(x) => {
+LL | | if external_cond {
+LL | | Some(x)
+... |
+LL | | _ => None,
+LL | | };
+ | |_____^ help: try this: `Some(String::new()).filter(|x| external_cond)`
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:98:5
+ |
+LL | / if let Some(x) = Some(7) {
+LL | | if external_cond { Some(x) } else { None }
+LL | | } else {
+LL | | None
+LL | | };
+ | |_____^ help: try this: `Some(7).filter(|&x| external_cond)`
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:104:5
+ |
+LL | / match &Some(8) {
+LL | | &Some(x) => {
+LL | | if x != 0 {
+LL | | Some(x)
+... |
+LL | | _ => None,
+LL | | };
+ | |_____^ help: try this: `Some(8).filter(|&x| x != 0)`
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:115:5
+ |
+LL | / match Some(9) {
+LL | | Some(x) => {
+LL | | if x > 10 && x < 100 {
+LL | | Some(x)
+... |
+LL | | None => None,
+LL | | };
+ | |_____^ help: try this: `Some(9).filter(|&x| x > 10 && x < 100)`
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:141:5
+ |
+LL | / match Some(11) {
+LL | | // Lint, statement is preserved by `.filter`
+LL | | Some(x) => {
+LL | | if {
+... |
+LL | | None => None,
+LL | | };
+ | |_____^
+ |
+help: try this
+ |
+LL ~ Some(11).filter(|&x| {
+LL + println!("foo");
+LL + x > 10 && x < 100
+LL ~ });
+ |
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:185:13
+ |
+LL | let _ = match Some(14) {
+ | _____________^
+LL | | Some(x) => {
+LL | | if unsafe { f(x) } {
+LL | | Some(x)
+... |
+LL | | None => None,
+LL | | };
+ | |_____^ help: try this: `Some(14).filter(|&x| unsafe { f(x) })`
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:195:13
+ |
+LL | let _ = match Some(15) {
+ | _____________^
+LL | | Some(x) => unsafe {
+LL | | if f(x) { Some(x) } else { None }
+LL | | },
+LL | | None => None,
+LL | | };
+ | |_____^ help: try this: `Some(15).filter(|&x| unsafe { f(x) })`
+
+error: manual implementation of `Option::filter`
+ --> $DIR/manual_filter.rs:205:12
+ |
+LL | } else if let Some(x) = Some(16) {
+ | ____________^
+LL | | // Lint starting from here
+LL | | if x % 2 == 0 { Some(x) } else { None }
+LL | | } else {
+LL | | None
+LL | | };
+ | |_____^ help: try this: `{ Some(16).filter(|&x| x % 2 == 0) }`
+
+error: aborting due to 15 previous errors
+
diff --git a/src/tools/clippy/tests/ui/manual_find.stderr b/src/tools/clippy/tests/ui/manual_find.stderr
index da0fd4aae..ea04bb066 100644
--- a/src/tools/clippy/tests/ui/manual_find.stderr
+++ b/src/tools/clippy/tests/ui/manual_find.stderr
@@ -9,8 +9,8 @@ LL | | }
LL | | None
| |________^ help: replace with an iterator: `strings.into_iter().find(|s| s == String::new())`
|
- = note: `-D clippy::manual-find` implied by `-D warnings`
= note: you may need to dereference some variables
+ = note: `-D clippy::manual-find` implied by `-D warnings`
error: manual implementation of `Iterator::find`
--> $DIR/manual_find.rs:14:5
diff --git a/src/tools/clippy/tests/ui/manual_find_fixable.fixed b/src/tools/clippy/tests/ui/manual_find_fixable.fixed
index 36d1644c2..2bce6e624 100644
--- a/src/tools/clippy/tests/ui/manual_find_fixable.fixed
+++ b/src/tools/clippy/tests/ui/manual_find_fixable.fixed
@@ -1,7 +1,7 @@
// run-rustfix
-
-#![allow(unused, clippy::needless_return)]
#![warn(clippy::manual_find)]
+#![allow(unused)]
+#![allow(clippy::needless_return, clippy::uninlined_format_args)]
use std::collections::HashMap;
diff --git a/src/tools/clippy/tests/ui/manual_find_fixable.rs b/src/tools/clippy/tests/ui/manual_find_fixable.rs
index ed277ddaa..f5c6de37a 100644
--- a/src/tools/clippy/tests/ui/manual_find_fixable.rs
+++ b/src/tools/clippy/tests/ui/manual_find_fixable.rs
@@ -1,7 +1,7 @@
// run-rustfix
-
-#![allow(unused, clippy::needless_return)]
#![warn(clippy::manual_find)]
+#![allow(unused)]
+#![allow(clippy::needless_return, clippy::uninlined_format_args)]
use std::collections::HashMap;
diff --git a/src/tools/clippy/tests/ui/manual_flatten.rs b/src/tools/clippy/tests/ui/manual_flatten.rs
index d922593bc..96cd87c0e 100644
--- a/src/tools/clippy/tests/ui/manual_flatten.rs
+++ b/src/tools/clippy/tests/ui/manual_flatten.rs
@@ -1,5 +1,5 @@
#![warn(clippy::manual_flatten)]
-#![allow(clippy::useless_vec)]
+#![allow(clippy::useless_vec, clippy::uninlined_format_args)]
fn main() {
// Test for loop over implicitly adjusted `Iterator` with `if let` expression
diff --git a/src/tools/clippy/tests/ui/manual_flatten.stderr b/src/tools/clippy/tests/ui/manual_flatten.stderr
index da053c056..180a6ff4e 100644
--- a/src/tools/clippy/tests/ui/manual_flatten.stderr
+++ b/src/tools/clippy/tests/ui/manual_flatten.stderr
@@ -11,7 +11,6 @@ LL | | }
LL | | }
| |_____^
|
- = note: `-D clippy::manual-flatten` implied by `-D warnings`
help: ...and remove the `if let` statement in the for loop
--> $DIR/manual_flatten.rs:8:9
|
@@ -19,6 +18,7 @@ LL | / if let Some(y) = n {
LL | | println!("{}", y);
LL | | }
| |_________^
+ = note: `-D clippy::manual-flatten` implied by `-D warnings`
error: unnecessary `if let` since only the `Ok` variant of the iterator element is used
--> $DIR/manual_flatten.rs:15:5
diff --git a/src/tools/clippy/tests/ui/manual_map_option.fixed b/src/tools/clippy/tests/ui/manual_map_option.fixed
index a59da4ae1..e12ea7ec1 100644
--- a/src/tools/clippy/tests/ui/manual_map_option.fixed
+++ b/src/tools/clippy/tests/ui/manual_map_option.fixed
@@ -7,7 +7,7 @@
clippy::unit_arg,
clippy::match_ref_pats,
clippy::redundant_pattern_matching,
- clippy::for_loops_over_fallibles,
+ for_loops_over_fallibles,
dead_code
)]
diff --git a/src/tools/clippy/tests/ui/manual_map_option.rs b/src/tools/clippy/tests/ui/manual_map_option.rs
index 0bdbefa51..325a6db06 100644
--- a/src/tools/clippy/tests/ui/manual_map_option.rs
+++ b/src/tools/clippy/tests/ui/manual_map_option.rs
@@ -7,7 +7,7 @@
clippy::unit_arg,
clippy::match_ref_pats,
clippy::redundant_pattern_matching,
- clippy::for_loops_over_fallibles,
+ for_loops_over_fallibles,
dead_code
)]
diff --git a/src/tools/clippy/tests/ui/manual_non_exhaustive_enum.stderr b/src/tools/clippy/tests/ui/manual_non_exhaustive_enum.stderr
index 144fe86df..087f766be 100644
--- a/src/tools/clippy/tests/ui/manual_non_exhaustive_enum.stderr
+++ b/src/tools/clippy/tests/ui/manual_non_exhaustive_enum.stderr
@@ -13,12 +13,12 @@ LL | | _C,
LL | | }
| |_^
|
- = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings`
help: remove this variant
--> $DIR/manual_non_exhaustive_enum.rs:9:5
|
LL | _C,
| ^^
+ = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings`
error: this seems like a manual implementation of the non-exhaustive pattern
--> $DIR/manual_non_exhaustive_enum.rs:14:1
diff --git a/src/tools/clippy/tests/ui/manual_non_exhaustive_struct.stderr b/src/tools/clippy/tests/ui/manual_non_exhaustive_struct.stderr
index e0766c17b..d0bed8e11 100644
--- a/src/tools/clippy/tests/ui/manual_non_exhaustive_struct.stderr
+++ b/src/tools/clippy/tests/ui/manual_non_exhaustive_struct.stderr
@@ -12,12 +12,12 @@ LL | | _c: (),
LL | | }
| |_____^
|
- = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings`
help: remove this field
--> $DIR/manual_non_exhaustive_struct.rs:8:9
|
LL | _c: (),
| ^^^^^^
+ = note: `-D clippy::manual-non-exhaustive` implied by `-D warnings`
error: this seems like a manual implementation of the non-exhaustive pattern
--> $DIR/manual_non_exhaustive_struct.rs:13:5
diff --git a/src/tools/clippy/tests/ui/manual_rem_euclid.fixed b/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
index 5601c96c1..b942fbfe9 100644
--- a/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
+++ b/src/tools/clippy/tests/ui/manual_rem_euclid.fixed
@@ -1,6 +1,7 @@
// run-rustfix
// aux-build:macro_rules.rs
+#![feature(custom_inner_attributes)]
#![warn(clippy::manual_rem_euclid)]
#[macro_use]
@@ -53,3 +54,32 @@ pub fn rem_euclid_4(num: i32) -> i32 {
pub const fn const_rem_euclid_4(num: i32) -> i32 {
num.rem_euclid(4)
}
+
+pub fn msrv_1_37() {
+ #![clippy::msrv = "1.37"]
+
+ let x: i32 = 10;
+ let _: i32 = ((x % 4) + 4) % 4;
+}
+
+pub fn msrv_1_38() {
+ #![clippy::msrv = "1.38"]
+
+ let x: i32 = 10;
+ let _: i32 = x.rem_euclid(4);
+}
+
+// For const fns:
+pub const fn msrv_1_51() {
+ #![clippy::msrv = "1.51"]
+
+ let x: i32 = 10;
+ let _: i32 = ((x % 4) + 4) % 4;
+}
+
+pub const fn msrv_1_52() {
+ #![clippy::msrv = "1.52"]
+
+ let x: i32 = 10;
+ let _: i32 = x.rem_euclid(4);
+}
diff --git a/src/tools/clippy/tests/ui/manual_rem_euclid.rs b/src/tools/clippy/tests/ui/manual_rem_euclid.rs
index 52135be26..7462d5321 100644
--- a/src/tools/clippy/tests/ui/manual_rem_euclid.rs
+++ b/src/tools/clippy/tests/ui/manual_rem_euclid.rs
@@ -1,6 +1,7 @@
// run-rustfix
// aux-build:macro_rules.rs
+#![feature(custom_inner_attributes)]
#![warn(clippy::manual_rem_euclid)]
#[macro_use]
@@ -53,3 +54,32 @@ pub fn rem_euclid_4(num: i32) -> i32 {
pub const fn const_rem_euclid_4(num: i32) -> i32 {
((num % 4) + 4) % 4
}
+
+pub fn msrv_1_37() {
+ #![clippy::msrv = "1.37"]
+
+ let x: i32 = 10;
+ let _: i32 = ((x % 4) + 4) % 4;
+}
+
+pub fn msrv_1_38() {
+ #![clippy::msrv = "1.38"]
+
+ let x: i32 = 10;
+ let _: i32 = ((x % 4) + 4) % 4;
+}
+
+// For const fns:
+pub const fn msrv_1_51() {
+ #![clippy::msrv = "1.51"]
+
+ let x: i32 = 10;
+ let _: i32 = ((x % 4) + 4) % 4;
+}
+
+pub const fn msrv_1_52() {
+ #![clippy::msrv = "1.52"]
+
+ let x: i32 = 10;
+ let _: i32 = ((x % 4) + 4) % 4;
+}
diff --git a/src/tools/clippy/tests/ui/manual_rem_euclid.stderr b/src/tools/clippy/tests/ui/manual_rem_euclid.stderr
index a237fd021..d51bac03b 100644
--- a/src/tools/clippy/tests/ui/manual_rem_euclid.stderr
+++ b/src/tools/clippy/tests/ui/manual_rem_euclid.stderr
@@ -1,5 +1,5 @@
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:19:18
+ --> $DIR/manual_rem_euclid.rs:20:18
|
LL | let _: i32 = ((value % 4) + 4) % 4;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)`
@@ -7,31 +7,31 @@ LL | let _: i32 = ((value % 4) + 4) % 4;
= note: `-D clippy::manual-rem-euclid` implied by `-D warnings`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:20:18
+ --> $DIR/manual_rem_euclid.rs:21:18
|
LL | let _: i32 = (4 + (value % 4)) % 4;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:21:18
+ --> $DIR/manual_rem_euclid.rs:22:18
|
LL | let _: i32 = (value % 4 + 4) % 4;
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:22:18
+ --> $DIR/manual_rem_euclid.rs:23:18
|
LL | let _: i32 = (4 + value % 4) % 4;
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:23:22
+ --> $DIR/manual_rem_euclid.rs:24:22
|
LL | let _: i32 = 1 + (4 + value % 4) % 4;
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:12:22
+ --> $DIR/manual_rem_euclid.rs:13:22
|
LL | let _: i32 = ((value % 4) + 4) % 4;
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using: `value.rem_euclid(4)`
@@ -42,16 +42,28 @@ LL | internal_rem_euclid!();
= note: this error originates in the macro `internal_rem_euclid` (in Nightly builds, run with -Z macro-backtrace for more info)
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:49:5
+ --> $DIR/manual_rem_euclid.rs:50:5
|
LL | ((num % 4) + 4) % 4
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `num.rem_euclid(4)`
error: manual `rem_euclid` implementation
- --> $DIR/manual_rem_euclid.rs:54:5
+ --> $DIR/manual_rem_euclid.rs:55:5
|
LL | ((num % 4) + 4) % 4
| ^^^^^^^^^^^^^^^^^^^ help: consider using: `num.rem_euclid(4)`
-error: aborting due to 8 previous errors
+error: manual `rem_euclid` implementation
+ --> $DIR/manual_rem_euclid.rs:69:18
+ |
+LL | let _: i32 = ((x % 4) + 4) % 4;
+ | ^^^^^^^^^^^^^^^^^ help: consider using: `x.rem_euclid(4)`
+
+error: manual `rem_euclid` implementation
+ --> $DIR/manual_rem_euclid.rs:84:18
+ |
+LL | let _: i32 = ((x % 4) + 4) % 4;
+ | ^^^^^^^^^^^^^^^^^ help: consider using: `x.rem_euclid(4)`
+
+error: aborting due to 10 previous errors
diff --git a/src/tools/clippy/tests/ui/manual_strip.rs b/src/tools/clippy/tests/ui/manual_strip.rs
index cbb84eb5c..85009d785 100644
--- a/src/tools/clippy/tests/ui/manual_strip.rs
+++ b/src/tools/clippy/tests/ui/manual_strip.rs
@@ -1,3 +1,4 @@
+#![feature(custom_inner_attributes)]
#![warn(clippy::manual_strip)]
fn main() {
@@ -64,3 +65,21 @@ fn main() {
s4[2..].to_string();
}
}
+
+fn msrv_1_44() {
+ #![clippy::msrv = "1.44"]
+
+ let s = "abc";
+ if s.starts_with('a') {
+ s[1..].to_string();
+ }
+}
+
+fn msrv_1_45() {
+ #![clippy::msrv = "1.45"]
+
+ let s = "abc";
+ if s.starts_with('a') {
+ s[1..].to_string();
+ }
+}
diff --git a/src/tools/clippy/tests/ui/manual_strip.stderr b/src/tools/clippy/tests/ui/manual_strip.stderr
index 896edf2ae..ad2a362f3 100644
--- a/src/tools/clippy/tests/ui/manual_strip.stderr
+++ b/src/tools/clippy/tests/ui/manual_strip.stderr
@@ -1,15 +1,15 @@
error: stripping a prefix manually
- --> $DIR/manual_strip.rs:7:24
+ --> $DIR/manual_strip.rs:8:24
|
LL | str::to_string(&s["ab".len()..]);
| ^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::manual-strip` implied by `-D warnings`
note: the prefix was tested here
- --> $DIR/manual_strip.rs:6:5
+ --> $DIR/manual_strip.rs:7:5
|
LL | if s.starts_with("ab") {
| ^^^^^^^^^^^^^^^^^^^^^^^
+ = note: `-D clippy::manual-strip` implied by `-D warnings`
help: try using the `strip_prefix` method
|
LL ~ if let Some(<stripped>) = s.strip_prefix("ab") {
@@ -21,13 +21,13 @@ LL ~ <stripped>.to_string();
|
error: stripping a suffix manually
- --> $DIR/manual_strip.rs:15:24
+ --> $DIR/manual_strip.rs:16:24
|
LL | str::to_string(&s[..s.len() - "bc".len()]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the suffix was tested here
- --> $DIR/manual_strip.rs:14:5
+ --> $DIR/manual_strip.rs:15:5
|
LL | if s.ends_with("bc") {
| ^^^^^^^^^^^^^^^^^^^^^
@@ -42,13 +42,13 @@ LL ~ <stripped>.to_string();
|
error: stripping a prefix manually
- --> $DIR/manual_strip.rs:24:24
+ --> $DIR/manual_strip.rs:25:24
|
LL | str::to_string(&s[1..]);
| ^^^^^^^
|
note: the prefix was tested here
- --> $DIR/manual_strip.rs:23:5
+ --> $DIR/manual_strip.rs:24:5
|
LL | if s.starts_with('a') {
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -60,13 +60,13 @@ LL ~ <stripped>.to_string();
|
error: stripping a prefix manually
- --> $DIR/manual_strip.rs:31:24
+ --> $DIR/manual_strip.rs:32:24
|
LL | str::to_string(&s[prefix.len()..]);
| ^^^^^^^^^^^^^^^^^^
|
note: the prefix was tested here
- --> $DIR/manual_strip.rs:30:5
+ --> $DIR/manual_strip.rs:31:5
|
LL | if s.starts_with(prefix) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -77,13 +77,13 @@ LL ~ str::to_string(<stripped>);
|
error: stripping a prefix manually
- --> $DIR/manual_strip.rs:37:24
+ --> $DIR/manual_strip.rs:38:24
|
LL | str::to_string(&s[PREFIX.len()..]);
| ^^^^^^^^^^^^^^^^^^
|
note: the prefix was tested here
- --> $DIR/manual_strip.rs:36:5
+ --> $DIR/manual_strip.rs:37:5
|
LL | if s.starts_with(PREFIX) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -95,13 +95,13 @@ LL ~ str::to_string(<stripped>);
|
error: stripping a prefix manually
- --> $DIR/manual_strip.rs:44:24
+ --> $DIR/manual_strip.rs:45:24
|
LL | str::to_string(&TARGET[prefix.len()..]);
| ^^^^^^^^^^^^^^^^^^^^^^^
|
note: the prefix was tested here
- --> $DIR/manual_strip.rs:43:5
+ --> $DIR/manual_strip.rs:44:5
|
LL | if TARGET.starts_with(prefix) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -112,13 +112,13 @@ LL ~ str::to_string(<stripped>);
|
error: stripping a prefix manually
- --> $DIR/manual_strip.rs:50:9
+ --> $DIR/manual_strip.rs:51:9
|
LL | s1[2..].to_uppercase();
| ^^^^^^^
|
note: the prefix was tested here
- --> $DIR/manual_strip.rs:49:5
+ --> $DIR/manual_strip.rs:50:5
|
LL | if s1.starts_with("ab") {
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -128,5 +128,22 @@ LL ~ if let Some(<stripped>) = s1.strip_prefix("ab") {
LL ~ <stripped>.to_uppercase();
|
-error: aborting due to 7 previous errors
+error: stripping a prefix manually
+ --> $DIR/manual_strip.rs:83:9
+ |
+LL | s[1..].to_string();
+ | ^^^^^^
+ |
+note: the prefix was tested here
+ --> $DIR/manual_strip.rs:82:5
+ |
+LL | if s.starts_with('a') {
+ | ^^^^^^^^^^^^^^^^^^^^^^
+help: try using the `strip_prefix` method
+ |
+LL ~ if let Some(<stripped>) = s.strip_prefix('a') {
+LL ~ <stripped>.to_string();
+ |
+
+error: aborting due to 8 previous errors
diff --git a/src/tools/clippy/tests/ui/map_err.stderr b/src/tools/clippy/tests/ui/map_err.stderr
index c03584052..d44403a84 100644
--- a/src/tools/clippy/tests/ui/map_err.stderr
+++ b/src/tools/clippy/tests/ui/map_err.stderr
@@ -4,8 +4,8 @@ error: `map_err(|_|...` wildcard pattern discards the original error
LL | println!("{:?}", x.map_err(|_| Errors::Ignored));
| ^^^
|
- = note: `-D clippy::map-err-ignore` implied by `-D warnings`
= help: consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`)
+ = note: `-D clippy::map-err-ignore` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/map_unwrap_or.rs b/src/tools/clippy/tests/ui/map_unwrap_or.rs
index 87e16f5d0..396b22a9a 100644
--- a/src/tools/clippy/tests/ui/map_unwrap_or.rs
+++ b/src/tools/clippy/tests/ui/map_unwrap_or.rs
@@ -1,6 +1,8 @@
// aux-build:option_helpers.rs
+#![feature(custom_inner_attributes)]
#![warn(clippy::map_unwrap_or)]
+#![allow(clippy::uninlined_format_args, clippy::unnecessary_lazy_evaluations)]
#[macro_use]
extern crate option_helpers;
@@ -79,3 +81,19 @@ fn main() {
option_methods();
result_methods();
}
+
+fn msrv_1_40() {
+ #![clippy::msrv = "1.40"]
+
+ let res: Result<i32, ()> = Ok(1);
+
+ let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
+}
+
+fn msrv_1_41() {
+ #![clippy::msrv = "1.41"]
+
+ let res: Result<i32, ()> = Ok(1);
+
+ let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
+}
diff --git a/src/tools/clippy/tests/ui/map_unwrap_or.stderr b/src/tools/clippy/tests/ui/map_unwrap_or.stderr
index abc9c1ece..d17d24a40 100644
--- a/src/tools/clippy/tests/ui/map_unwrap_or.stderr
+++ b/src/tools/clippy/tests/ui/map_unwrap_or.stderr
@@ -1,5 +1,5 @@
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:16:13
+ --> $DIR/map_unwrap_or.rs:18:13
|
LL | let _ = opt.map(|x| x + 1)
| _____________^
@@ -15,7 +15,7 @@ LL + let _ = opt.map_or(0, |x| x + 1);
|
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:20:13
+ --> $DIR/map_unwrap_or.rs:22:13
|
LL | let _ = opt.map(|x| {
| _____________^
@@ -33,7 +33,7 @@ LL ~ );
|
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:24:13
+ --> $DIR/map_unwrap_or.rs:26:13
|
LL | let _ = opt.map(|x| x + 1)
| _____________^
@@ -50,7 +50,7 @@ LL ~ }, |x| x + 1);
|
error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
- --> $DIR/map_unwrap_or.rs:29:13
+ --> $DIR/map_unwrap_or.rs:31:13
|
LL | let _ = opt.map(|x| Some(x + 1)).unwrap_or(None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -62,7 +62,7 @@ LL + let _ = opt.and_then(|x| Some(x + 1));
|
error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
- --> $DIR/map_unwrap_or.rs:31:13
+ --> $DIR/map_unwrap_or.rs:33:13
|
LL | let _ = opt.map(|x| {
| _____________^
@@ -80,7 +80,7 @@ LL ~ );
|
error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
- --> $DIR/map_unwrap_or.rs:35:13
+ --> $DIR/map_unwrap_or.rs:37:13
|
LL | let _ = opt
| _____________^
@@ -95,7 +95,7 @@ LL + .and_then(|x| Some(x + 1));
|
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:46:13
+ --> $DIR/map_unwrap_or.rs:48:13
|
LL | let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -107,7 +107,7 @@ LL + let _ = Some("prefix").map_or(id, |p| format!("{}.", p));
|
error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:50:13
+ --> $DIR/map_unwrap_or.rs:52:13
|
LL | let _ = opt.map(|x| {
| _____________^
@@ -117,7 +117,7 @@ LL | | ).unwrap_or_else(|| 0);
| |__________________________^
error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:54:13
+ --> $DIR/map_unwrap_or.rs:56:13
|
LL | let _ = opt.map(|x| x + 1)
| _____________^
@@ -127,7 +127,7 @@ LL | | );
| |_________^
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:66:13
+ --> $DIR/map_unwrap_or.rs:68:13
|
LL | let _ = res.map(|x| {
| _____________^
@@ -137,7 +137,7 @@ LL | | ).unwrap_or_else(|_e| 0);
| |____________________________^
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
- --> $DIR/map_unwrap_or.rs:70:13
+ --> $DIR/map_unwrap_or.rs:72:13
|
LL | let _ = res.map(|x| x + 1)
| _____________^
@@ -146,5 +146,11 @@ LL | | 0
LL | | });
| |__________^
-error: aborting due to 11 previous errors
+error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
+ --> $DIR/map_unwrap_or.rs:98:13
+ |
+LL | let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `res.map_or_else(|_e| 0, |x| x + 1)`
+
+error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed
index 95ca571d0..249800769 100644
--- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed
+++ b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed
@@ -1,5 +1,6 @@
// run-rustfix
+#![feature(custom_inner_attributes)]
#![warn(clippy::match_like_matches_macro)]
#![allow(unreachable_patterns, dead_code, clippy::equatable_if_let)]
@@ -193,3 +194,18 @@ fn main() {
_ => false,
};
}
+
+fn msrv_1_41() {
+ #![clippy::msrv = "1.41"]
+
+ let _y = match Some(5) {
+ Some(0) => true,
+ _ => false,
+ };
+}
+
+fn msrv_1_42() {
+ #![clippy::msrv = "1.42"]
+
+ let _y = matches!(Some(5), Some(0));
+}
diff --git a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs
index 3b9c8cada..b4e48499b 100644
--- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs
+++ b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.rs
@@ -1,5 +1,6 @@
// run-rustfix
+#![feature(custom_inner_attributes)]
#![warn(clippy::match_like_matches_macro)]
#![allow(unreachable_patterns, dead_code, clippy::equatable_if_let)]
@@ -234,3 +235,21 @@ fn main() {
_ => false,
};
}
+
+fn msrv_1_41() {
+ #![clippy::msrv = "1.41"]
+
+ let _y = match Some(5) {
+ Some(0) => true,
+ _ => false,
+ };
+}
+
+fn msrv_1_42() {
+ #![clippy::msrv = "1.42"]
+
+ let _y = match Some(5) {
+ Some(0) => true,
+ _ => false,
+ };
+}
diff --git a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr
index e94555e27..f1d1c23ae 100644
--- a/src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr
+++ b/src/tools/clippy/tests/ui/match_expr_like_matches_macro.stderr
@@ -1,5 +1,5 @@
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:10:14
+ --> $DIR/match_expr_like_matches_macro.rs:11:14
|
LL | let _y = match x {
| ______________^
@@ -11,7 +11,7 @@ LL | | };
= note: `-D clippy::match-like-matches-macro` implied by `-D warnings`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:16:14
+ --> $DIR/match_expr_like_matches_macro.rs:17:14
|
LL | let _w = match x {
| ______________^
@@ -21,7 +21,7 @@ LL | | };
| |_____^ help: try this: `matches!(x, Some(_))`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/match_expr_like_matches_macro.rs:22:14
+ --> $DIR/match_expr_like_matches_macro.rs:23:14
|
LL | let _z = match x {
| ______________^
@@ -33,7 +33,7 @@ LL | | };
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:28:15
+ --> $DIR/match_expr_like_matches_macro.rs:29:15
|
LL | let _zz = match x {
| _______________^
@@ -43,13 +43,13 @@ LL | | };
| |_____^ help: try this: `!matches!(x, Some(r) if r == 0)`
error: if let .. else expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:34:16
+ --> $DIR/match_expr_like_matches_macro.rs:35:16
|
LL | let _zzz = if let Some(5) = x { true } else { false };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `matches!(x, Some(5))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:58:20
+ --> $DIR/match_expr_like_matches_macro.rs:59:20
|
LL | let _ans = match x {
| ____________________^
@@ -60,7 +60,7 @@ LL | | };
| |_________^ help: try this: `matches!(x, E::A(_) | E::B(_))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:68:20
+ --> $DIR/match_expr_like_matches_macro.rs:69:20
|
LL | let _ans = match x {
| ____________________^
@@ -73,7 +73,7 @@ LL | | };
| |_________^ help: try this: `matches!(x, E::A(_) | E::B(_))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:78:20
+ --> $DIR/match_expr_like_matches_macro.rs:79:20
|
LL | let _ans = match x {
| ____________________^
@@ -84,7 +84,7 @@ LL | | };
| |_________^ help: try this: `!matches!(x, E::B(_) | E::C)`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:138:18
+ --> $DIR/match_expr_like_matches_macro.rs:139:18
|
LL | let _z = match &z {
| __________________^
@@ -94,7 +94,7 @@ LL | | };
| |_________^ help: try this: `matches!(z, Some(3))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:147:18
+ --> $DIR/match_expr_like_matches_macro.rs:148:18
|
LL | let _z = match &z {
| __________________^
@@ -104,7 +104,7 @@ LL | | };
| |_________^ help: try this: `matches!(&z, Some(3))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:164:21
+ --> $DIR/match_expr_like_matches_macro.rs:165:21
|
LL | let _ = match &z {
| _____________________^
@@ -114,7 +114,7 @@ LL | | };
| |_____________^ help: try this: `matches!(&z, AnEnum::X)`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:178:20
+ --> $DIR/match_expr_like_matches_macro.rs:179:20
|
LL | let _res = match &val {
| ____________________^
@@ -124,7 +124,7 @@ LL | | };
| |_________^ help: try this: `matches!(&val, &Some(ref _a))`
error: match expression looks like `matches!` macro
- --> $DIR/match_expr_like_matches_macro.rs:190:20
+ --> $DIR/match_expr_like_matches_macro.rs:191:20
|
LL | let _res = match &val {
| ____________________^
@@ -133,5 +133,15 @@ LL | | _ => false,
LL | | };
| |_________^ help: try this: `matches!(&val, &Some(ref _a))`
-error: aborting due to 13 previous errors
+error: match expression looks like `matches!` macro
+ --> $DIR/match_expr_like_matches_macro.rs:251:14
+ |
+LL | let _y = match Some(5) {
+ | ______________^
+LL | | Some(0) => true,
+LL | | _ => false,
+LL | | };
+ | |_____^ help: try this: `matches!(Some(5), Some(0))`
+
+error: aborting due to 14 previous errors
diff --git a/src/tools/clippy/tests/ui/match_overlapping_arm.rs b/src/tools/clippy/tests/ui/match_overlapping_arm.rs
index 2f85e6357..b4097fa96 100644
--- a/src/tools/clippy/tests/ui/match_overlapping_arm.rs
+++ b/src/tools/clippy/tests/ui/match_overlapping_arm.rs
@@ -1,5 +1,4 @@
#![feature(exclusive_range_pattern)]
-#![feature(half_open_range_patterns)]
#![warn(clippy::match_overlapping_arm)]
#![allow(clippy::redundant_pattern_matching)]
#![allow(clippy::if_same_then_else, clippy::equatable_if_let)]
diff --git a/src/tools/clippy/tests/ui/match_overlapping_arm.stderr b/src/tools/clippy/tests/ui/match_overlapping_arm.stderr
index b81bb1ecf..b98d4799e 100644
--- a/src/tools/clippy/tests/ui/match_overlapping_arm.stderr
+++ b/src/tools/clippy/tests/ui/match_overlapping_arm.stderr
@@ -1,96 +1,96 @@
error: some ranges overlap
- --> $DIR/match_overlapping_arm.rs:13:9
+ --> $DIR/match_overlapping_arm.rs:12:9
|
LL | 0..=10 => println!("0..=10"),
| ^^^^^^
|
- = note: `-D clippy::match-overlapping-arm` implied by `-D warnings`
note: overlaps with this
- --> $DIR/match_overlapping_arm.rs:14:9
+ --> $DIR/match_overlapping_arm.rs:13:9
|
LL | 0..=11 => println!("0..=11"),
| ^^^^^^
+ = note: `-D clippy::match-overlapping-arm` implied by `-D warnings`
error: some ranges overlap
- --> $DIR/match_overlapping_arm.rs:19:9
+ --> $DIR/match_overlapping_arm.rs:18:9
|
LL | 0..=5 => println!("0..=5"),
| ^^^^^
|
note: overlaps with this
- --> $DIR/match_overlapping_arm.rs:21:9
+ --> $DIR/match_overlapping_arm.rs:20:9
|
LL | FOO..=11 => println!("FOO..=11"),
| ^^^^^^^^
error: some ranges overlap
- --> $DIR/match_overlapping_arm.rs:56:9
+ --> $DIR/match_overlapping_arm.rs:55:9
|
LL | 0..11 => println!("0..11"),
| ^^^^^
|
note: overlaps with this
- --> $DIR/match_overlapping_arm.rs:57:9
+ --> $DIR/match_overlapping_arm.rs:56:9
|
LL | 0..=11 => println!("0..=11"),
| ^^^^^^
error: some ranges overlap
- --> $DIR/match_overlapping_arm.rs:81:9
+ --> $DIR/match_overlapping_arm.rs:80:9
|
LL | 0..=10 => println!("0..=10"),
| ^^^^^^
|
note: overlaps with this
- --> $DIR/match_overlapping_arm.rs:80:9
+ --> $DIR/match_overlapping_arm.rs:79:9
|
LL | 5..14 => println!("5..14"),
| ^^^^^
error: some ranges overlap
- --> $DIR/match_overlapping_arm.rs:86:9
+ --> $DIR/match_overlapping_arm.rs:85:9
|
LL | 0..7 => println!("0..7"),
| ^^^^
|
note: overlaps with this
- --> $DIR/match_overlapping_arm.rs:87:9
+ --> $DIR/match_overlapping_arm.rs:86:9
|
LL | 0..=10 => println!("0..=10"),
| ^^^^^^
error: some ranges overlap
- --> $DIR/match_overlapping_arm.rs:98:9
+ --> $DIR/match_overlapping_arm.rs:97:9
|
LL | ..=23 => println!("..=23"),
| ^^^^^
|
note: overlaps with this
- --> $DIR/match_overlapping_arm.rs:99:9
+ --> $DIR/match_overlapping_arm.rs:98:9
|
LL | ..26 => println!("..26"),
| ^^^^
error: some ranges overlap
- --> $DIR/match_overlapping_arm.rs:107:9
+ --> $DIR/match_overlapping_arm.rs:106:9
|
LL | 21..=30 => (),
| ^^^^^^^
|
note: overlaps with this
- --> $DIR/match_overlapping_arm.rs:108:9
+ --> $DIR/match_overlapping_arm.rs:107:9
|
LL | 21..=40 => (),
| ^^^^^^^
error: some ranges overlap
- --> $DIR/match_overlapping_arm.rs:121:9
+ --> $DIR/match_overlapping_arm.rs:120:9
|
LL | 0..=0x0000_0000_0000_00ff => (),
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: overlaps with this
- --> $DIR/match_overlapping_arm.rs:122:9
+ --> $DIR/match_overlapping_arm.rs:121:9
|
LL | 0..=0x0000_0000_0000_ffff => (),
| ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/match_ref_pats.fixed b/src/tools/clippy/tests/ui/match_ref_pats.fixed
index 1b6c2d924..cf37fc6dc 100644
--- a/src/tools/clippy/tests/ui/match_ref_pats.fixed
+++ b/src/tools/clippy/tests/ui/match_ref_pats.fixed
@@ -1,6 +1,7 @@
// run-rustfix
#![warn(clippy::match_ref_pats)]
-#![allow(dead_code, unused_variables, clippy::equatable_if_let, clippy::enum_variant_names)]
+#![allow(dead_code, unused_variables)]
+#![allow(clippy::enum_variant_names, clippy::equatable_if_let, clippy::uninlined_format_args)]
fn ref_pats() {
{
diff --git a/src/tools/clippy/tests/ui/match_ref_pats.rs b/src/tools/clippy/tests/ui/match_ref_pats.rs
index 68dfac4e2..3220b97d1 100644
--- a/src/tools/clippy/tests/ui/match_ref_pats.rs
+++ b/src/tools/clippy/tests/ui/match_ref_pats.rs
@@ -1,6 +1,7 @@
// run-rustfix
#![warn(clippy::match_ref_pats)]
-#![allow(dead_code, unused_variables, clippy::equatable_if_let, clippy::enum_variant_names)]
+#![allow(dead_code, unused_variables)]
+#![allow(clippy::enum_variant_names, clippy::equatable_if_let, clippy::uninlined_format_args)]
fn ref_pats() {
{
diff --git a/src/tools/clippy/tests/ui/match_ref_pats.stderr b/src/tools/clippy/tests/ui/match_ref_pats.stderr
index 353f7399d..7d9646c84 100644
--- a/src/tools/clippy/tests/ui/match_ref_pats.stderr
+++ b/src/tools/clippy/tests/ui/match_ref_pats.stderr
@@ -1,5 +1,5 @@
error: you don't need to add `&` to all patterns
- --> $DIR/match_ref_pats.rs:8:9
+ --> $DIR/match_ref_pats.rs:9:9
|
LL | / match v {
LL | | &Some(v) => println!("{:?}", v),
@@ -16,7 +16,7 @@ LL ~ None => println!("none"),
|
error: you don't need to add `&` to both the expression and the patterns
- --> $DIR/match_ref_pats.rs:25:5
+ --> $DIR/match_ref_pats.rs:26:5
|
LL | / match &w {
LL | | &Some(v) => println!("{:?}", v),
@@ -32,7 +32,7 @@ LL ~ None => println!("none"),
|
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/match_ref_pats.rs:37:12
+ --> $DIR/match_ref_pats.rs:38:12
|
LL | if let &None = a {
| -------^^^^^---- help: try this: `if a.is_none()`
@@ -40,13 +40,13 @@ LL | if let &None = a {
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: redundant pattern matching, consider using `is_none()`
- --> $DIR/match_ref_pats.rs:42:12
+ --> $DIR/match_ref_pats.rs:43:12
|
LL | if let &None = &b {
| -------^^^^^----- help: try this: `if b.is_none()`
error: you don't need to add `&` to all patterns
- --> $DIR/match_ref_pats.rs:102:9
+ --> $DIR/match_ref_pats.rs:103:9
|
LL | / match foobar_variant!(0) {
LL | | &FooBar::Foo => println!("Foo"),
diff --git a/src/tools/clippy/tests/ui/match_result_ok.fixed b/src/tools/clippy/tests/ui/match_result_ok.fixed
index d4760a975..8b91b9854 100644
--- a/src/tools/clippy/tests/ui/match_result_ok.fixed
+++ b/src/tools/clippy/tests/ui/match_result_ok.fixed
@@ -1,8 +1,7 @@
// run-rustfix
-
#![warn(clippy::match_result_ok)]
-#![allow(clippy::boxed_local)]
#![allow(dead_code)]
+#![allow(clippy::boxed_local, clippy::uninlined_format_args)]
// Checking `if` cases
diff --git a/src/tools/clippy/tests/ui/match_result_ok.rs b/src/tools/clippy/tests/ui/match_result_ok.rs
index 0b818723d..bc2c4b50e 100644
--- a/src/tools/clippy/tests/ui/match_result_ok.rs
+++ b/src/tools/clippy/tests/ui/match_result_ok.rs
@@ -1,8 +1,7 @@
// run-rustfix
-
#![warn(clippy::match_result_ok)]
-#![allow(clippy::boxed_local)]
#![allow(dead_code)]
+#![allow(clippy::boxed_local, clippy::uninlined_format_args)]
// Checking `if` cases
diff --git a/src/tools/clippy/tests/ui/match_result_ok.stderr b/src/tools/clippy/tests/ui/match_result_ok.stderr
index cc3bc8c76..98a95705c 100644
--- a/src/tools/clippy/tests/ui/match_result_ok.stderr
+++ b/src/tools/clippy/tests/ui/match_result_ok.stderr
@@ -1,5 +1,5 @@
error: matching on `Some` with `ok()` is redundant
- --> $DIR/match_result_ok.rs:10:5
+ --> $DIR/match_result_ok.rs:9:5
|
LL | if let Some(y) = x.parse().ok() { y } else { 0 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -11,7 +11,7 @@ LL | if let Ok(y) = x.parse() { y } else { 0 }
| ~~~~~~~~~~~~~~~~~~~~~~~~
error: matching on `Some` with `ok()` is redundant
- --> $DIR/match_result_ok.rs:20:9
+ --> $DIR/match_result_ok.rs:19:9
|
LL | if let Some(y) = x . parse() . ok () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | if let Ok(y) = x . parse() {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: matching on `Some` with `ok()` is redundant
- --> $DIR/match_result_ok.rs:46:5
+ --> $DIR/match_result_ok.rs:45:5
|
LL | while let Some(a) = wat.next().ok() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/match_same_arms.stderr b/src/tools/clippy/tests/ui/match_same_arms.stderr
index b6d04263b..db85b5964 100644
--- a/src/tools/clippy/tests/ui/match_same_arms.stderr
+++ b/src/tools/clippy/tests/ui/match_same_arms.stderr
@@ -4,13 +4,13 @@ error: this match arm has an identical body to the `_` wildcard arm
LL | Abc::A => 0,
| ^^^^^^^^^^^ help: try removing the arm
|
- = note: `-D clippy::match-same-arms` implied by `-D warnings`
= help: or try changing either arm body
note: `_` wildcard arm here
--> $DIR/match_same_arms.rs:13:9
|
LL | _ => 0, //~ ERROR match arms have same body
| ^^^^^^
+ = note: `-D clippy::match-same-arms` implied by `-D warnings`
error: this match arm has an identical body to another arm
--> $DIR/match_same_arms.rs:17:9
diff --git a/src/tools/clippy/tests/ui/match_same_arms2.rs b/src/tools/clippy/tests/ui/match_same_arms2.rs
index 61793e80c..82b2c433d 100644
--- a/src/tools/clippy/tests/ui/match_same_arms2.rs
+++ b/src/tools/clippy/tests/ui/match_same_arms2.rs
@@ -1,5 +1,9 @@
#![warn(clippy::match_same_arms)]
-#![allow(clippy::disallowed_names, clippy::diverging_sub_expression)]
+#![allow(
+ clippy::disallowed_names,
+ clippy::diverging_sub_expression,
+ clippy::uninlined_format_args
+)]
fn bar<T>(_: T) {}
fn foo() -> bool {
diff --git a/src/tools/clippy/tests/ui/match_same_arms2.stderr b/src/tools/clippy/tests/ui/match_same_arms2.stderr
index 14a672ba2..06cd43000 100644
--- a/src/tools/clippy/tests/ui/match_same_arms2.stderr
+++ b/src/tools/clippy/tests/ui/match_same_arms2.stderr
@@ -1,5 +1,5 @@
error: this match arm has an identical body to the `_` wildcard arm
- --> $DIR/match_same_arms2.rs:11:9
+ --> $DIR/match_same_arms2.rs:15:9
|
LL | / 42 => {
LL | | foo();
@@ -10,10 +10,9 @@ LL | | a
LL | | },
| |_________^ help: try removing the arm
|
- = note: `-D clippy::match-same-arms` implied by `-D warnings`
= help: or try changing either arm body
note: `_` wildcard arm here
- --> $DIR/match_same_arms2.rs:20:9
+ --> $DIR/match_same_arms2.rs:24:9
|
LL | / _ => {
LL | | //~ ERROR match arms have same body
@@ -23,9 +22,10 @@ LL | | let mut a = 42 + [23].len() as i32;
LL | | a
LL | | },
| |_________^
+ = note: `-D clippy::match-same-arms` implied by `-D warnings`
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:34:9
+ --> $DIR/match_same_arms2.rs:38:9
|
LL | 51 => foo(), //~ ERROR match arms have same body
| --^^^^^^^^^
@@ -34,13 +34,13 @@ LL | 51 => foo(), //~ ERROR match arms have same body
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:33:9
+ --> $DIR/match_same_arms2.rs:37:9
|
LL | 42 => foo(),
| ^^^^^^^^^^^
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:40:9
+ --> $DIR/match_same_arms2.rs:44:9
|
LL | None => 24, //~ ERROR match arms have same body
| ----^^^^^^
@@ -49,13 +49,13 @@ LL | None => 24, //~ ERROR match arms have same body
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:39:9
+ --> $DIR/match_same_arms2.rs:43:9
|
LL | Some(_) => 24,
| ^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:62:9
+ --> $DIR/match_same_arms2.rs:66:9
|
LL | (None, Some(a)) => bar(a), //~ ERROR match arms have same body
| ---------------^^^^^^^^^^
@@ -64,13 +64,13 @@ LL | (None, Some(a)) => bar(a), //~ ERROR match arms have same body
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:61:9
+ --> $DIR/match_same_arms2.rs:65:9
|
LL | (Some(a), None) => bar(a),
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:67:9
+ --> $DIR/match_same_arms2.rs:71:9
|
LL | (Some(a), ..) => bar(a),
| -------------^^^^^^^^^^
@@ -79,13 +79,13 @@ LL | (Some(a), ..) => bar(a),
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:68:9
+ --> $DIR/match_same_arms2.rs:72:9
|
LL | (.., Some(a)) => bar(a), //~ ERROR match arms have same body
| ^^^^^^^^^^^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:101:9
+ --> $DIR/match_same_arms2.rs:105:9
|
LL | (Ok(x), Some(_)) => println!("ok {}", x),
| ----------------^^^^^^^^^^^^^^^^^^^^^^^^
@@ -94,13 +94,13 @@ LL | (Ok(x), Some(_)) => println!("ok {}", x),
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:102:9
+ --> $DIR/match_same_arms2.rs:106:9
|
LL | (Ok(_), Some(x)) => println!("ok {}", x),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:117:9
+ --> $DIR/match_same_arms2.rs:121:9
|
LL | Ok(_) => println!("ok"),
| -----^^^^^^^^^^^^^^^^^^
@@ -109,13 +109,13 @@ LL | Ok(_) => println!("ok"),
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:116:9
+ --> $DIR/match_same_arms2.rs:120:9
|
LL | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:144:9
+ --> $DIR/match_same_arms2.rs:148:9
|
LL | 1 => {
| ^ help: try merging the arm patterns: `1 | 0`
@@ -127,7 +127,7 @@ LL | | },
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:141:9
+ --> $DIR/match_same_arms2.rs:145:9
|
LL | / 0 => {
LL | | empty!(0);
@@ -135,7 +135,7 @@ LL | | },
| |_________^
error: match expression looks like `matches!` macro
- --> $DIR/match_same_arms2.rs:162:16
+ --> $DIR/match_same_arms2.rs:166:16
|
LL | let _ans = match x {
| ________________^
@@ -148,7 +148,7 @@ LL | | };
= note: `-D clippy::match-like-matches-macro` implied by `-D warnings`
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:194:9
+ --> $DIR/match_same_arms2.rs:198:9
|
LL | Foo::X(0) => 1,
| ---------^^^^^
@@ -157,13 +157,13 @@ LL | Foo::X(0) => 1,
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:196:9
+ --> $DIR/match_same_arms2.rs:200:9
|
LL | Foo::Z(_) => 1,
| ^^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:204:9
+ --> $DIR/match_same_arms2.rs:208:9
|
LL | Foo::Z(_) => 1,
| ---------^^^^^
@@ -172,13 +172,13 @@ LL | Foo::Z(_) => 1,
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:202:9
+ --> $DIR/match_same_arms2.rs:206:9
|
LL | Foo::X(0) => 1,
| ^^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
- --> $DIR/match_same_arms2.rs:227:9
+ --> $DIR/match_same_arms2.rs:231:9
|
LL | Some(Bar { y: 0, x: 5, .. }) => 1,
| ----------------------------^^^^^
@@ -187,7 +187,7 @@ LL | Some(Bar { y: 0, x: 5, .. }) => 1,
|
= help: or try changing either arm body
note: other arm here
- --> $DIR/match_same_arms2.rs:224:9
+ --> $DIR/match_same_arms2.rs:228:9
|
LL | Some(Bar { x: 0, y: 5, .. }) => 1,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/match_single_binding.fixed b/src/tools/clippy/tests/ui/match_single_binding.fixed
index de46e6cff..a6e315e47 100644
--- a/src/tools/clippy/tests/ui/match_single_binding.fixed
+++ b/src/tools/clippy/tests/ui/match_single_binding.fixed
@@ -1,7 +1,7 @@
// run-rustfix
-
#![warn(clippy::match_single_binding)]
-#![allow(unused_variables, clippy::toplevel_ref_arg)]
+#![allow(unused_variables)]
+#![allow(clippy::toplevel_ref_arg, clippy::uninlined_format_args)]
struct Point {
x: i32,
@@ -124,3 +124,12 @@ fn issue_8723() {
let _ = val;
}
+
+#[allow(dead_code)]
+fn issue_9575() {
+ fn side_effects() {}
+ let _ = || {
+ side_effects();
+ println!("Needs curlies");
+ };
+}
diff --git a/src/tools/clippy/tests/ui/match_single_binding.rs b/src/tools/clippy/tests/ui/match_single_binding.rs
index eea64fcb2..cecbd703e 100644
--- a/src/tools/clippy/tests/ui/match_single_binding.rs
+++ b/src/tools/clippy/tests/ui/match_single_binding.rs
@@ -1,7 +1,7 @@
// run-rustfix
-
#![warn(clippy::match_single_binding)]
-#![allow(unused_variables, clippy::toplevel_ref_arg)]
+#![allow(unused_variables)]
+#![allow(clippy::toplevel_ref_arg, clippy::uninlined_format_args)]
struct Point {
x: i32,
@@ -140,3 +140,11 @@ fn issue_8723() {
let _ = val;
}
+
+#[allow(dead_code)]
+fn issue_9575() {
+ fn side_effects() {}
+ let _ = || match side_effects() {
+ _ => println!("Needs curlies"),
+ };
+}
diff --git a/src/tools/clippy/tests/ui/match_single_binding.stderr b/src/tools/clippy/tests/ui/match_single_binding.stderr
index 5d4e7314b..2b9ec7ee7 100644
--- a/src/tools/clippy/tests/ui/match_single_binding.stderr
+++ b/src/tools/clippy/tests/ui/match_single_binding.stderr
@@ -196,5 +196,22 @@ LL + suf
LL ~ };
|
-error: aborting due to 13 previous errors
+error: this match could be replaced by its scrutinee and body
+ --> $DIR/match_single_binding.rs:147:16
+ |
+LL | let _ = || match side_effects() {
+ | ________________^
+LL | | _ => println!("Needs curlies"),
+LL | | };
+ | |_____^
+ |
+help: consider using the scrutinee and body instead
+ |
+LL ~ let _ = || {
+LL + side_effects();
+LL + println!("Needs curlies");
+LL ~ };
+ |
+
+error: aborting due to 14 previous errors
diff --git a/src/tools/clippy/tests/ui/match_single_binding2.fixed b/src/tools/clippy/tests/ui/match_single_binding2.fixed
index a91fcc212..6a7db67e3 100644
--- a/src/tools/clippy/tests/ui/match_single_binding2.fixed
+++ b/src/tools/clippy/tests/ui/match_single_binding2.fixed
@@ -1,7 +1,7 @@
// run-rustfix
-
#![warn(clippy::match_single_binding)]
#![allow(unused_variables)]
+#![allow(clippy::uninlined_format_args)]
fn main() {
// Lint (additional curly braces needed, see #6572)
diff --git a/src/tools/clippy/tests/ui/match_single_binding2.rs b/src/tools/clippy/tests/ui/match_single_binding2.rs
index 476386eba..5a4bb8441 100644
--- a/src/tools/clippy/tests/ui/match_single_binding2.rs
+++ b/src/tools/clippy/tests/ui/match_single_binding2.rs
@@ -1,7 +1,7 @@
// run-rustfix
-
#![warn(clippy::match_single_binding)]
#![allow(unused_variables)]
+#![allow(clippy::uninlined_format_args)]
fn main() {
// Lint (additional curly braces needed, see #6572)
diff --git a/src/tools/clippy/tests/ui/match_wild_err_arm.edition2018.stderr b/src/tools/clippy/tests/ui/match_wild_err_arm.edition2018.stderr
deleted file mode 100644
index 2d66daea8..000000000
--- a/src/tools/clippy/tests/ui/match_wild_err_arm.edition2018.stderr
+++ /dev/null
@@ -1,35 +0,0 @@
-error: `Err(_)` matches all errors
- --> $DIR/match_wild_err_arm.rs:14:9
- |
-LL | Err(_) => panic!("err"),
- | ^^^^^^
- |
- = note: `-D clippy::match-wild-err-arm` implied by `-D warnings`
- = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
-
-error: `Err(_)` matches all errors
- --> $DIR/match_wild_err_arm.rs:20:9
- |
-LL | Err(_) => panic!(),
- | ^^^^^^
- |
- = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
-
-error: `Err(_)` matches all errors
- --> $DIR/match_wild_err_arm.rs:26:9
- |
-LL | Err(_) => {
- | ^^^^^^
- |
- = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
-
-error: `Err(_e)` matches all errors
- --> $DIR/match_wild_err_arm.rs:34:9
- |
-LL | Err(_e) => panic!(),
- | ^^^^^^^
- |
- = note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
-
-error: aborting due to 4 previous errors
-
diff --git a/src/tools/clippy/tests/ui/match_wild_err_arm.rs b/src/tools/clippy/tests/ui/match_wild_err_arm.rs
index 0a86144b9..823be65ef 100644
--- a/src/tools/clippy/tests/ui/match_wild_err_arm.rs
+++ b/src/tools/clippy/tests/ui/match_wild_err_arm.rs
@@ -1,6 +1,3 @@
-// revisions: edition2018 edition2021
-// [edition2018] edition:2018
-// [edition2021] edition:2021
#![feature(exclusive_range_pattern)]
#![allow(clippy::match_same_arms)]
#![warn(clippy::match_wild_err_arm)]
diff --git a/src/tools/clippy/tests/ui/match_wild_err_arm.edition2021.stderr b/src/tools/clippy/tests/ui/match_wild_err_arm.stderr
index 2d66daea8..b016d6826 100644
--- a/src/tools/clippy/tests/ui/match_wild_err_arm.edition2021.stderr
+++ b/src/tools/clippy/tests/ui/match_wild_err_arm.stderr
@@ -1,14 +1,14 @@
error: `Err(_)` matches all errors
- --> $DIR/match_wild_err_arm.rs:14:9
+ --> $DIR/match_wild_err_arm.rs:11:9
|
LL | Err(_) => panic!("err"),
| ^^^^^^
|
- = note: `-D clippy::match-wild-err-arm` implied by `-D warnings`
= note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
+ = note: `-D clippy::match-wild-err-arm` implied by `-D warnings`
error: `Err(_)` matches all errors
- --> $DIR/match_wild_err_arm.rs:20:9
+ --> $DIR/match_wild_err_arm.rs:17:9
|
LL | Err(_) => panic!(),
| ^^^^^^
@@ -16,7 +16,7 @@ LL | Err(_) => panic!(),
= note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
error: `Err(_)` matches all errors
- --> $DIR/match_wild_err_arm.rs:26:9
+ --> $DIR/match_wild_err_arm.rs:23:9
|
LL | Err(_) => {
| ^^^^^^
@@ -24,7 +24,7 @@ LL | Err(_) => {
= note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
error: `Err(_e)` matches all errors
- --> $DIR/match_wild_err_arm.rs:34:9
+ --> $DIR/match_wild_err_arm.rs:31:9
|
LL | Err(_e) => panic!(),
| ^^^^^^^
diff --git a/src/tools/clippy/tests/ui/mem_replace.fixed b/src/tools/clippy/tests/ui/mem_replace.fixed
index b609ba659..ae237395b 100644
--- a/src/tools/clippy/tests/ui/mem_replace.fixed
+++ b/src/tools/clippy/tests/ui/mem_replace.fixed
@@ -1,5 +1,7 @@
// run-rustfix
-#![allow(unused_imports)]
+
+#![feature(custom_inner_attributes)]
+#![allow(unused)]
#![warn(
clippy::all,
clippy::style,
@@ -77,3 +79,17 @@ fn main() {
replace_with_default();
dont_lint_primitive();
}
+
+fn msrv_1_39() {
+ #![clippy::msrv = "1.39"]
+
+ let mut s = String::from("foo");
+ let _ = std::mem::replace(&mut s, String::default());
+}
+
+fn msrv_1_40() {
+ #![clippy::msrv = "1.40"]
+
+ let mut s = String::from("foo");
+ let _ = std::mem::take(&mut s);
+}
diff --git a/src/tools/clippy/tests/ui/mem_replace.rs b/src/tools/clippy/tests/ui/mem_replace.rs
index 93f6dcdec..3202e99e0 100644
--- a/src/tools/clippy/tests/ui/mem_replace.rs
+++ b/src/tools/clippy/tests/ui/mem_replace.rs
@@ -1,5 +1,7 @@
// run-rustfix
-#![allow(unused_imports)]
+
+#![feature(custom_inner_attributes)]
+#![allow(unused)]
#![warn(
clippy::all,
clippy::style,
@@ -77,3 +79,17 @@ fn main() {
replace_with_default();
dont_lint_primitive();
}
+
+fn msrv_1_39() {
+ #![clippy::msrv = "1.39"]
+
+ let mut s = String::from("foo");
+ let _ = std::mem::replace(&mut s, String::default());
+}
+
+fn msrv_1_40() {
+ #![clippy::msrv = "1.40"]
+
+ let mut s = String::from("foo");
+ let _ = std::mem::replace(&mut s, String::default());
+}
diff --git a/src/tools/clippy/tests/ui/mem_replace.stderr b/src/tools/clippy/tests/ui/mem_replace.stderr
index 90dc6c95f..dd8a50dab 100644
--- a/src/tools/clippy/tests/ui/mem_replace.stderr
+++ b/src/tools/clippy/tests/ui/mem_replace.stderr
@@ -1,5 +1,5 @@
error: replacing an `Option` with `None`
- --> $DIR/mem_replace.rs:15:13
+ --> $DIR/mem_replace.rs:17:13
|
LL | let _ = mem::replace(&mut an_option, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()`
@@ -7,13 +7,13 @@ LL | let _ = mem::replace(&mut an_option, None);
= note: `-D clippy::mem-replace-option-with-none` implied by `-D warnings`
error: replacing an `Option` with `None`
- --> $DIR/mem_replace.rs:17:13
+ --> $DIR/mem_replace.rs:19:13
|
LL | let _ = mem::replace(an_option, None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:22:13
+ --> $DIR/mem_replace.rs:24:13
|
LL | let _ = std::mem::replace(&mut s, String::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)`
@@ -21,100 +21,106 @@ LL | let _ = std::mem::replace(&mut s, String::default());
= note: `-D clippy::mem-replace-with-default` implied by `-D warnings`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:25:13
+ --> $DIR/mem_replace.rs:27:13
|
LL | let _ = std::mem::replace(s, String::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:26:13
+ --> $DIR/mem_replace.rs:28:13
|
LL | let _ = std::mem::replace(s, Default::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:29:13
+ --> $DIR/mem_replace.rs:31:13
|
LL | let _ = std::mem::replace(&mut v, Vec::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:30:13
+ --> $DIR/mem_replace.rs:32:13
|
LL | let _ = std::mem::replace(&mut v, Default::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:31:13
+ --> $DIR/mem_replace.rs:33:13
|
LL | let _ = std::mem::replace(&mut v, Vec::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:32:13
+ --> $DIR/mem_replace.rs:34:13
|
LL | let _ = std::mem::replace(&mut v, vec![]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut v)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:35:13
+ --> $DIR/mem_replace.rs:37:13
|
LL | let _ = std::mem::replace(&mut hash_map, HashMap::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_map)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:38:13
+ --> $DIR/mem_replace.rs:40:13
|
LL | let _ = std::mem::replace(&mut btree_map, BTreeMap::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_map)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:41:13
+ --> $DIR/mem_replace.rs:43:13
|
LL | let _ = std::mem::replace(&mut vd, VecDeque::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut vd)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:44:13
+ --> $DIR/mem_replace.rs:46:13
|
LL | let _ = std::mem::replace(&mut hash_set, HashSet::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut hash_set)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:47:13
+ --> $DIR/mem_replace.rs:49:13
|
LL | let _ = std::mem::replace(&mut btree_set, BTreeSet::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut btree_set)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:50:13
+ --> $DIR/mem_replace.rs:52:13
|
LL | let _ = std::mem::replace(&mut list, LinkedList::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut list)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:53:13
+ --> $DIR/mem_replace.rs:55:13
|
LL | let _ = std::mem::replace(&mut binary_heap, BinaryHeap::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut binary_heap)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:56:13
+ --> $DIR/mem_replace.rs:58:13
|
LL | let _ = std::mem::replace(&mut tuple, (vec![], BinaryHeap::new()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut tuple)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:59:13
+ --> $DIR/mem_replace.rs:61:13
|
LL | let _ = std::mem::replace(&mut refstr, "");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut refstr)`
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
- --> $DIR/mem_replace.rs:62:13
+ --> $DIR/mem_replace.rs:64:13
|
LL | let _ = std::mem::replace(&mut slice, &[]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut slice)`
-error: aborting due to 19 previous errors
+error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
+ --> $DIR/mem_replace.rs:94:13
+ |
+LL | let _ = std::mem::replace(&mut s, String::default());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut s)`
+
+error: aborting due to 20 previous errors
diff --git a/src/tools/clippy/tests/ui/min_max.rs b/src/tools/clippy/tests/ui/min_max.rs
index b2bc97f47..24e52afd6 100644
--- a/src/tools/clippy/tests/ui/min_max.rs
+++ b/src/tools/clippy/tests/ui/min_max.rs
@@ -1,4 +1,5 @@
#![warn(clippy::all)]
+#![allow(clippy::manual_clamp)]
use std::cmp::max as my_max;
use std::cmp::min as my_min;
diff --git a/src/tools/clippy/tests/ui/min_max.stderr b/src/tools/clippy/tests/ui/min_max.stderr
index c70b77eab..069d90686 100644
--- a/src/tools/clippy/tests/ui/min_max.stderr
+++ b/src/tools/clippy/tests/ui/min_max.stderr
@@ -1,5 +1,5 @@
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:23:5
+ --> $DIR/min_max.rs:24:5
|
LL | min(1, max(3, x));
| ^^^^^^^^^^^^^^^^^
@@ -7,73 +7,73 @@ LL | min(1, max(3, x));
= note: `-D clippy::min-max` implied by `-D warnings`
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:24:5
+ --> $DIR/min_max.rs:25:5
|
LL | min(max(3, x), 1);
| ^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:25:5
+ --> $DIR/min_max.rs:26:5
|
LL | max(min(x, 1), 3);
| ^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:26:5
+ --> $DIR/min_max.rs:27:5
|
LL | max(3, min(x, 1));
| ^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:28:5
+ --> $DIR/min_max.rs:29:5
|
LL | my_max(3, my_min(x, 1));
| ^^^^^^^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:38:5
+ --> $DIR/min_max.rs:39:5
|
LL | min("Apple", max("Zoo", s));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:39:5
+ --> $DIR/min_max.rs:40:5
|
LL | max(min(s, "Apple"), "Zoo");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:44:5
+ --> $DIR/min_max.rs:45:5
|
LL | x.min(1).max(3);
| ^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:45:5
+ --> $DIR/min_max.rs:46:5
|
LL | x.max(3).min(1);
| ^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:46:5
+ --> $DIR/min_max.rs:47:5
|
LL | f.max(3f32).min(1f32);
| ^^^^^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:52:5
+ --> $DIR/min_max.rs:53:5
|
LL | max(x.min(1), 3);
| ^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:55:5
+ --> $DIR/min_max.rs:56:5
|
LL | s.max("Zoo").min("Apple");
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: this `min`/`max` combination leads to constant result
- --> $DIR/min_max.rs:56:5
+ --> $DIR/min_max.rs:57:5
|
LL | s.min("Apple").max("Zoo");
| ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/min_rust_version_attr.rs b/src/tools/clippy/tests/ui/min_rust_version_attr.rs
index 44e407bd1..cd148063b 100644
--- a/src/tools/clippy/tests/ui/min_rust_version_attr.rs
+++ b/src/tools/clippy/tests/ui/min_rust_version_attr.rs
@@ -1,228 +1,29 @@
#![allow(clippy::redundant_clone)]
#![feature(custom_inner_attributes)]
-#![clippy::msrv = "1.0.0"]
-use std::ops::{Deref, RangeFrom};
+fn main() {}
-fn approx_const() {
+fn just_under_msrv() {
+ #![clippy::msrv = "1.42.0"]
let log2_10 = 3.321928094887362;
- let log10_2 = 0.301029995663981;
}
-fn cloned_instead_of_copied() {
- let _ = [1].iter().cloned();
-}
-
-fn option_as_ref_deref() {
- let mut opt = Some(String::from("123"));
-
- let _ = opt.as_ref().map(String::as_str);
- let _ = opt.as_ref().map(|x| x.as_str());
- let _ = opt.as_mut().map(String::as_mut_str);
- let _ = opt.as_mut().map(|x| x.as_mut_str());
-}
-
-fn match_like_matches() {
- let _y = match Some(5) {
- Some(0) => true,
- _ => false,
- };
-}
-
-fn match_same_arms() {
- match (1, 2, 3) {
- (1, .., 3) => 42,
- (.., 3) => 42, //~ ERROR match arms have same body
- _ => 0,
- };
-}
-
-fn match_same_arms2() {
- let _ = match Some(42) {
- Some(_) => 24,
- None => 24, //~ ERROR match arms have same body
- };
-}
-
-pub fn manual_strip_msrv() {
- let s = "hello, world!";
- if s.starts_with("hello, ") {
- assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
- }
-}
-
-pub fn redundant_fieldnames() {
- let start = 0;
- let _ = RangeFrom { start: start };
-}
-
-pub fn redundant_static_lifetime() {
- const VAR_ONE: &'static str = "Test constant #1";
-}
-
-pub fn checked_conversion() {
- let value: i64 = 42;
- let _ = value <= (u32::max_value() as i64) && value >= 0;
- let _ = value <= (u32::MAX as i64) && value >= 0;
-}
-
-pub struct FromOverInto(String);
-
-impl Into<FromOverInto> for String {
- fn into(self) -> FromOverInto {
- FromOverInto(self)
- }
-}
-
-pub fn filter_map_next() {
- let a = ["1", "lol", "3", "NaN", "5"];
-
- #[rustfmt::skip]
- let _: Option<u32> = vec![1, 2, 3, 4, 5, 6]
- .into_iter()
- .filter_map(|x| {
- if x == 2 {
- Some(x * 2)
- } else {
- None
- }
- })
- .next();
-}
-
-#[allow(clippy::no_effect)]
-#[allow(clippy::short_circuit_statement)]
-#[allow(clippy::unnecessary_operation)]
-pub fn manual_range_contains() {
- let x = 5;
- x >= 8 && x < 12;
-}
-
-pub fn use_self() {
- struct Foo;
-
- impl Foo {
- fn new() -> Foo {
- Foo {}
- }
- fn test() -> Foo {
- Foo::new()
- }
- }
-}
-
-fn replace_with_default() {
- let mut s = String::from("foo");
- let _ = std::mem::replace(&mut s, String::default());
-}
-
-fn map_unwrap_or() {
- let opt = Some(1);
-
- // Check for `option.map(_).unwrap_or(_)` use.
- // Single line case.
- let _ = opt
- .map(|x| x + 1)
- // Should lint even though this call is on a separate line.
- .unwrap_or(0);
-}
-
-// Could be const
-fn missing_const_for_fn() -> i32 {
- 1
-}
-
-fn unnest_or_patterns() {
- struct TS(u8, u8);
- if let TS(0, x) | TS(1, x) = TS(0, 0) {}
-}
-
-#[cfg_attr(rustfmt, rustfmt_skip)]
-fn deprecated_cfg_attr() {}
-
-#[warn(clippy::cast_lossless)]
-fn int_from_bool() -> u8 {
- true as u8
-}
-
-fn err_expect() {
- let x: Result<u32, &str> = Ok(10);
- x.err().expect("Testing expect_err");
-}
-
-fn cast_abs_to_unsigned() {
- let x: i32 = 10;
- assert_eq!(10u32, x.abs() as u32);
-}
-
-fn manual_rem_euclid() {
- let x: i32 = 10;
- let _: i32 = ((x % 4) + 4) % 4;
-}
-
-fn main() {
- filter_map_next();
- checked_conversion();
- redundant_fieldnames();
- redundant_static_lifetime();
- option_as_ref_deref();
- match_like_matches();
- match_same_arms();
- match_same_arms2();
- manual_strip_msrv();
- manual_range_contains();
- use_self();
- replace_with_default();
- map_unwrap_or();
- missing_const_for_fn();
- unnest_or_patterns();
- int_from_bool();
- err_expect();
- cast_abs_to_unsigned();
- manual_rem_euclid();
+fn meets_msrv() {
+ #![clippy::msrv = "1.43.0"]
+ let log2_10 = 3.321928094887362;
}
-mod just_under_msrv {
- #![feature(custom_inner_attributes)]
+fn just_above_msrv() {
#![clippy::msrv = "1.44.0"]
-
- fn main() {
- let s = "hello, world!";
- if s.starts_with("hello, ") {
- assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
- }
- }
-}
-
-mod meets_msrv {
- #![feature(custom_inner_attributes)]
- #![clippy::msrv = "1.45.0"]
-
- fn main() {
- let s = "hello, world!";
- if s.starts_with("hello, ") {
- assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
- }
- }
+ let log2_10 = 3.321928094887362;
}
-mod just_above_msrv {
- #![feature(custom_inner_attributes)]
- #![clippy::msrv = "1.46.0"]
-
- fn main() {
- let s = "hello, world!";
- if s.starts_with("hello, ") {
- assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
- }
- }
+fn no_patch_under() {
+ #![clippy::msrv = "1.42"]
+ let log2_10 = 3.321928094887362;
}
-mod const_rem_euclid {
- #![feature(custom_inner_attributes)]
- #![clippy::msrv = "1.50.0"]
-
- pub const fn const_rem_euclid_4(num: i32) -> i32 {
- ((num % 4) + 4) % 4
- }
+fn no_patch_meets() {
+ #![clippy::msrv = "1.43"]
+ let log2_10 = 3.321928094887362;
}
diff --git a/src/tools/clippy/tests/ui/min_rust_version_attr.stderr b/src/tools/clippy/tests/ui/min_rust_version_attr.stderr
index b1c23b539..68aa58748 100644
--- a/src/tools/clippy/tests/ui/min_rust_version_attr.stderr
+++ b/src/tools/clippy/tests/ui/min_rust_version_attr.stderr
@@ -1,37 +1,27 @@
-error: stripping a prefix manually
- --> $DIR/min_rust_version_attr.rs:204:24
+error: approximate value of `f{32, 64}::consts::LOG2_10` found
+ --> $DIR/min_rust_version_attr.rs:13:19
|
-LL | assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
- | ^^^^^^^^^^^^^^^^^^^^
- |
- = note: `-D clippy::manual-strip` implied by `-D warnings`
-note: the prefix was tested here
- --> $DIR/min_rust_version_attr.rs:203:9
- |
-LL | if s.starts_with("hello, ") {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-help: try using the `strip_prefix` method
- |
-LL ~ if let Some(<stripped>) = s.strip_prefix("hello, ") {
-LL ~ assert_eq!(<stripped>.to_uppercase(), "WORLD!");
+LL | let log2_10 = 3.321928094887362;
+ | ^^^^^^^^^^^^^^^^^
|
+ = help: consider using the constant directly
+ = note: `#[deny(clippy::approx_constant)]` on by default
-error: stripping a prefix manually
- --> $DIR/min_rust_version_attr.rs:216:24
+error: approximate value of `f{32, 64}::consts::LOG2_10` found
+ --> $DIR/min_rust_version_attr.rs:18:19
|
-LL | assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
- | ^^^^^^^^^^^^^^^^^^^^
+LL | let log2_10 = 3.321928094887362;
+ | ^^^^^^^^^^^^^^^^^
|
-note: the prefix was tested here
- --> $DIR/min_rust_version_attr.rs:215:9
- |
-LL | if s.starts_with("hello, ") {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-help: try using the `strip_prefix` method
+ = help: consider using the constant directly
+
+error: approximate value of `f{32, 64}::consts::LOG2_10` found
+ --> $DIR/min_rust_version_attr.rs:28:19
|
-LL ~ if let Some(<stripped>) = s.strip_prefix("hello, ") {
-LL ~ assert_eq!(<stripped>.to_uppercase(), "WORLD!");
+LL | let log2_10 = 3.321928094887362;
+ | ^^^^^^^^^^^^^^^^^
|
+ = help: consider using the constant directly
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors
diff --git a/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.rs b/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.rs
index f20841891..02892f329 100644
--- a/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.rs
+++ b/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.rs
@@ -2,3 +2,17 @@
#![clippy::msrv = "invalid.version"]
fn main() {}
+
+#[clippy::msrv = "invalid.version"]
+fn outer_attr() {}
+
+mod multiple {
+ #![clippy::msrv = "1.40"]
+ #![clippy::msrv = "=1.35.0"]
+ #![clippy::msrv = "1.10.1"]
+
+ mod foo {
+ #![clippy::msrv = "1"]
+ #![clippy::msrv = "1.0.0"]
+ }
+}
diff --git a/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr b/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr
index 6ff88ca56..93370a0fa 100644
--- a/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr
+++ b/src/tools/clippy/tests/ui/min_rust_version_invalid_attr.stderr
@@ -4,5 +4,47 @@ error: `invalid.version` is not a valid Rust version
LL | #![clippy::msrv = "invalid.version"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to previous error
+error: `msrv` cannot be an outer attribute
+ --> $DIR/min_rust_version_invalid_attr.rs:6:1
+ |
+LL | #[clippy::msrv = "invalid.version"]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: `msrv` is defined multiple times
+ --> $DIR/min_rust_version_invalid_attr.rs:11:5
+ |
+LL | #![clippy::msrv = "=1.35.0"]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: first definition found here
+ --> $DIR/min_rust_version_invalid_attr.rs:10:5
+ |
+LL | #![clippy::msrv = "1.40"]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: `msrv` is defined multiple times
+ --> $DIR/min_rust_version_invalid_attr.rs:12:5
+ |
+LL | #![clippy::msrv = "1.10.1"]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: first definition found here
+ --> $DIR/min_rust_version_invalid_attr.rs:10:5
+ |
+LL | #![clippy::msrv = "1.40"]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: `msrv` is defined multiple times
+ --> $DIR/min_rust_version_invalid_attr.rs:16:9
+ |
+LL | #![clippy::msrv = "1.0.0"]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: first definition found here
+ --> $DIR/min_rust_version_invalid_attr.rs:15:9
+ |
+LL | #![clippy::msrv = "1"]
+ | ^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 5 previous errors
diff --git a/src/tools/clippy/tests/ui/min_rust_version_multiple_inner_attr.rs b/src/tools/clippy/tests/ui/min_rust_version_multiple_inner_attr.rs
deleted file mode 100644
index e882d5ccf..000000000
--- a/src/tools/clippy/tests/ui/min_rust_version_multiple_inner_attr.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-#![feature(custom_inner_attributes)]
-#![clippy::msrv = "1.40"]
-#![clippy::msrv = "=1.35.0"]
-#![clippy::msrv = "1.10.1"]
-
-mod foo {
- #![clippy::msrv = "1"]
- #![clippy::msrv = "1.0.0"]
-}
-
-fn main() {}
diff --git a/src/tools/clippy/tests/ui/min_rust_version_multiple_inner_attr.stderr b/src/tools/clippy/tests/ui/min_rust_version_multiple_inner_attr.stderr
deleted file mode 100644
index e3ff6605c..000000000
--- a/src/tools/clippy/tests/ui/min_rust_version_multiple_inner_attr.stderr
+++ /dev/null
@@ -1,38 +0,0 @@
-error: `msrv` is defined multiple times
- --> $DIR/min_rust_version_multiple_inner_attr.rs:3:1
- |
-LL | #![clippy::msrv = "=1.35.0"]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
-note: first definition found here
- --> $DIR/min_rust_version_multiple_inner_attr.rs:2:1
- |
-LL | #![clippy::msrv = "1.40"]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: `msrv` is defined multiple times
- --> $DIR/min_rust_version_multiple_inner_attr.rs:4:1
- |
-LL | #![clippy::msrv = "1.10.1"]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
-note: first definition found here
- --> $DIR/min_rust_version_multiple_inner_attr.rs:2:1
- |
-LL | #![clippy::msrv = "1.40"]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: `msrv` is defined multiple times
- --> $DIR/min_rust_version_multiple_inner_attr.rs:8:5
- |
-LL | #![clippy::msrv = "1.0.0"]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^
- |
-note: first definition found here
- --> $DIR/min_rust_version_multiple_inner_attr.rs:7:5
- |
-LL | #![clippy::msrv = "1"]
- | ^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 3 previous errors
-
diff --git a/src/tools/clippy/tests/ui/min_rust_version_no_patch.rs b/src/tools/clippy/tests/ui/min_rust_version_no_patch.rs
deleted file mode 100644
index 98fffe1e3..000000000
--- a/src/tools/clippy/tests/ui/min_rust_version_no_patch.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-#![allow(clippy::redundant_clone)]
-#![feature(custom_inner_attributes)]
-#![clippy::msrv = "1.0"]
-
-fn manual_strip_msrv() {
- let s = "hello, world!";
- if s.starts_with("hello, ") {
- assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
- }
-}
-
-fn main() {
- manual_strip_msrv()
-}
diff --git a/src/tools/clippy/tests/ui/min_rust_version_outer_attr.rs b/src/tools/clippy/tests/ui/min_rust_version_outer_attr.rs
deleted file mode 100644
index 551948bd7..000000000
--- a/src/tools/clippy/tests/ui/min_rust_version_outer_attr.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-#![feature(custom_inner_attributes)]
-
-#[clippy::msrv = "invalid.version"]
-fn main() {}
diff --git a/src/tools/clippy/tests/ui/min_rust_version_outer_attr.stderr b/src/tools/clippy/tests/ui/min_rust_version_outer_attr.stderr
deleted file mode 100644
index 579ee7a87..000000000
--- a/src/tools/clippy/tests/ui/min_rust_version_outer_attr.stderr
+++ /dev/null
@@ -1,8 +0,0 @@
-error: `msrv` cannot be an outer attribute
- --> $DIR/min_rust_version_outer_attr.rs:3:1
- |
-LL | #[clippy::msrv = "invalid.version"]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to previous error
-
diff --git a/src/tools/clippy/tests/ui/mismatched_target_os_unix.stderr b/src/tools/clippy/tests/ui/mismatched_target_os_unix.stderr
index 3534b5328..9822c77c9 100644
--- a/src/tools/clippy/tests/ui/mismatched_target_os_unix.stderr
+++ b/src/tools/clippy/tests/ui/mismatched_target_os_unix.stderr
@@ -6,8 +6,8 @@ LL | #[cfg(linux)]
| |
| help: try: `target_os = "linux"`
|
- = note: `-D clippy::mismatched-target-os` implied by `-D warnings`
= help: did you mean `unix`?
+ = note: `-D clippy::mismatched-target-os` implied by `-D warnings`
error: operating system used in target family position
--> $DIR/mismatched_target_os_unix.rs:9:1
diff --git a/src/tools/clippy/tests/ui/mismatching_type_param_order.stderr b/src/tools/clippy/tests/ui/mismatching_type_param_order.stderr
index cb720256c..204d49905 100644
--- a/src/tools/clippy/tests/ui/mismatching_type_param_order.stderr
+++ b/src/tools/clippy/tests/ui/mismatching_type_param_order.stderr
@@ -4,8 +4,8 @@ error: `Foo` has a similarly named generic type parameter `B` in its declaration
LL | impl<B, A> Foo<B, A> {}
| ^
|
- = note: `-D clippy::mismatching-type-param-order` implied by `-D warnings`
= help: try `A`, or a name that does not conflict with `Foo`'s generic params
+ = note: `-D clippy::mismatching-type-param-order` implied by `-D warnings`
error: `Foo` has a similarly named generic type parameter `A` in its declaration, but in a different order
--> $DIR/mismatching_type_param_order.rs:11:23
diff --git a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs
index 88f6935d2..b85e88784 100644
--- a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs
+++ b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.rs
@@ -77,5 +77,17 @@ mod const_fn_stabilized_before_msrv {
}
}
+fn msrv_1_45() -> i32 {
+ #![clippy::msrv = "1.45"]
+
+ 45
+}
+
+fn msrv_1_46() -> i32 {
+ #![clippy::msrv = "1.46"]
+
+ 46
+}
+
// Should not be const
fn main() {}
diff --git a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr
index 3eb52b682..f8e221c82 100644
--- a/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr
+++ b/src/tools/clippy/tests/ui/missing_const_for_fn/could_be_const.stderr
@@ -81,5 +81,15 @@ LL | | byte.is_ascii_digit();
LL | | }
| |_____^
-error: aborting due to 10 previous errors
+error: this could be a `const fn`
+ --> $DIR/could_be_const.rs:86:1
+ |
+LL | / fn msrv_1_46() -> i32 {
+LL | | #![clippy::msrv = "1.46"]
+LL | |
+LL | | 46
+LL | | }
+ | |_^
+
+error: aborting due to 11 previous errors
diff --git a/src/tools/clippy/tests/ui/missing_doc.rs b/src/tools/clippy/tests/ui/missing_doc.rs
index 29cc026a8..590ad63c9 100644
--- a/src/tools/clippy/tests/ui/missing_doc.rs
+++ b/src/tools/clippy/tests/ui/missing_doc.rs
@@ -1,3 +1,4 @@
+// needs-asm-support
// aux-build: proc_macro_with_span.rs
#![warn(clippy::missing_docs_in_private_items)]
diff --git a/src/tools/clippy/tests/ui/missing_doc.stderr b/src/tools/clippy/tests/ui/missing_doc.stderr
index 6c8e66f46..d3bef28bf 100644
--- a/src/tools/clippy/tests/ui/missing_doc.stderr
+++ b/src/tools/clippy/tests/ui/missing_doc.stderr
@@ -1,5 +1,5 @@
error: missing documentation for a type alias
- --> $DIR/missing_doc.rs:15:1
+ --> $DIR/missing_doc.rs:16:1
|
LL | type Typedef = String;
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -7,37 +7,37 @@ LL | type Typedef = String;
= note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings`
error: missing documentation for a type alias
- --> $DIR/missing_doc.rs:16:1
+ --> $DIR/missing_doc.rs:17:1
|
LL | pub type PubTypedef = String;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a module
- --> $DIR/missing_doc.rs:18:1
+ --> $DIR/missing_doc.rs:19:1
|
LL | mod module_no_dox {}
| ^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a module
- --> $DIR/missing_doc.rs:19:1
+ --> $DIR/missing_doc.rs:20:1
|
LL | pub mod pub_module_no_dox {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function
- --> $DIR/missing_doc.rs:23:1
+ --> $DIR/missing_doc.rs:24:1
|
LL | pub fn foo2() {}
| ^^^^^^^^^^^^^^^^
error: missing documentation for a function
- --> $DIR/missing_doc.rs:24:1
+ --> $DIR/missing_doc.rs:25:1
|
LL | fn foo3() {}
| ^^^^^^^^^^^^
error: missing documentation for an enum
- --> $DIR/missing_doc.rs:38:1
+ --> $DIR/missing_doc.rs:39:1
|
LL | / enum Baz {
LL | | BazA { a: isize, b: isize },
@@ -46,31 +46,31 @@ LL | | }
| |_^
error: missing documentation for a variant
- --> $DIR/missing_doc.rs:39:5
+ --> $DIR/missing_doc.rs:40:5
|
LL | BazA { a: isize, b: isize },
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a struct field
- --> $DIR/missing_doc.rs:39:12
+ --> $DIR/missing_doc.rs:40:12
|
LL | BazA { a: isize, b: isize },
| ^^^^^^^^
error: missing documentation for a struct field
- --> $DIR/missing_doc.rs:39:22
+ --> $DIR/missing_doc.rs:40:22
|
LL | BazA { a: isize, b: isize },
| ^^^^^^^^
error: missing documentation for a variant
- --> $DIR/missing_doc.rs:40:5
+ --> $DIR/missing_doc.rs:41:5
|
LL | BarB,
| ^^^^
error: missing documentation for an enum
- --> $DIR/missing_doc.rs:43:1
+ --> $DIR/missing_doc.rs:44:1
|
LL | / pub enum PubBaz {
LL | | PubBazA { a: isize },
@@ -78,43 +78,43 @@ LL | | }
| |_^
error: missing documentation for a variant
- --> $DIR/missing_doc.rs:44:5
+ --> $DIR/missing_doc.rs:45:5
|
LL | PubBazA { a: isize },
| ^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a struct field
- --> $DIR/missing_doc.rs:44:15
+ --> $DIR/missing_doc.rs:45:15
|
LL | PubBazA { a: isize },
| ^^^^^^^^
error: missing documentation for a constant
- --> $DIR/missing_doc.rs:64:1
+ --> $DIR/missing_doc.rs:65:1
|
LL | const FOO: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^
error: missing documentation for a constant
- --> $DIR/missing_doc.rs:71:1
+ --> $DIR/missing_doc.rs:72:1
|
LL | pub const FOO4: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a static
- --> $DIR/missing_doc.rs:73:1
+ --> $DIR/missing_doc.rs:74:1
|
LL | static BAR: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a static
- --> $DIR/missing_doc.rs:80:1
+ --> $DIR/missing_doc.rs:81:1
|
LL | pub static BAR4: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a module
- --> $DIR/missing_doc.rs:82:1
+ --> $DIR/missing_doc.rs:83:1
|
LL | / mod internal_impl {
LL | | /// dox
@@ -126,31 +126,31 @@ LL | | }
| |_^
error: missing documentation for a function
- --> $DIR/missing_doc.rs:85:5
+ --> $DIR/missing_doc.rs:86:5
|
LL | pub fn undocumented1() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function
- --> $DIR/missing_doc.rs:86:5
+ --> $DIR/missing_doc.rs:87:5
|
LL | pub fn undocumented2() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function
- --> $DIR/missing_doc.rs:87:5
+ --> $DIR/missing_doc.rs:88:5
|
LL | fn undocumented3() {}
| ^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function
- --> $DIR/missing_doc.rs:92:9
+ --> $DIR/missing_doc.rs:93:9
|
LL | pub fn also_undocumented1() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function
- --> $DIR/missing_doc.rs:93:9
+ --> $DIR/missing_doc.rs:94:9
|
LL | fn also_undocumented2() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/missing_panics_doc.stderr b/src/tools/clippy/tests/ui/missing_panics_doc.stderr
index 91ebd6952..c9ded7f1a 100644
--- a/src/tools/clippy/tests/ui/missing_panics_doc.stderr
+++ b/src/tools/clippy/tests/ui/missing_panics_doc.stderr
@@ -7,12 +7,12 @@ LL | | result.unwrap()
LL | | }
| |_^
|
- = note: `-D clippy::missing-panics-doc` implied by `-D warnings`
note: first possible panic found here
--> $DIR/missing_panics_doc.rs:8:5
|
LL | result.unwrap()
| ^^^^^^^^^^^^^^^
+ = note: `-D clippy::missing-panics-doc` implied by `-D warnings`
error: docs for function which may panic missing `# Panics` section
--> $DIR/missing_panics_doc.rs:12:1
diff --git a/src/tools/clippy/tests/ui/missing_trait_methods.rs b/src/tools/clippy/tests/ui/missing_trait_methods.rs
new file mode 100644
index 000000000..8df885919
--- /dev/null
+++ b/src/tools/clippy/tests/ui/missing_trait_methods.rs
@@ -0,0 +1,50 @@
+#![allow(unused, clippy::needless_lifetimes)]
+#![warn(clippy::missing_trait_methods)]
+
+trait A {
+ fn provided() {}
+}
+
+trait B {
+ fn required();
+
+ fn a(_: usize) -> usize {
+ 1
+ }
+
+ fn b<'a, T: AsRef<[u8]>>(a: &'a T) -> &'a [u8] {
+ a.as_ref()
+ }
+}
+
+struct Partial;
+
+impl A for Partial {}
+
+impl B for Partial {
+ fn required() {}
+
+ fn a(_: usize) -> usize {
+ 2
+ }
+}
+
+struct Complete;
+
+impl A for Complete {
+ fn provided() {}
+}
+
+impl B for Complete {
+ fn required() {}
+
+ fn a(_: usize) -> usize {
+ 2
+ }
+
+ fn b<T: AsRef<[u8]>>(a: &T) -> &[u8] {
+ a.as_ref()
+ }
+}
+
+fn main() {}
diff --git a/src/tools/clippy/tests/ui/missing_trait_methods.stderr b/src/tools/clippy/tests/ui/missing_trait_methods.stderr
new file mode 100644
index 000000000..0c5205e19
--- /dev/null
+++ b/src/tools/clippy/tests/ui/missing_trait_methods.stderr
@@ -0,0 +1,27 @@
+error: missing trait method provided by default: `provided`
+ --> $DIR/missing_trait_methods.rs:22:1
+ |
+LL | impl A for Partial {}
+ | ^^^^^^^^^^^^^^^^^^
+ |
+help: implement the method
+ --> $DIR/missing_trait_methods.rs:5:5
+ |
+LL | fn provided() {}
+ | ^^^^^^^^^^^^^
+ = note: `-D clippy::missing-trait-methods` implied by `-D warnings`
+
+error: missing trait method provided by default: `b`
+ --> $DIR/missing_trait_methods.rs:24:1
+ |
+LL | impl B for Partial {
+ | ^^^^^^^^^^^^^^^^^^
+ |
+help: implement the method
+ --> $DIR/missing_trait_methods.rs:15:5
+ |
+LL | fn b<'a, T: AsRef<[u8]>>(a: &'a T) -> &'a [u8] {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/src/tools/clippy/tests/ui/mixed_read_write_in_expression.stderr b/src/tools/clippy/tests/ui/mixed_read_write_in_expression.stderr
index 2e951cdbc..8cc68b0ac 100644
--- a/src/tools/clippy/tests/ui/mixed_read_write_in_expression.stderr
+++ b/src/tools/clippy/tests/ui/mixed_read_write_in_expression.stderr
@@ -4,12 +4,12 @@ error: unsequenced read of `x`
LL | } + x;
| ^
|
- = note: `-D clippy::mixed-read-write-in-expression` implied by `-D warnings`
note: whether read occurs before this write depends on evaluation order
--> $DIR/mixed_read_write_in_expression.rs:12:9
|
LL | x = 1;
| ^^^^^
+ = note: `-D clippy::mixed-read-write-in-expression` implied by `-D warnings`
error: unsequenced read of `x`
--> $DIR/mixed_read_write_in_expression.rs:17:5
diff --git a/src/tools/clippy/tests/ui/modulo_arithmetic_float.stderr b/src/tools/clippy/tests/ui/modulo_arithmetic_float.stderr
index 97844aaaa..36106de31 100644
--- a/src/tools/clippy/tests/ui/modulo_arithmetic_float.stderr
+++ b/src/tools/clippy/tests/ui/modulo_arithmetic_float.stderr
@@ -4,8 +4,8 @@ error: you are using modulo operator on constants with different signs: `-1.600
LL | -1.6 % 2.1;
| ^^^^^^^^^^
|
- = note: `-D clippy::modulo-arithmetic` implied by `-D warnings`
= note: double check for expected result especially when interoperating with different languages
+ = note: `-D clippy::modulo-arithmetic` implied by `-D warnings`
error: you are using modulo operator on constants with different signs: `1.600 % -2.100`
--> $DIR/modulo_arithmetic_float.rs:7:5
diff --git a/src/tools/clippy/tests/ui/modulo_arithmetic_integral.stderr b/src/tools/clippy/tests/ui/modulo_arithmetic_integral.stderr
index f71adf5b0..9ff676ff6 100644
--- a/src/tools/clippy/tests/ui/modulo_arithmetic_integral.stderr
+++ b/src/tools/clippy/tests/ui/modulo_arithmetic_integral.stderr
@@ -4,9 +4,9 @@ error: you are using modulo operator on types that might have different signs
LL | a % b;
| ^^^^^
|
- = note: `-D clippy::modulo-arithmetic` implied by `-D warnings`
= note: double check for expected result especially when interoperating with different languages
= note: or consider using `rem_euclid` or similar function
+ = note: `-D clippy::modulo-arithmetic` implied by `-D warnings`
error: you are using modulo operator on types that might have different signs
--> $DIR/modulo_arithmetic_integral.rs:9:5
diff --git a/src/tools/clippy/tests/ui/modulo_arithmetic_integral_const.stderr b/src/tools/clippy/tests/ui/modulo_arithmetic_integral_const.stderr
index 11b5f7746..1453d44f4 100644
--- a/src/tools/clippy/tests/ui/modulo_arithmetic_integral_const.stderr
+++ b/src/tools/clippy/tests/ui/modulo_arithmetic_integral_const.stderr
@@ -4,9 +4,9 @@ error: you are using modulo operator on constants with different signs: `-1 % 2`
LL | -1 % 2;
| ^^^^^^
|
- = note: `-D clippy::modulo-arithmetic` implied by `-D warnings`
= note: double check for expected result especially when interoperating with different languages
= note: or consider using `rem_euclid` or similar function
+ = note: `-D clippy::modulo-arithmetic` implied by `-D warnings`
error: you are using modulo operator on constants with different signs: `1 % -2`
--> $DIR/modulo_arithmetic_integral_const.rs:12:5
diff --git a/src/tools/clippy/tests/ui/mut_from_ref.stderr b/src/tools/clippy/tests/ui/mut_from_ref.stderr
index b76d6a13f..c20ff54bf 100644
--- a/src/tools/clippy/tests/ui/mut_from_ref.stderr
+++ b/src/tools/clippy/tests/ui/mut_from_ref.stderr
@@ -4,12 +4,12 @@ error: mutable borrow from immutable input(s)
LL | fn this_wont_hurt_a_bit(&self) -> &mut Foo {
| ^^^^^^^^
|
- = note: `-D clippy::mut-from-ref` implied by `-D warnings`
note: immutable borrow here
--> $DIR/mut_from_ref.rs:7:29
|
LL | fn this_wont_hurt_a_bit(&self) -> &mut Foo {
| ^^^^^
+ = note: `-D clippy::mut-from-ref` implied by `-D warnings`
error: mutable borrow from immutable input(s)
--> $DIR/mut_from_ref.rs:13:25
diff --git a/src/tools/clippy/tests/ui/mut_mut.rs b/src/tools/clippy/tests/ui/mut_mut.rs
index be854d941..ac8fd9d8f 100644
--- a/src/tools/clippy/tests/ui/mut_mut.rs
+++ b/src/tools/clippy/tests/ui/mut_mut.rs
@@ -1,7 +1,7 @@
// aux-build:macro_rules.rs
-
-#![allow(unused, clippy::no_effect, clippy::unnecessary_operation)]
#![warn(clippy::mut_mut)]
+#![allow(unused)]
+#![allow(clippy::no_effect, clippy::uninlined_format_args, clippy::unnecessary_operation)]
#[macro_use]
extern crate macro_rules;
diff --git a/src/tools/clippy/tests/ui/mut_range_bound.stderr b/src/tools/clippy/tests/ui/mut_range_bound.stderr
index 4b5a3fc1e..e0c8dced3 100644
--- a/src/tools/clippy/tests/ui/mut_range_bound.stderr
+++ b/src/tools/clippy/tests/ui/mut_range_bound.stderr
@@ -4,8 +4,8 @@ error: attempt to mutate range bound within loop
LL | m = 5;
| ^
|
- = note: `-D clippy::mut-range-bound` implied by `-D warnings`
= note: the range of the loop is unchanged
+ = note: `-D clippy::mut-range-bound` implied by `-D warnings`
error: attempt to mutate range bound within loop
--> $DIR/mut_range_bound.rs:15:9
diff --git a/src/tools/clippy/tests/ui/needless_borrow.fixed b/src/tools/clippy/tests/ui/needless_borrow.fixed
index 8cf93bd24..340e89d2d 100644
--- a/src/tools/clippy/tests/ui/needless_borrow.fixed
+++ b/src/tools/clippy/tests/ui/needless_borrow.fixed
@@ -1,9 +1,13 @@
// run-rustfix
-
#![feature(custom_inner_attributes, lint_reasons)]
#[warn(clippy::all, clippy::needless_borrow)]
-#[allow(unused_variables, clippy::unnecessary_mut_passed)]
+#[allow(unused_variables)]
+#[allow(
+ clippy::uninlined_format_args,
+ clippy::unnecessary_mut_passed,
+ clippy::unnecessary_to_owned
+)]
fn main() {
let a = 5;
let ref_a = &a;
@@ -134,6 +138,7 @@ fn main() {
multiple_constraints([[""]]);
multiple_constraints_normalizes_to_same(X, X);
let _ = Some("").unwrap_or("");
+ let _ = std::fs::write("x", "".to_string());
only_sized(&""); // Don't lint. `Sized` is only bound
let _ = std::any::Any::type_id(&""); // Don't lint. `Any` is only bound
@@ -276,8 +281,9 @@ mod copyable_iterator {
fn dont_warn(mut x: Iter) {
takes_iter(&mut x);
}
+ #[allow(unused_mut)]
fn warn(mut x: &mut Iter) {
- takes_iter(&mut x)
+ takes_iter(x)
}
}
@@ -298,3 +304,84 @@ mod meets_msrv {
let _ = std::process::Command::new("ls").args(["-a", "-l"]).status().unwrap();
}
}
+
+#[allow(unused)]
+fn issue9383() {
+ // Should not lint because unions need explicit deref when accessing field
+ use std::mem::ManuallyDrop;
+
+ union Coral {
+ crab: ManuallyDrop<Vec<i32>>,
+ }
+
+ union Ocean {
+ coral: ManuallyDrop<Coral>,
+ }
+
+ let mut ocean = Ocean {
+ coral: ManuallyDrop::new(Coral {
+ crab: ManuallyDrop::new(vec![1, 2, 3]),
+ }),
+ };
+
+ unsafe {
+ ManuallyDrop::drop(&mut (&mut ocean.coral).crab);
+
+ (*ocean.coral).crab = ManuallyDrop::new(vec![4, 5, 6]);
+ ManuallyDrop::drop(&mut (*ocean.coral).crab);
+
+ ManuallyDrop::drop(&mut ocean.coral);
+ }
+}
+
+#[allow(dead_code)]
+fn closure_test() {
+ let env = "env".to_owned();
+ let arg = "arg".to_owned();
+ let f = |arg| {
+ let loc = "loc".to_owned();
+ let _ = std::fs::write("x", &env); // Don't lint. In environment
+ let _ = std::fs::write("x", arg);
+ let _ = std::fs::write("x", loc);
+ };
+ let _ = std::fs::write("x", &env); // Don't lint. Borrowed by `f`
+ f(arg);
+}
+
+#[allow(dead_code)]
+mod significant_drop {
+ #[derive(Debug)]
+ struct X;
+
+ #[derive(Debug)]
+ struct Y;
+
+ impl Drop for Y {
+ fn drop(&mut self) {}
+ }
+
+ fn foo(x: X, y: Y) {
+ debug(x);
+ debug(&y); // Don't lint. Has significant drop
+ }
+
+ fn debug(_: impl std::fmt::Debug) {}
+}
+
+#[allow(dead_code)]
+mod used_exactly_once {
+ fn foo(x: String) {
+ use_x(x);
+ }
+ fn use_x(_: impl AsRef<str>) {}
+}
+
+#[allow(dead_code)]
+mod used_more_than_once {
+ fn foo(x: String) {
+ use_x(&x);
+ use_x_again(&x);
+ }
+ fn use_x(_: impl AsRef<str>) {}
+ fn use_x_again(_: impl AsRef<str>) {}
+}
diff --git a/src/tools/clippy/tests/ui/needless_borrow.rs b/src/tools/clippy/tests/ui/needless_borrow.rs
index fd9b2a11d..c93711ac8 100644
--- a/src/tools/clippy/tests/ui/needless_borrow.rs
+++ b/src/tools/clippy/tests/ui/needless_borrow.rs
@@ -1,9 +1,13 @@
// run-rustfix
-
#![feature(custom_inner_attributes, lint_reasons)]
#[warn(clippy::all, clippy::needless_borrow)]
-#[allow(unused_variables, clippy::unnecessary_mut_passed)]
+#[allow(unused_variables)]
+#[allow(
+ clippy::uninlined_format_args,
+ clippy::unnecessary_mut_passed,
+ clippy::unnecessary_to_owned
+)]
fn main() {
let a = 5;
let ref_a = &a;
@@ -134,6 +138,7 @@ fn main() {
multiple_constraints(&[[""]]);
multiple_constraints_normalizes_to_same(&X, X);
let _ = Some("").unwrap_or(&"");
+ let _ = std::fs::write("x", &"".to_string());
only_sized(&""); // Don't lint. `Sized` is only bound
let _ = std::any::Any::type_id(&""); // Don't lint. `Any` is only bound
@@ -276,6 +281,7 @@ mod copyable_iterator {
fn dont_warn(mut x: Iter) {
takes_iter(&mut x);
}
+ #[allow(unused_mut)]
fn warn(mut x: &mut Iter) {
takes_iter(&mut x)
}
@@ -298,3 +304,84 @@ mod meets_msrv {
let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
}
}
+
+#[allow(unused)]
+fn issue9383() {
+ // Should not lint because unions need explicit deref when accessing field
+ use std::mem::ManuallyDrop;
+
+ union Coral {
+ crab: ManuallyDrop<Vec<i32>>,
+ }
+
+ union Ocean {
+ coral: ManuallyDrop<Coral>,
+ }
+
+ let mut ocean = Ocean {
+ coral: ManuallyDrop::new(Coral {
+ crab: ManuallyDrop::new(vec![1, 2, 3]),
+ }),
+ };
+
+ unsafe {
+ ManuallyDrop::drop(&mut (&mut ocean.coral).crab);
+
+ (*ocean.coral).crab = ManuallyDrop::new(vec![4, 5, 6]);
+ ManuallyDrop::drop(&mut (*ocean.coral).crab);
+
+ ManuallyDrop::drop(&mut ocean.coral);
+ }
+}
+
+#[allow(dead_code)]
+fn closure_test() {
+ let env = "env".to_owned();
+ let arg = "arg".to_owned();
+ let f = |arg| {
+ let loc = "loc".to_owned();
+ let _ = std::fs::write("x", &env); // Don't lint. In environment
+ let _ = std::fs::write("x", &arg);
+ let _ = std::fs::write("x", &loc);
+ };
+ let _ = std::fs::write("x", &env); // Don't lint. Borrowed by `f`
+ f(arg);
+}
+
+#[allow(dead_code)]
+mod significant_drop {
+ #[derive(Debug)]
+ struct X;
+
+ #[derive(Debug)]
+ struct Y;
+
+ impl Drop for Y {
+ fn drop(&mut self) {}
+ }
+
+ fn foo(x: X, y: Y) {
+ debug(&x);
+ debug(&y); // Don't lint. Has significant drop
+ }
+
+ fn debug(_: impl std::fmt::Debug) {}
+}
+
+#[allow(dead_code)]
+mod used_exactly_once {
+ fn foo(x: String) {
+ use_x(&x);
+ }
+ fn use_x(_: impl AsRef<str>) {}
+}
+
+#[allow(dead_code)]
+mod used_more_than_once {
+ fn foo(x: String) {
+ use_x(&x);
+ use_x_again(&x);
+ }
+ fn use_x(_: impl AsRef<str>) {}
+ fn use_x_again(_: impl AsRef<str>) {}
+}
diff --git a/src/tools/clippy/tests/ui/needless_borrow.stderr b/src/tools/clippy/tests/ui/needless_borrow.stderr
index 5af68706d..8b593268b 100644
--- a/src/tools/clippy/tests/ui/needless_borrow.stderr
+++ b/src/tools/clippy/tests/ui/needless_borrow.stderr
@@ -1,5 +1,5 @@
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:11:15
+ --> $DIR/needless_borrow.rs:15:15
|
LL | let _ = x(&&a); // warn
| ^^^ help: change this to: `&a`
@@ -7,172 +7,208 @@ LL | let _ = x(&&a); // warn
= note: `-D clippy::needless-borrow` implied by `-D warnings`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:15:13
+ --> $DIR/needless_borrow.rs:19:13
|
LL | mut_ref(&mut &mut b); // warn
| ^^^^^^^^^^^ help: change this to: `&mut b`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:27:13
+ --> $DIR/needless_borrow.rs:31:13
|
LL | &&a
| ^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:29:15
+ --> $DIR/needless_borrow.rs:33:15
|
LL | 46 => &&a,
| ^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:35:27
+ --> $DIR/needless_borrow.rs:39:27
|
LL | break &ref_a;
| ^^^^^^ help: change this to: `ref_a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:42:15
+ --> $DIR/needless_borrow.rs:46:15
|
LL | let _ = x(&&&a);
| ^^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:43:15
+ --> $DIR/needless_borrow.rs:47:15
|
LL | let _ = x(&mut &&a);
| ^^^^^^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:44:15
+ --> $DIR/needless_borrow.rs:48:15
|
LL | let _ = x(&&&mut b);
| ^^^^^^^^ help: change this to: `&mut b`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:45:15
+ --> $DIR/needless_borrow.rs:49:15
|
LL | let _ = x(&&ref_a);
| ^^^^^^^ help: change this to: `ref_a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:48:11
+ --> $DIR/needless_borrow.rs:52:11
|
LL | x(&b);
| ^^ help: change this to: `b`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:55:13
+ --> $DIR/needless_borrow.rs:59:13
|
LL | mut_ref(&mut x);
| ^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:56:13
+ --> $DIR/needless_borrow.rs:60:13
|
LL | mut_ref(&mut &mut x);
| ^^^^^^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:57:23
+ --> $DIR/needless_borrow.rs:61:23
|
LL | let y: &mut i32 = &mut x;
| ^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:58:23
+ --> $DIR/needless_borrow.rs:62:23
|
LL | let y: &mut i32 = &mut &mut x;
| ^^^^^^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:67:14
+ --> $DIR/needless_borrow.rs:71:14
|
LL | 0 => &mut x,
| ^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:73:14
+ --> $DIR/needless_borrow.rs:77:14
|
LL | 0 => &mut x,
| ^^^^^^ help: change this to: `x`
error: this expression borrows a value the compiler would automatically borrow
- --> $DIR/needless_borrow.rs:85:13
+ --> $DIR/needless_borrow.rs:89:13
|
LL | let _ = (&x).0;
| ^^^^ help: change this to: `x`
error: this expression borrows a value the compiler would automatically borrow
- --> $DIR/needless_borrow.rs:87:22
+ --> $DIR/needless_borrow.rs:91:22
|
LL | let _ = unsafe { (&*x).0 };
| ^^^^^ help: change this to: `(*x)`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:97:5
+ --> $DIR/needless_borrow.rs:101:5
|
LL | (&&()).foo();
| ^^^^^^ help: change this to: `(&())`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:106:5
+ --> $DIR/needless_borrow.rs:110:5
|
LL | (&&5).foo();
| ^^^^^ help: change this to: `(&5)`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:131:51
+ --> $DIR/needless_borrow.rs:135:51
|
LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
| ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:132:44
+ --> $DIR/needless_borrow.rs:136:44
|
LL | let _ = std::path::Path::new(".").join(&&".");
| ^^^^^ help: change this to: `"."`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:133:23
+ --> $DIR/needless_borrow.rs:137:23
|
LL | deref_target_is_x(&X);
| ^^ help: change this to: `X`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:134:26
+ --> $DIR/needless_borrow.rs:138:26
|
LL | multiple_constraints(&[[""]]);
| ^^^^^^^ help: change this to: `[[""]]`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:135:45
+ --> $DIR/needless_borrow.rs:139:45
|
LL | multiple_constraints_normalizes_to_same(&X, X);
| ^^ help: change this to: `X`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:136:32
+ --> $DIR/needless_borrow.rs:140:32
|
LL | let _ = Some("").unwrap_or(&"");
| ^^^ help: change this to: `""`
+error: the borrowed expression implements the required traits
+ --> $DIR/needless_borrow.rs:141:33
+ |
+LL | let _ = std::fs::write("x", &"".to_string());
+ | ^^^^^^^^^^^^^^^ help: change this to: `"".to_string()`
+
error: this expression borrows a value the compiler would automatically borrow
- --> $DIR/needless_borrow.rs:187:13
+ --> $DIR/needless_borrow.rs:192:13
|
LL | (&self.f)()
| ^^^^^^^^^ help: change this to: `(self.f)`
error: this expression borrows a value the compiler would automatically borrow
- --> $DIR/needless_borrow.rs:196:13
+ --> $DIR/needless_borrow.rs:201:13
|
LL | (&mut self.f)()
| ^^^^^^^^^^^^^ help: change this to: `(self.f)`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:298:55
+ --> $DIR/needless_borrow.rs:286:20
+ |
+LL | takes_iter(&mut x)
+ | ^^^^^^ help: change this to: `x`
+
+error: the borrowed expression implements the required traits
+ --> $DIR/needless_borrow.rs:304:55
|
LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
| ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]`
-error: aborting due to 29 previous errors
+error: the borrowed expression implements the required traits
+ --> $DIR/needless_borrow.rs:344:37
+ |
+LL | let _ = std::fs::write("x", &arg);
+ | ^^^^ help: change this to: `arg`
+
+error: the borrowed expression implements the required traits
+ --> $DIR/needless_borrow.rs:345:37
+ |
+LL | let _ = std::fs::write("x", &loc);
+ | ^^^^ help: change this to: `loc`
+
+error: the borrowed expression implements the required traits
+ --> $DIR/needless_borrow.rs:364:15
+ |
+LL | debug(&x);
+ | ^^ help: change this to: `x`
+
+error: the borrowed expression implements the required traits
+ --> $DIR/needless_borrow.rs:374:15
+ |
+LL | use_x(&x);
+ | ^^ help: change this to: `x`
+
+error: aborting due to 35 previous errors
diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed b/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed
index a0937a2c5..bcb4eb2dd 100644
--- a/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed
+++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.fixed
@@ -1,17 +1,38 @@
// run-rustfix
-#[warn(clippy::needless_borrowed_reference)]
-#[allow(unused_variables)]
-fn main() {
+#![warn(clippy::needless_borrowed_reference)]
+#![allow(unused, clippy::needless_borrow)]
+
+fn main() {}
+
+fn should_lint(array: [u8; 4], slice: &[u8], slice_of_refs: &[&u8], vec: Vec<u8>) {
let mut v = Vec::<String>::new();
let _ = v.iter_mut().filter(|a| a.is_empty());
- // ^ should be linted
let var = 3;
let thingy = Some(&var);
- if let Some(&ref v) = thingy {
- // ^ should be linted
- }
+ if let Some(v) = thingy {}
+
+ if let &[a, ref b] = slice_of_refs {}
+
+ let [a, ..] = &array;
+ let [a, b, ..] = &array;
+
+ if let [a, b] = slice {}
+ if let [a, b] = &vec[..] {}
+
+ if let [a, b, ..] = slice {}
+ if let [a, .., b] = slice {}
+ if let [.., a, b] = slice {}
+}
+
+fn should_not_lint(array: [u8; 4], slice: &[u8], slice_of_refs: &[&u8], vec: Vec<u8>) {
+ if let [ref a] = slice {}
+ if let &[ref a, b] = slice {}
+ if let &[ref a, .., b] = slice {}
+
+ // must not be removed as variables must be bound consistently across | patterns
+ if let (&[ref a], _) | ([], ref a) = (slice_of_refs, &1u8) {}
let mut var2 = 5;
let thingy2 = Some(&mut var2);
@@ -28,17 +49,15 @@ fn main() {
}
}
-#[allow(dead_code)]
enum Animal {
Cat(u64),
Dog(u64),
}
-#[allow(unused_variables)]
-#[allow(dead_code)]
fn foo(a: &Animal, b: &Animal) {
match (a, b) {
- (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (), // lifetime mismatch error if there is no '&ref'
+ // lifetime mismatch error if there is no '&ref' before `feature(nll)` stabilization in 1.63
+ (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (),
// ^ and ^ should **not** be linted
(&Animal::Dog(ref a), &Animal::Dog(_)) => (), // ^ should **not** be linted
}
diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.rs b/src/tools/clippy/tests/ui/needless_borrowed_ref.rs
index 500ac448f..f6de1a6d8 100644
--- a/src/tools/clippy/tests/ui/needless_borrowed_ref.rs
+++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.rs
@@ -1,17 +1,38 @@
// run-rustfix
-#[warn(clippy::needless_borrowed_reference)]
-#[allow(unused_variables)]
-fn main() {
+#![warn(clippy::needless_borrowed_reference)]
+#![allow(unused, clippy::needless_borrow)]
+
+fn main() {}
+
+fn should_lint(array: [u8; 4], slice: &[u8], slice_of_refs: &[&u8], vec: Vec<u8>) {
let mut v = Vec::<String>::new();
let _ = v.iter_mut().filter(|&ref a| a.is_empty());
- // ^ should be linted
let var = 3;
let thingy = Some(&var);
- if let Some(&ref v) = thingy {
- // ^ should be linted
- }
+ if let Some(&ref v) = thingy {}
+
+ if let &[&ref a, ref b] = slice_of_refs {}
+
+ let &[ref a, ..] = &array;
+ let &[ref a, ref b, ..] = &array;
+
+ if let &[ref a, ref b] = slice {}
+ if let &[ref a, ref b] = &vec[..] {}
+
+ if let &[ref a, ref b, ..] = slice {}
+ if let &[ref a, .., ref b] = slice {}
+ if let &[.., ref a, ref b] = slice {}
+}
+
+fn should_not_lint(array: [u8; 4], slice: &[u8], slice_of_refs: &[&u8], vec: Vec<u8>) {
+ if let [ref a] = slice {}
+ if let &[ref a, b] = slice {}
+ if let &[ref a, .., b] = slice {}
+
+ // must not be removed as variables must be bound consistently across | patterns
+ if let (&[ref a], _) | ([], ref a) = (slice_of_refs, &1u8) {}
let mut var2 = 5;
let thingy2 = Some(&mut var2);
@@ -28,17 +49,15 @@ fn main() {
}
}
-#[allow(dead_code)]
enum Animal {
Cat(u64),
Dog(u64),
}
-#[allow(unused_variables)]
-#[allow(dead_code)]
fn foo(a: &Animal, b: &Animal) {
match (a, b) {
- (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (), // lifetime mismatch error if there is no '&ref'
+ // lifetime mismatch error if there is no '&ref' before `feature(nll)` stabilization in 1.63
+ (&Animal::Cat(v), &ref k) | (&ref k, &Animal::Cat(v)) => (),
// ^ and ^ should **not** be linted
(&Animal::Dog(ref a), &Animal::Dog(_)) => (), // ^ should **not** be linted
}
diff --git a/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr b/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr
index 0a5cfb3db..7453542e6 100644
--- a/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr
+++ b/src/tools/clippy/tests/ui/needless_borrowed_ref.stderr
@@ -1,10 +1,123 @@
-error: this pattern takes a reference on something that is being de-referenced
- --> $DIR/needless_borrowed_ref.rs:7:34
+error: this pattern takes a reference on something that is being dereferenced
+ --> $DIR/needless_borrowed_ref.rs:10:34
|
LL | let _ = v.iter_mut().filter(|&ref a| a.is_empty());
- | ^^^^^^ help: try removing the `&ref` part and just keep: `a`
+ | ^^^^^^
|
= note: `-D clippy::needless-borrowed-reference` implied by `-D warnings`
+help: try removing the `&ref` part
+ |
+LL - let _ = v.iter_mut().filter(|&ref a| a.is_empty());
+LL + let _ = v.iter_mut().filter(|a| a.is_empty());
+ |
+
+error: this pattern takes a reference on something that is being dereferenced
+ --> $DIR/needless_borrowed_ref.rs:14:17
+ |
+LL | if let Some(&ref v) = thingy {}
+ | ^^^^^^
+ |
+help: try removing the `&ref` part
+ |
+LL - if let Some(&ref v) = thingy {}
+LL + if let Some(v) = thingy {}
+ |
+
+error: this pattern takes a reference on something that is being dereferenced
+ --> $DIR/needless_borrowed_ref.rs:16:14
+ |
+LL | if let &[&ref a, ref b] = slice_of_refs {}
+ | ^^^^^^
+ |
+help: try removing the `&ref` part
+ |
+LL - if let &[&ref a, ref b] = slice_of_refs {}
+LL + if let &[a, ref b] = slice_of_refs {}
+ |
+
+error: dereferencing a slice pattern where every element takes a reference
+ --> $DIR/needless_borrowed_ref.rs:18:9
+ |
+LL | let &[ref a, ..] = &array;
+ | ^^^^^^^^^^^^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL - let &[ref a, ..] = &array;
+LL + let [a, ..] = &array;
+ |
+
+error: dereferencing a slice pattern where every element takes a reference
+ --> $DIR/needless_borrowed_ref.rs:19:9
+ |
+LL | let &[ref a, ref b, ..] = &array;
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL - let &[ref a, ref b, ..] = &array;
+LL + let [a, b, ..] = &array;
+ |
+
+error: dereferencing a slice pattern where every element takes a reference
+ --> $DIR/needless_borrowed_ref.rs:21:12
+ |
+LL | if let &[ref a, ref b] = slice {}
+ | ^^^^^^^^^^^^^^^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL - if let &[ref a, ref b] = slice {}
+LL + if let [a, b] = slice {}
+ |
+
+error: dereferencing a slice pattern where every element takes a reference
+ --> $DIR/needless_borrowed_ref.rs:22:12
+ |
+LL | if let &[ref a, ref b] = &vec[..] {}
+ | ^^^^^^^^^^^^^^^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL - if let &[ref a, ref b] = &vec[..] {}
+LL + if let [a, b] = &vec[..] {}
+ |
+
+error: dereferencing a slice pattern where every element takes a reference
+ --> $DIR/needless_borrowed_ref.rs:24:12
+ |
+LL | if let &[ref a, ref b, ..] = slice {}
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL - if let &[ref a, ref b, ..] = slice {}
+LL + if let [a, b, ..] = slice {}
+ |
+
+error: dereferencing a slice pattern where every element takes a reference
+ --> $DIR/needless_borrowed_ref.rs:25:12
+ |
+LL | if let &[ref a, .., ref b] = slice {}
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL - if let &[ref a, .., ref b] = slice {}
+LL + if let [a, .., b] = slice {}
+ |
+
+error: dereferencing a slice pattern where every element takes a reference
+ --> $DIR/needless_borrowed_ref.rs:26:12
+ |
+LL | if let &[.., ref a, ref b] = slice {}
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+help: try removing the `&` and `ref` parts
+ |
+LL - if let &[.., ref a, ref b] = slice {}
+LL + if let [.., a, b] = slice {}
+ |
-error: aborting due to previous error
+error: aborting due to 10 previous errors
diff --git a/src/tools/clippy/tests/ui/needless_collect_indirect.rs b/src/tools/clippy/tests/ui/needless_collect_indirect.rs
index 12a9ace1e..6d213b46c 100644
--- a/src/tools/clippy/tests/ui/needless_collect_indirect.rs
+++ b/src/tools/clippy/tests/ui/needless_collect_indirect.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::uninlined_format_args)]
+
use std::collections::{BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
fn main() {
diff --git a/src/tools/clippy/tests/ui/needless_collect_indirect.stderr b/src/tools/clippy/tests/ui/needless_collect_indirect.stderr
index 9f0880cc6..99e1b91d8 100644
--- a/src/tools/clippy/tests/ui/needless_collect_indirect.stderr
+++ b/src/tools/clippy/tests/ui/needless_collect_indirect.stderr
@@ -1,5 +1,5 @@
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:5:39
+ --> $DIR/needless_collect_indirect.rs:7:39
|
LL | let indirect_iter = sample.iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -14,7 +14,7 @@ LL ~ sample.iter().map(|x| (x, x + 1)).collect::<HashMap<_, _>>();
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:7:38
+ --> $DIR/needless_collect_indirect.rs:9:38
|
LL | let indirect_len = sample.iter().collect::<VecDeque<_>>();
| ^^^^^^^
@@ -28,7 +28,7 @@ LL ~ sample.iter().count();
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:9:40
+ --> $DIR/needless_collect_indirect.rs:11:40
|
LL | let indirect_empty = sample.iter().collect::<VecDeque<_>>();
| ^^^^^^^
@@ -42,7 +42,7 @@ LL ~ sample.iter().next().is_none();
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:11:43
+ --> $DIR/needless_collect_indirect.rs:13:43
|
LL | let indirect_contains = sample.iter().collect::<VecDeque<_>>();
| ^^^^^^^
@@ -56,7 +56,7 @@ LL ~ sample.iter().any(|x| x == &5);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:23:48
+ --> $DIR/needless_collect_indirect.rs:25:48
|
LL | let non_copy_contains = sample.into_iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -70,7 +70,7 @@ LL ~ sample.into_iter().any(|x| x == a);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:52:51
+ --> $DIR/needless_collect_indirect.rs:54:51
|
LL | let buffer: Vec<&str> = string.split('/').collect();
| ^^^^^^^
@@ -84,7 +84,7 @@ LL ~ string.split('/').count()
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:57:55
+ --> $DIR/needless_collect_indirect.rs:59:55
|
LL | let indirect_len: VecDeque<_> = sample.iter().collect();
| ^^^^^^^
@@ -98,7 +98,7 @@ LL ~ sample.iter().count()
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:62:57
+ --> $DIR/needless_collect_indirect.rs:64:57
|
LL | let indirect_len: LinkedList<_> = sample.iter().collect();
| ^^^^^^^
@@ -112,7 +112,7 @@ LL ~ sample.iter().count()
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:67:57
+ --> $DIR/needless_collect_indirect.rs:69:57
|
LL | let indirect_len: BinaryHeap<_> = sample.iter().collect();
| ^^^^^^^
@@ -126,7 +126,7 @@ LL ~ sample.iter().count()
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:127:59
+ --> $DIR/needless_collect_indirect.rs:129:59
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
@@ -143,7 +143,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == i);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:152:59
+ --> $DIR/needless_collect_indirect.rs:154:59
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
@@ -160,7 +160,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:181:63
+ --> $DIR/needless_collect_indirect.rs:183:63
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
@@ -177,7 +177,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:217:59
+ --> $DIR/needless_collect_indirect.rs:219:59
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
@@ -195,7 +195,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n);
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:242:26
+ --> $DIR/needless_collect_indirect.rs:244:26
|
LL | let w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -211,7 +211,7 @@ LL ~ for _ in 0..v.iter().count() {
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:264:30
+ --> $DIR/needless_collect_indirect.rs:266:30
|
LL | let mut w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
@@ -227,7 +227,7 @@ LL ~ while 1 == v.iter().count() {
|
error: avoid using `collect()` when not needed
- --> $DIR/needless_collect_indirect.rs:286:30
+ --> $DIR/needless_collect_indirect.rs:288:30
|
LL | let mut w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
diff --git a/src/tools/clippy/tests/ui/needless_continue.rs b/src/tools/clippy/tests/ui/needless_continue.rs
index f105d3d65..c891c9de3 100644
--- a/src/tools/clippy/tests/ui/needless_continue.rs
+++ b/src/tools/clippy/tests/ui/needless_continue.rs
@@ -1,4 +1,5 @@
#![warn(clippy::needless_continue)]
+#![allow(clippy::uninlined_format_args)]
macro_rules! zero {
($x:expr) => {
diff --git a/src/tools/clippy/tests/ui/needless_continue.stderr b/src/tools/clippy/tests/ui/needless_continue.stderr
index b8657c74c..d99989b54 100644
--- a/src/tools/clippy/tests/ui/needless_continue.stderr
+++ b/src/tools/clippy/tests/ui/needless_continue.stderr
@@ -1,5 +1,5 @@
error: this `else` block is redundant
- --> $DIR/needless_continue.rs:29:16
+ --> $DIR/needless_continue.rs:30:16
|
LL | } else {
| ________________^
@@ -7,7 +7,6 @@ LL | | continue;
LL | | }
| |_________^
|
- = note: `-D clippy::needless-continue` implied by `-D warnings`
= help: consider dropping the `else` clause and merging the code that follows (in the loop) with the `if` block
if i % 2 == 0 && i % 3 == 0 {
println!("{}", i);
@@ -33,9 +32,10 @@ LL | | }
}
println!("bleh");
}
+ = note: `-D clippy::needless-continue` implied by `-D warnings`
error: there is no need for an explicit `else` block for this `if` expression
- --> $DIR/needless_continue.rs:44:9
+ --> $DIR/needless_continue.rs:45:9
|
LL | / if (zero!(i % 2) || nonzero!(i % 5)) && i % 3 != 0 {
LL | | continue;
@@ -55,7 +55,7 @@ LL | | }
}
error: this `continue` expression is redundant
- --> $DIR/needless_continue.rs:57:9
+ --> $DIR/needless_continue.rs:58:9
|
LL | continue; // should lint here
| ^^^^^^^^^
@@ -63,7 +63,7 @@ LL | continue; // should lint here
= help: consider dropping the `continue` expression
error: this `continue` expression is redundant
- --> $DIR/needless_continue.rs:64:9
+ --> $DIR/needless_continue.rs:65:9
|
LL | continue; // should lint here
| ^^^^^^^^^
@@ -71,7 +71,7 @@ LL | continue; // should lint here
= help: consider dropping the `continue` expression
error: this `continue` expression is redundant
- --> $DIR/needless_continue.rs:71:9
+ --> $DIR/needless_continue.rs:72:9
|
LL | continue // should lint here
| ^^^^^^^^
@@ -79,7 +79,7 @@ LL | continue // should lint here
= help: consider dropping the `continue` expression
error: this `continue` expression is redundant
- --> $DIR/needless_continue.rs:79:9
+ --> $DIR/needless_continue.rs:80:9
|
LL | continue // should lint here
| ^^^^^^^^
@@ -87,7 +87,7 @@ LL | continue // should lint here
= help: consider dropping the `continue` expression
error: this `else` block is redundant
- --> $DIR/needless_continue.rs:129:24
+ --> $DIR/needless_continue.rs:130:24
|
LL | } else {
| ________________________^
@@ -110,7 +110,7 @@ LL | | }
}
error: there is no need for an explicit `else` block for this `if` expression
- --> $DIR/needless_continue.rs:135:17
+ --> $DIR/needless_continue.rs:136:17
|
LL | / if condition() {
LL | | continue; // should lint here
diff --git a/src/tools/clippy/tests/ui/needless_for_each_fixable.fixed b/src/tools/clippy/tests/ui/needless_for_each_fixable.fixed
index c1685f7b6..09e671b88 100644
--- a/src/tools/clippy/tests/ui/needless_for_each_fixable.fixed
+++ b/src/tools/clippy/tests/ui/needless_for_each_fixable.fixed
@@ -1,10 +1,11 @@
// run-rustfix
#![warn(clippy::needless_for_each)]
+#![allow(unused)]
#![allow(
- unused,
- clippy::needless_return,
+ clippy::let_unit_value,
clippy::match_single_binding,
- clippy::let_unit_value
+ clippy::needless_return,
+ clippy::uninlined_format_args
)]
use std::collections::HashMap;
diff --git a/src/tools/clippy/tests/ui/needless_for_each_fixable.rs b/src/tools/clippy/tests/ui/needless_for_each_fixable.rs
index ad17b0956..abb4045b9 100644
--- a/src/tools/clippy/tests/ui/needless_for_each_fixable.rs
+++ b/src/tools/clippy/tests/ui/needless_for_each_fixable.rs
@@ -1,10 +1,11 @@
// run-rustfix
#![warn(clippy::needless_for_each)]
+#![allow(unused)]
#![allow(
- unused,
- clippy::needless_return,
+ clippy::let_unit_value,
clippy::match_single_binding,
- clippy::let_unit_value
+ clippy::needless_return,
+ clippy::uninlined_format_args
)]
use std::collections::HashMap;
diff --git a/src/tools/clippy/tests/ui/needless_for_each_fixable.stderr b/src/tools/clippy/tests/ui/needless_for_each_fixable.stderr
index 08e995851..aebb762cc 100644
--- a/src/tools/clippy/tests/ui/needless_for_each_fixable.stderr
+++ b/src/tools/clippy/tests/ui/needless_for_each_fixable.stderr
@@ -1,5 +1,5 @@
error: needless use of `for_each`
- --> $DIR/needless_for_each_fixable.rs:15:5
+ --> $DIR/needless_for_each_fixable.rs:16:5
|
LL | / v.iter().for_each(|elem| {
LL | | acc += elem;
@@ -15,7 +15,7 @@ LL + }
|
error: needless use of `for_each`
- --> $DIR/needless_for_each_fixable.rs:18:5
+ --> $DIR/needless_for_each_fixable.rs:19:5
|
LL | / v.into_iter().for_each(|elem| {
LL | | acc += elem;
@@ -30,7 +30,7 @@ LL + }
|
error: needless use of `for_each`
- --> $DIR/needless_for_each_fixable.rs:22:5
+ --> $DIR/needless_for_each_fixable.rs:23:5
|
LL | / [1, 2, 3].iter().for_each(|elem| {
LL | | acc += elem;
@@ -45,7 +45,7 @@ LL + }
|
error: needless use of `for_each`
- --> $DIR/needless_for_each_fixable.rs:27:5
+ --> $DIR/needless_for_each_fixable.rs:28:5
|
LL | / hash_map.iter().for_each(|(k, v)| {
LL | | acc += k + v;
@@ -60,7 +60,7 @@ LL + }
|
error: needless use of `for_each`
- --> $DIR/needless_for_each_fixable.rs:30:5
+ --> $DIR/needless_for_each_fixable.rs:31:5
|
LL | / hash_map.iter_mut().for_each(|(k, v)| {
LL | | acc += *k + *v;
@@ -75,7 +75,7 @@ LL + }
|
error: needless use of `for_each`
- --> $DIR/needless_for_each_fixable.rs:33:5
+ --> $DIR/needless_for_each_fixable.rs:34:5
|
LL | / hash_map.keys().for_each(|k| {
LL | | acc += k;
@@ -90,7 +90,7 @@ LL + }
|
error: needless use of `for_each`
- --> $DIR/needless_for_each_fixable.rs:36:5
+ --> $DIR/needless_for_each_fixable.rs:37:5
|
LL | / hash_map.values().for_each(|v| {
LL | | acc += v;
@@ -105,7 +105,7 @@ LL + }
|
error: needless use of `for_each`
- --> $DIR/needless_for_each_fixable.rs:43:5
+ --> $DIR/needless_for_each_fixable.rs:44:5
|
LL | / my_vec().iter().for_each(|elem| {
LL | | acc += elem;
diff --git a/src/tools/clippy/tests/ui/needless_for_each_unfixable.rs b/src/tools/clippy/tests/ui/needless_for_each_unfixable.rs
index d765d7dab..282c72881 100644
--- a/src/tools/clippy/tests/ui/needless_for_each_unfixable.rs
+++ b/src/tools/clippy/tests/ui/needless_for_each_unfixable.rs
@@ -1,5 +1,5 @@
#![warn(clippy::needless_for_each)]
-#![allow(clippy::needless_return)]
+#![allow(clippy::needless_return, clippy::uninlined_format_args)]
fn main() {
let v: Vec<i32> = Vec::new();
diff --git a/src/tools/clippy/tests/ui/needless_late_init.fixed b/src/tools/clippy/tests/ui/needless_late_init.fixed
index fee8e3030..17f2227ba 100644
--- a/src/tools/clippy/tests/ui/needless_late_init.fixed
+++ b/src/tools/clippy/tests/ui/needless_late_init.fixed
@@ -1,12 +1,13 @@
// run-rustfix
#![feature(let_chains)]
+#![allow(unused)]
#![allow(
- unused,
clippy::assign_op_pattern,
clippy::blocks_in_if_conditions,
clippy::let_and_return,
clippy::let_unit_value,
- clippy::nonminimal_bool
+ clippy::nonminimal_bool,
+ clippy::uninlined_format_args
)]
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
diff --git a/src/tools/clippy/tests/ui/needless_late_init.rs b/src/tools/clippy/tests/ui/needless_late_init.rs
index 402d9f9ef..d84457a29 100644
--- a/src/tools/clippy/tests/ui/needless_late_init.rs
+++ b/src/tools/clippy/tests/ui/needless_late_init.rs
@@ -1,12 +1,13 @@
// run-rustfix
#![feature(let_chains)]
+#![allow(unused)]
#![allow(
- unused,
clippy::assign_op_pattern,
clippy::blocks_in_if_conditions,
clippy::let_and_return,
clippy::let_unit_value,
- clippy::nonminimal_bool
+ clippy::nonminimal_bool,
+ clippy::uninlined_format_args
)]
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
diff --git a/src/tools/clippy/tests/ui/needless_late_init.stderr b/src/tools/clippy/tests/ui/needless_late_init.stderr
index 313cdbbeb..0a256fb4a 100644
--- a/src/tools/clippy/tests/ui/needless_late_init.stderr
+++ b/src/tools/clippy/tests/ui/needless_late_init.stderr
@@ -1,5 +1,5 @@
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:23:5
+ --> $DIR/needless_late_init.rs:24:5
|
LL | let a;
| ^^^^^^ created here
@@ -13,7 +13,7 @@ LL | let a = "zero";
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:26:5
+ --> $DIR/needless_late_init.rs:27:5
|
LL | let b;
| ^^^^^^ created here
@@ -27,7 +27,7 @@ LL | let b = 1;
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:27:5
+ --> $DIR/needless_late_init.rs:28:5
|
LL | let c;
| ^^^^^^ created here
@@ -41,7 +41,7 @@ LL | let c = 2;
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:31:5
+ --> $DIR/needless_late_init.rs:32:5
|
LL | let d: usize;
| ^^^^^^^^^^^^^ created here
@@ -54,7 +54,7 @@ LL | let d: usize = 1;
| ~~~~~~~~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:34:5
+ --> $DIR/needless_late_init.rs:35:5
|
LL | let e;
| ^^^^^^ created here
@@ -67,7 +67,7 @@ LL | let e = format!("{}", d);
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:39:5
+ --> $DIR/needless_late_init.rs:40:5
|
LL | let a;
| ^^^^^^
@@ -88,7 +88,7 @@ LL | };
| +
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:48:5
+ --> $DIR/needless_late_init.rs:49:5
|
LL | let b;
| ^^^^^^
@@ -109,7 +109,7 @@ LL | };
| +
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:55:5
+ --> $DIR/needless_late_init.rs:56:5
|
LL | let d;
| ^^^^^^
@@ -130,7 +130,7 @@ LL | };
| +
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:63:5
+ --> $DIR/needless_late_init.rs:64:5
|
LL | let e;
| ^^^^^^
@@ -151,7 +151,7 @@ LL | };
| +
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:70:5
+ --> $DIR/needless_late_init.rs:71:5
|
LL | let f;
| ^^^^^^
@@ -167,7 +167,7 @@ LL + 1 => "three",
|
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:76:5
+ --> $DIR/needless_late_init.rs:77:5
|
LL | let g: usize;
| ^^^^^^^^^^^^^
@@ -187,7 +187,7 @@ LL | };
| +
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:84:5
+ --> $DIR/needless_late_init.rs:85:5
|
LL | let x;
| ^^^^^^ created here
@@ -201,7 +201,7 @@ LL | let x = 1;
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:88:5
+ --> $DIR/needless_late_init.rs:89:5
|
LL | let x;
| ^^^^^^ created here
@@ -215,7 +215,7 @@ LL | let x = SignificantDrop;
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:92:5
+ --> $DIR/needless_late_init.rs:93:5
|
LL | let x;
| ^^^^^^ created here
@@ -229,7 +229,7 @@ LL | let x = SignificantDrop;
| ~~~~~
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:111:5
+ --> $DIR/needless_late_init.rs:112:5
|
LL | let a;
| ^^^^^^
@@ -250,7 +250,7 @@ LL | };
| +
error: unneeded late initialization
- --> $DIR/needless_late_init.rs:128:5
+ --> $DIR/needless_late_init.rs:129:5
|
LL | let a;
| ^^^^^^
diff --git a/src/tools/clippy/tests/ui/needless_pass_by_value.rs b/src/tools/clippy/tests/ui/needless_pass_by_value.rs
index 5a35b100a..d79ad86b1 100644
--- a/src/tools/clippy/tests/ui/needless_pass_by_value.rs
+++ b/src/tools/clippy/tests/ui/needless_pass_by_value.rs
@@ -1,10 +1,11 @@
#![warn(clippy::needless_pass_by_value)]
+#![allow(dead_code)]
#![allow(
- dead_code,
- clippy::single_match,
- clippy::redundant_pattern_matching,
clippy::option_option,
- clippy::redundant_clone
+ clippy::redundant_clone,
+ clippy::redundant_pattern_matching,
+ clippy::single_match,
+ clippy::uninlined_format_args
)]
use std::borrow::Borrow;
diff --git a/src/tools/clippy/tests/ui/needless_pass_by_value.stderr b/src/tools/clippy/tests/ui/needless_pass_by_value.stderr
index 38f33c53f..0e660a77d 100644
--- a/src/tools/clippy/tests/ui/needless_pass_by_value.stderr
+++ b/src/tools/clippy/tests/ui/needless_pass_by_value.stderr
@@ -1,5 +1,5 @@
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:17:23
+ --> $DIR/needless_pass_by_value.rs:18:23
|
LL | fn foo<T: Default>(v: Vec<T>, w: Vec<T>, mut x: Vec<T>, y: Vec<T>) -> Vec<T> {
| ^^^^^^ help: consider changing the type to: `&[T]`
@@ -7,55 +7,55 @@ LL | fn foo<T: Default>(v: Vec<T>, w: Vec<T>, mut x: Vec<T>, y: Vec<T>) -> Vec<T
= note: `-D clippy::needless-pass-by-value` implied by `-D warnings`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:31:11
+ --> $DIR/needless_pass_by_value.rs:32:11
|
LL | fn bar(x: String, y: Wrapper) {
| ^^^^^^ help: consider changing the type to: `&str`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:31:22
+ --> $DIR/needless_pass_by_value.rs:32:22
|
LL | fn bar(x: String, y: Wrapper) {
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:37:71
+ --> $DIR/needless_pass_by_value.rs:38:71
|
LL | fn test_borrow_trait<T: Borrow<str>, U: AsRef<str>, V>(t: T, u: U, v: V) {
| ^ help: consider taking a reference instead: `&V`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:49:18
+ --> $DIR/needless_pass_by_value.rs:50:18
|
LL | fn test_match(x: Option<Option<String>>, y: Option<Option<String>>) {
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&Option<Option<String>>`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:62:24
+ --> $DIR/needless_pass_by_value.rs:63:24
|
LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) {
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:62:36
+ --> $DIR/needless_pass_by_value.rs:63:36
|
LL | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) {
| ^^^^^^^ help: consider taking a reference instead: `&Wrapper`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:78:49
+ --> $DIR/needless_pass_by_value.rs:79:49
|
LL | fn test_blanket_ref<T: Foo, S: Serialize>(_foo: T, _serializable: S) {}
| ^ help: consider taking a reference instead: `&T`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:80:18
+ --> $DIR/needless_pass_by_value.rs:81:18
|
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
| ^^^^^^ help: consider taking a reference instead: `&String`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:80:29
+ --> $DIR/needless_pass_by_value.rs:81:29
|
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
| ^^^^^^
@@ -70,13 +70,13 @@ LL | let _ = t.to_string();
| ~~~~~~~~~~~~~
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:80:40
+ --> $DIR/needless_pass_by_value.rs:81:40
|
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
| ^^^^^^^^ help: consider taking a reference instead: `&Vec<i32>`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:80:53
+ --> $DIR/needless_pass_by_value.rs:81:53
|
LL | fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
| ^^^^^^^^
@@ -91,85 +91,85 @@ LL | let _ = v.to_owned();
| ~~~~~~~~~~~~
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:93:12
+ --> $DIR/needless_pass_by_value.rs:94:12
|
LL | s: String,
| ^^^^^^ help: consider changing the type to: `&str`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:94:12
+ --> $DIR/needless_pass_by_value.rs:95:12
|
LL | t: String,
| ^^^^^^ help: consider taking a reference instead: `&String`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:103:23
+ --> $DIR/needless_pass_by_value.rs:104:23
|
LL | fn baz(&self, _u: U, _s: Self) {}
| ^ help: consider taking a reference instead: `&U`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:103:30
+ --> $DIR/needless_pass_by_value.rs:104:30
|
LL | fn baz(&self, _u: U, _s: Self) {}
| ^^^^ help: consider taking a reference instead: `&Self`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:125:24
+ --> $DIR/needless_pass_by_value.rs:126:24
|
LL | fn bar_copy(x: u32, y: CopyWrapper) {
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
|
help: consider marking this type as `Copy`
- --> $DIR/needless_pass_by_value.rs:123:1
+ --> $DIR/needless_pass_by_value.rs:124:1
|
LL | struct CopyWrapper(u32);
| ^^^^^^^^^^^^^^^^^^
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:131:29
+ --> $DIR/needless_pass_by_value.rs:132:29
|
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
|
help: consider marking this type as `Copy`
- --> $DIR/needless_pass_by_value.rs:123:1
+ --> $DIR/needless_pass_by_value.rs:124:1
|
LL | struct CopyWrapper(u32);
| ^^^^^^^^^^^^^^^^^^
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:131:45
+ --> $DIR/needless_pass_by_value.rs:132:45
|
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
|
help: consider marking this type as `Copy`
- --> $DIR/needless_pass_by_value.rs:123:1
+ --> $DIR/needless_pass_by_value.rs:124:1
|
LL | struct CopyWrapper(u32);
| ^^^^^^^^^^^^^^^^^^
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:131:61
+ --> $DIR/needless_pass_by_value.rs:132:61
|
LL | fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
| ^^^^^^^^^^^ help: consider taking a reference instead: `&CopyWrapper`
|
help: consider marking this type as `Copy`
- --> $DIR/needless_pass_by_value.rs:123:1
+ --> $DIR/needless_pass_by_value.rs:124:1
|
LL | struct CopyWrapper(u32);
| ^^^^^^^^^^^^^^^^^^
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:143:40
+ --> $DIR/needless_pass_by_value.rs:144:40
|
LL | fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {}
| ^ help: consider taking a reference instead: `&S`
error: this argument is passed by value, but not consumed in the function body
- --> $DIR/needless_pass_by_value.rs:148:20
+ --> $DIR/needless_pass_by_value.rs:149:20
|
LL | fn more_fun(_item: impl Club<'static, i32>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead: `&impl Club<'static, i32>`
diff --git a/src/tools/clippy/tests/ui/needless_range_loop.rs b/src/tools/clippy/tests/ui/needless_range_loop.rs
index 3fce34367..921801138 100644
--- a/src/tools/clippy/tests/ui/needless_range_loop.rs
+++ b/src/tools/clippy/tests/ui/needless_range_loop.rs
@@ -1,4 +1,5 @@
#![warn(clippy::needless_range_loop)]
+#![allow(clippy::uninlined_format_args)]
static STATIC: [usize; 4] = [0, 1, 8, 16];
const CONST: [usize; 4] = [0, 1, 8, 16];
diff --git a/src/tools/clippy/tests/ui/needless_range_loop.stderr b/src/tools/clippy/tests/ui/needless_range_loop.stderr
index a86cc69df..b31544ec3 100644
--- a/src/tools/clippy/tests/ui/needless_range_loop.stderr
+++ b/src/tools/clippy/tests/ui/needless_range_loop.stderr
@@ -1,5 +1,5 @@
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:10:14
+ --> $DIR/needless_range_loop.rs:11:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
@@ -11,7 +11,7 @@ LL | for <item> in &vec {
| ~~~~~~ ~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:19:14
+ --> $DIR/needless_range_loop.rs:20:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | for <item> in &vec {
| ~~~~~~ ~~~~
error: the loop variable `j` is only used to index `STATIC`
- --> $DIR/needless_range_loop.rs:24:14
+ --> $DIR/needless_range_loop.rs:25:14
|
LL | for j in 0..4 {
| ^^^^
@@ -33,7 +33,7 @@ LL | for <item> in &STATIC {
| ~~~~~~ ~~~~~~~
error: the loop variable `j` is only used to index `CONST`
- --> $DIR/needless_range_loop.rs:28:14
+ --> $DIR/needless_range_loop.rs:29:14
|
LL | for j in 0..4 {
| ^^^^
@@ -44,7 +44,7 @@ LL | for <item> in &CONST {
| ~~~~~~ ~~~~~~
error: the loop variable `i` is used to index `vec`
- --> $DIR/needless_range_loop.rs:32:14
+ --> $DIR/needless_range_loop.rs:33:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
@@ -55,7 +55,7 @@ LL | for (i, <item>) in vec.iter().enumerate() {
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec2`
- --> $DIR/needless_range_loop.rs:40:14
+ --> $DIR/needless_range_loop.rs:41:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
@@ -66,7 +66,7 @@ LL | for <item> in vec2.iter().take(vec.len()) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:44:14
+ --> $DIR/needless_range_loop.rs:45:14
|
LL | for i in 5..vec.len() {
| ^^^^^^^^^^^^
@@ -77,7 +77,7 @@ LL | for <item> in vec.iter().skip(5) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:48:14
+ --> $DIR/needless_range_loop.rs:49:14
|
LL | for i in 0..MAX_LEN {
| ^^^^^^^^^^
@@ -88,7 +88,7 @@ LL | for <item> in vec.iter().take(MAX_LEN) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:52:14
+ --> $DIR/needless_range_loop.rs:53:14
|
LL | for i in 0..=MAX_LEN {
| ^^^^^^^^^^^
@@ -99,7 +99,7 @@ LL | for <item> in vec.iter().take(MAX_LEN + 1) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:56:14
+ --> $DIR/needless_range_loop.rs:57:14
|
LL | for i in 5..10 {
| ^^^^^
@@ -110,7 +110,7 @@ LL | for <item> in vec.iter().take(10).skip(5) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:60:14
+ --> $DIR/needless_range_loop.rs:61:14
|
LL | for i in 5..=10 {
| ^^^^^^
@@ -121,7 +121,7 @@ LL | for <item> in vec.iter().take(10 + 1).skip(5) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is used to index `vec`
- --> $DIR/needless_range_loop.rs:64:14
+ --> $DIR/needless_range_loop.rs:65:14
|
LL | for i in 5..vec.len() {
| ^^^^^^^^^^^^
@@ -132,7 +132,7 @@ LL | for (i, <item>) in vec.iter().enumerate().skip(5) {
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is used to index `vec`
- --> $DIR/needless_range_loop.rs:68:14
+ --> $DIR/needless_range_loop.rs:69:14
|
LL | for i in 5..10 {
| ^^^^^
@@ -143,7 +143,7 @@ LL | for (i, <item>) in vec.iter().enumerate().take(10).skip(5) {
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is used to index `vec`
- --> $DIR/needless_range_loop.rs:73:14
+ --> $DIR/needless_range_loop.rs:74:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/needless_return.fixed b/src/tools/clippy/tests/ui/needless_return.fixed
index 695883e8d..d2163b14f 100644
--- a/src/tools/clippy/tests/ui/needless_return.fixed
+++ b/src/tools/clippy/tests/ui/needless_return.fixed
@@ -232,4 +232,41 @@ fn issue_9361() -> i32 {
return 1 + 2;
}
+fn issue8336(x: i32) -> bool {
+ if x > 0 {
+ println!("something");
+ true
+ } else {
+ false
+ }
+}
+
+fn issue8156(x: u8) -> u64 {
+ match x {
+ 80 => {
+ 10
+ },
+ _ => {
+ 100
+ },
+ }
+}
+
+// Ideally the compiler should throw `unused_braces` in this case
+fn issue9192() -> i32 {
+ {
+ 0
+ }
+}
+
+fn issue9503(x: usize) -> isize {
+ unsafe {
+ if x > 12 {
+ *(x as *const isize)
+ } else {
+ !*(x as *const isize)
+ }
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/needless_return.rs b/src/tools/clippy/tests/ui/needless_return.rs
index 63d9fe9ec..114414b5f 100644
--- a/src/tools/clippy/tests/ui/needless_return.rs
+++ b/src/tools/clippy/tests/ui/needless_return.rs
@@ -232,4 +232,41 @@ fn issue_9361() -> i32 {
return 1 + 2;
}
+fn issue8336(x: i32) -> bool {
+ if x > 0 {
+ println!("something");
+ return true;
+ } else {
+ return false;
+ };
+}
+
+fn issue8156(x: u8) -> u64 {
+ match x {
+ 80 => {
+ return 10;
+ },
+ _ => {
+ return 100;
+ },
+ };
+}
+
+// Ideally the compiler should throw `unused_braces` in this case
+fn issue9192() -> i32 {
+ {
+ return 0;
+ };
+}
+
+fn issue9503(x: usize) -> isize {
+ unsafe {
+ if x > 12 {
+ return *(x as *const isize);
+ } else {
+ return !*(x as *const isize);
+ };
+ };
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/needless_return.stderr b/src/tools/clippy/tests/ui/needless_return.stderr
index cadee6e00..047fb6c23 100644
--- a/src/tools/clippy/tests/ui/needless_return.stderr
+++ b/src/tools/clippy/tests/ui/needless_return.stderr
@@ -2,225 +2,354 @@ error: unneeded `return` statement
--> $DIR/needless_return.rs:26:5
|
LL | return true;
- | ^^^^^^^^^^^^ help: remove `return`: `true`
+ | ^^^^^^^^^^^
|
= note: `-D clippy::needless-return` implied by `-D warnings`
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:30:5
|
LL | return true;
- | ^^^^^^^^^^^^ help: remove `return`: `true`
+ | ^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:35:9
|
LL | return true;
- | ^^^^^^^^^^^^ help: remove `return`: `true`
+ | ^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:37:9
|
LL | return false;
- | ^^^^^^^^^^^^^ help: remove `return`: `false`
+ | ^^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:43:17
|
LL | true => return false,
- | ^^^^^^^^^^^^ help: remove `return`: `false`
+ | ^^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:45:13
|
LL | return true;
- | ^^^^^^^^^^^^ help: remove `return`: `true`
+ | ^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:52:9
|
LL | return true;
- | ^^^^^^^^^^^^ help: remove `return`: `true`
+ | ^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:54:16
|
LL | let _ = || return true;
- | ^^^^^^^^^^^ help: remove `return`: `true`
+ | ^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:58:5
|
LL | return the_answer!();
- | ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `the_answer!()`
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:62:5
|
LL | return;
- | ^^^^^^^ help: remove `return`
+ | ^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:67:9
|
LL | return;
- | ^^^^^^^ help: remove `return`
+ | ^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:69:9
|
LL | return;
- | ^^^^^^^ help: remove `return`
+ | ^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:76:14
|
LL | _ => return,
- | ^^^^^^ help: replace `return` with a unit value: `()`
+ | ^^^^^^
+ |
+ = help: replace `return` with a unit value
error: unneeded `return` statement
--> $DIR/needless_return.rs:85:13
|
LL | return;
- | ^^^^^^^ help: remove `return`
+ | ^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:87:14
|
LL | _ => return,
- | ^^^^^^ help: replace `return` with a unit value: `()`
+ | ^^^^^^
+ |
+ = help: replace `return` with a unit value
error: unneeded `return` statement
--> $DIR/needless_return.rs:100:9
|
LL | return String::from("test");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:102:9
|
LL | return String::new();
- | ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()`
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:124:32
|
LL | bar.unwrap_or_else(|_| return)
- | ^^^^^^ help: replace `return` with an empty block: `{}`
+ | ^^^^^^
+ |
+ = help: replace `return` with an empty block
error: unneeded `return` statement
--> $DIR/needless_return.rs:129:13
|
LL | return;
- | ^^^^^^^ help: remove `return`
+ | ^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:131:20
|
LL | let _ = || return;
- | ^^^^^^ help: replace `return` with an empty block: `{}`
+ | ^^^^^^
+ |
+ = help: replace `return` with an empty block
error: unneeded `return` statement
--> $DIR/needless_return.rs:137:32
|
LL | res.unwrap_or_else(|_| return Foo)
- | ^^^^^^^^^^ help: remove `return`: `Foo`
+ | ^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:146:5
|
LL | return true;
- | ^^^^^^^^^^^^ help: remove `return`: `true`
+ | ^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:150:5
|
LL | return true;
- | ^^^^^^^^^^^^ help: remove `return`: `true`
+ | ^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:155:9
|
LL | return true;
- | ^^^^^^^^^^^^ help: remove `return`: `true`
+ | ^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:157:9
|
LL | return false;
- | ^^^^^^^^^^^^^ help: remove `return`: `false`
+ | ^^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:163:17
|
LL | true => return false,
- | ^^^^^^^^^^^^ help: remove `return`: `false`
+ | ^^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:165:13
|
LL | return true;
- | ^^^^^^^^^^^^ help: remove `return`: `true`
+ | ^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:172:9
|
LL | return true;
- | ^^^^^^^^^^^^ help: remove `return`: `true`
+ | ^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:174:16
|
LL | let _ = || return true;
- | ^^^^^^^^^^^ help: remove `return`: `true`
+ | ^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:178:5
|
LL | return the_answer!();
- | ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `the_answer!()`
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:182:5
|
LL | return;
- | ^^^^^^^ help: remove `return`
+ | ^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:187:9
|
LL | return;
- | ^^^^^^^ help: remove `return`
+ | ^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:189:9
|
LL | return;
- | ^^^^^^^ help: remove `return`
+ | ^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:196:14
|
LL | _ => return,
- | ^^^^^^ help: replace `return` with a unit value: `()`
+ | ^^^^^^
+ |
+ = help: replace `return` with a unit value
error: unneeded `return` statement
--> $DIR/needless_return.rs:209:9
|
LL | return String::from("test");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::from("test")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:211:9
|
LL | return String::new();
- | ^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `String::new()`
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: remove `return`
error: unneeded `return` statement
--> $DIR/needless_return.rs:227:5
|
LL | return format!("Hello {}", "world!");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove `return`: `format!("Hello {}", "world!")`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: remove `return`
+
+error: unneeded `return` statement
+ --> $DIR/needless_return.rs:238:9
+ |
+LL | return true;
+ | ^^^^^^^^^^^
+ |
+ = help: remove `return`
+
+error: unneeded `return` statement
+ --> $DIR/needless_return.rs:240:9
+ |
+LL | return false;
+ | ^^^^^^^^^^^^
+ |
+ = help: remove `return`
+
+error: unneeded `return` statement
+ --> $DIR/needless_return.rs:247:13
+ |
+LL | return 10;
+ | ^^^^^^^^^
+ |
+ = help: remove `return`
+
+error: unneeded `return` statement
+ --> $DIR/needless_return.rs:250:13
+ |
+LL | return 100;
+ | ^^^^^^^^^^
+ |
+ = help: remove `return`
+
+error: unneeded `return` statement
+ --> $DIR/needless_return.rs:258:9
+ |
+LL | return 0;
+ | ^^^^^^^^
+ |
+ = help: remove `return`
+
+error: unneeded `return` statement
+ --> $DIR/needless_return.rs:265:13
+ |
+LL | return *(x as *const isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: remove `return`
+
+error: unneeded `return` statement
+ --> $DIR/needless_return.rs:267:13
+ |
+LL | return !*(x as *const isize);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: remove `return`
-error: aborting due to 37 previous errors
+error: aborting due to 44 previous errors
diff --git a/src/tools/clippy/tests/ui/never_loop.rs b/src/tools/clippy/tests/ui/never_loop.rs
index 0a21589dd..3dbef1989 100644
--- a/src/tools/clippy/tests/ui/never_loop.rs
+++ b/src/tools/clippy/tests/ui/never_loop.rs
@@ -203,6 +203,32 @@ pub fn test17() {
};
}
+// Issue #9356: `continue` in else branch of let..else
+pub fn test18() {
+ let x = Some(0);
+ let y = 0;
+ // might loop
+ let _ = loop {
+ let Some(x) = x else {
+ if y > 0 {
+ continue;
+ } else {
+ return;
+ }
+ };
+
+ break x;
+ };
+ // never loops
+ let _ = loop {
+ let Some(x) = x else {
+ return;
+ };
+
+ break x;
+ };
+}
+
fn main() {
test1();
test2();
diff --git a/src/tools/clippy/tests/ui/never_loop.stderr b/src/tools/clippy/tests/ui/never_loop.stderr
index f49b23924..3033f0192 100644
--- a/src/tools/clippy/tests/ui/never_loop.stderr
+++ b/src/tools/clippy/tests/ui/never_loop.stderr
@@ -101,5 +101,18 @@ LL | | break 'label;
LL | | }
| |_________^
-error: aborting due to 9 previous errors
+error: this loop never actually loops
+ --> $DIR/never_loop.rs:223:13
+ |
+LL | let _ = loop {
+ | _____________^
+LL | | let Some(x) = x else {
+LL | | return;
+LL | | };
+LL | |
+LL | | break x;
+LL | | };
+ | |_____^
+
+error: aborting due to 10 previous errors
diff --git a/src/tools/clippy/tests/ui/no_effect.rs b/src/tools/clippy/tests/ui/no_effect.rs
index fdefb11ae..f08eb092e 100644
--- a/src/tools/clippy/tests/ui/no_effect.rs
+++ b/src/tools/clippy/tests/ui/no_effect.rs
@@ -1,9 +1,7 @@
#![feature(box_syntax, fn_traits, unboxed_closures)]
#![warn(clippy::no_effect_underscore_binding)]
-#![allow(dead_code)]
-#![allow(path_statements)]
-#![allow(clippy::deref_addrof)]
-#![allow(clippy::redundant_field_names)]
+#![allow(dead_code, path_statements)]
+#![allow(clippy::deref_addrof, clippy::redundant_field_names, clippy::uninlined_format_args)]
struct Unit;
struct Tuple(i32);
diff --git a/src/tools/clippy/tests/ui/no_effect.stderr b/src/tools/clippy/tests/ui/no_effect.stderr
index 328d2555c..6a1e636f9 100644
--- a/src/tools/clippy/tests/ui/no_effect.stderr
+++ b/src/tools/clippy/tests/ui/no_effect.stderr
@@ -1,5 +1,5 @@
error: statement with no effect
- --> $DIR/no_effect.rs:94:5
+ --> $DIR/no_effect.rs:92:5
|
LL | 0;
| ^^
@@ -7,157 +7,157 @@ LL | 0;
= note: `-D clippy::no-effect` implied by `-D warnings`
error: statement with no effect
- --> $DIR/no_effect.rs:95:5
+ --> $DIR/no_effect.rs:93:5
|
LL | s2;
| ^^^
error: statement with no effect
- --> $DIR/no_effect.rs:96:5
+ --> $DIR/no_effect.rs:94:5
|
LL | Unit;
| ^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:97:5
+ --> $DIR/no_effect.rs:95:5
|
LL | Tuple(0);
| ^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:98:5
+ --> $DIR/no_effect.rs:96:5
|
LL | Struct { field: 0 };
| ^^^^^^^^^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:99:5
+ --> $DIR/no_effect.rs:97:5
|
LL | Struct { ..s };
| ^^^^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:100:5
+ --> $DIR/no_effect.rs:98:5
|
LL | Union { a: 0 };
| ^^^^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:101:5
+ --> $DIR/no_effect.rs:99:5
|
LL | Enum::Tuple(0);
| ^^^^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:102:5
+ --> $DIR/no_effect.rs:100:5
|
LL | Enum::Struct { field: 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:103:5
+ --> $DIR/no_effect.rs:101:5
|
LL | 5 + 6;
| ^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:104:5
+ --> $DIR/no_effect.rs:102:5
|
LL | *&42;
| ^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:105:5
+ --> $DIR/no_effect.rs:103:5
|
LL | &6;
| ^^^
error: statement with no effect
- --> $DIR/no_effect.rs:106:5
+ --> $DIR/no_effect.rs:104:5
|
LL | (5, 6, 7);
| ^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:107:5
+ --> $DIR/no_effect.rs:105:5
|
LL | box 42;
| ^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:108:5
+ --> $DIR/no_effect.rs:106:5
|
LL | ..;
| ^^^
error: statement with no effect
- --> $DIR/no_effect.rs:109:5
+ --> $DIR/no_effect.rs:107:5
|
LL | 5..;
| ^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:110:5
+ --> $DIR/no_effect.rs:108:5
|
LL | ..5;
| ^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:111:5
+ --> $DIR/no_effect.rs:109:5
|
LL | 5..6;
| ^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:112:5
+ --> $DIR/no_effect.rs:110:5
|
LL | 5..=6;
| ^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:113:5
+ --> $DIR/no_effect.rs:111:5
|
LL | [42, 55];
| ^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:114:5
+ --> $DIR/no_effect.rs:112:5
|
LL | [42, 55][1];
| ^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:115:5
+ --> $DIR/no_effect.rs:113:5
|
LL | (42, 55).1;
| ^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:116:5
+ --> $DIR/no_effect.rs:114:5
|
LL | [42; 55];
| ^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:117:5
+ --> $DIR/no_effect.rs:115:5
|
LL | [42; 55][13];
| ^^^^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:119:5
+ --> $DIR/no_effect.rs:117:5
|
LL | || x += 5;
| ^^^^^^^^^^
error: statement with no effect
- --> $DIR/no_effect.rs:121:5
+ --> $DIR/no_effect.rs:119:5
|
LL | FooString { s: s };
| ^^^^^^^^^^^^^^^^^^^
error: binding to `_` prefixed variable with no side-effect
- --> $DIR/no_effect.rs:122:5
+ --> $DIR/no_effect.rs:120:5
|
LL | let _unused = 1;
| ^^^^^^^^^^^^^^^^
@@ -165,19 +165,19 @@ LL | let _unused = 1;
= note: `-D clippy::no-effect-underscore-binding` implied by `-D warnings`
error: binding to `_` prefixed variable with no side-effect
- --> $DIR/no_effect.rs:123:5
+ --> $DIR/no_effect.rs:121:5
|
LL | let _penguin = || println!("Some helpful closure");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: binding to `_` prefixed variable with no side-effect
- --> $DIR/no_effect.rs:124:5
+ --> $DIR/no_effect.rs:122:5
|
LL | let _duck = Struct { field: 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: binding to `_` prefixed variable with no side-effect
- --> $DIR/no_effect.rs:125:5
+ --> $DIR/no_effect.rs:123:5
|
LL | let _cat = [2, 4, 6, 8][2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr
index b6c904a14..e912b59a6 100644
--- a/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr
+++ b/src/tools/clippy/tests/ui/non_send_fields_in_send_ty.stderr
@@ -4,13 +4,13 @@ error: some fields in `RingBuffer<T>` are not safe to be sent to another thread
LL | unsafe impl<T> Send for RingBuffer<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings`
note: it is not safe to send field `data` to another thread
--> $DIR/non_send_fields_in_send_ty.rs:12:5
|
LL | data: Vec<UnsafeCell<T>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^
= help: add bounds on type parameter `T` that satisfy `Vec<UnsafeCell<T>>: Send`
+ = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings`
error: some fields in `MvccRwLock<T>` are not safe to be sent to another thread
--> $DIR/non_send_fields_in_send_ty.rs:25:1
diff --git a/src/tools/clippy/tests/ui/nonminimal_bool.rs b/src/tools/clippy/tests/ui/nonminimal_bool.rs
index 24ae62bb0..e9b4367ca 100644
--- a/src/tools/clippy/tests/ui/nonminimal_bool.rs
+++ b/src/tools/clippy/tests/ui/nonminimal_bool.rs
@@ -57,3 +57,9 @@ fn check_expect() {
#[expect(clippy::nonminimal_bool)]
let _ = !!a;
}
+
+fn issue9428() {
+ if matches!(true, true) && true {
+ println!("foo");
+ }
+}
diff --git a/src/tools/clippy/tests/ui/nonminimal_bool.stderr b/src/tools/clippy/tests/ui/nonminimal_bool.stderr
index fc6a5ce1d..91b5805aa 100644
--- a/src/tools/clippy/tests/ui/nonminimal_bool.stderr
+++ b/src/tools/clippy/tests/ui/nonminimal_bool.stderr
@@ -107,5 +107,11 @@ LL | let _ = !(a == b || c == d);
LL | let _ = a != b && c != d;
| ~~~~~~~~~~~~~~~~
-error: aborting due to 12 previous errors
+error: this boolean expression can be simplified
+ --> $DIR/nonminimal_bool.rs:62:8
+ |
+LL | if matches!(true, true) && true {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `matches!(true, true)`
+
+error: aborting due to 13 previous errors
diff --git a/src/tools/clippy/tests/ui/octal_escapes.stderr b/src/tools/clippy/tests/ui/octal_escapes.stderr
index 54f5bbb0f..295dc1798 100644
--- a/src/tools/clippy/tests/ui/octal_escapes.stderr
+++ b/src/tools/clippy/tests/ui/octal_escapes.stderr
@@ -4,8 +4,8 @@ error: octal-looking escape in string literal
LL | let _bad1 = "/033[0m";
| ^^^^^^^^^
|
- = note: `-D clippy::octal-escapes` implied by `-D warnings`
= help: octal escapes are not supported, `/0` is always a null character
+ = note: `-D clippy::octal-escapes` implied by `-D warnings`
help: if an octal escape was intended, use the hexadecimal representation instead
|
LL | let _bad1 = "/x1b[0m";
diff --git a/src/tools/clippy/tests/ui/ok_expect.stderr b/src/tools/clippy/tests/ui/ok_expect.stderr
index b02b28e7f..6c40adbb5 100644
--- a/src/tools/clippy/tests/ui/ok_expect.stderr
+++ b/src/tools/clippy/tests/ui/ok_expect.stderr
@@ -4,8 +4,8 @@ error: called `ok().expect()` on a `Result` value
LL | res.ok().expect("disaster!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::ok-expect` implied by `-D warnings`
= help: you can call `expect()` directly on the `Result`
+ = note: `-D clippy::ok-expect` implied by `-D warnings`
error: called `ok().expect()` on a `Result` value
--> $DIR/ok_expect.rs:20:5
diff --git a/src/tools/clippy/tests/ui/only_used_in_recursion.stderr b/src/tools/clippy/tests/ui/only_used_in_recursion.stderr
index 74057ddcf..571e5c4b5 100644
--- a/src/tools/clippy/tests/ui/only_used_in_recursion.stderr
+++ b/src/tools/clippy/tests/ui/only_used_in_recursion.stderr
@@ -4,12 +4,12 @@ error: parameter is only used in recursion
LL | fn _one_unused(flag: u32, a: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`
|
- = note: `-D clippy::only-used-in-recursion` implied by `-D warnings`
note: parameter used here
--> $DIR/only_used_in_recursion.rs:12:53
|
LL | if flag == 0 { 0 } else { _one_unused(flag - 1, a) }
| ^
+ = note: `-D clippy::only-used-in-recursion` implied by `-D warnings`
error: parameter is only used in recursion
--> $DIR/only_used_in_recursion.rs:15:27
diff --git a/src/tools/clippy/tests/ui/only_used_in_recursion2.stderr b/src/tools/clippy/tests/ui/only_used_in_recursion2.stderr
index 23f6ffd30..8dcbfdd61 100644
--- a/src/tools/clippy/tests/ui/only_used_in_recursion2.stderr
+++ b/src/tools/clippy/tests/ui/only_used_in_recursion2.stderr
@@ -4,12 +4,12 @@ error: parameter is only used in recursion
LL | fn _with_inner(flag: u32, a: u32, b: u32) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`
|
- = note: `-D clippy::only-used-in-recursion` implied by `-D warnings`
note: parameter used here
--> $DIR/only_used_in_recursion2.rs:9:52
|
LL | if flag == 0 { 0 } else { _with_inner(flag, a, b + x) }
| ^
+ = note: `-D clippy::only-used-in-recursion` implied by `-D warnings`
error: parameter is only used in recursion
--> $DIR/only_used_in_recursion2.rs:4:25
diff --git a/src/tools/clippy/tests/ui/option_as_ref_deref.fixed b/src/tools/clippy/tests/ui/option_as_ref_deref.fixed
index 07d7f0b45..bc376d0d7 100644
--- a/src/tools/clippy/tests/ui/option_as_ref_deref.fixed
+++ b/src/tools/clippy/tests/ui/option_as_ref_deref.fixed
@@ -1,6 +1,7 @@
// run-rustfix
-#![allow(unused_imports, clippy::redundant_clone)]
+#![feature(custom_inner_attributes)]
+#![allow(unused, clippy::redundant_clone)]
#![warn(clippy::option_as_ref_deref)]
use std::ffi::{CString, OsString};
@@ -42,3 +43,17 @@ fn main() {
// Issue #5927
let _ = opt.as_deref();
}
+
+fn msrv_1_39() {
+ #![clippy::msrv = "1.39"]
+
+ let opt = Some(String::from("123"));
+ let _ = opt.as_ref().map(String::as_str);
+}
+
+fn msrv_1_40() {
+ #![clippy::msrv = "1.40"]
+
+ let opt = Some(String::from("123"));
+ let _ = opt.as_deref();
+}
diff --git a/src/tools/clippy/tests/ui/option_as_ref_deref.rs b/src/tools/clippy/tests/ui/option_as_ref_deref.rs
index 6ae059c94..ba3a2eedc 100644
--- a/src/tools/clippy/tests/ui/option_as_ref_deref.rs
+++ b/src/tools/clippy/tests/ui/option_as_ref_deref.rs
@@ -1,6 +1,7 @@
// run-rustfix
-#![allow(unused_imports, clippy::redundant_clone)]
+#![feature(custom_inner_attributes)]
+#![allow(unused, clippy::redundant_clone)]
#![warn(clippy::option_as_ref_deref)]
use std::ffi::{CString, OsString};
@@ -45,3 +46,17 @@ fn main() {
// Issue #5927
let _ = opt.as_ref().map(std::ops::Deref::deref);
}
+
+fn msrv_1_39() {
+ #![clippy::msrv = "1.39"]
+
+ let opt = Some(String::from("123"));
+ let _ = opt.as_ref().map(String::as_str);
+}
+
+fn msrv_1_40() {
+ #![clippy::msrv = "1.40"]
+
+ let opt = Some(String::from("123"));
+ let _ = opt.as_ref().map(String::as_str);
+}
diff --git a/src/tools/clippy/tests/ui/option_as_ref_deref.stderr b/src/tools/clippy/tests/ui/option_as_ref_deref.stderr
index 62f282324..7de8b3b6b 100644
--- a/src/tools/clippy/tests/ui/option_as_ref_deref.stderr
+++ b/src/tools/clippy/tests/ui/option_as_ref_deref.stderr
@@ -1,5 +1,5 @@
error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:13:13
+ --> $DIR/option_as_ref_deref.rs:14:13
|
LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.clone().as_deref()`
@@ -7,7 +7,7 @@ LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len);
= note: `-D clippy::option-as-ref-deref` implied by `-D warnings`
error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:16:13
+ --> $DIR/option_as_ref_deref.rs:17:13
|
LL | let _ = opt.clone()
| _____________^
@@ -17,94 +17,100 @@ LL | | )
| |_________^ help: try using as_deref instead: `opt.clone().as_deref()`
error: called `.as_mut().map(DerefMut::deref_mut)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
- --> $DIR/option_as_ref_deref.rs:22:13
+ --> $DIR/option_as_ref_deref.rs:23:13
|
LL | let _ = opt.as_mut().map(DerefMut::deref_mut);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:24:13
+ --> $DIR/option_as_ref_deref.rs:25:13
|
LL | let _ = opt.as_ref().map(String::as_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
error: called `.as_ref().map(|x| x.as_str())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:25:13
+ --> $DIR/option_as_ref_deref.rs:26:13
|
LL | let _ = opt.as_ref().map(|x| x.as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
error: called `.as_mut().map(String::as_mut_str)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
- --> $DIR/option_as_ref_deref.rs:26:13
+ --> $DIR/option_as_ref_deref.rs:27:13
|
LL | let _ = opt.as_mut().map(String::as_mut_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
error: called `.as_mut().map(|x| x.as_mut_str())` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
- --> $DIR/option_as_ref_deref.rs:27:13
+ --> $DIR/option_as_ref_deref.rs:28:13
|
LL | let _ = opt.as_mut().map(|x| x.as_mut_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
error: called `.as_ref().map(CString::as_c_str)` on an Option value. This can be done more directly by calling `Some(CString::new(vec![]).unwrap()).as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:28:13
+ --> $DIR/option_as_ref_deref.rs:29:13
|
LL | let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(CString::new(vec![]).unwrap()).as_deref()`
error: called `.as_ref().map(OsString::as_os_str)` on an Option value. This can be done more directly by calling `Some(OsString::new()).as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:29:13
+ --> $DIR/option_as_ref_deref.rs:30:13
|
LL | let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(OsString::new()).as_deref()`
error: called `.as_ref().map(PathBuf::as_path)` on an Option value. This can be done more directly by calling `Some(PathBuf::new()).as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:30:13
+ --> $DIR/option_as_ref_deref.rs:31:13
|
LL | let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(PathBuf::new()).as_deref()`
error: called `.as_ref().map(Vec::as_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:31:13
+ --> $DIR/option_as_ref_deref.rs:32:13
|
LL | let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(Vec::<()>::new()).as_deref()`
error: called `.as_mut().map(Vec::as_mut_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref_mut()` instead
- --> $DIR/option_as_ref_deref.rs:32:13
+ --> $DIR/option_as_ref_deref.rs:33:13
|
LL | let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `Some(Vec::<()>::new()).as_deref_mut()`
error: called `.as_ref().map(|x| x.deref())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:34:13
+ --> $DIR/option_as_ref_deref.rs:35:13
|
LL | let _ = opt.as_ref().map(|x| x.deref());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
error: called `.as_mut().map(|x| x.deref_mut())` on an Option value. This can be done more directly by calling `opt.clone().as_deref_mut()` instead
- --> $DIR/option_as_ref_deref.rs:35:13
+ --> $DIR/option_as_ref_deref.rs:36:13
|
LL | let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.clone().as_deref_mut()`
error: called `.as_ref().map(|x| &**x)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:42:13
+ --> $DIR/option_as_ref_deref.rs:43:13
|
LL | let _ = opt.as_ref().map(|x| &**x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
error: called `.as_mut().map(|x| &mut **x)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
- --> $DIR/option_as_ref_deref.rs:43:13
+ --> $DIR/option_as_ref_deref.rs:44:13
|
LL | let _ = opt.as_mut().map(|x| &mut **x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
error: called `.as_ref().map(std::ops::Deref::deref)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
- --> $DIR/option_as_ref_deref.rs:46:13
+ --> $DIR/option_as_ref_deref.rs:47:13
|
LL | let _ = opt.as_ref().map(std::ops::Deref::deref);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
-error: aborting due to 17 previous errors
+error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
+ --> $DIR/option_as_ref_deref.rs:61:13
+ |
+LL | let _ = opt.as_ref().map(String::as_str);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
+
+error: aborting due to 18 previous errors
diff --git a/src/tools/clippy/tests/ui/option_env_unwrap.stderr b/src/tools/clippy/tests/ui/option_env_unwrap.stderr
index 885ac096c..bc188a07e 100644
--- a/src/tools/clippy/tests/ui/option_env_unwrap.stderr
+++ b/src/tools/clippy/tests/ui/option_env_unwrap.stderr
@@ -4,8 +4,8 @@ error: this will panic at run-time if the environment variable doesn't exist at
LL | let _ = option_env!("PATH").unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::option-env-unwrap` implied by `-D warnings`
= help: consider using the `env!` macro instead
+ = note: `-D clippy::option-env-unwrap` implied by `-D warnings`
error: this will panic at run-time if the environment variable doesn't exist at compile-time
--> $DIR/option_env_unwrap.rs:19:13
diff --git a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed
index 1290bd8ef..00264dcce 100644
--- a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed
+++ b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.fixed
@@ -1,8 +1,7 @@
// run-rustfix
-
#![warn(clippy::option_map_unit_fn)]
#![allow(unused)]
-#![allow(clippy::unnecessary_wraps)]
+#![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)]
fn do_nothing<T>(_: T) {}
diff --git a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs
index f3e5b62c6..f3363ebce 100644
--- a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs
+++ b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.rs
@@ -1,8 +1,7 @@
// run-rustfix
-
#![warn(clippy::option_map_unit_fn)]
#![allow(unused)]
-#![allow(clippy::unnecessary_wraps)]
+#![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)]
fn do_nothing<T>(_: T) {}
diff --git a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr
index ab2a294a0..0305387b9 100644
--- a/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr
+++ b/src/tools/clippy/tests/ui/option_map_unit_fn_fixable.stderr
@@ -1,5 +1,5 @@
error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:39:5
+ --> $DIR/option_map_unit_fn_fixable.rs:38:5
|
LL | x.field.map(do_nothing);
| ^^^^^^^^^^^^^^^^^^^^^^^-
@@ -9,7 +9,7 @@ LL | x.field.map(do_nothing);
= note: `-D clippy::option-map-unit-fn` implied by `-D warnings`
error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:41:5
+ --> $DIR/option_map_unit_fn_fixable.rs:40:5
|
LL | x.field.map(do_nothing);
| ^^^^^^^^^^^^^^^^^^^^^^^-
@@ -17,7 +17,7 @@ LL | x.field.map(do_nothing);
| help: try this: `if let Some(x_field) = x.field { do_nothing(x_field) }`
error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:43:5
+ --> $DIR/option_map_unit_fn_fixable.rs:42:5
|
LL | x.field.map(diverge);
| ^^^^^^^^^^^^^^^^^^^^-
@@ -25,7 +25,7 @@ LL | x.field.map(diverge);
| help: try this: `if let Some(x_field) = x.field { diverge(x_field) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:49:5
+ --> $DIR/option_map_unit_fn_fixable.rs:48:5
|
LL | x.field.map(|value| x.do_option_nothing(value + captured));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -33,7 +33,7 @@ LL | x.field.map(|value| x.do_option_nothing(value + captured));
| help: try this: `if let Some(value) = x.field { x.do_option_nothing(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:51:5
+ --> $DIR/option_map_unit_fn_fixable.rs:50:5
|
LL | x.field.map(|value| { x.do_option_plus_one(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -41,7 +41,7 @@ LL | x.field.map(|value| { x.do_option_plus_one(value + captured); });
| help: try this: `if let Some(value) = x.field { x.do_option_plus_one(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:54:5
+ --> $DIR/option_map_unit_fn_fixable.rs:53:5
|
LL | x.field.map(|value| do_nothing(value + captured));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -49,7 +49,7 @@ LL | x.field.map(|value| do_nothing(value + captured));
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:56:5
+ --> $DIR/option_map_unit_fn_fixable.rs:55:5
|
LL | x.field.map(|value| { do_nothing(value + captured) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -57,7 +57,7 @@ LL | x.field.map(|value| { do_nothing(value + captured) });
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:58:5
+ --> $DIR/option_map_unit_fn_fixable.rs:57:5
|
LL | x.field.map(|value| { do_nothing(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -65,7 +65,7 @@ LL | x.field.map(|value| { do_nothing(value + captured); });
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:60:5
+ --> $DIR/option_map_unit_fn_fixable.rs:59:5
|
LL | x.field.map(|value| { { do_nothing(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -73,7 +73,7 @@ LL | x.field.map(|value| { { do_nothing(value + captured); } });
| help: try this: `if let Some(value) = x.field { do_nothing(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:63:5
+ --> $DIR/option_map_unit_fn_fixable.rs:62:5
|
LL | x.field.map(|value| diverge(value + captured));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -81,7 +81,7 @@ LL | x.field.map(|value| diverge(value + captured));
| help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:65:5
+ --> $DIR/option_map_unit_fn_fixable.rs:64:5
|
LL | x.field.map(|value| { diverge(value + captured) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -89,7 +89,7 @@ LL | x.field.map(|value| { diverge(value + captured) });
| help: try this: `if let Some(value) = x.field { diverge(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:67:5
+ --> $DIR/option_map_unit_fn_fixable.rs:66:5
|
LL | x.field.map(|value| { diverge(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -97,7 +97,7 @@ LL | x.field.map(|value| { diverge(value + captured); });
| help: try this: `if let Some(value) = x.field { diverge(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:69:5
+ --> $DIR/option_map_unit_fn_fixable.rs:68:5
|
LL | x.field.map(|value| { { diverge(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -105,7 +105,7 @@ LL | x.field.map(|value| { { diverge(value + captured); } });
| help: try this: `if let Some(value) = x.field { diverge(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:74:5
+ --> $DIR/option_map_unit_fn_fixable.rs:73:5
|
LL | x.field.map(|value| { let y = plus_one(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -113,7 +113,7 @@ LL | x.field.map(|value| { let y = plus_one(value + captured); });
| help: try this: `if let Some(value) = x.field { let y = plus_one(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:76:5
+ --> $DIR/option_map_unit_fn_fixable.rs:75:5
|
LL | x.field.map(|value| { plus_one(value + captured); });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -121,7 +121,7 @@ LL | x.field.map(|value| { plus_one(value + captured); });
| help: try this: `if let Some(value) = x.field { plus_one(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:78:5
+ --> $DIR/option_map_unit_fn_fixable.rs:77:5
|
LL | x.field.map(|value| { { plus_one(value + captured); } });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -129,7 +129,7 @@ LL | x.field.map(|value| { { plus_one(value + captured); } });
| help: try this: `if let Some(value) = x.field { plus_one(value + captured); }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:81:5
+ --> $DIR/option_map_unit_fn_fixable.rs:80:5
|
LL | x.field.map(|ref value| { do_nothing(value + captured) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -137,7 +137,7 @@ LL | x.field.map(|ref value| { do_nothing(value + captured) });
| help: try this: `if let Some(ref value) = x.field { do_nothing(value + captured) }`
error: called `map(f)` on an `Option` value where `f` is a function that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:83:5
+ --> $DIR/option_map_unit_fn_fixable.rs:82:5
|
LL | option().map(do_nothing);
| ^^^^^^^^^^^^^^^^^^^^^^^^-
@@ -145,7 +145,7 @@ LL | option().map(do_nothing);
| help: try this: `if let Some(a) = option() { do_nothing(a) }`
error: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
- --> $DIR/option_map_unit_fn_fixable.rs:85:5
+ --> $DIR/option_map_unit_fn_fixable.rs:84:5
|
LL | option().map(|value| println!("{:?}", value));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
diff --git a/src/tools/clippy/tests/ui/option_take_on_temporary.fixed b/src/tools/clippy/tests/ui/option_take_on_temporary.fixed
deleted file mode 100644
index 29691e816..000000000
--- a/src/tools/clippy/tests/ui/option_take_on_temporary.fixed
+++ /dev/null
@@ -1,15 +0,0 @@
-// run-rustfix
-
-fn main() {
- println!("Testing non erroneous option_take_on_temporary");
- let mut option = Some(1);
- let _ = Box::new(move || option.take().unwrap());
-
- println!("Testing non erroneous option_take_on_temporary");
- let x = Some(3);
- x.as_ref();
-
- println!("Testing erroneous option_take_on_temporary");
- let x = Some(3);
- x.as_ref();
-}
diff --git a/src/tools/clippy/tests/ui/or_fun_call.fixed b/src/tools/clippy/tests/ui/or_fun_call.fixed
index 5991188ab..23b1aa8be 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.fixed
+++ b/src/tools/clippy/tests/ui/or_fun_call.fixed
@@ -1,8 +1,7 @@
// run-rustfix
-
#![warn(clippy::or_fun_call)]
#![allow(dead_code)]
-#![allow(clippy::unnecessary_wraps, clippy::borrow_as_ptr)]
+#![allow(clippy::borrow_as_ptr, clippy::uninlined_format_args, clippy::unnecessary_wraps)]
use std::collections::BTreeMap;
use std::collections::HashMap;
@@ -226,4 +225,15 @@ mod issue8239 {
}
}
+mod issue9608 {
+ fn sig_drop() {
+ enum X {
+ X(std::fs::File),
+ Y(u32),
+ }
+
+ let _ = None.unwrap_or(X::Y(0));
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/or_fun_call.rs b/src/tools/clippy/tests/ui/or_fun_call.rs
index c353b41e4..039998f22 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.rs
+++ b/src/tools/clippy/tests/ui/or_fun_call.rs
@@ -1,8 +1,7 @@
// run-rustfix
-
#![warn(clippy::or_fun_call)]
#![allow(dead_code)]
-#![allow(clippy::unnecessary_wraps, clippy::borrow_as_ptr)]
+#![allow(clippy::borrow_as_ptr, clippy::uninlined_format_args, clippy::unnecessary_wraps)]
use std::collections::BTreeMap;
use std::collections::HashMap;
@@ -226,4 +225,15 @@ mod issue8239 {
}
}
+mod issue9608 {
+ fn sig_drop() {
+ enum X {
+ X(std::fs::File),
+ Y(u32),
+ }
+
+ let _ = None.unwrap_or(X::Y(0));
+ }
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/or_fun_call.stderr b/src/tools/clippy/tests/ui/or_fun_call.stderr
index e3dab4cb1..113ba150c 100644
--- a/src/tools/clippy/tests/ui/or_fun_call.stderr
+++ b/src/tools/clippy/tests/ui/or_fun_call.stderr
@@ -1,5 +1,5 @@
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:49:22
+ --> $DIR/or_fun_call.rs:48:22
|
LL | with_constructor.unwrap_or(make());
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(make)`
@@ -7,151 +7,151 @@ LL | with_constructor.unwrap_or(make());
= note: `-D clippy::or-fun-call` implied by `-D warnings`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:52:14
+ --> $DIR/or_fun_call.rs:51:14
|
LL | with_new.unwrap_or(Vec::new());
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:55:21
+ --> $DIR/or_fun_call.rs:54:21
|
LL | with_const_args.unwrap_or(Vec::with_capacity(12));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| Vec::with_capacity(12))`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:58:14
+ --> $DIR/or_fun_call.rs:57:14
|
LL | with_err.unwrap_or(make());
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| make())`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:61:19
+ --> $DIR/or_fun_call.rs:60:19
|
LL | with_err_args.unwrap_or(Vec::with_capacity(12));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| Vec::with_capacity(12))`
error: use of `unwrap_or` followed by a call to `default`
- --> $DIR/or_fun_call.rs:64:24
+ --> $DIR/or_fun_call.rs:63:24
|
LL | with_default_trait.unwrap_or(Default::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `default`
- --> $DIR/or_fun_call.rs:67:23
+ --> $DIR/or_fun_call.rs:66:23
|
LL | with_default_type.unwrap_or(u64::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:70:18
+ --> $DIR/or_fun_call.rs:69:18
|
LL | self_default.unwrap_or(<FakeDefault>::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(<FakeDefault>::default)`
error: use of `unwrap_or` followed by a call to `default`
- --> $DIR/or_fun_call.rs:73:18
+ --> $DIR/or_fun_call.rs:72:18
|
LL | real_default.unwrap_or(<FakeDefault as Default>::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:76:14
+ --> $DIR/or_fun_call.rs:75:14
|
LL | with_vec.unwrap_or(vec![]);
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:79:21
+ --> $DIR/or_fun_call.rs:78:21
|
LL | without_default.unwrap_or(Foo::new());
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(Foo::new)`
error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:82:19
+ --> $DIR/or_fun_call.rs:81:19
|
LL | map.entry(42).or_insert(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:85:23
+ --> $DIR/or_fun_call.rs:84:23
|
LL | map_vec.entry(42).or_insert(vec![]);
| ^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:88:21
+ --> $DIR/or_fun_call.rs:87:21
|
LL | btree.entry(42).or_insert(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:91:25
+ --> $DIR/or_fun_call.rs:90:25
|
LL | btree_vec.entry(42).or_insert(vec![]);
| ^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:94:21
+ --> $DIR/or_fun_call.rs:93:21
|
LL | let _ = stringy.unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:102:21
+ --> $DIR/or_fun_call.rs:101:21
|
LL | let _ = Some(1).unwrap_or(map[&1]);
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:104:21
+ --> $DIR/or_fun_call.rs:103:21
|
LL | let _ = Some(1).unwrap_or(map[&1]);
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
error: use of `or` followed by a function call
- --> $DIR/or_fun_call.rs:128:35
+ --> $DIR/or_fun_call.rs:127:35
|
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:167:14
+ --> $DIR/or_fun_call.rs:166:14
|
LL | None.unwrap_or(ptr_to_ref(s));
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| ptr_to_ref(s))`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:173:14
+ --> $DIR/or_fun_call.rs:172:14
|
LL | None.unwrap_or(unsafe { ptr_to_ref(s) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:175:14
+ --> $DIR/or_fun_call.rs:174:14
|
LL | None.unwrap_or( unsafe { ptr_to_ref(s) } );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:189:14
+ --> $DIR/or_fun_call.rs:188:14
|
LL | .unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:202:14
+ --> $DIR/or_fun_call.rs:201:14
|
LL | .unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:214:14
+ --> $DIR/or_fun_call.rs:213:14
|
LL | .unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:225:10
+ --> $DIR/or_fun_call.rs:224:10
|
LL | .unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
diff --git a/src/tools/clippy/tests/ui/out_of_bounds_indexing/issue-3102.rs b/src/tools/clippy/tests/ui/out_of_bounds_indexing/issue-3102.rs
index f20a0ede1..edd2123d4 100644
--- a/src/tools/clippy/tests/ui/out_of_bounds_indexing/issue-3102.rs
+++ b/src/tools/clippy/tests/ui/out_of_bounds_indexing/issue-3102.rs
@@ -1,5 +1,5 @@
#![warn(clippy::out_of_bounds_indexing)]
-#![allow(clippy::no_effect, const_err)]
+#![allow(clippy::no_effect)]
fn main() {
let x = [1, 2, 3, 4];
diff --git a/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs b/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs
index 590e578d7..4c541c23f 100644
--- a/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs
+++ b/src/tools/clippy/tests/ui/out_of_bounds_indexing/simple.rs
@@ -1,5 +1,5 @@
#![warn(clippy::out_of_bounds_indexing)]
-#![allow(clippy::no_effect, clippy::unnecessary_operation, const_err)]
+#![allow(clippy::no_effect, clippy::unnecessary_operation)]
fn main() {
let x = [1, 2, 3, 4];
diff --git a/src/tools/clippy/tests/ui/overly_complex_bool_expr.stderr b/src/tools/clippy/tests/ui/overly_complex_bool_expr.stderr
index 158cae8b8..e989f2ece 100644
--- a/src/tools/clippy/tests/ui/overly_complex_bool_expr.stderr
+++ b/src/tools/clippy/tests/ui/overly_complex_bool_expr.stderr
@@ -4,12 +4,12 @@ error: this boolean expression contains a logic bug
LL | let _ = a && b || a;
| ^^^^^^^^^^^ help: it would look like the following: `a`
|
- = note: `-D clippy::overly-complex-bool-expr` implied by `-D warnings`
help: this expression can be optimized out by applying boolean operations to the outer expression
--> $DIR/overly_complex_bool_expr.rs:11:18
|
LL | let _ = a && b || a;
| ^
+ = note: `-D clippy::overly-complex-bool-expr` implied by `-D warnings`
error: this boolean expression contains a logic bug
--> $DIR/overly_complex_bool_expr.rs:13:13
diff --git a/src/tools/clippy/tests/ui/panic_in_result_fn.stderr b/src/tools/clippy/tests/ui/panic_in_result_fn.stderr
index 561503ae5..97787bc84 100644
--- a/src/tools/clippy/tests/ui/panic_in_result_fn.stderr
+++ b/src/tools/clippy/tests/ui/panic_in_result_fn.stderr
@@ -7,13 +7,13 @@ LL | | panic!("error");
LL | | }
| |_____^
|
- = note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
= help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
note: return Err() instead of panicking
--> $DIR/panic_in_result_fn.rs:8:9
|
LL | panic!("error");
| ^^^^^^^^^^^^^^^
+ = note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
--> $DIR/panic_in_result_fn.rs:11:5
diff --git a/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.rs b/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.rs
index ffdf8288a..08ab4d868 100644
--- a/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.rs
+++ b/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.rs
@@ -1,5 +1,5 @@
#![warn(clippy::panic_in_result_fn)]
-#![allow(clippy::unnecessary_wraps)]
+#![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)]
struct A;
diff --git a/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr b/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr
index b6aa005e7..eb0aacbb6 100644
--- a/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr
+++ b/src/tools/clippy/tests/ui/panic_in_result_fn_assertions.stderr
@@ -8,13 +8,13 @@ LL | | Ok(true)
LL | | }
| |_____^
|
- = note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
= help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
note: return Err() instead of panicking
--> $DIR/panic_in_result_fn_assertions.rs:9:9
|
LL | assert!(x == 5, "wrong argument");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
--> $DIR/panic_in_result_fn_assertions.rs:13:5
diff --git a/src/tools/clippy/tests/ui/panic_in_result_fn_debug_assertions.rs b/src/tools/clippy/tests/ui/panic_in_result_fn_debug_assertions.rs
index c4fcd7e70..df89d8c50 100644
--- a/src/tools/clippy/tests/ui/panic_in_result_fn_debug_assertions.rs
+++ b/src/tools/clippy/tests/ui/panic_in_result_fn_debug_assertions.rs
@@ -1,5 +1,5 @@
#![warn(clippy::panic_in_result_fn)]
-#![allow(clippy::unnecessary_wraps)]
+#![allow(clippy::uninlined_format_args, clippy::unnecessary_wraps)]
// debug_assert should never trigger the `panic_in_result_fn` lint
diff --git a/src/tools/clippy/tests/ui/partial_pub_fields.rs b/src/tools/clippy/tests/ui/partial_pub_fields.rs
new file mode 100644
index 000000000..668545da8
--- /dev/null
+++ b/src/tools/clippy/tests/ui/partial_pub_fields.rs
@@ -0,0 +1,40 @@
+#![allow(unused)]
+#![warn(clippy::partial_pub_fields)]
+
+fn main() {
+ use std::collections::HashMap;
+
+ #[derive(Default)]
+ pub struct FileSet {
+ files: HashMap<String, u32>,
+ pub paths: HashMap<u32, String>,
+ }
+
+ pub struct Color {
+ pub r: u8,
+ pub g: u8,
+ b: u8,
+ }
+
+ pub struct Point(i32, pub i32);
+
+ pub struct Visibility {
+ r#pub: bool,
+ pub pos: u32,
+ }
+
+ // Don't lint on empty structs;
+ pub struct Empty1;
+ pub struct Empty2();
+ pub struct Empty3 {};
+
+ // Don't lint on structs with one field.
+ pub struct Single1(i32);
+ pub struct Single2(pub i32);
+ pub struct Single3 {
+ v1: i32,
+ }
+ pub struct Single4 {
+ pub v1: i32,
+ }
+}
diff --git a/src/tools/clippy/tests/ui/partial_pub_fields.stderr b/src/tools/clippy/tests/ui/partial_pub_fields.stderr
new file mode 100644
index 000000000..84cfc1a91
--- /dev/null
+++ b/src/tools/clippy/tests/ui/partial_pub_fields.stderr
@@ -0,0 +1,35 @@
+error: mixed usage of pub and non-pub fields
+ --> $DIR/partial_pub_fields.rs:10:9
+ |
+LL | pub paths: HashMap<u32, String>,
+ | ^^^
+ |
+ = help: consider using private field here
+ = note: `-D clippy::partial-pub-fields` implied by `-D warnings`
+
+error: mixed usage of pub and non-pub fields
+ --> $DIR/partial_pub_fields.rs:16:9
+ |
+LL | b: u8,
+ | ^
+ |
+ = help: consider using public field here
+
+error: mixed usage of pub and non-pub fields
+ --> $DIR/partial_pub_fields.rs:19:27
+ |
+LL | pub struct Point(i32, pub i32);
+ | ^^^
+ |
+ = help: consider using private field here
+
+error: mixed usage of pub and non-pub fields
+ --> $DIR/partial_pub_fields.rs:23:9
+ |
+LL | pub pos: u32,
+ | ^^^
+ |
+ = help: consider using private field here
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/mutability.stderr b/src/tools/clippy/tests/ui/pattern_type_mismatch/mutability.stderr
index 3421d5683..87fb243b6 100644
--- a/src/tools/clippy/tests/ui/pattern_type_mismatch/mutability.stderr
+++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/mutability.stderr
@@ -4,8 +4,8 @@ error: type of pattern does not match the expression type
LL | Some(_) => (),
| ^^^^^^^
|
- = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings`
= help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings
+ = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings`
error: type of pattern does not match the expression type
--> $DIR/mutability.rs:15:9
diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr
index d285c9378..a91b5ac6c 100644
--- a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr
+++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.stderr
@@ -4,8 +4,8 @@ error: type of pattern does not match the expression type
LL | if let Value::B | Value::A(_) = ref_value {}
| ^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings`
= help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings
+ = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings`
error: type of pattern does not match the expression type
--> $DIR/pattern_alternatives.rs:16:34
diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_structs.stderr b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_structs.stderr
index d428e85b0..8bc5c63ba 100644
--- a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_structs.stderr
+++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_structs.stderr
@@ -4,8 +4,8 @@ error: type of pattern does not match the expression type
LL | let Struct { .. } = ref_value;
| ^^^^^^^^^^^^^
|
- = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings`
= help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings
+ = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings`
error: type of pattern does not match the expression type
--> $DIR/pattern_structs.rs:14:33
diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_tuples.stderr b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_tuples.stderr
index edd0074d0..a1ef540d2 100644
--- a/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_tuples.stderr
+++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_tuples.stderr
@@ -4,8 +4,8 @@ error: type of pattern does not match the expression type
LL | let TupleStruct(_) = ref_value;
| ^^^^^^^^^^^^^^
|
- = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings`
= help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings
+ = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings`
error: type of pattern does not match the expression type
--> $DIR/pattern_tuples.rs:12:25
diff --git a/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.stderr b/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.stderr
index 12b3d3a8b..f56a3a893 100644
--- a/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.stderr
+++ b/src/tools/clippy/tests/ui/pattern_type_mismatch/syntax.stderr
@@ -4,8 +4,8 @@ error: type of pattern does not match the expression type
LL | Some(_) => (),
| ^^^^^^^
|
- = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings`
= help: use `*` to dereference the match expression or explicitly match against a `&_` pattern and adjust the enclosed variable bindings
+ = note: `-D clippy::pattern-type-mismatch` implied by `-D warnings`
error: type of pattern does not match the expression type
--> $DIR/syntax.rs:30:12
diff --git a/src/tools/clippy/tests/ui/patterns.fixed b/src/tools/clippy/tests/ui/patterns.fixed
index f22388154..cd6901432 100644
--- a/src/tools/clippy/tests/ui/patterns.fixed
+++ b/src/tools/clippy/tests/ui/patterns.fixed
@@ -1,6 +1,7 @@
// run-rustfix
-#![allow(unused)]
#![warn(clippy::all)]
+#![allow(unused)]
+#![allow(clippy::uninlined_format_args)]
fn main() {
let v = Some(true);
diff --git a/src/tools/clippy/tests/ui/patterns.rs b/src/tools/clippy/tests/ui/patterns.rs
index 5848ecd38..9128da420 100644
--- a/src/tools/clippy/tests/ui/patterns.rs
+++ b/src/tools/clippy/tests/ui/patterns.rs
@@ -1,6 +1,7 @@
// run-rustfix
-#![allow(unused)]
#![warn(clippy::all)]
+#![allow(unused)]
+#![allow(clippy::uninlined_format_args)]
fn main() {
let v = Some(true);
diff --git a/src/tools/clippy/tests/ui/patterns.stderr b/src/tools/clippy/tests/ui/patterns.stderr
index af0675806..2c46b4eb5 100644
--- a/src/tools/clippy/tests/ui/patterns.stderr
+++ b/src/tools/clippy/tests/ui/patterns.stderr
@@ -1,5 +1,5 @@
error: the `y @ _` pattern can be written as just `y`
- --> $DIR/patterns.rs:10:9
+ --> $DIR/patterns.rs:11:9
|
LL | y @ _ => (),
| ^^^^^ help: try: `y`
@@ -7,13 +7,13 @@ LL | y @ _ => (),
= note: `-D clippy::redundant-pattern` implied by `-D warnings`
error: the `x @ _` pattern can be written as just `x`
- --> $DIR/patterns.rs:25:9
+ --> $DIR/patterns.rs:26:9
|
LL | ref mut x @ _ => {
| ^^^^^^^^^^^^^ help: try: `ref mut x`
error: the `x @ _` pattern can be written as just `x`
- --> $DIR/patterns.rs:33:9
+ --> $DIR/patterns.rs:34:9
|
LL | ref x @ _ => println!("vec: {:?}", x),
| ^^^^^^^^^ help: try: `ref x`
diff --git a/src/tools/clippy/tests/ui/positional_named_format_parameters.fixed b/src/tools/clippy/tests/ui/positional_named_format_parameters.fixed
deleted file mode 100644
index 4170e1098..000000000
--- a/src/tools/clippy/tests/ui/positional_named_format_parameters.fixed
+++ /dev/null
@@ -1,56 +0,0 @@
-// run-rustfix
-#![allow(unused_must_use)]
-#![allow(named_arguments_used_positionally)] // Unstable at time of writing.
-#![warn(clippy::positional_named_format_parameters)]
-
-use std::io::Write;
-
-fn main() {
- let mut v = Vec::new();
- let hello = "Hello";
-
- println!("{hello:.foo$}", foo = 2);
- writeln!(v, "{hello:.foo$}", foo = 2);
-
- // Warnings
- println!("{zero} {one:?}", zero = 0, one = 1);
- println!("This is a test {zero} {one:?}", zero = 0, one = 1);
- println!("Hello {one} is {two:.zero$}", zero = 5, one = hello, two = 0.01);
- println!("Hello {one:zero$}!", zero = 5, one = 1);
- println!("Hello {zero:one$}!", zero = 4, one = 1);
- println!("Hello {zero:0one$}!", zero = 4, one = 1);
- println!("Hello is {one:.zero$}", zero = 5, one = 0.01);
- println!("Hello is {one:<6.zero$}", zero = 5, one = 0.01);
- println!("{zero}, `{two:>8.one$}` has 3", zero = hello, one = 3, two = hello);
- println!("Hello {one} is {two:.zero$}", zero = 5, one = hello, two = 0.01);
- println!("Hello {world} {world}!", world = 5);
-
- writeln!(v, "{zero} {one:?}", zero = 0, one = 1);
- writeln!(v, "This is a test {zero} {one:?}", zero = 0, one = 1);
- writeln!(v, "Hello {one} is {two:.zero$}", zero = 5, one = hello, two = 0.01);
- writeln!(v, "Hello {one:zero$}!", zero = 4, one = 1);
- writeln!(v, "Hello {zero:one$}!", zero = 4, one = 1);
- writeln!(v, "Hello {zero:0one$}!", zero = 4, one = 1);
- writeln!(v, "Hello is {one:.zero$}", zero = 3, one = 0.01);
- writeln!(v, "Hello is {one:<6.zero$}", zero = 2, one = 0.01);
- writeln!(v, "{zero}, `{two:>8.one$}` has 3", zero = hello, one = 3, two = hello);
- writeln!(v, "Hello {one} is {two:.zero$}", zero = 1, one = hello, two = 0.01);
- writeln!(v, "Hello {world} {world}!", world = 0);
-
- // Tests from other files
- println!("{w:w$}", w = 1);
- println!("{p:.p$}", p = 1);
- println!("{v}", v = 1);
- println!("{v:v$}", v = 1);
- println!("{v:v$}", v = 1);
- println!("{v:v$.v$}", v = 1);
- println!("{v:v$.v$}", v = 1);
- println!("{v:v$.v$}", v = 1);
- println!("{v:v$.v$}", v = 1);
- println!("{v:v$.v$}", v = 1);
- println!("{v:v$.v$}", v = 1);
- println!("{v:v$.v$}", v = 1);
- println!("{w:w$}", w = 1);
- println!("{p:.p$}", p = 1);
- println!("{:p$.w$}", 1, w = 1, p = 1);
-}
diff --git a/src/tools/clippy/tests/ui/positional_named_format_parameters.rs b/src/tools/clippy/tests/ui/positional_named_format_parameters.rs
deleted file mode 100644
index 553d8494e..000000000
--- a/src/tools/clippy/tests/ui/positional_named_format_parameters.rs
+++ /dev/null
@@ -1,56 +0,0 @@
-// run-rustfix
-#![allow(unused_must_use)]
-#![allow(named_arguments_used_positionally)] // Unstable at time of writing.
-#![warn(clippy::positional_named_format_parameters)]
-
-use std::io::Write;
-
-fn main() {
- let mut v = Vec::new();
- let hello = "Hello";
-
- println!("{hello:.foo$}", foo = 2);
- writeln!(v, "{hello:.foo$}", foo = 2);
-
- // Warnings
- println!("{} {1:?}", zero = 0, one = 1);
- println!("This is a test { } {000001:?}", zero = 0, one = 1);
- println!("Hello {1} is {2:.0$}", zero = 5, one = hello, two = 0.01);
- println!("Hello {1:0$}!", zero = 5, one = 1);
- println!("Hello {0:1$}!", zero = 4, one = 1);
- println!("Hello {0:01$}!", zero = 4, one = 1);
- println!("Hello is {1:.*}", zero = 5, one = 0.01);
- println!("Hello is {:<6.*}", zero = 5, one = 0.01);
- println!("{}, `{two:>8.*}` has 3", zero = hello, one = 3, two = hello);
- println!("Hello {1} is {2:.0$}", zero = 5, one = hello, two = 0.01);
- println!("Hello {world} {}!", world = 5);
-
- writeln!(v, "{} {1:?}", zero = 0, one = 1);
- writeln!(v, "This is a test { } {000001:?}", zero = 0, one = 1);
- writeln!(v, "Hello {1} is {2:.0$}", zero = 5, one = hello, two = 0.01);
- writeln!(v, "Hello {1:0$}!", zero = 4, one = 1);
- writeln!(v, "Hello {0:1$}!", zero = 4, one = 1);
- writeln!(v, "Hello {0:01$}!", zero = 4, one = 1);
- writeln!(v, "Hello is {1:.*}", zero = 3, one = 0.01);
- writeln!(v, "Hello is {:<6.*}", zero = 2, one = 0.01);
- writeln!(v, "{}, `{two:>8.*}` has 3", zero = hello, one = 3, two = hello);
- writeln!(v, "Hello {1} is {2:.0$}", zero = 1, one = hello, two = 0.01);
- writeln!(v, "Hello {world} {}!", world = 0);
-
- // Tests from other files
- println!("{:w$}", w = 1);
- println!("{:.p$}", p = 1);
- println!("{}", v = 1);
- println!("{:0$}", v = 1);
- println!("{0:0$}", v = 1);
- println!("{:0$.0$}", v = 1);
- println!("{0:0$.0$}", v = 1);
- println!("{0:0$.v$}", v = 1);
- println!("{0:v$.0$}", v = 1);
- println!("{v:0$.0$}", v = 1);
- println!("{v:v$.0$}", v = 1);
- println!("{v:0$.v$}", v = 1);
- println!("{:w$}", w = 1);
- println!("{:.p$}", p = 1);
- println!("{:p$.w$}", 1, w = 1, p = 1);
-}
diff --git a/src/tools/clippy/tests/ui/positional_named_format_parameters.stderr b/src/tools/clippy/tests/ui/positional_named_format_parameters.stderr
deleted file mode 100644
index 48ddb6d67..000000000
--- a/src/tools/clippy/tests/ui/positional_named_format_parameters.stderr
+++ /dev/null
@@ -1,418 +0,0 @@
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:16:16
- |
-LL | println!("{} {1:?}", zero = 0, one = 1);
- | ^ help: replace it with: `zero`
- |
- = note: `-D clippy::positional-named-format-parameters` implied by `-D warnings`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:16:19
- |
-LL | println!("{} {1:?}", zero = 0, one = 1);
- | ^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:17:31
- |
-LL | println!("This is a test { } {000001:?}", zero = 0, one = 1);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:17:35
- |
-LL | println!("This is a test { } {000001:?}", zero = 0, one = 1);
- | ^^^^^^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:18:32
- |
-LL | println!("Hello {1} is {2:.0$}", zero = 5, one = hello, two = 0.01);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:18:22
- |
-LL | println!("Hello {1} is {2:.0$}", zero = 5, one = hello, two = 0.01);
- | ^ help: replace it with: `one`
-
-error: named parameter two is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:18:29
- |
-LL | println!("Hello {1} is {2:.0$}", zero = 5, one = hello, two = 0.01);
- | ^ help: replace it with: `two`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:19:24
- |
-LL | println!("Hello {1:0$}!", zero = 5, one = 1);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:19:22
- |
-LL | println!("Hello {1:0$}!", zero = 5, one = 1);
- | ^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:20:22
- |
-LL | println!("Hello {0:1$}!", zero = 4, one = 1);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:20:24
- |
-LL | println!("Hello {0:1$}!", zero = 4, one = 1);
- | ^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:21:22
- |
-LL | println!("Hello {0:01$}!", zero = 4, one = 1);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:21:25
- |
-LL | println!("Hello {0:01$}!", zero = 4, one = 1);
- | ^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:22:28
- |
-LL | println!("Hello is {1:.*}", zero = 5, one = 0.01);
- | ^ help: replace it with: `zero$`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:22:25
- |
-LL | println!("Hello is {1:.*}", zero = 5, one = 0.01);
- | ^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:23:29
- |
-LL | println!("Hello is {:<6.*}", zero = 5, one = 0.01);
- | ^ help: replace it with: `zero$`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:23:25
- |
-LL | println!("Hello is {:<6.*}", zero = 5, one = 0.01);
- | ^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:24:16
- |
-LL | println!("{}, `{two:>8.*}` has 3", zero = hello, one = 3, two = hello);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:24:28
- |
-LL | println!("{}, `{two:>8.*}` has 3", zero = hello, one = 3, two = hello);
- | ^ help: replace it with: `one$`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:25:32
- |
-LL | println!("Hello {1} is {2:.0$}", zero = 5, one = hello, two = 0.01);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:25:22
- |
-LL | println!("Hello {1} is {2:.0$}", zero = 5, one = hello, two = 0.01);
- | ^ help: replace it with: `one`
-
-error: named parameter two is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:25:29
- |
-LL | println!("Hello {1} is {2:.0$}", zero = 5, one = hello, two = 0.01);
- | ^ help: replace it with: `two`
-
-error: named parameter world is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:26:30
- |
-LL | println!("Hello {world} {}!", world = 5);
- | ^ help: replace it with: `world`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:28:19
- |
-LL | writeln!(v, "{} {1:?}", zero = 0, one = 1);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:28:22
- |
-LL | writeln!(v, "{} {1:?}", zero = 0, one = 1);
- | ^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:29:34
- |
-LL | writeln!(v, "This is a test { } {000001:?}", zero = 0, one = 1);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:29:38
- |
-LL | writeln!(v, "This is a test { } {000001:?}", zero = 0, one = 1);
- | ^^^^^^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:30:35
- |
-LL | writeln!(v, "Hello {1} is {2:.0$}", zero = 5, one = hello, two = 0.01);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:30:25
- |
-LL | writeln!(v, "Hello {1} is {2:.0$}", zero = 5, one = hello, two = 0.01);
- | ^ help: replace it with: `one`
-
-error: named parameter two is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:30:32
- |
-LL | writeln!(v, "Hello {1} is {2:.0$}", zero = 5, one = hello, two = 0.01);
- | ^ help: replace it with: `two`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:31:27
- |
-LL | writeln!(v, "Hello {1:0$}!", zero = 4, one = 1);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:31:25
- |
-LL | writeln!(v, "Hello {1:0$}!", zero = 4, one = 1);
- | ^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:32:25
- |
-LL | writeln!(v, "Hello {0:1$}!", zero = 4, one = 1);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:32:27
- |
-LL | writeln!(v, "Hello {0:1$}!", zero = 4, one = 1);
- | ^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:33:25
- |
-LL | writeln!(v, "Hello {0:01$}!", zero = 4, one = 1);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:33:28
- |
-LL | writeln!(v, "Hello {0:01$}!", zero = 4, one = 1);
- | ^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:34:31
- |
-LL | writeln!(v, "Hello is {1:.*}", zero = 3, one = 0.01);
- | ^ help: replace it with: `zero$`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:34:28
- |
-LL | writeln!(v, "Hello is {1:.*}", zero = 3, one = 0.01);
- | ^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:35:32
- |
-LL | writeln!(v, "Hello is {:<6.*}", zero = 2, one = 0.01);
- | ^ help: replace it with: `zero$`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:35:28
- |
-LL | writeln!(v, "Hello is {:<6.*}", zero = 2, one = 0.01);
- | ^ help: replace it with: `one`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:36:19
- |
-LL | writeln!(v, "{}, `{two:>8.*}` has 3", zero = hello, one = 3, two = hello);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:36:31
- |
-LL | writeln!(v, "{}, `{two:>8.*}` has 3", zero = hello, one = 3, two = hello);
- | ^ help: replace it with: `one$`
-
-error: named parameter zero is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:37:35
- |
-LL | writeln!(v, "Hello {1} is {2:.0$}", zero = 1, one = hello, two = 0.01);
- | ^ help: replace it with: `zero`
-
-error: named parameter one is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:37:25
- |
-LL | writeln!(v, "Hello {1} is {2:.0$}", zero = 1, one = hello, two = 0.01);
- | ^ help: replace it with: `one`
-
-error: named parameter two is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:37:32
- |
-LL | writeln!(v, "Hello {1} is {2:.0$}", zero = 1, one = hello, two = 0.01);
- | ^ help: replace it with: `two`
-
-error: named parameter world is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:38:33
- |
-LL | writeln!(v, "Hello {world} {}!", world = 0);
- | ^ help: replace it with: `world`
-
-error: named parameter w is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:41:16
- |
-LL | println!("{:w$}", w = 1);
- | ^ help: replace it with: `w`
-
-error: named parameter p is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:42:16
- |
-LL | println!("{:.p$}", p = 1);
- | ^ help: replace it with: `p`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:43:16
- |
-LL | println!("{}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:44:16
- |
-LL | println!("{:0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:44:17
- |
-LL | println!("{:0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:45:16
- |
-LL | println!("{0:0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:45:18
- |
-LL | println!("{0:0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:46:16
- |
-LL | println!("{:0$.0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:46:20
- |
-LL | println!("{:0$.0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:46:17
- |
-LL | println!("{:0$.0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:47:16
- |
-LL | println!("{0:0$.0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:47:21
- |
-LL | println!("{0:0$.0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:47:18
- |
-LL | println!("{0:0$.0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:48:16
- |
-LL | println!("{0:0$.v$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:48:18
- |
-LL | println!("{0:0$.v$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:49:16
- |
-LL | println!("{0:v$.0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:49:21
- |
-LL | println!("{0:v$.0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:50:21
- |
-LL | println!("{v:0$.0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:50:18
- |
-LL | println!("{v:0$.0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:51:21
- |
-LL | println!("{v:v$.0$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter v is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:52:18
- |
-LL | println!("{v:0$.v$}", v = 1);
- | ^ help: replace it with: `v`
-
-error: named parameter w is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:53:16
- |
-LL | println!("{:w$}", w = 1);
- | ^ help: replace it with: `w`
-
-error: named parameter p is used as a positional parameter
- --> $DIR/positional_named_format_parameters.rs:54:16
- |
-LL | println!("{:.p$}", p = 1);
- | ^ help: replace it with: `p`
-
-error: aborting due to 69 previous errors
-
diff --git a/src/tools/clippy/tests/ui/print_literal.rs b/src/tools/clippy/tests/ui/print_literal.rs
index 8665a3bb2..86f908f66 100644
--- a/src/tools/clippy/tests/ui/print_literal.rs
+++ b/src/tools/clippy/tests/ui/print_literal.rs
@@ -1,4 +1,5 @@
#![warn(clippy::print_literal)]
+#![allow(clippy::uninlined_format_args)]
fn main() {
// these should be fine
@@ -20,11 +21,13 @@ fn main() {
println!("{} of {:b} people know binary, the other half doesn't", 1, 2);
println!("10 / 4 is {}", 2.5);
println!("2 + 1 = {}", 3);
+ println!("From expansion {}", stringify!(not a string literal));
// these should throw warnings
print!("Hello {}", "world");
println!("Hello {} {}", world, "world");
println!("Hello {}", "world");
+ println!("{} {:.4}", "a literal", 5);
// positional args don't change the fact
// that we're using a literal -- this should
diff --git a/src/tools/clippy/tests/ui/print_literal.stderr b/src/tools/clippy/tests/ui/print_literal.stderr
index 72aae0756..6404dacda 100644
--- a/src/tools/clippy/tests/ui/print_literal.stderr
+++ b/src/tools/clippy/tests/ui/print_literal.stderr
@@ -1,5 +1,5 @@
error: literal with an empty format string
- --> $DIR/print_literal.rs:25:24
+ --> $DIR/print_literal.rs:27:24
|
LL | print!("Hello {}", "world");
| ^^^^^^^
@@ -12,7 +12,7 @@ LL + print!("Hello world");
|
error: literal with an empty format string
- --> $DIR/print_literal.rs:26:36
+ --> $DIR/print_literal.rs:28:36
|
LL | println!("Hello {} {}", world, "world");
| ^^^^^^^
@@ -24,7 +24,7 @@ LL + println!("Hello {} world", world);
|
error: literal with an empty format string
- --> $DIR/print_literal.rs:27:26
+ --> $DIR/print_literal.rs:29:26
|
LL | println!("Hello {}", "world");
| ^^^^^^^
@@ -36,7 +36,19 @@ LL + println!("Hello world");
|
error: literal with an empty format string
- --> $DIR/print_literal.rs:32:25
+ --> $DIR/print_literal.rs:30:26
+ |
+LL | println!("{} {:.4}", "a literal", 5);
+ | ^^^^^^^^^^^
+ |
+help: try this
+ |
+LL - println!("{} {:.4}", "a literal", 5);
+LL + println!("a literal {:.4}", 5);
+ |
+
+error: literal with an empty format string
+ --> $DIR/print_literal.rs:35:25
|
LL | println!("{0} {1}", "hello", "world");
| ^^^^^^^
@@ -48,7 +60,7 @@ LL + println!("hello {1}", "world");
|
error: literal with an empty format string
- --> $DIR/print_literal.rs:32:34
+ --> $DIR/print_literal.rs:35:34
|
LL | println!("{0} {1}", "hello", "world");
| ^^^^^^^
@@ -60,34 +72,34 @@ LL + println!("{0} world", "hello");
|
error: literal with an empty format string
- --> $DIR/print_literal.rs:33:25
+ --> $DIR/print_literal.rs:36:34
|
LL | println!("{1} {0}", "hello", "world");
- | ^^^^^^^
+ | ^^^^^^^
|
help: try this
|
LL - println!("{1} {0}", "hello", "world");
-LL + println!("{1} hello", "world");
+LL + println!("world {0}", "hello");
|
error: literal with an empty format string
- --> $DIR/print_literal.rs:33:34
+ --> $DIR/print_literal.rs:36:25
|
LL | println!("{1} {0}", "hello", "world");
- | ^^^^^^^
+ | ^^^^^^^
|
help: try this
|
LL - println!("{1} {0}", "hello", "world");
-LL + println!("world {0}", "hello");
+LL + println!("{1} hello", "world");
|
error: literal with an empty format string
- --> $DIR/print_literal.rs:36:29
+ --> $DIR/print_literal.rs:39:35
|
LL | println!("{foo} {bar}", foo = "hello", bar = "world");
- | ^^^^^^^^^^^^^
+ | ^^^^^^^
|
help: try this
|
@@ -96,10 +108,10 @@ LL + println!("hello {bar}", bar = "world");
|
error: literal with an empty format string
- --> $DIR/print_literal.rs:36:44
+ --> $DIR/print_literal.rs:39:50
|
LL | println!("{foo} {bar}", foo = "hello", bar = "world");
- | ^^^^^^^^^^^^^
+ | ^^^^^^^
|
help: try this
|
@@ -108,28 +120,28 @@ LL + println!("{foo} world", foo = "hello");
|
error: literal with an empty format string
- --> $DIR/print_literal.rs:37:29
+ --> $DIR/print_literal.rs:40:50
|
LL | println!("{bar} {foo}", foo = "hello", bar = "world");
- | ^^^^^^^^^^^^^
+ | ^^^^^^^
|
help: try this
|
LL - println!("{bar} {foo}", foo = "hello", bar = "world");
-LL + println!("{bar} hello", bar = "world");
+LL + println!("world {foo}", foo = "hello");
|
error: literal with an empty format string
- --> $DIR/print_literal.rs:37:44
+ --> $DIR/print_literal.rs:40:35
|
LL | println!("{bar} {foo}", foo = "hello", bar = "world");
- | ^^^^^^^^^^^^^
+ | ^^^^^^^
|
help: try this
|
LL - println!("{bar} {foo}", foo = "hello", bar = "world");
-LL + println!("world {foo}", foo = "hello");
+LL + println!("{bar} hello", bar = "world");
|
-error: aborting due to 11 previous errors
+error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/print_with_newline.rs b/src/tools/clippy/tests/ui/print_with_newline.rs
index a43a1fc4f..b8c29d207 100644
--- a/src/tools/clippy/tests/ui/print_with_newline.rs
+++ b/src/tools/clippy/tests/ui/print_with_newline.rs
@@ -48,5 +48,13 @@ fn main() {
print!("\r\n");
print!("foo\r\n");
print!("\\r\n"); //~ ERROR
- print!("foo\rbar\n") // ~ ERROR
+ print!("foo\rbar\n");
+
+ // Ignore expanded format strings
+ macro_rules! newline {
+ () => {
+ "\n"
+ };
+ }
+ print!(newline!());
}
diff --git a/src/tools/clippy/tests/ui/print_with_newline.stderr b/src/tools/clippy/tests/ui/print_with_newline.stderr
index edbaa1cdf..b9f5675fa 100644
--- a/src/tools/clippy/tests/ui/print_with_newline.stderr
+++ b/src/tools/clippy/tests/ui/print_with_newline.stderr
@@ -83,7 +83,7 @@ LL | | );
help: use `println!` instead
|
LL ~ println!(
-LL ~ ""
+LL ~
|
error: using `print!()` with a format string that ends in a single newline
@@ -98,7 +98,7 @@ LL | | );
help: use `println!` instead
|
LL ~ println!(
-LL ~ r""
+LL ~
|
error: using `print!()` with a format string that ends in a single newline
@@ -113,17 +113,5 @@ LL - print!("/r/n"); //~ ERROR
LL + println!("/r"); //~ ERROR
|
-error: using `print!()` with a format string that ends in a single newline
- --> $DIR/print_with_newline.rs:51:5
- |
-LL | print!("foo/rbar/n") // ~ ERROR
- | ^^^^^^^^^^^^^^^^^^^^
- |
-help: use `println!` instead
- |
-LL - print!("foo/rbar/n") // ~ ERROR
-LL + println!("foo/rbar") // ~ ERROR
- |
-
-error: aborting due to 10 previous errors
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/println_empty_string.stderr b/src/tools/clippy/tests/ui/println_empty_string.stderr
index 17fe4ea74..3cc8bb947 100644
--- a/src/tools/clippy/tests/ui/println_empty_string.stderr
+++ b/src/tools/clippy/tests/ui/println_empty_string.stderr
@@ -1,28 +1,36 @@
-error: using `println!("")`
+error: empty string literal in `println!`
--> $DIR/println_empty_string.rs:6:5
|
LL | println!("");
- | ^^^^^^^^^^^^ help: replace it with: `println!()`
+ | ^^^^^^^^^--^
+ | |
+ | help: remove the empty string
|
= note: `-D clippy::println-empty-string` implied by `-D warnings`
-error: using `println!("")`
+error: empty string literal in `println!`
--> $DIR/println_empty_string.rs:9:14
|
LL | _ => println!(""),
- | ^^^^^^^^^^^^ help: replace it with: `println!()`
+ | ^^^^^^^^^--^
+ | |
+ | help: remove the empty string
-error: using `eprintln!("")`
+error: empty string literal in `eprintln!`
--> $DIR/println_empty_string.rs:13:5
|
LL | eprintln!("");
- | ^^^^^^^^^^^^^ help: replace it with: `eprintln!()`
+ | ^^^^^^^^^^--^
+ | |
+ | help: remove the empty string
-error: using `eprintln!("")`
+error: empty string literal in `eprintln!`
--> $DIR/println_empty_string.rs:16:14
|
LL | _ => eprintln!(""),
- | ^^^^^^^^^^^^^ help: replace it with: `eprintln!()`
+ | ^^^^^^^^^^--^
+ | |
+ | help: remove the empty string
error: aborting due to 4 previous errors
diff --git a/src/tools/clippy/tests/ui/proc_macro.stderr b/src/tools/clippy/tests/ui/proc_macro.stderr
index 48fd58c9a..c795f6ad0 100644
--- a/src/tools/clippy/tests/ui/proc_macro.stderr
+++ b/src/tools/clippy/tests/ui/proc_macro.stderr
@@ -4,8 +4,8 @@ error: approximate value of `f{32, 64}::consts::PI` found
LL | let _x = 3.14;
| ^^^^
|
- = note: `#[deny(clippy::approx_constant)]` on by default
= help: consider using the constant directly
+ = note: `#[deny(clippy::approx_constant)]` on by default
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/ptr_arg.rs b/src/tools/clippy/tests/ui/ptr_arg.rs
index fd15001e5..5f54101ca 100644
--- a/src/tools/clippy/tests/ui/ptr_arg.rs
+++ b/src/tools/clippy/tests/ui/ptr_arg.rs
@@ -3,7 +3,7 @@
#![warn(clippy::ptr_arg)]
use std::borrow::Cow;
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
fn do_vec(x: &Vec<i64>) {
//Nothing here
@@ -207,3 +207,31 @@ fn cow_conditional_to_mut(a: &mut Cow<str>) {
a.to_mut().push_str("foo");
}
}
+
+// Issue #9542
+fn dyn_trait_ok(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
+ trait T {}
+ impl<U> T for Vec<U> {}
+ impl T for String {}
+ impl T for PathBuf {}
+ fn takes_dyn(_: &mut dyn T) {}
+
+ takes_dyn(a);
+ takes_dyn(b);
+ takes_dyn(c);
+}
+
+fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
+ trait T {}
+ impl<U> T for Vec<U> {}
+ impl<U> T for [U] {}
+ impl T for String {}
+ impl T for str {}
+ impl T for PathBuf {}
+ impl T for Path {}
+ fn takes_dyn(_: &mut dyn T) {}
+
+ takes_dyn(a);
+ takes_dyn(b);
+ takes_dyn(c);
+}
diff --git a/src/tools/clippy/tests/ui/ptr_arg.stderr b/src/tools/clippy/tests/ui/ptr_arg.stderr
index d64b5f454..6b4de98ce 100644
--- a/src/tools/clippy/tests/ui/ptr_arg.stderr
+++ b/src/tools/clippy/tests/ui/ptr_arg.stderr
@@ -162,5 +162,23 @@ error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a sl
LL | fn mut_vec_slice_methods(v: &mut Vec<u32>) {
| ^^^^^^^^^^^^^ help: change this to: `&mut [u32]`
-error: aborting due to 17 previous errors
+error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
+ --> $DIR/ptr_arg.rs:224:17
+ |
+LL | fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
+ | ^^^^^^^^^^^^^ help: change this to: `&mut [u32]`
+
+error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do
+ --> $DIR/ptr_arg.rs:224:35
+ |
+LL | fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
+ | ^^^^^^^^^^^ help: change this to: `&mut str`
+
+error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do
+ --> $DIR/ptr_arg.rs:224:51
+ |
+LL | fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
+ | ^^^^^^^^^^^^ help: change this to: `&mut Path`
+
+error: aborting due to 20 previous errors
diff --git a/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed b/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed
index 718e391e8..c57e2990f 100644
--- a/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed
+++ b/src/tools/clippy/tests/ui/ptr_offset_with_cast.fixed
@@ -1,4 +1,5 @@
// run-rustfix
+#![allow(clippy::unnecessary_cast)]
fn main() {
let vec = vec![b'a', b'b', b'c'];
diff --git a/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs b/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs
index f613742c7..3de7997ac 100644
--- a/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs
+++ b/src/tools/clippy/tests/ui/ptr_offset_with_cast.rs
@@ -1,4 +1,5 @@
// run-rustfix
+#![allow(clippy::unnecessary_cast)]
fn main() {
let vec = vec![b'a', b'b', b'c'];
diff --git a/src/tools/clippy/tests/ui/ptr_offset_with_cast.stderr b/src/tools/clippy/tests/ui/ptr_offset_with_cast.stderr
index fd45224ca..3ba40593d 100644
--- a/src/tools/clippy/tests/ui/ptr_offset_with_cast.stderr
+++ b/src/tools/clippy/tests/ui/ptr_offset_with_cast.stderr
@@ -1,5 +1,5 @@
error: use of `offset` with a `usize` casted to an `isize`
- --> $DIR/ptr_offset_with_cast.rs:12:17
+ --> $DIR/ptr_offset_with_cast.rs:13:17
|
LL | let _ = ptr.offset(offset_usize as isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.add(offset_usize)`
@@ -7,7 +7,7 @@ LL | let _ = ptr.offset(offset_usize as isize);
= note: `-D clippy::ptr-offset-with-cast` implied by `-D warnings`
error: use of `wrapping_offset` with a `usize` casted to an `isize`
- --> $DIR/ptr_offset_with_cast.rs:16:17
+ --> $DIR/ptr_offset_with_cast.rs:17:17
|
LL | let _ = ptr.wrapping_offset(offset_usize as isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.wrapping_add(offset_usize)`
diff --git a/src/tools/clippy/tests/ui/pub_use.stderr b/src/tools/clippy/tests/ui/pub_use.stderr
index 9ab710df8..ba4ee732c 100644
--- a/src/tools/clippy/tests/ui/pub_use.stderr
+++ b/src/tools/clippy/tests/ui/pub_use.stderr
@@ -4,8 +4,8 @@ error: using `pub use`
LL | pub use inner::Test;
| ^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::pub-use` implied by `-D warnings`
= help: move the exported item to a public module instead
+ = note: `-D clippy::pub-use` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/question_mark.fixed b/src/tools/clippy/tests/ui/question_mark.fixed
index 57f23bd19..993389232 100644
--- a/src/tools/clippy/tests/ui/question_mark.fixed
+++ b/src/tools/clippy/tests/ui/question_mark.fixed
@@ -223,3 +223,12 @@ fn pattern() -> Result<(), PatternedError> {
}
fn main() {}
+
+// should not lint, `?` operator not available in const context
+const fn issue9175(option: Option<()>) -> Option<()> {
+ if option.is_none() {
+ return None;
+ }
+ //stuff
+ Some(())
+}
diff --git a/src/tools/clippy/tests/ui/question_mark.rs b/src/tools/clippy/tests/ui/question_mark.rs
index 436f027c2..9ae0d8882 100644
--- a/src/tools/clippy/tests/ui/question_mark.rs
+++ b/src/tools/clippy/tests/ui/question_mark.rs
@@ -259,3 +259,12 @@ fn pattern() -> Result<(), PatternedError> {
}
fn main() {}
+
+// should not lint, `?` operator not available in const context
+const fn issue9175(option: Option<()>) -> Option<()> {
+ if option.is_none() {
+ return None;
+ }
+ //stuff
+ Some(())
+}
diff --git a/src/tools/clippy/tests/ui/range_contains.fixed b/src/tools/clippy/tests/ui/range_contains.fixed
index 85d021b2f..824f00cb9 100644
--- a/src/tools/clippy/tests/ui/range_contains.fixed
+++ b/src/tools/clippy/tests/ui/range_contains.fixed
@@ -1,10 +1,12 @@
// run-rustfix
-#[warn(clippy::manual_range_contains)]
-#[allow(unused)]
-#[allow(clippy::no_effect)]
-#[allow(clippy::short_circuit_statement)]
-#[allow(clippy::unnecessary_operation)]
+#![feature(custom_inner_attributes)]
+#![warn(clippy::manual_range_contains)]
+#![allow(unused)]
+#![allow(clippy::no_effect)]
+#![allow(clippy::short_circuit_statement)]
+#![allow(clippy::unnecessary_operation)]
+
fn main() {
let x = 9_i32;
@@ -62,3 +64,17 @@ fn main() {
pub const fn in_range(a: i32) -> bool {
3 <= a && a <= 20
}
+
+fn msrv_1_34() {
+ #![clippy::msrv = "1.34"]
+
+ let x = 5;
+ x >= 8 && x < 34;
+}
+
+fn msrv_1_35() {
+ #![clippy::msrv = "1.35"]
+
+ let x = 5;
+ (8..35).contains(&x);
+}
diff --git a/src/tools/clippy/tests/ui/range_contains.rs b/src/tools/clippy/tests/ui/range_contains.rs
index 9a7a75dc1..df925eead 100644
--- a/src/tools/clippy/tests/ui/range_contains.rs
+++ b/src/tools/clippy/tests/ui/range_contains.rs
@@ -1,10 +1,12 @@
// run-rustfix
-#[warn(clippy::manual_range_contains)]
-#[allow(unused)]
-#[allow(clippy::no_effect)]
-#[allow(clippy::short_circuit_statement)]
-#[allow(clippy::unnecessary_operation)]
+#![feature(custom_inner_attributes)]
+#![warn(clippy::manual_range_contains)]
+#![allow(unused)]
+#![allow(clippy::no_effect)]
+#![allow(clippy::short_circuit_statement)]
+#![allow(clippy::unnecessary_operation)]
+
fn main() {
let x = 9_i32;
@@ -62,3 +64,17 @@ fn main() {
pub const fn in_range(a: i32) -> bool {
3 <= a && a <= 20
}
+
+fn msrv_1_34() {
+ #![clippy::msrv = "1.34"]
+
+ let x = 5;
+ x >= 8 && x < 34;
+}
+
+fn msrv_1_35() {
+ #![clippy::msrv = "1.35"]
+
+ let x = 5;
+ x >= 8 && x < 35;
+}
diff --git a/src/tools/clippy/tests/ui/range_contains.stderr b/src/tools/clippy/tests/ui/range_contains.stderr
index 936859db5..9689e665b 100644
--- a/src/tools/clippy/tests/ui/range_contains.stderr
+++ b/src/tools/clippy/tests/ui/range_contains.stderr
@@ -1,5 +1,5 @@
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:12:5
+ --> $DIR/range_contains.rs:14:5
|
LL | x >= 8 && x < 12;
| ^^^^^^^^^^^^^^^^ help: use: `(8..12).contains(&x)`
@@ -7,118 +7,124 @@ LL | x >= 8 && x < 12;
= note: `-D clippy::manual-range-contains` implied by `-D warnings`
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:13:5
+ --> $DIR/range_contains.rs:15:5
|
LL | x < 42 && x >= 21;
| ^^^^^^^^^^^^^^^^^ help: use: `(21..42).contains(&x)`
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:14:5
+ --> $DIR/range_contains.rs:16:5
|
LL | 100 > x && 1 <= x;
| ^^^^^^^^^^^^^^^^^ help: use: `(1..100).contains(&x)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:17:5
+ --> $DIR/range_contains.rs:19:5
|
LL | x >= 9 && x <= 99;
| ^^^^^^^^^^^^^^^^^ help: use: `(9..=99).contains(&x)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:18:5
+ --> $DIR/range_contains.rs:20:5
|
LL | x <= 33 && x >= 1;
| ^^^^^^^^^^^^^^^^^ help: use: `(1..=33).contains(&x)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:19:5
+ --> $DIR/range_contains.rs:21:5
|
LL | 999 >= x && 1 <= x;
| ^^^^^^^^^^^^^^^^^^ help: use: `(1..=999).contains(&x)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:22:5
+ --> $DIR/range_contains.rs:24:5
|
LL | x < 8 || x >= 12;
| ^^^^^^^^^^^^^^^^ help: use: `!(8..12).contains(&x)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:23:5
+ --> $DIR/range_contains.rs:25:5
|
LL | x >= 42 || x < 21;
| ^^^^^^^^^^^^^^^^^ help: use: `!(21..42).contains(&x)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:24:5
+ --> $DIR/range_contains.rs:26:5
|
LL | 100 <= x || 1 > x;
| ^^^^^^^^^^^^^^^^^ help: use: `!(1..100).contains(&x)`
error: manual `!RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:27:5
+ --> $DIR/range_contains.rs:29:5
|
LL | x < 9 || x > 99;
| ^^^^^^^^^^^^^^^ help: use: `!(9..=99).contains(&x)`
error: manual `!RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:28:5
+ --> $DIR/range_contains.rs:30:5
|
LL | x > 33 || x < 1;
| ^^^^^^^^^^^^^^^ help: use: `!(1..=33).contains(&x)`
error: manual `!RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:29:5
+ --> $DIR/range_contains.rs:31:5
|
LL | 999 < x || 1 > x;
| ^^^^^^^^^^^^^^^^ help: use: `!(1..=999).contains(&x)`
error: manual `Range::contains` implementation
- --> $DIR/range_contains.rs:44:5
+ --> $DIR/range_contains.rs:46:5
|
LL | y >= 0. && y < 1.;
| ^^^^^^^^^^^^^^^^^ help: use: `(0. ..1.).contains(&y)`
error: manual `!RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:45:5
+ --> $DIR/range_contains.rs:47:5
|
LL | y < 0. || y > 1.;
| ^^^^^^^^^^^^^^^^ help: use: `!(0. ..=1.).contains(&y)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:48:5
+ --> $DIR/range_contains.rs:50:5
|
LL | x >= -10 && x <= 10;
| ^^^^^^^^^^^^^^^^^^^ help: use: `(-10..=10).contains(&x)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:50:5
+ --> $DIR/range_contains.rs:52:5
|
LL | y >= -3. && y <= 3.;
| ^^^^^^^^^^^^^^^^^^^ help: use: `(-3. ..=3.).contains(&y)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:55:30
+ --> $DIR/range_contains.rs:57:30
|
LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10);
| ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&z)`
error: manual `RangeInclusive::contains` implementation
- --> $DIR/range_contains.rs:55:5
+ --> $DIR/range_contains.rs:57:5
|
LL | (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10);
| ^^^^^^^^^^^^^^^^^^^^^ help: use: `(0..=10).contains(&x)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:56:29
+ --> $DIR/range_contains.rs:58:29
|
LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10);
| ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&z)`
error: manual `!Range::contains` implementation
- --> $DIR/range_contains.rs:56:5
+ --> $DIR/range_contains.rs:58:5
|
LL | (x < 0) || (x >= 10) || (z < 0) || (z >= 10);
| ^^^^^^^^^^^^^^^^^^^^ help: use: `!(0..10).contains(&x)`
-error: aborting due to 20 previous errors
+error: manual `Range::contains` implementation
+ --> $DIR/range_contains.rs:79:5
+ |
+LL | x >= 8 && x < 35;
+ | ^^^^^^^^^^^^^^^^ help: use: `(8..35).contains(&x)`
+
+error: aborting due to 21 previous errors
diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr
index cd7d91e12..7814f5b54 100644
--- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr
+++ b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/arc.stderr
@@ -4,8 +4,8 @@ error: initializing a reference-counted pointer in `vec![elem; len]`
LL | let v = vec![Arc::new("x".to_string()); 2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings`
= note: each element will point to the same `Arc` instance
+ = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings`
help: consider initializing each `Arc` element individually
|
LL ~ let v = {
diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr
index fe861afe0..80deb7cb9 100644
--- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr
+++ b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/rc.stderr
@@ -4,8 +4,8 @@ error: initializing a reference-counted pointer in `vec![elem; len]`
LL | let v = vec![Rc::new("x".to_string()); 2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings`
= note: each element will point to the same `Rc` instance
+ = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings`
help: consider initializing each `Rc` element individually
|
LL ~ let v = {
diff --git a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr
index 4a21946cc..789e14a30 100644
--- a/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr
+++ b/src/tools/clippy/tests/ui/rc_clone_in_vec_init/weak.stderr
@@ -4,8 +4,8 @@ error: initializing a reference-counted pointer in `vec![elem; len]`
LL | let v = vec![SyncWeak::<u32>::new(); 2];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings`
= note: each element will point to the same `Weak` instance
+ = note: `-D clippy::rc-clone-in-vec-init` implied by `-D warnings`
help: consider initializing each `Weak` element individually
|
LL ~ let v = {
diff --git a/src/tools/clippy/tests/ui/rc_mutex.stderr b/src/tools/clippy/tests/ui/rc_mutex.stderr
index fe84361d7..cee3bd8b2 100644
--- a/src/tools/clippy/tests/ui/rc_mutex.stderr
+++ b/src/tools/clippy/tests/ui/rc_mutex.stderr
@@ -4,8 +4,8 @@ error: usage of `Rc<Mutex<_>>`
LL | foo: Rc<Mutex<i32>>,
| ^^^^^^^^^^^^^^
|
- = note: `-D clippy::rc-mutex` implied by `-D warnings`
= help: consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead
+ = note: `-D clippy::rc-mutex` implied by `-D warnings`
error: usage of `Rc<Mutex<_>>`
--> $DIR/rc_mutex.rs:26:18
diff --git a/src/tools/clippy/tests/ui/recursive_format_impl.rs b/src/tools/clippy/tests/ui/recursive_format_impl.rs
index cb6ba36b1..b92490b4c 100644
--- a/src/tools/clippy/tests/ui/recursive_format_impl.rs
+++ b/src/tools/clippy/tests/ui/recursive_format_impl.rs
@@ -1,9 +1,10 @@
#![warn(clippy::recursive_format_impl)]
#![allow(
+ clippy::borrow_deref_ref,
+ clippy::deref_addrof,
clippy::inherent_to_string_shadow_display,
clippy::to_string_in_format_args,
- clippy::deref_addrof,
- clippy::borrow_deref_ref
+ clippy::uninlined_format_args
)]
use std::fmt;
diff --git a/src/tools/clippy/tests/ui/recursive_format_impl.stderr b/src/tools/clippy/tests/ui/recursive_format_impl.stderr
index 84ce69df5..8a58b9a3b 100644
--- a/src/tools/clippy/tests/ui/recursive_format_impl.stderr
+++ b/src/tools/clippy/tests/ui/recursive_format_impl.stderr
@@ -1,5 +1,5 @@
error: using `self.to_string` in `fmt::Display` implementation will cause infinite recursion
- --> $DIR/recursive_format_impl.rs:30:25
+ --> $DIR/recursive_format_impl.rs:31:25
|
LL | write!(f, "{}", self.to_string())
| ^^^^^^^^^^^^^^^^
@@ -7,7 +7,7 @@ LL | write!(f, "{}", self.to_string())
= note: `-D clippy::recursive-format-impl` implied by `-D warnings`
error: using `self` as `Display` in `impl Display` will cause infinite recursion
- --> $DIR/recursive_format_impl.rs:74:9
+ --> $DIR/recursive_format_impl.rs:75:9
|
LL | write!(f, "{}", self)
| ^^^^^^^^^^^^^^^^^^^^^
@@ -15,7 +15,7 @@ LL | write!(f, "{}", self)
= note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
error: using `self` as `Display` in `impl Display` will cause infinite recursion
- --> $DIR/recursive_format_impl.rs:83:9
+ --> $DIR/recursive_format_impl.rs:84:9
|
LL | write!(f, "{}", &self)
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -23,7 +23,7 @@ LL | write!(f, "{}", &self)
= note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
error: using `self` as `Debug` in `impl Debug` will cause infinite recursion
- --> $DIR/recursive_format_impl.rs:89:9
+ --> $DIR/recursive_format_impl.rs:90:9
|
LL | write!(f, "{:?}", &self)
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -31,7 +31,7 @@ LL | write!(f, "{:?}", &self)
= note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
error: using `self` as `Display` in `impl Display` will cause infinite recursion
- --> $DIR/recursive_format_impl.rs:98:9
+ --> $DIR/recursive_format_impl.rs:99:9
|
LL | write!(f, "{}", &&&self)
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -39,7 +39,7 @@ LL | write!(f, "{}", &&&self)
= note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
error: using `self` as `Display` in `impl Display` will cause infinite recursion
- --> $DIR/recursive_format_impl.rs:172:9
+ --> $DIR/recursive_format_impl.rs:173:9
|
LL | write!(f, "{}", &*self)
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -47,7 +47,7 @@ LL | write!(f, "{}", &*self)
= note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
error: using `self` as `Debug` in `impl Debug` will cause infinite recursion
- --> $DIR/recursive_format_impl.rs:178:9
+ --> $DIR/recursive_format_impl.rs:179:9
|
LL | write!(f, "{:?}", &*self)
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -55,7 +55,7 @@ LL | write!(f, "{:?}", &*self)
= note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
error: using `self` as `Display` in `impl Display` will cause infinite recursion
- --> $DIR/recursive_format_impl.rs:194:9
+ --> $DIR/recursive_format_impl.rs:195:9
|
LL | write!(f, "{}", *self)
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -63,7 +63,7 @@ LL | write!(f, "{}", *self)
= note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
error: using `self` as `Display` in `impl Display` will cause infinite recursion
- --> $DIR/recursive_format_impl.rs:210:9
+ --> $DIR/recursive_format_impl.rs:211:9
|
LL | write!(f, "{}", **&&*self)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -71,7 +71,7 @@ LL | write!(f, "{}", **&&*self)
= note: this error originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
error: using `self` as `Display` in `impl Display` will cause infinite recursion
- --> $DIR/recursive_format_impl.rs:226:9
+ --> $DIR/recursive_format_impl.rs:227:9
|
LL | write!(f, "{}", &&**&&*self)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/redundant_allocation.stderr b/src/tools/clippy/tests/ui/redundant_allocation.stderr
index 54d4d88db..e0826fefa 100644
--- a/src/tools/clippy/tests/ui/redundant_allocation.stderr
+++ b/src/tools/clippy/tests/ui/redundant_allocation.stderr
@@ -4,9 +4,9 @@ error: usage of `Box<Rc<T>>`
LL | pub fn box_test6<T>(foo: Box<Rc<T>>) {}
| ^^^^^^^^^^
|
- = note: `-D clippy::redundant-allocation` implied by `-D warnings`
= note: `Rc<T>` is already on the heap, `Box<Rc<T>>` makes an extra allocation
= help: consider using just `Box<T>` or `Rc<T>`
+ = note: `-D clippy::redundant-allocation` implied by `-D warnings`
error: usage of `Box<Arc<T>>`
--> $DIR/redundant_allocation.rs:19:30
diff --git a/src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr b/src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr
index fdd76ef17..8dd4a6a26 100644
--- a/src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr
+++ b/src/tools/clippy/tests/ui/redundant_allocation_fixable.stderr
@@ -4,8 +4,8 @@ error: usage of `Box<&T>`
LL | pub fn box_test1<T>(foo: Box<&T>) {}
| ^^^^^^^ help: try: `&T`
|
- = note: `-D clippy::redundant-allocation` implied by `-D warnings`
= note: `&T` is already a pointer, `Box<&T>` allocates a pointer on the heap
+ = note: `-D clippy::redundant-allocation` implied by `-D warnings`
error: usage of `Box<&MyStruct>`
--> $DIR/redundant_allocation_fixable.rs:28:27
diff --git a/src/tools/clippy/tests/ui/redundant_clone.fixed b/src/tools/clippy/tests/ui/redundant_clone.fixed
index da52c0acf..00b427450 100644
--- a/src/tools/clippy/tests/ui/redundant_clone.fixed
+++ b/src/tools/clippy/tests/ui/redundant_clone.fixed
@@ -1,8 +1,8 @@
// run-rustfix
// rustfix-only-machine-applicable
-
#![feature(lint_reasons)]
-#![allow(clippy::implicit_clone, clippy::drop_non_drop)]
+#![allow(clippy::drop_non_drop, clippy::implicit_clone, clippy::uninlined_format_args)]
+
use std::ffi::OsString;
use std::path::Path;
diff --git a/src/tools/clippy/tests/ui/redundant_clone.rs b/src/tools/clippy/tests/ui/redundant_clone.rs
index 5867d019d..f899127db 100644
--- a/src/tools/clippy/tests/ui/redundant_clone.rs
+++ b/src/tools/clippy/tests/ui/redundant_clone.rs
@@ -1,8 +1,8 @@
// run-rustfix
// rustfix-only-machine-applicable
-
#![feature(lint_reasons)]
-#![allow(clippy::implicit_clone, clippy::drop_non_drop)]
+#![allow(clippy::drop_non_drop, clippy::implicit_clone, clippy::uninlined_format_args)]
+
use std::ffi::OsString;
use std::path::Path;
diff --git a/src/tools/clippy/tests/ui/redundant_clone.stderr b/src/tools/clippy/tests/ui/redundant_clone.stderr
index aa1dd7cbb..782590034 100644
--- a/src/tools/clippy/tests/ui/redundant_clone.stderr
+++ b/src/tools/clippy/tests/ui/redundant_clone.stderr
@@ -4,12 +4,12 @@ error: redundant clone
LL | let _s = ["lorem", "ipsum"].join(" ").to_string();
| ^^^^^^^^^^^^ help: remove this
|
- = note: `-D clippy::redundant-clone` implied by `-D warnings`
note: this value is dropped without further use
--> $DIR/redundant_clone.rs:10:14
|
LL | let _s = ["lorem", "ipsum"].join(" ").to_string();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: `-D clippy::redundant-clone` implied by `-D warnings`
error: redundant clone
--> $DIR/redundant_clone.rs:13:15
diff --git a/src/tools/clippy/tests/ui/redundant_else.stderr b/src/tools/clippy/tests/ui/redundant_else.stderr
index 9000cdc81..de9d00a60 100644
--- a/src/tools/clippy/tests/ui/redundant_else.stderr
+++ b/src/tools/clippy/tests/ui/redundant_else.stderr
@@ -7,8 +7,8 @@ LL | | println!("yet don't pull down your hedge.");
LL | | }
| |_________^
|
- = note: `-D clippy::redundant-else` implied by `-D warnings`
= help: remove the `else` block and move the contents out
+ = note: `-D clippy::redundant-else` implied by `-D warnings`
error: redundant else block
--> $DIR/redundant_else.rs:17:16
diff --git a/src/tools/clippy/tests/ui/redundant_field_names.fixed b/src/tools/clippy/tests/ui/redundant_field_names.fixed
index 5b4b8eeed..34ab552cb 100644
--- a/src/tools/clippy/tests/ui/redundant_field_names.fixed
+++ b/src/tools/clippy/tests/ui/redundant_field_names.fixed
@@ -1,4 +1,6 @@
// run-rustfix
+
+#![feature(custom_inner_attributes)]
#![warn(clippy::redundant_field_names)]
#![allow(clippy::no_effect, dead_code, unused_variables)]
@@ -69,3 +71,17 @@ fn issue_3476() {
S { foo: foo::<i32> };
}
+
+fn msrv_1_16() {
+ #![clippy::msrv = "1.16"]
+
+ let start = 0;
+ let _ = RangeFrom { start: start };
+}
+
+fn msrv_1_17() {
+ #![clippy::msrv = "1.17"]
+
+ let start = 0;
+ let _ = RangeFrom { start };
+}
diff --git a/src/tools/clippy/tests/ui/redundant_field_names.rs b/src/tools/clippy/tests/ui/redundant_field_names.rs
index 3f97b80c5..a051b1f96 100644
--- a/src/tools/clippy/tests/ui/redundant_field_names.rs
+++ b/src/tools/clippy/tests/ui/redundant_field_names.rs
@@ -1,4 +1,6 @@
// run-rustfix
+
+#![feature(custom_inner_attributes)]
#![warn(clippy::redundant_field_names)]
#![allow(clippy::no_effect, dead_code, unused_variables)]
@@ -69,3 +71,17 @@ fn issue_3476() {
S { foo: foo::<i32> };
}
+
+fn msrv_1_16() {
+ #![clippy::msrv = "1.16"]
+
+ let start = 0;
+ let _ = RangeFrom { start: start };
+}
+
+fn msrv_1_17() {
+ #![clippy::msrv = "1.17"]
+
+ let start = 0;
+ let _ = RangeFrom { start: start };
+}
diff --git a/src/tools/clippy/tests/ui/redundant_field_names.stderr b/src/tools/clippy/tests/ui/redundant_field_names.stderr
index 7976292df..8b82e062b 100644
--- a/src/tools/clippy/tests/ui/redundant_field_names.stderr
+++ b/src/tools/clippy/tests/ui/redundant_field_names.stderr
@@ -1,5 +1,5 @@
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:34:9
+ --> $DIR/redundant_field_names.rs:36:9
|
LL | gender: gender,
| ^^^^^^^^^^^^^^ help: replace it with: `gender`
@@ -7,40 +7,46 @@ LL | gender: gender,
= note: `-D clippy::redundant-field-names` implied by `-D warnings`
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:35:9
+ --> $DIR/redundant_field_names.rs:37:9
|
LL | age: age,
| ^^^^^^^^ help: replace it with: `age`
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:56:25
+ --> $DIR/redundant_field_names.rs:58:25
|
LL | let _ = RangeFrom { start: start };
| ^^^^^^^^^^^^ help: replace it with: `start`
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:57:23
+ --> $DIR/redundant_field_names.rs:59:23
|
LL | let _ = RangeTo { end: end };
| ^^^^^^^^ help: replace it with: `end`
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:58:21
+ --> $DIR/redundant_field_names.rs:60:21
|
LL | let _ = Range { start: start, end: end };
| ^^^^^^^^^^^^ help: replace it with: `start`
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:58:35
+ --> $DIR/redundant_field_names.rs:60:35
|
LL | let _ = Range { start: start, end: end };
| ^^^^^^^^ help: replace it with: `end`
error: redundant field names in struct initialization
- --> $DIR/redundant_field_names.rs:60:32
+ --> $DIR/redundant_field_names.rs:62:32
|
LL | let _ = RangeToInclusive { end: end };
| ^^^^^^^^ help: replace it with: `end`
-error: aborting due to 7 previous errors
+error: redundant field names in struct initialization
+ --> $DIR/redundant_field_names.rs:86:25
+ |
+LL | let _ = RangeFrom { start: start };
+ | ^^^^^^^^^^^^ help: replace it with: `start`
+
+error: aborting due to 8 previous errors
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.stderr b/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.stderr
index eb7aa70ee..23f08103f 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.stderr
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_drop_order.stderr
@@ -4,9 +4,9 @@ error: redundant pattern matching, consider using `is_ok()`
LL | if let Ok(_) = m.lock() {}
| -------^^^^^----------- help: try this: `if m.lock().is_ok()`
|
- = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
= note: this will change drop order of the result, as well as all temporaries
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
+ = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: redundant pattern matching, consider using `is_err()`
--> $DIR/redundant_pattern_matching_drop_order.rs:13:12
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed
index acc8de5f4..21bae9095 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.fixed
@@ -1,8 +1,11 @@
// run-rustfix
-
-#![warn(clippy::all)]
-#![warn(clippy::redundant_pattern_matching)]
-#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)]
+#![warn(clippy::all, clippy::redundant_pattern_matching)]
+#![allow(unused_must_use)]
+#![allow(
+ clippy::match_like_matches_macro,
+ clippy::needless_bool,
+ clippy::uninlined_format_args
+)]
use std::net::{
IpAddr::{self, V4, V6},
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs
index 678d91ce9..4dd917167 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.rs
@@ -1,8 +1,11 @@
// run-rustfix
-
-#![warn(clippy::all)]
-#![warn(clippy::redundant_pattern_matching)]
-#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)]
+#![warn(clippy::all, clippy::redundant_pattern_matching)]
+#![allow(unused_must_use)]
+#![allow(
+ clippy::match_like_matches_macro,
+ clippy::needless_bool,
+ clippy::uninlined_format_args
+)]
use std::net::{
IpAddr::{self, V4, V6},
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr
index caf458cd8..536b589de 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_ipaddr.stderr
@@ -1,5 +1,5 @@
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:14:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:17:12
|
LL | if let V4(_) = &ipaddr {}
| -------^^^^^---------- help: try this: `if ipaddr.is_ipv4()`
@@ -7,31 +7,31 @@ LL | if let V4(_) = &ipaddr {}
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:16:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:19:12
|
LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
| -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:18:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:21:12
|
LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
| -------^^^^^-------------------------- help: try this: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:20:15
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:23:15
|
LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
| ----------^^^^^-------------------------- help: try this: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:22:15
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:25:15
|
LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
| ----------^^^^^-------------------------- help: try this: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:32:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:35:5
|
LL | / match V4(Ipv4Addr::LOCALHOST) {
LL | | V4(_) => true,
@@ -40,7 +40,7 @@ LL | | };
| |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:37:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:40:5
|
LL | / match V4(Ipv4Addr::LOCALHOST) {
LL | | V4(_) => false,
@@ -49,7 +49,7 @@ LL | | };
| |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:42:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:45:5
|
LL | / match V6(Ipv6Addr::LOCALHOST) {
LL | | V4(_) => false,
@@ -58,7 +58,7 @@ LL | | };
| |_____^ help: try this: `V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:47:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:50:5
|
LL | / match V6(Ipv6Addr::LOCALHOST) {
LL | | V4(_) => true,
@@ -67,49 +67,49 @@ LL | | };
| |_____^ help: try this: `V6(Ipv6Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:52:20
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:55:20
|
LL | let _ = if let V4(_) = V4(Ipv4Addr::LOCALHOST) {
| -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:60:20
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:63:20
|
LL | let _ = if let V4(_) = gen_ipaddr() {
| -------^^^^^--------------- help: try this: `if gen_ipaddr().is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:62:19
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:65:19
|
LL | } else if let V6(_) = gen_ipaddr() {
| -------^^^^^--------------- help: try this: `if gen_ipaddr().is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:74:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:77:12
|
LL | if let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
| -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:76:12
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:79:12
|
LL | if let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
| -------^^^^^-------------------------- help: try this: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:78:15
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:81:15
|
LL | while let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
| ----------^^^^^-------------------------- help: try this: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:80:15
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:83:15
|
LL | while let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
| ----------^^^^^-------------------------- help: try this: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()`
error: redundant pattern matching, consider using `is_ipv4()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:82:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:85:5
|
LL | / match V4(Ipv4Addr::LOCALHOST) {
LL | | V4(_) => true,
@@ -118,7 +118,7 @@ LL | | };
| |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv4()`
error: redundant pattern matching, consider using `is_ipv6()`
- --> $DIR/redundant_pattern_matching_ipaddr.rs:87:5
+ --> $DIR/redundant_pattern_matching_ipaddr.rs:90:5
|
LL | / match V6(Ipv6Addr::LOCALHOST) {
LL | | V4(_) => false,
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed
index 83c783385..b88c5d0be 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.fixed
@@ -1,14 +1,13 @@
// run-rustfix
-
#![warn(clippy::all)]
#![warn(clippy::redundant_pattern_matching)]
+#![allow(deprecated, unused_must_use)]
#![allow(
- unused_must_use,
- clippy::needless_bool,
+ clippy::if_same_then_else,
clippy::match_like_matches_macro,
- clippy::unnecessary_wraps,
- deprecated,
- clippy::if_same_then_else
+ clippy::needless_bool,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_wraps
)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs
index e06d4485a..5949cb227 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.rs
@@ -1,14 +1,13 @@
// run-rustfix
-
#![warn(clippy::all)]
#![warn(clippy::redundant_pattern_matching)]
+#![allow(deprecated, unused_must_use)]
#![allow(
- unused_must_use,
- clippy::needless_bool,
+ clippy::if_same_then_else,
clippy::match_like_matches_macro,
- clippy::unnecessary_wraps,
- deprecated,
- clippy::if_same_then_else
+ clippy::needless_bool,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_wraps
)]
fn main() {
diff --git a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr
index d674d061e..e6afe9eb7 100644
--- a/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr
+++ b/src/tools/clippy/tests/ui/redundant_pattern_matching_result.stderr
@@ -1,5 +1,5 @@
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:16:12
+ --> $DIR/redundant_pattern_matching_result.rs:15:12
|
LL | if let Ok(_) = &result {}
| -------^^^^^---------- help: try this: `if result.is_ok()`
@@ -7,31 +7,31 @@ LL | if let Ok(_) = &result {}
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:18:12
+ --> $DIR/redundant_pattern_matching_result.rs:17:12
|
LL | if let Ok(_) = Ok::<i32, i32>(42) {}
| -------^^^^^--------------------- help: try this: `if Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:20:12
+ --> $DIR/redundant_pattern_matching_result.rs:19:12
|
LL | if let Err(_) = Err::<i32, i32>(42) {}
| -------^^^^^^---------------------- help: try this: `if Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:22:15
+ --> $DIR/redundant_pattern_matching_result.rs:21:15
|
LL | while let Ok(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:24:15
+ --> $DIR/redundant_pattern_matching_result.rs:23:15
|
LL | while let Err(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:34:5
+ --> $DIR/redundant_pattern_matching_result.rs:33:5
|
LL | / match Ok::<i32, i32>(42) {
LL | | Ok(_) => true,
@@ -40,7 +40,7 @@ LL | | };
| |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:39:5
+ --> $DIR/redundant_pattern_matching_result.rs:38:5
|
LL | / match Ok::<i32, i32>(42) {
LL | | Ok(_) => false,
@@ -49,7 +49,7 @@ LL | | };
| |_____^ help: try this: `Ok::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:44:5
+ --> $DIR/redundant_pattern_matching_result.rs:43:5
|
LL | / match Err::<i32, i32>(42) {
LL | | Ok(_) => false,
@@ -58,7 +58,7 @@ LL | | };
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:49:5
+ --> $DIR/redundant_pattern_matching_result.rs:48:5
|
LL | / match Err::<i32, i32>(42) {
LL | | Ok(_) => true,
@@ -67,73 +67,73 @@ LL | | };
| |_____^ help: try this: `Err::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:54:20
+ --> $DIR/redundant_pattern_matching_result.rs:53:20
|
LL | let _ = if let Ok(_) = Ok::<usize, ()>(4) { true } else { false };
| -------^^^^^--------------------- help: try this: `if Ok::<usize, ()>(4).is_ok()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:60:20
+ --> $DIR/redundant_pattern_matching_result.rs:59:20
|
LL | let _ = 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_result.rs:62:19
+ --> $DIR/redundant_pattern_matching_result.rs:61: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_result.rs:85:19
+ --> $DIR/redundant_pattern_matching_result.rs:84: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_result.rs:86:16
+ --> $DIR/redundant_pattern_matching_result.rs:85: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_result.rs:92:12
+ --> $DIR/redundant_pattern_matching_result.rs:91: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_result.rs:93:15
+ --> $DIR/redundant_pattern_matching_result.rs:92:15
|
LL | while let Some(_) = m!() {}
| ----------^^^^^^^------- help: try this: `while m!().is_some()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:111:12
+ --> $DIR/redundant_pattern_matching_result.rs:110:12
|
LL | if let Ok(_) = Ok::<i32, i32>(42) {}
| -------^^^^^--------------------- help: try this: `if Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:113:12
+ --> $DIR/redundant_pattern_matching_result.rs:112:12
|
LL | if let Err(_) = Err::<i32, i32>(42) {}
| -------^^^^^^---------------------- help: try this: `if Err::<i32, i32>(42).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:115:15
+ --> $DIR/redundant_pattern_matching_result.rs:114:15
|
LL | while let Ok(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:117:15
+ --> $DIR/redundant_pattern_matching_result.rs:116:15
|
LL | while let Err(_) = Ok::<i32, i32>(10) {}
| ----------^^^^^^--------------------- help: try this: `while Ok::<i32, i32>(10).is_err()`
error: redundant pattern matching, consider using `is_ok()`
- --> $DIR/redundant_pattern_matching_result.rs:119:5
+ --> $DIR/redundant_pattern_matching_result.rs:118:5
|
LL | / match Ok::<i32, i32>(42) {
LL | | Ok(_) => true,
@@ -142,7 +142,7 @@ LL | | };
| |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()`
error: redundant pattern matching, consider using `is_err()`
- --> $DIR/redundant_pattern_matching_result.rs:124:5
+ --> $DIR/redundant_pattern_matching_result.rs:123:5
|
LL | / match Err::<i32, i32>(42) {
LL | | Ok(_) => false,
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed b/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
index acc8f1e25..42110dbe8 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
@@ -1,5 +1,6 @@
// run-rustfix
+#![feature(custom_inner_attributes)]
#![allow(unused)]
#[derive(Debug)]
@@ -54,3 +55,15 @@ impl Foo {
impl Bar for Foo {
const TRAIT_VAR: &'static str = "foo";
}
+
+fn msrv_1_16() {
+ #![clippy::msrv = "1.16"]
+
+ static V: &'static u8 = &16;
+}
+
+fn msrv_1_17() {
+ #![clippy::msrv = "1.17"]
+
+ static V: &u8 = &17;
+}
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs b/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
index f2f0f7865..bc5200bc8 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
@@ -1,5 +1,6 @@
// run-rustfix
+#![feature(custom_inner_attributes)]
#![allow(unused)]
#[derive(Debug)]
@@ -54,3 +55,15 @@ impl Foo {
impl Bar for Foo {
const TRAIT_VAR: &'static str = "foo";
}
+
+fn msrv_1_16() {
+ #![clippy::msrv = "1.16"]
+
+ static V: &'static u8 = &16;
+}
+
+fn msrv_1_17() {
+ #![clippy::msrv = "1.17"]
+
+ static V: &'static u8 = &17;
+}
diff --git a/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr b/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
index 649831f9c..735113460 100644
--- a/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
+++ b/src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
@@ -1,5 +1,5 @@
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:8:17
+ --> $DIR/redundant_static_lifetimes.rs:9:17
|
LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static.
| -^^^^^^^---- help: consider removing `'static`: `&str`
@@ -7,94 +7,100 @@ LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removin
= note: `-D clippy::redundant-static-lifetimes` implied by `-D warnings`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:12:21
+ --> $DIR/redundant_static_lifetimes.rs:13:21
|
LL | const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
| -^^^^^^^---- help: consider removing `'static`: `&str`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:14:32
+ --> $DIR/redundant_static_lifetimes.rs:15:32
|
LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
| -^^^^^^^---- help: consider removing `'static`: `&str`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:14:47
+ --> $DIR/redundant_static_lifetimes.rs:15:47
|
LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
| -^^^^^^^---- help: consider removing `'static`: `&str`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:16:17
+ --> $DIR/redundant_static_lifetimes.rs:17:17
|
LL | const VAR_SIX: &'static u8 = &5;
| -^^^^^^^--- help: consider removing `'static`: `&u8`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:18:20
+ --> $DIR/redundant_static_lifetimes.rs:19:20
|
LL | const VAR_HEIGHT: &'static Foo = &Foo {};
| -^^^^^^^---- help: consider removing `'static`: `&Foo`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:20:19
+ --> $DIR/redundant_static_lifetimes.rs:21:19
|
LL | const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR Consider removing 'static.
| -^^^^^^^----- help: consider removing `'static`: `&[u8]`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:22:19
+ --> $DIR/redundant_static_lifetimes.rs:23:19
|
LL | const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static.
| -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)`
error: constants have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:24:19
+ --> $DIR/redundant_static_lifetimes.rs:25:19
|
LL | const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:26:25
+ --> $DIR/redundant_static_lifetimes.rs:27:25
|
LL | static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR Consider removing 'static.
| -^^^^^^^---- help: consider removing `'static`: `&str`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:30:29
+ --> $DIR/redundant_static_lifetimes.rs:31:29
|
LL | static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
| -^^^^^^^---- help: consider removing `'static`: `&str`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:32:25
+ --> $DIR/redundant_static_lifetimes.rs:33:25
|
LL | static STATIC_VAR_SIX: &'static u8 = &5;
| -^^^^^^^--- help: consider removing `'static`: `&u8`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:34:28
+ --> $DIR/redundant_static_lifetimes.rs:35:28
|
LL | static STATIC_VAR_HEIGHT: &'static Foo = &Foo {};
| -^^^^^^^---- help: consider removing `'static`: `&Foo`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:36:27
+ --> $DIR/redundant_static_lifetimes.rs:37:27
|
LL | static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR Consider removing 'static.
| -^^^^^^^----- help: consider removing `'static`: `&[u8]`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:38:27
+ --> $DIR/redundant_static_lifetimes.rs:39:27
|
LL | static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static.
| -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)`
error: statics have by default a `'static` lifetime
- --> $DIR/redundant_static_lifetimes.rs:40:27
+ --> $DIR/redundant_static_lifetimes.rs:41:27
|
LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
-error: aborting due to 16 previous errors
+error: statics have by default a `'static` lifetime
+ --> $DIR/redundant_static_lifetimes.rs:68:16
+ |
+LL | static V: &'static u8 = &17;
+ | -^^^^^^^--- help: consider removing `'static`: `&u8`
+
+error: aborting due to 17 previous errors
diff --git a/src/tools/clippy/tests/ui/ref_option_ref.rs b/src/tools/clippy/tests/ui/ref_option_ref.rs
index 2df45c927..e487799e1 100644
--- a/src/tools/clippy/tests/ui/ref_option_ref.rs
+++ b/src/tools/clippy/tests/ui/ref_option_ref.rs
@@ -45,3 +45,8 @@ impl RefOptTrait for u32 {
fn main() {
let x: &Option<&u32> = &None;
}
+
+fn issue9682(arg: &Option<&mut String>) {
+ // Should not lint, as the inner ref is mutable making it non `Copy`
+ println!("{arg:?}");
+}
diff --git a/src/tools/clippy/tests/ui/regex.stderr b/src/tools/clippy/tests/ui/regex.stderr
index 1394a9b63..2424644c6 100644
--- a/src/tools/clippy/tests/ui/regex.stderr
+++ b/src/tools/clippy/tests/ui/regex.stderr
@@ -4,8 +4,8 @@ error: trivial regex
LL | let pipe_in_wrong_position = Regex::new("|");
| ^^^
|
- = note: `-D clippy::trivial-regex` implied by `-D warnings`
= help: the regex is unlikely to be useful as it is
+ = note: `-D clippy::trivial-regex` implied by `-D warnings`
error: trivial regex
--> $DIR/regex.rs:14:60
diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed
index 9cbad2269..8beae8dee 100644
--- a/src/tools/clippy/tests/ui/rename.fixed
+++ b/src/tools/clippy/tests/ui/rename.fixed
@@ -12,7 +12,7 @@
#![allow(clippy::disallowed_methods)]
#![allow(clippy::disallowed_types)]
#![allow(clippy::mixed_read_write_in_expression)]
-#![allow(clippy::for_loops_over_fallibles)]
+#![allow(for_loops_over_fallibles)]
#![allow(clippy::useless_conversion)]
#![allow(clippy::match_result_ok)]
#![allow(clippy::overly_complex_bool_expr)]
@@ -32,6 +32,7 @@
#![allow(invalid_value)]
#![allow(enum_intrinsics_non_enums)]
#![allow(non_fmt_panics)]
+#![allow(named_arguments_used_positionally)]
#![allow(temporary_cstring_as_ptr)]
#![allow(unknown_lints)]
#![allow(unused_labels)]
@@ -44,8 +45,8 @@
#![warn(clippy::disallowed_methods)]
#![warn(clippy::disallowed_types)]
#![warn(clippy::mixed_read_write_in_expression)]
-#![warn(clippy::for_loops_over_fallibles)]
-#![warn(clippy::for_loops_over_fallibles)]
+#![warn(for_loops_over_fallibles)]
+#![warn(for_loops_over_fallibles)]
#![warn(clippy::useless_conversion)]
#![warn(clippy::match_result_ok)]
#![warn(clippy::overly_complex_bool_expr)]
@@ -64,11 +65,13 @@
#![warn(clippy::recursive_format_impl)]
#![warn(clippy::invisible_characters)]
#![warn(drop_bounds)]
+#![warn(for_loops_over_fallibles)]
#![warn(array_into_iter)]
#![warn(invalid_atomic_ordering)]
#![warn(invalid_value)]
#![warn(enum_intrinsics_non_enums)]
#![warn(non_fmt_panics)]
+#![warn(named_arguments_used_positionally)]
#![warn(temporary_cstring_as_ptr)]
#![warn(unknown_lints)]
#![warn(unused_labels)]
diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs
index 9153c0dab..9e665047b 100644
--- a/src/tools/clippy/tests/ui/rename.rs
+++ b/src/tools/clippy/tests/ui/rename.rs
@@ -12,7 +12,7 @@
#![allow(clippy::disallowed_methods)]
#![allow(clippy::disallowed_types)]
#![allow(clippy::mixed_read_write_in_expression)]
-#![allow(clippy::for_loops_over_fallibles)]
+#![allow(for_loops_over_fallibles)]
#![allow(clippy::useless_conversion)]
#![allow(clippy::match_result_ok)]
#![allow(clippy::overly_complex_bool_expr)]
@@ -32,6 +32,7 @@
#![allow(invalid_value)]
#![allow(enum_intrinsics_non_enums)]
#![allow(non_fmt_panics)]
+#![allow(named_arguments_used_positionally)]
#![allow(temporary_cstring_as_ptr)]
#![allow(unknown_lints)]
#![allow(unused_labels)]
@@ -64,11 +65,13 @@
#![warn(clippy::to_string_in_display)]
#![warn(clippy::zero_width_space)]
#![warn(clippy::drop_bounds)]
+#![warn(clippy::for_loops_over_fallibles)]
#![warn(clippy::into_iter_on_array)]
#![warn(clippy::invalid_atomic_ordering)]
#![warn(clippy::invalid_ref)]
#![warn(clippy::mem_discriminant_non_enum)]
#![warn(clippy::panic_params)]
+#![warn(clippy::positional_named_format_parameters)]
#![warn(clippy::temporary_cstring_as_ptr)]
#![warn(clippy::unknown_clippy_lints)]
#![warn(clippy::unused_label)]
diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr
index 9c03ea914..63eb56518 100644
--- a/src/tools/clippy/tests/ui/rename.stderr
+++ b/src/tools/clippy/tests/ui/rename.stderr
@@ -1,5 +1,5 @@
error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names`
- --> $DIR/rename.rs:38:9
+ --> $DIR/rename.rs:39:9
|
LL | #![warn(clippy::blacklisted_name)]
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names`
@@ -7,220 +7,232 @@ LL | #![warn(clippy::blacklisted_name)]
= note: `-D renamed-and-removed-lints` implied by `-D warnings`
error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions`
- --> $DIR/rename.rs:39:9
+ --> $DIR/rename.rs:40:9
|
LL | #![warn(clippy::block_in_if_condition_expr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions`
error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions`
- --> $DIR/rename.rs:40:9
+ --> $DIR/rename.rs:41:9
|
LL | #![warn(clippy::block_in_if_condition_stmt)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions`
error: lint `clippy::box_vec` has been renamed to `clippy::box_collection`
- --> $DIR/rename.rs:41:9
+ --> $DIR/rename.rs:42:9
|
LL | #![warn(clippy::box_vec)]
| ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection`
error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes`
- --> $DIR/rename.rs:42:9
+ --> $DIR/rename.rs:43:9
|
LL | #![warn(clippy::const_static_lifetime)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes`
error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity`
- --> $DIR/rename.rs:43:9
+ --> $DIR/rename.rs:44:9
|
LL | #![warn(clippy::cyclomatic_complexity)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity`
error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods`
- --> $DIR/rename.rs:44:9
+ --> $DIR/rename.rs:45:9
|
LL | #![warn(clippy::disallowed_method)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods`
error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types`
- --> $DIR/rename.rs:45:9
+ --> $DIR/rename.rs:46:9
|
LL | #![warn(clippy::disallowed_type)]
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types`
error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression`
- --> $DIR/rename.rs:46:9
+ --> $DIR/rename.rs:47:9
|
LL | #![warn(clippy::eval_order_dependence)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression`
-error: lint `clippy::for_loop_over_option` has been renamed to `clippy::for_loops_over_fallibles`
- --> $DIR/rename.rs:47:9
+error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles`
+ --> $DIR/rename.rs:48:9
|
LL | #![warn(clippy::for_loop_over_option)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::for_loops_over_fallibles`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles`
-error: lint `clippy::for_loop_over_result` has been renamed to `clippy::for_loops_over_fallibles`
- --> $DIR/rename.rs:48:9
+error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles`
+ --> $DIR/rename.rs:49:9
|
LL | #![warn(clippy::for_loop_over_result)]
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::for_loops_over_fallibles`
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles`
error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion`
- --> $DIR/rename.rs:49:9
+ --> $DIR/rename.rs:50:9
|
LL | #![warn(clippy::identity_conversion)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion`
error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok`
- --> $DIR/rename.rs:50:9
+ --> $DIR/rename.rs:51:9
|
LL | #![warn(clippy::if_let_some_result)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok`
error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr`
- --> $DIR/rename.rs:51:9
+ --> $DIR/rename.rs:52:9
|
LL | #![warn(clippy::logic_bug)]
| ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr`
error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default`
- --> $DIR/rename.rs:52:9
+ --> $DIR/rename.rs:53:9
|
LL | #![warn(clippy::new_without_default_derive)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default`
error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map`
- --> $DIR/rename.rs:53:9
+ --> $DIR/rename.rs:54:9
|
LL | #![warn(clippy::option_and_then_some)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map`
error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used`
- --> $DIR/rename.rs:54:9
+ --> $DIR/rename.rs:55:9
|
LL | #![warn(clippy::option_expect_used)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used`
error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or`
- --> $DIR/rename.rs:55:9
+ --> $DIR/rename.rs:56:9
|
LL | #![warn(clippy::option_map_unwrap_or)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or`
error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or`
- --> $DIR/rename.rs:56:9
+ --> $DIR/rename.rs:57:9
|
LL | #![warn(clippy::option_map_unwrap_or_else)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or`
error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used`
- --> $DIR/rename.rs:57:9
+ --> $DIR/rename.rs:58:9
|
LL | #![warn(clippy::option_unwrap_used)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used`
error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow`
- --> $DIR/rename.rs:58:9
+ --> $DIR/rename.rs:59:9
|
LL | #![warn(clippy::ref_in_deref)]
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow`
error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used`
- --> $DIR/rename.rs:59:9
+ --> $DIR/rename.rs:60:9
|
LL | #![warn(clippy::result_expect_used)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used`
error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or`
- --> $DIR/rename.rs:60:9
+ --> $DIR/rename.rs:61:9
|
LL | #![warn(clippy::result_map_unwrap_or_else)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or`
error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used`
- --> $DIR/rename.rs:61:9
+ --> $DIR/rename.rs:62:9
|
LL | #![warn(clippy::result_unwrap_used)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used`
error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str`
- --> $DIR/rename.rs:62:9
+ --> $DIR/rename.rs:63:9
|
LL | #![warn(clippy::single_char_push_str)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str`
error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions`
- --> $DIR/rename.rs:63:9
+ --> $DIR/rename.rs:64:9
|
LL | #![warn(clippy::stutter)]
| ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions`
error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl`
- --> $DIR/rename.rs:64:9
+ --> $DIR/rename.rs:65:9
|
LL | #![warn(clippy::to_string_in_display)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl`
error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters`
- --> $DIR/rename.rs:65:9
+ --> $DIR/rename.rs:66:9
|
LL | #![warn(clippy::zero_width_space)]
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters`
error: lint `clippy::drop_bounds` has been renamed to `drop_bounds`
- --> $DIR/rename.rs:66:9
+ --> $DIR/rename.rs:67:9
|
LL | #![warn(clippy::drop_bounds)]
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds`
+error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles`
+ --> $DIR/rename.rs:68:9
+ |
+LL | #![warn(clippy::for_loops_over_fallibles)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles`
+
error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter`
- --> $DIR/rename.rs:67:9
+ --> $DIR/rename.rs:69:9
|
LL | #![warn(clippy::into_iter_on_array)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter`
error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering`
- --> $DIR/rename.rs:68:9
+ --> $DIR/rename.rs:70:9
|
LL | #![warn(clippy::invalid_atomic_ordering)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering`
error: lint `clippy::invalid_ref` has been renamed to `invalid_value`
- --> $DIR/rename.rs:69:9
+ --> $DIR/rename.rs:71:9
|
LL | #![warn(clippy::invalid_ref)]
| ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value`
error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums`
- --> $DIR/rename.rs:70:9
+ --> $DIR/rename.rs:72:9
|
LL | #![warn(clippy::mem_discriminant_non_enum)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums`
error: lint `clippy::panic_params` has been renamed to `non_fmt_panics`
- --> $DIR/rename.rs:71:9
+ --> $DIR/rename.rs:73:9
|
LL | #![warn(clippy::panic_params)]
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics`
+error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally`
+ --> $DIR/rename.rs:74:9
+ |
+LL | #![warn(clippy::positional_named_format_parameters)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally`
+
error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr`
- --> $DIR/rename.rs:72:9
+ --> $DIR/rename.rs:75:9
|
LL | #![warn(clippy::temporary_cstring_as_ptr)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr`
error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints`
- --> $DIR/rename.rs:73:9
+ --> $DIR/rename.rs:76:9
|
LL | #![warn(clippy::unknown_clippy_lints)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints`
error: lint `clippy::unused_label` has been renamed to `unused_labels`
- --> $DIR/rename.rs:74:9
+ --> $DIR/rename.rs:77:9
|
LL | #![warn(clippy::unused_label)]
| ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels`
-error: aborting due to 37 previous errors
+error: aborting due to 39 previous errors
diff --git a/src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.stderr b/src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.stderr
index 57ebd47f8..e15633fb1 100644
--- a/src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.stderr
+++ b/src/tools/clippy/tests/ui/rest_pat_in_fully_bound_structs.stderr
@@ -4,8 +4,8 @@ error: unnecessary use of `..` pattern in struct binding. All fields were alread
LL | A { a: 5, b: 42, c: "", .. } => {}, // Lint
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::rest-pat-in-fully-bound-structs` implied by `-D warnings`
= help: consider removing `..` from this binding
+ = note: `-D clippy::rest-pat-in-fully-bound-structs` implied by `-D warnings`
error: unnecessary use of `..` pattern in struct binding. All fields were already bound
--> $DIR/rest_pat_in_fully_bound_structs.rs:23:9
diff --git a/src/tools/clippy/tests/ui/result_large_err.stderr b/src/tools/clippy/tests/ui/result_large_err.stderr
index ef19f2854..bea101fe2 100644
--- a/src/tools/clippy/tests/ui/result_large_err.stderr
+++ b/src/tools/clippy/tests/ui/result_large_err.stderr
@@ -4,8 +4,8 @@ error: the `Err`-variant returned from this function is very large
LL | pub fn large_err() -> Result<(), [u8; 512]> {
| ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes
|
- = note: `-D clippy::result-large-err` implied by `-D warnings`
= help: try reducing the size of `[u8; 512]`, for example by boxing large elements or replacing it with `Box<[u8; 512]>`
+ = note: `-D clippy::result-large-err` implied by `-D warnings`
error: the `Err`-variant returned from this function is very large
--> $DIR/result_large_err.rs:19:21
diff --git a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed
index 14c331f67..d8b56237e 100644
--- a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed
+++ b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.fixed
@@ -1,7 +1,7 @@
// run-rustfix
-
#![warn(clippy::result_map_unit_fn)]
#![allow(unused)]
+#![allow(clippy::uninlined_format_args)]
fn do_nothing<T>(_: T) {}
diff --git a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs
index 8b0fca9ec..44f50d211 100644
--- a/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs
+++ b/src/tools/clippy/tests/ui/result_map_unit_fn_fixable.rs
@@ -1,7 +1,7 @@
// run-rustfix
-
#![warn(clippy::result_map_unit_fn)]
#![allow(unused)]
+#![allow(clippy::uninlined_format_args)]
fn do_nothing<T>(_: T) {}
diff --git a/src/tools/clippy/tests/ui/result_unit_error.stderr b/src/tools/clippy/tests/ui/result_unit_error.stderr
index 8c7573eab..8393a4bf0 100644
--- a/src/tools/clippy/tests/ui/result_unit_error.stderr
+++ b/src/tools/clippy/tests/ui/result_unit_error.stderr
@@ -4,8 +4,8 @@ error: this returns a `Result<_, ()>`
LL | pub fn returns_unit_error() -> Result<u32, ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::result-unit-err` implied by `-D warnings`
= help: use a custom `Error` type instead
+ = note: `-D clippy::result-unit-err` implied by `-D warnings`
error: this returns a `Result<_, ()>`
--> $DIR/result_unit_error.rs:12:5
diff --git a/src/tools/clippy/tests/ui/return_self_not_must_use.stderr b/src/tools/clippy/tests/ui/return_self_not_must_use.stderr
index 94be87dfa..34932fe1c 100644
--- a/src/tools/clippy/tests/ui/return_self_not_must_use.stderr
+++ b/src/tools/clippy/tests/ui/return_self_not_must_use.stderr
@@ -4,8 +4,8 @@ error: missing `#[must_use]` attribute on a method returning `Self`
LL | fn what(&self) -> Self;
| ^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::return-self-not-must-use` implied by `-D warnings`
= help: consider adding the `#[must_use]` attribute to the method or directly to the `Self` type
+ = note: `-D clippy::return-self-not-must-use` implied by `-D warnings`
error: missing `#[must_use]` attribute on a method returning `Self`
--> $DIR/return_self_not_must_use.rs:18:5
diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed
index 79e482eec..c67edb36c 100644
--- a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed
+++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.fixed
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::reversed_empty_ranges)]
+#![allow(clippy::uninlined_format_args)]
const ANSWER: i32 = 42;
diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs
index b2e8bf337..0a4fef5bf 100644
--- a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs
+++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::reversed_empty_ranges)]
+#![allow(clippy::uninlined_format_args)]
const ANSWER: i32 = 42;
diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.stderr b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.stderr
index 2d1bfe62c..c2495ea95 100644
--- a/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.stderr
+++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.stderr
@@ -1,5 +1,5 @@
error: this range is empty so it will yield no values
- --> $DIR/reversed_empty_ranges_fixable.rs:9:5
+ --> $DIR/reversed_empty_ranges_fixable.rs:10:5
|
LL | (42..=21).for_each(|x| println!("{}", x));
| ^^^^^^^^^
@@ -11,7 +11,7 @@ LL | (21..=42).rev().for_each(|x| println!("{}", x));
| ~~~~~~~~~~~~~~~
error: this range is empty so it will yield no values
- --> $DIR/reversed_empty_ranges_fixable.rs:10:13
+ --> $DIR/reversed_empty_ranges_fixable.rs:11:13
|
LL | let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::<Vec<_>>();
| ^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | let _ = (21..ANSWER).rev().filter(|x| x % 2 == 0).take(10).collect::<Ve
| ~~~~~~~~~~~~~~~~~~
error: this range is empty so it will yield no values
- --> $DIR/reversed_empty_ranges_fixable.rs:12:14
+ --> $DIR/reversed_empty_ranges_fixable.rs:13:14
|
LL | for _ in -21..=-42 {}
| ^^^^^^^^^
@@ -33,7 +33,7 @@ LL | for _ in (-42..=-21).rev() {}
| ~~~~~~~~~~~~~~~~~
error: this range is empty so it will yield no values
- --> $DIR/reversed_empty_ranges_fixable.rs:13:14
+ --> $DIR/reversed_empty_ranges_fixable.rs:14:14
|
LL | for _ in 42u32..21u32 {}
| ^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed
index f1503ed6d..78401e463 100644
--- a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed
+++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::reversed_empty_ranges)]
+#![allow(clippy::uninlined_format_args)]
fn main() {
const MAX_LEN: usize = 42;
diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs
index a733788dc..f9e0f7fcd 100644
--- a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs
+++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs
@@ -1,5 +1,6 @@
// run-rustfix
#![warn(clippy::reversed_empty_ranges)]
+#![allow(clippy::uninlined_format_args)]
fn main() {
const MAX_LEN: usize = 42;
diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.stderr b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.stderr
index a135da488..dfc52e64c 100644
--- a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.stderr
+++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.stderr
@@ -1,5 +1,5 @@
error: this range is empty so it will yield no values
- --> $DIR/reversed_empty_ranges_loops_fixable.rs:7:14
+ --> $DIR/reversed_empty_ranges_loops_fixable.rs:8:14
|
LL | for i in 10..0 {
| ^^^^^
@@ -11,7 +11,7 @@ LL | for i in (0..10).rev() {
| ~~~~~~~~~~~~~
error: this range is empty so it will yield no values
- --> $DIR/reversed_empty_ranges_loops_fixable.rs:11:14
+ --> $DIR/reversed_empty_ranges_loops_fixable.rs:12:14
|
LL | for i in 10..=0 {
| ^^^^^^
@@ -22,7 +22,7 @@ LL | for i in (0..=10).rev() {
| ~~~~~~~~~~~~~~
error: this range is empty so it will yield no values
- --> $DIR/reversed_empty_ranges_loops_fixable.rs:15:14
+ --> $DIR/reversed_empty_ranges_loops_fixable.rs:16:14
|
LL | for i in MAX_LEN..0 {
| ^^^^^^^^^^
@@ -33,7 +33,7 @@ LL | for i in (0..MAX_LEN).rev() {
| ~~~~~~~~~~~~~~~~~~
error: this range is empty so it will yield no values
- --> $DIR/reversed_empty_ranges_loops_fixable.rs:34:14
+ --> $DIR/reversed_empty_ranges_loops_fixable.rs:35:14
|
LL | for i in (10..0).map(|x| x * 2) {
| ^^^^^^^
@@ -44,7 +44,7 @@ LL | for i in (0..10).rev().map(|x| x * 2) {
| ~~~~~~~~~~~~~
error: this range is empty so it will yield no values
- --> $DIR/reversed_empty_ranges_loops_fixable.rs:39:14
+ --> $DIR/reversed_empty_ranges_loops_fixable.rs:40:14
|
LL | for i in 10..5 + 4 {
| ^^^^^^^^^
@@ -55,7 +55,7 @@ LL | for i in (5 + 4..10).rev() {
| ~~~~~~~~~~~~~~~~~
error: this range is empty so it will yield no values
- --> $DIR/reversed_empty_ranges_loops_fixable.rs:43:14
+ --> $DIR/reversed_empty_ranges_loops_fixable.rs:44:14
|
LL | for i in (5 + 2)..(3 - 1) {
| ^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.rs b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.rs
index c4c572244..50264ef68 100644
--- a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.rs
+++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.rs
@@ -1,4 +1,5 @@
#![warn(clippy::reversed_empty_ranges)]
+#![allow(clippy::uninlined_format_args)]
fn main() {
for i in 5..5 {
diff --git a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.stderr b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.stderr
index 30095d20c..4490ff35f 100644
--- a/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.stderr
+++ b/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_unfixable.stderr
@@ -1,5 +1,5 @@
error: this range is empty so it will yield no values
- --> $DIR/reversed_empty_ranges_loops_unfixable.rs:4:14
+ --> $DIR/reversed_empty_ranges_loops_unfixable.rs:5:14
|
LL | for i in 5..5 {
| ^^^^
@@ -7,7 +7,7 @@ LL | for i in 5..5 {
= note: `-D clippy::reversed-empty-ranges` implied by `-D warnings`
error: this range is empty so it will yield no values
- --> $DIR/reversed_empty_ranges_loops_unfixable.rs:8:14
+ --> $DIR/reversed_empty_ranges_loops_unfixable.rs:9:14
|
LL | for i in (5 + 2)..(8 - 1) {
| ^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/same_functions_in_if_condition.rs b/src/tools/clippy/tests/ui/same_functions_in_if_condition.rs
index a48829caa..e6198a1bc 100644
--- a/src/tools/clippy/tests/ui/same_functions_in_if_condition.rs
+++ b/src/tools/clippy/tests/ui/same_functions_in_if_condition.rs
@@ -1,8 +1,14 @@
#![feature(adt_const_params)]
-#![allow(incomplete_features)]
#![warn(clippy::same_functions_in_if_condition)]
-#![allow(clippy::ifs_same_cond)] // This warning is different from `ifs_same_cond`.
-#![allow(clippy::if_same_then_else, clippy::comparison_chain)] // all empty blocks
+// ifs_same_cond warning is different from `ifs_same_cond`.
+// clippy::if_same_then_else, clippy::comparison_chain -- all empty blocks
+#![allow(incomplete_features)]
+#![allow(
+ clippy::comparison_chain,
+ clippy::if_same_then_else,
+ clippy::ifs_same_cond,
+ clippy::uninlined_format_args
+)]
fn function() -> bool {
true
diff --git a/src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr b/src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr
index cd438b830..f352ade15 100644
--- a/src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr
+++ b/src/tools/clippy/tests/ui/same_functions_in_if_condition.stderr
@@ -1,72 +1,72 @@
error: this `if` has the same function call as a previous `if`
- --> $DIR/same_functions_in_if_condition.rs:31:15
+ --> $DIR/same_functions_in_if_condition.rs:37:15
|
LL | } else if function() {
| ^^^^^^^^^^
|
- = note: `-D clippy::same-functions-in-if-condition` implied by `-D warnings`
note: same as this
- --> $DIR/same_functions_in_if_condition.rs:30:8
+ --> $DIR/same_functions_in_if_condition.rs:36:8
|
LL | if function() {
| ^^^^^^^^^^
+ = note: `-D clippy::same-functions-in-if-condition` implied by `-D warnings`
error: this `if` has the same function call as a previous `if`
- --> $DIR/same_functions_in_if_condition.rs:36:15
+ --> $DIR/same_functions_in_if_condition.rs:42:15
|
LL | } else if fn_arg(a) {
| ^^^^^^^^^
|
note: same as this
- --> $DIR/same_functions_in_if_condition.rs:35:8
+ --> $DIR/same_functions_in_if_condition.rs:41:8
|
LL | if fn_arg(a) {
| ^^^^^^^^^
error: this `if` has the same function call as a previous `if`
- --> $DIR/same_functions_in_if_condition.rs:41:15
+ --> $DIR/same_functions_in_if_condition.rs:47:15
|
LL | } else if obj.method() {
| ^^^^^^^^^^^^
|
note: same as this
- --> $DIR/same_functions_in_if_condition.rs:40:8
+ --> $DIR/same_functions_in_if_condition.rs:46:8
|
LL | if obj.method() {
| ^^^^^^^^^^^^
error: this `if` has the same function call as a previous `if`
- --> $DIR/same_functions_in_if_condition.rs:46:15
+ --> $DIR/same_functions_in_if_condition.rs:52:15
|
LL | } else if obj.method_arg(a) {
| ^^^^^^^^^^^^^^^^^
|
note: same as this
- --> $DIR/same_functions_in_if_condition.rs:45:8
+ --> $DIR/same_functions_in_if_condition.rs:51:8
|
LL | if obj.method_arg(a) {
| ^^^^^^^^^^^^^^^^^
error: this `if` has the same function call as a previous `if`
- --> $DIR/same_functions_in_if_condition.rs:53:15
+ --> $DIR/same_functions_in_if_condition.rs:59:15
|
LL | } else if v.pop().is_none() {
| ^^^^^^^^^^^^^^^^^
|
note: same as this
- --> $DIR/same_functions_in_if_condition.rs:51:8
+ --> $DIR/same_functions_in_if_condition.rs:57:8
|
LL | if v.pop().is_none() {
| ^^^^^^^^^^^^^^^^^
error: this `if` has the same function call as a previous `if`
- --> $DIR/same_functions_in_if_condition.rs:58:15
+ --> $DIR/same_functions_in_if_condition.rs:64:15
|
LL | } else if v.len() == 42 {
| ^^^^^^^^^^^^^
|
note: same as this
- --> $DIR/same_functions_in_if_condition.rs:56:8
+ --> $DIR/same_functions_in_if_condition.rs:62:8
|
LL | if v.len() == 42 {
| ^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/same_item_push.stderr b/src/tools/clippy/tests/ui/same_item_push.stderr
index d9ffa1578..1d1254d9f 100644
--- a/src/tools/clippy/tests/ui/same_item_push.stderr
+++ b/src/tools/clippy/tests/ui/same_item_push.stderr
@@ -4,8 +4,8 @@ error: it looks like the same item is being pushed into this Vec
LL | vec.push(item);
| ^^^
|
- = note: `-D clippy::same-item-push` implied by `-D warnings`
= help: try using vec![item;SIZE] or vec.resize(NEW_SIZE, item)
+ = note: `-D clippy::same-item-push` implied by `-D warnings`
error: it looks like the same item is being pushed into this Vec
--> $DIR/same_item_push.rs:29:9
diff --git a/src/tools/clippy/tests/ui/same_name_method.stderr b/src/tools/clippy/tests/ui/same_name_method.stderr
index f55ec9f3c..0c6908c09 100644
--- a/src/tools/clippy/tests/ui/same_name_method.stderr
+++ b/src/tools/clippy/tests/ui/same_name_method.stderr
@@ -4,12 +4,12 @@ error: method's name is the same as an existing method in a trait
LL | fn foo() {}
| ^^^^^^^^^^^
|
- = note: `-D clippy::same-name-method` implied by `-D warnings`
note: existing `foo` defined here
--> $DIR/same_name_method.rs:25:13
|
LL | fn foo() {}
| ^^^^^^^^^^^
+ = note: `-D clippy::same-name-method` implied by `-D warnings`
error: method's name is the same as an existing method in a trait
--> $DIR/same_name_method.rs:35:13
diff --git a/src/tools/clippy/tests/ui/search_is_some.stderr b/src/tools/clippy/tests/ui/search_is_some.stderr
index 54760545b..6bea8c674 100644
--- a/src/tools/clippy/tests/ui/search_is_some.stderr
+++ b/src/tools/clippy/tests/ui/search_is_some.stderr
@@ -8,8 +8,8 @@ LL | | }
LL | | ).is_some();
| |______________________________^
|
- = note: `-D clippy::search-is-some` implied by `-D warnings`
= help: this is more succinctly expressed by calling `any()`
+ = note: `-D clippy::search-is-some` implied by `-D warnings`
error: called `is_some()` after searching an `Iterator` with `position`
--> $DIR/search_is_some.rs:20:13
diff --git a/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs
index c4dfbd921..4ab7dbab5 100644
--- a/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs
+++ b/src/tools/clippy/tests/ui/semicolon_if_nothing_returned.rs
@@ -1,5 +1,5 @@
#![warn(clippy::semicolon_if_nothing_returned)]
-#![allow(clippy::redundant_closure)]
+#![allow(clippy::redundant_closure, clippy::uninlined_format_args)]
fn get_unit() {}
diff --git a/src/tools/clippy/tests/ui/shadow.stderr b/src/tools/clippy/tests/ui/shadow.stderr
index 43d76094d..c3d7bc2a5 100644
--- a/src/tools/clippy/tests/ui/shadow.stderr
+++ b/src/tools/clippy/tests/ui/shadow.stderr
@@ -4,12 +4,12 @@ error: `x` is shadowed by itself in `x`
LL | let x = x;
| ^
|
- = note: `-D clippy::shadow-same` implied by `-D warnings`
note: previous binding is here
--> $DIR/shadow.rs:5:9
|
LL | let x = 1;
| ^
+ = note: `-D clippy::shadow-same` implied by `-D warnings`
error: `mut x` is shadowed by itself in `&x`
--> $DIR/shadow.rs:7:13
@@ -53,12 +53,12 @@ error: `x` is shadowed
LL | let x = x.0;
| ^
|
- = note: `-D clippy::shadow-reuse` implied by `-D warnings`
note: previous binding is here
--> $DIR/shadow.rs:13:9
|
LL | let x = ([[0]], ());
| ^
+ = note: `-D clippy::shadow-reuse` implied by `-D warnings`
error: `x` is shadowed
--> $DIR/shadow.rs:15:9
@@ -150,12 +150,12 @@ error: `x` shadows a previous, unrelated binding
LL | let x = 2;
| ^
|
- = note: `-D clippy::shadow-unrelated` implied by `-D warnings`
note: previous binding is here
--> $DIR/shadow.rs:30:9
|
LL | let x = 1;
| ^
+ = note: `-D clippy::shadow-unrelated` implied by `-D warnings`
error: `x` shadows a previous, unrelated binding
--> $DIR/shadow.rs:36:13
diff --git a/src/tools/clippy/tests/ui/should_impl_trait/method_list_1.stderr b/src/tools/clippy/tests/ui/should_impl_trait/method_list_1.stderr
index 2b7d4628c..161dd66b0 100644
--- a/src/tools/clippy/tests/ui/should_impl_trait/method_list_1.stderr
+++ b/src/tools/clippy/tests/ui/should_impl_trait/method_list_1.stderr
@@ -6,8 +6,8 @@ LL | | unimplemented!()
LL | | }
| |_____^
|
- = note: `-D clippy::should-implement-trait` implied by `-D warnings`
= help: consider implementing the trait `std::ops::Add` or choosing a less ambiguous method name
+ = note: `-D clippy::should-implement-trait` implied by `-D warnings`
error: method `as_mut` can be confused for the standard trait method `std::convert::AsMut::as_mut`
--> $DIR/method_list_1.rs:29:5
@@ -99,6 +99,16 @@ LL | | }
|
= help: consider implementing the trait `std::cmp::Ord` or choosing a less ambiguous method name
+error: method `default` can be confused for the standard trait method `std::default::Default::default`
+ --> $DIR/method_list_1.rs:65:5
+ |
+LL | / pub fn default() -> Self {
+LL | | unimplemented!()
+LL | | }
+ | |_____^
+ |
+ = help: consider implementing the trait `std::default::Default` or choosing a less ambiguous method name
+
error: method `deref` can be confused for the standard trait method `std::ops::Deref::deref`
--> $DIR/method_list_1.rs:69:5
|
@@ -139,5 +149,5 @@ LL | | }
|
= help: consider implementing the trait `std::ops::Drop` or choosing a less ambiguous method name
-error: aborting due to 14 previous errors
+error: aborting due to 15 previous errors
diff --git a/src/tools/clippy/tests/ui/should_impl_trait/method_list_2.stderr b/src/tools/clippy/tests/ui/should_impl_trait/method_list_2.stderr
index b6fd43569..10bfea68f 100644
--- a/src/tools/clippy/tests/ui/should_impl_trait/method_list_2.stderr
+++ b/src/tools/clippy/tests/ui/should_impl_trait/method_list_2.stderr
@@ -6,8 +6,8 @@ LL | | unimplemented!()
LL | | }
| |_____^
|
- = note: `-D clippy::should-implement-trait` implied by `-D warnings`
= help: consider implementing the trait `std::cmp::PartialEq` or choosing a less ambiguous method name
+ = note: `-D clippy::should-implement-trait` implied by `-D warnings`
error: method `from_iter` can be confused for the standard trait method `std::iter::FromIterator::from_iter`
--> $DIR/method_list_2.rs:30:5
diff --git a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs
index 84ecf1ea5..c65df9ece 100644
--- a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs
+++ b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.rs
@@ -1,11 +1,8 @@
// FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934
// // run-rustfix
-
#![warn(clippy::significant_drop_in_scrutinee)]
-#![allow(clippy::single_match)]
-#![allow(clippy::match_single_binding)]
-#![allow(unused_assignments)]
-#![allow(dead_code)]
+#![allow(dead_code, unused_assignments)]
+#![allow(clippy::match_single_binding, clippy::single_match, clippy::uninlined_format_args)]
use std::num::ParseIntError;
use std::ops::Deref;
diff --git a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr
index 88ea6bce2..75063a8c9 100644
--- a/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr
+++ b/src/tools/clippy/tests/ui/significant_drop_in_scrutinee.stderr
@@ -1,5 +1,5 @@
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:59:11
+ --> $DIR/significant_drop_in_scrutinee.rs:56:11
|
LL | match mutex.lock().unwrap().foo() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -10,8 +10,8 @@ LL | mutex.lock().unwrap().bar();
LL | };
| - temporary lives until here
|
- = note: `-D clippy::significant-drop-in-scrutinee` implied by `-D warnings`
= note: this might lead to deadlocks or other unexpected behavior
+ = note: `-D clippy::significant-drop-in-scrutinee` implied by `-D warnings`
help: try moving the temporary above the match
|
LL ~ let value = mutex.lock().unwrap().foo();
@@ -19,7 +19,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:145:11
+ --> $DIR/significant_drop_in_scrutinee.rs:142:11
|
LL | match s.lock_m().get_the_value() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -38,7 +38,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:166:11
+ --> $DIR/significant_drop_in_scrutinee.rs:163:11
|
LL | match s.lock_m_m().get_the_value() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -57,7 +57,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:214:11
+ --> $DIR/significant_drop_in_scrutinee.rs:211:11
|
LL | match counter.temp_increment().len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -73,7 +73,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:237:16
+ --> $DIR/significant_drop_in_scrutinee.rs:234:16
|
LL | match (mutex1.lock().unwrap().s.len(), true) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -92,7 +92,7 @@ LL ~ match (value, true) {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:246:22
+ --> $DIR/significant_drop_in_scrutinee.rs:243:22
|
LL | match (true, mutex1.lock().unwrap().s.len(), true) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -111,7 +111,7 @@ LL ~ match (true, value, true) {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:256:16
+ --> $DIR/significant_drop_in_scrutinee.rs:253:16
|
LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -132,7 +132,7 @@ LL ~ match (value, true, mutex2.lock().unwrap().s.len()) {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:256:54
+ --> $DIR/significant_drop_in_scrutinee.rs:253:54
|
LL | match (mutex1.lock().unwrap().s.len(), true, mutex2.lock().unwrap().s.len()) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -153,7 +153,7 @@ LL ~ match (mutex1.lock().unwrap().s.len(), true, value) {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:267:15
+ --> $DIR/significant_drop_in_scrutinee.rs:264:15
|
LL | match mutex3.lock().unwrap().s.as_str() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -169,7 +169,7 @@ LL | };
= note: this might lead to deadlocks or other unexpected behavior
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:277:22
+ --> $DIR/significant_drop_in_scrutinee.rs:274:22
|
LL | match (true, mutex3.lock().unwrap().s.as_str()) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -185,7 +185,7 @@ LL | };
= note: this might lead to deadlocks or other unexpected behavior
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:296:11
+ --> $DIR/significant_drop_in_scrutinee.rs:293:11
|
LL | match mutex.lock().unwrap().s.len() > 1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -204,7 +204,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:303:11
+ --> $DIR/significant_drop_in_scrutinee.rs:300:11
|
LL | match 1 < mutex.lock().unwrap().s.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -223,7 +223,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:321:11
+ --> $DIR/significant_drop_in_scrutinee.rs:318:11
|
LL | match mutex1.lock().unwrap().s.len() < mutex2.lock().unwrap().s.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -244,7 +244,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:332:11
+ --> $DIR/significant_drop_in_scrutinee.rs:329:11
|
LL | match mutex1.lock().unwrap().s.len() >= mutex2.lock().unwrap().s.len() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -265,7 +265,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:367:11
+ --> $DIR/significant_drop_in_scrutinee.rs:364:11
|
LL | match get_mutex_guard().s.len() > 1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -284,7 +284,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:384:11
+ --> $DIR/significant_drop_in_scrutinee.rs:381:11
|
LL | match match i {
| ___________^
@@ -316,7 +316,7 @@ LL ~ match value
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:410:11
+ --> $DIR/significant_drop_in_scrutinee.rs:407:11
|
LL | match if i > 1 {
| ___________^
@@ -349,7 +349,7 @@ LL ~ match value
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:464:11
+ --> $DIR/significant_drop_in_scrutinee.rs:461:11
|
LL | match s.lock().deref().deref() {
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -367,7 +367,7 @@ LL ~ match value {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:492:11
+ --> $DIR/significant_drop_in_scrutinee.rs:489:11
|
LL | match s.lock().deref().deref() {
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -380,7 +380,7 @@ LL | };
= note: this might lead to deadlocks or other unexpected behavior
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:511:11
+ --> $DIR/significant_drop_in_scrutinee.rs:508:11
|
LL | match mutex.lock().unwrap().i = i {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -399,7 +399,7 @@ LL ~ match () {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:517:11
+ --> $DIR/significant_drop_in_scrutinee.rs:514:11
|
LL | match i = mutex.lock().unwrap().i {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -418,7 +418,7 @@ LL ~ match () {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:523:11
+ --> $DIR/significant_drop_in_scrutinee.rs:520:11
|
LL | match mutex.lock().unwrap().i += 1 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -437,7 +437,7 @@ LL ~ match () {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:529:11
+ --> $DIR/significant_drop_in_scrutinee.rs:526:11
|
LL | match i += mutex.lock().unwrap().i {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -456,7 +456,7 @@ LL ~ match () {
|
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:592:11
+ --> $DIR/significant_drop_in_scrutinee.rs:589:11
|
LL | match rwlock.read().unwrap().to_number() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -467,7 +467,7 @@ LL | };
= note: this might lead to deadlocks or other unexpected behavior
error: temporary with significant `Drop` in `for` loop condition will live until the end of the `for` expression
- --> $DIR/significant_drop_in_scrutinee.rs:602:14
+ --> $DIR/significant_drop_in_scrutinee.rs:599:14
|
LL | for s in rwlock.read().unwrap().iter() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -478,7 +478,7 @@ LL | }
= note: this might lead to deadlocks or other unexpected behavior
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
- --> $DIR/significant_drop_in_scrutinee.rs:617:11
+ --> $DIR/significant_drop_in_scrutinee.rs:614:11
|
LL | match mutex.lock().unwrap().foo() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/similar_names.stderr b/src/tools/clippy/tests/ui/similar_names.stderr
index 6e7726938..43c5cee4b 100644
--- a/src/tools/clippy/tests/ui/similar_names.stderr
+++ b/src/tools/clippy/tests/ui/similar_names.stderr
@@ -4,12 +4,12 @@ error: binding's name is too similar to existing binding
LL | let bpple: i32;
| ^^^^^
|
- = note: `-D clippy::similar-names` implied by `-D warnings`
note: existing binding defined here
--> $DIR/similar_names.rs:19:9
|
LL | let apple: i32;
| ^^^^^
+ = note: `-D clippy::similar-names` implied by `-D warnings`
error: binding's name is too similar to existing binding
--> $DIR/similar_names.rs:23:9
diff --git a/src/tools/clippy/tests/ui/single_char_lifetime_names.stderr b/src/tools/clippy/tests/ui/single_char_lifetime_names.stderr
index 1438b3999..bfe6d44b5 100644
--- a/src/tools/clippy/tests/ui/single_char_lifetime_names.stderr
+++ b/src/tools/clippy/tests/ui/single_char_lifetime_names.stderr
@@ -4,8 +4,8 @@ error: single-character lifetime names are likely uninformative
LL | struct DiagnosticCtx<'a, 'b>
| ^^
|
- = note: `-D clippy::single-char-lifetime-names` implied by `-D warnings`
= help: use a more informative name
+ = note: `-D clippy::single-char-lifetime-names` implied by `-D warnings`
error: single-character lifetime names are likely uninformative
--> $DIR/single_char_lifetime_names.rs:5:26
diff --git a/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr b/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr
index cf990be1b..633546f64 100644
--- a/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr
+++ b/src/tools/clippy/tests/ui/single_component_path_imports_nested_first.stderr
@@ -4,8 +4,8 @@ error: this import is redundant
LL | use {regex, serde};
| ^^^^^
|
- = note: `-D clippy::single-component-path-imports` implied by `-D warnings`
= help: remove this import
+ = note: `-D clippy::single-component-path-imports` implied by `-D warnings`
error: this import is redundant
--> $DIR/single_component_path_imports_nested_first.rs:13:17
diff --git a/src/tools/clippy/tests/ui/single_match.rs b/src/tools/clippy/tests/ui/single_match.rs
index dd148edf5..d0c9b7b56 100644
--- a/src/tools/clippy/tests/ui/single_match.rs
+++ b/src/tools/clippy/tests/ui/single_match.rs
@@ -1,4 +1,5 @@
#![warn(clippy::single_match)]
+#![allow(clippy::uninlined_format_args)]
fn dummy() {}
diff --git a/src/tools/clippy/tests/ui/single_match.stderr b/src/tools/clippy/tests/ui/single_match.stderr
index 4d2b9ec5f..7cecc1b73 100644
--- a/src/tools/clippy/tests/ui/single_match.stderr
+++ b/src/tools/clippy/tests/ui/single_match.stderr
@@ -1,5 +1,5 @@
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:8:5
+ --> $DIR/single_match.rs:9:5
|
LL | / match x {
LL | | Some(y) => {
@@ -18,7 +18,7 @@ LL ~ };
|
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:16:5
+ --> $DIR/single_match.rs:17:5
|
LL | / match x {
LL | | // Note the missing block braces.
@@ -30,7 +30,7 @@ LL | | }
| |_____^ help: try this: `if let Some(y) = x { println!("{:?}", y) }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:25:5
+ --> $DIR/single_match.rs:26:5
|
LL | / match z {
LL | | (2..=3, 7..=9) => dummy(),
@@ -39,7 +39,7 @@ LL | | };
| |_____^ help: try this: `if let (2..=3, 7..=9) = z { dummy() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:54:5
+ --> $DIR/single_match.rs:55:5
|
LL | / match x {
LL | | Some(y) => dummy(),
@@ -48,7 +48,7 @@ LL | | };
| |_____^ help: try this: `if let Some(y) = x { dummy() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:59:5
+ --> $DIR/single_match.rs:60:5
|
LL | / match y {
LL | | Ok(y) => dummy(),
@@ -57,7 +57,7 @@ LL | | };
| |_____^ help: try this: `if let Ok(y) = y { dummy() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:66:5
+ --> $DIR/single_match.rs:67:5
|
LL | / match c {
LL | | Cow::Borrowed(..) => dummy(),
@@ -66,7 +66,7 @@ LL | | };
| |_____^ help: try this: `if let Cow::Borrowed(..) = c { dummy() }`
error: you seem to be trying to use `match` for an equality check. Consider using `if`
- --> $DIR/single_match.rs:87:5
+ --> $DIR/single_match.rs:88:5
|
LL | / match x {
LL | | "test" => println!(),
@@ -75,7 +75,7 @@ LL | | }
| |_____^ help: try this: `if x == "test" { println!() }`
error: you seem to be trying to use `match` for an equality check. Consider using `if`
- --> $DIR/single_match.rs:100:5
+ --> $DIR/single_match.rs:101:5
|
LL | / match x {
LL | | Foo::A => println!(),
@@ -84,7 +84,7 @@ LL | | }
| |_____^ help: try this: `if x == Foo::A { println!() }`
error: you seem to be trying to use `match` for an equality check. Consider using `if`
- --> $DIR/single_match.rs:106:5
+ --> $DIR/single_match.rs:107:5
|
LL | / match x {
LL | | FOO_C => println!(),
@@ -93,7 +93,7 @@ LL | | }
| |_____^ help: try this: `if x == FOO_C { println!() }`
error: you seem to be trying to use `match` for an equality check. Consider using `if`
- --> $DIR/single_match.rs:111:5
+ --> $DIR/single_match.rs:112:5
|
LL | / match &&x {
LL | | Foo::A => println!(),
@@ -102,7 +102,7 @@ LL | | }
| |_____^ help: try this: `if x == Foo::A { println!() }`
error: you seem to be trying to use `match` for an equality check. Consider using `if`
- --> $DIR/single_match.rs:117:5
+ --> $DIR/single_match.rs:118:5
|
LL | / match &x {
LL | | Foo::A => println!(),
@@ -111,7 +111,7 @@ LL | | }
| |_____^ help: try this: `if x == &Foo::A { println!() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:134:5
+ --> $DIR/single_match.rs:135:5
|
LL | / match x {
LL | | Bar::A => println!(),
@@ -120,7 +120,7 @@ LL | | }
| |_____^ help: try this: `if let Bar::A = x { println!() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:142:5
+ --> $DIR/single_match.rs:143:5
|
LL | / match x {
LL | | None => println!(),
@@ -129,7 +129,7 @@ LL | | };
| |_____^ help: try this: `if let None = x { println!() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:164:5
+ --> $DIR/single_match.rs:165:5
|
LL | / match x {
LL | | (Some(_), _) => {},
@@ -138,7 +138,7 @@ LL | | }
| |_____^ help: try this: `if let (Some(_), _) = x {}`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:170:5
+ --> $DIR/single_match.rs:171:5
|
LL | / match x {
LL | | (Some(E::V), _) => todo!(),
@@ -147,7 +147,7 @@ LL | | }
| |_____^ help: try this: `if let (Some(E::V), _) = x { todo!() }`
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match.rs:176:5
+ --> $DIR/single_match.rs:177:5
|
LL | / match (Some(42), Some(E::V), Some(42)) {
LL | | (.., Some(E::V), _) => {},
diff --git a/src/tools/clippy/tests/ui/single_match_else.rs b/src/tools/clippy/tests/ui/single_match_else.rs
index 70d6febb7..5d03f77e9 100644
--- a/src/tools/clippy/tests/ui/single_match_else.rs
+++ b/src/tools/clippy/tests/ui/single_match_else.rs
@@ -1,8 +1,6 @@
// aux-build: proc_macro_with_span.rs
-
#![warn(clippy::single_match_else)]
-#![allow(clippy::needless_return)]
-#![allow(clippy::no_effect)]
+#![allow(clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)]
extern crate proc_macro_with_span;
use proc_macro_with_span::with_span;
diff --git a/src/tools/clippy/tests/ui/single_match_else.stderr b/src/tools/clippy/tests/ui/single_match_else.stderr
index 38fd9c6a6..62876a55d 100644
--- a/src/tools/clippy/tests/ui/single_match_else.stderr
+++ b/src/tools/clippy/tests/ui/single_match_else.stderr
@@ -1,5 +1,5 @@
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match_else.rs:19:13
+ --> $DIR/single_match_else.rs:17:13
|
LL | let _ = match ExprNode::Butterflies {
| _____________^
@@ -21,7 +21,7 @@ LL ~ };
|
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match_else.rs:84:5
+ --> $DIR/single_match_else.rs:82:5
|
LL | / match Some(1) {
LL | | Some(a) => println!("${:?}", a),
@@ -41,7 +41,7 @@ LL + }
|
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match_else.rs:93:5
+ --> $DIR/single_match_else.rs:91:5
|
LL | / match Some(1) {
LL | | Some(a) => println!("${:?}", a),
@@ -61,7 +61,7 @@ LL + }
|
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match_else.rs:103:5
+ --> $DIR/single_match_else.rs:101:5
|
LL | / match Result::<i32, Infallible>::Ok(1) {
LL | | Ok(a) => println!("${:?}", a),
@@ -81,7 +81,7 @@ LL + }
|
error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
- --> $DIR/single_match_else.rs:112:5
+ --> $DIR/single_match_else.rs:110:5
|
LL | / match Cow::from("moo") {
LL | | Cow::Owned(a) => println!("${:?}", a),
diff --git a/src/tools/clippy/tests/ui/size_of_in_element_count/expressions.stderr b/src/tools/clippy/tests/ui/size_of_in_element_count/expressions.stderr
index 0f0dff57f..037f695f3 100644
--- a/src/tools/clippy/tests/ui/size_of_in_element_count/expressions.stderr
+++ b/src/tools/clippy/tests/ui/size_of_in_element_count/expressions.stderr
@@ -4,8 +4,8 @@ error: found a count of bytes instead of a count of elements of `T`
LL | unsafe { copy_nonoverlapping(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>() * SIZE) };
| ^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::size-of-in-element-count` implied by `-D warnings`
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
+ = note: `-D clippy::size-of-in-element-count` implied by `-D warnings`
error: found a count of bytes instead of a count of elements of `T`
--> $DIR/expressions.rs:18:62
diff --git a/src/tools/clippy/tests/ui/size_of_in_element_count/functions.stderr b/src/tools/clippy/tests/ui/size_of_in_element_count/functions.stderr
index c1e824167..4351e6a14 100644
--- a/src/tools/clippy/tests/ui/size_of_in_element_count/functions.stderr
+++ b/src/tools/clippy/tests/ui/size_of_in_element_count/functions.stderr
@@ -4,8 +4,8 @@ error: found a count of bytes instead of a count of elements of `T`
LL | unsafe { copy_nonoverlapping::<u8>(x.as_ptr(), y.as_mut_ptr(), size_of::<u8>()) };
| ^^^^^^^^^^^^^^^
|
- = note: `-D clippy::size-of-in-element-count` implied by `-D warnings`
= help: use a count of elements instead of a count of bytes, it already gets multiplied by the size of the type
+ = note: `-D clippy::size-of-in-element-count` implied by `-D warnings`
error: found a count of bytes instead of a count of elements of `T`
--> $DIR/functions.rs:19:62
diff --git a/src/tools/clippy/tests/ui/skip_while_next.stderr b/src/tools/clippy/tests/ui/skip_while_next.stderr
index 269cc1346..7308ab4e5 100644
--- a/src/tools/clippy/tests/ui/skip_while_next.stderr
+++ b/src/tools/clippy/tests/ui/skip_while_next.stderr
@@ -4,8 +4,8 @@ error: called `skip_while(<p>).next()` on an `Iterator`
LL | let _ = v.iter().skip_while(|&x| *x < 0).next();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::skip-while-next` implied by `-D warnings`
= help: this is more succinctly expressed by calling `.find(!<p>)` instead
+ = note: `-D clippy::skip-while-next` implied by `-D warnings`
error: called `skip_while(<p>).next()` on an `Iterator`
--> $DIR/skip_while_next.rs:17:13
diff --git a/src/tools/clippy/tests/ui/stable_sort_primitive.stderr b/src/tools/clippy/tests/ui/stable_sort_primitive.stderr
index c35e0c22a..1432fdcff 100644
--- a/src/tools/clippy/tests/ui/stable_sort_primitive.stderr
+++ b/src/tools/clippy/tests/ui/stable_sort_primitive.stderr
@@ -4,8 +4,8 @@ error: used `sort` on primitive type `i32`
LL | vec.sort();
| ^^^^^^^^^^ help: try: `vec.sort_unstable()`
|
- = note: `-D clippy::stable-sort-primitive` implied by `-D warnings`
= note: an unstable sort typically performs faster without any observable difference for this data type
+ = note: `-D clippy::stable-sort-primitive` implied by `-D warnings`
error: used `sort` on primitive type `bool`
--> $DIR/stable_sort_primitive.rs:9:5
diff --git a/src/tools/clippy/tests/ui/std_instead_of_core.rs b/src/tools/clippy/tests/ui/std_instead_of_core.rs
index 6b27475de..75b114ba0 100644
--- a/src/tools/clippy/tests/ui/std_instead_of_core.rs
+++ b/src/tools/clippy/tests/ui/std_instead_of_core.rs
@@ -24,6 +24,12 @@ fn std_instead_of_core() {
let cell_absolute = ::std::cell::Cell::new(8u32);
let _ = std::env!("PATH");
+
+ // do not lint until `error_in_core` is stable
+ use std::error::Error;
+
+ // lint items re-exported from private modules, `core::iter::traits::iterator::Iterator`
+ use std::iter::Iterator;
}
#[warn(clippy::std_instead_of_alloc)]
diff --git a/src/tools/clippy/tests/ui/std_instead_of_core.stderr b/src/tools/clippy/tests/ui/std_instead_of_core.stderr
index bc49dabf5..d21024973 100644
--- a/src/tools/clippy/tests/ui/std_instead_of_core.stderr
+++ b/src/tools/clippy/tests/ui/std_instead_of_core.stderr
@@ -4,8 +4,8 @@ error: used import from `std` instead of `core`
LL | use std::hash::Hasher;
| ^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::std-instead-of-core` implied by `-D warnings`
= help: consider importing the item from `core`
+ = note: `-D clippy::std-instead-of-core` implied by `-D warnings`
error: used import from `std` instead of `core`
--> $DIR/std_instead_of_core.rs:11:9
@@ -63,17 +63,25 @@ LL | let cell_absolute = ::std::cell::Cell::new(8u32);
|
= help: consider importing the item from `core`
-error: used import from `std` instead of `alloc`
+error: used import from `std` instead of `core`
--> $DIR/std_instead_of_core.rs:32:9
|
+LL | use std::iter::Iterator;
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = help: consider importing the item from `core`
+
+error: used import from `std` instead of `alloc`
+ --> $DIR/std_instead_of_core.rs:38:9
+ |
LL | use std::vec;
| ^^^^^^^^
|
- = note: `-D clippy::std-instead-of-alloc` implied by `-D warnings`
= help: consider importing the item from `alloc`
+ = note: `-D clippy::std-instead-of-alloc` implied by `-D warnings`
error: used import from `std` instead of `alloc`
- --> $DIR/std_instead_of_core.rs:33:9
+ --> $DIR/std_instead_of_core.rs:39:9
|
LL | use std::vec::Vec;
| ^^^^^^^^^^^^^
@@ -81,13 +89,13 @@ LL | use std::vec::Vec;
= help: consider importing the item from `alloc`
error: used import from `alloc` instead of `core`
- --> $DIR/std_instead_of_core.rs:38:9
+ --> $DIR/std_instead_of_core.rs:44:9
|
LL | use alloc::slice::from_ref;
| ^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::alloc-instead-of-core` implied by `-D warnings`
= help: consider importing the item from `core`
+ = note: `-D clippy::alloc-instead-of-core` implied by `-D warnings`
-error: aborting due to 11 previous errors
+error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/str_to_string.stderr b/src/tools/clippy/tests/ui/str_to_string.stderr
index b1f73eda5..1d47da571 100644
--- a/src/tools/clippy/tests/ui/str_to_string.stderr
+++ b/src/tools/clippy/tests/ui/str_to_string.stderr
@@ -4,8 +4,8 @@ error: `to_string()` called on a `&str`
LL | let hello = "hello world".to_string();
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::str-to-string` implied by `-D warnings`
= help: consider using `.to_owned()`
+ = note: `-D clippy::str-to-string` implied by `-D warnings`
error: `to_string()` called on a `&str`
--> $DIR/str_to_string.rs:6:5
diff --git a/src/tools/clippy/tests/ui/string_to_string.stderr b/src/tools/clippy/tests/ui/string_to_string.stderr
index 1ebd17999..e304c3e34 100644
--- a/src/tools/clippy/tests/ui/string_to_string.stderr
+++ b/src/tools/clippy/tests/ui/string_to_string.stderr
@@ -4,8 +4,8 @@ error: `to_string()` called on a `String`
LL | let mut v = message.to_string();
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::string-to-string` implied by `-D warnings`
= help: consider using `.clone()`
+ = note: `-D clippy::string-to-string` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/struct_excessive_bools.stderr b/src/tools/clippy/tests/ui/struct_excessive_bools.stderr
index 2941bf298..e4d50043a 100644
--- a/src/tools/clippy/tests/ui/struct_excessive_bools.stderr
+++ b/src/tools/clippy/tests/ui/struct_excessive_bools.stderr
@@ -9,8 +9,8 @@ LL | | d: bool,
LL | | }
| |_^
|
- = note: `-D clippy::struct-excessive-bools` implied by `-D warnings`
= help: consider using a state machine or refactoring bools into two-variant enums
+ = note: `-D clippy::struct-excessive-bools` implied by `-D warnings`
error: more than 3 bools in a struct
--> $DIR/struct_excessive_bools.rs:38:5
diff --git a/src/tools/clippy/tests/ui/suspicious_else_formatting.stderr b/src/tools/clippy/tests/ui/suspicious_else_formatting.stderr
index ee68eb5a7..2e512b47f 100644
--- a/src/tools/clippy/tests/ui/suspicious_else_formatting.stderr
+++ b/src/tools/clippy/tests/ui/suspicious_else_formatting.stderr
@@ -4,8 +4,8 @@ error: this looks like an `else {..}` but the `else` is missing
LL | } {
| ^
|
- = note: `-D clippy::suspicious-else-formatting` implied by `-D warnings`
= note: to remove this lint, add the missing `else` or add a new line before the next block
+ = note: `-D clippy::suspicious-else-formatting` implied by `-D warnings`
error: this looks like an `else if` but the `else` is missing
--> $DIR/suspicious_else_formatting.rs:21:6
diff --git a/src/tools/clippy/tests/ui/suspicious_map.stderr b/src/tools/clippy/tests/ui/suspicious_map.stderr
index 3ffcd1a90..e25167481 100644
--- a/src/tools/clippy/tests/ui/suspicious_map.stderr
+++ b/src/tools/clippy/tests/ui/suspicious_map.stderr
@@ -4,8 +4,8 @@ error: this call to `map()` won't have an effect on the call to `count()`
LL | let _ = (0..3).map(|x| x + 2).count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::suspicious-map` implied by `-D warnings`
= help: make sure you did not confuse `map` with `filter`, `for_each` or `inspect`
+ = note: `-D clippy::suspicious-map` implied by `-D warnings`
error: this call to `map()` won't have an effect on the call to `count()`
--> $DIR/suspicious_map.rs:7:13
diff --git a/src/tools/clippy/tests/ui/suspicious_splitn.stderr b/src/tools/clippy/tests/ui/suspicious_splitn.stderr
index 3bcd681fa..55ce63d4f 100644
--- a/src/tools/clippy/tests/ui/suspicious_splitn.stderr
+++ b/src/tools/clippy/tests/ui/suspicious_splitn.stderr
@@ -4,8 +4,8 @@ error: `splitn` called with `0` splits
LL | let _ = "a,b".splitn(0, ',');
| ^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::suspicious-splitn` implied by `-D warnings`
= note: the resulting iterator will always return `None`
+ = note: `-D clippy::suspicious-splitn` implied by `-D warnings`
error: `rsplitn` called with `0` splits
--> $DIR/suspicious_splitn.rs:11:13
diff --git a/src/tools/clippy/tests/ui/suspicious_to_owned.stderr b/src/tools/clippy/tests/ui/suspicious_to_owned.stderr
index 92e1024bf..ae1aec34d 100644
--- a/src/tools/clippy/tests/ui/suspicious_to_owned.stderr
+++ b/src/tools/clippy/tests/ui/suspicious_to_owned.stderr
@@ -1,4 +1,4 @@
-error: this `to_owned` call clones the std::borrow::Cow<str> itself and does not cause the std::borrow::Cow<str> contents to become owned
+error: this `to_owned` call clones the std::borrow::Cow<'_, str> itself and does not cause the std::borrow::Cow<'_, str> contents to become owned
--> $DIR/suspicious_to_owned.rs:16:13
|
LL | let _ = cow.to_owned();
@@ -6,19 +6,19 @@ LL | let _ = cow.to_owned();
|
= note: `-D clippy::suspicious-to-owned` implied by `-D warnings`
-error: this `to_owned` call clones the std::borrow::Cow<[char; 3]> itself and does not cause the std::borrow::Cow<[char; 3]> contents to become owned
+error: this `to_owned` call clones the std::borrow::Cow<'_, [char; 3]> itself and does not cause the std::borrow::Cow<'_, [char; 3]> contents to become owned
--> $DIR/suspicious_to_owned.rs:26:13
|
LL | let _ = cow.to_owned();
| ^^^^^^^^^^^^^^ help: consider using, depending on intent: `cow.clone()` or `cow.into_owned()`
-error: this `to_owned` call clones the std::borrow::Cow<std::vec::Vec<char>> itself and does not cause the std::borrow::Cow<std::vec::Vec<char>> contents to become owned
+error: this `to_owned` call clones the std::borrow::Cow<'_, std::vec::Vec<char>> itself and does not cause the std::borrow::Cow<'_, std::vec::Vec<char>> contents to become owned
--> $DIR/suspicious_to_owned.rs:36:13
|
LL | let _ = cow.to_owned();
| ^^^^^^^^^^^^^^ help: consider using, depending on intent: `cow.clone()` or `cow.into_owned()`
-error: this `to_owned` call clones the std::borrow::Cow<str> itself and does not cause the std::borrow::Cow<str> contents to become owned
+error: this `to_owned` call clones the std::borrow::Cow<'_, str> itself and does not cause the std::borrow::Cow<'_, str> contents to become owned
--> $DIR/suspicious_to_owned.rs:46:13
|
LL | let _ = cow.to_owned();
diff --git a/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.stderr b/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.stderr
index 581527dcf..9f1289ccb 100644
--- a/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.stderr
+++ b/src/tools/clippy/tests/ui/suspicious_unary_op_formatting.stderr
@@ -4,8 +4,8 @@ error: by not having a space between `>` and `-` it looks like `>-` is a single
LL | if a >- 30 {}
| ^^^^
|
- = note: `-D clippy::suspicious-unary-op-formatting` implied by `-D warnings`
= help: put a space between `>` and `-` and remove the space after `-`
+ = note: `-D clippy::suspicious-unary-op-formatting` implied by `-D warnings`
error: by not having a space between `>=` and `-` it looks like `>=-` is a single operator
--> $DIR/suspicious_unary_op_formatting.rs:9:9
diff --git a/src/tools/clippy/tests/ui/swap.stderr b/src/tools/clippy/tests/ui/swap.stderr
index 2b556b475..ee4b7a508 100644
--- a/src/tools/clippy/tests/ui/swap.stderr
+++ b/src/tools/clippy/tests/ui/swap.stderr
@@ -6,8 +6,8 @@ LL | | bar.a = bar.b;
LL | | bar.b = temp;
| |________________^ help: try: `std::mem::swap(&mut bar.a, &mut bar.b)`
|
- = note: `-D clippy::manual-swap` implied by `-D warnings`
= note: or maybe you should use `std::mem::replace`?
+ = note: `-D clippy::manual-swap` implied by `-D warnings`
error: this looks like you are swapping elements of `foo` manually
--> $DIR/swap.rs:36:5
@@ -96,8 +96,8 @@ LL | / a = b;
LL | | b = a;
| |_________^ help: try: `std::mem::swap(&mut a, &mut b)`
|
- = note: `-D clippy::almost-swapped` implied by `-D warnings`
= note: or maybe you should use `std::mem::replace`?
+ = note: `-D clippy::almost-swapped` implied by `-D warnings`
error: this looks like you are trying to swap `c.0` and `a`
--> $DIR/swap.rs:140:5
diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed b/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed
index b129d95c5..09fb66ca3 100644
--- a/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed
+++ b/src/tools/clippy/tests/ui/toplevel_ref_arg.fixed
@@ -1,7 +1,7 @@
// run-rustfix
// aux-build:macro_rules.rs
-
#![warn(clippy::toplevel_ref_arg)]
+#![allow(clippy::uninlined_format_args)]
#[macro_use]
extern crate macro_rules;
diff --git a/src/tools/clippy/tests/ui/toplevel_ref_arg.rs b/src/tools/clippy/tests/ui/toplevel_ref_arg.rs
index 73eb4ff73..9d1f2f810 100644
--- a/src/tools/clippy/tests/ui/toplevel_ref_arg.rs
+++ b/src/tools/clippy/tests/ui/toplevel_ref_arg.rs
@@ -1,7 +1,7 @@
// run-rustfix
// aux-build:macro_rules.rs
-
#![warn(clippy::toplevel_ref_arg)]
+#![allow(clippy::uninlined_format_args)]
#[macro_use]
extern crate macro_rules;
diff --git a/src/tools/clippy/tests/ui/trailing_empty_array.stderr b/src/tools/clippy/tests/ui/trailing_empty_array.stderr
index 9e2bd31d9..2e1484400 100644
--- a/src/tools/clippy/tests/ui/trailing_empty_array.stderr
+++ b/src/tools/clippy/tests/ui/trailing_empty_array.stderr
@@ -7,8 +7,8 @@ LL | | last: [usize; 0],
LL | | }
| |_^
|
- = note: `-D clippy::trailing-empty-array` implied by `-D warnings`
= help: consider annotating `RarelyUseful` with `#[repr(C)]` or another `repr` attribute
+ = note: `-D clippy::trailing-empty-array` implied by `-D warnings`
error: trailing zero-sized array in a struct which is not marked with a `repr` attribute
--> $DIR/trailing_empty_array.rs:10:1
diff --git a/src/tools/clippy/tests/ui/trait_duplication_in_bounds_unfixable.stderr b/src/tools/clippy/tests/ui/trait_duplication_in_bounds_unfixable.stderr
index fbd9abb00..4d56a9464 100644
--- a/src/tools/clippy/tests/ui/trait_duplication_in_bounds_unfixable.stderr
+++ b/src/tools/clippy/tests/ui/trait_duplication_in_bounds_unfixable.stderr
@@ -4,12 +4,12 @@ error: this trait bound is already specified in the where clause
LL | fn bad_foo<T: Clone + Default, Z: Copy>(arg0: T, arg1: Z)
| ^^^^^
|
+ = help: consider removing this trait bound
note: the lint level is defined here
--> $DIR/trait_duplication_in_bounds_unfixable.rs:1:9
|
LL | #![deny(clippy::trait_duplication_in_bounds)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: consider removing this trait bound
error: this trait bound is already specified in the where clause
--> $DIR/trait_duplication_in_bounds_unfixable.rs:6:23
diff --git a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr
index 2993e5e7b..10117ee91 100644
--- a/src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr
+++ b/src/tools/clippy/tests/ui/transmute_ptr_to_ref.stderr
@@ -42,13 +42,13 @@ error: transmute from a pointer type (`*mut U`) to a reference type (`&T`)
LL | let _: &T = std::mem::transmute(om);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(om as *const T)`
-error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<u8>`)
+error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<'_, u8>`)
--> $DIR/transmute_ptr_to_ref.rs:36:32
|
LL | let _: &Foo<u8> = unsafe { std::mem::transmute::<_, &Foo<_>>(raw) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*raw.cast::<Foo<_>>()`
-error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<&u8>`)
+error: transmute from a pointer type (`*const i32`) to a reference type (`&_issue1231::Foo<'_, &u8>`)
--> $DIR/transmute_ptr_to_ref.rs:38:33
|
LL | let _: &Foo<&u8> = unsafe { std::mem::transmute::<_, &Foo<&_>>(raw) };
diff --git a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed
index 539239fc1..7263abac1 100644
--- a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed
+++ b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.fixed
@@ -8,7 +8,7 @@
use std::mem::{size_of, transmute};
-// rustc_typeck::check::cast contains documentation about when a cast `e as U` is
+// rustc_hir_analysis::check::cast contains documentation about when a cast `e as U` is
// valid, which we quote from below.
fn main() {
// We should see an error message for each transmute, and no error messages for
diff --git a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs
index b9e446dc8..d8e4421d4 100644
--- a/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs
+++ b/src/tools/clippy/tests/ui/transmutes_expressible_as_ptr_casts.rs
@@ -8,7 +8,7 @@
use std::mem::{size_of, transmute};
-// rustc_typeck::check::cast contains documentation about when a cast `e as U` is
+// rustc_hir_analysis::check::cast contains documentation about when a cast `e as U` is
// valid, which we quote from below.
fn main() {
// We should see an error message for each transmute, and no error messages for
diff --git a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs
index c0c64ebca..af4f3b184 100644
--- a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs
+++ b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.rs
@@ -1,8 +1,11 @@
// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)"
// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)"
-
#![deny(clippy::trivially_copy_pass_by_ref)]
-#![allow(clippy::disallowed_names, clippy::redundant_field_names)]
+#![allow(
+ clippy::disallowed_names,
+ clippy::redundant_field_names,
+ clippy::uninlined_format_args
+)]
#[derive(Copy, Clone)]
struct Foo(u32);
diff --git a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr
index 66ecb3d8e..6a8eca965 100644
--- a/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr
+++ b/src/tools/clippy/tests/ui/trivially_copy_pass_by_ref.stderr
@@ -1,113 +1,113 @@
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:47:11
+ --> $DIR/trivially_copy_pass_by_ref.rs:50:11
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
|
note: the lint level is defined here
- --> $DIR/trivially_copy_pass_by_ref.rs:4:9
+ --> $DIR/trivially_copy_pass_by_ref.rs:3:9
|
LL | #![deny(clippy::trivially_copy_pass_by_ref)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:47:20
+ --> $DIR/trivially_copy_pass_by_ref.rs:50:20
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:47:29
+ --> $DIR/trivially_copy_pass_by_ref.rs:50:29
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:54:12
+ --> $DIR/trivially_copy_pass_by_ref.rs:57:12
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^^ help: consider passing by value instead: `self`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:54:22
+ --> $DIR/trivially_copy_pass_by_ref.rs:57:22
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:54:31
+ --> $DIR/trivially_copy_pass_by_ref.rs:57:31
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:54:40
+ --> $DIR/trivially_copy_pass_by_ref.rs:57:40
|
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:56:16
+ --> $DIR/trivially_copy_pass_by_ref.rs:59:16
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:56:25
+ --> $DIR/trivially_copy_pass_by_ref.rs:59:25
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:56:34
+ --> $DIR/trivially_copy_pass_by_ref.rs:59:34
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:58:35
+ --> $DIR/trivially_copy_pass_by_ref.rs:61:35
|
LL | fn bad_issue7518(self, other: &Self) {}
| ^^^^^ help: consider passing by value instead: `Self`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:70:16
+ --> $DIR/trivially_copy_pass_by_ref.rs:73:16
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:70:25
+ --> $DIR/trivially_copy_pass_by_ref.rs:73:25
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:70:34
+ --> $DIR/trivially_copy_pass_by_ref.rs:73:34
|
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Baz`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:74:34
+ --> $DIR/trivially_copy_pass_by_ref.rs:77:34
|
LL | fn trait_method(&self, _foo: &Foo);
| ^^^^ help: consider passing by value instead: `Foo`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:106:21
+ --> $DIR/trivially_copy_pass_by_ref.rs:109:21
|
LL | fn foo_never(x: &i32) {
| ^^^^ help: consider passing by value instead: `i32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:111:15
+ --> $DIR/trivially_copy_pass_by_ref.rs:114:15
|
LL | fn foo(x: &i32) {
| ^^^^ help: consider passing by value instead: `i32`
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
- --> $DIR/trivially_copy_pass_by_ref.rs:138:37
+ --> $DIR/trivially_copy_pass_by_ref.rs:141:37
|
LL | fn _unrelated_lifetimes<'a, 'b>(_x: &'a u32, y: &'b u32) -> &'b u32 {
| ^^^^^^^ help: consider passing by value instead: `u32`
diff --git a/src/tools/clippy/tests/ui/type_repetition_in_bounds.stderr b/src/tools/clippy/tests/ui/type_repetition_in_bounds.stderr
index 1d8871481..70d700c1c 100644
--- a/src/tools/clippy/tests/ui/type_repetition_in_bounds.stderr
+++ b/src/tools/clippy/tests/ui/type_repetition_in_bounds.stderr
@@ -4,12 +4,12 @@ error: this type has already been used as a bound predicate
LL | T: Clone,
| ^^^^^^^^
|
+ = help: consider combining the bounds: `T: Copy + Clone`
note: the lint level is defined here
--> $DIR/type_repetition_in_bounds.rs:1:9
|
LL | #![deny(clippy::type_repetition_in_bounds)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: consider combining the bounds: `T: Copy + Clone`
error: this type has already been used as a bound predicate
--> $DIR/type_repetition_in_bounds.rs:25:5
diff --git a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr b/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr
index c6a212744..2c466ff5c 100644
--- a/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr
+++ b/src/tools/clippy/tests/ui/undocumented_unsafe_blocks.stderr
@@ -4,8 +4,8 @@ error: unsafe block missing a safety comment
LL | /* Safety: */ unsafe {}
| ^^^^^^^^^
|
- = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
= help: consider adding a safety comment on the preceding line
+ = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:266:5
diff --git a/src/tools/clippy/tests/ui/undropped_manually_drops.stderr b/src/tools/clippy/tests/ui/undropped_manually_drops.stderr
index 2ac0fe986..92611a9b7 100644
--- a/src/tools/clippy/tests/ui/undropped_manually_drops.stderr
+++ b/src/tools/clippy/tests/ui/undropped_manually_drops.stderr
@@ -4,8 +4,8 @@ error: the inner value of this ManuallyDrop will not be dropped
LL | drop(std::mem::ManuallyDrop::new(S));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::undropped-manually-drops` implied by `-D warnings`
= help: to drop a `ManuallyDrop<T>`, use std::mem::ManuallyDrop::drop
+ = note: `-D clippy::undropped-manually-drops` implied by `-D warnings`
error: the inner value of this ManuallyDrop will not be dropped
--> $DIR/undropped_manually_drops.rs:15:5
diff --git a/src/tools/clippy/tests/ui/uninit_vec.rs b/src/tools/clippy/tests/ui/uninit_vec.rs
index dc150cf28..194e4fc15 100644
--- a/src/tools/clippy/tests/ui/uninit_vec.rs
+++ b/src/tools/clippy/tests/ui/uninit_vec.rs
@@ -91,4 +91,10 @@ fn main() {
vec1.set_len(200);
vec2.set_len(200);
}
+
+ // set_len(0) should not be detected
+ let mut vec: Vec<u8> = Vec::with_capacity(1000);
+ unsafe {
+ vec.set_len(0);
+ }
}
diff --git a/src/tools/clippy/tests/ui/uninit_vec.stderr b/src/tools/clippy/tests/ui/uninit_vec.stderr
index 520bfb26b..77fc689f0 100644
--- a/src/tools/clippy/tests/ui/uninit_vec.stderr
+++ b/src/tools/clippy/tests/ui/uninit_vec.stderr
@@ -7,8 +7,8 @@ LL | unsafe {
LL | vec.set_len(200);
| ^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::uninit-vec` implied by `-D warnings`
= help: initialize the buffer or wrap the content in `MaybeUninit`
+ = note: `-D clippy::uninit-vec` implied by `-D warnings`
error: calling `set_len()` immediately after reserving a buffer creates uninitialized values
--> $DIR/uninit_vec.rs:18:5
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.fixed b/src/tools/clippy/tests/ui/uninlined_format_args.fixed
new file mode 100644
index 000000000..106274479
--- /dev/null
+++ b/src/tools/clippy/tests/ui/uninlined_format_args.fixed
@@ -0,0 +1,182 @@
+// aux-build:proc_macro_with_span.rs
+// run-rustfix
+#![feature(custom_inner_attributes)]
+#![warn(clippy::uninlined_format_args)]
+#![allow(named_arguments_used_positionally, unused_imports, unused_macros, unused_variables)]
+#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
+
+extern crate proc_macro_with_span;
+use proc_macro_with_span::with_span;
+
+macro_rules! no_param_str {
+ () => {
+ "{}"
+ };
+}
+
+macro_rules! my_println {
+ ($($args:tt),*) => {{
+ println!($($args),*)
+ }};
+}
+
+macro_rules! my_println_args {
+ ($($args:tt),*) => {{
+ println!("foo: {}", format_args!($($args),*))
+ }};
+}
+
+fn tester(fn_arg: i32) {
+ let local_i32 = 1;
+ let local_f64 = 2.0;
+ let local_opt: Option<i32> = Some(3);
+ let width = 4;
+ let prec = 5;
+ let val = 6;
+
+ // make sure this file hasn't been corrupted with tabs converted to spaces
+ // let _ = ' '; // <- this is a single tab character
+ let _: &[u8; 3] = b" "; // <- <tab><space><tab>
+
+ println!("val='{local_i32}'");
+ println!("val='{local_i32}'"); // 3 spaces
+ println!("val='{local_i32}'"); // tab
+ println!("val='{local_i32}'"); // space+tab
+ println!("val='{local_i32}'"); // tab+space
+ println!(
+ "val='{
+ }'",
+ local_i32
+ );
+ println!("{local_i32}");
+ println!("{fn_arg}");
+ println!("{local_i32:?}");
+ println!("{local_i32:#?}");
+ println!("{local_i32:4}");
+ println!("{local_i32:04}");
+ println!("{local_i32:<3}");
+ println!("{local_i32:#010x}");
+ println!("{local_f64:.1}");
+ println!("Hello {} is {local_f64:.local_i32$}", "x");
+ println!("Hello {local_i32} is {local_f64:.*}", 5);
+ println!("Hello {local_i32} is {local_f64:.*}", 5);
+ println!("{local_i32} {local_f64}");
+ println!("{local_i32}, {}", local_opt.unwrap());
+ println!("{val}");
+ println!("{val}");
+ println!("{} {1}", local_i32, 42);
+ println!("val='{local_i32}'");
+ println!("val='{local_i32}'");
+ println!("val='{local_i32}'");
+ println!("val='{fn_arg}'");
+ println!("{local_i32}");
+ println!("{local_i32:?}");
+ println!("{local_i32:#?}");
+ println!("{local_i32:04}");
+ println!("{local_i32:<3}");
+ println!("{local_i32:#010x}");
+ println!("{local_f64:.1}");
+ println!("{local_i32} {local_i32}");
+ println!("{local_f64} {local_i32} {local_i32} {local_f64}");
+ println!("{local_i32} {local_f64}");
+ println!("{local_f64} {local_i32}");
+ println!("{local_f64} {local_i32} {local_f64} {local_i32}");
+ println!("{1} {0}", "str", local_i32);
+ println!("{local_i32}");
+ println!("{local_i32:width$}");
+ println!("{local_i32:width$}");
+ println!("{local_i32:.prec$}");
+ println!("{local_i32:.prec$}");
+ println!("{val:val$}");
+ println!("{val:val$}");
+ println!("{val:val$.val$}");
+ println!("{val:val$.val$}");
+ println!("{val:val$.val$}");
+ println!("{val:val$.val$}");
+ println!("{val:val$.val$}");
+ println!("{val:val$.val$}");
+ println!("{val:val$.val$}");
+ println!("{val:val$.val$}");
+ println!("{width:width$}");
+ println!("{local_i32:width$}");
+ println!("{width:width$}");
+ println!("{local_i32:width$}");
+ println!("{prec:.prec$}");
+ println!("{local_i32:.prec$}");
+ println!("{prec:.prec$}");
+ println!("{local_i32:.prec$}");
+ println!("{width:width$.prec$}");
+ println!("{width:width$.prec$}");
+ println!("{local_f64:width$.prec$}");
+ println!("{local_f64:width$.prec$} {local_f64} {width} {prec}");
+ println!(
+ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
+ local_i32, width, prec,
+ );
+ println!(
+ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$} {3}",
+ local_i32,
+ width,
+ prec,
+ 1 + 2
+ );
+ println!("Width = {local_i32}, value with width = {local_f64:local_i32$}");
+ println!("{local_i32:width$.prec$}");
+ println!("{width:width$.prec$}");
+ println!("{}", format!("{local_i32}"));
+ my_println!("{}", local_i32);
+ my_println_args!("{}", local_i32);
+
+ // these should NOT be modified by the lint
+ println!(concat!("nope ", "{}"), local_i32);
+ println!("val='{local_i32}'");
+ println!("val='{local_i32 }'");
+ println!("val='{local_i32 }'"); // with tab
+ println!("val='{local_i32\n}'");
+ println!("{}", usize::MAX);
+ println!("{}", local_opt.unwrap());
+ println!(
+ "val='{local_i32
+ }'"
+ );
+ println!(no_param_str!(), local_i32);
+
+ println!(
+ "{}",
+ // comment with a comma , in it
+ val,
+ );
+ println!("{val}");
+
+ println!(with_span!("{0} {1}" "{1} {0}"), local_i32, local_f64);
+ println!("{}", with_span!(span val));
+
+ if local_i32 > 0 {
+ panic!("p1 {local_i32}");
+ }
+ if local_i32 > 0 {
+ panic!("p2 {local_i32}");
+ }
+ if local_i32 > 0 {
+ panic!("p3 {local_i32}");
+ }
+ if local_i32 > 0 {
+ panic!("p4 {local_i32}");
+ }
+}
+
+fn main() {
+ tester(42);
+}
+
+fn _under_msrv() {
+ #![clippy::msrv = "1.57"]
+ let local_i32 = 1;
+ println!("don't expand='{}'", local_i32);
+}
+
+fn _meets_msrv() {
+ #![clippy::msrv = "1.58"]
+ let local_i32 = 1;
+ println!("expand='{local_i32}'");
+}
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.rs b/src/tools/clippy/tests/ui/uninlined_format_args.rs
new file mode 100644
index 000000000..8e495ebd0
--- /dev/null
+++ b/src/tools/clippy/tests/ui/uninlined_format_args.rs
@@ -0,0 +1,182 @@
+// aux-build:proc_macro_with_span.rs
+// run-rustfix
+#![feature(custom_inner_attributes)]
+#![warn(clippy::uninlined_format_args)]
+#![allow(named_arguments_used_positionally, unused_imports, unused_macros, unused_variables)]
+#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
+
+extern crate proc_macro_with_span;
+use proc_macro_with_span::with_span;
+
+macro_rules! no_param_str {
+ () => {
+ "{}"
+ };
+}
+
+macro_rules! my_println {
+ ($($args:tt),*) => {{
+ println!($($args),*)
+ }};
+}
+
+macro_rules! my_println_args {
+ ($($args:tt),*) => {{
+ println!("foo: {}", format_args!($($args),*))
+ }};
+}
+
+fn tester(fn_arg: i32) {
+ let local_i32 = 1;
+ let local_f64 = 2.0;
+ let local_opt: Option<i32> = Some(3);
+ let width = 4;
+ let prec = 5;
+ let val = 6;
+
+ // make sure this file hasn't been corrupted with tabs converted to spaces
+ // let _ = ' '; // <- this is a single tab character
+ let _: &[u8; 3] = b" "; // <- <tab><space><tab>
+
+ println!("val='{}'", local_i32);
+ println!("val='{ }'", local_i32); // 3 spaces
+ println!("val='{ }'", local_i32); // tab
+ println!("val='{ }'", local_i32); // space+tab
+ println!("val='{ }'", local_i32); // tab+space
+ println!(
+ "val='{
+ }'",
+ local_i32
+ );
+ println!("{}", local_i32);
+ println!("{}", fn_arg);
+ println!("{:?}", local_i32);
+ println!("{:#?}", local_i32);
+ println!("{:4}", local_i32);
+ println!("{:04}", local_i32);
+ println!("{:<3}", local_i32);
+ println!("{:#010x}", local_i32);
+ println!("{:.1}", local_f64);
+ println!("Hello {} is {:.*}", "x", local_i32, local_f64);
+ println!("Hello {} is {:.*}", local_i32, 5, local_f64);
+ println!("Hello {} is {2:.*}", local_i32, 5, local_f64);
+ println!("{} {}", local_i32, local_f64);
+ println!("{}, {}", local_i32, local_opt.unwrap());
+ println!("{}", val);
+ println!("{}", v = val);
+ println!("{} {1}", local_i32, 42);
+ println!("val='{\t }'", local_i32);
+ println!("val='{\n }'", local_i32);
+ println!("val='{local_i32}'", local_i32 = local_i32);
+ println!("val='{local_i32}'", local_i32 = fn_arg);
+ println!("{0}", local_i32);
+ println!("{0:?}", local_i32);
+ println!("{0:#?}", local_i32);
+ println!("{0:04}", local_i32);
+ println!("{0:<3}", local_i32);
+ println!("{0:#010x}", local_i32);
+ println!("{0:.1}", local_f64);
+ println!("{0} {0}", local_i32);
+ println!("{1} {} {0} {}", local_i32, local_f64);
+ println!("{0} {1}", local_i32, local_f64);
+ println!("{1} {0}", local_i32, local_f64);
+ println!("{1} {0} {1} {0}", local_i32, local_f64);
+ println!("{1} {0}", "str", local_i32);
+ println!("{v}", v = local_i32);
+ println!("{local_i32:0$}", width);
+ println!("{local_i32:w$}", w = width);
+ println!("{local_i32:.0$}", prec);
+ println!("{local_i32:.p$}", p = prec);
+ println!("{:0$}", v = val);
+ println!("{0:0$}", v = val);
+ println!("{:0$.0$}", v = val);
+ println!("{0:0$.0$}", v = val);
+ println!("{0:0$.v$}", v = val);
+ println!("{0:v$.0$}", v = val);
+ println!("{v:0$.0$}", v = val);
+ println!("{v:v$.0$}", v = val);
+ println!("{v:0$.v$}", v = val);
+ println!("{v:v$.v$}", v = val);
+ println!("{:0$}", width);
+ println!("{:1$}", local_i32, width);
+ println!("{:w$}", w = width);
+ println!("{:w$}", local_i32, w = width);
+ println!("{:.0$}", prec);
+ println!("{:.1$}", local_i32, prec);
+ println!("{:.p$}", p = prec);
+ println!("{:.p$}", local_i32, p = prec);
+ println!("{:0$.1$}", width, prec);
+ println!("{:0$.w$}", width, w = prec);
+ println!("{:1$.2$}", local_f64, width, prec);
+ println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec);
+ println!(
+ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
+ local_i32, width, prec,
+ );
+ println!(
+ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$} {3}",
+ local_i32,
+ width,
+ prec,
+ 1 + 2
+ );
+ println!("Width = {}, value with width = {:0$}", local_i32, local_f64);
+ println!("{:w$.p$}", local_i32, w = width, p = prec);
+ println!("{:w$.p$}", w = width, p = prec);
+ println!("{}", format!("{}", local_i32));
+ my_println!("{}", local_i32);
+ my_println_args!("{}", local_i32);
+
+ // these should NOT be modified by the lint
+ println!(concat!("nope ", "{}"), local_i32);
+ println!("val='{local_i32}'");
+ println!("val='{local_i32 }'");
+ println!("val='{local_i32 }'"); // with tab
+ println!("val='{local_i32\n}'");
+ println!("{}", usize::MAX);
+ println!("{}", local_opt.unwrap());
+ println!(
+ "val='{local_i32
+ }'"
+ );
+ println!(no_param_str!(), local_i32);
+
+ println!(
+ "{}",
+ // comment with a comma , in it
+ val,
+ );
+ println!("{}", /* comment with a comma , in it */ val);
+
+ println!(with_span!("{0} {1}" "{1} {0}"), local_i32, local_f64);
+ println!("{}", with_span!(span val));
+
+ if local_i32 > 0 {
+ panic!("p1 {}", local_i32);
+ }
+ if local_i32 > 0 {
+ panic!("p2 {0}", local_i32);
+ }
+ if local_i32 > 0 {
+ panic!("p3 {local_i32}", local_i32 = local_i32);
+ }
+ if local_i32 > 0 {
+ panic!("p4 {local_i32}");
+ }
+}
+
+fn main() {
+ tester(42);
+}
+
+fn _under_msrv() {
+ #![clippy::msrv = "1.57"]
+ let local_i32 = 1;
+ println!("don't expand='{}'", local_i32);
+}
+
+fn _meets_msrv() {
+ #![clippy::msrv = "1.58"]
+ let local_i32 = 1;
+ println!("expand='{}'", local_i32);
+}
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args.stderr b/src/tools/clippy/tests/ui/uninlined_format_args.stderr
new file mode 100644
index 000000000..2ce3b7fa9
--- /dev/null
+++ b/src/tools/clippy/tests/ui/uninlined_format_args.stderr
@@ -0,0 +1,879 @@
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:41:5
+ |
+LL | println!("val='{}'", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::uninlined-format-args` implied by `-D warnings`
+help: change this to
+ |
+LL - println!("val='{}'", local_i32);
+LL + println!("val='{local_i32}'");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:42:5
+ |
+LL | println!("val='{ }'", local_i32); // 3 spaces
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("val='{ }'", local_i32); // 3 spaces
+LL + println!("val='{local_i32}'"); // 3 spaces
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:43:5
+ |
+LL | println!("val='{ }'", local_i32); // tab
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("val='{ }'", local_i32); // tab
+LL + println!("val='{local_i32}'"); // tab
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:44:5
+ |
+LL | println!("val='{ }'", local_i32); // space+tab
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("val='{ }'", local_i32); // space+tab
+LL + println!("val='{local_i32}'"); // space+tab
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:45:5
+ |
+LL | println!("val='{ }'", local_i32); // tab+space
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("val='{ }'", local_i32); // tab+space
+LL + println!("val='{local_i32}'"); // tab+space
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:51:5
+ |
+LL | println!("{}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{}", local_i32);
+LL + println!("{local_i32}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:52:5
+ |
+LL | println!("{}", fn_arg);
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{}", fn_arg);
+LL + println!("{fn_arg}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:53:5
+ |
+LL | println!("{:?}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:?}", local_i32);
+LL + println!("{local_i32:?}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:54:5
+ |
+LL | println!("{:#?}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:#?}", local_i32);
+LL + println!("{local_i32:#?}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:55:5
+ |
+LL | println!("{:4}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:4}", local_i32);
+LL + println!("{local_i32:4}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:56:5
+ |
+LL | println!("{:04}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:04}", local_i32);
+LL + println!("{local_i32:04}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:57:5
+ |
+LL | println!("{:<3}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:<3}", local_i32);
+LL + println!("{local_i32:<3}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:58:5
+ |
+LL | println!("{:#010x}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:#010x}", local_i32);
+LL + println!("{local_i32:#010x}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:59:5
+ |
+LL | println!("{:.1}", local_f64);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:.1}", local_f64);
+LL + println!("{local_f64:.1}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:60:5
+ |
+LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("Hello {} is {:.*}", "x", local_i32, local_f64);
+LL + println!("Hello {} is {local_f64:.local_i32$}", "x");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:61:5
+ |
+LL | println!("Hello {} is {:.*}", local_i32, 5, local_f64);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("Hello {} is {:.*}", local_i32, 5, local_f64);
+LL + println!("Hello {local_i32} is {local_f64:.*}", 5);
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:62:5
+ |
+LL | println!("Hello {} is {2:.*}", local_i32, 5, local_f64);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("Hello {} is {2:.*}", local_i32, 5, local_f64);
+LL + println!("Hello {local_i32} is {local_f64:.*}", 5);
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:63:5
+ |
+LL | println!("{} {}", local_i32, local_f64);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{} {}", local_i32, local_f64);
+LL + println!("{local_i32} {local_f64}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:64:5
+ |
+LL | println!("{}, {}", local_i32, local_opt.unwrap());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{}, {}", local_i32, local_opt.unwrap());
+LL + println!("{local_i32}, {}", local_opt.unwrap());
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:65:5
+ |
+LL | println!("{}", val);
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{}", val);
+LL + println!("{val}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:66:5
+ |
+LL | println!("{}", v = val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{}", v = val);
+LL + println!("{val}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:68:5
+ |
+LL | println!("val='{/t }'", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("val='{/t }'", local_i32);
+LL + println!("val='{local_i32}'");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:69:5
+ |
+LL | println!("val='{/n }'", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("val='{/n }'", local_i32);
+LL + println!("val='{local_i32}'");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:70:5
+ |
+LL | println!("val='{local_i32}'", local_i32 = local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("val='{local_i32}'", local_i32 = local_i32);
+LL + println!("val='{local_i32}'");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:71:5
+ |
+LL | println!("val='{local_i32}'", local_i32 = fn_arg);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("val='{local_i32}'", local_i32 = fn_arg);
+LL + println!("val='{fn_arg}'");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:72:5
+ |
+LL | println!("{0}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{0}", local_i32);
+LL + println!("{local_i32}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:73:5
+ |
+LL | println!("{0:?}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{0:?}", local_i32);
+LL + println!("{local_i32:?}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:74:5
+ |
+LL | println!("{0:#?}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{0:#?}", local_i32);
+LL + println!("{local_i32:#?}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:75:5
+ |
+LL | println!("{0:04}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{0:04}", local_i32);
+LL + println!("{local_i32:04}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:76:5
+ |
+LL | println!("{0:<3}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{0:<3}", local_i32);
+LL + println!("{local_i32:<3}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:77:5
+ |
+LL | println!("{0:#010x}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{0:#010x}", local_i32);
+LL + println!("{local_i32:#010x}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:78:5
+ |
+LL | println!("{0:.1}", local_f64);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{0:.1}", local_f64);
+LL + println!("{local_f64:.1}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:79:5
+ |
+LL | println!("{0} {0}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{0} {0}", local_i32);
+LL + println!("{local_i32} {local_i32}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:80:5
+ |
+LL | println!("{1} {} {0} {}", local_i32, local_f64);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{1} {} {0} {}", local_i32, local_f64);
+LL + println!("{local_f64} {local_i32} {local_i32} {local_f64}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:81:5
+ |
+LL | println!("{0} {1}", local_i32, local_f64);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{0} {1}", local_i32, local_f64);
+LL + println!("{local_i32} {local_f64}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:82:5
+ |
+LL | println!("{1} {0}", local_i32, local_f64);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{1} {0}", local_i32, local_f64);
+LL + println!("{local_f64} {local_i32}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:83:5
+ |
+LL | println!("{1} {0} {1} {0}", local_i32, local_f64);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{1} {0} {1} {0}", local_i32, local_f64);
+LL + println!("{local_f64} {local_i32} {local_f64} {local_i32}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:85:5
+ |
+LL | println!("{v}", v = local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{v}", v = local_i32);
+LL + println!("{local_i32}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:86:5
+ |
+LL | println!("{local_i32:0$}", width);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{local_i32:0$}", width);
+LL + println!("{local_i32:width$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:87:5
+ |
+LL | println!("{local_i32:w$}", w = width);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{local_i32:w$}", w = width);
+LL + println!("{local_i32:width$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:88:5
+ |
+LL | println!("{local_i32:.0$}", prec);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{local_i32:.0$}", prec);
+LL + println!("{local_i32:.prec$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:89:5
+ |
+LL | println!("{local_i32:.p$}", p = prec);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{local_i32:.p$}", p = prec);
+LL + println!("{local_i32:.prec$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:90:5
+ |
+LL | println!("{:0$}", v = val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:0$}", v = val);
+LL + println!("{val:val$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:91:5
+ |
+LL | println!("{0:0$}", v = val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{0:0$}", v = val);
+LL + println!("{val:val$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:92:5
+ |
+LL | println!("{:0$.0$}", v = val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:0$.0$}", v = val);
+LL + println!("{val:val$.val$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:93:5
+ |
+LL | println!("{0:0$.0$}", v = val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{0:0$.0$}", v = val);
+LL + println!("{val:val$.val$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:94:5
+ |
+LL | println!("{0:0$.v$}", v = val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{0:0$.v$}", v = val);
+LL + println!("{val:val$.val$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:95:5
+ |
+LL | println!("{0:v$.0$}", v = val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{0:v$.0$}", v = val);
+LL + println!("{val:val$.val$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:96:5
+ |
+LL | println!("{v:0$.0$}", v = val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{v:0$.0$}", v = val);
+LL + println!("{val:val$.val$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:97:5
+ |
+LL | println!("{v:v$.0$}", v = val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{v:v$.0$}", v = val);
+LL + println!("{val:val$.val$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:98:5
+ |
+LL | println!("{v:0$.v$}", v = val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{v:0$.v$}", v = val);
+LL + println!("{val:val$.val$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:99:5
+ |
+LL | println!("{v:v$.v$}", v = val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{v:v$.v$}", v = val);
+LL + println!("{val:val$.val$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:100:5
+ |
+LL | println!("{:0$}", width);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:0$}", width);
+LL + println!("{width:width$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:101:5
+ |
+LL | println!("{:1$}", local_i32, width);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:1$}", local_i32, width);
+LL + println!("{local_i32:width$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:102:5
+ |
+LL | println!("{:w$}", w = width);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:w$}", w = width);
+LL + println!("{width:width$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:103:5
+ |
+LL | println!("{:w$}", local_i32, w = width);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:w$}", local_i32, w = width);
+LL + println!("{local_i32:width$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:104:5
+ |
+LL | println!("{:.0$}", prec);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:.0$}", prec);
+LL + println!("{prec:.prec$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:105:5
+ |
+LL | println!("{:.1$}", local_i32, prec);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:.1$}", local_i32, prec);
+LL + println!("{local_i32:.prec$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:106:5
+ |
+LL | println!("{:.p$}", p = prec);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:.p$}", p = prec);
+LL + println!("{prec:.prec$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:107:5
+ |
+LL | println!("{:.p$}", local_i32, p = prec);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:.p$}", local_i32, p = prec);
+LL + println!("{local_i32:.prec$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:108:5
+ |
+LL | println!("{:0$.1$}", width, prec);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:0$.1$}", width, prec);
+LL + println!("{width:width$.prec$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:109:5
+ |
+LL | println!("{:0$.w$}", width, w = prec);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:0$.w$}", width, w = prec);
+LL + println!("{width:width$.prec$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:110:5
+ |
+LL | println!("{:1$.2$}", local_f64, width, prec);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:1$.2$}", local_f64, width, prec);
+LL + println!("{local_f64:width$.prec$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:111:5
+ |
+LL | println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec);
+LL + println!("{local_f64:width$.prec$} {local_f64} {width} {prec}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:123:5
+ |
+LL | println!("Width = {}, value with width = {:0$}", local_i32, local_f64);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("Width = {}, value with width = {:0$}", local_i32, local_f64);
+LL + println!("Width = {local_i32}, value with width = {local_f64:local_i32$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:124:5
+ |
+LL | println!("{:w$.p$}", local_i32, w = width, p = prec);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:w$.p$}", local_i32, w = width, p = prec);
+LL + println!("{local_i32:width$.prec$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:125:5
+ |
+LL | println!("{:w$.p$}", w = width, p = prec);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{:w$.p$}", w = width, p = prec);
+LL + println!("{width:width$.prec$}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:126:20
+ |
+LL | println!("{}", format!("{}", local_i32));
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{}", format!("{}", local_i32));
+LL + println!("{}", format!("{local_i32}"));
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:149:5
+ |
+LL | println!("{}", /* comment with a comma , in it */ val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("{}", /* comment with a comma , in it */ val);
+LL + println!("{val}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:155:9
+ |
+LL | panic!("p1 {}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - panic!("p1 {}", local_i32);
+LL + panic!("p1 {local_i32}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:158:9
+ |
+LL | panic!("p2 {0}", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - panic!("p2 {0}", local_i32);
+LL + panic!("p2 {local_i32}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:161:9
+ |
+LL | panic!("p3 {local_i32}", local_i32 = local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - panic!("p3 {local_i32}", local_i32 = local_i32);
+LL + panic!("p3 {local_i32}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args.rs:181:5
+ |
+LL | println!("expand='{}'", local_i32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - println!("expand='{}'", local_i32);
+LL + println!("expand='{local_i32}'");
+ |
+
+error: aborting due to 73 previous errors
+
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed
new file mode 100644
index 000000000..96cc08779
--- /dev/null
+++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.fixed
@@ -0,0 +1,29 @@
+// revisions: edition2018 edition2021
+//[edition2018] edition:2018
+//[edition2021] edition:2021
+// run-rustfix
+
+#![warn(clippy::uninlined_format_args)]
+
+fn main() {
+ let var = 1;
+
+ println!("val='{var}'");
+
+ if var > 0 {
+ panic!("p1 {}", var);
+ }
+ if var > 0 {
+ panic!("p2 {0}", var);
+ }
+ if var > 0 {
+ panic!("p3 {var}", var = var);
+ }
+
+ #[allow(non_fmt_panics)]
+ {
+ if var > 0 {
+ panic!("p4 {var}");
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.stderr b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.stderr
new file mode 100644
index 000000000..2c8061259
--- /dev/null
+++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2018.stderr
@@ -0,0 +1,15 @@
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args_panic.rs:11:5
+ |
+LL | println!("val='{}'", var);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::uninlined-format-args` implied by `-D warnings`
+help: change this to
+ |
+LL - println!("val='{}'", var);
+LL + println!("val='{var}'");
+ |
+
+error: aborting due to previous error
+
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed
new file mode 100644
index 000000000..faf8ca4d3
--- /dev/null
+++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.fixed
@@ -0,0 +1,29 @@
+// revisions: edition2018 edition2021
+//[edition2018] edition:2018
+//[edition2021] edition:2021
+// run-rustfix
+
+#![warn(clippy::uninlined_format_args)]
+
+fn main() {
+ let var = 1;
+
+ println!("val='{var}'");
+
+ if var > 0 {
+ panic!("p1 {var}");
+ }
+ if var > 0 {
+ panic!("p2 {var}");
+ }
+ if var > 0 {
+ panic!("p3 {var}");
+ }
+
+ #[allow(non_fmt_panics)]
+ {
+ if var > 0 {
+ panic!("p4 {var}");
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.stderr b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.stderr
new file mode 100644
index 000000000..0f09c45f4
--- /dev/null
+++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.edition2021.stderr
@@ -0,0 +1,51 @@
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args_panic.rs:11:5
+ |
+LL | println!("val='{}'", var);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: `-D clippy::uninlined-format-args` implied by `-D warnings`
+help: change this to
+ |
+LL - println!("val='{}'", var);
+LL + println!("val='{var}'");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args_panic.rs:14:9
+ |
+LL | panic!("p1 {}", var);
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - panic!("p1 {}", var);
+LL + panic!("p1 {var}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args_panic.rs:17:9
+ |
+LL | panic!("p2 {0}", var);
+ | ^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - panic!("p2 {0}", var);
+LL + panic!("p2 {var}");
+ |
+
+error: variables can be used directly in the `format!` string
+ --> $DIR/uninlined_format_args_panic.rs:20:9
+ |
+LL | panic!("p3 {var}", var = var);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: change this to
+ |
+LL - panic!("p3 {var}", var = var);
+LL + panic!("p3 {var}");
+ |
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs b/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs
new file mode 100644
index 000000000..6421c5bbe
--- /dev/null
+++ b/src/tools/clippy/tests/ui/uninlined_format_args_panic.rs
@@ -0,0 +1,29 @@
+// revisions: edition2018 edition2021
+//[edition2018] edition:2018
+//[edition2021] edition:2021
+// run-rustfix
+
+#![warn(clippy::uninlined_format_args)]
+
+fn main() {
+ let var = 1;
+
+ println!("val='{}'", var);
+
+ if var > 0 {
+ panic!("p1 {}", var);
+ }
+ if var > 0 {
+ panic!("p2 {0}", var);
+ }
+ if var > 0 {
+ panic!("p3 {var}", var = var);
+ }
+
+ #[allow(non_fmt_panics)]
+ {
+ if var > 0 {
+ panic!("p4 {var}");
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/unit_arg.rs b/src/tools/clippy/tests/ui/unit_arg.rs
index 7bf3adc07..07e70873a 100644
--- a/src/tools/clippy/tests/ui/unit_arg.rs
+++ b/src/tools/clippy/tests/ui/unit_arg.rs
@@ -1,17 +1,16 @@
// aux-build: proc_macro_with_span.rs
-
#![warn(clippy::unit_arg)]
+#![allow(unused_must_use, unused_variables)]
#![allow(
+ clippy::let_unit_value,
+ clippy::needless_question_mark,
+ clippy::never_loop,
clippy::no_effect,
- unused_must_use,
- unused_variables,
- clippy::unused_unit,
- clippy::unnecessary_wraps,
clippy::or_fun_call,
- clippy::needless_question_mark,
clippy::self_named_constructors,
- clippy::let_unit_value,
- clippy::never_loop
+ clippy::uninlined_format_args,
+ clippy::unnecessary_wraps,
+ clippy::unused_unit
)]
extern crate proc_macro_with_span;
diff --git a/src/tools/clippy/tests/ui/unit_arg.stderr b/src/tools/clippy/tests/ui/unit_arg.stderr
index 1de9d44bb..74d4d2f40 100644
--- a/src/tools/clippy/tests/ui/unit_arg.stderr
+++ b/src/tools/clippy/tests/ui/unit_arg.stderr
@@ -1,5 +1,5 @@
error: passing a unit value to a function
- --> $DIR/unit_arg.rs:63:5
+ --> $DIR/unit_arg.rs:62:5
|
LL | / foo({
LL | | 1;
@@ -20,7 +20,7 @@ LL ~ foo(());
|
error: passing a unit value to a function
- --> $DIR/unit_arg.rs:66:5
+ --> $DIR/unit_arg.rs:65:5
|
LL | foo(foo(1));
| ^^^^^^^^^^^
@@ -32,7 +32,7 @@ LL ~ foo(());
|
error: passing a unit value to a function
- --> $DIR/unit_arg.rs:67:5
+ --> $DIR/unit_arg.rs:66:5
|
LL | / foo({
LL | | foo(1);
@@ -54,7 +54,7 @@ LL ~ foo(());
|
error: passing a unit value to a function
- --> $DIR/unit_arg.rs:72:5
+ --> $DIR/unit_arg.rs:71:5
|
LL | / b.bar({
LL | | 1;
@@ -74,7 +74,7 @@ LL ~ b.bar(());
|
error: passing unit values to a function
- --> $DIR/unit_arg.rs:75:5
+ --> $DIR/unit_arg.rs:74:5
|
LL | taking_multiple_units(foo(0), foo(1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -87,7 +87,7 @@ LL ~ taking_multiple_units((), ());
|
error: passing unit values to a function
- --> $DIR/unit_arg.rs:76:5
+ --> $DIR/unit_arg.rs:75:5
|
LL | / taking_multiple_units(foo(0), {
LL | | foo(1);
@@ -110,7 +110,7 @@ LL ~ taking_multiple_units((), ());
|
error: passing unit values to a function
- --> $DIR/unit_arg.rs:80:5
+ --> $DIR/unit_arg.rs:79:5
|
LL | / taking_multiple_units(
LL | | {
@@ -146,7 +146,7 @@ LL ~ );
|
error: passing a unit value to a function
- --> $DIR/unit_arg.rs:91:13
+ --> $DIR/unit_arg.rs:90:13
|
LL | None.or(Some(foo(2)));
| ^^^^^^^^^^^^
@@ -160,7 +160,7 @@ LL ~ });
|
error: passing a unit value to a function
- --> $DIR/unit_arg.rs:94:5
+ --> $DIR/unit_arg.rs:93:5
|
LL | foo(foo(()));
| ^^^^^^^^^^^^
@@ -172,7 +172,7 @@ LL ~ foo(());
|
error: passing a unit value to a function
- --> $DIR/unit_arg.rs:131:5
+ --> $DIR/unit_arg.rs:130:5
|
LL | Some(foo(1))
| ^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed
index 9400e93ca..5787471a3 100644
--- a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed
+++ b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.fixed
@@ -1,6 +1,7 @@
// run-rustfix
#![warn(clippy::unit_arg)]
-#![allow(clippy::no_effect, unused_must_use, unused_variables)]
+#![allow(unused_must_use, unused_variables)]
+#![allow(clippy::no_effect, clippy::uninlined_format_args)]
use std::fmt::Debug;
diff --git a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs
index 5f52b6c53..6a42c2ccf 100644
--- a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs
+++ b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.rs
@@ -1,6 +1,7 @@
// run-rustfix
#![warn(clippy::unit_arg)]
-#![allow(clippy::no_effect, unused_must_use, unused_variables)]
+#![allow(unused_must_use, unused_variables)]
+#![allow(clippy::no_effect, clippy::uninlined_format_args)]
use std::fmt::Debug;
diff --git a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.stderr b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.stderr
index d35e93169..c697dfb1e 100644
--- a/src/tools/clippy/tests/ui/unit_arg_empty_blocks.stderr
+++ b/src/tools/clippy/tests/ui/unit_arg_empty_blocks.stderr
@@ -1,5 +1,5 @@
error: passing a unit value to a function
- --> $DIR/unit_arg_empty_blocks.rs:16:5
+ --> $DIR/unit_arg_empty_blocks.rs:17:5
|
LL | foo({});
| ^^^^--^
@@ -9,7 +9,7 @@ LL | foo({});
= note: `-D clippy::unit-arg` implied by `-D warnings`
error: passing a unit value to a function
- --> $DIR/unit_arg_empty_blocks.rs:17:5
+ --> $DIR/unit_arg_empty_blocks.rs:18:5
|
LL | foo3({}, 2, 2);
| ^^^^^--^^^^^^^
@@ -17,7 +17,7 @@ LL | foo3({}, 2, 2);
| help: use a unit literal instead: `()`
error: passing unit values to a function
- --> $DIR/unit_arg_empty_blocks.rs:18:5
+ --> $DIR/unit_arg_empty_blocks.rs:19:5
|
LL | taking_two_units({}, foo(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -29,7 +29,7 @@ LL ~ taking_two_units((), ());
|
error: passing unit values to a function
- --> $DIR/unit_arg_empty_blocks.rs:19:5
+ --> $DIR/unit_arg_empty_blocks.rs:20:5
|
LL | taking_three_units({}, foo(0), foo(1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/tools/clippy/tests/ui/unit_hash.stderr b/src/tools/clippy/tests/ui/unit_hash.stderr
index 050fa55a1..089d1212d 100644
--- a/src/tools/clippy/tests/ui/unit_hash.stderr
+++ b/src/tools/clippy/tests/ui/unit_hash.stderr
@@ -4,8 +4,8 @@ error: this call to `hash` on the unit type will do nothing
LL | Foo::Empty => ().hash(&mut state),
| ^^^^^^^^^^^^^^^^^^^ help: remove the call to `hash` or consider using: `0_u8.hash(&mut state)`
|
- = note: `-D clippy::unit-hash` implied by `-D warnings`
= note: the implementation of `Hash` for `()` is a no-op
+ = note: `-D clippy::unit-hash` implied by `-D warnings`
error: this call to `hash` on the unit type will do nothing
--> $DIR/unit_hash.rs:24:5
diff --git a/src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr b/src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr
index e63d58746..1d9564ce2 100644
--- a/src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr
+++ b/src/tools/clippy/tests/ui/unit_return_expecting_ord.stderr
@@ -4,12 +4,12 @@ error: this closure returns the unit type which also implements Ord
LL | structs.sort_by_key(|s| {
| ^^^
|
- = note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings`
help: probably caused by this trailing semicolon
--> $DIR/unit_return_expecting_ord.rs:19:24
|
LL | double(s.field);
| ^
+ = note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings`
error: this closure returns the unit type which also implements PartialOrd
--> $DIR/unit_return_expecting_ord.rs:22:30
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.fixed b/src/tools/clippy/tests/ui/unnecessary_cast.fixed
index ee9f15734..ec8c6abfa 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.fixed
@@ -97,4 +97,22 @@ mod fixable {
let _ = -(1 + 1) as i64;
}
+
+ fn issue_9563() {
+ let _: f64 = (-8.0_f64).exp();
+ #[allow(clippy::precedence)]
+ let _: f64 = -8.0_f64.exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior
+ }
+
+ fn issue_9562_non_literal() {
+ fn foo() -> f32 {
+ 0.
+ }
+
+ let _num = foo();
+ }
+
+ fn issue_9603() {
+ let _: f32 = -0x400 as f32;
+ }
}
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.rs b/src/tools/clippy/tests/ui/unnecessary_cast.rs
index 5b7041242..5213cdc26 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.rs
@@ -97,4 +97,22 @@ mod fixable {
let _ = -(1 + 1) as i64;
}
+
+ fn issue_9563() {
+ let _: f64 = (-8.0 as f64).exp();
+ #[allow(clippy::precedence)]
+ let _: f64 = -(8.0 as f64).exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior
+ }
+
+ fn issue_9562_non_literal() {
+ fn foo() -> f32 {
+ 0.
+ }
+
+ let _num = foo() as f32;
+ }
+
+ fn issue_9603() {
+ let _: f32 = -0x400 as f32;
+ }
}
diff --git a/src/tools/clippy/tests/ui/unnecessary_cast.stderr b/src/tools/clippy/tests/ui/unnecessary_cast.stderr
index f7829ff3b..e5c3dd5e5 100644
--- a/src/tools/clippy/tests/ui/unnecessary_cast.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_cast.stderr
@@ -162,5 +162,23 @@ error: casting integer literal to `i64` is unnecessary
LL | let _: i64 = -(1) as i64;
| ^^^^^^^^^^^ help: try: `-1_i64`
-error: aborting due to 27 previous errors
+error: casting float literal to `f64` is unnecessary
+ --> $DIR/unnecessary_cast.rs:102:22
+ |
+LL | let _: f64 = (-8.0 as f64).exp();
+ | ^^^^^^^^^^^^^ help: try: `(-8.0_f64)`
+
+error: casting float literal to `f64` is unnecessary
+ --> $DIR/unnecessary_cast.rs:104:23
+ |
+LL | let _: f64 = -(8.0 as f64).exp(); // should suggest `-8.0_f64.exp()` here not to change code behavior
+ | ^^^^^^^^^^^^ help: try: `8.0_f64`
+
+error: casting to the same type is unnecessary (`f32` -> `f32`)
+ --> $DIR/unnecessary_cast.rs:112:20
+ |
+LL | let _num = foo() as f32;
+ | ^^^^^^^^^^^^ help: try: `foo()`
+
+error: aborting due to 30 previous errors
diff --git a/src/tools/clippy/tests/ui/unnecessary_clone.rs b/src/tools/clippy/tests/ui/unnecessary_clone.rs
index 6770a7fac..8b1629b19 100644
--- a/src/tools/clippy/tests/ui/unnecessary_clone.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_clone.rs
@@ -1,7 +1,7 @@
// does not test any rustfixable lints
-
#![warn(clippy::clone_on_ref_ptr)]
-#![allow(unused, clippy::redundant_clone, clippy::unnecessary_wraps)]
+#![allow(unused)]
+#![allow(clippy::redundant_clone, clippy::uninlined_format_args, clippy::unnecessary_wraps)]
use std::cell::RefCell;
use std::rc::{self, Rc};
diff --git a/src/tools/clippy/tests/ui/unnecessary_join.fixed b/src/tools/clippy/tests/ui/unnecessary_join.fixed
index 7e12c6ae4..347953960 100644
--- a/src/tools/clippy/tests/ui/unnecessary_join.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_join.fixed
@@ -1,6 +1,6 @@
// run-rustfix
-
#![warn(clippy::unnecessary_join)]
+#![allow(clippy::uninlined_format_args)]
fn main() {
// should be linted
diff --git a/src/tools/clippy/tests/ui/unnecessary_join.rs b/src/tools/clippy/tests/ui/unnecessary_join.rs
index 0a21656a7..344918cd2 100644
--- a/src/tools/clippy/tests/ui/unnecessary_join.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_join.rs
@@ -1,6 +1,6 @@
// run-rustfix
-
#![warn(clippy::unnecessary_join)]
+#![allow(clippy::uninlined_format_args)]
fn main() {
// should be linted
diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
index eed817968..ce4a82e02 100644
--- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
@@ -1,9 +1,13 @@
// run-rustfix
+// aux-build: proc_macro_with_span.rs
#![warn(clippy::unnecessary_lazy_evaluations)]
#![allow(clippy::redundant_closure)]
#![allow(clippy::bind_instead_of_map)]
#![allow(clippy::map_identity)]
+extern crate proc_macro_with_span;
+use proc_macro_with_span::with_span;
+
struct Deep(Option<usize>);
#[derive(Copy, Clone)]
@@ -21,6 +25,14 @@ fn some_call<T: Default>() -> T {
T::default()
}
+struct Issue9427(i32);
+
+impl Drop for Issue9427 {
+ fn drop(&mut self) {
+ println!("{}", self.0);
+ }
+}
+
fn main() {
let astronomers_pi = 10;
let ext_arr: [usize; 1] = [2];
@@ -73,6 +85,9 @@ fn main() {
let _ = deep.0.or_else(|| some_call());
let _ = opt.ok_or_else(|| ext_arr[0]);
+ // Should not lint - bool
+ let _ = (0 == 1).then(|| Issue9427(0)); // Issue9427 has a significant drop
+
// should not lint, bind_instead_of_map takes priority
let _ = Some(10).and_then(|idx| Some(ext_arr[idx]));
let _ = Some(10).and_then(|idx| Some(idx));
@@ -130,3 +145,9 @@ fn main() {
let _: Result<usize, usize> = res.and_then(|x| Err(x));
let _: Result<usize, usize> = res.or_else(|err| Ok(err));
}
+
+#[allow(unused)]
+fn issue9485() {
+ // should not lint, is in proc macro
+ with_span!(span Some(42).unwrap_or_else(|| 2););
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs
index 1588db79b..59cdf6628 100644
--- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.rs
@@ -1,9 +1,13 @@
// run-rustfix
+// aux-build: proc_macro_with_span.rs
#![warn(clippy::unnecessary_lazy_evaluations)]
#![allow(clippy::redundant_closure)]
#![allow(clippy::bind_instead_of_map)]
#![allow(clippy::map_identity)]
+extern crate proc_macro_with_span;
+use proc_macro_with_span::with_span;
+
struct Deep(Option<usize>);
#[derive(Copy, Clone)]
@@ -21,6 +25,14 @@ fn some_call<T: Default>() -> T {
T::default()
}
+struct Issue9427(i32);
+
+impl Drop for Issue9427 {
+ fn drop(&mut self) {
+ println!("{}", self.0);
+ }
+}
+
fn main() {
let astronomers_pi = 10;
let ext_arr: [usize; 1] = [2];
@@ -73,6 +85,9 @@ fn main() {
let _ = deep.0.or_else(|| some_call());
let _ = opt.ok_or_else(|| ext_arr[0]);
+ // Should not lint - bool
+ let _ = (0 == 1).then(|| Issue9427(0)); // Issue9427 has a significant drop
+
// should not lint, bind_instead_of_map takes priority
let _ = Some(10).and_then(|idx| Some(ext_arr[idx]));
let _ = Some(10).and_then(|idx| Some(idx));
@@ -130,3 +145,9 @@ fn main() {
let _: Result<usize, usize> = res.and_then(|x| Err(x));
let _: Result<usize, usize> = res.or_else(|err| Ok(err));
}
+
+#[allow(unused)]
+fn issue9485() {
+ // should not lint, is in proc macro
+ with_span!(span Some(42).unwrap_or_else(|| 2););
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr
index 83dc7fd83..8a9ece4aa 100644
--- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.stderr
@@ -1,5 +1,5 @@
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:36:13
+ --> $DIR/unnecessary_lazy_eval.rs:48:13
|
LL | let _ = opt.unwrap_or_else(|| 2);
| ^^^^--------------------
@@ -9,7 +9,7 @@ LL | let _ = opt.unwrap_or_else(|| 2);
= note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:37:13
+ --> $DIR/unnecessary_lazy_eval.rs:49:13
|
LL | let _ = opt.unwrap_or_else(|| astronomers_pi);
| ^^^^---------------------------------
@@ -17,7 +17,7 @@ LL | let _ = opt.unwrap_or_else(|| astronomers_pi);
| help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:38:13
+ --> $DIR/unnecessary_lazy_eval.rs:50:13
|
LL | let _ = opt.unwrap_or_else(|| ext_str.some_field);
| ^^^^-------------------------------------
@@ -25,7 +25,7 @@ LL | let _ = opt.unwrap_or_else(|| ext_str.some_field);
| help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:40:13
+ --> $DIR/unnecessary_lazy_eval.rs:52:13
|
LL | let _ = opt.and_then(|_| ext_opt);
| ^^^^---------------------
@@ -33,7 +33,7 @@ LL | let _ = opt.and_then(|_| ext_opt);
| help: use `and(..)` instead: `and(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:41:13
+ --> $DIR/unnecessary_lazy_eval.rs:53:13
|
LL | let _ = opt.or_else(|| ext_opt);
| ^^^^-------------------
@@ -41,7 +41,7 @@ LL | let _ = opt.or_else(|| ext_opt);
| help: use `or(..)` instead: `or(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:42:13
+ --> $DIR/unnecessary_lazy_eval.rs:54:13
|
LL | let _ = opt.or_else(|| None);
| ^^^^----------------
@@ -49,7 +49,7 @@ LL | let _ = opt.or_else(|| None);
| help: use `or(..)` instead: `or(None)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:43:13
+ --> $DIR/unnecessary_lazy_eval.rs:55:13
|
LL | let _ = opt.get_or_insert_with(|| 2);
| ^^^^------------------------
@@ -57,7 +57,7 @@ LL | let _ = opt.get_or_insert_with(|| 2);
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:44:13
+ --> $DIR/unnecessary_lazy_eval.rs:56:13
|
LL | let _ = opt.ok_or_else(|| 2);
| ^^^^----------------
@@ -65,7 +65,7 @@ LL | let _ = opt.ok_or_else(|| 2);
| help: use `ok_or(..)` instead: `ok_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:45:13
+ --> $DIR/unnecessary_lazy_eval.rs:57:13
|
LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
| ^^^^^^^^^^^^^^^^^-------------------------------
@@ -73,7 +73,7 @@ LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
| help: use `unwrap_or(..)` instead: `unwrap_or(Some((1, 2)))`
error: unnecessary closure used with `bool::then`
- --> $DIR/unnecessary_lazy_eval.rs:46:13
+ --> $DIR/unnecessary_lazy_eval.rs:58:13
|
LL | let _ = cond.then(|| astronomers_pi);
| ^^^^^-----------------------
@@ -81,7 +81,7 @@ LL | let _ = cond.then(|| astronomers_pi);
| help: use `then_some(..)` instead: `then_some(astronomers_pi)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:49:13
+ --> $DIR/unnecessary_lazy_eval.rs:61:13
|
LL | let _ = Some(10).unwrap_or_else(|| 2);
| ^^^^^^^^^--------------------
@@ -89,7 +89,7 @@ LL | let _ = Some(10).unwrap_or_else(|| 2);
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:50:13
+ --> $DIR/unnecessary_lazy_eval.rs:62:13
|
LL | let _ = Some(10).and_then(|_| ext_opt);
| ^^^^^^^^^---------------------
@@ -97,7 +97,7 @@ LL | let _ = Some(10).and_then(|_| ext_opt);
| help: use `and(..)` instead: `and(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:51:28
+ --> $DIR/unnecessary_lazy_eval.rs:63:28
|
LL | let _: Option<usize> = None.or_else(|| ext_opt);
| ^^^^^-------------------
@@ -105,7 +105,7 @@ LL | let _: Option<usize> = None.or_else(|| ext_opt);
| help: use `or(..)` instead: `or(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:52:13
+ --> $DIR/unnecessary_lazy_eval.rs:64:13
|
LL | let _ = None.get_or_insert_with(|| 2);
| ^^^^^------------------------
@@ -113,7 +113,7 @@ LL | let _ = None.get_or_insert_with(|| 2);
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:53:35
+ --> $DIR/unnecessary_lazy_eval.rs:65:35
|
LL | let _: Result<usize, usize> = None.ok_or_else(|| 2);
| ^^^^^----------------
@@ -121,7 +121,7 @@ LL | let _: Result<usize, usize> = None.ok_or_else(|| 2);
| help: use `ok_or(..)` instead: `ok_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:54:28
+ --> $DIR/unnecessary_lazy_eval.rs:66:28
|
LL | let _: Option<usize> = None.or_else(|| None);
| ^^^^^----------------
@@ -129,7 +129,7 @@ LL | let _: Option<usize> = None.or_else(|| None);
| help: use `or(..)` instead: `or(None)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:57:13
+ --> $DIR/unnecessary_lazy_eval.rs:69:13
|
LL | let _ = deep.0.unwrap_or_else(|| 2);
| ^^^^^^^--------------------
@@ -137,7 +137,7 @@ LL | let _ = deep.0.unwrap_or_else(|| 2);
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:58:13
+ --> $DIR/unnecessary_lazy_eval.rs:70:13
|
LL | let _ = deep.0.and_then(|_| ext_opt);
| ^^^^^^^---------------------
@@ -145,7 +145,7 @@ LL | let _ = deep.0.and_then(|_| ext_opt);
| help: use `and(..)` instead: `and(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:59:13
+ --> $DIR/unnecessary_lazy_eval.rs:71:13
|
LL | let _ = deep.0.or_else(|| None);
| ^^^^^^^----------------
@@ -153,7 +153,7 @@ LL | let _ = deep.0.or_else(|| None);
| help: use `or(..)` instead: `or(None)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:60:13
+ --> $DIR/unnecessary_lazy_eval.rs:72:13
|
LL | let _ = deep.0.get_or_insert_with(|| 2);
| ^^^^^^^------------------------
@@ -161,7 +161,7 @@ LL | let _ = deep.0.get_or_insert_with(|| 2);
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:61:13
+ --> $DIR/unnecessary_lazy_eval.rs:73:13
|
LL | let _ = deep.0.ok_or_else(|| 2);
| ^^^^^^^----------------
@@ -169,7 +169,7 @@ LL | let _ = deep.0.ok_or_else(|| 2);
| help: use `ok_or(..)` instead: `ok_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:81:28
+ --> $DIR/unnecessary_lazy_eval.rs:96:28
|
LL | let _: Option<usize> = None.or_else(|| Some(3));
| ^^^^^-------------------
@@ -177,7 +177,7 @@ LL | let _: Option<usize> = None.or_else(|| Some(3));
| help: use `or(..)` instead: `or(Some(3))`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:82:13
+ --> $DIR/unnecessary_lazy_eval.rs:97:13
|
LL | let _ = deep.0.or_else(|| Some(3));
| ^^^^^^^-------------------
@@ -185,7 +185,7 @@ LL | let _ = deep.0.or_else(|| Some(3));
| help: use `or(..)` instead: `or(Some(3))`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:83:13
+ --> $DIR/unnecessary_lazy_eval.rs:98:13
|
LL | let _ = opt.or_else(|| Some(3));
| ^^^^-------------------
@@ -193,7 +193,7 @@ LL | let _ = opt.or_else(|| Some(3));
| help: use `or(..)` instead: `or(Some(3))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:89:13
+ --> $DIR/unnecessary_lazy_eval.rs:104:13
|
LL | let _ = res2.unwrap_or_else(|_| 2);
| ^^^^^---------------------
@@ -201,7 +201,7 @@ LL | let _ = res2.unwrap_or_else(|_| 2);
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:90:13
+ --> $DIR/unnecessary_lazy_eval.rs:105:13
|
LL | let _ = res2.unwrap_or_else(|_| astronomers_pi);
| ^^^^^----------------------------------
@@ -209,7 +209,7 @@ LL | let _ = res2.unwrap_or_else(|_| astronomers_pi);
| help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:91:13
+ --> $DIR/unnecessary_lazy_eval.rs:106:13
|
LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field);
| ^^^^^--------------------------------------
@@ -217,7 +217,7 @@ LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field);
| help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:113:35
+ --> $DIR/unnecessary_lazy_eval.rs:128:35
|
LL | let _: Result<usize, usize> = res.and_then(|_| Err(2));
| ^^^^--------------------
@@ -225,7 +225,7 @@ LL | let _: Result<usize, usize> = res.and_then(|_| Err(2));
| help: use `and(..)` instead: `and(Err(2))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:114:35
+ --> $DIR/unnecessary_lazy_eval.rs:129:35
|
LL | let _: Result<usize, usize> = res.and_then(|_| Err(astronomers_pi));
| ^^^^---------------------------------
@@ -233,7 +233,7 @@ LL | let _: Result<usize, usize> = res.and_then(|_| Err(astronomers_pi));
| help: use `and(..)` instead: `and(Err(astronomers_pi))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:115:35
+ --> $DIR/unnecessary_lazy_eval.rs:130:35
|
LL | let _: Result<usize, usize> = res.and_then(|_| Err(ext_str.some_field));
| ^^^^-------------------------------------
@@ -241,7 +241,7 @@ LL | let _: Result<usize, usize> = res.and_then(|_| Err(ext_str.some_field))
| help: use `and(..)` instead: `and(Err(ext_str.some_field))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:117:35
+ --> $DIR/unnecessary_lazy_eval.rs:132:35
|
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(2));
| ^^^^------------------
@@ -249,7 +249,7 @@ LL | let _: Result<usize, usize> = res.or_else(|_| Ok(2));
| help: use `or(..)` instead: `or(Ok(2))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:118:35
+ --> $DIR/unnecessary_lazy_eval.rs:133:35
|
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(astronomers_pi));
| ^^^^-------------------------------
@@ -257,7 +257,7 @@ LL | let _: Result<usize, usize> = res.or_else(|_| Ok(astronomers_pi));
| help: use `or(..)` instead: `or(Ok(astronomers_pi))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:119:35
+ --> $DIR/unnecessary_lazy_eval.rs:134:35
|
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(ext_str.some_field));
| ^^^^-----------------------------------
@@ -265,7 +265,7 @@ LL | let _: Result<usize, usize> = res.or_else(|_| Ok(ext_str.some_field));
| help: use `or(..)` instead: `or(Ok(ext_str.some_field))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:120:35
+ --> $DIR/unnecessary_lazy_eval.rs:135:35
|
LL | let _: Result<usize, usize> = res.
| ___________________________________^
diff --git a/src/tools/clippy/tests/ui/unnecessary_self_imports.stderr b/src/tools/clippy/tests/ui/unnecessary_self_imports.stderr
index 83a5618c9..db805eb36 100644
--- a/src/tools/clippy/tests/ui/unnecessary_self_imports.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_self_imports.stderr
@@ -6,8 +6,8 @@ LL | use std::fs::{self as alias};
| |
| help: consider omitting `::{self}`: `fs as alias;`
|
- = note: `-D clippy::unnecessary-self-imports` implied by `-D warnings`
= note: this will slightly change semantics; any non-module items at the same path will also be imported
+ = note: `-D clippy::unnecessary-self-imports` implied by `-D warnings`
error: import ending with `::{self}`
--> $DIR/unnecessary_self_imports.rs:8:1
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
index a920c63b1..fe09aad06 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
@@ -1,6 +1,6 @@
// run-rustfix
-#![allow(clippy::ptr_arg)]
+#![allow(clippy::needless_borrow, clippy::ptr_arg)]
#![warn(clippy::unnecessary_to_owned)]
#![feature(custom_inner_attributes)]
@@ -417,3 +417,12 @@ mod issue_9351 {
predicates_are_satisfied(id("abc".to_string()));
}
}
+
+mod issue_9504 {
+ #![allow(dead_code)]
+
+ async fn foo<S: AsRef<str>>(_: S) {}
+ async fn bar() {
+ foo(std::path::PathBuf::new().to_string_lossy().to_string()).await;
+ }
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
index 2128bdacd..3de6d0903 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.rs
@@ -1,6 +1,6 @@
// run-rustfix
-#![allow(clippy::ptr_arg)]
+#![allow(clippy::needless_borrow, clippy::ptr_arg)]
#![warn(clippy::unnecessary_to_owned)]
#![feature(custom_inner_attributes)]
@@ -417,3 +417,12 @@ mod issue_9351 {
predicates_are_satisfied(id("abc".to_string()));
}
}
+
+mod issue_9504 {
+ #![allow(dead_code)]
+
+ async fn foo<S: AsRef<str>>(_: S) {}
+ async fn bar() {
+ foo(std::path::PathBuf::new().to_string_lossy().to_string()).await;
+ }
+}
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr b/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr
index 7deb90b06..02bf45a33 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.stderr
@@ -4,12 +4,12 @@ error: redundant clone
LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned());
| ^^^^^^^^^^^ help: remove this
|
- = note: `-D clippy::redundant-clone` implied by `-D warnings`
note: this value is dropped without further use
--> $DIR/unnecessary_to_owned.rs:151:20
|
LL | require_c_str(&CString::from_vec_with_nul(vec![0]).unwrap().to_owned());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: `-D clippy::redundant-clone` implied by `-D warnings`
error: redundant clone
--> $DIR/unnecessary_to_owned.rs:152:40
diff --git a/src/tools/clippy/tests/ui/unneeded_field_pattern.stderr b/src/tools/clippy/tests/ui/unneeded_field_pattern.stderr
index b8d3c2945..6f7c31545 100644
--- a/src/tools/clippy/tests/ui/unneeded_field_pattern.stderr
+++ b/src/tools/clippy/tests/ui/unneeded_field_pattern.stderr
@@ -4,8 +4,8 @@ error: you matched a field with a wildcard pattern, consider using `..` instead
LL | Foo { a: _, b: 0, .. } => {},
| ^^^^
|
- = note: `-D clippy::unneeded-field-pattern` implied by `-D warnings`
= help: try with `Foo { b: 0, .. }`
+ = note: `-D clippy::unneeded-field-pattern` implied by `-D warnings`
error: all the struct fields are matched to a wildcard pattern, consider using `..`
--> $DIR/unneeded_field_pattern.rs:16:9
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns.fixed b/src/tools/clippy/tests/ui/unnested_or_patterns.fixed
index c223b5bc7..9786c7b12 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns.fixed
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns.fixed
@@ -1,9 +1,9 @@
// run-rustfix
-#![feature(box_patterns)]
+#![feature(box_patterns, custom_inner_attributes)]
#![warn(clippy::unnested_or_patterns)]
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)]
-#![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)]
+#![allow(unreachable_patterns, irrefutable_let_patterns, unused)]
fn main() {
// Should be ignored by this lint, as nesting requires more characters.
@@ -33,3 +33,15 @@ fn main() {
if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {}
if let S { x: 0, y, .. } | S { y, x: 1 } = (S { x: 0, y: 1 }) {}
}
+
+fn msrv_1_52() {
+ #![clippy::msrv = "1.52"]
+
+ if let [1] | [52] = [0] {}
+}
+
+fn msrv_1_53() {
+ #![clippy::msrv = "1.53"]
+
+ if let [1 | 53] = [0] {}
+}
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns.rs b/src/tools/clippy/tests/ui/unnested_or_patterns.rs
index 04cd11036..f57322396 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns.rs
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns.rs
@@ -1,9 +1,9 @@
// run-rustfix
-#![feature(box_patterns)]
+#![feature(box_patterns, custom_inner_attributes)]
#![warn(clippy::unnested_or_patterns)]
#![allow(clippy::cognitive_complexity, clippy::match_ref_pats, clippy::upper_case_acronyms)]
-#![allow(unreachable_patterns, irrefutable_let_patterns, unused_variables)]
+#![allow(unreachable_patterns, irrefutable_let_patterns, unused)]
fn main() {
// Should be ignored by this lint, as nesting requires more characters.
@@ -33,3 +33,15 @@ fn main() {
if let S { x: 0, y } | S { y, x: 1 } = (S { x: 0, y: 1 }) {}
if let S { x: 0, y, .. } | S { y, x: 1 } = (S { x: 0, y: 1 }) {}
}
+
+fn msrv_1_52() {
+ #![clippy::msrv = "1.52"]
+
+ if let [1] | [52] = [0] {}
+}
+
+fn msrv_1_53() {
+ #![clippy::msrv = "1.53"]
+
+ if let [1] | [53] = [0] {}
+}
diff --git a/src/tools/clippy/tests/ui/unnested_or_patterns.stderr b/src/tools/clippy/tests/ui/unnested_or_patterns.stderr
index 453c66cbb..fbc12fff0 100644
--- a/src/tools/clippy/tests/ui/unnested_or_patterns.stderr
+++ b/src/tools/clippy/tests/ui/unnested_or_patterns.stderr
@@ -175,5 +175,16 @@ help: nest the patterns
LL | if let S { x: 0 | 1, y } = (S { x: 0, y: 1 }) {}
| ~~~~~~~~~~~~~~~~~
-error: aborting due to 16 previous errors
+error: unnested or-patterns
+ --> $DIR/unnested_or_patterns.rs:46:12
+ |
+LL | if let [1] | [53] = [0] {}
+ | ^^^^^^^^^^
+ |
+help: nest the patterns
+ |
+LL | if let [1 | 53] = [0] {}
+ | ~~~~~~~~
+
+error: aborting due to 17 previous errors
diff --git a/src/tools/clippy/tests/ui/unsafe_derive_deserialize.stderr b/src/tools/clippy/tests/ui/unsafe_derive_deserialize.stderr
index 18c4276c6..8aaae2d7f 100644
--- a/src/tools/clippy/tests/ui/unsafe_derive_deserialize.stderr
+++ b/src/tools/clippy/tests/ui/unsafe_derive_deserialize.stderr
@@ -4,8 +4,8 @@ error: you are deriving `serde::Deserialize` on a type that has methods using `u
LL | #[derive(Deserialize)]
| ^^^^^^^^^^^
|
- = note: `-D clippy::unsafe-derive-deserialize` implied by `-D warnings`
= help: consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html
+ = note: `-D clippy::unsafe-derive-deserialize` implied by `-D warnings`
= note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
error: you are deriving `serde::Deserialize` on a type that has methods using `unsafe`
diff --git a/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs b/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs
index cde4e96d6..d29888ac6 100644
--- a/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs
+++ b/src/tools/clippy/tests/ui/unsafe_removed_from_name.rs
@@ -24,4 +24,7 @@ use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety;
use mod_with_some_unsafe_things::Safe as IPromiseItsSafeThisTime;
use mod_with_some_unsafe_things::Unsafe as SuperUnsafeModThing;
+#[allow(clippy::unsafe_removed_from_name)]
+use mod_with_some_unsafe_things::Unsafe as SuperSafeThing;
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/unused_async.stderr b/src/tools/clippy/tests/ui/unused_async.stderr
index 8b8ad065a..cff3eccbd 100644
--- a/src/tools/clippy/tests/ui/unused_async.stderr
+++ b/src/tools/clippy/tests/ui/unused_async.stderr
@@ -6,8 +6,8 @@ LL | | 4
LL | | }
| |_^
|
- = note: `-D clippy::unused-async` implied by `-D warnings`
= help: consider removing the `async` from this function
+ = note: `-D clippy::unused-async` implied by `-D warnings`
error: unused `async` for function with no await statements
--> $DIR/unused_async.rs:17:5
diff --git a/src/tools/clippy/tests/ui/unused_format_specs.fixed b/src/tools/clippy/tests/ui/unused_format_specs.fixed
new file mode 100644
index 000000000..2930722b4
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unused_format_specs.fixed
@@ -0,0 +1,18 @@
+// run-rustfix
+
+#![warn(clippy::unused_format_specs)]
+#![allow(unused)]
+
+fn main() {
+ let f = 1.0f64;
+ println!("{}", 1.0);
+ println!("{f} {f:?}");
+
+ println!("{}", 1);
+}
+
+fn should_not_lint() {
+ let f = 1.0f64;
+ println!("{:.1}", 1.0);
+ println!("{f:.w$} {f:.*?}", 3, w = 2);
+}
diff --git a/src/tools/clippy/tests/ui/unused_format_specs.rs b/src/tools/clippy/tests/ui/unused_format_specs.rs
new file mode 100644
index 000000000..ee192a000
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unused_format_specs.rs
@@ -0,0 +1,18 @@
+// run-rustfix
+
+#![warn(clippy::unused_format_specs)]
+#![allow(unused)]
+
+fn main() {
+ let f = 1.0f64;
+ println!("{:.}", 1.0);
+ println!("{f:.} {f:.?}");
+
+ println!("{:.}", 1);
+}
+
+fn should_not_lint() {
+ let f = 1.0f64;
+ println!("{:.1}", 1.0);
+ println!("{f:.w$} {f:.*?}", 3, w = 2);
+}
diff --git a/src/tools/clippy/tests/ui/unused_format_specs.stderr b/src/tools/clippy/tests/ui/unused_format_specs.stderr
new file mode 100644
index 000000000..7231c17e7
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unused_format_specs.stderr
@@ -0,0 +1,54 @@
+error: empty precision specifier has no effect
+ --> $DIR/unused_format_specs.rs:8:17
+ |
+LL | println!("{:.}", 1.0);
+ | ^
+ |
+ = note: a precision specifier is not required to format floats
+ = note: `-D clippy::unused-format-specs` implied by `-D warnings`
+help: remove the `.`
+ |
+LL - println!("{:.}", 1.0);
+LL + println!("{}", 1.0);
+ |
+
+error: empty precision specifier has no effect
+ --> $DIR/unused_format_specs.rs:9:18
+ |
+LL | println!("{f:.} {f:.?}");
+ | ^
+ |
+ = note: a precision specifier is not required to format floats
+help: remove the `.`
+ |
+LL - println!("{f:.} {f:.?}");
+LL + println!("{f} {f:.?}");
+ |
+
+error: empty precision specifier has no effect
+ --> $DIR/unused_format_specs.rs:9:24
+ |
+LL | println!("{f:.} {f:.?}");
+ | ^
+ |
+ = note: a precision specifier is not required to format floats
+help: remove the `.`
+ |
+LL - println!("{f:.} {f:.?}");
+LL + println!("{f:.} {f:?}");
+ |
+
+error: empty precision specifier has no effect
+ --> $DIR/unused_format_specs.rs:11:17
+ |
+LL | println!("{:.}", 1);
+ | ^
+ |
+help: remove the `.`
+ |
+LL - println!("{:.}", 1);
+LL + println!("{}", 1);
+ |
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui/unused_format_specs_unfixable.rs b/src/tools/clippy/tests/ui/unused_format_specs_unfixable.rs
new file mode 100644
index 000000000..78601a348
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unused_format_specs_unfixable.rs
@@ -0,0 +1,30 @@
+#![warn(clippy::unused_format_specs)]
+#![allow(unused)]
+
+macro_rules! format_args_from_macro {
+ () => {
+ format_args!("from macro")
+ };
+}
+
+fn main() {
+ // prints `.`, not ` .`
+ println!("{:5}.", format_args!(""));
+ //prints `abcde`, not `abc`
+ println!("{:.3}", format_args!("abcde"));
+
+ println!("{:5}.", format_args_from_macro!());
+
+ let args = format_args!("");
+ println!("{args:5}");
+}
+
+fn should_not_lint() {
+ println!("{}", format_args!(""));
+ // Technically the same as `{}`, but the `format_args` docs specifically mention that you can use
+ // debug formatting so allow it
+ println!("{:?}", format_args!(""));
+
+ let args = format_args!("");
+ println!("{args}");
+}
diff --git a/src/tools/clippy/tests/ui/unused_format_specs_unfixable.stderr b/src/tools/clippy/tests/ui/unused_format_specs_unfixable.stderr
new file mode 100644
index 000000000..9f1890282
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unused_format_specs_unfixable.stderr
@@ -0,0 +1,69 @@
+error: format specifiers have no effect on `format_args!()`
+ --> $DIR/unused_format_specs_unfixable.rs:12:15
+ |
+LL | println!("{:5}.", format_args!(""));
+ | ^^^^
+ |
+ = note: `-D clippy::unused-format-specs` implied by `-D warnings`
+help: for the width to apply consider using `format!()`
+ |
+LL | println!("{:5}.", format!(""));
+ | ~~~~~~
+help: if the current behavior is intentional, remove the format specifiers
+ |
+LL - println!("{:5}.", format_args!(""));
+LL + println!("{}.", format_args!(""));
+ |
+
+error: format specifiers have no effect on `format_args!()`
+ --> $DIR/unused_format_specs_unfixable.rs:14:15
+ |
+LL | println!("{:.3}", format_args!("abcde"));
+ | ^^^^^
+ |
+help: for the precision to apply consider using `format!()`
+ |
+LL | println!("{:.3}", format!("abcde"));
+ | ~~~~~~
+help: if the current behavior is intentional, remove the format specifiers
+ |
+LL - println!("{:.3}", format_args!("abcde"));
+LL + println!("{}", format_args!("abcde"));
+ |
+
+error: format specifiers have no effect on `format_args!()`
+ --> $DIR/unused_format_specs_unfixable.rs:16:15
+ |
+LL | println!("{:5}.", format_args_from_macro!());
+ | ^^^^
+ |
+help: for the width to apply consider using `format!()`
+ --> $DIR/unused_format_specs_unfixable.rs:16:17
+ |
+LL | println!("{:5}.", format_args_from_macro!());
+ | ^
+help: if the current behavior is intentional, remove the format specifiers
+ |
+LL - println!("{:5}.", format_args_from_macro!());
+LL + println!("{}.", format_args_from_macro!());
+ |
+
+error: format specifiers have no effect on `format_args!()`
+ --> $DIR/unused_format_specs_unfixable.rs:19:15
+ |
+LL | println!("{args:5}");
+ | ^^^^^^^^
+ |
+help: for the width to apply consider using `format!()`
+ --> $DIR/unused_format_specs_unfixable.rs:19:21
+ |
+LL | println!("{args:5}");
+ | ^
+help: if the current behavior is intentional, remove the format specifiers
+ |
+LL - println!("{args:5}");
+LL + println!("{args}");
+ |
+
+error: aborting due to 4 previous errors
+
diff --git a/src/tools/clippy/tests/ui/unused_io_amount.stderr b/src/tools/clippy/tests/ui/unused_io_amount.stderr
index e5bdd993a..7ba7e09c0 100644
--- a/src/tools/clippy/tests/ui/unused_io_amount.stderr
+++ b/src/tools/clippy/tests/ui/unused_io_amount.stderr
@@ -4,8 +4,8 @@ error: written amount is not handled
LL | s.write(b"test")?;
| ^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::unused-io-amount` implied by `-D warnings`
= help: use `Write::write_all` instead, or handle partial writes
+ = note: `-D clippy::unused-io-amount` implied by `-D warnings`
error: read amount is not handled
--> $DIR/unused_io_amount.rs:11:5
diff --git a/src/tools/clippy/tests/ui/unused_peekable.rs b/src/tools/clippy/tests/ui/unused_peekable.rs
index 153457e36..7374dfdf9 100644
--- a/src/tools/clippy/tests/ui/unused_peekable.rs
+++ b/src/tools/clippy/tests/ui/unused_peekable.rs
@@ -57,12 +57,22 @@ fn valid() {
impl PeekableConsumer {
fn consume(&self, _: Peekable<Empty<u32>>) {}
fn consume_mut_ref(&self, _: &mut Peekable<Empty<u32>>) {}
+ fn consume_assoc(_: Peekable<Empty<u32>>) {}
+ fn consume_assoc_mut_ref(_: &mut Peekable<Empty<u32>>) {}
}
-
let peekable_consumer = PeekableConsumer;
- let mut passed_along_to_method = std::iter::empty::<u32>().peekable();
- peekable_consumer.consume_mut_ref(&mut passed_along_to_method);
- peekable_consumer.consume(passed_along_to_method);
+
+ let peekable = std::iter::empty::<u32>().peekable();
+ peekable_consumer.consume(peekable);
+
+ let mut peekable = std::iter::empty::<u32>().peekable();
+ peekable_consumer.consume_mut_ref(&mut peekable);
+
+ let peekable = std::iter::empty::<u32>().peekable();
+ PeekableConsumer::consume_assoc(peekable);
+
+ let mut peekable = std::iter::empty::<u32>().peekable();
+ PeekableConsumer::consume_assoc_mut_ref(&mut peekable);
// `peek` called in another block
let mut peekable_in_block = std::iter::empty::<u32>().peekable();
@@ -141,4 +151,19 @@ fn valid() {
{
peekable_last_expr.peek();
}
+
+ let mut peek_in_closure = std::iter::empty::<u32>().peekable();
+ let _ = || {
+ let _ = peek_in_closure.peek();
+ };
+
+ trait PeekTrait {}
+ impl<I> PeekTrait for Peekable<I> where I: Iterator {}
+
+ let mut peekable = std::iter::empty::<u32>().peekable();
+ let _dyn = &mut peekable as &mut dyn PeekTrait;
+
+ fn takes_dyn(_: &mut dyn PeekTrait) {}
+ let mut peekable = std::iter::empty::<u32>().peekable();
+ takes_dyn(&mut peekable);
}
diff --git a/src/tools/clippy/tests/ui/unused_peekable.stderr b/src/tools/clippy/tests/ui/unused_peekable.stderr
index d557f5417..54788f2fa 100644
--- a/src/tools/clippy/tests/ui/unused_peekable.stderr
+++ b/src/tools/clippy/tests/ui/unused_peekable.stderr
@@ -4,8 +4,8 @@ error: `peek` never called on `Peekable` iterator
LL | let peekable = std::iter::empty::<u32>().peekable();
| ^^^^^^^^
|
- = note: `-D clippy::unused-peekable` implied by `-D warnings`
= help: consider removing the call to `peekable`
+ = note: `-D clippy::unused-peekable` implied by `-D warnings`
error: `peek` never called on `Peekable` iterator
--> $DIR/unused_peekable.rs:18:9
diff --git a/src/tools/clippy/tests/ui/unused_self.stderr b/src/tools/clippy/tests/ui/unused_self.stderr
index 0534b40ea..23186122a 100644
--- a/src/tools/clippy/tests/ui/unused_self.stderr
+++ b/src/tools/clippy/tests/ui/unused_self.stderr
@@ -4,8 +4,8 @@ error: unused `self` argument
LL | fn unused_self_move(self) {}
| ^^^^
|
- = note: `-D clippy::unused-self` implied by `-D warnings`
= help: consider refactoring to a associated function
+ = note: `-D clippy::unused-self` implied by `-D warnings`
error: unused `self` argument
--> $DIR/unused_self.rs:12:28
diff --git a/src/tools/clippy/tests/ui/unwrap.stderr b/src/tools/clippy/tests/ui/unwrap.stderr
index 784227578..e88d580f7 100644
--- a/src/tools/clippy/tests/ui/unwrap.stderr
+++ b/src/tools/clippy/tests/ui/unwrap.stderr
@@ -4,8 +4,8 @@ error: used `unwrap()` on `an Option` value
LL | let _ = opt.unwrap();
| ^^^^^^^^^^^^
|
- = note: `-D clippy::unwrap-used` implied by `-D warnings`
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
+ = note: `-D clippy::unwrap-used` implied by `-D warnings`
error: used `unwrap()` on `a Result` value
--> $DIR/unwrap.rs:10:13
diff --git a/src/tools/clippy/tests/ui/unwrap_expect_used.stderr b/src/tools/clippy/tests/ui/unwrap_expect_used.stderr
index 1a19459b2..211d2be18 100644
--- a/src/tools/clippy/tests/ui/unwrap_expect_used.stderr
+++ b/src/tools/clippy/tests/ui/unwrap_expect_used.stderr
@@ -4,8 +4,8 @@ error: used `unwrap()` on `an Option` value
LL | Some(3).unwrap();
| ^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::unwrap-used` implied by `-D warnings`
= help: if this value is `None`, it will panic
+ = note: `-D clippy::unwrap-used` implied by `-D warnings`
error: used `expect()` on `an Option` value
--> $DIR/unwrap_expect_used.rs:24:5
@@ -13,8 +13,8 @@ error: used `expect()` on `an Option` value
LL | Some(3).expect("Hello world!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::expect-used` implied by `-D warnings`
= help: if this value is `None`, it will panic
+ = note: `-D clippy::expect-used` implied by `-D warnings`
error: used `unwrap()` on `a Result` value
--> $DIR/unwrap_expect_used.rs:31:5
diff --git a/src/tools/clippy/tests/ui/unwrap_in_result.stderr b/src/tools/clippy/tests/ui/unwrap_in_result.stderr
index 56bc2f2d1..40e6bfe08 100644
--- a/src/tools/clippy/tests/ui/unwrap_in_result.stderr
+++ b/src/tools/clippy/tests/ui/unwrap_in_result.stderr
@@ -10,13 +10,13 @@ LL | | }
LL | | }
| |_____^
|
- = note: `-D clippy::unwrap-in-result` implied by `-D warnings`
= help: unwrap and expect should not be used in a function that returns result or option
note: potential non-recoverable error(s)
--> $DIR/unwrap_in_result.rs:24:17
|
LL | let i = i_str.parse::<i32>().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: `-D clippy::unwrap-in-result` implied by `-D warnings`
error: used unwrap or expect in a function that returns result or option
--> $DIR/unwrap_in_result.rs:32:5
diff --git a/src/tools/clippy/tests/ui/upper_case_acronyms.rs b/src/tools/clippy/tests/ui/upper_case_acronyms.rs
index 48bb9e54b..9b7c2f28e 100644
--- a/src/tools/clippy/tests/ui/upper_case_acronyms.rs
+++ b/src/tools/clippy/tests/ui/upper_case_acronyms.rs
@@ -38,4 +38,13 @@ enum ParseErrorPrivate<T> {
Parse(T, String),
}
+// do lint here
+struct JSON;
+
+// do lint here
+enum YAML {
+ Num(u32),
+ Str(String),
+}
+
fn main() {}
diff --git a/src/tools/clippy/tests/ui/upper_case_acronyms.stderr b/src/tools/clippy/tests/ui/upper_case_acronyms.stderr
index 250b196a9..74082ec16 100644
--- a/src/tools/clippy/tests/ui/upper_case_acronyms.stderr
+++ b/src/tools/clippy/tests/ui/upper_case_acronyms.stderr
@@ -54,5 +54,17 @@ error: name `WASD` contains a capitalized acronym
LL | WASD(u8),
| ^^^^ help: consider making the acronym lowercase, except the initial letter: `Wasd`
-error: aborting due to 9 previous errors
+error: name `JSON` contains a capitalized acronym
+ --> $DIR/upper_case_acronyms.rs:42:8
+ |
+LL | struct JSON;
+ | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Json`
+
+error: name `YAML` contains a capitalized acronym
+ --> $DIR/upper_case_acronyms.rs:45:6
+ |
+LL | enum YAML {
+ | ^^^^ help: consider making the acronym lowercase, except the initial letter: `Yaml`
+
+error: aborting due to 11 previous errors
diff --git a/src/tools/clippy/tests/ui/use_self.fixed b/src/tools/clippy/tests/ui/use_self.fixed
index 4f80aaecc..3b54fe9d5 100644
--- a/src/tools/clippy/tests/ui/use_self.fixed
+++ b/src/tools/clippy/tests/ui/use_self.fixed
@@ -1,6 +1,7 @@
// run-rustfix
// aux-build:proc_macro_derive.rs
+#![feature(custom_inner_attributes)]
#![warn(clippy::use_self)]
#![allow(dead_code, unreachable_code)]
#![allow(
@@ -608,3 +609,44 @@ mod issue8845 {
}
}
}
+
+mod issue6902 {
+ use serde::Serialize;
+
+ #[derive(Serialize)]
+ pub enum Foo {
+ Bar = 1,
+ }
+}
+
+fn msrv_1_36() {
+ #![clippy::msrv = "1.36"]
+
+ enum E {
+ A,
+ }
+
+ impl E {
+ fn foo(self) {
+ match self {
+ E::A => {},
+ }
+ }
+ }
+}
+
+fn msrv_1_37() {
+ #![clippy::msrv = "1.37"]
+
+ enum E {
+ A,
+ }
+
+ impl E {
+ fn foo(self) {
+ match self {
+ Self::A => {},
+ }
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/use_self.rs b/src/tools/clippy/tests/ui/use_self.rs
index 52da72db5..bf87633cd 100644
--- a/src/tools/clippy/tests/ui/use_self.rs
+++ b/src/tools/clippy/tests/ui/use_self.rs
@@ -1,6 +1,7 @@
// run-rustfix
// aux-build:proc_macro_derive.rs
+#![feature(custom_inner_attributes)]
#![warn(clippy::use_self)]
#![allow(dead_code, unreachable_code)]
#![allow(
@@ -608,3 +609,44 @@ mod issue8845 {
}
}
}
+
+mod issue6902 {
+ use serde::Serialize;
+
+ #[derive(Serialize)]
+ pub enum Foo {
+ Bar = 1,
+ }
+}
+
+fn msrv_1_36() {
+ #![clippy::msrv = "1.36"]
+
+ enum E {
+ A,
+ }
+
+ impl E {
+ fn foo(self) {
+ match self {
+ E::A => {},
+ }
+ }
+ }
+}
+
+fn msrv_1_37() {
+ #![clippy::msrv = "1.37"]
+
+ enum E {
+ A,
+ }
+
+ impl E {
+ fn foo(self) {
+ match self {
+ E::A => {},
+ }
+ }
+ }
+}
diff --git a/src/tools/clippy/tests/ui/use_self.stderr b/src/tools/clippy/tests/ui/use_self.stderr
index f06bb959b..16fb06092 100644
--- a/src/tools/clippy/tests/ui/use_self.stderr
+++ b/src/tools/clippy/tests/ui/use_self.stderr
@@ -1,5 +1,5 @@
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:22:21
+ --> $DIR/use_self.rs:23:21
|
LL | fn new() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
@@ -7,244 +7,250 @@ LL | fn new() -> Foo {
= note: `-D clippy::use-self` implied by `-D warnings`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:23:13
+ --> $DIR/use_self.rs:24:13
|
LL | Foo {}
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:25:22
+ --> $DIR/use_self.rs:26:22
|
LL | fn test() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:26:13
+ --> $DIR/use_self.rs:27:13
|
LL | Foo::new()
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:31:25
+ --> $DIR/use_self.rs:32:25
|
LL | fn default() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:32:13
+ --> $DIR/use_self.rs:33:13
|
LL | Foo::new()
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:97:24
+ --> $DIR/use_self.rs:98:24
|
LL | fn bad(foos: &[Foo]) -> impl Iterator<Item = &Foo> {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:97:55
+ --> $DIR/use_self.rs:98:55
|
LL | fn bad(foos: &[Foo]) -> impl Iterator<Item = &Foo> {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:112:13
+ --> $DIR/use_self.rs:113:13
|
LL | TS(0)
| ^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:147:29
+ --> $DIR/use_self.rs:148:29
|
LL | fn bar() -> Bar {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:148:21
+ --> $DIR/use_self.rs:149:21
|
LL | Bar { foo: Foo {} }
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:159:21
+ --> $DIR/use_self.rs:160:21
|
LL | fn baz() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:160:13
+ --> $DIR/use_self.rs:161:13
|
LL | Foo {}
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:177:21
+ --> $DIR/use_self.rs:178:21
|
LL | let _ = Enum::B(42);
| ^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:178:21
+ --> $DIR/use_self.rs:179:21
|
LL | let _ = Enum::C { field: true };
| ^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:179:21
+ --> $DIR/use_self.rs:180:21
|
LL | let _ = Enum::A;
| ^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:221:13
+ --> $DIR/use_self.rs:222:13
|
LL | nested::A::fun_1();
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:222:13
+ --> $DIR/use_self.rs:223:13
|
LL | nested::A::A;
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:224:13
+ --> $DIR/use_self.rs:225:13
|
LL | nested::A {};
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:243:13
+ --> $DIR/use_self.rs:244:13
|
LL | TestStruct::from_something()
| ^^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:257:25
+ --> $DIR/use_self.rs:258:25
|
LL | async fn g() -> S {
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:258:13
+ --> $DIR/use_self.rs:259:13
|
LL | S {}
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:262:16
+ --> $DIR/use_self.rs:263:16
|
LL | &p[S::A..S::B]
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:262:22
+ --> $DIR/use_self.rs:263:22
|
LL | &p[S::A..S::B]
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:285:29
+ --> $DIR/use_self.rs:286:29
|
LL | fn foo(value: T) -> Foo<T> {
| ^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:286:13
+ --> $DIR/use_self.rs:287:13
|
LL | Foo::<T> { value }
| ^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:458:13
+ --> $DIR/use_self.rs:459:13
|
LL | A::new::<submod::B>(submod::B {})
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:495:13
+ --> $DIR/use_self.rs:496:13
|
LL | S2::new()
| ^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:532:17
+ --> $DIR/use_self.rs:533:17
|
LL | Foo::Bar => unimplemented!(),
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:533:17
+ --> $DIR/use_self.rs:534:17
|
LL | Foo::Baz => unimplemented!(),
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:539:20
+ --> $DIR/use_self.rs:540:20
|
LL | if let Foo::Bar = self {
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:563:17
+ --> $DIR/use_self.rs:564:17
|
LL | Something::Num(n) => *n,
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:564:17
+ --> $DIR/use_self.rs:565:17
|
LL | Something::TupleNums(n, _m) => *n,
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:565:17
+ --> $DIR/use_self.rs:566:17
|
LL | Something::StructNums { one, two: _ } => *one,
| ^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:571:17
+ --> $DIR/use_self.rs:572:17
|
LL | crate::issue8845::Something::Num(n) => *n,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:572:17
+ --> $DIR/use_self.rs:573:17
|
LL | crate::issue8845::Something::TupleNums(n, _m) => *n,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:573:17
+ --> $DIR/use_self.rs:574:17
|
LL | crate::issue8845::Something::StructNums { one, two: _ } => *one,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:589:17
+ --> $DIR/use_self.rs:590:17
|
LL | let Foo(x) = self;
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:594:17
+ --> $DIR/use_self.rs:595:17
|
LL | let crate::issue8845::Foo(x) = self;
| ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:601:17
+ --> $DIR/use_self.rs:602:17
|
LL | let Bar { x, .. } = self;
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
- --> $DIR/use_self.rs:606:17
+ --> $DIR/use_self.rs:607:17
|
LL | let crate::issue8845::Bar { x, .. } = self;
| ^^^^^^^^^^^^^^^^^^^^^ help: use the applicable keyword: `Self`
-error: aborting due to 41 previous errors
+error: unnecessary structure name repetition
+ --> $DIR/use_self.rs:648:17
+ |
+LL | E::A => {},
+ | ^ help: use the applicable keyword: `Self`
+
+error: aborting due to 42 previous errors
diff --git a/src/tools/clippy/tests/ui/used_underscore_binding.rs b/src/tools/clippy/tests/ui/used_underscore_binding.rs
index 322083511..8c29e15b1 100644
--- a/src/tools/clippy/tests/ui/used_underscore_binding.rs
+++ b/src/tools/clippy/tests/ui/used_underscore_binding.rs
@@ -1,9 +1,8 @@
// aux-build:proc_macro_derive.rs
-
#![feature(rustc_private)]
#![warn(clippy::all)]
-#![allow(clippy::disallowed_names, clippy::eq_op)]
#![warn(clippy::used_underscore_binding)]
+#![allow(clippy::disallowed_names, clippy::eq_op, clippy::uninlined_format_args)]
#[macro_use]
extern crate proc_macro_derive;
diff --git a/src/tools/clippy/tests/ui/used_underscore_binding.stderr b/src/tools/clippy/tests/ui/used_underscore_binding.stderr
index 61a9161d2..875fafe43 100644
--- a/src/tools/clippy/tests/ui/used_underscore_binding.stderr
+++ b/src/tools/clippy/tests/ui/used_underscore_binding.stderr
@@ -1,5 +1,5 @@
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
- --> $DIR/used_underscore_binding.rs:25:5
+ --> $DIR/used_underscore_binding.rs:24:5
|
LL | _foo + 1
| ^^^^
@@ -7,31 +7,31 @@ LL | _foo + 1
= note: `-D clippy::used-underscore-binding` implied by `-D warnings`
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
- --> $DIR/used_underscore_binding.rs:30:20
+ --> $DIR/used_underscore_binding.rs:29:20
|
LL | println!("{}", _foo);
| ^^^^
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
- --> $DIR/used_underscore_binding.rs:31:16
+ --> $DIR/used_underscore_binding.rs:30:16
|
LL | assert_eq!(_foo, _foo);
| ^^^^
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
- --> $DIR/used_underscore_binding.rs:31:22
+ --> $DIR/used_underscore_binding.rs:30:22
|
LL | assert_eq!(_foo, _foo);
| ^^^^
error: used binding `_underscore_field` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
- --> $DIR/used_underscore_binding.rs:44:5
+ --> $DIR/used_underscore_binding.rs:43:5
|
LL | s._underscore_field += 1;
| ^^^^^^^^^^^^^^^^^^^
error: used binding `_i` which is prefixed with an underscore. A leading underscore signals that a binding will not be used
- --> $DIR/used_underscore_binding.rs:105:16
+ --> $DIR/used_underscore_binding.rs:104:16
|
LL | uses_i(_i);
| ^^
diff --git a/src/tools/clippy/tests/ui/useless_asref.fixed b/src/tools/clippy/tests/ui/useless_asref.fixed
index 90cb8945e..38e4b9201 100644
--- a/src/tools/clippy/tests/ui/useless_asref.fixed
+++ b/src/tools/clippy/tests/ui/useless_asref.fixed
@@ -1,7 +1,6 @@
// run-rustfix
-
#![deny(clippy::useless_asref)]
-#![allow(clippy::explicit_auto_deref)]
+#![allow(clippy::explicit_auto_deref, clippy::uninlined_format_args)]
use std::fmt::Debug;
diff --git a/src/tools/clippy/tests/ui/useless_asref.rs b/src/tools/clippy/tests/ui/useless_asref.rs
index cb9f8ae59..f1e83f9d3 100644
--- a/src/tools/clippy/tests/ui/useless_asref.rs
+++ b/src/tools/clippy/tests/ui/useless_asref.rs
@@ -1,7 +1,6 @@
// run-rustfix
-
#![deny(clippy::useless_asref)]
-#![allow(clippy::explicit_auto_deref)]
+#![allow(clippy::explicit_auto_deref, clippy::uninlined_format_args)]
use std::fmt::Debug;
diff --git a/src/tools/clippy/tests/ui/useless_asref.stderr b/src/tools/clippy/tests/ui/useless_asref.stderr
index b21c67bb3..67ce8b64e 100644
--- a/src/tools/clippy/tests/ui/useless_asref.stderr
+++ b/src/tools/clippy/tests/ui/useless_asref.stderr
@@ -1,71 +1,71 @@
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:44:18
+ --> $DIR/useless_asref.rs:43:18
|
LL | foo_rstr(rstr.as_ref());
| ^^^^^^^^^^^^^ help: try this: `rstr`
|
note: the lint level is defined here
- --> $DIR/useless_asref.rs:3:9
+ --> $DIR/useless_asref.rs:2:9
|
LL | #![deny(clippy::useless_asref)]
| ^^^^^^^^^^^^^^^^^^^^^
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:46:20
+ --> $DIR/useless_asref.rs:45:20
|
LL | foo_rslice(rslice.as_ref());
| ^^^^^^^^^^^^^^^ help: try this: `rslice`
error: this call to `as_mut` does nothing
- --> $DIR/useless_asref.rs:50:21
+ --> $DIR/useless_asref.rs:49:21
|
LL | foo_mrslice(mrslice.as_mut());
| ^^^^^^^^^^^^^^^^ help: try this: `mrslice`
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:52:20
+ --> $DIR/useless_asref.rs:51:20
|
LL | foo_rslice(mrslice.as_ref());
| ^^^^^^^^^^^^^^^^ help: try this: `mrslice`
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:59:20
+ --> $DIR/useless_asref.rs:58:20
|
LL | foo_rslice(rrrrrslice.as_ref());
| ^^^^^^^^^^^^^^^^^^^ help: try this: `rrrrrslice`
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:61:18
+ --> $DIR/useless_asref.rs:60:18
|
LL | foo_rstr(rrrrrstr.as_ref());
| ^^^^^^^^^^^^^^^^^ help: try this: `rrrrrstr`
error: this call to `as_mut` does nothing
- --> $DIR/useless_asref.rs:66:21
+ --> $DIR/useless_asref.rs:65:21
|
LL | foo_mrslice(mrrrrrslice.as_mut());
| ^^^^^^^^^^^^^^^^^^^^ help: try this: `mrrrrrslice`
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:68:20
+ --> $DIR/useless_asref.rs:67:20
|
LL | foo_rslice(mrrrrrslice.as_ref());
| ^^^^^^^^^^^^^^^^^^^^ help: try this: `mrrrrrslice`
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:72:16
+ --> $DIR/useless_asref.rs:71:16
|
LL | foo_rrrrmr((&&&&MoreRef).as_ref());
| ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `(&&&&MoreRef)`
error: this call to `as_mut` does nothing
- --> $DIR/useless_asref.rs:122:13
+ --> $DIR/useless_asref.rs:121:13
|
LL | foo_mrt(mrt.as_mut());
| ^^^^^^^^^^^^ help: try this: `mrt`
error: this call to `as_ref` does nothing
- --> $DIR/useless_asref.rs:124:12
+ --> $DIR/useless_asref.rs:123:12
|
LL | foo_rt(mrt.as_ref());
| ^^^^^^^^^^^^ help: try this: `mrt`
diff --git a/src/tools/clippy/tests/ui/useless_conversion.stderr b/src/tools/clippy/tests/ui/useless_conversion.stderr
index e6760f700..65ee3807f 100644
--- a/src/tools/clippy/tests/ui/useless_conversion.stderr
+++ b/src/tools/clippy/tests/ui/useless_conversion.stderr
@@ -46,7 +46,7 @@ error: useless conversion to the same type: `std::string::String`
LL | let _ = String::from(format!("A: {:04}", 123));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)`
-error: useless conversion to the same type: `std::str::Lines`
+error: useless conversion to the same type: `std::str::Lines<'_>`
--> $DIR/useless_conversion.rs:65:13
|
LL | let _ = "".lines().into_iter();
diff --git a/src/tools/clippy/tests/ui/useless_conversion_try.stderr b/src/tools/clippy/tests/ui/useless_conversion_try.stderr
index 12e74d614..9aef9dda6 100644
--- a/src/tools/clippy/tests/ui/useless_conversion_try.stderr
+++ b/src/tools/clippy/tests/ui/useless_conversion_try.stderr
@@ -4,12 +4,12 @@ error: useless conversion to the same type: `T`
LL | let _ = T::try_from(val).unwrap();
| ^^^^^^^^^^^^^^^^
|
+ = help: consider removing `T::try_from()`
note: the lint level is defined here
--> $DIR/useless_conversion_try.rs:1:9
|
LL | #![deny(clippy::useless_conversion)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: consider removing `T::try_from()`
error: useless conversion to the same type: `T`
--> $DIR/useless_conversion_try.rs:5:5
diff --git a/src/tools/clippy/tests/ui/vec.fixed b/src/tools/clippy/tests/ui/vec.fixed
index 318f9c2dc..2518d8049 100644
--- a/src/tools/clippy/tests/ui/vec.fixed
+++ b/src/tools/clippy/tests/ui/vec.fixed
@@ -1,6 +1,6 @@
// run-rustfix
-#![allow(clippy::nonstandard_macro_braces)]
#![warn(clippy::useless_vec)]
+#![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args)]
#[derive(Debug)]
struct NonCopy;
diff --git a/src/tools/clippy/tests/ui/vec.rs b/src/tools/clippy/tests/ui/vec.rs
index d7673ce3e..e1492e2f3 100644
--- a/src/tools/clippy/tests/ui/vec.rs
+++ b/src/tools/clippy/tests/ui/vec.rs
@@ -1,6 +1,6 @@
// run-rustfix
-#![allow(clippy::nonstandard_macro_braces)]
#![warn(clippy::useless_vec)]
+#![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args)]
#[derive(Debug)]
struct NonCopy;
diff --git a/src/tools/clippy/tests/ui/vec_resize_to_zero.stderr b/src/tools/clippy/tests/ui/vec_resize_to_zero.stderr
index 7428cf62d..8851e9f38 100644
--- a/src/tools/clippy/tests/ui/vec_resize_to_zero.stderr
+++ b/src/tools/clippy/tests/ui/vec_resize_to_zero.stderr
@@ -6,8 +6,8 @@ LL | v.resize(0, 5);
| |
| help: ...or you can empty the vector with: `clear()`
|
- = note: `-D clippy::vec-resize-to-zero` implied by `-D warnings`
= help: the arguments may be inverted...
+ = note: `-D clippy::vec-resize-to-zero` implied by `-D warnings`
error: aborting due to previous error
diff --git a/src/tools/clippy/tests/ui/verbose_file_reads.stderr b/src/tools/clippy/tests/ui/verbose_file_reads.stderr
index 550b6ab67..44266c7c0 100644
--- a/src/tools/clippy/tests/ui/verbose_file_reads.stderr
+++ b/src/tools/clippy/tests/ui/verbose_file_reads.stderr
@@ -4,8 +4,8 @@ error: use of `File::read_to_end`
LL | f.read_to_end(&mut buffer)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::verbose-file-reads` implied by `-D warnings`
= help: consider using `fs::read` instead
+ = note: `-D clippy::verbose-file-reads` implied by `-D warnings`
error: use of `File::read_to_string`
--> $DIR/verbose_file_reads.rs:26:5
diff --git a/src/tools/clippy/tests/ui/vtable_address_comparisons.stderr b/src/tools/clippy/tests/ui/vtable_address_comparisons.stderr
index 2f1be61e5..14748f583 100644
--- a/src/tools/clippy/tests/ui/vtable_address_comparisons.stderr
+++ b/src/tools/clippy/tests/ui/vtable_address_comparisons.stderr
@@ -4,8 +4,8 @@ error: comparing trait object pointers compares a non-unique vtable address
LL | let _ = a == b;
| ^^^^^^
|
- = note: `-D clippy::vtable-address-comparisons` implied by `-D warnings`
= help: consider extracting and comparing data pointers only
+ = note: `-D clippy::vtable-address-comparisons` implied by `-D warnings`
error: comparing trait object pointers compares a non-unique vtable address
--> $DIR/vtable_address_comparisons.rs:15:13
diff --git a/src/tools/clippy/tests/ui/while_let_loop.rs b/src/tools/clippy/tests/ui/while_let_loop.rs
index c42e2a79a..5b8075731 100644
--- a/src/tools/clippy/tests/ui/while_let_loop.rs
+++ b/src/tools/clippy/tests/ui/while_let_loop.rs
@@ -1,4 +1,5 @@
#![warn(clippy::while_let_loop)]
+#![allow(clippy::uninlined_format_args)]
fn main() {
let y = Some(true);
diff --git a/src/tools/clippy/tests/ui/while_let_loop.stderr b/src/tools/clippy/tests/ui/while_let_loop.stderr
index 13dd0ee22..04808c0b3 100644
--- a/src/tools/clippy/tests/ui/while_let_loop.stderr
+++ b/src/tools/clippy/tests/ui/while_let_loop.stderr
@@ -1,5 +1,5 @@
error: this loop could be written as a `while let` loop
- --> $DIR/while_let_loop.rs:5:5
+ --> $DIR/while_let_loop.rs:6:5
|
LL | / loop {
LL | | if let Some(_x) = y {
@@ -13,7 +13,7 @@ LL | | }
= note: `-D clippy::while-let-loop` implied by `-D warnings`
error: this loop could be written as a `while let` loop
- --> $DIR/while_let_loop.rs:22:5
+ --> $DIR/while_let_loop.rs:23:5
|
LL | / loop {
LL | | match y {
@@ -24,7 +24,7 @@ LL | | }
| |_____^ help: try: `while let Some(_x) = y { .. }`
error: this loop could be written as a `while let` loop
- --> $DIR/while_let_loop.rs:29:5
+ --> $DIR/while_let_loop.rs:30:5
|
LL | / loop {
LL | | let x = match y {
@@ -36,7 +36,7 @@ LL | | }
| |_____^ help: try: `while let Some(x) = y { .. }`
error: this loop could be written as a `while let` loop
- --> $DIR/while_let_loop.rs:38:5
+ --> $DIR/while_let_loop.rs:39:5
|
LL | / loop {
LL | | let x = match y {
@@ -48,7 +48,7 @@ LL | | }
| |_____^ help: try: `while let Some(x) = y { .. }`
error: this loop could be written as a `while let` loop
- --> $DIR/while_let_loop.rs:68:5
+ --> $DIR/while_let_loop.rs:69:5
|
LL | / loop {
LL | | let (e, l) = match "".split_whitespace().next() {
diff --git a/src/tools/clippy/tests/ui/while_let_on_iterator.fixed b/src/tools/clippy/tests/ui/while_let_on_iterator.fixed
index c57c46736..5afa0a89f 100644
--- a/src/tools/clippy/tests/ui/while_let_on_iterator.fixed
+++ b/src/tools/clippy/tests/ui/while_let_on_iterator.fixed
@@ -1,14 +1,12 @@
// run-rustfix
-
#![warn(clippy::while_let_on_iterator)]
+#![allow(dead_code, unreachable_code, unused_mut)]
#![allow(
- clippy::never_loop,
- unreachable_code,
- unused_mut,
- dead_code,
clippy::equatable_if_let,
clippy::manual_find,
- clippy::redundant_closure_call
+ clippy::never_loop,
+ clippy::redundant_closure_call,
+ clippy::uninlined_format_args
)]
fn base() {
diff --git a/src/tools/clippy/tests/ui/while_let_on_iterator.rs b/src/tools/clippy/tests/ui/while_let_on_iterator.rs
index 8b9a2dbcc..3de586c9d 100644
--- a/src/tools/clippy/tests/ui/while_let_on_iterator.rs
+++ b/src/tools/clippy/tests/ui/while_let_on_iterator.rs
@@ -1,14 +1,12 @@
// run-rustfix
-
#![warn(clippy::while_let_on_iterator)]
+#![allow(dead_code, unreachable_code, unused_mut)]
#![allow(
- clippy::never_loop,
- unreachable_code,
- unused_mut,
- dead_code,
clippy::equatable_if_let,
clippy::manual_find,
- clippy::redundant_closure_call
+ clippy::never_loop,
+ clippy::redundant_closure_call,
+ clippy::uninlined_format_args
)]
fn base() {
diff --git a/src/tools/clippy/tests/ui/while_let_on_iterator.stderr b/src/tools/clippy/tests/ui/while_let_on_iterator.stderr
index 3236765e1..4d9866619 100644
--- a/src/tools/clippy/tests/ui/while_let_on_iterator.stderr
+++ b/src/tools/clippy/tests/ui/while_let_on_iterator.stderr
@@ -1,5 +1,5 @@
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:16:5
+ --> $DIR/while_let_on_iterator.rs:14:5
|
LL | while let Option::Some(x) = iter.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter`
@@ -7,151 +7,151 @@ LL | while let Option::Some(x) = iter.next() {
= note: `-D clippy::while-let-on-iterator` implied by `-D warnings`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:21:5
+ --> $DIR/while_let_on_iterator.rs:19:5
|
LL | while let Some(x) = iter.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in iter`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:26:5
+ --> $DIR/while_let_on_iterator.rs:24:5
|
LL | while let Some(_) = iter.next() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in iter`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:102:9
+ --> $DIR/while_let_on_iterator.rs:100:9
|
LL | while let Some([..]) = it.next() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [..] in it`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:109:9
+ --> $DIR/while_let_on_iterator.rs:107:9
|
LL | while let Some([_x]) = it.next() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for [_x] in it`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:122:9
+ --> $DIR/while_let_on_iterator.rs:120:9
|
LL | while let Some(x @ [_]) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x @ [_] in it`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:142:9
+ --> $DIR/while_let_on_iterator.rs:140:9
|
LL | while let Some(_) = y.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in y`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:199:9
+ --> $DIR/while_let_on_iterator.rs:197:9
|
LL | while let Some(m) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it.by_ref()`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:210:5
+ --> $DIR/while_let_on_iterator.rs:208:5
|
LL | while let Some(n) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for n in it`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:212:9
+ --> $DIR/while_let_on_iterator.rs:210:9
|
LL | while let Some(m) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:221:9
+ --> $DIR/while_let_on_iterator.rs:219:9
|
LL | while let Some(m) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:230:9
+ --> $DIR/while_let_on_iterator.rs:228:9
|
LL | while let Some(m) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it.by_ref()`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:247:9
+ --> $DIR/while_let_on_iterator.rs:245:9
|
LL | while let Some(m) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for m in it.by_ref()`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:262:13
+ --> $DIR/while_let_on_iterator.rs:260:13
|
LL | while let Some(i) = self.0.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for i in self.0.by_ref()`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:294:13
+ --> $DIR/while_let_on_iterator.rs:292:13
|
LL | while let Some(i) = self.0.0.0.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for i in self.0.0.0.by_ref()`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:323:5
+ --> $DIR/while_let_on_iterator.rs:321:5
|
LL | while let Some(n) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for n in it.by_ref()`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:335:9
+ --> $DIR/while_let_on_iterator.rs:333:9
|
LL | while let Some(x) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.by_ref()`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:349:5
+ --> $DIR/while_let_on_iterator.rs:347:5
|
LL | while let Some(x) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.by_ref()`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:360:5
+ --> $DIR/while_let_on_iterator.rs:358:5
|
LL | while let Some(x) = it.0.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.0.by_ref()`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:395:5
+ --> $DIR/while_let_on_iterator.rs:393:5
|
LL | while let Some(x) = s.x.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in s.x.by_ref()`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:402:5
+ --> $DIR/while_let_on_iterator.rs:400:5
|
LL | while let Some(x) = x[0].next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in x[0].by_ref()`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:410:9
+ --> $DIR/while_let_on_iterator.rs:408:9
|
LL | while let Some(x) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:420:9
+ --> $DIR/while_let_on_iterator.rs:418:9
|
LL | while let Some(x) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:430:9
+ --> $DIR/while_let_on_iterator.rs:428:9
|
LL | while let Some(x) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it.by_ref()`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:440:9
+ --> $DIR/while_let_on_iterator.rs:438:9
|
LL | while let Some(x) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in it`
error: this loop could be written as a `for` loop
- --> $DIR/while_let_on_iterator.rs:450:5
+ --> $DIR/while_let_on_iterator.rs:448:5
|
LL | while let Some(..) = it.next() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in it`
diff --git a/src/tools/clippy/tests/ui/wild_in_or_pats.stderr b/src/tools/clippy/tests/ui/wild_in_or_pats.stderr
index 45b87aa0f..bd5860f45 100644
--- a/src/tools/clippy/tests/ui/wild_in_or_pats.stderr
+++ b/src/tools/clippy/tests/ui/wild_in_or_pats.stderr
@@ -4,8 +4,8 @@ error: wildcard pattern covers any other pattern as it will match anyway
LL | "bar" | _ => {
| ^^^^^^^^^
|
- = note: `-D clippy::wildcard-in-or-patterns` implied by `-D warnings`
= help: consider handling `_` separately
+ = note: `-D clippy::wildcard-in-or-patterns` implied by `-D warnings`
error: wildcard pattern covers any other pattern as it will match anyway
--> $DIR/wild_in_or_pats.rs:16:9
diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed
index 3ee4ab48a..236074978 100644
--- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed
+++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed
@@ -1,15 +1,13 @@
// run-rustfix
// aux-build:non-exhaustive-enum.rs
-
#![deny(clippy::wildcard_enum_match_arm)]
+#![allow(dead_code, unreachable_code, unused_variables)]
#![allow(
- unreachable_code,
- unused_variables,
- dead_code,
+ clippy::diverging_sub_expression,
clippy::single_match,
- clippy::wildcard_in_or_patterns,
+ clippy::uninlined_format_args,
clippy::unnested_or_patterns,
- clippy::diverging_sub_expression
+ clippy::wildcard_in_or_patterns
)]
extern crate non_exhaustive_enum;
diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs
index 468865504..decd86165 100644
--- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs
+++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs
@@ -1,15 +1,13 @@
// run-rustfix
// aux-build:non-exhaustive-enum.rs
-
#![deny(clippy::wildcard_enum_match_arm)]
+#![allow(dead_code, unreachable_code, unused_variables)]
#![allow(
- unreachable_code,
- unused_variables,
- dead_code,
+ clippy::diverging_sub_expression,
clippy::single_match,
- clippy::wildcard_in_or_patterns,
+ clippy::uninlined_format_args,
clippy::unnested_or_patterns,
- clippy::diverging_sub_expression
+ clippy::wildcard_in_or_patterns
)]
extern crate non_exhaustive_enum;
diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr
index d63f20903..efecc9576 100644
--- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr
+++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr
@@ -1,41 +1,41 @@
error: wildcard match will also match any future added variants
- --> $DIR/wildcard_enum_match_arm.rs:42:9
+ --> $DIR/wildcard_enum_match_arm.rs:40:9
|
LL | _ => eprintln!("Not red"),
| ^ help: try this: `Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan`
|
note: the lint level is defined here
- --> $DIR/wildcard_enum_match_arm.rs:4:9
+ --> $DIR/wildcard_enum_match_arm.rs:3:9
|
LL | #![deny(clippy::wildcard_enum_match_arm)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: wildcard match will also match any future added variants
- --> $DIR/wildcard_enum_match_arm.rs:46:9
+ --> $DIR/wildcard_enum_match_arm.rs:44:9
|
LL | _not_red => eprintln!("Not red"),
| ^^^^^^^^ help: try this: `_not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan`
error: wildcard match will also match any future added variants
- --> $DIR/wildcard_enum_match_arm.rs:50:9
+ --> $DIR/wildcard_enum_match_arm.rs:48:9
|
LL | not_red => format!("{:?}", not_red),
| ^^^^^^^ help: try this: `not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan`
error: wildcard match will also match any future added variants
- --> $DIR/wildcard_enum_match_arm.rs:66:9
+ --> $DIR/wildcard_enum_match_arm.rs:64:9
|
LL | _ => "No red",
| ^ help: try this: `Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan`
error: wildcard matches known variants and will also match future added variants
- --> $DIR/wildcard_enum_match_arm.rs:83:9
+ --> $DIR/wildcard_enum_match_arm.rs:81:9
|
LL | _ => {},
| ^ help: try this: `ErrorKind::PermissionDenied | _`
error: wildcard matches known variants and will also match future added variants
- --> $DIR/wildcard_enum_match_arm.rs:101:13
+ --> $DIR/wildcard_enum_match_arm.rs:99:13
|
LL | _ => (),
| ^ help: try this: `Enum::B | _`
diff --git a/src/tools/clippy/tests/ui/write_literal.rs b/src/tools/clippy/tests/ui/write_literal.rs
index 446691744..218385ea1 100644
--- a/src/tools/clippy/tests/ui/write_literal.rs
+++ b/src/tools/clippy/tests/ui/write_literal.rs
@@ -1,5 +1,5 @@
-#![allow(unused_must_use)]
#![warn(clippy::write_literal)]
+#![allow(clippy::uninlined_format_args, unused_must_use)]
use std::io::Write;
@@ -25,11 +25,13 @@ fn main() {
writeln!(v, "{} of {:b} people know binary, the other half doesn't", 1, 2);
writeln!(v, "10 / 4 is {}", 2.5);
writeln!(v, "2 + 1 = {}", 3);
+ writeln!(v, "From expansion {}", stringify!(not a string literal));
// these should throw warnings
write!(v, "Hello {}", "world");
writeln!(v, "Hello {} {}", world, "world");
writeln!(v, "Hello {}", "world");
+ writeln!(v, "{} {:.4}", "a literal", 5);
// positional args don't change the fact
// that we're using a literal -- this should
diff --git a/src/tools/clippy/tests/ui/write_literal.stderr b/src/tools/clippy/tests/ui/write_literal.stderr
index 3c5ec91d3..1e306ae28 100644
--- a/src/tools/clippy/tests/ui/write_literal.stderr
+++ b/src/tools/clippy/tests/ui/write_literal.stderr
@@ -1,5 +1,5 @@
error: literal with an empty format string
- --> $DIR/write_literal.rs:30:27
+ --> $DIR/write_literal.rs:31:27
|
LL | write!(v, "Hello {}", "world");
| ^^^^^^^
@@ -12,7 +12,7 @@ LL + write!(v, "Hello world");
|
error: literal with an empty format string
- --> $DIR/write_literal.rs:31:39
+ --> $DIR/write_literal.rs:32:39
|
LL | writeln!(v, "Hello {} {}", world, "world");
| ^^^^^^^
@@ -24,7 +24,7 @@ LL + writeln!(v, "Hello {} world", world);
|
error: literal with an empty format string
- --> $DIR/write_literal.rs:32:29
+ --> $DIR/write_literal.rs:33:29
|
LL | writeln!(v, "Hello {}", "world");
| ^^^^^^^
@@ -36,7 +36,19 @@ LL + writeln!(v, "Hello world");
|
error: literal with an empty format string
- --> $DIR/write_literal.rs:37:28
+ --> $DIR/write_literal.rs:34:29
+ |
+LL | writeln!(v, "{} {:.4}", "a literal", 5);
+ | ^^^^^^^^^^^
+ |
+help: try this
+ |
+LL - writeln!(v, "{} {:.4}", "a literal", 5);
+LL + writeln!(v, "a literal {:.4}", 5);
+ |
+
+error: literal with an empty format string
+ --> $DIR/write_literal.rs:39:28
|
LL | writeln!(v, "{0} {1}", "hello", "world");
| ^^^^^^^
@@ -48,7 +60,7 @@ LL + writeln!(v, "hello {1}", "world");
|
error: literal with an empty format string
- --> $DIR/write_literal.rs:37:37
+ --> $DIR/write_literal.rs:39:37
|
LL | writeln!(v, "{0} {1}", "hello", "world");
| ^^^^^^^
@@ -60,34 +72,34 @@ LL + writeln!(v, "{0} world", "hello");
|
error: literal with an empty format string
- --> $DIR/write_literal.rs:38:28
+ --> $DIR/write_literal.rs:40:37
|
LL | writeln!(v, "{1} {0}", "hello", "world");
- | ^^^^^^^
+ | ^^^^^^^
|
help: try this
|
LL - writeln!(v, "{1} {0}", "hello", "world");
-LL + writeln!(v, "{1} hello", "world");
+LL + writeln!(v, "world {0}", "hello");
|
error: literal with an empty format string
- --> $DIR/write_literal.rs:38:37
+ --> $DIR/write_literal.rs:40:28
|
LL | writeln!(v, "{1} {0}", "hello", "world");
- | ^^^^^^^
+ | ^^^^^^^
|
help: try this
|
LL - writeln!(v, "{1} {0}", "hello", "world");
-LL + writeln!(v, "world {0}", "hello");
+LL + writeln!(v, "{1} hello", "world");
|
error: literal with an empty format string
- --> $DIR/write_literal.rs:41:32
+ --> $DIR/write_literal.rs:43:38
|
LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world");
- | ^^^^^^^^^^^^^
+ | ^^^^^^^
|
help: try this
|
@@ -96,10 +108,10 @@ LL + writeln!(v, "hello {bar}", bar = "world");
|
error: literal with an empty format string
- --> $DIR/write_literal.rs:41:47
+ --> $DIR/write_literal.rs:43:53
|
LL | writeln!(v, "{foo} {bar}", foo = "hello", bar = "world");
- | ^^^^^^^^^^^^^
+ | ^^^^^^^
|
help: try this
|
@@ -108,28 +120,28 @@ LL + writeln!(v, "{foo} world", foo = "hello");
|
error: literal with an empty format string
- --> $DIR/write_literal.rs:42:32
+ --> $DIR/write_literal.rs:44:53
|
LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world");
- | ^^^^^^^^^^^^^
+ | ^^^^^^^
|
help: try this
|
LL - writeln!(v, "{bar} {foo}", foo = "hello", bar = "world");
-LL + writeln!(v, "{bar} hello", bar = "world");
+LL + writeln!(v, "world {foo}", foo = "hello");
|
error: literal with an empty format string
- --> $DIR/write_literal.rs:42:47
+ --> $DIR/write_literal.rs:44:38
|
LL | writeln!(v, "{bar} {foo}", foo = "hello", bar = "world");
- | ^^^^^^^^^^^^^
+ | ^^^^^^^
|
help: try this
|
LL - writeln!(v, "{bar} {foo}", foo = "hello", bar = "world");
-LL + writeln!(v, "world {foo}", foo = "hello");
+LL + writeln!(v, "{bar} hello", bar = "world");
|
-error: aborting due to 11 previous errors
+error: aborting due to 12 previous errors
diff --git a/src/tools/clippy/tests/ui/write_literal_2.rs b/src/tools/clippy/tests/ui/write_literal_2.rs
index ba0d7be5e..55a11daa1 100644
--- a/src/tools/clippy/tests/ui/write_literal_2.rs
+++ b/src/tools/clippy/tests/ui/write_literal_2.rs
@@ -10,7 +10,7 @@ fn main() {
writeln!(v, r"{}", r"{hello}");
writeln!(v, "{}", '\'');
writeln!(v, "{}", '"');
- writeln!(v, r"{}", '"'); // don't lint
+ writeln!(v, r"{}", '"');
writeln!(v, r"{}", '\'');
writeln!(
v,
@@ -24,4 +24,11 @@ fn main() {
{} \\ {}",
"1", "2", "3",
);
+ writeln!(v, "{}", "\\");
+ writeln!(v, r"{}", "\\");
+ writeln!(v, r#"{}"#, "\\");
+ writeln!(v, "{}", r"\");
+ writeln!(v, "{}", "\r");
+ writeln!(v, r#"{}{}"#, '#', '"'); // hard mode
+ writeln!(v, r"{}", "\r"); // should not lint
}
diff --git a/src/tools/clippy/tests/ui/write_literal_2.stderr b/src/tools/clippy/tests/ui/write_literal_2.stderr
index 9ff297069..d5956db9f 100644
--- a/src/tools/clippy/tests/ui/write_literal_2.stderr
+++ b/src/tools/clippy/tests/ui/write_literal_2.stderr
@@ -48,6 +48,12 @@ LL + writeln!(v, "/"");
|
error: literal with an empty format string
+ --> $DIR/write_literal_2.rs:13:24
+ |
+LL | writeln!(v, r"{}", '"');
+ | ^^^
+
+error: literal with an empty format string
--> $DIR/write_literal_2.rs:14:24
|
LL | writeln!(v, r"{}", '/'');
@@ -108,5 +114,77 @@ LL ~ {} / 3",
LL ~ "1", "2",
|
-error: aborting due to 9 previous errors
+error: literal with an empty format string
+ --> $DIR/write_literal_2.rs:27:23
+ |
+LL | writeln!(v, "{}", "/");
+ | ^^^^
+ |
+help: try this
+ |
+LL - writeln!(v, "{}", "/");
+LL + writeln!(v, "/");
+ |
+
+error: literal with an empty format string
+ --> $DIR/write_literal_2.rs:28:24
+ |
+LL | writeln!(v, r"{}", "/");
+ | ^^^^
+ |
+help: try this
+ |
+LL - writeln!(v, r"{}", "/");
+LL + writeln!(v, r"/");
+ |
+
+error: literal with an empty format string
+ --> $DIR/write_literal_2.rs:29:26
+ |
+LL | writeln!(v, r#"{}"#, "/");
+ | ^^^^
+ |
+help: try this
+ |
+LL - writeln!(v, r#"{}"#, "/");
+LL + writeln!(v, r#"/"#);
+ |
+
+error: literal with an empty format string
+ --> $DIR/write_literal_2.rs:30:23
+ |
+LL | writeln!(v, "{}", r"/");
+ | ^^^^
+ |
+help: try this
+ |
+LL - writeln!(v, "{}", r"/");
+LL + writeln!(v, "/");
+ |
+
+error: literal with an empty format string
+ --> $DIR/write_literal_2.rs:31:23
+ |
+LL | writeln!(v, "{}", "/r");
+ | ^^^^
+ |
+help: try this
+ |
+LL - writeln!(v, "{}", "/r");
+LL + writeln!(v, "/r");
+ |
+
+error: literal with an empty format string
+ --> $DIR/write_literal_2.rs:32:28
+ |
+LL | writeln!(v, r#"{}{}"#, '#', '"'); // hard mode
+ | ^^^
+
+error: literal with an empty format string
+ --> $DIR/write_literal_2.rs:32:33
+ |
+LL | writeln!(v, r#"{}{}"#, '#', '"'); // hard mode
+ | ^^^
+
+error: aborting due to 17 previous errors
diff --git a/src/tools/clippy/tests/ui/write_with_newline.rs b/src/tools/clippy/tests/ui/write_with_newline.rs
index 446d6914d..b79364c87 100644
--- a/src/tools/clippy/tests/ui/write_with_newline.rs
+++ b/src/tools/clippy/tests/ui/write_with_newline.rs
@@ -56,4 +56,12 @@ fn main() {
write!(v, "foo\r\n");
write!(v, "\\r\n"); //~ ERROR
write!(v, "foo\rbar\n");
+
+ // Ignore expanded format strings
+ macro_rules! newline {
+ () => {
+ "\n"
+ };
+ }
+ write!(v, newline!());
}
diff --git a/src/tools/clippy/tests/ui/write_with_newline.stderr b/src/tools/clippy/tests/ui/write_with_newline.stderr
index 5f55431be..2baaea166 100644
--- a/src/tools/clippy/tests/ui/write_with_newline.stderr
+++ b/src/tools/clippy/tests/ui/write_with_newline.stderr
@@ -5,7 +5,7 @@ LL | write!(v, "Hello/n");
| ^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::write-with-newline` implied by `-D warnings`
-help: use `writeln!()` instead
+help: use `writeln!` instead
|
LL - write!(v, "Hello/n");
LL + writeln!(v, "Hello");
@@ -17,7 +17,7 @@ error: using `write!()` with a format string that ends in a single newline
LL | write!(v, "Hello {}/n", "world");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: use `writeln!()` instead
+help: use `writeln!` instead
|
LL - write!(v, "Hello {}/n", "world");
LL + writeln!(v, "Hello {}", "world");
@@ -29,7 +29,7 @@ error: using `write!()` with a format string that ends in a single newline
LL | write!(v, "Hello {} {}/n", "world", "#2");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
-help: use `writeln!()` instead
+help: use `writeln!` instead
|
LL - write!(v, "Hello {} {}/n", "world", "#2");
LL + writeln!(v, "Hello {} {}", "world", "#2");
@@ -41,7 +41,7 @@ error: using `write!()` with a format string that ends in a single newline
LL | write!(v, "{}/n", 1265);
| ^^^^^^^^^^^^^^^^^^^^^^^
|
-help: use `writeln!()` instead
+help: use `writeln!` instead
|
LL - write!(v, "{}/n", 1265);
LL + writeln!(v, "{}", 1265);
@@ -53,7 +53,7 @@ error: using `write!()` with a format string that ends in a single newline
LL | write!(v, "/n");
| ^^^^^^^^^^^^^^^
|
-help: use `writeln!()` instead
+help: use `writeln!` instead
|
LL - write!(v, "/n");
LL + writeln!(v);
@@ -65,7 +65,7 @@ error: using `write!()` with a format string that ends in a single newline
LL | write!(v, "//n"); // should fail
| ^^^^^^^^^^^^^^^^^
|
-help: use `writeln!()` instead
+help: use `writeln!` instead
|
LL - write!(v, "//n"); // should fail
LL + writeln!(v, "/"); // should fail
@@ -81,11 +81,10 @@ LL | | "
LL | | );
| |_____^
|
-help: use `writeln!()` instead
+help: use `writeln!` instead
|
LL ~ writeln!(
-LL | v,
-LL ~ ""
+LL ~ v
|
error: using `write!()` with a format string that ends in a single newline
@@ -98,11 +97,10 @@ LL | | "
LL | | );
| |_____^
|
-help: use `writeln!()` instead
+help: use `writeln!` instead
|
LL ~ writeln!(
-LL | v,
-LL ~ r""
+LL ~ v
|
error: using `write!()` with a format string that ends in a single newline
@@ -111,23 +109,11 @@ error: using `write!()` with a format string that ends in a single newline
LL | write!(v, "/r/n"); //~ ERROR
| ^^^^^^^^^^^^^^^^^^
|
-help: use `writeln!()` instead
+help: use `writeln!` instead
|
LL - write!(v, "/r/n"); //~ ERROR
LL + writeln!(v, "/r"); //~ ERROR
|
-error: using `write!()` with a format string that ends in a single newline
- --> $DIR/write_with_newline.rs:58:5
- |
-LL | write!(v, "foo/rbar/n");
- | ^^^^^^^^^^^^^^^^^^^^^^^
- |
-help: use `writeln!()` instead
- |
-LL - write!(v, "foo/rbar/n");
-LL + writeln!(v, "foo/rbar");
- |
-
-error: aborting due to 10 previous errors
+error: aborting due to 9 previous errors
diff --git a/src/tools/clippy/tests/ui/writeln_empty_string.stderr b/src/tools/clippy/tests/ui/writeln_empty_string.stderr
index ac65aadfc..25e69ec48 100644
--- a/src/tools/clippy/tests/ui/writeln_empty_string.stderr
+++ b/src/tools/clippy/tests/ui/writeln_empty_string.stderr
@@ -1,16 +1,20 @@
-error: using `writeln!(v, "")`
+error: empty string literal in `writeln!`
--> $DIR/writeln_empty_string.rs:11:5
|
LL | writeln!(v, "");
- | ^^^^^^^^^^^^^^^ help: replace it with: `writeln!(v)`
+ | ^^^^^^^^^^----^
+ | |
+ | help: remove the empty string
|
= note: `-D clippy::writeln-empty-string` implied by `-D warnings`
-error: using `writeln!(suggestion, "")`
+error: empty string literal in `writeln!`
--> $DIR/writeln_empty_string.rs:14:5
|
LL | writeln!(suggestion, "");
- | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `writeln!(suggestion)`
+ | ^^^^^^^^^^^^^^^^^^^----^
+ | |
+ | help: remove the empty string
error: aborting due to 2 previous errors
diff --git a/src/tools/clippy/tests/ui/wrong_self_convention.stderr b/src/tools/clippy/tests/ui/wrong_self_convention.stderr
index 2e7ee51d7..d002e55c5 100644
--- a/src/tools/clippy/tests/ui/wrong_self_convention.stderr
+++ b/src/tools/clippy/tests/ui/wrong_self_convention.stderr
@@ -4,8 +4,8 @@ error: methods called `from_*` usually take no `self`
LL | fn from_i32(self) {}
| ^^^^
|
- = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
= help: consider choosing a less ambiguous name
+ = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
error: methods called `from_*` usually take no `self`
--> $DIR/wrong_self_convention.rs:22:21
diff --git a/src/tools/clippy/tests/ui/wrong_self_convention2.stderr b/src/tools/clippy/tests/ui/wrong_self_convention2.stderr
index 5bdc47f91..8de10e7be 100644
--- a/src/tools/clippy/tests/ui/wrong_self_convention2.stderr
+++ b/src/tools/clippy/tests/ui/wrong_self_convention2.stderr
@@ -4,8 +4,8 @@ error: methods called `from_*` usually take no `self`
LL | pub fn from_be_self(self) -> Self {
| ^^^^
|
- = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
= help: consider choosing a less ambiguous name
+ = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
error: methods called `from_*` usually take no `self`
--> $DIR/wrong_self_convention2.rs:63:25
diff --git a/src/tools/clippy/tests/ui/wrong_self_conventions_mut.stderr b/src/tools/clippy/tests/ui/wrong_self_conventions_mut.stderr
index 8665d8dc9..3d009083c 100644
--- a/src/tools/clippy/tests/ui/wrong_self_conventions_mut.stderr
+++ b/src/tools/clippy/tests/ui/wrong_self_conventions_mut.stderr
@@ -4,8 +4,8 @@ error: methods with the following characteristics: (`to_*` and `self` type is no
LL | pub fn to_many(&mut self) -> Option<&mut [T]> {
| ^^^^^^^^^
|
- = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
= help: consider choosing a less ambiguous name
+ = note: `-D clippy::wrong-self-convention` implied by `-D warnings`
error: methods with the following characteristics: (`to_*` and `*_mut`) usually take `self` by mutable reference
--> $DIR/wrong_self_conventions_mut.rs:22:28
diff --git a/src/tools/clippy/tests/ui/zero_div_zero.stderr b/src/tools/clippy/tests/ui/zero_div_zero.stderr
index 86563542e..2793d1606 100644
--- a/src/tools/clippy/tests/ui/zero_div_zero.stderr
+++ b/src/tools/clippy/tests/ui/zero_div_zero.stderr
@@ -4,8 +4,8 @@ error: constant division of `0.0` with `0.0` will always result in NaN
LL | let nan = 0.0 / 0.0;
| ^^^^^^^^^
|
- = note: `-D clippy::zero-divided-by-zero` implied by `-D warnings`
= help: consider using `f64::NAN` if you would like a constant representing NaN
+ = note: `-D clippy::zero-divided-by-zero` implied by `-D warnings`
error: constant division of `0.0` with `0.0` will always result in NaN
--> $DIR/zero_div_zero.rs:5:19
diff --git a/src/tools/clippy/tests/ui/zero_sized_btreemap_values.stderr b/src/tools/clippy/tests/ui/zero_sized_btreemap_values.stderr
index d924f3379..c6ba6fa76 100644
--- a/src/tools/clippy/tests/ui/zero_sized_btreemap_values.stderr
+++ b/src/tools/clippy/tests/ui/zero_sized_btreemap_values.stderr
@@ -4,8 +4,8 @@ error: map with zero-sized value type
LL | const CONST_NOT_OK: Option<BTreeMap<String, ()>> = None;
| ^^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::zero-sized-map-values` implied by `-D warnings`
= help: consider using a set instead
+ = note: `-D clippy::zero-sized-map-values` implied by `-D warnings`
error: map with zero-sized value type
--> $DIR/zero_sized_btreemap_values.rs:8:30
diff --git a/src/tools/clippy/tests/ui/zero_sized_hashmap_values.stderr b/src/tools/clippy/tests/ui/zero_sized_hashmap_values.stderr
index 79770bf90..75bdeb42e 100644
--- a/src/tools/clippy/tests/ui/zero_sized_hashmap_values.stderr
+++ b/src/tools/clippy/tests/ui/zero_sized_hashmap_values.stderr
@@ -4,8 +4,8 @@ error: map with zero-sized value type
LL | const CONST_NOT_OK: Option<HashMap<String, ()>> = None;
| ^^^^^^^^^^^^^^^^^^^
|
- = note: `-D clippy::zero-sized-map-values` implied by `-D warnings`
= help: consider using a set instead
+ = note: `-D clippy::zero-sized-map-values` implied by `-D warnings`
error: map with zero-sized value type
--> $DIR/zero_sized_hashmap_values.rs:8:30
diff --git a/src/tools/clippy/tests/versioncheck.rs b/src/tools/clippy/tests/versioncheck.rs
index 38498ebdc..a6d8d0307 100644
--- a/src/tools/clippy/tests/versioncheck.rs
+++ b/src/tools/clippy/tests/versioncheck.rs
@@ -8,12 +8,12 @@ use std::fs;
#[test]
fn check_that_clippy_lints_and_clippy_utils_have_the_same_version_as_clippy() {
fn read_version(path: &str) -> String {
- let contents = fs::read_to_string(path).unwrap_or_else(|e| panic!("error reading `{}`: {:?}", path, e));
+ let contents = fs::read_to_string(path).unwrap_or_else(|e| panic!("error reading `{path}`: {e:?}"));
contents
.lines()
.filter_map(|l| l.split_once('='))
.find_map(|(k, v)| (k.trim() == "version").then(|| v.trim()))
- .unwrap_or_else(|| panic!("error finding version in `{}`", path))
+ .unwrap_or_else(|| panic!("error finding version in `{path}`"))
.to_string()
}
@@ -48,7 +48,7 @@ fn check_that_clippy_has_the_same_major_version_as_rustc() {
// `RUSTC_REAL` if Clippy is build in the Rust repo with `./x.py`.
let rustc = std::env::var("RUSTC_REAL").unwrap_or_else(|_| "rustc".to_string());
let rustc_version = String::from_utf8(
- std::process::Command::new(&rustc)
+ std::process::Command::new(rustc)
.arg("--version")
.output()
.expect("failed to run `rustc --version`")
@@ -83,7 +83,7 @@ fn check_that_clippy_has_the_same_major_version_as_rustc() {
// we don't want our tests failing suddenly
},
_ => {
- panic!("Failed to parse rustc version: {:?}", vsplit);
+ panic!("Failed to parse rustc version: {vsplit:?}");
},
};
}
diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs
index 64df76e27..0260f6848 100644
--- a/src/tools/compiletest/src/common.rs
+++ b/src/tools/compiletest/src/common.rs
@@ -269,19 +269,15 @@ pub struct Config {
pub runtool: Option<String>,
/// Flags to pass to the compiler when building for the host
- pub host_rustcflags: Option<String>,
+ pub host_rustcflags: Vec<String>,
/// Flags to pass to the compiler when building for the target
- pub target_rustcflags: Option<String>,
+ pub target_rustcflags: Vec<String>,
/// Whether tests should be optimized by default. Individual test-suites and test files may
/// override this setting.
pub optimize_tests: bool,
- /// What panic strategy the target is built with. Unwind supports Abort, but
- /// not vice versa.
- pub target_panic: PanicStrategy,
-
/// Target system to be tested
pub target: String,
@@ -389,7 +385,8 @@ impl Config {
}
fn target_cfg(&self) -> &TargetCfg {
- self.target_cfg.borrow_with(|| TargetCfg::new(&self.rustc_path, &self.target))
+ self.target_cfg
+ .borrow_with(|| TargetCfg::new(&self.rustc_path, &self.target, &self.target_rustcflags))
}
pub fn matches_arch(&self, arch: &str) -> bool {
@@ -426,6 +423,10 @@ impl Config {
*&self.target_cfg().pointer_width
}
+ pub fn can_unwind(&self) -> bool {
+ self.target_cfg().panic == PanicStrategy::Unwind
+ }
+
pub fn has_asm_support(&self) -> bool {
static ASM_SUPPORTED_ARCHS: &[&str] = &[
"x86", "x86_64", "arm", "aarch64", "riscv32",
@@ -446,6 +447,7 @@ pub struct TargetCfg {
families: Vec<String>,
pointer_width: u32,
endian: Endian,
+ panic: PanicStrategy,
}
#[derive(Eq, PartialEq, Clone, Debug)]
@@ -455,11 +457,12 @@ pub enum Endian {
}
impl TargetCfg {
- fn new(rustc_path: &Path, target: &str) -> TargetCfg {
+ fn new(rustc_path: &Path, target: &str, target_rustcflags: &Vec<String>) -> TargetCfg {
let output = match Command::new(rustc_path)
.arg("--print=cfg")
.arg("--target")
.arg(target)
+ .args(target_rustcflags)
.output()
{
Ok(output) => output,
@@ -481,6 +484,7 @@ impl TargetCfg {
let mut families = Vec::new();
let mut pointer_width = None;
let mut endian = None;
+ let mut panic = None;
for line in print_cfg.lines() {
if let Some((name, value)) = line.split_once('=') {
let value = value.trim_matches('"');
@@ -498,6 +502,13 @@ impl TargetCfg {
s => panic!("unexpected {s}"),
})
}
+ "panic" => {
+ panic = match value {
+ "abort" => Some(PanicStrategy::Abort),
+ "unwind" => Some(PanicStrategy::Unwind),
+ s => panic!("unexpected {s}"),
+ }
+ }
_ => {}
}
}
@@ -510,6 +521,7 @@ impl TargetCfg {
families,
pointer_width: pointer_width.unwrap(),
endian: endian.unwrap(),
+ panic: panic.unwrap(),
}
}
}
diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs
index 3ff1cbf20..0d9a629e1 100644
--- a/src/tools/compiletest/src/header.rs
+++ b/src/tools/compiletest/src/header.rs
@@ -4,10 +4,11 @@ use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;
use std::path::{Path, PathBuf};
+use std::process::Command;
use tracing::*;
-use crate::common::{CompareMode, Config, Debugger, FailMode, Mode, PanicStrategy, PassMode};
+use crate::common::{CompareMode, Config, Debugger, FailMode, Mode, PassMode};
use crate::util;
use crate::{extract_cdb_version, extract_gdb_version};
@@ -843,6 +844,20 @@ pub fn extract_llvm_version(version: &str) -> Option<u32> {
Some(version)
}
+pub fn extract_llvm_version_from_binary(binary_path: &str) -> Option<u32> {
+ let output = Command::new(binary_path).arg("--version").output().ok()?;
+ if !output.status.success() {
+ return None;
+ }
+ let version = String::from_utf8(output.stdout).ok()?;
+ for line in version.lines() {
+ if let Some(version) = line.split("LLVM version ").skip(1).next() {
+ return extract_llvm_version(version);
+ }
+ }
+ None
+}
+
/// Takes a directive of the form "<version1> [- <version2>]",
/// returns the numeric representation of <version1> and <version2> as
/// tuple: (<version1> as u32, <version2> as u32)
@@ -949,8 +964,7 @@ pub fn make_test_description<R: Read>(
ignore |= !has_memtag && config.parse_name_directive(ln, "needs-sanitizer-memtag");
ignore |= !has_shadow_call_stack
&& config.parse_name_directive(ln, "needs-sanitizer-shadow-call-stack");
- ignore |= config.target_panic == PanicStrategy::Abort
- && config.parse_name_directive(ln, "needs-unwind");
+ ignore |= !config.can_unwind() && config.parse_name_directive(ln, "needs-unwind");
ignore |= config.target == "wasm32-unknown-unknown"
&& config.parse_name_directive(ln, directives::CHECK_RUN_RESULTS);
ignore |= config.debugger == Some(Debugger::Cdb) && ignore_cdb(config, ln);
diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs
index 38c7b87fc..19cf54780 100644
--- a/src/tools/compiletest/src/main.rs
+++ b/src/tools/compiletest/src/main.rs
@@ -5,9 +5,7 @@
extern crate test;
-use crate::common::{
- expected_output_path, output_base_dir, output_relative_path, PanicStrategy, UI_EXTENSIONS,
-};
+use crate::common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS};
use crate::common::{CompareMode, Config, Debugger, Mode, PassMode, TestPaths};
use crate::util::logv;
use getopts::Options;
@@ -105,7 +103,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
.optmulti("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS")
.optmulti("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS")
.optflag("", "optimize-tests", "run tests with optimizations enabled")
- .optopt("", "target-panic", "what panic strategy the target supports", "unwind | abort")
.optflag("", "verbose", "run tests verbosely, showing all output")
.optflag(
"",
@@ -203,7 +200,9 @@ pub fn parse_config(args: Vec<String>) -> Config {
Some(x) => panic!("argument for --color must be auto, always, or never, but found `{}`", x),
};
let llvm_version =
- matches.opt_str("llvm-version").as_deref().and_then(header::extract_llvm_version);
+ matches.opt_str("llvm-version").as_deref().and_then(header::extract_llvm_version).or_else(
+ || header::extract_llvm_version_from_binary(&matches.opt_str("llvm-filecheck")?),
+ );
let src_base = opt_path(matches, "src-base");
let run_ignored = matches.opt_present("ignored");
@@ -255,14 +254,9 @@ pub fn parse_config(args: Vec<String>) -> Config {
}),
logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)),
runtool: matches.opt_str("runtool"),
- host_rustcflags: Some(matches.opt_strs("host-rustcflags").join(" ")),
- target_rustcflags: Some(matches.opt_strs("target-rustcflags").join(" ")),
+ host_rustcflags: matches.opt_strs("host-rustcflags"),
+ target_rustcflags: matches.opt_strs("target-rustcflags"),
optimize_tests: matches.opt_present("optimize-tests"),
- target_panic: match matches.opt_str("target-panic").as_deref() {
- Some("unwind") | None => PanicStrategy::Unwind,
- Some("abort") => PanicStrategy::Abort,
- _ => panic!("unknown `--target-panic` option `{}` given", mode),
- },
target,
host: opt_str2(matches.opt_str("host")),
cdb,
@@ -328,8 +322,8 @@ pub fn log_config(config: &Config) {
format!("force_pass_mode: {}", opt_str(&config.force_pass_mode.map(|m| format!("{}", m))),),
);
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
- logv(c, format!("host-rustcflags: {}", opt_str(&config.host_rustcflags)));
- logv(c, format!("target-rustcflags: {}", opt_str(&config.target_rustcflags)));
+ logv(c, format!("host-rustcflags: {:?}", config.host_rustcflags));
+ logv(c, format!("target-rustcflags: {:?}", config.target_rustcflags));
logv(c, format!("target: {}", config.target));
logv(c, format!("host: {}", config.host));
logv(c, format!("android-cross-path: {:?}", config.android_cross_path.display()));
@@ -403,6 +397,8 @@ pub fn run_tests(config: Config) {
make_tests(c, &mut tests);
}
+ tests.sort_by(|a, b| a.desc.name.as_slice().cmp(&b.desc.name.as_slice()));
+
let res = test::run_tests_console(&opts, tests);
match res {
Ok(true) => {}
@@ -805,7 +801,10 @@ fn make_test_closure(
let config = config.clone();
let testpaths = testpaths.clone();
let revision = revision.cloned();
- test::DynTestFn(Box::new(move || runtest::run(config, &testpaths, revision.as_deref())))
+ test::DynTestFn(Box::new(move || {
+ runtest::run(config, &testpaths, revision.as_deref());
+ Ok(())
+ }))
}
/// Returns `true` if the given target is an Android target for the
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index 8f289876f..8af5f1da6 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -558,10 +558,7 @@ impl<'test> TestCx<'test> {
.arg(&aux_dir)
.args(&self.props.compile_flags)
.envs(self.props.rustc_env.clone());
- self.maybe_add_external_args(
- &mut rustc,
- self.split_maybe_args(&self.config.target_rustcflags),
- );
+ self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
let src = match read_from {
ReadFrom::Stdin(src) => Some(src),
@@ -629,10 +626,7 @@ impl<'test> TestCx<'test> {
.arg("-L")
.arg(aux_dir);
self.set_revision_flags(&mut rustc);
- self.maybe_add_external_args(
- &mut rustc,
- self.split_maybe_args(&self.config.target_rustcflags),
- );
+ self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
rustc.args(&self.props.compile_flags);
self.compose_and_run_compiler(rustc, Some(src))
@@ -1186,23 +1180,14 @@ impl<'test> TestCx<'test> {
ProcRes { status, stdout: out, stderr: err, cmdline: format!("{:?}", cmd) }
}
- fn cleanup_debug_info_options(&self, options: &Option<String>) -> Option<String> {
- if options.is_none() {
- return None;
- }
-
+ fn cleanup_debug_info_options(&self, options: &Vec<String>) -> Vec<String> {
// Remove options that are either unwanted (-O) or may lead to duplicates due to RUSTFLAGS.
let options_to_remove = ["-O".to_owned(), "-g".to_owned(), "--debuginfo".to_owned()];
- let new_options = self
- .split_maybe_args(options)
- .into_iter()
- .filter(|x| !options_to_remove.contains(x))
- .collect::<Vec<String>>();
- Some(new_options.join(" "))
+ options.iter().filter(|x| !options_to_remove.contains(x)).map(|x| x.clone()).collect()
}
- fn maybe_add_external_args(&self, cmd: &mut Command, args: Vec<String>) {
+ fn maybe_add_external_args(&self, cmd: &mut Command, args: &Vec<String>) {
// Filter out the arguments that should not be added by runtest here.
//
// Notable use-cases are: do not add our optimisation flag if
@@ -2035,15 +2020,9 @@ impl<'test> TestCx<'test> {
}
if self.props.force_host {
- self.maybe_add_external_args(
- &mut rustc,
- self.split_maybe_args(&self.config.host_rustcflags),
- );
+ self.maybe_add_external_args(&mut rustc, &self.config.host_rustcflags);
} else {
- self.maybe_add_external_args(
- &mut rustc,
- self.split_maybe_args(&self.config.target_rustcflags),
- );
+ self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
if !is_rustdoc {
if let Some(ref linker) = self.config.linker {
rustc.arg(format!("-Clinker={}", linker));
diff --git a/src/tools/compiletest/src/util.rs b/src/tools/compiletest/src/util.rs
index 9d047b63c..e5ff0906b 100644
--- a/src/tools/compiletest/src/util.rs
+++ b/src/tools/compiletest/src/util.rs
@@ -11,9 +11,15 @@ mod tests;
pub const ASAN_SUPPORTED_TARGETS: &[&str] = &[
"aarch64-apple-darwin",
"aarch64-fuchsia",
+ "aarch64-linux-android",
"aarch64-unknown-linux-gnu",
+ "arm-linux-androideabi",
+ "armv7-linux-androideabi",
+ "i686-linux-android",
+ "i686-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-fuchsia",
+ "x86_64-linux-android",
"x86_64-unknown-freebsd",
"x86_64-unknown-linux-gnu",
];
diff --git a/src/tools/error_index_generator/error-index.css b/src/tools/error_index_generator/error-index.css
index 8975af82d..dcac2e18e 100644
--- a/src/tools/error_index_generator/error-index.css
+++ b/src/tools/error_index_generator/error-index.css
@@ -27,10 +27,11 @@ pre .tooltip::before {
content: " ";
position: absolute;
top: 50%;
- left: 16px;
+ left: 2px;
margin-top: -5px;
border-width: 5px;
border-style: solid;
+ height: 0px;
}
pre .tooltip:hover::before, pre .tooltip:hover::after {
diff --git a/src/tools/jsondoclint/src/item_kind.rs b/src/tools/jsondoclint/src/item_kind.rs
index ad8e96a0b..6d986e575 100644
--- a/src/tools/jsondoclint/src/item_kind.rs
+++ b/src/tools/jsondoclint/src/item_kind.rs
@@ -142,8 +142,7 @@ impl Kind {
ItemEnum::Static(_) => Static,
ItemEnum::Macro(_) => Macro,
ItemEnum::ProcMacro(_) => ProcMacro,
- // https://github.com/rust-lang/rust/issues/100961
- ItemEnum::PrimitiveType(_) => Primitive,
+ ItemEnum::Primitive(_) => Primitive,
ItemEnum::ForeignType => ForeignType,
ItemEnum::ExternCrate { .. } => ExternCrate,
ItemEnum::AssocConst { .. } => AssocConst,
diff --git a/src/tools/jsondoclint/src/validator.rs b/src/tools/jsondoclint/src/validator.rs
index a0e77127d..94af4c5e9 100644
--- a/src/tools/jsondoclint/src/validator.rs
+++ b/src/tools/jsondoclint/src/validator.rs
@@ -4,8 +4,8 @@ use std::hash::Hash;
use rustdoc_json_types::{
Constant, Crate, DynTrait, Enum, FnDecl, Function, FunctionPointer, GenericArg, GenericArgs,
GenericBound, GenericParamDef, Generics, Id, Impl, Import, ItemEnum, Method, Module, OpaqueTy,
- Path, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type, TypeBinding,
- TypeBindingKind, Typedef, Union, Variant, WherePredicate,
+ Path, Primitive, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type,
+ TypeBinding, TypeBindingKind, Typedef, Union, Variant, WherePredicate,
};
use crate::{item_kind::Kind, Error, ErrorKind};
@@ -76,7 +76,7 @@ impl<'a> Validator<'a> {
ItemEnum::ForeignType => {} // nop
ItemEnum::Macro(x) => self.check_macro(x),
ItemEnum::ProcMacro(x) => self.check_proc_macro(x),
- ItemEnum::PrimitiveType(x) => self.check_primitive_type(x),
+ ItemEnum::Primitive(x) => self.check_primitive_type(x),
ItemEnum::Module(x) => self.check_module(x),
// FIXME: Why don't these have their own structs?
ItemEnum::ExternCrate { .. } => {}
@@ -219,8 +219,8 @@ impl<'a> Validator<'a> {
// nop
}
- fn check_primitive_type(&mut self, _: &'a str) {
- // nop
+ fn check_primitive_type(&mut self, x: &'a Primitive) {
+ x.impls.iter().for_each(|i| self.add_impl_id(i));
}
fn check_generics(&mut self, x: &'a Generics) {
diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs
index a7c78d80c..7842611bd 100644
--- a/src/tools/linkchecker/main.rs
+++ b/src/tools/linkchecker/main.rs
@@ -215,6 +215,7 @@ impl Checker {
|| url.starts_with("ftp:")
|| url.starts_with("irc:")
|| url.starts_with("data:")
+ || url.starts_with("mailto:")
{
report.links_ignored_external += 1;
return;
diff --git a/src/tools/publish_toolstate.py b/src/tools/publish_toolstate.py
index c0cef8f7b..9c16ef2cb 100755
--- a/src/tools/publish_toolstate.py
+++ b/src/tools/publish_toolstate.py
@@ -30,7 +30,6 @@ except ImportError:
# These should be collaborators of the rust-lang/rust repository (with at least
# read privileges on it). CI will fail otherwise.
MAINTAINERS = {
- 'miri': {'oli-obk', 'RalfJung'},
'book': {'carols10cents'},
'nomicon': {'frewsxcv', 'Gankra', 'JohnTitor'},
'reference': {'Havvy', 'matthewjasper', 'ehuss'},
@@ -41,7 +40,6 @@ MAINTAINERS = {
}
LABELS = {
- 'miri': ['A-miri', 'C-bug'],
'book': ['C-bug'],
'nomicon': ['C-bug'],
'reference': ['C-bug'],
@@ -52,7 +50,6 @@ LABELS = {
}
REPOS = {
- 'miri': 'https://github.com/rust-lang/miri',
'book': 'https://github.com/rust-lang/book',
'nomicon': 'https://github.com/rust-lang/nomicon',
'reference': 'https://github.com/rust-lang/reference',
@@ -239,16 +236,10 @@ def update_latest(
message += '{} (cc {}).\n' \
.format(title, maintainers)
# See if we need to create an issue.
- if tool == 'miri':
- # Create issue if tests used to pass before. Don't open a *second*
- # issue when we regress from "test-fail" to "build-fail".
- if old == 'test-pass':
- create_issue_for_status = new
- else:
- # Create issue if things no longer build.
- # (No issue for mere test failures to avoid spurious issues.)
- if new == 'build-fail':
- create_issue_for_status = new
+ # Create issue if things no longer build.
+ # (No issue for mere test failures to avoid spurious issues.)
+ if new == 'build-fail':
+ create_issue_for_status = new
if create_issue_for_status is not None:
try:
diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock
index 9f10d92c4..0ddea2f72 100644
--- a/src/tools/rust-analyzer/Cargo.lock
+++ b/src/tools/rust-analyzer/Cargo.lock
@@ -37,9 +37,9 @@ dependencies = [
[[package]]
name = "anyhow"
-version = "1.0.62"
+version = "1.0.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305"
+checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602"
[[package]]
name = "anymap"
@@ -49,9 +49,9 @@ checksum = "8f1f8f5a6f3d50d89e3797d7593a50f96bb2aaa20ca0cc7be1fb673232c91d72"
[[package]]
name = "arbitrary"
-version = "1.1.3"
+version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5a7924531f38b1970ff630f03eb20a2fde69db5c590c93b0f3482e95dcc5fd60"
+checksum = "d86fd10d912cab78764cc44307d9cd5f164e09abbeb87fb19fb6d95937e8da5f"
[[package]]
name = "arrayvec"
@@ -171,9 +171,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chalk-derive"
-version = "0.84.0"
+version = "0.86.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cf29c109d57f8d57b0e7675391be37a9285d86dd93278bd5f14a0ad3c447a6c2"
+checksum = "5499d415d855b5094366a824815341893ad3de0ecb6048c430118bdae6d27402"
dependencies = [
"proc-macro2",
"quote",
@@ -183,9 +183,9 @@ dependencies = [
[[package]]
name = "chalk-ir"
-version = "0.84.0"
+version = "0.86.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d391763027b5e50a5e15caf6d2857ec585fd68160367bbeac9e1804209620918"
+checksum = "3800118c76a48507b0eece3a01f3a429b5c478d203c493096e6040c67ab960e1"
dependencies = [
"bitflags",
"chalk-derive",
@@ -194,9 +194,9 @@ dependencies = [
[[package]]
name = "chalk-recursive"
-version = "0.84.0"
+version = "0.86.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "afafd92dcdc7fe0ea940ee94bdd8cc5bd18f4a4a84c593d6d7025fe16c150478"
+checksum = "1baf60628fd73104d1f8562586a52d48f37f1e84435aab2e62674b1fd935b8c8"
dependencies = [
"chalk-derive",
"chalk-ir",
@@ -207,9 +207,9 @@ dependencies = [
[[package]]
name = "chalk-solve"
-version = "0.84.0"
+version = "0.86.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3af1d111f11c91c48ace02e93e470c5bae6d2631bd112e4545317da53660d7fc"
+checksum = "0e9c3c068f9358786348e58a1b94ef0a5cf90a9810fc1f10fda896f0b5d80185"
dependencies = [
"chalk-derive",
"chalk-ir",
@@ -270,45 +270,44 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
-version = "0.9.10"
+version = "0.9.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1"
+checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348"
dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
"memoffset",
- "once_cell",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
-version = "0.8.11"
+version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc"
+checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac"
dependencies = [
"cfg-if",
- "once_cell",
]
[[package]]
name = "dashmap"
-version = "5.3.4"
+version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3495912c9c1ccf2e18976439f4443f3fee0fd61f424ff99fde6a66b15ecb448f"
+checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
dependencies = [
"cfg-if",
"hashbrown",
"lock_api",
+ "once_cell",
"parking_lot_core 0.9.3",
]
[[package]]
name = "derive_arbitrary"
-version = "1.1.3"
+version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c9a577516173adb681466d517d39bd468293bc2c2a16439375ef0f35bba45f3d"
+checksum = "226ad66541d865d7a7173ad6a9e691c33fdb910ac723f4bc734b3e5294a1f931"
dependencies = [
"proc-macro2",
"quote",
@@ -394,6 +393,7 @@ dependencies = [
"crossbeam-channel",
"jod-thread",
"paths",
+ "rustc-hash",
"serde",
"serde_json",
"stdx",
@@ -403,11 +403,10 @@ dependencies = [
[[package]]
name = "form_urlencoded"
-version = "1.0.1"
+version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191"
+checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8"
dependencies = [
- "matches",
"percent-encoding",
]
@@ -545,6 +544,7 @@ version = "0.0.0"
dependencies = [
"arrayvec",
"base-db",
+ "chalk-derive",
"chalk-ir",
"chalk-recursive",
"chalk-solve",
@@ -572,9 +572,9 @@ dependencies = [
[[package]]
name = "home"
-version = "0.5.3"
+version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654"
+checksum = "747309b4b440c06d57b0b25f2aee03ee9b5e5397d288c60e21fc709bb98a7408"
dependencies = [
"winapi",
]
@@ -660,6 +660,7 @@ dependencies = [
"indexmap",
"itertools",
"limit",
+ "memchr",
"once_cell",
"parser",
"profile",
@@ -712,11 +713,10 @@ dependencies = [
[[package]]
name = "idna"
-version = "0.2.3"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8"
+checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6"
dependencies = [
- "matches",
"unicode-bidi",
"unicode-normalization",
]
@@ -762,18 +762,18 @@ dependencies = [
[[package]]
name = "itertools"
-version = "0.10.3"
+version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
+checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
dependencies = [
"either",
]
[[package]]
name = "itoa"
-version = "1.0.3"
+version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"
+checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
[[package]]
name = "jod-thread"
@@ -813,9 +813,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
-version = "0.2.132"
+version = "0.2.135"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5"
+checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c"
[[package]]
name = "libloading"
@@ -829,9 +829,9 @@ dependencies = [
[[package]]
name = "libmimalloc-sys"
-version = "0.1.25"
+version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "11ca136052550448f55df7898c6dbe651c6b574fe38a0d9ea687a9f8088a2e2c"
+checksum = "8fc093ab289b0bfda3aa1bdfab9c9542be29c7ef385cfcbe77f8c9813588eb48"
dependencies = [
"cc",
]
@@ -842,9 +842,9 @@ version = "0.0.0"
[[package]]
name = "lock_api"
-version = "0.4.7"
+version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53"
+checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df"
dependencies = [
"autocfg",
"scopeguard",
@@ -861,7 +861,7 @@ dependencies = [
[[package]]
name = "lsp-server"
-version = "0.6.0"
+version = "0.7.0"
dependencies = [
"crossbeam-channel",
"log",
@@ -893,12 +893,6 @@ dependencies = [
]
[[package]]
-name = "matches"
-version = "0.1.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
-
-[[package]]
name = "mbe"
version = "0.0.0"
dependencies = [
@@ -939,18 +933,18 @@ dependencies = [
[[package]]
name = "mimalloc"
-version = "0.1.29"
+version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2f64ad83c969af2e732e907564deb0d0ed393cec4af80776f77dd77a1a427698"
+checksum = "76ce6a4b40d3bff9eb3ce9881ca0737a85072f9f975886082640cd46a75cdb35"
dependencies = [
"libmimalloc-sys",
]
[[package]]
name = "miniz_oxide"
-version = "0.5.3"
+version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc"
+checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34"
dependencies = [
"adler",
]
@@ -978,9 +972,9 @@ dependencies = [
[[package]]
name = "notify"
-version = "5.0.0-pre.16"
+version = "5.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "530f6314d6904508082f4ea424a0275cf62d341e118b313663f266429cb19693"
+checksum = "ed2c66da08abae1c024c01d635253e402341b4060a12e99b31c7594063bf490a"
dependencies = [
"bitflags",
"crossbeam-channel",
@@ -1015,9 +1009,9 @@ dependencies = [
[[package]]
name = "once_cell"
-version = "1.13.1"
+version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e"
+checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
[[package]]
name = "oorandom"
@@ -1086,9 +1080,9 @@ dependencies = [
[[package]]
name = "paste"
-version = "1.0.8"
+version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9423e2b32f7a043629287a536f21951e8c6a82482d0acb1eeebfc90bc2225b22"
+checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1"
[[package]]
name = "paths"
@@ -1096,9 +1090,9 @@ version = "0.0.0"
[[package]]
name = "percent-encoding"
-version = "2.1.0"
+version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
+checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
[[package]]
name = "perf-event"
@@ -1188,9 +1182,9 @@ version = "0.0.0"
[[package]]
name = "proc-macro2"
-version = "1.0.43"
+version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"
+checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
dependencies = [
"unicode-ident",
]
@@ -1263,9 +1257,9 @@ dependencies = [
[[package]]
name = "pulldown-cmark-to-cmark"
-version = "10.0.2"
+version = "10.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c1353ac408192fa925228d3e60ff746167d03f4f7e54835d78ef79e08225d913"
+checksum = "0194e6e1966c23cc5fd988714f85b18d548d773e81965413555d96569931833d"
dependencies = [
"pulldown-cmark",
]
@@ -1338,9 +1332,9 @@ checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
[[package]]
name = "rowan"
-version = "0.15.8"
+version = "0.15.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e88acf7b001007e9e8c989fe7449f6601d909e5dd2c56399fc158977ad6c56e8"
+checksum = "5811547e7ba31e903fe48c8ceab10d40d70a101f3d15523c847cce91aa71f332"
dependencies = [
"countme",
"hashbrown",
@@ -1491,27 +1485,27 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "semver"
-version = "1.0.13"
+version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "93f6841e709003d68bb2deee8c343572bf446003ec20a583e76f7b15cebf3711"
+checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4"
dependencies = [
"serde",
]
[[package]]
name = "serde"
-version = "1.0.143"
+version = "1.0.145"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "53e8e5d5b70924f74ff5c6d64d9a5acd91422117c60f48c4e07855238a254553"
+checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
-version = "1.0.143"
+version = "1.0.145"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d3d8e8de557aee63c26b85b947f5e59b690d0454c753f3adeb5cd7835ab88391"
+checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c"
dependencies = [
"proc-macro2",
"quote",
@@ -1520,9 +1514,9 @@ dependencies = [
[[package]]
name = "serde_json"
-version = "1.0.83"
+version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7"
+checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074"
dependencies = [
"indexmap",
"itoa",
@@ -1552,9 +1546,9 @@ dependencies = [
[[package]]
name = "smallvec"
-version = "1.9.0"
+version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1"
+checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]]
name = "smol_str"
@@ -1591,9 +1585,9 @@ dependencies = [
[[package]]
name = "syn"
-version = "1.0.99"
+version = "1.0.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13"
+checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1"
dependencies = [
"proc-macro2",
"quote",
@@ -1664,18 +1658,18 @@ checksum = "288cb548dbe72b652243ea797201f3d481a0609a967980fcc5b2315ea811560a"
[[package]]
name = "thiserror"
-version = "1.0.31"
+version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a"
+checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
-version = "1.0.31"
+version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
+checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
dependencies = [
"proc-macro2",
"quote",
@@ -1713,9 +1707,9 @@ dependencies = [
[[package]]
name = "tikv-jemalloc-sys"
-version = "0.5.1+5.3.0-patched"
+version = "0.5.2+5.3.0-patched"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "931e876f91fed0827f863a2d153897790da0b24d882c721a79cb3beb0b903261"
+checksum = "ec45c14da997d0925c7835883e4d5c181f196fa142f8c19d7643d1e9af2592c3"
dependencies = [
"cc",
"fs_extra",
@@ -1756,9 +1750,9 @@ dependencies = [
[[package]]
name = "tracing"
-version = "0.1.36"
+version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307"
+checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
dependencies = [
"cfg-if",
"pin-project-lite",
@@ -1768,9 +1762,9 @@ dependencies = [
[[package]]
name = "tracing-attributes"
-version = "0.1.22"
+version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2"
+checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
dependencies = [
"proc-macro2",
"quote",
@@ -1779,9 +1773,9 @@ dependencies = [
[[package]]
name = "tracing-core"
-version = "0.1.29"
+version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7"
+checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
dependencies = [
"once_cell",
"valuable",
@@ -1800,9 +1794,9 @@ dependencies = [
[[package]]
name = "tracing-subscriber"
-version = "0.3.15"
+version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "60db860322da191b40952ad9affe65ea23e7dd6a5c442c2c42865810c6ab8e6b"
+checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70"
dependencies = [
"matchers",
"once_cell",
@@ -1864,40 +1858,39 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992"
[[package]]
name = "unicode-ident"
-version = "1.0.1"
+version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
+checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
[[package]]
name = "unicode-normalization"
-version = "0.1.21"
+version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6"
+checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-segmentation"
-version = "1.9.0"
+version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
+checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a"
[[package]]
name = "unicode-xid"
-version = "0.2.3"
+version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
+checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
[[package]]
name = "url"
-version = "2.2.2"
+version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c"
+checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643"
dependencies = [
"form_urlencoded",
"idna",
- "matches",
"percent-encoding",
"serde",
]
@@ -2080,18 +2073,18 @@ checksum = "06069a848f95fceae3e5e03c0ddc8cb78452b56654ee0c8e68f938cf790fb9e3"
[[package]]
name = "xflags"
-version = "0.2.4"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3f14fe1ed41a5a2b5ef3f565586c4a8a559ee55d3953faab360a771135bdee00"
+checksum = "cbf19f5031a1a812e96fede16f8161218883079946cea87619d3613db1efd268"
dependencies = [
"xflags-macros",
]
[[package]]
name = "xflags-macros"
-version = "0.2.4"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "45d11d5fc2a97287eded8b170ca80533b3c42646dd7fa386a5eb045817921022"
+checksum = "2afbd7f2039bb6cad2dd45f0c5dff49c0d4e26118398768b7a605524d4251809"
[[package]]
name = "xshell"
diff --git a/src/tools/rust-analyzer/Cargo.toml b/src/tools/rust-analyzer/Cargo.toml
index 6b68ca823..286ef1e7d 100644
--- a/src/tools/rust-analyzer/Cargo.toml
+++ b/src/tools/rust-analyzer/Cargo.toml
@@ -27,6 +27,7 @@ debug = 0
# chalk-solve = { path = "../chalk/chalk-solve" }
# chalk-ir = { path = "../chalk/chalk-ir" }
# chalk-recursive = { path = "../chalk/chalk-recursive" }
+# chalk-derive = { path = "../chalk/chalk-derive" }
# ungrammar = { path = "../ungrammar" }
diff --git a/src/tools/rust-analyzer/crates/base-db/src/fixture.rs b/src/tools/rust-analyzer/crates/base-db/src/fixture.rs
index 8e6e6a11a..5b7828a26 100644
--- a/src/tools/rust-analyzer/crates/base-db/src/fixture.rs
+++ b/src/tools/rust-analyzer/crates/base-db/src/fixture.rs
@@ -196,7 +196,7 @@ impl ChangeFixture {
Env::default(),
Ok(Vec::new()),
false,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo { repo: None, name: None },
);
} else {
for (from, to, prelude) in crate_deps {
@@ -270,7 +270,7 @@ impl ChangeFixture {
Env::default(),
Ok(proc_macro),
true,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo { repo: None, name: None },
);
for krate in all_crates {
@@ -398,7 +398,7 @@ fn parse_crate(crate_str: String) -> (String, CrateOrigin, Option<String>) {
let (version, origin) = match b.split_once(':') {
Some(("CratesIo", data)) => match data.split_once(',') {
Some((version, url)) => {
- (version, CrateOrigin::CratesIo { repo: Some(url.to_owned()) })
+ (version, CrateOrigin::CratesIo { repo: Some(url.to_owned()), name: None })
}
_ => panic!("Bad crates.io parameter: {}", data),
},
@@ -409,7 +409,7 @@ fn parse_crate(crate_str: String) -> (String, CrateOrigin, Option<String>) {
let crate_origin = match &*crate_str {
"std" => CrateOrigin::Lang(LangCrateOrigin::Std),
"core" => CrateOrigin::Lang(LangCrateOrigin::Core),
- _ => CrateOrigin::CratesIo { repo: None },
+ _ => CrateOrigin::CratesIo { repo: None, name: None },
};
(crate_str, crate_origin, None)
}
diff --git a/src/tools/rust-analyzer/crates/base-db/src/input.rs b/src/tools/rust-analyzer/crates/base-db/src/input.rs
index b388e47de..e7f0c4ec2 100644
--- a/src/tools/rust-analyzer/crates/base-db/src/input.rs
+++ b/src/tools/rust-analyzer/crates/base-db/src/input.rs
@@ -136,7 +136,7 @@ impl ops::Deref for CrateName {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CrateOrigin {
/// Crates that are from crates.io official registry,
- CratesIo { repo: Option<String> },
+ CratesIo { repo: Option<String>, name: Option<String> },
/// Crates that are provided by the language, like std, core, proc-macro, ...
Lang(LangCrateOrigin),
}
@@ -648,7 +648,7 @@ mod tests {
Env::default(),
Ok(Vec::new()),
false,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo { repo: None, name: None },
);
let crate2 = graph.add_crate_root(
FileId(2u32),
@@ -660,7 +660,7 @@ mod tests {
Env::default(),
Ok(Vec::new()),
false,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo { repo: None, name: None },
);
let crate3 = graph.add_crate_root(
FileId(3u32),
@@ -672,7 +672,7 @@ mod tests {
Env::default(),
Ok(Vec::new()),
false,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo { repo: None, name: None },
);
assert!(graph
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
@@ -698,7 +698,7 @@ mod tests {
Env::default(),
Ok(Vec::new()),
false,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo { repo: None, name: None },
);
let crate2 = graph.add_crate_root(
FileId(2u32),
@@ -710,7 +710,7 @@ mod tests {
Env::default(),
Ok(Vec::new()),
false,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo { repo: None, name: None },
);
assert!(graph
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
@@ -733,7 +733,7 @@ mod tests {
Env::default(),
Ok(Vec::new()),
false,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo { repo: None, name: None },
);
let crate2 = graph.add_crate_root(
FileId(2u32),
@@ -745,7 +745,7 @@ mod tests {
Env::default(),
Ok(Vec::new()),
false,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo { repo: None, name: None },
);
let crate3 = graph.add_crate_root(
FileId(3u32),
@@ -757,7 +757,7 @@ mod tests {
Env::default(),
Ok(Vec::new()),
false,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo { repo: None, name: None },
);
assert!(graph
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
@@ -780,7 +780,7 @@ mod tests {
Env::default(),
Ok(Vec::new()),
false,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo { repo: None, name: None },
);
let crate2 = graph.add_crate_root(
FileId(2u32),
@@ -792,7 +792,7 @@ mod tests {
Env::default(),
Ok(Vec::new()),
false,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo { repo: None, name: None },
);
assert!(graph
.add_dep(
diff --git a/src/tools/rust-analyzer/crates/cfg/Cargo.toml b/src/tools/rust-analyzer/crates/cfg/Cargo.toml
index c9664a83a..ee1ad677a 100644
--- a/src/tools/rust-analyzer/crates/cfg/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/cfg/Cargo.toml
@@ -22,5 +22,5 @@ oorandom = "11.1.3"
# We depend on both individually instead of using `features = ["derive"]` to microoptimize the
# build graph: if the feature was enabled, syn would be built early on in the graph if `smolstr`
# supports `arbitrary`. This way, we avoid feature unification.
-arbitrary = "1.1.0"
-derive_arbitrary = "1.1.0"
+arbitrary = "1.1.7"
+derive_arbitrary = "1.1.6"
diff --git a/src/tools/rust-analyzer/crates/flycheck/Cargo.toml b/src/tools/rust-analyzer/crates/flycheck/Cargo.toml
index d3d180ece..2ad32d248 100644
--- a/src/tools/rust-analyzer/crates/flycheck/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/flycheck/Cargo.toml
@@ -11,10 +11,11 @@ doctest = false
[dependencies]
crossbeam-channel = "0.5.5"
-tracing = "0.1.35"
+tracing = "0.1.37"
cargo_metadata = "0.15.0"
+rustc-hash = "1.1.0"
serde = { version = "1.0.137", features = ["derive"] }
-serde_json = "1.0.81"
+serde_json = "1.0.86"
jod-thread = "0.1.2"
toolchain = { path = "../toolchain", version = "0.0.0" }
diff --git a/src/tools/rust-analyzer/crates/flycheck/src/lib.rs b/src/tools/rust-analyzer/crates/flycheck/src/lib.rs
index d9f4ef5b7..73c3a48b4 100644
--- a/src/tools/rust-analyzer/crates/flycheck/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/flycheck/src/lib.rs
@@ -12,6 +12,7 @@ use std::{
use crossbeam_channel::{never, select, unbounded, Receiver, Sender};
use paths::AbsPathBuf;
+use rustc_hash::FxHashMap;
use serde::Deserialize;
use stdx::{process::streaming_output, JodChild};
@@ -20,6 +21,20 @@ pub use cargo_metadata::diagnostic::{
DiagnosticSpanMacroExpansion,
};
+#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
+pub enum InvocationStrategy {
+ Once,
+ #[default]
+ PerWorkspace,
+}
+
+#[derive(Clone, Debug, Default, PartialEq, Eq)]
+pub enum InvocationLocation {
+ Root(AbsPathBuf),
+ #[default]
+ Workspace,
+}
+
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FlycheckConfig {
CargoCommand {
@@ -30,10 +45,14 @@ pub enum FlycheckConfig {
all_features: bool,
features: Vec<String>,
extra_args: Vec<String>,
+ extra_env: FxHashMap<String, String>,
},
CustomCommand {
command: String,
args: Vec<String>,
+ extra_env: FxHashMap<String, String>,
+ invocation_strategy: InvocationStrategy,
+ invocation_location: InvocationLocation,
},
}
@@ -41,7 +60,7 @@ impl fmt::Display for FlycheckConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
FlycheckConfig::CargoCommand { command, .. } => write!(f, "cargo {}", command),
- FlycheckConfig::CustomCommand { command, args } => {
+ FlycheckConfig::CustomCommand { command, args, .. } => {
write!(f, "{} {}", command, args.join(" "))
}
}
@@ -133,11 +152,15 @@ enum Restart {
No,
}
+/// A [`FlycheckActor`] is a single check instance of a workspace.
struct FlycheckActor {
+ /// The workspace id of this flycheck instance.
id: usize,
sender: Box<dyn Fn(Message) + Send>,
config: FlycheckConfig,
- workspace_root: AbsPathBuf,
+ /// Either the workspace root of the workspace we are flychecking,
+ /// or the project root of the project.
+ root: AbsPathBuf,
/// CargoHandle exists to wrap around the communication needed to be able to
/// run `cargo check` without blocking. Currently the Rust standard library
/// doesn't provide a way to read sub-process output without blocking, so we
@@ -159,20 +182,27 @@ impl FlycheckActor {
workspace_root: AbsPathBuf,
) -> FlycheckActor {
tracing::info!(%id, ?workspace_root, "Spawning flycheck");
- FlycheckActor { id, sender, config, workspace_root, cargo_handle: None }
+ FlycheckActor { id, sender, config, root: workspace_root, cargo_handle: None }
}
- fn progress(&self, progress: Progress) {
+
+ fn report_progress(&self, progress: Progress) {
self.send(Message::Progress { id: self.id, progress });
}
+
fn next_event(&self, inbox: &Receiver<Restart>) -> Option<Event> {
let check_chan = self.cargo_handle.as_ref().map(|cargo| &cargo.receiver);
+ if let Ok(msg) = inbox.try_recv() {
+ // give restarts a preference so check outputs don't block a restart or stop
+ return Some(Event::Restart(msg));
+ }
select! {
recv(inbox) -> msg => msg.ok().map(Event::Restart),
recv(check_chan.unwrap_or(&never())) -> msg => Some(Event::CheckEvent(msg.ok())),
}
}
+
fn run(mut self, inbox: Receiver<Restart>) {
- while let Some(event) = self.next_event(&inbox) {
+ 'event: while let Some(event) = self.next_event(&inbox) {
match event {
Event::Restart(Restart::No) => {
self.cancel_check_process();
@@ -180,7 +210,12 @@ impl FlycheckActor {
Event::Restart(Restart::Yes) => {
// Cancel the previously spawned process
self.cancel_check_process();
- while let Ok(_) = inbox.recv_timeout(Duration::from_millis(50)) {}
+ while let Ok(restart) = inbox.recv_timeout(Duration::from_millis(50)) {
+ // restart chained with a stop, so just cancel
+ if let Restart::No = restart {
+ continue 'event;
+ }
+ }
let command = self.check_command();
tracing::debug!(?command, "will restart flycheck");
@@ -191,10 +226,10 @@ impl FlycheckActor {
"did restart flycheck"
);
self.cargo_handle = Some(cargo_handle);
- self.progress(Progress::DidStart);
+ self.report_progress(Progress::DidStart);
}
Err(error) => {
- self.progress(Progress::DidFailToRestart(format!(
+ self.report_progress(Progress::DidFailToRestart(format!(
"Failed to run the following command: {:?} error={}",
self.check_command(),
error
@@ -214,17 +249,17 @@ impl FlycheckActor {
self.check_command()
);
}
- self.progress(Progress::DidFinish(res));
+ self.report_progress(Progress::DidFinish(res));
}
Event::CheckEvent(Some(message)) => match message {
CargoMessage::CompilerArtifact(msg) => {
- self.progress(Progress::DidCheckCrate(msg.target.name));
+ self.report_progress(Progress::DidCheckCrate(msg.target.name));
}
CargoMessage::Diagnostic(msg) => {
self.send(Message::AddDiagnostic {
id: self.id,
- workspace_root: self.workspace_root.clone(),
+ workspace_root: self.root.clone(),
diagnostic: msg,
});
}
@@ -242,12 +277,12 @@ impl FlycheckActor {
"did cancel flycheck"
);
cargo_handle.cancel();
- self.progress(Progress::DidCancel);
+ self.report_progress(Progress::DidCancel);
}
}
fn check_command(&self) -> Command {
- let mut cmd = match &self.config {
+ let (mut cmd, args) = match &self.config {
FlycheckConfig::CargoCommand {
command,
target_triple,
@@ -256,12 +291,11 @@ impl FlycheckActor {
all_features,
extra_args,
features,
+ extra_env,
} => {
let mut cmd = Command::new(toolchain::cargo());
cmd.arg(command);
- cmd.current_dir(&self.workspace_root);
- cmd.args(&["--workspace", "--message-format=json", "--manifest-path"])
- .arg(self.workspace_root.join("Cargo.toml").as_os_str());
+ cmd.args(&["--workspace", "--message-format=json"]);
if let Some(target) = target_triple {
cmd.args(&["--target", target.as_str()]);
@@ -280,16 +314,41 @@ impl FlycheckActor {
cmd.arg(features.join(" "));
}
}
- cmd.args(extra_args);
- cmd
+ cmd.envs(extra_env);
+ (cmd, extra_args)
}
- FlycheckConfig::CustomCommand { command, args } => {
+ FlycheckConfig::CustomCommand {
+ command,
+ args,
+ extra_env,
+ invocation_strategy,
+ invocation_location,
+ } => {
let mut cmd = Command::new(command);
- cmd.args(args);
- cmd
+ cmd.envs(extra_env);
+
+ match invocation_location {
+ InvocationLocation::Workspace => {
+ match invocation_strategy {
+ InvocationStrategy::Once => {
+ cmd.current_dir(&self.root);
+ }
+ InvocationStrategy::PerWorkspace => {
+ // FIXME: cmd.current_dir(&affected_workspace);
+ cmd.current_dir(&self.root);
+ }
+ }
+ }
+ InvocationLocation::Root(root) => {
+ cmd.current_dir(root);
+ }
+ }
+
+ (cmd, args)
}
};
- cmd.current_dir(&self.workspace_root);
+
+ cmd.args(args);
cmd
}
diff --git a/src/tools/rust-analyzer/crates/hir-def/Cargo.toml b/src/tools/rust-analyzer/crates/hir-def/Cargo.toml
index e8cff2f3e..4ad8e7597 100644
--- a/src/tools/rust-analyzer/crates/hir-def/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/hir-def/Cargo.toml
@@ -15,17 +15,17 @@ arrayvec = "0.7.2"
bitflags = "1.3.2"
cov-mark = "2.0.0-pre.1"
# We need to freeze the version of the crate, as the raw-api feature is considered unstable
-dashmap = { version = "=5.3.4", features = ["raw-api"] }
+dashmap = { version = "=5.4.0", features = ["raw-api"] }
drop_bomb = "0.1.5"
either = "1.7.0"
fst = { version = "0.4.7", default-features = false }
hashbrown = { version = "0.12.1", default-features = false }
indexmap = "1.9.1"
-itertools = "0.10.3"
+itertools = "0.10.5"
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
-once_cell = "1.12.0"
+once_cell = "1.15.0"
rustc-hash = "1.1.0"
-smallvec = "1.9.0"
+smallvec = "1.10.0"
tracing = "0.1.35"
stdx = { path = "../stdx", version = "0.0.0" }
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/adt.rs b/src/tools/rust-analyzer/crates/hir-def/src/adt.rs
index 277135d6d..938db032f 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/adt.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/adt.rs
@@ -1,12 +1,12 @@
//! Defines hir-level representation of structs, enums and unions
-use std::sync::Arc;
+use std::{num::NonZeroU32, sync::Arc};
use base_db::CrateId;
use either::Either;
use hir_expand::{
name::{AsName, Name},
- InFile,
+ HirFileId, InFile,
};
use la_arena::{Arena, ArenaMap};
use syntax::ast::{self, HasName, HasVisibility};
@@ -14,15 +14,18 @@ use tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree};
use crate::{
body::{CfgExpander, LowerCtx},
+ builtin_type::{BuiltinInt, BuiltinUint},
db::DefDatabase,
intern::Interned,
- item_tree::{AttrOwner, Field, Fields, ItemTree, ModItem, RawVisibilityId},
+ item_tree::{AttrOwner, Field, FieldAstId, Fields, ItemTree, ModItem, RawVisibilityId},
+ nameres::diagnostics::DefDiagnostic,
src::HasChildSource,
src::HasSource,
trace::Trace,
type_ref::TypeRef,
visibility::RawVisibility,
- EnumId, LocalEnumVariantId, LocalFieldId, Lookup, ModuleId, StructId, UnionId, VariantId,
+ EnumId, LocalEnumVariantId, LocalFieldId, LocalModuleId, Lookup, ModuleId, StructId, UnionId,
+ VariantId,
};
use cfg::CfgOptions;
@@ -31,7 +34,7 @@ use cfg::CfgOptions;
pub struct StructData {
pub name: Name,
pub variant_data: Arc<VariantData>,
- pub repr: Option<ReprKind>,
+ pub repr: Option<ReprData>,
pub visibility: RawVisibility,
}
@@ -39,6 +42,7 @@ pub struct StructData {
pub struct EnumData {
pub name: Name,
pub variants: Arena<EnumVariantData>,
+ pub repr: Option<ReprData>,
pub visibility: RawVisibility,
}
@@ -63,10 +67,19 @@ pub struct FieldData {
pub visibility: RawVisibility,
}
-#[derive(Debug, Clone, PartialEq, Eq)]
+#[derive(Copy, Debug, Clone, PartialEq, Eq)]
pub enum ReprKind {
- Packed,
- Other,
+ C,
+ BuiltinInt { builtin: Either<BuiltinInt, BuiltinUint>, is_c: bool },
+ Transparent,
+ Default,
+}
+
+#[derive(Copy, Debug, Clone, PartialEq, Eq)]
+pub struct ReprData {
+ pub kind: ReprKind,
+ pub packed: bool,
+ pub align: Option<NonZeroU32>,
}
fn repr_from_value(
@@ -74,25 +87,71 @@ fn repr_from_value(
krate: CrateId,
item_tree: &ItemTree,
of: AttrOwner,
-) -> Option<ReprKind> {
+) -> Option<ReprData> {
item_tree.attrs(db, krate, of).by_key("repr").tt_values().find_map(parse_repr_tt)
}
-fn parse_repr_tt(tt: &Subtree) -> Option<ReprKind> {
+fn parse_repr_tt(tt: &Subtree) -> Option<ReprData> {
match tt.delimiter {
Some(Delimiter { kind: DelimiterKind::Parenthesis, .. }) => {}
_ => return None,
}
- let mut it = tt.token_trees.iter();
- match it.next()? {
- TokenTree::Leaf(Leaf::Ident(ident)) if ident.text == "packed" => Some(ReprKind::Packed),
- _ => Some(ReprKind::Other),
+ let mut data = ReprData { kind: ReprKind::Default, packed: false, align: None };
+
+ let mut tts = tt.token_trees.iter().peekable();
+ while let Some(tt) = tts.next() {
+ if let TokenTree::Leaf(Leaf::Ident(ident)) = tt {
+ match &*ident.text {
+ "packed" => {
+ data.packed = true;
+ if let Some(TokenTree::Subtree(_)) = tts.peek() {
+ tts.next();
+ }
+ }
+ "align" => {
+ if let Some(TokenTree::Subtree(tt)) = tts.peek() {
+ tts.next();
+ if let Some(TokenTree::Leaf(Leaf::Literal(lit))) = tt.token_trees.first() {
+ if let Ok(align) = lit.text.parse() {
+ data.align = Some(align);
+ }
+ }
+ }
+ }
+ "C" => {
+ if let ReprKind::BuiltinInt { is_c, .. } = &mut data.kind {
+ *is_c = true;
+ } else {
+ data.kind = ReprKind::C;
+ }
+ }
+ "transparent" => data.kind = ReprKind::Transparent,
+ repr => {
+ let is_c = matches!(data.kind, ReprKind::C);
+ if let Some(builtin) = BuiltinInt::from_suffix(repr)
+ .map(Either::Left)
+ .or_else(|| BuiltinUint::from_suffix(repr).map(Either::Right))
+ {
+ data.kind = ReprKind::BuiltinInt { builtin, is_c };
+ }
+ }
+ }
+ }
}
+
+ Some(data)
}
impl StructData {
pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> {
+ db.struct_data_with_diagnostics(id).0
+ }
+
+ pub(crate) fn struct_data_with_diagnostics_query(
+ db: &dyn DefDatabase,
+ id: StructId,
+ ) -> (Arc<StructData>, Arc<[DefDiagnostic]>) {
let loc = id.lookup(db);
let krate = loc.container.krate;
let item_tree = loc.id.item_tree(db);
@@ -100,15 +159,35 @@ impl StructData {
let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone();
let strukt = &item_tree[loc.id.value];
- let variant_data = lower_fields(db, krate, &item_tree, &cfg_options, &strukt.fields, None);
- Arc::new(StructData {
- name: strukt.name.clone(),
- variant_data: Arc::new(variant_data),
- repr,
- visibility: item_tree[strukt.visibility].clone(),
- })
+ let (variant_data, diagnostics) = lower_fields(
+ db,
+ krate,
+ loc.id.file_id(),
+ loc.container.local_id,
+ &item_tree,
+ &cfg_options,
+ &strukt.fields,
+ None,
+ );
+ (
+ Arc::new(StructData {
+ name: strukt.name.clone(),
+ variant_data: Arc::new(variant_data),
+ repr,
+ visibility: item_tree[strukt.visibility].clone(),
+ }),
+ diagnostics.into(),
+ )
}
+
pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc<StructData> {
+ db.union_data_with_diagnostics(id).0
+ }
+
+ pub(crate) fn union_data_with_diagnostics_query(
+ db: &dyn DefDatabase,
+ id: UnionId,
+ ) -> (Arc<StructData>, Arc<[DefDiagnostic]>) {
let loc = id.lookup(db);
let krate = loc.container.krate;
let item_tree = loc.id.item_tree(db);
@@ -116,56 +195,98 @@ impl StructData {
let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone();
let union = &item_tree[loc.id.value];
- let variant_data = lower_fields(db, krate, &item_tree, &cfg_options, &union.fields, None);
-
- Arc::new(StructData {
- name: union.name.clone(),
- variant_data: Arc::new(variant_data),
- repr,
- visibility: item_tree[union.visibility].clone(),
- })
+ let (variant_data, diagnostics) = lower_fields(
+ db,
+ krate,
+ loc.id.file_id(),
+ loc.container.local_id,
+ &item_tree,
+ &cfg_options,
+ &union.fields,
+ None,
+ );
+ (
+ Arc::new(StructData {
+ name: union.name.clone(),
+ variant_data: Arc::new(variant_data),
+ repr,
+ visibility: item_tree[union.visibility].clone(),
+ }),
+ diagnostics.into(),
+ )
}
}
impl EnumData {
pub(crate) fn enum_data_query(db: &dyn DefDatabase, e: EnumId) -> Arc<EnumData> {
+ db.enum_data_with_diagnostics(e).0
+ }
+
+ pub(crate) fn enum_data_with_diagnostics_query(
+ db: &dyn DefDatabase,
+ e: EnumId,
+ ) -> (Arc<EnumData>, Arc<[DefDiagnostic]>) {
let loc = e.lookup(db);
let krate = loc.container.krate;
let item_tree = loc.id.item_tree(db);
let cfg_options = db.crate_graph()[krate].cfg_options.clone();
+ let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into());
let enum_ = &item_tree[loc.id.value];
let mut variants = Arena::new();
+ let mut diagnostics = Vec::new();
for tree_id in enum_.variants.clone() {
- if item_tree.attrs(db, krate, tree_id.into()).is_cfg_enabled(&cfg_options) {
- let var = &item_tree[tree_id];
- let var_data = lower_fields(
+ let attrs = item_tree.attrs(db, krate, tree_id.into());
+ let var = &item_tree[tree_id];
+ if attrs.is_cfg_enabled(&cfg_options) {
+ let (var_data, field_diagnostics) = lower_fields(
db,
krate,
+ loc.id.file_id(),
+ loc.container.local_id,
&item_tree,
&cfg_options,
&var.fields,
Some(enum_.visibility),
);
+ diagnostics.extend(field_diagnostics);
variants.alloc(EnumVariantData {
name: var.name.clone(),
variant_data: Arc::new(var_data),
});
+ } else {
+ diagnostics.push(DefDiagnostic::unconfigured_code(
+ loc.container.local_id,
+ InFile::new(loc.id.file_id(), var.ast_id.upcast()),
+ attrs.cfg().unwrap(),
+ cfg_options.clone(),
+ ))
}
}
- Arc::new(EnumData {
- name: enum_.name.clone(),
- variants,
- visibility: item_tree[enum_.visibility].clone(),
- })
+ (
+ Arc::new(EnumData {
+ name: enum_.name.clone(),
+ variants,
+ repr,
+ visibility: item_tree[enum_.visibility].clone(),
+ }),
+ diagnostics.into(),
+ )
}
pub fn variant(&self, name: &Name) -> Option<LocalEnumVariantId> {
let (id, _) = self.variants.iter().find(|(_id, data)| &data.name == name)?;
Some(id)
}
+
+ pub fn variant_body_type(&self) -> Either<BuiltinInt, BuiltinUint> {
+ match self.repr {
+ Some(ReprData { kind: ReprKind::BuiltinInt { builtin, .. }, .. }) => builtin,
+ _ => Either::Left(BuiltinInt::Isize),
+ }
+ }
}
impl HasChildSource<LocalEnumVariantId> for EnumId {
@@ -324,31 +445,64 @@ fn lower_struct(
fn lower_fields(
db: &dyn DefDatabase,
krate: CrateId,
+ current_file_id: HirFileId,
+ container: LocalModuleId,
item_tree: &ItemTree,
cfg_options: &CfgOptions,
fields: &Fields,
override_visibility: Option<RawVisibilityId>,
-) -> VariantData {
+) -> (VariantData, Vec<DefDiagnostic>) {
+ let mut diagnostics = Vec::new();
match fields {
Fields::Record(flds) => {
let mut arena = Arena::new();
for field_id in flds.clone() {
- if item_tree.attrs(db, krate, field_id.into()).is_cfg_enabled(cfg_options) {
- arena.alloc(lower_field(item_tree, &item_tree[field_id], override_visibility));
+ let attrs = item_tree.attrs(db, krate, field_id.into());
+ let field = &item_tree[field_id];
+ if attrs.is_cfg_enabled(cfg_options) {
+ arena.alloc(lower_field(item_tree, field, override_visibility));
+ } else {
+ diagnostics.push(DefDiagnostic::unconfigured_code(
+ container,
+ InFile::new(
+ current_file_id,
+ match field.ast_id {
+ FieldAstId::Record(it) => it.upcast(),
+ FieldAstId::Tuple(it) => it.upcast(),
+ },
+ ),
+ attrs.cfg().unwrap(),
+ cfg_options.clone(),
+ ))
}
}
- VariantData::Record(arena)
+ (VariantData::Record(arena), diagnostics)
}
Fields::Tuple(flds) => {
let mut arena = Arena::new();
for field_id in flds.clone() {
- if item_tree.attrs(db, krate, field_id.into()).is_cfg_enabled(cfg_options) {
- arena.alloc(lower_field(item_tree, &item_tree[field_id], override_visibility));
+ let attrs = item_tree.attrs(db, krate, field_id.into());
+ let field = &item_tree[field_id];
+ if attrs.is_cfg_enabled(cfg_options) {
+ arena.alloc(lower_field(item_tree, field, override_visibility));
+ } else {
+ diagnostics.push(DefDiagnostic::unconfigured_code(
+ container,
+ InFile::new(
+ current_file_id,
+ match field.ast_id {
+ FieldAstId::Record(it) => it.upcast(),
+ FieldAstId::Tuple(it) => it.upcast(),
+ },
+ ),
+ attrs.cfg().unwrap(),
+ cfg_options.clone(),
+ ))
}
}
- VariantData::Tuple(arena)
+ (VariantData::Tuple(arena), diagnostics)
}
- Fields::Unit => VariantData::Unit,
+ Fields::Unit => (VariantData::Unit, diagnostics),
}
}
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/body.rs b/src/tools/rust-analyzer/crates/hir-def/src/body.rs
index 22f5fb992..759f3b8c0 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/body.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/body.rs
@@ -27,7 +27,7 @@ use crate::{
macro_id_to_def_id,
nameres::DefMap,
path::{ModPath, Path},
- src::HasSource,
+ src::{HasChildSource, HasSource},
AsMacroCall, BlockId, DefWithBodyId, HasModule, LocalModuleId, Lookup, MacroId, ModuleId,
UnresolvedMacro,
};
@@ -311,7 +311,20 @@ impl Body {
DefWithBodyId::FunctionId(f) => {
let f = f.lookup(db);
let src = f.source(db);
- params = src.value.param_list();
+ params = src.value.param_list().map(|param_list| {
+ let item_tree = f.id.item_tree(db);
+ let func = &item_tree[f.id.value];
+ let krate = f.container.module(db).krate;
+ let crate_graph = db.crate_graph();
+ (
+ param_list,
+ func.params.clone().map(move |param| {
+ item_tree
+ .attrs(db, krate, param.into())
+ .is_cfg_enabled(&crate_graph[krate].cfg_options)
+ }),
+ )
+ });
(src.file_id, f.module(db), src.value.body().map(ast::Expr::from))
}
DefWithBodyId::ConstId(c) => {
@@ -324,10 +337,17 @@ impl Body {
let src = s.source(db);
(src.file_id, s.module(db), src.value.body())
}
+ DefWithBodyId::VariantId(v) => {
+ let e = v.parent.lookup(db);
+ let src = v.parent.child_source(db);
+ let variant = &src.value[v.local_id];
+ (src.file_id, e.container, variant.expr())
+ }
};
let expander = Expander::new(db, file_id, module);
let (mut body, source_map) = Body::new(db, expander, params, body);
body.shrink_to_fit();
+
(Arc::new(body), Arc::new(source_map))
}
@@ -364,7 +384,7 @@ impl Body {
fn new(
db: &dyn DefDatabase,
expander: Expander,
- params: Option<ast::ParamList>,
+ params: Option<(ast::ParamList, impl Iterator<Item = bool>)>,
body: Option<ast::Expr>,
) -> (Body, BodySourceMap) {
lower::lower(db, expander, params, body)
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs b/src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs
index 3b3297f78..ccc01c3ef 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs
@@ -29,8 +29,9 @@ use crate::{
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
db::DefDatabase,
expr::{
- dummy_expr_id, Array, BindingAnnotation, Expr, ExprId, FloatTypeWrapper, Label, LabelId,
- Literal, MatchArm, Pat, PatId, RecordFieldPat, RecordLitField, Statement,
+ dummy_expr_id, Array, BindingAnnotation, ClosureKind, Expr, ExprId, FloatTypeWrapper,
+ Label, LabelId, Literal, MatchArm, Movability, Pat, PatId, RecordFieldPat, RecordLitField,
+ Statement,
},
intern::Interned,
item_scope::BuiltinShadowMode,
@@ -76,7 +77,7 @@ impl<'a> LowerCtx<'a> {
pub(super) fn lower(
db: &dyn DefDatabase,
expander: Expander,
- params: Option<ast::ParamList>,
+ params: Option<(ast::ParamList, impl Iterator<Item = bool>)>,
body: Option<ast::Expr>,
) -> (Body, BodySourceMap) {
ExprCollector {
@@ -97,6 +98,7 @@ pub(super) fn lower(
name_to_pat_grouping: Default::default(),
is_lowering_inside_or_pat: false,
is_lowering_assignee_expr: false,
+ is_lowering_generator: false,
}
.collect(params, body)
}
@@ -111,16 +113,19 @@ struct ExprCollector<'a> {
name_to_pat_grouping: FxHashMap<Name, Vec<PatId>>,
is_lowering_inside_or_pat: bool,
is_lowering_assignee_expr: bool,
+ is_lowering_generator: bool,
}
impl ExprCollector<'_> {
fn collect(
mut self,
- param_list: Option<ast::ParamList>,
+ param_list: Option<(ast::ParamList, impl Iterator<Item = bool>)>,
body: Option<ast::Expr>,
) -> (Body, BodySourceMap) {
- if let Some(param_list) = param_list {
- if let Some(self_param) = param_list.self_param() {
+ if let Some((param_list, mut attr_enabled)) = param_list {
+ if let Some(self_param) =
+ param_list.self_param().filter(|_| attr_enabled.next().unwrap_or(false))
+ {
let ptr = AstPtr::new(&self_param);
let param_pat = self.alloc_pat(
Pat::Bind {
@@ -136,7 +141,11 @@ impl ExprCollector<'_> {
self.body.params.push(param_pat);
}
- for pat in param_list.params().filter_map(|param| param.pat()) {
+ for pat in param_list
+ .params()
+ .zip(attr_enabled)
+ .filter_map(|(param, enabled)| param.pat().filter(|_| enabled))
+ {
let param_pat = self.collect_pat(pat);
self.body.params.push(param_pat);
}
@@ -358,6 +367,7 @@ impl ExprCollector<'_> {
self.alloc_expr(Expr::Return { expr }, syntax_ptr)
}
ast::Expr::YieldExpr(e) => {
+ self.is_lowering_generator = true;
let expr = e.expr().map(|e| self.collect_expr(e));
self.alloc_expr(Expr::Yield { expr }, syntax_ptr)
}
@@ -459,13 +469,31 @@ impl ExprCollector<'_> {
.ret_type()
.and_then(|r| r.ty())
.map(|it| Interned::new(TypeRef::from_ast(&self.ctx(), it)));
+
+ let prev_is_lowering_generator = self.is_lowering_generator;
+ self.is_lowering_generator = false;
+
let body = self.collect_expr_opt(e.body());
+
+ let closure_kind = if self.is_lowering_generator {
+ let movability = if e.static_token().is_some() {
+ Movability::Static
+ } else {
+ Movability::Movable
+ };
+ ClosureKind::Generator(movability)
+ } else {
+ ClosureKind::Closure
+ };
+ self.is_lowering_generator = prev_is_lowering_generator;
+
self.alloc_expr(
Expr::Closure {
args: args.into(),
arg_types: arg_types.into(),
ret_type,
body,
+ closure_kind,
},
syntax_ptr,
)
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs b/src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs
index f2fed9544..162d173d5 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs
@@ -2,8 +2,10 @@
use std::fmt::{self, Write};
+use syntax::ast::HasName;
+
use crate::{
- expr::{Array, BindingAnnotation, Literal, Statement},
+ expr::{Array, BindingAnnotation, ClosureKind, Literal, Movability, Statement},
pretty::{print_generic_args, print_path, print_type_ref},
type_ref::TypeRef,
};
@@ -32,6 +34,16 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
};
format!("const {} = ", name)
}
+ DefWithBodyId::VariantId(it) => {
+ needs_semi = false;
+ let src = it.parent.child_source(db);
+ let variant = &src.value[it.local_id];
+ let name = match &variant.name() {
+ Some(name) => name.to_string(),
+ None => "_".to_string(),
+ };
+ format!("{}", name)
+ }
};
let mut p = Printer { body, buf: header, indent_level: 0, needs_indent: false };
@@ -350,7 +362,10 @@ impl<'a> Printer<'a> {
self.print_expr(*index);
w!(self, "]");
}
- Expr::Closure { args, arg_types, ret_type, body } => {
+ Expr::Closure { args, arg_types, ret_type, body, closure_kind } => {
+ if let ClosureKind::Generator(Movability::Static) = closure_kind {
+ w!(self, "static ");
+ }
w!(self, "|");
for (i, (pat, ty)) in args.iter().zip(arg_types.iter()).enumerate() {
if i != 0 {
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/builtin_attr.rs b/src/tools/rust-analyzer/crates/hir-def/src/builtin_attr.rs
index 0e7ce5f85..39581b33a 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/builtin_attr.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/builtin_attr.rs
@@ -379,7 +379,7 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
// ==========================================================================
rustc_attr!(rustc_allocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
- rustc_attr!(rustc_allocator_nounwind, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
+ rustc_attr!(rustc_nounwind, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
gated!(
alloc_error_handler, Normal, template!(Word), WarnFollowing,
experimental!(alloc_error_handler)
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/child_by_source.rs b/src/tools/rust-analyzer/crates/hir-def/src/child_by_source.rs
index 5b1435e8f..bb1316525 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/child_by_source.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/child_by_source.rs
@@ -198,6 +198,10 @@ impl ChildBySource for EnumId {
impl ChildBySource for DefWithBodyId {
fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId) {
let body = db.body(*self);
+ if let &DefWithBodyId::VariantId(v) = self {
+ VariantId::EnumVariantId(v).child_by_source_to(db, res, file_id)
+ }
+
for (_, def_map) in body.blocks(db) {
// All block expressions are merged into the same map, because they logically all add
// inner items to the containing `DefWithBodyId`.
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/data.rs b/src/tools/rust-analyzer/crates/hir-def/src/data.rs
index 631ae3cf1..2dc69b00a 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/data.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/data.rs
@@ -219,7 +219,7 @@ impl TraitData {
pub(crate) fn trait_data_with_diagnostics_query(
db: &dyn DefDatabase,
tr: TraitId,
- ) -> (Arc<TraitData>, Arc<Vec<DefDiagnostic>>) {
+ ) -> (Arc<TraitData>, Arc<[DefDiagnostic]>) {
let tr_loc @ ItemLoc { container: module_id, id: tree_id } = tr.lookup(db);
let item_tree = tree_id.item_tree(db);
let tr_def = &item_tree[tree_id.value];
@@ -251,7 +251,7 @@ impl TraitData {
visibility,
skip_array_during_method_dispatch,
}),
- Arc::new(diagnostics),
+ diagnostics.into(),
)
}
@@ -299,7 +299,7 @@ impl ImplData {
pub(crate) fn impl_data_with_diagnostics_query(
db: &dyn DefDatabase,
id: ImplId,
- ) -> (Arc<ImplData>, Arc<Vec<DefDiagnostic>>) {
+ ) -> (Arc<ImplData>, Arc<[DefDiagnostic]>) {
let _p = profile::span("impl_data_with_diagnostics_query");
let ItemLoc { container: module_id, id: tree_id } = id.lookup(db);
@@ -318,7 +318,7 @@ impl ImplData {
(
Arc::new(ImplData { target_trait, self_ty, items, is_negative, attribute_calls }),
- Arc::new(diagnostics),
+ diagnostics.into(),
)
}
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/db.rs b/src/tools/rust-analyzer/crates/hir-def/src/db.rs
index 40b2f734b..431c82554 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/db.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/db.rs
@@ -97,24 +97,33 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
#[salsa::invoke(StructData::struct_data_query)]
fn struct_data(&self, id: StructId) -> Arc<StructData>;
+ #[salsa::invoke(StructData::struct_data_with_diagnostics_query)]
+ fn struct_data_with_diagnostics(&self, id: StructId)
+ -> (Arc<StructData>, Arc<[DefDiagnostic]>);
+
#[salsa::invoke(StructData::union_data_query)]
fn union_data(&self, id: UnionId) -> Arc<StructData>;
+ #[salsa::invoke(StructData::union_data_with_diagnostics_query)]
+ fn union_data_with_diagnostics(&self, id: UnionId) -> (Arc<StructData>, Arc<[DefDiagnostic]>);
+
#[salsa::invoke(EnumData::enum_data_query)]
fn enum_data(&self, e: EnumId) -> Arc<EnumData>;
+ #[salsa::invoke(EnumData::enum_data_with_diagnostics_query)]
+ fn enum_data_with_diagnostics(&self, e: EnumId) -> (Arc<EnumData>, Arc<[DefDiagnostic]>);
+
#[salsa::invoke(ImplData::impl_data_query)]
fn impl_data(&self, e: ImplId) -> Arc<ImplData>;
#[salsa::invoke(ImplData::impl_data_with_diagnostics_query)]
- fn impl_data_with_diagnostics(&self, e: ImplId) -> (Arc<ImplData>, Arc<Vec<DefDiagnostic>>);
+ fn impl_data_with_diagnostics(&self, e: ImplId) -> (Arc<ImplData>, Arc<[DefDiagnostic]>);
#[salsa::invoke(TraitData::trait_data_query)]
fn trait_data(&self, e: TraitId) -> Arc<TraitData>;
#[salsa::invoke(TraitData::trait_data_with_diagnostics_query)]
- fn trait_data_with_diagnostics(&self, tr: TraitId)
- -> (Arc<TraitData>, Arc<Vec<DefDiagnostic>>);
+ fn trait_data_with_diagnostics(&self, tr: TraitId) -> (Arc<TraitData>, Arc<[DefDiagnostic]>);
#[salsa::invoke(TypeAliasData::type_alias_data_query)]
fn type_alias_data(&self, e: TypeAliasId) -> Arc<TypeAliasData>;
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/expr.rs b/src/tools/rust-analyzer/crates/hir-def/src/expr.rs
index 419d3feec..162646550 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/expr.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/expr.rs
@@ -198,6 +198,7 @@ pub enum Expr {
arg_types: Box<[Option<Interned<TypeRef>>]>,
ret_type: Option<Interned<TypeRef>>,
body: ExprId,
+ closure_kind: ClosureKind,
},
Tuple {
exprs: Box<[ExprId]>,
@@ -211,6 +212,18 @@ pub enum Expr {
Underscore,
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum ClosureKind {
+ Closure,
+ Generator(Movability),
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum Movability {
+ Static,
+ Movable,
+}
+
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Array {
ElementList { elements: Box<[ExprId]>, is_assignee_expr: bool },
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/find_path.rs b/src/tools/rust-analyzer/crates/hir-def/src/find_path.rs
index 89e961f84..c70e6fdcc 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/find_path.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/find_path.rs
@@ -1,6 +1,6 @@
//! An algorithm to find a path to refer to a certain item.
-use std::iter;
+use std::{cmp::Ordering, iter};
use hir_expand::name::{known, AsName, Name};
use rustc_hash::FxHashSet;
@@ -16,9 +16,14 @@ use crate::{
/// Find a path that can be used to refer to a certain item. This can depend on
/// *from where* you're referring to the item, hence the `from` parameter.
-pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
+pub fn find_path(
+ db: &dyn DefDatabase,
+ item: ItemInNs,
+ from: ModuleId,
+ prefer_no_std: bool,
+) -> Option<ModPath> {
let _p = profile::span("find_path");
- find_path_inner(db, item, from, None)
+ find_path_inner(db, item, from, None, prefer_no_std)
}
pub fn find_path_prefixed(
@@ -26,47 +31,14 @@ pub fn find_path_prefixed(
item: ItemInNs,
from: ModuleId,
prefix_kind: PrefixKind,
+ prefer_no_std: bool,
) -> Option<ModPath> {
let _p = profile::span("find_path_prefixed");
- find_path_inner(db, item, from, Some(prefix_kind))
+ find_path_inner(db, item, from, Some(prefix_kind), prefer_no_std)
}
const MAX_PATH_LEN: usize = 15;
-trait ModPathExt {
- fn starts_with_std(&self) -> bool;
- fn can_start_with_std(&self) -> bool;
-}
-
-impl ModPathExt for ModPath {
- fn starts_with_std(&self) -> bool {
- self.segments().first() == Some(&known::std)
- }
-
- // Can we replace the first segment with `std::` and still get a valid, identical path?
- fn can_start_with_std(&self) -> bool {
- let first_segment = self.segments().first();
- first_segment == Some(&known::alloc) || first_segment == Some(&known::core)
- }
-}
-
-fn check_self_super(def_map: &DefMap, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
- if item == ItemInNs::Types(from.into()) {
- // - if the item is the module we're in, use `self`
- Some(ModPath::from_segments(PathKind::Super(0), None))
- } else if let Some(parent_id) = def_map[from.local_id].parent {
- // - if the item is the parent module, use `super` (this is not used recursively, since `super::super` is ugly)
- let parent_id = def_map.module_id(parent_id);
- if item == ItemInNs::Types(ModuleDefId::ModuleId(parent_id)) {
- Some(ModPath::from_segments(PathKind::Super(1), None))
- } else {
- None
- }
- } else {
- None
- }
-}
-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum PrefixKind {
/// Causes paths to always start with either `self`, `super`, `crate` or a crate-name.
@@ -94,135 +66,247 @@ impl PrefixKind {
self == &PrefixKind::ByCrate
}
}
+
/// Attempts to find a path to refer to the given `item` visible from the `from` ModuleId
fn find_path_inner(
db: &dyn DefDatabase,
item: ItemInNs,
from: ModuleId,
prefixed: Option<PrefixKind>,
+ prefer_no_std: bool,
) -> Option<ModPath> {
- // FIXME: Do fast path for std/core libs?
+ // - if the item is a builtin, it's in scope
+ if let ItemInNs::Types(ModuleDefId::BuiltinType(builtin)) = item {
+ return Some(ModPath::from_segments(PathKind::Plain, Some(builtin.as_name())));
+ }
- let mut visited_modules = FxHashSet::default();
let def_map = from.def_map(db);
- find_path_inner_(db, &def_map, from, item, MAX_PATH_LEN, prefixed, &mut visited_modules)
+ let crate_root = def_map.crate_root(db);
+ // - if the item is a module, jump straight to module search
+ if let ItemInNs::Types(ModuleDefId::ModuleId(module_id)) = item {
+ let mut visited_modules = FxHashSet::default();
+ return find_path_for_module(
+ db,
+ &def_map,
+ &mut visited_modules,
+ crate_root,
+ from,
+ module_id,
+ MAX_PATH_LEN,
+ prefixed,
+ prefer_no_std || db.crate_supports_no_std(crate_root.krate),
+ );
+ }
+
+ // - if the item is already in scope, return the name under which it is
+ let scope_name = find_in_scope(db, &def_map, from, item);
+ if prefixed.is_none() {
+ if let Some(scope_name) = scope_name {
+ return Some(ModPath::from_segments(PathKind::Plain, Some(scope_name)));
+ }
+ }
+
+ // - if the item is in the prelude, return the name from there
+ if let Some(value) = find_in_prelude(db, &crate_root.def_map(db), item, from) {
+ return value;
+ }
+
+ if let Some(ModuleDefId::EnumVariantId(variant)) = item.as_module_def_id() {
+ // - if the item is an enum variant, refer to it via the enum
+ if let Some(mut path) = find_path_inner(
+ db,
+ ItemInNs::Types(variant.parent.into()),
+ from,
+ prefixed,
+ prefer_no_std,
+ ) {
+ let data = db.enum_data(variant.parent);
+ path.push_segment(data.variants[variant.local_id].name.clone());
+ return Some(path);
+ }
+ // If this doesn't work, it seems we have no way of referring to the
+ // enum; that's very weird, but there might still be a reexport of the
+ // variant somewhere
+ }
+
+ let mut visited_modules = FxHashSet::default();
+
+ calculate_best_path(
+ db,
+ &def_map,
+ &mut visited_modules,
+ crate_root,
+ MAX_PATH_LEN,
+ item,
+ from,
+ prefixed,
+ prefer_no_std || db.crate_supports_no_std(crate_root.krate),
+ scope_name,
+ )
}
-fn find_path_inner_(
+fn find_path_for_module(
db: &dyn DefDatabase,
def_map: &DefMap,
+ visited_modules: &mut FxHashSet<ModuleId>,
+ crate_root: ModuleId,
from: ModuleId,
- item: ItemInNs,
+ module_id: ModuleId,
max_len: usize,
- mut prefixed: Option<PrefixKind>,
- visited_modules: &mut FxHashSet<ModuleId>,
+ prefixed: Option<PrefixKind>,
+ prefer_no_std: bool,
) -> Option<ModPath> {
if max_len == 0 {
return None;
}
// Base cases:
-
// - if the item is already in scope, return the name under which it is
- let scope_name = def_map.with_ancestor_maps(db, from.local_id, &mut |def_map, local_id| {
- def_map[local_id].scope.name_of(item).map(|(name, _)| name.clone())
- });
+ let scope_name = find_in_scope(db, def_map, from, ItemInNs::Types(module_id.into()));
if prefixed.is_none() {
if let Some(scope_name) = scope_name {
return Some(ModPath::from_segments(PathKind::Plain, Some(scope_name)));
}
}
- // - if the item is a builtin, it's in scope
- if let ItemInNs::Types(ModuleDefId::BuiltinType(builtin)) = item {
- return Some(ModPath::from_segments(PathKind::Plain, Some(builtin.as_name())));
- }
-
// - if the item is the crate root, return `crate`
- let crate_root = def_map.crate_root(db);
- if item == ItemInNs::Types(ModuleDefId::ModuleId(crate_root)) {
+ if module_id == crate_root {
return Some(ModPath::from_segments(PathKind::Crate, None));
}
+ // - if relative paths are fine, check if we are searching for a parent
if prefixed.filter(PrefixKind::is_absolute).is_none() {
- if let modpath @ Some(_) = check_self_super(&def_map, item, from) {
+ if let modpath @ Some(_) = find_self_super(&def_map, module_id, from) {
return modpath;
}
}
// - if the item is the crate root of a dependency crate, return the name from the extern prelude
let root_def_map = crate_root.def_map(db);
- if let ItemInNs::Types(ModuleDefId::ModuleId(item)) = item {
- for (name, &def_id) in root_def_map.extern_prelude() {
- if item == def_id {
- let name = scope_name.unwrap_or_else(|| name.clone());
-
- let name_already_occupied_in_type_ns = def_map
- .with_ancestor_maps(db, from.local_id, &mut |def_map, local_id| {
- def_map[local_id]
- .scope
- .type_(&name)
- .filter(|&(id, _)| id != ModuleDefId::ModuleId(def_id))
- })
- .is_some();
- let kind = if name_already_occupied_in_type_ns {
- cov_mark::hit!(ambiguous_crate_start);
- PathKind::Abs
- } else {
- PathKind::Plain
- };
- return Some(ModPath::from_segments(kind, Some(name)));
- }
+ for (name, &def_id) in root_def_map.extern_prelude() {
+ if module_id == def_id {
+ let name = scope_name.unwrap_or_else(|| name.clone());
+
+ let name_already_occupied_in_type_ns = def_map
+ .with_ancestor_maps(db, from.local_id, &mut |def_map, local_id| {
+ def_map[local_id]
+ .scope
+ .type_(&name)
+ .filter(|&(id, _)| id != ModuleDefId::ModuleId(def_id))
+ })
+ .is_some();
+ let kind = if name_already_occupied_in_type_ns {
+ cov_mark::hit!(ambiguous_crate_start);
+ PathKind::Abs
+ } else {
+ PathKind::Plain
+ };
+ return Some(ModPath::from_segments(kind, Some(name)));
}
}
- // - if the item is in the prelude, return the name from there
+ if let Some(value) = find_in_prelude(db, &root_def_map, ItemInNs::Types(module_id.into()), from)
+ {
+ return value;
+ }
+ calculate_best_path(
+ db,
+ def_map,
+ visited_modules,
+ crate_root,
+ max_len,
+ ItemInNs::Types(module_id.into()),
+ from,
+ prefixed,
+ prefer_no_std,
+ scope_name,
+ )
+}
+
+fn find_in_scope(
+ db: &dyn DefDatabase,
+ def_map: &DefMap,
+ from: ModuleId,
+ item: ItemInNs,
+) -> Option<Name> {
+ def_map.with_ancestor_maps(db, from.local_id, &mut |def_map, local_id| {
+ def_map[local_id].scope.name_of(item).map(|(name, _)| name.clone())
+ })
+}
+
+fn find_in_prelude(
+ db: &dyn DefDatabase,
+ root_def_map: &DefMap,
+ item: ItemInNs,
+ from: ModuleId,
+) -> Option<Option<ModPath>> {
if let Some(prelude_module) = root_def_map.prelude() {
// Preludes in block DefMaps are ignored, only the crate DefMap is searched
let prelude_def_map = prelude_module.def_map(db);
let prelude_scope = &prelude_def_map[prelude_module.local_id].scope;
if let Some((name, vis)) = prelude_scope.name_of(item) {
if vis.is_visible_from(db, from) {
- return Some(ModPath::from_segments(PathKind::Plain, Some(name.clone())));
+ return Some(Some(ModPath::from_segments(PathKind::Plain, Some(name.clone()))));
}
}
}
+ None
+}
- // Recursive case:
- // - if the item is an enum variant, refer to it via the enum
- if let Some(ModuleDefId::EnumVariantId(variant)) = item.as_module_def_id() {
- if let Some(mut path) = find_path(db, ItemInNs::Types(variant.parent.into()), from) {
- let data = db.enum_data(variant.parent);
- path.push_segment(data.variants[variant.local_id].name.clone());
- return Some(path);
+fn find_self_super(def_map: &DefMap, item: ModuleId, from: ModuleId) -> Option<ModPath> {
+ if item == from {
+ // - if the item is the module we're in, use `self`
+ Some(ModPath::from_segments(PathKind::Super(0), None))
+ } else if let Some(parent_id) = def_map[from.local_id].parent {
+ // - if the item is the parent module, use `super` (this is not used recursively, since `super::super` is ugly)
+ let parent_id = def_map.module_id(parent_id);
+ if item == parent_id {
+ Some(ModPath::from_segments(PathKind::Super(1), None))
+ } else {
+ None
}
- // If this doesn't work, it seems we have no way of referring to the
- // enum; that's very weird, but there might still be a reexport of the
- // variant somewhere
+ } else {
+ None
}
+}
- // - otherwise, look for modules containing (reexporting) it and import it from one of those
- let prefer_no_std = db.crate_supports_no_std(crate_root.krate);
+fn calculate_best_path(
+ db: &dyn DefDatabase,
+ def_map: &DefMap,
+ visited_modules: &mut FxHashSet<ModuleId>,
+ crate_root: ModuleId,
+ max_len: usize,
+ item: ItemInNs,
+ from: ModuleId,
+ mut prefixed: Option<PrefixKind>,
+ prefer_no_std: bool,
+ scope_name: Option<Name>,
+) -> Option<ModPath> {
+ if max_len <= 1 {
+ return None;
+ }
let mut best_path = None;
- let mut best_path_len = max_len;
-
+ // Recursive case:
+ // - otherwise, look for modules containing (reexporting) it and import it from one of those
if item.krate(db) == Some(from.krate) {
+ let mut best_path_len = max_len;
// Item was defined in the same crate that wants to import it. It cannot be found in any
// dependency in this case.
- // FIXME: this should have a fast path that doesn't look through the prelude again?
for (module_id, name) in find_local_import_locations(db, item, from) {
if !visited_modules.insert(module_id) {
cov_mark::hit!(recursive_imports);
continue;
}
- if let Some(mut path) = find_path_inner_(
+ if let Some(mut path) = find_path_for_module(
db,
def_map,
+ visited_modules,
+ crate_root,
from,
- ItemInNs::Types(ModuleDefId::ModuleId(module_id)),
+ module_id,
best_path_len - 1,
prefixed,
- visited_modules,
+ prefer_no_std,
) {
path.push_segment(name);
@@ -245,14 +329,16 @@ fn find_path_inner_(
import_map.import_info_for(item).and_then(|info| {
// Determine best path for containing module and append last segment from `info`.
// FIXME: we should guide this to look up the path locally, or from the same crate again?
- let mut path = find_path_inner_(
+ let mut path = find_path_for_module(
db,
def_map,
+ visited_modules,
+ crate_root,
from,
- ItemInNs::Types(ModuleDefId::ModuleId(info.container)),
- best_path_len - 1,
+ info.container,
+ max_len - 1,
prefixed,
- visited_modules,
+ prefer_no_std,
)?;
cov_mark::hit!(partially_imported);
path.push_segment(info.path.segments.last()?.clone());
@@ -268,16 +354,12 @@ fn find_path_inner_(
best_path = Some(new_path);
}
}
-
- // If the item is declared inside a block expression, don't use a prefix, as we don't handle
- // that correctly (FIXME).
- if let Some(item_module) = item.as_module_def_id().and_then(|did| did.module(db)) {
- if item_module.def_map(db).block_id().is_some() && prefixed.is_some() {
+ if let Some(module) = item.module(db) {
+ if module.def_map(db).block_id().is_some() && prefixed.is_some() {
cov_mark::hit!(prefixed_in_block_expression);
prefixed = Some(PrefixKind::Plain);
}
}
-
match prefixed.map(PrefixKind::prefix) {
Some(prefix) => best_path.or_else(|| {
scope_name.map(|scope_name| ModPath::from_segments(prefix, Some(scope_name)))
@@ -287,29 +369,48 @@ fn find_path_inner_(
}
fn select_best_path(old_path: ModPath, new_path: ModPath, prefer_no_std: bool) -> ModPath {
- if old_path.starts_with_std() && new_path.can_start_with_std() {
- if prefer_no_std {
- cov_mark::hit!(prefer_no_std_paths);
- new_path
- } else {
- cov_mark::hit!(prefer_std_paths);
- old_path
+ const STD_CRATES: [Name; 3] = [known::std, known::core, known::alloc];
+ match (old_path.segments().first(), new_path.segments().first()) {
+ (Some(old), Some(new)) if STD_CRATES.contains(old) && STD_CRATES.contains(new) => {
+ let rank = match prefer_no_std {
+ false => |name: &Name| match name {
+ name if name == &known::core => 0,
+ name if name == &known::alloc => 0,
+ name if name == &known::std => 1,
+ _ => unreachable!(),
+ },
+ true => |name: &Name| match name {
+ name if name == &known::core => 2,
+ name if name == &known::alloc => 1,
+ name if name == &known::std => 0,
+ _ => unreachable!(),
+ },
+ };
+ let nrank = rank(new);
+ let orank = rank(old);
+ match nrank.cmp(&orank) {
+ Ordering::Less => old_path,
+ Ordering::Equal => {
+ if new_path.len() < old_path.len() {
+ new_path
+ } else {
+ old_path
+ }
+ }
+ Ordering::Greater => new_path,
+ }
}
- } else if new_path.starts_with_std() && old_path.can_start_with_std() {
- if prefer_no_std {
- cov_mark::hit!(prefer_no_std_paths);
- old_path
- } else {
- cov_mark::hit!(prefer_std_paths);
- new_path
+ _ => {
+ if new_path.len() < old_path.len() {
+ new_path
+ } else {
+ old_path
+ }
}
- } else if new_path.len() < old_path.len() {
- new_path
- } else {
- old_path
}
}
+// FIXME: Remove allocations
/// Finds locations in `from.krate` from which `item` can be imported by `from`.
fn find_local_import_locations(
db: &dyn DefDatabase,
@@ -428,7 +529,8 @@ mod tests {
.take_types()
.unwrap();
- let found_path = find_path_inner(&db, ItemInNs::Types(resolved), module, prefix_kind);
+ let found_path =
+ find_path_inner(&db, ItemInNs::Types(resolved), module, prefix_kind, false);
assert_eq!(found_path, Some(mod_path), "{:?}", prefix_kind);
}
@@ -468,8 +570,8 @@ $0
"#,
"E::A",
"E::A",
- "E::A",
- "E::A",
+ "crate::E::A",
+ "self::E::A",
);
}
@@ -788,7 +890,6 @@ pub use super::foo;
#[test]
fn prefer_std_paths_over_alloc() {
- cov_mark::check!(prefer_std_paths);
check_found_path(
r#"
//- /main.rs crate:main deps:alloc,std
@@ -813,7 +914,6 @@ pub mod sync {
#[test]
fn prefer_core_paths_over_std() {
- cov_mark::check!(prefer_no_std_paths);
check_found_path(
r#"
//- /main.rs crate:main deps:core,std
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs
index a11a92204..7721221c4 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/item_scope.rs
@@ -18,7 +18,7 @@ use crate::{
ConstId, HasModule, ImplId, LocalModuleId, MacroId, ModuleDefId, ModuleId, TraitId,
};
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, Debug)]
pub(crate) enum ImportType {
Glob,
Named,
@@ -302,13 +302,13 @@ impl ItemScope {
$changed = true;
}
Entry::Occupied(mut entry)
- if $glob_imports.$field.contains(&$lookup)
- && matches!($def_import_type, ImportType::Named) =>
+ if matches!($def_import_type, ImportType::Named) =>
{
- cov_mark::hit!(import_shadowed);
- $glob_imports.$field.remove(&$lookup);
- entry.insert(fld);
- $changed = true;
+ if $glob_imports.$field.remove(&$lookup) {
+ cov_mark::hit!(import_shadowed);
+ entry.insert(fld);
+ $changed = true;
+ }
}
_ => {}
}
@@ -457,8 +457,15 @@ impl ItemInNs {
/// Returns the crate defining this item (or `None` if `self` is built-in).
pub fn krate(&self, db: &dyn DefDatabase) -> Option<CrateId> {
match self {
- ItemInNs::Types(did) | ItemInNs::Values(did) => did.module(db).map(|m| m.krate),
+ ItemInNs::Types(id) | ItemInNs::Values(id) => id.module(db).map(|m| m.krate),
ItemInNs::Macros(id) => Some(id.module(db).krate),
}
}
+
+ pub fn module(&self, db: &dyn DefDatabase) -> Option<ModuleId> {
+ match self {
+ ItemInNs::Types(id) | ItemInNs::Values(id) => id.module(db),
+ ItemInNs::Macros(id) => Some(id.module(db)),
+ }
+ }
}
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs
index 3342d4db4..570344596 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs
@@ -943,6 +943,7 @@ impl AssocItem {
pub struct Variant {
pub name: Name,
pub fields: Fields,
+ pub ast_id: FileAstId<ast::Variant>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -952,10 +953,17 @@ pub enum Fields {
Unit,
}
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum FieldAstId {
+ Record(FileAstId<ast::RecordField>),
+ Tuple(FileAstId<ast::TupleField>),
+}
+
/// A single field of an enum variant or struct
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Field {
pub name: Name,
pub type_ref: Interned<TypeRef>,
pub visibility: RawVisibilityId,
+ pub ast_id: FieldAstId,
}
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs
index 7f2551e94..077a1b619 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs
@@ -184,7 +184,8 @@ impl<'a> Ctx<'a> {
let name = field.name()?.as_name();
let visibility = self.lower_visibility(field);
let type_ref = self.lower_type_ref_opt(field.ty());
- let res = Field { name, type_ref, visibility };
+ let ast_id = FieldAstId::Record(self.source_ast_id_map.ast_id(field));
+ let res = Field { name, type_ref, visibility, ast_id };
Some(res)
}
@@ -203,7 +204,8 @@ impl<'a> Ctx<'a> {
let name = Name::new_tuple_field(idx);
let visibility = self.lower_visibility(field);
let type_ref = self.lower_type_ref_opt(field.ty());
- Field { name, type_ref, visibility }
+ let ast_id = FieldAstId::Tuple(self.source_ast_id_map.ast_id(field));
+ Field { name, type_ref, visibility, ast_id }
}
fn lower_union(&mut self, union: &ast::Union) -> Option<FileItemTreeId<Union>> {
@@ -247,7 +249,8 @@ impl<'a> Ctx<'a> {
fn lower_variant(&mut self, variant: &ast::Variant) -> Option<Variant> {
let name = variant.name()?.as_name();
let fields = self.lower_fields(&variant.kind());
- let res = Variant { name, fields };
+ let ast_id = self.source_ast_id_map.ast_id(variant);
+ let res = Variant { name, fields, ast_id };
Some(res)
}
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/item_tree/pretty.rs b/src/tools/rust-analyzer/crates/hir-def/src/item_tree/pretty.rs
index 34dd817fd..da1643152 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/item_tree/pretty.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/item_tree/pretty.rs
@@ -115,7 +115,7 @@ impl<'a> Printer<'a> {
w!(self, "{{");
self.indented(|this| {
for field in fields.clone() {
- let Field { visibility, name, type_ref } = &this.tree[field];
+ let Field { visibility, name, type_ref, ast_id: _ } = &this.tree[field];
this.print_attrs_of(field);
this.print_visibility(*visibility);
w!(this, "{}: ", name);
@@ -129,7 +129,7 @@ impl<'a> Printer<'a> {
w!(self, "(");
self.indented(|this| {
for field in fields.clone() {
- let Field { visibility, name, type_ref } = &this.tree[field];
+ let Field { visibility, name, type_ref, ast_id: _ } = &this.tree[field];
this.print_attrs_of(field);
this.print_visibility(*visibility);
w!(this, "{}: ", name);
@@ -323,7 +323,7 @@ impl<'a> Printer<'a> {
self.print_where_clause_and_opening_brace(generic_params);
self.indented(|this| {
for variant in variants.clone() {
- let Variant { name, fields } = &this.tree[variant];
+ let Variant { name, fields, ast_id: _ } = &this.tree[variant];
this.print_attrs_of(variant);
w!(this, "{}", name);
this.print_fields(fields);
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/lib.rs b/src/tools/rust-analyzer/crates/hir-def/src/lib.rs
index 32ebfda4f..5c7aa7234 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/lib.rs
@@ -474,16 +474,24 @@ pub enum DefWithBodyId {
FunctionId(FunctionId),
StaticId(StaticId),
ConstId(ConstId),
+ VariantId(EnumVariantId),
}
impl_from!(FunctionId, ConstId, StaticId for DefWithBodyId);
+impl From<EnumVariantId> for DefWithBodyId {
+ fn from(id: EnumVariantId) -> Self {
+ DefWithBodyId::VariantId(id)
+ }
+}
+
impl DefWithBodyId {
pub fn as_generic_def_id(self) -> Option<GenericDefId> {
match self {
DefWithBodyId::FunctionId(f) => Some(f.into()),
DefWithBodyId::StaticId(_) => None,
DefWithBodyId::ConstId(c) => Some(c.into()),
+ DefWithBodyId::VariantId(c) => Some(c.into()),
}
}
}
@@ -681,6 +689,7 @@ impl HasModule for DefWithBodyId {
DefWithBodyId::FunctionId(it) => it.lookup(db).module(db),
DefWithBodyId::StaticId(it) => it.lookup(db).module(db),
DefWithBodyId::ConstId(it) => it.lookup(db).module(db),
+ DefWithBodyId::VariantId(it) => it.parent.lookup(db).container,
}
}
}
@@ -691,6 +700,7 @@ impl DefWithBodyId {
DefWithBodyId::FunctionId(it) => it.lookup(db).id.value.into(),
DefWithBodyId::StaticId(it) => it.lookup(db).id.value.into(),
DefWithBodyId::ConstId(it) => it.lookup(db).id.value.into(),
+ DefWithBodyId::VariantId(it) => it.parent.lookup(db).id.value.into(),
}
}
}
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs
index 6819e9114..fafcde25a 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs
@@ -12,11 +12,11 @@ fn test_copy_expand_simple() {
#[derive(Copy)]
struct Foo;
"#,
- expect![[r##"
+ expect![[r#"
#[derive(Copy)]
struct Foo;
-impl < > core::marker::Copy for Foo< > {}"##]],
+impl < > core::marker::Copy for Foo< > {}"#]],
);
}
@@ -33,7 +33,7 @@ macro Copy {}
#[derive(Copy)]
struct Foo;
"#,
- expect![[r##"
+ expect![[r#"
#[rustc_builtin_macro]
macro derive {}
#[rustc_builtin_macro]
@@ -41,7 +41,7 @@ macro Copy {}
#[derive(Copy)]
struct Foo;
-impl < > crate ::marker::Copy for Foo< > {}"##]],
+impl < > crate ::marker::Copy for Foo< > {}"#]],
);
}
@@ -53,11 +53,11 @@ fn test_copy_expand_with_type_params() {
#[derive(Copy)]
struct Foo<A, B>;
"#,
- expect![[r##"
+ expect![[r#"
#[derive(Copy)]
struct Foo<A, B>;
-impl <T0: core::marker::Copy, T1: core::marker::Copy> core::marker::Copy for Foo<T0, T1> {}"##]],
+impl <T0: core::marker::Copy, T1: core::marker::Copy, > core::marker::Copy for Foo<T0, T1, > {}"#]],
);
}
@@ -70,11 +70,11 @@ fn test_copy_expand_with_lifetimes() {
#[derive(Copy)]
struct Foo<A, B, 'a, 'b>;
"#,
- expect![[r##"
+ expect![[r#"
#[derive(Copy)]
struct Foo<A, B, 'a, 'b>;
-impl <T0: core::marker::Copy, T1: core::marker::Copy> core::marker::Copy for Foo<T0, T1> {}"##]],
+impl <T0: core::marker::Copy, T1: core::marker::Copy, > core::marker::Copy for Foo<T0, T1, > {}"#]],
);
}
@@ -86,10 +86,26 @@ fn test_clone_expand() {
#[derive(Clone)]
struct Foo<A, B>;
"#,
- expect![[r##"
+ expect![[r#"
#[derive(Clone)]
struct Foo<A, B>;
-impl <T0: core::clone::Clone, T1: core::clone::Clone> core::clone::Clone for Foo<T0, T1> {}"##]],
+impl <T0: core::clone::Clone, T1: core::clone::Clone, > core::clone::Clone for Foo<T0, T1, > {}"#]],
+ );
+}
+
+#[test]
+fn test_clone_expand_with_const_generics() {
+ check(
+ r#"
+//- minicore: derive, clone
+#[derive(Clone)]
+struct Foo<const X: usize, T>(u32);
+"#,
+ expect![[r#"
+#[derive(Clone)]
+struct Foo<const X: usize, T>(u32);
+
+impl <const T0: usize, T1: core::clone::Clone, > core::clone::Clone for Foo<T0, T1, > {}"#]],
);
}
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs
index 4f626105a..c04cd1651 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs
@@ -93,12 +93,12 @@ macro_rules! option_env {() => {}}
fn main() { option_env!("TEST_ENV_VAR"); }
"#,
- expect![[r##"
+ expect![[r#"
#[rustc_builtin_macro]
macro_rules! option_env {() => {}}
-fn main() { std::option::Option::None:: < &str>; }
-"##]],
+fn main() { $crate::option::Option::None:: < &str>; }
+"#]],
);
}
@@ -191,7 +191,7 @@ fn main() {
format_args!("{} {:?}", arg1(a, b, c), arg2);
}
"#,
- expect![[r##"
+ expect![[r#"
#[rustc_builtin_macro]
macro_rules! format_args {
($fmt:expr) => ({ /* compiler built-in */ });
@@ -199,9 +199,9 @@ macro_rules! format_args {
}
fn main() {
- std::fmt::Arguments::new_v1(&[], &[std::fmt::ArgumentV1::new(&(arg1(a, b, c)), std::fmt::Display::fmt), std::fmt::ArgumentV1::new(&(arg2), std::fmt::Display::fmt), ]);
+ $crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::ArgumentV1::new(&(arg1(a, b, c)), $crate::fmt::Display::fmt), $crate::fmt::ArgumentV1::new(&(arg2), $crate::fmt::Display::fmt), ]);
}
-"##]],
+"#]],
);
}
@@ -219,7 +219,7 @@ fn main() {
format_args!("{} {:?}", a::<A,B>(), b);
}
"#,
- expect![[r##"
+ expect![[r#"
#[rustc_builtin_macro]
macro_rules! format_args {
($fmt:expr) => ({ /* compiler built-in */ });
@@ -227,9 +227,9 @@ macro_rules! format_args {
}
fn main() {
- std::fmt::Arguments::new_v1(&[], &[std::fmt::ArgumentV1::new(&(a::<A, B>()), std::fmt::Display::fmt), std::fmt::ArgumentV1::new(&(b), std::fmt::Display::fmt), ]);
+ $crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::ArgumentV1::new(&(a::<A, B>()), $crate::fmt::Display::fmt), $crate::fmt::ArgumentV1::new(&(b), $crate::fmt::Display::fmt), ]);
}
-"##]],
+"#]],
);
}
@@ -248,7 +248,7 @@ fn main() {
format_args!/*+errors*/("{} {:?}", a.);
}
"#,
- expect![[r##"
+ expect![[r#"
#[rustc_builtin_macro]
macro_rules! format_args {
($fmt:expr) => ({ /* compiler built-in */ });
@@ -258,9 +258,9 @@ macro_rules! format_args {
fn main() {
let _ =
/* parse error: expected field name or number */
-std::fmt::Arguments::new_v1(&[], &[std::fmt::ArgumentV1::new(&(a.), std::fmt::Display::fmt), ]);
+$crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::ArgumentV1::new(&(a.), $crate::fmt::Display::fmt), ]);
}
-"##]],
+"#]],
);
}
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs
index 495bbe457..9ffc21881 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs
@@ -534,6 +534,7 @@ impl DefCollector<'_> {
match per_ns.types {
Some((ModuleDefId::ModuleId(m), _)) => {
self.def_map.prelude = Some(m);
+ break;
}
types => {
tracing::debug!(
@@ -2121,7 +2122,7 @@ impl ModCollector<'_, '_> {
fn emit_unconfigured_diagnostic(&mut self, item: ModItem, cfg: &CfgExpr) {
let ast_id = item.ast_id(self.item_tree);
- let ast_id = InFile::new(self.file_id(), ast_id);
+ let ast_id = InFile::new(self.file_id(), ast_id.upcast());
self.def_collector.def_map.diagnostics.push(DefDiagnostic::unconfigured_code(
self.module_id,
ast_id,
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/diagnostics.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/diagnostics.rs
index ed7e920fd..066142291 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/diagnostics.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/diagnostics.rs
@@ -4,7 +4,7 @@ use base_db::CrateId;
use cfg::{CfgExpr, CfgOptions};
use hir_expand::MacroCallKind;
use la_arena::Idx;
-use syntax::ast;
+use syntax::ast::{self, AnyHasAttrs};
use crate::{
attr::AttrId,
@@ -22,7 +22,7 @@ pub enum DefDiagnosticKind {
UnresolvedImport { id: ItemTreeId<item_tree::Import>, index: Idx<ast::UseTree> },
- UnconfiguredCode { ast: AstId<ast::Item>, cfg: CfgExpr, opts: CfgOptions },
+ UnconfiguredCode { ast: AstId<AnyHasAttrs>, cfg: CfgExpr, opts: CfgOptions },
UnresolvedProcMacro { ast: MacroCallKind, krate: CrateId },
@@ -75,7 +75,7 @@ impl DefDiagnostic {
pub fn unconfigured_code(
container: LocalModuleId,
- ast: AstId<ast::Item>,
+ ast: AstId<ast::AnyHasAttrs>,
cfg: CfgExpr,
opts: CfgOptions,
) -> Self {
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/resolver.rs b/src/tools/rust-analyzer/crates/hir-def/src/resolver.rs
index 8aa5973ca..070f68371 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/resolver.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/resolver.rs
@@ -839,6 +839,7 @@ impl HasResolver for DefWithBodyId {
DefWithBodyId::ConstId(c) => c.resolver(db),
DefWithBodyId::FunctionId(f) => f.resolver(db),
DefWithBodyId::StaticId(s) => s.resolver(db),
+ DefWithBodyId::VariantId(v) => v.parent.resolver(db),
}
}
}
diff --git a/src/tools/rust-analyzer/crates/hir-expand/Cargo.toml b/src/tools/rust-analyzer/crates/hir-expand/Cargo.toml
index dfd470ffc..3359c99b3 100644
--- a/src/tools/rust-analyzer/crates/hir-expand/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/hir-expand/Cargo.toml
@@ -15,11 +15,11 @@ tracing = "0.1.35"
either = "1.7.0"
rustc-hash = "1.1.0"
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
-itertools = "0.10.3"
+itertools = "0.10.5"
hashbrown = { version = "0.12.1", features = [
"inline-more",
], default-features = false }
-smallvec = { version = "1.9.0", features = ["const_new"] }
+smallvec = { version = "1.10.0", features = ["const_new"] }
stdx = { path = "../stdx", version = "0.0.0" }
base-db = { path = "../base-db", version = "0.0.0" }
diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/ast_id_map.rs b/src/tools/rust-analyzer/crates/hir-expand/src/ast_id_map.rs
index 11c0a6764..2b27db0e9 100644
--- a/src/tools/rust-analyzer/crates/hir-expand/src/ast_id_map.rs
+++ b/src/tools/rust-analyzer/crates/hir-expand/src/ast_id_map.rs
@@ -93,7 +93,12 @@ impl AstIdMap {
// trait does not change ids of top-level items, which helps caching.
bdfs(node, |it| {
let kind = it.kind();
- if ast::Item::can_cast(kind) || ast::BlockExpr::can_cast(kind) {
+ if ast::Item::can_cast(kind)
+ || ast::BlockExpr::can_cast(kind)
+ || ast::Variant::can_cast(kind)
+ || ast::RecordField::can_cast(kind)
+ || ast::TupleField::can_cast(kind)
+ {
res.alloc(&it);
true
} else {
diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/builtin_derive_macro.rs b/src/tools/rust-analyzer/crates/hir-expand/src/builtin_derive_macro.rs
index 79989bc2e..8966047c9 100644
--- a/src/tools/rust-analyzer/crates/hir-expand/src/builtin_derive_macro.rs
+++ b/src/tools/rust-analyzer/crates/hir-expand/src/builtin_derive_macro.rs
@@ -60,7 +60,8 @@ pub fn find_builtin_derive(ident: &name::Name) -> Option<BuiltinDeriveExpander>
struct BasicAdtInfo {
name: tt::Ident,
- type_or_const_params: usize,
+ /// `Some(ty)` if it's a const param of type `ty`, `None` if it's a type param.
+ param_types: Vec<Option<tt::Subtree>>,
}
fn parse_adt(tt: &tt::Subtree) -> Result<BasicAdtInfo, ExpandError> {
@@ -92,50 +93,22 @@ fn parse_adt(tt: &tt::Subtree) -> Result<BasicAdtInfo, ExpandError> {
let name_token_id =
token_map.token_by_range(name.syntax().text_range()).unwrap_or_else(TokenId::unspecified);
let name_token = tt::Ident { id: name_token_id, text: name.text().into() };
- let type_or_const_params =
- params.map_or(0, |type_param_list| type_param_list.type_or_const_params().count());
- Ok(BasicAdtInfo { name: name_token, type_or_const_params })
-}
-
-fn make_type_args(n: usize, bound: Vec<tt::TokenTree>) -> Vec<tt::TokenTree> {
- let mut result = Vec::<tt::TokenTree>::with_capacity(n * 2);
- result.push(
- tt::Leaf::Punct(tt::Punct {
- char: '<',
- spacing: tt::Spacing::Alone,
- id: tt::TokenId::unspecified(),
- })
- .into(),
- );
- for i in 0..n {
- if i > 0 {
- result.push(
- tt::Leaf::Punct(tt::Punct {
- char: ',',
- spacing: tt::Spacing::Alone,
- id: tt::TokenId::unspecified(),
- })
- .into(),
- );
- }
- result.push(
- tt::Leaf::Ident(tt::Ident {
- id: tt::TokenId::unspecified(),
- text: format!("T{}", i).into(),
- })
- .into(),
- );
- result.extend(bound.iter().cloned());
- }
- result.push(
- tt::Leaf::Punct(tt::Punct {
- char: '>',
- spacing: tt::Spacing::Alone,
- id: tt::TokenId::unspecified(),
+ let param_types = params
+ .into_iter()
+ .flat_map(|param_list| param_list.type_or_const_params())
+ .map(|param| {
+ if let ast::TypeOrConstParam::Const(param) = param {
+ let ty = param
+ .ty()
+ .map(|ty| mbe::syntax_node_to_token_tree(ty.syntax()).0)
+ .unwrap_or_default();
+ Some(ty)
+ } else {
+ None
+ }
})
- .into(),
- );
- result
+ .collect();
+ Ok(BasicAdtInfo { name: name_token, param_types })
}
fn expand_simple_derive(tt: &tt::Subtree, trait_path: tt::Subtree) -> ExpandResult<tt::Subtree> {
@@ -143,14 +116,27 @@ fn expand_simple_derive(tt: &tt::Subtree, trait_path: tt::Subtree) -> ExpandResu
Ok(info) => info,
Err(e) => return ExpandResult::only_err(e),
};
+ let (params, args): (Vec<_>, Vec<_>) = info
+ .param_types
+ .into_iter()
+ .enumerate()
+ .map(|(idx, param_ty)| {
+ let ident = tt::Leaf::Ident(tt::Ident {
+ id: tt::TokenId::unspecified(),
+ text: format!("T{idx}").into(),
+ });
+ let ident_ = ident.clone();
+ if let Some(ty) = param_ty {
+ (quote! { const #ident : #ty , }, quote! { #ident_ , })
+ } else {
+ let bound = trait_path.clone();
+ (quote! { #ident : #bound , }, quote! { #ident_ , })
+ }
+ })
+ .unzip();
let name = info.name;
- let trait_path_clone = trait_path.token_trees.clone();
- let bound = (quote! { : ##trait_path_clone }).token_trees;
- let type_params = make_type_args(info.type_or_const_params, bound);
- let type_args = make_type_args(info.type_or_const_params, Vec::new());
- let trait_path = trait_path.token_trees;
let expanded = quote! {
- impl ##type_params ##trait_path for #name ##type_args {}
+ impl < ##params > #trait_path for #name < ##args > {}
};
ExpandResult::ok(expanded)
}
diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/builtin_fn_macro.rs b/src/tools/rust-analyzer/crates/hir-expand/src/builtin_fn_macro.rs
index 8befa7f7d..7b19518e2 100644
--- a/src/tools/rust-analyzer/crates/hir-expand/src/builtin_fn_macro.rs
+++ b/src/tools/rust-analyzer/crates/hir-expand/src/builtin_fn_macro.rs
@@ -238,9 +238,9 @@ fn format_args_expand(
) -> ExpandResult<tt::Subtree> {
// We expand `format_args!("", a1, a2)` to
// ```
- // std::fmt::Arguments::new_v1(&[], &[
- // std::fmt::ArgumentV1::new(&arg1,std::fmt::Display::fmt),
- // std::fmt::ArgumentV1::new(&arg2,std::fmt::Display::fmt),
+ // $crate::fmt::Arguments::new_v1(&[], &[
+ // $crate::fmt::ArgumentV1::new(&arg1,$crate::fmt::Display::fmt),
+ // $crate::fmt::ArgumentV1::new(&arg2,$crate::fmt::Display::fmt),
// ])
// ```,
// which is still not really correct, but close enough for now
@@ -262,10 +262,10 @@ fn format_args_expand(
}
let _format_string = args.remove(0);
let arg_tts = args.into_iter().flat_map(|arg| {
- quote! { std::fmt::ArgumentV1::new(&(#arg), std::fmt::Display::fmt), }
+ quote! { #DOLLAR_CRATE::fmt::ArgumentV1::new(&(#arg), #DOLLAR_CRATE::fmt::Display::fmt), }
}.token_trees);
let expanded = quote! {
- std::fmt::Arguments::new_v1(&[], &[##arg_tts])
+ #DOLLAR_CRATE::fmt::Arguments::new_v1(&[], &[##arg_tts])
};
ExpandResult::ok(expanded)
}
@@ -675,8 +675,8 @@ fn option_env_expand(
};
let expanded = match get_env_inner(db, arg_id, &key) {
- None => quote! { std::option::Option::None::<&str> },
- Some(s) => quote! { std::option::Some(#s) },
+ None => quote! { #DOLLAR_CRATE::option::Option::None::<&str> },
+ Some(s) => quote! { #DOLLAR_CRATE::option::Some(#s) },
};
ExpandResult::ok(ExpandedEager::new(expanded))
diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/db.rs b/src/tools/rust-analyzer/crates/hir-expand/src/db.rs
index bc97ee15c..87e4db039 100644
--- a/src/tools/rust-analyzer/crates/hir-expand/src/db.rs
+++ b/src/tools/rust-analyzer/crates/hir-expand/src/db.rs
@@ -221,8 +221,16 @@ pub fn expand_speculative(
fixup::reverse_fixups(&mut speculative_expansion.value, &spec_args_tmap, &fixups.undo_info);
let (node, rev_tmap) = token_tree_to_syntax_node(&speculative_expansion.value, expand_to);
- let range = rev_tmap.first_range_by_token(token_id, token_to_map.kind())?;
- let token = node.syntax_node().covering_element(range).into_token()?;
+ let syntax_node = node.syntax_node();
+ let token = rev_tmap
+ .ranges_by_token(token_id, token_to_map.kind())
+ .filter_map(|range| syntax_node.covering_element(range).into_token())
+ .min_by_key(|t| {
+ // prefer tokens of the same kind and text
+ // Note the inversion of the score here, as we want to prefer the first token in case
+ // of all tokens having the same score
+ (t.kind() != token_to_map.kind()) as u8 + (t.text() != token_to_map.text()) as u8
+ })?;
Some((node.syntax_node(), token))
}
diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs b/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs
index fc128102f..a5b499fe8 100644
--- a/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/hir-expand/src/lib.rs
@@ -811,6 +811,31 @@ impl<'a> InFile<&'a SyntaxNode> {
_ => None,
}
}
+
+ pub fn original_syntax_node(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxNode>> {
+ // This kind of upmapping can only be achieved in attribute expanded files,
+ // as we don't have node inputs otherwise and therefor can't find an `N` node in the input
+ if !self.file_id.is_macro() {
+ return Some(self.map(Clone::clone));
+ } else if !self.file_id.is_attr_macro(db) {
+ return None;
+ }
+
+ if let Some(InFile { file_id, value: (first, last) }) = ascend_node_border_tokens(db, self)
+ {
+ if file_id.is_macro() {
+ let range = first.text_range().cover(last.text_range());
+ tracing::error!("Failed mapping out of macro file for {:?}", range);
+ return None;
+ }
+ // FIXME: This heuristic is brittle and with the right macro may select completely unrelated nodes
+ let anc = algo::least_common_ancestor(&first.parent()?, &last.parent()?)?;
+ let kind = self.value.kind();
+ let value = anc.ancestors().find(|it| it.kind() == kind)?;
+ return Some(InFile::new(file_id, value));
+ }
+ None
+ }
}
impl InFile<SyntaxToken> {
diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/name.rs b/src/tools/rust-analyzer/crates/hir-expand/src/name.rs
index 4ce21a579..2679a1c36 100644
--- a/src/tools/rust-analyzer/crates/hir-expand/src/name.rs
+++ b/src/tools/rust-analyzer/crates/hir-expand/src/name.rs
@@ -263,6 +263,7 @@ pub mod known {
Iterator,
IntoIterator,
Item,
+ IntoIter,
Try,
Ok,
Future,
diff --git a/src/tools/rust-analyzer/crates/hir-ty/Cargo.toml b/src/tools/rust-analyzer/crates/hir-ty/Cargo.toml
index 7f143f396..ed13275ba 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/hir-ty/Cargo.toml
@@ -11,18 +11,19 @@ doctest = false
[dependencies]
cov-mark = "2.0.0-pre.1"
-itertools = "0.10.3"
+itertools = "0.10.5"
arrayvec = "0.7.2"
-smallvec = "1.9.0"
+smallvec = "1.10.0"
ena = "0.14.0"
tracing = "0.1.35"
rustc-hash = "1.1.0"
scoped-tls = "1.0.0"
-chalk-solve = { version = "0.84.0", default-features = false }
-chalk-ir = "0.84.0"
-chalk-recursive = { version = "0.84.0", default-features = false }
+chalk-solve = { version = "0.86.0", default-features = false }
+chalk-ir = "0.86.0"
+chalk-recursive = { version = "0.86.0", default-features = false }
+chalk-derive = "0.86.0"
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
-once_cell = "1.12.0"
+once_cell = "1.15.0"
typed-arena = "2.0.1"
stdx = { path = "../stdx", version = "0.0.0" }
@@ -37,7 +38,7 @@ limit = { path = "../limit", version = "0.0.0" }
test-utils = { path = "../test-utils" }
expect-test = "1.4.0"
tracing = "0.1.35"
-tracing-subscriber = { version = "0.3.14", default-features = false, features = [
+tracing-subscriber = { version = "0.3.16", default-features = false, features = [
"env-filter",
"registry",
] }
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs b/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs
index 344036dd8..78911d8dc 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs
@@ -1,7 +1,7 @@
//! In certain situations, rust automatically inserts derefs as necessary: for
//! example, field accesses `foo.bar` still work when `foo` is actually a
//! reference to a type with the field `bar`. This is an approximation of the
-//! logic in rustc (which lives in librustc_typeck/check/autoderef.rs).
+//! logic in rustc (which lives in rustc_hir_analysis/check/autoderef.rs).
use std::sync::Arc;
@@ -123,13 +123,14 @@ fn deref_by_trait(table: &mut InferenceTable<'_>, ty: Ty) -> Option<Ty> {
let target = db.trait_data(deref_trait).associated_type_by_name(&name![Target])?;
let projection = {
- let b = TyBuilder::assoc_type_projection(db, target);
+ let b = TyBuilder::subst_for_def(db, deref_trait, None);
if b.remaining() != 1 {
// the Target type + Deref trait should only have one generic parameter,
// namely Deref's Self type
return None;
}
- b.push(ty).build()
+ let deref_subst = b.push(ty).build();
+ TyBuilder::assoc_type_projection(db, target, Some(deref_subst)).build()
};
// Check that the type implements Deref at all
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/builder.rs b/src/tools/rust-analyzer/crates/hir-ty/src/builder.rs
index 94d7806cb..9ae752556 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/builder.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/builder.rs
@@ -6,19 +6,19 @@ use chalk_ir::{
cast::{Cast, CastTo, Caster},
fold::TypeFoldable,
interner::HasInterner,
- AdtId, BoundVar, DebruijnIndex, Scalar,
+ AdtId, DebruijnIndex, Scalar,
};
use hir_def::{
- builtin_type::BuiltinType, generics::TypeOrConstParamData, ConstParamId, GenericDefId, TraitId,
- TypeAliasId,
+ builtin_type::BuiltinType, generics::TypeOrConstParamData, ConstParamId, DefWithBodyId,
+ GenericDefId, TraitId, TypeAliasId,
};
use smallvec::SmallVec;
use crate::{
consteval::unknown_const_as_generic, db::HirDatabase, infer::unify::InferenceTable, primitive,
- to_assoc_type_id, to_chalk_trait_id, utils::generics, Binders, CallableSig, ConstData,
- ConstValue, GenericArg, GenericArgData, Interner, ProjectionTy, Substitution, TraitRef, Ty,
- TyDefId, TyExt, TyKind, ValueTyDefId,
+ to_assoc_type_id, to_chalk_trait_id, utils::generics, Binders, BoundVar, CallableSig,
+ GenericArg, Interner, ProjectionTy, Substitution, TraitRef, Ty, TyDefId, TyExt, TyKind,
+ ValueTyDefId,
};
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -34,17 +34,32 @@ pub struct TyBuilder<D> {
data: D,
vec: SmallVec<[GenericArg; 2]>,
param_kinds: SmallVec<[ParamKind; 2]>,
+ parent_subst: Substitution,
}
impl<A> TyBuilder<A> {
fn with_data<B>(self, data: B) -> TyBuilder<B> {
- TyBuilder { data, param_kinds: self.param_kinds, vec: self.vec }
+ TyBuilder {
+ data,
+ vec: self.vec,
+ param_kinds: self.param_kinds,
+ parent_subst: self.parent_subst,
+ }
}
}
impl<D> TyBuilder<D> {
- fn new(data: D, param_kinds: SmallVec<[ParamKind; 2]>) -> TyBuilder<D> {
- TyBuilder { data, vec: SmallVec::with_capacity(param_kinds.len()), param_kinds }
+ fn new(
+ data: D,
+ param_kinds: SmallVec<[ParamKind; 2]>,
+ parent_subst: Option<Substitution>,
+ ) -> Self {
+ let parent_subst = parent_subst.unwrap_or_else(|| Substitution::empty(Interner));
+ Self { data, vec: SmallVec::with_capacity(param_kinds.len()), param_kinds, parent_subst }
+ }
+
+ fn new_empty(data: D) -> Self {
+ TyBuilder::new(data, SmallVec::new(), None)
}
fn build_internal(self) -> (D, Substitution) {
@@ -52,13 +67,18 @@ impl<D> TyBuilder<D> {
for (a, e) in self.vec.iter().zip(self.param_kinds.iter()) {
self.assert_match_kind(a, e);
}
- let subst = Substitution::from_iter(Interner, self.vec);
+ let subst = Substitution::from_iter(
+ Interner,
+ self.vec.into_iter().chain(self.parent_subst.iter(Interner).cloned()),
+ );
(self.data, subst)
}
pub fn push(mut self, arg: impl CastTo<GenericArg>) -> Self {
+ assert!(self.remaining() > 0);
let arg = arg.cast(Interner);
let expected_kind = &self.param_kinds[self.vec.len()];
+
let arg_kind = match arg.data(Interner) {
chalk_ir::GenericArgData::Ty(_) => ParamKind::Type,
chalk_ir::GenericArgData::Lifetime(_) => panic!("Got lifetime in TyBuilder::push"),
@@ -68,7 +88,9 @@ impl<D> TyBuilder<D> {
}
};
assert_eq!(*expected_kind, arg_kind);
+
self.vec.push(arg);
+
self
}
@@ -79,20 +101,12 @@ impl<D> TyBuilder<D> {
pub fn fill_with_bound_vars(self, debruijn: DebruijnIndex, starting_from: usize) -> Self {
// self.fill is inlined to make borrow checker happy
let mut this = self;
- let other = this.param_kinds.iter().skip(this.vec.len());
+ let other = &this.param_kinds[this.vec.len()..];
let filler = (starting_from..).zip(other).map(|(idx, kind)| match kind {
- ParamKind::Type => {
- GenericArgData::Ty(TyKind::BoundVar(BoundVar::new(debruijn, idx)).intern(Interner))
- .intern(Interner)
+ ParamKind::Type => BoundVar::new(debruijn, idx).to_ty(Interner).cast(Interner),
+ ParamKind::Const(ty) => {
+ BoundVar::new(debruijn, idx).to_const(Interner, ty.clone()).cast(Interner)
}
- ParamKind::Const(ty) => GenericArgData::Const(
- ConstData {
- value: ConstValue::BoundVar(BoundVar::new(debruijn, idx)),
- ty: ty.clone(),
- }
- .intern(Interner),
- )
- .intern(Interner),
});
this.vec.extend(filler.take(this.remaining()).casted(Interner));
assert_eq!(this.remaining(), 0);
@@ -102,8 +116,8 @@ impl<D> TyBuilder<D> {
pub fn fill_with_unknown(self) -> Self {
// self.fill is inlined to make borrow checker happy
let mut this = self;
- let filler = this.param_kinds.iter().skip(this.vec.len()).map(|x| match x {
- ParamKind::Type => GenericArgData::Ty(TyKind::Error.intern(Interner)).intern(Interner),
+ let filler = this.param_kinds[this.vec.len()..].iter().map(|x| match x {
+ ParamKind::Type => TyKind::Error.intern(Interner).cast(Interner),
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
});
this.vec.extend(filler.casted(Interner));
@@ -113,33 +127,17 @@ impl<D> TyBuilder<D> {
pub(crate) fn fill_with_inference_vars(self, table: &mut InferenceTable<'_>) -> Self {
self.fill(|x| match x {
- ParamKind::Type => GenericArgData::Ty(table.new_type_var()).intern(Interner),
- ParamKind::Const(ty) => {
- GenericArgData::Const(table.new_const_var(ty.clone())).intern(Interner)
- }
+ ParamKind::Type => table.new_type_var().cast(Interner),
+ ParamKind::Const(ty) => table.new_const_var(ty.clone()).cast(Interner),
})
}
pub fn fill(mut self, filler: impl FnMut(&ParamKind) -> GenericArg) -> Self {
- self.vec.extend(self.param_kinds.iter().skip(self.vec.len()).map(filler));
+ self.vec.extend(self.param_kinds[self.vec.len()..].iter().map(filler));
assert_eq!(self.remaining(), 0);
self
}
- pub fn use_parent_substs(mut self, parent_substs: &Substitution) -> Self {
- assert!(self.vec.is_empty());
- assert!(parent_substs.len(Interner) <= self.param_kinds.len());
- self.extend(parent_substs.iter(Interner).cloned());
- self
- }
-
- fn extend(&mut self, it: impl Iterator<Item = GenericArg> + Clone) {
- for x in it.clone().zip(self.param_kinds.iter().skip(self.vec.len())) {
- self.assert_match_kind(&x.0, &x.1);
- }
- self.vec.extend(it);
- }
-
fn assert_match_kind(&self, a: &chalk_ir::GenericArg<Interner>, e: &ParamKind) {
match (a.data(Interner), e) {
(chalk_ir::GenericArgData::Ty(_), ParamKind::Type)
@@ -188,21 +186,42 @@ impl TyBuilder<()> {
params.placeholder_subst(db)
}
- pub fn subst_for_def(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> TyBuilder<()> {
- let def = def.into();
- let params = generics(db.upcast(), def);
- TyBuilder::new(
- (),
- params
- .iter()
- .map(|(id, data)| match data {
- TypeOrConstParamData::TypeParamData(_) => ParamKind::Type,
- TypeOrConstParamData::ConstParamData(_) => {
- ParamKind::Const(db.const_param_ty(ConstParamId::from_unchecked(id)))
- }
- })
- .collect(),
- )
+ pub fn subst_for_def(
+ db: &dyn HirDatabase,
+ def: impl Into<GenericDefId>,
+ parent_subst: Option<Substitution>,
+ ) -> TyBuilder<()> {
+ let generics = generics(db.upcast(), def.into());
+ assert!(generics.parent_generics().is_some() == parent_subst.is_some());
+ let params = generics
+ .iter_self()
+ .map(|(id, data)| match data {
+ TypeOrConstParamData::TypeParamData(_) => ParamKind::Type,
+ TypeOrConstParamData::ConstParamData(_) => {
+ ParamKind::Const(db.const_param_ty(ConstParamId::from_unchecked(id)))
+ }
+ })
+ .collect();
+ TyBuilder::new((), params, parent_subst)
+ }
+
+ /// Creates a `TyBuilder` to build `Substitution` for a generator defined in `parent`.
+ ///
+ /// A generator's substitution consists of:
+ /// - resume type of generator
+ /// - yield type of generator ([`Generator::Yield`](std::ops::Generator::Yield))
+ /// - return type of generator ([`Generator::Return`](std::ops::Generator::Return))
+ /// - generic parameters in scope on `parent`
+ /// in this order.
+ ///
+ /// This method prepopulates the builder with placeholder substitution of `parent`, so you
+ /// should only push exactly 3 `GenericArg`s before building.
+ pub fn subst_for_generator(db: &dyn HirDatabase, parent: DefWithBodyId) -> TyBuilder<()> {
+ let parent_subst =
+ parent.as_generic_def_id().map(|p| generics(db.upcast(), p).placeholder_subst(db));
+ // These represent resume type, yield type, and return type of generator.
+ let params = std::iter::repeat(ParamKind::Type).take(3).collect();
+ TyBuilder::new((), params, parent_subst)
}
pub fn build(self) -> Substitution {
@@ -213,7 +232,7 @@ impl TyBuilder<()> {
impl TyBuilder<hir_def::AdtId> {
pub fn adt(db: &dyn HirDatabase, def: hir_def::AdtId) -> TyBuilder<hir_def::AdtId> {
- TyBuilder::subst_for_def(db, def).with_data(def)
+ TyBuilder::subst_for_def(db, def, None).with_data(def)
}
pub fn fill_with_defaults(
@@ -221,16 +240,27 @@ impl TyBuilder<hir_def::AdtId> {
db: &dyn HirDatabase,
mut fallback: impl FnMut() -> Ty,
) -> Self {
+ // Note that we're building ADT, so we never have parent generic parameters.
let defaults = db.generic_defaults(self.data.into());
+ let dummy_ty = TyKind::Error.intern(Interner).cast(Interner);
for default_ty in defaults.iter().skip(self.vec.len()) {
- if let GenericArgData::Ty(x) = default_ty.skip_binders().data(Interner) {
+ // NOTE(skip_binders): we only check if the arg type is error type.
+ if let Some(x) = default_ty.skip_binders().ty(Interner) {
if x.is_unknown() {
self.vec.push(fallback().cast(Interner));
continue;
}
- };
- // each default can depend on the previous parameters
- let subst_so_far = Substitution::from_iter(Interner, self.vec.clone());
+ }
+ // Each default can only depend on the previous parameters.
+ // FIXME: we don't handle const generics here.
+ let subst_so_far = Substitution::from_iter(
+ Interner,
+ self.vec
+ .iter()
+ .cloned()
+ .chain(iter::repeat(dummy_ty.clone()))
+ .take(self.param_kinds.len()),
+ );
self.vec.push(default_ty.clone().substitute(Interner, &subst_so_far).cast(Interner));
}
self
@@ -245,7 +275,7 @@ impl TyBuilder<hir_def::AdtId> {
pub struct Tuple(usize);
impl TyBuilder<Tuple> {
pub fn tuple(size: usize) -> TyBuilder<Tuple> {
- TyBuilder::new(Tuple(size), iter::repeat(ParamKind::Type).take(size).collect())
+ TyBuilder::new(Tuple(size), iter::repeat(ParamKind::Type).take(size).collect(), None)
}
pub fn build(self) -> Ty {
@@ -256,7 +286,7 @@ impl TyBuilder<Tuple> {
impl TyBuilder<TraitId> {
pub fn trait_ref(db: &dyn HirDatabase, def: TraitId) -> TyBuilder<TraitId> {
- TyBuilder::subst_for_def(db, def).with_data(def)
+ TyBuilder::subst_for_def(db, def, None).with_data(def)
}
pub fn build(self) -> TraitRef {
@@ -266,8 +296,12 @@ impl TyBuilder<TraitId> {
}
impl TyBuilder<TypeAliasId> {
- pub fn assoc_type_projection(db: &dyn HirDatabase, def: TypeAliasId) -> TyBuilder<TypeAliasId> {
- TyBuilder::subst_for_def(db, def).with_data(def)
+ pub fn assoc_type_projection(
+ db: &dyn HirDatabase,
+ def: TypeAliasId,
+ parent_subst: Option<Substitution>,
+ ) -> TyBuilder<TypeAliasId> {
+ TyBuilder::subst_for_def(db, def, parent_subst).with_data(def)
}
pub fn build(self) -> ProjectionTy {
@@ -277,19 +311,6 @@ impl TyBuilder<TypeAliasId> {
}
impl<T: HasInterner<Interner = Interner> + TypeFoldable<Interner>> TyBuilder<Binders<T>> {
- fn subst_binders(b: Binders<T>) -> Self {
- let param_kinds = b
- .binders
- .iter(Interner)
- .map(|x| match x {
- chalk_ir::VariableKind::Ty(_) => ParamKind::Type,
- chalk_ir::VariableKind::Lifetime => panic!("Got lifetime parameter"),
- chalk_ir::VariableKind::Const(ty) => ParamKind::Const(ty.clone()),
- })
- .collect();
- TyBuilder::new(b, param_kinds)
- }
-
pub fn build(self) -> T {
let (b, subst) = self.build_internal();
b.substitute(Interner, &subst)
@@ -297,15 +318,41 @@ impl<T: HasInterner<Interner = Interner> + TypeFoldable<Interner>> TyBuilder<Bin
}
impl TyBuilder<Binders<Ty>> {
- pub fn def_ty(db: &dyn HirDatabase, def: TyDefId) -> TyBuilder<Binders<Ty>> {
- TyBuilder::subst_binders(db.ty(def))
+ pub fn def_ty(
+ db: &dyn HirDatabase,
+ def: TyDefId,
+ parent_subst: Option<Substitution>,
+ ) -> TyBuilder<Binders<Ty>> {
+ let poly_ty = db.ty(def);
+ let id: GenericDefId = match def {
+ TyDefId::BuiltinType(_) => {
+ assert!(parent_subst.is_none());
+ return TyBuilder::new_empty(poly_ty);
+ }
+ TyDefId::AdtId(id) => id.into(),
+ TyDefId::TypeAliasId(id) => id.into(),
+ };
+ TyBuilder::subst_for_def(db, id, parent_subst).with_data(poly_ty)
}
pub fn impl_self_ty(db: &dyn HirDatabase, def: hir_def::ImplId) -> TyBuilder<Binders<Ty>> {
- TyBuilder::subst_binders(db.impl_self_ty(def))
+ TyBuilder::subst_for_def(db, def, None).with_data(db.impl_self_ty(def))
}
- pub fn value_ty(db: &dyn HirDatabase, def: ValueTyDefId) -> TyBuilder<Binders<Ty>> {
- TyBuilder::subst_binders(db.value_ty(def))
+ pub fn value_ty(
+ db: &dyn HirDatabase,
+ def: ValueTyDefId,
+ parent_subst: Option<Substitution>,
+ ) -> TyBuilder<Binders<Ty>> {
+ let poly_value_ty = db.value_ty(def);
+ let id = match def.to_generic_def_id() {
+ Some(id) => id,
+ None => {
+ // static items
+ assert!(parent_subst.is_none());
+ return TyBuilder::new_empty(poly_value_ty);
+ }
+ };
+ TyBuilder::subst_for_def(db, id, parent_subst).with_data(poly_value_ty)
}
}
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs b/src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs
index faec99c7d..43c3451ca 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs
@@ -11,6 +11,7 @@ use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
use base_db::CrateId;
use hir_def::{
+ expr::Movability,
lang_item::{lang_attr, LangItemTarget},
AssocItemId, GenericDefId, HasModule, ItemContainerId, Lookup, ModuleId, TypeAliasId,
};
@@ -26,9 +27,9 @@ use crate::{
to_assoc_type_id, to_chalk_trait_id,
traits::ChalkContext,
utils::generics,
- AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, Interner, ProjectionTy,
- ProjectionTyExt, QuantifiedWhereClause, Substitution, TraitRef, TraitRefExt, Ty, TyBuilder,
- TyExt, TyKind, WhereClause,
+ wrap_empty_binders, AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId,
+ Interner, ProjectionTy, ProjectionTyExt, QuantifiedWhereClause, Substitution, TraitRef,
+ TraitRefExt, Ty, TyBuilder, TyExt, TyKind, WhereClause,
};
pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>;
@@ -372,17 +373,62 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
}
fn generator_datum(
&self,
- _: chalk_ir::GeneratorId<Interner>,
+ id: chalk_ir::GeneratorId<Interner>,
) -> std::sync::Arc<chalk_solve::rust_ir::GeneratorDatum<Interner>> {
- // FIXME
- unimplemented!()
+ let (parent, expr) = self.db.lookup_intern_generator(id.into());
+
+ // We fill substitution with unknown type, because we only need to know whether the generic
+ // params are types or consts to build `Binders` and those being filled up are for
+ // `resume_type`, `yield_type`, and `return_type` of the generator in question.
+ let subst = TyBuilder::subst_for_generator(self.db, parent).fill_with_unknown().build();
+
+ let input_output = rust_ir::GeneratorInputOutputDatum {
+ resume_type: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
+ .intern(Interner),
+ yield_type: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 1))
+ .intern(Interner),
+ return_type: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 2))
+ .intern(Interner),
+ // FIXME: calculate upvars
+ upvars: vec![],
+ };
+
+ let it = subst
+ .iter(Interner)
+ .map(|it| it.constant(Interner).map(|c| c.data(Interner).ty.clone()));
+ let input_output = crate::make_type_and_const_binders(it, input_output);
+
+ let movability = match self.db.body(parent)[expr] {
+ hir_def::expr::Expr::Closure {
+ closure_kind: hir_def::expr::ClosureKind::Generator(movability),
+ ..
+ } => movability,
+ _ => unreachable!("non generator expression interned as generator"),
+ };
+ let movability = match movability {
+ Movability::Static => rust_ir::Movability::Static,
+ Movability::Movable => rust_ir::Movability::Movable,
+ };
+
+ Arc::new(rust_ir::GeneratorDatum { movability, input_output })
}
fn generator_witness_datum(
&self,
- _: chalk_ir::GeneratorId<Interner>,
+ id: chalk_ir::GeneratorId<Interner>,
) -> std::sync::Arc<chalk_solve::rust_ir::GeneratorWitnessDatum<Interner>> {
- // FIXME
- unimplemented!()
+ // FIXME: calculate inner types
+ let inner_types =
+ rust_ir::GeneratorWitnessExistential { types: wrap_empty_binders(vec![]) };
+
+ let (parent, _) = self.db.lookup_intern_generator(id.into());
+ // See the comment in `generator_datum()` for unknown types.
+ let subst = TyBuilder::subst_for_generator(self.db, parent).fill_with_unknown().build();
+ let it = subst
+ .iter(Interner)
+ .map(|it| it.constant(Interner).map(|c| c.data(Interner).ty.clone()));
+ let inner_types = crate::make_type_and_const_binders(it, inner_types);
+
+ Arc::new(rust_ir::GeneratorWitnessDatum { inner_types })
}
fn unification_database(&self) -> &dyn chalk_ir::UnificationDatabase<Interner> {
@@ -429,10 +475,15 @@ pub(crate) fn associated_ty_data_query(
let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast());
let ctx = crate::TyLoweringContext::new(db, &resolver)
.with_type_param_mode(crate::lower::ParamLoweringMode::Variable);
- let pro_ty = TyBuilder::assoc_type_projection(db, type_alias)
+
+ let trait_subst = TyBuilder::subst_for_def(db, trait_, None)
+ .fill_with_bound_vars(crate::DebruijnIndex::INNERMOST, generic_params.len_self())
+ .build();
+ let pro_ty = TyBuilder::assoc_type_projection(db, type_alias, Some(trait_subst))
.fill_with_bound_vars(crate::DebruijnIndex::INNERMOST, 0)
.build();
let self_ty = TyKind::Alias(AliasTy::Projection(pro_ty)).intern(Interner);
+
let mut bounds: Vec<_> = type_alias_data
.bounds
.iter()
@@ -772,10 +823,10 @@ pub(super) fn generic_predicate_to_inline_bound(
Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound)))
}
WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
- if projection_ty.self_type_parameter(Interner) != self_ty_shifted_in {
+ let trait_ = projection_ty.trait_(db);
+ if projection_ty.self_type_parameter(db) != self_ty_shifted_in {
return None;
}
- let trait_ = projection_ty.trait_(db);
let args_no_self = projection_ty.substitution.as_slice(Interner)[1..]
.iter()
.map(|ty| ty.clone().cast(Interner))
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/chalk_ext.rs b/src/tools/rust-analyzer/crates/hir-ty/src/chalk_ext.rs
index 4a5533c64..e2099d7e5 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/chalk_ext.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/chalk_ext.rs
@@ -152,7 +152,7 @@ impl TyExt for Ty {
TyKind::FnDef(def, parameters) => {
let callable_def = db.lookup_intern_callable_def((*def).into());
let sig = db.callable_item_signature(callable_def);
- Some(sig.substitute(Interner, &parameters))
+ Some(sig.substitute(Interner, parameters))
}
TyKind::Closure(.., substs) => {
let sig_param = substs.at(Interner, 0).assert_ty_ref(Interner);
@@ -166,6 +166,8 @@ impl TyExt for Ty {
let trait_ref = match self.kind(Interner) {
// The principal trait bound should be the first element of the bounds. This is an
// invariant ensured by `TyLoweringContext::lower_dyn_trait()`.
+ // FIXME: dyn types may not have principal trait and we don't want to return auto trait
+ // here.
TyKind::Dyn(dyn_ty) => dyn_ty.bounds.skip_binders().interned().get(0).and_then(|b| {
match b.skip_binders() {
WhereClause::Implemented(trait_ref) => Some(trait_ref),
@@ -260,7 +262,7 @@ impl TyExt for Ty {
WhereClause::AliasEq(AliasEq {
alias: AliasTy::Projection(proj),
ty: _,
- }) => &proj.self_type_parameter(Interner) == self,
+ }) => &proj.self_type_parameter(db) == self,
_ => false,
})
.collect::<Vec<_>>();
@@ -331,6 +333,7 @@ impl TyExt for Ty {
pub trait ProjectionTyExt {
fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef;
fn trait_(&self, db: &dyn HirDatabase) -> TraitId;
+ fn self_type_parameter(&self, db: &dyn HirDatabase) -> Ty;
}
impl ProjectionTyExt for ProjectionTy {
@@ -347,6 +350,10 @@ impl ProjectionTyExt for ProjectionTy {
_ => panic!("projection ty without parent trait"),
}
}
+
+ fn self_type_parameter(&self, db: &dyn HirDatabase) -> Ty {
+ self.trait_ref(db).self_type_parameter(Interner)
+ }
}
pub trait TraitRefExt {
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs b/src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs
index 6ecb6e6fd..2c0c6e0b8 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs
@@ -7,14 +7,17 @@ use std::{
use chalk_ir::{BoundVar, DebruijnIndex, GenericArgData, IntTy, Scalar};
use hir_def::{
+ builtin_type::BuiltinInt,
expr::{ArithOp, BinaryOp, Expr, ExprId, Literal, Pat, PatId},
path::ModPath,
resolver::{resolver_for_expr, ResolveValueResult, Resolver, ValueNs},
+ src::HasChildSource,
type_ref::ConstScalar,
- ConstId, DefWithBodyId,
+ ConstId, DefWithBodyId, EnumVariantId, Lookup,
};
-use la_arena::{Arena, Idx};
+use la_arena::{Arena, Idx, RawIdx};
use stdx::never;
+use syntax::ast::HasName;
use crate::{
db::HirDatabase, infer::InferenceContext, lower::ParamLoweringMode, to_placeholder_idx,
@@ -77,6 +80,7 @@ pub enum ConstEvalError {
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ComputedExpr {
Literal(Literal),
+ Enum(String, EnumVariantId, Literal),
Tuple(Box<[ComputedExpr]>),
}
@@ -104,6 +108,7 @@ impl Display for ComputedExpr {
Literal::String(x) => std::fmt::Debug::fmt(x, f),
Literal::ByteString(x) => std::fmt::Debug::fmt(x, f),
},
+ ComputedExpr::Enum(name, _, _) => name.fmt(f),
ComputedExpr::Tuple(t) => {
f.write_char('(')?;
for x in &**t {
@@ -148,13 +153,51 @@ fn is_valid(scalar: &Scalar, value: i128) -> bool {
}
}
+fn get_name(ctx: &mut ConstEvalCtx<'_>, variant: EnumVariantId) -> String {
+ let loc = variant.parent.lookup(ctx.db.upcast());
+ let children = variant.parent.child_source(ctx.db.upcast());
+ let item_tree = loc.id.item_tree(ctx.db.upcast());
+
+ let variant_name = children.value[variant.local_id].name();
+ let enum_name = item_tree[loc.id.value].name.to_string();
+ enum_name + "::" + &variant_name.unwrap().to_string()
+}
+
pub fn eval_const(
expr_id: ExprId,
ctx: &mut ConstEvalCtx<'_>,
) -> Result<ComputedExpr, ConstEvalError> {
+ let u128_to_i128 = |it: u128| -> Result<i128, ConstEvalError> {
+ it.try_into().map_err(|_| ConstEvalError::NotSupported("u128 is too big"))
+ };
+
let expr = &ctx.exprs[expr_id];
match expr {
- Expr::Missing => Err(ConstEvalError::IncompleteExpr),
+ Expr::Missing => match ctx.owner {
+ // evaluate the implicit variant index of an enum variant without expression
+ // FIXME: This should return the type of the enum representation
+ DefWithBodyId::VariantId(variant) => {
+ let prev_idx: u32 = variant.local_id.into_raw().into();
+ let prev_idx = prev_idx.checked_sub(1).map(RawIdx::from).map(Idx::from_raw);
+ let value = match prev_idx {
+ Some(local_id) => {
+ let prev_variant = EnumVariantId { local_id, parent: variant.parent };
+ 1 + match ctx.db.const_eval_variant(prev_variant)? {
+ ComputedExpr::Literal(Literal::Int(v, _)) => v,
+ ComputedExpr::Literal(Literal::Uint(v, _)) => u128_to_i128(v)?,
+ _ => {
+ return Err(ConstEvalError::NotSupported(
+ "Enum can't contain this kind of value",
+ ))
+ }
+ }
+ }
+ _ => 0,
+ };
+ Ok(ComputedExpr::Literal(Literal::Int(value, Some(BuiltinInt::I128))))
+ }
+ _ => Err(ConstEvalError::IncompleteExpr),
+ },
Expr::Literal(l) => Ok(ComputedExpr::Literal(l.clone())),
&Expr::UnaryOp { expr, op } => {
let ty = &ctx.expr_ty(expr);
@@ -167,9 +210,7 @@ pub fn eval_const(
return Ok(ComputedExpr::Literal(Literal::Bool(!b)))
}
ComputedExpr::Literal(Literal::Int(v, _)) => v,
- ComputedExpr::Literal(Literal::Uint(v, _)) => v
- .try_into()
- .map_err(|_| ConstEvalError::NotSupported("too big u128"))?,
+ ComputedExpr::Literal(Literal::Uint(v, _)) => u128_to_i128(v)?,
_ => return Err(ConstEvalError::NotSupported("this kind of operator")),
};
let r = match ty.kind(Interner) {
@@ -198,9 +239,7 @@ pub fn eval_const(
hir_def::expr::UnaryOp::Neg => {
let v = match ev {
ComputedExpr::Literal(Literal::Int(v, _)) => v,
- ComputedExpr::Literal(Literal::Uint(v, _)) => v
- .try_into()
- .map_err(|_| ConstEvalError::NotSupported("too big u128"))?,
+ ComputedExpr::Literal(Literal::Uint(v, _)) => u128_to_i128(v)?,
_ => return Err(ConstEvalError::NotSupported("this kind of operator")),
};
Ok(ComputedExpr::Literal(Literal::Int(
@@ -219,16 +258,12 @@ pub fn eval_const(
let op = op.ok_or(ConstEvalError::IncompleteExpr)?;
let v1 = match lhs {
ComputedExpr::Literal(Literal::Int(v, _)) => v,
- ComputedExpr::Literal(Literal::Uint(v, _)) => {
- v.try_into().map_err(|_| ConstEvalError::NotSupported("too big u128"))?
- }
+ ComputedExpr::Literal(Literal::Uint(v, _)) => u128_to_i128(v)?,
_ => return Err(ConstEvalError::NotSupported("this kind of operator")),
};
let v2 = match rhs {
ComputedExpr::Literal(Literal::Int(v, _)) => v,
- ComputedExpr::Literal(Literal::Uint(v, _)) => {
- v.try_into().map_err(|_| ConstEvalError::NotSupported("too big u128"))?
- }
+ ComputedExpr::Literal(Literal::Uint(v, _)) => u128_to_i128(v)?,
_ => return Err(ConstEvalError::NotSupported("this kind of operator")),
};
match op {
@@ -339,9 +374,22 @@ pub fn eval_const(
ValueNs::GenericParam(_) => {
Err(ConstEvalError::NotSupported("const generic without substitution"))
}
+ ValueNs::EnumVariantId(id) => match ctx.db.const_eval_variant(id)? {
+ ComputedExpr::Literal(lit) => {
+ Ok(ComputedExpr::Enum(get_name(ctx, id), id, lit))
+ }
+ _ => Err(ConstEvalError::NotSupported(
+ "Enums can't evalute to anything but numbers",
+ )),
+ },
_ => Err(ConstEvalError::NotSupported("path that are not const or local")),
}
}
+ // FIXME: Handle the cast target
+ &Expr::Cast { expr, .. } => match eval_const(expr, ctx)? {
+ ComputedExpr::Enum(_, _, lit) => Ok(ComputedExpr::Literal(lit)),
+ _ => Err(ConstEvalError::NotSupported("Can't cast these types")),
+ },
_ => Err(ConstEvalError::NotSupported("This kind of expression")),
}
}
@@ -412,7 +460,15 @@ pub(crate) fn const_eval_recover(
Err(ConstEvalError::Loop)
}
-pub(crate) fn const_eval_query(
+pub(crate) fn const_eval_variant_recover(
+ _: &dyn HirDatabase,
+ _: &[String],
+ _: &EnumVariantId,
+) -> Result<ComputedExpr, ConstEvalError> {
+ Err(ConstEvalError::Loop)
+}
+
+pub(crate) fn const_eval_variant_query(
db: &dyn HirDatabase,
const_id: ConstId,
) -> Result<ComputedExpr, ConstEvalError> {
@@ -433,6 +489,26 @@ pub(crate) fn const_eval_query(
result
}
+pub(crate) fn const_eval_query_variant(
+ db: &dyn HirDatabase,
+ variant_id: EnumVariantId,
+) -> Result<ComputedExpr, ConstEvalError> {
+ let def = variant_id.into();
+ let body = db.body(def);
+ let infer = &db.infer(def);
+ eval_const(
+ body.body_expr,
+ &mut ConstEvalCtx {
+ db,
+ owner: def,
+ exprs: &body.exprs,
+ pats: &body.pats,
+ local_data: HashMap::default(),
+ infer,
+ },
+ )
+}
+
pub(crate) fn eval_to_const<'a>(
expr: Idx<Expr>,
mode: ParamLoweringMode,
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests.rs b/src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests.rs
index 4a052851a..b76506f6e 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests.rs
@@ -88,6 +88,49 @@ fn consts() {
}
#[test]
+fn enums() {
+ check_number(
+ r#"
+ enum E {
+ F1 = 1,
+ F2 = 2 * E::F1 as u8,
+ F3 = 3 * E::F2 as u8,
+ }
+ const GOAL: i32 = E::F3 as u8;
+ "#,
+ 6,
+ );
+ check_number(
+ r#"
+ enum E { F1 = 1, F2, }
+ const GOAL: i32 = E::F2 as u8;
+ "#,
+ 2,
+ );
+ check_number(
+ r#"
+ enum E { F1, }
+ const GOAL: i32 = E::F1 as u8;
+ "#,
+ 0,
+ );
+ let r = eval_goal(
+ r#"
+ enum E { A = 1, }
+ const GOAL: E = E::A;
+ "#,
+ )
+ .unwrap();
+ match r {
+ ComputedExpr::Enum(name, _, Literal::Uint(val, _)) => {
+ assert_eq!(name, "E::A");
+ assert_eq!(val, 1);
+ }
+ x => panic!("Expected enum but found {:?}", x),
+ }
+}
+
+#[test]
fn const_loop() {
check_fail(
r#"
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/db.rs b/src/tools/rust-analyzer/crates/hir-ty/src/db.rs
index b385b1caf..932fce835 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/db.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/db.rs
@@ -6,8 +6,8 @@ use std::sync::Arc;
use arrayvec::ArrayVec;
use base_db::{impl_intern_key, salsa, CrateId, Upcast};
use hir_def::{
- db::DefDatabase, expr::ExprId, BlockId, ConstId, ConstParamId, DefWithBodyId, FunctionId,
- GenericDefId, ImplId, LifetimeParamId, LocalFieldId, TypeOrConstParamId, VariantId,
+ db::DefDatabase, expr::ExprId, BlockId, ConstId, ConstParamId, DefWithBodyId, EnumVariantId,
+ FunctionId, GenericDefId, ImplId, LifetimeParamId, LocalFieldId, TypeOrConstParamId, VariantId,
};
use la_arena::ArenaMap;
@@ -43,10 +43,14 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
#[salsa::invoke(crate::lower::const_param_ty_query)]
fn const_param_ty(&self, def: ConstParamId) -> Ty;
- #[salsa::invoke(crate::consteval::const_eval_query)]
+ #[salsa::invoke(crate::consteval::const_eval_variant_query)]
#[salsa::cycle(crate::consteval::const_eval_recover)]
fn const_eval(&self, def: ConstId) -> Result<ComputedExpr, ConstEvalError>;
+ #[salsa::invoke(crate::consteval::const_eval_query_variant)]
+ #[salsa::cycle(crate::consteval::const_eval_variant_recover)]
+ fn const_eval_variant(&self, def: EnumVariantId) -> Result<ComputedExpr, ConstEvalError>;
+
#[salsa::invoke(crate::lower::impl_trait_query)]
fn impl_trait(&self, def: ImplId) -> Option<Binders<TraitRef>>;
@@ -116,6 +120,8 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
fn intern_impl_trait_id(&self, id: ImplTraitId) -> InternedOpaqueTyId;
#[salsa::interned]
fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
+ #[salsa::interned]
+ fn intern_generator(&self, id: (DefWithBodyId, ExprId)) -> InternedGeneratorId;
#[salsa::invoke(chalk_db::associated_ty_data_query)]
fn associated_ty_data(&self, id: chalk_db::AssocTypeId) -> Arc<chalk_db::AssociatedTyDatum>;
@@ -150,6 +156,14 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
id: chalk_db::AssociatedTyValueId,
) -> Arc<chalk_db::AssociatedTyValue>;
+ #[salsa::invoke(crate::traits::normalize_projection_query)]
+ #[salsa::transparent]
+ fn normalize_projection(
+ &self,
+ projection: crate::ProjectionTy,
+ env: Arc<crate::TraitEnvironment>,
+ ) -> Ty;
+
#[salsa::invoke(trait_solve_wait)]
#[salsa::transparent]
fn trait_solve(
@@ -180,6 +194,9 @@ fn infer_wait(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult>
DefWithBodyId::ConstId(it) => {
db.const_data(it).name.clone().unwrap_or_else(Name::missing).to_string()
}
+ DefWithBodyId::VariantId(it) => {
+ db.enum_data(it.parent).variants[it.local_id].name.to_string()
+ }
});
db.infer_query(def)
}
@@ -218,6 +235,10 @@ impl_intern_key!(InternedOpaqueTyId);
pub struct InternedClosureId(salsa::InternId);
impl_intern_key!(InternedClosureId);
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+pub struct InternedGeneratorId(salsa::InternId);
+impl_intern_key!(InternedGeneratorId);
+
/// This exists just for Chalk, because Chalk just has a single `FnDefId` where
/// we have different IDs for struct and enum variant constructors.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/unsafe_check.rs b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/unsafe_check.rs
index 161b19a73..431ab949b 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/unsafe_check.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/unsafe_check.rs
@@ -18,7 +18,9 @@ pub fn missing_unsafe(db: &dyn HirDatabase, def: DefWithBodyId) -> Vec<ExprId> {
let is_unsafe = match def {
DefWithBodyId::FunctionId(it) => db.function_data(it).has_unsafe_kw(),
- DefWithBodyId::StaticId(_) | DefWithBodyId::ConstId(_) => false,
+ DefWithBodyId::StaticId(_) | DefWithBodyId::ConstId(_) | DefWithBodyId::VariantId(_) => {
+ false
+ }
};
if is_unsafe {
return res;
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs
index d2f9c2b8b..0221f922f 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs
@@ -20,13 +20,14 @@ use hir_def::{
};
use hir_expand::{hygiene::Hygiene, name::Name};
use itertools::Itertools;
+use smallvec::SmallVec;
use syntax::SmolStr;
use crate::{
db::HirDatabase,
from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, lt_from_placeholder_idx,
mapping::from_chalk,
- primitive, subst_prefix, to_assoc_type_id,
+ primitive, to_assoc_type_id,
utils::{self, generics},
AdtId, AliasEq, AliasTy, Binders, CallableDefId, CallableSig, Const, ConstValue, DomainGoal,
GenericArg, ImplTraitId, Interner, Lifetime, LifetimeData, LifetimeOutlives, Mutability,
@@ -221,6 +222,7 @@ pub enum DisplaySourceCodeError {
PathNotFound,
UnknownType,
Closure,
+ Generator,
}
pub enum HirDisplayError {
@@ -289,7 +291,7 @@ impl HirDisplay for ProjectionTy {
let trait_ = f.db.trait_data(self.trait_(f.db));
write!(f, "<")?;
- self.self_type_parameter(Interner).hir_fmt(f)?;
+ self.self_type_parameter(f.db).hir_fmt(f)?;
write!(f, " as {}", trait_.name)?;
if self.substitution.len(Interner) > 1 {
write!(f, "<")?;
@@ -504,8 +506,15 @@ impl HirDisplay for Ty {
let total_len = parent_params + self_param + type_params + const_params;
// We print all params except implicit impl Trait params. Still a bit weird; should we leave out parent and self?
if total_len > 0 {
+ // `parameters` are in the order of fn's params (including impl traits),
+ // parent's params (those from enclosing impl or trait, if any).
+ let parameters = parameters.as_slice(Interner);
+ let fn_params_len = self_param + type_params + const_params;
+ let fn_params = parameters.get(..fn_params_len);
+ let parent_params = parameters.get(parameters.len() - parent_params..);
+ let params = parent_params.into_iter().chain(fn_params).flatten();
write!(f, "<")?;
- f.write_joined(&parameters.as_slice(Interner)[..total_len], ", ")?;
+ f.write_joined(params, ", ")?;
write!(f, ">")?;
}
}
@@ -533,6 +542,7 @@ impl HirDisplay for Ty {
f.db.upcast(),
ItemInNs::Types((*def_id).into()),
module_id,
+ false,
) {
write!(f, "{}", path)?;
} else {
@@ -576,9 +586,8 @@ impl HirDisplay for Ty {
Some(x) => x,
None => return true,
};
- let actual_default = default_parameter
- .clone()
- .substitute(Interner, &subst_prefix(parameters, i));
+ let actual_default =
+ default_parameter.clone().substitute(Interner, &parameters);
parameter != &actual_default
}
let mut default_from = 0;
@@ -722,7 +731,7 @@ impl HirDisplay for Ty {
WhereClause::AliasEq(AliasEq {
alias: AliasTy::Projection(proj),
ty: _,
- }) => &proj.self_type_parameter(Interner) == self,
+ }) => &proj.self_type_parameter(f.db) == self,
_ => false,
})
.collect::<Vec<_>>();
@@ -742,9 +751,19 @@ impl HirDisplay for Ty {
}
TyKind::BoundVar(idx) => idx.hir_fmt(f)?,
TyKind::Dyn(dyn_ty) => {
+ // Reorder bounds to satisfy `write_bounds_like_dyn_trait()`'s expectation.
+ // FIXME: `Iterator::partition_in_place()` or `Vec::drain_filter()` may make it
+ // more efficient when either of them hits stable.
+ let mut bounds: SmallVec<[_; 4]> =
+ dyn_ty.bounds.skip_binders().iter(Interner).cloned().collect();
+ let (auto_traits, others): (SmallVec<[_; 4]>, _) =
+ bounds.drain(1..).partition(|b| b.skip_binders().trait_id().is_some());
+ bounds.extend(others);
+ bounds.extend(auto_traits);
+
write_bounds_like_dyn_trait_with_prefix(
"dyn",
- dyn_ty.bounds.skip_binders().interned(),
+ &bounds,
SizedByDefault::NotSized,
f,
)?;
@@ -782,7 +801,34 @@ impl HirDisplay for Ty {
write!(f, "{{unknown}}")?;
}
TyKind::InferenceVar(..) => write!(f, "_")?,
- TyKind::Generator(..) => write!(f, "{{generator}}")?,
+ TyKind::Generator(_, subst) => {
+ if f.display_target.is_source_code() {
+ return Err(HirDisplayError::DisplaySourceCodeError(
+ DisplaySourceCodeError::Generator,
+ ));
+ }
+
+ let subst = subst.as_slice(Interner);
+ let a: Option<SmallVec<[&Ty; 3]>> = subst
+ .get(subst.len() - 3..)
+ .map(|args| args.iter().map(|arg| arg.ty(Interner)).collect())
+ .flatten();
+
+ if let Some([resume_ty, yield_ty, ret_ty]) = a.as_deref() {
+ write!(f, "|")?;
+ resume_ty.hir_fmt(f)?;
+ write!(f, "|")?;
+
+ write!(f, " yields ")?;
+ yield_ty.hir_fmt(f)?;
+
+ write!(f, " -> ")?;
+ ret_ty.hir_fmt(f)?;
+ } else {
+ // This *should* be unreachable, but fallback just in case.
+ write!(f, "{{generator}}")?;
+ }
+ }
TyKind::GeneratorWitness(..) => write!(f, "{{generator witness}}")?,
}
Ok(())
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer.rs
index 10ffde87e..0efff651c 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/infer.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer.rs
@@ -2,7 +2,7 @@
//! the type of each expression and pattern.
//!
//! For type inference, compare the implementations in rustc (the various
-//! check_* methods in librustc_typeck/check/mod.rs are a good entry point) and
+//! check_* methods in rustc_hir_analysis/check/mod.rs are a good entry point) and
//! IntelliJ-Rust (org.rust.lang.core.types.infer). Our entry point for
//! inference here is the `infer` function, which infers the types of all
//! expressions in a given function.
@@ -19,14 +19,15 @@ use std::sync::Arc;
use chalk_ir::{cast::Cast, ConstValue, DebruijnIndex, Mutability, Safety, Scalar, TypeFlags};
use hir_def::{
body::Body,
+ builtin_type::BuiltinType,
data::{ConstData, StaticData},
expr::{BindingAnnotation, ExprId, PatId},
lang_item::LangItemTarget,
path::{path, Path},
resolver::{HasResolver, ResolveValueResult, Resolver, TypeNs, ValueNs},
type_ref::TypeRef,
- AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, FunctionId, HasModule, Lookup,
- TraitId, TypeAliasId, VariantId,
+ AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, FunctionId, HasModule,
+ ItemContainerId, Lookup, TraitId, TypeAliasId, VariantId,
};
use hir_expand::name::{name, Name};
use itertools::Either;
@@ -67,6 +68,12 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer
DefWithBodyId::ConstId(c) => ctx.collect_const(&db.const_data(c)),
DefWithBodyId::FunctionId(f) => ctx.collect_fn(f),
DefWithBodyId::StaticId(s) => ctx.collect_static(&db.static_data(s)),
+ DefWithBodyId::VariantId(v) => {
+ ctx.return_ty = TyBuilder::builtin(match db.enum_data(v.parent).variant_body_type() {
+ Either::Left(builtin) => BuiltinType::Int(builtin),
+ Either::Right(builtin) => BuiltinType::Uint(builtin),
+ });
+ }
}
ctx.infer_body();
@@ -332,7 +339,7 @@ pub struct InferenceResult {
/// unresolved or missing subpatterns or subpatterns of mismatched types.
pub type_of_pat: ArenaMap<PatId, Ty>,
type_mismatches: FxHashMap<ExprOrPatId, TypeMismatch>,
- /// Interned Unknown to return references to.
+ /// Interned common types to return references to.
standard_types: InternedStandardTypes,
/// Stores the types which were implicitly dereferenced in pattern binding modes.
pub pat_adjustments: FxHashMap<PatId, Vec<Ty>>,
@@ -412,6 +419,8 @@ pub(crate) struct InferenceContext<'a> {
/// closures, but currently this is the only field that will change there,
/// so it doesn't make sense.
return_ty: Ty,
+ /// The resume type and the yield type, respectively, of the generator being inferred.
+ resume_yield_tys: Option<(Ty, Ty)>,
diverges: Diverges,
breakables: Vec<BreakableContext>,
}
@@ -476,6 +485,7 @@ impl<'a> InferenceContext<'a> {
table: unify::InferenceTable::new(db, trait_env.clone()),
trait_env,
return_ty: TyKind::Error.intern(Interner), // set in collect_fn_signature
+ resume_yield_tys: None,
db,
owner,
body,
@@ -673,10 +683,6 @@ impl<'a> InferenceContext<'a> {
)
}
- fn resolve_obligations_as_possible(&mut self) {
- self.table.resolve_obligations_as_possible();
- }
-
fn push_obligation(&mut self, o: DomainGoal) {
self.table.register_obligation(o.cast(Interner));
}
@@ -696,7 +702,6 @@ impl<'a> InferenceContext<'a> {
}
fn resolve_ty_shallow(&mut self, ty: &Ty) -> Ty {
- self.resolve_obligations_as_possible();
self.table.resolve_ty_shallow(ty)
}
@@ -708,6 +713,8 @@ impl<'a> InferenceContext<'a> {
&mut self,
inner_ty: Ty,
assoc_ty: Option<TypeAliasId>,
+ // FIXME(GATs): these are args for the trait ref, args for assoc type itself should be
+ // handled when we support them.
params: &[GenericArg],
) -> Ty {
match assoc_ty {
@@ -799,7 +806,18 @@ impl<'a> InferenceContext<'a> {
self.resolve_variant_on_alias(ty, unresolved, path)
}
TypeNs::TypeAliasId(it) => {
- let ty = TyBuilder::def_ty(self.db, it.into())
+ let container = it.lookup(self.db.upcast()).container;
+ let parent_subst = match container {
+ ItemContainerId::TraitId(id) => {
+ let subst = TyBuilder::subst_for_def(self.db, id, None)
+ .fill_with_inference_vars(&mut self.table)
+ .build();
+ Some(subst)
+ }
+ // Type aliases do not exist in impls.
+ _ => None,
+ };
+ let ty = TyBuilder::def_ty(self.db, it.into(), parent_subst)
.fill_with_inference_vars(&mut self.table)
.build();
self.resolve_variant_on_alias(ty, unresolved, path)
@@ -878,6 +896,12 @@ impl<'a> InferenceContext<'a> {
fn resolve_into_iter_item(&self) -> Option<TypeAliasId> {
let path = path![core::iter::IntoIterator];
let trait_ = self.resolver.resolve_known_trait(self.db.upcast(), &path)?;
+ self.db.trait_data(trait_).associated_type_by_name(&name![IntoIter])
+ }
+
+ fn resolve_iterator_item(&self) -> Option<TypeAliasId> {
+ let path = path![core::iter::Iterator];
+ let trait_ = self.resolver.resolve_known_trait(self.db.upcast(), &path)?;
self.db.trait_data(trait_).associated_type_by_name(&name![Item])
}
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/closure.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/closure.rs
index 3ead92909..094e460db 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/closure.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/closure.rs
@@ -12,6 +12,7 @@ use crate::{
use super::{Expectation, InferenceContext};
impl InferenceContext<'_> {
+ // This function handles both closures and generators.
pub(super) fn deduce_closure_type_from_expectations(
&mut self,
closure_expr: ExprId,
@@ -27,6 +28,11 @@ impl InferenceContext<'_> {
// Deduction from where-clauses in scope, as well as fn-pointer coercion are handled here.
let _ = self.coerce(Some(closure_expr), closure_ty, &expected_ty);
+ // Generators are not Fn* so return early.
+ if matches!(closure_ty.kind(Interner), TyKind::Generator(..)) {
+ return;
+ }
+
// Deduction based on the expected `dyn Fn` is done separately.
if let TyKind::Dyn(dyn_ty) = expected_ty.kind(Interner) {
if let Some(sig) = self.deduce_sig_from_dyn_ty(dyn_ty) {
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs
index f54440bf5..8df25c83c 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs
@@ -3,7 +3,7 @@
//! like going from `&Vec<T>` to `&[T]`.
//!
//! See <https://doc.rust-lang.org/nomicon/coercions.html> and
-//! `librustc_typeck/check/coercion.rs`.
+//! `rustc_hir_analysis/check/coercion.rs`.
use std::{iter, sync::Arc};
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs
index 2d04a864a..f56108b26 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs
@@ -10,7 +10,10 @@ use chalk_ir::{
cast::Cast, fold::Shift, DebruijnIndex, GenericArgData, Mutability, TyVariableKind,
};
use hir_def::{
- expr::{ArithOp, Array, BinaryOp, CmpOp, Expr, ExprId, LabelId, Literal, Statement, UnaryOp},
+ expr::{
+ ArithOp, Array, BinaryOp, ClosureKind, CmpOp, Expr, ExprId, LabelId, Literal, Statement,
+ UnaryOp,
+ },
generics::TypeOrConstParamData,
path::{GenericArg, GenericArgs},
resolver::resolver_for_expr,
@@ -204,8 +207,10 @@ impl<'a> InferenceContext<'a> {
}
&Expr::For { iterable, body, pat, label } => {
let iterable_ty = self.infer_expr(iterable, &Expectation::none());
- let pat_ty =
+ let into_iter_ty =
self.resolve_associated_type(iterable_ty, self.resolve_into_iter_item());
+ let pat_ty =
+ self.resolve_associated_type(into_iter_ty, self.resolve_iterator_item());
self.infer_pat(pat, &pat_ty, BindingMode::default());
self.with_breakable_ctx(BreakableKind::Loop, self.err_ty(), label, |this| {
@@ -216,7 +221,7 @@ impl<'a> InferenceContext<'a> {
self.diverges = Diverges::Maybe;
TyBuilder::unit()
}
- Expr::Closure { body, args, ret_type, arg_types } => {
+ Expr::Closure { body, args, ret_type, arg_types, closure_kind } => {
assert_eq!(args.len(), arg_types.len());
let mut sig_tys = Vec::new();
@@ -244,20 +249,40 @@ impl<'a> InferenceContext<'a> {
),
})
.intern(Interner);
- let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into();
- let closure_ty =
- TyKind::Closure(closure_id, Substitution::from1(Interner, sig_ty.clone()))
- .intern(Interner);
+
+ let (ty, resume_yield_tys) = if matches!(closure_kind, ClosureKind::Generator(_)) {
+ // FIXME: report error when there are more than 1 parameter.
+ let resume_ty = match sig_tys.first() {
+ // When `sig_tys.len() == 1` the first type is the return type, not the
+ // first parameter type.
+ Some(ty) if sig_tys.len() > 1 => ty.clone(),
+ _ => self.result.standard_types.unit.clone(),
+ };
+ let yield_ty = self.table.new_type_var();
+
+ let subst = TyBuilder::subst_for_generator(self.db, self.owner)
+ .push(resume_ty.clone())
+ .push(yield_ty.clone())
+ .push(ret_ty.clone())
+ .build();
+
+ let generator_id = self.db.intern_generator((self.owner, tgt_expr)).into();
+ let generator_ty = TyKind::Generator(generator_id, subst).intern(Interner);
+
+ (generator_ty, Some((resume_ty, yield_ty)))
+ } else {
+ let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into();
+ let closure_ty =
+ TyKind::Closure(closure_id, Substitution::from1(Interner, sig_ty.clone()))
+ .intern(Interner);
+
+ (closure_ty, None)
+ };
// Eagerly try to relate the closure type with the expected
// type, otherwise we often won't have enough information to
// infer the body.
- self.deduce_closure_type_from_expectations(
- tgt_expr,
- &closure_ty,
- &sig_ty,
- expected,
- );
+ self.deduce_closure_type_from_expectations(tgt_expr, &ty, &sig_ty, expected);
// Now go through the argument patterns
for (arg_pat, arg_ty) in args.iter().zip(sig_tys) {
@@ -266,6 +291,8 @@ impl<'a> InferenceContext<'a> {
let prev_diverges = mem::replace(&mut self.diverges, Diverges::Maybe);
let prev_ret_ty = mem::replace(&mut self.return_ty, ret_ty.clone());
+ let prev_resume_yield_tys =
+ mem::replace(&mut self.resume_yield_tys, resume_yield_tys);
self.with_breakable_ctx(BreakableKind::Border, self.err_ty(), None, |this| {
this.infer_expr_coerce(*body, &Expectation::has_type(ret_ty));
@@ -273,8 +300,9 @@ impl<'a> InferenceContext<'a> {
self.diverges = prev_diverges;
self.return_ty = prev_ret_ty;
+ self.resume_yield_tys = prev_resume_yield_tys;
- closure_ty
+ ty
}
Expr::Call { callee, args, .. } => {
let callee_ty = self.infer_expr(*callee, &Expectation::none());
@@ -423,11 +451,18 @@ impl<'a> InferenceContext<'a> {
TyKind::Never.intern(Interner)
}
Expr::Yield { expr } => {
- // FIXME: track yield type for coercion
- if let Some(expr) = expr {
- self.infer_expr(*expr, &Expectation::none());
+ if let Some((resume_ty, yield_ty)) = self.resume_yield_tys.clone() {
+ if let Some(expr) = expr {
+ self.infer_expr_coerce(*expr, &Expectation::has_type(yield_ty));
+ } else {
+ let unit = self.result.standard_types.unit.clone();
+ let _ = self.coerce(Some(tgt_expr), &unit, &yield_ty);
+ }
+ resume_ty
+ } else {
+ // FIXME: report error (yield expr in non-generator)
+ TyKind::Error.intern(Interner)
}
- TyKind::Never.intern(Interner)
}
Expr::RecordLit { path, fields, spread, .. } => {
let (ty, def_id) = self.resolve_variant(path.as_deref(), false);
@@ -952,11 +987,13 @@ impl<'a> InferenceContext<'a> {
let lhs_ty = self.infer_expr(lhs, &lhs_expectation);
let rhs_ty = self.table.new_type_var();
- let func = lang_names_for_bin_op(op).and_then(|(name, lang_item)| {
- self.db.trait_data(self.resolve_lang_item(lang_item)?.as_trait()?).method_by_name(&name)
+ let trait_func = lang_names_for_bin_op(op).and_then(|(name, lang_item)| {
+ let trait_id = self.resolve_lang_item(lang_item)?.as_trait()?;
+ let func = self.db.trait_data(trait_id).method_by_name(&name)?;
+ Some((trait_id, func))
});
- let func = match func {
- Some(func) => func,
+ let (trait_, func) = match trait_func {
+ Some(it) => it,
None => {
let rhs_ty = self.builtin_binary_op_rhs_expectation(op, lhs_ty.clone());
let rhs_ty = self.infer_expr_coerce(rhs, &Expectation::from_option(rhs_ty));
@@ -966,7 +1003,9 @@ impl<'a> InferenceContext<'a> {
}
};
- let subst = TyBuilder::subst_for_def(self.db, func)
+ // HACK: We can use this substitution for the function because the function itself doesn't
+ // have its own generic parameters.
+ let subst = TyBuilder::subst_for_def(self.db, trait_, None)
.push(lhs_ty.clone())
.push(rhs_ty.clone())
.build();
@@ -1245,19 +1284,7 @@ impl<'a> InferenceContext<'a> {
assert_eq!(self_params, 0); // method shouldn't have another Self param
let total_len = parent_params + type_params + const_params + impl_trait_params;
let mut substs = Vec::with_capacity(total_len);
- // Parent arguments are unknown
- for (id, param) in def_generics.iter_parent() {
- match param {
- TypeOrConstParamData::TypeParamData(_) => {
- substs.push(GenericArgData::Ty(self.table.new_type_var()).intern(Interner));
- }
- TypeOrConstParamData::ConstParamData(_) => {
- let ty = self.db.const_param_ty(ConstParamId::from_unchecked(id));
- substs
- .push(GenericArgData::Const(self.table.new_const_var(ty)).intern(Interner));
- }
- }
- }
+
// handle provided arguments
if let Some(generic_args) = generic_args {
// if args are provided, it should be all of them, but we can't rely on that
@@ -1266,7 +1293,7 @@ impl<'a> InferenceContext<'a> {
.iter()
.filter(|arg| !matches!(arg, GenericArg::Lifetime(_)))
.take(type_params + const_params)
- .zip(def_generics.iter_id().skip(parent_params))
+ .zip(def_generics.iter_id())
{
if let Some(g) = generic_arg_to_chalk(
self.db,
@@ -1290,6 +1317,9 @@ impl<'a> InferenceContext<'a> {
}
}
};
+
+ // Handle everything else as unknown. This also handles generic arguments for the method's
+ // parent (impl or trait), which should come after those for the method.
for (id, data) in def_generics.iter().skip(substs.len()) {
match data {
TypeOrConstParamData::TypeParamData(_) => {
@@ -1327,9 +1357,13 @@ impl<'a> InferenceContext<'a> {
CallableDefId::FunctionId(f) => {
if let ItemContainerId::TraitId(trait_) = f.lookup(self.db.upcast()).container {
// construct a TraitRef
- let substs = crate::subst_prefix(
- &*parameters,
- generics(self.db.upcast(), trait_.into()).len(),
+ let params_len = parameters.len(Interner);
+ let trait_params_len = generics(self.db.upcast(), trait_.into()).len();
+ let substs = Substitution::from_iter(
+ Interner,
+ // The generic parameters for the trait come after those for the
+ // function.
+ &parameters.as_slice(Interner)[params_len - trait_params_len..],
);
self.push_obligation(
TraitRef { trait_id: to_chalk_trait_id(trait_), substitution: substs }
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs
index f580e09e9..7a4754cdc 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs
@@ -12,8 +12,8 @@ use crate::{
builder::ParamKind,
consteval,
method_resolution::{self, VisibleFromModule},
- GenericArgData, Interner, Substitution, TraitRefExt, Ty, TyBuilder, TyExt, TyKind,
- ValueTyDefId,
+ utils::generics,
+ Interner, Substitution, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, ValueTyDefId,
};
use super::{ExprOrPatId, InferenceContext, TraitRef};
@@ -96,17 +96,21 @@ impl<'a> InferenceContext<'a> {
ValueNs::GenericParam(it) => return Some(self.db.const_param_ty(it)),
};
- let parent_substs = self_subst.unwrap_or_else(|| Substitution::empty(Interner));
let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver);
let substs = ctx.substs_from_path(path, typable, true);
- let mut it = substs.as_slice(Interner)[parent_substs.len(Interner)..].iter().cloned();
- let ty = TyBuilder::value_ty(self.db, typable)
- .use_parent_substs(&parent_substs)
+ let substs = substs.as_slice(Interner);
+ let parent_substs = self_subst.or_else(|| {
+ let generics = generics(self.db.upcast(), typable.to_generic_def_id()?);
+ let parent_params_len = generics.parent_generics()?.len();
+ let parent_args = &substs[substs.len() - parent_params_len..];
+ Some(Substitution::from_iter(Interner, parent_args))
+ });
+ let parent_substs_len = parent_substs.as_ref().map_or(0, |s| s.len(Interner));
+ let mut it = substs.iter().take(substs.len() - parent_substs_len).cloned();
+ let ty = TyBuilder::value_ty(self.db, typable, parent_substs)
.fill(|x| {
it.next().unwrap_or_else(|| match x {
- ParamKind::Type => {
- GenericArgData::Ty(TyKind::Error.intern(Interner)).intern(Interner)
- }
+ ParamKind::Type => TyKind::Error.intern(Interner).cast(Interner),
ParamKind::Const(ty) => consteval::unknown_const_as_generic(ty.clone()),
})
})
@@ -249,7 +253,7 @@ impl<'a> InferenceContext<'a> {
};
let substs = match container {
ItemContainerId::ImplId(impl_id) => {
- let impl_substs = TyBuilder::subst_for_def(self.db, impl_id)
+ let impl_substs = TyBuilder::subst_for_def(self.db, impl_id, None)
.fill_with_inference_vars(&mut self.table)
.build();
let impl_self_ty =
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs
index e77b55670..b00e3216b 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs
@@ -4,7 +4,7 @@ use std::{fmt, mem, sync::Arc};
use chalk_ir::{
cast::Cast, fold::TypeFoldable, interner::HasInterner, zip::Zip, CanonicalVarKind, FloatTy,
- IntTy, NoSolution, TyVariableKind, UniverseIndex,
+ IntTy, TyVariableKind, UniverseIndex,
};
use chalk_solve::infer::ParameterEnaVariableExt;
use ena::unify::UnifyKey;
@@ -331,7 +331,6 @@ impl<'a> InferenceTable<'a> {
&mut resolve::Resolver { table: self, var_stack, fallback },
DebruijnIndex::INNERMOST,
)
- .expect("fold failed unexpectedly")
}
pub(crate) fn resolve_completely<T>(&mut self, t: T) -> T
@@ -452,13 +451,14 @@ impl<'a> InferenceTable<'a> {
f: impl FnOnce(&mut Self) -> T,
) -> T {
use chalk_ir::fold::TypeFolder;
+
+ #[derive(chalk_derive::FallibleTypeFolder)]
+ #[has_interner(Interner)]
struct VarFudger<'a, 'b> {
table: &'a mut InferenceTable<'b>,
highest_known_var: InferenceVar,
}
impl<'a, 'b> TypeFolder<Interner> for VarFudger<'a, 'b> {
- type Error = NoSolution;
-
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
self
}
@@ -472,24 +472,24 @@ impl<'a> InferenceTable<'a> {
var: chalk_ir::InferenceVar,
kind: TyVariableKind,
_outer_binder: chalk_ir::DebruijnIndex,
- ) -> chalk_ir::Fallible<chalk_ir::Ty<Interner>> {
- Ok(if var < self.highest_known_var {
+ ) -> chalk_ir::Ty<Interner> {
+ if var < self.highest_known_var {
var.to_ty(Interner, kind)
} else {
self.table.new_type_var()
- })
+ }
}
fn fold_inference_lifetime(
&mut self,
var: chalk_ir::InferenceVar,
_outer_binder: chalk_ir::DebruijnIndex,
- ) -> chalk_ir::Fallible<chalk_ir::Lifetime<Interner>> {
- Ok(if var < self.highest_known_var {
+ ) -> chalk_ir::Lifetime<Interner> {
+ if var < self.highest_known_var {
var.to_lifetime(Interner)
} else {
self.table.new_lifetime_var()
- })
+ }
}
fn fold_inference_const(
@@ -497,12 +497,12 @@ impl<'a> InferenceTable<'a> {
ty: chalk_ir::Ty<Interner>,
var: chalk_ir::InferenceVar,
_outer_binder: chalk_ir::DebruijnIndex,
- ) -> chalk_ir::Fallible<chalk_ir::Const<Interner>> {
- Ok(if var < self.highest_known_var {
+ ) -> chalk_ir::Const<Interner> {
+ if var < self.highest_known_var {
var.to_const(Interner, ty)
} else {
self.table.new_const_var(ty)
- })
+ }
}
}
@@ -512,7 +512,6 @@ impl<'a> InferenceTable<'a> {
self.rollback_to(snapshot);
result
.fold_with(&mut VarFudger { table: self, highest_known_var }, DebruijnIndex::INNERMOST)
- .expect("fold_with with VarFudger")
}
/// This checks whether any of the free variables in the `canonicalized`
@@ -598,11 +597,14 @@ impl<'a> InferenceTable<'a> {
.build();
let projection = {
- let b = TyBuilder::assoc_type_projection(self.db, output_assoc_type);
+ let b = TyBuilder::subst_for_def(self.db, fn_once_trait, None);
if b.remaining() != 2 {
return None;
}
- b.push(ty.clone()).push(arg_ty).build()
+ let fn_once_subst = b.push(ty.clone()).push(arg_ty).build();
+
+ TyBuilder::assoc_type_projection(self.db, output_assoc_type, Some(fn_once_subst))
+ .build()
};
let trait_env = self.trait_env.env.clone();
@@ -636,21 +638,24 @@ mod resolve {
use chalk_ir::{
cast::Cast,
fold::{TypeFoldable, TypeFolder},
- Fallible, NoSolution,
};
use hir_def::type_ref::ConstScalar;
- pub(super) struct Resolver<'a, 'b, F> {
+ #[derive(chalk_derive::FallibleTypeFolder)]
+ #[has_interner(Interner)]
+ pub(super) struct Resolver<
+ 'a,
+ 'b,
+ F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg,
+ > {
pub(super) table: &'a mut InferenceTable<'b>,
pub(super) var_stack: &'a mut Vec<InferenceVar>,
pub(super) fallback: F,
}
- impl<'a, 'b, 'i, F> TypeFolder<Interner> for Resolver<'a, 'b, F>
+ impl<'a, 'b, F> TypeFolder<Interner> for Resolver<'a, 'b, F>
where
- F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg + 'i,
+ F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg,
{
- type Error = NoSolution;
-
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
self
}
@@ -664,20 +669,19 @@ mod resolve {
var: InferenceVar,
kind: TyVariableKind,
outer_binder: DebruijnIndex,
- ) -> Fallible<Ty> {
+ ) -> Ty {
let var = self.table.var_unification_table.inference_var_root(var);
if self.var_stack.contains(&var) {
// recursive type
let default = self.table.fallback_value(var, kind).cast(Interner);
- return Ok((self.fallback)(var, VariableKind::Ty(kind), default, outer_binder)
+ return (self.fallback)(var, VariableKind::Ty(kind), default, outer_binder)
.assert_ty_ref(Interner)
- .clone());
+ .clone();
}
let result = if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
// known_ty may contain other variables that are known by now
self.var_stack.push(var);
- let result =
- known_ty.fold_with(self, outer_binder).expect("fold failed unexpectedly");
+ let result = known_ty.fold_with(self, outer_binder);
self.var_stack.pop();
result.assert_ty_ref(Interner).clone()
} else {
@@ -686,7 +690,7 @@ mod resolve {
.assert_ty_ref(Interner)
.clone()
};
- Ok(result)
+ result
}
fn fold_inference_const(
@@ -694,7 +698,7 @@ mod resolve {
ty: Ty,
var: InferenceVar,
outer_binder: DebruijnIndex,
- ) -> Fallible<Const> {
+ ) -> Const {
let var = self.table.var_unification_table.inference_var_root(var);
let default = ConstData {
ty: ty.clone(),
@@ -704,35 +708,33 @@ mod resolve {
.cast(Interner);
if self.var_stack.contains(&var) {
// recursive
- return Ok((self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
+ return (self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
.assert_const_ref(Interner)
- .clone());
+ .clone();
}
- let result = if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
+ if let Some(known_ty) = self.table.var_unification_table.probe_var(var) {
// known_ty may contain other variables that are known by now
self.var_stack.push(var);
- let result =
- known_ty.fold_with(self, outer_binder).expect("fold failed unexpectedly");
+ let result = known_ty.fold_with(self, outer_binder);
self.var_stack.pop();
result.assert_const_ref(Interner).clone()
} else {
(self.fallback)(var, VariableKind::Const(ty), default, outer_binder)
.assert_const_ref(Interner)
.clone()
- };
- Ok(result)
+ }
}
fn fold_inference_lifetime(
&mut self,
_var: InferenceVar,
_outer_binder: DebruijnIndex,
- ) -> Fallible<Lifetime> {
+ ) -> Lifetime {
// fall back all lifetimes to 'static -- currently we don't deal
// with any lifetimes, but we can sometimes get some lifetime
// variables through Chalk's unification, and this at least makes
// sure we don't leak them outside of inference
- Ok(crate::static_lifetime())
+ crate::static_lifetime()
}
}
}
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/lib.rs b/src/tools/rust-analyzer/crates/hir-ty/src/lib.rs
index a82a331d4..c4b700cbc 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/lib.rs
@@ -196,20 +196,6 @@ pub(crate) fn make_binders<T: HasInterner<Interner = Interner>>(
make_binders_with_count(db, usize::MAX, generics, value)
}
-// FIXME: get rid of this
-pub fn make_canonical<T: HasInterner<Interner = Interner>>(
- value: T,
- kinds: impl IntoIterator<Item = TyVariableKind>,
-) -> Canonical<T> {
- let kinds = kinds.into_iter().map(|tk| {
- chalk_ir::CanonicalVarKind::new(
- chalk_ir::VariableKind::Ty(tk),
- chalk_ir::UniverseIndex::ROOT,
- )
- });
- Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(Interner, kinds) }
-}
-
// FIXME: get rid of this, just replace it by FnPointer
/// A function signature as seen by type inference: Several parameter types and
/// one return type.
@@ -268,13 +254,13 @@ impl CallableSig {
}
impl TypeFoldable<Interner> for CallableSig {
- fn fold_with<E>(
+ fn try_fold_with<E>(
self,
- folder: &mut dyn chalk_ir::fold::TypeFolder<Interner, Error = E>,
+ folder: &mut dyn chalk_ir::fold::FallibleTypeFolder<Interner, Error = E>,
outer_binder: DebruijnIndex,
) -> Result<Self, E> {
let vec = self.params_and_return.to_vec();
- let folded = vec.fold_with(folder, outer_binder)?;
+ let folded = vec.try_fold_with(folder, outer_binder)?;
Ok(CallableSig { params_and_return: folded.into(), is_varargs: self.is_varargs })
}
}
@@ -306,16 +292,19 @@ pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + TypeFoldable<
for_ty: impl FnMut(BoundVar, DebruijnIndex) -> Ty,
for_const: impl FnMut(Ty, BoundVar, DebruijnIndex) -> Const,
) -> T {
- use chalk_ir::{fold::TypeFolder, Fallible};
- struct FreeVarFolder<F1, F2>(F1, F2);
+ use chalk_ir::fold::TypeFolder;
+
+ #[derive(chalk_derive::FallibleTypeFolder)]
+ #[has_interner(Interner)]
+ struct FreeVarFolder<
+ F1: FnMut(BoundVar, DebruijnIndex) -> Ty,
+ F2: FnMut(Ty, BoundVar, DebruijnIndex) -> Const,
+ >(F1, F2);
impl<
- 'i,
- F1: FnMut(BoundVar, DebruijnIndex) -> Ty + 'i,
- F2: FnMut(Ty, BoundVar, DebruijnIndex) -> Const + 'i,
+ F1: FnMut(BoundVar, DebruijnIndex) -> Ty,
+ F2: FnMut(Ty, BoundVar, DebruijnIndex) -> Const,
> TypeFolder<Interner> for FreeVarFolder<F1, F2>
{
- type Error = NoSolution;
-
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
self
}
@@ -324,12 +313,8 @@ pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + TypeFoldable<
Interner
}
- fn fold_free_var_ty(
- &mut self,
- bound_var: BoundVar,
- outer_binder: DebruijnIndex,
- ) -> Fallible<Ty> {
- Ok(self.0(bound_var, outer_binder))
+ fn fold_free_var_ty(&mut self, bound_var: BoundVar, outer_binder: DebruijnIndex) -> Ty {
+ self.0(bound_var, outer_binder)
}
fn fold_free_var_const(
@@ -337,12 +322,11 @@ pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + TypeFoldable<
ty: Ty,
bound_var: BoundVar,
outer_binder: DebruijnIndex,
- ) -> Fallible<Const> {
- Ok(self.1(ty, bound_var, outer_binder))
+ ) -> Const {
+ self.1(ty, bound_var, outer_binder)
}
}
t.fold_with(&mut FreeVarFolder(for_ty, for_const), DebruijnIndex::INNERMOST)
- .expect("fold failed unexpectedly")
}
pub(crate) fn fold_tys<T: HasInterner<Interner = Interner> + TypeFoldable<Interner>>(
@@ -365,16 +349,13 @@ pub(crate) fn fold_tys_and_consts<T: HasInterner<Interner = Interner> + TypeFold
f: impl FnMut(Either<Ty, Const>, DebruijnIndex) -> Either<Ty, Const>,
binders: DebruijnIndex,
) -> T {
- use chalk_ir::{
- fold::{TypeFolder, TypeSuperFoldable},
- Fallible,
- };
- struct TyFolder<F>(F);
- impl<'i, F: FnMut(Either<Ty, Const>, DebruijnIndex) -> Either<Ty, Const> + 'i>
- TypeFolder<Interner> for TyFolder<F>
+ use chalk_ir::fold::{TypeFolder, TypeSuperFoldable};
+ #[derive(chalk_derive::FallibleTypeFolder)]
+ #[has_interner(Interner)]
+ struct TyFolder<F: FnMut(Either<Ty, Const>, DebruijnIndex) -> Either<Ty, Const>>(F);
+ impl<F: FnMut(Either<Ty, Const>, DebruijnIndex) -> Either<Ty, Const>> TypeFolder<Interner>
+ for TyFolder<F>
{
- type Error = NoSolution;
-
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
self
}
@@ -383,16 +364,16 @@ pub(crate) fn fold_tys_and_consts<T: HasInterner<Interner = Interner> + TypeFold
Interner
}
- fn fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible<Ty> {
- let ty = ty.super_fold_with(self.as_dyn(), outer_binder)?;
- Ok(self.0(Either::Left(ty), outer_binder).left().unwrap())
+ fn fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Ty {
+ let ty = ty.super_fold_with(self.as_dyn(), outer_binder);
+ self.0(Either::Left(ty), outer_binder).left().unwrap()
}
- fn fold_const(&mut self, c: Const, outer_binder: DebruijnIndex) -> Fallible<Const> {
- Ok(self.0(Either::Right(c), outer_binder).right().unwrap())
+ fn fold_const(&mut self, c: Const, outer_binder: DebruijnIndex) -> Const {
+ self.0(Either::Right(c), outer_binder).right().unwrap()
}
}
- t.fold_with(&mut TyFolder(f), binders).expect("fold failed unexpectedly")
+ t.fold_with(&mut TyFolder(f), binders)
}
/// 'Canonicalizes' the `t` by replacing any errors with new variables. Also
@@ -404,16 +385,16 @@ where
T: HasInterner<Interner = Interner>,
{
use chalk_ir::{
- fold::{TypeFolder, TypeSuperFoldable},
+ fold::{FallibleTypeFolder, TypeSuperFoldable},
Fallible,
};
struct ErrorReplacer {
vars: usize,
}
- impl TypeFolder<Interner> for ErrorReplacer {
+ impl FallibleTypeFolder<Interner> for ErrorReplacer {
type Error = NoSolution;
- fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
+ fn as_dyn(&mut self) -> &mut dyn FallibleTypeFolder<Interner, Error = Self::Error> {
self
}
@@ -421,18 +402,17 @@ where
Interner
}
- fn fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible<Ty> {
+ fn try_fold_ty(&mut self, ty: Ty, outer_binder: DebruijnIndex) -> Fallible<Ty> {
if let TyKind::Error = ty.kind(Interner) {
let index = self.vars;
self.vars += 1;
Ok(TyKind::BoundVar(BoundVar::new(outer_binder, index)).intern(Interner))
} else {
- let ty = ty.super_fold_with(self.as_dyn(), outer_binder)?;
- Ok(ty)
+ ty.try_super_fold_with(self.as_dyn(), outer_binder)
}
}
- fn fold_inference_ty(
+ fn try_fold_inference_ty(
&mut self,
_var: InferenceVar,
_kind: TyVariableKind,
@@ -447,7 +427,7 @@ where
}
}
- fn fold_free_var_ty(
+ fn try_fold_free_var_ty(
&mut self,
_bound_var: BoundVar,
_outer_binder: DebruijnIndex,
@@ -461,7 +441,7 @@ where
}
}
- fn fold_inference_const(
+ fn try_fold_inference_const(
&mut self,
ty: Ty,
_var: InferenceVar,
@@ -474,7 +454,7 @@ where
}
}
- fn fold_free_var_const(
+ fn try_fold_free_var_const(
&mut self,
ty: Ty,
_bound_var: BoundVar,
@@ -487,7 +467,7 @@ where
}
}
- fn fold_inference_lifetime(
+ fn try_fold_inference_lifetime(
&mut self,
_var: InferenceVar,
_outer_binder: DebruijnIndex,
@@ -499,7 +479,7 @@ where
}
}
- fn fold_free_var_lifetime(
+ fn try_fold_free_var_lifetime(
&mut self,
_bound_var: BoundVar,
_outer_binder: DebruijnIndex,
@@ -512,7 +492,7 @@ where
}
}
let mut error_replacer = ErrorReplacer { vars: 0 };
- let value = match t.clone().fold_with(&mut error_replacer, DebruijnIndex::INNERMOST) {
+ let value = match t.clone().try_fold_with(&mut error_replacer, DebruijnIndex::INNERMOST) {
Ok(t) => t,
Err(_) => panic!("Encountered unbound or inference vars in {:?}", t),
};
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs
index 532544fee..223d705b1 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs
@@ -306,7 +306,7 @@ impl<'a> TyLoweringContext<'a> {
// FIXME we're probably doing something wrong here
self.impl_trait_counter.set(idx + count_impl_traits(type_ref) as u16);
let (
- parent_params,
+ _parent_params,
self_params,
list_params,
const_params,
@@ -319,7 +319,7 @@ impl<'a> TyLoweringContext<'a> {
};
TyKind::BoundVar(BoundVar::new(
self.in_binders,
- idx as usize + parent_params + self_params + list_params + const_params,
+ idx as usize + self_params + list_params + const_params,
))
.intern(Interner)
}
@@ -499,14 +499,31 @@ impl<'a> TyLoweringContext<'a> {
.intern(Interner)
}
TypeNs::SelfType(impl_id) => {
- let generics = generics(self.db.upcast(), impl_id.into());
- let substs = match self.type_param_mode {
- ParamLoweringMode::Placeholder => generics.placeholder_subst(self.db),
+ let def =
+ self.resolver.generic_def().expect("impl should have generic param scope");
+ let generics = generics(self.db.upcast(), def);
+
+ match self.type_param_mode {
+ ParamLoweringMode::Placeholder => {
+ // `def` can be either impl itself or item within, and we need impl itself
+ // now.
+ let generics = generics.parent_generics().unwrap_or(&generics);
+ let subst = generics.placeholder_subst(self.db);
+ self.db.impl_self_ty(impl_id).substitute(Interner, &subst)
+ }
ParamLoweringMode::Variable => {
- generics.bound_vars_subst(self.db, self.in_binders)
+ let starting_from = match def {
+ GenericDefId::ImplId(_) => 0,
+ // `def` is an item within impl. We need to substitute `BoundVar`s but
+ // remember that they are for parent (i.e. impl) generic params so they
+ // come after our own params.
+ _ => generics.len_self(),
+ };
+ TyBuilder::impl_self_ty(self.db, impl_id)
+ .fill_with_bound_vars(self.in_binders, starting_from)
+ .build()
}
- };
- self.db.impl_self_ty(impl_id).substitute(Interner, &substs)
+ }
}
TypeNs::AdtSelfType(adt) => {
let generics = generics(self.db.upcast(), adt.into());
@@ -663,40 +680,31 @@ impl<'a> TyLoweringContext<'a> {
fn substs_from_path_segment(
&self,
segment: PathSegment<'_>,
- def_generic: Option<GenericDefId>,
+ def: Option<GenericDefId>,
infer_args: bool,
explicit_self_ty: Option<Ty>,
) -> Substitution {
+ // Remember that the item's own generic args come before its parent's.
let mut substs = Vec::new();
- let def_generics = if let Some(def) = def_generic {
- generics(self.db.upcast(), def)
+ let def = if let Some(d) = def {
+ d
} else {
return Substitution::empty(Interner);
};
+ let def_generics = generics(self.db.upcast(), def);
let (parent_params, self_params, type_params, const_params, impl_trait_params) =
def_generics.provenance_split();
- let total_len =
- parent_params + self_params + type_params + const_params + impl_trait_params;
+ let item_len = self_params + type_params + const_params + impl_trait_params;
+ let total_len = parent_params + item_len;
- let ty_error = GenericArgData::Ty(TyKind::Error.intern(Interner)).intern(Interner);
+ let ty_error = TyKind::Error.intern(Interner).cast(Interner);
let mut def_generic_iter = def_generics.iter_id();
- for _ in 0..parent_params {
- if let Some(eid) = def_generic_iter.next() {
- match eid {
- Either::Left(_) => substs.push(ty_error.clone()),
- Either::Right(x) => {
- substs.push(unknown_const_as_generic(self.db.const_param_ty(x)))
- }
- }
- }
- }
-
let fill_self_params = || {
for x in explicit_self_ty
.into_iter()
- .map(|x| GenericArgData::Ty(x).intern(Interner))
+ .map(|x| x.cast(Interner))
.chain(iter::repeat(ty_error.clone()))
.take(self_params)
{
@@ -757,37 +765,40 @@ impl<'a> TyLoweringContext<'a> {
fill_self_params();
}
+ // These params include those of parent.
+ let remaining_params: SmallVec<[_; 2]> = def_generic_iter
+ .map(|eid| match eid {
+ Either::Left(_) => ty_error.clone(),
+ Either::Right(x) => unknown_const_as_generic(self.db.const_param_ty(x)),
+ })
+ .collect();
+ assert_eq!(remaining_params.len() + substs.len(), total_len);
+
// handle defaults. In expression or pattern path segments without
// explicitly specified type arguments, missing type arguments are inferred
// (i.e. defaults aren't used).
if !infer_args || had_explicit_args {
- if let Some(def_generic) = def_generic {
- let defaults = self.db.generic_defaults(def_generic);
- assert_eq!(total_len, defaults.len());
-
- for default_ty in defaults.iter().skip(substs.len()) {
- // each default can depend on the previous parameters
- let substs_so_far = Substitution::from_iter(Interner, substs.clone());
- if let Some(_id) = def_generic_iter.next() {
- substs.push(default_ty.clone().substitute(Interner, &substs_so_far));
- }
- }
+ let defaults = self.db.generic_defaults(def);
+ assert_eq!(total_len, defaults.len());
+ let parent_from = item_len - substs.len();
+
+ for (idx, default_ty) in defaults[substs.len()..item_len].iter().enumerate() {
+ // each default can depend on the previous parameters
+ let substs_so_far = Substitution::from_iter(
+ Interner,
+ substs.iter().cloned().chain(remaining_params[idx..].iter().cloned()),
+ );
+ substs.push(default_ty.clone().substitute(Interner, &substs_so_far));
}
- }
- // add placeholders for args that were not provided
- // FIXME: emit diagnostics in contexts where this is not allowed
- for eid in def_generic_iter {
- match eid {
- Either::Left(_) => substs.push(ty_error.clone()),
- Either::Right(x) => {
- substs.push(unknown_const_as_generic(self.db.const_param_ty(x)))
- }
- }
+ // Keep parent's params as unknown.
+ let mut remaining_params = remaining_params;
+ substs.extend(remaining_params.drain(parent_from..));
+ } else {
+ substs.extend(remaining_params);
}
- // If this assert fails, it means you pushed into subst but didn't call .next() of def_generic_iter
- assert_eq!(substs.len(), total_len);
+ assert_eq!(substs.len(), total_len);
Substitution::from_iter(Interner, substs)
}
@@ -981,10 +992,11 @@ impl<'a> TyLoweringContext<'a> {
fn lower_dyn_trait(&self, bounds: &[Interned<TypeBound>]) -> Ty {
let self_ty = TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(Interner);
- // INVARIANT: The principal trait bound must come first. Others may be in any order but
- // should be in the same order for the same set but possibly different order of bounds in
- // the input.
- // This invariant is used by `TyExt::dyn_trait()` and chalk.
+ // INVARIANT: The principal trait bound, if present, must come first. Others may be in any
+ // order but should be in the same order for the same set but possibly different order of
+ // bounds in the input.
+ // INVARIANT: If this function returns `DynTy`, there should be at least one trait bound.
+ // These invariants are utilized by `TyExt::dyn_trait()` and chalk.
let bounds = self.with_shifted_in(DebruijnIndex::ONE, |ctx| {
let mut bounds: Vec<_> = bounds
.iter()
@@ -1035,6 +1047,12 @@ impl<'a> TyLoweringContext<'a> {
return None;
}
+ if bounds.first().and_then(|b| b.trait_id()).is_none() {
+ // When there's no trait bound, that's an error. This happens when the trait refs
+ // are unresolved.
+ return None;
+ }
+
// As multiple occurrences of the same auto traits *are* permitted, we dedulicate the
// bounds. We shouldn't have repeated elements besides auto traits at this point.
bounds.dedup();
@@ -1046,7 +1064,8 @@ impl<'a> TyLoweringContext<'a> {
let bounds = crate::make_single_type_binders(bounds);
TyKind::Dyn(DynTy { bounds, lifetime: static_lifetime() }).intern(Interner)
} else {
- // FIXME: report error (additional non-auto traits or associated type rebound)
+ // FIXME: report error
+ // (additional non-auto traits, associated type rebound, or no resolved trait)
TyKind::Error.intern(Interner)
}
}
@@ -1139,11 +1158,28 @@ fn named_associated_type_shorthand_candidates<R>(
};
match res {
- TypeNs::SelfType(impl_id) => search(
+ TypeNs::SelfType(impl_id) => {
// we're _in_ the impl -- the binders get added back later. Correct,
// but it would be nice to make this more explicit
- db.impl_trait(impl_id)?.into_value_and_skipped_binders().0,
- ),
+ let trait_ref = db.impl_trait(impl_id)?.into_value_and_skipped_binders().0;
+
+ let impl_id_as_generic_def: GenericDefId = impl_id.into();
+ if impl_id_as_generic_def != def {
+ // `trait_ref` contains `BoundVar`s bound by impl's `Binders`, but here we need
+ // `BoundVar`s from `def`'s point of view.
+ // FIXME: A `HirDatabase` query may be handy if this process is needed in more
+ // places. It'd be almost identical as `impl_trait_query` where `resolver` would be
+ // of `def` instead of `impl_id`.
+ let starting_idx = generics(db.upcast(), def).len_self();
+ let subst = TyBuilder::subst_for_def(db, impl_id, None)
+ .fill_with_bound_vars(DebruijnIndex::INNERMOST, starting_idx)
+ .build();
+ let trait_ref = subst.apply(trait_ref, Interner);
+ search(trait_ref)
+ } else {
+ search(trait_ref)
+ }
+ }
TypeNs::GenericParam(param_id) => {
let predicates = db.generic_predicates_for_param(def, param_id.into(), assoc_name);
let res = predicates.iter().find_map(|pred| match pred.skip_binders().skip_binders() {
@@ -1160,10 +1196,18 @@ fn named_associated_type_shorthand_candidates<R>(
}
// Handle `Self::Type` referring to own associated type in trait definitions
if let GenericDefId::TraitId(trait_id) = param_id.parent() {
- let generics = generics(db.upcast(), trait_id.into());
- if generics.params.type_or_consts[param_id.local_id()].is_trait_self() {
+ let trait_generics = generics(db.upcast(), trait_id.into());
+ if trait_generics.params.type_or_consts[param_id.local_id()].is_trait_self() {
+ let def_generics = generics(db.upcast(), def);
+ let starting_idx = match def {
+ GenericDefId::TraitId(_) => 0,
+ // `def` is an item within trait. We need to substitute `BoundVar`s but
+ // remember that they are for parent (i.e. trait) generic params so they
+ // come after our own params.
+ _ => def_generics.len_self(),
+ };
let trait_ref = TyBuilder::trait_ref(db, trait_id)
- .fill_with_bound_vars(DebruijnIndex::INNERMOST, 0)
+ .fill_with_bound_vars(DebruijnIndex::INNERMOST, starting_idx)
.build();
return search(trait_ref);
}
@@ -1405,6 +1449,7 @@ pub(crate) fn generic_defaults_query(
let ctx =
TyLoweringContext::new(db, &resolver).with_type_param_mode(ParamLoweringMode::Variable);
let generic_params = generics(db.upcast(), def);
+ let parent_start_idx = generic_params.len_self();
let defaults = generic_params
.iter()
@@ -1417,19 +1462,17 @@ pub(crate) fn generic_defaults_query(
let val = unknown_const_as_generic(
db.const_param_ty(ConstParamId::from_unchecked(id)),
);
- return crate::make_binders_with_count(db, idx, &generic_params, val);
+ return make_binders(db, &generic_params, val);
}
};
let mut ty =
p.default.as_ref().map_or(TyKind::Error.intern(Interner), |t| ctx.lower_ty(t));
// Each default can only refer to previous parameters.
- // type variable default referring to parameter coming
- // after it. This is forbidden (FIXME: report
- // diagnostic)
- ty = fallback_bound_vars(ty, idx);
- let val = GenericArgData::Ty(ty).intern(Interner);
- crate::make_binders_with_count(db, idx, &generic_params, val)
+ // Type variable default referring to parameter coming
+ // after it is forbidden (FIXME: report diagnostic)
+ ty = fallback_bound_vars(ty, idx, parent_start_idx);
+ crate::make_binders(db, &generic_params, ty.cast(Interner))
})
.collect();
@@ -1446,15 +1489,14 @@ pub(crate) fn generic_defaults_recover(
// we still need one default per parameter
let defaults = generic_params
.iter_id()
- .enumerate()
- .map(|(count, id)| {
+ .map(|id| {
let val = match id {
itertools::Either::Left(_) => {
GenericArgData::Ty(TyKind::Error.intern(Interner)).intern(Interner)
}
itertools::Either::Right(id) => unknown_const_as_generic(db.const_param_ty(id)),
};
- crate::make_binders_with_count(db, count, &generic_params, val)
+ crate::make_binders(db, &generic_params, val)
})
.collect();
@@ -1633,6 +1675,19 @@ pub enum ValueTyDefId {
}
impl_from!(FunctionId, StructId, UnionId, EnumVariantId, ConstId, StaticId for ValueTyDefId);
+impl ValueTyDefId {
+ pub(crate) fn to_generic_def_id(self) -> Option<GenericDefId> {
+ match self {
+ Self::FunctionId(id) => Some(id.into()),
+ Self::StructId(id) => Some(id.into()),
+ Self::UnionId(id) => Some(id.into()),
+ Self::EnumVariantId(var) => Some(var.into()),
+ Self::ConstId(id) => Some(id.into()),
+ Self::StaticId(_) => None,
+ }
+ }
+}
+
/// Build the declared type of an item. This depends on the namespace; e.g. for
/// `struct Foo(usize)`, we have two types: The type of the struct itself, and
/// the constructor function `(usize) -> Foo` which lives in the values
@@ -1816,26 +1871,48 @@ pub(crate) fn const_or_path_to_chalk(
}
}
-/// This replaces any 'free' Bound vars in `s` (i.e. those with indices past
-/// num_vars_to_keep) by `TyKind::Unknown`.
+/// Replaces any 'free' `BoundVar`s in `s` by `TyKind::Error` from the perspective of generic
+/// parameter whose index is `param_index`. A `BoundVar` is free when it is or (syntactically)
+/// appears after the generic parameter of `param_index`.
fn fallback_bound_vars<T: TypeFoldable<Interner> + HasInterner<Interner = Interner>>(
s: T,
- num_vars_to_keep: usize,
+ param_index: usize,
+ parent_start: usize,
) -> T {
+ // Keep in mind that parent generic parameters, if any, come *after* those of the item in
+ // question. In the diagrams below, `c*` and `p*` represent generic parameters of the item and
+ // its parent respectively.
+ let is_allowed = |index| {
+ if param_index < parent_start {
+ // The parameter of `param_index` is one from the item in question. Any parent generic
+ // parameters or the item's generic parameters that come before `param_index` is
+ // allowed.
+ // [c1, .., cj, .., ck, p1, .., pl] where cj is `param_index`
+ // ^^^^^^ ^^^^^^^^^^ these are allowed
+ !(param_index..parent_start).contains(&index)
+ } else {
+ // The parameter of `param_index` is one from the parent generics. Only parent generic
+ // parameters that come before `param_index` are allowed.
+ // [c1, .., ck, p1, .., pj, .., pl] where pj is `param_index`
+ // ^^^^^^ these are allowed
+ (parent_start..param_index).contains(&index)
+ }
+ };
+
crate::fold_free_vars(
s,
|bound, binders| {
- if bound.index >= num_vars_to_keep && bound.debruijn == DebruijnIndex::INNERMOST {
- TyKind::Error.intern(Interner)
- } else {
+ if bound.index_if_innermost().map_or(true, is_allowed) {
bound.shifted_in_from(binders).to_ty(Interner)
+ } else {
+ TyKind::Error.intern(Interner)
}
},
|ty, bound, binders| {
- if bound.index >= num_vars_to_keep && bound.debruijn == DebruijnIndex::INNERMOST {
- unknown_const(ty.clone())
- } else {
+ if bound.index_if_innermost().map_or(true, is_allowed) {
bound.shifted_in_from(binders).to_const(Interner, ty)
+ } else {
+ unknown_const(ty.clone())
}
},
)
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs b/src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs
index d765fee0e..f80fb39c1 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs
@@ -103,6 +103,18 @@ impl From<crate::db::InternedClosureId> for chalk_ir::ClosureId<Interner> {
}
}
+impl From<chalk_ir::GeneratorId<Interner>> for crate::db::InternedGeneratorId {
+ fn from(id: chalk_ir::GeneratorId<Interner>) -> Self {
+ Self::from_intern_id(id.0)
+ }
+}
+
+impl From<crate::db::InternedGeneratorId> for chalk_ir::GeneratorId<Interner> {
+ fn from(id: crate::db::InternedGeneratorId) -> Self {
+ chalk_ir::GeneratorId(id.as_intern_id())
+ }
+}
+
pub fn to_foreign_def_id(id: TypeAliasId) -> ForeignDefId {
chalk_ir::ForeignDefId(salsa::InternKey::as_intern_id(&id))
}
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs
index 9a63d5013..3a1a3f4fd 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs
@@ -1,7 +1,7 @@
//! This module is concerned with finding methods that a given type provides.
//! For details about how this works in rustc, see the method lookup page in the
//! [rustc guide](https://rust-lang.github.io/rustc-guide/method-lookup.html)
-//! and the corresponding code mostly in librustc_typeck/check/method/probe.rs.
+//! and the corresponding code mostly in rustc_hir_analysis/check/method/probe.rs.
use std::{iter, ops::ControlFlow, sync::Arc};
use arrayvec::ArrayVec;
@@ -654,7 +654,7 @@ fn find_matching_impl(
let r = table.run_in_snapshot(|table| {
let impl_data = db.impl_data(impl_);
let substs =
- TyBuilder::subst_for_def(db, impl_).fill_with_inference_vars(table).build();
+ TyBuilder::subst_for_def(db, impl_, None).fill_with_inference_vars(table).build();
let impl_ty = db.impl_self_ty(impl_).substitute(Interner, &substs);
table
@@ -914,22 +914,10 @@ fn iterate_trait_method_candidates(
let db = table.db;
let env = table.trait_env.clone();
let self_is_array = matches!(self_ty.kind(Interner), chalk_ir::TyKind::Array(..));
- // if ty is `dyn Trait`, the trait doesn't need to be in scope
- let inherent_trait =
- self_ty.dyn_trait().into_iter().flat_map(|t| all_super_traits(db.upcast(), t));
- let env_traits = matches!(self_ty.kind(Interner), TyKind::Placeholder(_))
- // if we have `T: Trait` in the param env, the trait doesn't need to be in scope
- .then(|| {
- env.traits_in_scope_from_clauses(self_ty.clone())
- .flat_map(|t| all_super_traits(db.upcast(), t))
- })
- .into_iter()
- .flatten();
- let traits = inherent_trait.chain(env_traits).chain(traits_in_scope.iter().copied());
let canonical_self_ty = table.canonicalize(self_ty.clone()).value;
- 'traits: for t in traits {
+ 'traits: for &t in traits_in_scope {
let data = db.trait_data(t);
// Traits annotated with `#[rustc_skip_array_during_method_dispatch]` are skipped during
@@ -979,6 +967,44 @@ fn iterate_inherent_methods(
) -> ControlFlow<()> {
let db = table.db;
let env = table.trait_env.clone();
+
+ // For trait object types and placeholder types with trait bounds, the methods of the trait and
+ // its super traits are considered inherent methods. This matters because these methods have
+ // higher priority than the other traits' methods, which would be considered in
+ // `iterate_trait_method_candidates()` only after this function.
+ match self_ty.kind(Interner) {
+ TyKind::Placeholder(_) => {
+ let env = table.trait_env.clone();
+ let traits = env
+ .traits_in_scope_from_clauses(self_ty.clone())
+ .flat_map(|t| all_super_traits(db.upcast(), t));
+ iterate_inherent_trait_methods(
+ self_ty,
+ table,
+ name,
+ receiver_ty,
+ receiver_adjustments.clone(),
+ callback,
+ traits,
+ )?;
+ }
+ TyKind::Dyn(_) => {
+ if let Some(principal_trait) = self_ty.dyn_trait() {
+ let traits = all_super_traits(db.upcast(), principal_trait);
+ iterate_inherent_trait_methods(
+ self_ty,
+ table,
+ name,
+ receiver_ty,
+ receiver_adjustments.clone(),
+ callback,
+ traits.into_iter(),
+ )?;
+ }
+ }
+ _ => {}
+ }
+
let def_crates = match def_crates(db, self_ty, env.krate) {
Some(k) => k,
None => return ControlFlow::Continue(()),
@@ -1020,6 +1046,28 @@ fn iterate_inherent_methods(
}
return ControlFlow::Continue(());
+ fn iterate_inherent_trait_methods(
+ self_ty: &Ty,
+ table: &mut InferenceTable<'_>,
+ name: Option<&Name>,
+ receiver_ty: Option<&Ty>,
+ receiver_adjustments: Option<ReceiverAdjustments>,
+ callback: &mut dyn FnMut(ReceiverAdjustments, AssocItemId) -> ControlFlow<()>,
+ traits: impl Iterator<Item = TraitId>,
+ ) -> ControlFlow<()> {
+ let db = table.db;
+ for t in traits {
+ let data = db.trait_data(t);
+ for &(_, item) in data.items.iter() {
+ // We don't pass `visible_from_module` as all trait items should be visible.
+ if is_valid_candidate(table, name, receiver_ty, item, self_ty, None) {
+ callback(receiver_adjustments.clone().unwrap_or_default(), item)?;
+ }
+ }
+ }
+ ControlFlow::Continue(())
+ }
+
fn impls_for_self_ty(
impls: &InherentImpls,
self_ty: &Ty,
@@ -1099,10 +1147,9 @@ fn is_valid_candidate(
}));
if let ItemContainerId::ImplId(impl_id) = c.lookup(db.upcast()).container {
let self_ty_matches = table.run_in_snapshot(|table| {
- let subst =
- TyBuilder::subst_for_def(db, c).fill_with_inference_vars(table).build();
- let expected_self_ty =
- subst.apply(db.impl_self_ty(impl_id).skip_binders().clone(), Interner);
+ let expected_self_ty = TyBuilder::impl_self_ty(db, impl_id)
+ .fill_with_inference_vars(table)
+ .build();
table.unify(&expected_self_ty, &self_ty)
});
if !self_ty_matches {
@@ -1138,31 +1185,26 @@ fn is_valid_fn_candidate(
table.run_in_snapshot(|table| {
let container = fn_id.lookup(db.upcast()).container;
- let impl_subst = match container {
+ let (impl_subst, expect_self_ty) = match container {
ItemContainerId::ImplId(it) => {
- TyBuilder::subst_for_def(db, it).fill_with_inference_vars(table).build()
+ let subst =
+ TyBuilder::subst_for_def(db, it, None).fill_with_inference_vars(table).build();
+ let self_ty = db.impl_self_ty(it).substitute(Interner, &subst);
+ (subst, self_ty)
}
ItemContainerId::TraitId(it) => {
- TyBuilder::subst_for_def(db, it).fill_with_inference_vars(table).build()
+ let subst =
+ TyBuilder::subst_for_def(db, it, None).fill_with_inference_vars(table).build();
+ let self_ty = subst.at(Interner, 0).assert_ty_ref(Interner).clone();
+ (subst, self_ty)
}
_ => unreachable!(),
};
- let fn_subst = TyBuilder::subst_for_def(db, fn_id)
- .use_parent_substs(&impl_subst)
+ let fn_subst = TyBuilder::subst_for_def(db, fn_id, Some(impl_subst.clone()))
.fill_with_inference_vars(table)
.build();
- let expect_self_ty = match container {
- ItemContainerId::TraitId(_) => fn_subst.at(Interner, 0).assert_ty_ref(Interner).clone(),
- ItemContainerId::ImplId(impl_id) => {
- fn_subst.apply(db.impl_self_ty(impl_id).skip_binders().clone(), Interner)
- }
- // We should only get called for associated items (impl/trait)
- ItemContainerId::ModuleId(_) | ItemContainerId::ExternBlockId(_) => {
- unreachable!()
- }
- };
check_that!(table.unify(&expect_self_ty, self_ty));
if let Some(receiver_ty) = receiver_ty {
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests.rs
index d2f13e435..ebbc54101 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/tests.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests.rs
@@ -16,7 +16,7 @@ use base_db::{fixture::WithFixture, FileRange, SourceDatabaseExt};
use expect_test::Expect;
use hir_def::{
body::{Body, BodySourceMap, SyntheticSyntax},
- db::DefDatabase,
+ db::{DefDatabase, InternDatabase},
expr::{ExprId, PatId},
item_scope::ItemScope,
nameres::DefMap,
@@ -135,6 +135,10 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
let loc = it.lookup(&db);
loc.source(&db).value.syntax().text_range().start()
}
+ DefWithBodyId::VariantId(it) => {
+ let loc = db.lookup_intern_enum(it.parent);
+ loc.source(&db).value.syntax().text_range().start()
+ }
});
let mut unexpected_type_mismatches = String::new();
for def in defs {
@@ -388,6 +392,10 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
let loc = it.lookup(&db);
loc.source(&db).value.syntax().text_range().start()
}
+ DefWithBodyId::VariantId(it) => {
+ let loc = db.lookup_intern_enum(it.parent);
+ loc.source(&db).value.syntax().text_range().start()
+ }
});
for def in defs {
let (_body, source_map) = db.body_with_source_map(def);
@@ -453,6 +461,18 @@ fn visit_module(
let body = db.body(def);
visit_body(db, &body, cb);
}
+ ModuleDefId::AdtId(hir_def::AdtId::EnumId(it)) => {
+ db.enum_data(it)
+ .variants
+ .iter()
+ .map(|(id, _)| hir_def::EnumVariantId { parent: it, local_id: id })
+ .for_each(|it| {
+ let def = it.into();
+ cb(def);
+ let body = db.body(def);
+ visit_body(db, &body, cb);
+ });
+ }
ModuleDefId::TraitId(it) => {
let trait_data = db.trait_data(it);
for &(_, item) in trait_data.items.iter() {
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/coercion.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/coercion.rs
index bf59fadc2..d301595bc 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/coercion.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/coercion.rs
@@ -295,6 +295,24 @@ fn foo() {
}
#[test]
+fn generator_yield_return_coerce() {
+ check_no_mismatches(
+ r#"
+fn test() {
+ let g = || {
+ yield &1u32;
+ yield &&1u32;
+ if true {
+ return &1u32;
+ }
+ &&1u32
+ };
+}
+ "#,
+ );
+}
+
+#[test]
fn assign_coerce() {
check_no_mismatches(
r"
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/display_source_code.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/display_source_code.rs
index 240942e48..8a8ff08cf 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/display_source_code.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/display_source_code.rs
@@ -56,6 +56,28 @@ fn main() {
}
#[test]
+fn render_dyn_ty_independent_of_order() {
+ check_types_source_code(
+ r#"
+auto trait Send {}
+trait A {
+ type Assoc;
+}
+trait B: A {}
+
+fn test(
+ _: &(dyn A<Assoc = ()> + Send),
+ //^ &(dyn A<Assoc = ()> + Send)
+ _: &(dyn Send + A<Assoc = ()>),
+ //^ &(dyn A<Assoc = ()> + Send)
+ _: &dyn B<Assoc = ()>,
+ //^ &(dyn B<Assoc = ()>)
+) {}
+ "#,
+ );
+}
+
+#[test]
fn render_dyn_for_ty() {
// FIXME
check_types_source_code(
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs
index 81588a7c4..ac8edb841 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs
@@ -1219,6 +1219,40 @@ fn main() {
}
#[test]
+fn dyn_trait_method_priority() {
+ check_types(
+ r#"
+//- minicore: from
+trait Trait {
+ fn into(&self) -> usize { 0 }
+}
+
+fn foo(a: &dyn Trait) {
+ let _ = a.into();
+ //^usize
+}
+ "#,
+ );
+}
+
+#[test]
+fn trait_method_priority_for_placeholder_type() {
+ check_types(
+ r#"
+//- minicore: from
+trait Trait {
+ fn into(&self) -> usize { 0 }
+}
+
+fn foo<T: Trait>(a: &T) {
+ let _ = a.into();
+ //^usize
+}
+ "#,
+ );
+}
+
+#[test]
fn autoderef_visibility_field() {
check(
r#"
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/patterns.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/patterns.rs
index eb04bf877..74de33117 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/patterns.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/patterns.rs
@@ -1070,3 +1070,13 @@ fn main() {
"#,
);
}
+
+#[test]
+fn cfg_params() {
+ check_types(
+ r#"
+fn my_fn(#[cfg(feature = "feature")] u8: u8, u32: u32) {}
+ //^^^ u32
+"#,
+ );
+}
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
index 23e51a9c1..a155adcec 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
@@ -1488,7 +1488,6 @@ fn regression_11688_4() {
#[test]
fn gat_crash_1() {
- cov_mark::check!(ignore_gats);
check_no_mismatches(
r#"
trait ATrait {}
@@ -1527,30 +1526,22 @@ unsafe impl Storage for InlineStorage {
#[test]
fn gat_crash_3() {
- // FIXME: This test currently crashes rust analyzer in a debug build but not in a
- // release build (i.e. for the user). With the assumption that tests will always be run
- // in debug mode, we catch the unwind and expect that it panicked. See the
- // [`crate::utils::generics`] function for more information.
- cov_mark::check!(ignore_gats);
- std::panic::catch_unwind(|| {
- check_no_mismatches(
- r#"
+ check_no_mismatches(
+ r#"
trait Collection {
- type Item;
- type Member<T>: Collection<Item = T>;
- fn add(&mut self, value: Self::Item) -> Result<(), Self::Error>;
+type Item;
+type Member<T>: Collection<Item = T>;
+fn add(&mut self, value: Self::Item) -> Result<(), Self::Error>;
}
struct ConstGen<T, const N: usize> {
- data: [T; N],
+data: [T; N],
}
impl<T, const N: usize> Collection for ConstGen<T, N> {
- type Item = T;
- type Member<U> = ConstGen<U, N>;
+type Item = T;
+type Member<U> = ConstGen<U, N>;
}
- "#,
- );
- })
- .expect_err("must panic");
+ "#,
+ );
}
#[test]
@@ -1691,3 +1682,28 @@ fn macrostmts() -> u8 {
"#,
);
}
+
+#[test]
+fn dyn_with_unresolved_trait() {
+ check_types(
+ r#"
+fn foo(a: &dyn DoesNotExist) {
+ a.bar();
+ //^&{unknown}
+}
+ "#,
+ );
+}
+
+#[test]
+fn self_assoc_with_const_generics_crash() {
+ check_no_mismatches(
+ r#"
+trait Trait { type Item; }
+impl<T, const N: usize> Trait for [T; N] {
+ type Item = ();
+ fn f<U>(_: Self::Item) {}
+}
+ "#,
+ );
+}
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs
index 4ea103e5d..080e2ac1b 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs
@@ -1693,16 +1693,16 @@ fn infer_type_param() {
fn infer_const() {
check_infer(
r#"
- struct Foo;
- impl Foo { const ASSOC_CONST: u32 = 0; }
- const GLOBAL_CONST: u32 = 101;
- fn test() {
- const LOCAL_CONST: u32 = 99;
- let x = LOCAL_CONST;
- let z = GLOBAL_CONST;
- let id = Foo::ASSOC_CONST;
- }
- "#,
+struct Foo;
+impl Foo { const ASSOC_CONST: u32 = 0; }
+const GLOBAL_CONST: u32 = 101;
+fn test() {
+ const LOCAL_CONST: u32 = 99;
+ let x = LOCAL_CONST;
+ let z = GLOBAL_CONST;
+ let id = Foo::ASSOC_CONST;
+}
+"#,
expect![[r#"
48..49 '0': u32
79..82 '101': u32
@@ -1722,17 +1722,17 @@ fn infer_const() {
fn infer_static() {
check_infer(
r#"
- static GLOBAL_STATIC: u32 = 101;
- static mut GLOBAL_STATIC_MUT: u32 = 101;
- fn test() {
- static LOCAL_STATIC: u32 = 99;
- static mut LOCAL_STATIC_MUT: u32 = 99;
- let x = LOCAL_STATIC;
- let y = LOCAL_STATIC_MUT;
- let z = GLOBAL_STATIC;
- let w = GLOBAL_STATIC_MUT;
- }
- "#,
+static GLOBAL_STATIC: u32 = 101;
+static mut GLOBAL_STATIC_MUT: u32 = 101;
+fn test() {
+ static LOCAL_STATIC: u32 = 99;
+ static mut LOCAL_STATIC_MUT: u32 = 99;
+ let x = LOCAL_STATIC;
+ let y = LOCAL_STATIC_MUT;
+ let z = GLOBAL_STATIC;
+ let w = GLOBAL_STATIC_MUT;
+}
+"#,
expect![[r#"
28..31 '101': u32
69..72 '101': u32
@@ -1752,6 +1752,41 @@ fn infer_static() {
}
#[test]
+fn infer_enum_variant() {
+ check_infer(
+ r#"
+enum Foo {
+ A = 15,
+ B = Foo::A as isize + 1
+}
+"#,
+ expect![[r#"
+ 19..21 '15': isize
+ 31..37 'Foo::A': Foo
+ 31..46 'Foo::A as isize': isize
+ 31..50 'Foo::A...ze + 1': isize
+ 49..50 '1': isize
+ "#]],
+ );
+ check_infer(
+ r#"
+#[repr(u32)]
+enum Foo {
+ A = 15,
+ B = Foo::A as u32 + 1
+}
+"#,
+ expect![[r#"
+ 32..34 '15': u32
+ 44..50 'Foo::A': Foo
+ 44..57 'Foo::A as u32': u32
+ 44..61 'Foo::A...32 + 1': u32
+ 60..61 '1': u32
+ "#]],
+ );
+}
+
+#[test]
fn shadowing_primitive() {
check_types(
r#"
@@ -1918,6 +1953,88 @@ fn closure_return_inferred() {
}
#[test]
+fn generator_types_inferred() {
+ check_infer(
+ r#"
+//- minicore: generator, deref
+use core::ops::{Generator, GeneratorState};
+use core::pin::Pin;
+
+fn f(v: i64) {}
+fn test() {
+ let mut g = |r| {
+ let a = yield 0;
+ let a = yield 1;
+ let a = yield 2;
+ "return value"
+ };
+
+ match Pin::new(&mut g).resume(0usize) {
+ GeneratorState::Yielded(y) => { f(y); }
+ GeneratorState::Complete(r) => {}
+ }
+}
+ "#,
+ expect![[r#"
+ 70..71 'v': i64
+ 78..80 '{}': ()
+ 91..362 '{ ... } }': ()
+ 101..106 'mut g': |usize| yields i64 -> &str
+ 109..218 '|r| { ... }': |usize| yields i64 -> &str
+ 110..111 'r': usize
+ 113..218 '{ ... }': &str
+ 127..128 'a': usize
+ 131..138 'yield 0': usize
+ 137..138 '0': i64
+ 152..153 'a': usize
+ 156..163 'yield 1': usize
+ 162..163 '1': i64
+ 177..178 'a': usize
+ 181..188 'yield 2': usize
+ 187..188 '2': i64
+ 198..212 '"return value"': &str
+ 225..360 'match ... }': ()
+ 231..239 'Pin::new': fn new<&mut |usize| yields i64 -> &str>(&mut |usize| yields i64 -> &str) -> Pin<&mut |usize| yields i64 -> &str>
+ 231..247 'Pin::n...mut g)': Pin<&mut |usize| yields i64 -> &str>
+ 231..262 'Pin::n...usize)': GeneratorState<i64, &str>
+ 240..246 '&mut g': &mut |usize| yields i64 -> &str
+ 245..246 'g': |usize| yields i64 -> &str
+ 255..261 '0usize': usize
+ 273..299 'Genera...ded(y)': GeneratorState<i64, &str>
+ 297..298 'y': i64
+ 303..312 '{ f(y); }': ()
+ 305..306 'f': fn f(i64)
+ 305..309 'f(y)': ()
+ 307..308 'y': i64
+ 321..348 'Genera...ete(r)': GeneratorState<i64, &str>
+ 346..347 'r': &str
+ 352..354 '{}': ()
+ "#]],
+ );
+}
+
+#[test]
+fn generator_resume_yield_return_unit() {
+ check_no_mismatches(
+ r#"
+//- minicore: generator, deref
+use core::ops::{Generator, GeneratorState};
+use core::pin::Pin;
+fn test() {
+ let mut g = || {
+ let () = yield;
+ };
+
+ match Pin::new(&mut g).resume(()) {
+ GeneratorState::Yielded(()) => {}
+ GeneratorState::Complete(()) => {}
+ }
+}
+ "#,
+ );
+}
+
+#[test]
fn fn_pointer_return() {
check_infer(
r#"
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs
index 21a863197..555b6972f 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs
@@ -279,6 +279,10 @@ fn test() {
pub mod iter {
pub trait IntoIterator {
type Item;
+ type IntoIter: Iterator<Item = Self::Item>;
+ }
+ pub trait Iterator {
+ type Item;
}
}
pub mod prelude {
@@ -297,7 +301,13 @@ pub mod collections {
}
impl<T> IntoIterator for Vec<T> {
- type Item=T;
+ type Item = T;
+ type IntoIter = IntoIter<T>;
+ }
+
+ struct IntoIter<T> {}
+ impl<T> Iterator for IntoIter<T> {
+ type Item = T;
}
}
"#,
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/traits.rs b/src/tools/rust-analyzer/crates/hir-ty/src/traits.rs
index 77afeb321..c425f35ac 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/traits.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/traits.rs
@@ -1,6 +1,6 @@
//! Trait solving using Chalk.
-use std::env::var;
+use std::{env::var, sync::Arc};
use chalk_ir::GoalData;
use chalk_recursive::Cache;
@@ -12,8 +12,9 @@ use stdx::panic_context;
use syntax::SmolStr;
use crate::{
- db::HirDatabase, AliasEq, AliasTy, Canonical, DomainGoal, Goal, Guidance, InEnvironment,
- Interner, Solution, TraitRefExt, Ty, TyKind, WhereClause,
+ db::HirDatabase, infer::unify::InferenceTable, AliasEq, AliasTy, Canonical, DomainGoal, Goal,
+ Guidance, InEnvironment, Interner, ProjectionTy, ProjectionTyExt, Solution, TraitRefExt, Ty,
+ TyKind, WhereClause,
};
/// This controls how much 'time' we give the Chalk solver before giving up.
@@ -64,6 +65,16 @@ impl TraitEnvironment {
}
}
+pub(crate) fn normalize_projection_query(
+ db: &dyn HirDatabase,
+ projection: ProjectionTy,
+ env: Arc<TraitEnvironment>,
+) -> Ty {
+ let mut table = InferenceTable::new(db, env);
+ let ty = table.normalize_projection_ty(projection);
+ table.resolve_completely(ty)
+}
+
/// Solve a trait goal using Chalk.
pub(crate) fn trait_solve_query(
db: &dyn HirDatabase,
@@ -84,7 +95,7 @@ pub(crate) fn trait_solve_query(
..
}))) = &goal.value.goal.data(Interner)
{
- if let TyKind::BoundVar(_) = projection_ty.self_type_parameter(Interner).kind(Interner) {
+ if let TyKind::BoundVar(_) = projection_ty.self_type_parameter(db).kind(Interner) {
// Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible
return Some(Solution::Ambig(Guidance::Unknown));
}
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs b/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs
index d6638db02..e54bcb421 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs
@@ -4,7 +4,7 @@
use std::iter;
use base_db::CrateId;
-use chalk_ir::{fold::Shift, BoundVar, DebruijnIndex};
+use chalk_ir::{cast::Cast, fold::Shift, BoundVar, DebruijnIndex};
use hir_def::{
db::DefDatabase,
generics::{
@@ -24,8 +24,7 @@ use smallvec::{smallvec, SmallVec};
use syntax::SmolStr;
use crate::{
- db::HirDatabase, ChalkTraitId, ConstData, ConstValue, GenericArgData, Interner, Substitution,
- TraitRef, TraitRefExt, TyKind, WhereClause,
+ db::HirDatabase, ChalkTraitId, Interner, Substitution, TraitRef, TraitRefExt, WhereClause,
};
pub(crate) fn fn_traits(db: &dyn DefDatabase, krate: CrateId) -> impl Iterator<Item = TraitId> {
@@ -174,31 +173,6 @@ pub(super) fn associated_type_by_name_including_super_traits(
pub(crate) fn generics(db: &dyn DefDatabase, def: GenericDefId) -> Generics {
let parent_generics = parent_generic_def(db, def).map(|def| Box::new(generics(db, def)));
- if parent_generics.is_some() && matches!(def, GenericDefId::TypeAliasId(_)) {
- let params = db.generic_params(def);
- let parent_params = &parent_generics.as_ref().unwrap().params;
- let has_consts =
- params.iter().any(|(_, x)| matches!(x, TypeOrConstParamData::ConstParamData(_)));
- let parent_has_consts =
- parent_params.iter().any(|(_, x)| matches!(x, TypeOrConstParamData::ConstParamData(_)));
- return if has_consts || parent_has_consts {
- // XXX: treat const generic associated types as not existing to avoid crashes
- // (#11769)
- //
- // Note: Also crashes when the parent has const generics (also even if the GAT
- // doesn't use them), see `tests::regression::gat_crash_3` for an example.
- // Avoids that by disabling GATs when the parent (i.e. `impl` block) has
- // const generics (#12193).
- //
- // Chalk expects the inner associated type's parameters to come
- // *before*, not after the trait's generics as we've always done it.
- // Adapting to this requires a larger refactoring
- cov_mark::hit!(ignore_gats);
- Generics { def, params: Interned::new(Default::default()), parent_generics }
- } else {
- Generics { def, params, parent_generics }
- };
- }
Generics { def, params: db.generic_params(def), parent_generics }
}
@@ -221,23 +195,30 @@ impl Generics {
})
}
- /// Iterator over types and const params of parent, then self.
+ /// Iterator over types and const params of self, then parent.
pub(crate) fn iter<'a>(
&'a self,
) -> impl DoubleEndedIterator<Item = (TypeOrConstParamId, &'a TypeOrConstParamData)> + 'a {
let to_toc_id = |it: &'a Generics| {
move |(local_id, p)| (TypeOrConstParamId { parent: it.def, local_id }, p)
};
- self.parent_generics()
- .into_iter()
- .flat_map(move |it| it.params.iter().map(to_toc_id(it)))
- .chain(self.params.iter().map(to_toc_id(self)))
+ self.params.iter().map(to_toc_id(self)).chain(self.iter_parent())
+ }
+
+ /// Iterate over types and const params without parent params.
+ pub(crate) fn iter_self<'a>(
+ &'a self,
+ ) -> impl DoubleEndedIterator<Item = (TypeOrConstParamId, &'a TypeOrConstParamData)> + 'a {
+ let to_toc_id = |it: &'a Generics| {
+ move |(local_id, p)| (TypeOrConstParamId { parent: it.def, local_id }, p)
+ };
+ self.params.iter().map(to_toc_id(self))
}
/// Iterator over types and const params of parent.
pub(crate) fn iter_parent<'a>(
&'a self,
- ) -> impl Iterator<Item = (TypeOrConstParamId, &'a TypeOrConstParamData)> + 'a {
+ ) -> impl DoubleEndedIterator<Item = (TypeOrConstParamId, &'a TypeOrConstParamData)> + 'a {
self.parent_generics().into_iter().flat_map(|it| {
let to_toc_id =
move |(local_id, p)| (TypeOrConstParamId { parent: it.def, local_id }, p);
@@ -245,12 +226,18 @@ impl Generics {
})
}
+ /// Returns total number of generic parameters in scope, including those from parent.
pub(crate) fn len(&self) -> usize {
let parent = self.parent_generics().map_or(0, Generics::len);
let child = self.params.type_or_consts.len();
parent + child
}
+ /// Returns numbers of generic parameters excluding those from parent.
+ pub(crate) fn len_self(&self) -> usize {
+ self.params.type_or_consts.len()
+ }
+
/// (parent total, self param, type param list, const param list, impl trait)
pub(crate) fn provenance_split(&self) -> (usize, usize, usize, usize, usize) {
let ty_iter = || self.params.iter().filter_map(|x| x.1.type_param());
@@ -275,15 +262,17 @@ impl Generics {
if param.parent == self.def {
let (idx, (_local_id, data)) =
self.params.iter().enumerate().find(|(_, (idx, _))| *idx == param.local_id)?;
- let parent_len = self.parent_generics().map_or(0, Generics::len);
- Some((parent_len + idx, data))
+ Some((idx, data))
} else {
- self.parent_generics().and_then(|g| g.find_param(param))
+ self.parent_generics()
+ .and_then(|g| g.find_param(param))
+ // Remember that parent parameters come after parameters for self.
+ .map(|(idx, data)| (self.len_self() + idx, data))
}
}
- fn parent_generics(&self) -> Option<&Generics> {
- self.parent_generics.as_ref().map(|it| &**it)
+ pub(crate) fn parent_generics(&self) -> Option<&Generics> {
+ self.parent_generics.as_deref()
}
/// Returns a Substitution that replaces each parameter by a bound variable.
@@ -295,18 +284,10 @@ impl Generics {
Substitution::from_iter(
Interner,
self.iter_id().enumerate().map(|(idx, id)| match id {
- Either::Left(_) => GenericArgData::Ty(
- TyKind::BoundVar(BoundVar::new(debruijn, idx)).intern(Interner),
- )
- .intern(Interner),
- Either::Right(id) => GenericArgData::Const(
- ConstData {
- value: ConstValue::BoundVar(BoundVar::new(debruijn, idx)),
- ty: db.const_param_ty(id),
- }
- .intern(Interner),
- )
- .intern(Interner),
+ Either::Left(_) => BoundVar::new(debruijn, idx).to_ty(Interner).cast(Interner),
+ Either::Right(id) => BoundVar::new(debruijn, idx)
+ .to_const(Interner, db.const_param_ty(id))
+ .cast(Interner),
}),
)
}
@@ -316,18 +297,12 @@ impl Generics {
Substitution::from_iter(
Interner,
self.iter_id().map(|id| match id {
- Either::Left(id) => GenericArgData::Ty(
- TyKind::Placeholder(crate::to_placeholder_idx(db, id.into())).intern(Interner),
- )
- .intern(Interner),
- Either::Right(id) => GenericArgData::Const(
- ConstData {
- value: ConstValue::Placeholder(crate::to_placeholder_idx(db, id.into())),
- ty: db.const_param_ty(id),
- }
- .intern(Interner),
- )
- .intern(Interner),
+ Either::Left(id) => {
+ crate::to_placeholder_idx(db, id.into()).to_ty(Interner).cast(Interner)
+ }
+ Either::Right(id) => crate::to_placeholder_idx(db, id.into())
+ .to_const(Interner, db.const_param_ty(id))
+ .cast(Interner),
}),
)
}
diff --git a/src/tools/rust-analyzer/crates/hir/Cargo.toml b/src/tools/rust-analyzer/crates/hir/Cargo.toml
index 8e6a2441b..e1418de3c 100644
--- a/src/tools/rust-analyzer/crates/hir/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/hir/Cargo.toml
@@ -13,9 +13,9 @@ doctest = false
rustc-hash = "1.1.0"
either = "1.7.0"
arrayvec = "0.7.2"
-itertools = "0.10.3"
-smallvec = "1.9.0"
-once_cell = "1.12.0"
+itertools = "0.10.5"
+smallvec = "1.10.0"
+once_cell = "1.15.0"
stdx = { path = "../stdx", version = "0.0.0" }
syntax = { path = "../syntax", version = "0.0.0" }
diff --git a/src/tools/rust-analyzer/crates/hir/src/diagnostics.rs b/src/tools/rust-analyzer/crates/hir/src/diagnostics.rs
index 5edc16d8b..c5dc60f1e 100644
--- a/src/tools/rust-analyzer/crates/hir/src/diagnostics.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/diagnostics.rs
@@ -1,7 +1,7 @@
//! Re-export diagnostics such that clients of `hir` don't have to depend on
//! low-level crates.
//!
-//! This probably isn't the best way to do this -- ideally, diagnistics should
+//! This probably isn't the best way to do this -- ideally, diagnostics should
//! be expressed in terms of hir types themselves.
use base_db::CrateId;
use cfg::{CfgExpr, CfgOptions};
diff --git a/src/tools/rust-analyzer/crates/hir/src/display.rs b/src/tools/rust-analyzer/crates/hir/src/display.rs
index 0e29c52ad..27b2f445d 100644
--- a/src/tools/rust-analyzer/crates/hir/src/display.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/display.rs
@@ -492,6 +492,9 @@ impl HirDisplay for TypeAlias {
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
let data = f.db.type_alias_data(self.id);
write!(f, "type {}", data.name)?;
+ let def_id = GenericDefId::TypeAliasId(self.id);
+ write_generic_params(def_id, f)?;
+ write_where_clause(def_id, f)?;
if !data.bounds.is_empty() {
f.write_str(": ")?;
f.write_joined(&data.bounds, " + ")?;
diff --git a/src/tools/rust-analyzer/crates/hir/src/from_id.rs b/src/tools/rust-analyzer/crates/hir/src/from_id.rs
index 9c7558d19..f825a72c0 100644
--- a/src/tools/rust-analyzer/crates/hir/src/from_id.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/from_id.rs
@@ -140,6 +140,7 @@ impl From<DefWithBody> for DefWithBodyId {
DefWithBody::Function(it) => DefWithBodyId::FunctionId(it.id),
DefWithBody::Static(it) => DefWithBodyId::StaticId(it.id),
DefWithBody::Const(it) => DefWithBodyId::ConstId(it.id),
+ DefWithBody::Variant(it) => DefWithBodyId::VariantId(it.into()),
}
}
}
@@ -150,6 +151,7 @@ impl From<DefWithBodyId> for DefWithBody {
DefWithBodyId::FunctionId(it) => DefWithBody::Function(it.into()),
DefWithBodyId::StaticId(it) => DefWithBody::Static(it.into()),
DefWithBodyId::ConstId(it) => DefWithBody::Const(it.into()),
+ DefWithBodyId::VariantId(it) => DefWithBody::Variant(it.into()),
}
}
}
@@ -172,9 +174,7 @@ impl From<GenericDef> for GenericDefId {
GenericDef::Trait(it) => GenericDefId::TraitId(it.id),
GenericDef::TypeAlias(it) => GenericDefId::TypeAliasId(it.id),
GenericDef::Impl(it) => GenericDefId::ImplId(it.id),
- GenericDef::Variant(it) => {
- GenericDefId::EnumVariantId(EnumVariantId { parent: it.parent.id, local_id: it.id })
- }
+ GenericDef::Variant(it) => GenericDefId::EnumVariantId(it.into()),
GenericDef::Const(it) => GenericDefId::ConstId(it.id),
}
}
@@ -188,9 +188,7 @@ impl From<GenericDefId> for GenericDef {
GenericDefId::TraitId(it) => GenericDef::Trait(it.into()),
GenericDefId::TypeAliasId(it) => GenericDef::TypeAlias(it.into()),
GenericDefId::ImplId(it) => GenericDef::Impl(it.into()),
- GenericDefId::EnumVariantId(it) => {
- GenericDef::Variant(Variant { parent: it.parent.into(), id: it.local_id })
- }
+ GenericDefId::EnumVariantId(it) => GenericDef::Variant(it.into()),
GenericDefId::ConstId(it) => GenericDef::Const(it.into()),
}
}
diff --git a/src/tools/rust-analyzer/crates/hir/src/lib.rs b/src/tools/rust-analyzer/crates/hir/src/lib.rs
index e4bb63a86..f5324208c 100644
--- a/src/tools/rust-analyzer/crates/hir/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/lib.rs
@@ -39,7 +39,7 @@ use arrayvec::ArrayVec;
use base_db::{CrateDisplayName, CrateId, CrateOrigin, Edition, FileId, ProcMacroKind};
use either::Either;
use hir_def::{
- adt::{ReprKind, VariantData},
+ adt::{ReprData, VariantData},
body::{BodyDiagnostic, SyntheticSyntax},
expr::{BindingAnnotation, LabelId, Pat, PatId},
generics::{TypeOrConstParamData, TypeParamProvenance},
@@ -50,7 +50,7 @@ use hir_def::{
resolver::{HasResolver, Resolver},
src::HasSource as _,
AdtId, AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId, DefWithBodyId, EnumId,
- FunctionId, GenericDefId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
+ EnumVariantId, FunctionId, GenericDefId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
LocalEnumVariantId, LocalFieldId, Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId,
TraitId, TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
};
@@ -61,12 +61,10 @@ use hir_ty::{
diagnostics::BodyValidationDiagnostic,
method_resolution::{self, TyFingerprint},
primitive::UintTy,
- subst_prefix,
traits::FnTrait,
- AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast,
- ClosureId, DebruijnIndex, GenericArgData, InEnvironment, Interner, ParamKind,
- QuantifiedWhereClause, Scalar, Solution, Substitution, TraitEnvironment, TraitRefExt, Ty,
- TyBuilder, TyDefId, TyExt, TyKind, TyVariableKind, WhereClause,
+ AliasTy, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast, ClosureId,
+ GenericArgData, Interner, ParamKind, QuantifiedWhereClause, Scalar, Substitution,
+ TraitEnvironment, TraitRefExt, Ty, TyBuilder, TyDefId, TyExt, TyKind, WhereClause,
};
use itertools::Itertools;
use nameres::diagnostics::DefDiagnosticKind;
@@ -74,7 +72,7 @@ use once_cell::unsync::Lazy;
use rustc_hash::FxHashSet;
use stdx::{impl_from, never};
use syntax::{
- ast::{self, HasAttrs as _, HasDocComments, HasName},
+ ast::{self, Expr, HasAttrs as _, HasDocComments, HasName},
AstNode, AstPtr, SmolStr, SyntaxNodePtr, TextRange, T,
};
@@ -349,7 +347,10 @@ impl ModuleDef {
ModuleDef::Module(it) => it.id.into(),
ModuleDef::Const(it) => it.id.into(),
ModuleDef::Static(it) => it.id.into(),
- _ => return Vec::new(),
+ ModuleDef::Variant(it) => {
+ EnumVariantId { parent: it.parent.into(), local_id: it.id }.into()
+ }
+ ModuleDef::BuiltinType(_) | ModuleDef::Macro(_) => return Vec::new(),
};
let module = match self.module(db) {
@@ -378,10 +379,10 @@ impl ModuleDef {
ModuleDef::Function(it) => Some(it.into()),
ModuleDef::Const(it) => Some(it.into()),
ModuleDef::Static(it) => Some(it.into()),
+ ModuleDef::Variant(it) => Some(it.into()),
ModuleDef::Module(_)
| ModuleDef::Adt(_)
- | ModuleDef::Variant(_)
| ModuleDef::Trait(_)
| ModuleDef::TypeAlias(_)
| ModuleDef::Macro(_)
@@ -538,6 +539,30 @@ impl Module {
}
acc.extend(decl.diagnostics(db))
}
+ ModuleDef::Adt(adt) => {
+ match adt {
+ Adt::Struct(s) => {
+ for diag in db.struct_data_with_diagnostics(s.id).1.iter() {
+ emit_def_diagnostic(db, acc, diag);
+ }
+ }
+ Adt::Union(u) => {
+ for diag in db.union_data_with_diagnostics(u.id).1.iter() {
+ emit_def_diagnostic(db, acc, diag);
+ }
+ }
+ Adt::Enum(e) => {
+ for v in e.variants(db) {
+ acc.extend(ModuleDef::Variant(v).diagnostics(db));
+ }
+
+ for diag in db.enum_data_with_diagnostics(e.id).1.iter() {
+ emit_def_diagnostic(db, acc, diag);
+ }
+ }
+ }
+ acc.extend(decl.diagnostics(db))
+ }
_ => acc.extend(decl.diagnostics(db)),
}
}
@@ -582,8 +607,13 @@ impl Module {
/// Finds a path that can be used to refer to the given item from within
/// this module, if possible.
- pub fn find_use_path(self, db: &dyn DefDatabase, item: impl Into<ItemInNs>) -> Option<ModPath> {
- hir_def::find_path::find_path(db, item.into().into(), self.into())
+ pub fn find_use_path(
+ self,
+ db: &dyn DefDatabase,
+ item: impl Into<ItemInNs>,
+ prefer_no_std: bool,
+ ) -> Option<ModPath> {
+ hir_def::find_path::find_path(db, item.into().into(), self.into(), prefer_no_std)
}
/// Finds a path that can be used to refer to the given item from within
@@ -593,8 +623,15 @@ impl Module {
db: &dyn DefDatabase,
item: impl Into<ItemInNs>,
prefix_kind: PrefixKind,
+ prefer_no_std: bool,
) -> Option<ModPath> {
- hir_def::find_path::find_path_prefixed(db, item.into().into(), self.into(), prefix_kind)
+ hir_def::find_path::find_path_prefixed(
+ db,
+ item.into().into(),
+ self.into(),
+ prefix_kind,
+ prefer_no_std,
+ )
}
}
@@ -863,7 +900,7 @@ impl Struct {
Type::from_def(db, self.id)
}
- pub fn repr(self, db: &dyn HirDatabase) -> Option<ReprKind> {
+ pub fn repr(self, db: &dyn HirDatabase) -> Option<ReprData> {
db.struct_data(self.id).repr.clone()
}
@@ -941,6 +978,21 @@ impl Enum {
pub fn ty(self, db: &dyn HirDatabase) -> Type {
Type::from_def(db, self.id)
}
+
+ /// The type of the enum variant bodies.
+ pub fn variant_body_ty(self, db: &dyn HirDatabase) -> Type {
+ Type::new_for_crate(
+ self.id.lookup(db.upcast()).container.krate(),
+ TyBuilder::builtin(match db.enum_data(self.id).variant_body_type() {
+ Either::Left(builtin) => hir_def::builtin_type::BuiltinType::Int(builtin),
+ Either::Right(builtin) => hir_def::builtin_type::BuiltinType::Uint(builtin),
+ }),
+ )
+ }
+
+ pub fn is_data_carrying(self, db: &dyn HirDatabase) -> bool {
+ self.variants(db).iter().any(|v| !matches!(v.kind(db), StructKind::Unit))
+ }
}
impl HasVisibility for Enum {
@@ -949,6 +1001,12 @@ impl HasVisibility for Enum {
}
}
+impl From<&Variant> for DefWithBodyId {
+ fn from(&v: &Variant) -> Self {
+ DefWithBodyId::VariantId(v.into())
+ }
+}
+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Variant {
pub(crate) parent: Enum,
@@ -983,6 +1041,14 @@ impl Variant {
pub(crate) fn variant_data(self, db: &dyn HirDatabase) -> Arc<VariantData> {
db.enum_data(self.parent.id).variants[self.id].variant_data.clone()
}
+
+ pub fn value(self, db: &dyn HirDatabase) -> Option<Expr> {
+ self.source(db)?.value.expr()
+ }
+
+ pub fn eval(self, db: &dyn HirDatabase) -> Result<ComputedExpr, ConstEvalError> {
+ db.const_eval_variant(self.into())
+ }
}
/// Variants inherit visibility from the parent enum.
@@ -1023,7 +1089,7 @@ impl Adt {
pub fn ty_with_args(self, db: &dyn HirDatabase, args: &[Type]) -> Type {
let id = AdtId::from(self);
let mut it = args.iter().map(|t| t.ty.clone());
- let ty = TyBuilder::def_ty(db, id.into())
+ let ty = TyBuilder::def_ty(db, id.into(), None)
.fill(|x| {
let r = it.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
match x {
@@ -1118,8 +1184,9 @@ pub enum DefWithBody {
Function(Function),
Static(Static),
Const(Const),
+ Variant(Variant),
}
-impl_from!(Function, Const, Static for DefWithBody);
+impl_from!(Function, Const, Static, Variant for DefWithBody);
impl DefWithBody {
pub fn module(self, db: &dyn HirDatabase) -> Module {
@@ -1127,6 +1194,7 @@ impl DefWithBody {
DefWithBody::Const(c) => c.module(db),
DefWithBody::Function(f) => f.module(db),
DefWithBody::Static(s) => s.module(db),
+ DefWithBody::Variant(v) => v.module(db),
}
}
@@ -1135,6 +1203,7 @@ impl DefWithBody {
DefWithBody::Function(f) => Some(f.name(db)),
DefWithBody::Static(s) => Some(s.name(db)),
DefWithBody::Const(c) => c.name(db),
+ DefWithBody::Variant(v) => Some(v.name(db)),
}
}
@@ -1144,6 +1213,7 @@ impl DefWithBody {
DefWithBody::Function(it) => it.ret_type(db),
DefWithBody::Static(it) => it.ty(db),
DefWithBody::Const(it) => it.ty(db),
+ DefWithBody::Variant(it) => it.parent.variant_body_ty(db),
}
}
@@ -1152,6 +1222,7 @@ impl DefWithBody {
DefWithBody::Function(it) => it.id.into(),
DefWithBody::Static(it) => it.id.into(),
DefWithBody::Const(it) => it.id.into(),
+ DefWithBody::Variant(it) => it.into(),
}
}
@@ -1368,6 +1439,7 @@ impl DefWithBody {
DefWithBody::Function(it) => it.into(),
DefWithBody::Static(it) => it.into(),
DefWithBody::Const(it) => it.into(),
+ DefWithBody::Variant(it) => it.into(),
};
for diag in hir_ty::diagnostics::incorrect_case(db, krate, def.into()) {
acc.push(diag.into())
@@ -2474,7 +2546,7 @@ impl TypeParam {
let resolver = self.id.parent().resolver(db.upcast());
let ty = params.get(local_idx)?.clone();
let subst = TyBuilder::placeholder_subst(db, self.id.parent());
- let ty = ty.substitute(Interner, &subst_prefix(&subst, local_idx));
+ let ty = ty.substitute(Interner, &subst);
match ty.data(Interner) {
GenericArgData::Ty(x) => Some(Type::new_with_resolver_inner(db, &resolver, x.clone())),
_ => None,
@@ -2728,7 +2800,22 @@ impl Type {
}
fn from_def(db: &dyn HirDatabase, def: impl HasResolver + Into<TyDefId>) -> Type {
- let ty = TyBuilder::def_ty(db, def.into()).fill_with_unknown().build();
+ let ty_def = def.into();
+ let parent_subst = match ty_def {
+ TyDefId::TypeAliasId(id) => match id.lookup(db.upcast()).container {
+ ItemContainerId::TraitId(id) => {
+ let subst = TyBuilder::subst_for_def(db, id, None).fill_with_unknown().build();
+ Some(subst)
+ }
+ ItemContainerId::ImplId(id) => {
+ let subst = TyBuilder::subst_for_def(db, id, None).fill_with_unknown().build();
+ Some(subst)
+ }
+ _ => None,
+ },
+ _ => None,
+ };
+ let ty = TyBuilder::def_ty(db, ty_def, parent_subst).fill_with_unknown().build();
Type::new(db, def, ty)
}
@@ -2868,7 +2955,11 @@ impl Type {
alias: TypeAlias,
) -> Option<Type> {
let mut args = args.iter();
- let projection = TyBuilder::assoc_type_projection(db, alias.id)
+ let trait_id = match alias.id.lookup(db.upcast()).container {
+ ItemContainerId::TraitId(id) => id,
+ _ => unreachable!("non assoc type alias reached in normalize_trait_assoc_type()"),
+ };
+ let parent_subst = TyBuilder::subst_for_def(db, trait_id, None)
.push(self.ty.clone())
.fill(|x| {
// FIXME: this code is not covered in tests.
@@ -2880,27 +2971,14 @@ impl Type {
}
})
.build();
- let goal = hir_ty::make_canonical(
- InEnvironment::new(
- &self.env.env,
- AliasEq {
- alias: AliasTy::Projection(projection),
- ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
- .intern(Interner),
- }
- .cast(Interner),
- ),
- [TyVariableKind::General].into_iter(),
- );
+ // FIXME: We don't handle GATs yet.
+ let projection = TyBuilder::assoc_type_projection(db, alias.id, Some(parent_subst)).build();
- match db.trait_solve(self.env.krate, goal)? {
- Solution::Unique(s) => s
- .value
- .subst
- .as_slice(Interner)
- .first()
- .map(|ty| self.derived(ty.assert_ty_ref(Interner).clone())),
- Solution::Ambig(_) => None,
+ let ty = db.normalize_projection(projection, self.env.clone());
+ if ty.is_unknown() {
+ None
+ } else {
+ Some(self.derived(ty))
}
}
@@ -2944,7 +3022,7 @@ impl Type {
let adt = adt_id.into();
match adt {
- Adt::Struct(s) => matches!(s.repr(db), Some(ReprKind::Packed)),
+ Adt::Struct(s) => matches!(s.repr(db), Some(ReprData { packed: true, .. })),
_ => false,
}
}
diff --git a/src/tools/rust-analyzer/crates/hir/src/semantics.rs b/src/tools/rust-analyzer/crates/hir/src/semantics.rs
index 416b6f580..119ec3210 100644
--- a/src/tools/rust-analyzer/crates/hir/src/semantics.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/semantics.rs
@@ -257,6 +257,11 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
pub fn original_ast_node<N: AstNode>(&self, node: N) -> Option<N> {
self.imp.original_ast_node(node)
}
+ /// Attempts to map the node out of macro expanded files.
+ /// This only work for attribute expansions, as other ones do not have nodes as input.
+ pub fn original_syntax_node(&self, node: &SyntaxNode) -> Option<SyntaxNode> {
+ self.imp.original_syntax_node(node)
+ }
pub fn diagnostics_display_range(&self, diagnostics: InFile<SyntaxNodePtr>) -> FileRange {
self.imp.diagnostics_display_range(diagnostics)
@@ -956,6 +961,16 @@ impl<'db> SemanticsImpl<'db> {
)
}
+ fn original_syntax_node(&self, node: &SyntaxNode) -> Option<SyntaxNode> {
+ let InFile { file_id, .. } = self.find_file(node);
+ InFile::new(file_id, node).original_syntax_node(self.db.upcast()).map(
+ |InFile { file_id, value }| {
+ self.cache(find_root(&value), file_id);
+ value
+ },
+ )
+ }
+
fn diagnostics_display_range(&self, src: InFile<SyntaxNodePtr>) -> FileRange {
let root = self.parse_or_expand(src.file_id).unwrap();
let node = src.map(|it| it.to_node(&root));
diff --git a/src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs b/src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs
index ba9a1cfb6..fa45e3c12 100644
--- a/src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/semantics/source_to_def.rs
@@ -115,7 +115,7 @@ pub(super) struct SourceToDefCtx<'a, 'b> {
}
impl SourceToDefCtx<'_, '_> {
- pub(super) fn file_to_def(&mut self, file: FileId) -> SmallVec<[ModuleId; 1]> {
+ pub(super) fn file_to_def(&self, file: FileId) -> SmallVec<[ModuleId; 1]> {
let _p = profile::span("SourceBinder::to_module_def");
let mut mods = SmallVec::new();
for &crate_id in self.db.relevant_crates(file).iter() {
@@ -130,7 +130,7 @@ impl SourceToDefCtx<'_, '_> {
mods
}
- pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> {
+ pub(super) fn module_to_def(&self, src: InFile<ast::Module>) -> Option<ModuleId> {
let _p = profile::span("module_to_def");
let parent_declaration = src
.syntax()
@@ -151,7 +151,7 @@ impl SourceToDefCtx<'_, '_> {
Some(def_map.module_id(child_id))
}
- pub(super) fn source_file_to_def(&mut self, src: InFile<ast::SourceFile>) -> Option<ModuleId> {
+ pub(super) fn source_file_to_def(&self, src: InFile<ast::SourceFile>) -> Option<ModuleId> {
let _p = profile::span("source_file_to_def");
let file_id = src.file_id.original_file(self.db.upcast());
self.file_to_def(file_id).get(0).copied()
@@ -384,7 +384,7 @@ impl SourceToDefCtx<'_, '_> {
} else {
let it = ast::Variant::cast(container.value)?;
let def = self.enum_variant_to_def(InFile::new(container.file_id, it))?;
- VariantId::from(def).into()
+ DefWithBodyId::from(def).into()
};
Some(cont)
}
diff --git a/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs b/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs
index 342912b67..07bae2b38 100644
--- a/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs
@@ -22,7 +22,7 @@ use hir_def::{
resolver::{resolver_for_scope, Resolver, TypeNs, ValueNs},
type_ref::Mutability,
AsMacroCall, AssocItemId, DefWithBodyId, FieldId, FunctionId, ItemContainerId, LocalFieldId,
- Lookup, ModuleDefId, VariantId,
+ Lookup, ModuleDefId, TraitId, VariantId,
};
use hir_expand::{
builtin_fn_macro::BuiltinFnLikeExpander,
@@ -302,10 +302,15 @@ impl SourceAnalyzer {
}
}
+ let future_trait = db
+ .lang_item(self.resolver.krate(), hir_expand::name![future_trait].to_smol_str())?
+ .as_trait()?;
let poll_fn = db
.lang_item(self.resolver.krate(), hir_expand::name![poll].to_smol_str())?
.as_function()?;
- let substs = hir_ty::TyBuilder::subst_for_def(db, poll_fn).push(ty.clone()).build();
+ // HACK: subst for `poll()` coincides with that for `Future` because `poll()` itself
+ // doesn't have any generic parameters, so we skip building another subst for `poll()`.
+ let substs = hir_ty::TyBuilder::subst_for_def(db, future_trait, None).push(ty).build();
Some(self.resolve_impl_method_or_trait_def(db, poll_fn, &substs))
}
@@ -321,8 +326,10 @@ impl SourceAnalyzer {
};
let ty = self.ty_of_expr(db, &prefix_expr.expr()?.into())?;
- let op_fn = self.lang_trait_fn(db, &lang_item_name, &lang_item_name)?;
- let substs = hir_ty::TyBuilder::subst_for_def(db, op_fn).push(ty.clone()).build();
+ let (op_trait, op_fn) = self.lang_trait_fn(db, &lang_item_name, &lang_item_name)?;
+ // HACK: subst for all methods coincides with that for their trait because the methods
+ // don't have any generic parameters, so we skip building another subst for the methods.
+ let substs = hir_ty::TyBuilder::subst_for_def(db, op_trait, None).push(ty.clone()).build();
Some(self.resolve_impl_method_or_trait_def(db, op_fn, &substs))
}
@@ -337,8 +344,10 @@ impl SourceAnalyzer {
let lang_item_name = name![index];
- let op_fn = self.lang_trait_fn(db, &lang_item_name, &lang_item_name)?;
- let substs = hir_ty::TyBuilder::subst_for_def(db, op_fn)
+ let (op_trait, op_fn) = self.lang_trait_fn(db, &lang_item_name, &lang_item_name)?;
+ // HACK: subst for all methods coincides with that for their trait because the methods
+ // don't have any generic parameters, so we skip building another subst for the methods.
+ let substs = hir_ty::TyBuilder::subst_for_def(db, op_trait, None)
.push(base_ty.clone())
.push(index_ty.clone())
.build();
@@ -354,10 +363,14 @@ impl SourceAnalyzer {
let lhs = self.ty_of_expr(db, &binop_expr.lhs()?.into())?;
let rhs = self.ty_of_expr(db, &binop_expr.rhs()?.into())?;
- let op_fn = lang_names_for_bin_op(op)
+ let (op_trait, op_fn) = lang_names_for_bin_op(op)
.and_then(|(name, lang_item)| self.lang_trait_fn(db, &lang_item, &name))?;
- let substs =
- hir_ty::TyBuilder::subst_for_def(db, op_fn).push(lhs.clone()).push(rhs.clone()).build();
+ // HACK: subst for `index()` coincides with that for `Index` because `index()` itself
+ // doesn't have any generic parameters, so we skip building another subst for `index()`.
+ let substs = hir_ty::TyBuilder::subst_for_def(db, op_trait, None)
+ .push(lhs.clone())
+ .push(rhs.clone())
+ .build();
Some(self.resolve_impl_method_or_trait_def(db, op_fn, &substs))
}
@@ -371,7 +384,13 @@ impl SourceAnalyzer {
let op_fn =
db.lang_item(self.resolver.krate(), name![branch].to_smol_str())?.as_function()?;
- let substs = hir_ty::TyBuilder::subst_for_def(db, op_fn).push(ty.clone()).build();
+ let op_trait = match op_fn.lookup(db.upcast()).container {
+ ItemContainerId::TraitId(id) => id,
+ _ => return None,
+ };
+ // HACK: subst for `branch()` coincides with that for `Try` because `branch()` itself
+ // doesn't have any generic parameters, so we skip building another subst for `branch()`.
+ let substs = hir_ty::TyBuilder::subst_for_def(db, op_trait, None).push(ty.clone()).build();
Some(self.resolve_impl_method_or_trait_def(db, op_fn, &substs))
}
@@ -799,9 +818,10 @@ impl SourceAnalyzer {
db: &dyn HirDatabase,
lang_trait: &Name,
method_name: &Name,
- ) -> Option<FunctionId> {
- db.trait_data(db.lang_item(self.resolver.krate(), lang_trait.to_smol_str())?.as_trait()?)
- .method_by_name(method_name)
+ ) -> Option<(TraitId, FunctionId)> {
+ let trait_id = db.lang_item(self.resolver.krate(), lang_trait.to_smol_str())?.as_trait()?;
+ let fn_id = db.trait_data(trait_id).method_by_name(method_name)?;
+ Some((trait_id, fn_id))
}
fn ty_of_expr(&self, db: &dyn HirDatabase, expr: &ast::Expr) -> Option<&Ty> {
diff --git a/src/tools/rust-analyzer/crates/hir/src/symbols.rs b/src/tools/rust-analyzer/crates/hir/src/symbols.rs
index 616a406c7..fd78decda 100644
--- a/src/tools/rust-analyzer/crates/hir/src/symbols.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/symbols.rs
@@ -244,6 +244,10 @@ impl<'a> SymbolCollector<'a> {
DefWithBodyId::ConstId(id) => Some(
id.lookup(self.db.upcast()).source(self.db.upcast()).value.name()?.text().into(),
),
+ DefWithBodyId::VariantId(id) => Some({
+ let db = self.db.upcast();
+ id.parent.lookup(db).source(db).value.name()?.text().into()
+ }),
}
}
diff --git a/src/tools/rust-analyzer/crates/ide-assists/Cargo.toml b/src/tools/rust-analyzer/crates/ide-assists/Cargo.toml
index fca09d384..57a41f3d9 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/ide-assists/Cargo.toml
@@ -12,7 +12,7 @@ doctest = false
[dependencies]
cov-mark = "2.0.0-pre.1"
-itertools = "0.10.3"
+itertools = "0.10.5"
either = "1.7.0"
stdx = { path = "../stdx", version = "0.0.0" }
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/assist_config.rs b/src/tools/rust-analyzer/crates/ide-assists/src/assist_config.rs
index d4d148c77..60d1588a4 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/assist_config.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/assist_config.rs
@@ -13,4 +13,5 @@ pub struct AssistConfig {
pub snippet_cap: Option<SnippetCap>,
pub allowed: Option<Vec<AssistKind>>,
pub insert_use: InsertUseConfig,
+ pub prefer_no_std: bool,
}
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs
index 1a7919a5a..73f4db4e5 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/add_missing_match_arms.rs
@@ -87,7 +87,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
.into_iter()
.filter_map(|variant| {
Some((
- build_pat(ctx.db(), module, variant)?,
+ build_pat(ctx.db(), module, variant, ctx.config.prefer_no_std)?,
variant.should_be_hidden(ctx.db(), module.krate()),
))
})
@@ -132,8 +132,9 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
let is_hidden = variants
.iter()
.any(|variant| variant.should_be_hidden(ctx.db(), module.krate()));
- let patterns =
- variants.into_iter().filter_map(|variant| build_pat(ctx.db(), module, variant));
+ let patterns = variants.into_iter().filter_map(|variant| {
+ build_pat(ctx.db(), module, variant, ctx.config.prefer_no_std)
+ });
(ast::Pat::from(make::tuple_pat(patterns)), is_hidden)
})
@@ -349,10 +350,16 @@ fn resolve_tuple_of_enum_def(
.collect()
}
-fn build_pat(db: &RootDatabase, module: hir::Module, var: ExtendedVariant) -> Option<ast::Pat> {
+fn build_pat(
+ db: &RootDatabase,
+ module: hir::Module,
+ var: ExtendedVariant,
+ prefer_no_std: bool,
+) -> Option<ast::Pat> {
match var {
ExtendedVariant::Variant(var) => {
- let path = mod_path_to_ast(&module.find_use_path(db, ModuleDef::from(var))?);
+ let path =
+ mod_path_to_ast(&module.find_use_path(db, ModuleDef::from(var), prefer_no_std)?);
// FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though
let pat: ast::Pat = match var.source(db)?.value.kind() {
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/auto_import.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/auto_import.rs
index 949cf3167..678dc877d 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/auto_import.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/auto_import.rs
@@ -89,8 +89,11 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel};
// ```
pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let (import_assets, syntax_under_caret) = find_importable_node(ctx)?;
- let mut proposed_imports =
- import_assets.search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind);
+ let mut proposed_imports = import_assets.search_for_imports(
+ &ctx.sema,
+ ctx.config.insert_use.prefix_kind,
+ ctx.config.prefer_no_std,
+ );
if proposed_imports.is_empty() {
return None;
}
@@ -153,6 +156,8 @@ pub(super) fn find_importable_node(
{
ImportAssets::for_method_call(&method_under_caret, &ctx.sema)
.zip(Some(method_under_caret.syntax().clone().into()))
+ } else if let Some(_) = ctx.find_node_at_offset_with_descend::<ast::Param>() {
+ None
} else if let Some(pat) = ctx
.find_node_at_offset_with_descend::<ast::IdentPat>()
.filter(ast::IdentPat::is_simple_ident)
@@ -266,6 +271,20 @@ mod tests {
}
#[test]
+ fn ignore_parameter_name() {
+ check_assist_not_applicable(
+ auto_import,
+ r"
+ mod foo {
+ pub mod bar {}
+ }
+
+ fn foo(bar$0: &str) {}
+ ",
+ );
+ }
+
+ #[test]
fn prefer_shorter_paths() {
let before = r"
//- /main.rs crate:main deps:foo,bar
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_into_to_from.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_into_to_from.rs
index 30f6dd41a..95d11abe8 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_into_to_from.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_into_to_from.rs
@@ -50,7 +50,7 @@ pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext<'_>) -
_ => return None,
};
- mod_path_to_ast(&module.find_use_path(ctx.db(), src_type_def)?)
+ mod_path_to_ast(&module.find_use_path(ctx.db(), src_type_def, ctx.config.prefer_no_std)?)
};
let dest_type = match &ast_trait {
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs
new file mode 100644
index 000000000..8d11e0bac
--- /dev/null
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs
@@ -0,0 +1,822 @@
+use either::Either;
+use ide_db::defs::Definition;
+use itertools::Itertools;
+use syntax::{
+ ast::{self, AstNode, HasGenericParams, HasVisibility},
+ match_ast, SyntaxKind, SyntaxNode,
+};
+
+use crate::{assist_context::SourceChangeBuilder, AssistContext, AssistId, AssistKind, Assists};
+
+// Assist: convert_named_struct_to_tuple_struct
+//
+// Converts struct with named fields to tuple struct, and analogously for enum variants with named
+// fields.
+//
+// ```
+// struct Point$0 { x: f32, y: f32 }
+//
+// impl Point {
+// pub fn new(x: f32, y: f32) -> Self {
+// Point { x, y }
+// }
+//
+// pub fn x(&self) -> f32 {
+// self.x
+// }
+//
+// pub fn y(&self) -> f32 {
+// self.y
+// }
+// }
+// ```
+// ->
+// ```
+// struct Point(f32, f32);
+//
+// impl Point {
+// pub fn new(x: f32, y: f32) -> Self {
+// Point(x, y)
+// }
+//
+// pub fn x(&self) -> f32 {
+// self.0
+// }
+//
+// pub fn y(&self) -> f32 {
+// self.1
+// }
+// }
+// ```
+pub(crate) fn convert_named_struct_to_tuple_struct(
+ acc: &mut Assists,
+ ctx: &AssistContext<'_>,
+) -> Option<()> {
+ let strukt = ctx
+ .find_node_at_offset::<ast::Struct>()
+ .map(Either::Left)
+ .or_else(|| ctx.find_node_at_offset::<ast::Variant>().map(Either::Right))?;
+ let field_list = strukt.as_ref().either(|s| s.field_list(), |v| v.field_list())?;
+ let record_fields = match field_list {
+ ast::FieldList::RecordFieldList(it) => it,
+ ast::FieldList::TupleFieldList(_) => return None,
+ };
+ let strukt_def = match &strukt {
+ Either::Left(s) => Either::Left(ctx.sema.to_def(s)?),
+ Either::Right(v) => Either::Right(ctx.sema.to_def(v)?),
+ };
+ let target = strukt.as_ref().either(|s| s.syntax(), |v| v.syntax()).text_range();
+
+ acc.add(
+ AssistId("convert_named_struct_to_tuple_struct", AssistKind::RefactorRewrite),
+ "Convert to tuple struct",
+ target,
+ |edit| {
+ edit_field_references(ctx, edit, record_fields.fields());
+ edit_struct_references(ctx, edit, strukt_def);
+ edit_struct_def(ctx, edit, &strukt, record_fields);
+ },
+ )
+}
+
+fn edit_struct_def(
+ ctx: &AssistContext<'_>,
+ edit: &mut SourceChangeBuilder,
+ strukt: &Either<ast::Struct, ast::Variant>,
+ record_fields: ast::RecordFieldList,
+) {
+ let tuple_fields = record_fields
+ .fields()
+ .filter_map(|f| Some(ast::make::tuple_field(f.visibility(), f.ty()?)));
+ let tuple_fields = ast::make::tuple_field_list(tuple_fields);
+ let record_fields_text_range = record_fields.syntax().text_range();
+
+ edit.edit_file(ctx.file_id());
+ edit.replace(record_fields_text_range, tuple_fields.syntax().text());
+
+ if let Either::Left(strukt) = strukt {
+ if let Some(w) = strukt.where_clause() {
+ let mut where_clause = w.to_string();
+ if where_clause.ends_with(',') {
+ where_clause.pop();
+ }
+ where_clause.push(';');
+
+ edit.delete(w.syntax().text_range());
+ edit.insert(record_fields_text_range.end(), ast::make::tokens::single_newline().text());
+ edit.insert(record_fields_text_range.end(), where_clause);
+ edit.insert(record_fields_text_range.end(), ast::make::tokens::single_newline().text());
+
+ if let Some(tok) = strukt
+ .generic_param_list()
+ .and_then(|l| l.r_angle_token())
+ .and_then(|tok| tok.next_token())
+ .filter(|tok| tok.kind() == SyntaxKind::WHITESPACE)
+ {
+ edit.delete(tok.text_range());
+ }
+ } else {
+ edit.insert(record_fields_text_range.end(), ";");
+ }
+ }
+
+ if let Some(tok) = record_fields
+ .l_curly_token()
+ .and_then(|tok| tok.prev_token())
+ .filter(|tok| tok.kind() == SyntaxKind::WHITESPACE)
+ {
+ edit.delete(tok.text_range())
+ }
+}
+
+fn edit_struct_references(
+ ctx: &AssistContext<'_>,
+ edit: &mut SourceChangeBuilder,
+ strukt: Either<hir::Struct, hir::Variant>,
+) {
+ let strukt_def = match strukt {
+ Either::Left(s) => Definition::Adt(hir::Adt::Struct(s)),
+ Either::Right(v) => Definition::Variant(v),
+ };
+ let usages = strukt_def.usages(&ctx.sema).include_self_refs().all();
+
+ let edit_node = |edit: &mut SourceChangeBuilder, node: SyntaxNode| -> Option<()> {
+ match_ast! {
+ match node {
+ ast::RecordPat(record_struct_pat) => {
+ edit.replace(
+ record_struct_pat.syntax().text_range(),
+ ast::make::tuple_struct_pat(
+ record_struct_pat.path()?,
+ record_struct_pat
+ .record_pat_field_list()?
+ .fields()
+ .filter_map(|pat| pat.pat())
+ )
+ .to_string()
+ );
+ },
+ ast::RecordExpr(record_expr) => {
+ let path = record_expr.path()?;
+ let args = record_expr
+ .record_expr_field_list()?
+ .fields()
+ .filter_map(|f| f.expr())
+ .join(", ");
+
+ edit.replace(record_expr.syntax().text_range(), format!("{path}({args})"));
+ },
+ _ => return None,
+ }
+ }
+ Some(())
+ };
+
+ for (file_id, refs) in usages {
+ edit.edit_file(file_id);
+ for r in refs {
+ for node in r.name.syntax().ancestors() {
+ if edit_node(edit, node).is_some() {
+ break;
+ }
+ }
+ }
+ }
+}
+
+fn edit_field_references(
+ ctx: &AssistContext<'_>,
+ edit: &mut SourceChangeBuilder,
+ fields: impl Iterator<Item = ast::RecordField>,
+) {
+ for (index, field) in fields.enumerate() {
+ let field = match ctx.sema.to_def(&field) {
+ Some(it) => it,
+ None => continue,
+ };
+ let def = Definition::Field(field);
+ let usages = def.usages(&ctx.sema).all();
+ for (file_id, refs) in usages {
+ edit.edit_file(file_id);
+ for r in refs {
+ if let Some(name_ref) = r.name.as_name_ref() {
+ // Only edit the field reference if it's part of a `.field` access
+ if name_ref.syntax().parent().and_then(ast::FieldExpr::cast).is_some() {
+ edit.replace(name_ref.syntax().text_range(), index.to_string());
+ }
+ }
+ }
+ }
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::tests::{check_assist, check_assist_not_applicable};
+
+ use super::*;
+
+ #[test]
+ fn not_applicable_other_than_record_struct() {
+ check_assist_not_applicable(convert_named_struct_to_tuple_struct, r#"struct Foo$0(u32)"#);
+ check_assist_not_applicable(convert_named_struct_to_tuple_struct, r#"struct Foo$0;"#);
+ }
+
+ #[test]
+ fn convert_simple_struct() {
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+struct Inner;
+struct A$0 { inner: Inner }
+
+impl A {
+ fn new(inner: Inner) -> A {
+ A { inner }
+ }
+
+ fn new_with_default() -> A {
+ A::new(Inner)
+ }
+
+ fn into_inner(self) -> Inner {
+ self.inner
+ }
+}"#,
+ r#"
+struct Inner;
+struct A(Inner);
+
+impl A {
+ fn new(inner: Inner) -> A {
+ A(inner)
+ }
+
+ fn new_with_default() -> A {
+ A::new(Inner)
+ }
+
+ fn into_inner(self) -> Inner {
+ self.0
+ }
+}"#,
+ );
+ }
+
+ #[test]
+ fn convert_struct_referenced_via_self_kw() {
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+struct Inner;
+struct A$0 { inner: Inner }
+
+impl A {
+ fn new(inner: Inner) -> Self {
+ Self { inner }
+ }
+
+ fn new_with_default() -> Self {
+ Self::new(Inner)
+ }
+
+ fn into_inner(self) -> Inner {
+ self.inner
+ }
+}"#,
+ r#"
+struct Inner;
+struct A(Inner);
+
+impl A {
+ fn new(inner: Inner) -> Self {
+ Self(inner)
+ }
+
+ fn new_with_default() -> Self {
+ Self::new(Inner)
+ }
+
+ fn into_inner(self) -> Inner {
+ self.0
+ }
+}"#,
+ );
+ }
+
+ #[test]
+ fn convert_destructured_struct() {
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+struct Inner;
+struct A$0 { inner: Inner }
+
+impl A {
+ fn into_inner(self) -> Inner {
+ let A { inner: a } = self;
+ a
+ }
+
+ fn into_inner_via_self(self) -> Inner {
+ let Self { inner } = self;
+ inner
+ }
+}"#,
+ r#"
+struct Inner;
+struct A(Inner);
+
+impl A {
+ fn into_inner(self) -> Inner {
+ let A(a) = self;
+ a
+ }
+
+ fn into_inner_via_self(self) -> Inner {
+ let Self(inner) = self;
+ inner
+ }
+}"#,
+ );
+ }
+
+ #[test]
+ fn convert_struct_with_visibility() {
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+struct A$0 {
+ pub first: u32,
+ pub(crate) second: u64
+}
+
+impl A {
+ fn new() -> A {
+ A { first: 42, second: 42 }
+ }
+
+ fn into_first(self) -> u32 {
+ self.first
+ }
+
+ fn into_second(self) -> u64 {
+ self.second
+ }
+}"#,
+ r#"
+struct A(pub u32, pub(crate) u64);
+
+impl A {
+ fn new() -> A {
+ A(42, 42)
+ }
+
+ fn into_first(self) -> u32 {
+ self.0
+ }
+
+ fn into_second(self) -> u64 {
+ self.1
+ }
+}"#,
+ );
+ }
+
+ #[test]
+ fn convert_struct_with_wrapped_references() {
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+struct Inner$0 { uint: u32 }
+struct Outer { inner: Inner }
+
+impl Outer {
+ fn new() -> Self {
+ Self { inner: Inner { uint: 42 } }
+ }
+
+ fn into_inner(self) -> u32 {
+ self.inner.uint
+ }
+
+ fn into_inner_destructed(self) -> u32 {
+ let Outer { inner: Inner { uint: x } } = self;
+ x
+ }
+}"#,
+ r#"
+struct Inner(u32);
+struct Outer { inner: Inner }
+
+impl Outer {
+ fn new() -> Self {
+ Self { inner: Inner(42) }
+ }
+
+ fn into_inner(self) -> u32 {
+ self.inner.0
+ }
+
+ fn into_inner_destructed(self) -> u32 {
+ let Outer { inner: Inner(x) } = self;
+ x
+ }
+}"#,
+ );
+
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+struct Inner { uint: u32 }
+struct Outer$0 { inner: Inner }
+
+impl Outer {
+ fn new() -> Self {
+ Self { inner: Inner { uint: 42 } }
+ }
+
+ fn into_inner(self) -> u32 {
+ self.inner.uint
+ }
+
+ fn into_inner_destructed(self) -> u32 {
+ let Outer { inner: Inner { uint: x } } = self;
+ x
+ }
+}"#,
+ r#"
+struct Inner { uint: u32 }
+struct Outer(Inner);
+
+impl Outer {
+ fn new() -> Self {
+ Self(Inner { uint: 42 })
+ }
+
+ fn into_inner(self) -> u32 {
+ self.0.uint
+ }
+
+ fn into_inner_destructed(self) -> u32 {
+ let Outer(Inner { uint: x }) = self;
+ x
+ }
+}"#,
+ );
+ }
+
+ #[test]
+ fn convert_struct_with_multi_file_references() {
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+//- /main.rs
+struct Inner;
+struct A$0 { inner: Inner }
+
+mod foo;
+
+//- /foo.rs
+use crate::{A, Inner};
+fn f() {
+ let a = A { inner: Inner };
+}
+"#,
+ r#"
+//- /main.rs
+struct Inner;
+struct A(Inner);
+
+mod foo;
+
+//- /foo.rs
+use crate::{A, Inner};
+fn f() {
+ let a = A(Inner);
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn convert_struct_with_where_clause() {
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+struct Wrap$0<T>
+where
+ T: Display,
+{ field1: T }
+"#,
+ r#"
+struct Wrap<T>(T)
+where
+ T: Display;
+
+"#,
+ );
+ }
+
+ #[test]
+ fn not_applicable_other_than_record_variant() {
+ check_assist_not_applicable(
+ convert_named_struct_to_tuple_struct,
+ r#"enum Enum { Variant$0(usize) };"#,
+ );
+ check_assist_not_applicable(
+ convert_named_struct_to_tuple_struct,
+ r#"enum Enum { Variant$0 }"#,
+ );
+ }
+
+ #[test]
+ fn convert_simple_variant() {
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+enum A {
+ $0Variant { field1: usize },
+}
+
+impl A {
+ fn new(value: usize) -> A {
+ A::Variant { field1: value }
+ }
+
+ fn new_with_default() -> A {
+ A::new(Default::default())
+ }
+
+ fn value(self) -> usize {
+ match self {
+ A::Variant { field1: value } => value,
+ }
+ }
+}"#,
+ r#"
+enum A {
+ Variant(usize),
+}
+
+impl A {
+ fn new(value: usize) -> A {
+ A::Variant(value)
+ }
+
+ fn new_with_default() -> A {
+ A::new(Default::default())
+ }
+
+ fn value(self) -> usize {
+ match self {
+ A::Variant(value) => value,
+ }
+ }
+}"#,
+ );
+ }
+
+ #[test]
+ fn convert_variant_referenced_via_self_kw() {
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+enum A {
+ $0Variant { field1: usize },
+}
+
+impl A {
+ fn new(value: usize) -> A {
+ Self::Variant { field1: value }
+ }
+
+ fn new_with_default() -> A {
+ Self::new(Default::default())
+ }
+
+ fn value(self) -> usize {
+ match self {
+ Self::Variant { field1: value } => value,
+ }
+ }
+}"#,
+ r#"
+enum A {
+ Variant(usize),
+}
+
+impl A {
+ fn new(value: usize) -> A {
+ Self::Variant(value)
+ }
+
+ fn new_with_default() -> A {
+ Self::new(Default::default())
+ }
+
+ fn value(self) -> usize {
+ match self {
+ Self::Variant(value) => value,
+ }
+ }
+}"#,
+ );
+ }
+
+ #[test]
+ fn convert_destructured_variant() {
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+enum A {
+ $0Variant { field1: usize },
+}
+
+impl A {
+ fn into_inner(self) -> usize {
+ let A::Variant { field1: first } = self;
+ first
+ }
+
+ fn into_inner_via_self(self) -> usize {
+ let Self::Variant { field1: first } = self;
+ first
+ }
+}"#,
+ r#"
+enum A {
+ Variant(usize),
+}
+
+impl A {
+ fn into_inner(self) -> usize {
+ let A::Variant(first) = self;
+ first
+ }
+
+ fn into_inner_via_self(self) -> usize {
+ let Self::Variant(first) = self;
+ first
+ }
+}"#,
+ );
+ }
+
+ #[test]
+ fn convert_variant_with_wrapped_references() {
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+enum Inner {
+ $0Variant { field1: usize },
+}
+enum Outer {
+ Variant(Inner),
+}
+
+impl Outer {
+ fn new() -> Self {
+ Self::Variant(Inner::Variant { field1: 42 })
+ }
+
+ fn into_inner_destructed(self) -> u32 {
+ let Outer::Variant(Inner::Variant { field1: x }) = self;
+ x
+ }
+}"#,
+ r#"
+enum Inner {
+ Variant(usize),
+}
+enum Outer {
+ Variant(Inner),
+}
+
+impl Outer {
+ fn new() -> Self {
+ Self::Variant(Inner::Variant(42))
+ }
+
+ fn into_inner_destructed(self) -> u32 {
+ let Outer::Variant(Inner::Variant(x)) = self;
+ x
+ }
+}"#,
+ );
+
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+enum Inner {
+ Variant(usize),
+}
+enum Outer {
+ $0Variant { field1: Inner },
+}
+
+impl Outer {
+ fn new() -> Self {
+ Self::Variant { field1: Inner::Variant(42) }
+ }
+
+ fn into_inner_destructed(self) -> u32 {
+ let Outer::Variant { field1: Inner::Variant(x) } = self;
+ x
+ }
+}"#,
+ r#"
+enum Inner {
+ Variant(usize),
+}
+enum Outer {
+ Variant(Inner),
+}
+
+impl Outer {
+ fn new() -> Self {
+ Self::Variant(Inner::Variant(42))
+ }
+
+ fn into_inner_destructed(self) -> u32 {
+ let Outer::Variant(Inner::Variant(x)) = self;
+ x
+ }
+}"#,
+ );
+ }
+
+ #[test]
+ fn convert_variant_with_multi_file_references() {
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+//- /main.rs
+struct Inner;
+enum A {
+ $0Variant { field1: Inner },
+}
+
+mod foo;
+
+//- /foo.rs
+use crate::{A, Inner};
+fn f() {
+ let a = A::Variant { field1: Inner };
+}
+"#,
+ r#"
+//- /main.rs
+struct Inner;
+enum A {
+ Variant(Inner),
+}
+
+mod foo;
+
+//- /foo.rs
+use crate::{A, Inner};
+fn f() {
+ let a = A::Variant(Inner);
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn convert_directly_used_variant() {
+ check_assist(
+ convert_named_struct_to_tuple_struct,
+ r#"
+//- /main.rs
+struct Inner;
+enum A {
+ $0Variant { field1: Inner },
+}
+
+mod foo;
+
+//- /foo.rs
+use crate::{A::Variant, Inner};
+fn f() {
+ let a = Variant { field1: Inner };
+}
+"#,
+ r#"
+//- /main.rs
+struct Inner;
+enum A {
+ Variant(Inner),
+}
+
+mod foo;
+
+//- /foo.rs
+use crate::{A::Variant, Inner};
+fn f() {
+ let a = Variant(Inner);
+}
+"#,
+ );
+ }
+}
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_function.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_function.rs
index 52a55ead3..d6c8ea785 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_function.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_function.rs
@@ -152,6 +152,7 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
ctx.sema.db,
ModuleDef::from(control_flow_enum),
ctx.config.insert_use.prefix_kind,
+ ctx.config.prefer_no_std,
);
if let Some(mod_path) = mod_path {
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs
index ddc2052e7..970e948df 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -9,7 +9,7 @@ use ide_db::{
search::FileReference,
FxHashSet, RootDatabase,
};
-use itertools::{Itertools, Position};
+use itertools::Itertools;
use syntax::{
ast::{
self, edit::IndentLevel, edit_in_place::Indent, make, AstNode, HasAttrs, HasGenericParams,
@@ -298,37 +298,7 @@ fn update_variant(variant: &ast::Variant, generics: Option<ast::GenericParamList
let name = variant.name()?;
let ty = generics
.filter(|generics| generics.generic_params().count() > 0)
- .map(|generics| {
- let mut generic_str = String::with_capacity(8);
-
- for (p, more) in generics.generic_params().with_position().map(|p| match p {
- Position::First(p) | Position::Middle(p) => (p, true),
- Position::Last(p) | Position::Only(p) => (p, false),
- }) {
- match p {
- ast::GenericParam::ConstParam(konst) => {
- if let Some(name) = konst.name() {
- generic_str.push_str(name.text().as_str());
- }
- }
- ast::GenericParam::LifetimeParam(lt) => {
- if let Some(lt) = lt.lifetime() {
- generic_str.push_str(lt.text().as_str());
- }
- }
- ast::GenericParam::TypeParam(ty) => {
- if let Some(name) = ty.name() {
- generic_str.push_str(name.text().as_str());
- }
- }
- }
- if more {
- generic_str.push_str(", ");
- }
- }
-
- make::ty(&format!("{}<{}>", &name.text(), &generic_str))
- })
+ .map(|generics| make::ty(&format!("{}{}", &name.text(), generics.to_generic_args())))
.unwrap_or_else(|| make::ty(&name.text()));
// change from a record to a tuple field list
@@ -409,6 +379,7 @@ fn process_references(
ctx.sema.db,
*enum_module_def,
ctx.config.insert_use.prefix_kind,
+ ctx.config.prefer_no_std,
);
if let Some(mut mod_path) = mod_path {
mod_path.pop_segment();
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_constant.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_constant.rs
index eaa6de73e..ccdfcb0d9 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_constant.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_constant.rs
@@ -77,7 +77,7 @@ pub(crate) fn generate_constant(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
target_data_for_generate_constant(ctx, current_module, constant_module).unwrap_or_else(
|| {
let indent = IndentLevel::from_node(statement.syntax());
- (statement.syntax().text_range().start(), indent, None, format!("\n{}", indent))
+ (statement.syntax().text_range().start(), indent, None, format!("\n{indent}"))
},
);
@@ -90,7 +90,7 @@ pub(crate) fn generate_constant(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
if let Some(file_id) = file_id {
builder.edit_file(file_id);
}
- builder.insert(offset, format!("{}{}", text, post_string));
+ builder.insert(offset, format!("{text}{post_string}"));
},
)
}
@@ -103,13 +103,13 @@ fn get_text_for_generate_constant(
) -> Option<String> {
let constant_token = not_exist_name_ref.pop()?;
let vis = if not_exist_name_ref.len() == 0 && !outer_exists { "" } else { "\npub " };
- let mut text = format!("{}const {}: {} = $0;", vis, constant_token, type_name);
+ let mut text = format!("{vis}const {constant_token}: {type_name} = $0;");
while let Some(name_ref) = not_exist_name_ref.pop() {
let vis = if not_exist_name_ref.len() == 0 && !outer_exists { "" } else { "\npub " };
text = text.replace("\n", "\n ");
- text = format!("{}mod {} {{{}\n}}", vis, name_ref.to_string(), text);
+ text = format!("{vis}mod {name_ref} {{{text}\n}}");
}
- Some(text.replace("\n", &format!("\n{}", indent)))
+ Some(text.replace("\n", &format!("\n{indent}")))
}
fn target_data_for_generate_constant(
@@ -134,7 +134,7 @@ fn target_data_for_generate_constant(
.find(|it| it.kind() == SyntaxKind::WHITESPACE && it.to_string().contains("\n"))
.is_some();
let post_string =
- if siblings_has_newline { format!("{}", indent) } else { format!("\n{}", indent) };
+ if siblings_has_newline { format!("{indent}") } else { format!("\n{indent}") };
Some((offset, indent + 1, Some(file_id), post_string))
}
_ => Some((TextSize::from(0), 0.into(), Some(file_id), "\n".into())),
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs
index 5e9995a98..a6e3d49e0 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_enum_variant.rs
@@ -55,12 +55,11 @@ pub(crate) fn generate_default_from_enum_variant(
let buf = format!(
r#"
-impl Default for {0} {{
+impl Default for {enum_name} {{
fn default() -> Self {{
- Self::{1}
+ Self::{variant_name}
}}
}}"#,
- enum_name, variant_name
);
edit.insert(start_offset, buf);
},
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_new.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_new.rs
index cbd33de19..49d9fd707 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_new.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_default_from_new.rs
@@ -1,8 +1,7 @@
use ide_db::famous_defs::FamousDefs;
-use itertools::Itertools;
use stdx::format_to;
use syntax::{
- ast::{self, HasGenericParams, HasName, HasTypeBounds, Impl},
+ ast::{self, make, HasGenericParams, HasName, Impl},
AstNode,
};
@@ -77,45 +76,47 @@ pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext<'
)
}
+// FIXME: based on from utils::generate_impl_text_inner
fn generate_trait_impl_text_from_impl(impl_: &ast::Impl, trait_text: &str, code: &str) -> String {
- let generic_params = impl_.generic_param_list();
- let mut buf = String::with_capacity(code.len());
- buf.push_str("\n\n");
- buf.push_str("impl");
-
- if let Some(generic_params) = &generic_params {
- let lifetimes = generic_params.lifetime_params().map(|lt| format!("{}", lt.syntax()));
- let toc_params = generic_params.type_or_const_params().map(|toc_param| match toc_param {
- ast::TypeOrConstParam::Type(type_param) => {
- let mut buf = String::new();
- if let Some(it) = type_param.name() {
- format_to!(buf, "{}", it.syntax());
- }
- if let Some(it) = type_param.colon_token() {
- format_to!(buf, "{} ", it);
+ let impl_ty = impl_.self_ty().unwrap();
+ let generic_params = impl_.generic_param_list().map(|generic_params| {
+ let lifetime_params =
+ generic_params.lifetime_params().map(ast::GenericParam::LifetimeParam);
+ let ty_or_const_params = generic_params.type_or_const_params().filter_map(|param| {
+ // remove defaults since they can't be specified in impls
+ match param {
+ ast::TypeOrConstParam::Type(param) => {
+ let param = param.clone_for_update();
+ param.remove_default();
+ Some(ast::GenericParam::TypeParam(param))
}
- if let Some(it) = type_param.type_bound_list() {
- format_to!(buf, "{}", it.syntax());
+ ast::TypeOrConstParam::Const(param) => {
+ let param = param.clone_for_update();
+ param.remove_default();
+ Some(ast::GenericParam::ConstParam(param))
}
- buf
}
- ast::TypeOrConstParam::Const(const_param) => const_param.syntax().to_string(),
});
- let generics = lifetimes.chain(toc_params).format(", ");
- format_to!(buf, "<{}>", generics);
- }
- buf.push(' ');
- buf.push_str(trait_text);
- buf.push_str(" for ");
- buf.push_str(&impl_.self_ty().unwrap().syntax().text().to_string());
+ make::generic_param_list(itertools::chain(lifetime_params, ty_or_const_params))
+ });
+
+ let mut buf = String::with_capacity(code.len());
+ buf.push_str("\n\n");
+
+ // `impl{generic_params} {trait_text} for {impl_.self_ty()}`
+ buf.push_str("impl");
+ if let Some(generic_params) = &generic_params {
+ format_to!(buf, "{generic_params}")
+ }
+ format_to!(buf, " {trait_text} for {impl_ty}");
match impl_.where_clause() {
Some(where_clause) => {
- format_to!(buf, "\n{}\n{{\n{}\n}}", where_clause, code);
+ format_to!(buf, "\n{where_clause}\n{{\n{code}\n}}");
}
None => {
- format_to!(buf, " {{\n{}\n}}", code);
+ format_to!(buf, " {{\n{code}\n}}");
}
}
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_methods.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_methods.rs
index 85b193663..ceae80755 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_methods.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_methods.rs
@@ -51,14 +51,14 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
Some(field) => {
let field_name = field.name()?;
let field_ty = field.ty()?;
- (format!("{}", field_name), field_ty, field.syntax().text_range())
+ (field_name.to_string(), field_ty, field.syntax().text_range())
}
None => {
let field = ctx.find_node_at_offset::<ast::TupleField>()?;
let field_list = ctx.find_node_at_offset::<ast::TupleFieldList>()?;
let field_list_index = field_list.fields().position(|it| it == field)?;
let field_ty = field.ty()?;
- (format!("{}", field_list_index), field_ty, field.syntax().text_range())
+ (field_list_index.to_string(), field_ty, field.syntax().text_range())
}
};
@@ -77,7 +77,7 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
for method in methods {
let adt = ast::Adt::Struct(strukt.clone());
let name = method.name(ctx.db()).to_string();
- let impl_def = find_struct_impl(ctx, &adt, &name).flatten();
+ let impl_def = find_struct_impl(ctx, &adt, &[name]).flatten();
acc.add_group(
&GroupLabel("Generate delegate methods…".to_owned()),
AssistId("generate_delegate_methods", AssistKind::Generate),
@@ -151,7 +151,7 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
Some(cap) => {
let offset = strukt.syntax().text_range().end();
let snippet = render_snippet(cap, impl_def.syntax(), cursor);
- let snippet = format!("\n\n{}", snippet);
+ let snippet = format!("\n\n{snippet}");
builder.insert_snippet(cap, offset, snippet);
}
None => {
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs
index b48463512..55b7afb3d 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs
@@ -58,14 +58,15 @@ fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
- let trait_path = module.find_use_path(ctx.db(), ModuleDef::Trait(trait_))?;
+ let trait_path =
+ module.find_use_path(ctx.db(), ModuleDef::Trait(trait_), ctx.config.prefer_no_std)?;
let field_type = field.ty()?;
let field_name = field.name()?;
let target = field.syntax().text_range();
acc.add(
AssistId("generate_deref", AssistKind::Generate),
- format!("Generate `{:?}` impl using `{}`", deref_type_to_generate, field_name),
+ format!("Generate `{deref_type_to_generate:?}` impl using `{field_name}`"),
target,
|edit| {
generate_edit(
@@ -98,13 +99,14 @@ fn generate_tuple_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
- let trait_path = module.find_use_path(ctx.db(), ModuleDef::Trait(trait_))?;
+ let trait_path =
+ module.find_use_path(ctx.db(), ModuleDef::Trait(trait_), ctx.config.prefer_no_std)?;
let field_type = field.ty()?;
let target = field.syntax().text_range();
acc.add(
AssistId("generate_deref", AssistKind::Generate),
- format!("Generate `{:?}` impl using `{}`", deref_type_to_generate, field.syntax()),
+ format!("Generate `{deref_type_to_generate:?}` impl using `{field}`"),
target,
|edit| {
generate_edit(
@@ -130,18 +132,16 @@ fn generate_edit(
let start_offset = strukt.syntax().text_range().end();
let impl_code = match deref_type {
DerefType::Deref => format!(
- r#" type Target = {0};
+ r#" type Target = {field_type_syntax};
fn deref(&self) -> &Self::Target {{
- &self.{1}
+ &self.{field_name}
}}"#,
- field_type_syntax, field_name
),
DerefType::DerefMut => format!(
r#" fn deref_mut(&mut self) -> &mut Self::Target {{
- &mut self.{}
+ &mut self.{field_name}
}}"#,
- field_name
),
};
let strukt_adt = ast::Adt::Struct(strukt);
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_documentation_template.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_documentation_template.rs
index c91141f8e..b8415c72a 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_documentation_template.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_documentation_template.rs
@@ -139,40 +139,44 @@ fn make_example_for_fn(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<St
let mut example = String::new();
+ let use_path = build_path(ast_func, ctx)?;
let is_unsafe = ast_func.unsafe_token().is_some();
let param_list = ast_func.param_list()?;
let ref_mut_params = ref_mut_params(&param_list);
let self_name = self_name(ast_func);
- format_to!(example, "use {};\n\n", build_path(ast_func, ctx)?);
+ format_to!(example, "use {use_path};\n\n");
if let Some(self_name) = &self_name {
- if let Some(mtbl) = is_ref_mut_self(ast_func) {
- let mtbl = if mtbl == true { " mut" } else { "" };
- format_to!(example, "let{} {} = ;\n", mtbl, self_name);
+ if let Some(mut_) = is_ref_mut_self(ast_func) {
+ let mut_ = if mut_ == true { "mut " } else { "" };
+ format_to!(example, "let {mut_}{self_name} = ;\n");
}
}
for param_name in &ref_mut_params {
- format_to!(example, "let mut {} = ;\n", param_name);
+ format_to!(example, "let mut {param_name} = ;\n");
}
// Call the function, check result
let function_call = function_call(ast_func, &param_list, self_name.as_deref(), is_unsafe)?;
if returns_a_value(ast_func, ctx) {
if count_parameters(&param_list) < 3 {
- format_to!(example, "assert_eq!({}, );\n", function_call);
+ format_to!(example, "assert_eq!({function_call}, );\n");
} else {
- format_to!(example, "let result = {};\n", function_call);
+ format_to!(example, "let result = {function_call};\n");
example.push_str("assert_eq!(result, );\n");
}
} else {
- format_to!(example, "{};\n", function_call);
+ format_to!(example, "{function_call};\n");
}
// Check the mutated values
- if is_ref_mut_self(ast_func) == Some(true) {
- format_to!(example, "assert_eq!({}, );", self_name?);
+ if let Some(self_name) = &self_name {
+ if is_ref_mut_self(ast_func) == Some(true) {
+ format_to!(example, "assert_eq!({self_name}, );");
+ }
}
for param_name in &ref_mut_params {
- format_to!(example, "assert_eq!({}, );", param_name);
+ format_to!(example, "assert_eq!({param_name}, );");
}
+
Some(example)
}
@@ -189,7 +193,8 @@ fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<S
let intro_for_new = || {
let is_new = name == "new";
if is_new && ret_ty == self_ty {
- Some(format!("Creates a new [`{}`].", linkable_self_ty?))
+ let self_ty = linkable_self_ty?;
+ Some(format!("Creates a new [`{self_ty}`]."))
} else {
None
}
@@ -214,7 +219,9 @@ fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<S
} else {
""
};
- Some(format!("Returns{reference} the {what} of this [`{}`].", linkable_self_ty?))
+
+ let self_ty = linkable_self_ty?;
+ Some(format!("Returns{reference} the {what} of this [`{self_ty}`]."))
}
_ => None,
};
@@ -228,7 +235,9 @@ fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<S
if what == "len" {
what = "length".into()
};
- Some(format!("Sets the {what} of this [`{}`].", linkable_self_ty?))
+
+ let self_ty = linkable_self_ty?;
+ Some(format!("Sets the {what} of this [`{self_ty}`]."))
};
if let Some(intro) = intro_for_new() {
@@ -404,7 +413,7 @@ fn arguments_from_params(param_list: &ast::ParamList) -> String {
// instance `TuplePat`) could be managed later.
Some(ast::Pat::IdentPat(ident_pat)) => match ident_pat.name() {
Some(name) => match is_a_ref_mut_param(&param) {
- true => format!("&mut {}", name),
+ true => format!("&mut {name}"),
false => name.to_string(),
},
None => "_".to_string(),
@@ -424,14 +433,15 @@ fn function_call(
let name = ast_func.name()?;
let arguments = arguments_from_params(param_list);
let function_call = if param_list.self_param().is_some() {
- format!("{}.{}({})", self_name?, name, arguments)
+ let self_ = self_name?;
+ format!("{self_}.{name}({arguments})")
} else if let Some(implementation) = self_partial_type(ast_func) {
- format!("{}::{}({})", implementation, name, arguments)
+ format!("{implementation}::{name}({arguments})")
} else {
- format!("{}({})", name, arguments)
+ format!("{name}({arguments})")
};
match is_unsafe {
- true => Some(format!("unsafe {{ {} }}", function_call)),
+ true => Some(format!("unsafe {{ {function_call} }}")),
false => Some(function_call),
}
}
@@ -469,8 +479,8 @@ fn build_path(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<String> {
.unwrap_or_else(|| "*".into());
let module_def: ModuleDef = ctx.sema.to_def(ast_func)?.module(ctx.db()).into();
match module_def.canonical_path(ctx.db()) {
- Some(path) => Some(format!("{}::{}::{}", crate_name, path, leaf)),
- None => Some(format!("{}::{}", crate_name, leaf)),
+ Some(path) => Some(format!("{crate_name}::{path}::{leaf}")),
+ None => Some(format!("{crate_name}::{leaf}")),
}
}
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_is_method.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_is_method.rs
index 52d27d8a7..63e91b835 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_is_method.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_is_method.rs
@@ -52,7 +52,7 @@ pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext<'_>
let fn_name = format!("is_{}", &to_lower_snake_case(&variant_name.text()));
// Return early if we've found an existing new fn
- let impl_def = find_struct_impl(ctx, &parent_enum, &fn_name)?;
+ let impl_def = find_struct_impl(ctx, &parent_enum, &[fn_name.clone()])?;
let target = variant.syntax().text_range();
acc.add_group(
@@ -61,21 +61,15 @@ pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext<'_>
"Generate an `is_` method for this enum variant",
target,
|builder| {
- let vis = parent_enum.visibility().map_or(String::new(), |v| format!("{} ", v));
+ let vis = parent_enum.visibility().map_or(String::new(), |v| format!("{v} "));
let method = format!(
- " /// Returns `true` if the {} is [`{variant}`].
+ " /// Returns `true` if the {enum_lowercase_name} is [`{variant_name}`].
///
- /// [`{variant}`]: {}::{variant}
+ /// [`{variant_name}`]: {enum_name}::{variant_name}
#[must_use]
- {}fn {}(&self) -> bool {{
- matches!(self, Self::{variant}{})
+ {vis}fn {fn_name}(&self) -> bool {{
+ matches!(self, Self::{variant_name}{pattern_suffix})
}}",
- enum_lowercase_name,
- enum_name,
- vis,
- fn_name,
- pattern_suffix,
- variant = variant_name
);
add_method_to_adt(builder, &parent_enum, impl_def, &method);
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_projection_method.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_projection_method.rs
index b19aa0f65..bdd3cf4f0 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_projection_method.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_enum_projection_method.rs
@@ -116,6 +116,14 @@ fn generate_enum_projection_method(
assist_description: &str,
props: ProjectionProps,
) -> Option<()> {
+ let ProjectionProps {
+ fn_name_prefix,
+ self_param,
+ return_prefix,
+ return_suffix,
+ happy_case,
+ sad_case,
+ } = props;
let variant = ctx.find_node_at_offset::<ast::Variant>()?;
let variant_name = variant.name()?;
let parent_enum = ast::Adt::Enum(variant.parent_enum());
@@ -125,7 +133,7 @@ fn generate_enum_projection_method(
let (field,) = record.fields().collect_tuple()?;
let name = field.name()?.to_string();
let ty = field.ty()?;
- let pattern_suffix = format!(" {{ {} }}", name);
+ let pattern_suffix = format!(" {{ {name} }}");
(pattern_suffix, ty, name)
}
ast::StructKind::Tuple(tuple) => {
@@ -136,11 +144,10 @@ fn generate_enum_projection_method(
ast::StructKind::Unit => return None,
};
- let fn_name =
- format!("{}_{}", props.fn_name_prefix, &to_lower_snake_case(&variant_name.text()));
+ let fn_name = format!("{}_{}", fn_name_prefix, &to_lower_snake_case(&variant_name.text()));
// Return early if we've found an existing new fn
- let impl_def = find_struct_impl(ctx, &parent_enum, &fn_name)?;
+ let impl_def = find_struct_impl(ctx, &parent_enum, &[fn_name.clone()])?;
let target = variant.syntax().text_range();
acc.add_group(
@@ -149,27 +156,15 @@ fn generate_enum_projection_method(
assist_description,
target,
|builder| {
- let vis = parent_enum.visibility().map_or(String::new(), |v| format!("{} ", v));
+ let vis = parent_enum.visibility().map_or(String::new(), |v| format!("{v} "));
let method = format!(
- " {0}fn {1}({2}) -> {3}{4}{5} {{
- if let Self::{6}{7} = self {{
- {8}({9})
+ " {vis}fn {fn_name}({self_param}) -> {return_prefix}{field_type}{return_suffix} {{
+ if let Self::{variant_name}{pattern_suffix} = self {{
+ {happy_case}({bound_name})
}} else {{
- {10}
+ {sad_case}
}}
- }}",
- vis,
- fn_name,
- props.self_param,
- props.return_prefix,
- field_type.syntax(),
- props.return_suffix,
- variant_name,
- pattern_suffix,
- props.happy_case,
- bound_name,
- props.sad_case,
- );
+ }}");
add_method_to_adt(builder, &parent_enum, impl_def, &method);
},
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs
index 507ea012b..7c81d2c6a 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_from_impl_for_enum.rs
@@ -56,23 +56,18 @@ pub(crate) fn generate_from_impl_for_enum(
target,
|edit| {
let start_offset = variant.parent_enum().syntax().text_range().end();
- let from_trait = format!("From<{}>", field_type.syntax());
+ let from_trait = format!("From<{field_type}>");
let impl_code = if let Some(name) = field_name {
format!(
- r#" fn from({0}: {1}) -> Self {{
- Self::{2} {{ {0} }}
- }}"#,
- name.text(),
- field_type.syntax(),
- variant_name,
+ r#" fn from({name}: {field_type}) -> Self {{
+ Self::{variant_name} {{ {name} }}
+ }}"#
)
} else {
format!(
- r#" fn from(v: {}) -> Self {{
- Self::{}(v)
- }}"#,
- field_type.syntax(),
- variant_name,
+ r#" fn from(v: {field_type}) -> Self {{
+ Self::{variant_name}(v)
+ }}"#
)
};
let from_impl = generate_trait_impl_text(&enum_, &from_trait, &impl_code);
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs
index e26c76da1..c229127e4 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_function.rs
@@ -1,4 +1,4 @@
-use hir::{HasSource, HirDisplay, Module, Semantics, TypeInfo};
+use hir::{Adt, HasSource, HirDisplay, Module, Semantics, TypeInfo};
use ide_db::{
base_db::FileId,
defs::{Definition, NameRefClass},
@@ -145,7 +145,8 @@ fn gen_method(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
return None;
}
let (impl_, file) = get_adt_source(ctx, &adt, fn_name.text().as_str())?;
- let (target, insert_offset) = get_method_target(ctx, &target_module, &impl_)?;
+ let (target, insert_offset) = get_method_target(ctx, &impl_, &adt)?;
+
let function_builder =
FunctionBuilder::from_method_call(ctx, &call, &fn_name, target_module, target)?;
let text_range = call.syntax().text_range();
@@ -174,10 +175,11 @@ fn add_func_to_accumulator(
label: String,
) -> Option<()> {
acc.add(AssistId("generate_function", AssistKind::Generate), label, text_range, |builder| {
- let function_template = function_builder.render();
+ let indent = IndentLevel::from_node(function_builder.target.syntax());
+ let function_template = function_builder.render(adt_name.is_some());
let mut func = function_template.to_string(ctx.config.snippet_cap);
if let Some(name) = adt_name {
- func = format!("\nimpl {} {{\n{}\n}}", name, func);
+ func = format!("\n{indent}impl {name} {{\n{func}\n{indent}}}");
}
builder.edit_file(file);
match ctx.config.snippet_cap {
@@ -196,7 +198,7 @@ fn get_adt_source(
let file = ctx.sema.parse(range.file_id);
let adt_source =
ctx.sema.find_node_at_offset_with_macros(file.syntax(), range.range.start())?;
- find_struct_impl(ctx, &adt_source, fn_name).map(|impl_| (impl_, range.file_id))
+ find_struct_impl(ctx, &adt_source, &[fn_name.to_string()]).map(|impl_| (impl_, range.file_id))
}
struct FunctionTemplate {
@@ -210,23 +212,26 @@ struct FunctionTemplate {
impl FunctionTemplate {
fn to_string(&self, cap: Option<SnippetCap>) -> String {
+ let Self { leading_ws, fn_def, ret_type, should_focus_return_type, trailing_ws, tail_expr } =
+ self;
+
let f = match cap {
Some(cap) => {
- let cursor = if self.should_focus_return_type {
+ let cursor = if *should_focus_return_type {
// Focus the return type if there is one
- match self.ret_type {
- Some(ref ret_type) => ret_type.syntax(),
- None => self.tail_expr.syntax(),
+ match ret_type {
+ Some(ret_type) => ret_type.syntax(),
+ None => tail_expr.syntax(),
}
} else {
- self.tail_expr.syntax()
+ tail_expr.syntax()
};
- render_snippet(cap, self.fn_def.syntax(), Cursor::Replace(cursor))
+ render_snippet(cap, fn_def.syntax(), Cursor::Replace(cursor))
}
- None => self.fn_def.to_string(),
+ None => fn_def.to_string(),
};
- format!("{}{}{}", self.leading_ws, f, self.trailing_ws)
+ format!("{leading_ws}{f}{trailing_ws}")
}
}
@@ -307,7 +312,7 @@ impl FunctionBuilder {
})
}
- fn render(self) -> FunctionTemplate {
+ fn render(self, is_method: bool) -> FunctionTemplate {
let placeholder_expr = make::ext::expr_todo();
let fn_body = make::block_expr(vec![], Some(placeholder_expr));
let visibility = if self.needs_pub { Some(make::visibility_pub_crate()) } else { None };
@@ -325,16 +330,23 @@ impl FunctionBuilder {
match self.target {
GeneratedFunctionTarget::BehindItem(it) => {
- let indent = IndentLevel::from_node(&it);
- leading_ws = format!("\n\n{}", indent);
+ let mut indent = IndentLevel::from_node(&it);
+ if is_method {
+ indent = indent + 1;
+ leading_ws = format!("{indent}");
+ } else {
+ leading_ws = format!("\n\n{indent}");
+ }
+
fn_def = fn_def.indent(indent);
trailing_ws = String::new();
}
GeneratedFunctionTarget::InEmptyItemList(it) => {
let indent = IndentLevel::from_node(&it);
- leading_ws = format!("\n{}", indent + 1);
- fn_def = fn_def.indent(indent + 1);
- trailing_ws = format!("\n{}", indent);
+ let leading_indent = indent + 1;
+ leading_ws = format!("\n{leading_indent}");
+ fn_def = fn_def.indent(leading_indent);
+ trailing_ws = format!("\n{indent}");
}
};
@@ -411,14 +423,13 @@ fn get_fn_target(
fn get_method_target(
ctx: &AssistContext<'_>,
- target_module: &Module,
impl_: &Option<ast::Impl>,
+ adt: &Adt,
) -> Option<(GeneratedFunctionTarget, TextSize)> {
let target = match impl_ {
Some(impl_) => next_space_for_fn_in_impl(impl_)?,
None => {
- next_space_for_fn_in_module(ctx.sema.db, &target_module.definition_source(ctx.sema.db))?
- .1
+ GeneratedFunctionTarget::BehindItem(adt.source(ctx.sema.db)?.syntax().value.clone())
}
};
Some((target.clone(), get_insert_offset(&target)))
@@ -437,7 +448,7 @@ fn assoc_fn_target_info(
return None;
}
let (impl_, file) = get_adt_source(ctx, &adt, fn_name)?;
- let (target, insert_offset) = get_method_target(ctx, &module, &impl_)?;
+ let (target, insert_offset) = get_method_target(ctx, &impl_, &adt)?;
let adt_name = if impl_.is_none() { Some(adt.name(ctx.sema.db)) } else { None };
Some(TargetInfo::new(target_module, adt_name, target, file, insert_offset))
}
@@ -1468,14 +1479,12 @@ fn foo() {S.bar$0();}
",
r"
struct S;
-fn foo() {S.bar();}
impl S {
-
-
-fn bar(&self) ${0:-> _} {
- todo!()
-}
+ fn bar(&self) ${0:-> _} {
+ todo!()
+ }
}
+fn foo() {S.bar();}
",
)
}
@@ -1516,14 +1525,12 @@ fn foo() {s::S.bar$0();}
r"
mod s {
pub struct S;
-impl S {
-
-
- pub(crate) fn bar(&self) ${0:-> _} {
- todo!()
+ impl S {
+ pub(crate) fn bar(&self) ${0:-> _} {
+ todo!()
+ }
}
}
-}
fn foo() {s::S.bar();}
",
)
@@ -1544,18 +1551,16 @@ mod s {
",
r"
struct S;
+impl S {
+ fn bar(&self) ${0:-> _} {
+ todo!()
+ }
+}
mod s {
fn foo() {
super::S.bar();
}
}
-impl S {
-
-
-fn bar(&self) ${0:-> _} {
- todo!()
-}
-}
",
)
@@ -1571,14 +1576,12 @@ fn foo() {$0S.bar();}
",
r"
struct S;
-fn foo() {S.bar();}
impl S {
-
-
-fn bar(&self) ${0:-> _} {
- todo!()
-}
+ fn bar(&self) ${0:-> _} {
+ todo!()
+ }
}
+fn foo() {S.bar();}
",
)
}
@@ -1593,14 +1596,12 @@ fn foo() {S::bar$0();}
",
r"
struct S;
-fn foo() {S::bar();}
impl S {
-
-
-fn bar() ${0:-> _} {
- todo!()
-}
+ fn bar() ${0:-> _} {
+ todo!()
+ }
}
+fn foo() {S::bar();}
",
)
}
@@ -1641,14 +1642,12 @@ fn foo() {s::S::bar$0();}
r"
mod s {
pub struct S;
-impl S {
-
-
- pub(crate) fn bar() ${0:-> _} {
- todo!()
+ impl S {
+ pub(crate) fn bar() ${0:-> _} {
+ todo!()
+ }
}
}
-}
fn foo() {s::S::bar();}
",
)
@@ -1664,14 +1663,12 @@ fn foo() {$0S::bar();}
",
r"
struct S;
-fn foo() {S::bar();}
impl S {
-
-
-fn bar() ${0:-> _} {
- todo!()
-}
+ fn bar() ${0:-> _} {
+ todo!()
+ }
}
+fn foo() {S::bar();}
",
)
}
@@ -1841,15 +1838,13 @@ fn main() {
",
r"
enum Foo {}
-fn main() {
- Foo::new();
-}
impl Foo {
-
-
-fn new() ${0:-> _} {
- todo!()
+ fn new() ${0:-> _} {
+ todo!()
+ }
}
+fn main() {
+ Foo::new();
}
",
)
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_getter.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_getter.rs
index 76fcef0ca..5e7191428 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_getter.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_getter.rs
@@ -1,6 +1,9 @@
use ide_db::famous_defs::FamousDefs;
use stdx::{format_to, to_lower_snake_case};
-use syntax::ast::{self, AstNode, HasName, HasVisibility};
+use syntax::{
+ ast::{self, AstNode, HasName, HasVisibility},
+ TextRange,
+};
use crate::{
utils::{convert_reference_type, find_impl_block_end, find_struct_impl, generate_impl_text},
@@ -72,92 +75,259 @@ pub(crate) fn generate_getter_mut(acc: &mut Assists, ctx: &AssistContext<'_>) ->
generate_getter_impl(acc, ctx, true)
}
+#[derive(Clone, Debug)]
+struct RecordFieldInfo {
+ field_name: syntax::ast::Name,
+ field_ty: syntax::ast::Type,
+ fn_name: String,
+ target: TextRange,
+}
+
+struct GetterInfo {
+ impl_def: Option<ast::Impl>,
+ strukt: ast::Struct,
+ mutable: bool,
+}
+
pub(crate) fn generate_getter_impl(
acc: &mut Assists,
ctx: &AssistContext<'_>,
mutable: bool,
) -> Option<()> {
- let strukt = ctx.find_node_at_offset::<ast::Struct>()?;
- let field = ctx.find_node_at_offset::<ast::RecordField>()?;
+ // This if condition denotes two modes this assist can work in:
+ // - First is acting upon selection of record fields
+ // - Next is acting upon a single record field
+ //
+ // This is the only part where implementation diverges a bit,
+ // subsequent code is generic for both of these modes
- let field_name = field.name()?;
- let field_ty = field.ty()?;
+ let (strukt, info_of_record_fields, fn_names) = if !ctx.has_empty_selection() {
+ // Selection Mode
+ let node = ctx.covering_element();
- // Return early if we've found an existing fn
- let mut fn_name = to_lower_snake_case(&field_name.to_string());
- if mutable {
- format_to!(fn_name, "_mut");
+ let node = match node {
+ syntax::NodeOrToken::Node(n) => n,
+ syntax::NodeOrToken::Token(t) => t.parent()?,
+ };
+
+ let parent_struct = node.ancestors().find_map(ast::Struct::cast)?;
+
+ let (info_of_record_fields, field_names) =
+ extract_and_parse_record_fields(&parent_struct, ctx.selection_trimmed(), mutable)?;
+
+ (parent_struct, info_of_record_fields, field_names)
+ } else {
+ // Single Record Field mode
+ let strukt = ctx.find_node_at_offset::<ast::Struct>()?;
+ let field = ctx.find_node_at_offset::<ast::RecordField>()?;
+
+ let record_field_info = parse_record_field(field, mutable)?;
+
+ let fn_name = record_field_info.fn_name.clone();
+
+ (strukt, vec![record_field_info], vec![fn_name])
+ };
+
+ // No record fields to do work on :(
+ if info_of_record_fields.len() == 0 {
+ return None;
}
- let impl_def = find_struct_impl(ctx, &ast::Adt::Struct(strukt.clone()), fn_name.as_str())?;
+
+ let impl_def = find_struct_impl(ctx, &ast::Adt::Struct(strukt.clone()), &fn_names)?;
let (id, label) = if mutable {
("generate_getter_mut", "Generate a mut getter method")
} else {
("generate_getter", "Generate a getter method")
};
- let target = field.syntax().text_range();
+
+ // Computing collective text range of all record fields in selected region
+ let target: TextRange = info_of_record_fields
+ .iter()
+ .map(|record_field_info| record_field_info.target)
+ .reduce(|acc, target| acc.cover(target))?;
+
+ let getter_info = GetterInfo { impl_def, strukt, mutable };
+
acc.add_group(
&GroupLabel("Generate getter/setter".to_owned()),
AssistId(id, AssistKind::Generate),
label,
target,
|builder| {
+ let record_fields_count = info_of_record_fields.len();
+
let mut buf = String::with_capacity(512);
- if impl_def.is_some() {
- buf.push('\n');
+ // Check if an impl exists
+ if let Some(impl_def) = &getter_info.impl_def {
+ // Check if impl is empty
+ if let Some(assoc_item_list) = impl_def.assoc_item_list() {
+ if assoc_item_list.assoc_items().next().is_some() {
+ // If not empty then only insert a new line
+ buf.push('\n');
+ }
+ }
}
- let vis = strukt.visibility().map_or(String::new(), |v| format!("{} ", v));
- let (ty, body) = if mutable {
- (format!("&mut {}", field_ty), format!("&mut self.{}", field_name))
- } else {
- (|| {
- let krate = ctx.sema.scope(field_ty.syntax())?.krate();
- let famous_defs = &FamousDefs(&ctx.sema, krate);
- ctx.sema
- .resolve_type(&field_ty)
- .and_then(|ty| convert_reference_type(ty, ctx.db(), famous_defs))
- .map(|conversion| {
- cov_mark::hit!(convert_reference_type);
- (
- conversion.convert_type(ctx.db()),
- conversion.getter(field_name.to_string()),
- )
- })
- })()
- .unwrap_or_else(|| (format!("&{}", field_ty), format!("&self.{}", field_name)))
- };
-
- format_to!(
- buf,
- " {}fn {}(&{}self) -> {} {{
- {}
- }}",
- vis,
- fn_name,
- mutable.then(|| "mut ").unwrap_or_default(),
- ty,
- body,
- );
-
- let start_offset = impl_def
- .and_then(|impl_def| find_impl_block_end(impl_def, &mut buf))
+ for (i, record_field_info) in info_of_record_fields.iter().enumerate() {
+ // this buf inserts a newline at the end of a getter
+ // automatically, if one wants to add one more newline
+ // for separating it from other assoc items, that needs
+ // to be handled spearately
+ let mut getter_buf =
+ generate_getter_from_info(ctx, &getter_info, &record_field_info);
+
+ // Insert `$0` only for last getter we generate
+ if i == record_fields_count - 1 {
+ getter_buf = getter_buf.replacen("fn ", "fn $0", 1);
+ }
+
+ // For first element we do not merge with '\n', as
+ // that can be inserted by impl_def check defined
+ // above, for other cases which are:
+ //
+ // - impl exists but it empty, here we would ideally
+ // not want to keep newline between impl <struct> {
+ // and fn <fn-name>() { line
+ //
+ // - next if impl itself does not exist, in this
+ // case we ourselves generate a new impl and that
+ // again ends up with the same reasoning as above
+ // for not keeping newline
+ if i == 0 {
+ buf = buf + &getter_buf;
+ } else {
+ buf = buf + "\n" + &getter_buf;
+ }
+
+ // We don't insert a new line at the end of
+ // last getter as it will end up in the end
+ // of an impl where we would not like to keep
+ // getter and end of impl ( i.e. `}` ) with an
+ // extra line for no reason
+ if i < record_fields_count - 1 {
+ buf = buf + "\n";
+ }
+ }
+
+ let start_offset = getter_info
+ .impl_def
+ .as_ref()
+ .and_then(|impl_def| find_impl_block_end(impl_def.to_owned(), &mut buf))
.unwrap_or_else(|| {
- buf = generate_impl_text(&ast::Adt::Struct(strukt.clone()), &buf);
- strukt.syntax().text_range().end()
+ buf = generate_impl_text(&ast::Adt::Struct(getter_info.strukt.clone()), &buf);
+ getter_info.strukt.syntax().text_range().end()
});
match ctx.config.snippet_cap {
- Some(cap) => {
- builder.insert_snippet(cap, start_offset, buf.replacen("fn ", "fn $0", 1))
- }
+ Some(cap) => builder.insert_snippet(cap, start_offset, buf),
None => builder.insert(start_offset, buf),
}
},
)
}
+fn generate_getter_from_info(
+ ctx: &AssistContext<'_>,
+ info: &GetterInfo,
+ record_field_info: &RecordFieldInfo,
+) -> String {
+ let mut buf = String::with_capacity(512);
+
+ let vis = info.strukt.visibility().map_or(String::new(), |v| format!("{} ", v));
+ let (ty, body) = if info.mutable {
+ (
+ format!("&mut {}", record_field_info.field_ty),
+ format!("&mut self.{}", record_field_info.field_name),
+ )
+ } else {
+ (|| {
+ let krate = ctx.sema.scope(record_field_info.field_ty.syntax())?.krate();
+ let famous_defs = &FamousDefs(&ctx.sema, krate);
+ ctx.sema
+ .resolve_type(&record_field_info.field_ty)
+ .and_then(|ty| convert_reference_type(ty, ctx.db(), famous_defs))
+ .map(|conversion| {
+ cov_mark::hit!(convert_reference_type);
+ (
+ conversion.convert_type(ctx.db()),
+ conversion.getter(record_field_info.field_name.to_string()),
+ )
+ })
+ })()
+ .unwrap_or_else(|| {
+ (
+ format!("&{}", record_field_info.field_ty),
+ format!("&self.{}", record_field_info.field_name),
+ )
+ })
+ };
+
+ format_to!(
+ buf,
+ " {}fn {}(&{}self) -> {} {{
+ {}
+ }}",
+ vis,
+ record_field_info.fn_name,
+ info.mutable.then(|| "mut ").unwrap_or_default(),
+ ty,
+ body,
+ );
+
+ buf
+}
+
+fn extract_and_parse_record_fields(
+ node: &ast::Struct,
+ selection_range: TextRange,
+ mutable: bool,
+) -> Option<(Vec<RecordFieldInfo>, Vec<String>)> {
+ let mut field_names: Vec<String> = vec![];
+ let field_list = node.field_list()?;
+
+ match field_list {
+ ast::FieldList::RecordFieldList(ele) => {
+ let info_of_record_fields_in_selection = ele
+ .fields()
+ .filter_map(|record_field| {
+ if selection_range.contains_range(record_field.syntax().text_range()) {
+ let record_field_info = parse_record_field(record_field, mutable)?;
+ field_names.push(record_field_info.fn_name.clone());
+ return Some(record_field_info);
+ }
+
+ None
+ })
+ .collect::<Vec<RecordFieldInfo>>();
+
+ if info_of_record_fields_in_selection.len() == 0 {
+ return None;
+ }
+
+ Some((info_of_record_fields_in_selection, field_names))
+ }
+ ast::FieldList::TupleFieldList(_) => {
+ return None;
+ }
+ }
+}
+
+fn parse_record_field(record_field: ast::RecordField, mutable: bool) -> Option<RecordFieldInfo> {
+ let field_name = record_field.name()?;
+ let field_ty = record_field.ty()?;
+
+ let mut fn_name = to_lower_snake_case(&field_name.to_string());
+ if mutable {
+ format_to!(fn_name, "_mut");
+ }
+
+ let target = record_field.syntax().text_range();
+
+ Some(RecordFieldInfo { field_name, field_ty, fn_name, target })
+}
+
#[cfg(test)]
mod tests {
use crate::tests::{check_assist, check_assist_not_applicable};
@@ -489,4 +659,53 @@ impl Context {
"#,
);
}
+
+ #[test]
+ fn test_generate_multiple_getters_from_selection() {
+ check_assist(
+ generate_getter,
+ r#"
+struct Context {
+ $0data: Data,
+ count: usize,$0
+}
+ "#,
+ r#"
+struct Context {
+ data: Data,
+ count: usize,
+}
+
+impl Context {
+ fn data(&self) -> &Data {
+ &self.data
+ }
+
+ fn $0count(&self) -> &usize {
+ &self.count
+ }
+}
+ "#,
+ );
+ }
+
+ #[test]
+ fn test_generate_multiple_getters_from_selection_one_already_exists() {
+ // As impl for one of the fields already exist, skip it
+ check_assist_not_applicable(
+ generate_getter,
+ r#"
+struct Context {
+ $0data: Data,
+ count: usize,$0
+}
+
+impl Context {
+ fn data(&self) -> &Data {
+ &self.data
+ }
+}
+ "#,
+ );
+ }
}
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs
index 68287a20b..9af26c04e 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs
@@ -28,7 +28,7 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
acc.add(
AssistId("generate_impl", AssistKind::Generate),
- format!("Generate impl for `{}`", name),
+ format!("Generate impl for `{name}`"),
target,
|edit| {
let start_offset = nominal.syntax().text_range().end();
@@ -52,6 +52,7 @@ mod tests {
use super::*;
+ // FIXME: break up into separate test fns
#[test]
fn test_add_impl() {
check_assist(
@@ -136,6 +137,18 @@ mod tests {
check_assist(
generate_impl,
+ r#"
+ struct Defaulted<const N: i32 = 0> {}$0"#,
+ r#"
+ struct Defaulted<const N: i32 = 0> {}
+
+ impl<const N: i32> Defaulted<N> {
+ $0
+ }"#,
+ );
+
+ check_assist(
+ generate_impl,
r#"pub trait Trait {}
struct Struct<T>$0
where
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_new.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_new.rs
index 6c93875e9..17fadea0e 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_new.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_new.rs
@@ -39,7 +39,8 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
};
// Return early if we've found an existing new fn
- let impl_def = find_struct_impl(ctx, &ast::Adt::Struct(strukt.clone()), "new")?;
+ let impl_def =
+ find_struct_impl(ctx, &ast::Adt::Struct(strukt.clone()), &[String::from("new")])?;
let current_module = ctx.sema.scope(strukt.syntax())?.module();
@@ -51,17 +52,22 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
buf.push('\n');
}
- let vis = strukt.visibility().map_or(String::new(), |v| format!("{} ", v));
+ let vis = strukt.visibility().map_or(String::new(), |v| format!("{v} "));
let trivial_constructors = field_list
.fields()
.map(|f| {
+ let name = f.name()?;
+
let ty = ctx.sema.resolve_type(&f.ty()?)?;
let item_in_ns = hir::ItemInNs::from(hir::ModuleDef::from(ty.as_adt()?));
- let type_path = current_module
- .find_use_path(ctx.sema.db, item_for_path_search(ctx.sema.db, item_in_ns)?)?;
+ let type_path = current_module.find_use_path(
+ ctx.sema.db,
+ item_for_path_search(ctx.sema.db, item_in_ns)?,
+ ctx.config.prefer_no_std,
+ )?;
let expr = use_trivial_constructor(
&ctx.sema.db,
@@ -69,7 +75,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
&ty,
)?;
- Some(format!("{}: {}", f.name()?.syntax(), expr))
+ Some(format!("{name}: {expr}"))
})
.collect::<Vec<_>>();
@@ -78,7 +84,10 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
.enumerate()
.filter_map(|(i, f)| {
if trivial_constructors[i].is_none() {
- Some(format!("{}: {}", f.name()?.syntax(), f.ty()?.syntax()))
+ let name = f.name()?;
+ let ty = f.ty()?;
+
+ Some(format!("{name}: {ty}"))
} else {
None
}
@@ -98,7 +107,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
})
.format(", ");
- format_to!(buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}", vis, params, fields);
+ format_to!(buf, " {vis}fn new({params}) -> Self {{ Self {{ {fields} }} }}");
let start_offset = impl_def
.and_then(|impl_def| find_impl_block_start(impl_def, &mut buf))
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_setter.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_setter.rs
index 2a7ad6ce3..62f72df1c 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_setter.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_setter.rs
@@ -36,11 +36,8 @@ pub(crate) fn generate_setter(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
// Return early if we've found an existing fn
let fn_name = to_lower_snake_case(&field_name.to_string());
- let impl_def = find_struct_impl(
- ctx,
- &ast::Adt::Struct(strukt.clone()),
- format!("set_{}", fn_name).as_str(),
- )?;
+ let impl_def =
+ find_struct_impl(ctx, &ast::Adt::Struct(strukt.clone()), &[format!("set_{fn_name}")])?;
let target = field.syntax().text_range();
acc.add_group(
@@ -55,18 +52,12 @@ pub(crate) fn generate_setter(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opt
buf.push('\n');
}
- let vis = strukt.visibility().map_or(String::new(), |v| format!("{} ", v));
+ let vis = strukt.visibility().map_or(String::new(), |v| format!("{v} "));
format_to!(
buf,
- " {}fn set_{}(&mut self, {}: {}) {{
- self.{} = {};
- }}",
- vis,
- fn_name,
- fn_name,
- field_ty,
- fn_name,
- fn_name,
+ " {vis}fn set_{fn_name}(&mut self, {fn_name}: {field_ty}) {{
+ self.{fn_name} = {fn_name};
+ }}"
);
let start_offset = impl_def
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_format_string_arg.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_format_string_arg.rs
new file mode 100644
index 000000000..aa710d2ce
--- /dev/null
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_format_string_arg.rs
@@ -0,0 +1,296 @@
+use crate::{AssistContext, Assists};
+use ide_db::{
+ assists::{AssistId, AssistKind},
+ syntax_helpers::{
+ format_string::is_format_string,
+ format_string_exprs::{parse_format_exprs, Arg},
+ },
+};
+use itertools::Itertools;
+use stdx::format_to;
+use syntax::{ast, AstNode, AstToken, NodeOrToken, SyntaxKind::COMMA, TextRange};
+
+// Assist: move_format_string_arg
+//
+// Move an expression out of a format string.
+//
+// ```
+// macro_rules! format_args {
+// ($lit:literal $(tt:tt)*) => { 0 },
+// }
+// macro_rules! print {
+// ($($arg:tt)*) => (std::io::_print(format_args!($($arg)*)));
+// }
+//
+// fn main() {
+// print!("{x + 1}$0");
+// }
+// ```
+// ->
+// ```
+// macro_rules! format_args {
+// ($lit:literal $(tt:tt)*) => { 0 },
+// }
+// macro_rules! print {
+// ($($arg:tt)*) => (std::io::_print(format_args!($($arg)*)));
+// }
+//
+// fn main() {
+// print!("{}"$0, x + 1);
+// }
+// ```
+
+pub(crate) fn move_format_string_arg(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
+ let fmt_string = ctx.find_token_at_offset::<ast::String>()?;
+ let tt = fmt_string.syntax().parent().and_then(ast::TokenTree::cast)?;
+
+ let expanded_t = ast::String::cast(
+ ctx.sema.descend_into_macros_with_kind_preference(fmt_string.syntax().clone()),
+ )?;
+ if !is_format_string(&expanded_t) {
+ return None;
+ }
+
+ let (new_fmt, extracted_args) = parse_format_exprs(fmt_string.text()).ok()?;
+ if extracted_args.is_empty() {
+ return None;
+ }
+
+ acc.add(
+ AssistId(
+ "move_format_string_arg",
+ // if there aren't any expressions, then make the assist a RefactorExtract
+ if extracted_args.iter().filter(|f| matches!(f, Arg::Expr(_))).count() == 0 {
+ AssistKind::RefactorExtract
+ } else {
+ AssistKind::QuickFix
+ },
+ ),
+ "Extract format args",
+ tt.syntax().text_range(),
+ |edit| {
+ let fmt_range = fmt_string.syntax().text_range();
+
+ // Replace old format string with new format string whose arguments have been extracted
+ edit.replace(fmt_range, new_fmt);
+
+ // Insert cursor at end of format string
+ edit.insert(fmt_range.end(), "$0");
+
+ // Extract existing arguments in macro
+ let tokens =
+ tt.token_trees_and_tokens().collect_vec();
+
+ let mut existing_args: Vec<String> = vec![];
+
+ let mut current_arg = String::new();
+ if let [_opening_bracket, NodeOrToken::Token(format_string), _args_start_comma, tokens @ .., NodeOrToken::Token(end_bracket)] =
+ tokens.as_slice()
+ {
+ for t in tokens {
+ match t {
+ NodeOrToken::Node(n) => {
+ format_to!(current_arg, "{n}");
+ },
+ NodeOrToken::Token(t) if t.kind() == COMMA=> {
+ existing_args.push(current_arg.trim().into());
+ current_arg.clear();
+ },
+ NodeOrToken::Token(t) => {
+ current_arg.push_str(t.text());
+ },
+ }
+ }
+ existing_args.push(current_arg.trim().into());
+
+ // delete everything after the format string till end bracket
+ // we're going to insert the new arguments later
+ edit.delete(TextRange::new(
+ format_string.text_range().end(),
+ end_bracket.text_range().start(),
+ ));
+ }
+
+ // Start building the new args
+ let mut existing_args = existing_args.into_iter();
+ let mut args = String::new();
+
+ let mut placeholder_idx = 1;
+
+ for extracted_args in extracted_args {
+ // remove expr from format string
+ args.push_str(", ");
+
+ match extracted_args {
+ Arg::Ident(s) | Arg::Expr(s) => {
+ // insert arg
+ args.push_str(&s);
+ }
+ Arg::Placeholder => {
+ // try matching with existing argument
+ match existing_args.next() {
+ Some(ea) => {
+ args.push_str(&ea);
+ }
+ None => {
+ // insert placeholder
+ args.push_str(&format!("${placeholder_idx}"));
+ placeholder_idx += 1;
+ }
+ }
+ }
+ }
+ }
+
+ // Insert new args
+ edit.insert(fmt_range.end(), args);
+ },
+ );
+
+ Some(())
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::tests::check_assist;
+
+ const MACRO_DECL: &'static str = r#"
+macro_rules! format_args {
+ ($lit:literal $(tt:tt)*) => { 0 },
+}
+macro_rules! print {
+ ($($arg:tt)*) => (std::io::_print(format_args!($($arg)*)));
+}
+"#;
+
+ fn add_macro_decl(s: &'static str) -> String {
+ MACRO_DECL.to_string() + s
+ }
+
+ #[test]
+ fn multiple_middle_arg() {
+ check_assist(
+ move_format_string_arg,
+ &add_macro_decl(
+ r#"
+fn main() {
+ print!("{} {x + 1:b} {}$0", y + 2, 2);
+}
+"#,
+ ),
+ &add_macro_decl(
+ r#"
+fn main() {
+ print!("{} {:b} {}"$0, y + 2, x + 1, 2);
+}
+"#,
+ ),
+ );
+ }
+
+ #[test]
+ fn single_arg() {
+ check_assist(
+ move_format_string_arg,
+ &add_macro_decl(
+ r#"
+fn main() {
+ print!("{obj.value:b}$0",);
+}
+"#,
+ ),
+ &add_macro_decl(
+ r#"
+fn main() {
+ print!("{:b}"$0, obj.value);
+}
+"#,
+ ),
+ );
+ }
+
+ #[test]
+ fn multiple_middle_placeholders_arg() {
+ check_assist(
+ move_format_string_arg,
+ &add_macro_decl(
+ r#"
+fn main() {
+ print!("{} {x + 1:b} {} {}$0", y + 2, 2);
+}
+"#,
+ ),
+ &add_macro_decl(
+ r#"
+fn main() {
+ print!("{} {:b} {} {}"$0, y + 2, x + 1, 2, $1);
+}
+"#,
+ ),
+ );
+ }
+
+ #[test]
+ fn multiple_trailing_args() {
+ check_assist(
+ move_format_string_arg,
+ &add_macro_decl(
+ r#"
+fn main() {
+ print!("{} {x + 1:b} {Struct(1, 2)}$0", 1);
+}
+"#,
+ ),
+ &add_macro_decl(
+ r#"
+fn main() {
+ print!("{} {:b} {}"$0, 1, x + 1, Struct(1, 2));
+}
+"#,
+ ),
+ );
+ }
+
+ #[test]
+ fn improper_commas() {
+ check_assist(
+ move_format_string_arg,
+ &add_macro_decl(
+ r#"
+fn main() {
+ print!("{} {x + 1:b} {Struct(1, 2)}$0", 1,);
+}
+"#,
+ ),
+ &add_macro_decl(
+ r#"
+fn main() {
+ print!("{} {:b} {}"$0, 1, x + 1, Struct(1, 2));
+}
+"#,
+ ),
+ );
+ }
+
+ #[test]
+ fn nested_tt() {
+ check_assist(
+ move_format_string_arg,
+ &add_macro_decl(
+ r#"
+fn main() {
+ print!("My name is {} {x$0 + x}", stringify!(Paperino))
+}
+"#,
+ ),
+ &add_macro_decl(
+ r#"
+fn main() {
+ print!("My name is {} {}"$0, stringify!(Paperino), x + x)
+}
+"#,
+ ),
+ );
+ }
+}
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_method_call.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_method_call.rs
index 121f8b4a1..e57d1d065 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_method_call.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_method_call.rs
@@ -44,8 +44,11 @@ pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext<'_>) ->
let current_module = ctx.sema.scope(call.syntax())?.module();
let target_module_def = ModuleDef::from(resolved_call);
let item_in_ns = ItemInNs::from(target_module_def);
- let receiver_path = current_module
- .find_use_path(ctx.sema.db, item_for_path_search(ctx.sema.db, item_in_ns)?)?;
+ let receiver_path = current_module.find_use_path(
+ ctx.sema.db,
+ item_for_path_search(ctx.sema.db, item_in_ns)?,
+ ctx.config.prefer_no_std,
+ )?;
let qualify_candidate = QualifyCandidate::ImplMethod(ctx.sema.db, call, resolved_call);
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_path.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_path.rs
index 0c2e9da38..4b2af550b 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_path.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/qualify_path.rs
@@ -37,7 +37,8 @@ use crate::{
// ```
pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let (import_assets, syntax_under_caret) = find_importable_node(ctx)?;
- let mut proposed_imports = import_assets.search_for_relative_paths(&ctx.sema);
+ let mut proposed_imports =
+ import_assets.search_for_relative_paths(&ctx.sema, ctx.config.prefer_no_std);
if proposed_imports.is_empty() {
return None;
}
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
index d139f78a6..9fd5e1886 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
@@ -85,7 +85,7 @@ pub(crate) fn replace_derive_with_manual_impl(
})
.flat_map(|trait_| {
current_module
- .find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_))
+ .find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_), ctx.config.prefer_no_std)
.as_ref()
.map(mod_path_to_ast)
.zip(Some(trait_))
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs
index 2419fa11c..dbbc56958 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs
@@ -67,6 +67,7 @@ pub(crate) fn replace_qualified_name_with_use(
ctx.sema.db,
module,
ctx.config.insert_use.prefix_kind,
+ ctx.config.prefer_no_std,
)
})
.flatten();
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unwrap_tuple.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unwrap_tuple.rs
new file mode 100644
index 000000000..25c58d086
--- /dev/null
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/unwrap_tuple.rs
@@ -0,0 +1,159 @@
+use syntax::{
+ ast::{self, edit::AstNodeEdit},
+ AstNode, T,
+};
+
+use crate::{AssistContext, AssistId, AssistKind, Assists};
+
+// Assist: unwrap_tuple
+//
+// Unwrap the tuple to different variables.
+//
+// ```
+// # //- minicore: result
+// fn main() {
+// $0let (foo, bar) = ("Foo", "Bar");
+// }
+// ```
+// ->
+// ```
+// fn main() {
+// let foo = "Foo";
+// let bar = "Bar";
+// }
+// ```
+pub(crate) fn unwrap_tuple(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
+ let let_kw = ctx.find_token_syntax_at_offset(T![let])?;
+ let let_stmt = let_kw.parent().and_then(ast::LetStmt::cast)?;
+ let indent_level = let_stmt.indent_level().0 as usize;
+ let pat = let_stmt.pat()?;
+ let ty = let_stmt.ty();
+ let init = let_stmt.initializer()?;
+
+ // This only applies for tuple patterns, types, and initializers.
+ let tuple_pat = match pat {
+ ast::Pat::TuplePat(pat) => pat,
+ _ => return None,
+ };
+ let tuple_ty = ty.and_then(|it| match it {
+ ast::Type::TupleType(ty) => Some(ty),
+ _ => None,
+ });
+ let tuple_init = match init {
+ ast::Expr::TupleExpr(expr) => expr,
+ _ => return None,
+ };
+
+ if tuple_pat.fields().count() != tuple_init.fields().count() {
+ return None;
+ }
+ if let Some(tys) = &tuple_ty {
+ if tuple_pat.fields().count() != tys.fields().count() {
+ return None;
+ }
+ }
+
+ let parent = let_kw.parent()?;
+
+ acc.add(
+ AssistId("unwrap_tuple", AssistKind::RefactorRewrite),
+ "Unwrap tuple",
+ let_kw.text_range(),
+ |edit| {
+ let indents = " ".repeat(indent_level);
+
+ // If there is an ascribed type, insert that type for each declaration,
+ // otherwise, omit that type.
+ if let Some(tys) = tuple_ty {
+ let mut zipped_decls = String::new();
+ for (pat, ty, expr) in
+ itertools::izip!(tuple_pat.fields(), tys.fields(), tuple_init.fields())
+ {
+ zipped_decls.push_str(&format!("{}let {pat}: {ty} = {expr};\n", indents))
+ }
+ edit.replace(parent.text_range(), zipped_decls.trim());
+ } else {
+ let mut zipped_decls = String::new();
+ for (pat, expr) in itertools::izip!(tuple_pat.fields(), tuple_init.fields()) {
+ zipped_decls.push_str(&format!("{}let {pat} = {expr};\n", indents));
+ }
+ edit.replace(parent.text_range(), zipped_decls.trim());
+ }
+ },
+ )
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::tests::check_assist;
+
+ use super::*;
+
+ #[test]
+ fn unwrap_tuples() {
+ check_assist(
+ unwrap_tuple,
+ r#"
+fn main() {
+ $0let (foo, bar) = ("Foo", "Bar");
+}
+"#,
+ r#"
+fn main() {
+ let foo = "Foo";
+ let bar = "Bar";
+}
+"#,
+ );
+
+ check_assist(
+ unwrap_tuple,
+ r#"
+fn main() {
+ $0let (foo, bar, baz) = ("Foo", "Bar", "Baz");
+}
+"#,
+ r#"
+fn main() {
+ let foo = "Foo";
+ let bar = "Bar";
+ let baz = "Baz";
+}
+"#,
+ );
+ }
+
+ #[test]
+ fn unwrap_tuple_with_types() {
+ check_assist(
+ unwrap_tuple,
+ r#"
+fn main() {
+ $0let (foo, bar): (u8, i32) = (5, 10);
+}
+"#,
+ r#"
+fn main() {
+ let foo: u8 = 5;
+ let bar: i32 = 10;
+}
+"#,
+ );
+
+ check_assist(
+ unwrap_tuple,
+ r#"
+fn main() {
+ $0let (foo, bar, baz): (u8, i32, f64) = (5, 10, 17.5);
+}
+"#,
+ r#"
+fn main() {
+ let foo: u8 = 5;
+ let bar: i32 = 10;
+ let baz: f64 = 17.5;
+}
+"#,
+ );
+ }
+}
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/lib.rs b/src/tools/rust-analyzer/crates/ide-assists/src/lib.rs
index e52544db5..a07318cef 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/lib.rs
@@ -121,6 +121,7 @@ mod handlers {
mod convert_iter_for_each_to_for;
mod convert_let_else_to_match;
mod convert_tuple_struct_to_named_struct;
+ mod convert_named_struct_to_tuple_struct;
mod convert_to_guarded_return;
mod convert_two_arm_bool_match_to_matches_macro;
mod convert_while_to_loop;
@@ -136,6 +137,7 @@ mod handlers {
mod flip_binexpr;
mod flip_comma;
mod flip_trait_bound;
+ mod move_format_string_arg;
mod generate_constant;
mod generate_default_from_enum_variant;
mod generate_default_from_new;
@@ -188,6 +190,7 @@ mod handlers {
mod replace_turbofish_with_explicit_type;
mod split_import;
mod unmerge_match_arm;
+ mod unwrap_tuple;
mod sort_items;
mod toggle_ignore;
mod unmerge_use;
@@ -216,6 +219,7 @@ mod handlers {
convert_iter_for_each_to_for::convert_iter_for_each_to_for,
convert_iter_for_each_to_for::convert_for_loop_with_for_each,
convert_let_else_to_match::convert_let_else_to_match,
+ convert_named_struct_to_tuple_struct::convert_named_struct_to_tuple_struct,
convert_to_guarded_return::convert_to_guarded_return,
convert_tuple_struct_to_named_struct::convert_tuple_struct_to_named_struct,
convert_two_arm_bool_match_to_matches_macro::convert_two_arm_bool_match_to_matches_macro,
@@ -254,6 +258,7 @@ mod handlers {
merge_imports::merge_imports,
merge_match_arms::merge_match_arms,
move_bounds::move_bounds_to_where_clause,
+ move_format_string_arg::move_format_string_arg,
move_guard::move_arm_cond_to_match_guard,
move_guard::move_guard_to_arm_body,
move_module_to_file::move_module_to_file,
@@ -289,6 +294,7 @@ mod handlers {
unnecessary_async::unnecessary_async,
unwrap_block::unwrap_block,
unwrap_result_return_type::unwrap_result_return_type,
+ unwrap_tuple::unwrap_tuple,
wrap_return_type_in_result::wrap_return_type_in_result,
// These are manually sorted for better priorities. By default,
// priority is determined by the size of the target range (smaller
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/tests.rs b/src/tools/rust-analyzer/crates/ide-assists/src/tests.rs
index 9cd66c6b3..f7f2417d0 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/tests.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/tests.rs
@@ -29,6 +29,7 @@ pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig {
group: true,
skip_glob_imports: true,
},
+ prefer_no_std: false,
};
pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
@@ -95,8 +96,10 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
});
let actual = {
- let source_change =
- assist.source_change.expect("Assist did not contain any source changes");
+ let source_change = assist
+ .source_change
+ .filter(|it| !it.source_file_edits.is_empty() || !it.file_system_edits.is_empty())
+ .expect("Assist did not contain any source changes");
let mut actual = before;
if let Some(source_file_edit) = source_change.get_source_edit(file_id) {
source_file_edit.apply(&mut actual);
@@ -139,8 +142,10 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult<'_>, assist_la
match (assist, expected) {
(Some(assist), ExpectedResult::After(after)) => {
- let source_change =
- assist.source_change.expect("Assist did not contain any source changes");
+ let source_change = assist
+ .source_change
+ .filter(|it| !it.source_file_edits.is_empty() || !it.file_system_edits.is_empty())
+ .expect("Assist did not contain any source changes");
let skip_header = source_change.source_file_edits.len() == 1
&& source_change.file_system_edits.len() == 0;
@@ -227,6 +232,7 @@ fn assist_order_field_struct() {
assert_eq!(assists.next().expect("expected assist").label, "Generate a getter method");
assert_eq!(assists.next().expect("expected assist").label, "Generate a mut getter method");
assert_eq!(assists.next().expect("expected assist").label, "Generate a setter method");
+ assert_eq!(assists.next().expect("expected assist").label, "Convert to tuple struct");
assert_eq!(assists.next().expect("expected assist").label, "Add `#[derive]`");
}
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/tests/generated.rs b/src/tools/rust-analyzer/crates/ide-assists/src/tests/generated.rs
index 227e2300f..2c4000efe 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/tests/generated.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/tests/generated.rs
@@ -408,6 +408,47 @@ fn main() {
}
#[test]
+fn doctest_convert_named_struct_to_tuple_struct() {
+ check_doc_test(
+ "convert_named_struct_to_tuple_struct",
+ r#####"
+struct Point$0 { x: f32, y: f32 }
+
+impl Point {
+ pub fn new(x: f32, y: f32) -> Self {
+ Point { x, y }
+ }
+
+ pub fn x(&self) -> f32 {
+ self.x
+ }
+
+ pub fn y(&self) -> f32 {
+ self.y
+ }
+}
+"#####,
+ r#####"
+struct Point(f32, f32);
+
+impl Point {
+ pub fn new(x: f32, y: f32) -> Self {
+ Point(x, y)
+ }
+
+ pub fn x(&self) -> f32 {
+ self.0
+ }
+
+ pub fn y(&self) -> f32 {
+ self.1
+ }
+}
+"#####,
+ )
+}
+
+#[test]
fn doctest_convert_to_guarded_return() {
check_doc_test(
"convert_to_guarded_return",
@@ -1592,6 +1633,37 @@ fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U {
}
#[test]
+fn doctest_move_format_string_arg() {
+ check_doc_test(
+ "move_format_string_arg",
+ r#####"
+macro_rules! format_args {
+ ($lit:literal $(tt:tt)*) => { 0 },
+}
+macro_rules! print {
+ ($($arg:tt)*) => (std::io::_print(format_args!($($arg)*)));
+}
+
+fn main() {
+ print!("{x + 1}$0");
+}
+"#####,
+ r#####"
+macro_rules! format_args {
+ ($lit:literal $(tt:tt)*) => { 0 },
+}
+macro_rules! print {
+ ($($arg:tt)*) => (std::io::_print(format_args!($($arg)*)));
+}
+
+fn main() {
+ print!("{}"$0, x + 1);
+}
+"#####,
+ )
+}
+
+#[test]
fn doctest_move_from_mod_rs() {
check_doc_test(
"move_from_mod_rs",
@@ -2356,6 +2428,25 @@ fn foo() -> i32 { 42i32 }
}
#[test]
+fn doctest_unwrap_tuple() {
+ check_doc_test(
+ "unwrap_tuple",
+ r#####"
+//- minicore: result
+fn main() {
+ $0let (foo, bar) = ("Foo", "Bar");
+}
+"#####,
+ r#####"
+fn main() {
+ let foo = "Foo";
+ let bar = "Bar";
+}
+"#####,
+ )
+}
+
+#[test]
fn doctest_wrap_return_type_in_result() {
check_doc_test(
"wrap_return_type_in_result",
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs b/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs
index 4ab6e2627..db32e7182 100644
--- a/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs
+++ b/src/tools/rust-analyzer/crates/ide-assists/src/utils.rs
@@ -2,8 +2,6 @@
use std::ops;
-use itertools::Itertools;
-
pub(crate) use gen_trait_fn_body::gen_trait_fn_body;
use hir::{db::HirDatabase, HirDisplay, Semantics};
use ide_db::{famous_defs::FamousDefs, path_transform::PathTransform, RootDatabase, SnippetCap};
@@ -15,7 +13,7 @@ use syntax::{
edit_in_place::{AttrsOwnerEdit, Removable},
make, HasArgList, HasAttrs, HasGenericParams, HasName, HasTypeBounds, Whitespace,
},
- ted, AstNode, AstToken, Direction, SmolStr, SourceFile,
+ ted, AstNode, AstToken, Direction, SourceFile,
SyntaxKind::*,
SyntaxNode, TextRange, TextSize, T,
};
@@ -333,10 +331,14 @@ fn calc_depth(pat: &ast::Pat, depth: usize) -> usize {
// FIXME: change the new fn checking to a more semantic approach when that's more
// viable (e.g. we process proc macros, etc)
// FIXME: this partially overlaps with `find_impl_block_*`
+
+/// `find_struct_impl` looks for impl of a struct, but this also has additional feature
+/// where it takes a list of function names and check if they exist inside impl_, if
+/// even one match is found, it returns None
pub(crate) fn find_struct_impl(
ctx: &AssistContext<'_>,
adt: &ast::Adt,
- name: &str,
+ names: &[String],
) -> Option<Option<ast::Impl>> {
let db = ctx.db();
let module = adt.syntax().parent()?;
@@ -364,7 +366,7 @@ pub(crate) fn find_struct_impl(
});
if let Some(ref impl_blk) = block {
- if has_fn(impl_blk, name) {
+ if has_any_fn(impl_blk, names) {
return None;
}
}
@@ -372,12 +374,12 @@ pub(crate) fn find_struct_impl(
Some(block)
}
-fn has_fn(imp: &ast::Impl, rhs_name: &str) -> bool {
+fn has_any_fn(imp: &ast::Impl, names: &[String]) -> bool {
if let Some(il) = imp.assoc_item_list() {
for item in il.assoc_items() {
if let ast::AssocItem::Fn(f) = item {
if let Some(name) = f.name() {
- if name.text().eq_ignore_ascii_case(rhs_name) {
+ if names.iter().any(|n| n.eq_ignore_ascii_case(&name.text())) {
return true;
}
}
@@ -424,34 +426,44 @@ pub(crate) fn generate_trait_impl_text(adt: &ast::Adt, trait_text: &str, code: &
}
fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str) -> String {
- let generic_params = adt.generic_param_list();
+ // Ensure lifetime params are before type & const params
+ let generic_params = adt.generic_param_list().map(|generic_params| {
+ let lifetime_params =
+ generic_params.lifetime_params().map(ast::GenericParam::LifetimeParam);
+ let ty_or_const_params = generic_params.type_or_const_params().filter_map(|param| {
+ // remove defaults since they can't be specified in impls
+ match param {
+ ast::TypeOrConstParam::Type(param) => {
+ let param = param.clone_for_update();
+ param.remove_default();
+ Some(ast::GenericParam::TypeParam(param))
+ }
+ ast::TypeOrConstParam::Const(param) => {
+ let param = param.clone_for_update();
+ param.remove_default();
+ Some(ast::GenericParam::ConstParam(param))
+ }
+ }
+ });
+
+ make::generic_param_list(itertools::chain(lifetime_params, ty_or_const_params))
+ });
+
+ // FIXME: use syntax::make & mutable AST apis instead
+ // `trait_text` and `code` can't be opaque blobs of text
let mut buf = String::with_capacity(code.len());
+
+ // Copy any cfg attrs from the original adt
buf.push_str("\n\n");
- adt.attrs()
- .filter(|attr| attr.as_simple_call().map(|(name, _arg)| name == "cfg").unwrap_or(false))
- .for_each(|attr| buf.push_str(format!("{}\n", attr).as_str()));
+ let cfg_attrs = adt
+ .attrs()
+ .filter(|attr| attr.as_simple_call().map(|(name, _arg)| name == "cfg").unwrap_or(false));
+ cfg_attrs.for_each(|attr| buf.push_str(&format!("{attr}\n")));
+
+ // `impl{generic_params} {trait_text} for {name}{generic_params.to_generic_args()}`
buf.push_str("impl");
if let Some(generic_params) = &generic_params {
- let lifetimes = generic_params.lifetime_params().map(|lt| format!("{}", lt.syntax()));
- let toc_params = generic_params.type_or_const_params().map(|toc_param| {
- let type_param = match toc_param {
- ast::TypeOrConstParam::Type(x) => x,
- ast::TypeOrConstParam::Const(x) => return x.syntax().to_string(),
- };
- let mut buf = String::new();
- if let Some(it) = type_param.name() {
- format_to!(buf, "{}", it.syntax());
- }
- if let Some(it) = type_param.colon_token() {
- format_to!(buf, "{} ", it);
- }
- if let Some(it) = type_param.type_bound_list() {
- format_to!(buf, "{}", it.syntax());
- }
- buf
- });
- let generics = lifetimes.chain(toc_params).format(", ");
- format_to!(buf, "<{}>", generics);
+ format_to!(buf, "{generic_params}");
}
buf.push(' ');
if let Some(trait_text) = trait_text {
@@ -460,23 +472,15 @@ fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str
}
buf.push_str(&adt.name().unwrap().text());
if let Some(generic_params) = generic_params {
- let lifetime_params = generic_params
- .lifetime_params()
- .filter_map(|it| it.lifetime())
- .map(|it| SmolStr::from(it.text()));
- let toc_params = generic_params
- .type_or_const_params()
- .filter_map(|it| it.name())
- .map(|it| SmolStr::from(it.text()));
- format_to!(buf, "<{}>", lifetime_params.chain(toc_params).format(", "))
+ format_to!(buf, "{}", generic_params.to_generic_args());
}
match adt.where_clause() {
Some(where_clause) => {
- format_to!(buf, "\n{}\n{{\n{}\n}}", where_clause, code);
+ format_to!(buf, "\n{where_clause}\n{{\n{code}\n}}");
}
None => {
- format_to!(buf, " {{\n{}\n}}", code);
+ format_to!(buf, " {{\n{code}\n}}");
}
}
diff --git a/src/tools/rust-analyzer/crates/ide-completion/Cargo.toml b/src/tools/rust-analyzer/crates/ide-completion/Cargo.toml
index 8c9d6b228..75835bce9 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/ide-completion/Cargo.toml
@@ -11,10 +11,10 @@ doctest = false
[dependencies]
cov-mark = "2.0.0-pre.1"
-itertools = "0.10.3"
+itertools = "0.10.5"
-once_cell = "1.12.0"
-smallvec = "1.9.0"
+once_cell = "1.15.0"
+smallvec = "1.10.0"
stdx = { path = "../stdx", version = "0.0.0" }
syntax = { path = "../syntax", version = "0.0.0" }
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions.rs
index 55c3e2839..296dfc142 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/completions.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions.rs
@@ -19,6 +19,7 @@ pub(crate) mod snippet;
pub(crate) mod r#type;
pub(crate) mod use_;
pub(crate) mod vis;
+pub(crate) mod env_vars;
use std::iter;
@@ -551,7 +552,11 @@ fn enum_variants_with_paths(
}
for variant in variants {
- if let Some(path) = ctx.module.find_use_path(ctx.db, hir::ModuleDef::from(variant)) {
+ if let Some(path) = ctx.module.find_use_path(
+ ctx.db,
+ hir::ModuleDef::from(variant),
+ ctx.config.prefer_no_std,
+ ) {
// Variants with trivial paths are already added by the existing completion logic,
// so we should avoid adding these twice
if path.segments().len() > 1 {
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/env_vars.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/env_vars.rs
new file mode 100644
index 000000000..09e95e53d
--- /dev/null
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/env_vars.rs
@@ -0,0 +1,150 @@
+//! Completes environment variables defined by Cargo (https://doc.rust-lang.org/cargo/reference/environment-variables.html)
+use hir::Semantics;
+use ide_db::{syntax_helpers::node_ext::macro_call_for_string_token, RootDatabase};
+use syntax::ast::{self, IsString};
+
+use crate::{
+ completions::Completions, context::CompletionContext, CompletionItem, CompletionItemKind,
+};
+
+const CARGO_DEFINED_VARS: &[(&str, &str)] = &[
+ ("CARGO","Path to the cargo binary performing the build"),
+ ("CARGO_MANIFEST_DIR","The directory containing the manifest of your package"),
+ ("CARGO_PKG_VERSION","The full version of your package"),
+ ("CARGO_PKG_VERSION_MAJOR","The major version of your package"),
+ ("CARGO_PKG_VERSION_MINOR","The minor version of your package"),
+ ("CARGO_PKG_VERSION_PATCH","The patch version of your package"),
+ ("CARGO_PKG_VERSION_PRE","The pre-release version of your package"),
+ ("CARGO_PKG_AUTHORS","Colon separated list of authors from the manifest of your package"),
+ ("CARGO_PKG_NAME","The name of your package"),
+ ("CARGO_PKG_DESCRIPTION","The description from the manifest of your package"),
+ ("CARGO_PKG_HOMEPAGE","The home page from the manifest of your package"),
+ ("CARGO_PKG_REPOSITORY","The repository from the manifest of your package"),
+ ("CARGO_PKG_LICENSE","The license from the manifest of your package"),
+ ("CARGO_PKG_LICENSE_FILE","The license file from the manifest of your package"),
+ ("CARGO_PKG_RUST_VERSION","The Rust version from the manifest of your package. Note that this is the minimum Rust version supported by the package, not the current Rust version"),
+ ("CARGO_CRATE_NAME","The name of the crate that is currently being compiled"),
+ ("CARGO_BIN_NAME","The name of the binary that is currently being compiled (if it is a binary). This name does not include any file extension, such as .exe"),
+ ("CARGO_PRIMARY_PACKAGE","This environment variable will be set if the package being built is primary. Primary packages are the ones the user selected on the command-line, either with -p flags or the defaults based on the current directory and the default workspace members. This environment variable will not be set when building dependencies. This is only set when compiling the package (not when running binaries or tests)"),
+ ("CARGO_TARGET_TMPDIR","Only set when building integration test or benchmark code. This is a path to a directory inside the target directory where integration tests or benchmarks are free to put any data needed by the tests/benches. Cargo initially creates this directory but doesn't manage its content in any way, this is the responsibility of the test code")
+];
+
+pub(crate) fn complete_cargo_env_vars(
+ acc: &mut Completions,
+ ctx: &CompletionContext<'_>,
+ expanded: &ast::String,
+) -> Option<()> {
+ guard_env_macro(expanded, &ctx.sema)?;
+ let range = expanded.text_range_between_quotes()?;
+
+ CARGO_DEFINED_VARS.iter().for_each(|(var, detail)| {
+ let mut item = CompletionItem::new(CompletionItemKind::Keyword, range, var);
+ item.detail(*detail);
+ item.add_to(acc);
+ });
+
+ Some(())
+}
+
+fn guard_env_macro(string: &ast::String, semantics: &Semantics<'_, RootDatabase>) -> Option<()> {
+ let call = macro_call_for_string_token(string)?;
+ let name = call.path()?.segment()?.name_ref()?;
+ let makro = semantics.resolve_macro_call(&call)?;
+ let db = semantics.db;
+
+ match name.text().as_str() {
+ "env" | "option_env" if makro.kind(db) == hir::MacroKind::BuiltIn => Some(()),
+ _ => None,
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::tests::{check_edit, completion_list};
+
+ fn check(macro_name: &str) {
+ check_edit(
+ "CARGO_BIN_NAME",
+ &format!(
+ r#"
+ #[rustc_builtin_macro]
+ macro_rules! {} {{
+ ($var:literal) => {{ 0 }}
+ }}
+
+ fn main() {{
+ let foo = {}!("CAR$0");
+ }}
+ "#,
+ macro_name, macro_name
+ ),
+ &format!(
+ r#"
+ #[rustc_builtin_macro]
+ macro_rules! {} {{
+ ($var:literal) => {{ 0 }}
+ }}
+
+ fn main() {{
+ let foo = {}!("CARGO_BIN_NAME");
+ }}
+ "#,
+ macro_name, macro_name
+ ),
+ );
+ }
+ #[test]
+ fn completes_env_variable_in_env() {
+ check("env")
+ }
+
+ #[test]
+ fn completes_env_variable_in_option_env() {
+ check("option_env");
+ }
+
+ #[test]
+ fn doesnt_complete_in_random_strings() {
+ let fixture = r#"
+ fn main() {
+ let foo = "CA$0";
+ }
+ "#;
+
+ let completions = completion_list(fixture);
+ assert!(completions.is_empty(), "Completions weren't empty: {}", completions);
+ }
+
+ #[test]
+ fn doesnt_complete_in_random_macro() {
+ let fixture = r#"
+ macro_rules! bar {
+ ($($arg:tt)*) => { 0 }
+ }
+
+ fn main() {
+ let foo = bar!("CA$0");
+
+ }
+ "#;
+
+ let completions = completion_list(fixture);
+ assert!(completions.is_empty(), "Completions weren't empty: {}", completions);
+ }
+
+ #[test]
+ fn doesnt_complete_for_shadowed_macro() {
+ let fixture = r#"
+ macro_rules! env {
+ ($var:literal) => { 0 }
+ }
+
+ fn main() {
+ let foo = env!("CA$0");
+ }
+ "#;
+
+ let completions = completion_list(fixture);
+ assert!(completions.is_empty(), "Completions weren't empty: {}", completions)
+ }
+}
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs
index 588b52cc1..3192b21cf 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/expr.rs
@@ -165,7 +165,11 @@ pub(crate) fn complete_expr_path(
hir::Adt::Struct(strukt) => {
let path = ctx
.module
- .find_use_path(ctx.db, hir::ModuleDef::from(strukt))
+ .find_use_path(
+ ctx.db,
+ hir::ModuleDef::from(strukt),
+ ctx.config.prefer_no_std,
+ )
.filter(|it| it.len() > 1);
acc.add_struct_literal(ctx, path_ctx, strukt, path, None);
@@ -183,7 +187,11 @@ pub(crate) fn complete_expr_path(
hir::Adt::Union(un) => {
let path = ctx
.module
- .find_use_path(ctx.db, hir::ModuleDef::from(un))
+ .find_use_path(
+ ctx.db,
+ hir::ModuleDef::from(un),
+ ctx.config.prefer_no_std,
+ )
.filter(|it| it.len() > 1);
acc.add_union_literal(ctx, un, path, None);
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/flyimport.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/flyimport.rs
index f04cc15d7..364969af9 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/flyimport.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/flyimport.rs
@@ -262,7 +262,11 @@ fn import_on_the_fly(
acc.add_all(
import_assets
- .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind)
+ .search_for_imports(
+ &ctx.sema,
+ ctx.config.insert_use.prefix_kind,
+ ctx.config.prefer_no_std,
+ )
.into_iter()
.filter(ns_filter)
.filter(|import| {
@@ -306,7 +310,11 @@ fn import_on_the_fly_pat_(
acc.add_all(
import_assets
- .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind)
+ .search_for_imports(
+ &ctx.sema,
+ ctx.config.insert_use.prefix_kind,
+ ctx.config.prefer_no_std,
+ )
.into_iter()
.filter(ns_filter)
.filter(|import| {
@@ -344,7 +352,7 @@ fn import_on_the_fly_method(
let user_input_lowercased = potential_import_name.to_lowercase();
import_assets
- .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind)
+ .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind, ctx.config.prefer_no_std)
.into_iter()
.filter(|import| {
!ctx.is_item_hidden(&import.item_to_import)
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs
index 785db6fde..e82cbfdcb 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/item_list/trait_impl.rs
@@ -38,7 +38,7 @@ use ide_db::{
};
use syntax::{
ast::{self, edit_in_place::AttrsOwnerEdit},
- AstNode, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, T,
+ AstNode, SyntaxElement, SyntaxKind, TextRange, T,
};
use text_edit::TextEdit;
@@ -85,20 +85,36 @@ fn complete_trait_impl_name(
name: &Option<ast::Name>,
kind: ImplCompletionKind,
) -> Option<()> {
- let token = ctx.token.clone();
let item = match name {
Some(name) => name.syntax().parent(),
- None => if token.kind() == SyntaxKind::WHITESPACE { token.prev_token()? } else { token }
- .parent(),
+ None => {
+ let token = &ctx.token;
+ match token.kind() {
+ SyntaxKind::WHITESPACE => token.prev_token()?,
+ _ => token.clone(),
+ }
+ .parent()
+ }
}?;
- complete_trait_impl(
- acc,
- ctx,
- kind,
- replacement_range(ctx, &item),
- // item -> ASSOC_ITEM_LIST -> IMPL
- &ast::Impl::cast(item.parent()?.parent()?)?,
- );
+ let item = ctx.sema.original_syntax_node(&item)?;
+ // item -> ASSOC_ITEM_LIST -> IMPL
+ let impl_def = ast::Impl::cast(item.parent()?.parent()?)?;
+ let replacement_range = {
+ // ctx.sema.original_ast_node(item)?;
+ let first_child = item
+ .children_with_tokens()
+ .find(|child| {
+ !matches!(
+ child.kind(),
+ SyntaxKind::COMMENT | SyntaxKind::WHITESPACE | SyntaxKind::ATTR
+ )
+ })
+ .unwrap_or_else(|| SyntaxElement::Node(item.clone()));
+
+ TextRange::new(first_child.text_range().start(), ctx.source_range().end())
+ };
+
+ complete_trait_impl(acc, ctx, kind, replacement_range, &impl_def);
Some(())
}
@@ -341,17 +357,6 @@ fn function_declaration(node: &ast::Fn, needs_whitespace: bool) -> String {
syntax.trim_end().to_owned()
}
-fn replacement_range(ctx: &CompletionContext<'_>, item: &SyntaxNode) -> TextRange {
- let first_child = item
- .children_with_tokens()
- .find(|child| {
- !matches!(child.kind(), SyntaxKind::COMMENT | SyntaxKind::WHITESPACE | SyntaxKind::ATTR)
- })
- .unwrap_or_else(|| SyntaxElement::Node(item.clone()));
-
- TextRange::new(first_child.text_range().start(), ctx.source_range().end())
-}
-
#[cfg(test)]
mod tests {
use expect_test::{expect, Expect};
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/pattern.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/pattern.rs
index 71d2d9d43..58d5bf114 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/pattern.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/pattern.rs
@@ -145,6 +145,7 @@ pub(crate) fn complete_pattern_path(
u.ty(ctx.db)
}
hir::PathResolution::Def(hir::ModuleDef::BuiltinType(ty)) => ty.ty(ctx.db),
+ hir::PathResolution::Def(hir::ModuleDef::TypeAlias(ty)) => ty.ty(ctx.db),
_ => return,
};
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix/format_like.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix/format_like.rs
index b273a4cb5..b43bdb9ab 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix/format_like.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix/format_like.rs
@@ -16,8 +16,11 @@
//
// image::https://user-images.githubusercontent.com/48062697/113020656-b560f500-917a-11eb-87de-02991f61beb8.gif[]
-use ide_db::SnippetCap;
-use syntax::ast::{self, AstToken};
+use ide_db::{
+ syntax_helpers::format_string_exprs::{parse_format_exprs, with_placeholders},
+ SnippetCap,
+};
+use syntax::{ast, AstToken};
use crate::{
completions::postfix::build_postfix_snippet_builder, context::CompletionContext, Completions,
@@ -43,250 +46,24 @@ pub(crate) fn add_format_like_completions(
cap: SnippetCap,
receiver_text: &ast::String,
) {
- let input = match string_literal_contents(receiver_text) {
- // It's not a string literal, do not parse input.
- Some(input) => input,
- None => return,
- };
-
let postfix_snippet = match build_postfix_snippet_builder(ctx, cap, dot_receiver) {
Some(it) => it,
None => return,
};
- let mut parser = FormatStrParser::new(input);
- if parser.parse().is_ok() {
+ if let Ok((out, exprs)) = parse_format_exprs(receiver_text.text()) {
+ let exprs = with_placeholders(exprs);
for (label, macro_name) in KINDS {
- let snippet = parser.to_suggestion(macro_name);
+ let snippet = format!(r#"{}({}, {})"#, macro_name, out, exprs.join(", "));
postfix_snippet(label, macro_name, &snippet).add_to(acc);
}
}
}
-/// Checks whether provided item is a string literal.
-fn string_literal_contents(item: &ast::String) -> Option<String> {
- let item = item.text();
- if item.len() >= 2 && item.starts_with('\"') && item.ends_with('\"') {
- return Some(item[1..item.len() - 1].to_owned());
- }
-
- None
-}
-
-/// Parser for a format-like string. It is more allowing in terms of string contents,
-/// as we expect variable placeholders to be filled with expressions.
-#[derive(Debug)]
-pub(crate) struct FormatStrParser {
- input: String,
- output: String,
- extracted_expressions: Vec<String>,
- state: State,
- parsed: bool,
-}
-
-#[derive(Debug, Clone, Copy, PartialEq)]
-enum State {
- NotExpr,
- MaybeExpr,
- Expr,
- MaybeIncorrect,
- FormatOpts,
-}
-
-impl FormatStrParser {
- pub(crate) fn new(input: String) -> Self {
- Self {
- input,
- output: String::new(),
- extracted_expressions: Vec::new(),
- state: State::NotExpr,
- parsed: false,
- }
- }
-
- pub(crate) fn parse(&mut self) -> Result<(), ()> {
- let mut current_expr = String::new();
-
- let mut placeholder_id = 1;
-
- // Count of open braces inside of an expression.
- // We assume that user knows what they're doing, thus we treat it like a correct pattern, e.g.
- // "{MyStruct { val_a: 0, val_b: 1 }}".
- let mut inexpr_open_count = 0;
-
- // We need to escape '\' and '$'. See the comments on `get_receiver_text()` for detail.
- let mut chars = self.input.chars().peekable();
- while let Some(chr) = chars.next() {
- match (self.state, chr) {
- (State::NotExpr, '{') => {
- self.output.push(chr);
- self.state = State::MaybeExpr;
- }
- (State::NotExpr, '}') => {
- self.output.push(chr);
- self.state = State::MaybeIncorrect;
- }
- (State::NotExpr, _) => {
- if matches!(chr, '\\' | '$') {
- self.output.push('\\');
- }
- self.output.push(chr);
- }
- (State::MaybeIncorrect, '}') => {
- // It's okay, we met "}}".
- self.output.push(chr);
- self.state = State::NotExpr;
- }
- (State::MaybeIncorrect, _) => {
- // Error in the string.
- return Err(());
- }
- (State::MaybeExpr, '{') => {
- self.output.push(chr);
- self.state = State::NotExpr;
- }
- (State::MaybeExpr, '}') => {
- // This is an empty sequence '{}'. Replace it with placeholder.
- self.output.push(chr);
- self.extracted_expressions.push(format!("${}", placeholder_id));
- placeholder_id += 1;
- self.state = State::NotExpr;
- }
- (State::MaybeExpr, _) => {
- if matches!(chr, '\\' | '$') {
- current_expr.push('\\');
- }
- current_expr.push(chr);
- self.state = State::Expr;
- }
- (State::Expr, '}') => {
- if inexpr_open_count == 0 {
- self.output.push(chr);
- self.extracted_expressions.push(current_expr.trim().into());
- current_expr = String::new();
- self.state = State::NotExpr;
- } else {
- // We're closing one brace met before inside of the expression.
- current_expr.push(chr);
- inexpr_open_count -= 1;
- }
- }
- (State::Expr, ':') if chars.peek().copied() == Some(':') => {
- // path separator
- current_expr.push_str("::");
- chars.next();
- }
- (State::Expr, ':') => {
- if inexpr_open_count == 0 {
- // We're outside of braces, thus assume that it's a specifier, like "{Some(value):?}"
- self.output.push(chr);
- self.extracted_expressions.push(current_expr.trim().into());
- current_expr = String::new();
- self.state = State::FormatOpts;
- } else {
- // We're inside of braced expression, assume that it's a struct field name/value delimiter.
- current_expr.push(chr);
- }
- }
- (State::Expr, '{') => {
- current_expr.push(chr);
- inexpr_open_count += 1;
- }
- (State::Expr, _) => {
- if matches!(chr, '\\' | '$') {
- current_expr.push('\\');
- }
- current_expr.push(chr);
- }
- (State::FormatOpts, '}') => {
- self.output.push(chr);
- self.state = State::NotExpr;
- }
- (State::FormatOpts, _) => {
- if matches!(chr, '\\' | '$') {
- self.output.push('\\');
- }
- self.output.push(chr);
- }
- }
- }
-
- if self.state != State::NotExpr {
- return Err(());
- }
-
- self.parsed = true;
- Ok(())
- }
-
- pub(crate) fn to_suggestion(&self, macro_name: &str) -> String {
- assert!(self.parsed, "Attempt to get a suggestion from not parsed expression");
-
- let expressions_as_string = self.extracted_expressions.join(", ");
- format!(r#"{}("{}", {})"#, macro_name, self.output, expressions_as_string)
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;
- use expect_test::{expect, Expect};
-
- fn check(input: &str, expect: &Expect) {
- let mut parser = FormatStrParser::new((*input).to_owned());
- let outcome_repr = if parser.parse().is_ok() {
- // Parsing should be OK, expected repr is "string; expr_1, expr_2".
- if parser.extracted_expressions.is_empty() {
- parser.output
- } else {
- format!("{}; {}", parser.output, parser.extracted_expressions.join(", "))
- }
- } else {
- // Parsing should fail, expected repr is "-".
- "-".to_owned()
- };
-
- expect.assert_eq(&outcome_repr);
- }
-
- #[test]
- fn format_str_parser() {
- let test_vector = &[
- ("no expressions", expect![["no expressions"]]),
- (r"no expressions with \$0$1", expect![r"no expressions with \\\$0\$1"]),
- ("{expr} is {2 + 2}", expect![["{} is {}; expr, 2 + 2"]]),
- ("{expr:?}", expect![["{:?}; expr"]]),
- ("{expr:1$}", expect![[r"{:1\$}; expr"]]),
- ("{$0}", expect![[r"{}; \$0"]]),
- ("{malformed", expect![["-"]]),
- ("malformed}", expect![["-"]]),
- ("{{correct", expect![["{{correct"]]),
- ("correct}}", expect![["correct}}"]]),
- ("{correct}}}", expect![["{}}}; correct"]]),
- ("{correct}}}}}", expect![["{}}}}}; correct"]]),
- ("{incorrect}}", expect![["-"]]),
- ("placeholders {} {}", expect![["placeholders {} {}; $1, $2"]]),
- ("mixed {} {2 + 2} {}", expect![["mixed {} {} {}; $1, 2 + 2, $2"]]),
- (
- "{SomeStruct { val_a: 0, val_b: 1 }}",
- expect![["{}; SomeStruct { val_a: 0, val_b: 1 }"]],
- ),
- ("{expr:?} is {2.32f64:.5}", expect![["{:?} is {:.5}; expr, 2.32f64"]]),
- (
- "{SomeStruct { val_a: 0, val_b: 1 }:?}",
- expect![["{:?}; SomeStruct { val_a: 0, val_b: 1 }"]],
- ),
- ("{ 2 + 2 }", expect![["{}; 2 + 2"]]),
- ("{strsim::jaro_winkle(a)}", expect![["{}; strsim::jaro_winkle(a)"]]),
- ("{foo::bar::baz()}", expect![["{}; foo::bar::baz()"]]),
- ("{foo::bar():?}", expect![["{:?}; foo::bar()"]]),
- ];
-
- for (input, output) in test_vector {
- check(input, output)
- }
- }
#[test]
fn test_into_suggestion() {
@@ -302,10 +79,10 @@ mod tests {
];
for (kind, input, output) in test_vector {
- let mut parser = FormatStrParser::new((*input).to_owned());
- parser.parse().expect("Parsing must succeed");
-
- assert_eq!(&parser.to_suggestion(*kind), output);
+ let (parsed_string, exprs) = parse_format_exprs(input).unwrap();
+ let exprs = with_placeholders(exprs);
+ let snippet = format!(r#"{}("{}", {})"#, kind, parsed_string, exprs.join(", "));
+ assert_eq!(&snippet, output);
}
}
}
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/config.rs b/src/tools/rust-analyzer/crates/ide-completion/src/config.rs
index 80d6af281..a0f5e81b4 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/config.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/config.rs
@@ -17,6 +17,7 @@ pub struct CompletionConfig {
pub callable: Option<CallableSnippets>,
pub snippet_cap: Option<SnippetCap>,
pub insert_use: InsertUseConfig,
+ pub prefer_no_std: bool,
pub snippets: Vec<Snippet>,
}
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/context.rs b/src/tools/rust-analyzer/crates/ide-completion/src/context.rs
index a5e854b74..9850813a0 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/context.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/context.rs
@@ -1,4 +1,4 @@
-//! See `CompletionContext` structure.
+//! See [`CompletionContext`] structure.
mod analysis;
#[cfg(test)]
@@ -23,7 +23,10 @@ use syntax::{
};
use text_edit::Indel;
-use crate::CompletionConfig;
+use crate::{
+ context::analysis::{expand_and_analyze, AnalysisResult},
+ CompletionConfig,
+};
const COMPLETION_MARKER: &str = "intellijRulezz";
@@ -561,15 +564,27 @@ impl<'a> CompletionContext<'a> {
let edit = Indel::insert(offset, COMPLETION_MARKER.to_string());
parse.reparse(&edit).tree()
};
- let fake_ident_token =
- file_with_fake_ident.syntax().token_at_offset(offset).right_biased()?;
+ // always pick the token to the immediate left of the cursor, as that is what we are actually
+ // completing on
let original_token = original_file.syntax().token_at_offset(offset).left_biased()?;
- let token = sema.descend_into_macros_single(original_token.clone());
+
+ let AnalysisResult {
+ analysis,
+ expected: (expected_type, expected_name),
+ qualifier_ctx,
+ token,
+ offset,
+ } = expand_and_analyze(
+ &sema,
+ original_file.syntax().clone(),
+ file_with_fake_ident.syntax().clone(),
+ offset,
+ &original_token,
+ )?;
// adjust for macro input, this still fails if there is no token written yet
- let scope_offset = if original_token == token { offset } else { token.text_range().end() };
- let scope = sema.scope_at_offset(&token.parent()?, scope_offset)?;
+ let scope = sema.scope_at_offset(&token.parent()?, offset)?;
let krate = scope.krate();
let module = scope.module();
@@ -583,7 +598,7 @@ impl<'a> CompletionContext<'a> {
let depth_from_crate_root = iter::successors(module.parent(db), |m| m.parent(db)).count();
- let mut ctx = CompletionContext {
+ let ctx = CompletionContext {
sema,
scope,
db,
@@ -593,19 +608,13 @@ impl<'a> CompletionContext<'a> {
token,
krate,
module,
- expected_name: None,
- expected_type: None,
- qualifier_ctx: Default::default(),
+ expected_name,
+ expected_type,
+ qualifier_ctx,
locals,
depth_from_crate_root,
};
- let ident_ctx = ctx.expand_and_analyze(
- original_file.syntax().clone(),
- file_with_fake_ident.syntax().clone(),
- offset,
- fake_ident_token,
- )?;
- Some((ctx, ident_ctx))
+ Some((ctx, analysis))
}
}
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/context/analysis.rs b/src/tools/rust-analyzer/crates/ide-completion/src/context/analysis.rs
index 01dd9a234..04111ec7e 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/context/analysis.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/context/analysis.rs
@@ -11,1063 +11,1094 @@ use syntax::{
};
use crate::context::{
- AttrCtx, CompletionAnalysis, CompletionContext, DotAccess, DotAccessKind, ExprCtx,
- ItemListKind, LifetimeContext, LifetimeKind, NameContext, NameKind, NameRefContext,
- NameRefKind, ParamContext, ParamKind, PathCompletionCtx, PathKind, PatternContext,
- PatternRefutability, Qualified, QualifierCtx, TypeAscriptionTarget, TypeLocation,
- COMPLETION_MARKER,
+ AttrCtx, CompletionAnalysis, DotAccess, DotAccessKind, ExprCtx, ItemListKind, LifetimeContext,
+ LifetimeKind, NameContext, NameKind, NameRefContext, NameRefKind, ParamContext, ParamKind,
+ PathCompletionCtx, PathKind, PatternContext, PatternRefutability, Qualified, QualifierCtx,
+ TypeAscriptionTarget, TypeLocation, COMPLETION_MARKER,
};
-impl<'a> CompletionContext<'a> {
- /// Expand attributes and macro calls at the current cursor position for both the original file
- /// and fake file repeatedly. As soon as one of the two expansions fail we stop so the original
- /// and speculative states stay in sync.
- pub(super) fn expand_and_analyze(
- &mut self,
- mut original_file: SyntaxNode,
- mut speculative_file: SyntaxNode,
- mut offset: TextSize,
- mut fake_ident_token: SyntaxToken,
- ) -> Option<CompletionAnalysis> {
- let _p = profile::span("CompletionContext::expand_and_fill");
- let mut derive_ctx = None;
-
- 'expansion: loop {
- let parent_item =
- |item: &ast::Item| item.syntax().ancestors().skip(1).find_map(ast::Item::cast);
- let ancestor_items = iter::successors(
- Option::zip(
- find_node_at_offset::<ast::Item>(&original_file, offset),
- find_node_at_offset::<ast::Item>(&speculative_file, offset),
+struct ExpansionResult {
+ original_file: SyntaxNode,
+ speculative_file: SyntaxNode,
+ offset: TextSize,
+ fake_ident_token: SyntaxToken,
+ derive_ctx: Option<(SyntaxNode, SyntaxNode, TextSize, ast::Attr)>,
+}
+
+pub(super) struct AnalysisResult {
+ pub(super) analysis: CompletionAnalysis,
+ pub(super) expected: (Option<Type>, Option<ast::NameOrNameRef>),
+ pub(super) qualifier_ctx: QualifierCtx,
+ pub(super) token: SyntaxToken,
+ pub(super) offset: TextSize,
+}
+
+pub(super) fn expand_and_analyze(
+ sema: &Semantics<'_, RootDatabase>,
+ original_file: SyntaxNode,
+ speculative_file: SyntaxNode,
+ offset: TextSize,
+ original_token: &SyntaxToken,
+) -> Option<AnalysisResult> {
+ // as we insert after the offset, right biased will *always* pick the identifier no matter
+ // if there is an ident already typed or not
+ let fake_ident_token = speculative_file.token_at_offset(offset).right_biased()?;
+ // the relative offset between the cursor and the *identifier* token we are completing on
+ let relative_offset = offset - fake_ident_token.text_range().start();
+ // make the offset point to the start of the original token, as that is what the
+ // intermediate offsets calculated in expansion always points to
+ let offset = offset - relative_offset;
+ let expansion = expand(sema, original_file, speculative_file, offset, fake_ident_token);
+ // add the relative offset back, so that left_biased finds the proper token
+ let offset = expansion.offset + relative_offset;
+ let token = expansion.original_file.token_at_offset(offset).left_biased()?;
+
+ analyze(sema, expansion, original_token, &token).map(|(analysis, expected, qualifier_ctx)| {
+ AnalysisResult { analysis, expected, qualifier_ctx, token, offset }
+ })
+}
+
+/// Expand attributes and macro calls at the current cursor position for both the original file
+/// and fake file repeatedly. As soon as one of the two expansions fail we stop so the original
+/// and speculative states stay in sync.
+fn expand(
+ sema: &Semantics<'_, RootDatabase>,
+ mut original_file: SyntaxNode,
+ mut speculative_file: SyntaxNode,
+ mut offset: TextSize,
+ mut fake_ident_token: SyntaxToken,
+) -> ExpansionResult {
+ let _p = profile::span("CompletionContext::expand");
+ let mut derive_ctx = None;
+
+ 'expansion: loop {
+ let parent_item =
+ |item: &ast::Item| item.syntax().ancestors().skip(1).find_map(ast::Item::cast);
+ let ancestor_items = iter::successors(
+ Option::zip(
+ find_node_at_offset::<ast::Item>(&original_file, offset),
+ find_node_at_offset::<ast::Item>(&speculative_file, offset),
+ ),
+ |(a, b)| parent_item(a).zip(parent_item(b)),
+ );
+
+ // first try to expand attributes as these are always the outermost macro calls
+ 'ancestors: for (actual_item, item_with_fake_ident) in ancestor_items {
+ match (
+ sema.expand_attr_macro(&actual_item),
+ sema.speculative_expand_attr_macro(
+ &actual_item,
+ &item_with_fake_ident,
+ fake_ident_token.clone(),
),
- |(a, b)| parent_item(a).zip(parent_item(b)),
- );
-
- // first try to expand attributes as these are always the outermost macro calls
- 'ancestors: for (actual_item, item_with_fake_ident) in ancestor_items {
- match (
- self.sema.expand_attr_macro(&actual_item),
- self.sema.speculative_expand_attr_macro(
- &actual_item,
- &item_with_fake_ident,
- fake_ident_token.clone(),
- ),
- ) {
- // maybe parent items have attributes, so continue walking the ancestors
- (None, None) => continue 'ancestors,
- // successful expansions
- (Some(actual_expansion), Some((fake_expansion, fake_mapped_token))) => {
- let new_offset = fake_mapped_token.text_range().start();
- if new_offset > actual_expansion.text_range().end() {
- // offset outside of bounds from the original expansion,
- // stop here to prevent problems from happening
- break 'expansion;
- }
- original_file = actual_expansion;
- speculative_file = fake_expansion;
- fake_ident_token = fake_mapped_token;
- offset = new_offset;
- continue 'expansion;
+ ) {
+ // maybe parent items have attributes, so continue walking the ancestors
+ (None, None) => continue 'ancestors,
+ // successful expansions
+ (Some(actual_expansion), Some((fake_expansion, fake_mapped_token))) => {
+ let new_offset = fake_mapped_token.text_range().start();
+ if new_offset > actual_expansion.text_range().end() {
+ // offset outside of bounds from the original expansion,
+ // stop here to prevent problems from happening
+ break 'expansion;
}
- // exactly one expansion failed, inconsistent state so stop expanding completely
- _ => break 'expansion,
+ original_file = actual_expansion;
+ speculative_file = fake_expansion;
+ fake_ident_token = fake_mapped_token;
+ offset = new_offset;
+ continue 'expansion;
}
+ // exactly one expansion failed, inconsistent state so stop expanding completely
+ _ => break 'expansion,
}
+ }
- // No attributes have been expanded, so look for macro_call! token trees or derive token trees
- let orig_tt = match find_node_at_offset::<ast::TokenTree>(&original_file, offset) {
- Some(it) => it,
- None => break 'expansion,
- };
- let spec_tt = match find_node_at_offset::<ast::TokenTree>(&speculative_file, offset) {
- Some(it) => it,
- None => break 'expansion,
- };
+ // No attributes have been expanded, so look for macro_call! token trees or derive token trees
+ let orig_tt = match find_node_at_offset::<ast::TokenTree>(&original_file, offset) {
+ Some(it) => it,
+ None => break 'expansion,
+ };
+ let spec_tt = match find_node_at_offset::<ast::TokenTree>(&speculative_file, offset) {
+ Some(it) => it,
+ None => break 'expansion,
+ };
- // Expand pseudo-derive expansion
- if let (Some(orig_attr), Some(spec_attr)) = (
- orig_tt.syntax().parent().and_then(ast::Meta::cast).and_then(|it| it.parent_attr()),
- spec_tt.syntax().parent().and_then(ast::Meta::cast).and_then(|it| it.parent_attr()),
+ // Expand pseudo-derive expansion
+ if let (Some(orig_attr), Some(spec_attr)) = (
+ orig_tt.syntax().parent().and_then(ast::Meta::cast).and_then(|it| it.parent_attr()),
+ spec_tt.syntax().parent().and_then(ast::Meta::cast).and_then(|it| it.parent_attr()),
+ ) {
+ if let (Some(actual_expansion), Some((fake_expansion, fake_mapped_token))) = (
+ sema.expand_derive_as_pseudo_attr_macro(&orig_attr),
+ sema.speculative_expand_derive_as_pseudo_attr_macro(
+ &orig_attr,
+ &spec_attr,
+ fake_ident_token.clone(),
+ ),
) {
- if let (Some(actual_expansion), Some((fake_expansion, fake_mapped_token))) = (
- self.sema.expand_derive_as_pseudo_attr_macro(&orig_attr),
- self.sema.speculative_expand_derive_as_pseudo_attr_macro(
- &orig_attr,
- &spec_attr,
- fake_ident_token.clone(),
- ),
- ) {
- derive_ctx = Some((
- actual_expansion,
- fake_expansion,
- fake_mapped_token.text_range().start(),
- orig_attr,
- ));
- }
- // at this point we won't have any more successful expansions, so stop
+ derive_ctx = Some((
+ actual_expansion,
+ fake_expansion,
+ fake_mapped_token.text_range().start(),
+ orig_attr,
+ ));
+ }
+ // at this point we won't have any more successful expansions, so stop
+ break 'expansion;
+ }
+
+ // Expand fn-like macro calls
+ if let (Some(actual_macro_call), Some(macro_call_with_fake_ident)) = (
+ orig_tt.syntax().ancestors().find_map(ast::MacroCall::cast),
+ spec_tt.syntax().ancestors().find_map(ast::MacroCall::cast),
+ ) {
+ let mac_call_path0 = actual_macro_call.path().as_ref().map(|s| s.syntax().text());
+ let mac_call_path1 =
+ macro_call_with_fake_ident.path().as_ref().map(|s| s.syntax().text());
+
+ // inconsistent state, stop expanding
+ if mac_call_path0 != mac_call_path1 {
break 'expansion;
}
+ let speculative_args = match macro_call_with_fake_ident.token_tree() {
+ Some(tt) => tt,
+ None => break 'expansion,
+ };
- // Expand fn-like macro calls
- if let (Some(actual_macro_call), Some(macro_call_with_fake_ident)) = (
- orig_tt.syntax().ancestors().find_map(ast::MacroCall::cast),
- spec_tt.syntax().ancestors().find_map(ast::MacroCall::cast),
+ match (
+ sema.expand(&actual_macro_call),
+ sema.speculative_expand(
+ &actual_macro_call,
+ &speculative_args,
+ fake_ident_token.clone(),
+ ),
) {
- let mac_call_path0 = actual_macro_call.path().as_ref().map(|s| s.syntax().text());
- let mac_call_path1 =
- macro_call_with_fake_ident.path().as_ref().map(|s| s.syntax().text());
-
- // inconsistent state, stop expanding
- if mac_call_path0 != mac_call_path1 {
- break 'expansion;
- }
- let speculative_args = match macro_call_with_fake_ident.token_tree() {
- Some(tt) => tt,
- None => break 'expansion,
- };
-
- match (
- self.sema.expand(&actual_macro_call),
- self.sema.speculative_expand(
- &actual_macro_call,
- &speculative_args,
- fake_ident_token.clone(),
- ),
- ) {
- // successful expansions
- (Some(actual_expansion), Some((fake_expansion, fake_mapped_token))) => {
- let new_offset = fake_mapped_token.text_range().start();
- if new_offset > actual_expansion.text_range().end() {
- // offset outside of bounds from the original expansion,
- // stop here to prevent problems from happening
- break 'expansion;
- }
- original_file = actual_expansion;
- speculative_file = fake_expansion;
- fake_ident_token = fake_mapped_token;
- offset = new_offset;
- continue 'expansion;
+ // successful expansions
+ (Some(actual_expansion), Some((fake_expansion, fake_mapped_token))) => {
+ let new_offset = fake_mapped_token.text_range().start();
+ if new_offset > actual_expansion.text_range().end() {
+ // offset outside of bounds from the original expansion,
+ // stop here to prevent problems from happening
+ break 'expansion;
}
- // at least on expansion failed, we won't have anything to expand from this point
- // onwards so break out
- _ => break 'expansion,
+ original_file = actual_expansion;
+ speculative_file = fake_expansion;
+ fake_ident_token = fake_mapped_token;
+ offset = new_offset;
+ continue 'expansion;
}
+ // at least on expansion failed, we won't have anything to expand from this point
+ // onwards so break out
+ _ => break 'expansion,
}
-
- // none of our states have changed so stop the loop
- break 'expansion;
}
- self.analyze(&original_file, speculative_file, offset, derive_ctx)
+ // none of our states have changed so stop the loop
+ break 'expansion;
}
+ ExpansionResult { original_file, speculative_file, offset, fake_ident_token, derive_ctx }
+}
- /// Calculate the expected type and name of the cursor position.
- fn expected_type_and_name(
- &self,
- name_like: &ast::NameLike,
- ) -> (Option<Type>, Option<NameOrNameRef>) {
- let mut node = match self.token.parent() {
- Some(it) => it,
- None => return (None, None),
- };
+/// Fill the completion context, this is what does semantic reasoning about the surrounding context
+/// of the completion location.
+fn analyze(
+ sema: &Semantics<'_, RootDatabase>,
+ expansion_result: ExpansionResult,
+ original_token: &SyntaxToken,
+ self_token: &SyntaxToken,
+) -> Option<(CompletionAnalysis, (Option<Type>, Option<ast::NameOrNameRef>), QualifierCtx)> {
+ let _p = profile::span("CompletionContext::analyze");
+ let ExpansionResult { original_file, speculative_file, offset, fake_ident_token, derive_ctx } =
+ expansion_result;
+ let syntax_element = NodeOrToken::Token(fake_ident_token);
+ if is_in_token_of_for_loop(syntax_element.clone()) {
+ // for pat $0
+ // there is nothing to complete here except `in` keyword
+ // don't bother populating the context
+ // FIXME: the completion calculations should end up good enough
+ // such that this special case becomes unnecessary
+ return None;
+ }
- let strip_refs = |mut ty: Type| match name_like {
- ast::NameLike::NameRef(n) => {
- let p = match n.syntax().parent() {
- Some(it) => it,
- None => return ty,
- };
- let top_syn = match_ast! {
- match p {
- ast::FieldExpr(e) => e
- .syntax()
- .ancestors()
- .map_while(ast::FieldExpr::cast)
- .last()
- .map(|it| it.syntax().clone()),
- ast::PathSegment(e) => e
- .syntax()
- .ancestors()
- .skip(1)
- .take_while(|it| ast::Path::can_cast(it.kind()) || ast::PathExpr::can_cast(it.kind()))
- .find_map(ast::PathExpr::cast)
- .map(|it| it.syntax().clone()),
- _ => None
- }
+ // Overwrite the path kind for derives
+ if let Some((original_file, file_with_fake_ident, offset, origin_attr)) = derive_ctx {
+ if let Some(ast::NameLike::NameRef(name_ref)) =
+ find_node_at_offset(&file_with_fake_ident, offset)
+ {
+ let parent = name_ref.syntax().parent()?;
+ let (mut nameref_ctx, _) = classify_name_ref(&sema, &original_file, name_ref, parent)?;
+ if let NameRefKind::Path(path_ctx) = &mut nameref_ctx.kind {
+ path_ctx.kind = PathKind::Derive {
+ existing_derives: sema
+ .resolve_derive_macro(&origin_attr)
+ .into_iter()
+ .flatten()
+ .flatten()
+ .collect(),
};
- let top_syn = match top_syn {
- Some(it) => it,
- None => return ty,
- };
- for _ in top_syn.ancestors().skip(1).map_while(ast::RefExpr::cast) {
- cov_mark::hit!(expected_type_fn_param_ref);
- ty = ty.strip_reference();
- }
- ty
}
- _ => ty,
- };
+ return Some((
+ CompletionAnalysis::NameRef(nameref_ctx),
+ (None, None),
+ QualifierCtx::default(),
+ ));
+ }
+ return None;
+ }
- loop {
- break match_ast! {
- match node {
- ast::LetStmt(it) => {
- cov_mark::hit!(expected_type_let_with_leading_char);
- cov_mark::hit!(expected_type_let_without_leading_char);
- let ty = it.pat()
- .and_then(|pat| self.sema.type_of_pat(&pat))
- .or_else(|| it.initializer().and_then(|it| self.sema.type_of_expr(&it)))
- .map(TypeInfo::original);
- let name = match it.pat() {
- Some(ast::Pat::IdentPat(ident)) => ident.name().map(NameOrNameRef::Name),
- Some(_) | None => None,
- };
-
- (ty, name)
- },
- ast::LetExpr(it) => {
- cov_mark::hit!(expected_type_if_let_without_leading_char);
- let ty = it.pat()
- .and_then(|pat| self.sema.type_of_pat(&pat))
- .or_else(|| it.expr().and_then(|it| self.sema.type_of_expr(&it)))
- .map(TypeInfo::original);
- (ty, None)
- },
- ast::ArgList(_) => {
- cov_mark::hit!(expected_type_fn_param);
- ActiveParameter::at_token(
- &self.sema,
- self.token.clone(),
- ).map(|ap| {
- let name = ap.ident().map(NameOrNameRef::Name);
-
- let ty = strip_refs(ap.ty);
- (Some(ty), name)
- })
- .unwrap_or((None, None))
- },
- ast::RecordExprFieldList(it) => {
- // wouldn't try {} be nice...
- (|| {
- if self.token.kind() == T![..]
- || self.token.prev_token().map(|t| t.kind()) == Some(T![..])
- {
- cov_mark::hit!(expected_type_struct_func_update);
- let record_expr = it.syntax().parent().and_then(ast::RecordExpr::cast)?;
- let ty = self.sema.type_of_expr(&record_expr.into())?;
- Some((
- Some(ty.original),
- None
- ))
- } else {
- cov_mark::hit!(expected_type_struct_field_without_leading_char);
- let expr_field = self.token.prev_sibling_or_token()?
- .into_node()
- .and_then(ast::RecordExprField::cast)?;
- let (_, _, ty) = self.sema.resolve_record_field(&expr_field)?;
- Some((
- Some(ty),
- expr_field.field_name().map(NameOrNameRef::NameRef),
- ))
- }
- })().unwrap_or((None, None))
- },
- ast::RecordExprField(it) => {
- if let Some(expr) = it.expr() {
- cov_mark::hit!(expected_type_struct_field_with_leading_char);
- (
- self.sema.type_of_expr(&expr).map(TypeInfo::original),
- it.field_name().map(NameOrNameRef::NameRef),
- )
- } else {
- cov_mark::hit!(expected_type_struct_field_followed_by_comma);
- let ty = self.sema.resolve_record_field(&it)
- .map(|(_, _, ty)| ty);
- (
- ty,
- it.field_name().map(NameOrNameRef::NameRef),
- )
- }
- },
- // match foo { $0 }
- // match foo { ..., pat => $0 }
- ast::MatchExpr(it) => {
- let on_arrow = previous_non_trivia_token(self.token.clone()).map_or(false, |it| T![=>] == it.kind());
-
- let ty = if on_arrow {
- // match foo { ..., pat => $0 }
- cov_mark::hit!(expected_type_match_arm_body_without_leading_char);
- cov_mark::hit!(expected_type_match_arm_body_with_leading_char);
- self.sema.type_of_expr(&it.into())
- } else {
- // match foo { $0 }
- cov_mark::hit!(expected_type_match_arm_without_leading_char);
- it.expr().and_then(|e| self.sema.type_of_expr(&e))
- }.map(TypeInfo::original);
- (ty, None)
- },
- ast::IfExpr(it) => {
- let ty = it.condition()
- .and_then(|e| self.sema.type_of_expr(&e))
- .map(TypeInfo::original);
- (ty, None)
- },
- ast::IdentPat(it) => {
- cov_mark::hit!(expected_type_if_let_with_leading_char);
- cov_mark::hit!(expected_type_match_arm_with_leading_char);
- let ty = self.sema.type_of_pat(&ast::Pat::from(it)).map(TypeInfo::original);
- (ty, None)
- },
- ast::Fn(it) => {
- cov_mark::hit!(expected_type_fn_ret_with_leading_char);
- cov_mark::hit!(expected_type_fn_ret_without_leading_char);
- let def = self.sema.to_def(&it);
- (def.map(|def| def.ret_type(self.db)), None)
- },
- ast::ClosureExpr(it) => {
- let ty = self.sema.type_of_expr(&it.into());
- ty.and_then(|ty| ty.original.as_callable(self.db))
- .map(|c| (Some(c.return_type()), None))
- .unwrap_or((None, None))
- },
- ast::ParamList(_) => (None, None),
- ast::Stmt(_) => (None, None),
- ast::Item(_) => (None, None),
- _ => {
- match node.parent() {
- Some(n) => {
- node = n;
- continue;
- },
- None => (None, None),
- }
- },
+ let name_like = match find_node_at_offset(&speculative_file, offset) {
+ Some(it) => it,
+ None => {
+ let analysis = if let Some(original) = ast::String::cast(original_token.clone()) {
+ CompletionAnalysis::String {
+ original,
+ expanded: ast::String::cast(self_token.clone()),
+ }
+ } else {
+ // Fix up trailing whitespace problem
+ // #[attr(foo = $0
+ let token = syntax::algo::skip_trivia_token(self_token.clone(), Direction::Prev)?;
+ let p = token.parent()?;
+ if p.kind() == SyntaxKind::TOKEN_TREE
+ && p.ancestors().any(|it| it.kind() == SyntaxKind::META)
+ {
+ let colon_prefix = previous_non_trivia_token(self_token.clone())
+ .map_or(false, |it| T![:] == it.kind());
+ CompletionAnalysis::UnexpandedAttrTT {
+ fake_attribute_under_caret: syntax_element
+ .ancestors()
+ .find_map(ast::Attr::cast),
+ colon_prefix,
+ }
+ } else {
+ return None;
}
};
+ return Some((analysis, (None, None), QualifierCtx::default()));
}
- }
-
- /// Fill the completion context, this is what does semantic reasoning about the surrounding context
- /// of the completion location.
- fn analyze(
- &mut self,
- original_file: &SyntaxNode,
- file_with_fake_ident: SyntaxNode,
- offset: TextSize,
- derive_ctx: Option<(SyntaxNode, SyntaxNode, TextSize, ast::Attr)>,
- ) -> Option<CompletionAnalysis> {
- let fake_ident_token = file_with_fake_ident.token_at_offset(offset).right_biased()?;
- let syntax_element = NodeOrToken::Token(fake_ident_token);
- if is_in_token_of_for_loop(syntax_element.clone()) {
- // for pat $0
- // there is nothing to complete here except `in` keyword
- // don't bother populating the context
- // FIXME: the completion calculations should end up good enough
- // such that this special case becomes unnecessary
- return None;
+ };
+ let expected = expected_type_and_name(sema, &self_token, &name_like);
+ let mut qual_ctx = QualifierCtx::default();
+ let analysis = match name_like {
+ ast::NameLike::Lifetime(lifetime) => {
+ CompletionAnalysis::Lifetime(classify_lifetime(sema, &original_file, lifetime)?)
+ }
+ ast::NameLike::NameRef(name_ref) => {
+ let parent = name_ref.syntax().parent()?;
+ let (nameref_ctx, qualifier_ctx) =
+ classify_name_ref(sema, &original_file, name_ref, parent.clone())?;
+ qual_ctx = qualifier_ctx;
+ CompletionAnalysis::NameRef(nameref_ctx)
+ }
+ ast::NameLike::Name(name) => {
+ let name_ctx = classify_name(sema, &original_file, name)?;
+ CompletionAnalysis::Name(name_ctx)
}
+ };
+ Some((analysis, expected, qual_ctx))
+}
- // Overwrite the path kind for derives
- if let Some((original_file, file_with_fake_ident, offset, origin_attr)) = derive_ctx {
- if let Some(ast::NameLike::NameRef(name_ref)) =
- find_node_at_offset(&file_with_fake_ident, offset)
- {
- let parent = name_ref.syntax().parent()?;
- let (mut nameref_ctx, _) =
- Self::classify_name_ref(&self.sema, &original_file, name_ref, parent)?;
- if let NameRefKind::Path(path_ctx) = &mut nameref_ctx.kind {
- path_ctx.kind = PathKind::Derive {
- existing_derives: self
- .sema
- .resolve_derive_macro(&origin_attr)
- .into_iter()
- .flatten()
- .flatten()
- .collect(),
- };
+/// Calculate the expected type and name of the cursor position.
+fn expected_type_and_name(
+ sema: &Semantics<'_, RootDatabase>,
+ token: &SyntaxToken,
+ name_like: &ast::NameLike,
+) -> (Option<Type>, Option<NameOrNameRef>) {
+ let mut node = match token.parent() {
+ Some(it) => it,
+ None => return (None, None),
+ };
+
+ let strip_refs = |mut ty: Type| match name_like {
+ ast::NameLike::NameRef(n) => {
+ let p = match n.syntax().parent() {
+ Some(it) => it,
+ None => return ty,
+ };
+ let top_syn = match_ast! {
+ match p {
+ ast::FieldExpr(e) => e
+ .syntax()
+ .ancestors()
+ .map_while(ast::FieldExpr::cast)
+ .last()
+ .map(|it| it.syntax().clone()),
+ ast::PathSegment(e) => e
+ .syntax()
+ .ancestors()
+ .skip(1)
+ .take_while(|it| ast::Path::can_cast(it.kind()) || ast::PathExpr::can_cast(it.kind()))
+ .find_map(ast::PathExpr::cast)
+ .map(|it| it.syntax().clone()),
+ _ => None
}
- return Some(CompletionAnalysis::NameRef(nameref_ctx));
+ };
+ let top_syn = match top_syn {
+ Some(it) => it,
+ None => return ty,
+ };
+ for _ in top_syn.ancestors().skip(1).map_while(ast::RefExpr::cast) {
+ cov_mark::hit!(expected_type_fn_param_ref);
+ ty = ty.strip_reference();
}
- return None;
+ ty
}
+ _ => ty,
+ };
- let name_like = match find_node_at_offset(&file_with_fake_ident, offset) {
- Some(it) => it,
- None => {
- let analysis =
- if let Some(original) = ast::String::cast(self.original_token.clone()) {
- CompletionAnalysis::String {
- original,
- expanded: ast::String::cast(self.token.clone()),
- }
- } else {
- // Fix up trailing whitespace problem
- // #[attr(foo = $0
- let token =
- syntax::algo::skip_trivia_token(self.token.clone(), Direction::Prev)?;
- let p = token.parent()?;
- if p.kind() == SyntaxKind::TOKEN_TREE
- && p.ancestors().any(|it| it.kind() == SyntaxKind::META)
+ loop {
+ break match_ast! {
+ match node {
+ ast::LetStmt(it) => {
+ cov_mark::hit!(expected_type_let_with_leading_char);
+ cov_mark::hit!(expected_type_let_without_leading_char);
+ let ty = it.pat()
+ .and_then(|pat| sema.type_of_pat(&pat))
+ .or_else(|| it.initializer().and_then(|it| sema.type_of_expr(&it)))
+ .map(TypeInfo::original);
+ let name = match it.pat() {
+ Some(ast::Pat::IdentPat(ident)) => ident.name().map(NameOrNameRef::Name),
+ Some(_) | None => None,
+ };
+
+ (ty, name)
+ },
+ ast::LetExpr(it) => {
+ cov_mark::hit!(expected_type_if_let_without_leading_char);
+ let ty = it.pat()
+ .and_then(|pat| sema.type_of_pat(&pat))
+ .or_else(|| it.expr().and_then(|it| sema.type_of_expr(&it)))
+ .map(TypeInfo::original);
+ (ty, None)
+ },
+ ast::ArgList(_) => {
+ cov_mark::hit!(expected_type_fn_param);
+ ActiveParameter::at_token(
+ &sema,
+ token.clone(),
+ ).map(|ap| {
+ let name = ap.ident().map(NameOrNameRef::Name);
+
+ let ty = strip_refs(ap.ty);
+ (Some(ty), name)
+ })
+ .unwrap_or((None, None))
+ },
+ ast::RecordExprFieldList(it) => {
+ // wouldn't try {} be nice...
+ (|| {
+ if token.kind() == T![..]
+ ||token.prev_token().map(|t| t.kind()) == Some(T![..])
{
- let colon_prefix = previous_non_trivia_token(self.token.clone())
- .map_or(false, |it| T![:] == it.kind());
- CompletionAnalysis::UnexpandedAttrTT {
- fake_attribute_under_caret: syntax_element
- .ancestors()
- .find_map(ast::Attr::cast),
- colon_prefix,
- }
+ cov_mark::hit!(expected_type_struct_func_update);
+ let record_expr = it.syntax().parent().and_then(ast::RecordExpr::cast)?;
+ let ty = sema.type_of_expr(&record_expr.into())?;
+ Some((
+ Some(ty.original),
+ None
+ ))
} else {
- return None;
+ cov_mark::hit!(expected_type_struct_field_without_leading_char);
+ let expr_field = token.prev_sibling_or_token()?
+ .into_node()
+ .and_then(ast::RecordExprField::cast)?;
+ let (_, _, ty) = sema.resolve_record_field(&expr_field)?;
+ Some((
+ Some(ty),
+ expr_field.field_name().map(NameOrNameRef::NameRef),
+ ))
}
- };
- return Some(analysis);
+ })().unwrap_or((None, None))
+ },
+ ast::RecordExprField(it) => {
+ if let Some(expr) = it.expr() {
+ cov_mark::hit!(expected_type_struct_field_with_leading_char);
+ (
+ sema.type_of_expr(&expr).map(TypeInfo::original),
+ it.field_name().map(NameOrNameRef::NameRef),
+ )
+ } else {
+ cov_mark::hit!(expected_type_struct_field_followed_by_comma);
+ let ty = sema.resolve_record_field(&it)
+ .map(|(_, _, ty)| ty);
+ (
+ ty,
+ it.field_name().map(NameOrNameRef::NameRef),
+ )
+ }
+ },
+ // match foo { $0 }
+ // match foo { ..., pat => $0 }
+ ast::MatchExpr(it) => {
+ let on_arrow = previous_non_trivia_token(token.clone()).map_or(false, |it| T![=>] == it.kind());
+
+ let ty = if on_arrow {
+ // match foo { ..., pat => $0 }
+ cov_mark::hit!(expected_type_match_arm_body_without_leading_char);
+ cov_mark::hit!(expected_type_match_arm_body_with_leading_char);
+ sema.type_of_expr(&it.into())
+ } else {
+ // match foo { $0 }
+ cov_mark::hit!(expected_type_match_arm_without_leading_char);
+ it.expr().and_then(|e| sema.type_of_expr(&e))
+ }.map(TypeInfo::original);
+ (ty, None)
+ },
+ ast::IfExpr(it) => {
+ let ty = it.condition()
+ .and_then(|e| sema.type_of_expr(&e))
+ .map(TypeInfo::original);
+ (ty, None)
+ },
+ ast::IdentPat(it) => {
+ cov_mark::hit!(expected_type_if_let_with_leading_char);
+ cov_mark::hit!(expected_type_match_arm_with_leading_char);
+ let ty = sema.type_of_pat(&ast::Pat::from(it)).map(TypeInfo::original);
+ (ty, None)
+ },
+ ast::Fn(it) => {
+ cov_mark::hit!(expected_type_fn_ret_with_leading_char);
+ cov_mark::hit!(expected_type_fn_ret_without_leading_char);
+ let def = sema.to_def(&it);
+ (def.map(|def| def.ret_type(sema.db)), None)
+ },
+ ast::ClosureExpr(it) => {
+ let ty = sema.type_of_expr(&it.into());
+ ty.and_then(|ty| ty.original.as_callable(sema.db))
+ .map(|c| (Some(c.return_type()), None))
+ .unwrap_or((None, None))
+ },
+ ast::ParamList(_) => (None, None),
+ ast::Stmt(_) => (None, None),
+ ast::Item(_) => (None, None),
+ _ => {
+ match node.parent() {
+ Some(n) => {
+ node = n;
+ continue;
+ },
+ None => (None, None),
+ }
+ },
}
};
- (self.expected_type, self.expected_name) = self.expected_type_and_name(&name_like);
- let analysis = match name_like {
- ast::NameLike::Lifetime(lifetime) => CompletionAnalysis::Lifetime(
- Self::classify_lifetime(&self.sema, original_file, lifetime)?,
- ),
- ast::NameLike::NameRef(name_ref) => {
- let parent = name_ref.syntax().parent()?;
- let (nameref_ctx, qualifier_ctx) =
- Self::classify_name_ref(&self.sema, &original_file, name_ref, parent.clone())?;
+ }
+}
- self.qualifier_ctx = qualifier_ctx;
- CompletionAnalysis::NameRef(nameref_ctx)
- }
- ast::NameLike::Name(name) => {
- let name_ctx = Self::classify_name(&self.sema, original_file, name)?;
- CompletionAnalysis::Name(name_ctx)
- }
- };
- Some(analysis)
+fn classify_lifetime(
+ _sema: &Semantics<'_, RootDatabase>,
+ original_file: &SyntaxNode,
+ lifetime: ast::Lifetime,
+) -> Option<LifetimeContext> {
+ let parent = lifetime.syntax().parent()?;
+ if parent.kind() == SyntaxKind::ERROR {
+ return None;
}
- fn classify_lifetime(
- _sema: &Semantics<'_, RootDatabase>,
- original_file: &SyntaxNode,
- lifetime: ast::Lifetime,
- ) -> Option<LifetimeContext> {
- let parent = lifetime.syntax().parent()?;
- if parent.kind() == SyntaxKind::ERROR {
- return None;
+ let kind = match_ast! {
+ match parent {
+ ast::LifetimeParam(param) => LifetimeKind::LifetimeParam {
+ is_decl: param.lifetime().as_ref() == Some(&lifetime),
+ param
+ },
+ ast::BreakExpr(_) => LifetimeKind::LabelRef,
+ ast::ContinueExpr(_) => LifetimeKind::LabelRef,
+ ast::Label(_) => LifetimeKind::LabelDef,
+ _ => LifetimeKind::Lifetime,
}
+ };
+ let lifetime = find_node_at_offset(&original_file, lifetime.syntax().text_range().start());
- let kind = match_ast! {
- match parent {
- ast::LifetimeParam(param) => LifetimeKind::LifetimeParam {
- is_decl: param.lifetime().as_ref() == Some(&lifetime),
- param
- },
- ast::BreakExpr(_) => LifetimeKind::LabelRef,
- ast::ContinueExpr(_) => LifetimeKind::LabelRef,
- ast::Label(_) => LifetimeKind::LabelDef,
- _ => LifetimeKind::Lifetime,
- }
- };
- let lifetime = find_node_at_offset(&original_file, lifetime.syntax().text_range().start());
+ Some(LifetimeContext { lifetime, kind })
+}
- Some(LifetimeContext { lifetime, kind })
- }
+fn classify_name(
+ sema: &Semantics<'_, RootDatabase>,
+ original_file: &SyntaxNode,
+ name: ast::Name,
+) -> Option<NameContext> {
+ let parent = name.syntax().parent()?;
+ let kind = match_ast! {
+ match parent {
+ ast::Const(_) => NameKind::Const,
+ ast::ConstParam(_) => NameKind::ConstParam,
+ ast::Enum(_) => NameKind::Enum,
+ ast::Fn(_) => NameKind::Function,
+ ast::IdentPat(bind_pat) => {
+ let mut pat_ctx = pattern_context_for(sema, original_file, bind_pat.into());
+ if let Some(record_field) = ast::RecordPatField::for_field_name(&name) {
+ pat_ctx.record_pat = find_node_in_file_compensated(sema, original_file, &record_field.parent_record_pat());
+ }
- fn classify_name(
- sema: &Semantics<'_, RootDatabase>,
- original_file: &SyntaxNode,
- name: ast::Name,
- ) -> Option<NameContext> {
- let parent = name.syntax().parent()?;
- let kind = match_ast! {
- match parent {
- ast::Const(_) => NameKind::Const,
- ast::ConstParam(_) => NameKind::ConstParam,
- ast::Enum(_) => NameKind::Enum,
- ast::Fn(_) => NameKind::Function,
- ast::IdentPat(bind_pat) => {
- let mut pat_ctx = pattern_context_for(sema, original_file, bind_pat.into());
- if let Some(record_field) = ast::RecordPatField::for_field_name(&name) {
- pat_ctx.record_pat = find_node_in_file_compensated(sema, original_file, &record_field.parent_record_pat());
- }
+ NameKind::IdentPat(pat_ctx)
+ },
+ ast::MacroDef(_) => NameKind::MacroDef,
+ ast::MacroRules(_) => NameKind::MacroRules,
+ ast::Module(module) => NameKind::Module(module),
+ ast::RecordField(_) => NameKind::RecordField,
+ ast::Rename(_) => NameKind::Rename,
+ ast::SelfParam(_) => NameKind::SelfParam,
+ ast::Static(_) => NameKind::Static,
+ ast::Struct(_) => NameKind::Struct,
+ ast::Trait(_) => NameKind::Trait,
+ ast::TypeAlias(_) => NameKind::TypeAlias,
+ ast::TypeParam(_) => NameKind::TypeParam,
+ ast::Union(_) => NameKind::Union,
+ ast::Variant(_) => NameKind::Variant,
+ _ => return None,
+ }
+ };
+ let name = find_node_at_offset(&original_file, name.syntax().text_range().start());
+ Some(NameContext { name, kind })
+}
- NameKind::IdentPat(pat_ctx)
- },
- ast::MacroDef(_) => NameKind::MacroDef,
- ast::MacroRules(_) => NameKind::MacroRules,
- ast::Module(module) => NameKind::Module(module),
- ast::RecordField(_) => NameKind::RecordField,
- ast::Rename(_) => NameKind::Rename,
- ast::SelfParam(_) => NameKind::SelfParam,
- ast::Static(_) => NameKind::Static,
- ast::Struct(_) => NameKind::Struct,
- ast::Trait(_) => NameKind::Trait,
- ast::TypeAlias(_) => NameKind::TypeAlias,
- ast::TypeParam(_) => NameKind::TypeParam,
- ast::Union(_) => NameKind::Union,
- ast::Variant(_) => NameKind::Variant,
- _ => return None,
- }
- };
- let name = find_node_at_offset(&original_file, name.syntax().text_range().start());
- Some(NameContext { name, kind })
+fn classify_name_ref(
+ sema: &Semantics<'_, RootDatabase>,
+ original_file: &SyntaxNode,
+ name_ref: ast::NameRef,
+ parent: SyntaxNode,
+) -> Option<(NameRefContext, QualifierCtx)> {
+ let nameref = find_node_at_offset(&original_file, name_ref.syntax().text_range().start());
+
+ let make_res = |kind| (NameRefContext { nameref: nameref.clone(), kind }, Default::default());
+
+ if let Some(record_field) = ast::RecordExprField::for_field_name(&name_ref) {
+ let dot_prefix = previous_non_trivia_token(name_ref.syntax().clone())
+ .map_or(false, |it| T![.] == it.kind());
+
+ return find_node_in_file_compensated(
+ sema,
+ original_file,
+ &record_field.parent_record_lit(),
+ )
+ .map(|expr| NameRefKind::RecordExpr { expr, dot_prefix })
+ .map(make_res);
}
-
- fn classify_name_ref(
- sema: &Semantics<'_, RootDatabase>,
- original_file: &SyntaxNode,
- name_ref: ast::NameRef,
- parent: SyntaxNode,
- ) -> Option<(NameRefContext, QualifierCtx)> {
- let nameref = find_node_at_offset(&original_file, name_ref.syntax().text_range().start());
-
- let make_res =
- |kind| (NameRefContext { nameref: nameref.clone(), kind }, Default::default());
-
- if let Some(record_field) = ast::RecordExprField::for_field_name(&name_ref) {
- let dot_prefix = previous_non_trivia_token(name_ref.syntax().clone())
- .map_or(false, |it| T![.] == it.kind());
-
- return find_node_in_file_compensated(
+ if let Some(record_field) = ast::RecordPatField::for_field_name_ref(&name_ref) {
+ let kind = NameRefKind::Pattern(PatternContext {
+ param_ctx: None,
+ has_type_ascription: false,
+ ref_token: None,
+ mut_token: None,
+ record_pat: find_node_in_file_compensated(
sema,
original_file,
- &record_field.parent_record_lit(),
+ &record_field.parent_record_pat(),
+ ),
+ ..pattern_context_for(
+ sema,
+ original_file,
+ record_field.parent_record_pat().clone().into(),
)
- .map(|expr| NameRefKind::RecordExpr { expr, dot_prefix })
- .map(make_res);
+ });
+ return Some(make_res(kind));
+ }
+
+ let segment = match_ast! {
+ match parent {
+ ast::PathSegment(segment) => segment,
+ ast::FieldExpr(field) => {
+ let receiver = find_opt_node_in_file(original_file, field.expr());
+ let receiver_is_ambiguous_float_literal = match &receiver {
+ Some(ast::Expr::Literal(l)) => matches! {
+ l.kind(),
+ ast::LiteralKind::FloatNumber { .. } if l.syntax().last_token().map_or(false, |it| it.text().ends_with('.'))
+ },
+ _ => false,
+ };
+ let kind = NameRefKind::DotAccess(DotAccess {
+ receiver_ty: receiver.as_ref().and_then(|it| sema.type_of_expr(it)),
+ kind: DotAccessKind::Field { receiver_is_ambiguous_float_literal },
+ receiver
+ });
+ return Some(make_res(kind));
+ },
+ ast::MethodCallExpr(method) => {
+ let receiver = find_opt_node_in_file(original_file, method.receiver());
+ let kind = NameRefKind::DotAccess(DotAccess {
+ receiver_ty: receiver.as_ref().and_then(|it| sema.type_of_expr(it)),
+ kind: DotAccessKind::Method { has_parens: method.arg_list().map_or(false, |it| it.l_paren_token().is_some()) },
+ receiver
+ });
+ return Some(make_res(kind));
+ },
+ _ => return None,
}
- if let Some(record_field) = ast::RecordPatField::for_field_name_ref(&name_ref) {
- let kind = NameRefKind::Pattern(PatternContext {
- param_ctx: None,
- has_type_ascription: false,
- ref_token: None,
- mut_token: None,
- record_pat: find_node_in_file_compensated(
- sema,
- original_file,
- &record_field.parent_record_pat(),
- ),
- ..pattern_context_for(
- sema,
- original_file,
- record_field.parent_record_pat().clone().into(),
- )
- });
- return Some(make_res(kind));
+ };
+
+ let path = segment.parent_path();
+ let original_path = find_node_in_file_compensated(sema, original_file, &path);
+
+ let mut path_ctx = PathCompletionCtx {
+ has_call_parens: false,
+ has_macro_bang: false,
+ qualified: Qualified::No,
+ parent: None,
+ path: path.clone(),
+ original_path,
+ kind: PathKind::Item { kind: ItemListKind::SourceFile },
+ has_type_args: false,
+ use_tree_parent: false,
+ };
+
+ let is_in_block = |it: &SyntaxNode| {
+ it.parent()
+ .map(|node| {
+ ast::ExprStmt::can_cast(node.kind()) || ast::StmtList::can_cast(node.kind())
+ })
+ .unwrap_or(false)
+ };
+ let func_update_record = |syn: &SyntaxNode| {
+ if let Some(record_expr) = syn.ancestors().nth(2).and_then(ast::RecordExpr::cast) {
+ find_node_in_file_compensated(sema, original_file, &record_expr)
+ } else {
+ None
+ }
+ };
+ let after_if_expr = |node: SyntaxNode| {
+ let prev_expr = (|| {
+ let prev_sibling = non_trivia_sibling(node.into(), Direction::Prev)?.into_node()?;
+ ast::ExprStmt::cast(prev_sibling)?.expr()
+ })();
+ matches!(prev_expr, Some(ast::Expr::IfExpr(_)))
+ };
+
+ // We do not want to generate path completions when we are sandwiched between an item decl signature and its body.
+ // ex. trait Foo $0 {}
+ // in these cases parser recovery usually kicks in for our inserted identifier, causing it
+ // to either be parsed as an ExprStmt or a MacroCall, depending on whether it is in a block
+ // expression or an item list.
+ // The following code checks if the body is missing, if it is we either cut off the body
+ // from the item or it was missing in the first place
+ let inbetween_body_and_decl_check = |node: SyntaxNode| {
+ if let Some(NodeOrToken::Node(n)) =
+ syntax::algo::non_trivia_sibling(node.into(), syntax::Direction::Prev)
+ {
+ if let Some(item) = ast::Item::cast(n) {
+ let is_inbetween = match &item {
+ ast::Item::Const(it) => it.body().is_none(),
+ ast::Item::Enum(it) => it.variant_list().is_none(),
+ ast::Item::ExternBlock(it) => it.extern_item_list().is_none(),
+ ast::Item::Fn(it) => it.body().is_none(),
+ ast::Item::Impl(it) => it.assoc_item_list().is_none(),
+ ast::Item::Module(it) => it.item_list().is_none(),
+ ast::Item::Static(it) => it.body().is_none(),
+ ast::Item::Struct(it) => it.field_list().is_none(),
+ ast::Item::Trait(it) => it.assoc_item_list().is_none(),
+ ast::Item::TypeAlias(it) => it.ty().is_none(),
+ ast::Item::Union(it) => it.record_field_list().is_none(),
+ _ => false,
+ };
+ if is_inbetween {
+ return Some(item);
+ }
+ }
}
+ None
+ };
- let segment = match_ast! {
+ let type_location = |node: &SyntaxNode| {
+ let parent = node.parent()?;
+ let res = match_ast! {
match parent {
- ast::PathSegment(segment) => segment,
- ast::FieldExpr(field) => {
- let receiver = find_opt_node_in_file(original_file, field.expr());
- let receiver_is_ambiguous_float_literal = match &receiver {
- Some(ast::Expr::Literal(l)) => matches! {
- l.kind(),
- ast::LiteralKind::FloatNumber { .. } if l.syntax().last_token().map_or(false, |it| it.text().ends_with('.'))
- },
- _ => false,
+ ast::Const(it) => {
+ let name = find_opt_node_in_file(original_file, it.name())?;
+ let original = ast::Const::cast(name.syntax().parent()?)?;
+ TypeLocation::TypeAscription(TypeAscriptionTarget::Const(original.body()))
+ },
+ ast::RetType(it) => {
+ if it.thin_arrow_token().is_none() {
+ return None;
+ }
+ let parent = match ast::Fn::cast(parent.parent()?) {
+ Some(x) => x.param_list(),
+ None => ast::ClosureExpr::cast(parent.parent()?)?.param_list(),
};
- let kind = NameRefKind::DotAccess(DotAccess {
- receiver_ty: receiver.as_ref().and_then(|it| sema.type_of_expr(it)),
- kind: DotAccessKind::Field { receiver_is_ambiguous_float_literal },
- receiver
- });
- return Some(make_res(kind));
+
+ let parent = find_opt_node_in_file(original_file, parent)?.syntax().parent()?;
+ TypeLocation::TypeAscription(TypeAscriptionTarget::RetType(match_ast! {
+ match parent {
+ ast::ClosureExpr(it) => {
+ it.body()
+ },
+ ast::Fn(it) => {
+ it.body().map(ast::Expr::BlockExpr)
+ },
+ _ => return None,
+ }
+ }))
},
- ast::MethodCallExpr(method) => {
- let receiver = find_opt_node_in_file(original_file, method.receiver());
- let kind = NameRefKind::DotAccess(DotAccess {
- receiver_ty: receiver.as_ref().and_then(|it| sema.type_of_expr(it)),
- kind: DotAccessKind::Method { has_parens: method.arg_list().map_or(false, |it| it.l_paren_token().is_some()) },
- receiver
- });
- return Some(make_res(kind));
+ ast::Param(it) => {
+ if it.colon_token().is_none() {
+ return None;
+ }
+ TypeLocation::TypeAscription(TypeAscriptionTarget::FnParam(find_opt_node_in_file(original_file, it.pat())))
},
+ ast::LetStmt(it) => {
+ if it.colon_token().is_none() {
+ return None;
+ }
+ TypeLocation::TypeAscription(TypeAscriptionTarget::Let(find_opt_node_in_file(original_file, it.pat())))
+ },
+ ast::Impl(it) => {
+ match it.trait_() {
+ Some(t) if t.syntax() == node => TypeLocation::ImplTrait,
+ _ => match it.self_ty() {
+ Some(t) if t.syntax() == node => TypeLocation::ImplTarget,
+ _ => return None,
+ },
+ }
+ },
+ ast::TypeBound(_) => TypeLocation::TypeBound,
+ // is this case needed?
+ ast::TypeBoundList(_) => TypeLocation::TypeBound,
+ ast::GenericArg(it) => TypeLocation::GenericArgList(find_opt_node_in_file_compensated(sema, original_file, it.syntax().parent().and_then(ast::GenericArgList::cast))),
+ // is this case needed?
+ ast::GenericArgList(it) => TypeLocation::GenericArgList(find_opt_node_in_file_compensated(sema, original_file, Some(it))),
+ ast::TupleField(_) => TypeLocation::TupleField,
_ => return None,
}
};
+ Some(res)
+ };
- let path = segment.parent_path();
- let original_path = find_node_in_file_compensated(sema, original_file, &path);
-
- let mut path_ctx = PathCompletionCtx {
- has_call_parens: false,
- has_macro_bang: false,
- qualified: Qualified::No,
- parent: None,
- path: path.clone(),
- original_path,
- kind: PathKind::Item { kind: ItemListKind::SourceFile },
- has_type_args: false,
- use_tree_parent: false,
- };
-
- let is_in_block = |it: &SyntaxNode| {
- it.parent()
- .map(|node| {
- ast::ExprStmt::can_cast(node.kind()) || ast::StmtList::can_cast(node.kind())
- })
- .unwrap_or(false)
- };
- let func_update_record = |syn: &SyntaxNode| {
- if let Some(record_expr) = syn.ancestors().nth(2).and_then(ast::RecordExpr::cast) {
- find_node_in_file_compensated(sema, original_file, &record_expr)
+ let is_in_condition = |it: &ast::Expr| {
+ (|| {
+ let parent = it.syntax().parent()?;
+ if let Some(expr) = ast::WhileExpr::cast(parent.clone()) {
+ Some(expr.condition()? == *it)
+ } else if let Some(expr) = ast::IfExpr::cast(parent) {
+ Some(expr.condition()? == *it)
} else {
None
}
- };
- let after_if_expr = |node: SyntaxNode| {
- let prev_expr = (|| {
- let prev_sibling = non_trivia_sibling(node.into(), Direction::Prev)?.into_node()?;
- ast::ExprStmt::cast(prev_sibling)?.expr()
- })();
- matches!(prev_expr, Some(ast::Expr::IfExpr(_)))
- };
+ })()
+ .unwrap_or(false)
+ };
- // We do not want to generate path completions when we are sandwiched between an item decl signature and its body.
- // ex. trait Foo $0 {}
- // in these cases parser recovery usually kicks in for our inserted identifier, causing it
- // to either be parsed as an ExprStmt or a MacroCall, depending on whether it is in a block
- // expression or an item list.
- // The following code checks if the body is missing, if it is we either cut off the body
- // from the item or it was missing in the first place
- let inbetween_body_and_decl_check = |node: SyntaxNode| {
- if let Some(NodeOrToken::Node(n)) =
- syntax::algo::non_trivia_sibling(node.into(), syntax::Direction::Prev)
- {
- if let Some(item) = ast::Item::cast(n) {
- let is_inbetween = match &item {
- ast::Item::Const(it) => it.body().is_none(),
- ast::Item::Enum(it) => it.variant_list().is_none(),
- ast::Item::ExternBlock(it) => it.extern_item_list().is_none(),
- ast::Item::Fn(it) => it.body().is_none(),
- ast::Item::Impl(it) => it.assoc_item_list().is_none(),
- ast::Item::Module(it) => it.item_list().is_none(),
- ast::Item::Static(it) => it.body().is_none(),
- ast::Item::Struct(it) => it.field_list().is_none(),
- ast::Item::Trait(it) => it.assoc_item_list().is_none(),
- ast::Item::TypeAlias(it) => it.ty().is_none(),
- ast::Item::Union(it) => it.record_field_list().is_none(),
- _ => false,
- };
- if is_inbetween {
- return Some(item);
+ let make_path_kind_expr = |expr: ast::Expr| {
+ let it = expr.syntax();
+ let in_block_expr = is_in_block(it);
+ let in_loop_body = is_in_loop_body(it);
+ let after_if_expr = after_if_expr(it.clone());
+ let ref_expr_parent =
+ path.as_single_name_ref().and_then(|_| it.parent()).and_then(ast::RefExpr::cast);
+ let (innermost_ret_ty, self_param) = {
+ let find_ret_ty = |it: SyntaxNode| {
+ if let Some(item) = ast::Item::cast(it.clone()) {
+ match item {
+ ast::Item::Fn(f) => Some(sema.to_def(&f).map(|it| it.ret_type(sema.db))),
+ ast::Item::MacroCall(_) => None,
+ _ => Some(None),
}
- }
- }
- None
- };
-
- let type_location = |node: &SyntaxNode| {
- let parent = node.parent()?;
- let res = match_ast! {
- match parent {
- ast::Const(it) => {
- let name = find_opt_node_in_file(original_file, it.name())?;
- let original = ast::Const::cast(name.syntax().parent()?)?;
- TypeLocation::TypeAscription(TypeAscriptionTarget::Const(original.body()))
- },
- ast::RetType(it) => {
- if it.thin_arrow_token().is_none() {
- return None;
- }
- let parent = match ast::Fn::cast(parent.parent()?) {
- Some(x) => x.param_list(),
- None => ast::ClosureExpr::cast(parent.parent()?)?.param_list(),
- };
-
- let parent = find_opt_node_in_file(original_file, parent)?.syntax().parent()?;
- TypeLocation::TypeAscription(TypeAscriptionTarget::RetType(match_ast! {
- match parent {
- ast::ClosureExpr(it) => {
- it.body()
- },
- ast::Fn(it) => {
- it.body().map(ast::Expr::BlockExpr)
- },
- _ => return None,
- }
- }))
- },
- ast::Param(it) => {
- if it.colon_token().is_none() {
- return None;
- }
- TypeLocation::TypeAscription(TypeAscriptionTarget::FnParam(find_opt_node_in_file(original_file, it.pat())))
- },
- ast::LetStmt(it) => {
- if it.colon_token().is_none() {
- return None;
- }
- TypeLocation::TypeAscription(TypeAscriptionTarget::Let(find_opt_node_in_file(original_file, it.pat())))
- },
- ast::Impl(it) => {
- match it.trait_() {
- Some(t) if t.syntax() == node => TypeLocation::ImplTrait,
- _ => match it.self_ty() {
- Some(t) if t.syntax() == node => TypeLocation::ImplTarget,
- _ => return None,
- },
- }
- },
- ast::TypeBound(_) => TypeLocation::TypeBound,
- // is this case needed?
- ast::TypeBoundList(_) => TypeLocation::TypeBound,
- ast::GenericArg(it) => TypeLocation::GenericArgList(find_opt_node_in_file_compensated(sema, original_file, it.syntax().parent().and_then(ast::GenericArgList::cast))),
- // is this case needed?
- ast::GenericArgList(it) => TypeLocation::GenericArgList(find_opt_node_in_file_compensated(sema, original_file, Some(it))),
- ast::TupleField(_) => TypeLocation::TupleField,
- _ => return None,
- }
- };
- Some(res)
- };
-
- let is_in_condition = |it: &ast::Expr| {
- (|| {
- let parent = it.syntax().parent()?;
- if let Some(expr) = ast::WhileExpr::cast(parent.clone()) {
- Some(expr.condition()? == *it)
- } else if let Some(expr) = ast::IfExpr::cast(parent) {
- Some(expr.condition()? == *it)
} else {
- None
- }
- })()
- .unwrap_or(false)
- };
-
- let make_path_kind_expr = |expr: ast::Expr| {
- let it = expr.syntax();
- let in_block_expr = is_in_block(it);
- let in_loop_body = is_in_loop_body(it);
- let after_if_expr = after_if_expr(it.clone());
- let ref_expr_parent =
- path.as_single_name_ref().and_then(|_| it.parent()).and_then(ast::RefExpr::cast);
- let (innermost_ret_ty, self_param) = {
- let find_ret_ty = |it: SyntaxNode| {
- if let Some(item) = ast::Item::cast(it.clone()) {
- match item {
- ast::Item::Fn(f) => {
- Some(sema.to_def(&f).map(|it| it.ret_type(sema.db)))
- }
- ast::Item::MacroCall(_) => None,
- _ => Some(None),
- }
- } else {
- let expr = ast::Expr::cast(it)?;
- let callable = match expr {
- // FIXME
- // ast::Expr::BlockExpr(b) if b.async_token().is_some() || b.try_token().is_some() => sema.type_of_expr(b),
- ast::Expr::ClosureExpr(_) => sema.type_of_expr(&expr),
- _ => return None,
- };
- Some(
- callable
- .and_then(|c| c.adjusted().as_callable(sema.db))
- .map(|it| it.return_type()),
- )
- }
- };
- let find_fn_self_param = |it| match it {
- ast::Item::Fn(fn_) => {
- Some(sema.to_def(&fn_).and_then(|it| it.self_param(sema.db)))
- }
- ast::Item::MacroCall(_) => None,
- _ => Some(None),
- };
-
- match find_node_in_file_compensated(sema, original_file, &expr) {
- Some(it) => {
- let innermost_ret_ty = sema
- .ancestors_with_macros(it.syntax().clone())
- .find_map(find_ret_ty)
- .flatten();
-
- let self_param = sema
- .ancestors_with_macros(it.syntax().clone())
- .filter_map(ast::Item::cast)
- .find_map(find_fn_self_param)
- .flatten();
- (innermost_ret_ty, self_param)
- }
- None => (None, None),
+ let expr = ast::Expr::cast(it)?;
+ let callable = match expr {
+ // FIXME
+ // ast::Expr::BlockExpr(b) if b.async_token().is_some() || b.try_token().is_some() => sema.type_of_expr(b),
+ ast::Expr::ClosureExpr(_) => sema.type_of_expr(&expr),
+ _ => return None,
+ };
+ Some(
+ callable
+ .and_then(|c| c.adjusted().as_callable(sema.db))
+ .map(|it| it.return_type()),
+ )
}
};
- let is_func_update = func_update_record(it);
- let in_condition = is_in_condition(&expr);
- let incomplete_let = it
- .parent()
- .and_then(ast::LetStmt::cast)
- .map_or(false, |it| it.semicolon_token().is_none());
- let impl_ = fetch_immediate_impl(sema, original_file, expr.syntax());
-
- let in_match_guard = match it.parent().and_then(ast::MatchArm::cast) {
- Some(arm) => arm
- .fat_arrow_token()
- .map_or(true, |arrow| it.text_range().start() < arrow.text_range().start()),
- None => false,
+ let find_fn_self_param = |it| match it {
+ ast::Item::Fn(fn_) => Some(sema.to_def(&fn_).and_then(|it| it.self_param(sema.db))),
+ ast::Item::MacroCall(_) => None,
+ _ => Some(None),
};
- PathKind::Expr {
- expr_ctx: ExprCtx {
- in_block_expr,
- in_loop_body,
- after_if_expr,
- in_condition,
- ref_expr_parent,
- is_func_update,
- innermost_ret_ty,
- self_param,
- incomplete_let,
- impl_,
- in_match_guard,
- },
+ match find_node_in_file_compensated(sema, original_file, &expr) {
+ Some(it) => {
+ let innermost_ret_ty = sema
+ .ancestors_with_macros(it.syntax().clone())
+ .find_map(find_ret_ty)
+ .flatten();
+
+ let self_param = sema
+ .ancestors_with_macros(it.syntax().clone())
+ .filter_map(ast::Item::cast)
+ .find_map(find_fn_self_param)
+ .flatten();
+ (innermost_ret_ty, self_param)
+ }
+ None => (None, None),
}
};
- let make_path_kind_type = |ty: ast::Type| {
- let location = type_location(ty.syntax());
- PathKind::Type { location: location.unwrap_or(TypeLocation::Other) }
+ let is_func_update = func_update_record(it);
+ let in_condition = is_in_condition(&expr);
+ let incomplete_let = it
+ .parent()
+ .and_then(ast::LetStmt::cast)
+ .map_or(false, |it| it.semicolon_token().is_none());
+ let impl_ = fetch_immediate_impl(sema, original_file, expr.syntax());
+
+ let in_match_guard = match it.parent().and_then(ast::MatchArm::cast) {
+ Some(arm) => arm
+ .fat_arrow_token()
+ .map_or(true, |arrow| it.text_range().start() < arrow.text_range().start()),
+ None => false,
};
- let mut kind_macro_call = |it: ast::MacroCall| {
- path_ctx.has_macro_bang = it.excl_token().is_some();
- let parent = it.syntax().parent()?;
- // Any path in an item list will be treated as a macro call by the parser
- let kind = match_ast! {
- match parent {
- ast::MacroExpr(expr) => make_path_kind_expr(expr.into()),
- ast::MacroPat(it) => PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into())},
- ast::MacroType(ty) => make_path_kind_type(ty.into()),
- ast::ItemList(_) => PathKind::Item { kind: ItemListKind::Module },
- ast::AssocItemList(_) => PathKind::Item { kind: match parent.parent() {
- Some(it) => match_ast! {
- match it {
- ast::Trait(_) => ItemListKind::Trait,
- ast::Impl(it) => if it.trait_().is_some() {
- ItemListKind::TraitImpl(find_node_in_file_compensated(sema, original_file, &it))
- } else {
- ItemListKind::Impl
- },
- _ => return None
- }
- },
- None => return None,
- } },
- ast::ExternItemList(_) => PathKind::Item { kind: ItemListKind::ExternBlock },
- ast::SourceFile(_) => PathKind::Item { kind: ItemListKind::SourceFile },
- _ => return None,
- }
- };
- Some(kind)
- };
- let make_path_kind_attr = |meta: ast::Meta| {
- let attr = meta.parent_attr()?;
- let kind = attr.kind();
- let attached = attr.syntax().parent()?;
- let is_trailing_outer_attr = kind != AttrKind::Inner
- && non_trivia_sibling(attr.syntax().clone().into(), syntax::Direction::Next)
- .is_none();
- let annotated_item_kind =
- if is_trailing_outer_attr { None } else { Some(attached.kind()) };
- Some(PathKind::Attr { attr_ctx: AttrCtx { kind, annotated_item_kind } })
- };
+ PathKind::Expr {
+ expr_ctx: ExprCtx {
+ in_block_expr,
+ in_loop_body,
+ after_if_expr,
+ in_condition,
+ ref_expr_parent,
+ is_func_update,
+ innermost_ret_ty,
+ self_param,
+ incomplete_let,
+ impl_,
+ in_match_guard,
+ },
+ }
+ };
+ let make_path_kind_type = |ty: ast::Type| {
+ let location = type_location(ty.syntax());
+ PathKind::Type { location: location.unwrap_or(TypeLocation::Other) }
+ };
- // Infer the path kind
- let parent = path.syntax().parent()?;
+ let mut kind_macro_call = |it: ast::MacroCall| {
+ path_ctx.has_macro_bang = it.excl_token().is_some();
+ let parent = it.syntax().parent()?;
+ // Any path in an item list will be treated as a macro call by the parser
let kind = match_ast! {
match parent {
- ast::PathType(it) => make_path_kind_type(it.into()),
- ast::PathExpr(it) => {
- if let Some(p) = it.syntax().parent() {
- if ast::ExprStmt::can_cast(p.kind()) {
- if let Some(kind) = inbetween_body_and_decl_check(p) {
- return Some(make_res(NameRefKind::Keyword(kind)));
- }
- }
- }
-
- path_ctx.has_call_parens = it.syntax().parent().map_or(false, |it| ast::CallExpr::can_cast(it.kind()));
-
- make_path_kind_expr(it.into())
- },
- ast::TupleStructPat(it) => {
- path_ctx.has_call_parens = true;
- PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into()) }
- },
- ast::RecordPat(it) => {
- path_ctx.has_call_parens = true;
- PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into()) }
- },
- ast::PathPat(it) => {
- PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into())}
- },
- ast::MacroCall(it) => {
- // A macro call in this position is usually a result of parsing recovery, so check that
- if let Some(kind) = inbetween_body_and_decl_check(it.syntax().clone()) {
- return Some(make_res(NameRefKind::Keyword(kind)));
- }
-
- kind_macro_call(it)?
- },
- ast::Meta(meta) => make_path_kind_attr(meta)?,
- ast::Visibility(it) => PathKind::Vis { has_in_token: it.in_token().is_some() },
- ast::UseTree(_) => PathKind::Use,
- // completing inside a qualifier
- ast::Path(parent) => {
- path_ctx.parent = Some(parent.clone());
- let parent = iter::successors(Some(parent), |it| it.parent_path()).last()?.syntax().parent()?;
- match_ast! {
- match parent {
- ast::PathType(it) => make_path_kind_type(it.into()),
- ast::PathExpr(it) => {
- path_ctx.has_call_parens = it.syntax().parent().map_or(false, |it| ast::CallExpr::can_cast(it.kind()));
-
- make_path_kind_expr(it.into())
- },
- ast::TupleStructPat(it) => {
- path_ctx.has_call_parens = true;
- PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into()) }
- },
- ast::RecordPat(it) => {
- path_ctx.has_call_parens = true;
- PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into()) }
- },
- ast::PathPat(it) => {
- PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into())}
- },
- ast::MacroCall(it) => {
- kind_macro_call(it)?
+ ast::MacroExpr(expr) => make_path_kind_expr(expr.into()),
+ ast::MacroPat(it) => PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into())},
+ ast::MacroType(ty) => make_path_kind_type(ty.into()),
+ ast::ItemList(_) => PathKind::Item { kind: ItemListKind::Module },
+ ast::AssocItemList(_) => PathKind::Item { kind: match parent.parent() {
+ Some(it) => match_ast! {
+ match it {
+ ast::Trait(_) => ItemListKind::Trait,
+ ast::Impl(it) => if it.trait_().is_some() {
+ ItemListKind::TraitImpl(find_node_in_file_compensated(sema, original_file, &it))
+ } else {
+ ItemListKind::Impl
},
- ast::Meta(meta) => make_path_kind_attr(meta)?,
- ast::Visibility(it) => PathKind::Vis { has_in_token: it.in_token().is_some() },
- ast::UseTree(_) => PathKind::Use,
- ast::RecordExpr(it) => make_path_kind_expr(it.into()),
- _ => return None,
+ _ => return None
}
- }
- },
- ast::RecordExpr(it) => make_path_kind_expr(it.into()),
+ },
+ None => return None,
+ } },
+ ast::ExternItemList(_) => PathKind::Item { kind: ItemListKind::ExternBlock },
+ ast::SourceFile(_) => PathKind::Item { kind: ItemListKind::SourceFile },
_ => return None,
}
};
+ Some(kind)
+ };
+ let make_path_kind_attr = |meta: ast::Meta| {
+ let attr = meta.parent_attr()?;
+ let kind = attr.kind();
+ let attached = attr.syntax().parent()?;
+ let is_trailing_outer_attr = kind != AttrKind::Inner
+ && non_trivia_sibling(attr.syntax().clone().into(), syntax::Direction::Next).is_none();
+ let annotated_item_kind = if is_trailing_outer_attr { None } else { Some(attached.kind()) };
+ Some(PathKind::Attr { attr_ctx: AttrCtx { kind, annotated_item_kind } })
+ };
- path_ctx.kind = kind;
- path_ctx.has_type_args = segment.generic_arg_list().is_some();
+ // Infer the path kind
+ let parent = path.syntax().parent()?;
+ let kind = match_ast! {
+ match parent {
+ ast::PathType(it) => make_path_kind_type(it.into()),
+ ast::PathExpr(it) => {
+ if let Some(p) = it.syntax().parent() {
+ if ast::ExprStmt::can_cast(p.kind()) {
+ if let Some(kind) = inbetween_body_and_decl_check(p) {
+ return Some(make_res(NameRefKind::Keyword(kind)));
+ }
+ }
+ }
- // calculate the qualifier context
- if let Some((qualifier, use_tree_parent)) = path_or_use_tree_qualifier(&path) {
- path_ctx.use_tree_parent = use_tree_parent;
- if !use_tree_parent && segment.coloncolon_token().is_some() {
- path_ctx.qualified = Qualified::Absolute;
- } else {
- let qualifier = qualifier
- .segment()
- .and_then(|it| find_node_in_file(original_file, &it))
- .map(|it| it.parent_path());
- if let Some(qualifier) = qualifier {
- let type_anchor = match qualifier.segment().and_then(|it| it.kind()) {
- Some(ast::PathSegmentKind::Type {
- type_ref: Some(type_ref),
- trait_ref,
- }) if qualifier.qualifier().is_none() => Some((type_ref, trait_ref)),
- _ => None,
- };
+ path_ctx.has_call_parens = it.syntax().parent().map_or(false, |it| ast::CallExpr::can_cast(it.kind()));
+
+ make_path_kind_expr(it.into())
+ },
+ ast::TupleStructPat(it) => {
+ path_ctx.has_call_parens = true;
+ PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into()) }
+ },
+ ast::RecordPat(it) => {
+ path_ctx.has_call_parens = true;
+ PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into()) }
+ },
+ ast::PathPat(it) => {
+ PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into())}
+ },
+ ast::MacroCall(it) => {
+ // A macro call in this position is usually a result of parsing recovery, so check that
+ if let Some(kind) = inbetween_body_and_decl_check(it.syntax().clone()) {
+ return Some(make_res(NameRefKind::Keyword(kind)));
+ }
- path_ctx.qualified = if let Some((ty, trait_ref)) = type_anchor {
- let ty = match ty {
- ast::Type::InferType(_) => None,
- ty => sema.resolve_type(&ty),
- };
- let trait_ = trait_ref.and_then(|it| sema.resolve_trait(&it.path()?));
- Qualified::TypeAnchor { ty, trait_ }
- } else {
- let res = sema.resolve_path(&qualifier);
-
- // For understanding how and why super_chain_len is calculated the way it
- // is check the documentation at it's definition
- let mut segment_count = 0;
- let super_count =
- iter::successors(Some(qualifier.clone()), |p| p.qualifier())
- .take_while(|p| {
- p.segment()
- .and_then(|s| {
- segment_count += 1;
- s.super_token()
- })
- .is_some()
- })
- .count();
+ kind_macro_call(it)?
+ },
+ ast::Meta(meta) => make_path_kind_attr(meta)?,
+ ast::Visibility(it) => PathKind::Vis { has_in_token: it.in_token().is_some() },
+ ast::UseTree(_) => PathKind::Use,
+ // completing inside a qualifier
+ ast::Path(parent) => {
+ path_ctx.parent = Some(parent.clone());
+ let parent = iter::successors(Some(parent), |it| it.parent_path()).last()?.syntax().parent()?;
+ match_ast! {
+ match parent {
+ ast::PathType(it) => make_path_kind_type(it.into()),
+ ast::PathExpr(it) => {
+ path_ctx.has_call_parens = it.syntax().parent().map_or(false, |it| ast::CallExpr::can_cast(it.kind()));
+
+ make_path_kind_expr(it.into())
+ },
+ ast::TupleStructPat(it) => {
+ path_ctx.has_call_parens = true;
+ PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into()) }
+ },
+ ast::RecordPat(it) => {
+ path_ctx.has_call_parens = true;
+ PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into()) }
+ },
+ ast::PathPat(it) => {
+ PathKind::Pat { pat_ctx: pattern_context_for(sema, original_file, it.into())}
+ },
+ ast::MacroCall(it) => {
+ kind_macro_call(it)?
+ },
+ ast::Meta(meta) => make_path_kind_attr(meta)?,
+ ast::Visibility(it) => PathKind::Vis { has_in_token: it.in_token().is_some() },
+ ast::UseTree(_) => PathKind::Use,
+ ast::RecordExpr(it) => make_path_kind_expr(it.into()),
+ _ => return None,
+ }
+ }
+ },
+ ast::RecordExpr(it) => make_path_kind_expr(it.into()),
+ _ => return None,
+ }
+ };
- let super_chain_len =
- if segment_count > super_count { None } else { Some(super_count) };
+ path_ctx.kind = kind;
+ path_ctx.has_type_args = segment.generic_arg_list().is_some();
- Qualified::With { path: qualifier, resolution: res, super_chain_len }
+ // calculate the qualifier context
+ if let Some((qualifier, use_tree_parent)) = path_or_use_tree_qualifier(&path) {
+ path_ctx.use_tree_parent = use_tree_parent;
+ if !use_tree_parent && segment.coloncolon_token().is_some() {
+ path_ctx.qualified = Qualified::Absolute;
+ } else {
+ let qualifier = qualifier
+ .segment()
+ .and_then(|it| find_node_in_file(original_file, &it))
+ .map(|it| it.parent_path());
+ if let Some(qualifier) = qualifier {
+ let type_anchor = match qualifier.segment().and_then(|it| it.kind()) {
+ Some(ast::PathSegmentKind::Type { type_ref: Some(type_ref), trait_ref })
+ if qualifier.qualifier().is_none() =>
+ {
+ Some((type_ref, trait_ref))
}
+ _ => None,
};
- }
- } else if let Some(segment) = path.segment() {
- if segment.coloncolon_token().is_some() {
- path_ctx.qualified = Qualified::Absolute;
- }
- }
- let mut qualifier_ctx = QualifierCtx::default();
- if path_ctx.is_trivial_path() {
- // fetch the full expression that may have qualifiers attached to it
- let top_node = match path_ctx.kind {
- PathKind::Expr { expr_ctx: ExprCtx { in_block_expr: true, .. } } => {
- parent.ancestors().find(|it| ast::PathExpr::can_cast(it.kind())).and_then(|p| {
- let parent = p.parent()?;
- if ast::StmtList::can_cast(parent.kind()) {
- Some(p)
- } else if ast::ExprStmt::can_cast(parent.kind()) {
- Some(parent)
- } else {
- None
- }
- })
- }
- PathKind::Item { .. } => {
- parent.ancestors().find(|it| ast::MacroCall::can_cast(it.kind()))
+ path_ctx.qualified = if let Some((ty, trait_ref)) = type_anchor {
+ let ty = match ty {
+ ast::Type::InferType(_) => None,
+ ty => sema.resolve_type(&ty),
+ };
+ let trait_ = trait_ref.and_then(|it| sema.resolve_trait(&it.path()?));
+ Qualified::TypeAnchor { ty, trait_ }
+ } else {
+ let res = sema.resolve_path(&qualifier);
+
+ // For understanding how and why super_chain_len is calculated the way it
+ // is check the documentation at it's definition
+ let mut segment_count = 0;
+ let super_count = iter::successors(Some(qualifier.clone()), |p| p.qualifier())
+ .take_while(|p| {
+ p.segment()
+ .and_then(|s| {
+ segment_count += 1;
+ s.super_token()
+ })
+ .is_some()
+ })
+ .count();
+
+ let super_chain_len =
+ if segment_count > super_count { None } else { Some(super_count) };
+
+ Qualified::With { path: qualifier, resolution: res, super_chain_len }
}
- _ => None,
};
- if let Some(top) = top_node {
- if let Some(NodeOrToken::Node(error_node)) =
- syntax::algo::non_trivia_sibling(top.clone().into(), syntax::Direction::Prev)
- {
- if error_node.kind() == SyntaxKind::ERROR {
- qualifier_ctx.unsafe_tok = error_node
- .children_with_tokens()
- .filter_map(NodeOrToken::into_token)
- .find(|it| it.kind() == T![unsafe]);
- qualifier_ctx.vis_node =
- error_node.children().find_map(ast::Visibility::cast);
+ }
+ } else if let Some(segment) = path.segment() {
+ if segment.coloncolon_token().is_some() {
+ path_ctx.qualified = Qualified::Absolute;
+ }
+ }
+
+ let mut qualifier_ctx = QualifierCtx::default();
+ if path_ctx.is_trivial_path() {
+ // fetch the full expression that may have qualifiers attached to it
+ let top_node = match path_ctx.kind {
+ PathKind::Expr { expr_ctx: ExprCtx { in_block_expr: true, .. } } => {
+ parent.ancestors().find(|it| ast::PathExpr::can_cast(it.kind())).and_then(|p| {
+ let parent = p.parent()?;
+ if ast::StmtList::can_cast(parent.kind()) {
+ Some(p)
+ } else if ast::ExprStmt::can_cast(parent.kind()) {
+ Some(parent)
+ } else {
+ None
}
+ })
+ }
+ PathKind::Item { .. } => {
+ parent.ancestors().find(|it| ast::MacroCall::can_cast(it.kind()))
+ }
+ _ => None,
+ };
+ if let Some(top) = top_node {
+ if let Some(NodeOrToken::Node(error_node)) =
+ syntax::algo::non_trivia_sibling(top.clone().into(), syntax::Direction::Prev)
+ {
+ if error_node.kind() == SyntaxKind::ERROR {
+ qualifier_ctx.unsafe_tok = error_node
+ .children_with_tokens()
+ .filter_map(NodeOrToken::into_token)
+ .find(|it| it.kind() == T![unsafe]);
+ qualifier_ctx.vis_node = error_node.children().find_map(ast::Visibility::cast);
}
+ }
- if let PathKind::Item { .. } = path_ctx.kind {
- if qualifier_ctx.none() {
- if let Some(t) = top.first_token() {
- if let Some(prev) = t
- .prev_token()
- .and_then(|t| syntax::algo::skip_trivia_token(t, Direction::Prev))
- {
- if ![T![;], T!['}'], T!['{']].contains(&prev.kind()) {
- // This was inferred to be an item position path, but it seems
- // to be part of some other broken node which leaked into an item
- // list
- return None;
- }
+ if let PathKind::Item { .. } = path_ctx.kind {
+ if qualifier_ctx.none() {
+ if let Some(t) = top.first_token() {
+ if let Some(prev) = t
+ .prev_token()
+ .and_then(|t| syntax::algo::skip_trivia_token(t, Direction::Prev))
+ {
+ if ![T![;], T!['}'], T!['{']].contains(&prev.kind()) {
+ // This was inferred to be an item position path, but it seems
+ // to be part of some other broken node which leaked into an item
+ // list
+ return None;
}
}
}
}
}
}
- Some((NameRefContext { nameref, kind: NameRefKind::Path(path_ctx) }, qualifier_ctx))
}
+ Some((NameRefContext { nameref, kind: NameRefKind::Path(path_ctx) }, qualifier_ctx))
}
fn pattern_context_for(
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/lib.rs b/src/tools/rust-analyzer/crates/ide-completion/src/lib.rs
index ae1a440d0..9d0044e55 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/lib.rs
@@ -183,6 +183,7 @@ pub fn completions(
CompletionAnalysis::String { original, expanded: Some(expanded) } => {
completions::extern_abi::complete_extern_abi(acc, ctx, expanded);
completions::format_string::format_string(acc, ctx, original, expanded);
+ completions::env_vars::complete_cargo_env_vars(acc, ctx, expanded);
}
CompletionAnalysis::UnexpandedAttrTT {
colon_prefix,
@@ -234,7 +235,12 @@ pub fn resolve_completion_edits(
);
let import = items_with_name
.filter_map(|candidate| {
- current_module.find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind)
+ current_module.find_use_path_prefixed(
+ db,
+ candidate,
+ config.insert_use.prefix_kind,
+ config.prefer_no_std,
+ )
})
.find(|mod_path| mod_path.to_string() == full_import_path);
if let Some(import_path) = import {
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/snippet.rs b/src/tools/rust-analyzer/crates/ide-completion/src/snippet.rs
index dc1039fa6..f3b8eae4f 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/snippet.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/snippet.rs
@@ -174,8 +174,12 @@ fn import_edits(ctx: &CompletionContext<'_>, requires: &[GreenNode]) -> Option<V
hir::PathResolution::Def(def) => def.into(),
_ => return None,
};
- let path =
- ctx.module.find_use_path_prefixed(ctx.db, item, ctx.config.insert_use.prefix_kind)?;
+ let path = ctx.module.find_use_path_prefixed(
+ ctx.db,
+ item,
+ ctx.config.insert_use.prefix_kind,
+ ctx.config.prefer_no_std,
+ )?;
Some((path.len() > 1).then(|| LocatedImport::new(path.clone(), item, item, None)))
};
let mut res = Vec::with_capacity(requires.len());
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/tests.rs b/src/tools/rust-analyzer/crates/ide-completion/src/tests.rs
index cf826648d..9e2beb9ee 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/tests.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/tests.rs
@@ -66,6 +66,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
enable_private_editable: false,
callable: Some(CallableSnippets::FillArguments),
snippet_cap: SnippetCap::new(true),
+ prefer_no_std: false,
insert_use: InsertUseConfig {
granularity: ImportGranularity::Crate,
prefix_kind: PrefixKind::Plain,
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/tests/pattern.rs b/src/tools/rust-analyzer/crates/ide-completion/src/tests/pattern.rs
index 85c4dbd66..db8bef664 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/tests/pattern.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/tests/pattern.rs
@@ -714,3 +714,30 @@ impl Ty {
"#]],
);
}
+
+#[test]
+fn through_alias() {
+ check_empty(
+ r#"
+enum Enum<T> {
+ Unit,
+ Tuple(T),
+}
+
+type EnumAlias<T> = Enum<T>;
+
+fn f(x: EnumAlias<u8>) {
+ match x {
+ EnumAlias::$0 => (),
+ _ => (),
+ }
+
+}
+
+"#,
+ expect![[r#"
+ bn Tuple(…) Tuple($1)$0
+ bn Unit Unit$0
+ "#]],
+ );
+}
diff --git a/src/tools/rust-analyzer/crates/ide-db/Cargo.toml b/src/tools/rust-analyzer/crates/ide-db/Cargo.toml
index a1b0bd6cb..cf0bcd5c9 100644
--- a/src/tools/rust-analyzer/crates/ide-db/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/ide-db/Cargo.toml
@@ -15,11 +15,12 @@ tracing = "0.1.35"
rayon = "1.5.3"
fst = { version = "0.4.7", default-features = false }
rustc-hash = "1.1.0"
-once_cell = "1.12.0"
+once_cell = "1.15.0"
either = "1.7.0"
-itertools = "0.10.3"
+itertools = "0.10.5"
arrayvec = "0.7.2"
indexmap = "1.9.1"
+memchr = "2.5.0"
stdx = { path = "../stdx", version = "0.0.0" }
parser = { path = "../parser", version = "0.0.0" }
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs b/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs
index 26ef86155..40a6a3e89 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs
+++ b/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs
@@ -212,18 +212,20 @@ impl ImportAssets {
&self,
sema: &Semantics<'_, RootDatabase>,
prefix_kind: PrefixKind,
+ prefer_no_std: bool,
) -> Vec<LocatedImport> {
let _p = profile::span("import_assets::search_for_imports");
- self.search_for(sema, Some(prefix_kind))
+ self.search_for(sema, Some(prefix_kind), prefer_no_std)
}
/// This may return non-absolute paths if a part of the returned path is already imported into scope.
pub fn search_for_relative_paths(
&self,
sema: &Semantics<'_, RootDatabase>,
+ prefer_no_std: bool,
) -> Vec<LocatedImport> {
let _p = profile::span("import_assets::search_for_relative_paths");
- self.search_for(sema, None)
+ self.search_for(sema, None, prefer_no_std)
}
pub fn path_fuzzy_name_to_exact(&mut self, case_sensitive: bool) {
@@ -242,6 +244,7 @@ impl ImportAssets {
&self,
sema: &Semantics<'_, RootDatabase>,
prefixed: Option<PrefixKind>,
+ prefer_no_std: bool,
) -> Vec<LocatedImport> {
let _p = profile::span("import_assets::search_for");
@@ -252,6 +255,7 @@ impl ImportAssets {
item_for_path_search(sema.db, item)?,
&self.module_with_candidate,
prefixed,
+ prefer_no_std,
)
};
@@ -564,11 +568,12 @@ fn get_mod_path(
item_to_search: ItemInNs,
module_with_candidate: &Module,
prefixed: Option<PrefixKind>,
+ prefer_no_std: bool,
) -> Option<ModPath> {
if let Some(prefix_kind) = prefixed {
- module_with_candidate.find_use_path_prefixed(db, item_to_search, prefix_kind)
+ module_with_candidate.find_use_path_prefixed(db, item_to_search, prefix_kind, prefer_no_std)
} else {
- module_with_candidate.find_use_path(db, item_to_search)
+ module_with_candidate.find_use_path(db, item_to_search, prefer_no_std)
}
}
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/imports/merge_imports.rs b/src/tools/rust-analyzer/crates/ide-db/src/imports/merge_imports.rs
index 7fb4b90e6..371d642c1 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/imports/merge_imports.rs
+++ b/src/tools/rust-analyzer/crates/ide-db/src/imports/merge_imports.rs
@@ -225,7 +225,7 @@ fn path_cmp_short(a: &ast::Path, b: &ast::Path) -> Ordering {
}
/// Compares two paths, if one ends earlier than the other the has_tl parameters decide which is
-/// greater as a a path that has a tree list should be greater, while one that just ends without
+/// greater as a path that has a tree list should be greater, while one that just ends without
/// a tree list should be considered less.
pub(super) fn use_tree_path_cmp(
a: &ast::Path,
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/lib.rs b/src/tools/rust-analyzer/crates/ide-db/src/lib.rs
index 1ec62a842..e0bc0f89f 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/ide-db/src/lib.rs
@@ -38,6 +38,7 @@ pub mod syntax_helpers {
pub mod node_ext;
pub mod insert_whitespace_into_node;
pub mod format_string;
+ pub mod format_string_exprs;
pub use parser::LexedStr;
}
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs b/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs
index 40af9e6fe..12d873b4a 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs
+++ b/src/tools/rust-analyzer/crates/ide-db/src/path_transform.rs
@@ -173,6 +173,7 @@ impl<'a> Ctx<'a> {
let found_path = self.target_module.find_use_path(
self.source_scope.db.upcast(),
hir::ModuleDef::Trait(trait_ref),
+ false,
)?;
match ast::make::ty_path(mod_path_to_ast(&found_path)) {
ast::Type::PathType(path_ty) => Some(path_ty),
@@ -209,7 +210,7 @@ impl<'a> Ctx<'a> {
}
let found_path =
- self.target_module.find_use_path(self.source_scope.db.upcast(), def)?;
+ self.target_module.find_use_path(self.source_scope.db.upcast(), def, false)?;
let res = mod_path_to_ast(&found_path).clone_for_update();
if let Some(args) = path.segment().and_then(|it| it.generic_arg_list()) {
if let Some(segment) = res.segment() {
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/search.rs b/src/tools/rust-analyzer/crates/ide-db/src/search.rs
index 7deffe8e0..82b85f2fa 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/search.rs
+++ b/src/tools/rust-analyzer/crates/ide-db/src/search.rs
@@ -8,7 +8,9 @@ use std::{mem, sync::Arc};
use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt};
use hir::{DefWithBody, HasAttrs, HasSource, InFile, ModuleSource, Semantics, Visibility};
+use memchr::memmem::Finder;
use once_cell::unsync::Lazy;
+use parser::SyntaxKind;
use stdx::hash::NoHashHashMap;
use syntax::{ast, match_ast, AstNode, TextRange, TextSize};
@@ -67,6 +69,7 @@ pub enum ReferenceCategory {
// Create
Write,
Read,
+ Import,
// FIXME: Some day should be able to search in doc comments. Would probably
// need to switch from enum to bitflags then?
// DocComment
@@ -236,6 +239,7 @@ impl Definition {
DefWithBody::Function(f) => f.source(db).map(|src| src.syntax().cloned()),
DefWithBody::Const(c) => c.source(db).map(|src| src.syntax().cloned()),
DefWithBody::Static(s) => s.source(db).map(|src| src.syntax().cloned()),
+ DefWithBody::Variant(v) => v.source(db).map(|src| src.syntax().cloned()),
};
return match def {
Some(def) => SearchScope::file_range(def.as_ref().original_file_range(db)),
@@ -409,14 +413,17 @@ impl<'a> FindUsages<'a> {
Some(s) => s.as_str(),
None => return,
};
+ let finder = &Finder::new(name);
+ let include_self_kw_refs =
+ self.include_self_kw_refs.as_ref().map(|ty| (ty, Finder::new("Self")));
- // these can't be closures because rust infers the lifetimes wrong ...
+ // for<'a> |text: &'a str, name: &'a str, search_range: TextRange| -> impl Iterator<Item = TextSize> + 'a { ... }
fn match_indices<'a>(
text: &'a str,
- name: &'a str,
+ finder: &'a Finder<'a>,
search_range: TextRange,
) -> impl Iterator<Item = TextSize> + 'a {
- text.match_indices(name).filter_map(move |(idx, _)| {
+ finder.find_iter(text.as_bytes()).filter_map(move |idx| {
let offset: TextSize = idx.try_into().unwrap();
if !search_range.contains_inclusive(offset) {
return None;
@@ -425,6 +432,7 @@ impl<'a> FindUsages<'a> {
})
}
+ // for<'a> |scope: &'a SearchScope| -> impl Iterator<Item = (Arc<String>, FileId, TextRange)> + 'a { ... }
fn scope_files<'a>(
sema: &'a Semantics<'_, RootDatabase>,
scope: &'a SearchScope,
@@ -448,7 +456,7 @@ impl<'a> FindUsages<'a> {
let tree = Lazy::new(move || sema.parse(file_id).syntax().clone());
// Search for occurrences of the items name
- for offset in match_indices(&text, name, search_range) {
+ for offset in match_indices(&text, finder, search_range) {
for name in sema.find_nodes_at_offset_with_descend(&tree, offset) {
if match name {
ast::NameLike::NameRef(name_ref) => self.found_name_ref(&name_ref, sink),
@@ -460,8 +468,8 @@ impl<'a> FindUsages<'a> {
}
}
// Search for occurrences of the `Self` referring to our type
- if let Some(self_ty) = &self.include_self_kw_refs {
- for offset in match_indices(&text, "Self", search_range) {
+ if let Some((self_ty, finder)) = &include_self_kw_refs {
+ for offset in match_indices(&text, finder, search_range) {
for name_ref in sema.find_nodes_at_offset_with_descend(&tree, offset) {
if self.found_self_ty_name_ref(self_ty, &name_ref, sink) {
return;
@@ -477,20 +485,22 @@ impl<'a> FindUsages<'a> {
let scope = search_scope
.intersection(&SearchScope::module_and_children(self.sema.db, module));
- let is_crate_root = module.is_crate_root(self.sema.db);
+ let is_crate_root =
+ module.is_crate_root(self.sema.db).then(|| Finder::new("crate"));
+ let finder = &Finder::new("super");
for (text, file_id, search_range) in scope_files(sema, &scope) {
let tree = Lazy::new(move || sema.parse(file_id).syntax().clone());
- for offset in match_indices(&text, "super", search_range) {
+ for offset in match_indices(&text, finder, search_range) {
for name_ref in sema.find_nodes_at_offset_with_descend(&tree, offset) {
if self.found_name_ref(&name_ref, sink) {
return;
}
}
}
- if is_crate_root {
- for offset in match_indices(&text, "crate", search_range) {
+ if let Some(finder) = &is_crate_root {
+ for offset in match_indices(&text, finder, search_range) {
for name_ref in sema.find_nodes_at_offset_with_descend(&tree, offset) {
if self.found_name_ref(&name_ref, sink) {
return;
@@ -531,8 +541,9 @@ impl<'a> FindUsages<'a> {
search_range.unwrap_or_else(|| TextRange::up_to(TextSize::of(text.as_str())));
let tree = Lazy::new(|| sema.parse(file_id).syntax().clone());
+ let finder = &Finder::new("self");
- for offset in match_indices(&text, "self", search_range) {
+ for offset in match_indices(&text, finder, search_range) {
for name_ref in sema.find_nodes_at_offset_with_descend(&tree, offset) {
if self.found_self_module_name_ref(&name_ref, sink) {
return;
@@ -577,7 +588,7 @@ impl<'a> FindUsages<'a> {
let reference = FileReference {
range,
name: ast::NameLike::NameRef(name_ref.clone()),
- category: None,
+ category: is_name_ref_in_import(name_ref).then(|| ReferenceCategory::Import),
};
sink(file_id, reference)
}
@@ -756,7 +767,7 @@ impl ReferenceCategory {
fn new(def: &Definition, r: &ast::NameRef) -> Option<ReferenceCategory> {
// Only Locals and Fields have accesses for now.
if !matches!(def, Definition::Local(_) | Definition::Field(_)) {
- return None;
+ return is_name_ref_in_import(r).then(|| ReferenceCategory::Import);
}
let mode = r.syntax().ancestors().find_map(|node| {
@@ -783,3 +794,12 @@ impl ReferenceCategory {
mode.or(Some(ReferenceCategory::Read))
}
}
+
+fn is_name_ref_in_import(name_ref: &ast::NameRef) -> bool {
+ name_ref
+ .syntax()
+ .parent()
+ .and_then(ast::PathSegment::cast)
+ .and_then(|it| it.parent_path().top_path().syntax().parent())
+ .map_or(false, |it| it.kind() == SyntaxKind::USE_TREE)
+}
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string.rs b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string.rs
index f48a57008..2d6927cee 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string.rs
+++ b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string.rs
@@ -1,7 +1,8 @@
//! Tools to work with format string literals for the `format_args!` family of macros.
+use crate::syntax_helpers::node_ext::macro_call_for_string_token;
use syntax::{
ast::{self, IsString},
- AstNode, AstToken, TextRange, TextSize,
+ TextRange, TextSize,
};
pub fn is_format_string(string: &ast::String) -> bool {
@@ -14,8 +15,7 @@ pub fn is_format_string(string: &ast::String) -> bool {
// This setup lets us correctly highlight the components of `concat!("{}", "bla")` format
// strings. It still fails for `concat!("{", "}")`, but that is rare.
(|| {
- let macro_call = string.syntax().parent_ancestors().find_map(ast::MacroCall::cast)?;
- let name = macro_call.path()?.segment()?.name_ref()?;
+ let name = macro_call_for_string_token(string)?.path()?.segment()?.name_ref()?;
if !matches!(
name.text().as_str(),
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string_exprs.rs b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string_exprs.rs
new file mode 100644
index 000000000..ac6c6e8fe
--- /dev/null
+++ b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/format_string_exprs.rs
@@ -0,0 +1,267 @@
+//! Tools to work with expressions present in format string literals for the `format_args!` family of macros.
+//! Primarily meant for assists and completions.
+
+/// Enum for represenging extraced format string args.
+/// Can either be extracted expressions (which includes identifiers),
+/// or placeholders `{}`.
+#[derive(Debug, PartialEq, Eq)]
+pub enum Arg {
+ Placeholder,
+ Ident(String),
+ Expr(String),
+}
+
+/**
+ Add placeholders like `$1` and `$2` in place of [`Arg::Placeholder`],
+ and unwraps the [`Arg::Ident`] and [`Arg::Expr`] enums.
+ ```rust
+ # use ide_db::syntax_helpers::format_string_exprs::*;
+ assert_eq!(with_placeholders(vec![Arg::Ident("ident".to_owned()), Arg::Placeholder, Arg::Expr("expr + 2".to_owned())]), vec!["ident".to_owned(), "$1".to_owned(), "expr + 2".to_owned()])
+ ```
+*/
+
+pub fn with_placeholders(args: Vec<Arg>) -> Vec<String> {
+ let mut placeholder_id = 1;
+ args.into_iter()
+ .map(move |a| match a {
+ Arg::Expr(s) | Arg::Ident(s) => s,
+ Arg::Placeholder => {
+ let s = format!("${placeholder_id}");
+ placeholder_id += 1;
+ s
+ }
+ })
+ .collect()
+}
+
+/**
+ Parser for a format-like string. It is more allowing in terms of string contents,
+ as we expect variable placeholders to be filled with expressions.
+
+ Built for completions and assists, and escapes `\` and `$` in output.
+ (See the comments on `get_receiver_text()` for detail.)
+ Splits a format string that may contain expressions
+ like
+ ```rust
+ assert_eq!(parse("{ident} {} {expr + 42} ").unwrap(), ("{} {} {}", vec![Arg::Ident("ident"), Arg::Placeholder, Arg::Expr("expr + 42")]));
+ ```
+*/
+pub fn parse_format_exprs(input: &str) -> Result<(String, Vec<Arg>), ()> {
+ #[derive(Debug, Clone, Copy, PartialEq)]
+ enum State {
+ NotArg,
+ MaybeArg,
+ Expr,
+ Ident,
+ MaybeIncorrect,
+ FormatOpts,
+ }
+
+ let mut state = State::NotArg;
+ let mut current_expr = String::new();
+ let mut extracted_expressions = Vec::new();
+ let mut output = String::new();
+
+ // Count of open braces inside of an expression.
+ // We assume that user knows what they're doing, thus we treat it like a correct pattern, e.g.
+ // "{MyStruct { val_a: 0, val_b: 1 }}".
+ let mut inexpr_open_count = 0;
+
+ let mut chars = input.chars().peekable();
+ while let Some(chr) = chars.next() {
+ match (state, chr) {
+ (State::NotArg, '{') => {
+ output.push(chr);
+ state = State::MaybeArg;
+ }
+ (State::NotArg, '}') => {
+ output.push(chr);
+ state = State::MaybeIncorrect;
+ }
+ (State::NotArg, _) => {
+ if matches!(chr, '\\' | '$') {
+ output.push('\\');
+ }
+ output.push(chr);
+ }
+ (State::MaybeIncorrect, '}') => {
+ // It's okay, we met "}}".
+ output.push(chr);
+ state = State::NotArg;
+ }
+ (State::MaybeIncorrect, _) => {
+ // Error in the string.
+ return Err(());
+ }
+ // Escaped braces `{{`
+ (State::MaybeArg, '{') => {
+ output.push(chr);
+ state = State::NotArg;
+ }
+ (State::MaybeArg, '}') => {
+ // This is an empty sequence '{}'.
+ output.push(chr);
+ extracted_expressions.push(Arg::Placeholder);
+ state = State::NotArg;
+ }
+ (State::MaybeArg, _) => {
+ if matches!(chr, '\\' | '$') {
+ current_expr.push('\\');
+ }
+ current_expr.push(chr);
+
+ // While Rust uses the unicode sets of XID_start and XID_continue for Identifiers
+ // this is probably the best we can do to avoid a false positive
+ if chr.is_alphabetic() || chr == '_' {
+ state = State::Ident;
+ } else {
+ state = State::Expr;
+ }
+ }
+ (State::Ident | State::Expr, '}') => {
+ if inexpr_open_count == 0 {
+ output.push(chr);
+
+ if matches!(state, State::Expr) {
+ extracted_expressions.push(Arg::Expr(current_expr.trim().into()));
+ } else {
+ extracted_expressions.push(Arg::Ident(current_expr.trim().into()));
+ }
+
+ current_expr = String::new();
+ state = State::NotArg;
+ } else {
+ // We're closing one brace met before inside of the expression.
+ current_expr.push(chr);
+ inexpr_open_count -= 1;
+ }
+ }
+ (State::Ident | State::Expr, ':') if matches!(chars.peek(), Some(':')) => {
+ // path separator
+ state = State::Expr;
+ current_expr.push_str("::");
+ chars.next();
+ }
+ (State::Ident | State::Expr, ':') => {
+ if inexpr_open_count == 0 {
+ // We're outside of braces, thus assume that it's a specifier, like "{Some(value):?}"
+ output.push(chr);
+
+ if matches!(state, State::Expr) {
+ extracted_expressions.push(Arg::Expr(current_expr.trim().into()));
+ } else {
+ extracted_expressions.push(Arg::Ident(current_expr.trim().into()));
+ }
+
+ current_expr = String::new();
+ state = State::FormatOpts;
+ } else {
+ // We're inside of braced expression, assume that it's a struct field name/value delimiter.
+ current_expr.push(chr);
+ }
+ }
+ (State::Ident | State::Expr, '{') => {
+ state = State::Expr;
+ current_expr.push(chr);
+ inexpr_open_count += 1;
+ }
+ (State::Ident | State::Expr, _) => {
+ if !(chr.is_alphanumeric() || chr == '_' || chr == '#') {
+ state = State::Expr;
+ }
+
+ if matches!(chr, '\\' | '$') {
+ current_expr.push('\\');
+ }
+ current_expr.push(chr);
+ }
+ (State::FormatOpts, '}') => {
+ output.push(chr);
+ state = State::NotArg;
+ }
+ (State::FormatOpts, _) => {
+ if matches!(chr, '\\' | '$') {
+ output.push('\\');
+ }
+ output.push(chr);
+ }
+ }
+ }
+
+ if state != State::NotArg {
+ return Err(());
+ }
+
+ Ok((output, extracted_expressions))
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use expect_test::{expect, Expect};
+
+ fn check(input: &str, expect: &Expect) {
+ let (output, exprs) = parse_format_exprs(input).unwrap_or(("-".to_string(), vec![]));
+ let outcome_repr = if !exprs.is_empty() {
+ format!("{}; {}", output, with_placeholders(exprs).join(", "))
+ } else {
+ output
+ };
+
+ expect.assert_eq(&outcome_repr);
+ }
+
+ #[test]
+ fn format_str_parser() {
+ let test_vector = &[
+ ("no expressions", expect![["no expressions"]]),
+ (r"no expressions with \$0$1", expect![r"no expressions with \\\$0\$1"]),
+ ("{expr} is {2 + 2}", expect![["{} is {}; expr, 2 + 2"]]),
+ ("{expr:?}", expect![["{:?}; expr"]]),
+ ("{expr:1$}", expect![[r"{:1\$}; expr"]]),
+ ("{$0}", expect![[r"{}; \$0"]]),
+ ("{malformed", expect![["-"]]),
+ ("malformed}", expect![["-"]]),
+ ("{{correct", expect![["{{correct"]]),
+ ("correct}}", expect![["correct}}"]]),
+ ("{correct}}}", expect![["{}}}; correct"]]),
+ ("{correct}}}}}", expect![["{}}}}}; correct"]]),
+ ("{incorrect}}", expect![["-"]]),
+ ("placeholders {} {}", expect![["placeholders {} {}; $1, $2"]]),
+ ("mixed {} {2 + 2} {}", expect![["mixed {} {} {}; $1, 2 + 2, $2"]]),
+ (
+ "{SomeStruct { val_a: 0, val_b: 1 }}",
+ expect![["{}; SomeStruct { val_a: 0, val_b: 1 }"]],
+ ),
+ ("{expr:?} is {2.32f64:.5}", expect![["{:?} is {:.5}; expr, 2.32f64"]]),
+ (
+ "{SomeStruct { val_a: 0, val_b: 1 }:?}",
+ expect![["{:?}; SomeStruct { val_a: 0, val_b: 1 }"]],
+ ),
+ ("{ 2 + 2 }", expect![["{}; 2 + 2"]]),
+ ("{strsim::jaro_winkle(a)}", expect![["{}; strsim::jaro_winkle(a)"]]),
+ ("{foo::bar::baz()}", expect![["{}; foo::bar::baz()"]]),
+ ("{foo::bar():?}", expect![["{:?}; foo::bar()"]]),
+ ];
+
+ for (input, output) in test_vector {
+ check(input, output)
+ }
+ }
+
+ #[test]
+ fn arg_type() {
+ assert_eq!(
+ parse_format_exprs("{_ident} {r#raw_ident} {expr.obj} {name {thing: 42} } {}")
+ .unwrap()
+ .1,
+ vec![
+ Arg::Ident("_ident".to_owned()),
+ Arg::Ident("r#raw_ident".to_owned()),
+ Arg::Expr("expr.obj".to_owned()),
+ Arg::Expr("name {thing: 42}".to_owned()),
+ Arg::Placeholder
+ ]
+ );
+ }
+}
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs
index b890e2b58..39710b8f1 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs
+++ b/src/tools/rust-analyzer/crates/ide-db/src/syntax_helpers/node_ext.rs
@@ -2,8 +2,8 @@
use itertools::Itertools;
use parser::T;
use syntax::{
- ast::{self, HasLoopBody, PathSegmentKind, VisibilityKind},
- AstNode, Preorder, RustLanguage, WalkEvent,
+ ast::{self, HasLoopBody, MacroCall, PathSegmentKind, VisibilityKind},
+ AstNode, AstToken, Preorder, RustLanguage, WalkEvent,
};
pub fn expr_as_name_ref(expr: &ast::Expr) -> Option<ast::NameRef> {
@@ -457,3 +457,8 @@ pub fn parse_tt_as_comma_sep_paths(input: ast::TokenTree) -> Option<Vec<ast::Pat
.collect();
Some(paths)
}
+
+pub fn macro_call_for_string_token(string: &ast::String) -> Option<MacroCall> {
+ let macro_call = string.syntax().parent_ancestors().find_map(ast::MacroCall::cast)?;
+ Some(macro_call)
+}
diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/Cargo.toml b/src/tools/rust-analyzer/crates/ide-diagnostics/Cargo.toml
index 9b9e21a4d..e1d146f4e 100644
--- a/src/tools/rust-analyzer/crates/ide-diagnostics/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/ide-diagnostics/Cargo.toml
@@ -11,11 +11,9 @@ doctest = false
[dependencies]
cov-mark = "2.0.0-pre.1"
-itertools = "0.10.3"
-
-
either = "1.7.0"
-serde_json = "1.0.82"
+itertools = "0.10.5"
+serde_json = "1.0.86"
profile = { path = "../profile", version = "0.0.0" }
stdx = { path = "../stdx", version = "0.0.0" }
diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/inactive_code.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/inactive_code.rs
index 04918891b..f558b7256 100644
--- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/inactive_code.rs
+++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/inactive_code.rs
@@ -140,4 +140,35 @@ trait Bar {
"#,
);
}
+
+ #[test]
+ fn inactive_fields_and_variants() {
+ check(
+ r#"
+enum Foo {
+ #[cfg(a)] Bar,
+//^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: a is disabled
+ Baz {
+ #[cfg(a)] baz: String,
+ //^^^^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: a is disabled
+ },
+ Qux(#[cfg(a)] String),
+ //^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: a is disabled
+}
+
+struct Baz {
+ #[cfg(a)] baz: String,
+//^^^^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: a is disabled
+}
+
+struct Qux(#[cfg(a)] String);
+ //^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: a is disabled
+
+union FooBar {
+ #[cfg(a)] baz: u32,
+//^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: a is disabled
+}
+"#,
+ );
+ }
}
diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs
index a21db5b2c..303429519 100644
--- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs
+++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs
@@ -137,6 +137,7 @@ pub(crate) fn json_in_items(
sema.db,
it,
config.insert_use.prefix_kind,
+ config.prefer_no_std,
) {
insert_use(
&scope,
@@ -152,6 +153,7 @@ pub(crate) fn json_in_items(
sema.db,
it,
config.insert_use.prefix_kind,
+ config.prefer_no_std,
) {
insert_use(
&scope,
diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_fields.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_fields.rs
index edb1fc091..7f140eb6a 100644
--- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_fields.rs
+++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_fields.rs
@@ -124,6 +124,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
let type_path = current_module?.find_use_path(
ctx.sema.db,
item_for_path_search(ctx.sema.db, item_in_ns)?,
+ ctx.config.prefer_no_std,
)?;
use_trivial_constructor(
diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs
index 6bf90e645..62c69f90b 100644
--- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs
+++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs
@@ -59,9 +59,6 @@ fn add_reference(
d: &hir::TypeMismatch,
acc: &mut Vec<Assist>,
) -> Option<()> {
- let root = ctx.sema.db.parse_or_expand(d.expr.file_id)?;
- let expr_node = d.expr.value.to_node(&root);
-
let range = ctx.sema.diagnostics_display_range(d.expr.clone().map(|it| it.into())).range;
let (_, mutability) = d.expected.as_reference()?;
@@ -72,7 +69,7 @@ fn add_reference(
let ampersands = format!("&{}", mutability.as_keyword_for_ref());
- let edit = TextEdit::insert(expr_node.syntax().text_range().start(), ampersands);
+ let edit = TextEdit::insert(range.start(), ampersands);
let source_change =
SourceChange::from_text_edit(d.expr.file_id.original_file(ctx.sema.db), edit);
acc.push(fix("add_reference_here", "Add reference here", source_change, range));
@@ -315,6 +312,34 @@ fn main() {
}
#[test]
+ fn test_add_reference_to_macro_call() {
+ check_fix(
+ r#"
+macro_rules! thousand {
+ () => {
+ 1000_u64
+ };
+}
+fn test(foo: &u64) {}
+fn main() {
+ test($0thousand!());
+}
+ "#,
+ r#"
+macro_rules! thousand {
+ () => {
+ 1000_u64
+ };
+}
+fn test(foo: &u64) {}
+fn main() {
+ test(&thousand!());
+}
+ "#,
+ );
+ }
+
+ #[test]
fn test_add_mutable_reference_to_let_stmt() {
check_fix(
r#"
diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs
index 61e63ea7a..ae299f058 100644
--- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs
@@ -150,6 +150,7 @@ pub struct DiagnosticsConfig {
pub expr_fill_default: ExprFillDefaultMode,
// FIXME: We may want to include a whole `AssistConfig` here
pub insert_use: InsertUseConfig,
+ pub prefer_no_std: bool,
}
impl DiagnosticsConfig {
@@ -170,6 +171,7 @@ impl DiagnosticsConfig {
group: false,
skip_glob_imports: false,
},
+ prefer_no_std: false,
}
}
}
diff --git a/src/tools/rust-analyzer/crates/ide-ssr/Cargo.toml b/src/tools/rust-analyzer/crates/ide-ssr/Cargo.toml
index 73314e0f3..4baf786c4 100644
--- a/src/tools/rust-analyzer/crates/ide-ssr/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/ide-ssr/Cargo.toml
@@ -12,8 +12,7 @@ doctest = false
[dependencies]
cov-mark = "2.0.0-pre.1"
-
-itertools = "0.10.3"
+itertools = "0.10.5"
text-edit = { path = "../text-edit", version = "0.0.0" }
parser = { path = "../parser", version = "0.0.0" }
diff --git a/src/tools/rust-analyzer/crates/ide-ssr/src/matching.rs b/src/tools/rust-analyzer/crates/ide-ssr/src/matching.rs
index e3a837ddc..57b5ab6ab 100644
--- a/src/tools/rust-analyzer/crates/ide-ssr/src/matching.rs
+++ b/src/tools/rust-analyzer/crates/ide-ssr/src/matching.rs
@@ -648,9 +648,10 @@ impl Match {
.module();
for (path, resolved_path) in &template.resolved_paths {
if let hir::PathResolution::Def(module_def) = resolved_path.resolution {
- let mod_path = module.find_use_path(sema.db, module_def).ok_or_else(|| {
- match_error!("Failed to render template path `{}` at match location")
- })?;
+ let mod_path =
+ module.find_use_path(sema.db, module_def, false).ok_or_else(|| {
+ match_error!("Failed to render template path `{}` at match location")
+ })?;
self.rendered_template_paths.insert(path.clone(), mod_path);
}
}
diff --git a/src/tools/rust-analyzer/crates/ide/Cargo.toml b/src/tools/rust-analyzer/crates/ide/Cargo.toml
index 0e9771cd2..712459a7e 100644
--- a/src/tools/rust-analyzer/crates/ide/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/ide/Cargo.toml
@@ -13,12 +13,12 @@ doctest = false
cov-mark = "2.0.0-pre.1"
crossbeam-channel = "0.5.5"
either = "1.7.0"
-itertools = "0.10.3"
+itertools = "0.10.5"
tracing = "0.1.35"
oorandom = "11.1.3"
-pulldown-cmark-to-cmark = "10.0.1"
+pulldown-cmark-to-cmark = "10.0.4"
pulldown-cmark = { version = "0.9.1", default-features = false }
-url = "2.2.2"
+url = "2.3.1"
dot = "0.1.4"
stdx = { path = "../stdx", version = "0.0.0" }
diff --git a/src/tools/rust-analyzer/crates/ide/src/annotations.rs b/src/tools/rust-analyzer/crates/ide/src/annotations.rs
index 210c5c7fa..f994c284c 100644
--- a/src/tools/rust-analyzer/crates/ide/src/annotations.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/annotations.rs
@@ -8,13 +8,15 @@ use ide_db::{
use syntax::{ast::HasName, AstNode, TextRange};
use crate::{
- fn_references::find_all_methods,
+ annotations::fn_references::find_all_methods,
goto_implementation::goto_implementation,
references::find_all_refs,
runnables::{runnables, Runnable},
NavigationTarget, RunnableKind,
};
+mod fn_references;
+
// Feature: Annotations
//
// Provides user with annotations above items for looking up references or impl blocks
@@ -30,8 +32,8 @@ pub struct Annotation {
#[derive(Debug)]
pub enum AnnotationKind {
Runnable(Runnable),
- HasImpls { file_id: FileId, data: Option<Vec<NavigationTarget>> },
- HasReferences { file_id: FileId, data: Option<Vec<FileRange>> },
+ HasImpls { pos: FilePosition, data: Option<Vec<NavigationTarget>> },
+ HasReferences { pos: FilePosition, data: Option<Vec<FileRange>> },
}
pub struct AnnotationConfig {
@@ -41,6 +43,12 @@ pub struct AnnotationConfig {
pub annotate_references: bool,
pub annotate_method_references: bool,
pub annotate_enum_variant_references: bool,
+ pub location: AnnotationLocation,
+}
+
+pub enum AnnotationLocation {
+ AboveName,
+ AboveWholeItem,
}
pub(crate) fn annotations(
@@ -62,6 +70,16 @@ pub(crate) fn annotations(
}
}
+ let mk_ranges = |(range, focus): (_, Option<_>)| {
+ let cmd_target: TextRange = focus.unwrap_or(range);
+ let annotation_range = match config.location {
+ AnnotationLocation::AboveName => cmd_target,
+ AnnotationLocation::AboveWholeItem => range,
+ };
+ let target_pos = FilePosition { file_id, offset: cmd_target.start() };
+ (annotation_range, target_pos)
+ };
+
visit_file_defs(&Semantics::new(db), file_id, &mut |def| {
let range = match def {
Definition::Const(konst) if config.annotate_references => {
@@ -81,9 +99,13 @@ pub(crate) fn annotations(
})
.flatten()
.for_each(|range| {
+ let (annotation_range, target_position) = mk_ranges(range);
annotations.push(Annotation {
- range,
- kind: AnnotationKind::HasReferences { file_id, data: None },
+ range: annotation_range,
+ kind: AnnotationKind::HasReferences {
+ pos: target_position,
+ data: None,
+ },
})
})
}
@@ -108,15 +130,18 @@ pub(crate) fn annotations(
Some(range) => range,
None => return,
};
-
+ let (annotation_range, target_pos) = mk_ranges(range);
if config.annotate_impls && !matches!(def, Definition::Const(_)) {
- annotations
- .push(Annotation { range, kind: AnnotationKind::HasImpls { file_id, data: None } });
+ annotations.push(Annotation {
+ range: annotation_range,
+ kind: AnnotationKind::HasImpls { pos: target_pos, data: None },
+ });
}
+
if config.annotate_references {
annotations.push(Annotation {
- range,
- kind: AnnotationKind::HasReferences { file_id, data: None },
+ range: annotation_range,
+ kind: AnnotationKind::HasReferences { pos: target_pos, data: None },
});
}
@@ -124,10 +149,13 @@ pub(crate) fn annotations(
db: &RootDatabase,
node: InFile<T>,
source_file_id: FileId,
- ) -> Option<TextRange> {
+ ) -> Option<(TextRange, Option<TextRange>)> {
if let Some(InFile { file_id, value }) = node.original_ast_node(db) {
if file_id == source_file_id.into() {
- return value.name().map(|it| it.syntax().text_range());
+ return Some((
+ value.syntax().text_range(),
+ value.name().map(|name| name.syntax().text_range()),
+ ));
}
}
None
@@ -135,12 +163,13 @@ pub(crate) fn annotations(
});
if config.annotate_method_references {
- annotations.extend(find_all_methods(db, file_id).into_iter().map(
- |FileRange { file_id, range }| Annotation {
- range,
- kind: AnnotationKind::HasReferences { file_id, data: None },
- },
- ));
+ annotations.extend(find_all_methods(db, file_id).into_iter().map(|range| {
+ let (annotation_range, target_range) = mk_ranges(range);
+ Annotation {
+ range: annotation_range,
+ kind: AnnotationKind::HasReferences { pos: target_range, data: None },
+ }
+ }));
}
annotations
@@ -148,18 +177,11 @@ pub(crate) fn annotations(
pub(crate) fn resolve_annotation(db: &RootDatabase, mut annotation: Annotation) -> Annotation {
match annotation.kind {
- AnnotationKind::HasImpls { file_id, ref mut data } => {
- *data =
- goto_implementation(db, FilePosition { file_id, offset: annotation.range.start() })
- .map(|range| range.info);
+ AnnotationKind::HasImpls { pos, ref mut data } => {
+ *data = goto_implementation(db, pos).map(|range| range.info);
}
- AnnotationKind::HasReferences { file_id, ref mut data } => {
- *data = find_all_refs(
- &Semantics::new(db),
- FilePosition { file_id, offset: annotation.range.start() },
- None,
- )
- .map(|result| {
+ AnnotationKind::HasReferences { pos, ref mut data } => {
+ *data = find_all_refs(&Semantics::new(db), pos, None).map(|result| {
result
.into_iter()
.flat_map(|res| res.references)
@@ -188,21 +210,23 @@ mod tests {
use crate::{fixture, Annotation, AnnotationConfig};
- fn check(ra_fixture: &str, expect: Expect) {
+ use super::AnnotationLocation;
+
+ const DEFAULT_CONFIG: AnnotationConfig = AnnotationConfig {
+ binary_target: true,
+ annotate_runnables: true,
+ annotate_impls: true,
+ annotate_references: true,
+ annotate_method_references: true,
+ annotate_enum_variant_references: true,
+ location: AnnotationLocation::AboveName,
+ };
+
+ fn check_with_config(ra_fixture: &str, expect: Expect, config: &AnnotationConfig) {
let (analysis, file_id) = fixture::file(ra_fixture);
let annotations: Vec<Annotation> = analysis
- .annotations(
- &AnnotationConfig {
- binary_target: true,
- annotate_runnables: true,
- annotate_impls: true,
- annotate_references: true,
- annotate_method_references: true,
- annotate_enum_variant_references: true,
- },
- file_id,
- )
+ .annotations(config, file_id)
.unwrap()
.into_iter()
.map(|annotation| analysis.resolve_annotation(annotation).unwrap())
@@ -211,6 +235,10 @@ mod tests {
expect.assert_debug_eq(&annotations);
}
+ fn check(ra_fixture: &str, expect: Expect) {
+ check_with_config(ra_fixture, expect, &DEFAULT_CONFIG);
+ }
+
#[test]
fn const_annotations() {
check(
@@ -247,9 +275,12 @@ fn main() {
Annotation {
range: 6..10,
kind: HasReferences {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 6,
+ },
data: Some(
[
FileRange {
@@ -265,9 +296,12 @@ fn main() {
Annotation {
range: 30..36,
kind: HasReferences {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 30,
+ },
data: Some(
[],
),
@@ -276,9 +310,12 @@ fn main() {
Annotation {
range: 53..57,
kind: HasReferences {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 53,
+ },
data: Some(
[],
),
@@ -323,9 +360,12 @@ fn main() {
Annotation {
range: 7..11,
kind: HasImpls {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 7,
+ },
data: Some(
[],
),
@@ -334,9 +374,12 @@ fn main() {
Annotation {
range: 7..11,
kind: HasReferences {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 7,
+ },
data: Some(
[
FileRange {
@@ -352,9 +395,12 @@ fn main() {
Annotation {
range: 17..21,
kind: HasReferences {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 17,
+ },
data: Some(
[],
),
@@ -403,9 +449,12 @@ fn main() {
Annotation {
range: 7..11,
kind: HasImpls {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 7,
+ },
data: Some(
[
NavigationTarget {
@@ -424,9 +473,12 @@ fn main() {
Annotation {
range: 7..11,
kind: HasReferences {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 7,
+ },
data: Some(
[
FileRange {
@@ -448,9 +500,12 @@ fn main() {
Annotation {
range: 20..31,
kind: HasImpls {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 20,
+ },
data: Some(
[
NavigationTarget {
@@ -469,9 +524,12 @@ fn main() {
Annotation {
range: 20..31,
kind: HasReferences {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 20,
+ },
data: Some(
[
FileRange {
@@ -487,9 +545,12 @@ fn main() {
Annotation {
range: 69..73,
kind: HasReferences {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 69,
+ },
data: Some(
[],
),
@@ -530,9 +591,12 @@ fn main() {}
Annotation {
range: 3..7,
kind: HasReferences {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 3,
+ },
data: Some(
[],
),
@@ -581,9 +645,12 @@ fn main() {
Annotation {
range: 7..11,
kind: HasImpls {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 7,
+ },
data: Some(
[
NavigationTarget {
@@ -602,9 +669,12 @@ fn main() {
Annotation {
range: 7..11,
kind: HasReferences {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 7,
+ },
data: Some(
[
FileRange {
@@ -626,9 +696,12 @@ fn main() {
Annotation {
range: 33..44,
kind: HasReferences {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 33,
+ },
data: Some(
[
FileRange {
@@ -644,9 +717,12 @@ fn main() {
Annotation {
range: 61..65,
kind: HasReferences {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 61,
+ },
data: Some(
[],
),
@@ -740,9 +816,12 @@ mod tests {
Annotation {
range: 3..7,
kind: HasReferences {
- file_id: FileId(
- 0,
- ),
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 3,
+ },
data: Some(
[],
),
@@ -786,4 +865,48 @@ m!();
"#]],
);
}
+
+ #[test]
+ fn test_annotations_appear_above_whole_item_when_configured_to_do_so() {
+ check_with_config(
+ r#"
+/// This is a struct named Foo, obviously.
+#[derive(Clone)]
+struct Foo;
+"#,
+ expect![[r#"
+ [
+ Annotation {
+ range: 0..71,
+ kind: HasImpls {
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 67,
+ },
+ data: Some(
+ [],
+ ),
+ },
+ },
+ Annotation {
+ range: 0..71,
+ kind: HasReferences {
+ pos: FilePosition {
+ file_id: FileId(
+ 0,
+ ),
+ offset: 67,
+ },
+ data: Some(
+ [],
+ ),
+ },
+ },
+ ]
+ "#]],
+ &AnnotationConfig { location: AnnotationLocation::AboveWholeItem, ..DEFAULT_CONFIG },
+ );
+ }
}
diff --git a/src/tools/rust-analyzer/crates/ide/src/fn_references.rs b/src/tools/rust-analyzer/crates/ide/src/annotations/fn_references.rs
index 63fb322ce..0cadf125f 100644
--- a/src/tools/rust-analyzer/crates/ide/src/fn_references.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/annotations/fn_references.rs
@@ -4,30 +4,38 @@
use hir::Semantics;
use ide_assists::utils::test_related_attribute;
use ide_db::RootDatabase;
-use syntax::{ast, ast::HasName, AstNode, SyntaxNode};
+use syntax::{ast, ast::HasName, AstNode, SyntaxNode, TextRange};
-use crate::{FileId, FileRange};
+use crate::FileId;
-pub(crate) fn find_all_methods(db: &RootDatabase, file_id: FileId) -> Vec<FileRange> {
+pub(super) fn find_all_methods(
+ db: &RootDatabase,
+ file_id: FileId,
+) -> Vec<(TextRange, Option<TextRange>)> {
let sema = Semantics::new(db);
let source_file = sema.parse(file_id);
- source_file.syntax().descendants().filter_map(|it| method_range(it, file_id)).collect()
+ source_file.syntax().descendants().filter_map(|it| method_range(it)).collect()
}
-fn method_range(item: SyntaxNode, file_id: FileId) -> Option<FileRange> {
+fn method_range(item: SyntaxNode) -> Option<(TextRange, Option<TextRange>)> {
ast::Fn::cast(item).and_then(|fn_def| {
if test_related_attribute(&fn_def).is_some() {
None
} else {
- fn_def.name().map(|name| FileRange { file_id, range: name.syntax().text_range() })
+ Some((
+ fn_def.syntax().text_range(),
+ fn_def.name().map(|name| name.syntax().text_range()),
+ ))
}
})
}
#[cfg(test)]
mod tests {
+ use syntax::TextRange;
+
use crate::fixture;
- use crate::{FileRange, TextSize};
+ use crate::TextSize;
use std::ops::RangeInclusive;
#[test]
@@ -42,7 +50,7 @@ mod tests {
"#,
);
- let refs = analysis.find_all_methods(pos.file_id).unwrap();
+ let refs = super::find_all_methods(&analysis.db, pos.file_id);
check_result(&refs, &[3..=13, 27..=33, 47..=57]);
}
@@ -57,7 +65,7 @@ mod tests {
"#,
);
- let refs = analysis.find_all_methods(pos.file_id).unwrap();
+ let refs = super::find_all_methods(&analysis.db, pos.file_id);
check_result(&refs, &[19..=22, 35..=38]);
}
@@ -78,17 +86,18 @@ mod tests {
"#,
);
- let refs = analysis.find_all_methods(pos.file_id).unwrap();
+ let refs = super::find_all_methods(&analysis.db, pos.file_id);
check_result(&refs, &[28..=34]);
}
- fn check_result(refs: &[FileRange], expected: &[RangeInclusive<u32>]) {
+ fn check_result(refs: &[(TextRange, Option<TextRange>)], expected: &[RangeInclusive<u32>]) {
assert_eq!(refs.len(), expected.len());
- for (i, item) in refs.iter().enumerate() {
+ for (i, &(full, focus)) in refs.iter().enumerate() {
let range = &expected[i];
- assert_eq!(TextSize::from(*range.start()), item.range.start());
- assert_eq!(TextSize::from(*range.end()), item.range.end());
+ let item = focus.unwrap_or(full);
+ assert_eq!(TextSize::from(*range.start()), item.start());
+ assert_eq!(TextSize::from(*range.end()), item.end());
}
}
}
diff --git a/src/tools/rust-analyzer/crates/ide/src/doc_links.rs b/src/tools/rust-analyzer/crates/ide/src/doc_links.rs
index 92ce26b42..d96827326 100644
--- a/src/tools/rust-analyzer/crates/ide/src/doc_links.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/doc_links.rs
@@ -232,8 +232,13 @@ pub(crate) fn token_as_doc_comment(doc_token: &SyntaxToken) -> Option<DocComment
(match_ast! {
match doc_token {
ast::Comment(comment) => TextSize::try_from(comment.prefix().len()).ok(),
- ast::String(string) => doc_token.parent_ancestors().find_map(ast::Attr::cast)
- .filter(|attr| attr.simple_name().as_deref() == Some("doc")).and_then(|_| string.open_quote_text_range().map(|it| it.len())),
+ ast::String(string) => {
+ doc_token.parent_ancestors().find_map(ast::Attr::cast).filter(|attr| attr.simple_name().as_deref() == Some("doc"))?;
+ if doc_token.parent_ancestors().find_map(ast::MacroCall::cast).filter(|mac| mac.path().and_then(|p| p.segment()?.name_ref()).as_ref().map(|n| n.text()).as_deref() == Some("include_str")).is_some() {
+ return None;
+ }
+ string.open_quote_text_range().map(|it| it.len())
+ },
_ => None,
}
}).map(|prefix_len| DocCommentToken { prefix_len, doc_token: doc_token.clone() })
diff --git a/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs b/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs
index 36a648fe4..d0be1b3f4 100644
--- a/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/goto_definition.rs
@@ -48,10 +48,14 @@ pub(crate) fn goto_definition(
_ => 1,
})?;
if let Some(doc_comment) = token_as_doc_comment(&original_token) {
- return doc_comment.get_definition_with_descend_at(sema, position.offset, |def, _, _| {
- let nav = def.try_to_nav(db)?;
- Some(RangeInfo::new(original_token.text_range(), vec![nav]))
- });
+ return doc_comment.get_definition_with_descend_at(
+ sema,
+ position.offset,
+ |def, _, link_range| {
+ let nav = def.try_to_nav(db)?;
+ Some(RangeInfo::new(link_range, vec![nav]))
+ },
+ );
}
let navs = sema
.descend_into_macros(original_token.clone())
@@ -95,6 +99,14 @@ fn try_lookup_include_path(
if !matches!(&*name.text(), "include" | "include_str" | "include_bytes") {
return None;
}
+
+ // Ignore non-built-in macros to account for shadowing
+ if let Some(it) = sema.resolve_macro_call(&macro_call) {
+ if !matches!(it.kind(sema.db), hir::MacroKind::BuiltIn) {
+ return None;
+ }
+ }
+
let file_id = sema.db.resolve_path(AnchoredPath { anchor: file_id, path: &path })?;
let size = sema.db.file_text(file_id).len().try_into().ok()?;
Some(NavigationTarget {
@@ -156,9 +168,6 @@ mod tests {
fn check(ra_fixture: &str) {
let (analysis, position, expected) = fixture::annotations(ra_fixture);
let navs = analysis.goto_definition(position).unwrap().expect("no definition found").info;
- if navs.is_empty() {
- panic!("unresolved reference")
- }
let cmp = |&FileRange { file_id, range }: &_| (file_id, range.start());
let navs = navs
@@ -1348,6 +1357,10 @@ fn f(e: Enum) {
check(
r#"
//- /main.rs
+
+#[rustc_builtin_macro]
+macro_rules! include_str {}
+
fn main() {
let str = include_str!("foo.txt$0");
}
@@ -1357,6 +1370,42 @@ fn main() {
"#,
);
}
+
+ #[test]
+ fn goto_doc_include_str() {
+ check(
+ r#"
+//- /main.rs
+#[rustc_builtin_macro]
+macro_rules! include_str {}
+
+#[doc = include_str!("docs.md$0")]
+struct Item;
+
+//- /docs.md
+// docs
+//^file
+"#,
+ );
+ }
+
+ #[test]
+ fn goto_shadow_include() {
+ check(
+ r#"
+//- /main.rs
+macro_rules! include {
+ ("included.rs") => {}
+}
+
+include!("included.rs$0");
+
+//- /included.rs
+// empty
+"#,
+ );
+ }
+
#[cfg(test)]
mod goto_impl_of_trait_fn {
use super::check;
diff --git a/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs b/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs
index f190da326..540a11583 100644
--- a/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/highlight_related.rs
@@ -377,6 +377,7 @@ mod tests {
match it {
ReferenceCategory::Read => "read",
ReferenceCategory::Write => "write",
+ ReferenceCategory::Import => "import",
}
.to_string()
}),
@@ -423,12 +424,12 @@ struct Foo;
check(
r#"
use crate$0;
- //^^^^^
+ //^^^^^ import
use self;
- //^^^^
+ //^^^^ import
mod __ {
use super;
- //^^^^^
+ //^^^^^ import
}
"#,
);
@@ -436,7 +437,7 @@ mod __ {
r#"
//- /main.rs crate:main deps:lib
use lib$0;
- //^^^
+ //^^^ import
//- /lib.rs crate:lib
"#,
);
@@ -450,7 +451,7 @@ use lib$0;
mod foo;
//- /foo.rs
use self$0;
- // ^^^^
+ // ^^^^ import
"#,
);
}
@@ -1375,4 +1376,20 @@ fn main() {
"#,
);
}
+
+ #[test]
+ fn test_assoc_type_highlighting() {
+ check(
+ r#"
+trait Trait {
+ type Output;
+ // ^^^^^^
+}
+impl Trait for () {
+ type Output$0 = ();
+ // ^^^^^^
+}
+"#,
+ );
+ }
}
diff --git a/src/tools/rust-analyzer/crates/ide/src/hover/render.rs b/src/tools/rust-analyzer/crates/ide/src/hover/render.rs
index c5c50d88d..d109c0769 100644
--- a/src/tools/rust-analyzer/crates/ide/src/hover/render.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/hover/render.rs
@@ -346,7 +346,16 @@ pub(super) fn definition(
Definition::Module(it) => label_and_docs(db, it),
Definition::Function(it) => label_and_docs(db, it),
Definition::Adt(it) => label_and_docs(db, it),
- Definition::Variant(it) => label_and_docs(db, it),
+ Definition::Variant(it) => label_value_and_docs(db, it, |&it| {
+ if !it.parent_enum(db).is_data_carrying(db) {
+ match it.eval(db) {
+ Ok(x) => Some(format!("{}", x)),
+ Err(_) => it.value(db).map(|x| format!("{:?}", x)),
+ }
+ } else {
+ None
+ }
+ }),
Definition::Const(it) => label_value_and_docs(db, it, |it| {
let body = it.eval(db);
match body {
diff --git a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
index 4b8b47783..eb997e6fe 100644
--- a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
@@ -698,6 +698,7 @@ fn hover_enum_variant() {
check(
r#"
enum Option<T> {
+ Some(T)
/// The None variant
Non$0e
}
@@ -3528,6 +3529,112 @@ impl<const LEN: usize> Foo<LEN$0> {}
}
#[test]
+fn hover_const_eval_variant() {
+ // show hex for <10
+ check(
+ r#"
+#[repr(u8)]
+enum E {
+ /// This is a doc
+ A$0 = 1 << 3,
+}
+"#,
+ expect![[r#"
+ *A*
+
+ ```rust
+ test::E
+ ```
+
+ ```rust
+ A = 8
+ ```
+
+ ---
+
+ This is a doc
+ "#]],
+ );
+ // show hex for >10
+ check(
+ r#"
+#[repr(u8)]
+enum E {
+ /// This is a doc
+ A$0 = (1 << 3) + (1 << 2),
+}
+"#,
+ expect![[r#"
+ *A*
+
+ ```rust
+ test::E
+ ```
+
+ ```rust
+ A = 12 (0xC)
+ ```
+
+ ---
+
+ This is a doc
+ "#]],
+ );
+ // enums in const eval
+ check(
+ r#"
+#[repr(u8)]
+enum E {
+ A = 1,
+ /// This is a doc
+ B$0 = E::A as u8 + 1,
+}
+"#,
+ expect![[r#"
+ *B*
+
+ ```rust
+ test::E
+ ```
+
+ ```rust
+ B = 2
+ ```
+
+ ---
+
+ This is a doc
+ "#]],
+ );
+ // unspecified variant should increment by one
+ check(
+ r#"
+#[repr(u8)]
+enum E {
+ A = 4,
+ /// This is a doc
+ B$0,
+}
+"#,
+ expect![[r#"
+ *B*
+
+ ```rust
+ test::E
+ ```
+
+ ```rust
+ B = 5
+ ```
+
+ ---
+
+ This is a doc
+ "#]],
+ );
+}
+
+#[test]
fn hover_const_eval() {
// show hex for <10
check(
@@ -3823,6 +3930,35 @@ fn foo() {
This is a doc
"#]],
);
+ check(
+ r#"
+enum E {
+ /// This is a doc
+ A = 3,
+}
+fn foo(e: E) {
+ match e {
+ E::A$0 => (),
+ _ => ()
+ }
+}
+"#,
+ expect![[r#"
+ *A*
+
+ ```rust
+ test::E
+ ```
+
+ ```rust
+ A = 3
+ ```
+
+ ---
+
+ This is a doc
+ "#]],
+ );
}
#[test]
diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs
index d1b1d2c33..34d8bf67a 100644
--- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs
@@ -176,12 +176,6 @@ impl fmt::Debug for InlayHintLabelPart {
// * elided lifetimes
// * compiler inserted reborrows
//
-// |===
-// | Editor | Action Name
-//
-// | VS Code | **rust-analyzer: Toggle inlay hints*
-// |===
-//
// image::https://user-images.githubusercontent.com/48062697/113020660-b5f98b80-917a-11eb-8d70-3be3fd558cdd.png[]
pub(crate) fn inlay_hints(
db: &RootDatabase,
@@ -1688,6 +1682,74 @@ fn main() {
}
#[test]
+ fn iterator_hint_regression_issue_12674() {
+ // Ensure we don't crash while solving the projection type of iterators.
+ check_expect(
+ InlayHintsConfig { chaining_hints: true, ..DISABLED_CONFIG },
+ r#"
+//- minicore: iterators
+struct S<T>(T);
+impl<T> S<T> {
+ fn iter(&self) -> Iter<'_, T> { loop {} }
+}
+struct Iter<'a, T: 'a>(&'a T);
+impl<'a, T> Iterator for Iter<'a, T> {
+ type Item = &'a T;
+ fn next(&mut self) -> Option<Self::Item> { loop {} }
+}
+struct Container<'a> {
+ elements: S<&'a str>,
+}
+struct SliceIter<'a, T>(&'a T);
+impl<'a, T> Iterator for SliceIter<'a, T> {
+ type Item = &'a T;
+ fn next(&mut self) -> Option<Self::Item> { loop {} }
+}
+
+fn main(a: SliceIter<'_, Container>) {
+ a
+ .filter_map(|c| Some(c.elements.iter().filter_map(|v| Some(v))))
+ .map(|e| e);
+}
+ "#,
+ expect![[r#"
+ [
+ InlayHint {
+ range: 484..554,
+ kind: ChainingHint,
+ label: [
+ "impl Iterator<Item = impl Iterator<Item = &&str>>",
+ ],
+ tooltip: Some(
+ HoverRanged(
+ FileId(
+ 0,
+ ),
+ 484..554,
+ ),
+ ),
+ },
+ InlayHint {
+ range: 484..485,
+ kind: ChainingHint,
+ label: [
+ "SliceIter<Container>",
+ ],
+ tooltip: Some(
+ HoverRanged(
+ FileId(
+ 0,
+ ),
+ 484..485,
+ ),
+ ),
+ },
+ ]
+ "#]],
+ );
+ }
+
+ #[test]
fn infer_call_method_return_associated_types_with_generic() {
check_types(
r#"
@@ -1962,7 +2024,14 @@ impl<T> Vec<T> {
}
impl<T> IntoIterator for Vec<T> {
- type Item=T;
+ type Item = T;
+ type IntoIter = IntoIter<T>;
+}
+
+struct IntoIter<T> {}
+
+impl<T> Iterator for IntoIter<T> {
+ type Item = T;
}
fn main() {
diff --git a/src/tools/rust-analyzer/crates/ide/src/lib.rs b/src/tools/rust-analyzer/crates/ide/src/lib.rs
index 055233081..416817ca0 100644
--- a/src/tools/rust-analyzer/crates/ide/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/lib.rs
@@ -31,7 +31,6 @@ mod highlight_related;
mod expand_macro;
mod extend_selection;
mod file_structure;
-mod fn_references;
mod folding_ranges;
mod goto_declaration;
mod goto_definition;
@@ -74,7 +73,7 @@ use syntax::SourceFile;
use crate::navigation_target::{ToNav, TryToNav};
pub use crate::{
- annotations::{Annotation, AnnotationConfig, AnnotationKind},
+ annotations::{Annotation, AnnotationConfig, AnnotationKind, AnnotationLocation},
call_hierarchy::CallItem,
expand_macro::ExpandedMacro,
file_structure::{StructureNode, StructureNodeKind},
@@ -236,7 +235,7 @@ impl Analysis {
Env::default(),
Ok(Vec::new()),
false,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo { repo: None, name: None },
);
change.change_file(file_id, Some(Arc::new(text)));
change.set_crate_graph(crate_graph);
@@ -429,11 +428,6 @@ impl Analysis {
self.with_db(|db| references::find_all_refs(&Semantics::new(db), position, search_scope))
}
- /// Finds all methods and free functions for the file. Does not return tests!
- pub fn find_all_methods(&self, file_id: FileId) -> Cancellable<Vec<FileRange>> {
- self.with_db(|db| fn_references::find_all_methods(db, file_id))
- }
-
/// Returns a short text describing element at position.
pub fn hover(
&self,
@@ -488,8 +482,18 @@ impl Analysis {
}
/// Returns crates this file belongs too.
- pub fn crate_for(&self, file_id: FileId) -> Cancellable<Vec<CrateId>> {
- self.with_db(|db| parent_module::crate_for(db, file_id))
+ pub fn crates_for(&self, file_id: FileId) -> Cancellable<Vec<CrateId>> {
+ self.with_db(|db| parent_module::crates_for(db, file_id))
+ }
+
+ /// Returns crates this file belongs too.
+ pub fn transitive_rev_deps(&self, crate_id: CrateId) -> Cancellable<Vec<CrateId>> {
+ self.with_db(|db| db.crate_graph().transitive_rev_deps(crate_id).collect())
+ }
+
+ /// Returns crates this file *might* belong too.
+ pub fn relevant_crates_for(&self, file_id: FileId) -> Cancellable<Vec<CrateId>> {
+ self.with_db(|db| db.relevant_crates(file_id).iter().copied().collect())
}
/// Returns the edition of the given crate.
diff --git a/src/tools/rust-analyzer/crates/ide/src/moniker.rs b/src/tools/rust-analyzer/crates/ide/src/moniker.rs
index 600a52630..852a8fd83 100644
--- a/src/tools/rust-analyzer/crates/ide/src/moniker.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/moniker.rs
@@ -253,10 +253,14 @@ pub(crate) fn def_to_moniker(
},
kind: if krate == from_crate { MonikerKind::Export } else { MonikerKind::Import },
package_information: {
- let name = krate.display_name(db)?.to_string();
- let (repo, version) = match krate.origin(db) {
- CrateOrigin::CratesIo { repo } => (repo?, krate.version(db)?),
+ let (name, repo, version) = match krate.origin(db) {
+ CrateOrigin::CratesIo { repo, name } => (
+ name.unwrap_or(krate.display_name(db)?.canonical_name().to_string()),
+ repo?,
+ krate.version(db)?,
+ ),
CrateOrigin::Lang(lang) => (
+ krate.display_name(db)?.canonical_name().to_string(),
"https://github.com/rust-lang/rust/".to_string(),
match lang {
LangCrateOrigin::Other => {
diff --git a/src/tools/rust-analyzer/crates/ide/src/parent_module.rs b/src/tools/rust-analyzer/crates/ide/src/parent_module.rs
index 8f3cc8687..506f9452c 100644
--- a/src/tools/rust-analyzer/crates/ide/src/parent_module.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/parent_module.rs
@@ -1,6 +1,6 @@
-use hir::Semantics;
+use hir::{db::DefDatabase, Semantics};
use ide_db::{
- base_db::{CrateId, FileId, FilePosition},
+ base_db::{CrateId, FileId, FileLoader, FilePosition},
RootDatabase,
};
use itertools::Itertools;
@@ -55,9 +55,13 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na
}
/// Returns `Vec` for the same reason as `parent_module`
-pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
- let sema = Semantics::new(db);
- sema.to_module_defs(file_id).map(|module| module.krate().into()).unique().collect()
+pub(crate) fn crates_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
+ db.relevant_crates(file_id)
+ .iter()
+ .copied()
+ .filter(|&crate_id| db.crate_def_map(crate_id).modules_for_file(file_id).next().is_some())
+ .sorted()
+ .collect()
}
#[cfg(test)]
@@ -147,7 +151,7 @@ $0
mod foo;
"#,
);
- assert_eq!(analysis.crate_for(file_id).unwrap().len(), 1);
+ assert_eq!(analysis.crates_for(file_id).unwrap().len(), 1);
}
#[test]
@@ -162,6 +166,6 @@ mod baz;
mod baz;
"#,
);
- assert_eq!(analysis.crate_for(file_id).unwrap().len(), 2);
+ assert_eq!(analysis.crates_for(file_id).unwrap().len(), 2);
}
}
diff --git a/src/tools/rust-analyzer/crates/ide/src/references.rs b/src/tools/rust-analyzer/crates/ide/src/references.rs
index 99614b645..e942413c1 100644
--- a/src/tools/rust-analyzer/crates/ide/src/references.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/references.rs
@@ -742,7 +742,7 @@ pub struct Foo {
expect![[r#"
foo Module FileId(0) 0..8 4..7
- FileId(0) 14..17
+ FileId(0) 14..17 Import
"#]],
);
}
@@ -760,7 +760,7 @@ use self$0;
expect![[r#"
foo Module FileId(0) 0..8 4..7
- FileId(1) 4..8
+ FileId(1) 4..8 Import
"#]],
);
}
@@ -775,7 +775,7 @@ use self$0;
expect![[r#"
Module FileId(0) 0..10
- FileId(0) 4..8
+ FileId(0) 4..8 Import
"#]],
);
}
@@ -803,7 +803,7 @@ pub(super) struct Foo$0 {
expect![[r#"
Foo Struct FileId(2) 0..41 18..21
- FileId(1) 20..23
+ FileId(1) 20..23 Import
FileId(1) 47..50
"#]],
);
@@ -966,7 +966,7 @@ fn g() { f(); }
expect![[r#"
f Function FileId(0) 22..31 25..26
- FileId(1) 11..12
+ FileId(1) 11..12 Import
FileId(1) 24..25
"#]],
);
@@ -1424,9 +1424,9 @@ pub use level1::Foo;
expect![[r#"
Foo Struct FileId(0) 0..15 11..14
- FileId(1) 16..19
- FileId(2) 16..19
- FileId(3) 16..19
+ FileId(1) 16..19 Import
+ FileId(2) 16..19 Import
+ FileId(3) 16..19 Import
"#]],
);
}
@@ -1454,7 +1454,7 @@ lib::foo!();
expect![[r#"
foo Macro FileId(1) 0..61 29..32
- FileId(0) 46..49
+ FileId(0) 46..49 Import
FileId(2) 0..3
FileId(3) 5..8
"#]],
@@ -1617,7 +1617,7 @@ struct Foo;
expect![[r#"
derive_identity Derive FileId(2) 1..107 45..60
- FileId(0) 17..31
+ FileId(0) 17..31 Import
FileId(0) 56..70
"#]],
);
diff --git a/src/tools/rust-analyzer/crates/ide/src/static_index.rs b/src/tools/rust-analyzer/crates/ide/src/static_index.rs
index 9e5eb9095..27ad1a948 100644
--- a/src/tools/rust-analyzer/crates/ide/src/static_index.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/static_index.rs
@@ -210,9 +210,7 @@ fn get_definition(sema: &Semantics<'_, RootDatabase>, token: SyntaxToken) -> Opt
let def = IdentClass::classify_token(sema, &token).map(IdentClass::definitions_no_ops);
if let Some(&[x]) = def.as_deref() {
return Some(x);
- } else {
- continue;
- };
+ }
}
None
}
diff --git a/src/tools/rust-analyzer/crates/ide/src/status.rs b/src/tools/rust-analyzer/crates/ide/src/status.rs
index f4d038744..20810c25b 100644
--- a/src/tools/rust-analyzer/crates/ide/src/status.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/status.rs
@@ -45,7 +45,7 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
if let Some(file_id) = file_id {
format_to!(buf, "\nFile info:\n");
- let crates = crate::parent_module::crate_for(db, file_id);
+ let crates = crate::parent_module::crates_for(db, file_id);
if crates.is_empty() {
format_to!(buf, "Does not belong to any crate");
}
diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/highlight.rs b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/highlight.rs
index 9395e914c..e7d0a8be7 100644
--- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/highlight.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/highlight.rs
@@ -87,9 +87,9 @@ fn punctuation(
let parent = token.parent();
let parent_kind = parent.as_ref().map_or(EOF, SyntaxNode::kind);
match (kind, parent_kind) {
- (T![?], _) => HlTag::Operator(HlOperator::Other) | HlMod::ControlFlow,
+ (T![?], TRY_EXPR) => HlTag::Operator(HlOperator::Other) | HlMod::ControlFlow,
(T![&], BIN_EXPR) => HlOperator::Bitwise.into(),
- (T![&], _) => {
+ (T![&], REF_EXPR) => {
let h = HlTag::Operator(HlOperator::Other).into();
let is_unsafe = parent
.and_then(ast::RefExpr::cast)
@@ -100,7 +100,9 @@ fn punctuation(
h
}
}
- (T![::] | T![->] | T![=>] | T![..] | T![=] | T![@] | T![.], _) => HlOperator::Other.into(),
+ (T![::] | T![->] | T![=>] | T![..] | T![..=] | T![=] | T![@] | T![.], _) => {
+ HlOperator::Other.into()
+ }
(T![!], MACRO_CALL | MACRO_RULES) => HlPunct::MacroBang.into(),
(T![!], NEVER_TYPE) => HlTag::BuiltinType.into(),
(T![!], PREFIX_EXPR) => HlOperator::Logical.into(),
@@ -129,7 +131,7 @@ fn punctuation(
(T![+=] | T![-=] | T![*=] | T![/=] | T![%=], BIN_EXPR) => {
Highlight::from(HlOperator::Arithmetic) | HlMod::Mutable
}
- (T![|] | T![&] | T![!] | T![^] | T![>>] | T![<<], BIN_EXPR) => HlOperator::Bitwise.into(),
+ (T![|] | T![&] | T![^] | T![>>] | T![<<], BIN_EXPR) => HlOperator::Bitwise.into(),
(T![|=] | T![&=] | T![^=] | T![>>=] | T![<<=], BIN_EXPR) => {
Highlight::from(HlOperator::Bitwise) | HlMod::Mutable
}
@@ -137,7 +139,6 @@ fn punctuation(
(T![>] | T![<] | T![==] | T![>=] | T![<=] | T![!=], BIN_EXPR) => {
HlOperator::Comparison.into()
}
- (_, PREFIX_EXPR | BIN_EXPR | RANGE_EXPR | RANGE_PAT | REST_PAT) => HlOperator::Other.into(),
(_, ATTR) => HlTag::AttributeBracket.into(),
(kind, _) => match kind {
T!['['] | T![']'] => HlPunct::Bracket,
diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html
index e07fd3925..9ed65fbc8 100644
--- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html
+++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_assoc_functions.html
@@ -48,15 +48,15 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="keyword">impl</span> <span class="struct">foo</span> <span class="brace">{</span>
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public static">is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
- <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public reference">is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
+ <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public reference">is_not_static</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
<span class="brace">}</span>
<span class="keyword">trait</span> <span class="trait declaration">t</span> <span class="brace">{</span>
<span class="keyword">fn</span> <span class="function associated declaration static trait">t_is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
- <span class="keyword">fn</span> <span class="function associated declaration reference trait">t_is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
+ <span class="keyword">fn</span> <span class="function associated declaration reference trait">t_is_not_static</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
<span class="brace">}</span>
<span class="keyword">impl</span> <span class="trait">t</span> <span class="keyword">for</span> <span class="struct">foo</span> <span class="brace">{</span>
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public static trait">is_static</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
- <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public reference trait">is_not_static</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
+ <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public reference trait">is_not_static</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
<span class="brace">}</span></code></pre> \ No newline at end of file
diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html
index eef5baea9..18045f1f5 100644
--- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html
+++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html
@@ -125,7 +125,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="comment documentation">/// ```sh</span>
<span class="comment documentation">/// echo 1</span>
<span class="comment documentation">/// ```</span>
- <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public reference">foo</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-&gt;</span> <span class="builtin_type">bool</span> <span class="brace">{</span>
+ <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function associated declaration public reference">foo</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-&gt;</span> <span class="builtin_type">bool</span> <span class="brace">{</span>
<span class="bool_literal">true</span>
<span class="brace">}</span>
<span class="brace">}</span>
diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_general.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_general.html
index a97802cbb..9f2b1926b 100644
--- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_general.html
+++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_general.html
@@ -61,11 +61,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="brace">}</span>
<span class="keyword">trait</span> <span class="trait declaration">Bar</span> <span class="brace">{</span>
- <span class="keyword">fn</span> <span class="function associated declaration reference trait">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-&gt;</span> <span class="builtin_type">i32</span><span class="semicolon">;</span>
+ <span class="keyword">fn</span> <span class="function associated declaration reference trait">bar</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-&gt;</span> <span class="builtin_type">i32</span><span class="semicolon">;</span>
<span class="brace">}</span>
<span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> <span class="brace">{</span>
- <span class="keyword">fn</span> <span class="function associated declaration reference trait">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-&gt;</span> <span class="builtin_type">i32</span> <span class="brace">{</span>
+ <span class="keyword">fn</span> <span class="function associated declaration reference trait">bar</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-&gt;</span> <span class="builtin_type">i32</span> <span class="brace">{</span>
<span class="self_keyword reference">self</span><span class="operator">.</span><span class="field">x</span>
<span class="brace">}</span>
<span class="brace">}</span>
@@ -75,11 +75,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="value_param">f</span><span class="operator">.</span><span class="function associated consuming">baz</span><span class="parenthesis">(</span><span class="self_keyword consuming mutable">self</span><span class="parenthesis">)</span>
<span class="brace">}</span>
- <span class="keyword">fn</span> <span class="function associated declaration mutable reference">qux</span><span class="parenthesis">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span>
+ <span class="keyword">fn</span> <span class="function associated declaration mutable reference">qux</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span>
<span class="self_keyword mutable reference">self</span><span class="operator">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span>
<span class="brace">}</span>
- <span class="keyword">fn</span> <span class="function associated declaration reference">quop</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-&gt;</span> <span class="builtin_type">i32</span> <span class="brace">{</span>
+ <span class="keyword">fn</span> <span class="function associated declaration reference">quop</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-&gt;</span> <span class="builtin_type">i32</span> <span class="brace">{</span>
<span class="self_keyword reference">self</span><span class="operator">.</span><span class="field">x</span>
<span class="brace">}</span>
<span class="brace">}</span>
@@ -96,11 +96,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="value_param">f</span><span class="operator">.</span><span class="function associated">baz</span><span class="parenthesis">(</span><span class="self_keyword">self</span><span class="parenthesis">)</span>
<span class="brace">}</span>
- <span class="keyword">fn</span> <span class="function associated declaration mutable reference">qux</span><span class="parenthesis">(</span><span class="operator">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span>
+ <span class="keyword">fn</span> <span class="function associated declaration mutable reference">qux</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="keyword">mut</span> <span class="self_keyword declaration mutable reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span>
<span class="self_keyword mutable reference">self</span><span class="operator">.</span><span class="field">x</span> <span class="operator">=</span> <span class="numeric_literal">0</span><span class="semicolon">;</span>
<span class="brace">}</span>
- <span class="keyword">fn</span> <span class="function associated declaration reference">quop</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-&gt;</span> <span class="builtin_type">u32</span> <span class="brace">{</span>
+ <span class="keyword">fn</span> <span class="function associated declaration reference">quop</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-&gt;</span> <span class="builtin_type">u32</span> <span class="brace">{</span>
<span class="self_keyword reference">self</span><span class="operator">.</span><span class="field">x</span>
<span class="brace">}</span>
<span class="brace">}</span>
diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html
index ced7d22f0..abcd80c28 100644
--- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html
+++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_injection.html
@@ -42,7 +42,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
</style>
-<pre><code><span class="keyword">fn</span> <span class="function declaration">fixture</span><span class="parenthesis">(</span><span class="value_param declaration reference">ra_fixture</span><span class="colon">:</span> <span class="operator">&</span><span class="builtin_type">str</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
+<pre><code><span class="keyword">fn</span> <span class="function declaration">fixture</span><span class="parenthesis">(</span><span class="value_param declaration reference">ra_fixture</span><span class="colon">:</span> <span class="punctuation">&</span><span class="builtin_type">str</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
<span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
<span class="function">fixture</span><span class="parenthesis">(</span><span class="string_literal">r#"</span>
diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_lifetimes.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_lifetimes.html
index 2d85fc8c9..f98e0b1cd 100644
--- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_lifetimes.html
+++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_lifetimes.html
@@ -45,8 +45,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<pre><code>
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="attribute attribute default_library library">derive</span><span class="parenthesis attribute">(</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
<span class="keyword">struct</span> <span class="struct declaration">Foo</span><span class="angle">&lt;</span><span class="lifetime declaration">'a</span><span class="comma">,</span> <span class="lifetime declaration">'b</span><span class="comma">,</span> <span class="lifetime declaration">'c</span><span class="angle">&gt;</span> <span class="keyword">where</span> <span class="lifetime">'a</span><span class="colon">:</span> <span class="lifetime">'a</span><span class="comma">,</span> <span class="lifetime">'static</span><span class="colon">:</span> <span class="lifetime">'static</span> <span class="brace">{</span>
- <span class="field declaration">field</span><span class="colon">:</span> <span class="operator">&</span><span class="lifetime">'a</span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="comma">,</span>
- <span class="field declaration">field2</span><span class="colon">:</span> <span class="operator">&</span><span class="lifetime">'static</span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="comma">,</span>
+ <span class="field declaration">field</span><span class="colon">:</span> <span class="punctuation">&</span><span class="lifetime">'a</span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="comma">,</span>
+ <span class="field declaration">field2</span><span class="colon">:</span> <span class="punctuation">&</span><span class="lifetime">'static</span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="comma">,</span>
<span class="brace">}</span>
<span class="keyword">impl</span><span class="angle">&lt;</span><span class="lifetime declaration">'a</span><span class="angle">&gt;</span> <span class="struct">Foo</span><span class="angle">&lt;</span><span class="lifetime">'_</span><span class="comma">,</span> <span class="lifetime">'a</span><span class="comma">,</span> <span class="lifetime">'static</span><span class="angle">&gt;</span>
<span class="keyword">where</span>
diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html
index c627bc9b0..a626cda3f 100644
--- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html
+++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html
@@ -62,16 +62,16 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">&gt;</span> <span class="parenthesis">(</span>
<span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>panicking<span class="colon">:</span><span class="colon">:</span>panic<span class="parenthesis">(</span><span class="string_literal">"explicit panic"</span><span class="parenthesis">)</span>
<span class="parenthesis">)</span><span class="comma">,</span>
- <span class="parenthesis">(</span><span class="punctuation">$</span>msg<span class="colon">:</span>literal <span class="punctuation">$</span><span class="parenthesis">(</span><span class="comma">,</span><span class="parenthesis">)</span><span class="operator control">?</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">&gt;</span> <span class="parenthesis">(</span>
+ <span class="parenthesis">(</span><span class="punctuation">$</span>msg<span class="colon">:</span>literal <span class="punctuation">$</span><span class="parenthesis">(</span><span class="comma">,</span><span class="parenthesis">)</span><span class="punctuation">?</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">&gt;</span> <span class="parenthesis">(</span>
<span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>panicking<span class="colon">:</span><span class="colon">:</span>panic<span class="parenthesis">(</span><span class="punctuation">$</span>msg<span class="parenthesis">)</span>
<span class="parenthesis">)</span><span class="comma">,</span>
<span class="comment">// Use `panic_str` instead of `panic_display::&lt;&str&gt;` for non_fmt_panic lint.</span>
- <span class="parenthesis">(</span><span class="punctuation">$</span>msg<span class="colon">:</span>expr <span class="punctuation">$</span><span class="parenthesis">(</span><span class="comma">,</span><span class="parenthesis">)</span><span class="operator control">?</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">&gt;</span> <span class="parenthesis">(</span>
+ <span class="parenthesis">(</span><span class="punctuation">$</span>msg<span class="colon">:</span>expr <span class="punctuation">$</span><span class="parenthesis">(</span><span class="comma">,</span><span class="parenthesis">)</span><span class="punctuation">?</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">&gt;</span> <span class="parenthesis">(</span>
<span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>panicking<span class="colon">:</span><span class="colon">:</span>panic_str<span class="parenthesis">(</span><span class="punctuation">$</span>msg<span class="parenthesis">)</span>
<span class="parenthesis">)</span><span class="comma">,</span>
<span class="comment">// Special-case the single-argument case for const_panic.</span>
- <span class="parenthesis">(</span><span class="string_literal">"{}"</span><span class="comma">,</span> <span class="punctuation">$</span>arg<span class="colon">:</span>expr <span class="punctuation">$</span><span class="parenthesis">(</span><span class="comma">,</span><span class="parenthesis">)</span><span class="operator control">?</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">&gt;</span> <span class="parenthesis">(</span>
- <span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>panicking<span class="colon">:</span><span class="colon">:</span>panic_display<span class="parenthesis">(</span><span class="operator">&</span><span class="punctuation">$</span>arg<span class="parenthesis">)</span>
+ <span class="parenthesis">(</span><span class="string_literal">"{}"</span><span class="comma">,</span> <span class="punctuation">$</span>arg<span class="colon">:</span>expr <span class="punctuation">$</span><span class="parenthesis">(</span><span class="comma">,</span><span class="parenthesis">)</span><span class="punctuation">?</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">&gt;</span> <span class="parenthesis">(</span>
+ <span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>panicking<span class="colon">:</span><span class="colon">:</span>panic_display<span class="parenthesis">(</span><span class="punctuation">&</span><span class="punctuation">$</span>arg<span class="parenthesis">)</span>
<span class="parenthesis">)</span><span class="comma">,</span>
<span class="parenthesis">(</span><span class="punctuation">$</span>fmt<span class="colon">:</span>expr<span class="comma">,</span> <span class="punctuation">$</span><span class="parenthesis">(</span><span class="punctuation">$</span>arg<span class="colon">:</span>tt<span class="parenthesis">)</span><span class="punctuation">+</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">&gt;</span> <span class="parenthesis">(</span>
<span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>panicking<span class="colon">:</span><span class="colon">:</span>panic_fmt<span class="parenthesis">(</span><span class="punctuation">$</span>crate<span class="colon">:</span><span class="colon">:</span>const_format_args<span class="punctuation">!</span><span class="parenthesis">(</span><span class="punctuation">$</span>fmt<span class="comma">,</span> <span class="punctuation">$</span><span class="parenthesis">(</span><span class="punctuation">$</span>arg<span class="parenthesis">)</span><span class="punctuation">+</span><span class="parenthesis">)</span><span class="parenthesis">)</span>
diff --git a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html
index 0716bae75..1992bdc6a 100644
--- a/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html
+++ b/src/tools/rust-analyzer/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html
@@ -49,7 +49,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="brace">}</span>
<span class="keyword">macro_rules</span><span class="macro_bang">!</span> <span class="macro declaration">unsafe_deref</span> <span class="brace">{</span>
<span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="operator">=</span><span class="angle">&gt;</span> <span class="brace">{</span>
- <span class="punctuation">*</span><span class="parenthesis">(</span><span class="operator">&</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="keyword">as</span> <span class="punctuation">*</span><span class="keyword">const</span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="parenthesis">)</span>
+ <span class="punctuation">*</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="keyword">as</span> <span class="punctuation">*</span><span class="keyword">const</span> <span class="parenthesis">(</span><span class="parenthesis">)</span><span class="parenthesis">)</span>
<span class="brace">}</span><span class="semicolon">;</span>
<span class="brace">}</span>
<span class="keyword">static</span> <span class="keyword">mut</span> <span class="static declaration mutable unsafe">MUT_GLOBAL</span><span class="colon">:</span> <span class="struct">Struct</span> <span class="operator">=</span> <span class="struct">Struct</span> <span class="brace">{</span> <span class="field">field</span><span class="colon">:</span> <span class="numeric_literal">0</span> <span class="brace">}</span><span class="semicolon">;</span>
@@ -63,7 +63,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="keyword">struct</span> <span class="struct declaration">Struct</span> <span class="brace">{</span> <span class="field declaration">field</span><span class="colon">:</span> <span class="builtin_type">i32</span> <span class="brace">}</span>
<span class="keyword">impl</span> <span class="struct">Struct</span> <span class="brace">{</span>
- <span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function associated declaration reference unsafe">unsafe_method</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
+ <span class="keyword unsafe">unsafe</span> <span class="keyword">fn</span> <span class="function associated declaration reference unsafe">unsafe_method</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
<span class="brace">}</span>
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="builtin_attr attribute library">repr</span><span class="parenthesis attribute">(</span><span class="none attribute">packed</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
@@ -78,11 +78,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="keyword">fn</span> <span class="function declaration">unsafe_trait_bound</span><span class="angle">&lt;</span><span class="type_param declaration">T</span><span class="colon">:</span> <span class="trait">UnsafeTrait</span><span class="angle">&gt;</span><span class="parenthesis">(</span><span class="punctuation">_</span><span class="colon">:</span> <span class="type_param">T</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
<span class="keyword">trait</span> <span class="trait declaration">DoTheAutoref</span> <span class="brace">{</span>
- <span class="keyword">fn</span> <span class="function associated declaration reference trait">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span><span class="semicolon">;</span>
+ <span class="keyword">fn</span> <span class="function associated declaration reference trait">calls_autoref</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span><span class="semicolon">;</span>
<span class="brace">}</span>
<span class="keyword">impl</span> <span class="trait">DoTheAutoref</span> <span class="keyword">for</span> <span class="builtin_type">u16</span> <span class="brace">{</span>
- <span class="keyword">fn</span> <span class="function associated declaration reference trait">calls_autoref</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
+ <span class="keyword">fn</span> <span class="function associated declaration reference trait">calls_autoref</span><span class="parenthesis">(</span><span class="punctuation">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
<span class="brace">}</span>
<span class="keyword">fn</span> <span class="function declaration">main</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
diff --git a/src/tools/rust-analyzer/crates/mbe/Cargo.toml b/src/tools/rust-analyzer/crates/mbe/Cargo.toml
index 5ff3448a1..13cd89010 100644
--- a/src/tools/rust-analyzer/crates/mbe/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/mbe/Cargo.toml
@@ -12,7 +12,7 @@ doctest = false
[dependencies]
cov-mark = "2.0.0-pre.1"
rustc-hash = "1.1.0"
-smallvec = "1.9.0"
+smallvec = "1.10.0"
tracing = "0.1.35"
syntax = { path = "../syntax", version = "0.0.0" }
diff --git a/src/tools/rust-analyzer/crates/mbe/src/benchmark.rs b/src/tools/rust-analyzer/crates/mbe/src/benchmark.rs
index ac691578d..9c92bae6a 100644
--- a/src/tools/rust-analyzer/crates/mbe/src/benchmark.rs
+++ b/src/tools/rust-analyzer/crates/mbe/src/benchmark.rs
@@ -8,7 +8,7 @@ use syntax::{
use test_utils::{bench, bench_fixture, skip_slow_tests};
use crate::{
- parser::{Op, RepeatKind, Separator},
+ parser::{MetaVarKind, Op, RepeatKind, Separator},
syntax_node_to_token_tree, DeclarativeMacro,
};
@@ -111,35 +111,35 @@ fn invocation_fixtures(rules: &FxHashMap<String, DeclarativeMacro>) -> Vec<(Stri
fn collect_from_op(op: &Op, parent: &mut tt::Subtree, seed: &mut usize) {
return match op {
- Op::Var { kind, .. } => match kind.as_ref().map(|it| it.as_str()) {
- Some("ident") => parent.token_trees.push(make_ident("foo")),
- Some("ty") => parent.token_trees.push(make_ident("Foo")),
- Some("tt") => parent.token_trees.push(make_ident("foo")),
- Some("vis") => parent.token_trees.push(make_ident("pub")),
- Some("pat") => parent.token_trees.push(make_ident("foo")),
- Some("path") => parent.token_trees.push(make_ident("foo")),
- Some("literal") => parent.token_trees.push(make_literal("1")),
- Some("expr") => parent.token_trees.push(make_ident("foo")),
- Some("lifetime") => {
+ Op::Var { kind, .. } => match kind.as_ref() {
+ Some(MetaVarKind::Ident) => parent.token_trees.push(make_ident("foo")),
+ Some(MetaVarKind::Ty) => parent.token_trees.push(make_ident("Foo")),
+ Some(MetaVarKind::Tt) => parent.token_trees.push(make_ident("foo")),
+ Some(MetaVarKind::Vis) => parent.token_trees.push(make_ident("pub")),
+ Some(MetaVarKind::Pat) => parent.token_trees.push(make_ident("foo")),
+ Some(MetaVarKind::Path) => parent.token_trees.push(make_ident("foo")),
+ Some(MetaVarKind::Literal) => parent.token_trees.push(make_literal("1")),
+ Some(MetaVarKind::Expr) => parent.token_trees.push(make_ident("foo")),
+ Some(MetaVarKind::Lifetime) => {
parent.token_trees.push(make_punct('\''));
parent.token_trees.push(make_ident("a"));
}
- Some("block") => {
+ Some(MetaVarKind::Block) => {
parent.token_trees.push(make_subtree(tt::DelimiterKind::Brace, None))
}
- Some("item") => {
+ Some(MetaVarKind::Item) => {
parent.token_trees.push(make_ident("fn"));
parent.token_trees.push(make_ident("foo"));
parent.token_trees.push(make_subtree(tt::DelimiterKind::Parenthesis, None));
parent.token_trees.push(make_subtree(tt::DelimiterKind::Brace, None));
}
- Some("meta") => {
+ Some(MetaVarKind::Meta) => {
parent.token_trees.push(make_ident("foo"));
parent.token_trees.push(make_subtree(tt::DelimiterKind::Parenthesis, None));
}
None => (),
- Some(kind) => panic!("Unhandled kind {}", kind),
+ Some(kind) => panic!("Unhandled kind {:?}", kind),
},
Op::Leaf(leaf) => parent.token_trees.push(leaf.clone().into()),
Op::Repeat { tokens, kind, separator } => {
diff --git a/src/tools/rust-analyzer/crates/mbe/src/expander.rs b/src/tools/rust-analyzer/crates/mbe/src/expander.rs
index 1e1bfa550..100ec6bfb 100644
--- a/src/tools/rust-analyzer/crates/mbe/src/expander.rs
+++ b/src/tools/rust-analyzer/crates/mbe/src/expander.rs
@@ -8,7 +8,7 @@ mod transcriber;
use rustc_hash::FxHashMap;
use syntax::SmolStr;
-use crate::{ExpandError, ExpandResult};
+use crate::{parser::MetaVarKind, ExpandError, ExpandResult};
pub(crate) fn expand_rules(
rules: &[crate::Rule],
@@ -104,6 +104,7 @@ enum Binding {
Fragment(Fragment),
Nested(Vec<Binding>),
Empty,
+ Missing(MetaVarKind),
}
#[derive(Debug, Clone, PartialEq, Eq)]
diff --git a/src/tools/rust-analyzer/crates/mbe/src/expander/matcher.rs b/src/tools/rust-analyzer/crates/mbe/src/expander/matcher.rs
index c1aa14d6b..3f656df25 100644
--- a/src/tools/rust-analyzer/crates/mbe/src/expander/matcher.rs
+++ b/src/tools/rust-analyzer/crates/mbe/src/expander/matcher.rs
@@ -66,7 +66,7 @@ use syntax::SmolStr;
use crate::{
expander::{Binding, Bindings, ExpandResult, Fragment},
- parser::{Op, RepeatKind, Separator},
+ parser::{MetaVarKind, Op, RepeatKind, Separator},
tt_iter::TtIter,
ExpandError, MetaTemplate,
};
@@ -119,6 +119,7 @@ pub(super) fn match_(pattern: &MetaTemplate, input: &tt::Subtree) -> Match {
.map(|it| match it {
Binding::Fragment(_) => 1,
Binding::Empty => 1,
+ Binding::Missing(_) => 1,
Binding::Nested(it) => count(it.iter()),
})
.sum()
@@ -130,6 +131,7 @@ enum BindingKind {
Empty(SmolStr),
Optional(SmolStr),
Fragment(SmolStr, Fragment),
+ Missing(SmolStr, MetaVarKind),
Nested(usize, usize),
}
@@ -190,6 +192,10 @@ impl BindingsBuilder {
.push(LinkNode::Node(Rc::new(BindingKind::Fragment(var.clone(), fragment))));
}
+ fn push_missing(&mut self, idx: &mut BindingsIdx, var: &SmolStr, kind: MetaVarKind) {
+ self.nodes[idx.0].push(LinkNode::Node(Rc::new(BindingKind::Missing(var.clone(), kind))));
+ }
+
fn push_nested(&mut self, parent: &mut BindingsIdx, child: &BindingsIdx) {
let BindingsIdx(idx, nidx) = self.copy(child);
self.nodes[parent.0].push(LinkNode::Node(Rc::new(BindingKind::Nested(idx, nidx))));
@@ -203,17 +209,16 @@ impl BindingsBuilder {
}
fn build(self, idx: &BindingsIdx) -> Bindings {
- let mut bindings = Bindings::default();
- self.build_inner(&mut bindings, &self.nodes[idx.0]);
- bindings
+ self.build_inner(&self.nodes[idx.0])
}
- fn build_inner(&self, bindings: &mut Bindings, link_nodes: &[LinkNode<Rc<BindingKind>>]) {
+ fn build_inner(&self, link_nodes: &[LinkNode<Rc<BindingKind>>]) -> Bindings {
+ let mut bindings = Bindings::default();
let mut nodes = Vec::new();
self.collect_nodes(link_nodes, &mut nodes);
for cmd in nodes {
- match &**cmd {
+ match cmd {
BindingKind::Empty(name) => {
bindings.push_empty(name);
}
@@ -223,6 +228,9 @@ impl BindingsBuilder {
BindingKind::Fragment(name, fragment) => {
bindings.inner.insert(name.clone(), Binding::Fragment(fragment.clone()));
}
+ BindingKind::Missing(name, kind) => {
+ bindings.inner.insert(name.clone(), Binding::Missing(*kind));
+ }
BindingKind::Nested(idx, nested_idx) => {
let mut nested_nodes = Vec::new();
self.collect_nested(*idx, *nested_idx, &mut nested_nodes);
@@ -246,13 +254,15 @@ impl BindingsBuilder {
}
}
}
+
+ bindings
}
fn collect_nested_ref<'a>(
&'a self,
id: usize,
len: usize,
- nested_refs: &mut Vec<&'a Vec<LinkNode<Rc<BindingKind>>>>,
+ nested_refs: &mut Vec<&'a [LinkNode<Rc<BindingKind>>]>,
) {
self.nested[id].iter().take(len).for_each(|it| match it {
LinkNode::Node(id) => nested_refs.push(&self.nodes[*id]),
@@ -262,26 +272,16 @@ impl BindingsBuilder {
fn collect_nested(&self, idx: usize, nested_idx: usize, nested: &mut Vec<Bindings>) {
let last = &self.nodes[idx];
- let mut nested_refs = Vec::new();
+ let mut nested_refs: Vec<&[_]> = Vec::new();
self.nested[nested_idx].iter().for_each(|it| match *it {
LinkNode::Node(idx) => nested_refs.push(&self.nodes[idx]),
LinkNode::Parent { idx, len } => self.collect_nested_ref(idx, len, &mut nested_refs),
});
nested_refs.push(last);
-
- nested_refs.into_iter().for_each(|iter| {
- let mut child_bindings = Bindings::default();
- self.build_inner(&mut child_bindings, iter);
- nested.push(child_bindings)
- })
+ nested.extend(nested_refs.into_iter().map(|iter| self.build_inner(iter)));
}
- fn collect_nodes_ref<'a>(
- &'a self,
- id: usize,
- len: usize,
- nodes: &mut Vec<&'a Rc<BindingKind>>,
- ) {
+ fn collect_nodes_ref<'a>(&'a self, id: usize, len: usize, nodes: &mut Vec<&'a BindingKind>) {
self.nodes[id].iter().take(len).for_each(|it| match it {
LinkNode::Node(it) => nodes.push(it),
LinkNode::Parent { idx, len } => self.collect_nodes_ref(*idx, *len, nodes),
@@ -291,7 +291,7 @@ impl BindingsBuilder {
fn collect_nodes<'a>(
&'a self,
link_nodes: &'a [LinkNode<Rc<BindingKind>>],
- nodes: &mut Vec<&'a Rc<BindingKind>>,
+ nodes: &mut Vec<&'a BindingKind>,
) {
link_nodes.iter().for_each(|it| match it {
LinkNode::Node(it) => nodes.push(it),
@@ -386,10 +386,10 @@ fn match_loop_inner<'t>(
let op = match item.dot.peek() {
None => {
// We are at or past the end of the matcher of `item`.
- if item.up.is_some() {
+ if let Some(up) = &item.up {
if item.sep_parsed.is_none() {
// Get the `up` matcher
- let mut new_pos = *item.up.clone().unwrap();
+ let mut new_pos = (**up).clone();
new_pos.bindings = bindings_builder.copy(&new_pos.bindings);
// Add matches from this repetition to the `matches` of `up`
bindings_builder.push_nested(&mut new_pos.bindings, &item.bindings);
@@ -402,7 +402,7 @@ fn match_loop_inner<'t>(
// Check if we need a separator.
// We check the separator one by one
- let sep_idx = *item.sep_parsed.as_ref().unwrap_or(&0);
+ let sep_idx = item.sep_parsed.unwrap_or(0);
let sep_len = item.sep.as_ref().map_or(0, Separator::tt_count);
if item.sep.is_some() && sep_idx != sep_len {
let sep = item.sep.as_ref().unwrap();
@@ -467,9 +467,9 @@ fn match_loop_inner<'t>(
}
}
OpDelimited::Op(Op::Var { kind, name, .. }) => {
- if let Some(kind) = kind {
+ if let &Some(kind) = kind {
let mut fork = src.clone();
- let match_res = match_meta_var(kind.as_str(), &mut fork);
+ let match_res = match_meta_var(kind, &mut fork);
match match_res.err {
None => {
// Some meta variables are optional (e.g. vis)
@@ -484,8 +484,15 @@ fn match_loop_inner<'t>(
}
Some(err) => {
res.add_err(err);
- if let Some(fragment) = match_res.value {
- bindings_builder.push_fragment(&mut item.bindings, name, fragment);
+ match match_res.value {
+ Some(fragment) => bindings_builder.push_fragment(
+ &mut item.bindings,
+ name,
+ fragment,
+ ),
+ None => {
+ bindings_builder.push_missing(&mut item.bindings, name, kind)
+ }
}
item.is_error = true;
error_items.push(item);
@@ -677,20 +684,20 @@ fn match_leaf(lhs: &tt::Leaf, src: &mut TtIter<'_>) -> Result<(), ExpandError> {
}
}
-fn match_meta_var(kind: &str, input: &mut TtIter<'_>) -> ExpandResult<Option<Fragment>> {
+fn match_meta_var(kind: MetaVarKind, input: &mut TtIter<'_>) -> ExpandResult<Option<Fragment>> {
let fragment = match kind {
- "path" => parser::PrefixEntryPoint::Path,
- "ty" => parser::PrefixEntryPoint::Ty,
+ MetaVarKind::Path => parser::PrefixEntryPoint::Path,
+ MetaVarKind::Ty => parser::PrefixEntryPoint::Ty,
// FIXME: These two should actually behave differently depending on the edition.
//
// https://doc.rust-lang.org/edition-guide/rust-2021/or-patterns-macro-rules.html
- "pat" | "pat_param" => parser::PrefixEntryPoint::Pat,
- "stmt" => parser::PrefixEntryPoint::Stmt,
- "block" => parser::PrefixEntryPoint::Block,
- "meta" => parser::PrefixEntryPoint::MetaItem,
- "item" => parser::PrefixEntryPoint::Item,
- "vis" => parser::PrefixEntryPoint::Vis,
- "expr" => {
+ MetaVarKind::Pat | MetaVarKind::PatParam => parser::PrefixEntryPoint::Pat,
+ MetaVarKind::Stmt => parser::PrefixEntryPoint::Stmt,
+ MetaVarKind::Block => parser::PrefixEntryPoint::Block,
+ MetaVarKind::Meta => parser::PrefixEntryPoint::MetaItem,
+ MetaVarKind::Item => parser::PrefixEntryPoint::Item,
+ MetaVarKind::Vis => parser::PrefixEntryPoint::Vis,
+ MetaVarKind::Expr => {
// `expr` should not match underscores.
// HACK: Macro expansion should not be done using "rollback and try another alternative".
// rustc [explicitly checks the next token][0].
@@ -707,17 +714,17 @@ fn match_meta_var(kind: &str, input: &mut TtIter<'_>) -> ExpandResult<Option<Fra
}
_ => {
let tt_result = match kind {
- "ident" => input
+ MetaVarKind::Ident => input
.expect_ident()
.map(|ident| tt::Leaf::from(ident.clone()).into())
.map_err(|()| ExpandError::binding_error("expected ident")),
- "tt" => input
+ MetaVarKind::Tt => input
.expect_tt()
.map_err(|()| ExpandError::binding_error("expected token tree")),
- "lifetime" => input
+ MetaVarKind::Lifetime => input
.expect_lifetime()
.map_err(|()| ExpandError::binding_error("expected lifetime")),
- "literal" => {
+ MetaVarKind::Literal => {
let neg = input.eat_char('-');
input
.expect_literal()
diff --git a/src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs b/src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs
index 7bcc84740..cbb59ab8e 100644
--- a/src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs
+++ b/src/tools/rust-analyzer/crates/mbe/src/expander/transcriber.rs
@@ -6,7 +6,7 @@ use tt::{Delimiter, Subtree};
use crate::{
expander::{Binding, Bindings, Fragment},
- parser::{Op, RepeatKind, Separator},
+ parser::{MetaVarKind, Op, RepeatKind, Separator},
ExpandError, ExpandResult, MetaTemplate,
};
@@ -15,7 +15,7 @@ impl Bindings {
self.inner.contains_key(name)
}
- fn get(&self, name: &str, nesting: &mut [NestingState]) -> Result<&Fragment, ExpandError> {
+ fn get(&self, name: &str, nesting: &mut [NestingState]) -> Result<Fragment, ExpandError> {
macro_rules! binding_err {
($($arg:tt)*) => { ExpandError::binding_error(format!($($arg)*)) };
}
@@ -26,6 +26,7 @@ impl Bindings {
nesting_state.hit = true;
b = match b {
Binding::Fragment(_) => break,
+ Binding::Missing(_) => break,
Binding::Nested(bs) => bs.get(nesting_state.idx).ok_or_else(|| {
nesting_state.at_end = true;
binding_err!("could not find nested binding `{name}`")
@@ -37,7 +38,55 @@ impl Bindings {
};
}
match b {
- Binding::Fragment(it) => Ok(it),
+ Binding::Fragment(it) => Ok(it.clone()),
+ // emit some reasonable default expansion for missing bindings,
+ // this gives better recovery than emitting the `$fragment-name` verbatim
+ Binding::Missing(it) => Ok(match it {
+ MetaVarKind::Stmt => {
+ Fragment::Tokens(tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct {
+ id: tt::TokenId::unspecified(),
+ char: ';',
+ spacing: tt::Spacing::Alone,
+ })))
+ }
+ MetaVarKind::Block => Fragment::Tokens(tt::TokenTree::Subtree(tt::Subtree {
+ delimiter: Some(tt::Delimiter {
+ id: tt::TokenId::unspecified(),
+ kind: tt::DelimiterKind::Brace,
+ }),
+ token_trees: vec![],
+ })),
+ // FIXME: Meta and Item should get proper defaults
+ MetaVarKind::Meta | MetaVarKind::Item | MetaVarKind::Tt | MetaVarKind::Vis => {
+ Fragment::Tokens(tt::TokenTree::Subtree(tt::Subtree {
+ delimiter: None,
+ token_trees: vec![],
+ }))
+ }
+ MetaVarKind::Path
+ | MetaVarKind::Ty
+ | MetaVarKind::Pat
+ | MetaVarKind::PatParam
+ | MetaVarKind::Expr
+ | MetaVarKind::Ident => {
+ Fragment::Tokens(tt::TokenTree::Leaf(tt::Leaf::Ident(tt::Ident {
+ text: SmolStr::new_inline("missing"),
+ id: tt::TokenId::unspecified(),
+ })))
+ }
+ MetaVarKind::Lifetime => {
+ Fragment::Tokens(tt::TokenTree::Leaf(tt::Leaf::Ident(tt::Ident {
+ text: SmolStr::new_inline("'missing"),
+ id: tt::TokenId::unspecified(),
+ })))
+ }
+ MetaVarKind::Literal => {
+ Fragment::Tokens(tt::TokenTree::Leaf(tt::Leaf::Ident(tt::Ident {
+ text: SmolStr::new_inline("\"missing\""),
+ id: tt::TokenId::unspecified(),
+ })))
+ }
+ }),
Binding::Nested(_) => {
Err(binding_err!("expected simple binding, found nested binding `{name}`"))
}
@@ -157,7 +206,7 @@ fn expand_var(ctx: &mut ExpandCtx<'_>, v: &SmolStr, id: tt::TokenId) -> ExpandRe
} else {
ctx.bindings.get(v, &mut ctx.nesting).map_or_else(
|e| ExpandResult { value: Fragment::Tokens(tt::TokenTree::empty()), err: Some(e) },
- |b| ExpandResult::ok(b.clone()),
+ |it| ExpandResult::ok(it),
)
}
}
diff --git a/src/tools/rust-analyzer/crates/mbe/src/lib.rs b/src/tools/rust-analyzer/crates/mbe/src/lib.rs
index 79da84f4a..c4f0fa20d 100644
--- a/src/tools/rust-analyzer/crates/mbe/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/mbe/src/lib.rs
@@ -21,7 +21,7 @@ mod token_map;
use std::fmt;
use crate::{
- parser::{MetaTemplate, Op},
+ parser::{MetaTemplate, MetaVarKind, Op},
tt_iter::TtIter,
};
@@ -291,9 +291,9 @@ fn validate(pattern: &MetaTemplate) -> Result<(), ParseError> {
// Checks that no repetition which could match an empty token
// https://github.com/rust-lang/rust/blob/a58b1ed44f5e06976de2bdc4d7dc81c36a96934f/src/librustc_expand/mbe/macro_rules.rs#L558
let lsh_is_empty_seq = separator.is_none() && subtree.iter().all(|child_op| {
- match child_op {
+ match *child_op {
// vis is optional
- Op::Var { kind: Some(kind), .. } => kind == "vis",
+ Op::Var { kind: Some(kind), .. } => kind == MetaVarKind::Vis,
Op::Repeat {
kind: parser::RepeatKind::ZeroOrMore | parser::RepeatKind::ZeroOrOne,
..
diff --git a/src/tools/rust-analyzer/crates/mbe/src/parser.rs b/src/tools/rust-analyzer/crates/mbe/src/parser.rs
index acb4be584..351c359b7 100644
--- a/src/tools/rust-analyzer/crates/mbe/src/parser.rs
+++ b/src/tools/rust-analyzer/crates/mbe/src/parser.rs
@@ -50,7 +50,7 @@ impl MetaTemplate {
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum Op {
- Var { name: SmolStr, kind: Option<SmolStr>, id: tt::TokenId },
+ Var { name: SmolStr, kind: Option<MetaVarKind>, id: tt::TokenId },
Ignore { name: SmolStr, id: tt::TokenId },
Index { depth: u32 },
Repeat { tokens: MetaTemplate, kind: RepeatKind, separator: Option<Separator> },
@@ -65,6 +65,24 @@ pub(crate) enum RepeatKind {
ZeroOrOne,
}
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+pub(crate) enum MetaVarKind {
+ Path,
+ Ty,
+ Pat,
+ PatParam,
+ Stmt,
+ Block,
+ Meta,
+ Item,
+ Vis,
+ Expr,
+ Ident,
+ Tt,
+ Lifetime,
+ Literal,
+}
+
#[derive(Clone, Debug, Eq)]
pub(crate) enum Separator {
Literal(tt::Literal),
@@ -179,13 +197,30 @@ fn next_op<'a>(first: &tt::TokenTree, src: &mut TtIter<'a>, mode: Mode) -> Resul
Ok(res)
}
-fn eat_fragment_kind(src: &mut TtIter<'_>, mode: Mode) -> Result<Option<SmolStr>, ParseError> {
+fn eat_fragment_kind(src: &mut TtIter<'_>, mode: Mode) -> Result<Option<MetaVarKind>, ParseError> {
if let Mode::Pattern = mode {
src.expect_char(':').map_err(|()| ParseError::unexpected("missing fragment specifier"))?;
let ident = src
.expect_ident()
.map_err(|()| ParseError::unexpected("missing fragment specifier"))?;
- return Ok(Some(ident.text.clone()));
+ let kind = match ident.text.as_str() {
+ "path" => MetaVarKind::Path,
+ "ty" => MetaVarKind::Ty,
+ "pat" => MetaVarKind::Pat,
+ "pat_param" => MetaVarKind::PatParam,
+ "stmt" => MetaVarKind::Stmt,
+ "block" => MetaVarKind::Block,
+ "meta" => MetaVarKind::Meta,
+ "item" => MetaVarKind::Item,
+ "vis" => MetaVarKind::Vis,
+ "expr" => MetaVarKind::Expr,
+ "ident" => MetaVarKind::Ident,
+ "tt" => MetaVarKind::Tt,
+ "lifetime" => MetaVarKind::Lifetime,
+ "literal" => MetaVarKind::Literal,
+ _ => return Ok(None),
+ };
+ return Ok(Some(kind));
};
Ok(None)
}
diff --git a/src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml b/src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml
index 85a1c13fe..54879c187 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/proc-macro-api/Cargo.toml
@@ -19,7 +19,7 @@ object = { version = "0.29.0", default-features = false, features = [
] }
serde = { version = "1.0.137", features = ["derive"] }
serde_json = { version = "1.0.81", features = ["unbounded_depth"] }
-tracing = "0.1.35"
+tracing = "0.1.37"
memmap2 = "0.5.4"
snap = "1.0.5"
diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_sysroot/mod.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_sysroot/mod.rs
index 44712f419..243972b04 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_sysroot/mod.rs
+++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/abi_sysroot/mod.rs
@@ -11,6 +11,8 @@ use proc_macro_api::ProcMacroKind;
use super::PanicMessage;
+pub use ra_server::TokenStream;
+
pub(crate) struct Abi {
exported_macros: Vec<proc_macro::bridge::client::ProcMacro>,
}
diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/mod.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/mod.rs
index f7d3a3091..2f854bc15 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/mod.rs
+++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/abis/mod.rs
@@ -32,8 +32,8 @@ mod abi_sysroot;
include!(concat!(env!("OUT_DIR"), "/rustc_version.rs"));
// Used by `test/utils.rs`
-#[cfg(test)]
-pub(crate) use abi_1_63::TokenStream as TestTokenStream;
+#[cfg(all(test, feature = "sysroot-abi"))]
+pub(crate) use abi_sysroot::TokenStream as TestTokenStream;
use super::dylib::LoadProcMacroDylibError;
pub(crate) use abi_1_58::Abi as Abi_1_58;
@@ -144,3 +144,10 @@ impl Abi {
}
}
}
+
+#[test]
+fn test_version_check() {
+ let path = paths::AbsPathBuf::assert(crate::proc_macro_test_dylib_path());
+ let info = proc_macro_api::read_dylib_info(&path).unwrap();
+ assert!(info.version.1 >= 50);
+}
diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs
index 3679bfc43..72a2dfe72 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs
@@ -20,6 +20,8 @@
mod dylib;
mod abis;
+pub mod cli;
+
use std::{
collections::{hash_map::Entry, HashMap},
env,
@@ -149,7 +151,10 @@ impl EnvSnapshot {
}
}
-pub mod cli;
+#[cfg(all(feature = "sysroot-abi", test))]
+mod tests;
#[cfg(test)]
-mod tests;
+pub fn proc_macro_test_dylib_path() -> std::path::PathBuf {
+ proc_macro_test::PROC_MACRO_TEST_LOCATION.into()
+}
diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs
index 6339d56d0..b46cdddcf 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs
+++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs
@@ -2,10 +2,10 @@
#[macro_use]
mod utils;
-use expect_test::expect;
-use paths::AbsPathBuf;
use utils::*;
+use expect_test::expect;
+
#[test]
fn test_derive_empty() {
assert_expand("DeriveEmpty", r#"struct S;"#, expect![[r#"SUBTREE $"#]]);
@@ -157,10 +157,3 @@ fn list_test_macros() {
DeriveError [CustomDerive]"#]]
.assert_eq(&res);
}
-
-#[test]
-fn test_version_check() {
- let path = AbsPathBuf::assert(fixtures::proc_macro_test_dylib_path());
- let info = proc_macro_api::read_dylib_info(&path).unwrap();
- assert!(info.version.1 >= 50);
-}
diff --git a/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs b/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs
index f881fe868..44b1b6588 100644
--- a/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs
+++ b/src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/utils.rs
@@ -1,15 +1,9 @@
//! utils used in proc-macro tests
-use crate::dylib;
-use crate::ProcMacroSrv;
use expect_test::Expect;
use std::str::FromStr;
-pub mod fixtures {
- pub fn proc_macro_test_dylib_path() -> std::path::PathBuf {
- proc_macro_test::PROC_MACRO_TEST_LOCATION.into()
- }
-}
+use crate::{dylib, proc_macro_test_dylib_path, ProcMacroSrv};
fn parse_string(code: &str) -> Option<crate::abis::TestTokenStream> {
// This is a bit strange. We need to parse a string into a token stream into
@@ -30,7 +24,7 @@ pub fn assert_expand_attr(macro_name: &str, ra_fixture: &str, attr_args: &str, e
}
fn assert_expand_impl(macro_name: &str, input: &str, attr: Option<&str>, expect: Expect) {
- let path = fixtures::proc_macro_test_dylib_path();
+ let path = proc_macro_test_dylib_path();
let expander = dylib::Expander::new(&path).unwrap();
let fixture = parse_string(input).unwrap();
let attr = attr.map(|attr| parse_string(attr).unwrap().into_subtree());
@@ -40,7 +34,7 @@ fn assert_expand_impl(macro_name: &str, input: &str, attr: Option<&str>, expect:
}
pub(crate) fn list() -> Vec<String> {
- let dylib_path = fixtures::proc_macro_test_dylib_path();
+ let dylib_path = proc_macro_test_dylib_path();
let mut srv = ProcMacroSrv::default();
let res = srv.list_macros(&dylib_path).unwrap();
res.into_iter().map(|(name, kind)| format!("{} [{:?}]", name, kind)).collect()
diff --git a/src/tools/rust-analyzer/crates/profile/Cargo.toml b/src/tools/rust-analyzer/crates/profile/Cargo.toml
index 0b78a45a2..5697aea96 100644
--- a/src/tools/rust-analyzer/crates/profile/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/profile/Cargo.toml
@@ -10,9 +10,9 @@ rust-version = "1.57"
doctest = false
[dependencies]
-once_cell = "1.12.0"
+once_cell = "1.15.0"
cfg-if = "1.0.0"
-libc = "0.2.126"
+libc = "0.2.135"
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
countme = { version = "3.0.1", features = ["enable"] }
jemalloc-ctl = { version = "0.5.0", package = "tikv-jemalloc-ctl", optional = true }
diff --git a/src/tools/rust-analyzer/crates/project-model/Cargo.toml b/src/tools/rust-analyzer/crates/project-model/Cargo.toml
index bc75d6faa..cf9868740 100644
--- a/src/tools/rust-analyzer/crates/project-model/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/project-model/Cargo.toml
@@ -13,11 +13,10 @@ doctest = false
tracing = "0.1.35"
rustc-hash = "1.1.0"
cargo_metadata = "0.15.0"
-semver = "1.0.10"
+semver = "1.0.14"
serde = { version = "1.0.137", features = ["derive"] }
-serde_json = "1.0.81"
-anyhow = "1.0.57"
-expect-test = "1.4.0"
+serde_json = "1.0.86"
+anyhow = "1.0.62"
la-arena = { version = "0.3.0", path = "../../lib/la-arena" }
cfg = { path = "../cfg", version = "0.0.0" }
@@ -26,3 +25,6 @@ toolchain = { path = "../toolchain", version = "0.0.0" }
paths = { path = "../paths", version = "0.0.0" }
stdx = { path = "../stdx", version = "0.0.0" }
profile = { path = "../profile", version = "0.0.0" }
+
+[dev-dependencies]
+expect-test = "1.4.0"
diff --git a/src/tools/rust-analyzer/crates/project-model/src/build_scripts.rs b/src/tools/rust-analyzer/crates/project-model/src/build_scripts.rs
index 84e772d16..a26a7c57a 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/build_scripts.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/build_scripts.rs
@@ -6,7 +6,12 @@
//! This module implements this second part. We use "build script" terminology
//! here, but it covers procedural macros as well.
-use std::{cell::RefCell, io, path::PathBuf, process::Command};
+use std::{
+ cell::RefCell,
+ io, mem,
+ path::{self, PathBuf},
+ process::Command,
+};
use cargo_metadata::{camino::Utf8Path, Message};
use la_arena::ArenaMap;
@@ -15,11 +20,14 @@ use rustc_hash::FxHashMap;
use semver::Version;
use serde::Deserialize;
-use crate::{cfg_flag::CfgFlag, CargoConfig, CargoWorkspace, Package};
+use crate::{
+ cfg_flag::CfgFlag, CargoConfig, CargoFeatures, CargoWorkspace, InvocationLocation,
+ InvocationStrategy, Package,
+};
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct WorkspaceBuildScripts {
- outputs: ArenaMap<Package, Option<BuildScriptOutput>>,
+ outputs: ArenaMap<Package, BuildScriptOutput>,
error: Option<String>,
}
@@ -38,43 +46,71 @@ pub(crate) struct BuildScriptOutput {
pub(crate) proc_macro_dylib_path: Option<AbsPathBuf>,
}
+impl BuildScriptOutput {
+ fn is_unchanged(&self) -> bool {
+ self.cfgs.is_empty()
+ && self.envs.is_empty()
+ && self.out_dir.is_none()
+ && self.proc_macro_dylib_path.is_none()
+ }
+}
+
impl WorkspaceBuildScripts {
- fn build_command(config: &CargoConfig) -> Command {
- if let Some([program, args @ ..]) = config.run_build_script_command.as_deref() {
- let mut cmd = Command::new(program);
- cmd.args(args);
- return cmd;
- }
+ fn build_command(config: &CargoConfig) -> io::Result<Command> {
+ let mut cmd = match config.run_build_script_command.as_deref() {
+ Some([program, args @ ..]) => {
+ let mut cmd = Command::new(program);
+ cmd.args(args);
+ cmd
+ }
+ _ => {
+ let mut cmd = Command::new(toolchain::cargo());
- let mut cmd = Command::new(toolchain::cargo());
+ cmd.args(&["check", "--quiet", "--workspace", "--message-format=json"]);
- cmd.args(&["check", "--quiet", "--workspace", "--message-format=json"]);
+ // --all-targets includes tests, benches and examples in addition to the
+ // default lib and bins. This is an independent concept from the --targets
+ // flag below.
+ cmd.arg("--all-targets");
- // --all-targets includes tests, benches and examples in addition to the
- // default lib and bins. This is an independent concept from the --targets
- // flag below.
- cmd.arg("--all-targets");
+ if let Some(target) = &config.target {
+ cmd.args(&["--target", target]);
+ }
- if let Some(target) = &config.target {
- cmd.args(&["--target", target]);
- }
+ match &config.features {
+ CargoFeatures::All => {
+ cmd.arg("--all-features");
+ }
+ CargoFeatures::Selected { features, no_default_features } => {
+ if *no_default_features {
+ cmd.arg("--no-default-features");
+ }
+ if !features.is_empty() {
+ cmd.arg("--features");
+ cmd.arg(features.join(" "));
+ }
+ }
+ }
- if config.all_features {
- cmd.arg("--all-features");
- } else {
- if config.no_default_features {
- cmd.arg("--no-default-features");
- }
- if !config.features.is_empty() {
- cmd.arg("--features");
- cmd.arg(config.features.join(" "));
+ cmd
}
+ };
+
+ cmd.envs(&config.extra_env);
+ if config.wrap_rustc_in_build_scripts {
+ // Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
+ // that to compile only proc macros and build scripts during the initial
+ // `cargo check`.
+ let myself = std::env::current_exe()?;
+ cmd.env("RUSTC_WRAPPER", myself);
+ cmd.env("RA_RUSTC_WRAPPER", "1");
}
- cmd
+ Ok(cmd)
}
- pub(crate) fn run(
+ /// Runs the build scripts for the given workspace
+ pub(crate) fn run_for_workspace(
config: &CargoConfig,
workspace: &CargoWorkspace,
progress: &dyn Fn(String),
@@ -82,15 +118,23 @@ impl WorkspaceBuildScripts {
) -> io::Result<WorkspaceBuildScripts> {
const RUST_1_62: Version = Version::new(1, 62, 0);
- match Self::run_(Self::build_command(config), config, workspace, progress) {
+ let current_dir = match &config.invocation_location {
+ InvocationLocation::Root(root) if config.run_build_script_command.is_some() => {
+ root.as_path()
+ }
+ _ => &workspace.workspace_root(),
+ }
+ .as_ref();
+
+ match Self::run_per_ws(Self::build_command(config)?, workspace, current_dir, progress) {
Ok(WorkspaceBuildScripts { error: Some(error), .. })
if toolchain.as_ref().map_or(false, |it| *it >= RUST_1_62) =>
{
// building build scripts failed, attempt to build with --keep-going so
// that we potentially get more build data
- let mut cmd = Self::build_command(config);
+ let mut cmd = Self::build_command(config)?;
cmd.args(&["-Z", "unstable-options", "--keep-going"]).env("RUSTC_BOOTSTRAP", "1");
- let mut res = Self::run_(cmd, config, workspace, progress)?;
+ let mut res = Self::run_per_ws(cmd, workspace, current_dir, progress)?;
res.error = Some(error);
Ok(res)
}
@@ -98,23 +142,90 @@ impl WorkspaceBuildScripts {
}
}
- fn run_(
- mut cmd: Command,
+ /// Runs the build scripts by invoking the configured command *once*.
+ /// This populates the outputs for all passed in workspaces.
+ pub(crate) fn run_once(
config: &CargoConfig,
- workspace: &CargoWorkspace,
+ workspaces: &[&CargoWorkspace],
progress: &dyn Fn(String),
- ) -> io::Result<WorkspaceBuildScripts> {
- if config.wrap_rustc_in_build_scripts {
- // Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
- // that to compile only proc macros and build scripts during the initial
- // `cargo check`.
- let myself = std::env::current_exe()?;
- cmd.env("RUSTC_WRAPPER", myself);
- cmd.env("RA_RUSTC_WRAPPER", "1");
+ ) -> io::Result<Vec<WorkspaceBuildScripts>> {
+ assert_eq!(config.invocation_strategy, InvocationStrategy::Once);
+
+ let current_dir = match &config.invocation_location {
+ InvocationLocation::Root(root) => root,
+ InvocationLocation::Workspace => {
+ return Err(io::Error::new(
+ io::ErrorKind::Other,
+ "Cannot run build scripts from workspace with invocation strategy `once`",
+ ))
+ }
+ };
+ let cmd = Self::build_command(config)?;
+ // NB: Cargo.toml could have been modified between `cargo metadata` and
+ // `cargo check`. We shouldn't assume that package ids we see here are
+ // exactly those from `config`.
+ let mut by_id = FxHashMap::default();
+ // some workspaces might depend on the same crates, so we need to duplicate the outputs
+ // to those collisions
+ let mut collisions = Vec::new();
+ let mut res: Vec<_> = workspaces
+ .iter()
+ .enumerate()
+ .map(|(idx, workspace)| {
+ let mut res = WorkspaceBuildScripts::default();
+ for package in workspace.packages() {
+ res.outputs.insert(package, BuildScriptOutput::default());
+ if by_id.contains_key(&workspace[package].id) {
+ collisions.push((&workspace[package].id, idx, package));
+ } else {
+ by_id.insert(workspace[package].id.clone(), (package, idx));
+ }
+ }
+ res
+ })
+ .collect();
+
+ let errors = Self::run_command(
+ cmd,
+ current_dir.as_path().as_ref(),
+ |package, cb| {
+ if let Some(&(package, workspace)) = by_id.get(package) {
+ cb(&workspaces[workspace][package].name, &mut res[workspace].outputs[package]);
+ }
+ },
+ progress,
+ )?;
+ res.iter_mut().for_each(|it| it.error = errors.clone());
+ collisions.into_iter().for_each(|(id, workspace, package)| {
+ if let Some(&(p, w)) = by_id.get(id) {
+ res[workspace].outputs[package] = res[w].outputs[p].clone();
+ }
+ });
+
+ if tracing::enabled!(tracing::Level::INFO) {
+ for (idx, workspace) in workspaces.iter().enumerate() {
+ for package in workspace.packages() {
+ let package_build_data = &mut res[idx].outputs[package];
+ if !package_build_data.is_unchanged() {
+ tracing::info!(
+ "{}: {:?}",
+ workspace[package].manifest.parent().display(),
+ package_build_data,
+ );
+ }
+ }
+ }
}
- cmd.current_dir(workspace.workspace_root());
+ Ok(res)
+ }
+ fn run_per_ws(
+ cmd: Command,
+ workspace: &CargoWorkspace,
+ current_dir: &path::Path,
+ progress: &dyn Fn(String),
+ ) -> io::Result<WorkspaceBuildScripts> {
let mut res = WorkspaceBuildScripts::default();
let outputs = &mut res.outputs;
// NB: Cargo.toml could have been modified between `cargo metadata` and
@@ -122,10 +233,46 @@ impl WorkspaceBuildScripts {
// exactly those from `config`.
let mut by_id: FxHashMap<String, Package> = FxHashMap::default();
for package in workspace.packages() {
- outputs.insert(package, None);
+ outputs.insert(package, BuildScriptOutput::default());
by_id.insert(workspace[package].id.clone(), package);
}
+ res.error = Self::run_command(
+ cmd,
+ current_dir,
+ |package, cb| {
+ if let Some(&package) = by_id.get(package) {
+ cb(&workspace[package].name, &mut outputs[package]);
+ }
+ },
+ progress,
+ )?;
+
+ if tracing::enabled!(tracing::Level::INFO) {
+ for package in workspace.packages() {
+ let package_build_data = &mut outputs[package];
+ if !package_build_data.is_unchanged() {
+ tracing::info!(
+ "{}: {:?}",
+ workspace[package].manifest.parent().display(),
+ package_build_data,
+ );
+ }
+ }
+ }
+
+ Ok(res)
+ }
+
+ fn run_command(
+ mut cmd: Command,
+ current_dir: &path::Path,
+ // ideally this would be something like:
+ // with_output_for: impl FnMut(&str, dyn FnOnce(&mut BuildScriptOutput)),
+ // but owned trait objects aren't a thing
+ mut with_output_for: impl FnMut(&str, &mut dyn FnMut(&str, &mut BuildScriptOutput)),
+ progress: &dyn Fn(String),
+ ) -> io::Result<Option<String>> {
let errors = RefCell::new(String::new());
let push_err = |err: &str| {
let mut e = errors.borrow_mut();
@@ -133,7 +280,8 @@ impl WorkspaceBuildScripts {
e.push('\n');
};
- tracing::info!("Running build scripts: {:?}", cmd);
+ tracing::info!("Running build scripts in {}: {:?}", current_dir.display(), cmd);
+ cmd.current_dir(current_dir);
let output = stdx::process::spawn_with_streaming_output(
cmd,
&mut |line| {
@@ -145,59 +293,58 @@ impl WorkspaceBuildScripts {
.unwrap_or_else(|_| Message::TextLine(line.to_string()));
match message {
- Message::BuildScriptExecuted(message) => {
- let package = match by_id.get(&message.package_id.repr) {
- Some(&it) => it,
- None => return,
- };
- let cfgs = {
- let mut acc = Vec::new();
- for cfg in message.cfgs {
- match cfg.parse::<CfgFlag>() {
- Ok(it) => acc.push(it),
- Err(err) => {
- push_err(&format!(
- "invalid cfg from cargo-metadata: {}",
- err
- ));
- return;
- }
- };
+ Message::BuildScriptExecuted(mut message) => {
+ with_output_for(&message.package_id.repr, &mut |name, data| {
+ progress(format!("running build-script: {}", name));
+ let cfgs = {
+ let mut acc = Vec::new();
+ for cfg in &message.cfgs {
+ match cfg.parse::<CfgFlag>() {
+ Ok(it) => acc.push(it),
+ Err(err) => {
+ push_err(&format!(
+ "invalid cfg from cargo-metadata: {}",
+ err
+ ));
+ return;
+ }
+ };
+ }
+ acc
+ };
+ if !message.env.is_empty() {
+ data.envs = mem::take(&mut message.env);
}
- acc
- };
- // cargo_metadata crate returns default (empty) path for
- // older cargos, which is not absolute, so work around that.
- let out_dir = message.out_dir.into_os_string();
- if !out_dir.is_empty() {
- let data = outputs[package].get_or_insert_with(Default::default);
- data.out_dir = Some(AbsPathBuf::assert(PathBuf::from(out_dir)));
- data.cfgs = cfgs;
- }
- if !message.env.is_empty() {
- outputs[package].get_or_insert_with(Default::default).envs =
- message.env;
- }
+ // cargo_metadata crate returns default (empty) path for
+ // older cargos, which is not absolute, so work around that.
+ let out_dir = mem::take(&mut message.out_dir).into_os_string();
+ if !out_dir.is_empty() {
+ let out_dir = AbsPathBuf::assert(PathBuf::from(out_dir));
+ // inject_cargo_env(package, package_build_data);
+ // NOTE: cargo and rustc seem to hide non-UTF-8 strings from env! and option_env!()
+ if let Some(out_dir) =
+ out_dir.as_os_str().to_str().map(|s| s.to_owned())
+ {
+ data.envs.push(("OUT_DIR".to_string(), out_dir));
+ }
+ data.out_dir = Some(out_dir);
+ data.cfgs = cfgs;
+ }
+ });
}
Message::CompilerArtifact(message) => {
- let package = match by_id.get(&message.package_id.repr) {
- Some(it) => *it,
- None => return,
- };
-
- progress(format!("metadata {}", message.target.name));
-
- if message.target.kind.iter().any(|k| k == "proc-macro") {
- // Skip rmeta file
- if let Some(filename) =
- message.filenames.iter().find(|name| is_dylib(name))
- {
- let filename = AbsPathBuf::assert(PathBuf::from(&filename));
- outputs[package]
- .get_or_insert_with(Default::default)
- .proc_macro_dylib_path = Some(filename);
+ with_output_for(&message.package_id.repr, &mut |name, data| {
+ progress(format!("building proc-macros: {}", name));
+ if message.target.kind.iter().any(|k| k == "proc-macro") {
+ // Skip rmeta file
+ if let Some(filename) =
+ message.filenames.iter().find(|name| is_dylib(name))
+ {
+ let filename = AbsPathBuf::assert(PathBuf::from(&filename));
+ data.proc_macro_dylib_path = Some(filename);
+ }
}
- }
+ });
}
Message::CompilerMessage(message) => {
progress(message.target.name);
@@ -216,32 +363,13 @@ impl WorkspaceBuildScripts {
},
)?;
- for package in workspace.packages() {
- if let Some(package_build_data) = &mut outputs[package] {
- tracing::info!(
- "{}: {:?}",
- workspace[package].manifest.parent().display(),
- package_build_data,
- );
- // inject_cargo_env(package, package_build_data);
- if let Some(out_dir) = &package_build_data.out_dir {
- // NOTE: cargo and rustc seem to hide non-UTF-8 strings from env! and option_env!()
- if let Some(out_dir) = out_dir.as_os_str().to_str().map(|s| s.to_owned()) {
- package_build_data.envs.push(("OUT_DIR".to_string(), out_dir));
- }
- }
- }
- }
-
- let mut errors = errors.into_inner();
- if !output.status.success() {
- if errors.is_empty() {
- errors = "cargo check failed".to_string();
- }
- res.error = Some(errors);
- }
-
- Ok(res)
+ let errors = if !output.status.success() {
+ let errors = errors.into_inner();
+ Some(if errors.is_empty() { "cargo check failed".to_string() } else { errors })
+ } else {
+ None
+ };
+ Ok(errors)
}
pub fn error(&self) -> Option<&str> {
@@ -249,11 +377,11 @@ impl WorkspaceBuildScripts {
}
pub(crate) fn get_output(&self, idx: Package) -> Option<&BuildScriptOutput> {
- self.outputs.get(idx)?.as_ref()
+ self.outputs.get(idx)
}
}
-// FIXME: File a better way to know if it is a dylib.
+// FIXME: Find a better way to know if it is a dylib.
fn is_dylib(path: &Utf8Path) -> bool {
match path.extension().map(|e| e.to_string().to_lowercase()) {
None => false,
diff --git a/src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs b/src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs
index eed955b42..b4c2ba436 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs
@@ -2,6 +2,7 @@
use std::iter;
use std::path::PathBuf;
+use std::str::from_utf8;
use std::{ops, process::Command};
use anyhow::{Context, Result};
@@ -13,8 +14,8 @@ use rustc_hash::FxHashMap;
use serde::Deserialize;
use serde_json::from_value;
-use crate::CfgOverrides;
-use crate::{utf8_stdout, ManifestPath};
+use crate::{utf8_stdout, InvocationLocation, ManifestPath};
+use crate::{CfgOverrides, InvocationStrategy};
/// [`CargoWorkspace`] represents the logical structure of, well, a Cargo
/// workspace. It pretty closely mirrors `cargo metadata` output.
@@ -70,34 +71,43 @@ impl Default for UnsetTestCrates {
}
}
-#[derive(Default, Clone, Debug, PartialEq, Eq)]
-pub struct CargoConfig {
- /// Do not activate the `default` feature.
- pub no_default_features: bool,
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub enum CargoFeatures {
+ All,
+ Selected {
+ /// List of features to activate.
+ features: Vec<String>,
+ /// Do not activate the `default` feature.
+ no_default_features: bool,
+ },
+}
- /// Activate all available features
- pub all_features: bool,
+impl Default for CargoFeatures {
+ fn default() -> Self {
+ CargoFeatures::Selected { features: vec![], no_default_features: false }
+ }
+}
+#[derive(Default, Clone, Debug, PartialEq, Eq)]
+pub struct CargoConfig {
/// List of features to activate.
- /// This will be ignored if `cargo_all_features` is true.
- pub features: Vec<String>,
-
+ pub features: CargoFeatures,
/// rustc target
pub target: Option<String>,
-
- /// Don't load sysroot crates (`std`, `core` & friends). Might be useful
- /// when debugging isolated issues.
- pub no_sysroot: bool,
-
+ /// Sysroot loading behavior
+ pub sysroot: Option<RustcSource>,
/// rustc private crate source
pub rustc_source: Option<RustcSource>,
-
/// crates to disable `#[cfg(test)]` on
pub unset_test_crates: UnsetTestCrates,
-
+ /// Invoke `cargo check` through the RUSTC_WRAPPER.
pub wrap_rustc_in_build_scripts: bool,
-
+ /// The command to run instead of `cargo check` for building build scripts.
pub run_build_script_command: Option<Vec<String>>,
+ /// Extra env vars to set when invoking the cargo command
+ pub extra_env: FxHashMap<String, String>,
+ pub invocation_strategy: InvocationStrategy,
+ pub invocation_location: InvocationLocation,
}
impl CargoConfig {
@@ -140,7 +150,7 @@ pub struct PackageData {
pub targets: Vec<Target>,
/// Does this package come from the local filesystem (and is editable)?
pub is_local: bool,
- // Whether this package is a member of the workspace
+ /// Whether this package is a member of the workspace
pub is_member: bool,
/// List of packages this package depends on
pub dependencies: Vec<PackageDependency>,
@@ -246,8 +256,8 @@ impl TargetKind {
}
}
+// Deserialize helper for the cargo metadata
#[derive(Deserialize, Default)]
-// Deserialise helper for the cargo metadata
struct PackageMetadata {
#[serde(rename = "rust-analyzer")]
rust_analyzer: Option<RustAnalyzerPackageMetaData>,
@@ -263,22 +273,23 @@ impl CargoWorkspace {
let target = config
.target
.clone()
- .or_else(|| cargo_config_build_target(cargo_toml))
- .or_else(|| rustc_discover_host_triple(cargo_toml));
+ .or_else(|| cargo_config_build_target(cargo_toml, &config.extra_env))
+ .or_else(|| rustc_discover_host_triple(cargo_toml, &config.extra_env));
let mut meta = MetadataCommand::new();
meta.cargo_path(toolchain::cargo());
meta.manifest_path(cargo_toml.to_path_buf());
- if config.all_features {
- meta.features(CargoOpt::AllFeatures);
- } else {
- if config.no_default_features {
- // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
- // https://github.com/oli-obk/cargo_metadata/issues/79
- meta.features(CargoOpt::NoDefaultFeatures);
+ match &config.features {
+ CargoFeatures::All => {
+ meta.features(CargoOpt::AllFeatures);
}
- if !config.features.is_empty() {
- meta.features(CargoOpt::SomeFeatures(config.features.clone()));
+ CargoFeatures::Selected { features, no_default_features } => {
+ if *no_default_features {
+ meta.features(CargoOpt::NoDefaultFeatures);
+ }
+ if !features.is_empty() {
+ meta.features(CargoOpt::SomeFeatures(features.clone()));
+ }
}
}
meta.current_dir(current_dir.as_os_str());
@@ -292,10 +303,22 @@ impl CargoWorkspace {
// unclear whether cargo itself supports it.
progress("metadata".to_string());
- let meta =
- meta.exec().with_context(|| format!("Failed to run `{:?}`", meta.cargo_command()))?;
-
- Ok(meta)
+ (|| -> Result<cargo_metadata::Metadata, cargo_metadata::Error> {
+ let mut command = meta.cargo_command();
+ command.envs(&config.extra_env);
+ let output = command.output()?;
+ if !output.status.success() {
+ return Err(cargo_metadata::Error::CargoMetadata {
+ stderr: String::from_utf8(output.stderr)?,
+ });
+ }
+ let stdout = from_utf8(&output.stdout)?
+ .lines()
+ .find(|line| line.starts_with('{'))
+ .ok_or(cargo_metadata::Error::NoJson)?;
+ cargo_metadata::MetadataCommand::parse(stdout)
+ })()
+ .with_context(|| format!("Failed to run `{:?}`", meta.cargo_command()))
}
pub fn new(mut meta: cargo_metadata::Metadata) -> CargoWorkspace {
@@ -306,18 +329,21 @@ impl CargoWorkspace {
let ws_members = &meta.workspace_members;
meta.packages.sort_by(|a, b| a.id.cmp(&b.id));
- for meta_pkg in &meta.packages {
+ for meta_pkg in meta.packages {
let cargo_metadata::Package {
- id,
- edition,
name,
- manifest_path,
version,
- metadata,
+ id,
+ source,
+ targets: meta_targets,
+ features,
+ manifest_path,
repository,
+ edition,
+ metadata,
..
} = meta_pkg;
- let meta = from_value::<PackageMetadata>(metadata.clone()).unwrap_or_default();
+ let meta = from_value::<PackageMetadata>(metadata).unwrap_or_default();
let edition = match edition {
cargo_metadata::Edition::E2015 => Edition::Edition2015,
cargo_metadata::Edition::E2018 => Edition::Edition2018,
@@ -329,67 +355,50 @@ impl CargoWorkspace {
};
// We treat packages without source as "local" packages. That includes all members of
// the current workspace, as well as any path dependency outside the workspace.
- let is_local = meta_pkg.source.is_none();
- let is_member = ws_members.contains(id);
+ let is_local = source.is_none();
+ let is_member = ws_members.contains(&id);
let pkg = packages.alloc(PackageData {
id: id.repr.clone(),
- name: name.clone(),
- version: version.clone(),
- manifest: AbsPathBuf::assert(PathBuf::from(&manifest_path)).try_into().unwrap(),
+ name,
+ version,
+ manifest: AbsPathBuf::assert(manifest_path.into()).try_into().unwrap(),
targets: Vec::new(),
is_local,
is_member,
edition,
- repository: repository.clone(),
+ repository,
dependencies: Vec::new(),
- features: meta_pkg.features.clone().into_iter().collect(),
+ features: features.into_iter().collect(),
active_features: Vec::new(),
metadata: meta.rust_analyzer.unwrap_or_default(),
});
let pkg_data = &mut packages[pkg];
pkg_by_id.insert(id, pkg);
- for meta_tgt in &meta_pkg.targets {
- let is_proc_macro = meta_tgt.kind.as_slice() == ["proc-macro"];
+ for meta_tgt in meta_targets {
+ let cargo_metadata::Target { name, kind, required_features, src_path, .. } =
+ meta_tgt;
let tgt = targets.alloc(TargetData {
package: pkg,
- name: meta_tgt.name.clone(),
- root: AbsPathBuf::assert(PathBuf::from(&meta_tgt.src_path)),
- kind: TargetKind::new(meta_tgt.kind.as_slice()),
- is_proc_macro,
- required_features: meta_tgt.required_features.clone(),
+ name,
+ root: AbsPathBuf::assert(src_path.into()),
+ kind: TargetKind::new(&kind),
+ is_proc_macro: &*kind == ["proc-macro"],
+ required_features,
});
pkg_data.targets.push(tgt);
}
}
let resolve = meta.resolve.expect("metadata executed with deps");
for mut node in resolve.nodes {
- let source = match pkg_by_id.get(&node.id) {
- Some(&src) => src,
- // FIXME: replace this and a similar branch below with `.unwrap`, once
- // https://github.com/rust-lang/cargo/issues/7841
- // is fixed and hits stable (around 1.43-is probably?).
- None => {
- tracing::error!("Node id do not match in cargo metadata, ignoring {}", node.id);
- continue;
- }
- };
+ let &source = pkg_by_id.get(&node.id).unwrap();
node.deps.sort_by(|a, b| a.pkg.cmp(&b.pkg));
- for (dep_node, kind) in node
+ let dependencies = node
.deps
.iter()
- .flat_map(|dep| DepKind::iter(&dep.dep_kinds).map(move |kind| (dep, kind)))
- {
- let pkg = match pkg_by_id.get(&dep_node.pkg) {
- Some(&pkg) => pkg,
- None => {
- tracing::error!(
- "Dep node id do not match in cargo metadata, ignoring {}",
- dep_node.pkg
- );
- continue;
- }
- };
+ .flat_map(|dep| DepKind::iter(&dep.dep_kinds).map(move |kind| (dep, kind)));
+ for (dep_node, kind) in dependencies {
+ let &pkg = pkg_by_id.get(&dep_node.pkg).unwrap();
let dep = PackageDependency { name: dep_node.name.clone(), pkg, kind };
packages[source].dependencies.push(dep);
}
@@ -434,10 +443,7 @@ impl CargoWorkspace {
found = true
}
self[pkg].dependencies.iter().find_map(|dep| {
- if &self[dep.pkg].manifest == manifest_path {
- return Some(self[pkg].manifest.clone());
- }
- None
+ (&self[dep.pkg].manifest == manifest_path).then(|| self[pkg].manifest.clone())
})
})
.collect::<Vec<ManifestPath>>();
@@ -463,8 +469,12 @@ impl CargoWorkspace {
}
}
-fn rustc_discover_host_triple(cargo_toml: &ManifestPath) -> Option<String> {
+fn rustc_discover_host_triple(
+ cargo_toml: &ManifestPath,
+ extra_env: &FxHashMap<String, String>,
+) -> Option<String> {
let mut rustc = Command::new(toolchain::rustc());
+ rustc.envs(extra_env);
rustc.current_dir(cargo_toml.parent()).arg("-vV");
tracing::debug!("Discovering host platform by {:?}", rustc);
match utf8_stdout(rustc) {
@@ -486,8 +496,12 @@ fn rustc_discover_host_triple(cargo_toml: &ManifestPath) -> Option<String> {
}
}
-fn cargo_config_build_target(cargo_toml: &ManifestPath) -> Option<String> {
+fn cargo_config_build_target(
+ cargo_toml: &ManifestPath,
+ extra_env: &FxHashMap<String, String>,
+) -> Option<String> {
let mut cargo_config = Command::new(toolchain::cargo());
+ cargo_config.envs(extra_env);
cargo_config
.current_dir(cargo_toml.parent())
.args(&["-Z", "unstable-options", "config", "get", "build.target"])
diff --git a/src/tools/rust-analyzer/crates/project-model/src/lib.rs b/src/tools/rust-analyzer/crates/project-model/src/lib.rs
index b81b7432f..575581fa5 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/lib.rs
@@ -42,8 +42,8 @@ use rustc_hash::FxHashSet;
pub use crate::{
build_scripts::WorkspaceBuildScripts,
cargo_workspace::{
- CargoConfig, CargoWorkspace, Package, PackageData, PackageDependency, RustcSource, Target,
- TargetData, TargetKind, UnsetTestCrates,
+ CargoConfig, CargoFeatures, CargoWorkspace, Package, PackageData, PackageDependency,
+ RustcSource, Target, TargetData, TargetKind, UnsetTestCrates,
},
manifest_path::ManifestPath,
project_json::{ProjectJson, ProjectJsonData},
@@ -67,7 +67,7 @@ impl ProjectManifest {
if path.file_name().unwrap_or_default() == "Cargo.toml" {
return Ok(ProjectManifest::CargoToml(path));
}
- bail!("project root must point to Cargo.toml or rust-project.json: {}", path.display())
+ bail!("project root must point to Cargo.toml or rust-project.json: {}", path.display());
}
pub fn discover_single(path: &AbsPath) -> Result<ProjectManifest> {
@@ -78,7 +78,7 @@ impl ProjectManifest {
};
if !candidates.is_empty() {
- bail!("more than one project")
+ bail!("more than one project");
}
Ok(res)
}
@@ -157,3 +157,17 @@ fn utf8_stdout(mut cmd: Command) -> Result<String> {
let stdout = String::from_utf8(output.stdout)?;
Ok(stdout.trim().to_string())
}
+
+#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
+pub enum InvocationStrategy {
+ Once,
+ #[default]
+ PerWorkspace,
+}
+
+#[derive(Clone, Debug, Default, PartialEq, Eq)]
+pub enum InvocationLocation {
+ Root(AbsPathBuf),
+ #[default]
+ Workspace,
+}
diff --git a/src/tools/rust-analyzer/crates/project-model/src/project_json.rs b/src/tools/rust-analyzer/crates/project-model/src/project_json.rs
index 63d1d0ace..5133a14d5 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/project_json.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/project_json.rs
@@ -110,14 +110,17 @@ impl ProjectJson {
.collect::<Vec<_>>(),
}
}
+
/// Returns the number of crates in the project.
pub fn n_crates(&self) -> usize {
self.crates.len()
}
+
/// Returns an iterator over the crates in the project.
pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ {
self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate))
}
+
/// Returns the path to the project's root folder.
pub fn path(&self) -> &AbsPath {
&self.project_root
diff --git a/src/tools/rust-analyzer/crates/project-model/src/rustc_cfg.rs b/src/tools/rust-analyzer/crates/project-model/src/rustc_cfg.rs
index 17e244d06..323136183 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/rustc_cfg.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/rustc_cfg.rs
@@ -3,10 +3,15 @@
use std::process::Command;
use anyhow::Result;
+use rustc_hash::FxHashMap;
use crate::{cfg_flag::CfgFlag, utf8_stdout, ManifestPath};
-pub(crate) fn get(cargo_toml: Option<&ManifestPath>, target: Option<&str>) -> Vec<CfgFlag> {
+pub(crate) fn get(
+ cargo_toml: Option<&ManifestPath>,
+ target: Option<&str>,
+ extra_env: &FxHashMap<String, String>,
+) -> Vec<CfgFlag> {
let _p = profile::span("rustc_cfg::get");
let mut res = Vec::with_capacity(6 * 2 + 1);
@@ -18,7 +23,7 @@ pub(crate) fn get(cargo_toml: Option<&ManifestPath>, target: Option<&str>) -> Ve
}
}
- match get_rust_cfgs(cargo_toml, target) {
+ match get_rust_cfgs(cargo_toml, target, extra_env) {
Ok(rustc_cfgs) => {
tracing::debug!(
"rustc cfgs found: {:?}",
@@ -35,9 +40,14 @@ pub(crate) fn get(cargo_toml: Option<&ManifestPath>, target: Option<&str>) -> Ve
res
}
-fn get_rust_cfgs(cargo_toml: Option<&ManifestPath>, target: Option<&str>) -> Result<String> {
+fn get_rust_cfgs(
+ cargo_toml: Option<&ManifestPath>,
+ target: Option<&str>,
+ extra_env: &FxHashMap<String, String>,
+) -> Result<String> {
if let Some(cargo_toml) = cargo_toml {
let mut cargo_config = Command::new(toolchain::cargo());
+ cargo_config.envs(extra_env);
cargo_config
.current_dir(cargo_toml.parent())
.args(&["-Z", "unstable-options", "rustc", "--print", "cfg"])
@@ -52,6 +62,7 @@ fn get_rust_cfgs(cargo_toml: Option<&ManifestPath>, target: Option<&str>) -> Res
}
// using unstable cargo features failed, fall back to using plain rustc
let mut cmd = Command::new(toolchain::rustc());
+ cmd.envs(extra_env);
cmd.args(&["--print", "cfg", "-O"]);
if let Some(target) = target {
cmd.args(&["--target", target]);
diff --git a/src/tools/rust-analyzer/crates/project-model/src/sysroot.rs b/src/tools/rust-analyzer/crates/project-model/src/sysroot.rs
index 362bb0f5e..fa8d76f3f 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/sysroot.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/sysroot.rs
@@ -9,6 +9,7 @@ use std::{env, fs, iter, ops, path::PathBuf, process::Command};
use anyhow::{format_err, Result};
use la_arena::{Arena, Idx};
use paths::{AbsPath, AbsPathBuf};
+use rustc_hash::FxHashMap;
use crate::{utf8_stdout, ManifestPath};
@@ -63,22 +64,38 @@ impl Sysroot {
self.by_name("proc_macro")
}
- pub fn crates<'a>(&'a self) -> impl Iterator<Item = SysrootCrate> + ExactSizeIterator + 'a {
+ pub fn crates(&self) -> impl Iterator<Item = SysrootCrate> + ExactSizeIterator + '_ {
self.crates.iter().map(|(id, _data)| id)
}
+}
- pub fn discover(dir: &AbsPath) -> Result<Sysroot> {
- tracing::debug!("Discovering sysroot for {}", dir.display());
- let sysroot_dir = discover_sysroot_dir(dir)?;
- let sysroot_src_dir = discover_sysroot_src_dir(&sysroot_dir, dir)?;
+impl Sysroot {
+ /// Attempts to discover the toolchain's sysroot from the given `dir`.
+ pub fn discover(dir: &AbsPath, extra_env: &FxHashMap<String, String>) -> Result<Sysroot> {
+ tracing::debug!("discovering sysroot for {}", dir.display());
+ let sysroot_dir = discover_sysroot_dir(dir, extra_env)?;
+ let sysroot_src_dir =
+ discover_sysroot_src_dir_or_add_component(&sysroot_dir, dir, extra_env)?;
let res = Sysroot::load(sysroot_dir, sysroot_src_dir)?;
Ok(res)
}
- pub fn discover_rustc(cargo_toml: &ManifestPath) -> Option<ManifestPath> {
- tracing::debug!("Discovering rustc source for {}", cargo_toml.display());
+ pub fn discover_rustc(
+ cargo_toml: &ManifestPath,
+ extra_env: &FxHashMap<String, String>,
+ ) -> Option<ManifestPath> {
+ tracing::debug!("discovering rustc source for {}", cargo_toml.display());
let current_dir = cargo_toml.parent();
- discover_sysroot_dir(current_dir).ok().and_then(|sysroot_dir| get_rustc_src(&sysroot_dir))
+ let sysroot_dir = discover_sysroot_dir(current_dir, extra_env).ok()?;
+ get_rustc_src(&sysroot_dir)
+ }
+
+ pub fn with_sysroot_dir(sysroot_dir: AbsPathBuf) -> Result<Sysroot> {
+ let sysroot_src_dir = discover_sysroot_src_dir(&sysroot_dir).ok_or_else(|| {
+ format_err!("can't load standard library from sysroot {}", sysroot_dir.display())
+ })?;
+ let res = Sysroot::load(sysroot_dir, sysroot_src_dir)?;
+ Ok(res)
}
pub fn load(sysroot_dir: AbsPathBuf, sysroot_src_dir: AbsPathBuf) -> Result<Sysroot> {
@@ -144,33 +161,46 @@ impl Sysroot {
}
}
-fn discover_sysroot_dir(current_dir: &AbsPath) -> Result<AbsPathBuf> {
+fn discover_sysroot_dir(
+ current_dir: &AbsPath,
+ extra_env: &FxHashMap<String, String>,
+) -> Result<AbsPathBuf> {
let mut rustc = Command::new(toolchain::rustc());
+ rustc.envs(extra_env);
rustc.current_dir(current_dir).args(&["--print", "sysroot"]);
tracing::debug!("Discovering sysroot by {:?}", rustc);
let stdout = utf8_stdout(rustc)?;
Ok(AbsPathBuf::assert(PathBuf::from(stdout)))
}
-fn discover_sysroot_src_dir(
- sysroot_path: &AbsPathBuf,
- current_dir: &AbsPath,
-) -> Result<AbsPathBuf> {
+fn discover_sysroot_src_dir(sysroot_path: &AbsPathBuf) -> Option<AbsPathBuf> {
if let Ok(path) = env::var("RUST_SRC_PATH") {
- let path = AbsPathBuf::try_from(path.as_str())
- .map_err(|path| format_err!("RUST_SRC_PATH must be absolute: {}", path.display()))?;
- let core = path.join("core");
- if fs::metadata(&core).is_ok() {
- tracing::debug!("Discovered sysroot by RUST_SRC_PATH: {}", path.display());
- return Ok(path);
+ if let Ok(path) = AbsPathBuf::try_from(path.as_str()) {
+ let core = path.join("core");
+ if fs::metadata(&core).is_ok() {
+ tracing::debug!("Discovered sysroot by RUST_SRC_PATH: {}", path.display());
+ return Some(path);
+ }
+ tracing::debug!("RUST_SRC_PATH is set, but is invalid (no core: {:?}), ignoring", core);
+ } else {
+ tracing::debug!("RUST_SRC_PATH is set, but is invalid, ignoring");
}
- tracing::debug!("RUST_SRC_PATH is set, but is invalid (no core: {:?}), ignoring", core);
}
get_rust_src(sysroot_path)
+}
+
+fn discover_sysroot_src_dir_or_add_component(
+ sysroot_path: &AbsPathBuf,
+ current_dir: &AbsPath,
+ extra_env: &FxHashMap<String, String>,
+) -> Result<AbsPathBuf> {
+ discover_sysroot_src_dir(sysroot_path)
.or_else(|| {
let mut rustup = Command::new(toolchain::rustup());
+ rustup.envs(extra_env);
rustup.current_dir(current_dir).args(&["component", "add", "rust-src"]);
+ tracing::info!("adding rust-src component by {:?}", rustup);
utf8_stdout(rustup).ok()?;
get_rust_src(sysroot_path)
})
@@ -189,7 +219,7 @@ try installing the Rust source the same way you installed rustc",
fn get_rustc_src(sysroot_path: &AbsPath) -> Option<ManifestPath> {
let rustc_src = sysroot_path.join("lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml");
let rustc_src = ManifestPath::try_from(rustc_src).ok()?;
- tracing::debug!("Checking for rustc source code: {}", rustc_src.display());
+ tracing::debug!("checking for rustc source code: {}", rustc_src.display());
if fs::metadata(&rustc_src).is_ok() {
Some(rustc_src)
} else {
@@ -199,7 +229,7 @@ fn get_rustc_src(sysroot_path: &AbsPath) -> Option<ManifestPath> {
fn get_rust_src(sysroot_path: &AbsPath) -> Option<AbsPathBuf> {
let rust_src = sysroot_path.join("lib/rustlib/src/rust/library");
- tracing::debug!("Checking sysroot: {}", rust_src.display());
+ tracing::debug!("checking sysroot library: {}", rust_src.display());
if fs::metadata(&rust_src).is_ok() {
Some(rust_src)
} else {
diff --git a/src/tools/rust-analyzer/crates/project-model/src/tests.rs b/src/tools/rust-analyzer/crates/project-model/src/tests.rs
index 9ccb6e910..e2444e249 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/tests.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/tests.rs
@@ -92,13 +92,17 @@ fn rooted_project_json(data: ProjectJsonData) -> ProjectJson {
}
fn to_crate_graph(project_workspace: ProjectWorkspace) -> CrateGraph {
- project_workspace.to_crate_graph(&mut |_, _| Ok(Vec::new()), &mut {
- let mut counter = 0;
- move |_path| {
- counter += 1;
- Some(FileId(counter))
- }
- })
+ project_workspace.to_crate_graph(
+ &mut |_, _| Ok(Vec::new()),
+ &mut {
+ let mut counter = 0;
+ move |_path| {
+ counter += 1;
+ Some(FileId(counter))
+ }
+ },
+ &Default::default(),
+ )
}
fn check_crate_graph(crate_graph: CrateGraph, expect: Expect) {
@@ -181,6 +185,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
),
origin: CratesIo {
repo: None,
+ name: Some(
+ "hello-world",
+ ),
},
is_proc_macro: false,
},
@@ -256,6 +263,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
),
origin: CratesIo {
repo: None,
+ name: Some(
+ "hello-world",
+ ),
},
is_proc_macro: false,
},
@@ -331,6 +341,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
),
origin: CratesIo {
repo: None,
+ name: Some(
+ "hello-world",
+ ),
},
is_proc_macro: false,
},
@@ -406,6 +419,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
),
origin: CratesIo {
repo: None,
+ name: Some(
+ "hello-world",
+ ),
},
is_proc_macro: false,
},
@@ -473,6 +489,9 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
repo: Some(
"https://github.com/rust-lang/libc",
),
+ name: Some(
+ "libc",
+ ),
},
is_proc_macro: false,
},
@@ -563,6 +582,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
),
origin: CratesIo {
repo: None,
+ name: Some(
+ "hello-world",
+ ),
},
is_proc_macro: false,
},
@@ -640,6 +662,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
),
origin: CratesIo {
repo: None,
+ name: Some(
+ "hello-world",
+ ),
},
is_proc_macro: false,
},
@@ -717,6 +742,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
),
origin: CratesIo {
repo: None,
+ name: Some(
+ "hello-world",
+ ),
},
is_proc_macro: false,
},
@@ -794,6 +822,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
),
origin: CratesIo {
repo: None,
+ name: Some(
+ "hello-world",
+ ),
},
is_proc_macro: false,
},
@@ -861,6 +892,9 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
repo: Some(
"https://github.com/rust-lang/libc",
),
+ name: Some(
+ "libc",
+ ),
},
is_proc_macro: false,
},
@@ -942,6 +976,9 @@ fn cargo_hello_world_project_model() {
),
origin: CratesIo {
repo: None,
+ name: Some(
+ "hello-world",
+ ),
},
is_proc_macro: false,
},
@@ -1019,6 +1056,9 @@ fn cargo_hello_world_project_model() {
),
origin: CratesIo {
repo: None,
+ name: Some(
+ "hello-world",
+ ),
},
is_proc_macro: false,
},
@@ -1096,6 +1136,9 @@ fn cargo_hello_world_project_model() {
),
origin: CratesIo {
repo: None,
+ name: Some(
+ "hello-world",
+ ),
},
is_proc_macro: false,
},
@@ -1173,6 +1216,9 @@ fn cargo_hello_world_project_model() {
),
origin: CratesIo {
repo: None,
+ name: Some(
+ "hello-world",
+ ),
},
is_proc_macro: false,
},
@@ -1240,6 +1286,9 @@ fn cargo_hello_world_project_model() {
repo: Some(
"https://github.com/rust-lang/libc",
),
+ name: Some(
+ "libc",
+ ),
},
is_proc_macro: false,
},
@@ -1800,6 +1849,9 @@ fn rust_project_hello_world_project_model() {
),
origin: CratesIo {
repo: None,
+ name: Some(
+ "hello_world",
+ ),
},
is_proc_macro: false,
},
diff --git a/src/tools/rust-analyzer/crates/project-model/src/workspace.rs b/src/tools/rust-analyzer/crates/project-model/src/workspace.rs
index 818bbed6a..2780c62ed 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/workspace.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/workspace.rs
@@ -2,7 +2,7 @@
//! metadata` or `rust-project.json`) into representation stored in the salsa
//! database -- `CrateGraph`.
-use std::{collections::VecDeque, fmt, fs, process::Command};
+use std::{collections::VecDeque, fmt, fs, process::Command, sync::Arc};
use anyhow::{format_err, Context, Result};
use base_db::{
@@ -21,8 +21,8 @@ use crate::{
cfg_flag::CfgFlag,
rustc_cfg,
sysroot::SysrootCrate,
- utf8_stdout, CargoConfig, CargoWorkspace, ManifestPath, ProjectJson, ProjectManifest, Sysroot,
- TargetKind, WorkspaceBuildScripts,
+ utf8_stdout, CargoConfig, CargoWorkspace, InvocationStrategy, ManifestPath, Package,
+ ProjectJson, ProjectManifest, Sysroot, TargetKind, WorkspaceBuildScripts,
};
/// A set of cfg-overrides per crate.
@@ -156,11 +156,16 @@ impl ProjectWorkspace {
})?;
let project_location = project_json.parent().to_path_buf();
let project_json = ProjectJson::new(&project_location, data);
- ProjectWorkspace::load_inline(project_json, config.target.as_deref())?
+ ProjectWorkspace::load_inline(
+ project_json,
+ config.target.as_deref(),
+ &config.extra_env,
+ )?
}
ProjectManifest::CargoToml(cargo_toml) => {
let cargo_version = utf8_stdout({
let mut cmd = Command::new(toolchain::cargo());
+ cmd.envs(&config.extra_env);
cmd.arg("--version");
cmd
})?;
@@ -183,22 +188,41 @@ impl ProjectWorkspace {
})?;
let cargo = CargoWorkspace::new(meta);
- let sysroot = if config.no_sysroot {
- None
- } else {
- Some(Sysroot::discover(cargo_toml.parent()).with_context(|| {
- format!(
+ let sysroot = match &config.sysroot {
+ Some(RustcSource::Path(path)) => {
+ Some(Sysroot::with_sysroot_dir(path.clone()).with_context(|| {
+ format!(
+ "Failed to find sysroot for Cargo.toml file {}.",
+ cargo_toml.display()
+ )
+ })?)
+ }
+ Some(RustcSource::Discover) => Some(
+ Sysroot::discover(cargo_toml.parent(), &config.extra_env).with_context(
+ || {
+ format!(
"Failed to find sysroot for Cargo.toml file {}. Is rust-src installed?",
cargo_toml.display()
)
- })?)
+ },
+ )?,
+ ),
+ None => None,
};
+ if let Some(sysroot) = &sysroot {
+ tracing::info!(src_root = %sysroot.src_root().display(), root = %sysroot.root().display(), "Using sysroot");
+ }
let rustc_dir = match &config.rustc_source {
Some(RustcSource::Path(path)) => ManifestPath::try_from(path.clone()).ok(),
- Some(RustcSource::Discover) => Sysroot::discover_rustc(&cargo_toml),
+ Some(RustcSource::Discover) => {
+ Sysroot::discover_rustc(&cargo_toml, &config.extra_env)
+ }
None => None,
};
+ if let Some(rustc_dir) = &rustc_dir {
+ tracing::info!(rustc_dir = %rustc_dir.display(), "Using rustc source");
+ }
let rustc = match rustc_dir {
Some(rustc_dir) => Some({
@@ -216,7 +240,8 @@ impl ProjectWorkspace {
None => None,
};
- let rustc_cfg = rustc_cfg::get(Some(&cargo_toml), config.target.as_deref());
+ let rustc_cfg =
+ rustc_cfg::get(Some(&cargo_toml), config.target.as_deref(), &config.extra_env);
let cfg_overrides = config.cfg_overrides();
ProjectWorkspace::Cargo {
@@ -237,6 +262,7 @@ impl ProjectWorkspace {
pub fn load_inline(
project_json: ProjectJson,
target: Option<&str>,
+ extra_env: &FxHashMap<String, String>,
) -> Result<ProjectWorkspace> {
let sysroot = match (project_json.sysroot.clone(), project_json.sysroot_src.clone()) {
(Some(sysroot), Some(sysroot_src)) => Some(Sysroot::load(sysroot, sysroot_src)?),
@@ -257,8 +283,11 @@ impl ProjectWorkspace {
}
(None, None) => None,
};
+ if let Some(sysroot) = &sysroot {
+ tracing::info!(src_root = %sysroot.src_root().display(), root = %sysroot.root().display(), "Using sysroot");
+ }
- let rustc_cfg = rustc_cfg::get(None, target);
+ let rustc_cfg = rustc_cfg::get(None, target, extra_env);
Ok(ProjectWorkspace::Json { project: project_json, sysroot, rustc_cfg })
}
@@ -268,11 +297,13 @@ impl ProjectWorkspace {
.first()
.and_then(|it| it.parent())
.ok_or_else(|| format_err!("No detached files to load"))?,
+ &Default::default(),
)?;
- let rustc_cfg = rustc_cfg::get(None, None);
+ let rustc_cfg = rustc_cfg::get(None, None, &Default::default());
Ok(ProjectWorkspace::DetachedFiles { files: detached_files, sysroot, rustc_cfg })
}
+ /// Runs the build scripts for this [`ProjectWorkspace`].
pub fn run_build_scripts(
&self,
config: &CargoConfig,
@@ -280,9 +311,13 @@ impl ProjectWorkspace {
) -> Result<WorkspaceBuildScripts> {
match self {
ProjectWorkspace::Cargo { cargo, toolchain, .. } => {
- WorkspaceBuildScripts::run(config, cargo, progress, toolchain).with_context(|| {
- format!("Failed to run build scripts for {}", &cargo.workspace_root().display())
- })
+ WorkspaceBuildScripts::run_for_workspace(config, cargo, progress, toolchain)
+ .with_context(|| {
+ format!(
+ "Failed to run build scripts for {}",
+ &cargo.workspace_root().display()
+ )
+ })
}
ProjectWorkspace::Json { .. } | ProjectWorkspace::DetachedFiles { .. } => {
Ok(WorkspaceBuildScripts::default())
@@ -290,6 +325,49 @@ impl ProjectWorkspace {
}
}
+ /// Runs the build scripts for the given [`ProjectWorkspace`]s. Depending on the invocation
+ /// strategy this may run a single build process for all project workspaces.
+ pub fn run_all_build_scripts(
+ workspaces: &[ProjectWorkspace],
+ config: &CargoConfig,
+ progress: &dyn Fn(String),
+ ) -> Vec<Result<WorkspaceBuildScripts>> {
+ if matches!(config.invocation_strategy, InvocationStrategy::PerWorkspace)
+ || config.run_build_script_command.is_none()
+ {
+ return workspaces.iter().map(|it| it.run_build_scripts(config, progress)).collect();
+ }
+
+ let cargo_ws: Vec<_> = workspaces
+ .iter()
+ .filter_map(|it| match it {
+ ProjectWorkspace::Cargo { cargo, .. } => Some(cargo),
+ _ => None,
+ })
+ .collect();
+ let ref mut outputs = match WorkspaceBuildScripts::run_once(config, &cargo_ws, progress) {
+ Ok(it) => Ok(it.into_iter()),
+ // io::Error is not Clone?
+ Err(e) => Err(Arc::new(e)),
+ };
+
+ workspaces
+ .iter()
+ .map(|it| match it {
+ ProjectWorkspace::Cargo { cargo, .. } => match outputs {
+ Ok(outputs) => Ok(outputs.next().unwrap()),
+ Err(e) => Err(e.clone()).with_context(|| {
+ format!(
+ "Failed to run build scripts for {}",
+ &cargo.workspace_root().display()
+ )
+ }),
+ },
+ _ => Ok(WorkspaceBuildScripts::default()),
+ })
+ .collect()
+ }
+
pub fn set_build_scripts(&mut self, bs: WorkspaceBuildScripts) {
match self {
ProjectWorkspace::Cargo { build_scripts, .. } => *build_scripts = bs,
@@ -303,6 +381,13 @@ impl ProjectWorkspace {
/// The return type contains the path and whether or not
/// the root is a member of the current workspace
pub fn to_roots(&self) -> Vec<PackageRoot> {
+ let mk_sysroot = |sysroot: Option<&Sysroot>| {
+ sysroot.map(|sysroot| PackageRoot {
+ is_local: false,
+ include: vec![sysroot.src_root().to_path_buf()],
+ exclude: Vec::new(),
+ })
+ };
match self {
ProjectWorkspace::Json { project, sysroot, rustc_cfg: _ } => project
.crates()
@@ -313,13 +398,7 @@ impl ProjectWorkspace {
})
.collect::<FxHashSet<_>>()
.into_iter()
- .chain(sysroot.as_ref().into_iter().flat_map(|sysroot| {
- sysroot.crates().map(move |krate| PackageRoot {
- is_local: false,
- include: vec![sysroot[krate].root.parent().to_path_buf()],
- exclude: Vec::new(),
- })
- }))
+ .chain(mk_sysroot(sysroot.as_ref()))
.collect::<Vec<_>>(),
ProjectWorkspace::Cargo {
cargo,
@@ -368,11 +447,7 @@ impl ProjectWorkspace {
}
PackageRoot { is_local, include, exclude }
})
- .chain(sysroot.iter().map(|sysroot| PackageRoot {
- is_local: false,
- include: vec![sysroot.src_root().to_path_buf()],
- exclude: Vec::new(),
- }))
+ .chain(mk_sysroot(sysroot.as_ref()))
.chain(rustc.iter().flat_map(|rustc| {
rustc.packages().map(move |krate| PackageRoot {
is_local: false,
@@ -389,11 +464,7 @@ impl ProjectWorkspace {
include: vec![detached_file.clone()],
exclude: Vec::new(),
})
- .chain(sysroot.crates().map(|krate| PackageRoot {
- is_local: false,
- include: vec![sysroot[krate].root.parent().to_path_buf()],
- exclude: Vec::new(),
- }))
+ .chain(mk_sysroot(Some(sysroot)))
.collect(),
}
}
@@ -416,6 +487,7 @@ impl ProjectWorkspace {
&self,
load_proc_macro: &mut dyn FnMut(&str, &AbsPath) -> ProcMacroLoadResult,
load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
+ extra_env: &FxHashMap<String, String>,
) -> CrateGraph {
let _p = profile::span("ProjectWorkspace::to_crate_graph");
@@ -426,6 +498,7 @@ impl ProjectWorkspace {
load,
project,
sysroot,
+ extra_env,
),
ProjectWorkspace::Cargo {
cargo,
@@ -464,6 +537,7 @@ fn project_json_to_crate_graph(
load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
project: &ProjectJson,
sysroot: &Option<Sysroot>,
+ extra_env: &FxHashMap<String, String>,
) -> CrateGraph {
let mut crate_graph = CrateGraph::default();
let sysroot_deps = sysroot
@@ -489,9 +563,9 @@ fn project_json_to_crate_graph(
};
let target_cfgs = match krate.target.as_deref() {
- Some(target) => {
- cfg_cache.entry(target).or_insert_with(|| rustc_cfg::get(None, Some(target)))
- }
+ Some(target) => cfg_cache
+ .entry(target)
+ .or_insert_with(|| rustc_cfg::get(None, Some(target), extra_env)),
None => &rustc_cfg,
};
@@ -510,9 +584,15 @@ fn project_json_to_crate_graph(
proc_macro,
krate.is_proc_macro,
if krate.display_name.is_some() {
- CrateOrigin::CratesIo { repo: krate.repository.clone() }
+ CrateOrigin::CratesIo {
+ repo: krate.repository.clone(),
+ name: krate
+ .display_name
+ .clone()
+ .map(|n| n.canonical_name().to_string()),
+ }
} else {
- CrateOrigin::CratesIo { repo: None }
+ CrateOrigin::CratesIo { repo: None, name: None }
},
),
)
@@ -624,6 +704,8 @@ fn cargo_to_crate_graph(
lib_tgt = Some((crate_id, cargo[tgt].name.clone()));
pkg_to_lib_crate.insert(pkg, crate_id);
}
+ // Even crates that don't set proc-macro = true are allowed to depend on proc_macro
+ // (just none of the APIs work when called outside of a proc macro).
if let Some(proc_macro) = libproc_macro {
add_dep_with_prelude(
&mut crate_graph,
@@ -639,19 +721,19 @@ fn cargo_to_crate_graph(
}
// Set deps to the core, std and to the lib target of the current package
- for (from, kind) in pkg_crates.get(&pkg).into_iter().flatten() {
+ for &(from, kind) in pkg_crates.get(&pkg).into_iter().flatten() {
// Add sysroot deps first so that a lib target named `core` etc. can overwrite them.
- public_deps.add(*from, &mut crate_graph);
+ public_deps.add(from, &mut crate_graph);
if let Some((to, name)) = lib_tgt.clone() {
- if to != *from && *kind != TargetKind::BuildScript {
+ if to != from && kind != TargetKind::BuildScript {
// (build script can not depend on its library target)
// For root projects with dashes in their name,
// cargo metadata does not do any normalization,
// so we do it ourselves currently
let name = CrateName::normalize_dashes(&name);
- add_dep(&mut crate_graph, *from, name, to);
+ add_dep(&mut crate_graph, from, name, to);
}
}
}
@@ -663,17 +745,17 @@ fn cargo_to_crate_graph(
for dep in cargo[pkg].dependencies.iter() {
let name = CrateName::new(&dep.name).unwrap();
if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) {
- for (from, kind) in pkg_crates.get(&pkg).into_iter().flatten() {
- if dep.kind == DepKind::Build && *kind != TargetKind::BuildScript {
+ for &(from, kind) in pkg_crates.get(&pkg).into_iter().flatten() {
+ if dep.kind == DepKind::Build && kind != TargetKind::BuildScript {
// Only build scripts may depend on build dependencies.
continue;
}
- if dep.kind != DepKind::Build && *kind == TargetKind::BuildScript {
+ if dep.kind != DepKind::Build && kind == TargetKind::BuildScript {
// Build scripts may only depend on build dependencies.
continue;
}
- add_dep(&mut crate_graph, *from, name.clone(), to)
+ add_dep(&mut crate_graph, from, name.clone(), to)
}
}
}
@@ -684,9 +766,9 @@ fn cargo_to_crate_graph(
// and create dependencies on them for the crates which opt-in to that
if let Some(rustc_workspace) = rustc {
handle_rustc_crates(
+ &mut crate_graph,
rustc_workspace,
load,
- &mut crate_graph,
&cfg_options,
override_cfg,
load_proc_macro,
@@ -730,14 +812,17 @@ fn detached_files_to_crate_graph(
let detached_file_crate = crate_graph.add_crate_root(
file_id,
Edition::CURRENT,
- display_name,
+ display_name.clone(),
None,
cfg_options.clone(),
cfg_options.clone(),
Env::default(),
Ok(Vec::new()),
false,
- CrateOrigin::CratesIo { repo: None },
+ CrateOrigin::CratesIo {
+ repo: None,
+ name: display_name.map(|n| n.canonical_name().to_string()),
+ },
);
public_deps.add(detached_file_crate, &mut crate_graph);
@@ -746,16 +831,16 @@ fn detached_files_to_crate_graph(
}
fn handle_rustc_crates(
+ crate_graph: &mut CrateGraph,
rustc_workspace: &CargoWorkspace,
load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
- crate_graph: &mut CrateGraph,
cfg_options: &CfgOptions,
override_cfg: &CfgOverrides,
load_proc_macro: &mut dyn FnMut(&str, &AbsPath) -> ProcMacroLoadResult,
- pkg_to_lib_crate: &mut FxHashMap<la_arena::Idx<crate::PackageData>, CrateId>,
+ pkg_to_lib_crate: &mut FxHashMap<Package, CrateId>,
public_deps: &SysrootPublicDeps,
cargo: &CargoWorkspace,
- pkg_crates: &FxHashMap<la_arena::Idx<crate::PackageData>, Vec<(CrateId, TargetKind)>>,
+ pkg_crates: &FxHashMap<Package, Vec<(CrateId, TargetKind)>>,
build_scripts: &WorkspaceBuildScripts,
) {
let mut rustc_pkg_crates = FxHashMap::default();
@@ -769,8 +854,8 @@ fn handle_rustc_crates(
let mut queue = VecDeque::new();
queue.push_back(root_pkg);
while let Some(pkg) = queue.pop_front() {
- // Don't duplicate packages if they are dependended on a diamond pattern
- // N.B. if this line is omitted, we try to analyse over 4_800_000 crates
+ // Don't duplicate packages if they are dependent on a diamond pattern
+ // N.B. if this line is omitted, we try to analyze over 4_800_000 crates
// which is not ideal
if rustc_pkg_crates.contains_key(&pkg) {
continue;
@@ -913,7 +998,7 @@ fn add_target_crate_root(
env,
proc_macro,
is_proc_macro,
- CrateOrigin::CratesIo { repo: pkg.repository.clone() },
+ CrateOrigin::CratesIo { repo: pkg.repository.clone(), name: Some(pkg.name.clone()) },
)
}
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml
index 539258918..544502853 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/Cargo.toml
@@ -18,14 +18,14 @@ name = "rust-analyzer"
path = "src/bin/main.rs"
[dependencies]
-anyhow = "1.0.57"
+anyhow = "1.0.62"
crossbeam-channel = "0.5.5"
dissimilar = "1.0.4"
-itertools = "0.10.3"
+itertools = "0.10.5"
scip = "0.1.1"
lsp-types = { version = "0.93.1", features = ["proposed"] }
parking_lot = "0.12.1"
-xflags = "0.2.4"
+xflags = "0.3.0"
oorandom = "11.1.3"
rustc-hash = "1.1.0"
serde = { version = "1.0.137", features = ["derive"] }
@@ -33,10 +33,10 @@ serde_json = { version = "1.0.81", features = ["preserve_order"] }
threadpool = "1.8.1"
rayon = "1.5.3"
num_cpus = "1.13.1"
-mimalloc = { version = "0.1.29", default-features = false, optional = true }
-lsp-server = { version = "0.6.0", path = "../../lib/lsp-server" }
+mimalloc = { version = "0.1.30", default-features = false, optional = true }
+lsp-server = { version = "0.7.0", path = "../../lib/lsp-server" }
tracing = "0.1.35"
-tracing-subscriber = { version = "0.3.14", default-features = false, features = [
+tracing-subscriber = { version = "0.3.16", default-features = false, features = [
"env-filter",
"registry",
"fmt",
@@ -87,7 +87,6 @@ jemalloc = ["jemallocator", "profile/jemalloc"]
force-always-assert = ["always-assert/force"]
in-rust-tree = [
"proc-macro-srv/sysroot-abi",
- "sourcegen/in-rust-tree",
"ide/in-rust-tree",
"syntax/in-rust-tree",
]
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/logger.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/logger.rs
index 298814af5..ac10721d9 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/logger.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/logger.rs
@@ -132,7 +132,7 @@ where
let ext = span.extensions();
- // `FormattedFields` is a a formatted representation of the span's
+ // `FormattedFields` is a formatted representation of the span's
// fields, which is stored in its extensions by the `fmt` layer's
// `new_span` method. The fields will have been formatted
// by the same field formatter that's provided to the event
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs
index f6a680297..eabfcf194 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/bin/main.rs
@@ -37,16 +37,15 @@ fn main() {
process::exit(code);
}
- if let Err(err) = try_main() {
+ let flags = flags::RustAnalyzer::from_env_or_exit();
+ if let Err(err) = try_main(flags) {
tracing::error!("Unexpected error: {}", err);
eprintln!("{}", err);
process::exit(101);
}
}
-fn try_main() -> Result<()> {
- let flags = flags::RustAnalyzer::from_env()?;
-
+fn try_main(flags: flags::RustAnalyzer) -> Result<()> {
#[cfg(debug_assertions)]
if flags.wait_dbg || env::var("RA_WAIT_DBG").is_ok() {
#[allow(unused_mut)]
@@ -76,10 +75,6 @@ fn try_main() -> Result<()> {
println!("rust-analyzer {}", rust_analyzer::version());
return Ok(());
}
- if cmd.help {
- println!("{}", flags::RustAnalyzer::HELP);
- return Ok(());
- }
with_extra_thread("LspServer", run_server)?;
}
flags::RustAnalyzerCmd::ProcMacro(flags::ProcMacro) => {
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cargo_target_spec.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cargo_target_spec.rs
index 1c39e9391..6ede194ba 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cargo_target_spec.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cargo_target_spec.rs
@@ -4,7 +4,7 @@ use std::mem;
use cfg::{CfgAtom, CfgExpr};
use ide::{FileId, RunnableKind, TestId};
-use project_model::{self, ManifestPath, TargetKind};
+use project_model::{self, CargoFeatures, ManifestPath, TargetKind};
use vfs::AbsPathBuf;
use crate::{global_state::GlobalStateSnapshot, Result};
@@ -35,41 +35,41 @@ impl CargoTargetSpec {
match kind {
RunnableKind::Test { test_id, attr } => {
- args.push("test".to_string());
+ args.push("test".to_owned());
extra_args.push(test_id.to_string());
if let TestId::Path(_) = test_id {
- extra_args.push("--exact".to_string());
+ extra_args.push("--exact".to_owned());
}
- extra_args.push("--nocapture".to_string());
+ extra_args.push("--nocapture".to_owned());
if attr.ignore {
- extra_args.push("--ignored".to_string());
+ extra_args.push("--ignored".to_owned());
}
}
RunnableKind::TestMod { path } => {
- args.push("test".to_string());
- extra_args.push(path.to_string());
- extra_args.push("--nocapture".to_string());
+ args.push("test".to_owned());
+ extra_args.push(path.clone());
+ extra_args.push("--nocapture".to_owned());
}
RunnableKind::Bench { test_id } => {
- args.push("bench".to_string());
+ args.push("bench".to_owned());
extra_args.push(test_id.to_string());
if let TestId::Path(_) = test_id {
- extra_args.push("--exact".to_string());
+ extra_args.push("--exact".to_owned());
}
- extra_args.push("--nocapture".to_string());
+ extra_args.push("--nocapture".to_owned());
}
RunnableKind::DocTest { test_id } => {
- args.push("test".to_string());
- args.push("--doc".to_string());
+ args.push("test".to_owned());
+ args.push("--doc".to_owned());
extra_args.push(test_id.to_string());
- extra_args.push("--nocapture".to_string());
+ extra_args.push("--nocapture".to_owned());
}
RunnableKind::Bin => {
let subcommand = match spec {
Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => "test",
_ => "run",
};
- args.push(subcommand.to_string());
+ args.push(subcommand.to_owned());
}
}
@@ -82,29 +82,35 @@ impl CargoTargetSpec {
};
let cargo_config = snap.config.cargo();
- if cargo_config.all_features {
- args.push("--all-features".to_string());
- for feature in target_required_features {
- args.push("--features".to_string());
- args.push(feature);
- }
- } else {
- let mut features = Vec::new();
- if let Some(cfg) = cfg.as_ref() {
- required_features(cfg, &mut features);
+ match &cargo_config.features {
+ CargoFeatures::All => {
+ args.push("--all-features".to_owned());
+ for feature in target_required_features {
+ args.push("--features".to_owned());
+ args.push(feature);
+ }
}
+ CargoFeatures::Selected { features, no_default_features } => {
+ let mut feats = Vec::new();
+ if let Some(cfg) = cfg.as_ref() {
+ required_features(cfg, &mut feats);
+ }
- features.extend(cargo_config.features);
- features.extend(target_required_features);
+ feats.extend(features.iter().cloned());
+ feats.extend(target_required_features);
- features.dedup();
- for feature in features {
- args.push("--features".to_string());
- args.push(feature);
+ feats.dedup();
+ for feature in feats {
+ args.push("--features".to_owned());
+ args.push(feature);
+ }
+
+ if *no_default_features {
+ args.push("--no-default-features".to_owned());
+ }
}
}
-
Ok((args, extra_args))
}
@@ -112,7 +118,7 @@ impl CargoTargetSpec {
global_state_snapshot: &GlobalStateSnapshot,
file_id: FileId,
) -> Result<Option<CargoTargetSpec>> {
- let crate_id = match &*global_state_snapshot.analysis.crate_for(file_id)? {
+ let crate_id = match &*global_state_snapshot.analysis.crates_for(file_id)? {
&[crate_id, ..] => crate_id,
_ => return Ok(None),
};
@@ -136,7 +142,7 @@ impl CargoTargetSpec {
}
pub(crate) fn push_to(self, buf: &mut Vec<String>, kind: &RunnableKind) {
- buf.push("--package".to_string());
+ buf.push("--package".to_owned());
buf.push(self.package);
// Can't mix --doc with other target flags
@@ -145,23 +151,23 @@ impl CargoTargetSpec {
}
match self.target_kind {
TargetKind::Bin => {
- buf.push("--bin".to_string());
+ buf.push("--bin".to_owned());
buf.push(self.target);
}
TargetKind::Test => {
- buf.push("--test".to_string());
+ buf.push("--test".to_owned());
buf.push(self.target);
}
TargetKind::Bench => {
- buf.push("--bench".to_string());
+ buf.push("--bench".to_owned());
buf.push(self.target);
}
TargetKind::Example => {
- buf.push("--example".to_string());
+ buf.push("--example".to_owned());
buf.push(self.target);
}
TargetKind::Lib => {
- buf.push("--lib".to_string());
+ buf.push("--lib".to_owned());
}
TargetKind::Other | TargetKind::BuildScript => (),
}
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs
index f52e1e751..01fccc83e 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -24,7 +24,7 @@ use ide_db::base_db::{
use itertools::Itertools;
use oorandom::Rand32;
use profile::{Bytes, StopWatch};
-use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace};
+use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustcSource};
use rayon::prelude::*;
use rustc_hash::FxHashSet;
use stdx::format_to;
@@ -55,7 +55,10 @@ impl flags::AnalysisStats {
};
let mut cargo_config = CargoConfig::default();
- cargo_config.no_sysroot = self.no_sysroot;
+ cargo_config.sysroot = match self.no_sysroot {
+ true => None,
+ false => Some(RustcSource::Discover),
+ };
let load_cargo_config = LoadCargoConfig {
load_out_dirs_from_check: !self.disable_build_scripts,
with_proc_macro: !self.disable_proc_macros,
@@ -80,7 +83,8 @@ impl flags::AnalysisStats {
Some(build_scripts_sw.elapsed())
};
- let (host, vfs, _proc_macro) = load_workspace(workspace, &load_cargo_config)?;
+ let (host, vfs, _proc_macro) =
+ load_workspace(workspace, &cargo_config.extra_env, &load_cargo_config)?;
let db = host.raw_database();
eprint!("{:<20} {}", "Database loaded:", db_load_sw.elapsed());
eprint!(" (metadata {}", metadata_time);
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/flags.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/flags.rs
index aa32654fb..5bcc97e22 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/flags.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/flags.rs
@@ -31,8 +31,6 @@ xflags::xflags! {
default cmd lsp-server {
/// Print version.
optional --version
- /// Print help.
- optional -h, --help
/// Dump a LSP config JSON schema.
optional --print-config-schema
@@ -54,10 +52,10 @@ xflags::xflags! {
}
/// Batch typecheck project and print summary statistics
- cmd analysis-stats
+ cmd analysis-stats {
/// Directory with Cargo.toml.
required path: PathBuf
- {
+
optional --output format: OutputFormat
/// Randomize order in which crates, modules, and items are processed.
@@ -84,38 +82,37 @@ xflags::xflags! {
optional --skip-inference
}
- cmd diagnostics
+ cmd diagnostics {
/// Directory with Cargo.toml.
required path: PathBuf
- {
+
/// Don't run build scripts or load `OUT_DIR` values by running `cargo check` before analysis.
optional --disable-build-scripts
/// Don't use expand proc macros.
optional --disable-proc-macros
}
- cmd ssr
+ cmd ssr {
/// A structured search replace rule (`$a.foo($b) ==> bar($a, $b)`)
repeated rule: SsrRule
- {}
+ }
- cmd search
+ cmd search {
/// A structured search replace pattern (`$a.foo($b)`)
repeated pattern: SsrPattern
- {
/// Prints debug information for any nodes with source exactly equal to snippet.
optional --debug snippet: String
}
cmd proc-macro {}
- cmd lsif
+ cmd lsif {
required path: PathBuf
- {}
+ }
- cmd scip
+ cmd scip {
required path: PathBuf
- {}
+ }
}
}
@@ -150,7 +147,6 @@ pub enum RustAnalyzerCmd {
#[derive(Debug)]
pub struct LspServer {
pub version: bool,
- pub help: bool,
pub print_config_schema: bool,
}
@@ -218,7 +214,10 @@ pub struct Scip {
}
impl RustAnalyzer {
- pub const HELP: &'static str = Self::HELP_;
+ #[allow(dead_code)]
+ pub fn from_env_or_exit() -> Self {
+ Self::from_env_or_exit_()
+ }
#[allow(dead_code)]
pub fn from_env() -> xflags::Result<Self> {
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/load_cargo.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/load_cargo.rs
index 5d1c013c3..5dba545b8 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/load_cargo.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -6,7 +6,7 @@ use anyhow::Result;
use crossbeam_channel::{unbounded, Receiver};
use hir::db::DefDatabase;
use ide::{AnalysisHost, Change};
-use ide_db::base_db::CrateGraph;
+use ide_db::{base_db::CrateGraph, FxHashMap};
use proc_macro_api::ProcMacroServer;
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace};
use vfs::{loader::Handle, AbsPath, AbsPathBuf};
@@ -38,7 +38,7 @@ pub fn load_workspace_at(
workspace.set_build_scripts(build_scripts)
}
- load_workspace(workspace, load_config)
+ load_workspace(workspace, &cargo_config.extra_env, load_config)
}
// Note: Since this function is used by external tools that use rust-analyzer as a library
@@ -48,6 +48,7 @@ pub fn load_workspace_at(
// these tools need access to `ProjectWorkspace`, too, which `load_workspace_at` hides.
pub fn load_workspace(
ws: ProjectWorkspace,
+ extra_env: &FxHashMap<String, String>,
load_config: &LoadCargoConfig,
) -> Result<(AnalysisHost, vfs::Vfs, Option<ProcMacroServer>)> {
let (sender, receiver) = unbounded();
@@ -59,10 +60,26 @@ pub fn load_workspace(
};
let proc_macro_client = if load_config.with_proc_macro {
- let path = AbsPathBuf::assert(std::env::current_exe()?);
- Ok(ProcMacroServer::spawn(path, &["proc-macro"]).unwrap())
+ let mut path = AbsPathBuf::assert(std::env::current_exe()?);
+ let mut args = vec!["proc-macro"];
+
+ if let ProjectWorkspace::Cargo { sysroot, .. } | ProjectWorkspace::Json { sysroot, .. } =
+ &ws
+ {
+ if let Some(sysroot) = sysroot.as_ref() {
+ let standalone_server_name =
+ format!("rust-analyzer-proc-macro-srv{}", std::env::consts::EXE_SUFFIX);
+ let server_path = sysroot.root().join("libexec").join(&standalone_server_name);
+ if std::fs::metadata(&server_path).is_ok() {
+ path = server_path;
+ args = vec![];
+ }
+ }
+ }
+
+ ProcMacroServer::spawn(path.clone(), args.clone()).map_err(|e| e.to_string())
} else {
- Err("proc macro server not started".to_owned())
+ Err("proc macro server disabled".to_owned())
};
let crate_graph = ws.to_crate_graph(
@@ -75,6 +92,7 @@ pub fn load_workspace(
vfs.set_file_contents(path.clone(), contents);
vfs.file_id(&path)
},
+ extra_env,
);
let project_folders = ProjectFolders::new(&[ws], &[]);
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/lsif.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/lsif.rs
index 491c55a04..748306ea5 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/lsif.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/lsif.rs
@@ -299,7 +299,8 @@ impl flags::Lsif {
let workspace = ProjectWorkspace::load(manifest, &cargo_config, no_progress)?;
- let (host, vfs, _proc_macro) = load_workspace(workspace, &load_cargo_config)?;
+ let (host, vfs, _proc_macro) =
+ load_workspace(workspace, &cargo_config.extra_env, &load_cargo_config)?;
let db = host.raw_database();
let analysis = host.analysis();
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs
index 65cc993c4..8b77ccde0 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/cli/scip.rs
@@ -8,8 +8,8 @@ use std::{
use crate::line_index::{LineEndings, LineIndex, OffsetEncoding};
use hir::Name;
use ide::{
- LineCol, MonikerDescriptorKind, MonikerResult, StaticIndex, StaticIndexedFile, TextRange,
- TokenId,
+ LineCol, MonikerDescriptorKind, StaticIndex, StaticIndexedFile, TextRange, TokenId,
+ TokenStaticData,
};
use ide_db::LineIndexDatabase;
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace};
@@ -40,7 +40,8 @@ impl flags::Scip {
let workspace = ProjectWorkspace::load(manifest, &cargo_config, no_progress)?;
- let (host, vfs, _) = load_workspace(workspace, &load_cargo_config)?;
+ let (host, vfs, _) =
+ load_workspace(workspace, &cargo_config.extra_env, &load_cargo_config)?;
let db = host.raw_database();
let analysis = host.analysis();
@@ -74,7 +75,7 @@ impl flags::Scip {
let mut symbols_emitted: HashSet<TokenId> = HashSet::default();
let mut tokens_to_symbol: HashMap<TokenId, String> = HashMap::new();
- for file in si.files {
+ for StaticIndexedFile { file_id, tokens, .. } in si.files {
let mut local_count = 0;
let mut new_local_symbol = || {
let new_symbol = scip::types::Symbol::new_local(local_count);
@@ -83,7 +84,6 @@ impl flags::Scip {
new_symbol
};
- let StaticIndexedFile { file_id, tokens, .. } = file;
let relative_path = match get_relative_filepath(&vfs, &rootpath, file_id) {
Some(relative_path) => relative_path,
None => continue,
@@ -106,28 +106,20 @@ impl flags::Scip {
let mut occurrence = scip_types::Occurrence::default();
occurrence.range = text_range_to_scip_range(&line_index, range);
- occurrence.symbol = match tokens_to_symbol.get(&id) {
- Some(symbol) => symbol.clone(),
- None => {
- let symbol = match &token.moniker {
- Some(moniker) => moniker_to_symbol(&moniker),
- None => new_local_symbol(),
- };
-
- let symbol = scip::symbol::format_symbol(symbol);
- tokens_to_symbol.insert(id, symbol.clone());
- symbol
- }
- };
+ occurrence.symbol = tokens_to_symbol
+ .entry(id)
+ .or_insert_with(|| {
+ let symbol = token_to_symbol(&token).unwrap_or_else(&mut new_local_symbol);
+ scip::symbol::format_symbol(symbol)
+ })
+ .clone();
if let Some(def) = token.definition {
if def.range == range {
occurrence.symbol_roles |= scip_types::SymbolRole::Definition as i32;
}
- if !symbols_emitted.contains(&id) {
- symbols_emitted.insert(id);
-
+ if symbols_emitted.insert(id) {
let mut symbol_info = scip_types::SymbolInformation::default();
symbol_info.symbol = occurrence.symbol.clone();
if let Some(hover) = &token.hover {
@@ -206,9 +198,11 @@ fn new_descriptor(name: Name, suffix: scip_types::descriptor::Suffix) -> scip_ty
///
/// Only returns a Symbol when it's a non-local symbol.
/// So if the visibility isn't outside of a document, then it will return None
-fn moniker_to_symbol(moniker: &MonikerResult) -> scip_types::Symbol {
+fn token_to_symbol(token: &TokenStaticData) -> Option<scip_types::Symbol> {
use scip_types::descriptor::Suffix::*;
+ let moniker = token.moniker.as_ref()?;
+
let package_name = moniker.package_information.name.clone();
let version = moniker.package_information.version.clone();
let descriptors = moniker
@@ -232,7 +226,7 @@ fn moniker_to_symbol(moniker: &MonikerResult) -> scip_types::Symbol {
})
.collect();
- scip_types::Symbol {
+ Some(scip_types::Symbol {
scheme: "rust-analyzer".into(),
package: Some(scip_types::Package {
manager: "cargo".to_string(),
@@ -243,19 +237,15 @@ fn moniker_to_symbol(moniker: &MonikerResult) -> scip_types::Symbol {
.into(),
descriptors,
..Default::default()
- }
+ })
}
#[cfg(test)]
mod test {
use super::*;
- use hir::Semantics;
- use ide::{AnalysisHost, FilePosition};
- use ide_db::defs::IdentClass;
- use ide_db::{base_db::fixture::ChangeFixture, helpers::pick_best_token};
+ use ide::{AnalysisHost, FilePosition, StaticIndex, TextSize};
+ use ide_db::base_db::fixture::ChangeFixture;
use scip::symbol::format_symbol;
- use syntax::SyntaxKind::*;
- use syntax::{AstNode, T};
fn position(ra_fixture: &str) -> (AnalysisHost, FilePosition) {
let mut host = AnalysisHost::default();
@@ -272,53 +262,33 @@ mod test {
fn check_symbol(ra_fixture: &str, expected: &str) {
let (host, position) = position(ra_fixture);
+ let analysis = host.analysis();
+ let si = StaticIndex::compute(&analysis);
+
let FilePosition { file_id, offset } = position;
- let db = host.raw_database();
- let sema = &Semantics::new(db);
- let file = sema.parse(file_id).syntax().clone();
- let original_token = pick_best_token(file.token_at_offset(offset), |kind| match kind {
- IDENT
- | INT_NUMBER
- | LIFETIME_IDENT
- | T![self]
- | T![super]
- | T![crate]
- | T![Self]
- | COMMENT => 2,
- kind if kind.is_trivia() => 0,
- _ => 1,
- })
- .expect("OK OK");
-
- let navs = sema
- .descend_into_macros(original_token.clone())
- .into_iter()
- .filter_map(|token| {
- IdentClass::classify_token(sema, &token).map(IdentClass::definitions).map(|it| {
- it.into_iter().flat_map(|def| {
- let module = def.module(db).unwrap();
- let current_crate = module.krate();
-
- match MonikerResult::from_def(sema.db, def, current_crate) {
- Some(moniker_result) => Some(moniker_to_symbol(&moniker_result)),
- None => None,
- }
- })
- })
- })
- .flatten()
- .collect::<Vec<_>>();
+ let mut found_symbol = None;
+ for file in &si.files {
+ if file.file_id != file_id {
+ continue;
+ }
+ for &(range, id) in &file.tokens {
+ if range.contains(offset - TextSize::from(1)) {
+ let token = si.tokens.get(id).unwrap();
+ found_symbol = token_to_symbol(token);
+ break;
+ }
+ }
+ }
if expected == "" {
- assert_eq!(0, navs.len(), "must have no symbols {:?}", navs);
+ assert!(found_symbol.is_none(), "must have no symbols {:?}", found_symbol);
return;
}
- assert_eq!(1, navs.len(), "must have one symbol {:?}", navs);
-
- let res = navs.get(0).unwrap();
- let formatted = format_symbol(res.clone());
+ assert!(found_symbol.is_some(), "must have one symbol {:?}", found_symbol);
+ let res = found_symbol.unwrap();
+ let formatted = format_symbol(res);
assert_eq!(formatted, expected);
}
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs
index 54dcb42d9..85322f12a 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs
@@ -7,7 +7,7 @@
//! configure the server itself, feature flags are passed into analysis, and
//! tweak things like automatic insertion of `()` in completions.
-use std::{ffi::OsString, fmt, iter, path::PathBuf};
+use std::{fmt, iter, path::PathBuf};
use flycheck::FlycheckConfig;
use ide::{
@@ -22,7 +22,8 @@ use ide_db::{
use itertools::Itertools;
use lsp_types::{ClientCapabilities, MarkupKind};
use project_model::{
- CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest, RustcSource, UnsetTestCrates,
+ CargoConfig, CargoFeatures, ProjectJson, ProjectJsonData, ProjectManifest, RustcSource,
+ UnsetTestCrates,
};
use rustc_hash::{FxHashMap, FxHashSet};
use serde::{de::DeserializeOwned, Deserialize};
@@ -68,6 +69,19 @@ config_data! {
cargo_autoreload: bool = "true",
/// Run build scripts (`build.rs`) for more precise code analysis.
cargo_buildScripts_enable: bool = "true",
+ /// Specifies the working directory for running build scripts.
+ /// - "workspace": run build scripts for a workspace in the workspace's root directory.
+ /// This is incompatible with `#rust-analyzer.cargo.buildScripts.invocationStrategy#` set to `once`.
+ /// - "root": run build scripts in the project's root directory.
+ /// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
+ /// is set.
+ cargo_buildScripts_invocationLocation: InvocationLocation = "\"workspace\"",
+ /// Specifies the invocation strategy to use when running the build scripts command.
+ /// If `per_workspace` is set, the command will be executed for each workspace.
+ /// If `once` is set, the command will be executed once.
+ /// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
+ /// is set.
+ cargo_buildScripts_invocationStrategy: InvocationStrategy = "\"per_workspace\"",
/// Override the command rust-analyzer uses to run build scripts and
/// build procedural macros. The command is required to output json
/// and should therefore include `--message-format=json` or a similar
@@ -84,14 +98,22 @@ config_data! {
/// Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
/// avoid checking unnecessary things.
cargo_buildScripts_useRustcWrapper: bool = "true",
+ /// Extra environment variables that will be set when running cargo, rustc
+ /// or other commands within the workspace. Useful for setting RUSTFLAGS.
+ cargo_extraEnv: FxHashMap<String, String> = "{}",
/// List of features to activate.
///
/// Set this to `"all"` to pass `--all-features` to cargo.
- cargo_features: CargoFeatures = "[]",
+ cargo_features: CargoFeaturesDef = "[]",
/// Whether to pass `--no-default-features` to cargo.
cargo_noDefaultFeatures: bool = "false",
- /// Internal config for debugging, disables loading of sysroot crates.
- cargo_noSysroot: bool = "false",
+ /// Relative path to the sysroot, or "discover" to try to automatically find it via
+ /// "rustc --print sysroot".
+ ///
+ /// Unsetting this disables sysroot loading.
+ ///
+ /// This option does not take effect until rust-analyzer is restarted.
+ cargo_sysroot: Option<String> = "\"discover\"",
/// Compilation target override (target triple).
cargo_target: Option<String> = "null",
/// Unsets `#[cfg(test)]` for the specified crates.
@@ -105,11 +127,28 @@ config_data! {
checkOnSave_enable: bool = "true",
/// Extra arguments for `cargo check`.
checkOnSave_extraArgs: Vec<String> = "[]",
+ /// Extra environment variables that will be set when running `cargo check`.
+ /// Extends `#rust-analyzer.cargo.extraEnv#`.
+ checkOnSave_extraEnv: FxHashMap<String, String> = "{}",
/// List of features to activate. Defaults to
/// `#rust-analyzer.cargo.features#`.
///
/// Set to `"all"` to pass `--all-features` to Cargo.
- checkOnSave_features: Option<CargoFeatures> = "null",
+ checkOnSave_features: Option<CargoFeaturesDef> = "null",
+ /// Specifies the working directory for running checks.
+ /// - "workspace": run checks for workspaces in the corresponding workspaces' root directories.
+ // FIXME: Ideally we would support this in some way
+ /// This falls back to "root" if `#rust-analyzer.cargo.checkOnSave.invocationStrategy#` is set to `once`.
+ /// - "root": run checks in the project's root directory.
+ /// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
+ /// is set.
+ checkOnSave_invocationLocation: InvocationLocation = "\"workspace\"",
+ /// Specifies the invocation strategy to use when running the checkOnSave command.
+ /// If `per_workspace` is set, the command will be executed for each workspace.
+ /// If `once` is set, the command will be executed once.
+ /// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
+ /// is set.
+ checkOnSave_invocationStrategy: InvocationStrategy = "\"per_workspace\"",
/// Whether to pass `--no-default-features` to Cargo. Defaults to
/// `#rust-analyzer.cargo.noDefaultFeatures#`.
checkOnSave_noDefaultFeatures: Option<bool> = "null",
@@ -219,7 +258,6 @@ config_data! {
files_excludeDirs: Vec<PathBuf> = "[]",
/// Controls file watching implementation.
files_watcher: FilesWatcherDef = "\"client\"",
-
/// Enables highlighting of related references while the cursor is on `break`, `loop`, `while`, or `for` keywords.
highlightRelated_breakPoints_enable: bool = "true",
/// Enables highlighting of all exit points while the cursor is on any `return`, `?`, `fn`, or return type arrow (`->`).
@@ -263,6 +301,8 @@ config_data! {
imports_group_enable: bool = "true",
/// Whether to allow import insertion to merge new imports into single path glob imports like `use std::fmt::*;`.
imports_merge_glob: bool = "true",
+ /// Prefer to unconditionally use imports of the core and alloc crate, over the std crate.
+ imports_prefer_no_std: bool = "false",
/// The path structure for newly inserted paths to use.
imports_prefix: ImportPrefixDef = "\"plain\"",
@@ -307,6 +347,7 @@ config_data! {
/// Join lines unwraps trivial blocks.
joinLines_unwrapTrivialBlock: bool = "true",
+
/// Whether to show `Debug` lens. Only applies when
/// `#rust-analyzer.lens.enable#` is set.
lens_debug_enable: bool = "true",
@@ -318,6 +359,8 @@ config_data! {
/// Whether to show `Implementations` lens. Only applies when
/// `#rust-analyzer.lens.enable#` is set.
lens_implementations_enable: bool = "true",
+ /// Where to render annotations.
+ lens_location: AnnotationLocation = "\"above_name\"",
/// Whether to show `References` lens for Struct, Enum, and Union.
/// Only applies when `#rust-analyzer.lens.enable#` is set.
lens_references_adt_enable: bool = "false",
@@ -359,6 +402,9 @@ config_data! {
/// this is rust-analyzer itself, but we override this in tests).
procMacro_server: Option<PathBuf> = "null",
+ /// Exclude imports from find-all-references.
+ references_excludeImports: bool = "false",
+
/// Command to be executed instead of 'cargo' for runnables.
runnables_command: Option<String> = "null",
/// Additional arguments to be passed to cargo for runnables such as
@@ -494,6 +540,25 @@ pub struct LensConfig {
pub refs_adt: bool, // for Struct, Enum, Union and Trait
pub refs_trait: bool, // for Struct, Enum, Union and Trait
pub enum_variant_refs: bool,
+
+ // annotations
+ pub location: AnnotationLocation,
+}
+
+#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum AnnotationLocation {
+ AboveName,
+ AboveWholeItem,
+}
+
+impl From<AnnotationLocation> for ide::AnnotationLocation {
+ fn from(location: AnnotationLocation) -> Self {
+ match location {
+ AnnotationLocation::AboveName => ide::AnnotationLocation::AboveName,
+ AnnotationLocation::AboveWholeItem => ide::AnnotationLocation::AboveWholeItem,
+ }
+ }
}
impl LensConfig {
@@ -918,6 +983,7 @@ impl Config {
ExprFillDefaultDef::Default => ExprFillDefaultMode::Default,
},
insert_use: self.insert_use_config(),
+ prefer_no_std: self.data.imports_prefer_no_std,
}
}
@@ -929,19 +995,31 @@ impl Config {
}
}
+ pub fn extra_env(&self) -> &FxHashMap<String, String> {
+ &self.data.cargo_extraEnv
+ }
+
+ pub fn check_on_save_extra_env(&self) -> FxHashMap<String, String> {
+ let mut extra_env = self.data.cargo_extraEnv.clone();
+ extra_env.extend(self.data.checkOnSave_extraEnv.clone());
+ extra_env
+ }
+
pub fn lru_capacity(&self) -> Option<usize> {
self.data.lru_capacity
}
- pub fn proc_macro_srv(&self) -> Option<(AbsPathBuf, Vec<OsString>)> {
+ pub fn proc_macro_srv(&self) -> Option<(AbsPathBuf, /* is path explicitly set */ bool)> {
if !self.data.procMacro_enable {
return None;
}
- let path = match &self.data.procMacro_server {
- Some(it) => self.root_path.join(it),
- None => AbsPathBuf::assert(std::env::current_exe().ok()?),
- };
- Some((path, vec!["proc-macro".into()]))
+ Some(match &self.data.procMacro_server {
+ Some(it) => (
+ AbsPathBuf::try_from(it.clone()).unwrap_or_else(|path| self.root_path.join(path)),
+ true,
+ ),
+ None => (AbsPathBuf::assert(std::env::current_exe().ok()?), false),
+ })
}
pub fn dummy_replacements(&self) -> &FxHashMap<Box<str>, Box<[Box<str>]>> {
@@ -984,20 +1062,39 @@ impl Config {
RustcSource::Path(self.root_path.join(rustc_src))
}
});
+ let sysroot = self.data.cargo_sysroot.as_ref().map(|sysroot| {
+ if sysroot == "discover" {
+ RustcSource::Discover
+ } else {
+ RustcSource::Path(self.root_path.join(sysroot))
+ }
+ });
CargoConfig {
- no_default_features: self.data.cargo_noDefaultFeatures,
- all_features: matches!(self.data.cargo_features, CargoFeatures::All),
features: match &self.data.cargo_features {
- CargoFeatures::All => vec![],
- CargoFeatures::Listed(it) => it.clone(),
+ CargoFeaturesDef::All => CargoFeatures::All,
+ CargoFeaturesDef::Selected(features) => CargoFeatures::Selected {
+ features: features.clone(),
+ no_default_features: self.data.cargo_noDefaultFeatures,
+ },
},
target: self.data.cargo_target.clone(),
- no_sysroot: self.data.cargo_noSysroot,
+ sysroot,
rustc_source,
unset_test_crates: UnsetTestCrates::Only(self.data.cargo_unsetTest.clone()),
wrap_rustc_in_build_scripts: self.data.cargo_buildScripts_useRustcWrapper,
+ invocation_strategy: match self.data.cargo_buildScripts_invocationStrategy {
+ InvocationStrategy::Once => project_model::InvocationStrategy::Once,
+ InvocationStrategy::PerWorkspace => project_model::InvocationStrategy::PerWorkspace,
+ },
+ invocation_location: match self.data.cargo_buildScripts_invocationLocation {
+ InvocationLocation::Root => {
+ project_model::InvocationLocation::Root(self.root_path.clone())
+ }
+ InvocationLocation::Workspace => project_model::InvocationLocation::Workspace,
+ },
run_build_script_command: self.data.cargo_buildScripts_overrideCommand.clone(),
+ extra_env: self.data.cargo_extraEnv.clone(),
}
}
@@ -1023,7 +1120,23 @@ impl Config {
Some(args) if !args.is_empty() => {
let mut args = args.clone();
let command = args.remove(0);
- FlycheckConfig::CustomCommand { command, args }
+ FlycheckConfig::CustomCommand {
+ command,
+ args,
+ extra_env: self.check_on_save_extra_env(),
+ invocation_strategy: match self.data.checkOnSave_invocationStrategy {
+ InvocationStrategy::Once => flycheck::InvocationStrategy::Once,
+ InvocationStrategy::PerWorkspace => {
+ flycheck::InvocationStrategy::PerWorkspace
+ }
+ },
+ invocation_location: match self.data.checkOnSave_invocationLocation {
+ InvocationLocation::Root => {
+ flycheck::InvocationLocation::Root(self.root_path.clone())
+ }
+ InvocationLocation::Workspace => flycheck::InvocationLocation::Workspace,
+ },
+ }
}
Some(_) | None => FlycheckConfig::CargoCommand {
command: self.data.checkOnSave_command.clone(),
@@ -1039,7 +1152,7 @@ impl Config {
.unwrap_or(self.data.cargo_noDefaultFeatures),
all_features: matches!(
self.data.checkOnSave_features.as_ref().unwrap_or(&self.data.cargo_features),
- CargoFeatures::All
+ CargoFeaturesDef::All
),
features: match self
.data
@@ -1047,10 +1160,11 @@ impl Config {
.clone()
.unwrap_or_else(|| self.data.cargo_features.clone())
{
- CargoFeatures::All => vec![],
- CargoFeatures::Listed(it) => it,
+ CargoFeaturesDef::All => vec![],
+ CargoFeaturesDef::Selected(it) => it,
},
extra_args: self.data.checkOnSave_extraArgs.clone(),
+ extra_env: self.check_on_save_extra_env(),
},
};
Some(flycheck_config)
@@ -1133,6 +1247,7 @@ impl Config {
CallableCompletionDef::None => None,
},
insert_use: self.insert_use_config(),
+ prefer_no_std: self.data.imports_prefer_no_std,
snippet_cap: SnippetCap::new(try_or_def!(
self.caps
.text_document
@@ -1147,6 +1262,10 @@ impl Config {
}
}
+ pub fn find_all_refs_exclude_imports(&self) -> bool {
+ self.data.references_excludeImports
+ }
+
pub fn snippet_cap(&self) -> bool {
self.experimental("snippetTextEdit")
}
@@ -1156,6 +1275,7 @@ impl Config {
snippet_cap: SnippetCap::new(self.experimental("snippetTextEdit")),
allowed: None,
insert_use: self.insert_use_config(),
+ prefer_no_std: self.data.imports_prefer_no_std,
}
}
@@ -1185,6 +1305,7 @@ impl Config {
refs_trait: self.data.lens_enable && self.data.lens_references_trait_enable,
enum_variant_refs: self.data.lens_enable
&& self.data.lens_references_enumVariant_enable,
+ location: self.data.lens_location,
}
}
@@ -1509,10 +1630,24 @@ enum CallableCompletionDef {
#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)]
-enum CargoFeatures {
+enum CargoFeaturesDef {
#[serde(deserialize_with = "de_unit_v::all")]
All,
- Listed(Vec<String>),
+ Selected(Vec<String>),
+}
+
+#[derive(Deserialize, Debug, Clone)]
+#[serde(rename_all = "snake_case")]
+enum InvocationStrategy {
+ Once,
+ PerWorkspace,
+}
+
+#[derive(Deserialize, Debug, Clone)]
+#[serde(rename_all = "snake_case")]
+enum InvocationLocation {
+ Root,
+ Workspace,
}
#[derive(Deserialize, Debug, Clone)]
@@ -1857,7 +1992,7 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
"Only show mutable reborrow hints."
]
},
- "CargoFeatures" => set! {
+ "CargoFeaturesDef" => set! {
"anyOf": [
{
"type": "string",
@@ -1874,7 +2009,7 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
}
],
},
- "Option<CargoFeatures>" => set! {
+ "Option<CargoFeaturesDef>" => set! {
"anyOf": [
{
"type": "string",
@@ -1921,6 +2056,30 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
"Use server-side file watching",
],
},
+ "AnnotationLocation" => set! {
+ "type": "string",
+ "enum": ["above_name", "above_whole_item"],
+ "enumDescriptions": [
+ "Render annotations above the name of the item.",
+ "Render annotations above the whole item, including documentation comments and attributes."
+ ],
+ },
+ "InvocationStrategy" => set! {
+ "type": "string",
+ "enum": ["per_workspace", "once"],
+ "enumDescriptions": [
+ "The command will be executed for each workspace.",
+ "The command will be executed once."
+ ],
+ },
+ "InvocationLocation" => set! {
+ "type": "string",
+ "enum": ["workspace", "root"],
+ "enumDescriptions": [
+ "The command will be executed in the corresponding workspace root.",
+ "The command will be executed in the project root."
+ ],
+ },
_ => panic!("missing entry for {}: {}", ty, default),
}
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/dispatch.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/dispatch.rs
index f16559148..57899b599 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/dispatch.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/dispatch.rs
@@ -52,7 +52,7 @@ impl<'a> RequestDispatcher<'a> {
let _pctx = stdx::panic_context::enter(panic_context);
f(self.global_state, params)
};
- if let Ok(response) = result_to_response::<R>(req.id.clone(), result) {
+ if let Ok(response) = result_to_response::<R>(req.id, result) {
self.global_state.respond(response);
}
@@ -80,7 +80,7 @@ impl<'a> RequestDispatcher<'a> {
f(global_state_snapshot, params)
});
- if let Ok(response) = thread_result_to_response::<R>(req.id.clone(), result) {
+ if let Ok(response) = thread_result_to_response::<R>(req.id, result) {
self.global_state.respond(response);
}
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/from_proto.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/from_proto.rs
index 7bdd34d1f..f2db9a273 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/from_proto.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/from_proto.rs
@@ -95,22 +95,22 @@ pub(crate) fn annotation(
match resolve {
lsp_ext::CodeLensResolveData::Impls(params) => {
- let file_id =
- snap.url_to_file_id(&params.text_document_position_params.text_document.uri)?;
+ let pos @ FilePosition { file_id, .. } =
+ file_position(snap, params.text_document_position_params)?;
let line_index = snap.file_line_index(file_id)?;
Ok(Annotation {
range: text_range(&line_index, code_lens.range)?,
- kind: AnnotationKind::HasImpls { file_id, data: None },
+ kind: AnnotationKind::HasImpls { pos, data: None },
})
}
lsp_ext::CodeLensResolveData::References(params) => {
- let file_id = snap.url_to_file_id(&params.text_document.uri)?;
+ let pos @ FilePosition { file_id, .. } = file_position(snap, params)?;
let line_index = snap.file_line_index(file_id)?;
Ok(Annotation {
range: text_range(&line_index, code_lens.range)?,
- kind: AnnotationKind::HasReferences { file_id, data: None },
+ kind: AnnotationKind::HasReferences { pos, data: None },
})
}
}
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs
index 92df4d70f..3fb06c31f 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs
@@ -64,7 +64,7 @@ pub(crate) struct GlobalState {
pub(crate) source_root_config: SourceRootConfig,
pub(crate) proc_macro_clients: Vec<Result<ProcMacroServer, String>>,
- pub(crate) flycheck: Vec<FlycheckHandle>,
+ pub(crate) flycheck: Arc<[FlycheckHandle]>,
pub(crate) flycheck_sender: Sender<flycheck::Message>,
pub(crate) flycheck_receiver: Receiver<flycheck::Message>,
@@ -117,6 +117,7 @@ pub(crate) struct GlobalStateSnapshot {
vfs: Arc<RwLock<(vfs::Vfs, NoHashHashMap<FileId, LineEndings>)>>,
pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>,
pub(crate) proc_macros_loaded: bool,
+ pub(crate) flycheck: Arc<[FlycheckHandle]>,
}
impl std::panic::UnwindSafe for GlobalStateSnapshot {}
@@ -155,7 +156,7 @@ impl GlobalState {
source_root_config: SourceRootConfig::default(),
proc_macro_clients: vec![],
- flycheck: Vec::new(),
+ flycheck: Arc::new([]),
flycheck_sender,
flycheck_receiver,
@@ -185,11 +186,48 @@ impl GlobalState {
let (change, changed_files) = {
let mut change = Change::new();
let (vfs, line_endings_map) = &mut *self.vfs.write();
- let changed_files = vfs.take_changes();
+ let mut changed_files = vfs.take_changes();
if changed_files.is_empty() {
return false;
}
+ // important: this needs to be a stable sort, the order between changes is relevant
+ // for the same file ids
+ changed_files.sort_by_key(|file| file.file_id);
+ // We need to fix up the changed events a bit, if we have a create or modify for a file
+ // id that is followed by a delete we actually no longer observe the file text from the
+ // create or modify which may cause problems later on
+ changed_files.dedup_by(|a, b| {
+ use vfs::ChangeKind::*;
+
+ if a.file_id != b.file_id {
+ return false;
+ }
+
+ match (a.change_kind, b.change_kind) {
+ // duplicate can be merged
+ (Create, Create) | (Modify, Modify) | (Delete, Delete) => true,
+ // just leave the create, modify is irrelevant
+ (Create, Modify) => {
+ std::mem::swap(a, b);
+ true
+ }
+ // modify becomes irrelevant if the file is deleted
+ (Modify, Delete) => true,
+ // we should fully remove this occurrence,
+ // but leaving just a delete works as well
+ (Create, Delete) => true,
+ // this is equivalent to a modify
+ (Delete, Create) => {
+ a.change_kind = Modify;
+ true
+ }
+ // can't really occur
+ (Modify, Create) => false,
+ (Delete, Modify) => false,
+ }
+ });
+
for file in &changed_files {
if let Some(path) = vfs.file_path(file.file_id).as_path() {
let path = path.to_path_buf();
@@ -258,6 +296,7 @@ impl GlobalState {
mem_docs: self.mem_docs.clone(),
semantic_tokens_cache: Arc::clone(&self.semantic_tokens_cache),
proc_macros_loaded: !self.fetch_build_data_queue.last_op_result().0.is_empty(),
+ flycheck: self.flycheck.clone(),
}
}
@@ -317,6 +356,10 @@ impl GlobalState {
}
}
+ pub(crate) fn is_completed(&self, request: &lsp_server::Request) -> bool {
+ self.req_queue.incoming.is_completed(&request.id)
+ }
+
fn send(&mut self, message: lsp_server::Message) {
self.sender.send(message).unwrap()
}
@@ -357,6 +400,10 @@ impl GlobalStateSnapshot {
url_from_abs_path(path)
}
+ pub(crate) fn file_id_to_file_path(&self, file_id: FileId) -> vfs::VfsPath {
+ self.vfs.read().0.file_path(file_id)
+ }
+
pub(crate) fn cargo_target_for_crate_root(
&self,
crate_id: CrateId,
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers.rs
index e79cf3d3f..34795a8eb 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers.rs
@@ -10,8 +10,8 @@ use std::{
use anyhow::Context;
use ide::{
AnnotationConfig, AssistKind, AssistResolveStrategy, FileId, FilePosition, FileRange,
- HoverAction, HoverGotoTypeData, Query, RangeInfo, Runnable, RunnableKind, SingleResolve,
- SourceChange, TextEdit,
+ HoverAction, HoverGotoTypeData, Query, RangeInfo, ReferenceCategory, Runnable, RunnableKind,
+ SingleResolve, SourceChange, TextEdit,
};
use ide_db::SymbolKind;
use lsp_server::ErrorCode;
@@ -658,7 +658,7 @@ pub(crate) fn handle_parent_module(
// check if invoked at the crate root
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
- let crate_id = match snap.analysis.crate_for(file_id)?.first() {
+ let crate_id = match snap.analysis.crates_for(file_id)?.first() {
Some(&crate_id) => crate_id,
None => return Ok(None),
};
@@ -1012,6 +1012,8 @@ pub(crate) fn handle_references(
let _p = profile::span("handle_references");
let position = from_proto::file_position(&snap, params.text_document_position)?;
+ let exclude_imports = snap.config.find_all_refs_exclude_imports();
+
let refs = match snap.analysis.find_all_refs(position, None)? {
None => return Ok(None),
Some(refs) => refs,
@@ -1032,7 +1034,11 @@ pub(crate) fn handle_references(
refs.references
.into_iter()
.flat_map(|(file_id, refs)| {
- refs.into_iter().map(move |(range, _)| FileRange { file_id, range })
+ refs.into_iter()
+ .filter(|&(_, category)| {
+ !exclude_imports || category != Some(ReferenceCategory::Import)
+ })
+ .map(move |(range, _)| FileRange { file_id, range })
})
.chain(decl)
})
@@ -1234,6 +1240,7 @@ pub(crate) fn handle_code_lens(
annotate_references: lens_config.refs_adt,
annotate_method_references: lens_config.method_refs,
annotate_enum_variant_references: lens_config.enum_variant_refs,
+ location: lens_config.location.into(),
},
file_id,
)?;
@@ -1283,7 +1290,7 @@ pub(crate) fn handle_document_highlight(
.into_iter()
.map(|ide::HighlightedRange { range, category }| lsp_types::DocumentHighlight {
range: to_proto::range(&line_index, range),
- kind: category.map(to_proto::document_highlight_kind),
+ kind: category.and_then(to_proto::document_highlight_kind),
})
.collect();
Ok(Some(res))
@@ -1775,13 +1782,22 @@ fn run_rustfmt(
) -> Result<Option<Vec<lsp_types::TextEdit>>> {
let file_id = from_proto::file_id(snap, &text_document.uri)?;
let file = snap.analysis.file_text(file_id)?;
- let crate_ids = snap.analysis.crate_for(file_id)?;
+
+ // find the edition of the package the file belongs to
+ // (if it belongs to multiple we'll just pick the first one and pray)
+ let edition = snap
+ .analysis
+ .relevant_crates_for(file_id)?
+ .into_iter()
+ .find_map(|crate_id| snap.cargo_target_for_crate_root(crate_id))
+ .map(|(ws, target)| ws[ws[target].package].edition);
let line_index = snap.file_line_index(file_id)?;
let mut command = match snap.config.rustfmt() {
RustfmtConfig::Rustfmt { extra_args, enable_range_formatting } => {
let mut cmd = process::Command::new(toolchain::rustfmt());
+ cmd.envs(snap.config.extra_env());
cmd.args(extra_args);
// try to chdir to the file so we can respect `rustfmt.toml`
// FIXME: use `rustfmt --config-path` once
@@ -1800,9 +1816,7 @@ fn run_rustfmt(
);
}
}
- if let Some(&crate_id) = crate_ids.first() {
- // Assume all crates are in the same edition
- let edition = snap.analysis.crate_edition(crate_id)?;
+ if let Some(edition) = edition {
cmd.arg("--edition");
cmd.arg(edition.to_string());
}
@@ -1839,6 +1853,7 @@ fn run_rustfmt(
}
RustfmtConfig::CustomCommand { command, args } => {
let mut cmd = process::Command::new(command);
+ cmd.envs(snap.config.extra_env());
cmd.args(args);
cmd
}
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/integrated_benchmarks.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/integrated_benchmarks.rs
index e49a98685..96b1cb6b1 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/integrated_benchmarks.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/integrated_benchmarks.rs
@@ -145,6 +145,7 @@ fn integrated_completion_benchmark() {
skip_glob_imports: true,
},
snippets: Vec::new(),
+ prefer_no_std: false,
};
let position =
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
@@ -182,6 +183,7 @@ fn integrated_completion_benchmark() {
skip_glob_imports: true,
},
snippets: Vec::new(),
+ prefer_no_std: false,
};
let position =
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp_utils.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp_utils.rs
index 5a37cbe2e..b3cea64d4 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp_utils.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp_utils.rs
@@ -87,6 +87,7 @@ impl GlobalState {
state: Progress,
message: Option<String>,
fraction: Option<f64>,
+ cancel_token: Option<String>,
) {
if !self.config.work_done_progress() {
return;
@@ -95,7 +96,10 @@ impl GlobalState {
assert!((0.0..=1.0).contains(&f));
(f * 100.0) as u32
});
- let token = lsp_types::ProgressToken::String(format!("rustAnalyzer/{}", title));
+ let cancellable = Some(cancel_token.is_some());
+ let token = lsp_types::ProgressToken::String(
+ cancel_token.unwrap_or_else(|| format!("rustAnalyzer/{}", title)),
+ );
let work_done_progress = match state {
Progress::Begin => {
self.send_request::<lsp_types::request::WorkDoneProgressCreate>(
@@ -105,14 +109,14 @@ impl GlobalState {
lsp_types::WorkDoneProgress::Begin(lsp_types::WorkDoneProgressBegin {
title: title.into(),
- cancellable: None,
+ cancellable,
message,
percentage,
})
}
Progress::Report => {
lsp_types::WorkDoneProgress::Report(lsp_types::WorkDoneProgressReport {
- cancellable: None,
+ cancellable,
message,
percentage,
})
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs
index 3cfbc2e4e..2c928a580 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs
@@ -10,7 +10,7 @@ use std::{
use always_assert::always;
use crossbeam_channel::{select, Receiver};
use flycheck::FlycheckHandle;
-use ide_db::base_db::{SourceDatabase, SourceDatabaseExt, VfsPath};
+use ide_db::base_db::{SourceDatabaseExt, VfsPath};
use itertools::Itertools;
use lsp_server::{Connection, Notification, Request};
use lsp_types::notification::Notification as _;
@@ -191,7 +191,7 @@ impl GlobalState {
// NOTE: don't count blocking select! call as a loop-turn time
let _p = profile::span("GlobalState::handle_event");
- tracing::debug!("handle_event({:?})", event);
+ tracing::debug!("{:?} handle_event({:?})", loop_start, event);
let task_queue_len = self.task_pool.handle.len();
if task_queue_len > 0 {
tracing::info!("task queue len: {}", task_queue_len);
@@ -257,7 +257,7 @@ impl GlobalState {
}
};
- self.report_progress("Indexing", state, message, Some(fraction));
+ self.report_progress("Indexing", state, message, Some(fraction), None);
}
}
Event::Vfs(message) => {
@@ -425,7 +425,9 @@ impl GlobalState {
fn handle_task(&mut self, prime_caches_progress: &mut Vec<PrimeCachesProgress>, task: Task) {
match task {
Task::Response(response) => self.respond(response),
- Task::Retry(req) => self.on_request(req),
+ // Only retry requests that haven't been cancelled. Otherwise we do unnecessary work.
+ Task::Retry(req) if !self.is_completed(&req) => self.on_request(req),
+ Task::Retry(_) => (),
Task::Diagnostics(diagnostics_per_file) => {
for (file_id, diagnostics) in diagnostics_per_file {
self.diagnostics.set_native_diagnostics(file_id, diagnostics)
@@ -463,7 +465,7 @@ impl GlobalState {
}
};
- self.report_progress("Fetching", state, msg, None);
+ self.report_progress("Fetching", state, msg, None, None);
}
Task::FetchBuildData(progress) => {
let (state, msg) = match progress {
@@ -479,7 +481,7 @@ impl GlobalState {
};
if let Some(state) = state {
- self.report_progress("Loading", state, msg, None);
+ self.report_progress("Loading", state, msg, None, None);
}
}
}
@@ -516,6 +518,7 @@ impl GlobalState {
state,
Some(format!("{}/{}", n_done, n_total)),
Some(Progress::fraction(n_done, n_total)),
+ None,
)
}
}
@@ -540,7 +543,10 @@ impl GlobalState {
diag.fix,
),
Err(err) => {
- tracing::error!("File with cargo diagnostic not found in VFS: {}", err);
+ tracing::error!(
+ "flycheck {id}: File with cargo diagnostic not found in VFS: {}",
+ err
+ );
}
};
}
@@ -582,7 +588,13 @@ impl GlobalState {
} else {
format!("cargo check (#{})", id + 1)
};
- self.report_progress(&title, state, message, None);
+ self.report_progress(
+ &title,
+ state,
+ message,
+ None,
+ Some(format!("rust-analyzer/checkOnSave/{}", id)),
+ );
}
}
}
@@ -696,7 +708,16 @@ impl GlobalState {
this.cancel(id);
Ok(())
})?
- .on::<lsp_types::notification::WorkDoneProgressCancel>(|_this, _params| {
+ .on::<lsp_types::notification::WorkDoneProgressCancel>(|this, params| {
+ if let lsp_types::NumberOrString::String(s) = &params.token {
+ if let Some(id) = s.strip_prefix("rust-analyzer/checkOnSave/") {
+ if let Ok(id) = u32::from_str_radix(id, 10) {
+ if let Some(flycheck) = this.flycheck.get(id as usize) {
+ flycheck.cancel();
+ }
+ }
+ }
+ }
// Just ignore this. It is OK to continue sending progress
// notifications for this token, as the client can't know when
// we accepted notification.
@@ -709,7 +730,7 @@ impl GlobalState {
.insert(path.clone(), DocumentData::new(params.text_document.version))
.is_err();
if already_exists {
- tracing::error!("duplicate DidOpenTextDocument: {}", path)
+ tracing::error!("duplicate DidOpenTextDocument: {}", path);
}
this.vfs
.write()
@@ -756,69 +777,7 @@ impl GlobalState {
Ok(())
})?
.on::<lsp_types::notification::DidSaveTextDocument>(|this, params| {
- let mut updated = false;
if let Ok(vfs_path) = from_proto::vfs_path(&params.text_document.uri) {
- let (vfs, _) = &*this.vfs.read();
-
- // Trigger flychecks for all workspaces that depend on the saved file
- if let Some(file_id) = vfs.file_id(&vfs_path) {
- let analysis = this.analysis_host.analysis();
- // Crates containing or depending on the saved file
- let crate_ids: Vec<_> = analysis
- .crate_for(file_id)?
- .into_iter()
- .flat_map(|id| {
- this.analysis_host
- .raw_database()
- .crate_graph()
- .transitive_rev_deps(id)
- })
- .sorted()
- .unique()
- .collect();
-
- let crate_root_paths: Vec<_> = crate_ids
- .iter()
- .filter_map(|&crate_id| {
- analysis
- .crate_root(crate_id)
- .map(|file_id| {
- vfs.file_path(file_id).as_path().map(ToOwned::to_owned)
- })
- .transpose()
- })
- .collect::<ide::Cancellable<_>>()?;
- let crate_root_paths: Vec<_> =
- crate_root_paths.iter().map(Deref::deref).collect();
-
- // Find all workspaces that have at least one target containing the saved file
- let workspace_ids =
- this.workspaces.iter().enumerate().filter(|(_, ws)| match ws {
- project_model::ProjectWorkspace::Cargo { cargo, .. } => {
- cargo.packages().any(|pkg| {
- cargo[pkg].targets.iter().any(|&it| {
- crate_root_paths.contains(&cargo[it].root.as_path())
- })
- })
- }
- project_model::ProjectWorkspace::Json { project, .. } => project
- .crates()
- .any(|(c, _)| crate_ids.iter().any(|&crate_id| crate_id == c)),
- project_model::ProjectWorkspace::DetachedFiles { .. } => false,
- });
-
- // Find and trigger corresponding flychecks
- for flycheck in &this.flycheck {
- for (id, _) in workspace_ids.clone() {
- if id == flycheck.id() {
- updated = true;
- flycheck.restart();
- continue;
- }
- }
- }
- }
-
// Re-fetch workspaces if a workspace related file has changed
if let Some(abs_path) = vfs_path.as_path() {
if reload::should_refresh_for_change(&abs_path, ChangeKind::Modify) {
@@ -826,13 +785,90 @@ impl GlobalState {
.request_op(format!("DidSaveTextDocument {}", abs_path.display()));
}
}
+
+ let file_id = this.vfs.read().0.file_id(&vfs_path);
+ if let Some(file_id) = file_id {
+ let world = this.snapshot();
+ let mut updated = false;
+ let task = move || -> std::result::Result<(), ide::Cancelled> {
+ // Trigger flychecks for all workspaces that depend on the saved file
+ // Crates containing or depending on the saved file
+ let crate_ids: Vec<_> = world
+ .analysis
+ .crates_for(file_id)?
+ .into_iter()
+ .flat_map(|id| world.analysis.transitive_rev_deps(id))
+ .flatten()
+ .sorted()
+ .unique()
+ .collect();
+
+ let crate_root_paths: Vec<_> = crate_ids
+ .iter()
+ .filter_map(|&crate_id| {
+ world
+ .analysis
+ .crate_root(crate_id)
+ .map(|file_id| {
+ world
+ .file_id_to_file_path(file_id)
+ .as_path()
+ .map(ToOwned::to_owned)
+ })
+ .transpose()
+ })
+ .collect::<ide::Cancellable<_>>()?;
+ let crate_root_paths: Vec<_> =
+ crate_root_paths.iter().map(Deref::deref).collect();
+
+ // Find all workspaces that have at least one target containing the saved file
+ let workspace_ids =
+ world.workspaces.iter().enumerate().filter(|(_, ws)| match ws {
+ project_model::ProjectWorkspace::Cargo { cargo, .. } => {
+ cargo.packages().any(|pkg| {
+ cargo[pkg].targets.iter().any(|&it| {
+ crate_root_paths.contains(&cargo[it].root.as_path())
+ })
+ })
+ }
+ project_model::ProjectWorkspace::Json { project, .. } => {
+ project.crates().any(|(c, _)| {
+ crate_ids.iter().any(|&crate_id| crate_id == c)
+ })
+ }
+ project_model::ProjectWorkspace::DetachedFiles { .. } => false,
+ });
+
+ // Find and trigger corresponding flychecks
+ for flycheck in world.flycheck.iter() {
+ for (id, _) in workspace_ids.clone() {
+ if id == flycheck.id() {
+ updated = true;
+ flycheck.restart();
+ continue;
+ }
+ }
+ }
+ // No specific flycheck was triggered, so let's trigger all of them.
+ if !updated {
+ for flycheck in world.flycheck.iter() {
+ flycheck.restart();
+ }
+ }
+ Ok(())
+ };
+ this.task_pool.handle.spawn_with_sender(move |_| {
+ if let Err(e) = std::panic::catch_unwind(task) {
+ tracing::error!("DidSaveTextDocument flycheck task panicked: {e:?}")
+ }
+ });
+ return Ok(());
+ }
}
// No specific flycheck was triggered, so let's trigger all of them.
- if !updated {
- for flycheck in &this.flycheck {
- flycheck.restart();
- }
+ for flycheck in this.flycheck.iter() {
+ flycheck.restart();
}
Ok(())
})?
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs
index e47f70fff..e1f651786 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/reload.rs
@@ -143,6 +143,7 @@ impl GlobalState {
project_model::ProjectWorkspace::load_inline(
it.clone(),
cargo_config.target.as_deref(),
+ &cargo_config.extra_env,
)
}
})
@@ -174,10 +175,8 @@ impl GlobalState {
sender.send(Task::FetchBuildData(BuildDataProgress::Report(msg))).unwrap()
}
};
- let mut res = Vec::new();
- for ws in workspaces.iter() {
- res.push(ws.run_build_scripts(&config, &progress));
- }
+ let res = ProjectWorkspace::run_all_build_scripts(&workspaces, &config, &progress);
+
sender.send(Task::FetchBuildData(BuildDataProgress::End((workspaces, res)))).unwrap();
});
}
@@ -305,41 +304,50 @@ impl GlobalState {
format!("rust-analyzer-proc-macro-srv{}", std::env::consts::EXE_SUFFIX);
if self.proc_macro_clients.is_empty() {
- if let Some((path, args)) = self.config.proc_macro_srv() {
+ if let Some((path, path_manually_set)) = self.config.proc_macro_srv() {
tracing::info!("Spawning proc-macro servers");
self.proc_macro_clients = self
.workspaces
.iter()
.map(|ws| {
- let mut args = args.clone();
- let mut path = path.clone();
-
- if let ProjectWorkspace::Cargo { sysroot, .. }
- | ProjectWorkspace::Json { sysroot, .. } = ws
- {
- tracing::debug!("Found a cargo workspace...");
- if let Some(sysroot) = sysroot.as_ref() {
- tracing::debug!("Found a cargo workspace with a sysroot...");
- let server_path =
- sysroot.root().join("libexec").join(&standalone_server_name);
- if std::fs::metadata(&server_path).is_ok() {
- tracing::debug!(
- "And the server exists at {}",
- server_path.display()
- );
- path = server_path;
- args = vec![];
- } else {
- tracing::debug!(
- "And the server does not exist at {}",
- server_path.display()
- );
+ let (path, args) = if path_manually_set {
+ tracing::debug!(
+ "Pro-macro server path explicitly set: {}",
+ path.display()
+ );
+ (path.clone(), vec![])
+ } else {
+ let mut sysroot_server = None;
+ if let ProjectWorkspace::Cargo { sysroot, .. }
+ | ProjectWorkspace::Json { sysroot, .. } = ws
+ {
+ if let Some(sysroot) = sysroot.as_ref() {
+ let server_path = sysroot
+ .root()
+ .join("libexec")
+ .join(&standalone_server_name);
+ if std::fs::metadata(&server_path).is_ok() {
+ tracing::debug!(
+ "Sysroot proc-macro server exists at {}",
+ server_path.display()
+ );
+ sysroot_server = Some(server_path);
+ } else {
+ tracing::debug!(
+ "Sysroot proc-macro server does not exist at {}",
+ server_path.display()
+ );
+ }
}
}
- }
+ sysroot_server.map_or_else(
+ || (path.clone(), vec!["proc-macro".to_owned()]),
+ |path| (path, vec![]),
+ )
+ };
tracing::info!(?args, "Using proc-macro server at {}", path.display(),);
- ProcMacroServer::spawn(path.clone(), args.clone()).map_err(|err| {
+ ProcMacroServer::spawn(path.clone(), args).map_err(|err| {
let error = format!(
"Failed to run proc-macro server from path {}, error: {:?}",
path.display(),
@@ -398,7 +406,11 @@ impl GlobalState {
dummy_replacements.get(crate_name).map(|v| &**v).unwrap_or_default(),
)
};
- crate_graph.extend(ws.to_crate_graph(&mut load_proc_macro, &mut load));
+ crate_graph.extend(ws.to_crate_graph(
+ &mut load_proc_macro,
+ &mut load,
+ &self.config.cargo().extra_env,
+ ));
}
crate_graph
};
@@ -454,39 +466,54 @@ impl GlobalState {
let config = match self.config.flycheck() {
Some(it) => it,
None => {
- self.flycheck = Vec::new();
+ self.flycheck = Arc::new([]);
self.diagnostics.clear_check_all();
return;
}
};
let sender = self.flycheck_sender.clone();
- self.flycheck = self
- .workspaces
- .iter()
- .enumerate()
- .filter_map(|(id, w)| match w {
- ProjectWorkspace::Cargo { cargo, .. } => Some((id, cargo.workspace_root())),
- ProjectWorkspace::Json { project, .. } => {
- // Enable flychecks for json projects if a custom flycheck command was supplied
- // in the workspace configuration.
- match config {
- FlycheckConfig::CustomCommand { .. } => Some((id, project.path())),
- _ => None,
- }
- }
- ProjectWorkspace::DetachedFiles { .. } => None,
- })
- .map(|(id, root)| {
- let sender = sender.clone();
- FlycheckHandle::spawn(
- id,
- Box::new(move |msg| sender.send(msg).unwrap()),
- config.clone(),
- root.to_path_buf(),
- )
- })
- .collect();
+ let invocation_strategy = match config {
+ FlycheckConfig::CargoCommand { .. } => flycheck::InvocationStrategy::PerWorkspace,
+ FlycheckConfig::CustomCommand { invocation_strategy, .. } => invocation_strategy,
+ };
+
+ self.flycheck = match invocation_strategy {
+ flycheck::InvocationStrategy::Once => vec![FlycheckHandle::spawn(
+ 0,
+ Box::new(move |msg| sender.send(msg).unwrap()),
+ config.clone(),
+ self.config.root_path().clone(),
+ )],
+ flycheck::InvocationStrategy::PerWorkspace => {
+ self.workspaces
+ .iter()
+ .enumerate()
+ .filter_map(|(id, w)| match w {
+ ProjectWorkspace::Cargo { cargo, .. } => Some((id, cargo.workspace_root())),
+ ProjectWorkspace::Json { project, .. } => {
+ // Enable flychecks for json projects if a custom flycheck command was supplied
+ // in the workspace configuration.
+ match config {
+ FlycheckConfig::CustomCommand { .. } => Some((id, project.path())),
+ _ => None,
+ }
+ }
+ ProjectWorkspace::DetachedFiles { .. } => None,
+ })
+ .map(|(id, root)| {
+ let sender = sender.clone();
+ FlycheckHandle::spawn(
+ id,
+ Box::new(move |msg| sender.send(msg).unwrap()),
+ config.clone(),
+ root.to_path_buf(),
+ )
+ })
+ .collect()
+ }
+ }
+ .into();
}
}
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/to_proto.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/to_proto.rs
index e083b9d0e..5936454a7 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/src/to_proto.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/to_proto.rs
@@ -83,10 +83,11 @@ pub(crate) fn structure_node_kind(kind: StructureNodeKind) -> lsp_types::SymbolK
pub(crate) fn document_highlight_kind(
category: ReferenceCategory,
-) -> lsp_types::DocumentHighlightKind {
+) -> Option<lsp_types::DocumentHighlightKind> {
match category {
- ReferenceCategory::Read => lsp_types::DocumentHighlightKind::READ,
- ReferenceCategory::Write => lsp_types::DocumentHighlightKind::WRITE,
+ ReferenceCategory::Read => Some(lsp_types::DocumentHighlightKind::READ),
+ ReferenceCategory::Write => Some(lsp_types::DocumentHighlightKind::WRITE),
+ ReferenceCategory::Import => None,
}
}
@@ -1176,13 +1177,13 @@ pub(crate) fn code_lens(
})
}
}
- AnnotationKind::HasImpls { file_id, data } => {
+ AnnotationKind::HasImpls { pos: file_range, data } => {
if !client_commands_config.show_reference {
return Ok(());
}
- let line_index = snap.file_line_index(file_id)?;
+ let line_index = snap.file_line_index(file_range.file_id)?;
let annotation_range = range(&line_index, annotation.range);
- let url = url(snap, file_id);
+ let url = url(snap, file_range.file_id);
let id = lsp_types::TextDocumentIdentifier { uri: url.clone() };
@@ -1220,13 +1221,13 @@ pub(crate) fn code_lens(
data: Some(to_value(lsp_ext::CodeLensResolveData::Impls(goto_params)).unwrap()),
})
}
- AnnotationKind::HasReferences { file_id, data } => {
+ AnnotationKind::HasReferences { pos: file_range, data } => {
if !client_commands_config.show_reference {
return Ok(());
}
- let line_index = snap.file_line_index(file_id)?;
+ let line_index = snap.file_line_index(file_range.file_id)?;
let annotation_range = range(&line_index, annotation.range);
- let url = url(snap, file_id);
+ let url = url(snap, file_range.file_id);
let id = lsp_types::TextDocumentIdentifier { uri: url.clone() };
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs
index 4cc46af1b..fa55f7d90 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/main.rs
@@ -18,7 +18,6 @@ mod tidy;
use std::{collections::HashMap, path::PathBuf, time::Instant};
-use expect_test::expect;
use lsp_types::{
notification::DidOpenTextDocument,
request::{
@@ -60,7 +59,7 @@ use std::collections::Spam;
"#,
)
.with_config(serde_json::json!({
- "cargo": { "noSysroot": false }
+ "cargo": { "sysroot": "discover" }
}))
.server()
.wait_until_workspace_is_loaded();
@@ -615,7 +614,7 @@ fn main() {{}}
librs, libs
))
.with_config(serde_json::json!({
- "cargo": { "noSysroot": false }
+ "cargo": { "sysroot": "discover" }
}))
.server()
.wait_until_workspace_is_loaded();
@@ -743,7 +742,7 @@ fn main() {
"buildScripts": {
"enable": true
},
- "noSysroot": true,
+ "sysroot": null,
}
}))
.server()
@@ -821,7 +820,10 @@ fn main() {
}
#[test]
+// FIXME: Re-enable once we can run proc-macro tests on rust-lang/rust-analyzer again
+#[cfg(any())]
fn resolve_proc_macro() {
+ use expect_test::expect;
if skip_slow_tests() {
return;
}
@@ -898,7 +900,7 @@ pub fn foo(_input: TokenStream) -> TokenStream {
"buildScripts": {
"enable": true
},
- "noSysroot": true,
+ "sysroot": null,
},
"procMacro": {
"enable": true,
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs
index 4fa88c3c6..7257445da 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs
@@ -34,7 +34,7 @@ impl<'a> Project<'a> {
config: serde_json::json!({
"cargo": {
// Loading standard library is costly, let's ignore it by default
- "noSysroot": true,
+ "sysroot": null,
// Can't use test binary as rustc wrapper.
"buildScripts": {
"useRustcWrapper": false
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs
index 58099a58d..24e68eca6 100644
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs
+++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs
@@ -177,6 +177,7 @@ fn check_licenses() {
let sh = &Shell::new().unwrap();
let expected = "
+(MIT OR Apache-2.0) AND Unicode-DFS-2016
0BSD OR MIT OR Apache-2.0
Apache-2.0
Apache-2.0 OR BSL-1.0
diff --git a/src/tools/rust-analyzer/crates/sourcegen/Cargo.toml b/src/tools/rust-analyzer/crates/sourcegen/Cargo.toml
index a84110d94..e75867e2d 100644
--- a/src/tools/rust-analyzer/crates/sourcegen/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/sourcegen/Cargo.toml
@@ -11,6 +11,3 @@ doctest = false
[dependencies]
xshell = "0.2.2"
-
-[features]
-in-rust-tree = []
diff --git a/src/tools/rust-analyzer/crates/stdx/Cargo.toml b/src/tools/rust-analyzer/crates/stdx/Cargo.toml
index 092b99ae5..e0657ab0f 100644
--- a/src/tools/rust-analyzer/crates/stdx/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/stdx/Cargo.toml
@@ -10,7 +10,7 @@ rust-version = "1.57"
doctest = false
[dependencies]
-libc = "0.2.126"
+libc = "0.2.135"
backtrace = { version = "0.3.65", optional = true }
always-assert = { version = "0.1.2", features = ["log"] }
# Think twice before adding anything here
diff --git a/src/tools/rust-analyzer/crates/syntax/Cargo.toml b/src/tools/rust-analyzer/crates/syntax/Cargo.toml
index 0e2dec386..1ef903371 100644
--- a/src/tools/rust-analyzer/crates/syntax/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/syntax/Cargo.toml
@@ -12,11 +12,11 @@ doctest = false
[dependencies]
cov-mark = "2.0.0-pre.1"
-itertools = "0.10.3"
-rowan = "0.15.8"
+itertools = "0.10.5"
+rowan = "0.15.10"
rustc_lexer = { version = "725.0.0", package = "rustc-ap-rustc_lexer" }
rustc-hash = "1.1.0"
-once_cell = "1.12.0"
+once_cell = "1.15.0"
indexmap = "1.9.1"
smol_str = "0.1.23"
@@ -28,7 +28,7 @@ profile = { path = "../profile", version = "0.0.0" }
[dev-dependencies]
rayon = "1.5.3"
expect-test = "1.4.0"
-proc-macro2 = "1.0.39"
+proc-macro2 = "1.0.47"
quote = "1.0.20"
ungrammar = "1.16.1"
diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/edit_in_place.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/edit_in_place.rs
index eadebbe8a..660c057e9 100644
--- a/src/tools/rust-analyzer/crates/syntax/src/ast/edit_in_place.rs
+++ b/src/tools/rust-analyzer/crates/syntax/src/ast/edit_in_place.rs
@@ -235,6 +235,24 @@ impl ast::GenericParamList {
}
}
}
+
+ /// Constructs a matching [`ast::GenericArgList`]
+ pub fn to_generic_args(&self) -> ast::GenericArgList {
+ let args = self.generic_params().filter_map(|param| match param {
+ ast::GenericParam::LifetimeParam(it) => {
+ Some(ast::GenericArg::LifetimeArg(make::lifetime_arg(it.lifetime()?)))
+ }
+ ast::GenericParam::TypeParam(it) => {
+ Some(ast::GenericArg::TypeArg(make::type_arg(make::ext::ty_name(it.name()?))))
+ }
+ ast::GenericParam::ConstParam(it) => {
+ // Name-only const params get parsed as `TypeArg`s
+ Some(ast::GenericArg::TypeArg(make::type_arg(make::ext::ty_name(it.name()?))))
+ }
+ });
+
+ make::generic_arg_list(args)
+ }
}
impl ast::WhereClause {
@@ -248,6 +266,42 @@ impl ast::WhereClause {
}
}
+impl ast::TypeParam {
+ pub fn remove_default(&self) {
+ if let Some((eq, last)) = self
+ .syntax()
+ .children_with_tokens()
+ .find(|it| it.kind() == T![=])
+ .zip(self.syntax().last_child_or_token())
+ {
+ ted::remove_all(eq..=last);
+
+ // remove any trailing ws
+ if let Some(last) = self.syntax().last_token().filter(|it| it.kind() == WHITESPACE) {
+ last.detach();
+ }
+ }
+ }
+}
+
+impl ast::ConstParam {
+ pub fn remove_default(&self) {
+ if let Some((eq, last)) = self
+ .syntax()
+ .children_with_tokens()
+ .find(|it| it.kind() == T![=])
+ .zip(self.syntax().last_child_or_token())
+ {
+ ted::remove_all(eq..=last);
+
+ // remove any trailing ws
+ if let Some(last) = self.syntax().last_token().filter(|it| it.kind() == WHITESPACE) {
+ last.detach();
+ }
+ }
+ }
+}
+
pub trait Removable: AstNode {
fn remove(&self);
}
@@ -264,7 +318,7 @@ impl Removable for ast::TypeBoundList {
impl ast::PathSegment {
pub fn get_or_create_generic_arg_list(&self) -> ast::GenericArgList {
if self.generic_arg_list().is_none() {
- let arg_list = make::generic_arg_list().clone_for_update();
+ let arg_list = make::generic_arg_list(empty()).clone_for_update();
ted::append_child(self.syntax(), arg_list.syntax());
}
self.generic_arg_list().unwrap()
@@ -591,7 +645,7 @@ impl ast::RecordPatFieldList {
}
fn get_or_insert_comma_after(syntax: &SyntaxNode) -> SyntaxToken {
- let comma = match syntax
+ match syntax
.siblings_with_tokens(Direction::Next)
.filter_map(|it| it.into_token())
.find(|it| it.kind() == T![,])
@@ -602,8 +656,7 @@ fn get_or_insert_comma_after(syntax: &SyntaxNode) -> SyntaxToken {
ted::insert(Position::after(syntax), &comma);
comma
}
- };
- comma
+ }
}
impl ast::StmtList {
diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs
index 83f8bbac5..4057a75e7 100644
--- a/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs
+++ b/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs
@@ -88,6 +88,9 @@ pub mod ext {
block_expr(None, None)
}
+ pub fn ty_name(name: ast::Name) -> ast::Type {
+ ty_path(ident_path(&name.to_string()))
+ }
pub fn ty_bool() -> ast::Type {
ty_path(ident_path("bool"))
}
@@ -160,6 +163,7 @@ pub fn assoc_item_list() -> ast::AssocItemList {
ast_from_text("impl C for D {}")
}
+// FIXME: `ty_params` should be `ast::GenericArgList`
pub fn impl_(
ty: ast::Path,
params: Option<ast::GenericParamList>,
@@ -185,10 +189,6 @@ pub fn impl_trait(
ast_from_text(&format!("impl{ty_params} {trait_} for {ty}{ty_params} {{}}"))
}
-pub(crate) fn generic_arg_list() -> ast::GenericArgList {
- ast_from_text("const S: T<> = ();")
-}
-
pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment {
ast_from_text(&format!("type __ = {name_ref};"))
}
@@ -718,6 +718,21 @@ pub fn generic_param_list(
ast_from_text(&format!("fn f<{args}>() {{ }}"))
}
+pub fn type_arg(ty: ast::Type) -> ast::TypeArg {
+ ast_from_text(&format!("const S: T<{ty}> = ();"))
+}
+
+pub fn lifetime_arg(lifetime: ast::Lifetime) -> ast::LifetimeArg {
+ ast_from_text(&format!("const S: T<{lifetime}> = ();"))
+}
+
+pub(crate) fn generic_arg_list(
+ args: impl IntoIterator<Item = ast::GenericArg>,
+) -> ast::GenericArgList {
+ let args = args.into_iter().join(", ");
+ ast_from_text(&format!("const S: T<{args}> = ();"))
+}
+
pub fn visibility_pub_crate() -> ast::Visibility {
ast_from_text("pub(crate) struct S")
}
diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs
index bb92c51e9..fe82aa907 100644
--- a/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs
+++ b/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs
@@ -873,3 +873,33 @@ impl ast::MatchGuard {
support::child(&self.syntax)
}
}
+
+impl From<ast::Item> for ast::AnyHasAttrs {
+ fn from(node: ast::Item) -> Self {
+ Self::new(node)
+ }
+}
+
+impl From<ast::AssocItem> for ast::AnyHasAttrs {
+ fn from(node: ast::AssocItem) -> Self {
+ Self::new(node)
+ }
+}
+
+impl From<ast::Variant> for ast::AnyHasAttrs {
+ fn from(node: ast::Variant) -> Self {
+ Self::new(node)
+ }
+}
+
+impl From<ast::RecordField> for ast::AnyHasAttrs {
+ fn from(node: ast::RecordField) -> Self {
+ Self::new(node)
+ }
+}
+
+impl From<ast::TupleField> for ast::AnyHasAttrs {
+ fn from(node: ast::TupleField) -> Self {
+ Self::new(node)
+ }
+}
diff --git a/src/tools/rust-analyzer/crates/syntax/src/lib.rs b/src/tools/rust-analyzer/crates/syntax/src/lib.rs
index 4f5e273a5..84c66b27e 100644
--- a/src/tools/rust-analyzer/crates/syntax/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/syntax/src/lib.rs
@@ -92,7 +92,7 @@ impl<T> Parse<T> {
SyntaxNode::new_root(self.green.clone())
}
pub fn errors(&self) -> &[SyntaxError] {
- &*self.errors
+ &self.errors
}
}
diff --git a/src/tools/rust-analyzer/crates/test-utils/src/fixture.rs b/src/tools/rust-analyzer/crates/test-utils/src/fixture.rs
index 8c806e792..c824f5af7 100644
--- a/src/tools/rust-analyzer/crates/test-utils/src/fixture.rs
+++ b/src/tools/rust-analyzer/crates/test-utils/src/fixture.rs
@@ -61,6 +61,8 @@
//! "
//! ```
+use std::iter;
+
use rustc_hash::FxHashMap;
use stdx::trim_indent;
@@ -259,7 +261,7 @@ impl MiniCore {
if res.has_flag(entry) {
panic!("duplicate minicore flag: {:?}", entry);
}
- res.activated_flags.push(entry.to_string());
+ res.activated_flags.push(entry.to_owned());
}
res
@@ -273,35 +275,34 @@ impl MiniCore {
let raw_mini_core = include_str!("./minicore.rs");
let mut lines = raw_mini_core.split_inclusive('\n');
- let mut parsing_flags = false;
let mut implications = Vec::new();
// Parse `//!` preamble and extract flags and dependencies.
- for line in lines.by_ref() {
- let line = match line.strip_prefix("//!") {
- Some(it) => it,
- None => {
- assert!(line.trim().is_empty());
- break;
- }
- };
-
- if parsing_flags {
- let (flag, deps) = line.split_once(':').unwrap();
- let flag = flag.trim();
- self.valid_flags.push(flag.to_string());
- for dep in deps.split(", ") {
- let dep = dep.trim();
- if !dep.is_empty() {
- self.assert_valid_flag(dep);
- implications.push((flag, dep));
- }
- }
+ let trim_doc: fn(&str) -> Option<&str> = |line| match line.strip_prefix("//!") {
+ Some(it) => Some(it),
+ None => {
+ assert!(line.trim().is_empty(), "expected empty line after minicore header");
+ None
}
+ };
+ for line in lines
+ .by_ref()
+ .map_while(trim_doc)
+ .skip_while(|line| !line.contains("Available flags:"))
+ .skip(1)
+ {
+ let (flag, deps) = line.split_once(':').unwrap();
+ let flag = flag.trim();
+
+ self.valid_flags.push(flag.to_string());
+ implications.extend(
+ iter::repeat(flag)
+ .zip(deps.split(", ").map(str::trim).filter(|dep| !dep.is_empty())),
+ );
+ }
- if line.contains("Available flags:") {
- parsing_flags = true;
- }
+ for (_, dep) in &implications {
+ self.assert_valid_flag(dep);
}
for flag in &self.activated_flags {
@@ -332,7 +333,7 @@ impl MiniCore {
}
if let Some(region) = trimmed.strip_prefix("// endregion:") {
let prev = active_regions.pop().unwrap();
- assert_eq!(prev, region);
+ assert_eq!(prev, region, "unbalanced region pairs");
continue;
}
diff --git a/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs b/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs
index 6df29db47..69d2e62b2 100644
--- a/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs
+++ b/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs
@@ -8,35 +8,36 @@
//! We then strip all the code marked with other flags.
//!
//! Available flags:
-//! sized:
-//! unsize: sized
+//! add:
+//! as_ref: sized
+//! bool_impl: option, fn
+//! clone: sized
//! coerce_unsized: unsize
-//! slice:
-//! range:
-//! deref: sized
+//! copy: clone
+//! default: sized
//! deref_mut: deref
-//! index: sized
+//! deref: sized
+//! derive:
+//! drop:
+//! eq: sized
+//! fmt: result
//! fn:
-//! try:
-//! pin:
+//! from: sized
//! future: pin
-//! option:
-//! result:
+//! generator: pin
+//! hash:
+//! index: sized
//! iterator: option
//! iterators: iterator, fn
-//! default: sized
-//! hash:
-//! clone: sized
-//! copy: clone
-//! from: sized
-//! eq: sized
+//! option:
//! ord: eq, option
-//! derive:
-//! fmt: result
-//! bool_impl: option, fn
-//! add:
-//! as_ref: sized
-//! drop:
+//! pin:
+//! range:
+//! result:
+//! sized:
+//! slice:
+//! try:
+//! unsize: sized
pub mod marker {
// region:sized
@@ -182,6 +183,19 @@ pub mod ops {
type Target: ?Sized;
fn deref(&self) -> &Self::Target;
}
+
+ impl<T: ?Sized> Deref for &T {
+ type Target = T;
+ fn deref(&self) -> &T {
+ loop {}
+ }
+ }
+ impl<T: ?Sized> Deref for &mut T {
+ type Target = T;
+ fn deref(&self) -> &T {
+ loop {}
+ }
+ }
// region:deref_mut
#[lang = "deref_mut"]
pub trait DerefMut: Deref {
@@ -347,6 +361,27 @@ pub mod ops {
fn add(self, rhs: Rhs) -> Self::Output;
}
// endregion:add
+
+ // region:generator
+ mod generator {
+ use crate::pin::Pin;
+
+ #[lang = "generator"]
+ pub trait Generator<R = ()> {
+ type Yield;
+ #[lang = "generator_return"]
+ type Return;
+ fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return>;
+ }
+
+ #[lang = "generator_state"]
+ pub enum GeneratorState<Y, R> {
+ Yielded(Y),
+ Complete(R),
+ }
+ }
+ pub use self::generator::{Generator, GeneratorState};
+ // endregion:generator
}
// region:eq
@@ -455,6 +490,19 @@ pub mod pin {
pub struct Pin<P> {
pointer: P,
}
+ impl<P> Pin<P> {
+ pub fn new(pointer: P) -> Pin<P> {
+ loop {}
+ }
+ }
+ // region:deref
+ impl<P: crate::ops::Deref> crate::ops::Deref for Pin<P> {
+ type Target = P::Target;
+ fn deref(&self) -> &P::Target {
+ loop {}
+ }
+ }
+ // endregion:deref
}
// endregion:pin
@@ -536,7 +584,7 @@ pub mod iter {
}
}
}
- pub use self::adapters::{Take, FilterMap};
+ pub use self::adapters::{FilterMap, Take};
mod sources {
mod repeat {
diff --git a/src/tools/rust-analyzer/crates/text-edit/Cargo.toml b/src/tools/rust-analyzer/crates/text-edit/Cargo.toml
index cf14bbd3c..7a90d64a9 100644
--- a/src/tools/rust-analyzer/crates/text-edit/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/text-edit/Cargo.toml
@@ -10,5 +10,5 @@ rust-version = "1.57"
doctest = false
[dependencies]
-itertools = "0.10.3"
+itertools = "0.10.5"
text-size = "1.1.0"
diff --git a/src/tools/rust-analyzer/crates/toolchain/Cargo.toml b/src/tools/rust-analyzer/crates/toolchain/Cargo.toml
index 7d3b9e09e..3e0f31f19 100644
--- a/src/tools/rust-analyzer/crates/toolchain/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/toolchain/Cargo.toml
@@ -10,4 +10,4 @@ rust-version = "1.57"
doctest = false
[dependencies]
-home = "0.5.3"
+home = "0.5.4"
diff --git a/src/tools/rust-analyzer/crates/vfs-notify/Cargo.toml b/src/tools/rust-analyzer/crates/vfs-notify/Cargo.toml
index fcc693a7d..df5dc24e2 100644
--- a/src/tools/rust-analyzer/crates/vfs-notify/Cargo.toml
+++ b/src/tools/rust-analyzer/crates/vfs-notify/Cargo.toml
@@ -14,7 +14,7 @@ tracing = "0.1.35"
jod-thread = "0.1.2"
walkdir = "2.3.2"
crossbeam-channel = "0.5.5"
-notify = "=5.0.0-pre.16"
+notify = "5.0"
vfs = { path = "../vfs", version = "0.0.0" }
paths = { path = "../paths", version = "0.0.0" }
diff --git a/src/tools/rust-analyzer/docs/dev/README.md b/src/tools/rust-analyzer/docs/dev/README.md
index c7f152acc..4ac75b4bb 100644
--- a/src/tools/rust-analyzer/docs/dev/README.md
+++ b/src/tools/rust-analyzer/docs/dev/README.md
@@ -98,7 +98,7 @@ After I am done with the fix, I use `cargo xtask install --client` to try the ne
If I need to fix something in the `rust-analyzer` crate, I feel sad because it's on the boundary between the two processes, and working there is slow.
I usually just `cargo xtask install --server` and poke changes from my live environment.
Note that this uses `--release`, which is usually faster overall, because loading stdlib into debug version of rust-analyzer takes a lot of time.
-To speed things up, sometimes I open a temporary hello-world project which has `"rust-analyzer.cargo.noSysroot": true` in `.code/settings.json`.
+To speed things up, sometimes I open a temporary hello-world project which has `"rust-analyzer.cargo.sysroot": null` in `.code/settings.json`.
This flag causes rust-analyzer to skip loading the sysroot, which greatly reduces the amount of things rust-analyzer needs to do, and makes printf's more useful.
Note that you should only use the `eprint!` family of macros for debugging: stdout is used for LSP communication, and `print!` would break it.
diff --git a/src/tools/rust-analyzer/docs/dev/guide.md b/src/tools/rust-analyzer/docs/dev/guide.md
index 808eb5d10..52a13da31 100644
--- a/src/tools/rust-analyzer/docs/dev/guide.md
+++ b/src/tools/rust-analyzer/docs/dev/guide.md
@@ -40,8 +40,8 @@ terms of files and offsets, and **not** in terms of Rust concepts like structs,
traits, etc. The "typed" API with Rust specific types is slightly lower in the
stack, we'll talk about it later.
-[`AnalysisHost`]: https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ide_api/src/lib.rs#L265-L284
-[`Analysis`]: https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ide_api/src/lib.rs#L291-L478
+[`AnalysisHost`]: https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_ide_api/src/lib.rs#L265-L284
+[`Analysis`]: https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_ide_api/src/lib.rs#L291-L478
The reason for this separation of `Analysis` and `AnalysisHost` is that we want to apply
changes "uniquely", but we might also want to fork an `Analysis` and send it to
@@ -88,9 +88,8 @@ is lower than Cargo's model of packages: each Cargo package consists of several
targets, each of which is a separate crate (or several crates, if you try
different feature combinations).
-Procedural macros should become inputs as well, but currently they are not
-supported. Procedural macro will be a black box `Box<dyn Fn(TokenStream) -> TokenStream>`
-function, and will be inserted into the crate graph just like dependencies.
+Procedural macros are inputs as well, roughly modeled as a crate with a bunch of
+additional black box `dyn Fn(TokenStream) -> TokenStream` functions.
Soon we'll talk how we build an LSP server on top of `Analysis`, but first,
let's deal with that paths issue.
diff --git a/src/tools/rust-analyzer/docs/dev/syntax.md b/src/tools/rust-analyzer/docs/dev/syntax.md
index 30e137013..97e376787 100644
--- a/src/tools/rust-analyzer/docs/dev/syntax.md
+++ b/src/tools/rust-analyzer/docs/dev/syntax.md
@@ -8,10 +8,10 @@ This guide describes the current state of syntax trees and parsing in rust-analy
The things described are implemented in three places
-* [rowan](https://github.com/rust-analyzer/rowan/tree/v0.9.0) -- a generic library for rowan syntax trees.
-* [ra_syntax](https://github.com/rust-lang/rust-analyzer/tree/cf5bdf464cad7ceb9a67e07985a3f4d3799ec0b6/crates/ra_syntax) crate inside rust-analyzer which wraps `rowan` into rust-analyzer specific API.
+* [rowan](https://github.com/rust-analyzer/rowan/tree/v0.15.10) -- a generic library for rowan syntax trees.
+* [syntax](https://github.com/rust-lang/rust-analyzer/tree/36a70b7435c48837018c71576d7bb4e8f763f501/crates/syntax) crate inside rust-analyzer which wraps `rowan` into rust-analyzer specific API.
Nothing in rust-analyzer except this crate knows about `rowan`.
-* [parser](https://github.com/rust-lang/rust-analyzer/tree/cf5bdf464cad7ceb9a67e07985a3f4d3799ec0b6/crates/parser) crate parses input tokens into an `ra_syntax` tree
+* [parser](https://github.com/rust-lang/rust-analyzer/tree/36a70b7435c48837018c71576d7bb4e8f763f501/crates/parser) crate parses input tokens into a `syntax` tree
## Design Goals
diff --git a/src/tools/rust-analyzer/docs/user/generated_config.adoc b/src/tools/rust-analyzer/docs/user/generated_config.adoc
index 72b925726..502833de7 100644
--- a/src/tools/rust-analyzer/docs/user/generated_config.adoc
+++ b/src/tools/rust-analyzer/docs/user/generated_config.adoc
@@ -24,6 +24,25 @@ Automatically refresh project info via `cargo metadata` on
--
Run build scripts (`build.rs`) for more precise code analysis.
--
+[[rust-analyzer.cargo.buildScripts.invocationLocation]]rust-analyzer.cargo.buildScripts.invocationLocation (default: `"workspace"`)::
++
+--
+Specifies the working directory for running build scripts.
+- "workspace": run build scripts for a workspace in the workspace's root directory.
+ This is incompatible with `#rust-analyzer.cargo.buildScripts.invocationStrategy#` set to `once`.
+- "root": run build scripts in the project's root directory.
+This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
+is set.
+--
+[[rust-analyzer.cargo.buildScripts.invocationStrategy]]rust-analyzer.cargo.buildScripts.invocationStrategy (default: `"per_workspace"`)::
++
+--
+Specifies the invocation strategy to use when running the build scripts command.
+If `per_workspace` is set, the command will be executed for each workspace.
+If `once` is set, the command will be executed once.
+This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
+is set.
+--
[[rust-analyzer.cargo.buildScripts.overrideCommand]]rust-analyzer.cargo.buildScripts.overrideCommand (default: `null`)::
+
--
@@ -46,6 +65,12 @@ cargo check --quiet --workspace --message-format=json --all-targets
Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
avoid checking unnecessary things.
--
+[[rust-analyzer.cargo.extraEnv]]rust-analyzer.cargo.extraEnv (default: `{}`)::
++
+--
+Extra environment variables that will be set when running cargo, rustc
+or other commands within the workspace. Useful for setting RUSTFLAGS.
+--
[[rust-analyzer.cargo.features]]rust-analyzer.cargo.features (default: `[]`)::
+
--
@@ -58,10 +83,15 @@ Set this to `"all"` to pass `--all-features` to cargo.
--
Whether to pass `--no-default-features` to cargo.
--
-[[rust-analyzer.cargo.noSysroot]]rust-analyzer.cargo.noSysroot (default: `false`)::
+[[rust-analyzer.cargo.sysroot]]rust-analyzer.cargo.sysroot (default: `"discover"`)::
+
--
-Internal config for debugging, disables loading of sysroot crates.
+Relative path to the sysroot, or "discover" to try to automatically find it via
+"rustc --print sysroot".
+
+Unsetting this disables sysroot loading.
+
+This option does not take effect until rust-analyzer is restarted.
--
[[rust-analyzer.cargo.target]]rust-analyzer.cargo.target (default: `null`)::
+
@@ -93,6 +123,12 @@ Run specified `cargo check` command for diagnostics on save.
--
Extra arguments for `cargo check`.
--
+[[rust-analyzer.checkOnSave.extraEnv]]rust-analyzer.checkOnSave.extraEnv (default: `{}`)::
++
+--
+Extra environment variables that will be set when running `cargo check`.
+Extends `#rust-analyzer.cargo.extraEnv#`.
+--
[[rust-analyzer.checkOnSave.features]]rust-analyzer.checkOnSave.features (default: `null`)::
+
--
@@ -101,6 +137,25 @@ List of features to activate. Defaults to
Set to `"all"` to pass `--all-features` to Cargo.
--
+[[rust-analyzer.checkOnSave.invocationLocation]]rust-analyzer.checkOnSave.invocationLocation (default: `"workspace"`)::
++
+--
+Specifies the working directory for running checks.
+- "workspace": run checks for workspaces in the corresponding workspaces' root directories.
+ This falls back to "root" if `#rust-analyzer.cargo.checkOnSave.invocationStrategy#` is set to `once`.
+- "root": run checks in the project's root directory.
+This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
+is set.
+--
+[[rust-analyzer.checkOnSave.invocationStrategy]]rust-analyzer.checkOnSave.invocationStrategy (default: `"per_workspace"`)::
++
+--
+Specifies the invocation strategy to use when running the checkOnSave command.
+If `per_workspace` is set, the command will be executed for each workspace.
+If `once` is set, the command will be executed once.
+This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
+is set.
+--
[[rust-analyzer.checkOnSave.noDefaultFeatures]]rust-analyzer.checkOnSave.noDefaultFeatures (default: `null`)::
+
--
@@ -353,6 +408,11 @@ Group inserted imports by the https://rust-analyzer.github.io/manual.html#auto-i
--
Whether to allow import insertion to merge new imports into single path glob imports like `use std::fmt::*;`.
--
+[[rust-analyzer.imports.prefer.no.std]]rust-analyzer.imports.prefer.no.std (default: `false`)::
++
+--
+Prefer to unconditionally use imports of the core and alloc crate, over the std crate.
+--
[[rust-analyzer.imports.prefix]]rust-analyzer.imports.prefix (default: `"plain"`)::
+
--
@@ -474,6 +534,11 @@ client doesn't set the corresponding capability.
Whether to show `Implementations` lens. Only applies when
`#rust-analyzer.lens.enable#` is set.
--
+[[rust-analyzer.lens.location]]rust-analyzer.lens.location (default: `"above_name"`)::
++
+--
+Where to render annotations.
+--
[[rust-analyzer.lens.references.adt.enable]]rust-analyzer.lens.references.adt.enable (default: `false`)::
+
--
@@ -546,6 +611,11 @@ This config takes a map of crate names with the exported proc-macro names to ign
Internal config, path to proc-macro server executable (typically,
this is rust-analyzer itself, but we override this in tests).
--
+[[rust-analyzer.references.excludeImports]]rust-analyzer.references.excludeImports (default: `false`)::
++
+--
+Exclude imports from find-all-references.
+--
[[rust-analyzer.runnables.command]]rust-analyzer.runnables.command (default: `null`)::
+
--
diff --git a/src/tools/rust-analyzer/docs/user/manual.adoc b/src/tools/rust-analyzer/docs/user/manual.adoc
index 9bd3b6a69..c30838e5f 100644
--- a/src/tools/rust-analyzer/docs/user/manual.adoc
+++ b/src/tools/rust-analyzer/docs/user/manual.adoc
@@ -174,14 +174,25 @@ On Unix, running the editor from a shell or changing the `.desktop` file to set
==== `rustup`
-`rust-analyzer` is available in `rustup`, but only in the nightly toolchain:
+`rust-analyzer` is available in `rustup`:
[source,bash]
----
-$ rustup +nightly component add rust-analyzer-preview
+$ rustup component add rust-analyzer
----
-However, in contrast to `component add clippy` or `component add rustfmt`, this does not actually place a `rust-analyzer` binary in `~/.cargo/bin`, see https://github.com/rust-lang/rustup/issues/2411[this issue].
+However, in contrast to `component add clippy` or `component add rustfmt`, this does not actually place a `rust-analyzer` binary in `~/.cargo/bin`, see https://github.com/rust-lang/rustup/issues/2411[this issue]. You can find the path to the binary using:
+[source,bash]
+----
+$ rustup which --toolchain stable rust-analyzer
+----
+You can link to there from `~/.cargo/bin` or configure your editor to use the full path.
+
+Alternatively you might be able to configure your editor to start `rust-analyzer` using the command:
+[source,bash]
+----
+$ rustup run stable rust-analyzer
+----
==== Arch Linux
diff --git a/src/tools/rust-analyzer/lib/lsp-server/Cargo.toml b/src/tools/rust-analyzer/lib/lsp-server/Cargo.toml
index 204d120d0..5922bbfdb 100644
--- a/src/tools/rust-analyzer/lib/lsp-server/Cargo.toml
+++ b/src/tools/rust-analyzer/lib/lsp-server/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "lsp-server"
-version = "0.6.0"
+version = "0.7.0"
description = "Generic LSP server scaffold."
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/rust-analyzer/tree/master/lib/lsp-server"
@@ -8,9 +8,9 @@ edition = "2021"
[dependencies]
log = "0.4.17"
-serde_json = "1.0.81"
-serde = { version = "1.0.137", features = ["derive"] }
-crossbeam-channel = "0.5.5"
+serde_json = "1.0.86"
+serde = { version = "1.0.144", features = ["derive"] }
+crossbeam-channel = "0.5.6"
[dev-dependencies]
-lsp-types = "0.93.0"
+lsp-types = "0.93.1"
diff --git a/src/tools/rust-analyzer/lib/lsp-server/src/msg.rs b/src/tools/rust-analyzer/lib/lsp-server/src/msg.rs
index 97e5bd35c..b241561f9 100644
--- a/src/tools/rust-analyzer/lib/lsp-server/src/msg.rs
+++ b/src/tools/rust-analyzer/lib/lsp-server/src/msg.rs
@@ -98,7 +98,7 @@ pub struct ResponseError {
}
#[derive(Clone, Copy, Debug)]
-#[allow(unused)]
+#[non_exhaustive]
pub enum ErrorCode {
// Defined by JSON RPC:
ParseError = -32700,
@@ -135,6 +135,14 @@ pub enum ErrorCode {
///
/// @since 3.17.0
ServerCancelled = -32802,
+
+ /// A request failed but it was syntactically correct, e.g the
+ /// method name was known and the parameters were valid. The error
+ /// message should contain human readable information about why
+ /// the request failed.
+ ///
+ /// @since 3.17.0
+ RequestFailed = -32803,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
diff --git a/src/tools/rust-analyzer/lib/lsp-server/src/req_queue.rs b/src/tools/rust-analyzer/lib/lsp-server/src/req_queue.rs
index 1f3d44715..e5f19be20 100644
--- a/src/tools/rust-analyzer/lib/lsp-server/src/req_queue.rs
+++ b/src/tools/rust-analyzer/lib/lsp-server/src/req_queue.rs
@@ -35,6 +35,7 @@ impl<I> Incoming<I> {
pub fn register(&mut self, id: RequestId, data: I) {
self.pending.insert(id, data);
}
+
pub fn cancel(&mut self, id: RequestId) -> Option<Response> {
let _data = self.complete(id.clone())?;
let error = ResponseError {
@@ -44,9 +45,14 @@ impl<I> Incoming<I> {
};
Some(Response { id, result: None, error: Some(error) })
}
+
pub fn complete(&mut self, id: RequestId) -> Option<I> {
self.pending.remove(&id)
}
+
+ pub fn is_completed(&self, id: &RequestId) -> bool {
+ !self.pending.contains_key(id)
+ }
}
impl<O> Outgoing<O> {
@@ -56,6 +62,7 @@ impl<O> Outgoing<O> {
self.next_id += 1;
Request::new(id, method, params)
}
+
pub fn complete(&mut self, id: RequestId) -> Option<O> {
self.pending.remove(&id)
}
diff --git a/src/tools/rust-analyzer/xtask/Cargo.toml b/src/tools/rust-analyzer/xtask/Cargo.toml
index 95d44e9b9..0be0bf920 100644
--- a/src/tools/rust-analyzer/xtask/Cargo.toml
+++ b/src/tools/rust-analyzer/xtask/Cargo.toml
@@ -7,9 +7,9 @@ edition = "2021"
rust-version = "1.57"
[dependencies]
-anyhow = "1.0.57"
+anyhow = "1.0.62"
flate2 = "1.0.24"
write-json = "0.1.2"
xshell = "0.2.2"
-xflags = "0.2.4"
+xflags = "0.3.0"
# Avoid adding more dependencies to this crate
diff --git a/src/tools/rust-analyzer/xtask/src/flags.rs b/src/tools/rust-analyzer/xtask/src/flags.rs
index 993c64cce..0fce48898 100644
--- a/src/tools/rust-analyzer/xtask/src/flags.rs
+++ b/src/tools/rust-analyzer/xtask/src/flags.rs
@@ -7,10 +7,6 @@ xflags::xflags! {
/// Run custom build command.
cmd xtask {
- default cmd help {
- /// Print help information.
- optional -h, --help
- }
/// Install rust-analyzer server or editor plugin.
cmd install {
@@ -42,9 +38,9 @@ xflags::xflags! {
optional --dry-run
}
/// Builds a benchmark version of rust-analyzer and puts it into `./target`.
- cmd bb
+ cmd bb {
required suffix: String
- {}
+ }
}
}
@@ -58,7 +54,6 @@ pub struct Xtask {
#[derive(Debug)]
pub enum XtaskCmd {
- Help(Help),
Install(Install),
FuzzTests(FuzzTests),
Release(Release),
@@ -69,11 +64,6 @@ pub enum XtaskCmd {
}
#[derive(Debug)]
-pub struct Help {
- pub help: bool,
-}
-
-#[derive(Debug)]
pub struct Install {
pub client: bool,
pub code_bin: Option<String>,
@@ -111,7 +101,10 @@ pub struct Bb {
}
impl Xtask {
- pub const HELP: &'static str = Self::HELP_;
+ #[allow(dead_code)]
+ pub fn from_env_or_exit() -> Self {
+ Self::from_env_or_exit_()
+ }
#[allow(dead_code)]
pub fn from_env() -> xflags::Result<Self> {
diff --git a/src/tools/rust-analyzer/xtask/src/main.rs b/src/tools/rust-analyzer/xtask/src/main.rs
index 335ac324a..a37f469ad 100644
--- a/src/tools/rust-analyzer/xtask/src/main.rs
+++ b/src/tools/rust-analyzer/xtask/src/main.rs
@@ -25,15 +25,12 @@ use std::{
use xshell::{cmd, Shell};
fn main() -> anyhow::Result<()> {
+ let flags = flags::Xtask::from_env_or_exit();
+
let sh = &Shell::new()?;
sh.change_dir(project_root());
- let flags = flags::Xtask::from_env()?;
match flags.subcommand {
- flags::XtaskCmd::Help(_) => {
- println!("{}", flags::Xtask::HELP);
- Ok(())
- }
flags::XtaskCmd::Install(cmd) => cmd.run(sh),
flags::XtaskCmd::FuzzTests(_) => run_fuzzer(sh),
flags::XtaskCmd::Release(cmd) => cmd.run(sh),
diff --git a/src/tools/rustdoc/main.rs b/src/tools/rustdoc/main.rs
index 5b499a1fa..b81f46d12 100644
--- a/src/tools/rustdoc/main.rs
+++ b/src/tools/rustdoc/main.rs
@@ -1,3 +1,6 @@
+#![feature(unix_sigpipe)]
+
+#[unix_sigpipe = "sig_dfl"]
fn main() {
rustdoc::main()
}
diff --git a/src/tools/rustfmt/src/chains.rs b/src/tools/rustfmt/src/chains.rs
index e26e24ec5..fcc02eca4 100644
--- a/src/tools/rustfmt/src/chains.rs
+++ b/src/tools/rustfmt/src/chains.rs
@@ -145,7 +145,7 @@ impl ChainItemKind {
fn from_ast(context: &RewriteContext<'_>, expr: &ast::Expr) -> (ChainItemKind, Span) {
let (kind, span) = match expr.kind {
- ast::ExprKind::MethodCall(ref segment, ref expressions, _) => {
+ ast::ExprKind::MethodCall(ref segment, ref receiver, ref expressions, _) => {
let types = if let Some(ref generic_args) = segment.args {
if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
data.args
@@ -163,7 +163,7 @@ impl ChainItemKind {
} else {
vec![]
};
- let span = mk_sp(expressions[0].span.hi(), expr.span.hi());
+ let span = mk_sp(receiver.span.hi(), expr.span.hi());
let kind = ChainItemKind::MethodCall(segment.clone(), types, expressions.clone());
(kind, span)
}
@@ -253,7 +253,7 @@ impl ChainItem {
format!("::<{}>", type_list.join(", "))
};
let callee_str = format!(".{}{}", rewrite_ident(context, method_name), type_str);
- rewrite_call(context, &callee_str, &args[1..], span, shape)
+ rewrite_call(context, &callee_str, &args, span, shape)
}
}
@@ -400,8 +400,8 @@ impl Chain {
// is a try! macro, we'll convert it to shorthand when the option is set.
fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext<'_>) -> Option<ast::Expr> {
match expr.kind {
- ast::ExprKind::MethodCall(_, ref expressions, _) => {
- Some(Self::convert_try(&expressions[0], context))
+ ast::ExprKind::MethodCall(_, ref receiver, _, _) => {
+ Some(Self::convert_try(&receiver, context))
}
ast::ExprKind::Field(ref subexpr, _)
| ast::ExprKind::Try(ref subexpr)
diff --git a/src/tools/rustfmt/src/config/config_type.rs b/src/tools/rustfmt/src/config/config_type.rs
index e37ed798c..c5e61658a 100644
--- a/src/tools/rustfmt/src/config/config_type.rs
+++ b/src/tools/rustfmt/src/config/config_type.rs
@@ -4,7 +4,7 @@ use crate::config::options::{IgnoreList, WidthHeuristics};
/// Trait for types that can be used in `Config`.
pub(crate) trait ConfigType: Sized {
/// Returns hint text for use in `Config::print_docs()`. For enum types, this is a
- /// pipe-separated list of variants; for other types it returns "<type>".
+ /// pipe-separated list of variants; for other types it returns `<type>`.
fn doc_hint() -> String;
}
diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs
index 8f35068e3..a2a73f0a5 100644
--- a/src/tools/rustfmt/src/items.rs
+++ b/src/tools/rustfmt/src/items.rs
@@ -594,7 +594,7 @@ impl<'a> FmtVisitor<'a> {
let both_type = |l: &TyOpt, r: &TyOpt| is_type(l) && is_type(r);
let both_opaque = |l: &TyOpt, r: &TyOpt| is_opaque(l) && is_opaque(r);
let need_empty_line = |a: &ast::AssocItemKind, b: &ast::AssocItemKind| match (a, b) {
- (TyAlias(lty), TyAlias(rty))
+ (Type(lty), Type(rty))
if both_type(&lty.ty, &rty.ty) || both_opaque(&lty.ty, &rty.ty) =>
{
false
@@ -612,7 +612,7 @@ impl<'a> FmtVisitor<'a> {
}
buffer.sort_by(|(_, a), (_, b)| match (&a.kind, &b.kind) {
- (TyAlias(lty), TyAlias(rty))
+ (Type(lty), Type(rty))
if both_type(&lty.ty, &rty.ty) || both_opaque(&lty.ty, &rty.ty) =>
{
a.ident.as_str().cmp(b.ident.as_str())
@@ -621,10 +621,10 @@ impl<'a> FmtVisitor<'a> {
a.ident.as_str().cmp(b.ident.as_str())
}
(Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()),
- (TyAlias(ty), _) if is_type(&ty.ty) => Ordering::Less,
- (_, TyAlias(ty)) if is_type(&ty.ty) => Ordering::Greater,
- (TyAlias(..), _) => Ordering::Less,
- (_, TyAlias(..)) => Ordering::Greater,
+ (Type(ty), _) if is_type(&ty.ty) => Ordering::Less,
+ (_, Type(ty)) if is_type(&ty.ty) => Ordering::Greater,
+ (Type(..), _) => Ordering::Less,
+ (_, Type(..)) => Ordering::Greater,
(Const(..), _) => Ordering::Less,
(_, Const(..)) => Ordering::Greater,
(MacCall(..), _) => Ordering::Less,
diff --git a/src/tools/rustfmt/src/visitor.rs b/src/tools/rustfmt/src/visitor.rs
index 7bb745eeb..9c3cc7820 100644
--- a/src/tools/rustfmt/src/visitor.rs
+++ b/src/tools/rustfmt/src/visitor.rs
@@ -660,7 +660,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
self.push_rewrite(ai.span, rewrite);
}
}
- (ast::AssocItemKind::TyAlias(ref ty_alias), _) => {
+ (ast::AssocItemKind::Type(ref ty_alias), _) => {
self.visit_ty_alias_kind(ty_alias, visitor_kind, ai.span);
}
(ast::AssocItemKind::MacCall(ref mac), _) => {
diff --git a/src/tools/tidy/src/alphabetical.rs b/src/tools/tidy/src/alphabetical.rs
new file mode 100644
index 000000000..f913f6cde
--- /dev/null
+++ b/src/tools/tidy/src/alphabetical.rs
@@ -0,0 +1,111 @@
+//! Checks that a list of items is in alphabetical order
+//!
+//! To use, use the following annotation in the code:
+//! ```rust
+//! // tidy-alphabetical-start
+//! fn aaa() {}
+//! fn eee() {}
+//! fn z() {}
+//! // tidy-alphabetical-end
+//! ```
+//!
+//! The following lines are ignored:
+//! - Lines that are indented with more or less spaces than the first line
+//! - Lines starting with `//`, `#[`, `)`, `]`, `}` if the comment has the same indentation as
+//! the first line
+//!
+//! If a line ends with an opening bracket, the line is ignored and the next line will have
+//! its extra indentation ignored.
+
+use std::{fmt::Display, path::Path};
+
+use crate::walk::{filter_dirs, walk};
+
+fn indentation(line: &str) -> usize {
+ line.find(|c| c != ' ').unwrap_or(0)
+}
+
+fn is_close_bracket(c: char) -> bool {
+ matches!(c, ')' | ']' | '}')
+}
+
+// Don't let tidy check this here :D
+const START_COMMENT: &str = concat!("// tidy-alphabetical", "-start");
+const END_COMMENT: &str = "// tidy-alphabetical-end";
+
+fn check_section<'a>(
+ file: impl Display,
+ lines: impl Iterator<Item = (usize, &'a str)>,
+ bad: &mut bool,
+) {
+ let content_lines = lines.take_while(|(_, line)| !line.contains(END_COMMENT));
+
+ let mut prev_line = String::new();
+ let mut first_indent = None;
+ let mut in_split_line = None;
+
+ for (line_idx, line) in content_lines {
+ if line.contains(START_COMMENT) {
+ tidy_error!(
+ bad,
+ "{file}:{} found `{START_COMMENT}` expecting `{END_COMMENT}`",
+ line_idx
+ )
+ }
+
+ let indent = first_indent.unwrap_or_else(|| {
+ let indent = indentation(line);
+ first_indent = Some(indent);
+ indent
+ });
+
+ let line = if let Some(prev_split_line) = in_split_line {
+ in_split_line = None;
+ format!("{prev_split_line}{}", line.trim_start())
+ } else {
+ line.to_string()
+ };
+
+ if indentation(&line) != indent {
+ continue;
+ }
+
+ let trimmed_line = line.trim_start_matches(' ');
+
+ if trimmed_line.starts_with("//")
+ || trimmed_line.starts_with("#[")
+ || trimmed_line.starts_with(is_close_bracket)
+ {
+ continue;
+ }
+
+ if line.trim_end().ends_with('(') {
+ in_split_line = Some(line);
+ continue;
+ }
+
+ let prev_line_trimmed_lowercase = prev_line.trim_start_matches(' ').to_lowercase();
+
+ if trimmed_line.to_lowercase() < prev_line_trimmed_lowercase {
+ tidy_error!(bad, "{file}:{}: line not in alphabetical order", line_idx + 1,);
+ }
+
+ prev_line = line;
+ }
+}
+
+pub fn check(path: &Path, bad: &mut bool) {
+ walk(path, &mut filter_dirs, &mut |entry, contents| {
+ let file = &entry.path().display();
+
+ let mut lines = contents.lines().enumerate().peekable();
+ while let Some((_, line)) = lines.next() {
+ if line.contains(START_COMMENT) {
+ check_section(file, &mut lines, bad);
+ if lines.peek().is_none() {
+ tidy_error!(bad, "{file}: reached end of file expecting `{END_COMMENT}`")
+ }
+ }
+ }
+ });
+}
diff --git a/src/tools/tidy/src/bins.rs b/src/tools/tidy/src/bins.rs
index 30903f56d..b898f20a5 100644
--- a/src/tools/tidy/src/bins.rs
+++ b/src/tools/tidy/src/bins.rs
@@ -21,6 +21,7 @@ mod os_impl {
#[cfg(unix)]
mod os_impl {
+ use crate::walk::{filter_dirs, walk_no_read};
use std::fs;
use std::os::unix::prelude::*;
use std::path::Path;
@@ -100,10 +101,10 @@ mod os_impl {
const ALLOWED: &[&str] = &["configure", "x"];
- crate::walk_no_read(
+ walk_no_read(
path,
&mut |path| {
- crate::filter_dirs(path)
+ filter_dirs(path)
|| path.ends_with("src/etc")
// This is a list of directories that we almost certainly
// don't need to walk. A future PR will likely want to
diff --git a/src/tools/tidy/src/debug_artifacts.rs b/src/tools/tidy/src/debug_artifacts.rs
index ab87230f8..9880a32ad 100644
--- a/src/tools/tidy/src/debug_artifacts.rs
+++ b/src/tools/tidy/src/debug_artifacts.rs
@@ -1,5 +1,6 @@
//! Tidy check to prevent creation of unnecessary debug artifacts while running tests.
+use crate::walk::{filter_dirs, walk};
use std::path::{Path, PathBuf};
const GRAPHVIZ_POSTFLOW_MSG: &str = "`borrowck_graphviz_postflow` attribute in test";
@@ -7,7 +8,7 @@ const GRAPHVIZ_POSTFLOW_MSG: &str = "`borrowck_graphviz_postflow` attribute in t
pub fn check(path: &Path, bad: &mut bool) {
let test_dir: PathBuf = path.join("test");
- super::walk(&test_dir, &mut super::filter_dirs, &mut |entry, contents| {
+ walk(&test_dir, &mut filter_dirs, &mut |entry, contents| {
let filename = entry.path();
let is_rust = filename.extension().map_or(false, |ext| ext == "rs");
if !is_rust {
diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs
index cbd8cfa01..8a0239ece 100644
--- a/src/tools/tidy/src/deps.rs
+++ b/src/tools/tidy/src/deps.rs
@@ -18,9 +18,11 @@ const LICENSES: &[&str] = &[
"ISC",
"Unlicense/MIT",
"Unlicense OR MIT",
- "0BSD OR MIT OR Apache-2.0", // adler license
- "Zlib OR Apache-2.0 OR MIT", // tinyvec
- "MIT OR Zlib OR Apache-2.0", // miniz_oxide
+ "0BSD OR MIT OR Apache-2.0", // adler license
+ "Zlib OR Apache-2.0 OR MIT", // tinyvec
+ "MIT OR Apache-2.0 OR Zlib", // tinyvec_macros
+ "MIT OR Zlib OR Apache-2.0", // miniz_oxide
+ "(MIT OR Apache-2.0) AND Unicode-DFS-2016", // unicode_ident
];
/// These are exceptions to Rust's permissive licensing policy, and
@@ -72,14 +74,11 @@ const EXCEPTIONS_BOOTSTRAP: &[(&str, &str)] = &[
/// these and all their dependencies *must not* be in the exception list.
const RUNTIME_CRATES: &[&str] = &["std", "core", "alloc", "test", "panic_abort", "panic_unwind"];
-/// Crates whose dependencies must be explicitly permitted.
-const RESTRICTED_DEPENDENCY_CRATES: &[&str] = &["rustc_driver", "rustc_codegen_llvm"];
-
/// Crates rustc is allowed to depend on. Avoid adding to the list if possible.
///
/// This list is here to provide a speed-bump to adding a new dependency to
/// rustc. Please check with the compiler team before adding an entry.
-const PERMITTED_DEPENDENCIES: &[&str] = &[
+const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
"addr2line",
"adler",
"ahash",
@@ -218,6 +217,7 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
"time",
"tinystr",
"tinyvec",
+ "tinyvec_macros",
"thin-vec",
"tracing",
"tracing-attributes",
@@ -236,6 +236,7 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
"unic-langid-macros",
"unic-langid-macros-impl",
"unic-ucd-version",
+ "unicode-ident",
"unicode-normalization",
"unicode-script",
"unicode-security",
@@ -258,7 +259,9 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
"ahash",
"anyhow",
"ar",
+ "arrayvec",
"autocfg",
+ "bumpalo",
"bitflags",
"byteorder",
"cfg-if",
@@ -305,7 +308,7 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
];
const FORBIDDEN_TO_HAVE_DUPLICATES: &[&str] = &[
- // These two crates take quite a long time to build, so don't allow two versions of them
+ // This crate takes quite a long time to build, so don't allow two versions of them
// to accidentally sneak into our dependency graph, in order to ensure we keep our CI times
// under control.
"cargo",
@@ -322,12 +325,12 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
.features(cargo_metadata::CargoOpt::AllFeatures);
let metadata = t!(cmd.exec());
let runtime_ids = compute_runtime_crates(&metadata);
- check_exceptions(&metadata, EXCEPTIONS, runtime_ids, bad);
- check_dependencies(
+ check_license_exceptions(&metadata, EXCEPTIONS, runtime_ids, bad);
+ check_permitted_dependencies(
&metadata,
- "main workspace",
- PERMITTED_DEPENDENCIES,
- RESTRICTED_DEPENDENCY_CRATES,
+ "rustc",
+ PERMITTED_RUSTC_DEPENDENCIES,
+ &["rustc_driver", "rustc_codegen_llvm"],
bad,
);
check_crate_duplicate(&metadata, FORBIDDEN_TO_HAVE_DUPLICATES, bad);
@@ -340,8 +343,8 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
.features(cargo_metadata::CargoOpt::AllFeatures);
let metadata = t!(cmd.exec());
let runtime_ids = HashSet::new();
- check_exceptions(&metadata, EXCEPTIONS_CRANELIFT, runtime_ids, bad);
- check_dependencies(
+ check_license_exceptions(&metadata, EXCEPTIONS_CRANELIFT, runtime_ids, bad);
+ check_permitted_dependencies(
&metadata,
"cranelift",
PERMITTED_CRANELIFT_DEPENDENCIES,
@@ -356,13 +359,13 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
.features(cargo_metadata::CargoOpt::AllFeatures);
let metadata = t!(cmd.exec());
let runtime_ids = HashSet::new();
- check_exceptions(&metadata, EXCEPTIONS_BOOTSTRAP, runtime_ids, bad);
+ check_license_exceptions(&metadata, EXCEPTIONS_BOOTSTRAP, runtime_ids, bad);
}
/// Check that all licenses are in the valid list in `LICENSES`.
///
-/// Packages listed in `EXCEPTIONS` are allowed for tools.
-fn check_exceptions(
+/// Packages listed in `exceptions` are allowed for tools.
+fn check_license_exceptions(
metadata: &Metadata,
exceptions: &[(&str, &str)],
runtime_ids: HashSet<&PackageId>,
@@ -432,11 +435,11 @@ fn check_exceptions(
}
}
-/// Checks the dependency of `RESTRICTED_DEPENDENCY_CRATES` at the given path. Changes `bad` to
+/// Checks the dependency of `restricted_dependency_crates` at the given path. Changes `bad` to
/// `true` if a check failed.
///
-/// Specifically, this checks that the dependencies are on the `PERMITTED_DEPENDENCIES`.
-fn check_dependencies(
+/// Specifically, this checks that the dependencies are on the `permitted_dependencies`.
+fn check_permitted_dependencies(
metadata: &Metadata,
descr: &str,
permitted_dependencies: &[&'static str],
diff --git a/src/tools/tidy/src/edition.rs b/src/tools/tidy/src/edition.rs
index b0abee459..8a7c4460d 100644
--- a/src/tools/tidy/src/edition.rs
+++ b/src/tools/tidy/src/edition.rs
@@ -1,5 +1,6 @@
//! Tidy check to ensure that crate `edition` is '2018' or '2021'.
+use crate::walk::{filter_dirs, walk};
use std::path::Path;
fn is_edition_2021(mut line: &str) -> bool {
@@ -8,9 +9,9 @@ fn is_edition_2021(mut line: &str) -> bool {
}
pub fn check(path: &Path, bad: &mut bool) {
- super::walk(
+ walk(
path,
- &mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
+ &mut |path| filter_dirs(path) || path.ends_with("src/test"),
&mut |entry, contents| {
let file = entry.path();
let filename = file.file_name().unwrap();
diff --git a/src/tools/tidy/src/error_codes_check.rs b/src/tools/tidy/src/error_codes_check.rs
index 0a226443e..610e322e1 100644
--- a/src/tools/tidy/src/error_codes_check.rs
+++ b/src/tools/tidy/src/error_codes_check.rs
@@ -1,6 +1,7 @@
//! Checks that all error codes have at least one test to prevent having error
//! codes that are silently not thrown by the compiler anymore.
+use crate::walk::{filter_dirs, walk};
use std::collections::{HashMap, HashSet};
use std::ffi::OsStr;
use std::fs::read_to_string;
@@ -217,7 +218,7 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
println!("Checking which error codes lack tests...");
for path in paths {
- super::walk(path, &mut super::filter_dirs, &mut |entry, contents| {
+ walk(path, &mut filter_dirs, &mut |entry, contents| {
let file_name = entry.file_name();
let entry_path = entry.path();
diff --git a/src/tools/tidy/src/errors.rs b/src/tools/tidy/src/errors.rs
index dbcc9341a..fe5fd72b9 100644
--- a/src/tools/tidy/src/errors.rs
+++ b/src/tools/tidy/src/errors.rs
@@ -3,14 +3,15 @@
//! This ensures that error codes are used at most once and also prints out some
//! statistics about the error codes.
+use crate::walk::{filter_dirs, walk};
use std::collections::HashMap;
use std::path::Path;
pub fn check(path: &Path, bad: &mut bool) {
let mut map: HashMap<_, Vec<_>> = HashMap::new();
- super::walk(
+ walk(
path,
- &mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
+ &mut |path| filter_dirs(path) || path.ends_with("src/test"),
&mut |entry, contents| {
let file = entry.path();
let filename = file.file_name().unwrap().to_string_lossy();
diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs
index b306a527a..f10ecf5f2 100644
--- a/src/tools/tidy/src/features.rs
+++ b/src/tools/tidy/src/features.rs
@@ -9,7 +9,8 @@
//! * All unstable lang features have tests to ensure they are actually unstable.
//! * Language features in a group are sorted by feature name.
-use std::collections::HashMap;
+use crate::walk::{filter_dirs, walk, walk_many};
+use std::collections::hash_map::{Entry, HashMap};
use std::fmt;
use std::fs;
use std::num::NonZeroU32;
@@ -92,14 +93,14 @@ pub fn check(
let lib_features = get_and_check_lib_features(lib_path, bad, &features);
assert!(!lib_features.is_empty());
- super::walk_many(
+ walk_many(
&[
&src_path.join("test/ui"),
&src_path.join("test/ui-fulldeps"),
&src_path.join("test/rustdoc-ui"),
&src_path.join("test/rustdoc"),
],
- &mut |path| super::filter_dirs(path),
+ &mut filter_dirs,
&mut |entry, contents| {
let file = entry.path();
let filename = file.file_name().unwrap().to_string_lossy();
@@ -279,13 +280,14 @@ fn test_filen_gate(filen_underscore: &str, features: &mut Features) -> bool {
}
pub fn collect_lang_features(base_compiler_path: &Path, bad: &mut bool) -> Features {
- let mut all = collect_lang_features_in(base_compiler_path, "active.rs", bad);
- all.extend(collect_lang_features_in(base_compiler_path, "accepted.rs", bad));
- all.extend(collect_lang_features_in(base_compiler_path, "removed.rs", bad));
- all
+ let mut features = Features::new();
+ collect_lang_features_in(&mut features, base_compiler_path, "active.rs", bad);
+ collect_lang_features_in(&mut features, base_compiler_path, "accepted.rs", bad);
+ collect_lang_features_in(&mut features, base_compiler_path, "removed.rs", bad);
+ features
}
-fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features {
+fn collect_lang_features_in(features: &mut Features, base: &Path, file: &str, bad: &mut bool) {
let path = base.join("rustc_feature").join("src").join(file);
let contents = t!(fs::read_to_string(&path));
@@ -297,135 +299,145 @@ fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features
let mut in_feature_group = false;
let mut prev_names = vec![];
- contents
- .lines()
- .zip(1..)
- .filter_map(|(line, line_number)| {
- let line = line.trim();
-
- // Within -start and -end, the tracking issue can be omitted.
- match line {
- "// no-tracking-issue-start" => {
- next_feature_omits_tracking_issue = true;
- return None;
- }
- "// no-tracking-issue-end" => {
- next_feature_omits_tracking_issue = false;
- return None;
- }
- _ => {}
+ let lines = contents.lines().zip(1..);
+ for (line, line_number) in lines {
+ let line = line.trim();
+
+ // Within -start and -end, the tracking issue can be omitted.
+ match line {
+ "// no-tracking-issue-start" => {
+ next_feature_omits_tracking_issue = true;
+ continue;
}
+ "// no-tracking-issue-end" => {
+ next_feature_omits_tracking_issue = false;
+ continue;
+ }
+ _ => {}
+ }
- if line.starts_with(FEATURE_GROUP_START_PREFIX) {
- if in_feature_group {
- tidy_error!(
- bad,
- "{}:{}: \
+ if line.starts_with(FEATURE_GROUP_START_PREFIX) {
+ if in_feature_group {
+ tidy_error!(
+ bad,
+ "{}:{}: \
new feature group is started without ending the previous one",
- path.display(),
- line_number,
- );
- }
-
- in_feature_group = true;
- prev_names = vec![];
- return None;
- } else if line.starts_with(FEATURE_GROUP_END_PREFIX) {
- in_feature_group = false;
- prev_names = vec![];
- return None;
+ path.display(),
+ line_number,
+ );
}
- let mut parts = line.split(',');
- let level = match parts.next().map(|l| l.trim().trim_start_matches('(')) {
- Some("active") => Status::Unstable,
- Some("incomplete") => Status::Unstable,
- Some("removed") => Status::Removed,
- Some("accepted") => Status::Stable,
- _ => return None,
- };
- let name = parts.next().unwrap().trim();
-
- let since_str = parts.next().unwrap().trim().trim_matches('"');
- let since = match since_str.parse() {
- Ok(since) => Some(since),
- Err(err) => {
- tidy_error!(
- bad,
- "{}:{}: failed to parse since: {} ({:?})",
- path.display(),
- line_number,
- since_str,
- err,
- );
- None
- }
- };
- if in_feature_group {
- if prev_names.last() > Some(&name) {
- // This assumes the user adds the feature name at the end of the list, as we're
- // not looking ahead.
- let correct_index = match prev_names.binary_search(&name) {
- Ok(_) => {
- // This only occurs when the feature name has already been declared.
- tidy_error!(
- bad,
- "{}:{}: duplicate feature {}",
- path.display(),
- line_number,
- name,
- );
- // skip any additional checks for this line
- return None;
- }
- Err(index) => index,
- };
+ in_feature_group = true;
+ prev_names = vec![];
+ continue;
+ } else if line.starts_with(FEATURE_GROUP_END_PREFIX) {
+ in_feature_group = false;
+ prev_names = vec![];
+ continue;
+ }
- let correct_placement = if correct_index == 0 {
- "at the beginning of the feature group".to_owned()
- } else if correct_index == prev_names.len() {
- // I don't believe this is reachable given the above assumption, but it
- // doesn't hurt to be safe.
- "at the end of the feature group".to_owned()
- } else {
- format!(
- "between {} and {}",
- prev_names[correct_index - 1],
- prev_names[correct_index],
- )
- };
+ let mut parts = line.split(',');
+ let level = match parts.next().map(|l| l.trim().trim_start_matches('(')) {
+ Some("active") => Status::Unstable,
+ Some("incomplete") => Status::Unstable,
+ Some("removed") => Status::Removed,
+ Some("accepted") => Status::Stable,
+ _ => continue,
+ };
+ let name = parts.next().unwrap().trim();
+
+ let since_str = parts.next().unwrap().trim().trim_matches('"');
+ let since = match since_str.parse() {
+ Ok(since) => Some(since),
+ Err(err) => {
+ tidy_error!(
+ bad,
+ "{}:{}: failed to parse since: {} ({:?})",
+ path.display(),
+ line_number,
+ since_str,
+ err,
+ );
+ None
+ }
+ };
+ if in_feature_group {
+ if prev_names.last() > Some(&name) {
+ // This assumes the user adds the feature name at the end of the list, as we're
+ // not looking ahead.
+ let correct_index = match prev_names.binary_search(&name) {
+ Ok(_) => {
+ // This only occurs when the feature name has already been declared.
+ tidy_error!(
+ bad,
+ "{}:{}: duplicate feature {}",
+ path.display(),
+ line_number,
+ name,
+ );
+ // skip any additional checks for this line
+ continue;
+ }
+ Err(index) => index,
+ };
- tidy_error!(
- bad,
- "{}:{}: feature {} is not sorted by feature name (should be {})",
- path.display(),
- line_number,
- name,
- correct_placement,
- );
- }
- prev_names.push(name);
+ let correct_placement = if correct_index == 0 {
+ "at the beginning of the feature group".to_owned()
+ } else if correct_index == prev_names.len() {
+ // I don't believe this is reachable given the above assumption, but it
+ // doesn't hurt to be safe.
+ "at the end of the feature group".to_owned()
+ } else {
+ format!(
+ "between {} and {}",
+ prev_names[correct_index - 1],
+ prev_names[correct_index],
+ )
+ };
+
+ tidy_error!(
+ bad,
+ "{}:{}: feature {} is not sorted by feature name (should be {})",
+ path.display(),
+ line_number,
+ name,
+ correct_placement,
+ );
}
+ prev_names.push(name);
+ }
- let issue_str = parts.next().unwrap().trim();
- let tracking_issue = if issue_str.starts_with("None") {
- if level == Status::Unstable && !next_feature_omits_tracking_issue {
- tidy_error!(
- bad,
- "{}:{}: no tracking issue for feature {}",
- path.display(),
- line_number,
- name,
- );
- }
- None
- } else {
- let s = issue_str.split('(').nth(1).unwrap().split(')').next().unwrap();
- Some(s.parse().unwrap())
- };
- Some((name.to_owned(), Feature { level, since, has_gate_test: false, tracking_issue }))
- })
- .collect()
+ let issue_str = parts.next().unwrap().trim();
+ let tracking_issue = if issue_str.starts_with("None") {
+ if level == Status::Unstable && !next_feature_omits_tracking_issue {
+ tidy_error!(
+ bad,
+ "{}:{}: no tracking issue for feature {}",
+ path.display(),
+ line_number,
+ name,
+ );
+ }
+ None
+ } else {
+ let s = issue_str.split('(').nth(1).unwrap().split(')').next().unwrap();
+ Some(s.parse().unwrap())
+ };
+ match features.entry(name.to_owned()) {
+ Entry::Occupied(e) => {
+ tidy_error!(
+ bad,
+ "{}:{} feature {name} already specified with status '{}'",
+ path.display(),
+ line_number,
+ e.get().level,
+ );
+ }
+ Entry::Vacant(e) => {
+ e.insert(Feature { level, since, has_gate_test: false, tracking_issue });
+ }
+ }
+ }
}
fn get_and_check_lib_features(
@@ -466,9 +478,9 @@ fn map_lib_features(
base_src_path: &Path,
mf: &mut dyn FnMut(Result<(&str, Feature), &str>, &Path, usize),
) {
- super::walk(
+ walk(
base_src_path,
- &mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
+ &mut |path| filter_dirs(path) || path.ends_with("src/test"),
&mut |entry, contents| {
let file = entry.path();
let filename = file.file_name().unwrap().to_string_lossy();
@@ -537,7 +549,9 @@ fn map_lib_features(
becoming_feature = None;
if line.contains("rustc_const_unstable(") {
// `const fn` features are handled specially.
- let feature_name = match find_attr_val(line, "feature") {
+ let feature_name = match find_attr_val(line, "feature").or_else(|| {
+ iter_lines.peek().and_then(|next| find_attr_val(next.1, "feature"))
+ }) {
Some(name) => name,
None => err!("malformed stability attribute: missing `feature` key"),
};
diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs
index 12d3bdcd7..fc0bce585 100644
--- a/src/tools/tidy/src/lib.rs
+++ b/src/tools/tidy/src/lib.rs
@@ -3,8 +3,6 @@
//! This library contains the tidy lints and exposes it
//! to be used by tools.
-use walk::{filter_dirs, walk, walk_many, walk_no_read};
-
/// A helper macro to `unwrap` a result except also print out details like:
///
/// * The expression that failed
@@ -40,6 +38,7 @@ macro_rules! tidy_error {
});
}
+pub mod alphabetical;
pub mod bins;
pub mod debug_artifacts;
pub mod deps;
diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs
index c1ce94f47..ca785042a 100644
--- a/src/tools/tidy/src/main.rs
+++ b/src/tools/tidy/src/main.rs
@@ -90,6 +90,10 @@ fn main() {
check!(edition, &compiler_path);
check!(edition, &library_path);
+ check!(alphabetical, &src_path);
+ check!(alphabetical, &compiler_path);
+ check!(alphabetical, &library_path);
+
let collected = {
while handles.len() >= concurrency.get() {
handles.pop_front().unwrap().join().unwrap();
diff --git a/src/tools/tidy/src/pal.rs b/src/tools/tidy/src/pal.rs
index 4d86fe8be..f4592fdcf 100644
--- a/src/tools/tidy/src/pal.rs
+++ b/src/tools/tidy/src/pal.rs
@@ -30,6 +30,7 @@
//! platform-specific cfgs are allowed. Not sure yet how to deal with
//! this in the long term.
+use crate::walk::{filter_dirs, walk};
use std::iter::Iterator;
use std::path::Path;
@@ -67,7 +68,7 @@ pub fn check(path: &Path, bad: &mut bool) {
// Sanity check that the complex parsing here works.
let mut saw_target_arch = false;
let mut saw_cfg_bang = false;
- super::walk(path, &mut super::filter_dirs, &mut |entry, contents| {
+ walk(path, &mut filter_dirs, &mut |entry, contents| {
let file = entry.path();
let filestr = file.to_string_lossy().replace("\\", "/");
if !filestr.ends_with(".rs") {
diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs
index dee58ff2f..541380ceb 100644
--- a/src/tools/tidy/src/style.rs
+++ b/src/tools/tidy/src/style.rs
@@ -16,6 +16,7 @@
//! A number of these checks can be opted-out of with various directives of the form:
//! `// ignore-tidy-CHECK-NAME`.
+use crate::walk::{filter_dirs, walk};
use regex::Regex;
use std::path::Path;
@@ -218,13 +219,13 @@ fn is_unexplained_ignore(extension: &str, line: &str) -> bool {
pub fn check(path: &Path, bad: &mut bool) {
fn skip(path: &Path) -> bool {
- super::filter_dirs(path) || skip_markdown_path(path)
+ filter_dirs(path) || skip_markdown_path(path)
}
let problematic_consts_strings: Vec<String> = (PROBLEMATIC_CONSTS.iter().map(u32::to_string))
.chain(PROBLEMATIC_CONSTS.iter().map(|v| format!("{:x}", v)))
.chain(PROBLEMATIC_CONSTS.iter().map(|v| format!("{:X}", v)))
.collect();
- super::walk(path, &mut skip, &mut |entry, contents| {
+ walk(path, &mut skip, &mut |entry, contents| {
let file = entry.path();
let filename = file.file_name().unwrap().to_string_lossy();
let extensions = [".rs", ".py", ".js", ".sh", ".c", ".cpp", ".h", ".md", ".css", ".ftl"];
diff --git a/src/tools/tidy/src/target_specific_tests.rs b/src/tools/tidy/src/target_specific_tests.rs
index 723684bfa..8ba257056 100644
--- a/src/tools/tidy/src/target_specific_tests.rs
+++ b/src/tools/tidy/src/target_specific_tests.rs
@@ -36,7 +36,7 @@ struct RevisionInfo<'a> {
pub fn check(path: &Path, bad: &mut bool) {
let tests = path.join("test");
- super::walk(
+ crate::walk::walk(
&tests,
&mut |path| path.extension().map(|p| p == "rs") == Some(false),
&mut |entry, content| {
diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs
index 8ec5c3324..c600f99c2 100644
--- a/src/tools/tidy/src/ui_tests.rs
+++ b/src/tools/tidy/src/ui_tests.rs
@@ -7,8 +7,8 @@ use std::path::Path;
const ENTRY_LIMIT: usize = 1000;
// FIXME: The following limits should be reduced eventually.
-const ROOT_ENTRY_LIMIT: usize = 968;
-const ISSUES_ENTRY_LIMIT: usize = 2147;
+const ROOT_ENTRY_LIMIT: usize = 948;
+const ISSUES_ENTRY_LIMIT: usize = 2117;
fn check_entries(path: &Path, bad: &mut bool) {
let dirs = walkdir::WalkDir::new(&path.join("test/ui"))
@@ -47,7 +47,7 @@ fn check_entries(path: &Path, bad: &mut bool) {
pub fn check(path: &Path, bad: &mut bool) {
check_entries(&path, bad);
for path in &[&path.join("test/ui"), &path.join("test/ui-fulldeps")] {
- super::walk_no_read(path, &mut |_| false, &mut |entry| {
+ crate::walk::walk_no_read(path, &mut |_| false, &mut |entry| {
let file_path = entry.path();
if let Some(ext) = file_path.extension() {
if ext == "stderr" || ext == "stdout" {
diff --git a/src/tools/tidy/src/unit_tests.rs b/src/tools/tidy/src/unit_tests.rs
index f675b7865..2c23b6ebc 100644
--- a/src/tools/tidy/src/unit_tests.rs
+++ b/src/tools/tidy/src/unit_tests.rs
@@ -7,6 +7,7 @@
//! named `tests.rs` or `benches.rs`, or directories named `tests` or `benches` unconfigured
//! during normal build.
+use crate::walk::{filter_dirs, walk};
use std::path::Path;
pub fn check(root_path: &Path, bad: &mut bool) {
@@ -20,7 +21,7 @@ pub fn check(root_path: &Path, bad: &mut bool) {
let mut skip = |path: &Path| {
let file_name = path.file_name().unwrap_or_default();
if path.is_dir() {
- super::filter_dirs(path)
+ filter_dirs(path)
|| path.ends_with("src/test")
|| path.ends_with("src/doc")
|| (file_name == "tests" || file_name == "benches") && !is_core(path)
@@ -34,7 +35,7 @@ pub fn check(root_path: &Path, bad: &mut bool) {
}
};
- super::walk(root_path, &mut skip, &mut |entry, contents| {
+ walk(root_path, &mut skip, &mut |entry, contents| {
let path = entry.path();
let is_core = path.starts_with(core);
for (i, line) in contents.lines().enumerate() {
diff --git a/src/tools/tidy/src/walk.rs b/src/tools/tidy/src/walk.rs
index b07e80767..4cfb70fa3 100644
--- a/src/tools/tidy/src/walk.rs
+++ b/src/tools/tidy/src/walk.rs
@@ -21,6 +21,12 @@ pub fn filter_dirs(path: &Path) -> bool {
"src/tools/rust-installer",
"src/tools/rustfmt",
"src/doc/book",
+ "src/doc/edition-guide",
+ "src/doc/embedded-book",
+ "src/doc/nomicon",
+ "src/doc/rust-by-example",
+ "src/doc/rustc-dev-guide",
+ "src/doc/reference",
// Filter RLS output directories
"target/rls",
"src/bootstrap/target",
diff --git a/src/version b/src/version
index 902c74186..b6148bc0a 100644
--- a/src/version
+++ b/src/version
@@ -1 +1 @@
-1.65.0
+1.66.0