From 67e352fcb63cea4d97895d258ef3b70c4ab3ecf7 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 3 May 2021 13:51:13 -0400 Subject: [PATCH 01/13] rename rust-2018 section --- src/SUMMARY.md | 142 +++++++++--------- ...go-can-use-a-local-registry-replacement.md | 0 .../cargo-check-for-faster-checking.md | 0 ...-install-for-easy-installation-of-tools.md | 0 .../cargo-new-defaults-to-a-binary-project.md | 0 ...tc-for-passing-arbitrary-flags-to-rustc.md | 0 ...o-workspaces-for-multi-package-projects.md | 0 ...ates-io-disallows-wildcard-dependencies.md | 0 .../cargo-and-crates-io/index.md | 0 .../multi-file-examples.md | 0 .../replacing-dependencies-with-patch.md | 0 .../async-await-for-easier-concurrency.md | 0 .../control-flow/index.md | 0 .../loops-can-break-with-a-value.md | 0 .../data-types/128-bit-integers.md | 0 ...osing-alignment-with-the-repr-attribute.md | 0 .../data-types/field-init-shorthand.md | 0 .../data-types/inclusive-ranges.md | 0 .../data-types/index.md | 0 .../operator-equals-are-now-implementable.md | 0 .../union-for-an-unsafe-form-of-enum.md | 0 .../documentation/index.md | 0 .../documentation/new-editions-of-the-book.md | 0 ...-os-has-documentation-for-all-platforms.md | 0 .../documentation/the-rust-bookshelf.md | 0 .../documentation/the-rustonomicon.md | 0 .../edition-changes.md | 0 .../aborting-on-panic.md | 0 .../controlling-panics-with-std-panic.md | 0 .../error-handling-and-panics/index.md | 0 .../question-mark-in-main-and-tests.md | 0 ...mark-operator-for-easier-error-handling.md | 0 .../index.md | 0 .../macros/at-most-once.md | 0 .../macros/custom-derive.md | 0 .../macros/index.md | 0 .../macros/macro-changes.md | 0 .../module-system/index.md | 0 .../more-visibility-modifiers.md | 0 .../module-system/nested-imports-with-use.md | 0 .../module-system/path-clarity.md | 0 .../module-system/raw-identifiers.md | 0 .../default-match-bindings.md | 0 .../ownership-and-lifetimes/index.md | 0 .../inference-in-structs.md | 0 .../lifetime-elision-in-impl.md | 0 .../non-lexical-lifetimes.md | 0 .../simpler-lifetimes-in-static-and-const.md | 0 .../the-anonymous-lifetime.md | 0 .../cdylib-crates-for-c-interoperability.md | 0 .../global-allocators.md | 0 .../platform-and-target-support/index.md | 0 .../libcore-for-low-level-rust.md | 0 .../msvc-toolchain-support.md | 0 .../musl-support-for-fully-static-binaries.md | 0 .../webassembly-support.md | 0 ...ocumentation-tests-can-now-compile-fail.md | 0 .../rustdoc/index.md | 0 .../rustdoc/rustdoc-uses-commonmark.md | 0 .../rustup-for-managing-rust-versions.md | 0 .../simd-for-faster-computing.md | 0 .../slice-patterns.md | 0 .../an-attribute-for-deprecation.md | 0 .../the-compiler/improved-error-messages.md | 0 ...emental-compilation-for-faster-compiles.md | 0 .../the-compiler/index.md | 0 .../trait-system/associated-constants.md | 0 .../dyn-trait-for-trait-objects.md | 0 ...t-for-returning-complex-types-with-ease.md | 0 .../trait-system/index.md | 0 ...e-container-types-support-trait-objects.md | 0 .../trait-system/no-anon-params.md | 0 72 files changed, 71 insertions(+), 71 deletions(-) rename src/{rust-2018 => rust-2018-outdated}/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.md (100%) rename src/{rust-2018 => rust-2018-outdated}/cargo-and-crates-io/cargo-check-for-faster-checking.md (100%) rename src/{rust-2018 => rust-2018-outdated}/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.md (100%) rename src/{rust-2018 => rust-2018-outdated}/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.md (100%) rename src/{rust-2018 => rust-2018-outdated}/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.md (100%) rename src/{rust-2018 => rust-2018-outdated}/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.md (100%) rename src/{rust-2018 => rust-2018-outdated}/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.md (100%) rename src/{rust-2018 => rust-2018-outdated}/cargo-and-crates-io/index.md (100%) rename src/{rust-2018 => rust-2018-outdated}/cargo-and-crates-io/multi-file-examples.md (100%) rename src/{rust-2018 => rust-2018-outdated}/cargo-and-crates-io/replacing-dependencies-with-patch.md (100%) rename src/{rust-2018 => rust-2018-outdated}/control-flow/async-await-for-easier-concurrency.md (100%) rename src/{rust-2018 => rust-2018-outdated}/control-flow/index.md (100%) rename src/{rust-2018 => rust-2018-outdated}/control-flow/loops-can-break-with-a-value.md (100%) rename src/{rust-2018 => rust-2018-outdated}/data-types/128-bit-integers.md (100%) rename src/{rust-2018 => rust-2018-outdated}/data-types/choosing-alignment-with-the-repr-attribute.md (100%) rename src/{rust-2018 => rust-2018-outdated}/data-types/field-init-shorthand.md (100%) rename src/{rust-2018 => rust-2018-outdated}/data-types/inclusive-ranges.md (100%) rename src/{rust-2018 => rust-2018-outdated}/data-types/index.md (100%) rename src/{rust-2018 => rust-2018-outdated}/data-types/operator-equals-are-now-implementable.md (100%) rename src/{rust-2018 => rust-2018-outdated}/data-types/union-for-an-unsafe-form-of-enum.md (100%) rename src/{rust-2018 => rust-2018-outdated}/documentation/index.md (100%) rename src/{rust-2018 => rust-2018-outdated}/documentation/new-editions-of-the-book.md (100%) rename src/{rust-2018 => rust-2018-outdated}/documentation/std-os-has-documentation-for-all-platforms.md (100%) rename src/{rust-2018 => rust-2018-outdated}/documentation/the-rust-bookshelf.md (100%) rename src/{rust-2018 => rust-2018-outdated}/documentation/the-rustonomicon.md (100%) rename src/{rust-2018 => rust-2018-outdated}/edition-changes.md (100%) rename src/{rust-2018 => rust-2018-outdated}/error-handling-and-panics/aborting-on-panic.md (100%) rename src/{rust-2018 => rust-2018-outdated}/error-handling-and-panics/controlling-panics-with-std-panic.md (100%) rename src/{rust-2018 => rust-2018-outdated}/error-handling-and-panics/index.md (100%) rename src/{rust-2018 => rust-2018-outdated}/error-handling-and-panics/question-mark-in-main-and-tests.md (100%) rename src/{rust-2018 => rust-2018-outdated}/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.md (100%) rename src/{rust-2018 => rust-2018-outdated}/index.md (100%) rename src/{rust-2018 => rust-2018-outdated}/macros/at-most-once.md (100%) rename src/{rust-2018 => rust-2018-outdated}/macros/custom-derive.md (100%) rename src/{rust-2018 => rust-2018-outdated}/macros/index.md (100%) rename src/{rust-2018 => rust-2018-outdated}/macros/macro-changes.md (100%) rename src/{rust-2018 => rust-2018-outdated}/module-system/index.md (100%) rename src/{rust-2018 => rust-2018-outdated}/module-system/more-visibility-modifiers.md (100%) rename src/{rust-2018 => rust-2018-outdated}/module-system/nested-imports-with-use.md (100%) rename src/{rust-2018 => rust-2018-outdated}/module-system/path-clarity.md (100%) rename src/{rust-2018 => rust-2018-outdated}/module-system/raw-identifiers.md (100%) rename src/{rust-2018 => rust-2018-outdated}/ownership-and-lifetimes/default-match-bindings.md (100%) rename src/{rust-2018 => rust-2018-outdated}/ownership-and-lifetimes/index.md (100%) rename src/{rust-2018 => rust-2018-outdated}/ownership-and-lifetimes/inference-in-structs.md (100%) rename src/{rust-2018 => rust-2018-outdated}/ownership-and-lifetimes/lifetime-elision-in-impl.md (100%) rename src/{rust-2018 => rust-2018-outdated}/ownership-and-lifetimes/non-lexical-lifetimes.md (100%) rename src/{rust-2018 => rust-2018-outdated}/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.md (100%) rename src/{rust-2018 => rust-2018-outdated}/ownership-and-lifetimes/the-anonymous-lifetime.md (100%) rename src/{rust-2018 => rust-2018-outdated}/platform-and-target-support/cdylib-crates-for-c-interoperability.md (100%) rename src/{rust-2018 => rust-2018-outdated}/platform-and-target-support/global-allocators.md (100%) rename src/{rust-2018 => rust-2018-outdated}/platform-and-target-support/index.md (100%) rename src/{rust-2018 => rust-2018-outdated}/platform-and-target-support/libcore-for-low-level-rust.md (100%) rename src/{rust-2018 => rust-2018-outdated}/platform-and-target-support/msvc-toolchain-support.md (100%) rename src/{rust-2018 => rust-2018-outdated}/platform-and-target-support/musl-support-for-fully-static-binaries.md (100%) rename src/{rust-2018 => rust-2018-outdated}/platform-and-target-support/webassembly-support.md (100%) rename src/{rust-2018 => rust-2018-outdated}/rustdoc/documentation-tests-can-now-compile-fail.md (100%) rename src/{rust-2018 => rust-2018-outdated}/rustdoc/index.md (100%) rename src/{rust-2018 => rust-2018-outdated}/rustdoc/rustdoc-uses-commonmark.md (100%) rename src/{rust-2018 => rust-2018-outdated}/rustup-for-managing-rust-versions.md (100%) rename src/{rust-2018 => rust-2018-outdated}/simd-for-faster-computing.md (100%) rename src/{rust-2018 => rust-2018-outdated}/slice-patterns.md (100%) rename src/{rust-2018 => rust-2018-outdated}/the-compiler/an-attribute-for-deprecation.md (100%) rename src/{rust-2018 => rust-2018-outdated}/the-compiler/improved-error-messages.md (100%) rename src/{rust-2018 => rust-2018-outdated}/the-compiler/incremental-compilation-for-faster-compiles.md (100%) rename src/{rust-2018 => rust-2018-outdated}/the-compiler/index.md (100%) rename src/{rust-2018 => rust-2018-outdated}/trait-system/associated-constants.md (100%) rename src/{rust-2018 => rust-2018-outdated}/trait-system/dyn-trait-for-trait-objects.md (100%) rename src/{rust-2018 => rust-2018-outdated}/trait-system/impl-trait-for-returning-complex-types-with-ease.md (100%) rename src/{rust-2018 => rust-2018-outdated}/trait-system/index.md (100%) rename src/{rust-2018 => rust-2018-outdated}/trait-system/more-container-types-support-trait-objects.md (100%) rename src/{rust-2018 => rust-2018-outdated}/trait-system/no-anon-params.md (100%) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index b9913830..fe816098 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -14,77 +14,77 @@ ## Rust 2018 -- [Rust 2018](rust-2018/index.md) - - [2018-Specific Changes](rust-2018/edition-changes.md) - - [Module system](rust-2018/module-system/index.md) - - [Raw identifiers](rust-2018/module-system/raw-identifiers.md) - - [Path clarity](rust-2018/module-system/path-clarity.md) - - [More visibility modifiers](rust-2018/module-system/more-visibility-modifiers.md) - - [Nested imports with `use`](rust-2018/module-system/nested-imports-with-use.md) - - [Error handling and panics](rust-2018/error-handling-and-panics/index.md) - - [The `?` operator for easier error handling](rust-2018/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.md) - - [`?` in `main` and tests](rust-2018/error-handling-and-panics/question-mark-in-main-and-tests.md) - - [Controlling panics with `std::panic`](rust-2018/error-handling-and-panics/controlling-panics-with-std-panic.md) - - [Aborting on panic](rust-2018/error-handling-and-panics/aborting-on-panic.md) - - [Control flow](rust-2018/control-flow/index.md) - - [Loops can `break` with a value](rust-2018/control-flow/loops-can-break-with-a-value.md) - - [`async`/`await` for easier concurrency](rust-2018/control-flow/async-await-for-easier-concurrency.md) - - [Trait system](rust-2018/trait-system/index.md) - - [`impl Trait` for returning complex types with ease](rust-2018/trait-system/impl-trait-for-returning-complex-types-with-ease.md) - - [`dyn Trait` for trait objects](rust-2018/trait-system/dyn-trait-for-trait-objects.md) - - [More container types support trait objects](rust-2018/trait-system/more-container-types-support-trait-objects.md) - - [Associated constants](rust-2018/trait-system/associated-constants.md) - - [No more anonymous parameters](rust-2018/trait-system/no-anon-params.md) - - [Slice patterns](rust-2018/slice-patterns.md) - - [Ownership and lifetimes](rust-2018/ownership-and-lifetimes/index.md) - - [Non-lexical lifetimes](rust-2018/ownership-and-lifetimes/non-lexical-lifetimes.md) - - [Default `match` bindings](rust-2018/ownership-and-lifetimes/default-match-bindings.md) - - [`'_`, the anonymous lifetime](rust-2018/ownership-and-lifetimes/the-anonymous-lifetime.md) - - [Lifetime elision in `impl`](rust-2018/ownership-and-lifetimes/lifetime-elision-in-impl.md) - - [`T: 'a` inference in structs](rust-2018/ownership-and-lifetimes/inference-in-structs.md) - - [Simpler lifetimes in `static` and `const`](rust-2018/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.md) - - [Data types](rust-2018/data-types/index.md) - - [Field init shorthand](rust-2018/data-types/field-init-shorthand.md) - - [`..=` for inclusive ranges](rust-2018/data-types/inclusive-ranges.md) - - [128 bit integers](rust-2018/data-types/128-bit-integers.md) - - ["Operator-equals" are now implementable](rust-2018/data-types/operator-equals-are-now-implementable.md) - - [`union` for an unsafe form of `enum`](rust-2018/data-types/union-for-an-unsafe-form-of-enum.md) - - [Choosing alignment with the `repr` attribute](rust-2018/data-types/choosing-alignment-with-the-repr-attribute.md) - - [SIMD for faster computing](rust-2018/simd-for-faster-computing.md) - - [Macros](rust-2018/macros/index.md) - - [Custom Derive](rust-2018/macros/custom-derive.md) - - [Macro changes](rust-2018/macros/macro-changes.md) - - [At most one repetition](rust-2018/macros/at-most-once.md) - - [The compiler](rust-2018/the-compiler/index.md) - - [Improved error messages](rust-2018/the-compiler/improved-error-messages.md) - - [Incremental Compilation for faster compiles](rust-2018/the-compiler/incremental-compilation-for-faster-compiles.md) - - [An attribute for deprecation](rust-2018/the-compiler/an-attribute-for-deprecation.md) - - [Rustup for managing Rust versions](rust-2018/rustup-for-managing-rust-versions.md) - - [Cargo and crates.io](rust-2018/cargo-and-crates-io/index.md) - - [`cargo check` for faster checking](rust-2018/cargo-and-crates-io/cargo-check-for-faster-checking.md) - - [`cargo install` for easy installation of tools](rust-2018/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.md) - - [`cargo new` defaults to a binary project](rust-2018/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.md) - - [`cargo rustc` for passing arbitrary flags to `rustc`](rust-2018/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.md) - - [Cargo workspaces for multi-package projects](rust-2018/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.md) - - [Multi-file `examples`](rust-2018/cargo-and-crates-io/multi-file-examples.md) - - [Replacing dependencies with `patch`](rust-2018/cargo-and-crates-io/replacing-dependencies-with-patch.md) - - [Cargo can use a local registry replacement](rust-2018/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.md) - - [Crates.io disallows wildcard dependencies](rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.md) - - [Documentation](rust-2018/documentation/index.md) - - [New editions of the "the book"](rust-2018/documentation/new-editions-of-the-book.md) - - [The Rust Bookshelf](rust-2018/documentation/the-rust-bookshelf.md) - - [The Rustonomicon](rust-2018/documentation/the-rustonomicon.md) - - [Full documentation for `std::os`](rust-2018/documentation/std-os-has-documentation-for-all-platforms.md) - - [`rustdoc`](rust-2018/rustdoc/index.md) - - [Documentation tests can now `compile-fail`](rust-2018/rustdoc/documentation-tests-can-now-compile-fail.md) - - [Rustdoc uses CommonMark](rust-2018/rustdoc/rustdoc-uses-commonmark.md) - - [Platform and target support](rust-2018/platform-and-target-support/index.md) - - [`libcore` for low-level Rust](rust-2018/platform-and-target-support/libcore-for-low-level-rust.md) - - [WebAssembly support](rust-2018/platform-and-target-support/webassembly-support.md) - - [Global allocators](rust-2018/platform-and-target-support/global-allocators.md) - - [MSVC toolchain support](rust-2018/platform-and-target-support/msvc-toolchain-support.md) - - [MUSL support for fully static binaries](rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.md) - - [`cdylib` crates for C interoperability](rust-2018/platform-and-target-support/cdylib-crates-for-c-interoperability.md) +- [Rust 2018 (outdated)](rust-2018-outdated/index.md) + - [2018-Specific Changes](rust-2018-outdated/edition-changes.md) + - [Module system](rust-2018-outdated/module-system/index.md) + - [Raw identifiers](rust-2018-outdated/module-system/raw-identifiers.md) + - [Path clarity](rust-2018-outdated/module-system/path-clarity.md) + - [More visibility modifiers](rust-2018-outdated/module-system/more-visibility-modifiers.md) + - [Nested imports with `use`](rust-2018-outdated/module-system/nested-imports-with-use.md) + - [Error handling and panics](rust-2018-outdated/error-handling-and-panics/index.md) + - [The `?` operator for easier error handling](rust-2018-outdated/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.md) + - [`?` in `main` and tests](rust-2018-outdated/error-handling-and-panics/question-mark-in-main-and-tests.md) + - [Controlling panics with `std::panic`](rust-2018-outdated/error-handling-and-panics/controlling-panics-with-std-panic.md) + - [Aborting on panic](rust-2018-outdated/error-handling-and-panics/aborting-on-panic.md) + - [Control flow](rust-2018-outdated/control-flow/index.md) + - [Loops can `break` with a value](rust-2018-outdated/control-flow/loops-can-break-with-a-value.md) + - [`async`/`await` for easier concurrency](rust-2018-outdated/control-flow/async-await-for-easier-concurrency.md) + - [Trait system](rust-2018-outdated/trait-system/index.md) + - [`impl Trait` for returning complex types with ease](rust-2018-outdated/trait-system/impl-trait-for-returning-complex-types-with-ease.md) + - [`dyn Trait` for trait objects](rust-2018-outdated/trait-system/dyn-trait-for-trait-objects.md) + - [More container types support trait objects](rust-2018-outdated/trait-system/more-container-types-support-trait-objects.md) + - [Associated constants](rust-2018-outdated/trait-system/associated-constants.md) + - [No more anonymous parameters](rust-2018-outdated/trait-system/no-anon-params.md) + - [Slice patterns](rust-2018-outdated/slice-patterns.md) + - [Ownership and lifetimes](rust-2018-outdated/ownership-and-lifetimes/index.md) + - [Non-lexical lifetimes](rust-2018-outdated/ownership-and-lifetimes/non-lexical-lifetimes.md) + - [Default `match` bindings](rust-2018-outdated/ownership-and-lifetimes/default-match-bindings.md) + - [`'_`, the anonymous lifetime](rust-2018-outdated/ownership-and-lifetimes/the-anonymous-lifetime.md) + - [Lifetime elision in `impl`](rust-2018-outdated/ownership-and-lifetimes/lifetime-elision-in-impl.md) + - [`T: 'a` inference in structs](rust-2018-outdated/ownership-and-lifetimes/inference-in-structs.md) + - [Simpler lifetimes in `static` and `const`](rust-2018-outdated/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.md) + - [Data types](rust-2018-outdated/data-types/index.md) + - [Field init shorthand](rust-2018-outdated/data-types/field-init-shorthand.md) + - [`..=` for inclusive ranges](rust-2018-outdated/data-types/inclusive-ranges.md) + - [128 bit integers](rust-2018-outdated/data-types/128-bit-integers.md) + - ["Operator-equals" are now implementable](rust-2018-outdated/data-types/operator-equals-are-now-implementable.md) + - [`union` for an unsafe form of `enum`](rust-2018-outdated/data-types/union-for-an-unsafe-form-of-enum.md) + - [Choosing alignment with the `repr` attribute](rust-2018-outdated/data-types/choosing-alignment-with-the-repr-attribute.md) + - [SIMD for faster computing](rust-2018-outdated/simd-for-faster-computing.md) + - [Macros](rust-2018-outdated/macros/index.md) + - [Custom Derive](rust-2018-outdated/macros/custom-derive.md) + - [Macro changes](rust-2018-outdated/macros/macro-changes.md) + - [At most one repetition](rust-2018-outdated/macros/at-most-once.md) + - [The compiler](rust-2018-outdated/the-compiler/index.md) + - [Improved error messages](rust-2018-outdated/the-compiler/improved-error-messages.md) + - [Incremental Compilation for faster compiles](rust-2018-outdated/the-compiler/incremental-compilation-for-faster-compiles.md) + - [An attribute for deprecation](rust-2018-outdated/the-compiler/an-attribute-for-deprecation.md) + - [Rustup for managing Rust versions](rust-2018-outdated/rustup-for-managing-rust-versions.md) + - [Cargo and crates.io](rust-2018-outdated/cargo-and-crates-io/index.md) + - [`cargo check` for faster checking](rust-2018-outdated/cargo-and-crates-io/cargo-check-for-faster-checking.md) + - [`cargo install` for easy installation of tools](rust-2018-outdated/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.md) + - [`cargo new` defaults to a binary project](rust-2018-outdated/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.md) + - [`cargo rustc` for passing arbitrary flags to `rustc`](rust-2018-outdated/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.md) + - [Cargo workspaces for multi-package projects](rust-2018-outdated/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.md) + - [Multi-file `examples`](rust-2018-outdated/cargo-and-crates-io/multi-file-examples.md) + - [Replacing dependencies with `patch`](rust-2018-outdated/cargo-and-crates-io/replacing-dependencies-with-patch.md) + - [Cargo can use a local registry replacement](rust-2018-outdated/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.md) + - [Crates.io disallows wildcard dependencies](rust-2018-outdated/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.md) + - [Documentation](rust-2018-outdated/documentation/index.md) + - [New editions of the "the book"](rust-2018-outdated/documentation/new-editions-of-the-book.md) + - [The Rust Bookshelf](rust-2018-outdated/documentation/the-rust-bookshelf.md) + - [The Rustonomicon](rust-2018-outdated/documentation/the-rustonomicon.md) + - [Full documentation for `std::os`](rust-2018-outdated/documentation/std-os-has-documentation-for-all-platforms.md) + - [`rustdoc`](rust-2018-outdated/rustdoc/index.md) + - [Documentation tests can now `compile-fail`](rust-2018-outdated/rustdoc/documentation-tests-can-now-compile-fail.md) + - [Rustdoc uses CommonMark](rust-2018-outdated/rustdoc/rustdoc-uses-commonmark.md) + - [Platform and target support](rust-2018-outdated/platform-and-target-support/index.md) + - [`libcore` for low-level Rust](rust-2018-outdated/platform-and-target-support/libcore-for-low-level-rust.md) + - [WebAssembly support](rust-2018-outdated/platform-and-target-support/webassembly-support.md) + - [Global allocators](rust-2018-outdated/platform-and-target-support/global-allocators.md) + - [MSVC toolchain support](rust-2018-outdated/platform-and-target-support/msvc-toolchain-support.md) + - [MUSL support for fully static binaries](rust-2018-outdated/platform-and-target-support/musl-support-for-fully-static-binaries.md) + - [`cdylib` crates for C interoperability](rust-2018-outdated/platform-and-target-support/cdylib-crates-for-c-interoperability.md) ## The Next Edition diff --git a/src/rust-2018/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.md b/src/rust-2018-outdated/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.md similarity index 100% rename from src/rust-2018/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.md rename to src/rust-2018-outdated/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.md diff --git a/src/rust-2018/cargo-and-crates-io/cargo-check-for-faster-checking.md b/src/rust-2018-outdated/cargo-and-crates-io/cargo-check-for-faster-checking.md similarity index 100% rename from src/rust-2018/cargo-and-crates-io/cargo-check-for-faster-checking.md rename to src/rust-2018-outdated/cargo-and-crates-io/cargo-check-for-faster-checking.md diff --git a/src/rust-2018/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.md b/src/rust-2018-outdated/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.md similarity index 100% rename from src/rust-2018/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.md rename to src/rust-2018-outdated/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.md diff --git a/src/rust-2018/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.md b/src/rust-2018-outdated/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.md similarity index 100% rename from src/rust-2018/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.md rename to src/rust-2018-outdated/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.md diff --git a/src/rust-2018/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.md b/src/rust-2018-outdated/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.md similarity index 100% rename from src/rust-2018/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.md rename to src/rust-2018-outdated/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.md diff --git a/src/rust-2018/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.md b/src/rust-2018-outdated/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.md similarity index 100% rename from src/rust-2018/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.md rename to src/rust-2018-outdated/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.md diff --git a/src/rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.md b/src/rust-2018-outdated/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.md similarity index 100% rename from src/rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.md rename to src/rust-2018-outdated/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.md diff --git a/src/rust-2018/cargo-and-crates-io/index.md b/src/rust-2018-outdated/cargo-and-crates-io/index.md similarity index 100% rename from src/rust-2018/cargo-and-crates-io/index.md rename to src/rust-2018-outdated/cargo-and-crates-io/index.md diff --git a/src/rust-2018/cargo-and-crates-io/multi-file-examples.md b/src/rust-2018-outdated/cargo-and-crates-io/multi-file-examples.md similarity index 100% rename from src/rust-2018/cargo-and-crates-io/multi-file-examples.md rename to src/rust-2018-outdated/cargo-and-crates-io/multi-file-examples.md diff --git a/src/rust-2018/cargo-and-crates-io/replacing-dependencies-with-patch.md b/src/rust-2018-outdated/cargo-and-crates-io/replacing-dependencies-with-patch.md similarity index 100% rename from src/rust-2018/cargo-and-crates-io/replacing-dependencies-with-patch.md rename to src/rust-2018-outdated/cargo-and-crates-io/replacing-dependencies-with-patch.md diff --git a/src/rust-2018/control-flow/async-await-for-easier-concurrency.md b/src/rust-2018-outdated/control-flow/async-await-for-easier-concurrency.md similarity index 100% rename from src/rust-2018/control-flow/async-await-for-easier-concurrency.md rename to src/rust-2018-outdated/control-flow/async-await-for-easier-concurrency.md diff --git a/src/rust-2018/control-flow/index.md b/src/rust-2018-outdated/control-flow/index.md similarity index 100% rename from src/rust-2018/control-flow/index.md rename to src/rust-2018-outdated/control-flow/index.md diff --git a/src/rust-2018/control-flow/loops-can-break-with-a-value.md b/src/rust-2018-outdated/control-flow/loops-can-break-with-a-value.md similarity index 100% rename from src/rust-2018/control-flow/loops-can-break-with-a-value.md rename to src/rust-2018-outdated/control-flow/loops-can-break-with-a-value.md diff --git a/src/rust-2018/data-types/128-bit-integers.md b/src/rust-2018-outdated/data-types/128-bit-integers.md similarity index 100% rename from src/rust-2018/data-types/128-bit-integers.md rename to src/rust-2018-outdated/data-types/128-bit-integers.md diff --git a/src/rust-2018/data-types/choosing-alignment-with-the-repr-attribute.md b/src/rust-2018-outdated/data-types/choosing-alignment-with-the-repr-attribute.md similarity index 100% rename from src/rust-2018/data-types/choosing-alignment-with-the-repr-attribute.md rename to src/rust-2018-outdated/data-types/choosing-alignment-with-the-repr-attribute.md diff --git a/src/rust-2018/data-types/field-init-shorthand.md b/src/rust-2018-outdated/data-types/field-init-shorthand.md similarity index 100% rename from src/rust-2018/data-types/field-init-shorthand.md rename to src/rust-2018-outdated/data-types/field-init-shorthand.md diff --git a/src/rust-2018/data-types/inclusive-ranges.md b/src/rust-2018-outdated/data-types/inclusive-ranges.md similarity index 100% rename from src/rust-2018/data-types/inclusive-ranges.md rename to src/rust-2018-outdated/data-types/inclusive-ranges.md diff --git a/src/rust-2018/data-types/index.md b/src/rust-2018-outdated/data-types/index.md similarity index 100% rename from src/rust-2018/data-types/index.md rename to src/rust-2018-outdated/data-types/index.md diff --git a/src/rust-2018/data-types/operator-equals-are-now-implementable.md b/src/rust-2018-outdated/data-types/operator-equals-are-now-implementable.md similarity index 100% rename from src/rust-2018/data-types/operator-equals-are-now-implementable.md rename to src/rust-2018-outdated/data-types/operator-equals-are-now-implementable.md diff --git a/src/rust-2018/data-types/union-for-an-unsafe-form-of-enum.md b/src/rust-2018-outdated/data-types/union-for-an-unsafe-form-of-enum.md similarity index 100% rename from src/rust-2018/data-types/union-for-an-unsafe-form-of-enum.md rename to src/rust-2018-outdated/data-types/union-for-an-unsafe-form-of-enum.md diff --git a/src/rust-2018/documentation/index.md b/src/rust-2018-outdated/documentation/index.md similarity index 100% rename from src/rust-2018/documentation/index.md rename to src/rust-2018-outdated/documentation/index.md diff --git a/src/rust-2018/documentation/new-editions-of-the-book.md b/src/rust-2018-outdated/documentation/new-editions-of-the-book.md similarity index 100% rename from src/rust-2018/documentation/new-editions-of-the-book.md rename to src/rust-2018-outdated/documentation/new-editions-of-the-book.md diff --git a/src/rust-2018/documentation/std-os-has-documentation-for-all-platforms.md b/src/rust-2018-outdated/documentation/std-os-has-documentation-for-all-platforms.md similarity index 100% rename from src/rust-2018/documentation/std-os-has-documentation-for-all-platforms.md rename to src/rust-2018-outdated/documentation/std-os-has-documentation-for-all-platforms.md diff --git a/src/rust-2018/documentation/the-rust-bookshelf.md b/src/rust-2018-outdated/documentation/the-rust-bookshelf.md similarity index 100% rename from src/rust-2018/documentation/the-rust-bookshelf.md rename to src/rust-2018-outdated/documentation/the-rust-bookshelf.md diff --git a/src/rust-2018/documentation/the-rustonomicon.md b/src/rust-2018-outdated/documentation/the-rustonomicon.md similarity index 100% rename from src/rust-2018/documentation/the-rustonomicon.md rename to src/rust-2018-outdated/documentation/the-rustonomicon.md diff --git a/src/rust-2018/edition-changes.md b/src/rust-2018-outdated/edition-changes.md similarity index 100% rename from src/rust-2018/edition-changes.md rename to src/rust-2018-outdated/edition-changes.md diff --git a/src/rust-2018/error-handling-and-panics/aborting-on-panic.md b/src/rust-2018-outdated/error-handling-and-panics/aborting-on-panic.md similarity index 100% rename from src/rust-2018/error-handling-and-panics/aborting-on-panic.md rename to src/rust-2018-outdated/error-handling-and-panics/aborting-on-panic.md diff --git a/src/rust-2018/error-handling-and-panics/controlling-panics-with-std-panic.md b/src/rust-2018-outdated/error-handling-and-panics/controlling-panics-with-std-panic.md similarity index 100% rename from src/rust-2018/error-handling-and-panics/controlling-panics-with-std-panic.md rename to src/rust-2018-outdated/error-handling-and-panics/controlling-panics-with-std-panic.md diff --git a/src/rust-2018/error-handling-and-panics/index.md b/src/rust-2018-outdated/error-handling-and-panics/index.md similarity index 100% rename from src/rust-2018/error-handling-and-panics/index.md rename to src/rust-2018-outdated/error-handling-and-panics/index.md diff --git a/src/rust-2018/error-handling-and-panics/question-mark-in-main-and-tests.md b/src/rust-2018-outdated/error-handling-and-panics/question-mark-in-main-and-tests.md similarity index 100% rename from src/rust-2018/error-handling-and-panics/question-mark-in-main-and-tests.md rename to src/rust-2018-outdated/error-handling-and-panics/question-mark-in-main-and-tests.md diff --git a/src/rust-2018/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.md b/src/rust-2018-outdated/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.md similarity index 100% rename from src/rust-2018/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.md rename to src/rust-2018-outdated/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.md diff --git a/src/rust-2018/index.md b/src/rust-2018-outdated/index.md similarity index 100% rename from src/rust-2018/index.md rename to src/rust-2018-outdated/index.md diff --git a/src/rust-2018/macros/at-most-once.md b/src/rust-2018-outdated/macros/at-most-once.md similarity index 100% rename from src/rust-2018/macros/at-most-once.md rename to src/rust-2018-outdated/macros/at-most-once.md diff --git a/src/rust-2018/macros/custom-derive.md b/src/rust-2018-outdated/macros/custom-derive.md similarity index 100% rename from src/rust-2018/macros/custom-derive.md rename to src/rust-2018-outdated/macros/custom-derive.md diff --git a/src/rust-2018/macros/index.md b/src/rust-2018-outdated/macros/index.md similarity index 100% rename from src/rust-2018/macros/index.md rename to src/rust-2018-outdated/macros/index.md diff --git a/src/rust-2018/macros/macro-changes.md b/src/rust-2018-outdated/macros/macro-changes.md similarity index 100% rename from src/rust-2018/macros/macro-changes.md rename to src/rust-2018-outdated/macros/macro-changes.md diff --git a/src/rust-2018/module-system/index.md b/src/rust-2018-outdated/module-system/index.md similarity index 100% rename from src/rust-2018/module-system/index.md rename to src/rust-2018-outdated/module-system/index.md diff --git a/src/rust-2018/module-system/more-visibility-modifiers.md b/src/rust-2018-outdated/module-system/more-visibility-modifiers.md similarity index 100% rename from src/rust-2018/module-system/more-visibility-modifiers.md rename to src/rust-2018-outdated/module-system/more-visibility-modifiers.md diff --git a/src/rust-2018/module-system/nested-imports-with-use.md b/src/rust-2018-outdated/module-system/nested-imports-with-use.md similarity index 100% rename from src/rust-2018/module-system/nested-imports-with-use.md rename to src/rust-2018-outdated/module-system/nested-imports-with-use.md diff --git a/src/rust-2018/module-system/path-clarity.md b/src/rust-2018-outdated/module-system/path-clarity.md similarity index 100% rename from src/rust-2018/module-system/path-clarity.md rename to src/rust-2018-outdated/module-system/path-clarity.md diff --git a/src/rust-2018/module-system/raw-identifiers.md b/src/rust-2018-outdated/module-system/raw-identifiers.md similarity index 100% rename from src/rust-2018/module-system/raw-identifiers.md rename to src/rust-2018-outdated/module-system/raw-identifiers.md diff --git a/src/rust-2018/ownership-and-lifetimes/default-match-bindings.md b/src/rust-2018-outdated/ownership-and-lifetimes/default-match-bindings.md similarity index 100% rename from src/rust-2018/ownership-and-lifetimes/default-match-bindings.md rename to src/rust-2018-outdated/ownership-and-lifetimes/default-match-bindings.md diff --git a/src/rust-2018/ownership-and-lifetimes/index.md b/src/rust-2018-outdated/ownership-and-lifetimes/index.md similarity index 100% rename from src/rust-2018/ownership-and-lifetimes/index.md rename to src/rust-2018-outdated/ownership-and-lifetimes/index.md diff --git a/src/rust-2018/ownership-and-lifetimes/inference-in-structs.md b/src/rust-2018-outdated/ownership-and-lifetimes/inference-in-structs.md similarity index 100% rename from src/rust-2018/ownership-and-lifetimes/inference-in-structs.md rename to src/rust-2018-outdated/ownership-and-lifetimes/inference-in-structs.md diff --git a/src/rust-2018/ownership-and-lifetimes/lifetime-elision-in-impl.md b/src/rust-2018-outdated/ownership-and-lifetimes/lifetime-elision-in-impl.md similarity index 100% rename from src/rust-2018/ownership-and-lifetimes/lifetime-elision-in-impl.md rename to src/rust-2018-outdated/ownership-and-lifetimes/lifetime-elision-in-impl.md diff --git a/src/rust-2018/ownership-and-lifetimes/non-lexical-lifetimes.md b/src/rust-2018-outdated/ownership-and-lifetimes/non-lexical-lifetimes.md similarity index 100% rename from src/rust-2018/ownership-and-lifetimes/non-lexical-lifetimes.md rename to src/rust-2018-outdated/ownership-and-lifetimes/non-lexical-lifetimes.md diff --git a/src/rust-2018/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.md b/src/rust-2018-outdated/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.md similarity index 100% rename from src/rust-2018/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.md rename to src/rust-2018-outdated/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.md diff --git a/src/rust-2018/ownership-and-lifetimes/the-anonymous-lifetime.md b/src/rust-2018-outdated/ownership-and-lifetimes/the-anonymous-lifetime.md similarity index 100% rename from src/rust-2018/ownership-and-lifetimes/the-anonymous-lifetime.md rename to src/rust-2018-outdated/ownership-and-lifetimes/the-anonymous-lifetime.md diff --git a/src/rust-2018/platform-and-target-support/cdylib-crates-for-c-interoperability.md b/src/rust-2018-outdated/platform-and-target-support/cdylib-crates-for-c-interoperability.md similarity index 100% rename from src/rust-2018/platform-and-target-support/cdylib-crates-for-c-interoperability.md rename to src/rust-2018-outdated/platform-and-target-support/cdylib-crates-for-c-interoperability.md diff --git a/src/rust-2018/platform-and-target-support/global-allocators.md b/src/rust-2018-outdated/platform-and-target-support/global-allocators.md similarity index 100% rename from src/rust-2018/platform-and-target-support/global-allocators.md rename to src/rust-2018-outdated/platform-and-target-support/global-allocators.md diff --git a/src/rust-2018/platform-and-target-support/index.md b/src/rust-2018-outdated/platform-and-target-support/index.md similarity index 100% rename from src/rust-2018/platform-and-target-support/index.md rename to src/rust-2018-outdated/platform-and-target-support/index.md diff --git a/src/rust-2018/platform-and-target-support/libcore-for-low-level-rust.md b/src/rust-2018-outdated/platform-and-target-support/libcore-for-low-level-rust.md similarity index 100% rename from src/rust-2018/platform-and-target-support/libcore-for-low-level-rust.md rename to src/rust-2018-outdated/platform-and-target-support/libcore-for-low-level-rust.md diff --git a/src/rust-2018/platform-and-target-support/msvc-toolchain-support.md b/src/rust-2018-outdated/platform-and-target-support/msvc-toolchain-support.md similarity index 100% rename from src/rust-2018/platform-and-target-support/msvc-toolchain-support.md rename to src/rust-2018-outdated/platform-and-target-support/msvc-toolchain-support.md diff --git a/src/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.md b/src/rust-2018-outdated/platform-and-target-support/musl-support-for-fully-static-binaries.md similarity index 100% rename from src/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.md rename to src/rust-2018-outdated/platform-and-target-support/musl-support-for-fully-static-binaries.md diff --git a/src/rust-2018/platform-and-target-support/webassembly-support.md b/src/rust-2018-outdated/platform-and-target-support/webassembly-support.md similarity index 100% rename from src/rust-2018/platform-and-target-support/webassembly-support.md rename to src/rust-2018-outdated/platform-and-target-support/webassembly-support.md diff --git a/src/rust-2018/rustdoc/documentation-tests-can-now-compile-fail.md b/src/rust-2018-outdated/rustdoc/documentation-tests-can-now-compile-fail.md similarity index 100% rename from src/rust-2018/rustdoc/documentation-tests-can-now-compile-fail.md rename to src/rust-2018-outdated/rustdoc/documentation-tests-can-now-compile-fail.md diff --git a/src/rust-2018/rustdoc/index.md b/src/rust-2018-outdated/rustdoc/index.md similarity index 100% rename from src/rust-2018/rustdoc/index.md rename to src/rust-2018-outdated/rustdoc/index.md diff --git a/src/rust-2018/rustdoc/rustdoc-uses-commonmark.md b/src/rust-2018-outdated/rustdoc/rustdoc-uses-commonmark.md similarity index 100% rename from src/rust-2018/rustdoc/rustdoc-uses-commonmark.md rename to src/rust-2018-outdated/rustdoc/rustdoc-uses-commonmark.md diff --git a/src/rust-2018/rustup-for-managing-rust-versions.md b/src/rust-2018-outdated/rustup-for-managing-rust-versions.md similarity index 100% rename from src/rust-2018/rustup-for-managing-rust-versions.md rename to src/rust-2018-outdated/rustup-for-managing-rust-versions.md diff --git a/src/rust-2018/simd-for-faster-computing.md b/src/rust-2018-outdated/simd-for-faster-computing.md similarity index 100% rename from src/rust-2018/simd-for-faster-computing.md rename to src/rust-2018-outdated/simd-for-faster-computing.md diff --git a/src/rust-2018/slice-patterns.md b/src/rust-2018-outdated/slice-patterns.md similarity index 100% rename from src/rust-2018/slice-patterns.md rename to src/rust-2018-outdated/slice-patterns.md diff --git a/src/rust-2018/the-compiler/an-attribute-for-deprecation.md b/src/rust-2018-outdated/the-compiler/an-attribute-for-deprecation.md similarity index 100% rename from src/rust-2018/the-compiler/an-attribute-for-deprecation.md rename to src/rust-2018-outdated/the-compiler/an-attribute-for-deprecation.md diff --git a/src/rust-2018/the-compiler/improved-error-messages.md b/src/rust-2018-outdated/the-compiler/improved-error-messages.md similarity index 100% rename from src/rust-2018/the-compiler/improved-error-messages.md rename to src/rust-2018-outdated/the-compiler/improved-error-messages.md diff --git a/src/rust-2018/the-compiler/incremental-compilation-for-faster-compiles.md b/src/rust-2018-outdated/the-compiler/incremental-compilation-for-faster-compiles.md similarity index 100% rename from src/rust-2018/the-compiler/incremental-compilation-for-faster-compiles.md rename to src/rust-2018-outdated/the-compiler/incremental-compilation-for-faster-compiles.md diff --git a/src/rust-2018/the-compiler/index.md b/src/rust-2018-outdated/the-compiler/index.md similarity index 100% rename from src/rust-2018/the-compiler/index.md rename to src/rust-2018-outdated/the-compiler/index.md diff --git a/src/rust-2018/trait-system/associated-constants.md b/src/rust-2018-outdated/trait-system/associated-constants.md similarity index 100% rename from src/rust-2018/trait-system/associated-constants.md rename to src/rust-2018-outdated/trait-system/associated-constants.md diff --git a/src/rust-2018/trait-system/dyn-trait-for-trait-objects.md b/src/rust-2018-outdated/trait-system/dyn-trait-for-trait-objects.md similarity index 100% rename from src/rust-2018/trait-system/dyn-trait-for-trait-objects.md rename to src/rust-2018-outdated/trait-system/dyn-trait-for-trait-objects.md diff --git a/src/rust-2018/trait-system/impl-trait-for-returning-complex-types-with-ease.md b/src/rust-2018-outdated/trait-system/impl-trait-for-returning-complex-types-with-ease.md similarity index 100% rename from src/rust-2018/trait-system/impl-trait-for-returning-complex-types-with-ease.md rename to src/rust-2018-outdated/trait-system/impl-trait-for-returning-complex-types-with-ease.md diff --git a/src/rust-2018/trait-system/index.md b/src/rust-2018-outdated/trait-system/index.md similarity index 100% rename from src/rust-2018/trait-system/index.md rename to src/rust-2018-outdated/trait-system/index.md diff --git a/src/rust-2018/trait-system/more-container-types-support-trait-objects.md b/src/rust-2018-outdated/trait-system/more-container-types-support-trait-objects.md similarity index 100% rename from src/rust-2018/trait-system/more-container-types-support-trait-objects.md rename to src/rust-2018-outdated/trait-system/more-container-types-support-trait-objects.md diff --git a/src/rust-2018/trait-system/no-anon-params.md b/src/rust-2018-outdated/trait-system/no-anon-params.md similarity index 100% rename from src/rust-2018/trait-system/no-anon-params.md rename to src/rust-2018-outdated/trait-system/no-anon-params.md From 38e49159626c7699a9adc4dd7cb3ebff341968e9 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 3 May 2021 14:07:03 -0400 Subject: [PATCH 02/13] introduce new rust 2018 content --- src/SUMMARY.md | 10 + src/rust-2018/cargo.md | 10 + src/rust-2018/index.md | 3 + src/rust-2018/new_keywords.md | 64 ++++ src/rust-2018/path-changes.md | 359 ++++++++++++++++++++++ src/rust-2018/trait_fn_parameters.md | 32 ++ src/rust-2018/tyvar_behind_raw_pointer.md | 11 + src/rust-2021/index.md | 1 + 8 files changed, 490 insertions(+) create mode 100644 src/rust-2018/cargo.md create mode 100644 src/rust-2018/index.md create mode 100644 src/rust-2018/new_keywords.md create mode 100644 src/rust-2018/path-changes.md create mode 100644 src/rust-2018/trait_fn_parameters.md create mode 100644 src/rust-2018/tyvar_behind_raw_pointer.md create mode 100644 src/rust-2021/index.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index fe816098..358d1876 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -14,6 +14,16 @@ ## Rust 2018 +- [Rust 2018](rust-2018/index.md) + - [Path and module system changes](rust-2018/path-changes.md) + - [Anonymous trait function parameters deprecated](rust-2018/trait_fn_parameters.md) + - [New keywords](rust-2018/new_keywords.md) + - [Method dispatch for raw pointers to inference variables](rust-2018/tyvar_behind_raw_pointer.md) + - [Cargo changes](rust-2018/cargo.md) +- [Rust 2021](rust-2021/index.md) + +## Rust 2018 (outdated) + - [Rust 2018 (outdated)](rust-2018-outdated/index.md) - [2018-Specific Changes](rust-2018-outdated/edition-changes.md) - [Module system](rust-2018-outdated/module-system/index.md) diff --git a/src/rust-2018/cargo.md b/src/rust-2018/cargo.md new file mode 100644 index 00000000..6b7ee9be --- /dev/null +++ b/src/rust-2018/cargo.md @@ -0,0 +1,10 @@ +# Cargo changes + +## Summary + +- If there is a target definition in a `Cargo.toml` manifest, it no longer + automatically disables automatic discovery of other targets. +- Target paths of the form `src/{target_name}.rs` are no longer inferred for + targets where the `path` field is not set. +- `cargo install` for the current directory is no longer allowed, you must + specify `cargo install --path .` to install the current package. \ No newline at end of file diff --git a/src/rust-2018/index.md b/src/rust-2018/index.md new file mode 100644 index 00000000..021c6d7f --- /dev/null +++ b/src/rust-2018/index.md @@ -0,0 +1,3 @@ +# Rust 2018 + +The edition system was created for the release of Rust 2018. The release of the Rust 2018 edition coincided with a number of other features all coordinated around the theme of *productivity*. The majority of those features were backwards compatible and are now available on all editions; however, some of those changes required the edition mechanism (most notably the [module system changes](path-changes.md)). diff --git a/src/rust-2018/new_keywords.md b/src/rust-2018/new_keywords.md new file mode 100644 index 00000000..2fe564dc --- /dev/null +++ b/src/rust-2018/new_keywords.md @@ -0,0 +1,64 @@ +# New keywords + +![Minimum Rust version: 1.27](https://img.shields.io/badge/Minimum%20Rust%20Version-1.27-brightgreen.svg) + +## Summary + +- [`dyn`] is a [strict keyword][strict], in 2015 it is a [weak keyword]. +- `async` and `await` are [strict keywords][strict]. +- `try` is a [reserved keyword]. + +[strict]: https://doc.rust-lang.org/reference/keywords.html#strict-keywords +[weak keyword]: https://doc.rust-lang.org/reference/keywords.html#weak-keywords +[reserved keyword]: https://doc.rust-lang.org/reference/keywords.html#reserved-keywords + +## Motivation + +### `dyn Trait` for trait objects + +The `dyn Trait` feature is the new syntax for using trait objects. In short: + +* `Box` becomes `Box` +* `&Trait` and `&mut Trait` become `&dyn Trait` and `&mut dyn Trait` + +And so on. In code: + +```rust +trait Trait {} + +impl Trait for i32 {} + +// old +fn function1() -> Box { +# unimplemented!() +} + +// new +fn function2() -> Box { +# unimplemented!() +} +``` + +That's it! + +#### Why? + +Using just the trait name for trait objects turned out to be a bad decision. +The current syntax is often ambiguous and confusing, even to veterans, +and favors a feature that is not more frequently used than its alternatives, +is sometimes slower, and often cannot be used at all when its alternatives can. + +Furthermore, with `impl Trait` arriving, "`impl Trait` vs `dyn Trait`" is much +more symmetric, and therefore a bit nicer, than "`impl Trait` vs `Trait`". +`impl Trait` is explained [here](impl-trait-for-returning-complex-types-with-ease.md). + +In the new edition, you should therefore prefer `dyn Trait` to just `Trait` +where you need a trait object. + +### `async` and `await` + +These keywords are reserved to implement the async-await feature of Rust, which was ultimately [released to stable in 1.39.0](https://blog.rust-lang.org/2019/11/07/Async-await-stable.html). + +### `try` keyword + +The `try` keyword is reserved for use in `try` blocks, which have not (as of this writing) been stabilized ([tracking issue](https://github.com/rust-lang/rust/issues/31436)) diff --git a/src/rust-2018/path-changes.md b/src/rust-2018/path-changes.md new file mode 100644 index 00000000..f4e5ceea --- /dev/null +++ b/src/rust-2018/path-changes.md @@ -0,0 +1,359 @@ +# Path and module system changes + +![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) + +## Summary + +- Paths in `use` declarations now work the same as other paths. +- Paths starting with `::` must now be followed with an external crate. +- Paths in `pub(in path)` visibility modifiers must now start with `crate`, `self`, or `super`. + +## Motivation + +The module system is often one of the hardest things for people new to Rust. Everyone +has their own things that take time to master, of course, but there's a root +cause for why it's so confusing to many: while there are simple and +consistent rules defining the module system, their consequences can feel +inconsistent, counterintuitive and mysterious. + +As such, the 2018 edition of Rust introduces a few new module system +features, but they end up *simplifying* the module system, to make it more +clear as to what is going on. + +Here's a brief summary: + +* `extern crate` is no longer needed in 99% of circumstances. +* The `crate` keyword refers to the current crate. +* Paths may start with a crate name, even within submodules. +* Paths starting with `::` must reference an external crate. +* A `foo.rs` and `foo/` subdirectory may coexist; `mod.rs` is no longer needed + when placing submodules in a subdirectory. +* Paths in `use` declarations work the same as other paths. + +These may seem like arbitrary new rules when put this way, but the mental +model is now significantly simplified overall. Read on for more details! + +## More details + +Let's talk about each new feature in turn. + +### No more `extern crate` + +This one is quite straightforward: you no longer need to write `extern crate` to +import a crate into your project. Before: + +```rust,ignore +// Rust 2015 + +extern crate futures; + +mod submodule { + use futures::Future; +} +``` + +After: + +```rust,ignore +// Rust 2018 + +mod submodule { + use futures::Future; +} +``` + +Now, to add a new crate to your project, you can add it to your `Cargo.toml`, +and then there is no step two. If you're not using Cargo, you already had to pass +`--extern` flags to give `rustc` the location of external crates, so you'd just +keep doing what you were doing there as well. + +> One small note here: `cargo fix` will not currently automate this change. We may +> have it do this for you in the future. + +#### An exception + +There's one exception to this rule, and that's the "sysroot" crates. These are the +crates distributed with Rust itself. + +Usually these are only needed in very specialized situations. Starting in +1.41, `rustc` accepts the `--extern=CRATE_NAME` flag which automatically adds +the given crate name in a way similar to `extern crate`. Build tools may use +this to inject sysroot crates into the crate's prelude. Cargo does not have a +general way to express this, though it uses it for `proc_macro` crates. + +Some examples of needing to explicitly import sysroot crates are: + +* [`std`]: Usually this is not neccesary, because `std` is automatically + imported unless the crate is marked with [`#![no_std]`][no_std]. +* [`core`]: Usually this is not necessary, because `core` is automatically + imported, unless the crate is marked with [`#![no_core]`][no_core]. For + example, some of the internal crates used by the standard library itself + need this. +* [`proc_macro`]: This is automatically imported by Cargo if it is a + proc-macro crate starting in 1.42. `extern crate proc_macro;` would be + needed if you want to support older releases, or if using another build tool + that does not pass the appropriate `--extern` flags to `rustc`. +* [`alloc`]: Items in the `alloc` crate are usually accessed via re-exports in + the `std` crate. If you are working with a `no_std` crate that supports + allocation, then you may need to explicitly import `alloc`. +* [`test`]: This is only available on the [nightly channel], and is usually + only used for the unstable benchmark support. + +[`alloc`]: ../../../alloc/index.html +[`core`]: ../../../core/index.html +[`proc_macro`]: ../../../proc_macro/index.html +[`std`]: ../../../std/index.html +[`test`]: ../../../test/index.html +[nightly channel]: ../../../book/appendix-07-nightly-rust.html +[no_core]: https://github.com/rust-lang/rust/issues/29639 +[no_std]: ../../../reference/names/preludes.html#the-no_std-attribute + +#### Macros + +One other use for `extern crate` was to import macros; that's no longer needed. +Check [the macro section](../macros/macro-changes.md) for more. + +#### Renaming crates + +If you've been using `as` to rename your crate like this: + +```rust,ignore +extern crate futures as f; + +use f::Future; +``` + +then removing the `extern crate` line on its own won't work. You'll need to do this: + +```rust,ignore +use futures as f; + +use self::f::Future; +``` + +This change will need to happen in any module that uses `f`. + +### The `crate` keyword refers to the current crate + +In `use` declarations and in other code, you can refer to the root of the +current crate with the `crate::` prefix. For instance, `crate::foo::bar` will +always refer to the name `bar` inside the module `foo`, from anywhere else in +the same crate. + +The prefix `::` previously referred to either the crate root or an external +crate; it now unambiguously refers to an external crate. For instance, +`::foo::bar` always refers to the name `bar` inside the external crate `foo`. + +### Extern crate paths + +Previously, using an external crate in a module without a `use` import +required a leading `::` on the path. + +```rust,ignore +// Rust 2015 + +extern crate chrono; + +fn foo() { + // this works in the crate root + let x = chrono::Utc::now(); +} + +mod submodule { + fn function() { + // but in a submodule it requires a leading :: if not imported with `use` + let x = ::chrono::Utc::now(); + } +} +``` + +Now, extern crate names are in scope in the entire crate, including +submodules. + +```rust,ignore +// Rust 2018 + +fn foo() { + // this works in the crate root + let x = chrono::Utc::now(); +} + +mod submodule { + fn function() { + // crates may be referenced directly, even in submodules + let x = chrono::Utc::now(); + } +} +``` + +### No more `mod.rs` + +In Rust 2015, if you have a submodule: + +```rust,ignore +// This `mod` declaration looks for the `foo` module in +// `foo.rs` or `foo/mod.rs`. +mod foo; +``` + +It can live in `foo.rs` or `foo/mod.rs`. If it has submodules of its own, it +*must* be `foo/mod.rs`. So a `bar` submodule of `foo` would live at +`foo/bar.rs`. + +In Rust 2018 the restriction that a module with submodules must be named +`mod.rs` is lifted. `foo.rs` can just be `foo.rs`, +and the submodule is still `foo/bar.rs`. This eliminates the special +name, and if you have a bunch of files open in your editor, you can clearly +see their names, instead of having a bunch of tabs named `mod.rs`. + + + + + + + + + + + + + + +
Rust 2015Rust 2018
+
+.
+├── lib.rs
+└── foo/
+    ├── mod.rs
+    └── bar.rs
+
+
+
+.
+├── lib.rs
+├── foo.rs
+└── foo/
+    └── bar.rs
+
+
+ +### `use` paths + +![Minimum Rust version: 1.32](https://img.shields.io/badge/Minimum%20Rust%20Version-1.32-brightgreen.svg) + +Rust 2018 simplifies and unifies path handling compared to Rust 2015. In Rust +2015, paths work differently in `use` declarations than they do elsewhere. In +particular, paths in `use` declarations would always start from the crate +root, while paths in other code implicitly started from the current scope. +Those differences didn't have any effect in the top-level module, which meant +that everything would seem straightforward until working on a project large +enough to have submodules. + +In Rust 2018, paths in `use` declarations and in other code work the same way, +both in the top-level module and in any submodule. You can use a relative path +from the current scope, a path starting from an external crate name, or a path +starting with `crate`, `super`, or `self`. + +Code that looked like this: + +```rust,ignore +// Rust 2015 + +extern crate futures; + +use futures::Future; + +mod foo { + pub struct Bar; +} + +use foo::Bar; + +fn my_poll() -> futures::Poll { ... } + +enum SomeEnum { + V1(usize), + V2(String), +} + +fn func() { + let five = std::sync::Arc::new(5); + use SomeEnum::*; + match ... { + V1(i) => { ... } + V2(s) => { ... } + } +} +``` + +will look exactly the same in Rust 2018, except that you can delete the `extern +crate` line: + +```rust,ignore +// Rust 2018 + +use futures::Future; + +mod foo { + pub struct Bar; +} + +use foo::Bar; + +fn my_poll() -> futures::Poll { ... } + +enum SomeEnum { + V1(usize), + V2(String), +} + +fn func() { + let five = std::sync::Arc::new(5); + use SomeEnum::*; + match ... { + V1(i) => { ... } + V2(s) => { ... } + } +} +``` + +The same code will also work completely unmodified in a submodule: + +```rust,ignore +// Rust 2018 + +mod submodule { + use futures::Future; + + mod foo { + pub struct Bar; + } + + use foo::Bar; + + fn my_poll() -> futures::Poll { ... } + + enum SomeEnum { + V1(usize), + V2(String), + } + + fn func() { + let five = std::sync::Arc::new(5); + use SomeEnum::*; + match ... { + V1(i) => { ... } + V2(s) => { ... } + } + } +} +``` + +This makes it easy to move code around in a project, and avoids introducing +additional complexity to multi-module projects. + +If a path is ambiguous, such as if you have an external crate and a local +module or item with the same name, you'll get an error, and you'll need to +either rename one of the conflicting names or explicitly disambiguate the path. +To explicitly disambiguate a path, use `::name` for an external crate name, or +`self::name` for a local module or item. diff --git a/src/rust-2018/trait_fn_parameters.md b/src/rust-2018/trait_fn_parameters.md new file mode 100644 index 00000000..e82af19c --- /dev/null +++ b/src/rust-2018/trait_fn_parameters.md @@ -0,0 +1,32 @@ +# Anonymous trait function parameters deprecated + +![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) + +## Summary + +- [Trait function parameters] may use any irrefutable pattern when the function has a body. + +[Trait function parameters]: https://doc.rust-lang.org/stable/reference/items/traits.html#parameter-patterns + + +## Details + +In accordance with RFC [#1685](https://github.com/rust-lang/rfcs/pull/1685), +parameters in trait method declarations are no longer allowed to be anonymous. + +For example, in the 2015 edition, this was allowed: + +```rust +trait Foo { + fn foo(&self, u8); +} +``` + +In the 2018 edition, all parameters must be given an argument name (even if it's just +`_`): + +```rust +trait Foo { + fn foo(&self, baz: u8); +} +``` diff --git a/src/rust-2018/tyvar_behind_raw_pointer.md b/src/rust-2018/tyvar_behind_raw_pointer.md new file mode 100644 index 00000000..fce7d06a --- /dev/null +++ b/src/rust-2018/tyvar_behind_raw_pointer.md @@ -0,0 +1,11 @@ +# Method dispatch for raw pointers to inference variables + +## Summary + +- The [`tyvar_behind_raw_pointer`][#46906] lint is now a hard error. + +[#46906]: https://github.com/rust-lang/rust/issues/46906 + +## Details + +See Rust issue [#46906] for details. \ No newline at end of file diff --git a/src/rust-2021/index.md b/src/rust-2021/index.md new file mode 100644 index 00000000..72a1ac65 --- /dev/null +++ b/src/rust-2021/index.md @@ -0,0 +1 @@ +# Rust 2021 From 0dd70e210c768f4d0ecca4e4d357bc2e11545ca7 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 3 May 2021 14:22:50 -0400 Subject: [PATCH 03/13] incorporate material from Rust 2021 blog post --- src/SUMMARY.md | 13 ++- src/editions/index.md | 100 +++++++++++------- ...ng-an-existing-project-to-a-new-edition.md | 2 +- src/rust-2021/IntoIterator_for_arrays.md | 49 +++++++++ src/rust-2021/default_cargo_resolver.md | 18 ++++ src/rust-2021/disjoint_capture_in_closures.md | 37 +++++++ src/rust-2021/index.md | 17 ++- src/rust-2021/or_patterns_macro_rules.md | 28 +++++ src/rust-2021/panic_macro_consistency.md | 44 ++++++++ src/rust-2021/prelude.md | 32 ++++++ src/rust-2021/reserving_syntax.md | 40 +++++++ src/rust-2021/warnings_promoted_to_error.md | 17 +++ 12 files changed, 353 insertions(+), 44 deletions(-) create mode 100644 src/rust-2021/IntoIterator_for_arrays.md create mode 100644 src/rust-2021/default_cargo_resolver.md create mode 100644 src/rust-2021/disjoint_capture_in_closures.md create mode 100644 src/rust-2021/or_patterns_macro_rules.md create mode 100644 src/rust-2021/panic_macro_consistency.md create mode 100644 src/rust-2021/prelude.md create mode 100644 src/rust-2021/reserving_syntax.md create mode 100644 src/rust-2021/warnings_promoted_to_error.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 358d1876..11be43b1 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -20,7 +20,18 @@ - [New keywords](rust-2018/new_keywords.md) - [Method dispatch for raw pointers to inference variables](rust-2018/tyvar_behind_raw_pointer.md) - [Cargo changes](rust-2018/cargo.md) -- [Rust 2021](rust-2021/index.md) + +## Rust 2021 + +- [Rust 2021 ⚠️](rust-2021/index.md) + - [Additions to the prelude](rust-2021/prelude.md) + - [Default Cargo feature resolver](rust-2021/default_cargo_resolver.md) + - [IntoIterator for arrays](rust-2021/IntoIterator_for_arrays.md) + - [Disjoint capture in closures](rust-2021/disjoint_capture_in_closures.md) + - [Panic macro consistency](rust-2021/panic_macro_consistency.md) + - [Reserving syntax](rust-2021/reserving_syntax.md) + - [Warnings promoted to errors](rust-2021/warnings_promoted_to_error.md) + - [Or patterns in macro-rules](rust-2021/or_patterns_macro_rules.md) ## Rust 2018 (outdated) diff --git a/src/editions/index.md b/src/editions/index.md index 7555b097..e12285c4 100644 --- a/src/editions/index.md +++ b/src/editions/index.md @@ -1,43 +1,61 @@ # What are Editions? -Rust ships releases on a six-week cycle. This means that users get a constant -stream of new features. This is much faster than updates for other languages, -but this also means that each update is smaller. After a while, all of those -tiny changes add up. But, from release to release, it can be hard to look back -and say *"Wow, between Rust 1.10 and Rust 1.20, Rust has changed a lot!"* - -Every two or three years, we'll be producing a new *edition* of Rust. Each -edition brings together the features that have landed into a clear package, with -fully updated documentation and tooling. New editions ship through the usual -release process. - -This serves different purposes for different people: - -- For active Rust users, it brings together incremental changes into an - easy-to-understand package. - -- For non-users, it signals that some major advancements have landed, which - might make Rust worth another look. - -- For those developing Rust itself, it provides a rallying point for the project as a - whole. - -## Compatibility - -When a new edition becomes available in the compiler, crates must explicitly opt -in to it to take full advantage. This opt in enables editions to contain -incompatible changes, like adding a new keyword that might conflict with -identifiers in code, or turning warnings into errors. A Rust compiler will -support all editions that existed prior to the compiler's release, and can link -crates of any supported editions together. -Edition changes only affect the way the compiler initially parses the code. -Therefore, if you're using Rust 2015, and -one of your dependencies uses Rust 2018, it all works just fine. The opposite -situation works as well. - -Just to be clear: most features will be available on all editions. -People using any edition of Rust will continue to see improvements as new -stable releases are made. In some cases however, mainly when new keywords are -added, but sometimes for other reasons, there may be new features that are only -available in later editions. You only need to upgrade if you want to take -advantage of such features. \ No newline at end of file +The release of Rust 1.0 established +["stability without stagnation"](https://blog.rust-lang.org/2014/10/30/Stability.html) +as a core Rust deliverable. +Ever since the 1.0 release, +the rule for Rust has been that once a feature has been released on stable, +we are committed to supporting that feature for all future releases. + +There are times, however, when it is useful to be able to make small changes +to the language that are not backwards compatible. +The most obvious example is introducing a new keyword, +which would invalidate variables with the same name. +For example, the first version of Rust did not have the `async` and `await` keywords. +Suddenly changing those words to keywords in a later version would've broken code like `let async = 1;`. + +**Editions** are the mechanism we use to solve this problem. +When we want to release a feature that would otherwise be backwards incompatible, +we do so as part of a new Rust *edition*. +Editions are opt-in, and so existing crates do +not see these changes until they explicitly migrate over to the new edition. +This means that even the latest version of Rust will still *not* treat `async` as a keyword, +unless edition 2018 or later is chosen. +This choice is made *per crate* [as part of its `Cargo.toml`](https://doc.rust-lang.org/cargo/reference/manifest.html#the-edition-field). +New crates created by `cargo new` are always configured to use the latest stable edition. + +### Editions do not split the ecosystem + +The most important rule for editions is that crates in one edition can +interoperate seamlessly with crates compiled in other editions. This ensures +that the decision to migrate to a newer edition is a "private one" that the +crate can make without affecting others. + +The requirement for crate interoperability implies some limits on the kinds of +changes that we can make in an edition. +In general, changes that occur in an edition tend to be "skin deep". +All Rust code, regardless of edition, +is ultimately compiled to the same internal representation within the compiler. + +### Edition migration is easy and largely automated + +Our goal is to make it easy for crates to upgrade to a new edition. +When we release a new edition, +we also provide [tooling to automate the migration](https://doc.rust-lang.org/cargo/commands/cargo-fix.html). +It makes minor changes to your code necessary to make it compatible with the new edition. +For example, when migrating to Rust 2018, it changes anything named `async` to use the equivalent +[raw identifier syntax](https://doc.rust-lang.org/rust-by-example/compatibility/raw_identifiers.html): `r#async`. + +The automated migrations are not necessarily perfect: +there might be some corner cases where manual changes are still required. +The tooling tries hard to avoid changes +to semantics that could affect the correctness or performance of the code. + +In addition to tooling, we also maintain this Edition Migration Guide that covers +the changes that are part of an edition. +This guide describes each change and gives pointers to where you can learn more about it. +It also covers any corner cases or details you should be aware of. +This guide serves both as an overview of the edition +and as a quick troubleshooting reference +if you encounter problems with the automated tooling. + diff --git a/src/editions/transitioning-an-existing-project-to-a-new-edition.md b/src/editions/transitioning-an-existing-project-to-a-new-edition.md index 161b742d..beb23604 100644 --- a/src/editions/transitioning-an-existing-project-to-a-new-edition.md +++ b/src/editions/transitioning-an-existing-project-to-a-new-edition.md @@ -7,7 +7,7 @@ have a project that's using Rust 2015, and you'd like to use Rust 2018 for it instead, there's a few steps that you need to take. > It's our intention that the migration to new editions is as smooth an -> experience as possible. If it's difficult for you to upgrade to Rust 2018, +> experience as possible. If it's difficult for you to upgrade to the latest edition, > we consider that a bug. If you run into problems with this process, please > [file a bug](https://github.com/rust-lang/rust/issues/new). Thank you! diff --git a/src/rust-2021/IntoIterator_for_arrays.md b/src/rust-2021/IntoIterator_for_arrays.md new file mode 100644 index 00000000..302c285a --- /dev/null +++ b/src/rust-2021/IntoIterator_for_arrays.md @@ -0,0 +1,49 @@ +# IntoIterator for arrays + +## Summary + +## Details + +Until Rust 1.53, only *references* to arrays implement `IntoIterator`. +This means you can iterate over `&[1, 2, 3]` and `&mut [1, 2, 3]`, +but not over `[1, 2, 3]` directly. + +```rust +for &e in &[1, 2, 3] {} // Ok :) + +for e in [1, 2, 3] {} // Error :( +``` + +This has been [a long-standing issue][25], but the solution is not as simple as it seems. +Just [adding the trait implementation][20] would break existing code. +`array.into_iter()` already compiles today because that implicitly calls +`(&array).into_iter()` due to [how method call syntax works][22]. +Adding the trait implementation would change the meaning. + +Usually we categorize this type of breakage +(adding a trait implementation) 'minor' and acceptable. +But in this case there is too much code that would be broken by it. + +It has been suggested many times to "only implement `IntoIterator` for arrays in Rust 2021". +However, this is simply not possible. +You can't have a trait implementation exist in one edition and not in another, +since editions can be mixed. + +Instead, we decided to add the trait implementation in *all* editions (starting in Rust 1.53.0), +but add a small hack to avoid breakage until Rust 2021. +In Rust 2015 and 2018 code, the compiler will still resolve `array.into_iter()` +to `(&array).into_iter()` like before, as if the trait implementation does not exist. +This *only* applies to the `.into_iter()` method call syntax. +It does not affect any other syntax such as `for e in [1, 2, 3]`, `iter.zip([1, 2, 3])` or +`IntoIterator::into_iter([1, 2, 3])`. +Those will start to work in *all* editions. + +While it's a shame that this required a small hack to avoid breakage, +we're very happy with how this solution keeps the difference between +the editions to an absolute minimum. +Since the hack is only present in the older editions, +there is no added complexity in the new edition. + +[25]: https://github.com/rust-lang/rust/issues/25725 +[20]: https://github.com/rust-lang/rust/pull/65819 +[22]: https://doc.rust-lang.org/book/ch05-03-method-syntax.html#wheres-the---operator \ No newline at end of file diff --git a/src/rust-2021/default_cargo_resolver.md b/src/rust-2021/default_cargo_resolver.md new file mode 100644 index 00000000..a798b873 --- /dev/null +++ b/src/rust-2021/default_cargo_resolver.md @@ -0,0 +1,18 @@ +# Default Cargo feature resolver + +## Summary + +## Details + +Since Rust 1.51.0, Cargo has opt-in support for a [new feature resolver][4] +which can be activated with `resolver = "2"` in `Cargo.toml`. + +Starting in Rust 2021, this will be the default. +That is, writing `edition = "2021"` in `Cargo.toml` will imply `resolver = "2"`. + +The new feature resolver no longer merges all requested features for +crates that are depended on in multiple ways. +See [the announcement of Rust 1.51][5] for details. + +[4]: https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2 +[5]: https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver \ No newline at end of file diff --git a/src/rust-2021/disjoint_capture_in_closures.md b/src/rust-2021/disjoint_capture_in_closures.md new file mode 100644 index 00000000..b49c5045 --- /dev/null +++ b/src/rust-2021/disjoint_capture_in_closures.md @@ -0,0 +1,37 @@ +# Disjoint capture in closures + +## Summary + +## Details + +[Closures](https://doc.rust-lang.org/book/ch13-01-closures.html) +automatically capture anything that you refer to from within their body. +For example, `|| a + 1` automatically captures a reference to `a` from the surrounding context. + +Currently, this applies to whole structs, even when only using one field. +For example, `|| a.x + 1` captures a reference to `a` and not just `a.x`. +In some situations, this is a problem. +When a field of the struct is already borrowed (mutably) or moved out of, +the other fields can no longer be used in a closure, +since that would capture the whole struct, which is no longer available. + +```rust +let a = SomeStruct::new(); + +drop(a.x); // Move out of one field of the struct + +println!("{}", a.y); // Ok: Still use another field of the struct + +let c = || println!("{}", a.y); // Error: Tries to capture all of `a` +c(); +``` + +Starting in Rust 2021, closures will only capture the fields that they use. +So, the above example will compile fine in Rust 2021. + +This new behavior is only activated in the new edition, +since it can change the order in which fields are dropped. +As for all edition changes, an automatic migration is available, +which will update your closures for which this matters. +It can insert `let _ = &a;` inside the closure to force the entire +struct to be captured as before. diff --git a/src/rust-2021/index.md b/src/rust-2021/index.md index 72a1ac65..6afb8fea 100644 --- a/src/rust-2021/index.md +++ b/src/rust-2021/index.md @@ -1 +1,16 @@ -# Rust 2021 +# Rust 2021 ⚠️ + +⚠️ The 2021 Edition has not yet been released and hence this section is still "under construction". + +The Rust 2021 Edition is currently slated for release in Rust 1.56.0. +Rust 1.56.0 will then be in beta for six weeks, +after which it is released as stable on October 21st. + +However, note that Rust is a project run by volunteers. +We prioritize the personal well-being of everyone working on Rust +over any deadlines and expectations we might have set. +This could mean delaying the edition a version if necessary, +or dropping a feature that turns out to be too difficult or stressful to finish in time. + +That said, we are on schedule and many of the difficult problems are already tackled, +thanks to all the people contributing to Rust 2021! 💛 diff --git a/src/rust-2021/or_patterns_macro_rules.md b/src/rust-2021/or_patterns_macro_rules.md new file mode 100644 index 00000000..451b0e5f --- /dev/null +++ b/src/rust-2021/or_patterns_macro_rules.md @@ -0,0 +1,28 @@ +# Or patterns in macro-rules + +## Summary + +## Details + +Starting in Rust 1.53.0, [patterns](https://doc.rust-lang.org/stable/reference/patterns.html) +are extended to support `|` nested anywhere in the pattern. +This enables you to write `Some(1 | 2)` instead of `Some(1) | Some(2)`. +Since this was simply not allowed before, this is not a breaking change. + +However, this change also affects [`macro_rules` macros](https://doc.rust-lang.org/stable/reference/macros-by-example.html). +Such macros can accept patterns using the `:pat` fragment specifier. +Currently, `:pat` does *not* match `|`, since before Rust 1.53, +not all patterns (at all nested levels) could contain a `|`. +Macros that accept patterns like `A | B`, +such as [`matches!()`](https://doc.rust-lang.org/1.51.0/std/macro.matches.html) +use something like `$($_:pat)|+`. +Because we don't want to break any existing macros, +we did *not* change the meaning of `:pat` in Rust 1.53.0 to include `|`. + +Instead, we will make that change as part of Rust 2021. +In the new edition, the `:pat` fragment specifier *will* match `A | B`. + +Since there are times that one still wishes to match a single pattern +variant without `|`, the fragment specified `:pat_param` has been added +to retain the older behavior. +The name refers to its main use case: a pattern in a closure parameter. diff --git a/src/rust-2021/panic_macro_consistency.md b/src/rust-2021/panic_macro_consistency.md new file mode 100644 index 00000000..f2f87ebf --- /dev/null +++ b/src/rust-2021/panic_macro_consistency.md @@ -0,0 +1,44 @@ +# Panic macro consistency + +## Summary + +## Details + + +The `panic!()` macro is one of Rust's most well known macros. +However, it has [some subtle surprises](https://github.com/rust-lang/rfcs/blob/master/text/3007-panic-plan.md) +that we can't just change due to backwards compatibility. + +```rust +panic!("{}", 1); // Ok, panics with the message "1" +panic!("{}"); // Ok, panics with the message "{}" +``` + +The `panic!()` macro only uses string formatting when it's invoked with more than one argument. +When invoked with a single argument, it doesn't even look at that argument. + +```rust +let a = "{"; +println!(a); // Error: First argument must be a format string literal +panic!(a); // Ok: The panic macro doesn't care +``` + +(It even accepts non-strings such as `panic!(123)`, which is uncommon and rarely useful.) + +This will especially be a problem once +[implicit format arguments](https://rust-lang.github.io/rfcs/2795-format-args-implicit-identifiers.html) +are stabilized. +That feature will make `println!("hello {name}")` a short-hand for `println!("hello {}", name)`. +However, `panic!("hello {name}")` would not work as expected, +since `panic!()` doesn't process a single argument as format string. + +To avoid that confusing situation, Rust 2021 features a more consistent `panic!()` macro. +The new `panic!()` macro will no longer accept arbitrary expressions as the only argument. +It will, just like `println!()`, always process the first argument as format string. +Since `panic!()` will no longer accept arbitrary payloads, +[`panic_any()`](https://doc.rust-lang.org/stable/std/panic/fn.panic_any.html) +will be the only way to panic with something other than a formatted string. + +In addition, `core::panic!()` and `std::panic!()` will be identical in Rust 2021. +Currently, there are some historical differences between those two, +which can be noticable when switching `#![no_std]` on or off. \ No newline at end of file diff --git a/src/rust-2021/prelude.md b/src/rust-2021/prelude.md new file mode 100644 index 00000000..2d182066 --- /dev/null +++ b/src/rust-2021/prelude.md @@ -0,0 +1,32 @@ +# Additions to the prelude + +## Summary + +## Details + +The [prelude of the standard library](https://doc.rust-lang.org/stable/std/prelude/index.html) +is the module containing everything that is automatically imported in every module. +It contains commonly used items such as `Option`, `Vec`, `drop`, and `Clone`. + +The Rust compiler prioritizes any manually imported items over those +from the prelude, to make sure additions to the prelude will not break any existing code. +For example, if you have a crate or module called `example` containing a `pub struct Option;`, +then `use example::*;` will make `Option` unambiguously refer to the one from `example`; +not the one from the standard library. + +However, adding a *trait* to the prelude can break existing code in a subtle way. +A call to `x.try_into()` using a `MyTryInto` trait might become ambiguous and +fail to compile if `std`'s `TryInto` is also imported, +since it provides a method with the same name. +This is the reason we haven't added `TryInto` to the prelude yet, +since there is a lot of code that would break this way. + +As a solution, Rust 2021 will use a new prelude. +It's identical to the current one, except for three new additions: + +- [`std::convert::TryInto`](https://doc.rust-lang.org/stable/std/convert/trait.TryInto.html) +- [`std::convert::TryFrom`](https://doc.rust-lang.org/stable/std/convert/trait.TryFrom.html) +- [`std::iter::FromIterator`](https://doc.rust-lang.org/stable/std/iter/trait.FromIterator.html) + +The library team still needs to formally approve these, which will likely happen soon. + diff --git a/src/rust-2021/reserving_syntax.md b/src/rust-2021/reserving_syntax.md new file mode 100644 index 00000000..315954be --- /dev/null +++ b/src/rust-2021/reserving_syntax.md @@ -0,0 +1,40 @@ +# Reserving syntax + +## Summary + +## Details + +To make space for some new syntax in the future, +we've decided to reserve syntax for prefixed identifiers and literals: +`prefix#identifier`, `prefix"string"`, `prefix'c'`, and `prefix#123`, +where `prefix` can be any identifier. +(Except those that already have a meaning, such as `b'…'` and `r"…"`.) + +This is a breaking change, since macros can currently accept `hello"world"`, +which they will see as two separate tokens: `hello` and `"world"`. +The (automatic) fix is simple though. Just insert a space: `hello "world"`. + + + +Other than turning these into a tokenization error, +[the RFC][10] does not attach a meaning to any prefix yet. +Assigning meaning to specific prefixes is left to future proposals, +which will—thanks to reserving these prefixes now—not be breaking changes. + +These are some new prefixes you might see in the future: + +- `f""` as a short-hand for a format string. + For example, `f"hello {name}"` as a short-hand for the equivalent `format_args!()` invocation. + +- `c""` or `z""` for null-terminated C strings. + +- `k#keyword` to allow writing keywords that don't exist yet in the current edition. + For example, while `async` is not a keyword in edition 2015, + this prefix would've allowed us to accept `k#async` in edition 2015 + without having to wait for edition 2018 to reserve `async` as a keyword. + +[10]: https://github.com/rust-lang/rfcs/pull/3101 \ No newline at end of file diff --git a/src/rust-2021/warnings_promoted_to_error.md b/src/rust-2021/warnings_promoted_to_error.md new file mode 100644 index 00000000..5c20246d --- /dev/null +++ b/src/rust-2021/warnings_promoted_to_error.md @@ -0,0 +1,17 @@ +# Warnings promoted to errors + +## Summary + +## Details + +Two existing lints are becoming hard errors in Rust 2021. +These lints will remain warnings in older editions. + +* `bare-trait-objects`: + The use of the `dyn` keyword to identify [trait objects](https://doc.rust-lang.org/book/ch17-02-trait-objects.html) + will be mandatory in Rust 2021. + +* `ellipsis-inclusive-range-patterns`: + The [deprecated `...` syntax](https://doc.rust-lang.org/stable/reference/patterns.html#range-patterns) + for inclusive range patterns is no longer accepted in Rust 2021. + It has been superseded by `..=`, which is consistent with expressions. \ No newline at end of file From 3c9ceeae06394181f48ec4d441b3f7a4f8102f1c Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 3 May 2021 14:22:56 -0400 Subject: [PATCH 04/13] simplify the introduction --- src/introduction.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/introduction.md b/src/introduction.md index 7479cce7..c23508b2 100644 --- a/src/introduction.md +++ b/src/introduction.md @@ -1,16 +1,11 @@ # Introduction -Welcome to the Rust Edition Guide! "Editions" are Rust's way of communicating -large changes in the way that it feels to write Rust code. +Welcome to the Rust Edition Guide! "Editions" are Rust's way of introducing +changes into the language that would not otherwise be backwards +compatible. In this guide, we'll discuss: * What editions are -* What each edition is about +* Which changes are contained in each edition * How to migrate your code from one edition to another - -Note that the standard library grows with each Rust release; there are *many* -additions to the standard library that are not called out in this guide. Only -the major ones are, but there's tons of medium and small things that are -great too. You may want to check out [the standard library -documentation](https://doc.rust-lang.org/std/) as well. \ No newline at end of file From 4a7fc7ee4ca3d18a354c7525f44015a4dc21c3f3 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 3 May 2021 14:23:45 -0400 Subject: [PATCH 05/13] remove content that does not cover migrations or changes in the edition --- src/SUMMARY.md | 93 ----- ...go-can-use-a-local-registry-replacement.md | 38 -- .../cargo-check-for-faster-checking.md | 54 --- ...-install-for-easy-installation-of-tools.md | 32 -- .../cargo-new-defaults-to-a-binary-project.md | 18 - ...tc-for-passing-arbitrary-flags-to-rustc.md | 21 -- ...o-workspaces-for-multi-package-projects.md | 30 -- ...ates-io-disallows-wildcard-dependencies.md | 25 -- .../cargo-and-crates-io/index.md | 7 - .../multi-file-examples.md | 22 -- .../replacing-dependencies-with-patch.md | 35 -- .../async-await-for-easier-concurrency.md | 7 - src/rust-2018-outdated/control-flow/index.md | 6 - .../loops-can-break-with-a-value.md | 26 -- .../data-types/128-bit-integers.md | 17 - ...osing-alignment-with-the-repr-attribute.md | 55 --- .../data-types/field-init-shorthand.md | 49 --- .../data-types/inclusive-ranges.md | 72 ---- src/rust-2018-outdated/data-types/index.md | 6 - .../operator-equals-are-now-implementable.md | 33 -- .../union-for-an-unsafe-form-of-enum.md | 60 --- src/rust-2018-outdated/documentation/index.md | 6 - .../documentation/new-editions-of-the-book.md | 31 -- ...-os-has-documentation-for-all-platforms.md | 11 - .../documentation/the-rust-bookshelf.md | 33 -- .../documentation/the-rustonomicon.md | 10 - src/rust-2018-outdated/edition-changes.md | 36 -- .../aborting-on-panic.md | 18 - .../controlling-panics-with-std-panic.md | 80 ---- .../error-handling-and-panics/index.md | 6 - .../question-mark-in-main-and-tests.md | 131 ------- ...mark-operator-for-easier-error-handling.md | 120 ------ src/rust-2018-outdated/index.md | 8 - src/rust-2018-outdated/macros/at-most-once.md | 42 --- .../macros/custom-derive.md | 49 --- src/rust-2018-outdated/macros/index.md | 6 - .../macros/macro-changes.md | 271 -------------- src/rust-2018-outdated/module-system/index.md | 6 - .../more-visibility-modifiers.md | 16 - .../module-system/nested-imports-with-use.md | 35 -- .../module-system/path-clarity.md | 351 ------------------ .../module-system/raw-identifiers.md | 68 ---- .../default-match-bindings.md | 61 --- .../ownership-and-lifetimes/index.md | 6 - .../inference-in-structs.md | 72 ---- .../lifetime-elision-in-impl.md | 75 ---- .../non-lexical-lifetimes.md | 85 ----- .../simpler-lifetimes-in-static-and-const.md | 41 -- .../the-anonymous-lifetime.md | 96 ----- .../cdylib-crates-for-c-interoperability.md | 18 - .../global-allocators.md | 35 -- .../platform-and-target-support/index.md | 6 - .../libcore-for-low-level-rust.md | 31 -- .../msvc-toolchain-support.md | 18 - .../musl-support-for-fully-static-binaries.md | 45 --- .../webassembly-support.md | 28 -- ...ocumentation-tests-can-now-compile-fail.md | 19 - src/rust-2018-outdated/rustdoc/index.md | 6 - .../rustdoc/rustdoc-uses-commonmark.md | 16 - .../rustup-for-managing-rust-versions.md | 224 ----------- .../simd-for-faster-computing.md | 108 ------ src/rust-2018-outdated/slice-patterns.md | 91 ----- .../an-attribute-for-deprecation.md | 35 -- .../the-compiler/improved-error-messages.md | 50 --- ...emental-compilation-for-faster-compiles.md | 23 -- src/rust-2018-outdated/the-compiler/index.md | 6 - .../trait-system/associated-constants.md | 117 ------ .../dyn-trait-for-trait-objects.md | 42 --- ...t-for-returning-complex-types-with-ease.md | 168 --------- src/rust-2018-outdated/trait-system/index.md | 6 - ...e-container-types-support-trait-objects.md | 29 -- .../trait-system/no-anon-params.md | 23 -- src/rust-next/alloc.md | 28 -- src/rust-next/alternative-cargo-registries.md | 26 -- src/rust-next/cargo-vendor.md | 9 - src/rust-next/const-fn.md | 241 ------------ src/rust-next/dbg-macro.md | 104 ------ src/rust-next/edition-changes.md | 3 - src/rust-next/future.md | 10 - src/rust-next/index.md | 7 - src/rust-next/literal-macro-matcher.md | 18 - src/rust-next/maybe-uninit.md | 28 -- src/rust-next/no-jemalloc.md | 43 --- src/rust-next/no-more-fnbox.md | 38 -- src/rust-next/pin.md | 21 -- .../qustion-mark-operator-in-macros.md | 14 - src/rust-next/tryfrom-and-tryinto.md | 23 -- src/rust-next/uniform-paths.md | 23 -- 88 files changed, 4256 deletions(-) delete mode 100644 src/rust-2018-outdated/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.md delete mode 100644 src/rust-2018-outdated/cargo-and-crates-io/cargo-check-for-faster-checking.md delete mode 100644 src/rust-2018-outdated/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.md delete mode 100644 src/rust-2018-outdated/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.md delete mode 100644 src/rust-2018-outdated/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.md delete mode 100644 src/rust-2018-outdated/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.md delete mode 100644 src/rust-2018-outdated/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.md delete mode 100644 src/rust-2018-outdated/cargo-and-crates-io/index.md delete mode 100644 src/rust-2018-outdated/cargo-and-crates-io/multi-file-examples.md delete mode 100644 src/rust-2018-outdated/cargo-and-crates-io/replacing-dependencies-with-patch.md delete mode 100644 src/rust-2018-outdated/control-flow/async-await-for-easier-concurrency.md delete mode 100644 src/rust-2018-outdated/control-flow/index.md delete mode 100644 src/rust-2018-outdated/control-flow/loops-can-break-with-a-value.md delete mode 100644 src/rust-2018-outdated/data-types/128-bit-integers.md delete mode 100644 src/rust-2018-outdated/data-types/choosing-alignment-with-the-repr-attribute.md delete mode 100644 src/rust-2018-outdated/data-types/field-init-shorthand.md delete mode 100644 src/rust-2018-outdated/data-types/inclusive-ranges.md delete mode 100644 src/rust-2018-outdated/data-types/index.md delete mode 100644 src/rust-2018-outdated/data-types/operator-equals-are-now-implementable.md delete mode 100644 src/rust-2018-outdated/data-types/union-for-an-unsafe-form-of-enum.md delete mode 100644 src/rust-2018-outdated/documentation/index.md delete mode 100644 src/rust-2018-outdated/documentation/new-editions-of-the-book.md delete mode 100644 src/rust-2018-outdated/documentation/std-os-has-documentation-for-all-platforms.md delete mode 100644 src/rust-2018-outdated/documentation/the-rust-bookshelf.md delete mode 100644 src/rust-2018-outdated/documentation/the-rustonomicon.md delete mode 100644 src/rust-2018-outdated/edition-changes.md delete mode 100644 src/rust-2018-outdated/error-handling-and-panics/aborting-on-panic.md delete mode 100644 src/rust-2018-outdated/error-handling-and-panics/controlling-panics-with-std-panic.md delete mode 100644 src/rust-2018-outdated/error-handling-and-panics/index.md delete mode 100644 src/rust-2018-outdated/error-handling-and-panics/question-mark-in-main-and-tests.md delete mode 100644 src/rust-2018-outdated/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.md delete mode 100644 src/rust-2018-outdated/index.md delete mode 100644 src/rust-2018-outdated/macros/at-most-once.md delete mode 100644 src/rust-2018-outdated/macros/custom-derive.md delete mode 100644 src/rust-2018-outdated/macros/index.md delete mode 100644 src/rust-2018-outdated/macros/macro-changes.md delete mode 100644 src/rust-2018-outdated/module-system/index.md delete mode 100644 src/rust-2018-outdated/module-system/more-visibility-modifiers.md delete mode 100644 src/rust-2018-outdated/module-system/nested-imports-with-use.md delete mode 100644 src/rust-2018-outdated/module-system/path-clarity.md delete mode 100644 src/rust-2018-outdated/module-system/raw-identifiers.md delete mode 100644 src/rust-2018-outdated/ownership-and-lifetimes/default-match-bindings.md delete mode 100644 src/rust-2018-outdated/ownership-and-lifetimes/index.md delete mode 100644 src/rust-2018-outdated/ownership-and-lifetimes/inference-in-structs.md delete mode 100644 src/rust-2018-outdated/ownership-and-lifetimes/lifetime-elision-in-impl.md delete mode 100644 src/rust-2018-outdated/ownership-and-lifetimes/non-lexical-lifetimes.md delete mode 100644 src/rust-2018-outdated/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.md delete mode 100644 src/rust-2018-outdated/ownership-and-lifetimes/the-anonymous-lifetime.md delete mode 100644 src/rust-2018-outdated/platform-and-target-support/cdylib-crates-for-c-interoperability.md delete mode 100644 src/rust-2018-outdated/platform-and-target-support/global-allocators.md delete mode 100644 src/rust-2018-outdated/platform-and-target-support/index.md delete mode 100644 src/rust-2018-outdated/platform-and-target-support/libcore-for-low-level-rust.md delete mode 100644 src/rust-2018-outdated/platform-and-target-support/msvc-toolchain-support.md delete mode 100644 src/rust-2018-outdated/platform-and-target-support/musl-support-for-fully-static-binaries.md delete mode 100644 src/rust-2018-outdated/platform-and-target-support/webassembly-support.md delete mode 100644 src/rust-2018-outdated/rustdoc/documentation-tests-can-now-compile-fail.md delete mode 100644 src/rust-2018-outdated/rustdoc/index.md delete mode 100644 src/rust-2018-outdated/rustdoc/rustdoc-uses-commonmark.md delete mode 100644 src/rust-2018-outdated/rustup-for-managing-rust-versions.md delete mode 100644 src/rust-2018-outdated/simd-for-faster-computing.md delete mode 100644 src/rust-2018-outdated/slice-patterns.md delete mode 100644 src/rust-2018-outdated/the-compiler/an-attribute-for-deprecation.md delete mode 100644 src/rust-2018-outdated/the-compiler/improved-error-messages.md delete mode 100644 src/rust-2018-outdated/the-compiler/incremental-compilation-for-faster-compiles.md delete mode 100644 src/rust-2018-outdated/the-compiler/index.md delete mode 100644 src/rust-2018-outdated/trait-system/associated-constants.md delete mode 100644 src/rust-2018-outdated/trait-system/dyn-trait-for-trait-objects.md delete mode 100644 src/rust-2018-outdated/trait-system/impl-trait-for-returning-complex-types-with-ease.md delete mode 100644 src/rust-2018-outdated/trait-system/index.md delete mode 100644 src/rust-2018-outdated/trait-system/more-container-types-support-trait-objects.md delete mode 100644 src/rust-2018-outdated/trait-system/no-anon-params.md delete mode 100644 src/rust-next/alloc.md delete mode 100644 src/rust-next/alternative-cargo-registries.md delete mode 100644 src/rust-next/cargo-vendor.md delete mode 100644 src/rust-next/const-fn.md delete mode 100644 src/rust-next/dbg-macro.md delete mode 100644 src/rust-next/edition-changes.md delete mode 100644 src/rust-next/future.md delete mode 100644 src/rust-next/index.md delete mode 100644 src/rust-next/literal-macro-matcher.md delete mode 100644 src/rust-next/maybe-uninit.md delete mode 100644 src/rust-next/no-jemalloc.md delete mode 100644 src/rust-next/no-more-fnbox.md delete mode 100644 src/rust-next/pin.md delete mode 100644 src/rust-next/qustion-mark-operator-in-macros.md delete mode 100644 src/rust-next/tryfrom-and-tryinto.md delete mode 100644 src/rust-next/uniform-paths.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 11be43b1..3fd60ef9 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -32,96 +32,3 @@ - [Reserving syntax](rust-2021/reserving_syntax.md) - [Warnings promoted to errors](rust-2021/warnings_promoted_to_error.md) - [Or patterns in macro-rules](rust-2021/or_patterns_macro_rules.md) - -## Rust 2018 (outdated) - -- [Rust 2018 (outdated)](rust-2018-outdated/index.md) - - [2018-Specific Changes](rust-2018-outdated/edition-changes.md) - - [Module system](rust-2018-outdated/module-system/index.md) - - [Raw identifiers](rust-2018-outdated/module-system/raw-identifiers.md) - - [Path clarity](rust-2018-outdated/module-system/path-clarity.md) - - [More visibility modifiers](rust-2018-outdated/module-system/more-visibility-modifiers.md) - - [Nested imports with `use`](rust-2018-outdated/module-system/nested-imports-with-use.md) - - [Error handling and panics](rust-2018-outdated/error-handling-and-panics/index.md) - - [The `?` operator for easier error handling](rust-2018-outdated/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.md) - - [`?` in `main` and tests](rust-2018-outdated/error-handling-and-panics/question-mark-in-main-and-tests.md) - - [Controlling panics with `std::panic`](rust-2018-outdated/error-handling-and-panics/controlling-panics-with-std-panic.md) - - [Aborting on panic](rust-2018-outdated/error-handling-and-panics/aborting-on-panic.md) - - [Control flow](rust-2018-outdated/control-flow/index.md) - - [Loops can `break` with a value](rust-2018-outdated/control-flow/loops-can-break-with-a-value.md) - - [`async`/`await` for easier concurrency](rust-2018-outdated/control-flow/async-await-for-easier-concurrency.md) - - [Trait system](rust-2018-outdated/trait-system/index.md) - - [`impl Trait` for returning complex types with ease](rust-2018-outdated/trait-system/impl-trait-for-returning-complex-types-with-ease.md) - - [`dyn Trait` for trait objects](rust-2018-outdated/trait-system/dyn-trait-for-trait-objects.md) - - [More container types support trait objects](rust-2018-outdated/trait-system/more-container-types-support-trait-objects.md) - - [Associated constants](rust-2018-outdated/trait-system/associated-constants.md) - - [No more anonymous parameters](rust-2018-outdated/trait-system/no-anon-params.md) - - [Slice patterns](rust-2018-outdated/slice-patterns.md) - - [Ownership and lifetimes](rust-2018-outdated/ownership-and-lifetimes/index.md) - - [Non-lexical lifetimes](rust-2018-outdated/ownership-and-lifetimes/non-lexical-lifetimes.md) - - [Default `match` bindings](rust-2018-outdated/ownership-and-lifetimes/default-match-bindings.md) - - [`'_`, the anonymous lifetime](rust-2018-outdated/ownership-and-lifetimes/the-anonymous-lifetime.md) - - [Lifetime elision in `impl`](rust-2018-outdated/ownership-and-lifetimes/lifetime-elision-in-impl.md) - - [`T: 'a` inference in structs](rust-2018-outdated/ownership-and-lifetimes/inference-in-structs.md) - - [Simpler lifetimes in `static` and `const`](rust-2018-outdated/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.md) - - [Data types](rust-2018-outdated/data-types/index.md) - - [Field init shorthand](rust-2018-outdated/data-types/field-init-shorthand.md) - - [`..=` for inclusive ranges](rust-2018-outdated/data-types/inclusive-ranges.md) - - [128 bit integers](rust-2018-outdated/data-types/128-bit-integers.md) - - ["Operator-equals" are now implementable](rust-2018-outdated/data-types/operator-equals-are-now-implementable.md) - - [`union` for an unsafe form of `enum`](rust-2018-outdated/data-types/union-for-an-unsafe-form-of-enum.md) - - [Choosing alignment with the `repr` attribute](rust-2018-outdated/data-types/choosing-alignment-with-the-repr-attribute.md) - - [SIMD for faster computing](rust-2018-outdated/simd-for-faster-computing.md) - - [Macros](rust-2018-outdated/macros/index.md) - - [Custom Derive](rust-2018-outdated/macros/custom-derive.md) - - [Macro changes](rust-2018-outdated/macros/macro-changes.md) - - [At most one repetition](rust-2018-outdated/macros/at-most-once.md) - - [The compiler](rust-2018-outdated/the-compiler/index.md) - - [Improved error messages](rust-2018-outdated/the-compiler/improved-error-messages.md) - - [Incremental Compilation for faster compiles](rust-2018-outdated/the-compiler/incremental-compilation-for-faster-compiles.md) - - [An attribute for deprecation](rust-2018-outdated/the-compiler/an-attribute-for-deprecation.md) - - [Rustup for managing Rust versions](rust-2018-outdated/rustup-for-managing-rust-versions.md) - - [Cargo and crates.io](rust-2018-outdated/cargo-and-crates-io/index.md) - - [`cargo check` for faster checking](rust-2018-outdated/cargo-and-crates-io/cargo-check-for-faster-checking.md) - - [`cargo install` for easy installation of tools](rust-2018-outdated/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.md) - - [`cargo new` defaults to a binary project](rust-2018-outdated/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.md) - - [`cargo rustc` for passing arbitrary flags to `rustc`](rust-2018-outdated/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.md) - - [Cargo workspaces for multi-package projects](rust-2018-outdated/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.md) - - [Multi-file `examples`](rust-2018-outdated/cargo-and-crates-io/multi-file-examples.md) - - [Replacing dependencies with `patch`](rust-2018-outdated/cargo-and-crates-io/replacing-dependencies-with-patch.md) - - [Cargo can use a local registry replacement](rust-2018-outdated/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.md) - - [Crates.io disallows wildcard dependencies](rust-2018-outdated/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.md) - - [Documentation](rust-2018-outdated/documentation/index.md) - - [New editions of the "the book"](rust-2018-outdated/documentation/new-editions-of-the-book.md) - - [The Rust Bookshelf](rust-2018-outdated/documentation/the-rust-bookshelf.md) - - [The Rustonomicon](rust-2018-outdated/documentation/the-rustonomicon.md) - - [Full documentation for `std::os`](rust-2018-outdated/documentation/std-os-has-documentation-for-all-platforms.md) - - [`rustdoc`](rust-2018-outdated/rustdoc/index.md) - - [Documentation tests can now `compile-fail`](rust-2018-outdated/rustdoc/documentation-tests-can-now-compile-fail.md) - - [Rustdoc uses CommonMark](rust-2018-outdated/rustdoc/rustdoc-uses-commonmark.md) - - [Platform and target support](rust-2018-outdated/platform-and-target-support/index.md) - - [`libcore` for low-level Rust](rust-2018-outdated/platform-and-target-support/libcore-for-low-level-rust.md) - - [WebAssembly support](rust-2018-outdated/platform-and-target-support/webassembly-support.md) - - [Global allocators](rust-2018-outdated/platform-and-target-support/global-allocators.md) - - [MSVC toolchain support](rust-2018-outdated/platform-and-target-support/msvc-toolchain-support.md) - - [MUSL support for fully static binaries](rust-2018-outdated/platform-and-target-support/musl-support-for-fully-static-binaries.md) - - [`cdylib` crates for C interoperability](rust-2018-outdated/platform-and-target-support/cdylib-crates-for-c-interoperability.md) - -## The Next Edition - -- [The Next Edition](rust-next/index.md) - - [Next-Specific Changes](rust-next/edition-changes.md) - - [The dbg! macro](rust-next/dbg-macro.md) - - [No jemalloc by default](rust-next/no-jemalloc.md) - - [Uniform Paths](rust-next/uniform-paths.md) - - [`literal` macro matcher](rust-next/literal-macro-matcher.md) - - [`?` operator in macros](rust-next/qustion-mark-operator-in-macros.md) - - [const fn](rust-next/const-fn.md) - - [Pinning](rust-next/pin.md) - - [No more FnBox](rust-next/no-more-fnbox.md) - - [Alternative Cargo Registries](rust-next/alternative-cargo-registries.md) - - [TryFrom and TryInto](rust-next/tryfrom-and-tryinto.md) - - [The Future trait](rust-next/future.md) - - [The alloc crate](rust-next/alloc.md) - - [MaybeUninit](rust-next/maybe-uninit.md) - - [cargo vendor](rust-next/cargo-vendor.md) diff --git a/src/rust-2018-outdated/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.md b/src/rust-2018-outdated/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.md deleted file mode 100644 index bd49bece..00000000 --- a/src/rust-2018-outdated/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.md +++ /dev/null @@ -1,38 +0,0 @@ -# Cargo can use a local registry replacement - -![Minimum Rust version: 1.12](https://img.shields.io/badge/Minimum%20Rust%20Version-1.12-brightgreen.svg) - -Cargo finds its packages in a "source". The default source is [crates.io](https://crates.io). However, you -can choose a different source in your `.cargo/config`: - -```toml -[source.crates-io] -replace-with = 'my-awesome-registry' - -[source.my-awesome-registry] -registry = 'https://github.com/my-awesome/registry-index' -``` - -This configuration means that instead of using crates.io, Cargo will query -the `my-awesome-registry` source instead (configured to a different index -here). This alternate source *must be the exact same* as the crates.io index. -Cargo assumes that replacement sources are exact 1:1 mirrors in this respect, -and the following support is designed around that assumption. - -When generating a lock file for crate using a replacement registry, the -original registry will be encoded into the lock file. For example in the -configuration above, all lock files will still mention crates.io as the -registry that packages originated from. This semantically represents how -crates.io is the source of truth for all crates, and this is upheld because -all replacements have a 1:1 correspondance. - -Overall, this means that no matter what replacement source you're working -with, you can ship your lock file to anyone else and you'll all still have -verifiably reproducible builds! - -This has enabled tools like -[`cargo-vendor`](https://github.com/alexcrichton/cargo-vendor) and -[`cargo-local-registry`](https://github.com/alexcrichton/cargo-local-registry), -which are often useful for "offline builds." They prepare the list of all -Rust dependencies ahead of time, which lets you ship them to a build machine -with ease. \ No newline at end of file diff --git a/src/rust-2018-outdated/cargo-and-crates-io/cargo-check-for-faster-checking.md b/src/rust-2018-outdated/cargo-and-crates-io/cargo-check-for-faster-checking.md deleted file mode 100644 index e3883f3b..00000000 --- a/src/rust-2018-outdated/cargo-and-crates-io/cargo-check-for-faster-checking.md +++ /dev/null @@ -1,54 +0,0 @@ -# `cargo check` for faster checking - -![Minimum Rust version: 1.16](https://img.shields.io/badge/Minimum%20Rust%20Version-1.16-brightgreen.svg) - -`cargo check` is a new subcommand that should speed up the development -workflow in many cases. - -What does it do? Let's take a step back and talk about how `rustc` compiles -your code. Compilation has many "passes", that is, there are many distinct -steps that the compiler takes on the road from your source code to producing -the final binary. However, you can think of this process in two big steps: -first, `rustc` does all of its safety checks, makes sure your syntax is -correct, all that stuff. Second, once it's satisfied that everything is in -order, it produces the actual binary code that you end up executing. - -It turns out that that second step takes a lot of time. And most of the time, -it's not necessary. That is, when you're working on some Rust code, many -developers will get into a workflow like this: - -1. Write some code. -2. Run `cargo build` to make sure it compiles. -3. Repeat 1-2 as needed. -4. Run `cargo test` to make sure your tests pass. -5. Try the binary yourself -6. GOTO 1. - -In step two, you never actually run your code. You're looking for feedback -from the compiler, not to actually run the binary. `cargo check` supports -exactly this use-case: it runs all of the compiler's checks, but doesn't -produce the final binary. To use it: - -```console -$ cargo check -``` - -where you may normally `cargo build`. The workflow now looks like: - -1. Write some code. -2. Run `cargo check` to make sure it compiles. -3. Repeat 1-2 as needed. -4. Run `cargo test` to make sure your tests pass. -5. Run `cargo build` to build a binary and try it yourself -6. GOTO 1. - - -So how much speedup do you actually get? Like most performance related -questions, the answer is "it depends." Here are some very un-scientific -benchmarks at the time of writing. - -| use case | build performance | check performance | speedup | -|--------|-------------|-------------------|---------| -| initial compile | 11s | 5.6s | 1.96x | -| second compile (no changes) | 3s | 1.9s | 1.57x | -| third compile with small change | 5.8s | 3s | 1.93x | diff --git a/src/rust-2018-outdated/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.md b/src/rust-2018-outdated/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.md deleted file mode 100644 index cb901051..00000000 --- a/src/rust-2018-outdated/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.md +++ /dev/null @@ -1,32 +0,0 @@ -# `cargo install` for easy installation of tools - -![Minimum Rust version: 1.5](https://img.shields.io/badge/Minimum%20Rust%20Version-1.5-brightgreen.svg) - -Cargo has grown a new `install` command. This is intended to be used for installing -new subcommands for Cargo, or tools for Rust developers. This doesn't replace the need -to build real, native packages for end-users on the platforms you support. - -For example, this guide is created with [`mdbook`](https://crates.io/crates/mdbook). You -can install it on your system with - -```console -$ cargo install mdbook -``` - -And then use it with - -```console -$ mdbook --help -``` - -## Cargo Extensions - -As an example of extending Cargo, you can use the [`cargo-update`](https://crates.io/crates/cargo-update) -package. To install it: - -```console -$ cargo install cargo-update -``` - -This will allow you to use `cargo install-update -a` command, which checks everything you've `cargo install`'d and -updates it to the latest version. diff --git a/src/rust-2018-outdated/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.md b/src/rust-2018-outdated/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.md deleted file mode 100644 index 96198aba..00000000 --- a/src/rust-2018-outdated/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.md +++ /dev/null @@ -1,18 +0,0 @@ -# `cargo new` defaults to a binary project - -![Minimum Rust version: 1.25](https://img.shields.io/badge/Minimum%20Rust%20Version-1.25-brightgreen.svg) - -`cargo new` will now default to generating a binary, rather than a library. -We try to keep Cargo’s CLI quite stable, but this change is important, and is -unlikely to cause breakage. - -For some background, `cargo new` accepts two flags: `--lib`, for creating -libraries, and `--bin`, for creating binaries, or executables. If you don’t -pass one of these flags, it used to default to `--lib`. At the time, we made -this decision because each binary (often) depends on many libraries, and so -we thought the library case would be more common. However, this is incorrect; -each library is depended upon by many binaries. Furthermore, when getting -started, what you often want is a program you can run and play around with. -It’s not just new Rustaceans though; even very long-time community members -have said that they find this default surprising. As such, we’ve changed it, -and it now defaults to `--bin`. diff --git a/src/rust-2018-outdated/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.md b/src/rust-2018-outdated/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.md deleted file mode 100644 index cd419646..00000000 --- a/src/rust-2018-outdated/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.md +++ /dev/null @@ -1,21 +0,0 @@ -# `cargo rustc` for passing arbitrary flags to rustc - -![Minimum Rust version: 1.1](https://img.shields.io/badge/Minimum%20Rust%20Version-1.1-brightgreen.svg) - -`cargo rustc` is a new subcommand for Cargo that allows you to pass arbitrary -`rustc` flags through Cargo. - -For example, Cargo does not have a way to pass unstable flags built-in. But -if we'd like to use `print-type-sizes` to see what layout information our -types have, we can run this: - -```console -$ cargo rustc -- -Z print-type-sizes -``` - -And we'll get a bunch of output describing the size of our types. - -## Note - -`cargo rustc` only passes these flags to invocations of your crate, and not to any `rustc` -invocations used to build dependencies. If you'd like to do that, see `$RUSTFLAGS`. \ No newline at end of file diff --git a/src/rust-2018-outdated/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.md b/src/rust-2018-outdated/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.md deleted file mode 100644 index 9804ac9a..00000000 --- a/src/rust-2018-outdated/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.md +++ /dev/null @@ -1,30 +0,0 @@ -# Cargo workspaces for multi-package projects - -![Minimum Rust version: 1.12](https://img.shields.io/badge/Minimum%20Rust%20Version-1.12-brightgreen.svg) - -Cargo used to have two levels of organization: - -* A *package* contains one or more crates -* A crate has one or more modules - -Cargo now has an additional level: - -* A *workspace* contains one or more packages - -This can be useful for larger projects. For example, [the `futures` package] -is a *workspace* that contains many related packages: - -* futures -* futures-util -* futures-io -* futures-channel - -and more. - -[the `futures` package]: https://github.com/rust-lang/futures-rs - -Workspaces allow these packages to be developed individually, but they share -a single set of dependencies, and therefore have a single target directory -and a single `Cargo.lock`. - -For more details about workspaces, please see [the Cargo documentation](https://doc.rust-lang.org/stable/cargo/reference/manifest.html#the-workspace-section). diff --git a/src/rust-2018-outdated/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.md b/src/rust-2018-outdated/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.md deleted file mode 100644 index ac8cd5a9..00000000 --- a/src/rust-2018-outdated/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.md +++ /dev/null @@ -1,25 +0,0 @@ -# Crates.io disallows wildcard dependencies - -![Minimum Rust version: 1.6](https://img.shields.io/badge/Minimum%20Rust%20Version-1.6-brightgreen.svg) - -Crates.io will not allow you to upload a package with a wildcard dependency. -In other words, these: - -```toml -[dependencies] -regex = "*" -``` - -A wildcard dependency means that you work with any possible version of your -dependency. This is highly unlikely to be true, and would cause unnecessary -breakage in the ecosystem. - -Instead, depend on a version range. For example, `^` is the default, so -you could use - -```toml -[dependencies] -regex = "1.0.0" -``` - -instead. `>`, `<=`, and all of the other, non-`*` ranges work as well. \ No newline at end of file diff --git a/src/rust-2018-outdated/cargo-and-crates-io/index.md b/src/rust-2018-outdated/cargo-and-crates-io/index.md deleted file mode 100644 index 2608e338..00000000 --- a/src/rust-2018-outdated/cargo-and-crates-io/index.md +++ /dev/null @@ -1,7 +0,0 @@ -# Cargo and crates.io - -[check]: cargo-check-for-faster-checking.md -[cratesio]: https://crates.io - -In this chapter of the guide, we discuss a few improvements to `cargo` and [crates.io][cratesio]. -A notable addition here is the new [`cargo check`][check] command. diff --git a/src/rust-2018-outdated/cargo-and-crates-io/multi-file-examples.md b/src/rust-2018-outdated/cargo-and-crates-io/multi-file-examples.md deleted file mode 100644 index d73a5524..00000000 --- a/src/rust-2018-outdated/cargo-and-crates-io/multi-file-examples.md +++ /dev/null @@ -1,22 +0,0 @@ -# Multi-file examples - -![Minimum Rust version: 1.22](https://img.shields.io/badge/Minimum%20Rust%20Version-1.22-brightgreen.svg) - -Cargo has an `examples` feature for showing people how to use your package. -By putting individual files inside of the top-level `examples` directory, you -can create multiple examples. - -But what if your example is too big for a single file? Cargo supports adding -sub-directories inside of `examples`, and looks for a `main.rs` inside of -them to build the example. It looks like this: - -```text -my-package - └──src - └── lib.rs // code here - └──examples - └── simple-example.rs // a single-file example - └── complex-example - └── helper.rs - └── main.rs // a more complex example that also uses `helper` as a submodule -``` diff --git a/src/rust-2018-outdated/cargo-and-crates-io/replacing-dependencies-with-patch.md b/src/rust-2018-outdated/cargo-and-crates-io/replacing-dependencies-with-patch.md deleted file mode 100644 index a0ba636c..00000000 --- a/src/rust-2018-outdated/cargo-and-crates-io/replacing-dependencies-with-patch.md +++ /dev/null @@ -1,35 +0,0 @@ -# Replacing dependencies with patch - -![Minimum Rust version: 1.21](https://img.shields.io/badge/Minimum%20Rust%20Version-1.21-brightgreen.svg) - -The `[patch]` section of your `Cargo.toml` can be used when you want to -override certain parts of your dependency graph. - -> Cargo has a `[replace]` feature that is similar; while we don't intend to deprecate -> or remove `[replace]`, you should prefer `[patch]` in all circumstances. - -So what’s it look like? Let’s say we have a Cargo.toml that looks like this: - -```toml -[dependencies] -foo = "1.2.3" -``` - -In addition, our `foo` package depends on a `bar` crate, and we find a bug in `bar`. -To test this out, we’d download the source code for `bar`, and then update our -`Cargo.toml`: - -```toml -[dependencies] -foo = "1.2.3" - -[patch.crates-io] -bar = { path = '/path/to/bar' } -``` - -Now, when you `cargo build`, it will use the local version of `bar`, rather -than the one from crates.io that `foo` depends on. You can then try out your -changes, and fix that bug! - -For more details, see [the documentation for -`patch`](https://doc.rust-lang.org/cargo/reference/manifest.html#the-patch-section). \ No newline at end of file diff --git a/src/rust-2018-outdated/control-flow/async-await-for-easier-concurrency.md b/src/rust-2018-outdated/control-flow/async-await-for-easier-concurrency.md deleted file mode 100644 index 1ba53bdc..00000000 --- a/src/rust-2018-outdated/control-flow/async-await-for-easier-concurrency.md +++ /dev/null @@ -1,7 +0,0 @@ -# async/await for easier concurrency - -![Minimum Rust version: nightly](https://img.shields.io/badge/Minimum%20Rust%20Version-nightly-red.svg) - -The initial release of Rust 2018 won't ship with `async`/`await` support, but -we have reserved the keywords so that a future release will contain them. -We'll update this page when it's closer to shipping! \ No newline at end of file diff --git a/src/rust-2018-outdated/control-flow/index.md b/src/rust-2018-outdated/control-flow/index.md deleted file mode 100644 index 0d338b13..00000000 --- a/src/rust-2018-outdated/control-flow/index.md +++ /dev/null @@ -1,6 +0,0 @@ -# Control flow - -[async_await]: async-await-for-easier-concurrency.md - -In this chapter of the guide, we discuss a few improvements to control flow. -The most notable of these *will* be [`async` and `await`][async_await]. \ No newline at end of file diff --git a/src/rust-2018-outdated/control-flow/loops-can-break-with-a-value.md b/src/rust-2018-outdated/control-flow/loops-can-break-with-a-value.md deleted file mode 100644 index c3099981..00000000 --- a/src/rust-2018-outdated/control-flow/loops-can-break-with-a-value.md +++ /dev/null @@ -1,26 +0,0 @@ -# `loop`s can break with a value - -![Minimum Rust version: 1.19](https://img.shields.io/badge/Minimum%20Rust%20Version-1.19-brightgreen.svg) - -`loop`s can now break with a value: - -```rust -// old code -let x; - -loop { - x = 7; - break; -} - -// new code -let x = loop { break 7; }; -``` - -Rust has traditionally positioned itself as an “expression oriented -language”, that is, most things are expressions that evaluate to a value, -rather than statements. `loop` stuck out as strange in this way, as it was -previously a statement. - -For now, this only applies to `loop`, and not things like `while` or `for`. -See the rationale for this decision in RFC issue [#1767](https://github.com/rust-lang/rfcs/issues/1767). diff --git a/src/rust-2018-outdated/data-types/128-bit-integers.md b/src/rust-2018-outdated/data-types/128-bit-integers.md deleted file mode 100644 index 68f06162..00000000 --- a/src/rust-2018-outdated/data-types/128-bit-integers.md +++ /dev/null @@ -1,17 +0,0 @@ -# 128 bit integers - -![Minimum Rust version: 1.26](https://img.shields.io/badge/Minimum%20Rust%20Version-1.26-brightgreen.svg) - -A very simple feature: Rust now has 128 bit integers! - -```rust -let x: i128 = 0; -let y: u128 = 0; -``` - -These are twice the size of `u64`, and so can hold more values. More specifically, - -* `u128`: `0` - `340,282,366,920,938,463,463,374,607,431,768,211,455` -* `i128`: `−170,141,183,460,469,231,731,687,303,715,884,105,728` - `170,141,183,460,469,231,731,687,303,715,884,105,727` - -Whew! \ No newline at end of file diff --git a/src/rust-2018-outdated/data-types/choosing-alignment-with-the-repr-attribute.md b/src/rust-2018-outdated/data-types/choosing-alignment-with-the-repr-attribute.md deleted file mode 100644 index b2624de6..00000000 --- a/src/rust-2018-outdated/data-types/choosing-alignment-with-the-repr-attribute.md +++ /dev/null @@ -1,55 +0,0 @@ -# Choosing alignment with the repr attribute - -![Minimum Rust version: 1.25](https://img.shields.io/badge/Minimum%20Rust%20Version-1.25-brightgreen.svg) - -From [Wikipedia](https://en.wikipedia.org/wiki/Data_structure_alignment): - -> The CPU in modern computer hardware performs reads and writes to memory -> most efficiently when the data is naturally aligned, which generally means -> that the data address is a multiple of the data size. Data alignment refers -> to aligning elements according to their natural alignment. To ensure natural -> alignment, it may be necessary to insert some padding between structure -> elements or after the last element of a structure. - -The `#[repr]` attribute has a new parameter, `align`, that sets the alignment of your struct: - -```rust -struct Number(i32); - -assert_eq!(std::mem::align_of::(), 4); -assert_eq!(std::mem::size_of::(), 4); - -#[repr(align(16))] -struct Align16(i32); - -assert_eq!(std::mem::align_of::(), 16); -assert_eq!(std::mem::size_of::(), 16); -``` - -If you’re working with low-level stuff, control of these kinds of things can -be very important! - -The alignment of a type is normally not worried about as the compiler will -"do the right thing" of picking an appropriate alignment for general use -cases. There are situations, however, where a nonstandard alignment may be -desired when operating with foreign systems. For example these sorts of -situations tend to necessitate or be much easier with a custom alignment: - -* Hardware can often have obscure requirements such as "this structure is - aligned to 32 bytes" when it in fact is only composed of 4-byte values. While - this can typically be manually calculated and managed, it's often also useful - to express this as a property of a type to get the compiler to do a little - extra work instead. -* C compilers like `gcc` and `clang` offer the ability to specify a custom - alignment for structures, and Rust can much more easily interoperate with - these types if Rust can also mirror the request for a custom alignment (e.g. - passing a structure to C correctly is much easier). -* Custom alignment can often be used for various tricks here and there and is - often convenient as "let's play around with an implementation" tool. For - example this can be used to statically allocate page tables in a kernel or - create an at-least cache-line-sized structure easily for concurrent - programming. - -The purpose of this feature is to provide a lightweight annotation to alter -the compiler-inferred alignment of a structure to enable these situations -much more easily. \ No newline at end of file diff --git a/src/rust-2018-outdated/data-types/field-init-shorthand.md b/src/rust-2018-outdated/data-types/field-init-shorthand.md deleted file mode 100644 index 85eb7157..00000000 --- a/src/rust-2018-outdated/data-types/field-init-shorthand.md +++ /dev/null @@ -1,49 +0,0 @@ -# Field init shorthand - -![Minimum Rust version: 1.17](https://img.shields.io/badge/Minimum%20Rust%20Version-1.17-brightgreen.svg) - -In older Rust, when initializing a struct, you must always give the full set of `key: value` pairs -for its fields: - -```rust -struct Point { - x: i32, - y: i32, -} - -let a = 5; -let b = 6; - -let p = Point { - x: a, - y: b, -}; -``` - -However, often these variables would have the same names as the fields. So you'd end up -with code that looks like this: - -```rust,ignore -let p = Point { - x: x, - y: y, -}; -``` - -Now, if the variable is of the same name, you don't have to write out both, just write out the key: - -```rust -struct Point { - x: i32, - y: i32, -} - -let x = 5; -let y = 6; - -// new -let p = Point { - x, - y, -}; -``` \ No newline at end of file diff --git a/src/rust-2018-outdated/data-types/inclusive-ranges.md b/src/rust-2018-outdated/data-types/inclusive-ranges.md deleted file mode 100644 index 740877d5..00000000 --- a/src/rust-2018-outdated/data-types/inclusive-ranges.md +++ /dev/null @@ -1,72 +0,0 @@ -# `..=` for inclusive ranges - -![Minimum Rust version: 1.26](https://img.shields.io/badge/Minimum%20Rust%20Version-1.26-brightgreen.svg) - -Since well before Rust 1.0, you’ve been able to create exclusive ranges with -`..` like this: - -```rust -for i in 1..3 { - println!("i: {}", i); -} -``` - -This will print `i: 1` and then `i: 2`. Today, you can now create an -inclusive range, like this: - -```rust -for i in 1..=3 { - println!("i: {}", i); -} -``` - -This will print `i: 1` and then `i: 2` like before, but also `i: 3`; the -three is included in the range. Inclusive ranges are especially useful if you -want to iterate over every possible value in a range. For example, this is a -surprising Rust program: - -```rust,compile_fail -fn takes_u8(x: u8) { - // ... -} - -fn main() { - for i in 0..256 { - println!("i: {}", i); - takes_u8(i); - } -} -``` - -What does this program do? The answer: it fails to compile. The error we get -when compiling has a hint: - -```text -error: literal out of range for u8 - --> src/main.rs:6:17 - | -6 | for i in 0..256 { - | ^^^ - | - = note: #[deny(overflowing_literals)] on by default -``` - -That’s right, since `i` is a `u8`, this overflows, and the compiler produces -an error. - -We can do this with inclusive ranges, however: - -```rust -fn takes_u8(x: u8) { - // ... -} - -fn main() { - for i in 0..=255 { - println!("i: {}", i); - takes_u8(i); - } -} -``` - -This will produce those 256 lines of output you might have been expecting. diff --git a/src/rust-2018-outdated/data-types/index.md b/src/rust-2018-outdated/data-types/index.md deleted file mode 100644 index 3da89d67..00000000 --- a/src/rust-2018-outdated/data-types/index.md +++ /dev/null @@ -1,6 +0,0 @@ -# Data types - -[fis]: field-init-shorthand.md - -In this chapter of the guide, we discuss a few improvements to data types. -One of these are [field-init-shorthand][fis]. \ No newline at end of file diff --git a/src/rust-2018-outdated/data-types/operator-equals-are-now-implementable.md b/src/rust-2018-outdated/data-types/operator-equals-are-now-implementable.md deleted file mode 100644 index 19390fa3..00000000 --- a/src/rust-2018-outdated/data-types/operator-equals-are-now-implementable.md +++ /dev/null @@ -1,33 +0,0 @@ -# "Operator-equals" are now implementable - -![Minimum Rust version: 1.8](https://img.shields.io/badge/Minimum%20Rust%20Version-1.8-brightgreen.svg) - -The various “operator equals” operators, such as `+=` and `-=`, are -implementable via various traits. For example, to implement `+=` on -a type of your own: - -```rust -use std::ops::AddAssign; - -#[derive(Debug)] -struct Count { - value: i32, -} - -impl AddAssign for Count { - fn add_assign(&mut self, other: Count) { - self.value += other.value; - } -} - -fn main() { - let mut c1 = Count { value: 1 }; - let c2 = Count { value: 5 }; - - c1 += c2; - - println!("{:?}", c1); -} -``` - -This will print `Count { value: 6 }`. \ No newline at end of file diff --git a/src/rust-2018-outdated/data-types/union-for-an-unsafe-form-of-enum.md b/src/rust-2018-outdated/data-types/union-for-an-unsafe-form-of-enum.md deleted file mode 100644 index a0bea758..00000000 --- a/src/rust-2018-outdated/data-types/union-for-an-unsafe-form-of-enum.md +++ /dev/null @@ -1,60 +0,0 @@ -# `union` for an unsafe form of `enum` - -![Minimum Rust version: 1.19](https://img.shields.io/badge/Minimum%20Rust%20Version-1.19-brightgreen.svg) - -Rust now supports `unions`: - -```rust -union MyUnion { - f1: u32, - f2: f32, -} -``` - -Unions are kind of like enums, but they are “untagged”. Enums have a “tag” -that stores which variant is the correct one at runtime; unions don't have -this tag. - -Since we can interpret the data held in the union using the wrong variant and -Rust can’t check this for us, that means reading a union’s field is unsafe: - -```rust -# union MyUnion { -# f1: u32, -# f2: f32, -# } -let mut u = MyUnion { f1: 1 }; - -u.f1 = 5; - -let value = unsafe { u.f1 }; -``` - -Pattern matching works too: - -```rust -# union MyUnion { -# f1: u32, -# f2: f32, -# } -fn f(u: MyUnion) { - unsafe { - match u { - MyUnion { f1: 10 } => { println!("ten"); } - MyUnion { f2 } => { println!("{}", f2); } - } - } -} -``` - -When are unions useful? One major use-case is interoperability with C. C APIs -can (and depending on the area, often do) expose unions, and so this makes -writing API wrappers for those libraries significantly easier. Additionally, -unions also simplify Rust implementations of space-efficient or -cache-efficient structures relying on value representation, such as -machine-word-sized unions using the least-significant bits of aligned -pointers to distinguish cases. - -There’s still more improvements to come. For now, unions can only include -`Copy` types and may not implement `Drop`. We expect to lift these -restrictions in the future. diff --git a/src/rust-2018-outdated/documentation/index.md b/src/rust-2018-outdated/documentation/index.md deleted file mode 100644 index 4c566544..00000000 --- a/src/rust-2018-outdated/documentation/index.md +++ /dev/null @@ -1,6 +0,0 @@ -# Documentation - -[sec_ed]: new-editions-of-the-book.md - -In this chapter of the guide, we discuss a few improvements to documentation. -A notable addition here is the [second edition of "the book"][sec_ed]. \ No newline at end of file diff --git a/src/rust-2018-outdated/documentation/new-editions-of-the-book.md b/src/rust-2018-outdated/documentation/new-editions-of-the-book.md deleted file mode 100644 index ecee4bc8..00000000 --- a/src/rust-2018-outdated/documentation/new-editions-of-the-book.md +++ /dev/null @@ -1,31 +0,0 @@ -# New editions of the "the book" - -![Minimum Rust version: 1.26](https://img.shields.io/badge/Minimum%20Rust%20Version-1.26-brightgreen.svg) for the final version of the second edition - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) for the 2018 edition - -We've distributed a copy of "The Rust Programming Language," affectionately -nicknamed "the book", with every version of Rust since Rust 1.0. - -However, because it was written before Rust 1.0, it started showing its age. -Many parts of the book are vague, because it was written before the true -details were nailed down for the 1.0 release. It didn't do a fantastic job of -teaching lifetimes. - -Starting with Rust 1.18, we shipped drafts of a second edition of the book. -The final version was shipped with Rust 1.26. The second edition is a complete -re-write from the ground up, using the last two years of knowledge we’ve -gained from teaching people Rust. - -You can purchase [a printed version of the second edition from No Starch -Press](https://nostarch.com/Rust). Now that the print version has shipped, the -second edition is frozen. - -As of 1.31, the book has been completely updated for the 2018 Edition release. -It's still pretty close to the second edition, but contains information about -newer features since the book's content was frozen. Additionally, instead of -publishing separate editions of the book, only the latest version of the book -is published online. You’ll find brand-new explanations for a lot of Rust’s -core concepts, new projects to build, and all kinds of other good stuff. -Please [check it out](https://doc.rust-lang.org/book/index.html) and let us -know what you think! diff --git a/src/rust-2018-outdated/documentation/std-os-has-documentation-for-all-platforms.md b/src/rust-2018-outdated/documentation/std-os-has-documentation-for-all-platforms.md deleted file mode 100644 index 5be8f01b..00000000 --- a/src/rust-2018-outdated/documentation/std-os-has-documentation-for-all-platforms.md +++ /dev/null @@ -1,11 +0,0 @@ -# `std::os` has documentation for all platforms - -![Minimum Rust version: 1.21](https://img.shields.io/badge/Minimum%20Rust%20Version-1.21-brightgreen.svg) - -The `std::os` module contains operating system specific functionality. You’ll -now see more than just linux, the platform we build the documentation on. - -We’ve long regretted that the hosted version of the documentation has been -Linux-specific; this is a first step towards rectifying that. This is -specific to the standard library and not for general use; we hope to improve -this further in the future. \ No newline at end of file diff --git a/src/rust-2018-outdated/documentation/the-rust-bookshelf.md b/src/rust-2018-outdated/documentation/the-rust-bookshelf.md deleted file mode 100644 index e91627ac..00000000 --- a/src/rust-2018-outdated/documentation/the-rust-bookshelf.md +++ /dev/null @@ -1,33 +0,0 @@ -# The Rust Bookshelf - -![Minimum Rust version: various](https://img.shields.io/badge/Minimum%20Rust%20Version-various-brightgreen.svg), each book is different. - -As Rust's documentation has grown, we've gained far more than just "The book" -and the reference. We now have a collection of various long-form docs, -nicknamed "the Rust Bookshelf." Different resources are added at various -times, and we're adding new ones as more get written. - -## The Cargo book - -![Minimum Rust version: 1.21](https://img.shields.io/badge/Minimum%20Rust%20Version-1.21-brightgreen.svg) - -Historically, Cargo’s docs were hosted on , which -doesn’t follow the release train model, even though Cargo itself does. This -led to situations where a feature would land in Cargo nightly, the docs would -be updated, and then for up to twelve weeks, users would think that it should -work, but it wouldn’t yet. is the new home -of Cargo’s docs, and now redirects there. - -## The `rustdoc` book - -![Minimum Rust version: 1.21](https://img.shields.io/badge/Minimum%20Rust%20Version-1.21-brightgreen.svg) - -Rustdoc, our documentation tool, now has a guide at . - -## Rust By Example - -![Minimum Rust version: 1.25](https://img.shields.io/badge/Minimum%20Rust%20Version-1.25-brightgreen.svg) - -Rust by Example used to live at , but now is part of the Bookshelf! -It can be found at . RBE lets you learn Rust through -short code examples and exercises, as opposed to the lengthy prose of The Book. \ No newline at end of file diff --git a/src/rust-2018-outdated/documentation/the-rustonomicon.md b/src/rust-2018-outdated/documentation/the-rustonomicon.md deleted file mode 100644 index 514520c0..00000000 --- a/src/rust-2018-outdated/documentation/the-rustonomicon.md +++ /dev/null @@ -1,10 +0,0 @@ -# The Rustonomicon - -![Minimum Rust version: 1.3](https://img.shields.io/badge/Minimum%20Rust%20Version-1.3-brightgreen.svg) - -We now have a draft book, [The Rustonomicon: the Dark Arts of Advanced and -Unsafe Rust Programming](https://doc.rust-lang.org/stable/nomicon/). - -From the title, I'm sure you can guess: this book discusses some advanced -topics, including `unsafe`. It's a must-read for anyone who's working at the -lowest levels with Rust. \ No newline at end of file diff --git a/src/rust-2018-outdated/edition-changes.md b/src/rust-2018-outdated/edition-changes.md deleted file mode 100644 index 7c4d1762..00000000 --- a/src/rust-2018-outdated/edition-changes.md +++ /dev/null @@ -1,36 +0,0 @@ -# 2018-Specific Changes - -The following is a summary of changes that only apply to code compiled with -the 2018 edition compared to the 2015 edition. - -- [Path changes]: - - Paths in `use` declarations work the same as other paths. - - Paths starting with `::` must be followed with an external crate. - - Paths in `pub(in path)` visibility modifiers must start with `crate`, - `self`, or `super`. -- [Anonymous trait function parameters] are not allowed. - - [Trait function parameters] may use any irrefutable pattern when the - function has a body. -- Keyword changes: - - [`dyn`] is a [strict keyword][strict], in 2015 it is a [weak keyword]. - - `async` and `await` are [strict keywords][strict]. - - `try` is a [reserved keyword]. -- The following lints are now a hard error that you cannot silence: - - [tyvar_behind_raw_pointer] - -## Cargo -- If there is a target definition in a `Cargo.toml` manifest, it no longer - automatically disables automatic discovery of other targets. -- Target paths of the form `src/{target_name}.rs` are no longer inferred for - targets where the `path` field is not set. -- `cargo install` for the current directory is no longer allowed, you must - specify `cargo install --path .` to install the current package. - -[Anonymous trait function parameters]: trait-system/no-anon-params.md -[Path changes]: module-system/path-clarity.md -[Trait function parameters]: https://doc.rust-lang.org/stable/reference/items/traits.html#parameter-patterns -[`dyn`]: trait-system/dyn-trait-for-trait-objects.md -[reserved keyword]: https://doc.rust-lang.org/reference/keywords.html#reserved-keywords -[strict]: https://doc.rust-lang.org/reference/keywords.html#strict-keywords -[tyvar_behind_raw_pointer]: https://github.com/rust-lang/rust/issues/46906 -[weak keyword]: https://doc.rust-lang.org/reference/keywords.html#weak-keywords diff --git a/src/rust-2018-outdated/error-handling-and-panics/aborting-on-panic.md b/src/rust-2018-outdated/error-handling-and-panics/aborting-on-panic.md deleted file mode 100644 index 303395e2..00000000 --- a/src/rust-2018-outdated/error-handling-and-panics/aborting-on-panic.md +++ /dev/null @@ -1,18 +0,0 @@ -# Aborting on panic - -![Minimum Rust version: 1.10](https://img.shields.io/badge/Minimum%20Rust%20Version-1.10-brightgreen.svg) - -By default, Rust programs will unwind the stack when a `panic!` happens. If you'd prefer an -immediate abort instead, you can configure this in `Cargo.toml`: - -```toml -[profile.dev] -panic = "abort" - -[profile.release] -panic = "abort" -``` - -Why might you choose to do this? By removing support for unwinding, you'll -get smaller binaries. You will lose the ability to catch panics. Which choice -is right for you depends on exactly what you're doing. diff --git a/src/rust-2018-outdated/error-handling-and-panics/controlling-panics-with-std-panic.md b/src/rust-2018-outdated/error-handling-and-panics/controlling-panics-with-std-panic.md deleted file mode 100644 index 3f4ae236..00000000 --- a/src/rust-2018-outdated/error-handling-and-panics/controlling-panics-with-std-panic.md +++ /dev/null @@ -1,80 +0,0 @@ -# Controlling panics with `std::panic` - -![Minimum Rust version: 1.9](https://img.shields.io/badge/Minimum%20Rust%20Version-1.9-brightgreen.svg) - -There is a `std::panic` module, which includes methods for halting the -unwinding process started by a panic: - -```rust -use std::panic; - -let result = panic::catch_unwind(|| { - println!("hello!"); -}); -assert!(result.is_ok()); - -let result = panic::catch_unwind(|| { - panic!("oh no!"); -}); -assert!(result.is_err()); -``` - -In general, Rust distinguishes between two ways that an operation can fail: - -- Due to an *expected problem*, like a file not being found. -- Due to an *unexpected problem*, like an index being out of bounds for an array. - -Expected problems usually arise from conditions that are outside of your -control; robust code should be prepared for anything its environment might throw -at it. In Rust, expected problems are handled via [the `Result` type][result], -which allows a function to return information about the problem to its caller, -which can then handle the error in a fine-grained way. - -[result]: http://doc.rust-lang.org/std/result/index.html - -Unexpected problems are *bugs*: they arise due to a contract or assertion being -violated. Since they are unexpected, it doesn't make sense to handle them in a -fine-grained way. Instead, Rust employs a "fail fast" approach by *panicking*, -which by default unwinds the stack (running destructors but no other code) of -the thread which discovered the error. Other threads continue running, but will -discover the panic any time they try to communicate with the panicked thread -(whether through channels or shared memory). Panics thus abort execution up to -some "isolation boundary", with code on the other side of the boundary still -able to run, and perhaps to "recover" from the panic in some very coarse-grained -way. A server, for example, does not necessarily need to go down just because of -an assertion failure in one of its threads. - -It's also worth noting that programs may choose to *abort* instead of unwind, -and so catching panics may not work. If your code relies on `catch_unwind`, you -should add this to your Cargo.toml: - -```toml -[profile.dev] -panic = "unwind" - -[profile.release] -panic = "unwind" -``` - -If any of your users choose to abort, they'll get a compile-time failure. - -The `catch_unwind` API offers a way to introduce new isolation boundaries -*within a thread*. There are a couple of key motivating examples: - -* Embedding Rust in other languages -* Abstractions that manage threads -* Test frameworks, because tests may panic and you don't want that to kill the test runner - -For the first case, unwinding across a language boundary is undefined behavior, -and often leads to segfaults in practice. Allowing panics to be caught means -that you can safely expose Rust code via a C API, and translate unwinding into -an error on the C side. - -For the second case, consider a threadpool library. If a thread in the pool -panics, you generally don't want to kill the thread itself, but rather catch the -panic and communicate it to the client of the pool. The `catch_unwind` API is -paired with `resume_unwind`, which can then be used to restart the panicking -process on the client of the pool, where it belongs. - -In both cases, you're introducing a new isolation boundary within a thread, and -then translating the panic into some other form of error elsewhere. diff --git a/src/rust-2018-outdated/error-handling-and-panics/index.md b/src/rust-2018-outdated/error-handling-and-panics/index.md deleted file mode 100644 index c89a7d5e..00000000 --- a/src/rust-2018-outdated/error-handling-and-panics/index.md +++ /dev/null @@ -1,6 +0,0 @@ -# Error handling and Panics - -[qop]: the-question-mark-operator-for-easier-error-handling.md - -In this chapter of the guide, we discuss a few improvements to error handling -in Rust. The most notable of these is [the introduction of the `?` operator][qop]. \ No newline at end of file diff --git a/src/rust-2018-outdated/error-handling-and-panics/question-mark-in-main-and-tests.md b/src/rust-2018-outdated/error-handling-and-panics/question-mark-in-main-and-tests.md deleted file mode 100644 index 4c116b56..00000000 --- a/src/rust-2018-outdated/error-handling-and-panics/question-mark-in-main-and-tests.md +++ /dev/null @@ -1,131 +0,0 @@ -# `?` in `main` and tests - -![Minimum Rust version: 1.26](https://img.shields.io/badge/Minimum%20Rust%20Version-1.26-brightgreen.svg) - -Rust's error handling revolves around returning `Result` and using `?` -to propagate errors. For those who write many small programs and, hopefully, -many tests, one common paper cut has been mixing entry points such as `main` -and `#[test]`s with error handling. - -As an example, you might have tried to write: - -```rust,ignore -use std::fs::File; - -fn main() { - let f = File::open("bar.txt")?; -} -``` - -Since `?` works by propagating the `Result` with an early return to the -enclosing function, the snippet above does not work, and results today -in the following error: - -```rust,ignore -error[E0277]: the `?` operator can only be used in a function that returns `Result` - or `Option` (or another type that implements `std::ops::Try`) - --> src/main.rs:5:13 - | -5 | let f = File::open("bar.txt")?; - | ^^^^^^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()` - | - = help: the trait `std::ops::Try` is not implemented for `()` - = note: required by `std::ops::Try::from_error` -``` - -To solve this problem in Rust 2015, you might have written something like: - -```rust -// Rust 2015 - -# use std::process; -# use std::error::Error; - -fn run() -> Result<(), Box> { - // real logic.. - Ok(()) -} - -fn main() { - if let Err(e) = run() { - println!("Application error: {}", e); - process::exit(1); - } -} -``` - -However, in this case, the `run` function has all the interesting logic and -`main` is just boilerplate. The problem is even worse for `#[test]`s, since -there tend to be a lot more of them. - -In Rust 2018 you can instead let your `#[test]`s and `main` functions return -a `Result`: - -```rust,no_run -// Rust 2018 - -use std::fs::File; - -fn main() -> Result<(), std::io::Error> { - let f = File::open("bar.txt")?; - - Ok(()) -} -``` - -In this case, if say the file doesn't exist and there is an `Err(err)` somewhere, -then `main` will exit with an error code (not `0`) and print out a `Debug` -representation of `err`. Note that this will always print out the `Debug` representation. -If you would like to, for example, print out the `Display` representation of `err`, -you will still have to do what you would in Rust 2015. - -## More details - -Getting `-> Result<..>` to work in the context of `main` and `#[test]`s is not -magic. It is all backed up by a `Termination` trait which all valid return -types of `main` and testing functions must implement. The trait is defined as: - -```rust -pub trait Termination { - fn report(self) -> i32; -} -``` - -When setting up the entry point for your application, the compiler will use this -trait and call `.report()` on the `Result` of the `main` function you have written. - -Two simplified example implementations of this trait for `Result` and `()` are: - -```rust -# #![feature(process_exitcode_placeholder, termination_trait_lib)] -# use std::process::ExitCode; -# use std::fmt; -# -# pub trait Termination { fn report(self) -> i32; } - -impl Termination for () { - fn report(self) -> i32 { - # use std::process::Termination; - ExitCode::SUCCESS.report() - } -} - -impl Termination for Result<(), E> { - fn report(self) -> i32 { - match self { - Ok(()) => ().report(), - Err(err) => { - eprintln!("Error: {:?}", err); - # use std::process::Termination; - ExitCode::FAILURE.report() - } - } - } -} -``` - -As you can see in the case of `()`, a success code is simply returned. -In the case of `Result`, the success case delegates to the implementation for -`()` but prints out an error message and a failure exit code on `Err(..)`. - -To learn more about the finer details, consult either [the tracking issue](https://github.com/rust-lang/rust/issues/43301) or [the RFC](https://github.com/rust-lang/rfcs/blob/master/text/1937-ques-in-main.md). diff --git a/src/rust-2018-outdated/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.md b/src/rust-2018-outdated/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.md deleted file mode 100644 index d521a4a1..00000000 --- a/src/rust-2018-outdated/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.md +++ /dev/null @@ -1,120 +0,0 @@ -# The `?` operator for easier error handling - -![Minimum Rust version: 1.13](https://img.shields.io/badge/Minimum%20Rust%20Version-1.13-brightgreen.svg) for `Result` - -![Minimum Rust version: 1.22](https://img.shields.io/badge/Minimum%20Rust%20Version-1.22-brightgreen.svg) for `Option` - -Rust has gained a new operator, `?`, that makes error handling more pleasant -by reducing the visual noise involved. It does this by solving one simple -problem. To illustrate, imagine we had some code to read some data from a -file: - -```rust -# use std::{io::{self, prelude::*}, fs::File}; -fn read_username_from_file() -> Result { - let f = File::open("username.txt"); - - let mut f = match f { - Ok(file) => file, - Err(e) => return Err(e), - }; - - let mut s = String::new(); - - match f.read_to_string(&mut s) { - Ok(_) => Ok(s), - Err(e) => Err(e), - } -} -``` - -> Note: this code could be made simpler with a single call to -> [`std::fs::read_to_string`](https://doc.rust-lang.org/stable/std/fs/fn.read_to_string.html), -> but we're writing it all out manually here to have an example with multiple -> errors. - -This code has two paths that can fail, opening the file and reading the data -from it. If either of these fail to work, we'd like to return an error from -`read_username_from_file`. Doing so involves `match`ing on the result of the -I/O operations. In simple cases like this though, where we are only -propagating errors up the call stack, the matching is just boilerplate - -seeing it written out, in the same pattern every time, doesn't provide the -reader with a great deal of useful information. - -With `?`, the above code looks like this: - -```rust -# use std::{io::{self, prelude::*}, fs::File}; -fn read_username_from_file() -> Result { - let mut f = File::open("username.txt")?; - let mut s = String::new(); - - f.read_to_string(&mut s)?; - - Ok(s) -} -``` - -The `?` is shorthand for the entire match statements we wrote earlier. In -other words, `?` applies to a `Result` value, and if it was an `Ok`, it -unwraps it and gives the inner value. If it was an `Err`, it returns from the -function you're currently in. Visually, it is much more straightforward. -Instead of an entire match statement, now we are just using the single "?" -character to indicate that here we are handling errors in the standard way, -by passing them up the call stack. - -Seasoned Rustaceans may recognize that this is the same as the `try!` macro -that's been available since Rust `1.0`. And indeed, they are the same. -Previously, `read_username_from_file` could have been implemented like this: - -```rust -# use std::{io::{self, prelude::*}, fs::File}; -fn read_username_from_file() -> Result { - let mut f = try!(File::open("username.txt")); - let mut s = String::new(); - - try!(f.read_to_string(&mut s)); - - Ok(s) -} -``` - -So why extend the language when we already have a macro? There are multiple -reasons. First, `try!` has proved to be extremely useful, and is used often -in idiomatic Rust. It is used so often that we think it's worth having a -sweet syntax. This sort of evolution is one of the great advantages of a -powerful macro system: speculative extensions to the language syntax can be -prototyped and iterated on without modifying the language itself, and in -return, macros that turn out to be especially useful can indicate missing -language features. This evolution, from `try!` to `?` is a great example. - -One of the reasons `try!` needs a sweeter syntax is that it is quite -unattractive when multiple invocations of `try!` are used in succession. -Consider: - -```rust,ignore -try!(try!(try!(foo()).bar()).baz()) -``` - -as opposed to - -```rust,ignore -foo()?.bar()?.baz()? -``` - -The first is quite difficult to scan visually, and each layer of error -handling prefixes the expression with an additional call to `try!`. This -brings undue attention to the trivial error propagation, obscuring the main -code path, in this example the calls to `foo`, `bar` and `baz`. This sort of -method chaining with error handling occurs in situations like the builder -pattern. - -Finally, the dedicated syntax will make it easier in the future to produce -nicer error messages tailored specifically to `?`, whereas it is difficult to -produce nice errors for macro-expanded code generally. - -You can use `?` with `Result`s, but also with `Option`. In that -case, `?` will return a value for `Some(T)` and return `None` for `None`. One -current restriction is that you cannot use `?` for both in the same function, -as the return type needs to match the type you use `?` on. In the future, -this restriction will be lifted. diff --git a/src/rust-2018-outdated/index.md b/src/rust-2018-outdated/index.md deleted file mode 100644 index ee982334..00000000 --- a/src/rust-2018-outdated/index.md +++ /dev/null @@ -1,8 +0,0 @@ -# Rust 2018 - -The edition system was created for the release of Rust 2018. The theme of Rust 2018 -is *productivity*. Rust 2018 improves upon Rust 2015 through new features, -simpler syntax in some cases, a smarter borrow-checker, and a host of other things. -These are all in service of the productivity goal. Rust 2015 was a foundation; -Rust 2018 smooths off rough edges, makes writing code simpler and easier, -and removes some inconsistencies. \ No newline at end of file diff --git a/src/rust-2018-outdated/macros/at-most-once.md b/src/rust-2018-outdated/macros/at-most-once.md deleted file mode 100644 index 56e30b97..00000000 --- a/src/rust-2018-outdated/macros/at-most-once.md +++ /dev/null @@ -1,42 +0,0 @@ -# At most one repetition - -![Minimum Rust version: 1.32](https://img.shields.io/badge/Minimum%20Rust%20Version-1.32-brightgreen.svg) for 2018 edition - -![Minimum Rust version: 1.37](https://img.shields.io/badge/Minimum%20Rust%20Version-1.37-brightgreen.svg) for 2015 edition - -In Rust 2018, we have made a couple of changes to the macros-by-example syntax. - -1. We have added a new Kleene operator `?` which means "at most one" - repetition. This operator does not accept a separator token. -2. We have disallowed using `?` as a separator to remove ambiguity with `?`. - -For example, consider the following Rust 2015 code: - -```rust -macro_rules! foo { - ($a:ident, $b:expr) => { - println!("{}", $a); - println!("{}", $b); - }; - ($a:ident) => { - println!("{}", $a); - } -} -``` - -Macro `foo` can be called with 1 or 2 arguments; the second one is optional, -but you need a whole other matcher to represent this possibility. This is -annoying if your matchers are long. In Rust 2018, one can simply write the -following: - -```rust -macro_rules! foo { - ($a:ident $(, $b:expr)?) => { - println!("{}", $a); - - $( - println!("{}", $b); - )? - } -} -``` diff --git a/src/rust-2018-outdated/macros/custom-derive.md b/src/rust-2018-outdated/macros/custom-derive.md deleted file mode 100644 index 4a1cd833..00000000 --- a/src/rust-2018-outdated/macros/custom-derive.md +++ /dev/null @@ -1,49 +0,0 @@ -# Custom Derive - -![Minimum Rust version: 1.15](https://img.shields.io/badge/Minimum%20Rust%20Version-1.15-brightgreen.svg) - -In Rust, you’ve always been able to automatically implement some traits -through the derive attribute: - -```rust -#[derive(Debug)] -struct Pet { - name: String, -} -``` - -The `Debug` trait is then implemented for `Pet`, with vastly less boilerplate. For example, without `derive`, you'd have -to write this: - -```rust -use std::fmt; - -struct Pet { - name: String, -} - -impl fmt::Debug for Pet { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - Pet { name } => { - let mut debug_trait_builder = f.debug_struct("Pet"); - - let _ = debug_trait_builder.field("name", name); - - debug_trait_builder.finish() - } - } - } -} -``` - -Whew! - -However, this only worked for traits provided as part of the standard -library; it was not customizable. But now, you can tell Rust what to do when -someone wants to derive your trait. This is used heavily in popular crates -like [serde](https://serde.rs/) and [Diesel](http://diesel.rs/). - -For more, including learning how to build your own custom derive, see [The -Rust Programming -Language](https://doc.rust-lang.org/book/ch19-06-macros.html#how-to-write-a-custom-derive-macro). \ No newline at end of file diff --git a/src/rust-2018-outdated/macros/index.md b/src/rust-2018-outdated/macros/index.md deleted file mode 100644 index a87105fd..00000000 --- a/src/rust-2018-outdated/macros/index.md +++ /dev/null @@ -1,6 +0,0 @@ -# Macros - -[custom-derive]: custom-derive.md - -In this chapter of the guide, we discuss a few improvements to the macro system. -A notable addition here is the introduction of [custom derive macros][custom-derive]. \ No newline at end of file diff --git a/src/rust-2018-outdated/macros/macro-changes.md b/src/rust-2018-outdated/macros/macro-changes.md deleted file mode 100644 index b561c9c3..00000000 --- a/src/rust-2018-outdated/macros/macro-changes.md +++ /dev/null @@ -1,271 +0,0 @@ -# Macro changes - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -## `macro_rules!` style macros - -In Rust 2018, you can import specific macros from external crates via `use` -statements, rather than the old `#[macro_use]` attribute. - -For example, consider a `bar` crate that implements a `baz!` macro. In -`src/lib.rs`: - -```rust -#[macro_export] -macro_rules! baz { - () => () -} -``` - -In your crate, you would have written - -```rust,ignore -// Rust 2015 - -#[macro_use] -extern crate bar; - -fn main() { - baz!(); -} -``` - -Now, you write: - -```rust,ignore -// Rust 2018 - -use bar::baz; - -fn main() { - baz!(); -} -``` - -This moves `macro_rules` macros to be a bit closer to other kinds of items. - -Note that you'll still need `#[macro_use]` to use macros you've defined -in your own crate; this feature only works for importing macros from -external crates. - -## Procedural macros - -When using procedural macros to derive traits, you will have to name the macro -that provides the custom derive. This generally matches the name of the trait, -but check with the documentation of the crate providing the derives to be sure. - -For example, with Serde you would have written - -```rust,ignore -// Rust 2015 -extern crate serde; -#[macro_use] extern crate serde_derive; - -#[derive(Serialize, Deserialize)] -struct Bar; -``` - -Now, you write instead: - -```rust,ignore -// Rust 2018 -use serde_derive::{Serialize, Deserialize}; - -#[derive(Serialize, Deserialize)] -struct Bar; -``` - - -## More details - -This only works for macros defined in external crates. -For macros defined locally, `#[macro_use] mod foo;` is still required, as it was in Rust 2015. - -### Local helper macros - -Sometimes it is helpful or necessary to have helper macros inside your module. This can make -supporting both versions of rust more complicated. - -For example, let's make a simplified (and slightly contrived) version of the `log` crate in 2015 -edition style: - -```rust -use std::fmt; - -/// How important/severe the log message is. -#[derive(Copy, Clone)] -pub enum LogLevel { - Warn, - Error -} - -impl fmt::Display for LogLevel { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - LogLevel::Warn => write!(f, "warning"), - LogLevel::Error => write!(f, "error"), - } - } -} - -// A helper macro to log the message. -#[doc(hidden)] -#[macro_export] -macro_rules! __impl_log { - ($level:expr, $msg:expr) => {{ - println!("{}: {}", $level, $msg) - }} -} - -/// Warn level log message -#[macro_export] -macro_rules! warn { - ($($args:tt)*) => { - __impl_log!($crate::LogLevel::Warn, format_args!($($args)*)) - } -} - -/// Error level log message -#[macro_export] -macro_rules! error { - ($($args:tt)*) => { - __impl_log!($crate::LogLevel::Error, format_args!($($args)*)) - } -} -``` - -Our `__impl_log!` macro is private to our module, but needs to be exported as it is called by other -macros, and in 2015 edition all used macros must be exported. - -Now, in 2018 this example will not compile: - -```rust,ignore -use log::error; - -fn main() { - error!("error message"); -} -``` - -will give an error message about not finding the `__impl_log!` macro. This is because unlike in -the 2015 edition, macros are namespaced and we must import them. We could do - -```rust,ignore -use log::{__impl_log, error}; -``` - -which would make our code compile, but `__impl_log` is meant to be an implementation detail! - -#### Macros with `$crate::` prefix. - -The cleanest way to handle this situation is to use the `$crate::` prefix for macros, the same as -you would for any other path. Versions of the compiler >= 1.30 will handle this in both editions: - -```rust -macro_rules! warn { - ($($args:tt)*) => { - $crate::__impl_log!($crate::LogLevel::Warn, format_args!($($args)*)) - } -} - -// ... -``` - -However, this will not work for older versions of the compiler that don't understand the -`$crate::` prefix for macros. - -#### Macros using `local_inner_macros` - -We also have the `local_inner_macros` modifier that we can add to our `#[macro_export]` attribute. -This has the advantage of working with older rustc versions (older versions just ignore the extra -modifier). The downside is that it's a bit messier: - -```rust,ignore -#[macro_export(local_inner_macros)] -macro_rules! warn { - ($($args:tt)*) => { - __impl_log!($crate::LogLevel::Warn, format_args!($($args)*)) - } -} -``` - -So the code knows to look for any macros used locally. But wait - this won't compile, because we -use the `format_args!` macro that isn't in our local crate (hence the convoluted example). The -solution is to add a level of indirection: we create a macro that wraps `format_args`, but is local -to our crate. That way everything works in both editions (sadly we have to pollute the global -namespace a bit, but that's ok). - -```rust -// I've used the pattern `___` to name this macro, hopefully avoiding -// name clashes. -#[doc(hidden)] -#[macro_export] -macro_rules! _log__format_args { - ($($inner:tt)*) => { - format_args! { $($inner)* } - } -} -``` - -Here we're using the most general macro pattern possible, a list of token trees. We just pass -whatever tokens we get to the inner macro, and rely on it to report errors. - -So the full 2015/2018 working example would be: - -```rust -use std::fmt; - -/// How important/severe the log message is. -#[derive(Debug, Copy, Clone)] -pub enum LogLevel { - Warn, - Error -} - -impl fmt::Display for LogLevel { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - LogLevel::Warn => write!(f, "warning"), - LogLevel::Error => write!(f, "error"), - } - } -} - -// A helper macro to log the message. -#[doc(hidden)] -#[macro_export] -macro_rules! __impl_log { - ($level:expr, $msg:expr) => {{ - println!("{}: {}", $level, $msg) - }} -} - -/// Warn level log message -#[macro_export(local_inner_macros)] -macro_rules! warn { - ($($args:tt)*) => { - __impl_log!($crate::LogLevel::Warn, _log__format_args!($($args)*)) - } -} - -/// Error level log message -#[macro_export(local_inner_macros)] -macro_rules! error { - ($($args:tt)*) => { - __impl_log!($crate::LogLevel::Error, _log__format_args!($($args)*)) - } -} - -#[doc(hidden)] -#[macro_export] -macro_rules! _log__format_args { - ($($inner:tt)*) => { - format_args! { $($inner)* } - } -} -``` - -Once everyone is using a rustc version >= 1.30, we can all just use the `$crate::` method (2015 -crates are guaranteed to carry on compiling fine with later versions of the compiler). We need to -wait for package managers and larger organisations to update their compilers before this happens, -so in the mean time we can use the `local_inner_macros` method to support everybody. :) diff --git a/src/rust-2018-outdated/module-system/index.md b/src/rust-2018-outdated/module-system/index.md deleted file mode 100644 index 42fea5fd..00000000 --- a/src/rust-2018-outdated/module-system/index.md +++ /dev/null @@ -1,6 +0,0 @@ -# Module system - -[path clarity changes]: path-clarity.md - -In this chapter of the guide, we discuss a few changes to the module system. -The most notable of these are the [path clarity changes]. \ No newline at end of file diff --git a/src/rust-2018-outdated/module-system/more-visibility-modifiers.md b/src/rust-2018-outdated/module-system/more-visibility-modifiers.md deleted file mode 100644 index cd7b7c1b..00000000 --- a/src/rust-2018-outdated/module-system/more-visibility-modifiers.md +++ /dev/null @@ -1,16 +0,0 @@ -# More visibility modifiers - -![Minimum Rust version: 1.18](https://img.shields.io/badge/Minimum%20Rust%20Version-1.18-brightgreen.svg) - -You can use the `pub` keyword to make something a part of a module's public interface. But in -addition, there are some new forms: - -```rust,ignore -pub(crate) struct Foo; - -pub(in a::b::c) struct Bar; -``` - -The first form makes the `Foo` struct public to your entire crate, but not -externally. The second form is similar, but makes `Bar` public for one other -module, `a::b::c` in this case. \ No newline at end of file diff --git a/src/rust-2018-outdated/module-system/nested-imports-with-use.md b/src/rust-2018-outdated/module-system/nested-imports-with-use.md deleted file mode 100644 index b813590c..00000000 --- a/src/rust-2018-outdated/module-system/nested-imports-with-use.md +++ /dev/null @@ -1,35 +0,0 @@ -# Nested imports with `use` - -![Minimum Rust version: 1.25](https://img.shields.io/badge/Minimum%20Rust%20Version-1.25-brightgreen.svg) - -A new way to write `use` statements has been added to Rust: nested import -groups. If you’ve ever written a set of imports like this: - -```rust -use std::fs::File; -use std::io::Read; -use std::path::{Path, PathBuf}; -``` - -You can now write this: - -```rust -# mod foo { -// on one line -use std::{fs::File, io::Read, path::{Path, PathBuf}}; -# } - -# mod bar { -// with some more breathing room -use std::{ - fs::File, - io::Read, - path::{ - Path, - PathBuf - } -}; -# } -``` - -This can reduce some repetition, and make things a bit more clear. diff --git a/src/rust-2018-outdated/module-system/path-clarity.md b/src/rust-2018-outdated/module-system/path-clarity.md deleted file mode 100644 index 03270aa0..00000000 --- a/src/rust-2018-outdated/module-system/path-clarity.md +++ /dev/null @@ -1,351 +0,0 @@ -# Path clarity - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -The module system is often one of the hardest things for people new to Rust. Everyone -has their own things that take time to master, of course, but there's a root -cause for why it's so confusing to many: while there are simple and -consistent rules defining the module system, their consequences can feel -inconsistent, counterintuitive and mysterious. - -As such, the 2018 edition of Rust introduces a few new module system -features, but they end up *simplifying* the module system, to make it more -clear as to what is going on. - -Here's a brief summary: - -* `extern crate` is no longer needed in 99% of circumstances. -* The `crate` keyword refers to the current crate. -* Paths may start with a crate name, even within submodules. -* Paths starting with `::` must reference an external crate. -* A `foo.rs` and `foo/` subdirectory may coexist; `mod.rs` is no longer needed - when placing submodules in a subdirectory. -* Paths in `use` declarations work the same as other paths. - -These may seem like arbitrary new rules when put this way, but the mental -model is now significantly simplified overall. Read on for more details! - -## More details - -Let's talk about each new feature in turn. - -### No more `extern crate` - -This one is quite straightforward: you no longer need to write `extern crate` to -import a crate into your project. Before: - -```rust,ignore -// Rust 2015 - -extern crate futures; - -mod submodule { - use futures::Future; -} -``` - -After: - -```rust,ignore -// Rust 2018 - -mod submodule { - use futures::Future; -} -``` - -Now, to add a new crate to your project, you can add it to your `Cargo.toml`, -and then there is no step two. If you're not using Cargo, you already had to pass -`--extern` flags to give `rustc` the location of external crates, so you'd just -keep doing what you were doing there as well. - -> One small note here: `cargo fix` will not currently automate this change. We may -> have it do this for you in the future. - -#### An exception - -There's one exception to this rule, and that's the "sysroot" crates. These are the -crates distributed with Rust itself. - -Usually these are only needed in very specialized situations. Starting in -1.41, `rustc` accepts the `--extern=CRATE_NAME` flag which automatically adds -the given crate name in a way similar to `extern crate`. Build tools may use -this to inject sysroot crates into the crate's prelude. Cargo does not have a -general way to express this, though it uses it for `proc_macro` crates. - -Some examples of needing to explicitly import sysroot crates are: - -* [`std`]: Usually this is not neccesary, because `std` is automatically - imported unless the crate is marked with [`#![no_std]`][no_std]. -* [`core`]: Usually this is not necessary, because `core` is automatically - imported, unless the crate is marked with [`#![no_core]`][no_core]. For - example, some of the internal crates used by the standard library itself - need this. -* [`proc_macro`]: This is automatically imported by Cargo if it is a - proc-macro crate starting in 1.42. `extern crate proc_macro;` would be - needed if you want to support older releases, or if using another build tool - that does not pass the appropriate `--extern` flags to `rustc`. -* [`alloc`]: Items in the `alloc` crate are usually accessed via re-exports in - the `std` crate. If you are working with a `no_std` crate that supports - allocation, then you may need to explicitly import `alloc`. -* [`test`]: This is only available on the [nightly channel], and is usually - only used for the unstable benchmark support. - -[`alloc`]: ../../../alloc/index.html -[`core`]: ../../../core/index.html -[`proc_macro`]: ../../../proc_macro/index.html -[`std`]: ../../../std/index.html -[`test`]: ../../../test/index.html -[nightly channel]: ../../../book/appendix-07-nightly-rust.html -[no_core]: https://github.com/rust-lang/rust/issues/29639 -[no_std]: ../../../reference/names/preludes.html#the-no_std-attribute - -#### Macros - -One other use for `extern crate` was to import macros; that's no longer needed. -Check [the macro section](../macros/macro-changes.md) for more. - -#### Renaming crates - -If you've been using `as` to rename your crate like this: - -```rust,ignore -extern crate futures as f; - -use f::Future; -``` - -then removing the `extern crate` line on its own won't work. You'll need to do this: - -```rust,ignore -use futures as f; - -use self::f::Future; -``` - -This change will need to happen in any module that uses `f`. - -### The `crate` keyword refers to the current crate - -In `use` declarations and in other code, you can refer to the root of the -current crate with the `crate::` prefix. For instance, `crate::foo::bar` will -always refer to the name `bar` inside the module `foo`, from anywhere else in -the same crate. - -The prefix `::` previously referred to either the crate root or an external -crate; it now unambiguously refers to an external crate. For instance, -`::foo::bar` always refers to the name `bar` inside the external crate `foo`. - -### Extern crate paths - -Previously, using an external crate in a module without a `use` import -required a leading `::` on the path. - -```rust,ignore -// Rust 2015 - -extern crate chrono; - -fn foo() { - // this works in the crate root - let x = chrono::Utc::now(); -} - -mod submodule { - fn function() { - // but in a submodule it requires a leading :: if not imported with `use` - let x = ::chrono::Utc::now(); - } -} -``` - -Now, extern crate names are in scope in the entire crate, including -submodules. - -```rust,ignore -// Rust 2018 - -fn foo() { - // this works in the crate root - let x = chrono::Utc::now(); -} - -mod submodule { - fn function() { - // crates may be referenced directly, even in submodules - let x = chrono::Utc::now(); - } -} -``` - -### No more `mod.rs` - -In Rust 2015, if you have a submodule: - -```rust,ignore -// This `mod` declaration looks for the `foo` module in -// `foo.rs` or `foo/mod.rs`. -mod foo; -``` - -It can live in `foo.rs` or `foo/mod.rs`. If it has submodules of its own, it -*must* be `foo/mod.rs`. So a `bar` submodule of `foo` would live at -`foo/bar.rs`. - -In Rust 2018 the restriction that a module with submodules must be named -`mod.rs` is lifted. `foo.rs` can just be `foo.rs`, -and the submodule is still `foo/bar.rs`. This eliminates the special -name, and if you have a bunch of files open in your editor, you can clearly -see their names, instead of having a bunch of tabs named `mod.rs`. - - - - - - - - - - - - - - -
Rust 2015Rust 2018
-
-.
-├── lib.rs
-└── foo/
-    ├── mod.rs
-    └── bar.rs
-
-
-
-.
-├── lib.rs
-├── foo.rs
-└── foo/
-    └── bar.rs
-
-
- -### `use` paths - -![Minimum Rust version: 1.32](https://img.shields.io/badge/Minimum%20Rust%20Version-1.32-brightgreen.svg) - -Rust 2018 simplifies and unifies path handling compared to Rust 2015. In Rust -2015, paths work differently in `use` declarations than they do elsewhere. In -particular, paths in `use` declarations would always start from the crate -root, while paths in other code implicitly started from the current scope. -Those differences didn't have any effect in the top-level module, which meant -that everything would seem straightforward until working on a project large -enough to have submodules. - -In Rust 2018, paths in `use` declarations and in other code work the same way, -both in the top-level module and in any submodule. You can use a relative path -from the current scope, a path starting from an external crate name, or a path -starting with `crate`, `super`, or `self`. - -Code that looked like this: - -```rust,ignore -// Rust 2015 - -extern crate futures; - -use futures::Future; - -mod foo { - pub struct Bar; -} - -use foo::Bar; - -fn my_poll() -> futures::Poll { ... } - -enum SomeEnum { - V1(usize), - V2(String), -} - -fn func() { - let five = std::sync::Arc::new(5); - use SomeEnum::*; - match ... { - V1(i) => { ... } - V2(s) => { ... } - } -} -``` - -will look exactly the same in Rust 2018, except that you can delete the `extern -crate` line: - -```rust,ignore -// Rust 2018 - -use futures::Future; - -mod foo { - pub struct Bar; -} - -use foo::Bar; - -fn my_poll() -> futures::Poll { ... } - -enum SomeEnum { - V1(usize), - V2(String), -} - -fn func() { - let five = std::sync::Arc::new(5); - use SomeEnum::*; - match ... { - V1(i) => { ... } - V2(s) => { ... } - } -} -``` - -The same code will also work completely unmodified in a submodule: - -```rust,ignore -// Rust 2018 - -mod submodule { - use futures::Future; - - mod foo { - pub struct Bar; - } - - use foo::Bar; - - fn my_poll() -> futures::Poll { ... } - - enum SomeEnum { - V1(usize), - V2(String), - } - - fn func() { - let five = std::sync::Arc::new(5); - use SomeEnum::*; - match ... { - V1(i) => { ... } - V2(s) => { ... } - } - } -} -``` - -This makes it easy to move code around in a project, and avoids introducing -additional complexity to multi-module projects. - -If a path is ambiguous, such as if you have an external crate and a local -module or item with the same name, you'll get an error, and you'll need to -either rename one of the conflicting names or explicitly disambiguate the path. -To explicitly disambiguate a path, use `::name` for an external crate name, or -`self::name` for a local module or item. diff --git a/src/rust-2018-outdated/module-system/raw-identifiers.md b/src/rust-2018-outdated/module-system/raw-identifiers.md deleted file mode 100644 index 208501de..00000000 --- a/src/rust-2018-outdated/module-system/raw-identifiers.md +++ /dev/null @@ -1,68 +0,0 @@ -# Raw identifiers - -![Minimum Rust version: 1.30](https://img.shields.io/badge/Minimum%20Rust%20Version-1.30-brightgreen.svg) - -Rust, like many programming languages, has the concept of "keywords". -These identifiers mean something to the language, and so you cannot use them in -places like variable names, function names, and other places. -Raw identifiers let you use keywords where they would not normally be allowed. - -For example, `match` is a keyword. If you try to compile this function: - -```rust,ignore -fn match(needle: &str, haystack: &str) -> bool { - haystack.contains(needle) -} -``` - -You'll get this error: - -```text -error: expected identifier, found keyword `match` - --> src/main.rs:4:4 - | -4 | fn match(needle: &str, haystack: &str) -> bool { - | ^^^^^ expected identifier, found keyword -``` - -You can write this with a raw identifier: - -```rust -fn r#match(needle: &str, haystack: &str) -> bool { - haystack.contains(needle) -} - -fn main() { - assert!(r#match("foo", "foobar")); -} -``` - -Note the `r#` prefix on both the function name as well as the call. - -## Motivation - -This feature is useful for a few reasons, but the primary motivation was -inter-edition situations. For example, `try` is not a keyword in the 2015 -edition, but is in the 2018 edition. So if you have a library that is written -in Rust 2015 and has a `try` function, to call it in Rust 2018, you'll need -to use the raw identifier. - -## New keywords - -The new confirmed keywords in edition 2018 are: - -### `async` and `await` - -[RFC 2394]: https://github.com/rust-lang/rfcs/blob/master/text/2394-async_await.md#final-syntax-for-the-await-expression - -Here, `async` is reserved for use in `async fn` as well as in `async ||` closures and -`async { .. }` blocks. Meanwhile, `await` is reserved to keep our options open -with respect to `await!(expr)` syntax. See [RFC 2394] for more details. - -### `try` - -[RFC 2388]: https://github.com/rust-lang/rfcs/pull/2388 - -The `do catch { .. }` blocks have been renamed to `try { .. }` and to support -that, the keyword `try` is reserved in edition 2018. -See [RFC 2388] for more details. diff --git a/src/rust-2018-outdated/ownership-and-lifetimes/default-match-bindings.md b/src/rust-2018-outdated/ownership-and-lifetimes/default-match-bindings.md deleted file mode 100644 index 05107c61..00000000 --- a/src/rust-2018-outdated/ownership-and-lifetimes/default-match-bindings.md +++ /dev/null @@ -1,61 +0,0 @@ -# Default match bindings - -![Minimum Rust version: 1.26](https://img.shields.io/badge/Minimum%20Rust%20Version-1.26-brightgreen.svg) - -Have you ever had a borrowed `Option` and tried to match on it? You -probably wrote this: - -```rust,ignore -let s: &Option = &Some("hello".to_string()); - -match s { - Some(s) => println!("s is: {}", s), - _ => (), -}; -``` - -In Rust 2015, this would fail to compile, and you would have to write the -following instead: - -```rust,ignore -// Rust 2015 - -let s: &Option = &Some("hello".to_string()); - -match s { - &Some(ref s) => println!("s is: {}", s), - _ => (), -}; -``` - -Rust 2018, by contrast, will infer the `&`s and `ref`s, and your original -code will Just Work. - -This affects not just `match`, but patterns everywhere, such as in `let` -statements, closure arguments, and `for` loops. - -## More details - -The mental model of patterns has shifted a bit with this change, to bring it -into line with other aspects of the language. For example, when writing a -`for` loop, you can iterate over borrowed contents of a collection by -borrowing the collection itself: - -```rust,ignore -let my_vec: Vec = vec![0, 1, 2]; - -for x in &my_vec { ... } -``` - -The idea is that an `&T` can be understood as a *borrowed view of `T`*, and -so when you iterate, match, or otherwise destructure a `&T` you get a -borrowed view of its internals as well. - -More formally, patterns have a "binding mode," which is either by value -(`x`), by reference (`ref x`), or by mutable reference (`ref mut x`). In Rust -2015, `match` always started in by-value mode, and required you to explicitly -write `ref` or `ref mut` in patterns to switch to a borrowing mode. In Rust -2018, the type of the value being matched informs the binding mode, so that -if you match against an `&Option` with a `Some` variant, you are put -into `ref` mode automatically, giving you a borrowed view of the internal -data. Similarly, `&mut Option` would give you a `ref mut` view. diff --git a/src/rust-2018-outdated/ownership-and-lifetimes/index.md b/src/rust-2018-outdated/ownership-and-lifetimes/index.md deleted file mode 100644 index 06456107..00000000 --- a/src/rust-2018-outdated/ownership-and-lifetimes/index.md +++ /dev/null @@ -1,6 +0,0 @@ -# Ownership and lifetimes - -[dmbm]: default-match-bindings.md - -In this chapter of the guide, we discuss a few improvements to ownership and lifetimes. -One of the most notable of these is [default match binding modes][dmbm]. diff --git a/src/rust-2018-outdated/ownership-and-lifetimes/inference-in-structs.md b/src/rust-2018-outdated/ownership-and-lifetimes/inference-in-structs.md deleted file mode 100644 index d4396ffd..00000000 --- a/src/rust-2018-outdated/ownership-and-lifetimes/inference-in-structs.md +++ /dev/null @@ -1,72 +0,0 @@ -# `T: 'a` inference in structs - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -An annotation in the form of `T: 'a`, where `T` is either a type or another -lifetime, is called an *"outlives"* requirement. Note that *"outlives"* also -implies `'a: 'a`. - -One way in which edition 2018 helps you out in maintaining flow when writing -programs is by removing the need to explicitly annotate these `T: 'a` outlives -requirements in `struct` definitions. Instead, the requirements will be -inferred from the fields present in the definitions. - -Consider the following `struct` definitions in Rust 2015: - -```rust -// Rust 2015 - -struct Ref<'a, T: 'a> { - field: &'a T -} - -// or written with a `where` clause: - -struct WhereRef<'a, T> where T: 'a { - data: &'a T -} - -// with nested references: - -struct RefRef<'a, 'b: 'a, T: 'b> { - field: &'a &'b T, -} - -// using an associated type: - -struct ItemRef<'a, T: Iterator> -where - T::Item: 'a -{ - field: &'a T::Item -} -``` - -In Rust 2018, since the requirements are inferred, you can instead write: - -```rust,ignore -// Rust 2018 - -struct Ref<'a, T> { - field: &'a T -} - -struct WhereRef<'a, T> { - data: &'a T -} - -struct RefRef<'a, 'b, T> { - field: &'a &'b T, -} - -struct ItemRef<'a, T: Iterator> { - field: &'a T::Item -} -``` - -If you prefer to be more explicit in some cases, that is still possible. - -## More details - -For more details, see [the tracking issue](https://github.com/rust-lang/rust/issues/44493) -and [the RFC](https://github.com/rust-lang/rfcs/pull/2093). diff --git a/src/rust-2018-outdated/ownership-and-lifetimes/lifetime-elision-in-impl.md b/src/rust-2018-outdated/ownership-and-lifetimes/lifetime-elision-in-impl.md deleted file mode 100644 index a8c22c30..00000000 --- a/src/rust-2018-outdated/ownership-and-lifetimes/lifetime-elision-in-impl.md +++ /dev/null @@ -1,75 +0,0 @@ -# Lifetime elision in impl - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -When writing `impl` blocks, you can now elide lifetime annotations in some -situations. - -Consider a trait like `MyIterator`: - -```rust,ignore -trait MyIterator { - type Item; - fn next(&mut self) -> Option; -} -``` - -In Rust 2015, if we wanted to implement this iterator for mutable references -to `Iterators`, we'd need to write this: - -```rust,ignore -impl<'a, I: MyIterator> MyIterator for &'a mut I { - type Item = I::Item; - fn next(&mut self) -> Option { - (*self).next() - } -} -``` - -Note all of the `'a` annotations. In Rust 2018, we can write this: - -```rust,ignore -impl MyIterator for &mut I { - type Item = I::Item; - fn next(&mut self) -> Option { - (*self).next() - } -} -``` - -Similarly, lifetime annotations can appear due to a struct that contains -references: - -```rust,ignore -struct SetOnDrop<'a, T> { - borrow: &'a mut T, - value: Option, -} -``` - -In Rust 2015, to implement `Drop` on this struct, we'd write: - -```rust,ignore -impl<'a, T> Drop for SetOnDrop<'a, T> { - fn drop(&mut self) { - if let Some(x) = self.value.take() { - *self.borrow = x; - } - } -} -``` - -But in Rust 2018, we can combine elision with [the anonymous lifetime] and -write this instead. - -```rust,ignore -impl Drop for SetOnDrop<'_, T> { - fn drop(&mut self) { - if let Some(x) = self.value.take() { - *self.borrow = x; - } - } -} -``` - -[the anonymous lifetime]: the-anonymous-lifetime.md \ No newline at end of file diff --git a/src/rust-2018-outdated/ownership-and-lifetimes/non-lexical-lifetimes.md b/src/rust-2018-outdated/ownership-and-lifetimes/non-lexical-lifetimes.md deleted file mode 100644 index 8daaef9a..00000000 --- a/src/rust-2018-outdated/ownership-and-lifetimes/non-lexical-lifetimes.md +++ /dev/null @@ -1,85 +0,0 @@ -# Non-lexical lifetimes - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) for 2018 edition - -![Minimum Rust version: 1.36](https://img.shields.io/badge/Minimum%20Rust%20Version-1.36-brightgreen.svg) for 2015 edition - -The borrow checker has been enhanced to accept more code, via a mechanism -called "non-lexical lifetimes." Consider this example: - -```rust,ignore -fn main() { - let mut x = 5; - - let y = &x; - - let z = &mut x; -} -``` - -In older Rust, this is a compile-time error: - -```text -error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable - --> src/main.rs:5:18 - | -4 | let y = &x; - | - immutable borrow occurs here -5 | let z = &mut x; - | ^ mutable borrow occurs here -6 | } - | - immutable borrow ends here -``` - -This is because lifetimes follow "lexical scope"; that is, the borrow from `y` is -considered to be held until `y` goes out of scope at the end of `main`, even though -we never use `y` again. This code is fine, but the borrow checker could not handle it. - -Today, this code will compile just fine. - -## Better errors - -What if we did use `y`, like this? - -```rust,ignore -fn main() { - let mut x = 5; - let y = &x; - let z = &mut x; - - println!("y: {}", y); -} -``` - -Here's the error: - -```text -error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable - --> src/main.rs:5:18 - | -4 | let y = &x; - | - immutable borrow occurs here -5 | let z = &mut x; - | ^ mutable borrow occurs here -... -8 | } - | - immutable borrow ends here -``` - -With non-lexical lifetimes, the error changes slightly: - -```text -error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable - --> src/main.rs:5:13 - | -4 | let y = &x; - | -- immutable borrow occurs here -5 | let z = &mut x; - | ^^^^^^ mutable borrow occurs here -6 | -7 | println!("y: {}", y); - | - borrow later used here -``` - -Instead of pointing to where `y` goes out of scope, it shows you where -the conflicting borrow occurs. This makes these sorts of errors *far* easier to debug. diff --git a/src/rust-2018-outdated/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.md b/src/rust-2018-outdated/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.md deleted file mode 100644 index 113c5705..00000000 --- a/src/rust-2018-outdated/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.md +++ /dev/null @@ -1,41 +0,0 @@ -# Simpler lifetimes in `static` and `const` - -![Minimum Rust version: 1.17](https://img.shields.io/badge/Minimum%20Rust%20Version-1.17-brightgreen.svg) - -In older Rust, you had to explicitly write the `'static` lifetime in any -`static` or `const` that needed a lifetime: - -```rust -# mod foo { -const NAME: &'static str = "Ferris"; -# } -# mod bar { -static NAME: &'static str = "Ferris"; -# } -``` - -But `'static` is the only possible lifetime there. So Rust now assumes the `'static` lifetime, -and you don't have to write it out: - -```rust -# mod foo { -const NAME: &str = "Ferris"; -# } -# mod bar { -static NAME: &str = "Ferris"; -# } -``` - -In some situations, this can remove a *lot* of boilerplate: - -```rust -# mod foo { -// old -const NAMES: &'static [&'static str; 2] = &["Ferris", "Bors"]; -# } -# mod bar { - -// new -const NAMES: &[&str; 2] = &["Ferris", "Bors"]; -# } -``` diff --git a/src/rust-2018-outdated/ownership-and-lifetimes/the-anonymous-lifetime.md b/src/rust-2018-outdated/ownership-and-lifetimes/the-anonymous-lifetime.md deleted file mode 100644 index aa2da7a5..00000000 --- a/src/rust-2018-outdated/ownership-and-lifetimes/the-anonymous-lifetime.md +++ /dev/null @@ -1,96 +0,0 @@ -# `'_`, the anonymous lifetime - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -Rust 2018 allows you to explicitly mark where a lifetime is elided, for types -where this elision might otherwise be unclear. To do this, you can use the -special lifetime `'_` much like you can explicitly mark that a type is inferred -with the syntax `let x: _ = ..;`. - -Let's say, for whatever reason, that we have a simple wrapper around `&'a str`: - -```rust -struct StrWrap<'a>(&'a str); -``` - -In Rust 2015, you might have written: - -```rust -# use std::fmt; -# struct StrWrap<'a>(&'a str); -// Rust 2015 - -fn make_wrapper(string: &str) -> StrWrap { - StrWrap(string) -} - -impl<'a> fmt::Debug for StrWrap<'a> { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.write_str(self.0) - } -} -``` - -In Rust 2018, you can instead write: - -```rust -# use std::fmt; -# struct StrWrap<'a>(&'a str); -// Rust 2018 - -fn make_wrapper(string: &str) -> StrWrap<'_> { - StrWrap(string) -} - -impl fmt::Debug for StrWrap<'_> { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt.write_str(self.0) - } -} -``` - -## More details - -In the Rust 2015 snippet above, we've used `-> StrWrap`. However, unless you take -a look at the definition of `StrWrap`, it is not clear that the returned value -is actually borrowing something. Therefore, starting with Rust 2018, it is -deprecated to leave off the lifetime parameters for non-reference-types (types -other than `&` and `&mut`). Instead, where you previously wrote `-> StrWrap`, -you should now write `-> StrWrap<'_>`, making clear that borrowing is occurring. - -What exactly does `'_` mean? It depends on the context! -In output contexts, as in the return type of `make_wrapper`, -it refers to a single lifetime for all "output" locations. -In input contexts, a fresh lifetime is generated for each "input location". -More concretely, to understand input contexts, consider the following example: - -```rust -// Rust 2015 - -struct Foo<'a, 'b: 'a> { - field: &'a &'b str, -} - -impl<'a, 'b: 'a> Foo<'a, 'b> { - // some methods... -} -``` - -We can rewrite this as: - -```rust -# struct Foo<'a, 'b: 'a> { -# field: &'a &'b str, -# } - -// Rust 2018 - -impl Foo<'_, '_> { - // some methods... -} -``` - -This is the same, because for each `'_`, a fresh lifetime is generated. -Finally, the relationship `'a: 'b` which the struct requires must be upheld. - -For more details, see the [tracking issue on In-band lifetime bindings](https://github.com/rust-lang/rust/issues/44524). diff --git a/src/rust-2018-outdated/platform-and-target-support/cdylib-crates-for-c-interoperability.md b/src/rust-2018-outdated/platform-and-target-support/cdylib-crates-for-c-interoperability.md deleted file mode 100644 index 5a8a394f..00000000 --- a/src/rust-2018-outdated/platform-and-target-support/cdylib-crates-for-c-interoperability.md +++ /dev/null @@ -1,18 +0,0 @@ -# cdylib crates for C interoperability - -![Minimum Rust version: 1.10](https://img.shields.io/badge/Minimum%20Rust%20Version-1.10-brightgreen.svg) for `rustc` - -![Minimum Rust version: 1.11](https://img.shields.io/badge/Minimum%20Rust%20Version-1.11-brightgreen.svg) for `cargo` - -If you're producing a library that you intend to be used from C (or another -language through a C FFI), there's no need for Rust to include Rust-specific -stuff in the final object code. For libraries like that, you'll want to use -the `cdylib` crate type in your `Cargo.toml`: - -```toml -[lib] -crate-type = ["cdylib"] -``` - -This will produce a smaller binary, with no Rust-specific information inside -of it. diff --git a/src/rust-2018-outdated/platform-and-target-support/global-allocators.md b/src/rust-2018-outdated/platform-and-target-support/global-allocators.md deleted file mode 100644 index 43f6ce8d..00000000 --- a/src/rust-2018-outdated/platform-and-target-support/global-allocators.md +++ /dev/null @@ -1,35 +0,0 @@ -# Global allocators - -![Minimum Rust version: 1.28](https://img.shields.io/badge/Minimum%20Rust%20Version-1.28-brightgreen.svg) - -Allocators are the way that programs in Rust obtain memory from the system at -runtime. Previously, Rust did not allow changing the way memory is obtained, -which prevented some use cases. On some platforms, this meant using jemalloc, -on others, the system allocator, but there was no way for users to control -this key component. With 1.28.0, the `#[global_allocator]` attribute is now -stable, which allows Rust programs to set their allocator to the system -allocator, as well as define new allocators by implementing the `GlobalAlloc` -trait. - -The default allocator for Rust programs on some platforms is jemalloc. The -standard library now provides a handle to the system allocator, which can be -used to switch to the system allocator when desired, by declaring a static -and marking it with the `#[global_allocator]` attribute. - -```rust -use std::alloc::System; - -#[global_allocator] -static GLOBAL: System = System; - -fn main() { - let mut v = Vec::new(); - // This will allocate memory using the system allocator. - v.push(1); -} -``` - -However, sometimes you want to define a custom allocator for a given -application domain. This is also relatively easy to do by implementing the -`GlobalAlloc` trait. You can read more about how to do this in [the -documentation](https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html). \ No newline at end of file diff --git a/src/rust-2018-outdated/platform-and-target-support/index.md b/src/rust-2018-outdated/platform-and-target-support/index.md deleted file mode 100644 index bf2fcdf1..00000000 --- a/src/rust-2018-outdated/platform-and-target-support/index.md +++ /dev/null @@ -1,6 +0,0 @@ -# Platform and target support - -[libcore]: libcore-for-low-level-rust.md - -In this chapter of the guide, we discuss a few improvements to platform and target support. -A notable addition to it was [that the `libcore` library now works on stable Rust][libcore]. \ No newline at end of file diff --git a/src/rust-2018-outdated/platform-and-target-support/libcore-for-low-level-rust.md b/src/rust-2018-outdated/platform-and-target-support/libcore-for-low-level-rust.md deleted file mode 100644 index fc64cba6..00000000 --- a/src/rust-2018-outdated/platform-and-target-support/libcore-for-low-level-rust.md +++ /dev/null @@ -1,31 +0,0 @@ -# libcore for low-level Rust - -![Minimum Rust version: 1.6](https://img.shields.io/badge/Minimum%20Rust%20Version-1.6-brightgreen.svg) - -Rust’s standard library is two-tiered: there’s a small core library, -`libcore`, and the full standard library, `libstd`, that builds on top of it. -`libcore` is completely platform agnostic, and requires only a handful of -external symbols to be defined. Rust’s `libstd` builds on top of `libcore`, -adding support for things like memory allocation and I/O. Applications using -Rust in the embedded space, as well as those writing operating systems, often -eschew `libstd`, using only `libcore`. - -As an additional note, while building *libraries* with `libcore` is supported -today, building full applications is not yet stable. - -To use `libcore`, add this flag to your crate root: - -```rust,ignore -#![no_std] -``` - -This will remove the standard library, and bring the `core` crate into your -namespace for use: - -```rust,ignore -#![no_std] - -use core::cell::Cell; -``` - -You can find `libcore`'s documentation [here](https://doc.rust-lang.org/core/). diff --git a/src/rust-2018-outdated/platform-and-target-support/msvc-toolchain-support.md b/src/rust-2018-outdated/platform-and-target-support/msvc-toolchain-support.md deleted file mode 100644 index 67549e55..00000000 --- a/src/rust-2018-outdated/platform-and-target-support/msvc-toolchain-support.md +++ /dev/null @@ -1,18 +0,0 @@ -# MSVC toolchain support - -![Minimum Rust version: 1.2](https://img.shields.io/badge/Minimum%20Rust%20Version-1.2-brightgreen.svg) - -At the release of Rust 1.0, we only supported the GNU toolchain on Windows. With the -release of Rust 1.2, we introduced initial support for the MSVC toolchain. After that, -as support matured, we eventually made it the default choice for Windows users. - -The difference between the two matters for interacting with C. If you're using a library -built with one toolchain or another, you need to match that with the appropriate Rust -toolchain. If you're not sure, go with MSVC; it's the default for good reason. - -To use this feature, simply use Rust on Windows, and the installer will default to it. -If you'd prefer to switch to the GNU toolchain, you can install it with Rustup: - -```console -$ rustup toolchain install stable-x86_64-pc-windows-gnu -``` \ No newline at end of file diff --git a/src/rust-2018-outdated/platform-and-target-support/musl-support-for-fully-static-binaries.md b/src/rust-2018-outdated/platform-and-target-support/musl-support-for-fully-static-binaries.md deleted file mode 100644 index 4a3752f6..00000000 --- a/src/rust-2018-outdated/platform-and-target-support/musl-support-for-fully-static-binaries.md +++ /dev/null @@ -1,45 +0,0 @@ -# MUSL support for fully static binaries - -![Minimum Rust version: 1.1](https://img.shields.io/badge/Minimum%20Rust%20Version-1.1-brightgreen.svg) - -By default, Rust will statically link all Rust code. However, if you use the -standard library, it will dynamically link to the system's `libc` -implementation. - -If you'd like a 100% static binary, the [`MUSL -libc`](https://musl.libc.org/) can be used on Linux. - -## Installing MUSL support - -To add support for MUSL, you need to choose the correct target. [The forge -has a full list of -targets](https://forge.rust-lang.org/release/platform-support.html) supported, -with a number of ones using `musl`. - -If you're not sure what you want, it's probably `x86_64-unknown-linux-musl`, -for 64-bit Linux. We'll be using this target in this guide, but the -instructions remain the same for other targets, just change the name wherever -we mention the target. - -To get support for this target, you use `rustup`: - -```console -$ rustup target add x86_64-unknown-linux-musl -``` - -This will install support for the default toolchain; to install for other toolchains, -add the `--toolchain` flag. For example: - -```console -$ rustup target add x86_64-unknown-linux-musl --toolchain=nightly -``` - -## Building with MUSL - -To use this new target, pass the `--target` flag to Cargo: - -```console -$ cargo build --target x86_64-unknown-linux-musl -``` - -The binary produced will now be built with MUSL! diff --git a/src/rust-2018-outdated/platform-and-target-support/webassembly-support.md b/src/rust-2018-outdated/platform-and-target-support/webassembly-support.md deleted file mode 100644 index 55a3a280..00000000 --- a/src/rust-2018-outdated/platform-and-target-support/webassembly-support.md +++ /dev/null @@ -1,28 +0,0 @@ -# WebAssembly support - -![Minimum Rust version: 1.14](https://img.shields.io/badge/Minimum%20Rust%20Version-1.14-brightgreen.svg) for `emscripten` - -![Minimum Rust version: nightly](https://img.shields.io/badge/Minimum%20Rust%20Version-nightly-red.svg) for `wasm32-unknown-unknown` - -Rust has gained support for [WebAssembly](https://webassembly.org/), meaning -that you can run Rust code in your browser, client-side. - -In Rust 1.14, we gained support through -[emscripten](http://kripken.github.io/emscripten-site/index.html). With it -installed, you can write Rust code and have it produce -[asm.js](http://asmjs.org/) (the precusor to wasm) and/or WebAssembly. - -Here's an example of using this support: - -```console -$ rustup target add wasm32-unknown-emscripten -$ echo 'fn main() { println!("Hello, Emscripten!"); }' > hello.rs -$ rustc --target=wasm32-unknown-emscripten hello.rs -$ node hello.js -``` - -However, in the meantime, Rust has also grown its own support, independent -from Emscripten. This is known as "the unknown target", because instead of -`wasm32-unknown-emscripten`, it's `wasm32-unknown-unknown`. This will be -the preferred target to use once it's ready, but for now, it's really -only well-supported in nightly. \ No newline at end of file diff --git a/src/rust-2018-outdated/rustdoc/documentation-tests-can-now-compile-fail.md b/src/rust-2018-outdated/rustdoc/documentation-tests-can-now-compile-fail.md deleted file mode 100644 index 7fbf4fb7..00000000 --- a/src/rust-2018-outdated/rustdoc/documentation-tests-can-now-compile-fail.md +++ /dev/null @@ -1,19 +0,0 @@ -# Documentation tests can now compile-fail - -![Minimum Rust version: 1.22](https://img.shields.io/badge/Minimum%20Rust%20Version-1.22-brightgreen.svg) - -You can now create `compile-fail` tests in Rustdoc, like this: - -```rust -/// ```compile_fail -/// let x = 5; -/// x += 2; // shouldn't compile! -/// ``` -# fn foo() {} -``` - -Please note that these kinds of tests can be more fragile than others, as -additions to Rust may cause code to compile when it previously would not. -Consider the first release with `?`, for example: code using `?` would fail -to compile on Rust 1.21, but compile successfully on Rust 1.22, causing your -test suite to start failing. diff --git a/src/rust-2018-outdated/rustdoc/index.md b/src/rust-2018-outdated/rustdoc/index.md deleted file mode 100644 index a63ee9a2..00000000 --- a/src/rust-2018-outdated/rustdoc/index.md +++ /dev/null @@ -1,6 +0,0 @@ -# `rustdoc` - -[cf]: documentation-tests-can-now-compile-fail.md - -In this chapter of the guide, we discuss a few improvements to `rustdoc`. -A notable addition to it was [that documentation tests can now compile-fail][cf]. \ No newline at end of file diff --git a/src/rust-2018-outdated/rustdoc/rustdoc-uses-commonmark.md b/src/rust-2018-outdated/rustdoc/rustdoc-uses-commonmark.md deleted file mode 100644 index c1871149..00000000 --- a/src/rust-2018-outdated/rustdoc/rustdoc-uses-commonmark.md +++ /dev/null @@ -1,16 +0,0 @@ -# Rustdoc uses CommonMark - -![Minimum Rust version: 1.25](https://img.shields.io/badge/Minimum%20Rust%20Version-1.25-brightgreen.svg) for support by default - -![Minimum Rust version: 1.23](https://img.shields.io/badge/Minimum%20Rust%20Version-1.23-red.svg) for support via a flag - -Rustdoc lets you write documentation comments in Markdown. At Rust 1.0, we -were using the `hoedown` markdown implementation, written in C. Markdown is -more of a family of implementations of an idea, and so `hoedown` had its own -dialect, like many parsers. The [CommonMark project](https://commonmark.org/) -has attempted to define a more strict version of Markdown, and so now, Rustdoc -uses it by default. - -As of Rust 1.23, we still defaulted to `hoedown`, but you could enable -Commonmark via a flag, `--enable-commonmark`. Today, we only support -CommonMark. \ No newline at end of file diff --git a/src/rust-2018-outdated/rustup-for-managing-rust-versions.md b/src/rust-2018-outdated/rustup-for-managing-rust-versions.md deleted file mode 100644 index 715f3fec..00000000 --- a/src/rust-2018-outdated/rustup-for-managing-rust-versions.md +++ /dev/null @@ -1,224 +0,0 @@ -# Rustup for managing Rust versions - -![Minimum Rust version: various](https://img.shields.io/badge/Minimum%20Rust%20Version-various-brightgreen.svg) (this tool has its own versioning scheme and works with all Rust versions) - -The [Rustup](https://rustup.rs/) tool has become *the* recommended way to -install Rust, and is advertised on our website. Its powers go further than -that though, allowing you to manage various versions, components, and -platforms. - -## For installing Rust - -To install Rust through Rustup, you can go to -, which will let you know how to do -so on your platform. This will install both `rustup` itself and the `stable` -version of `rustc` and `cargo`. - -To install a specific Rust version, you can use `rustup toolchain install`: - -```console -$ rustup toolchain install 1.30.0 -``` - -This works for a specific nightly, as well: - -```console -$ rustup toolchain install nightly-2018-08-01 -``` - -As well as any of our release channels: - -```console -$ rustup toolchain install stable -$ rustup toolchain install beta -$ rustup toolchain install nightly -``` - -## For updating your installation - -To update all of the various channels you may have installed: - -```console -$ rustup update -``` - -This will look at everything you've installed, and if there are new releases, -will update anything that has one. - -## Managing versions - -To set the default toolchain to something other than `stable`: - -```console -$ rustup default nightly -``` - -To uninstall a specific Rust version, you can use `rustup toolchain uninstall`: - -```console -$ rustup toolchain uninstall 1.30.0 -``` - -To use a toolchain other than the default, use `rustup run`: - -```console -$ rustup run nightly cargo build -``` - -There's also an alias for this that's a little shorter: - -```console -$ cargo +nightly build -``` - -If you'd like to have a different default per-directory, that's easy too! -If you run this inside of a project: - -```console -$ rustup override set nightly -``` - -Or, if you'd like to target a different version of Rust: -```console -$ rustup override set 1.30.0 -``` - -Then when you're in that directory, any invocations of `rustc` or `cargo` -will use that toolchain. To share this with others, you can create a -`rust-toolchain` file with the contents of a toolchain, and check it into -source control. Now, when someone clones your project, they'll get the -right version without needing to `override set` themselves. - -## Installing other targets - -Rust supports cross-compiling to other targets, and Rustup can help you -manage them. For example, to use MUSL: - -```console -$ rustup target add x86_64-unknown-linux-musl -``` - -And then you can - -```console -$ cargo build --target=x86_64-unknown-linux-musl -``` - -To see the full list of targets you can install: - -```console -$ rustup target list -``` - -## Installing components - -Components are used to install certain kinds of tools. While `cargo-install` -has you covered for most tools, some tools need deep integration into the -compiler. Rustup knows exactly what version of the compiler you're using, and -so it's got just the information that these tools need. - -Components are per-toolchain, so if you want them to be available to more -than one toolchain, you'll need to install them multiple times. In the -following examples, add a `--toolchain` flag, set to the toolchain you -want to install for, `nightly` for example. Without this flag, it will -install the component for the default toolchain. - -To see the full list of components you can install: - -```console -$ rustup component list -``` - -Next, let's talk about some popular components and when you might want to -install them. - -### `rust-docs`, for local documentation - -This first component is installed by default when you install a toolchain. It -contains a copy of Rust's documentation, so that you can read it offline. - -This component cannot be removed for now; if that's of interest, please -comment on [this -issue](https://github.com/rust-lang/rustup.rs/issues/998). - -### `rust-src` for a copy of Rust's source code - -The `rust-src` component can give you a local copy of Rust's source code. Why -might you need this? Well, autocompletion tools like Racer use this -information to know more about the functions you're trying to call. - -```console -$ rustup component add rust-src -``` - -### `rustfmt` for automatic code formatting - -![Minimum Rust version: 1.24](https://img.shields.io/badge/Minimum%20Rust%20Version-1.24-brightgreen.svg) - -If you'd like to have your code automatically formatted, you can -install this component: - -```console -$ rustup component add rustfmt -``` - -This will install two tools, `rustfmt` and `cargo-fmt`, that will reformat your -code for you! For example: - -```console -$ cargo fmt -``` - -will reformat your entire Cargo project. - -### `rls` for IDE integration - -![Minimum Rust version: 1.21](https://img.shields.io/badge/Minimum%20Rust%20Version-1.21-brightgreen.svg) - -Many IDE features are built off of the [`langserver` -protocol](http://langserver.org/). To gain support for Rust with these IDEs, -you'll need to install the Rust language sever, aka the "RLS": - -```console -$ rustup component add rls -``` - -For more information about integrating this into your IDE, see the [RLS -documentation](https://github.com/rust-lang/rls). - -### `clippy` for more lints - -For even more lints to help you write Rust code, you can install `clippy`: - -```console -$ rustup component add clippy -``` - -This will install `cargo-clippy` for you: - -```console -$ cargo clippy -``` - -For more, check out [clippy's -documentation](https://github.com/rust-lang/rust-clippy). - -### The "preview" components - -There are several components in a "preview" stage. These components currently -have `-preview` in their name, and this indicates that they're not quite 100% -ready for general consumption yet. Please try them out and give us feedback, -but know that they do not follow Rust's stability guarantees, and are still -actively changing, possibly in backwards-incompatible ways. - -#### `llvm-tools-preview` for using extra LLVM tools - -If you'd like to use the `lld` linker, or other tools like `llvm-objdump` or -`llvm-objcopy`, you can install this component: - -```console -$ rustup component add llvm-tools-preview -``` - -This is the newest component, and so doesn't have good documentation at the -moment. diff --git a/src/rust-2018-outdated/simd-for-faster-computing.md b/src/rust-2018-outdated/simd-for-faster-computing.md deleted file mode 100644 index b7943eb0..00000000 --- a/src/rust-2018-outdated/simd-for-faster-computing.md +++ /dev/null @@ -1,108 +0,0 @@ -# SIMD for faster computing - -![Minimum Rust version: 1.27](https://img.shields.io/badge/Minimum%20Rust%20Version-1.27-brightgreen.svg) - -The basics of [SIMD](https://en.wikipedia.org/wiki/SIMD) are now available! -SIMD stands for “single instruction, multiple data.” Consider a function like -this: - -```rust -pub fn foo(a: &[u8], b: &[u8], c: &mut [u8]) { - for ((a, b), c) in a.iter().zip(b).zip(c) { - *c = *a + *b; - } -} -``` - -Here, we’re taking two slices, and adding the numbers together, placing the -result in a third slice. The simplest possible way to do this would be to do -exactly what the code does, and loop through each set of elements, add them -together, and store it in the result. However, compilers can often do better. -LLVM will usually “autovectorize” code like this, which is a fancy term for -“use SIMD.” Imagine that `a` and `b` were both 16 elements long. Each element -is a `u8`, and so that means that each slice would be 128 bits of data. Using -SIMD, we could put both `a` and `b` into 128 bit registers, add them together -in a *single* instruction, and then copy the resulting 128 bits into `c`. -That’d be much faster! - -While stable Rust has always been able to take advantage of -autovectorization, sometimes, the compiler just isn’t smart enough to realize -that we can do something like this. Additionally, not every CPU has these -features, and so LLVM may not use them so your program can be used on a wide -variety of hardware. The `std::arch` module allows us to use these kinds of -instructions directly, which means we don’t need to rely on a smart compiler. -Additionally, it includes some features that allow us to choose a particular -implementation based on various criteria. For example: - -```rust,ignore -#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), - target_feature = "avx2"))] -fn foo() { - #[cfg(target_arch = "x86")] - use std::arch::x86::_mm256_add_epi64; - #[cfg(target_arch = "x86_64")] - use std::arch::x86_64::_mm256_add_epi64; - - unsafe { - _mm256_add_epi64(...); - } -} -``` - -Here, we use cfg flags to choose the correct version based on the machine -we’re targeting; on x86 we use that version, and on x86_64 we use its -version. We can also choose at runtime: - -```rust,ignore -fn foo() { - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - { - if is_x86_feature_detected!("avx2") { - return unsafe { foo_avx2() }; - } - } - - foo_fallback(); -} -``` - -Here, we have two versions of the function: one which uses AVX2, a specific -kind of SIMD feature that lets you do 256-bit operations. The -`is_x86_feature_detected!` macro will generate code that detects if your CPU -supports AVX2, and if so, calls the foo_avx2 function. If not, then we fall -back to a non-AVX implementation, foo_fallback. This means that our code will -run super fast on CPUs that support AVX2, but still work on ones that don’t, -albeit slower. - -If all of this seems a bit low-level and fiddly, well, it is! `std::arch` is -specifically primitives for building these kinds of things. We hope to -eventually stabilize a `std::simd` module with higher-level stuff in the -future. But landing the basics now lets the ecosystem experiment with higher -level libraries starting today. For example, check out the -[faster](https://github.com/AdamNiederer/faster) crate. Here’s a code snippet -with no SIMD: - -```rust,ignore -let lots_of_3s = (&[-123.456f32; 128][..]).iter() - .map(|v| { - 9.0 * v.abs().sqrt().sqrt().recip().ceil().sqrt() - 4.0 - 2.0 - }) - .collect::>(); -``` - -To use SIMD with this code via faster, you’d change it to this: - -```rust,ignore -let lots_of_3s = (&[-123.456f32; 128][..]).simd_iter() - .simd_map(f32s(0.0), |v| { - f32s(9.0) * v.abs().sqrt().rsqrt().ceil().sqrt() - f32s(4.0) - f32s(2.0) - }) - .scalar_collect(); -``` - -It looks almost the same: `simd_iter` instead of `iter`, `simd_map` instead of `map`, -`f32s(2.0)` instead of `2.0`. But you get a SIMD-ified version generated for you. - -Beyond that, you may never write any of this yourself, but as always, the -libraries you depend on may. For example, the regex crate contains these SIMD -speedups without you needing to do anything at all! diff --git a/src/rust-2018-outdated/slice-patterns.md b/src/rust-2018-outdated/slice-patterns.md deleted file mode 100644 index a69dba15..00000000 --- a/src/rust-2018-outdated/slice-patterns.md +++ /dev/null @@ -1,91 +0,0 @@ -# Slice patterns - -![Minimum Rust version: 1.26](https://img.shields.io/badge/Minimum%20Rust%20Version-1.26-brightgreen.svg) - -Have you ever tried to pattern match on the contents and structure of a slice? -Rust 2018 will let you do just that. - -For example, say we want to accept a list of names and respond to that with a -greeting. With slice patterns, we can do that easy as pie with: - -```rust -fn main() { - greet(&[]); - // output: Bummer, there's no one here :( - greet(&["Alan"]); - // output: Hey, there Alan! You seem to be alone. - greet(&["Joan", "Hugh"]); - // output: Hello, Joan and Hugh. Nice to see you are exactly 2! - greet(&["John", "Peter", "Stewart"]); - // output: Hey everyone, we seem to be 3 here today. -} - -fn greet(people: &[&str]) { - match people { - [] => println!("Bummer, there's no one here :("), - [only_one] => println!("Hey, there {}! You seem to be alone.", only_one), - [first, second] => println!( - "Hello, {} and {}. Nice to see you are exactly 2!", - first, second - ), - _ => println!("Hey everyone, we seem to be {} here today.", people.len()), - } -} -``` - -Now, you don't have to check the length first. - -We can also match on arrays like so: - -```rust -let arr = [1, 2, 3]; - -assert_eq!("ends with 3", match arr { - [_, _, 3] => "ends with 3", - [a, b, c] => "ends with something else", -}); -``` - -## More details - -### Exhaustive patterns - -In the first example, note in particular the `_ => ...` pattern. -Since we are matching on a slice, it could be of any length, so we need a -*"catch all pattern"* to handle it. If we forgot the `_ => ...` or -`identifier => ...` pattern, we would instead get an error saying: - -```ignore -error[E0004]: non-exhaustive patterns: `&[_, _, _]` not covered -``` - -If we added a case for a slice of size `3` we would instead get: - -```ignore -error[E0004]: non-exhaustive patterns: `&[_, _, _, _]` not covered -``` - -and so on... - -### Arrays and exact lengths - -In the second example above, since arrays in Rust are of known lengths, -we have to match on exactly three elements. -If we try to match on 2 or 4 elements,we get the errors: - -```ignore -error[E0527]: pattern requires 2 elements but array has 3 -``` - -and - -```ignore -error[E0527]: pattern requires 4 elements but array has 3 -``` - -### In the pipeline - -[the tracking issue]: https://github.com/rust-lang/rust/issues/23121 - -When it comes to slice patterns, more advanced forms are planned but -have not been stabilized yet. To learn more, follow [the tracking issue]. diff --git a/src/rust-2018-outdated/the-compiler/an-attribute-for-deprecation.md b/src/rust-2018-outdated/the-compiler/an-attribute-for-deprecation.md deleted file mode 100644 index d414dbaa..00000000 --- a/src/rust-2018-outdated/the-compiler/an-attribute-for-deprecation.md +++ /dev/null @@ -1,35 +0,0 @@ -# An attribute for deprecation - -![Minimum Rust version: 1.9](https://img.shields.io/badge/Minimum%20Rust%20Version-1.9-brightgreen.svg) - -If you're writing a library, and you'd like to deprecate something, you can -use the `deprecated` attribute: - -```rust -#[deprecated( - since = "0.2.1", - note = "Please use the bar function instead" -)] -pub fn foo() { - // ... -} -``` - -This will give your users a warning if they use the deprecated functionality: - -```text - Compiling playground v0.0.1 (file:///playground) -warning: use of deprecated item 'foo': Please use the bar function instead - --> src/main.rs:10:5 - | -10 | foo(); - | ^^^ - | - = note: #[warn(deprecated)] on by default - -``` - -Both `since` and `note` are optional. - -`since` can be in the future; you can put whatever you'd like, and what's put in -there isn't checked. diff --git a/src/rust-2018-outdated/the-compiler/improved-error-messages.md b/src/rust-2018-outdated/the-compiler/improved-error-messages.md deleted file mode 100644 index 711d0099..00000000 --- a/src/rust-2018-outdated/the-compiler/improved-error-messages.md +++ /dev/null @@ -1,50 +0,0 @@ -# Improved error messages - -![Minimum Rust version: 1.12](https://img.shields.io/badge/Minimum%20Rust%20Version-1.12-brightgreen.svg) - -We're always working on error improvements, and there are little improvements -in almost every Rust version, but in Rust 1.12, a significant overhaul of the -error message system was created. - -For example, here's some code that produces an error: - -```rust,compile_fail -fn main() { - let mut x = 5; - let y = &x; - x += 1; - println!("{} {}", x, y); -} -``` - -Here's the error in Rust 1.11: - -```text -foo.rs:4:5: 4:11 error: cannot assign to `x` because it is borrowed [E0506] -foo.rs:4 x += 1; - ^~~~~~ -foo.rs:3:14: 3:15 note: borrow of `x` occurs here -foo.rs:3 let y = &x; - ^ -foo.rs:4:5: 4:11 help: run `rustc --explain E0506` to see a detailed explanation -error: aborting due to previous error -``` - -Here's the error in Rust 1.28: - -```text -error[E0506]: cannot assign to `x` because it is borrowed - --> foo.rs:4:5 - | -3 | let y = &x; - | - borrow of `x` occurs here -4 | x += 1; - | ^^^^^^ assignment to borrowed `x` occurs here - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0506`. -``` - -This error isn't terribly different, but shows off how the format has changed. It shows -off your code in context, rather than just showing the text of the lines themselves. diff --git a/src/rust-2018-outdated/the-compiler/incremental-compilation-for-faster-compiles.md b/src/rust-2018-outdated/the-compiler/incremental-compilation-for-faster-compiles.md deleted file mode 100644 index 8ce7a3c9..00000000 --- a/src/rust-2018-outdated/the-compiler/incremental-compilation-for-faster-compiles.md +++ /dev/null @@ -1,23 +0,0 @@ -# Incremental Compilation - -![Minimum Rust version: 1.24](https://img.shields.io/badge/Minimum%20Rust%20Version-1.24-brightgreen.svg) - -Back in September of 2016, we [blogged about Incremental -Compilation](https://blog.rust-lang.org/2016/09/08/incremental.html). While -that post goes into the details, the idea is basically this: when you’re -working on a project, you often compile it, then change something small, then -compile again. Historically, the compiler has compiled your entire project, -no matter how little you’ve changed the code. The idea with incremental -compilation is that you only need to compile the code you’ve actually -changed, which means that that second build is faster. - -This is now turned on by default. This means that your builds should be -faster! Don’t forget about `cargo check` when trying to get the lowest possible -build times. - -This is still not the end story for compiler performance generally, nor -incremental compilation specifically. We have a lot more work planned in the -future. - -One small note about this change: it makes builds faster, but makes the final -binary a bit slower. For this reason, it's not turned on in release builds. \ No newline at end of file diff --git a/src/rust-2018-outdated/the-compiler/index.md b/src/rust-2018-outdated/the-compiler/index.md deleted file mode 100644 index c4637577..00000000 --- a/src/rust-2018-outdated/the-compiler/index.md +++ /dev/null @@ -1,6 +0,0 @@ -# The compiler - -[errors]: improved-error-messages.md - -In this chapter of the guide, we discuss a few improvements to the compiler. -A notable addition here is our new and [improved error messages][errors]. \ No newline at end of file diff --git a/src/rust-2018-outdated/trait-system/associated-constants.md b/src/rust-2018-outdated/trait-system/associated-constants.md deleted file mode 100644 index 26564943..00000000 --- a/src/rust-2018-outdated/trait-system/associated-constants.md +++ /dev/null @@ -1,117 +0,0 @@ -# Associated constants - -![Minimum Rust version: 1.20](https://img.shields.io/badge/Minimum%20Rust%20Version-1.20-brightgreen.svg) - -You can define traits, structs, and enums that have “associated functions”: - -```rust -struct Struct; - -impl Struct { - fn foo() { - println!("foo is an associated function of Struct"); - } -} - -fn main() { - Struct::foo(); -} -``` - -These are called “associated functions” because they are functions that are -associated with the type, that is, they’re attached to the type itself, and -not any particular instance. - -Rust 1.20 adds the ability to define “associated constants” as well: - -```rust -struct Struct; - -impl Struct { - const ID: u32 = 0; -} - -fn main() { - println!("the ID of Struct is: {}", Struct::ID); -} -``` - -That is, the constant `ID` is associated with `Struct`. Like functions, -associated constants work with traits and enums as well. - -Traits have an extra ability with associated constants that gives them some -extra power. With a trait, you can use an associated constant in the same way -you’d use an associated type: by declaring it, but not giving it a value. The -implementor of the trait then declares its value upon implementation: - -```rust -trait Trait { - const ID: u32; -} - -struct Struct; - -impl Trait for Struct { - const ID: u32 = 5; -} - -fn main() { - println!("{}", Struct::ID); -} -``` - -Before this feature, if you wanted to make a trait that represented floating -point numbers, you’d have to write this: - -```rust -trait Float { - fn nan() -> Self; - fn infinity() -> Self; - // ... -} -``` - -This is slightly unwieldy, but more importantly, because they’re functions, -they cannot be used in constant expressions, even though they only return a -constant. Because of this, a design for `Float` would also have to include -constants as well: - -```rust,ignore -mod f32 { - const NAN: f32 = 0.0f32 / 0.0f32; - const INFINITY: f32 = 1.0f32 / 0.0f32; - - impl Float for f32 { - fn nan() -> Self { - f32::NAN - } - fn infinity() -> Self { - f32::INFINITY - } - } -} -``` - -Associated constants let you do this in a much cleaner way. This trait -definition: - -```rust -trait Float { - const NAN: Self; - const INFINITY: Self; - // ... -} -``` - -Leads to this implementation: - -```rust,ignore -mod f32 { - impl Float for f32 { - const NAN: f32 = 0.0f32 / 0.0f32; - const INFINITY: f32 = 1.0f32 / 0.0f32; - } -} -``` - -much cleaner, and more versatile. diff --git a/src/rust-2018-outdated/trait-system/dyn-trait-for-trait-objects.md b/src/rust-2018-outdated/trait-system/dyn-trait-for-trait-objects.md deleted file mode 100644 index d6e62a26..00000000 --- a/src/rust-2018-outdated/trait-system/dyn-trait-for-trait-objects.md +++ /dev/null @@ -1,42 +0,0 @@ -# `dyn Trait` for trait objects - -![Minimum Rust version: 1.27](https://img.shields.io/badge/Minimum%20Rust%20Version-1.27-brightgreen.svg) - -The `dyn Trait` feature is the new syntax for using trait objects. In short: - -* `Box` becomes `Box` -* `&Trait` and `&mut Trait` become `&dyn Trait` and `&mut dyn Trait` - -And so on. In code: - -```rust -trait Trait {} - -impl Trait for i32 {} - -// old -fn function1() -> Box { -# unimplemented!() -} - -// new -fn function2() -> Box { -# unimplemented!() -} -``` - -That's it! - -## More details - -Using just the trait name for trait objects turned out to be a bad decision. -The current syntax is often ambiguous and confusing, even to veterans, -and favors a feature that is not more frequently used than its alternatives, -is sometimes slower, and often cannot be used at all when its alternatives can. - -Furthermore, with `impl Trait` arriving, "`impl Trait` vs `dyn Trait`" is much -more symmetric, and therefore a bit nicer, than "`impl Trait` vs `Trait`". -`impl Trait` is explained [here](impl-trait-for-returning-complex-types-with-ease.md). - -In the new edition, you should therefore prefer `dyn Trait` to just `Trait` -where you need a trait object. \ No newline at end of file diff --git a/src/rust-2018-outdated/trait-system/impl-trait-for-returning-complex-types-with-ease.md b/src/rust-2018-outdated/trait-system/impl-trait-for-returning-complex-types-with-ease.md deleted file mode 100644 index 87efbfe7..00000000 --- a/src/rust-2018-outdated/trait-system/impl-trait-for-returning-complex-types-with-ease.md +++ /dev/null @@ -1,168 +0,0 @@ -# `impl Trait` for returning complex types with ease - -![Minimum Rust version: 1.26](https://img.shields.io/badge/Minimum%20Rust%20Version-1.26-brightgreen.svg) - -`impl Trait` is the new way to specify unnamed but concrete types that -implement a specific trait. There are two places you can put it: argument -position, and return position. - -```rust,ignore -trait Trait {} - -// argument position -fn foo(arg: impl Trait) { -} - -// return position -fn foo() -> impl Trait { -} -``` - -## Argument Position - -In argument position, this feature is quite simple. These two forms are -almost the same: - -```rust,ignore -trait Trait {} - -fn foo(arg: T) { -} - -fn foo(arg: impl Trait) { -} -``` - -That is, it's a slightly shorter syntax for a generic type parameter. It -means, "`arg` is an argument that takes any type that implements the `Trait` -trait." - -However, there's also an important technical difference between `T: Trait` -and `impl Trait` here. When you write the former, you can specify the type of -`T` at the call site with turbo-fish syntax as with `foo::(1)`. In the -case of `impl Trait`, if it is used anywhere in the function definition, then -you can't use turbo-fish at all. Therefore, you should be mindful that -changing both from and to `impl Trait` can constitute a breaking change for -the users of your code. - -## Return Position - -In return position, this feature is more interesting. It means "I am -returning some type that implements the `Trait` trait, but I'm not going to -tell you exactly what the type is." Before `impl Trait`, you could do this -with trait objects: - -```rust -trait Trait {} - -impl Trait for i32 {} - -fn returns_a_trait_object() -> Box { - Box::new(5) -} -``` - -However, this has some overhead: the `Box` means that there's a heap -allocation here, and this will use dynamic dispatch. See the `dyn Trait` -section for an explanation of this syntax. But we only ever return one -possible thing here, the `Box`. This means that we're paying for dynamic -dispatch, even though we don't use it! - -With `impl Trait`, the code above could be written like this: - -```rust -trait Trait {} - -impl Trait for i32 {} - -fn returns_a_trait_object() -> impl Trait { - 5 -} -``` - -Here, we have no `Box`, no trait object, and no dynamic dispatch. But we -still can obscure the `i32` return type. - -With `i32`, this isn't super useful. But there's one major place in Rust -where this is much more useful: closures. - -### `impl Trait` and closures - -> If you need to catch up on closures, check out [their chapter in the -> book](https://doc.rust-lang.org/book/second-edition/ch13-01-closures.html). - -In Rust, closures have a unique, un-writable type. They do implement the `Fn` -family of traits, however. This means that previously, the only way to return -a closure from a function was to use a trait object: - -```rust -fn returns_closure() -> Box i32> { - Box::new(|x| x + 1) -} -``` - -You couldn't write the type of the closure, only use the `Fn` trait. That means -that the trait object is necessary. However, with `impl Trait`: - -```rust -fn returns_closure() -> impl Fn(i32) -> i32 { - |x| x + 1 -} -``` - -We can now return closures by value, just like any other type! - -## More details - -The above is all you need to know to get going with `impl Trait`, but for -some more nitty-gritty details: type parameters and `impl Trait` work -slightly differently when they're in argument position versus return -position. Consider this function: - -```rust,ignore -fn foo(x: T) { -``` - -When you call it, you set the type, `T`. "you" being the caller here. This -signature says "I accept any type that implements `Trait`." ("any type" == -universal in the jargon) - -This version: - -```rust,ignore -fn foo() -> T { -``` - -is similar, but also different. You, the caller, provide the type you want, -`T`, and then the function returns it. You can see this in Rust today with -things like parse or collect: - -```rust,ignore -let x: i32 = "5".parse()?; -let x: u64 = "5".parse()?; -``` - -Here, `.parse` has this signature: - -```rust,ignore -pub fn parse(&self) -> Result::Err> where - F: FromStr, -``` - -Same general idea, though with a result type and `FromStr` has an associated -type... anyway, you can see how `F` is in the return position here. So you -have the ability to choose. - -With `impl Trait`, you're saying "hey, some type exists that implements this -trait, but I'm not gonna tell you what it is." So now, the caller can't -choose, and the function itself gets to choose. If we tried to define parse -with `Result`, one of Rust's reference-counted types: - -```rust -use std::rc::Rc; - -trait Foo {} - -impl Foo for i32 { - -} - -fn main() { - let obj: Rc = Rc::new(5); -} -``` - -This code would not work with Rust 1.0, but now works. - -> If you haven't seen the `dyn` syntax before, see [the section on -> it](dyn-trait-for-trait-objects.md). For versions that do not support it, replace `Rc` -> with `Rc`. diff --git a/src/rust-2018-outdated/trait-system/no-anon-params.md b/src/rust-2018-outdated/trait-system/no-anon-params.md deleted file mode 100644 index c0607516..00000000 --- a/src/rust-2018-outdated/trait-system/no-anon-params.md +++ /dev/null @@ -1,23 +0,0 @@ -# No more anonymous trait parameters - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -In accordance with RFC [#1685](https://github.com/rust-lang/rfcs/pull/1685), -parameters in trait method declarations are no longer allowed to be anonymous. - -For example, in the 2015 edition, this was allowed: - -```rust -trait Foo { - fn foo(&self, u8); -} -``` - -In the 2018 edition, all parameters must be given an argument name (even if it's just -`_`): - -```rust -trait Foo { - fn foo(&self, baz: u8); -} -``` diff --git a/src/rust-next/alloc.md b/src/rust-next/alloc.md deleted file mode 100644 index 036328d8..00000000 --- a/src/rust-next/alloc.md +++ /dev/null @@ -1,28 +0,0 @@ -# The alloc crate - -Initially added: ![Minimum Rust version: 1.36](https://img.shields.io/badge/Minimum%20Rust%20Version-1.36-brightgreen.svg) - -Before 1.36.0, the standard library consisted of the crates `std`, `core`, and `proc_macro`. -The `core` crate provided core functionality such as `Iterator` and `Copy` -and could be used in `#![no_std]` environments since it did not impose any requirements. -Meanwhile, the `std` crate provided types like `Box` and OS functionality -but required a global allocator and other OS capabilities in return. - -Starting with Rust 1.36.0, the parts of `std` that depend on a global allocator, e.g. `Vec`, -are now available in the `alloc` crate. The `std` crate then re-exports these parts. -While `#![no_std]` *binaries* using `alloc` still require nightly Rust, -`#![no_std]` *library* crates can use the `alloc` crate in stable Rust. -Meanwhile, normal binaries, without `#![no_std]`, can depend on such library crates. -We hope this will facilitate the development of a `#![no_std]` compatible ecosystem of libraries -prior to stabilizing support for `#![no_std]` binaries using `alloc`. - -If you are the maintainer of a library that only relies on some allocation primitives to function, -consider making your library `#[no_std]` compatible by using the following at the top of your `lib.rs` file: - -```rust,ignore -#![no_std] - -extern crate alloc; - -use alloc::vec::Vec; -``` diff --git a/src/rust-next/alternative-cargo-registries.md b/src/rust-next/alternative-cargo-registries.md deleted file mode 100644 index 84e70672..00000000 --- a/src/rust-next/alternative-cargo-registries.md +++ /dev/null @@ -1,26 +0,0 @@ -# Alternative Cargo registries - -Initially added: ![Minimum Rust version: 1.34](https://img.shields.io/badge/Minimum%20Rust%20Version-1.34-brightgreen.svg) - -For various reasons, you may not want to publish code to crates.io, but you -may want to share it with others. For example, maybe your company writes Rust -code that's not open source, but you'd still like to use these internal -packages. - -Cargo supports alternative registries by settings in `.cargo/config`: - -```toml -[registries] -my-registry = { index = "https://my-intranet:7878/git/index" } -``` - -When you want to depend on a package from another registry, you add that -in to your `Cargo.toml`: - -```toml -[dependencies] -other-crate = { version = "1.0", registry = "my-registry" } -``` - -To learn more, check out the [registries section of the Cargo -book](https://doc.rust-lang.org/nightly/cargo/reference/registries.html). diff --git a/src/rust-next/cargo-vendor.md b/src/rust-next/cargo-vendor.md deleted file mode 100644 index 7ef779b2..00000000 --- a/src/rust-next/cargo-vendor.md +++ /dev/null @@ -1,9 +0,0 @@ -# cargo vendor - -Initially added: ![Minimum Rust version: 1.37](https://img.shields.io/badge/Minimum%20Rust%20Version-1.37-brightgreen.svg) - -After being available [as a separate crate][vendor-crate] for years, the `cargo vendor` command is now integrated directly into Cargo. The command fetches all your project's dependencies unpacking them into the `vendor/` directory, and shows the configuration snippet required to use the vendored code during builds. - -There are multiple cases where `cargo vendor` is already used in production: the Rust compiler `rustc` uses it to ship all its dependencies in release tarballs, and projects with monorepos use it to commit the dependencies' code in source control. - -[vendor-crate]: https://crates.io/crates/cargo-vendor diff --git a/src/rust-next/const-fn.md b/src/rust-next/const-fn.md deleted file mode 100644 index 13bb50bc..00000000 --- a/src/rust-next/const-fn.md +++ /dev/null @@ -1,241 +0,0 @@ -# `const fn` - -Initially added: ![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -Expanded in many releases, see each aspect below for more details. - -A `const fn` allows you to execute code in a "const context." For example: - -```rust -const fn five() -> i32 { - 5 -} - -const FIVE: i32 = five(); -``` - -You cannot execute arbitrary code; the reasons why boil down to "you can -destroy the type system." The details are a bit too much to put here, but the -core idea is that `const fn` started off allowing the absolutely minimal -subset of the language, and has slowly added more abilities over time. -Therefore, while you can create a `const fn` in Rust 1.31, you cannot do much -with it. This is why we didn't add `const fn` to the Rust 2018 section; it -truly didn't become useful until after the release of the 2018 edition. This -means that if you read this document top to bottom, the earlier versions may -describe restrictions that are relaxed in later versions. - -Additionally, this has allowed more and more of the standard library to be -made `const`, we won't put all of those changes here, but you should know -that it is becoming more `const` over time. - -## Arithmetic and comparison operators on integers - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -You can do arithmetic on integer literals: - -```rust -const fn foo() -> i32 { - 5 + 6 -} -``` - -## Many boolean operators - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -You can use boolean operators other than `&&` and `||`, because they short-circut evaluation: - -```rust -const fn mask(val: u8) -> u8 { - let mask = 0x0f; - - mask & val -} -``` - -## Constructing arrays, structs, enums, and tuples - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -You can create arrays, structs, enums, and tuples: - -```rust -struct Point { - x: i32, - y: i32, -} - -enum Error { - Incorrect, - FileNotFound, -} - -const fn foo() { - let array = [1, 2, 3]; - - let point = Point { - x: 5, - y: 10, - }; - - let error = Error::FileNotFound; - - let tuple = (1, 2, 3); -} -``` - -## Calls to other const fns - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -You can call `const fn` from a `const fn`: - - -```rust -const fn foo() -> i32 { - 5 -} - -const fn bar() -> i32 { - foo() -} -``` - -## Index expressions on arrays and slices - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -You can index into an array or slice: - -```rust -const fn foo() -> i32 { - let array = [1, 2, 3]; - - array[1] -} -``` - -## Field accesses on structs and tuples - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -You can access parts of a struct or tuple: - -```rust -struct Point { - x: i32, - y: i32, -} - -const fn foo() { - let point = Point { - x: 5, - y: 10, - }; - - let tuple = (1, 2, 3); - - point.x; - tuple.0; -} -``` - -## Reading from constants - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -You can read from a constant: - -```rust -const FOO: i32 = 5; - -const fn foo() -> i32 { - FOO -} -``` - -Note that this is *only* `const`, not `static`. - -## & and * of references - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -You can create and de-reference references: - -```rust -const fn foo(r: &i32) { - *r; - - &5; -} -``` - -## Casts, except for raw pointer to integer casts - -![Minimum Rust version: 1.31](https://img.shields.io/badge/Minimum%20Rust%20Version-1.31-brightgreen.svg) - -You may cast things, except for raw pointers may not be casted to an integer: - -```rust -const fn foo() { - let x: usize = 5; - - x as i32; -} -``` - -## Irrefutable destructuring patterns - -![Minimum Rust version: 1.33](https://img.shields.io/badge/Minimum%20Rust%20Version-1.33-brightgreen.svg) - -You can use irrefutable patterns that destructure values. For example: - -```rust -const fn foo((x, y): (u8, u8)) { - // ... -} -``` - -Here, `foo` destructures the tuple into `x` and `y`. `if let` is another -place that uses irrefutable patterns. - -## `let` bindings - -![Minimum Rust version: 1.33](https://img.shields.io/badge/Minimum%20Rust%20Version-1.33-brightgreen.svg) - -You can use both mutable and immutable `let` bindings: - -```rust -const fn foo() { - let x = 5; - let mut y = 10; -} -``` - -## Assignment - -![Minimum Rust version: 1.33](https://img.shields.io/badge/Minimum%20Rust%20Version-1.33-brightgreen.svg) - -You can use assignment and assignment operators: - -```rust -const fn foo() { - let mut x = 5; - x = 10; -} -``` - -## Calling `unsafe fn` - -![Minimum Rust version: 1.33](https://img.shields.io/badge/Minimum%20Rust%20Version-1.33-brightgreen.svg) - -You can call an `unsafe fn` inside a `const fn`: - -```rust -const unsafe fn foo() -> i32 { 5 } - -const fn bar() -> i32 { - unsafe { foo() } -} -``` diff --git a/src/rust-next/dbg-macro.md b/src/rust-next/dbg-macro.md deleted file mode 100644 index a2ac7ad8..00000000 --- a/src/rust-next/dbg-macro.md +++ /dev/null @@ -1,104 +0,0 @@ -# The dbg! macro - -![Minimum Rust version: 1.32](https://img.shields.io/badge/Minimum%20Rust%20Version-1.32-brightgreen.svg) - -The `dbg!` macro provides a nicer experience for debugging than `println!`: - -```rust -fn main() { - let x = 5; - - dbg!(x); -} -``` - -If you run this program, you'll see: - -```text -[src/main.rs:4] x = 5 -``` - -You get the file and line number of where this was invoked, as well as the -name and value. Additionally, `println!` prints to the standard output, so you -really should be using `eprintln!` to print to standard error. `dbg!` does the -right thing and goes to stderr. - -It even works in more complex circumstances. Consider this factorial example: - -```rust -fn factorial(n: u32) -> u32 { - if n <= 1 { - n - } else { - n * factorial(n - 1) - } -} -``` - -If we wanted to debug this, we might write it like this with `eprintln!`: - -```rust -fn factorial(n: u32) -> u32 { - eprintln!("n: {}", n); - - if n <= 1 { - eprintln!("n <= 1"); - - n - } else { - let n = n * factorial(n - 1); - - eprintln!("n: {}", n); - - n - } -} -``` - -We want to log `n` on each iteration, as well as have some kind of context -for each of the branches. We see this output for `factorial(4)`: - -```text -n: 4 -n: 3 -n: 2 -n: 1 -n <= 1 -n: 2 -n: 6 -n: 24 -``` - -This is servicable, but not particularly great. Maybe we could work on how we -print out the context to make it more clear, but now we're not debugging our -code, we're figuring out how to make our debugging code better. - -Consider this version using `dbg!`: - -```rust -fn factorial(n: u32) -> u32 { - if dbg!(n <= 1) { - dbg!(1) - } else { - dbg!(n * factorial(n - 1)) - } -} -``` - -We simply wrap each of the various expressions we want to print with the macro. We get this output instead: - -```text -[src/main.rs:3] n <= 1 = false -[src/main.rs:3] n <= 1 = false -[src/main.rs:3] n <= 1 = false -[src/main.rs:3] n <= 1 = true -[src/main.rs:4] 1 = 1 -[src/main.rs:5] n * factorial(n - 1) = 2 -[src/main.rs:5] n * factorial(n - 1) = 6 -[src/main.rs:5] n * factorial(n - 1) = 24 -[src/main.rs:11] factorial(4) = 24 -``` - -Because the `dbg!` macro returns the value of what it's debugging, instead of -`eprintln!` which returns `()`, we need to make no changes to the structure of -our code. Additionally, we have vastly more useful output. diff --git a/src/rust-next/edition-changes.md b/src/rust-next/edition-changes.md deleted file mode 100644 index 58475292..00000000 --- a/src/rust-next/edition-changes.md +++ /dev/null @@ -1,3 +0,0 @@ -# Next-Specific Changes - -There have been no specific changes accepted for the next edition yet. \ No newline at end of file diff --git a/src/rust-next/future.md b/src/rust-next/future.md deleted file mode 100644 index 4fe158c3..00000000 --- a/src/rust-next/future.md +++ /dev/null @@ -1,10 +0,0 @@ -# The Future trait - -Initially added: ![Minimum Rust version: 1.36](https://img.shields.io/badge/Minimum%20Rust%20Version-1.36-brightgreen.svg) - -In Rust 1.36.0 the long awaited [`Future`] trait has been stabilized! - -TODO: this will probably be folded into a larger async section once we're -closer to the next edition. - -[`Future`]: https://doc.rust-lang.org/std/future/trait.Future.html diff --git a/src/rust-next/index.md b/src/rust-next/index.md deleted file mode 100644 index 195118dd..00000000 --- a/src/rust-next/index.md +++ /dev/null @@ -1,7 +0,0 @@ -# The Next Edition - -We have not decided if and when the next edition will ship; there is talk of -a 2021 edition to keep up the three-year schedule, but that has not been -formally decided. - -Until we do, this section keeps track of changes that landed after Rust 2018. \ No newline at end of file diff --git a/src/rust-next/literal-macro-matcher.md b/src/rust-next/literal-macro-matcher.md deleted file mode 100644 index 1b84aade..00000000 --- a/src/rust-next/literal-macro-matcher.md +++ /dev/null @@ -1,18 +0,0 @@ -# literal macro matcher - -![Minimum Rust version: 1.32](https://img.shields.io/badge/Minimum%20Rust%20Version-1.32-brightgreen.svg) - -A new `literal` matcher was added for macros: - -```rust -macro_rules! m { - ($lt:literal) => {}; -} - -fn main() { - m!("some string literal"); -} -``` - -`literal` matches against literals of any type; string literals, numeric -literals, `char` literals. diff --git a/src/rust-next/maybe-uninit.md b/src/rust-next/maybe-uninit.md deleted file mode 100644 index 6c1d4ca0..00000000 --- a/src/rust-next/maybe-uninit.md +++ /dev/null @@ -1,28 +0,0 @@ -# MaybeUninit - -Initially added: ![Minimum Rust version: 1.36](https://img.shields.io/badge/Minimum%20Rust%20Version-1.36-brightgreen.svg) - -In previous releases of Rust, the [`mem::uninitialized`] function has allowed -you to bypass Rust's initialization checks by pretending that you've -initialized a value at type `T` without doing anything. One of the main uses -of this function has been to lazily allocate arrays. - -However, [`mem::uninitialized`] is an incredibly dangerous operation that -essentially cannot be used correctly as the Rust compiler assumes that values -are properly initialized. For example, calling `mem::uninitialized::()` -causes *instantaneous __undefined behavior__* as, from Rust's point of view, -the uninitialized bits are neither `0` (for `false`) nor `1` (for `true`) - -the only two allowed bit patterns for `bool`. - -To remedy this situation, in Rust 1.36.0, the type [`MaybeUninit`] has -been stabilized. The Rust compiler will understand that it should not assume -that a [`MaybeUninit`] is a properly initialized `T`. Therefore, you can -do gradual initialization more safely and eventually use `.assume_init()` -once you are certain that `maybe_t: MaybeUninit` contains an initialized -`T`. - -As [`MaybeUninit`] is the safer alternative, starting with Rust 1.39, the -function [`mem::uninitialized`] will be deprecated. - -[`MaybeUninit`]: https://doc.rust-lang.org/std/mem/union.MaybeUninit.html -[`mem::uninitialized`]: https://doc.rust-lang.org/std/mem/fn.uninitialized.html diff --git a/src/rust-next/no-jemalloc.md b/src/rust-next/no-jemalloc.md deleted file mode 100644 index cd024108..00000000 --- a/src/rust-next/no-jemalloc.md +++ /dev/null @@ -1,43 +0,0 @@ -# No jemalloc by default - -![Minimum Rust version: 1.32](https://img.shields.io/badge/Minimum%20Rust%20Version-1.32-brightgreen.svg) - -Long, long ago, Rust had a large, Erlang-like runtime. We chose to use -jemalloc instead of the system allocator, because it often improved -performance over the default system one. Over time, we shed more and more of -this runtime, and eventually almost all of it was removed, but jemalloc was -not. We didn't have a way to choose a custom allocator, and so we couldn't -really remove it without causing a regression for people who do need -jemalloc. - -Also, saying that jemalloc was always the default is a bit UNIX-centric, as -it was only the default on some platforms. Notably, the MSVC target on -Windows has shipped the system allocator for a long time. - -While jemalloc usually has great performance, that's not always the case. -Additionally, it adds about 300kb to every Rust binary. We've also had a host -of other issues with jemalloc in the past. It has also felt a little strange -that a systems language does not default to the system's allocator. - -For all of these reasons, once Rust 1.28 shipped a way to choose a global -allocator, we started making plans to switch the default to the system -allocator, and allow you to use jemalloc via a crate. In Rust 1.32, we've -finally finished this work, and by default, you will get the system allocator -for your programs. - -If you'd like to continue to use jemalloc, use the jemallocator crate. In -your Cargo.toml: - -```toml -jemallocator = "0.1.8" -``` - -And in your crate root: - -```rust,ignore -#[global_allocator] -static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; -``` - -That's it! If you don't need jemalloc, it's not forced upon you, and if you -do need it, it's a few lines of code away. diff --git a/src/rust-next/no-more-fnbox.md b/src/rust-next/no-more-fnbox.md deleted file mode 100644 index c5e18f44..00000000 --- a/src/rust-next/no-more-fnbox.md +++ /dev/null @@ -1,38 +0,0 @@ -# No more FnBox - -![Minimum Rust version: 1.35](https://img.shields.io/badge/Minimum%20Rust%20Version-1.35-brightgreen.svg) - -The book used to have this code in Chapter 20, section 2: - -```rust -trait FnBox { - fn call_box(self: Box); -} - -impl FnBox for F { - fn call_box(self: Box) { - (*self)() - } -} - -type Job = Box; -``` - -Here, we define a new trait called `FnBox`, and then implement it for all -`FnOnce` closures. All the implementation does is call the closure. These -sorts of hacks were needed because a `Box` didn't implement -`FnOnce`. This was true for all three posibilities: - -* `Box` and `Fn` -* `Box` and `FnMut` -* `Box` and `FnOnce` - -However, as of Rust 1.35, these traits are implemented for these types, -and so the `FnBox` trick is no longer required. In the latest version of -the book, the `Job` type looks like this: - -```rust -type Job = Box; -``` - -No need for all that other code. diff --git a/src/rust-next/pin.md b/src/rust-next/pin.md deleted file mode 100644 index a52f70cf..00000000 --- a/src/rust-next/pin.md +++ /dev/null @@ -1,21 +0,0 @@ -# Pinning - -![Minimum Rust version: 1.33](https://img.shields.io/badge/Minimum%20Rust%20Version-1.33-brightgreen.svg) - -Rust 1.33 introduced a new concept, implemented as two types: - -* [`Pin

`](https://doc.rust-lang.org/std/pin/struct.Pin.html), a wrapper - around a kind of pointer which makes that pointer "pin" its value in place, - preventing the value referenced by that pointer from being moved. -* [`Unpin`](https://doc.rust-lang.org/std/marker/trait.Unpin.html), types that - are safe to be moved, even if they're pinned. - -Most users will not interact with pinning directly, and so we won't explain -more here. For the details, see the [documentation for -`std::pin`](https://doc.rust-lang.org/std/pin/index.html). - -What *is* useful to know about pinning is that it's a pre-requisite for -`async`/`await`. Folks who write async libraries may need to learn about -pinning, but folks using them generally shouldn't need to interact with this -feature at all. - diff --git a/src/rust-next/qustion-mark-operator-in-macros.md b/src/rust-next/qustion-mark-operator-in-macros.md deleted file mode 100644 index bed0381d..00000000 --- a/src/rust-next/qustion-mark-operator-in-macros.md +++ /dev/null @@ -1,14 +0,0 @@ -# ? operator in macros - -![Minimum Rust version: 1.32](https://img.shields.io/badge/Minimum%20Rust%20Version-1.32-brightgreen.svg) - -`macro_rules` macros can use `?`, like this: - -```rust -macro_rules! bar { - ($(a)?) => {} -} -``` - -The `?` will match zero or one repetitions of the pattern, similar to the -already-existing `*` for "zero or more" and `+` for "one or more." diff --git a/src/rust-next/tryfrom-and-tryinto.md b/src/rust-next/tryfrom-and-tryinto.md deleted file mode 100644 index 3c4be087..00000000 --- a/src/rust-next/tryfrom-and-tryinto.md +++ /dev/null @@ -1,23 +0,0 @@ -# TryFrom and TryInto - -Initially added: ![Minimum Rust version: 1.34](https://img.shields.io/badge/Minimum%20Rust%20Version-1.34-brightgreen.svg) - -The [`TryFrom`](../../std/convert/trait.TryFrom.html) and -[`TryInto`](../../std/convert/trait.TryInto.html) traits are like the -[`From`](../../std/convert/trait.From.html) and -[`Into`](../../std/convert/trait.Into.html) traits, except that they return a -result, meaning that they may fail. - -For example, the `from_be_bytes` and related methods on integer types take -arrays, but data is often read in via slices. Converting between slices and -arrays is tedious to do manually. With the new traits, it can be done inline -with `.try_into()`: - -```rust -use std::convert::TryInto; -# fn main() -> Result<(), Box> { -# let slice = &[1, 2, 3, 4][..]; -let num = u32::from_be_bytes(slice.try_into()?); -# Ok(()) -# } -``` diff --git a/src/rust-next/uniform-paths.md b/src/rust-next/uniform-paths.md deleted file mode 100644 index 27a91abf..00000000 --- a/src/rust-next/uniform-paths.md +++ /dev/null @@ -1,23 +0,0 @@ -# Uniform Paths - -![Minimum Rust version: 1.32](https://img.shields.io/badge/Minimum%20Rust%20Version-1.32-brightgreen.svg) - -Rust 2018 added several improvements to the module system. We have one last -tweak landing in 1.32.0. Nicknamed "uniform paths", it permits previously -invalid import path statements to be resolved exactly the same way as -non-import paths. For example: - -```rust,edition2018 -enum Color { - Red, - Green, - Blue, -} - -use Color::*; -``` - -This code did not previously compile, as use statements had to start with -`super`, `self`, or `crate`. Now that the compiler supports uniform paths, -this code will work, and do what you probably expect: import the variants of -the Color enum defined above the `use` statement. From 7bef7baa5e6c85f3ac89a4afd2ea65ce46e09fdb Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 3 May 2021 14:25:30 -0400 Subject: [PATCH 06/13] use a better emoji for under construction --- src/SUMMARY.md | 2 +- src/rust-2021/index.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 3fd60ef9..84935c87 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -23,7 +23,7 @@ ## Rust 2021 -- [Rust 2021 ⚠️](rust-2021/index.md) +- [Rust 2021 🚧](rust-2021/index.md) - [Additions to the prelude](rust-2021/prelude.md) - [Default Cargo feature resolver](rust-2021/default_cargo_resolver.md) - [IntoIterator for arrays](rust-2021/IntoIterator_for_arrays.md) diff --git a/src/rust-2021/index.md b/src/rust-2021/index.md index 6afb8fea..0991164a 100644 --- a/src/rust-2021/index.md +++ b/src/rust-2021/index.md @@ -1,6 +1,6 @@ -# Rust 2021 ⚠️ +# Rust 2021 -⚠️ The 2021 Edition has not yet been released and hence this section is still "under construction". +🚧 The 2021 Edition has not yet been released and hence this section is still "under construction". The Rust 2021 Edition is currently slated for release in Rust 1.56.0. Rust 1.56.0 will then be in beta for six weeks, From 81336c966dd98028c5f4a4ab56571b512a3ead0f Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 3 May 2021 14:31:02 -0400 Subject: [PATCH 07/13] add a little info table for each edition --- src/rust-2018/index.md | 6 ++++++ src/rust-2021/index.md | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/rust-2018/index.md b/src/rust-2018/index.md index 021c6d7f..f41956b5 100644 --- a/src/rust-2018/index.md +++ b/src/rust-2018/index.md @@ -1,3 +1,9 @@ # Rust 2018 +| Info | | +| --- | --- | +| RFC | [#2052](https://rust-lang.github.io/rfcs/2052-epochs.html), which also proposed the Edition system | +| Release version | [1.31.0](https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html) | + The edition system was created for the release of Rust 2018. The release of the Rust 2018 edition coincided with a number of other features all coordinated around the theme of *productivity*. The majority of those features were backwards compatible and are now available on all editions; however, some of those changes required the edition mechanism (most notably the [module system changes](path-changes.md)). +s \ No newline at end of file diff --git a/src/rust-2021/index.md b/src/rust-2021/index.md index 0991164a..90304a72 100644 --- a/src/rust-2021/index.md +++ b/src/rust-2021/index.md @@ -2,6 +2,11 @@ 🚧 The 2021 Edition has not yet been released and hence this section is still "under construction". +| Info | | +| --- | --- | +| RFC | [#3085](https://github.com/rust-lang/rfcs/pull/3085) | +| Release version | 1.56.0 (anticipated) | + The Rust 2021 Edition is currently slated for release in Rust 1.56.0. Rust 1.56.0 will then be in beta for six weeks, after which it is released as stable on October 21st. From b8525aae90f10df002c2731bb91cc3de7af656e2 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 17 May 2021 13:15:12 -0400 Subject: [PATCH 08/13] rename from _ to - --- src/SUMMARY.md | 20 +++++++++---------- src/rust-2018/index.md | 1 - .../{new_keywords.md => new-keywords.md} | 0 ...n_parameters.md => trait-fn-parameters.md} | 0 ...pointer.md => tyvar-behind-raw-pointer.md} | 0 ...r_arrays.md => IntoIterator-for-arrays.md} | 0 ..._resolver.md => default-cargo-resolver.md} | 0 ...res.md => disjoint-capture-in-closures.md} | 0 ...ro_rules.md => or-patterns-macro-rules.md} | 0 ...sistency.md => panic-macro-consistency.md} | 0 ...eserving_syntax.md => reserving-syntax.md} | 0 ...error.md => warnings-promoted-to-error.md} | 0 12 files changed, 10 insertions(+), 11 deletions(-) rename src/rust-2018/{new_keywords.md => new-keywords.md} (100%) rename src/rust-2018/{trait_fn_parameters.md => trait-fn-parameters.md} (100%) rename src/rust-2018/{tyvar_behind_raw_pointer.md => tyvar-behind-raw-pointer.md} (100%) rename src/rust-2021/{IntoIterator_for_arrays.md => IntoIterator-for-arrays.md} (100%) rename src/rust-2021/{default_cargo_resolver.md => default-cargo-resolver.md} (100%) rename src/rust-2021/{disjoint_capture_in_closures.md => disjoint-capture-in-closures.md} (100%) rename src/rust-2021/{or_patterns_macro_rules.md => or-patterns-macro-rules.md} (100%) rename src/rust-2021/{panic_macro_consistency.md => panic-macro-consistency.md} (100%) rename src/rust-2021/{reserving_syntax.md => reserving-syntax.md} (100%) rename src/rust-2021/{warnings_promoted_to_error.md => warnings-promoted-to-error.md} (100%) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 84935c87..2eae0132 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -16,19 +16,19 @@ - [Rust 2018](rust-2018/index.md) - [Path and module system changes](rust-2018/path-changes.md) - - [Anonymous trait function parameters deprecated](rust-2018/trait_fn_parameters.md) - - [New keywords](rust-2018/new_keywords.md) - - [Method dispatch for raw pointers to inference variables](rust-2018/tyvar_behind_raw_pointer.md) + - [Anonymous trait function parameters deprecated](rust-2018/trait-fn-parameters.md) + - [New keywords](rust-2018/new-keywords.md) + - [Method dispatch for raw pointers to inference variables](rust-2018/tyvar-behind-raw-pointer.md) - [Cargo changes](rust-2018/cargo.md) ## Rust 2021 - [Rust 2021 🚧](rust-2021/index.md) - [Additions to the prelude](rust-2021/prelude.md) - - [Default Cargo feature resolver](rust-2021/default_cargo_resolver.md) - - [IntoIterator for arrays](rust-2021/IntoIterator_for_arrays.md) - - [Disjoint capture in closures](rust-2021/disjoint_capture_in_closures.md) - - [Panic macro consistency](rust-2021/panic_macro_consistency.md) - - [Reserving syntax](rust-2021/reserving_syntax.md) - - [Warnings promoted to errors](rust-2021/warnings_promoted_to_error.md) - - [Or patterns in macro-rules](rust-2021/or_patterns_macro_rules.md) + - [Default Cargo feature resolver](rust-2021/default-cargo-resolver.md) + - [IntoIterator for arrays](rust-2021/IntoIterator-for-arrays.md) + - [Disjoint capture in closures](rust-2021/disjoint-capture-in-closures.md) + - [Panic macro consistency](rust-2021/panic-macro-consistency.md) + - [Reserving syntax](rust-2021/reserving-syntax.md) + - [Warnings promoted to errors](rust-2021/warnings-promoted-to-error.md) + - [Or patterns in macro-rules](rust-2021/or-patterns-macro-rules.md) diff --git a/src/rust-2018/index.md b/src/rust-2018/index.md index f41956b5..77d3f48f 100644 --- a/src/rust-2018/index.md +++ b/src/rust-2018/index.md @@ -6,4 +6,3 @@ | Release version | [1.31.0](https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html) | The edition system was created for the release of Rust 2018. The release of the Rust 2018 edition coincided with a number of other features all coordinated around the theme of *productivity*. The majority of those features were backwards compatible and are now available on all editions; however, some of those changes required the edition mechanism (most notably the [module system changes](path-changes.md)). -s \ No newline at end of file diff --git a/src/rust-2018/new_keywords.md b/src/rust-2018/new-keywords.md similarity index 100% rename from src/rust-2018/new_keywords.md rename to src/rust-2018/new-keywords.md diff --git a/src/rust-2018/trait_fn_parameters.md b/src/rust-2018/trait-fn-parameters.md similarity index 100% rename from src/rust-2018/trait_fn_parameters.md rename to src/rust-2018/trait-fn-parameters.md diff --git a/src/rust-2018/tyvar_behind_raw_pointer.md b/src/rust-2018/tyvar-behind-raw-pointer.md similarity index 100% rename from src/rust-2018/tyvar_behind_raw_pointer.md rename to src/rust-2018/tyvar-behind-raw-pointer.md diff --git a/src/rust-2021/IntoIterator_for_arrays.md b/src/rust-2021/IntoIterator-for-arrays.md similarity index 100% rename from src/rust-2021/IntoIterator_for_arrays.md rename to src/rust-2021/IntoIterator-for-arrays.md diff --git a/src/rust-2021/default_cargo_resolver.md b/src/rust-2021/default-cargo-resolver.md similarity index 100% rename from src/rust-2021/default_cargo_resolver.md rename to src/rust-2021/default-cargo-resolver.md diff --git a/src/rust-2021/disjoint_capture_in_closures.md b/src/rust-2021/disjoint-capture-in-closures.md similarity index 100% rename from src/rust-2021/disjoint_capture_in_closures.md rename to src/rust-2021/disjoint-capture-in-closures.md diff --git a/src/rust-2021/or_patterns_macro_rules.md b/src/rust-2021/or-patterns-macro-rules.md similarity index 100% rename from src/rust-2021/or_patterns_macro_rules.md rename to src/rust-2021/or-patterns-macro-rules.md diff --git a/src/rust-2021/panic_macro_consistency.md b/src/rust-2021/panic-macro-consistency.md similarity index 100% rename from src/rust-2021/panic_macro_consistency.md rename to src/rust-2021/panic-macro-consistency.md diff --git a/src/rust-2021/reserving_syntax.md b/src/rust-2021/reserving-syntax.md similarity index 100% rename from src/rust-2021/reserving_syntax.md rename to src/rust-2021/reserving-syntax.md diff --git a/src/rust-2021/warnings_promoted_to_error.md b/src/rust-2021/warnings-promoted-to-error.md similarity index 100% rename from src/rust-2021/warnings_promoted_to_error.md rename to src/rust-2021/warnings-promoted-to-error.md From 9ce6aeb18ec068ff375a0f873340427b6b67f3e6 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 17 May 2021 13:18:20 -0400 Subject: [PATCH 09/13] link blog post --- src/rust-2021/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rust-2021/index.md b/src/rust-2021/index.md index 90304a72..45f09abe 100644 --- a/src/rust-2021/index.md +++ b/src/rust-2021/index.md @@ -1,6 +1,7 @@ # Rust 2021 🚧 The 2021 Edition has not yet been released and hence this section is still "under construction". +You can [read more about our plans in this blog post](https://blog.rust-lang.org/2021/05/11/edition-2021.html). | Info | | | --- | --- | From 83507159fdc27405810745d6767e883edf9cf175 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 17 May 2021 13:40:00 -0400 Subject: [PATCH 10/13] add redirects --- book.toml | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/book.toml b/book.toml index 0d09bd4b..dd3a796b 100644 --- a/book.toml +++ b/book.toml @@ -6,3 +6,75 @@ title = "The Edition Guide" [output.html] git-repository-url = "https://github.com/rust-lang/edition-guide" + +[output.html.redirect] +"/rust-2018/edition-changes.html" = "/rust-2018/index.html" +"/rust-2018/module-system/index.html" = "/rust-2018/path-changes.html" +"/rust-2018/module-system/raw-identifiers.html" = "/rust-2018/path-changes.html" +"/rust-2018/module-system/path-clarity.html" = "/rust-2018/path-changes.html" +"/rust-2018/module-system/more-visibility-modifiers.html" = "/rust-2018/path-changes.html" +"/rust-2018/module-system/nested-imports-with-use.html" = "/rust-2018/path-changes.html" +"/rust-2018/error-handling-and-panics/index.html" = "/rust-2018/index.html" +"/rust-2018/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.html" = "/rust-2018/index.html" +"/rust-2018/error-handling-and-panics/question-mark-in-main-and-tests.html" = "/rust-2018/index.html" +"/rust-2018/error-handling-and-panics/controlling-panics-with-std-panic.html" = "/rust-2018/index.html" +"/rust-2018/error-handling-and-panics/aborting-on-panic.html" = "/rust-2018/index.html" +"/rust-2018/control-flow/index.html" = "/rust-2018/index.html" +"/rust-2018/control-flow/loops-can-break-with-a-value.html" = "/rust-2018/index.html" +"/rust-2018/control-flow/async-await-for-easier-concurrency.html" = "/rust-2018/index.html" +"/rust-2018/trait-system/index.html" = "/rust-2018/index.html" +"/rust-2018/trait-system/impl-trait-for-returning-complex-types-with-ease.html" = "/rust-2018/index.html" +"/rust-2018/trait-system/dyn-trait-for-trait-objects.html" = "/rust-2018/index.html" +"/rust-2018/trait-system/more-container-types-support-trait-objects.html" = "/rust-2018/index.html" +"/rust-2018/trait-system/associated-constants.html" = "/rust-2018/index.html" +"/rust-2018/trait-system/no-anon-params.html" = "/rust-2018/index.html" +"/rust-2018/slice-patterns.html" = "/rust-2018/index.html" +"/rust-2018/ownership-and-lifetimes/index.html" = "/rust-2018/index.html" +"/rust-2018/ownership-and-lifetimes/non-lexical-lifetimes.html" = "/rust-2018/index.html" +"/rust-2018/ownership-and-lifetimes/default-match-bindings.html" = "/rust-2018/index.html" +"/rust-2018/ownership-and-lifetimes/the-anonymous-lifetime.html" = "/rust-2018/index.html" +"/rust-2018/ownership-and-lifetimes/lifetime-elision-in-impl.html" = "/rust-2018/index.html" +"/rust-2018/ownership-and-lifetimes/inference-in-structs.html" = "/rust-2018/index.html" +"/rust-2018/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.html" = "/rust-2018/index.html" +"/rust-2018/data-types/index.html" = "/rust-2018/index.html" +"/rust-2018/data-types/field-init-shorthand.html" = "/rust-2018/index.html" +"/rust-2018/data-types/inclusive-ranges.html" = "/rust-2018/index.html" +"/rust-2018/data-types/128-bit-integers.html" = "/rust-2018/index.html" +"/rust-2018/data-types/operator-equals-are-now-implementable.html" = "/rust-2018/index.html" +"/rust-2018/data-types/union-for-an-unsafe-form-of-enum.html" = "/rust-2018/index.html" +"/rust-2018/data-types/choosing-alignment-with-the-repr-attribute.html" = "/rust-2018/index.html" +"/rust-2018/simd-for-faster-computing.html" = "/rust-2018/index.html" +"/rust-2018/macros/index.html" = "/rust-2018/index.html" +"/rust-2018/macros/custom-derive.html" = "/rust-2018/index.html" +"/rust-2018/macros/macro-changes.html" = "/rust-2018/index.html" +"/rust-2018/macros/at-most-once.html" = "/rust-2018/index.html" +"/rust-2018/the-compiler/index.html" = "/rust-2018/index.html" +"/rust-2018/the-compiler/improved-error-messages.html" = "/rust-2018/index.html" +"/rust-2018/the-compiler/incremental-compilation-for-faster-compiles.html" = "/rust-2018/index.html" +"/rust-2018/the-compiler/an-attribute-for-deprecation.html" = "/rust-2018/index.html" +"/rust-2018/rustup-for-managing-rust-versions.html" = "/rust-2018/index.html" +"/rust-2018/cargo-and-crates-io/index.html" = "/rust-2018/cargo.html" +"/rust-2018/cargo-and-crates-io/cargo-check-for-faster-checking.html" = "/rust-2018/cargo.html" +"/rust-2018/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.html" = "/rust-2018/cargo.html" +"/rust-2018/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.html" = "/rust-2018/cargo.html" +"/rust-2018/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.html" = "/rust-2018/cargo.html" +"/rust-2018/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.html" = "/rust-2018/cargo.html" +"/rust-2018/cargo-and-crates-io/multi-file-examples.html" = "/rust-2018/cargo.html" +"/rust-2018/cargo-and-crates-io/replacing-dependencies-with-patch.html" = "/rust-2018/cargo.html" +"/rust-2018/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.html" = "/rust-2018/cargo.html" +"/rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.html" = "/rust-2018/cargo.html" +"/rust-2018/documentation/index.html" = "/rust-2018/index.html" +"/rust-2018/documentation/new-editions-of-the-book.html" = "/rust-2018/index.html" +"/rust-2018/documentation/the-rust-bookshelf.html" = "/rust-2018/index.html" +"/rust-2018/documentation/the-rustonomicon.html" = "/rust-2018/index.html" +"/rust-2018/documentation/std-os-has-documentation-for-all-platforms.html" = "/rust-2018/index.html" +"/rust-2018/rustdoc/index.html" = "/rust-2018/index.html" +"/rust-2018/rustdoc/documentation-tests-can-now-compile-fail.html" = "/rust-2018/index.html" +"/rust-2018/rustdoc/rustdoc-uses-commonmark.html" = "/rust-2018/index.html" +"/rust-2018/platform-and-target-support/index.html" = "/rust-2018/index.html" +"/rust-2018/platform-and-target-support/libcore-for-low-level-rust.html" = "/rust-2018/index.html" +"/rust-2018/platform-and-target-support/webassembly-support.html" = "/rust-2018/index.html" +"/rust-2018/platform-and-target-support/global-allocators.html" = "/rust-2018/index.html" +"/rust-2018/platform-and-target-support/msvc-toolchain-support.html" = "/rust-2018/index.html" +"/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.html" = "/rust-2018/index.html" +"/rust-2018/platform-and-target-support/cdylib-crates-for-c-interoperability.html" = "/rust-2018/index.html" From 3059d00448e9b0951a11ca9aeca09ace6d56f6c9 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 17 May 2021 13:50:14 -0400 Subject: [PATCH 11/13] ignore code examples in tests --- src/rust-2021/IntoIterator-for-arrays.md | 2 +- src/rust-2021/disjoint-capture-in-closures.md | 2 +- src/rust-2021/panic-macro-consistency.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rust-2021/IntoIterator-for-arrays.md b/src/rust-2021/IntoIterator-for-arrays.md index 302c285a..e26e7fbf 100644 --- a/src/rust-2021/IntoIterator-for-arrays.md +++ b/src/rust-2021/IntoIterator-for-arrays.md @@ -8,7 +8,7 @@ Until Rust 1.53, only *references* to arrays implement `IntoIterator`. This means you can iterate over `&[1, 2, 3]` and `&mut [1, 2, 3]`, but not over `[1, 2, 3]` directly. -```rust +```rust,ignore for &e in &[1, 2, 3] {} // Ok :) for e in [1, 2, 3] {} // Error :( diff --git a/src/rust-2021/disjoint-capture-in-closures.md b/src/rust-2021/disjoint-capture-in-closures.md index b49c5045..4e47fd45 100644 --- a/src/rust-2021/disjoint-capture-in-closures.md +++ b/src/rust-2021/disjoint-capture-in-closures.md @@ -15,7 +15,7 @@ When a field of the struct is already borrowed (mutably) or moved out of, the other fields can no longer be used in a closure, since that would capture the whole struct, which is no longer available. -```rust +```rust,ignore let a = SomeStruct::new(); drop(a.x); // Move out of one field of the struct diff --git a/src/rust-2021/panic-macro-consistency.md b/src/rust-2021/panic-macro-consistency.md index f2f87ebf..cf4265bc 100644 --- a/src/rust-2021/panic-macro-consistency.md +++ b/src/rust-2021/panic-macro-consistency.md @@ -9,7 +9,7 @@ The `panic!()` macro is one of Rust's most well known macros. However, it has [some subtle surprises](https://github.com/rust-lang/rfcs/blob/master/text/3007-panic-plan.md) that we can't just change due to backwards compatibility. -```rust +```rust,ignore panic!("{}", 1); // Ok, panics with the message "1" panic!("{}"); // Ok, panics with the message "{}" ``` @@ -17,7 +17,7 @@ panic!("{}"); // Ok, panics with the message "{}" The `panic!()` macro only uses string formatting when it's invoked with more than one argument. When invoked with a single argument, it doesn't even look at that argument. -```rust +```rust,ignore let a = "{"; println!(a); // Error: First argument must be a format string literal panic!(a); // Ok: The panic macro doesn't care From 5a21cd54126e5a5d4f3f66fee77bcf29a8a4613c Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 17 May 2021 13:53:25 -0400 Subject: [PATCH 12/13] redirect rust-next pages to rust-2021 index --- book.toml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/book.toml b/book.toml index dd3a796b..2c48ed04 100644 --- a/book.toml +++ b/book.toml @@ -78,3 +78,19 @@ git-repository-url = "https://github.com/rust-lang/edition-guide" "/rust-2018/platform-and-target-support/msvc-toolchain-support.html" = "/rust-2018/index.html" "/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.html" = "/rust-2018/index.html" "/rust-2018/platform-and-target-support/cdylib-crates-for-c-interoperability.html" = "/rust-2018/index.html" +"/rust-next/index.html" = "/rust-2021/index.html" +"/rust-next/edition-changes.html" = "/rust-2021/index.html" +"/rust-next/dbg-macro.html" = "/rust-2021/index.html" +"/rust-next/no-jemalloc.html" = "/rust-2021/index.html" +"/rust-next/uniform-paths.html" = "/rust-2021/index.html" +"/rust-next/literal-macro-matcher.html" = "/rust-2021/index.html" +"/rust-next/qustion-mark-operator-in-macros.html" = "/rust-2021/index.html" +"/rust-next/const-fn.html" = "/rust-2021/index.html" +"/rust-next/pin.html" = "/rust-2021/index.html" +"/rust-next/no-more-fnbox.html" = "/rust-2021/index.html" +"/rust-next/alternative-cargo-registries.html" = "/rust-2021/index.html" +"/rust-next/tryfrom-and-tryinto.html" = "/rust-2021/index.html" +"/rust-next/future.html" = "/rust-2021/index.html" +"/rust-next/alloc.html" = "/rust-2021/index.html" +"/rust-next/maybe-uninit.html" = "/rust-2021/index.html" +"/rust-next/cargo-vendor.html" = "/rust-2021/index.html" From 8b6d2d1a22b96512b88958915ff656c48f318f1f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 19 May 2021 12:02:05 -0700 Subject: [PATCH 13/13] Fix some links. --- .github/workflows/main.yml | 2 +- book.toml | 172 +++++++++++++++++----------------- src/rust-2018/new-keywords.md | 6 +- src/rust-2018/path-changes.md | 36 +++++-- 4 files changed, 119 insertions(+), 97 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2fe67600..27a9336a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: - name: Install mdbook run: | mkdir bin - curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.3.5/mdbook-v0.3.5-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin + curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.7/mdbook-v0.4.7-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin echo "$(pwd)/bin" >> $GITHUB_PATH - name: Report versions run: | diff --git a/book.toml b/book.toml index 2c48ed04..8d8b2632 100644 --- a/book.toml +++ b/book.toml @@ -8,89 +8,89 @@ title = "The Edition Guide" git-repository-url = "https://github.com/rust-lang/edition-guide" [output.html.redirect] -"/rust-2018/edition-changes.html" = "/rust-2018/index.html" -"/rust-2018/module-system/index.html" = "/rust-2018/path-changes.html" -"/rust-2018/module-system/raw-identifiers.html" = "/rust-2018/path-changes.html" -"/rust-2018/module-system/path-clarity.html" = "/rust-2018/path-changes.html" -"/rust-2018/module-system/more-visibility-modifiers.html" = "/rust-2018/path-changes.html" -"/rust-2018/module-system/nested-imports-with-use.html" = "/rust-2018/path-changes.html" -"/rust-2018/error-handling-and-panics/index.html" = "/rust-2018/index.html" -"/rust-2018/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.html" = "/rust-2018/index.html" -"/rust-2018/error-handling-and-panics/question-mark-in-main-and-tests.html" = "/rust-2018/index.html" -"/rust-2018/error-handling-and-panics/controlling-panics-with-std-panic.html" = "/rust-2018/index.html" -"/rust-2018/error-handling-and-panics/aborting-on-panic.html" = "/rust-2018/index.html" -"/rust-2018/control-flow/index.html" = "/rust-2018/index.html" -"/rust-2018/control-flow/loops-can-break-with-a-value.html" = "/rust-2018/index.html" -"/rust-2018/control-flow/async-await-for-easier-concurrency.html" = "/rust-2018/index.html" -"/rust-2018/trait-system/index.html" = "/rust-2018/index.html" -"/rust-2018/trait-system/impl-trait-for-returning-complex-types-with-ease.html" = "/rust-2018/index.html" -"/rust-2018/trait-system/dyn-trait-for-trait-objects.html" = "/rust-2018/index.html" -"/rust-2018/trait-system/more-container-types-support-trait-objects.html" = "/rust-2018/index.html" -"/rust-2018/trait-system/associated-constants.html" = "/rust-2018/index.html" -"/rust-2018/trait-system/no-anon-params.html" = "/rust-2018/index.html" -"/rust-2018/slice-patterns.html" = "/rust-2018/index.html" -"/rust-2018/ownership-and-lifetimes/index.html" = "/rust-2018/index.html" -"/rust-2018/ownership-and-lifetimes/non-lexical-lifetimes.html" = "/rust-2018/index.html" -"/rust-2018/ownership-and-lifetimes/default-match-bindings.html" = "/rust-2018/index.html" -"/rust-2018/ownership-and-lifetimes/the-anonymous-lifetime.html" = "/rust-2018/index.html" -"/rust-2018/ownership-and-lifetimes/lifetime-elision-in-impl.html" = "/rust-2018/index.html" -"/rust-2018/ownership-and-lifetimes/inference-in-structs.html" = "/rust-2018/index.html" -"/rust-2018/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.html" = "/rust-2018/index.html" -"/rust-2018/data-types/index.html" = "/rust-2018/index.html" -"/rust-2018/data-types/field-init-shorthand.html" = "/rust-2018/index.html" -"/rust-2018/data-types/inclusive-ranges.html" = "/rust-2018/index.html" -"/rust-2018/data-types/128-bit-integers.html" = "/rust-2018/index.html" -"/rust-2018/data-types/operator-equals-are-now-implementable.html" = "/rust-2018/index.html" -"/rust-2018/data-types/union-for-an-unsafe-form-of-enum.html" = "/rust-2018/index.html" -"/rust-2018/data-types/choosing-alignment-with-the-repr-attribute.html" = "/rust-2018/index.html" -"/rust-2018/simd-for-faster-computing.html" = "/rust-2018/index.html" -"/rust-2018/macros/index.html" = "/rust-2018/index.html" -"/rust-2018/macros/custom-derive.html" = "/rust-2018/index.html" -"/rust-2018/macros/macro-changes.html" = "/rust-2018/index.html" -"/rust-2018/macros/at-most-once.html" = "/rust-2018/index.html" -"/rust-2018/the-compiler/index.html" = "/rust-2018/index.html" -"/rust-2018/the-compiler/improved-error-messages.html" = "/rust-2018/index.html" -"/rust-2018/the-compiler/incremental-compilation-for-faster-compiles.html" = "/rust-2018/index.html" -"/rust-2018/the-compiler/an-attribute-for-deprecation.html" = "/rust-2018/index.html" -"/rust-2018/rustup-for-managing-rust-versions.html" = "/rust-2018/index.html" -"/rust-2018/cargo-and-crates-io/index.html" = "/rust-2018/cargo.html" -"/rust-2018/cargo-and-crates-io/cargo-check-for-faster-checking.html" = "/rust-2018/cargo.html" -"/rust-2018/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.html" = "/rust-2018/cargo.html" -"/rust-2018/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.html" = "/rust-2018/cargo.html" -"/rust-2018/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.html" = "/rust-2018/cargo.html" -"/rust-2018/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.html" = "/rust-2018/cargo.html" -"/rust-2018/cargo-and-crates-io/multi-file-examples.html" = "/rust-2018/cargo.html" -"/rust-2018/cargo-and-crates-io/replacing-dependencies-with-patch.html" = "/rust-2018/cargo.html" -"/rust-2018/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.html" = "/rust-2018/cargo.html" -"/rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.html" = "/rust-2018/cargo.html" -"/rust-2018/documentation/index.html" = "/rust-2018/index.html" -"/rust-2018/documentation/new-editions-of-the-book.html" = "/rust-2018/index.html" -"/rust-2018/documentation/the-rust-bookshelf.html" = "/rust-2018/index.html" -"/rust-2018/documentation/the-rustonomicon.html" = "/rust-2018/index.html" -"/rust-2018/documentation/std-os-has-documentation-for-all-platforms.html" = "/rust-2018/index.html" -"/rust-2018/rustdoc/index.html" = "/rust-2018/index.html" -"/rust-2018/rustdoc/documentation-tests-can-now-compile-fail.html" = "/rust-2018/index.html" -"/rust-2018/rustdoc/rustdoc-uses-commonmark.html" = "/rust-2018/index.html" -"/rust-2018/platform-and-target-support/index.html" = "/rust-2018/index.html" -"/rust-2018/platform-and-target-support/libcore-for-low-level-rust.html" = "/rust-2018/index.html" -"/rust-2018/platform-and-target-support/webassembly-support.html" = "/rust-2018/index.html" -"/rust-2018/platform-and-target-support/global-allocators.html" = "/rust-2018/index.html" -"/rust-2018/platform-and-target-support/msvc-toolchain-support.html" = "/rust-2018/index.html" -"/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.html" = "/rust-2018/index.html" -"/rust-2018/platform-and-target-support/cdylib-crates-for-c-interoperability.html" = "/rust-2018/index.html" -"/rust-next/index.html" = "/rust-2021/index.html" -"/rust-next/edition-changes.html" = "/rust-2021/index.html" -"/rust-next/dbg-macro.html" = "/rust-2021/index.html" -"/rust-next/no-jemalloc.html" = "/rust-2021/index.html" -"/rust-next/uniform-paths.html" = "/rust-2021/index.html" -"/rust-next/literal-macro-matcher.html" = "/rust-2021/index.html" -"/rust-next/qustion-mark-operator-in-macros.html" = "/rust-2021/index.html" -"/rust-next/const-fn.html" = "/rust-2021/index.html" -"/rust-next/pin.html" = "/rust-2021/index.html" -"/rust-next/no-more-fnbox.html" = "/rust-2021/index.html" -"/rust-next/alternative-cargo-registries.html" = "/rust-2021/index.html" -"/rust-next/tryfrom-and-tryinto.html" = "/rust-2021/index.html" -"/rust-next/future.html" = "/rust-2021/index.html" -"/rust-next/alloc.html" = "/rust-2021/index.html" -"/rust-next/maybe-uninit.html" = "/rust-2021/index.html" -"/rust-next/cargo-vendor.html" = "/rust-2021/index.html" +"/rust-2018/edition-changes.html" = "index.html" +"/rust-2018/module-system/index.html" = "../path-changes.html" +"/rust-2018/module-system/raw-identifiers.html" = "../../../rust-by-example/compatibility/raw_identifiers.html" +"/rust-2018/module-system/path-clarity.html" = "../path-changes.html" +"/rust-2018/module-system/more-visibility-modifiers.html" = "../../../reference/visibility-and-privacy.html" +"/rust-2018/module-system/nested-imports-with-use.html" = "../../../rust-by-example/mod/use.html" +"/rust-2018/error-handling-and-panics/index.html" = "../../../book/ch09-00-error-handling.html" +"/rust-2018/error-handling-and-panics/the-question-mark-operator-for-easier-error-handling.html" = "../../../book/ch09-02-recoverable-errors-with-result.html" +"/rust-2018/error-handling-and-panics/question-mark-in-main-and-tests.html" = "../../../rust-by-example/error/result.html#using-result-in-main" +"/rust-2018/error-handling-and-panics/controlling-panics-with-std-panic.html" = "https://blog.rust-lang.org/2016/05/26/Rust-1.9.html#controlled-unwinding" +"/rust-2018/error-handling-and-panics/aborting-on-panic.html" = "../../../book/ch09-01-unrecoverable-errors-with-panic.html" +"/rust-2018/control-flow/index.html" = "../../../rust-by-example/flow_control.html" +"/rust-2018/control-flow/loops-can-break-with-a-value.html" = "../../../rust-by-example/flow_control/loop/return.html" +"/rust-2018/control-flow/async-await-for-easier-concurrency.html" = "https://rust-lang.github.io/async-book/" +"/rust-2018/trait-system/index.html" = "../index.html" +"/rust-2018/trait-system/impl-trait-for-returning-complex-types-with-ease.html" = "https://blog.rust-lang.org/2018/05/10/Rust-1.26.html#impl-trait" +"/rust-2018/trait-system/dyn-trait-for-trait-objects.html" = "https://blog.rust-lang.org/2018/06/21/Rust-1.27.html#dyn-trait" +"/rust-2018/trait-system/more-container-types-support-trait-objects.html" = "https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md" +"/rust-2018/trait-system/associated-constants.html" = "../../../reference/items/associated-items.html#associated-constants" +"/rust-2018/trait-system/no-anon-params.html" = "../trait-fn-parameters.html" +"/rust-2018/slice-patterns.html" = "https://blog.rust-lang.org/2018/05/10/Rust-1.26.html#basic-slice-patterns" +"/rust-2018/ownership-and-lifetimes/index.html" = "../../../book/ch04-00-understanding-ownership.html" +"/rust-2018/ownership-and-lifetimes/non-lexical-lifetimes.html" = "https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#non-lexical-lifetimes" +"/rust-2018/ownership-and-lifetimes/default-match-bindings.html" = "https://blog.rust-lang.org/2018/05/10/Rust-1.26.html#nicer-match-bindings" +"/rust-2018/ownership-and-lifetimes/the-anonymous-lifetime.html" = "https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#more-lifetime-elision-rules" +"/rust-2018/ownership-and-lifetimes/lifetime-elision-in-impl.html" = "https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#more-lifetime-elision-rules" +"/rust-2018/ownership-and-lifetimes/inference-in-structs.html" = "https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md" +"/rust-2018/ownership-and-lifetimes/simpler-lifetimes-in-static-and-const.html" = "../../../reference/lifetime-elision.html#static-lifetime-elision" +"/rust-2018/data-types/index.html" = "../index.html" +"/rust-2018/data-types/field-init-shorthand.html" = "../../../reference/expressions/struct-expr.html#struct-field-init-shorthand" +"/rust-2018/data-types/inclusive-ranges.html" = "https://blog.rust-lang.org/2018/05/10/Rust-1.26.html#inclusive-ranges-with-" +"/rust-2018/data-types/128-bit-integers.html" = "https://blog.rust-lang.org/2018/05/10/Rust-1.26.html#128-bit-integers" +"/rust-2018/data-types/operator-equals-are-now-implementable.html" = "../../../std/ops/index.html" +"/rust-2018/data-types/union-for-an-unsafe-form-of-enum.html" = "../../../reference/items/unions.html" +"/rust-2018/data-types/choosing-alignment-with-the-repr-attribute.html" = "../../../reference/type-layout.html#representations" +"/rust-2018/simd-for-faster-computing.html" = "https://blog.rust-lang.org/2018/06/21/Rust-1.27.html#simd" +"/rust-2018/macros/index.html" = "../../../book/ch19-06-macros.html" +"/rust-2018/macros/custom-derive.html" = "../../../book/ch19-06-macros.html#how-to-write-a-custom-derive-macro" +"/rust-2018/macros/macro-changes.html" = "../../../book/ch19-06-macros.html" +"/rust-2018/macros/at-most-once.html" = "../../../reference/macros-by-example.html#repetitions" +"/rust-2018/the-compiler/index.html" = "../index.html" +"/rust-2018/the-compiler/improved-error-messages.html" = "https://blog.rust-lang.org/2016/09/29/Rust-1.12.html#overhauled-error-messages" +"/rust-2018/the-compiler/incremental-compilation-for-faster-compiles.html" = "https://blog.rust-lang.org/2018/02/15/Rust-1.24.html#incremental-compilation" +"/rust-2018/the-compiler/an-attribute-for-deprecation.html" = "../../../reference/attributes/diagnostics.html#the-deprecated-attribute" +"/rust-2018/rustup-for-managing-rust-versions.html" = "https://rust-lang.github.io/rustup/" +"/rust-2018/cargo-and-crates-io/index.html" = "../../../cargo/index.html" +"/rust-2018/cargo-and-crates-io/cargo-check-for-faster-checking.html" = "../../../cargo/commands/cargo-check.html" +"/rust-2018/cargo-and-crates-io/cargo-install-for-easy-installation-of-tools.html" = "../../../cargo/commands/cargo-install.html" +"/rust-2018/cargo-and-crates-io/cargo-new-defaults-to-a-binary-project.html" = "https://blog.rust-lang.org/2018/03/29/Rust-1.25.html#cargo-features" +"/rust-2018/cargo-and-crates-io/cargo-rustc-for-passing-arbitrary-flags-to-rustc.html" = "../../../cargo/commands/cargo-rustc.html" +"/rust-2018/cargo-and-crates-io/cargo-workspaces-for-multi-package-projects.html" = "../../../cargo/reference/workspaces.html" +"/rust-2018/cargo-and-crates-io/multi-file-examples.html" = "../../../cargo/guide/project-layout.html" +"/rust-2018/cargo-and-crates-io/replacing-dependencies-with-patch.html" = "../../../cargo/reference/overriding-dependencies.html#the-patch-section" +"/rust-2018/cargo-and-crates-io/cargo-can-use-a-local-registry-replacement.html" = "../../../cargo/reference/source-replacement.html" +"/rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.html" = "https://blog.rust-lang.org/2016/01/21/Rust-1.6.html#cratesio-disallows-wildcards" +"/rust-2018/documentation/index.html" = "../../../index.html" +"/rust-2018/documentation/new-editions-of-the-book.html" = "../../../book/index.html" +"/rust-2018/documentation/the-rust-bookshelf.html" = "../../../index.html" +"/rust-2018/documentation/the-rustonomicon.html" = "../../../nomicon/index.html" +"/rust-2018/documentation/std-os-has-documentation-for-all-platforms.html" = "../../../std/os/index.html" +"/rust-2018/rustdoc/index.html" = "../../../rustdoc/index.html" +"/rust-2018/rustdoc/documentation-tests-can-now-compile-fail.html" = "../../../rustdoc/documentation-tests.html#attributes" +"/rust-2018/rustdoc/rustdoc-uses-commonmark.html" = "../../../rustdoc/how-to-write-documentation.html#markdown" +"/rust-2018/platform-and-target-support/index.html" = "../../../rustc/targets/index.html" +"/rust-2018/platform-and-target-support/libcore-for-low-level-rust.html" = "../../../core/index.html" +"/rust-2018/platform-and-target-support/webassembly-support.html" = "https://rustwasm.github.io/docs/book/" +"/rust-2018/platform-and-target-support/global-allocators.html" = "https://blog.rust-lang.org/2018/08/02/Rust-1.28.html#global-allocators" +"/rust-2018/platform-and-target-support/msvc-toolchain-support.html" = "../../../rustc/platform-support.html" +"/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.html" = "../../../rustc/platform-support.html" +"/rust-2018/platform-and-target-support/cdylib-crates-for-c-interoperability.html" = "https://github.com/rust-lang/rfcs/blob/master/text/1510-cdylib.md" +"/rust-next/index.html" = "../rust-2021/index.html" +"/rust-next/edition-changes.html" = "../rust-2021/index.html" +"/rust-next/dbg-macro.html" = "../../std/macro.dbg.html" +"/rust-next/no-jemalloc.html" = "https://blog.rust-lang.org/2019/01/17/Rust-1.32.0.html#jemalloc-is-removed-by-default" +"/rust-next/uniform-paths.html" = "https://blog.rust-lang.org/2019/01/17/Rust-1.32.0.html#final-module-improvements" +"/rust-next/literal-macro-matcher.html" = "https://blog.rust-lang.org/2019/01/17/Rust-1.32.0.html#macro-improvements" +"/rust-next/qustion-mark-operator-in-macros.html" = "https://blog.rust-lang.org/2019/01/17/Rust-1.32.0.html#macro-improvements" +"/rust-next/const-fn.html" = "../../reference/const_eval.html" +"/rust-next/pin.html" = "../../std/pin/index.html" +"/rust-next/no-more-fnbox.html" = "https://blog.rust-lang.org/2019/05/23/Rust-1.35.0.html#fn-closure-traits-implemented-for-boxdyn-fn" +"/rust-next/alternative-cargo-registries.html" = "https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#alternative-cargo-registries" +"/rust-next/tryfrom-and-tryinto.html" = "https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html#tryfrom-and-tryinto" +"/rust-next/future.html" = "../../std/future/trait.Future.html" +"/rust-next/alloc.html" = "https://blog.rust-lang.org/2019/07/04/Rust-1.36.0.html#the-alloc-crate-is-stable" +"/rust-next/maybe-uninit.html" = "https://blog.rust-lang.org/2019/07/04/Rust-1.36.0.html#maybeuninitt-instead-of-memuninitialized" +"/rust-next/cargo-vendor.html" = "../../cargo/commands/cargo-vendor.html" diff --git a/src/rust-2018/new-keywords.md b/src/rust-2018/new-keywords.md index 2fe564dc..92ee8770 100644 --- a/src/rust-2018/new-keywords.md +++ b/src/rust-2018/new-keywords.md @@ -4,7 +4,7 @@ ## Summary -- [`dyn`] is a [strict keyword][strict], in 2015 it is a [weak keyword]. +- `dyn` is a [strict keyword][strict], in 2015 it is a [weak keyword]. - `async` and `await` are [strict keywords][strict]. - `try` is a [reserved keyword]. @@ -50,11 +50,13 @@ is sometimes slower, and often cannot be used at all when its alternatives can. Furthermore, with `impl Trait` arriving, "`impl Trait` vs `dyn Trait`" is much more symmetric, and therefore a bit nicer, than "`impl Trait` vs `Trait`". -`impl Trait` is explained [here](impl-trait-for-returning-complex-types-with-ease.md). +`impl Trait` is explained [here][impl-trait]. In the new edition, you should therefore prefer `dyn Trait` to just `Trait` where you need a trait object. +[impl-trait]: ../../rust-by-example/trait/impl_trait.html + ### `async` and `await` These keywords are reserved to implement the async-await feature of Rust, which was ultimately [released to stable in 1.39.0](https://blog.rust-lang.org/2019/11/07/Async-await-stable.html). diff --git a/src/rust-2018/path-changes.md b/src/rust-2018/path-changes.md index f4e5ceea..fc16d472 100644 --- a/src/rust-2018/path-changes.md +++ b/src/rust-2018/path-changes.md @@ -99,19 +99,39 @@ Some examples of needing to explicitly import sysroot crates are: * [`test`]: This is only available on the [nightly channel], and is usually only used for the unstable benchmark support. -[`alloc`]: ../../../alloc/index.html -[`core`]: ../../../core/index.html -[`proc_macro`]: ../../../proc_macro/index.html -[`std`]: ../../../std/index.html -[`test`]: ../../../test/index.html -[nightly channel]: ../../../book/appendix-07-nightly-rust.html +[`alloc`]: ../../alloc/index.html +[`core`]: ../../core/index.html +[`proc_macro`]: ../../proc_macro/index.html +[`std`]: ../../std/index.html +[`test`]: ../../test/index.html +[nightly channel]: ../../book/appendix-07-nightly-rust.html [no_core]: https://github.com/rust-lang/rust/issues/29639 -[no_std]: ../../../reference/names/preludes.html#the-no_std-attribute +[no_std]: ../../reference/names/preludes.html#the-no_std-attribute #### Macros One other use for `extern crate` was to import macros; that's no longer needed. -Check [the macro section](../macros/macro-changes.md) for more. +Macros may be imported with `use` like any other item. For example, the +following use of `extern crate`: + +```rust,ignore +#[macro_use] +extern crate bar; + +fn main() { + baz!(); +} +``` + +Can be changed to something like the following: + +```rust,ignore +use bar::baz; + +fn main() { + baz!(); +} +``` #### Renaming crates