diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 853f43e15e307..26e589c092eda 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -294,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: {}
@@ -319,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
@@ -332,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
@@ -343,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
@@ -354,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
@@ -364,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
@@ -375,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"
diff --git a/Cargo.lock b/Cargo.lock
index 25f4959bf141f..fff30b0f27bcb 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",
@@ -556,7 +556,7 @@ checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
[[package]]
name = "clippy"
-version = "0.1.77"
+version = "0.1.78"
dependencies = [
"anstream",
"clippy_config",
@@ -584,7 +584,7 @@ dependencies = [
[[package]]
name = "clippy_config"
-version = "0.1.77"
+version = "0.1.78"
dependencies = [
"rustc-semver",
"serde",
@@ -607,7 +607,7 @@ dependencies = [
[[package]]
name = "clippy_lints"
-version = "0.1.77"
+version = "0.1.78"
dependencies = [
"arrayvec",
"cargo_metadata 0.18.0",
@@ -632,7 +632,7 @@ dependencies = [
[[package]]
name = "clippy_utils"
-version = "0.1.77"
+version = "0.1.78"
dependencies = [
"arrayvec",
"clippy_config",
@@ -1003,7 +1003,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
[[package]]
name = "declare_clippy_lint"
-version = "0.1.77"
+version = "0.1.78"
dependencies = [
"itertools",
"quote",
@@ -2090,9 +2090,9 @@ dependencies = [
[[package]]
name = "jobserver"
-version = "0.1.27"
+version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d"
+checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6"
dependencies = [
"libc",
]
@@ -2169,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",
]
@@ -4374,6 +4374,7 @@ dependencies = [
"rustc_middle",
"rustc_session",
"rustc_span",
+ "rustc_ty_utils",
"tracing",
]
@@ -5321,6 +5322,7 @@ version = "0.0.0"
dependencies = [
"core",
"getopts",
+ "libc",
"panic_abort",
"panic_unwind",
"std",
@@ -6406,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..20e317a4d236a 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -1,3 +1,96 @@
+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/)
+- [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_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 51bb8a96fad26..6225358569573 100644
--- a/compiler/rustc_ast_lowering/src/errors.rs
+++ b/compiler/rustc_ast_lowering/src/errors.rs
@@ -1,4 +1,6 @@
-use rustc_errors::{codes::*, DiagnosticArgFromDisplay};
+use rustc_errors::{
+ codes::*, AddToDiagnostic, Diagnostic, DiagnosticArgFromDisplay, SubdiagnosticMessageOp,
+};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{symbol::Ident, Span, Symbol};
@@ -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);
}
@@ -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 0ad4a59c17eb1..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) => {
@@ -264,7 +267,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
qself,
path,
ParamMode::Optional,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Path),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);
hir::ExprKind::Path(qpath)
@@ -292,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))),
),
@@ -311,7 +314,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&se.qself,
&se.path,
ParamMode::Optional,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Path),
+ ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
)),
self.arena
@@ -1026,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());
@@ -1060,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),
@@ -1079,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)
@@ -1241,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.
@@ -1261,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.
@@ -1286,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..fb52f9cf58f26 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,21 @@ 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);
+ // Condition should match `build_reduced_graph_for_use_tree`.
+ let path = if trees.is_empty()
+ && !(prefix.segments.is_empty()
+ || prefix.segments.len() == 1
+ && prefix.segments[0].ident.name == kw::PathRoot)
+ {
+ // 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 +638,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 +655,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 +727,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 +760,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 +806,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 +885,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 +919,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 +932,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 +1101,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 +1122,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 +1291,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 +1326,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 +1404,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 +1610,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 +1684,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 +1698,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 +1706,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 3621844efc8d2..4ef9c7607be5e 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,32 +1084,30 @@ 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,
}
// Piggy-back on the `impl Trait` context to figure out the correct behavior.
let desugar_kind = match itctx {
- // We are in the return position:
- //
- // fn foo() -> impl Iterator
- //
- // so desugar to
- //
- // fn foo() -> impl Iterator
-
- ImplTraitContext::ReturnPositionOpaqueTy { .. }
- | ImplTraitContext::TypeAliasesOpaqueTy { .. } => DesugarKind::ImplTrait,
-
- // We are in the argument position, but within a dyn type:
+ // in an argument, RPIT, or TAIT, if we are within a dyn type:
//
// fn foo(x: dyn Iterator)
//
- // so desugar to
+ // then desugar to:
//
// fn foo(x: dyn Iterator
- )
- ImplTraitContext::Universal if self.is_in_dyn_type => DesugarKind::ImplTrait,
+ //
+ // This is because dyn traits must have all of their associated types specified.
+ ImplTraitContext::ReturnPositionOpaqueTy { .. }
+ | ImplTraitContext::TypeAliasesOpaqueTy { .. }
+ | ImplTraitContext::Universal
+ if self.is_in_dyn_type =>
+ {
+ DesugarKind::ImplTrait
+ }
ImplTraitContext::Disallowed(position) if self.is_in_dyn_type => {
DesugarKind::Error(position)
@@ -1156,7 +1160,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 +1207,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 +1286,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 +1296,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 +1315,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 +1338,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 +1430,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 +1457,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 +1510,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 +1520,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 +1578,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 +1845,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 +1873,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 +1974,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