diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 853f43e15e30..02a2193ad883 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
@@ -365,7 +365,7 @@ jobs:
- 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"
+ 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"
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
SELECT_XCODE: /Applications/Xcode_13.4.1.app
USE_XCODE_CLANG: 1
diff --git a/Cargo.lock b/Cargo.lock
index 25f4959bf141..f6512caf6584 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",
@@ -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",
]
@@ -6406,18 +6406,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 3fb74b52292c..038a83cde84d 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/)
+- [Warn against ambiguous wide pointer 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_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index 4eb8169d0c37..296a570de6b3 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_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl
index 8615016cda59..e0dc227ca4c0 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
diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs
index 51bb8a96fad2..7658dfa5d5f6 100644
--- a/compiler/rustc_ast_lowering/src/errors.rs
+++ b/compiler/rustc_ast_lowering/src/errors.rs
@@ -395,3 +395,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 0ad4a59c17eb..3b00a84e67e9 100644
--- a/compiler/rustc_ast_lowering/src/expr.rs
+++ b/compiler/rustc_ast_lowering/src/expr.rs
@@ -100,6 +100,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
ParenthesizedGenericArgs::Err,
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
+ // Method calls can't have bound modifiers
+ None,
));
let receiver = self.lower_expr(receiver);
let args =
diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs
index dd3f7289a60b..987f74af0a42 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];
@@ -343,14 +340,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
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,
+ 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),
)
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs
index 3621844efc8d..c0b6922fc051 100644
--- a/compiler/rustc_ast_lowering/src/lib.rs
+++ b/compiler/rustc_ast_lowering/src/lib.rs
@@ -99,7 +99,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 +131,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 +177,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(),
@@ -415,7 +417,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()
@@ -1311,7 +1313,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);
@@ -1426,7 +1428,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,
@@ -2019,7 +2024,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
) -> hir::GenericBound<'hir> {
match tpb {
GenericBound::Trait(p, modifiers) => hir::GenericBound::Trait(
- self.lower_poly_trait_ref(p, itctx, modifiers.constness.into()),
+ self.lower_poly_trait_ref(p, itctx, *modifiers),
self.lower_trait_bound_modifiers(*modifiers),
),
GenericBound::Outlives(lifetime) => {
@@ -2192,7 +2197,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_trait_ref(
&mut self,
- constness: ast::BoundConstness,
+ modifiers: ast::TraitBoundModifiers,
p: &TraitRef,
itctx: &ImplTraitContext,
) -> hir::TraitRef<'hir> {
@@ -2202,7 +2207,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&p.path,
ParamMode::Explicit,
itctx,
- Some(constness),
+ Some(modifiers),
) {
hir::QPath::Resolved(None, path) => path,
qpath => panic!("lower_trait_ref: unexpected QPath `{qpath:?}`"),
@@ -2215,11 +2220,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self,
p: &PolyTraitRef,
itctx: &ImplTraitContext,
- constness: ast::BoundConstness,
+ modifiers: ast::TraitBoundModifiers,
) -> hir::PolyTraitRef<'hir> {
let bound_generic_params =
self.lower_lifetime_binder(p.trait_ref.ref_id, &p.bound_generic_params);
- let trait_ref = self.lower_trait_ref(constness, &p.trait_ref, itctx);
+ let trait_ref = self.lower_trait_ref(modifiers, &p.trait_ref, itctx);
hir::PolyTraitRef { bound_generic_params, trait_ref, span: self.lower_span(p.span) }
}
diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs
index c679ee56fcd8..b58ac5c3dae4 100644
--- a/compiler/rustc_ast_lowering/src/path.rs
+++ b/compiler/rustc_ast_lowering/src/path.rs
@@ -1,17 +1,21 @@
use crate::ImplTraitPosition;
-use super::errors::{GenericTypeWithParentheses, UseAngleBrackets};
+use super::errors::{
+ AsyncBoundNotOnTrait, AsyncBoundOnlyForFnTraits, GenericTypeWithParentheses, UseAngleBrackets,
+};
use super::ResolverAstLoweringExt;
use super::{GenericArgsCtor, LifetimeRes, ParenthesizedGenericArgs};
use super::{ImplTraitContext, LoweringContext, ParamMode};
use rustc_ast::{self as ast, *};
+use rustc_data_structures::sync::Lrc;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, PartialRes, Res};
+use rustc_hir::def_id::DefId;
use rustc_hir::GenericArg;
use rustc_middle::span_bug;
use rustc_span::symbol::{kw, sym, Ident};
-use rustc_span::{BytePos, Span, DUMMY_SP};
+use rustc_span::{BytePos, DesugaringKind, Span, Symbol, DUMMY_SP};
use smallvec::{smallvec, SmallVec};
@@ -24,8 +28,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
p: &Path,
param_mode: ParamMode,
itctx: &ImplTraitContext,
- // constness of the impl/bound if this is a trait path
- constness: Option,
+ // modifiers of the impl/bound if this is a trait path
+ modifiers: Option,
) -> hir::QPath<'hir> {
let qself_position = qself.as_ref().map(|q| q.position);
let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx));
@@ -35,10 +39,36 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let base_res = partial_res.base_res();
let unresolved_segments = partial_res.unresolved_segments();
+ let mut res = self.lower_res(base_res);
+
+ // When we have an `async` kw on a bound, map the trait it resolves to.
+ let mut bound_modifier_allowed_features = None;
+ if let Some(TraitBoundModifiers { asyncness: BoundAsyncness::Async(_), .. }) = modifiers {
+ match res {
+ Res::Def(DefKind::Trait, def_id) => {
+ if let Some((async_def_id, features)) = self.map_trait_to_async_trait(def_id) {
+ res = Res::Def(DefKind::Trait, async_def_id);
+ bound_modifier_allowed_features = Some(features);
+ } else {
+ self.dcx().emit_err(AsyncBoundOnlyForFnTraits { span: p.span });
+ }
+ }
+ Res::Err => {
+ // No additional error.
+ }
+ _ => {
+ // This error isn't actually emitted AFAICT, but it's best to keep
+ // it around in case the resolver doesn't always check the defkind
+ // of an item or something.
+ self.dcx().emit_err(AsyncBoundNotOnTrait { span: p.span, descr: res.descr() });
+ }
+ }
+ }
+
let path_span_lo = p.span.shrink_to_lo();
let proj_start = p.segments.len() - unresolved_segments;
let path = self.arena.alloc(hir::Path {
- res: self.lower_res(base_res),
+ res,
segments: self.arena.alloc_from_iter(p.segments[..proj_start].iter().enumerate().map(
|(i, segment)| {
let param_mode = match (qself_position, param_mode) {
@@ -77,7 +107,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
parenthesized_generic_args,
itctx,
// if this is the last segment, add constness to the trait path
- if i == proj_start - 1 { constness } else { None },
+ if i == proj_start - 1 { modifiers.map(|m| m.constness) } else { None },
+ bound_modifier_allowed_features.clone(),
)
},
)),
@@ -88,6 +119,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
),
});
+ if let Some(bound_modifier_allowed_features) = bound_modifier_allowed_features {
+ path.span = self.mark_span_with_reason(
+ DesugaringKind::BoundModifier,
+ path.span,
+ Some(bound_modifier_allowed_features),
+ );
+ }
+
// Simple case, either no projections, or only fully-qualified.
// E.g., `std::mem::size_of` or `::Item`.
if unresolved_segments == 0 {
@@ -125,6 +164,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ParenthesizedGenericArgs::Err,
itctx,
None,
+ None,
));
let qpath = hir::QPath::TypeRelative(ty, hir_segment);
@@ -166,6 +206,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ParenthesizedGenericArgs::Err,
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
+ None,
)
})),
span: self.lower_span(p.span),
@@ -180,6 +221,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
parenthesized_generic_args: ParenthesizedGenericArgs,
itctx: &ImplTraitContext,
constness: Option,
+ // Additional features ungated with a bound modifier like `async`.
+ // This is passed down to the implicit associated type binding in
+ // parenthesized bounds.
+ bound_modifier_allowed_features: Option>,
) -> hir::PathSegment<'hir> {
debug!("path_span: {:?}, lower_path_segment(segment: {:?})", path_span, segment);
let (mut generic_args, infer_args) = if let Some(generic_args) = segment.args.as_deref() {
@@ -188,9 +233,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.lower_angle_bracketed_parameter_data(data, param_mode, itctx)
}
GenericArgs::Parenthesized(data) => match parenthesized_generic_args {
- ParenthesizedGenericArgs::ParenSugar => {
- self.lower_parenthesized_parameter_data(data, itctx)
- }
+ ParenthesizedGenericArgs::ParenSugar => self
+ .lower_parenthesized_parameter_data(
+ data,
+ itctx,
+ bound_modifier_allowed_features,
+ ),
ParenthesizedGenericArgs::Err => {
// Suggest replacing parentheses with angle brackets `Trait(params...)` to `Trait`
let sub = if !data.inputs.is_empty() {
@@ -357,6 +405,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self,
data: &ParenthesizedArgs,
itctx: &ImplTraitContext,
+ bound_modifier_allowed_features: Option>,
) -> (GenericArgsCtor<'hir>, bool) {
// Switch to `PassThrough` mode for anonymous lifetimes; this
// means that we permit things like `&Ref`, where `Ref` has
@@ -392,7 +441,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
FnRetTy::Default(_) => self.arena.alloc(self.ty_tup(*span, &[])),
};
let args = smallvec![GenericArg::Type(self.arena.alloc(self.ty_tup(*inputs_span, inputs)))];
- let binding = self.assoc_ty_binding(sym::Output, output_ty.span, output_ty);
+
+ // If we have a bound like `async Fn() -> T`, make sure that we mark the
+ // `Output = T` associated type bound with the right feature gates.
+ let mut output_span = output_ty.span;
+ if let Some(bound_modifier_allowed_features) = bound_modifier_allowed_features {
+ output_span = self.mark_span_with_reason(
+ DesugaringKind::BoundModifier,
+ output_span,
+ Some(bound_modifier_allowed_features),
+ );
+ }
+ let binding = self.assoc_ty_binding(sym::Output, output_span, output_ty);
+
(
GenericArgsCtor {
args,
@@ -429,4 +490,23 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
kind,
}
}
+
+ /// When a bound is annotated with `async`, it signals to lowering that the trait
+ /// that the bound refers to should be mapped to the "async" flavor of the trait.
+ ///
+ /// This only needs to be done until we unify `AsyncFn` and `Fn` traits into one
+ /// that is generic over `async`ness, if that's ever possible, or modify the
+ /// lowering of `async Fn()` bounds to desugar to another trait like `LendingFn`.
+ fn map_trait_to_async_trait(&self, def_id: DefId) -> Option<(DefId, Lrc<[Symbol]>)> {
+ let lang_items = self.tcx.lang_items();
+ if Some(def_id) == lang_items.fn_trait() {
+ Some((lang_items.async_fn_trait()?, self.allow_async_fn_traits.clone()))
+ } else if Some(def_id) == lang_items.fn_mut_trait() {
+ Some((lang_items.async_fn_mut_trait()?, self.allow_async_fn_traits.clone()))
+ } else if Some(def_id) == lang_items.fn_once_trait() {
+ Some((lang_items.async_fn_once_trait()?, self.allow_async_fn_traits.clone()))
+ } else {
+ None
+ }
+ }
}
diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs
index 82236d2e3067..409aef9185d9 100644
--- a/compiler/rustc_ast_passes/src/feature_gate.rs
+++ b/compiler/rustc_ast_passes/src/feature_gate.rs
@@ -362,6 +362,19 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
}
+ fn visit_generic_args(&mut self, args: &'a ast::GenericArgs) {
+ // This check needs to happen here because the never type can be returned from a function,
+ // but cannot be used in any other context. If this check was in `visit_fn_ret_ty`, it
+ // include both functions and generics like `impl Fn() -> !`.
+ if let ast::GenericArgs::Parenthesized(generic_args) = args
+ && let ast::FnRetTy::Ty(ref ty) = generic_args.output
+ && matches!(ty.kind, ast::TyKind::Never)
+ {
+ gate!(&self, never_type, ty.span, "the `!` type is experimental");
+ }
+ visit::walk_generic_args(self, args);
+ }
+
fn visit_expr(&mut self, e: &'a ast::Expr) {
match e.kind {
ast::ExprKind::TryBlock(_) => {
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs
index a6f6f0b29a04..731232bce65c 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state.rs
@@ -8,6 +8,7 @@ mod item;
use crate::pp::Breaks::{Consistent, Inconsistent};
use crate::pp::{self, Breaks};
use crate::pprust::state::expr::FixupContext;
+use ast::TraitBoundModifiers;
use rustc_ast::attr::AttrIdGenerator;
use rustc_ast::ptr::P;
use rustc_ast::token::{self, BinOpToken, CommentKind, Delimiter, Nonterminal, Token, TokenKind};
@@ -1590,18 +1591,28 @@ impl<'a> State<'a> {
}
match bound {
- GenericBound::Trait(tref, modifier) => {
- match modifier.constness {
+ GenericBound::Trait(
+ tref,
+ TraitBoundModifiers { constness, asyncness, polarity },
+ ) => {
+ match constness {
ast::BoundConstness::Never => {}
ast::BoundConstness::Always(_) | ast::BoundConstness::Maybe(_) => {
- self.word_space(modifier.constness.as_str());
+ self.word_space(constness.as_str());
}
}
- match modifier.polarity {
+ match asyncness {
+ ast::BoundAsyncness::Normal => {}
+ ast::BoundAsyncness::Async(_) => {
+ self.word_space(asyncness.as_str());
+ }
+ }
+
+ match polarity {
ast::BoundPolarity::Positive => {}
ast::BoundPolarity::Negative(_) | ast::BoundPolarity::Maybe(_) => {
- self.word(modifier.polarity.as_str());
+ self.word(polarity.as_str());
}
}
diff --git a/compiler/rustc_borrowck/src/borrowck_errors.rs b/compiler/rustc_borrowck/src/borrowck_errors.rs
index 8a275a836301..6cbcda37f50b 100644
--- a/compiler/rustc_borrowck/src/borrowck_errors.rs
+++ b/compiler/rustc_borrowck/src/borrowck_errors.rs
@@ -130,7 +130,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
noun_old: &str,
old_opt_via: &str,
previous_end_span: Option,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_code_err!(
self.dcx(),
new_loan_span,
@@ -162,7 +162,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
old_opt_via: &str,
previous_end_span: Option,
second_borrow_desc: &str,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_code_err!(
self.dcx(),
new_loan_span,
@@ -194,7 +194,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
kind_old: &str,
msg_old: &str,
old_load_end_span: Option,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") };
let mut err = struct_span_code_err!(
self.dcx(),
@@ -235,7 +235,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
span: Span,
borrow_span: Span,
desc: &str,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
struct_span_code_err!(
self.dcx(),
span,
@@ -252,7 +252,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
span: Span,
desc: &str,
is_arg: bool,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let msg = if is_arg { "to immutable argument" } else { "twice to immutable variable" };
struct_span_code_err!(self.dcx(), span, E0384, "cannot assign {} {}", msg, desc)
}
@@ -265,7 +265,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self,
move_from_span: Span,
move_from_desc: &str,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
struct_span_code_err!(
self.dcx(),
move_from_span,
@@ -283,7 +283,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
move_from_span: Span,
ty: Ty<'_>,
is_index: Option,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let type_name = match (&ty.kind(), is_index) {
(&ty::Array(_, _), Some(true)) | (&ty::Array(_, _), None) => "array",
(&ty::Slice(_), _) => "slice",
@@ -304,7 +304,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self,
move_from_span: Span,
container_ty: Ty<'_>,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
struct_span_code_err!(
self.dcx(),
move_from_span,
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
index 2e83072b8d13..b0b7cc076bab 100644
--- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
@@ -327,7 +327,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut self,
mpi: MovePathIndex,
move_span: Span,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut DiagnosticBuilder<'tcx>,
in_pattern: &mut bool,
move_spans: UseSpans<'_>,
) {
@@ -486,7 +486,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
desired_action: InitializationRequiringAction,
span: Span,
use_spans: UseSpans<'tcx>,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
// We need all statements in the body where the binding was assigned to later find all
// the branching code paths where the binding *wasn't* assigned to.
let inits = &self.move_data.init_path_map[mpi];
@@ -880,7 +880,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
location: Location,
(place, _span): (Place<'tcx>, Span),
borrow: &BorrowData<'tcx>,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let borrow_spans = self.retrieve_borrow_spans(borrow);
let borrow_span = borrow_spans.args_or_use();
@@ -930,7 +930,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
(place, span): (Place<'tcx>, Span),
gen_borrow_kind: BorrowKind,
issued_borrow: &BorrowData<'tcx>,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let issued_spans = self.retrieve_borrow_spans(issued_borrow);
let issued_span = issued_spans.args_or_use();
@@ -2129,7 +2129,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
drop_span: Span,
borrow_spans: UseSpans<'tcx>,
explanation: BorrowExplanation<'tcx>,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
debug!(
"report_local_value_does_not_live_long_enough(\
{:?}, {:?}, {:?}, {:?}, {:?}\
@@ -2304,7 +2304,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut self,
drop_span: Span,
borrow_span: Span,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
debug!(
"report_thread_local_value_does_not_live_long_enough(\
{:?}, {:?}\
@@ -2329,7 +2329,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
borrow_spans: UseSpans<'tcx>,
proper_span: Span,
explanation: BorrowExplanation<'tcx>,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
if let BorrowExplanation::MustBeValidFor { category, span, from_closure: false, .. } =
explanation
{
@@ -2440,7 +2440,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
"consider consuming the `{ty}` when turning it into an \
`Iterator`",
),
- "into_iter".to_string(),
+ "into_iter",
Applicability::MaybeIncorrect,
);
}
@@ -2496,7 +2496,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
return_span: Span,
category: ConstraintCategory<'tcx>,
opt_place_desc: Option<&String>,
- ) -> Option> {
+ ) -> Option> {
let return_kind = match category {
ConstraintCategory::Return(_) => "return",
ConstraintCategory::Yield => "yield",
@@ -2591,7 +2591,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
constraint_span: Span,
captured_var: &str,
scope: &str,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let tcx = self.infcx.tcx;
let args_span = use_span.args_or_use();
@@ -2699,7 +2699,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
upvar_span: Span,
upvar_name: Symbol,
escape_span: Span,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let tcx = self.infcx.tcx;
let escapes_from = tcx.def_descr(self.mir_def_id().to_def_id());
diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs
index fb3525e8998c..0a0bb75a2a3a 100644
--- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs
@@ -288,7 +288,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
&mut self,
place: Place<'tcx>,
span: Span,
- ) -> DiagnosticBuilder<'a> {
+ ) -> DiagnosticBuilder<'tcx> {
let description = if place.projection.len() == 1 {
format!("static item {}", self.describe_any_place(place.as_ref()))
} else {
@@ -310,7 +310,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
deref_target_place: Place<'tcx>,
span: Span,
use_spans: Option>,
- ) -> DiagnosticBuilder<'a> {
+ ) -> DiagnosticBuilder<'tcx> {
// Inspect the type of the content behind the
// borrow to provide feedback about why this
// was a move rather than a copy.
diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
index 0a6b758efa56..3fddf67f55b9 100644
--- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
@@ -198,12 +198,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
{
let span = self.body.local_decls[local].source_info.span;
mut_error = Some(span);
- if let Some((buffer, c)) = self.get_buffered_mut_error(span) {
+ if let Some((buffered_err, c)) = self.get_buffered_mut_error(span) {
// We've encountered a second (or more) attempt to mutably borrow an
// immutable binding, so the likely problem is with the binding
// declaration, not the use. We collect these in a single diagnostic
// and make the binding the primary span of the error.
- err = buffer;
+ err = buffered_err;
count = c + 1;
if count == 2 {
err.replace_span_with(span, false);
@@ -924,7 +924,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.span_suggestion_verbose(
expr.span.shrink_to_lo(),
"use a mutable iterator instead",
- "mut ".to_string(),
+ "mut ",
Applicability::MachineApplicable,
);
}
diff --git a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs
index ad66c677c78f..bac1d9dd57f6 100644
--- a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs
@@ -251,6 +251,6 @@ impl OutlivesSuggestionBuilder {
diag.sort_span = mir_span.shrink_to_hi();
// Buffer the diagnostic
- mbcx.buffer_non_error_diag(diag);
+ mbcx.buffer_non_error(diag);
}
}
diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs
index ea48e78509b7..8b5e548345c9 100644
--- a/compiler/rustc_borrowck/src/lib.rs
+++ b/compiler/rustc_borrowck/src/lib.rs
@@ -19,7 +19,7 @@ extern crate tracing;
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::graph::dominators::Dominators;
-use rustc_errors::{Diagnostic, DiagnosticBuilder};
+use rustc_errors::DiagnosticBuilder;
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_index::bit_set::{BitSet, ChunkedBitSet};
@@ -173,12 +173,11 @@ fn do_mir_borrowck<'tcx>(
}
}
- let mut errors = error::BorrowckErrors::new(infcx.tcx);
+ let mut diags = diags::BorrowckDiags::new();
// Gather the upvars of a closure, if any.
if let Some(e) = input_body.tainted_by_errors {
infcx.set_tainted_by_errors(e);
- errors.set_tainted_by_errors(e);
}
// Replace all regions with fresh inference variables. This
@@ -244,7 +243,7 @@ fn do_mir_borrowck<'tcx>(
®ioncx,
&opt_closure_req,
&opaque_type_values,
- &mut errors,
+ &mut diags,
);
// The various `flow_*` structures can be large. We drop `flow_inits` here
@@ -305,11 +304,11 @@ fn do_mir_borrowck<'tcx>(
next_region_name: RefCell::new(1),
polonius_output: None,
move_errors: Vec::new(),
- errors,
+ diags,
};
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
promoted_mbcx.report_move_errors();
- errors = promoted_mbcx.errors;
+ diags = promoted_mbcx.diags;
struct MoveVisitor<'a, 'cx, 'tcx> {
ctxt: &'a mut MirBorrowckCtxt<'cx, 'tcx>,
@@ -346,7 +345,7 @@ fn do_mir_borrowck<'tcx>(
next_region_name: RefCell::new(1),
polonius_output,
move_errors: Vec::new(),
- errors,
+ diags,
};
// Compute and report region errors, if any.
@@ -574,7 +573,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
/// Results of Polonius analysis.
polonius_output: Option>,
- errors: error::BorrowckErrors<'tcx>,
+ diags: diags::BorrowckDiags<'tcx>,
move_errors: Vec>,
}
@@ -2125,7 +2124,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
| WriteKind::MutableBorrow(BorrowKind::Fake),
) => {
if self.is_mutable(place.as_ref(), is_local_mutation_allowed).is_err()
- && !self.has_buffered_errors()
+ && !self.has_buffered_diags()
{
// rust-lang/rust#46908: In pure NLL mode this code path should be
// unreachable, but we use `span_delayed_bug` because we can hit this when
@@ -2383,17 +2382,30 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
}
-mod error {
+mod diags {
use rustc_errors::ErrorGuaranteed;
use super::*;
- pub struct BorrowckErrors<'tcx> {
- tcx: TyCtxt<'tcx>,
+ enum BufferedDiag<'tcx> {
+ Error(DiagnosticBuilder<'tcx>),
+ NonError(DiagnosticBuilder<'tcx, ()>),
+ }
+
+ impl<'tcx> BufferedDiag<'tcx> {
+ fn sort_span(&self) -> Span {
+ match self {
+ BufferedDiag::Error(diag) => diag.sort_span,
+ BufferedDiag::NonError(diag) => diag.sort_span,
+ }
+ }
+ }
+
+ pub struct BorrowckDiags<'tcx> {
/// This field keeps track of move errors that are to be reported for given move indices.
///
- /// There are situations where many errors can be reported for a single move out (see #53807)
- /// and we want only the best of those errors.
+ /// There are situations where many errors can be reported for a single move out (see
+ /// #53807) and we want only the best of those errors.
///
/// The `report_use_of_moved_or_uninitialized` function checks this map and replaces the
/// diagnostic (if there is one) if the `Place` of the error being reported is a prefix of
@@ -2406,51 +2418,38 @@ mod error {
/// same primary span come out in a consistent order.
buffered_move_errors:
BTreeMap, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)>,
+
buffered_mut_errors: FxIndexMap, usize)>,
- /// Buffer of diagnostics to be reported. Uses `Diagnostic` rather than `DiagnosticBuilder`
- /// because it has a mixture of error diagnostics and non-error diagnostics.
- buffered: Vec,
- /// Set to Some if we emit an error during borrowck
- tainted_by_errors: Option,
+
+ /// Buffer of diagnostics to be reported. A mixture of error and non-error diagnostics.
+ buffered_diags: Vec>,
}
- impl<'tcx> BorrowckErrors<'tcx> {
- pub fn new(tcx: TyCtxt<'tcx>) -> Self {
- BorrowckErrors {
- tcx,
+ impl<'tcx> BorrowckDiags<'tcx> {
+ pub fn new() -> Self {
+ BorrowckDiags {
buffered_move_errors: BTreeMap::new(),
buffered_mut_errors: Default::default(),
- buffered: Default::default(),
- tainted_by_errors: None,
+ buffered_diags: Default::default(),
}
}
- pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_>) {
- if let None = self.tainted_by_errors {
- self.tainted_by_errors = Some(self.tcx.dcx().span_delayed_bug(
- t.span.clone_ignoring_labels(),
- "diagnostic buffered but not emitted",
- ))
- }
- self.buffered.push(t.into_diagnostic());
+ pub fn buffer_error(&mut self, t: DiagnosticBuilder<'tcx>) {
+ self.buffered_diags.push(BufferedDiag::Error(t));
}
- pub fn buffer_non_error_diag(&mut self, t: DiagnosticBuilder<'_, ()>) {
- self.buffered.push(t.into_diagnostic());
- }
-
- pub fn set_tainted_by_errors(&mut self, e: ErrorGuaranteed) {
- self.tainted_by_errors = Some(e);
+ pub fn buffer_non_error(&mut self, t: DiagnosticBuilder<'tcx, ()>) {
+ self.buffered_diags.push(BufferedDiag::NonError(t));
}
}
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
- pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_>) {
- self.errors.buffer_error(t);
+ pub fn buffer_error(&mut self, t: DiagnosticBuilder<'tcx>) {
+ self.diags.buffer_error(t);
}
- pub fn buffer_non_error_diag(&mut self, t: DiagnosticBuilder<'_, ()>) {
- self.errors.buffer_non_error_diag(t);
+ pub fn buffer_non_error(&mut self, t: DiagnosticBuilder<'tcx, ()>) {
+ self.diags.buffer_non_error(t);
}
pub fn buffer_move_error(
@@ -2459,7 +2458,7 @@ mod error {
place_and_err: (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>),
) -> bool {
if let Some((_, diag)) =
- self.errors.buffered_move_errors.insert(move_out_indices, place_and_err)
+ self.diags.buffered_move_errors.insert(move_out_indices, place_and_err)
{
// Cancel the old diagnostic so we don't ICE
diag.cancel();
@@ -2473,47 +2472,50 @@ mod error {
&mut self,
span: Span,
) -> Option<(DiagnosticBuilder<'tcx>, usize)> {
- self.errors.buffered_mut_errors.remove(&span)
+ self.diags.buffered_mut_errors.remove(&span)
}
pub fn buffer_mut_error(&mut self, span: Span, t: DiagnosticBuilder<'tcx>, count: usize) {
- self.errors.buffered_mut_errors.insert(span, (t, count));
+ self.diags.buffered_mut_errors.insert(span, (t, count));
}
pub fn emit_errors(&mut self) -> Option {
+ let mut res = None;
+
// Buffer any move errors that we collected and de-duplicated.
- for (_, (_, diag)) in std::mem::take(&mut self.errors.buffered_move_errors) {
+ for (_, (_, diag)) in std::mem::take(&mut self.diags.buffered_move_errors) {
// We have already set tainted for this error, so just buffer it.
- self.errors.buffered.push(diag.into_diagnostic());
+ self.diags.buffered_diags.push(BufferedDiag::Error(diag));
}
- for (_, (mut diag, count)) in std::mem::take(&mut self.errors.buffered_mut_errors) {
+ for (_, (mut diag, count)) in std::mem::take(&mut self.diags.buffered_mut_errors) {
if count > 10 {
diag.note(format!("...and {} other attempted mutable borrows", count - 10));
}
- self.errors.buffered.push(diag.into_diagnostic());
+ self.diags.buffered_diags.push(BufferedDiag::Error(diag));
}
- if !self.errors.buffered.is_empty() {
- self.errors.buffered.sort_by_key(|diag| diag.sort_span);
-
- let dcx = self.dcx();
- for diag in self.errors.buffered.drain(..) {
- dcx.emit_diagnostic(diag);
+ if !self.diags.buffered_diags.is_empty() {
+ self.diags.buffered_diags.sort_by_key(|buffered_diag| buffered_diag.sort_span());
+ for buffered_diag in self.diags.buffered_diags.drain(..) {
+ match buffered_diag {
+ BufferedDiag::Error(diag) => res = Some(diag.emit()),
+ BufferedDiag::NonError(diag) => diag.emit(),
+ }
}
}
- self.errors.tainted_by_errors
+ res
}
- pub fn has_buffered_errors(&self) -> bool {
- self.errors.buffered.is_empty()
+ pub(crate) fn has_buffered_diags(&self) -> bool {
+ self.diags.buffered_diags.is_empty()
}
pub fn has_move_error(
&self,
move_out_indices: &[MoveOutIndex],
- ) -> Option<&(PlaceRef<'tcx>, DiagnosticBuilder<'cx>)> {
- self.errors.buffered_move_errors.get(move_out_indices)
+ ) -> Option<&(PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)> {
+ self.diags.buffered_move_errors.get(move_out_indices)
}
}
}
diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs
index cc8208e9dc30..7ace013975e1 100644
--- a/compiler/rustc_borrowck/src/nll.rs
+++ b/compiler/rustc_borrowck/src/nll.rs
@@ -264,7 +264,7 @@ pub(super) fn dump_annotation<'tcx>(
regioncx: &RegionInferenceContext<'tcx>,
closure_region_requirements: &Option>,
opaque_type_values: &FxIndexMap>,
- errors: &mut crate::error::BorrowckErrors<'tcx>,
+ diags: &mut crate::diags::BorrowckDiags<'tcx>,
) {
let tcx = infcx.tcx;
let base_def_id = tcx.typeck_root_def_id(body.source.def_id());
@@ -310,7 +310,7 @@ pub(super) fn dump_annotation<'tcx>(
err.note(format!("Inferred opaque type values:\n{opaque_type_values:#?}"));
}
- errors.buffer_non_error_diag(err);
+ diags.buffer_non_error(err);
}
fn for_each_region_constraint<'tcx>(
diff --git a/compiler/rustc_codegen_cranelift/Cargo.lock b/compiler/rustc_codegen_cranelift/Cargo.lock
index 86bc7d0f067c..b70a1234af39 100644
--- a/compiler/rustc_codegen_cranelift/Cargo.lock
+++ b/compiler/rustc_codegen_cranelift/Cargo.lock
@@ -4,13 +4,14 @@ version = 3
[[package]]
name = "ahash"
-version = "0.8.3"
+version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
+checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01"
dependencies = [
"cfg-if",
"once_cell",
"version_check",
+ "zerocopy",
]
[[package]]
@@ -293,6 +294,24 @@ version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
+[[package]]
+name = "proc-macro2"
+version = "1.0.75"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
+dependencies = [
+ "proc-macro2",
+]
+
[[package]]
name = "regalloc2"
version = "0.9.3"
@@ -360,12 +379,29 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
+[[package]]
+name = "syn"
+version = "2.0.47"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1726efe18f42ae774cc644f330953a5e7b3c3003d3edcecf18850fe9d4dd9afb"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
[[package]]
name = "target-lexicon"
version = "0.12.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a"
+[[package]]
+name = "unicode-ident"
+version = "1.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
+
[[package]]
name = "version_check"
version = "0.9.4"
@@ -536,3 +572,23 @@ name = "windows_x86_64_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
+
+[[package]]
+name = "zerocopy"
+version = "0.7.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be"
+dependencies = [
+ "zerocopy-derive",
+]
+
+[[package]]
+name = "zerocopy-derive"
+version = "0.7.32"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs
index abd70dd4458f..0f0d828c8fc3 100644
--- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs
+++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs
@@ -56,11 +56,7 @@ pub(crate) fn conv_to_call_conv(sess: &Session, c: Conv, default_call_conv: Call
sess.dcx().fatal("C-cmse-nonsecure-call call conv is not yet implemented");
}
- Conv::Msp430Intr
- | Conv::PtxKernel
- | Conv::AmdGpuKernel
- | Conv::AvrInterrupt
- | Conv::AvrNonBlockingInterrupt => {
+ Conv::Msp430Intr | Conv::PtxKernel | Conv::AvrInterrupt | Conv::AvrNonBlockingInterrupt => {
unreachable!("tried to use {c:?} call conv which only exists on an unsupported target");
}
}
diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs
index 03f8f43ff164..f8f054db65ed 100644
--- a/compiler/rustc_codegen_gcc/src/lib.rs
+++ b/compiler/rustc_codegen_gcc/src/lib.rs
@@ -408,7 +408,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool, target_info: &Locke
.filter(|_feature| {
target_info.cpu_supports(_feature)
/*
- adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512ifma,
+ adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512fp16, avx512ifma,
avx512pf, avx512vbmi, avx512vbmi2, avx512vl, avx512vnni, avx512vp2intersect, avx512vpopcntdq,
bmi1, bmi2, cmpxchg16b, ermsb, f16c, fma, fxsr, gfni, lzcnt, movbe, pclmulqdq, popcnt, rdrand, rdseed, rtm,
sha, sse, sse2, sse3, sse4.1, sse4.2, sse4a, ssse3, tbm, vaes, vpclmulqdq, xsave, xsavec, xsaveopt, xsaves
diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs
index 0718bebb31bf..b5b4f894e4d8 100644
--- a/compiler/rustc_codegen_llvm/src/abi.rs
+++ b/compiler/rustc_codegen_llvm/src/abi.rs
@@ -590,7 +590,6 @@ impl From for llvm::CallConv {
Conv::Cold => llvm::ColdCallConv,
Conv::PreserveMost => llvm::PreserveMost,
Conv::PreserveAll => llvm::PreserveAll,
- Conv::AmdGpuKernel => llvm::AmdGpuKernel,
Conv::AvrInterrupt => llvm::AvrInterrupt,
Conv::AvrNonBlockingInterrupt => llvm::AvrNonBlockingInterrupt,
Conv::ArmAapcs => llvm::ArmAapcsCallConv,
diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs
index 6cb62280a595..7dfcf1ab50e4 100644
--- a/compiler/rustc_codegen_llvm/src/context.rs
+++ b/compiler/rustc_codegen_llvm/src/context.rs
@@ -909,6 +909,7 @@ impl<'ll> CodegenCx<'ll, '_> {
ifn!("llvm.is.constant.isize", fn(t_isize) -> i1);
ifn!("llvm.is.constant.f32", fn(t_f32) -> i1);
ifn!("llvm.is.constant.f64", fn(t_f64) -> i1);
+ ifn!("llvm.is.constant.ptr", fn(ptr) -> i1);
ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
ifn!("llvm.eh.typeid.for", fn(ptr) -> t_i32);
diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs
index d82ff6656f4d..e839d278bea7 100644
--- a/compiler/rustc_codegen_llvm/src/errors.rs
+++ b/compiler/rustc_codegen_llvm/src/errors.rs
@@ -102,7 +102,7 @@ pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
impl IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> {
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
let diag: DiagnosticBuilder<'_, G> = self.0.into_diagnostic(dcx, level);
- let (message, _) = diag.messages().first().expect("`LlvmError` with no message");
+ let (message, _) = diag.messages.first().expect("`LlvmError` with no message");
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args());
DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)
diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs
index f1a6f7bd8e69..b4512af38e37 100644
--- a/compiler/rustc_codegen_llvm/src/intrinsic.rs
+++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs
@@ -119,10 +119,18 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
sym::likely => {
self.call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(true)])
}
- sym::is_val_statically_known => self.call_intrinsic(
- &format!("llvm.is.constant.{:?}", args[0].layout.immediate_llvm_type(self.cx)),
- &[args[0].immediate()],
- ),
+ sym::is_val_statically_known => {
+ let intrinsic_type = args[0].layout.immediate_llvm_type(self.cx);
+ match self.type_kind(intrinsic_type) {
+ TypeKind::Pointer | TypeKind::Integer | TypeKind::Float | TypeKind::Double => {
+ self.call_intrinsic(
+ &format!("llvm.is.constant.{:?}", intrinsic_type),
+ &[args[0].immediate()],
+ )
+ }
+ _ => self.const_bool(false),
+ }
+ }
sym::unlikely => self
.call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(false)]),
kw::Try => {
diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs
index ee73c6b4756f..4ad44a42738b 100644
--- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs
+++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs
@@ -106,7 +106,6 @@ pub enum CallConv {
X86_Intr = 83,
AvrNonBlockingInterrupt = 84,
AvrInterrupt = 85,
- AmdGpuKernel = 91,
}
/// LLVMRustLinkage
diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs
index 06edb7945372..4211f875dd01 100644
--- a/compiler/rustc_codegen_ssa/src/back/write.rs
+++ b/compiler/rustc_codegen_ssa/src/back/write.rs
@@ -39,7 +39,6 @@ use rustc_target::spec::{MergeFunctions, SanitizerSet};
use crate::errors::ErrorCreatingRemarkDir;
use std::any::Any;
-use std::borrow::Cow;
use std::fs;
use std::io;
use std::marker::PhantomData;
@@ -1812,12 +1811,12 @@ impl Translate for SharedEmitter {
impl Emitter for SharedEmitter {
fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
- let args: FxHashMap, DiagnosticArgValue> =
+ let args: FxHashMap =
diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect();
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
msgs: diag.messages.clone(),
args: args.clone(),
- code: diag.code.clone(),
+ code: diag.code,
lvl: diag.level(),
})));
for child in &diag.children {
diff --git a/compiler/rustc_const_eval/src/const_eval/error.rs b/compiler/rustc_const_eval/src/const_eval/error.rs
index dabf78ef90e5..62af21396ab4 100644
--- a/compiler/rustc_const_eval/src/const_eval/error.rs
+++ b/compiler/rustc_const_eval/src/const_eval/error.rs
@@ -1,6 +1,8 @@
use std::mem;
-use rustc_errors::{DiagnosticArgValue, DiagnosticMessage, IntoDiagnostic, IntoDiagnosticArg};
+use rustc_errors::{
+ DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, IntoDiagnostic, IntoDiagnosticArg,
+};
use rustc_hir::CRATE_HIR_ID;
use rustc_middle::mir::AssertKind;
use rustc_middle::query::TyCtxtAt;
@@ -32,10 +34,7 @@ impl MachineStopType for ConstEvalErrKind {
AssertFailure(x) => x.diagnostic_message(),
}
}
- fn add_args(
- self: Box,
- adder: &mut dyn FnMut(std::borrow::Cow<'static, str>, DiagnosticArgValue),
- ) {
+ fn add_args(self: Box, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue)) {
use ConstEvalErrKind::*;
match *self {
ConstAccessesStatic | ModifiedGlobal => {}
@@ -50,9 +49,7 @@ impl MachineStopType for ConstEvalErrKind {
}
}
-// The errors become `MachineStop` with plain strings when being raised.
-// `ConstEvalErr` (in `librustc_middle/mir/interpret/error.rs`) knows to
-// handle these.
+/// The errors become [`InterpError::MachineStop`] when being raised.
impl<'tcx> Into> for ConstEvalErrKind {
fn into(self) -> InterpErrorInfo<'tcx> {
err_machine_stop!(self).into()
diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs
index 7b993279f18e..b7ffb4a16fc3 100644
--- a/compiler/rustc_const_eval/src/interpret/terminator.rs
+++ b/compiler/rustc_const_eval/src/interpret/terminator.rs
@@ -373,7 +373,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
if let (Some(caller), Some(callee)) = (pointee_ty(caller.ty)?, pointee_ty(callee.ty)?) {
// This is okay if they have the same metadata type.
let meta_ty = |ty: Ty<'tcx>| {
- let (meta, only_if_sized) = ty.ptr_metadata_ty(*self.tcx, |ty| ty);
+ // Even if `ty` is normalized, the search for the unsized tail will project
+ // to fields, which can yield non-normalized types. So we need to provide a
+ // normalization function.
+ let normalize = |ty| self.tcx.normalize_erasing_regions(self.param_env, ty);
+ let (meta, only_if_sized) = ty.ptr_metadata_ty(*self.tcx, normalize);
assert!(
!only_if_sized,
"there should be no more 'maybe has that metadata' types during interpretation"
diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs
index 563d8501890c..a71d012db2d9 100644
--- a/compiler/rustc_data_structures/src/lib.rs
+++ b/compiler/rustc_data_structures/src/lib.rs
@@ -148,7 +148,7 @@ pub fn make_display(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl
Printer { f }
}
-// See comments in src/librustc_middle/lib.rs
+// See comments in compiler/rustc_middle/src/tests.rs
#[doc(hidden)]
pub fn __noop_fix_for_27438() {}
diff --git a/compiler/rustc_error_codes/src/error_codes/E0091.md b/compiler/rustc_error_codes/src/error_codes/E0091.md
index 03cb32803715..3bf4e907ecb1 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0091.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0091.md
@@ -1,11 +1,11 @@
-An unnecessary type or const parameter was given in a type alias.
+An unnecessary type parameter was given in a type alias.
Erroneous code example:
```compile_fail,E0091
-type Foo = u32; // error: type parameter `T` is unused
+type Foo = u32; // error: type parameter `T` is never used
// or:
-type Foo = Box; // error: type parameter `B` is unused
+type Foo = Box; // error: type parameter `B` is never used
```
Please check you didn't write too many parameters. Example:
diff --git a/compiler/rustc_error_codes/src/error_codes/E0264.md b/compiler/rustc_error_codes/src/error_codes/E0264.md
index d79060762299..33ddf3405acc 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0264.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0264.md
@@ -13,7 +13,7 @@ extern "C" {
```
A list of available external lang items is available in
-`src/librustc_middle/middle/weak_lang_items.rs`. Example:
+`compiler/rustc_hir/src/weak_lang_items.rs`. Example:
```
#![feature(lang_items)]
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs
index bf1ab37a1cf4..8ad4925cff28 100644
--- a/compiler/rustc_errors/src/diagnostic.rs
+++ b/compiler/rustc_errors/src/diagnostic.rs
@@ -33,7 +33,10 @@ pub type DiagnosticArgName = Cow<'static, str>;
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
pub enum DiagnosticArgValue {
Str(Cow<'static, str>),
- Number(i128),
+ // This gets converted to a `FluentNumber`, which is an `f64`. An `i32`
+ // safely fits in an `f64`. Any integers bigger than that will be converted
+ // to strings in `into_diagnostic_arg` and stored using the `Str` variant.
+ Number(i32),
StrListSepByAnd(Vec>),
}
@@ -109,13 +112,11 @@ pub struct Diagnostic {
/// `span` if there is one. Otherwise, it is `DUMMY_SP`.
pub sort_span: Span,
- /// If diagnostic is from Lint, custom hash function ignores children.
- /// Otherwise hash is based on the all the fields.
pub is_lint: Option,
/// With `-Ztrack_diagnostics` enabled,
/// we print where in rustc this error was emitted.
- pub emitted_at: DiagnosticLocation,
+ pub(crate) emitted_at: DiagnosticLocation,
}
#[derive(Clone, Debug, Encodable, Decodable)]
@@ -164,10 +165,10 @@ impl DiagnosticStyledString {
DiagnosticStyledString(vec![])
}
pub fn push_normal>(&mut self, t: S) {
- self.0.push(StringPart::Normal(t.into()));
+ self.0.push(StringPart::normal(t));
}
pub fn push_highlighted>(&mut self, t: S) {
- self.0.push(StringPart::Highlighted(t.into()));
+ self.0.push(StringPart::highlighted(t));
}
pub fn push>(&mut self, t: S, highlight: bool) {
if highlight {
@@ -177,35 +178,34 @@ impl DiagnosticStyledString {
}
}
pub fn normal>(t: S) -> DiagnosticStyledString {
- DiagnosticStyledString(vec![StringPart::Normal(t.into())])
+ DiagnosticStyledString(vec![StringPart::normal(t)])
}
pub fn highlighted>(t: S) -> DiagnosticStyledString {
- DiagnosticStyledString(vec![StringPart::Highlighted(t.into())])
+ DiagnosticStyledString(vec![StringPart::highlighted(t)])
}
pub fn content(&self) -> String {
- self.0.iter().map(|x| x.content()).collect::()
+ self.0.iter().map(|x| x.content.as_str()).collect::()
}
}
#[derive(Debug, PartialEq, Eq)]
-pub enum StringPart {
- Normal(String),
- Highlighted(String),
+pub struct StringPart {
+ content: String,
+ style: Style,
}
impl StringPart {
- pub fn content(&self) -> &str {
- match self {
- &StringPart::Normal(ref s) | &StringPart::Highlighted(ref s) => s,
- }
+ pub fn normal>(content: S) -> StringPart {
+ StringPart { content: content.into(), style: Style::NoStyle }
+ }
+
+ pub fn highlighted>(content: S) -> StringPart {
+ StringPart { content: content.into(), style: Style::Highlight }
}
}
-// Note: most of these methods are setters that return `&mut Self`. The small
-// number of simple getter functions all have `get_` prefixes to distinguish
-// them from the setters.
impl Diagnostic {
#[track_caller]
pub fn new>(level: Level, message: M) -> Self {
@@ -391,19 +391,16 @@ impl Diagnostic {
} else {
(0, found_label.len() - expected_label.len())
};
- let mut msg: Vec<_> =
- vec![(format!("{}{} `", " ".repeat(expected_padding), expected_label), Style::NoStyle)];
- msg.extend(expected.0.iter().map(|x| match *x {
- StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
- StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
- }));
- msg.push((format!("`{expected_extra}\n"), Style::NoStyle));
- msg.push((format!("{}{} `", " ".repeat(found_padding), found_label), Style::NoStyle));
- msg.extend(found.0.iter().map(|x| match *x {
- StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
- StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
- }));
- msg.push((format!("`{found_extra}"), Style::NoStyle));
+ let mut msg = vec![StringPart::normal(format!(
+ "{}{} `",
+ " ".repeat(expected_padding),
+ expected_label
+ ))];
+ msg.extend(expected.0.into_iter());
+ msg.push(StringPart::normal(format!("`{expected_extra}\n")));
+ msg.push(StringPart::normal(format!("{}{} `", " ".repeat(found_padding), found_label)));
+ msg.extend(found.0.into_iter());
+ msg.push(StringPart::normal(format!("`{found_extra}")));
// For now, just attach these as notes.
self.highlighted_note(msg);
@@ -412,9 +409,9 @@ impl Diagnostic {
pub fn note_trait_signature(&mut self, name: Symbol, signature: String) -> &mut Self {
self.highlighted_note(vec![
- (format!("`{name}` from trait: `"), Style::NoStyle),
- (signature, Style::Highlight),
- ("`".to_string(), Style::NoStyle),
+ StringPart::normal(format!("`{name}` from trait: `")),
+ StringPart::highlighted(signature),
+ StringPart::normal("`"),
]);
self
}
@@ -426,10 +423,7 @@ impl Diagnostic {
self
}
- fn highlighted_note>(
- &mut self,
- msg: Vec<(M, Style)>,
- ) -> &mut Self {
+ fn highlighted_note(&mut self, msg: Vec) -> &mut Self {
self.sub_with_highlights(Level::Note, msg, MultiSpan::new());
self
}
@@ -498,7 +492,7 @@ impl Diagnostic {
}
/// Add a help message attached to this diagnostic with a customizable highlighted message.
- pub fn highlighted_help(&mut self, msg: Vec<(String, Style)>) -> &mut Self {
+ pub fn highlighted_help(&mut self, msg: Vec) -> &mut Self {
self.sub_with_highlights(Level::Help, msg, MultiSpan::new());
self
}
@@ -892,15 +886,6 @@ impl Diagnostic {
self
}
- pub fn clear_code(&mut self) -> &mut Self {
- self.code = None;
- self
- }
-
- pub fn get_code(&self) -> Option {
- self.code
- }
-
pub fn primary_message(&mut self, msg: impl Into) -> &mut Self {
self.messages[0] = (msg.into(), Style::NoStyle);
self
@@ -915,7 +900,7 @@ impl Diagnostic {
pub fn arg(
&mut self,
- name: impl Into>,
+ name: impl Into,
arg: impl IntoDiagnosticArg,
) -> &mut Self {
self.args.insert(name.into(), arg.into_diagnostic_arg());
@@ -926,10 +911,6 @@ impl Diagnostic {
self.args = args;
}
- pub fn messages(&self) -> &[(DiagnosticMessage, Style)] {
- &self.messages
- }
-
/// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagnosticMessage` by
/// combining it with the primary message of the diagnostic (if translatable, otherwise it just
/// passes the user's string along).
@@ -960,15 +941,10 @@ impl Diagnostic {
/// Convenience function for internal use, clients should use one of the
/// public methods above.
- fn sub_with_highlights>(
- &mut self,
- level: Level,
- messages: Vec<(M, Style)>,
- span: MultiSpan,
- ) {
+ fn sub_with_highlights(&mut self, level: Level, messages: Vec, span: MultiSpan) {
let messages = messages
.into_iter()
- .map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.0), m.1))
+ .map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.content), m.style))
.collect();
let sub = SubDiagnostic { level, messages, span };
self.children.push(sub);
@@ -980,22 +956,24 @@ impl Diagnostic {
) -> (
&Level,
&[(DiagnosticMessage, Style)],
- Vec<(&Cow<'static, str>, &DiagnosticArgValue)>,
&Option,
- &Option,
&MultiSpan,
+ &[SubDiagnostic],
&Result, SuggestionsDisabled>,
- Option<&[SubDiagnostic]>,
+ Vec<(&DiagnosticArgName, &DiagnosticArgValue)>,
+ &Option,
) {
(
&self.level,
&self.messages,
- self.args().collect(),
&self.code,
- &self.is_lint,
&self.span,
+ &self.children,
&self.suggestions,
- (if self.is_lint.is_some() { None } else { Some(&self.children) }),
+ self.args().collect(),
+ // omit self.sort_span
+ &self.is_lint,
+ // omit self.emitted_at
)
}
}
diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs
index 8bfb18164862..faff7f0b5267 100644
--- a/compiler/rustc_errors/src/diagnostic_builder.rs
+++ b/compiler/rustc_errors/src/diagnostic_builder.rs
@@ -255,13 +255,8 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
/// Stashes diagnostic for possible later improvement in a different,
/// later stage of the compiler. The diagnostic can be accessed with
/// the provided `span` and `key` through [`DiagCtxt::steal_diagnostic()`].
- pub fn stash(self, span: Span, key: StashKey) {
- self.dcx.stash_diagnostic(span, key, self.into_diagnostic());
- }
-
- /// Converts the builder to a `Diagnostic` for later emission.
- pub fn into_diagnostic(mut self) -> Diagnostic {
- self.take_diag()
+ pub fn stash(mut self, span: Span, key: StashKey) {
+ self.dcx.stash_diagnostic(span, key, self.take_diag());
}
/// Delay emission of this diagnostic as a bug.
diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs
index faab3fc663a8..15effd3cbec9 100644
--- a/compiler/rustc_errors/src/diagnostic_impls.rs
+++ b/compiler/rustc_errors/src/diagnostic_impls.rs
@@ -63,12 +63,8 @@ macro_rules! into_diagnostic_arg_for_number {
$(
impl IntoDiagnosticArg for $ty {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
- // HACK: `FluentNumber` the underline backing struct represent
- // numbers using a f64 which can't represent all the i128 numbers
- // So in order to be able to use fluent selectors and still
- // have all the numbers representable we only convert numbers
- // below a certain threshold.
- if let Ok(n) = TryInto::::try_into(self) && n >= -100 && n <= 100 {
+ // Convert to a string if it won't fit into `Number`.
+ if let Ok(n) = TryInto::::try_into(self) {
DiagnosticArgValue::Number(n)
} else {
self.to_string().into_diagnostic_arg()
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index 9f76c1dd248b..4be5ed923e5e 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -558,7 +558,7 @@ impl Emitter for HumanEmitter {
/// failures of rustc, as witnessed e.g. in issue #89358.
pub struct SilentEmitter {
pub fatal_dcx: DiagCtxt,
- pub fatal_note: Option,
+ pub fatal_note: String,
}
impl Translate for SilentEmitter {
@@ -576,13 +576,11 @@ impl Emitter for SilentEmitter {
None
}
- fn emit_diagnostic(&mut self, d: &Diagnostic) {
- if d.level == Level::Fatal {
- let mut d = d.clone();
- if let Some(ref note) = self.fatal_note {
- d.note(note.clone());
- }
- self.fatal_dcx.emit_diagnostic(d);
+ fn emit_diagnostic(&mut self, diag: &Diagnostic) {
+ if diag.level == Level::Fatal {
+ let mut diag = diag.clone();
+ diag.note(self.fatal_note.clone());
+ self.fatal_dcx.emit_diagnostic(diag);
}
}
}
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index 960b68196ff0..9ec636dcc9cd 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -34,7 +34,7 @@ extern crate self as rustc_errors;
pub use codes::*;
pub use diagnostic::{
AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgName,
- DiagnosticArgValue, DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
+ DiagnosticArgValue, DiagnosticStyledString, IntoDiagnosticArg, StringPart, SubDiagnostic,
};
pub use diagnostic_builder::{
BugAbort, DiagnosticBuilder, EmissionGuarantee, FatalAbort, IntoDiagnostic,
@@ -102,7 +102,6 @@ pub type PResult<'a, T> = Result>;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
// `PResult` is used a lot. Make sure it doesn't unintentionally get bigger.
-// (See also the comment on `DiagnosticBuilderInner`'s `diagnostic` field.)
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(PResult<'_, ()>, 16);
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
@@ -646,7 +645,8 @@ impl DiagCtxt {
}
// This is here to not allow mutation of flags;
- // as of this writing it's only used in tests in librustc_middle.
+ // as of this writing it's used in Session::consider_optimizing and
+ // in tests in rustc_interface.
pub fn can_emit_warnings(&self) -> bool {
self.inner.borrow_mut().flags.can_emit_warnings
}
@@ -1039,10 +1039,6 @@ impl DiagCtxt {
}
}
- pub fn take_future_breakage_diagnostics(&self) -> Vec {
- std::mem::take(&mut self.inner.borrow_mut().future_breakage_diagnostics)
- }
-
pub fn abort_if_errors(&self) {
let mut inner = self.inner.borrow_mut();
inner.emit_stashed_diagnostics();
@@ -1150,8 +1146,12 @@ impl DiagCtxt {
self.inner.borrow_mut().emitter.emit_artifact_notification(path, artifact_type);
}
- pub fn emit_future_breakage_report(&self, diags: Vec) {
- self.inner.borrow_mut().emitter.emit_future_breakage_report(diags)
+ pub fn emit_future_breakage_report(&self) {
+ let mut inner = self.inner.borrow_mut();
+ let diags = std::mem::take(&mut inner.future_breakage_diagnostics);
+ if !diags.is_empty() {
+ inner.emitter.emit_future_breakage_report(diags);
+ }
}
pub fn emit_unused_externs(
@@ -1224,9 +1224,8 @@ impl DiagCtxtInner {
/// Emit all stashed diagnostics.
fn emit_stashed_diagnostics(&mut self) -> Option {
let has_errors = self.has_errors();
- let diags = self.stashed_diagnostics.drain(..).map(|x| x.1).collect::>();
let mut reported = None;
- for diag in diags {
+ for (_, diag) in std::mem::take(&mut self.stashed_diagnostics).into_iter() {
// Decrement the count tracking the stash; emitting will increment it.
if diag.is_error() {
if diag.is_lint.is_some() {
@@ -1254,7 +1253,7 @@ impl DiagCtxtInner {
// be stored. Instead, they are buffered until the `LintExpectationId` is replaced by
// a stable one by the `LintLevelsBuilder`.
if let Some(LintExpectationId::Unstable { .. }) = diagnostic.level.get_expectation_id() {
- self.unstable_expect_diagnostics.push(diagnostic.clone());
+ self.unstable_expect_diagnostics.push(diagnostic);
return None;
}
@@ -1269,16 +1268,14 @@ impl DiagCtxtInner {
DelayedBug(DelayedBugKind::Normal) => {
let backtrace = std::backtrace::Backtrace::capture();
self.span_delayed_bugs
- .push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace));
-
+ .push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
#[allow(deprecated)]
return Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
}
DelayedBug(DelayedBugKind::GoodPath) => {
let backtrace = std::backtrace::Backtrace::capture();
self.good_path_delayed_bugs
- .push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace));
-
+ .push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
return None;
}
_ => {}
@@ -1424,7 +1421,7 @@ impl DiagCtxtInner {
&mut out,
"delayed span bug: {}\n{}\n",
bug.inner
- .messages()
+ .messages
.iter()
.filter_map(|(msg, _)| msg.as_str())
.collect::(),
diff --git a/compiler/rustc_errors/src/snippet.rs b/compiler/rustc_errors/src/snippet.rs
index 98eb70b5fcee..b55f78538852 100644
--- a/compiler/rustc_errors/src/snippet.rs
+++ b/compiler/rustc_errors/src/snippet.rs
@@ -197,7 +197,7 @@ pub struct StyledString {
pub style: Style,
}
-#[derive(Copy, Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
pub enum Style {
MainHeaderMsg,
HeaderMsg,
diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs
index f9bfebee12e9..5879e025e7db 100644
--- a/compiler/rustc_expand/src/build.rs
+++ b/compiler/rustc_expand/src/build.rs
@@ -141,6 +141,7 @@ impl<'a> ExtCtxt<'a> {
} else {
ast::BoundConstness::Never
},
+ asyncness: ast::BoundAsyncness::Normal,
},
)
}
diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs
index 67ee53d8ae53..85fcf6a99941 100644
--- a/compiler/rustc_feature/src/removed.rs
+++ b/compiler/rustc_feature/src/removed.rs
@@ -32,6 +32,8 @@ declare_features! (
// feature-group-start: removed features
// -------------------------------------------------------------------------
+ /// Allows using the `amdgpu-kernel` ABI.
+ (removed, abi_amdgpu_kernel, "CURRENT_RUSTC_VERSION", Some(51575), None),
(removed, advanced_slice_patterns, "1.0.0", Some(62254),
Some("merged into `#![feature(slice_patterns)]`")),
(removed, allocator, "1.0.0", None, None),
diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs
index e66a66e23dc4..d00621d8254c 100644
--- a/compiler/rustc_feature/src/unstable.rs
+++ b/compiler/rustc_feature/src/unstable.rs
@@ -321,8 +321,6 @@ declare_features! (
// feature-group-start: actual feature gates
// -------------------------------------------------------------------------
- /// Allows using the `amdgpu-kernel` ABI.
- (unstable, abi_amdgpu_kernel, "1.29.0", Some(51575)),
/// Allows `extern "avr-interrupt" fn()` and `extern "avr-non-blocking-interrupt" fn()`.
(unstable, abi_avr_interrupt, "1.45.0", Some(69664)),
/// Allows `extern "C-cmse-nonsecure-call" fn()`.
@@ -498,7 +496,7 @@ declare_features! (
/// Allow anonymous constants from an inline `const` block
(unstable, inline_const, "1.49.0", Some(76001)),
/// Allow anonymous constants from an inline `const` block in pattern position
- (incomplete, inline_const_pat, "1.58.0", Some(76001)),
+ (unstable, inline_const_pat, "1.58.0", Some(76001)),
/// Allows using `pointer` and `reference` in intra-doc links
(unstable, intra_doc_pointers, "1.51.0", Some(80896)),
// Allows setting the threshold for the `large_assignments` lint.
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index 681e228a0f2f..de1b28acb126 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -894,34 +894,23 @@ impl<'tcx> OwnerInfo<'tcx> {
}
#[derive(Copy, Clone, Debug, HashStable_Generic)]
-pub enum MaybeOwner {
- Owner(T),
+pub enum MaybeOwner<'tcx> {
+ Owner(&'tcx OwnerInfo<'tcx>),
NonOwner(HirId),
/// Used as a placeholder for unused LocalDefId.
Phantom,
}
-impl MaybeOwner {
- pub fn as_owner(self) -> Option {
+impl<'tcx> MaybeOwner<'tcx> {
+ pub fn as_owner(self) -> Option<&'tcx OwnerInfo<'tcx>> {
match self {
MaybeOwner::Owner(i) => Some(i),
MaybeOwner::NonOwner(_) | MaybeOwner::Phantom => None,
}
}
- pub fn map(self, f: impl FnOnce(T) -> U) -> MaybeOwner {
- match self {
- MaybeOwner::Owner(i) => MaybeOwner::Owner(f(i)),
- MaybeOwner::NonOwner(hir_id) => MaybeOwner::NonOwner(hir_id),
- MaybeOwner::Phantom => MaybeOwner::Phantom,
- }
- }
-
- pub fn unwrap(self) -> T {
- match self {
- MaybeOwner::Owner(i) => i,
- MaybeOwner::NonOwner(_) | MaybeOwner::Phantom => panic!("Not a HIR owner"),
- }
+ pub fn unwrap(self) -> &'tcx OwnerInfo<'tcx> {
+ self.as_owner().unwrap_or_else(|| panic!("Not a HIR owner"))
}
}
@@ -933,7 +922,7 @@ impl MaybeOwner {
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
#[derive(Debug)]
pub struct Crate<'hir> {
- pub owners: IndexVec>>,
+ pub owners: IndexVec>,
// Only present when incr. comp. is enabled.
pub opt_hir_hash: Option,
}
diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl
index 432c9c12cbfb..54d0fb6ffab7 100644
--- a/compiler/rustc_hir_analysis/messages.ftl
+++ b/compiler/rustc_hir_analysis/messages.ftl
@@ -434,6 +434,17 @@ hir_analysis_unused_associated_type_bounds =
.note = this associated type has a `where Self: Sized` bound. Thus, while the associated type can be specified, it cannot be used in any way, because trait objects are not `Sized`.
.suggestion = remove this bound
+hir_analysis_unused_generic_parameter =
+ {$param_def_kind} `{$param_name}` is never used
+ .label = unused {$param_def_kind}
+ .const_param_help = if you intended `{$param_name}` to be a const parameter, use `const {$param_name}: /* Type */` instead
+hir_analysis_unused_generic_parameter_adt_help =
+ consider removing `{$param_name}`, referring to it in a field, or using a marker such as `{$phantom_data}`
+hir_analysis_unused_generic_parameter_adt_no_phantom_data_help =
+ consider removing `{$param_name}` or referring to it in a field
+hir_analysis_unused_generic_parameter_ty_alias_help =
+ consider removing `{$param_name}` or referring to it in the body of the type alias
+
hir_analysis_value_of_associated_struct_already_specified =
the value of the associated type `{$item_name}` in trait `{$def_path}` is already specified
.label = re-bound here
diff --git a/compiler/rustc_hir_analysis/src/astconv/bounds.rs b/compiler/rustc_hir_analysis/src/astconv/bounds.rs
index c22daad334fc..e37119e7d4dc 100644
--- a/compiler/rustc_hir_analysis/src/astconv/bounds.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/bounds.rs
@@ -28,6 +28,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
let tcx = self.tcx();
let sized_def_id = tcx.lang_items().sized_trait();
let mut seen_negative_sized_bound = false;
+ let mut seen_positive_sized_bound = false;
// Try to find an unbound in bounds.
let mut unbounds: SmallVec<[_; 1]> = SmallVec::new();
@@ -45,6 +46,13 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
seen_negative_sized_bound = true;
}
}
+ hir::TraitBoundModifier::None => {
+ if let Some(sized_def_id) = sized_def_id
+ && ptr.trait_ref.path.res == Res::Def(DefKind::Trait, sized_def_id)
+ {
+ seen_positive_sized_bound = true;
+ }
+ }
_ => {}
}
}
@@ -82,11 +90,11 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
);
}
- if seen_sized_unbound || seen_negative_sized_bound {
- // There was in fact a `?Sized` or `!Sized` bound;
+ if seen_sized_unbound || seen_negative_sized_bound || seen_positive_sized_bound {
+ // There was in fact a `?Sized`, `!Sized` or explicit `Sized` bound;
// we don't need to do anything.
} else if sized_def_id.is_some() {
- // There was no `?Sized` or `!Sized` bound;
+ // There was no `?Sized`, `!Sized` or explicit `Sized` bound;
// add `Sized` if it's available.
bounds.push_sized(tcx, self_ty, span);
}
diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs
index 407517b15ef5..e67a44d96ad4 100644
--- a/compiler/rustc_hir_analysis/src/astconv/errors.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs
@@ -247,7 +247,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
err.span_suggestion_verbose(
assoc_name.span,
fluent::hir_analysis_assoc_item_not_found_similar_in_other_trait_with_bound_sugg,
- suggested_name.to_string(),
+ suggested_name,
Applicability::MaybeIncorrect,
);
}
diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs
index 2fe3499e8e69..50809a571b8d 100644
--- a/compiler/rustc_hir_analysis/src/check/check.rs
+++ b/compiler/rustc_hir_analysis/src/check/check.rs
@@ -31,6 +31,7 @@ use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
use rustc_trait_selection::traits::{self, TraitEngine, TraitEngineExt as _};
use rustc_type_ir::fold::TypeFoldable;
+use std::cell::LazyCell;
use std::ops::ControlFlow;
pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
@@ -520,9 +521,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
}
}
DefKind::TyAlias => {
- let pty_ty = tcx.type_of(def_id).instantiate_identity();
- let generics = tcx.generics_of(def_id);
- check_type_params_are_used(tcx, generics, pty_ty);
+ check_type_alias_type_params_are_used(tcx, def_id);
}
DefKind::ForeignMod => {
let it = tcx.hir().expect_item(def_id);
@@ -1269,28 +1268,51 @@ fn detect_discriminant_duplicate<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
}
}
-pub(super) fn check_type_params_are_used<'tcx>(
- tcx: TyCtxt<'tcx>,
- generics: &ty::Generics,
- ty: Ty<'tcx>,
-) {
- debug!("check_type_params_are_used(generics={:?}, ty={:?})", generics, ty);
-
- assert_eq!(generics.parent, None);
+fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) {
+ if tcx.type_alias_is_lazy(def_id) {
+ // Since we compute the variances for lazy type aliases and already reject bivariant
+ // parameters as unused, we can and should skip this check for lazy type aliases.
+ return;
+ }
+ let generics = tcx.generics_of(def_id);
if generics.own_counts().types == 0 {
return;
}
- let mut params_used = BitSet::new_empty(generics.params.len());
-
+ let ty = tcx.type_of(def_id).instantiate_identity();
if ty.references_error() {
- // If there is already another error, do not emit
- // an error for not using a type parameter.
+ // If there is already another error, do not emit an error for not using a type parameter.
assert!(tcx.dcx().has_errors().is_some());
return;
}
+ // Lazily calculated because it is only needed in case of an error.
+ let bounded_params = LazyCell::new(|| {
+ tcx.explicit_predicates_of(def_id)
+ .predicates
+ .iter()
+ .filter_map(|(predicate, span)| {
+ let bounded_ty = match predicate.kind().skip_binder() {
+ ty::ClauseKind::Trait(pred) => pred.trait_ref.self_ty(),
+ ty::ClauseKind::TypeOutlives(pred) => pred.0,
+ _ => return None,
+ };
+ if let ty::Param(param) = bounded_ty.kind() {
+ Some((param.index, span))
+ } else {
+ None
+ }
+ })
+ // FIXME: This assumes that elaborated `Sized` bounds come first (which does hold at the
+ // time of writing). This is a bit fragile since we later use the span to detect elaborated
+ // `Sized` bounds. If they came last for example, this would break `Trait + /*elab*/Sized`
+ // since it would overwrite the span of the user-written bound. This could be fixed by
+ // folding the spans with `Span::to` which requires a bit of effort I think.
+ .collect::>()
+ });
+
+ let mut params_used = BitSet::new_empty(generics.params.len());
for leaf in ty.walk() {
if let GenericArgKind::Type(leaf_ty) = leaf.unpack()
&& let ty::Param(param) = leaf_ty.kind()
@@ -1305,15 +1327,24 @@ pub(super) fn check_type_params_are_used<'tcx>(
&& let ty::GenericParamDefKind::Type { .. } = param.kind
{
let span = tcx.def_span(param.def_id);
- struct_span_code_err!(
- tcx.dcx(),
+ let param_name = Ident::new(param.name, span);
+
+ // The corresponding predicates are post-`Sized`-elaboration. Therefore we
+ // * check for emptiness to detect lone user-written `?Sized` bounds
+ // * compare the param span to the pred span to detect lone user-written `Sized` bounds
+ let has_explicit_bounds = bounded_params.is_empty()
+ || (*bounded_params).get(¶m.index).is_some_and(|&&pred_sp| pred_sp != span);
+ let const_param_help = (!has_explicit_bounds).then_some(());
+
+ let mut diag = tcx.dcx().create_err(errors::UnusedGenericParameter {
span,
- E0091,
- "type parameter `{}` is unused",
- param.name,
- )
- .with_span_label(span, "unused type parameter")
- .emit();
+ param_name,
+ param_def_kind: tcx.def_descr(param.def_id),
+ help: errors::UnusedGenericParameterHelp::TyAlias { param_name },
+ const_param_help,
+ });
+ diag.code(E0091);
+ diag.emit();
}
}
}
diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs
index 28c8f846c23a..b74431983113 100644
--- a/compiler/rustc_hir_analysis/src/check/mod.rs
+++ b/compiler/rustc_hir_analysis/src/check/mod.rs
@@ -578,7 +578,7 @@ pub fn check_function_signature<'tcx>(
fn_id: LocalDefId,
) -> rustc_span::Span {
let mut args = {
- let node = tcx.hir().expect_owner(fn_id);
+ let node = tcx.expect_hir_owner_node(fn_id);
let decl = node.fn_decl().unwrap_or_else(|| bug!("expected fn decl, found {:?}", node));
decl.inputs.iter().map(|t| t.span).chain(std::iter::once(decl.output.span()))
};
diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs
index b9c9eec28139..885cfbd0fe22 100644
--- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs
+++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs
@@ -1,11 +1,10 @@
use crate::autoderef::Autoderef;
use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter};
+use crate::errors;
use rustc_ast as ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
-use rustc_errors::{
- codes::*, pluralize, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed,
-};
+use rustc_errors::{codes::*, pluralize, struct_span_code_err, Applicability, ErrorGuaranteed};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
use rustc_hir::lang_items::LangItem;
@@ -21,7 +20,7 @@ use rustc_middle::ty::{
};
use rustc_middle::ty::{GenericArgKind, GenericArgs};
use rustc_session::parse::feature_err;
-use rustc_span::symbol::{sym, Ident, Symbol};
+use rustc_span::symbol::{sym, Ident};
use rustc_span::{Span, DUMMY_SP};
use rustc_target::spec::abi::Abi;
use rustc_trait_selection::regions::InferCtxtRegionExt;
@@ -188,7 +187,7 @@ where
}
fn check_well_formed(tcx: TyCtxt<'_>, def_id: hir::OwnerId) -> Result<(), ErrorGuaranteed> {
- let node = tcx.hir().owner(def_id);
+ let node = tcx.hir_owner_node(def_id);
let mut res = match node {
hir::OwnerNode::Crate(_) => bug!("check_well_formed cannot be applied to the crate root"),
hir::OwnerNode::Item(item) => check_item(tcx, item),
@@ -1869,7 +1868,7 @@ fn check_variances_for_type_defn<'tcx>(
hir::ParamName::Error => {}
_ => {
let has_explicit_bounds = explicitly_bounded_params.contains(¶meter);
- report_bivariance(tcx, hir_param, has_explicit_bounds);
+ report_bivariance(tcx, hir_param, has_explicit_bounds, item.kind);
}
}
}
@@ -1879,30 +1878,38 @@ fn report_bivariance(
tcx: TyCtxt<'_>,
param: &rustc_hir::GenericParam<'_>,
has_explicit_bounds: bool,
+ item_kind: ItemKind<'_>,
) -> ErrorGuaranteed {
- let span = param.span;
- let param_name = param.name.ident().name;
- let mut err = error_392(tcx, span, param_name);
+ let param_name = param.name.ident();
- let suggested_marker_id = tcx.lang_items().phantom_data();
- // Help is available only in presence of lang items.
- let msg = if let Some(def_id) = suggested_marker_id {
- format!(
- "consider removing `{}`, referring to it in a field, or using a marker such as `{}`",
- param_name,
- tcx.def_path_str(def_id),
- )
- } else {
- format!("consider removing `{param_name}` or referring to it in a field")
+ let help = match item_kind {
+ ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => {
+ if let Some(def_id) = tcx.lang_items().phantom_data() {
+ errors::UnusedGenericParameterHelp::Adt {
+ param_name,
+ phantom_data: tcx.def_path_str(def_id),
+ }
+ } else {
+ errors::UnusedGenericParameterHelp::AdtNoPhantomData { param_name }
+ }
+ }
+ ItemKind::TyAlias(..) => errors::UnusedGenericParameterHelp::TyAlias { param_name },
+ item_kind => bug!("report_bivariance: unexpected item kind: {item_kind:?}"),
};
- err.help(msg);
- if matches!(param.kind, hir::GenericParamKind::Type { .. }) && !has_explicit_bounds {
- err.help(format!(
- "if you intended `{param_name}` to be a const parameter, use `const {param_name}: usize` instead"
- ));
- }
- err.emit()
+ let const_param_help =
+ matches!(param.kind, hir::GenericParamKind::Type { .. } if !has_explicit_bounds)
+ .then_some(());
+
+ let mut diag = tcx.dcx().create_err(errors::UnusedGenericParameter {
+ span: param.span,
+ param_name,
+ param_def_kind: tcx.def_descr(param.def_id.to_def_id()),
+ help,
+ const_param_help,
+ });
+ diag.code(E0392);
+ diag.emit()
}
impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
@@ -1967,11 +1974,6 @@ fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalModDefId) -> Result<(), Error
res
}
-fn error_392(tcx: TyCtxt<'_>, span: Span, param_name: Symbol) -> DiagnosticBuilder<'_> {
- struct_span_code_err!(tcx.dcx(), span, E0392, "parameter `{param_name}` is never used")
- .with_span_label(span, "unused parameter")
-}
-
pub fn provide(providers: &mut Providers) {
*providers = Providers { check_mod_type_wf, check_well_formed, ..*providers };
}
diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
index 97d792e49aea..3849c0893f47 100644
--- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
+++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
@@ -254,7 +254,7 @@ fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBou
map: &mut named_variable_map,
scope: &Scope::Root { opt_parent_item: None },
};
- match tcx.hir().owner(local_def_id) {
+ match tcx.hir_owner_node(local_def_id) {
hir::OwnerNode::Item(item) => visitor.visit_item(item),
hir::OwnerNode::ForeignItem(item) => visitor.visit_foreign_item(item),
hir::OwnerNode::TraitItem(item) => {
diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs
index 3674a760cbf9..5cdcc1bb860b 100644
--- a/compiler/rustc_hir_analysis/src/collect/type_of.rs
+++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs
@@ -590,7 +590,6 @@ fn infer_placeholder_type<'a>(
// The parser provided a sub-optimal `HasPlaceholders` suggestion for the type.
// We are typeck and have the real type, so remove that and suggest the actual type.
- // FIXME(eddyb) this looks like it should be functionality on `Diagnostic`.
if let Ok(suggestions) = &mut err.suggestions {
suggestions.clear();
}
diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs
index e5871276d641..4eba31e327f6 100644
--- a/compiler/rustc_hir_analysis/src/errors.rs
+++ b/compiler/rustc_hir_analysis/src/errors.rs
@@ -1511,3 +1511,27 @@ pub struct NotSupportedDelegation<'a> {
#[label]
pub callee_span: Span,
}
+
+#[derive(Diagnostic)]
+#[diag(hir_analysis_unused_generic_parameter)]
+pub(crate) struct UnusedGenericParameter {
+ #[primary_span]
+ #[label]
+ pub span: Span,
+ pub param_name: Ident,
+ pub param_def_kind: &'static str,
+ #[subdiagnostic]
+ pub help: UnusedGenericParameterHelp,
+ #[help(hir_analysis_const_param_help)]
+ pub const_param_help: Option<()>,
+}
+
+#[derive(Subdiagnostic)]
+pub(crate) enum UnusedGenericParameterHelp {
+ #[help(hir_analysis_unused_generic_parameter_adt_help)]
+ Adt { param_name: Ident, phantom_data: String },
+ #[help(hir_analysis_unused_generic_parameter_adt_no_phantom_data_help)]
+ AdtNoPhantomData { param_name: Ident },
+ #[help(hir_analysis_unused_generic_parameter_ty_alias_help)]
+ TyAlias { param_name: Ident },
+}
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index 2bbef11fa245..1adde8c21b8e 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -1000,7 +1000,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_suggestion_verbose(
lhs.span.shrink_to_hi(),
"you might have meant to write a semicolon here",
- ";".to_string(),
+ ";",
Applicability::MachineApplicable,
);
return true;
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
index 95c1139e43e4..5395ffda1d13 100644
--- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
+++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
@@ -261,6 +261,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr.kind
&& let Some(recv_ty) = self.typeck_results.borrow().expr_ty_opt(recv_expr)
&& self.can_coerce(recv_ty, expected)
+ && let name = method.name.as_str()
+ && (name.starts_with("to_") || name.starts_with("as_") || name == "into")
{
let span = if let Some(recv_span) = recv_expr.span.find_ancestor_inside(expr.span) {
expr.span.with_lo(recv_span.hi())
diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs
index 6c9501e93fa1..904961d9eba2 100644
--- a/compiler/rustc_hir_typeck/src/method/suggest.rs
+++ b/compiler/rustc_hir_typeck/src/method/suggest.rs
@@ -1116,9 +1116,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
item_name.span,
format!(
"you might have meant to use `{}`",
- inherent_method.name.as_str()
+ inherent_method.name
),
- inherent_method.name.as_str(),
+ inherent_method.name,
Applicability::MaybeIncorrect,
);
break 'outer;
@@ -2019,7 +2019,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
diag.span_suggestion_verbose(
sm.span_extend_while(seg1.ident.span.shrink_to_hi(), |c| c == ':').unwrap(),
"you may have meant to call an instance method",
- ".".to_string(),
+ ".",
Applicability::MaybeIncorrect,
);
}
diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs
index b7f28ef958aa..fcf4b59e93fc 100644
--- a/compiler/rustc_hir_typeck/src/pat.rs
+++ b/compiler/rustc_hir_typeck/src/pat.rs
@@ -576,7 +576,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if (lhs, rhs).references_error() {
err.downgrade_to_delayed_bug();
}
- if self.tcx.sess.teach(err.get_code().unwrap()) {
+ if self.tcx.sess.teach(err.code.unwrap()) {
err.note(
"In a match expression, only numbers and characters can be matched \
against a range. This is because the compiler checks that the range \
@@ -847,7 +847,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
type_str
);
err.span_label(span, format!("type `{type_str}` cannot be dereferenced"));
- if self.tcx.sess.teach(err.get_code().unwrap()) {
+ if self.tcx.sess.teach(err.code.unwrap()) {
err.note(CANNOT_IMPLICITLY_DEREF_POINTER_TRAIT_OBJ);
}
return Err(err.emit());
@@ -1669,7 +1669,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
}
- if tcx.sess.teach(err.get_code().unwrap()) {
+ if tcx.sess.teach(err.code.unwrap()) {
err.note(
"This error indicates that a struct pattern attempted to \
extract a nonexistent field from a struct. Struct fields \
diff --git a/compiler/rustc_incremental/src/assert_dep_graph.rs b/compiler/rustc_incremental/src/assert_dep_graph.rs
index 6f909a0cc9db..aa6f184a2d7d 100644
--- a/compiler/rustc_incremental/src/assert_dep_graph.rs
+++ b/compiler/rustc_incremental/src/assert_dep_graph.rs
@@ -131,7 +131,7 @@ impl<'tcx> IfThisChanged<'tcx> {
None => DepNode::from_def_path_hash(
self.tcx,
def_path_hash,
- dep_kinds::hir_owner_nodes,
+ dep_kinds::opt_hir_owner_nodes,
),
Some(n) => {
match DepNode::from_label_string(self.tcx, n.as_str(), def_path_hash) {
diff --git a/compiler/rustc_incremental/src/persist/dirty_clean.rs b/compiler/rustc_incremental/src/persist/dirty_clean.rs
index 842cc9fae9b4..14cc8c260e21 100644
--- a/compiler/rustc_incremental/src/persist/dirty_clean.rs
+++ b/compiler/rustc_incremental/src/persist/dirty_clean.rs
@@ -57,8 +57,8 @@ const BASE_FN: &[&str] = &[
/// DepNodes for Hir, which is pretty much everything
const BASE_HIR: &[&str] = &[
- // hir_owner_nodes should be computed for all nodes
- label_strs::hir_owner_nodes,
+ // opt_hir_owner_nodes should be computed for all nodes
+ label_strs::opt_hir_owner_nodes,
];
/// `impl` implementation of struct/trait
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
index 006638b740ef..b8344310d5df 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
@@ -2555,7 +2555,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
add_lt_suggs,
new_lt: &new_lt,
};
- match self.tcx.hir().expect_owner(lifetime_scope) {
+ match self.tcx.expect_hir_owner_node(lifetime_scope) {
hir::OwnerNode::Item(i) => visitor.visit_item(i),
hir::OwnerNode::ForeignItem(i) => visitor.visit_foreign_item(i),
hir::OwnerNode::ImplItem(i) => visitor.visit_impl_item(i),
diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs
index a7d1c2ca6669..c8fd4e3a6928 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs
@@ -443,7 +443,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
if let hir::OwnerNode::Item(Item {
kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
..
- }) = tcx.hir().owner(impl_did)
+ }) = tcx.hir_owner_node(impl_did)
{
Some((impl_item.ident, self_ty))
} else {
diff --git a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs
index 0e7c641e0e0b..0452d4fe6c80 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs
@@ -195,7 +195,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
}
diag.help("type parameters must be constrained to match other types");
- if tcx.sess.teach(diag.get_code().unwrap()) {
+ if tcx.sess.teach(diag.code.unwrap()) {
diag.help(
"given a type parameter `T` and a method `foo`:
```
@@ -678,7 +678,7 @@ impl Trait for X {
https://doc.rust-lang.org/book/ch19-03-advanced-traits.html",
);
}
- if tcx.sess.teach(diag.get_code().unwrap()) {
+ if tcx.sess.teach(diag.code.unwrap()) {
diag.help(
"given an associated type `T` and a method `foo`:
```
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs
index 5ca880909967..8a4705e0056e 100644
--- a/compiler/rustc_interface/src/interface.rs
+++ b/compiler/rustc_interface/src/interface.rs
@@ -45,20 +45,19 @@ pub struct Compiler {
pub(crate) fn parse_cfg(dcx: &DiagCtxt, cfgs: Vec) -> Cfg {
cfgs.into_iter()
.map(|s| {
- let sess = ParseSess::with_silent_emitter(Some(format!(
+ let sess = ParseSess::with_silent_emitter(format!(
"this error occurred on the command line: `--cfg={s}`"
- )));
+ ));
let filename = FileName::cfg_spec_source_code(&s);
macro_rules! error {
($reason: expr) => {
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
- dcx.struct_fatal(format!(
+ dcx.fatal(format!(
concat!("invalid `--cfg` argument: `{}` (", $reason, ")"),
s
- ))
- .emit();
+ ));
};
}
@@ -108,20 +107,19 @@ pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec) -> CheckCfg {
let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg::default() };
for s in specs {
- let sess = ParseSess::with_silent_emitter(Some(format!(
+ let sess = ParseSess::with_silent_emitter(format!(
"this error occurred on the command line: `--check-cfg={s}`"
- )));
+ ));
let filename = FileName::cfg_spec_source_code(&s);
macro_rules! error {
($reason:expr) => {
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
- dcx.struct_fatal(format!(
+ dcx.fatal(format!(
concat!("invalid `--check-cfg` argument: `{}` (", $reason, ")"),
s
))
- .emit()
};
}
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs
index 07f127414dbc..f10d3d4a68a7 100644
--- a/compiler/rustc_lint/src/builtin.rs
+++ b/compiler/rustc_lint/src/builtin.rs
@@ -72,7 +72,7 @@ use crate::nonstandard_style::{method_context, MethodLateContext};
use std::fmt::Write;
-// hardwired lints from librustc_middle
+// hardwired lints from rustc_lint_defs
pub use rustc_session::lint::builtin::*;
declare_lint! {
diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs
index d37f0c151714..40fb12b21070 100644
--- a/compiler/rustc_lint/src/levels.rs
+++ b/compiler/rustc_lint/src/levels.rs
@@ -181,7 +181,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe
// Otherwise, we need to visit the attributes in source code order, so we fetch HIR and do
// a standard visit.
// FIXME(#102522) Just iterate on attrs once that iteration order matches HIR's.
- _ => match tcx.hir().owner(owner) {
+ _ => match tcx.hir_owner_node(owner) {
hir::OwnerNode::Item(item) => levels.visit_item(item),
hir::OwnerNode::ForeignItem(item) => levels.visit_foreign_item(item),
hir::OwnerNode::TraitItem(item) => levels.visit_trait_item(item),
diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs
index 1d9ce10bcaf3..0a15671e6869 100644
--- a/compiler/rustc_lint/src/lib.rs
+++ b/compiler/rustc_lint/src/lib.rs
@@ -516,6 +516,10 @@ fn register_builtins(store: &mut LintStore) {
"converted into hard error, see PR #118649 \
for more information",
);
+ store.register_removed(
+ "illegal_floating_point_literal_pattern",
+ "no longer a warning, float patterns behave the same as `==`",
+ );
}
fn register_internals(store: &mut LintStore) {
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs
index e6d837ecd92b..07c0e75a71c9 100644
--- a/compiler/rustc_lint_defs/src/builtin.rs
+++ b/compiler/rustc_lint_defs/src/builtin.rs
@@ -45,7 +45,6 @@ declare_lint_pass! {
FUZZY_PROVENANCE_CASTS,
HIDDEN_GLOB_REEXPORTS,
ILL_FORMED_ATTRIBUTE_INPUT,
- ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
INCOMPLETE_INCLUDE,
INDIRECT_STRUCTURAL_MATCH,
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
@@ -1873,55 +1872,6 @@ declare_lint! {
};
}
-declare_lint! {
- /// The `illegal_floating_point_literal_pattern` lint detects
- /// floating-point literals used in patterns.
- ///
- /// ### Example
- ///
- /// ```rust
- /// let x = 42.0;
- ///
- /// match x {
- /// 5.0 => {}
- /// _ => {}
- /// }
- /// ```
- ///
- /// {{produces}}
- ///
- /// ### Explanation
- ///
- /// Previous versions of the compiler accepted floating-point literals in
- /// patterns, but it was later determined this was a mistake. The
- /// semantics of comparing floating-point values may not be clear in a
- /// pattern when contrasted with "structural equality". Typically you can
- /// work around this by using a [match guard], such as:
- ///
- /// ```rust
- /// # let x = 42.0;
- ///
- /// match x {
- /// y if y == 5.0 => {}
- /// _ => {}
- /// }
- /// ```
- ///
- /// This is a [future-incompatible] lint to transition this to a hard
- /// error in the future. See [issue #41620] for more details.
- ///
- /// [issue #41620]: https://github.com/rust-lang/rust/issues/41620
- /// [match guard]: https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards
- /// [future-incompatible]: ../index.md#future-incompatible-lints
- pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
- Warn,
- "floating-point literals cannot be used in patterns",
- @future_incompatible = FutureIncompatibleInfo {
- reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
- reference: "issue #41620 ",
- };
-}
-
declare_lint! {
/// The `unstable_name_collisions` lint detects that you have used a name
/// that the standard library plans to add in the future.
diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs
index e745913fabc3..c648b2bfe9b9 100644
--- a/compiler/rustc_middle/src/arena.rs
+++ b/compiler/rustc_middle/src/arena.rs
@@ -94,7 +94,7 @@ macro_rules! arena_types {
// Note that this deliberately duplicates items in the `rustc_hir::arena`,
// since we need to allocate this type on both the `rustc_hir` arena
- // (during lowering) and the `librustc_middle` arena (for decoding MIR)
+ // (during lowering) and the `rustc_middle` arena (for decoding MIR)
[decode] asm_template: rustc_ast::InlineAsmTemplatePiece,
[decode] used_trait_imports: rustc_data_structures::unord::UnordSet,
[decode] is_late_bound_map: rustc_data_structures::fx::FxIndexSet,
diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs
index 211da8002029..3ebbcd650302 100644
--- a/compiler/rustc_middle/src/error.rs
+++ b/compiler/rustc_middle/src/error.rs
@@ -1,7 +1,6 @@
-use std::borrow::Cow;
use std::fmt;
-use rustc_errors::{codes::*, DiagnosticArgValue, DiagnosticMessage};
+use rustc_errors::{codes::*, DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage};
use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol};
@@ -95,14 +94,14 @@ pub(super) struct ConstNotUsedTraitAlias {
pub struct CustomSubdiagnostic<'a> {
pub msg: fn() -> DiagnosticMessage,
- pub add_args: Box, DiagnosticArgValue)) + 'a>,
+ pub add_args: Box,
}
impl<'a> CustomSubdiagnostic<'a> {
pub fn label(x: fn() -> DiagnosticMessage) -> Self {
Self::label_and_then(x, |_| {})
}
- pub fn label_and_then, DiagnosticArgValue)) + 'a>(
+ pub fn label_and_then(
msg: fn() -> DiagnosticMessage,
f: F,
) -> Self {
diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs
index 949b786e3a7d..ba1ae46626b2 100644
--- a/compiler/rustc_middle/src/hir/map/mod.rs
+++ b/compiler/rustc_middle/src/hir/map/mod.rs
@@ -107,9 +107,8 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
fn next(&mut self) -> Option {
if self.current_id.local_id.index() != 0 {
self.current_id.local_id = ItemLocalId::new(0);
- if let Some(node) = self.map.tcx.hir_owner(self.current_id.owner) {
- return Some((self.current_id.owner, node));
- }
+ let node = self.map.tcx.hir_owner_node(self.current_id.owner);
+ return Some((self.current_id.owner, node));
}
if self.current_id == CRATE_HIR_ID {
return None;
@@ -125,22 +124,42 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
self.current_id = HirId::make_owner(parent_id.def_id);
// If this `HirId` doesn't have an entry, skip it and look for its `parent_id`.
- if let Some(node) = self.map.tcx.hir_owner(self.current_id.owner) {
- return Some((self.current_id.owner, node));
- }
+ let node = self.map.tcx.hir_owner_node(self.current_id.owner);
+ return Some((self.current_id.owner, node));
}
}
}
impl<'tcx> TyCtxt<'tcx> {
#[inline]
- fn hir_owner(self, owner: OwnerId) -> Option> {
- Some(self.hir_owner_nodes(owner).as_owner()?.node())
+ fn expect_hir_owner_nodes(self, def_id: LocalDefId) -> &'tcx OwnerNodes<'tcx> {
+ self.opt_hir_owner_nodes(def_id)
+ .unwrap_or_else(|| span_bug!(self.def_span(def_id), "{def_id:?} is not an owner"))
+ }
+
+ #[inline]
+ pub fn hir_owner_nodes(self, owner_id: OwnerId) -> &'tcx OwnerNodes<'tcx> {
+ self.expect_hir_owner_nodes(owner_id.def_id)
+ }
+
+ #[inline]
+ fn opt_hir_owner_node(self, def_id: LocalDefId) -> Option> {
+ self.opt_hir_owner_nodes(def_id).map(|nodes| nodes.node())
+ }
+
+ #[inline]
+ pub fn expect_hir_owner_node(self, def_id: LocalDefId) -> OwnerNode<'tcx> {
+ self.expect_hir_owner_nodes(def_id).node()
+ }
+
+ #[inline]
+ pub fn hir_owner_node(self, owner_id: OwnerId) -> OwnerNode<'tcx> {
+ self.hir_owner_nodes(owner_id).node()
}
/// Retrieves the `hir::Node` corresponding to `id`, returning `None` if cannot be found.
pub fn opt_hir_node(self, id: HirId) -> Option> {
- let owner = self.hir_owner_nodes(id.owner).as_owner()?;
+ let owner = self.hir_owner_nodes(id.owner);
let node = owner.nodes[id.local_id].as_ref()?;
Some(node.node)
}
@@ -174,8 +193,8 @@ impl<'hir> Map<'hir> {
#[inline]
pub fn root_module(self) -> &'hir Mod<'hir> {
- match self.tcx.hir_owner(CRATE_OWNER_ID) {
- Some(OwnerNode::Crate(item)) => item,
+ match self.tcx.hir_owner_node(CRATE_OWNER_ID) {
+ OwnerNode::Crate(item) => item,
_ => bug!(),
}
}
@@ -213,7 +232,7 @@ impl<'hir> Map<'hir> {
if id.local_id == ItemLocalId::from_u32(0) {
Some(self.tcx.hir_owner_parent(id.owner))
} else {
- let owner = self.tcx.hir_owner_nodes(id.owner).as_owner()?;
+ let owner = self.tcx.hir_owner_nodes(id.owner);
let node = owner.nodes[id.local_id].as_ref()?;
let hir_id = HirId { owner: id.owner, local_id: node.parent };
// HIR indexing should have checked that.
@@ -241,32 +260,27 @@ impl<'hir> Map<'hir> {
}
pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'hir>> {
- let node = self.tcx.hir_owner(OwnerId { def_id: id })?;
- node.generics()
- }
-
- pub fn owner(self, id: OwnerId) -> OwnerNode<'hir> {
- self.tcx.hir_owner(id).unwrap_or_else(|| bug!("expected owner for {:?}", id))
+ self.tcx.opt_hir_owner_node(id)?.generics()
}
pub fn item(self, id: ItemId) -> &'hir Item<'hir> {
- self.tcx.hir_owner(id.owner_id).unwrap().expect_item()
+ self.tcx.hir_owner_node(id.owner_id).expect_item()
}
pub fn trait_item(self, id: TraitItemId) -> &'hir TraitItem<'hir> {
- self.tcx.hir_owner(id.owner_id).unwrap().expect_trait_item()
+ self.tcx.hir_owner_node(id.owner_id).expect_trait_item()
}
pub fn impl_item(self, id: ImplItemId) -> &'hir ImplItem<'hir> {
- self.tcx.hir_owner(id.owner_id).unwrap().expect_impl_item()
+ self.tcx.hir_owner_node(id.owner_id).expect_impl_item()
}
pub fn foreign_item(self, id: ForeignItemId) -> &'hir ForeignItem<'hir> {
- self.tcx.hir_owner(id.owner_id).unwrap().expect_foreign_item()
+ self.tcx.hir_owner_node(id.owner_id).expect_foreign_item()
}
pub fn body(self, id: BodyId) -> &'hir Body<'hir> {
- self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies[&id.hir_id.local_id]
+ self.tcx.hir_owner_nodes(id.hir_id.owner).bodies[&id.hir_id.local_id]
}
#[track_caller]
@@ -436,9 +450,9 @@ impl<'hir> Map<'hir> {
pub fn get_module(self, module: LocalModDefId) -> (&'hir Mod<'hir>, Span, HirId) {
let hir_id = HirId::make_owner(module.to_local_def_id());
- match self.tcx.hir_owner(hir_id.owner) {
- Some(OwnerNode::Item(&Item { span, kind: ItemKind::Mod(m), .. })) => (m, span, hir_id),
- Some(OwnerNode::Crate(item)) => (item, item.spans.inner_span, hir_id),
+ match self.tcx.hir_owner_node(hir_id.owner) {
+ OwnerNode::Item(&Item { span, kind: ItemKind::Mod(m), .. }) => (m, span, hir_id),
+ OwnerNode::Crate(item) => (item, item.spans.inner_span, hir_id),
node => panic!("not a module: {node:?}"),
}
}
@@ -726,8 +740,8 @@ impl<'hir> Map<'hir> {
pub fn get_foreign_abi(self, hir_id: HirId) -> Abi {
let parent = self.get_parent_item(hir_id);
- if let Some(node) = self.tcx.hir_owner(parent)
- && let OwnerNode::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }) = node
+ if let OwnerNode::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }) =
+ self.tcx.hir_owner_node(parent)
{
return *abi;
}
@@ -737,38 +751,29 @@ impl<'hir> Map<'hir> {
)
}
- pub fn expect_owner(self, def_id: LocalDefId) -> OwnerNode<'hir> {
- self.tcx
- .hir_owner(OwnerId { def_id })
- .unwrap_or_else(|| bug!("expected owner for {:?}", def_id))
- }
-
pub fn expect_item(self, id: LocalDefId) -> &'hir Item<'hir> {
- match self.tcx.hir_owner(OwnerId { def_id: id }) {
- Some(OwnerNode::Item(item)) => item,
+ match self.tcx.expect_hir_owner_node(id) {
+ OwnerNode::Item(item) => item,
_ => bug!("expected item, found {}", self.node_to_string(HirId::make_owner(id))),
}
}
pub fn expect_impl_item(self, id: LocalDefId) -> &'hir ImplItem<'hir> {
- match self.tcx.hir_owner(OwnerId { def_id: id }) {
- Some(OwnerNode::ImplItem(item)) => item,
+ match self.tcx.expect_hir_owner_node(id) {
+ OwnerNode::ImplItem(item) => item,
_ => bug!("expected impl item, found {}", self.node_to_string(HirId::make_owner(id))),
}
}
pub fn expect_trait_item(self, id: LocalDefId) -> &'hir TraitItem<'hir> {
- match self.tcx.hir_owner(OwnerId { def_id: id }) {
- Some(OwnerNode::TraitItem(item)) => item,
+ match self.tcx.expect_hir_owner_node(id) {
+ OwnerNode::TraitItem(item) => item,
_ => bug!("expected trait item, found {}", self.node_to_string(HirId::make_owner(id))),
}
}
pub fn get_fn_output(self, def_id: LocalDefId) -> Option<&'hir FnRetTy<'hir>> {
- match self.tcx.hir_owner(OwnerId { def_id }) {
- Some(node) => node.fn_decl().map(|fn_decl| &fn_decl.output),
- _ => None,
- }
+ Some(&self.tcx.opt_hir_owner_node(def_id)?.fn_decl()?.output)
}
pub fn expect_variant(self, id: HirId) -> &'hir Variant<'hir> {
@@ -779,8 +784,8 @@ impl<'hir> Map<'hir> {
}
pub fn expect_foreign_item(self, id: OwnerId) -> &'hir ForeignItem<'hir> {
- match self.tcx.hir_owner(id) {
- Some(OwnerNode::ForeignItem(item)) => item,
+ match self.tcx.hir_owner_node(id) {
+ OwnerNode::ForeignItem(item) => item,
_ => {
bug!(
"expected foreign item, found {}",
diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs
index 2d4d5deaefa9..94191df30a5e 100644
--- a/compiler/rustc_middle/src/hir/mod.rs
+++ b/compiler/rustc_middle/src/hir/mod.rs
@@ -127,21 +127,15 @@ pub fn provide(providers: &mut Providers) {
providers.hir_crate_items = map::hir_crate_items;
providers.crate_hash = map::crate_hash;
providers.hir_module_items = map::hir_module_items;
- providers.opt_local_def_id_to_hir_id = |tcx, id| {
- let owner = tcx.hir_crate(()).owners[id].map(|_| ());
- Some(match owner {
- MaybeOwner::Owner(_) => HirId::make_owner(id),
- MaybeOwner::Phantom => bug!("No HirId for {:?}", id),
+ providers.opt_local_def_id_to_hir_id = |tcx, def_id| {
+ Some(match tcx.hir_crate(()).owners[def_id] {
+ MaybeOwner::Owner(_) => HirId::make_owner(def_id),
MaybeOwner::NonOwner(hir_id) => hir_id,
+ MaybeOwner::Phantom => bug!("No HirId for {:?}", def_id),
})
};
- providers.hir_owner_nodes = |tcx, id| {
- if let Some(i) = tcx.hir_crate(()).owners.get(id.def_id) {
- i.map(|i| &i.nodes)
- } else {
- MaybeOwner::Phantom
- }
- };
+ providers.opt_hir_owner_nodes =
+ |tcx, id| tcx.hir_crate(()).owners.get(id)?.as_owner().map(|i| &i.nodes);
providers.hir_owner_parent = |tcx, id| {
// Accessing the local_parent is ok since its value is hashed as part of `id`'s DefPathHash.
tcx.opt_local_parent(id.def_id).map_or(CRATE_HIR_ID, |parent| {
diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs
index 95574aee499f..0f69ab93452f 100644
--- a/compiler/rustc_middle/src/mir/interpret/error.rs
+++ b/compiler/rustc_middle/src/mir/interpret/error.rs
@@ -5,7 +5,9 @@ use crate::mir::{ConstAlloc, ConstValue};
use crate::ty::{layout, tls, Ty, TyCtxt, ValTree};
use rustc_data_structures::sync::Lock;
-use rustc_errors::{DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg};
+use rustc_errors::{
+ DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg,
+};
use rustc_macros::HashStable;
use rustc_session::CtfeBacktrace;
use rustc_span::{def_id::DefId, Span, DUMMY_SP};
@@ -485,7 +487,7 @@ pub trait MachineStopType: Any + fmt::Debug + Send {
fn diagnostic_message(&self) -> DiagnosticMessage;
/// Add diagnostic arguments by passing name and value pairs to `adder`, which are passed to
/// fluent for formatting the translated diagnostic message.
- fn add_args(self: Box, adder: &mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue));
+ fn add_args(self: Box, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue));
}
impl dyn MachineStopType {
diff --git a/compiler/rustc_middle/src/mir/interpret/value.rs b/compiler/rustc_middle/src/mir/interpret/value.rs
index 5ecff04f3ae3..e937c17c8ace 100644
--- a/compiler/rustc_middle/src/mir/interpret/value.rs
+++ b/compiler/rustc_middle/src/mir/interpret/value.rs
@@ -418,8 +418,8 @@ impl<'tcx, Prov: Provenance> Scalar {
#[inline]
pub fn to_float(self) -> InterpResult<'tcx, F> {
- // Going through `to_uint` to check size and truncation.
- Ok(F::from_bits(self.to_uint(Size::from_bits(F::BITS))?))
+ // Going through `to_bits` to check size and truncation.
+ Ok(F::from_bits(self.to_bits(Size::from_bits(F::BITS))?))
}
#[inline]
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs
index 37c5bba46a7d..c9e69253701c 100644
--- a/compiler/rustc_middle/src/mir/mod.rs
+++ b/compiler/rustc_middle/src/mir/mod.rs
@@ -14,7 +14,9 @@ use crate::ty::{AdtDef, InstanceDef, UserTypeAnnotationIndex};
use crate::ty::{GenericArg, GenericArgsRef};
use rustc_data_structures::captures::Captures;
-use rustc_errors::{DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg};
+use rustc_errors::{
+ DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg,
+};
use rustc_hir::def::{CtorKind, Namespace};
use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
use rustc_hir::{self, CoroutineDesugaring, CoroutineKind, ImplicitSelfKind};
diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs
index 0fe33e441f43..91b7952bec5e 100644
--- a/compiler/rustc_middle/src/mir/terminator.rs
+++ b/compiler/rustc_middle/src/mir/terminator.rs
@@ -292,7 +292,7 @@ impl AssertKind {
}
}
- pub fn add_args(self, adder: &mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue))
+ pub fn add_args(self, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue))
where
O: fmt::Debug,
{
diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs
index 1b01df6a1871..a272a51f3274 100644
--- a/compiler/rustc_middle/src/query/erase.rs
+++ b/compiler/rustc_middle/src/query/erase.rs
@@ -185,8 +185,8 @@ impl EraseType for Option>> {
type Result = [u8; size_of::