diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index caf97abf78d9e..26e589c092eda 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -28,6 +28,7 @@ name: CI
- "**"
permissions:
contents: read
+ packages: write
defaults:
run:
shell: bash
@@ -42,6 +43,7 @@ jobs:
CI_JOB_NAME: "${{ matrix.name }}"
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
+ DOCKER_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
SCCACHE_BUCKET: rust-lang-ci-sccache2
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
CACHE_DOMAIN: ci-caches.rust-lang.org
@@ -172,6 +174,7 @@ jobs:
CI_JOB_NAME: "${{ matrix.name }}"
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
+ DOCKER_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
SCCACHE_BUCKET: rust-lang-ci-sccache2
DEPLOY_BUCKET: rust-lang-ci2
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
@@ -291,7 +294,7 @@ jobs:
- name: x86_64-gnu-integration
env:
CI_ONLY_WHEN_CHANNEL: nightly
- os: ubuntu-20.04-16core-64gb
+ os: ubuntu-20.04-8core-32gb
- name: x86_64-gnu-debug
os: ubuntu-20.04-8core-32gb
env: {}
@@ -316,7 +319,7 @@ jobs:
- name: dist-x86_64-apple
env:
SCRIPT: "./x.py dist bootstrap --include-default-paths --host=x86_64-apple-darwin --target=x86_64-apple-darwin"
- RUST_CONFIGURE_ARGS: "--enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false --set rust.lto=thin"
+ RUST_CONFIGURE_ARGS: "--enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc --set rust.lto=thin"
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
MACOSX_DEPLOYMENT_TARGET: 10.12
SELECT_XCODE: /Applications/Xcode_13.4.1.app
@@ -329,7 +332,7 @@ jobs:
- name: dist-apple-various
env:
SCRIPT: "./x.py dist bootstrap --include-default-paths --host='' --target=aarch64-apple-ios,x86_64-apple-ios,aarch64-apple-ios-sim"
- RUST_CONFIGURE_ARGS: "--enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false"
+ RUST_CONFIGURE_ARGS: "--enable-sanitizers --enable-profiler --set rust.jemalloc"
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
MACOSX_DEPLOYMENT_TARGET: 10.12
SELECT_XCODE: /Applications/Xcode_13.4.1.app
@@ -340,7 +343,7 @@ jobs:
- name: x86_64-apple-1
env:
SCRIPT: "./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc --skip tests/run-make-fulldeps"
- RUST_CONFIGURE_ARGS: "--build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false"
+ RUST_CONFIGURE_ARGS: "--build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set rust.jemalloc"
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
MACOSX_DEPLOYMENT_TARGET: 10.12
MACOSX_STD_DEPLOYMENT_TARGET: 10.12
@@ -351,7 +354,7 @@ jobs:
- name: x86_64-apple-2
env:
SCRIPT: "./x.py --stage 2 test tests/ui tests/rustdoc tests/run-make-fulldeps"
- RUST_CONFIGURE_ARGS: "--build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false"
+ RUST_CONFIGURE_ARGS: "--build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set rust.jemalloc"
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
MACOSX_DEPLOYMENT_TARGET: 10.12
MACOSX_STD_DEPLOYMENT_TARGET: 10.12
@@ -361,8 +364,8 @@ jobs:
os: macos-13
- name: dist-aarch64-apple
env:
- SCRIPT: "./x.py dist bootstrap --include-default-paths --stage 2"
- RUST_CONFIGURE_ARGS: "--build=x86_64-apple-darwin --host=aarch64-apple-darwin --target=aarch64-apple-darwin --enable-full-tools --enable-sanitizers --enable-profiler --disable-docs --set rust.jemalloc --set llvm.ninja=false"
+ SCRIPT: "./x.py dist bootstrap --include-default-paths --host=aarch64-apple-darwin --target=aarch64-apple-darwin"
+ RUST_CONFIGURE_ARGS: "--enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc --set llvm.ninja=false --set rust.lto=thin"
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
SELECT_XCODE: /Applications/Xcode_13.4.1.app
USE_XCODE_CLANG: 1
@@ -372,8 +375,20 @@ jobs:
NO_DEBUG_ASSERTIONS: 1
NO_OVERFLOW_CHECKS: 1
DIST_REQUIRE_ALL_TOOLS: 1
- JEMALLOC_SYS_WITH_LG_PAGE: 14
- os: macos-13
+ os: macos-14
+ - name: aarch64-apple
+ env:
+ SCRIPT: "./x.py --stage 2 test --host=aarch64-apple-darwin --target=aarch64-apple-darwin"
+ RUST_CONFIGURE_ARGS: "--enable-sanitizers --enable-profiler --set rust.jemalloc"
+ RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
+ SELECT_XCODE: /Applications/Xcode_13.4.1.app
+ USE_XCODE_CLANG: 1
+ MACOSX_DEPLOYMENT_TARGET: 11.0
+ MACOSX_STD_DEPLOYMENT_TARGET: 11.0
+ NO_LLVM_ASSERTIONS: 1
+ NO_DEBUG_ASSERTIONS: 1
+ NO_OVERFLOW_CHECKS: 1
+ os: macos-14
- name: x86_64-msvc
env:
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc --enable-profiler"
@@ -554,6 +569,7 @@ jobs:
CI_JOB_NAME: "${{ matrix.name }}"
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
+ DOCKER_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
SCCACHE_BUCKET: rust-lang-ci-sccache2
DEPLOY_BUCKET: rust-lang-ci2
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
diff --git a/Cargo.lock b/Cargo.lock
index 74f96983b3149..300cc02330f97 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -37,9 +37,9 @@ dependencies = [
[[package]]
name = "ahash"
-version = "0.8.6"
+version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a"
+checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01"
dependencies = [
"cfg-if",
"once_cell",
@@ -382,9 +382,9 @@ dependencies = [
[[package]]
name = "byteorder"
-version = "1.4.3"
+version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
+checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
@@ -596,11 +596,11 @@ dependencies = [
name = "clippy_dev"
version = "0.0.1"
dependencies = [
- "aho-corasick 0.7.20",
+ "aho-corasick 1.0.2",
"clap",
"indoc",
"itertools",
- "opener 0.5.2",
+ "opener",
"shell-escape",
"walkdir",
]
@@ -610,7 +610,7 @@ name = "clippy_lints"
version = "0.1.77"
dependencies = [
"arrayvec",
- "cargo_metadata 0.15.4",
+ "cargo_metadata 0.18.0",
"clippy_config",
"clippy_utils",
"declare_clippy_lint",
@@ -1268,7 +1268,6 @@ name = "error_index_generator"
version = "0.0.0"
dependencies = [
"mdbook",
- "rustc_error_codes",
]
[[package]]
@@ -2170,9 +2169,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"
[[package]]
name = "libc"
-version = "0.2.150"
+version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
+checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
dependencies = [
"rustc-std-workspace-core",
]
@@ -2351,7 +2350,7 @@ dependencies = [
"log",
"memchr",
"once_cell",
- "opener 0.6.1",
+ "opener",
"pathdiff",
"pulldown-cmark",
"regex",
@@ -2596,9 +2595,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]]
name = "object"
-version = "0.32.1"
+version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
+checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
dependencies = [
"compiler_builtins",
"crc32fast",
@@ -2626,16 +2625,6 @@ version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
-[[package]]
-name = "opener"
-version = "0.5.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "293c15678e37254c15bd2f092314abb4e51d7fdde05c2021279c12631b54f005"
-dependencies = [
- "bstr",
- "winapi",
-]
-
[[package]]
name = "opener"
version = "0.6.1"
@@ -3014,11 +3003,11 @@ dependencies = [
[[package]]
name = "pulldown-cmark"
-version = "0.9.3"
+version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998"
+checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b"
dependencies = [
- "bitflags 1.3.2",
+ "bitflags 2.4.1",
"memchr",
"unicase",
]
@@ -3711,7 +3700,6 @@ dependencies = [
"rustc_codegen_ssa",
"rustc_const_eval",
"rustc_data_structures",
- "rustc_error_codes",
"rustc_errors",
"rustc_expand",
"rustc_feature",
@@ -3784,9 +3772,11 @@ dependencies = [
"rustc_ast",
"rustc_ast_pretty",
"rustc_data_structures",
+ "rustc_error_codes",
"rustc_error_messages",
"rustc_fluent_macro",
"rustc_hir",
+ "rustc_index",
"rustc_lint_defs",
"rustc_macros",
"rustc_serialize",
@@ -4352,7 +4342,6 @@ dependencies = [
name = "rustc_pattern_analysis"
version = "0.0.0"
dependencies = [
- "derivative",
"rustc-hash",
"rustc_apfloat",
"rustc_arena",
@@ -4385,6 +4374,7 @@ dependencies = [
"rustc_middle",
"rustc_session",
"rustc_span",
+ "rustc_ty_utils",
"tracing",
]
@@ -4797,12 +4787,12 @@ checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06"
[[package]]
name = "ruzstd"
-version = "0.4.0"
+version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ac3ffab8f9715a0d455df4bbb9d21e91135aab3cd3ca187af0cd0c3c3f868fdc"
+checksum = "58c4eb8a81997cf040a091d1f7e1938aeab6749d3a0dfa73af43cdc32393483d"
dependencies = [
"byteorder",
- "thiserror-core",
+ "derive_more",
"twox-hash",
]
@@ -5332,6 +5322,7 @@ version = "0.0.0"
dependencies = [
"core",
"getopts",
+ "libc",
"panic_abort",
"panic_unwind",
"std",
@@ -5365,26 +5356,6 @@ dependencies = [
"thiserror-impl",
]
-[[package]]
-name = "thiserror-core"
-version = "1.0.38"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0d97345f6437bb2004cd58819d8a9ef8e36cdd7661c2abc4bbde0a7c40d9f497"
-dependencies = [
- "thiserror-core-impl",
-]
-
-[[package]]
-name = "thiserror-core-impl"
-version = "1.0.38"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "10ac1c5050e43014d16b2f94d0d2ce79e65ffdd8b38d8048f9c8f6a8a6da62ac"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 1.0.109",
-]
-
[[package]]
name = "thiserror-impl"
version = "1.0.47"
@@ -5757,9 +5728,9 @@ dependencies = [
[[package]]
name = "unic-langid"
-version = "0.9.1"
+version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "398f9ad7239db44fd0f80fe068d12ff22d78354080332a5077dc6f52f14dcf2f"
+checksum = "238722e6d794ed130f91f4ea33e01fcff4f188d92337a21297892521c72df516"
dependencies = [
"unic-langid-impl",
"unic-langid-macros",
@@ -5767,18 +5738,18 @@ dependencies = [
[[package]]
name = "unic-langid-impl"
-version = "0.9.1"
+version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e35bfd2f2b8796545b55d7d3fd3e89a0613f68a0d1c8bc28cb7ff96b411a35ff"
+checksum = "4bd55a2063fdea4ef1f8633243a7b0524cbeef1905ae04c31a1c9b9775c55bc6"
dependencies = [
"tinystr",
]
[[package]]
name = "unic-langid-macros"
-version = "0.9.1"
+version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "055e618bf694161ffff0466d95cef3e1a5edc59f6ba1888e97801f2b4ebdc4fe"
+checksum = "5c854cefb82ff2816410ce606acbad1b3af065140907b29be9229040752b83ec"
dependencies = [
"proc-macro-hack",
"tinystr",
@@ -5788,13 +5759,13 @@ dependencies = [
[[package]]
name = "unic-langid-macros-impl"
-version = "0.9.1"
+version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1f5cdec05b907f4e2f6843f4354f4ce6a5bebe1a56df320a49134944477ce4d8"
+checksum = "fea2a4c80deb4fb3ca51f66b5e2dd91e3642bbce52234bcf22e41668281208e4"
dependencies = [
"proc-macro-hack",
"quote",
- "syn 1.0.109",
+ "syn 2.0.32",
"unic-langid-impl",
]
@@ -6437,18 +6408,18 @@ dependencies = [
[[package]]
name = "zerocopy"
-version = "0.7.28"
+version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7d6f15f7ade05d2a4935e34a457b936c23dc70a05cc1d97133dc99e7a3fe0f0e"
+checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
-version = "0.7.28"
+version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dbbad221e3f78500350ecbd7dfa4e63ef945c05f4c61cb7f4d3f84cd0bba649b"
+checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
dependencies = [
"proc-macro2",
"quote",
diff --git a/RELEASES.md b/RELEASES.md
index 3fb74b52292c1..3751b15b361b1 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -1,3 +1,97 @@
+Version 1.76.0 (2024-02-08)
+==========================
+
+
+
+Language
+--------
+- [Document Rust ABI compatibility between various types](https://github.com/rust-lang/rust/pull/115476/)
+- [Also: guarantee that char and u32 are ABI-compatible](https://github.com/rust-lang/rust/pull/118032/)
+- [Warn against ambiguous wide pointer comparisons](https://github.com/rust-lang/rust/pull/117758/)
+- [Add lint `ambiguous_wide_pointer_comparisons` that supersedes `clippy::vtable_address_comparisons`](https://github.com/rust-lang/rust/pull/117758)
+
+
+
+Compiler
+--------
+- [Lint pinned `#[must_use]` pointers (in particular, `Box` where `T` is `#[must_use]`) in `unused_must_use`.](https://github.com/rust-lang/rust/pull/118054/)
+- [Soundness fix: fix computing the offset of an unsized field in a packed struct](https://github.com/rust-lang/rust/pull/118540/)
+- [Soundness fix: fix dynamic size/align computation logic for packed types with dyn Trait tail](https://github.com/rust-lang/rust/pull/118538/)
+- [Add `$message_type` field to distinguish json diagnostic outputs](https://github.com/rust-lang/rust/pull/115691/)
+- [Enable Rust to use the EHCont security feature of Windows](https://github.com/rust-lang/rust/pull/118013/)
+- [Add tier 3 {x86_64,i686}-win7-windows-msvc targets](https://github.com/rust-lang/rust/pull/118150/)
+- [Add tier 3 aarch64-apple-watchos target](https://github.com/rust-lang/rust/pull/119074/)
+- [Add tier 3 arm64e-apple-ios & arm64e-apple-darwin targets](https://github.com/rust-lang/rust/pull/115526/)
+
+Refer to Rust's [platform support page][platform-support-doc]
+for more information on Rust's tiered platform support.
+
+
+
+Libraries
+---------
+- [Add a column number to `dbg!()`](https://github.com/rust-lang/rust/pull/114962/)
+- [Add `std::hash::{DefaultHasher, RandomState}` exports](https://github.com/rust-lang/rust/pull/115694/)
+- [Fix rounding issue with exponents in fmt](https://github.com/rust-lang/rust/pull/116301/)
+- [Add T: ?Sized to `RwLockReadGuard` and `RwLockWriteGuard`'s Debug impls.](https://github.com/rust-lang/rust/pull/117138/)
+- [Windows: Allow `File::create` to work on hidden files](https://github.com/rust-lang/rust/pull/116438/)
+
+
+
+Stabilized APIs
+---------------
+
+- [`Arc::unwrap_or_clone`](https://doc.rust-lang.org/stable/std/sync/struct.Arc.html#method.unwrap_or_clone)
+- [`Rc::unwrap_or_clone`](https://doc.rust-lang.org/stable/std/rc/struct.Rc.html#method.unwrap_or_clone)
+- [`Result::inspect`](https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.inspect)
+- [`Result::inspect_err`](https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.inspect_err)
+- [`Option::inspect`](https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.inspect)
+- [`type_name_of_val`](https://doc.rust-lang.org/stable/std/any/fn.type_name_of_val.html)
+- [`std::hash::{DefaultHasher, RandomState}`](https://doc.rust-lang.org/stable/std/hash/index.html#structs)
+ These were previously available only through `std::collections::hash_map`.
+- [`ptr::{from_ref, from_mut}`](https://doc.rust-lang.org/stable/std/ptr/fn.from_ref.html)
+- [`ptr::addr_eq`](https://doc.rust-lang.org/stable/std/ptr/fn.addr_eq.html)
+
+
+
+Cargo
+-----
+
+See [Cargo release notes](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-176-2024-02-08).
+
+
+
+Rustdoc
+-------
+
+- [Don't merge cfg and doc(cfg) attributes for re-exports](https://github.com/rust-lang/rust/pull/113091/)
+- [rustdoc: allow resizing the sidebar / hiding the top bar](https://github.com/rust-lang/rust/pull/115660/)
+- [rustdoc-search: add support for traits and associated types](https://github.com/rust-lang/rust/pull/116085/)
+- [rustdoc: Add highlighting for comments in items declaration](https://github.com/rust-lang/rust/pull/117869/)
+
+
+
+Compatibility Notes
+-------------------
+- [Add allow-by-default lint for unit bindings](https://github.com/rust-lang/rust/pull/112380/)
+ This is expected to be upgraded to a warning by default in a future Rust
+ release. Some macros emit bindings with type `()` with user-provided spans,
+ which means that this lint will warn for user code.
+- [Remove x86_64-sun-solaris target.](https://github.com/rust-lang/rust/pull/118091/)
+- [Remove asmjs-unknown-emscripten target](https://github.com/rust-lang/rust/pull/117338/)
+- [Report errors in jobserver inherited through environment variables](https://github.com/rust-lang/rust/pull/113730/)
+ This [may warn](https://github.com/rust-lang/rust/issues/120515) on benign problems too.
+- [Update the minimum external LLVM to 16.](https://github.com/rust-lang/rust/pull/117947/)
+- [Improve `print_tts`](https://github.com/rust-lang/rust/pull/114571/)
+ This change can break some naive manual parsing of token trees in proc macro
+ code which expect a particular structure after `.to_string()`, rather than just arbitrary Rust code.
+- [Make `IMPLIED_BOUNDS_ENTAILMENT` into a hard error from a lint](https://github.com/rust-lang/rust/pull/117984/)
+- [Vec's allocation behavior was changed when collecting some iterators](https://github.com/rust-lang/rust/pull/110353)
+ Allocation behavior is currently not specified, nevertheless changes can be surprising.
+ See [`impl FromIterator for Vec`](https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html#impl-FromIterator%3CT%3E-for-Vec%3CT%3E)
+ for more details.
+- [Properly reject `default` on free const items](https://github.com/rust-lang/rust/pull/117818/)
+
Version 1.75.0 (2023-12-28)
==========================
diff --git a/compiler/rustc_arena/src/lib.rs b/compiler/rustc_arena/src/lib.rs
index 90ddeec4bc7a4..5cb79d9eea53b 100644
--- a/compiler/rustc_arena/src/lib.rs
+++ b/compiler/rustc_arena/src/lib.rs
@@ -22,8 +22,6 @@
#![cfg_attr(test, feature(test))]
#![feature(strict_provenance)]
#![deny(unsafe_op_in_unsafe_fn)]
-#![deny(rustc::untranslatable_diagnostic)]
-#![deny(rustc::diagnostic_outside_of_impl)]
#![allow(internal_features)]
#![allow(clippy::mut_from_ref)] // Arena allocators are one of the places where this pattern is fine.
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index 4eb8169d0c37c..296a570de6b33 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -291,12 +291,16 @@ pub use crate::node_id::{NodeId, CRATE_NODE_ID, DUMMY_NODE_ID};
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)]
pub struct TraitBoundModifiers {
pub constness: BoundConstness,
+ pub asyncness: BoundAsyncness,
pub polarity: BoundPolarity,
}
impl TraitBoundModifiers {
- pub const NONE: Self =
- Self { constness: BoundConstness::Never, polarity: BoundPolarity::Positive };
+ pub const NONE: Self = Self {
+ constness: BoundConstness::Never,
+ asyncness: BoundAsyncness::Normal,
+ polarity: BoundPolarity::Positive,
+ };
}
/// The AST represents all type param bounds as types.
@@ -2562,6 +2566,25 @@ impl BoundConstness {
}
}
+/// The asyncness of a trait bound.
+#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)]
+#[derive(HashStable_Generic)]
+pub enum BoundAsyncness {
+ /// `Type: Trait`
+ Normal,
+ /// `Type: async Trait`
+ Async(Span),
+}
+
+impl BoundAsyncness {
+ pub fn as_str(self) -> &'static str {
+ match self {
+ Self::Normal => "",
+ Self::Async(_) => "async",
+ }
+ }
+}
+
#[derive(Clone, Encodable, Decodable, Debug)]
pub enum FnRetTy {
/// Returns type is not specified.
@@ -3300,7 +3323,7 @@ mod size_asserts {
static_assert_size!(ForeignItem, 96);
static_assert_size!(ForeignItemKind, 24);
static_assert_size!(GenericArg, 24);
- static_assert_size!(GenericBound, 72);
+ static_assert_size!(GenericBound, 88);
static_assert_size!(Generics, 40);
static_assert_size!(Impl, 136);
static_assert_size!(Item, 136);
diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs
index 76d838308b461..356e9fef439ed 100644
--- a/compiler/rustc_ast/src/lib.rs
+++ b/compiler/rustc_ast/src/lib.rs
@@ -18,8 +18,6 @@
#![feature(min_specialization)]
#![feature(negative_impls)]
#![feature(stmt_expr_attributes)]
-#![deny(rustc::untranslatable_diagnostic)]
-#![deny(rustc::diagnostic_outside_of_impl)]
#[macro_use]
extern crate rustc_macros;
diff --git a/compiler/rustc_ast/src/util/literal.rs b/compiler/rustc_ast/src/util/literal.rs
index 7b781ba1e1121..aaeb1bb9bff82 100644
--- a/compiler/rustc_ast/src/util/literal.rs
+++ b/compiler/rustc_ast/src/util/literal.rs
@@ -3,8 +3,7 @@
use crate::ast::{self, LitKind, MetaItemLit, StrStyle};
use crate::token::{self, Token};
use rustc_lexer::unescape::{
- byte_from_char, unescape_byte, unescape_c_string, unescape_char, unescape_literal, CStrUnit,
- Mode,
+ byte_from_char, unescape_byte, unescape_char, unescape_mixed, unescape_unicode, MixedUnit, Mode,
};
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::Span;
@@ -48,6 +47,9 @@ impl LitKind {
return Err(LitError::InvalidSuffix);
}
+ // For byte/char/string literals, chars and escapes have already been
+ // checked in the lexer (in `cook_lexer_literal`). So we can assume all
+ // chars and escapes are valid here.
Ok(match kind {
token::Bool => {
assert!(symbol.is_bool_lit());
@@ -56,12 +58,12 @@ impl LitKind {
token::Byte => {
return unescape_byte(symbol.as_str())
.map(LitKind::Byte)
- .map_err(|_| LitError::LexerError);
+ .map_err(|_| panic!("failed to unescape byte literal"));
}
token::Char => {
return unescape_char(symbol.as_str())
.map(LitKind::Char)
- .map_err(|_| LitError::LexerError);
+ .map_err(|_| panic!("failed to unescape char literal"));
}
// There are some valid suffixes for integer and float literals,
@@ -77,26 +79,22 @@ impl LitKind {
let s = symbol.as_str();
// Vanilla strings are so common we optimize for the common case where no chars
// requiring special behaviour are present.
- let symbol = if s.contains(['\\', '\r']) {
+ let symbol = if s.contains('\\') {
let mut buf = String::with_capacity(s.len());
- let mut error = Ok(());
// Force-inlining here is aggressive but the closure is
- // called on every char in the string, so it can be
- // hot in programs with many long strings.
- unescape_literal(
+ // called on every char in the string, so it can be hot in
+ // programs with many long strings containing escapes.
+ unescape_unicode(
s,
Mode::Str,
&mut #[inline(always)]
- |_, unescaped_char| match unescaped_char {
+ |_, c| match c {
Ok(c) => buf.push(c),
Err(err) => {
- if err.is_fatal() {
- error = Err(LitError::LexerError);
- }
+ assert!(!err.is_fatal(), "failed to unescape string literal")
}
},
);
- error?;
Symbol::intern(&buf)
} else {
symbol
@@ -104,86 +102,46 @@ impl LitKind {
LitKind::Str(symbol, ast::StrStyle::Cooked)
}
token::StrRaw(n) => {
- // Raw strings have no escapes, so we only need to check for invalid chars, and we
- // can reuse the symbol on success.
- let mut error = Ok(());
- unescape_literal(symbol.as_str(), Mode::RawStr, &mut |_, unescaped_char| {
- match unescaped_char {
- Ok(_) => {}
- Err(err) => {
- if err.is_fatal() {
- error = Err(LitError::LexerError);
- }
- }
- }
- });
- error?;
+ // Raw strings have no escapes so no work is needed here.
LitKind::Str(symbol, ast::StrStyle::Raw(n))
}
token::ByteStr => {
let s = symbol.as_str();
let mut buf = Vec::with_capacity(s.len());
- let mut error = Ok(());
- unescape_literal(s, Mode::ByteStr, &mut |_, c| match c {
+ unescape_unicode(s, Mode::ByteStr, &mut |_, c| match c {
Ok(c) => buf.push(byte_from_char(c)),
Err(err) => {
- if err.is_fatal() {
- error = Err(LitError::LexerError);
- }
+ assert!(!err.is_fatal(), "failed to unescape string literal")
}
});
- error?;
LitKind::ByteStr(buf.into(), StrStyle::Cooked)
}
token::ByteStrRaw(n) => {
- // Raw strings have no escapes, so we only need to check for invalid chars, and we
- // can convert the symbol directly to a `Lrc` on success.
- let s = symbol.as_str();
- let mut error = Ok(());
- unescape_literal(s, Mode::RawByteStr, &mut |_, c| match c {
- Ok(_) => {}
- Err(err) => {
- if err.is_fatal() {
- error = Err(LitError::LexerError);
- }
- }
- });
- LitKind::ByteStr(s.to_owned().into_bytes().into(), StrStyle::Raw(n))
+ // Raw strings have no escapes so we can convert the symbol
+ // directly to a `Lrc`.
+ let buf = symbol.as_str().to_owned().into_bytes();
+ LitKind::ByteStr(buf.into(), StrStyle::Raw(n))
}
token::CStr => {
let s = symbol.as_str();
let mut buf = Vec::with_capacity(s.len());
- let mut error = Ok(());
- unescape_c_string(s, Mode::CStr, &mut |_span, c| match c {
- Ok(CStrUnit::Byte(b)) => buf.push(b),
- Ok(CStrUnit::Char(c)) => {
+ unescape_mixed(s, Mode::CStr, &mut |_span, c| match c {
+ Ok(MixedUnit::Char(c)) => {
buf.extend_from_slice(c.encode_utf8(&mut [0; 4]).as_bytes())
}
+ Ok(MixedUnit::HighByte(b)) => buf.push(b),
Err(err) => {
- if err.is_fatal() {
- error = Err(LitError::LexerError);
- }
+ assert!(!err.is_fatal(), "failed to unescape C string literal")
}
});
- error?;
buf.push(0);
LitKind::CStr(buf.into(), StrStyle::Cooked)
}
token::CStrRaw(n) => {
- // Raw strings have no escapes, so we only need to check for invalid chars, and we
- // can convert the symbol directly to a `Lrc` on success.
- let s = symbol.as_str();
- let mut error = Ok(());
- unescape_c_string(s, Mode::RawCStr, &mut |_, c| match c {
- Ok(_) => {}
- Err(err) => {
- if err.is_fatal() {
- error = Err(LitError::LexerError);
- }
- }
- });
- error?;
- let mut buf = s.to_owned().into_bytes();
+ // Raw strings have no escapes so we can convert the symbol
+ // directly to a `Lrc` after appending the terminating NUL
+ // char.
+ let mut buf = symbol.as_str().to_owned().into_bytes();
buf.push(0);
LitKind::CStr(buf.into(), StrStyle::Raw(n))
}
diff --git a/compiler/rustc_ast_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl
index 8615016cda599..37e45379ba9a2 100644
--- a/compiler/rustc_ast_lowering/messages.ftl
+++ b/compiler/rustc_ast_lowering/messages.ftl
@@ -11,6 +11,12 @@ ast_lowering_argument = argument
ast_lowering_assoc_ty_parentheses =
parenthesized generic arguments cannot be used in associated type constraints
+ast_lowering_async_bound_not_on_trait =
+ `async` bound modifier only allowed on trait, not `{$descr}`
+
+ast_lowering_async_bound_only_for_fn_traits =
+ `async` bound modifier only allowed on `Fn`/`FnMut`/`FnOnce` traits
+
ast_lowering_async_coroutines_not_supported =
`async` coroutines are not yet supported
@@ -117,9 +123,6 @@ ast_lowering_never_pattern_with_guard =
a guard on a never pattern will never be run
.suggestion = remove this guard
-ast_lowering_not_supported_for_lifetime_binder_async_closure =
- `for<...>` binders on `async` closures are not currently supported
-
ast_lowering_previously_used_here = previously used here
ast_lowering_register1 = register `{$reg1_name}`
diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs
index 3742cf9d881d8..fd717e82d26df 100644
--- a/compiler/rustc_ast_lowering/src/asm.rs
+++ b/compiler/rustc_ast_lowering/src/asm.rs
@@ -205,7 +205,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&sym.qself,
&sym.path,
ParamMode::Optional,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Path),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);
hir::InlineAsmOperand::SymStatic { path, def_id }
diff --git a/compiler/rustc_ast_lowering/src/block.rs b/compiler/rustc_ast_lowering/src/block.rs
index d310f72f7a3f8..865a56b2c1f15 100644
--- a/compiler/rustc_ast_lowering/src/block.rs
+++ b/compiler/rustc_ast_lowering/src/block.rs
@@ -85,7 +85,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let ty = l
.ty
.as_ref()
- .map(|t| self.lower_ty(t, &ImplTraitContext::Disallowed(ImplTraitPosition::Variable)));
+ .map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Variable)));
let init = l.kind.init().map(|init| self.lower_expr(init));
let hir_id = self.lower_node_id(l.id);
let pat = self.lower_pat(&l.pat);
diff --git a/compiler/rustc_ast_lowering/src/delegation.rs b/compiler/rustc_ast_lowering/src/delegation.rs
index 6ccf39b0cb167..d1ba93f067553 100644
--- a/compiler/rustc_ast_lowering/src/delegation.rs
+++ b/compiler/rustc_ast_lowering/src/delegation.rs
@@ -218,7 +218,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&delegation.qself,
&delegation.path,
ParamMode::Optional,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Path),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);
let block = delegation.body.as_deref();
diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs
index 4843d36372dcc..6225358569573 100644
--- a/compiler/rustc_ast_lowering/src/errors.rs
+++ b/compiler/rustc_ast_lowering/src/errors.rs
@@ -1,9 +1,11 @@
-use rustc_errors::DiagnosticArgFromDisplay;
+use rustc_errors::{
+ codes::*, AddToDiagnostic, Diagnostic, DiagnosticArgFromDisplay, SubdiagnosticMessageOp,
+};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{symbol::Ident, Span, Symbol};
#[derive(Diagnostic, Clone, Copy)]
-#[diag(ast_lowering_generic_type_with_parentheses, code = "E0214")]
+#[diag(ast_lowering_generic_type_with_parentheses, code = E0214)]
pub struct GenericTypeWithParentheses {
#[primary_span]
#[label]
@@ -22,7 +24,7 @@ pub struct UseAngleBrackets {
}
#[derive(Diagnostic)]
-#[diag(ast_lowering_invalid_abi, code = "E0703")]
+#[diag(ast_lowering_invalid_abi, code = E0703)]
#[note]
pub struct InvalidAbi {
#[primary_span]
@@ -38,14 +40,8 @@ pub struct InvalidAbi {
pub struct InvalidAbiReason(pub &'static str);
-impl rustc_errors::AddToDiagnostic for InvalidAbiReason {
- fn add_to_diagnostic_with(self, diag: &mut rustc_errors::Diagnostic, _: F)
- where
- F: Fn(
- &mut rustc_errors::Diagnostic,
- rustc_errors::SubdiagnosticMessage,
- ) -> rustc_errors::SubdiagnosticMessage,
- {
+impl AddToDiagnostic for InvalidAbiReason {
+ fn add_to_diagnostic_with(self, diag: &mut Diagnostic, _: F) {
#[allow(rustc::untranslatable_diagnostic)]
diag.note(self.0);
}
@@ -89,7 +85,7 @@ pub enum AssocTyParenthesesSub {
}
#[derive(Diagnostic)]
-#[diag(ast_lowering_misplaced_impl_trait, code = "E0562")]
+#[diag(ast_lowering_misplaced_impl_trait, code = E0562)]
#[note]
pub struct MisplacedImplTrait<'a> {
#[primary_span]
@@ -114,7 +110,7 @@ pub struct UnderscoreExprLhsAssign {
}
#[derive(Diagnostic, Clone, Copy)]
-#[diag(ast_lowering_base_expression_double_dot, code = "E0797")]
+#[diag(ast_lowering_base_expression_double_dot, code = E0797)]
pub struct BaseExpressionDoubleDot {
#[primary_span]
#[suggestion(code = "/* expr */", applicability = "has-placeholders", style = "verbose")]
@@ -122,7 +118,7 @@ pub struct BaseExpressionDoubleDot {
}
#[derive(Diagnostic, Clone, Copy)]
-#[diag(ast_lowering_await_only_in_async_fn_and_blocks, code = "E0728")]
+#[diag(ast_lowering_await_only_in_async_fn_and_blocks, code = E0728)]
pub struct AwaitOnlyInAsyncFnAndBlocks {
#[primary_span]
#[label]
@@ -132,14 +128,14 @@ pub struct AwaitOnlyInAsyncFnAndBlocks {
}
#[derive(Diagnostic, Clone, Copy)]
-#[diag(ast_lowering_coroutine_too_many_parameters, code = "E0628")]
+#[diag(ast_lowering_coroutine_too_many_parameters, code = E0628)]
pub struct CoroutineTooManyParameters {
#[primary_span]
pub fn_decl_span: Span,
}
#[derive(Diagnostic, Clone, Copy)]
-#[diag(ast_lowering_closure_cannot_be_static, code = "E0697")]
+#[diag(ast_lowering_closure_cannot_be_static, code = E0697)]
pub struct ClosureCannotBeStatic {
#[primary_span]
pub fn_decl_span: Span,
@@ -154,14 +150,14 @@ pub struct FunctionalRecordUpdateDestructuringAssignment {
}
#[derive(Diagnostic, Clone, Copy)]
-#[diag(ast_lowering_async_coroutines_not_supported, code = "E0727")]
+#[diag(ast_lowering_async_coroutines_not_supported, code = E0727)]
pub struct AsyncCoroutinesNotSupported {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic, Clone, Copy)]
-#[diag(ast_lowering_inline_asm_unsupported_target, code = "E0472")]
+#[diag(ast_lowering_inline_asm_unsupported_target, code = E0472)]
pub struct InlineAsmUnsupportedTarget {
#[primary_span]
pub span: Span,
@@ -326,13 +322,6 @@ pub struct MisplacedRelaxTraitBound {
pub span: Span,
}
-#[derive(Diagnostic, Clone, Copy)]
-#[diag(ast_lowering_not_supported_for_lifetime_binder_async_closure)]
-pub struct NotSupportedForLifetimeBinderAsyncClosure {
- #[primary_span]
- pub span: Span,
-}
-
#[derive(Diagnostic)]
#[diag(ast_lowering_match_arm_with_no_body)]
pub struct MatchArmWithNoBody {
@@ -395,3 +384,18 @@ pub(crate) struct GenericParamDefaultInBinder {
#[primary_span]
pub span: Span,
}
+
+#[derive(Diagnostic)]
+#[diag(ast_lowering_async_bound_not_on_trait)]
+pub(crate) struct AsyncBoundNotOnTrait {
+ #[primary_span]
+ pub span: Span,
+ pub descr: &'static str,
+}
+
+#[derive(Diagnostic)]
+#[diag(ast_lowering_async_bound_only_for_fn_traits)]
+pub(crate) struct AsyncBoundOnlyForFnTraits {
+ #[primary_span]
+ pub span: Span,
+}
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs
index cc172b376573f..942aae3d53600 100644
--- a/compiler/rustc_ast_lowering/src/expr.rs
+++ b/compiler/rustc_ast_lowering/src/expr.rs
@@ -1,9 +1,10 @@
+use std::assert_matches::assert_matches;
+
use super::errors::{
AsyncCoroutinesNotSupported, AwaitOnlyInAsyncFnAndBlocks, BaseExpressionDoubleDot,
ClosureCannotBeStatic, CoroutineTooManyParameters,
FunctionalRecordUpdateDestructuringAssignment, InclusiveRangeWithNoEnd, MatchArmWithNoBody,
- NeverPatternWithBody, NeverPatternWithGuard, NotSupportedForLifetimeBinderAsyncClosure,
- UnderscoreExprLhsAssign,
+ NeverPatternWithBody, NeverPatternWithGuard, UnderscoreExprLhsAssign,
};
use super::ResolverAstLoweringExt;
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
@@ -98,7 +99,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
seg,
ParamMode::Optional,
ParenthesizedGenericArgs::Err,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Path),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Path),
+ None,
+ // Method calls can't have bound modifiers
None,
));
let receiver = self.lower_expr(receiver);
@@ -138,13 +141,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
ExprKind::Cast(expr, ty) => {
let expr = self.lower_expr(expr);
let ty =
- self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Cast));
+ self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Cast));
hir::ExprKind::Cast(expr, ty)
}
ExprKind::Type(expr, ty) => {
let expr = self.lower_expr(expr);
let ty =
- self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Cast));
+ self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Cast));
hir::ExprKind::Type(expr, ty)
}
ExprKind::AddrOf(k, m, ohs) => {
@@ -153,7 +156,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
ExprKind::Let(pat, scrutinee, span, is_recovered) => {
hir::ExprKind::Let(self.arena.alloc(hir::Let {
- hir_id: self.next_id(),
span: self.lower_span(*span),
pat: self.lower_pat(pat),
ty: None,
@@ -265,7 +267,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
qself,
path,
ParamMode::Optional,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Path),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);
hir::ExprKind::Path(qpath)
@@ -293,7 +295,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ExprKind::OffsetOf(container, fields) => hir::ExprKind::OffsetOf(
self.lower_ty(
container,
- &ImplTraitContext::Disallowed(ImplTraitPosition::OffsetOf),
+ ImplTraitContext::Disallowed(ImplTraitPosition::OffsetOf),
),
self.arena.alloc_from_iter(fields.iter().map(|&ident| self.lower_ident(ident))),
),
@@ -312,7 +314,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&se.qself,
&se.path,
ParamMode::Optional,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Path),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
)),
self.arena
@@ -1027,30 +1029,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn_decl_span: Span,
fn_arg_span: Span,
) -> hir::ExprKind<'hir> {
- if let &ClosureBinder::For { span, .. } = binder {
- self.dcx().emit_err(NotSupportedForLifetimeBinderAsyncClosure { span });
- }
-
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
+ assert_matches!(
+ coroutine_kind,
+ CoroutineKind::Async { .. },
+ "only async closures are supported currently"
+ );
+
let body = self.with_new_scopes(fn_decl_span, |this| {
+ let inner_decl =
+ FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
+
// Transform `async |x: u8| -> X { ... }` into
// `|x: u8| || -> X { ... }`.
let body_id = this.lower_body(|this| {
- let async_ret_ty = if let FnRetTy::Ty(ty) = &decl.output {
- let itctx = ImplTraitContext::Disallowed(ImplTraitPosition::AsyncBlock);
- Some(hir::FnRetTy::Return(this.lower_ty(ty, &itctx)))
- } else {
- None
- };
-
let (parameters, expr) = this.lower_coroutine_body_with_moved_arguments(
- decl,
+ &inner_decl,
|this| this.with_new_scopes(fn_decl_span, |this| this.lower_expr_mut(body)),
body.span,
coroutine_kind,
hir::CoroutineSource::Closure,
- async_ret_ty,
);
let hir_id = this.lower_node_id(coroutine_kind.closure_id());
@@ -1061,15 +1060,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
body_id
});
- let outer_decl =
- FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
-
let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params);
// We need to lower the declaration outside the new scope, because we
// have to conserve the state of being inside a loop condition for the
// closure argument types.
let fn_decl =
- self.lower_fn_decl(&outer_decl, closure_id, fn_decl_span, FnDeclKind::Closure, None);
+ self.lower_fn_decl(&decl, closure_id, fn_decl_span, FnDeclKind::Closure, None);
let c = self.arena.alloc(hir::Closure {
def_id: self.local_def_id(closure_id),
@@ -1080,7 +1076,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
body,
fn_decl_span: self.lower_span(fn_decl_span),
fn_arg_span: Some(self.lower_span(fn_arg_span)),
- kind: hir::ClosureKind::Closure,
+ // Lower this as a `CoroutineClosure`. That will ensure that HIR typeck
+ // knows that a `FnDecl` output type like `-> &str` actually means
+ // "coroutine that returns &str", rather than directly returning a `&str`.
+ kind: hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async),
constness: hir::Constness::NotConst,
});
hir::ExprKind::Closure(c)
@@ -1242,7 +1241,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
qself,
path,
ParamMode::Optional,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Path),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);
// Destructure like a tuple struct.
@@ -1262,7 +1261,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
qself,
path,
ParamMode::Optional,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Path),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);
// Destructure like a unit struct.
@@ -1287,7 +1286,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&se.qself,
&se.path,
ParamMode::Optional,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Path),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);
let fields_omitted = match &se.rest {
diff --git a/compiler/rustc_ast_lowering/src/index.rs b/compiler/rustc_ast_lowering/src/index.rs
index 993ddf00eb5b9..11aa6b250b129 100644
--- a/compiler/rustc_ast_lowering/src/index.rs
+++ b/compiler/rustc_ast_lowering/src/index.rs
@@ -15,7 +15,7 @@ struct NodeCollector<'a, 'hir> {
bodies: &'a SortedMap>,
/// Outputs
- nodes: IndexVec>>,
+ nodes: IndexVec>,
parenting: LocalDefIdMap,
/// The parent of this node
@@ -29,16 +29,19 @@ pub(super) fn index_hir<'hir>(
tcx: TyCtxt<'hir>,
item: hir::OwnerNode<'hir>,
bodies: &SortedMap>,
-) -> (IndexVec>>, LocalDefIdMap) {
- let mut nodes = IndexVec::new();
+ num_nodes: usize,
+) -> (IndexVec>, LocalDefIdMap) {
+ let zero_id = ItemLocalId::new(0);
+ let err_node = ParentedNode { parent: zero_id, node: Node::Err(item.span()) };
+ let mut nodes = IndexVec::from_elem_n(err_node, num_nodes);
// This node's parent should never be accessed: the owner's parent is computed by the
// hir_owner_parent query. Make it invalid (= ItemLocalId::MAX) to force an ICE whenever it is
// used.
- nodes.push(Some(ParentedNode { parent: ItemLocalId::INVALID, node: item.into() }));
+ nodes[zero_id] = ParentedNode { parent: ItemLocalId::INVALID, node: item.into() };
let mut collector = NodeCollector {
tcx,
owner: item.def_id(),
- parent_node: ItemLocalId::new(0),
+ parent_node: zero_id,
nodes,
bodies,
parenting: Default::default(),
@@ -54,6 +57,14 @@ pub(super) fn index_hir<'hir>(
OwnerNode::ForeignItem(item) => collector.visit_foreign_item(item),
};
+ for (local_id, node) in collector.nodes.iter_enumerated() {
+ if let Node::Err(span) = node.node {
+ let hir_id = HirId { owner: item.def_id(), local_id };
+ let msg = format!("ID {hir_id} not encountered when visiting item HIR");
+ tcx.dcx().span_delayed_bug(*span, msg);
+ }
+ }
+
(collector.nodes, collector.parenting)
}
@@ -88,7 +99,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
}
}
- self.nodes.insert(hir_id.local_id, ParentedNode { parent: self.parent_node, node });
+ self.nodes[hir_id.local_id] = ParentedNode { parent: self.parent_node, node };
}
fn with_parent(&mut self, parent_node_id: HirId, f: F) {
@@ -254,6 +265,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
}
fn visit_path_segment(&mut self, path_segment: &'hir PathSegment<'hir>) {
+ // FIXME: walk path segment with `path_segment.hir_id` parent.
self.insert(path_segment.ident.span, path_segment.hir_id, Node::PathSegment(path_segment));
intravisit::walk_path_segment(self, path_segment);
}
@@ -348,4 +360,23 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
self.visit_nested_foreign_item(id);
}
+
+ fn visit_where_predicate(&mut self, predicate: &'hir WherePredicate<'hir>) {
+ match predicate {
+ WherePredicate::BoundPredicate(pred) => {
+ self.insert(pred.span, pred.hir_id, Node::WhereBoundPredicate(pred));
+ self.with_parent(pred.hir_id, |this| {
+ intravisit::walk_where_predicate(this, predicate)
+ })
+ }
+ _ => intravisit::walk_where_predicate(self, predicate),
+ }
+ }
+
+ fn visit_array_length(&mut self, len: &'hir ArrayLen) {
+ match len {
+ ArrayLen::Infer(inf) => self.insert(inf.span, inf.hir_id, Node::ArrayLenInfer(inf)),
+ ArrayLen::Body(..) => intravisit::walk_array_len(self, len),
+ }
+ }
}
diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs
index dd3f7289a60b2..75410323f97df 100644
--- a/compiler/rustc_ast_lowering/src/item.rs
+++ b/compiler/rustc_ast_lowering/src/item.rs
@@ -25,7 +25,7 @@ pub(super) struct ItemLowerer<'a, 'hir> {
pub(super) tcx: TyCtxt<'hir>,
pub(super) resolver: &'a mut ResolverAstLowering,
pub(super) ast_index: &'a IndexSlice>,
- pub(super) owners: &'a mut IndexVec>>,
+ pub(super) owners: &'a mut IndexVec>,
}
/// When we have a ty alias we *may* have two where clauses. To give the best diagnostics, we set the span
@@ -64,10 +64,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
}
}
- pub(super) fn lower_node(
- &mut self,
- def_id: LocalDefId,
- ) -> hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>> {
+ pub(super) fn lower_node(&mut self, def_id: LocalDefId) -> hir::MaybeOwner<'hir> {
let owner = self.owners.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom);
if let hir::MaybeOwner::Phantom = owner {
let node = self.ast_index[def_id];
@@ -192,7 +189,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
Const::No,
id,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| {
this.lower_const_item(ty, span, expr.as_deref(), ImplTraitPosition::ConstTy)
},
@@ -221,7 +218,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let itctx = ImplTraitContext::Universal;
let (generics, decl) =
- this.lower_generics(generics, header.constness, id, &itctx, |this| {
+ this.lower_generics(generics, header.constness, id, itctx, |this| {
this.lower_fn_decl(
decl,
id,
@@ -266,7 +263,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&generics,
Const::No,
id,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| match ty {
None => {
let guar = this.dcx().span_delayed_bug(
@@ -277,7 +274,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
Some(ty) => this.lower_ty(
ty,
- &ImplTraitContext::TypeAliasesOpaqueTy { in_assoc_ty: false },
+ ImplTraitContext::TypeAliasesOpaqueTy { in_assoc_ty: false },
),
},
);
@@ -288,7 +285,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
Const::No,
id,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| {
this.arena.alloc_from_iter(
enum_definition.variants.iter().map(|x| this.lower_variant(x)),
@@ -302,7 +299,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
Const::No,
id,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| this.lower_variant_data(hir_id, struct_def),
);
hir::ItemKind::Struct(struct_def, generics)
@@ -312,7 +309,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
Const::No,
id,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| this.lower_variant_data(hir_id, vdata),
);
hir::ItemKind::Union(vdata, generics)
@@ -342,23 +339,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
// parent lifetime.
let itctx = ImplTraitContext::Universal;
let (generics, (trait_ref, lowered_ty)) =
- self.lower_generics(ast_generics, *constness, id, &itctx, |this| {
- let constness = match *constness {
- Const::Yes(span) => BoundConstness::Maybe(span),
- Const::No => BoundConstness::Never,
+ self.lower_generics(ast_generics, *constness, id, itctx, |this| {
+ let modifiers = TraitBoundModifiers {
+ constness: match *constness {
+ Const::Yes(span) => BoundConstness::Maybe(span),
+ Const::No => BoundConstness::Never,
+ },
+ asyncness: BoundAsyncness::Normal,
+ // we don't use this in bound lowering
+ polarity: BoundPolarity::Positive,
};
let trait_ref = trait_ref.as_ref().map(|trait_ref| {
this.lower_trait_ref(
- constness,
+ modifiers,
trait_ref,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Trait),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Trait),
)
});
let lowered_ty = this.lower_ty(
ty,
- &ImplTraitContext::Disallowed(ImplTraitPosition::ImplSelf),
+ ImplTraitContext::Disallowed(ImplTraitPosition::ImplSelf),
);
(trait_ref, lowered_ty)
@@ -398,11 +400,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
constness,
id,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| {
let bounds = this.lower_param_bounds(
bounds,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
);
let items = this.arena.alloc_from_iter(
items.iter().map(|item| this.lower_trait_item_ref(item)),
@@ -418,11 +420,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
Const::No,
id,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| {
this.lower_param_bounds(
bounds,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
)
},
);
@@ -462,7 +464,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
body: Option<&Expr>,
impl_trait_position: ImplTraitPosition,
) -> (&'hir hir::Ty<'hir>, hir::BodyId) {
- let ty = self.lower_ty(ty, &ImplTraitContext::Disallowed(impl_trait_position));
+ let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(impl_trait_position));
(ty, self.lower_const_body(span, body))
}
@@ -496,8 +498,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}
- let res =
- self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
+ let res = self.lower_import_res(id, path.span);
let path = self.lower_use_path(res, &path, ParamMode::Explicit);
hir::ItemKind::Use(path, hir::UseKind::Single)
}
@@ -533,7 +534,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
// for that we return the `{}` import (called the
// `ListStem`).
- let prefix = Path { segments, span: prefix.span.to(path.span), tokens: None };
+ let span = prefix.span.to(path.span);
+ let prefix = Path { segments, span, tokens: None };
// Add all the nested `PathListItem`s to the HIR.
for &(ref use_tree, id) in trees {
@@ -567,9 +569,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
});
}
- let res =
- self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
- let path = self.lower_use_path(res, &prefix, ParamMode::Explicit);
+ let path = if trees.is_empty() && !prefix.segments.is_empty() {
+ // For empty lists we need to lower the prefix so it is checked for things
+ // like stability later.
+ let res = self.lower_import_res(id, span);
+ self.lower_use_path(res, &prefix, ParamMode::Explicit)
+ } else {
+ // For non-empty lists we can just drop all the data, the prefix is already
+ // present in HIR as a part of nested imports.
+ self.arena.alloc(hir::UsePath { res: smallvec![], segments: &[], span })
+ };
hir::ItemKind::Use(path, hir::UseKind::ListStem)
}
}
@@ -624,7 +633,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let fdec = &sig.decl;
let itctx = ImplTraitContext::Universal;
let (generics, (fn_dec, fn_args)) =
- self.lower_generics(generics, Const::No, i.id, &itctx, |this| {
+ self.lower_generics(generics, Const::No, i.id, itctx, |this| {
(
// Disallow `impl Trait` in foreign items.
this.lower_fn_decl(
@@ -641,8 +650,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
}
ForeignItemKind::Static(t, m, _) => {
- let ty = self
- .lower_ty(t, &ImplTraitContext::Disallowed(ImplTraitPosition::StaticTy));
+ let ty =
+ self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::StaticTy));
hir::ForeignItemKind::Static(ty, *m)
}
ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
@@ -713,11 +722,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
qself,
path,
ParamMode::ExplicitNamed, // no `'_` in declarations (Issue #61124)
- &ImplTraitContext::Disallowed(ImplTraitPosition::FieldTy),
+ ImplTraitContext::Disallowed(ImplTraitPosition::FieldTy),
);
self.arena.alloc(t)
} else {
- self.lower_ty(&f.ty, &ImplTraitContext::Disallowed(ImplTraitPosition::FieldTy))
+ self.lower_ty(&f.ty, ImplTraitContext::Disallowed(ImplTraitPosition::FieldTy))
};
let hir_id = self.lower_node_id(f.id);
self.lower_attrs(hir_id, &f.attrs);
@@ -746,12 +755,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
Const::No,
i.id,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| {
- let ty = this.lower_ty(
- ty,
- &ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy),
- );
+ let ty = this
+ .lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
let body = expr.as_ref().map(|x| this.lower_const_body(i.span, Some(x)));
hir::TraitItemKind::Const(ty, body)
@@ -794,18 +801,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
&generics,
Const::No,
i.id,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| {
let ty = ty.as_ref().map(|x| {
this.lower_ty(
x,
- &ImplTraitContext::Disallowed(ImplTraitPosition::AssocTy),
+ ImplTraitContext::Disallowed(ImplTraitPosition::AssocTy),
)
});
hir::TraitItemKind::Type(
this.lower_param_bounds(
bounds,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
),
ty,
)
@@ -873,10 +880,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics,
Const::No,
i.id,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| {
- let ty = this
- .lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
+ let ty =
+ this.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
let body = this.lower_const_body(i.span, expr.as_deref());
hir::ImplItemKind::Const(ty, body)
@@ -907,7 +914,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&generics,
Const::No,
i.id,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| match ty {
None => {
let guar = this.dcx().span_delayed_bug(
@@ -920,7 +927,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
Some(ty) => {
let ty = this.lower_ty(
ty,
- &ImplTraitContext::TypeAliasesOpaqueTy { in_assoc_ty: true },
+ ImplTraitContext::TypeAliasesOpaqueTy { in_assoc_ty: true },
);
hir::ImplItemKind::Type(ty)
}
@@ -1089,7 +1096,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
body.span,
coroutine_kind,
hir::CoroutineSource::Fn,
- None,
);
// FIXME(async_fn_track_caller): Can this be moved above?
@@ -1111,7 +1117,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
body_span: Span,
coroutine_kind: CoroutineKind,
coroutine_source: hir::CoroutineSource,
- return_type_hint: Option>,
) -> (&'hir [hir::Param<'hir>], hir::Expr<'hir>) {
let mut parameters: Vec> = Vec::new();
let mut statements: Vec> = Vec::new();
@@ -1281,12 +1286,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
};
let closure_id = coroutine_kind.closure_id();
let coroutine_expr = self.make_desugared_coroutine_expr(
- // FIXME(async_closures): This should only move locals,
- // and not upvars. Capturing closure upvars by ref doesn't
- // work right now anyways, so whatever.
- CaptureBy::Value { move_kw: rustc_span::DUMMY_SP },
+ // The default capture mode here is by-ref. Later on during upvar analysis,
+ // we will force the captured arguments to by-move, but for async closures,
+ // we want to make sure that we avoid unnecessarily moving captures, or else
+ // all async closures would default to `FnOnce` as their calling mode.
+ CaptureBy::Ref,
closure_id,
- return_type_hint,
+ None,
body_span,
desugaring_kind,
coroutine_source,
@@ -1315,7 +1321,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// synthesize a host effect param for them. We reject `const` on them during AST validation.
let constness = if kind == FnDeclKind::Inherent { sig.header.constness } else { Const::No };
let itctx = ImplTraitContext::Universal;
- let (generics, decl) = self.lower_generics(generics, constness, id, &itctx, |this| {
+ let (generics, decl) = self.lower_generics(generics, constness, id, itctx, |this| {
this.lower_fn_decl(&sig.decl, id, sig.span, kind, coroutine_kind)
});
(generics, hir::FnSig { header, decl, span: self.lower_span(sig.span) })
@@ -1393,7 +1399,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
generics: &Generics,
constness: Const,
parent_node_id: NodeId,
- itctx: &ImplTraitContext,
+ itctx: ImplTraitContext,
f: impl FnOnce(&mut Self) -> T,
) -> (&'hir hir::Generics<'hir>, T) {
debug_assert!(self.impl_trait_defs.is_empty());
@@ -1599,7 +1605,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
bounds: &[GenericBound],
colon_span: Option,
parent_span: Span,
- itctx: &ImplTraitContext,
+ itctx: ImplTraitContext,
origin: PredicateOrigin,
) -> Option> {
// Do not create a clause if we do not have anything inside it.
@@ -1673,10 +1679,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
bound_generic_params: self
.lower_generic_params(bound_generic_params, hir::GenericParamSource::Binder),
bounded_ty: self
- .lower_ty(bounded_ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Bound)),
+ .lower_ty(bounded_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Bound)),
bounds: self.lower_param_bounds(
bounds,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
),
span: self.lower_span(*span),
origin: PredicateOrigin::WhereClause,
@@ -1687,7 +1693,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
lifetime: self.lower_lifetime(lifetime),
bounds: self.lower_param_bounds(
bounds,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
),
in_where_clause: true,
})
@@ -1695,9 +1701,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
WherePredicate::EqPredicate(WhereEqPredicate { lhs_ty, rhs_ty, span }) => {
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
lhs_ty: self
- .lower_ty(lhs_ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Bound)),
+ .lower_ty(lhs_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Bound)),
rhs_ty: self
- .lower_ty(rhs_ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Bound)),
+ .lower_ty(rhs_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Bound)),
span: self.lower_span(*span),
})
}
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs
index ee1f5d5bd7a3f..dc427f607f5d2 100644
--- a/compiler/rustc_ast_lowering/src/lib.rs
+++ b/compiler/rustc_ast_lowering/src/lib.rs
@@ -33,10 +33,9 @@
#![allow(internal_features)]
#![feature(rustdoc_internals)]
#![doc(rust_logo)]
+#![feature(assert_matches)]
#![feature(box_patterns)]
#![feature(let_chains)]
-#![deny(rustc::untranslatable_diagnostic)]
-#![deny(rustc::diagnostic_outside_of_impl)]
#[macro_use]
extern crate tracing;
@@ -63,7 +62,7 @@ use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
use rustc_session::parse::{add_feature_diagnostics, feature_err};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{DesugaringKind, Span, DUMMY_SP};
-use smallvec::SmallVec;
+use smallvec::{smallvec, SmallVec};
use std::collections::hash_map::Entry;
use thin_vec::ThinVec;
@@ -99,7 +98,7 @@ struct LoweringContext<'a, 'hir> {
/// Attributes inside the owner being lowered.
attrs: SortedMap,
/// Collect items that were created by lowering the current owner.
- children: Vec<(LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>)>,
+ children: Vec<(LocalDefId, hir::MaybeOwner<'hir>)>,
coroutine_kind: Option,
@@ -131,6 +130,7 @@ struct LoweringContext<'a, 'hir> {
allow_gen_future: Lrc<[Symbol]>,
allow_async_iterator: Lrc<[Symbol]>,
allow_for_await: Lrc<[Symbol]>,
+ allow_async_fn_traits: Lrc<[Symbol]>,
/// Mapping from generics `def_id`s to TAIT generics `def_id`s.
/// For each captured lifetime (e.g., 'a), we create a new lifetime parameter that is a generic
@@ -176,6 +176,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
[sym::gen_future].into()
},
allow_for_await: [sym::async_iterator].into(),
+ allow_async_fn_traits: [sym::async_fn_traits].into(),
// FIXME(gen_blocks): how does `closure_track_caller`/`async_fn_track_caller`
// interact with `gen`/`async gen` blocks
allow_async_iterator: [sym::gen_future, sym::async_iterator].into(),
@@ -296,7 +297,6 @@ enum ImplTraitPosition {
Path,
Variable,
Trait,
- AsyncBlock,
Bound,
Generic,
ExternFnParam,
@@ -323,7 +323,6 @@ impl std::fmt::Display for ImplTraitPosition {
ImplTraitPosition::Path => "paths",
ImplTraitPosition::Variable => "the type of variable bindings",
ImplTraitPosition::Trait => "traits",
- ImplTraitPosition::AsyncBlock => "async blocks",
ImplTraitPosition::Bound => "bounds",
ImplTraitPosition::Generic => "generics",
ImplTraitPosition::ExternFnParam => "`extern fn` parameters",
@@ -415,7 +414,7 @@ fn index_crate<'a>(
/// This hash will then be part of the crate_hash which is stored in the metadata.
fn compute_hir_hash(
tcx: TyCtxt<'_>,
- owners: &IndexSlice>>,
+ owners: &IndexSlice>,
) -> Fingerprint {
let mut hir_body_nodes: Vec<_> = owners
.iter_enumerated()
@@ -674,7 +673,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} else {
(None, None)
};
- let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies);
+ let num_nodes = self.item_local_id_counter.as_usize();
+ let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };
let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash };
@@ -749,8 +749,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.resolver.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
}
- fn expect_full_res_from_use(&mut self, id: NodeId) -> impl Iterator- > {
- self.resolver.get_import_res(id).present_items()
+ fn lower_import_res(&mut self, id: NodeId, span: Span) -> SmallVec<[Res; 3]> {
+ let res = self.resolver.get_import_res(id).present_items();
+ let res: SmallVec<_> = res.map(|res| self.lower_res(res)).collect();
+ if res.is_empty() {
+ self.dcx().span_delayed_bug(span, "no resolution for an import");
+ return smallvec![Res::Err];
+ }
+ res
}
fn make_lang_item_qpath(&mut self, lang_item: hir::LangItem, span: Span) -> hir::QPath<'hir> {
@@ -999,7 +1005,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_assoc_ty_constraint(
&mut self,
constraint: &AssocConstraint,
- itctx: &ImplTraitContext,
+ itctx: ImplTraitContext,
) -> hir::TypeBinding<'hir> {
debug!("lower_assoc_ty_constraint(constraint={:?}, itctx={:?})", constraint, itctx);
// lower generic arguments of identifier in constraint
@@ -1078,9 +1084,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::TypeBindingKind::Equality { term }
}
AssocConstraintKind::Bound { bounds } => {
- enum DesugarKind<'a> {
+ enum DesugarKind {
ImplTrait,
- Error(&'a ImplTraitPosition),
+ Error(ImplTraitPosition),
Bound,
}
@@ -1156,7 +1162,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
DesugarKind::Error(position) => {
let guar = self.dcx().emit_err(errors::MisplacedAssocTyBinding {
span: constraint.span,
- position: DiagnosticArgFromDisplay(position),
+ position: DiagnosticArgFromDisplay(&position),
});
let err_ty =
&*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
@@ -1203,7 +1209,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_generic_arg(
&mut self,
arg: &ast::GenericArg,
- itctx: &ImplTraitContext,
+ itctx: ImplTraitContext,
) -> hir::GenericArg<'hir> {
match arg {
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(lt)),
@@ -1282,7 +1288,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
#[instrument(level = "debug", skip(self))]
- fn lower_ty(&mut self, t: &Ty, itctx: &ImplTraitContext) -> &'hir hir::Ty<'hir> {
+ fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> {
self.arena.alloc(self.lower_ty_direct(t, itctx))
}
@@ -1292,7 +1298,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
qself: &Option>,
path: &Path,
param_mode: ParamMode,
- itctx: &ImplTraitContext,
+ itctx: ImplTraitContext,
) -> hir::Ty<'hir> {
// Check whether we should interpret this as a bare trait object.
// This check mirrors the one in late resolution. We only introduce this special case in
@@ -1311,7 +1317,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: t.span,
},
itctx,
- ast::BoundConstness::Never,
+ TraitBoundModifiers::NONE,
);
let bounds = this.arena.alloc_from_iter([bound]);
let lifetime_bound = this.elided_dyn_bound(t.span);
@@ -1334,7 +1340,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.ty(span, hir::TyKind::Tup(tys))
}
- fn lower_ty_direct(&mut self, t: &Ty, itctx: &ImplTraitContext) -> hir::Ty<'hir> {
+ fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
let kind = match &t.kind {
TyKind::Infer => hir::TyKind::Infer,
TyKind::Err => {
@@ -1426,7 +1432,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
itctx,
// Still, don't pass along the constness here; we don't want to
// synthesize any host effect args, it'd only cause problems.
- ast::BoundConstness::Never,
+ TraitBoundModifiers {
+ constness: BoundConstness::Never,
+ ..*modifiers
+ },
))
}
BoundPolarity::Maybe(_) => None,
@@ -1450,13 +1459,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ImplTraitContext::ReturnPositionOpaqueTy { origin, fn_kind } => self
.lower_opaque_impl_trait(
span,
- *origin,
+ origin,
*def_node_id,
bounds,
- Some(*fn_kind),
+ Some(fn_kind),
itctx,
),
- &ImplTraitContext::TypeAliasesOpaqueTy { in_assoc_ty } => self
+ ImplTraitContext::TypeAliasesOpaqueTy { in_assoc_ty } => self
.lower_opaque_impl_trait(
span,
hir::OpaqueTyOrigin::TyAlias { in_assoc_ty },
@@ -1503,9 +1512,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
.create_feature_err(
MisplacedImplTrait {
span: t.span,
- position: DiagnosticArgFromDisplay(position),
+ position: DiagnosticArgFromDisplay(&position),
},
- *feature,
+ feature,
)
.emit();
hir::TyKind::Err(guar)
@@ -1513,7 +1522,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ImplTraitContext::Disallowed(position) => {
let guar = self.dcx().emit_err(MisplacedImplTrait {
span: t.span,
- position: DiagnosticArgFromDisplay(position),
+ position: DiagnosticArgFromDisplay(&position),
});
hir::TyKind::Err(guar)
}
@@ -1571,7 +1580,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
opaque_ty_node_id: NodeId,
bounds: &GenericBounds,
fn_kind: Option,
- itctx: &ImplTraitContext,
+ itctx: ImplTraitContext,
) -> hir::TyKind<'hir> {
// Make sure we know that some funky desugaring has been going on here.
// This is a first: there is code in other places like for loop
@@ -1838,7 +1847,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ImplTraitContext::Disallowed(ImplTraitPosition::PointerParam)
}
};
- self.lower_ty_direct(¶m.ty, &itctx)
+ self.lower_ty_direct(¶m.ty, itctx)
}));
let output = match coro {
@@ -1866,7 +1875,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ImplTraitContext::Disallowed(ImplTraitPosition::PointerReturn)
}
};
- hir::FnRetTy::Return(self.lower_ty(ty, &itctx))
+ hir::FnRetTy::Return(self.lower_ty(ty, itctx))
}
FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(*span)),
},
@@ -1967,7 +1976,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
output: &FnRetTy,
coro: CoroutineKind,
opaque_ty_span: Span,
- nested_impl_trait_context: ImplTraitContext,
+ itctx: ImplTraitContext,
) -> hir::GenericBound<'hir> {
// Compute the `T` in `Future